fcapy.poset.tree

The module provides BinaryTree class which represents a binary tree as a partial case of a poset.

Classes

BinaryTree(elements, leq_func[, use_cache, ...])

class fcapy.poset.tree.BinaryTree(elements, leq_func, use_cache: bool = True, direct_subelements_dict=None)
add(element, fill_up_cache=True)

Add an element to the BinaryTree only if it does not break the binary structure

property bottom_elements

A list of the bottom (the smallest) elements in a POSet

direct_sub_elements(element_index: int)

Return a set of indexes of closest elements of POSet smaller than element #``element_index``

Element a is a direct sub element of element b if a``<``b and there is no element c such that a``<``c``<``b

property direct_sub_elements_dict

list`[indexes of closest elements smaller than `element_index]

Type

A dictionary of kind {element_index

direct_super_elements(element_index: int)

Return a set of indexes of closest elements of POSet bigger than element #``element_index``

Element a is a direct super element of element b if a>``b`` and there is no element c such that a>``c``>``b``

property direct_super_elements_dict

list`[indexes of closest elements bigger than `element_index]

Type

A dictionary of kind {element_index

property elements

A set of elements of the POSet

fill_up_caches()

Fill up each cache of POSet

fill_up_direct_subelements_cache()

Compute direct subelements of each element in a POSet

fill_up_direct_superelements_cache()

Compute direct superelements of each element in a POSet

fill_up_leq_cache()

Compare all the elements of POSet at once

fill_up_subelements_cache()

Compute all subelements of each element in a POSet

fill_up_superelements_cache()

Compute all superelements of each element in a POSet

index(element)

Returns an index of the element in the list of POSet.elements

infimum(element_indexes: Optional[Collection] = None)

Alias for self.meet_elements(element_indexes)

join_elements(element_indexes: Optional[Collection] = None)

Return the smallest element from POSet bigger than all elements from element_indexes

leq_elements(a_index: int, b_index: int)

Compare two elements of POSet by their indexes

property leq_func

A function to compare whether element a` from the POSet is smaller than ``b or not

meet_elements(element_indexes: Optional[Collection] = None)

Return the biggest element from POSet smaller than all elements from element_indexes

remove(element)

Remove and element from the semilattice

sub_elements(element_index: int)

Return a set of indexes of elements of POSet smaller than element #``element_index``

property sub_elements_dict

list`[indexes of all elements smaller than `element_index]

Type

A dictionary of kind {element_index

super_elements(element_index: int)

Return a set of indexes of elements of POSet bigger than element #``element_index``

property super_elements_dict

list`[indexes of all elements bigger than `element_index]

Type

A dictionary of kind {element_index

supremum(element_indexes: Optional[Collection] = None)

Alias for self.join_elements(element_indexes)

to_networkx(direction: str = 'down')

Construct networkx.Graph (or DiGraph) based on POSet relations and direction

property top_element

An index of the single top (the biggest) element of the semilattice

property top_elements

The set of indexes of the top (the biggest) elements of the semilattice

trace_element(element, direction: str)

Get the sets of all and direct superelements (or subelements) of an element in 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) subelements of an element, if set ‘down’ then compute all (and direct) superelements of an element

Returns

  • final_elements (set) – A set of direct super (or sub) elements of element in the POSet

  • traced_elements (set) – A set of all super (or sub) elements of element in the POSet