本文整理汇总了C++中GraphAttributes::has方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphAttributes::has方法的具体用法?C++ GraphAttributes::has怎么用?C++ GraphAttributes::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphAttributes
的用法示例。
在下文中一共展示了GraphAttributes::has方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepareGraphAttributes
void MultilevelGraph::prepareGraphAttributes(GraphAttributes &GA) const
{
long additionalAttributes = 0;
if (!GA.has(GraphAttributes::edgeDoubleWeight)) {
additionalAttributes |= GraphAttributes::edgeDoubleWeight;
}
if (!GA.has(GraphAttributes::nodeWeight)) {
additionalAttributes |= GraphAttributes::nodeWeight;
}
GA.addAttributes(additionalAttributes);
}
示例2: call
void StressMinimization::call(GraphAttributes& GA)
{
const Graph& G = GA.constGraph();
// if the graph has at most one node nothing to do
if (G.numberOfNodes() <= 1) {
// make it exception save
for(node v : G.nodes)
{
GA.x(v) = 0;
GA.y(v) = 0;
}
return;
}
if (m_componentLayout && !isConnected(G)) {
OGDF_THROW(PreconditionViolatedException);
return;
}
NodeArray<NodeArray<double> > shortestPathMatrix(G);
NodeArray<NodeArray<double> > weightMatrix(G);
initMatrices(G, shortestPathMatrix, weightMatrix);
// if the edge costs are defined by the attribute copy it to an array and
// construct the proper shortest path matrix
if (m_hasEdgeCostsAttribute) {
if (!GA.has(GraphAttributes::edgeDoubleWeight)) {
OGDF_THROW(PreconditionViolatedException);
return;
}
m_avgEdgeCosts = dijkstra_SPAP(GA, shortestPathMatrix);
// compute shortest path all pairs
} else {
m_avgEdgeCosts = m_edgeCosts;
bfs_SPAP(G, shortestPathMatrix, m_edgeCosts);
}
call(GA, shortestPathMatrix, weightMatrix);
}
示例3: pivotMDSLayout
void PivotMDS::pivotMDSLayout(GraphAttributes& GA)
{
const Graph& G = GA.constGraph();
bool use3D = GA.has(GraphAttributes::threeD) && DIMENSION_COUNT > 2;
const int n = G.numberOfNodes();
// trivial cases
if (n == 0)
return;
if (n == 1) {
node v1 = G.firstNode();
GA.x(v1) = 0.0;
GA.y(v1) = 0.0;
if (use3D)
GA.z(v1) = 0.0;
return;
}
// check whether the graph is a path or not
const node head = getRootedPath(G);
if (head != nullptr) {
doPathLayout(GA, head);
}
else {
Array<Array<double> > pivDistMatrix;
// compute the pivot matrix
getPivotDistanceMatrix(GA, pivDistMatrix);
// center the pivot matrix
centerPivotmatrix(pivDistMatrix);
// init the coordinate matrix
Array<Array<double> > coord(DIMENSION_COUNT);
for (int i = 0; i < coord.size(); i++) {
coord[i].init(n);
}
// init the eigen values array
Array<double> eVals(DIMENSION_COUNT);
singularValueDecomposition(pivDistMatrix, coord, eVals);
// compute the correct aspect ratio
for (int i = 0; i < coord.size(); i++) {
eVals[i] = sqrt(eVals[i]);
for (int j = 0; j < n; j++) {
coord[i][j] *= eVals[i];
}
}
// set the new positions to the graph
int i = 0;
for (node v : G.nodes)
{
GA.x(v) = coord[0][i];
GA.y(v) = coord[1][i];
if (use3D){
GA.z(v) = coord[2][i];//cout << coord[2][i] << "\n";
}
++i;
}
}
}
示例4: minimizeStress
void StressMinimization::minimizeStress(
GraphAttributes& GA,
NodeArray<NodeArray<double> >& shortestPathMatrix,
NodeArray<NodeArray<double> >& weightMatrix)
{
const Graph& G = GA.constGraph();
int numberOfPerformedIterations = 0;
double prevStress = numeric_limits<double>::max();
double curStress = numeric_limits<double>::max();
if (m_terminationCriterion == STRESS) {
curStress = calcStress(GA, shortestPathMatrix, weightMatrix);
}
NodeArray<double> newX;
NodeArray<double> newY;
NodeArray<double> newZ;
if (m_terminationCriterion == POSITION_DIFFERENCE) {
newX.init(G);
newY.init(G);
if (GA.has(GraphAttributes::threeD))
newZ.init(G);
}
do {
if (m_terminationCriterion == POSITION_DIFFERENCE) {
if (GA.has(GraphAttributes::threeD))
copyLayout(GA, newX, newY, newZ);
else copyLayout(GA, newX, newY);
}
nextIteration(GA, shortestPathMatrix, weightMatrix);
if (m_terminationCriterion == STRESS) {
prevStress = curStress;
curStress = calcStress(GA, shortestPathMatrix, weightMatrix);
}
} while (!finished(GA, ++numberOfPerformedIterations, newX, newY, prevStress, curStress));
Logger::slout() << "Iteration count:\t" << numberOfPerformedIterations
<< "\tStress:\t" << calcStress(GA, shortestPathMatrix, weightMatrix) << endl;
}
示例5: 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);
}
示例6: 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";
}
}
示例7: write_ogml_graph
// write graph structure with attributes
static void write_ogml_graph(const GraphAttributes &A, ostream &os)
{
const Graph &G = A.constGraph();
GraphIO::indent(os,2) << "<structure>\n";
for(node v : G.nodes) {
GraphIO::indent(os,3) << "<node id=\"n" << v->index() << "\">\n";
if (A.has(GraphAttributes::nodeLabel)) {
GraphIO::indent(os,4) << "<label id=\"ln" << v->index() << "\">\n";
GraphIO::indent(os,5) << "<content>" << formatLabel(A.label(v)) << "</content>\n";
GraphIO::indent(os,4) << "</label>\n";
}
GraphIO::indent(os,3) << "</node>\n";
}
write_ogml_graph_edges(A, os);
GraphIO::indent(os,2) << "</structure>\n";
}
示例8: calcStress
double StressMinimization::calcStress(
const GraphAttributes& GA,
NodeArray<NodeArray<double> >& shortestPathMatrix,
NodeArray<NodeArray<double> >& weightMatrix)
{
double stress = 0;
for (node v = GA.constGraph().firstNode(); v != nullptr; v = v->succ()) {
for (node w = v->succ(); w != nullptr; w = w->succ()) {
double xDiff = GA.x(v) - GA.x(w);
double yDiff = GA.y(v) - GA.y(w);
double zDiff = 0.0;
if (GA.has(GraphAttributes::threeD))
{
zDiff = GA.z(v) - GA.z(w);
}
double dist = sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);
if (dist != 0) {
stress += weightMatrix[v][w] * (shortestPathMatrix[v][w] - dist)
* (shortestPathMatrix[v][w] - dist);//
}
}
}
return stress;
}
示例9: write_ogml_layout_nodes_edges
static void write_ogml_layout_nodes_edges(const GraphAttributes &A, ostream &os)
{
const Graph &G = A.constGraph();
if (A.has(GraphAttributes::nodeGraphics | GraphAttributes::nodeStyle))
{
for(node v : G.nodes) {
GraphIO::indent(os,4) << "<nodeStyle idRef=\"n" << v->index() << "\">\n";
if(A.has(GraphAttributes::nodeGraphics)) {
GraphIO::indent(os,5) << "<location x=\"" << A.x(v)-0.5*A.width(v) << "\" y=\""<< A.y(v)-0.5*A.height(v) << "\" />\n";
GraphIO::indent(os,5) << "<shape type=\"";
switch (A.shape(v)) {
case shRect:
os << "rect";
break;
case shRoundedRect:
os << "roundedRect";
break;
case shEllipse:
os << "ellipse";
break;
case shTriangle:
os << "triangle";
break;
case shPentagon:
os << "pentagon";
break;
case shHexagon:
os << "hexagon";
break;
case shOctagon:
os << "octagon";
break;
case shRhomb:
os << "rhomb";
break;
case shTrapeze:
os << "trapeze";
break;
case shParallelogram:
os << "parallelogram";
break;
case shInvTriangle:
os << "invTriangle";
break;
case shInvTrapeze:
os << "invTrapeze";
break;
case shInvParallelogram:
os << "invParallelogram";
break;
case shImage:
os << "image";
break;
}
os << "\" width=\"" << A.width(v) << "\" height=\"" << A.height(v) << "\" />\n";
}
if(A.has(GraphAttributes::nodeStyle)) {
// fill-tag
GraphIO::indent(os,5) << "<fill";
// color-attribute of fill-tag
os << " color=\"" << A.fillColor(v) << "\"";
// pattern- and patternColor-attribute of fill-tag (closing)
os << " pattern=\"" << fillPatternToOGML(A.fillPattern(v)) << "\" patternColor=\"" << A.fillBgColor(v) << "\" />\n";
// line-tag
GraphIO::indent(os,5) << "<line type=\"" << edgeStyleToOGML(A.strokeType(v)) << "\" width=\"" << A.strokeWidth(v) << "\""
<< " color=\"" << A.strokeColor(v) << "\"";
// closing fill-tag
os << " />\n";
}
GraphIO::indent(os,4) << "</nodeStyle>\n";
}
}
if (A.has(GraphAttributes::edgeGraphics | GraphAttributes::edgeStyle))
{
int pointId = 0;
for(edge e : G.edges) {
GraphIO::indent(os,4) << "<edgeStyle idRef=\"e" << e->index() << "\">\n";
if(A.has(GraphAttributes::edgeStyle)) {
GraphIO::indent(os,5) << "<line ";
if (A.has(GraphAttributes::edgeStyle)) {
os << "type=\"" << edgeStyleToOGML(A.strokeType(e)) << "\" width=\"" << A.strokeWidth(e) << "\" ";
os << "color=\"" << A.strokeColor(e) << "\" />\n";
} else {
os << " />\n";
}
}
// TODO review the handling of edge arrows
if(A.has(GraphAttributes::edgeArrow))
{
//.........这里部分代码省略.........
示例10: nextIteration
void StressMinimization::nextIteration(
GraphAttributes& GA,
NodeArray<NodeArray<double> >& shortestPathMatrix,
NodeArray<NodeArray<double> >& weights)
{
const Graph& G = GA.constGraph();
for (node v : G.nodes)
{
double newXCoord = 0.0;
double newYCoord = 0.0;
double newZCoord = 0.0;
double& currXCoord = GA.x(v);
double& currYCoord = GA.y(v);
double totalWeight = 0;
for (node w : G.nodes)
{
if (v == w) {
continue;
}
// calculate euclidean distance between both points
double xDiff = currXCoord - GA.x(w);
double yDiff = currYCoord - GA.y(w);
double zDiff = (GA.has(GraphAttributes::threeD)) ? GA.z(v) - GA.z(w) : 0.0;
double euclideanDist = sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);
// get the weight
double weight = weights[v][w];
// get the desired distance
double desDistance = shortestPathMatrix[v][w];
// reset the voted x coordinate
// if x is not fixed
if (!m_fixXCoords) {
double voteX = GA.x(w);
if (euclideanDist != 0) {
// calc the vote
voteX += desDistance * (currXCoord - voteX) / euclideanDist;
}
// add the vote
newXCoord += weight * voteX;
}
// reset the voted y coordinate
// y is not fixed
if (!m_fixYCoords) {
double voteY = GA.y(w);
if (euclideanDist != 0) {
// calc the vote
voteY += desDistance * (currYCoord - voteY) / euclideanDist;
}
newYCoord += weight * voteY;
}
if (GA.has(GraphAttributes::threeD))
{
// reset the voted z coordinate
// z is not fixed
if (!m_fixZCoords) {
double voteZ = GA.z(w);
if (euclideanDist != 0) {
// calc the vote
voteZ += desDistance * (GA.z(v) - voteZ) / euclideanDist;
}
newZCoord += weight * voteZ;
}
}
// sum up the weights
totalWeight += weight;
}
// update the positions
if (totalWeight != 0) {
if (!m_fixXCoords) {
currXCoord = newXCoord / totalWeight;
}
if (!m_fixYCoords) {
currYCoord = newYCoord / totalWeight;
}
if (GA.has(GraphAttributes::threeD))
{
if (!m_fixZCoords) {
GA.z(v) = newZCoord / totalWeight;
}
}
}
}
}
示例11: read
//.........这里部分代码省略.........
case stipplePredefKey: //line style
if(graphicsObject->m_valueType != gmlIntValue) break;
stipple = graphicsObject->m_intValue;
}
}
break; }
case templatePredefKey:
if (nodeSon->m_valueType != gmlStringValue) break;
templ = nodeSon->m_stringValue;
break;
case labelPredefKey:
if (nodeSon->m_valueType != gmlStringValue) break;
label = nodeSon->m_stringValue;
break;
case edgeWeightPredefKey: //sic!
if (nodeSon->m_valueType != gmlIntValue) break;
weight = nodeSon->m_intValue;
break;
}
}
// check if everything required is defined correctly
if (vId == notDefined) {
setError("node id not defined");
return false;
}
// create new node if necessary and assign attributes
if (m_mapToNode[vId] == nullptr) m_mapToNode[vId] = G.newNode();
node v = m_mapToNode[vId];
if (AG.has(GraphAttributes::nodeGraphics))
{
AG.x(v) = x;
AG.y(v) = y;
AG.width (v) = w;
AG.height(v) = h;
AG.shape(v) = strToShape[shape];
}
if (AG.has(GraphAttributes::nodeLabel))
AG.label(m_mapToNode[vId]) = label;
if (AG.has(GraphAttributes::nodeTemplate))
AG.templateNode(m_mapToNode[vId]) = templ;
if (AG.has(GraphAttributes::nodeId))
AG.idNode(m_mapToNode[vId]) = vId;
if (AG.has(GraphAttributes::nodeWeight))
AG.weight(m_mapToNode[vId]) = weight;
if (AG.has(GraphAttributes::nodeStyle))
{
AG.fillColor(m_mapToNode[vId]) = fill;
AG.strokeColor(m_mapToNode[vId]) = line;
AG.setFillPattern(m_mapToNode[vId], intToFillPattern(pattern));
AG.setStrokeType(m_mapToNode[vId], intToStrokeType(stipple));
AG.strokeWidth(m_mapToNode[vId]) = lineWidth;
}
}//node
//Todo: line style set stipple value
break;
case edgePredefKey: {
string arrow; // the arrow type attribute
string fill; //the color fill attribute
int stipple = 1; //the line style
float lineWidth = 1.0f;