/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (MethodInfo method in this.Selector.SelectMethodsForInjection(plan.Type)) { plan.Add(new MethodInjectionDirective(method, this.InjectorFactory.Create(method))); } }
/// <summary> /// Adds a <see cref="MethodInjectionDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (MethodInfo method in Selector.SelectMethodsForInjection(plan.Type)) plan.Add(new MethodInjectionDirective(method, InjectorFactory.Create(method))); }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public virtual void Execute( IPlan plan ) { IEnumerable<MethodInfo> candidates = GetCandidateMethods( plan.Type ); RegisterClassInterceptors( plan.Type, plan, candidates ); foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( plan.Type ); ICustomAttributeProvider provider = (ICustomAttributeProvider) property ?? method; InterceptAttribute[] attributes = provider.GetAllAttributes<InterceptAttribute>(); if ( attributes.Length == 0 ) { continue; } RegisterMethodInterceptors( plan.Type, method, attributes ); // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } } }
public RootTrainingAction(IPlan plan, ContextMaps maps) { foreach (var contained in plan.ContainedPlans) { ChildActions.Add(new TrainingAction(contained, maps)); } }
/// <summary> /// Execute the plan strategy /// </summary> /// <param name="plan">Plan</param> public void Execute(IPlan plan) { var manager = this._kernel.Get<IObjectCacheManager>(); if (!manager.HasCachedMethods(plan.Type)) { return; } var methods = manager.GetCachedMethods(plan.Type); foreach (var method in methods) { var advice = this._adviceFactory.Create(method); var cache = manager.GetCache(plan.Type, method); var methodCache = typeof (MethodCache); var cacheMethod = (IInterceptor)Activator.CreateInstance(methodCache, cache); advice.Callback = request => cacheMethod; this._adviceRegistry.Register(advice); if (!plan.Has<ProxyDirective>()) { plan.Add(new ProxyDirective()); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public override void Execute( IPlan plan ) { if ( !typeof (IAutoNotifyPropertyChanged).IsAssignableFrom( plan.Type ) ) { return; } IEnumerable<MethodInfo> candidates = GetCandidateMethods( plan.Type ); RegisterClassInterceptors( plan.Type, plan, candidates ); foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( method.DeclaringType ); NotifyOfChangesAttribute[] attributes = property.GetAllAttributes<NotifyOfChangesAttribute>(); if ( attributes.Length == 0 ) { continue; } RegisterMethodInterceptors( plan.Type, method, attributes ); // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } } }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); }
public DefaultBuildEnvironment(IPlan plan, ITargetDescription description, TaskMap<ModuleName, ITarget> taskMap, CancellationToken token) { if (taskMap == null) throw new System.ArgumentNullException("taskMap"); if (description == null) throw new System.ArgumentNullException("description"); if ((object) plan == null) throw new System.ArgumentNullException("plan"); _token = token; _plan = plan; _taskMap = taskMap; _description = description; var externals = new List<SymbolInfo>(); foreach (var name in description.Dependencies) { var d = taskMap[name].Value.Result; if (d.Symbols == null) continue; var origin = new SymbolOrigin.ModuleTopLevel(name, NoSourcePosition.Instance); externals.AddRange(from decl in d.Symbols select new SymbolInfo(decl.Value, origin, decl.Key)); } _externalSymbols = SymbolStore.Create(conflictUnionSource: externals); _compilationEngine = new Engine(); _module = Module.Create(description.Name); }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute( IPlan plan ) { EventInfo[] events = plan.Type.GetEvents( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); foreach ( EventInfo evt in events ) { IEnumerable<PublishAttribute> attributes = evt.GetAttributes<PublishAttribute>(); foreach ( PublishAttribute attribute in attributes ) { plan.Add( new PublicationDirective( attribute.Channel, evt ) ); } } MethodInfo[] methods = plan.Type.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); foreach ( MethodInfo method in methods ) { IEnumerable<SubscribeAttribute> attributes = method.GetAttributes<SubscribeAttribute>(); foreach ( SubscribeAttribute attribute in attributes ) { MethodInjector injector = InjectorFactory.Create( method ); plan.Add( new SubscriptionDirective( attribute.Channel, injector, attribute.Thread ) ); } } }
/// <summary> /// Contributes to the specified plan. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute( IPlan plan ) { EventInfo[] events = plan.Type.GetEvents( DefaultBindingFlags ); foreach ( EventInfo evt in events ) { IEnumerable<PublishAttribute> attributes = evt.GetAttributes<PublishAttribute>(); foreach ( PublishAttribute attribute in attributes ) { plan.Add( new PublicationDirective( attribute.Channel, evt ) ); } } MethodInfo[] methods = plan.Type.GetMethods( DefaultBindingFlags ); foreach ( MethodInfo method in methods ) { IEnumerable<SubscribeAttribute> attributes = method.GetAttributes<SubscribeAttribute>(); foreach ( SubscribeAttribute attribute in attributes ) { plan.Add( new SubscriptionDirective( attribute.Channel, method ) ); } } }
public void ExecutePlan(IPlan plan, MorphoSyntacticContext initialContext) { var baseAction = TrainingAction.ImplementPlan(plan, _vectors, _contextMaps); //todo - could loop to reduce error var error = baseAction.Train(_network,initialContext); baseAction.SaveContexts(_contextMaps); }
public void AddChildNode(IPlan parent, INode child) { if (!((INode) parent).Children.Contains(child)) { ((DefaultNode) parent).AddChild(child); } AddNodeToLookup(child); }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); ConstructorInfo constructor = Selector.SelectConstructor(plan.Type); if (constructor != null) plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); }
public IPlan AssemblePlan(IPlan plan) { this.RootNeuron = new ActionNeuron(); this.RootNeuron.LoadConnections(new NeuralPath(RootNeuron, plan)); this.Path = this.RootNeuron.Fire(); return plan; }
public static string GetDebugRepresentation(this IPlan currentPlan, string indent = null) { var current = (INode)currentPlan; indent = indent ?? string.Empty; if (current == null) { return(string.Empty); } var me = (indent + "* " + current.Name).TrimEnd(); if (current.Type != null) { me += " (" + current.Type.FullName + ")"; } if (current.Planned) { if (current.Deferred) { if (!string.IsNullOrEmpty(current.PlanName)) { me += " **DEFERRED (as '" + current.PlanName + "')**"; } else { me += " **DEFERRED**"; } } else { if (!string.IsNullOrEmpty(current.PlanName)) { me += " **PLANNED (as '" + current.PlanName + "')**"; } else { me += " **PLANNED**"; } } } me += Environment.NewLine; foreach (var c in current.Children) { me += GetDebugRepresentation(c, indent + " "); } if (current.Planned && current.PlannedConstructorArguments != null) { foreach (var p in current.PlannedConstructorArguments) { me += GetDebugRepresentation(p, indent + " "); } } return(me); }
public float Evaluate(IPlan plan) { if (plan.Flaws.Count == 0 && plan.Hdepth > 0) { return(-10000f - plan.Steps.Count); } return(HMethod.Heuristic(plan) + ((plan.Steps.Count - (2 * plan.Decomps)) / (float)(1 + System.Math.Log((double)plan.Hdepth + 1f, 2)))); }
public TrainingAction(IPlan plan, ContextMaps maps) : base(plan,maps) { _contextMap = maps.For(plan.Word); _weights = _contextMap.NeuronWeights; if (!plan.Output.HasValue) throw new ArgumentException("plan.Output must be set", "plan"); _wordVector = _vectors[plan.Word]; if (_outputArray == null) { _outputArray = OutputToArray(plan.Output.Value); } }
/// <summary> /// Adds a serial of <see cref="ConstructorInjectionDirective"/>s to the plan for the constructors /// that could be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> /// <exception cref="ArgumentNullException"><paramref name="plan"/> is <see langword="null"/>.</exception> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, nameof(plan)); var constructors = this.selector.SelectConstructorsForInjection(plan.Type); foreach (var constructor in constructors) { var directive = new ConstructorInjectionDirective(constructor, this.injectorFactory.Create(constructor)); plan.Add(directive); } }
public void GetStandardEventSubscribers_ReturnsPlans() { FixtureData.TestPlanWithSubscribeEvent(); IPlan curPlan = ObjectFactory.GetInstance <IPlan>(); EventReportCM curEventReport = FixtureData.StandardEventReportFormat(); var result = curPlan.GetMatchingPlans("testuser1", curEventReport); Assert.IsNotNull(result); Assert.Greater(result.Count, 0); Assert.Greater(result.Where(name => name.Name.Contains("StandardEventTesting")).Count(), 0); }
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); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective" /> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); var constructors = Selector.SelectConstructorsForInjection(plan.Type); if (constructors == null) return; foreach (var constructor in constructors) { plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))); } }
public void Add(IPlan plan, OpenCondition oc) { // Don't add an open condition if it's already in the Flawque. if (OpenConditions.Contains(oc)) { return; } // Predicates are labeled as static before planning if (GroundActionFactory.Statics.Contains(oc.precondition)) { oc.isStatic = true; oc.addReuseHeuristic = 0; OpenConditions.Add(oc); return; } // Use this value to keep track of amount of work. if (HeuristicMethods.visitedPreds.Get(oc.precondition.Sign).ContainsKey(oc.precondition)) { oc.addReuseHeuristic = HeuristicMethods.visitedPreds.Get(oc.precondition.Sign)[oc.precondition]; } // Calculate risks and cndts foreach (var step in plan.Steps) { if (step.ID == oc.step.ID) { continue; } if (plan.Orderings.IsPath(oc.step, step)) { continue; } if (CacheMaps.IsThreat(oc.precondition, step)) { oc.risks += 1; } } if (oc.risks == 0 && plan.Initial.InState(oc.precondition)) { oc.isInit = true; oc.addReuseHeuristic = 1; } OpenConditions.Add(oc); }
private void ValidateArgument(IUnresolvedArgument argument, IPlan target) { if (argument.InjectionParameters.OfType <OptionalAttribute>().Any()) { // Optional arguments are always valid, because the result will // simply be null when injected. return; } if (!target.Valid) { throw new ActivationException("The planned node is not valid (hint: " + target.InvalidHint + ")", target); } }
public void SetPlan(IPlan plan) { if (!(plan is PlanWrapper <TStateKey, TActionKey, TStateManager, TStateData, TStateDataContext> planWrapper)) { throw new ArgumentException($"Plan must be of type {typeof(PlanWrapper<TStateKey, TActionKey, TStateManager, TStateData, TStateDataContext>)}."); } if (Status == PlanExecutionStatus.AwaitingPlan) { Status = PlanExecutionStatus.AwaitingExecution; } m_PlanWrapper = planWrapper; }
public static void RunPlanner(IPlan initPi, List <IOperator> domainOps, ISelection SelectMethod, ISearch SearchMethod, int k, float cutoff, string directoryToSaveTo, int problem) { var POP = new StateSpacePlanner(initPi, SelectMethod, SearchMethod, domainOps, true) { directory = directoryToSaveTo, problemNumber = problem, }; var Solutions = POP.Solve(k, cutoff); if (Solutions != null) { Console.WriteLine(Solutions[0].ToString()); } }
public static void RunPlanner(IPlan initPi, ISearch SearchMethod, ISelection SelectMethod, int k, float cutoff, string directoryToSaveTo, int problem) { var POP = new PlanSpacePlanner(initPi, SelectMethod, SearchMethod, true) { directory = directoryToSaveTo, problemNumber = problem, }; var Solutions = POP.Solve(k, cutoff); if (Solutions != null) { Solutions[0].ToStringOrdered(); } }
public void Reuse(IPlan plan, OpenCondition oc) { // if repaired by initial state if (plan.Initial.InState(oc.precondition)) { var planClone = plan.Clone() as IPlan; planClone.Repair(oc, planClone.InitialStep); Insert(planClone); } foreach (var step in plan.Steps) { if (oc.step.ID == step.ID) { continue; } if (step.Height > 0) { continue; } if (step == oc.step.InitCndt && oc.hasDummyInit) { var planClone = plan.Clone() as IPlan; planClone.Repair(oc, step); Insert(planClone); continue; } //if (step.Effects.Contains(oc.precondition)) //{ // Console.Write("here"); //} if (CacheMaps.IsCndt(oc.precondition, step)) { // before adding a repair, check if there is a path. if (plan.Orderings.IsPath(oc.step, step)) { continue; } var planClone = plan.Clone() as IPlan; planClone.Repair(oc, step); Insert(planClone); } } }
// h^r_add(pi) = sum_(oc in plan) 0 if exists a step possibly preceding oc.step and h_add(oc.precondition) otherwise. public static int AddReuseHeuristic(IPlan plan) { // we are just taking the sum of the visitedPreds values of the open conditions, unless there is a step that establishes the condition already in plan (reuse). int sumo = 0; foreach (var oc in plan.Flaws.OpenConditions) { // Does there exist a step in the plan that can establish this needed precondition? var existsA = false; foreach (var existingStep in plan.Steps) { if (existingStep.Height > 0) { continue; } if (plan.Orderings.IsPath(oc.step, existingStep)) { continue; } if (CacheMaps.IsCndt(oc.precondition, existingStep)) { existsA = true; break; } } // append heuristic for open condition if (!existsA) { // we should always have the conditions in the visitedPreds dictionary if we processed correctly if (visitedPreds.Get(oc.precondition.Sign).ContainsKey(oc.precondition)) { sumo += visitedPreds.Get(oc.precondition.Sign)[oc.precondition]; continue; } throw new System.Exception("visitedPreds does not contain " + oc.precondition.ToString()); //currentlyEvaluatedPreds.Add(oc.precondition); //var amountToAdd = AddHeuristic(plan.Initial, oc.precondition, new HashSet<IPredicate>() { oc.precondition }); var amountToAdd = AddHeuristic(oc.precondition); sumo += amountToAdd; visitedPreds.Get(oc.precondition.Sign)[oc.precondition] = amountToAdd; } } return(sumo); }
// Update is called once per frame void Update() { if (compilePrimitiveSteps) { compilePrimitiveSteps = false; initialPlan = PreparePlanner(true); PrimitiveOps = GroundActionFactory.GroundActions; PrimitiveSteps = PrimitiveOps.Count; CompositeSteps = 0; } if (compileCompositeSteps) { compileCompositeSteps = false; CompileCompositeSteps(); } if (checkEffects) { checkEffects = false; foreach (var compstep in CompositeOps) { foreach (var effect in compstep.Effects) { if (effect.Name != "obs") // && effect.Name != "obs-starts") { continue; } Debug.Log(effect.ToString()); } } // do we have what we need? } if (regenerateInitialPlanWithComposite) { regenerateInitialPlanWithComposite = false; Parser.path = "/"; var domainOperatorComponent = GameObject.FindGameObjectWithTag("ActionHost").GetComponent <DomainOperators>(); domainOperatorComponent.Reset(); var problem = CreateProblem(domainOperatorComponent.DomainOps); var domain = CreateDomain(domainOperatorComponent); var PF = new ProblemFreezer("Unity", "", domain, problem); var initPlan = PlannerScheduler.CreateInitialPlan(PF); CacheMaps.CacheAddReuseHeuristic(initPlan.Initial); PrimaryEffectHack(InitialPlan.Initial); } }
public List <IPlan> Process(IPlan planToBuildOn) { var newPlans = new List <IPlan>(); foreach (var precon in thisConstraint.Second.Preconditions) { if (CacheMaps.IsCndt(precon, thisConstraint.First)) { var planClone = planToBuildOn.Clone() as IPlan; planClone.CausalLinks.Add(new CausalLink <IPlanStep>(precon, thisConstraint.First, thisConstraint.Second)); newPlans.Add(planClone); } } return(newPlans); }
private List <IPlan> IListToDelPlan(IList lst) { List <IPlan> delPlan = new List <IPlan>(); for (int i = 0; i < lst.Count; i++) { IPlan p = lst[i] as IPlan; if (p == null) { break; } delPlan.Add(p); } return(delPlan); }
/// <summary> /// Adds a <see cref="PropertyDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var properties = Selector.SelectPropertiesForInjection(plan.Type); if (properties != null) { foreach (var property in properties) { plan.Add(new PropertyDirective(property, InjectorFactory.Create(property))); } } }
public PlansController(IPlan plan, ISecurityServices securityServices, ICrateManager crateManager, IPusherNotifier pusherNotifier, IActivityTemplate activityTemplate, IActivity activity, IPlanDirectoryService planDirectoryService) { _plan = plan; _security = securityServices; _crate = crateManager; _pusherNotifier = pusherNotifier; _activityTemplate = activityTemplate; _activity = activity; _planDirectoryService = planDirectoryService; }
/// <summary> /// Adds a <see cref="MethodDirective"/> to the plan for each method /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var methods = Selector.SelectMethodsForInjection(plan.Type); if (methods != null) { foreach (var method in methods) { plan.Add(new MethodDirective(method, InjectorFactory.Create(method))); } } }
public void Add(IPlan plan, OpenCondition oc) { // Don't add an open condition if it's already in the Flawque. if (OpenConditions.Contains(oc)) { return; } // Predicates are labeled as static before planning if (GroundActionFactory.Statics.Contains(oc.precondition)) { oc.isStatic = true; OpenConditions.Add(oc); return; } // Calculate risks and cndts foreach (var step in plan.Steps) { if (step.ID == oc.step.ID) { continue; } if (plan.Orderings.IsPath(oc.step, step)) { continue; } if (CacheMaps.IsCndt(oc.precondition, step)) { oc.cndts += 1; } if (CacheMaps.IsThreat(oc.precondition, step)) { oc.risks += 1; } } if (oc.risks == 0 && plan.Initial.InState(oc.precondition)) { oc.isInit = true; } OpenConditions.Add(oc); }
public new void Insert(IPlan plan) { var planschedule = plan as PlanSchedule; long before = 0; var watch = System.Diagnostics.Stopwatch.StartNew(); before = watch.ElapsedMilliseconds; if (planschedule.Cntgs.HasFault(plan.Orderings)) { LogTime("CheckFaults", watch.ElapsedMilliseconds - before); return; } LogTime("CheckFaults", watch.ElapsedMilliseconds - before); base.Insert(plan); }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); var directive = new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }; plan.Add(directive); } }
public float Evaluate(IPlan plan) { if (plan.Flaws.Count == 0 && plan.Hdepth > 0) { return(-10000f - plan.Steps.Count); } if (plan.Hdepth == 0) { return(HMethod.Heuristic(plan) + (plan.Steps.Count - (3 * plan.Decomps))); } else { return(HMethod.Heuristic(plan) + (plan.Steps.Count - (3 * plan.Decomps)) - (plan.Decomps / plan.Hdepth)); } }
public float Evaluate(IPlan plan) { if (plan.Flaws.Count == 0 && plan.Hdepth > 0) { return(-10000f - plan.Steps.Count); } if (firstNoFlaws) { if (plan.Flaws.Count == 0) { return(-100f - plan.Steps.Count); } } return(plan.Steps.Count - (2 * plan.Decomps) + HMethod.Heuristic(plan)); }
protected void Awake() { // Set animator _animator = GetComponentInChildren <Animator>(); // Set action planner _actionPlanner = new ActionPlanner <Dog, IDogAction>(); // Set state _state = _actionPlanner.GetState(); _state.Position = new Vector2(_animator.transform.position.x, _animator.transform.position.z); _state.Speed = new Vector2(0, 0); // Set active plan _planActive = _actionPlanner.GetPlan(); // Set test plan _planTest = _actionPlanner.GetPlan(); // Set action state machine _actionStateMachine = new ActionStateMachine <Dog, IDogAction, float>(); }
public static void RunPlanner(IPlan initPi, ISearch SearchMethod, ISelection SelectMethod, int k, float cutoff, string directoryToSaveTo, int problem) { // Create a planner object to run this instance var POP = new PlanSpacePlanner(initPi, SelectMethod, SearchMethod, true) { directory = directoryToSaveTo, problemNumber = problem, }; // Return a list of k solutions var Solutions = POP.Solve(k, cutoff); // Print the first solution to console if (Solutions != null) { Console.Write(Solutions[0].ToStringOrdered()); } }
/// <summary> /// Adds a <see cref="ConstructorInjectionDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { Ensure.ArgumentNotNull(plan, "plan"); IEnumerable<ConstructorInfo> constructors = Selector.SelectConstructorsForInjection(plan.Type); if(constructors == null) return; foreach(ConstructorInfo constructor in constructors) { var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); plan.Add( new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute }); } }
public void Insert(IPlan plan) { var watch = System.Diagnostics.Stopwatch.StartNew(); long before = watch.ElapsedMilliseconds; if (!plan.Orderings.HasCycle()) { LogTime("checkOrderings", watch.ElapsedMilliseconds - before); //if (Visited.Contains(plan as Plan)) //{ // return; //} //Visited.Add(plan as Plan); Search.Frontier.Enqueue(plan, Score(plan)); opened++; } LogTime("checkOrderings", watch.ElapsedMilliseconds - before); }
/// <summary> /// Adds a <see cref="ConstructorDirective"/> to the plan for the constructor /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { if (plan == null) { throw new ArgumentNullException(nameof(plan)); } var constructors = Selector.SelectConstructorsForInjection(plan.Type); if (constructors != null) { foreach (var constructor in constructors) { plan.Add(new ConstructorDirective(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = constructor.IsDefined(Settings.InjectAttribute, false) }); } } }
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); } }
public void Insert(IPlan plan) { if (!plan.Orderings.HasCycle()) { var score = Score(plan); if (score > 600) { Console.WriteLine(score); // reduce size of frontier return; } search.Frontier.Enqueue(plan, score); opened++; } else { plan = null; } }
public void RepairThreat(IPlan plan, ThreatenedLinkFlaw tclf) { var cl = tclf.causallink; var threat = tclf.threatener; if (threat is CompositePlanStep cps) { if (!plan.Orderings.IsPath(cps.InitialStep, cl.Tail)) { var promote = plan.Clone() as IPlan; promote.ID += "p"; promote.Orderings.Insert(cl.Tail, cps.InitialStep); Insert(promote); } if (!plan.Orderings.IsPath(cl.Head, cps.GoalStep)) { var demote = plan.Clone() as IPlan; demote.ID += "d"; demote.Orderings.Insert(cps.GoalStep, cl.Head); Insert(demote); } } else { // Promote if (!plan.Orderings.IsPath(threat, cl.Tail)) { var promote = plan.Clone() as IPlan; promote.ID += "p"; promote.Orderings.Insert(cl.Tail, threat); Insert(promote); } // Demote if (!plan.Orderings.IsPath(cl.Head, threat)) { var demote = plan.Clone() as IPlan; demote.ID += "d"; demote.Orderings.Insert(threat, cl.Head); Insert(demote); } } }
public bool PreparePlan(int sentenceLength, IPlan basePlan) { bool foundAny = false; foreach (var writtenSentence in _sentences.SentencesOfLength(sentenceLength)) { foundAny = true; IPlan nextPlanNode= basePlan; WrittenWord prevWord = null; foreach (WrittenWord writtenWord in writtenSentence.Words) { var output = writtenWord.IsEndOfSentence() ? TrainingOutput.Complete : TrainingOutput.Incomplete; if (prevWord != null) { nextPlanNode = nextPlanNode.AddPlanStep(prevWord, output); } prevWord = writtenWord; } } return foundAny; }
public static ITrainingAction ImplementPlan(IPlan plan, WordVectors vectors, ContextMaps maps) { _vectors = vectors; var action = new RootTrainingAction(plan, maps); return action; }
/// <summary> /// Adds a <see cref="PropertyInjectionDirective"/> to the plan for each property /// that should be injected. /// </summary> /// <param name="plan">The plan that is being generated.</param> public void Execute(IPlan plan) { foreach (PropertyInfo property in Selector.SelectPropertiesForInjection(plan.Type)) plan.Add(new PropertyInjectionDirective(property, InjectorFactory.Create(property))); }
public void MoveNode(IPlan newParent, INode child) { RemoveNode(child); AddChildNode(newParent, child); // Since we're moving the node, update it's parent. We don't // always do this on AddChildNode / RemoveNode, because we might // be adding a reference from one node to a node that is already // parented to something else. ((DefaultNode)child).Parent = (INode)newParent; }
public void RemoveChildNode(IPlan parent, INode child) { ((DefaultNode)parent).RemoveChild(child); }
public DefaultContext(IKernel kernel, INode parent, IPlan childToResolve) { Kernel = kernel; Parent = parent; ChildToResolve = childToResolve; }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected virtual void RegisterClassInterceptors( Type type, IPlan plan, IEnumerable<MethodInfo> candidates ) { InterceptAttribute[] attributes = type.GetAllAttributes<InterceptAttribute>(); if ( attributes.Length == 0 ) { return; } foreach ( MethodInfo method in candidates ) { PropertyInfo property = method.GetPropertyFromMethod( type ); ICustomAttributeProvider provider = (ICustomAttributeProvider) property ?? method; if ( !provider.HasAttribute<DoNotInterceptAttribute>() ) { RegisterMethodInterceptors( type, method, attributes ); } } // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } }
private void ProcessElementToPlan(IPlan parentPlan, IPlan rootPlan, XmlElement currentElement, List<IPlan> rootPlans, int depth, Func<IPlan, object, bool> filter) { switch (currentElement.LocalName) { case "gameObjectFolder": { foreach (var childElement in currentElement.ChildNodes.OfType<XmlElement>()) { ProcessElementToPlan(parentPlan, rootPlan, childElement, rootPlans, depth, filter); } break; } case "resource": { // This is used directly by the parent game object. break; } case "gameObject": { Type targetType = null; var xsiType = currentElement.GetAttribute("xsi:type"); if (xsiType == "gameObjectGroupType") { targetType = typeof (EntityGroup); } else if (xsiType == "locatorType") { targetType = typeof (LocatorEntity); } else if (xsiType == "DirLight") { targetType = typeof (DefaultDirectionalLightEntity); } else if (xsiType == "PointLight") { targetType = typeof (DefaultPointLightEntity); } var qualifiedName = currentElement.GetAttribute("qualifiedName"); if (!string.IsNullOrEmpty(qualifiedName)) { targetType = Type.GetType(qualifiedName); } if (targetType == null) { break; } var queryType = typeof (IEditorQuery<>).MakeGenericType(targetType); var plan = _kernel.Plan( targetType, (INode) parentPlan, null, null, (INode) rootPlan, null, null, new Dictionary<Type, List<IMapping>> { { queryType, new List<IMapping> { new DefaultMapping( null, ctx => ResolveEditorQueryForElement(ctx, queryType, targetType, currentElement), false, null, null, true, true, null) } } }); if (filter != null && !filter(plan, currentElement)) { // Discard this plan; it has been filtered out. _kernel.Discard(plan); } else { _hierarchy.AddChildNode(parentPlan, (INode) plan); if (rootPlan == null) { rootPlan = (INode) plan; } if (depth == 0) { rootPlans.Add(plan); } foreach (var childElement in currentElement.ChildNodes.OfType<XmlElement>()) { ProcessElementToPlan(plan, rootPlan, childElement, null, depth + 1, filter); } if (depth > 0) { parentPlan.PlannedCreatedNodes.InsertRange(0, plan.PlannedCreatedNodes); } } break; } } }
public ActivationException(string message, IPlan current) : base(message + " while underneath " + (current == null ? "<root>" : ("'" + current.FullName + "'")) + "") { }
internal static void _LinkDependenciesImpl(IPlan plan, TaskMap<ModuleName, ITarget> taskMap, Application instance, ITargetDescription instanceDescription, CancellationToken token) { foreach (var dependency in instanceDescription.Dependencies) { if (instance.IsLinkedTo(dependency)) continue; var dependencyDescription = plan.TargetDescriptions[dependency]; token.ThrowIfCancellationRequested(); var dependencyInstance = new Application(taskMap[dependency].Value.Result.Module); Application.Link(instance, dependencyInstance); _LinkDependenciesImpl(plan, taskMap, dependencyInstance, dependencyDescription, token); } }
public void Execute(IPlan plan) { if (plan.Has<ConstructorInjectionDirective>()) { var ctor = plan.GetOne<ConstructorInjectionDirective>(); for (int i = 0; i < ctor.Targets.Length; i++) { var prm = ctor.Targets[i] as ParameterTarget; NamedAttribute named = null; if (prm != null && (named = prm.GetCustomAttributes(typeof(NamedAttribute), true) .OfType<NamedAttribute>().FirstOrDefault()) != null) { // Overwrite the target with a named one. // We just replace the target with one that appends the named attribute. ctor.Targets[i] = new ParameterTarget((MethodBase)prm.Member, new NamedParameterInfo(prm.Site, named.Name)); } } } }
/// <summary> /// Registers static interceptors defined by attributes on the class for all candidate /// methods on the class, execept those decorated with a <see cref="DoNotInterceptAttribute"/>. /// </summary> /// <param name="type">The type whose activation plan is being manipulated.</param> /// <param name="plan">The activation plan that is being manipulated.</param> /// <param name="candidates">The candidate methods to intercept.</param> protected override void RegisterClassInterceptors( Type type, IPlan plan, IEnumerable<MethodInfo> candidates ) { NotifyOfChangesAttribute[] attributes = type.GetAllAttributes<NotifyOfChangesAttribute>(); if ( attributes.Length == 0 ) { return; } foreach ( MethodInfo method in candidates ) { if ( !method.HasAttribute<DoNotNotifyOfChangesAttribute>() ) { RegisterMethodInterceptors(type, method, attributes); } } // Indicate that instances of the type should be proxied. if ( !plan.Has<ProxyDirective>() ) { plan.Add( new ProxyDirective() ); } }