1以下是具有4个边和4个节点的
---
1 | 1
2 | 0
3 | 1
incidence matrix
的示例。请记住,列是边,行是节点本身。 1 2 3 4下面是同一件事的JavaScript实现。
--------
1 | 0 1 1 1
2 | 1 1 0 0
3 | 1 0 0 1
4 | 0 0 1 0
var incMat = [要制作有向图,请使用
[0,1,1,1],
[1,1,0,0],
[1,0,0,1],
[0,0,1,0]
]。
-1
表示离开特定节点的边,使用1
作为边进入节点。 var incMatDirected = [图形的边缘也可以有权重 。到目前为止,我们有未加权的边缘,只有存在和缺少边是二进制(
[0,-1,1,-1],
[-1,1,0,0],
[1,0,0,1],
[0,0,-1,0]
]。
0
或1
)。根据您的应用,您可以拥有不同的重量。不同的权重表示为大于1的数字。 incMatUndirected
应该只包含五个节点。
testString: 'assert((incMatUndirected.length === 5) && incMatUndirected.map(function(x) { return x.length === 4 }).reduce(function(a, b) { return a && b }) , "incMatUndirected
should only contain five nodes.");'
- text: 第一个和第二个节点之间应该有第一条边。
testString: 'assert((incMatUndirected[0][0] === 1) && (incMatUndirected[1][0] === 1), "There should be a first edge between the first and second node.");'
- text: 第二个和第三个节点之间应该有第二条边。
testString: 'assert((incMatUndirected[1][1] === 1) && (incMatUndirected[2][1] === 1), "There should be a second edge between the second and third node.");'
- text: 第三个和第五个节点之间应该有第三条边。
testString: 'assert((incMatUndirected[2][2] === 1) && (incMatUndirected[4][2] === 1), "There should be a third edge between the third and fifth node.");'
- text: 第二个和第四个节点之间应该有第四条边。
testString: 'assert((incMatUndirected[1][3] === 1) && (incMatUndirected[3][3] === 1), "There should be a fourth edge between the second and fourth node.");'
```