Documentation
¶
Index ¶
- Constants
- func FindInSlice(xIn interface{}, sliceIn interface{}) (int, error)
- func Identity(dim int) mat.Dense
- func IsConstraint(c Constraint) bool
- func IsExpression(e interface{}) bool
- func OnesVector(lengthIn int) mat.VecDense
- func Unique(listIn []uint64) []uint64
- func ZerosMatrix(nR, nC int) mat.Dense
- func ZerosVector(lengthIn int) mat.VecDense
- type ConstrSense
- type Constraint
- type Expression
- type K
- func (c K) Coeffs() []float64
- func (c K) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
- func (c K) Constant() float64
- func (c K) Eq(other ScalarExpression) (ScalarConstraint, error)
- func (c K) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
- func (c K) IDs() []uint64
- func (c K) LessEq(other ScalarExpression) (ScalarConstraint, error)
- func (c K) Mult(val float64) (ScalarExpression, error)
- func (c K) Multiply(term1 interface{}) (Expression, error)
- func (c K) NumVars() int
- func (c K) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
- func (c K) Variables() []Variable
- type KVector
- func (kv KVector) At(i int) float64
- func (kv KVector) AtVec(idx int) ScalarExpression
- func (kv KVector) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
- func (kv KVector) Constant() mat.VecDense
- func (kv KVector) Eq(rhsIn interface{}) (VectorConstraint, error)
- func (kv KVector) GreaterEq(rhsIn interface{}) (VectorConstraint, error)
- func (kv KVector) IDs() []uint64
- func (kv KVector) Len() int
- func (kv KVector) LessEq(rhsIn interface{}) (VectorConstraint, error)
- func (kv KVector) LinearCoeff() mat.Dense
- func (kv KVector) Mult(val float64) (VectorExpression, error)
- func (kv KVector) Multiply(term1 interface{}, extras ...interface{}) (Expression, error)
- func (kv KVector) NumVars() int
- func (kv KVector) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
- type Model
- func (m *Model) AddBinaryVariable() Variable
- func (m *Model) AddBinaryVariableMatrix(rows, cols int) [][]Variable
- func (m *Model) AddBinaryVariableVector(num int) VarVector
- func (m *Model) AddConstr(constr Constraint, extras ...interface{}) error
- func (m *Model) AddRealVariable() Variable
- func (m *Model) AddVariable() Variable
- func (m *Model) AddVariableClassic(lower, upper float64, vtype VarType) Variable
- func (m *Model) AddVariableMatrix(rows, cols int, lower, upper float64, vtype VarType) [][]Variable
- func (m *Model) AddVariableVector(dim int) VarVector
- func (m *Model) AddVariableVectorClassic(num int, lower, upper float64, vtype VarType) VarVector
- func (m *Model) Optimize(solver Solver) (*Solution, error)
- func (m *Model) SetObjective(e ScalarExpression, sense ObjSense)
- func (m *Model) SetTimeLimit(dur time.Duration)
- type ObjSense
- type Objective
- type OptimizationStatus
- type ScalarConstraint
- type ScalarExpression
- func Dot(vs []Variable, coeffs []float64) ScalarExpression
- func NewExpr(c float64) ScalarExpression
- func NewLinearExpr(c float64) ScalarExpression
- func SumCol(vs [][]Variable, col int) ScalarExpression
- func SumRow(vs [][]Variable, row int) ScalarExpression
- func SumVars(vs ...Variable) ScalarExpression
- type ScalarLinearExpr
- func (sle ScalarLinearExpr) Coeffs() []float64
- func (sle ScalarLinearExpr) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
- func (sle ScalarLinearExpr) Constant() float64
- func (sle ScalarLinearExpr) Eq(other ScalarExpression) (ScalarConstraint, error)
- func (sle ScalarLinearExpr) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
- func (sle ScalarLinearExpr) IDs() []uint64
- func (sle ScalarLinearExpr) LessEq(other ScalarExpression) (ScalarConstraint, error)
- func (sle ScalarLinearExpr) Mult(c float64) (ScalarExpression, error)
- func (sle ScalarLinearExpr) NumVars() int
- func (sle ScalarLinearExpr) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
- func (sle ScalarLinearExpr) RewriteInTermsOf(newX VarVector) (ScalarLinearExpr, error)
- func (sle ScalarLinearExpr) Variables() []Variable
- type ScalarQuadraticExpression
- func (qe ScalarQuadraticExpression) Check() error
- func (qe ScalarQuadraticExpression) Coeffs() []float64
- func (qe ScalarQuadraticExpression) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
- func (qe ScalarQuadraticExpression) Constant() float64
- func (qe ScalarQuadraticExpression) Eq(other ScalarExpression) (ScalarConstraint, error)
- func (qe ScalarQuadraticExpression) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
- func (qe ScalarQuadraticExpression) IDs() []uint64
- func (qe ScalarQuadraticExpression) LessEq(other ScalarExpression) (ScalarConstraint, error)
- func (qe ScalarQuadraticExpression) Mult(c float64) (ScalarExpression, error)
- func (qe ScalarQuadraticExpression) NumVars() int
- func (qe ScalarQuadraticExpression) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
- func (qe ScalarQuadraticExpression) RewriteInTermsOf(newX VarVector) (ScalarQuadraticExpression, error)
- func (qe ScalarQuadraticExpression) Variables() []Variable
- type Solution
- type Solver
- type VarType
- type VarVector
- func (vv VarVector) AtVec(idx int) ScalarExpression
- func (vv VarVector) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
- func (vv VarVector) Constant() mat.VecDense
- func (vv VarVector) Eq(rhs interface{}) (VectorConstraint, error)
- func (vv VarVector) GreaterEq(rhs interface{}) (VectorConstraint, error)
- func (vv VarVector) IDs() []uint64
- func (vv VarVector) Len() int
- func (vv VarVector) Length() int
- func (vv VarVector) LessEq(rhs interface{}) (VectorConstraint, error)
- func (vv VarVector) LinearCoeff() mat.Dense
- func (vv VarVector) Mult(c float64) (VectorExpression, error)
- func (vv VarVector) NumVars() int
- func (vv VarVector) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
- type Variable
- func (v Variable) Coeffs() []float64
- func (v Variable) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
- func (v Variable) Constant() float64
- func (v Variable) Eq(other ScalarExpression) (ScalarConstraint, error)
- func (v Variable) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
- func (v Variable) IDs() []uint64
- func (v Variable) LessEq(other ScalarExpression) (ScalarConstraint, error)
- func (v Variable) Mult(m float64) (ScalarExpression, error)
- func (v Variable) NumVars() int
- func (v Variable) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
- func (v Variable) Variables() []Variable
- type VectorConstraint
- type VectorExpression
- type VectorLinearExpr
- func (vle VectorLinearExpr) AtVec(idx int) ScalarExpression
- func (vle VectorLinearExpr) Check() error
- func (vle VectorLinearExpr) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
- func (vle VectorLinearExpr) Constant() mat.VecDense
- func (vle VectorLinearExpr) Eq(rhs interface{}) (VectorConstraint, error)
- func (vle VectorLinearExpr) GreaterEq(rhs interface{}) (VectorConstraint, error)
- func (vle VectorLinearExpr) IDs() []uint64
- func (vle VectorLinearExpr) Len() int
- func (vle VectorLinearExpr) LessEq(rhs interface{}) (VectorConstraint, error)
- func (vle VectorLinearExpr) LinearCoeff() mat.Dense
- func (vle VectorLinearExpr) Mult(c float64) (VectorExpression, error)
- func (vle VectorLinearExpr) NumVars() int
- func (vle VectorLinearExpr) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
- func (vle VectorLinearExpr) RewriteInTermsOf(vv VarVector) VectorLinearExpr
Constants ¶
const ( Zero = K(0) One = K(1) )
Integer constants represnting commonly used numbers. Makes for better readability
const ( SenseEqual ConstrSense = '=' SenseLessThanEqual = '<' SenseGreaterThanEqual = '>' )
Different constraint senses conforming to Gurobi's encoding.
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
const ( Continuous VarType = 'C' Binary = 'B' Integer = 'I' )
Multiple common variable types have been included as constants that conform to Gurobi's encoding.
const INFINITY = 1e100
Variables ¶
This section is empty.
Functions ¶
func FindInSlice ¶
FindInSlice Description:
Identifies if the input xIn is in the slice sliceIn. If it is, then this function returns the index such that xIn = sliceIn[index] and no errors. If it is not, then this function returns the index -1 and the boolean value false.
func Identity ¶
Identity Description:
Returns a symmetric matrix that is the identity matrix. Note: this function assumes lengthIn is a positive number.
func IsConstraint ¶
func IsConstraint(c Constraint) bool
func IsExpression ¶
func IsExpression(e interface{}) bool
IsExpression Description:
Tests whether or not the input variable is one of the expression types.
func OnesVector ¶
OnesVector Description:
Returns a vector of ones with length lengthIn. Note: this function assumes lengthIn is a positive number.
func ZerosVector ¶
ZerosVector Description:
Returns a vector of zeros with length lengthIn. Note: this function assumes lengthIn is a positive number.
Types ¶
type ConstrSense ¶
type ConstrSense byte
ConstrSense represents if the constraint x <= y, x >= y, or x == y. For easy integration with Gurobi, the senses have been encoding using a byte in the same way Gurobi encodes the constraint senses.
type Constraint ¶
type Constraint interface { }
func Comparison ¶
func Comparison(lhs, rhs interface{}, sense ConstrSense) (Constraint, error)
Comparison Description:
Compares the two inputs lhs (Left Hand Side) and rhs (Right Hand Side) in the sense provided in sense.
Usage:
constr, err := Comparison(expr1, expr2, SenseGreaterThanEqual)
func Eq ¶
func Eq(lhs, rhs interface{}) (Constraint, error)
Eq Description:
Returns a constraint representing lhs == rhs
func GreaterEq ¶
func GreaterEq(lhs, rhs ScalarExpression) (Constraint, error)
GreaterEq returns a constraint representing lhs >= rhs
func LessEq ¶
func LessEq(lhs, rhs interface{}) (Constraint, error)
LessEq returns a constraint representing lhs <= rhs
type Expression ¶
type Expression interface { // NumVars returns the number of variables in the expression NumVars() int // Vars returns a slice of the Var ids in the expression IDs() []uint64 }
Expression Description:
This interface should be implemented by and ScalarExpression and VectorExpression
func Multiply ¶
func Multiply(term1, term2 interface{}) (Expression, error)
Multiply Description:
Defines the multiplication between two objects.
func Sum ¶
func Sum(exprs ...interface{}) (Expression, error)
Sum returns the sum of the given expressions. It creates a new empty expression and adds to it the given expressions.
func ToExpression ¶
func ToExpression(eIn interface{}) (Expression, error)
type K ¶
type K float64
K is a constant expression type for an MIP. K for short ¯\_(ツ)_/¯
func (K) Coeffs ¶
Coeffs returns a slice of the coefficients in the expression. For constants, this is always nil
func (K) Comparison ¶
func (c K) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
Comparison Description:
This method compares the receiver with expression rhs in the sense provided by sense.
func (K) Constant ¶
Constant returns the constant additive value in the expression. For constants, this is just the constants value
func (K) Eq ¶
func (c K) Eq(other ScalarExpression) (ScalarConstraint, error)
Eq returns an equality (==) constraint between the current expression and another
func (K) GreaterEq ¶
func (c K) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another
func (K) IDs ¶
Vars returns a slice of the Var ids in the expression. For constants, this is always nil
func (K) LessEq ¶
func (c K) LessEq(other ScalarExpression) (ScalarConstraint, error)
LessEq returns a less than or equal to (<=) constraint between the current expression and another
func (K) Mult ¶
func (c K) Mult(val float64) (ScalarExpression, error)
Mult multiplies the current expression to another and returns the resulting expression
func (K) Multiply ¶
func (c K) Multiply(term1 interface{}) (Expression, error)
Multiply Description:
This method multiplies the input constant by another expression.
func (K) NumVars ¶
NumVars returns the number of variables in the expression. For constants, this is always 0
func (K) Plus ¶
func (c K) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
Plus adds the current expression to another and returns the resulting expression
type KVector ¶
KVector
A type which is built on top of the KVector() a constant expression type for an MIP. K for short ¯\_(ツ)_/¯
func (KVector) AtVec ¶
func (kv KVector) AtVec(idx int) ScalarExpression
AtVec Description:
This function returns the value at the k index.
func (KVector) Comparison ¶
func (kv KVector) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
func (KVector) Constant ¶
Constant
Returns the constant additive value in the expression. For constants, this is just the constants value
func (KVector) Eq ¶
func (kv KVector) Eq(rhsIn interface{}) (VectorConstraint, error)
Eq Description:
This method returns an equality (==) constraint between the current expression and another
func (KVector) GreaterEq ¶
func (kv KVector) GreaterEq(rhsIn interface{}) (VectorConstraint, error)
GreaterEq Description:
This method returns a greater than or equal to (>=) constraint between the current expression and another
func (KVector) IDs ¶
Vars Description:
This function returns a slice of the Var ids in the expression. For constants, this is always nil.
func (KVector) LessEq ¶
func (kv KVector) LessEq(rhsIn interface{}) (VectorConstraint, error)
LessEq Description:
Returns a less than or equal to (<=) constraint between the current expression and another
func (KVector) LinearCoeff ¶
Coeffs Description:
This function returns a slice of the coefficients in the expression. For constants, this is always nil.
func (KVector) Mult ¶
func (kv KVector) Mult(val float64) (VectorExpression, error)
Mult Description:
This method multiplies the current expression to another and returns the resulting expression.
func (KVector) Multiply ¶
func (kv KVector) Multiply(term1 interface{}, extras ...interface{}) (Expression, error)
Multiply Description:
This method is used to compute the multiplication of the input vector constant with another term.
func (KVector) NumVars ¶
NumVars Description:
This returns the number of variables in the expression. For constants, this is 0.
func (KVector) Plus ¶
func (kv KVector) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
Plus Description:
Adds the current expression to another and returns the resulting expression
type Model ¶
type Model struct { Name string Variables []Variable Constraints []Constraint Obj *Objective ShowLog bool TimeLimit time.Duration }
Model represents the overall constrained linear optimization model to be solved. Model contains all the variables associated with the optimization problem, constraints, objective, and parameters. New variables can only be created using an instantiated Model.
func NewModel ¶
NewModel returns a new model with some default arguments such as not to show the log and no time limit.
func (*Model) AddBinaryVariable ¶
AddBinaryVar adds a binary variable to the model and returns said variable.
func (*Model) AddBinaryVariableMatrix ¶
AddBinaryVariableMatrix adds a matrix of binary variables to the model and returns the resulting slice.
func (*Model) AddBinaryVariableVector ¶
AddBinaryVariableVector adds a vector of binary variables to the model and returns the slice.
func (*Model) AddConstr ¶
func (m *Model) AddConstr(constr Constraint, extras ...interface{}) error
AddConstr adds the given constraint to the model.
func (*Model) AddRealVariable ¶
AddRealVariable Description:
Adds a Real variable to the model and returns said variable.
func (*Model) AddVariable ¶
AddVariable Description:
This method adds an "unbounded" continuous variable to the model.
func (*Model) AddVariableClassic ¶
AddVariable adds a variable of a given variable type to the model given the lower and upper value limits. This variable is returned.
func (*Model) AddVariableMatrix ¶
func (m *Model) AddVariableMatrix( rows, cols int, lower, upper float64, vtype VarType, ) [][]Variable
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 (*Model) AddVariableVector ¶
AddVariableVector Description:
Creates a VarVector object using a constructor that assumes you want an "unbounded" vector of real optimization variables.
func (*Model) AddVariableVectorClassic ¶
AddVariableVectorClassic Description:
The classic version of AddVariableVector defined in the original goop.
func (*Model) Optimize ¶
Optimize optimizes the model using the given solver type and returns the solution or an error.
func (*Model) SetObjective ¶
func (m *Model) SetObjective(e ScalarExpression, sense ObjSense)
SetObjective sets the objective of the model given an expression and objective sense.
func (*Model) SetTimeLimit ¶
SetTimeLimit sets the solver time limit for the model.
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 )
Objective senses (minimize and maximize) encoding using Gurobi's standard
type Objective ¶
type Objective struct { ScalarExpression Sense ObjSense }
Objective represents an optimization objective given an expression and objective sense (maximize or minimize).
func NewObjective ¶
func NewObjective(e ScalarExpression, sense ObjSense) *Objective
NewObjective returns a new optimization objective given an expression and objective sense
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 ScalarConstraint ¶
type ScalarConstraint struct { LeftHandSide ScalarExpression RightHandSide ScalarExpression Sense ConstrSense }
ScalarConstraint represnts a linear constraint of the form x <= y, x >= y, or x == y. ScalarConstraint uses a left and right hand side expressions along with a constraint sense (<=, >=, ==) to represent a generalized linear constraint
type ScalarExpression ¶
type ScalarExpression interface { // Variables returns the variables included in the scalar expression Variables() []Variable // NumVars returns the number of variables in the expression NumVars() int // Vars returns a slice of the Var ids in the expression IDs() []uint64 // Coeffs returns a slice of the coefficients in the expression Coeffs() []float64 // Constant returns the constant additive value in the expression Constant() float64 // Plus adds the current expression to another and returns the resulting // expression Plus(e interface{}, extras ...interface{}) (ScalarExpression, error) // Mult multiplies the current expression to another and returns the // resulting expression Mult(c float64) (ScalarExpression, error) // LessEq returns a less than or equal to (<=) constraint between the // current expression and another LessEq(e ScalarExpression) (ScalarConstraint, error) // GreaterEq returns a greater than or equal to (>=) constraint between the // current expression and another GreaterEq(e ScalarExpression) (ScalarConstraint, error) // Eq returns an equality (==) constraint between the current expression // and another Eq(e ScalarExpression) (ScalarConstraint, error) //Comparison // Compares the receiver expression rhs with the expression rhs in the sense of sense. Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error) }
ScalarExpression represents a linear general expression of the form c0 * x0 + c1 * x1 + ... + cn * xn + k where ci are coefficients and xi are variables and k is a constant. This is a base interface that is implemented by single variables, constants, and general linear expressions.
func Dot ¶
func Dot(vs []Variable, coeffs []float64) ScalarExpression
Dot returns the dot product of a vector of variables and slice of floats.
func NewExpr ¶
func NewExpr(c float64) ScalarExpression
NewExpr returns a new expression with a single additive constant value, c, and no variables. Creating an expression like sum := NewExpr(0) is useful for creating new empty expressions that you can perform operatotions on later
func NewLinearExpr ¶
func NewLinearExpr(c float64) ScalarExpression
NewLinearExpr returns a new expression with a single additive constant value, c, and no variables.
func SumCol ¶
func SumCol(vs [][]Variable, col int) ScalarExpression
SumCol returns the sum of all variables in a single specified column of a variable matrix.
func SumRow ¶
func SumRow(vs [][]Variable, row int) ScalarExpression
SumRow returns the sum of all the variables in a single specified row of a variable matrix.
func SumVars ¶
func SumVars(vs ...Variable) ScalarExpression
SumVars returns the sum of the given variables. It creates a new empty expression and adds to it the given variables.
type ScalarLinearExpr ¶
type ScalarLinearExpr struct { X VarVector L mat.VecDense // Vector of coefficients. Should match the dimensions of XIndices C float64 }
ScalarLinearExpr represents a linear general expression of the form
L' * x + C
where L is a vector of coefficients that matches the dimension of x, the vector of variables variables and C is a constant
func (ScalarLinearExpr) Coeffs ¶
func (sle ScalarLinearExpr) Coeffs() []float64
Coeffs returns a slice of the coefficients in the expression
func (ScalarLinearExpr) Comparison ¶
func (sle ScalarLinearExpr) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
Comparison Description:
This method compares the receiver with expression rhs in the sense provided by sense.
Usage:
constr, err := e.Comparison(expr1,SenseGreaterThanEqual)
func (ScalarLinearExpr) Constant ¶
func (sle ScalarLinearExpr) Constant() float64
Constant returns the constant additive value in the expression
func (ScalarLinearExpr) Eq ¶
func (sle ScalarLinearExpr) Eq(other ScalarExpression) (ScalarConstraint, error)
Eq returns an equality (==) constraint between the current expression and another
func (ScalarLinearExpr) GreaterEq ¶
func (sle ScalarLinearExpr) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another
func (ScalarLinearExpr) IDs ¶
func (sle ScalarLinearExpr) IDs() []uint64
Vars returns a slice of the Var ids in the expression
func (ScalarLinearExpr) LessEq ¶
func (sle ScalarLinearExpr) LessEq(other ScalarExpression) (ScalarConstraint, error)
LessEq returns a less than or equal to (<=) constraint between the current expression and another
func (ScalarLinearExpr) Mult ¶
func (sle ScalarLinearExpr) Mult(c float64) (ScalarExpression, error)
Mult multiplies the current expression to another and returns the resulting expression
func (ScalarLinearExpr) NumVars ¶
func (sle ScalarLinearExpr) NumVars() int
NumVars returns the number of variables in the expression
func (ScalarLinearExpr) Plus ¶
func (sle ScalarLinearExpr) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
Plus adds the current expression to another and returns the resulting expression
func (ScalarLinearExpr) RewriteInTermsOf ¶
func (sle ScalarLinearExpr) RewriteInTermsOf(newX VarVector) (ScalarLinearExpr, error)
RewriteInTermsOf Description:
Rewrites the current linear expression in terms of the new variables.
Usage:
rewrittenLE, err := orignalLE.RewriteInTermsOfIndices(newXIndices1)
func (ScalarLinearExpr) Variables ¶
func (sle ScalarLinearExpr) Variables() []Variable
Variables Description:
This function returns a slice containing all unique variables in the linear expression le.
type ScalarQuadraticExpression ¶
type ScalarQuadraticExpression struct { Q mat.Dense // Quadratic Term L mat.VecDense // Linear Term C float64 // Constant Term X VarVector }
QuadraticExpr Description:
A quadratic expression of optimization variables (given by their indices). The quadratic expression object defines a quadratic written as follows: x' * Q * x + L * x + C
func NewQuadraticExpr ¶
func NewQuadraticExpr(QIn mat.Dense, qIn mat.VecDense, bIn float64, xIn VarVector) (ScalarQuadraticExpression, error)
NewQuadraticExpr Description:
NewQuadraticExpr returns a basic Quadratic expression whuch is defined by QIn, qIn and bIn.
func NewQuadraticExpr_qb0 ¶
func NewQuadraticExpr_qb0(QIn mat.Dense, xIn VarVector) (ScalarQuadraticExpression, error)
NewQuadraticExpr_qb0 Description:
NewQuadraticExpr_q0 returns a basic Quadratic expression with only the matrix Q being defined, all other values are assumed to be zero.
func (ScalarQuadraticExpression) Check ¶
func (qe ScalarQuadraticExpression) Check() error
Check Description:
This function checks the dimensions of all of the members of the quadratic expression which are slices. They should have compatible dimensions.
func (ScalarQuadraticExpression) Coeffs ¶
func (qe ScalarQuadraticExpression) Coeffs() []float64
Coeffs Description:
Returns the slice of all coefficient values for each pair of variable tuples. The coefficients of the quadratic expression are created in an ordering that comes from the following vector. Consider xI (the indices of the input expression e). The output coefficients will be c. The coefficients of the expression e = x' Q x + q' * x + b will be e = c' mx + b where mx = [ x[0]*x[0], x[0]*x[1], ... , x[0]*x[N-1], x[1]*x[1] , x[1]*x[2], ... , x[1]*x[N-1], x[2]*x[2], ... , x[N-1]*x[N-1], x[0], x[1], ... , x[N-1] ]
func (ScalarQuadraticExpression) Comparison ¶
func (qe ScalarQuadraticExpression) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
Comparison Description:
This method compares the receiver with expression rhs in the sense provided by sense.
Usage:
constr, err := qe.Comparison(expr1,SenseGreaterThanEqual)
func (ScalarQuadraticExpression) Constant ¶
func (qe ScalarQuadraticExpression) Constant() float64
Constant Description:
Returns the constant value associated with a quadratic expression.
func (ScalarQuadraticExpression) Eq ¶
func (qe ScalarQuadraticExpression) Eq(other ScalarExpression) (ScalarConstraint, error)
Eq Description:
Form an equality constraint with this equality constraint and another Eq returns an equality (==) constraint between the current expression and another
func (ScalarQuadraticExpression) GreaterEq ¶
func (qe ScalarQuadraticExpression) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
GreaterEq Description:
GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another
func (ScalarQuadraticExpression) IDs ¶
func (qe ScalarQuadraticExpression) IDs() []uint64
Vars Description:
Returns the ids of all of the variables in the quadratic expression.
func (ScalarQuadraticExpression) LessEq ¶
func (qe ScalarQuadraticExpression) LessEq(other ScalarExpression) (ScalarConstraint, error)
LessEq Description:
LessEq returns a less than or equal to (<=) constraint between the current expression and another
func (ScalarQuadraticExpression) Mult ¶
func (qe ScalarQuadraticExpression) Mult(c float64) (ScalarExpression, error)
// Mult multiplies the current expression to another and returns the // resulting expression
Mult Description:
Mult multiplies the current expression to another and returns the resulting expression
func (ScalarQuadraticExpression) NumVars ¶
func (qe ScalarQuadraticExpression) NumVars() int
NumVars Description:
Returns the number of variables in the expression. To make this actually meaningful, we only count the unique vars.
func (ScalarQuadraticExpression) Plus ¶
func (qe ScalarQuadraticExpression) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
Plus Description:
Adds a quadratic expression to either: - A Quadratic Expression, - A Linear Expression, or - A Constant
func (ScalarQuadraticExpression) RewriteInTermsOf ¶
func (qe ScalarQuadraticExpression) RewriteInTermsOf(newX VarVector) (ScalarQuadraticExpression, error)
RewriteInTermsOfIndices Description:
Rewrites the current quadratic expression in terms of the new variables.
Usage:
rewrittenQE, err := orignalQE.RewriteInTermsOfIndices(newXIndices1)
func (ScalarQuadraticExpression) Variables ¶
func (qe ScalarQuadraticExpression) Variables() []Variable
Variables Description:
This function returns a slice containing all unique variables in the expression qe.
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
type VarType ¶
type VarType byte
VarType represents the type of the variable (continuous, binary, integer, etc) and uses Gurobi's encoding.
type VarVector ¶
type VarVector struct {
Elements []Variable
}
VarVector Description:
Represnts a variable in a optimization problem. The variable is
func (VarVector) AtVec ¶
func (vv VarVector) AtVec(idx int) ScalarExpression
At Description:
Mirrors the gonum api for vectors. This extracts the element of the variable vector at the index x.
func (VarVector) Comparison ¶
func (vv VarVector) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
Comparison Description:
This method creates a constraint of type sense between the receiver (as left hand side) and rhs (as right hand side) if both are valid.
func (VarVector) Constant ¶
Constant Description:
Returns an all zeros vector as output from the method.
func (VarVector) Eq ¶
func (vv VarVector) Eq(rhs interface{}) (VectorConstraint, error)
Eq Description:
This method creates an equal to vector constraint using the receiver as the left hand side and the input rhs as the right hand side if it is valid.
func (VarVector) GreaterEq ¶
func (vv VarVector) GreaterEq(rhs interface{}) (VectorConstraint, error)
GreaterEq Description:
This method creates a greater than or equal to vector constraint using the receiver as the left hand side and the input rhs as the right hand side if it is valid.
func (VarVector) Len ¶
Len Description:
This function is created to mirror the GoNum Vector API. Does the same thing as Length.
func (VarVector) Length ¶
Length Description:
Returns the length of the vector of optimization variables.
func (VarVector) LessEq ¶
func (vv VarVector) LessEq(rhs interface{}) (VectorConstraint, error)
LessEq Description:
This method creates a less than or equal to vector constraint using the receiver as the left hand side and the input rhs as the right hand side if it is valid.
func (VarVector) LinearCoeff ¶
LinearCoeff Description:
Returns the matrix which is multiplied by Variables to get the current "expression". For a single vector, this is an identity matrix.
func (VarVector) Mult ¶
func (vv VarVector) Mult(c float64) (VectorExpression, error)
Mult Description:
This member function computest the multiplication of the receiver vector var with some incoming vector expression (may result in quadratic?).
func (VarVector) NumVars ¶
NumVars Description:
The number of unique variables inside the variable vector.
func (VarVector) Plus ¶
func (vv VarVector) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
Plus Description:
This member function computes the addition of the receiver vector var with the incoming vector expression ve.
type Variable ¶
Var represnts a variable in a optimization problem. The variable is identified with an uint64.
func UniqueVars ¶
UniqueVars Description:
This function creates a slice of unique variables from the slice given in varsIn
func (Variable) Coeffs ¶
Coeffs returns a slice of the coefficients in the expression. For a variable, it always returns a singleton slice containing the value one.
func (Variable) Comparison ¶
func (v Variable) Comparison(rhs ScalarExpression, sense ConstrSense) (ScalarConstraint, error)
Comparison Description:
This method compares the receiver with expression rhs in the sense provided by sense.
Usage:
constr, err := v.Comparison(expr1,SenseGreaterThanEqual)
func (Variable) Constant ¶
Constant returns the constant additive value in the expression. For a variable, it always returns zero.
func (Variable) Eq ¶
func (v Variable) Eq(other ScalarExpression) (ScalarConstraint, error)
Eq returns an equality (==) constraint between the current expression and another
func (Variable) GreaterEq ¶
func (v Variable) GreaterEq(other ScalarExpression) (ScalarConstraint, error)
GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another
func (Variable) IDs ¶
Vars returns a slice of the Var ids in the expression. For a variable, it always returns a singleton slice with the given variable ID.
func (Variable) LessEq ¶
func (v Variable) LessEq(other ScalarExpression) (ScalarConstraint, error)
LessEq returns a less than or equal to (<=) constraint between the current expression and another
func (Variable) Mult ¶
func (v Variable) Mult(m float64) (ScalarExpression, error)
Mult multiplies the current expression to another and returns the resulting expression
func (Variable) NumVars ¶
NumVars returns the number of variables in the expression. For a variable, it always returns one.
func (Variable) Plus ¶
func (v Variable) Plus(e interface{}, extras ...interface{}) (ScalarExpression, error)
Plus adds the current expression to another and returns the resulting expression.
type VectorConstraint ¶
type VectorConstraint struct { LeftHandSide VectorExpression RightHandSide VectorExpression Sense ConstrSense }
func (VectorConstraint) AtVec ¶
func (vc VectorConstraint) AtVec(i int) (ScalarConstraint, error)
AtVec Description:
Retrieves the constraint formed by one element of the "vector" constraint.
func (VectorConstraint) Check ¶
func (vc VectorConstraint) Check() error
Check Description:
Checks that the VectorConstraint is valid.
type VectorExpression ¶
type VectorExpression interface { // NumVars returns the number of variables in the expression NumVars() int // IDs returns a slice of the Var ids in the expression IDs() []uint64 // Coeffs returns a slice of the coefficients in the expression LinearCoeff() mat.Dense // Constant returns the constant additive value in the expression Constant() mat.VecDense // Plus adds the current expression to another and returns the resulting // expression Plus(e interface{}, extras ...interface{}) (VectorExpression, error) // Mult multiplies the current expression with another and returns the // resulting expression Mult(c float64) (VectorExpression, error) // LessEq returns a less than or equal to (<=) constraint between the // current expression and another LessEq(rhs interface{}) (VectorConstraint, error) // GreaterEq returns a greater than or equal to (>=) constraint between the // current expression and another GreaterEq(rhs interface{}) (VectorConstraint, error) // Comparison // Returns a constraint with respect to the sense (senseIn) between the // current expression and another. Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error) // Eq returns an equality (==) constraint between the current expression // and another Eq(rhs interface{}) (VectorConstraint, error) // Len returns the length of the vector expression. Len() int //AtVec returns the expression at a given index AtVec(idx int) ScalarExpression }
VectorExpression Description:
This interface represents any expression written in terms of a vector of represents a linear general expression of the form c0 * x0 + c1 * x1 + ... + cn * xn + k where ci are coefficients and xi are variables and k is a constant. This is a base interface that is implemented by single variables, constants, and general linear expressions.
type VectorLinearExpr ¶
type VectorLinearExpr struct { X VarVector L mat.Dense // Matrix of coefficients. Should match the dimensions of XIndices C mat.VecDense }
VectorLinearExpr represents a linear general expression of the form
L' * x + C
where L is an n x m matrix of coefficients that matches the dimension of x, the vector of variables and C is a constant vector
func NewVectorExpression ¶
func NewVectorExpression(c mat.VecDense) VectorLinearExpr
NewVectorExpression Description:
NewExpr returns a new expression with a single additive constant value, c, and no variables. Creating an expression like sum := NewVectorExpr(0) is useful for creating new empty expressions that you can perform operatotions on later
func (VectorLinearExpr) AtVec ¶
func (vle VectorLinearExpr) AtVec(idx int) ScalarExpression
AtVec Description:
func (VectorLinearExpr) Check ¶
func (vle VectorLinearExpr) Check() error
Check Description:
Checks to see if the VectorLinearExpression is well-defined.
func (VectorLinearExpr) Comparison ¶
func (vle VectorLinearExpr) Comparison(rhs interface{}, sense ConstrSense) (VectorConstraint, error)
Comparison Description:
Compares the input vector linear expression with respect to the expression rhsIn and the sense senseIn.
func (VectorLinearExpr) Constant ¶
func (vle VectorLinearExpr) Constant() mat.VecDense
Constant Description:
Returns the vector which is given as an offset vector in the linear expression represented by v (the c in the above expression).
func (VectorLinearExpr) Eq ¶
func (vle VectorLinearExpr) Eq(rhs interface{}) (VectorConstraint, error)
Eq Description:
Creates a constraint between the current vector linear expression v and the rhs given by rhs.
func (VectorLinearExpr) GreaterEq ¶
func (vle VectorLinearExpr) GreaterEq(rhs interface{}) (VectorConstraint, error)
GreaterEq Description:
Creates a VectorConstraint that declares vle is greater than or equal to the value to the right hand side rhs.
func (VectorLinearExpr) IDs ¶
func (vle VectorLinearExpr) IDs() []uint64
IDs Description:
Returns the MatProInterface ID of each variable in the current vector linear expression.
func (VectorLinearExpr) Len ¶
func (vle VectorLinearExpr) Len() int
Len Description:
The size of the constraint.
func (VectorLinearExpr) LessEq ¶
func (vle VectorLinearExpr) LessEq(rhs interface{}) (VectorConstraint, error)
LessEq Description:
Creates a VectorConstraint that declares vle is less than or equal to the value to the right hand side rhs.
func (VectorLinearExpr) LinearCoeff ¶
func (vle VectorLinearExpr) LinearCoeff() mat.Dense
LinearCoeff Description:
Returns the matrix which is applied as a coefficient to the vector X in our expression.
func (VectorLinearExpr) Mult ¶
func (vle VectorLinearExpr) Mult(c float64) (VectorExpression, error)
Mult Description:
Returns an expression which scales every dimension of the vector linear expression by the input.
func (VectorLinearExpr) NumVars ¶
func (vle VectorLinearExpr) NumVars() int
NumVars Description:
Returns the goop2 ID of each variable in the current vector linear expression.
func (VectorLinearExpr) Plus ¶
func (vle VectorLinearExpr) Plus(e interface{}, extras ...interface{}) (VectorExpression, error)
Plus Description:
Returns an expression which adds the expression e to the vector linear expression at hand.
func (VectorLinearExpr) RewriteInTermsOf ¶
func (vle VectorLinearExpr) RewriteInTermsOf(vv VarVector) VectorLinearExpr
RewriteInTermsOf Description:
Rewrites the VectorLinearExpression in terms of a new set of variables vv
Assumes:
vv contains all unique variables. All elements of vle.X are in vv.