state_server v0.4.10 StateServer.StateGraph View Source
tools for dealing with stategraphs.
State graphs take the form of a keyword list of keyword lists, wherein the outer list is a comprehensive list of the states, and the inner lists are keywords list of all the transitions, with the values of the keyword list as the destination states.
Link to this section Summary
Functions
lists all state/transition pairs. Used to generate the StateServer.is_transition/2
guard.
converts a list of atoms to a type which is the union of the atom literals
outputs a list of edges of the graph. Used to generate the StateServer.is_transition/3
guard.
returns the starting state from the state graph.
lists all states in the state graph. The first element in this list will always be the initial state.
outputs a list of terminal states of the graph. Used to generate the
StateServer.is_terminal/1
guard.
outputs a list of terminal {state, transition} tuples of the graph. Used to generate the
StateServer.is_terminal/2
guard.
outputs the destination state given a source state and a transition.
lists all transitions in the state graph.
lists all transitions emanating from a given state.
checks the validity of the state graph.
Link to this section Types
Link to this section Functions
lists all state/transition pairs. Used to generate the StateServer.is_transition/2
guard.
Example
iex> StateServer.StateGraph.all_transitions([start: [t1: :state1, t2: :state2], state1: [], state2: [t2: :state1]])
[start: :t1, start: :t2, state2: :t2]
converts a list of atoms to a type which is the union of the atom literals
outputs a list of edges of the graph. Used to generate the StateServer.is_transition/3
guard.
iex> StateServer.StateGraph.edges(start: [t1: :state1, t2: :state2], state1: [t3: :start], state2: [])
[start: {:t1, :state1}, start: {:t2, :state2}, state1: {:t3, :start}]
returns the starting state from the state graph.
iex> StateServer.StateGraph.start([start: [t1: :state1], state1: [t2: :state2], state2: []])
:start
lists all states in the state graph. The first element in this list will always be the initial state.
Example
iex> StateServer.StateGraph.states([start: [t1: :state1], state1: [t2: :state2], state2: [t2: :state2]])
[:start, :state1, :state2]
outputs a list of terminal states of the graph. Used to generate the
StateServer.is_terminal/1
guard.
iex> StateServer.StateGraph.terminal_states(start: [t1: :state1, t2: :state2], state1: [], state2: [])
[:state1, :state2]
outputs a list of terminal {state, transition} tuples of the graph. Used to generate the
StateServer.is_terminal/2
guard.
iex> StateServer.StateGraph.terminal_transitions(start: [t1: :state1, t2: :state2], state1: [], state2: [])
[start: :t1, start: :t2]
outputs the destination state given a source state and a transition.
Example
iex> StateServer.StateGraph.transition([start: [t1: :state1, t2: :state2], state1: [], state2: []], :start, :t1)
:state1
lists all transitions in the state graph.
Example
iex> StateServer.StateGraph.transitions([start: [t1: :state1], state1: [t2: :state2], state2: [t2: :state2]])
[:t1, :t2]
lists all transitions emanating from a given state.
Example
iex> StateServer.StateGraph.transitions([start: [t1: :state1, t2: :state2], state1: [], state2: []], :start)
[:t1, :t2]
checks the validity of the state graph.
Should only be called when we build the state graph.
A state graph is valid if and only if all of the following are true:
- the graph is a keyword of keywords.
- there is at least one state.
- there are no duplicate state definitions.
- there are no duplicate transition definitions emanating from any given state.
- all of the destinations of the transitions are states.