Decision Optimization

 View Only
  • 1.  Doubt Cplex C and C++

    Posted Tue March 08, 2011 01:18 PM

    Originally posted by: dbaena


    Hi,
    I want to use the status code CPX_TIME_LIM_FEAS or CPX_TIME_LIM_INFEAS but not in C. I am using C++ Ilog Concert. I dont find the equivalent parameter.
    I need it in order to know if I have feasible solutions or not when I exit by time limit. I need it because Local Branching code use it.

    Thanks a lot.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Doubt Cplex C and C++

    Posted Tue March 08, 2011 02:40 PM

    Originally posted by: SystemAdmin


    I guess you are talking about CPXMIP_TIME_LIM_FEAS and CPXMIP_TIME_LIM_INFEAS?
    I don't see these two guys in the C++ API either. But you can easily define them yourself and test like this:
    if ( cplex.getCplexStatus() == IloCplex::CplexStatus(CPXMIP_TIME_LIM_FEAS) ) {
       // Aborted due to time limit, feasible solution exists.
       ...
    }
    else if (cplex.getCplexStatus() == IloCplex::CplexStatus(CPXMIP_TIME_LIM_INFEAS) ) {
       // Aborted due to time limit, no feasible solution eixsts.
       ...
    }
    

    Or construct a suitable switch statement.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Doubt Cplex C and C++

    Posted Wed March 09, 2011 04:48 PM

    Originally posted by: dbaena


    Hi Daniel,

    Thanks a lot, but it doesn't work. Maybe I didn't explain well. I have a MIP problem and I have done:

    cplex.setParam(IloCplex::TiLim,TL);

    when I do:

    status=cplex.getCplexStatus() it returns the value 11.

    This value is (in API C++) --> CPX_STAT_ABORT_TIME_LIM.

    With this code I don't know if I have found feasible solutions or not. However, the same situation with C returns CPXMIP_TIME_LIM_FEAS or CPXMIP_TIME_LIM_INFEAS...

    Thanks a lot.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Doubt Cplex C and C++

    Posted Thu March 10, 2011 05:01 AM

    Originally posted by: SystemAdmin


    The function IloCplex::solve() (see here) returns true if a solution is available. So you just need to check what that function returns.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Doubt Cplex C and C++

    Posted Thu March 10, 2011 02:02 PM

    Originally posted by: dbaena


    OK. Yes, now I can do it. Thank you Daniel.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Doubt Cplex C and C++

    Posted Thu March 10, 2011 05:37 PM

    Originally posted by: GuangFeng


    One remark is that when you check CPLEX status by using Concert function IloCplex::getCplexStatus(), you should check the result against the values in enumeration IloCplex::CplexStatus, instead of relying on the numerical values listed in optim.cplex.solutionstatus. The reason is that Concert API has a different view of the problem from callable libraries. For example, there is no differentiation in problem types. You use IloCplex::solve() to solve all problems, but in callable libraries, you need a problem specific function.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Doubt Cplex C and C++

    Posted Mon March 14, 2011 02:43 PM

    Originally posted by: dbaena


    Thanks GuangFeng, but I don't understand what do you mean.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Doubt Cplex C and C++

    Posted Mon March 14, 2011 06:10 PM

    Originally posted by: dbaena


    Hi,

    I'll solve my problem that I said, using SolutionPool of CPLEX. I explain it. Maybe it is interesting.

    I do:

    cplex.solve();
    status = cplex.getCplexStatus();
    if (status == CPX_STAT_ABORT_TIME_LIM)
    {
    int nsols=cplex.getSolnPoolNsolns();
    if (nsols>0)
    {
    // I HAVE FEASIBLE SOLUTIONS
    }
    else
    {
    // INFEASIBLE SOLUTIONS
    }
    If you want to know the objective value of each solution you can iterate for each solution (i) and do:

    cplex.getObjValue(i);
    cplex.getValues(IloNumArray,IloNumVarArray,i);
    I Hope it help you!
    }
    #CPLEXOptimizers
    #DecisionOptimization