diff --git a/lib/src/mixed-integer/modeling/models/KKT.cpp b/lib/src/mixed-integer/modeling/models/KKT.cpp index 4fe175bf..2c212038 100644 --- a/lib/src/mixed-integer/modeling/models/KKT.cpp +++ b/lib/src/mixed-integer/modeling/models/KKT.cpp @@ -338,13 +338,13 @@ void idol::Reformulators::KKT::create_dual_constraints() { std::move(dual_constraint_expression.affine().linear()), Equal, -dual_constraint_expression.affine().constant()), - "dual_constraint_" + var.name()); + "dual_" + var.name()); } else { m_dual_constraints[index] = QCtr(env, TempQCtr( std::move(dual_constraint_expression), Equal), - "dual_constraint_" + var.name()); + "dual_" + var.name()); } } @@ -533,9 +533,9 @@ void idol::Reformulators::KKT::add_strong_duality_reformulation(idol::Model &t_d auto duality_gap = m_primal_objective - m_dual_objective; if (duality_gap.has_quadratic()) { - t_destination.add_qctr(std::move(duality_gap), LessOrEqual); + t_destination.add_qctr(std::move(duality_gap), LessOrEqual, "strong_duality"); } else { - t_destination.add_ctr(std::move(duality_gap.affine()) <= 0); + t_destination.add_ctr(std::move(duality_gap.affine()) <= 0, "strong_duality"); } } diff --git a/lib/src/mixed-integer/optimizers/padm/Formulation.cpp b/lib/src/mixed-integer/optimizers/padm/Formulation.cpp index fd7d28bf..1a3bfd2b 100644 --- a/lib/src/mixed-integer/optimizers/padm/Formulation.cpp +++ b/lib/src/mixed-integer/optimizers/padm/Formulation.cpp @@ -10,6 +10,7 @@ #include "idol/mixed-integer/modeling/constraints/TempCtr.h" #include +#include idol::ADM::Formulation::Formulation(const Model& t_src_model, Annotation t_decomposition, @@ -251,8 +252,6 @@ void idol::ADM::Formulation::set_penalty_in_all_sub_problems(const Var &t_var, d void idol::ADM::Formulation::initialize_penalty_parameters(bool t_use_inverse_penalties) { - const unsigned int n_sub_problems = m_sub_problems.size(); - for (auto& sub_problem : m_sub_problems) { for (const auto& var : sub_problem.l1_epigraph_vars) { @@ -417,32 +416,41 @@ void idol::ADM::Formulation::dispatch_qctr(const idol::Model &t_src_model, } auto& sub_problem = m_sub_problems[t_sub_problem_id]; + std::optional new_linear_ctr; if (!full_row) { // here, we are still on RHS fixation if (rhs_quad.empty_all()) { - sub_problem.model.add_ctr(TempCtr(LinExpr(lhs), type, rhs_quad.affine().constant()), t_ctr.name()); + new_linear_ctr = sub_problem.model.add_ctr(TempCtr(LinExpr(lhs), type, rhs_quad.affine().constant()), t_ctr.name()); } else { - const auto c = sub_problem.model.add_ctr(TempCtr(std::move(lhs), type, 0), t_ctr.name()); - sub_problem.rhs_fixations.emplace_back(c, std::move(rhs_quad)); + new_linear_ctr = sub_problem.model.add_ctr(TempCtr(std::move(lhs), type, 0), t_ctr.name()); + sub_problem.rhs_fixations.emplace_back(*new_linear_ctr, std::move(rhs_quad)); } - return; - } + } else { - // here, we are on LHS fixation + // here, we are on LHS fixation + + if (full_row->has_quadratic()) { + // we have to add a quadratic constraint here + throw Exception("Quadratic constraints in fixed problems are not implemented"); + } + + new_linear_ctr = sub_problem.model.add_ctr(TempCtr(LinExpr(), type, 0.), t_ctr.name()); + sub_problem.row_fixations.emplace_back(*new_linear_ctr, std::move(*full_row)); - if (full_row->has_quadratic()) { - // we have to add a quadratic constraint here - throw Exception("Quadratic constraints in fixed problems are not implemented"); } - const auto c = sub_problem.model.add_ctr(TempCtr(LinExpr(), type, 0.), t_ctr.name()); - sub_problem.row_fixations.emplace_back(c, std::move(*full_row)); + assert(new_linear_ctr.has_value()); + + if (m_initial_penalty_parameters.has_value()) { + new_linear_ctr->set(*m_initial_penalty_parameters, t_ctr.get(*m_initial_penalty_parameters)); + } } + double idol::ADM::Formulation::evaluate(const QuadExpr& t_expr, const std::vector>& t_primals) { double result = t_expr.affine().constant(); for (const auto& [var, coeff] : t_expr.affine().linear()) { @@ -479,7 +487,7 @@ idol::LinExpr idol::ADM::Formulation::add_l1_vars(unsigned int t_ctr_ if (const auto it = m_l1_epigraph_vars.find(t_ctr_id) ; it != m_l1_epigraph_vars.end()) { var = it->second; } else { - var = Var(model.env(), 0, Inf, Continuous, 0); + var = Var(model.env(), 0, Inf, Continuous, 0, "l1_epigraph_" + std::to_string(t_ctr_id)); var->set(*m_initial_penalty_parameters, t_initial_penalty_parameter); m_l1_epigraph_vars.emplace_hint(it, t_ctr_id, *var); m_sub_problems[t_sub_problem_id].l1_epigraph_vars.emplace_back(*var);