DISCUSSION PAPER DRD118 · MODELING SYSTEHS AND NONLINEAR PROGR..A}1MING IN A RESEARCH ENVIROID1ENT Anthony Brooke Arne Drud ·Alexander Heeraus April 1~85·;< , Development Research Department Economics and Research Staff World Bank · The World Bank does not accept :responsibility for the views expressed herein which are those of the author(S!' and should not be attributed to the World Bank or to its affiliated organizations. The findings,' interpretations, and conclusions are the results of :research supported by the Bank; they do not necessarily represent official 'Bolicy of the Bank. The designations employed, the presentation of material, and any maps used in this document are solely for the convenience of the reader and do not imply the expression 0: any opinion whatsoever on the part of the World Bank or its affiliates concerning the legal status of any country, territory, city, atea, or of its authorities, or concerning the delimftations of its boundaries, or national affiliation. MODELING SYSTEMS AND NONLINEAR PROGRAMMING IN A RESEARCH ENVIRONMENT by Anthony Brooke Arne Drud Alexander Meeraus !:" Apri~.J.~8?, ' The World Bank does not accept responsibili tt for the views expressed herei,'l, · which are those of the authors and should not be attributed to the World Bank or to its affiliated organizations. The findings, interpretations, and, conclusions are the results of research supported by the Bank; they do not "- necessarily represent official Bank policy. ,The designations employed, the '! presentation of material, and any maps used in this document are solely for ... the convenience of the' reader and do not imply the expression of any opinion = whatsoever on the part of tl* world Bank or its affiliates concerning the · legal status of any country,· territory, city, areas, or of its authorities, or concerning the delimitation of its boundaries, or national affiliation. · MODELING SYSTEMS AND NONLINEAR PROGRAMMING IN A RESEARCH ENVIRONMENT by Anthony Brooke* Arne Drud** Alexander Meeraus** Development Research~De~t;m~&.:" World Bank April 1985 * Consultant, The World Bank, supported by external research budget RPO 673-06 · ** Staff Members. The World Bank · Paper prepared for the American Society of Mecl:1anical Engineers Conference on Computers in Engineering, Boston, Massachusetts, August 1985. .... · ·- - ABSTRACT Nonlinear programming (NLP) algorithms are often designed for expert users and users from other fields can find them hard to ~ork with~ The paper argues that High Level Modeling Systems can help researchers from other fields use NLP .,roductively. It describes the traditional approach to NLP modeling, ... outlines its limitations, and shows with examples from a particular mOdeling system, the General Algebraic Modeling System (GA.."tS), how the limitations can be removed. Finally, the paper reports on the use of GAMS in a research environment. Key words: Nonlinear Programming, Modeling Systems ·011 · MODELING SYSTEMS AND NONLINEAR PROGRAMMING IN A RESEARCH ENVIRONMENT TABLE OF CONTENTS I. INTRODUCTION ······· '·································· ·· 1 .. II· mE MODELING PROCESS........................ ···········3 ~ III. GAMS AND THE MODELING PROCESS ··························8 IV. THE GAMS INTERFACE TO NLP CODES ······················· 14 V. EXPERIENCE WITHGAMS ··································16 · .... ".. "- ·.. I. INTRODUCTION Nonlinear Programming (NLP) is often thought of as consisting only of nonlinear programming algorithms, and much research has been devoted to NLP algorithms in recent years. If we are interested in the usefulness of NLP as a tool in other disciplines, however, it is not enough to look at the algorithms. We must also consider the many other constraints in the overall modeling process, i.e, the process of model building, model implementation, model solution, report writing, and model documentation. And we must realize that the constraints imposed by the algorithms, i.e, by the model solution step, are often less significant· in pra!;,tjce than the t:on-s4:t."a:inf;:rlmposed by the other steps in the rnodelingproces~, in particular bYi t,.l:'~·mo<..tI:!t.. , implementation step. These observations suggest that the usefulness of NLP can be great ly improved by improving the tools for implementing the other steps in the model building process, without changing the optimization algorithms themselves. The most appropriate tools for a given task. will of course depend on the nature of the work environment; in this paper, we have distinguished between two environments with very different requirements. !?or the sake of simplicity, we call these environments the operational environment and the research environments. In a typical operational en-¥-ronment, the same type of model is t solved repeatedly. In this case, we ~an think of special purpose model ·· implementation tools that take advantllge of the special structure of the " particular problem. A hypothetical example might be a system used to help design an oil refinery. Such a system could have 'knowledge' of how an oil refinery works; the user could define an overall model by defining a set of - 2 - units from a prespecified set of well defined units arid a network o·f p1pes and ~!'~..t~E!.,~.connes~ing the ~nits. The system would be able to construct a model, with process equations for the selected units and material balance equations for the network, and submit the modeL to an optimization algorithm for solution. The system would even be able to use established rules of thumb to select initial values for the optimization. The key to the operational environment is the availability of 'knowledge', that can be used to make the modeling tools user friendly and efficient. The research envi ronment, on the otb,g.r__,h.~nd, is characterized by, ' constantly changing models and by the lack of a pool of stand.!trdized' knowledge that can be packaged irito the model building tools. In this instance, therefore, modeling tools cannot be designed to take advantage of any specific problem structure or body of knowledge. The tools for this environment must b~ general purpose; they can therefore ~nly rely on a few things that are common to most modeling projects, such as the use of mathematics. Until recently, it was common practice to use FORTRAN as the general tool in the research environment; model were implemented using specially written FORTRAN programs. Lately, however, alternative 'High Level Modeling Systems' have appeared and this paper examines the potential advantages of such systems in ~:he research environment, using examples from a particular system, the General · . 'f ... Algebraic Modeli g, System I1 (GAM~). .. . The d1scuss10n that foJlows 1S conf1ned to the research environment. Section II describes the typical modeling process 1n this environment and explains why current techniques are inadequate. In addition to a general shortage of tools, this inadequacy stems from the fact that the input to NLP codes has usually been designed to be algorithm or machine - 3 - friendly and little has been done to make it user friendly; moreover, different codes use very different types of input. The position is further complicated by the possibility that one code may prefer one type of mathematical model formulation, while another may prefer a different but mathematically equivalent formulation. Sections III and IV show how GAMS, a high level modeling system developed at the World Bank, tries to improve on this situation. GAMS breaks the input phase into two parts. The first part, described in Section III, comprises the model formulation process its'elfand th-e-bJin.ition of the representation of model and data that allows the user to define large and complex models and to test them for logical consistency in a very short time. The second part of the input phase, discussed in Section IV, is the translation of the user's model representation into the input format of the NLP code. This is done automatically by GAliS once the user has chosen a NLP code. GAMS knows the input (and output) format of several NLP codes, and the user can switch from one to another by simply changing a code name. Section V ends the pape-r with a short description of experience to date with the GAMS modeling system · · tI. THE MODELING PROCESS "- · The process of building and uSing models, linear or nonline~r, is composed of five interrelated steps: model formulation, model implementation, model solution, report writing, and model documentation. The efficiency of the overall modeling process depends on the techniques used in each of the five steps, and on how well these techniques are integrated. ~q will try in · . ... ~ '1 " .,. 'I · '\ ~ ; - " · · · - - 4 - the following pa~ag~aphs to cover each step and emphasiz~ the links between steps (see also [1]). A mathematician may think of a model simply as a set of variables tied together by constraints or equations. In p~actice, however, a set of data and the t~ansformations that convert the data into model coefficients are equally important. We define the model formulation process as that of defining the ~asic data set, defining the transformations of the data that create the coefficients of the model, and defining the variables and the constraints. Note that ou~ definition contains bqtb-a- prQcp...tj!.lc;~lO_~ recursive ... -"'''' ' -I·' .": part, the data transformations, and a non-procedural orsimu1tanequs part, the variables and the constraints. It is important to realize that we are probably dealing with multidimensional quantities such as demand in different regions for different products, output of different products in different plants· in different periods, stress in different points of a construction under different external load scenarios, etc. Basic data, derived coefficients, variables, and equations can all be multidimensional. It is also important to realize that exceptions exist in all but the most tdvi;p1 models: initial and terminal periods diffEi!r" some plants only pr'oduce some products, n'c;t all pairs of nodesln a network are connected, and so forth, This is equivalent to saying thit the multidimensional quantities 'f ... can be sparse. The model formulation procsss must therefore rely on · techniques for defining data, data transfo~ations, and variables and equations over multidimensional domains, subject tv exceptions or sparsity. Conventional a1geb~aic notation with subscripts and summations is well suited for this purpose, and most models are initially defined using this notation. - 5 - The subsequent process of implementing the model on a computer can be broken down into several linked subproce!.ses: structuring and entering the basic data, programming the data transformations, selecting the solution cede, and translating the model into the format required by the solution code. The translation step will usually involve writing a FORTRAN subroutine that can compute the constraint values for given values of the variables. It sometimes involves writing subroutines for the derivatives of the constraints; for large models it ;nay also involve specifying a sparsity pattern. Using conventional techniques, the-. FeR'i"RAN code witl-be ~it;1:"@ using approach. The block approach exploits the multidimenfti; !rti!! 'all nodes. In practice, we must remove Q(N,NP) for all pairs of nodes that are not connected, and S(N) for all non-reservoir nodes. This and other types of exceptions frequently occur in large models, and a consistent and convenient way of representing ~hemis crucial in any modeling system. The first step in our application is to define a c~rrespondence (a sparse two-dimensional set); that defines the arcs of the network. SlIT A(N,N) NETWORK ARCS ARBITRARILY DIRECTED /W.(W,CC,N), B.,(N,CC,S,~B), CC.(W,SW,S,N), S.SB, S..SW, SW.W/ An arc is represented by an ordered pair of nodes, e.g., S.5F.1 and - NW.(W,CC,N) is a shorthand for NW.W, ml.CC, NW.N. Exceptions or spariity are ... now defined with a $ err "such that" operator. Applied to the CaNT equ!tion · · above it yields - CONT(N) ·· SUK(NP, Q(NP,N)$A(NP,N)-q(N,NP)$A(N,NP» + S(N)$RN(N) =E= NODK(N,ftDEMANDn ); - 11 - The $A(NP,N) means that the term Q(NP,N) is only included in the summation if A(NP,N) is defined which means an arc existed. Similarly, SeN) is included only if the current element of N belongs to RN, the set of reservoir nodes, meaning there i~ lupply only from reservoirs. The $-operator .. can also be applied to the domain over which an equation or an assignment statement is defined, as in the following pressure loss equation. VARIABLE H(N) PRESSURE IN EACH NODE EQUATION LOSS(N,N) PRESSURE LOSS EQUATION; LOSS(N,NP)$A(N,NP) ·· H(N) - H(NP) =E=expression; Exceptions can also be handled through the use of subsets, as In the following pumping cost equation. PARAMETER PC(RH) PUMPING COST PARAMETER VARIABLE PCOST TOTAL PUMPING COSTS EQUATION PEQ PUMPING COST EQUATION PEQ·· PCOST =E= SUM(RN,S(RN) + PC(RN)*(H(RN)-NODE(RN, "HIUGHTII»); Notice that H is defined over the set of all nodes, but only referenced over the set of reservoir nodes ·. This does. not create any conflict; CAMS matches set elements properly. A model in CAMS is defined as a collect ion of equat ions and the variables they contain. To start optimizing, we simply state the objective, its direction, and. the generic problem class. Partic~lar c~des can be s~lected uSing OPTION statements. - - ... MODEL NETWORK I CONT, LOSS, PEQ, other equation names I; OPTION HLP = nlp-code; ! SOLVE NETWORK USING HLP MINIMIZING objective; Notice that the definition of the model is completely independent of the solution code, The solution code is only meqtioned in the OPTION - 12 - statement above. This is very important; if the solution attempt fails with one algorithm, it is easy to switch to another by simply changing this one statement. The execution of the SOLVE statement entails several verification and testing steps. CAMS checks that all sets, parameters, and equations used in the model have been defined and it checks that the model belongs to the class of models that can be handled by the particular NLP code. The restrictions are that equations must be differentiable functions of the variables and that variables cannot be binary. The user can disable the differentiability test by defining the model as a discontinousNLP (DNLP), but this must be done expl icitly and should only be undertaken by expel"i~~I!ced users. Then, . if~ att- is well, the model implementation and solution~~.eps outlined in sectian.d;~·· are executed. CAMS will create the problem representation in the correct format, possibly create and compile a FORTRAN subroutine, design a solution .strategy, and transfer control to the NLP code. After the solution code has terminated, CAMS will read the output and translate it back into CAMS notation for storage in the CAMS data base. Normally the user will not see any output from the NLP code. Only if it fails in an unexpected way will code specific output be returned to the user · .. The report writing step is straightforward. The solution' values were saved in the GA..'1S database by the SOLVE statement, and they can now be used in further data manipulation~, often using the DISPLAY statement to design and ... print tables. Four quantrties are saved in the database for each variable: the level value,. the lower- bound, the upper bound, and the marginal value; " four similar quantities are saved for each equation. The four values of variable Q can be referred to as Q.L, Q.LO, Q.UP, and Q.M, respectively. The - 13 - level values of Q are displayed with a "DISPLAY Q.L;" statement yielding the printout in Fig. 1. References to the four quantities associated with a variable or an equation can be on either the right or left hand side of an assignment, i.e., H.LO can be used to compute values for a report after a model has been solved, but it can also be assigned a value, e.g., H.LO(N) = NODK{N,tlHEIGHT It ) + 7.5 + 5.0*NODE(N,"DEMAtm"); Assignments of level values are used to define initial values for an optimization, and all the data manipulation machinery of GAMS is available. It is therefore easy to compute good initial vatues"an.cL.tD_try alterna.f:ivl:!'"'· sets of these values. The use of the current le:v.QI..:values· as initiaL~a1'4E:;'S'i'" for an optimization has an added advantage: if we want to solve a second, related model,GAMS will auto~atically use the optimal values from the first model as initial values for the second. It is sometimes useful to solve one DESIGN OF A WATER DISTRIBUTION NETWORK (WATER,SEQ-G8) EX E CUT I N G 102 VAR.l Q FLOW ON EACti ARC - SIGNED (M*,3 PER SEC) CC W SW S SE N NW 1.238 ~.685 0.606' E 0.005 0.644 0.244 0.441 CC 0.007 0.010 0.011 0.003 SW -0.240 S -0.005 ~.ooa f ... . Figure 1: Printout Produced bX the "DISPLAY g.t;!' Statement · ..- or more relatively simple problems, perhaps linear ones, to find a good starting point from which the NtP can take over automatically. The use of current level values as inita1 values is also extremely useful if an NtP code cannot solve a model. It is easy to try to solve the model with another code, starting from the intermediate solution found by the first code. All the user · has to do is to specify the name of the new code, and GAMS~an take care of \ I l t, the rest. Automatic use of level values can also be useful after reformulations of certain parts of a model. The values of the variables will automatically be used by GAMS as long as their names are the same. Documentation is the final step in the modelling process. The only thing that has to be documented is the GAMS source input; all other parts of ,the model are temporary data structures and can be ignored. CAMS> ha.& ,been designed to encourage the modeler to docuoent the model as it is' d~apedcl..l All sets, parameters, variables, and equations can have documentation texts associated with them, and the documentation is kept in the GAMS database and displayed each time they are printed. The GAMS source input can be used as the complete documentation of the model, especially if the modeler makes a conscientious effort to make source text clear and easy to understand. The development of a model in GAMS is similar to that of writing a scientific paper: several drafts are usually needed before the message has been ... presented in a clear and concise vay to make it as easy as possible for the reader. Several models developed in the World Bank now use the GAMS input as the final model documentation and include it in the final reports, as in for example Brown et al, [3], Choks i et al, [4], and Keldrick et al [9]. - 15 - IV THE GAMS INTERFACE TO NLP CODES. One of the design philosophies of Gfu~S is that models should be represented in an algorithmically independent way. This is, of course, useful only if links exist to many different optimization codes, and preferably to codes that are built around different principles. At present, GAMS can communicate with four L.P systems and four NLP codes~ and more links, both generic and specific, will be added. Table 1 gives an overVlew of severaL characteristics of the four NLP codes that can be used with GAMS. The codes are GRG 2 (Lasdon et.al. [11]), NPSOL (Gill et.al., [8]), MINOS 5.0 (Murtagh and Saunders, [14]), and CONOPT (Drud, [6]). The table entries· describe different dimens~o1Vl of an interface; the table has been included to show the kind of effort that must be put in~~& set of interfaces between a modeling system and several algorithms. A more technical description of how the interfaces have actually been built can be found in the appendix of Brooke et.al. [2]. V. EXPERIENCE WITH GAMS. GAMS has been available for LP models since 1980, and for NLPs since 1982. It has been used in the World Bank and at collaborating research and teaching institutions by peopl~ Vith widely differing exp~rience in mathema- tical programming, mostly for solving problems in policy analysis, economics, and engineering. ~he benefits to these users have been substantial. For 'f .. example, the model$r is more productive; in many cases, a modeler has been able toavoidempltying a programmer to translate algebra into the machine · representation, thus maintaining direct control of the project while still producing timely results. Perhaps more importantly, the details of a modeling Table 1: SOME CHARACTERISTICS OF THE FOUR NLP CODES CURRENTLY ACCESSIBLE THROUGH GAMS Code GRG2 CONOPT NPSOL MINOS Characteri stics : .. Algori thm Type: 1/ GRG GRG SQP PAL Jacobian. representation: Sparse No Yes No Yes Equations ordered No No Yes Yes Variables ordered No No No Yes Non linear elements distinguished No Yes No 2/ No 2/ Subroutines: Constraints and objective separated No No Yes Yes Linear terms in functions Yes 3/ Yes No Numerical derivatives Yes Yes No '(e.s Numerical derivatives computed sparse 4/ Yes No Name to index mappings 5/ Yes No Miscellaneous Stand-alone system Yes Yes No Yes System can be modified Yes No Yes Yes System controls memory, error recovery and file buffers No Yes No No Notes: 1. ·The algorithm types are: GRG - Generalized Reduced Gradient t SQP - Sequential Quadratic Programming, and PAL - Projected Augmented Lagrangian. ) 2. NPSOL considers aloJ-. Jacobian elements in the nonlinear equatioI1s ,to be nonlinear, and MINOS considers all Jacobian elements occuring in both nonlinear variables and nonlinear equations to be nonlinear. 3. Linear terms can either be included in·the FORTRAN subroutine or the coefficient can be defined through the MPS file. · 4. Numerical derivatives are computed 'sparse' if sev~ral columns of the Jacobian can be computed in one call of the constr!int subroutine (see C~eman and Moret [4]).~ 5. Bo.th MINOS and CONOPT define a sparse Jacobian thrtxgh an MPS":'type file, i.e., through names of variables. The subroutines use variable indices. CONOPT allows explicit mappings from names to indices MINOS does not. t effort are now more readily accessible to others, and the traditional question about 'what really happens in this model' can be answered. GAMS has also been found very useful in teaching. Models set up and solved by students have typically been small, because understanding and implementing the data structure for complex models 1S a tedious and specialized task. GAMS and its associated library of models permit students to concentrate on the model and not on the details of its implementation, and to experiment with formulation or data changes on models large enough to be interesting. As mentioned 1n the introduction, GAMS has been designed to be a research tool. Once a problem 1S well understood through model experiments and the results are ready to be used operat i'ona'tly, , H., rna)" oe"aavahtageous t'0' switch to a modeling system that is more directly oriented towards the needs of the operational environment. A major oil company has used GAMS in its research department for some years without changing its operational modeling system. The company saw a need for experimentation with alternative model formulations before a final model was selected for operational use. The operational modeling system was not considered suitable for experimentation, and GAMS was selected for this task. After a robust formulation was found with GAMS, however, the model was transferred into the,existing operational . modeling system. The transfer was done manually in this case, but models can often be moved to other ~ystems automatically by the same mechanisms as those '! used in the interfaces to model solution algorithms. . .... .- .. - Finally, it is worth noting same usage statistics. In the World Bank alone, 15 projects currently use GAMS. Non-linear problems, ranging up to 700 equations, now outnumber linear problems. The GAMS system is accessed by World Bank users about 50 times on a normal weekday. REFERENCES [1] J. Bisschop and A. !'Ieeraus, "On the development of a General Algebraic Modeling System in a Strategic Planning Environment", Mathematical Programming Study, Vol. 20 (1982) pp. 1-29. [2] A. Brooke, A. Drud, and A. Meeraus, "High Level Modeling Systems and Nonlinear Programming", Development Research Department, Discussion paper No.ll3, World Bank (1984) 30p. · [3] M. Brown, A. Dammert, A. Meeraus, and A. Stoutjesdijk, "Worldwide Investment Analysis, The Case of Aluminum", World Bank Staff Working Paper, 603 (1983) l68p. [4] A. M. Choksi, A. Meeraus, and A. Stoutjesdijk "The Planning of Investment Programs in the Fertilizer Industry", John Hopkins University Press, (1980) 333p. [5] C. F. Coleman and J. J. More, "Estimation of Sparse Jacobian Matrices and Graph Coloring PrOblems", SIfu~ Journal of Numerical Analysis, vol. 20 (1983) pp.187-209. [6] A. Drud, "CONOPT - A GRG Code for Large Sparse Dynamic NonLi,r.-e-ar-- - Opt imizat ion Problems", Mathematical Programming, vol. 31, 1985", pp,.153-' 191. [7] S. I. Gass, K. L. Hoffman, R. H. F. Jackson, L. S. Joel, and P. B. Saunders "Documentation for a Model: A Hierarchical Approach" Communications of the ACM, vol.24 (1982), pp. 728-733. [8] E. P. Gill, W. Murray, M. A. Saunders, and M. H. Wright, "User's Guide for SOL/NPSOL: A Fortran Package for Nonlinear Programming", Department of Operations Research, Stanford University, (1984) 34p. [9] D. Kendrick, A. Meeraus, and J. Alatorre, "The Planning of Investment Programs in the Steel Industry", John Hopkins University Press, (1984) 3l0p. [10] D. Kendric:k and A. Meeraus, "GAMS, An Introduction", mimeo, Development Research Department, World Bank, (1984). [11] L. S. Lasdon, A. D. Waren, A. Jain, and M. Ratner, "Design and Testing of a Generalized Reduced Gradient Code for Nonlinear Programming", ACM '. transactions on Mathematical Software, vol. 4 (1978), pp. 34-50.--- [12]~. Meeraus, "General Algebraic Modeling System (GAMS), User's Guide . -:.ersion 1.0", Development Research Center,World Bank, (1982). [13]'1. Meeraus, "An Algebraic Approach to Modeling", Journal of Economi: Dynamics and Control, vol. 5 (1983) ?p. 81-108. [141 B. A. Murtagh and M. A. Saunders, itA Projected Lagrangian Algorithm and its Implementation for Sparse Nonlinear Constraints", Mathematical Programming Study vol. 16 {1982}, pp. 84-117. -. ·- · APPENDIX A GAMS LISTING OF EXAMPLE MODEL .. 'f ... · .,-- - I" H H. I' 04/10/85 10;52:43 PAGE DESIGN OF A WATER DISTRIBUTION NETWORK (WATER,SEQ=66) GAMS 2.00 IBM CMS 2 " THIS EXAMPLE ILLUSTRATES THE USE OF NONLINEAR PROGRAMMING IN THE DESIGN OF 3 " WATER DISTRIBUTION SYSTEMS THE MODEL CAPTURES THE MAIN FEATURES OF AN J 4 " ACTUAL APPLICATION FORA CITY IN INDONESIA. 5 6 "" REFERENCES; A BROOKE, A DRUD, AND A MEERAUS. MODELING SYSTEMS AND 7 " NONLINEAR PROGRAMMING IN A RESEARCH ENVIRONMENT, """ 8 ORO DISCUSSION PAPER 118, DEVELOPMENT RESEARCH DEPARTMENT, 9 WORLD BANK, 1985. 10 A DRUD AND A AF ROSENBORG, DIMENSIONING WATER DISTRIBUTION 11 " NETWORKS, M. SC. DISSERTATION, (IN DANISH), INSTITUTE OF 12 " MATHEMATICAL STATISTICS AND OPERATIONS RESEARCH, TECHNICAL 13 " UNIVERSITY OF DENMARK, 1973. 14 "SET 15 N NODES 1 NW NORTH WEST RESERVOIR 16 £ EAST RESERVOIR 17 CC CENTRAL CITY 16 W WEST 19 SW SOUTH WEST 20 S SOUTH 21 SE SOUTH EAST 22 N NORTH 1 23 A(N,N) ARCS (ARBITRARILY DIRECTED) 1 NW.(W,CC.N). E.(N,CC.S,SE). CC.(W,SW,S.N). S.SE.S.SW, SW.W 1 24 RN(N) RESERVOIRS 1 NW, E 1 25 DN(N) DEMAND NODES; DN(N) =YES;DN(RN) · NO; DISPLAY ON; 26 ALIAS (N,NP); 27 28 TABLE NODE(N,") NODE DATA 29 PCOST 30 DEMAND HEIGHT X Y SUPPLY WCOST 31 MU 3/SEC RP/M"4 " M OVER BASE M M Mf"3/SEC RP/M"3 1.02 32 NW 6.50 1200 3600 :2.500 0.20 33 E 3.25 4000 2200, 6.000 0.17 1. 02 34 CC 1.212 3.02 2000 2300 35 W 0.452 5.16 750 2400 36 SW 0.245 4.20 900 1200 37 S 0.652 1.50 2000 1000 38 SE 0.252 0.00 4000 900 39 N 0.456 6.30 3700 3500 40 41 PARAMETER DIST(N,N) DISTANCE BETWEEN NODES (M); 42 'DlSl'(N,NP)$A(N,NP) :: SQRT( SQR( NODE(N,"X")-NODE(NP,"X") .) + SQR( NOOE(N,"Y")-NOOE(NP,"Y") ) ); 43 DISPLAY OIST; 44 45 SCALAR DPOW POWER ON DIAMETER IN PRESSURE LOSS EQUATIQN 1 5.33 1 46 QPOW POWER ON FLOW. IN PRESSURE LOSS EQUATION ',I 1 2.00 1 47 DMIN MINIMUM DIAMETER OF PIPE 1 0.15 1 41l DMAX. MAXIMUM DIAMETER OF PIPE 1 2.00 1 1 1.03E-31 4", HLOSS CONSTANT IN THE PRESSURE LOSS EQUATION 1 6.90E-21 50 DPRC SCALE FACTOR IN THE INVESTMENT COST EQUATIQN 51 CPOW POWER ON DIAMETER IN THE COST EQUATION 1 1.29 1 52 R INTEREST RATE 1 0.10 1 53 DAVG AVERAG~OIAMETER (GEOMETRIC MEAN) 54 RR RATIO OF DEMAND TO SUPPLY; 55 56 DAVG =SQRT(DMIN.OMAX.); 57 RR = SUM(DN.NODE(ON."OEMANO"» 1 SUM(RN,NOOE(RN,"SUPPLV"»; .' ., 'j?, ... t/ ", DESIGN OF A WATER DISTRIBUTION NETWORK (WATER,SEQ=68) 04/10/85 10:52:43 PAGE 2 GAMS 2.00 ISM CMS 58 59 VARIABLES Q(N,N) FLOW ON EACH ARC - SIGNED (MU 3 PER SEC)· 60 D(N,N) PIPE DIAMETER FOR EACH ARC (M) 61 H(N) PRESSURE AT EACH NODE (M) 62 SeN) SUPPLY AT RESERVOIR NODES (Mu 3 PER SEC) 63 PCOST ,· ,1I'.·ANtlUiALIRECURRENT PUMP COSTS (MIL.L RP) 64 DCOST INVESTMENT COSTS FOR PIPES (MILL RP) 65 weOST ANNUAL RECURRENT WATER COSTS (MILL RP) 66 COST TOTAL DISCOUNTED COSTS (MILL RP) 87 68 EQUATIONS CONT(N) .FLOW CONSERVATION EQUATION AT EACH NODE 68 LIJSS(N.N) PRESSURE LOSS ON EACH ARC 70 PEQ PUMP COST EQUATION 71 DEQ INVESTMENT COST EQUATION 72 WEQ WATER COST EQUATION 73 DBJ . OBJECTIVE FUNCTION; 74 75 CONT(N).. SU~( NP , Q(NP,N)$A(NP,N) - Q(N,NP)$A(N,NP) ) + S(N)$RN(N) -E= NOOE(N,"OEMANO"); 16 71. LOSS(N,NP)$A(N,NP) .. 78 H(N) - H(NP) HLOSS · DIST(N,NP) · ABS(Q(N,NP» ·· (QPOW-l) · Q(N,NP) I O(N,NP) ·· DPOW; 79 )0 PEQ ·. PCOST =E= SUM( RN , S(RN) · NODEiRN,"PCOST") · ( H{RN)-NODE{RN,"HEIGHT") ) ); 81 82 OEQ .. DCOST =E= DPRC · SUM( (N,NP)$A(N,NP) · OIST(N,NP) · O(N,NP).+CPOW }, IV IV 83 84 WEQ ·. WCOST =E= SUM( RN S(RN) · NOOE(RN."WCOST") ), 85 86 OBJ .· COST =E= ( PCOST + WCOST I R + DCOST; 81 · 88 · BOUNDS 89 · 90 D.LO(N,NP)$A{N,NP) = DMIN; D.UP(N,NP)$A(N,NP) =OMAX; 91 H.LO(RN) = NODE(RN,"HEIGHT"); H.LO(ON) =NODE(DN."HEIGHT") + 1.5 + 5.0 · NODE(DN."OEMANO"); 92 S.LO(RN) = 0; . S.UP(RN) = NODE(RN,"SUPpLY"); 93 · 94 · INITIAL VALUES 95 · 96 O.L(N,NP)$A(N,NP) = OAVG; 97 H.L(N) = H.LO(N) + 5.0; 98 S.L(RN) = NODE(RN,"SUPPLY").RR; '99 · 100 MODEL NETWORK IALL/; 101 SOLVE NeTWORK USING ONLP MINIMIZING COST; 102 DISPLAY Q.L; ",.;; ,~W'. " ··:.,..,.~~, .:' ."~"."-_=='1 .... ,. .. " 04/10/85 10:52:43 PAGE 3 DESIGN OF A WATER DISTRIBUTION NETWORK (WATER.SEQ=68) GAMS 2.00 IBM CMS SYMBOL LISTING SYMBOL TYPE REFEREN~ , A SET DECLARED 23. REF 2*42 4*75 2*7; 2*82 4*90 2*96 ABS FUNCT REF 78 CONT EQU DECLARED 68 DEFINED 75 COST VAR DECLARED 66 IMPL-DEF 101 REF 2*86 CPOW PARAM , DECLARED 51 REF 2*82 REF 2*78 2*S2 0 VMl DECLARED 60 IMPL-DEF 2*101 ASSIGNED 2*90 96 OAVG PARAM DECLARED 53 ASSIGNED 56 REF 2*96 OCOST VAR DECLARED 64 IMPL-DEF 2*101 REF 2*82 2*86 OEQ EQU DECLARED 71 ,DEFINED 82 DIST PARAM DECLARED 41 ASSIGNED 42 REF 43 2*78 2*82 DMAX., PARAM DECLARED 48 REfit . 2*56 2*90 OM1N PARAM DECLARED 47 REF 2*56 2*90 CONTROL 57 91 ON SET DECLARED 25 ASSIGNED 2*25 REF 25 57 2*91 OPOW PARA" DeCLAReD 48 RI!I' 2'78 DPRC PARAM OECLARED 50 REF 2*(12 REF 4*78 2*80 2*97 H VAR DECLARED 61 IMPL-DEF 3*101 ASSIGNED 2*91 97 HLOSS PARAM DECLARED 49 REF 2*78 LOSS EQU DECLARED 69 DEFINED 78 25 26 28 2*41 3*42 2*59 2*60 N SET ·DECLARED 15 REF 2*23 24 96 97 61 62 68 2*69 7*75 77 5*78 3*82 2*90 CONTROL 25 42 75 77 82 2*90 96 97 NETWORK MODEL DECLARED 100 2*84 6*91 2*92 2*98 NODE PARAM DECLARED 28 REF 6*42 4*57 2*75 4*80 a*S2 2*90 96 CONTROL 42 NP SET DECLARED 26 REF 3*42 4*75 77 5*78 \ N 75 77 62 2*90 96 ; w OBJ cQU DF.CLARED 73 DEFINED 66 I PCOST VAR DECLARED 63 IMPL-DEF 2*101 REF 2*60 2*66 PEQ EQU DECLARED 70 DEFINED 60 102 Q VAR DECLARED 59 I,MPL-DEF 4*101 REF 4*75 4*78 QPOW PARAM DECLARED 46 REF 2*78 R PARAM DECLARED 52 REF 2*86 91 92 98 CONTROL 25 RN SET DECLARED 24 REF 57 2*75 4*80 2*8~ .~ 57 SO 84 91 2*92 98 RR PARAM DECLARE~\''* .i.I1IASSIGNED 57 REF 2*98 REF 2*75 2*80 2*84 S VAR 'DECLARE 62 IMPL-DEF 3*101 ASSIGNED 2*92 SQR FUNCT REF 2*42 SQRT FUNCT REF 42 56 WCOST VAR DECLARED 65 IMPL-DEF 2*101 REF 2*84 2*~6 WEQ EQU DECLARED 72 DEFINED 84 <, F. SETS A ARCS (ARBITRARILY DIRECTED) ON DEMAND NODES 'N NODES /liP ALIASED WITH N RN RESERVOIRS PARAMETERS CPOW POWER ON DIAMETER IN THE COST EQUATION DAVG AVERAGE DIAMETER (GEOMETRIC MEAN) ...,.'<, It_,'~ " *' f.-YMW¢' fSltus'wuerWh'StWS', t- UW@' ti 01fft··iiil,j*..xWkftft*e&Hr .- . I eret'hiS, ,&rrOit*VJit1ta?MtI/4j:tt:U#,f!x iZ f(B\'''fiW6 ~'.~~ 11 DESIGN OF A WATER DISTRIBUTION NETWORK (WATER,SEQ=68) 04/10/85 10:52:43 PAGE 4 SYMBOL LISTING " GAMS 2.00 IBM CMS PARAMETERS DIST DISTANCE BETWEEN NODES (M) DMAX MAXIMUM DIAMETER OF,PIPE OMIN MINIMUM DIAMETER OF PIPE DPOW POWER ON DIAMETER IN PRESSURE LOSS EQUATION DPRC SCALE FACTOR IN THE INVESTMENT COST EQUATION HLOSS CONSTANT IN THE PRESSURE LOSS EQUATION NODE NODE DATA QPOW POWER ON FLOW IN PRESSURE LOSS EQUATION R INTEREST RATE RR RATIO OF DEMAND TO SUPPLY VARIABLES COST TOTAL DISCOUNTED COSTS (MILL RP) 0 PIPE DIAMETER FOR EACH ARC (M) DCOST INVESTMENT COSTS fOR PIPES (MILL RP) H PRESSURE AT EACH NODE (M) PCOST ANNUAL RECURRENT PUMP COSTS (MILL RP) Q FLOW ON EACH ARC - SIGNED (MU 3 PER SEC) S SUPPLY AT RESERVOIR NODES (MU 3 PER SEC) WCOST ANNUAL RECURRENT WATER COSTS (MILL RP) N '-' .I:'- !5QUATIONS CaNT FLOW CONSERVATlON EQUATION AT EACH NODE DEQ INVESTMENT COST EQUATION L.OSS PRESSURE LOSS ON EACH ARC OBJ OBJECTIVE FUNCTION PEQ PUMP COST EQUATION WEQ WATER COST EQUATION 'w MODELS ~ETWORK ~. 10MPILATION TIME = 0.551 SECONDS .'