updated weighted_graph
This commit is contained in:
parent
5f71dd5d45
commit
54cef5809d
2 changed files with 10 additions and 1 deletions
|
@ -19,13 +19,14 @@ int Node::deg() const
|
|||
|
||||
WeightedGraph::WeightedGraph(size_t num_nodes) : nodes(num_nodes)
|
||||
{
|
||||
|
||||
edges = 0;
|
||||
}
|
||||
|
||||
void WeightedGraph::add_edge(int from, int to, double weight)
|
||||
{
|
||||
nodes[from].add_edge(to, weight);
|
||||
nodes[to].add_edge(from, weight);
|
||||
edges++;
|
||||
}
|
||||
|
||||
std::list<std::pair<int, double>> WeightedGraph::adjList(int node_id) const
|
||||
|
@ -43,6 +44,11 @@ size_t WeightedGraph::num_nodes() const
|
|||
return nodes.size();
|
||||
}
|
||||
|
||||
int WeightedGraph::num_edges() const
|
||||
{
|
||||
return edges;
|
||||
}
|
||||
|
||||
std::pair<int,double> WeightedGraph::min_neighbour(int node_id) const
|
||||
{
|
||||
if (adjList(node_id).empty())
|
||||
|
@ -82,6 +88,7 @@ WeightedGraph WeightedGraph::remove_parallel() const
|
|||
for (const auto& [to, weight] : lightestEdges)
|
||||
{
|
||||
G.nodes[i].add_edge(to, weight);
|
||||
G.edges++;
|
||||
}
|
||||
}
|
||||
return G;
|
||||
|
|
|
@ -20,12 +20,14 @@ public:
|
|||
void add_edge(int from, int to, double weight);
|
||||
std::list<std::pair<int, double>> adjList(int node_id) const;
|
||||
size_t num_nodes() const;
|
||||
int num_edges() const;
|
||||
int deg(int v) const;
|
||||
std::pair<int,double> min_neighbour(int node_id) const;
|
||||
WeightedGraph remove_parallel() const;
|
||||
|
||||
private:
|
||||
std::vector<Node> nodes;
|
||||
int edges;
|
||||
};
|
||||
|
||||
#endif //C___WEIGHTEDGRAPH_H
|
||||
|
|
Loading…
Reference in a new issue