Toy Instance Generation

Minimalist instance, for easy quick testing and debug.

Toy instance generation settings are defined in file toy_instance_generator.py.

ToyInstanceGenerator

class maenvs4vrp.environments.pdptw.toy_instance_generator.ToyInstanceGenerator(instance_type: str = 'toy', set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = None, seed: int = None)[source]

PDPTW toy instance generation class.

__init__(instance_type: str = 'toy', set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = None, seed: int = None) None[source]

Constructor. Toy instance generator for testing.

Parameters:
  • instance_type (str) – instance type. Can be “validation” or “test”. Defaults to “validation”.

  • set_of_instances (set) – Set of instances file names. Defaults to None.

  • device (str, optional) – Type of processing. It can be “cpu” or “gpu”. Defaults to “cpu”.

  • batch_size (torch.Size, optional) – Batch size. If not specified, defaults to 1. Defaults to None.

  • seed (int) – Random number generator seed. Defaults to None.

random_generate_instance(num_agents: int = 4, num_nodes: int = 13, capacity: int = 10, service_times: int = 0.2, batch_size: int = 1, seed: int = None) TensorDict[source]

Generate random toy instance.

Parameters:
  • num_agents (int) – Total number of agents. Defaults to 4.

  • num_nodes (int) – Total number of nodes. Defaults to 13.

  • capacity (int) – Total capacity for each agent. Defaults to 10.

  • service_times (int) – Service times in the nodes. Defaults to 0.2.

  • batch_size (int) – Batch size. Defaults to 1.

  • seed (int, optional) – Random number generator seed. Defaults to None.

Returns:

Instance data.

Return type:

TensorDict

sample_instance(num_agents=None, num_nodes=None, service_times=0.2, capacity=10, instance_name: str = None, sample_type: str = 'random', batch_size: Size | None = None, n_augment: int | None = None, seed: int = None) Dict[source]

Sample one instance from instance space.

Parameters:
  • num_agents (int) – Total number of agents. Defaults to None.

  • num_nodes (int) – Total number of nodes. Defaults to None.

  • service_times (float) – Service times in the nodes. Defaults to 0.2.

  • capacity (int) – Capacity of the agents. Defaults to 10.

  • instance_name (str) – Instance name. Defaults to None.

  • sample_type (str) – Sample type. It can be “random” or something else for “first n”. Defaults to “random”.

  • batch_size (torch.Size, optional) – Batch size. Defaults to None.

  • n_augment (int, optional) – Data augmentation. Defaults to None.

  • seed (int) – Random number generator seed. Defaults to None.

Returns:

Instance data.

Return type:

Dict