public static List <IPlanStep> SubStepsFromJson(JsonArray substepjson) { var substeps = new List <IPlanStep>(); // each item is another list of form <intID, openCondition JsonObject predicates> foreach (JsonArray substepArray in substepjson) { var intID = int.Parse(substepArray[0].ToString()); var underlyingComposite = GroundActionFactory.GroundLibrary[intID]; IPlanStep plansubstep; if (underlyingComposite.Height == 0) { plansubstep = new PlanStep(underlyingComposite as IOperator); } else { plansubstep = new CompositePlanStep(underlyingComposite as IComposite); } var openConditions = new List <IPredicate>(); foreach (JsonObject openCondition in substepArray[1] as JsonArray) { var removeThis = PredicateFromJsonObject(openCondition); openConditions.Add(removeThis); } plansubstep.OpenConditions = openConditions; substeps.Add(plansubstep); } return(substeps); }
protected override bool DecideWhattoDo(GameTime gameTime, out int Action) { if (IsWaiting) { WaitTime -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (WaitTime > 0) { Action = 0; return(false);//note this is a return and so terminates the method } //else IsWaiting = false; WaitTime = 0; } //if was waiting and is no longer, or was never waiting... //CurrentTarget = NextTarget; if (stepToComplete.Completed) { //so get a new one! stepToComplete.End(); //just before binning the old one, call End in case it needs to signal back to AIBehaviour (like the results of a search) stepToComplete = CurrentBS.DecideWhatToDo(); // now fetch a new one. } stepToComplete.UsePlanStep(gameTime, this, out Action, out Vector2 NextTarget); // was an instruction to wait? otherwise, do the action outputted if (!IsWaiting) { //turn to face the next target Vector2 NextFacing = new Vector2(Math.Sign(NextTarget.X - TilePosition.X), Math.Sign(NextTarget.Y - TilePosition.Y)); if (NextFacing != Vector2.Zero) { FacingAddup = GetFacing(NextFacing); } if (Action > 0) { if (ActionIsMovementBased(Action)) { if (NextTarget == TilePosition) { Action = 0; return(false); } else {//target elsewhere, so a valid 'moving action' MovingToTilePosition = NextTarget; return(true); } } else {//target must be this tile or elsewhere, but we aren't moving!, since we are on the tile already! MovingToTilePosition = TilePosition; return(true); } } return(false); } //else IS waiting return(false); }
public static List <Tuple <IPlanStep, IPlanStep> > SubOrderingsFromJson(JsonArray suborderingsjson) { var tupleList = new List <Tuple <IPlanStep, IPlanStep> >(); foreach (var jsonTuple in suborderingsjson) { var tupleItem = IntTupleFromJsonArray(jsonTuple as JsonArray); IPlanStep head; if (tupleItem.First.Height > 0) { head = new CompositePlanStep(tupleItem.First as IComposite); } else { head = new PlanStep(tupleItem.First as IOperator); } IPlanStep tail; if (tupleItem.Second.Height > 0) { tail = new CompositePlanStep(tupleItem.Second as IComposite); } else { tail = new PlanStep(tupleItem.Second as IOperator); } var modTuple = new Tuple <IPlanStep, IPlanStep>(head, tail); tupleList.Add(modTuple); } return(tupleList); }
public static List <CausalLink <IPlanStep> > CausalLinksFromJsonArray(JsonArray jsoncausallinkslist) { var clinks = new List <CausalLink <IPlanStep> >(); foreach (var jsonlink in jsoncausallinkslist) { var clink = CausalLinkFromJsonArray(jsonlink as JsonArray); IPlanStep head; if (clink.Head.Height > 0) { head = new CompositePlanStep(clink.Head as IComposite); } else { head = new PlanStep(clink.Head as IOperator); } IPlanStep tail; if (clink.Tail.Height > 0) { tail = new CompositePlanStep(clink.Tail as IComposite); } else { tail = new PlanStep(clink.Tail as IOperator); } var newLink = new CausalLink <IPlanStep>(clink.Predicate, head, tail); clinks.Add(newLink); } return(clinks); }
// used for initialization public TimelineDecomposition(IOperator core, List <IPredicate> literals, List <Tuple <IPlanStep, IPlanStep> > fcntgs, List <Tuple <CamPlanStep, CamPlanStep> > dcntgs, List <Tuple <string, Tuple <PlanStep, PlanStep> > > fconstraints, List <Tuple <string, Tuple <CamPlanStep, CamPlanStep> > > dconstraints, List <IPlanStep> substeps, List <CamPlanStep> camSteps, List <Tuple <IPlanStep, IPlanStep> > suborderings, List <Tuple <CamPlanStep, CamPlanStep> > dOrderings, List <CausalLink <IPlanStep> > sublinks, List <CausalLink <CamPlanStep> > dLinks, Dictionary <string, PlanStep> fabulaStepVariableNameDictionary) : base(core, literals, substeps, suborderings, sublinks) { fabCntgs = fcntgs; discCntgs = dcntgs; fabConstraints = fconstraints; discourseSubSteps = camSteps; discConstraints = dconstraints; discOrderings = dOrderings; discLinks = dLinks; fabulaActionNameMap = fabulaStepVariableNameDictionary; // to be updated after grounding or adding connectives InitialCamAction = discourseSubSteps[0]; FinalCamAction = discourseSubSteps[discourseSubSteps.Count - 1]; // to beupdated after grounding regular actions InitialActionSeg = InitialCamAction.TargetDetails.ActionSegs[0]; FinalActionSeg = FinalCamAction.TargetDetails.ActionSegs[FinalCamAction.TargetDetails.ActionSegs.Count - 1]; // to be instantiated after grounding actions InitialAction = new PlanStep(); FinalAction = new PlanStep(); }
public static List <IPlanStep> ReadPlayerTrace(string directory, Domain domain, Problem problem) { var planTrace = new List <IPlanStep>(); string[] input = System.IO.File.ReadAllLines(directory); foreach (var line in input) { var opToken = PlayerTraceUtilities.CreateOperatorToken(line); var iopToken = PlayerTraceUtilities.AddPreconditionsAndEffects(opToken, domain); // make sure we don't accidentally use.... <_<, >_> opToken = null; var newStep = new PlanStep(); if (GroundActionFactory.GroundActions.Contains(iopToken)) { var opIndex = GroundActionFactory.GroundActions.IndexOf(iopToken); var existingOpToken = GroundActionFactory.GroundActions[opIndex]; newStep = new PlanStep(existingOpToken.Clone() as IOperator); } else { GroundActionFactory.InsertOperator(iopToken); newStep = new PlanStep(iopToken.Clone() as IOperator); } planTrace.Add(newStep); } return(planTrace); }
public static void AddCurrentPlan(this FabPegPart pp, PlanStep plan) { if (pp.Steps == null) { pp.Steps = new List <PlanStep>(); } pp.Steps.Add(plan); }
public void AddStep(IPlan plan) { foreach (var cndt in GetActions(plan.CurrentState as State)) { var planClone = plan.Clone() as IPlan; var newStep = new PlanStep(cndt.Clone() as IOperator); planClone.Insert(newStep); Insert(planClone); } }
public void AddStep(IPlan plan, OpenCondition oc) { foreach (var cndt in CacheMaps.GetCndts(oc.precondition)) { if (cndt == null) { continue; } var planClone = plan.Clone() as IPlan; planClone.ID += "a"; IPlanStep newStep; if (cndt.Height > 0) { //continue; var compCndt = cndt as Composite; newStep = new CompositePlanStep(compCndt.Clone() as Composite) { Depth = oc.step.Depth }; //planClone.Hdepth += compCndt.SubSteps.Count; // this is done now in beginning of Insert Decomp } else { newStep = new PlanStep(cndt.Clone() as IOperator) { Depth = oc.step.Depth }; } // For debugging //planClone.ID += "(" + GroundActionFactory.GroundActions.IndexOf(newStep.Action) + ")"; planClone.Insert(newStep); planClone.Repair(oc, newStep); if (oc.isDummyGoal) { if (newStep.Height > 0) { var compNewStep = newStep as CompositePlanStep; planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep); } else { planClone.Orderings.Insert(oc.step.InitCndt, newStep); } } planClone.DetectThreats(newStep); Insert(planClone); } }
public Plan(List <Prereq> input) { foreach (var prereq in input) { PlanStep prerequisite = GetOrCreate(prereq.Prerequisite); PlanStep after = GetOrCreate(prereq.After); prerequisite.After.Add(after); after.Prerequisite.Add(prerequisite); } }
public TimelineDecomposition() : base() { fabCntgs = new List <Tuple <IPlanStep, IPlanStep> >(); discCntgs = new List <Tuple <CamPlanStep, CamPlanStep> >(); discourseSubSteps = new List <CamPlanStep>(); InitialActionSeg = new ActionSeg(); FinalActionSeg = new ActionSeg(); InitialAction = new PlanStep(); FinalAction = new PlanStep(); InitialCamAction = new CamPlanStep(); FinalCamAction = new CamPlanStep(); }
public void AddStep(IPlan plan, OpenCondition oc) { foreach (var cndt in CacheMaps.GetCndts(oc.precondition)) { if (cndt == null) { continue; } var planClone = plan.Clone() as IPlan; IPlanStep newStep; if (cndt.Height > 0) { //continue; var compCndt = cndt as IComposite; newStep = new CompositePlanStep(compCndt.Clone() as IComposite) { Depth = oc.step.Depth }; } else { newStep = new PlanStep(cndt.Clone() as IOperator) { Depth = oc.step.Depth }; } //newStep.Height = cndt.Height; planClone.Insert(newStep); planClone.Repair(oc, newStep); // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap //planClone.Flaws.UpdateFlaws(planClone, newStep); if (oc.isDummyGoal) { if (newStep.Height > 0) { var compNewStep = newStep as ICompositePlanStep; planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep); } else { planClone.Orderings.Insert(oc.step.InitCndt, newStep); } } planClone.DetectThreats(newStep); Insert(planClone); } }
private PlanStep GetOrCreate(char key) { PlanStep step; steps.TryGetValue(key, out step); if (step == null) { step = new PlanStep(); step.TimeTaken = key - 'A' + 61; // haha, side effects much steps.Add(key, step); } return(step); }
public void RepairWithComposite(OpenCondition oc, CompositeSchedulePlanStep repairStep) { var needStep = Find(oc.step); if (!needStep.Name.Equals("DummyGoal") && !needStep.Name.Equals("DummyInit")) { needStep.Fulfill(oc.precondition); } // need to merge all steps that are being connected by this predicate: if (oc.precondition.Name.Equals("obs-starts")) { var stepThatNeedsToBeMerged = oc.precondition.Terms[0]; IPlanStep ReferencedStep1 = new PlanStep(); IPlanStep ReferencedStep2 = new PlanStep(); foreach (var step in Steps) { if (step.Action.ID.ToString().Equals(stepThatNeedsToBeMerged)) { if (repairStep.SubSteps.Contains(step)) { ReferencedStep1 = step; } else { ReferencedStep2 = step; } } } if (ReferencedStep1.Name.Equals("") || ReferencedStep2.Name.Equals("")) { Debug.Log("never found steps to merge"); throw new System.Exception(); } if (ReferencedStep1.OpenConditions.Count > ReferencedStep2.OpenConditions.Count) { MergeSteps(ReferencedStep1, ReferencedStep2); } else { MergeSteps(ReferencedStep2, ReferencedStep1); } } orderings.Insert(repairStep.GoalStep as IPlanStep, needStep); var clink = new CausalLink <IPlanStep>(oc.precondition as Predicate, repairStep.GoalStep as IPlanStep, needStep); causalLinks.Add(clink); }
public static PlanStep GetPlanStepFromVariableName <T>(string variableName, List <ClipSchema <T> > clips, Dictionary <ClipSchema <T>, PlanStep> schemaMap) { var step = new PlanStep(); foreach (var schema in clips) { if (schema.display.Equals(variableName)) { return(schemaMap[schema]); } } return(step); }
public static void AddCurrentPlan(this FabPegPart pp, FabProduct prod, FabStep step) { if (prod == null || step == null) { //TODO : Write Error return; } PlanStep plan = new PlanStep(); plan.Product = prod; plan.Step = step; plan.isDummy = step.IsDummy; pp.AddCurrentPlan(plan); }
public static Decomposition GenericSubStepExample() { //(: action travel // : parameters(?person - person ? to - place) // :precondition() // :effect(and(at ? person ? to)) // :decomp( // :sub -params(? travel - step - step) // :requirements(and // (effect ? travel - step(at ? person ? to))))) var objTerms = new List <ITerm>() { new Term("?person") { Type = "person" }, new Term("?to") { Type = "place" }, }; var litTerms = new List <IPredicate>(); var atPersonTo = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[1] }, true); var travelOp = new Operator("", new List <IPredicate>(), new List <IPredicate>() { atPersonTo }); // check that travelOp.Terms are updated based on Effect? No this won't happen... var travelSubStep = new PlanStep(travelOp); var root = new Operator(new Predicate("generic-travel", objTerms, true)); var decomp = new Decomposition(root, litTerms, new List <IPlanStep>() { travelSubStep }, new List <BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep> >(), new List <CausalLink <IPlanStep> >()); return(decomp); }
public void AddStep(IPlan plan, OpenCondition oc) { foreach (var cndt in CacheMaps.GetCndts(oc.precondition)) { var planClone = plan.Clone() as IPlan; var newStep = new PlanStep(cndt.Clone() as IOperator); planClone.Insert(newStep); planClone.Repair(oc, newStep); // Check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap //planClone.Flaws.UpdateFlaws(planClone, newStep); // Detect if this new step threatens existing causal links planClone.DetectThreats(newStep); Insert(planClone); } }
// TODO: this is hacky because it's not actually based on Orientation Codes in cineamtography attributes public static Orient MapToNearestOrientation(PlanStep step, Dictionary <string, Vector3> locationMap) { // determine what the orientation is Orient orientEnum; var orientFloat = OrientInFloat(locationMap[step.Terms[step.Terms.Count - 1].Constant], locationMap[step.Terms[step.Terms.Count - 2].Constant]); while (orientFloat > 360) { orientFloat -= 360; } while (orientFloat < 0) { orientFloat += 360; } if ((orientFloat < 25 && orientFloat > -25) || (orientFloat > 335 && orientFloat < 385)) { orientEnum = Orient.o0; } else if (orientFloat > 65 && orientFloat < 115) { orientEnum = Orient.o90; } else if (orientFloat > 155 && orientFloat < 205) { orientEnum = Orient.o180; } else if (orientFloat > 245 && orientFloat < 295) { orientEnum = Orient.o270; } else { Debug.Log(orientFloat); Debug.Log("not a good orientation calculation or else not correct positioning of locations"); throw new System.Exception(); } return(orientEnum); }
public void DecacheSteps() { Parser.path = @"D:\documents\frostbow\"; var FileName = GetFileName(); GroundActionFactory.GroundActions = new List <IOperator>(); GroundActionFactory.GroundLibrary = new Dictionary <int, IOperator>(); int maxSeen = 0; int maxStepSeen = 0; foreach (var file in Directory.GetFiles(Parser.GetTopDirectory() + @"Cached\CachedOperators\UnityBlocksWorld\", problemname + "*.CachedOperator")) { var op = BinarySerializer.DeSerializeObject <IOperator>(file); GroundActionFactory.GroundActions.Add(op); GroundActionFactory.GroundLibrary[op.ID] = op; if (op.ID > maxSeen) { maxSeen = op.ID; } if (op is IComposite comp) { foreach (var sub in comp.SubSteps) { if (sub.ID > maxStepSeen) { maxStepSeen = sub.ID; } } if (comp.GoalStep.ID > maxStepSeen) { maxStepSeen = comp.GoalStep.ID; } } } // THIS is so that initial and goal steps created don't get matched with these Operator.SetCounterExternally(maxSeen + 1); PlanStep.SetCounterExternally(maxStepSeen + 1); }
public override void LoadContent(Vector2 TileDimensions, Vector2 SpawnLocation, Map map) { base.LoadContent(TileDimensions, SpawnLocation, map); LoadBehaviourSets(map); FacingAddup = map.D.Next(0, 4); CollisionType = 4; MyCollFactFile = new CollFactFile(CollisionType, true, MyIndex); GoldDrop = map.D.Next(MinGoldDrop, MaxGoldDrop); stepToComplete = new EmptyStep(TilePosition); //while (true) // { // foreach (LoadItemStack IS in PossDrops) // { // if (map.D.Next(0, 100) < IS.I) // { // //add that item to the drops // Item New = new Item(IS.ID); // New.Load(); // DropItems.Add(New); // } // } // } }
public static Decomposition TravelByPlane() { // (: action travel - by - plane // :parameters(?person - person ? from ? to - place) //:precondition(and(at ? person ? from)(not(= ? from ? to))) // :effect(and(at ? person ? to) // (not(at ? person ? from))) //:decomp( // :sub -params (? plane - plane // ? s1 ? s2 ? s3 ? s4 - step) // :requirements(and // (= ? s1(buy - tickets ? person)) // (= ? s2(board - plane ? person ? plane ? from)) // (= ? s3(fly ? person ? plane ? from ? to)) // (= ? s4(deplane ? person ? plane ? to)) // (linked - by ? s1 ? s2(has - ticket ? person)) // (linked - by ? s2 ? s3(in ? person ? plane)) // (linked - by ? s2 ? s4(in ? person ? plane)) // (linked - by ? s3 ? s4(at ? plane ? to))))) // Params var objTerms = new List <ITerm>() { new Term("?person") { Type = "person" }, new Term("?from") { Type = "place" }, new Term("?to") { Type = "place" }, new Term("?plane") { Type = "plane" } }; var litTerms = new List <IPredicate>(); var buyTerms = new List <ITerm>() { objTerms[0] }; var boardTerms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[1] }; var flyTerms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[1], objTerms[2] }; var deplaneTerms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[2] }; var buy = new PlanStep(new Operator(new Predicate("buy-tickets", buyTerms, true))); var board = new PlanStep(new Operator(new Predicate("board-plane", boardTerms, true))); var fly = new PlanStep(new Operator(new Predicate("fly", flyTerms, true))); var deplane = new PlanStep(new Operator(new Predicate("deplane", deplaneTerms, true))); var hasTicketPerson = new Predicate("has-ticket", new List <ITerm>() { objTerms[0] }, true); var inPersonPlane = new Predicate("in", new List <ITerm>() { objTerms[0], objTerms[3] }, true); var atPlaneTo = new Predicate("at", new List <ITerm>() { objTerms[3], objTerms[2] }, true); //new Operator() var substeps = new List <IPlanStep>() { buy, board, fly, deplane }; var sublinks = new List <CausalLink <IPlanStep> >() { new CausalLink <IPlanStep>(hasTicketPerson, buy, board), new CausalLink <IPlanStep>(inPersonPlane, board, fly), new CausalLink <IPlanStep>(inPersonPlane, board, deplane), new CausalLink <IPlanStep>(atPlaneTo, fly, deplane) }; var suborderings = new List <BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep> >() { new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(buy, board), new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(board, fly), new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(fly, deplane) }; var root = new Operator(new Predicate("travel-by-plane", objTerms, true)); var decomp = new Decomposition(root, litTerms, substeps, suborderings, sublinks) { NonEqualities = new List <List <ITerm> >() { new List <ITerm>() { objTerms[1], objTerms[2] } } }; return(decomp); }
public static Decomposition MultiMove() { // Params var objTerms = new List <ITerm>() { new Term("?agent") { Type = "steeringagent" }, //0 new Term("?from") { Type = "location" }, //1 new Term("?to") { Type = "location" }, //2 new Term("?intermediate") { Type = "location" } //3 }; var litTerms = new List <IPredicate>(); var atAgentOrigin = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[1] }, true); var atAgentInt = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[3] }, true); var atAgentDest = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[2] }, true); var move1 = new PlanStep(new Operator("", new List <IPredicate>() { atAgentOrigin }, new List <IPredicate> { atAgentInt })); var move2 = new PlanStep(new Operator("", new List <IPredicate>() { atAgentInt }, new List <IPredicate> { atAgentDest })); var substeps = new List <IPlanStep>() { move1, move2 }; var sublinks = new List <CausalLink <IPlanStep> >() { new CausalLink <IPlanStep>(atAgentInt, move1, move2) }; var suborderings = new List <BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep> >() { new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(move1, move2) }; var root = new Operator(new Predicate("multimove", objTerms, true)); var decomp = new Decomposition(root, litTerms, substeps, suborderings, sublinks) { NonEqualities = new List <List <ITerm> >() { new List <ITerm>() { objTerms[1], objTerms[2] }, new List <ITerm>() { objTerms[2], objTerms[3] }, new List <ITerm>() { objTerms[1], objTerms[3] } } }; return(decomp); }
/// <summary> /// Filters candidates for substeps, at least one with height "height" /// </summary> /// <param name="decomp"></param> /// <returns> List of decompositions with ground sub-steps. </returns> public static List <Decomposition> FilterDecompCandidates(Decomposition decomp, int height) { // find and replace sub-steps var comboList = new List <List <IOperator> >(); var ID_List = new List <int>(); foreach (var substep in decomp.SubSteps) { ID_List.Add(substep.ID); // each substep has ground terms that are already consistent. Composite IS-A Operator var cndts = ConsistentSteps(substep.Action as Operator); // If there's no cndts for this substep, then abandon this decomp. if (cndts.Count == 0) { return(new List <Decomposition>()); } comboList.Add(cndts); } List <Decomposition> decompList = new List <Decomposition>(); foreach (var combination in EnumerableExtension.GenerateCombinations(comboList)) { var decompClone = decomp.Clone() as Decomposition; var newSubsteps = new List <IPlanStep>(); var substepDict = new Dictionary <int, IPlanStep>(); var order = 0; var hasPrerequisiteHeight = false; foreach (var item in combination) { if (item.Height >= height) { // meets height requirement hasPrerequisiteHeight = true; } var originalID = ID_List[order++]; if (item.Height > 0) { var newPlanStep = new CompositePlanStep(item as Composite); substepDict[originalID] = newPlanStep; newSubsteps.Add(newPlanStep); } else { var newPlanStep = new PlanStep(item); substepDict[originalID] = newPlanStep; newSubsteps.Add(newPlanStep); } } // Did not meet requirements for height. if (!hasPrerequisiteHeight) { continue; } var newSuborderings = new List <Tuple <IPlanStep, IPlanStep> >(); foreach (var subordering in decomp.SubOrderings) { var first = substepDict[subordering.First.ID]; var second = substepDict[subordering.Second.ID]; newSuborderings.Add(new Tuple <IPlanStep, IPlanStep>(first, second)); } var linkWorlds = new List <List <CausalLink <IPlanStep> > >(); linkWorlds.Add(new List <CausalLink <IPlanStep> >()); var newSublinks = new List <CausalLink <IPlanStep> >(); foreach (var sublink in decomp.SubLinks) { var head = substepDict[sublink.Head.ID]; var tail = substepDict[sublink.Tail.ID]; var cndts = head.Effects.Where(eff => eff.IsConsistent(sublink.Predicate) && tail.Preconditions.Any(pre => pre.Equals(eff))); //// swap tall members //if (head.Height > 0) //{ // var Chead = head as CompositePlanStep; // head = Chead.GoalStep; //} //if (tail.Height > 0) //{ // var Ctail = tail as CompositePlanStep; // tail = Ctail.InitialStep; //} if (cndts.Count() == 0) { // forfeit this entire subplan linkWorlds = new List <List <CausalLink <IPlanStep> > >(); continue; } if (cndts.Count() == 1) { var cndt = cndts.First(); var dependency = cndt.Clone() as Predicate; var newLink = new CausalLink <IPlanStep>(dependency, head, tail); newLink.Tail.Fulfill(cndt); foreach (var linkworld in linkWorlds) { linkworld.Add(newLink); } } else { foreach (var cndt in cndts) { var dependency = cndt.Clone() as Predicate; var newLink = new CausalLink <IPlanStep>(dependency, head, tail); newLink.Tail.Fulfill(cndt); var clonedLinks = EnumerableExtension.CloneList(newSublinks); linkWorlds.Add(clonedLinks); foreach (var linkworld in linkWorlds) { linkworld.Add(newLink); } } } } foreach (var linkworld in linkWorlds) { var newDecomp = decomp.Clone() as Decomposition; newDecomp.SubSteps = newSubsteps; newDecomp.SubOrderings = newSuborderings; newDecomp.SubLinks = linkworld; decompList.Add(newDecomp); } } return(decompList); }
public new void AddStep(IPlan plan, OpenCondition oc) { long before = 0; var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var cndt in CacheMaps.GetCndts(oc.precondition)) { if (cndt == null) { continue; } if (cndt.Height == 0) { continue; } before = watch.ElapsedMilliseconds; var planClone = plan.Clone() as PlanSchedule; IPlanStep newStep; if (cndt.Height > 0) { //continue; var compCndt = cndt as CompositeSchedule; newStep = new CompositeSchedulePlanStep(compCndt.Clone() as IComposite, compCndt.Cntgs) { Depth = oc.step.Depth }; } else { // only add composite steps... //continue; newStep = new PlanStep(cndt.Clone() as IOperator) { Depth = oc.step.Depth }; } LogTime("CloneCndt", watch.ElapsedMilliseconds - before); before = watch.ElapsedMilliseconds; planClone.Insert(newStep); LogTime("InsertDecomp", watch.ElapsedMilliseconds - before); //newStep.Height = cndt.Height; // planClone.Insert(newStep); before = watch.ElapsedMilliseconds; planClone.Repair(oc, newStep); LogTime("RepairDecomp", watch.ElapsedMilliseconds - before); // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap //planClone.Flaws.UpdateFlaws(planClone, newStep); if (oc.isDummyGoal) { if (newStep.Height > 0) { var compNewStep = newStep as CompositeSchedulePlanStep; planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep); } else { planClone.Orderings.Insert(oc.step.InitCndt, newStep); } } before = watch.ElapsedMilliseconds; planClone.DetectThreats(newStep); LogTime("DetectThreats", watch.ElapsedMilliseconds - before); before = watch.ElapsedMilliseconds; Insert(planClone); LogTime("InsertPlan", watch.ElapsedMilliseconds - before); } }
public PlanStep ReadStepVariable(ClipSchema <FabulaAsset> schema) { PlanStep ps; FabulaAsset fabAsset = schema.asset; var terms = new List <ITerm>(); var preconditions = new List <IPredicate>(); var effects = new List <IPredicate>(); string schemaName = ""; var unityactionschema = fabAsset.schema; if (unityactionschema != null) { schemaName = unityactionschema.name; var actionOperator = GameObject.Find(schemaName).GetComponent <UnityActionOperator>(); for (int i = 0; i < actionOperator.MutableParameters.Count; i++) { var newTerm = new Term(i.ToString()) { Type = actionOperator.MutableParameters[i].name }; terms.Add(newTerm as ITerm); } } foreach (var constraint in fabAsset.Constraints) { var constraintParts = constraint.Split(' '); var instruction = constraintParts[0]; if (instruction.Equals("terms")) { for (int j = 1; j < constraintParts.Count(); j++) { var instructArg = constraintParts[j]; var newTerm = new Term(instructArg, true) as ITerm; // if there already is a term at this index, need to reference with variable if (terms.Count > j - 1) { var existingTerm = terms[j - 1]; newTerm.Variable = existingTerm.Variable; newTerm.Type = existingTerm.Type; terms[j - 1] = newTerm; } else { terms.Add(newTerm); } } //foreach(var instructArg in constraintParts.Skip(1)) //{ // terms.Add(new Term(instructArg, true) as ITerm); //} } if (instruction.Equals("term")) { var argPos = Int32.Parse(constraintParts[1]); if (argPos >= terms.Count - 1) { // if the arg position is not the next item in term list, then while (argPos != terms.Count) { // add placeholder terms terms.Add(new Term(terms.Count.ToString()) as ITerm); } terms.Add(new Term(constraintParts[2], true) as ITerm); } else if (argPos < terms.Count) { terms.Insert(argPos, new Term(constraintParts[2], true) as ITerm); } } if (instruction.Equals("precond") || instruction.Equals("has-precond") || instruction.Equals("precondition")) { var pred = ProcessPredicateString(constraintParts); preconditions.Add(pred); } if (instruction.Equals("effect") || instruction.Equals("has-effect")) { var pred = ProcessPredicateString(constraintParts); effects.Add(pred); } if (instruction.Equals("schema")) { // then this operator gets a particular name schemaName = constraintParts[1]; } if (instruction.Equals("not")) { if (constraintParts[1].Equals("schema")) { // propagate to schema schema.AddConstraint(constraint); } // TODO: assemble list of negative constraints and propagate to filtering } } var root = new Operator(new Predicate(schemaName, terms, true), preconditions, effects); ps = new PlanStep(root as IOperator); return(ps); }
public static Decomposition TravelByCar() { // (: action travel - by - car // :parameters(?person - person ? from ? to - place) //:precondition(and(at ? person ? from)(not(= ? from ? to))) // :effect(and(at ? person ? to) // (not(at ? person ? from))) //:decomp( // :sub -params (? car - car ? s1 ? s2 ? s3 - step) // :requirements(and // (= ? s1(get -in -car ? person ? car ? from)) // (= ? s2(drive ? person ? car ? from ? to)) // (= ? s3(get -out -of - car ? person ? car ? to)) // (linked - by ? s1 ? s2(in ? person ? car)) // (linked - by ? s1 ? s3(in ? person ? car)) // (linked - by ? s2 ? s3(at ? car ? to))))) // Params var objTerms = new List <ITerm>() { new Term("?person") { Type = "person" }, new Term("?from") { Type = "place" }, new Term("?to") { Type = "place" }, new Term("?car") { Type = "car" } }; var litTerms = new List <IPredicate>(); var s1terms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[1] }; var s2terms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[1], objTerms[2] }; var s3terms = new List <ITerm>() { objTerms[0], objTerms[3], objTerms[2] }; var getInCar = new PlanStep(new Operator(new Predicate("get-in-car", s1terms, true))); var drive = new PlanStep(new Operator(new Predicate("drive", s2terms, true))); var getOutOfCar = new PlanStep(new Operator(new Predicate("get-out-of-car", s3terms, true))); var inPersonCar = new Predicate("in", new List <ITerm>() { objTerms[0], objTerms[3] }, true); var atCarTo = new Predicate("at", new List <ITerm>() { objTerms[3], objTerms[2] }, true); //new Operator() var substeps = new List <IPlanStep>() { getInCar, drive, getOutOfCar }; var sublinks = new List <CausalLink <IPlanStep> >() { new CausalLink <IPlanStep>(inPersonCar, getInCar, drive), new CausalLink <IPlanStep>(inPersonCar, getInCar, getOutOfCar), new CausalLink <IPlanStep>(atCarTo, drive, getOutOfCar) }; var suborderings = new List <BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep> >() { new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(getInCar, drive), new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(drive, getOutOfCar) }; var root = new Operator(new Predicate("travel-by-car", objTerms, true)); var decomp = new Decomposition(root, litTerms, substeps, suborderings, sublinks); return(decomp); }
public new void AddStep(IPlan plan, OpenCondition oc) { long before = 0; // check oc step depth. var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var cndt in CacheMaps.GetCndts(oc.precondition)) { if (cndt == null) { continue; } if (cndt.Height == 0) { continue; } before = watch.ElapsedMilliseconds; var planClone = plan.Clone() as PlanSchedule; //if (planClone.ID.Equals("1335")) //{ // Console.WriteLine("Here"); //} planClone.ID += "a"; IPlanStep newStep; if (cndt.Height > 0) { //continue; var compCndt = cndt as CompositeSchedule; newStep = new CompositeSchedulePlanStep(compCndt.Clone() as CompositeSchedule) { Depth = oc.step.Depth }; } else { // only add composite steps... //continue; newStep = new PlanStep(cndt.Clone() as IOperator) { Depth = oc.step.Depth }; } planClone.ID += "(" + GroundActionFactory.GroundActions.IndexOf(newStep.Action) + ")"; LogTime("CloneCndt", watch.ElapsedMilliseconds - before); before = watch.ElapsedMilliseconds; planClone.Insert(newStep); LogTime("InsertDecomp", watch.ElapsedMilliseconds - before); //newStep.Height = cndt.Height; // planClone.Insert(newStep); before = watch.ElapsedMilliseconds; planClone.Repair(oc, newStep); LogTime("RepairDecomp", watch.ElapsedMilliseconds - before); // check if inserting new Step (with orderings given by Repair) add cndts/risks to existing open conditions, affecting their status in the heap //planClone.Flaws.UpdateFlaws(planClone, newStep); if (oc.isDummyGoal) { if (newStep.Height > 0) { var compNewStep = newStep as CompositeSchedulePlanStep; planClone.Orderings.Insert(oc.step.InitCndt, compNewStep.InitialStep); //planClone.ID += string.Format("(^Oa[{0},{1}])", oc.step.InitCndt.ID, compNewStep.InitialStep.ID); } else { planClone.Orderings.Insert(oc.step.InitCndt, newStep); //planClone.ID += string.Format("(^Oa[{0},{1}])", oc.step.InitCndt.ID, newStep.ID); } } before = watch.ElapsedMilliseconds; planClone.DetectThreats(newStep); LogTime("DetectThreats", watch.ElapsedMilliseconds - before); before = watch.ElapsedMilliseconds; Insert(planClone); LogTime("InsertPlan", watch.ElapsedMilliseconds - before); } }
public static Decomposition Transport() { // Params var objTerms = new List <ITerm>() { new Term("?agent") { Type = "steeringagent" }, //0 new Term("?item") { Type = "block" }, //1 new Term("?from") { Type = "location" }, //2 new Term("?to") { Type = "location" }, //3 new Term("?adjacentfrom") { Type = "location" }, //4 new Term("?adjacentto") { Type = "location" } //5 }; var litTerms = new List <IPredicate>(); // pickup (?taker - agent ?block - block ?location - location ?takerLocation - location) var pickupterms = new List <ITerm>() { objTerms[0], objTerms[1], objTerms[2], objTerms[4] }; // This guaranteed move //var moveterms = new List<ITerm>() { objTerms[0], objTerms[4], objTerms[5] }; //(?putter - agent ?thing - block ?agentlocation - location ?newlocation - location) var putdownterms = new List <ITerm>() { objTerms[0], objTerms[1], objTerms[5], objTerms[3] }; var pickup = new PlanStep(new Operator(new Predicate("pickup", pickupterms, true))); // var travelOp = new Operator("", new List<IPredicate>(), new List<IPredicate>(){ atPersonTo}); var putdown = new PlanStep(new Operator(new Predicate("putdown", putdownterms, true))); var atAgentOrigin = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[4] }, true); var hasAgentThing = new Predicate("has", new List <ITerm>() { objTerms[0], objTerms[1] }, true); var atAgentDest = new Predicate("at", new List <ITerm>() { objTerms[0], objTerms[5] }, true); var move = new PlanStep(new Operator("", new List <IPredicate>() { atAgentOrigin }, new List <IPredicate> { atAgentDest })); //new Operator() var substeps = new List <IPlanStep>() { pickup, move, putdown }; var sublinks = new List <CausalLink <IPlanStep> >() { // new CausalLink<IPlanStep>(atAgentOrigin, pickup, move), new CausalLink <IPlanStep>(hasAgentThing, pickup, putdown), new CausalLink <IPlanStep>(atAgentDest, move, putdown), }; var suborderings = new List <BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep> >() { new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(pickup, move), new BoltFreezer.Utilities.Tuple <IPlanStep, IPlanStep>(move, putdown) }; var root = new Operator(new Predicate("transport", objTerms, true)); var decomp = new Decomposition(root, litTerms, substeps, suborderings, sublinks) { NonEqualities = new List <List <ITerm> >() { new List <ITerm>() { objTerms[2], objTerms[3] }, new List <ITerm>() { objTerms[2], objTerms[4] }, new List <ITerm>() { objTerms[3], objTerms[5] } } }; return(decomp); }
protected virtual PlanStep CreateStep(ProjectionElement parent, ProjectionElement child, ParameterNames pars, ParameterNames allPars, Provider provider, int priorGroup, Query func) { var step = new PlanStep(parent, child, pars, provider, allPars, priorGroup, _checkMode); return(step); }