Cytoscape Dijkstra 算法关闭?

Cytoscape Dijkstra Algorithm off?

我正在尝试使用 Cytoscape 在各种图形上测试 Dijkstra 算法。使用下图

很容易看出从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"
  }
}

我遇到了同样的问题,几乎相同的代码。

进行了一些调试,看起来 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".