Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Change position of tuple elements

    Posted 06/18/20 01:43 AM
    Hello,

    Please help me with the following issue.

    I have the following tuples:

    int NumNodes = 5; // Number of nodes
    range Nodes = 1..NumNodes;

    int Tmax = 5; // Number of periods 
    range T = 1..Tmax;

    tuple TimeNode { //Defining a node replicated in time
    key int node;
    key int time;
    }
    {TimeNode} tnodes = { <n,t> | n in Nodes, t in T };

    tuple Arcs{ /
    key TimeNode FromNode; //node i
    key TimeNode ToNode;      // node j
    }

    {Arcs} arcs ={<<1,1>,<5,2>>,<<1,2>,<5,3>>,<<1,3>,<5,4>>,<<1,4>,<5,5>>.......};

    My question is, how do I change tuple elements' position in a tuple, so that in output it gives:
     <<5,2>,<1,1>>,<<5,3>,<1,2>>,<<5,4>,<1,3>>,<<5,5>,<1,4>> basically, so that the tuples within the tuple {Arcs} change their posiiton. 

    Thank you in advance for any support.
    BR, Irina

    ------------------------------
    Irina Tremaskina
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Change position of tuple elements

    Posted 06/18/20 03:17 AM
    I am not sure why you cannot just swap the lines in the tuple definition:
    tuple Arcs{
      key TimeNode ToNode; // node j
      key TimeNode FromNode; //node i
    }
    ?
    If the lines cannot be swapped, then there are several options:
    If you have control of the output then instead of outputting an arc 'a' you can output '<arg.ToNode, arg.FromNode>'.
    Another option is to create an "inverse tuple":
    tuple InverseArc {
      key TimeNode ToNode;
      key TimeNode FromNode;
    };
    and then create a corresponding set of inverse arcs:
    {InverseArc} inverse_arc_set = { <t.ToNode, t.FromNode | t in arcs };
    InverseArc inverse_arc_array[t in arcs] = < t.ToNode, t.FromNode >;

    ------------------------------
    Daniel Junglas
    ------------------------------