From 6d3e2e6f00a2e1e5cf827e5db1911bd8b96b968e Mon Sep 17 00:00:00 2001 From: p-hamann <p.hamann@dareit.de> Date: Mon, 27 May 2019 14:09:54 +0200 Subject: [PATCH] Avoid running lb algos without satisfied requirements --- bnb/bnb.cpp | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/bnb/bnb.cpp b/bnb/bnb.cpp index ebe934c..2bad4ef 100644 --- a/bnb/bnb.cpp +++ b/bnb/bnb.cpp @@ -29,31 +29,28 @@ solver::solver(graph& g, lb lb_algorithm) : graph_(g), partition_(partition{g}), } unsigned int solver::get_lower(){ - unsigned int lower_bound; + std::vector<node_id> sources, sinks; + for(node_id node = 1; node <= graph_.num_nodes(); node++){ + if(partition_.assigned_subgraph_of(node) == partition::sg_a) + sources.push_back(node); + else if(partition_.assigned_subgraph_of(node) == partition::sg_b) + sinks.push_back(node); + } + if (sources.empty() || sinks.empty()) { + return partition_.current_objective(); + } + + + if(lb_algorithm_ == lb::ek){ - std::vector<node_id> sources, sinks; - for(node_id node = 1; node <= graph_.num_nodes(); node++){ - if(partition_.assigned_subgraph_of(node) == partition::sg_a) - sources.push_back(node); - else if(partition_.assigned_subgraph_of(node) == partition::sg_b) - sinks.push_back(node); - } auto ek = edmonds_karp(graph_, sources, sinks); ek.run(); - lower_bound = ek.get_max_flow(); + return ek.get_max_flow(); } else if(lb_algorithm_ == lb::ibfs){ - std::vector<node_id> sources, sinks; - for(node_id node = 1; node <= graph_.num_nodes(); node++){ - if(partition_.assigned_subgraph_of(node) == partition::sg_a) - sources.push_back(node); - else if(partition_.assigned_subgraph_of(node) == partition::sg_b) - sinks.push_back(node); - } auto i_bfs = incremental_bfs(graph_, sources, sinks); i_bfs.run(); - lower_bound = i_bfs.get_max_flow(); - + return i_bfs.get_max_flow(); } else if(lb_algorithm_ == lb::pr){ @@ -61,11 +58,7 @@ unsigned int solver::get_lower(){ else if(lb_algorithm_ == lb::gp){ } - else{ - lower_bound = partition_.current_objective(); - } - - return lower_bound; + return partition_.current_objective(); } void solver::solve() { -- GitLab