0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
17 visualizzazioni4 pagine
This library is used to solve linear programming problems using the 2 phase simplex algorithm. It can solve a 8 variables by 5 constraints problem in less than 7 seconds. This is over 50% better than the original userRPL / sysRPL version.
This library is used to solve linear programming problems using the 2 phase simplex algorithm. It can solve a 8 variables by 5 constraints problem in less than 7 seconds. This is over 50% better than the original userRPL / sysRPL version.
This library is used to solve linear programming problems using the 2 phase simplex algorithm. It can solve a 8 variables by 5 constraints problem in less than 7 seconds. This is over 50% better than the original userRPL / sysRPL version.
Documentation *************************************************************************** Table of Contents: 1. Introduction 2. Command Reference 3. Example: Using SLACK to convert standard forms. 1. Introduction This library is used to solve linear programming problems using the 2 phase simplex algorithm. I find it very fast, it can solve a 8 variables by 5 constraints problem in less than 7 seconds performing 5 iterations on the tableau. This is over 50% better than the original userRPL/sysRPL version. The problem this program is intended to solve is of the form, min c.x st A.x = b (* b must be greater than zero *) x >= 0 The way the problem is entered is as a matrix of the following form, [[ c | 0 ] [---+----] [ A | b ]] For example, to solve the following problem max x1 + 2 x2 + x3 st x1 + x2 <= 3 x1 - x2 + x3 <= 3 x2 + x3 <= 3 x1 + x2 + x3 >= 3 x2 <= 2 x1, x2, x3 >=0 We convert it to the standard form min - x1 - 2 x2 - x3 st x1 + x2 + x4 = 3 x1 - x2 + x3 + x5 = 3 x2 + x3 + x6 = 3 x1 + x2 + x3 - x7 = 3 x2 + x8 = 2 x1, x2, x3 >= 0 And write it as a matrix to enter it in the program. [[ -1 -2 -1 0 0 0 0 0 0 ] [ 1 1 0 1 0 0 0 0 3 ] [ 1 -1 1 0 1 0 0 0 3 ] [ 0 1 1 0 0 1 0 0 3 ] [ 1 1 1 0 0 0 -1 0 3 ] [ 0 1 0 0 0 0 0 1 2 ]] To solve the problem right away, just enter the matrix, press the [INIT] key which initializes the variable 'LPdat' in the current directory. Then press the [SOLVE] key which iterates and gives the solution in three parts as follows, 3: :\Gl: [ -1 0 -1 0 0 ] 2: :Z: -6 1: :X: [ 2 .999999999998 2 0 0 0 2 1 ] Where x is the actual point that minimizes the problem, the \Gl (lambda) is the solution to the dual problem or shadow prices of each of the constraints, and Z is the objective function value at the point found to be the minimum. This is the end of the quick start procedure to solve linear programs (LP) with this program. Now lets go to some details... The solution of an LP can be classified into, infeasible, when there is no point satisfying the set of constraints unbounded, when the set of constraints can not restrict the decrease of the objective function (c.x) feasible & bounded, when there is a solution to the set of constraints which minimizes the objective function value. The problem can handle all three cases, giving the solution when it is feasible and bounded, providing a ray (which is a vector through which you can infinitely decrease the objective function while remaining in the feasible region) when the solution is unbounded, or flagging that there is no feasible solution. To achieve the different solutions, the program goes through the two phase simplex method automatically (you don't have to include artificial variables). Phase 1 is used to derive a starting basic feasible solution by introducing a set of artificial variables with the objective of minimizing its sum; when this is achieved, the set of artificial variables is removed and Phase 2 starts with the original objective function. (Refer to any LP book for more details on the 2 phase simplex method.) One important thing to notice, is that the columns corresponding to the artificial variables, although not taken into account on phase 2, are not removed from the problem because it is sometimes useful to have these columns at the end of the problem in order to perform sensitivity analysis. The basic algorithm that I used to solve the problem is a pseudo revised simplex method, where all that is maintained is the inverse of the base, the set of basic and non basic variables, and the rest of the data provided at the initialization process. I think this is the most efficient procedure in terms of time because it requires less computations... 2. Command Reference Now it will give a brief explanation of what the programs in the directory do. This first set of programs are the ones intended to be used directly to solve the problem, [INIT] Initializes the set of variables that are needed by the program. [TABL] Extract the current tableau from the problem. [TRACE] Performs one iteration at a time, it is equivalent to solve, but you can take a look at the partial tableaus that are generated by the procedure. If the LP is solved then the solution is returned to the stack. [SOLVE] Gives the answer to the LP if it exists. [SLACK] ( 1: array -> 1: array) Adds a slack variable to each constraint ( 2: array 1: list -> 1: array) Adds a slack variable to each constraint in list. Constraints are numbered from 1 (meaning the second row of the matrix is the first constraint). [NEWV] ( 3: problem (m+1xn+1 array) 2: consts of new vars (1xp array) 1: constraint coeffs of new vars (pxm array) -> 1: new problem (m+1xn+p+1 array) ) Adds variables to a problem. [ABOUT] Minimalist about screen. 3. Example: Using SLACK to convert standard forms. The library requires problems to be in the standard form: min c.x (1) st A.x = b Using standard tricks, one can transform any LP problem into this form. However, many textbooks teach with a standard from: min c.x (2) st A.x <= b In order to facilitate transforming (2) into (1), I have included the SLACK function. The problem max 10 x1 + 20 x2 + 15 x3 st 2 x1 + 3 x2 + 4 x3 <= 1000 x1 + x2 + x3 <= 400 x1 + 3 x2 + x3 <= 480 when written in stanard form (2) yields c = [[ -10 -20 -15 ]] A = [[ 2 3 4 ] [ 1 1 1 ] [ 1 3 1 ]] b = [[ 1000 ] [ 400 ] [ 480 ]] Enter this as a single big matrix on the stack: [[ c | 0 ] [ A | b ]] which is [[ -10 -20 -15 0 ] [ 2 3 4 1000 ] [ 1 1 1 400 ] [ 1 3 1 480 ]] This is the matrix describing the problem in standard form (2). In order to convert it into standard form (1), press SLACK with this problem on the stack. SLACK ( 1: arry -> 1: arry ) - Converts a problem from standard form (2) into standard form (1) by adding slack variables to every constraint. After executing SLACK with the above problem, the equivalent problem in standard form (1) is on the stack: [[ -10 -20 -15 0 0 0 0 ] [ 2 3 4 1 0 0 1000 ] [ 1 1 1 0 1 0 400 ] [ 1 3 1 0 0 1 480 ]] This problem can now be solved by pressing INIT to initialize the solver. Then pressing SOLVE ( or repeatedly pressing TRACE ) to solve the problem. The optimal solution is placed on the stack after the problem is solved: lambda: [ -2.49999999998 -1.25000000005 -3.74999999998 ] Z: -4799.99999999 X: [ 280 39.9999999997 79.9999999998 0 0 0 ] Which says that the optimal solution to the original maximization problem has value 4800 when x1 = 280, x2 = 40, x3 = 80. If the numeric inaccuracy is upsetting, the solver will look for a variable called ZERO and round off every operation to the accuracy stored there. The value in ZERO is interpreted in two ways: if it is an integer, the value represents the number of places to the left of the radix; if it is a float, the operations are rounded to the same number of places as EXP(ZERO). Suppose we want all arthmatic to be performed to 5 places. Store either -5 or .00001 in ZERO. Now, reenter the problem matrix, INIT then SOLVE. The optimal solution is displayed: lambda: [ -2.5 -1.25 -3.75 ] Z: -4800 X: [ 280 40 80 0 0 0 ]