コード例 #1
0
        public void Initialize()
        {
            _cognitiveArchitecture = new CognitiveArchitecture
            {
                KnowledgeAndBeliefs     = { HasBelief = true, HasKnowledge = true },
                MessageContent          = { CanReceiveBeliefs = true, CanReceiveKnowledge = true },
                InternalCharacteristics = { CanLearn = true, CanForget = true, CanInfluenceOrBeInfluence = true }
            };
            _knowledge = new Knowledge(Network, MainOrganization.Models, "1", 1);
            var modelEntity = new BeliefModelEntity {
                On = true
            };

            _beliefsModel = new BeliefsModel(_agentId, modelEntity, _cognitiveArchitecture, Network,
                                             MainOrganization.Models.Generator);
            _belief = new Belief(Network, 1, RandomGenerator.RandomUniform, BeliefWeightLevel.RandomWeight);
            _beliefBitsNonNeutral =
                _belief.InitializeBits(MainOrganization.Models.Generator, BeliefLevel.NeitherAgreeNorDisagree);
            _beliefBitsNeutral = _belief.InitializeBits(MainOrganization.Models.Generator, BeliefLevel.NoBelief);

            _actorBelief = new ActorBelief(Network.ActorBelief, _agentId, _belief.EntityId, BeliefLevel.NeitherAgreeNorDisagree);

            _taskBits.SetMandatory(new byte[] { 0 });
            _taskBits.SetRequired(new byte[] { 0 });
        }
コード例 #2
0
        /// <summary>
        ///     Missing belief is guessed
        ///     The worker possibly complete the task incorrectly
        ///     and learn by doing
        /// </summary>
        /// <param name="task"></param>
        /// <param name="blocker"></param>
        public void RecoverBlockerIncompleteBeliefByGuessing(SymuTask task, Blocker blocker)
        {
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (blocker == null)
            {
                throw new ArgumentNullException(nameof(blocker));
            }

            RecoverBlockerIncompleteByGuessing(task, blocker, Environment.MainOrganization.Murphies.IncompleteBelief,
                                               BlockerResolution.Guessing);
            if (task.Incorrectness == ImpactLevel.Blocked)
            {
                return;
            }

            var knowledgeId = (IAgentId)blocker.Parameter;
            var beliefBit   = (byte)blocker.Parameter2;
            var beliefId    = BeliefsModel.GetBeliefIdFromKnowledgeId(knowledgeId);

            InfluenceModel.ReinforcementByDoing(beliefId, beliefBit, Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel);
        }
コード例 #3
0
        /// <summary>
        ///     Check a particular beliefId from Task.BeliefBits against Agent.Beliefs
        ///     Prevent the agent from acting on a particular belief
        ///     Task may be blocked if it is the case
        /// </summary>
        public void CheckBlockerIncompleteBelief(SymuTask task, IAgentId knowledgeId)
        {
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (!Environment.MainOrganization.Murphies.IncompleteBelief.On ||
                !Environment.MainOrganization.Models.Beliefs.On)
            {
                return;
            }

            var   taskBits       = task.KnowledgesBits.GetBits(knowledgeId);
            float mandatoryScore = 0;
            float requiredScore  = 0;
            byte  mandatoryIndex = 0;
            byte  requiredIndex  = 0;

            var belief      = BeliefsModel.GetBeliefFromKnowledgeId(knowledgeId);
            var actorBelief = BeliefsModel.GetActorBelief(belief.EntityId);

            Environment.MainOrganization.Murphies.IncompleteBelief.CheckBelief(belief, taskBits, actorBelief,
                                                                               ref mandatoryScore, ref requiredScore,
                                                                               ref mandatoryIndex, ref requiredIndex);
            if (Math.Abs(mandatoryScore + requiredScore) < Tolerance)
            {
                // Check belief is ok
                return;
            }

            CheckBlockerIncompleteBelief(task, knowledgeId, mandatoryScore, requiredScore, mandatoryIndex,
                                         requiredIndex);
        }
コード例 #4
0
 /// <summary>
 ///     Customize the models of the agent
 ///     After setting the Agent basics models
 /// </summary>
 public override void SetModels()
 {
     base.SetModels();
     foreach (var knowledgeId in Environment.MainOrganization.ArtifactNetwork.Knowledge.GetEntityIds())
     {
         KnowledgeModel.AddKnowledge(knowledgeId, KnowledgeLevel.FullKnowledge,
                                     Cognitive.InternalCharacteristics);
         BeliefsModel.AddBeliefFromKnowledgeId(knowledgeId, Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel);
     }
 }
コード例 #5
0
ファイル: InfluenceModelTests.cs プロジェクト: lmorisse/Symu
 public void Initialize()
 {
     MainOrganization.Models.SetOn(1);
     _belief = new Belief(MainOrganization.ArtifactNetwork, 1, RandomGenerator.RandomUniform,
                          BeliefWeightLevel.RandomWeight);
     Environment.SetOrganization(MainOrganization);
     _beliefsModel = new BeliefsModel(_agentId, MainOrganization.Models.Beliefs, _cognitiveArchitecture,
                                      MainOrganization.ArtifactNetwork, MainOrganization.Models.Generator);
     _influenceModel = new InfluenceModel(MainOrganization.Models.Influence, _cognitiveArchitecture, WhitePages,
                                          _beliefsModel, MainOrganization.Models.Generator);
 }
コード例 #6
0
        /// <summary>
        ///     Finalize all the agent's cognitive models
        /// </summary>
        protected override void FinalizeModels()
        {
            base.FinalizeModels();
            if (KnowledgeModel.On)
            {
                KnowledgeModel.InitializeExpertise(Schedule.Step);
                foreach (var knowledgeId in KnowledgeModel.Expertise.Select(x => x.Target))
                {
                    BeliefsModel.AddBeliefFromKnowledgeId(knowledgeId);
                }
            }

            if (BeliefsModel.On)
            {
                BeliefsModel.InitializeBeliefs();
            }
        }
コード例 #7
0
 /// <summary>
 ///     Initialize all the agent's cognitive models
 ///     Should be called after SetTemplate and after having customized the cognitive parameters
 /// </summary>
 protected override void InitializeModels()
 {
     base.InitializeModels();
     // Initialize agent models
     KnowledgeModel = new KnowledgeModel(AgentId, Environment.MainOrganization.Models.Knowledge, Cognitive,
                                         Environment.MainOrganization.ArtifactNetwork, Environment.MainOrganization.Models.Generator);
     BeliefsModel = new BeliefsModel(AgentId, Environment.MainOrganization.Models.Beliefs, Cognitive,
                                     Environment.MainOrganization.ArtifactNetwork, Environment.MainOrganization.Models.Generator);
     LearningModel = new LearningModel(AgentId, Environment.MainOrganization.Models,
                                       Environment.MainOrganization.ArtifactNetwork.Knowledge,
                                       Environment.MainOrganization.ArtifactNetwork.ActorKnowledge, Cognitive,
                                       Environment.MainOrganization.Models.Generator, Environment.RandomLevelValue);
     ForgettingModel = new ForgettingModel(AgentId, Environment.MainOrganization.ArtifactNetwork.ActorKnowledge,
                                           Cognitive, Environment.MainOrganization.Models, Environment.RandomLevelValue);
     InfluenceModel = new InfluenceModel(Environment.MainOrganization.Models.Influence,
                                         Cognitive, Environment.AgentNetwork, BeliefsModel, Environment.MainOrganization.Models.Generator);
     TaskModel = new ActorTaskModel(AgentId, Cognitive, Environment.MainOrganization.ArtifactNetwork);
 }
コード例 #8
0
        /// <summary>
        ///     Check a particular beliefId from Task.BeliefBits against Agent.Beliefs
        ///     Prevent the agent from acting on a particular belief
        ///     Task may be blocked if it is the case
        /// </summary>
        public void CheckRiskAversion(SymuTask task, IAgentId knowledgeId)
        {
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (!BeliefsModel.On)
            {
                return;
            }

            var   taskBits       = task.KnowledgesBits.GetBits(knowledgeId);
            float mandatoryScore = 0;
            byte  mandatoryIndex = 0;

            var belief      = BeliefsModel.GetBeliefFromKnowledgeId(knowledgeId);
            var actorBelief = BeliefsModel.GetActorBelief(knowledgeId);

            MurphyIncompleteBelief.CheckRiskAversion(belief, taskBits, actorBelief, ref mandatoryScore,
                                                     ref mandatoryIndex, -Cognitive.InternalCharacteristics.RiskAversionValue());
            if (!(mandatoryScore <= -Cognitive.InternalCharacteristics.RiskAversionValue()))
            {
                return;
            }

            var murphy = Environment.MainOrganization.Murphies.IncompleteBelief;

            // Prevent the agent from acting on a particular belief
            if (murphy.ShouldGuess((byte)task.HasBeenCancelledBy.Count))
            {
                // to avoid complete blocking, we allow the agent, depending on the Murphies.IncompleteBelief parameters
                // to unblock the task
                var blocker = task.Add(Murphy.IncompleteBelief, Schedule.Step, knowledgeId, mandatoryIndex);
                RecoverBlockerIncompleteBeliefByGuessing(task, blocker);
            }
            else
            {
                // Agent can cancel the task a certain number of times
                TaskProcessor.Cancel(task);
            }
        }