diff options
author | kanzure <kanzure@gmail.com> | 2009-09-26 14:55:44 -0500 |
---|---|---|
committer | kanzure <kanzure@gmail.com> | 2009-09-26 14:55:44 -0500 |
commit | e6ce40f4b99560f0b65d9889c0c5b5cecaf85f61 (patch) | |
tree | 348c3b92be41e7a9fc18d13f917c3b4d9d255590 | |
parent | 7dfe4e81520e111155a0a7d1cab71ddbaff44615 (diff) | |
download | skdb-e6ce40f4b99560f0b65d9889c0c5b5cecaf85f61.tar.gz skdb-e6ce40f4b99560f0b65d9889c0c5b5cecaf85f61.zip |
make it optional to build an oven if you can allocate an oven
-rw-r--r-- | doc/proposals/action.py | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/doc/proposals/action.py b/doc/proposals/action.py index 48b7d04..bd8fbb1 100644 --- a/doc/proposals/action.py +++ b/doc/proposals/action.py @@ -14,6 +14,8 @@ class Agent: print "Agent.insert: pretending to look at the surface" print "Add the %s into the %s" % (object, into) return + def do(self, method=None): + method() class Plan(tinytree.Tree): pass @@ -34,14 +36,6 @@ class Operation(Node): #meanwhile somewhere in the pie package.. class Pie(Part, Plan): #or maybe Part should inherit from Plan? - #def build(self, pie_name=None): - #step 0. make the crust and slice the apples - #step 1. affix pan to a surface - #step 2. affix crust to the pan (don't do this in midair) #or it should be made in the pan - #step 3. insert sliced apples into crust in the pan on the surface - #step 4. detach the pan from the surface - #step 5. bake the pan (and the food inside) into a mouth watering apple pie - def build(self, pie_name=None): if pie_name is not None: #come up with some parameters by parsing pie_name @@ -51,57 +45,89 @@ class Pie(Part, Plan): #or maybe Part should inherit from Plan? #parameters were set in the __init__ or later pass - #step 0. make the crust and slice the apples. + #make the crust and slice the apples. crust = self.crust apples = self.apples crust.build() apples.build() - #allocate a surface + #build a new surface some_surface = Surface() some_surface.build() - #TODO: a new surface is not necessary if you have a surface already - #but it's possible that other recipes (say a biology lab protocol) will require a freshly sterilized and allocated surface #sterilize the surface (or should we assume all allocated items are sterilized?) - sterilize = Operation("sterilize", object=some_surface) - sterilized = Plan(objects=[some_surface], connector=sterilize) - internal_steralize(some_surface) #pretend to do it + sterilize_surface_op = Operation(action="sterilize", object=some_surface) + sterilized_surface = Plan(objects=[some_surface], connector=sterilize_surface_op) + + #a new surface is not necessary if you can allocate one + def autofalse(): + return False + get_a_surface = Operation(action="allocate", object=some_surface, conditional=autofalse) #not sure how to alloc :( + some_surface = Plan(connector=get_a_surface, substitutes=[sterilized_surface]) + #if get_a_surface's conditional == False, some_surface will just secretly point to sterilized_surface (a fresh build) - #allocate a pan + #build a new pan pan = CookingPan() pan.build() - #sterilize the pan? + #sterilize the pan + sterilize_pan_op = Operation(action="sterilize", object=pan) + sterilized_pan = Plan(objects=[pan], connector=sterilize_pan_op) + + #a new pan is not necessary if you can allocate one + get_a_pan = Operation(action="allocate", object=pan, conditional=autofalse) + some_pan = Plan(connector=get_a_pan, substitutes=[sterilized_pan]) + #if get_a_pan's conditional == False, some_plan will just secretly point to sterilized_pan #affix pan to the surface - affix_pan_op = Operation("affix", object=pan, _to=sterilized) - affixed_pan = Plan(objects=[pan, sterilized], connector=affix_pan_op) + affix_pan_op = Operation(action="affix", object=sterilized_pan, _to=sterilized_surface) + affixed_pan = Plan(objects=[sterilized_pan, sterilized_surface], connector=affix_pan_op) #a new pan is not necessary if you have the crust in one already def check_for_pan(crust): - if crust.is_in(CookingPan): #er, how would this be done? + if crust.is_in(CookingPan): #how? return False else: return True the_conditional = functools.partial(check_for_pan, crust=crust) - pan_the_crust = ConditionalOperation("insert", object=crust, into=affixed_pan, conditional=the_conditional) - panned_crust = Plan(objects=[affixed_pan, crust], connector=pan_the_crust) + pan_the_crust = Operation(action="insert", object=crust, into=affixed_pan, conditional=the_conditional) + panned_crust = Plan(objects=[affixed_pan, crust], connector=pan_the_crust, substitutes=[crust]) #if the conditional is not met, the action will not be executed, however tree traversal can still occur - - #affix crust to the pan - affix = Operation("affix", object=crust, _to=affixed_pan) - affixed_crust = Plan(objects=[crust, affixed_pan], connector=affix) - - #TODO: apples may be in a container. make another ConditionalOperation + #substitutes=[crust] simply means that if the Operation doesn't execute, what to go try instead + #otherwise the "affixed pan" would be used when it's not needed, you already have a panned_crust apparently + + #if the apples are in a container, remove them from the container + def check_for_container(object): + if object.is_in(Container): #any ideas? + return True + return False + apples_in_container = functools.partial(check_for_container, object=apples) + remove_apples_op = Operation(action="remove_container", object=apples, conditional=apples_in_container) + removed_apples = Plan(objects=[apples], connector=remove_apples_op) #in this case the substitute is unambiguous (apples) + #slice the apples if they aren't sliced + def are_apples_sliced_checker(apples): + return apples.sliced #any better ideas? + are_apples_sliced = functools.partial(are_apples_sliced_checker, apples=removed_apples) + slice_apples_op = Operation(action="slice", object=removed_apples, conditional=are_apples_sliced) + sliced_apples = Plan(objects=[removed_apples], connector=slice_apples_op) #in this case the substitute is unambiguous (removed_apples) + #insert sliced apples into crust - insert = Operation("insert", object=apples, into=crust) - inserted = Plan(objects=[affixed_crust, apples], connector=insert) + insert = Operation(action="insert", object=removed_apples, into=panned_crust) + inserted = Plan(objects=[panned_crust, removed_apples], connector=insert) + + #build an oven + oven = Oven() + oven.build() + + #new oven not necessary if you can allocate one + get_an_oven = Operation(action="allocate", object=oven, conditional=autofalse) + some_oven = Plan(connector=get_an_oven, substitutes=[oven]) + #if get_an_oven's conditional == False, some_oven will just secretly point to oven - #bake the crust-and-apples into a mouth watering apple pie - bake = Operation("bake", object=inserted, temperature="450 celsius", time="2 hr") + #bake the crust-and-apples into a mouth watering apple pie via the oven + bake = Operation(action="bake", object=inserted, temperature="450 celsius", time="36 hr", device=some_oven) #final step: turn self into a plan for a baked pie - Plan.__init__(self, objects=[inserted], connector=bake) + Plan.__init__(self, objects=[inserted, some_oven], connector=bake) #you are now free to traverse this part and part plan |