Environment

MTDVRP environment operations.

Environment settings are defined in file env.py.

Environment

class maenvs4vrp.environments.mtdvrp.env.Environment(instance_generator_object: InstanceBuilder, obs_builder_object: ObservationBuilder, agent_selector_object: BaseSelector, reward_evaluator: RewardFn, seed=None, device: str | None = None, batch_size: Size = None)[source]

MTDVRP environment generator class.

__init__(instance_generator_object: InstanceBuilder, obs_builder_object: ObservationBuilder, agent_selector_object: BaseSelector, reward_evaluator: RewardFn, seed=None, device: str | None = None, batch_size: Size = None)[source]

Constructor.

Parameters:
  • instance_generator_object (InstanceBuilder) – Generator instance.

  • obs_builder_object (ObservationBuilder) – Observations instance.

  • agent_selector_object (BaseSelector) – Agent selector instance

  • reward_evaluator (RewardFn) – Reward evaluator instance.

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

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

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

check_solution_validity()[source]

Check if solution is valid according to constraints.

Parameters:

N/a.

Returns:

None.

observe(is_reset=False) TensorDict[source]

Retrieve agent environment observations.

Parameters:

is_reset (bool) – If the environment is on reset. Defauts to False.

Returns

td_observations(TensorDict): Current agent observaions and masks dictionary.

reset(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, instance_name: str | None = 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 = None, max_distance_limit: float = None, speed: float = None, subsample: bool = True, variant_preset: str = None, use_combinations: bool = False, instance_dict: Dict = None, force_visit: bool = False, batch_size: Size | None = None, n_augment: int | None = 2, sample_type: str = 'random', seed: int = None, device: str | None = 'cpu')[source]

Reset the environment.

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

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

  • n_augment (int, optional) – Number of augmentations. Defaults to None.

  • sample_type (str) – Type of instance to sample. It can be “random”, “augment” or “saved”. Defaults to “random”.

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

Environment information dictionary.

Return type:

TensorDict

sample_action(td: TensorDict) TensorDict[source]

Compute a random action from avaliable actions to current agent.

Parameters:

td (TensorDict) – Environment instance tensor.

Returns:

Environment instance tensor with updated action.

Return type:

td(TensorDict)

step(td: TensorDict) TensorDict[source]

Perform an environment step for active agent.

Parameters:

td (TensorDict) – Environment tensor instance.

Returns:

Updated environment tensor instance.

Return type:

td(TensorDict)