Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solving Problem Error

    Posted 05/20/14 09:08 AM

    Originally posted by: thomasmoreaumaster


    Hi everybody,

     

    My name is Thomas and i'm a master degree student in France.

    I started one month ago a new project , But i'm stucked and i can't find any solutions this is why i'm posting a new topic.

    First of all, all i needed to do is implement thoses methods bellow:

    4.1 Linearization
    We use the formulation (2)-(5) to develop a mixed integer linear programming (MILP)
    formulation for MRCP. We follow the linearization framework proposed by Wu (1997).

    4.2 Binary search
    Binary search has been used as a method to solve fractional programming problems
    by Lawler (1976) and Ibaraki (1983). We adopt this method for MRCP as follows.

    4.3 Newton's method
    Newton's MNewton's Method for fractional programming problems was proposed by Isbell and
    Marlow (1956) and has been adapted to MRCP here.ethod for fractional programming problems was proposed by Isbell and
     

    But all i can get from my computer is an error of type : terminate called after throwing an instance of 'IloCplex::Exception'

    Or terminate called after throwing an instance of 'IloAlgorithm::CannotExtractException'

     

    I did spend a lotf of times on the internet in order to find what is wrong with my code but i couldn't find.

    Here is my code in CPP using Concert Technology:

    #include"Compute.h"

    using namespace std;
    ILOSTLBEGIN//

    void q_compute(int size,std::vector<double> vector_a_i,std::vector<double> vector_b_i,double alpha,std::vector<std::vector<int> > &matr,std::vector<int> clique,double & palpha,std::vector<int> & c_alpha)
    {
        //Creating environment
        IloEnv env;
        //creating the model
        IloModel model(env);
        //creating variable x
        IloNumVarArray x(env,size,0,1,ILOBOOL);

        cout<<"creating objective function"<<endl;


        IloExpr obj(env);
        for(int i=0;i<size;++i)
        {
            obj+=vector_a_i[i]*x[i];
            obj-=vector_b_i[i]*alpha*x[i];
        }
        IloObjective obj2 (env,obj,IloObjective::Maximize);
        model.add(obj2);
    //    model.add(IloMaximize(env,obj));

        cout<<"creating constraints"<<endl;
        for(int i=0;i<size;++i)
            for(int j=0;j<size;++j)
                if(i!=j && !matr[i][j])
                    model.add(x[i]+x[j]<=1);
        cout<<"First added"<<endl;
        for(int j=0;j<size;++j)
        {
            IloExpr cont(env);
            for(int i=0;i<size;++i)
                cont+=(1-matr[i][j])*x[i];
            model.add(cont>=1);
        }
        for(int i=0;i<size;++i)
        {
            model.add(x[i]<=1);
            model.add(x[i]>=0);
        }
        cout<<"model"<<endl;
        IloCplex cplex(model);

        cout<<"Solving the problem"<<endl;
        cplex.solve();
        cout<<"cplex solved"<<endl;
        //Print results
        cout << "The objective value is " << cplex.getObjValue() << endl;
        palpha=cplex.getObjValue();
        for(int i=0;i<size;++i)
        {
            cout << "X :"<<i<<" values are " << cplex.getValue(x[i]) << endl;
            c_alpha[i]=cplex.getValue(x[i]);
        }
        env.end();
    }
    double getAlpha1(std::vector<int> anyMC,std::vector<double> vector_a_i,std::vector<double> vector_b_i)
    {
            double a=0,b=0;
            for(int i=0;i<anyMC.size();++i)
            {
                    if(anyMC[i])
                    {
                            a+=vector_a_i[i];
                            b+=vector_b_i[i];
                    }
            }
            return a/b;
    }
    void m_compute(int size,std::vector<double> vector_a_i,std::vector<double> vector_b_i,std::vector<std::vector<int> > &matr,std::vector<int> clique,double LowerBound,double UpperBound)
    {
        //creating environment
        IloEnv env;
        //creating model
        IloModel model(env);
        //creating variable x
        IloNumVarArray x(env,size,0,1,ILOINT);
        cout<<"creating objective function"<<endl;
        IloExpr cont(env);
        for(int i=0;i<size;++i)
            cont+=(1/(vector_b_i[i]*x[i]));
        IloExpr obj(env);

        for(int i=0;i<size;++i)
            obj+=vector_a_i[i]*cont*x[i];

        model.add(IloMaximize(env,obj));

        cout<<"creating constraints"<<endl;
        for(int i=0;i<size;++i)
            for(int j=0;j<size;++j)
                if(i!=j && !matr[i][j])
                    model.add(x[i]+x[j]<=1);

        cout<<"First added mcompute"<<endl;
        for(int j=0;j<size;++j)
        {
            IloExpr cont2(env);
            for(int i=0;i<size;++i)
                cont2+=(1-matr[i][j])*x[i];
            model.add(cont2>=1);
        }
        cout<<"Second Added"<<endl;
        IloExpr cont3(env);
        for(int i=0;i<size;++i)
            cont3+=vector_b_i[i]*cont*x[i];
        model.add(cont3==1);
        cout<<"Third added"<<endl;
        for(int i=0;i<size;++i)
            if(clique[i])
            {
                model.add(cont*x[i]<=UpperBound*x[i]);
                model.add(cont*x[i]>=LowerBound*x[i]);
                model.add(cont*x[i]<=cont-LowerBound*(1-x[i]));
                model.add(cont*x[i]>=cont-UpperBound*(1-x[i]));
                model.add(cont >= LowerBound);
                model.add(cont <= UpperBound);
                model.add(cont*x[i]>=0);
            }

        cout<<"Creating model"<<endl;
        IloCplex cplex(model);

        cout<<"Solving the problem"<<endl;
        cplex.solve();

        //Print results
        cout << "The objective value is " << cplex.getObjValue() << endl;
        for(int i=0;i<x.getSize();++i)
        cout << "X :"<<i<<" values are " << cplex.getValue(x[i]) << endl;

        env.end();
    }

    You'll find in attachments the file that i used to buil my code from.

    Can someon can see what is wrong ?

    Thank you very much for your time and your answer,

    Thomas.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Solving Problem Error

    Posted 05/20/14 09:33 AM

    This is a problem:

    for(int i=0;i<size;++i)
            cont+=(1/(vector_b_i[i]*x[i]));
    

    Neither CPLEX nor CP support quotients with variables in the denominator.

    To find errors more quickly you should add try/catch to your code and print out the exceptions you get. This will give you more details about the issues. If you get a "cannot extract" exception then the exception should be an instance of IloAlgorithm::CannotExtractException. This has a getExtractables() member function that lists all the extractables that could not be extracted. Printing them should give you a quick idea of which expressions cause trouble.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Solving Problem Error

    Posted 05/20/14 09:47 AM

    Originally posted by: thomasmoreaumaster


    Hi DanielJunglas,

     

    Thank you a lot about the try and catch advice.

    I can get this error now CPLEX Error  3023: Integer feasible solution values are unavailable.

    for the q_compute function.

    May i ask you how am i suppose to code expression with quotient ?

     

    Thank you,

    Thomas.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Solving Problem Error

    Posted 05/21/14 02:52 AM

    For the error 3023: Could you export the model (cplex.exportModel("q_compute.sav") before solving and then post the .sav file here? Or at least show us the log for this solve.

    Since CPLEX does not support quotients with variables in the denominator you need to reformulate your model/constraint in a way that does not have such quotients. For this, it is probably easier to work on the mathematical formulation of the model instead of the C++ code.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Solving Problem Error

    Posted 05/21/14 04:26 AM

    Originally posted by: thomasmoreaumaster


    Hi,

     

    You will find in attachments the q_compute.sav file.

    i tried to read it with gnu pspp but it don't seem to work.

    The Q_compute function works when i'm calling it from the binary search but it doesn't when i try to call it from my newton search.

     

    Thank you so much for your time and your advice.

    Thomas.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Solving Problem Error

    Posted 05/21/14 08:43 AM

    Originally posted by: thomasmoreaumaster


    Hi,

     

    Thank you so much for your help, i did find my horrible mistake.

    I didn't initialised any maximal clique correctly so the algorithm didn't work properly.

     

    Thank you again for spending time on my problem,

    Thomas.


    #CPLEXOptimizers
    #DecisionOptimization