Documentation
¶
Overview ¶
Package golp gives Go bindings for LPSolve, a Mixed Integer Linear Programming (MILP) solver.
For usage examples, see https://github.com/draffensperger/golp#examples.
Not all LPSolve functions have bindings. Feel free to open an issue or contact me if you would like more added.
One difference from the LPSolve C library, is that the golp columns are always zero-based.
The Go code of golp is MIT licensed, but LPSolve itself is licensed under the LGPL. This roughly means that you can include golp in a closed-source project as long as you do not modify LPSolve itself and you use dynamic linking to access LPSolve (and provide a way for someone to link your program to a different version of LPSolve). For the legal details: http://lpsolve.sourceforge.net/5.0/LGPL.htm
Index ¶
- type ConstraintType
- type Entry
- type LP
- func (l *LP) AddConstraint(row []float64, ct ConstraintType, rightHand float64) error
- func (l *LP) AddConstraintSparse(row []Entry, ct ConstraintType, rightHand float64) error
- func (l *LP) ColName(col int) string
- func (l *LP) Copy() *LP
- func (l *LP) DualResult(index int) float64
- func (l *LP) Duals() []float64
- func (l *LP) GetPresolveLoops() int
- func (l *LP) IsBinary(col int) bool
- func (l *LP) IsInt(col int) bool
- func (l *LP) NumCols() int
- func (l *LP) NumRows() int
- func (l *LP) Objective() float64
- func (l *LP) SetAddRowMode(addRowMode bool)
- func (l *LP) SetBinary(col int, mustBeBinary bool)
- func (l *LP) SetBounds(col int, lower, upper float64)
- func (l *LP) SetColName(col int, name string)
- func (l *LP) SetInt(col int, mustBeInt bool)
- func (l *LP) SetMaximize()
- func (l *LP) SetObjFn(row []float64)
- func (l *LP) SetPresolve(level PresolveType, maxLoops int)
- func (l *LP) SetTimeout(timeoutSecond int)
- func (l *LP) SetUnbounded(col int)
- func (l *LP) SetVerboseLevel(level VerboseLevel)
- func (l *LP) Solve() SolutionType
- func (l *LP) Variables() []float64
- func (l *LP) WriteToStdout()
- func (l *LP) WriteToString() string
- type PresolveType
- type SolutionType
- type VerboseLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstraintType ¶
type ConstraintType int
ConstraintType can be less than (golp.LE), greater than (golp.GE) or equal (golp.EQ)
const ( LE ConstraintType // LE == 1 GE // GE == 2 EQ // EQ == 3 )
Contraint type constants
func (ConstraintType) String ¶
func (t ConstraintType) String() string
type LP ¶
type LP struct {
// contains filtered or unexported fields
}
LP stores a linear (or mixed integer) programming problem
func NewLP ¶
NewLP create a new linear program structure with specified number of rows and columns. The underlying C data structure's memory will be freed in a Go finalizer, so there is no need to explicitly deallocate it.
func (*LP) AddConstraint ¶
func (l *LP) AddConstraint(row []float64, ct ConstraintType, rightHand float64) error
AddConstraint adds a constraint to the linear program. This (unlike the LPSolve C function), expects the data in the row param to start at index 0 for the first column. See http://lpsolve.sourceforge.net/5.5/add_constraint.htm
func (*LP) AddConstraintSparse ¶
func (l *LP) AddConstraintSparse(row []Entry, ct ConstraintType, rightHand float64) error
AddConstraintSparse adds a constraint row by specifying only the non-zero entries. Entries column indices are zero-based. See http://lpsolve.sourceforge.net/5.5/add_constraint.htm
func (*LP) DualResult ¶
DualResult retrieves dual variable aka reduced costs for given index. DualResult should be called only after Solve() is successful. Duals indexing starts from 0. See https://lpsolve.sourceforge.net/5.5/get_sensitivity_rhs.htm
func (*LP) Duals ¶
Duals retrieves all dual variable aka reduced costs. Duals should be called only after Solve() is successful. See https://lpsolve.sourceforge.net/5.5/get_sensitivity_rhs.htm This is not using `C.get_dual_solution()` because of suspicion of memory corruption via the pointer that needs to be passed in. See details at https://github.com/draffensperger/golp/issues/22
func (*LP) GetPresolveLoops ¶
GetPresolveLoops determines optimal number of loops for pre solve. See: http://lpsolve.sourceforge.net/5.5/get_presolveloops.htm
func (*LP) IsBinary ¶
IsBinary returns whether the given column must take a binary (0 or 1) value See http://lpsolve.sourceforge.net/5.5/is_binary.htm
func (*LP) IsInt ¶
IsInt returns whether the given column must take an integer value See http://lpsolve.sourceforge.net/5.5/is_int.htm
func (*LP) NumCols ¶
NumCols returns the number of columns (variables) in the linear program. See http://lpsolve.sourceforge.net/5.5/get_Ncolumns.htm
func (*LP) NumRows ¶
NumRows returns the number of rows (constraints) in the linear program. See http://lpsolve.sourceforge.net/5.5/get_Nrows.htm
func (*LP) Objective ¶
Objective gives the value of the objective function of the solved linear program. See http://lpsolve.sourceforge.net/5.5/get_objective.htm
func (*LP) SetAddRowMode ¶
SetAddRowMode specifies whether adding by row (true) or by column (false) performs best. By default NewLP sets this for adding by row to perform best. See http://lpsolve.sourceforge.net/5.5/set_add_rowmode.htm
func (*LP) SetBinary ¶
SetBinary specifies that the given column must take a binary (0 or 1) value See http://lpsolve.sourceforge.net/5.5/set_binary.htm
func (*LP) SetBounds ¶
SetBounds sets the lower and upper bounds for the given column. By default, columns have a lower bound of 0 and an upper bound of +infinity. See http://lpsolve.sourceforge.net/5.5/set_bounds.htm
func (*LP) SetColName ¶
SetColName changes a column name. Unlike the LPSolve C library, col is zero-based
func (*LP) SetInt ¶
SetInt specifies that the given column must take an integer value. This triggers LPSolve to use branch-and-bound instead of simplex to solve. See http://lpsolve.sourceforge.net/5.5/set_int.htm
func (*LP) SetMaximize ¶
func (l *LP) SetMaximize()
SetMaximize will set the objective function to maximize instead of minimizing by default. and http://lpsolve.sourceforge.net/5.5/set_maxim.htm
func (*LP) SetObjFn ¶
SetObjFn changes the objective function. Row indices are zero-based. See http://lpsolve.sourceforge.net/5.5/set_obj_fn.htm
func (*LP) SetPresolve ¶
func (l *LP) SetPresolve(level PresolveType, maxLoops int)
SetPresolve specifies whether pre solve should be used to try to simplify problem, by default it is set to not to perform pre solve, level specifies type of pre solve and maxLoops the maximum number of times pre solve may be done (use 0 to determine number of pre solve loops automatically by get_presolveloop()). For more info see: http://lpsolve.sourceforge.net/5.5/set_presolve.htm
func (*LP) SetTimeout ¶
SetTimeout sets the timeout in seconds for the solver. The default timeout is 0, resulting in no timeout. If a timout occurs, then solve will return SUBOPTIMAL or TIMEOUT. See http://lpsolve.sourceforge.net/5.5/set_timeout.htm
func (*LP) SetUnbounded ¶
SetUnbounded specifies that the given column has a lower bound of -infinity and an upper bound of +infinity. (By default, columns have a lower bound of 0 and an upper bound of +infinity.) See http://lpsolve.sourceforge.net/5.5/set_unbounded.htm
func (*LP) SetVerboseLevel ¶
func (l *LP) SetVerboseLevel(level VerboseLevel)
SetVerboseLevel changes the output verbose level (golp defaults it to IMPORTANT). See http://lpsolve.sourceforge.net/5.5/set_verbose.htm
func (*LP) Solve ¶
func (l *LP) Solve() SolutionType
Solve the linear (or mixed integer) program and return the solution type See http://lpsolve.sourceforge.net/5.5/solve.htm
func (*LP) Variables ¶
Variables return the values for the variables of the solved linear program See http://lpsolve.sourceforge.net/5.5/get_variables.htm
func (*LP) WriteToStdout ¶
func (l *LP) WriteToStdout()
WriteToStdout writes a representation of the linear program to standard out See http://lpsolve.sourceforge.net/5.5/write_lp.htm
func (*LP) WriteToString ¶
WriteToString returns a representation of the linear program as a string
type PresolveType ¶
type PresolveType int
PresolveType specifies type of presolve, see http://lpsolve.sourceforge.net/5.5/set_presolve.htm
const ( NONE PresolveType = 0 ROWS PresolveType = 1 COLS PresolveType = 2 LINDEP PresolveType = 4 SOS PresolveType = 32 REDUCEMIP PresolveType = 64 KNAPSACK PresolveType = 128 ELIMEQ2 PresolveType = 256 IMPLIEDFREE PresolveType = 512 REDUCEGCD PresolveType = 1024 PROBEFIX PresolveType = 2048 PROBEREDUCE PresolveType = 4096 ROWDOMANITE PresolveType = 8192 COLDOMINATE PresolveType = 16384 MERGEROWS PresolveType = 32768 COLFIXDUAL PresolveType = 131072 BOUNDS PresolveType = 262144 DUALS PresolveType = 524288 SENSDUALS PresolveType = 1048576 )
Presolve types
func (PresolveType) String ¶
func (level PresolveType) String() string
type SolutionType ¶
type SolutionType int
SolutionType represents the result type.
const ( NOMEMORY SolutionType = -2 OPTIMAL SolutionType = 0 SUBOPTIMAL SolutionType = 1 INFEASIBLE SolutionType = 2 UNBOUNDED SolutionType = 3 DEGENERATE SolutionType = 4 NUMFAILURE SolutionType = 5 USERABORT SolutionType = 6 TIMEOUT SolutionType = 7 PROCFAIL SolutionType = 10 PROCBREAK SolutionType = 11 FEASFOUND SolutionType = 12 NOFEASFOUND SolutionType = 13 )
Constants for the solution result type. See http://lpsolve.sourceforge.net/5.5/solve.htm
func (SolutionType) String ¶
func (t SolutionType) String() string
type VerboseLevel ¶
type VerboseLevel int
VerboseLevel represents different verbose levels, see http://lpsolve.sourceforge.net/5.1/set_verbose.htm
const ( NEUTRAL VerboseLevel = iota // NEUTRAL == 0 CRITICAL // CRITICAL == 1 SEVERE IMPORTANT NORMAL DETAILED FULL )
Verbose levels
func (VerboseLevel) String ¶
func (level VerboseLevel) String() string