/// <summary>
        /// Assigns new decision option to mental model of current agent. If empty rooms ended, old decision options will be removed.
        /// </summary>
        /// <param name="newDecisionOption"></param>
        public void AssignNewDecisionOption(DecisionOption newDecisionOption)
        {
            DecisionOptionLayer layer = newDecisionOption.Layer;

            DecisionOption[] layerDecisionOptions = AssignedDecisionOptions.GroupBy(r => r.Layer).Where(g => g.Key == layer).SelectMany(g => g).ToArray();

            if (layerDecisionOptions.Length < layer.LayerConfiguration.MaxNumberOfDecisionOptions)
            {
                AssignedDecisionOptions.Add(newDecisionOption);
                AnticipationInfluence.Add(newDecisionOption, new Dictionary <Goal, double>());

                DecisionOptionActivationFreshness[newDecisionOption] = 0;
            }
            else
            {
                DecisionOption decisionOptionForRemoving = DecisionOptionActivationFreshness.Where(kvp => kvp.Key.Layer == layer).GroupBy(kvp => kvp.Value).OrderByDescending(g => g.Key)
                                                           .Take(1).SelectMany(g => g.Select(kvp => kvp.Key)).RandomizeOne();

                AssignedDecisionOptions.Remove(decisionOptionForRemoving);
                AnticipationInfluence.Remove(decisionOptionForRemoving);

                DecisionOptionActivationFreshness.Remove(decisionOptionForRemoving);

                AssignNewDecisionOption(newDecisionOption);
            }
        }
示例#2
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);
            }
        }