API reference.
The complete public surface of the grove package
as of v0.1. Items are grouped by type; within each type,
fields and methods appear in declaration order. For the
always-current view, see
pkg.go.dev.
Constants and package-level vars
Positive infinity (math.Inf(1)). Pass as either end of Bounds for an unbounded side. Use -grove.Inf for a free left side.
Stable prefix of the warning grove appends to Result.Warnings when an Integer/Binary model was silently solved as its LP relaxation. strings.HasPrefix against this to gate CI.
Returned by the HiGHS solver stub when the binary wasn’t built with -tags highs. Detectable with errors.Is.
Sense, VarKind, ConstraintType, Status
All four are small int-backed enums with a String method.
Optimization direction. Values: grove.Maximize, grove.Minimize.
Domain of a variable. Values: grove.Continuous, grove.Integer, grove.Binary. The latter two are solved as their LP relaxation in v0.1 — see Integer variables.
Relation used by AddConstraint. Values: grove.LTE, grove.GTE, grove.EQ.
Outcome of a solve. Values: Optimal, Infeasible, Unbounded, IterationLimit, NumericalError, NotSolved.
Var
A decision variable, created via Problem.NewVar.
Don’t construct Var values directly.
The name given at construction.
The declared kind.
Lower bound. -grove.Inf for a free left side.
Upper bound. grove.Inf for a free right side.
VarOption
Functional option passed to NewVar. v0.1 exposes exactly one: Bounds.
Sets the closed interval [low, high]. Use ±grove.Inf for open ends.
Expr
A sparse linear expression. The map is the expression directly; no wrapper type.
Adds other into e in place; returns e.
Multiplies every coefficient in e by k; returns e.
Constraint
The name given at construction.
The LHS expression.
The relation (LTE / GTE / EQ).
The right-hand-side scalar.
Problem
The root object of a grove model. Construct with
NewProblem and attach variables, objective, and
constraints before calling Solve.
Fields
Backend used by Solve. nil ⇒ default pure-Go simplex. Set to &grove.HiGHS{} for the HiGHS stub (real backend lands in v0.3).
When true, streams Phase I/II pivot detail to stderr. Off by default.
Hard pivot cap. 0 (the default) means “use the solver default” — effectively unbounded.
When true, Solve bypasses the v0.2 presolve pass (fixed-variable substitution, empty-row/empty-column removal). Off by default. Useful for debugging solver behaviour or for reproducing results against an external reference; most callers should leave it alone. See Presolve.
Construction
Returns a fresh *Problem. name is used in error messages, exports, and the sensitivity report.
Read-only accessors
Problem name.
Optimization direction.
All variables, in declaration order.
All constraints, in declaration order.
The objective expression.
The constant offset (0 unless set explicitly).
Lookup; nil if not found.
Lookup; nil if not found.
Human-readable summary of the whole model — useful for logging or test assertions.
Mutators
Creates a variable on this problem and returns its handle. Names must be unique per problem.
Sets the objective expression. Every *Var key in e must belong to this problem.
Sets the fixed constant added to the objective.
Appends a constraint and returns its handle. Names must be unique per problem.
Validation & solving
Returns every modeling problem it finds in one pass — an
empty/nil slice means the model is valid. The checks cover
missing variables/objective (except presolve-reduced models
whose linear objective was folded entirely into
ObjectiveConstant), all-zero objective when
every stated coefficient is finite, inverted bounds and NaN
bounds (±Inf remains valid for unbounded sides),
NaN/±Inf objective and constraint coefficients, NaN/±Inf
right-hand sides, empty LHS rows, all-zero LHS rows when
every coefficient is finite, and duplicate constraint names.
Each error is a *ValidationError carrying a
stable Kind classifier; see
Validation.
Solve invokes Validate
automatically and refuses to run when the returned slice
is non-empty.
Single issue returned from Problem.Validate.
Kind is a stable string classifier;
Target is the variable or constraint name (or
"" for problem-level errors);
Message is the human-readable text
(Error() returns it verbatim). Pull a specific
kind out of a []error with
errors.As(err, &verr).
Stable classifier constants:
ValidationNoVariables,
ValidationNoObjective,
ValidationZeroObjective,
ValidationBadBound,
ValidationInvertedBounds,
ValidationBadObjectiveCoef,
ValidationBadRHS,
ValidationEmptyRow,
ValidationZeroRow,
ValidationBadCoefficient,
ValidationDuplicateConstraint.
See Validation
for what each one catches.
Runs p.Solver (or the default simplex). Returns (*Result, nil) for any logical outcome including Infeasible/Unbounded; non-nil error is reserved for structural model mistakes. See Solve and Result.
Runs the presolve pass and returns a reduced copy of p plus the undo map required to re-expand a Result. Never mutates p. Solve invokes this automatically unless p.SkipPresolve is true. See Presolve.
Configuration for Presolve. Tolerance (default 1e-9) is the slack used for feasibility and zero checks on reduced rows. Passing nil is equivalent to passing the zero value.
Undo record produced by Presolve. Terminal is non-NotSolved when the pass decided the problem's status on its own — Infeasible for an inconsistent empty row, Unbounded for a free objective-only variable, Optimal when every variable was fixed. Solve uses the undo record to re-expand Value and duals to the original index space automatically.
File I/O
Writes the problem in CPLEX-LP format.
Writes the problem in fixed-column MPS format.
Parses a problem from CPLEX-LP format — the inverse of WriteLP. Accepts the usual tolerances (case-insensitive keywords, abbreviated headers, multi-line expressions, backslash comments, blank lines anywhere). Parse errors are returned as *grove.ParseError; see below.
Parses a problem from fixed-column or free-form MPS — the inverse of WriteMPS. Handles NAME, OBJSENSE, ROWS, COLUMNS (with INTORG/INTEND markers), RHS, RANGES, BOUNDS, and ENDATA; SOS sections are silently skipped. Auto-detects fixed vs free form by default; use MPSFixedInput() or MPSFreeInput() to override. Range rows raise an error (grove doesn’t model range constraints yet).
Selects the MPS encoding. Values: MPSAuto (default), MPSFixed, MPSFree.
Functional option for ReadMPS.
Forces the parser onto the strict fixed-column layout, bypassing auto-detection.
Forces the parser onto whitespace-separated free-form MPS, bypassing auto-detection.
Structured error returned by ReadLP and ReadMPS. Line is 1-based; Col is 1-based when the position inside a line is meaningful and 0 otherwise. Format names the file format ("LP" or "MPS") and appears in the rendered message. Extract with errors.As to drive editor highlights, etc. Error() folds the prefix "grove: LP parse error …" or "grove: MPS parse error …" around Msg.
Result
Fields
Outcome classification. Always set.
Objective value in the user-facing sense. Valid when Status == Optimal.
Total simplex pivots across Phase I and Phase II.
Optional human-readable detail. Includes the LP-relaxation warning when applicable.
Advisory notes. v0.1 emits exactly one kind (WarnLPRelaxationOnly).
Accessor methods
Value of v in the optimal solution, in the original (un-shifted, un-split) variable. 0 on non-Optimal results.
The full primal solution map. Safe to iterate.
Shadow price of c: the rate at which the optimal objective changes with the constraint’s RHS.
Reduced cost of v: per-unit objective change if v were forced into the basis. Zero on basic variables at a non-degenerate optimum.
Integer/Binary variables whose optimum came back non-integer (within a 1e-6 tolerance). nil if the problem is all-continuous or the solve was not Optimal.
Sensitivity
Builds a structured sensitivity snapshot from a solved problem. Returns nil if r.Status != Optimal.
Constraints and variables in declaration order. Use .String() for a pretty-printed block.
Per-constraint diagnostics block.
Per-variable diagnostics block. AtLower/AtUpper indicate which bound the variable sits on, if any.
Pretty-printed report grouped into binding constraints, slack constraints, and variables.
Solver interface
The single extension point. Assign any implementation to Problem.Solver and it will be used in place of the default simplex.
The default pure-Go simplex. You rarely construct this yourself — setting Problem.Verbose and Problem.MaxIterations forwards into a freshly-built instance.
CGO-linked HiGHS backend. In v0.1, Solve returns ErrHiGHSNotBuilt; a real implementation ships behind -tags highs in v0.3.
Versioning promise
Pre-1.0 minor versions (0.1 → 0.2 → 0.3 → 0.4) are permitted
to break the API as the design settles. All breakages will
be called out in the release notes. The intent is that the
modeling layer (Problem,
Var, Expr, Constraint,
Result, Solver) freezes at v1.0.
See the roadmap.