1package com.gams.examples.transport;
4import java.util.Arrays;
5import java.util.HashMap;
8import java.util.Vector;
26 public static void main(String[] args) {
29 if (args.length > 0) {
33 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Transport11");
34 workingDirectory.mkdir();
41 CreateSaveRestart( ws,
"tbase" );
44 List<String> plants = Arrays.asList(
"Seattle",
"San-Diego");
45 List<String> markets = Arrays.asList(
"New-York",
"Chicago",
"Topeka");
47 Map<String, Double> capacity =
new HashMap<String, Double>();
49 capacity.put(
"Seattle", Double.valueOf(350.0));
50 capacity.put(
"San-Diego", Double.valueOf(600.0));
53 Map<String, Double> demand =
new HashMap<String, Double>();
55 demand.put(
"New-York", Double.valueOf(325.0));
56 demand.put(
"Chicago", Double.valueOf(300.0));
57 demand.put(
"Topeka", Double.valueOf(275.0));
60 Map<Vector<String>, Double> distance =
new HashMap<Vector<String>, Double>();
62 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"New-York"}) ), Double.valueOf(2.5));
63 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"Chicago"}) ), Double.valueOf(1.7));
64 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"Topeka"}) ), Double.valueOf(1.8));
65 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"New-York"}) ), Double.valueOf(2.5));
66 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"Chicago"}) ), Double.valueOf(1.8));
67 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"Topeka"}) ), Double.valueOf(1.4));
76 for (String p : plants)
80 for (String m : markets)
84 for (String p : plants)
88 for (String m : markets)
92 for(Vector<String> vd : distance.keySet())
108 System.out.println(
"x(" + rec.getKey(0) +
"," + rec.getKey(1) +
"): level=" + rec.getLevel() +
" marginal=" + rec.getMarginal());
111 static void CreateSaveRestart(
GAMSWorkspace ws, String cpFileName) {
127 static String baseModel =
130 " i(*) canning plants / / \n"+
131 " j(*) markets / / \n"+
134 " a(i) capacity of plant i in cases / / \n"+
135 " b(j) demand at market j in cases / / \n"+
136 " d(i,j) distance in thousands of miles / / \n"+
137 " Scalar f freight in dollars per case per thousand miles /0/; \n"+
139 " Parameter c(i,j) transport cost in thousands of dollars per case ;\n"+
141 " c(i,j) = f * d(i,j) / 1000 ; \n"+
144 " x(i,j) shipment quantities in cases \n"+
145 " z total transportation costs in thousands of dollars ; \n"+
147 " Positive Variable x ; \n"+
150 " cost define objective function \n"+
151 " supply(i) observe supply limit at plant i \n"+
152 " demand(j) satisfy demand at market j ; \n"+
154 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"+
156 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"+
158 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"+
160 " Model transport /all/ ; \n"+
162 " Solve transport using lp minimizing z ; \n"+
165 static String model =
166 "$if not set gdxincname $abort 'no include file name for data file provided' \n"+
167 "$gdxin %gdxincname% \n"+
169 "$load i j a b d f \n"+
172 "Display x.l, x.m ; \n"+
GAMSSet addSet(String identifier, int dimension)
GAMSParameter addParameter(String identifier, int dimension)
GAMSVariable getVariable(String identifier)
void defines(String defStr, String asStr)
void setAllModelTypes(String value)
void setAction(GAMSOptions.EAction x)
void setValue(double value)
T addRecord(Vector< String > keys)
void setSystemDirectory(String directory)
void setWorkingDirectory(String directory)
GAMSJob addJobFromString(String source)
GAMSCheckpoint addCheckpoint()
GAMSDatabase addDatabase()
This example shows how to create and use save/restart file.
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS).