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.mtvrp.toy_instance_generator.ToyInstanceGenerator(device: str | None = 'cpu', batch_size: Size | None = None, seed: int = None)[source]¶
MTVRP toy instance generation class.
- __init__(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.
- sample_instance(num_agents: int = 2, num_nodes: int = 15, capacity: int = 50, service_time: float = 0.2, subsample: bool = True, variant_preset=None, use_combinations: bool = False, force_visit: bool = True, batch_size: int = 1, seed: int = None, device: str | None = 'cpu', **kwargs) TensorDict[source]¶
Sample one instance from instance space.
- Parameters:
num_agents (int) – Total number of agents. Defaults to 2.
num_nodes (int) – Total number of nodes. Defaults to 15.
capacity (int) – Capacity of the agents. Defaults to 50.
service_times (float) – Service times in the nodes. Defaults to 0.2.
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 1.
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
- subsample_variant(prob_open_routes: float = 0.5, prob_time_windows: float = 0.5, prob_limit: float = 0.5, prob_backhaul: float = 0.5, td: TensorDict = None, variant_preset=None) Tensor[source]¶
Subsample variant. If variant_preset is specified, it loads that variant. Otherwise it samples variant’s parameters across batches based on probabilities.
- Parameters:
prob_open_routes (float) – Probability of open routes. Defaults to 0.5.
prob_time_windows (float) – Probability of time windows. Defaults to 0.5.
prob_limit (float) – Probability of distance limits. Defaults to 0.5.
prob_backhaul (float) – Probability of backhaul. Defaults to 0.5.
td (TensorDict) – Environment instance tensor. Defaults to None.
variant_preset (TensorDict) – Variant preset. Defaults to None.
- Returns:
Environment instance tensor.
- Return type:
td(TensorDict)