Benchmark Instance Generation¶
MDVRPTW environment instances are introduced in [Vid2013]:
Benchmark instance generation settings are defined in file benchmark_instances_generator.py.
Data files format¶
************************
* MDVRPTW instances *
************************
The first line contains the following information:
type m n t d
where
type = 8 (MDPVRP)
m = number of vehicles
n = number of customers
t = number of days
d = number of depots
The next t lines contain, for each day/depot, the following information:
D Q
where
D = maximum duration of a route
Q = maximum load of a vehicle
The next lines contain, for each depot and for each customer, the following information:
i x y d q f a list e l
where
i = customer/depot number
x = x coordinate
y = y coordinate
d = service duration
q = demand
f = frequency of visit
a = number of possible visit combinations
list = list of all possible visit combinations
e = beginning of time window (earliest time for start of service),
if any
l = end of time window (latest time for start of service), if any
Each visit combination is coded with the decimal equivalent of
the corresponding binary bit string. For example, in a 5-day
period, the code 10 which is equivalent to the bit string 01010
means that a customer is visited on days 2 and 4. (Days are
numbered from left to right.)
BenchmarkInstanceGenerator¶
- class maenvs4vrp.environments.mdvrptw.benchmark_instances_generator.BenchmarkInstanceGenerator(instance_type: str = 'Vidal', set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = None, seed: int = None)[source]¶
MDVRPTW benchmark instance generation class.
- __init__(instance_type: str = 'Vidal', 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.
- 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, num_depots: 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_first_n_services(instance_name: str = None, num_agents: int = None, num_nodes: int = None, device: str | None = 'cpu') Dict[source]¶
Sample first n 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 (n) nodes intended. Defaults to None.
- Returns:
New instance of the first n nodes.
- Return type:
Dict
- sample_instance(num_agents: int = None, num_nodes: int = None, capacity: int = None, service_times: float = 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
References
M, T. Vidal, T. G. Crainic, M. Gendreau, and C. Prins, A hybrid genetic algorithm with adaptive diversity management for a large class of vehicle routing problems with time-windows, Comput. Oper. Res., vol. 40, no. 1, pp. 475-489, 2013.