Documentation ¶
Index ¶
- Constants
- func GenerateHierarchy(s HierarchySpec) (*Network, *NetworkOptions, error)
- type Agent
- type AgentLink
- type AgentState
- func (a *AgentState) AgentName() string
- func (a *AgentState) ClearMail()
- func (a *AgentState) GetColor() Color
- func (a *AgentState) Identifier() string
- func (a *AgentState) Initialise(n RelationshipMgr)
- func (a *AgentState) PostMsg(msg string) bool
- func (a *AgentState) ReadMail(n RelationshipMgr) Color
- func (a *AgentState) ReceiveMsg() (string, bool)
- func (a *AgentState) SendMail(n RelationshipMgr) int
- func (a *AgentState) SetColor(color Color)
- func (a *AgentState) State() *AgentState
- func (a *AgentState) UpdateColor(n RelationshipMgr, ra *AgentState) (Color, bool)
- type AgentWithMemory
- type Color
- type HierarchySpec
- type Link
- type Network
- func (n *Network) AddAgent(a Agent)
- func (n *Network) AddLink(a1 Agent, a2 Agent)
- func (n *Network) Agents() []Agent
- func (n *Network) GetAgentByID(id string) Agent
- func (n *Network) GetRelatedAgents(a Agent) []Agent
- func (n *Network) IncrementLinkStrength(id1 string, id2 string) error
- func (n *Network) Links() []*Link
- func (n *Network) MaxColors() int
- func (n *Network) PopulateMaps() error
- func (n *Network) Serialise() string
- func (n *Network) SetMaxColors(c int)
- func (n *Network) UnmarshalJSON(b []byte) error
- type NetworkOptions
- func (o *NetworkOptions) AddEvangelists(rm RelationshipMgr) error
- func (o *NetworkOptions) AddLoneEvangelist(rm RelationshipMgr) error
- func (o *NetworkOptions) AddTeamPeerLinks(rm RelationshipMgr) error
- func (o *NetworkOptions) CloneModify(rm RelationshipMgr) (RelationshipMgr, error)
- func (o *NetworkOptions) LinkTeams(rm RelationshipMgr) error
- func (o *NetworkOptions) ModifyNetwork(rm RelationshipMgr) error
- type ParseOptions
- func (po *ParseOptions) GetColRegex(col int) (*regexp.Regexp, bool)
- func (po *ParseOptions) GetOtherRegex() map[int]*regexp.Regexp
- func (po *ParseOptions) IdentifierRegex() *regexp.Regexp
- func (po *ParseOptions) ParentRegex() *regexp.Regexp
- func (po *ParseOptions) ParseDelim(data []string) (RelationshipMgr, error)
- func (po *ParseOptions) ParseEdges(edges []string, n RelationshipMgr) (RelationshipMgr, error)
- type RelationshipMgr
- type Results
- type Runner
- type RunnerInfo
Constants ¶
const MaxDefinedColors int = 7
MaxDefinedColors is the number of defined colors.
Variables ¶
This section is empty.
Functions ¶
func GenerateHierarchy ¶
func GenerateHierarchy(s HierarchySpec) (*Network, *NetworkOptions, error)
GenerateHierarchy generates a hierarchical network
Types ¶
type Agent ¶
type Agent interface { Initialise(n RelationshipMgr) Identifier() string AgentName() string State() *AgentState SendMail(n RelationshipMgr) int ReadMail(n RelationshipMgr) Color ClearMail() GetColor() Color PostMsg(msg string) bool ReceiveMsg() (string, bool) }
Agent is an interface that allows interaction with an Agent
type AgentState ¶
type AgentState struct { ID string `json:"id"` Name string `json:"name"` Color Color `json:"color"` Susceptability float64 `json:"susceptability"` Influence float64 `json:"influence"` Contrariness float64 `json:"contrariness"` Mail chan string `json:"-"` ChangeCount int `json:"change"` Type string `json:"type"` X float64 `json:"fx,omitempty"` Y float64 `json:"fy,omitempty"` }
An AgentState carries the state of a node in the network
func (*AgentState) AgentName ¶
func (a *AgentState) AgentName() string
State returns the Name of this Agent
func (*AgentState) ClearMail ¶
func (a *AgentState) ClearMail()
ClearMail throws away any message on the Agent's Mail channel
func (*AgentState) GetColor ¶
func (a *AgentState) GetColor() Color
GetColor returns the Color of this Agent
func (*AgentState) Identifier ¶
func (a *AgentState) Identifier() string
Identifier returns the Identifier for the Agent
func (*AgentState) Initialise ¶
func (a *AgentState) Initialise(n RelationshipMgr)
Initialise ensures the agent is correctly initialised
func (*AgentState) PostMsg ¶
func (a *AgentState) PostMsg(msg string) bool
PostMsg tries to add an entry into an Agent's Mail channel, if it succeeds, that Agent will be blocked for any other Agent trying to send a Mail and this function returns true (the Agent is now Matched). If it returns false the Agent is already matched by another Agent.
func (*AgentState) ReadMail ¶
func (a *AgentState) ReadMail(n RelationshipMgr) Color
ReadMail checks for any messages it received in its own Mail queue. If it receives one then it decides whether to update its color.
func (*AgentState) ReceiveMsg ¶
func (a *AgentState) ReceiveMsg() (string, bool)
ReceiveMsg picks a message up from the Agent's Mail channel
func (*AgentState) SendMail ¶
func (a *AgentState) SendMail(n RelationshipMgr) int
SendMail iterates over a randomly ordered slice of related agents trying to find a match. It sends a mail to the first successful match it finds.
func (*AgentState) SetColor ¶
func (a *AgentState) SetColor(color Color)
SetColor changes the color of the current Agent and counts the number of times the Agent changes color It also adds each color to a memory so that once it changes it's mind it doesn't change back
func (*AgentState) State ¶
func (a *AgentState) State() *AgentState
State returns the struct containing the state of this Agent
func (*AgentState) UpdateColor ¶
func (a *AgentState) UpdateColor(n RelationshipMgr, ra *AgentState) (Color, bool)
UpdateColor looks at the properties of the passed agent and decides what the agent should update its color to
type AgentWithMemory ¶
type AgentWithMemory struct { AgentState PreviousColors map[Color]struct{} `json:"-"` ShortMemory map[Color]struct{} `json:"-"` MaxColors int `json:"-"` }
An AgentWithMemory is a node in the network that has memory
func (*AgentWithMemory) Initialise ¶
func (a *AgentWithMemory) Initialise(n RelationshipMgr)
Initialise ensures the agent is correctly initialised
func (*AgentWithMemory) ReadMail ¶
func (a *AgentWithMemory) ReadMail(n RelationshipMgr) Color
ReadMail checks for any messages it received in its own Mail queue. If it receives one then it decides whether to update its color.
func (*AgentWithMemory) SetColor ¶
func (a *AgentWithMemory) SetColor(color Color)
SetColor changes the color of the current Agent and counts the number of times the Agent changes color It also adds each color to a short term memory. It will only change its color if it hears about another color twice. Once it has updated its color it will clear its short term memory and update its long term memory with its previous color so that it doesn't get set to the same color twice
func (*AgentWithMemory) State ¶
func (a *AgentWithMemory) State() *AgentState
State returns the struct containing the state of this Agent
type Color ¶
type Color int
A Color of an Agent
func RandomlySelectAlternateColor ¶
RandomlySelectAlternateColor selects a Color other than the one passed and other than Grey unless there is only one color to choose from
type HierarchySpec ¶
type HierarchySpec struct { Levels int `json:"levels"` TeamSize int `json:"teamSize"` TeamLinkLevel int `json:"teamLinkLevel"` LinkTeamPeers bool `json:"linkTeamPeers"` LinkTeams bool `json:"linkTeams"` InitColors []Color `json:"initColors"` MaxColors int `json:"maxColors"` EvangelistAgents bool `json:"evangelistAgents"` LoneEvangelist bool `json:"loneEvangelist"` AgentsWithMemory bool `json:"agentsWithMemory"` }
HierarchySpec provides parameters to the GenerateHierarchy function specifying the features of the Hierarchical network to generate
type Link ¶
type Link struct { Agent1ID string `json:"source"` Agent2ID string `json:"target"` Strength int `json:"strength,omitempty"` Length float64 `json:"length,omitempty"` }
A Link between Agents in the Network
type Network ¶
type Network struct { Edges []*Link `json:"links"` Nodes []Agent `json:"nodes"` AgentsByID map[string]Agent `json:"-"` AgentLinkMap map[string]map[string]AgentLink `json:"-"` MaxColorCount int `json:"maxColors"` }
A Network of Agents
func NewNetwork ¶
NewNetwork creates a new Network structure from the passed json string
func (*Network) GetAgentByID ¶
GetAgentByID returns a reference to the Agent with the given ID or nil if it doesn't exist
func (*Network) GetRelatedAgents ¶
GetRelatedAgents returns a slice of Agents adjacent in the Network to the passed Agent The returned slice of Agents is always deliberately shuffled into random order
func (*Network) IncrementLinkStrength ¶
IncrementLinkStrength updates the strength field of the link connecting Agents id1 and id2. Returns an error if no link is found
func (*Network) MaxColors ¶
MaxColors returns the maximum number of color states that the agents are permitted on this network
func (*Network) PopulateMaps ¶
PopulateMaps creates the map lookups from the Links and Nodes arrays
func (*Network) SetMaxColors ¶
SetMaxColors sets the maximum number of color states that the agents are permitted on this network
func (*Network) UnmarshalJSON ¶
UnmarshalJSON implements unmarshalling of Agents of different types
type NetworkOptions ¶
type NetworkOptions struct { LinkTeamPeers bool `json:"linkTeamPeers"` LinkedTeamList []string `json:"linkedTeamList"` EvangelistList []string `json:"evangelistList"` LoneEvangelist []string `json:"loneEvangelist"` InitColors []Color `json:"initColors"` MaxColors int `json:"maxColors"` AgentsWithMemory bool `json:"agentsWithMemory"` }
NetworkOptions contains information about how the network is set up for the simulation
func CreateNetworkOptions ¶
func CreateNetworkOptions(s HierarchySpec) *NetworkOptions
CreateNetworkOptions creates a new network modifier from the passed HierarchySpec
func (*NetworkOptions) AddEvangelists ¶
func (o *NetworkOptions) AddEvangelists(rm RelationshipMgr) error
AddEvangelists sets a list of individuals to Blue and increases their susceptibility so that they cannot be influenced by another Agent
func (*NetworkOptions) AddLoneEvangelist ¶
func (o *NetworkOptions) AddLoneEvangelist(rm RelationshipMgr) error
AddLoneEvangelist links a single Agent to a list of other Agents across the Network. The first agent in the LoneEvangelist list is the Evangelist and all subsequent Agents are connected to her. If the Lone Evangelist Id does not exist in the network she is created.
func (*NetworkOptions) AddTeamPeerLinks ¶
func (o *NetworkOptions) AddTeamPeerLinks(rm RelationshipMgr) error
AddTeamPeerLinks links all Agents related to the same parent node to each other. Turns a strictly hierarchical network in to a more realistic communication network.
func (*NetworkOptions) CloneModify ¶
func (o *NetworkOptions) CloneModify(rm RelationshipMgr) (RelationshipMgr, error)
CloneModify clones the agents and links in the passed RelationshipMgr into a new RelationshipMgr changing the Agent type and initial colors of all Agents on the Network, then it modifies the links as specified in the passed Options struct.
func (*NetworkOptions) LinkTeams ¶
func (o *NetworkOptions) LinkTeams(rm RelationshipMgr) error
LinkTeams creates links between a specified set of individuals from across teams in the network
func (*NetworkOptions) ModifyNetwork ¶
func (o *NetworkOptions) ModifyNetwork(rm RelationshipMgr) error
ModifyNetwork takes a RelationshipMgr as input and adds links as specified in the passed Options struct. Note this method will ignore the InitColors and AgentsWithMemory options because a new set of Agents require to be generated in order to set these options. To do that use the CloneModify function instead.
type ParseOptions ¶
type ParseOptions struct { Identifier int `json:"identifier"` Parent int `json:"parent"` Name int `json:"name"` Regex map[string]string `json:"regex"` Delimiter string `json:"delimiter"` }
ParseOptions contains details about how to parse data from the incoming file Identifier provides the index of the column to use as an Agnent Identifier Parent provides the index of the column to use as the Identifier of a Parent Agent Regex provides the regular expressions to use to extract data from the columns. It is in the form of a map, the key being the index of the column, the value being the regex to apply. When a Regex is supplied for the parent or identifier columns it will be used to extract the value to use as the Identifier. If it is applied to another column then the row will be skipped where the regex does not match the contents in that column. Any regex supplied for a column that doesn't exist within a row will result in that row being skipped. If no regex is supplied for the parent and identifier columns then a default is applied which will strip leading and trailing whitespace. Delimiter is the delimiter to use when slicing rows into columns
func (*ParseOptions) GetColRegex ¶
func (po *ParseOptions) GetColRegex(col int) (*regexp.Regexp, bool)
GetColRegex returns the Regexp that must be applied to the indicated column
func (*ParseOptions) GetOtherRegex ¶
func (po *ParseOptions) GetOtherRegex() map[int]*regexp.Regexp
GetOtherRegex returns the compiled regular expressions for columns other than the parent and identifier columns
func (*ParseOptions) IdentifierRegex ¶
func (po *ParseOptions) IdentifierRegex() *regexp.Regexp
IdentifierRegex returns the Regexp that must be applied to the Identifier column
func (*ParseOptions) ParentRegex ¶
func (po *ParseOptions) ParentRegex() *regexp.Regexp
ParentRegex returns the Regexp that must be applied to the Parent column
func (*ParseOptions) ParseDelim ¶
func (po *ParseOptions) ParseDelim(data []string) (RelationshipMgr, error)
ParseDelim takes a hierarchy expressed in a comma separated file and generates a Network out of it po are the ParseOptions that control how the parse will operate. returns a RelationshipMgr containing all the Agents with links to parent Agents as described in the input data. If the same Id is listed in multiple rows as specified after any regular expressions is applied the first row is used and subsequent rows are ignored.
func (*ParseOptions) ParseEdges ¶
func (po *ParseOptions) ParseEdges(edges []string, n RelationshipMgr) (RelationshipMgr, error)
ParseEdges is a variant of ParseDelim that takes a list of edges and adds the links in to an existing network. This is useful when the network is expressed as separate lists of nodes and edges, or when the nodes data is a list of parent child relationships and there are additional relationships to be added to the network to complete it. ParseDelim may be used to parse a list of nodes with or without edges. The edges are expected to be in the form of a list of pairs of IDs. Unlike ParseDelim this function will not add any Agents that are not already in the network. It will also ignore any edges that are not between two Agents that are already in the network.
type RelationshipMgr ¶
type RelationshipMgr interface { GetRelatedAgents(a Agent) []Agent GetAgentByID(id string) Agent IncrementLinkStrength(id1 string, id2 string) error AddAgent(a Agent) AddLink(a1 Agent, a2 Agent) Agents() []Agent Links() []*Link MaxColors() int SetMaxColors(c int) PopulateMaps() error }
RelationshipMgr is an interface for the Network
type Results ¶
type Results struct { Iterations int `json:"iterations"` Colors [][]int `json:"colors"` Conversations []int `json:"conversations"` }
Results contains the results from a Sim run over a number of iterations
type Runner ¶
type Runner interface { Run() Results GetRelationshipMgr() RelationshipMgr }
Runner is used to run a simulation for a specified number of steps on its network
func NewRunner ¶
func NewRunner(n RelationshipMgr, iterations int) Runner
NewRunner returns an instance of a sim Runner
type RunnerInfo ¶
type RunnerInfo struct { RelationshipMgr RelationshipMgr `json:"network"` Iterations int `json:"iterations"` }
RunnerInfo specifies the number of iterations and steps to run and records the results
func (*RunnerInfo) GetRelationshipMgr ¶
func (ri *RunnerInfo) GetRelationshipMgr() RelationshipMgr
GetRelationshipMgr returns the internal network state