Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  expressing a = b = c

    Posted 11/10/16 10:17 AM

    Originally posted by: gorlami


    I am trying to code the expression a = b = c as a constraint in C# Cplex.

    Currently, I have tried splitting the expression into two, and using the AddEq function for both.

    My code thus far is as follows:

     INumExpr constraint21 = model.NumExpr();
                INumExpr constraint22 = model.NumExpr();
                for (int k = 0; k < numberOfTrucks; k++)
                {
                    for (int j = 0; j < numberOfNodes; j++)
                    {
                        constraint21 = model.Sum(constraint21, route[0, j, k]);
                        constraint22 = model.Sum(constraint22, route[j, 0, k]);
                    }
                }
                model.AddEq(numberOfTrucks, constraint21);
                model.AddEq(numberOfTrucks, constraint22);

     

    I need constraint21 = constraint22 = numberOfTrucks to be fulfilled.

     

    This way of expressing the constraint seems problematic. Is there maybe another function that can handle the equation a=b=c directly without splitting?

    Thank you


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: expressing a = b = c

    Posted 11/16/16 01:40 AM

    No, there is no way to add a constraint that forces 3 expressions to be equal. This has to be modeled by 2 equations.

    What are the problems you are observing with this formulation?

    Note that you can use an ILinearNumExpr to write code that is more efficient:

    ILinearNumExpr constraint21 = model.LinearNumExpr();
    ...
        constraint21.AddTerm(1.0, route[0, k, k]);

     


    #CPLEXOptimizers
    #DecisionOptimization