golp: github.com/draffensperger/golp Index | Files

package golp

import "github.com/draffensperger/golp"

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

Package Files

lp.go

type ConstraintType Uses

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 Uses

func (t ConstraintType) String() string

type Entry Uses

type Entry struct {
    Col int
    Val float64
}

Entry is for sparse constraint or objective function rows

type LP Uses

type LP struct {
    // contains filtered or unexported fields
}

LP stores a linear (or mixed integer) programming problem

func NewLP Uses

func NewLP(rows, cols int) *LP

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 Uses

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 Uses

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) ColName Uses

func (l *LP) ColName(col int) string

ColName gives a column name, index is zero-based.

func (*LP) IsBinary Uses

func (l *LP) IsBinary(col int) bool

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 Uses

func (l *LP) IsInt(col int) bool

IsInt returns whether the given column must take an integer value See http://lpsolve.sourceforge.net/5.5/is_int.htm

func (*LP) NumCols Uses

func (l *LP) NumCols() int

NumCols returns the number of columns (variables) in the linear program. See http://lpsolve.sourceforge.net/5.5/get_Ncolumns.htm

func (*LP) NumRows Uses

func (l *LP) NumRows() int

NumRows returns the number of rows (constraints) in the linear program. See http://lpsolve.sourceforge.net/5.5/get_Nrows.htm

func (*LP) Objective Uses

func (l *LP) Objective() float64

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 Uses

func (l *LP) SetAddRowMode(addRowMode bool)

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 Uses

func (l *LP) SetBinary(col int, mustBeBinary bool)

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) SetColName Uses

func (l *LP) SetColName(col int, name string)

SetColName changes a column name. Unlike the LPSolve C library, col is zero-based

func (*LP) SetInt Uses

func (l *LP) SetInt(col int, mustBeInt bool)

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 Uses

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 Uses

func (l *LP) SetObjFn(row []float64)

SetObjFn changes the objective function. Row indices are zero-based. See http://lpsolve.sourceforge.net/5.5/set_obj_fn.htm

func (*LP) SetUnbounded Uses

func (l *LP) SetUnbounded(col int)

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 Uses

func (l *LP) SetVerboseLevel(level VerboseLevel)

SetVerboseLevel changes the output verbose level (golp defaults it to IMPORTANT). See http://lpsolve.sourceforge.net/5.1/set_verbose.htm

func (*LP) Solve Uses

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 Uses

func (l *LP) Variables() []float64

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 Uses

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 Uses

func (l *LP) WriteToString() string

WriteToString returns a representation of the linear program as a string

type SolutionType Uses

type SolutionType int

SolutionType represents the result type.

const (
    NOMEMORY    SolutionType = -2
    OPTIMAL                  = 0
    SUBOPTIMAL               = 1
    INFEASIBLE               = 2
    UNBOUNDED                = 3
    DEGENERATE               = 4
    NUMFAILURE               = 5
    USERABORT                = 6
    TIMEOUT                  = 7
    PROCFAIL                 = 10
    PROCBREAK                = 11
    FEASFOUND                = 12
    NOFEASFOUND              = 13
)

Constants for the solution result type. See http://lpsolve.sourceforge.net/5.5/solve.htm

func (SolutionType) String Uses

func (t SolutionType) String() string

type VerboseLevel Uses

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 Uses

func (level VerboseLevel) String() string

Package golp imports 4 packages (graph) and is imported by 4 packages. Updated 2017-10-02. Refresh now. Tools for package owners.