Skip to content
Snippets Groups Projects
Commit b464955e authored by Jakub Janák's avatar Jakub Janák
Browse files

method ge_min_cost made public

parent 2f4ff9d7
No related branches found
No related tags found
No related merge requests found
......@@ -127,12 +127,13 @@ void ts_instance::branch_parallel(std::vector<node> visitedNodes, double cost, c
}
}
// After all neighbors are posted to the thread pool, handle the first neighbor immediately
// After all, neighbors are posted to the thread pool, handle the first neighbor immediately
if (firstNeighbour) {
branch_parallel(firstBranchVisNodes, firstSendCost, *firstNeighbour);
}
if (visitedNodes.size() == nodes.size()) {
std::lock_guard lock(m_1);
cost += get_cost_between_nodes(visitedNodes.back(), startingNode);
if (cost < get_min_cost()) {
set_min_cost(cost);
......@@ -204,12 +205,11 @@ double ts_instance::heuristic_combo() const {
}
double ts_instance::get_min_cost() {
std::lock_guard lock(m_1);
std::lock_guard lock(m_2);
return this->minCost;
}
void ts_instance::set_min_cost(const double minCost) {
std::lock_guard lock(m_1);
this->minCost = minCost;
}
......@@ -218,12 +218,10 @@ bool ts_instance::is_solved() const {
}
void ts_instance::clear_best_hams() {
std::lock_guard lock(m_1);
this->bestHamiltonianPaths.clear();
}
void ts_instance::add_best_hamiltonian(const std::vector<node> &path) {
std::lock_guard lock(m_1);
this->bestHamiltonianPaths.push_back(path);
}
......
......@@ -8,7 +8,8 @@
class ts_instance : public graph {
std::mutex m_1; // mutex for thread safety of minCost
std::mutex m_1;
std::mutex m_2;
std::unique_ptr<boost::asio::thread_pool> pool;
double minCost; // thread save minimal cost variable
node startingNode;
......@@ -28,8 +29,6 @@ class ts_instance : public graph {
static double two_opt(std::vector<node> greedyPath);
[[nodiscard]] double get_min_cost();
void set_min_cost(double minCost);
void clear_best_hams();
......@@ -37,6 +36,8 @@ class ts_instance : public graph {
void add_best_hamiltonian(const std::vector<node> &path);
public:
[[nodiscard]] double get_min_cost();
ts_instance(std::vector<std::shared_ptr<node> > nodes, std::vector<std::shared_ptr<edge> > edges);
std::vector<std::vector<node> > solve(int num_of_threads = 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment