Linear programming
First of all, generally all linear programming problems can be converted to the following standard type :
But we can see that all of these are inequalities, and we prefer the equation in our calculations, so we introduce this new concept: slack type :
It is clear that our final request is that all constraints to the left of the variable are not less than 0. To solve such problems, we have a very convenient model algorithm: simplex
Base variable : All variables to the left of the relaxed equation
non-base variable : All variables to the right of the relaxed equation
Basic Solution : A set of base variables and non-base variables contains a set of basic solutions, that is, all non-base variables are 0, the base variable is the right side of the constant term (this requires constant term is positive, negative when we discuss later)
Algorithm principle:
The solution space of the programmable linear programming is a convex region, which means that the global optimal solution is only one, or there are multiple parallel optimal solutions. By the nature of the above, we can know that the local optimal solution is the global optimal solution, which is the simplex algorithm idea.
Algorithm process:
Pivot operation: Select a base variable and a non-base variable to swap it
Simplex operation: The main process, starting from a basic solution, through a series of rotating shaft operation, to find the optimal solution
Example:
Solve the following problems:
First step: Interchange X1 and X6
Step two: Interchange X3 and X5
The third step: Interchange X2 and X3
At this point we get the basic solution: (x1, x2, X3, X4, x5, x6) = (8, 4, 0, 18, 0, 0), easy to verify is the final optimal solution
Algorithm pseudo-code:
1 defSimplex (A, B, c):2 initialization (A, B, c)3 whileThere isE that Ce >0 Do:4Find the index L that Ale > 0 andMinimizes bi/Ale5 ifAll L, Ale <=0 Then:6 returnunbounded7 Else:8Pivot (A, B, C, L, E)
Where we find that there is a "initialization" function that is used to process our bi<0, it is done by introducing an auxiliary linear programming :
After a rotating axis operation, the L constraint becomes:
The rest becomes:
Ishi at this time is not less than 0 for the new bi satisfaction
Duality problem
Defined:
Using matrices to represent more image, but also more conducive to our later calculation and understanding:
Therefore, we can consider the mutual transformation between them in the face of such problems. Here is no proof of the theorem:
Two groups of optimal solutions for mutual duality problems
Subsequent update of the Python implementation of the simplex algorithm ...
Linear programming (simplex simplex) and duality problem