culebra.solution.tsp.Species class

class Species(num_nodes: int, banned_nodes: Sequence[int] | None = None)

Create a new species.

Parameters:
  • num_nodes (int) – Number of nodes considered

  • banned_nodes (Sequence of int, optional) – Sequence of banned nodes. If provided, each node index in the sequence must be in the interval [0, num_nodes). Defaults to None

Raises:
  • TypeError – If any argument is not of the appropriate type

  • ValueError – If any argument has an incorrect value

Class methods

classmethod Species.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:

Properties

property Species.num_nodes: int

Get the number of nodes for this species.

Type:

int

property Species.banned_nodes: Sequence[int]

Get and set the sequence of banned nodes.

Type:

Sequence of int

Methods

Species.save_pickle(filename: str) None

Pickle this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Species.is_banned(node: int) bool

Return True if the node index provided is banned.

Parameters:

node (int) – The node index

Species.is_feasible(node: int) bool

Return True if the node index provided is feasible.

Parameters:

node (int) – The node index

Species.is_member(sol: Solution) bool

Check if a solution meets the constraints imposed by the species.

Parameters:

sol (Solution) – The solution

Returns:

True if the solution belongs to the species. False otherwise

Return type:

bool