rules

package
v0.0.0-...-95be186 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SingleValueVariableEntry = 0

Variables

View Source
var StaticVariables = [...]VariableValuePair{
	{
		VariableName: NumberOfIslandsContributingToCommonPool,
		Values:       []float64{5},
	},
	{
		VariableName: NumberOfFailedForages,
		Values:       []float64{0.5},
	},
	{
		VariableName: NumberOfBrokenAgreements,
		Values:       []float64{1},
	},
	{
		VariableName: MaxSeverityOfSanctions,
		Values:       []float64{2},
	},
	{
		VariableName: NumberOfIslandsAlive,
		Values:       []float64{6},
	},
	{
		VariableName: NumberOfBallotsCast,
		Values:       []float64{6},
	},
	{
		VariableName: NumberOfAllocationsSent,
		Values:       []float64{6},
	},
	{
		VariableName: IslandsAlive,
		Values:       []float64{0, 1, 2, 3, 4, 5},
	},
	{
		VariableName: SpeakerSalary,
		Values:       []float64{50},
	},
	{
		VariableName: SpeakerPayment,
		Values:       []float64{50},
	},
	{
		VariableName: SpeakerPaid,
		Values:       []float64{0},
	},
	{
		VariableName: SpeakerBudgetIncrement,
		Values:       []float64{100},
	},
	{
		VariableName: JudgeSalary,
		Values:       []float64{50},
	},
	{
		VariableName: JudgePayment,
		Values:       []float64{50},
	},
	{
		VariableName: JudgePaid,
		Values:       []float64{0},
	},
	{
		VariableName: JudgeBudgetIncrement,
		Values:       []float64{100},
	},
	{
		VariableName: PresidentSalary,
		Values:       []float64{50},
	},
	{
		VariableName: PresidentPayment,
		Values:       []float64{50},
	},
	{
		VariableName: PresidentPaid,
		Values:       []float64{0},
	},
	{
		VariableName: PresidentBudgetIncrement,
		Values:       []float64{100},
	},
	{
		VariableName: ExpectedTaxContribution,
		Values:       []float64{0},
	},
	{
		VariableName: ExpectedAllocation,
		Values:       []float64{0},
	},
	{
		VariableName: IslandTaxContribution,
		Values:       []float64{0},
	},
	{
		VariableName: IslandAllocation,
		Values:       []float64{0},
	},
	{
		VariableName: RuleSelected,
		Values:       []float64{0},
	},
	{
		VariableName: VoteCalled,
		Values:       []float64{0},
	},
	{
		VariableName: IslandReportedResources,
		Values:       []float64{0},
	},
	{
		VariableName: ConstSanctionAmount,
		Values:       []float64{0},
	},
	{
		VariableName: TurnsLeftOnSanction,
		Values:       []float64{0},
	},
	{
		VariableName: SanctionPaid,
		Values:       []float64{0},
	},
	{
		VariableName: SanctionExpected,
		Values:       []float64{0},
	},
	{
		VariableName: AllocationRequestsMade,
		Values:       []float64{1},
	},
	{
		VariableName: AllocationMade,
		Values:       []float64{0},
	},
	{
		VariableName: JudgeInspectionPerformed,
		Values:       []float64{0},
	},
	{
		VariableName: MonitorRoleAnnounce,
		Values:       []float64{0},
	},
	{
		VariableName: MonitorRoleDecideToMonitor,
		Values:       []float64{0},
	},
	{
		VariableName: MonitorRoleEvalResult,
		Values:       []float64{0},
	},
	{
		VariableName: MonitorRoleEvalResultDecide,
		Values:       []float64{0},
	},
	{
		VariableName: VoteResultAnnounced,
		Values:       []float64{0},
	},
	{
		VariableName: AllIslandsAllowedToVote,
		Values:       []float64{0},
	},
	{
		VariableName: SpeakerProposedPresidentRule,
		Values:       []float64{0},
	},
	{
		VariableName: PresidentRuleProposal,
		Values:       []float64{0},
	},
	{
		VariableName: RuleChosenFromProposalList,
		Values:       []float64{0},
	},
	{
		VariableName: AnnouncementRuleMatchesVote,
		Values:       []float64{0},
	},
	{
		VariableName: AnnouncementResultMatchesVote,
		Values:       []float64{0},
	},
	{
		VariableName: PresidentLeftoverBudget,
		Values:       []float64{0},
	},
	{
		VariableName: SpeakerLeftoverBudget,
		Values:       []float64{0},
	},
	{
		VariableName: JudgeLeftoverBudget,
		Values:       []float64{0},
	},
	{
		VariableName: IslandsProposedRules,
		Values:       []float64{0},
	},
	{
		VariableName: HasIslandReportPrivateResources,
		Values:       []float64{0},
	},
	{
		VariableName: IslandActualPrivateResources,
		Values:       []float64{0},
	},
	{
		VariableName: IslandReportedPrivateResources,
		Values:       []float64{0},
	},
	{
		VariableName: JudgeHistoricalRetributionPerformed,
		Values:       []float64{0},
	},
	{
		VariableName: TermEnded,
		Values:       []float64{0},
	},
	{
		VariableName: ElectionHeld,
		Values:       []float64{0},
	},
	{
		VariableName: AppointmentMatchesVote,
		Values:       []float64{0},
	},
	{
		VariableName: TaxDecisionMade,
		Values:       []float64{1},
	},
}

StaticVariables holds all globally defined variables

Functions

func ComplianceCheck

func ComplianceCheck(rule RuleMatrix, variables map[VariableFieldName]VariableValuePair, inPlayRules map[string]RuleMatrix) (compliant bool, ruleError error)

ComplianceCheck Gives a simple check for compliance to clients, they just need to feed in a RuleMatrix and the variable cache they want to feed from

func ComplianceRecommendation

func ComplianceRecommendation(rule RuleMatrix, variables map[VariableFieldName]VariableValuePair) (map[VariableFieldName]VariableValuePair, bool)

ComplianceRecommendation *attempts* to calculate a set of variables that comply with a rule if the input variables don't satisfy it already

func CopyRulesMap

func CopyRulesMap(rulesMap map[string]RuleMatrix) map[string]RuleMatrix

func CopyVariableMap

CopyVariableMap easily copies variable cache

func InitialRuleRegistration

func InitialRuleRegistration(startWithRules bool) (AvailableRules map[string]RuleMatrix, RulesInPlay map[string]RuleMatrix)

Init Registers all global scoped rules

func InitialVarRegistration

func InitialVarRegistration() map[VariableFieldName]VariableValuePair

init Registers all variables defined in Static variables list

func IsChangeable

func IsChangeable() map[VariableFieldName]bool

func ModifyRuleInternal

func ModifyRuleInternal(rulename string, newMatrix mat.Dense, newAuxiliary mat.VecDense, rulesCache map[string]RuleMatrix, inPlayCache map[string]RuleMatrix) error

func PickUpRulesByVariable

func PickUpRulesByVariable(variableName VariableFieldName, ruleStore map[string]RuleMatrix, variableMap map[VariableFieldName]VariableValuePair) ([]string, bool)

PickUpRulesByVariable returns a list of rule_id's which are affected by certain variables.

func PullRuleIntoPlayInternal

func PullRuleIntoPlayInternal(rulename string, allRules map[string]RuleMatrix, playRules map[string]RuleMatrix) error

PullRuleIntoPlayInternal provides primal rule engagement logic for any pair of caches

func PullRuleOutOfPlayInternal

func PullRuleOutOfPlayInternal(rulename string, allRules map[string]RuleMatrix, playRules map[string]RuleMatrix) error

PullRuleOutOfPlayInternal provides primal rule disengagement logic for any pair of caches

func RegisterNewVariableInternal

func RegisterNewVariableInternal(pair VariableValuePair, variableStore map[VariableFieldName]VariableValuePair) error

RegisterNewVariableInternal provides primal register logic for any variable cache

func UpdateVariableInternal

func UpdateVariableInternal(variableName VariableFieldName, newValue VariableValuePair, variableStore map[VariableFieldName]VariableValuePair) bool

UpdateVariableInternal provides primal update logic for any variable cache

Types

type LinkTypeOption

type LinkTypeOption int

LinkTypeOption gives an enumerated type for the various link types available for rules

const (
	// ParentFailAutoRulePass allows for NOT(Parent Passes) || Parent and Child pass
	// Useful for cases where if a condition isn't met we don't want to evaluate a rule
	ParentFailAutoRulePass LinkTypeOption = iota
	NoLink
)

type RawRuleSpecification

type RawRuleSpecification struct {
	Name       string
	ReqVar     []VariableFieldName
	Values     []float64
	Aux        []float64
	Mutable    bool
	Linked     bool
	LinkType   LinkTypeOption
	LinkedRule string
}

RawRuleSpecification allows a user to use the CompileRuleCase function to build a rule matrix

type RuleError

type RuleError struct {
	ErrorType RuleErrorType
	Err       error
}

RuleError provides a packaged version of the RuleErrorType for clients to deal with

func (*RuleError) Error

func (e *RuleError) Error() string

func (*RuleError) Type

func (e *RuleError) Type() RuleErrorType

type RuleErrorType

type RuleErrorType int

RuleErrorType is a non-critical issue which can be caused by an island trying to modify, register or pick rules which isn't mechanically feasible

const (
	RuleNotInAvailableRulesCache RuleErrorType = iota
	ModifiedRuleMatrixDimensionMismatch
	AuxVectorDimensionDontMatchRuleMatrix
	RuleRequestedForModificationWasImmutable
	TriedToReRegisterRule
	RuleIsAlreadyInPlay
	RuleIsNotInPlay
	VariableCacheDidNotHaveAllRequiredVariables
	VariableVectDimsDoNotMatchRuleMatrix
	AuxVectorCodeOutOfRange
	ChildRuleNotFound
)

RuleError enum allows for programmatic handling of Rule related errors .String() function available for printing in logs

func (RuleErrorType) GoString

func (r RuleErrorType) GoString() string

GoString implements GoStringer

func (RuleErrorType) MarshalJSON

func (r RuleErrorType) MarshalJSON() ([]byte, error)

MarshalJSON implements RawMessage

func (RuleErrorType) MarshalText

func (r RuleErrorType) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (RuleErrorType) String

func (r RuleErrorType) String() string

type RuleEvaluationReturn

type RuleEvaluationReturn struct {
	RulePasses    bool
	IsRealOutput  bool
	RealOutputVal float64
	EvalError     error
}

RuleEvaluationReturn provides a wrapped for the results of a rule evaluation

func EvaluateRuleFromCaches

func EvaluateRuleFromCaches(ruleName string, rulesCache map[string]RuleMatrix, variableCache map[VariableFieldName]VariableValuePair) RuleEvaluationReturn
type RuleLink struct {
	Linked     bool
	LinkType   LinkTypeOption
	LinkedRule string
}

RuleLink provides a containerised package for all linked rules

type RuleMatrix

type RuleMatrix struct {
	RuleName          string
	RequiredVariables []VariableFieldName
	ApplicableMatrix  mat.Dense
	AuxiliaryVector   mat.VecDense
	Mutable           bool
	Link              RuleLink
}

RuleMatrix provides a container for our matrix based rules

func CompileRuleCase

func CompileRuleCase(spec RawRuleSpecification) (RuleMatrix, bool)

CompileRuleCase allows an agent to quickly build a RuleMatrix using the RawRuleSpecification

func RegisterNewRuleInternal

func RegisterNewRuleInternal(ruleName string, requiredVariables []VariableFieldName, applicableMatrix mat.Dense, auxiliaryVector mat.VecDense, ruleStore map[string]RuleMatrix, mutable bool, link RuleLink) (constructedMatrix *RuleMatrix, Error error)

RegisterNewRuleInternal provides primal register logic for any rule cache

func (*RuleMatrix) RuleMatrixIsEmpty

func (r *RuleMatrix) RuleMatrixIsEmpty() bool

RuleMatrixIsEmpty returns true is the RuleMatrix is uninitialised

type VariableFieldName

type VariableFieldName int
const (
	NumberOfIslandsContributingToCommonPool VariableFieldName = iota
	NumberOfFailedForages
	NumberOfBrokenAgreements
	MaxSeverityOfSanctions
	NumberOfIslandsAlive
	NumberOfBallotsCast
	NumberOfAllocationsSent
	AllocationRequestsMade
	AllocationMade
	IslandsAlive
	SpeakerSalary
	SpeakerPayment
	SpeakerPaid
	SpeakerBudgetIncrement
	JudgeSalary
	JudgePayment
	JudgePaid
	JudgeBudgetIncrement
	PresidentSalary
	PresidentPayment
	PresidentPaid
	PresidentBudgetIncrement
	RuleSelected
	VoteCalled
	ExpectedTaxContribution
	ExpectedAllocation
	IslandTaxContribution
	IslandAllocation
	IslandReportedResources
	ConstSanctionAmount
	TurnsLeftOnSanction
	SanctionPaid
	SanctionExpected
	TestVariable
	JudgeInspectionPerformed
	TaxDecisionMade
	MonitorRoleAnnounce
	MonitorRoleDecideToMonitor
	MonitorRoleEvalResult
	MonitorRoleEvalResultDecide
	VoteResultAnnounced
	AllIslandsAllowedToVote
	SpeakerProposedPresidentRule
	PresidentRuleProposal
	RuleChosenFromProposalList
	AnnouncementRuleMatchesVote
	AnnouncementResultMatchesVote
	PresidentLeftoverBudget
	SpeakerLeftoverBudget
	JudgeLeftoverBudget
	IslandsProposedRules
	HasIslandReportPrivateResources
	IslandActualPrivateResources
	IslandReportedPrivateResources
	JudgeHistoricalRetributionPerformed
	TermEnded
	ElectionHeld
	AppointmentMatchesVote
)

func (VariableFieldName) GoString

func (v VariableFieldName) GoString() string

GoString implements GoStringer

func (VariableFieldName) MarshalJSON

func (v VariableFieldName) MarshalJSON() ([]byte, error)

MarshalJSON implements RawMessage

func (VariableFieldName) MarshalText

func (v VariableFieldName) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler

func (VariableFieldName) String

func (v VariableFieldName) String() string

type VariableValuePair

type VariableValuePair struct {
	VariableName VariableFieldName
	Values       []float64
}

func MakeVariableValuePair

func MakeVariableValuePair(variable VariableFieldName, value []float64) VariableValuePair

MakeVariableValuePair creates a VariableValuePair from the variable name and its value

Jump to

Keyboard shortcuts

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