def __init__(self, ID=None, type_graph=None, name=None, Elements=None, plan_elm=None, Edges=None, Restrictions=None): if ID is None: ID = uuid4() if type_graph is None: type_graph = 'PlanElementGraph' if Elements is None: Elements = set() if Edges is None: Edges = set() if Restrictions is None: Restrictions = set() self.OrderingGraph = OrderingGraph() self.CausalLinkGraph = CausalLinkGraph() self.flaws = FlawLib() self.solved = False self.initial_dummy_step = None self.final_dummy_step = None if plan_elm is None: plan_elm = Element(ID=ID, typ=type_graph, name=name) super(PlanElementGraph, self).__init__(ID, type_graph, name, Elements, plan_elm, Edges, Restrictions)
def __init__(self, dummy_init_constructor, dummy_goal_constructor): self.ID = uuid4() self.OrderingGraph = OrderingGraph() self.CausalLinkGraph = CausalLinkGraph() # self.HierarchyGraph = HierarchyGraph() self.flaws = FlawLib() self.solved = False self.dummy = dummyTuple(dummy_init_constructor.instantiate(), dummy_goal_constructor.instantiate()) self.init = self.dummy.init.preconds self.goal = self.dummy.final.preconds self.steps = [self.dummy.init, self.dummy.final] # check if any existing steps are choices (instances of cndts of open conditions) self.dummy.final.update_choices(self) self.cndt_map = None self.threat_map = None # self.gstep_lib = ground_step_list # self.h_step_dict = dict() self.heuristic = float('inf') self.name = '' self.cost = 0 self.depth = 0
def swap_substeps(self, gsteps, GL, decomp_step): # base case - sub-steps are all height = 0 primitive_substeps = [arg for arg in decomp_step.ground_subplan.elements if type(arg) == Operator and arg.height == 0] composite_substeps = [arg for arg in decomp_step.ground_subplan.elements if type(arg) == Operator and arg.height > 0] if len(composite_substeps) == 0: prim_dict = {step: gsteps[step.stepnumber].instantiate() for step in primitive_substeps} self.create_composite_gstep(gsteps, decomp_step, prim_dict) return prim_dict else: # links and orderings in intermediate stage # change_dict = {step.root: gsteps[step.stepnumber].instantiate() for step in decomp_step.ground_subplan.Root_Graphs} change_dict = {} # order steps by height, lowest to highest. step_list = [step for step in decomp_step.ground_subplan.Step_Graphs] step_list.sort(key=lambda x: x.height) do_not_add_as_substep = [] for step in step_list: Args = [decompile(arg, decomp_step.ground_subplan) for arg in step.Args] preconds = [GLiteral(p.name, [decompile(arg, p) for arg in p.Args], p.truth, p.replaced_ID, (p.name, p.truth) not in GL.non_static_preds) for p in step.Preconditions] effects = [GLiteral(e.name, [decompile(arg, e) for arg in e.Args], e.truth, e.replaced_ID, (e.name, e.truth) not in GL.non_static_preds) for e in step.Effects] schema = str(step) step_copy = GStep(schema, Args, preconds, effects, step.stepnumber, step.height) step_copy.ID = step.root.ID st_t = gsteps[step.stepnumber].instantiate() step_copy.swap_setup(st_t.cndts, st_t.cndt_map, st_t.threats, st_t.threat_map, st_t.cntg_mental) # give no children if step.height > 0: init_step = st_t.dummy[0] init_step.schema = "begin:" + str(step) final_step = st_t.dummy[1] final_step.schema = "finish:" + str(step) step_copy.dummy = dummyTuple(init_step, final_step) # step_copy.sub_steps = [] children = decomp_step.ground_subplan.DecompGraph.getNeighbors(step.root) step_copy.sub_steps = [change_dict[child] for child in children if child.typ != 'step-s'] do_not_add_as_substep.extend(step_copy.sub_steps) step_copy.sub_orderings = OrderingGraph() step_copy.sub_links = CausalLinkGraph() change_dict[step.root] = step_copy # self.sub_steps.append(step) self.create_composite_gstep(gsteps, decomp_step, change_dict, do_not_add_as_substep) return change_dict
def Actions_2_Plan(cls, Actions, h): # Used by Plannify if not checkHeight(Actions, h): return None elements = set().union(*[A.elements for A in Actions]) edges = set().union(*[A.edges for A in Actions]) Plan = cls(name='Action_2_Plan', Elements=elements, Edges=edges) for edge in Plan.edges: if edge.label == 'effect-of': elm = Plan.getElementById(edge.sink.ID) elm.replaced_ID = edge.sink.replaced_ID Plan.OrderingGraph = OrderingGraph() Plan.CausalLinkGraph = CausalLinkGraph() # Plan.Steps = [A.root for A in Actions] return Plan
def __init__(self, operator, args, preconditions, effects, stepnum, height): # READ-ONLY ATTRIBUTES # # schema refers to the name of the operator self.schema = operator # Args are Argument or Actor "Element" types self.Args = args # ID used as "instance ID" self.ID = uuid4() # preconds is a list of GCond self.preconds = preconditions self.effects = effects # stepnum is the ground step constructor type self.stepnum = stepnum self.stepnumber = stepnum # height is 0 when primitive self.height = height if height > 0: self.sub_steps = [] self.sub_orderings = OrderingGraph() self.sub_links = CausalLinkGraph() self.dummy = dummyTuple(None, None) # depth starts at 0 and takes on value during planning self.depth = 0 self.cndts = None self.cndt_map = None self.threat_map = None self.threats = None self.cntg_mental = None self.instantiable = True # INSTANCE ATTRIBUTES # # risks are number of threat instances self.risks = list() self.choices = list() # choices are instances of cndt antecedents self.choice_map = dict() # self.num_choices = 0 # open preconditions which need causal link self.open_preconds = list(self.preconds)