Skip to content

Commit

Permalink
add clone to CallbackAsBranchAndBoundCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Nov 28, 2023
1 parent 194ac7e commit fd669ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
11 changes: 6 additions & 5 deletions examples/assignment.example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#include "idol/optimizers/dantzig-wolfe/infeasibility-strategies/FarkasPricing.h"
#include "idol/optimizers/dantzig-wolfe/stabilization/Neame.h"
#include "idol/optimizers/dantzig-wolfe/logs/Info.h"
#include "idol/optimizers/wrappers/Gurobi/Gurobi.h"

using namespace idol;

int main(int t_argc, const char** t_argv) {

const auto instance = Problems::GAP::read_instance("assignment.data.txt");
const auto instance = Problems::GAP::read_instance("/home/henri/Research/idol/tests/data/generalized-assignment-problem/GAP_instance0.txt");

const unsigned int n_agents = instance.n_agents();
const unsigned int n_jobs = instance.n_jobs();
Expand Down Expand Up @@ -56,22 +57,22 @@ int main(int t_argc, const char** t_argv) {
model.use(BranchAndBound()
.with_node_optimizer(
DantzigWolfeDecomposition(decomposition)
.with_master_optimizer(HiGHS::ContinuousRelaxation())
.with_master_optimizer(Gurobi::ContinuousRelaxation())
.with_default_sub_problem_spec(
DantzigWolfe::SubProblem()
.add_optimizer(HiGHS())
.add_optimizer(Gurobi())
.with_column_pool_clean_up(1500, .75)
)
.with_logger(Logs::DantzigWolfe::Info().with_frequency_in_seconds(.0001).with_sub_problems(true))
.with_dual_price_smoothing_stabilization(DantzigWolfe::Neame(.3))
.with_dual_price_smoothing_stabilization(DantzigWolfe::Neame(.0))
.with_infeasibility_strategy(DantzigWolfe::FarkasPricing())
.with_hard_branching(true)
.with_logs(true)
)
.with_subtree_depth(0)
.with_branching_rule(MostInfeasible())
.with_node_selection_rule(WorstBound())
.add_callback(Heuristics::IntegerMaster().with_optimizer(HiGHS().with_logs(false)))
.add_callback(Heuristics::IntegerMaster().with_optimizer(Gurobi().with_presolve(false).with_logs(false)))
.with_logs(true)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class idol::CallbackAsBranchAndBoundCallback : public BranchAndBoundCallbackFact
[[nodiscard]] const Timer &time() const override {
return m_parent.time();
}
public:
CallbackI *clone() const override {
return new Interface(*this);
}

};

Expand All @@ -70,6 +74,10 @@ class idol::CallbackAsBranchAndBoundCallback : public BranchAndBoundCallbackFact
void operator()(CallbackEvent t_event) override {
m_interface.execute(*m_callback, t_event);
}
public:
Strategy(const Strategy& t_src);

Strategy* clone() const override { return new Strategy(*this); }
};

explicit CallbackAsBranchAndBoundCallback(const CallbackFactory& t_factory)
Expand All @@ -85,4 +93,12 @@ class idol::CallbackAsBranchAndBoundCallback : public BranchAndBoundCallbackFact
}
};

template<class NodeInfoT>
idol::CallbackAsBranchAndBoundCallback<NodeInfoT>::Strategy::Strategy(const Strategy &t_src)
: BranchAndBoundCallback<NodeInfoT>(t_src),
m_interface(t_src.m_interface),
m_callback(t_src.m_callback ? t_src.m_callback->clone() : nullptr) {

}

#endif //IDOL_CALLBACKASBRANCHANDBOUNDCALLBACK_H
10 changes: 1 addition & 9 deletions lib/src/optimizers/wrappers/gurobi/Optimizers_Gurobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,7 @@ idol::Optimizers::Gurobi *idol::Optimizers::Gurobi::clone() const {
}

idol::Optimizers::Gurobi::Gurobi(const idol::Optimizers::Gurobi &t_src)
:
OptimizerWithLazyUpdates(*this),
m_env([&]() -> GRBEnv&{
const_cast<GRBModel&>(t_src.m_model).update();
return get_global_env();
}()),
m_model(t_src.m_model),
m_continuous_relaxation(t_src.m_continuous_relaxation),
m_gurobi_callback(t_src.m_gurobi_callback->clone()) {
: Gurobi(t_src.parent(), t_src.m_continuous_relaxation) {

}

Expand Down

0 comments on commit fd669ef

Please sign in to comment.