diff --git a/examples/Optimization/MISDP/CBF/misdp_cbf.cpp b/examples/Optimization/MISDP/CBF/misdp_cbf.cpp index aee8d6f2..c35dd693 100644 --- a/examples/Optimization/MISDP/CBF/misdp_cbf.cpp +++ b/examples/Optimization/MISDP/CBF/misdp_cbf.cpp @@ -56,7 +56,7 @@ using namespace std; int main(int argc, char * argv[]){ //string fname=string(prj_dir)+"/data_sets/MISDP/2x7_3bars.cbf"; - string fname=string(prj_dir)+"/data_sets/MISDP/band50_3.cbf"; + string fname=string(prj_dir)+"/data_sets/MISDP/2x3_3bars.cbf"; bool root_refine = false, add_soc=false, add_threed=false, add_bag=false, hierarc=false; string root_refine_s = "false", add_soc_s="false", add_threed_s="false", add_bag_s="false", hierarc_s="false"; if(argc>=2){ @@ -94,6 +94,10 @@ int main(int argc, char * argv[]){ m->add_hierarc=hierarc; auto g=CBF_read(fname.c_str(), m); + if(g.nodes.size()==0){ + cerr << "graph with size 0\n"; + return -1; + } m->print(); DebugOn("Instance "<>& m, bool add_3d) { pFile = FOPEN(file, "rt"); if (!pFile) { - throw invalid_argument("cannot open misdp data file"); + cerr <<"Cannot open misdp data file " << file << endl; + return g; } CBFdata data = { 0, }; // Keyword OBJ should exist! diff --git a/src/GurobiProgram.cpp b/src/GurobiProgram.cpp index da8482cd..2c9125ab 100755 --- a/src/GurobiProgram.cpp +++ b/src/GurobiProgram.cpp @@ -13,6 +13,42 @@ class cuts: public GRBCallback vector vec_expi; int soc_viol=0, soc_found=0,soc_added=0,det_viol=0, det_found=0, det_added=0; int soc_viol_user=0, soc_found_user=0,soc_added_user=0,det_viol_user=0, det_found_user=0, det_added_user=0; + + + void update_rel_solution(){ + size_t vid, vid_inst; + GRBVar gvar; + param_* v; + for(auto& v_p: m->_vars) + { + v = v_p.second.get(); + auto idx = v->get_id(); + auto dim = v->_dim[0]; + for (auto i = 0; i < dim; i++) { + auto vid = idx + v->get_id_inst(i); + gvar = vars.at(vid); + v->set_double_val(i,getNodeRel(gvar)); + } + } + } + + void update_solution(){ + size_t vid, vid_inst; + GRBVar gvar; + param_* v; + for(auto& v_p: m->_vars) + { + v = v_p.second.get(); + auto idx = v->get_id(); + auto dim = v->_dim[0]; + for (auto i = 0; i < dim; i++) { + auto vid = idx + v->get_id_inst(i); + gvar = vars.at(vid); + v->set_double_val(i,getSolution(gvar)); + } + } + } + //cuts(vector _grb_vars, int xn, Model<>* mn, Model<> interiorn, vector& vec_exp) { cuts(vector _grb_vars, int xn, Model<>* mn, Model<> interiorn) { vars = _grb_vars; @@ -49,15 +85,16 @@ class cuts: public GRBCallback add_bag_iteration=add_bag; add_full_iteration=add_full; /* Found an integer feasible solution */ - double *x = new double[n]; - vector vec_x; - int i; - x=getSolution(vars.data(),n); - for(i=0;i vec_x; +// int i; +// x=getSolution(vars.data(),n); +// for(i=0;icompute_funcs(); if(add_soc){ - m->set_solution(vec_x); auto res= m->cutting_planes_soc(1e-9, soc_found, soc_added); if(res.size()>=1){ for(auto i=0;inum_cuts[0]++; } } - // if(hierarc && res.size()>=1){ - // add_bag_iteration=false; - // add_full_iteration=false; - // } } if(add_threed){ - m->set_solution(vec_x); auto res= m->cutting_planes_threed(1e-9, soc_found, soc_added); if(res.size()>=1){ for(auto i=0;iset_solution(vec_x); auto res1=m->cuts_eigen_bags(1e-9); if(res1.size()>=1){ for(auto i=0;iset_solution(vec_x); auto res2=m->cuts_eigen_full(1e-9); if(res2.size()>=1){ for(auto i=0;i vec_x; - int i; - x=getNodeRel(vars.data(),n); - for(i=0;iset_solution(vec_x); + update_rel_solution(); +// m->compute_funcs(); if(add_soc){ - m->set_solution(vec_x); auto res= m->cutting_planes_soc(1e-9, soc_found, soc_added); if(res.size()>=1){ for(auto i=0;iset_solution(vec_x); auto res= m->cutting_planes_threed(1e-9, soc_found, soc_added); if(res.size()>=1){ for(auto i=0;iset_solution(vec_x); auto res1=m->cuts_eigen_bags(1e-9); if(res1.size()>=1){ DebugOff("Added " << res1.size() << " bag cuts\n"); @@ -228,7 +249,6 @@ class cuts: public GRBCallback add_full_iteration=false; } if(add_full_iteration){ - m->set_solution(vec_x); auto res2=m->cuts_eigen_full(1e-9); if(res2.size()>=1){ DebugOff("Added " << res2.size() << " full cuts\n"); @@ -467,6 +487,7 @@ void GurobiProgram::reset_model(){ bool GurobiProgram::solve(bool relax, double mipgap, double time_limit){ //cout << "\n Presolve = " << grb_env->get(GRB_IntParam_Presolve) << endl; // print_constraints(); + grb_mod->update(); if (relax) relax_model(); else unrelax_model(); @@ -474,7 +495,7 @@ bool GurobiProgram::solve(bool relax, double mipgap, double time_limit){ grb_mod->set(GRB_DoubleParam_MIPGap, 1e-6); grb_mod->set(GRB_DoubleParam_FeasibilityTol, 1e-9); - grb_mod->set(GRB_DoubleParam_OptimalityTol, 1e-9); +// grb_mod->set(GRB_DoubleParam_OptimalityTol, 1e-9); // grb_mod->set(GRB_IntParam_StartNodeLimit, -3); // grb_mod->getEnv().set(GRB_IntParam_DualReductions, 0); // grb_mod->getEnv().set(GRB_IntParam_PreCrush, 1); @@ -492,7 +513,7 @@ bool GurobiProgram::solve(bool relax, double mipgap, double time_limit){ // grb_mod->set(GRB_IntParam_RINS,1000); // grb_mod->set(GRB_IntParam_Cuts,0); - grb_mod->set(GRB_DoubleParam_TimeLimit,25200); + grb_mod->set(GRB_DoubleParam_TimeLimit,10800); grb_mod->set(GRB_IntParam_OutputFlag,1); //grb_mod->set(GRB_DoubleParam_Cutoff,5.33); // grb_mod->set(GRB_IntParam_MinRelNodes,0); @@ -793,7 +814,7 @@ void GurobiProgram::prepare_model(){ fill_in_grb_vmap(); create_grb_constraints(); set_grb_objective(); - grb_mod->write("gurobiprint.lp"); +// grb_mod->write("gurobiprint.lp"); // print_constraints(); } void GurobiProgram::update_model(){