本文整理汇总了C++中hypergraph::VertexSet类的典型用法代码示例。如果您正苦于以下问题:C++ VertexSet类的具体用法?C++ VertexSet怎么用?C++ VertexSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VertexSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateInitialization
bool SparseOptimizer::updateInitialization(HyperGraph::VertexSet& vset, HyperGraph::EdgeSet& eset)
{
std::vector<HyperGraph::Vertex*> newVertices;
newVertices.reserve(vset.size());
_activeVertices.reserve(_activeVertices.size() + vset.size());
//for (HyperGraph::VertexSet::iterator it = vset.begin(); it != vset.end(); ++it)
//_activeVertices.push_back(static_cast<OptimizableGraph::Vertex*>(*it));
_activeEdges.reserve(_activeEdges.size() + eset.size());
for (HyperGraph::EdgeSet::iterator it = eset.begin(); it != eset.end(); ++it)
_activeEdges.push_back(static_cast<OptimizableGraph::Edge*>(*it));
// update the index mapping
size_t next = _ivMap.size();
for (HyperGraph::VertexSet::iterator it = vset.begin(); it != vset.end(); ++it) {
OptimizableGraph::Vertex* v=static_cast<OptimizableGraph::Vertex*>(*it);
if (! v->fixed()){
if (! v->marginalized()){
v->setTempIndex(next);
_ivMap.push_back(v);
newVertices.push_back(v);
_activeVertices.push_back(v);
next++;
}
else // not supported right now
abort();
}
else {
v->setTempIndex(-1);
}
}
//if (newVertices.size() != vset.size())
//cerr << __PRETTY_FUNCTION__ << ": something went wrong " << PVAR(vset.size()) << " " << PVAR(newVertices.size()) << endl;
return _solver->updateStructure(newVertices, eset);
}
示例2: starsInEdge
void starsInEdge(StarSet& stars, HyperGraph::Edge* e, EdgeStarMap& esmap, HyperGraph::VertexSet& gauge){
for (size_t i=0; i<e->vertices().size(); i++){
OptimizableGraph::Vertex* v=(OptimizableGraph::Vertex*)e->vertices()[i];
if (gauge.find(v)==gauge.end())
starsInVertex(stars, v, esmap);
}
}
示例3: push
void OptimizableGraph::push(HyperGraph::VertexSet& vset) {
for (HyperGraph::VertexSet::iterator it = vset.begin(); it != vset.end();
it++) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
v->push();
}
}
示例4: shortestPaths
void HyperDijkstra::shortestPaths(HyperGraph::Vertex* v, HyperDijkstra::CostFunction* cost, double maxDistance,
double comparisonConditioner, bool directed, double maxEdgeCost)
{
HyperGraph::VertexSet vset;
vset.insert(v);
shortestPaths(vset, cost, maxDistance, comparisonConditioner, directed, maxEdgeCost);
}
示例5: setFixed
void OptimizableGraph::setFixed(HyperGraph::VertexSet& vset, bool fixed)
{
for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
v->setFixed(fixed);
}
}
示例6: discardTop
void OptimizableGraph::discardTop(HyperGraph::VertexSet& vset)
{
for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
v->discardTop();
}
}
示例7: saveGnuplot
bool saveGnuplot(const std::string& gnudump, const OptimizableGraph& optimizer)
{
HyperGraph::VertexSet vset;
for (HyperGraph::VertexIDMap::const_iterator it=optimizer.vertices().begin(); it!=optimizer.vertices().end(); it++){
vset.insert(it->second);
}
return saveGnuplot(gnudump, vset, optimizer.edges());
}
示例8: push
void SparseOptimizer::push(HyperGraph::VertexSet& vlist)
{
for (HyperGraph::VertexSet::iterator it = vlist.begin(); it != vlist.end(); ++it) {
OptimizableGraph::Vertex* v = dynamic_cast<OptimizableGraph::Vertex*>(*it);
if (v)
v->push();
else
cerr << __FUNCTION__ << ": FATAL PUSH SET" << endl;
}
}
示例9: pop
void SparseOptimizer::pop(HyperGraph::VertexSet& vlist)
{
for (HyperGraph::VertexSet::iterator it = vlist.begin(); it != vlist.end(); ++it){
OptimizableGraph::Vertex* v = dynamic_cast<OptimizableGraph::Vertex*> (*it);
if (v)
v->pop();
else
cerr << "FATAL POP SET" << endl;
}
}
示例10: shortestPaths
void HyperDijkstra::shortestPaths(HyperGraph::VertexSet& vset, HyperDijkstra::CostFunction* cost,
double maxDistance, double comparisonConditioner, bool directed, double maxEdgeCost)
{
reset();
std::priority_queue< AdjacencyMapEntry > frontier;
for (HyperGraph::VertexSet::iterator vit=vset.begin(); vit!=vset.end(); ++vit){
HyperGraph::Vertex* v=*vit;
AdjacencyMap::iterator it=_adjacencyMap.find(v);
assert(it!=_adjacencyMap.end());
it->second._distance=0.;
it->second._parent=0;
frontier.push(it->second);
}
while(! frontier.empty()){
AdjacencyMapEntry entry=frontier.top();
frontier.pop();
HyperGraph::Vertex* u=entry.child();
AdjacencyMap::iterator ut=_adjacencyMap.find(u);
assert(ut!=_adjacencyMap.end());
double uDistance=ut->second.distance();
std::pair< HyperGraph::VertexSet::iterator, bool> insertResult=_visited.insert(u); (void) insertResult;
HyperGraph::EdgeSet::iterator et=u->edges().begin();
while (et != u->edges().end()){
HyperGraph::Edge* edge=*et;
++et;
if (directed && edge->vertex(0) != u)
continue;
for (size_t i = 0; i < edge->vertices().size(); ++i) {
HyperGraph::Vertex* z = edge->vertex(i);
if (z == u)
continue;
double edgeDistance=(*cost)(edge, u, z);
if (edgeDistance==std::numeric_limits< double >::max() || edgeDistance > maxEdgeCost)
continue;
double zDistance=uDistance+edgeDistance;
//cerr << z->id() << " " << zDistance << endl;
AdjacencyMap::iterator ot=_adjacencyMap.find(z);
assert(ot!=_adjacencyMap.end());
if (zDistance+comparisonConditioner<ot->second.distance() && zDistance<maxDistance){
ot->second._distance=zDistance;
ot->second._parent=u;
ot->second._edge=edge;
frontier.push(ot->second);
}
}
}
}
}
示例11: initializeOptimization
bool SparseOptimizer::initializeOptimization(int level)
{
HyperGraph::VertexSet vset;
for (VertexIDMap::iterator
it = vertices().begin();
it != vertices().end();
it++)
vset.insert(it->second);
return initializeOptimization(vset,level);
}
示例12: computeInitialGuess
void SparseOptimizer::computeInitialGuess(EstimatePropagatorCost& costFunction)
{
OptimizableGraph::VertexSet emptySet;
std::set<Vertex*> backupVertices;
HyperGraph::VertexSet fixedVertices; // these are the root nodes where to start the initialization
for (EdgeContainer::iterator it = _activeEdges.begin(); it != _activeEdges.end(); ++it) {
OptimizableGraph::Edge* e = *it;
for (size_t i = 0; i < e->vertices().size(); ++i) {
OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(e->vertex(i));
if (!v)
continue;
if (v->fixed())
fixedVertices.insert(v);
else { // check for having a prior which is able to fully initialize a vertex
for (EdgeSet::const_iterator vedgeIt = v->edges().begin(); vedgeIt != v->edges().end(); ++vedgeIt) {
OptimizableGraph::Edge* vedge = static_cast<OptimizableGraph::Edge*>(*vedgeIt);
if (vedge->vertices().size() == 1 && vedge->initialEstimatePossible(emptySet, v) > 0.) {
//cerr << "Initialize with prior for " << v->id() << endl;
vedge->initialEstimate(emptySet, v);
fixedVertices.insert(v);
}
}
}
if (v->hessianIndex() == -1) {
std::set<Vertex*>::const_iterator foundIt = backupVertices.find(v);
if (foundIt == backupVertices.end()) {
v->push();
backupVertices.insert(v);
}
}
}
}
EstimatePropagator estimatePropagator(this);
estimatePropagator.propagate(fixedVertices, costFunction);
// restoring the vertices that should not be initialized
for (std::set<Vertex*>::iterator it = backupVertices.begin(); it != backupVertices.end(); ++it) {
Vertex* v = *it;
v->pop();
}
if (verbose()) {
computeActiveErrors();
cerr << "iteration= -1\t chi2= " << activeChi2()
<< "\t time= 0.0"
<< "\t cumTime= 0.0"
<< "\t (using initial guess from " << costFunction.name() << ")" << endl;
}
}
示例13: 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());
}
}
示例14: connectedSubset
void HyperDijkstra::connectedSubset(HyperGraph::VertexSet& connected, HyperGraph::VertexSet& visited,
HyperGraph::VertexSet& startingSet,
HyperGraph* g, HyperGraph::Vertex* v,
HyperDijkstra::CostFunction* cost, double distance,
double comparisonConditioner, double maxEdgeCost)
{
typedef std::queue<HyperGraph::Vertex*> VertexDeque;
visited.clear();
connected.clear();
VertexDeque frontier;
HyperDijkstra dv(g);
connected.insert(v);
frontier.push(v);
while (! frontier.empty()) {
HyperGraph::Vertex* v0=frontier.front();
frontier.pop();
dv.shortestPaths(v0, cost, distance, comparisonConditioner, false, maxEdgeCost);
for (HyperGraph::VertexSet::iterator it=dv.visited().begin(); it!=dv.visited().end(); ++it) {
visited.insert(*it);
if (startingSet.find(*it)==startingSet.end())
continue;
std::pair<HyperGraph::VertexSet::iterator, bool> insertOutcome=connected.insert(*it);
if (insertOutcome.second) { // the node was not in the connectedSet;
frontier.push(dynamic_cast<HyperGraph::Vertex*>(*it));
}
}
}
}
示例15: buildIndexMapping
bool SparseOptimizer::initializeOptimization
(HyperGraph::VertexSet& vset, int level)
{
// Recorre todos los vertices introducidos en el optimizador.
// Para cada vertice 'V' obtiene los edges de los que forma parte.
// Para cada uno de esos edges, se mira si todos sus vertices estan en el
// optimizador. Si lo estan, el edge se aniade a _activeEdges.
// Si el vertice 'V' tiene algun edge con todos los demas vertices en el
// optimizador, se aniade 'V' a _activeVertices
// Al final se asignan unos indices internos para los vertices:
// -1: vertices fijos
// 0..n: vertices no fijos y NO marginalizables
// n+1..m: vertices no fijos y marginalizables
clearIndexMapping();
_activeVertices.clear();
_activeVertices.reserve(vset.size());
_activeEdges.clear();
set<Edge*> auxEdgeSet; // temporary structure to avoid duplicates
for (HyperGraph::VertexSet::iterator
it = vset.begin();
it != vset.end();
it++)
{
OptimizableGraph::Vertex* v= (OptimizableGraph::Vertex*) *it;
const OptimizableGraph::EdgeSet& vEdges=v->edges();
// count if there are edges in that level. If not remove from the pool
int levelEdges=0;
for (OptimizableGraph::EdgeSet::const_iterator
it = vEdges.begin();
it != vEdges.end();
it++)
{
OptimizableGraph::Edge* e =
reinterpret_cast<OptimizableGraph::Edge*>(*it);
if (level < 0 || e->level() == level)
{
bool allVerticesOK = true;
for (vector<HyperGraph::Vertex*>::const_iterator
vit = e->vertices().begin();
vit != e->vertices().end();
++vit)
{
if (vset.find(*vit) == vset.end())
{
allVerticesOK = false;
break;
}
}
if (allVerticesOK)
{
auxEdgeSet.insert(reinterpret_cast<OptimizableGraph::Edge*>(*it));
levelEdges++;
}
}
}
if (levelEdges) _activeVertices.push_back(v);
}
_activeEdges.reserve(auxEdgeSet.size());
for (set<Edge*>::iterator
it = auxEdgeSet.begin();
it != auxEdgeSet.end();
++it)
_activeEdges.push_back(*it);
sortVectorContainers();
return buildIndexMapping(_activeVertices);
}