cfpq_data.graphs.utils.multiple_source_utils#

Utilities for the multiple-source query evaluation.

Functions

generate_multiple_source(graph, set_size, *)

Returns a fixed-size set of graph vertices for multiple-source evaluation.

generate_multiple_source_percent(graph, ...)

Returns a set of graph vertices with the given percent of vertices for multiple-source evaluation.

multiple_source_from_txt(path)

Returns a set of source vertices loaded from a TXT file.

multiple_source_result_from_txt(path)

Returns a set with the result of multiple-source query evaluation loaded from a TXT file.

multiple_source_result_to_txt(...)

Returns a path to the TXT file where the multiple-source query evaluation result will be saved.

multiple_source_to_txt(source_vertices, path)

Returns a path to the TXT file where the set of source vertices will be saved.

generate_multiple_source(graph: MultiDiGraph, set_size: int, *, seed: int | None = None) Set[int][source]#

Returns a fixed-size set of graph vertices for multiple-source evaluation.

Parameters:
  • graph (MultiDiGraph) -- Graph for which the sample is generated.

  • set_size (int) -- Number of nodes to sample into the generated set.

  • seed (Union[int, None]) -- Indicator of random number generation state.

Examples

>>> from cfpq_data import *
>>> seed = 42
>>> g = cfpq_data.labeled_two_cycles_graph(42, 29)
>>> source_vertices = cfpq_data.generate_multiple_source(g, 10, seed=seed)
>>> source_vertices
{32, 3, 4, 36, 12, 14, 15, 18, 54, 29}
Returns:

source_vertices -- The set of sampled source vertices for the given graph.

Return type:

Set[int]

generate_multiple_source_percent(graph: MultiDiGraph, percent: float, *, seed: int | None = None) Set[int][source]#

Returns a set of graph vertices with the given percent of vertices for multiple-source evaluation.

Parameters:
  • graph (MultiDiGraph) -- Graph for which the sample is generated.

  • percent (float) -- Percent of nodes to sample into the generated set.

  • seed (Union[int, None]) -- Indicator of random number generation state.

Examples

>>> from cfpq_data import *
>>> g = cfpq_data.labeled_two_cycles_graph(42, 29)
>>> g.number_of_nodes()
72
>>> seed = 42
>>> source_vertices = cfpq_data.generate_multiple_source_percent(g, 10.0, seed=seed)
>>> source_vertices
{32, 4, 36, 14, 15, 18, 29}
Returns:

source_vertices -- The set of sampled source vertices for the given graph.

Return type:

Set[int]

multiple_source_from_txt(path: Path | str) Set[int][source]#

Returns a set of source vertices loaded from a TXT file.

Parameters:

path (Union[Path, str]) -- The path to the TXT file with the set of source vertices.

Examples

>>> from cfpq_data import *
>>> s = {1, 2, 5, 10}
>>> path = multiple_source_to_txt(s, "test.txt")
>>> source_vertices = multiple_source_from_txt(path)
>>> len(source_vertices)
4
Returns:

source_vertices -- The loaded set of source vertices.

Return type:

Set[int]

multiple_source_result_from_txt(path: Path | str) Set[Tuple[int, int]][source]#

Returns a set with the result of multiple-source query evaluation loaded from a TXT file.

Parameters:

path (Union[Path, str]) -- The path to the TXT file with the result of multiple-source query evaluation.

Examples

>>> from cfpq_data import *
>>> ms_result = {(1, 1), (1, 3), (2, 2), (3, 1)}
>>> path = multiple_source_result_to_txt(ms_result, "test.txt")
>>> reachable_pairs = multiple_source_result_from_txt(path)
>>> len(reachable_pairs)
4
Returns:

reachable_pairs -- The loaded pairs of reachable vertices.

Return type:

Set[Tuple[int, int]]

multiple_source_result_to_txt(reachable_pairs: Set[Tuple[int, int]], path: Path | str) Path[source]#

Returns a path to the TXT file where the multiple-source query evaluation result will be saved.

Parameters:
  • reachable_pairs (Set[Tuple[int, int]]) -- The multiple-source query evaluation result to save.

  • path (Union[Path, str]) -- The path to the file where the multiple-source query evaluation result will be saved.

Examples

>>> from cfpq_data import *
>>> ms_result = {(1, 1), (1, 3), (2, 2), (3, 1)}
>>> path = multiple_source_result_to_txt(ms_result, "test.txt")
Returns:

path -- Path to a TXT file where the multiple-source query evaluation result will be saved.

Return type:

Path

multiple_source_to_txt(source_vertices: Set[int], path: Path | str) Path[source]#

Returns a path to the TXT file where the set of source vertices will be saved.

Parameters:
  • source_vertices (Set[int]) -- The set of source vertices to save.

  • path (Union[Path, str]) -- The path to the file where the set of source vertices will be saved.

Examples

>>> from cfpq_data import *
>>> s = {1, 2, 5, 10}
>>> path = multiple_source_to_txt(s, "test.txt")
Returns:

path -- Path to a TXT file where the set of source vertices will be saved.

Return type:

Path