SpecialValues.java
1package com.gams.examples.specialvalues;
2
3import java.io.File;
4
6import com.gams.api.GAMSJob;
10
16public class SpecialValues {
17
18 public static void main(String[] args) throws Exception {
20 if (args.length > 0)
21 wsInfo.setSystemDirectory( args[0] );
22 File workingDirectory = new File(System.getProperty("user.dir"), "sp");
23 workingDirectory.mkdir();
24 wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath());
25 GAMSWorkspace ws = new GAMSWorkspace( wsInfo );
26
27 GAMSDatabase dbIn = ws.addDatabase("myDB");
28 dbIn.addParameter("javaUndef", 0).addRecord().setValue( 1.0E300 );
29 dbIn.addParameter("javaNA", 0).addRecord().setValue( Double.NaN );
30 dbIn.addParameter("javaPInf", 0).addRecord().setValue( Double.POSITIVE_INFINITY );
31 dbIn.addParameter("javaMInf", 0).addRecord().setValue( Double.NEGATIVE_INFINITY );
32 dbIn.addParameter("javaEps", 0).addRecord().setValue( 4.94066E-324 );
33
34 GAMSJob gj = ws.addJobFromString( model );
35
36 GAMSOptions opt = ws.addOptions();
37 opt.defines("gdxincname", dbIn.getName());
38
39 gj.run(opt, dbIn);
40
41 GAMSDatabase dbOut = gj.OutDB();
42 double GUndef = dbOut.getParameter("GUndef").getFirstRecord().getValue();
43 if (GUndef != 1.0E300 )
44 throw new Exception("GUndef not as expected: " + GUndef);
45 double GNA = dbOut.getParameter("GNA").getFirstRecord().getValue();
46 if (!Double.isNaN(GNA))
47 throw new Exception("GNA not as expected: " + GNA);
48 double GPInf = dbOut.getParameter("GPInf").getFirstRecord().getValue();
49 if (GPInf != Double.POSITIVE_INFINITY)
50 throw new Exception("GPInf not as expected: " + GPInf);
51 double GMInf = dbOut.getParameter("GMInf").getFirstRecord().getValue();
52 if (GMInf != Double.NEGATIVE_INFINITY)
53 throw new Exception("GMInf not as expected: " + GMInf);
54 double GEps = dbOut.getParameter("GEps").getFirstRecord().getValue();
55 if (GEps != 4.94066E-324)
56 throw new Exception("GEps not as expected: " + GEps);
57
58 System.exit(0);
59 }
60
61 static String model =
62 "Scalar GUndef \n" +
63 " GNA / NA / \n" +
64 " GPInf / +Inf / \n" +
65 " GMInf / -Inf / \n" +
66 " GEps / eps / \n" +
67 " javaUndef \n" +
68 " javaNA \n" +
69 " javaPInf \n" +
70 " javaMInf \n" +
71 " javaEps ; \n" +
72 " \n" +
73 "$onUndf \n" +
74 "$gdxIn %gdxincname% \n" +
75 "$load javaUndef javaNA javaPInf javaMInf javaEps \n" +
76 "$gdxIn \n" +
77 " \n" +
78 "GUndef = 1/0; \n" +
79 "ExecError = 0; \n" +
80 " \n" +
81 "abort$(GUndef <> javaUndef) 'javaUndef not as expected', GUndef, javaUndef;\n" +
82 "abort$(GNA <> javaNA ) 'javaNA not as expected', GNA, javaNA; \n" +
83 "abort$(GPInf <> javaPInf ) 'javaPInf not as expected', GPInf, javaPInf; \n" +
84 "abort$(GMInf <> javaMInf ) 'javaMInf not as expected', GMInf, javaMInf; \n" +
85 "abort$(GEps <> javaEps ) 'javaEps not as expected', GEps, javaEps \n";
86}
87
This example shows how special values of the programming language (e.g.
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS)...
GAMSParameter addParameter(String identifier, int dimension)
&#160;
GAMSParameter getParameter(String identifier)
void defines(String defStr, String asStr)
void setSystemDirectory(String directory)
T addRecord(Vector< String > keys)
GAMSDatabase OutDB()
GAMSJob addJobFromString(String source)
void setWorkingDirectory(String directory)