From 7c730899163294970ae7e74dad3214c0999bd4e2 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Sun, 10 Sep 2023 22:10:14 -0500 Subject: [PATCH] Added cost --- src/algorithm.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/algorithm.cpp b/src/algorithm.cpp index fe959c8..f40977f 100644 --- a/src/algorithm.cpp +++ b/src/algorithm.cpp @@ -54,9 +54,19 @@ void Graph::PrintGraph(void) { } void PrintSolution(std::vector solution) { + int cost = 0; std::cout << "Path: "; - for (Vertex* i : solution) { std::cout << i->nodeNumber << ' '; } + Vertex* lastVertex = solution.front(); + for (Vertex* i : solution) { + std::cout << i->nodeNumber << ' '; + for (Edge j : lastVertex->edges) { + if (j.destination->nodeNumber == i->nodeNumber) { + cost += j.weight; + } + } + } std::cout << std::endl; + std::cout << "Cost: " << cost << std::endl; } void UCBFS(Graph graph, int start) {