ampl

Ordering the Display in AMPL


I'm doing a model for the scheduling problem, I already solved it, but I want to order the output, by crescent numbers. This is my output, where X[i] is the time of the beginning of the job i.

x [*] :=
NM2646FX-1024  109.5
 NM2646FX-107  138.3
NM2646FX-1115  120.3
 NM2646FX-176  213.3
 NM2646FX-220  180.3
  NM2646FX-81  220.8
 NM2646FX-999  285.9
RD1060FX-2144   68.1
RD1060FX-3854   34.5
 RD720FX-1515    0
  RD720FX-878  237.9
;

Solution

  • Unfortunatelly, the only type of model entity that can be easily sorted in AMPL is set. Sorting parameters is trickier. You can create an ordered set and assign the values of your x variables to it:

    set xOrderedSet ordered by Reals;
    let xOrderedSet := setof {i in S} x[i].val;
    display xOrderedSet;
    

    I believe this will only work if all x's are unique. Then you can create a param xOrdered to map the values with its respective set entry:

    param xOrdered{xOrderedSet} symbolic;
    
    for {i in xOrderedSet} {
        let {s in S : i = x[s].val} xOrdered[i] := s;
    }
    
    display xOrdered;
    

    More info on the let command here.