def drop(self, action, sim, taken_inf): tank = list(filter(action.param["tank"], taken_inf))[0] if tank.is_full(): Event(sim, sim.now + 1, "haul") Action.abort(action, sim) tank.put_water(10) yield sim.wait(10)
def haul(event): if event.sim.get_status().rain: raise Manager.RetryLater() g = ActionsGraph(event.sim) b = Block(g, lambda x: isinstance(x, Aquifer)) b1 = Block(g, lambda x: isinstance(x, Well)) t = Action(g, "take", lambda x: isinstance(x, Aquifer), param={"well": lambda x: isinstance(x, Well)}, after=[b.id, b1.id], condition=lambda x: not x.get_status().rain, on_false=Aquifer.rain) f1 = Free(g, lambda x: isinstance(x, Well), after=[t.id]) b1 = Block(g, lambda x: isinstance(x, Tank) and not x.is_full(), sort_by=lambda x: x.full.level, after=[t.id]) t = Action(g, "drop", lambda x: isinstance(x, Aquifer), param={"tank": lambda x: isinstance(x, Tank)}, after=[b1.id]) f = Free(g, lambda x: isinstance(x, Aquifer), None, after=[t.id]) f1 = Free(g, lambda x: isinstance(x, Tank), None, after=[t.id, b1.id]) bh = Branch(g, after=[t.id], condition=lambda x: x.now < 5000) GenerateEvent(g, Event(sim, None, "haul"), after=[bh.id], branch=bh.id) return g
def __init__(self, sim, position, capacity): Performer.__init__(self, sim) Movable.__init__(self, position, sim) self.full = Container(sim, capacity) Event(sim, sim.now + 1000, "empty_tank" + str(self.id)) self.sim.manager.add_mapping("empty_tank" + str(self.id), self.empty_tank) self.add_mapping("empty", self.__do_empty__)
def ab(action, sim): assert (isinstance(sim, Simulation)) sim.logger.log("aborting " + str(action), type=sim.Logger.Type.WARNING) Event(sim, sim.now + 1, "new_task", param={"task": action.action_graph.task}) Action.abort(action, sim)
def empty_tank(self, event): g = ActionsGraph(event.sim) b = Block(g, self.id, sort_by=None) e = Action(g, "empty", self.id, after=[b.id], condition=lambda x: x.find_res_by_id(self.id, free=False). full.level != 0) Free(g, self.id, after=[e.id]) Event(sim, sim.now + 1000, "empty_tank" + str(self.id)) return g
def rain(action, sim): Event(sim, sim.now + 1, "haul") Action.abort(action, sim)
def __init__(self, sim, position): Performer.__init__(self, sim) Movable.__init__(self, position, sim) self.add_mapping("take", self.take) self.add_mapping("drop", self.drop) Event(sim, 10 + len(sim.all_res), "haul")
def change_of_whether(event): event.sim.modify_status().toggle_rain() Event(sim, sim.now + 59, "weather")
def __init__(self, sim): self.rain = False self.sim = sim sim.manager.add_mapping("weather", Status.change_of_whether) Event(sim, 50, "weather")
def run(self): for time in self.tasks.keys(): Event(self.sim, time, "new_task", param={"task": self.tasks[time]}) self.sim.get_status().monitor.due_tasks = len(self.tasks)
def add_future_task(self, time, task): self.tasks[time] = task Event(self.sim, time, "new_task", param={"task": self.tasks[time]})