1
我正在嘗試使用Cytoscape在各種圖表上測試Dijkstra的算法。使用以下Cytoscape Dijkstra算法關閉?
圖可以很容易地看到,從A
到C
最短路徑將是A -> D -> E -> C
。
當運行的Cytoscape的Djikstra的算法雖然
const dijkstra = cy.elements().dijkstra('#A', function(){
const weight = this.data('weight');
return weight;
}, false);
const pathToC = dijkstra.pathTo(cy.$('#C'));
const distToC = dijkstra.distanceTo(cy.$('#C'));
Cytoscape的給出了輸出
A -> B -> C
這肯定是不對的。
我做錯了什麼?還是Cytoscape的算法關閉?
PS碼生成Cytoscape中的圖是
{
"elements": {
"nodes": [
{
"data": {
"id": "A"
},
"position": {
"x": 187,
"y": 135
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "B"
},
"position": {
"x": 516,
"y": 128
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "C"
},
"position": {
"x": 726,
"y": 302
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "D"
},
"position": {
"x": 186,
"y": 447
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "E"
},
"position": {
"x": 510,
"y": 445
},
"group": "nodes",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
}
],
"edges": [
{
"data": {
"id": "BA",
"source": "B",
"target": "A",
"weight": "100"
},
"position": {
"x": 514,
"y": 127
},
"group": "edges",
"removed": false,
"selected": true,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "DA",
"source": "D",
"target": "A",
"weight": "1"
},
"position": {
"x": 187,
"y": 446
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "BD",
"source": "B",
"target": "D",
"weight": "100"
},
"position": {
"x": 516,
"y": 127
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "EB",
"source": "E",
"target": "B",
"weight": "100"
},
"position": {
"x": 500,
"y": 442
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "ED",
"source": "E",
"target": "D",
"weight": "1"
},
"position": {
"x": 501,
"y": 443
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "CE",
"source": "C",
"target": "E",
"weight": "5"
},
"position": {
"x": 727,
"y": 304
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
},
{
"data": {
"id": "BC",
"source": "B",
"target": "C",
"weight": "5"
},
"position": {
"x": 521,
"y": 132
},
"group": "edges",
"removed": false,
"selected": false,
"selectable": true,
"locked": false,
"grabbable": true,
"classes": ""
}
]
},
"style": [
{
"selector": "node",
"style": {
"background-color": "#666",
"label": "data(id)"
}
},
{
"selector": "edge",
"style": {
"width": "3px",
"label": "data(weight)",
"line-color": "#ccc",
"target-arrow-color": "#ccc",
"target-arrow-shape": "triangle"
}
}
],
"zoomingEnabled": true,
"userZoomingEnabled": true,
"zoom": 1,
"minZoom": 1.0e-50,
"maxZoom": 1.0e+50,
"panningEnabled": true,
"userPanningEnabled": true,
"pan": {
"x": 0,
"y": 0
},
"boxSelectionEnabled": true,
"renderer": {
"name": "canvas"
}
}