abm

package
v0.0.0-...-59476ba Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBG background for visualisation
	DefaultBG = colour.RGB{Red: 0.423529411765, Green: 0.376470588235, Blue: 0.376470588235}

	// DefaultEnvironment to be used as a baseline example
	DefaultEnvironment = Environment{
		Bounds:         []float64{d, d},
		Dimensionality: dimensionality,
		BG:             DefaultBG,
	}

	// DefaultConditionParams to be used as a baseline example
	DefaultConditionParams = ConditionParams{
		Environment:              DefaultEnvironment,
		CpPreyPopulationStart:    dCpPreyPopStart,
		CpPreyPopulationCap:      dCpPreyPopCap,
		CpPreyAgeing:             dCpPreyAgeing,
		CpPreyLifespan:           dCpPreyLifespan,
		CpPreyS:                  dCpPreyMovS,
		CpPreyA:                  1.0,
		CpPreyTurn:               dCpPreyTurn,
		CpPreySr:                 dCpPreyTurn,
		CpPreyGestation:          dCpPreyGestation,
		CpPreySexualCost:         dCpPreySexualCost,
		CpPreyReproductionChance: dCpPreyReproductionChance,
		CpPreySpawnSize:          dCpPreySpawnSize,
		VpPopulationStart:        dVpPopStart,
		VpPopulationCap:          dVpPopCap,
		VpAgeing:                 dVpAgeing,
		VpLifespan:               dVpLifespan,
		VpStarvationPoint:        dVpStarvationPoint,
		VpMovS:                   dVpMovS,
		VpMovA:                   1.0,
		VpTurn:                   dVpTurn,
		VpVsr:                    dVpVsr,
		VpVb𝛄:                    dV𝛄,
		VpV𝛄Bump:                 dVpV𝛄Bump,
		VpReproductionChance:     dVpReproductiveChance,
		VpSexualRequirement:      dVpSexualRequirement,
		VpGestation:              dVpGestation,
		VpSearchChance:           dVpSearchChance,
		VpAttackChance:           dVpAttackChance,
		VpCaf:                    dVpColAdaptationFactor,
		CpPreyMutationFactor:     dCpPreyMf,
		VpStarvation:             dVpStarvation,
		RandomAges:               dRandomAges,
		RNGRandomSeed:            dRNGRandomSeed,
		RNGSeedVal:               dRNGSeedVal,
		Fuzzy:                    dFuzzy,
	}

	// TestConditionParams to be used for unit testing.
	TestConditionParams = ConditionParams{
		Environment:              DefaultEnvironment,
		CpPreyPopulationStart:    tCpPreyPopStart,
		CpPreyPopulationCap:      tCpPreyPopCap,
		CpPreyAgeing:             tCpPreyAgeing,
		CpPreyLifespan:           tCpPreyLifespan,
		CpPreyS:                  tCpPreyMovS,
		CpPreyA:                  1.0,
		CpPreyTurn:               tCpPreyTurn,
		CpPreySr:                 tCpPreyTurn,
		CpPreyGestation:          tCpPreyGestation,
		CpPreySexualCost:         tCpPreySexualCost,
		CpPreyReproductionChance: tCpPreyReproductionChance,
		CpPreySpawnSize:          tCpPreySpawnSize,
		VpPopulationStart:        tVpPopStart,
		VpPopulationCap:          tVpPopCap,
		VpAgeing:                 tVpAgeing,
		VpLifespan:               tVpLifespan,
		VpStarvationPoint:        tVpStarvationPoint,
		VpMovS:                   tVpMovS,
		VpMovA:                   1.0,
		VpTurn:                   tVpTurn,
		VpVsr:                    tVpVpVsr,
		VpVb𝛄:                    tV𝛄,
		VpV𝛄Bump:                 tVpV𝛄Bump,
		VpVbε:                    tVpVbε,
		VpBaseAttackGain:         tVpBaseAttackGain,
		VpReproductionChance:     tVpReproductiveChance,
		VpSearchChance:           tVpSearchChance,
		VpAttackChance:           tVpAttackChance,
		VpCaf:                    tVpColAdaptationFactor,
		CpPreyMutationFactor:     tCpPreyMf,
		VpStarvation:             tVpStarvation,
		RandomAges:               tRandomAges,
		RNGRandomSeed:            tRNGRandomSeed,
		RNGSeedVal:               tRNGSeedVal,
		Fuzzy:                    tFuzzy,
		Logging:                  tLogging,
		LogFreq:                  tLogFreq,
		UseCustomLogPath:         tUseCustomLogPath,
		CustomLogPath:            tCustomLogPath,
		LimitDuration:            tLimitDuration,
		FixedDuration:            tFixedDuration,
		SessionIdentifier:        tSessionIdentifier,
	}

	// PresetParams holds the parameters defined at the time of `abm-cp run`. If the [-l | --load] param is not specififed, then the default conditions will be used.
	PresetParams = DefaultConditionParams
)

Functions

func TestCPPComparitorSort

func TestCPPComparitorSort(t *testing.T)

func TestDefaultModelCreation

func TestDefaultModelCreation(t *testing.T)

func TestOptimalAttackVectorSort

func TestOptimalAttackVectorSort(t *testing.T)

Types

type AgentDescription

type AgentDescription struct {
	AgentType  string `json:"agent-type"`
	AgentNum   int    `json:"agent-num"`
	ParentUUID string `json:"parent"`
	CreatedMT  int    `json:"creation-turn"`
	CreatedAT  string `json:"creation-date"`
}

AgentDescription used to aid for logging / debugging - used at time of agent creation

type AgentPopulations

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

AgentPopulations collects slices of agent types of the `abm` package active in a model instance.

type Client

type Client interface {
	Monitor(chan struct{})
	Dead() bool
	TimeStamp() time.Time
}

Client is the wrapper interface between the different comm protocols with the 'user' / 'caller' and the Model.

type ColourPolymorphicPrey

type ColourPolymorphicPrey struct {
	𝚯 float64 //	 heading angle
	// contains filtered or unexported fields
}

ColourPolymorphicPrey – Prey agent type for Predator-Prey ABM

func GenerateCpPreyPopulation

func GenerateCpPreyPopulation(size int, start int, mt int, conditions ConditionParams, timestamp string) []ColourPolymorphicPrey

GenerateCpPreyPopulation will create `size` number of Colour Polymorphic Prey agents

func (*ColourPolymorphicPrey) Action

func (c *ColourPolymorphicPrey) Action(conditions ConditionParams, popSize int) (newpop []ColourPolymorphicPrey)

Action = Rule Based Behaviour that each cpPrey agent engages in once per turn, counts as the agent's action for that turn/phase.

func (*ColourPolymorphicPrey) Age

func (c *ColourPolymorphicPrey) Age(conditions ConditionParams) (jump string)

Age decrements the lifespan of an agent, and applies the effects of ageing (if any)

func (*ColourPolymorphicPrey) Birth

Birth implemets Breeder interface method for ColourPolymorphicPrey:

func (ColourPolymorphicPrey) GetDrawInfo

func (c ColourPolymorphicPrey) GetDrawInfo() (ar render.AgentRender)

GetDrawInfo exports the data set needed for agent visualisation.

func (ColourPolymorphicPrey) MarshalJSON

func (c ColourPolymorphicPrey) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface on a CP Prey object

func (*ColourPolymorphicPrey) MateSearch

func (c *ColourPolymorphicPrey) MateSearch(pop []ColourPolymorphicPrey, skip int) (mate *ColourPolymorphicPrey, err error)

MateSearch implements Breeder interface method for ColourPolymorphicPrey: NEEDS BETTER HANDLING THAN JUST PUSHING THE ERROR UP!

func (*ColourPolymorphicPrey) Move

func (c *ColourPolymorphicPrey) Move() error

Move implements agent Mover interface method for ColourPolymorphicPrey: updates the agent's position according to its direction (heading) and velocity (speed*acceleration) if it doesn't encounter any errors.

func (*ColourPolymorphicPrey) Reproduction

func (c *ColourPolymorphicPrey) Reproduction(chance float64, gestation int) bool

Reproduction implements Breeder interface method - ASEXUAL (self-reproduction) ColourPolymorphicPrey:

func (*ColourPolymorphicPrey) String

func (c *ColourPolymorphicPrey) String() string

String returns a clear textual presentation the internal values of the CP Prey agent

func (*ColourPolymorphicPrey) Turn

func (c *ColourPolymorphicPrey) Turn(𝚯 float64)

Turn implements agent Mover interface method for ColourPolymorphicPrey: updates 𝚯 and dir vector to the new heading offset by 𝚯

func (*ColourPolymorphicPrey) UUID

func (c *ColourPolymorphicPrey) UUID() string

UUID is just a getter method for the unexported uuid field, which absolutely must not change after agent creation.

type ConditionParams

type ConditionParams struct {
	Environment              `json:"abm-environment"` //	embedded model environment
	CpPreyPopulationStart    int                      `json:"abm-cp-prey-pop-start"`               // starting Prey agent population size
	CpPreyPopulationCap      int                      `json:"abm-cp-prey-pop-cap"`                 //
	CpPreyAgeing             bool                     `json:"abm-cp-prey-ageing"`                  //
	CpPreyLifespan           int                      `json:"abm-cp-prey-lifespan"`                // Prey agent lifespan
	CpPreyS                  float64                  `json:"abm-cp-prey-speed"`                   // Prey agent speed
	CpPreyA                  float64                  `json:"abm-cp-prey-acceleration"`            // Prey agent acceleration
	CpPreyTurn               float64                  `json:"abm-cp-prey-turn"`                    // Prey agent turn rate / range (in radians)
	CpPreySr                 float64                  `json:"abm-cp-prey-sr"`                      // Prey agent search range for mating
	CpPreyGestation          int                      `json:"abm-cp-prey-gestation"`               // Prey gestation period
	CpPreySexualCost         int                      `json:"abm-cp-prey-sexual-cost"`             // Prey sexual rest cost
	CpPreyReproductionChance float64                  `json:"abm-cp-prey-reproduction-chance"`     // chance of CP Prey  copulation success.
	CpPreySpawnSize          int                      `json:"abm-cp-prey-spawn-size"`              // possible number of progeny = [1, max]
	CpPreyMutationFactor     float64                  `json:"abm-cp-prey-mf"`                      // mutation factor
	VpPopulationStart        int                      `json:"abm-vp-pop-start"`                    // starting Predator agent population size
	VpPopulationCap          int                      `json:"abm-vp-pop-cap"`                      //
	VpAgeing                 bool                     `json:"abm-vp-ageing"`                       //
	VpLifespan               int                      `json:"abm-vp-lifespan"`                     // Visual Predator lifespan
	VpStarvationPoint        int                      `json:"abm-vp-starvation-point"`             //
	VpPanicPoint             int                      `json:"abm-vp-panic-point"`                  //
	VpGestation              int                      `json:"abm-vp-gestation"`                    // Visual Predator gestation period
	VpSexualRequirement      int                      `json:"abm-vp-sex-req"`                      //
	VpMovS                   float64                  `json:"abm-vp-speed"`                        // Visual Predator speed
	VpMovA                   float64                  `json:"abm-vp-acceleration"`                 // Visual Predator acceleration
	VpTurn                   float64                  `json:"abm-vp-turn"`                         // Visual Predator turn rate / range (in radians)
	VpVsr                    float64                  `json:"abm-vp-vsr"`                          // Visual Predator visual search range
	VpVb𝛄                    float64                  `json:"abm-vp-visual-search-tolerance"`      //
	VpV𝛄Bump                 float64                  `json:"abm-vp-visual-search-tolerance-bump"` //
	VpVbε                    float64                  `json:"abm-vp-baseline-col-sig-strength"`    // baseline colour signal strength factor
	VpVmε                    float64                  `json:"abm-vp-max-col-sig-strength"`         // max limit colour signal strength factor
	VpReproductionChance     float64                  `json:"abm-vp-reproduction-chance"`          // chance of VP copulation success.
	VpSpawnSize              int                      `json:"abm-vp-spawn-size"`                   //
	VpSearchChance           float64                  `json:"abm-vp-vsr-chance"`                   //
	VpAttackChance           float64                  `json:"abm-vp-attack-chance"`                //
	VpBaseAttackGain         float64                  `json:"abm-vp-baseline-attack-gain"`         //
	VpCaf                    float64                  `json:"abm-vp-col-adaptation-factor"`        //
	VpStarvation             bool                     `json:"abm-vp-starvation"`                   //
	RandomAges               bool                     `json:"abm-random-ages"`                     //	flag determining if agent ages are randomised
	RNGRandomSeed            bool                     `json:"abm-rng-random-seed"`                 // flag for using server-set random seed val.
	RNGSeedVal               int64                    `json:"abm-rng-seedval"`                     // RNG seed value
	Fuzzy                    float64                  `json:"abm-rng-fuzziness"`                   //	random 'fuzziness' offset
	Logging                  bool                     `json:"abm-logging-flag"`                    // log abm on/off
	LogFreq                  int                      `json:"abm-log-frequency"`                   // # of turns between writing log files. Default = 0
	UseCustomLogPath         bool                     `json:"abm-use-custom-log-filepath"`         //
	CustomLogPath            string                   `json:"abm-custom-log-filepath"`             //
	LogPath                  string                   `json:"abm-log-filepath"`                    //	Default logging filepath unless UseCustomLogPath is ON
	Visualise                bool                     `json:"abm-visualise-flag"`                  // Visualisation on/off
	VisFreq                  int                      `json:"abm-visualise-freq"`                  //	# of turns between sending draw instructions to web client. Default = 0
	LimitDuration            bool                     `json:"abm-limit-duration"`                  //
	FixedDuration            int                      `json:"abm-fixed-duration"`                  // fixed abm running length.
	SessionIdentifier        string                   `json:"abm-session-identifier"`              // user-friendly string (from client) to identify session
}

ConditionParams groups the CONSTANT LOCAL model conditions and constraints into a single set

type DatBuf

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

DatBuf is a wrapper for the buffered agent data saved for logging.

type Environment

type Environment struct {
	Bounds         []float64  `json:"abm-environment-bounds"` // d value for each axis
	Dimensionality int        `json:"abm-environment-dimensionality"`
	BG             colour.RGB `json:"abm-environment-background"`
}

Environment specifies the boundary / dimensions of the working model. They extend in both positive and negative directions, oriented at the center. Setting any field (eg. zBounds) to zero will reduce the dimensionality of the model. For most cases, a 2D environment will be sufficient. In the future it may include some environmental factors etc.

type Model

type Model struct {
	Timeframe        // embedded Model clock
	Environment      // embedded environment attributes
	ConditionParams  //	embedded local model conditions and constraints
	AgentPopulations //	embedded slices of each agent type

	Om chan gobr.OutMsg // Outgoing comm channel – dispatches batch render instructions
	Im chan gobr.InMsg  // Incoming comm channel – receives user control messages

	Quit chan struct{} // WebSckt monitor signal - external stop signal on ch close

	Stats  //	embedded global agent population statistics
	DatBuf //	embedded buffer of last turn agent pop record for LOG
	// contains filtered or unexported fields
}

Model acts as the working instance of the modelling session / 'game'

func NewModel

func NewModel() *Model

NewModel is a constructor for initialising a Model instance

func (*Model) Controller

func (m *Model) Controller()

Controller processes instructions from client (web, command-line) for now, we just send errors to the general error channel for the model instance (m.e)

func (*Model) ErrPrinter

func (m *Model) ErrPrinter()

ErrPrinter is the most basic error channel handler – it simply prints error messages.

func (*Model) PopLog

func (m *Model) PopLog()

PopLog prints the current time and populations

func (*Model) Resume

func (m *Model) Resume() error

Resume from a suspended agent-based model

func (*Model) Start

func (m *Model) Start() error

Start the agent-based model

func (*Model) Stop

func (m *Model) Stop() error

Stop the agent-based model

func (*Model) Suspend

func (m *Model) Suspend() error

Suspend = pause a running agent-based model to be resumed later.

type Stats

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

Stats holds global statistics of the model instance.

type Timeframe

type Timeframe struct {
	Turn   int
	Phase  int
	Action int
}

Timeframe holds the model's representation of the time metrics. Turn – The cycle length for all agents ∈ 𝐄 to perform 1 (and only 1) Action. Phase – Division of a Turn, between agent sets, environmental effects/factors,

and updates to populations and model conditionss (via external).
One Phase is complete when all members of a set have performed an Action
or all requirements for the model's continuation have been fulfilled.

Action – An individual 'step' in the model. All Actions have a cost:

the period (number of turns) before that specific Action can be
performed again. For most actions this is zero.
Some Actions could also *stop* any other behaviour by that agent
for a period.

func (*Timeframe) Reset

func (t *Timeframe) Reset()

Reset 's the timeframe to 00:00:00

type VisualPredator

type VisualPredator struct {
	𝚯 float64 // heading angle
	// contains filtered or unexported fields
}

VisualPredator - Predator agent type for Predator-Prey ABM

func GenerateVPredatorPopulation

func GenerateVPredatorPopulation(size int, start int, mt int, conditions ConditionParams, timestamp string) []VisualPredator

GenerateVPredatorPopulation will create `size` number of Visual Predator agents

func (*VisualPredator) Action

func (vp *VisualPredator) Action(errCh chan<- error, conditions ConditionParams, start int, turn int, cpPreyPop []ColourPolymorphicPrey, neighbours []VisualPredator, me int) []VisualPredator

Action : Rule-Based-Behaviour for Visual Predator Agent

func (*VisualPredator) Age

func (vp *VisualPredator) Age(conditions ConditionParams, popSize int) string

Age the vp agent by one step

func (*VisualPredator) Attack

func (vp *VisualPredator) Attack(prey *ColourPolymorphicPrey, conditions ConditionParams) bool

Attack VP agent attempts to attack CP prey agent

func (*VisualPredator) Birth

func (vp *VisualPredator) Birth(conditions ConditionParams, start int, mt int) []VisualPredator

Birth spawns Visual Predator children

func (*VisualPredator) Copulation

func (vp *VisualPredator) Copulation(mate *VisualPredator, conditions ConditionParams) bool

Copulation for sexual reproduction between Visual Predator agents

func (*VisualPredator) GetDrawInfo

func (vp *VisualPredator) GetDrawInfo() (ar render.AgentRender)

GetDrawInfo exports the data set needed for agent visualisation.

func (*VisualPredator) Intercept

func (vp *VisualPredator) Intercept(target geometry.Vector) (bool, error)

Intercept attempts to turn and move towards target position (as much as vp is able)

func (VisualPredator) MarshalJSON

func (vp VisualPredator) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface for VisualPredator object

func (*VisualPredator) MateSearch

func (vp *VisualPredator) MateSearch(neighbours []VisualPredator, me int, errCh chan<- error) *VisualPredator

MateSearch searches species population for sexual coupling

func (*VisualPredator) Move

func (vp *VisualPredator) Move() error

Move updates the agent's position if it doesn't encounter any errors.

func (*VisualPredator) PreySearch

PreySearch – uses Visual Search to try to 'recognise' a nearby prey agent within model Environment to target

func (*VisualPredator) SearchAndAttack

func (vp *VisualPredator) SearchAndAttack(prey []ColourPolymorphicPrey, conditions ConditionParams, errCh chan<- error) bool

SearchAndAttack gathers the logic for these steps of the VP Action

func (*VisualPredator) String

func (vp *VisualPredator) String() string

String returns a clear textual presentation the internal values of the VP agent

func (*VisualPredator) Turn

func (vp *VisualPredator) Turn(𝚯 float64)

Turn updates 𝚯 and dir vector to the new heading offset by 𝚯

func (*VisualPredator) UUID

func (vp *VisualPredator) UUID() string

UUID is just a getter method for the unexported uuid field, which absolutely must not change after agent creation.

func (*VisualPredator) VSRSectorSampling

func (vp *VisualPredator) VSRSectorSampling(d float64, n int) ([4][2]int, error)

VSRSectorSampling checks which sectors the VP agent's Visual Search Radius intersects. This initial version samples from 4 points on the circumference of the circle with radius vp.visRange originating at the VP agent's position The four sample points on the circumference at 45°, 135°, 225°, 315° or π/4, 3π/4, 5π/4, 7π/4 radians, or NE, NW, SW, SE on a compass, if you want to think of it that way :-)

Jump to

Keyboard shortcuts

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