Beispiel #1
0
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
Beispiel #2
0
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