forall_nodes(vh,G) { cout << vh << ":"; adjEntry adj; forall_adj(adj,vh) cout << " " << adj; cout << endl; }
// The check function below tests if the current OrthoRep instance really // represents a correct orthogonal representation, i.e., it tests if // * the associated graph is embedded. // * the external face of the embedding is set // * the sum of the angles at each vertex is 4 // * if corresponding bend strings are consistent, that is, if e has // adj. entries adjSrc and adjTgt, then the bend string of adjTgt // is the string obtained from bend string of adjSrc by reversing the // sequence and flipping the bits // * the shape of each face is rectagonal, i.e., if // #zeros(f) - #ones(f) - 2|f| + sum of angles at vertices in f // is 4 if f is an internal face or -4 if f is the external face. bool OrthoRep::check(String &error) { const Graph &G = (Graph&) *m_pE; // is the associated graph embedded ? if (G.representsCombEmbedding() == false) { error = "Graph is not embedded!"; return false; } // sum of angles at each vertex equals 4 ? node v; forall_nodes(v,G) { int sumAngles = 0; adjEntry adj; forall_adj(adj,v) sumAngles += angle(adj); if(sumAngles != 4) { error.sprintf("Angle sum at vertex %d is %d.", v->index(), sumAngles); return false; } }
void randomTriconnectedGraph(Graph &G, int n, double p1, double p2) { if(n < 4) n = 4; // start with K_4 completeGraph(G,4); // nodes[0],...,nodes[i-1] is array of all nodes Array<node> nodes(n); node v; int i = 0; forall_nodes(v,G) nodes[i++] = v; // Will be used below as array of neighbors of v Array<edge> neighbors(n); // used to mark neighbors // 0 = not marked // 1 = marked left // 2 = marked right // 3 = marked both Array<int> mark(0,n-1,0); for(; i < n; ++i) { // pick a random node v = nodes[randomNumber(0,i-1)]; // create a new node w such that v is split into v and w node w = nodes[i] = G.newNode(); // build array of all neighbors int d = v->degree(); int j = 0; adjEntry adj; forall_adj(adj,v) neighbors[j++] = adj->theEdge(); // mark two distinct neighbors for left for(j = 2; j > 0; ) { int r = randomNumber(0,d-1); if((mark[r] & 1) == 0) { mark[r] |= 1; --j; } } // mark two distinct neighbors for right for(j = 2; j > 0; ) { int r = randomNumber(0,d-1); if((mark[r] & 2) == 0) { mark[r] |= 2; --j; } } for(j = 0; j < d; ++j) { int m = mark[j]; mark[j] = 0; // decide to with which node each neighbor is connected // (possible: v, w, or both) double x = randomDouble(0.0,1.0); switch(m) { case 0: if(x < p1) m = 1; else if(x < p1+p2) m = 2; else m = 3; break; case 1: case 2: if(x >= p1+p2) m = 3; break; } // move edge or create new one if necessary edge e = neighbors[j]; switch(m) { case 2: if(v == e->source()) G.moveSource(e,w); else G.moveTarget(e,w); break; case 3: G.newEdge(w,e->opposite(v)); break; } } G.newEdge(v,w); } }