diff --git a/gtsam/3rdparty/metis-5.1.0/libmetis/pmetis.c b/gtsam/3rdparty/metis-5.1.0/libmetis/pmetis.c index d32e84921..15d59f5dd 100644 --- a/gtsam/3rdparty/metis-5.1.0/libmetis/pmetis.c +++ b/gtsam/3rdparty/metis-5.1.0/libmetis/pmetis.c @@ -256,8 +256,9 @@ idx_t MultilevelBisect(ctrl_t *ctrl, graph_t *graph, real_t *tpwgts) icopy(graph->nvtxs, graph->where, bestwhere); } - if (bestobj == 0) + if (bestobj == 0){ break; + } if (i < ctrl->ncuts-1) FreeRData(graph); @@ -269,7 +270,6 @@ idx_t MultilevelBisect(ctrl_t *ctrl, graph_t *graph, real_t *tpwgts) } WCOREPOP; - return bestobj; } diff --git a/gtsam_unstable/partition/FindSeparator-inl.h b/gtsam_unstable/partition/FindSeparator-inl.h index 2e147ff20..6f6f8d817 100644 --- a/gtsam_unstable/partition/FindSeparator-inl.h +++ b/gtsam_unstable/partition/FindSeparator-inl.h @@ -202,19 +202,22 @@ namespace gtsam { namespace partition { if (index1 >= 0 && index2 >= 0) { pair& adjancyMap1 = adjancyMap[index1]; pair& adjancyMap2 = adjancyMap[index2]; - cout << adjancyMap1.first.size() << endl; - adjancyMap1.first .push_back(index2); - adjancyMap1.second.push_back(factor->weight); - adjancyMap2.first .push_back(index1); - adjancyMap2.second.push_back(factor->weight); + try{ + adjancyMap1.first.push_back(index2); + adjancyMap1.second.push_back(factor->weight); + adjancyMap2.first.push_back(index1); + adjancyMap2.second.push_back(factor->weight); + }catch(std::exception& e){ + cout << e.what() << endl; + } numEdges++; } } // prepare for {xadj}, {adjncy}, and {adjwgt} - *ptr_xadj = sharedInts(new int[numNodes+1]); - *ptr_adjncy = sharedInts(new int[numEdges*2]); - *ptr_adjwgt = sharedInts(new int[numEdges*2]); + *ptr_xadj = sharedInts(new idx_t[numNodes+1]); + *ptr_adjncy = sharedInts(new idx_t[numEdges*2]); + *ptr_adjwgt = sharedInts(new idx_t[numEdges*2]); sharedInts& xadj = *ptr_xadj; sharedInts& adjncy = *ptr_adjncy; sharedInts& adjwgt = *ptr_adjwgt; diff --git a/gtsam_unstable/partition/PartitionWorkSpace.h b/gtsam_unstable/partition/PartitionWorkSpace.h index 021c1cdcc..b268c0fb2 100644 --- a/gtsam_unstable/partition/PartitionWorkSpace.h +++ b/gtsam_unstable/partition/PartitionWorkSpace.h @@ -22,7 +22,8 @@ namespace gtsam { namespace partition { PartitionTable partitionTable; // a mapping from a key to the submap index, 0 means the separator, i means the ith submap // constructor - WorkSpace(const size_t numNodes) : dictionary(numNodes,0), dsf(new std::vector(numNodes, 0)), partitionTable(numNodes, -1) { } + WorkSpace(const size_t numNodes) : dictionary(numNodes,0), + dsf(new std::vector(numNodes, 0)), partitionTable(numNodes, -1) { } // set up dictionary: -1: no such key, none-zero: the corresponding 0-based index inline void prepareDictionary(const std::vector& keys) { diff --git a/gtsam_unstable/partition/tests/testFindSeparator.cpp b/gtsam_unstable/partition/tests/testFindSeparator.cpp index 1bed2e0da..a489d4d34 100644 --- a/gtsam_unstable/partition/tests/testFindSeparator.cpp +++ b/gtsam_unstable/partition/tests/testFindSeparator.cpp @@ -72,22 +72,22 @@ TEST ( Partition, separatorPartitionByMetis2 ) } /* *************************************************************************/ -// x0 - x2 - x3 - x5 +// x0 - x1 - x2 - x3 TEST ( Partition, edgePartitionByMetis ) { - GenericGraph3D graph; - graph.push_back(boost::make_shared(0, 2, 0, NODE_POSE_3D, NODE_POSE_3D)); - graph.push_back(boost::make_shared(2, 3, 1, NODE_POSE_3D, NODE_POSE_3D)); - graph.push_back(boost::make_shared(3, 5, 2, NODE_POSE_3D, NODE_POSE_3D)); - std::vector keys; keys += 0, 2, 3, 5; + GenericGraph2D graph; + graph.push_back(boost::make_shared(0, NODE_POSE_2D, 1, NODE_POSE_2D, 1)); + graph.push_back(boost::make_shared(1, NODE_POSE_2D, 2, NODE_POSE_2D, 1)); + graph.push_back(boost::make_shared(2, NODE_POSE_2D, 3, NODE_POSE_2D, 1)); + std::vector keys; keys += 0, 1, 2, 3; WorkSpace workspace(6); - boost::optional actual = edgePartitionByMetis(graph, keys, + boost::optional actual = edgePartitionByMetis(graph, keys, workspace, true); CHECK(actual.is_initialized()); - vector A_expected; A_expected += 0, 2; // frontal - vector B_expected; B_expected += 3, 5; // frontal + vector A_expected; A_expected += 0, 1; // frontal + vector B_expected; B_expected += 2, 3; // frontal vector C_expected; // separator BOOST_FOREACH(const size_t a, actual->A) cout << a << " "; @@ -102,22 +102,26 @@ TEST ( Partition, edgePartitionByMetis ) } /* *************************************************************************/ -// x0 - x2 - x3 - x5 - x6 +// x0 - x1 - x2 - x3 - x4 TEST ( Partition, edgePartitionByMetis2 ) { - GenericGraph3D graph; - graph.push_back(boost::make_shared(0, 2, 0, NODE_POSE_3D, NODE_POSE_3D, 1)); - graph.push_back(boost::make_shared(2, 3, 1, NODE_POSE_3D, NODE_POSE_3D, 1)); - graph.push_back(boost::make_shared(3, 5, 2, NODE_POSE_3D, NODE_POSE_3D, 20)); - graph.push_back(boost::make_shared(5, 6, 3, NODE_POSE_3D, NODE_POSE_3D, 1)); - std::vector keys; keys += 0, 2, 3, 5, 6; + GenericGraph2D graph; + graph.push_back(boost::make_shared(0, NODE_POSE_2D, 1, NODE_POSE_2D, 20)); + graph.push_back(boost::make_shared(1, NODE_POSE_2D, 2, NODE_POSE_2D, 1)); + graph.push_back(boost::make_shared(2, NODE_POSE_2D, 3, NODE_POSE_2D, 1)); + graph.push_back(boost::make_shared(3, NODE_POSE_2D, 4, NODE_POSE_2D, 1)); + //graph.push_back(boost::make_shared(0, 2, 0, NODE_POSE_3D, NODE_POSE_3D, 1)); + //graph.push_back(boost::make_shared(2, 3, 1, NODE_POSE_3D, NODE_POSE_3D, 1)); + //graph.push_back(boost::make_shared(3, 5, 2, NODE_POSE_3D, NODE_POSE_3D, 20)); + //graph.push_back(boost::make_shared(5, 6, 3, NODE_POSE_3D, NODE_POSE_3D, 1)); + std::vector keys; keys += 0, 1, 2, 3, 4; - WorkSpace workspace(5); - boost::optional actual = edgePartitionByMetis(graph, keys, - workspace, false); + WorkSpace workspace(6); + boost::optional actual = edgePartitionByMetis(graph, keys, + workspace, true); CHECK(actual.is_initialized()); - vector A_expected; A_expected += 0, 2; // frontal - vector B_expected; B_expected += 3, 5, 6; // frontal + vector A_expected; A_expected += 0, 1; // frontal + vector B_expected; B_expected += 2, 3, 4; // frontal vector C_expected; // separator CHECK(A_expected == actual->A); CHECK(B_expected == actual->B);