5.1. Markov Chains Brain

This module contains the Brain class which will control a ConsoleUser in order to simulate user behavior.

class MarkovBrain.MarkovBrain(user)

This <no title> works using Markov transition matricies for both the transition from application to application, but also for those actions performed within an application. In the same directory as the config file pointed to by path should be the files defining those transition matricies. The application matrix is in modules.conf and then each application has its own called <application>Actions.conf.

There is some opportunity for outside influences to alter the state without using the matrix state change, but generally speaking the user will simply continue bouncing around the matrix until told to stop.

Parameters:

get_remote_funcs()

This function should be overridden by every subclass that wants to export additional functions that can be accessed remotely.

Each exported function should support the function signature func( outputFileObject, *args ) (obviously “self” is allowed as a first arg for any method). All output the function wants to send to the caller should be written to the outputFileObject, and any expected args will be passed in via the *args. The docstring will be exposed on a request for “help” from the remote caller–unless one of the exported functions overrides the “help” name–so those should provide information about both what the function does and how to use it.

Return: a dictionary of exported function name to the function itself

is_failed(cur_mod)

This will return if the user should currently be considered to be in a failed state.

Parameters:

  • cur_mod: the key in self._loaded_mods for the current module

main(times=None)

This is the main loop for the brain. It will loop either a certain number of times through, or will continually loop until the brain’s stop method is called.

Parameters:

  • times: instead of looping indefinitely only loop this many times

next_action()

Get the next action that is to be used and advance the state to that action.

Return: the action to use

next_module()

Get the next module that is to be used and advance the state to that module.

Return: the module to use

valid_transition(mod, action=None, args=None)

Check whether a given transition would be valid for this brain/user

Parameters:

  • mod: the destination module

  • action: the destination action

  • args: a tuple of the arguments to that action