本文整理汇总了C++中GraphCopy::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphCopy::copy方法的具体用法?C++ GraphCopy::copy怎么用?C++ GraphCopy::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphCopy
的用法示例。
在下文中一共展示了GraphCopy::copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: constructMergeGraph
bool FeasibleUpwardPlanarSubgraph::constructMergeGraph(
GraphCopy &M,
adjEntry adj_orig,
const List<edge> &orig_edges)
{
CombinatorialEmbedding Beta(M);
//set ext. face of Beta
adjEntry ext_adj = M.copy(adj_orig->theEdge())->adjSource();
Beta.setExternalFace(Beta.rightFace(ext_adj));
FaceSinkGraph fsg(Beta, M.copy(adj_orig->theNode()));
SList<node> aug_nodes;
SList<edge> aug_edges;
SList<face> fList;
fsg.possibleExternalFaces(fList); // use this method to call the methode checkForest()
node v_ext = fsg.faceNodeOf(Beta.externalFace());
OGDF_ASSERT(v_ext != 0);
fsg.stAugmentation(v_ext, M, aug_nodes, aug_edges);
//add the deleted edges
for(edge eOrig: orig_edges) {
node a = M.copy(eOrig->source());
node b = M.copy(eOrig->target());
M.newEdge(a, b);
}
return (isAcyclic(M));
}
示例2: call
Module::ReturnType FeasibleUpwardPlanarSubgraph::call(
const Graph &G,
GraphCopy &FUPS,
adjEntry &extFaceHandle,
List<edge> &delEdges,
bool multisources)
{
FUPS = GraphCopy(G);
delEdges.clear();
node s_orig;
hasSingleSource(G, s_orig);
List<edge> nonTreeEdges_orig;
getSpanTree(FUPS, nonTreeEdges_orig, true, multisources);
CombinatorialEmbedding Gamma(FUPS);
nonTreeEdges_orig.permute(); // random order
//insert nonTreeEdges
while (!nonTreeEdges_orig.empty()) {
// make identical copy GC of Fups
//and insert e_orig in GC
GraphCopy GC = FUPS;
edge e_orig = nonTreeEdges_orig.popFrontRet();
//node a = GC.copy(e_orig->source());
//node b = GC.copy(e_orig->target());
GC.newEdge(e_orig);
if (UpwardPlanarity::upwardPlanarEmbed_singleSource(GC)) { //upward embedded the fups and check feasibility
CombinatorialEmbedding Beta(GC);
//choose a arbitrary feasibel ext. face
FaceSinkGraph fsg(Beta, GC.copy(s_orig));
SList<face> ext_faces;
fsg.possibleExternalFaces(ext_faces);
OGDF_ASSERT(!ext_faces.empty());
Beta.setExternalFace(ext_faces.front());
GraphCopy M = GC; // use a identical copy of GC to constrcut the merge graph of GC
adjEntry extFaceHandle_cur = getAdjEntry(Beta, GC.copy(s_orig), Beta.externalFace());
adjEntry adj_orig = GC.original(extFaceHandle_cur->theEdge())->adjSource();
if (constructMergeGraph(M, adj_orig, nonTreeEdges_orig)) {
FUPS = GC;
extFaceHandle = FUPS.copy(GC.original(extFaceHandle_cur->theEdge()))->adjSource();
continue;
}
else {
//Beta is not feasible
delEdges.pushBack(e_orig);
}
}
else {
// not ok, GC is not feasible
delEdges.pushBack(e_orig);
}
}
return Module::retFeasible;
}
示例3: clusterConnection
//todo: is called only once, but could be sped up the same way as the co-conn check
void MaxCPlanarMaster::clusterConnection(cluster c, GraphCopy &gc, double &upperBoundC) {
// For better performance, a node array is used to indicate which nodes are contained
// in the currently considered cluster.
NodeArray<bool> vInC(gc,false);
// First check, if the current cluster \a c is a leaf cluster.
// If so, compute the number of edges that have at least to be added
// to make the cluster induced graph connected.
if (c->cCount()==0) { //cluster \a c is a leaf cluster
GraphCopy *inducedC = new GraphCopy((const Graph&)gc);
List<node> clusterNodes;
c->getClusterNodes(clusterNodes); // \a clusterNodes now contains all (original) nodes of cluster \a c.
for (node w : clusterNodes) {
vInC[gc.copy(w)] = true;
}
// Delete all nodes from \a inducedC that do not belong to the cluster,
// in order to obtain the cluster induced graph.
node v = inducedC->firstNode();
while (v!=nullptr) {
node w = v->succ();
if (!vInC[inducedC->original(v)]) inducedC->delNode(v);
v = w;
}
// Determine number of connected components of cluster induced graph.
//Todo: check could be skipped
if (!isConnected(*inducedC)) {
NodeArray<int> conC(*inducedC);
int nCC = connectedComponents(*inducedC,conC);
//at least #connected components - 1 edges have to be added.
upperBoundC -= (nCC-1)*m_largestConnectionCoeff;
}
delete inducedC;
// Cluster \a c is an "inner" cluster. Process all child clusters first.
} else { //c->cCount is != 0, process all child clusters first
for (cluster ci : c->children) {
clusterConnection(ci, gc, upperBoundC);
}
// Create cluster induced graph.
GraphCopy *inducedC = new GraphCopy((const Graph&)gc);
List<node> clusterNodes;
c->getClusterNodes(clusterNodes); //\a clusterNodes now contains all (original) nodes of cluster \a c.
for (node w : clusterNodes) {
vInC[gc.copy(w)] = true;
}
node v = inducedC->firstNode();
while (v!=nullptr) {
node w = v->succ();
if (!vInC[inducedC->original(v)]) inducedC->delNode(v);
v = w;
}
// Now collapse each child cluster to one node and determine #connected components of \a inducedC.
List<node> oChildClusterNodes;
List<node> cChildClusterNodes;
for (cluster ci : c->children) {
ci->getClusterNodes(oChildClusterNodes);
// Compute corresponding nodes of graph \a inducedC.
for (node u : oChildClusterNodes) {
node copy = inducedC->copy(gc.copy(u));
cChildClusterNodes.pushBack(copy);
}
inducedC->collapse(cChildClusterNodes);
oChildClusterNodes.clear();
cChildClusterNodes.clear();
}
// Now, check \a inducedC for connectivity.
if (!isConnected(*inducedC)) {
NodeArray<int> conC(*inducedC);
int nCC = connectedComponents(*inducedC,conC);
//at least #connected components - 1 edges have to added.
upperBoundC -= (nCC-1)*m_largestConnectionCoeff;
}
delete inducedC;
}
}//clusterConnection
示例4: call
//.........这里部分代码省略.........
SList<Tuple2<node,node> > augmented;
GraphCopySimple graphAcyclicTest(G);
for(edge eG : G.edges)
{
// already treated ?
if(visitedEdge[eG] == true)
continue;
// insert edge into H
edge eH = H.newEdge(mapToH[eG->source()],mapToH[eG->target()]);
node superSink;
SList<edge> augmentedEdges;
if (UpwardPlanarity::upwardPlanarAugment_singleSource(H,superSink,augmentedEdges) == false) {
// if H is no longer upward planar, remove eG from subgraph
H.delEdge(eH);
delEdges.pushBack(eG);
} else {
// add augmented edges as node-pair to tmpAugmented and remove
// all augmented edges from H again
SList<Tuple2<node,node> > tmpAugmented;
SListConstIterator<edge> it;
for(it = augmentedEdges.begin(); it.valid(); ++it) {
node v = mapToG[(*it)->source()];
node w = mapToG[(*it)->target()];
if (v && w)
tmpAugmented.pushBack(Tuple2<node,node>(v,w));
H.delEdge(*it);
}
if (mapToG[superSink] == nullptr)
H.delNode(superSink);
//****************************************************************
// The following is a simple workaround to assure the following
// property of the upward planar subgraph:
// The st-augmented upward planar subgraph plus the edges not
// in the subgraph must be acyclic. (This is a special property
// of the embedding, not the augmentation.)
// The upward-planar embedding function gives us ANY upward-planar
// embedding. We check if the property above holds with this
// embedding. If it doesn't, we have actually no idea if another
// embedding would do.
// The better solution would be to incorporate the acyclicity
// property into the upward-planarity test, but this is compicated.
//****************************************************************
// test if original graph plus augmented edges is still acyclic
if(checkAcyclic(graphAcyclicTest,tmpAugmented) == true) {
augmented = tmpAugmented;
} else {
// if not, remove eG from subgraph
H.delEdge(eH);
delEdges.pushBack(eG);
}
}
}
// remove edges not in the subgraph from GC
ListConstIterator<edge> itE;
for(itE = delEdges.begin(); itE.valid(); ++itE)
GC.delEdge(GC.copy(*itE));
// add augmented edges to GC
SListConstIterator<Tuple2<node,node> > itP;
for(itP = augmented.begin(); itP.valid(); ++itP) {
node v = (*itP).x1();
node w = (*itP).x2();
GC.newEdge(GC.copy(v),GC.copy(w));
}
// add super sink to GC
node sGC = nullptr;
SList<node> sinks;
for(node v : GC.nodes) {
if(v->indeg() == 0)
sGC = v;
if(v->outdeg() == 0)
sinks.pushBack(v);
}
node superSinkGC = GC.newNode();
SListConstIterator<node> itV;
for(itV = sinks.begin(); itV.valid(); ++itV)
GC.newEdge(*itV,superSinkGC);
// add st-edge to GC, so that we now have a planar st-digraph
GC.newEdge(sGC,superSinkGC);
OGDF_ASSERT(isAcyclic(GC));
OGDF_ASSERT(isPlanar(GC));
}
示例5: constructMergeGraph
bool FUPSSimple::constructMergeGraph(GraphCopy &M, adjEntry adj_orig, const List<edge> &orig_edges)
{
CombinatorialEmbedding Beta(M);
//set ext. face of Beta
adjEntry ext_adj = M.copy(adj_orig->theEdge())->adjSource();
Beta.setExternalFace(Beta.rightFace(ext_adj));
//*************************** debug ********************************
/*
cout << endl << "FUPS : " << endl;
for(face ff : Beta.faces) {
cout << "face " << ff->index() << ": ";
adjEntry adjNext = ff->firstAdj();
do {
cout << adjNext->theEdge() << "; ";
adjNext = adjNext->faceCycleSucc();
} while(adjNext != ff->firstAdj());
cout << endl;
}
if (Beta.externalFace() != 0)
cout << "ext. face of the graph is: " << Beta.externalFace()->index() << endl;
else
cout << "no ext. face set." << endl;
*/
FaceSinkGraph fsg(Beta, M.copy(adj_orig->theNode()));
SList<node> aug_nodes;
SList<edge> aug_edges;
SList<face> fList;
fsg.possibleExternalFaces(fList); // use this method to call the methode checkForest()
node v_ext = fsg.faceNodeOf(Beta.externalFace());
OGDF_ASSERT(v_ext != 0);
fsg.stAugmentation(v_ext, M, aug_nodes, aug_edges);
/*
//------------------------------------debug
GraphAttributes AG(M, GraphAttributes::nodeGraphics|
GraphAttributes::edgeGraphics|
GraphAttributes::nodeColor|
GraphAttributes::edgeColor|
GraphAttributes::nodeLabel|
GraphAttributes::edgeLabel
);
// label the nodes with their index
for(node v : AG.constGraph().nodes) {
AG.label(v) = to_string(v->index());
}
AG.writeGML("c:/temp/MergeFUPS.gml");
*/
OGDF_ASSERT(isStGraph(M));
//add the deleted edges
for(edge eOrig : orig_edges) {
node a = M.copy(eOrig->source());
node b = M.copy(eOrig->target());
M.newEdge(a, b);
}
return (isAcyclic(M));
}
示例6: schnyderEmbedding
void SchnyderLayout::schnyderEmbedding(
GraphCopy& GC,
GridLayout &gridLayout,
adjEntry adjExternal)
{
NodeArray<int> &xcoord = gridLayout.x();
NodeArray<int> &ycoord = gridLayout.y();
node v;
List<node> L; // (un)contraction order
GraphCopy T = GraphCopy(GC); // the realizer tree (reverse direction of edges!!!)
EdgeArray<int> rValues(T); // the realizer values
// choose outer face a,b,c
adjEntry adja;
if (adjExternal != 0) {
edge eG = adjExternal->theEdge();
edge eGC = GC.copy(eG);
adja = (adjExternal == eG->adjSource()) ? eGC->adjSource() : eGC->adjTarget();
}
else {
adja = GC.firstEdge()->adjSource();
}
adjEntry adjb = adja->faceCyclePred();
adjEntry adjc = adjb->faceCyclePred();
node a = adja->theNode();
node b = adjb->theNode();
node c = adjc->theNode();
node a_in_T = T.copy(GC.original(a));
node b_in_T = T.copy(GC.original(b));
node c_in_T = T.copy(GC.original(c));
contract(GC, a, b, c, L);
realizer(GC, L, a, b, c, rValues, T);
NodeArray<int> t1(T);
NodeArray<int> t2(T);
NodeArray<int> val(T, 1);
NodeArray<int> P1(T);
NodeArray<int> P3(T);
NodeArray<int> v1(T);
NodeArray<int> v2(T);
subtreeSizes(rValues, 1, a_in_T, t1);
subtreeSizes(rValues, 2, b_in_T, t2);
prefixSum(rValues, 1, a_in_T, val, P1);
prefixSum(rValues, 3, c_in_T, val, P3);
// now Pi = depth of all nodes in Tree T(i) (depth[root] = 1)
prefixSum(rValues, 2, b_in_T, t1, v1);
// special treatment for a
v1[a_in_T] = t1[a_in_T];
/*
* v1[v] now is the sum of the
* "count of nodes in t1" minus the "subtree size for node x"
* for every node x on a path from b to v in t2
*/
prefixSum(rValues, 3, c_in_T, t1, val);
// special treatment for a
val[a_in_T] = t1[a_in_T];
/*
* val[v] now is the sum of the
* "count of nodes in t1" minus the "subtree size for node x"
* for every node x on a path from c to v in t3
*/
// r1[v]=v1[v]+val[v]-t1[v] is the number of nodes in region 1 from v
forall_nodes(v, T) {
// calc v1'
v1[v] += val[v] - t1[v] - P3[v];
}
示例7: realizer
/*
* Construct the realiszer and the Tree T
* rValues = realizer value
* T = Tree
*/
void SchnyderLayout::realizer(
GraphCopy& G,
const List<node>& L,
node a,
node b,
node c,
EdgeArray<int>& rValues,
GraphCopy& T)
{
int i = 0;
edge e;
NodeArray<int> ord(G, 0);
// ordering: b,c,L,a
ord[b] = i++;
ord[c] = i++;
for(node v : L) {
ord[v] = i++; // enumerate V(G)
}
ord[a] = i++;
// remove all edges (they will be re-added later with different orientation)
while (T.numberOfEdges() > 0) {
e = T.firstEdge();
T.delEdge(e);
}
for(node v : L) {
node u = T.copy(G.original(v)); // u is copy of v in T
adjEntry adj = nullptr;
for(adjEntry adjRun : v->adjEdges) {
if (ord[adjRun->twinNode()] > ord[v]) {
adj = adjRun;
break;
}
}
adjEntry adj1 = adj;
while (ord[adj1->twinNode()] > ord[v]) {
adj1 = adj1->cyclicSucc();
}
e = T.newEdge(T.copy(G.original(adj1->twinNode())), u);
rValues[e] = 2;
adjEntry adj2 = adj;
while (ord[adj2->twinNode()] > ord[v]) {
adj2 = adj2->cyclicPred();
}
e = T.newEdge(T.copy(G.original(adj2->twinNode())), u);
rValues[e] = 3;
for (adj = adj1->cyclicSucc(); adj != adj2; adj = adj->cyclicSucc()) {
e = T.newEdge(u, T.copy(G.original(adj->twinNode())));
rValues[e] = 1;
}
}
// special treatement of a,b,c
node a_in_T = T.copy(G.original(a));
node b_in_T = T.copy(G.original(b));
node c_in_T = T.copy(G.original(c));
// all edges to node a get realizer value 1
for(adjEntry adj : a->adjEdges) {
e = T.newEdge(a_in_T, T.copy(G.original(adj->twinNode())));
rValues[e] = 1;
}
// rest of outer triangle (reciprocal linked, realizer values 2 and 3)
e = T.newEdge(b_in_T, a_in_T);
rValues[e] = 2;
e = T.newEdge(b_in_T, c_in_T);
rValues[e] = 2;
e = T.newEdge(c_in_T, a_in_T);
rValues[e] = 3;
e = T.newEdge(c_in_T, b_in_T);
rValues[e] = 3;
}