Пример #1
0
        /// <summary>
        /// Assigns new rule to mental model (rule list) of current agent. If empty rooms ended, old rules will be removed.
        /// </summary>
        /// <param name="newRule"></param>
        public void AssignNewRule(Rule newRule)
        {
            RuleLayer layer = newRule.Layer;

            Rule[] layerRules = AssignedRules.GroupBy(r => r.Layer).Where(g => g.Key == layer).SelectMany(g => g).ToArray();

            if (layerRules.Length < layer.LayerConfiguration.MaxNumberOfRules)
            {
                AssignedRules.Add(newRule);
                AnticipationInfluence.Add(newRule, new Dictionary <Goal, double>());

                RuleActivationFreshness[newRule] = 0;
            }
            else
            {
                Rule ruleForRemoving = RuleActivationFreshness.Where(kvp => kvp.Key.Layer == layer && kvp.Key.IsAction).GroupBy(kvp => kvp.Value).OrderByDescending(g => g.Key)
                                       .Take(1).SelectMany(g => g.Select(kvp => kvp.Key)).RandomizeOne();

                AssignedRules.Remove(ruleForRemoving);
                AnticipationInfluence.Remove(ruleForRemoving);

                RuleActivationFreshness.Remove(ruleForRemoving);

                AssignNewRule(newRule);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds layer to the rule set.
        /// </summary>
        /// <param name="layer"></param>
        public void Add(RuleLayer layer)
        {
            layerIndexer++;
            layer.Set            = this;
            layer.PositionNumber = layerIndexer;

            Layers.Add(layer);
        }
Пример #3
0
        /// <summary>
        /// Adds rule to rule scope of current prototype if it isn't exists in the scope.
        /// </summary>
        /// <param name="newRule"></param>
        /// <param name="layer"></param>
        public void AddNewRule(Rule newRule, RuleLayer layer)
        {
            if (mentalProto == null)
            {
                TransformRulesToRuleSets();
            }

            layer.Add(newRule);

            Rules.Add(newRule);
        }
Пример #4
0
        /// <summary>
        /// Adds rule to prototype rules and then assign one to the rule list of current agent.
        /// Also copies anticipated influence to the agent.
        /// </summary>
        /// <param name="newRule"></param>
        /// <param name="layer"></param>
        /// <param name="anticipatedInfluence"></param>
        public void AddRule(Rule newRule, RuleLayer layer, Dictionary <Goal, double> anticipatedInfluence)
        {
            Prototype.AddNewRule(newRule, layer);

            AssignNewRule(newRule, anticipatedInfluence);
        }
Пример #5
0
        /// <summary>
        /// Adds rule to prototype rules and then assign one to the rule list of current agent.
        /// </summary>
        /// <param name="newRule"></param>
        /// <param name="layer"></param>
        public void AddRule(Rule newRule, RuleLayer layer)
        {
            Prototype.AddNewRule(newRule, layer);

            AssignNewRule(newRule);
        }