Skip to content

Commit

Permalink
using only 'vertex/arc' notation
Browse files Browse the repository at this point in the history
  • Loading branch information
stopa85milk committed May 31, 2011
1 parent 6e0435a commit 9ab859a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
42 changes: 21 additions & 21 deletions src/analysis/network/qgsgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

#include "qgsgraph.h"
Expand All @@ -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 ];
}


Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/analysis/network/qgsgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ class ANALYSIS_EXPORT QgsGraphEdge
};


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

/**
* \ingroup analysis
Expand All @@ -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
Expand All @@ -113,8 +113,8 @@ class ANALYSIS_EXPORT QgsGraphVertex

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

friend class QgsGraph;
};
Expand All @@ -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
Expand All @@ -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
Expand All @@ -172,7 +172,7 @@ class ANALYSIS_EXPORT QgsGraph
private:
QVector<QgsGraphVertex> mGraphVertexes;

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

#endif //QGSGRAPHH
24 changes: 12 additions & 12 deletions src/analysis/network/qgsgraphanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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() );
}
}
}
Expand All @@ -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() );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/network/qgsgraphbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/roadgraph/shortestpathwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9ab859a

Please sign in to comment.