Skip to content

Commit

Permalink
fix Robust::Deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Nov 28, 2024
1 parent 24ad40b commit 0addc45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions examples/robust/adr-facility-location.example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ int main(int t_argc, const char** t_argv) {

// Uncertainty set
Model uncertainty_set(env);
const double Gamma = 1;
const auto xi = uncertainty_set.add_vars(Dim<1>(n_customers), 0., 1., Continuous, 0., "xi");
uncertainty_set.add_ctr(idol_Sum(i, Range(n_customers), xi[i]) <= Gamma);
const double Gamma = .2;
const auto xi = uncertainty_set.add_vars(Dim<2>(n_facilities, n_customers), 0., 1., Continuous, 0., "xi");
uncertainty_set.add_ctr(idol_Sum(i, Range(n_facilities), idol_Sum(j, Range(n_customers), xi[i][j])) <= Gamma);

// Make model
Model model(env);
Expand Down Expand Up @@ -68,16 +68,19 @@ int main(int t_argc, const char** t_argv) {
for (unsigned int i = 0 ; i < n_facilities ; ++i) {
for (unsigned int j = 0; j < n_customers; ++j) {
const auto c = model.add_ctr(y[i][j] <= 1);
description.set_uncertain_rhs(c, -xi[j]); // models y_ij <= 1 - xi_j
description.set_uncertain_rhs(c, -xi[i][j]); // models y_ij <= 1 - xi_j
description.set_stage(y[i][j], 1); // models y_ij as a second-stage variable
}
}

/*
* const auto deterministic_model = Robust::AffineDecisionRule::make_model(model, description);
* std::cout << Robust::Description::View(model, description) << std::endl;
* const auto adr_result = Robust::AffineDecisionRule::make_model(model, description);
* std::cout << Robust::Description::View(adr_result.model, description) << std::endl;
*/

const auto adr_result = Robust::AffineDecisionRule::make_model(model, description);
std::cout << Robust::Description::View(adr_result.model, description) << std::endl;

model.use(Gurobi());
model.optimize();
std::cout << "Deterministic Problem has value: " << model.get_best_obj() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ idol::Robust::AffineDecisionRule::Result idol::Robust::AffineDecisionRule::make_
result.affine_decision_rules.emplace_back(std::move(adr));
}

// Add Uncertain constraints
for (const auto& ctr : t_model.ctrs()) {

const auto& row = t_model.get_ctr_row(ctr);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/robust/optimizers/deterministic/Deterministic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ idol::Robust::Deterministic::make_model(const idol::Model &t_model, const idol::
}

QuadExpr<Var> objective = row;
for (const auto& [var, uncertain_coeff] : row) {
for (const auto& [var, uncertain_coeff] : t_description.uncertain_mat_coeffs(ctr)) {
const auto& uncertain_mat_coeff = uncertain_mat_coeffs.get(var);
objective += uncertain_mat_coeff * var;
}
Expand Down

0 comments on commit 0addc45

Please sign in to comment.