27 return mNextVertexId++;
30int QgsGraph::addEdge(
int fromVertexIdx,
int toVertexIdx,
const QVector<QVariant> &strategies )
34 e.mStrategies = strategies;
35 e.mToIdx = toVertexIdx;
36 e.mFromIdx = fromVertexIdx;
51 return ( it ).value();
52 Q_ASSERT_X(
false,
"QgsGraph::vertex()",
"Invalid vertex ID" );
55 return ( *
const_cast<QHash<int, QgsGraphVertex> *
>( &
mGraphVertices ) )[idx];
63 QSet<int> affectedEdges = qgis::listToSet( it->incomingEdges() );
64 affectedEdges.unite( qgis::listToSet( it->outgoingEdges() ) );
69 for (
int edgeId : std::as_const( affectedEdges ) )
80 return ( it ).value();
81 Q_ASSERT_X(
false,
"QgsGraph::edge()",
"Invalid edge ID" );
84 return ( *
const_cast<QHash<int, QgsGraphEdge> *
>( &
mGraphEdges ) )[idx];
92 const int fromVertex = it->fromVertex();
93 const int toVertex = it->toVertex();
100 vertexIt->mOutgoingEdges.removeAll( index );
101 if ( vertexIt->mOutgoingEdges.empty() && vertexIt->mIncomingEdges.empty() )
108 vertexIt->mIncomingEdges.removeAll( index );
109 if ( vertexIt->mOutgoingEdges.empty() && vertexIt->mIncomingEdges.empty() )
155 const int fromVertex = it->fromVertex();
156 const int toVertex = it->toVertex();
160 for (
int candidate : candidates )
162 if (
mGraphEdges.value( candidate ).toVertex() == fromVertex )
171 return mStrategies[i];
190 : mCoordinate( point )
196 return mIncomingEdges;
201 return mOutgoingEdges;
This class implements a graph edge.
int fromVertex() const
Returns the index of the vertex at the start of this edge.
QVector< QVariant > strategies() const
Returns array of available strategies.
int toVertex() const
Returns the index of the vertex at the end of this edge.
QVariant cost(int strategyIndex) const
Returns edge cost calculated using specified strategy.
This class implements a graph vertex.
QgsGraphEdgeIds outgoingEdges() const
Returns outgoing edge ids, i.e.
QgsGraphEdgeIds incomingEdges() const
Returns the incoming edge ids, i.e.
QgsPointXY point() const
Returns point associated with graph vertex.
const QgsGraphVertex & vertex(int idx) const
Returns the vertex at the given index.
int addEdge(int fromVertexIdx, int toVertexIdx, const QVector< QVariant > &strategies)
Add an edge to the graph, going from the fromVertexIdx to toVertexIdx.
int findOppositeEdge(int index) const
Finds the first edge which is the opposite of the edge with the specified index.
int findVertex(const QgsPointXY &pt) const
Find vertex by associated point.
bool hasVertex(int index) const
Returns whether the vertex of the given index exists.
bool hasEdge(int index) const
Returns whether the edge of the given index exists.
QHash< int, QgsGraphVertex > mGraphVertices
Graph vertices.
int edgeCount() const
Returns number of graph edges.
const QgsGraphEdge & edge(int idx) const
Returns the edge at the given index.
void removeEdge(int index)
Removes the edge at specified index.
int addVertex(const QgsPointXY &pt)
Add a vertex to the graph.
QHash< int, QgsGraphEdge > mGraphEdges
Graph edges.
void removeVertex(int index)
Removes the vertex at specified index.
int vertexCount() const
Returns number of graph vertices.
A class to represent a 2D point.
QList< int > QgsGraphEdgeIds