Package org.ssclab.pl.milp
Class LP
- java.lang.Object
-
- org.ssclab.pl.milp.LP
-
- All Implemented Interfaces:
FormatTypeInput
public final class LP extends java.lang.Object implements FormatTypeInput
This class allows executing and solving formulations of linear programming problems. The method used for solving such optimization problems is the simplex method.- Version:
- 4.0
- Author:
- Stefano Scarioli
- See Also:
- SSC Software www.sscLab.org
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ssclab.pl.milp.FormatTypeInput
FormatTypeInput.FormatType
-
-
Field Summary
Fields Modifier and Type Field Description static double
NaN
-
Constructor Summary
Constructors Constructor Description LP(java.lang.String path)
LP(java.util.ArrayList<java.lang.String> inequality)
LP(LinearObjectiveFunction fo, java.util.ArrayList<Constraint> constraints)
Constructor Creates an LP object for solving problems expressed in matrix format.LP(LinearObjectiveFunction fo, ListConstraints constraints)
Constructor of an LP object for solving problems expressed in matrix format.LP(org.ssclab.ref.Input input_natural)
Constructor of an LP object for solving problems expressed in coefficient format.LP(org.ssclab.ref.Input input_natural, org.ssclab.context.Session session)
Constructor of an LP object for solving problems expressed in coefficient format.LP(org.ssclab.ref.Input input, org.ssclab.context.Session session, FormatTypeInput.FormatType format)
Constructor of an LP object for solving problems expressed in sparse format or coefficient format.LP(org.ssclab.ref.Input input, FormatTypeInput.FormatType format)
Constructor of an LP object for solving problems expressed in either sparse or coefficient format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getNumMaxIteration()
This method returns the maximum number of simplex iterationsSolution
getSolution()
If the problem has an optimal solution, this method returns that optimal solution in the form of an object of the Solution class.double[][]
getStandartMatrixA()
This method returns the matrix A obtained after the process of reduction to standard form (max z , Ax + s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.double[]
getStandartVectorB()
This method returns the vector b of the rhs values obtained after the process of reduction to standard form(max z , Ax+s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.double[]
getStandartVectorC()
This method returns the vector c of the coefficients of the objective function after the process of reduction to standard form (max z , Ax+s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.LPThreadsNumber
getThreadsNumber()
double[]
getValuesSolution()
If the problem has an optimal solution, this method returns that optimal solution in the form of an array with the values of the variables.boolean
isJustTakeFeasibleSolution()
Returns true if only phase 1 execution is set to obtain a feasible solution.boolean
isParallelSimplex()
SolutionType
resolve()
Executes the simplex (phase 1 + phase 2).void
setCEpsilon(EPSILON epsilon)
This method allows setting the epsilon value relative to the tolerance in determining if an optimal solution expressed by phase 1 is close to or equal to zero and thus gives rise to feasible solutions for the initial problem.void
setEpsilon(EPSILON epsilon)
This method allows setting the epsilon value relative to the tolerance that intervenes in various contexts.void
setJustTakeFeasibleSolution(boolean isStopPhase2)
Setting to true allows interrupting the simplex at the end of phase 1, in order to determine not an optimal solution but only a feasible solution of the problem.void
setNumMaxIteration(int num_max_iteration)
This method allows limiting the maximum number of simplex iterations (phase 1 iterations + phase 2 iterations)void
setParallelSimplex(boolean isParallelSimplex)
If the number of physical cores of the host on which SSc is running is greater than 4, the performance of the simplex can be improved by executing the optimization processes in parallel on multiple threads.void
setThreadsNumber(LPThreadsNumber threadsNumber)
If the set value is AUTO, the system decides the number of threads to use.
-
-
-
Constructor Detail
-
LP
public LP(java.util.ArrayList<java.lang.String> inequality) throws java.lang.Exception
- Parameters:
inequality
- An ArrayList (of String objects) containing the problem formulation in the form of inequalities- Throws:
java.lang.Exception
- An exception is thrown if the problem is not correctly formulated
-
LP
public LP(java.lang.String path) throws java.lang.Exception
- Parameters:
path
- The path where the file containing the LP problem formulated with the inequality format is located- Throws:
java.lang.Exception
- An exception is thrown if the problem is not correctly formulated or if the file does not exist
-
LP
public LP(LinearObjectiveFunction fo, java.util.ArrayList<Constraint> constraints) throws java.lang.Exception
Constructor Creates an LP object for solving problems expressed in matrix format.- Parameters:
fo
- A LinearObjectiveFunction object representing the objective functionconstraints
- The list of constraints expressed as an ArrayList of Constraint objects- Throws:
java.lang.Exception
- An exception is thrown if the problem is not correctly formulated
-
LP
public LP(LinearObjectiveFunction fo, ListConstraints constraints) throws java.lang.Exception
Constructor of an LP object for solving problems expressed in matrix format.- Parameters:
fo
- A LinearObjectiveFunction object representing the objective functionconstraints
- The list of constraints as a ListConstraints object- Throws:
java.lang.Exception
- An exception is thrown if the problem is not correctly formulated
-
LP
public LP(org.ssclab.ref.Input input, org.ssclab.context.Session session, FormatTypeInput.FormatType format) throws java.lang.Exception
Constructor of an LP object for solving problems expressed in sparse format or coefficient format.- Parameters:
input
- The problem formulated in sparse format or coefficient formatsession
- An SSC working sessionformat
- Constant to express in which format the problem is formulated (FormatType.SPARSE or FormatType.COEFF)- Throws:
java.lang.Exception
- An exception is thrown if the problem is not formulated correctly
-
LP
public LP(org.ssclab.ref.Input input, FormatTypeInput.FormatType format) throws java.lang.Exception
Constructor of an LP object for solving problems expressed in either sparse or coefficient format.- Parameters:
input
- The problem formulated in sparse formatformat
- Constant to express in which format the problem is formulated (FormatType.SPARSE or FormatType.COEFF)- Throws:
java.lang.Exception
- An exception is thrown if the problem is not formulated correctly
-
LP
public LP(org.ssclab.ref.Input input_natural) throws java.lang.Exception
Constructor of an LP object for solving problems expressed in coefficient format.- Parameters:
input_natural
- The problem formulated in coefficient format- Throws:
java.lang.Exception
- An exception is thrown if the problem is not formulated correctly
-
LP
public LP(org.ssclab.ref.Input input_natural, org.ssclab.context.Session session) throws java.lang.Exception
Constructor of an LP object for solving problems expressed in coefficient format.- Parameters:
input_natural
- The problem formulated in coefficient formatsession
- An SSC working session- Throws:
java.lang.Exception
- An exception is thrown if the problem is not formulated correctly
-
-
Method Detail
-
setEpsilon
public void setEpsilon(EPSILON epsilon)
This method allows setting the epsilon value relative to the tolerance that intervenes in various contexts. It is used in the following cases:
During phase one, both in determining the entering variable and in determining the exiting variable with or without the Bland rule; it is also used to determine if the base is degenerate. It is also used at the end of phase one: if there is an auxiliary variable in the base, epsilon is used to determine if it is possible to eliminate the rows and columns of these on the extended table.
During phase two, both in determining the entering variable and in determining the exiting variable with or without the Bland rule; it is also used to determine if the base is degenerate.- Parameters:
epsilon
- Tolerance used in various phases of the simplex. Default value 1E-10
-
setCEpsilon
public void setCEpsilon(EPSILON epsilon)
This method allows setting the epsilon value relative to the tolerance in determining if an optimal solution expressed by phase 1 is close to or equal to zero and thus gives rise to feasible solutions for the initial problem.- Parameters:
epsilon
- Tolerance of phase 1 solution with respect to zero. Default value 1E-8
-
setNumMaxIteration
public void setNumMaxIteration(int num_max_iteration) throws LPException
This method allows limiting the maximum number of simplex iterations (phase 1 iterations + phase 2 iterations)- Parameters:
num_max_iteration
- The maximum number of iterations to be executed. Default value 10,000,000.- Throws:
LPException
- If an incorrect number (zero or negative) is set
-
getNumMaxIteration
public int getNumMaxIteration()
This method returns the maximum number of simplex iterations- Returns:
- The maximum number of iterations
-
resolve
public SolutionType resolve() throws java.lang.Exception
Executes the simplex (phase 1 + phase 2).- Returns:
- The type of solution found
- Throws:
java.lang.Exception
- If the execution process generates an error
-
getStandartMatrixA
public double[][] getStandartMatrixA() throws org.ssclab.pl.milp.simplex.SimplexException, java.io.IOException
This method returns the matrix A obtained after the process of reduction to standard form (max z , Ax + s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.- Returns:
- The coefficient matrix A
- Throws:
org.ssclab.pl.milp.simplex.SimplexException
- If null matrixjava.io.IOException
- if the problem has not been reduced to standard form
-
getStandartVectorB
public double[] getStandartVectorB()
This method returns the vector b of the rhs values obtained after the process of reduction to standard form(max z , Ax+s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.- Returns:
- The vector of RHS coefficients
-
getStandartVectorC
public double[] getStandartVectorC()
This method returns the vector c of the coefficients of the objective function after the process of reduction to standard form (max z , Ax+s=b, x ≥ 0, b ≥ 0) of the original linear programming problem.- Returns:
- The vector c of the coefficients of the objective function.
-
getSolution
public Solution getSolution() throws org.ssclab.pl.milp.simplex.SimplexException
If the problem has an optimal solution, this method returns that optimal solution in the form of an object of the Solution class.- Returns:
- The optimal solution of the problem
- Throws:
org.ssclab.pl.milp.simplex.SimplexException
- If the optimal solution is not present
-
getValuesSolution
public double[] getValuesSolution() throws org.ssclab.pl.milp.simplex.SimplexException
If the problem has an optimal solution, this method returns that optimal solution in the form of an array with the values of the variables.- Returns:
- The optimal solution of the problem as an array of double values
- Throws:
org.ssclab.pl.milp.simplex.SimplexException
- If the optimal solution is not present
-
isParallelSimplex
public boolean isParallelSimplex()
- Returns:
- true if the parallelization with multiple threads of the simplex is active.
-
setParallelSimplex
public void setParallelSimplex(boolean isParallelSimplex)
If the number of physical cores of the host on which SSc is running is greater than 4, the performance of the simplex can be improved by executing the optimization processes in parallel on multiple threads.- Parameters:
isParallelSimplex
- True to activate parallelization
-
getThreadsNumber
public LPThreadsNumber getThreadsNumber()
- Returns:
- the number of threads used in the execution. If the value is AUTO, the system decides the number of threads to use.
-
setThreadsNumber
public void setThreadsNumber(LPThreadsNumber threadsNumber)
If the set value is AUTO, the system decides the number of threads to use.- Parameters:
threadsNumber
- Sets the number of threads to use in the execution.
-
isJustTakeFeasibleSolution
public boolean isJustTakeFeasibleSolution()
Returns true if only phase 1 execution is set to obtain a feasible solution.- Returns:
- true if active
-
setJustTakeFeasibleSolution
public void setJustTakeFeasibleSolution(boolean isStopPhase2)
Setting to true allows interrupting the simplex at the end of phase 1, in order to determine not an optimal solution but only a feasible solution of the problem.- Parameters:
isStopPhase2
- true to interrupt the simplex before phase 2.
-
-