Observations

GMTDVRP observations.

Observations settings are defined in file observations.py.

Observations

class maenvs4vrp.environments.gmtdvrp.observations.Observations(feature_list: Dict = None)[source]

GMTDVRP observations class.

__init__(feature_list: Dict = None)[source]

Constructor

Parameters:

feature_list (Dict) – Dictionary containing observation features list to be available to the agent. Defaults to None.

set_env(env: AECEnv)[source]

Set environment.

Parameters:

env (AECEnv) – Environment.

Returns:

None.

Nodes static features

Observations.get_feat_x_coordinate()[source]

Instance nodes X coordinates.

Parameters:

n/a.

Returns:

Instance nodes X coordinates.

Return type:

torch.Tensor

Observations.get_feat_y_coordinate()[source]

Instance nodes Y coordinates.

Parameters:

n/a.

Returns:

Instance nodes Y coordinates.

Return type:

torch.Tensor

Observations.get_feat_x_coordinate_min_max()[source]

Min-max normalized X coordinates of instance nodes.

Parameters:

n/a.

Returns:

Min. and max. x coordinates of instance nodes.

Return type:

torch.Tensor

Observations.get_feat_y_coordinate_min_max()[source]

Min-max normalized Y coordinates of instance nodes.

Parameters:

n/a.

Returns:

Min-max normalized Y coordinates of instance nodes.

Return type:

torch.Tensor

Observations.get_feat_tw_low()[source]

Nodes time windows starting times.

Parameters:

n/a.

Returns:

Nodes time windows starting times.

Return type:

torch.Tensor

Observations.get_feat_tw_high()[source]

Nodes time windows ending times.

Parameters:

n/a.

Returns:

Nodes time windows ending times.

Return type:

torch.Tensor

Observations.get_feat_linehaul_demand()[source]

Nodes linehaul demands.

Parameters:

n/a.

Returns:

Nodes linehaul demands.

Return type:

torch.Tensor

Observations.get_feat_backhaul_demand()[source]

Nodes backhaul demands.

Parameters:

n/a.

Returns:

Nodes backhaul demands.

Return type:

torch.Tensor

Observations.get_feat_service_time()[source]

Nodes service times.

Parameters:

n/a.

Returns:

Nodes service times.

Return type:

torch.Tensor

Observations.get_feat_tw_high_minus_tw_low_div_max_dur()[source]

Nodes time window amplitude divided by max tour duration.

Parameters:

n/a.

Returns:

Nodes time window amplitude divided by max tour duration.

Return type:

torch.Tensor

Observations.get_feat_is_depot()[source]

Checks if node is depot.

Parameters:

n/a.

Returns:

If the node is depot or not.

Return type:

torch.Tensor

Nodes dynamic features

Observations.get_feat_time2open_div_end_time()[source]

Nodes time to open divided by end time.

Parameters:

n/a.

Returns:

Nodes time to open divided by end time.

Return type:

torch.Tensor

Observations.get_feat_time2close_div_end_time()[source]

Nodes time to close divided by end time.

Parameters:

n/a.

Returns:

Nodes time to close divided by end time.

Return type:

torch.Tensor

Observations.get_feat_arrive2node_div_end_time()[source]

Agent arriving time to nodes divided by end time.

Parameters:

n/a.

Returns:

Agent arriving time to nodes divided by end time.

Return type:

torch.Tensor

Observations.get_feat_time2open_after_step_div_end_time()[source]

Nodes time to open, after agent step, divided by end time.

Parameters:

n/a.

Returns:

Nodes time to open, after agent step, divided by end time.

Return type:

torch.Tensor

Observations.get_feat_time2close_after_step_div_end_time()[source]

Nodes time to close, after agent step, divided by end time.

Parameters:

n/a.

Returns:

Nodes time to close, after agent step, divided by end time.

Return type:

torch.Tensor

Observations.get_feat_time2end_after_step_div_end_time()[source]

Time end, after agent step to node, divided by end time.

Parameters:

n/a.

Returns:

Time end, after agent step to node, divided by end time.

Return type:

torch.Tensor

Observations.get_feat_fract_time_after_step_div_end_time()[source]

Fraction of time left, after agent step to node.

Parameters:

n/a.

Returns:

Fraction of time left, after agent step to node.

Return type:

torch.Tensor

Observations.get_feat_reachable_frac_agents()[source]

Feasible nodes per agent.

Parameters:

n/a.

Returns:

Feasible nodes per agent.

Return type:

torch.Tensor

Current agent features

Observations.get_feat_agent_x_coordinate()[source]

Current agent X coordinate.

Parameters:

n/a.

Returns:

Current agent X coordinate.

Return type:

torch.Tensor

Observations.get_feat_agent_y_coordinate()[source]

Current agent Y coordinate.

Parameters:

n/a.

Returns:

Current agent Y coordinate.

Return type:

torch.Tensor

Observations.get_feat_agent_x_coordinate_min_max()[source]

Current agent min-max normalized X location.

Parameters:

n/a.

Returns:

Current agent min-max normalized X location.

Return type:

torch.Tensor

Observations.get_feat_agent_y_coordinate_min_max()[source]

Current agent min-max normalized Y location.

Parameters:

n/a.

Returns:

Current agent min-max normalized Y location.

Return type:

torch.Tensor

Observations.get_feat_agent_frac_current_time()[source]

Agent fraction of time elapsed.

Parameters:

n/a.

Returns:

Agent fraction of time elapsed.

Return type:

torch.Tensor

Observations.get_feat_agent_cur_linehaul_load()[source]

Current linehaul load carried by agent.

Parameters:

n/a.

Returns:

Current linehaul load.

Return type:

torch.Tensor

Observations.get_feat_agent_cur_backhaul_load()[source]

Current backhaul load carried by agent.

Parameters:

n/a.

Returns:

Current backhaul load.

Return type:

torch.Tensor

Observations.get_feat_agent_avaliable_load()[source]

Agent’s avaliable load when problem is unmixed.

Parameters:

n/a.

Returns:

Avaliable load.

Return type:

torch.Tensor

Observations.get_feat_agent_avaliable_load_vrpmpd()[source]

Agent’s avaliable load when problem is mixed.

Parameters:

n/a.

Returns:

Avaliable load.

Return type:

torch.Tensor

Observations.get_feat_agent_arrivedepot_div_end_time()[source]

Agent time to depot divided by end time.

Parameters:

n/a.

Returns:

Agent time to depot divided by end time.

Return type:

torch.Tensor

Observations.get_feat_agent_frac_feasible_nodes()[source]

Fraction of current agent feasible nodes, in order to the total number of instance nodes.

Parameters:

n/a.

Returns:

Fraction of current agent feasible nodes, in order to the total number of instance nodes.

Return type:

torch.Tensor

Observations.get_feat_agent_remaining_dist()[source]

Agent’s remaining distance.

Parameters:

n/a.

Returns:

Remaining distance.

Return type:

torch.Tensor

Observations.get_feat_agent_current_time()[source]

Agent’s current time.

Parameters:

n/a.

Returns:

Current time.

Return type:

torch.Tensor

Other agents features

Observations.get_feat_agents_x_coordinate()[source]

Agents X coordinates.

Parameters:

n/a.

Returns:

Agents X coordinates.

Return type:

torch.Tensor

Observations.get_feat_agents_y_coordinate()[source]

Agents Y coordinates.

Parameters:

n/a.

Returns:

Agents Y coordinates.

Return type:

torch.Tensor

Observations.get_feat_agents_x_coordinate_min_max()[source]

Agents min-max normalized X location.

Parameters:

n/a.

Returns:

Agents min-max normalized X location.

Return type:

torch.Tensor

Observations.get_feat_agents_y_coordinate_min_max()[source]

Agents min-max normalized Y location.

Parameters:

n/a.

Returns:

Agents min-max normalized Y location.

Return type:

torch.Tensor

Observations.get_feat_agents_frac_current_time()[source]

Agents fraction of elapsed time.

Parameters:

n/a.

Returns:

Agents fraction of elapsed time.

Return type:

torch.Tensor

Observations.get_feat_agents_dist2depot_div_end_time()[source]

Fraction of current agent distance to depot compared to its end time.

Parameters:

n/a.

Returns:

Fraction of current agent distance to depot compared to its end time.

Return type:

torch.Tensor

Observations.get_feat_agents_dist2agent_div_end_time()[source]

Agents distance to active agent divided by end time.

Parameters:

n/a.

Returns:

Agents distance to active agent divided by end time.

Return type:

torch.Tensor

Observations.get_feat_agents_frac_feasible_nodes()[source]

Fraction of agents feasible nodes, in order to the total number of instance nodes.

Parameters:

n/a.

Returns:

Fraction of agents feasible nodes, in order to the total number of instance nodes.

Return type:

torch.Tensor

Observations.get_feat_agents_time_delta2agent_div_max_dur()[source]

Difference between agents time and current agent time, divided by max. tour duration.

Parameters:

n/a.

Returns:

Difference between agents time and current agent time, divided by max. tour duration.

Return type:

torch.Tensor

Observations.get_feat_agents_was_last()[source]

Last agent performing an action.

Parameters:

n/a.

Returns:

Last agent performing an action.

Return type:

torch.Tensor

Global features

Observations.get_feat_global_frac_done_agents()[source]

Fraction of done agents.

Parameters:

n/a.

Returns:

Fraction of done agents.

Return type:

torch.Tensor

Observations.get_feat_global_frac_linehaul_demands()[source]

Fraction of served demands.

Parameters:

n/a.

Returns:

Fraction of served demands.

Return type:

torch.Tensor

Observations.get_feat_global_frac_backhaul_demands()[source]

Fraction of served demands.

Parameters:

n/a.

Returns:

Fraction of served demands.

Return type:

torch.Tensor

Observations.get_feat_global_open_routes()[source]

Checks if problems have open routes.

Parameters:

n/a.

Returns:

Open routes.

Return type:

torch.Tensor

Observations.get_feat_global_distance_limits()[source]

Chack problems distance limits.

Parameters:

n/a.

Returns:

Distance limits.

Return type:

torch.Tensor

Observations.get_feat_global_max_tw_depot()[source]

High tw from depot. Max tour duration.

Parameters:

N/a.

Returns:

Max tour duration.

Return type:

torch.Tensor

Observations.get_feat_global_is_problem_backhaul_mixed()[source]

Checks if problem is mixed. 0 means it’s unmixed, 1 means it’s mixed.

Parameters:

n/a.

Returns:

Is problem mixed?

Return type:

torch.Tensor

Computing features

Observations.compute_static_features()[source]

Compute nodes static features.

Parameters:

n/a.

Returns:

Nodes static features.

Return type:

torch.Tensor

Observations.compute_dynamic_features()[source]

Compute nodes dynamic features.

Parameters:

n/a.

Returns:

Nodes dynamic features.

Return type:

torch.Tensor

Observations.compute_agent_features()[source]

Compute current agent features.

Parameters:

n/a.

Returns:

Current agent features.

Return type:

torch.Tensor

Observations.compute_agents_features()[source]

Compute other agent features.

Parameters:

n/a.

Returns:

Other agent features.

Return type:

torch.Tensor

Observations.compute_global_features()[source]

Compute global features.

Parameters:

n/a.

Returns:

Global features.

Return type:

torch.Tensor

Observations.get_observations(is_reset=False) TensorDict[source]

Compute the environment.

Parameters:

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

Returns

observations(TensorDict): Current environment observations and masks dictionary.

Internal methods

static Observations._concat_features(features)[source]

Concatenate features.

Parameters:

features (list) – Features to concatenate.

Returns:

Concatenated tensor.

Return type:

torch.Tensor

Observations._normalize_feature(x, norm)[source]

Normalize features.

Parameters:
  • x (torch.Tensor) – Tensor to be normalized.

  • norm (str) – Type of normalization. It can be ‘min_max’ or ‘standardize’. If None, tensor is returned.

Returns:

Tensor normalized or default tensor if norm is invalid.

Return type:

torch.Tensor

static Observations._min_max_normalization(x)[source]

Min. max. normalization.

Parameters:

x (torch.Tensor) – Tensor to be normalized.

Returns:

Normalized tensor.

Return type:

torch.Tensor

static Observations._min_max_normalization2d(x)[source]

Min. max. normalization 2 dimensions.

Parameters:

x (torch.Tensor) – Tensor to be normalized.

Returns:

Normalized tensor.

Return type:

torch.Tensor

static Observations._standardize(x)[source]

Tensor standardization.

Parameters:

x (torch.Tensor) – Tensor to be normalized.

Returns:

Normalized tensor.

Return type:

torch.Tensor