kiwi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INVALID kind = iota
	EXTERNAL
	SLACK
	ERROR
	DUMMY
)
View Source
const (
	OPTIONAL Strength = iota
	WEAK
	MEDIUM   = (1000 * WEAK)
	STRONG   = (1000 * MEDIUM)
	REQUIRED = (1000 * STRONG) + STRONG + MEDIUM
)
View Source
const BadRequiredStrength = Error("Bad Required Strength")
View Source
const EPS = 1.0e-8
View Source
const FailedToFindLeavingRow = Error("Failed to find Leaving Row")
View Source
const InternalSolverError = Error("Internal Solver Error")
View Source
const SyntaxError = Error("Syntax Error")
View Source
const UnboundedObjective = Error("Objective is Unbounded")

Variables

This section is empty.

Functions

func NearZero

func NearZero(value float64) bool

Types

type AST

type AST struct{ ast.Expr }

func ParseExpr

func ParseExpr(a ...interface{}) (*AST, error)

func (AST) NewConstraint

func (a AST) NewConstraint(vars []*Variable, options ...ConstraintOption) (*Constraint, error)

func (AST) String

func (a AST) String() string

func (AST) TechString

func (a AST) TechString() string

type Constrainer

type Constrainer interface {
	EqualsConstant(float64) *Constraint
	EqualsVariable(*Variable) *Constraint
	EqualsTerm(Term) *Constraint
	EqualsExpression(Expression) *Constraint
	LessThanOrEqualsConstant(float64) *Constraint
	LessThanOrEqualsVariable(*Variable) *Constraint
	LessThanOrEqualsTerm(Term) *Constraint
	LessThanOrEqualsExpression(Expression) *Constraint
	GreaterThanOrEqualsConstant(float64) *Constraint
	GreaterThanOrEqualsVariable(*Variable) *Constraint
	GreaterThanOrEqualsTerm(Term) *Constraint
	GreaterThanOrEqualsExpression(Expression) *Constraint
}

type Constraint

type Constraint struct {
	Expression Expression
	Operator   Operator
	Strength   Strength
}

func NewConstraint

func NewConstraint(expr Expression, op Operator, options ...ConstraintOption) *Constraint

func ParseConstraint

func ParseConstraint(x string, vars []*Variable, options ...ConstraintOption) (*Constraint, error)

func (*Constraint) ApplyOptions

func (c *Constraint) ApplyOptions(options ...ConstraintOption)

func (*Constraint) String

func (c *Constraint) String() string

type ConstraintOption

type ConstraintOption func(*Constraint)

func WithStrength

func WithStrength(strength Strength) ConstraintOption

WithStrength is a constraint option to set the strength of the constraint

type DuplicateConstraint

type DuplicateConstraint struct{ *Constraint }

func (DuplicateConstraint) Error

func (e DuplicateConstraint) Error() string

type DuplicateEditVariable

type DuplicateEditVariable struct{ *Variable }

func (DuplicateEditVariable) Error

func (e DuplicateEditVariable) Error() string

type DuplicateStayVariable

type DuplicateStayVariable struct{ *Variable }

func (DuplicateStayVariable) Error

func (e DuplicateStayVariable) Error() string

type Error

type Error string

func EvaluationError

func EvaluationError(a ...interface{}) Error

func (Error) Error

func (e Error) Error() string

type Expression

type Expression struct {
	Terms    []Term
	Constant float64
}

func (Expression) AddConstant

func (e Expression) AddConstant(constant float64) Expression

func (Expression) AddExpression

func (e Expression) AddExpression(other Expression) Expression

func (Expression) AddTerm

func (e Expression) AddTerm(term Term) Expression

func (Expression) AddVariable

func (e Expression) AddVariable(variable *Variable) Expression

func (Expression) Divide

func (e Expression) Divide(denominator float64) Expression

func (Expression) EqualsConstant

func (e Expression) EqualsConstant(constant float64) *Constraint

func (Expression) EqualsExpression

func (e Expression) EqualsExpression(expression Expression) *Constraint

func (Expression) EqualsTerm

func (e Expression) EqualsTerm(term Term) *Constraint

func (Expression) EqualsVariable

func (e Expression) EqualsVariable(variable *Variable) *Constraint

func (Expression) GetValue

func (e Expression) GetValue() float64

func (Expression) GreaterThanOrEqualsConstant

func (e Expression) GreaterThanOrEqualsConstant(constant float64) *Constraint

func (Expression) GreaterThanOrEqualsExpression

func (e Expression) GreaterThanOrEqualsExpression(expression Expression) *Constraint

func (Expression) GreaterThanOrEqualsTerm

func (e Expression) GreaterThanOrEqualsTerm(term Term) *Constraint

func (Expression) GreaterThanOrEqualsVariable

func (e Expression) GreaterThanOrEqualsVariable(variable *Variable) *Constraint

func (Expression) IsConstant

func (e Expression) IsConstant() bool

func (Expression) LessThanOrEqualsConstant

func (e Expression) LessThanOrEqualsConstant(constant float64) *Constraint

func (Expression) LessThanOrEqualsExpression

func (e Expression) LessThanOrEqualsExpression(expression Expression) *Constraint

func (Expression) LessThanOrEqualsTerm

func (e Expression) LessThanOrEqualsTerm(term Term) *Constraint

func (Expression) LessThanOrEqualsVariable

func (e Expression) LessThanOrEqualsVariable(variable *Variable) *Constraint

func (Expression) Multiply

func (e Expression) Multiply(coefficient float64) Expression

func (Expression) Negate

func (e Expression) Negate() Expression

func (Expression) String

func (e Expression) String() string

type Operator

type Operator int
const (
	LE Operator = iota
	GE
	EQ
)

func (Operator) String

func (o Operator) String() string

type Solver

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

func NewSolver

func NewSolver() *Solver

func (*Solver) AddConstraint

func (s *Solver) AddConstraint(constraint *Constraint, options ...ConstraintOption) error

AddConstraint adds a constraint to the solver.

Returns

DuplicateConstraint

The given constraint has already been added to the solver.

UnsatisfiableConstraint

The given constraint is required and cannot be satisfied.

func (*Solver) AddEditVariable

func (s *Solver) AddEditVariable(variable *Variable, options ...ConstraintOption) error

AddEditVariable adds an edit variable to the solver.

This method should be called before the `suggestValue` method is used to supply a suggested value for the given edit variable.

When no strength option is given the edit variable will be created with STRONG strength.

Returns

DuplicateEditVariable

The given edit variable has already been added to the solver.

BadRequiredStrength

The given strength is >= required.

func (*Solver) AddStay

func (s *Solver) AddStay(variable *Variable, options ...ConstraintOption) error

AddStay adds a constraint that says that a particular variable shouldn’t be modified unless it needs to be - that it should “stay” as is unless there is a reason not to.

By default when no constraint option is given the strength of the stay constraint will be the weakest strength possible, which is 'OPTIONAL'.

func (*Solver) HasConstraint

func (s *Solver) HasConstraint(constraint *Constraint) bool

HasConstraint tests whether a constraint has been added to the solver.

func (*Solver) HasEditVariable

func (s *Solver) HasEditVariable(variable *Variable) bool

HasEditVariable tests whether an edit variable has been added to the solver.

func (*Solver) HasStay

func (s *Solver) HasStay(variable *Variable) bool

HasStay tests whether a stay constraint has been added to the solver for the given variable.

func (*Solver) RemoveConstraint

func (s *Solver) RemoveConstraint(constraint *Constraint) error

RemoveConstraint removes a constraint from the solver.

Returns

UnknownConstraint

The given constraint has not been added to the solver.

func (*Solver) RemoveEditVariable

func (s *Solver) RemoveEditVariable(variable *Variable) error

RemoveEditVariable removes an edit variable from the solver.

Returns

UnknownEditVariable

The given edit variable has not been added to the solver.

func (*Solver) RemoveStay

func (s *Solver) RemoveStay(variable *Variable) error

RemoveStay removes a stay constraint for the given variable from the solver.

func (*Solver) Reset

func (s *Solver) Reset()

Reset resets the solver to the empty starting condition.

This method resets the internal solver state to the empty starting condition, as if no constraints or edit variables have been added. This can be faster than deleting the solver and creating a new one when the entire system must change, since it can avoid unecessary heap (de)allocations.

func (Solver) String

func (s Solver) String() string

func (*Solver) SuggestValue

func (s *Solver) SuggestValue(variable *Variable, value float64) error

SuggestValue suggests a value for the given edit variable.

This method should be used after an edit variable as been added to the solver in order to suggest the value for that variable. After all suggestions have been made, the `solve` method can be used to update the values of all variables.

Returns

UnknownEditVariable

The given edit variable has not been added to the solver.

func (*Solver) UpdateStays

func (s *Solver) UpdateStays()

UpdateStays updates all stay constraints to match the value their associated variable currently holds.

This is automatically called by RemoveEditVariable to commit the changes caused by the editing of the variable.

func (*Solver) UpdateVariables

func (s *Solver) UpdateVariables()

UpdateVariables updates the values of the external solver variables.

type Strength

type Strength float64

func Medium

func Medium(weight ...float64) Strength

Medium returns a medium strength with a weight in the range [1 .. 1000)

func Strong

func Strong(weight ...float64) Strength

Strong returns a strong strength with a weight in the range [1 .. 1000)

func Weak

func Weak(weight ...float64) Strength

Weak returns a weak strength with a weight in the range [1 .. 1000)

func (Strength) Base

func (s Strength) Base() Strength

func (Strength) String

func (s Strength) String() string

func (Strength) WithWeight

func (s Strength) WithWeight(weight float64) Strength

type Term

type Term struct {
	Variable    *Variable
	Coefficient float64
}

func (Term) AddConstant

func (t Term) AddConstant(constant float64) Expression

func (Term) AddExpression

func (t Term) AddExpression(expression Expression) Expression

func (Term) AddTerm

func (t Term) AddTerm(term Term) Expression

func (Term) AddVariable

func (t Term) AddVariable(variable *Variable) Expression

func (Term) Divide

func (t Term) Divide(denominator float64) Term

func (Term) EqualsConstant

func (t Term) EqualsConstant(constant float64) *Constraint

func (Term) EqualsExpression

func (t Term) EqualsExpression(expression Expression) *Constraint

func (Term) EqualsTerm

func (t Term) EqualsTerm(term Term) *Constraint

func (Term) EqualsVariable

func (t Term) EqualsVariable(variable *Variable) *Constraint

func (Term) GetValue

func (t Term) GetValue() float64

func (Term) GreaterThanOrEqualsConstant

func (t Term) GreaterThanOrEqualsConstant(constant float64) *Constraint

func (Term) GreaterThanOrEqualsExpression

func (t Term) GreaterThanOrEqualsExpression(expression Expression) *Constraint

func (Term) GreaterThanOrEqualsTerm

func (t Term) GreaterThanOrEqualsTerm(term Term) *Constraint

func (Term) GreaterThanOrEqualsVariable

func (t Term) GreaterThanOrEqualsVariable(variable *Variable) *Constraint

func (Term) LessThanOrEqualsConstant

func (t Term) LessThanOrEqualsConstant(constant float64) *Constraint

func (Term) LessThanOrEqualsExpression

func (t Term) LessThanOrEqualsExpression(expression Expression) *Constraint

func (Term) LessThanOrEqualsTerm

func (t Term) LessThanOrEqualsTerm(term Term) *Constraint

func (Term) LessThanOrEqualsVariable

func (t Term) LessThanOrEqualsVariable(variable *Variable) *Constraint

func (Term) Multiply

func (t Term) Multiply(coefficient float64) Term

func (Term) Negate

func (t Term) Negate() Term

func (Term) String

func (t Term) String() string

type UnknownConstraint

type UnknownConstraint struct{ *Constraint }

func (UnknownConstraint) Error

func (e UnknownConstraint) Error() string

type UnknownEditVariable

type UnknownEditVariable struct{ *Variable }

func (UnknownEditVariable) Error

func (e UnknownEditVariable) Error() string

type UnknownStayVariable

type UnknownStayVariable struct{ *Variable }

func (UnknownStayVariable) Error

func (e UnknownStayVariable) Error() string

type UnknownVariableName

type UnknownVariableName struct{ Name string }

func (UnknownVariableName) Error

func (e UnknownVariableName) Error() string

type UnsatisfiableConstraint

type UnsatisfiableConstraint struct{ *Constraint }

func (UnsatisfiableConstraint) Error

func (e UnsatisfiableConstraint) Error() string

type Variable

type Variable struct {
	Name  string
	Value float64
}

func NewVariable

func NewVariable(name string) *Variable

func Var

func Var(n string, v ...float64) *Variable

func Vars

func Vars(names ...string) []*Variable

func (*Variable) AddConstant

func (v *Variable) AddConstant(constant float64) Expression

func (*Variable) AddExpression

func (v *Variable) AddExpression(expression Expression) Expression

func (*Variable) AddTerm

func (v *Variable) AddTerm(term Term) Expression

func (*Variable) AddVariable

func (v *Variable) AddVariable(variable *Variable) Expression

func (*Variable) Divide

func (v *Variable) Divide(denominator float64) Term

func (*Variable) EqualsConstant

func (v *Variable) EqualsConstant(constant float64) *Constraint

func (*Variable) EqualsExpression

func (v *Variable) EqualsExpression(expression Expression) *Constraint

func (*Variable) EqualsTerm

func (v *Variable) EqualsTerm(term Term) *Constraint

func (*Variable) EqualsVariable

func (v *Variable) EqualsVariable(variable *Variable) *Constraint

func (*Variable) GreaterThanOrEqualsConstant

func (v *Variable) GreaterThanOrEqualsConstant(constant float64) *Constraint

func (*Variable) GreaterThanOrEqualsExpression

func (v *Variable) GreaterThanOrEqualsExpression(expression Expression) *Constraint

func (*Variable) GreaterThanOrEqualsTerm

func (v *Variable) GreaterThanOrEqualsTerm(term Term) *Constraint

func (*Variable) GreaterThanOrEqualsVariable

func (v *Variable) GreaterThanOrEqualsVariable(variable *Variable) *Constraint

func (*Variable) LessThanOrEqualsConstant

func (v *Variable) LessThanOrEqualsConstant(constant float64) *Constraint

func (*Variable) LessThanOrEqualsExpression

func (v *Variable) LessThanOrEqualsExpression(expression Expression) *Constraint

func (*Variable) LessThanOrEqualsTerm

func (v *Variable) LessThanOrEqualsTerm(term Term) *Constraint

func (*Variable) LessThanOrEqualsVariable

func (v *Variable) LessThanOrEqualsVariable(variable *Variable) *Constraint

func (*Variable) Multiply

func (v *Variable) Multiply(coefficient float64) Term

func (*Variable) Negate

func (v *Variable) Negate() Term

func (*Variable) String

func (v *Variable) String() string

Directories

Path Synopsis
gio module

Jump to

Keyboard shortcuts

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