Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to use binary variable OPL CPLEX

    Posted 03/05/16 09:20 AM

    Originally posted by: islaabdi


    Hi everyone,

     

    I've got a problem with my optimization file. In fact I'm trying to use a binary variable but I've got some error (Cplex default can't extract the expression). Do I need to initialize the variable ? If yes how ?

     

    Here my data and mod files.

     

    Thanks


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to use binary variable OPL CPLEX

    Posted 03/05/16 11:21 PM

    Originally posted by: EdKlotz


    I don't have time to run your model; in general you may get more responses if you point to the specific lines that cause the

    errors.   I suspect they involve the multiplications of a float variable by a binary, such as

     

    allocate1:   (sum(i in Investments) Return[i]*Binary[i]*Allocation[i])>= 0.02;

      // sum of allocations equals amount to be invested

      allocate2: (sum (i in Investments) (Allocation[i]*Binary[i])) == Wealth;

     

    You declared these as

     

    dvar int  Binary[Investments] in 0..1;

    dvar float  Allocation[Investments] in FloatRange;  // Investment Level

     

    I don't think any of CPLEX's APIs will directly extract the product of a binary and continuous variable.

    You either need to linearize this expression through a series of constraints (you can search this forum and

    also www.or-exchange.org and will probably find a description of how to do that if it is unfamiliar, but you might

    want to try it yourself first), or you can make use OPL's logical if/then functionality and let OPL/CPLEX do the internal

    linearization.   In other words, declare an array of dvars, say z[i], and then specify the logical constraint

     

    if Binary[i] == 1 then z[i] = Allocate[i]

    if Binary[i] == 0 then z[i] = 0

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to use binary variable OPL CPLEX

    Posted 03/06/16 07:00 AM

    Originally posted by: islaabdi


    I'm sorry if my question wasn't clear. As you said the problem was from the product between a binary variable and a continuous. The solution was to linearize the expression and adding some constraint about it.

     

    Thanks you for your response.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to use binary variable OPL CPLEX

    Posted 03/06/16 09:13 AM

    Hi,

    this looks similar to

    https://www.ibm.com/developerworks/community/forums/html/topic?id=cee677ca-ee08-488e-82c6-851f26790d1d&ps=25

    You could  write a logical constraint like

    forall(i in Investments) Binary[i]==(Allocation[i]>=0.000001);

    and then you would be able to control the number of investments that are not zero.

    regards

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to use binary variable OPL CPLEX

    Posted 03/07/16 06:42 PM

    Originally posted by: EdKlotz


    I agree with both responses that followed mine.   But, the main point here is that while can indeed linearize the product of a binary and general integer yourself, you  can save yourself some work by taking advantage of the more powerful modeling constructs in either the OPL language or CPLEX's object oriented APIs.   If you use CPLEX's C API, then you do indeed need to do the linearization yourself.


    #CPLEXOptimizers
    #DecisionOptimization