@@ -27,13 +27,30 @@ auto action_set(scip::Model const& model, bool pseudo) -> std::optional<xt::xten
2727 return branch_cols;
2828}
2929
30+ /* * Iterative solving until next LP branchrule call and return the action_set. */
31+ template <typename FCall>
32+ auto keep_solving_until_next_LP_callback (scip::Model& model, FCall& fcall, bool pseudo_candidates)
33+ -> std::tuple<bool, BranchingDynamics::ActionSet> {
34+ using Call = scip::callback::BranchruleCall;
35+ // While solving is not finished.
36+ while (fcall.has_value ()) {
37+ // LP branchrule found, we give control back to the agent.
38+ // Assuming Branchrules are the only reverse callbacks.
39+ if (std::get<Call>(fcall.value ()).where == Call::Where::LP) {
40+ return {false , action_set (model, pseudo_candidates)};
41+ }
42+ // Otherwise keep looping, ignoring the callback.
43+ fcall = model.solve_iter_continue (SCIP_DIDNOTRUN);
44+ }
45+ // Solving is finished.
46+ return {true , {}};
47+ }
48+
3049} // namespace
3150
3251auto BranchingDynamics::reset_dynamics (scip::Model& model) const -> std::tuple<bool, ActionSet> {
33- if (model.solve_iter (scip::callback::BranchruleConstructor{}).has_value ()) {
34- return {false , action_set (model, pseudo_candidates)};
35- }
36- return {true , {}};
52+ auto fcall = model.solve_iter (scip::callback::BranchruleConstructor{});
53+ return keep_solving_until_next_LP_callback (model, fcall, pseudo_candidates);
3754}
3855
3956auto BranchingDynamics::step_dynamics (scip::Model& model, Defaultable<std::size_t > maybe_var_idx) const
@@ -54,21 +71,9 @@ auto BranchingDynamics::step_dynamics(scip::Model& model, Defaultable<std::size_
5471 scip_result = SCIP_BRANCHED;
5572 }
5673
57- using Call = scip::callback::BranchruleCall;
5874 // Looping until the next LP branchrule rule callback, if it exists.
5975 auto fcall = model.solve_iter_continue (scip_result);
60- while (fcall.has_value ()) {
61- // LP branchrule found, we give control back to the agent.
62- // Assuming Branchrul are the only reverse callbacks.
63- if (std::get<Call>(fcall.value ()).where == Call::Where::LP) {
64- return {false , action_set (model, pseudo_candidates)};
65- }
66- // Otherwise keep looping, ignoring the callback.
67- fcall = model.solve_iter_continue (SCIP_DIDNOTRUN);
68- }
69-
70- // Solving has terminated.
71- return {true , {}};
76+ return keep_solving_until_next_LP_callback (model, fcall, pseudo_candidates);
7277}
7378
7479} // namespace ecole::dynamics
0 commit comments