variable

package
v0.0.0-...-c864ae1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: BSD-2-Clause, BSD-3-Clause, MIT Imports: 10 Imported by: 0

Documentation

Overview

Variable package supplies generalised model variables that allow watchers of models to make decisions on those models by reacting the changes in model decision variables. Decision variables for a model are considered part of that model's public interface.

Index

Constants

View Source
const KeyNotFound = -1
View Source
const NullDecisionVariableName = "NullDecisionVariable"

Variables

View Source
var NullDecisionVariable = new(nullDecisionVariable)

Functions

This section is empty.

Types

type Bounded

type Bounded interface {
	WithinBounds(value float64) bool
	BoundErrorAsText(value float64) string
}

type Bounds

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

func (*Bounds) BoundErrorAsText

func (vb *Bounds) BoundErrorAsText(value float64) string

func (*Bounds) SetMaximum

func (vb *Bounds) SetMaximum(maximum float64)

func (*Bounds) WithinBounds

func (vb *Bounds) WithinBounds(value float64) bool

type ChangeCommand

type ChangeCommand interface {
	command.Command
	Value() float64
	SetChange(change float64)
	Change() float64
}

type ChangePerPlanningUnitDecisionVariableCommand

type ChangePerPlanningUnitDecisionVariableCommand struct {
	command.BaseCommand
	// contains filtered or unexported fields
}

func (*ChangePerPlanningUnitDecisionVariableCommand) Change

func (*ChangePerPlanningUnitDecisionVariableCommand) Do

func (*ChangePerPlanningUnitDecisionVariableCommand) DoUnguarded

func (*ChangePerPlanningUnitDecisionVariableCommand) ForVariable

func (*ChangePerPlanningUnitDecisionVariableCommand) InPlanningUnit

func (*ChangePerPlanningUnitDecisionVariableCommand) PlanningUnit

func (*ChangePerPlanningUnitDecisionVariableCommand) SetChange

func (c *ChangePerPlanningUnitDecisionVariableCommand) SetChange(changeValue float64)

func (*ChangePerPlanningUnitDecisionVariableCommand) Undo

func (*ChangePerPlanningUnitDecisionVariableCommand) UndoUnguarded

func (*ChangePerPlanningUnitDecisionVariableCommand) UndoneValue

func (*ChangePerPlanningUnitDecisionVariableCommand) Value

func (*ChangePerPlanningUnitDecisionVariableCommand) Variable

func (*ChangePerPlanningUnitDecisionVariableCommand) WithChange

type ContainedDecisionVariableObservers

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

func (*ContainedDecisionVariableObservers) Observers

func (*ContainedDecisionVariableObservers) Subscribe

func (c *ContainedDecisionVariableObservers) Subscribe(observers ...Observer)

type ContainedDecisionVariables

type ContainedDecisionVariables struct {
	UndoableDecisionVariables
}

func (*ContainedDecisionVariables) CreationOrderedVariables

func (c *ContainedDecisionVariables) CreationOrderedVariables() UndoableDecisionVariables

func (*ContainedDecisionVariables) DecisionVariable

func (c *ContainedDecisionVariables) DecisionVariable(name string) DecisionVariable

func (*ContainedDecisionVariables) DecisionVariableChange

func (c *ContainedDecisionVariables) DecisionVariableChange(variableName string) float64

func (*ContainedDecisionVariables) DecisionVariableNames

func (c *ContainedDecisionVariables) DecisionVariableNames() []string

func (*ContainedDecisionVariables) Initialise

func (c *ContainedDecisionVariables) Initialise()

func (*ContainedDecisionVariables) NameMappedVariables

func (c *ContainedDecisionVariables) NameMappedVariables() *DecisionVariableMap

func (*ContainedDecisionVariables) OffersDecisionVariable

func (c *ContainedDecisionVariables) OffersDecisionVariable(name string) bool

type DecisionVariable

type DecisionVariable interface {
	// Name returns the model-centric name of the DecisionVariable.
	// Decision variables are expected to have unique names within a model.
	name.Nameable

	Value() float64
	SetValue(value float64)

	UnitOfMeasure() UnitOfMeasure
	Precision() Precision
}

DecisionVariable describes an interface between a Model and any decision making logic observing the model via its decision variables. This Value of a decision Variable should be a fine-grained indicator of how well a model is doing against some objective we have for that model. There should be one decision Variable representing each objective being evaluated for a model.

type DecisionVariableMap

type DecisionVariableMap map[string]DecisionVariable

func (DecisionVariableMap) SortedKeyIndex

func (m DecisionVariableMap) SortedKeyIndex(key string) int

func (DecisionVariableMap) SortedKeys

func (m DecisionVariableMap) SortedKeys() (keys []string)

type EncodeableDecisionVariable

type EncodeableDecisionVariable struct {
	Name                 string
	Value                float64
	Measure              UnitOfMeasure      `json:"UnitOfMeasure"`
	ValuePerPlanningUnit PlanningUnitValues `json:",omitempty"`
}

func MakeEncodeable

func MakeEncodeable(variable DecisionVariable) EncodeableDecisionVariable

func (*EncodeableDecisionVariable) MarshalJSON

func (v *EncodeableDecisionVariable) MarshalJSON() ([]byte, error)

type EncodeableDecisionVariables

type EncodeableDecisionVariables []EncodeableDecisionVariable

func (EncodeableDecisionVariables) Len

func (EncodeableDecisionVariables) Less

func (v EncodeableDecisionVariables) Less(i, j int) bool

func (EncodeableDecisionVariables) Swap

func (v EncodeableDecisionVariables) Swap(i, j int)

type NullChangeCommand

type NullChangeCommand struct{}

func (*NullChangeCommand) Change

func (c *NullChangeCommand) Change() float64

func (*NullChangeCommand) Do

func (*NullChangeCommand) Reset

func (c *NullChangeCommand) Reset()

func (*NullChangeCommand) SetChange

func (c *NullChangeCommand) SetChange(change float64)

func (*NullChangeCommand) Undo

func (*NullChangeCommand) Value

func (c *NullChangeCommand) Value() float64

type Observable

type Observable interface {
	Subscribe(observers ...Observer)
}

type Observer

type Observer interface {
	ObserveDecisionVariable(variable DecisionVariable)
}

type PerPlanningUnitDecisionVariable

type PerPlanningUnitDecisionVariable struct {
	SimpleDecisionVariable
	ContainedDecisionVariableObservers
	// contains filtered or unexported fields
}

func NewPerPlanningUnitDecisionVariable

func NewPerPlanningUnitDecisionVariable() *PerPlanningUnitDecisionVariable

func (*PerPlanningUnitDecisionVariable) Initialise

func (*PerPlanningUnitDecisionVariable) NotifyObservers

func (v *PerPlanningUnitDecisionVariable) NotifyObservers()

func (*PerPlanningUnitDecisionVariable) PlanningUnitValue

func (v *PerPlanningUnitDecisionVariable) PlanningUnitValue(planningUnit planningunit.Id) float64

func (*PerPlanningUnitDecisionVariable) SetPlanningUnitValue

func (v *PerPlanningUnitDecisionVariable) SetPlanningUnitValue(planningUnit planningunit.Id, newPlanningUnitValue float64)

func (*PerPlanningUnitDecisionVariable) ValuesPerPlanningUnit

func (v *PerPlanningUnitDecisionVariable) ValuesPerPlanningUnit() PlanningUnitValueMap

type PlanningUnitDecisionVariable

type PlanningUnitDecisionVariable interface {
	DecisionVariable
	ValuesPerPlanningUnit() PlanningUnitValueMap
	SetPlanningUnitValue(planningUnit planningunit.Id, newValue float64)
	PlanningUnitValue(planningUnit planningunit.Id) float64
}

type PlanningUnitValue

type PlanningUnitValue struct {
	PlanningUnit planningunit.Id
	Value        float64
}

type PlanningUnitValueMap

type PlanningUnitValueMap map[planningunit.Id]float64

type PlanningUnitValues

type PlanningUnitValues []PlanningUnitValue

func (PlanningUnitValues) Len

func (v PlanningUnitValues) Len() int

func (PlanningUnitValues) Less

func (v PlanningUnitValues) Less(i, j int) bool

func (PlanningUnitValues) Swap

func (v PlanningUnitValues) Swap(i, j int)

type Precision

type Precision int

type SimpleDecisionVariable

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

func NewSimpleDecisionVariable

func NewSimpleDecisionVariable(name string) *SimpleDecisionVariable

func (*SimpleDecisionVariable) Name

func (v *SimpleDecisionVariable) Name() string

func (*SimpleDecisionVariable) Precision

func (v *SimpleDecisionVariable) Precision() Precision

func (*SimpleDecisionVariable) SetName

func (v *SimpleDecisionVariable) SetName(name string)

func (*SimpleDecisionVariable) SetPrecision

func (v *SimpleDecisionVariable) SetPrecision(precision Precision)

func (*SimpleDecisionVariable) SetUnitOfMeasure

func (v *SimpleDecisionVariable) SetUnitOfMeasure(measure UnitOfMeasure)

func (*SimpleDecisionVariable) SetValue

func (v *SimpleDecisionVariable) SetValue(value float64)

func (*SimpleDecisionVariable) UnitOfMeasure

func (v *SimpleDecisionVariable) UnitOfMeasure() UnitOfMeasure

func (*SimpleDecisionVariable) Value

func (v *SimpleDecisionVariable) Value() float64

type SimpleUndoableDecisionVariable

type SimpleUndoableDecisionVariable struct {
	SimpleDecisionVariable

	ContainedDecisionVariableObservers
	// contains filtered or unexported fields
}

func NewUndoableDecisionVariable

func NewUndoableDecisionVariable(name string) *SimpleUndoableDecisionVariable

func (*SimpleUndoableDecisionVariable) ApplyDoneValue

func (v *SimpleUndoableDecisionVariable) ApplyDoneValue()

func (*SimpleUndoableDecisionVariable) ApplyUndoneValue

func (v *SimpleUndoableDecisionVariable) ApplyUndoneValue()

func (*SimpleUndoableDecisionVariable) DifferenceInValues

func (v *SimpleUndoableDecisionVariable) DifferenceInValues() float64

func (*SimpleUndoableDecisionVariable) SetUndoableChange

func (v *SimpleUndoableDecisionVariable) SetUndoableChange(change float64)

func (*SimpleUndoableDecisionVariable) SetUndoableValue

func (v *SimpleUndoableDecisionVariable) SetUndoableValue(value float64)

func (*SimpleUndoableDecisionVariable) UndoableValue

func (v *SimpleUndoableDecisionVariable) UndoableValue() float64

type UndoableDecisionVariable

type UndoableDecisionVariable interface {
	DecisionVariable

	// UndoableValue returns an "inductive" Value for the variableOld.  This Value cannot become the
	// actual (induced) Value for the variableOld without a call to ApplyDoneValue.
	UndoableValue() float64

	// SetUndoableValue allows an "undoable"vValue for the variable to be set.  This undoable Value is not the
	// variable's actual value. It is a Value that would result (or be induced) from, some management action change.
	// This Value  is expected to be a temporary, lasting only as long as it takes for decision-making logic to decide
	// whether to accept the variable value, or reject/undo it.
	SetUndoableValue(value float64)

	// DifferenceInValues report the difference in taking the variableOld's actual Value for its inductive Value.
	// This difference is often used in decision making around whether to accept the inductive Value.
	DifferenceInValues() float64

	// Accepts the inductive Value of the variableOld as the variableOld's actual Value.
	ApplyDoneValue()

	// Rejects the inductive Value of the variableOld, resetting the inductive Value to the variableOld's actual Value.
	ApplyUndoneValue()
}

UndoableDecisionVariable is a DecisionVariable that allows an 'inductive' Value to be temporarily stored and retrieved for the decision variableOld (typically based based on some management action change). The induced Value does not become the actual Value for the decision variableOld without being explicitly accepted. The induced Value can also be rejected, which sees it revert to the actual Value of the variableOld.

type UndoableDecisionVariables

type UndoableDecisionVariables []UndoableDecisionVariable

UndoableDecisionVariables offers up a name-indexed collection of UndoableDecisionVariable instances, along with convenience methods for the collection's management. It is typically expected that a model would contain only a single instance of UndoableDecisionVariables to house all of its decision variables.

func NewUndoableDecisionVariables

func NewUndoableDecisionVariables() UndoableDecisionVariables

func (*UndoableDecisionVariables) AcceptAll

func (vs *UndoableDecisionVariables) AcceptAll()

AcceptAll accepts the inductive Value of all the BaseInductiveDecisionVariable instances in its collection.

func (*UndoableDecisionVariables) Add

func (vs *UndoableDecisionVariables) Add(newVariables ...UndoableDecisionVariable)

Adds a number of UndoableDecisionVariables to the collection

func (*UndoableDecisionVariables) DifferenceInValues

func (vs *UndoableDecisionVariables) DifferenceInValues(variableName string) float64

DifferenceInValues reports the difference in values of the variableOld in its collection with the supplied name.

func (*UndoableDecisionVariables) NewForName

func (vs *UndoableDecisionVariables) NewForName(name string)

NewForName creates and adds to its collection, a new BaseInductiveDecisionVariable with the supplied name.

func (*UndoableDecisionVariables) RejectAll

func (vs *UndoableDecisionVariables) RejectAll()

RejectAll rejects the inductive Value of all the BaseInductiveDecisionVariable instances in its collection.

func (*UndoableDecisionVariables) SetValue

func (vs *UndoableDecisionVariables) SetValue(name string, value float64)

SetValue finds the variableOld with supplied name in its collection, and sets its Value appropriately. If the collection has no variableOld for the supplied name, it panics.

func (*UndoableDecisionVariables) Value

func (vs *UndoableDecisionVariables) Value(name string) float64

Value returns the Value of the variableOld in its collection with the supplied name. If the collection has no variableOld for the supplied name, it panics.

func (*UndoableDecisionVariables) Variable

Variable returns a pointer to the variableOld in its collection with the supplied name. If the collection has no variableOld for the supplied name, it panics.

type UndoableValueCommand

type UndoableValueCommand struct {
	command.BaseCommand
	// contains filtered or unexported fields
}

func (*UndoableValueCommand) Change

func (c *UndoableValueCommand) Change() float64

func (*UndoableValueCommand) Do

func (*UndoableValueCommand) DoUnguarded

func (c *UndoableValueCommand) DoUnguarded()

func (*UndoableValueCommand) ForVariable

func (*UndoableValueCommand) SetChange

func (c *UndoableValueCommand) SetChange(changeValue float64)

func (*UndoableValueCommand) SetValue

func (c *UndoableValueCommand) SetValue(value float64)

func (*UndoableValueCommand) Undo

func (*UndoableValueCommand) UndoUnguarded

func (c *UndoableValueCommand) UndoUnguarded()

func (*UndoableValueCommand) Value

func (c *UndoableValueCommand) Value() float64

func (*UndoableValueCommand) Variable

func (*UndoableValueCommand) WithChange

func (c *UndoableValueCommand) WithChange(changeValue float64) *UndoableValueCommand

func (*UndoableValueCommand) WithValue

func (c *UndoableValueCommand) WithValue(value float64) *UndoableValueCommand

type UnitOfMeasure

type UnitOfMeasure string
const (
	NotApplicable UnitOfMeasure = "Not Applicable (NA)"
	TonnesPerYear UnitOfMeasure = "Tonnes per Year (t/y)"
	Dollars       UnitOfMeasure = "Dollars ($)"
)

func (UnitOfMeasure) String

func (uom UnitOfMeasure) String() string

Jump to

Keyboard shortcuts

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