Load problem state from JSON 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)