第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CouchDB 圖形中的最短路徑

CouchDB 圖形中的最短路徑

縹緲止盈 2021-06-16 13:01:56
我正在嘗試計算存儲在 CouchDB 中的圖形中的最短路徑。我必須在 db 中執(zhí)行此操作,因為我的任務(wù)是比較 3 種不同 DBMS 在各種情況下的查詢速度。因此,在 python(或其他任何東西)中加載數(shù)據(jù)和運行 dijkstra 不是一種選擇。我對基于文檔的數(shù)據(jù)庫很陌生,所以我可能錯了,但在我看來,我唯一的選擇是視圖。我的數(shù)據(jù)庫結(jié)構(gòu)如下:一份文件代表一張圖。在帶有“邊緣”鍵的文檔中,有一組具有 3 個屬性的對象:開始、結(jié)束、距離。start和end是節(jié)點 ID,但沒有關(guān)于節(jié)點的其他有趣信息,因此它們不會存儲在其他任何地方。距離是一個浮動我的想法是創(chuàng)建一個返回最短路徑的視圖。我有計算它的代碼。它基于這篇文章。我只需要稍微修改一下,否則我會遇到像let,foreach這樣的語法錯誤:function (doc) {  function Graph() {    this.nodes = [];    this.adjacencyList = {};    this.addNode = function(node) {      if(this.nodes.indexOf(node) != -1)        return;      this.nodes.push(node);       this.adjacencyList[node] = [];    }    this.addEdge = function(node1, node2, weight) {      this.adjacencyList[node1].push({node:node2, weight: weight});      //this.adjacencyList[node2].push({node:node1, weight: weight});    }    this.shortestPath = function(startNode, endNode){      var times = {};      var backtrace = {};      var pq = new PriorityQueue();      times[startNode] = 0;      for(var i = 0; i<this.nodes.length; i++){        if(this.nodes[i] != startNode){          times[node] = Infinity;        }      }      pq.enqueue([startNode, 0]);      while (!pq.isEmpty()) {        var shortestStep = pq.dequeue();        var currentNode = shortestStep[0];        for(var i=0;i< this.adjacencyList[currentNode].length; i++){          var neighbor = this.adjacencyList[currentNode][i];          var time = times[currentNode] + neighbor.weight;          if (time < times[neighbor.node]) {            times[neighbor.node] = time;            backtrace[neighbor.node] = currentNode;            pq.enqueue([neighbor.node, time]);          }        }      }      var path = [endNode];      var lastStep = endNode;      while(lastStep !== startNode) {        path.unshift(backtrace[lastStep]);        lastStep = backtrace[lastStep];      }      return 'Path is ${path} and time is ${times[endNode]}';    }  };但是,在查詢視圖時,我得到 0 行。
查看完整描述

1 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗 獲得超4個贊

終于我找到了。當(dāng)我將 foreach 重寫為傳統(tǒng)的 for 時,我忘記更改了:


for(var i = 0; i<this.nodes.length; i++){

    if(this.nodes[i] != startNode){

      times[node] = Infinity;

    }

}

對此:


for(var i = 0; i<this.nodes.length; i++){

   if(this.nodes[i] != startNode){

      times[this.nodes[i]] = Infinity;

   }

}

有趣的是,我在 CouchDB 中沒有看到任何錯誤。我必須使用 node.js 在本地運行我的代碼才能發(fā)現(xiàn)有錯誤。


查看完整回答
反對 回復(fù) 2021-06-18
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號