/// <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);
            }
        }
        /// <summary>
        /// Creates copy of current agent, after cloning need to set Id, connected agents don't copied
        /// </summary>
        /// <returns></returns>
        public virtual Agent Clone()
        {
            Agent agent = CreateInstance();

            agent.Archetype        = Archetype;
            agent.privateVariables = new Dictionary <string, dynamic>(privateVariables);

            agent.AssignedGoals           = new List <Goal>(AssignedGoals);
            agent.AssignedDecisionOptions = new List <DecisionOption>(AssignedDecisionOptions);

            //copy ai
            AnticipationInfluence.ForEach(kvp =>
            {
                agent.AnticipationInfluence.Add(kvp.Key, new Dictionary <Goal, double>(kvp.Value));
            });

            agent.DecisionOptionActivationFreshness = new Dictionary <DecisionOption, int>(DecisionOptionActivationFreshness);

            return(agent);
        }
示例#4
0
        /// <summary>
        /// Creates copy of current agent, after cloning need to set Id, connected agents don't copied
        /// </summary>
        /// <returns></returns>
        public Agent Clone()
        {
            Agent agent = new Agent();

            agent.Prototype        = Prototype;
            agent.privateVariables = new Dictionary <string, dynamic>(privateVariables);

            agent.AssignedGoals = new List <Goal>(AssignedGoals);
            agent.AssignedRules = new List <Rule>(AssignedRules);

            //copy ai
            AnticipationInfluence.ForEach(kvp =>
            {
                agent.AnticipationInfluence.Add(kvp.Key, new Dictionary <Goal, double>(kvp.Value));
            });

            agent.RuleActivationFreshness = new Dictionary <Rule, int>(RuleActivationFreshness);

            return(agent);
        }