h1loan.mos |
(!******************************************************
Mosel Example Problems
======================
file h1loan.mos
```````````````
Choice of loans
A chain of shops aims to open three new shops located in
different cities. An associated opening cost with each
shop is given. To finance this project, the company can
get loans from three different banks which offer a maximum
loan amount and different rates for the different shop
projects. To minimize the company's total cost, how much
money should be borrowed from each bank to finance
each shop?
This LP model minimizes the sum of annual interest payments
that the company must make. A set of constraints ensures that
the borrowed amount for each shop is equal to its opening
cost. Another set of constraints guarantees, for each bank,
that the company borrows at most the maximum loan amount
offered by the bank.
(c) 2008-2022 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002, rev. Mar. 2022
*******************************************************!)
model "H-1 Loan choice"
uses "mmxprs"
declarations
BANKS = 1..3 ! Set of banks
SHOPS = {"London", "Munich", "Rome"} ! Set of shops
DUR: integer ! Duration of loans
PRICE: array(SHOPS) of integer ! Price of shops
RATE: array(BANKS,SHOPS) of real ! Interest rates offered by banks
VMAX: integer ! Maximum loan volume per bank
borrow: array(BANKS,SHOPS) of mpvar ! Loan taken from banks per project
end-declarations
initializations from 'h1loan.dat'
PRICE RATE VMAX DUR
end-initializations
! Objective: interest payments
Interest:=
sum(b in BANKS, s in SHOPS) borrow(b,s)*RATE(b,s)/(1-(1+RATE(b,s))^(-DUR))
! Finance all projects
forall(s in SHOPS) sum(b in BANKS) borrow(b,s) = PRICE(s)
! Keep within maximum loan volume per bank
forall(b in BANKS) sum(s in SHOPS) borrow(b,s) <= VMAX
! Solve the problem
minimize(Interest)
! Solution printing
writeln("Total interest: ", getobjval)
forall(s in SHOPS) do
write("Shop in ", s, ": ")
forall(b in BANKS | getsol(borrow(b,s))>0)
write(" bank ", b, ": ", getsol(borrow(b,s))/1000000, " million")
writeln
end-do
end-model
|
|
h2publ.mos |
(!******************************************************
Mosel Example Problems
======================
file h2publ.mos
```````````````
Planning a publicity campaign for a new product
A company launches a new product and reaches out to a
publicity agency to develop a publicity campaign. A
maximum budget is defined for this campaign. For each
media type (e.g., radio, tv, newspaper, etc.), there are
the people potentially reached, the cost, the maximum use,
and the index of perception quality. The campaign must
reach at least a given number of people. Which media should
be chosen and in which proportions (i.e., number of uses)
to maximize the total sum of indexes of perception quality?
This problem is represented with a simple IP model.
The model is implemented in a generic way (using
data arrays read from file) to make modifying the input
data easier for future extensions and data instances.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002
*******************************************************!)
model "H-2 Publicity"
uses "mmxprs"
declarations
MEDIA = 1..6 ! Set of media types
REACH: array(MEDIA) of integer ! Number of people reached
COST: array(MEDIA) of integer ! Unitary cost
MAXUSE: array(MEDIA) of integer ! Maximum use
SCORE: array(MEDIA) of integer ! Quality rating (best=highest value)
BUDGET: integer ! Available publicity budget
TARGET: integer ! Number of people to be reached
use: array(MEDIA) of mpvar ! Use made of different media
end-declarations
initializations from 'h2publ.dat'
REACH COST MAXUSE SCORE BUDGET TARGET
end-initializations
! Objective: quality of perception of the campaign
Perceive:= sum(m in MEDIA) SCORE(m)*use(m)
! Budgetary limit
sum(m in MEDIA) COST(m)*use(m) <= BUDGET
! Outreach of campaign
sum(m in MEDIA) REACH(m)*use(m) >= TARGET
forall(m in MEDIA) do
use(m) is_integer
use(m) <= MAXUSE(m)
end-do
! Solve the problem
maximize(Perceive)
! Solution printing
declarations
NAMES: array(MEDIA) of string
end-declarations
initializations from 'h2publ.dat'
NAMES
end-initializations
writeln("Perception: ", getobjval, " units (",
getsol(sum(m in MEDIA) REACH(m)*use(m)), " people)")
forall(m in MEDIA) writeln(NAMES(m), ": ", getsol(use(m)))
end-model
|
|
h3portf.mos |
(!******************************************************
Mosel Example Problems
======================
file h3portf.mos
````````````````
Composition of an investment portfolio
A financial consultant aims to determine in which shares
to invest given an investment budget and the estimated
return on investment. There are minimum and maximum
investments for different subsets of shares. How much
money should be invested in each share to obtain the
highest expected ROI?
The model and its implementation present the use of subsets.
A new condition is introduced, instead of investing between
a minimum (VMIN) and maximum (VMAX) amount into *every*
share, the invested amount for each share must be within
[VMIN,VMAX] or take the value 0. In this case, the decision
variable is known as semi-continuous variable so, the
implementation presents the possible use of 'is_semcont'.
Limit values are defined as runtime parameters fr which new
values can be stated when executing the model without having
to edit the model source.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002
*******************************************************!)
model "H-3 Portfolio"
uses "mmxprs"
parameters
MAXTECH = 0.3 ! Maximum investment into tech. values
MINEU = 0.5 ! Minimum investment into European shares
VMIN = 5000 ! Minimum amount for a single value
VMAX = 40000 ! Maximum amount for a single value
end-parameters
declarations
SHARES = 1..6 ! Set of shares
RET: array(SHARES) of real ! Estimated return in investment
CAPITAL: integer ! Capital to invest
EU: set of integer ! European values among the shares
TECHNOLOGY: set of integer ! Technology values among shares
buy: array(SHARES) of mpvar ! Amount of values taken into portfolio
end-declarations
initializations from 'h3portf.dat'
RET CAPITAL EU TECHNOLOGY
end-initializations
! Objective: total return
Return:= sum(s in SHARES) RET(s)/100*buy(s)
! Requirements concerning portfolio composition
sum(s in TECHNOLOGY) buy(s) <= MAXTECH*CAPITAL
sum(s in EU) buy(s) >= MINEU*CAPITAL
! Total capital to invest
sum(s in SHARES) buy(s) = CAPITAL
forall(s in SHARES) do
VMIN <= buy(s);
! buy(s) is_semcont(VMIN)
buy(s) <= VMAX
end-do
! Solve the problem
maximize(Return)
! Solution printing
writeln("Total return: ", getobjval)
forall(s in SHARES) writeln(s, ": ", getsol(buy(s)))
end-model
|
|
h4retire.mos |
(!******************************************************
Mosel Example Problems
======================
file h4retire.mos
`````````````````
Financing an early retirement scheme
To finance a pre-retirement scheme, a bank can invest
in three different types of bonds during a given period
of years. Bonds can be acquired only at the beginning of
the first year. Some technical conditions are defined on
the money not invested, the quantity of bonds to be bought
and the available money to be distributed. How many bonds
of each type should the bank acquire to minimize the money
spent to cover the retirement scheme?
A MIP model is implemented to determine the best way to
finance the retirement plan. To model the constraints
based on the maturity (duration) of the bond, conditionals
over sums and the inline 'if' are used to generalize
the set of constraints.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002
*******************************************************!)
model "H-4 Retirement"
uses "mmxprs"
declarations
BONDS = {"SNCF","Fujitsu","Treasury"} ! Set of bonds
NT = 7 ! Length of planning period
YEARS = 1..NT
DEM: array(YEARS) of integer ! Annual payments for retirement
VALUE: array(BONDS) of real ! Unit price of bonds
RATE: array(BONDS) of real ! Remuneration rates paid by bonds
RET: array(BONDS) of real ! Unit annual interest of bonds
DUR: array(BONDS) of real ! Duration of loans
INTEREST: real ! Interest for other secure investment
buy: array(BONDS) of mpvar ! Number of bonds acquired
invest: array(YEARS) of mpvar ! Other annual investment
capital: mpvar ! Total capital required
end-declarations
initializations from 'h4retire.dat'
DEM VALUE RATE DUR INTEREST
end-initializations
forall(b in BONDS) RET(b):= VALUE(b)*RATE(b)/100
! Annual balances
capital - sum(b in BONDS) VALUE(b)*buy(b) - invest(1) = DEM(1)
forall(t in 2..NT)
sum(b in BONDS | DUR(b)+1>=t) (RET(b)*buy(b) +
if(DUR(b)+1=t, VALUE(b)*buy(b), 0)) +
(1+INTEREST/100)*invest(t-1) - if(t<NT, invest(t), 0) = DEM(t)
forall(b in BONDS) buy(b) is_integer
! Solve the problem: minimize invested capital
minimize(capital)
! Solution printing
writeln("Total capital: ", getobjval)
writeln("Number of bonds to buy:")
forall(b in BONDS) write(b, ": ", getsol(buy(b)),
" (price: ", VALUE(b)*getsol(buy(b)), ") ")
writeln("\nOther investment:")
forall(t in 1..NT-1) write(" year ", t)
writeln
forall(t in 1..NT-1) write(strfmt(getsol(invest(t)),9,3))
writeln
end-model
|
|
h5budget.mos |
(!******************************************************
Mosel Example Problems
======================
file h5budget.mos
`````````````````
Planning the family budget
A mother wants to plan her family's annual budget. A
list of monthly expenses is provided as well as the
family salary and allowances. Each month, the mother
pays at least a given amount for leisure, but she would
like to spend more in such activities. How should she
balance the budget through the year to maximize the money
available for leisure?
This is a LP model similar to a production planning
model where money can be transferred from one time
period to the next one. To deal with the different
periodicities of the expenses, the Mosel operator 'mod'
is introduced. For the savings at the beginning of the
first period, the conditional 'if' is used in the constraint
formulation.
(c) 2008-2022 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002, rev. Mar. 2022
*******************************************************!)
model "H-5 Family budget"
uses "mmxprs"
declarations
MONTHS = 1..12 ! Time period
ITEMS: set of string ! Set of shops
INCOME, ALLOW: integer ! Monthly income and allowance
HMIN: integer ! Min. amount required for hobbies
EXPENSE: array(ITEMS) of integer ! Expenses
FREQ: array(ITEMS) of integer ! Frequency (periodicity) of expenses
hobby: array(MONTHS) of mpvar ! Money to spend for leisure/hobbies
saving: array(MONTHS) of mpvar ! Savings
end-declarations
initializations from 'h5budget.dat'
INCOME ALLOW HMIN
[EXPENSE, FREQ] as 'PAYMENT'
end-initializations
! Objective: money for hobby
Leisure:= sum(m in MONTHS) hobby(m)
! Monthly balances
forall(m in MONTHS)
sum(i in ITEMS | m mod FREQ(i) = 0) EXPENSE(i) + hobby(m) +
saving(m) <= INCOME + ALLOW + if(m>1, saving(m-1), 0)
forall(m in MONTHS) hobby(m) >= HMIN
! Solve the problem
maximize(Leisure)
! Solution printing
writeln("Money for hobby: ", getobjval)
write("Month ")
forall(m in MONTHS) write(" ", strfmt(m,4))
setparam("realfmt", "%4g") ! Reserve 4 char.s for display of real numbers
write("\nHobby: ")
forall(m in MONTHS) write(" ", getsol(hobby(m)))
write("\nSavings:")
forall(m in MONTHS) write(" ", getsol(saving(m)))
writeln
end-model
|
|
h6expand.mos |
(!******************************************************
Mosel Example Problems
======================
file h6expand.mos
`````````````````
Planning the expansion of a company
A company aims to expand and has a series of candidate
projects for a planning horizon of five years. Every
project has an annual cost and expected benefit after
five years. The forecast annual costs of the projects
for the next five years as well as the available yearly
funds are known. Which project(s) should the company
choose now to maximize the total benefit after five years?
A simple IP model with binary decision variables is
implemented. For each period, we ensure that the
annual cost of the project is at most the available
funds for the specific year. The problem solving is
started repeatedly, initially solving only the root
LP relaxation.
(c) 2008-2022 Fair Isaac Corporation
author: S. Heipcke, Mar. 2002, rev. Mar. 2022
*******************************************************!)
model "H-6 Expansion"
uses "mmxprs"
forward procedure printsol
declarations
PROJECTS = 1..5 ! Set of possible projects
TIME = 1..5 ! Planning period
COST: array(PROJECTS,TIME) of real ! Annual costs of projects
CAP: array(TIME) of real ! Annually available capital
RET: array(PROJECTS) of real ! Estimated profits
DESCR: array(PROJECTS) of string ! Description of projects
choose: array(PROJECTS) of mpvar ! 1 if project is chosen, 0 otherwise
end-declarations
initializations from 'h6expand.dat'
COST CAP RET DESCR
end-initializations
! Objective: Total profit
Profit:= sum(p in PROJECTS) RET(p)*choose(p)
! Limit on capital availability
forall(t in TIME) sum(p in PROJECTS) COST(p,t)*choose(p) <= CAP(t)
forall(p in PROJECTS) choose(p) is_binary
! Solve the problem
maximize(XPRS_LIN, Profit)
write("LP solution: ")
printsol
maximize(Profit)
write("MIP solution: ")
printsol
! Force acceptance of project 1 (='rounding' of an almost integer LP solution value)
choose(1)=1
maximize(Profit)
write("Forcing project 1 (", DESCR(1), "): ")
printsol
!-----------------------------------------------------------------
! Solution printing
procedure printsol
writeln("Total profit: ", getobjval)
forall(p in PROJECTS | getsol(choose(p))>0)
writeln(" ", DESCR(p), " (", getsol(choose(p)), ")")
end-procedure
end-model
|
|
h7qportf.mos |
(!******************************************************
Mosel Example Problems
======================
file h7qportf.mos
`````````````````
Mean-variance portfolio selection
An investor considers 4 different securities to invest
capital. The mean yield on each invested dollar in each
of the securities is known. The investor gets estimates
of the variance/covariance matrix of estimated returns
on the securities. What fraction of the total capital
should be invested in each security?
Two problem variants are proposed. Problem 1: Which
investment strategy should the investor adopt to minimize
the variance subject to getting some specified minimum
target yield? Problem 2: Which is the least variance
investment strategy if the investor wants to choose
at most two different securities (again subject to
getting some specified minimum target yield)?
For problem 1, a quadratic program (quadratic objective
function subject to linear constraints and continuous
variables) is presented. For problem 2, the model is
extended by introducing binary decision variables leading
to a Mixed Integer Quadratic Program. The module 'mmnl'
is used in both cases to handle such a quadratic (non-
linear) feature.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Aug. 2002, rev. Sep. 2017
*******************************************************!)
model "H-7 QP Portfolio"
uses "mmxprs", "mmnl"
parameters
TARGET = 7.0 ! Minimum target yield
MAXASSETS = 4 ! Maximum number of assets in portfolio
end-parameters
declarations
SECS = 1..4 ! Set of securities
RET: array(SECS) of real ! Expected yield of securities
VAR: array(SECS,SECS) of real ! Variance/covariance matrix of
! estimated returns
frac: array(SECS) of mpvar ! Fraction of capital used per security
end-declarations
initializations from 'h7qportf.dat'
RET VAR
end-initializations
! **** First problem: unlimited number of assets ****
! Objective: mean variance
Variance:= sum(s,t in SECS) VAR(s,t)*frac(s)*frac(t)
! Spend all the capital
sum(s in SECS) frac(s) = 1
! Target yield
sum(s in SECS) RET(s)*frac(s) >= TARGET
! Solve the problem
minimize(Variance)
! Solution printing
declarations
NAMES: array(SECS) of string
end-declarations
initializations from 'h7qportf.dat' ! Get the names of the assets
NAMES
end-initializations
writeln("With a target of ", TARGET, " minimum variance is ", getobjval)
forall(s in SECS) writeln(NAMES(s), ": ", getsol(frac(s))*100, "%")
! **** Second problem: limit total number of assets ****
declarations
buy: array(SECS) of mpvar ! 1 if asset is in portfolio, 0 otherwise
end-declarations
! Limit the total number of assets
sum(s in SECS) buy(s) <= MAXASSETS
forall(s in SECS) do
buy(s) is_binary
frac(s) <= buy(s)
end-do
! Solve the problem
minimize(Variance)
writeln("With a target of ", TARGET," and at most ", MAXASSETS,
" assets, minimum variance is ", getobjval)
forall(s in SECS) writeln(NAMES(s), ": ", getsol(frac(s))*100, "%")
end-model
|
|