本文整理汇总了C++中hypergraph::EdgeSet::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ EdgeSet::insert方法的具体用法?C++ EdgeSet::insert怎么用?C++ EdgeSet::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypergraph::EdgeSet
的用法示例。
在下文中一共展示了EdgeSet::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vertexEdgesInStar
size_t vertexEdgesInStar(HyperGraph::EdgeSet& eset, HyperGraph::Vertex* v, Star* s, EdgeStarMap& esmap){
eset.clear();
for (HyperGraph::EdgeSet::iterator it=v->edges().begin(); it!=v->edges().end(); it++){
HyperGraph::Edge* e=*it;
EdgeStarMap::iterator eit=esmap.find(e);
if (eit!=esmap.end() && eit->second == s)
eset.insert(e);
}
return eset.size();
}
示例2: main
int main(int argc, char** argv) {
CommandArgs arg;
std::string outputFilename;
std::string inputFilename;
arg.param("o", outputFilename, "", "output file name");
arg.paramLeftOver("input-filename ", inputFilename, "", "graph file to read", true);
arg.parseArgs(argc, argv);
OptimizableGraph graph;
if (!graph.load(inputFilename.c_str())){
cerr << "Error: cannot load a file from \"" << inputFilename << "\", aborting." << endl;
return 0;
}
HyperGraph::EdgeSet removedEdges;
HyperGraph::VertexSet removedVertices;
for (HyperGraph::EdgeSet::iterator it = graph.edges().begin(); it!=graph.edges().end(); it++) {
HyperGraph::Edge* e = *it;
EdgeSE2PointXY* edgePointXY = dynamic_cast<EdgeSE2PointXY*>(e);
if (edgePointXY) {
VertexSE2* pose = dynamic_cast<VertexSE2*>(edgePointXY->vertex(0));
VertexPointXY* landmark = dynamic_cast<VertexPointXY*>(edgePointXY->vertex(1));
FeaturePointXYData * feature = new FeaturePointXYData();
feature->setPositionMeasurement(edgePointXY->measurement());
feature->setPositionInformation(edgePointXY->information());
pose->addUserData(feature);
removedEdges.insert(edgePointXY);
removedVertices.insert(landmark);
}
}
for (HyperGraph::EdgeSet::iterator it = removedEdges.begin(); it!=removedEdges.end(); it++){
OptimizableGraph::Edge* e = dynamic_cast<OptimizableGraph::Edge*>(*it);
graph.removeEdge(e);
}
for (HyperGraph::VertexSet::iterator it = removedVertices.begin(); it!=removedVertices.end(); it++){
OptimizableGraph::Vertex* v = dynamic_cast<OptimizableGraph::Vertex*>(*it);
graph.removeVertex(v);
}
if (outputFilename.length()){
graph.save(outputFilename.c_str());
}
}
示例3: computeSimpleStars
void computeSimpleStars(StarSet& stars,
SparseOptimizer* optimizer,
EdgeLabeler* labeler,
EdgeCreator* creator,
OptimizableGraph::Vertex* gauge_,
std::string edgeTag,
std::string vertexTag,
int level,
int step,
int backboneIterations,
int starIterations,
double rejectionThreshold,
bool debug){
cerr << "preforming the tree actions" << endl;
HyperDijkstra d(optimizer);
// compute a spanning tree based on the types of edges and vertices in the pool
EdgeTypesCostFunction f(edgeTag, vertexTag, level);
d.shortestPaths(gauge_,
&f,
std::numeric_limits< double >::max(),
1e-6,
false,
std::numeric_limits< double >::max()/2);
HyperDijkstra::computeTree(d.adjacencyMap());
// constructs the stars on the backbone
BackBoneTreeAction bact(optimizer, vertexTag, level, step);
bact.init();
cerr << "free edges size " << bact.freeEdges().size() << endl;
// perform breadth-first visit of the visit tree and create the stars on the backbone
d.visitAdjacencyMap(d.adjacencyMap(),&bact,true);
stars.clear();
for (VertexStarMultimap::iterator it=bact.vertexStarMultiMap().begin();
it!=bact.vertexStarMultiMap().end(); it++){
stars.insert(it->second);
}
cerr << "stars.size: " << stars.size() << endl;
cerr << "size: " << bact.vertexStarMultiMap().size() << endl;
// for each star
// for all vertices in the backbone, select all edges leading/leaving from that vertex
// that are contained in freeEdges.
// mark the corresponding "open" vertices and add them to a multimap (vertex->star)
// select a gauge in the backbone
// push all vertices on the backbone
// compute an initial guess on the backbone
// one round of optimization backbone
// lock all vertices in the backbone
// push all "open" vertices
// for each open vertex,
// compute an initial guess given the backbone
// do some rounds of solveDirect
// if (fail)
// - remove the vertex and the edges in that vertex from the star
// - make the structures consistent
// pop all "open" vertices
// pop all "vertices" in the backbone
// unfix the vertices in the backbone
int starNum=0;
for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
Star* s =*it;
HyperGraph::VertexSet backboneVertices = s->_lowLevelVertices;
HyperGraph::EdgeSet backboneEdges = s->_lowLevelEdges;
if (backboneEdges.empty())
continue;
// cerr << "optimizing backbone" << endl;
// one of these should be the gauge, to be simple we select the fisrt one in the backbone
OptimizableGraph::VertexSet gauge;
gauge.insert(*backboneVertices.begin());
s->gauge()=gauge;
s->optimizer()->push(backboneVertices);
s->optimizer()->setFixed(gauge,true);
s->optimizer()->initializeOptimization(backboneEdges);
s->optimizer()->computeInitialGuess();
s->optimizer()->optimize(backboneIterations);
s->optimizer()->setFixed(backboneVertices, true);
// cerr << "assignind edges.vertices not in bbone" << endl;
HyperGraph::EdgeSet otherEdges;
HyperGraph::VertexSet otherVertices;
std::multimap<HyperGraph::Vertex*, HyperGraph::Edge*> vemap;
//.........这里部分代码省略.........
示例4: main
//.........这里部分代码省略.........
SparseOptimizer::Edge* e = dynamic_cast<SparseOptimizer::Edge*>(*it);
edges.push_back(e);
}
optimizer.edges().clear();
optimizer.vertices().clear();
optimizer.setVerbose(false);
// sort the edges in a way that inserting them makes sense
sort(edges.begin(), edges.end(), IncrementalEdgesCompare());
double cumTime = 0.;
int vertexCount=0;
int lastOptimizedVertexCount = 0;
int lastVisUpdateVertexCount = 0;
bool freshlyOptimized=false;
bool firstRound = true;
HyperGraph::VertexSet verticesAdded;
HyperGraph::EdgeSet edgesAdded;
for (vector<SparseOptimizer::Edge*>::iterator it = edges.begin(); it != edges.end(); ++it) {
SparseOptimizer::Edge* e = *it;
int doInit = 0;
SparseOptimizer::Vertex* v1 = optimizer.vertex(e->vertices()[0]->id());
SparseOptimizer::Vertex* v2 = optimizer.vertex(e->vertices()[1]->id());
if (! v1) {
SparseOptimizer::Vertex* v = v1 = dynamic_cast<SparseOptimizer::Vertex*>(e->vertices()[0]);
bool v1Added = optimizer.addVertex(v);
//cerr << "adding" << v->id() << "(" << v->dimension() << ")" << endl;
assert(v1Added);
if (! v1Added)
cerr << "Error adding vertex " << v->id() << endl;
else
verticesAdded.insert(v);
doInit = 1;
if (v->dimension() == maxDim)
vertexCount++;
}
if (! v2) {
SparseOptimizer::Vertex* v = v2 = dynamic_cast<SparseOptimizer::Vertex*>(e->vertices()[1]);
bool v2Added = optimizer.addVertex(v);
//cerr << "adding" << v->id() << "(" << v->dimension() << ")" << endl;
assert(v2Added);
if (! v2Added)
cerr << "Error adding vertex " << v->id() << endl;
else
verticesAdded.insert(v);
doInit = 2;
if (v->dimension() == maxDim)
vertexCount++;
}
// adding the edge and initialization of the vertices
{
//cerr << " adding edge " << e->vertices()[0]->id() << " " << e->vertices()[1]->id() << endl;
if (! optimizer.addEdge(e)) {
cerr << "Unable to add edge " << e->vertices()[0]->id() << " -> " << e->vertices()[1]->id() << endl;
} else {
edgesAdded.insert(e);
}
if (doInit) {
OptimizableGraph::Vertex* from = static_cast<OptimizableGraph::Vertex*>(e->vertices()[0]);
OptimizableGraph::Vertex* to = static_cast<OptimizableGraph::Vertex*>(e->vertices()[1]);
switch (doInit){