fcapy.poset.POSet

class fcapy.poset.POSet(elements=None, leq_func=None, use_cache: bool = True, direct_subelements_dict=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=None, leq_func=None, use_cache: bool = True, direct_subelements_dict=None)

Construct a POSet based on a set of elements and leq_func defined on this set

Parameters
  • elements (list) – A set of elements of POSet of any kind

  • leq_func (function (a,b)-> True of False) – A function to compare whether element a` from the POSet is smaller than ``b or not

  • use_cache (bool) – A flag whether to save for the output of leq_func and other computations in the cache or not

  • direct_subelements_dict (dict of type {element_i: indexes of direct subelements of element_i}) – (optional) A dictionary that contains the precomputed direct subelements relation

Methods

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

Construct a POSet based on a set of elements and leq_func defined on this set

add(element[, fill_up_cache])

Add an element to POSet.

direct_sub_elements(element_index)

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

direct_super_elements(element_index)

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

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])

Alias for self.meet_elements(element_indexes)

join_elements([element_indexes])

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

leq_elements(a_index, b_index)

Compare two elements of POSet by their indexes

meet_elements([element_indexes])

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

remove(element)

Remove an element from POSet

sub_elements(element_index)

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

super_elements(element_index)

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

supremum([element_indexes])

Alias for self.join_elements(element_indexes)

to_networkx([direction])

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

trace_element(element, direction)

Get the sets of all and direct superelements (or subelements) of an element in the POSet

Attributes

bottom_elements

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

direct_sub_elements_dict

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

direct_super_elements_dict

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

elements

A set of elements of the POSet

leq_func

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

sub_elements_dict

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

super_elements_dict

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

top_elements

A list of the top (the biggest) elements in a POSet

add(element, fill_up_cache=True)

Add an element to POSet. Automatically fill up the comparison caches if needed

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 an element from POSet

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_elements

A list of the top (the biggest) elements in a POSet

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