Instituto Superior Técnico Masters in Civil Engineering REGIÕES E REDES () Lecture 2: Transport networks design and evaluation Xpress presentation - Laboratory work Eng. Luis Martínez
OUTLINE Xpress presentation Xpress structure Create input files for Xpress Xpress-IVE overview Xpress-IVE key features Mosel programming language key words Declare and initialize variables in Mosel Declare an objective function and constraints in Mosel Declare and run the optimization in Mosel Output the results (library mmive ) Xpress Laboratory work with two network design examples A minimum spanning tree problem example A Min-cost-flow problem example 2
XPRESS PRESENTATION - XPRESS STRUCTURE Xpress-MP is a suite of mathematical modeling and optimization tools used to solve linear, integer, quadratic, non-linear, and stochastic programming problems. Solver engines: Xpress-Optimizer (LP, MIP, QP, MIQP, QCQP, NLP) Xpress-SLP (NLP, MINLP) Xpress-SP is a Stochastic Programming tool for solving optimization problems involving uncertainty Xpress-Kalis is Constraint Programming software (discrete combinatorial problems) Model building and development tools: Xpress-Mosel programming language Xpress-BCL is an object-oriented library Xpress-IVE is a complete visual development environment for Xpress-Mosel under Windows Xpress-Application Developer (XAD) extends Xpress-Mosel with an API for graphical user interface development 3
XPRESS PRESENTATION - CREATE INPUT FILES FOR XPRESS The input files are created in.dat files format These files should contain the vectors and matrices with the input variables identified for reading from the Xpress engine. Arcs: [( ) "Lisboa" "Odivelas" (2 ) "Lisboa" "Loures" (3 ) "Lisboa" "Amadora" (4 ) "Lisboa" "Oeiras" (5 ) "Lisboa" "Sintra" (6 ) "Lisboa" "Cascais" (7 ) "Lisboa" "Mafra" (8 ) "Lisboa" "Vila Franca de Xira ] x: [("Lisboa")46 ("Odivelas") 08843 ("Loures") 0098 ("Amadora") 052] flow: [0 5900 26500 26500 23850 5900 0 9540 3780 5900 26500 9540 0 4840 9080 26500 3780 4840 0 42400 23850 5900 9080 42400 0] 4
XPRESS PRESENTATION - XPRESS-IVE OVERVIEW Run and debug control Variables and constraints activity and output Mosel editor Optimization results Optimization process 5
XPRESS PRESENTATION - XPRESS-IVE KEY FEATURES The code file should have the following structure: model model name uses libraries to be used ("mmxprs","mmive ) parameters define parameters of the model filename of the input data file (DATAFILE= dat) end-parameters declarations declare variables and ranges of variables of the input file end-declarations initializations from DATAFILE initialize variables from file (insert variables names) end-initializations declarations declare decision variables end-declarations end-model 6
XPRESS PRESENTATION - MOSEL PROGRAMMING LANGUAGE KEY WORDS Key words: Variables types string text integer integer number real real number mpvar decision variable array(range) of type of variable forall(range) iterator forall(range) do end-do cycle with actions if end-if conditional action sum somation := assign value; =, >=,<= equality and inequality operators 7
XPRESS PRESENTATION - DECLARE AND INITIALIZE VARIABLES IN MOSEL Variables declaration and initialization: declarations NODES: set of string x: array(nodes) of real y: array(nodes) of real A: array(arcs:set of integer,..2) of string DIST: array (ARCS) of real demand:array(nodes,nodes) of integer end-declarations initializations from DATAFILE A x y demand end-initializations Declare range Declare input variables (range size defined by the input data file) Variables read in the file 8
XPRESS PRESENTATION - DECLARE AN OBJECTIVE FUNCTION AND CONSTRAINTS Objective function declaration Cost:=sum(i in ARCS)(a*flow(i) + b*exist(i))*dist(i) Constraint variable (linctr) Constraints declaration forall(a in NODES) Total(a):= sum(i in ARCS A(i,)=a) flow(i)>= sum(b in NODES) demand(a,b) FlowT:=sum(c in ARCS) flow(c) = sum(i,j in NODES) demand(i,j) forall(c in ARCS) flow(c) is_integer forall(c in ARCS) Exist(c) is_binary Decision variables 9
XPRESS PRESENTATION - DECLARE AND RUN THE OPTIMIZATION IN MOSEL After the declaration of the objective function and all the constraints we need to define the optimization method that will apply (minimization, maximization) minimize (Cost) maximize (utility) Optimize the identified constraint variable After the definition of the optimization method (if we don t define any output results text or graphical), we need to close the model with the key word end-model Having all the complete code needed we can now run the model in the Run button. 0
XPRESS PRESENTATION - OUTPUT THE RESULTS Write output results in text: getsol(mpvar) get the solution values of the variable getobjval get final value of the objective function writeln(string) write in a string line write(string) write a string strfmt(number) write as string Draw graphs: CnctGraph:= IVEaddplot("Road", IVE_YELLOW) TermGraph:= IVEaddplot("Cities", IVE_GREEN) IVEdrawpoint(TermGraph, x(i), y(i)) IVEdrawline(CnctGraph, x(a(i)), y(a(i)), x(a(j)), y(a(j))) IVEdrawlabel(CnctGraph, (x(a(i))+x(a(j)))/2, (y(a(i))+y(a(j)))/2, string(getsol(flow(a,j))))
XPRESS LABORATORY - A MINIMUM SPANNING TREE PROBLEM EXAMPLE (I) Goal: Design a network that connects all the nodes of the graph at minimum cost Decision Variables: X: array (NODES, NODES) binary Level: array (NODES) - integer Objective function: Constraints: Number of connections: Nodes i, j= Nodes / i <> j xij i, j= α Length ij Avoid Subcycle: level level + N + N x i, j j i Direct all connections towards the root: Road length: 2333.06 = N ij N / j <> j x ij i= = Spain Network Example Connections: A Coruña-Pontevedra Lugo-A Coruña Asturias-Lugo Cantabria-León Vizcaya-Cantabria Guipúzcoa-Vizcaya León-Asturias Burgos-Vizcaya Navarra-Guipúzcoa Madrid-Salamanca Barcelona-Zaragoza Valencia-Zaragoza Sevilla- Badajoz Salamanca-León Zaragoza-Navarra Badajoz-Salamanca 2
XPRESS LABORATORY - A MIN-COST COST-FLOW MULTI-TERMINAL TERMINAL PROBLEM EXAMPLE (I) Goal: Assign demand flow the an existing network from a several sources to a several sink nodes at minimum cost considering capacity constraints on the links of the graph Decision Variables: Flow: array (ARCS,ODpairs) integer Objective function: Constraints: Total source flow: Node equilibrium: Capacity constraint: nodes, jodpairs arcs ODPairs i= Flow ai Positive flow: i Capacity arcs Arcs / D = n i= Arcs / O = i O j j, ODPairs i= Flow Arcs, ODPairs ij i=, j= = a k k=, jodpairs Flowaj 0 α Flow Length Flow Arcs / O = n MaximumRatio ij ij Flow Demand k, j i j Spain Network Example 3