FoPra Beluga Challenge - Reinforcement Learning v1.0
Deep Reinforcement Learning solution for the Beluga Challenge shipping container optimization problem using PPO and MCTS
rl.env.action Namespace Reference

Functions

bool load_beluga (state, int trailer_beluga, none)
 Load beluga from specific trailer.
 
bool unload_beluga (state)
 Unload beluga (no additional parameter besides state)
 
bool get_from_hangar (state, int hangar, int trailer_factory)
 Get jig from specific hangar to specific trailer.
 
bool deliver_to_hangar (state, int hangar, int trailer_factory)
 Deliver jig from specific trailer to specific hangar.
 
bool left_stack_rack (state, int rack, int trailer_id)
 Stack jig on rack from the left trailer (Beluga)
 
bool right_stack_rack (state, int rack, int trailer_id)
 Stack jig on rack from the right trailer (Factory)
 
bool left_unstack_rack (state, int rack, int trailer_id)
 Unstack jig from rack to the left trailer (Beluga)
 
bool right_unstack_rack (state, int rack, int trailer_id)
 Unstack jig from rack to the right trailer (Factory)
 

Function Documentation

◆ deliver_to_hangar()

bool rl.env.action.deliver_to_hangar ( state,
int hangar,
int trailer_factory )

Deliver jig from specific trailer to specific hangar.

Parameters
stateCurrent problem state
hangarIndex of the hangar to deliver to
trailer_factoryIndex of the factory trailer to take jig from
Returns
True if delivery was successful, False otherwise
121def deliver_to_hangar(state, hangar: int, trailer_factory: int) -> bool:
122 """!
123 @brief Deliver jig from specific trailer to specific hangar
124 @param state Current problem state
125 @param hangar Index of the hangar to deliver to
126 @param trailer_factory Index of the factory trailer to take jig from
127 @return True if delivery was successful, False otherwise
128 """
129 if hangar >= len(state.hangars) or trailer_factory >= len(state.trailers_factory):
130 return False
131
132 if state.hangars[hangar] is not None or state.trailers_factory[trailer_factory] is None:
133 return False
134
135 jig_id = state.trailers_factory[trailer_factory]
136 if state.jigs[jig_id].empty:
137 return False
138
139 # Find corresponding production line for the jig
140 production_line_idx = None
141 for i, pl in enumerate(state.production_lines):
142 if pl.scheduled_jigs and jig_id == pl.scheduled_jigs[0]:
143 production_line_idx = i
144 break
145
146 if production_line_idx is None:
147 return False
148
149 # Effects: Remove jig from production line, deliver to hangar, and clear trailer slot
150 state.production_lines[production_line_idx].scheduled_jigs.pop(0)
151 state.hangars[hangar] = jig_id
152 state.jigs[jig_id].empty = True
153 state.trailers_factory[trailer_factory] = None
154
155 if not state.production_lines[production_line_idx].scheduled_jigs:
156 state.production_lines.pop(production_line_idx)
157 return True
158
159
160# 4

◆ get_from_hangar()

bool rl.env.action.get_from_hangar ( state,
int hangar,
int trailer_factory )

Get jig from specific hangar to specific trailer.

Parameters
stateCurrent problem state
hangarIndex of the hangar to retrieve from
trailer_factoryIndex of the factory trailer to place jig into
Returns
True if retrieval was successful, False otherwise
96def get_from_hangar(state, hangar: int, trailer_factory: int) -> bool:
97 """!
98 @brief Get jig from specific hangar to specific trailer
99 @param state Current problem state
100 @param hangar Index of the hangar to retrieve from
101 @param trailer_factory Index of the factory trailer to place jig into
102 @return True if retrieval was successful, False otherwise
103 """
104 if hangar >= len(state.hangars) or trailer_factory >= len(state.trailers_factory):
105 return False
106
107 if state.hangars[hangar] is None or state.trailers_factory[trailer_factory] is not None:
108 return False
109
110 jig_id = state.hangars[hangar]
111 if not state.jigs[jig_id].empty:
112 return False
113
114 # Effects: Move jig from hangar to factory trailer
115 state.trailers_factory[trailer_factory] = jig_id
116 state.hangars[hangar] = None
117 return True
118
119
120# 3

◆ left_stack_rack()

bool rl.env.action.left_stack_rack ( state,
int rack,
int trailer_id )

Stack jig on rack from the left trailer (Beluga)

Parameters
stateCurrent problem state
rackIndex of the rack to stack onto
trailer_idIndex of the left (Beluga) trailer to take jig from
Returns
True if stacking was successful, False otherwise
161def left_stack_rack(state, rack: int, trailer_id: int) -> bool:
162 """!
163 @brief Stack jig on rack from the left trailer (Beluga)
164 @param state Current problem state
165 @param rack Index of the rack to stack onto
166 @param trailer_id Index of the left (Beluga) trailer to take jig from
167 @return True if stacking was successful, False otherwise
168 """
169 rack = int(rack)
170 if rack >= len(state.racks):
171 return False
172
173 trailers = state.trailers_beluga
174 if trailer_id >= len(trailers) or trailers[trailer_id] is None:
175 return False
176
177 jig_id = trailers[trailer_id]
178 jig = state.jigs[jig_id]
179 jig_size = jig.jig_type.size_empty if jig.empty else jig.jig_type.size_loaded
180
181 rack_obj = state.racks[rack]
182 if rack_obj.get_free_space(state.jigs) < jig_size:
183 return False
184
185 # Effects: Clear trailer slot and stack jig onto the rack
186 trailers[trailer_id] = None
187 rack_obj.current_jigs.insert(0, jig_id)
188 return True
189
190
191# 5

◆ left_unstack_rack()

bool rl.env.action.left_unstack_rack ( state,
int rack,
int trailer_id )

Unstack jig from rack to the left trailer (Beluga)

Parameters
stateCurrent problem state
rackIndex of the rack to unstack from
trailer_idIndex of the left (Beluga) trailer to place jig into
Returns
True if unstacking was successful, False otherwise
223def left_unstack_rack(state, rack: int, trailer_id: int) -> bool:
224 """!
225 @brief Unstack jig from rack to the left trailer (Beluga)
226 @param state Current problem state
227 @param rack Index of the rack to unstack from
228 @param trailer_id Index of the left (Beluga) trailer to place jig into
229 @return True if unstacking was successful, False otherwise
230 """
231 rack = int(rack)
232 if rack >= len(state.racks):
233 return False
234
235 trailers = state.trailers_beluga
236 if trailer_id >= len(trailers) or trailers[trailer_id] is not None or not state.racks[rack].current_jigs:
237 return False
238
239 # Effects: Remove jig from rack and place it into the trailer
240 trailers[trailer_id] = state.racks[rack].current_jigs.pop(0)
241 return True
242
243
244# 7

◆ load_beluga()

bool rl.env.action.load_beluga ( state,
int trailer_beluga,
none )

Load beluga from specific trailer.

Parameters
stateCurrent problem state
trailer_belugaIndex of the beluga trailer to load from
noneUnused parameter for API consistency
Returns
True if loading was successful, False otherwise
7def load_beluga(state, trailer_beluga: int, none) -> bool:
8 """!
9 @brief Load beluga from specific trailer
10 @param state Current problem state
11 @param trailer_beluga Index of the beluga trailer to load from
12 @param none Unused parameter for API consistency
13 @return True if loading was successful, False otherwise
14 """
15 jig_id = state.trailers_beluga[trailer_beluga]
16
17 # Preconditions
18 if len(state.belugas) == 0:
19 return False
20
21 beluga = state.belugas[0]
22
23 if jig_id is None: # Trailer is empty
24 return False
25
26 if not state.jigs[jig_id].empty: # Jig must be empty
27 return False
28
29 if not beluga.outgoing: # Beluga must have outgoing types
30 return False
31
32 if len(beluga.current_jigs) != 0: # Beluga must not have incoming jigs
33 return False
34
35 if state.jigs[jig_id].jig_type != beluga.outgoing[0]:
36 return False
37
38 # Effects: Remove outgoing type and clear trailer slot
39
40 # Case: only one jig left in beluga, gets unloaded and then new beluga is fetched
41 if len(beluga.outgoing) == 1:
42 beluga.outgoing.pop(0)
43 state.trailers_beluga[trailer_beluga] = None
44 state.beluga_complete()
45 return True
46
47
48 beluga.outgoing.pop(0)
49 state.trailers_beluga[trailer_beluga] = None
50 return True
51
52
53# 1

◆ right_stack_rack()

bool rl.env.action.right_stack_rack ( state,
int rack,
int trailer_id )

Stack jig on rack from the right trailer (Factory)

Parameters
stateCurrent problem state
rackIndex of the rack to stack onto
trailer_idIndex of the right (Factory) trailer to take jig from
Returns
True if stacking was successful, False otherwise
192def right_stack_rack(state, rack: int, trailer_id: int) -> bool:
193 """!
194 @brief Stack jig on rack from the right trailer (Factory)
195 @param state Current problem state
196 @param rack Index of the rack to stack onto
197 @param trailer_id Index of the right (Factory) trailer to take jig from
198 @return True if stacking was successful, False otherwise
199 """
200 rack = int(rack)
201 if rack >= len(state.racks):
202 return False
203
204 trailers = state.trailers_factory
205 if trailer_id >= len(trailers) or trailers[trailer_id] is None:
206 return False
207
208 jig_id = trailers[trailer_id]
209 jig = state.jigs[jig_id]
210 jig_size = jig.jig_type.size_empty if jig.empty else jig.jig_type.size_loaded
211
212 rack_obj = state.racks[rack]
213 if rack_obj.get_free_space(state.jigs) < jig_size:
214 return False
215
216 # Effects: Clear trailer slot and stack jig onto the rack
217 trailers[trailer_id] = None
218 rack_obj.current_jigs.append(jig_id)
219 return True
220
221
222# 6

◆ right_unstack_rack()

bool rl.env.action.right_unstack_rack ( state,
int rack,
int trailer_id )

Unstack jig from rack to the right trailer (Factory)

Parameters
stateCurrent problem state
rackIndex of the rack to unstack from
trailer_idIndex of the right (Factory) trailer to place jig into
Returns
True if unstacking was successful, False otherwise
245def right_unstack_rack(state, rack: int, trailer_id: int) -> bool:
246 """!
247 @brief Unstack jig from rack to the right trailer (Factory)
248 @param state Current problem state
249 @param rack Index of the rack to unstack from
250 @param trailer_id Index of the right (Factory) trailer to place jig into
251 @return True if unstacking was successful, False otherwise
252 """
253 rack = int(rack)
254 if rack >= len(state.racks):
255 return False
256
257 trailers = state.trailers_factory
258 if trailer_id >= len(trailers) or trailers[trailer_id] is not None or not state.racks[rack].current_jigs:
259 return False
260
261 # Effects: Remove jig from rack and place it into the trailer
262 trailers[trailer_id] = state.racks[rack].current_jigs.pop(-1)
263 return True

◆ unload_beluga()

bool rl.env.action.unload_beluga ( state)

Unload beluga (no additional parameter besides state)

Parameters
stateCurrent problem state
Returns
True if unloading was successful, False otherwise
54def unload_beluga(state) -> bool:
55 """!
56 @brief Unload beluga (no additional parameter besides state)
57 @param state Current problem state
58 @return True if unloading was successful, False otherwise
59 """
60 # Find the first empty trailer slot
61 trailer_beluga = None
62 for i, trailer in enumerate(state.trailers_beluga):
63 if trailer is None:
64 trailer_beluga = i
65 break
66
67 if trailer_beluga is None or not state.belugas:
68 return False
69
70 beluga = state.belugas[0]
71 if not beluga.current_jigs:
72 return False
73
74 if len(state.belugas[0].current_jigs) == 1:
75 state.belugas_unloaded += 1
76 state.trailers_beluga[trailer_beluga] = beluga.current_jigs.pop(-1)
77
78 if not beluga.outgoing:
79 state.beluga_complete()
80
81 return True
82
83 # Effects: Unload the last jig from current_jigs into the trailer slot
84 state.trailers_beluga[trailer_beluga] = beluga.current_jigs.pop(-1)
85
86
87
88 # if not beluga.current_jigs and not beluga.outgoing:
89 # # Effect: Remove beluga from the list if fully processed
90 # state.belugas.pop(0)
91
92 return True
93
94
95# 2