Transport13.java
1package com.gams.examples.transport;
2 
3 import java.io.File;
4 import java.util.Arrays;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.Vector;
9 
11 import com.gams.api.GAMSWorkspace;
13 
19 public class Transport13 {
20 
21  public static void main(String[] args) {
22  List<String> plants = Arrays.asList("Seattle", "San-Diego");
23  List<String> markets = Arrays.asList("New-York", "Chicago", "Topeka");
24  Map<String, Double> capacity = new HashMap<String, Double>();
25  {
26  capacity.put("Seattle", Double.valueOf(350.0));
27  capacity.put("San-Diego", Double.valueOf(600.0));
28  }
29  Map<String, Double> demand = new HashMap<String, Double>();
30  {
31  demand.put("New-York", Double.valueOf(325.0));
32  demand.put("Chicago", Double.valueOf(300.0));
33  demand.put("Topeka", Double.valueOf(275.0));
34  }
35 
36  Map<Vector<String>, Double> distance = new HashMap<Vector<String>, Double>();
37  {
38  distance.put( new Vector<String>( Arrays.asList(new String[]{"Seattle", "New-York"}) ), Double.valueOf(2.5));
39  distance.put( new Vector<String>( Arrays.asList(new String[]{"Seattle", "Chicago"}) ), Double.valueOf(1.7));
40  distance.put( new Vector<String>( Arrays.asList(new String[]{"Seattle", "Topeka"}) ), Double.valueOf(1.8));
41  distance.put( new Vector<String>( Arrays.asList(new String[]{"San-Diego", "New-York"}) ), Double.valueOf(2.5));
42  distance.put( new Vector<String>( Arrays.asList(new String[]{"San-Diego", "Chicago"}) ), Double.valueOf(1.8));
43  distance.put( new Vector<String>( Arrays.asList(new String[]{"San-Diego", "Topeka"}) ), Double.valueOf(1.4));
44  }
45 
46  GAMSWorkspaceInfo wsInfo = new GAMSWorkspaceInfo();
47  if (args.length > 0)
48  wsInfo.setSystemDirectory( args[0] );
49 
50  File workingDirectory = new File(System.getProperty("user.dir"), "Transport13");
51  workingDirectory.mkdir();
52  wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath());
53 
54  GAMSWorkspace ws = new GAMSWorkspace(wsInfo);
55 
56  TransportModel t = new TransportModel(ws);
57 
58  for(String p : plants)
59  t.geti().addRecord(p);
60 
61  for(String m : markets)
62  t.getj().addRecord(m);
63 
64  for(String p : plants)
65  t.geta().addRecord(p).setValue( capacity.get(p) );
66 
67  for(String m : markets)
68  t.getb().addRecord(m).setValue( demand.get(m) );
69 
70  for(Vector<String> vd : distance.keySet()) {
71  String[] keys = new String[vd.size()];
72  vd.toArray(keys);
73  t.getd().addRecord( keys ).setValue( distance.get(vd).doubleValue() );
74  }
75 
76  t.getf().addRecord().setValue( 90 );
77 
78  t.getopt().setAllModelTypes( "cplex" );
79 
80  t.run(System.out);
81 
82  System.out.println("Objective: " + t.getz().getFirstRecord().getLevel());
83 
84  for(GAMSVariableRecord rec: t.getx())
85  System.out.println("x(" + rec.getKey(0) + "," + rec.getKey(1) + "): level=" + rec.getLevel() + " marginal=" + rec.getMarginal());
86 
87  }
88 }
GAMSParameter geta()
a(i): capacity of plant i in cases
void run(GAMSCheckpoint checkpoint)
Executes the trnsport model.
This example demonstrates how to run a job via the wrapper model of a GAMS [trnsport] from the transp...
GAMSParameter getb()
b(i): demand at market j in cases
GAMSParameter getf()
f: freight in dollars per case per thousand miles
void setSystemDirectory(String directory)
GAMSVariable getz()
z: total transportation costs in thousands of dollars
GAMSVariable getx()
x(i,j): shipment quantities in cases
void setWorkingDirectory(String directory)
This example shows the wrapper model of a transportation problem based on the simple GAMS [trnsport] ...
GAMSOptions getopt()
Options for the execution of the trnsport model.
T addRecord(Vector< String > keys)
void setAllModelTypes(String value)
GAMSParameter getd()
d(i,j): distance in thousands of miles