| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Overview of Mosel examples for 'Business Optimization' book Description List of FICO Xpress Mosel implementations of examples discussed in the book 'J. Kallrath: Business Optimization Using Mathematical Programming - An Introduction with Case Studies and Solutions in Various Algebraic Modeling Languages' (2nd edition, Springer, Cham, 2021, DOI 10.1007/978-3-030-73237-0). List of provided model files(Examples marked with * are newly introduced in the 2nd edition, all other models have been converted from the mp-model versions that were provided with the 1st edition of the book in 1997.)
Source Files By clicking on a file name, a preview is opened at the bottom of this page. Data Files quadrat.mos (!********************************************************************* Mosel Example Problems ====================== file quadrat.mos ```````````````` Quadratic Programming problem solved via linearization Example discussed in section 11.4 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 To minimise 1/2x'Gx + g'x (' indicates transpose) subject to A'x >= b , x>= 0 , x<= U [ A is m*n , G is n*n ] Lagrangian L(x,lam,sigma,pi) = 1/2x'Gx +g'x -lam'(A'x-b)-sigma'(U-x)-pi'x Kuhn Tucker conditions imply pi-sigma-Gx+A*lam = g i.e.: pi + A*lam = g + sigma + Gx A'x-r = b x+slack = U pi'*x=0; slack'*sigma=0; r'*lam=0 (complementary slackness) lam is free if A'x=b, and the corresponding r does not exist sigma and slack do not exist if U(i) infinite 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 'quadrat' uses "mmxprs" declarations N=3 ! Dimension of x (three variables) M=2 ! Number of linear constraints HUGE= 1.0e10 ! Upper bounds > HUGE are assumed not to exist RN=1..N RM=1..M G: array(RN,RN) of real ! Coeff matrix for quadratic portion B: array(RM) of real ! RHS values of linear constraints AT: array(RM,RN) of real ! Constraint coefficient matrix g: array(RN) of real ! Coefficients of linear portion U: array(RN) of real ! Upper bounds on variables IFEQ: array(RM) of real ! 1 if row i is equality, else 0 end-declarations G::[6, 2, 1, 2, 4, -0.8, 1, -0.8, 2] B::[1, 1.12] AT::[1, 1, 1, 1.3, 1.2, 1.08] g::[0, 0, 0] U::[0.75, 0.75, 0.75] IFEQ::[0, 0] declarations x: array(RN) of mpvar pi: array(RN) of mpvar lam: array(RM) of mpvar r: dynamic array(RM) of mpvar slack: dynamic array(RN) of mpvar sigma: dynamic array(RN) of mpvar end-declarations forall(i in RM| IFEQ(i)<>1) create(r(i)) forall(i in RN| U(i) < HUGE) create(slack(i)) forall(i in RN| U(i) < HUGE) create(sigma(i)) Dummy:= -sum(i in RN) x(i) + sum(i in RN) pi(i) - sum(i in RM| IFEQ(i)=0) r(i) + sum(i in RM| IFEQ(i)=0) lam(i) - sum(i in RN| U(i) < HUGE) slack(i) + sum(i in RN| U(i) < HUGE) sigma(i) ! Makes a refence row forall(i in RN) PI(i):= pi(i) + sum(j in RM) AT(j,i) * lam(j)= g(i) + sigma(i) + sum(j in RN) G(i,j) * x(j) forall(i in RM) R(i):= -r(i) + sum(j in RN) AT(i,j) * x(j) = B(i) forall(i in RN| U(i) < HUGE) UPx(i):= x(i) + slack(i) = U(i) forall(i in RM| IFEQ(i)=1) lam(i) is_free ! Free for = constraints declarations SSpi,SSs: array(RN) of linctr SSl: array(RM) of linctr end-declarations forall(i in RN) makesos1(SSpi(i),{pi(i)} + {x(i)},Dummy) forall(i in RM| IFEQ(i)=0) makesos1(SSl(i),{r(i)} + {lam(i)},Dummy) forall(i in RN| U(i) < HUGE) makesos1(SSs(i),{slack(i)} + {sigma(i)},Dummy) ! Solve the problem minimise(0) writeln("Solution: ", sum(i,j in RN) G(i,j)*x(i).sol*x(j).sol + sum(i in RN) g(i)*x(i).sol) forall(i in RN) writeln(i, ": ", x(i).sol) end-model | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
© Copyright 2024 Fair Isaac Corporation. |