def run(self, timeout=30, sessionName=None, schedule=schedule, raise_=False): if not sessionName: sessionName = self.__class__.__name__ self.problem() self_methods = [ getattr(self, m) for m in dir(self) if callable(getattr(self, m)) and hasattr(getattr(self, m), "_planned") ] model_methods = [] methods_scanned = set() for obj in self.objectList: if not obj.__class__.__name__ in methods_scanned: methods_scanned.add(obj.__class__.__name__) for m in dir(obj): if callable(getattr(obj, m)) and hasattr( getattr(obj, m), "_planned"): model_methods.append(getattr(obj, m)) try: self.plan = schedule(methods=self_methods + list(model_methods), space=list(self.__dict__.values()) + self.objectList, goal=lambda: (self.goal()), timeout=timeout, sessionName=sessionName #exit=self.exit ) except SchedulingError: if raise_: raise SchedulingError("Can't solve") else: pass
def run(self, timeout=30): self.problem() try: self.plan = schedule(methods=[ getattr(self, m) for m in dir(self) if callable(getattr(self, m)) and hasattr(getattr(self, m), "_planned") ], space=list(self.__dict__.values()) + self.objectList, goal=lambda: (self.goal()), timeout=timeout #exit=self.exit ) except SchedulingError: pass
S.at = p2 def toright(person1: Person, person2: Person, boat: Boat, where: Positions, world: World): assert person1.at == boat.at assert person2.at == boat.at person1.at = where person2.at = where boat.at = where world.cost = world.cost + max(person1.time, person2.time) return f"{person1.name} and {person2.name} moved to the Right" def toleft(person1: Person, boat: Boat, where: Positions, world: World): assert person1.at == boat.at person1.at = where boat.at = where world.cost = world.cost + person1.time return f"{person1.name} moved to the Left" print('\n'.join(x() for x in schedule( methods=[toright, toleft], space=[A, B, C, D, S, W, p1, p1], goal=lambda: (A.at == p1 and B.at == p1 and C.at == p1 and D.at == p1))))
assert jug.Water == world.onetest world.one = True return 'got one Water' def PoorCase1(jug1: Jug, jug2: Jug): assert jug1.Cap > jug2.Cap assert jug1.Water > 0 assert jug2.Water < jug2.Cap assert jug1.Water <= (jug2.Cap - jug2.Water) jug2.Water += jug1.Water jug1.Water = 0 return f'pour {jug1.name} to {jug2.name}' def PoorCase2(jug1: Jug, jug2: Jug): assert jug1.Cap > jug2.Cap assert jug1.Water > 0 assert jug2.Water < jug2.Cap assert jug1.Water > (jug2.Cap - jug2.Water) jug2.Water = jug2.Cap jug1.Water -= (jug2.Cap - jug2.Water) return f'pour {jug1.name} to {jug2.name}' print('\n'.join( x() for x in schedule(methods=[FillJug, EmptyJug, Check, PoorCase1, PoorCase2], space=[A, B, C, D, W], goal=lambda: W.one == True)))