From 982d0212a0b9e10134ac4f7020f0e6587135ad3d Mon Sep 17 00:00:00 2001 From: lmorisse Date: Tue, 12 May 2020 16:08:39 +0200 Subject: [PATCH] Add SymuGroupAndInteraction project --- CHANGELOG.md | 6 + RELEASENOTES.md | 3 + .../SymuGroupAndInteraction/App.config | 28 + .../Classes/ExampleEnvironment.cs | 116 ++ .../Classes/GroupAgent.cs | 30 + .../Classes/PersonAgent.cs | 83 ++ .../SymuGroupAndInteraction/Home.Designer.cs | 1000 +++++++++++++++++ Symu examples/SymuGroupAndInteraction/Home.cs | 549 +++++++++ .../SymuGroupAndInteraction/Home.resx | 130 +++ .../SymuGroupAndInteraction/Program.cs | 32 + .../Properties/AssemblyInfo.cs | 48 + .../Properties/Resources.Designer.cs | 63 ++ .../Properties/Resources.resx | 117 ++ .../Properties/Settings.Designer.cs | 26 + .../Properties/Settings.settings | 8 + .../SymuGroupAndInteraction.csproj | 158 +++ .../SymuGroupAndInteraction/packages.config | 17 + .../IntegrationTests.cs | 396 +++++++ .../SymuGroupAndInteractionTests.csproj | 20 + .../Classes/ExampleEnvironment.cs | 14 +- .../SymuLearnAndForget/Classes/ExpertAgent.cs | 8 +- .../SymuLearnAndForget/Classes/LearnAgent.cs | 8 +- .../Classes/LearnByAskingAgent.cs | 4 +- .../Classes/LearnByDOingAgent.cs | 2 +- .../Classes/LearnFromSourceAgent.cs | 2 +- Symu examples/SymuLearnAndForget/Home.cs | 84 +- Symu examples/SymuLearnAndForget/Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Properties/Resources.Designer.cs | 2 +- .../IntegrationTests.cs | 68 +- .../Classes/ExampleEnvironment.cs | 6 +- .../SymuMessageAndTask/Classes/GroupAgent.cs | 6 +- .../SymuMessageAndTask/Classes/PersonAgent.cs | 20 +- .../SymuMessageAndTask/Home.Designer.cs | 48 +- Symu examples/SymuMessageAndTask/Home.cs | 56 +- Symu examples/SymuMessageAndTask/Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Properties/Resources.Designer.cs | 2 +- .../IntegrationTests.cs | 88 +- .../SymuMessageAndTaskTests.csproj | 2 +- .../InteractionStrategy.cs | 21 - .../CognitiveArchitecture/InternalPatterns.cs | 155 --- .../Classes/{Agent => Agents}/Agent.cs | 198 +++- .../Classes/{Agent => Agents}/AgentEntity.cs | 4 +- .../Classes/{Agent => Agents}/AgentId.cs | 10 +- .../Classes/{Agent => Agents}/AgentStatus.cs | 4 +- .../{Agent => Agents}/Models/AgentCapacity.cs | 6 +- .../Models/AgentTemplates.cs | 10 +- .../CognitiveArchitecture.cs | 6 +- .../CognitiveArchitecture/ForgettingMode.cs | 4 +- .../CognitiveArchitecture/ForgettingModel.cs | 6 +- .../InteractionCharacteristics.cs | 6 +- .../InteractionPatterns.cs | 375 +++++++ .../InteractionStrategy.cs | 42 + .../InternalCharacteristics.cs | 6 +- .../KnowledgeAndBeliefs.cs | 4 +- .../CognitiveArchitecture/MessageContent.cs | 10 +- .../CognitiveArchitecture/SituationType.cs | 4 +- .../TasksAndPerformance.cs | 24 +- .../{Agent => Agents}/Models/ModelEntity.cs | 6 +- .../CognitiveArchitectureTemplate.cs | 4 +- .../Communication/CommunicationTemplate.cs | 6 +- .../Templates/Communication/EmailTemplate.cs | 6 +- .../Templates/Communication/FaceToFace.cs | 6 +- .../Templates/Communication/IRCTemplate.cs | 6 +- .../Communication/MeetingTemplate.cs | 6 +- .../Templates/Communication/PhoneTemplate.cs | 6 +- .../Communication/ViaPlatformTemplate.cs | 6 +- .../Templates/InternetAccessTemplate.cs | 6 +- .../Models/Templates/SimpleHumanTemplate.cs | 17 +- .../Models/Templates/StandardAgentTemplate.cs | 4 +- .../SymuEngine/Classes/Blockers/Blocker.cs | 2 +- .../SymuEngine/Classes/Blockers/Blockers.cs | 2 +- .../SymuEngine/Classes/Murphies/Murphy.cs | 2 +- .../Murphies/MurphyIncompleteBelief.cs | 6 +- .../Murphies/MurphyIncompleteKnowledge.cs | 6 +- .../Classes/Murphies/MurphyUnavailability.cs | 2 +- .../Organization/InteracionSphereModel.cs | 170 +++ .../Organization/OrganizationEntity.cs | 6 +- .../Organization/OrganizationModels.cs | 17 +- .../Classes/Scenario/ScenarioEntity.cs | 4 +- .../Classes/Scenario/SimulationScenario.cs | 16 +- .../Classes/Scenario/TimeStepScenario.cs | 6 +- .../Task/Knowledge/TaskKnowledgeBits.cs | 2 +- .../Task/Knowledge/TaskKnowledgesBits.cs | 2 +- .../Classes/Task/Manager/TaskEventArgs.cs | 2 +- .../Classes/Task/Manager/TaskProcessor.cs | 2 +- .../Classes/Task/Manager/TasksEventArgs.cs | 2 +- .../Classes/Task/Manager/TasksManager.cs | 6 +- .../SymuEngine/Classes/Task/MurphyTask.cs | 4 +- .../SymuEngine/Classes/Task/SymuTask.cs | 6 +- .../SymuEngine/Classes/Task/TasksLimit.cs | 4 +- .../SymuEngine/Common/AgentState.cs | 2 +- .../SymuEngine/Common/Frequency.cs | 2 +- .../Common/FrequencyLevelService.cs | 22 +- .../SymuEngine/Common/GenericLevel.cs | 2 +- .../SymuEngine/Common/GenericLevelService.cs | 22 +- .../SymuEngine/Common/ImpactLevel.cs | 2 +- .../SymuEngine/Common/RandomGenerator.cs | 2 +- .../SymuEngine/Engine/Form/SymuForm.cs | 3 +- .../SymuEngine/Engine/Iterations.cs | 2 +- .../SymuEngine/Engine/SimulationEngine.cs | 9 +- .../SymuEngine/Engine/SimulationEngines.cs | 2 +- .../SymuEngine/Engine/SimulationRandom.cs | 2 +- .../Environment/EnvironmentState.cs | 4 +- .../SymuEngine/Environment/SymuEnvironment.cs | 48 +- .../SymuEngine/Environment/TimeStep.cs | 2 +- .../SymuEngine/Environment/TimeStepType.cs | 2 +- .../Environment/TimeStepTypeService.cs | 64 ++ .../Messaging/Delayed/DelayedMessages.cs | 17 +- .../Manager/AsyncMessageProcessor.cs | 2 +- .../Messaging/Manager/MessageEventArgs.cs | 7 +- .../Messaging/Manager/MessageProcessor.cs | 35 +- .../Messaging/Manager/MessagesManager.cs | 15 +- .../CommunicationMediums.cs | 4 +- .../CommunicationMediumsModel.cs | 6 +- .../{Message => Messages}/Message.cs | 6 +- .../{Message => Messages}/MessageAction.cs | 4 +- .../MessageAttachments.cs | 4 +- .../{Message => Messages}/MessageState.cs | 4 +- .../Messaging/Reply/WaitingMessageSent.cs | 7 +- .../Messaging/Reply/WaitingMessagesSent.cs | 2 +- .../Messaging/Reply/WaitingReplies.cs | 2 +- .../Messaging/Reply/WaitingReply.cs | 2 +- .../Subscription/MessageSubscription.cs | 4 +- .../Subscription/MessageSubscriptions.cs | 4 +- .../SymuEngine/Repository/ConcurrentAgents.cs | 4 +- .../Networks/Activities/Activity.cs | 2 +- .../Networks/Activities/AgentActivity.cs | 4 +- .../Networks/Activities/NetworkActivities.cs | 37 +- .../Networks/Beliefs/AgentBelief.cs | 6 +- .../Networks/Beliefs/AgentBeliefs.cs | 12 +- .../Repository/Networks/Beliefs/Belief.cs | 4 +- .../Networks/Beliefs/BeliefCollection.cs | 2 +- .../Networks/Beliefs/NetworkBeliefs.cs | 14 +- .../Communication/NetworkCommunications.cs | 12 +- .../Repository/Networks/Databases/Database.cs | 4 +- .../Networks/Databases/DatabaseCollection.cs | 2 +- .../Networks/Databases/NetworkDatabases.cs | 4 +- .../Enculturation/NetworkEnculturation.cs | 4 +- .../Networks/Group/GroupAllocation.cs | 4 +- .../Networks/Group/NetworkGroups.cs | 37 +- .../Networks/Influences/Influence.cs | 4 +- .../Networks/Influences/NetworkInfluences.cs | 4 +- .../Networks/Knowledges/AgentExpertise.cs | 2 +- .../Networks/Knowledges/AgentKnowledge.cs | 12 +- .../Repository/Networks/Knowledges/Bits.cs | 35 +- .../Networks/Knowledges/Knowledge.cs | 6 +- .../Networks/Knowledges/KnowledgeBits.cs | 3 +- .../Knowledges/KnowledgeCollection.cs | 2 +- .../Networks/Knowledges/KnowledgeLevel.cs | 2 +- .../Knowledges/KnowledgeLevelService.cs | 22 +- .../Networks/Knowledges/KnowledgeMatrix.cs | 370 ------ .../Networks/Knowledges/NetworkKnowledges.cs | 4 +- .../Networks/Link/CommunicationLink.cs | 63 -- .../Networks/Link/CommunicationType.cs | 24 - .../Repository/Networks/Link/NetworkLink.cs | 82 +- .../Networks/Link/NetworkLinkState.cs | 20 - .../Repository/Networks/Link/NetworkLinks.cs | 124 +- .../SymuEngine/Repository/Networks/Network.cs | 55 +- .../Networks/Portfolio/NetworkPortfolio.cs | 4 +- .../Networks/Portfolio/NetworkPortfolios.cs | 4 +- .../Repository/Networks/Role/NetworkRole.cs | 4 +- .../Repository/Networks/Role/NetworkRoles.cs | 4 +- .../Networks/Sphere/DerivedParameter.cs | 80 ++ .../Networks/Sphere/InteractionMatrix.cs | 132 +++ .../Networks/Sphere/InteractionSphere.cs | 521 +++++++++ .../SymuEngine/Repository/SymuYellowPages.cs | 2 +- .../SymuEngine/Repository/WhitePages.cs | 20 +- .../Results/Blocker/BlockerResolution.cs | 2 +- .../Results/Blocker/BlockerResult.cs | 2 +- .../Results/Blocker/BlockerResults.cs | 5 +- .../SymuEngine/Results/IterationResult.cs | 2 +- .../Organization/GroupDensityStruct.cs | 55 + .../Organization/KnowledgeAndBeliefStruct.cs | 2 +- .../Organization/OrganizationFlexibility.cs | 64 +- .../OrganizationKnowledgeAndBelief.cs | 2 +- .../Results/Organization/TriadsStruct.cs | 39 - .../SymuEngine/Results/PostProcessResult.cs | 2 +- .../SymuEngine/Results/SimulationResults.cs | 2 +- .../SymuEngine/Results/Task/TaskResult.cs | 2 +- .../SymuEngine/Results/Task/TaskResults.cs | 4 +- .../Classes/{Agent => Agents}/AgentTests.cs | 161 ++- .../ForgettingModelTests.cs | 19 +- .../InteractionPatternsTests.cs | 12 +- .../InternalCharacteristicsTests.cs | 13 +- .../KnowledgeAndBeliefsTests.cs | 13 +- .../MessageContentTests.cs | 8 +- .../TasksAndPerformanceTests.cs | 13 +- .../Models/ModelEntityTests.cs | 6 +- .../Classes/Blockers/BlockerTests.cs | 2 +- .../Classes/Blockers/BlockersTests.cs | 2 +- .../Murphy/MurphyIncompleteBeliefTests.cs | 4 +- .../Murphy/MurphyIncompleteKnowledgeTests.cs | 2 +- .../Murphy/MurphyUnAvailabilityTests.cs | 2 +- .../Task/Knowledge/TaskKnowledgeBitsTests.cs | 2 +- .../Classes/Task/Manager/TasksManagerTests.cs | 4 +- .../Classes/Task/MasTaskTests.cs | 4 +- .../Classes/Task/TasksLimitTests.cs | 2 +- .../Environment/EnvironmentStateTests.cs | 4 +- .../Environment/SymuEnvironmentTests.cs | 4 +- .../Environment/TimeStep/TimeStepTests.cs | 2 +- .../SymuEngineTests/Helpers/TestAgent.cs | 9 +- .../Helpers/TestEnvironment.cs | 5 +- .../Messaging/Delayed/DelayedMessagesTests.cs | 18 +- .../Manager/MessageProcessorTests.cs | 12 +- .../Message/CommunicationMediumsModelTests.cs | 4 +- .../Message/MessageTypesToolsTests.cs | 4 +- .../Reply/AgentWaitingRepliesTests.cs | 2 +- .../Networks/Activities/ActivityTests.cs | 2 +- .../Activities/NetworkActivitiesTests.cs | 78 +- .../Networks/Beliefs/AgentBeliefTests.cs | 2 +- .../Networks/Beliefs/AgentBeliefsTests.cs | 3 +- .../Networks/Beliefs/BeliefCollectionTests.cs | 2 +- .../Networks/Beliefs/BeliefTests.cs | 2 +- .../Networks/Beliefs/NetworkBeliefsTests.cs | 14 +- .../Databases/DatabaseCollectionTests.cs | 4 +- .../Networks/Databases/DatabaseTests.cs | 4 +- .../Databases/NetworkDatabasesTests.cs | 6 +- .../NetworkEnculturationTests.cs | 4 +- .../Networks/Group/NetworkGroupsTests.cs | 67 +- .../Influences/NetworkInfluencesTests.cs | 4 +- .../Knowledges/AgentExpertiseTests.cs | 2 +- .../Knowledges/AgentKnowledgeTests.cs | 17 +- .../Networks/Knowledges/BitsTests.cs | 13 +- .../Networks/Knowledges/KnowledgeBitsTests.cs | 3 +- .../Knowledges/KnowledgeCollectionTests.cs | 2 +- .../Knowledges/KnowledgeMatrixTests.cs | 253 ----- .../Networks/Knowledges/KnowledgeTests.cs | 4 +- .../Knowledges/NetworkKnowledgesTests.cs | 4 +- .../Networks/Link/NetworkLinkTests.cs | 20 +- .../Networks/Link/NetworkLinksTests.cs | 186 ++- .../Repository/Networks/NetworkTests.cs | 36 +- .../Portfolio/NetworkPortfolioTests.cs | 4 +- .../Portfolio/NetworkPortfoliosTests.cs | 4 +- .../Networks/Role/NetworkRoleTests.cs | 4 +- .../Networks/Role/NetworkRolesTests.cs | 4 +- .../Networks/Sphere/InteractionMatrixTests.cs | 196 ++++ .../Networks/Sphere/InteractionSphereTests.cs | 369 ++++++ .../Repository/WhitePagesTests.cs | 32 +- .../OrganizationKnowledgeAndBeliefTests.cs | 8 +- .../organizationFlexibilityTests.cs | 99 +- .../SymuTools/Algorithm/SpecialFunctions.cs | 29 - .../SymuTools/{Algorithm => }/Constants.cs | 4 +- Symu source code/SymuTools/List.cs | 6 +- .../SymuTools/Math/Combinatorics.cs | 36 + .../MachineLearning/LinearRegression.cs | 10 +- .../ProbabilityDistributions/Bernoulli.cs | 8 +- .../ProbabilityDistributions/Categorical.cs | 61 +- .../ContinuousUniform.cs | 9 +- .../DiscreteUniform.cs | 15 +- .../ProbabilityDistributions/Normal.cs | 10 +- Symu source code/SymuToolsTests/ListTests.cs | 2 +- .../MachineLearning/LinearRegressionTests.cs | 4 +- .../BernoulliTests.cs | 4 +- .../CategoricalTests.cs | 17 +- .../ContinuousUniformTests.cs | 13 +- .../DiscreteUniformTests.cs | 6 +- .../ProbabilityDistributions/NormalTests.cs | 4 +- .../Serialization/SerializationTests.cs | 2 +- 260 files changed, 6650 insertions(+), 2133 deletions(-) create mode 100644 Symu examples/SymuGroupAndInteraction/App.config create mode 100644 Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Home.Designer.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Home.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Home.resx create mode 100644 Symu examples/SymuGroupAndInteraction/Program.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Properties/AssemblyInfo.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Properties/Resources.Designer.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Properties/Resources.resx create mode 100644 Symu examples/SymuGroupAndInteraction/Properties/Settings.Designer.cs create mode 100644 Symu examples/SymuGroupAndInteraction/Properties/Settings.settings create mode 100644 Symu examples/SymuGroupAndInteraction/SymuGroupAndInteraction.csproj create mode 100644 Symu examples/SymuGroupAndInteraction/packages.config create mode 100644 Symu examples/SymuGroupAndInteractionTests/IntegrationTests.cs create mode 100644 Symu examples/SymuGroupAndInteractionTests/SymuGroupAndInteractionTests.csproj delete mode 100644 Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionStrategy.cs delete mode 100644 Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalPatterns.cs rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Agent.cs (88%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/AgentEntity.cs (96%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/AgentId.cs (87%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/AgentStatus.cs (90%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/AgentCapacity.cs (92%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/AgentTemplates.cs (78%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/CognitiveArchitecture.cs (95%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/ForgettingMode.cs (84%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/ForgettingModel.cs (98%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/InteractionCharacteristics.cs (97%) create mode 100644 Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionPatterns.cs create mode 100644 Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionStrategy.cs rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/InternalCharacteristics.cs (98%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs (99%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/MessageContent.cs (97%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/SituationType.cs (74%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/CognitiveArchitecture/TasksAndPerformance.cs (95%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/ModelEntity.cs (95%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/CognitiveArchitectureTemplate.cs (90%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/CommunicationTemplate.cs (97%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/EmailTemplate.cs (89%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/FaceToFace.cs (88%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/IRCTemplate.cs (89%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/MeetingTemplate.cs (88%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/PhoneTemplate.cs (88%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/Communication/ViaPlatformTemplate.cs (89%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/InternetAccessTemplate.cs (95%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/SimpleHumanTemplate.cs (82%) rename Symu source code/SymuEngine/Classes/{Agent => Agents}/Models/Templates/StandardAgentTemplate.cs (80%) create mode 100644 Symu source code/SymuEngine/Classes/Organization/InteracionSphereModel.cs create mode 100644 Symu source code/SymuEngine/Environment/TimeStepTypeService.cs rename Symu source code/SymuEngine/Messaging/{Message => Messages}/CommunicationMediums.cs (93%) rename Symu source code/SymuEngine/Messaging/{Message => Messages}/CommunicationMediumsModel.cs (95%) rename Symu source code/SymuEngine/Messaging/{Message => Messages}/Message.cs (98%) rename Symu source code/SymuEngine/Messaging/{Message => Messages}/MessageAction.cs (87%) rename Symu source code/SymuEngine/Messaging/{Message => Messages}/MessageAttachments.cs (96%) rename Symu source code/SymuEngine/Messaging/{Message => Messages}/MessageState.cs (89%) delete mode 100644 Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeMatrix.cs delete mode 100644 Symu source code/SymuEngine/Repository/Networks/Link/CommunicationLink.cs delete mode 100644 Symu source code/SymuEngine/Repository/Networks/Link/CommunicationType.cs delete mode 100644 Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinkState.cs create mode 100644 Symu source code/SymuEngine/Repository/Networks/Sphere/DerivedParameter.cs create mode 100644 Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionMatrix.cs create mode 100644 Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionSphere.cs create mode 100644 Symu source code/SymuEngine/Results/Organization/GroupDensityStruct.cs delete mode 100644 Symu source code/SymuEngine/Results/Organization/TriadsStruct.cs rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/AgentTests.cs (88%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/ForgettingModelTests.cs (95%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/InteractionPatternsTests.cs (79%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs (87%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs (96%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/MessageContentTests.cs (97%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs (96%) rename Symu source code/SymuEngineTests/Classes/{Agent => Agents}/Models/ModelEntityTests.cs (92%) delete mode 100644 Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeMatrixTests.cs create mode 100644 Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionMatrixTests.cs create mode 100644 Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionSphereTests.cs delete mode 100644 Symu source code/SymuTools/Algorithm/SpecialFunctions.cs rename Symu source code/SymuTools/{Algorithm => }/Constants.cs (84%) create mode 100644 Symu source code/SymuTools/Math/Combinatorics.cs rename Symu source code/SymuTools/{ => Math}/MachineLearning/LinearRegression.cs (97%) rename Symu source code/SymuTools/{ => Math}/ProbabilityDistributions/Bernoulli.cs (88%) rename Symu source code/SymuTools/{ => Math}/ProbabilityDistributions/Categorical.cs (58%) rename Symu source code/SymuTools/{ => Math}/ProbabilityDistributions/ContinuousUniform.cs (92%) rename Symu source code/SymuTools/{ => Math}/ProbabilityDistributions/DiscreteUniform.cs (89%) rename Symu source code/SymuTools/{ => Math}/ProbabilityDistributions/Normal.cs (86%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab4c91d..699c7bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.4.0 [☰](https://github.com/lmorisse/symu/compare/v0.4.0..v0.3.0) +* Add new project example: [SymuGroupAndInteraction](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuGroupAndInteraction) by [@lmorisse] +* Add new project example: [SymuGroupAndInteractionTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuGroupAndInteractionTests) by [@lmorisse] +* SymuEngine - add InteractionSphereModel by [@lmorisse] +* SymuEngine - update InteractionPatterns by [@lmorisse] + ## 0.3.0 [☰](https://github.com/lmorisse/symu/compare/v0.3.0..v0.2.0) * Add new project example: [SymuMessageAndTask](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMessageAndTask) by [@lmorisse] * Add new project example: [SymuMessageAndTaskTest](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMessageAndTaskTests) by [@lmorisse] diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3bb00d77..7210b566 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,8 @@ # Release notes +## 0.4.0 +This release contains a new project example: [SymuGroupAndInteraction](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuGroupAndInteraction). + ## 0.3.0 This release contains a new project example: [SymuMessageAndTask](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMessageAndTask). diff --git a/Symu examples/SymuGroupAndInteraction/App.config b/Symu examples/SymuGroupAndInteraction/App.config new file mode 100644 index 00000000..96570b4b --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/App.config @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs b/Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs new file mode 100644 index 00000000..7aefe877 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs @@ -0,0 +1,116 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System.Collections.Generic; +using SymuEngine.Classes.Agents; +using SymuEngine.Common; +using SymuEngine.Environment; +using SymuEngine.Repository.Networks.Knowledges; +using SymuTools.Math.ProbabilityDistributions; + +#endregion + +namespace SymuGroupAndInteraction.Classes +{ + public class ExampleEnvironment : SymuEnvironment + { + public byte GroupsCount { get; set; } = 2; + public byte WorkersCount { get; set; } = 5; + public byte Knowledge { get; set; } = 0; + public byte Activities { get; set; } = 0; + public KnowledgeLevel KnowledgeLevel { get; set; } = KnowledgeLevel.FullKnowledge; + + public override void SetModelForAgents() + { + base.SetModelForAgents(); + Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationIsRandom = false; + Organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + Organization.Models.FollowGroupFlexibility = true; + Organization.Models.InteractionSphere.SphereUpdateOverTime = true; + Organization.Models.InteractionSphere.On = true; + var knowledges = new List(); + var activities = new List(); + for (var i = 0; i < GroupsCount; i++) + { + // knowledge length of 10 is arbitrary in this example + var knowledge = new Knowledge((ushort) i, i.ToString(), 10); + WhitePages.Network.AddKnowledge(knowledge); + knowledges.Add(knowledge); + activities.Add(i.ToString()); + //Beliefs are created based on knowledge + } + + for (var i = 0; i < GroupsCount; i++) + { + var group = new GroupAgent(Organization.NextEntityIndex(), this); + + for (var j = 0; j < WorkersCount; j++) + { + var actor = new PersonAgent(Organization.NextEntityIndex(), this) + { + GroupId = group.Id + }; + WhitePages.Network.AddMemberToGroup(actor.Id, 100, group.Id); + //Beliefs are added with knowledge + SetKnowledge(actor, knowledges, i); + SetActivity(actor.Id, activities, i, group.Id); + } + } + } + + private void SetKnowledge(Agent actor, IReadOnlyList knowledges, int i) + { + switch (Knowledge) + { + case 0: + // same Knowledge for all + actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[0], + KnowledgeLevel, + Organization.Templates.Human.Cognitive.InternalCharacteristics); + + break; + case 1: + // Knowledge is by group + actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[i], + KnowledgeLevel, + Organization.Templates.Human.Cognitive.InternalCharacteristics); + break; + case 2: + // Knowledge is randomly defined for agentId + var index = DiscreteUniform.Sample(0, GroupsCount - 1); + actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[index], + KnowledgeLevel, + Organization.Templates.Human.Cognitive.InternalCharacteristics); + break; + } + } + + private void SetActivity(AgentId agentId, IReadOnlyList activities, int i, AgentId groupId) + { + switch (Activities) + { + case 0: + // same activity for all + WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[0], groupId); + break; + case 1: + // Activity is by group + WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[i], groupId); + break; + case 2: + // Activity is randomly defined for agentId + var index = DiscreteUniform.Sample(0, GroupsCount - 1); + WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[index], groupId); + break; + } + } + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs b/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs new file mode 100644 index 00000000..b329f639 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs @@ -0,0 +1,30 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using SymuEngine.Classes.Agents; +using SymuEngine.Environment; + +#endregion + +namespace SymuGroupAndInteraction.Classes +{ + public sealed class GroupAgent : Agent + { + public const byte ClassKey = 1; + + public GroupAgent(ushort agentKey, SymuEnvironment environment) : base( + new AgentId(agentKey, ClassKey), + environment) + { + SetCognitive(Environment.Organization.Templates.Standard); + } + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs b/Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs new file mode 100644 index 00000000..00cbbe5c --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs @@ -0,0 +1,83 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuEngine.Classes.Agents; +using SymuEngine.Environment; +using SymuEngine.Messaging.Messages; +using SymuEngine.Repository; + +#endregion + +namespace SymuGroupAndInteraction.Classes +{ + public sealed class PersonAgent : Agent + { + public const byte ClassKey = SymuYellowPages.Actor; + + public PersonAgent(ushort agentKey, SymuEnvironment environment) : base( + new AgentId(agentKey, ClassKey), + environment) + { + SetCognitive(Environment.Organization.Templates.Human); + // Communication medium + Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = + CommunicationMediums.FaceToFace; + } + + /// + /// Agent is member of a group + /// + public AgentId GroupId { get; set; } + + + protected override void ActClassKey(Message message) + { + if (message is null) + { + throw new ArgumentNullException(nameof(message)); + } + + base.ActClassKey(message); + switch (message.Subject) + { + case SymuYellowPages.Actor: + ActActor(message); + break; + } + } + + private void ActActor(Message message) + { + switch (message.Action) + { + case MessageAction.Ask: + AskActor(message); + break; + } + } + + private void AskActor(Message message) + { + // New interaction has already been accepted + // Let's reply positively + var reply = Message.ReplyMessage(message); + Send(reply); + } + + public override void ActEndOfDay() + { + base.ActEndOfDay(); + // Time for a coffee break and have interaction with other agents + Send(GroupId, MessageAction.Stop, SymuYellowPages.WorkingDay, CommunicationMediums.FaceToFace); + } + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Home.Designer.cs b/Symu examples/SymuGroupAndInteraction/Home.Designer.cs new file mode 100644 index 00000000..db3a78ed --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Home.Designer.cs @@ -0,0 +1,1000 @@ +namespace SymuGroupAndInteraction +{ + partial class Home + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Home)); + this.btnStart = new System.Windows.Forms.Button(); + this.btnStop = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.TimeStep = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.NotAcceptedMessages = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); + this.lblMessagesSent = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.label29 = new System.Windows.Forms.Label(); + this.SphereDensity = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.Triads = new System.Windows.Forms.Label(); + this.InteractionSphereCount = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.tbWorkers = new System.Windows.Forms.TextBox(); + this.btnResume = new System.Windows.Forms.Button(); + this.btnPause = new System.Windows.Forms.Button(); + this.richTextBox2 = new System.Windows.Forms.RichTextBox(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.groupBox9 = new System.Windows.Forms.GroupBox(); + this.label28 = new System.Windows.Forms.Label(); + this.label27 = new System.Windows.Forms.Label(); + this.WeightBeliefs = new System.Windows.Forms.TextBox(); + this.label14 = new System.Windows.Forms.Label(); + this.WeightGroups = new System.Windows.Forms.TextBox(); + this.label23 = new System.Windows.Forms.Label(); + this.WeightKnowledge = new System.Windows.Forms.TextBox(); + this.label24 = new System.Windows.Forms.Label(); + this.WeightActivities = new System.Windows.Forms.TextBox(); + this.label25 = new System.Windows.Forms.Label(); + this.label26 = new System.Windows.Forms.Label(); + this.RadomlyGenerated = new System.Windows.Forms.RadioButton(); + this.SimilarityMatching = new System.Windows.Forms.RadioButton(); + this.MaxSphereDensity = new System.Windows.Forms.TextBox(); + this.label21 = new System.Windows.Forms.Label(); + this.MinSphereDensity = new System.Windows.Forms.TextBox(); + this.label22 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.ActivitiesRandom = new System.Windows.Forms.RadioButton(); + this.ActivitiesByGroup = new System.Windows.Forms.RadioButton(); + this.ActivitiesSame = new System.Windows.Forms.RadioButton(); + this.groupBox12 = new System.Windows.Forms.GroupBox(); + this.label16 = new System.Windows.Forms.Label(); + this.cbInitialKnowledgeLevel = new System.Windows.Forms.ComboBox(); + this.label12 = new System.Windows.Forms.Label(); + this.KnowledgeRandom = new System.Windows.Forms.RadioButton(); + this.KnowledgeByGroup = new System.Windows.Forms.RadioButton(); + this.KnowledgeSame = new System.Windows.Forms.RadioButton(); + this.groupBox7 = new System.Windows.Forms.GroupBox(); + this.Homophily = new System.Windows.Forms.CheckBox(); + this.AllowNewInteractions = new System.Windows.Forms.CheckBox(); + this.InteractionBeliefs = new System.Windows.Forms.TextBox(); + this.label11 = new System.Windows.Forms.Label(); + this.InteractionSocialDemographics = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.MaxDailyInteractions = new System.Windows.Forms.TextBox(); + this.label17 = new System.Windows.Forms.Label(); + this.InteractionKnowledge = new System.Windows.Forms.TextBox(); + this.label20 = new System.Windows.Forms.Label(); + this.InteractionActivities = new System.Windows.Forms.TextBox(); + this.label15 = new System.Windows.Forms.Label(); + this.ThresholdFornewInteraction = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); + this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.GroupsCount = new System.Windows.Forms.TextBox(); + this.label13 = new System.Windows.Forms.Label(); + this.tbSteps = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.groupBox1.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.groupBox5.SuspendLayout(); + this.groupBox4.SuspendLayout(); + this.groupBox9.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.groupBox12.SuspendLayout(); + this.groupBox7.SuspendLayout(); + this.groupBox6.SuspendLayout(); + this.SuspendLayout(); + // + // btnStart + // + this.btnStart.Location = new System.Drawing.Point(32, 34); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(75, 23); + this.btnStart.TabIndex = 0; + this.btnStart.Text = "Start"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.Button1_Click); + // + // btnStop + // + this.btnStop.Location = new System.Drawing.Point(32, 63); + this.btnStop.Name = "btnStop"; + this.btnStop.Size = new System.Drawing.Size(75, 23); + this.btnStop.TabIndex = 1; + this.btnStop.Text = "Stop"; + this.btnStop.UseVisualStyleBackColor = true; + this.btnStop.Click += new System.EventHandler(this.Button2_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(253, 40); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 17); + this.label1.TabIndex = 2; + this.label1.Text = "Steps"; + // + // TimeStep + // + this.TimeStep.AutoSize = true; + this.TimeStep.Location = new System.Drawing.Point(316, 40); + this.TimeStep.Name = "TimeStep"; + this.TimeStep.Size = new System.Drawing.Size(16, 17); + this.TimeStep.TabIndex = 3; + this.TimeStep.Text = "0"; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.NotAcceptedMessages); + this.groupBox1.Controls.Add(this.label18); + this.groupBox1.Controls.Add(this.lblMessagesSent); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Location = new System.Drawing.Point(32, 116); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(305, 110); + this.groupBox1.TabIndex = 4; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Messages"; + // + // NotAcceptedMessages + // + this.NotAcceptedMessages.AutoSize = true; + this.NotAcceptedMessages.Location = new System.Drawing.Point(224, 62); + this.NotAcceptedMessages.Name = "NotAcceptedMessages"; + this.NotAcceptedMessages.Size = new System.Drawing.Size(16, 17); + this.NotAcceptedMessages.TabIndex = 8; + this.NotAcceptedMessages.Text = "0"; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(24, 62); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(198, 17); + this.label18.TabIndex = 7; + this.label18.Text = "New interactions not accepted"; + // + // lblMessagesSent + // + this.lblMessagesSent.AutoSize = true; + this.lblMessagesSent.Location = new System.Drawing.Point(223, 30); + this.lblMessagesSent.Name = "lblMessagesSent"; + this.lblMessagesSent.Size = new System.Drawing.Size(16, 17); + this.lblMessagesSent.TabIndex = 6; + this.lblMessagesSent.Text = "0"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(24, 30); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(103, 17); + this.label3.TabIndex = 5; + this.label3.Text = "Messages sent"; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.label29); + this.groupBox3.Controls.Add(this.SphereDensity); + this.groupBox3.Controls.Add(this.label19); + this.groupBox3.Controls.Add(this.label5); + this.groupBox3.Controls.Add(this.label4); + this.groupBox3.Controls.Add(this.Triads); + this.groupBox3.Controls.Add(this.InteractionSphereCount); + this.groupBox3.Controls.Add(this.label8); + this.groupBox3.Location = new System.Drawing.Point(32, 251); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(305, 161); + this.groupBox3.TabIndex = 9; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Organization flexibility"; + // + // label29 + // + this.label29.AutoSize = true; + this.label29.Location = new System.Drawing.Point(26, 95); + this.label29.Name = "label29"; + this.label29.Size = new System.Drawing.Size(134, 17); + this.label29.TabIndex = 21; + this.label29.Text = "Sphere total density"; + // + // SphereDensity + // + this.SphereDensity.AutoSize = true; + this.SphereDensity.Location = new System.Drawing.Point(224, 95); + this.SphereDensity.Name = "SphereDensity"; + this.SphereDensity.Size = new System.Drawing.Size(16, 17); + this.SphereDensity.TabIndex = 22; + this.SphereDensity.Text = "0"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(256, 37); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(20, 17); + this.label19.TabIndex = 20; + this.label19.Text = "%"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(256, 67); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(20, 17); + this.label5.TabIndex = 19; + this.label5.Text = "%"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(26, 67); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(97, 17); + this.label4.TabIndex = 17; + this.label4.Text = "Triads density"; + // + // Triads + // + this.Triads.AutoSize = true; + this.Triads.Location = new System.Drawing.Point(224, 67); + this.Triads.Name = "Triads"; + this.Triads.Size = new System.Drawing.Size(16, 17); + this.Triads.TabIndex = 18; + this.Triads.Text = "0"; + // + // InteractionSphereCount + // + this.InteractionSphereCount.AutoSize = true; + this.InteractionSphereCount.Location = new System.Drawing.Point(224, 37); + this.InteractionSphereCount.Name = "InteractionSphereCount"; + this.InteractionSphereCount.Size = new System.Drawing.Size(16, 17); + this.InteractionSphereCount.TabIndex = 6; + this.InteractionSphereCount.Text = "0"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(26, 37); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(90, 17); + this.label8.TabIndex = 5; + this.label8.Text = "Links density"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(25, 60); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(193, 17); + this.label2.TabIndex = 7; + this.label2.Text = "Number of workers per group"; + // + // tbWorkers + // + this.tbWorkers.Location = new System.Drawing.Point(242, 55); + this.tbWorkers.Name = "tbWorkers"; + this.tbWorkers.Size = new System.Drawing.Size(87, 22); + this.tbWorkers.TabIndex = 10; + this.tbWorkers.Text = "5"; + this.tbWorkers.TextChanged += new System.EventHandler(this.tbWorkers_TextChanged); + // + // btnResume + // + this.btnResume.Location = new System.Drawing.Point(119, 63); + this.btnResume.Name = "btnResume"; + this.btnResume.Size = new System.Drawing.Size(75, 23); + this.btnResume.TabIndex = 12; + this.btnResume.Text = "Resume"; + this.btnResume.UseVisualStyleBackColor = true; + this.btnResume.Click += new System.EventHandler(this.button3_Click); + // + // btnPause + // + this.btnPause.Location = new System.Drawing.Point(119, 34); + this.btnPause.Name = "btnPause"; + this.btnPause.Size = new System.Drawing.Size(75, 23); + this.btnPause.TabIndex = 11; + this.btnPause.Text = "Pause"; + this.btnPause.UseVisualStyleBackColor = true; + this.btnPause.Click += new System.EventHandler(this.button4_Click); + // + // richTextBox2 + // + this.richTextBox2.BackColor = System.Drawing.Color.AliceBlue; + this.richTextBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.richTextBox2.ForeColor = System.Drawing.SystemColors.WindowFrame; + this.richTextBox2.Location = new System.Drawing.Point(457, 12); + this.richTextBox2.Name = "richTextBox2"; + this.richTextBox2.Size = new System.Drawing.Size(823, 174); + this.richTextBox2.TabIndex = 18; + this.richTextBox2.Text = resources.GetString("richTextBox2.Text"); + // + // richTextBox1 + // + this.richTextBox1.BackColor = System.Drawing.Color.AliceBlue; + this.richTextBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.richTextBox1.ForeColor = System.Drawing.SystemColors.WindowFrame; + this.richTextBox1.Location = new System.Drawing.Point(4, 12); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(428, 174); + this.richTextBox1.TabIndex = 17; + this.richTextBox1.Text = "Goal:\nGroup and interaction models are implemented in Symu.\nThe objective of this" + + " example is to show how to use, configure and see the impacts of those models on" + + " agents."; + // + // groupBox5 + // + this.groupBox5.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.groupBox5.Controls.Add(this.btnResume); + this.groupBox5.Controls.Add(this.btnPause); + this.groupBox5.Controls.Add(this.TimeStep); + this.groupBox5.Controls.Add(this.label1); + this.groupBox5.Controls.Add(this.btnStop); + this.groupBox5.Controls.Add(this.btnStart); + this.groupBox5.Controls.Add(this.groupBox3); + this.groupBox5.Controls.Add(this.groupBox1); + this.groupBox5.Location = new System.Drawing.Point(920, 203); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(360, 575); + this.groupBox5.TabIndex = 20; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "Run"; + // + // groupBox4 + // + this.groupBox4.BackColor = System.Drawing.SystemColors.ControlLight; + this.groupBox4.Controls.Add(this.groupBox9); + this.groupBox4.Controls.Add(this.groupBox2); + this.groupBox4.Controls.Add(this.groupBox12); + this.groupBox4.Controls.Add(this.groupBox7); + this.groupBox4.Controls.Add(this.groupBox6); + this.groupBox4.Location = new System.Drawing.Point(4, 203); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(900, 575); + this.groupBox4.TabIndex = 21; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "Settings"; + // + // groupBox9 + // + this.groupBox9.Controls.Add(this.label28); + this.groupBox9.Controls.Add(this.label27); + this.groupBox9.Controls.Add(this.WeightBeliefs); + this.groupBox9.Controls.Add(this.label14); + this.groupBox9.Controls.Add(this.WeightGroups); + this.groupBox9.Controls.Add(this.label23); + this.groupBox9.Controls.Add(this.WeightKnowledge); + this.groupBox9.Controls.Add(this.label24); + this.groupBox9.Controls.Add(this.WeightActivities); + this.groupBox9.Controls.Add(this.label25); + this.groupBox9.Controls.Add(this.label26); + this.groupBox9.Controls.Add(this.RadomlyGenerated); + this.groupBox9.Controls.Add(this.SimilarityMatching); + this.groupBox9.Controls.Add(this.MaxSphereDensity); + this.groupBox9.Controls.Add(this.label21); + this.groupBox9.Controls.Add(this.MinSphereDensity); + this.groupBox9.Controls.Add(this.label22); + this.groupBox9.Location = new System.Drawing.Point(29, 21); + this.groupBox9.Name = "groupBox9"; + this.groupBox9.Size = new System.Drawing.Size(374, 251); + this.groupBox9.TabIndex = 133; + this.groupBox9.TabStop = false; + this.groupBox9.Text = "Sphere of interaction model"; + // + // label28 + // + this.label28.AutoSize = true; + this.label28.Location = new System.Drawing.Point(33, 84); + this.label28.Name = "label28"; + this.label28.Size = new System.Drawing.Size(103, 17); + this.label28.TabIndex = 163; + this.label28.Text = "Sphere density"; + // + // label27 + // + this.label27.AutoSize = true; + this.label27.Location = new System.Drawing.Point(33, 25); + this.label27.Name = "label27"; + this.label27.Size = new System.Drawing.Size(81, 17); + this.label27.TabIndex = 162; + this.label27.Text = "Initialization"; + // + // WeightBeliefs + // + this.WeightBeliefs.Location = new System.Drawing.Point(283, 226); + this.WeightBeliefs.Name = "WeightBeliefs"; + this.WeightBeliefs.Size = new System.Drawing.Size(87, 22); + this.WeightBeliefs.TabIndex = 161; + this.WeightBeliefs.TextChanged += new System.EventHandler(this.WeightBeliefs_TextChanged); + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(66, 227); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(50, 17); + this.label14.TabIndex = 160; + this.label14.Text = "Beliefs"; + // + // WeightGroups + // + this.WeightGroups.Location = new System.Drawing.Point(283, 198); + this.WeightGroups.Name = "WeightGroups"; + this.WeightGroups.Size = new System.Drawing.Size(87, 22); + this.WeightGroups.TabIndex = 159; + this.WeightGroups.TextChanged += new System.EventHandler(this.WeightGroups_TextChanged); + // + // label23 + // + this.label23.AutoSize = true; + this.label23.Location = new System.Drawing.Point(66, 199); + this.label23.Name = "label23"; + this.label23.Size = new System.Drawing.Size(55, 17); + this.label23.TabIndex = 158; + this.label23.Text = "Groups"; + // + // WeightKnowledge + // + this.WeightKnowledge.Location = new System.Drawing.Point(283, 169); + this.WeightKnowledge.Name = "WeightKnowledge"; + this.WeightKnowledge.Size = new System.Drawing.Size(87, 22); + this.WeightKnowledge.TabIndex = 157; + this.WeightKnowledge.TextChanged += new System.EventHandler(this.textBox3_TextChanged); + // + // label24 + // + this.label24.AutoSize = true; + this.label24.Location = new System.Drawing.Point(66, 170); + this.label24.Name = "label24"; + this.label24.Size = new System.Drawing.Size(77, 17); + this.label24.TabIndex = 156; + this.label24.Text = "Knowledge"; + // + // WeightActivities + // + this.WeightActivities.Location = new System.Drawing.Point(283, 141); + this.WeightActivities.Name = "WeightActivities"; + this.WeightActivities.Size = new System.Drawing.Size(87, 22); + this.WeightActivities.TabIndex = 155; + this.WeightActivities.TextChanged += new System.EventHandler(this.WeightActivities_TextChanged); + // + // label25 + // + this.label25.AutoSize = true; + this.label25.Location = new System.Drawing.Point(66, 142); + this.label25.Name = "label25"; + this.label25.Size = new System.Drawing.Size(63, 17); + this.label25.TabIndex = 154; + this.label25.Text = "Activities"; + // + // label26 + // + this.label26.AutoSize = true; + this.label26.Location = new System.Drawing.Point(33, 114); + this.label26.Name = "label26"; + this.label26.Size = new System.Drawing.Size(125, 17); + this.label26.TabIndex = 153; + this.label26.Text = "Interaction weights"; + // + // RadomlyGenerated + // + this.RadomlyGenerated.AutoSize = true; + this.RadomlyGenerated.Checked = true; + this.RadomlyGenerated.Location = new System.Drawing.Point(207, 52); + this.RadomlyGenerated.Name = "RadomlyGenerated"; + this.RadomlyGenerated.Size = new System.Drawing.Size(161, 21); + this.RadomlyGenerated.TabIndex = 152; + this.RadomlyGenerated.TabStop = true; + this.RadomlyGenerated.Text = "Randomly generated"; + this.RadomlyGenerated.UseVisualStyleBackColor = true; + // + // SimilarityMatching + // + this.SimilarityMatching.AutoSize = true; + this.SimilarityMatching.Location = new System.Drawing.Point(207, 25); + this.SimilarityMatching.Name = "SimilarityMatching"; + this.SimilarityMatching.Size = new System.Drawing.Size(146, 21); + this.SimilarityMatching.TabIndex = 151; + this.SimilarityMatching.Text = "Similarity matching"; + this.SimilarityMatching.UseVisualStyleBackColor = true; + // + // MaxSphereDensity + // + this.MaxSphereDensity.Location = new System.Drawing.Point(323, 84); + this.MaxSphereDensity.Name = "MaxSphereDensity"; + this.MaxSphereDensity.Size = new System.Drawing.Size(45, 22); + this.MaxSphereDensity.TabIndex = 150; + this.MaxSphereDensity.TextChanged += new System.EventHandler(this.MaxSphereDensity_TextChanged); + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(271, 84); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(37, 17); + this.label21.TabIndex = 149; + this.label21.Text = "Max."; + // + // MinSphereDensity + // + this.MinSphereDensity.Location = new System.Drawing.Point(206, 81); + this.MinSphereDensity.Name = "MinSphereDensity"; + this.MinSphereDensity.Size = new System.Drawing.Size(45, 22); + this.MinSphereDensity.TabIndex = 148; + this.MinSphereDensity.TextChanged += new System.EventHandler(this.MinSphereDensity_TextChanged); + // + // label22 + // + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(166, 84); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(34, 17); + this.label22.TabIndex = 147; + this.label22.Text = "Min."; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.ActivitiesRandom); + this.groupBox2.Controls.Add(this.ActivitiesByGroup); + this.groupBox2.Controls.Add(this.ActivitiesSame); + this.groupBox2.Location = new System.Drawing.Point(453, 221); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(374, 108); + this.groupBox2.TabIndex = 133; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Activities"; + // + // ActivitiesRandom + // + this.ActivitiesRandom.AutoSize = true; + this.ActivitiesRandom.Location = new System.Drawing.Point(37, 84); + this.ActivitiesRandom.Name = "ActivitiesRandom"; + this.ActivitiesRandom.Size = new System.Drawing.Size(82, 21); + this.ActivitiesRandom.TabIndex = 2; + this.ActivitiesRandom.Text = "Random"; + this.ActivitiesRandom.UseVisualStyleBackColor = true; + // + // ActivitiesByGroup + // + this.ActivitiesByGroup.AutoSize = true; + this.ActivitiesByGroup.Checked = true; + this.ActivitiesByGroup.Location = new System.Drawing.Point(37, 57); + this.ActivitiesByGroup.Name = "ActivitiesByGroup"; + this.ActivitiesByGroup.Size = new System.Drawing.Size(86, 21); + this.ActivitiesByGroup.TabIndex = 1; + this.ActivitiesByGroup.TabStop = true; + this.ActivitiesByGroup.Text = "By group"; + this.ActivitiesByGroup.UseVisualStyleBackColor = true; + // + // ActivitiesSame + // + this.ActivitiesSame.AutoSize = true; + this.ActivitiesSame.Location = new System.Drawing.Point(37, 30); + this.ActivitiesSame.Name = "ActivitiesSame"; + this.ActivitiesSame.Size = new System.Drawing.Size(112, 21); + this.ActivitiesSame.TabIndex = 0; + this.ActivitiesSame.Text = "Same activity"; + this.ActivitiesSame.UseVisualStyleBackColor = true; + // + // groupBox12 + // + this.groupBox12.Controls.Add(this.label16); + this.groupBox12.Controls.Add(this.cbInitialKnowledgeLevel); + this.groupBox12.Controls.Add(this.label12); + this.groupBox12.Controls.Add(this.KnowledgeRandom); + this.groupBox12.Controls.Add(this.KnowledgeByGroup); + this.groupBox12.Controls.Add(this.KnowledgeSame); + this.groupBox12.Location = new System.Drawing.Point(453, 21); + this.groupBox12.Name = "groupBox12"; + this.groupBox12.Size = new System.Drawing.Size(374, 186); + this.groupBox12.TabIndex = 16; + this.groupBox12.TabStop = false; + this.groupBox12.Text = "Knowledge and beliefs"; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(34, 148); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(289, 17); + this.label16.TabIndex = 133; + this.label16.Text = "Beliefs are randomly created for every agent"; + // + // cbInitialKnowledgeLevel + // + this.cbInitialKnowledgeLevel.FormattingEnabled = true; + this.cbInitialKnowledgeLevel.Location = new System.Drawing.Point(242, 107); + this.cbInitialKnowledgeLevel.Name = "cbInitialKnowledgeLevel"; + this.cbInitialKnowledgeLevel.Size = new System.Drawing.Size(87, 24); + this.cbInitialKnowledgeLevel.TabIndex = 38; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(34, 114); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(173, 17); + this.label12.TabIndex = 132; + this.label12.Text = "Knowledge level of agents"; + // + // KnowledgeRandom + // + this.KnowledgeRandom.AutoSize = true; + this.KnowledgeRandom.Location = new System.Drawing.Point(37, 84); + this.KnowledgeRandom.Name = "KnowledgeRandom"; + this.KnowledgeRandom.Size = new System.Drawing.Size(82, 21); + this.KnowledgeRandom.TabIndex = 2; + this.KnowledgeRandom.Text = "Random"; + this.KnowledgeRandom.UseVisualStyleBackColor = true; + // + // KnowledgeByGroup + // + this.KnowledgeByGroup.AutoSize = true; + this.KnowledgeByGroup.Checked = true; + this.KnowledgeByGroup.Location = new System.Drawing.Point(37, 57); + this.KnowledgeByGroup.Name = "KnowledgeByGroup"; + this.KnowledgeByGroup.Size = new System.Drawing.Size(86, 21); + this.KnowledgeByGroup.TabIndex = 1; + this.KnowledgeByGroup.TabStop = true; + this.KnowledgeByGroup.Text = "By group"; + this.KnowledgeByGroup.UseVisualStyleBackColor = true; + // + // KnowledgeSame + // + this.KnowledgeSame.AutoSize = true; + this.KnowledgeSame.Location = new System.Drawing.Point(37, 30); + this.KnowledgeSame.Name = "KnowledgeSame"; + this.KnowledgeSame.Size = new System.Drawing.Size(136, 21); + this.KnowledgeSame.TabIndex = 0; + this.KnowledgeSame.Text = "Same knowledge"; + this.KnowledgeSame.UseVisualStyleBackColor = true; + // + // groupBox7 + // + this.groupBox7.Controls.Add(this.Homophily); + this.groupBox7.Controls.Add(this.AllowNewInteractions); + this.groupBox7.Controls.Add(this.InteractionBeliefs); + this.groupBox7.Controls.Add(this.label11); + this.groupBox7.Controls.Add(this.InteractionSocialDemographics); + this.groupBox7.Controls.Add(this.label6); + this.groupBox7.Controls.Add(this.MaxDailyInteractions); + this.groupBox7.Controls.Add(this.label17); + this.groupBox7.Controls.Add(this.InteractionKnowledge); + this.groupBox7.Controls.Add(this.label20); + this.groupBox7.Controls.Add(this.InteractionActivities); + this.groupBox7.Controls.Add(this.label15); + this.groupBox7.Controls.Add(this.ThresholdFornewInteraction); + this.groupBox7.Controls.Add(this.label9); + this.groupBox7.Controls.Add(this.label10); + this.groupBox7.Location = new System.Drawing.Point(29, 289); + this.groupBox7.Name = "groupBox7"; + this.groupBox7.Size = new System.Drawing.Size(374, 280); + this.groupBox7.TabIndex = 32; + this.groupBox7.TabStop = false; + this.groupBox7.Text = "Agent interactions"; + // + // Homophily + // + this.Homophily.AutoSize = true; + this.Homophily.Location = new System.Drawing.Point(282, 28); + this.Homophily.Name = "Homophily"; + this.Homophily.Size = new System.Drawing.Size(45, 21); + this.Homophily.TabIndex = 147; + this.Homophily.Text = "All"; + this.Homophily.UseVisualStyleBackColor = true; + this.Homophily.CheckedChanged += new System.EventHandler(this.Homophily_CheckedChanged); + // + // AllowNewInteractions + // + this.AllowNewInteractions.AutoSize = true; + this.AllowNewInteractions.Location = new System.Drawing.Point(18, 175); + this.AllowNewInteractions.Name = "AllowNewInteractions"; + this.AllowNewInteractions.Size = new System.Drawing.Size(168, 21); + this.AllowNewInteractions.TabIndex = 146; + this.AllowNewInteractions.Text = "Allow new interactions"; + this.AllowNewInteractions.UseVisualStyleBackColor = true; + // + // InteractionBeliefs + // + this.InteractionBeliefs.Location = new System.Drawing.Point(281, 143); + this.InteractionBeliefs.Name = "InteractionBeliefs"; + this.InteractionBeliefs.Size = new System.Drawing.Size(87, 22); + this.InteractionBeliefs.TabIndex = 145; + this.InteractionBeliefs.TextChanged += new System.EventHandler(this.InteractionBeliefs_TextChanged); + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(64, 144); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(50, 17); + this.label11.TabIndex = 144; + this.label11.Text = "Beliefs"; + // + // InteractionSocialDemographics + // + this.InteractionSocialDemographics.Location = new System.Drawing.Point(281, 113); + this.InteractionSocialDemographics.Name = "InteractionSocialDemographics"; + this.InteractionSocialDemographics.Size = new System.Drawing.Size(87, 22); + this.InteractionSocialDemographics.TabIndex = 143; + this.InteractionSocialDemographics.TextChanged += new System.EventHandler(this.InteractionSocialDemographics_TextChanged); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(64, 114); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(55, 17); + this.label6.TabIndex = 142; + this.label6.Text = "Groups"; + // + // MaxDailyInteractions + // + this.MaxDailyInteractions.Location = new System.Drawing.Point(281, 242); + this.MaxDailyInteractions.Name = "MaxDailyInteractions"; + this.MaxDailyInteractions.Size = new System.Drawing.Size(87, 22); + this.MaxDailyInteractions.TabIndex = 141; + this.MaxDailyInteractions.TextChanged += new System.EventHandler(this.DailyInteractions_TextChanged); + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(64, 244); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(211, 17); + this.label17.TabIndex = 140; + this.label17.Text = "Max. number of new interactions"; + // + // InteractionKnowledge + // + this.InteractionKnowledge.Location = new System.Drawing.Point(281, 83); + this.InteractionKnowledge.Name = "InteractionKnowledge"; + this.InteractionKnowledge.Size = new System.Drawing.Size(87, 22); + this.InteractionKnowledge.TabIndex = 139; + this.InteractionKnowledge.TextChanged += new System.EventHandler(this.DeliberateSearch_TextChanged); + // + // label20 + // + this.label20.AutoSize = true; + this.label20.Location = new System.Drawing.Point(64, 84); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(77, 17); + this.label20.TabIndex = 138; + this.label20.Text = "Knowledge"; + // + // InteractionActivities + // + this.InteractionActivities.Location = new System.Drawing.Point(281, 54); + this.InteractionActivities.Name = "InteractionActivities"; + this.InteractionActivities.Size = new System.Drawing.Size(87, 22); + this.InteractionActivities.TabIndex = 135; + this.InteractionActivities.TextChanged += new System.EventHandler(this.Coworkers_TextChanged); + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(64, 55); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(63, 17); + this.label15.TabIndex = 134; + this.label15.Text = "Activities"; + // + // ThresholdFornewInteraction + // + this.ThresholdFornewInteraction.Location = new System.Drawing.Point(281, 202); + this.ThresholdFornewInteraction.Name = "ThresholdFornewInteraction"; + this.ThresholdFornewInteraction.Size = new System.Drawing.Size(87, 22); + this.ThresholdFornewInteraction.TabIndex = 30; + this.ThresholdFornewInteraction.TextChanged += new System.EventHandler(this.ThresholdForNewInteraction_TextChanged); + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(64, 207); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(192, 17); + this.label9.TabIndex = 29; + this.label9.Text = "Threshold for new interaction"; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(25, 28); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(161, 17); + this.label10.TabIndex = 4; + this.label10.Text = "Interaction strategy ratio"; + // + // groupBox6 + // + this.groupBox6.Controls.Add(this.GroupsCount); + this.groupBox6.Controls.Add(this.label13); + this.groupBox6.Controls.Add(this.tbWorkers); + this.groupBox6.Controls.Add(this.label2); + this.groupBox6.Controls.Add(this.tbSteps); + this.groupBox6.Controls.Add(this.label7); + this.groupBox6.Location = new System.Drawing.Point(453, 335); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(374, 123); + this.groupBox6.TabIndex = 18; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "Simulation"; + // + // GroupsCount + // + this.GroupsCount.Location = new System.Drawing.Point(242, 21); + this.GroupsCount.Name = "GroupsCount"; + this.GroupsCount.Size = new System.Drawing.Size(87, 22); + this.GroupsCount.TabIndex = 131; + this.GroupsCount.Text = "2"; + this.GroupsCount.TextChanged += new System.EventHandler(this.GroupsCount_TextChanged); + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(25, 26); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(122, 17); + this.label13.TabIndex = 130; + this.label13.Text = "Number of groups"; + // + // tbSteps + // + this.tbSteps.Location = new System.Drawing.Point(242, 87); + this.tbSteps.Name = "tbSteps"; + this.tbSteps.Size = new System.Drawing.Size(87, 22); + this.tbSteps.TabIndex = 39; + this.tbSteps.Text = "200"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(25, 92); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(112, 17); + this.label7.TabIndex = 42; + this.label7.Text = "Number of steps"; + // + // Home + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1298, 790); + this.Controls.Add(this.groupBox4); + this.Controls.Add(this.groupBox5); + this.Controls.Add(this.richTextBox2); + this.Controls.Add(this.richTextBox1); + this.Name = "Home"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.groupBox5.ResumeLayout(false); + this.groupBox5.PerformLayout(); + this.groupBox4.ResumeLayout(false); + this.groupBox9.ResumeLayout(false); + this.groupBox9.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox12.ResumeLayout(false); + this.groupBox12.PerformLayout(); + this.groupBox7.ResumeLayout(false); + this.groupBox7.PerformLayout(); + this.groupBox6.ResumeLayout(false); + this.groupBox6.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.Button btnStop; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label TimeStep; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label lblMessagesSent; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox tbWorkers; + private System.Windows.Forms.Button btnResume; + private System.Windows.Forms.Button btnPause; + private System.Windows.Forms.RichTextBox richTextBox2; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.GroupBox groupBox5; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.GroupBox groupBox6; + private System.Windows.Forms.TextBox tbSteps; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.GroupBox groupBox12; + private System.Windows.Forms.GroupBox groupBox7; + private System.Windows.Forms.TextBox ThresholdFornewInteraction; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox GroupsCount; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.TextBox InteractionKnowledge; + private System.Windows.Forms.Label label20; + private System.Windows.Forms.TextBox InteractionActivities; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.TextBox MaxDailyInteractions; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.RadioButton KnowledgeRandom; + private System.Windows.Forms.RadioButton KnowledgeByGroup; + private System.Windows.Forms.RadioButton KnowledgeSame; + private System.Windows.Forms.TextBox InteractionSocialDemographics; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox InteractionBeliefs; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.CheckBox AllowNewInteractions; + private System.Windows.Forms.ComboBox cbInitialKnowledgeLevel; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.RadioButton ActivitiesRandom; + private System.Windows.Forms.RadioButton ActivitiesByGroup; + private System.Windows.Forms.RadioButton ActivitiesSame; + private System.Windows.Forms.GroupBox groupBox9; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label Triads; + private System.Windows.Forms.Label label19; + private System.Windows.Forms.Label InteractionSphereCount; + private System.Windows.Forms.TextBox MaxSphereDensity; + private System.Windows.Forms.Label label21; + private System.Windows.Forms.TextBox MinSphereDensity; + private System.Windows.Forms.Label label22; + private System.Windows.Forms.RadioButton RadomlyGenerated; + private System.Windows.Forms.RadioButton SimilarityMatching; + private System.Windows.Forms.Label NotAcceptedMessages; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.Label label28; + private System.Windows.Forms.Label label27; + private System.Windows.Forms.TextBox WeightBeliefs; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.TextBox WeightGroups; + private System.Windows.Forms.Label label23; + private System.Windows.Forms.TextBox WeightKnowledge; + private System.Windows.Forms.Label label24; + private System.Windows.Forms.TextBox WeightActivities; + private System.Windows.Forms.Label label25; + private System.Windows.Forms.Label label26; + private System.Windows.Forms.CheckBox Homophily; + private System.Windows.Forms.Label label29; + private System.Windows.Forms.Label SphereDensity; + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Home.cs b/Symu examples/SymuGroupAndInteraction/Home.cs new file mode 100644 index 00000000..fcc11261 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Home.cs @@ -0,0 +1,549 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using System.Drawing; +using System.Globalization; +using System.Linq; +using System.Windows.Forms; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Scenario; +using SymuEngine.Common; +using SymuEngine.Engine.Form; +using SymuEngine.Environment; +using SymuEngine.Repository.Networks.Knowledges; +using SymuGroupAndInteraction.Classes; + +#endregion + +namespace SymuGroupAndInteraction +{ + public partial class Home : SymuForm + { + private readonly ExampleEnvironment _environment = new ExampleEnvironment(); + + public Home() + { + InitializeComponent(); + LoadSettings(); + } + + private void LoadSettings() + { + DisplayButtons(); + + #region Environment + + tbWorkers.Text = _environment.WorkersCount.ToString(CultureInfo.InvariantCulture); + GroupsCount.Text = _environment.GroupsCount.ToString(CultureInfo.InvariantCulture); + + #endregion + + #region sphere of interaction + + RadomlyGenerated.Checked = true; + AllowNewInteractions.Checked = true; + MaxSphereDensity.Text = + OrganizationEntity.Models.InteractionSphere.MaxSphereDensity.ToString(); + MinSphereDensity.Text = + OrganizationEntity.Models.InteractionSphere.MinSphereDensity.ToString(); + WeightKnowledge.Text = OrganizationEntity.Models.InteractionSphere.RelativeKnowledgeWeight.ToString(); + WeightActivities.Text = OrganizationEntity.Models.InteractionSphere.RelativeActivityWeight.ToString(); + WeightBeliefs.Text = OrganizationEntity.Models.InteractionSphere.RelativeBeliefWeight.ToString(); + WeightGroups.Text = OrganizationEntity.Models.InteractionSphere.SocialDemographicWeight.ToString(); + + #endregion + + #region Interaction + + OrganizationEntity.Models.InteractionSphere.SetInteractionPatterns(InteractionStrategy.Homophily); + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0.1F; + ThresholdFornewInteraction.Text = OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns + .ThresholdForNewInteraction.ToString(); + MaxDailyInteractions.Text = "2"; + + Homophily.Checked = true; + + #endregion + + #region Knowledge + + KnowledgeRandom.Checked = true; + cbInitialKnowledgeLevel.Items.AddRange(KnowledgeLevelService.GetNames()); + cbInitialKnowledgeLevel.SelectedItem = KnowledgeLevelService.GetName(_environment.KnowledgeLevel); + + #endregion + + #region Activities + + ActivitiesRandom.Checked = true; + + #endregion + } + + protected override void SetUpOrganization() + { + TimeStepType = TimeStepType.Daily; + } + + protected override void SetScenarii() + { + _ = new TimeStepScenario(_environment) + { + NumberOfSteps = ushort.Parse(tbSteps.Text) + }; + } + + protected override void OnStopped() + { + base.OnStopped(); + DisplayButtons(); + } + + private void Button1_Click(object sender, EventArgs e) + { + #region Knowledge + + if (KnowledgeSame.Checked) + { + _environment.Knowledge = 0; + } + + if (KnowledgeByGroup.Checked) + { + _environment.Knowledge = 1; + } + + if (KnowledgeRandom.Checked) + { + _environment.Knowledge = 2; + } + + OrganizationEntity.Models.Generator = RandomGenerator.RandomUniform; + _environment.KnowledgeLevel = + KnowledgeLevelService.GetValue(cbInitialKnowledgeLevel.SelectedItem.ToString()); + + #endregion + + + #region sphere of interaction + + OrganizationEntity.Models.InteractionSphere.RandomlyGeneratedSphere = RadomlyGenerated.Checked; + + #endregion + + #region Activities + + if (ActivitiesSame.Checked) + { + _environment.Activities = 0; + } + + if (ActivitiesByGroup.Checked) + { + _environment.Activities = 1; + } + + if (ActivitiesRandom.Checked) + { + _environment.Activities = 2; + } + + #endregion + + #region Interactions + + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = + AllowNewInteractions.Checked; + + #endregion + + Start(_environment); + } + + private void Button2_Click(object sender, EventArgs e) + { + Cancel(); + } + + public override void Display() + { + DisplayButtons(); + WriteTextSafe(TimeStep, _environment.TimeStep.Step.ToString()); + UpDateMessages(); + UpdateAgents(); + } + + private void UpDateMessages() + { + WriteTextSafe(lblMessagesSent, _environment.Messages.SentMessagesCount.ToString()); + var notAcceptedMessages = _environment.WhitePages.AllAgents() + .Sum(agent => agent.MessageProcessor.NotAcceptedMessages.Count); + WriteTextSafe(NotAcceptedMessages, notAcceptedMessages.ToString()); + } + + private void UpdateAgents() + { + WriteTextSafe(Triads, + _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density + .ToString("F1", CultureInfo.InvariantCulture)); + WriteTextSafe(InteractionSphereCount, + _environment.IterationResult.OrganizationFlexibility.Links.Last().Density + .ToString("F1", CultureInfo.InvariantCulture)); + WriteTextSafe(SphereDensity, + _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density + .ToString("F1", CultureInfo.InvariantCulture)); + } + + private void button4_Click(object sender, EventArgs e) + { + Pause(); + } + + private void button3_Click(object sender, EventArgs e) + { + Resume(); + } + + private void DisplayButtons() + { + switch (State) + { + case AgentState.Stopped: + case AgentState.NotStarted: + WriteButtonSafe(btnStart, true); + WriteButtonSafe(btnStop, false); + WriteButtonSafe(btnPause, false); + WriteButtonSafe(btnResume, false); + break; + case AgentState.Stopping: + case AgentState.Starting: + WriteButtonSafe(btnStart, false); + WriteButtonSafe(btnStop, false); + WriteButtonSafe(btnPause, false); + WriteButtonSafe(btnResume, false); + break; + case AgentState.Started: + WriteButtonSafe(btnStart, false); + WriteButtonSafe(btnStop, true); + WriteButtonSafe(btnPause, true); + WriteButtonSafe(btnResume, false); + break; + case AgentState.Paused: + WriteButtonSafe(btnStart, false); + WriteButtonSafe(btnStop, true); + WriteButtonSafe(btnPause, false); + WriteButtonSafe(btnResume, true); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + protected void WriteButtonSafe(Button button, bool enabled) + { + if (button is null) + { + throw new ArgumentNullException(nameof(button)); + } + + if (button.InvokeRequired) + { + var d = new SafeCallButtonDelegate(WriteButtonSafe); + button.Invoke(d, button, enabled); + } + else + { + button.Enabled = enabled; + } + } + + private void tbWorkers_TextChanged(object sender, EventArgs e) + { + try + { + _environment.WorkersCount = byte.Parse(tbWorkers.Text); + tbWorkers.BackColor = SystemColors.Window; + } + catch (FormatException) + { + tbWorkers.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + tbWorkers.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void GroupsCount_TextChanged(object sender, EventArgs e) + { + try + { + _environment.GroupsCount = byte.Parse(GroupsCount.Text); + GroupsCount.BackColor = SystemColors.Window; + } + catch (FormatException) + { + GroupsCount.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + GroupsCount.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void Coworkers_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnActivities = + float.Parse(InteractionActivities.Text); + InteractionActivities.BackColor = SystemColors.Window; + } + catch (FormatException) + { + InteractionActivities.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + InteractionActivities.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void DeliberateSearch_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnKnowledge = + float.Parse(InteractionKnowledge.Text); + InteractionKnowledge.BackColor = SystemColors.Window; + } + catch (FormatException) + { + InteractionKnowledge.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + InteractionKnowledge.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void ThresholdForNewInteraction_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = + float.Parse(ThresholdFornewInteraction.Text); + ThresholdFornewInteraction.BackColor = SystemColors.Window; + } + catch (FormatException) + { + ThresholdFornewInteraction.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + ThresholdFornewInteraction.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void DailyInteractions_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = + byte.Parse(MaxDailyInteractions.Text); + MaxDailyInteractions.BackColor = SystemColors.Window; + } + catch (FormatException) + { + MaxDailyInteractions.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + MaxDailyInteractions.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void InteractionSocialDemographics_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnSocialDemographics = + float.Parse(InteractionSocialDemographics.Text); + InteractionSocialDemographics.BackColor = SystemColors.Window; + } + catch (FormatException) + { + InteractionSocialDemographics.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + InteractionSocialDemographics.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void InteractionBeliefs_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnBeliefs = + float.Parse(InteractionBeliefs.Text); + InteractionBeliefs.BackColor = SystemColors.Window; + } + catch (FormatException) + { + InteractionBeliefs.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + InteractionBeliefs.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void MinSphereDensity_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.MinSphereDensity = float.Parse(MinSphereDensity.Text); + MinSphereDensity.BackColor = SystemColors.Window; + } + catch (FormatException) + { + MinSphereDensity.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + MinSphereDensity.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void MaxSphereDensity_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.MaxSphereDensity = float.Parse(MaxSphereDensity.Text); + MaxSphereDensity.BackColor = SystemColors.Window; + } + catch (FormatException) + { + MaxSphereDensity.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + MaxSphereDensity.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void textBox3_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.RelativeKnowledgeWeight = float.Parse(WeightKnowledge.Text); + WeightKnowledge.BackColor = SystemColors.Window; + } + catch (FormatException) + { + WeightKnowledge.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + WeightKnowledge.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void WeightActivities_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.RelativeActivityWeight = float.Parse(WeightActivities.Text); + WeightActivities.BackColor = SystemColors.Window; + } + catch (FormatException) + { + WeightActivities.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + WeightActivities.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void WeightGroups_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.SocialDemographicWeight = float.Parse(WeightGroups.Text); + WeightGroups.BackColor = SystemColors.Window; + } + catch (FormatException) + { + WeightGroups.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + WeightGroups.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void WeightBeliefs_TextChanged(object sender, EventArgs e) + { + try + { + OrganizationEntity.Models.InteractionSphere.RelativeBeliefWeight = float.Parse(WeightBeliefs.Text); + WeightBeliefs.BackColor = SystemColors.Window; + } + catch (FormatException) + { + WeightBeliefs.BackColor = Color.Red; + } + catch (ArgumentOutOfRangeException exception) + { + WeightBeliefs.BackColor = Color.Red; + MessageBox.Show(exception.Message); + } + } + + private void Homophily_CheckedChanged(object sender, EventArgs e) + { + if (!Homophily.Checked) + { + return; + } + + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns( + InteractionStrategy.Homophily); + InteractionActivities.Text = "0"; + InteractionBeliefs.Text = "0"; + InteractionKnowledge.Text = "0"; + InteractionSocialDemographics.Text = "0"; + } + + #region Nested type: SafeCallButtonDelegate + + protected delegate void SafeCallButtonDelegate(Button button, bool enabled); + + #endregion + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Home.resx b/Symu examples/SymuGroupAndInteraction/Home.resx new file mode 100644 index 00000000..f87ffda3 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Home.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Scenario: +* Groups of people +* People who are members of the group + +Knowledge, activites, beliefs and social-demographics are defined for every agents. +Those parameters has an impact on the way people are interacting every day in their group, in their sphere of _model. +Play with the _model strategy to see the impact on the organization flexibility, defined by the capacity of creating triads. +Try to increase triads with the creation of new _models. + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Program.cs b/Symu examples/SymuGroupAndInteraction/Program.cs new file mode 100644 index 00000000..76218b34 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Program.cs @@ -0,0 +1,32 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using System.Windows.Forms; + +#endregion + +namespace SymuGroupAndInteraction +{ + internal static class Program + { + /// + /// Point d'entrée principal de l'application. + /// + [STAThread] + private static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Home()); + } + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Properties/AssemblyInfo.cs b/Symu examples/SymuGroupAndInteraction/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..de391059 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Properties/AssemblyInfo.cs @@ -0,0 +1,48 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteraction +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System.Reflection; +using System.Runtime.InteropServices; + +#endregion + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("SymuGroupAndInteraction")] +[assembly: AssemblyDescription("Symu group and interaction models")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Symu.org")] +[assembly: AssemblyProduct("Symu")] +[assembly: AssemblyCopyright("Copyright © Symu.org 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur true à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("998c00b3-6a46-41d7-9140-57e1d07a7b6d")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Properties/Resources.Designer.cs b/Symu examples/SymuGroupAndInteraction/Properties/Resources.Designer.cs new file mode 100644 index 00000000..b4672bdd --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace SymuGroupAndInteraction.Properties { + using System; + + + /// + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Density", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SymuGroupAndInteraction.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Symu examples/SymuGroupAndInteraction/Properties/Resources.resx b/Symu examples/SymuGroupAndInteraction/Properties/Resources.resx new file mode 100644 index 00000000..d81dfc13 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/Properties/Settings.Designer.cs b/Symu examples/SymuGroupAndInteraction/Properties/Settings.Designer.cs new file mode 100644 index 00000000..395cf41c --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace SymuGroupAndInteraction.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Symu examples/SymuGroupAndInteraction/Properties/Settings.settings b/Symu examples/SymuGroupAndInteraction/Properties/Settings.settings new file mode 100644 index 00000000..e04fc631 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/Properties/Settings.settings @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/SymuGroupAndInteraction.csproj b/Symu examples/SymuGroupAndInteraction/SymuGroupAndInteraction.csproj new file mode 100644 index 00000000..2bebf36c --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/SymuGroupAndInteraction.csproj @@ -0,0 +1,158 @@ + + + + + + + Debug + AnyCPU + {7FB89272-EBE0-42FC-8DCC-84E09DCBBC44} + WinExe + SymuGroupAndInteraction + SymuGroupAndInteraction + v4.8 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MathNet.Numerics.4.9.1\lib\net461\MathNet.Numerics.dll + + + ..\packages\Microsoft.CodeAnalysis.Common.3.5.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.3.5.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll + + + + ..\..\Symu source code\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + True + + + ..\..\Symu source code\packages\System.Collections.Immutable.1.7.0\lib\netstandard2.0\System.Collections.Immutable.dll + True + + + + ..\..\Symu source code\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + True + + + + ..\..\Symu source code\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + True + + + ..\..\Symu source code\packages\System.Reflection.Metadata.1.8.0\lib\netstandard2.0\System.Reflection.Metadata.dll + True + + + ..\..\Symu source code\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + True + + + + ..\..\Symu source code\packages\System.Text.Encoding.CodePages.4.7.0\lib\net461\System.Text.Encoding.CodePages.dll + True + + + ..\..\Symu source code\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + True + + + + + + + + + + + + + + + + + Form + + + Home.cs + + + + + Home.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + + {7fb12021-615c-4b12-b925-701e2c69969f} + SymuEngine + + + {5475a2e5-e10f-46ef-b24e-450d717af7cf} + SymuTools + + + + + + + + + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteraction/packages.config b/Symu examples/SymuGroupAndInteraction/packages.config new file mode 100644 index 00000000..64903b07 --- /dev/null +++ b/Symu examples/SymuGroupAndInteraction/packages.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteractionTests/IntegrationTests.cs b/Symu examples/SymuGroupAndInteractionTests/IntegrationTests.cs new file mode 100644 index 00000000..a893558d --- /dev/null +++ b/Symu examples/SymuGroupAndInteractionTests/IntegrationTests.cs @@ -0,0 +1,396 @@ +#region Licence + +// Description: Symu - SymuGroupAndInteractionTests +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; +using SymuEngine.Classes.Scenario; +using SymuEngine.Common; +using SymuEngine.Engine; +using SymuEngine.Environment; +using SymuEngine.Repository.Networks.Knowledges; +using SymuGroupAndInteraction.Classes; + +#endregion + + +namespace SymuGroupAndInteractionTests +{ + /// + /// Integration tests using SimulationEngine + /// + [TestClass] + public class IntegrationTests + { + private const int NumberOfSteps = 31; // 2 organizationFlexibility computations + private readonly ExampleEnvironment _environment = new ExampleEnvironment(); + private readonly OrganizationEntity _organization = new OrganizationEntity("1"); + private readonly SimulationEngine _simulation = new SimulationEngine(); + + [TestInitialize] + public void Initialize() + { + _environment.SetOrganization(_organization); + _simulation.SetEnvironment(_environment); + var scenario = new TimeStepScenario(_environment) + { + NumberOfSteps = NumberOfSteps + }; + _simulation.AddScenario(scenario); + _environment.TimeStep.Type = TimeStepType.Daily; + _organization.Models.Generator = RandomGenerator.RandomUniform; + _environment.Knowledge = 0; + _environment.Activities = 0; + _organization.Models.InteractionSphere.RandomlyGeneratedSphere = false; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = false; + } + + public void SetInteractionPatterns(InteractionStrategy strategy) + { + _organization.Models.InteractionSphere.SetInteractionPatterns(strategy); + _organization.Templates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(strategy); + } + + private int GetNotAcceptedMessages() + { + return _environment.WhitePages.AllAgents().Sum(agent => agent.MessageProcessor.NotAcceptedMessages.Count); + } + + #region n groups- 10 workers + + /// + /// Interaction sphere == Coworkers because no opportunities to grow the sphere of interaction which is initialized + /// with coworkers + /// + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [TestMethod] + public void KnowledgeSphereCount(int groupsCount) + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = (byte) groupsCount; + _environment.WorkersCount = 10; + _organization.Templates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 1; + _environment.Knowledge = 1; + _simulation.Process(); + var links = _environment.WhitePages.Network.NetworkLinks.Count; + var triads = _environment.IterationResult.OrganizationFlexibility.Triads.Last().ActualNumber; + _simulation.Process(); + Assert.AreEqual(links, _environment.WhitePages.Network.NetworkLinks.Count); + Assert.AreEqual(triads, _environment.IterationResult.OrganizationFlexibility.Triads.Last().ActualNumber); + } + + #endregion + + #region 0 group + + [DataRow(0)] + [DataRow(1)] + [TestMethod] + public void NoGroupsOneMemberTest(int agentCount) + { + _environment.GroupsCount = 0; + _environment.WorkersCount = (byte) agentCount; + _simulation.Process(); + Assert.AreEqual(0F, GetNotAcceptedMessages()); + Assert.AreEqual(0F, _environment.Messages.SentMessagesCount); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + #endregion + + #region 1 group + + [DataRow(0)] + [DataRow(1)] + [TestMethod] + public void OneGroupsOneMemberTest(int agentCount) + { + _environment.GroupsCount = 0; + _environment.WorkersCount = (byte) agentCount; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _simulation.Process(); + Assert.AreEqual(0F, GetNotAcceptedMessages()); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + [DataRow(2, 100, 0, 100)] + [DataRow(3, 100, 100, 100)] + [DataRow(4, 100, 100, 100)] + [TestMethod] + public void LinksCountTest(int workers, float links, float triads, float sphere) + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 1; + _environment.WorkersCount = (byte) workers; + _simulation.Process(); + Assert.AreEqual(links, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(triads, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(sphere, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// Randomly generated + /// + [TestMethod] + public void TriadsTest5() + { + SetInteractionPatterns(InteractionStrategy.Homophily); + _environment.GroupsCount = 1; + _environment.WorkersCount = 3; + _organization.Models.InteractionSphere.RandomlyGeneratedSphere = true; + _organization.Models.InteractionSphere.MinSphereDensity = 0; + _organization.Models.InteractionSphere.MaxSphereDensity = 0; + _simulation.Process(); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + } + + [TestMethod] + public void CoworkersCountTest() + { + _environment.GroupsCount = 1; + _environment.WorkersCount = 10; + // knowledge by group + _environment.Knowledge = 1; + SetInteractionPatterns(InteractionStrategy.Knowledge); + _simulation.Process(); + var links = _environment.WhitePages.Network.NetworkLinks.Count; + var triads = _environment.IterationResult.OrganizationFlexibility.Triads.Last().ActualNumber; + // results should be a multiple of groups count, because interaction sphere can't changes + _environment.GroupsCount = 2; + _simulation.Process(); + Assert.AreEqual(links * _environment.GroupsCount, _environment.WhitePages.Network.NetworkLinks.Count); + Assert.AreEqual(triads * _environment.GroupsCount, + _environment.IterationResult.OrganizationFlexibility.Triads.Last().ActualNumber); + _environment.GroupsCount = 3; + _simulation.Process(); + Assert.AreEqual(links * _environment.GroupsCount, _environment.WhitePages.Network.NetworkLinks.Count); + Assert.AreEqual(triads * _environment.GroupsCount, + _environment.IterationResult.OrganizationFlexibility.Triads.Last().ActualNumber); + } + + /// + /// With new interactions + /// + [TestMethod] + public void NewInteractionTest() + { + _environment.GroupsCount = 1; + _environment.WorkersCount = 3; + _simulation.Process(); + Assert.AreEqual(0F, GetNotAcceptedMessages()); + } + + #endregion + + #region 2 groups - 1 member + + /// + /// Same Knowledge + /// + [TestMethod] + public void TwoGroupsOneMemberTest() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 1; + _environment.Knowledge = 0; + _simulation.Process(); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(100F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// By group Knowledge + /// + [TestMethod] + public void TwoGroupsOneMemberTest1() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 1; + _environment.Knowledge = 1; + _simulation.Process(); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// Allow interaction - threshold = 0 + /// + [TestMethod] + public void TwoGroupsOneMemberTest2() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 1; + _environment.Knowledge = 1; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0; + _simulation.Process(); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + Assert.IsTrue(GetNotAcceptedMessages() > 0); + } + + /// + /// Allow interaction - threshold = 1 + /// + [TestMethod] + public void TwoGroupsOneMemberTest3() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 1; + _environment.Knowledge = 1; + _organization.Models.InteractionSphere.FrequencyOfSphereUpdate = TimeStepType.Daily; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1; + _simulation.Process(); + Assert.AreEqual(100F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + Assert.AreEqual(0, GetNotAcceptedMessages()); + } + + #endregion + + #region 2 groups > 1 member + + /// + /// With same knowledge + /// + [TestMethod] + public void TriadsTest() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _environment.Knowledge = 0; + _simulation.Process(); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(100.0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(100.0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// With knowledge by group + /// + [TestMethod] + public void TriadsTest1() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _environment.Knowledge = 1; + _simulation.Process(); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(10.0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// With same activity + /// + [TestMethod] + public void TriadsTest2() + { + SetInteractionPatterns(InteractionStrategy.Activities); + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _environment.Activities = 0; + _simulation.Process(); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(100.0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(100.0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// With activity by group + /// + [TestMethod] + public void TriadsTest3() + { + SetInteractionPatterns(InteractionStrategy.Activities); + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _environment.Activities = 1; + _simulation.Process(); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(10.0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.AreEqual(40.0F, _environment.IterationResult.OrganizationFlexibility.Sphere.Last().Density); + } + + /// + /// With random no knowledge + /// + [TestMethod] + public void TriadsTest4() + { + SetInteractionPatterns(InteractionStrategy.Knowledge); + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _environment.Knowledge = 2; + _environment.KnowledgeLevel = KnowledgeLevel.NoKnowledge; + _simulation.Process(); + Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + } + + /// + /// Allow new interaction with homophily - threshold = 0 + /// + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [TestMethod] + public void NewInteractionWithHomophilyTest(int interactions) + { + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0; + _organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = + (byte) interactions; + _simulation.Process(); + Assert.AreEqual(40F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(10F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density); + Assert.IsTrue(GetNotAcceptedMessages() > 0); + } + + /// + /// Allow new interaction with homophily - threshold = 1 + /// + [TestMethod] + public void NewInteractionWithHomophily1Test() + { + _environment.GroupsCount = 2; + _environment.WorkersCount = 3; + _organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1; + _organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 5; + _simulation.Process(); + Assert.AreEqual(100F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density); + Assert.AreEqual(0, GetNotAcceptedMessages()); + } + + #endregion + } +} \ No newline at end of file diff --git a/Symu examples/SymuGroupAndInteractionTests/SymuGroupAndInteractionTests.csproj b/Symu examples/SymuGroupAndInteractionTests/SymuGroupAndInteractionTests.csproj new file mode 100644 index 00000000..592204c1 --- /dev/null +++ b/Symu examples/SymuGroupAndInteractionTests/SymuGroupAndInteractionTests.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + diff --git a/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs b/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs index 29396054..c92b06f5 100644 --- a/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -35,20 +35,22 @@ public override void SetModelForAgents() WhitePages.Network.AddKnowledge(Knowledge); LearnFromSourceAgent = new LearnFromSourceAgent(Organization.NextEntityIndex(), this); LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel, - Organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics); + Organization.Templates.Human.Cognitive.InternalCharacteristics); LearnByDoingAgent = new LearnByDoingAgent(Organization.NextEntityIndex(), this); LearnByDoingAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel, - Organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics); + Organization.Templates.Human.Cognitive.InternalCharacteristics); LearnByAskingAgent = new LearnByAskingAgent(Organization.NextEntityIndex(), this); LearnByAskingAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel, - Organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics); + Organization.Templates.Human.Cognitive.InternalCharacteristics); DoesNotLearnAgent = new LearnAgent(Organization.NextEntityIndex(), this); DoesNotLearnAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel, - Organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics); + Organization.Templates.Human.Cognitive.InternalCharacteristics); ExpertAgent = new ExpertAgent(Organization.NextEntityIndex(), this); ExpertAgent.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; ExpertAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel.Expert, - Organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics); + Organization.Templates.Human.Cognitive.InternalCharacteristics); + // Set active link between expert and LearnByAskingAgent to be able to exchange information + WhitePages.Network.NetworkLinks.AddLink(LearnByAskingAgent.Id, ExpertAgent.Id); } } } \ No newline at end of file diff --git a/Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs b/Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs index dff293a9..8bebbf80 100644 --- a/Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs +++ b/Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,10 +10,10 @@ #region using directives using System; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Common; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; #endregion @@ -28,7 +28,7 @@ public ExpertAgent(ushort agentKey, SymuEnvironment environment) : base( new AgentId(agentKey, ClassKey), environment) { - SetCognitive(Environment.Organization.Templates.SimpleHuman); + SetCognitive(Environment.Organization.Templates.Human); Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; } diff --git a/Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs b/Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs index 15f4f169..9c01e5cf 100644 --- a/Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs +++ b/Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,12 +10,12 @@ #region using directives using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Task; using SymuEngine.Classes.Task.Manager; using SymuEngine.Common; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository.Networks.Databases; using SymuEngine.Repository.Networks.Knowledges; @@ -31,7 +31,7 @@ public LearnAgent(ushort agentKey, SymuEnvironment environment) : base( new AgentId(agentKey, ClassKey), environment) { - SetCognitive(Environment.Organization.Templates.SimpleHuman); + SetCognitive(Environment.Organization.Templates.Human); Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; Cognitive.TasksAndPerformance.TasksLimit.LimitSimultaneousTasks = true; Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = CommunicationMediums.ViaAPlatform; diff --git a/Symu examples/SymuLearnAndForget/Classes/LearnByAskingAgent.cs b/Symu examples/SymuLearnAndForget/Classes/LearnByAskingAgent.cs index fb71c3c4..913a8e8f 100644 --- a/Symu examples/SymuLearnAndForget/Classes/LearnByAskingAgent.cs +++ b/Symu examples/SymuLearnAndForget/Classes/LearnByAskingAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; #endregion diff --git a/Symu examples/SymuLearnAndForget/Classes/LearnByDOingAgent.cs b/Symu examples/SymuLearnAndForget/Classes/LearnByDOingAgent.cs index 37101396..ac45c56a 100644 --- a/Symu examples/SymuLearnAndForget/Classes/LearnByDOingAgent.cs +++ b/Symu examples/SymuLearnAndForget/Classes/LearnByDOingAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuLearnAndForget/Classes/LearnFromSourceAgent.cs b/Symu examples/SymuLearnAndForget/Classes/LearnFromSourceAgent.cs index e9659354..4a79623e 100644 --- a/Symu examples/SymuLearnAndForget/Classes/LearnFromSourceAgent.cs +++ b/Symu examples/SymuLearnAndForget/Classes/LearnFromSourceAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuLearnAndForget/Home.cs b/Symu examples/SymuLearnAndForget/Home.cs index a1633e8e..ad6fa981 100644 --- a/Symu examples/SymuLearnAndForget/Home.cs +++ b/Symu examples/SymuLearnAndForget/Home.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,7 +14,7 @@ using System.Globalization; using System.Linq; using System.Windows.Forms; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Classes.Scenario; using SymuEngine.Common; using SymuEngine.Engine.Form; @@ -22,7 +22,7 @@ using SymuEngine.Repository.Networks.Databases; using SymuEngine.Repository.Networks.Knowledges; using SymuLearnAndForget.Classes; -using SymuTools.Algorithm; +using static SymuTools.Constants; #endregion @@ -56,40 +56,40 @@ private void LoadSettings() cbLearningOn.Checked = true; tbMicroLearningAgentRate.Text = "1"; - cbHasInitialKnowledge.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs + cbHasInitialKnowledge.Checked = OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs .HasInitialKnowledge; cbInitialKnowledgeLevel.Items.AddRange(KnowledgeLevelService.GetNames()); cbInitialKnowledgeLevel.SelectedItem = KnowledgeLevelService.GetName(_environment.KnowledgeLevel); cbHasKnowledge.Checked = - OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasKnowledge; + OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasKnowledge; tbKnowledgeThreshold.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing + OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing .ToString(CultureInfo.InvariantCulture); tbTimeToLive.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.TimeToLive.ToString( + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.TimeToLive.ToString( CultureInfo.InvariantCulture); tbLearnRate.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningRate.ToString(CultureInfo + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.LearningRate.ToString(CultureInfo .InvariantCulture); tbLearnByDoingRate.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningByDoingRate.ToString( + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.LearningByDoingRate.ToString( CultureInfo.InvariantCulture); tbTaskCostFactor.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CostFactorOfLearningByDoing + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.CostFactorOfLearningByDoing .ToString(CultureInfo.InvariantCulture); cbCanSendKnowledge.Checked = - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.CanSendKnowledge; + OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanSendKnowledge; cbCanReceiveKnowledge.Checked = - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.CanReceiveKnowledge; + OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanReceiveKnowledge; // Email tbMinKnowledge.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit.ToString( + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit.ToString( CultureInfo.InvariantCulture); tbMinBitsKnowledge.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend .ToString(CultureInfo.InvariantCulture); tbMaxBitsKnowledge.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend .ToString(CultureInfo.InvariantCulture); tbMaxRateLearnable.Text = OrganizationEntity.Templates.Email.MaxRateLearnable.ToString(CultureInfo.InvariantCulture); @@ -101,21 +101,21 @@ private void LoadSettings() cbForgettingOn.Checked = true; tbForgettingAgentRate.Text = "1"; tbForgettingMean.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingMean.ToString( + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.ForgettingMean.ToString( CultureInfo.InvariantCulture); cgForgettingStdDev.Items.AddRange(GenericLevelService.GetNames()); cgForgettingStdDev.SelectedItem = - GenericLevelService.GetName(OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics + GenericLevelService.GetName(OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics .ForgettingStandardDeviation); - cbPartialForgetting.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics + cbPartialForgetting.Checked = OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics .PartialForgetting; tbPartialForgettingRate.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.PartialForgettingRate + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.PartialForgettingRate .ToString(CultureInfo.InvariantCulture); tbMinimRemainningLevel.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge .ToString(CultureInfo.InvariantCulture); - switch (OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode) + switch (OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode) { case ForgettingSelectingMode.Random: rbICForgettingSelectingRandomMode.Checked = true; @@ -141,7 +141,7 @@ protected override void SetUpOrganization() protected override void SetScenarii() { - _ = new TimeStepScenario(OrganizationEntity.NextEntityIndex(), _environment) + _ = new TimeStepScenario(_environment) { NumberOfSteps = ushort.Parse(tbSteps.Text) }; @@ -160,20 +160,20 @@ private void Button1_Click(object sender, EventArgs e) #region Learning OrganizationEntity.Models.Learning.On = cbLearningOn.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasKnowledge = + OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasKnowledge = cbHasKnowledge.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = + OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = cbHasInitialKnowledge.Checked; _environment.KnowledgeLevel = KnowledgeLevelService.GetValue(cbInitialKnowledgeLevel.SelectedItem.ToString()); - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.CanSendKnowledge = + OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanSendKnowledge = cbCanSendKnowledge.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.CanReceiveKnowledge = + OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanReceiveKnowledge = cbCanReceiveKnowledge.Checked; // In this example: // we use email, but we can use other communications medium - // we set the email template with the same values of SimpleHuman Template, but it could be different + // we set the email template with the same values of Human Template, but it could be different OrganizationEntity.Templates.Email.Cognitive.MessageContent.CanSendKnowledge = cbCanSendKnowledge.Checked; OrganizationEntity.Templates.Email.Cognitive.MessageContent.CanReceiveKnowledge = cbCanReceiveKnowledge.Checked; @@ -183,11 +183,11 @@ private void Button1_Click(object sender, EventArgs e) #region Forgetting OrganizationEntity.Models.Forgetting.On = cbForgettingOn.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingStandardDeviation = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.ForgettingStandardDeviation = GenericLevelService.GetValue(cgForgettingStdDev.SelectedItem.ToString()); - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.PartialForgetting = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.PartialForgetting = cbPartialForgetting.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = rbICForgettingSelectingRandomMode.Checked ? ForgettingSelectingMode.Random : ForgettingSelectingMode.Oldest; @@ -266,7 +266,7 @@ public override void Display() // Wiki WriteTextSafe(lblWiki, _wiki.GetKnowledgesSum().ToString("F1", CultureInfo.InvariantCulture)); if (_fullKnowledge == 0 && - Math.Abs(_wiki.GetKnowledgesSum() - _environment.Knowledge.Length) < Constants.Tolerance) + Math.Abs(_wiki.GetKnowledgesSum() - _environment.Knowledge.Length) < Tolerance) { _fullKnowledge = _environment.TimeStep.Step; } @@ -372,7 +372,7 @@ private void tbKnowledgeThreshold_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing = + OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing = float.Parse(tbKnowledgeThreshold.Text, CultureInfo.InvariantCulture); tbKnowledgeThreshold.BackColor = SystemColors.Window; } @@ -391,7 +391,7 @@ private void tbLearnRate_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningRate = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.LearningRate = float.Parse(tbLearnRate.Text, CultureInfo.InvariantCulture); tbLearnRate.BackColor = SystemColors.Window; } @@ -410,7 +410,7 @@ private void tbLearnByDoingRate_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningByDoingRate = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.LearningByDoingRate = float.Parse(tbLearnByDoingRate.Text, CultureInfo.InvariantCulture); tbLearnByDoingRate.BackColor = SystemColors.Window; } @@ -429,7 +429,7 @@ private void tbTaskCostFactor_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CostFactorOfLearningByDoing = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.CostFactorOfLearningByDoing = float.Parse(tbTaskCostFactor.Text, CultureInfo.InvariantCulture); tbTaskCostFactor.BackColor = SystemColors.Window; } @@ -448,7 +448,7 @@ private void tbMinKnowledge_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit = + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit = float.Parse(tbMinKnowledge.Text, CultureInfo.InvariantCulture); OrganizationEntity.Templates.Email.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit = float.Parse(tbMinKnowledge.Text, CultureInfo.InvariantCulture); @@ -469,7 +469,7 @@ private void tbMinBitsKnowledge_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = byte.Parse(tbMinBitsKnowledge.Text, CultureInfo.InvariantCulture); OrganizationEntity.Templates.Email.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = byte.Parse(tbMinBitsKnowledge.Text, CultureInfo.InvariantCulture); @@ -490,7 +490,7 @@ private void tbMaxBitsKnowledge_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = + OrganizationEntity.Templates.Human.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = byte.Parse(tbMaxBitsKnowledge.Text, CultureInfo.InvariantCulture); OrganizationEntity.Templates.Email.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = byte.Parse(tbMaxBitsKnowledge.Text, CultureInfo.InvariantCulture); @@ -549,7 +549,7 @@ private void tbForgettingMean_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingMean = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.ForgettingMean = float.Parse(tbForgettingMean.Text, CultureInfo.InvariantCulture); tbForgettingMean.BackColor = SystemColors.Window; } @@ -568,7 +568,7 @@ private void tbTimeToLive_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.TimeToLive = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.TimeToLive = short.Parse(tbTimeToLive.Text, CultureInfo.InvariantCulture); tbTimeToLive.BackColor = SystemColors.Window; } @@ -587,7 +587,7 @@ private void tbPartialForgettingRate_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.PartialForgettingRate = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.PartialForgettingRate = float.Parse(tbPartialForgettingRate.Text, CultureInfo.InvariantCulture); tbPartialForgettingRate.BackColor = SystemColors.Window; } @@ -606,7 +606,7 @@ private void tbMinimRemainningLevel_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge = + OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge = float.Parse(tbMinimRemainningLevel.Text, CultureInfo.InvariantCulture); tbMinimRemainningLevel.BackColor = SystemColors.Window; } diff --git a/Symu examples/SymuLearnAndForget/Program.cs b/Symu examples/SymuLearnAndForget/Program.cs index 62f79329..f746352b 100644 --- a/Symu examples/SymuLearnAndForget/Program.cs +++ b/Symu examples/SymuLearnAndForget/Program.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuLearnAndForget/Properties/AssemblyInfo.cs b/Symu examples/SymuLearnAndForget/Properties/AssemblyInfo.cs index e5e9d2a9..cde3cab1 100644 --- a/Symu examples/SymuLearnAndForget/Properties/AssemblyInfo.cs +++ b/Symu examples/SymuLearnAndForget/Properties/AssemblyInfo.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForget -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuLearnAndForget/Properties/Resources.Designer.cs b/Symu examples/SymuLearnAndForget/Properties/Resources.Designer.cs index 67184a28..15221ffd 100644 --- a/Symu examples/SymuLearnAndForget/Properties/Resources.Designer.cs +++ b/Symu examples/SymuLearnAndForget/Properties/Resources.Designer.cs @@ -25,7 +25,7 @@ internal class Resources { private static global::System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Density", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } diff --git a/Symu examples/SymuLearnAndForgetTests/IntegrationTests.cs b/Symu examples/SymuLearnAndForgetTests/IntegrationTests.cs index a6cd1e2d..381212d5 100644 --- a/Symu examples/SymuLearnAndForgetTests/IntegrationTests.cs +++ b/Symu examples/SymuLearnAndForgetTests/IntegrationTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuLearnAndForgetTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Classes.Organization; using SymuEngine.Classes.Scenario; using SymuEngine.Common; @@ -41,7 +41,7 @@ public void Initialize() { _environment.SetOrganization(_organization); _simulation.SetEnvironment(_environment); - var scenario = new TimeStepScenario(_environment.Organization.NextEntityIndex(), _environment) + var scenario = new TimeStepScenario(_environment) { NumberOfSteps = 10 }; @@ -67,7 +67,7 @@ public void LearnByDoingTest() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = false; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = false; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByDoingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -81,7 +81,7 @@ public void LearnByDoingTest1() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.IsTrue(0 < _environment.LearnByDoingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); @@ -96,7 +96,7 @@ public void LearnByDoingTest2() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _organization.Models.Generator = RandomGenerator.RandomBinary; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); @@ -114,9 +114,9 @@ public void LearnByDoingTest3() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _organization.Models.Generator = RandomGenerator.RandomBinary; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing = 0; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.KnowledgeThreshHoldForDoing = 0; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); // Should be > 0 because Knowledge threshold for doing is == 0, agent has the knowledge or not but he can't learn @@ -132,7 +132,7 @@ public void LearnByDoingTest4() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningByDoingRate = 0; + _organization.Templates.Human.Cognitive.TasksAndPerformance.LearningByDoingRate = 0; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByDoingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); @@ -164,7 +164,7 @@ public void LearnByAskingTest1() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit = 1; + _organization.Templates.Human.Cognitive.MessageContent.MinimumKnowledgeToSendPerBit = 1; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByAskingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -178,7 +178,7 @@ public void LearnByAskingTest2() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.MessageContent.CanReceiveKnowledge = false; + _organization.Templates.Human.Cognitive.MessageContent.CanReceiveKnowledge = false; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByAskingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -192,7 +192,7 @@ public void LearnByAskingTest3() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.MessageContent.CanSendKnowledge = false; + _organization.Templates.Human.Cognitive.MessageContent.CanSendKnowledge = false; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByAskingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -220,8 +220,8 @@ public void LearnByAskingTest5() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = 0; - _organization.Templates.SimpleHuman.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = 0; + _organization.Templates.Human.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = 0; + _organization.Templates.Human.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = 0; _organization.Templates.Email.Cognitive.MessageContent.MinimumNumberOfBitsOfKnowledgeToSend = 0; _organization.Templates.Email.Cognitive.MessageContent.MaximumNumberOfBitsOfKnowledgeToSend = 0; _simulation.Process(); @@ -237,7 +237,7 @@ public void LearnByAskingTest6() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningRate = 0; + _organization.Templates.Human.Cognitive.TasksAndPerformance.LearningRate = 0; _simulation.Process(); Assert.AreEqual(0, _environment.LearnByAskingAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -267,7 +267,7 @@ public void LearnFromSourceTest1() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.LearningRate = 0; + _organization.Templates.Human.Cognitive.TasksAndPerformance.LearningRate = 0; _simulation.Process(); Assert.AreEqual(0, _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); } @@ -314,7 +314,7 @@ public void LearnWithInitialFullKnowledgeTest(RandomGenerator model) { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _organization.Models.Generator = model; _environment.KnowledgeLevel = KnowledgeLevel.FullKnowledge; _simulation.Process(); @@ -338,7 +338,7 @@ public void HasNoKnowledgeTest() { _organization.Models.Learning.On = true; _organization.Models.Learning.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasKnowledge = false; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasKnowledge = false; _simulation.Process(); // Should be = 0 because fullKnowledge => nothing to learn Assert.AreEqual(0, _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Learning); @@ -364,11 +364,11 @@ public void ForgettingTest() { _organization.Models.Forgetting.On = true; _organization.Models.Forgetting.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.TimeToLive = 0; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + _organization.Templates.Human.Cognitive.InternalCharacteristics.TimeToLive = 0; + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Oldest; // must have some knowledge to forget - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.IsTrue(0 > _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Forgetting); @@ -385,10 +385,10 @@ public void ForgettingTest2() { _organization.Models.Forgetting.On = true; _organization.Models.Forgetting.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Random; // must have some knowledge to forget - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.IsTrue(0 > _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Forgetting); @@ -405,10 +405,10 @@ public void TimeToLiveTest() { _organization.Models.Forgetting.On = true; _organization.Models.Forgetting.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.TimeToLive = -1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + _organization.Templates.Human.Cognitive.InternalCharacteristics.TimeToLive = -1; + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Oldest; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.AreEqual(0, _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Forgetting); @@ -425,10 +425,10 @@ public void ForgettingMeanTest() { _organization.Models.Forgetting.On = true; _organization.Models.Forgetting.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Random; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingMean = 0; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingMean = 0; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.AreEqual(0, _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Forgetting); @@ -445,12 +445,12 @@ public void NoRemainingKnowledgeTest() { _organization.Models.Forgetting.On = true; _organization.Models.Forgetting.RateOfAgentsOn = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingSelectingMode = + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Random; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.ForgettingMean = 1; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.PartialForgetting = false; - _organization.Templates.SimpleHuman.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge = 0; - _organization.Templates.SimpleHuman.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; + _organization.Templates.Human.Cognitive.InternalCharacteristics.ForgettingMean = 1; + _organization.Templates.Human.Cognitive.InternalCharacteristics.PartialForgetting = false; + _organization.Templates.Human.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge = 0; + _organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; _environment.KnowledgeLevel = KnowledgeLevel.Expert; _simulation.Process(); Assert.AreNotEqual(0, _environment.LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.Expertise.Forgetting); diff --git a/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs b/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs index 460e51d2..919ac64a 100644 --- a/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using System; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents.Models.Templates.Communication; using SymuEngine.Environment; #endregion @@ -101,7 +101,7 @@ public float SwitchingContextCost public override void SetModelForAgents() { base.SetModelForAgents(); - Organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.IsolationIsRandom = true; + Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationIsRandom = true; Organization.Models.FollowTasks = true; var group = new GroupAgent(Organization.NextEntityIndex(), this); for (var i = 0; i < WorkersCount; i++) diff --git a/Symu examples/SymuMessageAndTask/Classes/GroupAgent.cs b/Symu examples/SymuMessageAndTask/Classes/GroupAgent.cs index 73d56fcd..de245a84 100644 --- a/Symu examples/SymuMessageAndTask/Classes/GroupAgent.cs +++ b/Symu examples/SymuMessageAndTask/Classes/GroupAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,10 +11,10 @@ using System; using System.Collections.Generic; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Task; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; #endregion diff --git a/Symu examples/SymuMessageAndTask/Classes/PersonAgent.cs b/Symu examples/SymuMessageAndTask/Classes/PersonAgent.cs index eddd3a1f..0ac9fdd0 100644 --- a/Symu examples/SymuMessageAndTask/Classes/PersonAgent.cs +++ b/Symu examples/SymuMessageAndTask/Classes/PersonAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,11 +11,11 @@ using System; using System.Collections.Generic; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Task; using SymuEngine.Classes.Task.Manager; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; #endregion @@ -30,7 +30,7 @@ public PersonAgent(ushort agentKey, SymuEnvironment environment) : base( new AgentId(agentKey, ClassKey), environment) { - SetCognitive(Environment.Organization.Templates.SimpleHuman); + SetCognitive(Environment.Organization.Templates.Human); // Communication medium Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = CommunicationMediums.Email; @@ -92,12 +92,14 @@ private void ActTasks(Message message) } // Get new tasks - if (message.Attachments.First is List tasks) + if (!(message.Attachments.First is List tasks)) { - foreach (var task in tasks) - { - TaskProcessor.Post(task); - } + return; + } + + foreach (var task in tasks) + { + TaskProcessor.Post(task); } } diff --git a/Symu examples/SymuMessageAndTask/Home.Designer.cs b/Symu examples/SymuMessageAndTask/Home.Designer.cs index 676c934c..2b4398ff 100644 --- a/Symu examples/SymuMessageAndTask/Home.Designer.cs +++ b/Symu examples/SymuMessageAndTask/Home.Designer.cs @@ -78,6 +78,8 @@ private void InitializeComponent() this.cbRandomLevel = new System.Windows.Forms.ComboBox(); this.groupBox10 = new System.Windows.Forms.GroupBox(); this.groupBox7 = new System.Windows.Forms.GroupBox(); + this.SwitchingContextCost = new System.Windows.Forms.TextBox(); + this.label21 = new System.Windows.Forms.Label(); this.costOfTask = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.numberTasksSent = new System.Windows.Forms.TextBox(); @@ -95,8 +97,6 @@ private void InitializeComponent() this.maxNumberTasks = new System.Windows.Forms.TextBox(); this.label16 = new System.Windows.Forms.Label(); this.CanPerformTask = new System.Windows.Forms.CheckBox(); - this.SwitchingContextCost = new System.Windows.Forms.TextBox(); - this.label21 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox5.SuspendLayout(); @@ -362,9 +362,9 @@ private void InitializeComponent() this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(428, 151); this.richTextBox1.TabIndex = 17; - this.richTextBox1.Text = "Goal:\nMessgae and task models are implemented in Symu.\nThe objective of this exam" + - "ple is to show how to use, configure and see the impacts of those models on agen" + - "ts."; + this.richTextBox1.Text = "Goal:\nMessaging and tasking models are implemented in Symu.\nThe objective of this" + + " example is to show how to use, configure and see the impacts of those models on" + + " agents."; // // groupBox5 // @@ -417,7 +417,7 @@ private void InitializeComponent() this.groupBox11.Size = new System.Drawing.Size(374, 346); this.groupBox11.TabIndex = 16; this.groupBox11.TabStop = false; - this.groupBox11.Text = "Message model"; + this.groupBox11.Text = "Messaging model"; // // CostToReceive // @@ -602,7 +602,7 @@ private void InitializeComponent() this.groupBox10.Size = new System.Drawing.Size(403, 491); this.groupBox10.TabIndex = 13; this.groupBox10.TabStop = false; - this.groupBox10.Text = "Task model"; + this.groupBox10.Text = "Tasking model"; // // groupBox7 // @@ -619,6 +619,23 @@ private void InitializeComponent() this.groupBox7.TabStop = false; this.groupBox7.Text = "Task"; // + // SwitchingContextCost + // + this.SwitchingContextCost.Location = new System.Drawing.Point(281, 106); + this.SwitchingContextCost.Name = "SwitchingContextCost"; + this.SwitchingContextCost.Size = new System.Drawing.Size(87, 22); + this.SwitchingContextCost.TabIndex = 32; + this.SwitchingContextCost.TextChanged += new System.EventHandler(this.SwitchingContextCost_TextChanged); + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(25, 106); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(146, 17); + this.label21.TabIndex = 31; + this.label21.Text = "Switching context cost"; + // // costOfTask // this.costOfTask.Location = new System.Drawing.Point(281, 76); @@ -783,23 +800,6 @@ private void InitializeComponent() this.CanPerformTask.Text = "Can perform task"; this.CanPerformTask.UseVisualStyleBackColor = true; // - // SwitchingContextCost - // - this.SwitchingContextCost.Location = new System.Drawing.Point(281, 106); - this.SwitchingContextCost.Name = "SwitchingContextCost"; - this.SwitchingContextCost.Size = new System.Drawing.Size(87, 22); - this.SwitchingContextCost.TabIndex = 32; - this.SwitchingContextCost.TextChanged += new System.EventHandler(this.SwitchingContextCost_TextChanged); - // - // label21 - // - this.label21.AutoSize = true; - this.label21.Location = new System.Drawing.Point(25, 106); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(183, 21); - this.label21.TabIndex = 31; - this.label21.Text = "Switching context cost"; - // // Home // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); diff --git a/Symu examples/SymuMessageAndTask/Home.cs b/Symu examples/SymuMessageAndTask/Home.cs index 06bd5ecc..b6d27659 100644 --- a/Symu examples/SymuMessageAndTask/Home.cs +++ b/Symu examples/SymuMessageAndTask/Home.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -49,44 +49,44 @@ private void LoadSettings() #region Task model CanPerformTask.Checked = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask; - CanPerformTasksOnWeekends.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask; + CanPerformTasksOnWeekends.Checked = OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance .CanPerformTaskOnWeekEnds; - LimitNumberTasks.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit + LimitNumberTasks.Checked = OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit .LimitTasksInTotal; maxNumberTasks.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal .ToString(CultureInfo.InvariantCulture); - LimitSimultaneousTasks.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance + LimitSimultaneousTasks.Checked = OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance .TasksLimit .LimitSimultaneousTasks; MaxSimultaneousTasks.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit .MaximumSimultaneousTasks .ToString(CultureInfo.InvariantCulture); AgentCanBeIsolated.Items.AddRange(FrequencyLevelService.GetNames()); - AgentCanBeIsolated.SelectedItem = FrequencyLevelService.GetName(OrganizationEntity.Templates.SimpleHuman + AgentCanBeIsolated.SelectedItem = FrequencyLevelService.GetName(OrganizationEntity.Templates.Human .Cognitive.InteractionPatterns.AgentCanBeIsolated); #endregion #region Message model - LimitMessages.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics + LimitMessages.Checked = OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics .LimitMessagesPerPeriod; MaxMessages.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod .ToString(CultureInfo.InvariantCulture); - LimitMessagesSent.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics + LimitMessagesSent.Checked = OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics .LimitMessagesSentPerPeriod; MaxMessagesSent.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics .MaximumMessagesSentPerPeriod .ToString(CultureInfo.InvariantCulture); - LimitMessagesReceived.Checked = OrganizationEntity.Templates.SimpleHuman.Cognitive + LimitMessagesReceived.Checked = OrganizationEntity.Templates.Human.Cognitive .InteractionCharacteristics.LimitReceptionsPerPeriod; MaxMessagesReceived.Text = - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumReceptionsPerPeriod + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.MaximumReceptionsPerPeriod .ToString(CultureInfo.InvariantCulture); CostToSend.Items.AddRange(GenericLevelService.GetNames()); @@ -107,7 +107,7 @@ protected override void SetUpOrganization() protected override void SetScenarii() { - _ = new TimeStepScenario(OrganizationEntity.NextEntityIndex(), _environment) + _ = new TimeStepScenario(_environment) { NumberOfSteps = ushort.Parse(tbSteps.Text) }; @@ -123,16 +123,16 @@ private void Button1_Click(object sender, EventArgs e) { #region Task model - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = CanPerformTask.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = CanPerformTasksOnWeekends.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit .LimitTasksInTotal = LimitNumberTasks.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit .LimitSimultaneousTasks = LimitSimultaneousTasks.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = + OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = FrequencyLevelService.GetValue(AgentCanBeIsolated.SelectedItem.ToString()); try { @@ -148,11 +148,11 @@ private void Button1_Click(object sender, EventArgs e) #region message - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = LimitMessages.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesSentPerPeriod = + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesSentPerPeriod = LimitMessagesSent.Checked; - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitReceptionsPerPeriod = + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.LimitReceptionsPerPeriod = LimitMessagesReceived.Checked; OrganizationEntity.Templates.Email.CostToSendLevel = @@ -265,7 +265,7 @@ private void maxNumberTasks_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal = + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal = ushort.Parse(maxNumberTasks.Text, CultureInfo.InvariantCulture); maxNumberTasks.BackColor = SystemColors.Window; } @@ -284,7 +284,7 @@ private void MaxSimultaneousTasks_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit + OrganizationEntity.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit .MaximumSimultaneousTasks = byte.Parse(MaxSimultaneousTasks.Text, CultureInfo.InvariantCulture); MaxSimultaneousTasks.BackColor = SystemColors.Window; @@ -309,7 +309,7 @@ private void MaxMessages_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = byte.Parse(MaxMessages.Text, CultureInfo.InvariantCulture); MaxMessages.BackColor = SystemColors.Window; } @@ -328,7 +328,7 @@ private void MaxMessagesSent_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics .MaximumMessagesSentPerPeriod = byte.Parse(MaxMessagesSent.Text, CultureInfo.InvariantCulture); MaxMessagesSent.BackColor = SystemColors.Window; @@ -348,7 +348,7 @@ private void MaxMessagesReceived_TextChanged(object sender, EventArgs e) { try { - OrganizationEntity.Templates.SimpleHuman.Cognitive.InteractionCharacteristics + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics .MaximumReceptionsPerPeriod = byte.Parse(MaxMessagesReceived.Text, CultureInfo.InvariantCulture); MaxMessagesReceived.BackColor = SystemColors.Window; diff --git a/Symu examples/SymuMessageAndTask/Program.cs b/Symu examples/SymuMessageAndTask/Program.cs index bd666d9b..ead2b0b0 100644 --- a/Symu examples/SymuMessageAndTask/Program.cs +++ b/Symu examples/SymuMessageAndTask/Program.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuMessageAndTask/Properties/AssemblyInfo.cs b/Symu examples/SymuMessageAndTask/Properties/AssemblyInfo.cs index 9ba51b30..231a74aa 100644 --- a/Symu examples/SymuMessageAndTask/Properties/AssemblyInfo.cs +++ b/Symu examples/SymuMessageAndTask/Properties/AssemblyInfo.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTask -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu examples/SymuMessageAndTask/Properties/Resources.Designer.cs b/Symu examples/SymuMessageAndTask/Properties/Resources.Designer.cs index d4622fa4..b7044380 100644 --- a/Symu examples/SymuMessageAndTask/Properties/Resources.Designer.cs +++ b/Symu examples/SymuMessageAndTask/Properties/Resources.Designer.cs @@ -28,7 +28,7 @@ internal class Resources { private static global::System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Density", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } diff --git a/Symu examples/SymuMessageAndTaskTests/IntegrationTests.cs b/Symu examples/SymuMessageAndTaskTests/IntegrationTests.cs index ab431c7d..e53d7043 100644 --- a/Symu examples/SymuMessageAndTaskTests/IntegrationTests.cs +++ b/Symu examples/SymuMessageAndTaskTests/IntegrationTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuMessageAndTaskTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -38,7 +38,7 @@ public void Initialize() { _environment.SetOrganization(_organization); _simulation.SetEnvironment(_environment); - var scenario = new TimeStepScenario(_environment.Organization.NextEntityIndex(), _environment) + var scenario = new TimeStepScenario(_environment) { NumberOfSteps = NumberOfSteps }; @@ -55,7 +55,7 @@ public void Initialize() [TestMethod] public void TaskModelOffTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = false; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = false; _simulation.Process(); Assert.AreEqual(0, _environment.IterationResult.Tasks.Total); } @@ -66,11 +66,11 @@ public void TaskModelOffTest() [TestMethod] public void TaskModelOnTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; _simulation.Process(); var total = _environment.IterationResult.Tasks.Total; Assert.IsTrue(total > 0); - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; _simulation.Process(); var total2 = _environment.IterationResult.Tasks.Total; Assert.IsTrue(total2 > total); @@ -79,8 +79,8 @@ public void TaskModelOnTest() [TestMethod] public void TotalWeight() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _simulation.Process(); @@ -94,8 +94,8 @@ public void TotalWeight() [TestMethod] public void TotalWeight1() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _environment.CostOfTask = 0; @@ -110,7 +110,7 @@ public void TotalWeight1() [TestMethod] public void ToDoTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; _environment.NumberOfTasks = 10; _simulation.Process(); Assert.AreEqual(0, _environment.IterationResult.Tasks.AverageToDo); @@ -122,9 +122,9 @@ public void ToDoTest() [TestMethod] public void ToDoTest1() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.LimitSimultaneousTasks = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.MaximumSimultaneousTasks = 1; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.LimitSimultaneousTasks = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.MaximumSimultaneousTasks = 1; _environment.NumberOfTasks = 10; _simulation.Process(); Assert.IsTrue(0 < _environment.IterationResult.Tasks.AverageToDo); @@ -133,7 +133,7 @@ public void ToDoTest1() [TestMethod] public void InProgressTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; _environment.InitialCapacity = 0.1F; _simulation.Process(); Assert.IsTrue(0 < _environment.IterationResult.Tasks.AverageInProgress); @@ -143,10 +143,10 @@ public void InProgressTest() public void LimitNumberOfTasksTest() { const ushort number = 4; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.LimitTasksInTotal = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal = number; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.LimitTasksInTotal = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.TasksLimit.MaximumTasksInTotal = number; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _simulation.Process(); @@ -156,8 +156,8 @@ public void LimitNumberOfTasksTest() [TestMethod] public void AgentCanBeIsolatedTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Always; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Always; _simulation.Process(); Assert.AreEqual(0, _environment.IterationResult.Tasks.Total); Assert.AreEqual(0, _environment.IterationResult.Capacity); @@ -166,8 +166,8 @@ public void AgentCanBeIsolatedTest() [TestMethod] public void RandomLevelTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _environment.SetRandomLevel(3); @@ -179,8 +179,8 @@ public void RandomLevelTest() [TestMethod] public void SwitchingContextTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _environment.SwitchingContextCost = 2; @@ -200,8 +200,8 @@ public void SwitchingContextTest() [TestMethod] public void LimitMessageTest() { - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 0; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 0; _simulation.Process(); Assert.AreEqual(0, (int) _environment.Messages.SentMessagesCount); Assert.AreEqual(0, _environment.IterationResult.Tasks.Total); @@ -213,10 +213,10 @@ public void LimitMessageTest() [TestMethod] public void LimitMessageTest1() { - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 1; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 1; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; _simulation.Process(); Assert.AreEqual(_environment.WorkersCount * NumberOfSteps, (int) _environment.Messages.SentMessagesCount); Assert.AreEqual(0, _environment.IterationResult.Tasks.Total); @@ -228,11 +228,11 @@ public void LimitMessageTest1() [TestMethod] public void LimitMessageTest2() { - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 2; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesPerPeriod = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesPerPeriod = 2; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _simulation.Process(); @@ -247,13 +247,13 @@ public void LimitMessageTest2() [TestMethod] public void LimitMessageTest3() { - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitMessagesSentPerPeriod = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumMessagesSentPerPeriod = 1; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.LimitReceptionsPerPeriod = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionCharacteristics.MaximumReceptionsPerPeriod = 1; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.LimitMessagesSentPerPeriod = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.MaximumMessagesSentPerPeriod = 1; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.LimitReceptionsPerPeriod = true; + _organization.Templates.Human.Cognitive.InteractionCharacteristics.MaximumReceptionsPerPeriod = 1; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTaskOnWeekEnds = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.None; _organization.Templates.Email.CostToSendLevel = GenericLevel.None; _simulation.Process(); @@ -265,8 +265,8 @@ public void LimitMessageTest3() [TestMethod] public void CostOfMessageTest() { - _organization.Templates.SimpleHuman.Cognitive.TasksAndPerformance.CanPerformTask = true; - _organization.Templates.SimpleHuman.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; + _organization.Templates.Human.Cognitive.TasksAndPerformance.CanPerformTask = true; + _organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; _organization.Templates.Email.CostToReceiveLevel = GenericLevel.Complete; _organization.Templates.Email.CostToSendLevel = GenericLevel.Complete; _simulation.Process(); diff --git a/Symu examples/SymuMessageAndTaskTests/SymuMessageAndTaskTests.csproj b/Symu examples/SymuMessageAndTaskTests/SymuMessageAndTaskTests.csproj index 28b6d1eb..0b73919f 100644 --- a/Symu examples/SymuMessageAndTaskTests/SymuMessageAndTaskTests.csproj +++ b/Symu examples/SymuMessageAndTaskTests/SymuMessageAndTaskTests.csproj @@ -14,7 +14,7 @@ - + diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionStrategy.cs b/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionStrategy.cs deleted file mode 100644 index 3494403e..00000000 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionStrategy.cs +++ /dev/null @@ -1,21 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture -{ - /// - /// Enum the different interaction strategy used in InteractionPatterns - /// - public enum InteractionStrategy - { - Homophily, - DeliberateSearch, - CoWorkers - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalPatterns.cs b/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalPatterns.cs deleted file mode 100644 index cc01ec73..00000000 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalPatterns.cs +++ /dev/null @@ -1,155 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -#region using directives - -using System; -using SymuEngine.Common; -using SymuTools.ProbabilityDistributions; - -#endregion - -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture -{ - /// - /// InteractionPatterns from Construct Software - /// Sphere of interaction - /// Isolation - /// Interactions patterns - /// - /// Interaction Patterns from Construct Software - public class InteractionPatterns - { - public void CopyTo(InteractionPatterns interactionPatterns) - { - if (interactionPatterns is null) - { - throw new ArgumentNullException(nameof(interactionPatterns)); - } - - interactionPatterns.AgentCanBeIsolated = AgentCanBeIsolated; - interactionPatterns.IsolationIsCyclical = IsolationIsCyclical; - interactionPatterns.IsolationIsRandom = IsolationIsRandom; - interactionPatterns.InteractionsDeliberateSearch = InteractionsDeliberateSearch; - interactionPatterns.InteractionsUsingHomophily = InteractionsUsingHomophily; - interactionPatterns.InteractionsWithCoWorkers = InteractionsWithCoWorkers; - } - - #region Sphere of interactions - - #endregion - - #region Isolation - - /// - /// This parameter specify whether agent must be isolated or whether they are active during the entire simulation - /// - public Frequency AgentCanBeIsolated { get; set; } - - public bool IsolationIsCyclical { get; set; } - public bool IsolationIsRandom { get; set; } - - /// - /// Impact of isolation parameter on the capacity to work of the agent - /// - /// true if agent is isolated, false otherwise - public bool IsIsolated() - { - if (!IsolationIsRandom) - { - return false; - } - - float isolationThreshold; - switch (AgentCanBeIsolated) - { - case Frequency.Never: - isolationThreshold = 0; - break; - case Frequency.VeryRarely: - isolationThreshold = 0.1F; - break; - case Frequency.Rarely: - isolationThreshold = 0.3F; - break; - case Frequency.Medium: - isolationThreshold = 0.5F; - break; - case Frequency.Often: - isolationThreshold = 0.7F; - break; - case Frequency.VeryOften: - isolationThreshold = 0.9F; - break; - case Frequency.Always: - isolationThreshold = 1; - break; - default: - throw new ArgumentOutOfRangeException(); - } - - return Bernoulli.Sample(isolationThreshold); - } - - #endregion - - #region Interactions strategy - - /// - /// An agent that acts via homophily attempts to find an interaction partner that shares its characteristics. - /// When searching for suitable partners, the agent will stress agents who have similar socio-demographic parameters, - /// similar knowledge, and similar beliefs - /// Range [0;1] - /// - /// InteractionsUsingHomophily+InteractionsDeliberateSearch+InteractionsWithCoWorkers = 100 - public float InteractionsUsingHomophily { get; set; } - - /// - /// An agent that acts via deliberate search will attempt to find an interaction partner that knows a particular piece - /// of information. - /// When searching for suitable partners, the agent will stress knowledge and will ignore most other parameters. - /// Agents who lack the piece of information will be ignored by the seeker. - /// Range [0;1] - /// - /// InteractionsUsingHomophily+InteractionsDeliberateSearch+InteractionsWithCoWorkers = 100 - public float InteractionsDeliberateSearch { get; set; } - - /// - /// An agent that acts with its co-workers will interact with those agents that are performing a similar task. - /// When searching for interaction partners, the agent will stress tasks primarily and will ignore most other - /// parameters. - /// Agents assigned to other tasks will be ignored by the seeker. - /// Range [0;1] - /// - /// InteractionsUsingHomophily+InteractionsDeliberateSearch+InteractionsWithCoWorkers = 100 - public float InteractionsWithCoWorkers { get; set; } - - /// - /// return a random value of the InteractionStrategy based on InteractionsUsingHomophily, InteractionsDeliberateSearch, - /// InteractionsWithCoWorkers probabilities - /// - /// a random value of InteractionStrategy - public InteractionStrategy NextInteractionStrategy() - { - var index = Categorical.SampleIndex(InteractionsUsingHomophily, InteractionsDeliberateSearch, - InteractionsWithCoWorkers); - switch (index) - { - default: - return InteractionStrategy.Homophily; - case 1: - return InteractionStrategy.DeliberateSearch; - case 2: - return InteractionStrategy.CoWorkers; - } - } - - #endregion - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Classes/Agent/Agent.cs b/Symu source code/SymuEngine/Classes/Agents/Agent.cs similarity index 88% rename from Symu source code/SymuEngine/Classes/Agent/Agent.cs rename to Symu source code/SymuEngine/Classes/Agents/Agent.cs index 27432758..5547f14b 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Agent.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Agent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,26 +14,27 @@ using System.Linq; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; -using SymuEngine.Classes.Agent.Models.Templates; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.Templates; +using SymuEngine.Classes.Agents.Models.Templates.Communication; using SymuEngine.Classes.Blockers; using SymuEngine.Classes.Task; using SymuEngine.Classes.Task.Manager; using SymuEngine.Common; using SymuEngine.Environment; using SymuEngine.Messaging.Manager; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; using SymuEngine.Repository.Networks.Databases; using SymuEngine.Repository.Networks.Knowledges; using SymuTools; -using static SymuTools.Algorithm.Constants; +using SymuTools.Math.ProbabilityDistributions; +using static SymuTools.Constants; #endregion -namespace SymuEngine.Classes.Agent +namespace SymuEngine.Classes.Agents { /// /// An abstract base class for agents. @@ -41,6 +42,8 @@ namespace SymuEngine.Classes.Agent /// public abstract class Agent { + private byte _newInteractionCounter; + /// /// constructor for generic new() /// Use with CreateAgent method @@ -62,9 +65,8 @@ protected Agent(AgentId agentId, SymuEnvironment environment) /// /// The name of the agent. Each agent must have a unique name in its environment. /// Most operations are performed using agent names rather than agent objects. - /// FIPA Norm : AID /// - public virtual AgentId Id { get; set; } + public AgentId Id { get; set; } /// /// State of the agent @@ -155,40 +157,57 @@ protected virtual void SetCognitive(CognitiveArchitectureTemplate agentTemplate) #region Interaction strategy /// - /// Random list of AgentId part of its interaction sphere based on the interaction strategy of the interaction patterns - /// Filtered by the activity, the knowledgeId or the groupId + /// List of AgentId for new interactions : there is no Active link (difference with GetAgentIdsForInteractions) + /// based on the interaction strategy of the interaction patterns : + /// Filtered with interactionStrategy and limit with number of new interactions /// - /// - /// - /// - public IEnumerable GetAgentIdsToInteract(AgentId groupId, string activity, ushort knowledgeId) + public IEnumerable GetAgentIdsForNewInteractions() { - var agentIdsToInteract = new List(); - IEnumerable teammateIds; - switch (Cognitive.InteractionPatterns.NextInteractionStrategy()) + var agentIds = Environment.WhitePages.Network.InteractionSphere.GetAgentIdsForNewInteractions(Id, + Cognitive.InteractionPatterns.NextInteractionStrategy(), Cognitive.InteractionPatterns).ToList(); + return FilterAgentIdsToInteract(agentIds); + } + + /// + /// List of AgentId for interactions : there is Active link (difference with GetAgentIdsForNewInteractions) + /// based on the interaction strategy of the interaction patterns : + /// Filtered with interactionStrategy and limit with number of new interactions + /// + public IEnumerable GetAgentIdsForInteractions() + { + return GetAgentIdsForInteractions(Cognitive.InteractionPatterns.NextInteractionStrategy()); + } + + /// + /// List of AgentId for interactions : there is Active link (difference with GetAgentIdsForNewInteractions) + /// based on the interaction strategy of the interaction patterns : + /// Filtered with interactionStrategy and limit with number of new interactions + /// + public IEnumerable GetAgentIdsForInteractions(InteractionStrategy interactionStrategy) + { + var agentIds = Environment.WhitePages.Network.InteractionSphere + .GetAgentIdsForInteractions(Id, interactionStrategy, Cognitive.InteractionPatterns).ToList(); + return FilterAgentIdsToInteract(agentIds); + } + + public IEnumerable FilterAgentIdsToInteract(List agentIds) + { + if (agentIds == null) { - case InteractionStrategy.Homophily: - // best HomophilyScore (Knowledge, beliefs, socio-demographics - throw new NotImplementedException(); - case InteractionStrategy.DeliberateSearch: - // Having the good knowledge - teammateIds = Environment.WhitePages.Network.GetActiveLinks(Id); - agentIdsToInteract.AddRange( - Environment.WhitePages.Network.NetworkKnowledges.FilterAgentsWithKnowledge(teammateIds, - knowledgeId)); - break; - case InteractionStrategy.CoWorkers: - // Working on the same activity, - teammateIds = Environment.WhitePages.Network.GetActiveLinks(Id); - agentIdsToInteract.AddRange( - Environment.WhitePages.Network.NetworkActivities.FilterAgentIdsWithActivity(teammateIds, - groupId, activity)); - break; - default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentNullException(nameof(agentIds)); } - return agentIdsToInteract; + // Filter the good number of agents + var numberOfNewInteractions = + Cognitive.InteractionPatterns.MaxNumberOfNewInteractions - _newInteractionCounter; + if (Cognitive.InteractionPatterns.LimitNumberOfNewInteractions && numberOfNewInteractions > 0 && + agentIds.Count > numberOfNewInteractions) + { + agentIds.RemoveRange(Cognitive.InteractionPatterns.MaxNumberOfNewInteractions, + agentIds.Count - Cognitive.InteractionPatterns.MaxNumberOfNewInteractions); + } + + return agentIds; } #endregion @@ -364,11 +383,19 @@ public void PostMessage(Message message) throw new ArgumentNullException(nameof(message)); } + // The agent may have received too much messages for the step if (IsMessagesPerPeriodBelowLimit(message.Medium) && IsMessagesReceivedPerPeriodBelowLimit(message.Medium)) { - OnBeforePostMessage(message); - MessageProcessor.Post(message); - OnAfterPostMessage(message); + if (AcceptNewInteraction(message.Sender)) + { + OnBeforePostMessage(message); + MessageProcessor.Post(message); + OnAfterPostMessage(message); + } + else + { + MessageProcessor.AddNotAcceptedMessages(message, Environment.State.Debug); + } } else { @@ -377,7 +404,62 @@ public void PostMessage(Message message) } /// - /// Triggered after message post in the MessageManager + /// The message may be accepted or not depending if it's in its interaction sphere : + /// Or does he accept a new interaction : + /// + /// + /// True if the new interaction has been accepted + public bool AcceptNewInteraction(AgentId senderId) + { + if (Id.Equals(senderId)) + { + // for unit test + return true; + } + + var sender = Environment.WhitePages.GetAgent(senderId); + if (!Cognitive.InteractionPatterns.IsPartOfInteractionSphere || + !sender.Cognitive.InteractionPatterns.IsPartOfInteractionSphere) + { + return true; + } + + if (Environment.WhitePages.Network.NetworkLinks.HasActiveLink(Id, senderId)) + { + return true; + } + + if (!Cognitive.InteractionPatterns.AllowNewInteractions) + { + return false; + } + + if (Cognitive.InteractionPatterns.LimitNumberOfNewInteractions && _newInteractionCounter >= + Cognitive.InteractionPatterns.MaxNumberOfNewInteractions) + { + return false; + } + + // Not in its sphere of interaction (with an active link) + if (!Bernoulli.Sample(Cognitive.InteractionPatterns.ThresholdForNewInteraction)) + { + return false; + } + + _newInteractionCounter++; + + // Decide to positively answer to this new interaction + if (Environment.Organization.Models.InteractionSphere.SphereUpdateOverTime) + { + // Message.Sender is now part of agent interaction sphere + Environment.WhitePages.Network.NetworkLinks.AddLink(Id, senderId); + } + + return true; + } + + /// + /// Triggered before post message in the MessageManager /// /// public virtual void OnBeforePostMessage(Message message) @@ -876,18 +958,6 @@ public Bits FilterBeliefToSend(ushort beliefId, byte beliefBit, CommunicationTem return Cognitive.MessageContent.GetFilteredBeliefToSend(agentBelief, beliefBit, channel); } - /// - /// Agent don't have still this Knowledge, it's time to create one - /// - /// - /// - public void LearnNewKnowledge(ushort knowledgeId, ushort step) - { - Environment.WhitePages.Network.NetworkKnowledges.LearnNewKnowledge(Id, knowledgeId, - Cognitive.InternalCharacteristics.MinimumRemainingKnowledge, - Cognitive.InternalCharacteristics.TimeToLive, step); - } - #endregion #region Act @@ -970,6 +1040,7 @@ public virtual async void PreStep() Email.ForgettingProcess(TimeStep.Step); } + _newInteractionCounter = 0; HandleStatus(); // intentionally after Status HandleCapacity(true); @@ -1046,9 +1117,26 @@ public virtual void PostStep() /// public virtual void ActEndOfDay() { + SendNewInteractions(); TaskProcessor?.TasksManager.TasksCheck(TimeStep.Step); } + /// + /// Send new interactions to augment its sphere of interaction if possible + /// Depends on Cognitive.InteractionPatterns && Cognitive.InteractionCharacteristics + /// + public void SendNewInteractions() + { + var agents = GetAgentIdsForNewInteractions().ToList(); + if (!agents.Any()) + { + return; + } + + // Send new interactions + SendToMany(agents, MessageAction.Ask, SymuYellowPages.Actor, CommunicationMediums.FaceToFace); + } + /// /// Start a weekend, by asking new tasks if agent perform tasks on weekends /// diff --git a/Symu source code/SymuEngine/Classes/Agent/AgentEntity.cs b/Symu source code/SymuEngine/Classes/Agents/AgentEntity.cs similarity index 96% rename from Symu source code/SymuEngine/Classes/Agent/AgentEntity.cs rename to Symu source code/SymuEngine/Classes/Agents/AgentEntity.cs index 88203b6d..2abf3fbe 100644 --- a/Symu source code/SymuEngine/Classes/Agent/AgentEntity.cs +++ b/Symu source code/SymuEngine/Classes/Agents/AgentEntity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuEngine.Classes.Agent +namespace SymuEngine.Classes.Agents { /// /// class for Entity class of the Agent diff --git a/Symu source code/SymuEngine/Classes/Agent/AgentId.cs b/Symu source code/SymuEngine/Classes/Agents/AgentId.cs similarity index 87% rename from Symu source code/SymuEngine/Classes/Agent/AgentId.cs rename to Symu source code/SymuEngine/Classes/Agents/AgentId.cs index 76527800..94244540 100644 --- a/Symu source code/SymuEngine/Classes/Agent/AgentId.cs +++ b/Symu source code/SymuEngine/Classes/Agents/AgentId.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuEngine.Classes.Agent +namespace SymuEngine.Classes.Agents { public struct AgentId { @@ -45,13 +45,13 @@ public AgentId(ushort key, byte classKey) public override bool Equals(object obj) { return obj is AgentId id && - Key == id.Key && - ClassKey == id.ClassKey; + Key == id.Key; //&& + //ClassKey == id.ClassKey; } public bool Equals(AgentId other) { - return Key == other.Key && ClassKey == other.ClassKey; + return Key == other.Key; //&& ClassKey == other.ClassKey; } public override string ToString() diff --git a/Symu source code/SymuEngine/Classes/Agent/AgentStatus.cs b/Symu source code/SymuEngine/Classes/Agents/AgentStatus.cs similarity index 90% rename from Symu source code/SymuEngine/Classes/Agent/AgentStatus.cs rename to Symu source code/SymuEngine/Classes/Agents/AgentStatus.cs index d4864b34..323274b2 100644 --- a/Symu source code/SymuEngine/Classes/Agent/AgentStatus.cs +++ b/Symu source code/SymuEngine/Classes/Agents/AgentStatus.cs @@ -1,13 +1,13 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License #endregion -namespace SymuEngine.Classes.Agent +namespace SymuEngine.Classes.Agents { /// /// Status of the agent during a interaction diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/AgentCapacity.cs b/Symu source code/SymuEngine/Classes/Agents/Models/AgentCapacity.cs similarity index 92% rename from Symu source code/SymuEngine/Classes/Agent/Models/AgentCapacity.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/AgentCapacity.cs index a9486da8..8fe38581 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/AgentCapacity.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/AgentCapacity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,11 +9,11 @@ #region using directives -using static SymuTools.Algorithm.Constants; +using static SymuTools.Constants; #endregion -namespace SymuEngine.Classes.Agent.Models +namespace SymuEngine.Classes.Agents.Models { public class AgentCapacity { diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/AgentTemplates.cs b/Symu source code/SymuEngine/Classes/Agents/Models/AgentTemplates.cs similarity index 78% rename from Symu source code/SymuEngine/Classes/Agent/Models/AgentTemplates.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/AgentTemplates.cs index 673861bd..7cf51c08 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/AgentTemplates.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/AgentTemplates.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,12 +9,12 @@ #region using directives -using SymuEngine.Classes.Agent.Models.Templates; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents.Models.Templates; +using SymuEngine.Classes.Agents.Models.Templates.Communication; #endregion -namespace SymuEngine.Classes.Agent.Models +namespace SymuEngine.Classes.Agents.Models { /// /// List of all available agent templates @@ -27,7 +27,7 @@ namespace SymuEngine.Classes.Agent.Models public class AgentTemplates { public StandardAgentTemplate Standard { get; } = new StandardAgentTemplate(); - public SimpleHumanTemplate SimpleHuman { get; } = new SimpleHumanTemplate(); + public SimpleHumanTemplate Human { get; } = new SimpleHumanTemplate(); public EmailTemplate Email { get; } = new EmailTemplate(); public FaceToFaceTemplate FaceToFace { get; } = new FaceToFaceTemplate(); public IrcTemplate Irc { get; } = new IrcTemplate(); diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/CognitiveArchitecture.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/CognitiveArchitecture.cs similarity index 95% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/CognitiveArchitecture.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/CognitiveArchitecture.cs index fc95881b..129ee3d7 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/CognitiveArchitecture.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/CognitiveArchitecture.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,7 +14,7 @@ #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// Define the cognitive architecture model of an agent @@ -53,7 +53,7 @@ public CognitiveArchitecture(Network network, AgentId agentId, byte randomLevel) public InternalCharacteristics InternalCharacteristics { get; } /// - /// Tasks & Performance from Construct Software + /// Tasks & Density from Construct Software /// MultiTasking /// Performs tasks /// learning by doing diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingMode.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingMode.cs similarity index 84% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingMode.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingMode.cs index 69959ab0..2ecc4cb4 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingMode.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingMode.cs @@ -1,13 +1,13 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// Collection of forgetting modes diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingModel.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingModel.cs similarity index 98% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingModel.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingModel.cs index 6f967797..d2533d47 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/ForgettingModel.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/ForgettingModel.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,11 +13,11 @@ using SymuEngine.Classes.Task.Knowledge; using SymuEngine.Common; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// CognitiveArchitecture define how an actor will forget diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionCharacteristics.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionCharacteristics.cs similarity index 97% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionCharacteristics.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionCharacteristics.cs index 7ef2b911..b39b785e 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InteractionCharacteristics.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionCharacteristics.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using System; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// Interaction Characteristics from Construct Software diff --git a/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionPatterns.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionPatterns.cs new file mode 100644 index 00000000..752e1288 --- /dev/null +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionPatterns.cs @@ -0,0 +1,375 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuEngine.Common; +using SymuTools.Math.ProbabilityDistributions; + +#endregion + +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture +{ + /// + /// InteractionPatterns from Construct Software + /// Sphere of interaction + /// Isolation + /// Interactions patterns + /// + /// Interaction Patterns from Construct Software + public class InteractionPatterns + { + /// + /// If set to true, agent is computed in the interaction sphere + /// + public bool IsPartOfInteractionSphere { get; set; } + + public void CopyTo(InteractionPatterns interactionPatterns) + { + if (interactionPatterns is null) + { + throw new ArgumentNullException(nameof(interactionPatterns)); + } + + interactionPatterns.AgentCanBeIsolated = AgentCanBeIsolated; + interactionPatterns.IsolationIsCyclical = IsolationIsCyclical; + interactionPatterns.IsolationIsRandom = IsolationIsRandom; + interactionPatterns.InteractionsBasedOnKnowledge = InteractionsBasedOnKnowledge; + interactionPatterns.InteractionsBasedOnHomophily = InteractionsBasedOnHomophily; + interactionPatterns.InteractionsBasedOnActivities = InteractionsBasedOnActivities; + interactionPatterns.InteractionsBasedOnBeliefs = InteractionsBasedOnBeliefs; + interactionPatterns.InteractionsBasedOnSocialDemographics = InteractionsBasedOnSocialDemographics; + interactionPatterns.MaxNumberOfNewInteractions = MaxNumberOfNewInteractions; + interactionPatterns.LimitNumberOfNewInteractions = LimitNumberOfNewInteractions; + interactionPatterns.IsPartOfInteractionSphere = IsPartOfInteractionSphere; + interactionPatterns.AllowNewInteractions = AllowNewInteractions; + interactionPatterns.ThresholdForNewInteraction = ThresholdForNewInteraction; + } + + #region Isolation + + /// + /// This parameter specify whether agent must be isolated or whether they are active during the entire simulation + /// + public Frequency AgentCanBeIsolated { get; set; } + + public bool IsolationIsCyclical { get; set; } + public bool IsolationIsRandom { get; set; } + + /// + /// Impact of isolation parameter on the capacity to work of the agent + /// + /// true if agent is isolated, false otherwise + public bool IsIsolated() + { + if (!IsolationIsRandom) + { + return false; + } + + float isolationThreshold; + switch (AgentCanBeIsolated) + { + case Frequency.Never: + isolationThreshold = 0; + break; + case Frequency.VeryRarely: + isolationThreshold = 0.1F; + break; + case Frequency.Rarely: + isolationThreshold = 0.3F; + break; + case Frequency.Medium: + isolationThreshold = 0.5F; + break; + case Frequency.Often: + isolationThreshold = 0.7F; + break; + case Frequency.VeryOften: + isolationThreshold = 0.9F; + break; + case Frequency.Always: + isolationThreshold = 1; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return Bernoulli.Sample(isolationThreshold); + } + + #endregion + + #region Interactions strategy + + private float _interactionsBasedOnHomophily = 1; + + /// + /// An agent that acts via homophily attempts to find an interaction partner that shares its characteristics. + /// When searching for suitable partners, the agent will stress agents who have similar socio-demographic parameters, + /// similar knowledge, and similar beliefs + /// Range [0;1] + /// Default interaction + /// + /// + /// InteractionsBasedOnHomophily+InteractionsBasedOnKnowledge+InteractionsBasedOnActivities+ + /// InteractionsBasedOnBelief+InteractionsBasedOnSocialDemographics= 1 + /// + public float InteractionsBasedOnHomophily + { + get => _interactionsBasedOnHomophily; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("InteractionsBasedOnHomophily should be between [0;1]"); + } + + _interactionsBasedOnHomophily = value; + } + } + + private float _interactionsBasedOnKnowledge; + + /// + /// An agent that acts via deliberate search will attempt to find an interaction partner that knows a particular piece + /// of information. + /// When searching for suitable partners, the agent will stress knowledge and will ignore most other parameters. + /// Agents who lack the piece of information will be ignored by the seeker. + /// Range [0;1] + /// + /// + /// InteractionsBasedOnHomophily+InteractionsBasedOnKnowledge+InteractionsBasedOnActivities+ + /// InteractionsBasedOnBelief+InteractionsBasedOnSocialDemographics= 1 + /// + public float InteractionsBasedOnKnowledge + { + get => _interactionsBasedOnKnowledge; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("InteractionsBasedOnKnowledge should be between [0;1]"); + } + + _interactionsBasedOnKnowledge = value; + } + } + + private float _interactionsBasedOnActivities; + + /// + /// An agent that acts with its co-workers will interact with those agents that are performing a similar task. + /// When searching for interaction partners, the agent will stress tasks primarily and will ignore most other + /// parameters. + /// Agents assigned to other tasks will be ignored by the seeker. + /// Range [0;1] + /// + /// + /// InteractionsBasedOnHomophily+InteractionsBasedOnKnowledge+InteractionsBasedOnActivities+ + /// InteractionsBasedOnBelief+InteractionsBasedOnSocialDemographics= 1 + /// + public float InteractionsBasedOnActivities + { + get => _interactionsBasedOnActivities; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("InteractionsBasedOnActivities should be between [0;1]"); + } + + _interactionsBasedOnActivities = value; + } + } + + private float _interactionsBasedOnBeliefs; + + /// + /// An agent that acts with its co-workers will interact with those agents that have the same beliefs. + /// When searching for interaction partners, the agent will stress tasks primarily and will ignore most other + /// parameters. + /// Range [0;1] + /// + /// + /// InteractionsBasedOnHomophily+InteractionsBasedOnKnowledge+InteractionsBasedOnActivities+ + /// InteractionsBasedOnBelief+InteractionsBasedOnSocialDemographics= 1 + /// + public float InteractionsBasedOnBeliefs + { + get => _interactionsBasedOnBeliefs; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("InteractionsBasedOnBeliefs should be between [0;1]"); + } + + _interactionsBasedOnBeliefs = value; + } + } + + /// + /// An agent that acts with its co-workers will interact with those agents that have the same beliefs. + /// When searching for interaction partners, the agent will stress tasks primarily and will ignore most other + /// parameters. + /// Range [0;1] + /// + /// + /// InteractionsBasedOnHomophily+InteractionsBasedOnKnowledge+InteractionsBasedOnActivities+ + /// InteractionsBasedOnBelief+InteractionsBasedOnSocialDemographics= 1 + /// + private float _interactionsBasedOnSocialDemographics; + + public float InteractionsBasedOnSocialDemographics + { + get => _interactionsBasedOnSocialDemographics; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException( + "InteractionsBasedOnSocialDemographics should be between [0;1]"); + } + + _interactionsBasedOnSocialDemographics = value; + } + } + + /// + /// Set binary interaction pattern based on InteractionStrategy + /// + /// + public void SetInteractionPatterns(InteractionStrategy strategy) + { + switch (strategy) + { + case InteractionStrategy.Homophily: + InteractionsBasedOnHomophily = 1; + InteractionsBasedOnKnowledge = 0; + InteractionsBasedOnActivities = 0; + InteractionsBasedOnBeliefs = 0; + InteractionsBasedOnSocialDemographics = 0; + break; + case InteractionStrategy.Knowledge: + InteractionsBasedOnHomophily = 0; + InteractionsBasedOnKnowledge = 1; + InteractionsBasedOnActivities = 0; + InteractionsBasedOnBeliefs = 0; + InteractionsBasedOnSocialDemographics = 0; + break; + case InteractionStrategy.Activities: + InteractionsBasedOnHomophily = 0; + InteractionsBasedOnKnowledge = 0; + InteractionsBasedOnActivities = 1; + InteractionsBasedOnBeliefs = 0; + InteractionsBasedOnSocialDemographics = 0; + break; + case InteractionStrategy.Beliefs: + InteractionsBasedOnHomophily = 0; + InteractionsBasedOnKnowledge = 0; + InteractionsBasedOnActivities = 0; + InteractionsBasedOnBeliefs = 1; + InteractionsBasedOnSocialDemographics = 0; + break; + case InteractionStrategy.SocialDemographics: + InteractionsBasedOnHomophily = 0; + InteractionsBasedOnKnowledge = 0; + InteractionsBasedOnActivities = 0; + InteractionsBasedOnBeliefs = 0; + InteractionsBasedOnSocialDemographics = 1; + break; + default: + throw new ArgumentOutOfRangeException(nameof(strategy), strategy, null); + } + } + + #endregion + + #region new interactions + + /// + /// If set to true, agent can initiate new interactions. + /// + public bool AllowNewInteractions { get; set; } + + /// + /// If set to true, agent can initiate a limited number of new interactions. + /// It is associated with MaxNumberOfNewInteractions. + /// + public bool LimitNumberOfNewInteractions { get; set; } = true; + + private byte _maxNumberOfNewInteractions = 5; + + /// + /// Maximum number of new interactions per step: + /// a new interaction is a new agent in the sphere of interaction + /// + public byte MaxNumberOfNewInteractions + { + get => _maxNumberOfNewInteractions; + set + { + if (value > 5) + { + throw new ArgumentOutOfRangeException("MaxNumberOfNewInteractions should be <= 5"); + } + + _maxNumberOfNewInteractions = value; + } + } + + private float _thresholdForNewInteraction = 0.2F; + + public float ThresholdForNewInteraction + { + get => _thresholdForNewInteraction; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("ThresholdForNewInteraction should be between [0;1]"); + } + + _thresholdForNewInteraction = value; + } + } + + + /// + /// return a random value of the InteractionStrategy based on InteractionsBasedOnHomophily, + /// InteractionsBasedOnKnowledge, + /// InteractionsBasedOnActivities probabilities + /// + /// a random value of InteractionStrategy + public InteractionStrategy NextInteractionStrategy() + { + var index = Categorical.SampleIndex(InteractionsBasedOnHomophily, InteractionsBasedOnKnowledge, + InteractionsBasedOnActivities, InteractionsBasedOnBeliefs, InteractionsBasedOnSocialDemographics); + switch (index) + { + case 0: + return InteractionStrategy.Homophily; + case 1: + return InteractionStrategy.Knowledge; + case 2: + return InteractionStrategy.Activities; + case 3: + return InteractionStrategy.Beliefs; + case 4: + return InteractionStrategy.SocialDemographics; + default: + throw new ArgumentOutOfRangeException(); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionStrategy.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionStrategy.cs new file mode 100644 index 00000000..f7d2efda --- /dev/null +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InteractionStrategy.cs @@ -0,0 +1,42 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture +{ + /// + /// Enum the different interaction strategy used in InteractionPatterns + /// + public enum InteractionStrategy + { + /// + /// among the interaction sphere, with best Homophily score (Knowledge, beliefs, socio-demographics, activity) + /// + Homophily, + + /// + /// among the interaction sphere, with best Knowledge score + /// + Knowledge, + + /// + /// among the interaction sphere, with best Activities score + /// + Activities, + + /// + /// among the interaction sphere, with best Beliefs score + /// + Beliefs, + + /// + /// among the interaction sphere, with best SocialDemographics score + /// + SocialDemographics + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristics.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristics.cs similarity index 98% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristics.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristics.cs index f38b345f..c12ecbc4 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristics.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristics.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,11 +13,11 @@ using SymuEngine.Common; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// InternalCharacteristics from Construct Software diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs similarity index 99% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs index f2fa0eae..fefbeec6 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -17,7 +17,7 @@ #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// Knowledge & Beliefs from Construct Software diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/MessageContent.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/MessageContent.cs similarity index 97% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/MessageContent.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/MessageContent.cs index 6b2be295..ea1edbb3 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/MessageContent.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/MessageContent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,15 +11,15 @@ using System; using System.Linq; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents.Models.Templates.Communication; using SymuEngine.Repository.Networks.Beliefs; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; -using static SymuTools.Algorithm.Constants; +using SymuTools.Math.ProbabilityDistributions; +using static SymuTools.Constants; #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// /// Message content from Construct Software diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/SituationType.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/SituationType.cs similarity index 74% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/SituationType.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/SituationType.cs index aa795dbb..16a69d97 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/SituationType.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/SituationType.cs @@ -1,13 +1,13 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { public enum SituationType { diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformance.cs b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformance.cs similarity index 95% rename from Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformance.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformance.cs index f38e565b..3ff220ce 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformance.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformance.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -16,21 +16,21 @@ using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Activities; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; -using static SymuTools.Algorithm.Constants; +using SymuTools.Math.ProbabilityDistributions; +using static SymuTools.Constants; #endregion -namespace SymuEngine.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngine.Classes.Agents.Models.CognitiveArchitecture { /// - /// Tasks & Performance from Construct Software + /// Tasks & Density from Construct Software /// Activities /// MultiTasking /// Performs tasks /// learning by doing /// - /// Tasks and Performance from Construct Software + /// Tasks and Density from Construct Software public class TasksAndPerformance { private readonly AgentId _id; @@ -235,11 +235,13 @@ public void Learn(Bits knowledgeBits, float maxRateLearnable, AgentKnowledge age for (byte i = 0; i < knowledgeBits.Length; i++) // other agent must have more knowledge bit than the agent { - if (knowledgeBits.GetBit(i) > 0 && knowledgeBits.GetBit(i) >= agentKnowledge.GetKnowledgeBit(i)) + if (!(knowledgeBits.GetBit(i) > 0) || !(knowledgeBits.GetBit(i) >= agentKnowledge.GetKnowledgeBit(i))) { - var learning = Math.Min(knowledgeBits.GetBit(i), learningRate * maxRateLearnable); - agentKnowledge.Learn(i, learning, step); + continue; } + + var learning = Math.Min(knowledgeBits.GetBit(i), learningRate * maxRateLearnable); + agentKnowledge.Learn(i, learning, step); } } @@ -375,7 +377,7 @@ private static float LearningStandardDeviationValue(GenericLevel level) /// /// Get all the activities of an agent /// - public IEnumerable Activities => _network.NetworkActivities.GetActivities(_id); + public IEnumerable Activities => _network.NetworkActivities.GetGroupActivities(_id); /// /// Add a list of activities an agent can perform @@ -396,7 +398,7 @@ public void AddActivities(IEnumerable activities) /// public IEnumerable GetGroupActivities(AgentId groupId) { - return _network.NetworkActivities.GetActivities(_id, groupId); + return _network.NetworkActivities.GetAgentActivities(_id, groupId); } /// diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/ModelEntity.cs b/Symu source code/SymuEngine/Classes/Agents/Models/ModelEntity.cs similarity index 95% rename from Symu source code/SymuEngine/Classes/Agent/Models/ModelEntity.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/ModelEntity.cs index c6b028c1..91145aee 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/ModelEntity.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/ModelEntity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using System; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion -namespace SymuEngine.Classes.Agent.Models +namespace SymuEngine.Classes.Agents.Models { /// /// Base Class to a simulation model diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/CognitiveArchitectureTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/CognitiveArchitectureTemplate.cs similarity index 90% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/CognitiveArchitectureTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/CognitiveArchitectureTemplate.cs index 08392dd3..07a72e88 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/CognitiveArchitectureTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/CognitiveArchitectureTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuEngine.Classes.Agent.Models.Templates +namespace SymuEngine.Classes.Agents.Models.Templates { /// /// Set all the CognitiveArchitecture parameters for the AgentTemplate diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/CommunicationTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/CommunicationTemplate.cs similarity index 97% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/CommunicationTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/CommunicationTemplate.cs index a8d06be1..3ed99258 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/CommunicationTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/CommunicationTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,11 +11,11 @@ using System; using SymuEngine.Common; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the CommunicationChannels diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/EmailTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/EmailTemplate.cs similarity index 89% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/EmailTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/EmailTemplate.cs index 2fc1c5f5..65355b92 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/EmailTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/EmailTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/FaceToFace.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/FaceToFace.cs similarity index 88% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/FaceToFace.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/FaceToFace.cs index 22b348d9..6b71c64c 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/FaceToFace.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/FaceToFace.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/IRCTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/IRCTemplate.cs similarity index 89% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/IRCTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/IRCTemplate.cs index 36521291..3d37af1a 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/IRCTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/IRCTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/MeetingTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/MeetingTemplate.cs similarity index 88% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/MeetingTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/MeetingTemplate.cs index 7f80dd56..5bbd8a85 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/MeetingTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/MeetingTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/PhoneTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/PhoneTemplate.cs similarity index 88% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/PhoneTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/PhoneTemplate.cs index 56b74296..32b3cab2 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/PhoneTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/PhoneTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/ViaPlatformTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/ViaPlatformTemplate.cs similarity index 89% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/ViaPlatformTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/ViaPlatformTemplate.cs index b5af42af..7f1cdce1 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/Communication/ViaPlatformTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/Communication/ViaPlatformTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates.Communication +namespace SymuEngine.Classes.Agents.Models.Templates.Communication { /// /// Set all the CognitiveArchitecture parameters for the Email diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/InternetAccessTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/InternetAccessTemplate.cs similarity index 95% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/InternetAccessTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/InternetAccessTemplate.cs index e03ea987..3956a3d1 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/InternetAccessTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/InternetAccessTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates +namespace SymuEngine.Classes.Agents.Models.Templates { /// /// Set all the CognitiveArchitecture parameters for the InternetAccessTemplate diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/SimpleHumanTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/SimpleHumanTemplate.cs similarity index 82% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/SimpleHumanTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/SimpleHumanTemplate.cs index 972c256a..4d598357 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/SimpleHumanTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/SimpleHumanTemplate.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,12 +9,12 @@ #region using directives -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Common; #endregion -namespace SymuEngine.Classes.Agent.Models.Templates +namespace SymuEngine.Classes.Agents.Models.Templates { /// /// Set all the CognitiveArchitecture parameters for the Simple human template @@ -63,11 +63,16 @@ public SimpleHumanTemplate() Cognitive.TasksAndPerformance.LearningByDoingRate = 0.1F; Cognitive.TasksAndPerformance.CostFactorOfLearningByDoing = 1.2F; // Cognitive.InteractionPatterns + Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + Cognitive.InteractionPatterns.AllowNewInteractions = true; + Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0.2F; + Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 1; Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Rarely; Cognitive.InteractionPatterns.IsolationIsRandom = true; - Cognitive.InteractionPatterns.InteractionsUsingHomophily = 100; - Cognitive.InteractionPatterns.InteractionsDeliberateSearch = 0; - Cognitive.InteractionPatterns.InteractionsWithCoWorkers = 0; + Cognitive.InteractionPatterns.InteractionsBasedOnHomophily = 1; + Cognitive.InteractionPatterns.InteractionsBasedOnKnowledge = 0; + Cognitive.InteractionPatterns.InteractionsBasedOnActivities = 0; Cognitive.InternalCharacteristics.TimeToLive = 365; } } diff --git a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/StandardAgentTemplate.cs b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/StandardAgentTemplate.cs similarity index 80% rename from Symu source code/SymuEngine/Classes/Agent/Models/Templates/StandardAgentTemplate.cs rename to Symu source code/SymuEngine/Classes/Agents/Models/Templates/StandardAgentTemplate.cs index 59efe456..db3969e4 100644 --- a/Symu source code/SymuEngine/Classes/Agent/Models/Templates/StandardAgentTemplate.cs +++ b/Symu source code/SymuEngine/Classes/Agents/Models/Templates/StandardAgentTemplate.cs @@ -1,13 +1,13 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License #endregion -namespace SymuEngine.Classes.Agent.Models.Templates +namespace SymuEngine.Classes.Agents.Models.Templates { /// /// Set all the CognitiveArchitecture parameters for the standardAgent diff --git a/Symu source code/SymuEngine/Classes/Blockers/Blocker.cs b/Symu source code/SymuEngine/Classes/Blockers/Blocker.cs index dd9119d0..8a4e0e68 100644 --- a/Symu source code/SymuEngine/Classes/Blockers/Blocker.cs +++ b/Symu source code/SymuEngine/Classes/Blockers/Blocker.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Blockers/Blockers.cs b/Symu source code/SymuEngine/Classes/Blockers/Blockers.cs index 9c7079b5..f8829b7c 100644 --- a/Symu source code/SymuEngine/Classes/Blockers/Blockers.cs +++ b/Symu source code/SymuEngine/Classes/Blockers/Blockers.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Murphies/Murphy.cs b/Symu source code/SymuEngine/Classes/Murphies/Murphy.cs index 51f3892c..2e5f6715 100644 --- a/Symu source code/SymuEngine/Classes/Murphies/Murphy.cs +++ b/Symu source code/SymuEngine/Classes/Murphies/Murphy.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteBelief.cs b/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteBelief.cs index 4669b927..85bc440a 100644 --- a/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteBelief.cs +++ b/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteBelief.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,8 +11,8 @@ using SymuEngine.Classes.Task; using SymuEngine.Common; -using SymuEngine.Messaging.Message; -using SymuTools.ProbabilityDistributions; +using SymuEngine.Messaging.Messages; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteKnowledge.cs b/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteKnowledge.cs index 39b2358f..8760ccb2 100644 --- a/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteKnowledge.cs +++ b/Symu source code/SymuEngine/Classes/Murphies/MurphyIncompleteKnowledge.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,8 +11,8 @@ using SymuEngine.Classes.Task; using SymuEngine.Common; -using SymuEngine.Messaging.Message; -using SymuTools.ProbabilityDistributions; +using SymuEngine.Messaging.Messages; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuEngine/Classes/Murphies/MurphyUnavailability.cs b/Symu source code/SymuEngine/Classes/Murphies/MurphyUnavailability.cs index 56170831..f3c4b4ab 100644 --- a/Symu source code/SymuEngine/Classes/Murphies/MurphyUnavailability.cs +++ b/Symu source code/SymuEngine/Classes/Murphies/MurphyUnavailability.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Organization/InteracionSphereModel.cs b/Symu source code/SymuEngine/Classes/Organization/InteracionSphereModel.cs new file mode 100644 index 00000000..026cd1fa --- /dev/null +++ b/Symu source code/SymuEngine/Classes/Organization/InteracionSphereModel.cs @@ -0,0 +1,170 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Environment; + +#endregion + +namespace SymuEngine.Classes.Organization +{ + /// + /// Model for interaction sphere settings + /// + public class InteractionSphereModel : ModelEntity + { + private float _maxSphereDensity = 1; + + private float _minSphereDensity; + + /// + /// If set to true, sphere of interaction will be re calculate at the FrequencyOfSphereUpdate. + /// If set to true, agent can initiate new interaction to add an agent in his sphere of interaction. + /// Otherwise, it will be initialized once + /// + public bool SphereUpdateOverTime { get; set; } + + /// + /// Define the frequency of sphere change if sphere change overtime + /// + public TimeStepType FrequencyOfSphereUpdate { get; set; } = TimeStepType.Monthly; + + /// + /// If set to true, sphere of interaction is randomly generated, min/max sphere density are associated. + /// Is set to false, sphere is generated based on similarity matching + /// + public bool RandomlyGeneratedSphere { get; set; } + + /// + /// If sphere of interaction is randomly generated, + /// min sphere density is used as range min for the random generation + /// + public float MinSphereDensity + { + get => _minSphereDensity; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("MinSphereDensity should be between [0;1]"); + } + + _minSphereDensity = value; + } + } + + /// + /// If sphere of interaction is randomly generated, + /// max sphere density is used as range max for the random generation + /// + public float MaxSphereDensity + { + get => _maxSphereDensity; + set + { + if (value < 0 || value > 1) + { + throw new ArgumentOutOfRangeException("MaxSphereDensity should be between [0;1]"); + } + + _maxSphereDensity = value; + } + } + + /// + /// Weight of SocialDemographic in the calculus of DerivedParameter + /// Range[0;1] + /// + public float SocialDemographicWeight { get; set; } = 1; + + /// + /// Weight of RelativeBelief in the calculus of DerivedParameter + /// Range[0;1] + /// + public float RelativeBeliefWeight { get; set; } = 1; + + /// + /// Weight of RelativeKnowledge in the calculus of DerivedParameter + /// Range[0;1] + /// + public float RelativeKnowledgeWeight { get; set; } = 1; + + /// + /// Weight of RelativeBeliefs in the calculus of DerivedParameter + /// Range[0;1] + /// + public float RelativeActivityWeight { get; set; } = 1; + + public void CopyTo(InteractionSphereModel entity) + { + if (entity is null) + { + throw new ArgumentNullException(nameof(entity)); + } + + base.CopyTo(entity); + entity.SphereUpdateOverTime = SphereUpdateOverTime; + entity.FrequencyOfSphereUpdate = FrequencyOfSphereUpdate; + entity.MaxSphereDensity = MaxSphereDensity; + entity.MinSphereDensity = MinSphereDensity; + entity.RandomlyGeneratedSphere = RandomlyGeneratedSphere; + entity.RelativeActivityWeight = RelativeActivityWeight; + entity.RelativeBeliefWeight = RelativeBeliefWeight; + entity.RelativeKnowledgeWeight = RelativeKnowledgeWeight; + entity.SocialDemographicWeight = SocialDemographicWeight; + } + + /// + /// Set binary interaction pattern based on InteractionStrategy + /// + /// + public void SetInteractionPatterns(InteractionStrategy strategy) + { + switch (strategy) + { + case InteractionStrategy.Homophily: + RelativeActivityWeight = 0.25F; + RelativeBeliefWeight = 0.25F; + RelativeKnowledgeWeight = 0.25F; + SocialDemographicWeight = 0.25F; + break; + case InteractionStrategy.Knowledge: + RelativeActivityWeight = 0F; + RelativeBeliefWeight = 0F; + RelativeKnowledgeWeight = 1F; + SocialDemographicWeight = 0F; + break; + case InteractionStrategy.Activities: + RelativeActivityWeight = 1F; + RelativeBeliefWeight = 0F; + RelativeKnowledgeWeight = 0F; + SocialDemographicWeight = 0F; + break; + case InteractionStrategy.Beliefs: + RelativeActivityWeight = 0F; + RelativeBeliefWeight = 1F; + RelativeKnowledgeWeight = 0F; + SocialDemographicWeight = 0F; + break; + case InteractionStrategy.SocialDemographics: + RelativeActivityWeight = 0F; + RelativeBeliefWeight = 0F; + RelativeKnowledgeWeight = 0F; + SocialDemographicWeight = 1F; + break; + default: + throw new ArgumentOutOfRangeException(nameof(strategy), strategy, null); + } + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Classes/Organization/OrganizationEntity.cs b/Symu source code/SymuEngine/Classes/Organization/OrganizationEntity.cs index 5cf18026..2a982aac 100644 --- a/Symu source code/SymuEngine/Classes/Organization/OrganizationEntity.cs +++ b/Symu source code/SymuEngine/Classes/Organization/OrganizationEntity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,8 +10,8 @@ #region using directives using System.Collections.Generic; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; using SymuEngine.Repository; using SymuEngine.Repository.Networks.Databases; using SymuEngine.Repository.Networks.Knowledges; diff --git a/Symu source code/SymuEngine/Classes/Organization/OrganizationModels.cs b/Symu source code/SymuEngine/Classes/Organization/OrganizationModels.cs index a78d8969..2492c0da 100644 --- a/Symu source code/SymuEngine/Classes/Organization/OrganizationModels.cs +++ b/Symu source code/SymuEngine/Classes/Organization/OrganizationModels.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using System; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents.Models; using SymuEngine.Common; using SymuEngine.Engine; @@ -47,6 +47,12 @@ public class OrganizationModels //TODO should be with IterationResult as Results Settings with cadence of feeds public bool FollowBlockers { get; set; } + /// + /// If true, allow multiple blockers at the same time + /// If false, will check new blockers only if there is no blocker + /// + public bool MultipleBlockers { get; set; } + /// /// Agent knowledge learning model /// @@ -57,11 +63,7 @@ public class OrganizationModels /// public ModelEntity Forgetting { get; set; } = new ModelEntity(); - /// - /// If true, allow multiple blockers at the same time - /// If false, will check new blockers only if there is no blocker - /// - public bool MultipleBlockers { get; set; } + public InteractionSphereModel InteractionSphere { get; set; } = new InteractionSphereModel(); /// /// Random generator modes in order to create random network @@ -108,6 +110,7 @@ public void CopyTo(OrganizationModels entity) Learning.CopyTo(entity.Learning); Forgetting.CopyTo(entity.Forgetting); + InteractionSphere.CopyTo(entity.InteractionSphere); entity.FollowGroupFlexibility = FollowGroupFlexibility; entity.FollowGroupKnowledge = FollowGroupKnowledge; entity.MultipleBlockers = MultipleBlockers; diff --git a/Symu source code/SymuEngine/Classes/Scenario/ScenarioEntity.cs b/Symu source code/SymuEngine/Classes/Scenario/ScenarioEntity.cs index dff6f56c..bfd6e2e7 100644 --- a/Symu source code/SymuEngine/Classes/Scenario/ScenarioEntity.cs +++ b/Symu source code/SymuEngine/Classes/Scenario/ScenarioEntity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository; #endregion diff --git a/Symu source code/SymuEngine/Classes/Scenario/SimulationScenario.cs b/Symu source code/SymuEngine/Classes/Scenario/SimulationScenario.cs index 0a3757c5..4ba98821 100644 --- a/Symu source code/SymuEngine/Classes/Scenario/SimulationScenario.cs +++ b/Symu source code/SymuEngine/Classes/Scenario/SimulationScenario.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,25 +10,25 @@ #region using directives using System; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models.Templates; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models.Templates; using SymuEngine.Environment; #endregion namespace SymuEngine.Classes.Scenario { - public class SimulationScenario : Agent.Agent + public class SimulationScenario : Agent { - public SimulationScenario(ushort key, object parent, SymuEnvironment environment) : base( - new AgentId(key, ScenarioEntity.ClassKey), environment) + public SimulationScenario(object parent, SymuEnvironment environment) : base( + new AgentId(environment.Organization.NextEntityIndex(), ScenarioEntity.ClassKey), environment) { if (environment is null) { throw new ArgumentNullException(nameof(environment)); } - Entity = new ScenarioEntity(key); + Entity = new ScenarioEntity(Id.Key); Parent = parent; SetCognitive(new StandardAgentTemplate()); } @@ -41,7 +41,7 @@ public SimulationScenario(ushort key, object parent, SymuEnvironment environment public virtual SimulationScenario Clone() { - var clone = new SimulationScenario(Id.Key, Parent, Environment); + var clone = new SimulationScenario(Parent, Environment); return clone; } diff --git a/Symu source code/SymuEngine/Classes/Scenario/TimeStepScenario.cs b/Symu source code/SymuEngine/Classes/Scenario/TimeStepScenario.cs index 255f46b4..2d3ab91f 100644 --- a/Symu source code/SymuEngine/Classes/Scenario/TimeStepScenario.cs +++ b/Symu source code/SymuEngine/Classes/Scenario/TimeStepScenario.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -18,7 +18,7 @@ namespace SymuEngine.Classes.Scenario { public class TimeStepScenario : SimulationScenario { - public TimeStepScenario(ushort key, SymuEnvironment environment) : base(key, null, environment) + public TimeStepScenario(SymuEnvironment environment) : base(null, environment) { } @@ -42,7 +42,7 @@ public override void PreStep() public override SimulationScenario Clone() { - var clone = new TimeStepScenario(Id.Key, Environment) + var clone = new TimeStepScenario(Environment) { NumberOfSteps = NumberOfSteps }; diff --git a/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgeBits.cs b/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgeBits.cs index 12ce1e3c..2ed7f0de 100644 --- a/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgeBits.cs +++ b/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgeBits.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgesBits.cs b/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgesBits.cs index 52b526fc..bd31aea0 100644 --- a/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgesBits.cs +++ b/Symu source code/SymuEngine/Classes/Task/Knowledge/TaskKnowledgesBits.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Task/Manager/TaskEventArgs.cs b/Symu source code/SymuEngine/Classes/Task/Manager/TaskEventArgs.cs index 337a09aa..89d68c68 100644 --- a/Symu source code/SymuEngine/Classes/Task/Manager/TaskEventArgs.cs +++ b/Symu source code/SymuEngine/Classes/Task/Manager/TaskEventArgs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Task/Manager/TaskProcessor.cs b/Symu source code/SymuEngine/Classes/Task/Manager/TaskProcessor.cs index c4623955..c2a7a2ef 100644 --- a/Symu source code/SymuEngine/Classes/Task/Manager/TaskProcessor.cs +++ b/Symu source code/SymuEngine/Classes/Task/Manager/TaskProcessor.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Task/Manager/TasksEventArgs.cs b/Symu source code/SymuEngine/Classes/Task/Manager/TasksEventArgs.cs index 5675eed5..f11ddf6b 100644 --- a/Symu source code/SymuEngine/Classes/Task/Manager/TasksEventArgs.cs +++ b/Symu source code/SymuEngine/Classes/Task/Manager/TasksEventArgs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Classes/Task/Manager/TasksManager.cs b/Symu source code/SymuEngine/Classes/Task/Manager/TasksManager.cs index ea8ca0e5..cec45b13 100644 --- a/Symu source code/SymuEngine/Classes/Task/Manager/TasksManager.cs +++ b/Symu source code/SymuEngine/Classes/Task/Manager/TasksManager.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,8 +13,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using SymuEngine.Messaging.Message; -using static SymuTools.Algorithm.Constants; +using SymuEngine.Messaging.Messages; +using static SymuTools.Constants; #endregion diff --git a/Symu source code/SymuEngine/Classes/Task/MurphyTask.cs b/Symu source code/SymuEngine/Classes/Task/MurphyTask.cs index 247c7886..b64409da 100644 --- a/Symu source code/SymuEngine/Classes/Task/MurphyTask.cs +++ b/Symu source code/SymuEngine/Classes/Task/MurphyTask.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System; using SymuEngine.Classes.Murphies; -using static SymuTools.Algorithm.Constants; +using static SymuTools.Constants; #endregion diff --git a/Symu source code/SymuEngine/Classes/Task/SymuTask.cs b/Symu source code/SymuEngine/Classes/Task/SymuTask.cs index 4d6967b4..9baab021 100644 --- a/Symu source code/SymuEngine/Classes/Task/SymuTask.cs +++ b/Symu source code/SymuEngine/Classes/Task/SymuTask.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,10 +10,10 @@ #region using directives using System; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Task.Knowledge; using SymuEngine.Common; -using static SymuTools.Algorithm.Constants; +using static SymuTools.Constants; #endregion diff --git a/Symu source code/SymuEngine/Classes/Task/TasksLimit.cs b/Symu source code/SymuEngine/Classes/Task/TasksLimit.cs index 6d02d180..dd45515c 100644 --- a/Symu source code/SymuEngine/Classes/Task/TasksLimit.cs +++ b/Symu source code/SymuEngine/Classes/Task/TasksLimit.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -18,7 +18,7 @@ namespace SymuEngine.Classes.Task /// /// Manage all limits related to Tasks /// - /// Tasks and Performance from Construct Software + /// Tasks and Density from Construct Software public class TasksLimit { private byte _maximumSimultaneousTasks = 10; diff --git a/Symu source code/SymuEngine/Common/AgentState.cs b/Symu source code/SymuEngine/Common/AgentState.cs index 4842a9df..9fa2ff18 100644 --- a/Symu source code/SymuEngine/Common/AgentState.cs +++ b/Symu source code/SymuEngine/Common/AgentState.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Common/Frequency.cs b/Symu source code/SymuEngine/Common/Frequency.cs index 64e85b90..8aacfc0e 100644 --- a/Symu source code/SymuEngine/Common/Frequency.cs +++ b/Symu source code/SymuEngine/Common/Frequency.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Common/FrequencyLevelService.cs b/Symu source code/SymuEngine/Common/FrequencyLevelService.cs index 6df339f2..caf3536a 100644 --- a/Symu source code/SymuEngine/Common/FrequencyLevelService.cs +++ b/Symu source code/SymuEngine/Common/FrequencyLevelService.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -65,25 +65,7 @@ public static Frequency GetValue(string level) /// public static string GetName(Frequency level) { - switch (level) - { - case Frequency.Never: - return "Never"; - case Frequency.VeryRarely: - return "VeryRarely"; - case Frequency.Rarely: - return "Rarely"; - case Frequency.Medium: - return "Medium"; - case Frequency.Often: - return "Often"; - case Frequency.VeryOften: - return "VeryOften"; - case Frequency.Always: - return "Always"; - default: - throw new ArgumentOutOfRangeException(); - } + return level.ToString(); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Common/GenericLevel.cs b/Symu source code/SymuEngine/Common/GenericLevel.cs index 1d680b06..4127280d 100644 --- a/Symu source code/SymuEngine/Common/GenericLevel.cs +++ b/Symu source code/SymuEngine/Common/GenericLevel.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Common/GenericLevelService.cs b/Symu source code/SymuEngine/Common/GenericLevelService.cs index e6123b42..15c7bfeb 100644 --- a/Symu source code/SymuEngine/Common/GenericLevelService.cs +++ b/Symu source code/SymuEngine/Common/GenericLevelService.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -65,25 +65,7 @@ public static GenericLevel GetValue(string level) /// public static string GetName(GenericLevel level) { - switch (level) - { - case GenericLevel.None: - return "None"; - case GenericLevel.VeryLow: - return "VeryLow"; - case GenericLevel.Low: - return "Low"; - case GenericLevel.Medium: - return "Medium"; - case GenericLevel.High: - return "High"; - case GenericLevel.VeryHigh: - return "VeryHigh"; - case GenericLevel.Complete: - return "Complete"; - default: - throw new ArgumentOutOfRangeException(); - } + return level.ToString(); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Common/ImpactLevel.cs b/Symu source code/SymuEngine/Common/ImpactLevel.cs index 1693d032..7282a690 100644 --- a/Symu source code/SymuEngine/Common/ImpactLevel.cs +++ b/Symu source code/SymuEngine/Common/ImpactLevel.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Common/RandomGenerator.cs b/Symu source code/SymuEngine/Common/RandomGenerator.cs index b5b689f9..8973e20f 100644 --- a/Symu source code/SymuEngine/Common/RandomGenerator.cs +++ b/Symu source code/SymuEngine/Common/RandomGenerator.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Engine/Form/SymuForm.cs b/Symu source code/SymuEngine/Engine/Form/SymuForm.cs index 0c37ba09..eb97c644 100644 --- a/Symu source code/SymuEngine/Engine/Form/SymuForm.cs +++ b/Symu source code/SymuEngine/Engine/Form/SymuForm.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -36,7 +36,6 @@ public SymuForm() } protected OrganizationEntity OrganizationEntity { get; set; } = new OrganizationEntity("symu"); - protected MurphyUnAvailability UnAvailability { get; } = new MurphyUnAvailability(); protected TimeStepType TimeStepType { get; set; } = TimeStepType.Daily; protected AgentState State { get; private set; } = AgentState.NotStarted; diff --git a/Symu source code/SymuEngine/Engine/Iterations.cs b/Symu source code/SymuEngine/Engine/Iterations.cs index 1f0271e1..10197d4f 100644 --- a/Symu source code/SymuEngine/Engine/Iterations.cs +++ b/Symu source code/SymuEngine/Engine/Iterations.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Engine/SimulationEngine.cs b/Symu source code/SymuEngine/Engine/SimulationEngine.cs index 9c4e52ba..0e9d9374 100644 --- a/Symu source code/SymuEngine/Engine/SimulationEngine.cs +++ b/Symu source code/SymuEngine/Engine/SimulationEngine.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Scenario; using SymuEngine.Common; using SymuEngine.Environment; @@ -47,11 +47,6 @@ public class SimulationEngine public IterationResult IterationResult => Environment.IterationResult; - /// - /// EventHandler use to update the form after each step - /// - public event EventHandler AfterStopProcess; - #region Step level /// diff --git a/Symu source code/SymuEngine/Engine/SimulationEngines.cs b/Symu source code/SymuEngine/Engine/SimulationEngines.cs index 2619161a..ce0ea4cc 100644 --- a/Symu source code/SymuEngine/Engine/SimulationEngines.cs +++ b/Symu source code/SymuEngine/Engine/SimulationEngines.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Engine/SimulationRandom.cs b/Symu source code/SymuEngine/Engine/SimulationRandom.cs index 4c8059f3..0dc1266a 100644 --- a/Symu source code/SymuEngine/Engine/SimulationRandom.cs +++ b/Symu source code/SymuEngine/Engine/SimulationRandom.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Environment/EnvironmentState.cs b/Symu source code/SymuEngine/Environment/EnvironmentState.cs index f872e7e9..c41d1f89 100644 --- a/Symu source code/SymuEngine/Environment/EnvironmentState.cs +++ b/Symu source code/SymuEngine/Environment/EnvironmentState.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Concurrent; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Environment/SymuEnvironment.cs b/Symu source code/SymuEngine/Environment/SymuEnvironment.cs index 0201e3be..beec3e26 100644 --- a/Symu source code/SymuEngine/Environment/SymuEnvironment.cs +++ b/Symu source code/SymuEngine/Environment/SymuEnvironment.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,11 +13,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Organization; using SymuEngine.Classes.Scenario; using SymuEngine.Messaging.Log; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; using SymuEngine.Results; using SymuTools; @@ -74,7 +74,7 @@ protected SymuEnvironment() public void SetOrganization(OrganizationEntity organization) { Organization = organization ?? throw new ArgumentNullException(nameof(organization)); - WhitePages = new WhitePages(Organization.Templates); + WhitePages = new WhitePages(Organization.Templates, Organization.Models.InteractionSphere); } /// @@ -150,6 +150,8 @@ public virtual void InitializeIteration() WhitePages.Network.NetworkBeliefs.Model = Organization.Models.Generator; SetModelForAgents(); + WhitePages.Network.InitializeNetworkLinks(); + WhitePages.SetStarted(); } /// @@ -274,6 +276,11 @@ public void OnNextStep() public void NextStep() { SendDelayedMessages(); + if (TimeStep.Step == 0) + { + SetInteractionSphere(true); + } + var agents = WhitePages.AllAgents().Shuffle(); if (TimeStep.Type <= TimeStepType.Daily) { @@ -286,25 +293,56 @@ public void NextStep() { agents.ForEach(a => a.ActWeekEnd()); } + + if (Organization.Models.InteractionSphere.FrequencyOfSphereUpdate <= + TimeStepType.Daily && TimeStep.Step > 0) + { + SetInteractionSphere(false); + } } if (TimeStep.Type <= TimeStepType.Weekly && TimeStep.IsEndOfWeek) { agents.ForEach(a => a.ActEndOfWeek()); + if (Organization.Models.InteractionSphere.FrequencyOfSphereUpdate == + TimeStepType.Weekly && TimeStep.Step > 0) + { + SetInteractionSphere(false); + } } if (TimeStep.Type <= TimeStepType.Monthly && TimeStep.IsEndOfMonth) { SetMonthlyIterationResult(); agents.ForEach(a => a.ActEndOfMonth()); + if (Organization.Models.InteractionSphere.FrequencyOfSphereUpdate == + TimeStepType.Monthly && TimeStep.Step > 0) + { + SetInteractionSphere(false); + } } if (TimeStep.IsEndOfYear) { agents.ForEach(a => a.ActEndOfYear()); + if (Organization.Models.InteractionSphere.FrequencyOfSphereUpdate == + TimeStepType.Yearly && TimeStep.Step > 0) + { + SetInteractionSphere(false); + } } } + /// + /// Set Sphere for the InteractionSphere + /// + public void SetInteractionSphere(bool initialization) + { + var agentIds = WhitePages.AllAgents().Where(x => x.Cognitive.InteractionPatterns.IsPartOfInteractionSphere) + .Select(x => x.Id).ToList(); + WhitePages.Network.InteractionSphere.SetSphere(initialization, agentIds, WhitePages.Network); + } + /// /// Set monthly iterationResult /// @@ -317,6 +355,8 @@ public virtual void SetMonthlyIterationResult() } /// + /// Trigger every event before the new step + /// Do not send messages, use NextStep for that /// Trigger Agent.PreStep() /// public void PreStep() diff --git a/Symu source code/SymuEngine/Environment/TimeStep.cs b/Symu source code/SymuEngine/Environment/TimeStep.cs index e6bf554c..1b4b8f2b 100644 --- a/Symu source code/SymuEngine/Environment/TimeStep.cs +++ b/Symu source code/SymuEngine/Environment/TimeStep.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Environment/TimeStepType.cs b/Symu source code/SymuEngine/Environment/TimeStepType.cs index 5b9bc3d6..3312b580 100644 --- a/Symu source code/SymuEngine/Environment/TimeStepType.cs +++ b/Symu source code/SymuEngine/Environment/TimeStepType.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Environment/TimeStepTypeService.cs b/Symu source code/SymuEngine/Environment/TimeStepTypeService.cs new file mode 100644 index 00000000..5bdd0f39 --- /dev/null +++ b/Symu source code/SymuEngine/Environment/TimeStepTypeService.cs @@ -0,0 +1,64 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using System.Linq; + +#endregion + +namespace SymuEngine.Environment +{ + public static class TimeStepTypeService + { + /// + /// Get all names of the KnowledgeLevel enum + /// + /// + public static string[] GetNames() + { + return Enum.GetNames(typeof(TimeStepType)).ToArray(); + } + + /// + /// Get the value based on the GenericLevel name + /// + /// + /// + public static TimeStepType GetValue(string level) + { + switch (level) + { + case "Intraday": + return TimeStepType.Intraday; + case "Daily": + return TimeStepType.Daily; + case "Weekly": + return TimeStepType.Weekly; + case "Monthly": + return TimeStepType.Monthly; + case "Yearly": + return TimeStepType.Yearly; + default: + throw new ArgumentOutOfRangeException(); + } + } + + /// + /// Get the name of a TimeStepType + /// + /// + /// + public static string GetName(TimeStepType level) + { + return level.ToString(); + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Messaging/Delayed/DelayedMessages.cs b/Symu source code/SymuEngine/Messaging/Delayed/DelayedMessages.cs index 5ea1acce..808fde0d 100644 --- a/Symu source code/SymuEngine/Messaging/Delayed/DelayedMessages.cs +++ b/Symu source code/SymuEngine/Messaging/Delayed/DelayedMessages.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; +using SymuEngine.Messaging.Messages; #endregion @@ -25,12 +26,12 @@ public class DelayedMessages /// /// Key => step /// - private readonly Dictionary> _messages = - new Dictionary>(); + private readonly Dictionary> _messages = + new Dictionary>(); public int Count => _messages.Values.Sum(l => l.Count); - public void Enqueue(Message.Message message, ushort step) + public void Enqueue(Message message, ushort step) { if (message is null) { @@ -41,7 +42,7 @@ public void Enqueue(Message.Message message, ushort step) { if (!_messages.ContainsKey(step)) { - _messages.Add(step, new Queue()); + _messages.Add(step, new Queue()); } _messages[step].Enqueue(message); @@ -53,7 +54,7 @@ public void Enqueue(Message.Message message, ushort step) /// /// /// - public Message.Message Dequeue(ushort step) + public Message Dequeue(ushort step) { var keys = _messages.Where(m => m.Key <= step && m.Value.Count > 0).OrderBy(m => m.Key).Select(m => m.Key) .ToList(); @@ -65,7 +66,7 @@ public Message.Message Dequeue(ushort step) /// /// /// - public Message.Message Last(ushort step) + public Message Last(ushort step) { var keys = _messages.Where(m => m.Key <= step && m.Value.Count > 0).OrderBy(m => m.Key).Select(m => m.Key) .ToList(); @@ -76,7 +77,7 @@ public Message.Message Last(ushort step) /// Return the last message without remove it /// /// - public Message.Message Last() + public Message Last() { return _messages.Values.Last().Peek(); } diff --git a/Symu source code/SymuEngine/Messaging/Manager/AsyncMessageProcessor.cs b/Symu source code/SymuEngine/Messaging/Manager/AsyncMessageProcessor.cs index df2f135c..d832b521 100644 --- a/Symu source code/SymuEngine/Messaging/Manager/AsyncMessageProcessor.cs +++ b/Symu source code/SymuEngine/Messaging/Manager/AsyncMessageProcessor.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Messaging/Manager/MessageEventArgs.cs b/Symu source code/SymuEngine/Messaging/Manager/MessageEventArgs.cs index 734bebb7..018823ef 100644 --- a/Symu source code/SymuEngine/Messaging/Manager/MessageEventArgs.cs +++ b/Symu source code/SymuEngine/Messaging/Manager/MessageEventArgs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,6 +10,7 @@ #region using directives using System; +using SymuEngine.Messaging.Messages; #endregion @@ -20,11 +21,11 @@ namespace SymuEngine.Messaging.Manager /// public class MessageEventArgs : EventArgs { - public MessageEventArgs(Message.Message message) + public MessageEventArgs(Message message) { Message = message ?? throw new ArgumentNullException(nameof(message)); } - public Message.Message Message { get; set; } + public Message Message { get; set; } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Messaging/Manager/MessageProcessor.cs b/Symu source code/SymuEngine/Messaging/Manager/MessageProcessor.cs index 3cb62de2..289074ff 100644 --- a/Symu source code/SymuEngine/Messaging/Manager/MessageProcessor.cs +++ b/Symu source code/SymuEngine/Messaging/Manager/MessageProcessor.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -15,7 +15,7 @@ using System.Threading; using System.Threading.Tasks; using SymuEngine.Messaging.Delayed; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Messaging.Reply; using SymuEngine.Messaging.Subscription; @@ -106,7 +106,7 @@ public void Start() /// public event EventHandler OnBeforePostEvent; - public void Post(Message.Message message) + public void Post(Message message) { if (message is null) { @@ -165,7 +165,7 @@ public void ClearMessagesPerPeriod() /// public byte NumberReceivedPerPeriod { get; set; } - public Task Receive() + public Task Receive() { return _messagesManager.Receive(); } @@ -179,7 +179,7 @@ public void ClearMessagesPerPeriod() /// public DelayedMessages DelayedMessages { get; } = new DelayedMessages(); - public void PostAsADelayed(Message.Message message, ushort step) + public void PostAsADelayed(Message message, ushort step) { DelayedMessages.Enqueue(message, step); } @@ -189,7 +189,7 @@ public void PostAsADelayed(Message.Message message, ushort step) /// /// /// - public Message.Message NextDelayedMessages(ushort step) + public Message NextDelayedMessages(ushort step) { return DelayedMessages.Dequeue(step); } @@ -203,9 +203,9 @@ public Message.Message NextDelayedMessages(ushort step) /// message /// Missed messages trace those missed message in debug /// - public List MissedMessages { get; } = new List(); + public List MissedMessages { get; } = new List(); - public void AddMissedMessage(Message.Message message, bool debug) + public void AddMissedMessage(Message message, bool debug) { if (debug) { @@ -214,5 +214,24 @@ public void AddMissedMessage(Message.Message message, bool debug) } #endregion + + #region Not accepted Message + + /// + /// An sender agent has send a message of type phone, or meeting, ... but the sender was not in the interaction sphere + /// of the receiver and did not accept the message + /// NotAcceptedMessages trace those not accepted message in debug + /// + public List NotAcceptedMessages { get; } = new List(); + + public void AddNotAcceptedMessages(Message message, bool debug) + { + if (debug) + { + NotAcceptedMessages.Add(message); + } + } + + #endregion } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Messaging/Manager/MessagesManager.cs b/Symu source code/SymuEngine/Messaging/Manager/MessagesManager.cs index c05d1400..333a14cf 100644 --- a/Symu source code/SymuEngine/Messaging/Manager/MessagesManager.cs +++ b/Symu source code/SymuEngine/Messaging/Manager/MessagesManager.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using SymuEngine.Messaging.Messages; #endregion @@ -19,13 +20,13 @@ namespace SymuEngine.Messaging.Manager { internal class MessagesManager : IDisposable { - private readonly Queue _arrivals; + private readonly Queue _arrivals; private TaskCompletionSource _savedCont; public MessagesManager() { - _arrivals = new Queue(); + _arrivals = new Queue(); } #region IDisposable Members @@ -66,7 +67,7 @@ private async Task WaitOneNoTimeout() return await _savedCont.Task.ConfigureAwait(false); } - internal Message.Message ReceiveFromArrivals() + internal Message ReceiveFromArrivals() { lock (_arrivals) { @@ -74,7 +75,7 @@ internal Message.Message ReceiveFromArrivals() } } - internal void Post(Message.Message msg) + internal void Post(Message msg) { lock (_arrivals) { @@ -95,9 +96,9 @@ internal void Post(Message.Message msg) } } - internal async Task Receive() + internal async Task Receive() { - async Task ProcessFirstArrival() + async Task ProcessFirstArrival() { while (true) { diff --git a/Symu source code/SymuEngine/Messaging/Message/CommunicationMediums.cs b/Symu source code/SymuEngine/Messaging/Messages/CommunicationMediums.cs similarity index 93% rename from Symu source code/SymuEngine/Messaging/Message/CommunicationMediums.cs rename to Symu source code/SymuEngine/Messaging/Messages/CommunicationMediums.cs index e6d3ae63..0830abdd 100644 --- a/Symu source code/SymuEngine/Messaging/Message/CommunicationMediums.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/CommunicationMediums.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,7 +14,7 @@ #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { /// /// A message is an interaction between tow agents diff --git a/Symu source code/SymuEngine/Messaging/Message/CommunicationMediumsModel.cs b/Symu source code/SymuEngine/Messaging/Messages/CommunicationMediumsModel.cs similarity index 95% rename from Symu source code/SymuEngine/Messaging/Message/CommunicationMediumsModel.cs rename to Symu source code/SymuEngine/Messaging/Messages/CommunicationMediumsModel.cs index 8900aef5..a74cfed1 100644 --- a/Symu source code/SymuEngine/Messaging/Message/CommunicationMediumsModel.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/CommunicationMediumsModel.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,11 +11,11 @@ using System.Collections; using System.Linq; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { public static class CommunicationMediumsModel { diff --git a/Symu source code/SymuEngine/Messaging/Message/Message.cs b/Symu source code/SymuEngine/Messaging/Messages/Message.cs similarity index 98% rename from Symu source code/SymuEngine/Messaging/Message/Message.cs rename to Symu source code/SymuEngine/Messaging/Messages/Message.cs index a36fba91..88381bc2 100644 --- a/Symu source code/SymuEngine/Messaging/Message/Message.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/Message.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using System; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { /// /// A message that the agents use to communicate. In an agent-based system, the communication between the agents is diff --git a/Symu source code/SymuEngine/Messaging/Message/MessageAction.cs b/Symu source code/SymuEngine/Messaging/Messages/MessageAction.cs similarity index 87% rename from Symu source code/SymuEngine/Messaging/Message/MessageAction.cs rename to Symu source code/SymuEngine/Messaging/Messages/MessageAction.cs index 1b2eea23..4e5622f5 100644 --- a/Symu source code/SymuEngine/Messaging/Message/MessageAction.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/MessageAction.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { [SuppressMessage("Design", "CA1028:Le stockage d'enum doit être de type Int32", Justification = "")] public enum MessageAction : byte diff --git a/Symu source code/SymuEngine/Messaging/Message/MessageAttachments.cs b/Symu source code/SymuEngine/Messaging/Messages/MessageAttachments.cs similarity index 96% rename from Symu source code/SymuEngine/Messaging/Message/MessageAttachments.cs rename to Symu source code/SymuEngine/Messaging/Messages/MessageAttachments.cs index 156d8735..423db36d 100644 --- a/Symu source code/SymuEngine/Messaging/Message/MessageAttachments.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/MessageAttachments.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -15,7 +15,7 @@ #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { /// /// Manage the message attachments diff --git a/Symu source code/SymuEngine/Messaging/Message/MessageState.cs b/Symu source code/SymuEngine/Messaging/Messages/MessageState.cs similarity index 89% rename from Symu source code/SymuEngine/Messaging/Message/MessageState.cs rename to Symu source code/SymuEngine/Messaging/Messages/MessageState.cs index 87624381..71353e2b 100644 --- a/Symu source code/SymuEngine/Messaging/Message/MessageState.cs +++ b/Symu source code/SymuEngine/Messaging/Messages/MessageState.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuEngine.Messaging.Message +namespace SymuEngine.Messaging.Messages { /// /// Message life cycle diff --git a/Symu source code/SymuEngine/Messaging/Reply/WaitingMessageSent.cs b/Symu source code/SymuEngine/Messaging/Reply/WaitingMessageSent.cs index 0025bfd5..47afd4e3 100644 --- a/Symu source code/SymuEngine/Messaging/Reply/WaitingMessageSent.cs +++ b/Symu source code/SymuEngine/Messaging/Reply/WaitingMessageSent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,6 +10,7 @@ #region using directives using System.Collections.Generic; +using SymuEngine.Messaging.Messages; #endregion @@ -30,9 +31,9 @@ public WaitingMessageSent(byte content, object param, ushort messagesSent) : bas public object Param { get; } - public List Messages { get; } = new List(); + public List Messages { get; } = new List(); - public void Increment(Message.Message message) + public void Increment(Message message) { Increment(); Messages.Add(message); diff --git a/Symu source code/SymuEngine/Messaging/Reply/WaitingMessagesSent.cs b/Symu source code/SymuEngine/Messaging/Reply/WaitingMessagesSent.cs index 2ac53334..5551daa4 100644 --- a/Symu source code/SymuEngine/Messaging/Reply/WaitingMessagesSent.cs +++ b/Symu source code/SymuEngine/Messaging/Reply/WaitingMessagesSent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Messaging/Reply/WaitingReplies.cs b/Symu source code/SymuEngine/Messaging/Reply/WaitingReplies.cs index fdc32565..3a491fd5 100644 --- a/Symu source code/SymuEngine/Messaging/Reply/WaitingReplies.cs +++ b/Symu source code/SymuEngine/Messaging/Reply/WaitingReplies.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Messaging/Reply/WaitingReply.cs b/Symu source code/SymuEngine/Messaging/Reply/WaitingReply.cs index 4f0fa787..a3700a47 100644 --- a/Symu source code/SymuEngine/Messaging/Reply/WaitingReply.cs +++ b/Symu source code/SymuEngine/Messaging/Reply/WaitingReply.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscription.cs b/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscription.cs index 751a45b7..be2345f6 100644 --- a/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscription.cs +++ b/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscription.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscriptions.cs b/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscriptions.cs index 0b0b801e..0c170ee7 100644 --- a/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscriptions.cs +++ b/Symu source code/SymuEngine/Messaging/Subscription/MessageSubscriptions.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/ConcurrentAgents.cs b/Symu source code/SymuEngine/Repository/ConcurrentAgents.cs index ddfa12d5..11fc7726 100644 --- a/Symu source code/SymuEngine/Repository/ConcurrentAgents.cs +++ b/Symu source code/SymuEngine/Repository/ConcurrentAgents.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Activities/Activity.cs b/Symu source code/SymuEngine/Repository/Networks/Activities/Activity.cs index 01350729..c50e1a6b 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Activities/Activity.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Activities/Activity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Activities/AgentActivity.cs b/Symu source code/SymuEngine/Repository/Networks/Activities/AgentActivity.cs index 6519b969..b11e7d1a 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Activities/AgentActivity.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Activities/AgentActivity.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Activities/NetworkActivities.cs b/Symu source code/SymuEngine/Repository/Networks/Activities/NetworkActivities.cs index 7004c5a8..3cf894c5 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Activities/NetworkActivities.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Activities/NetworkActivities.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Knowledges; #endregion @@ -148,7 +148,7 @@ public void AddActivities(IEnumerable activities, AgentId groupId) /// /// /// - public bool HasActivities(AgentId groupId) + public bool GroupHasActivities(AgentId groupId) { return Exists(groupId) && Repository[groupId].Any(); } @@ -158,7 +158,7 @@ public bool HasActivities(AgentId groupId) /// /// /// - public IEnumerable GetActivities(AgentId groupId) + public IEnumerable GetGroupActivities(AgentId groupId) { return Exists(groupId) ? Repository[groupId].Select(x => x.Name) : new List(); } @@ -241,7 +241,7 @@ public void RemoveMember(AgentId agentId, AgentId groupId) public void AddActivity(AgentId agentId, string activity, AgentId groupId) { AddGroup(groupId); - if (HasAnActivityOn(agentId, groupId, activity)) + if (AgentHasAnActivityOn(agentId, groupId, activity)) { return; } @@ -250,13 +250,13 @@ public void AddActivity(AgentId agentId, string activity, AgentId groupId) AgentActivities[groupId].Add(agentActivity); } - public bool HasAnActivityOn(AgentId agentId, AgentId groupId, string activity) + public bool AgentHasAnActivityOn(AgentId agentId, AgentId groupId, string activity) { return Exists(groupId) && AgentActivities[groupId] .Exists(g => g.AgentId.Equals(agentId) && g.Activity == activity); } - public bool HasActivitiesOn(AgentId agentId, AgentId groupId) + public bool AgentHasActivitiesOn(AgentId agentId, AgentId groupId) { return Exists(groupId) && AgentActivities[groupId].Exists(g => g.AgentId.Equals(agentId)); } @@ -268,13 +268,30 @@ public bool HasActivitiesOn(AgentId agentId, AgentId groupId) /// /// /// - public IEnumerable GetActivities(AgentId agentId, AgentId groupId) + public IEnumerable GetAgentActivities(AgentId agentId, AgentId groupId) { return Exists(groupId) ? AgentActivities[groupId].FindAll(g => g.AgentId.Equals(agentId)).Select(x => x.Activity) : new List(); } + /// + /// Get all the activities of an agentId + /// + /// + /// + public IEnumerable GetAgentActivities(AgentId agentId) + { + var activities = new List(); + foreach (var agentActivities in AgentActivities) + { + activities.AddRange(agentActivities.Value.Where(x => x.AgentId.Equals(agentId)) + .Select(agentActivity => agentActivity.Activity)); + } + + return activities; + } + public IEnumerable FilterAgentIdsWithActivity(IEnumerable agentIds, AgentId groupId, string activity) { @@ -283,7 +300,7 @@ public IEnumerable FilterAgentIdsWithActivity(IEnumerable agen throw new ArgumentNullException(nameof(agentIds)); } - return agentIds.Where(agentId => HasAnActivityOn(agentId, groupId, activity)).ToList(); + return agentIds.Where(agentId => AgentHasAnActivityOn(agentId, groupId, activity)).ToList(); } /// @@ -325,7 +342,7 @@ public void AddActivities(AgentId agentId, AgentId groupId, List agentKn /// public void TransferTo(AgentId agentId, AgentId groupSourceId, AgentId groupTargetId) { - AddActivities(agentId, groupTargetId, GetActivities(agentId, groupSourceId)); + AddActivities(agentId, groupTargetId, GetAgentActivities(agentId, groupSourceId)); RemoveMember(agentId, groupSourceId); } diff --git a/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBelief.cs b/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBelief.cs index df45d275..ad691fdd 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBelief.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBelief.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,8 +12,8 @@ using System; using SymuEngine.Common; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; -using static SymuTools.Algorithm.Constants; +using SymuTools.Math.ProbabilityDistributions; +using static SymuTools.Constants; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBeliefs.cs b/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBeliefs.cs index 13ed6262..1d0c3e38 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBeliefs.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Beliefs/AgentBeliefs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -91,5 +91,15 @@ public float GetBeliefsSum() { return List.Sum(l => l.GetBeliefSum()); } + + + /// + /// Get all the belief Ids of an agent + /// + /// + public IEnumerable GetBeliefIds() + { + return List.Select(x => x.BeliefId); + } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Beliefs/Belief.cs b/Symu source code/SymuEngine/Repository/Networks/Beliefs/Belief.cs index 02ed596b..334e1c59 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Beliefs/Belief.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Beliefs/Belief.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using SymuEngine.Common; using SymuEngine.Repository.Networks.Knowledges; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Beliefs/BeliefCollection.cs b/Symu source code/SymuEngine/Repository/Networks/Beliefs/BeliefCollection.cs index d2d2358b..f830357d 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Beliefs/BeliefCollection.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Beliefs/BeliefCollection.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Beliefs/NetworkBeliefs.cs b/Symu source code/SymuEngine/Repository/Networks/Beliefs/NetworkBeliefs.cs index fb1bbf6a..d0671461 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Beliefs/NetworkBeliefs.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Beliefs/NetworkBeliefs.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Common; using SymuEngine.Repository.Networks.Knowledges; @@ -236,6 +236,16 @@ public AgentBeliefs GetAgentBeliefs(AgentId agentId) return AgentsRepository[agentId]; } + public IEnumerable GetBeliefIds(AgentId agentId) + { + if (!Exists(agentId)) + { + throw new NullReferenceException(nameof(agentId)); + } + + return AgentsRepository[agentId].GetBeliefIds(); + } + /// /// Get Agent belief /// diff --git a/Symu source code/SymuEngine/Repository/Networks/Communication/NetworkCommunications.cs b/Symu source code/SymuEngine/Repository/Networks/Communication/NetworkCommunications.cs index 12303bb4..c369433a 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Communication/NetworkCommunications.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Communication/NetworkCommunications.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,9 +10,9 @@ #region using directives using System; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.Templates.Communication; -using SymuEngine.Messaging.Message; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.Templates.Communication; +using SymuEngine.Messaging.Messages; #endregion @@ -61,8 +61,10 @@ public CommunicationTemplate TemplateFromChannel(CommunicationMediums channel) return FaceToFace; case CommunicationMediums.ViaAPlatform: return ViaPlatform; - default: + case CommunicationMediums.System: return null; + default: + throw new ArgumentOutOfRangeException(nameof(channel), channel, null); } } diff --git a/Symu source code/SymuEngine/Repository/Networks/Databases/Database.cs b/Symu source code/SymuEngine/Repository/Networks/Databases/Database.cs index 3fb08edc..97d0f5c1 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Databases/Database.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Databases/Database.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using System; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Repository.Networks.Knowledges; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Databases/DatabaseCollection.cs b/Symu source code/SymuEngine/Repository/Networks/Databases/DatabaseCollection.cs index 09331a4c..4c9c7b78 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Databases/DatabaseCollection.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Databases/DatabaseCollection.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Databases/NetworkDatabases.cs b/Symu source code/SymuEngine/Repository/Networks/Databases/NetworkDatabases.cs index 8ea550a8..2a2bdcbd 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Databases/NetworkDatabases.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Databases/NetworkDatabases.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Enculturation/NetworkEnculturation.cs b/Symu source code/SymuEngine/Repository/Networks/Enculturation/NetworkEnculturation.cs index 3c286014..f487f2c0 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Enculturation/NetworkEnculturation.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Enculturation/NetworkEnculturation.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Group/GroupAllocation.cs b/Symu source code/SymuEngine/Repository/Networks/Group/GroupAllocation.cs index 0ead5fc4..afe618fb 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Group/GroupAllocation.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Group/GroupAllocation.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Group/NetworkGroups.cs b/Symu source code/SymuEngine/Repository/Networks/Group/NetworkGroups.cs index 1b2a4855..fa687b3a 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Group/NetworkGroups.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Group/NetworkGroups.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion @@ -53,13 +53,7 @@ public void RemoveAgent(AgentId agentId) public void RemoveMember(AgentId agentId) { - var groupIds = GetGroups(); - if (groupIds == null) - { - return; - } - - foreach (var groupId in groupIds) + foreach (var groupId in GetGroups().ToList()) { RemoveMember(agentId, groupId); } @@ -75,7 +69,7 @@ public void RemoveMember(AgentId agentId, AgentId groupId) public IEnumerable GetGroups() { - return List.Any() ? List.Keys : null; + return List.Any() ? (IEnumerable) List.Keys : new List(); } /// @@ -209,6 +203,29 @@ public IEnumerable GetGroups(AgentId agentId, byte groupClassKey) return groupIds; } + /// + /// Get the list of the members of all the groups of a agentId, filtered by group.ClassKey + /// + /// + /// + /// List of groupIds + public IEnumerable GetCoMemberIds(AgentId agentId, byte groupClassKey) + { + var coMemberIds = new List(); + var groupIds = GetGroups(agentId, groupClassKey).ToList(); + if (!groupIds.Any()) + { + return coMemberIds; + } + + foreach (var groupId in groupIds) + { + coMemberIds.AddRange(List[groupId].FindAll(x => !x.AgentId.Equals(agentId)).Select(x => x.AgentId)); + } + + return coMemberIds.Distinct(); + } + /// /// Get the list of the group allocations of a agentId, filtered by group.ClassKey /// diff --git a/Symu source code/SymuEngine/Repository/Networks/Influences/Influence.cs b/Symu source code/SymuEngine/Repository/Networks/Influences/Influence.cs index 0643a1f5..ed095a4d 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Influences/Influence.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Influences/Influence.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Influences/NetworkInfluences.cs b/Symu source code/SymuEngine/Repository/Networks/Influences/NetworkInfluences.cs index 24735b49..9bfe4ef0 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Influences/NetworkInfluences.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Influences/NetworkInfluences.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentExpertise.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentExpertise.cs index 84e562f9..17bd8864 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentExpertise.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentExpertise.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentKnowledge.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentKnowledge.cs index 7aeeb51e..78b209d9 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentKnowledge.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/AgentKnowledge.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using System; -using static SymuTools.Algorithm.Constants; +using static SymuTools.Constants; #endregion @@ -224,11 +224,13 @@ public bool Check(byte[] taskKnowledgeIndexes, out byte index, float knowledgeTh for (byte i = 0; i < taskKnowledgeIndexes.Length; i++) { - if (!KnowsEnough(taskKnowledgeIndexes[i], knowledgeThreshHoldForDoing, step)) + if (KnowsEnough(taskKnowledgeIndexes[i], knowledgeThreshHoldForDoing, step)) { - index = taskKnowledgeIndexes[i]; - return false; + continue; } + + index = taskKnowledgeIndexes[i]; + return false; } index = 0; diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/Bits.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/Bits.cs index 3edea930..bf20004c 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/Bits.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/Bits.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -71,12 +71,12 @@ public Bits Clone() /// Get the knowledgeBit at the index i /// /// - /// -1 if knowledgeBits == null + /// 0 if knowledgeBits == null public float GetBit(byte index) { if (IsNull) { - return -1; + return 0; } return _bits[index]; @@ -203,5 +203,34 @@ public static ushort[] Initialize(byte length, ushort value) return bits; } + + + /// + /// Get a normalized value of the bits1 * bits2 / Length + /// This is used to set the relative expertise or belief of an agent vs another + /// + /// + /// + /// + public static float GetRelativeBits(Bits bits1, Bits bits2) + { + if (bits1 == null) + { + throw new ArgumentNullException(nameof(bits1)); + } + + if (bits2 == null) + { + throw new ArgumentNullException(nameof(bits2)); + } + + var relativeKnowledgeBits = 0F; + for (byte i = 0; i < bits1.Length; i++) + { + relativeKnowledgeBits += bits1.GetBit(i) * bits2.GetBit(i); + } + + return bits1.Length > 0 ? relativeKnowledgeBits / bits1.Length : 0; + } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/Knowledge.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/Knowledge.cs index 8d5cfa32..7f52ae10 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/Knowledge.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/Knowledge.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,8 +12,8 @@ using System; using SymuEngine.Classes.Task; using SymuEngine.Common; -using SymuTools.Algorithm; -using SymuTools.ProbabilityDistributions; +using SymuTools; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeBits.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeBits.cs index 6c278207..4a3f6a16 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeBits.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeBits.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,6 @@ using System; using SymuTools; -using SymuTools.Algorithm; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeCollection.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeCollection.cs index b5a72b29..d386d939 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeCollection.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeCollection.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevel.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevel.cs index a11c5943..4dafc134 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevel.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevel.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevelService.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevelService.cs index a33f883b..b8e0b3ec 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevelService.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeLevelService.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -65,25 +65,7 @@ public static KnowledgeLevel GetValue(string level) /// public static string GetName(KnowledgeLevel level) { - switch (level) - { - case KnowledgeLevel.NoKnowledge: - return "NoKnowledge"; - case KnowledgeLevel.BasicKnowledge: - return "BasicKnowledge"; - case KnowledgeLevel.Foundational: - return "Foundational"; - case KnowledgeLevel.Intermediate: - return "Intermediate"; - case KnowledgeLevel.FullProficiency: - return "FullProficiency"; - case KnowledgeLevel.Expert: - return "Expert"; - case KnowledgeLevel.FullKnowledge: - return "FullKnowledge"; - default: - throw new ArgumentOutOfRangeException(); - } + return level.ToString(); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeMatrix.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeMatrix.cs deleted file mode 100644 index b1b7ec74..00000000 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/KnowledgeMatrix.cs +++ /dev/null @@ -1,370 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -#region using directives - -using System; -using System.Collections.Generic; -using System.Linq; -using SymuEngine.Classes.Agent; -using SymuTools.Algorithm; - -#endregion - -namespace SymuEngine.Repository.Networks.Knowledges -{ - /// - /// Knowledge matrix - /// use to compute metrics based on Knowledges and NetworkKnowledges - /// - /// - public static class KnowledgeMatrix - { - /// - /// Transform networkKnowledge into a dense matrix (filled with 0 & 1) - /// - /// Column - /// Row - /// - /// Knowledges x Agents matrix - public static sbyte[,] GetMatrixKnowledge(KnowledgeCollection knowledges, IEnumerable actors, - NetworkKnowledges knowledgeNetwork) - { - #region Null - - if (knowledges is null) - { - throw new ArgumentNullException(nameof(knowledges)); - } - - if (actors is null) - { - throw new ArgumentNullException(nameof(actors)); - } - - if (knowledgeNetwork is null) - { - throw new ArgumentNullException(nameof(knowledgeNetwork)); - } - - #endregion - - var agentIds = actors.ToList(); - var actorsCount = agentIds.Count(); - var arrays = new sbyte[actorsCount, knowledges.Count]; - for (var i = 0; i < actorsCount; i++) - for (var j = 0; j < knowledges.Count; j++) - { - if (knowledgeNetwork.Exists(agentIds.ElementAt(i), knowledges.List[j].Id)) - { - arrays[i, j] = 1; - } - else - { - arrays[i, j] = 0; - } - } - - return arrays; - } - - /// - /// The likelihood that one actor is to attempt to interact with another is defined by the fact that - /// the actor i knows the fact k or not - /// - /// - /// - /// - /// - public static float[,] GetPassiveInteractionMatrix(KnowledgeCollection knowledges, IEnumerable actors, - NetworkKnowledges knowledgeNetwork) - { - #region Null - - if (knowledges is null) - { - throw new ArgumentNullException(nameof(knowledges)); - } - - if (actors is null) - { - throw new ArgumentNullException(nameof(actors)); - } - - if (knowledgeNetwork is null) - { - throw new ArgumentNullException(nameof(knowledgeNetwork)); - } - - #endregion - - var agentIds = actors.ToList(); - var matrixKnowledge = GetMatrixKnowledge(knowledges, agentIds, knowledgeNetwork); - - var actorsCount = agentIds.Count(); - var arrays = new float[actorsCount, actorsCount]; - for (var i = 0; i < actorsCount; i++) - { - float denominator = 0; - for (var j = 0; j < actorsCount; j++) - for (var k = 0; k < knowledges.Count; k++) - { - denominator += matrixKnowledge[i, k] * matrixKnowledge[j, k]; - } - - for (var j = 0; j < actorsCount; j++) - { - if (denominator > 0) - { - float numerator = 0; - for (var k = 0; k < knowledges.Count; k++) - { - numerator += matrixKnowledge[i, k] * matrixKnowledge[j, k]; - } - - arrays[i, j] = numerator / denominator; - } - else - { - arrays[i, j] = 0; - } - } - } - - return arrays; - } - - /// - /// Combinations without repeating triplets - /// - /// - /// - - //TODO refactor to another class - public static uint MaxTriads(int agentsCount) - { - if (agentsCount < 3) - { - return 0; - } - - if (agentsCount == 3) - { - return 1; - } - - var arrangements = SpecialFunctions.Factorial(agentsCount) / SpecialFunctions.Factorial(agentsCount - 3); - uint max = 0; - try - { - max = Convert.ToUInt32(Math.Round(arrangements / SpecialFunctions.Factorial(3))); - } - catch (OverflowException) - { - } - - return max; - } - - /// - /// The likelihood that one actor is to attempt to interact with another is defined by the fact that - /// The actor i does not know the information k, but j does - /// only if the actor has an active interaction style - /// - /// - /// - /// - /// - /// - public static float[,] GetActiveInteractionMatrix(KnowledgeCollection knowledges, IEnumerable actors, - List actorInteractionsSytles, NetworkKnowledges knowledgeNetwork) - { - #region Null - - if (knowledges is null) - { - throw new ArgumentNullException(nameof(knowledges)); - } - - if (actors is null) - { - throw new ArgumentNullException(nameof(actors)); - } - - if (actorInteractionsSytles is null) - { - throw new ArgumentNullException(nameof(actorInteractionsSytles)); - } - - if (knowledgeNetwork is null) - { - throw new ArgumentNullException(nameof(knowledgeNetwork)); - } - - #endregion - - var agentIds = actors.ToList(); - var matrixKnowledge = GetMatrixKnowledge(knowledges, agentIds, knowledgeNetwork); - var actorsCount = agentIds.Count(); - var arrays = new float[actorsCount, actorsCount]; - for (var i = 0; i < actorsCount; i++) - { - if (actorInteractionsSytles[i]) - { - float denominator = 0; - for (var j = 0; j < actorsCount; j++) - for (var k = 0; k < knowledges.Count; k++) - { - if (matrixKnowledge[i, k] == 0 && matrixKnowledge[j, k] == 1) - { - denominator += 1; - } - } - - for (var j = 0; j < actorsCount; j++) - { - if (denominator > 0) - { - float numerator = 0; - for (var k = 0; k < knowledges.Count; k++) - // The goal of getting new information - { - if (matrixKnowledge[i, k] == 0 && matrixKnowledge[j, k] == 1) - { - numerator += 1; - } - } - - arrays[i, j] = numerator / denominator; - } - else - { - arrays[i, j] = 0; - } - } - } - else - { - // Actor is passive - for (var j = 0; j < actorsCount; j++) - { - arrays[i, j] = 0; - } - } - } - - return arrays; - } - - //TODO refactor to another class - public static uint NumberOfTriads(KnowledgeCollection knowledges, IEnumerable actors, - NetworkKnowledges knowledgeNetwork) - { - #region Null - - if (knowledges is null) - { - throw new ArgumentNullException(nameof(knowledges)); - } - - if (actors is null) - { - throw new ArgumentNullException(nameof(actors)); - } - - if (knowledgeNetwork is null) - { - throw new ArgumentNullException(nameof(knowledgeNetwork)); - } - - #endregion - - var agentIds = actors.ToList(); - var actorsCount = agentIds.Count(); - if (actorsCount < 3) - { - return 0; - } - - var averageInteraction = GetAverageInteractionMatrix(knowledges, agentIds, knowledgeNetwork); - var interactionMatrix = GetPassiveInteractionMatrix(knowledges, agentIds, knowledgeNetwork); - var interactionForTriads = new sbyte[actorsCount, actorsCount]; - for (var i = 0; i < actorsCount; i++) - for (var j = 0; j < actorsCount; j++) - { - if (i != j && interactionMatrix[i, j] >= averageInteraction) - { - interactionForTriads[i, j] = 1; - } - else - { - interactionForTriads[i, j] = 0; - } - } - - uint numberOfTriads = 0; - - for (var i = 0; i < actorsCount - 2; i++) - { - if (interactionForTriads[i, i + 1] + interactionForTriads[i + 1, i] > 0 - && interactionForTriads[i, i + 2] + interactionForTriads[i + 2, i] > 0 - && interactionForTriads[i + 1, i + 2] + interactionForTriads[i + 2, i + 1] > 0) - { - numberOfTriads++; - } - } - - return numberOfTriads; - } - - public static float GetAverageInteractionMatrix(KnowledgeCollection knowledges, IEnumerable actors, - NetworkKnowledges knowledgeNetwork) - { - #region Null - - if (knowledges is null) - { - throw new ArgumentNullException(nameof(knowledges)); - } - - if (actors is null) - { - throw new ArgumentNullException(nameof(actors)); - } - - if (knowledgeNetwork is null) - { - throw new ArgumentNullException(nameof(knowledgeNetwork)); - } - - #endregion - - var agentIds = actors.ToList(); - var interactionMatrix = GetPassiveInteractionMatrix(knowledges, agentIds, knowledgeNetwork); - - var actorsCount = agentIds.Count(); - if (actorsCount == 0 || actorsCount == 1) - { - return 0; - } - - float average = 0; - for (var i = 0; i < agentIds.Count(); i++) - for (var j = 0; j < agentIds.Count(); j++) - { - if (i != j) - { - average += interactionMatrix[i, j]; - } - } - - return average / (actorsCount * (actorsCount - 1)); - } - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Knowledges/NetworkKnowledges.cs b/Symu source code/SymuEngine/Repository/Networks/Knowledges/NetworkKnowledges.cs index 7fcccf14..e3d896aa 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Knowledges/NetworkKnowledges.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Knowledges/NetworkKnowledges.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Common; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationLink.cs b/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationLink.cs deleted file mode 100644 index a024d319..00000000 --- a/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationLink.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -#region using directives - -using SymuEngine.Classes.Agent; - -#endregion - -namespace SymuEngine.Repository.Networks.Link -{ - /// - /// Describe the communication link between two people - /// Report to , communicate to - /// in the context of a team - /// - /// - /// a teammate report to a manager in the context of a team, - /// but can communicate to him in the context of a task force - /// - public class CommunicationLink : NetworkLink - { - /// - /// AgentId1 communicate to AgentId2 in the context of the TeamId - /// - /// - /// - /// - /// - public CommunicationLink(AgentId agentId1, CommunicationType communication, AgentId agentId2, AgentId teamId) : - base(agentId1, agentId2) - { - Communication = communication; - TeamId = teamId; - } - - /// - /// in the context of a team - /// - public AgentId TeamId { get; } - - /// - /// Type of communication - /// Report to , communicate to - /// - public CommunicationType Communication { get; } - - public override bool Equals(object obj) - { - return obj is CommunicationLink link && - Communication == link.Communication && - AgentId1.Equals(link.AgentId1) && - AgentId2.Equals(link.AgentId2) && - TeamId.Equals(link.TeamId); - } - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationType.cs b/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationType.cs deleted file mode 100644 index 4ea1de26..00000000 --- a/Symu source code/SymuEngine/Repository/Networks/Link/CommunicationType.cs +++ /dev/null @@ -1,24 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -namespace SymuEngine.Repository.Networks.Link -{ - public enum CommunicationType - { - /// - /// Teammate report to its manager - /// - ReportTo, - - /// - /// Teammate communicate to its teammates, its PO, its users, ... - /// - CommunicateTo - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLink.cs b/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLink.cs index 2063fdf1..a23723d6 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLink.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLink.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,81 +9,105 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion namespace SymuEngine.Repository.Networks.Link { /// - /// Sphere of interaction + /// Sphere of interaction - link are bidirectional. + /// AgentId1 has the smallest key + /// AgentId2 has the highest key /// public class NetworkLink { + /// + /// Constructor + /// + /// + /// public NetworkLink(AgentId agentId1, AgentId agentId2) { - AgentId1 = agentId1; - AgentId2 = agentId2; + if (agentId1.Key < agentId2.Key) + { + AgentId1 = agentId1; + AgentId2 = agentId2; + } + else + { + AgentId1 = agentId2; + AgentId2 = agentId1; + } + + Activate(); } /// - /// Unique key of the agent + /// Number of links between the two agents /// - public AgentId AgentId1 { get; } + public byte Count { get; private set; } /// - /// Unique key of the agent + /// Unique key of the agent with the smallest key /// - public AgentId AgentId2 { get; } + public AgentId AgentId1 { get; } /// - /// State of the Link : Active / Passive + /// Unique key of the agent with the highest key /// - public NetworkLinkState State { get; private set; } = NetworkLinkState.Active; + public AgentId AgentId2 { get; } - public bool IsActive => State == NetworkLinkState.Active; - public bool IsPassive => State == NetworkLinkState.Passive; + public bool IsActive => Count > 0; + public bool IsPassive => Count == 0; public void Activate() { - State = NetworkLinkState.Active; + Count++; } public void Deactivate() { - State = NetworkLinkState.Passive; + if (Count > 0) + { + Count--; + } + } + + public bool HasActiveLinks(AgentId agentId) + { + return IsActive && (AgentId1.Equals(agentId) || AgentId2.Equals(agentId)); } public bool HasActiveLink(AgentId agentId1, AgentId agentId2) { - return HasLink(agentId1, agentId2) && IsActive; + return IsActive && HasLink(agentId1, agentId2); } public bool HasPassiveLink(AgentId agentId1, AgentId agentId2) { - return HasLink(agentId1, agentId2) && IsPassive; + return IsPassive && HasLink(agentId1, agentId2); } public bool HasLink(AgentId agentId1, AgentId agentId2) { - return AgentId1.Equals(agentId1) && AgentId2.Equals(agentId2) || - AgentId1.Equals(agentId2) && AgentId2.Equals(agentId1); + if (agentId1.Key < agentId2.Key) + { + return AgentId1.Equals(agentId1) && AgentId2.Equals(agentId2); + } + + return AgentId1.Equals(agentId2) && AgentId2.Equals(agentId1); } public override bool Equals(object obj) { return obj is NetworkLink link && - AgentId1.Equals(link.AgentId1) && AgentId2.Equals(link.AgentId2); - } - - public bool HasActiveLinks(AgentId agentId) - { - return IsActive && AgentId1.Equals(agentId); + link.HasLink(AgentId1, AgentId2); } - public bool HasActiveLinks(AgentId agentId, byte groupClassKey) - { - return AgentId2.ClassKey == groupClassKey && HasActiveLinks(agentId); - } + //public bool HasActiveLinks(AgentId agentId, byte groupClassKey) + //{ + // return AgentId2.ClassKey == groupClassKey && HasActiveLinks(agentId); + //} } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinkState.cs b/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinkState.cs deleted file mode 100644 index 99ee0b0c..00000000 --- a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinkState.cs +++ /dev/null @@ -1,20 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -namespace SymuEngine.Repository.Networks.Link -{ - /// - /// LinkType of a Network - /// - public enum NetworkLinkState - { - Active, - Passive - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinks.cs b/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinks.cs index 8aeba5f8..7bf82a3c 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinks.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Link/NetworkLinks.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,9 +9,10 @@ #region using directives +using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion @@ -22,7 +23,9 @@ namespace SymuEngine.Repository.Networks.Link /// public class NetworkLinks { + private uint _maxLinksCount; public List List { get; } = new List(); + public int Count => List.Count; /// /// Gets or sets the element at the specified index @@ -46,33 +49,26 @@ public bool Any() } /// - /// teammateId is managerId subordinate in the context of teamId + /// Reinitialize links between members of a group : + /// Add a bi directional link between every member of a group /// - /// - /// - /// - public void AddSubordinate(AgentId teammateId, AgentId managerId, AgentId teamId) + public void AddLinks(List members) { - var link = new CommunicationLink(teammateId, CommunicationType.ReportTo, managerId, teamId); - AddLink(link); - } - - public void DeactivateSubordinate(AgentId teammateId, AgentId managerId, AgentId teamId) - { - var link = new CommunicationLink(teammateId, CommunicationType.ReportTo, managerId, teamId); - DeactivateLink(link); - } + if (members == null) + { + throw new ArgumentNullException(nameof(members)); + } - /// - /// teammate1 and teammate2 are now teammates in the context of the teamId - /// Link are bidirectional - /// - public void AddMembers(AgentId teammateId1, AgentId teammateId2, AgentId teamId) - { - var link1 = new CommunicationLink(teammateId1, CommunicationType.CommunicateTo, teammateId2, teamId); - AddLink(link1); - var link2 = new CommunicationLink(teammateId2, CommunicationType.CommunicateTo, teammateId1, teamId); - AddLink(link2); + var count = members.Count; + for (var i = 0; i < count; i++) + { + var agentId1 = members[i]; + for (var j = i + 1; j < count; j++) + { + var agentId2 = members[j]; + AddLink(agentId1, agentId2); + } + } } public void Clear() @@ -81,55 +77,58 @@ public void Clear() } /// - /// Use AddMembers + /// Use AddLink + /// Link is bidirectional /// - /// - public void AddLink(CommunicationLink link) + /// + /// + public void AddLink(AgentId agentId1, AgentId agentId2) { - if (Exists(link)) + if (agentId1.Equals(agentId2)) + { + return; + } + + if (Exists(agentId1, agentId2)) { - Activate(link); + Activate(agentId1, agentId2); } else { - List.Add(link); + List.Add(new NetworkLink(agentId1, agentId2)); } } - public bool Exists(AgentId teammateId1, CommunicationType type, AgentId teammateId2, AgentId teamId) - { - var link = new CommunicationLink(teammateId1, type, teammateId2, teamId); - return Exists(link); - } - public bool Exists(NetworkLink link) { return List.Contains(link); } - private NetworkLink Get(NetworkLink link) + /// + /// Link exists between agentId1 and agentId2 in the context of the groupId + /// + /// + /// + public bool Exists(AgentId agentId1, AgentId agentId2) { - return List.Find(l => l.Equals(link)); + return List.Exists(x => x.HasLink(agentId1, agentId2)); } - private void Activate(NetworkLink link) + private NetworkLink Get(AgentId agentId1, AgentId agentId2) { - Get(link).Activate(); + return List.Find(x => x.HasLink(agentId1, agentId2)); } - public void DeactivateTeammates(AgentId teammateId1, AgentId teammateId2, AgentId teamId) + private void Activate(AgentId agentId1, AgentId agentId2) { - var link1 = new CommunicationLink(teammateId1, CommunicationType.CommunicateTo, teammateId2, teamId); - DeactivateLink(link1); - var link2 = new CommunicationLink(teammateId2, CommunicationType.CommunicateTo, teammateId1, teamId); - DeactivateLink(link2); + Get(agentId1, agentId2).Activate(); } - private void DeactivateLink(NetworkLink link) + public void DeactivateLink(AgentId agentId1, AgentId agentId2) { - if (Exists(link)) + if (Exists(agentId1, agentId2)) { - Get(link).Deactivate(); + Get(agentId1, agentId2).Deactivate(); } } @@ -138,19 +137,36 @@ public bool HasActiveLink(AgentId agentId1, AgentId agentId2) return List.Exists(l => l.HasActiveLink(agentId1, agentId2)); } + public float CountLinks(AgentId agentId1, AgentId agentId2) + { + return Exists(agentId1, agentId2) ? Get(agentId1, agentId2).Count : 0; + } + + public float NormalizedCountLinks(AgentId agentId1, AgentId agentId2) + { + return _maxLinksCount == 0 ? 0 : CountLinks(agentId1, agentId2) / _maxLinksCount; + } + + public void SetMaxLinksCount() + { + _maxLinksCount = List.Any() ? List.Max(x => x.Count) : (uint) 0; + } + + #region unit tests + public bool HasPassiveLink(AgentId agentId1, AgentId agentId2) { return List.Exists(l => l.HasPassiveLink(agentId1, agentId2)); } + /// + /// Get all the active links of an agent + /// public IEnumerable GetActiveLinks(AgentId agentId) { return List.FindAll(l => l.HasActiveLinks(agentId)).Select(l => l.AgentId2).Distinct(); } - public IEnumerable GetActiveLinks(AgentId agentId, byte groupClassKey) - { - return List.FindAll(l => l.HasActiveLinks(agentId, groupClassKey)).Select(l => l.AgentId2).Distinct(); - } + #endregion } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Network.cs b/Symu source code/SymuEngine/Repository/Networks/Network.cs index 474918d8..a46ee866 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Network.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Network.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,9 +12,11 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.Templates.Communication; +using SymuEngine.Classes.Organization; +using SymuEngine.Common; using SymuEngine.Repository.Networks.Activities; using SymuEngine.Repository.Networks.Beliefs; using SymuEngine.Repository.Networks.Communication; @@ -26,6 +28,7 @@ using SymuEngine.Repository.Networks.Link; using SymuEngine.Repository.Networks.Portfolio; using SymuEngine.Repository.Networks.Role; +using SymuEngine.Repository.Networks.Sphere; #endregion @@ -36,11 +39,14 @@ namespace SymuEngine.Repository.Networks /// public class Network { - public Network(AgentTemplates agentTemplates) + public Network(AgentTemplates agentTemplates, InteractionSphereModel interactionSphereModel) { NetworkCommunications = new NetworkCommunications(agentTemplates); + InteractionSphere = new InteractionSphere(interactionSphereModel); } + public AgentState State { get; set; } = AgentState.NotStarted; + /// /// Directory of social links between AgentIds, with their interaction type /// Who report/communicate to who @@ -103,6 +109,12 @@ public Network(AgentTemplates agentTemplates) /// public NetworkDatabases NetworkDatabases { get; } = new NetworkDatabases(); + /// + /// Derived Parameters from others networks. + /// these parameters are use indirectly to change agent behavior. + /// + public InteractionSphere InteractionSphere { get; } + #region Clear & remove Agents public void Clear() @@ -240,18 +252,33 @@ public void AddMemberToGroup(AgentId agentId, float allocation, AgentId groupId) lock (NetworkGroups) { NetworkGroups.AddGroup(groupId); - foreach (var newTeammateId in NetworkGroups.GetMembers(groupId, agentId.ClassKey)) + if (State == AgentState.Started) { - NetworkLinks.AddMembers(agentId, newTeammateId, groupId); + // AddLink is done during the simulation. 1t the initialization, use InitializeNetworkLinks, for performance issues + foreach (var newTeammateId in NetworkGroups.GetMembers(groupId, agentId.ClassKey)) + { + NetworkLinks.AddLink(agentId, newTeammateId); + } } - // intentionally after Links.AddMembers NetworkGroups.AddMember(agentId, allocation, groupId); } NetworkPortfolios.AddMemberToGroup(agentId, groupId); } + /// + /// Initialize the network links. + /// For performance it is not done in AddMemberToGroup at initialization + /// + public void InitializeNetworkLinks() + { + foreach (var groupId in NetworkGroups.GetGroups().ToList()) + { + NetworkLinks.AddLinks(NetworkGroups.GetMembers(groupId, SymuYellowPages.Actor).ToList()); + } + } + /// /// Remove an agent to a group /// It doesn't handle roles @@ -262,7 +289,7 @@ public void RemoveMemberFromGroup(AgentId agentId, AgentId groupId) { foreach (var oldTeammateId in NetworkGroups.GetMembers(groupId, agentId.ClassKey)) { - NetworkLinks.DeactivateTeammates(agentId, oldTeammateId, groupId); + NetworkLinks.DeactivateLink(agentId, oldTeammateId); } NetworkGroups.RemoveMember(agentId, groupId); @@ -284,16 +311,6 @@ public bool IsMemberOfGroup(AgentId agentId, AgentId groupId) return NetworkGroups.IsMemberOfGroup(agentId, groupId); } - /// - /// Get all the active links of an agent - /// - /// - /// - public IEnumerable GetActiveLinks(AgentId agentId) - { - return NetworkLinks.GetActiveLinks(agentId); - } - /// /// Add a Knowledge to the repository /// diff --git a/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolio.cs b/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolio.cs index 7948d6cb..c0808aba 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolio.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolio.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolios.cs b/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolios.cs index af274b97..9aa08eae 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolios.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Portfolio/NetworkPortfolios.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRole.cs b/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRole.cs index 63d16f40..71284ab6 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRole.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRole.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,7 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRoles.cs b/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRoles.cs index b0064003..e11843d9 100644 --- a/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRoles.cs +++ b/Symu source code/SymuEngine/Repository/Networks/Role/NetworkRoles.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; #endregion diff --git a/Symu source code/SymuEngine/Repository/Networks/Sphere/DerivedParameter.cs b/Symu source code/SymuEngine/Repository/Networks/Sphere/DerivedParameter.cs new file mode 100644 index 00000000..053bddc0 --- /dev/null +++ b/Symu source code/SymuEngine/Repository/Networks/Sphere/DerivedParameter.cs @@ -0,0 +1,80 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuEngine.Classes.Organization; + +#endregion + +namespace SymuEngine.Repository.Networks.Sphere +{ + public readonly struct DerivedParameter + { + /// + /// The closer two agents are in each of these areas, the more likely they will be to interact. + /// + public float SocialDemographic { get; } + + /// + /// + public float RelativeBelief { get; } + + /// + /// An agent’s relative expertise is a function of its expertise and the expertise of an agent with which it is + /// interacting, and helps affect the transfer of knowledge between agents. + /// While an agent may be an expert in one interaction, it may not be an expert in another interaction since relative + /// expertise partially depends upon the knowledge of the interaction partner. + /// In general, agents prefer to seek out others who are relative experts, especially when attempting to accomplish a + /// particular task. + /// + public float RelativeKnowledge { get; } + + /// + /// An agent’s relative activity + /// In general, agents prefer to seek out others who are doing the same activities, especially when attempting to + /// accomplish a particular task. + /// + public float RelativeActivity { get; } + + /// + /// + /// + /// An agent that acts via homophily attempts to find an interaction partner that shares its characteristics. + /// When searching for suitable partners, the agent will stress agents who have similar socio-demographic parameters, + /// similar knowledge, and similar beliefs. + /// This process utilizes the derived parameters + /// + public float Homophily => SocialDemographic + RelativeBelief + RelativeKnowledge + RelativeActivity; + + public DerivedParameter(float socialDemographic, float relativeBelief, float relativeKnowledge, + float relativeActivity) + { + SocialDemographic = socialDemographic; + RelativeBelief = relativeBelief; + RelativeKnowledge = relativeKnowledge; + RelativeActivity = relativeActivity; + } + + public DerivedParameter(InteractionSphereModel model, float socialDemographic, float relativeBelief, + float relativeKnowledge, float relativeActivity) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + SocialDemographic = socialDemographic * model.SocialDemographicWeight; + RelativeBelief = relativeBelief * model.RelativeBeliefWeight; + RelativeKnowledge = relativeKnowledge * model.RelativeKnowledgeWeight; + RelativeActivity = relativeActivity * model.RelativeActivityWeight; + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionMatrix.cs b/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionMatrix.cs new file mode 100644 index 00000000..c4a56862 --- /dev/null +++ b/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionMatrix.cs @@ -0,0 +1,132 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuTools; +using SymuTools.Math; + +#endregion + +namespace SymuEngine.Repository.Networks.Sphere +{ + /// + /// Knowledge matrix + /// use to compute metrics based on Knowledges and NetworkKnowledges + /// + /// + public static class InteractionMatrix + { + /// + /// The likelihood that one actor is to attempt to interact with another is defined by the fact that + /// the actor i knows the fact k or not + /// + /// + /// + public static float GetAverageInteractionMatrix(float[,] interactionMatrix) + { + if (interactionMatrix == null) + { + throw new ArgumentNullException(nameof(interactionMatrix)); + } + + var actorsCount = interactionMatrix.GetLength(0); + if (actorsCount == 0 || actorsCount == 1) + { + return 0; + } + + float average = 0; + for (var i = 0; i < actorsCount; i++) + for (var j = 0; j < actorsCount; j++) + { + if (i != j) + { + average += interactionMatrix[i, j]; + } + } + + return average / (actorsCount * (actorsCount - 1)); + } + + public static uint NumberOfTriads(DerivedParameter[,] network) + { + if (network == null) + { + return 0; + } + + var actorsCount = network.GetLength(0); + if (actorsCount < 3) + { + return 0; + } + + var interactionMatrix = GetInteractionMatrix(network, actorsCount); + + var averageInteraction = GetAverageInteractionMatrix(interactionMatrix); + var interactionForTriads = new sbyte[actorsCount, actorsCount]; + for (var i = 0; i < actorsCount; i++) + for (var j = 0; j < actorsCount; j++) + { + if (interactionMatrix[i, j] >= averageInteraction - Constants.Tolerance && + interactionMatrix[i, j] > Constants.Tolerance) + { + interactionForTriads[i, j] = 1; + } + else + { + interactionForTriads[i, j] = 0; + } + } + + uint numberOfTriads = 0; + for (var i = 0; i < actorsCount; i++) + { + for (var j = i + 1; j < actorsCount; j++) + { + for (var k = j + 1; k < actorsCount; k++) + { + if (interactionForTriads[i, j] + interactionForTriads[j, i] > Constants.Tolerance + && interactionForTriads[i, k] + interactionForTriads[k, i] > Constants.Tolerance + && interactionForTriads[j, k] + interactionForTriads[k, j] > Constants.Tolerance) + { + numberOfTriads++; + } + } + } + } + + return numberOfTriads; + } + + public static float[,] GetInteractionMatrix(DerivedParameter[,] network, int actorsCount) + { + var interactionMatrix = new float[actorsCount, actorsCount]; + for (var i = 0; i < actorsCount; i++) + for (var j = 0; j < actorsCount; j++) + { + interactionMatrix[i, j] = network[i, j].Homophily; + } + + return interactionMatrix; + } + + /// + /// Maximum number of combinations without repeating triplets + /// + /// + /// + public static uint MaxTriads(int agentsCount) + { + return Combinatorics.Combinations(agentsCount, 3); + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionSphere.cs b/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionSphere.cs new file mode 100644 index 00000000..35d76762 --- /dev/null +++ b/Symu source code/SymuEngine/Repository/Networks/Sphere/InteractionSphere.cs @@ -0,0 +1,521 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using System.Collections.Generic; +using System.Linq; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; +using SymuEngine.Repository.Networks.Activities; +using SymuEngine.Repository.Networks.Beliefs; +using SymuEngine.Repository.Networks.Knowledges; +using SymuEngine.Repository.Networks.Link; +using SymuTools; +using SymuTools.Math.ProbabilityDistributions; + +#endregion + +namespace SymuEngine.Repository.Networks.Sphere +{ + /// + /// Array Agent * Agent of derived parameters from all networks. + /// Those parameters are relative parameters of an agent fro another agent. + /// these parameters are use indirectly to change agent behavior. + /// + public class InteractionSphere + { + private Dictionary _agentIndex; + private Dictionary _indexAgent; + private readonly InteractionSphereModel _model; + + public InteractionSphere(InteractionSphereModel model) + { + _model = model ?? throw new ArgumentNullException(nameof(model)); + } + + /// + /// List of all agentId and their enculturation information + /// + public DerivedParameter[,] Sphere { get; private set; } + + public void SetSphere(bool initialization, List agentIds, Network network) + { + if (agentIds == null) + { + throw new ArgumentNullException(nameof(agentIds)); + } + + if (network == null) + { + throw new ArgumentNullException(nameof(network)); + } + + var modelOn = _model.On; + var sphereChange = initialization || _model.SphereUpdateOverTime; + if (!modelOn || !sphereChange) + { + return; + } + + network.NetworkLinks.SetMaxLinksCount(); + if (_model.RandomlyGeneratedSphere) + { + if (initialization) + { + SetSphereRandomly(agentIds); + } + else + { + UpdateSphereRandomly(agentIds, network); + } + } + else + { + SetSphereWithSimilarityMatching(agentIds, network); + } + } + + /// + /// Set sphere randomly based on InteractionPatterns + /// + /// + public void SetSphereRandomly(IReadOnlyList agentIds) + { + if (agentIds == null) + { + throw new ArgumentNullException(nameof(agentIds)); + } + + var count = agentIds.Count; + _agentIndex = new Dictionary(); + _indexAgent = new Dictionary(); + Sphere = new DerivedParameter[count, count]; + // for the moment the matrix is symmetrical + for (var i = 0; i < count; i++) + { + var agentI = agentIds[i]; + _agentIndex[agentI] = i; + _indexAgent[i] = agentI; + + var density = ContinuousUniform.Sample(_model.MinSphereDensity, _model.MaxSphereDensity); + for (var j = i + 1; j < count; j++) + { + var value = Bernoulli.Sample(density) ? ContinuousUniform.Sample(0F, 1F) : 0F; + Sphere[i, j] = + new DerivedParameter(_model, value, value, value, value); + Sphere[j, i] = Sphere[i, j]; + } + } + } + + /// + /// Update sphere randomly based on InteractionPatterns with new agent + /// + /// + /// + public void UpdateSphereRandomly(IReadOnlyList agentIds, Network network) + { + if (agentIds == null) + { + throw new ArgumentNullException(nameof(agentIds)); + } + + if (network == null) + { + throw new ArgumentNullException(nameof(network)); + } + + var count = agentIds.Count; + var tempAgentIndex = new Dictionary(); + var tempIndexAgent = new Dictionary(); + var tempSphere = new DerivedParameter[count, count]; + for (var i = 0; i < count; i++) + { + var agentI = agentIds[i]; + tempAgentIndex[agentI] = i; + tempIndexAgent[i] = agentI; + if (_agentIndex.ContainsKey(agentI)) + { + var oldIndexI = _agentIndex[agentI]; + for (var j = i + 1; j < count; j++) + { + var agentJ = agentIds[j]; + if (_agentIndex.ContainsKey(agentJ)) + { + var oldIndexJ = _agentIndex[agentJ]; + + var tempDerivedParameter = SetDerivedParameter(network, agentI, agentJ); + var socialProximity = Math.Max(tempDerivedParameter.SocialDemographic, + Sphere[oldIndexI, oldIndexJ].SocialDemographic); + var relativeBelief = Math.Max(tempDerivedParameter.RelativeBelief, + Sphere[oldIndexI, oldIndexJ].RelativeBelief); + var relativeKnowledge = Math.Max(tempDerivedParameter.RelativeKnowledge, + Sphere[oldIndexI, oldIndexJ].RelativeKnowledge); + var relativeActivity = Math.Max(tempDerivedParameter.RelativeActivity, + Sphere[oldIndexI, oldIndexJ].RelativeActivity); + + tempSphere[i, j] = new DerivedParameter(socialProximity, relativeBelief, relativeKnowledge, + relativeActivity); + } + else + { + //new agent + var density = ContinuousUniform.Sample(_model.MinSphereDensity, _model.MaxSphereDensity); + var value = Bernoulli.Sample(density) ? ContinuousUniform.Sample(0F, 1F) : 0F; + tempSphere[i, j] = + new DerivedParameter(_model, value, value, value, value); + } + + Sphere[j, i] = Sphere[i, j]; + } + } + else + { + // new agent + var density = ContinuousUniform.Sample(_model.MinSphereDensity, _model.MaxSphereDensity); + for (var j = i + 1; j < count; j++) + { + var value = Bernoulli.Sample(density) ? ContinuousUniform.Sample(0F, 1F) : 0F; + tempSphere[i, j] = + new DerivedParameter(_model, value, value, + value, value); + Sphere[j, i] = Sphere[i, j]; + } + } + } + + _agentIndex = tempAgentIndex; + _indexAgent = tempIndexAgent; + Sphere = tempSphere; + } + + private void SetSphereWithSimilarityMatching(IReadOnlyList agentIds, Network network) + { + var count = agentIds.Count; + _agentIndex = new Dictionary(); + _indexAgent = new Dictionary(); + Sphere = new DerivedParameter[count, count]; + // for the moment it is a symmetrical matrix + for (var i = 0; i < count; i++) + { + var agentI = agentIds[i]; + _agentIndex[agentI] = i; + _indexAgent[i] = agentI; + for (var j = i + 1; j < count; j++) + { + var agentJ = agentIds[j]; + Sphere[i, j] = SetDerivedParameter(network, agentI, agentJ); + Sphere[j, i] = Sphere[i, j]; + } + } + } + + private DerivedParameter SetDerivedParameter(Network network, AgentId agentI, AgentId agentJ) + { + var socialProximity = _model.SocialDemographicWeight > Constants.Tolerance + ? SetSocialProximity(agentI, agentJ, network.NetworkLinks) + : 0; + + var relativeBelief = _model.RelativeBeliefWeight > Constants.Tolerance + ? SetRelativeBelief(agentI, agentJ, network.NetworkBeliefs) + : 0; + var relativeKnowledge = _model.RelativeKnowledgeWeight > Constants.Tolerance + ? SetRelativeKnowledge(agentI, agentJ, network.NetworkKnowledges) + : 0; + var relativeActivity = _model.RelativeActivityWeight > Constants.Tolerance + ? SetRelativeActivity(agentI, agentJ, network.NetworkActivities) + : 0; + + var derivedParameter = + new DerivedParameter(_model, socialProximity, relativeBelief, relativeKnowledge, relativeActivity); + return derivedParameter; + } + + /// + /// The closer two agents are in the belief area, the more likely they will be to interact. + /// + public static float SetRelativeBelief(AgentId agentId1, AgentId agentId2, NetworkBeliefs networkBeliefs) + { + if (networkBeliefs == null) + { + throw new ArgumentNullException(nameof(networkBeliefs)); + } + + if (!networkBeliefs.Exists(agentId1) || !networkBeliefs.Exists(agentId2)) + { + return 0; + } + + var relativeBelief = 0F; + var beliefIds = networkBeliefs.GetBeliefIds(agentId1).ToList(); + foreach (var beliefId in beliefIds) + { + var bits1 = networkBeliefs.GetAgentBelief(agentId1, beliefId).BeliefBits; + if (!networkBeliefs.Exists(agentId2, beliefId)) + { + continue; + } + + var bits2 = networkBeliefs.GetAgentBelief(agentId2, beliefId).BeliefBits; + relativeBelief += Bits.GetRelativeBits(bits1, bits2); + } + + return beliefIds.Any() ? relativeBelief / beliefIds.Count : 0; + } + + /// + /// The closer two agents are in the knowledge area, the more likely they will be to interact. + /// + public static float SetRelativeKnowledge(AgentId agentId1, AgentId agentId2, + NetworkKnowledges networkKnowledges) + { + if (networkKnowledges == null) + { + throw new ArgumentNullException(nameof(networkKnowledges)); + } + + if (!networkKnowledges.Exists(agentId1) || !networkKnowledges.Exists(agentId2)) + { + return 0; + } + + var relativeExpertise = 0F; + var knowledgeIds = networkKnowledges.GetKnowledgeIds(agentId1).ToList(); + foreach (var knowledgeId in knowledgeIds) + { + var knowledgeBits1 = networkKnowledges.GetAgentKnowledge(agentId1, knowledgeId).KnowledgeBits; + if (!networkKnowledges.Exists(agentId2, knowledgeId)) + { + continue; + } + + var knowledgeBits2 = networkKnowledges.GetAgentKnowledge(agentId2, knowledgeId).KnowledgeBits; + if (!knowledgeBits2.IsNull) + { + relativeExpertise += Bits.GetRelativeBits(knowledgeBits1, knowledgeBits2); + } + } + + return knowledgeIds.Any() ? relativeExpertise / knowledgeIds.Count : 0; + } + + /// + /// The closer two agents are, the more likely they will be to interact. + /// + /// + /// + /// + /// + public static float SetSocialProximity(AgentId agentId1, AgentId agentId2, NetworkLinks networkLinks) + { + //todo graph : number of nodes between agentId1 and agentId2 + if (networkLinks == null) + { + throw new ArgumentNullException(nameof(networkLinks)); + } + + return networkLinks.NormalizedCountLinks(agentId1, agentId2); + } + + /// + /// The closer two agents are on this area, the more likely they will be to interact. + /// + /// + /// + /// + /// + public static float SetRelativeActivity(AgentId agentId1, AgentId agentId2, NetworkActivities networkActivities) + { + if (networkActivities == null) + { + throw new ArgumentNullException(nameof(networkActivities)); + } + + var activity1 = networkActivities.GetAgentActivities(agentId1).ToList(); + var activity2 = networkActivities.GetAgentActivities(agentId2).ToList(); + var relativeActivity = activity1.Count(activity => activity2.Contains(activity)); + return activity1.Any() ? relativeActivity / activity1.Count : 0; + } + + /// + /// List of AgentId for interactions : there is Active link (difference with GetAgentIdsForNewInteractions) + /// based on the interaction strategy of the interaction patterns : + /// Filtered with interactionStrategy and limit with number of new interactions + /// + /// + /// can come from InteractionPatterns, but passed in parameter for unit test + /// + /// + public IEnumerable GetAgentIdsForInteractions(AgentId agentId, InteractionStrategy interactionStrategy, + InteractionPatterns interactionPatterns) + { + if (interactionPatterns is null) + { + throw new ArgumentNullException(nameof(interactionPatterns)); + } + + if (!_model.On || !_agentIndex.ContainsKey(agentId)) + { + return new List(); + } + + var agentIdDerivedParameters = new Dictionary(); + var agentIndex = _agentIndex[agentId]; + for (var i = 0; i < _agentIndex.Count; i++) + { + if (i == agentIndex) + { + continue; + } + + agentIdDerivedParameters.Add(_indexAgent[i], Sphere[agentIndex, i]); + } + + return OrderAgentIdsForInteractions(interactionStrategy, agentIdDerivedParameters); + } + + private static IEnumerable OrderAgentIdsForInteractions(InteractionStrategy interactionStrategy, + Dictionary agentIdDerivedParameters) + { + List orderedAgentIds; + switch (interactionStrategy) + { + case InteractionStrategy.Homophily: + orderedAgentIds = agentIdDerivedParameters.OrderByDescending(x => x.Value.Homophily) + .Select(x => x.Key) + .ToList(); + break; + case InteractionStrategy.Knowledge: + orderedAgentIds = agentIdDerivedParameters.OrderByDescending(x => x.Value.RelativeKnowledge) + .Select(x => x.Key).ToList(); + break; + case InteractionStrategy.Activities: + orderedAgentIds = agentIdDerivedParameters.OrderByDescending(x => x.Value.RelativeActivity) + .Select(x => x.Key).ToList(); + break; + case InteractionStrategy.Beliefs: + orderedAgentIds = agentIdDerivedParameters.OrderByDescending(x => x.Value.RelativeBelief) + .Select(x => x.Key) + .ToList(); + break; + case InteractionStrategy.SocialDemographics: + orderedAgentIds = agentIdDerivedParameters.OrderByDescending(x => x.Value.SocialDemographic) + .Select(x => x.Key).ToList(); + break; + default: + throw new ArgumentOutOfRangeException(nameof(interactionStrategy), interactionStrategy, null); + } + + return orderedAgentIds; + } + + /// + /// List of AgentId for new interactions : there is no Active link (difference with GetAgentIdsForInteractions) + /// based on the interaction strategy of the interaction patterns : + /// Filtered with interactionStrategy and limit with number of new interactions + /// + /// + /// can come from InteractionPatterns, but passed in parameter for unit test + /// + /// + public IEnumerable GetAgentIdsForNewInteractions(AgentId agentId, + InteractionStrategy interactionStrategy, InteractionPatterns interactionPatterns) + { + if (interactionPatterns == null) + { + throw new ArgumentNullException(nameof(interactionPatterns)); + } + + if (!_model.On || !_model.SphereUpdateOverTime || !_agentIndex.ContainsKey(agentId)) + { + return new List(); + } + + var agentIdDerivedParameters = new Dictionary(); + var agentIndex = _agentIndex[agentId]; + for (var i = 0; i < _agentIndex.Count; i++) + { + if (i == agentIndex || Sphere[agentIndex, i].SocialDemographic > Constants.Tolerance) + { + continue; + } + + agentIdDerivedParameters.Add(_indexAgent[i], Sphere[agentIndex, i]); + } + + return OrderAgentIdsForInteractions(interactionStrategy, agentIdDerivedParameters); + } + + /// + /// Get the homophily value of the AgentId2 for the AgentId1 + /// + /// + /// + /// + /// 0 if one of the agent is not yet present in the network + /// The homophily value if both exist. + /// + /// + /// An agent that acts via homophily attempts to find an _model partner that shares its characteristics. + /// When searching for suitable partners, the agent will stress agents who have similar socio-demographic parameters, + /// similar knowledge, and similar beliefs. + /// This process utilizes the derived parameters + /// + public float GetHomophily(AgentId agentId1, AgentId agentId2) + { + if (_agentIndex == null) + { + throw new NullReferenceException(nameof(_agentIndex)); + } + + if (!_model.On || !_agentIndex.ContainsKey(agentId1) || !_agentIndex.ContainsKey(agentId2)) + { + return 0; + } + + var index1 = _agentIndex[agentId1]; + var index2 = _agentIndex[agentId2]; + return Sphere[index1, index2].Homophily; + } + + public float GetSphereWeight() + { + if (!_model.On) + { + return 0; + } + + // for the moment it is a symmetrical matrix + var weight = 0F; + for (var i = 0; i < Sphere.GetLength(0); i++) + { + for (var j = i + 1; j < Sphere.GetLength(1); j++) + { + weight += Sphere[i, j].Homophily; + } + } + + return weight * 2; + } + + public float GetMaxSphereWeight() + { + if (!_model.On) + { + return 0; + } + + return (_model.SocialDemographicWeight + _model.RelativeBeliefWeight + _model.RelativeKnowledgeWeight + + _model.RelativeActivityWeight) * Sphere.GetLength(0) * (Sphere.GetLength(0) - 1); + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Repository/SymuYellowPages.cs b/Symu source code/SymuEngine/Repository/SymuYellowPages.cs index 9c39bc3b..400ec94c 100644 --- a/Symu source code/SymuEngine/Repository/SymuYellowPages.cs +++ b/Symu source code/SymuEngine/Repository/SymuYellowPages.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Repository/WhitePages.cs b/Symu source code/SymuEngine/Repository/WhitePages.cs index cbea950d..36a8f23e 100644 --- a/Symu source code/SymuEngine/Repository/WhitePages.cs +++ b/Symu source code/SymuEngine/Repository/WhitePages.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,8 +12,9 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Organization; using SymuEngine.Common; using SymuEngine.Repository.Networks; @@ -32,9 +33,9 @@ namespace SymuEngine.Repository /// FIPA Norm : Agent Management System (AMS) public class WhitePages { - public WhitePages(AgentTemplates agentTemplates) + public WhitePages(AgentTemplates agentTemplates, InteractionSphereModel interactionSphereModel) { - Network = new Network(agentTemplates); + Network = new Network(agentTemplates, interactionSphereModel); } /// @@ -59,11 +60,20 @@ public WhitePages(AgentTemplates agentTemplates) /// public void Clear() { + Network.State = AgentState.Starting; StoppedAgents.Clear(); Network.Clear(); Agents.Clear(); } + /// + /// CLear agents between two iterations + /// + public void SetStarted() + { + Network.State = AgentState.Started; + } + /// /// Stops the execution of the agent identified by name and removes it from the environment. Use the Remove method /// instead of Agent.Stop diff --git a/Symu source code/SymuEngine/Results/Blocker/BlockerResolution.cs b/Symu source code/SymuEngine/Results/Blocker/BlockerResolution.cs index 37de7684..a86cda01 100644 --- a/Symu source code/SymuEngine/Results/Blocker/BlockerResolution.cs +++ b/Symu source code/SymuEngine/Results/Blocker/BlockerResolution.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Blocker/BlockerResult.cs b/Symu source code/SymuEngine/Results/Blocker/BlockerResult.cs index 15b10db3..1f671bd3 100644 --- a/Symu source code/SymuEngine/Results/Blocker/BlockerResult.cs +++ b/Symu source code/SymuEngine/Results/Blocker/BlockerResult.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Blocker/BlockerResults.cs b/Symu source code/SymuEngine/Results/Blocker/BlockerResults.cs index 1f481631..6356f735 100644 --- a/Symu source code/SymuEngine/Results/Blocker/BlockerResults.cs +++ b/Symu source code/SymuEngine/Results/Blocker/BlockerResults.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,6 +9,7 @@ #region using directives +using System; using System.Collections.Concurrent; using System.Linq; @@ -81,6 +82,8 @@ public void BlockerDone(BlockerResolution resolution, ushort step) case BlockerResolution.Searching: _results[step].Search++; break; + default: + throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } _results[step].Done++; diff --git a/Symu source code/SymuEngine/Results/IterationResult.cs b/Symu source code/SymuEngine/Results/IterationResult.cs index 28fa148b..18cec948 100644 --- a/Symu source code/SymuEngine/Results/IterationResult.cs +++ b/Symu source code/SymuEngine/Results/IterationResult.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Organization/GroupDensityStruct.cs b/Symu source code/SymuEngine/Results/Organization/GroupDensityStruct.cs new file mode 100644 index 00000000..4c61908e --- /dev/null +++ b/Symu source code/SymuEngine/Results/Organization/GroupDensityStruct.cs @@ -0,0 +1,55 @@ +#region Licence + +// Description: Symu - SymuEngine +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System; +using SymuTools; + +#endregion + +namespace SymuEngine.Results.Organization +{ + /// + /// Group density is used to store information about group density per step : number of groups, max potential number of + /// groups, density + /// + /// Dynamics of organizations, page 75 + public readonly struct GroupDensityStruct + { + public GroupDensityStruct(float actualNumber, float maxNumber, ushort step) + { + ActualNumber = actualNumber; + MaxNumber = maxNumber; + Step = step; + } + + /// + /// Maximum number of groups + /// + public float MaxNumber { get; } + + /// + /// Real number of groups at the Step + /// + public float ActualNumber { get; } + + public ushort Step { get; } + + /// + /// Density of groups : percentage of actual groups vs the maximum number of groups possible + /// + public float Density => Math.Abs(MaxNumber) < Constants.Tolerance ? 0 : ActualNumber * 100F / MaxNumber; + + public override string ToString() + { + return "Density " + Density + " / step" + Step; + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Results/Organization/KnowledgeAndBeliefStruct.cs b/Symu source code/SymuEngine/Results/Organization/KnowledgeAndBeliefStruct.cs index f444a443..ba3740ee 100644 --- a/Symu source code/SymuEngine/Results/Organization/KnowledgeAndBeliefStruct.cs +++ b/Symu source code/SymuEngine/Results/Organization/KnowledgeAndBeliefStruct.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Organization/OrganizationFlexibility.cs b/Symu source code/SymuEngine/Results/Organization/OrganizationFlexibility.cs index 9108cc7a..028d68be 100644 --- a/Symu source code/SymuEngine/Results/Organization/OrganizationFlexibility.cs +++ b/Symu source code/SymuEngine/Results/Organization/OrganizationFlexibility.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,8 @@ using System.Collections.Generic; using SymuEngine.Environment; using SymuEngine.Repository; -using SymuEngine.Repository.Networks.Knowledges; +using SymuEngine.Repository.Networks.Sphere; +using SymuTools.Math; #endregion @@ -24,11 +25,6 @@ namespace SymuEngine.Results.Organization /// public class OrganizationFlexibility { - /// - /// Set the classKey of the agents that we want to get the flexibility performance - /// - private const byte ClassKey = SymuYellowPages.Actor; - /// /// Network of the simulation /// @@ -48,11 +44,24 @@ public OrganizationFlexibility(SymuEnvironment environment) /// In nonlinear stochastics systems with noise, a standard measure is the 90 % point (90% of its final theoretical /// value) /// - public List Triads { get; } = new List(); + public List Triads { get; } = new List(); + + /// + /// The number of connections between agents + /// + public List Links { get; } = new List(); + + /// + /// Sphere of interaction is the weight of the network in the simulation + /// + + public List Sphere { get; } = new List(); public void Clear() { Triads.Clear(); + Links.Clear(); + Sphere.Clear(); } /// @@ -60,17 +69,37 @@ public void Clear() /// Rapid formation and reformation of triads is one key aspect of flexibility /// For flexibility, Triads numbers are normalized with maximum potential triads /// - public void HandleTriads(ushort step) + public void HandleTriads(ushort agentsCount, ushort step) { - var numberOfTriads = KnowledgeMatrix.NumberOfTriads( - _environment.WhitePages.Network.NetworkKnowledges.Repository, - _environment.WhitePages.FilteredAgentIdsByClassKey(ClassKey), - _environment.WhitePages.Network.NetworkKnowledges); - var maxTriads = KnowledgeMatrix.MaxTriads(_environment.WhitePages.FilteredAgentsByClassCount(ClassKey)); - var triads = new TriadsStruct(numberOfTriads, maxTriads, step); + var numberOfTriads = + InteractionMatrix.NumberOfTriads(_environment.WhitePages.Network.InteractionSphere.Sphere); + var maxTriads = InteractionMatrix.MaxTriads(agentsCount); + var triads = new GroupDensityStruct(numberOfTriads, maxTriads, step); Triads.Add(triads); } + /// + /// Sphere of interaction is the length of the network in the simulation, the number of connections between agents + /// + public void HandleLinks(ushort agentsCount, ushort step) + { + var actualLinks = _environment.WhitePages.Network.NetworkLinks.Count; + var maxLinks = Combinatorics.Combinations(agentsCount, 2); + var sphere = new GroupDensityStruct(actualLinks, maxLinks, step); + Links.Add(sphere); + } + + /// + /// Sphere of interaction is the length of the network in the simulation, the number of connections between agents + /// + public void HandleSphere(ushort step) + { + var actualSphereWeight = _environment.WhitePages.Network.InteractionSphere.GetSphereWeight(); + var maxSphereWeight = _environment.WhitePages.Network.InteractionSphere.GetMaxSphereWeight(); + var sphere = new GroupDensityStruct(actualSphereWeight, maxSphereWeight, step); + Sphere.Add(sphere); + } + public void HandlePerformance(ushort step) { if (!_environment.Organization.Models.FollowGroupFlexibility) @@ -78,7 +107,10 @@ public void HandlePerformance(ushort step) return; } - HandleTriads(step); + var actorCount = _environment.WhitePages.FilteredAgentsByClassCount(SymuYellowPages.Actor); + HandleTriads(actorCount, step); + HandleLinks(actorCount, step); + HandleSphere(step); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngine/Results/Organization/OrganizationKnowledgeAndBelief.cs b/Symu source code/SymuEngine/Results/Organization/OrganizationKnowledgeAndBelief.cs index c6a08459..aca36269 100644 --- a/Symu source code/SymuEngine/Results/Organization/OrganizationKnowledgeAndBelief.cs +++ b/Symu source code/SymuEngine/Results/Organization/OrganizationKnowledgeAndBelief.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Organization/TriadsStruct.cs b/Symu source code/SymuEngine/Results/Organization/TriadsStruct.cs deleted file mode 100644 index ed1250bf..00000000 --- a/Symu source code/SymuEngine/Results/Organization/TriadsStruct.cs +++ /dev/null @@ -1,39 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngine -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -namespace SymuEngine.Results.Organization -{ - /// - /// One of the most fundamental types of groups is the triads - /// Rapid formation and reformation of triads is one key aspect of flexibility - /// - public readonly struct TriadsStruct - { - public TriadsStruct(uint numberOfTriads, uint maxTriads, ushort step) - { - NumberOfTriads = numberOfTriads; - MaxTriads = maxTriads; - Step = step; - } - - public uint MaxTriads { get; } - public uint NumberOfTriads { get; } - public ushort Step { get; } - - /// - /// Percentage of the theoretical value - /// - public float Performance => NumberOfTriads * 100F / MaxTriads; - - public override string ToString() - { - return "Performance " + Performance + " / step" + Step; - } - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngine/Results/PostProcessResult.cs b/Symu source code/SymuEngine/Results/PostProcessResult.cs index 18d77fb8..115fb29c 100644 --- a/Symu source code/SymuEngine/Results/PostProcessResult.cs +++ b/Symu source code/SymuEngine/Results/PostProcessResult.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/SimulationResults.cs b/Symu source code/SymuEngine/Results/SimulationResults.cs index 898f9d15..259b09cd 100644 --- a/Symu source code/SymuEngine/Results/SimulationResults.cs +++ b/Symu source code/SymuEngine/Results/SimulationResults.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Task/TaskResult.cs b/Symu source code/SymuEngine/Results/Task/TaskResult.cs index 441a4f88..1090b4da 100644 --- a/Symu source code/SymuEngine/Results/Task/TaskResult.cs +++ b/Symu source code/SymuEngine/Results/Task/TaskResult.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngine/Results/Task/TaskResults.cs b/Symu source code/SymuEngine/Results/Task/TaskResults.cs index 93279e1d..05f10298 100644 --- a/Symu source code/SymuEngine/Results/Task/TaskResults.cs +++ b/Symu source code/SymuEngine/Results/Task/TaskResults.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngine -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Concurrent; using System.Linq; using SymuEngine.Environment; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion diff --git a/Symu source code/SymuEngineTests/Classes/Agent/AgentTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/AgentTests.cs similarity index 88% rename from Symu source code/SymuEngineTests/Classes/Agent/AgentTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/AgentTests.cs index 45c93544..b8cf0015 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/AgentTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/AgentTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,16 +9,17 @@ #region using directives +using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.Templates.Communication; using SymuEngine.Classes.Organization; using SymuEngine.Common; using SymuEngine.Engine; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngine.Repository; using SymuEngine.Repository.Networks.Beliefs; using SymuEngine.Repository.Networks.Knowledges; @@ -26,7 +27,7 @@ #endregion -namespace SymuEngineTests.Classes.Agent +namespace SymuEngineTests.Classes.Agents { [TestClass] public class AgentTests @@ -77,8 +78,8 @@ public void AgentTest() Assert.AreEqual(1, _agent.Id.Key); Assert.IsNotNull(_agent.Environment); Assert.IsNotNull(_agent.Cognitive); - Assert.AreEqual(0, _environment.WhitePages.Network.NetworkInfluences.GetInfluenceability(_agent.Id)); - Assert.AreEqual(0, _environment.WhitePages.Network.NetworkInfluences.GetInfluentialness(_agent.Id)); + Assert.AreNotEqual(0, _environment.WhitePages.Network.NetworkInfluences.GetInfluenceability(_agent.Id)); + Assert.AreNotEqual(0, _environment.WhitePages.Network.NetworkInfluences.GetInfluentialness(_agent.Id)); Assert.AreEqual(AgentState.Started, _agent.State); } @@ -1109,5 +1110,147 @@ public void HandleStatusTest2() } #endregion + + #region Interactions + + /// + /// With empty list + /// + [TestMethod] + public void FilterAgentIdsToInteractTest() + { + var agentIds = new List(); + Assert.AreEqual(0, _agent.FilterAgentIdsToInteract(agentIds).Count()); + } + + /// + /// With filled list - limit false + /// + [TestMethod] + public void FilterAgentIdsToInteractTest1() + { + var agentIds = new List(); + for (ushort i = 2; i < 12; i++) + { + agentIds.Add(new AgentId(i, 1)); + } + + _agent.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = false; + Assert.AreEqual(10, _agent.FilterAgentIdsToInteract(agentIds).Count()); + } + + /// + /// With filled list - limit on - below limit(default 5) + /// + [TestMethod] + public void FilterAgentIdsToInteractTest2() + { + var agentIds = new List(); + for (ushort i = 2; i < 5; i++) + { + agentIds.Add(new AgentId(i, 1)); + } + + _agent.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + Assert.AreEqual(3, _agent.FilterAgentIdsToInteract(agentIds).Count()); + } + + /// + /// With filled list - limit on - above limit(default 5) + /// + [TestMethod] + public void FilterAgentIdsToInteractTest3() + { + var agentIds = new List(); + for (ushort i = 2; i < 12; i++) + { + agentIds.Add(new AgentId(i, 1)); + } + + _agent.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + Assert.AreEqual(5, _agent.FilterAgentIdsToInteract(agentIds).Count()); + } + + /// + /// IsPartOfInteractionSphere false + /// + [TestMethod] + public void AcceptNewInteractionTest() + { + var agent2 = new TestAgent(2, _environment); + Assert.IsTrue(_agent.AcceptNewInteraction(agent2.Id)); + } + + /// + /// IsPartOfInteractionSphere true true + /// ActiveLink + /// + [TestMethod] + public void AcceptNewInteractionTest1() + { + _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + var agent2 = new TestAgent(2, _environment); + _environment.WhitePages.Network.NetworkLinks.AddLink(_agent.Id, agent2.Id); + Assert.IsTrue(_agent.AcceptNewInteraction(agent2.Id)); + } + + /// + /// IsPartOfInteractionSphere true true + /// ActiveLink false + /// AllowNewInteractions false + /// + [TestMethod] + public void AcceptNewInteractionTest2() + { + _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + var agent2 = new TestAgent(2, _environment); + _agent.Cognitive.InteractionPatterns.AllowNewInteractions = false; + Assert.IsFalse(_agent.AcceptNewInteraction(agent2.Id)); + } + + /// + /// IsPartOfInteractionSphere true true + /// Limit interaction to 0 + /// + [TestMethod] + public void AcceptNewInteractionTest3() + { + _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + var agent2 = new TestAgent(2, _environment); + _agent.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _agent.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true; + _agent.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 0; + Assert.IsFalse(_agent.AcceptNewInteraction(agent2.Id)); + } + + /// + /// IsPartOfInteractionSphere true true + /// ThresholdForNewInteraction 0 + /// + [TestMethod] + public void AcceptNewInteractionTest4() + { + _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + var agent2 = new TestAgent(2, _environment); + _agent.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _agent.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0; + Assert.IsFalse(_agent.AcceptNewInteraction(agent2.Id)); + } + + /// + /// IsPartOfInteractionSphere true true + /// ThresholdForNewInteraction 1 + /// + [TestMethod] + public void AcceptNewInteractionTest5() + { + _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; + var agent2 = new TestAgent(2, _environment); + _agent.Cognitive.InteractionPatterns.AllowNewInteractions = true; + _agent.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1; + Assert.IsTrue(_agent.AcceptNewInteraction(agent2.Id)); + } + + #endregion } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/ForgettingModelTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/ForgettingModelTests.cs similarity index 95% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/ForgettingModelTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/ForgettingModelTests.cs index 6ffdaefc..4d50c00c 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/ForgettingModelTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/ForgettingModelTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,16 +10,17 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; using SymuEngine.Classes.Task.Knowledge; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Knowledges; #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class ForgettingModelTests @@ -36,15 +37,17 @@ public class ForgettingModelTests [TestInitialize] public void Initialize() { - var network = new Network(new AgentTemplates()); + var network = new Network(new AgentTemplates(), new InteractionSphereModel()); _networkKnowledges = network.NetworkKnowledges; _networkKnowledges.Add(_agentId, _expertise); _taskBits.SetMandatory(new byte[] {0}); _taskBits.SetRequired(new byte[] {0}); _forgetting.On = true; _forgetting.RateOfAgentsOn = 1; - _internalCharacteristics = new InternalCharacteristics(network, _agentId); - _internalCharacteristics.ForgettingSelectingMode = ForgettingSelectingMode.Random; + _internalCharacteristics = new InternalCharacteristics(network, _agentId) + { + ForgettingSelectingMode = ForgettingSelectingMode.Random + }; } public void InitializeModel(bool modelOn, byte randomLevel) diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InteractionPatternsTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InteractionPatternsTests.cs similarity index 79% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InteractionPatternsTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InteractionPatternsTests.cs index 2cb09274..d6135cca 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InteractionPatternsTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InteractionPatternsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,12 +10,12 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Common; #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class InteractionPatternsTests @@ -48,9 +48,9 @@ public void PassingNextIsolationTest() [TestMethod] public void NextInteractionStrategyTest() { - _interaction.InteractionsUsingHomophily = 1; - _interaction.InteractionsDeliberateSearch = 0; - _interaction.InteractionsWithCoWorkers = 0; + _interaction.InteractionsBasedOnHomophily = 1; + _interaction.InteractionsBasedOnKnowledge = 0; + _interaction.InteractionsBasedOnActivities = 0; Assert.AreEqual(InteractionStrategy.Homophily, _interaction.NextInteractionStrategy()); } } diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs similarity index 87% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs index 480a471f..f2df8963 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/InternalCharacteristicsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,16 +10,17 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; using SymuEngine.Common; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Beliefs; #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class InternalCharacteristicsTests @@ -31,7 +32,7 @@ public class InternalCharacteristicsTests [TestInitialize] public void Initialize() { - _network = new Network(new AgentTemplates()); + _network = new Network(new AgentTemplates(), new InteractionSphereModel()); _model = new InternalCharacteristics(_network, _agentId); } diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs similarity index 96% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs index 3d8c7571..1939b4df 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/KnowledgeAndBeliefsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,9 +11,10 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; using SymuEngine.Classes.Task.Knowledge; using SymuEngine.Common; using SymuEngine.Repository.Networks; @@ -22,7 +23,7 @@ #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class KnowledgeAndBeliefsTests @@ -37,7 +38,7 @@ public class KnowledgeAndBeliefsTests [TestInitialize] public void Initialize() { - _network = new Network(new AgentTemplates()); + _network = new Network(new AgentTemplates(), new InteractionSphereModel()); _network.NetworkKnowledges.Add(_agentId, _expertise); _knowledgeAndBeliefs = new KnowledgeAndBeliefs(_network, _agentId) { diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/MessageContentTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/MessageContentTests.cs similarity index 97% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/MessageContentTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/MessageContentTests.cs index 0a6557aa..8aac51d0 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/MessageContentTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/MessageContentTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,14 +10,14 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; -using SymuEngine.Classes.Agent.Models.Templates.Communication; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.Templates.Communication; using SymuEngine.Repository.Networks.Beliefs; using SymuEngine.Repository.Networks.Knowledges; #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class MessageContentTests diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs similarity index 96% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs index 0db9d379..c9b7673a 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/CognitiveArchitecture/TasksAndPerformanceTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,16 +10,17 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; using SymuEngine.Common; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Knowledges; #endregion -namespace SymuEngineTests.Classes.Agent.Models.CognitiveArchitecture +namespace SymuEngineTests.Classes.Agents.Models.CognitiveArchitecture { [TestClass] public class TasksAndPerformanceTests @@ -27,7 +28,7 @@ public class TasksAndPerformanceTests private readonly AgentId _agentId = new AgentId(1, 1); private readonly AgentExpertise _expertise = new AgentExpertise(); private readonly Knowledge _knowledge = new Knowledge(1, "1", 1); - private readonly Network _network = new Network(new AgentTemplates()); + private readonly Network _network = new Network(new AgentTemplates(), new InteractionSphereModel()); private TasksAndPerformance _tasksAndPerformance; [TestInitialize] diff --git a/Symu source code/SymuEngineTests/Classes/Agent/Models/ModelEntityTests.cs b/Symu source code/SymuEngineTests/Classes/Agents/Models/ModelEntityTests.cs similarity index 92% rename from Symu source code/SymuEngineTests/Classes/Agent/Models/ModelEntityTests.cs rename to Symu source code/SymuEngineTests/Classes/Agents/Models/ModelEntityTests.cs index 6e8e090d..0c59fef1 100644 --- a/Symu source code/SymuEngineTests/Classes/Agent/Models/ModelEntityTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Agents/Models/ModelEntityTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,11 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents.Models; #endregion -namespace SymuEngineTests.Classes.Agent.Models +namespace SymuEngineTests.Classes.Agents.Models { [TestClass] public class ModelEntityTests diff --git a/Symu source code/SymuEngineTests/Classes/Blockers/BlockerTests.cs b/Symu source code/SymuEngineTests/Classes/Blockers/BlockerTests.cs index 28c556d9..04d43e74 100644 --- a/Symu source code/SymuEngineTests/Classes/Blockers/BlockerTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Blockers/BlockerTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Classes/Blockers/BlockersTests.cs b/Symu source code/SymuEngineTests/Classes/Blockers/BlockersTests.cs index 3822b7ef..fec0012e 100644 --- a/Symu source code/SymuEngineTests/Classes/Blockers/BlockersTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Blockers/BlockersTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteBeliefTests.cs b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteBeliefTests.cs index f438ed23..1bd3a1b8 100644 --- a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteBeliefTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteBeliefTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using SymuEngine.Classes.Murphies; using SymuEngine.Common; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion diff --git a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteKnowledgeTests.cs b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteKnowledgeTests.cs index db323844..6791fa09 100644 --- a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteKnowledgeTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyIncompleteKnowledgeTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyUnAvailabilityTests.cs b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyUnAvailabilityTests.cs index cbb5ab5a..d9d8d88e 100644 --- a/Symu source code/SymuEngineTests/Classes/Murphy/MurphyUnAvailabilityTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Murphy/MurphyUnAvailabilityTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Classes/Task/Knowledge/TaskKnowledgeBitsTests.cs b/Symu source code/SymuEngineTests/Classes/Task/Knowledge/TaskKnowledgeBitsTests.cs index e36d295f..191427fc 100644 --- a/Symu source code/SymuEngineTests/Classes/Task/Knowledge/TaskKnowledgeBitsTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Task/Knowledge/TaskKnowledgeBitsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Classes/Task/Manager/TasksManagerTests.cs b/Symu source code/SymuEngineTests/Classes/Task/Manager/TasksManagerTests.cs index f8871646..423f921c 100644 --- a/Symu source code/SymuEngineTests/Classes/Task/Manager/TasksManagerTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Task/Manager/TasksManagerTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,7 +14,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using SymuEngine.Classes.Task; using SymuEngine.Classes.Task.Manager; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion diff --git a/Symu source code/SymuEngineTests/Classes/Task/MasTaskTests.cs b/Symu source code/SymuEngineTests/Classes/Task/MasTaskTests.cs index 84a63d36..84a333bf 100644 --- a/Symu source code/SymuEngineTests/Classes/Task/MasTaskTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Task/MasTaskTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Task; #endregion diff --git a/Symu source code/SymuEngineTests/Classes/Task/TasksLimitTests.cs b/Symu source code/SymuEngineTests/Classes/Task/TasksLimitTests.cs index 4c495f04..421c102d 100644 --- a/Symu source code/SymuEngineTests/Classes/Task/TasksLimitTests.cs +++ b/Symu source code/SymuEngineTests/Classes/Task/TasksLimitTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Environment/EnvironmentStateTests.cs b/Symu source code/SymuEngineTests/Environment/EnvironmentStateTests.cs index 4f47cffa..62176d89 100644 --- a/Symu source code/SymuEngineTests/Environment/EnvironmentStateTests.cs +++ b/Symu source code/SymuEngineTests/Environment/EnvironmentStateTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Environment; #endregion diff --git a/Symu source code/SymuEngineTests/Environment/SymuEnvironmentTests.cs b/Symu source code/SymuEngineTests/Environment/SymuEnvironmentTests.cs index f7ddb9de..862ae63c 100644 --- a/Symu source code/SymuEngineTests/Environment/SymuEnvironmentTests.cs +++ b/Symu source code/SymuEngineTests/Environment/SymuEnvironmentTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using SymuEngine.Classes.Organization; using SymuEngine.Engine; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; using SymuEngineTests.Helpers; #endregion diff --git a/Symu source code/SymuEngineTests/Environment/TimeStep/TimeStepTests.cs b/Symu source code/SymuEngineTests/Environment/TimeStep/TimeStepTests.cs index e397ad33..febae4e7 100644 --- a/Symu source code/SymuEngineTests/Environment/TimeStep/TimeStepTests.cs +++ b/Symu source code/SymuEngineTests/Environment/TimeStep/TimeStepTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Helpers/TestAgent.cs b/Symu source code/SymuEngineTests/Helpers/TestAgent.cs index 449df112..c90b5ade 100644 --- a/Symu source code/SymuEngineTests/Helpers/TestAgent.cs +++ b/Symu source code/SymuEngineTests/Helpers/TestAgent.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,7 +9,8 @@ #region using directives -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models.Templates; using SymuEngine.Environment; using SymuEngine.Repository; @@ -26,13 +27,13 @@ internal sealed class TestAgent : Agent public TestAgent(ushort key, SymuEnvironment environment) : base(new AgentId(key, ClassKey), environment) { - SetCognitive(null); + SetCognitive(new SimpleHumanTemplate()); } public TestAgent(ushort key, byte classKey, SymuEnvironment environment) : base(new AgentId(key, classKey), environment) { - SetCognitive(null); + SetCognitive(new SimpleHumanTemplate()); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Helpers/TestEnvironment.cs b/Symu source code/SymuEngineTests/Helpers/TestEnvironment.cs index e5642e81..bae2a41d 100644 --- a/Symu source code/SymuEngineTests/Helpers/TestEnvironment.cs +++ b/Symu source code/SymuEngineTests/Helpers/TestEnvironment.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -17,8 +17,5 @@ namespace SymuEngineTests.Helpers { internal class TestEnvironment : SymuEnvironment { - public virtual void OnBoardAgent(object agent) - { - } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Messaging/Delayed/DelayedMessagesTests.cs b/Symu source code/SymuEngineTests/Messaging/Delayed/DelayedMessagesTests.cs index 5ac364ba..56565891 100644 --- a/Symu source code/SymuEngineTests/Messaging/Delayed/DelayedMessagesTests.cs +++ b/Symu source code/SymuEngineTests/Messaging/Delayed/DelayedMessagesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using SymuEngine.Messaging.Delayed; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion @@ -26,11 +26,11 @@ public class DelayedMessagesTests [TestMethod] public void EnqueueSameStepsTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); Assert.AreEqual(0, _delayedMessages.Count); _delayedMessages.Enqueue(message, 0); Assert.AreEqual(1, _delayedMessages.Count); - message = new SymuEngine.Messaging.Message.Message(); + message = new SymuEngine.Messaging.Messages.Message(); _delayedMessages.Enqueue(message, 0); Assert.AreEqual(2, _delayedMessages.Count); } @@ -38,11 +38,11 @@ public void EnqueueSameStepsTest() [TestMethod] public void EnqueueDifferentStepsTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); Assert.AreEqual(0, _delayedMessages.Count); _delayedMessages.Enqueue(message, 0); Assert.AreEqual(1, _delayedMessages.Count); - message = new SymuEngine.Messaging.Message.Message(); + message = new SymuEngine.Messaging.Messages.Message(); _delayedMessages.Enqueue(message, 1); Assert.AreEqual(2, _delayedMessages.Count); } @@ -59,7 +59,7 @@ public void EnqueueNullMessageTest() [TestMethod] public void DequeueTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); _delayedMessages.Enqueue(message, 1); // Non passing test Assert.IsNull(_delayedMessages.Dequeue(0)); @@ -79,7 +79,7 @@ public void DequeueTest() [TestMethod] public void DequeueTest1() { - var message = new SymuEngine.Messaging.Message.Message + var message = new SymuEngine.Messaging.Messages.Message { Attachments = new MessageAttachments() }; @@ -93,7 +93,7 @@ public void DequeueTest1() [TestMethod] public void LastTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); _delayedMessages.Enqueue(message, 1); // Non passing test Assert.IsNull(_delayedMessages.Last(0)); diff --git a/Symu source code/SymuEngineTests/Messaging/Manager/MessageProcessorTests.cs b/Symu source code/SymuEngineTests/Messaging/Manager/MessageProcessorTests.cs index b540504d..ee35af40 100644 --- a/Symu source code/SymuEngineTests/Messaging/Manager/MessageProcessorTests.cs +++ b/Symu source code/SymuEngineTests/Messaging/Manager/MessageProcessorTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.VisualStudio.TestTools.UnitTesting; using SymuEngine.Messaging.Manager; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion @@ -43,7 +43,7 @@ public void Initialize() [TestMethod] public void ExceptionTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); _mailbox.Post(message); } @@ -65,7 +65,7 @@ private static void Act() public void PostDelayedTest() { Assert.AreEqual(0, _mailbox.DelayedMessages.Count); - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); _mailbox.PostAsADelayed(message, 0); Assert.AreEqual(1, _mailbox.DelayedMessages.Count); } @@ -73,7 +73,7 @@ public void PostDelayedTest() [TestMethod] public void NextDelayedMessagesTest() { - var message = new SymuEngine.Messaging.Message.Message(); + var message = new SymuEngine.Messaging.Messages.Message(); _mailbox.PostAsADelayed(message, 0); Assert.AreEqual(message, _mailbox.NextDelayedMessages(0)); Assert.AreEqual(0, _mailbox.DelayedMessages.Count); @@ -99,7 +99,7 @@ public void IncrementMessagesPerPeriodTest() [TestMethod] public void PostTest() { - var message = new SymuEngine.Messaging.Message.Message + var message = new SymuEngine.Messaging.Messages.Message { Medium = CommunicationMediums.Email }; diff --git a/Symu source code/SymuEngineTests/Messaging/Message/CommunicationMediumsModelTests.cs b/Symu source code/SymuEngineTests/Messaging/Message/CommunicationMediumsModelTests.cs index 15f6301f..a73634f9 100644 --- a/Symu source code/SymuEngineTests/Messaging/Message/CommunicationMediumsModelTests.cs +++ b/Symu source code/SymuEngineTests/Messaging/Message/CommunicationMediumsModelTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion diff --git a/Symu source code/SymuEngineTests/Messaging/Message/MessageTypesToolsTests.cs b/Symu source code/SymuEngineTests/Messaging/Message/MessageTypesToolsTests.cs index 52c4195d..32dac8e8 100644 --- a/Symu source code/SymuEngineTests/Messaging/Message/MessageTypesToolsTests.cs +++ b/Symu source code/SymuEngineTests/Messaging/Message/MessageTypesToolsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Messaging.Message; +using SymuEngine.Messaging.Messages; #endregion diff --git a/Symu source code/SymuEngineTests/Messaging/Reply/AgentWaitingRepliesTests.cs b/Symu source code/SymuEngineTests/Messaging/Reply/AgentWaitingRepliesTests.cs index 9419f237..e3c719af 100644 --- a/Symu source code/SymuEngineTests/Messaging/Reply/AgentWaitingRepliesTests.cs +++ b/Symu source code/SymuEngineTests/Messaging/Reply/AgentWaitingRepliesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Activities/ActivityTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Activities/ActivityTests.cs index 26d06408..41de063b 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Activities/ActivityTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Activities/ActivityTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Activities/NetworkActivitiesTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Activities/NetworkActivitiesTests.cs index 6ac73359..0b621bfa 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Activities/NetworkActivitiesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Activities/NetworkActivitiesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,12 +12,13 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Activities; using SymuEngine.Repository.Networks.Knowledges; #endregion + namespace SymuEngineTests.Repository.Networks.Activities { [TestClass] @@ -68,7 +69,7 @@ public void RemoveAgentTest1() _network.AddGroup(_kanbanId); _network.AddActivities(_agentId, _kanbanId, _activities); _network.RemoveAgent(_agentId); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); } [TestMethod] @@ -79,8 +80,8 @@ public void RemoveMemberTest() _network.AddActivities(_agentId, _kanbanId, _activities); _network.AddActivities(_agentId, _kanbanId2, _activities); _network.RemoveMember(_agentId, _kanbanId); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId)); - Assert.IsTrue(_network.HasActivitiesOn(_agentId, _kanbanId2)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); + Assert.IsTrue(_network.AgentHasActivitiesOn(_agentId, _kanbanId2)); } [TestMethod] @@ -91,8 +92,8 @@ public void RemoveMemberTest1() _network.AddActivities(_agentId, _kanbanId, _activities); _network.AddActivities(_agentId, _kanbanId2, _activities); _network.RemoveMember(_agentId); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId)); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId2)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId2)); } [TestMethod] @@ -148,27 +149,27 @@ public void AddKanbanTest() public void AddAndGetActivitiesTest() { _network.AddGroup(_kanbanId); - Assert.AreEqual(0, _network.GetActivities(_agentId, _kanbanId).Count()); + Assert.AreEqual(0, _network.GetAgentActivities(_agentId, _kanbanId).Count()); _network.AddActivities(_agentId, _kanbanId, _activities); - Assert.AreEqual(_activities.Count, _network.GetActivities(_agentId, _kanbanId).Count()); + Assert.AreEqual(_activities.Count, _network.GetAgentActivities(_agentId, _kanbanId).Count()); } [TestMethod] public void IsWorkingOnActivityTest() { _network.AddGroup(_kanbanId); - Assert.IsFalse(_network.HasAnActivityOn(_agentId, _kanbanId, StrActivity1)); + Assert.IsFalse(_network.AgentHasAnActivityOn(_agentId, _kanbanId, StrActivity1)); _network.AddActivities(_agentId, _kanbanId, _activities); - Assert.IsTrue(_network.HasAnActivityOn(_agentId, _kanbanId, StrActivity1)); - Assert.IsTrue(_network.HasAnActivityOn(_agentId, _kanbanId, StrActivity2)); + Assert.IsTrue(_network.AgentHasAnActivityOn(_agentId, _kanbanId, StrActivity1)); + Assert.IsTrue(_network.AgentHasAnActivityOn(_agentId, _kanbanId, StrActivity2)); } [TestMethod] public void GetActivitiesTest() { - Assert.AreEqual(0, _network.GetActivities(_kanbanId).Count()); + Assert.AreEqual(0, _network.GetGroupActivities(_kanbanId).Count()); _network.AddActivity(_activity1, _kanbanId); - Assert.AreEqual(1, _network.GetActivities(_kanbanId).Count()); + Assert.AreEqual(1, _network.GetGroupActivities(_kanbanId).Count()); } [TestMethod] @@ -197,11 +198,11 @@ public void GetActivitiesKnowledgeIdsTest() [TestMethod] public void AddActivityTest() { - Assert.IsFalse(_network.HasActivities(_kanbanId)); + Assert.IsFalse(_network.GroupHasActivities(_kanbanId)); _network.AddActivity(_activity1, _kanbanId); - Assert.IsTrue(_network.HasActivities(_kanbanId)); + Assert.IsTrue(_network.GroupHasActivities(_kanbanId)); _network.AddActivity(_activity1, _kanbanId); //Duplicate - Assert.AreEqual(1, _network.GetActivities(_kanbanId).Count()); + Assert.AreEqual(1, _network.GetGroupActivities(_kanbanId).Count()); } /// @@ -211,9 +212,9 @@ public void AddActivityTest() public void AddActivityTest1() { _network.AddGroup(_kanbanId); - Assert.IsFalse(_network.HasAnActivityOn(_agentId, _kanbanId, StrActivity1)); + Assert.IsFalse(_network.AgentHasAnActivityOn(_agentId, _kanbanId, StrActivity1)); _network.AddActivity(_agentId, StrActivity1, _kanbanId); - Assert.IsTrue(_network.HasAnActivityOn(_agentId, _kanbanId, StrActivity1)); + Assert.IsTrue(_network.AgentHasAnActivityOn(_agentId, _kanbanId, StrActivity1)); } /// @@ -223,9 +224,9 @@ public void AddActivityTest1() public void AddActivitiesTest() { _network.AddGroup(_kanbanId); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); _network.AddActivities(_agentId, _kanbanId, _activities); - Assert.IsTrue(_network.HasActivitiesOn(_agentId, _kanbanId)); + Assert.IsTrue(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); } /// @@ -236,15 +237,15 @@ public void AddActivitiesTest1() { _network.AddGroup(_kanbanId); _network.AddActivities(_agentId, _kanbanId, new List {_knowledge1.Id}); - Assert.AreEqual(0, _network.GetActivities(_agentId, _kanbanId).Count()); + Assert.AreEqual(0, _network.GetAgentActivities(_agentId, _kanbanId).Count()); // Has the knowledge _network.AddActivity(_activity1, _kanbanId); _network.AddActivities(_agentId, _kanbanId, new List {_knowledge1.Id}); - Assert.AreEqual(1, _network.GetActivities(_agentId, _kanbanId).Count()); + Assert.AreEqual(1, _network.GetAgentActivities(_agentId, _kanbanId).Count()); // Hasn't the knowledge _network.AddActivity(_activity2, _kanbanId); _network.AddActivities(_agentId, _kanbanId, new List {_knowledge1.Id}); - Assert.AreEqual(1, _network.GetActivities(_agentId, _kanbanId).Count()); + Assert.AreEqual(1, _network.GetAgentActivities(_agentId, _kanbanId).Count()); } [TestMethod] @@ -252,16 +253,16 @@ public void TransferToTest() { _network.AddActivities(_agentId, _kanbanId, _activities); _network.TransferTo(_agentId, _kanbanId, _kanbanId2); - Assert.IsTrue(_network.HasActivitiesOn(_agentId, _kanbanId2)); - Assert.IsFalse(_network.HasActivitiesOn(_agentId, _kanbanId)); + Assert.IsTrue(_network.AgentHasActivitiesOn(_agentId, _kanbanId2)); + Assert.IsFalse(_network.AgentHasActivitiesOn(_agentId, _kanbanId)); } [TestMethod] public void AddActivitiesTest2() { - Assert.IsFalse(_network.HasActivities(_kanbanId)); + Assert.IsFalse(_network.GroupHasActivities(_kanbanId)); _network.AddActivities(new List {_activity1}, _kanbanId); - Assert.IsTrue(_network.HasActivities(_kanbanId)); + Assert.IsTrue(_network.GroupHasActivities(_kanbanId)); } [TestMethod] @@ -285,5 +286,26 @@ public void FilterAgentIdsWithActivityTest() _network.AddActivity(_agentId, _activity1.Name, _kanbanId); Assert.AreEqual(1, _network.FilterAgentIdsWithActivity(agentIds, _kanbanId, _activity1.Name).Count()); } + + /// + /// With no activities + /// + [TestMethod] + public void GetAgentActivitiesTest() + { + Assert.AreEqual(0, _network.GetAgentActivities(_agentId).Count()); + } + + /// + /// With activities + /// + [TestMethod] + public void GetAgentActivitiesTest1() + { + _network.AddActivity(_agentId, _activity1.Name, _kanbanId); + Assert.AreEqual(1, _network.GetAgentActivities(_agentId).Count()); + _network.AddActivity(_agentId, _activity2.Name, _kanbanId); + Assert.AreEqual(2, _network.GetAgentActivities(_agentId).Count()); + } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefTests.cs index 16bf67df..53277ced 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefsTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefsTests.cs index 2023bb24..3c2cfa53 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefsTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/AgentBeliefsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -15,6 +15,7 @@ #endregion + namespace SymuEngineTests.Repository.Networks.Beliefs { [TestClass] diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefCollectionTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefCollectionTests.cs index 92eb8573..2cf52a05 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefCollectionTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefCollectionTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefTests.cs index ad3bb263..8dd2fb1f 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/BeliefTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/NetworkBeliefsTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/NetworkBeliefsTests.cs index 8358938f..275c8a4a 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/NetworkBeliefsTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Beliefs/NetworkBeliefsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,8 +11,9 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Common; using SymuEngine.Repository.Networks.Beliefs; using SymuEngine.Repository.Networks.Knowledges; @@ -215,5 +216,14 @@ public void LearnNewBeliefTest() _network.LearnNewBelief(_agentId, _belief.Id); Assert.IsNotNull(_network.GetAgentBelief(_agentId, _belief.Id)); } + + [TestMethod] + public void GetBeliefIdsTest() + { + _network.AddAgentId(_agentId); + Assert.AreEqual(0, _network.GetBeliefIds(_agentId).Count()); + _network.AddBelief(_agentId, 1); + Assert.AreEqual(1, _network.GetBeliefIds(_agentId).Count()); + } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseCollectionTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseCollectionTests.cs index 1292d9c8..8c160f3f 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseCollectionTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseCollectionTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Repository.Networks.Databases; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseTests.cs index d953d84c..10ec09b3 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Databases/DatabaseTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Repository.Networks.Databases; using SymuEngine.Repository.Networks.Knowledges; diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Databases/NetworkDatabasesTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Databases/NetworkDatabasesTests.cs index add11388..d3b129f3 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Databases/NetworkDatabasesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Databases/NetworkDatabasesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,8 +10,8 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models.CognitiveArchitecture; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Repository.Networks.Databases; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Enculturation/NetworkEnculturationTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Enculturation/NetworkEnculturationTests.cs index 31216d7f..0c0d5c08 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Enculturation/NetworkEnculturationTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Enculturation/NetworkEnculturationTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Enculturation; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Group/NetworkGroupsTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Group/NetworkGroupsTests.cs index 54043a3d..931855bc 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Group/NetworkGroupsTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Group/NetworkGroupsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Group; #endregion @@ -24,8 +24,14 @@ public class NetworkGroupsTests { private readonly NetworkGroups _group = new NetworkGroups(); private readonly AgentId _teamId = new AgentId(1, 1); - private readonly AgentId _teammateId = new AgentId(2, 2); + private readonly AgentId _teamId2 = new AgentId(2, 1); + private readonly AgentId _teammateId = new AgentId(3, 2); + private readonly AgentId _teammateId2 = new AgentId(4, 2); + private readonly AgentId _teammateId3 = new AgentId(5, 2); + /// + /// With agent 1 one team + /// [TestMethod] public void RemoveAgentTest() { @@ -35,13 +41,19 @@ public void RemoveAgentTest() _group.AddMember(_teammateId, 100, _teamId); _group.RemoveAgent(_teammateId); Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, _teamId)); - // With agent 1 two teams + } + + /// + /// With agent 1 two teams + /// + [TestMethod] + public void RemoveAgentTest1() + { _group.AddMember(_teammateId, 100, _teamId); - var teamId2 = new AgentId(3, 1); - _group.AddMember(_teammateId, 100, teamId2); + _group.AddMember(_teammateId, 100, _teamId2); _group.RemoveAgent(_teammateId); Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, _teamId)); - Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, teamId2)); + Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, _teamId2)); } [TestMethod] @@ -80,11 +92,10 @@ public void RemoveTeammateTest() Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, _teamId)); // With agent 1 two teams _group.AddMember(_teammateId, 100, _teamId); - var teamId2 = new AgentId(3, 1); - _group.AddMember(_teammateId, 100, teamId2); + _group.AddMember(_teammateId, 100, _teamId2); _group.RemoveMember(_teammateId, _teamId); Assert.IsFalse(_group.IsMemberOfGroup(_teammateId, _teamId)); - Assert.IsTrue(_group.IsMemberOfGroup(_teammateId, teamId2)); + Assert.IsTrue(_group.IsMemberOfGroup(_teammateId, _teamId2)); } [TestMethod] @@ -127,9 +138,8 @@ public void IsTeammateTest1() Assert.AreEqual(0, _group.GetGroups(_teammateId, _teamId.ClassKey).Count()); _group.AddMember(_teammateId, 100, _teamId); Assert.AreEqual(1, _group.GetGroups(_teammateId, _teamId.ClassKey).Count()); - var teamId2 = new AgentId(1, 3); - _group.AddMember(_teammateId, 100, teamId2); - Assert.AreEqual(1, _group.GetGroups(_teammateId, _teamId.ClassKey).Count()); + _group.AddMember(_teammateId, 100, _teamId2); + Assert.AreEqual(2, _group.GetGroups(_teammateId, _teamId.ClassKey).Count()); } [TestMethod] @@ -143,11 +153,28 @@ public void RemoveGroupTest() [TestMethod] public void GetGroupsTest() { - Assert.IsNull(_group.GetGroups()); - _group.AddGroup(_teamId); Assert.IsNotNull(_group.GetGroups()); + Assert.AreEqual(0, _group.GetGroups().Count()); + _group.AddGroup(_teamId); + Assert.AreEqual(1, _group.GetGroups().Count()); } + [TestMethod] + public void GetCoMemberIds() + { + Assert.AreEqual(0, _group.GetCoMemberIds(_teammateId, _teamId.ClassKey).Count()); + _group.AddMember(_teammateId, 100, _teamId); + Assert.AreEqual(0, _group.GetCoMemberIds(_teammateId, _teamId.ClassKey).Count()); + _group.AddMember(_teammateId2, 100, _teamId); + Assert.AreEqual(1, _group.GetCoMemberIds(_teammateId, _teamId.ClassKey).Count()); + _group.AddMember(_teammateId3, 100, _teamId2); + Assert.AreEqual(1, _group.GetCoMemberIds(_teammateId, _teamId.ClassKey).Count()); + _group.AddMember(_teammateId, 100, _teamId2); + Assert.AreEqual(2, _group.GetCoMemberIds(_teammateId, _teamId.ClassKey).Count()); + } + + #region Allocation + [TestMethod] public void GetGroupAllocationsTest() { @@ -221,9 +248,8 @@ public void NullUpdateGroupAllocationsTest() public void CopyToTest() { _group.AddMember(_teammateId, 100, _teamId); - var teamId2 = new AgentId(3, 1); - _group.CopyTo(_teamId, teamId2); - Assert.AreEqual(100, _group.GetAllocation(_teammateId, teamId2)); + _group.CopyTo(_teamId, _teamId2); + Assert.AreEqual(100, _group.GetAllocation(_teammateId, _teamId2)); } [TestMethod] @@ -232,9 +258,10 @@ public void GetMemberAllocationsTest() Assert.AreEqual(0, _group.GetMemberAllocations(_teamId)); _group.AddMember(_teammateId, 100, _teamId); Assert.AreEqual(100, _group.GetMemberAllocations(_teamId)); - var teammateId2 = new AgentId(3, 2); - _group.AddMember(teammateId2, 50, _teamId); + _group.AddMember(_teammateId2, 50, _teamId); Assert.AreEqual(150, _group.GetMemberAllocations(_teamId)); } + + #endregion } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Influences/NetworkInfluencesTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Influences/NetworkInfluencesTests.cs index adaa6f1e..ac019748 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Influences/NetworkInfluencesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Influences/NetworkInfluencesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Influences; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentExpertiseTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentExpertiseTests.cs index 3f7938a2..8d0e5749 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentExpertiseTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentExpertiseTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentKnowledgeTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentKnowledgeTests.cs index 4ae18555..ec3503ed 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentKnowledgeTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/AgentKnowledgeTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -170,12 +170,21 @@ public void GetKnowledgeBitsTest() Assert.AreEqual(_knowledge01Bits[0], _agentKnowledge01.GetKnowledgeBit(0)); } + /// + /// Non passing test knowledgeBits == null + /// [TestMethod] public void GetKnowledgeBitTest() { - // Non passing test knowledgeBits == null - Assert.AreEqual(-1, _agentKnowledge.GetKnowledgeBit(0)); - // Passing tests + Assert.AreEqual(0, _agentKnowledge.GetKnowledgeBit(0)); + } + + /// + /// Passing test + /// + [TestMethod] + public void GetKnowledgeBitTest1() + { for (byte i = 0; i < 2; i++) { Assert.AreEqual(_knowledge0Bits[i], _agentKnowledge0.GetKnowledgeBit(i)); diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/BitsTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/BitsTests.cs index 578296cb..433d18c2 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/BitsTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/BitsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -114,5 +114,16 @@ public void UpdateBitTest4() Assert.AreEqual(0, _bits0.UpdateBit(0, -1)); Assert.AreEqual(0, _bits0.GetBit(0)); } + + + [TestMethod] + public void GetRelativeKnowledgeBitsTest() + { + _bits0 = new Bits(_floats0, 0); + Assert.AreEqual(0, Bits.GetRelativeBits(_bits0, _bits0)); + _bits1 = new Bits(_floats1, 0); + Assert.AreEqual(1, Bits.GetRelativeBits(_bits1, _bits1)); + Assert.AreEqual(0, Bits.GetRelativeBits(_bits0, _bits1)); + } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeBitsTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeBitsTests.cs index 0fb6df42..6f7f3f59 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeBitsTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeBitsTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,6 +14,7 @@ #endregion + namespace SymuEngineTests.Repository.Networks.Knowledges { [TestClass] diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeCollectionTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeCollectionTests.cs index 70ba4d64..be6c5566 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeCollectionTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeCollectionTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeMatrixTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeMatrixTests.cs deleted file mode 100644 index c0e8b5ef..00000000 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeMatrixTests.cs +++ /dev/null @@ -1,253 +0,0 @@ -#region Licence - -// Description: Symu - SymuEngineTests -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -#region using directives - -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Repository.Networks.Knowledges; - -#endregion - -namespace SymuEngineTests.Repository.Networks.Knowledges -{ - [TestClass] - public class KnowledgeMatrixTests - { - private readonly List _actors = new List(); - private readonly List _actorStyles = new List(); - private readonly AgentId _agentId1 = new AgentId(1, 1); - private readonly AgentId _agentId2 = new AgentId(2, 1); - private readonly AgentId _agentId3 = new AgentId(3, 1); - - private readonly Knowledge _info1 = - new Knowledge(1, "1", 1); - - private readonly Knowledge _info2 = - new Knowledge(2, "2", 1); - - private readonly Knowledge _info3 = - new Knowledge(3, "3", 1); - - private readonly KnowledgeCollection _knowledges = new KnowledgeCollection(); - private readonly NetworkKnowledges _network = new NetworkKnowledges(); - - private void Interaction1X1() - { - _actors.Add(_agentId1); - _knowledges.Add(_info1); - _network.Add(_agentId1, _info1, KnowledgeLevel.Expert, 0, -1); - } - - private void NoInteraction2X2() - { - Interaction1X1(); - _actors.Add(_agentId2); - _knowledges.Add(_info2); - _network.Add(_agentId2, _info2, KnowledgeLevel.Expert, 0, -1); - } - - private void NoInteraction3X3() - { - NoInteraction2X2(); - _actors.Add(_agentId3); - _knowledges.Add(_info3); - _network.Add(_agentId3, _info3, KnowledgeLevel.Expert, 0, -1); - } - - [TestMethod] - public void MaxTriadsTest() - { - Assert.AreEqual((uint) 0, KnowledgeMatrix.MaxTriads(1)); - Assert.AreEqual((uint) 0, KnowledgeMatrix.MaxTriads(2)); - Assert.AreEqual((uint) 1, KnowledgeMatrix.MaxTriads(3)); - Assert.AreEqual((uint) 4, KnowledgeMatrix.MaxTriads(4)); - } - - #region Knowledge matrix - - [TestMethod] - public void GetMatrixKnowledge1X1Test() - { - Interaction1X1(); - - var matrix = KnowledgeMatrix.GetMatrixKnowledge(_knowledges, _actors, _network); - Assert.AreEqual(1, matrix[0, 0]); - } - - [TestMethod] - public void GetMatrixKnowledge2X2Test() - { - NoInteraction2X2(); - - var matrix = KnowledgeMatrix.GetMatrixKnowledge(_knowledges, _actors, _network); - Assert.AreEqual(1, matrix[0, 0]); - Assert.AreEqual(1, matrix[1, 1]); - Assert.AreEqual(0, matrix[1, 0]); - Assert.AreEqual(0, matrix[0, 1]); - } - - #endregion - - #region PassiveInteractionMatrix - - [TestMethod] - public void PassiveInteractionMatrix1X1Test() - { - Interaction1X1(); - - var matrix = KnowledgeMatrix.GetPassiveInteractionMatrix(_knowledges, _actors, _network); - Assert.AreEqual(1, matrix[0, 0]); - } - - [TestMethod] - public void PassiveInteractionMatrix2X2Test() - { - NoInteraction2X2(); - - var matrix = KnowledgeMatrix.GetPassiveInteractionMatrix(_knowledges, _actors, _network); - Assert.AreEqual(1, matrix[0, 0]); - Assert.AreEqual(1, matrix[1, 1]); - Assert.AreEqual(0, matrix[1, 0]); - Assert.AreEqual(0, matrix[0, 1]); - } - - #endregion - - #region ActiveInteractionMatrix - - [TestMethod] - public void ActiveInteractionMatrix1X1Test() - { - Interaction1X1(); - _actorStyles.Add(true); - - var matrix = KnowledgeMatrix.GetActiveInteractionMatrix(_knowledges, _actors, _actorStyles, _network); - Assert.AreEqual(0, matrix[0, 0]); - } - - /// - /// Given active actors - /// Active interaction matrix 2x2 - /// - [TestMethod] - public void GivenActiveActorsActiveInteractionMatrix2X2Test() - { - NoInteraction2X2(); - _actorStyles.Add(true); - _actorStyles.Add(true); - - var matrix = KnowledgeMatrix.GetActiveInteractionMatrix(_knowledges, _actors, _actorStyles, _network); - Assert.AreEqual(0, matrix[0, 0]); - Assert.AreEqual(0, matrix[1, 1]); - Assert.AreEqual(1, matrix[1, 0]); - Assert.AreEqual(1, matrix[0, 1]); - } - - /// - /// Given passive Actors - /// Active Interaction Matrix 2x2 - /// - [TestMethod] - public void GivenPassiveActorsActiveInteractionMatrix2X2Test() - { - NoInteraction2X2(); - _actorStyles.Add(false); - _actorStyles.Add(false); - - var matrix = KnowledgeMatrix.GetActiveInteractionMatrix(_knowledges, _actors, _actorStyles, _network); - Assert.AreEqual(0, matrix[0, 0]); - Assert.AreEqual(0, matrix[1, 1]); - Assert.AreEqual(0, matrix[1, 0]); - Assert.AreEqual(0, matrix[0, 1]); - } - - #endregion - - #region Average interaction - - [TestMethod] - public void AverageInteraction1X1Test() - { - Interaction1X1(); - - Assert.AreEqual(0, KnowledgeMatrix.GetAverageInteractionMatrix(_knowledges, _actors, _network)); - } - - [TestMethod] - public void Average0Interaction2X2Test() - { - NoInteraction2X2(); - - Assert.AreEqual(0, KnowledgeMatrix.GetAverageInteractionMatrix(_knowledges, _actors, _network)); - } - - [TestMethod] - public void Average1Interaction2X2Test() - { - NoInteraction2X2(); - _network.Add(_agentId1, _info2, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId2, _info1, KnowledgeLevel.Expert, 0, -1); - - Assert.AreEqual(0.5F, KnowledgeMatrix.GetAverageInteractionMatrix(_knowledges, _actors, _network)); - } - - [TestMethod] - public void Average0Interaction3X3Test() - { - NoInteraction3X3(); - - Assert.AreEqual(0, KnowledgeMatrix.GetAverageInteractionMatrix(_knowledges, _actors, _network)); - } - - #endregion - - #region triad - - [TestMethod] - public void NumberOfTriads1X1Test() - { - Interaction1X1(); - - Assert.AreEqual((uint) 0, KnowledgeMatrix.NumberOfTriads(_knowledges, _actors, _network)); - } - - [TestMethod] - public void NoInteractionNumberOfTriads2X2Test() - { - NoInteraction2X2(); - - Assert.AreEqual((uint) 0, KnowledgeMatrix.NumberOfTriads(_knowledges, _actors, _network)); - } - - [TestMethod] - public void NoInteractionNumberOfTriads3X3Test() - { - NoInteraction3X3(); - - Assert.AreEqual((uint) 1, KnowledgeMatrix.NumberOfTriads(_knowledges, _actors, _network)); - } - - [TestMethod] - public void InteractionNumberOfTriads3X3Test() - { - NoInteraction3X3(); - _network.Add(_agentId1, _info2, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId1, _info3, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId2, _info1, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId2, _info3, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId3, _info1, KnowledgeLevel.Expert, 0, -1); - _network.Add(_agentId3, _info2, KnowledgeLevel.Expert, 0, -1); - Assert.AreEqual((uint) 1, KnowledgeMatrix.NumberOfTriads(_knowledges, _actors, _network)); - } - - #endregion - } -} \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeTests.cs index 0d7ad28c..fe1ab215 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/KnowledgeTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -14,7 +14,7 @@ using SymuEngine.Classes.Task; using SymuEngine.Common; using SymuEngine.Repository.Networks.Knowledges; -using static SymuTools.Algorithm.Constants; +using static SymuTools.Constants; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/NetworkKnowledgesTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/NetworkKnowledgesTests.cs index a511005e..9a628fe2 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/NetworkKnowledgesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Knowledges/NetworkKnowledgesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Knowledges; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinkTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinkTests.cs index b304c53e..dc8d6f09 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinkTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinkTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Link; #endregion @@ -55,7 +55,7 @@ public void EqualsTest() var link3 = new NetworkLink(_agentId2, _agentId1); var link4 = new NetworkLink(_agentId1, _agentId1); Assert.IsTrue(link.Equals(link2)); - Assert.IsFalse(link.Equals(link3)); + Assert.IsTrue(link.Equals(link3)); Assert.IsFalse(link.Equals(link4)); } @@ -81,19 +81,11 @@ public void HasActiveLinksTest() { var link = new NetworkLink(_agentId1, _agentId2); Assert.IsTrue(link.HasActiveLinks(_agentId1)); - Assert.IsFalse(link.HasActiveLinks(_agentId2)); + // links are bidirectional + Assert.IsTrue(link.HasActiveLinks(_agentId2)); link.Deactivate(); Assert.IsFalse(link.HasActiveLinks(_agentId1)); - } - - [TestMethod] - public void HasActiveLinksByClassKeyTest() - { - var link = new NetworkLink(_agentId1, _agentId2); - Assert.IsTrue(link.HasActiveLinks(_agentId1, _agentId2.ClassKey)); - Assert.IsFalse(link.HasActiveLinks(_agentId1, _agentId1.ClassKey)); - link.Deactivate(); - Assert.IsFalse(link.HasActiveLinks(_agentId1, _agentId2.ClassKey)); + Assert.IsFalse(link.HasActiveLinks(_agentId2)); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinksTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinksTests.cs index 1cd68850..ce543857 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinksTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Link/NetworkLinksTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,29 +11,29 @@ using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Link; #endregion + namespace SymuEngineTests.Repository.Networks.Link { [TestClass] public class NetworkLinksTests { + private readonly AgentId _agentId1 = new AgentId(2, 2); + private readonly AgentId _agentId2 = new AgentId(3, 2); + private readonly AgentId _agentId3 = new AgentId(4, 2); private readonly NetworkLinks _links = new NetworkLinks(); - private readonly AgentId _teamId = new AgentId(1, 1); - private readonly AgentId _teammateId1 = new AgentId(2, 2); - private readonly AgentId _teammateId2 = new AgentId(3, 2); - private readonly AgentId _teammateId3 = new AgentId(4, 2); [TestMethod] public void RemoveAgentTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - _links.AddMembers(_teammateId3, _teammateId1, _teamId); - _links.RemoveAgent(_teammateId1); + _links.AddLink(_agentId1, _agentId2); + _links.AddLink(_agentId3, _agentId1); + _links.RemoveAgent(_agentId1); Assert.IsFalse(_links.Any()); } @@ -41,46 +41,15 @@ public void RemoveAgentTest() public void AnyTest() { Assert.IsFalse(_links.Any()); - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - Assert.IsTrue(_links.Any()); - } - - [TestMethod] - public void AddSubordinateTest() - { - _links.AddSubordinate(_teammateId1, _teammateId2, _teamId); - var link = _links[0] as CommunicationLink; - Assert.IsNotNull(link); - Assert.AreEqual(CommunicationType.ReportTo, link.Communication); - } - - [TestMethod] - public void RemoveSubordinateTest() - { - _links.AddSubordinate(_teammateId1, _teammateId2, _teamId); - _links.DeactivateSubordinate(_teammateId1, _teammateId2, _teamId); + _links.AddLink(_agentId1, _agentId2); Assert.IsTrue(_links.Any()); - Assert.IsTrue(_links[0].IsPassive); - } - - [TestMethod] - public void AddTeammatesTest() - { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - Assert.AreEqual(2, _links.List.Count); - var link = _links[0] as CommunicationLink; - Assert.IsNotNull(link); - Assert.AreEqual(CommunicationType.CommunicateTo, link.Communication); - link = _links[1] as CommunicationLink; - Assert.IsNotNull(link); - Assert.AreEqual(CommunicationType.CommunicateTo, link.Communication); } [TestMethod] public void ClearTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - _links.AddMembers(_teammateId3, _teammateId1, _teamId); + _links.AddLink(_agentId1, _agentId2); + _links.AddLink(_agentId3, _agentId1); _links.Clear(); Assert.IsFalse(_links.Any()); } @@ -88,112 +57,129 @@ public void ClearTest() [TestMethod] public void DeactivateTeammatesLinkTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); + _links.AddLink(_agentId1, _agentId2); var link = _links[0]; // Active link - Assert.AreEqual(NetworkLinkState.Active, link.State); Assert.IsTrue(link.IsActive); // Deactivate - _links.DeactivateTeammates(_teammateId1, _teammateId2, _teamId); - Assert.AreEqual(NetworkLinkState.Passive, link.State); + _links.DeactivateLink(_agentId1, _agentId2); + Assert.IsFalse(link.IsActive); Assert.IsTrue(link.IsPassive); } [TestMethod] public void HasActiveLinkTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); + _links.AddLink(_agentId1, _agentId2); var link = _links[0]; - Assert.IsTrue(link.HasActiveLink(_teammateId1, _teammateId2)); - Assert.IsFalse(link.HasActiveLink(_teammateId1, _teammateId3)); + Assert.IsTrue(link.HasActiveLink(_agentId1, _agentId2)); + Assert.IsFalse(link.HasActiveLink(_agentId1, _agentId3)); } [TestMethod] public void HasPassiveLinkTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); + _links.AddLink(_agentId1, _agentId2); var link = _links[0]; link.Deactivate(); - Assert.IsTrue(link.HasPassiveLink(_teammateId1, _teammateId2)); - Assert.IsFalse(link.HasPassiveLink(_teammateId1, _teammateId3)); + Assert.IsTrue(link.HasPassiveLink(_agentId1, _agentId2)); + Assert.IsFalse(link.HasPassiveLink(_agentId1, _agentId3)); } [TestMethod] public void GetActiveLinksTest() { - Assert.AreEqual(0, new List(_links.GetActiveLinks(_teammateId1)).Count); - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - _links.AddMembers(_teammateId3, _teammateId1, _teamId); - var teamId2 = new AgentId(2, 1); + Assert.AreEqual(0, new List(_links.GetActiveLinks(_agentId1)).Count); + _links.AddLink(_agentId1, _agentId2); + _links.AddLink(_agentId3, _agentId1); var teammateId4 = new AgentId(5, 2); - _links.AddMembers(_teammateId1, teammateId4, teamId2); - Assert.AreEqual(3, new List(_links.GetActiveLinks(_teammateId1)).Count); + _links.AddLink(_agentId1, teammateId4); + Assert.AreEqual(3, new List(_links.GetActiveLinks(_agentId1)).Count); // Distinct test - _links.AddMembers(_teammateId1, _teammateId2, teamId2); - Assert.AreEqual(3, new List(_links.GetActiveLinks(_teammateId1)).Count); - } - - [TestMethod] - public void SubordinateExistsTest() - { - _links.AddSubordinate(_teammateId1, _teammateId2, _teamId); - Assert.IsFalse(_links.Exists(_teammateId1, CommunicationType.CommunicateTo, _teammateId2, _teamId)); - Assert.IsFalse(_links.Exists(_teammateId2, CommunicationType.CommunicateTo, _teammateId1, _teamId)); - Assert.IsFalse(_links.Exists(_teammateId1, CommunicationType.ReportTo, _teammateId1, _teamId)); - Assert.IsFalse(_links.Exists(_teammateId2, CommunicationType.ReportTo, _teammateId2, _teamId)); - Assert.IsTrue(_links.Exists(_teammateId1, CommunicationType.ReportTo, _teammateId2, _teamId)); + _links.AddLink(_agentId1, _agentId2); + Assert.AreEqual(3, new List(_links.GetActiveLinks(_agentId1)).Count); } [TestMethod] public void TeammateExistsTest() { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - Assert.IsTrue(_links.Exists(_teammateId1, CommunicationType.CommunicateTo, _teammateId2, _teamId)); - Assert.IsFalse(_links.Exists(_teammateId1, CommunicationType.ReportTo, _teammateId2, _teamId)); - } - - [TestMethod] - public void GetActiveLinksByGroupClassKeyTest() - { - _links.AddMembers(_teammateId1, _teammateId2, _teamId); - Assert.AreEqual(1, new List(_links.GetActiveLinks(_teammateId1, _teammateId2.ClassKey)).Count); - var teammateId4 = new AgentId(5, 3); - _links.AddMembers(_teammateId1, teammateId4, _teamId); - Assert.AreEqual(1, new List(_links.GetActiveLinks(_teammateId1, _teammateId2.ClassKey)).Count); - Assert.AreEqual(1, new List(_links.GetActiveLinks(_teammateId1, teammateId4.ClassKey)).Count); - // Distinct test - var teamId2 = new AgentId(2, 1); - _links.AddMembers(_teammateId1, _teammateId2, teamId2); - Assert.AreEqual(1, new List(_links.GetActiveLinks(_teammateId1, _teammateId2.ClassKey)).Count); + _links.AddLink(_agentId1, _agentId2); + Assert.IsTrue(_links.Exists(_agentId1, _agentId2)); + Assert.IsTrue(_links.Exists(_agentId2, _agentId1)); } [TestMethod] public void ExistsTest() { - var link = new CommunicationLink(_teammateId1, CommunicationType.CommunicateTo, _teammateId2, _teamId); - var linkFalse = new CommunicationLink(_teammateId1, CommunicationType.ReportTo, _teammateId2, _teamId); + var link = new NetworkLink(_agentId1, _agentId2); Assert.IsFalse(_links.Exists(link)); _links.List.Add(link); Assert.IsTrue(_links.Exists(link)); - Assert.IsFalse(_links.Exists(linkFalse)); } [TestMethod] public void AddLinkTest() { - var link = new CommunicationLink(_teammateId1, CommunicationType.CommunicateTo, _teammateId2, _teamId); - _links.AddLink(link); + var link = new NetworkLink(_agentId1, _agentId2); + _links.AddLink(_agentId1, _agentId2); Assert.IsTrue(_links.Exists(link)); // Deactivate test link.Deactivate(); - _links.AddLink(link); + _links.AddLink(_agentId1, _agentId2); Assert.AreEqual(1, _links.List.Count); Assert.IsTrue(_links[0].IsActive); - // Duplicate test - link = new CommunicationLink(_teammateId1, CommunicationType.CommunicateTo, _teammateId2, _teamId); - _links.AddLink(link); - Assert.AreEqual(1, _links.List.Count); + } + + /// + /// Empty list + /// + [TestMethod] + public void AddLinksTest() + { + var agents = new List(); + _links.AddLinks(agents); + Assert.AreEqual(0, _links.Count); + } + + /// + /// Empty list + /// + [TestMethod] + public void AddLinksTest1() + { + var agents = new List {_agentId1, _agentId2, _agentId3}; + _links.AddLinks(agents); + Assert.AreEqual(3, _links.Count); + for (var i = 0; i < 3; i++) + { + Assert.AreEqual(1, _links[i].Count); + } + } + + /// + /// No link + /// + [TestMethod] + public void CountLinksTest() + { + Assert.AreEqual(0, _links.CountLinks(_agentId1, _agentId2)); + _links.AddLink(_agentId1, _agentId2); + Assert.AreEqual(1, _links.CountLinks(_agentId1, _agentId2)); + _links.AddLink(_agentId2, _agentId1); + Assert.AreEqual(2, _links.CountLinks(_agentId1, _agentId2)); + } + + [TestMethod] + public void NormalizedCountLinksTest() + { + Assert.AreEqual(0, _links.NormalizedCountLinks(_agentId1, _agentId2)); + _links.AddLink(_agentId1, _agentId2); + _links.SetMaxLinksCount(); + Assert.AreEqual(1, _links.NormalizedCountLinks(_agentId1, _agentId2)); + _links.AddLink(_agentId2, _agentId1); + _links.SetMaxLinksCount(); + Assert.AreEqual(1, _links.NormalizedCountLinks(_agentId1, _agentId2)); } } } \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/NetworkTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/NetworkTests.cs index 148f4a69..c07383e8 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/NetworkTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/NetworkTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,8 +11,10 @@ using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Organization; +using SymuEngine.Common; using SymuEngine.Repository; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Activities; @@ -36,7 +38,7 @@ public class NetworkTests new Knowledge(1, "1", 1); private readonly AgentId _managerId = new AgentId(3, 2); - private readonly Network _network = new Network(new AgentTemplates()); + private readonly Network _network = new Network(new AgentTemplates(), new InteractionSphereModel()); private readonly AgentId _teamId = new AgentId(1, 1); private readonly AgentId _teamId2 = new AgentId(2, 1); private readonly AgentId _teammateId = new AgentId(4, SymuYellowPages.Actor); @@ -56,7 +58,7 @@ public void Initialize() [TestMethod] public void ClearTest() { - _network.NetworkLinks.AddMembers(_teammateId, _managerId, _teamId); + _network.NetworkLinks.AddLink(_teammateId, _managerId); _network.NetworkGroups.AddGroup(_teamId); _network.NetworkRoles.Add(_networkRole); _network.NetworkPortfolios.AddPortfolio(_teammateId, _componentId, IsWorkingOn, 100); @@ -82,9 +84,13 @@ public void AddTeamTest() Assert.IsTrue(_network.NetworkGroups.Any()); } + /// + /// With network started + /// [TestMethod] public void AddMemberToGroupTest() { + _network.State = AgentState.Started; _network.AddGroup(_teamId); _network.NetworkPortfolios.AddPortfolio(_teamId, _componentId, IsSupportOn, 100); // Method to test @@ -98,6 +104,22 @@ public void AddMemberToGroupTest() Assert.IsTrue(_network.HasObject(_teammateId, IsSupportOn)); } + /// + /// With network starting + /// + [TestMethod] + public void AddMemberToGroupTest2() + { + _network.State = AgentState.Starting; + _network.AddGroup(_teamId); + _network.NetworkPortfolios.AddPortfolio(_teamId, _componentId, IsSupportOn, 100); + // Method to test + _network.AddMemberToGroup(_teammateId, 100, _teamId); + _network.AddMemberToGroup(_teammateId2, 100, _teamId); + // Test link teammates + Assert.IsFalse(_network.NetworkLinks.HasActiveLink(_teammateId, _teammateId2)); + } + [TestMethod] public void RemoveMemberFromGroupTest() { @@ -121,7 +143,7 @@ public void RemoveMemberFromGroupTest() [TestMethod] public void RemoveAgentTest() { - _network.NetworkLinks.AddMembers(_teammateId, _managerId, _teamId); + _network.NetworkLinks.AddLink(_teammateId, _managerId); _network.NetworkGroups.AddMember(_teammateId, 100, _teamId); _network.NetworkRoles.Add(_networkRole); _network.NetworkPortfolios.AddPortfolio(_teammateId, _componentId, IsWorkingOn, 100); @@ -135,7 +157,7 @@ public void RemoveAgentTest() Assert.IsFalse(_network.NetworkRoles.IsMember(_teammateId, _teamId.ClassKey)); Assert.IsFalse(_network.NetworkPortfolios.Exists(_teammateId, _componentId, IsWorkingOn)); Assert.IsFalse(_network.NetworkKnowledges.Any()); - Assert.IsFalse(_network.NetworkActivities.HasActivitiesOn(_teammateId, _teamId)); + Assert.IsFalse(_network.NetworkActivities.AgentHasActivitiesOn(_teammateId, _teamId)); } [TestMethod] diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfolioTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfolioTests.cs index 35cc0fb6..3927d3cd 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfolioTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfolioTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Portfolio; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfoliosTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfoliosTests.cs index 4c7ae031..b2e261d0 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfoliosTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Portfolio/NetworkPortfoliosTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Portfolio; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRoleTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRoleTests.cs index a563f25b..85058fcf 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRoleTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRoleTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Role; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRolesTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRolesTests.cs index f1a09acb..7a3aaca3 100644 --- a/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRolesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/Networks/Role/NetworkRolesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Repository.Networks.Role; #endregion diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionMatrixTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionMatrixTests.cs new file mode 100644 index 00000000..08fa5e97 --- /dev/null +++ b/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionMatrixTests.cs @@ -0,0 +1,196 @@ +#region Licence + +// Description: Symu - SymuEngineTests +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; +using SymuEngine.Repository.Networks; +using SymuEngine.Repository.Networks.Knowledges; +using SymuEngine.Repository.Networks.Sphere; + +#endregion + +namespace SymuEngineTests.Repository.Networks.Sphere +{ + [TestClass] + public class InteractionMatrixTests + { + private readonly List _actors = new List(); + private readonly AgentId _agentId1 = new AgentId(1, 1); + private readonly AgentId _agentId2 = new AgentId(2, 1); + private readonly AgentId _agentId3 = new AgentId(3, 1); + + private readonly Knowledge _info1 = + new Knowledge(1, "1", 1); + + private readonly Knowledge _info2 = + new Knowledge(2, "2", 1); + + private readonly Knowledge _info3 = + new Knowledge(3, "3", 1); + + private readonly AgentTemplates _templates = new AgentTemplates(); + private Network _network; + + private NetworkKnowledges _networkKnowledge; + + [TestInitialize] + public void Initialize() + { + _templates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(InteractionStrategy.Knowledge); + var model = new InteractionSphereModel {On = true}; + _network = new Network(_templates, model); + _networkKnowledge = _network.NetworkKnowledges; + } + + private void Interaction1X1() + { + _actors.Add(_agentId1); + _networkKnowledge.AddKnowledge(_info1); + _networkKnowledge.Add(_agentId1, _info1, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(_agentId1, false, 0); + _network.InteractionSphere.SetSphere(true, _actors, _network); + } + + private void NoInteraction2X2() + { + Interaction1X1(); + _actors.Add(_agentId2); + _networkKnowledge.AddKnowledge(_info2); + _networkKnowledge.Add(_agentId2, _info2, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(_agentId2, false, 0); + _network.InteractionSphere.SetSphere(true, _actors, _network); + } + + private void NoInteraction3X3() + { + NoInteraction2X2(); + _actors.Add(_agentId3); + _networkKnowledge.AddKnowledge(_info3); + _networkKnowledge.Add(_agentId3, _info3, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(_agentId3, false, 0); + _network.InteractionSphere.SetSphere(true, _actors, _network); + } + + [TestMethod] + public void MaxTriadsTest() + { + Assert.AreEqual((uint) 0, InteractionMatrix.MaxTriads(1)); + Assert.AreEqual((uint) 0, InteractionMatrix.MaxTriads(2)); + Assert.AreEqual((uint) 1, InteractionMatrix.MaxTriads(3)); + Assert.AreEqual((uint) 4, InteractionMatrix.MaxTriads(4)); + Assert.AreEqual((uint) 10, InteractionMatrix.MaxTriads(5)); + Assert.AreEqual((uint) 20, InteractionMatrix.MaxTriads(6)); + } + + #region Average interaction + + [TestMethod] + public void AverageInteraction1X1Test() + { + Interaction1X1(); + Assert.AreEqual(0, + InteractionMatrix.GetAverageInteractionMatrix( + InteractionMatrix.GetInteractionMatrix(_network.InteractionSphere.Sphere, _actors.Count))); + } + + [TestMethod] + public void Average0Interaction2X2Test() + { + NoInteraction2X2(); + + Assert.AreEqual(0, + InteractionMatrix.GetAverageInteractionMatrix( + InteractionMatrix.GetInteractionMatrix(_network.InteractionSphere.Sphere, _actors.Count))); + } + + [TestMethod] + public void Average1Interaction2X2Test() + { + NoInteraction2X2(); + _networkKnowledge.Add(_agentId1, _info2, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.Add(_agentId2, _info1, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(_agentId1, false, 0); + _networkKnowledge.InitializeExpertise(_agentId2, false, 0); + _network.InteractionSphere.SetSphere(true, _actors, _network); + + Assert.AreEqual(1F, + InteractionMatrix.GetAverageInteractionMatrix( + InteractionMatrix.GetInteractionMatrix(_network.InteractionSphere.Sphere, _actors.Count))); + } + + [TestMethod] + public void Average0Interaction3X3Test() + { + NoInteraction3X3(); + + Assert.AreEqual(0, + InteractionMatrix.GetAverageInteractionMatrix( + InteractionMatrix.GetInteractionMatrix(_network.InteractionSphere.Sphere, _actors.Count))); + } + + #endregion + + #region triad + + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [DataRow(4)] + [DataRow(5)] + [DataRow(6)] + [TestMethod] + public void SameKnowledgeNumberEqualMaxTriads(int count) + { + _networkKnowledge.AddKnowledge(_info1); + for (ushort i = 0; i < count; i++) + { + var agentId = new AgentId(i, 1); + _actors.Add(agentId); + _networkKnowledge.Add(agentId, _info1, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(agentId, false, 0); + } + + _network.InteractionSphere.SetSphere(true, _actors, _network); + Assert.AreEqual(InteractionMatrix.MaxTriads(count), + InteractionMatrix.NumberOfTriads(_network.InteractionSphere.Sphere)); + } + + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [DataRow(4)] + [DataRow(5)] + [DataRow(6)] + [TestMethod] + public void DifferentKnowledgeNumberEqualMaxTriads(int count) + { + for (ushort i = 0; i < count; i++) + { + var info = + new Knowledge(i, i.ToString(), 1); + _networkKnowledge.AddKnowledge(info); + var agentId = new AgentId(i, 1); + _actors.Add(agentId); + _networkKnowledge.Add(agentId, info, KnowledgeLevel.FullKnowledge, 0, -1); + _networkKnowledge.InitializeExpertise(agentId, false, 0); + } + + _network.InteractionSphere.SetSphere(true, _actors, _network); + Assert.AreEqual((uint) 0, InteractionMatrix.NumberOfTriads(_network.InteractionSphere.Sphere)); + } + + #endregion + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionSphereTests.cs b/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionSphereTests.cs new file mode 100644 index 00000000..6917d4d5 --- /dev/null +++ b/Symu source code/SymuEngineTests/Repository/Networks/Sphere/InteractionSphereTests.cs @@ -0,0 +1,369 @@ +#region Licence + +// Description: Symu - SymuEngineTests +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; +using SymuEngine.Classes.Organization; +using SymuEngine.Common; +using SymuEngine.Repository.Networks; +using SymuEngine.Repository.Networks.Activities; +using SymuEngine.Repository.Networks.Beliefs; +using SymuEngine.Repository.Networks.Knowledges; +using SymuEngine.Repository.Networks.Link; +using SymuEngine.Repository.Networks.Sphere; + +#endregion + +namespace SymuEngineTests.Repository.Networks.Sphere +{ + [TestClass] + public class InteractionSphereTests + { + private readonly Activity _activity = new Activity("1"); + private readonly AgentId _agentId1 = new AgentId(1, 1); + private readonly AgentId _agentId2 = new AgentId(2, 1); + private readonly List _agents = new List(); + private readonly Belief _belief = new Belief(1, 1, RandomGenerator.RandomBinary); + private readonly AgentId _groupId = new AgentId(3, 2); + private readonly Knowledge _knowledge = new Knowledge(1, "1", 1); + private readonly InteractionSphereModel _model = new InteractionSphereModel(); + private readonly AgentTemplates _templates = new AgentTemplates(); + private Network _network; + private InteractionSphere InteractionSphere => _network.InteractionSphere; + + [TestInitialize] + public void Initialize() + { + _model.On = true; + _network = new Network(_templates, _model); + _agents.Add(_agentId1); + _agents.Add(_agentId2); + _network.NetworkKnowledges.AddKnowledge(_knowledge); + _network.NetworkBeliefs.AddBelief(_belief); + _network.NetworkActivities.AddActivity(_activity, _groupId); + } + + [TestMethod] + public void GeAgentIdsForInteractionsTest() + { + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(1, InteractionSphere.GetAgentIdsForInteractions(_agentId1, InteractionStrategy.Homophily, + new InteractionPatterns()).Count()); + } + + /// + /// Without link & !_model.SphereUpdateOverTime + /// + [TestMethod] + public void GeAgentIdsForNewInteractionsTest() + { + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(0, InteractionSphere.GetAgentIdsForNewInteractions(_agentId1, InteractionStrategy.Homophily, + new InteractionPatterns()).Count()); + } + + /// + /// Without link & _model.SphereUpdateOverTime + /// + [TestMethod] + public void GeAgentIdsForNewInteractionsTest1() + { + _model.SphereUpdateOverTime = true; + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(1, InteractionSphere.GetAgentIdsForNewInteractions(_agentId1, InteractionStrategy.Homophily, + new InteractionPatterns()).Count()); + } + + /// + /// With link + /// + [TestMethod] + public void GeAgentIdsForNewInteractionsTest2() + { + _model.SphereUpdateOverTime = true; + AddLink(); + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(0, InteractionSphere.GetAgentIdsForNewInteractions(_agentId1, InteractionStrategy.Homophily, + new InteractionPatterns()).Count()); + } + + /// + /// With no interaction + /// + [TestMethod] + public void GetSphereWeightTest() + { + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(0, InteractionSphere.GetSphereWeight()); + } + + /// + /// With full interaction + /// + [TestMethod] + public void GetSphereWeightTest1() + { + AddBelief(_agentId1, 1); + AddBelief(_agentId2, 1); + AddKnowledge(_agentId1, KnowledgeLevel.FullKnowledge); + AddKnowledge(_agentId2, KnowledgeLevel.FullKnowledge); + AddLink(); + AddActivity(_agentId1); + AddActivity(_agentId2); + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(InteractionSphere.GetMaxSphereWeight(), InteractionSphere.GetSphereWeight()); + } + + [TestMethod] + public void GetMaxSphereWeightTest() + { + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(8, InteractionSphere.GetMaxSphereWeight()); + } + + #region common + + private void AddLink() + { + _network.NetworkLinks.AddLink(_agentId1, _agentId2); + } + + private void AddKnowledge(AgentId agentId, KnowledgeLevel level) + { + _network.NetworkKnowledges.Add(agentId, _knowledge, level, 0, -1); + _network.NetworkKnowledges.InitializeExpertise(agentId, false, 0); + } + + private void AddActivity(AgentId agentId) + { + _network.NetworkActivities.AddActivity(agentId, _activity.Name, _groupId); + } + + private void AddBelief(AgentId agentId, float belief) + { + _network.NetworkBeliefs.Add(agentId, _belief); + _network.NetworkBeliefs.InitializeBeliefs(agentId, false); + _network.NetworkBeliefs.GetAgentBelief(agentId, _belief.Id).BeliefBits.SetBit(0, belief); + } + + #endregion + + #region Homophily + + /// + /// Empty network + /// + [TestMethod] + public void GetHomophilyTest() + { + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(0, InteractionSphere.GetHomophily(_agentId1, _agentId2)); + } + + /// + /// Linked agents + /// + [TestMethod] + public void GetHomophilyTest1() + { + AddLink(); + _model.SetInteractionPatterns(InteractionStrategy.SocialDemographics); + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(1, InteractionSphere.GetHomophily(_agentId1, _agentId2)); + } + + /// + /// Knowledge + /// + [TestMethod] + public void GetHomophilyTest2() + { + AddKnowledge(_agentId1, KnowledgeLevel.FullKnowledge); + AddKnowledge(_agentId2, KnowledgeLevel.FullKnowledge); + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(1, InteractionSphere.GetHomophily(_agentId1, _agentId2)); + } + + /// + /// Belief + /// + [TestMethod] + public void GetHomophilyTest3() + { + AddBelief(_agentId1, 1); + AddBelief(_agentId2, 1); + InteractionSphere.SetSphere(true, _agents, _network); + Assert.AreEqual(1, InteractionSphere.GetHomophily(_agentId1, _agentId2)); + } + + #endregion + + #region Belief + + /// + /// Without belief + /// + [TestMethod] + public void SetRelativeBeliefTest() + { + Assert.AreEqual(0, InteractionSphere.SetRelativeBelief(_agentId1, _agentId2, _network.NetworkBeliefs)); + } + + /// + /// With same belief 1 + /// + [TestMethod] + public void SetRelativeBeliefTest1() + { + AddBelief(_agentId1, 1); + AddBelief(_agentId2, 1); + Assert.AreEqual(1, InteractionSphere.SetRelativeBelief(_agentId1, _agentId2, _network.NetworkBeliefs)); + } + + /// + /// With same belief -1 + /// + [TestMethod] + public void SetRelativeBeliefTest2() + { + AddBelief(_agentId1, -1); + AddBelief(_agentId2, -1); + Assert.AreEqual(1, InteractionSphere.SetRelativeBelief(_agentId1, _agentId2, _network.NetworkBeliefs)); + } + + /// + /// With same belief 0 + /// + [TestMethod] + public void SetRelativeBeliefTest3() + { + AddBelief(_agentId1, 0); + AddBelief(_agentId2, 0); + Assert.AreEqual(0, InteractionSphere.SetRelativeBelief(_agentId1, _agentId2, _network.NetworkBeliefs)); + } + + /// + /// With different belief + /// + [TestMethod] + public void SetRelativeBeliefTest4() + { + AddBelief(_agentId1, -1); + AddBelief(_agentId2, 1); + Assert.AreEqual(-1, InteractionSphere.SetRelativeBelief(_agentId1, _agentId2, _network.NetworkBeliefs)); + } + + #endregion + + #region Knowledge + + /// + /// Without knowledge + /// + [TestMethod] + public void SetRelativeExpertiseTest() + { + Assert.AreEqual(0, + InteractionSphere.SetRelativeKnowledge(_agentId1, _agentId2, _network.NetworkKnowledges)); + } + + /// + /// With different knowledge level + /// + [TestMethod] + public void SetRelativeExpertiseTest1() + { + AddKnowledge(_agentId1, KnowledgeLevel.FullKnowledge); + AddKnowledge(_agentId2, KnowledgeLevel.NoKnowledge); + Assert.AreEqual(0, + InteractionSphere.SetRelativeKnowledge(_agentId1, _agentId2, _network.NetworkKnowledges)); + } + + /// + /// With same knowledge level + /// + [TestMethod] + public void SetRelativeExpertiseTest2() + { + AddKnowledge(_agentId1, KnowledgeLevel.FullKnowledge); + AddKnowledge(_agentId2, KnowledgeLevel.FullKnowledge); + Assert.AreEqual(1, + InteractionSphere.SetRelativeKnowledge(_agentId1, _agentId2, _network.NetworkKnowledges)); + } + + #endregion + + #region SocialProximity + + /// + /// Without link + /// + [TestMethod] + public void SetSocialProximityTest() + { + _network.NetworkLinks.SetMaxLinksCount(); + Assert.AreEqual(0, InteractionSphere.SetSocialProximity(_agentId1, _agentId2, _network.NetworkLinks)); + } + + /// + /// With active link + /// + [TestMethod] + public void SetSocialProximityTest1() + { + AddLink(); + _network.NetworkLinks.SetMaxLinksCount(); + Assert.AreEqual(1, InteractionSphere.SetSocialProximity(_agentId1, _agentId2, _network.NetworkLinks)); + } + + /// + /// With passive link + /// + [TestMethod] + public void SetSocialProximityTest2() + { + var networkLink = new NetworkLink(_agentId1, _agentId2); + networkLink.Deactivate(); + _network.NetworkLinks.AddLink(_agentId1, _agentId2); + Assert.AreEqual(0F, InteractionSphere.SetSocialProximity(_agentId1, _agentId2, _network.NetworkLinks)); + } + + #endregion + + #region Activities + + /// + /// Without Activity + /// + [TestMethod] + public void SetRelativeActivityTest() + { + Assert.AreEqual(0, InteractionSphere.SetRelativeActivity(_agentId1, _agentId2, _network.NetworkActivities)); + } + + /// + /// With different activities level + /// + [TestMethod] + public void SetRelativeActivityTest1() + { + AddActivity(_agentId1); + AddActivity(_agentId2); + Assert.AreEqual(1, InteractionSphere.SetRelativeActivity(_agentId1, _agentId2, _network.NetworkActivities)); + } + + #endregion + } +} \ No newline at end of file diff --git a/Symu source code/SymuEngineTests/Repository/WhitePagesTests.cs b/Symu source code/SymuEngineTests/Repository/WhitePagesTests.cs index 01bbd2c5..3240585a 100644 --- a/Symu source code/SymuEngineTests/Repository/WhitePagesTests.cs +++ b/Symu source code/SymuEngineTests/Repository/WhitePagesTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; +using SymuEngine.Classes.Agents; using SymuEngine.Classes.Organization; using SymuEngine.Common; using SymuEngine.Engine; @@ -44,23 +44,12 @@ public void Initialize() [TestMethod] public void ExistAgentTests() { - var agentId = new AgentId(1, ClassName1); - Assert.IsFalse(_environment.WhitePages.ExistsAgent(agentId)); Assert.IsTrue(_environment.WhitePages.ExistsAgent(_agent.Id)); } - [TestMethod] - public void ExistWithEnvironmentIdAgentTests() - { - var agentId = new AgentId(1, ClassName1); - Assert.IsFalse(_environment.WhitePages.ExistsAgent(agentId)); - } - [TestMethod] public void GetAgentTests() { - var agentId = new AgentId(1, ClassName1); - Assert.IsNull(_environment.WhitePages.GetAgent(agentId)); Assert.AreEqual(_agent, _environment.WhitePages.GetAgent(_agent.Id)); } @@ -99,16 +88,6 @@ public void TestAgentTest1() Assert.ThrowsException(() => new TestAgent(1, _environment)); } - /// - /// 2 Agents With different Names - /// - [TestMethod] - public void TestAgentTest2() - { - _ = new TestAgent(1, ClassName1, _environment); - Assert.AreEqual(1, _environment.WhitePages.FilteredAgentsByClassCount(ClassName1)); - } - [TestMethod] public void SetEnvironment() { @@ -118,12 +97,11 @@ public void SetEnvironment() [TestMethod] public void ClearAgentsTest() { - var agent = new TestAgent(1, ClassName1, _environment); _environment.Start(); - _environment.WhitePages.WaitingForStart(agent.Id); - agent.State = AgentState.Stopping; + _environment.WhitePages.WaitingForStart(_agent.Id); + _agent.State = AgentState.Stopping; _environment.ManageAgentsToStop(); - _environment.WhitePages.WaitingForStop(agent.Id); + _environment.WhitePages.WaitingForStop(_agent.Id); _environment.InitializeIteration(); //Assert Assert.IsFalse(_environment.WhitePages.StoppedAgents.Any()); diff --git a/Symu source code/SymuEngineTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs b/Symu source code/SymuEngineTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs index 7641ba58..e6d69f9a 100644 --- a/Symu source code/SymuEngineTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs +++ b/Symu source code/SymuEngineTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,8 +10,8 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuEngine.Classes.Agent; -using SymuEngine.Classes.Agent.Models; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models; using SymuEngine.Classes.Organization; using SymuEngine.Repository.Networks; using SymuEngine.Repository.Networks.Knowledges; @@ -29,7 +29,7 @@ public class OrganizationKnowledgeAndBeliefTests private readonly AgentExpertise _expertise = new AgentExpertise(); private readonly Knowledge _knowledge = new Knowledge(1, "1", 1); private readonly Knowledge _knowledge2 = new Knowledge(2, "2", 1); - private readonly Network _network = new Network(new AgentTemplates()); + private readonly Network _network = new Network(new AgentTemplates(), new InteractionSphereModel()); private readonly OrganizationModels _organizationModels = new OrganizationModels(); private OrganizationKnowledgeAndBelief _result; diff --git a/Symu source code/SymuEngineTests/Results/Organization/organizationFlexibilityTests.cs b/Symu source code/SymuEngineTests/Results/Organization/organizationFlexibilityTests.cs index daa356ff..99baea32 100644 --- a/Symu source code/SymuEngineTests/Results/Organization/organizationFlexibilityTests.cs +++ b/Symu source code/SymuEngineTests/Results/Organization/organizationFlexibilityTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuEngineTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,8 +9,11 @@ #region using directives +using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using SymuEngine.Classes.Agents; +using SymuEngine.Classes.Agents.Models.CognitiveArchitecture; using SymuEngine.Classes.Organization; using SymuEngine.Results.Organization; using SymuEngineTests.Helpers; @@ -29,20 +32,25 @@ public class OrganizationFlexibilityTests [TestInitialize] public void Initialize() { + _organizationEntity.Models.InteractionSphere.SetInteractionPatterns(InteractionStrategy.SocialDemographics); + _organizationEntity.Models.InteractionSphere.On = true; _environment.SetOrganization(_organizationEntity); _result = new OrganizationFlexibility(_environment); } + #region triads + /// /// No employee /// [TestMethod] public void HandleTriadsTest() { - _result.HandleTriads(0); + SetAgents(0); + _result.HandleTriads(0, 0); Assert.IsTrue(_result.Triads.Any()); - Assert.AreEqual((uint) 0, _result.Triads[0].NumberOfTriads); - Assert.AreEqual((uint) 0, _result.Triads[0].MaxTriads); + Assert.AreEqual(0, _result.Triads[0].ActualNumber); + Assert.AreEqual(0, _result.Triads[0].MaxNumber); } /// @@ -51,15 +59,86 @@ public void HandleTriadsTest() [TestMethod] public void HandleTriadsTest1() { - for (var i = 0; i < 5; i++) + SetAgents(5); + _result.HandleTriads(5, 0); + Assert.AreEqual(1, _result.Triads.Count); + Assert.IsTrue(_result.Triads[0].ActualNumber > 0); + Assert.AreEqual(10, _result.Triads[0].MaxNumber); + } + + private void SetAgents(int count) + { + var agents = new List(); + for (var i = 0; i < count; i++) { - _ = new TestAgent(_organizationEntity.NextEntityIndex(), _environment); + var agent = new TestAgent(_organizationEntity.NextEntityIndex(), _environment); + agents.Add(agent.Id); } - _result.HandleTriads(0); - Assert.AreEqual(1, _result.Triads.Count); - Assert.IsTrue(_result.Triads[0].NumberOfTriads > 0); - Assert.IsTrue(_result.Triads[0].MaxTriads > 0); + _environment.WhitePages.Network.NetworkLinks.AddLinks(agents); + _environment.SetInteractionSphere(true); + } + + #endregion + + #region links + + /// + /// No employee + /// + [TestMethod] + public void HandleLinksTest() + { + SetAgents(0); + _result.HandleLinks(0, 0); + Assert.IsTrue(_result.Links.Any()); + Assert.AreEqual(0, _result.Links[0].ActualNumber); + Assert.AreEqual(0, _result.Links[0].MaxNumber); } + + /// + /// With employees + /// + [TestMethod] + public void HandleLinksTest1() + { + SetAgents(5); + _result.HandleLinks(5, 0); + Assert.AreEqual(1, _result.Links.Count); + Assert.IsTrue(_result.Links[0].ActualNumber > 0); + Assert.AreEqual(10, _result.Links[0].MaxNumber); + } + + #endregion + + #region Sphere + + /// + /// No employee + /// + [TestMethod] + public void HandleSphereTest() + { + SetAgents(0); + _result.HandleSphere(0); + Assert.IsTrue(_result.Sphere.Any()); + Assert.AreEqual(0, _result.Sphere[0].ActualNumber); + Assert.AreEqual(0, _result.Sphere[0].MaxNumber); + } + + /// + /// With employees + /// + [TestMethod] + public void HandleSphereTest1() + { + SetAgents(5); + _result.HandleSphere(0); + Assert.AreEqual(1, _result.Sphere.Count); + Assert.IsTrue(_result.Sphere[0].ActualNumber > 0); + Assert.AreEqual(20, _result.Sphere[0].MaxNumber); + } + + #endregion } } \ No newline at end of file diff --git a/Symu source code/SymuTools/Algorithm/SpecialFunctions.cs b/Symu source code/SymuTools/Algorithm/SpecialFunctions.cs deleted file mode 100644 index ad493317..00000000 --- a/Symu source code/SymuTools/Algorithm/SpecialFunctions.cs +++ /dev/null @@ -1,29 +0,0 @@ -#region Licence - -// Description: Symu - SymuTools -// Website: Website: https://symu.org -// Copyright: (c) 2020 laurent morisseau -// License : the program is distributed under the terms of the GNU General Public License - -#endregion - -#region using directives - -#endregion - -namespace SymuTools.Algorithm -{ - public static class SpecialFunctions - { - /// - /// Return the factorial of a number - /// - /// - /// - public static double Factorial(int x) - // Don't change double for float - { - return MathNet.Numerics.SpecialFunctions.Factorial(x); - } - } -} \ No newline at end of file diff --git a/Symu source code/SymuTools/Algorithm/Constants.cs b/Symu source code/SymuTools/Constants.cs similarity index 84% rename from Symu source code/SymuTools/Algorithm/Constants.cs rename to Symu source code/SymuTools/Constants.cs index cd29a8bf..e0af4a59 100644 --- a/Symu source code/SymuTools/Algorithm/Constants.cs +++ b/Symu source code/SymuTools/Constants.cs @@ -1,13 +1,13 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License #endregion -namespace SymuTools.Algorithm +namespace SymuTools { public static class Constants { diff --git a/Symu source code/SymuTools/List.cs b/Symu source code/SymuTools/List.cs index 6e3723fe..b60ad96f 100644 --- a/Symu source code/SymuTools/List.cs +++ b/Symu source code/SymuTools/List.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion @@ -95,7 +95,7 @@ public static byte Average(this List values) var sum = values.Aggregate(0, (current, value) => (byte) (current + value)); - return (byte) Math.Round(1.0 * sum / values.Count); + return (byte) System.Math.Round(1.0 * sum / values.Count); } public static float Average(this ushort[] values) diff --git a/Symu source code/SymuTools/Math/Combinatorics.cs b/Symu source code/SymuTools/Math/Combinatorics.cs new file mode 100644 index 00000000..e7d0191f --- /dev/null +++ b/Symu source code/SymuTools/Math/Combinatorics.cs @@ -0,0 +1,36 @@ +#region Licence + +// Description: Symu - SymuTools +// Website: https://symu.org +// Copyright: (c) 2020 laurent morisseau +// License : the program is distributed under the terms of the GNU General Public License + +#endregion + +#region using directives + +#endregion + +#region using directives + +using System; + +#endregion + +namespace SymuTools.Math +{ + public static class Combinatorics + { + /// + /// Count the number of possible combinations without repetition. + /// The order does not matter and each object can be chosen only once. + /// + /// Number of elements in the set. + /// Number of elements to choose from the set. Each element is chosen at most once. + /// Maximum number of combinations. + public static uint Combinations(int n, int k) + { + return Convert.ToUInt32(System.Math.Round(MathNet.Numerics.Combinatorics.Combinations(n, k))); + } + } +} \ No newline at end of file diff --git a/Symu source code/SymuTools/MachineLearning/LinearRegression.cs b/Symu source code/SymuTools/Math/MachineLearning/LinearRegression.cs similarity index 97% rename from Symu source code/SymuTools/MachineLearning/LinearRegression.cs rename to Symu source code/SymuTools/Math/MachineLearning/LinearRegression.cs index 9bed022a..5a6da692 100644 --- a/Symu source code/SymuTools/MachineLearning/LinearRegression.cs +++ b/Symu source code/SymuTools/Math/MachineLearning/LinearRegression.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -13,7 +13,7 @@ #endregion -namespace SymuTools.MachineLearning +namespace SymuTools.Math.MachineLearning { /// /// Obsolete, should use ML.Net lib @@ -171,14 +171,14 @@ private static double[][] MatrixDecompose(double[][] matrix, out int[] perm, for (var j = 0; j < n - 1; ++j) // each column { - var colMax = Math.Abs(result[j][j]); + var colMax = System.Math.Abs(result[j][j]); var pRow = j; for (var i = j + 1; i < n; ++i) // reader Matt V needed this: { - if (Math.Abs(result[i][j]) > colMax) + if (System.Math.Abs(result[i][j]) > colMax) { - colMax = Math.Abs(result[i][j]); + colMax = System.Math.Abs(result[i][j]); pRow = i; } } diff --git a/Symu source code/SymuTools/ProbabilityDistributions/Bernoulli.cs b/Symu source code/SymuTools/Math/ProbabilityDistributions/Bernoulli.cs similarity index 88% rename from Symu source code/SymuTools/ProbabilityDistributions/Bernoulli.cs rename to Symu source code/SymuTools/Math/ProbabilityDistributions/Bernoulli.cs index 955aea84..d8cfc6b5 100644 --- a/Symu source code/SymuTools/ProbabilityDistributions/Bernoulli.cs +++ b/Symu source code/SymuTools/Math/ProbabilityDistributions/Bernoulli.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -9,11 +9,9 @@ #region using directives -using Math = MathNet.Numerics.Distributions; - #endregion -namespace SymuTools.ProbabilityDistributions +namespace SymuTools.Math.ProbabilityDistributions { /// /// the discrete probability distribution of a random variable which takes the value 1 with probability p @@ -35,7 +33,7 @@ public static class Bernoulli /// A sample from the Bernoulli distribution public static bool Sample(float probability) { - return Math.Bernoulli.Sample(probability) == 1; + return MathNet.Numerics.Distributions.Bernoulli.Sample(probability) == 1; } } } \ No newline at end of file diff --git a/Symu source code/SymuTools/ProbabilityDistributions/Categorical.cs b/Symu source code/SymuTools/Math/ProbabilityDistributions/Categorical.cs similarity index 58% rename from Symu source code/SymuTools/ProbabilityDistributions/Categorical.cs rename to Symu source code/SymuTools/Math/ProbabilityDistributions/Categorical.cs index 9ac552e0..cce8fbe6 100644 --- a/Symu source code/SymuTools/ProbabilityDistributions/Categorical.cs +++ b/Symu source code/SymuTools/Math/ProbabilityDistributions/Categorical.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,10 @@ #region using directives using System; -using Math = MathNet.Numerics.Distributions; #endregion -namespace SymuTools.ProbabilityDistributions +namespace SymuTools.Math.ProbabilityDistributions { /// /// a categorical distribution (also called a generalized Bernoulli distribution, multinoulli distribution[1]) is a @@ -38,7 +37,7 @@ public static class Categorical /// public static int SampleIndex(double[] probabilityMass) { - return Math.Categorical.Sample(probabilityMass); + return MathNet.Numerics.Distributions.Categorical.Sample(probabilityMass); } /// @@ -62,6 +61,56 @@ public static int SampleIndex(float probabilityMass1, float probabilityMass2, fl return SampleIndex(probabilityMass); } + /// + /// Samples one categorical distributed random variable + /// + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// + /// One random integer between 0 and the size of the categorical (exclusive) representing the index of + /// probabilityMass + /// + public static int SampleIndex(float probabilityMass1, float probabilityMass2, float probabilityMass3, + float probabilityMass4) + { + var probabilityMass = new double[] + { + probabilityMass1, + probabilityMass2, + probabilityMass3, + probabilityMass4 + }; + return SampleIndex(probabilityMass); + } + + /// + /// Samples one categorical distributed random variable + /// + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// An array of nonnegative ratios. Not assumed to be normalized. + /// + /// One random integer between 0 and the size of the categorical (exclusive) representing the index of + /// probabilityMass + /// + public static int SampleIndex(float probabilityMass1, float probabilityMass2, float probabilityMass3, + float probabilityMass4, float probabilityMass5) + { + var probabilityMass = new double[] + { + probabilityMass1, + probabilityMass2, + probabilityMass3, + probabilityMass4, + probabilityMass5 + }; + return SampleIndex(probabilityMass); + } + /// /// Samples one categorical distributed random variable /// @@ -77,7 +126,7 @@ public static double SampleValue(double[] probabilityMass) throw new ArgumentNullException(nameof(probabilityMass)); } - var index = Math.Categorical.Sample(probabilityMass); + var index = MathNet.Numerics.Distributions.Categorical.Sample(probabilityMass); return probabilityMass[index]; } @@ -97,7 +146,7 @@ public static float SampleValue(float[] probabilityMass) } var probabilityMassDouble = Array.ConvertAll(probabilityMass, x => (double) x); - var index = Math.Categorical.Sample(probabilityMassDouble); + var index = MathNet.Numerics.Distributions.Categorical.Sample(probabilityMassDouble); return probabilityMass[index]; } } diff --git a/Symu source code/SymuTools/ProbabilityDistributions/ContinuousUniform.cs b/Symu source code/SymuTools/Math/ProbabilityDistributions/ContinuousUniform.cs similarity index 92% rename from Symu source code/SymuTools/ProbabilityDistributions/ContinuousUniform.cs rename to Symu source code/SymuTools/Math/ProbabilityDistributions/ContinuousUniform.cs index 6169f68b..e79d4192 100644 --- a/Symu source code/SymuTools/ProbabilityDistributions/ContinuousUniform.cs +++ b/Symu source code/SymuTools/Math/ProbabilityDistributions/ContinuousUniform.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,10 @@ #region using directives using System; -using Math = MathNet.Numerics.Distributions; #endregion -namespace SymuTools.ProbabilityDistributions +namespace SymuTools.Math.ProbabilityDistributions { /// /// The distribution describes an experiment where there is an arbitrary outcome that lies between certain bounds. @@ -31,7 +30,7 @@ public static class ContinuousUniform /// A sample from the discrete uniform distribution [lower, upper] public static float Sample(float lower, float upper) { - return (float) Math.ContinuousUniform.Sample(lower, upper); + return (float) MathNet.Numerics.Distributions.ContinuousUniform.Sample(lower, upper); } /// @@ -44,7 +43,7 @@ public static float Sample(float lower, float upper) public static float[] Samples(int length, float lower, float upper) { var values = new double[length]; - Math.ContinuousUniform.Samples(values, lower, upper); + MathNet.Numerics.Distributions.ContinuousUniform.Samples(values, lower, upper); return Array.ConvertAll(values, x => (float) x); } diff --git a/Symu source code/SymuTools/ProbabilityDistributions/DiscreteUniform.cs b/Symu source code/SymuTools/Math/ProbabilityDistributions/DiscreteUniform.cs similarity index 89% rename from Symu source code/SymuTools/ProbabilityDistributions/DiscreteUniform.cs rename to Symu source code/SymuTools/Math/ProbabilityDistributions/DiscreteUniform.cs index c9165f9e..0d1b463f 100644 --- a/Symu source code/SymuTools/ProbabilityDistributions/DiscreteUniform.cs +++ b/Symu source code/SymuTools/Math/ProbabilityDistributions/DiscreteUniform.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,11 +10,10 @@ #region using directives using System; -using Math = MathNet.Numerics.Distributions; #endregion -namespace SymuTools.ProbabilityDistributions +namespace SymuTools.Math.ProbabilityDistributions { /// /// the discrete uniform distribution is a symmetric probability distribution wherein a finite number of values are @@ -33,7 +32,7 @@ public static class DiscreteUniform /// A sample from the discrete uniform distribution [lower, upper] public static int Sample(int lower, int upper) { - return Math.DiscreteUniform.Sample(lower, upper); + return MathNet.Numerics.Distributions.DiscreteUniform.Sample(lower, upper); } /// @@ -44,7 +43,7 @@ public static int Sample(int lower, int upper) /// A sample from the discrete uniform distribution [lower, upper] public static byte SampleToByte(byte lower, byte upper) { - return Convert.ToByte(Math.DiscreteUniform.Sample(lower, upper)); + return Convert.ToByte(MathNet.Numerics.Distributions.DiscreteUniform.Sample(lower, upper)); } /// @@ -67,7 +66,7 @@ public static byte SampleByMeanToByte(byte mean, byte standardDeviation) /// A sample from the discrete uniform distribution public static int Sample(int upper) { - return Math.DiscreteUniform.Sample(0, upper); + return MathNet.Numerics.Distributions.DiscreteUniform.Sample(0, upper); } /// @@ -90,7 +89,7 @@ public static byte SampleToByte(int upper) public static float[] Samples(int length, int lower, int upper) { var values = new int[length]; - Math.DiscreteUniform.Samples(values, lower, upper); + MathNet.Numerics.Distributions.DiscreteUniform.Samples(values, lower, upper); return Array.ConvertAll(values, x => (float) x); } @@ -103,7 +102,7 @@ public static float[] Samples(int length, int lower, int upper) public static byte[] SamplesToByte(int length, int upper) { var values = new int[length]; - Math.DiscreteUniform.Samples(values, 0, upper); + MathNet.Numerics.Distributions.DiscreteUniform.Samples(values, 0, upper); return Array.ConvertAll(values, x => (byte) x); } } diff --git a/Symu source code/SymuTools/ProbabilityDistributions/Normal.cs b/Symu source code/SymuTools/Math/ProbabilityDistributions/Normal.cs similarity index 86% rename from Symu source code/SymuTools/ProbabilityDistributions/Normal.cs rename to Symu source code/SymuTools/Math/ProbabilityDistributions/Normal.cs index 53223846..c327eef6 100644 --- a/Symu source code/SymuTools/ProbabilityDistributions/Normal.cs +++ b/Symu source code/SymuTools/Math/ProbabilityDistributions/Normal.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuTools -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,12 +10,10 @@ #region using directives using System; -using SymuTools.Algorithm; -using Math = MathNet.Numerics.Distributions; #endregion -namespace SymuTools.ProbabilityDistributions +namespace SymuTools.Math.ProbabilityDistributions { /// /// a normal (or Gaussian or Gauss or Laplace–Gauss) distribution is a type of continuous probability distribution for @@ -38,7 +36,7 @@ public static float Sample(float mean, float stdDev) { return System.Math.Abs(stdDev) < Constants.Tolerance ? mean - : Convert.ToSingle(Math.Normal.Sample(mean, stdDev)); + : Convert.ToSingle(MathNet.Numerics.Distributions.Normal.Sample(mean, stdDev)); } /// @@ -48,7 +46,7 @@ public static float Sample(float mean, float stdDev) /// the cumulative distribution at location x public static float CumulativeDistribution(float x) { - return Convert.ToSingle(Math.Normal.CDF(0, 1, x)); + return Convert.ToSingle(MathNet.Numerics.Distributions.Normal.CDF(0, 1, x)); } } } \ No newline at end of file diff --git a/Symu source code/SymuToolsTests/ListTests.cs b/Symu source code/SymuToolsTests/ListTests.cs index d972de82..e4ac57ee 100644 --- a/Symu source code/SymuToolsTests/ListTests.cs +++ b/Symu source code/SymuToolsTests/ListTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License diff --git a/Symu source code/SymuToolsTests/MachineLearning/LinearRegressionTests.cs b/Symu source code/SymuToolsTests/MachineLearning/LinearRegressionTests.cs index 81254dcd..70f77958 100644 --- a/Symu source code/SymuToolsTests/MachineLearning/LinearRegressionTests.cs +++ b/Symu source code/SymuToolsTests/MachineLearning/LinearRegressionTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.MachineLearning; +using SymuTools.Math.MachineLearning; #endregion diff --git a/Symu source code/SymuToolsTests/ProbabilityDistributions/BernoulliTests.cs b/Symu source code/SymuToolsTests/ProbabilityDistributions/BernoulliTests.cs index 0199fab3..1551b860 100644 --- a/Symu source code/SymuToolsTests/ProbabilityDistributions/BernoulliTests.cs +++ b/Symu source code/SymuToolsTests/ProbabilityDistributions/BernoulliTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuToolsTests/ProbabilityDistributions/CategoricalTests.cs b/Symu source code/SymuToolsTests/ProbabilityDistributions/CategoricalTests.cs index 1f78d26a..83ea60f0 100644 --- a/Symu source code/SymuToolsTests/ProbabilityDistributions/CategoricalTests.cs +++ b/Symu source code/SymuToolsTests/ProbabilityDistributions/CategoricalTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,7 +11,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion @@ -39,12 +39,21 @@ public void SampleIndexTest() } /// - /// Force Sample to index 0 + /// Force Sample to index 1 /// [TestMethod] public void SampleIndexTest1() { - Assert.AreEqual(0, Categorical.SampleIndex(1, 0, 0)); + Assert.AreEqual(1, Categorical.SampleIndex(0, 1, 0)); + } + + /// + /// Force Sample to not be equal to index 0 + /// + [TestMethod] + public void SampleIndexTest2() + { + Assert.AreNotEqual(0, Categorical.SampleIndex(0, 0.3F, 0.3F, 0.4F)); } /// diff --git a/Symu source code/SymuToolsTests/ProbabilityDistributions/ContinuousUniformTests.cs b/Symu source code/SymuToolsTests/ProbabilityDistributions/ContinuousUniformTests.cs index 4e413a8a..046babae 100644 --- a/Symu source code/SymuToolsTests/ProbabilityDistributions/ContinuousUniformTests.cs +++ b/Symu source code/SymuToolsTests/ProbabilityDistributions/ContinuousUniformTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion @@ -77,14 +77,5 @@ public void ValueBinaryArrayTest1() var binaryArray = ContinuousUniform.FilteredSamples(1, 0, 5); Assert.AreEqual(5, binaryArray[0]); } - - [TestMethod] - public void Test() - { - var test = - new MathNet.Numerics.Distributions.ContinuousUniform(0, 1); - var ret = test.InverseCumulativeDistribution(0.2); - var ret2 = MathNet.Numerics.Distributions.ContinuousUniform.InvCDF(0, 1, 0.2); - } } } \ No newline at end of file diff --git a/Symu source code/SymuToolsTests/ProbabilityDistributions/DiscreteUniformTests.cs b/Symu source code/SymuToolsTests/ProbabilityDistributions/DiscreteUniformTests.cs index 65ad4a21..3e106b91 100644 --- a/Symu source code/SymuToolsTests/ProbabilityDistributions/DiscreteUniformTests.cs +++ b/Symu source code/SymuToolsTests/ProbabilityDistributions/DiscreteUniformTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -11,8 +11,8 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.Algorithm; -using SymuTools.ProbabilityDistributions; +using SymuTools; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuToolsTests/ProbabilityDistributions/NormalTests.cs b/Symu source code/SymuToolsTests/ProbabilityDistributions/NormalTests.cs index ea3831dc..9f32e4d2 100644 --- a/Symu source code/SymuToolsTests/ProbabilityDistributions/NormalTests.cs +++ b/Symu source code/SymuToolsTests/ProbabilityDistributions/NormalTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -10,7 +10,7 @@ #region using directives using Microsoft.VisualStudio.TestTools.UnitTesting; -using SymuTools.ProbabilityDistributions; +using SymuTools.Math.ProbabilityDistributions; #endregion diff --git a/Symu source code/SymuToolsTests/Serialization/SerializationTests.cs b/Symu source code/SymuToolsTests/Serialization/SerializationTests.cs index 32d2f2ca..176023b2 100644 --- a/Symu source code/SymuToolsTests/Serialization/SerializationTests.cs +++ b/Symu source code/SymuToolsTests/Serialization/SerializationTests.cs @@ -1,7 +1,7 @@ #region Licence // Description: Symu - SymuToolsTests -// Website: Website: https://symu.org +// Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License