Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  un problème dans le cplex

    Posted Fri April 15, 2016 10:01 AM

    Originally posted by: benzaid_yasmine@hotmail.fr


    Bonjour a tous svp est ce que quelqu'un pourrai me dire ou est le problème dans mon programe:

     

    #include<ilcplex/ilocplex.h>
    ILOSTLBEGIN

    typedef IloArray<IloNumVarArray> IloNumVarArray2;

    int main(int argc,char **argv){

        IloEnv env;
        try{
            const char* filename="steel.dat";

            if(argc >= 2) filename = argv[1];
            ifstream file(filename);
            if(!file){
                cerr<<"no_sush_file"<<filename<<endl;
                throw(-1);

            }

            IloNumArray avail(env),rate(env),inv0(env),prodCost(env),invCost(env);
            IloNumArray2 revenue(env),market(env);

            file >> avail >> rate >> inv0 >> prodCost >> invCost >> revenue >> market;


            IloInt nProd=rate.getSize();

            IloInt nTime=avail.getSize();
            //IloInt nTime=4;

            IloInt p,t ;
            IloModel mod(env);

            IloNumVarArray2 Make(env);
            for(p=0;p<nProd;p++){
                Make.add(IloNumVarArray(env,nTime,0.0,IloInfinity));
            }
            IloNumVarArray2 Inv(env);
            for(p=0;p<nProd;p++){
             Inv.add(IloNumVarArray(env,nTime,0.0,IloInfinity));
                    }

            IloNumVarArray2 Sell(env);

            for(p=0; p<nProd ;p++){
                Sell.add(IloNumVarArray(env, 0.0 , market[p]));
            }
    cout<<"la fonction objectif"<<endl;

           IloExpr TotalRevenue(env),TotalProdCost(env),TotalInvCost(env);
           for(p=0; p<nProd; p++){
               for(t=1; t<nTime;t++){
                   TotalRevenue += revenue[p][t]*Sell[p][t];
                   TotalProdCost += prodCost[p]*Make[p][t];
                   TotalInvCost +=invCost[p]*Inv[p][t];

               }
           }
           mod.add(IloMaximize(env,TotalRevenue-TotalProdCost-TotalInvCost));
           TotalRevenue .end();
           TotalProdCost.end();
           TotalInvCost .end();


    cout<<"contrainte de temps"<<endl;
           for(t=0;t<nTime;t++){
              IloExpr availExpr(env);
              for(p=0;p<nProd;p++){
                  availExpr+=(1/rate[p])*Make[p][t];
              }
              mod.add(availExpr<=avail[t]);
              availExpr.end();
           }

    cout<<"contrainte de balnce "<<endl;
           for(p=0;p<nProd;p++){

               mod.add(Make[p][0]+inv0[p]==Sell[p][0]+Inv[p][t]);

               for(t=1;t<nTime;t++){
                       mod.add(Make[p][t]+Inv[p][t-1]==Sell[p][t]+Inv[p][t]);

            }
           }
          IloCplex cplex(mod);
          cplex.exportModel("steel.lp");

          cplex.solve();

          env.out()<<endl<<"total-profit:"<<cplex.getObjValue()<<endl;
          env.out()<<endl<<"tp\tt\tMake\tInv\tSell"<<endl;

          for(p=0;p<nProd;p++){
              for(t=0;t<nTime;t++){

                  env.out()<<'t'<<p
                          <<'t'<<t
                          <<'t'<<cplex.getValue(Make[p][t] )
                          <<'t'<<cplex.getValue(Inv[p][t])
                          <<'t'<<cplex.getValue(Sell[p][t])<<endl;


                }

          }
        }
          catch(IloException& ex){
              cout<<"Error:"<<ex<<endl;
          }
    catch(...){
        cout<<"Error:Unknow exception caught"<<endl;
    }
    env.end();

    return 0;

     

        }

     

    mon data est

    [40,40,62,40]
    [200,140]
    [10,0]
    [10,11]
    [2.5,3]
    [[0,25,27,27],[30,35,37,39]]
    [[6000,6000,4000,6500],[4000,2500,3500,4200]]

     

     

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: un problème dans le cplex

    Posted Fri April 15, 2016 10:02 AM

    Originally posted by: benzaid_yasmine@hotmail.fr


    l'erreur qui s'affiche est :

     

    X& IloArray::operator[] (IloInt i) : Out of bounds operation: index superior to size of array
    model1: /opt/local/stow/cplex124/CPLEX_Studio/concert/include/ilconcert/iloenv.h:2200: X& IloArray<X>::operator[](IloInt) [with X = IloExtractable; IloInt = long int]: Assertion `(i < _impl->getSize()) || (std:: cerr << "X& IloArray::operator[] (IloInt i) : Out of bounds operation: index superior to size of array" << std:: endl, ilo_stop_assert())' failed.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: un problème dans le cplex

    Posted Mon April 18, 2016 04:57 AM

    You are accessing an array index that does not exist. You should

    • track down at which line the assertion failure happens,
    • check which are the indices you are trying to access,
    • make sure you are using only valid indices instead (either fix the limits of your loop or make sure you initialize all data).

    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: un problème dans le cplex

    Posted Mon April 18, 2016 08:57 AM

    Originally posted by: benzaid_yasmine@hotmail.fr


    hello , please how can i initialise an arrat with N ligne and K colonne ?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: un problème dans le cplex

    Posted Tue April 19, 2016 04:00 AM

    Are you talking about a plain C++ array or an instance of IloNumArray or IloNumVarArray?

    In general it probably is a good idea to the various C++ examples shipped with CPLEX. These examples contain code that uses multi-dimensional arrays.


    #CPLEXOptimizers
    #DecisionOptimization