Decision Optimization

Decision Optimization

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

 View Only
  • 1.  CPLEX Excel VBA error for simple objective function coefficient

    Posted Mon September 17, 2012 01:23 AM

    Originally posted by: Yeahoos


    When I run the macro "Example" in the attached workbook, I get the error:

    Failed to setup optimization problem.
    Error 24: Cannot convert value to number.

    There is one variable. The coefficient on the variable in the objective function is 0.2 divided by the sum of other data (the sum is 46). I'm guessing this is why I am getting the error, but it seems like something I should be able to do, right? I am dividing by data to get an objective coefficient. Variables are not used as divisors.

    Any ideas?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Mon September 17, 2012 01:28 AM

    Originally posted by: Yeahoos


    I guess I wasn't able to post my workbook. Here is the macro:

    Sub Example()
    CPXclear
    CPXaddVariable Variable:=ActiveSheet.Cells(5, 3), Lb:=4, Ub:=6
    CPXsetObjective ObjCell:=ActiveSheet.Cells(6, 3), Sense:=2

    CPXsolve
    End Sub

    The sheet has a values of 34, 0, and 12 in C1, D1, and E1, resp. Cell C4 has the formula "=0.2/(SUM(C2:E2)+1)". Cell C6 has the formula "=C4*C5".
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Thu September 20, 2012 03:40 AM

    Originally posted by: SystemAdmin


    According to your post the formula in cell C4 references C2, D2 and E2. You gave only data for C1, D1, and E1. Is this a typo or does C2 indeed reference empty cells?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Thu September 20, 2012 09:29 AM

    Originally posted by: Yeahoos


    Sorry, yes, the data are in C2, D2, and E2; C1:E1 are blank.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Tue September 25, 2012 06:50 AM

    Originally posted by: SystemAdmin


    Does it help to replace the formula
    =0.2/(SUM(C2:E2)+1)
    

    by the equivalent expression
    =0.2/(C2 + D2 + E2 + 1)
    

    ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Tue September 25, 2012 09:39 AM

    Originally posted by: Yeahoos


    Yes, it does. It compiles and runs with no errors with the 'SUM' function removed. What gives?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Wed September 26, 2012 07:18 AM

    Originally posted by: SystemAdmin


    Looks like you have found a bug in the CPLEX Excel connector :-(
    I have filed a bug report.
    Right now the only workaround I see is to use '+' instead of SUM.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: CPLEX Excel VBA error for simple objective function coefficient

    Posted Wed September 26, 2012 12:54 PM

    Originally posted by: Yeahoos


    Ok, thanks for following up. I'll look for the fix. In the meantime, I'm just using VB to call CPLEX which works really nicely.
    #CPLEXOptimizers
    #DecisionOptimization