symbolic

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Zero     = K(0)
	One      = K(1)
	Infinity = K(1e100)
)

Integer constants representing commonly used numbers. Makes for better readability

View Source
const (
	SenseEqual            ConstrSense = '='
	SenseLessThanEqual                = '<'
	SenseGreaterThanEqual             = '>'
)

Different constraint senses conforming to Gurobi's encoding.

View Source
const (
	Continuous VarType = 'C'
	Binary             = 'B'
	Integer            = 'I'
)

Multiple common variable types have been included as constants that conform to Gurobi's encoding.

Variables

View Source
var BackgroundEnvironment = Environment{
	Name:      "Background",
	Variables: []Variable{},
}

BackgroundEnvironment A variable that exists in the background and used to store information about the variables currently created.

Functions

func CheckDimensionsInComparison

func CheckDimensionsInComparison(left, right Expression, senseIn ConstrSense) error

CheckDimensionsInComparison Description:

Verifies that the two objects being compared in a Comparison method (Comparison, LessEq, Eq, GreaterEq)
have the same dimensions.

func FindInSlice

func FindInSlice(xIn interface{}, sliceIn interface{}) (int, error)

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

func Identity(dim int) mat.Dense

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 interface{}) bool

func IsExpression

func IsExpression(e interface{}) bool

IsExpression Description:

Tests whether or not the input variable is one of the expression types.

func IsLinear added in v0.1.4

func IsLinear(e Expression) bool

IsLinear Description:

Determines whether an input object is a
valid linear expression.
In math, this means that the polynomial like expression
has a degree less than or equal to 1.

func IsMatrixExpression

func IsMatrixExpression(e interface{}) bool

IsMatrixExpression Description:

Determines whether or not an input object is a valid "VectorExpression" according to MatProInterface.

func IsPolynomialLike added in v0.1.2

func IsPolynomialLike(e interface{}) bool

IsExpression Description:

Tests whether or not the input variable is one of the expression types.

func IsPolynomialLikeMatrix added in v0.1.4

func IsPolynomialLikeMatrix(e interface{}) bool

IsPolynomialLikeMatrix Description:

Determines whether or not an input object is a valid "VectorExpression" according to MatProInterface.

func IsPolynomialLikeScalar added in v0.1.4

func IsPolynomialLikeScalar(e interface{}) bool

IsPolynomialLikeScalar Description:

Determines whether or not an input object is a
valid "PolynomialLikeScalar" according to MatProInterface.

func IsPolynomialLikeVector added in v0.1.4

func IsPolynomialLikeVector(e interface{}) bool

IsPolynomialLikeVector Description:

Determines whether or not an input object is a valid "PolynomialLikeVector" according to MatProInterface.

func IsQuadratic added in v0.1.4

func IsQuadratic(e Expression) bool

IsQuadratic Description:

Determines whether or not an input object is a
valid Quadratic Expression.
In math, this means that the polynomial like expression
has a degree less than or equal to 2.

func IsScalarExpression

func IsScalarExpression(e interface{}) bool

IsScalarExpression Description:

Determines whether or not an input object is a
valid "ScalarExpression" according to MatProInterface.

func IsVectorExpression

func IsVectorExpression(e interface{}) bool

IsVectorExpression Description:

Determines whether or not an input object is a valid "VectorExpression" according to MatProInterface.

func NumVariables

func NumVariables(e Expression) int

NumVariables Description:

The number of distinct variables.

func OnesMatrix

func OnesMatrix(nR, nC int) mat.Dense

OnesMatrix Description:

Returns a dense matrix of all ones.

func OnesVector

func OnesVector(lengthIn int) mat.VecDense

OnesVector Description:

Returns a vector of ones with length lengthIn.
Note: this function assumes lengthIn is a positive number.

func Unique

func Unique(listIn []uint64) []uint64

Unique Description:

Returns the unique list of variables in a slice of uint64's.

func VariableIDs

func VariableIDs(e Expression) []uint64

VariableIDs Description:

Returns a list of ids associated with each variable.

func ZerosMatrix

func ZerosMatrix(nR, nC int) mat.Dense

ZerosMatrix Description:

Returns a dense matrix of all zeros.

func ZerosVector

func ZerosVector(lengthIn int) mat.VecDense

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.

func (ConstrSense) Check

func (cs ConstrSense) Check() error

Check Description:

This method checks if the receiver is one of the allowed types of sense.

func (ConstrSense) String

func (cs ConstrSense) String() string

type Constraint

type Constraint interface {
	Left() Expression
	Right() Expression
	ConstrSense() ConstrSense
	Check() error
}

type Environment

type Environment struct {
	Name      string
	Variables []Variable
}

type Expression

type Expression interface {
	// NumVars returns the number of variables in the expression
	Variables() []Variable

	// Dims returns a slice describing the true dimensions of a given expression (scalar, vector, or matrix)
	Dims() []int

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(rightIn interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Multiply multiplies the current expression to another and returns the
	// resulting expression
	Multiply(rightIn interface{}) Expression

	// Transpose transposes the given expression
	Transpose() Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rightIn interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rightIn interface{}) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rightIn interface{}) Constraint

	// Comparison
	Comparison(rightIn interface{}, sense ConstrSense) Constraint

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// Check
	Check() error

	// String returns a string representation of the expression
	String() string
}

Expression Description:

This interface should be implemented by and ScalarExpression and VectorExpression

func Minus added in v0.1.5

func Minus(left, right Expression) Expression

Minus Description:

subtracts the current expression from another and returns the resulting expression

func ToExpression

func ToExpression(e interface{}) (Expression, error)

type K

type K float64

K is a constant expression type for an MIP. K for short ¯\_(ツ)_/¯

func (K) Check

func (c K) Check() error

Check Description:

Checks to make sure that the constant is initialized properly.
Constants are always initialized properly, so this should always return
no error.

func (K) Comparison

func (c K) Comparison(rhsIn interface{}, sense ConstrSense) Constraint

Comparison Description:

This method compares the receiver with expression rhs in the sense provided by sense.

func (K) Constant

func (c K) Constant() float64

Constant returns the constant additive value in the expression. For constants, this is just the constants value

func (K) Degree added in v0.1.4

func (c K) Degree() int

Degree Description:

The degree of a constant is always 0.

func (K) DerivativeWrt

func (c K) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Computes the derivative of a constant, which should be 0 for any constant.

func (K) Dims

func (c K) Dims() []int

func (K) Eq

func (c K) Eq(rightIn interface{}) Constraint

Eq returns an equality (==) constraint between the current expression and another

func (K) GreaterEq

func (c K) GreaterEq(rightIn interface{}) Constraint

GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another

func (K) LessEq

func (c K) LessEq(rightIn interface{}) Constraint

LessEq returns a less than or equal to (<=) constraint between the current expression and another

func (K) LinearCoeff added in v0.1.1

func (c K) LinearCoeff(wrt ...[]Variable) mat.VecDense

LinearCoeff Description

Returns the coefficient of the linear term in the expression. For a constant,
this is always a matrix of zeros.

func (K) Minus added in v0.1.5

func (c K) Minus(rightIn interface{}) Expression

Minus Description:

This function subtracts the current expression from another and returns the resulting expression.

func (K) Multiply

func (c K) Multiply(term1 interface{}) Expression

Multiply Description:

This method multiplies the input constant by another expression.

func (K) Plus

func (c K) Plus(rightIn interface{}) Expression

Plus Description:

adds the current expression to another and returns the resulting expression

func (K) String

func (c K) String() string

String Description:

Returns a string representation of the constant.

func (K) ToMonomial

func (c K) ToMonomial() Monomial

ToMonomial Description:

Converts the constant into a monomial.

func (K) ToPolynomial

func (c K) ToPolynomial() Polynomial

ToPolynomial Description:

Converts the constant into a polynomial.

func (K) Transpose

func (c K) Transpose() Expression

func (K) Variables

func (c K) Variables() []Variable

Variables Description:

Shares all variables included in the expression that is K.
It is a constant, so there are none.

type KMatrix

type KMatrix [][]K

func DenseToKMatrix

func DenseToKMatrix(denseIn mat.Dense) KMatrix

DenseToKMatrix Description:

Converts a dense matrix to a KMatrix.

func (KMatrix) At

func (km KMatrix) At(i, j int) ScalarExpression

At Description:

Retrieves element at the specified indices.

func (KMatrix) Check

func (km KMatrix) Check() error

Check Description:

Checks to make sure that the constant is initialized properly.
ConstantMatrix objects are always initialized properly, so this should always return
no error.

func (KMatrix) Comparison

func (km KMatrix) Comparison(rightIn interface{}, sense ConstrSense) Constraint

Comparison Description:

Returns a constraint between the KMatrix and the
expression on the right hand side.

func (KMatrix) Constant

func (km KMatrix) Constant() mat.Dense

Constant Description:

Retrieves the constant component.

func (KMatrix) Degree added in v0.1.5

func (km KMatrix) Degree() int

Degree Description:

The degree of a constant matrix is always 0.

func (KMatrix) DerivativeWrt

func (km KMatrix) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Computes the derivative of the constant matrix with respect to the variable
v. For a constant matrix, this should create a matrix of all zeros (ZerosMatrix).

func (KMatrix) Dims

func (km KMatrix) Dims() []int

Dims Description:

The dimensions of the given matrix.

func (KMatrix) Eq

func (km KMatrix) Eq(rightIn interface{}) Constraint

Eq Description:

Returns an equal constraint between the KMatrix and the
expression on the right hand side.

func (KMatrix) GreaterEq

func (km KMatrix) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

Returns a greater equal constraint between the KMatrix and the
expression on the right hand side.

func (KMatrix) LessEq

func (km KMatrix) LessEq(rightIn interface{}) Constraint

LessEq Description:

Returns a constraint between the KMatrix and the
expression on the right hand side.

func (KMatrix) Minus added in v0.1.5

func (km KMatrix) Minus(e interface{}) Expression

Minus Description:

Subtraction of the constant matrix with another expression.

func (KMatrix) Multiply

func (km KMatrix) Multiply(e interface{}) Expression

Multiply Description:

Multiplication of the constant matrix with another expression.

func (KMatrix) Plus

func (km KMatrix) Plus(e interface{}) Expression

Plus Description:

Addition of the constant matrix with another expression.

func (KMatrix) String

func (km KMatrix) String() string

String Description:

Returns a string representation of the constant matrix.

func (KMatrix) ToDense

func (km KMatrix) ToDense() mat.Dense

ToDense Description:

Converts the constant matrix to a dense matrix.

func (KMatrix) ToMonomialMatrix

func (km KMatrix) ToMonomialMatrix() MonomialMatrix

ToMonomialMatrix Description:

Converts the constant matrix to a monomial matrix.

func (KMatrix) ToPolynomialMatrix

func (km KMatrix) ToPolynomialMatrix() PolynomialMatrix

ToPolynomialMatrix Description:

Converts the constant matrix to a polynomial matrix.

func (KMatrix) Transpose

func (km KMatrix) Transpose() Expression

Transpose Description:

Transposes the constant matrix and returns a new
matrix.

func (KMatrix) Variables

func (km KMatrix) Variables() []Variable

Variables Description:

There are no variables in the constant matrix.

type KVector

type KVector []K // Inherit all methods from mat.VecDense

KVector

A type which is built on top of the KVector()
a constant expression type for an MIP. K for short ¯\_(ツ)_/¯

func VecDenseToKVector

func VecDenseToKVector(v mat.VecDense) KVector

VecDenseToKVector Description:

This method converts the mat.VecDense to a KVector.

func (KVector) AtVec

func (kv KVector) AtVec(idx int) ScalarExpression

AtVec Description:

This function returns the value at the k index.

func (KVector) Check

func (kv KVector) Check() error

Check Description:

This method is used to make sure that the variable is well-defined.
For a constant vector, the vecdense should always be well-defined.

func (KVector) Comparison

func (kv KVector) Comparison(rightIn interface{}, sense ConstrSense) Constraint

func (KVector) Constant

func (kv KVector) Constant() mat.VecDense

Constant

Returns the constant additive value in the expression. For constants, this is just the constants value

func (KVector) Degree added in v0.1.5

func (kv KVector) Degree() int

Degree Description:

The degree of a constant matrix is always 0.

func (KVector) DerivativeWrt

func (kv KVector) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Computes the derivative of the symbolic expression with respect to the
variable vIn which should be a vector of all zeros.

func (KVector) Dims

func (kv KVector) Dims() []int

Dims Description:

Returns the dimension of the constant vector.

func (KVector) Eq

func (kv KVector) Eq(rightIn interface{}) Constraint

Eq Description:

This method returns an equality (==) constraint between the current expression and another

func (KVector) GreaterEq

func (kv KVector) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

This method returns a greater than or equal to (>=) constraint between the current expression and another

func (KVector) Len

func (kv KVector) Len() int

Len

Computes the length of the KVector given.

func (KVector) LessEq

func (kv KVector) LessEq(rightIn interface{}) Constraint

LessEq Description:

Returns a less than or equal to (<=) constraint between the current expression and another

func (KVector) LinearCoeff

func (kv KVector) LinearCoeff() mat.Dense

LinearCoeff Description:

This function returns a slice of the coefficients in the expression. For constants, this is always nil.

func (KVector) Minus added in v0.1.5

func (kv KVector) Minus(e interface{}) Expression

Minus Description:

Subtracts the current expression from another and returns the resulting expression

func (KVector) Multiply

func (kv KVector) Multiply(rightIn interface{}) Expression

Multiply Description:

This method is used to compute the multiplication of the input vector constant with another term.

func (KVector) Plus

func (kv KVector) Plus(rightIn interface{}) Expression

Plus Description:

Adds the current expression to another and returns the resulting expression

func (KVector) String

func (kv KVector) String() string

String Description:

Returns a string representation of the constant vector.

func (KVector) ToMonomialVector

func (kv KVector) ToMonomialVector() MonomialVector

ToMonomialVector Description:

This function converts the input expression to a monomial vector.

func (KVector) ToPolynomialVector

func (kv KVector) ToPolynomialVector() PolynomialVector

ToPolynomialVector Description:

This function converts the input expression to a polynomial vector.

func (KVector) ToVecDense

func (kv KVector) ToVecDense() mat.VecDense

ToVecDense Description:

This method converts the KVector to a mat.VecDense.

func (KVector) Transpose

func (kv KVector) Transpose() Expression

Transpose Description:

This method creates the transpose of the current vector and returns it.

func (KVector) Variables

func (kv KVector) Variables() []Variable

Variables Description:

This function returns the empty slice because no variables are in a constant vector.

type MatrixConstraint

type MatrixConstraint struct {
	LeftHandSide  MatrixExpression
	RightHandSide MatrixExpression
	Sense         ConstrSense
}

func (MatrixConstraint) At

func (mc MatrixConstraint) At(ii, jj int) ScalarConstraint

AtVec Description:

Retrieves the constraint formed by one element of the "vector" constraint.

func (MatrixConstraint) Check

func (mc MatrixConstraint) Check() error

Check Description:

Verifies that:
- The left and right hand sides have matching dimensions,
- The sense is valid, (i.e., it is from the set of allowable senses defined in ConstrSense.

func (MatrixConstraint) ConstrSense

func (mc MatrixConstraint) ConstrSense() ConstrSense

ConstrSense Description:

Returns the sense of the constraint.

func (MatrixConstraint) Dims

func (mc MatrixConstraint) Dims() []int

Dims Description:

The dimension of the matrix constraint (ideally this should be the same as the dimensions
of the left and right hand sides).

func (MatrixConstraint) IsLinear added in v0.1.5

func (mc MatrixConstraint) IsLinear() bool

IsLinear Description:

Describes whether a given matrix constraint is
linear or not.

func (MatrixConstraint) Left

func (mc MatrixConstraint) Left() Expression

func (MatrixConstraint) Right

func (mc MatrixConstraint) Right() Expression

type MatrixExpression

type MatrixExpression interface {
	// Check returns an error if the expression is not initialized properly
	Check() error

	// Variables returns the number of variables in the expression.
	Variables() []Variable

	// Constant returns the constant additive value in the expression
	Constant() mat.Dense

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(e interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Mult multiplies the current expression with another and returns the
	// resulting expression
	Multiply(e interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhs interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhs interface{}) Constraint

	// Comparison
	// Returns a constraint with respect to the sense (senseIn) between the
	// current expression and another.
	Comparison(rhs interface{}, sense ConstrSense) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhs interface{}) Constraint

	//AtVec returns the expression at a given index
	At(i int, j int) ScalarExpression

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// Dims returns the dimensions of the given expression
	Dims() []int

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// String returns a string representation of the expression
	String() string
}

func ToMatrixExpression

func ToMatrixExpression(e interface{}) (MatrixExpression, error)

ToMatrixExpression Description:

Converts the input expression to a valid type that implements "VectorExpression".

type Monomial

type Monomial struct {
	Coefficient     float64
	Exponents       []int
	VariableFactors []Variable
}

Type Definition

func (Monomial) Check

func (m Monomial) Check() error

Check Description:

This function checks that the monomial is valid.

func (Monomial) Comparison

func (m Monomial) Comparison(rhsIn interface{}, sense ConstrSense) Constraint

Comparison Description:

Base method for creating constraints as comparisons between
two different expressions according to a sense.

func (Monomial) Constant

func (m Monomial) Constant() float64

Constant Description:

Returns the constant component in the scalar monomial.
This should be zero unless there are no variables present. Then it will be the coefficient.

func (Monomial) Copy added in v0.1.1

func (m Monomial) Copy() Monomial

Copy Description:

Returns a copy of the monomial.

func (Monomial) Degree added in v0.1.4

func (m Monomial) Degree() int

Degree Description:

Returns the degree of the monomial.

func (Monomial) DerivativeWrt

func (m Monomial) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

This function returns the derivative of the monomial with respect to the input
variable vIn. If the monomial does not contain the variable vIn, then the
derivative is zero.
If the monomial does contain the variable vIn, then the derivative is the monomial
with a decreased degree of vIn and a coefficient equal to the original coefficient.

func (Monomial) Dims

func (m Monomial) Dims() []int

Dims Description:

Returns the dimensions of the monomial. (It is a scalar, so this is [1,1])

func (Monomial) Eq

func (m Monomial) Eq(rightIn interface{}) Constraint

Eq Description:

Returns a constraint between a monomial being equal to an
expression.

func (Monomial) GreaterEq

func (m Monomial) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

Returns a constraint between a monomial being greater than an
expression.

func (Monomial) IsConstant

func (m Monomial) IsConstant() bool

IsConstant Description:

Returns true if the monomial defines a constant.

func (Monomial) IsVariable

func (m Monomial) IsVariable(v Variable) bool

IsVariable Description:

Returns true if the monomial defines an expression containing only the
variable v.

func (Monomial) LessEq

func (m Monomial) LessEq(rightIn interface{}) Constraint

LessEq Description:

Returns a constraint between a monomial being less than an
expression.

func (Monomial) LinearCoeff added in v0.1.1

func (m Monomial) LinearCoeff(wrt ...[]Variable) mat.VecDense

LinearCoeffs Description:

Returns the coefficients of the linear terms in the monomial.

func (Monomial) MatchesFormOf

func (m Monomial) MatchesFormOf(mIn Monomial) bool

MatchesFormOf Description:

Returns true if the monomial matches the form of the input monomial.
(in other words if the input monomial has the same variables and degrees as the input monomial.)

func (Monomial) Minus added in v0.1.5

func (m Monomial) Minus(e interface{}) Expression

Minus Description:

Subtraction of the monomial with another expression.

func (Monomial) Multiply

func (m Monomial) Multiply(e interface{}) Expression

Multiply Description:

Defines the multiplication operation between a monomial and another expression.

func (Monomial) Plus

func (m Monomial) Plus(e interface{}) Expression

Plus Description:

Multiplication of the monomial with another expression.

func (Monomial) String

func (m Monomial) String() string

String Description:

Returns a string representation of the monomial.

func (Monomial) ToPolynomial

func (m Monomial) ToPolynomial() Polynomial

ToPolynomial Description:

Creates a copy of the monomial m as a polynomial.

func (Monomial) Transpose

func (m Monomial) Transpose() Expression

Transpose Description:

Transposes the scalar monomial and returns it. (This is the same as simply copying the monomial.)

func (Monomial) Variables

func (m Monomial) Variables() []Variable

Variables Description:

Returns the variables in the monomial.

type MonomialMatrix

type MonomialMatrix [][]Monomial

func (MonomialMatrix) At

func (mm MonomialMatrix) At(ii, jj int) ScalarExpression

At Description:

Returns the (ii,jj)-th value of the monomial matrix.

func (MonomialMatrix) Check

func (mm MonomialMatrix) Check() error

Check Description:

Verifies that:
- The matrix has at least one row
- The number of columns is the same in each row.
- Each of the monomials in the matrix are valid.

func (MonomialMatrix) Comparison

func (mm MonomialMatrix) Comparison(rightIn interface{}, sense ConstrSense) Constraint

Comparison Description:

Compares the monomial matrix to another expression according to the sense `sense`.

func (MonomialMatrix) Constant

func (mm MonomialMatrix) Constant() mat.Dense

Constant Description:

Returns the components of the monomial matrix which are constant-valued.

func (MonomialMatrix) Degree added in v0.1.5

func (mm MonomialMatrix) Degree() int

Degree Description:

Returns the MAXIMUM degree in the monomial matrix.

func (MonomialMatrix) DerivativeWrt

func (mm MonomialMatrix) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Returns the derivative of the monomial matrix with respect to the input variable.

func (MonomialMatrix) Dims

func (mm MonomialMatrix) Dims() []int

Dims Description:

Returns the dimensions of the matrix.

func (MonomialMatrix) Eq

func (mm MonomialMatrix) Eq(rightIn interface{}) Constraint

Eq Description:

Returns an equality (==) constraint between the current expression
and another.

func (MonomialMatrix) GreaterEq

func (mm MonomialMatrix) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

Returns a greater than or equal to (>=) constraint between the
current expression and another.

func (MonomialMatrix) LessEq

func (mm MonomialMatrix) LessEq(rightIn interface{}) Constraint

LessEq Description:

Returns a less than or equal to (<=) constraint between the
current expression and another.

func (MonomialMatrix) Minus added in v0.1.5

func (mm MonomialMatrix) Minus(e interface{}) Expression

Minus Description:

Subtraction of the monomial matrix with another expression.

func (MonomialMatrix) Multiply

func (mm MonomialMatrix) Multiply(e interface{}) Expression

Multiply Description:

Multiplication of the monomial matrix with another expression.

func (MonomialMatrix) Plus

func (mm MonomialMatrix) Plus(e interface{}) Expression

Plus Description:

Addition of the monomial matrix with another expression.

func (MonomialMatrix) String

func (mm MonomialMatrix) String() string

String Description:

Returns a string representation of the monomial matrix.

func (MonomialMatrix) Transpose

func (mm MonomialMatrix) Transpose() Expression

Transpose Description:

Returns the transpose of the monomial matrix.

func (MonomialMatrix) Variables

func (mm MonomialMatrix) Variables() []Variable

Variables Description:

Returns the variables in the matrix.

type MonomialVector

type MonomialVector []Monomial

func (MonomialVector) AtVec

func (mv MonomialVector) AtVec(idx int) ScalarExpression

AtVec Description:

This function returns the value of the monomial vector at the input vector.

func (MonomialVector) Check

func (mv MonomialVector) Check() error

Check Description:

This function checks that the monomial vector is valid.
It does this by checking that each of the monomials in the vector are valid.
And by checking that there is a non-zero number of them.

func (MonomialVector) Comparison

func (mv MonomialVector) Comparison(rightIn interface{}, sense ConstrSense) Constraint

Comparison Description:

This function compares the monomial vector to the input expression in the sense provided by sense.

func (MonomialVector) Constant

func (mv MonomialVector) Constant() mat.VecDense

Constant Description:

Returns the constant component of the monomial vector (if one exists).

func (MonomialVector) Degree added in v0.1.5

func (mv MonomialVector) Degree() int

Degree Description:

Returns the MAXIMUM degree in the monomial vector.

func (MonomialVector) DerivativeWrt

func (mv MonomialVector) DerivativeWrt(v Variable) Expression

DerivativeWrt Description:

This function returns the derivative of the monomial vector with respect to the input variable.

func (MonomialVector) Dims

func (mv MonomialVector) Dims() []int

Dims Description:

Returns the dimensions of the monomial vector.

func (MonomialVector) Eq

func (mv MonomialVector) Eq(rightIn interface{}) Constraint

Eq Description:

This function creates a constraint that the monomial vector is equal to the input expression.

func (MonomialVector) GreaterEq

func (mv MonomialVector) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

This function creates a constraint that the monomial vector is greater than or equal to the input expression.

func (MonomialVector) IsConstant

func (mv MonomialVector) IsConstant() bool

IsConstant Description:

Determines whether or not an input object is a valid "MonomialVector" according to MatProInterface.

func (MonomialVector) Len

func (mv MonomialVector) Len() int

Len Description:

Returns the number of monomials in the vector.

func (MonomialVector) LessEq

func (mv MonomialVector) LessEq(rightIn interface{}) Constraint

LessEq Description:

This function creates a constraint that the monomial vector is less than or equal to the input expression.

func (MonomialVector) Minus added in v0.1.5

func (mv MonomialVector) Minus(term1 interface{}) Expression

Minus Description:

This function returns the difference of the monomial vector and the input expression.

func (MonomialVector) Multiply

func (mv MonomialVector) Multiply(term1 interface{}) Expression

Multiply Description:

This function returns the product of the monomial vector and the input expression.

func (MonomialVector) Plus

func (mv MonomialVector) Plus(term1 interface{}) Expression

Plus Description:

This function returns the sum of the monomial vector and the input expression.

func (MonomialVector) String

func (mv MonomialVector) String() string

String Description:

This function returns a string representation of the monomial vector.

func (MonomialVector) ToPolynomialVector

func (mv MonomialVector) ToPolynomialVector() PolynomialVector

ToPolynomialVector Description:

This function converts the input monomial vector to a polynomial vector.

func (MonomialVector) Transpose

func (mv MonomialVector) Transpose() Expression

Transpose Description:

This function returns the transpose of the monomial vector.

func (MonomialVector) Variables

func (mv MonomialVector) Variables() []Variable

Variables Description:

Returns the variables in the monomial vector.

type Polynomial

type Polynomial struct {
	Monomials []Monomial
}

Type Definition

func (Polynomial) Check

func (p Polynomial) Check() error

Check Description:

Verifies that all elements of the polynomial are defined correctly.

func (Polynomial) Comparison

func (p Polynomial) Comparison(rightIn interface{}, sense ConstrSense) Constraint

Comparison Description:

Creates a constraint between the polynomial and another expression
of the sense provided in Sense.

func (Polynomial) Constant

func (p Polynomial) Constant() float64

Constant Description:

Retrieves the constant component of the polynomial if there is one.

func (Polynomial) ConstantMonomialIndex

func (p Polynomial) ConstantMonomialIndex() int

ConstantMonomialIndex Description:

Returns the index of the monomial in the polynomial which is a constant.
If none are found, then this returns -1.

func (Polynomial) Copy added in v0.1.5

func (p Polynomial) Copy() Polynomial

Copy Description:

Returns a deep copy of the polynomial.

func (Polynomial) Degree added in v0.1.4

func (p Polynomial) Degree() int

Degree Description:

The degree of the polynomial is the maximum degree of any of the monomials.

func (Polynomial) DerivativeWrt

func (p Polynomial) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

The derivative of the polynomial with respect to the input variable.

func (Polynomial) Dims

func (p Polynomial) Dims() []int

Dims Description:

The scalar polynomial should have dimensions [1,1].

func (Polynomial) Eq

func (p Polynomial) Eq(rightIn interface{}) Constraint

Eq Description:

Creates an equality constraint between the polynomial and another expression.

func (Polynomial) GreaterEq

func (p Polynomial) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

Creates a greater than equal constraint between the polynomial and another expression.

func (Polynomial) IsConstant

func (p Polynomial) IsConstant() bool

IsConstant Description:

This method returns true if and only if the polynomial
represented by pv is a constant (i.e., it contains no variables).

func (Polynomial) LessEq

func (p Polynomial) LessEq(rightIn interface{}) Constraint

LessEq Description:

Creates a less than equal constraint between the polynomial and another expression.

func (Polynomial) LinearCoeff

func (p Polynomial) LinearCoeff(wrt ...[]Variable) mat.VecDense

LinearCoeff Description:

This function returns a vector describing the coefficients of the linear component
of the polynomial.
The (ii)th element of the vector is the coefficient of the (ii)th variable in the
p.Variables() slice as it appears in the polynomial.

func (Polynomial) Minus added in v0.1.5

func (p Polynomial) Minus(e interface{}) Expression

Minus Description:

Defines a subtraction between the polynomial and another expression.

func (Polynomial) MonomialIndex

func (p Polynomial) MonomialIndex(mIn Monomial) int

MonomialIndex Description:

Returns the index of the monomial which has the same
degrees and variables as the input monomial mIn.

func (Polynomial) Multiply

func (p Polynomial) Multiply(e interface{}) Expression

Multiply Description:

Implements the multiplication operator between a polynomial and another expression.

func (Polynomial) Plus

func (p Polynomial) Plus(e interface{}) Expression

Plus Description:

Defines an addition between the polynomial and another expression.

func (Polynomial) Simplify

func (p Polynomial) Simplify() Polynomial

Simplify Description:

This function simplifies the number of monomials in the polynomial,
by finding the matching terms (i.e., monomials with matching Variables and Exponents)
and combining them.

func (Polynomial) String

func (p Polynomial) String() string

String Description:

This method returns a string representation of the polynomial.

func (Polynomial) Transpose

func (p Polynomial) Transpose() Expression

Transpose Description:

The transpose operator when applied to a scalar is just the same scalar object.

func (Polynomial) VariableMonomialIndex

func (p Polynomial) VariableMonomialIndex(vIn Variable) int

VariableMonomialIndex Description:

Returns the index of the monomial which represents the variable given as vIn.

func (Polynomial) Variables

func (p Polynomial) Variables() []Variable

Variables Description:

The unique variables used to define the polynomial.

type PolynomialLike added in v0.1.2

type PolynomialLike interface {
	// NumVars returns the number of variables in the expression
	Variables() []Variable

	// Dims returns a slice describing the true dimensions of a given expression (scalar, vector, or matrix)
	Dims() []int

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(rightIn interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Multiply multiplies the current expression to another and returns the
	// resulting expression
	Multiply(rightIn interface{}) Expression

	// Transpose transposes the given expression
	Transpose() Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rightIn interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rightIn interface{}) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rightIn interface{}) Constraint

	// Comparison
	Comparison(rightIn interface{}, sense ConstrSense) Constraint

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// Check
	Check() error

	// String returns a string representation of the expression
	String() string

	// Degree returns the degree of the expression
	Degree() int
}

polynomial_like.go Description:

This interface should be implemented by all objects
that are polynomial like (i.e., are linear combinations
of variables (potentially raised to powers) and coefficients).

func ToPolynomialLike added in v0.1.2

func ToPolynomialLike(e interface{}) (PolynomialLike, error)

type PolynomialLikeMatrix added in v0.1.4

type PolynomialLikeMatrix interface {
	// Check returns an error if the expression is not initialized properly
	Check() error

	// Variables returns the number of variables in the expression.
	Variables() []Variable

	// Constant returns the constant additive value in the expression
	Constant() mat.Dense

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(e interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Multiply multiplies the current expression with another and returns the
	// resulting expression
	Multiply(e interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhs interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhs interface{}) Constraint

	// Comparison
	// Returns a constraint with respect to the sense (senseIn) between the
	// current expression and another.
	Comparison(rhs interface{}, sense ConstrSense) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhs interface{}) Constraint

	//AtVec returns the expression at a given index
	At(i int, j int) ScalarExpression

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// Dims returns the dimensions of the given expression
	Dims() []int

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// String returns a string representation of the expression
	String() string

	// Degree returns the degree of the expression
	Degree() int
}

func ToPolynomialLikeMatrix added in v0.1.4

func ToPolynomialLikeMatrix(e interface{}) (PolynomialLikeMatrix, error)

ToPolynomialLikeMatrix Description:

Converts the input expression to a valid type that implements "VectorExpression".

type PolynomialLikeScalar added in v0.1.4

type PolynomialLikeScalar interface {
	// Check returns an error if the expression is not valid
	Check() error

	// Variables returns the variables included in the scalar expression
	Variables() []Variable

	// Constant returns the constant additive value in the expression
	Constant() float64

	// LinearCoeff returns the coefficient of the linear terms in the expression
	LinearCoeff(wrt ...[]Variable) mat.VecDense

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(rightIn interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhsIn interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhsIn interface{}) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhsIn interface{}) Constraint

	//Comparison
	// Compares the receiver expression rhs with the expression rhs in the sense of sense.
	Comparison(rhsIn interface{}, sense ConstrSense) Constraint

	//Multiply
	// Multiplies the given scalar expression with another expression
	Multiply(rightIn interface{}) Expression

	//Dims
	// Returns the dimensions of the scalar expression (should always be 1,1)
	Dims() []int

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// Degree returns the degree of the expression
	Degree() int

	// String returns a string representation of the expression
	String() string
}

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 ToPolynomialLikeScalar added in v0.1.4

func ToPolynomialLikeScalar(e interface{}) (PolynomialLikeScalar, error)

ToPolynomialLikeScalar Description:

Converts the input expression to a valid type that
implements "PolynomialLikeScalar".

type PolynomialLikeVector added in v0.1.4

type PolynomialLikeVector interface {
	// Check returns an error if the expression is not valid
	Check() error

	// Variables returns the number of variables in the expression.
	Variables() []Variable

	// 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{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Mult multiplies the current expression with another and returns the
	// resulting expression
	Multiply(e interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhs interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhs interface{}) Constraint

	// Comparison
	// Returns a constraint with respect to the sense (senseIn) between the
	// current expression and another.
	Comparison(rhs interface{}, sense ConstrSense) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhs interface{}) Constraint

	// Len returns the length of the vector expression.
	Len() int

	//AtVec returns the expression at a given index
	AtVec(idx int) ScalarExpression

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// Dims returns the dimensions of the given expression
	Dims() []int

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// String returns a string representation of the expression
	String() string

	// Degree returns the degree of the expression
	Degree() int
}

PolynomialLikeVector 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.

func ToPolynomialLikeVector added in v0.1.4

func ToPolynomialLikeVector(e interface{}) (PolynomialLikeVector, error)

ToPolynomialLikeVector Description:

Converts the input expression to a valid type that implements "PolynomialLikeVector".

type PolynomialMatrix

type PolynomialMatrix [][]Polynomial

func (PolynomialMatrix) At

func (pm PolynomialMatrix) At(ii int, jj int) ScalarExpression

At Description:

Returns the (ii, jj)-th element of the polynomial matrix.

func (PolynomialMatrix) Check

func (pm PolynomialMatrix) Check() error

Check Description:

Verifies that:
- The matrix has at least one row
- The number of columns is the same in each row.
- Each of the polynomials in the matrix are valid.

func (PolynomialMatrix) Comparison

func (pm PolynomialMatrix) Comparison(e interface{}, sense ConstrSense) Constraint

Comparison Description:

Compares the polynomial matrix to another expression.

func (PolynomialMatrix) Constant

func (pm PolynomialMatrix) Constant() mat.Dense

Constant Description:

Returns the components of the polynomial matrix which are
constant-valued.

func (PolynomialMatrix) Degree added in v0.1.5

func (pm PolynomialMatrix) Degree() int

Degree Description:

The degree of the polynomial matrix
is the maximum degree of the entries.

func (PolynomialMatrix) DerivativeWrt

func (pm PolynomialMatrix) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Returns the derivative of the polynomial matrix with respect to the
input variable.

func (PolynomialMatrix) Dims

func (pm PolynomialMatrix) Dims() []int

Dims Description:

Returns the dimensions of the matrix of polynomials.

func (PolynomialMatrix) Eq

func (pm PolynomialMatrix) Eq(e interface{}) Constraint

Eq Description:

Compares the polynomial matrix to another expression using
the SenseEqual sense.

func (PolynomialMatrix) GreaterEq

func (pm PolynomialMatrix) GreaterEq(e interface{}) Constraint

GreaterEq Description:

Compares the polynomial matrix to another expression using
the SenseGreaterThanEqual sense.

func (PolynomialMatrix) LessEq

func (pm PolynomialMatrix) LessEq(e interface{}) Constraint

LessEq Description:

Compares the polynomial matrix to another expression using
the SenseLessThanEqual sense.

func (PolynomialMatrix) Minus added in v0.1.5

func (pm PolynomialMatrix) Minus(e interface{}) Expression

Minus Description:

Subtracts another expression from the given polynomial matrix
and returns the result.

func (PolynomialMatrix) Multiply

func (pm PolynomialMatrix) Multiply(e interface{}) Expression

Multiply Description:

Multiplication of the polynomial matrix with another expression.

func (PolynomialMatrix) Plus

func (pm PolynomialMatrix) Plus(e interface{}) Expression

Plus Description:

Addition of the polynomial matrix with another expression.

func (PolynomialMatrix) Simplify

func (pm PolynomialMatrix) Simplify() PolynomialMatrix

Simplify Description:

Simplifies the polynomial matrix, if possible.

func (PolynomialMatrix) String

func (pm PolynomialMatrix) String() string

String Description:

Returns a string representation of the polynomial matrix.

func (PolynomialMatrix) Transpose

func (pm PolynomialMatrix) Transpose() Expression

Transpose Description:

Transposes the polynomial matrix.

func (PolynomialMatrix) Variables

func (pm PolynomialMatrix) Variables() []Variable

Variables Description:

Returns the variables in the polynomial matrix.

type PolynomialVector

type PolynomialVector []Polynomial

func (PolynomialVector) AtVec

func (pv PolynomialVector) AtVec(idx int) ScalarExpression

AtVec Description:

Retrieves the polynomial at the index idx.

func (PolynomialVector) Check

func (pv PolynomialVector) Check() error

Check Description:

Verifies that each of the polynomials in the vector are valid.

func (PolynomialVector) Comparison

func (pv PolynomialVector) Comparison(e interface{}, senseIn ConstrSense) Constraint

Comparison Description:

Creates the vector constraint between the polynomial vector pv and another
expression according to the sense senseIn.

func (PolynomialVector) Constant

func (pv PolynomialVector) Constant() mat.VecDense

Constant Description:

Returns all of the constant components of the polynomial vector.

func (PolynomialVector) Degree added in v0.1.5

func (pv PolynomialVector) Degree() int

Degree Description:

Returns the maximum degree of any of the entries
in the polynomial vector.

func (PolynomialVector) DerivativeWrt

func (pv PolynomialVector) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Returns the derivative of the polynomial vector with respect to the input variable.

func (PolynomialVector) Dims

func (pv PolynomialVector) Dims() []int

Dims Description:

Returns the shape of the vector which should always be (pv.Len(), 1).

func (PolynomialVector) Eq

func (pv PolynomialVector) Eq(e interface{}) Constraint

Eq Description:

Returns a vector constraint comparing pv and the input expression according
to the Eq sense.
Leverages the Comparison method.

func (PolynomialVector) GreaterEq

func (pv PolynomialVector) GreaterEq(e interface{}) Constraint

GreaterEq Description:

Returns a vector constraint comparing pv and the input expression according
to the GreaterEq sense.
Leverages the Comparison method.

func (PolynomialVector) IsConstantVector

func (pv PolynomialVector) IsConstantVector() bool

IsConstantVector Description:

This method returns true if the polynomial vector is constant.

func (PolynomialVector) Len

func (pv PolynomialVector) Len() int

Len Description:

Mirrors the gonum api for vectors. This extracts the element of the variable vector at the index x.

func (PolynomialVector) Length

func (pv PolynomialVector) Length() int

Length Description:

The number of elements in the Polynomial vector.

func (PolynomialVector) LessEq

func (pv PolynomialVector) LessEq(e interface{}) Constraint

LessEq Description:

Returns a vector constraint between pv and the input expression.
Leverages the Comparison method.

func (PolynomialVector) LinearCoeff

func (pv PolynomialVector) LinearCoeff(vSlices ...[]Variable) mat.Dense

LinearCoeff Description:

Retrieves the coefficients of the linear terms in the polynomial vector.
The output is a matrix where element (ii,jj) of the matrix describes the coefficient
of variable jj (from pv.Variables()) in the polynomial at index ii.

func (PolynomialVector) Minus added in v0.1.5

func (pv PolynomialVector) Minus(e interface{}) Expression

Minus Description:

Defines a subtraction between the polynomial vector and another expression.

func (PolynomialVector) Multiply

func (pv PolynomialVector) Multiply(rightIn interface{}) Expression

Multiply Description:

Computes the product of a polynomial vector and another expression.

func (PolynomialVector) Plus

func (pv PolynomialVector) Plus(e interface{}) Expression

Plus Description:

Defines an addition between the polynomial vector and another expression.

func (PolynomialVector) Simplify

func (pv PolynomialVector) Simplify() PolynomialVector

Simplify Description:

This method simplifies the polynomial vector.

func (PolynomialVector) String

func (pv PolynomialVector) String() string

String Description:

Returns a string representation of the polynomial vector.

func (PolynomialVector) Transpose

func (pv PolynomialVector) Transpose() Expression

Transpose Description:

Computes the transpose of the polynomial vector.

func (PolynomialVector) Variables

func (pv PolynomialVector) Variables() []Variable

Variables Description:

Retrieves the set of all unique variables in the polynomial vector.

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

func (ScalarConstraint) Check added in v0.1.2

func (sc ScalarConstraint) Check() error

Check Description:

Checks that the ScalarConstraint is valid.

func (ScalarConstraint) ConstrSense

func (sc ScalarConstraint) ConstrSense() ConstrSense

ConstrSense Description:

Returns the sense of the constraint.

func (ScalarConstraint) IsLinear

func (sc ScalarConstraint) IsLinear() bool

IsLinear Description:

Describes whether a given scalar constraint is
linear or not.

func (ScalarConstraint) Left

func (sc ScalarConstraint) Left() Expression

func (ScalarConstraint) Right

func (sc ScalarConstraint) Right() Expression

func (ScalarConstraint) Simplify

func (sc ScalarConstraint) Simplify() ScalarConstraint

Simplify Description:

Moves all of the variables of the ScalarConstraint to its
left hand side.

type ScalarExpression

type ScalarExpression interface {
	// Check returns an error if the expression is not valid
	Check() error

	// Variables returns the variables included in the scalar expression
	Variables() []Variable

	// Constant returns the constant additive value in the expression
	Constant() float64

	// LinearCoeff returns the coefficient of the linear terms in the expression
	LinearCoeff(wrt ...[]Variable) mat.VecDense

	// Plus adds the current expression to another and returns the resulting
	// expression
	Plus(rightIn interface{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhsIn interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhsIn interface{}) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhsIn interface{}) Constraint

	//Comparison
	// Compares the receiver expression rhs with the expression rhs in the sense of sense.
	Comparison(rhsIn interface{}, sense ConstrSense) Constraint

	//Multiply
	// Multiplies the given scalar expression with another expression
	Multiply(rightIn interface{}) Expression

	//Dims
	// Returns the dimensions of the scalar expression (should always be 1,1)
	Dims() []int

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// String returns a string representation of the expression
	String() string
}

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 ToScalarExpression

func ToScalarExpression(e interface{}) (ScalarExpression, error)

ToScalarExpression Description:

Converts the input expression to a valid type that
implements "ScalarExpression".

type VarType

type VarType byte

VarType represents the type of the variable (continuous, binary, integer, etc) and uses Gurobi's encoding.

type Variable

type Variable struct {
	ID    uint64
	Lower float64
	Upper float64
	Type  VarType
	Name  string
}

Var represnts a variable in a optimization problem. The variable is identified with an uint64.

func NewBinaryVariable

func NewBinaryVariable(envs ...Environment) Variable

NewContinuousVariable Description:

Creates a new binary variable.

func NewContinuousVariable

func NewContinuousVariable(envs ...*Environment) Variable

NewContinuousVariable Description:

Creates a new continuous variable.

func NewVariable

func NewVariable(envs ...*Environment) Variable

NewVariable Description:

func UniqueVars

func UniqueVars(varsIn []Variable) []Variable

UniqueVars Description:

This function creates a slice of unique variables from the slice given in
varsIn

func (Variable) Check

func (v Variable) Check() error

Check Description:

Checks whether the Variable has a sensible initialization.

func (Variable) Comparison

func (v Variable) Comparison(rhsIn interface{}, sense ConstrSense) Constraint

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

func (v Variable) Constant() float64

Constant returns the constant additive value in the expression. For a variable, it always returns zero.

func (Variable) Degree added in v0.1.4

func (v Variable) Degree() int

Degree Description:

Returns the degree of the variable (which is always 1).

func (Variable) DerivativeWrt

func (v Variable) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

Computes the derivative of the Variable with respect to vIn.
If vIn is the same as the Variable, then this returns 1.0. Otherwise, it
returns 0.0.

func (Variable) Dims

func (v Variable) Dims() []int

Dims Description:

Returns the dimension of the Variable object (should be scalar).

func (Variable) Eq

func (v Variable) Eq(rhsIn interface{}) Constraint

Eq returns an equality (==) constraint between the current expression and another

func (Variable) GreaterEq

func (v Variable) GreaterEq(rhsIn interface{}) Constraint

GreaterEq returns a greater than or equal to (>=) constraint between the current expression and another

func (Variable) LessEq

func (v Variable) LessEq(rhsIn interface{}) Constraint

LessEq returns a less than or equal to (<=) constraint between the current expression and another

func (Variable) LinearCoeff added in v0.1.1

func (v Variable) LinearCoeff(wrt ...[]Variable) mat.VecDense

LinearCoeff Description:

Returns the coefficient of the linear term in the expression. For a variable,
this is always a vector containing exactly 1 value of 1.0 all others are zero.

func (Variable) Minus added in v0.1.5

func (v Variable) Minus(rightIn interface{}) Expression

Minus Description:

This function subtracts an expression from the current
variable.

func (Variable) Multiply

func (v Variable) Multiply(rightIn interface{}) Expression

Multiply Description:

multiplies the current expression to another and returns the resulting expression

func (Variable) Plus

func (v Variable) Plus(rightIn interface{}) Expression

Plus adds the current expression to another and returns the resulting expression.

func (Variable) String

func (v Variable) String() string

String Description:

This method returns a string representation of the variable.

func (Variable) ToMonomial

func (v Variable) ToMonomial() Monomial

ToMonomial Description:

Converts the variable into a monomial.

func (Variable) ToPolynomial

func (v Variable) ToPolynomial() Polynomial

ToPolynomial Description:

Converts the variable into a monomial and then into a polynomial.

func (Variable) Transpose

func (v Variable) Transpose() Expression

func (Variable) Variables

func (v Variable) Variables() []Variable

Variables Description:

This function returns a slice containing all unique variables in the variable expression v.

type VariableMatrix

type VariableMatrix [][]Variable

func NewVariableMatrix

func NewVariableMatrix(nRows, nCols int, envs ...*Environment) VariableMatrix

NewVariableMatrix Description:

This function creates a new variable matrix
and properly initializes each element in it.

func NewVariableMatrixClassic added in v0.1.2

func NewVariableMatrixClassic(nRows, nCols int, envs ...*Environment) VariableMatrix

NewVariableMatrixClassic Description:

This function creates a new variable matrix
and properly initializes each element in it
when given a list of variables.

func (VariableMatrix) At

func (vm VariableMatrix) At(ii, jj int) ScalarExpression

At Description:

This function returns the element of the variable matrix at the given indices.

func (VariableMatrix) Check

func (vm VariableMatrix) Check() error

Check Description:

This method is used to make sure that the variable matrix is well-defined.
It checks:
- That the matrix is not empty.
- That all of the rows have the same number of columns.
- That all of the variables are well-defined.

func (VariableMatrix) Comparison

func (vm VariableMatrix) Comparison(rightIn interface{}, sense ConstrSense) Constraint

Comparison Description:

This function compares the variable matrix to another expression.

func (VariableMatrix) Constant

func (vm VariableMatrix) Constant() mat.Dense

Constant Description:

This function returns the constant value in the variable matrix.
this should always be zero.

func (VariableMatrix) Degree added in v0.1.5

func (vm VariableMatrix) Degree() int

Degree Description:

Returns the maximum degree of the vector of
variables (which is always 1).

func (VariableMatrix) DerivativeWrt

func (vm VariableMatrix) DerivativeWrt(v Variable) Expression

DerivativeWrt Description:

This function returns the derivative of the variable matrix
with respect to a given variable.

func (VariableMatrix) Dims

func (vm VariableMatrix) Dims() []int

Dims Description:

This function returns the dimensions of the variable matrix.

func (VariableMatrix) Eq

func (vm VariableMatrix) Eq(rightIn interface{}) Constraint

Eq Description:

Returns an equality (==) constraint between
the VariableMatrix and another expression.

func (VariableMatrix) GreaterEq

func (vm VariableMatrix) GreaterEq(rightIn interface{}) Constraint

GreaterEq Description:

Returns a greater than or equal to (>=) constraint between
the VariableMatrix and another expression.

func (VariableMatrix) LessEq

func (vm VariableMatrix) LessEq(rightIn interface{}) Constraint

LessEq Description:

Returns a less than or equal to (<=) constraint between
the VariableMatrix and another expression.

func (VariableMatrix) Minus added in v0.1.5

func (vm VariableMatrix) Minus(e interface{}) Expression

Minus Description:

This function subtracts a variable matrix from another term.

func (VariableMatrix) Multiply

func (vm VariableMatrix) Multiply(e interface{}) Expression

Multiply Description:

This function multiplies a variable matrix by another term.

func (VariableMatrix) Plus

func (vm VariableMatrix) Plus(e interface{}) Expression

Plus Description:

This function adds two variable matrices together.

func (VariableMatrix) String

func (vm VariableMatrix) String() string

String Description:

This function returns a string representation of the variable matrix.

func (VariableMatrix) ToMonomialMatrix added in v0.1.1

func (vm VariableMatrix) ToMonomialMatrix() MonomialMatrix

ToMonomialMatrix Description:

This function converts the variable matrix to a monomial matrix.

func (VariableMatrix) ToPolynomialMatrix added in v0.1.1

func (vm VariableMatrix) ToPolynomialMatrix() PolynomialMatrix

ToPolynomialMatrix Description:

This function converts the variable matrix to a polynomial matrix.

func (VariableMatrix) Transpose

func (vm VariableMatrix) Transpose() Expression

Transpose Description:

This function returns the transpose of the variable matrix.

func (VariableMatrix) Variables

func (vm VariableMatrix) Variables() []Variable

Variables Description:

This function returns the list of variables in the matrix.

type VariableVector

type VariableVector []Variable

VariableVector Description:

Represnts a variable in a optimization problem. The variable is

func NewVariableVector

func NewVariableVector(N int, envs ...*Environment) VariableVector

NewVariableVector Description:

Returns a new VariableVector object.

func (VariableVector) AtVec

func (vv VariableVector) 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 (VariableVector) Check

func (vv VariableVector) Check() error

Check Description:

Checks whether or not the VariableVector has a sensible initialization.

func (VariableVector) Comparison

func (vv VariableVector) Comparison(rightIn interface{}, sense ConstrSense) Constraint

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 (VariableVector) Constant

func (vv VariableVector) Constant() mat.VecDense

Constant Description:

Returns an all zeros vector as output from the method.

func (VariableVector) Copy

func (vv VariableVector) Copy() VariableVector

func (VariableVector) Degree added in v0.1.5

func (vv VariableVector) Degree() int

Degree Description:

Returns the degree of the vector of variables
(which is always 1).

func (VariableVector) DerivativeWrt

func (vv VariableVector) DerivativeWrt(vIn Variable) Expression

DerivativeWrt Description:

This function returns the derivative of the VariableVector with respect to the input variable
vIn, which is a vector where each element:
	- is 0 if the variable is not the same as vIn
	- is 1 if the variable is the same as vIn

func (VariableVector) Dims

func (vv VariableVector) Dims() []int

Dims Description:

Dimensions of the variable vector.

func (VariableVector) Eq

func (vv VariableVector) Eq(rightIn interface{}) Constraint

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 (VariableVector) GreaterEq

func (vv VariableVector) GreaterEq(rightIn interface{}) Constraint

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 (VariableVector) Len

func (vv VariableVector) Len() int

Len Description:

This function is created to mirror the GoNum Vector API. Does the same thing as Length.

func (VariableVector) Length

func (vv VariableVector) Length() int

Length Description:

Returns the length of the vector of optimization variables.

func (VariableVector) LessEq

func (vv VariableVector) LessEq(rightIn interface{}) Constraint

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 (VariableVector) LinearCoeff

func (vv VariableVector) LinearCoeff() mat.Dense

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 (VariableVector) Minus added in v0.1.5

func (vv VariableVector) Minus(rightIn interface{}) Expression

Minus Description:

This function subtracts an expression from the current
variable vector and returns the resulting expression.

func (VariableVector) Multiply

func (vv VariableVector) Multiply(rightIn interface{}) Expression

Multiply Description:

Multiplication of a VariableVector with another expression.

func (VariableVector) Plus

func (vv VariableVector) Plus(rightIn interface{}) Expression

Plus Description:

This member function computes the addition of the receiver vector var with the
incoming vector expression ve.

func (VariableVector) String

func (vv VariableVector) String() string

String Description:

Returns a string representation of the VariableVector.

func (VariableVector) ToMonomialVector

func (vv VariableVector) ToMonomialVector() MonomialVector

ToMonomialVector Description:

This function converts the input expression to a monomial vector.

func (VariableVector) ToPolynomialVector added in v0.1.3

func (vv VariableVector) ToPolynomialVector() PolynomialVector

ToPolynomialVector Description:

This function converts the input expression to a polynomial vector.

func (VariableVector) Transpose

func (vv VariableVector) Transpose() Expression

Transpose Description:

This method creates the transpose of the current vector and returns it.

func (VariableVector) Variables

func (vv VariableVector) Variables() []Variable

Variables Description:

Returns the slice of all variables in the vector.

type VectorConstraint

type VectorConstraint struct {
	LeftHandSide  VectorExpression
	RightHandSide VectorExpression
	Sense         ConstrSense
}

func (VectorConstraint) AtVec

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.

func (VectorConstraint) ConstrSense

func (vc VectorConstraint) ConstrSense() ConstrSense

ConstrSense Description:

Returns the sense of the constraint.

func (VectorConstraint) Dims

func (vc VectorConstraint) Dims() []int

Dims Description:

The dimension of the vector constraint (ideally this should be the same as the dimensions
of the left and right hand sides).

func (VectorConstraint) IsLinear added in v0.1.5

func (vc VectorConstraint) IsLinear() bool

IsLinear Description:

Describes whether a given vector constraint is
linear or not.

func (VectorConstraint) Left

func (vc VectorConstraint) Left() Expression

func (VectorConstraint) Right

func (vc VectorConstraint) Right() Expression

type VectorExpression

type VectorExpression interface {
	// Check returns an error if the expression is not valid
	Check() error

	// Variables returns the number of variables in the expression.
	Variables() []Variable

	// 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{}) Expression

	// Minus subtracts an expression from the current one and returns the resulting
	// expression
	Minus(rightIn interface{}) Expression

	// Mult multiplies the current expression with another and returns the
	// resulting expression
	Multiply(e interface{}) Expression

	// LessEq returns a less than or equal to (<=) constraint between the
	// current expression and another
	LessEq(rhs interface{}) Constraint

	// GreaterEq returns a greater than or equal to (>=) constraint between the
	// current expression and another
	GreaterEq(rhs interface{}) Constraint

	// Comparison
	// Returns a constraint with respect to the sense (senseIn) between the
	// current expression and another.
	Comparison(rhs interface{}, sense ConstrSense) Constraint

	// Eq returns an equality (==) constraint between the current expression
	// and another
	Eq(rhs interface{}) Constraint

	// Len returns the length of the vector expression.
	Len() int

	//AtVec returns the expression at a given index
	AtVec(idx int) ScalarExpression

	//Transpose returns the transpose of the given vector expression
	Transpose() Expression

	// Dims returns the dimensions of the given expression
	Dims() []int

	// DerivativeWrt returns the derivative of the expression with respect to the input variable vIn.
	DerivativeWrt(vIn Variable) Expression

	// String returns a string representation of the expression
	String() string
}

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.

func ToVectorExpression

func ToVectorExpression(e interface{}) (VectorExpression, error)

ToVectorExpression Description:

Converts the input expression to a valid type that implements "VectorExpression".

Jump to

Keyboard shortcuts

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