culebra.solution.tsp.Species class

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

Bases: Species

Create a new species.

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

  • banned_nodes (Sequence[int]) – 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(filename: str) Base

Load a serialized object from a file.

Parameters:

filename (str) – The file name.

Returns:

The loaded object

Raises:

Properties

property Species.banned_nodes: ndarray[int]

Banned nodes.

Return type:

ndarray[int]

Setter:

Set new banned nodes

Parameters:

values (Sequence[int]) – The new banned nodes or None if all the nodes are allowed

Raises:
  • TypeError – If values is not a Sequence

  • ValueError – If any item in values is not a valid node index

property Species.num_nodes: int

Number of nodes.

Return type:

int

Methods

Species.dump(filename: str) None

Serialize this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Species.is_banned(node: int) bool

Check if a node is banned.

Parameters:

node (int) – The node index

Returns:

True if the node index provided is banned

Return type:

bool

Species.is_feasible(node: int) bool

Check if a node is feasible.

Parameters:

node (int) – The node index

Returns:

True if the node index provided is feasible.

Return type:

bool

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