27 public static void main(String[] args) {
33 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Transport4");
34 workingDirectory.mkdir();
40 List<String> plants = Arrays.asList(
"Seattle",
"San-Diego");
41 List<String> markets = Arrays.asList(
"New-York",
"Chicago",
"Topeka");
42 Map<String, Double> capacity =
new HashMap<String, Double>();
44 capacity.put(
"Seattle", Double.valueOf(350.0));
45 capacity.put(
"San-Diego", Double.valueOf(600.0));
47 Map<String, Double> demand =
new HashMap<String, Double>();
49 demand.put(
"New-York", Double.valueOf(325.0));
50 demand.put(
"Chicago", Double.valueOf(300.0));
51 demand.put(
"Topeka", Double.valueOf(275.0));
54 Map<Vector<String>, Double> distance =
new HashMap<Vector<String>, Double>();
56 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"New-York"}) ), Double.valueOf(2.5));
57 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"Chicago"}) ), Double.valueOf(1.7));
58 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"Seattle",
"Topeka"}) ), Double.valueOf(1.8));
59 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"New-York"}) ), Double.valueOf(2.5));
60 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"Chicago"}) ), Double.valueOf(1.8));
61 distance.put(
new Vector<String>( Arrays.asList(
new String[]{
"San-Diego",
"Topeka"}) ), Double.valueOf(1.4));
68 for(String p : plants)
72 for(String m : markets)
76 for (String p : plants) {
77 a.addRecord(p).setValue( capacity.get(p) );
81 for(String m : markets)
82 b.addRecord(m).setValue( demand.get(m) );
85 for(Vector<String> vd : distance.keySet())
86 d.addRecord(vd).setValue( distance.get(vd).doubleValue() );
89 f.addRecord().setValue( 90 );
100 System.out.println(
"x(" + rec.getKey(0) +
", " + rec.getKey(1) +
"): level=" + rec.getLevel() +
" marginal=" + rec.getMarginal());
101 System.out.println();
104 opt.setAllModelTypes(
"xpress");
108 System.out.println(
"x(" + rec.getKey(0) +
"," + rec.getKey(1) +
"): level=" + rec.getLevel() +
" marginal=" + rec.getMarginal());
112 static String model =
114 " i canning plants \n" +
118 " a(i) capacity of plant i in cases \n" +
119 " b(j) demand at market j in cases \n" +
120 " d(i,j) distance in thousands of miles \n" +
121 " Scalar f freight in dollars per case per thousand miles; \n" +
123 "$if not set gdxincname $abort 'no include file name for data file provided'\n" +
124 "$gdxin %gdxincname% \n" +
125 "$load i j a b d f \n" +
128 " Parameter c(i,j) transport cost in thousands of dollars per case ; \n" +
130 " c(i,j) = f * d(i,j) / 1000 ; \n" +
133 " x(i,j) shipment quantities in cases \n" +
134 " z total transportation costs in thousands of dollars ; \n" +
136 " Positive Variable x ; \n" +
140 " cost define objective function \n" +
141 " supply(i) observe supply limit at plant i \n" +
142 " demand(j) satisfy demand at market j ; \n" +
144 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n" +
146 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n" +
148 " demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n" +
150 " Model transport /all/ ; \n" +
152 " Solve transport using lp minimizing z ; \n" +
154 " Display x.l, x.m ; \n" +