0

LEMON ライブラリを使用しようとしていますが、実装しようとしているアルゴリズムで問題が発生しています。このアルゴリズムの考え方は、ノードのベクトルのベクトルがあり、ノードを特定の制限付きで別のベクトル (カラー クラス) に移動したいということです。私のアルゴリズムを実装するコードは次のとおりです。

bool moveColor() {
  // pick the smallest color class
  sort(colors.begin(), colors.end(), vectorSort);
  vector< vector< ListGraph::Node > >::iterator smallestColor = colors.begin();

  // shuffle this class
  random_shuffle(smallestColor->begin(), smallestColor->end());

  // try to move any of the nodes to any bigger class
  bool foundNode = false;
  vector< ListGraph::Node >::iterator movingNode;
  vector< vector< ListGraph::Node > >::iterator destinationClass;
  for (movingNode = smallestColor->begin(); movingNode != smallestColor->end() && !foundNode; ++movingNode) {
    for (destinationClass = colors.begin()+1; destinationClass != colors.end() && !foundNode; ++destinationClass) {
      ListGraph::NodeMap<bool> filter(g, false);
      vector< ListGraph::Node >::iterator classNode;
      for (classNode = destinationClass->begin(); classNode != destinationClass->end(); ++classNode) {
        filter[*classNode] = true;
      }
      filter[*movingNode] = true;
      FilterNodes<ListGraph> subgraph(g, filter);
      if (acyclic(subgraph)) {
        foundNode = true;
      }
    }
  }

  // if a movable node was found, move it. otherwise return false
  if (foundNode) {
    destinationClass->push_back(*movingNode);
    smallestColor->erase(movingNode);
    if (smallestColor->empty()) {
      colors.erase(smallestColor);
    }
    return true;
  }
  return false;
}

この関数は、ノードが移動できなくなるまでループ内で呼び出されます。コードで私が抱えている主な問題は、ノードをあるベクトルから別のベクトルに実際に移動するセクションです。

if (foundNode) {
  destinationClass->push_back(*movingNode);
  smallestColor->erase(movingNode);
  if (smallestColor->empty()) {
    colors.erase(smallestColor);
  }
  return true;
}

消去関数が呼び出されているときにノードが分解されていると思うので、この部分は機能していないようです。この関数が呼び出される前後のノード ID のサンプルを次に示します。

NEW ROUND
1 
3 
0 
5 2 
7 6 4 
NEW ROUND
3 
0 32701 
5 2 
7 6 4 

ご覧のとおり、移動されたノードの ID が正しくありません (1 ではなく 32701)。どんな助けでも大歓迎です。

4

1 に答える 1