本文整理汇总了C++中GraphCopy::initByNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphCopy::initByNodes方法的具体用法?C++ GraphCopy::initByNodes怎么用?C++ GraphCopy::initByNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphCopy
的用法示例。
在下文中一共展示了GraphCopy::initByNodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: call
void GEMLayout::call(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
if(G.empty())
return;
OGDF_ASSERT(m_numberOfRounds >= 0);
OGDF_ASSERT(DIsGreaterEqual(m_minimalTemperature,0));
OGDF_ASSERT(DIsGreaterEqual(m_initialTemperature,m_minimalTemperature));
OGDF_ASSERT(DIsGreaterEqual(m_gravitationalConstant,0));
OGDF_ASSERT(DIsGreaterEqual(m_desiredLength,0));
OGDF_ASSERT(DIsGreaterEqual(m_maximalDisturbance,0));
OGDF_ASSERT(DIsGreaterEqual(m_rotationAngle,0));
OGDF_ASSERT(DIsLessEqual(m_rotationAngle,pi / 2));
OGDF_ASSERT(DIsGreaterEqual(m_oscillationAngle,0));
OGDF_ASSERT(DIsLessEqual(m_oscillationAngle,pi / 2));
OGDF_ASSERT(DIsGreaterEqual(m_rotationSensitivity,0));
OGDF_ASSERT(DIsLessEqual(m_rotationSensitivity,1));
OGDF_ASSERT(DIsGreaterEqual(m_oscillationSensitivity,0));
OGDF_ASSERT(DIsLessEqual(m_oscillationSensitivity,1));
OGDF_ASSERT(m_attractionFormula == 1 || m_attractionFormula == 2);
// 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);
}
SList<node> permutation;
node v;
// 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;
forall_nodes(v,GC) {
m_barycenterX += weight(v) * AGC.x(v);
m_barycenterY += weight(v) * AGC.y(v);
}
示例3: doCall
void OptimalRanking::doCall(
const Graph& G,
NodeArray<int> &rank,
EdgeArray<bool> &reversed,
const EdgeArray<int> &length,
const EdgeArray<int> &costOrig)
{
MinCostFlowReinelt 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);
node v;
forall_nodes(v,G)
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);
edge e;
forall_edges(e,GC)
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) {
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);
forall_edges(e,GC)
cost[e] = -length[GC.original(e)];
node v;
forall_nodes(v,GC) {
int s = 0;
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);
forall_nodes(v,GC)
rank[GC.original(v)] = dual[v];
}
示例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;
}
//.........这里部分代码省略.........