(!********************************************************************* Mosel Example Problems ====================== file trim2.mos `````````````` Trim loss problem Example solution for exercise 4.2 in section 4.7 / described in section 4.1.1 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 'trim2' uses "mmxprs" declarations S= 3 ! Number of sizes to be cut P= 10 ! Number of patterns RPATT=1..P ! Set of cutting patterns RSZ=1..S ! Set of sizes N: array(RSZ,RPATT) of real ! Sizes for patterns LOSS: array(RPATT) of real ! Trim loss of pattern p DEM: array(RSZ) of real ! Demand for size s end-declarations N::[5, 4, 4, 2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 3] LOSS::[10, 2, 0, 6, 4, 2, 10, 8, 6, 4] DEM::[8, 13, 10] declarations x: array(RPATT) of mpvar ! Number of rolls to cut to pattern p end-declarations ! Objective: total loss Trimloss:= sum(p in RPATT) LOSS(p)*x(p) ! Satisfy the demand forall(s in RSZ) Demand(s):= sum(p in RPATT) N(s,p)*x(p)>= DEM(s) forall(p in RPATT) do x(p) is_integer; x(p)<= 9 end-do minimise(Trimloss) writeln("Solution: Trimloss=", getobjval) forall(p in RPATT | x(p).sol>0) do write("Pattern ", p, " x ", x(p).sol, ":") forall(s in RSZ) write(" ", N(s,p)) writeln end-do write(" Excess:") forall(s in RSZ) write(strfmt(Demand(s).act-DEM(s),2)) writeln end-model