Documentation
¶
Index ¶
- func ConstraintIsRedundantGivenOthers(constraint symbolic.Constraint, constraints []symbolic.Constraint) bool
- func ToSymbolicConstraint(inputConstraint optim.Constraint) (symbolic.Constraint, error)
- type ObjSense
- type Objective
- type OptimizationProblem
- func (op *OptimizationProblem) AddBinaryVariable() symbolic.Variable
- func (op *OptimizationProblem) AddBinaryVariableMatrix(rows, cols int) [][]symbolic.Variable
- func (op *OptimizationProblem) AddBinaryVariableVector(num int) symbolic.VariableVector
- func (op *OptimizationProblem) AddRealVariable() symbolic.Variable
- func (op *OptimizationProblem) AddVariable() symbolic.Variable
- func (op *OptimizationProblem) AddVariableClassic(lower, upper float64, vtype symbolic.VarType) symbolic.Variable
- func (op *OptimizationProblem) AddVariableMatrix(rows, cols int, lower, upper float64, vtype symbolic.VarType) symbolic.VariableMatrix
- func (op *OptimizationProblem) AddVariableVector(dim int) symbolic.VariableVector
- func (op *OptimizationProblem) AddVariableVectorClassic(num int, lower, upper float64, vtype symbolic.VarType) symbolic.VariableVector
- func (op *OptimizationProblem) Check() error
- func (op *OptimizationProblem) CheckIfLinear() error
- func (op *OptimizationProblem) Copy() *OptimizationProblem
- func (op *OptimizationProblem) CopyVariable(variable symbolic.Variable) symbolic.Variable
- func (op *OptimizationProblem) IsLinear() bool
- func (op *OptimizationProblem) LinearEqualityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error)
- func (op *OptimizationProblem) LinearInequalityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error)
- func (op *OptimizationProblem) MakeNotWellDefinedError() ope.NotWellDefinedError
- func (op *OptimizationProblem) SetObjective(e symbolic.Expression, sense ObjSense) error
- func (op *OptimizationProblem) SimplifyConstraints()
- func (op *OptimizationProblem) String() string
- func (problemIn *OptimizationProblem) ToLPStandardForm1() (*OptimizationProblem, []symbolic.Variable, ...)
- func (problemIn *OptimizationProblem) ToLPStandardForm2() (*OptimizationProblem, []symbolic.Variable, ...)
- func (op *OptimizationProblem) ToProblemWithAllPositiveVariables() (*OptimizationProblem, map[symbolic.Variable]symbolic.Expression, error)
- func (op *OptimizationProblem) WithAllPositiveVariableConstraintsRemoved() *OptimizationProblem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstraintIsRedundantGivenOthers ¶ added in v0.5.5
func ConstraintIsRedundantGivenOthers( constraint symbolic.Constraint, constraints []symbolic.Constraint, ) bool
func ToSymbolicConstraint ¶
func ToSymbolicConstraint(inputConstraint optim.Constraint) (symbolic.Constraint, error)
ToSymbolicConstraint Description:
Converts a constraint in the form of a optim.Constraint object into a symbolic.Constraint object.
Types ¶
type ObjSense ¶
type ObjSense string
ObjSense represents whether an optimization objective is to be maximized or minimized. This implementation conforms to the Gurobi encoding
const ( SenseMinimize ObjSense = "Minimize" SenseMaximize = "Maximize" SenseFind ObjSense = "Find" )
Objective senses (minimize and maximize) encoding using Gurobi's standard
func ToObjSense ¶
ToObjSense Description:
This method converts an input optim.ObjSense to a problem.ObjSense.
type Objective ¶
type Objective struct { symbolic.Expression Sense ObjSense }
Objective represents an optimization objective given an expression and objective sense (maximize or minimize).
func NewObjective ¶
func NewObjective(e symbolic.Expression, sense ObjSense) *Objective
NewObjective returns a new optimization objective given an expression and objective sense
func (*Objective) IsLinear ¶ added in v0.5.1
IsLinear Description:
This method returns true if the objective is linear, false otherwise.
func (*Objective) SubstituteAccordingTo ¶ added in v0.5.5
func (o *Objective) SubstituteAccordingTo(replacementMap map[symbolic.Variable]symbolic.Expression) *Objective
SubstituteAccordingTo Description:
Substitutes the variables in the objective according to the replacement map.
type OptimizationProblem ¶
type OptimizationProblem struct { Name string Variables []symbolic.Variable Constraints []symbolic.Constraint Objective Objective }
OptimizationProblem represents the overall constrained linear optimization model to be solved. OptimizationProblem contains all the variables associated with the optimization problem, constraints, objective, and parameters. New variables can only be created using an instantiated OptimizationProblem.
func From ¶
func From(inputModel optim.Model) (*OptimizationProblem, error)
From Description:
Converts the given input into an optimization problem.
func GetExampleProblem3 ¶ added in v0.5.3
func GetExampleProblem3() *OptimizationProblem
GetExampleProblem3 Description:
Returns the LP from this youtube video: https://www.youtube.com/watch?v=QAR8zthQypc&t=483s It should look like this: Maximize 4 x1 + 3 x2 + 5 x3 Subject to x1 + 2 x2 + 2 x3 <= 4 3 x1 + 4 x3 <= 6 2 x1 + x2 + 4 x3 <= 8 x1 >= -1.0 x2 >= -1.0 x3 >= -1.0
func GetExampleProblem4 ¶ added in v0.5.5
func GetExampleProblem4() *OptimizationProblem
GetExampleProblem4 Description:
Returns the LP from this youtube video: https://www.youtube.com/watch?v=QAR8zthQypc&t=483s It should look like this: Maximize 4 x1 + 3 x2 + 5 x3 Subject to x1 + 2 x2 + 2 x3 <= 4 3 x1 + 4 x3 <= 6 2 x1 + x2 + 4 x3 <= 8 x1 >= 0 x2 >= 0 x3 >= 0
func GetExampleProblem5 ¶ added in v0.5.5
func GetExampleProblem5() *OptimizationProblem
GetExampleProblem5 Description:
Returns the LP from this youtube video: https://www.youtube.com/watch?v=QAR8zthQypc&t=483s It should look like this: Maximize 4 x1 + 3 x2 + 5 x3 Subject to x1 + 2 x2 + 2 x3 <= 4 3 x1 + 4 x3 <= 6 2 x1 + x2 + 4 x3 <= 8 x1 >= 0 x2 >= 0 x3 >= 0
func NewProblem ¶
func NewProblem(name string) *OptimizationProblem
NewProblem returns a new model with some default arguments such as not to show the log and no time limit.
func (*OptimizationProblem) AddBinaryVariable ¶
func (op *OptimizationProblem) AddBinaryVariable() symbolic.Variable
AddBinaryVar adds a binary variable to the model and returns said variable.
func (*OptimizationProblem) AddBinaryVariableMatrix ¶
func (op *OptimizationProblem) AddBinaryVariableMatrix(rows, cols int) [][]symbolic.Variable
AddBinaryVariableMatrix adds a matrix of binary variables to the model and returns the resulting slice.
func (*OptimizationProblem) AddBinaryVariableVector ¶
func (op *OptimizationProblem) AddBinaryVariableVector(num int) symbolic.VariableVector
AddBinaryVariableVector adds a vector of binary variables to the model and returns the slice.
func (*OptimizationProblem) AddRealVariable ¶
func (op *OptimizationProblem) AddRealVariable() symbolic.Variable
AddRealVariable Description:
Adds a Real variable to the model and returns said variable.
func (*OptimizationProblem) AddVariable ¶
func (op *OptimizationProblem) AddVariable() symbolic.Variable
AddVariable Description:
This method adds an "unbounded" continuous variable to the model.
func (*OptimizationProblem) AddVariableClassic ¶
func (op *OptimizationProblem) AddVariableClassic(lower, upper float64, vtype symbolic.VarType) symbolic.Variable
AddVariable adds a variable of a given variable type to the model given the lower and upper value limits. This variable is returned.
func (*OptimizationProblem) AddVariableMatrix ¶
func (op *OptimizationProblem) AddVariableMatrix( rows, cols int, lower, upper float64, vtype symbolic.VarType, ) symbolic.VariableMatrix
AddVariableMatrix adds a matrix of variables of a given type to the model with lower and upper value limits and returns the resulting slice.
func (*OptimizationProblem) AddVariableVector ¶
func (op *OptimizationProblem) AddVariableVector(dim int) symbolic.VariableVector
AddVariableVector Description:
Creates a VarVector object using a constructor that assumes you want an "unbounded" vector of real optimization variables.
func (*OptimizationProblem) AddVariableVectorClassic ¶
func (op *OptimizationProblem) AddVariableVectorClassic( num int, lower, upper float64, vtype symbolic.VarType, ) symbolic.VariableVector
AddVariableVectorClassic Description:
The classic version of AddVariableVector defined in the original goop.
func (*OptimizationProblem) Check ¶ added in v0.5.1
func (op *OptimizationProblem) Check() error
Check Description:
Checks that the OptimizationProblem is valid.
func (*OptimizationProblem) CheckIfLinear ¶ added in v0.5.3
func (op *OptimizationProblem) CheckIfLinear() error
CheckIfLinear Description:
Checks the current optimization problem to see if it is linear. Returns an error if the problem is not linear.
func (*OptimizationProblem) Copy ¶ added in v0.5.5
func (op *OptimizationProblem) Copy() *OptimizationProblem
Copy Description:
Returns a deep copy of the optimization problem.
func (*OptimizationProblem) CopyVariable ¶ added in v0.5.5
func (op *OptimizationProblem) CopyVariable(variable symbolic.Variable) symbolic.Variable
CopyVariable Description:
Creates a deep copy of the given variable within the optimization problem.
func (*OptimizationProblem) IsLinear ¶ added in v0.5.1
func (op *OptimizationProblem) IsLinear() bool
IsLinear Description:
Checks if the optimization problem is linear. Per the definition of a linear optimization problem, the problem is linear if and only if: 1. The objective function is linear (i.e., a constant or an affine combination of variables). 2. All constraints are linear (i.e., an affine combination of variables in an inequality or equality).
func (*OptimizationProblem) LinearEqualityConstraintMatrices ¶ added in v0.5.2
func (op *OptimizationProblem) LinearEqualityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error)
LinearEqualityConstraintMatrices Description:
Returns the linear EQUALITY constraint matrices and vectors. For all linear equality constraints, we assemble them into the form: Cx = d Where C is the matrix of coefficients, x is the vector of variables, and d is the vector of constants. We return C and d.
func (*OptimizationProblem) LinearInequalityConstraintMatrices ¶ added in v0.5.2
func (op *OptimizationProblem) LinearInequalityConstraintMatrices() (symbolic.KMatrix, symbolic.KVector, error)
LinearInequalityConstraintMatrices Description:
Returns the linear INEQUALITY constraint matrices and vectors. For all linear inequality constraints, we assemble them into the form: Ax <= b Where A is the matrix of coefficients, x is the vector of variables, and b is the vector of constants. We return A and b.
func (*OptimizationProblem) MakeNotWellDefinedError ¶ added in v0.5.5
func (op *OptimizationProblem) MakeNotWellDefinedError() ope.NotWellDefinedError
func (*OptimizationProblem) SetObjective ¶
func (op *OptimizationProblem) SetObjective(e symbolic.Expression, sense ObjSense) error
func (*OptimizationProblem) SimplifyConstraints ¶ added in v0.5.5
func (op *OptimizationProblem) SimplifyConstraints()
SimplifyConstraints Description:
This method simplifies the constraints of the optimization problem by removing redundant constraints.
func (*OptimizationProblem) String ¶ added in v0.6.1
func (op *OptimizationProblem) String() string
String Description:
Creates a string for the problem.
func (*OptimizationProblem) ToLPStandardForm1 ¶ added in v0.5.3
func (problemIn *OptimizationProblem) ToLPStandardForm1() (*OptimizationProblem, []symbolic.Variable, map[symbolic.Variable]symbolic.Expression, error)
ToLPStandardForm1 Description:
Transforms the given linear program (represented in an OptimizationProblem object) into a standard form (i.e., only linear equality constraints and a linear objective function). sense c^T * x subject to A * x = b x >= 0 Where A is a matrix of coefficients, b is a vector of constants, and c is the vector of coefficients for the objective function. This method also returns the slack variables (i.e., the variables that are added to the problem to convert the inequalities into equalities).
Note:
This method will transform the vector or matrix constraints in the input problem into a set of scalar constraints. Thus, the number of constraints in your problem may "seem" to change.
func (*OptimizationProblem) ToLPStandardForm2 ¶ added in v0.5.5
func (problemIn *OptimizationProblem) ToLPStandardForm2() (*OptimizationProblem, []symbolic.Variable, map[symbolic.Variable]symbolic.Expression, error)
ToLPStandardForm2 Description:
Transforms the given linear program (represented in an OptimizationProblem object) into a standard form (i.e., only linear equality constraints and a linear objective function). max c^T * x subject to A * x = b x >= 0 Where: - A is a matrix of coefficients, - b is a vector of constants, and - c is the vector of coefficients for the objective function. This method also returns the slack variables (i.e., the variables that are added to the problem to convert the inequalities into equalities).
func (*OptimizationProblem) ToProblemWithAllPositiveVariables ¶ added in v0.5.3
func (op *OptimizationProblem) ToProblemWithAllPositiveVariables() (*OptimizationProblem, map[symbolic.Variable]symbolic.Expression, error)
ToProblemWithAllPositiveVariables Description:
Transforms the given optimization problem into a new optimization problem that only contains positive variables. In math, this means that we will create two new variables (x_+ and x_-) for each original variable (x), one for the positive part and one for the negative part. Then, we replace every instance of the original variable with the difference of the two new variables (x = x_+ - x_-).
func (*OptimizationProblem) WithAllPositiveVariableConstraintsRemoved ¶ added in v0.5.5
func (op *OptimizationProblem) WithAllPositiveVariableConstraintsRemoved() *OptimizationProblem
WithAllPositiveVariableConstraintsRemoved Description:
Returns a new optimization problem that is the same as the original problem but with all constraints of the following form removed: x >= 0 0 <= x Where x is a variable in the problem. This is useful for removing redundant constraints that are already implied by the variable bounds.