Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  getValues Error

    Posted 07/06/17 03:12 AM

    Originally posted by: a.teuffel


    Hi,

    I build a cplex lp model in a .net application using the .net API. After solving the problem I want to extract the solution values using cplex.getvalues().

    When I do this I come across the error: CPLEX Error: object is unknown to IloCplex.

    I know what causes the problem thanks to this thread: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014530212

    I use  

     Dim x As INumVar() = model.NumVarArray(Varname.Count, lb, ub, vartype, varn)
    

    entering the variables with their respective bounds when building the model. The problem is that I can not guarantee that there will be variables added which are not used in any constraint later on.

    As I understand,

    model.getValues(x)
    

    can only give me the values of variables which are at least occuring in one constraint or objective function.

     

    Can you help me find a way to cope with this? Is there a way to extract a INumVar from the model which contains only the "used" variables which then could be used in getVariables() ?

    Or maybe is there a simple way to identify which variables are not used and remove them from x?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: getValues Error

    Posted 07/06/17 03:22 AM

    The thread you found is not the best answer for your question. There are other threads that provide a more clear answer. Bad luck.

    Anyway: There is no way to get a list of "used" variables. However, you can easily work around your problem by explicitly adding all the variables to the model:

    Dim x As INumVar() = model.NumVarArray(Varname.Count, lb, ub, vartype, varn)
    model.Add(x)

    After this getValues() should no longer fail. If any variable is not used it will be eliminated by presolve, so performance should not suffer unless you have many thousands of such variables.
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: getValues Error

    Posted 07/06/17 03:27 AM

    Originally posted by: a.teuffel


    Thank you that helped!

    Why didn't I have to add the variables explicitly to the model with model.Add(x) in the first place?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: getValues Error

    Posted 07/06/17 03:35 AM

    When you add a constraint or objective function to a model then all variables referenced by this constraint or the objective function are implicitly added to the model. That is why you usually do not have to explicitly add variables.

    Note that cplex.numVarArray() does not add the created variables to the model.
     


    #CPLEXOptimizers
    #DecisionOptimization