Loading...
Searching...
No Matches
Transport5.java
1package com.gams.examples.transport;
2
3import java.io.File;
4
7import com.gams.api.GAMSJob;
10
16public class Transport5 {
17
18 public static void main(String[] args) {
19 // check workspace info from command line arguments
21 if (args.length > 0)
22 wsInfo.setSystemDirectory( args[0] );
23 // create a directory
24 File workingDirectory = new File(System.getProperty("user.dir"), "Transport5");
25 workingDirectory.mkdir();
26 wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath());
27 // create a workspace
28 GAMSWorkspace ws = new GAMSWorkspace(wsInfo);
29 // create a checkpoint
31
32 // initialize a checkpoint by running a job
33 GAMSJob t5 = ws.addJobFromString(model);
34 t5.run(cp);
35
36 double[] bmultlist = new double[] { 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 };
37
38 // create a new GAMSJob that is initialized from the GAMSCheckpoint
39 for(double b : bmultlist)
40 {
41 t5 = ws.addJobFromString("bmult=" + b + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", cp);
42 t5.run();
43
44 System.out.println("Scenario bmult=" + b + ":");
45 System.out.println(" Modelstatus: " + GAMSGlobals.ModelStat.lookup( (int) t5.OutDB().getParameter("ms").findRecord().getValue() ));
46 System.out.println(" Solvestatus: " + GAMSGlobals.SolveStat.lookup( (int)t5.OutDB().getParameter("ss").findRecord().getValue() ));
47 System.out.println(" Obj: " + t5.OutDB().getVariable("z").findRecord().getLevel());
48 }
49
50 }
51
52 static String model =
53 " Sets \n"+
54 " i canning plants / seattle, san-diego / \n"+
55 " j markets / new-york, chicago, topeka / ; \n"+
56 " \n"+
57 "Parameters \n"+
58 "\n"+
59 " a(i) capacity of plant i in cases \n"+
60 " / seattle 350 \n"+
61 " san-diego 600 / \n"+
62 " \n"+
63 " b(j) demand at market j in cases \n"+
64 " / new-york 325 \n"+
65 " chicago 300 \n"+
66 " topeka 275 / ; \n"+
67 " \n"+
68 "Table d(i,j) distance in thousands of miles \n"+
69 " new-york chicago topeka \n"+
70 " seattle 2.5 1.7 1.8 \n"+
71 " san-diego 2.5 1.8 1.4 ; \n"+
72 " \n"+
73 "Scalar f freight in dollars per case per thousand miles /90/ ;\n"+
74 "Scalar bmult demand multiplier /1/; \n"+
75 " \n"+
76 "Parameter c(i,j) transport cost in thousands of dollars per case ; \n"+
77 " \n"+
78 " c(i,j) = f * d(i,j) / 1000 ; \n"+
79 " \n"+
80 "Variables \n"+
81 " x(i,j) shipment quantities in cases \n"+
82 " z total transportation costs in thousands of dollars ; \n"+
83 " \n"+
84 "Positive Variable x ; \n"+
85 " \n"+
86 "Equations \n"+
87 " cost define objective function \n"+
88 " supply(i) observe supply limit at plant i \n"+
89 " demand(j) satisfy demand at market j ; \n"+
90 " \n"+
91 "cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n"+
92 " \n"+
93 "supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n"+
94 " \n"+
95 "demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ; \n"+
96 " \n"+
97 "Model transport /all/ ; \n"+
98 "Scalar ms 'model status', ss 'solve status'; \n";
99
100}
GAMSParameter getParameter(String identifier)
GAMSVariable getVariable(String identifier)
GAMSDatabase OutDB()
T findRecord(String ... keys)
void setSystemDirectory(String directory)
void setWorkingDirectory(String directory)
GAMSJob addJobFromString(String source)
GAMSCheckpoint addCheckpoint()
This example shows how to initialize a GAMSJob from a GAMSCheckpoint.
Definition: Transport5.java:16
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS).