ranking

class corankco.ranking.Ranking(buckets: List[Set[Element]])

A class to represent a ranking, defined as a List of disjoint Set of Elements

property buckets: List[Set[Element]]

Returns the buckets of the ranking.

Returns:

The buckets of the ranking

Return type:

List[Set[Element]]

can_be_of_int() bool

Returns true iif all the elements in the ranking can be converted to int

Returns:

true iif all the elements in the ranking can be converted to int

Return type:

bool

property domain: Set[Element]

Returns the set of all elements in the Ranking.

Returns:

A set of Elements which are the unique elements in the Ranking.

classmethod from_file(file_path: str) Ranking

Constructs a Ranking instance from a file.

Parameters:

file_path (str) – The path to a file containing a ranking representation

Returns:

A Ranking instance

Return type:

Ranking

classmethod from_list(ranking_list: List[Set[int | str]]) Ranking

Constructs a Ranking instance from a list of elements.

Parameters:

ranking_list (List[Union[int, str]]) – A list of elements representing a ranking

Returns:

A Ranking instance

Return type:

Ranking

classmethod from_string(ranking_str: str) Ranking

Constructs a Ranking instance from a string representation.

Parameters:

ranking_str (str) – A string representation of a ranking

Returns:

A Ranking instance

Return type:

Ranking

static generate_rankings(nb_elements: int, nb_rankings: int, steps: int, complete=False) List[Ranking]

Method to generate a List of nb_rankings rankings of nb_elements elements, possibly incomplete with ties. Each ranking is initially [{0}, {1}, …, {n-1}], then modifications are done using a Markov chain. For each step from range 1 … step parameter: an element is uniformly selected and may uniformly: - be added in the ranking if the element is currently non-ranked - be removed in the ranking if the element is currently ranked - be in a new bucket at the left of the current left neighbor bucket - be in a new bucket at the right of the current right neighbor bucket - be added in the current left neighbor bucket - be added in the current right neighbor bucket

Parameters:

nb_elements – number of elements of the universe. Note that according to the steps of the Markov chain,

the final list of rankings may have less than the given number of elements (if an element has been removed from

all the input ranking)

Parameters:
  • nb_rankings – the number of rankings to generate

  • steps – the number of steps in the markov chain

  • complete – does the final rankings need to be complete ? Default = False

Returns:

a List of Ranking generated as described in the above description

property nb_elements: int

Returns the number of unique elements in the Ranking. This is equivalent to the size of the domain of the Ranking.

Returns:

An integer which is the number of unique elements in the Ranking.

property positions: Dict[Element, int]

Returns the positions of the elements in the ranking.

Returns:

The positions of the elements in the ranking

Return type:

Dict[Element, int]

static uniform_permutations(nb_elem: int, nb_rankings: int) List[Ranking]

Method to get a List of random uniform Rankings that are complete and without ties.

Parameters:
  • nb_elem – the number of elements in the rankings

  • nb_rankings – the number of rankings to generate

Returns:

a list of random complete rankings without ties on {0, …, n-1}