Package tulip :: Package transys :: Module labeled_graphs :: Class States
[frames] | no frames]

Class States


Methods to manage states and initial states.

Instance Methods
 
__init__(self, graph)
Initialize States.
 
__getitem__(self, state)
 
__call__(self, *args, **kwargs)
Return list of states.
 
__str__(self)
str(x)
 
__len__(self)
Total number of states.
 
__iter__(self)
 
__ior__(self, new_states)
 
__contains__(self, state)
Return True if state in states.
 
add(self, new_state, attr_dict=None, check=True, **attr)
Wraps LabeledDiGraph.add_node,
 
add_from(self, new_states, check=True, **attr)
Wraps LabeledDiGraph.add_nodes_from,
 
remove(self, state)
Remove state from states (including initial).
 
remove_from(self, states)
Remove a list of states.
set
post(self, states=None)
Direct successor set (1-hop) for given states.
set
pre(self, states)
Return direct predecessors (1-hop) of given state.
 
forward_reachable(self, state)
Return states reachable from given state.
 
backward_reachable(self, state)
Return states from which the given state can be reached.
 
paint(self, state, color)
Color the given state.
list of labeled states
find(self, states=None, with_attr_dict=None, **with_attr)
Filter by desired states and by desired state labels.
 
is_terminal(self, state)
Return True if state has no outgoing transitions.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties
  initial
Return SubSet of initial states.

Inherited from object: __class__

Method Details

__init__(self, graph)
(Constructor)

 

Initialize States.

Parameters:
Overrides: object.__init__

__call__(self, *args, **kwargs)
(Call operator)

 

Return list of states.

For more details see LabeledDiGraph.nodes

__str__(self)
(Informal representation operator)

 

str(x)

Overrides: object.__str__
(inherited documentation)

add(self, new_state, attr_dict=None, check=True, **attr)

 

Wraps LabeledDiGraph.add_node,

which wraps networkx.MultiDiGraph.add_node.

add_from(self, new_states, check=True, **attr)

 

Wraps LabeledDiGraph.add_nodes_from,

which wraps networkx.MultiDiGraph.add_nodes_from.

remove(self, state)

 

Remove state from states (including initial).

Wraps networkx.MultiDiGraph.remove_node.

remove_from(self, states)

 

Remove a list of states.

Iterates States.remove to imitate networkx.MultiDiGraph.remove_nodes_from, handling also initial states.

post(self, states=None)

 

Direct successor set (1-hop) for given states.

Edge labels are ignored.

If multiple states provided, then union Post(s) for s in states provided.

See Also

Parameters:
  • states -
    • None, so initial states returned
    • single state or
    • set of states or
Returns: set

pre(self, states)

 

Return direct predecessors (1-hop) of given state.

See Also

Returns: set

forward_reachable(self, state)

 

Return states reachable from given state.

Iterated post(), a wrapper of networkx.descendants.

backward_reachable(self, state)

 

Return states from which the given state can be reached.

A wrapper of networkx.ancestors.

paint(self, state, color)

 

Color the given state.

The state is filled with given color, rendered with dot when plotting and saving.

Parameters:
  • state - valid system state
  • color (str of valid dot color) - with which to paint state

find(self, states=None, with_attr_dict=None, **with_attr)

 

Filter by desired states and by desired state labels.

Examples

Assume that the system is:

>>> import transys as trs
>>> ts = trs.FTS()
>>> ts.atomic_propositions.add('p')
>>> ts.states.add('s0', ap={'p'})
  • To find the label of a single state 's0':
    >>> a = ts.states.find(['s0'] )
    >>> (s0_, label) = a[0]
    >>> print(label)
    {'ap': set(['p'])}
  • To find all states with a specific label {'p'}:
    >>> ts.states.add('s1', ap={'p'})
    >>> b = ts.states.find(with_attr_dict={'ap':{'p'} } )
    >>> states = [state for (state, label_) in b]
    >>> print(set(states) )
    {'s0', 's1'}
  • To find all states in subset M labeled with {'p'}:
    >>> ts.states.add('s2', ap={'p'})
    >>> M = {'s0', 's2'}
    >>> b = ts.states.find(M, {'ap': {'p'} } )
    >>> states = [state for (state, label_) in b]
    >>> print(set(states) )
    {'s0', 's2'}
Parameters:
  • states ('any' (default) | iterable of valid states | single valid state) - subset of states over which to search
  • with_attr_dict ({sublabel_type : desired_sublabel_value, ...} | leave empty, to allow any state label (default)) - label with which to filter the states
  • with_attr - label key-value pairs which take precedence over with_attr_dict.
Returns: list of labeled states
[(state, label),...] where:
  • state \in states
  • label: dict

is_terminal(self, state)

 

Return True if state has no outgoing transitions.

See Also

Def. 2.4, p.23 [BK08]


Property Details

initial

Return SubSet of initial states.

Get Method:
unreachable.initial(self) - Return SubSet of initial states.
Set Method:
unreachable.initial(self, states)