Add vertex weights and neighbor iterator for WeightedEdgeGraph
This commit is contained in:
@@ -23,9 +23,10 @@ WeightedEdgeGraph::WeightedEdgeGraph()
|
||||
{
|
||||
}
|
||||
|
||||
int WeightedEdgeGraph::addVertex()
|
||||
int WeightedEdgeGraph::addVertex(const int weight)
|
||||
{
|
||||
firstVertexIncidences_.push_back(-1);
|
||||
vertexWeights_.push_back(weight);
|
||||
return (int)firstVertexIncidences_.size() - 1;
|
||||
}
|
||||
|
||||
@@ -38,6 +39,16 @@ void WeightedEdgeGraph::addEdge(const int vertex1, const int vertex2, const int
|
||||
edgeWeights_.push_back(weight);
|
||||
}
|
||||
|
||||
int WeightedEdgeGraph::getVertexWeight(const int vertex) const
|
||||
{
|
||||
return vertexWeights_[vertex];
|
||||
}
|
||||
|
||||
int WeightedEdgeGraph::getEdgeWeight(const int edge) const
|
||||
{
|
||||
return edgeWeights_[edge];
|
||||
}
|
||||
|
||||
int WeightedEdgeGraph::dijkstra(const int source, const int target) const
|
||||
{
|
||||
std::vector<int> distances(firstVertexIncidences_.size(), std::numeric_limits<int>::max());
|
||||
@@ -72,3 +83,13 @@ int WeightedEdgeGraph::dijkstra(const int source, const int target) const
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
WeightedEdgeGraph::NeighborIterator WeightedEdgeGraph::begin(const int vertex) const
|
||||
{
|
||||
return { *this, vertex };
|
||||
}
|
||||
|
||||
WeightedEdgeGraph::NeighborIterator WeightedEdgeGraph::end() const
|
||||
{
|
||||
return { *this, -1 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user