solver

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Incomplete = errors.New("cancelled before a solution could be found")

Functions

This section is empty.

Types

type AppliedConstraint

type AppliedConstraint struct {
	Installable Installable
	Constraint  Constraint
}

AppliedConstraint values compose a single Constraint with the Installable it applies to.

func (AppliedConstraint) String

func (a AppliedConstraint) String() string

String implements fmt.Stringer and returns a human-readable message representing the receiver.

type Constraint

type Constraint interface {
	String(subject Identifier) string
	// contains filtered or unexported methods
}

Constraint implementations limit the circumstances under which a particular Installable can appear in a solution.

func AtMost

func AtMost(n int, ids ...Identifier) Constraint

AtMost returns a Constraint that forbids solutions that contain more than n of the Installables identified by the given Identifiers.

func Conflict

func Conflict(id Identifier) Constraint

Conflict returns a Constraint that will permit solutions containing either the constrained Installable, the Installable identified by the given Identifier, or neither, but not both.

func Dependency

func Dependency(ids ...Identifier) Constraint

Dependency returns a Constraint that will only permit solutions containing a given Installable on the condition that at least one of the Installables identified by the given Identifiers also appears in the solution. Identifiers appearing earlier in the argument list have higher preference than those appearing later.

func Mandatory

func Mandatory() Constraint

Mandatory returns a Constraint that will permit only solutions that contain a particular Installable.

func Prohibited

func Prohibited() Constraint

Prohibited returns a Constraint that will reject any solution that contains a particular Installable. Callers may also decide to omit an Installable from input to Solve rather than apply such a Constraint.

type DefaultTracer

type DefaultTracer struct{}

func (DefaultTracer) Trace

func (DefaultTracer) Trace(_ SearchPosition)

type DuplicateIdentifier

type DuplicateIdentifier Identifier

func (DuplicateIdentifier) Error

func (e DuplicateIdentifier) Error() string

type Identifier

type Identifier string

Identifier values uniquely identify particular Installables within the input to a single call to Solve.

func IdentifierFromString added in v0.18.0

func IdentifierFromString(s string) Identifier

IdentifierFromString returns an Identifier based on a provided string.

func (Identifier) String

func (id Identifier) String() string

type Installable

type Installable interface {
	// Identifier returns the Identifier that uniquely identifies
	// this Installable among all other Installables in a given
	// problem.
	Identifier() Identifier
	// Constraints returns the set of constraints that apply to
	// this Installable.
	Constraints() []Constraint
}

Installable values are the basic unit of problems and solutions understood by this package.

type LoggingTracer

type LoggingTracer struct {
	Writer io.Writer
}

func (LoggingTracer) Trace

func (t LoggingTracer) Trace(p SearchPosition)

type NotSatisfiable

type NotSatisfiable []AppliedConstraint

NotSatisfiable is an error composed of a minimal set of applied constraints that is sufficient to make a solution impossible.

func (NotSatisfiable) Error

func (e NotSatisfiable) Error() string

type Option

type Option func(s *solver) error

func WithInput

func WithInput(input []Installable) Option

func WithTracer

func WithTracer(t Tracer) Option

type SearchPosition

type SearchPosition interface {
	Installables() []Installable
	Conflicts() []AppliedConstraint
}

type Solver

type Solver interface {
	Solve(context.Context) ([]Installable, error)
}

func New

func New(options ...Option) (Solver, error)

type Tracer

type Tracer interface {
	Trace(p SearchPosition)
}

Jump to

Keyboard shortcuts

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