(!******************************************************
Mosel User Guide Example Problems
=================================
file initeval.mos
`````````````````
Initializations with evaluation.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Sep. 2007
*******************************************************!)
model "Evaluations"
uses "mmxprs"
declarations
small,large: mpvar ! Decision variables: produced quantities
end-declarations
Profit:= 5*small + 20*large ! Objective function
Lathe:= 3*small + 2*large <= 160 ! Lathe-hours
Boxwood:= small + 3*large <= 200 ! kg of boxwood
small is_integer; large is_integer ! Integrality constraints
maximize(Profit) ! Solve the problem
initializations to "chessout.txt" ! Solution output to a file
evaluation of getparam("XPRS_mipstatus") as "Status"
evaluation of getobjval as "Objective"
evaluation of small.sol as "small_sol"
evaluation of large.sol as "large_sol"
evaluation of Lathe.slack as "Spare time"
evaluation of Boxwood.act as "Used wood"
evaluation of Boxwood.act-200 as "Spare wood"
evaluation of [ small.sol, large.sol ] as "x_sol"
end-initializations
writeln("Solution: ", getobjval) ! Display solution values
writeln("Small: ", getsol(small), " large: ", getsol(large))
writeln("Time: ", getact(Lathe), " ", getslack(Lathe))
writeln("Wood: ", Boxwood.sol, " ", Boxwood.act, " ", Boxwood.slack)
end-model
|
(!******************************************************
Mosel User Guide Example Problems
=================================
file initeval2.mos
``````````````````
Initializations with evaluation.
- Using arrays -
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Sep. 2007, rev. Jan. 2010
*******************************************************!)
model "Evaluations 2"
uses "mmxprs"
declarations
R = 1..2 ! Index range
DUR, WOOD, PROFIT: array(R) of real ! Coefficients
x: array(R) of mpvar ! Array of variables
end-declarations
! Function returning solution values as an array
function solx:array(R) of real
forall(i in R) returned(i):=x(i).sol
end-function
DUR :: [3, 2] ! Initialize data arrays
WOOD :: [1, 3]
PROFIT:: [5, 20]
! Constraint definition
Lathe:= sum(i in R) DUR(i)*x(i) <= 160
Boxwood:= sum(i in R) WOOD(i)*x(i) <= 200
forall(i in R) x(i) is_integer
maximize(sum(i in R) PROFIT(i)*x(i))
initializations to "chessout.txt" ! Solution output to a file
evaluation of getobjval as "Objective"
evaluation of Lathe.slack as "Spare time"
evaluation of Boxwood.act as "Used wood"
evaluation of Boxwood.act-200 as "Spare wood"
evaluation of solx as "x_sol"
evaluation of array(i in R) x(i).sol as "x_sol_alt"
end-initializations
writeln("Solution: ", getobjval) ! Print objective function value
writeln("x: ", solx) ! Print solution values
writeln("Time: ", getact(Lathe), " ", getslack(Lathe))
writeln("Wood: ", Boxwood.sol, " ", Boxwood.act, " ", Boxwood.slack)
end-model
|
(!******************************************************
Mosel User Guide Example Problems
=================================
file initeval2s.mos
```````````````````
Initializations with evaluation.
- Using arrays, string indices -
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Sep. 2007, rev. Jan. 2010
*******************************************************!)
model "Evaluations 2s"
uses "mmxprs"
declarations
PRODS = {"small", "large"} ! Index set
DUR, WOOD, PROFIT: array(PRODS) of real ! Coefficients
x: array(PRODS) of mpvar ! Array of variables
end-declarations
! Function returning solution values as an array
function solx:array(PRODS) of real
forall(i in PRODS) returned(i):=x(i).sol
end-function
DUR :: (["small","large"])[3, 2] ! Initialize data arrays
WOOD :: (["small","large"])[1, 3]
PROFIT:: (["small","large"])[5, 20]
! Constraint definition
Lathe:= sum(i in PRODS) DUR(i)*x(i) <= 160
Boxwood:= sum(i in PRODS) WOOD(i)*x(i) <= 200
forall(i in PRODS) x(i) is_integer
maximize(sum(i in PRODS) PROFIT(i)*x(i))
initializations to "chessout.dat"
evaluation of getobjval as "Objective"
evaluation of Lathe.slack as "Spare time"
evaluation of Boxwood.act as "Used wood"
evaluation of Boxwood.act-200 as "Spare wood"
evaluation of solx as "x_sol"
evaluation of array(i in PRODS) x(i).sol as "x_sol_alt"
end-initializations
writeln("Solution: ", getobjval) ! Print objective function value
writeln("x: ", solx) ! Print solution values
writeln("Time: ", getact(Lathe), " ", getslack(Lathe))
writeln("Wood: ", Boxwood.sol, " ", Boxwood.act, " ", Boxwood.slack)
end-model
|