本文整理汇总了C++中GraphCopy::firstNode方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphCopy::firstNode方法的具体用法?C++ GraphCopy::firstNode怎么用?C++ GraphCopy::firstNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphCopy
的用法示例。
在下文中一共展示了GraphCopy::firstNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doCall
void OptimalRanking::doCall(
const Graph& G,
NodeArray<int> &rank,
EdgeArray<bool> &reversed,
const EdgeArray<int> &length,
const EdgeArray<int> &costOrig)
{
MinCostFlowReinelt<int> mcf;
// construct min-cost flow problem
GraphCopy GC;
GC.createEmpty(G);
// compute connected component of G
NodeArray<int> component(G);
int numCC = connectedComponents(G,component);
// intialize the array of lists of nodes contained in a CC
Array<List<node> > nodesInCC(numCC);
for(node v : G.nodes)
nodesInCC[component[v]].pushBack(v);
EdgeArray<edge> auxCopy(G);
rank.init(G);
for(int i = 0; i < numCC; ++i)
{
GC.initByNodes(nodesInCC[i], auxCopy);
makeLoopFree(GC);
for(edge e : GC.edges)
if(reversed[GC.original(e)])
GC.reverseEdge(e);
// special cases:
if(GC.numberOfNodes() == 1) {
rank[GC.original(GC.firstNode())] = 0;
continue;
} else if(GC.numberOfEdges() == 1) {
edge e = GC.original(GC.firstEdge());
rank[e->source()] = 0;
rank[e->target()] = length[e];
continue;
}
EdgeArray<int> lowerBound(GC,0);
EdgeArray<int> upperBound(GC,mcf.infinity());
EdgeArray<int> cost(GC);
NodeArray<int> supply(GC);
for(edge e : GC.edges)
cost[e] = -length[GC.original(e)];
for(node v : GC.nodes) {
int s = 0;
edge e;
forall_adj_edges(e,v) {
if(v == e->source())
s += costOrig[GC.original(e)];
else
s -= costOrig[GC.original(e)];
}
supply[v] = s;
}
OGDF_ASSERT(isAcyclic(GC) == true);
// find min-cost flow
EdgeArray<int> flow(GC);
NodeArray<int> dual(GC);
#ifdef OGDF_DEBUG
bool feasible =
#endif
mcf.call(GC, lowerBound, upperBound, cost, supply, flow, dual);
OGDF_ASSERT(feasible);
for(node v : GC.nodes)
rank[GC.original(v)] = dual[v];
}
}
示例2: call
void SpringEmbedderFR::call(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
if(G.empty())
return;
// all edges straight-line
AG.clearAllBends();
GraphCopy GC;
GC.createEmpty(G);
// compute connected component of G
NodeArray<int> component(G);
int numCC = connectedComponents(G,component);
// intialize the array of lists of nodes contained in a CC
Array<List<node> > nodesInCC(numCC);
node v;
forall_nodes(v,G)
nodesInCC[component[v]].pushBack(v);
EdgeArray<edge> auxCopy(G);
Array<DPoint> boundingBox(numCC);
int i;
for(i = 0; i < numCC; ++i)
{
GC.initByNodes(nodesInCC[i],auxCopy);
GraphCopyAttributes AGC(GC,AG);
node vCopy;
forall_nodes(vCopy, GC) {
node vOrig = GC.original(vCopy);
AGC.x(vCopy) = AG.x(vOrig);
AGC.y(vCopy) = AG.y(vOrig);
}
// original
if (initialize(GC, AGC) == true)
{
for(int i = 1; i <= m_iterations; i++)
mainStep(GC, AGC);
}
cleanup();
// end original
node vFirst = GC.firstNode();
double minX = AGC.x(vFirst), maxX = AGC.x(vFirst),
minY = AGC.y(vFirst), maxY = AGC.y(vFirst);
forall_nodes(vCopy,GC) {
node v = GC.original(vCopy);
AG.x(v) = AGC.x(vCopy);
AG.y(v) = AGC.y(vCopy);
if(AG.x(v)-AG.width (v)/2 < minX) minX = AG.x(v)-AG.width(v) /2;
if(AG.x(v)+AG.width (v)/2 > maxX) maxX = AG.x(v)+AG.width(v) /2;
if(AG.y(v)-AG.height(v)/2 < minY) minY = AG.y(v)-AG.height(v)/2;
if(AG.y(v)+AG.height(v)/2 > maxY) maxY = AG.y(v)+AG.height(v)/2;
}
示例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
void GEMLayout::call(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
if(G.empty())
return;
// all edges straight-line
AG.clearAllBends();
GraphCopy GC;
GC.createEmpty(G);
// compute connected component of G
NodeArray<int> component(G);
int numCC = connectedComponents(G,component);
// intialize the array of lists of nodes contained in a CC
Array<List<node> > nodesInCC(numCC);
for(node v : G.nodes)
nodesInCC[component[v]].pushBack(v);
EdgeArray<edge> auxCopy(G);
Array<DPoint> boundingBox(numCC);
int i;
for(i = 0; i < numCC; ++i)
{
GC.initByNodes(nodesInCC[i],auxCopy);
GraphCopyAttributes AGC(GC,AG);
for(node vCopy : GC.nodes) {
node vOrig = GC.original(vCopy);
AGC.x(vCopy) = AG.x(vOrig);
AGC.y(vCopy) = AG.y(vOrig);
}
SList<node> permutation;
// initialize node data
m_impulseX.init(GC,0);
m_impulseY.init(GC,0);
m_skewGauge.init(GC,0);
m_localTemperature.init(GC,m_initialTemperature);
// initialize other data
m_globalTemperature = m_initialTemperature;
m_barycenterX = 0;
m_barycenterY = 0;
for(node v : GC.nodes) {
m_barycenterX += weight(v) * AGC.x(v);
m_barycenterY += weight(v) * AGC.y(v);
}
m_cos = cos(m_oscillationAngle / 2.0);
m_sin = sin(Math::pi / 2 + m_rotationAngle / 2.0);
// main loop
int counter = m_numberOfRounds;
while(OGDF_GEOM_ET.greater(m_globalTemperature,m_minimalTemperature) && counter--) {
// choose nodes by random permutations
if(permutation.empty()) {
for(node v : GC.nodes)
permutation.pushBack(v);
permutation.permute(m_rng);
}
node v = permutation.popFrontRet();
// compute the impulse of node v
computeImpulse(GC,AGC,v);
// update node v
updateNode(GC,AGC,v);
}
node vFirst = GC.firstNode();
double minX = AGC.x(vFirst), maxX = AGC.x(vFirst),
minY = AGC.y(vFirst), maxY = AGC.y(vFirst);
for(node vCopy : GC.nodes) {
node v = GC.original(vCopy);
AG.x(v) = AGC.x(vCopy);
AG.y(v) = AGC.y(vCopy);
if(AG.x(v)-AG.width (v)/2 < minX) minX = AG.x(v)-AG.width(v) /2;
if(AG.x(v)+AG.width (v)/2 > maxX) maxX = AG.x(v)+AG.width(v) /2;
if(AG.y(v)-AG.height(v)/2 < minY) minY = AG.y(v)-AG.height(v)/2;
if(AG.y(v)+AG.height(v)/2 > maxY) maxY = AG.y(v)+AG.height(v)/2;
}
minX -= m_minDistCC;
minY -= m_minDistCC;
for(node vCopy : GC.nodes) {
node v = GC.original(vCopy);
AG.x(v) -= minX;
AG.y(v) -= minY;
}
//.........这里部分代码省略.........