Decision Optimization

Decision Optimization

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

 View Only
  • 1.  constraint in CPLEX Excel VBA

    Posted Mon September 17, 2012 12:29 AM

    Originally posted by: Yeahoos


    If I have a constraint of the form x <= y, for variables x and y, is it true that I need to allocate 3 cells: one for x, one for y, and one for the value of x - y?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: constraint in CPLEX Excel VBA

    Posted Thu September 20, 2012 04:42 AM

    Originally posted by: SystemAdmin


    At the moment I am not sure whether this is explicitly supported but I just tried with the GUI and there it seems to work: I used two variable cells A2 and A3 and added a constraint with lower bound empty, upper bound A3 and constraint A2 (which gives A2 <= A3).
    Did you observe an error when you tried this with macros?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: constraint in CPLEX Excel VBA

    Posted Thu September 20, 2012 10:08 PM

    Originally posted by: Yeahoos


    Okay, thanks, I see how it works for one constraint. But I still can't do

    x1 <= 2*y1
    x2 <= 2*y2

    using ranges. It works with the GUI: $A$1:$A$2 <= 2*$B$1:$B$2. But I am using the macros. Here is the code I tried:

    CPXaddVariable Variable:= ActiveSheet.Cells(1,1), Lb:=0, Ub:= 2
    CPXaddVariable Variable:= ActiveSheet.Cells(1,2), Lb:=0, Ub:= 1
    CPXaddVariable Variable:= ActiveSheet.Cells(2,1), Lb:=0, Ub:= 2
    CPXaddVariable Variable:= ActiveSheet.Cells(2,2), Lb:=0, Ub:= 1

    CPXaddConstraint Constraint:=Range(ActiveSheet.Cells(1,1),ActiveSheet.Cells(2,1)), Ub:=2*Range(ActiveSheet.Cells(1,2),ActiveSheet.Cells(2,2))

    I get a "Run-Time Error '13': Type mismatch.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: constraint in CPLEX Excel VBA

    Posted Mon September 24, 2012 12:12 PM

    Originally posted by: SystemAdmin


    The macros expect the LB or UB arguments to be a constant or a reference to a cell/range. So I'm afraid you cannot create those constraints using macros without using intermediate cells.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: constraint in CPLEX Excel VBA

    Posted Mon September 24, 2012 01:35 PM

    Originally posted by: Yeahoos


    Ok, thank you.
    #CPLEXOptimizers
    #DecisionOptimization