logic

package
v0.0.0-...-dccb852 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	Name    string
	MinSize int
	MaxSize int
	Items   []*Item
}

Group is passed to GetArrangement to indicate what groups there are and how full they can be. Items will be populated by GetArrangement.

func GetArrangement

func GetArrangement(ctx context.Context, items []*Item, rules []*Rule, groups []*Group) ([]*Group, error)

GetArrangement is the primary workhorse of the algorithm. Given a set of items, rules, and groups to fill, it returns copies of the Groups with Items filled in matching the rules.

func MustGetArrangement

func MustGetArrangement(items []*Item, rules []*Rule, groups []*Group) []*Group

MustGetArrangement calls GetArrangement but panics on failures. Good for testing.

func (*Group) Copy

func (g *Group) Copy() *Group

Copy creates a copy of a Group so it can be modified for a new State. Note that Items are not deep copied as we don't modify these.

type Item

type Item struct {
	// ID must be unique to each item
	ID string

	// Map of tag names to tag values for this item
	Tags map[string]string
	// contains filtered or unexported fields
}

Item defines a thing or person that has a set of tags and needs to be arranged into groups.

type Rule

type Rule struct {
	// Tag name to which this rule applies
	TagName string

	// What type of rule this is (see RuleType)
	Type RuleType

	// How important this rule is relative to the other rules
	Weight int
}

Rule is one instance of an input rule. There could potentially be multiple rules on the same tag and/or of the same type.

type RuleType

type RuleType string

RuleType definitions control the behavior of a rule and can be found below.

const (
	// Try to keep items together that share the same value for this tag.
	RuleTypeSameness RuleType = "Sameness"

	// Interpret the tag value as the ID of another item, and try to keep these items together.
	RuleTypeRelationship RuleType = "Relationship"

	// Try to interpret the given tag value as a geolocation and put nearby items together.
	RuleTypeNearness RuleType = "Nearness"
)

type State

type State struct {
	// Groups which include items that may have been put in them in this state
	Groups []*Group

	// Items that haven't been put into groups yet for this state
	ItemsNotInGroups []*Item

	// Score is higher the better this State follows the provided rules.
	// If this state is non-terminal (i.e. not all items are in groups yet), then Score is a heuristically guessed
	// maximum score this state may end up producing after further iteration.
	Score float64
}

State represents a particular arrangement of items in the groups, which may be intermediate/non-terminal. I.e. not everyone has been placed in a group yet.

func (*State) Copy

func (s *State) Copy() *State

Copy produces a new State that can be modified without messing with the old State. NOTE: Items themselves are not deep copied since we don't modify those.

func (*State) IsTerminal

func (s *State) IsTerminal() bool

IsTerminal returns true if this state is a complete arrangement, every item has been put in a group.

Jump to

Keyboard shortcuts

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