(!********************************************************************* Mosel Example Problems ====================== file npv.mos ```````````` Net present value (NPV) problem Example solution for exercise 6.8 in section 6.11 of J. Kallrath: Business Optimization Using Mathematical Programming - An Introduction with Case Studies and Solutions in Various Algebraic Modeling Languages. 2nd edition, Springer Nature, Cham, 2021 author: S. Heipcke, June 2018 (c) Copyright 2020 Fair Isaac Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *********************************************************************!) model 'npv' uses "mmxprs" declarations YEARS=1..4 PROJECTS=1..5 N: array(PROJECTS,YEARS) of real ! Cashflows P: array(PROJECTS,YEARS) of real ! Discounted returns x: array(PROJECTS,YEARS) of mpvar ! If a project is selected in a period end-declarations N::[-100,-50,150,150, -100,-40,50,200, 40,-100,50,50, -200,100,100,200, -150,0,150,100] P::[104.29,90.68,78.86,68.57, 52.51,45.66,39.71,34.53, 36.09,31.38,27.29,23.73, 143.08,124.41,108.19,94.07, 44.38,38.58,33.55,29.17] ! Objective: maximise total return NPV:=sum(i in PROJECTS,j in YEARS) P(i,j)*x(i,j) ! Cashflow limit applies annually forall(j in YEARS) Budget(j):= -sum(i in PROJECTS) N(i,j)*x(i,j) <= 250 + sum(i in PROJECTS,k in 1..j-1) N(i,k)*x(i,k) ! At least one project must be started annually forall(j in YEARS) Conv(j):=sum(i in PROJECTS) x(i,j)>=1 forall(i in PROJECTS,j in YEARS) x(i,j) is_binary ! Solve the problem maximise(NPV) writeln("Solution: NPV=", getobjval) forall(i in PROJECTS) do write(" Project ", i, " selected in") forall(j in YEARS | x(i,j).sol=1) write(" ", j) writeln end-do end-model