Benchmark Instance Generation

Benchmark instance generation settings are defined in file benchmark_instances_generator.py.

Data files format

************************
* TOPTW instances      *
************************

The first line contains the following data:

    k v N t

Where
    k = not relevant
    v = with this number of paths, all vertices can be visited
    N = number of vertices
    t = not relevant


The next line contains the following data:

        D Q

Where
    D = not relevant (in many files this number is missing)
    Q = not relevant


The remaining lines contain the data of each point.
For each point, the line contains the following data:

    i x y d S f a list O C

Where
    i = vertex number
    x = x coordinate
    y = y coordinate
    d = service duration or visiting time
    S = profit of the location
    f = not relevant
    a = not relevant
    list = not relevant (length of the list depends on a)
        O = opening of time window (earliest time for start of service)
    C = closing of time window (latest time for start of service)

* REMARKS *
    - The first point (index 0) is the starting AND ending point.
    - The number of paths (P) is not included in the data file. This value can vary (1,2,3, etc.).
    - The time budget per path (Tmax) equals the closing time of the starting point.
    - The Euclidean distance is used and rounded down to the first decimal for the Solomon instances
        and to the second decimal for the instances of Cordeau et al.

Taken from: https://www.mech.kuleuven.be/en/cib/op#autotoc-item-autotoc-6

BenchmarkInstanceGenerator

class maenvs4vrp.environments.toptw.benchmark_instances_generator.BenchmarkInstanceGenerator(instance_type: str = 'Solomon', set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = None, seed: int = None)[source]

TOPTW benchmark instance generation class.

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

Constructor. Create an instance space of one or several sets of data.

Parameters:
  • instance_type (str) – Instance type. Can be “Solomon” or “Homberger”. Defaults to “Solomon”.

  • 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.

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

Returns:

None.

eliminate_extra_columns(instance_data: list) list[source]

Cordeau instances have extra columns in some rows. This function eliminates the extra columns. This will also correct position of total time in row 0 for all instances.

Parameters:

instance_data (list) – Instance data.

Returns:

List with eliminated rows.

Return type:

list

get_instance(instance_name: str, num_agents: int = None) Dict[source]

Get an instance with custom number of agents.

Parameters:
  • instance_name (str) – Instance file name.

  • num_agents (int) – Number of agents. Defaults to None.

Returns:

Instance data.

Return type:

Dict

classmethod get_list_of_benchmark_instances()[source]

Get list of possible instances from benchmark files.

Parameters:

n/a.

Returns:

None.

load_set_of_instances(set_of_instances: set = None)[source]

Load every instance on set_of_instances set.

Parameters:

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

Returns:

None.

parse_instance_data(instance_data: list, instance_name: str) Dict[source]

Parse instance data list into a dictionary.

Parameters:

instance_data (list) – Instance data.

Returns:

Parsed instance data.

Return type:

Dict

random_sample_instance(instance_name: str = None, num_agents: int = None, num_nodes: int = None, seed: int = None, device: str | None = 'cpu') Dict[source]

Sample one instance from instance space, randomly adjusting the nodes.

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

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

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

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

Returns:

Instance data.

Return type:

Dict

read_instance_data(instance_name: str) Dict[source]

Read instance data from file.

Parameters:

instance_name (str) – Instance file name.

Returns:

Instance data.

Return type:

Dict

sample_instance(num_agents: int = None, num_nodes: int = None, service_times: float = None, profits: str = None, instance_name: str = None, sample_type: str = 'random', batch_size: Size | None = None, n_augment: int | None = None, seed: int = None, device: str | None = 'cpu') 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.

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

  • service_times (float) – Service time in the nodes. Defaults to None.

  • 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 or None) – 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

sample_name_from_set(seed: int = None) str[source]

Sample one instance from instance set.

Parameters:

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

Returns:

Instance sample name.

Return type:

str