2011-06-03 15:21:02 +06:00
|
|
|
class QgsGraphAnalyzer
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsgraphanalyzer.h>
|
|
|
|
%End
|
2013-01-12 23:48:58 +01:00
|
|
|
|
2011-06-03 15:21:02 +06:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* solve shortest path problem using dijkstra algorithm
|
|
|
|
* @param source The source graph
|
|
|
|
* @param startVertexIdx index of start vertex
|
2012-01-17 16:36:25 +06:00
|
|
|
* @param criterionNum index of arc property as optimization criterion
|
2014-01-27 09:22:24 +01:00
|
|
|
* @param resultTree array represents the shortest path tree. resultTree[ vertexIndex ] == inboundingArcIndex if vertex reacheble and resultTree[ vertexIndex ] == -1 others.
|
2012-01-17 16:36:25 +06:00
|
|
|
* @param resultCost array of cost paths
|
2011-06-03 15:21:02 +06:00
|
|
|
*/
|
2012-01-17 16:36:25 +06:00
|
|
|
static SIP_PYLIST dijkstra( const QgsGraph* source, int startVertexIdx, int criterionNum );
|
|
|
|
%MethodCode
|
|
|
|
QVector< int > treeResult;
|
|
|
|
QVector< double > costResult;
|
2013-01-12 23:48:58 +01:00
|
|
|
QgsGraphAnalyzer::dijkstra( a0, a1, a2, &treeResult, &costResult );
|
|
|
|
|
2012-01-17 16:36:25 +06:00
|
|
|
PyObject *l1 = PyList_New( treeResult.size() );
|
|
|
|
if ( l1 == NULL )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyObject *l2 = PyList_New( costResult.size() );
|
|
|
|
if ( l2 == NULL )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int i;
|
|
|
|
for ( i = 0; i < costResult.size(); ++i )
|
2013-01-12 23:48:58 +01:00
|
|
|
{
|
2012-01-17 16:36:25 +06:00
|
|
|
PyObject *Int = PyInt_FromLong( treeResult[i] );
|
|
|
|
PyList_SET_ITEM( l1, i, Int );
|
|
|
|
PyObject *Float = PyFloat_FromDouble( costResult[i] );
|
2013-01-12 23:48:58 +01:00
|
|
|
PyList_SET_ITEM( l2, i, Float );
|
2012-01-17 16:36:25 +06:00
|
|
|
}
|
2013-01-12 23:48:58 +01:00
|
|
|
|
2012-01-17 16:36:25 +06:00
|
|
|
sipRes = PyTuple_New( 2 );
|
|
|
|
PyTuple_SET_ITEM( sipRes, 0, l1 );
|
|
|
|
PyTuple_SET_ITEM( sipRes, 1, l2 );
|
|
|
|
%End
|
2011-06-03 15:21:02 +06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* return shortest path tree with root-node in startVertexIdx
|
|
|
|
* @param source The source graph
|
|
|
|
* @param startVertexIdx index of start vertex
|
|
|
|
* @param criterionNum index of edge property as optimization criterion
|
|
|
|
*/
|
|
|
|
static QgsGraph* shortestTree( const QgsGraph* source, int startVertexIdx, int criterionNum );
|
|
|
|
};
|