Search code examples
arraysoptimizationtuplesrangecplex

What does this array initialisation mean? CPLEX


I am very new to CPLEX and am trying to understand a friends example so i may produce a model myself, however I am confused as to how one of the decision variables has been created. The notation is unfamiliar to me and also the fact that they are using a set of tuples as well as ranges in it's definition. Any help explaining what is going on and what the line of code does would be greatly appreciated.

tuple bus{int busnumber; float capacity; string start_location; string stop_location; int maxleg;};

{bus} busfleet=...; 

int maxroute=...;

range route = 1..maxroute;
range route0 = 1..maxroute-1;

tuple job {string start_location; string stop_location; int runafter; int runbefore; int runstop; float demand;};

{job} jobs=...;
{job} initialjobs=...;
{job} jobs1=...;
{job} alljobs = initialjobs union jobs union jobs1;

//variable
dvar boolean scheduleofbus[busfleet, route, alljobs, alljobs];

My confusion concerns the final line, where "scheduleofbus" is defined. What does this initialization of the array do? If possible could you also help define it's dimensions, what selecting an element of it would do etc. Any help would be greatly appreciated. Many thanks in advance. =)


Solution

  • The line

    dvar boolean scheduleofbus[busfleet, route, alljobs, alljobs];
    

    could equivalently be written as

    dvar boolean scheduleofbus[busfleet][route][alljobs][alljobs];
    

    which may be a bit more obvious. It defines a 4-dimensional boolean decision variable. The index set for this variable is the cartesian product of the elements in busfleet, route, alljobs and alljobs (yes, alljobs appears twice).

    In other words, you have a variable for each combination of bus, route and pair of jobs.