Example #1
0
 public void InitializeModel(bool modelOn, byte randomLevel)
 {
     _cognitiveArchitecture.InternalCharacteristics.CanForget = true;
     _forgetting.On             = modelOn;
     _forgetting.RateOfAgentsOn = 1;
     _forgettingModel           = new ForgettingModel(_agentId, Network.ActorKnowledge, _cognitiveArchitecture,
                                                      _forgetting, true, randomLevel);
     _forgettingModel.InitializeForgettingProcess();
 }
Example #2
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);
 }
Example #3
0
        public Database(GraphMetaNetwork metaNetwork, MainOrganizationModels models, CommunicationTemplate medium,
                        IClassId classId) : base(metaNetwork, classId)
        {
            if (metaNetwork is null)
            {
                throw new ArgumentNullException(nameof(metaNetwork));
            }

            if (models is null)
            {
                throw new ArgumentNullException(nameof(models));
            }

            SetCognitiveArchitecture(medium);
            // There is no random level for database
            _learningModel = new LearningModel(EntityId, models, MetaNetwork.Knowledge, MetaNetwork.ResourceKnowledge,
                                               CognitiveArchitecture, models.Generator, 0);
            _forgettingModel =
                new ForgettingModel(EntityId, MetaNetwork.ResourceKnowledge, CognitiveArchitecture, models, 0);
        }
Example #4
0
        /// <summary>
        ///     Simulate the work on a specific task
        /// </summary>
        /// <param name="task"></param>
        public virtual float WorkOnTask(SymuTask task)
        {
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            float timeSpent;

            if (Schedule.Type == TimeStepType.Intraday)
            {
                timeSpent = Math.Min(Environment.MainOrganization.Models.Intraday, Capacity.Actual);
            }
            else
            {
                timeSpent = Cognitive.TasksAndPerformance.TasksLimit.LimitSimultaneousTasks
                            // Mono tasking
                    ? Math.Min(task.Weight, Capacity.Actual)
                            // Multi tasking
                    : Math.Min(task.Weight / 2, Capacity.Actual);
            }

            timeSpent      = Math.Min(task.WorkToDo, timeSpent);
            task.WorkToDo -= timeSpent;
            if (task.WorkToDo < Tolerance)
            {
                SetTaskDone(task);
            }
            else
            {
                UpdateTask(task);
            }

            // As the agent work on task that requires knowledge, the agent can't forget the associate knowledge today
            ForgettingModel.UpdateForgettingProcess(task.KnowledgesBits);

            Capacity.Decrement(timeSpent);
            return(timeSpent);
        }
Example #5
0
 /// <summary>
 ///     Trigger every event after the actual step,
 ///     Do not send messages
 /// </summary>
 public override void PostStep()
 {
     base.PostStep();
     ForgettingModel?.FinalizeForgettingProcess(Schedule.Step);
 }
Example #6
0
        /// <summary>
        ///     Trigger every event before the new step
        ///     Do not send messages, use NextStep for that
        /// </summary>
        public override async void PreStep()
        {
            MessageProcessor?.ClearMessagesPerPeriod();
            ForgettingModel?.InitializeForgettingProcess();

            // Databases
            if (HasEmail)
            {
                Email.ForgettingProcess(Schedule.Step);
            }

            _newInteractionCounter = 0;

            var isolated = Cognitive.InteractionPatterns.IsIsolated(Schedule.Step);

            HandleStatus(isolated);
            // intentionally after Status
            HandleCapacity(isolated, true);
            // Task manager
            if (!Cognitive.TasksAndPerformance.CanPerformTask)
            {
                return;
            }

            async Task <bool> ProcessWorkInProgress()
            {
                while (Capacity.HasCapacity && Status != AgentStatus.Offline)
                {
                    try
                    {
                        var task = await TaskProcessor.Receive(Schedule.Step).ConfigureAwait(false);

                        switch (task.Parent)
                        {
                        case Message message:
                            // When Schedule.Type is Intraday, messages are treated as tasks and stored in task.Parent attribute
                            // Once a message (as a task) is receive it is treated as a message
                            if (!task.IsStarted)
                            {
                                ActMessage(message);
                            }

                            WorkOnTask(task);
                            break;

                        default:
                            WorkInProgress(task);
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        var exceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception);
                        exceptionDispatchInfo.Throw();
                    }
                }

                // If we didn't deschedule then run the continuation immediately
                return(true);
            }

            await ProcessWorkInProgress().ConfigureAwait(false);

            if (Schedule.Type <= TimeStepType.Daily)
            {
                ActEndOfDay();
            }
        }