2017-01-02 82 views
1

我正在嘗試使用Cytoscape在各種圖表上測試Dijkstra的算法。使用以下Cytoscape Dijkstra算法關閉?

enter image description here

圖可以很容易地看到,從AC最短路徑將是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" 
    } 
} 

回答

2
我有同樣的問題,幾乎相同的代碼

完成一些調試,看起來像dist對象連接字符串而不是添加整數。

dist: Object 
AMS11: "0474483" -> 0, 4, 74, 483 should really be 561 
BRU11: Infinity 
FRA11: Infinity 
GVA11: Infinity 
LON11: "0474"  -> 0, 4, 74 should really be 78 
LON21: 0 
LON22: "04"  -> 0, 4 should really be 4 
LON31: "047415" -> 0, 4, 74, 15 should really be 93 
LUX21: Infinity 
LUX31: Infinity 
MOW11: Infinity 
MOW12: Infinity 
PAR11: "049693" 
PAR21: "0474805" 
STO21: Infinity 
STO31: Infinity 
TYO11: Infinity 
TYO12: Infinity 

編輯:答案是改變你的砝碼爲整數,所以使用「weight」:1代替「weight」:「1」。