Skip to content
Permalink
Browse files

using only 'vertex/arc' notation

  • Loading branch information
Sergey Yakushevs
Sergey Yakushevs committed May 31, 2011
1 parent 6e0435a commit 9ab859ad19014dda50a56dd8444b40e32ca8d36a
@@ -11,7 +11,7 @@

/**
* \file qgsgraph.cpp
* \brief implementation QgsGraph, QgsGraphVertex, QgsGraphEdge
* \brief implementation QgsGraph, QgsGraphVertex, QgsGraphArc
*/

#include "qgsgraph.h"
@@ -32,30 +32,30 @@ int QgsGraph::addVertex( const QgsPoint& pt )
return mGraphVertexes.size()-1;
}

int QgsGraph::addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
int QgsGraph::addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties )
{
QgsGraphEdge e;
QgsGraphArc e;

e.mProperties = properties;
e.mOut = outVertexIdx;
e.mIn = inVertexIdx;
mGraphEdges.push_back( e );
int edgeIdx = mGraphEdges.size()-1;
mGraphArc.push_back( e );
int edgeIdx = mGraphArc.size()-1;

mGraphVertexes[ outVertexIdx ].mOutEdges.push_back( edgeIdx );
mGraphVertexes[ inVertexIdx ].mInEdges.push_back( edgeIdx );
mGraphVertexes[ outVertexIdx ].mOutArc.push_back( edgeIdx );
mGraphVertexes[ inVertexIdx ].mInArc.push_back( edgeIdx );

return mGraphEdges.size()-1;
return mGraphArc.size()-1;
}

const QgsGraphVertex& QgsGraph::vertex( int idx ) const
{
return mGraphVertexes[ idx ];
}

const QgsGraphEdge& QgsGraph::edge( int idx ) const
const QgsGraphArc& QgsGraph::arc( int idx ) const
{
return mGraphEdges[ idx ];
return mGraphArc[ idx ];
}


@@ -64,9 +64,9 @@ int QgsGraph::vertexCount() const
return mGraphVertexes.size();
}

int QgsGraph::edgeCount() const
int QgsGraph::arcCount() const
{
return mGraphEdges.size();
return mGraphArc.size();
}

int QgsGraph::findVertex( const QgsPoint& pt ) const
@@ -82,27 +82,27 @@ int QgsGraph::findVertex( const QgsPoint& pt ) const
return -1;
}

QgsGraphEdge::QgsGraphEdge()
QgsGraphArc::QgsGraphArc()
{

}

QVariant QgsGraphEdge::property(int i) const
QVariant QgsGraphArc::property(int i) const
{
return mProperties[ i ];
}

QVector< QVariant > QgsGraphEdge::properties() const
QVector< QVariant > QgsGraphArc::properties() const
{
return mProperties;
}

int QgsGraphEdge::in() const
int QgsGraphArc::in() const
{
return mIn;
}

int QgsGraphEdge::out() const
int QgsGraphArc::out() const
{
return mOut;
}
@@ -113,14 +113,14 @@ QgsGraphVertex::QgsGraphVertex( const QgsPoint& point )

}

QgsGraphEdgeList QgsGraphVertex::outEdges() const
QgsGraphArcIdList QgsGraphVertex::outArc() const
{
return mOutEdges;
return mOutArc;
}

QgsGraphEdgeList QgsGraphVertex::inEdges() const
QgsGraphArcIdList QgsGraphVertex::inArc() const
{
return mInEdges;
return mInArc;
}

QgsPoint QgsGraphVertex::point() const
@@ -38,10 +38,10 @@ class QgsGraphVertex;
* \class QgsGraphEdge
* \brief This class implement a graph edge
*/
class ANALYSIS_EXPORT QgsGraphEdge
class ANALYSIS_EXPORT QgsGraphArc
{
public:
QgsGraphEdge();
QgsGraphArc();

/**
* return property value
@@ -75,7 +75,7 @@ class ANALYSIS_EXPORT QgsGraphEdge
};


typedef QList< int > QgsGraphEdgeList;
typedef QList< int > QgsGraphArcIdList;

/**
* \ingroup analysis
@@ -99,12 +99,12 @@ class ANALYSIS_EXPORT QgsGraphVertex
/**
* return outgoing edges
*/
QgsGraphEdgeList outEdges() const;
QgsGraphArcIdList outArc() const;

/**
* return incoming edges
*/
QgsGraphEdgeList inEdges() const;
QgsGraphArcIdList inArc() const;

/**
* return vertex point
@@ -113,8 +113,8 @@ class ANALYSIS_EXPORT QgsGraphVertex

private:
QgsPoint mCoordinate;
QgsGraphEdgeList mOutEdges;
QgsGraphEdgeList mInEdges;
QgsGraphArcIdList mOutArc;
QgsGraphArcIdList mInArc;

friend class QgsGraph;
};
@@ -141,7 +141,7 @@ class ANALYSIS_EXPORT QgsGraph
/**
* add edge to a graph
*/
int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties );
int addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties );

/**
* retrun vertex count
@@ -156,12 +156,12 @@ class ANALYSIS_EXPORT QgsGraph
/**
* retrun edge count
*/
int edgeCount() const;
int arcCount() const;

/**
* retrun edge at index
*/
const QgsGraphEdge& edge( int idx ) const;
const QgsGraphArc& arc( int idx ) const;

/**
* find vertex by point
@@ -172,7 +172,7 @@ class ANALYSIS_EXPORT QgsGraph
private:
QVector<QgsGraphVertex> mGraphVertexes;

QVector<QgsGraphEdge> mGraphEdges;
QVector<QgsGraphArc> mGraphArc;
};

#endif //QGSGRAPHH
@@ -34,7 +34,7 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
QMap< double, int > not_begin;
QMap< double, int >::iterator it;

// QVector< QPair< cost, edge id > result
// QVector< QPair< cost, arc id > result
QVector< QPair< double, int > > result;

result.reserve( source->vertexCount() );
@@ -56,17 +56,17 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
not_begin.erase( it );

// edge index list
QgsGraphEdgeList l = source->vertex( curVertex ).outEdges();
QgsGraphEdgeList::iterator edgeIt;
for ( edgeIt = l.begin(); edgeIt != l.end(); ++edgeIt )
QgsGraphArcIdList l = source->vertex( curVertex ).outArc();
QgsGraphArcIdList::iterator arcIt;
for ( arcIt = l.begin(); arcIt != l.end(); ++arcIt )
{
const QgsGraphEdge& edge = source->edge( *edgeIt );
double cost = edge.property( criterionNum ).toDouble() + curCost;
const QgsGraphArc& arc = source->arc( *arcIt );
double cost = arc.property( criterionNum ).toDouble() + curCost;

if ( cost < result[ edge.in() ].first )
if ( cost < result[ arc.in() ].first )
{
result[ edge.in() ] = QPair< double, int >( cost, *edgeIt );
not_begin.insert( cost, edge.in() );
result[ arc.in() ] = QPair< double, int >( cost, *arcIt );
not_begin.insert( cost, arc.in() );
}
}
}
@@ -88,10 +88,10 @@ void QgsGraphAnalyzer::shortestpath( const QgsGraph* source, int startPointIdx,
{
if ( result[ i ].first < std::numeric_limits<double>::infinity() && result[i].second != -1)
{
const QgsGraphEdge& edge = source->edge( result[i].second );
const QgsGraphArc& arc = source->arc( result[i].second );

treeResult->addEdge( source2result[ edge.out() ], source2result[ i ],
edge.properties() );
treeResult->addArc( source2result[ arc.out() ], source2result[ i ],
arc.properties() );
}
}
}
@@ -40,7 +40,7 @@ void QgsGraphBuilder::addVertex( int, const QgsPoint& pt )

void QgsGraphBuilder::addArc( int pt1id, const QgsPoint&, int pt2id, const QgsPoint&, const QVector< QVariant >& prop )
{
mGraph->addEdge( pt1id, pt2id, prop );
mGraph->addArc( pt1id, pt2id, prop );
}

QgsGraph* QgsGraphBuilder::graph()
@@ -316,10 +316,10 @@ void RgShortestPathWidget::findingPath()
QList< QgsPoint > p;
while( startVertexIdx != stopVertexIdx )
{
QgsGraphEdgeList l = path.vertex( stopVertexIdx ).inEdges();
QgsGraphArcIdList l = path.vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphEdge& e = path.edge( l.front() );
const QgsGraphArc& e = path.arc( l.front() );

cost += e.property(0).toDouble();
time += e.property(1).toDouble();

0 comments on commit 9ab859a

Please sign in to comment.
You can’t perform that action at this time.