int main (int argc, char ** argv) { H.init ("Random triangulation", argc,argv, "n=10,t=-1"); int t = H['t']; if (t==-1) t=50*int(H['n'])*int(H['n']); Triangulation T (H['n']); T.inscribe(T.face(Edge(0,1))); { ProgressBar P (t); for (int i=0; i<t; ++i) { T.flip(T.random_edge()); P.set(i); } } T.show(); T.inscribe (T.face (Edge (0,*(T.v[0]->adj.begin())))); T.balance_old(); T.pause(); std::cout << T; }
void FlipGraph::compute(int n) { graph_.clear(); int count = 0; std::queue<std::pair<Triangulation *, int> > queue; std::map<Code, int> indices; // build canonical triangulation on n vertices Triangulation *triangulation = new Triangulation(n); Code *code = new Code(*triangulation); // add canonical triangulation int index = count++; indices[*code] = 0; graph_.push_back(std::vector<int>()); codes_.push_back(*code); queue.push(std::make_pair(triangulation, index)); delete code; // explore flip graph_ using a bfs while (!queue.empty()) { // get current triangulation triangulation = queue.front().first; index = queue.front().second; queue.pop(); // loop through neighboring triangulations int m = triangulation->size(); for (int i = 0; i < m; ++i) { Halfedge *halfedge = triangulation->halfedge(i); if (triangulation->is_representative(halfedge) && triangulation->is_flippable(halfedge)) { triangulation->flip(halfedge); Code triangulation_code(*triangulation); int other_index = 0; if (indices.count(triangulation_code) == 0) { // add newly discovered triangulation other_index = count++; indices[triangulation_code] = other_index; graph_.push_back(std::vector<int>()); codes_.push_back(triangulation_code); queue.push(std::make_pair(new Triangulation(*triangulation), other_index)); } else { // get index of triangulation other_index = indices[triangulation_code]; } // add edge if not already present if (std::count(graph_[index].begin(), graph_[index].end(), other_index) == 0 && index != other_index) { graph_[index].push_back(other_index); } // note: after two flips the halfedge and its twin are swapped // all other edges stay in place. this is crucial since // we loop over all edges. triangulation->flip(halfedge); } } delete triangulation; } }