summaryrefslogtreecommitdiff
path: root/tests/examplefiles
diff options
context:
space:
mode:
authorjcmuel <JohannesMueller@fico.com>2019-12-03 23:23:08 +0100
committerGeorg Brandl <georg@python.org>2019-12-08 10:58:21 +0100
commite07f99a24c1621033df3ca554962bd382c7ca2b1 (patch)
tree01d1ea58571b710cc2e63f02c1a6e3bd60bffeb6 /tests/examplefiles
parentb0e98663d4f84962ee48775b6a92181324f7a98c (diff)
downloadpygments-git-e07f99a24c1621033df3ca554962bd382c7ca2b1.tar.gz
Add keywords, define types and operators. Remove parameters. Delete test file with incompatible license.
Diffstat (limited to 'tests/examplefiles')
-rw-r--r--tests/examplefiles/test.mos38
-rw-r--r--tests/examplefiles/test2.mos162
2 files changed, 31 insertions, 169 deletions
diff --git a/tests/examplefiles/test.mos b/tests/examplefiles/test.mos
index e1b81d6b..ccf17f68 100644
--- a/tests/examplefiles/test.mos
+++ b/tests/examplefiles/test.mos
@@ -1,10 +1,34 @@
-(!******************************************************
- Mosel Example Problems
+(!*******************************************************
+ Multiline comment
*******************************************************!)
+model 'pygments test'
+ uses "mmxprs"
-! Objective function: total daily cost
- Cost:= sum(p in TYPES, t in TIME) (CSTART(p)*start(p,t) +
- LEN(t)*(CMIN(p)*work(p,t) + CADD(p)*padd(p,t)))
+ forward public procedure main ! Test forward declaration
+
+ public procedure main
+ declarations
+ MySet = {1, 2}
+ I: range
+ Coefficients: array(I) of real
+ Vars: array(I) of mpvar
+ end-declarations
+
+ Coefficients :: [2.2, -3.3, 4.4, 5.5, 1.1, -3.3, 7.7]
+
+ ! Single line comment
+ forall (i in I) Vars(i) is_binary
+
+ ! Constraint
+ sum (i in I) Vars(i) <= 3
+
+ maximize(sum(i in I) Coefficients(i) * Vars(i))
+
+ forall (i in I| Vars(i).sol <> 0) do
+ writeln("Vars(", i,") = ", Vars(i).sol)
+ end-do
+ end-procedure
+
+ main
+end-model
-! Limit on power production above minimum level
- forall(p in TYPES, t in TIME) padd(p,t) <= (PMAX(p)-PMIN(p))*work(p,t)
diff --git a/tests/examplefiles/test2.mos b/tests/examplefiles/test2.mos
deleted file mode 100644
index 99d4cb55..00000000
--- a/tests/examplefiles/test2.mos
+++ /dev/null
@@ -1,162 +0,0 @@
-(!******************************************************
- Mosel Example Problems
- ======================
-
- file runfolio.mos
- `````````````````
- Master model running portfolio optimization model.
-
- Runs model foliomemio.mos.
- -- Data input/output in memory --
-
- (c) 2009 Fair Isaac Corporation
- author: S.Heipcke, Jan. 2009
-*******************************************************!)
-
-model "Run portfolio optimization model"
- uses "mmjobs" ! Use multiple model handling
- uses "mmsystem", "mmxprs"
-
- parameters
- MODELFILE = "foliomemio.mos" ! Optimization model
- INPUTFILE = "folio10.dat" ! File with problem data
-
- MAXRISK = 1/3 ! Max. investment into high-risk values
- MINREG = 0.2 ! Min. investment per geogr. region
- MAXREG = 0.5 ! Max. investment per geogr. region
- MAXSEC = 0.25 ! Max. investment per ind. sector
- MAXVAL = 0.2 ! Max. investment per share
- MINVAL = 0.1 ! Min. investment per share
- MAXNUM = 15 ! Max. number of different assets
- end-parameters
-
- forward procedure write_html_results
-
- declarations
- SHARES: set of string ! Set of shares
- RISK: set of string ! Set of high-risk values among shares
- REGIONS: set of string ! Geographical regions
- TYPES: set of string ! Share types (ind. sectors)
- LOCTAB: dynamic array(REGIONS,SHARES) of boolean ! Shares per geogr. region
- RET: array(SHARES) of real ! Estimated return in investment
- SECTAB: dynamic array(TYPES,SHARES) of boolean ! Shares per industry sector
-
- returnsol: real ! Solution values
- numsharessol,status: integer
- fracsol: array(SHARES) of real ! Fraction of capital used per share
- buysol: array(SHARES) of real ! 1 if asset is in portfolio, 0 otherwise
-
- foliomod: Model
- end-declarations
-
-! Compile and load the optimization model
- if compile("", MODELFILE, "shmem:bim") <> 0 then
- writeln("Error during model compilation")
- exit(1)
- end-if
- load(foliomod, "shmem:bim")
- fdelete("shmem:bim")
-
-! Read in data from file
- initializations from INPUTFILE
- RISK RET LOCTAB SECTAB
- end-initializations
-
-! Save data to memory
- initializations to "raw:"
- RISK as 'shmem:RISK'
- RET as 'shmem:RET'
- LOCTAB as 'shmem:LOCTAB'
- SECTAB as 'shmem:SECTAB'
- end-initializations
-
- run(foliomod, "MAXRISK=" + MAXRISK + ",MINREG=" + MINREG +
- ",MAXREG=" + MAXREG + ",MAXSEC=" + MAXSEC +
- ",MAXVAL=" + MAXVAL + ",MINVAL=" + MINVAL +
- ",MAXNUM=" + MAXNUM + ",DATAFILE='raw:',OUTPUTFILE='raw:'," +
- "RISKDATA='shmem:RISK',RETDATA='shmem:RET',LOCDATA='shmem:LOCTAB'," +
- "SECDATA='shmem:SECTAB',FRACSOL='shmem:FRAC',BUYSOL='shmem:BUY'," +
- "NUMSHARES='shmem:NUMSHARES',RETSOL='shmem:RETSOL'," +
- "SOLSTATUS='shmem:SOLSTATUS'")
- wait ! Wait for model termination
- dropnextevent ! Ignore termination event message
-
- initializations from "raw:"
- returnsol as 'shmem:RETSOL'
- numsharessol as 'shmem:NUMSHARES'
- fracsol as 'shmem:FRAC'
- buysol as 'shmem:BUY'
- status as 'shmem:SOLSTATUS'
- end-initializations
-
- case status of
- XPRS_OPT: writeln("Problem solved to optimality")
- XPRS_UNF: writeln("Problem solving unfinished")
- XPRS_INF: writeln("Problem is infeasible")
- XPRS_UNB,XPRS_OTH: writeln("No solution available")
- end-case
-
- ! Solution printing
- writeln("Total return: ", returnsol)
- writeln("Number of shares: ", numsharessol)
- forall(s in SHARES | fracsol(s)>0)
- writeln(s, ": ", fracsol(s)*100, "% (", buysol(s), ")")
-
- write_html_results
-
-! *********** Writing an HTML result file ***********
- procedure write_html_results
- setparam("datetimefmt", "%0d-%N-%y, %0H:%0M:%0S")
-
- HTMLFILE:= INPUTFILE + "_sol.html"
- fopen(HTMLFILE, F_OUTPUT)
- writeln("<html>")
- writeln("<head>")
- writeln("<style type='text/css'>")
- writeln("body {font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; color: 000055 }")
- writeln("table td {background-color: ffffaa; text-align: left }")
- writeln("table th {background-color: 053055; color: ffcc88}")
- writeln("</style>")
- writeln("</head>")
-
- writeln("<body>")
- writeln("<center><h2>Portfolio Optimization Results</h2></center>")
- writeln("<table width='100%' cellpadding='5' cellspacing='0' border=0>")
- writeln("<tr><td width='55%'><font color='#000055'><b>Total return: ",
- returnsol, "</b></font></td><td><font color='#885533'><b>Problem instance: ",
- INPUTFILE,"</b></font></td></tr>")
- writeln("<tr><td><font color='#000055'><b>Number of shares: ", numsharessol, "</b></font></td><td><font color='#885533'><b>Date: ", datetime(SYS_NOW),"</b></font></td></tr>")
- writeln("<tr><td colspan='2'>&nbsp;</td></tr>")
- writeln("</table>")
-
- writeln("<table cellpadding='2' cellspacing='1' width='100%'>")
- writeln("<tr><th>Value</th><th>Percentage</th></tr>")
- forall(s in SHARES | fracsol(s)>0)
- writeln("<tr><td>", s, "</td><td>", strfmt(fracsol(s)*100,4,2),
- "%</td></tr>")
- writeln("</table>")
- writeln("</body>")
- writeln("</html>")
- fclose(F_OUTPUT)
- end-procedure
-
-! Test multiple strings escaping
-
- writeln("Reading 'KnapsackData.txt' ... ")
- writeln("Reading \"KnapsackData.txt\" ... ")
- writeln('Reading "KnapsackData.txt" ... ')
- writeln("A double-quote string with a escape\nbreakline")
- writeln('A single-quote string with a escape\nbreakline which should be ignored')
- writeln("The letter q has octal code 161 can written as \161. But \229 is not a valid octal number")
-! Multiline strings
- writeln("This is
- a multi-line
- string with three lines")
- writeln("Reading
- file 'KnapsackData.txt' ... ")
- writeln('Reading
- file "KnapsackData.txt" ... ')
- ! function highlighting test
- y := sin(x)
-
-end-model