/** * Return first path found from start vertex to end vertex * as a vector of edges, or NULL of no such path is found. */ bool findDfsVertexPathMarking(vector<Vertex*> &path, Vertex *start, const Vertex *end) { mMarks.clear(); path.clear(); if (mEdges.find(start) != mEdges.end()) { mMarks.insert(start); path.push_back(start); return findDfsVertexPathMarkingRec(path, end); } return false; }
VertSet Vert::one_ring() { VertSet result = VertSet(); Edge *e = edge; do { result.insert(e->pair->vert); e = e->pair->prev; } while(e != edge); return result; }
/** * Add an edge if both vertices are non-NULL and distinct */ bool addEdge(Vertex *vertA, Vertex *vertB) { if (vertA == NULL || vertB == NULL || vertA == vertB) return false; // no side effects on failure addVertex(vertA); addVertex(vertB); if (mEdges.find(vertA) == mEdges.end()) { mEdges.insert(EdgeMap::value_type(vertA, new VertSet())); } VertSet *nexts = mEdges.at(vertA); return nexts->insert(vertB).second; }
VertSet Vert::two_ring() { VertSet result = VertSet(); VertSet first_ring = edge->vert->one_ring(); for (VertSet_IT it = first_ring.begin(); it != first_ring.end(); it++) { VertSet temp_ring = (*it)->edge->vert->one_ring(); for (VertSet_IT it = temp_ring.begin(); it != temp_ring.end(); it++) { result.insert(*it); } } return result; }
bool findDfsVertexPathRec(vector<Vertex*> &path, const Vertex *end) const { Vertex *lastVert = path.back(); if (lastVert == end) return true; if (mEdges.find(lastVert) != mEdges.end()) { VertSet *nexts = mEdges.at(lastVert); for (auto it = nexts->begin(); it != nexts->end(); ++it) { path.push_back(*it); bool found = findDfsVertexPathRec(path, end); if ( found ) return found; else path.pop_back(); } } return false; }
void Network::Reset(int n,int s,int t) { _V.resize(n); _E.clear(); for (_s = 0;_s < n;_s++) { _V[_s].e = _V[_s].l = _V[_s].o = -1; } _s = s,_t = t; }
void TimeSliceObservableCDT::process(const std::vector<Vertex*>& state) { // define a timelike direction that is the future Vertex* cur = state[0]; Vertex* future = cur->getNeighbouringVertex(); Triangle *f, *p; Vertex::getAdjacentTriangles(cur, future, &f, &p); if (!f->isTimelike(cur, future)) future = f->getThirdVertex(cur, future); for (unsigned int t = 0; t < T; t++) { unsigned int count = 0; // find spacelike loop at cur Vertex::getAdjacentTriangles(cur, future, &f, &p); VertSet n = cur->getSectorVertices(f, future, false); BOOST_ASSERT(n.size() == 1); // CDT constraint Vertex* prev = *n.begin(); Vertex* lc = cur; do { VertSet sec = lc->getOtherSectorVertices(prev); BOOST_ASSERT(sec.size() == 1); // CDT constraint prev = lc; lc = *sec.begin(); count++; } while (lc != cur); Vertex* newfut = *future->getOtherSectorVertices(cur).begin(); cur = future; future = newfut; volumeProfile[t] = count; } }
bool DVGraph::findDfsVertexPathMarkingRec(vector<Vertex*> &path, const Vertex *end) { Vertex *lastVert = path.back(); if (lastVert == end) return true; if (mEdges.find(lastVert) != mEdges.end()) { VertSet *nexts = mEdges.at(lastVert); for (VertSet::iterator it = nexts->begin(); it != nexts->end(); ++it) { Vertex *vert = *it; if (mMarks.find(vert) == mMarks.end()) { mMarks.insert(vert); path.push_back(vert); bool found = findDfsVertexPathMarkingRec(path, end); if ( found ) return found; else path.pop_back(); } } } return false; }
VertSet intersection(const VertSet &set1, const VertSet &set2) { VertSet result = VertSet(); for (VertSet_const_IT it = set1.begin(); it != set1.end(); it++) { if (set2.find(*it) != set2.end()) { result.insert(*it); } } return result; }
bool addVertex(Vertex *vert) { return mVerts.insert(vert).second; }
int Network::Dinic() { int maxflow = 0; int u,v,e,ee,f; IntArray q; _E.resize(_E.size()+1); _E.back().v = _s; while (true) { for (u = 0;u < _V.size();u++) _V[u].l = -1; _V[_s].l = f = 0; _V[_s].o = _V[_s].e; q.clear(); q.push_back(_s); while (f < (int)q.size()) { u = q[f++]; for (e = _V[u].e;e != -1;e = _E[e].n) { v = _E[e].v; if (_V[v].l == -1 && _E[e].c > 0) { _V[v].o = _V[v].e; _V[v].l = _V[u].l+1; q.push_back(v); } } } if (_V[_t].l == -1) break; q.clear(); q.push_back(_E.size()-1); while (!q.empty()) { u = _E[q.back()].v; if (u == _t) { for (f = INT_MAX,e = 1;e < (int)q.size();e++) if (_E[q[e]].c < f) f = _E[q[e]].c,u = e; for (e = 1;e < q.size();e++) { _E[q[e]].c -= f; _E[q[e]^1].c += f; } maxflow += f; q.resize(u); } else { for (e = _V[u].o;e != -1;e = _E[e].n) { if (_V[_E[e].v].l < 0 || _E[e].c < 1) continue; if (_V[_E[e].v].l == _V[u].l+1) break; } if ((_V[u].o = e) != -1) q.push_back(e); else { q.pop_back(); _V[u].l = -1; } } } } return maxflow; }