void BNC::configureCPLEX(){ op1=op2=0; //disable output //cplex->setOut(env->getNullStream()); //define a time limit execution cplex->setParam( IloCplex::TiLim, time_limit ); //disable presolve cplex->setParam( IloCplex::PreInd, false ); //assure linear mappings between the presolved and original models cplex->setParam( IloCplex::PreLinear, 0 ); //Turn on traditional search for use with control callback cplex->setParam( IloCplex::MIPSearch, IloCplex::Traditional); //Decides how often to apply the periodic heuristic. Setting the value to -1 turns off the periodic heuristic cplex->setParam( IloCplex::HeurFreq, 0 ); //CPX_PARAM_MIPCBREDLP equivalent is not availible in c++ api //cpx_ret = CPXsetintparam (env, CPX_PARAM_MIPCBREDLP, CPX_OFF); /* impressao para conferencia */ if (primal_heuristic) { //cout << "*** Primal Heuristic is going to be used." << endl; cplex->use(Rounddown(*env, *variables, graph, adj)); } cplex->setParam( IloCplex::FracCuts, -1 ); //disable cplex cutting separation cplex->setParam( IloCplex::CutsFactor, 1.0);//conferir valor //Decides whether or not Gomory fractional cuts should be generated for the problem: -1 disables cuts cplex->setParam( IloCplex::FracCuts, -1 ); //Controls whether CPLEX applies a local branching heuristic to try to improve new incumbents found during a MIP search cplex->setParam( IloCplex::LBHeur, false ); //Set the upper limit on the number of cutting plane passes CPLEX performs when solving the root node of a MIP model printf("N cortes %d\n", n_cortes); printf("MaxDeep %d\n", max_deep); //status = CPXsetintparam (env, CPX_PARAM_DATACHECK, CPX_ON); //actives the node callback MySelect cplex->use( MySelect( *env, ¤t_deep ) ); }
int main (int argc, char **argv) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); if ( argc != 2 ) { usage (argv[0]); throw(-1); } IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); cplex.importModel(model, argv[1], obj, var, rng); cplex.use(MyBranch(env, var)); cplex.use(MySelect(env)); cplex.setParam(IloCplex::Param::MIP::Strategy::Search, IloCplex::Traditional); cplex.extract(model); cplex.solve(); IloNumArray vals(env); cplex.getValues(vals, var); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Solution value = " << cplex.getObjValue() << endl; env.out() << "Values = " << vals << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main
int solveCplex (char * str,ListStructure<number_element> * l) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, str, obj, var, rng, sos1, sos2, lazy, cuts); cplex.use(MyBranch(env, var)); cplex.use(MySelect(env)); cplex.setParam(IloCplex::MIPSearch, IloCplex::Traditional); cplex.extract(model); cplex.setParam(IloCplex::EpInt,0.000000000001); cplex.setParam(IloCplex::TiLim,120*60); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); cplex.solve(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Solution value = " << cplex.getObjValue() << endl; IloNumArray vals(env); cplex.getValues(vals, var); //IloObjective obj=cplex.getObjective(); env.out() << "Values = " << vals << endl; long long sum=0; int a=vals.getSize(); for(int i=0;i<a;i++){ int b=l->getSize(); number_element n=l->retrieve_K_esimo(i%b)->element; if(i<b){ if(vals[i]>0.9){ sum+=n.id; } }else{ if(vals[i]>0.9){ sum-=n.id; } } } } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); } // END main