def _time_advance_function(self, state: StationState) -> Time: """Obtains the time of the next processed entity.""" if state["parts"] < 1: state["remaining_time"] = Time(-1) else: state["remaining_time"] = Time(self._processing_time.evaluate()) return state["remaining_time"]
def test_validation(self): assembly_line = AssemblyLine([1, 2]) experiment = DiscreteEventExperiment(assembly_line) experiment.simulation_control.start(stop_time=Time(7)) experiment.simulation_control.wait() print(experiment.simulation_report.generate_report())
def decrease_time(self, time: Time) -> Time: """Decreases the time of the scheduled model. Args: time (int): Time variation. """ self._time = max((self._time - time), Time(0)) return self._time
def _internal_state_transition_function(self, state: ModelState) -> ModelState: state["p"] = max(state["p"] - 1, 0) if state["p"] < 1: state["s"] = Time(-1) else: state["s"] = 2 self.schedule(self.get_time()) return state
def schedule(self, model: DiscreteEventModel, time: Time): """Schedule an event at the specified time. Args: model (DiscreteEventModel): DiscreteEventModel with an autonomous event scheduled time (Time): Time to execute an autonomous event """ if time >= 0 and time != Time('inf'): sm = ScheduledModel(model, time) heapq.heappush(self._future_event_list, sm)
def _external_state_transition_function(self, state: ModelState, inputs: ModelInput, event_time: Time) -> ModelState: values = inputs.values() state["s"] = state["s"] - event_time for part in values: if state["p"] > 0: state["p"] = state["p"] + part elif state["p"] == 0: state["p"] = part state["s"] = 2 self.schedule(Time(2)) return state
def __init__( self, dynamic_system: DiscreteEventDynamicSystem, pieces: GeneratorState, interarrival_time: Expression, ): """Args: dynamic_system(DiscreteEventDynamicSystem): factory where stations belongs. pieces(GeneratorState): number of pieces to create when there is an arrival. interarrival_time(Expression): interarrival time of pieces. """ super().__init__(dynamic_system, state=pieces) self.schedule(Time(0)) self._interarrival_time = interarrival_time
def compute_next_state( self, inputs: DynamicSystemInput = None, time: Time = Time(0) ): """Compute the next state of the dynamic system Args: inputs (DynamicSystemInput): Input for the dynamic system. time (Time): Time of the event. """ if ( time - self._last_event_time - self.get_time_of_next_event() == 0 ): # Time to change the output out = self.compute_output() if out: self._report_generator.add_output(out, time) self._dynamic_system.state_transition(inputs, time - self._last_event_time) self._last_event_time = time self._is_output_up_to_update = False
def _confluent_state_transition_function( self, state: ModelState, inputs: ModelInput ) -> ModelState: """ .. math:: \delta_{con}(s,x) Implements the confluent state transition function delta. The confluent state transition executes an external transition function at the time of an autonomous event. .. math:: \delta_{con} \; : \; S \; x \; X \longrightarrow S Args: state (ModelState): Current state of the model. inputs (ModelInput): Input trajectory x. """ new_state = self._internal_state_transition_function(state) return self._external_state_transition_function( new_state, inputs, Time(0) ) # 0 because is equal to (e = ta(s)) ½ ta(s)
def process(self, inputs: List[int]): i = 0 while True: print("------------------") print("time -> " + str(i)) if inputs[int(i)] is not None: print("Inserting " + str(inputs[int(i)]) + " part(s)") print("output -> " + str(self.get_output())) print("--") r_input = None if inputs[int(i)]: r_input = {self.press: inputs[int(i)]} if i < 1: self.state_transition(r_input, Time(0)) else: self.state_transition(r_input, self.get_time_of_next_events()) print("--") print(self._scheduler) if self.get_time_of_next_events() == -1: break i = i + self.get_time_of_next_events() return i
def _time_advance_function(self, state: int) -> Time: """Prevents to execute an autonomous event""" return Time(-1)
def _time_advance_function(self, state: GeneratorState) -> Time: """Calculates the time of the creation of next part""" if isinstance(state, list): return self._interarrival_time.evaluate() if len(state) > 0 else Time(-1) return self._interarrival_time.evaluate()
def _time_advance_function(self, state: bool) -> Time: return Time(1)
def run_generations(self, generations: int = 10): for i in range(generations): self.get_output() self.state_transition(event_time=Time(1))
def _time_advance_function(self, state: List[int]) -> Time: return Time(1) if len(state) > 0 else Time(-1)
def get_time(self) -> Time: """Gets the time of the next autonomous event.""" try: return self._time_advance_function(self.get_state()) except AttributeError: return Time(0)
def _time_advance_function(self, state: ModelState) -> Time: return Time(1)
def get_time_of_next_event(self) -> Time: """Gets the time of the next event""" if len(self._future_event_list) > 0: return self._future_event_list[0].get_time() return Time(-1)
def init(self): """Initializes the simulator properties""" super(DiscreteEventSimulationEngine, self).init() self._last_event_time = Time(0)
def _time_advance_function(self, state: Dict[str, bool]) -> Time: return Time(1)
def __init__(self, dynamic_system: DiscreteEventDynamicSystem, pieces: List[int]): super().__init__(dynamic_system, name="Generator", state=pieces) self.schedule(Time(0))