problem

package
v0.5.3-1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptimizationStatus_LOADED          OptimizationStatus = 1
	OptimizationStatus_OPTIMAL                            = 2
	OptimizationStatus_INFEASIBLE                         = 3
	OptimizationStatus_INF_OR_UNBD                        = 4
	OptimizationStatus_UNBOUNDED                          = 5
	OptimizationStatus_CUTOFF                             = 6
	OptimizationStatus_ITERATION_LIMIT                    = 7
	OptimizationStatus_NODE_LIMIT                         = 8
	OptimizationStatus_TIME_LIMIT                         = 9
	OptimizationStatus_SOLUTION_LIMIT                     = 10
	OptimizationStatus_INTERRUPTED                        = 11
	OptimizationStatus_NUMERIC                            = 12
	OptimizationStatus_SUBOPTIMAL                         = 13
	OptimizationStatus_INPROGRESS                         = 14
	OptimizationStatus_USER_OBJ_LIMIT                     = 15
	OptimizationStatus_WORK_LIMIT                         = 16
)

OptimizationStatuses

Variables

This section is empty.

Functions

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 int

ObjSense represents whether an optimization objective is to be maximized or minimized. This implementation conforms to the Gurobi encoding

const (
	SenseMinimize ObjSense = 1
	SenseMaximize          = -1
	SenseFind     ObjSense = 0
)

Objective senses (minimize and maximize) encoding using Gurobi's standard

func ToObjSense

func ToObjSense(sense optim.ObjSense) ObjSense

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

func (o *Objective) IsLinear() bool

IsLinear Description:

This method returns true if the objective is linear, false otherwise.

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 >= 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) 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) SetObjective

func (op *OptimizationProblem) SetObjective(e symbolic.Expression, sense ObjSense) error

func (*OptimizationProblem) ToLPStandardForm1 added in v0.5.3

func (problemIn *OptimizationProblem) ToLPStandardForm1() (*OptimizationProblem, []symbolic.Variable, 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).

func (*OptimizationProblem) ToProblemWithAllPositiveVariables added in v0.5.3

func (op *OptimizationProblem) ToProblemWithAllPositiveVariables() (*OptimizationProblem, 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_-).

type OptimizationStatus

type OptimizationStatus int

func (OptimizationStatus) ToMessage

func (os OptimizationStatus) ToMessage() (string, error)

ToMessage Description:

Translates the code to the text meaning.
This comes from the status codes documentation: https://www.gurobi.com/documentation/9.5/refman/optimization_status_codes.html#sec:StatusCodes

type Solution

type Solution struct {
	Values map[uint64]float64

	// The objective for the solution
	Objective float64

	// Whether or not the solution is within the optimality threshold
	Status OptimizationStatus
}

Solution stores the solution of an optimization problem and associated metatdata

func (*Solution) Value

func (s *Solution) Value(v optim.Variable) float64

Value returns the value assigned to the variable in the solution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL