Environment Embeddings¶
In autoregressive policies, environment embeddings transfer data from feature space to hidden space:
- Initial Embeddings: encode global problem features
- Context Embeddings: modify current node embedding during decoding
- Dynamic Embeddings: modify all nodes embeddings during decoding
Context Embeddings¶
The context embedding is used to modify the query embedding of the problem node of the current partial solution. Usually consists of a projection of gathered node embeddings and features to the embedding space.
Classes:
-
EnvContext
–Base class for environment context embeddings. The context embedding is used to modify the
-
FFSPContext
– -
TSPContext
–Context embedding for the Traveling Salesman Problem (TSP).
-
VRPContext
–Context embedding for the Capacitated Vehicle Routing Problem (CVRP).
-
VRPTWContext
–Context embedding for the Capacitated Vehicle Routing Problem (CVRP).
-
SVRPContext
–Context embedding for the Skill Vehicle Routing Problem (SVRP).
-
PCTSPContext
–Context embedding for the Prize Collecting TSP (PCTSP).
-
OPContext
–Context embedding for the Orienteering Problem (OP).
-
DPPContext
–Context embedding for the Decap Placement Problem (DPP), EDA (electronic design automation).
-
PDPContext
–Context embedding for the Pickup and Delivery Problem (PDP).
-
MTSPContext
–Context embedding for the Multiple Traveling Salesman Problem (mTSP).
-
SMTWTPContext
–Context embedding for the Single Machine Total Weighted Tardiness Problem (SMTWTP).
-
MDCPDPContext
–Context embedding for the MDCPDP.
-
MTVRPContext
–Context embedding for Multi-Task VRPEnv.
-
FLPContext
–Context embedding for the Facility Location Problem (FLP).
-
MCPContext
–Context embedding for the Maximum Coverage Problem (MCP).
Functions:
-
env_context_embedding
–Get environment context embedding. The context embedding is used to modify the
EnvContext
¶
EnvContext(
embed_dim, step_context_dim=None, linear_bias=False
)
Bases: Module
Base class for environment context embeddings. The context embedding is used to modify the query embedding of the problem node of the current partial solution. Consists of a linear layer that projects the node features to the embedding space.
Source code in rl4co/models/nn/env_embeddings/context.py
55 56 57 58 59 |
|
FFSPContext
¶
FFSPContext(embed_dim, stage_cnt=None)
Bases: EnvContext
Source code in rl4co/models/nn/env_embeddings/context.py
78 79 80 81 82 83 |
|
TSPContext
¶
TSPContext(embed_dim)
Bases: EnvContext
Context embedding for the Traveling Salesman Problem (TSP). Project the following to the embedding space:
- first node embedding
- current node embedding
Source code in rl4co/models/nn/env_embeddings/context.py
112 113 114 115 116 |
|
VRPContext
¶
VRPContext(embed_dim)
Bases: EnvContext
Context embedding for the Capacitated Vehicle Routing Problem (CVRP). Project the following to the embedding space:
- current node embedding
- remaining capacity (vehicle_capacity - used_capacity)
Source code in rl4co/models/nn/env_embeddings/context.py
150 151 152 153 |
|
VRPTWContext
¶
VRPTWContext(embed_dim)
Bases: VRPContext
Context embedding for the Capacitated Vehicle Routing Problem (CVRP). Project the following to the embedding space:
- current node embedding
- remaining capacity (vehicle_capacity - used_capacity)
- current time
Source code in rl4co/models/nn/env_embeddings/context.py
168 169 170 171 |
|
SVRPContext
¶
SVRPContext(embed_dim)
Bases: EnvContext
Context embedding for the Skill Vehicle Routing Problem (SVRP). Project the following to the embedding space:
- current node embedding
- current technician
Source code in rl4co/models/nn/env_embeddings/context.py
186 187 |
|
PCTSPContext
¶
PCTSPContext(embed_dim)
Bases: EnvContext
Context embedding for the Prize Collecting TSP (PCTSP). Project the following to the embedding space:
- current node embedding
- remaining prize (prize_required - cur_total_prize)
Source code in rl4co/models/nn/env_embeddings/context.py
201 202 |
|
OPContext
¶
OPContext(embed_dim)
Bases: EnvContext
Context embedding for the Orienteering Problem (OP). Project the following to the embedding space:
- current node embedding
- remaining distance (max_length - tour_length)
Source code in rl4co/models/nn/env_embeddings/context.py
218 219 |
|
DPPContext
¶
DPPContext(embed_dim)
Bases: EnvContext
Context embedding for the Decap Placement Problem (DPP), EDA (electronic design automation). Project the following to the embedding space:
- current cell embedding
Methods:
-
forward
–Context cannot be defined by a single node embedding for DPP, hence 0.
Source code in rl4co/models/nn/env_embeddings/context.py
232 233 |
|
forward
¶
forward(embeddings, td)
Context cannot be defined by a single node embedding for DPP, hence 0. We modify the dynamic embedding instead to capture placed items
Source code in rl4co/models/nn/env_embeddings/context.py
235 236 237 238 239 |
|
PDPContext
¶
PDPContext(embed_dim)
Bases: EnvContext
Context embedding for the Pickup and Delivery Problem (PDP). Project the following to the embedding space:
- current node embedding
Source code in rl4co/models/nn/env_embeddings/context.py
248 249 |
|
MTSPContext
¶
MTSPContext(embed_dim, linear_bias=False)
Bases: EnvContext
Context embedding for the Multiple Traveling Salesman Problem (mTSP). Project the following to the embedding space:
- current node embedding
- remaining_agents
- current_length
- max_subtour_length
- distance_from_depot
Source code in rl4co/models/nn/env_embeddings/context.py
266 267 268 269 270 271 |
|
SMTWTPContext
¶
SMTWTPContext(embed_dim)
Bases: EnvContext
Context embedding for the Single Machine Total Weighted Tardiness Problem (SMTWTP). Project the following to the embedding space:
- current node embedding
- current time
Source code in rl4co/models/nn/env_embeddings/context.py
302 303 |
|
MDCPDPContext
¶
MDCPDPContext(embed_dim)
Bases: EnvContext
Context embedding for the MDCPDP. Project the following to the embedding space:
- current node embedding
Source code in rl4co/models/nn/env_embeddings/context.py
320 321 |
|
MTVRPContext
¶
MTVRPContext(embed_dim)
Bases: VRPContext
Context embedding for Multi-Task VRPEnv. Project the following to the embedding space:
- current node embedding
- remaining_linehaul_capacity (vehicle_capacity - used_capacity_linehaul)
- remaining_backhaul_capacity (vehicle_capacity - used_capacity_backhaul)
- current time
- current_route_length
- open route indicator
Source code in rl4co/models/nn/env_embeddings/context.py
352 353 354 355 |
|
FLPContext
¶
FLPContext(embed_dim: int)
Bases: EnvContext
Context embedding for the Facility Location Problem (FLP).
Source code in rl4co/models/nn/env_embeddings/context.py
381 382 383 384 |
|
MCPContext
¶
MCPContext(embed_dim: int)
Bases: EnvContext
Context embedding for the Maximum Coverage Problem (MCP).
Source code in rl4co/models/nn/env_embeddings/context.py
399 400 401 402 |
|
env_context_embedding
¶
Get environment context embedding. The context embedding is used to modify the query embedding of the problem node of the current partial solution. Usually consists of a projection of gathered node embeddings and features to the embedding space.
Parameters:
-
env
–Environment or its name.
-
config
(dict
) –A dictionary of configuration options for the environment.
Source code in rl4co/models/nn/env_embeddings/context.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Dynamic Embeddings¶
The dynamic embedding is used to modify query, key and value vectors of the attention mechanism based on the current state of the environment (which is changing during the rollout). Generally consists of a linear layer that projects the node features to the embedding space.
Classes:
-
StaticEmbedding
–Static embedding for general problems.
-
SDVRPDynamicEmbedding
–Dynamic embedding for the Split Delivery Vehicle Routing Problem (SDVRP).
Functions:
-
env_dynamic_embedding
–Get environment dynamic embedding. The dynamic embedding is used to modify query, key and value vectors of the attention mechanism
StaticEmbedding
¶
StaticEmbedding(*args, **kwargs)
Bases: Module
Static embedding for general problems. This is used for problems that do not have any dynamic information, except for the information regarding the current action (e.g. the current node in TSP). See context embedding for more details.
Source code in rl4co/models/nn/env_embeddings/dynamic.py
53 54 |
|
SDVRPDynamicEmbedding
¶
SDVRPDynamicEmbedding(embed_dim, linear_bias=False)
Bases: Module
Dynamic embedding for the Split Delivery Vehicle Routing Problem (SDVRP). Embed the following node features to the embedding space:
- demand_with_depot: demand of the customers and the depot
The demand with depot is used to modify the query, key and value vectors of the attention mechanism based on the current state of the environment (which is changing during the rollout).
Source code in rl4co/models/nn/env_embeddings/dynamic.py
68 69 70 |
|
env_dynamic_embedding
¶
Get environment dynamic embedding. The dynamic embedding is used to modify query, key and value vectors of the attention mechanism based on the current state of the environment (which is changing during the rollout). Consists of a linear layer that projects the node features to the embedding space.
Parameters:
-
env
–Environment or its name.
-
config
(dict
) –A dictionary of configuration options for the environment.
Source code in rl4co/models/nn/env_embeddings/dynamic.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
Init Embeddings¶
The init embedding is used to initialize the general embedding of the problem nodes without any solution information. Generally consists of a linear layer that projects the node features to the embedding space.
Classes:
-
TSPInitEmbedding
–Initial embedding for the Traveling Salesman Problems (TSP).
-
MatNetInitEmbedding
–Preparing the initial row and column embeddings for MatNet.
-
VRPInitEmbedding
–Initial embedding for the Vehicle Routing Problems (VRP).
-
VRPPolarInitEmbedding
–Initial embedding for the Vehicle Routing Problems (VRP).
-
PCTSPInitEmbedding
–Initial embedding for the Prize Collecting Traveling Salesman Problems (PCTSP).
-
OPInitEmbedding
–Initial embedding for the Orienteering Problems (OP).
-
DPPInitEmbedding
–Initial embedding for the Decap Placement Problem (DPP), EDA (electronic design automation).
-
MDPPInitEmbedding
–Initial embedding for the Multi-port Placement Problem (MDPP), EDA (electronic design automation).
-
PDPInitEmbedding
–Initial embedding for the Pickup and Delivery Problem (PDP).
-
MTSPInitEmbedding
–Initial embedding for the Multiple Traveling Salesman Problem (mTSP).
-
SMTWTPInitEmbedding
–Initial embedding for the Single Machine Total Weighted Tardiness Problem (SMTWTP).
-
MDCPDPInitEmbedding
–Initial embedding for the MDCPDP environment
Functions:
-
env_init_embedding
–Get environment initial embedding. The init embedding is used to initialize the
TSPInitEmbedding
¶
TSPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Traveling Salesman Problems (TSP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the cities
Source code in rl4co/models/nn/env_embeddings/init.py
61 62 63 64 |
|
MatNetInitEmbedding
¶
Bases: Module
Preparing the initial row and column embeddings for MatNet.
Source code in rl4co/models/nn/env_embeddings/init.py
81 82 83 84 85 86 87 88 89 |
|
VRPInitEmbedding
¶
VRPInitEmbedding(
embed_dim, linear_bias=True, node_dim: int = 3
)
Bases: Module
Initial embedding for the Vehicle Routing Problems (VRP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot and customers separately)
- demand: demand of the customers
Source code in rl4co/models/nn/env_embeddings/init.py
122 123 124 125 126 |
|
VRPPolarInitEmbedding
¶
VRPPolarInitEmbedding(
embed_dim,
linear_bias=True,
node_dim: int = 3,
attach_cartesian_coords=False,
)
Bases: Module
Initial embedding for the Vehicle Routing Problems (VRP). Embed the following node features to the embedding space, based on polar coordinates:
- locs: r, theta coordinates of the nodes, with the depot as the origin
- demand: demand of the customers
Source code in rl4co/models/nn/env_embeddings/init.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
PCTSPInitEmbedding
¶
PCTSPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Prize Collecting Traveling Salesman Problems (PCTSP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot and customers separately)
- expected_prize: expected prize for visiting the customers.
In PCTSP, this is the actual prize. In SPCTSP, this is the expected prize.
- penalty: penalty for not visiting the customers
Source code in rl4co/models/nn/env_embeddings/init.py
236 237 238 239 240 |
|
OPInitEmbedding
¶
OPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Orienteering Problems (OP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot and customers separately)
- prize: prize for visiting the customers
Source code in rl4co/models/nn/env_embeddings/init.py
267 268 269 270 271 |
|
DPPInitEmbedding
¶
DPPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Decap Placement Problem (DPP), EDA (electronic design automation). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (cells)
- probe: index of the (single) probe cell. We embed the euclidean distance from the probe to all cells.
Source code in rl4co/models/nn/env_embeddings/init.py
296 297 298 299 300 |
|
MDPPInitEmbedding
¶
MDPPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Multi-port Placement Problem (MDPP), EDA (electronic design automation). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (cells)
- probe: indexes of the probe cells (multiple). We embed the euclidean distance of each cell to the closest probe.
Source code in rl4co/models/nn/env_embeddings/init.py
322 323 324 325 326 327 328 329 |
|
PDPInitEmbedding
¶
PDPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Pickup and Delivery Problem (PDP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot, pickups and deliveries separately)
Note that pickups and deliveries are interleaved in the input.
Source code in rl4co/models/nn/env_embeddings/init.py
354 355 356 357 358 359 |
|
MTSPInitEmbedding
¶
MTSPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Multiple Traveling Salesman Problem (mTSP). Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot, cities)
Source code in rl4co/models/nn/env_embeddings/init.py
381 382 383 384 385 386 |
|
SMTWTPInitEmbedding
¶
SMTWTPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the Single Machine Total Weighted Tardiness Problem (SMTWTP). Embed the following node features to the embedding space:
- job_due_time: due time of the jobs
- job_weight: weights of the jobs
- job_process_time: the processing time of jobs
Source code in rl4co/models/nn/env_embeddings/init.py
402 403 404 405 |
|
MDCPDPInitEmbedding
¶
MDCPDPInitEmbedding(embed_dim, linear_bias=True)
Bases: Module
Initial embedding for the MDCPDP environment Embed the following node features to the embedding space:
- locs: x, y coordinates of the nodes (depot, pickups and deliveries separately)
Note that pickups and deliveries are interleaved in the input.
Source code in rl4co/models/nn/env_embeddings/init.py
423 424 425 426 427 428 |
|
env_init_embedding
¶
Get environment initial embedding. The init embedding is used to initialize the general embedding of the problem nodes without any solution information. Consists of a linear layer that projects the node features to the embedding space.
Parameters:
-
env
–Environment or its name.
-
config
(dict
) –A dictionary of configuration options for the environment.
Source code in rl4co/models/nn/env_embeddings/init.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|