Benchmark Instance Generation¶
TODO: CHANGE HERE!
Solomon and Homberger instances are included to be used with CVRPTW environment.
Benchmark instance generation settings are defined in file benchmark_instances_generator.py.
Data files format¶
************************
* GMTDVRP instances *
************************
Data files format:
For these problem, data files format is as follows:
The first line contains the following data, number of paths, all vertices can be visited and number of vertices.
From the 3th line, each line contains the integer data associated to each customer, starting with the depot:
vertex number
x coordinate
y coordinate
service duration or visiting time
profit of the location
Opening of time window
Closing of time window
Gavalas
For these problem, data files format is as follows:
The first line contains the following data, number of tours, start day,number of vertices.
The second line associties with start/end point:
vertex number = 0
x coordinate
y coordinate
visiting duration = 0
score of the location = 0
Opening of time window
Closing of time window
The remaining lines contain the data of each point. For each point, the line contains the following data:
vertex number
x coordinate
y coordinate
visiting duration
score of the location
Opening hour of the day i, i = 0,1,2,3,4,5,6
Closing hour of the day i, i = 0,1,2,3,4,5,6
Taken from: https://www.sintef.no/projectweb/top/vrptw/
BenchmarkInstanceGenerator¶
- class maenvs4vrp.environments.gmtdvrp.benchmark_instances_generator.BenchmarkInstanceGenerator(problem_type: set = 'all', instance_type: str = None, set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = 1000, seed: int = None)[source]¶
GMTDVRP benchmark instance generation class.
- __init__(problem_type: set = 'all', instance_type: str = None, set_of_instances: set = None, device: str | None = 'cpu', batch_size: Size | None = 1000, seed: int = None) None[source]¶
Constructor. Create an instance space of one or several sets of data.
- Parameters:
problem_type (set) – Problem type. Defaults to “all”.
instance_type (str) – Instance type. It must be “50_test”, “100_test”, “50_validation” or “100_validation”. Defaults to None.
set_of_instances (set) – Set of instances paths. 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 1000.
seed (int) – Random number generator seed. Defaults to None.
- Returns:
None.
- classmethod download_and_copy_instances()[source]¶
Download benchmark instances from HuggingFace if they are not locally present.
- Parameters:
n/a.
- 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 path.
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 paths. Defaults to None.
- Returns:
None.
- random_sample_instance(instance_name: str = None, num_depots: int = None, num_agents: int = None, num_nodes: int = None, min_coords: float = None, max_coords: float = None, capacity: int = None, service_time: float = None, min_demands: int = None, max_demands: int = None, min_backhaul: int = None, max_backhaul: int = None, max_time: float = None, backhaul_ratio: float = None, backhaul_class: int = None, sample_backhaul_class: bool = False, max_distance_limit: float = None, speed: float = None, initial_load: float = None, subsample: bool = True, variant_preset=None, use_combinations: bool = False, force_visit: bool = True, batch_size: Size | None = None, seed: int = None, device: str | None = None) Dict[source]¶
Sample one instance from instance space, randomly adjusting the nodes.
- Parameters:
instance_name (str) – Instance file path. Defaults to None.
num_depots (int) – Total number of depots. Defaults to None.
num_agents (int) – Total number of agents. Defaults to None.
num_nodes (int) – Total number of nodes. Defaults to None.
min_coords (float) – Minimum number of coords. Defaults to None.
max_coords (float) – Maximum number of coords. Defaults to None.
capacity (int) – Vehicles’ capacity. Defaults to None.
service_time (float) – Service time. Defaults to None.
min_demands (int) – Minimum number of demands. Defaults to None.
max_demands (int) – Maximum number of demands. Defaults to None.
min_backhaul (int) – Minimum number of backhauls. Defaults to None.
max_backhaul (int) – Maximum number of backhauls. Defaults to None.
max_time (float) – Maximum route time. Defaults to None.
backhaul_ratio (float) – Ratio of backhaul demands. Defaults to None.
backhaul_class (int) – Class of backhaul problem. If 1, it’s unmixed, if 2, it’s mixed. Defaults to None.
sample_backhaul_class (bool) – If backhaul class is sampled across batches. Defaults to False.
max_distance_limit (float) – Route distance limits. Defaults to None.
speed (float) – Vehicles’ speed. Defaults to None.
initial_load (float) – Vehicles’ initial load. Defaults to None.
subsample (bool) – If problem variants are to be sampled. Defaults to True.
variant_preset (str) – Variant preset to be sampled. Defaults to None.
use_combinations (bool) – It considers combinations for which sampling mask the instance is defined. Defaults to False.
force_visit (bool) – It forces the agent to visit all feasible nodes before going back to depot. Defaults to True.
batch_size (torch.Size, optional) – Batch size. Defaults to None.
seed (int) – Random number generator seed. Defaults to None.
device (str, optional) – Type of processing. It can be “cpu” or “gpu”. Defaults to “cpu”.
- Returns:
Instance data.
- Return type:
Dict
- read_parse_instance_data(instance_name: str) Dict[source]¶
Read instance data from file. Benchmark’s instance keys are translated into our keys.
- Parameters:
instance_name (str) – Instance path.
- Returns:
Instance data.
- Return type:
Dict
- sample_instance(sample_type: str = 'random', instance_name: str = None, num_depots: int = None, num_agents: int = None, num_nodes: int = None, min_coords: float = None, max_coords: float = None, capacity: int = None, service_time: float = None, min_demands: int = None, max_demands: int = None, min_backhaul: int = None, max_backhaul: int = None, max_time: float = None, backhaul_ratio: float = None, backhaul_class: int = None, sample_backhaul_class: bool = False, max_distance_limit: float = None, speed: float = None, initial_load: float = None, subsample: bool = True, variant_preset=None, use_combinations: bool = False, force_visit: bool = True, batch_size: Size | None = None, seed: int = None, n_augment: int | None = None, device: str | None = None) Dict[source]¶
Sample one instance from instance space.
- Parameters:
sample_type (str) – Type of instance to sample. It can be “random” or “augment”. Defaults to “random”.
instance_name (str) – Instance file path. Defaults to None.
num_depots (int) – Total number of depots. Defaults to None.
num_agents (int) – Total number of agents. Defaults to None.
num_nodes (int) – Total number of nodes. Defaults to None.
min_coords (float) – Minimum number of coords. Defaults to None.
max_coords (float) – Maximum number of coords. Defaults to None.
capacity (int) – Vehicles’ capacity. Defaults to None.
service_time (float) – Service time. Defaults to None.
min_demands (int) – Minimum number of demands. Defaults to None.
max_demands (int) – Maximum number of demands. Defaults to None.
min_backhaul (int) – Minimum number of backhauls. Defaults to None.
max_backhaul (int) – Maximum number of backhauls. Defaults to None.
max_time (float) – Maximum route time. Defaults to None.
backhaul_ratio (float) – Ratio of backhaul demands. Defaults to None.
backhaul_class (int) – Class of backhaul problem. If 1, it’s unmixed, if 2, it’s mixed. Defaults to None.
sample_backhaul_class (bool) – If backhaul class is sampled across batches. Defaults to False.
max_distance_limit (float) – Route distance limits. Defaults to None.
speed (float) – Vehicles’ speed. Defaults to None.
initial_load (float) – Vehicles’ initial load. Defaults to None.
subsample (bool) – If problem variants are to be sampled. Defaults to True.
variant_preset (str) – Variant preset to be sampled. Defaults to None.
use_combinations (bool) – It considers combinations for which sampling mask the instance is defined. Defaults to False.
force_visit (bool) – It forces the agent to visit all feasible nodes before going back to depot. Defaults to True.
batch_size (torch.Size, optional) – Batch size. Defaults to None.
seed (int) – Random number generator seed. Defaults to None.
n_augment (int, optional) – Number of augmentations. Defaults to None.
device (str, optional) – Type of processing. It can be “cpu” or “gpu”. Defaults to “cpu”.
- Returns:
Instance data.
- Return type:
Dict