本文整理汇总了C++中GraphAttributes::constGraph方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphAttributes::constGraph方法的具体用法?C++ GraphAttributes::constGraph怎么用?C++ GraphAttributes::constGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphAttributes
的用法示例。
在下文中一共展示了GraphAttributes::constGraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: call
void GridLayoutModule::call(GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
// compute grid layout
GridLayout gridLayout(G);
doCall(G,gridLayout,m_gridBoundingBox);
// transform grid layout to real layout
mapGridLayout(G,gridLayout,AG);
}
示例2: addGraphAttributes
//*************************************************************
//adds new GraphAttributes to m_G if maxSubgraph() < 32
//
bool SimDraw::addGraphAttributes(const GraphAttributes & GA)
{
if(maxSubGraph() >= 31)
return false;
//if(compareBy() == label)
OGDF_ASSERT((compareBy() != label) || (m_GA.attributes() & GraphAttributes::edgeLabel));
int max = numberOfBasicGraphs();
bool foundEdge = false;
//node v;
//edge e, f;
Graph G = GA.constGraph();
for(edge e : G.edges) {
for(edge f : m_G.edges) {
if (compare(m_GA, f->source(), GA, e->source())
&& compare(m_GA, f->target(), GA, e->target())) {
foundEdge = true;
m_GA.addSubGraph(f,max);
}
}
if (!foundEdge) {
node s, t;
bool srcFound = false;
bool tgtFound = false;
for(node v : m_G.nodes) {
if (compare(m_GA, v, GA, e->source())) {
s = v;
srcFound = true;
}
if (compare(m_GA, v, GA, e->target())) {
t = v;
tgtFound = true;
}
}
if (!srcFound)
s = m_G.newNode(e->source()->index());
if (!tgtFound)
t = m_G.newNode(e->target()->index());
edge d = m_G.newEdge(s, t);
if(compareBy() == label)
m_GA.label(d) = GA.label(e);
m_GA.addSubGraph(d, max);
}
}
return true;
}// end addGraphAttributes
示例3: copyLayout
void StressMinimization::copyLayout(
const GraphAttributes& GA,
NodeArray<double>& newX,
NodeArray<double>& newY)
{
// copy the layout
for(node v : GA.constGraph().nodes)
{
newX[v] = GA.x(v);
newY[v] = GA.y(v);
}
}
示例4: getPivotDistanceMatrix
void PivotMDS::getPivotDistanceMatrix(
const GraphAttributes& GA,
Array<Array<double> >& pivDistMatrix)
{
const Graph& G = GA.constGraph();
const int n = G.numberOfNodes();
// lower the number of pivots if necessary
int numberOfPivots = min(n, m_numberOfPivots);
// number of pivots times n matrix used to store the graph distances
pivDistMatrix.init(numberOfPivots);
for (int i = 0; i < numberOfPivots; i++) {
pivDistMatrix[i].init(n);
}
// edges costs array
EdgeArray<double> edgeCosts;
bool hasEdgeCosts = false;
// already checked whether this attribute exists or not (see call method)
if (m_hasEdgeCostsAttribute) {
edgeCosts.init(G);
for(edge e : G.edges)
{
edgeCosts[e] = GA.doubleWeight(e);
}
hasEdgeCosts = true;
}
// used for min-max strategy
NodeArray<double> minDistances(G, std::numeric_limits<double>::infinity());
NodeArray<double> shortestPathSingleSource(G);
// the current pivot node
node pivNode = G.firstNode();
for (int i = 0; i < numberOfPivots; i++) {
// get the shortest path from the currently processed pivot node to
// all other nodes in the graph
shortestPathSingleSource.fill(std::numeric_limits<double>::infinity());
if (hasEdgeCosts) {
dijkstra_SPSS(pivNode, G, shortestPathSingleSource, edgeCosts);
} else {
bfs_SPSS(pivNode, G, shortestPathSingleSource, m_edgeCosts);
}
copySPSS(pivDistMatrix[i], shortestPathSingleSource);
// update the pivot and the minDistances array ... to ensure the
// correctness set minDistance of the pivot node to zero
minDistances[pivNode] = 0;
for(node v : G.nodes)
{
minDistances[v] = min(minDistances[v], shortestPathSingleSource[v]);
if (minDistances[v] > minDistances[pivNode]) {
pivNode = v;
}
}
}
}
示例5: numberOfBends
int LayoutStatistics::numberOfBends(
const GraphAttributes &ga,
int *pMinBendsPerEdge,
int *pMaxBendsPerEdge,
double *pAvgBendsPerEdge,
double *pStdDeviation,
bool considerSelfLoops)
{
const Graph &G = ga.constGraph();
int m = G.numberOfEdges();
int totalBends = 0, minBends = numeric_limits<int>::max(), maxBends = 0;
EdgeArray<int> bends(G);
int nSelfLoops = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop()) {
nSelfLoops++;
continue;
}
const DPolyline &dpl = ga.bends(e);
bends[e] = max(0, dpl.size() - 2);
totalBends += bends[e];
minBends = min(minBends, bends[e]);
maxBends = max(maxBends, bends[e]);
}
m -= nSelfLoops;
double avgBends = double(totalBends) / m;
if(pAvgBendsPerEdge) *pAvgBendsPerEdge = avgBends;
if(pMinBendsPerEdge) *pMinBendsPerEdge = minBends;
if(pMaxBendsPerEdge) *pMaxBendsPerEdge = maxBends;
if(pStdDeviation) {
double sum = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop())
continue;
double d = bends[e] - avgBends;
sum += d*d;
}
*pStdDeviation = sqrt(sum / m);
}
return totalBends;
}
示例6: call
void ComponentSplitterLayout::call(GraphAttributes &GA)
{
// Only do preparations and call if layout is valid
if (m_secondaryLayout.valid())
{
//first we split the graph into its components
const Graph& G = GA.constGraph();
NodeArray<int> componentNumber(G);
m_numberOfComponents = connectedComponents(G, componentNumber);
if (m_numberOfComponents == 0) {
return;
}
//std::vector< std::vector<node> > componentArray;
//componentArray.resize(numComponents);
//Array<GraphAttributes *> components(numComponents);
//
// intialize the array of lists of nodes contained in a CC
nodesInCC.init(m_numberOfComponents);
node v;
forall_nodes(v,G)
nodesInCC[componentNumber[v]].pushBack(v);
// Create copies of the connected components and corresponding
// GraphAttributes
GraphCopy GC;
GC.createEmpty(G);
EdgeArray<edge> auxCopy(G);
for (int i = 0; i < m_numberOfComponents; i++)
{
GC.initByNodes(nodesInCC[i],auxCopy);
GraphAttributes cGA(GC, GA.attributes());
//copy information into copy GA
forall_nodes(v, GC)
{
cGA.width(v) = GA.width(GC.original(v));
cGA.height(v) = GA.height(GC.original(v));
cGA.x(v) = GA.x(GC.original(v));
cGA.y(v) = GA.y(GC.original(v));
}
// copy information on edges
if (GA.attributes() & GraphAttributes::edgeDoubleWeight) {
edge e;
forall_edges(e, GC) {
cGA.doubleWeight(e) = GA.doubleWeight(GC.original(e));
}
}
示例7: callFixEmbed
void PlanarGridLayoutModule::callFixEmbed(GraphAttributes &AG, adjEntry adjExternal)
{
const Graph &G = AG.constGraph();
// compute grid layout
GridLayout gridLayout(G);
if (!handleTrivial(G, gridLayout, m_gridBoundingBox)) {
doCall(G, adjExternal, gridLayout, m_gridBoundingBox, true);
}
// transform grid layout to real layout
mapGridLayout(G,gridLayout,AG);
}
示例8: call
void FastMultipoleMultilevelEmbedder::call(GraphAttributes &GA)
{
EdgeArray<float> edgeLengthAuto(GA.constGraph());
computeAutoEdgeLength(GA, edgeLengthAuto);
const Graph& t = GA.constGraph();
if (t.numberOfNodes() <= 25)
{
FastMultipoleEmbedder fme;
fme.setNumberOfThreads(this->m_iMaxNumThreads);
fme.setRandomize(true);
fme.setNumIterations(500);
fme.call(GA);
return;
}
run(GA, edgeLengthAuto);
for(edge e : GA.constGraph().edges)
{
GA.bends(e).clear();
}
}
示例9: pivotMDSLayout
void PivotMDS::pivotMDSLayout(GraphAttributes& GA)
{
const Graph& G = GA.constGraph();
if (G.numberOfNodes() <= 1) {
// make it exception save
node v;
forall_nodes(v,G)
{
GA.x(v) = 0.0;
GA.y(v) = 0.0;
if (DIMENSION_COUNT > 2)
GA.z(v) = 0.0;
}
示例10: call
void PivotMDS::call(GraphAttributes& GA)
{
if (!isConnected(GA.constGraph())) {
OGDF_THROW_PARAM(PreconditionViolatedException,pvcConnected);
return;
}
if (m_hasEdgeCostsAttribute
&& !GA.has(GraphAttributes::edgeDoubleWeight)) {
OGDF_THROW(PreconditionViolatedException);
return;
}
pivotMDSLayout(GA);
}
示例11: computeFirstRadius
//chooses the initial radius of the disk as half the maximum of width and height of
//the initial layout or depending on the value of m_fineTune
void DavidsonHarel::computeFirstRadius(const GraphAttributes &AG)
{
const Graph &G = AG.constGraph();
node v = G.firstNode();
double minX = AG.x(v);
double minY = AG.y(v);
double maxX = minX;
double maxY = minY;
forall_nodes(v,G) {
minX = min(minX,AG.x(v));
maxX = max(maxX,AG.x(v));
minY = min(minY,AG.y(v));
maxY = max(maxY,AG.y(v));
}
示例12: computeAutoEdgeLength
void FastMultipoleMultilevelEmbedder::computeAutoEdgeLength(const GraphAttributes& GA, EdgeArray<float>& edgeLength, float factor)
{
for(edge e : GA.constGraph().edges)
{
node v = e->source();
node w = e->target();
float radius_v = (float)sqrt(GA.width(v)*GA.width(v) + GA.height(v)*GA.height(v)) * 0.5f;
float radius_w = (float)sqrt(GA.width(w)*GA.width(w) + GA.height(w)*GA.height(w)) * 0.5f;
float sum = radius_v + radius_w;
if (OGDF_GEOM_ET.equal(sum, (float) 0))
sum = 1.0;
edgeLength[e] = factor*(sum);
}
}
示例13: initFinestLevel
void FastMultipoleMultilevelEmbedder::initFinestLevel(GraphAttributes &GA, const EdgeArray<float>& edgeLength)
{
#if 0
NodeArray<float> perimeter(GA.constGraph(), 0.0);
#endif
for(node v : GA.constGraph().nodes)
{
GalaxyMultilevel::LevelNodeInfo& nodeInfo = (*(m_pFinestLevel->m_pNodeInfo))[v];
nodeInfo.mass = 1.0;
float r = (float)sqrt(GA.width(v)*GA.width(v) + GA.height(v)*GA.height(v)) * 0.5f;
nodeInfo.radius = r;
}
for(edge e : GA.constGraph().edges)
{
GalaxyMultilevel::LevelEdgeInfo& edgeInfo = (*(m_pFinestLevel->m_pEdgeInfo))[e];
node v = e->source();
node w = e->target();
GalaxyMultilevel::LevelNodeInfo& vNodeInfo = (*(m_pFinestLevel->m_pNodeInfo))[v];
GalaxyMultilevel::LevelNodeInfo& wNodeInfo = (*(m_pFinestLevel->m_pNodeInfo))[w];
edgeInfo.length = (vNodeInfo.radius + wNodeInfo.radius) + edgeLength[e];
}
}
示例14: placeIsolatedNodes
//the vertices with degree zero are placed below all other vertices on a horizontal
// line centered with repect to the rest of the drawing
void DavidsonHarel::placeIsolatedNodes(GraphAttributes &AG) const {
double minX = 0.0;
double minY = 0.0;
double maxX = 0.0;
if (!m_nonIsolatedNodes.empty()) {
//compute a rectangle that includes all non-isolated vertices
node vFirst = m_nonIsolatedNodes.front();
minX = AG.x(vFirst);
minY = AG.y(vFirst);
maxX = minX;
double maxY = minY;
for (node v : m_nonIsolatedNodes) {
double xVal = AG.x(v);
double yVal = AG.y(v);
double halfHeight = AG.height(v) / 2.0;
double halfWidth = AG.width(v) / 2.0;
if (xVal - halfWidth < minX) minX = xVal - halfWidth;
if (xVal + halfWidth > maxX) maxX = xVal + halfWidth;
if (yVal - halfHeight < minY) minY = yVal - halfHeight;
if (yVal + halfHeight > maxY) maxY = yVal + halfHeight;
}
}
// compute the width and height of the largest isolated node
List<node> isolated;
const Graph &G = AG.constGraph();
double maxWidth = 0;
double maxHeight = 0;
for (node v : G.nodes)
if (v->degree() == 0) {
isolated.pushBack(v);
if (AG.height(v) > maxHeight) maxHeight = AG.height(v);
if (AG.width(v) > maxWidth) maxWidth = AG.width(v);
}
// The nodes are placed on a line in the middle under the non isolated vertices.
// Each node gets a box sized 2 maxWidth.
double boxWidth = 2.0*maxWidth;
double commonYCoord = minY - (1.5*maxHeight);
double XCenterOfDrawing = minX + ((maxX - minX) / 2.0);
double startXCoord = XCenterOfDrawing - 0.5*(isolated.size()*boxWidth);
double xcoord = startXCoord;
for (node v : isolated) {
AG.x(v) = xcoord;
AG.y(v) = commonYCoord;
xcoord += boxWidth;
}
}
示例15: write_ogml_graph_edges
static void write_ogml_graph_edges(const GraphAttributes &A, ostream &os)
{
const Graph &G = A.constGraph();
for(edge e : G.edges) {
GraphIO::indent(os,3) << "<edge id=\"e" << e->index() << "\">\n";
if (A.has(GraphAttributes::edgeLabel)) {
GraphIO::indent(os,4) << "<label id=\"le" << e->index() << "\">\n";
GraphIO::indent(os,5) << "<content>" << formatLabel(A.label(e)) << "</content>\n";
GraphIO::indent(os,4) << "</label>\n";
}
GraphIO::indent(os,4) << "<source idRef=\"n" << e->source()->index() << "\" />\n";
GraphIO::indent(os,4) << "<target idRef=\"n" << e->target()->index() << "\" />\n";
GraphIO::indent(os,3) << "</edge>\n";
}
}