- graph --> a collection of nodes(also called vertices顶点) and edges
- 可能会在边上设置权重weights——表示节点之间连接的一些成本或其他度量(可以在边上附加其他信息,但权重是最常见的)
- 在某些情况下,使用无向边,而在其他情况下可能需要有向边
1 Graph Applications
1.1 Task Scheduling
- 任务的依赖性
- critical path关键路径 --> constrain how quickly we can complete our entire work
- If reduce the length of this particular path enough, then it becomes non-critical, and some other path becomes critical
- tasks that are not on the critical path have some slack—could start them later without affecting the overall completion time
- 在general cases中,调度图可能是一个有向无环图directed acylic graph(DAG)——它不包含有向环,尽管它可能包含无向环
- 任务图中的有向循环将不可能进行调度,因为它将指示任务中的循环依赖关系——我们将需要在A之前完成B、C之前完成B和A之前完成C——没有一个任务可以先被调度
- 无向循环是允许的(there is a cycle if we ignore the edge directions, but not if we pay attention to them)。完全可以B和C依赖于A,同时D依赖于B和C
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/89401af1c4cf7c352790485d7ea09fe1.png)
1.2 Resource Allocation
- graph coloring是将一个图赋色给每个节点,使每个相邻的节点都不具有相同的颜色的过程
- 在资源分配的情况下,创建一个interference graph干涉图——在这个图中,如果两个节点相互冲突(即同时需要一个资源),则通过一条边连接两个节点。在这样的图中,一个有效的着色代表一个有效的资源分配,其中每个颜色代表一个特定的资源
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/1bab9d15ea234d260629f1a33e2eee7b.png)
- 相邻的不一个颜色,一共四个屋子,所以四种颜色,平面图没有交叉
- 四色定理four color theorem --> 每个平面图最多有4种颜色
1.3 Path Planning
1.4 Social Networks
2 Graph Implementations
- 最简单表示graph的方法:用一个无符号整数标识每个节点,并用double表示权重(或者是整数,或者没有权重信息)
class Graph {
public:
unsigned addNode();
void removeNode (unsigned whichNode);
void addEdge(unsigned from, unsigned to, double weight);
void removeEdge(unsigned from, unsigned to);
unsigned getNodeCount() const;
set<pair<unsigned, double> > getAdjacencies(unsigned whichNode) const;
double getEdge(unsigned from, unsigned to