// Creates a clone of the plan. (orderings, and Links are Read-only, so only their host containers are replaced) public Object Clone() { var newSteps = new List <IPlanStep>(); foreach (var step in steps) { // need clone because these have fulfilled conditions that are mutable. newSteps.Add(step.Clone() as IPlanStep); } var newInitialStep = initialStep.Clone() as IPlanStep; // need clone of goal step because this as fulfillable conditions var newGoalStep = goalStep.Clone() as IPlanStep; // Assuming for now that members of the ordering graph are never mutated. If they are, then a clone will keep references to mutated members var newOrderings = orderings.Clone() as Graph <IPlanStep>; // Causal Links are containers whose members are not mutated. List <CausalLink <IPlanStep> > newLinks = new List <CausalLink <IPlanStep> >(); foreach (var cl in causalLinks) { newLinks.Add(cl as CausalLink <IPlanStep>); } // Inherit all flaws, must clone very flaw var flawList = flaws.Clone() as Flawque; //return new Plan(newSteps, newInitial, newGoal, newInitialStep, newGoalStep, newOrderings, newLinks, flawList); return(new Plan(newSteps, Initial, Goal, newInitialStep, newGoalStep, newOrderings, newLinks, flawList)); }
// Creates a clone of the plan. (orderings, and Links are Read-only, so only their host containers are replaced) public Object Clone() { List <IPlanStep> newSteps = new List <IPlanStep>(); foreach (var step in steps) { // need clone because these have fulfilled conditions that are mutable. newSteps.Add(step.Clone() as IPlanStep); } // these are static read only things //IState newInitial = initial.Clone() as IState; //IState newGoal = goal.Clone() as IState; IPlanStep newInitialStep = initialStep.Clone() as IPlanStep; // need clone of goal step because this as fulfillable conditions IPlanStep newGoalStep = goalStep.Clone() as IPlanStep; // Assuming for now that members of the ordering graph are never mutated. If they are, then a clone will keep references to mutated members Graph <IPlanStep> newOrderings = orderings.Clone() as Graph <IPlanStep>; // Causal Links are containers whose members are not mutated. List <CausalLink <IPlanStep> > newLinks = new List <CausalLink <IPlanStep> >(); foreach (var cl in causalLinks) { newLinks.Add(cl as CausalLink <IPlanStep>); //newLinks.Add(cl.Clone() as CausalLink<IPlanStep>); } // Inherit all flaws, must clone very flaw Flawque flawList = flaws.Clone() as Flawque; //return new Plan(newSteps, newInitial, newGoal, newInitialStep, newGoalStep, newOrderings, newLinks, flawList); var p = new Plan(newSteps, Initial, Goal, newInitialStep, newGoalStep, newOrderings, newLinks, flawList) { Hdepth = hdepth, Decomps = decomps }; p.id = id + p.id; return(p); }