Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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__)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 def rain(action, sim):
     Event(sim, sim.now + 1, "haul")
     Action.abort(action, sim)
Ejemplo n.º 7
0
 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")
Ejemplo n.º 8
0
 def change_of_whether(event):
     event.sim.modify_status().toggle_rain()
     Event(sim, sim.now + 59, "weather")
Ejemplo n.º 9
0
 def __init__(self, sim):
     self.rain = False
     self.sim = sim
     sim.manager.add_mapping("weather", Status.change_of_whether)
     Event(sim, 50, "weather")
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
 def add_future_task(self, time, task):
     self.tasks[time] = task
     Event(self.sim, time, "new_task", param={"task": self.tasks[time]})