Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Issue with Adding Constraints into an array list

  • 1.  Issue with Adding Constraints into an array list

    Posted 08/01/18 10:50 AM

    Originally posted by: Bahman


    Hello Everyone,

    I am learning to code optimization problems using Java API and I have an issue in saving the last constraints of the following simple LP into the Array List named Constraints. without that, the code runs, however, an error pops up as I make this line of code active:

    Constraints.add(model.addEq(proportionalWeight[j], y));

    instead of the following line:

     

    model.addEq(proportionalWeight[j], y);

     

    please find the code attached. 

     

    I would really appreciate if you could help me out with this issue.

     

    Regards,
    Bahman 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Issue with Adding Constraints into an array list

    Posted 08/01/18 12:17 PM

    The problem is this:

    As you can see, this returns an instance of IloConstraint, not IloRange. Hence you cannot put the returned object into a list of IloRange instances.

    There are a number of remedies, including:

    • Change the type of the list to be a list of IloConstraint instances
    • change the addEq() call to something that will use an overload that returns a range, for example addEq(model.diff(proportionalWeight[j], y), 0.0)

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Issue with Adding Constraints into an array list

    Posted 08/01/18 01:43 PM

    Originally posted by: Bahman


    Hi Daniel,

    Thank you! Both of the remedies actually worked. I appreciate it.

    Regards,
    Bahman Bornay


    #CPLEXOptimizers
    #DecisionOptimization