Skip to content

Commit

Permalink
remove names in Mosek
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Nov 10, 2023
1 parent 56bd48a commit 113b0ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 50 deletions.
46 changes: 2 additions & 44 deletions dev/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,17 @@
#include "idol/optimizers/branch-and-bound/branching-rules/factories/PseudoCost.h"
#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BestEstimate.h"
#include "idol/optimizers/branch-and-bound/branching-rules/factories/BracnhingWithPriority.h"
#include "idol/optimizers/wrappers/Mosek/Mosek.h"

using namespace idol;

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

Env env;

// Read instance
const auto instance = Problems::FLP::read_instance_1991_Cornuejols_et_al("/home/henri/Research/idol/examples/facility.data.txt");
const unsigned int n_customers = instance.n_customers();
const unsigned int n_facilities = instance.n_facilities();

// Make model

Model model(env);

auto x = model.add_vars(Dim<1>(n_facilities), 0., 1., Binary, "x");
auto y = model.add_vars(Dim<2>(n_facilities, n_customers), 0., 1., Continuous, "y");

for (unsigned int i = 0 ; i < n_facilities ; ++i) {
model.add_ctr(idol_Sum(j, Range(n_customers), instance.demand(j) * y[i][j]) <= instance.capacity(i) * x[i]);
}

for (unsigned int j = 0 ; j < n_customers ; ++j) {
model.add_ctr(idol_Sum(i, Range(n_facilities), y[i][j]) == 1);
}

model.set_obj_expr(idol_Sum(i, Range(n_facilities),
instance.fixed_cost(i) * x[i]
+ idol_Sum(j, Range(n_customers),
instance.per_unit_transportation_cost(i, j) *
instance.demand(j) *
y[i][j]
)
)
);

// Set backend options
model.use(
BranchAndBound()
.with_node_optimizer(HiGHS::ContinuousRelaxation())
.with_branching_rule(
BranchingWithPriority()
.add_branching_rule(MostInfeasible(x.begin(), x.end()))
.add_branching_rule(MostInfeasible(y.at(5).begin(), y.at(5).end()))
)
.with_node_selection_rule(BestEstimate())
.with_log_level(Trace, Blue)
);

model.optimize();

std::cout << save_primal(model) << std::endl;
model.use(Mosek());

return 0;
}
12 changes: 6 additions & 6 deletions lib/src/optimizers/wrappers/Mosek/Optimizers_Mosek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ idol::MosekVar idol::Optimizers::Mosek::hook_add(const Var &t_var, bool t_add_co

MosekVar result;

result.variable = m_model->variable(t_var.name(), 1, mosek::fusion::Domain::unbounded());
result.variable = m_model->variable(/* t_var.name(), */ 1, mosek::fusion::Domain::unbounded());

const double lb = parent().get_var_lb(t_var);
const double ub = parent().get_var_ub(t_var);
Expand Down Expand Up @@ -225,11 +225,11 @@ idol::MosekCtr idol::Optimizers::Mosek::hook_add(const Ctr &t_ctr) {
);
}

result.constraint = m_model->constraint(t_ctr.name(), std::move(expression), mosek::fusion::Domain::inRotatedQCone());
result.constraint = m_model->constraint(/* t_ctr.name(), */ std::move(expression), mosek::fusion::Domain::inRotatedQCone());

return result;
#else
throw Exception("idol/modeling/ quadratic expressions with Mosek requires Eigen, please set the USE_EIGEN cmake option to YES to use this feature.");
throw Exception("Modeling quadratic expressions with Mosek requires Eigen, please set the USE_EIGEN cmake option to YES to use this feature.");
#endif

}
Expand All @@ -241,13 +241,13 @@ idol::MosekCtr idol::Optimizers::Mosek::hook_add(const Ctr &t_ctr) {
// Set constraint type
switch (type) {
case LessOrEqual:
result.constraint = m_model->constraint(t_ctr.name(), std::move(expr), mosek::fusion::Domain::lessThan(0.));
result.constraint = m_model->constraint(/* t_ctr.name(), */ std::move(expr), mosek::fusion::Domain::lessThan(0.));
break;
case GreaterOrEqual:
result.constraint = m_model->constraint(t_ctr.name(), std::move(expr), mosek::fusion::Domain::greaterThan(0.));
result.constraint = m_model->constraint(/* t_ctr.name(), */ std::move(expr), mosek::fusion::Domain::greaterThan(0.));
break;
case Equal:
result.constraint = m_model->constraint(t_ctr.name(), std::move(expr), mosek::fusion::Domain::equalsTo(0.));
result.constraint = m_model->constraint(/* t_ctr.name(), */ std::move(expr), mosek::fusion::Domain::equalsTo(0.));
break;
default: throw Exception("Enum out of bounds.");
}
Expand Down

0 comments on commit 113b0ac

Please sign in to comment.