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.state Namespace Reference

Classes

class  Beluga
 Container ship (Beluga) with current and outgoing jigs. More...
 
class  Jig
 Individual jig instance with type and status. More...
 
class  JigType
 Represents a type of jig with size properties. More...
 
class  ProblemState
 Complete state representation for the Beluga Challenge. More...
 
class  ProductionLine
 Factory production line with scheduled jigs. More...
 
class  Rack
 Storage rack with size constraints. More...
 

Functions

int extract_id (str name)
 Extract numeric ID from jig name string.
 
str get_name_from_id (int id)
 Generate jig name from numeric ID.
 
JigType|None get_type (str name)
 Get JigType instance from type name string.
 
ProblemState load_from_json (path)
 Load problem state from JSON file.
 

Function Documentation

◆ extract_id()

int rl.env.state.extract_id ( str name)

Extract numeric ID from jig name string.

Parameters
nameJig name in format "jigXXXX"
Returns
Integer ID (0-based indexing)
637def extract_id(name: str) -> int:
638 """!
639 @brief Extract numeric ID from jig name string
640 @param name Jig name in format "jigXXXX"
641 @return Integer ID (0-based indexing)
642 """
643 name = name.replace("jig", "")
644 return int(name) - 1
645

◆ get_name_from_id()

str rl.env.state.get_name_from_id ( int id)

Generate jig name from numeric ID.

Parameters
idInteger ID (0-based)
Returns
Jig name in format "jigXXXX"
646def get_name_from_id(id: int) -> str:
647 """!
648 @brief Generate jig name from numeric ID
649 @param id Integer ID (0-based)
650 @return Jig name in format "jigXXXX"
651 """
652 return "jig" + "0" * (4-len(str(id))) + str(id)
653
654

◆ get_type()

JigType | None rl.env.state.get_type ( str name)

Get JigType instance from type name string.

Parameters
nameType name (typeA, typeB, typeC, typeD, or typeE)
Returns
JigType instance with appropriate size properties, or None if unknown
655def get_type(name: str) -> JigType | None:
656 """!
657 @brief Get JigType instance from type name string
658 @param name Type name (typeA, typeB, typeC, typeD, or typeE)
659 @return JigType instance with appropriate size properties, or None if unknown
660 """
661 if name == "typeA":
662 return JigType("typeA", 4, 4)
663 elif name == "typeB":
664 return JigType("typeB", 8, 11)
665 elif name == "typeC":
666 return JigType("typeC", 9, 18)
667 elif name == "typeD":
668 return JigType("typeD", 18, 25)
669 elif name == "typeE":
670 return JigType("typeE", 32, 32)
671 return None
672

◆ load_from_json()

ProblemState rl.env.state.load_from_json ( path)

Load problem state from JSON file.

Parameters
pathPath to the JSON problem file
Returns
ProblemState instance loaded from the file

Parses the JSON problem definition and creates all necessary objects (jigs, belugas, racks, production lines, etc.)

673def load_from_json(path) -> ProblemState:
674 """!
675 @brief Load problem state from JSON file
676 @param path Path to the JSON problem file
677 @return ProblemState instance loaded from the file
678
679 Parses the JSON problem definition and creates all necessary
680 objects (jigs, belugas, racks, production lines, etc.)
681 """
682
683 data = open(path, "r")
684 dictionary = json.loads(data.read())
685 data.close()
686
687 jig_data = dictionary["jigs"]
688
689 jigs: list[Jig] = []
690 for jig_n, jig in jig_data.items():
691 jigs.append(Jig(get_type(jig["type"]), jig["empty"]))
692
693 beluga_data = dictionary["flights"]
694 belugas: list[Beluga] = []
695 for beluga in beluga_data:
696 incoming: list[int] = []
697 outgoing: list[JigType] = []
698 for entry in beluga["incoming"]:
699 incoming.append(extract_id(entry))
700 for entry in beluga["outgoing"]:
701 outgoing.append(get_type(entry))
702 belugas.append(Beluga(incoming, outgoing))
703
704 production_lines_data = dictionary["production_lines"]
705 production_lines: list[ProductionLine] = []
706 for production_line in production_lines_data:
707 schedule: list[int] = []
708 for entry in production_line["schedule"]:
709 schedule.append(extract_id(entry))
710 production_lines.append(ProductionLine(schedule))
711
712 racks_data = dictionary["racks"]
713 racks: list[Rack] = []
714 for rack in racks_data:
715 storage: list[int] = []
716 for entry in rack["jigs"]:
717 storage.append(extract_id(entry))
718 racks.append(Rack(rack["size"], storage))
719
720 hangars: list[Jig | None] = [None] * len(dictionary["hangars"])
721 trailers_beluga: list[Jig | None] = [None] * len(dictionary["trailers_beluga"])
722 trailers_factory: list[Jig | None] = [None] * len(dictionary["trailers_factory"])
723
724
725 return ProblemState(jigs, belugas, trailers_beluga, trailers_factory, racks, production_lines, hangars)