0

How do I use param Distance as following in GLPK? like param Distance {line in Line, dir in Direction , ori in Station , des in Station};?

data;

set Direction := Eastbound Westbound;

set Line := District Piccadilly;

set Station := ACTON_TOWN ALDGATE_EAST ALPERTON ARNOS_GROVE...;

param Distance := #  Line Direction StationFrom StationTo Kilometers
District Eastbound ACTON_TOWN CHISWICK_PARK 1.22
District Eastbound ALDGATE_EAST WHITECHAPEL 0.82
District Eastbound BARKING UPNEY 1.38
District Eastbound BARONS_COURT WEST_KENSINGTON 0.64
District Eastbound BAYSWATER PADDINGTON 0.98
District Eastbound BECONTREE DAGENHAM_HEATHWAY 1.37
...
end;
Baisheng
  • 1
  • 1

1 Answers1

1

Before the "data" Part you can define the parameter like the following

param Distance {Line, Direction, Station, Station};

And then use it like

var x, >= 0;
minimize obj : sum{line in Line, dir in Direction , ori in Station , des in Station}(x*Distance[line,dir,ori,des]);

But you have one big Problem. With one Station set you will have connection like from and to Acton_Town, so you have to set them to Zero in the data part. Additional there is a problem with this combined distance representation with the direction Eastbound and Westbound - there will be an ACTON_TOWN to CHIPSWICK_PARK in both directions, so you have to handle the value for the unplausible connection in some way (like fixed indexing or high pricing). Same for Stations not on the Line.

You should probably think about a seperate representation of your Stations like

set Station_Piccadilly := ...;
set Station_District := ...;
...

If you want to make some routing you should probably look at the glpk example tsp.mod containing the Traveling Salesman Problem.

Paul G.
  • 632
  • 6
  • 16