Docsity

linear - programming - in - pascal - 2-220115, Notas de estudo de Medicina Veterinária

Pré-visualização parcial do texto

Baixe linear - programming - in - pascal - 2-220115 e outras Notas de estudo em PDF para Medicina Veterinária, somente na Docsity!

Programming | Pascal 005 133 Bo42L O B. D. Bunday 1987 First published 1987 by Edward Arnold (Publishers) Ltd 41 Bedford Square, London WCIB 3DQ Edward Arnold 3 East Read Street, Baltimore, Maryland 21202, USA Edward Arnold (Australia) Pty Ltd 80 Waverley Road, Caulfield East, Victoria 3145, Australia British Library Cataloguing in Publication Data Bunday, B. D. Linear programming in Pascal. 1. Linear programming—Dara processing 2. PASCAL (Computer program language) I. Title IL Garside, Gerald 519.7'2'02855133 T57.74 ISBN 0-7131-3647-2 AM Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopyiag, recording or otherwise, without the prior permission of Edward Amold (Publishers) Ltd. Reg. CoNPRA — , BBã ERRO cpcabAt o 8318 nc r/0s/ Text set in 10/12pt Times Compugraphic by Mathematica! Composition Serters Ltd, Salisbury Printed and bound in Great Britain by J. W. Arrowsmith, Bristol i i t Preface This book presents a course in Linear Programming which will be suitable for a wide range of undergraduate and postgraduate courses. Students of Mathematics, Science and Engineering, as well as students on Management courses which contain a solid component of quantitative methods, will find the text very useful and suited to their needs, Postgraduate students, particularly those on conversion courses in Operational Research or Management Science, will also find the material of value. The mathematical theory is carefully developed, although there are more rigorous treatments. What the text may lack in rigour is more than compensated for by the main thrust of this book, which is to show, in a vivid manner, the way in which the theoretical ideas are transformed into practical computational procedures capable of implementation on a digital computer. The methods are computer methods and should be treated as such. 1t is no accident that the main theoretical developments coincided in time with the advent of the computer. Without the iatter it would not have been possible to exploit the potential of the theory in the actual solution of real problems. The text assumes that the reader is famitiar with the computer language Pascal. The programs have been written in this language. Of course many main frame com- puters contain packages which will implement the methods discussed in this book. However, these can be remote and can be treated as a black box and thus used without full understanding. Pascal is available on many microcomputers and their interactive nature will allow the student to become intimately involved with the programs, It is not claimed that these are incapable of improvement. Indeed the authors would be delighted to hear from readers who feel that they can produce better programs. It is through such close involvement thar students will gain a.real appreciation of the significance of the theory as well as developing their practical computational and programming techniques. The programs given are robust and practical. The modeiling aspects of Linear Programming are catered for through the worked examples within the text, and the exercises to be found at the end of each chapter. The reader is strongly advised to test his skills with these problems, Although some of them are necessarily abbreviated and simplified, they do point to the wide variety Of situations in which Linear Programming can find application. A few remarks about Pascal and the way it is used in this book are appropriate. The programs have been written in Level O ISO Pascal. The modular and data strucruring facilities of Pascal have been used in implementing the algorithms and these, together with the comments in the code, should make the programs reasonabiy easy to follow. Since Pascal is a compiled language, each linear programming problem may require some modification to the program constants and recompilation before the problem can be soived. The parts of the program that may require such modification are indicated by the symbols [++ on the right hand side of the appropriate lines. Alternatively, the reader may prefer to declare these program constants as variables, introducing new constants with sensibie upper bounds for any subranges and arrays that exist. Several problems could then be solved by the same compiled program, providing the problem parameters are made part of the input data. All the programs given in this book have been compiled and run successfully on a mainframe (CDC 180--830 using the University of Minnesota Pascal-6000 V4.0 compiler running under NOS 2.3), à minicomputer (Vax 11/750 using the Berkeley Pascal compiler running under UNIX 4.2BSD) and a microcomputer (an IBM- compatible Ericsson PC using Turbo Pascai running under DOS 2.11). The output shown in the text is that from the CDC machine. k may be necessary or desirable to make slight alterations to the input/output instructions in the program code dependent on the host machine and whether inter- active features are favoured or data and ontput files used. For example, on Turbo Pascal using files it will be necessary to assign file names, reset and rewrite files, include file names in read/vrite instructions and close files. The manner in which the programs have been written should make the points of required alteration easy to identify. Ii is a pleasure to thank friends, colleagues and students who have contributed to this work. The students have been willing guinea-pigs for many of the problems. Some of these have been taken from examination papers set at the University of Bradford. We are grateful to the university for permission to use these questions. We are indebted to Mr C. Mack for many beneficial and illuminating discussions on the ideas of his method for the Assignment Problem. Last but not least we must thank Mrs Valerie Hunter for her help in wansforming what was at times a messy manuscript into a neat and tidy typeseript. BRIAN BUNDAY AND GERALD GARSIDE 1987 Contents Preface 1 Fundamental Ideas tl Introducrion 1.2 Graphical solution of two-dimensional problems 1.3 A standard form for linear programming problems 1.4 Some n-dimensional geometry 1.5 Fundamental results for linear programming 2 The Simplex Method 2.1 The Simplex Method given an initial basic feasible solution 2.2 Implementing the Simplex Method on the computer 2.3 Generating an initial basic feasible solution 2.4 The full Simplex Method 2.5 The problem of degeneracy 3 Sensitivity Analysis 3.1 The inverse of the basis and the simplex muitipliers 3.2 The effect of changes in the problem 3.3 The Dual Simplex method 4 The Transportation Problem 4.1 The nature of the problem and its solution 4.2 The 'Stepping Stones” algorithm 4.3 Unbalance and degeneracy in the Transportation problem 4.4 Implementing the Transportation algoritim on the computer 5 The Assignment Problem 5.1 Introduction 5.2 Mack's method of solution 5.3 A computer program for Mack's method 6 The Revised Simplex Method 6.1 The Revised Simplex algorithm 6.2 Initiating the algorithm 6.3 Degeneracy revisited 6.4 A computer program for the Revised Simplex Method 7% 7% 8 84 89 105 105 106 no 120 120 126 128 13] and it is not possible to make ihese derivatives zero by choice of xi and x2. Indeed the way to increase P is to go on increasing Xi and x>. But, and this is the essence of the problem, x; and x» cannot be increased without limit. Their possible values are restricted by physical considerations and by the constraints on raw material and machine time. Because x, and x; represent the number of units of each model produced each week, it is clear that they cannot be negative: ie 020020. (1.2) The constraints on availability of board and machine time can be put in the form: Board: 3x + 4x, < 1700 Machine hours: 3x1 +12 < 160 Le. 3x +40 S Teco) . 1.3 24 4 5x < 1600) (1.3) Thus the problem is to find values of x1 and x, which satisfy the non-negativity conditions (1.2) and the ineguality constraints (1.3) so as to maximise P = 2x + Aa. This ís a typical linear programming problem. The objective function which isto be maximised is a linear function of the variables. The constraints on these variables are also linear. Indeed for this particular two-dimensional problem they can be represented graphically by the lines shown in Fig. 1.1. The non-negativity conditions restrict the variables to the positive quadrant. The constraints are represented by the lines: 3x1 + 4x2 = 1700 2x, + 5x2 = 1600. The arrow on each constraint in Fig. 1.1 indicates the side of the line on which the constraint is satisfied. The directions on each arrow can easily be determined by considering whether the origin (0, 0) satishes the constraint. The shaded area OABC which contains all points (x, Xz) satisfving equations (1.2) and (1.3) is called the feasible region. Points within and on the boundary of this region represent feasible solutions of the constraints. There are plenty of feasible solutions. The problem is to find the one (or might there be more than one?) which maximises P. . The (dashed) lines (a) 2x1+4x2=0, (b) 2x + 4x2 = 800, are shown in Fig. LI. These lines are paralle! and represent two contour tines of the function P with values O and 800 respectively. It is clear that the value of P increases as the contour lines move further away from the origin in the positive quadrant. Indeed the vector with ap 3x Ela ôx: 2 : gun components, i.e. the vector with components ( ) points in the direction of 4 increasing P and this direction is perpendicular to these parallel lines, away from 0, as shown. *2 800) Es Direction of increasing = 2x, + 5x7 = 1800 - 3x, + 4x, = 1700 >s 2 Figure 1.1 The contour line with the highest value of P which has at least one point in com- mon with the feasible region is the line (c), which passes through the vertex B, and on which P has rhe value 1400, The point B, xy = 300, x2 = 200 corresponds to the optimai solution for the problem, These values can be obtained as the solution of the equations 3x1 + 4x2 = 1700 2x1+5x2= 1600, Of course the maximum profit is then 2 x 300 + 4x 200 = 1400. In the optimal solution both constraints are satisfed as equalíties, and this can be interpreted as meaning thas all the available raw material and machine time is ntilised. It is clear that this problem could be extended. There could be three or more models and a corresponding number of non-negative variabies. There could be additional constraints representing market capacity, limitations on packaging facilities, etc. The problem would still be one of maximising a linear function of several non-negative variables which are subject to finear inequality constraints. The general linear programming problem is that of maximising (or it couid be minimising) a linear function Z= CH + Cro + eo > Ca (1.4) of x real variables xr, 22 Xm satisfying the non-negativity conditions 2120,020,...,x%m20 (1.5) and m linear constraints aum tanm+ro tas = bd, <=2b Qux+ ana + + dana S = - 489) Gm + Qmaka + eee + Gm, <= 2 bm The constraints can be a mixture of the “x”, '="or >" variety. The aim will be to maximise the objective or perhaps to minimise the objective (if it represents a cost for example). The values of the ds, Cy, ay are assumed to be known constants. They will often have a physical interpretation in terms of a practical problem as in Example 1. in matrix notation the problem can be written Maximise (or minimise) z=e'xo (17) where 20 (1.8) and Am<=2b (1.9) x where xo=[| x» jisannx1 column vector, Xn, T=(ee» o Cn)isa 1 XA TOW vector, bi b=[ b> lis an mx 1 column vector, which can be assumed non-negative, and Ao = (a) is an mx n matr. The suffx O or xo and Ao is to be taken to mean “original”. The point will be taken up and made clear in Section 1.3. 4.2 Graphica! Solution of Two-Dimensional Problems The two-dimensional example of the previous section served to show how a linear programming problem could arise from a practical situation and aiso showed à graphical method of solution. Through a study of a few other such examples which are simple enough for us to see “what is going on”, it will be possible to bring out certain general features of linear programming problems whose expioitation can lead to a systematic solution procedure. Example + Minimise z=-3xr- 4% | 22 20) 1, +x9220 x, 10 Figure 1.2 where xi, x2 20 and n+ asa -n+40<20 x 210 m>s. PQRS is the feasible region in Fig. 1.2. The last two constraints subsume the non- negativity conditions. z decreases in the direction Ea º x é y Eos (3 àm The minimum value of z is — 68 and arises at R(12, 8). Note that as in the example of the last section the minimum occurs at a vertex of the feasible region. The optimal solution is x1 = 12, x =8 with the minimum of z at —68. Sometimes there is more than one optimal solution. Example 2 Minimise z=-6m- 2x 8 Fundamentai facas a DA 3x, +50 =15 4 ta9 210 445% 142 Figure 1.5 One or two fairly general features of linear programming (L.P.) problems can be deduced from the examples already considered. The first is that the feasible region is always a convex polygon. Even in the case where it was unbounded it was convex on its closed aspect. The second is that the optimum solution always occurs at a vertex of the feasible region. in Example 2 where there were several optima! solu- tions both the vertices B and C corresponded to optimal solutions. We shall see that we can generalise these results. First we show that we can put all L.P. problems in a standard form. 1.3 A Standard Form for Linear Programming Problems Tt may appear that L.P. problems cam take on a variety of forms with the con- straints a mixture of “>','='or'<' type. They can ali be put into a standard form in which the objective function is to be minimised and all constraints take the form of equations in non-negative variables. Problems which do not initially conform to this standard form can be brought to this form quite simply. (a) Maximising the objective function 7=CX1 + + + CaXn is equivalent to mini- mising the objective function g=— enem —Cakm (b) Inequality constraints. The constraint 3x + 2x, x3 € 6 can be put in equation form as Im +2m-0+%=6 where the slack variable xs is non-negative. The constraint x1 — x2 + 3x3 > 10 can be put in equation form as *1-22+3x3— x5= 10 where the slack variable xs is non-negative. (c) Non-negarive variables. If a particular variable xy can take on any value then we can write x = Xk — Xk where xt > 0 and xt > 0. Thus bringing a problem into the standard form might involve the introduction of additional variables, (which are still non-negative) into the problem. Thus following on from equations (1.7), (1.8), (1.9) our most general L.P. problem can be put in the form minimise a=elx (1.10) where x>0 (in) and Ax=b, with 5>0. q. If this problem did indeed arise from that given earlier then x will contain the slack variables as well as the original variables and 4 will contain the coefficients of the slack variables as well as the original coefficients. Thus Example 1 of Section 1.2 can be put in the form minimise z=—-3n— 4x subject to the constraints x -3 =10 *2 — xa =5 + x + =20 -x+4% +x4=20 and x, 20,i=1,2,...,6. Example 1 of Section 1.1 can be put in the form minimise z= lx, — 4x subject to the constraints 3x +40 + %3 = 1700 2x1 +5x + xa = 1600 and x 20,i=1,..0,4. in matrix form the constraints can be written 3 41 Nf x | (1700 250 1)4x |O 160 They consist of 2 eguations in 4 unknowns, Any non-negative solution of these constraints is a feasible solution. 10 Fundamentat ideas Of course with 2 equations ir 4 unknowns we can hope to get a solution (though not necessarily a feasible solution) by giving two of the variables arhitrary values and solving for the remaining two. Of particular interest are solutions of this type which arise by setting two of the variables to zero. Such a solution, if unique, is referred to as a basie solution. If it is also feasible it is a basic feasible solution (b.f.s.). For the general linear programming problem with say m linear equation constraints in n variables (m < n) a basic solution of the constraints is obtained by setting (n - m) of the variables to zero and solving the m equations which result for the remaining m variables, provided these equations have a unique solution. The variables put equal to zero are called the non-basic variables (n.b.v.), The others are the basic variables and form a basis. For the problem just considered we can select the two non-basic variables in (3) = 6 ways. The basic solutions are casily seen to be given by oo mo x 1 0] o| 1700 | 1600l O 2 0 ]425 0 |-525 3 0/320 | 420 0; à 4 Isem | 0 0| 466] C s | 800) 0]-700 [a 6 | 300 |200 º o| B corresponding to non-basic variables (xr, X2), (xt, x3), (xt, xa), (2, X3), (xo, xa), (xa, x4). Of these 6 basic solutions, only 4 are also feasible, and it will be seen thar these solutions correspond to the vertices of the feasible region in Fig. 1.1 with cor- respondence as indicated. In three dimensions the linear constraints take the form of planes (instead of lines). The feasible region, instead of being a convex polygon, is a convex polyhedron, An optimal solution to the problem will correspond to a vertex of this polyhedron since the contours of the objective function will be planes instead of lines, and the plane corresponding to the least value wili generally have just one point in common with the feasible region, and this will be a vertex of the convex polyhedron, and will correspond to an optimai solution of the problem. We shall see that this particular type of result is quite general. The basic feasible solutions of a system of m eguations in 1 unknowns correspond to the vertices of the feasible region. Further an optimal solution, if it exists, corresponds to a basic feasible solution, and hence a vertex of the feasible region. 1.4 Some n-Dimensional Geometry Before establishing the results just mentioned iz is necessary to generalise some geometric concepts from two dimensions to 7 dimensions. The two-dimensional graphical solution method used in Section 1.2 is quite general. However, in x dimen- sions our intuition and ability to visualise the situation is not so clear. We need algebraic methods to do the geometry. Ness qui Lineu ifugitimetias vs We first define some terms which allow the concept of a convex ser to be understood. We use x= | x |to denote a point in a-dimensional space. Xn, The line segment PQ, where P and Q, represented by vectors p and q, are two points, consists of all points of the form bp+(l-b)g; 0P;PsPs are the vertices of the Brst set. The convex hull of two points P;P; is the line segment P,P>. The convex hull of three points is the triangle P;P>Ps, of 4 points the terrahedron P;P;P;P. and of five points the hyperpolyhedron with the five points as vertices. tab Ps Pa Figure 1.6(a) Figure 1.6(b) 1.5 Fundamental Results for Linear Programming In standard form the general linear programming probiem takes he form minimise ESC + C++ Cala Now it is easy to see that provided then the vectors where a= Or are such that 41,%2 2 0. Further since Ae = O An=A( + pa)=44"+040=b Similarly Axo = 5d. 5 o. Thus x, and x; are feasible solutions and xº = j(x; + x2) so that xº is not a vertex. This then leads to a contradiction and we conclude that r is at most m. If there are m constraints in » variables, there are at most (%) basic feasible solutions (and vertices) and the convex hull of these points forms the feasible region. IV If the Objective Function has a Finite Minimum, then at Least One Optimal Solution is a Basic Feasible Solution Let the basic feasible solutions correspond to the points Pr, Pa», ..., Pk with vectors pr Da... pr, and suppose the objective function takes the values 21,22,..., Zk at these points. É Tiz=ex +ex ++ Cn = x u=c'p, for i=i,2..,k For any other point in the feasible region x=0pi+ô2pr+...+0kpe where 620, Lô=]. The value of z at this point is c=cir=00p + Bacipr+... + Ore! pr =Ohz1 + 62x +... + Optu. + Pk which minimises Thus the problem of finding x in the convex hull of P,, Pa, z, reduces to the problem of finding 9; > O such that which minimises Now of the values z1, z2, ..., zk there will be one (or more) that is the minimum. Suppose this is 2; so ihat x; < u fori=1,2,..,k. Thus Z6; which is the weighted average of Z1... 2 with weights 61,62,...,0% will be a minimum when 8,= 1 and 8;= O(i x ;). Thus the minimum of z will arise at the vertex P;. These results mean that in searching for the optimal solution in the feasible region it is only necessary to consider the basic feasible solutions. The Simplex Method of the next chapter is a systematic procedure for doing this. Exercises 1 1 A firm manufactures two products A and B, the market for each being virtually unlimited. Each product is processed on each of the machines 1, II and [II The processing times in hours per item of A or B on each machine are given in the table. I um A OS 04 0.2 B 025 03 0. The available production time of the machines 1, II and III is 40 hours, 36 hours and 36 hours respectively each week. The profit per item of A and B is 55 and $3 respectively. The firm wishes to determine the weekly production of items of A and B which will maximise its profit. Formulate this problem as a linear programming problem and solve it. 2 Maximise w= x +2x% subject to x 20,3% 20 3 Express the problem above in standard form. Show that there are 15 basic solu- tions of which 5 are also feasible. Identify these with the vertices of the feasible region. 4 Minimise z=-2n-» subject to x1 20,x2 20 5 Minimise z=-3x-—% subject to 120,02 o in each of the cases () «=8=1 (db) a=2,8=5 (0) «=6,8= 6. 6 Minimise z=-m-5a subject to X1, X2 20 7 Maximise 3x + 622 + 2X: where X1, X2, X3 20 and Intén+ 32 x+3m+2081 For this three-dimensional problem show that the feasible region is a convex polyhedron and that the optima! solution occurs at à vertex. 8 A firm requires coal with a phosphorus content no more than 0:03% and no more than 325% ash impurity. Three grades of coal À, B, C are available at the prices shown. Grade % Phosphorus Mo Ash Cost($/tonne) A 0-06 2:0 30 B 0:04 40 30 c 0-02 30 45 How should these be blended to meet the impurity restrictions at minimum cost? LHint. If we let one tonne of the blend contain x1, X2, Xa tonnes ofA,B, € respect- ively, x1+ Xp +25=1. Thus this three-dimensional problem can easily be reduced to two-dimensional form by etiminating x3.] 9 Floor cleaning detergents for domestic usage are formulated with three characteristics in mind, (a) cleaning capacity, (b) disinfectant power, (c) skin isrita- tion level. Each of these characteristics is measured on a linear scale 0-100. The market product must have à cleaning capacity of at least 60 units and disinfectant power of at least 60 units as measured on these scales. At the same time it is desired to minímise the skin irritation level. This final product is to be à blend of three basic detergents whose characteristics are derailed below. Basic detergent Cleaning capacity Disinfectant power Trritation level A 30 30 7 B 65 Bs so Cc as 0 10 Formulate the problem of finding the optimum biend as a linear programming prob- lem. Show that this problem can be represented graphically in two dimensions and hence obtain the solution. 10 A frm manufactures two products A and B which are sold at 8 cents and 15 cents per unit respectively, the market for both products being virtually unlimited. A is processed on machine 1, B is processed on machine Y. Then both are packaged at the packing plant (see sketch). Ema 1 ———— ——— Raw material for A e Machine Finished A pat —— 5] Machine 11 Finished 8 Raw material costs 6 cents per kg and is processed at 5000 kg per hour by machine with 10% wastage; it is processed at 4000 kg per hour by machine II and 20% is wasted. Machine [ is available 6 hours a day with a running cost of 5288 per hour; machine IL is available 5 hours a day with a running cost of $336 per hour. Finished units of A weigh !kg and units of B weigh $kg. The packing plant is available 10 hours a day at a cost of 8360 per hour. Units of A can be packed at 12000 per hour whilst units of B are packed at the slower rate of 8000 units per hour. The company wishes to determine those values for x, and Xa, the input (in thousands of kg) of raw material used for the products A and B respectively, so as to maximise daily profit. Formulate this problem as a linear programming problem and calculate the optimal solution graphicaily. Raw material for 8 Lo 1 For the two-dimensional examples of Section 1.2, put each problem into stand- ard form. Find all the basic solutions and show thar the basic feasible solutions can be identifed with the vertices of the feasible region. 12 Ina certain area the need arises for additional transport at two points A and B. Five extra buses are required at À and seven extra buses at B. It is known that 3, 4 and 5 buses can be allocated from three garages Gs, G: and Gs respectively. How should these buses be distributed between A and B in order to minimise the total distance travelled? The distances from garages to À and B are given in the foilowing table: Of course equations (2.4) and (2.3) represent the same constraints, equations (2.5) and (2.1) the same objective function even though the algebraic forms differ. Equa- tions (2.4) and (2.5) are à canonical form for the basis X1, X2, -.., Xm. HE Xm-t Xma 2 e, Xn ATE put equal to Zero, X = bixo = Di ces Xm = Dios Xmei = O, eos a = o is a basic solution. Jf all b/>0, it is a basic feasible solution. The optimum is to be found among such solutions. The Simplex Method provides a systematic pro- cedure for moving from one (feasible) canonical form to another whilst at the same time reducing Z. o 1t should be noted that if the matrix 4 is partitioned as A=(BR) (2.6) where B is them xm matrix of coefficients Of X1, +...» %m and R is an m xt(n > m) matrix (the rest of 4), premultipiication of equations (2.3) by B” gives-equations (2.4). 8! will exist for a basic feasible solution. For (2.3) is (BR) x=b, whence, BBR)x=5"'b, ie. EnBIR) x =b', [which is (2.4) en so that b'=B"'b (2.8) and aj= Bra, for all columns j. (2.9) « Also cj=e- » craiy, É cj= q chaj= c;— EB” ig, (2.10) where cà = (cr Cr, ..., Cm) is the TOW vector of coeffcients of the basic variables in the ariginal form for £, equation (2.1). . . . It is not suggested that these ideas are used to search fora basic feasible solution. Such a search method would be very ineficient. Sometimes a'basic feasible solution is obvious, and this is the case with the example chosen to illustrate the Simplex Method. It is Example 1 of Section 4.1 which has already been soived graphically. Example 1 Subject to X1,42 2 0 and 3x + 4a & 1700 2x1 +5x < 1600 minimise -2x- dm =& In standard form with non-negative slack variables xs and xa the constraints and objective function take the form Imntáodro =1700 2x, +5x% + x4=1600 |. (2.11) -2x,— 4x2 =z Because in this case the b's are positive and the slack variables occur with coeff- cients + 1, it is clear that x = x2 = 0, x3 = 1700, xs = 1600 is a basic feasible solution and equations (2.11) the appropriate canonical form. z is expressed in terms of the non-basic variables. They have value zero and z has value zero. How can we decrease 2? Since x and x: must be non-negative any change in their values must be an increase. Because they have negative coefhcients in the canonical form for z any such increase wi!) decrease z. Rather than increase them both we adopt the simpler strategy Of increasing just one of them. Since xz bas the most negative coefhcient we choose x». This would appear to be the most rapid way of decreasing 7. However, if we increase x», the values of x; and x4 will change since we must satisfy equations (2.11). All values must also remain non-negative. Thus there will be a limit on the amount by which we can increase xs. For 3x1 +42 + 2x1 = 1700 xs is made zero when m= um =425. For 2x1+ 5x + xa = 1600 xy is made zero when noi 320, Thus we cannot increase x; beyond 320 (the minimum of these values) without violating the non-negativity condition on x4 The second constraint can be written (on division by 5, the coefficient of x2) as Erro + fu =320. 1f we subtract 4 times this from the first constraint in equations (2.11) (the *4 is the coefhcient of x> in this constraint) and — 4 times this from the objective function (the '—4º is the coefficient of x> in the objective) we eliminate eliminate x2 from everywhere except the second constraint where it has coefhcient 1. The constraínts and objective function then appear as im +, —$xa=420 ima + 1x, = 320 (2.12) -in +5xu=2+ 1280 which is a canonical form for the basis xa, xs which represents a basic feasible solution. The non-basic variables are x, and x4. They are currently zero. In this case it is oniy by increasing x that we decrease z. By how much can we increase x1 whilst still keeping x> and xs non-negative? For Do +as-ix=420 0.300. xs is made zero when us ane dUHpres cneieuu For êxito +:x4=320 320 x> is made zero when x = = 800. 7 Thus we cannot increase x: above 300 (the minimum of these). On division by 5 (the coefficient of x) the first constraint becomes ot ixs—i xa =300. We eliminate x, from the other constraint and the objective function by subrracting Zand -? times this from the constraint and objective to obtain a canonical form for the basis x1, x2 which is also feasible. It is x +5x—$xk=300 xo— 3x3 +23 x4=200 . (2.13) ixg+ixa=7+ 1400 At this stage it will be observed that increases in either of the non-basic variables 3, X4, Which both have positive coefficients in the form for z, will increase z. Thus à is not possible to reduce 2 further and we have reached the minimum of z which is — 1400 at the basic feasible solution x1 = 300, x2 = 200, x; = x4 = 0. If we look back to the geometrical solution of Fig. 1.1 we can see that the successive canonical forms have taken us from O to À to B, the minimum point. The reader is urged to verify that had we chosen to increase x; in equations (2.11) the procedure would have taken us from O to C to B. The caiculations of this iteralive process can be set out conveniently in the so called Simplex Tableaux. These are read just as equations (2.11), (2.12), (2.13) for the constraints. The objective function has been written as —-7— 2x, —4x,=0; 2-3 + fx = 1280; -2 +22, + 3x4 = 1400, in the three tableaux which now follow. leration Basis Valve x x EE 0 * 1700 3 4 1 . % 1600 2 5 . t -1 o |-2 1-4 1 E 420 EM . e RR * 320 3 1 E) - 1280 | -& E 2 x 300 1 sos E 200 . 1 -3 1 -: 1400 E É! At iteration O we asterisk the value 5, the coefficient of the variable about to become basic in the critical constraint. At iteration 1 it is the number ; as shown. Note also the use of dots for zeros which have to be zero as opposed to just turning ouz to be zero. We can generalise the results just obtained in this particular example. We assume that we have an initial canoniçal form and that at iteration k have reached the canonical form given by equations (2.4) and (2.5) which in tableau form can be written as follows. feration Basis Value x x * Xm Xmel x *%y x] bi O O Gino ais ain x | «a . = | amei ais dia k x | «tetoda “À Um [a ai Xm | bi do. 1 | aims ais Em =z =% - - - Cm-1 co € There are 3 stages in the iterative process. I Find the Variable to Enter rhe Basis The variables xm-1,..., xa are non-basic. We find the smallest of ca. t,..., Ci ««v Cn. Suppose this is cs. If c; is negative then increasing x, will decrease z. Thus we adopt the convention, if several of cj are negative, of choosing the most negative. This is reasonabie but not essential. Any negative c/ will do. Of course if cris 20 then z cannot be decreased any more and we have the minimum. 1 Find the Variable to Leave the Basis By how much can we increase x, without violating the non-negativity conditions on the current basic variables? In the ith constraint, if aí > O the larges: value that can be given to x, is bi/aís, otherwise x, wili become negative. (N.B. If ai; O the basic variable x; will increase as x; increases.) Thus x; can be increased (o the value b; max x,= min ( dsloem 2450 ). (2.14) Gis If this minimum occurs in row , x, is made zero when x, is given the value b;/a;,. The other basic variables will stay positive. a; is called the pivot element, row 7 the pivot row, column s the pivot column. Hi Construct the New Canonical! Form The new basis is X4, X2, ..., Xs,..., Xm the variable x, having become non-basic. To construct the new canonical form we make the coefhicient of xs in the pivot row unity by dividing this row by a; to form the new pivor row. Next we eliminate x, from the other constraints and the objective function. Thus for the ith row (i = r)in which x; has coefficient aí we subtract aí x (new pivot row) The second tableau which is computed in the usual way is also shown. K corresponds to the point B in Fig. 1.4. z can be further decreased by increasing xa. But now we come to a problem. There are no strictly positive coefficients in the xs columm in the constraints. Thus, however much we increase x» we will never drive a basic variable to zero; indeed x; will be increased and x» will remain unchanged. We have a case of an unbounded solution which is quite clear from Fig. 1.4. It manifests itself in the Simplex Method through the fact that ali ai; < O. 2.2 Ymplementing the Simplex Method on the Computer The computationa! procedure of the Simplex Method is an iterative process. It would, however, be very tedious if the probiem contained several variables and con- straints. Many practical problems have tens of variables and constraints (some many more), and it is clear that it will not be reasonabie to tackle such problems by way of a hand calculation. But the Simplex Method is a method for the computer. It is no accident that the theoretical developments of linear programming coincided in time with the development of the computer. Without the latter the theory would have had little scope for real applications. The procedures of the last section can be put in the form of a flow chart for the computation, which can in tum be coded as a computer program. The iterative routine consists essentially of three steps. First we find the min c/=c; (<0) to locate the variable to enter the basis. Then the row of the basic j variable to leave the basis is found from (2.21) max X = as>0 This of course is the result (2.14). Finally we find the next canonical form in accordance with equations (2.15)... (2.20). The program listing follows the flow chart and uses the notation that has been adopted in the text. PROGRAM Simplex (input ,outpuc); CONST m=2: n=4; £ Mo. of constraints and total no. of variables ) fut=8; dpt-2; ( Output format conscants for tableau values | fwi=l; [ Output format constant for indices ) largevalue = 1.0E20; smallvalue = 1.0E-10; TYPE mrange = l..m; nrange = 3 matrix = ARRAY [mrange,nrange] OF real; column = ARRAY [mrange] OF REAL; baseindex = ARRAY [mrange] OF integer; row = ARRAY Ínrange] OF real; rowboolean = ARRAY [nrange] OF boolean; Flow Chart for Simplex Method given an initial Canonical Form problem | Read coefficients in cananical foem, í basic variahies and set non-basit variables, Find sos Yves nc | optimum at sc; =0? pi) T— Fo Sop À | ves Find min. af &; wenich is 4/45, Compute new canonveai form and change basis Lol Ss VAR a: matrix: ( Matrix A ín standard form of problem, see (2.3) ) b : colum:; ( Vector b in standard fora of problem, see (2,3) ) c + row; ( Coef£icients of objective function, see (2.1) | baste : baseindex; f Basic variables at each stage | nonbasic : romboolean; ( Status indicators for variables | 20 : real; | Value of objective function ) it : integer; ( Iteration counter ) solution, unbounded : boolean; — ( Iteration process terminators ) r, 8: integer; Row and colum of pivot element | PROCEDURE inputdatas; VAR à, j: integer; BEGIN FOR i:=l TO m DO BEGIN FOR j:=1 TO n DO read(al1,3]); read(b[i]) END; FOR j:=L TO n DO read(c[3]); read(20); FOR j:=1 TO m DO read(basicl1]); ( Inítial base + END; ( inputdata ) PROCEDURE initialise; var À, j: integer; BEGIN 1t:=0; solution:=false; unbounded:-false; FOR j:=1 TO n DO nonhasic[jl:=true; FOR i:=| TO m DO nonbasicíbasic[i]):=false END; ( initialise ) PROCEDURE outputtableau; VAR À, ): integer; BEGIN writeln; writeln(” ITERATION 7, it:2); wríte(” BASE VAR. C,T TIÉwt-5, VALUES); FOR j:=l TO n DO write(” Cifut-êwi-i, CX", j:Éwi); uritela; FOR 4:=1 TO m DO BEGIN write(” FOR j:=1 TO n DO write(ali,jl:fw END; write(” Ci], C=20, 0 57, 20:wtidpt); FOR $:=1 TO n DO write(cljl:futidpt); writeln END; | outputtableau ) :B-Ewi, “Xº, basicliJ:fwi, “ “27, bIilifwr:dpt); pt); writela PROCEDURE nexcbasisvariable (VAR resiinteger); VAR 1, j: integer; min: ceal; BEGIN min:=largevalue; ( Find che variable, s, | FOR j:=1 TO n DO f to enter the basis. |) 1F nonbasic(j] THEN IF cljl -smallvalue; IF NOT solution THEN BEGIN unbounded:=true; i:=l; ( Check that at least one value WHILE unbounded AND (i<=m) DO ( in colum s is positive. BEGIN unbounded := ali,s] < smallvalue; iisítl END; LF NOT unbounded THEN H 1) ! BEGIN min:slargevalue; ( Find the variable, basiclr], FOR í:=! TO m DO ( to leave the basis. , IF a[i,s] > smallvalue THEN IF bfil/ali,s] < min THEN BEGIN min:=b[i]/a[í,s]; ri=i END; monbasic[basiclr]|:=true; nonbasic(s]i=faise; basic(r]:=5; writelo; writein(” PIVOT IS AT ROM”, rifui, ” COL", stfuwi) END END END 4 nextbasicvariable ) PROCEDURE transformtableau (r,siinteger); ( Construct the new canonical form, implementing (2.15) to (2.20) ) VAR 1, j: integer; pivot, savec : real; savecol : colum; BEGIN FOR ii=l TO m DO savecol[1]:=a[i,s]; saveciscis]; bEr]i=blc]/pivor; 462.153) à To n DO ale,jlisalr,jl/pivot; ((2.16)) =1 TO m DO 1F i
Docsity logo

Copyright © 2026 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved