Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  C# : accessing variable value for a variable indexed by a tuple

    Posted 02/04/10 11:45 AM

    Originally posted by: NicoGDFSUEZ


    Hi everybody,
    I have in my .mod file :

    tuple T{int a; int b;};
    {T} SetOfT = ...;
    dvar float+ xSetOfT;

    Then I want to access in my c# file to the value of x.
    If x would be indexed by integer, I would have used for example model.GetElement( "x" ).AsNumMap().Get(0)

    But I do not find how to do this when x is indexed by a set of tuple.
    Can someone help me ?? (even in c++ or java)
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: C# : accessing variable value for a variable indexed by a tuple

    Posted 02/08/10 06:19 AM
    For example in the delivered example iterators.cs

    if you add

    rc.Cplex.Solve();
    INumVarMap trans = opl.GetElement("Trans").AsNumVarMap();

    // Iterate through the TupleSet.
    IEnumerator it3 = Routes.GetEnumerator();
    while (it3.MoveNext())
    {
    ITuple t = ((ITuple)it3.Current);
    string p = t.GetStringValue("p");
    string o = t.GetStringValue("o");
    string d = t.GetStringValue("d");
    Console.Out.WriteLine("for route = " + p + " "o" "d " : "+rc.Cplex.GetValue(trans.Get(t)));
    }

    then you will get all the values of the dvar Trans for all values from the tuple set Routes

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: C# : accessing variable value for a variable indexed by a tuple

    Posted 02/10/10 07:20 AM

    Originally posted by: NicoGDFSUEZ


    Thank you for your answer.
    It was not exactly what I looked for because I wanted the value of the variable for a particular tuple.
    I finally find the answer :

    var variable = model.GetElement( "x" ).AsNumMap();
    var tupleSet = model.GetElement( "SetOfT" ).AsTupleSet();
    var tuple = tupleSet.MakeTupleBuffer( 0 );
    tuple.SetIntValue(0, 3);
    tuple.SetIntValue(1, 3);
    var tupleReal = tupleSet.Find( tuple );
    var result = variable.Get( tupleReal );

    With this code, I obtain the value of "x" for the tuple {a = 3, b = 3}.
    However, I am not totally satisfied with the cplex/opl API : in my opinion, it would be very useful to be able to create a tuple from its schema obtained by model.GetElement( "T" ).AsTupleSchema() instead of using the tuple set "SetOfT"

    If anyone of Ilog/IBM could see my post... ;)
    #DecisionOptimization
    #OPLusingCPLEXOptimizer