Example #1
0
    def __init__(self,
                 event_buffer: EventBuffer,
                 topology: Optional[str],
                 start_tick: int,
                 max_tick: int,
                 snapshot_resolution: int,
                 max_snapshots: Optional[int],
                 additional_options: dict = None):
        super().__init__("cim", event_buffer, topology, start_tick, max_tick,
                         snapshot_resolution, max_snapshots,
                         additional_options)

        # Update self._config_path with current file path.
        self.update_config_root_path(__file__)

        # Load data from wrapper.
        self._data_cntr: CimDataContainerWrapper = CimDataContainerWrapper(
            self._config_path, max_tick, self._topology)

        # Create a copy of config object to expose to others, and not affect generator.
        self._config = {}
        config_path = os.path.join(self._config_path, "config.yml")
        if os.path.exists(config_path):
            with open(config_path) as fp:
                self._config = safe_load(fp)

        self._vessels = []
        self._ports = []
        self._frame: Optional[FrameBase] = None
        self._full_on_ports: Optional[MatrixAttributeAccessor] = None
        self._full_on_vessels: Optional[MatrixAttributeAccessor] = None
        self._vessel_plans: Optional[MatrixAttributeAccessor] = None
        self._port_orders_exporter = PortOrderExporter(
            "enable-dump-snapshot" in additional_options)

        self._load_cost_factor: float = self._data_cntr.load_cost_factor
        self._dsch_cost_factor: float = self._data_cntr.dsch_cost_factor

        # Used to collect total cost to avoid to much snapshot querying.
        self._total_operate_num: float = 0

        self._init_frame()

        # Snapshot list should be initialized after frame.
        self._snapshots = self._frame.snapshots

        self._register_events()

        # As we already unpack the route to the max tick, we can insert all departure events at the beginning.
        self._load_departure_events()

        # Since there is no Arrival Event at the very beginning, init the vessel states maunally.
        self._init_vessel_plans()

        self._stream_base_info()
Example #2
0
    def __init__(self,
                 event_buffer: EventBuffer,
                 topology: str,
                 start_tick: int,
                 max_tick: int,
                 snapshot_resolution: int,
                 max_snapshots: int,
                 additional_options: dict = None):
        super().__init__("cim", event_buffer, topology, start_tick, max_tick,
                         snapshot_resolution, max_snapshots,
                         additional_options)

        # Update self._config_path with current file path.
        self.update_config_root_path(__file__)

        config_path = os.path.join(self._config_path, "config.yml")

        # Load data from wrapper.
        self._data_cntr: CimDataContainerWrapper = CimDataContainerWrapper(
            config_path, max_tick, self._topology)

        # Create a copy of config object to expose to others, and not affect generator.
        with open(config_path) as fp:
            self._config = safe_load(fp)

        self._vessels = []
        self._ports = []
        self._frame = None
        self._full_on_ports: MatrixAttributeAccessor = None
        self._full_on_vessels: MatrixAttributeAccessor = None
        self._vessel_plans: MatrixAttributeAccessor = None
        self._port_orders_exporter = PortOrderExporter(
            "enable-dump-snapshot" in additional_options)

        # Read transfer cost factors.
        transfer_cost_factors = self._config["transfer_cost_factors"]

        self._load_cost_factor: float = transfer_cost_factors["load"]
        self._dsch_cost_factor: float = transfer_cost_factors["dsch"]

        # Used to collect total cost to avoid to much snapshot querying.
        self._total_operate_num: float = 0

        self._init_frame()

        # Snapshot list should be initialized after frame.
        self._snapshots = self._frame.snapshots

        self._register_events()

        # As we already unpack the route to the max tick, we can insert all departure events at the beginning.
        self._load_departure_events()