Skip to content

Commit

Permalink
Compact model with nxor var
Browse files Browse the repository at this point in the history
  • Loading branch information
hhijazi committed Dec 17, 2023
1 parent 4e9ff3c commit d872c93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions examples/Optimization/MINLP/LABS/LABS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ int main(int argc, char * argv[]){
Model<> M_obj("M_obj_LABS_"+to_string(n));
Model<> M("LABS_"+to_string(n));
var<int> s("s", -1, 1);
var<> z("z", -1, 1);
var<int> z("z", -1, 1);
var<int> y("y", 0, 1);
var<int> cs("cs", pos_);
var<> c("c");
var<int> c("c");
indices s_ids = range(0,n-1);
indices c_ids = range(1,n-1);
int opt_obj = 0;
Expand Down Expand Up @@ -151,13 +151,22 @@ int main(int argc, char * argv[]){
// p_def = p - (2*y.from(pairs) - 1)*(2*y.to(pairs) - 1);
// M_obj.add(p_def.in(pairs) == 0);

var<> y2("y2", 0, 1);
var<int> y2("y2", 0, 1);
M_obj.add(y2.in(pairs));

var<int> yp("yp", 0, 1);
M_obj.add(yp.in(pairs));

Constraint<> y2_def("y2_def");
y2_def = y2 - (2*y.from(pairs)*y.to(pairs) - y.from(pairs) - y.to(pairs) + 1);
y2_def = y2 - (2*yp.in(pairs) - y.from(pairs) - y.to(pairs) + 1);
M_obj.add(y2_def.in(pairs) == 0);


Constraint<> yp_def("yp_def");
yp_def = yp - y.from(pairs)*y.to(pairs);
M_obj.add(yp_def.in(pairs) == 0);


// Constraint<> pp_def("pp_def");
// pp_def = pp - (2*y2.in(multi_p1) - 1)*(2*y2.in(multi_p2) - 1);
// M_obj.add(pp_def.in(multi_terms) == 0);
Expand Down Expand Up @@ -192,7 +201,7 @@ int main(int argc, char * argv[]){
sixteen.in(multi_terms);
sixteen = 16;

M_obj.min((sixteen.tr()*y2.in(multi_p1)*y2.in(multi_p2) - eight_p1.tr()*y2.in(multi_p1) - eight_p2.tr()*y2.in(multi_p2) + 4*nb_mult) + (eight.tr()*y.from(pairs)*y.to(pairs) - four_fr.tr()*y.in(pairs_fr) - four_to.tr()*y.in(pairs_to) + 2*nb_quad) + obj.eval_cst(0));//4*sum(pp)+
M_obj.min((sixteen.tr()*y2.in(multi_p1)*y2.in(multi_p2) - eight_p1.tr()*y2.in(multi_p1) - eight_p2.tr()*y2.in(multi_p2) + 4*nb_mult) + (eight.tr()*yp.in(pairs) - four_fr.tr()*y.in(pairs_fr) - four_to.tr()*y.in(pairs_to) + 2*nb_quad) + obj.eval_cst(0));//4*sum(pp)+
// M_obj.add(obj_def.in(range(1,1)) == 0);
//
// M_obj.min(obj_var);
Expand Down Expand Up @@ -255,10 +264,10 @@ int main(int argc, char * argv[]){
// c_def = c - z.in(z_sum);
c_def = c - (2*y.in(y_sum_fr) - 1)*(2*y.in(y_sum_to) - 1) - rhs;
M.add(c_def.in(c_ids) == 0);
for(auto i = 0; i < c_ids.size(); i++){
c.set_lb(c_ids._keys->at(i), -1.*y_sum_fr._ids->at(i).size());
c.set_ub(c_ids._keys->at(i), y_sum_fr._ids->at(i).size());
}
// for(auto i = 0; i < c_ids.size(); i++){
// c.set_lb(c_ids._keys->at(i), -1.*y_sum_fr._ids->at(i).size());
// c.set_ub(c_ids._keys->at(i), y_sum_fr._ids->at(i).size());
// }
// Constraint<> c_fix("c_fix");
// c_fix = c[1];
// M.add(c_fix == 1);
Expand Down
2 changes: 1 addition & 1 deletion src/GurobiProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ bool GurobiProgram::solve(bool relax, double mipgap, double time_limit){
// grb_mod->set(GRB_IntParam_MIPFocus,1);
// grb_mod->set(GRB_IntParam_IntegralityFocus,1);
// grb_mod->set(GRB_IntParam_MIPFocus,1);
// grb_mod->set(GRB_DoubleParam_Heuristics,0);
grb_mod->set(GRB_DoubleParam_Heuristics,0);
// grb_mod->set(GRB_IntParam_PumpPasses,50);
// grb_mod->set(GRB_IntParam_RINS,1);
grb_mod->set(GRB_IntParam_Cuts,0);
Expand Down

0 comments on commit d872c93

Please sign in to comment.