/// <summary>
        /// Creates agent instance based on agent archetype and agent configuration.
        /// </summary>
        /// <param name="agentConfiguration"></param>
        /// <param name="archetype"></param>
        /// <returns></returns>
        public static SosielHarvestAgent Create(
            AgentStateConfiguration agentConfiguration, AgentArchetype archetype, string name)
        {
            var agent = new SosielHarvestAgent();

            agent.Id                      = name;
            agent.Archetype               = archetype;
            agent.privateVariables        = new Dictionary <string, dynamic>(agentConfiguration.PrivateVariables);
            agent.AssignedDecisionOptions = archetype.DecisionOptions.Where(
                r => agentConfiguration.AssignedDecisionOptions.Contains(r.Name)).ToList();
            agent.AssignedGoals = archetype.Goals.Where(
                g => agentConfiguration.AssignedGoals.Contains(g.Name)).ToList();
            agent.AssignedDecisionOptions.ForEach(
                decisionOption => agent.DecisionOptionActivationFreshness.Add(decisionOption, 1));

            // Generates goal importance.
            agentConfiguration.GoalStates.ForEach(kvp =>
            {
                var goalName = kvp.Key;
                var config   = kvp.Value;
                var goal     = agent.AssignedGoals.FirstOrDefault(g => g.Name == goalName);
                if (goal != null)
                {
                    var goalState = new GoalState(goal, agent, config.Value, config.FocalValue, config.Importance,
                                                  config.MinValue, config.MaxValue, config.MinValueReference, config.MaxValueReference);
                    agent.InitialGoalStates.Add(goal, goalState);
                }
            });

            // Initializes initial anticipated influence for each kh and goal assigned to the agent
            agent.AssignedDecisionOptions.ForEach(decisionOption =>
            {
                Dictionary <string, double> source;
                if (decisionOption.AutoGenerated && agent.Archetype.DoNothingAnticipatedInfluence != null)
                {
                    source = agent.Archetype.DoNothingAnticipatedInfluence;
                }
                else
                {
                    agentConfiguration.AnticipatedInfluenceState.TryGetValue(decisionOption.Name, out source);
                }

                var inner = new Dictionary <Goal, double>();
                agent.AssignedGoals.ForEach(g =>
                {
                    inner.Add(g, source != null && source.ContainsKey(g.Name) ? source[g.Name] : 0);
                });

                agent.AnticipationInfluence.Add(decisionOption, inner);
            });

            InitializeDynamicVariables(agent);
            agent.AgentStateConfiguration = agentConfiguration;
            return(agent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates agent instance based on agent prototype and agent configuration
        /// </summary>
        /// <param name="agentConfiguration"></param>
        /// <param name="prototype"></param>
        /// <returns></returns>
        public static Agent CreateAgent(AgentStateConfiguration agentConfiguration, AgentPrototype prototype)
        {
            Agent agent = new Agent();

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

            agent.AssignedRules = prototype.Rules.Where(r => agentConfiguration.AssignedRules.Contains(r.Id)).ToList();
            agent.AssignedGoals = prototype.Goals.Where(g => agentConfiguration.AssignedGoals.Contains(g.Name)).ToList();

            agent.AssignedRules.ForEach(rule => agent.RuleActivationFreshness.Add(rule, 1));


            //initializes initial anticipated influence for each rule and goal assigned to the agent
            agent.AssignedRules.ForEach(r =>
            {
                Dictionary <string, double> source;

                if (r.AutoGenerated && agent.Prototype.DoNothingAnticipatedInfluence != null)
                {
                    source = agent.Prototype.DoNothingAnticipatedInfluence;
                }
                else
                {
                    agentConfiguration.AnticipatedInfluenceState.TryGetValue(r.Id, out source);
                }


                Dictionary <Goal, double> inner = new Dictionary <Goal, double>();

                agent.AssignedGoals.ForEach(g =>
                {
                    inner.Add(g, source != null && source.ContainsKey(g.Name) ? source[g.Name] : 0);
                });

                agent.AnticipationInfluence.Add(r, inner);
            });


            agent.InitialStateConfiguration = agentConfiguration;

            return(agent);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates agent instance based on agent prototype and agent configuration
        /// </summary>
        /// <param name="agentConfiguration"></param>
        /// <param name="prototype"></param>
        /// <returns></returns>
        public static Agent CreateAgent(AgentStateConfiguration agentConfiguration, AgentPrototype prototype)
        {
            Agent agent = new Agent();

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

            agent.AssignedDecisionOptions = prototype.DecisionOptions.Where(r => agentConfiguration.AssignedDecisionOptions.Contains(r.Id)).ToList();
            agent.AssignedGoals           = prototype.Goals.Where(g => agentConfiguration.AssignedGoals.Contains(g.Name)).ToList();

            agent.AssignedDecisionOptions.ForEach(kh => agent.DecisionOptionActivationFreshness.Add(kh, 1));

            //generate goal importance
            agentConfiguration.GoalsState.ForEach(kvp =>
            {
                var goalName      = kvp.Key;
                var configuration = kvp.Value;

                var goal = agent.AssignedGoals.FirstOrDefault(g => g.Name == goalName);
                if (goal == null)
                {
                    return;
                }

                double importance = configuration.Importance;

                if (configuration.Randomness)
                {
                    if (string.IsNullOrEmpty(configuration.BasedOn))
                    {
                        var from = (int)(configuration.RandomFrom * 10);
                        var to   = (int)(configuration.RandomTo * 10);

                        importance = GenerateImportance(agent, configuration.RandomFrom, configuration.RandomTo);
                    }
                    else
                    {
                        var anotherGoalImportance = agent.InitialGoalStates[agent.AssignedGoals.FirstOrDefault(g => g.Name == configuration.BasedOn)]
                                                    .Importance;

                        importance = Math.Round(1 - anotherGoalImportance, 2);
                    }
                }

                GoalState goalState = new GoalState(configuration.Value, goal.FocalValue, importance);

                agent.InitialGoalStates.Add(goal, goalState);

                agent[string.Format("{0}_Importance", goal.Name)] = importance;
            });

            //initializes initial anticipated influence for each kh and goal assigned to the agent
            agent.AssignedDecisionOptions.ForEach(kh =>
            {
                Dictionary <string, double> source;

                if (kh.AutoGenerated && agent.Prototype.DoNothingAnticipatedInfluence != null)
                {
                    source = agent.Prototype.DoNothingAnticipatedInfluence;
                }
                else
                {
                    agentConfiguration.AnticipatedInfluenceState.TryGetValue(kh.Id, out source);
                }


                Dictionary <Goal, double> inner = new Dictionary <Goal, double>();

                agent.AssignedGoals.ForEach(g =>
                {
                    inner.Add(g, source != null && source.ContainsKey(g.Name) ? source[g.Name] : 0);
                });

                agent.AnticipationInfluence.Add(kh, inner);
            });


            InitializeDynamicvariables(agent);

            agent.AgentStateConfiguration = agentConfiguration;

            return(agent);
        }