Packages
|
|
Type: | Programming |
Rating: | 3 |
Description: | Packages are libraries written in the Mosel language that extend the language with
|
File(s): | myconstants.mos, myconst_test.mos, solarray.mos, solarr_test.mos, arc.mos, arc_test.mos |
Data file(s): | arcs.dat |
|
myconstants.mos |
(!****************************************** Mosel Examples ============== File myconstants.mos ```````````````````` Example package defining constants of different types. (c) 2008 Fair Isaac Corporation author: S. Heipcke, 2005 *******************************************!) package myconstants public declarations MYCST_BIGM = 10000 ! A large integer value MYCST_TOL = 0.00001 ! A tolerance value MYCST_LINE = ! String constant "----------------------------------------------------------------" MYCST_FLAG = true ! Constant with value true MYCST_NOFLAG = false ! Constant with value false end-declarations end-package |
myconst_test.mos |
(!****************************************************** Mosel NI Examples ================= File myconst_test.mos ````````````````````` Using module myconstants (c) 2008 Fair Isaac Corporation author: S. Heipcke, 2002 *******************************************************!) model "Test myconstants module" uses "myconstants" writeln(MYCST_LINE) writeln("BigM value: ", MYCST_BIGM, ", tolerance value: ", MYCST_TOL) writeln("Boolean flags: ", MYCST_FLAG, " ", MYCST_NOFLAG) writeln(MYCST_LINE) end-model |
solarray.mos |
(!****************************************** Mosel Examples ============== File solarray.mos ````````````````` Example package providing the procedure solarray(array of mpvar, array of real) for getting solutions into an array. (c) 2008 Fair Isaac Corporation author: S. Heipcke, May 2005 *******************************************!) package solarraypkg ! **** Integer indices (including ranges) **** public procedure solarray(x:array(R:set of integer) of mpvar, s:array(set of integer) of real) forall(i in R) s(i):=getsol(x(i)) end-procedure public procedure solarray(x:array(R1:set of integer, R2:set of integer) of mpvar, s:array(set of integer, set of integer) of real) forall(i in R1, j in R2) s(i,j):=getsol(x(i,j)) end-procedure public procedure solarray(x:array(R1:set of integer, R2:set of integer, R3:set of integer) of mpvar, s:array(set of integer, set of integer, set of integer) of real) forall(i in R1, j in R2, k in R3) s(i,j,k):=getsol(x(i,j,k)) end-procedure public procedure solarray(x:array(R1:set of integer, R2:set of integer, R3:set of integer, R4:set of integer) of mpvar, s:array(set of integer, set of integer, set of integer, set of integer) of real) forall(i in R1, j in R2, k in R3, l in R4) s(i,j,k,l):=getsol(x(i,j,k,l)) end-procedure ! ****String indices **** public procedure solarray(x:array(R:set of string) of mpvar, s:array(set of string) of real) forall(i in R) s(i):=getsol(x(i)) end-procedure public procedure solarray(x:array(R1:set of string, R2:set of string) of mpvar, s:array(set of string, set of string) of real) forall(i in R1, j in R2) s(i,j):=getsol(x(i,j)) end-procedure public procedure solarray(x:array(R1:set of string, R2:set of string, R3:set of string) of mpvar, s:array(set of string, set of string, set of string) of real) forall(i in R1, j in R2, k in R3) s(i,j,k):=getsol(x(i,j,k)) end-procedure public procedure solarray(x:array(R1:set of string, R2:set of string, R3:set of string, R4:set of string) of mpvar, s:array(set of string, set of string, set of string, set of string) of real) forall(i in R1, j in R2, k in R3, l in R4) s(i,j,k,l):=getsol(x(i,j,k,l)) end-procedure end-package |
solarr_test.mos |
(!****************************************************** Mosel NI Examples ================= File solarr_test.mos ```````````````````` Using module solarray (c) 2008 Fair Isaac Corporation author: S. Heipcke, 2002 *******************************************************!) model "Test solarray module" uses "solarray", "mmxprs" declarations R1=1..2 R2={6,7,9} R3={5,-1} x: array(R1,R2,R3) of mpvar sol: array(R1,R2,R3) of real end-declarations ! Define and solve a small problem sum(i in R1, j in R2, k in R3) (i+j+2*k) * x(i,j,k) <= 20 forall(i in R1, j in R2, k in R3) x(i,j,k)<=1 maximize(sum(i in R1, j in R2, k in R3) (i+2*j+k) * x(i,j,k)) ! Get the solution array solarray(x,sol) ! Print the solution forall(i in R1, j in R2, k in R3) writeln(" (", i, ",", j, ",", k, ") ", sol(i,j,k), " ", getsol(x(i,j,k))) writeln(sol) end-model |
arc.mos |
(!****************************************************** Mosel User Guide Example Problems ================================= file arc.mos ```````````` Definition of the package 'arc'. (c) 2008 Fair Isaac Corporation author: S. Heipcke, Jan. 2007 *******************************************************!) package arcPkg public declarations arc = public record ! Arcs: Source,Sink: string ! Source and sink of arc Cost: real ! Cost coefficient end-record end-declarations (! Alternatively: declarations public arc = record ! Arcs: public Source,Sink: string ! Source and sink of arc public Cost: real ! Cost coefficient end-record end-declarations !) public function is_neighbor(n1,n2: string, A: array(Arcs:set of integer) of arc): boolean returned:=or(a in Arcs ) (( A(a).Source=n1 and A(a).Sink=n2) or ( A(a).Source=n2 and A(a).Sink=n1)) end-function end-package |
arc_test.mos |
(!****************************************************** Mosel Example Problems ====================== file arc_test.mos ````````````````` Using the package 'arc'. (c) 2008 Fair Isaac Corporation author: S. Heipcke, Jan. 2007 *******************************************************!) model "Arcs" uses "arc" declarations NODES: set of string ! Set of nodes ARC: array(ARCSET:range) of arc ! Arcs end-declarations initializations from 'arcs.dat' ARC end-initializations ! Calculate the set of nodes NODES:=union(a in ARCSET) {ARC(a).Source, ARC(a).Sink} writeln(NODES) writeln("Average arc cost: ", sum(a in ARCSET) ARC(a).Cost / getsize(ARCSET) ) writeln("Neighbors A and F: ", is_neighbor("A","F",ARC)) writeln("Neighbors A and B: ", is_neighbor("A","B",ARC)) end-model |