diff --git a/examples/Optimization/MINLP/LABS/LABS.cpp b/examples/Optimization/MINLP/LABS/LABS.cpp index f8e1e8fc..ad50dbaf 100644 --- a/examples/Optimization/MINLP/LABS/LABS.cpp +++ b/examples/Optimization/MINLP/LABS/LABS.cpp @@ -21,55 +21,84 @@ int main(int argc, char * argv[]){ if(argc>=2){ n=stoi(argv[1]); } - Model<> m("LABS_"+to_string(n)); + Model<> M_obj("M_obj_LABS_"+to_string(n)); + Model<> M("LABS_"+to_string(n)); var<> s("s", -1, 1); var<> z("z", -1, 1); var y("y", 0, 1); var<> cs("cs", pos_); var<> c("c"); indices s_ids = range(0,n-1); - indices c_ids = range(1,n-1); - indices z_ids("z_ids"); - for (int i = 0; i obj; + for (int k = 1; k<=n-1; k++) { + func<> cterm; + for (int i = 0; i g_sol(M_obj,ipopt); + g_sol.run(); + M_obj.print_solution(); + M_obj.round_solution(); + M_obj.print_solution(); } - m.add(s.in(s_ids), c.in(c_ids), z.in(z_ids)); - m.add(y.in(s_ids)); - -// Constraint<> y_on_off("y_on_off"); -// y_on_off = s - 2*y + 1; -// m.add(y_on_off.in(s_ids) == 0); - - Constraint<> z_def("z_def"); - z_def = z - (2*y.from(z_ids) - 1)*(2*y.to(z_ids) - 1); - m.add(z_def.in(z_ids) == 0); - - indices z_sum("z_sum"); - for (int k = 1; k<=n-1; k++) { - for (int i = 0; i y_on_off("y_on_off"); + // y_on_off = s - 2*y + 1; + // m.add(y_on_off.in(s_ids) == 0); + + Constraint<> z_def("z_def"); + z_def = z - (2*y.from(z_ids) - 1)*(2*y.to(z_ids) - 1); + M.add(z_def.in(z_ids) == 0); + + indices z_sum("z_sum"); + for (int k = 1; k<=n-1; k++) { + for (int i = 0; i c_def("c_def"); + c_def = c - z.in(z_sum); + M.add(c_def.in(c_ids) == 0); + + // Constraint<> cs_def("cs_def"); + // cs_def = cs - c*c; + // m.add(cs_def.in(c_ids) >= 0); + + // m.min(sum(cs)); + param<> ones("1"); + ones.in(c_ids); + ones = 1; + M.min(ones.tr()*c*c); + + solver<> mip_solver(M,gurobi); +// solver<> nlp_solver(M,ipopt); + mip_solver.run(); +// nlp_solver.run(); +// M.print_solution(); +// M.round_solution(); + M.print_solution(); } - Constraint<> c_def("c_def"); - c_def = c - z.in(z_sum); - m.add(c_def.in(c_ids) == 0); - -// Constraint<> cs_def("cs_def"); -// cs_def = cs - c*c; -// m.add(cs_def.in(c_ids) >= 0); - -// m.min(sum(cs)); - param<> ones("1"); - ones.in(c_ids); - ones = 1; - m.min(ones.tr()*c*c); - -// m.print(); - solver<> g_sol(m,gurobi); - g_sol.run(); - m.print_solution(); - }