Loading...
Searching...
No Matches
SpecialValues.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using GAMS;
6
7namespace SpecialValues
8{
15 {
16 static int Main(string[] args)
17 {
18 try
19 {
21 if (Environment.GetCommandLineArgs().Length > 1)
22 ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
23 else
24 ws = new GAMSWorkspace();
25
26 GAMSDatabase dbIn = ws.AddDatabase(inModelName: "myDB");
27 dbIn.AddParameter("dotNetUndef", 0).AddRecord().Value = gamsglobals.sv_valund;
28 dbIn.AddParameter("dotNetNA", 0).AddRecord().Value = double.NaN;
29 dbIn.AddParameter("dotNetPInf", 0).AddRecord().Value = double.PositiveInfinity;
30 dbIn.AddParameter("dotNetMInf", 0).AddRecord().Value = double.NegativeInfinity;
31 dbIn.AddParameter("dotNetEps", 0).AddRecord().Value = double.Epsilon;
32
33 GAMSJob gj = ws.AddJobFromString(GetModel());
34
35 gj.Run(dbIn);
36
37 GAMSDatabase dbOut = gj.OutDB;
38
39 double GUndef = dbOut.GetParameter("GUndef").FirstRecord().Value;
40 if (GUndef != gamsglobals.sv_valund)
41 throw new Exception("GUndef not as expected: " + GUndef);
42 double GNA = dbOut.GetParameter("GNA").FirstRecord().Value;
43 if (!double.IsNaN(GNA))
44 throw new Exception("GNA not as expected: " + GNA);
45 double GPInf = dbOut.GetParameter("GPInf").FirstRecord().Value;
46 if (!double.IsPositiveInfinity(GPInf))
47 throw new Exception("GPInf not as expected: " + GPInf);
48 double GMInf = dbOut.GetParameter("GMInf").FirstRecord().Value;
49 if (!double.IsNegativeInfinity(GMInf))
50 throw new Exception("GMInf not as expected: " + GMInf);
51 double GEps = dbOut.GetParameter("GEps").FirstRecord().Value;
52 if (GEps != double.Epsilon)
53 throw new Exception("GEps not as expected: " + GEps);
54 }
55 catch (Exception e)
56 {
57 Console.WriteLine("###");
58 Console.WriteLine("### Exception caught:" + e.Message);
59 Console.WriteLine("###");
60 return 1;
61 }
62 return 0;
63 }
64
65 static String GetModel()
66 {
67 String model = @"
68Scalar GUndef
69 GNA / NA /
70 GPInf / +Inf /
71 GMInf / -Inf /
72 GEps / eps /
73 dotNetUndef
74 dotNetNA
75 dotNetPInf
76 dotNetMInf
77 dotNetEps ;
78
79$onUndf
80$gdxIn %myDB%
81$load dotNetUndef dotNetNA dotNetPInf dotNetMInf dotNetEps
82$gdxIn
83
84GUndef = 1/0;
85ExecError = 0;
86
87abort$(GUndef <> dotNetUndef) 'dotNetUndef not as expected', GUndef, dotNetUndef;
88abort$(GNA <> dotNetNA ) 'dotNetNA not as expected', GNA, dotNetNA;
89abort$(GPInf <> dotNetPInf ) 'dotNetPInf not as expected', GPInf, dotNetPInf;
90abort$(GMInf <> dotNetMInf ) 'dotNetMInf not as expected', GMInf, dotNetMInf;
91abort$(GEps <> dotNetEps ) 'dotNetEps not as expected', GEps, dotNetEps;
92";
93 return model;
94 }
95 }
96}
GAMSParameter GetParameter(string parameterIdentifier)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
GAMSDatabase OutDB
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
new GAMSParameterRecord FirstRecord()
new GAMSParameterRecord AddRecord(params string[] keys)
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)