Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How can I traverse a CpxLinkedExpr in C#?

    Posted 11/03/10 11:15 AM

    Originally posted by: KristianSchmidt


    Hi

    I'm trying to traverse a INumExpr that I have built using the Sum and Prod methods. The expression is linear, but since it is built sequentially, it looks like this:
    constant1 + a * x + b * x + constant + constant + e * (c * y) + d * y etc. where only x and y are variables.

    Normally I would just do (here the variable con is an IRange):
    ILinearNumExprEnumerator e = ((ILinearNumExpr)con.Expr).GetLinearEnumerator();
                while (e.MoveNext())
                {
                }
    

    But if I try it with this expression, it says that it cannot cast from CpxLinkedExpr to ILinearNumExpr. Do I need to traverse CpxLinkedExpr in a different way, or can I force cplex to calculate the expression to its shortest form, where it will be a regular linear expression?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How can I traverse a CpxLinkedExpr in C#?

    Posted 11/05/10 06:37 AM

    Originally posted by: KristianSchmidt


    No one? I was hoping this would be pretty simple :|
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How can I traverse a CpxLinkedExpr in C#?

    Posted 11/08/10 11:29 PM

    Originally posted by: SystemAdmin


    You should not have to mess around with CpxLinkedExpr as this is an internal class.
    Did you really pass an instance of ILinearNumExpr to con when you created it? Or was that an instance of INumExpr that you just happened to know to be linear?
    Functions Prod() and Sum() do not return instances of ILinearNumExpr but instances of INumExpr. If you want to get an ILinearNumExpr over which you can iterate you should create an empty expression via Cplex.LinearNumExpr() and add terms to this expression via the AddTerm() method.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How can I traverse a CpxLinkedExpr in C#?

    Posted 11/09/10 07:18 AM

    Originally posted by: KristianSchmidt


    Hi Daniel.

    Yes I think the problem lies in the fact that it's just an INumExpr that I know is linear. I can see that I should just be using AddTerm at all times instead of the prod and sum methods.

    In the end, I ended up finding a more elegant way of completing my task, instead of relying on manipulating I(Linear)NumExprs directly. Thanks for the help though.
    #CPLEXOptimizers
    #DecisionOptimization