fcapy.poset.POSet
- class fcapy.poset.POSet(elements: ~typing.Optional[~typing.Collection[~typing.Any]] = None, leq_func: ~typing.Callable[[~typing.Any, ~typing.Any], bool] = <function POSet.<lambda>>, use_cache: bool = True, children_dict: ~typing.Optional[~typing.Dict[int, ~typing.Tuple[int, ...]]] = None)
A class to represent a Partially Ordered Set (POSet)
A POSet (Partially Ordered Set) is a set in which some elements are bigger than the others, some are smaller, and some are incomparable.
Example
A set of elements = [set(), {‘a’}, {‘b’}] with defined leq (less or equal) function = lambda a,b: a in b is a POSet.
set() in {‘a’} = True <=> set()<={‘a’} <=> element #0 is smaller than element #1 set() in {‘b’} = True <=> set()<={‘b’} <=> element #0 is smaller than element #2 {‘a’} in {‘b’} = False and {‘b’} in {‘a’} = False <=> ({‘a’} not <= {‘b’}) and ({‘b’} not <= {‘a’}) <=> element #1 and element #2 are incomparable
- __init__(elements: ~typing.Optional[~typing.Collection[~typing.Any]] = None, leq_func: ~typing.Callable[[~typing.Any, ~typing.Any], bool] = <function POSet.<lambda>>, use_cache: bool = True, children_dict: ~typing.Optional[~typing.Dict[int, ~typing.Tuple[int, ...]]] = None)
Construct a POSet based on a set of
elementsandleq_funcdefined on this set- Parameters
elements (list) – A set of elements of POSet of any kind
leq_func (function (a,b)-> True or False) – A function to compare whether element
a` from the POSet is smaller than ``bor notuse_cache (bool) – A flag whether to save for the output of leq_func and other computations in the cache or not
children_dict (dict of type {
element_i: indexes of the biggest elements smaller thanelement_i}) – (optional) A dictionary that contains the precomputed relation representing the biggest elements smaller than an element
Methods
__init__([elements, leq_func, use_cache, ...])Construct a POSet based on a set of
elementsandleq_funcdefined on this setadd(element[, fill_up_cache])Add an
elementto POSet.ancestors(element_index)Return a set of indexes of elements of POSet bigger than element #``element_index``
children(element_index)Return a set of indexes of the biggest elements smaller than #``element_index``
descendants(element_index)Return a set of indexes of elements of POSet smaller than element #``element_index``
Compute all ancestors of each element in a POSet
Fill up each cache of POSet
Compute children of each element in a POSet
Compute all descendants of each element in a POSet
Compare all the elements of POSet at once
Compute parents of each element in a POSet
index(element)Returns an index of the
elementin the list ofPOSet.elementsinfimum([element_indexes])Alias for self.meet(element_indexes)
join([element_indexes])Return the smallest element from POSet bigger than all elements from
element_indexesleq_elements(a_index, b_index)Compare two elements of POSet by their indexes
meet([element_indexes])Return the biggest element from POSet smaller than all elements from
element_indexesparents(element_index)Return a set of indexes of the smallest elements bigger than #``element_index``
remove(element)Remove an
elementfrom POSetsupremum([element_indexes])Alias for self.join(element_indexes)
to_networkx([direction])Construct networkx.Graph (or DiGraph) based on POSet relations and
directiontrace_element(element, direction)Get the sets of descendants and children (or ancestors and parents) of an
elementin the POSetAttributes
list`[indexes of all elements bigger than `element_idx]
A list of the bottom (the smallest) elements in a POSet
list`[indexes of the biggest elements smaller than `element_idx]
list`[indexes of all elements smaller than `element_idx]
A list of elements of the POSet
A function to compare whether element
a` from the POSet is smaller than ``bor notlist`[indexes of the smallest elements bigger than `element_idx]
A list of the top (the biggest) elements in a POSet
- add(element: Any, fill_up_cache: bool = True)
Add an
elementto POSet. Automatically fill up the comparison caches if needed
- ancestors(element_index: int) FrozenSet[int]
Return a set of indexes of elements of POSet bigger than element #``element_index``
- property ancestors_dict: Dict[int, FrozenSet[int]]
list`[indexes of all elements bigger than `element_idx]
- Type
A dictionary of kind {element_idx
- property bottoms: List[int]
A list of the bottom (the smallest) elements in a POSet
- children(element_index: int) FrozenSet[int]
Return a set of indexes of the biggest elements smaller than #``element_index``
Element
ais a direct sub element of elementbifa``<``band there is no elementcsuch thata``<``c``<``b
- property children_dict: Dict[int, FrozenSet[int]]
list`[indexes of the biggest elements smaller than `element_idx]
- Type
A dictionary of kind {element_idx
- descendants(element_index: int) FrozenSet[int]
Return a set of indexes of elements of POSet smaller than element #``element_index``
- property descendants_dict: Dict[int, FrozenSet[int]]
list`[indexes of all elements smaller than `element_idx]
- Type
A dictionary of kind {element_idx
- property elements: List[Any]
A list of elements of the POSet
- fill_up_ancestors_cache()
Compute all ancestors of each element in a POSet
- fill_up_caches()
Fill up each cache of POSet
- fill_up_children_cache()
Compute children of each element in a POSet
- fill_up_descendants_cache()
Compute all descendants of each element in a POSet
- fill_up_leq_cache()
Compare all the elements of POSet at once
- fill_up_parents_cache()
Compute parents of each element in a POSet
- index(element: Any) int
Returns an index of the
elementin the list ofPOSet.elements
- infimum(element_indexes: Optional[Collection[int]] = None) Optional[int]
Alias for self.meet(element_indexes)
- join(element_indexes: Optional[Collection[int]] = None) Optional[int]
Return the smallest element from POSet bigger than all elements from
element_indexes
- leq_elements(a_index: int, b_index: int) bool
Compare two elements of POSet by their indexes
- property leq_func: Callable[[Any, Any], bool]
A function to compare whether element
a` from the POSet is smaller than ``bor not
- meet(element_indexes: Optional[Collection[int]] = None) Optional[int]
Return the biggest element from POSet smaller than all elements from
element_indexes
- parents(element_index: int) FrozenSet[int]
Return a set of indexes of the smallest elements bigger than #``element_index``
Element
ais a direct super element of elementbifa>``b`` and there is no elementcsuch thata>``c``>``b``
- property parents_dict: Dict[int, FrozenSet[int]]
list`[indexes of the smallest elements bigger than `element_idx]
- Type
A dictionary of kind {element_idx
- remove(element: Any)
Remove an
elementfrom POSet
- supremum(element_indexes: Optional[Collection[int]] = None) Optional[int]
Alias for self.join(element_indexes)
- to_networkx(direction: str = 'down')
Construct networkx.Graph (or DiGraph) based on POSet relations and
direction
- property tops: List[int]
A list of the top (the biggest) elements in a POSet
- trace_element(element: Any, direction: str) Tuple[Set[int], Set[int]]
Get the sets of descendants and children (or ancestors and parents) of an
elementin the POSet- Parameters
element – An element to compare POSet elements with (not necessary from the POSet itself)
direction ({'up', 'down'}) – If set ‘up’ then compute all (and direct) descendants of an
element, if set ‘down’ then compute all (and direct) ancestors of anelement
- Returns
final_elements (set) – A set of children (or parents) of
elementin the POSettraced_elements (set) – A set of descendants (or ancestors) of
elementin the POSet