1package com.gams.examples.transport;
19 public static void main(String[] args) {
20 initializeWorkspace(args);
21 double[] bmultlist =
new double[] { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
22 Optimizer[] optim =
new Optimizer[bmultlist.length];
23 for (
int i=0; i<bmultlist.length; i++) {
24 optim[i] =
new Optimizer(bmultlist[i]);
29 static void initializeWorkspace(String[] args) {
31 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Transport14");
32 workingDirectory.mkdir();
43 class Optimizer
extends Thread {
51 public Optimizer(
double mult) {
52 if (workspace ==
null)
53 throw new GAMSException(
"no workspace information, initialize workspace before creating an Optimizer");
60 GAMSParameter f = gDb.
addParameter(
"f",
"freight in dollars per case per thousand miles");
66 gOption.
defines(
"gdxincname", gDb.getName());
67 gModJob.run(gOption, gDb);
69 double obj = gModJob.OutDB().getVariable(
"z").getFirstRecord().getLevel();
70 System.out.println(
"Scenario bmult=" + bmult +
", Obj=" + obj);
75 gModJob.OutDB().dispose();
80 " i canning plants / seattle, san-diego / \n"+
81 " j markets / new-york, chicago, topeka / ; \n"+
85 " a(i) capacity of plant i in cases \n"+
87 " san-diego 600 / \n"+
89 " b(j) demand at market j in cases \n"+
94 "Table d(i,j) distance in thousands of miles \n"+
95 " new-york chicago topeka \n"+
96 " seattle 2.5 1.7 1.8 \n"+
97 " san-diego 2.5 1.8 1.4 ; \n"+
99 "Scalar f freight in dollars per case per thousand miles; \n"+
101 "$if not set gdxincname $abort 'no include file name for data file provided' \n"+
102 "$gdxin %gdxincname% \n"+
106 "Parameter c(i,j) transport cost in thousands of dollars per case ; \n"+
108 " c(i,j) = f * d(i,j) / 1000 ; \n"+
111 " x(i,j) shipment quantities in cases \n"+
112 " z total transportation costs in thousands of dollars ; \n"+
114 "Positive Variable x ; \n"+
117 " cost define objective function \n"+
118 " supply(i) observe supply limit at plant i \n"+
119 " demand(j) satisfy demand at market j ; \n"+
121 "cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"+
123 "supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"+
125 "demand(j) .. sum(i, x(i,j)) =g= b(j) ; \n"+
127 "Model transport /all/ ; \n"+
129 "Solve transport using lp minimizing z ; \n"+
131 "Display x.l, x.m ; \n"+
void defines(String defStr, String asStr)
void setSystemDirectory(String directory)
This example shows how to run multiple GAMSJobs in parallel each using different scenario.
GAMSParameter addParameter(String identifier, int dimension)
GAMSDatabase addDatabase()
GAMSJob addJobFromString(String source)
void setWorkingDirectory(String directory)
T addRecord(Vector< String > keys)