Class: Micro::MarkovAgent
- Inherits:
-
Object
- Object
- Micro::MarkovAgent
- Defined in:
- lib/micro_agent.rb
Overview
An agent is a autonomous entity that interacts with the Micro::World. Each agent has a collection of properties that are updated over time (i.e. with each call to #step_agents in the #World).
Dependancy relationships can be setup between an agent’s parameters. So that properties:
a.depends_on b.depends_on c
d.depends_on b.depends_on c
b.depends_on c
This is useful where one parameter is required for calculation of another. For example, calculating a speed parameter might require you to know the values of the distance and time parameters. #step_agents calculates dependancies in the correct order, making that a parameter’s dependants are calculated first . Note however that cyclic depends_on relationships aren’t supported.
The runtime complexity of processing dependacies is still O(n) (where n is the number of parameters) even with complex dependency trees thanks to the niftyness of dynamic programming algorithms.
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Instance Method Summary collapse
- #[](parameter_name) ⇒ Object
-
#initialize(parameters) ⇒ MarkovAgent
constructor
A new instance of MarkovAgent.
-
#step(number = 1) ⇒ Object
Updates the parameter value using the parameter’s change function.
- #values ⇒ Object
Constructor Details
#initialize(parameters) ⇒ MarkovAgent
Returns a new instance of MarkovAgent.
69 70 71 72 |
# File 'lib/micro_agent.rb', line 69 def initialize(parameters) @parameters = parameters @already_done = Hash.new end |
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
67 68 69 |
# File 'lib/micro_agent.rb', line 67 def parameters @parameters end |
Instance Method Details
#[](parameter_name) ⇒ Object
86 87 88 |
# File 'lib/micro_agent.rb', line 86 def [](parameter_name) @parameters[parameter_name].value end |
#step(number = 1) ⇒ Object
Updates the parameter value using the parameter’s change function. Each parameter is updated with probability equal to its probability value.
77 78 79 80 81 82 83 84 |
# File 'lib/micro_agent.rb', line 77 def step(number = 1) number.times do @already_done.clear @parameters.each_value do |parameter| process(parameter) end end end |
#values ⇒ Object
90 91 92 93 94 |
# File 'lib/micro_agent.rb', line 90 def values value_hash = {} @parameters.each_pair { |key, parameter| value_hash[key.to_s] = parameter.value } value_hash end |