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); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); 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); 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 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); IloSOS1Array sos1(env); IloSOS2Array sos2(env); cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2); cplex.use(SOSbranch(env, sos1)); 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 main (int argc, char **argv) { char const *vmconfig = NULL; // Check command line length (exactly two arguments are required). if ( argc != 3 ) { usage (argv[0]); return -1; } // Pick up VMC from command line. vmconfig = argv[1]; // Solve the model. int exitcode = 0; IloEnv env; try { // Create and read the model. IloModel model(env); IloCplex cplex(model); IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[2], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); // Load the virtual machine configuration. // This will force solve() to use parallel distributed MIP. cplex.readVMConfig(vmconfig); // Install logging info callback. IloNum lastObjVal = (obj.getSense() == IloObjective::Minimize ) ? IloInfinity : -IloInfinity; cplex.use(loggingCallback(env, var, -100000, lastObjVal, cplex.getCplexTime(), cplex.getDetTime())); // Turn off CPLEX logging cplex.setParam(IloCplex::Param::MIP::Display, 0); // Solve the problem and display some results. if ( cplex.solve() ) env.out() << "Solution value = " << cplex.getObjValue() << endl; else env.out() << "No solution" << endl; env.out() << "Solution status = " << cplex.getStatus() << endl; // Cleanup. cplex.end(); model.end(); } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; exitcode = -1; } catch (...) { cerr << "Unknown exception caught" << endl; exitcode = -1; } env.end(); return exitcode; } // 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
int main (int argc, char **argv) { IloEnv env; try { IloModel model(env); IloCplex cplex(env); IloBool useLoggingCallback = IloFalse; IloBool useTimeLimitCallback = IloFalse; IloBool useAborter = IloFalse; if (( argc != 3 ) || ( strchr ("lat", argv[2][0]) == NULL ) ) { usage (argv[0]); throw(-1); } switch (argv[2][0]) { case 'l': useLoggingCallback = IloTrue; break; case 't': useTimeLimitCallback = IloTrue; break; case 'a': useAborter = IloTrue; break; default: break; } IloObjective obj; IloNumVarArray var(env); IloRangeArray rng(env); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); IloCplex::Aborter myAborter; cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints (lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts (cuts); if ( useLoggingCallback ) { // Set an overall node limit in case callback conditions // are not met. cplex.setParam(IloCplex::Param::MIP::Limits::Nodes, 5000); IloNum lastObjVal = (obj.getSense() == IloObjective::Minimize ) ? IloInfinity : -IloInfinity; cplex.use(loggingCallback(env, var, -100000, lastObjVal, cplex.getCplexTime(), cplex.getDetTime())); // Turn off CPLEX logging cplex.setParam(IloCplex::Param::MIP::Display, 0); } else if ( useTimeLimitCallback ) { cplex.use(timeLimitCallback(env, cplex, IloFalse, cplex.getCplexTime(), 1.0, 10.0)); } else if ( useAborter ) { myAborter = IloCplex::Aborter(env); cplex.use(myAborter); // Typically, you would pass the Aborter object to // another thread or pass it to an interrupt handler, // and monitor for some event to occur. When it does, // call the Aborter's abort method. // // To illustrate its use without creating a thread or // an interrupt handler, abort immediately by calling // abort before the solve. // myAborter.abort(); } cplex.solve(); env.out() << endl; env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "CPLEX status = " << cplex.getCplexStatus() << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main
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); IloSOS1Array sos1(env); IloSOS2Array sos2(env); IloRangeArray lazy(env); IloRangeArray cuts(env); cplex.importModel(model, argv[1], obj, var, rng, sos1, sos2, lazy, cuts); /* Set the solution pool relative gap parameter to obtain solutions of objective value within 10% of the optimal */ cplex.setParam(IloCplex::Param::MIP::Pool::RelGap, 0.1); cplex.extract(model); if ( lazy.getSize() > 0 ) cplex.addLazyConstraints(lazy); if ( cuts.getSize() > 0 ) cplex.addUserCuts(cuts); cplex.populate(); env.out() << "Solution status = " << cplex.getStatus() << endl; env.out() << "Incumbent objective value = " << cplex.getObjValue() << endl; IloNumArray incvals(env); cplex.getValues(incvals, var); env.out() << "Incumbent values = " << incvals << endl << endl; /* Get the number of solutions in the solution pool */ int numsol = cplex.getSolnPoolNsolns(); env.out() << "The solution pool contains " << numsol << " solutions." << endl; /* Some solutions are deleted from the pool because of the solution pool relative gap parameter */ int numsolreplaced = cplex.getSolnPoolNreplaced(); env.out() << numsolreplaced << " solutions were removed due to the " "solution pool relative gap parameter." << endl; env.out() << "In total, " << numsol + numsolreplaced << " solutions were generated." << endl; /* Get the average objective value of solutions in the solution pool */ env.out() << "The average objective value of the solutions is " << cplex.getSolnPoolMeanObjValue() << "." << endl << endl; /* Write out the objective value of each solution and its difference to the incumbent */ for (int i = 0; i < numsol; i++) { /* Write out objective value */ env.out() << "Solution " << i << " with objective " << cplex.getObjValue(i) << " differs in "; IloNumArray vals(env); cplex.getValues(vals, var, i); /* Compute the number of variables that differ in the solution and in the incumbent */ int numdiff = 0; for (int j = 0; j < vals.getSize(); j++) { if ( fabs(vals[j] - incvals[j]) > EPSZERO ) numdiff++; } env.out() << numdiff << " of " << vals.getSize() << " variables." << endl; } } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); return 0; } // END main