public PlanningAction(string name, IEnumerable <IPrecondition> preconditions, IEnumerable <IEffect> effects, double cost) { this.Name = PreconditionUtils.EnsureNotBlank(name, "name"); this.preconditions = new List <IPrecondition>(PreconditionUtils.EnsureNotNull(preconditions, "preconditions")); this.effects = new List <IEffect>(PreconditionUtils.EnsureNotNull(effects, "effects")); this.Cost = cost; }
public GoalSelector(IDictionary <Goal, GoalEvaluator> evaluators, float reevaluationPeriod = DEFAULT_REEVALUATION_PERIOD) { this.evaluators = PreconditionUtils.EnsureNotNull(evaluators, "evaluators"); this.reevaluationPeriod = reevaluationPeriod; this.reevaluationTimer = new ResettableStopwatchExecutionTimer(false); this.ForceReevaluation(); }
//private readonly Func<int, int> effectDeapplication; public SingleSymbolEffect(SymbolId symbolId, Func <int, int> effectApplication /*, Func<int, int> effectDeapplication = null*/) { this.symbolId = symbolId; this.effectApplication = PreconditionUtils.EnsureNotNull(effectApplication, "effectApplication"); // this.effectDeapplication = effectDeapplication == null // ? ((value) => value) // Use identity as default deapplication // : effectDeapplication; }
public static ForwardNode MakeRegularNode(WorldState worldState, INodeExpander <ForwardNode> nodeExpander) { return(new ForwardNode( PreconditionUtils.EnsureNotNull(worldState, "worldState"), PreconditionUtils.EnsureNotNull(nodeExpander, "nodeExpander"), default(Goal), false )); }
public SimpleActionFactory( IDictionary <PlanningAction, Func <IAction> > actionFactories ) { PreconditionUtils.EnsureNotNull(actionFactories, "actionFactories"); this.actionFactories = actionFactories.ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value); SupportedPlanningActions = new HashSet <PlanningAction>(actionFactories.Keys); }
public PlanningAction(string name, IEnumerable <IPrecondition> preconditions, IEnumerable <IEffect> effects, double cost) { IsExperience = false; Name = PreconditionUtils.EnsureNotBlank(name, "name"); Preconditions = new List <IPrecondition>(PreconditionUtils.EnsureNotNull(preconditions, "preconditions")); Effects = new List <IEffect>(PreconditionUtils.EnsureNotNull(effects, "effects")); Cost = cost; }
private GoalSelector(IDictionary <Goal, GoalEvaluator> evaluators, float reevaluationPeriod = DefaultReevaluationPeriod) { this.evaluators = PreconditionUtils.EnsureNotNull(evaluators, "evaluators"); this.reevaluationPeriod = reevaluationPeriod; reevaluationTimer = new ResettableStopwatchExecutionTimer(false); ForceReevaluation(); }
public RelevantSymbolsPopulator(IEnumerable <PlanningAction> availableActions, Goal goal) { this.relevantSymbols = PreconditionUtils.EnsureNotNull(availableActions, "availableActions").Aggregate( new List <SymbolId>(), (soFar, action) => { soFar.AddRange(action.GetRelevantSymbols()); return(soFar); } ).Concat(PreconditionUtils.EnsureNotNull(goal, "goal").PreconditionSymbols); }
public PlanExecutor(IActionFactory actionFactory) { this.actionFactory = PreconditionUtils.EnsureNotNull(actionFactory, "actionFactory"); Status = ExecutionStatus.None; Plan = null; CurrentActionIndex = -1; currentAction = null; }
//public bool AssumeNonNegativeCosts { get; } private AstarPathfinderConfiguration( PathCostHeuristic <GraphNode> heuristic, int maxSearchDepth, float maxSecondsPerSearch //, //bool assumeNonNegativeCosts ) { this.Heuristic = PreconditionUtils.EnsureNotNull(heuristic, "heuristic must not be null"); this.MaxSearchDepth = maxSearchDepth; this.MaxSecondsPerSearch = maxSecondsPerSearch; //this.AssumeNonNegativeCosts = assumeNonNegativeCosts; }
private AStarPathfinderConfiguration( PathCostHeuristic <TGraphNode> heuristic, int maxSearchDepth = UnlimitedSearchDepth, float maxSecondsPerSearch = UnlimitedSecondsPerSearch, bool assumeNonNegativeCosts = DefaultAssumeNonNegativeCosts ) { Heuristic = PreconditionUtils.EnsureNotNull(heuristic, "heuristic must not be null"); MaxSearchDepth = maxSearchDepth; MaxSecondsPerSearch = maxSecondsPerSearch; AssumeNonNegativeCosts = assumeNonNegativeCosts; }
public static RegressiveNode MakeRegular( RegressiveState currentConstraints, WorldState initialState, INodeExpander <RegressiveNode> nodeExpander ) { return(new RegressiveNode( currentConstraints, initialState, PreconditionUtils.EnsureNotNull(nodeExpander, "nodeExpander"), false )); }
private AgentConfiguration( IGoalSelector goalSelector, IPlanner planner, IKnowledgeProvider knowledgeProvider, IPlanExecutor planExecutor, IReevaluationSensor reevaluationSensor = null ) { GoalSelector = PreconditionUtils.EnsureNotNull(goalSelector, "goalSelector"); Planner = PreconditionUtils.EnsureNotNull(planner, "planner"); KnowledgeProvider = PreconditionUtils.EnsureNotNull(knowledgeProvider, "knowledgeProvider"); PlanExecutor = PreconditionUtils.EnsureNotNull(planExecutor, "planExecutor"); ReevaluationSensor = reevaluationSensor ?? new NullReevaluationSensor(); }
// etc. public AgentEnvironment( IGoalSelector goalSelector, IPlanner planner, IKnowledgeProvider knowledgeProvider, IPlanExecutor planExecutor, IReevaluationSensor reevaluationSensor = null ) { this.GoalSelector = PreconditionUtils.EnsureNotNull(goalSelector, "goalSelector"); this.Planner = PreconditionUtils.EnsureNotNull(planner, "planner"); this.KnowledgeProvider = PreconditionUtils.EnsureNotNull(knowledgeProvider, "knowledgeProvider"); this.PlanExecutor = PreconditionUtils.EnsureNotNull(planExecutor, "planExecutor"); this.ReevaluationSensor = reevaluationSensor != null ? reevaluationSensor : new NullReevaluationSensor(); }
public WorldState PopulateWorldState(IKnowledgeProvider knowledgeProvider, WorldState initialWorldState = default(WorldState)) { PreconditionUtils.EnsureNotNull(knowledgeProvider, "knowledgeProvider"); var builder = initialWorldState.BuildUpon(); foreach (var symbolId in relevantSymbols) { if (!initialWorldState.Contains(symbolId)) { builder.SetSymbol(symbolId, knowledgeProvider.GetSymbolValue(symbolId)); } } return(builder.Build()); }
public Plan(IEnumerable<PlanningAction> actions, Goal goal) { var actionList = actions.ToList(); PrintRawPlan(actionList); for (var i = 0; i < actionList.Count; i++) { var action = actionList[i]; if (action.IsExperience) { actionList.Remove(action); actionList.InsertRange(i, ((ExperienceAction) action).Actions); } } Actions = new List<PlanningAction>(PreconditionUtils.EnsureNotNull(actionList, "actions")).AsReadOnly(); Goal = PreconditionUtils.EnsureNotNull(goal, "goal"); }
public SymbolId(string name) { Name = PreconditionUtils.EnsureNotBlank(name, "name"); }
public ForwardEdge(PlanningAction action, ForwardNode sourceNode, ForwardNode targetNode) { this.Action = PreconditionUtils.EnsureNotNull(action, "action"); this.SourceNode = sourceNode; this.TargetNode = targetNode; }
public Plan(IEnumerable <PlanningAction> actions, Goal goal) { this.Actions = new List <PlanningAction>(PreconditionUtils.EnsureNotNull(actions, "actions")).AsReadOnly(); this.Goal = PreconditionUtils.EnsureNotNull(goal, "goal"); }
public void AddSensor(IReevaluationSensor sensor) { sensors.Add(PreconditionUtils.EnsureNotNull(sensor, nameof(sensor))); }
public IEnumerable <IGraphEdge <RegressiveNode> > ExpandNode(RegressiveNode node) { if (PreconditionUtils.EnsureNotNull(node, "node").IsTarget) { throw new InvalidOperationException( string.Format( "{0} cannot expand a target {1}", this.GetType(), node.GetType() ) ); } var result = new List <IGraphEdge <RegressiveNode> >(); foreach (var action in availableActions) { bool incompatible = false; // Whether any effect contradicts existing constraints // TODO: Ensure this is calculated properly. bool useful = false; // Whether any effect affects existing constraints bool deadend = false; // Whether any resulting constraint is unsatisfiable var resultingConstraintsBuilder = node.CurrentConstraints.BuildUpon(); foreach (var effect in action.Effects) { if (effect.ValueAssigned != null) { if (!node.CurrentConstraints[effect.SymbolId].Contains(effect.ValueAssigned.Value)) { // (At least) one of this action's effects contradicts the current constraints, // so this action cannot immediately precede the current node. incompatible = true; break; } else { // If updating the symbol value matters if (!node.CurrentConstraints[effect.SymbolId].Equals(ValueRange.AnyValue)) { // Since the effect resets symbol to a new value, // its value before action is not important // (unless there is a corresponding precondition on the action itself, // but this is checked later) resultingConstraintsBuilder.SetRange(effect.SymbolId, ValueRange.AnyValue); useful = true; } } } else if (effect.ValueDelta != null) { // Shift constraints to account for this effect's contribution into symbol value. resultingConstraintsBuilder.SetRange( effect.SymbolId, node.CurrentConstraints[effect.SymbolId].ShiftBy(-effect.ValueDelta.Value) ); //useful = true; //useful = (useful || resultingConstraintsBuilder[effect.SymbolId].Size > node.CurrentConstraints[effect.SymbolId].Size); // The action is useful if at least one of its effects // shifts at least one of existing constraints // closer to the initial state value for corresponding symbol. useful = ( useful || resultingConstraintsBuilder[effect.SymbolId].AbsDistanceFrom(node.InitialState[effect.SymbolId]) < node.CurrentConstraints[effect.SymbolId].AbsDistanceFrom(node.InitialState[effect.SymbolId]) ); } else { throw new InvalidOperationException( string.Format( "Effect {0} cannot be used with RegressivePlanner: either ValueAssigned or ValueDelta must return non-null", effect.GetType() ) ); } } if (incompatible) { continue; } foreach (var precond in action.Preconditions) { try { resultingConstraintsBuilder.IntersectRange(precond.SymbolId, precond.AsValueRange); // If we've arrived at an unsatisfiable constraint if (resultingConstraintsBuilder[precond.SymbolId].IsEmpty) { deadend = true; break; } } catch (NotImplementedException) { throw new InvalidOperationException( string.Format( "Precondition {0} cannot be used with RegressivePlanner: AsValueRange must be implemented", precond.GetType() ) ); } } if (!incompatible && useful && !deadend) { result.Add( new RegressiveEdge( action, node, RegressiveNode.MakeRegular( resultingConstraintsBuilder.Build(), node.InitialState, this ) ) ); } } return(result); }
protected SingleSymbolEffect(SymbolId symbolId, Func <int, int> effectApplication) { SymbolId = symbolId; this.effectApplication = PreconditionUtils.EnsureNotNull(effectApplication, "effectApplication"); }
public ForwardNodeExpander(IEnumerable <PlanningAction> availableActions) { this.availableActions = PreconditionUtils.EnsureNotNull(availableActions, "availableActions"); }
public ActionGetResource(Townsman subject, ResourceType resource, Storage source) : base(subject) { resourceType = resource; this.source = PreconditionUtils.EnsureNotNull(source, "source"); }
public RegressiveEdge(PlanningAction action, RegressiveNode sourceNode, RegressiveNode targetNode) { Action = PreconditionUtils.EnsureNotNull(action, "action"); SourceNode = sourceNode; TargetNode = targetNode; }
public ActionPutResource(Townsman subject, ResourceType resource, Storage target) : base(subject) { resourceType = resource; this.target = PreconditionUtils.EnsureNotNull(target, "target"); }
public void RemoveSensor(IReevaluationSensor sensor) { sensors.Remove(PreconditionUtils.EnsureNotNull(sensor, nameof(sensor))); }
public ActionGetTool(Townsman subject, ToolType toolType, ToolBench source) : base(subject) { this.toolType = toolType; this.source = PreconditionUtils.EnsureNotNull(source, "source"); }
public Goal(string name, IEnumerable <IPrecondition> preconditions) { Name = PreconditionUtils.EnsureNotBlank(name, "name"); Preconditions = new List <IPrecondition>(PreconditionUtils.EnsureNotNull(preconditions, "preconditions")); }
public ActionPutTool(Townsman subject, ToolType toolType, ToolBench target) : base(subject) { this.toolType = toolType; this.target = PreconditionUtils.EnsureNotNull(target, "target"); }