![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 network2.mos (!********************************************************************* Mosel Example Problems ====================== file network2.mos ````````````````` Network problem -- Generic formulation -- Example solution to exercise 4.3 in section 4.7 / discussed in section 4.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 author: S. Heipcke, Mar.2020 (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 'network2' uses "mmxprs", "mmsvg" declarations SOURCES, SINKS: set of integer ! Nodes with outflow NODES=1..10 ! All nodes INFLOW: array(SOURCES) of real ! Inflow at source nodes OUTFLOW: array(SINKS) of real ! Outflow at sink nodes C: dynamic array(NODES,NODES) of real ! Cost of flow on arcs x: dynamic array(NODES,NODES) of mpvar ! Flows on arcs end-declarations C(1,3):=2; C(1,4):=2; C(2,4):=3; C(2,5):=5; C(3,4):=2; C(3,8):=5; C(4,5):=4; C(4,7):=2; C(5,10):=3; C(6,3):=3; C(6,8):=5; C(6,9):=2; C(7,6):=3; C(7,9):=2; C(7,10):=5 INFLOW::([1,2])[10,10] OUTFLOW::([8,9,10])[5,10,5] ! Create decision variables for defined arcs forall(i,j in NODES | exists(C(i,j))) create(x(i,j)) ! Objective: minimise total cost of flows Cost:= sum(i,j in NODES | exists(x(i,j))) C(i,j)*x(i,j) ! Flow conservation constraints: ! Outflow from sources forall(i in SOURCES) sum(j in NODES | exists(x(i,j))) x(i,j) = INFLOW(i) ! Balance at intermediate nodes forall(i in NODES-SOURCES-SINKS) sum(j in NODES | exists(x(i,j))) x(i,j) = sum(j in NODES | exists(x(j,i))) x(j,i) ! Flow into sinks forall(i in SINKS) sum(j in NODES | exists(x(j,i))) x(j,i) = OUTFLOW(i) ! Solve the problem minimise(Cost) writeln("Solution: Total cost=", getobjval) forall(i,j in NODES | exists(x(i,j)) and x(i,j).sol>0) writeln(i,"->",j,": ", x(i,j).sol) ! Graphical representation of the solution declarations XPOS,YPOS: array(NODES) of integer ! Coordinates of nodes end-declarations svgaddgroup("ArcGraph", "Arcs") svgaddgroup("NodeGraph", "Nodes") svgaddgroup("SolGraph", "Selected arcs") XPOS::(1..10)[10,10,20,20,20,30,30,30,40,40] YPOS::(1..10)[15,25,30,20,10,28,19,40,28,18] forall(i,j in NODES | exists(C(i,j))) svgaddarrow("ArcGraph",XPOS(i),YPOS(i),XPOS(j),YPOS(j)) forall(i in SOURCES) do svgaddarrow("ArcGraph",XPOS(i)-5,YPOS(i),XPOS(i),YPOS(i)) svgsetstyle(svggetlastobj,SVG_STROKEDASH, "1,1") svgaddtext("ArcGraph",XPOS(i)-8,YPOS(i)-1, text(INFLOW(i))) end-do forall(i in SINKS) do svgaddarrow("ArcGraph",XPOS(i),YPOS(i),XPOS(i)+5,YPOS(i)) svgsetstyle(svggetlastobj,SVG_STROKEDASH, "1,1") svgaddtext("ArcGraph",XPOS(i)+6,YPOS(i)-1, text(OUTFLOW(i))) end-do forall(i in NODES) do svgaddcircle("NodeGraph",XPOS(i),YPOS(i),0.5) svgsetstyle(svggetlastobj,SVG_FILL, SVG_CURRENT) svgaddtext("NodeGraph",XPOS(i)+1,YPOS(i)+1, text(i)) end-do forall(i,j in NODES | exists(x(i,j)) and x(i,j).sol>0) svgaddarrow("SolGraph",XPOS(i),YPOS(i),XPOS(j),YPOS(j)) svgsetgraphviewbox(0,0,50,50) svgsetgraphscale(5) svgsave("network.svg") svgrefresh svgwaitclose("Close browser window to terminate model execution.", 1) end-model
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |