コード例 #1
0
ファイル: startEndModel.cpp プロジェクト: sims2B/Expe_these
int LPsolveSE(const Problem<double>& P,const std::vector<int>& config,int time_limite) {  
  try{
    IloNum start,time_exec;
    const int nbTask = P.nbTask;
    const int E=2*nbTask;
    
    IloEnv env;
    IloModel model(env);
    IloNumVarMatrix x(env,nbTask),y(env,nbTask);
    IloNumVarMatrix b(env,nbTask), w(env,nbTask);
    IloNumVarArray t(env, E, 0, P.D, ILOFLOAT);
    
    // create cplex model
    createModel(P,env,model,t,x,y,b,w,config);
    for (int i=0;i<nbTask;++i){
      for (int e=0;e<E;++e){
	model.add(IloConversion(env,x[i][e],ILOFLOAT));
	model.add(IloConversion(env,y[i][e],ILOFLOAT));
      }
    }
    IloCplex cplex(model);
    setCplexParam(cplex,env,time_limite);
    start= cplex.getCplexTime();
      
    // solve !
    if (cplex.solve()) {	 
      time_exec=cplex.getCplexTime()-start;
      std::cout << "Final status: \t"<< cplex.getStatus() << std::endl;
      std::cout << "Final time: \t"<< time_exec << std::endl;
      std:: cout << "Final objective: " << cplex.getObjValue() <<"\nFinal gap: \t" 
		 << cplex.getMIPRelativeGap()<< std::endl;   
            env.end();
      return 0;
    }
    else if (cplex.getStatus()==IloAlgorithm::Infeasible){
      time_exec=cplex.getCplexTime()-start;
      std::cout << "status: "<< cplex.getStatus() << " en " << time_exec << std::endl;
    }
    env.end();
    return 1;
  }
  catch (IloException &e){
    std::cout << "Iloexception in solve" << e << std::endl;
    e.end();
    return  1;
  }
}
コード例 #2
0
void profit_solve(graph g, vector<int>& allocation, vector<double>& pricing, bool integer) {
  int **columns = (int **)malloc(g->bidders * sizeof(int *));
  for(int i = 0; i < g->bidders; i++)
    columns[i] = (int *)calloc(g->items, sizeof(int));
  IloEnv env;
  try {
    if(getVerbosity() != CplexOutput)
      env.setOut(env.getNullStream());
    IloModel model(env);
    IloNumVarArray x(env);
    IloNumVarArray p(env);
    IloNumVarArray z(env);
    IloCplex cplex(model);
    profit_create_vars(g, model, x, p, z, columns);
    profit_create_objective(g, model, x, z, columns);
    model.add(profit_constraints(g, model, x, p, z, columns));
    config_cplex(cplex); 
    if(!integer) {
      model.add(IloConversion(env, x, ILOFLOAT));
    } else {
      profit_load(g, cplex, model, x, p, z, columns, allocation, pricing);
    }
    clock_start();
    if (!cplex.solve()) {
      failed_print(g);
    } else {
      if(integer)
        solution_print(cplex, env, g);  
      else
        relax_print(cplex, env);
    }
  }
  catch (IloException& e) {
    cerr << "Concert exception caught: " << e << endl;
  }
  catch (...) {
    cerr << "Unknown exception caught" << endl;
  }
}
コード例 #3
0
ファイル: cutstock.cpp プロジェクト: annaPolytech/PRD
int
main(int argc, char **argv)
{
   IloEnv env;
   try {
      IloInt  i, j;

      IloNum      rollWidth;
      IloNumArray amount(env);
      IloNumArray size(env);

      if ( argc > 1 )
         readData(argv[1], rollWidth, size, amount);
      else
         readData("../../../examples/data/cutstock.dat",
                  rollWidth, size, amount);

      /// CUTTING-OPTIMIZATION PROBLEM ///

      IloModel cutOpt (env);

      IloObjective   RollsUsed = IloAdd(cutOpt, IloMinimize(env));
      IloRangeArray  Fill = IloAdd(cutOpt,
                                   IloRangeArray(env, amount, IloInfinity));
      IloNumVarArray Cut(env);

      IloInt nWdth = size.getSize();
      for (j = 0; j < nWdth; j++) {
         Cut.add(IloNumVar(RollsUsed(1) + Fill[j](int(rollWidth / size[j]))));
      }
      
      IloCplex cutSolver(cutOpt);

      /// PATTERN-GENERATION PROBLEM ///

      IloModel patGen (env);

      IloObjective ReducedCost = IloAdd(patGen, IloMinimize(env, 1));
      IloNumVarArray Use(env, nWdth, 0.0, IloInfinity, ILOINT);
      patGen.add(IloScalProd(size, Use) <= rollWidth);

      IloCplex patSolver(patGen);

      /// COLUMN-GENERATION PROCEDURE ///

      IloNumArray price(env, nWdth);
      IloNumArray newPatt(env, nWdth);

      /// COLUMN-GENERATION PROCEDURE ///

      for (;;) {
         /// OPTIMIZE OVER CURRENT PATTERNS ///
       
         cutSolver.solve();
         report1 (cutSolver, Cut, Fill);
       
         /// FIND AND ADD A NEW PATTERN ///
       
         for (i = 0; i < nWdth; i++) {
           price[i] = -cutSolver.getDual(Fill[i]);
         }
         ReducedCost.setLinearCoefs(Use, price);
       
         patSolver.solve();
         report2 (patSolver, Use, ReducedCost);
       
         if (patSolver.getValue(ReducedCost) > -RC_EPS) break;
       
         patSolver.getValues(newPatt, Use);
         Cut.add( IloNumVar(RollsUsed(1) + Fill(newPatt)) );
      }

      cutOpt.add(IloConversion(env, Cut, ILOINT));

      cutSolver.solve();
      cout << "Solution status: " << cutSolver.getStatus() << endl;
      report3 (cutSolver, Cut);
   }
   catch (IloException& ex) {
      cerr << "Error: " << ex << endl;
   }
   catch (...) {
      cerr << "Error" << endl;
   }

   env.end();

   return 0;
}