bool isParallelFreeUndirected(const Graph &G) { if (G.numberOfEdges() <= 1) return true; SListPure<edge> edges; EdgeArray<int> minIndex(G), maxIndex(G); parallelFreeSortUndirected(G,edges,minIndex,maxIndex); SListConstIterator<edge> it = edges.begin(); edge ePrev = *it, e; for(it = ++it; it.valid(); ++it, ePrev = e) { e = *it; if (minIndex[ePrev] == minIndex[e] && maxIndex[ePrev] == maxIndex[e]) return false; } return true; }
void OptimalRanking::call (const Graph& G, NodeArray<int> &rank) { List<edge> R; m_subgraph.get().call(G,R); EdgeArray<bool> reversed(G,false); for (edge e : R) reversed[e] = true; R.clear(); EdgeArray<int> length(G,1); if(m_separateMultiEdges) { SListPure<edge> edges; EdgeArray<int> minIndex(G), maxIndex(G); parallelFreeSortUndirected(G, edges, minIndex, maxIndex); SListConstIterator<edge> it = edges.begin(); if(it.valid()) { int prevSrc = minIndex[*it]; int prevTgt = maxIndex[*it]; for(it = it.succ(); it.valid(); ++it) { edge e = *it; if (minIndex[e] == prevSrc && maxIndex[e] == prevTgt) length[e] = 2; else { prevSrc = minIndex[e]; prevTgt = maxIndex[e]; } } } } EdgeArray<int> cost(G,1); doCall(G, rank, reversed, length, cost); }
void planarCNBGraph(Graph &G, int n, int m, int b) { G.clear(); if (b <= 0) b = 1; if (n <= 0) n = 1; if ((m <= 0) || (m > 3*n-6)) m = 3*n-6; node cutv; G.newNode(); for (int nB=1; nB<=b; nB++){ cutv = G.chooseNode(); // set number of nodes for the current created block int actN = randomNumber(1, n); node v1 = G.newNode(); if (actN <= 1){ G.newEdge(v1, cutv); } else if (actN == 2){ node v2 = G.newNode(); G.newEdge(v1, v2); int rnd = randomNumber(1, 2); edge newE; int rnd2 = randomNumber(1, 2); if (rnd == 1){ newE = G.newEdge(v1, cutv); } else{ newE = G.newEdge(v2, cutv); } if (rnd2 == 1){ G.contract(newE); } } else{ // set number of edges for the current created block int actM; if (m > 3*actN-6) actM = randomNumber(1, 3*actN-6); else actM = randomNumber(1, m); if (actM < actN) actM = actN; int ke = actN-3, kf = actM-actN; Array<node> nodes(actN); Array<edge> edges(actM); Array<face> bigFaces(actM); // we start with a triangle node v2 = G.newNode(), v3 = G.newNode(); nodes[0] = v1; nodes[1] = v2; nodes[2] = v3; edges[0] = G.newEdge(v1,v2); edges[1] = G.newEdge(v2,v3); edges[2] = G.newEdge(v3,v1); int actInsertedNodes = 3; CombinatorialEmbedding E(G); FaceArray<int> posBigFaces(E); int nBigFaces = 0, nEdges = 3; while(ke+kf > 0) { int p = randomNumber(1,ke+kf); if (nBigFaces == 0 || p <= ke) { int eNr = randomNumber(0,nEdges-1); edge e = edges[eNr]; face f = E.rightFace(e->adjSource()); face fr = E.rightFace(e->adjTarget()); node u = e->source(); node v = e->target(); edges[nEdges++] = E.split(e); if (e->source() != v && e->source() != u) nodes[actInsertedNodes++] = e->source(); else nodes[actInsertedNodes++] = e->target(); if (f->size() == 4) { posBigFaces[f] = nBigFaces; bigFaces[nBigFaces++] = f; } if (fr->size() == 4) { posBigFaces[fr] = nBigFaces; bigFaces[nBigFaces++] = fr; } ke--; } else { int pos = randomNumber(0,nBigFaces-1); face f = bigFaces[pos]; int df = f->size(); int i = randomNumber(0,df-1), j = randomNumber(2,df-2); adjEntry adj1; for (adj1 = f->firstAdj(); i > 0; adj1 = adj1->faceCycleSucc()) i--; adjEntry adj2; for (adj2 = adj1; j > 0; adj2 = adj2->faceCycleSucc()) j--; edge e = E.splitFace(adj1,adj2); edges[nEdges++] = e; face f1 = E.rightFace(e->adjSource()); face f2 = E.rightFace(e->adjTarget()); bigFaces[pos] = f1; posBigFaces[f1] = pos; if (f2->size() >= 4) { posBigFaces[f2] = nBigFaces; bigFaces[nBigFaces++] = f2; } if (f1->size() == 3) { bigFaces[pos] = bigFaces[--nBigFaces]; } kf--; } } // delete multi edges SListPure<edge> allEdges; EdgeArray<int> minIndex(G), maxIndex(G); parallelFreeSortUndirected(G,allEdges,minIndex,maxIndex); SListConstIterator<edge> it = allEdges.begin(); edge ePrev = *it, e; for(it = ++it; it.valid(); ++it, ePrev = e) { e = *it; if (minIndex[ePrev] == minIndex[e] && maxIndex[ePrev] == maxIndex[e]) { G.move(e, e->adjTarget()->faceCycleSucc()->twin(), ogdf::before, e->adjSource()->faceCycleSucc()->twin(), ogdf::before); } } node cutv2 = nodes[randomNumber(0,actN-1)]; int rnd = randomNumber(1,2); edge newE = G.newEdge(cutv2, cutv); if (rnd == 1){ G.contract(newE); } } } };
void planarBiconnectedGraph(Graph &G, int n, int m, bool multiEdges) { if (n < 3) n = 3; if (m < n) m = n; if (m > 3*n-6) m = 3*n-6; int ke = n-3, kf = m-n; G.clear(); Array<edge> edges(m); Array<face> bigFaces(m); //random_source S; // we start with a triangle node v1 = G.newNode(), v2 = G.newNode(), v3 = G.newNode(); edges[0] = G.newEdge(v1,v2); edges[1] = G.newEdge(v2,v3); edges[2] = G.newEdge(v3,v1); CombinatorialEmbedding E(G); FaceArray<int> posBigFaces(E); int nBigFaces = 0, nEdges = 3; while(ke+kf > 0) { int p = randomNumber(1,ke+kf); if (nBigFaces == 0 || p <= ke) { edge e = edges[randomNumber(0,nEdges-1)]; face f = E.rightFace(e->adjSource()); face fr = E.rightFace(e->adjTarget()); edges[nEdges++] = E.split(e); if (f->size() == 4) { posBigFaces[f] = nBigFaces; bigFaces[nBigFaces++] = f; } if (fr->size() == 4) { posBigFaces[fr] = nBigFaces; bigFaces[nBigFaces++] = fr; } ke--; } else { int pos = randomNumber(0,nBigFaces-1); face f = bigFaces[pos]; int df = f->size(); int i = randomNumber(0,df-1), j = randomNumber(2,df-2); adjEntry adj1; for (adj1 = f->firstAdj(); i > 0; adj1 = adj1->faceCycleSucc()) i--; adjEntry adj2; for (adj2 = adj1; j > 0; adj2 = adj2->faceCycleSucc()) j--; edge e = E.splitFace(adj1,adj2); edges[nEdges++] = e; face f1 = E.rightFace(e->adjSource()); face f2 = E.rightFace(e->adjTarget()); bigFaces[pos] = f1; posBigFaces[f1] = pos; if (f2->size() >= 4) { posBigFaces[f2] = nBigFaces; bigFaces[nBigFaces++] = f2; } if (f1->size() == 3) { bigFaces[pos] = bigFaces[--nBigFaces]; } kf--; } } if (multiEdges == false) { SListPure<edge> allEdges; EdgeArray<int> minIndex(G), maxIndex(G); parallelFreeSortUndirected(G,allEdges,minIndex,maxIndex); SListConstIterator<edge> it = allEdges.begin(); edge ePrev = *it, e; for(it = ++it; it.valid(); ++it, ePrev = e) { e = *it; if (minIndex[ePrev] == minIndex[e] && maxIndex[ePrev] == maxIndex[e]) { G.move(e, e->adjTarget()->faceCycleSucc()->twin(), ogdf::before, e->adjSource()->faceCycleSucc()->twin(), ogdf::before); } } } }