cube_solver.solver.utils module

Solver utils module.

cube_solver.solver.utils.flatten(coords)[source]

Get the flattened cube coordinates.

Parameters:

coords (tuple of (int or tuple of int)) – Cube coordinates.

Returns:

flatten_coords – Flattened cube coordinates.

Return type:

tuple of int

Examples

>>> from cube_solver import Cube
>>> from cube_solver.solver import utils
>>> cube = Cube()
>>> coords = cube.get_coords(partial_corner_perm=True, partial_edge_perm=True)
>>> coords
(0, 0, (0, 1656), (0, 11856, 1656))
>>> utils.flatten(coords)
(0, 0, 0, 1656, 0, 11856, 1656)
cube_solver.solver.utils.select(coords, indexes)[source]

Select coordinates.

Parameters:
  • coords (tuple of int) – Coordinates.

  • indexes (int or tuple of int or None) – Index or indexes of the coordinates to select. If None, all coordinates are selected.

Returns:

selected_coords – Selected coordinates.

Return type:

tuple of int

Examples

>>> from cube_solver import Cube
>>> from cube_solver.solver import utils
>>> cube = Cube()
>>> coords = cube.get_coords(partial_corner_perm=True, partial_edge_perm=True)
>>> flatten_coords = utils.flatten(coords)
>>> utils.select(flatten_coords, None)
(0, 0, 0, 1656, 0, 11856, 1656)
>>> utils.select(flatten_coords, 5)
(11856,)
>>> utils.select(flatten_coords, (3, 5, 6))
(1656, 11856, 1656)
cube_solver.solver.utils.load_tables(path)[source]

Load the tables from a file.

Parameters:

path (str or Path) – Path of the file.

Returns:

tables – Dictionary containig the tables.

Return type:

dict

cube_solver.solver.utils.save_tables(path, tables)[source]

Save the tables into a single file.

Parameters:
  • path (str or Path) – Path of the file.

  • tables (dict) – Dictionary containig the tables.

cube_solver.solver.utils.get_tables(filename, tables_defs, generate_table_fn, accumulate=False)[source]

Create or load tables from the tables/ directory according to the tables_defs.

If the file does not exist, or if it exists but is missing some tables, create the missing tables from tables_defs and update the file.

Parameters:
  • filename (str) – Name of the file in the tables/ directory.

  • tables_defs (list of TableDef) – Table definitions.

  • generate_table_fn (Callable) – Function to generate the table. It must accept the TableDef keyword arguments.

  • accumulate (bool, optional) – Whether to keep the tables not included in tables_defs. Default is False.

Returns:

tables – Dictionary containig the tables. The keys represent the name of the table from TableDef.name.

Return type:

dict

cube_solver.solver.utils.generate_transition_table(coord_name, coord_size)[source]

Generate the cube coordinate transition table.

Parameters:
  • coord_name (str) – Cube coordinate name.

  • coord_size (int) – Cube coordinate size.

Returns:

transition_table – Cube coordinate transition table.

Return type:

ndarray

cube_solver.solver.utils.generate_pruning_table(solver, phase, shape, indexes, **kwargs)[source]

Generate the phase coordinates pruning table.

Parameters:
  • solver (BaseSolver) – Solver object.

  • phase (int) – Solver phase (0-indexed).

  • shape (int or tuple of int) – Shape of the pruning table.

  • indexes (int or tuple of int or None) – Index or indexes of the phase coordinates to use for the pruning table. If None, use all the phase coordinates.

Returns:

pruning_table – Phase coordinates pruning table.

Return type:

ndarray