From 015cc51ed37089818384c44cdcfcd836b871d946 Mon Sep 17 00:00:00 2001 From: lmorisse Date: Thu, 8 Oct 2020 09:29:32 +0200 Subject: [PATCH] Add factory constructor --- .../Agents/CognitiveAgent.Messaging.cs | 2 +- .../Models/CognitiveModels/ActorTaskModel.cs | 2 +- .../Models/CognitiveModels/BeliefsModel.cs | 6 +-- .../Models/CognitiveModels/KnowledgeModel.cs | 5 +-- .../CognitiveModels/ResourceTaskModel.cs | 2 +- .../Classes/Organization/MainOrganization.cs | 6 +-- .../Symu/Repository/Edges/ActorBelief.cs | 13 +++++++ .../Symu/Repository/Edges/ActorKnowledge.cs | 23 ++++++++---- .../Symu/Repository/Edges/ActorPortfolio.cs | 30 --------------- SourceCode/Symu/Repository/Entities/Belief.cs | 19 ++++++++++ .../Symu/Repository/Entities/CyclicalEvent.cs | 4 ++ .../Symu/Repository/Entities/Database.cs | 6 +++ .../Symu/Repository/Entities/EventEntity.cs | 5 ++- .../Symu/Repository/Entities/Knowledge.cs | 4 ++ .../Symu/Repository/Entities/RandomEvent.cs | 5 ++- .../Classes/Agents/CognitiveAgentTests.cs | 16 ++++---- .../CognitiveModels/BeliefsModelTests.cs | 2 +- .../CognitiveModels/ForgettingModelTests.cs | 12 ++---- .../CognitiveModels/KnowledgeModelTests.cs | 2 +- .../CognitiveModels/LearningModelTests.cs | 6 +-- .../MurphyIncompleteKnowledgeTests.cs | 6 +-- .../Repository/Entities/PortfolioTests.cs | 37 ------------------- .../organizationFlexibilityTests.cs | 2 +- .../Classes/ExampleEnvironment.cs | 2 +- .../Classes/ExampleOrganization.cs | 2 +- .../SymuLearnAndForgetTests.cs | 2 +- .../Classes/ExampleOrganization.cs | 4 +- .../Classes/GroupAgent.cs | 4 +- .../Classes/ExampleEnvironment.cs | 2 +- Symu examples/SymuLearnAndForget/Home.cs | 2 +- .../Classes/ExampleEnvironment.cs | 4 +- .../Classes/ExampleEnvironment.cs | 4 +- .../Classes/ExampleOrganization.cs | 2 +- .../Classes/ExampleEnvironment.cs | 4 +- .../Classes/ExampleOrganization.cs | 2 +- 35 files changed, 117 insertions(+), 132 deletions(-) delete mode 100644 SourceCode/Symu/Repository/Edges/ActorPortfolio.cs delete mode 100644 SourceCode/SymuTests/Repository/Entities/PortfolioTests.cs diff --git a/SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs b/SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs index 5bccd795..349a5bcd 100644 --- a/SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs +++ b/SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs @@ -229,7 +229,7 @@ public bool AcceptNewInteraction(IAgentId senderId) } // Message.Sender is now part of agent interaction sphere - _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, AgentId, senderId); + ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, AgentId, senderId); return true; } diff --git a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ActorTaskModel.cs b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ActorTaskModel.cs index 894ec348..63421504 100644 --- a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ActorTaskModel.cs +++ b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ActorTaskModel.cs @@ -92,7 +92,7 @@ public IDictionary> Knowledge /// public void AddActorTask(IAgentId taskId) { - _ = new ActorTask(_actorTaskNetwork, _agentId, taskId); + ActorTask.CreateInstance(_actorTaskNetwork, _agentId, taskId); } /// diff --git a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/BeliefsModel.cs b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/BeliefsModel.cs index 9eb13f89..6ca0af36 100644 --- a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/BeliefsModel.cs +++ b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/BeliefsModel.cs @@ -157,7 +157,7 @@ public void AddBelief(IAgentId beliefId, BeliefLevel beliefLevel) return; } - _ = new ActorBelief(_actorBeliefNetwork, _agentId, beliefId, beliefLevel); + ActorBelief.CreateInstance(_actorBeliefNetwork, _agentId, beliefId, beliefLevel); } @@ -180,7 +180,7 @@ public void AddBeliefFromKnowledgeId(IAgentId knowledgeId, BeliefLevel beliefLev throw new NullReferenceException(nameof(belief)); } - _ = new ActorBelief(_actorBeliefNetwork, _agentId, belief.EntityId, beliefLevel); + ActorBelief.CreateInstance(_actorBeliefNetwork, _agentId, belief.EntityId, beliefLevel); } public ActorBelief GetActorBelief(IAgentId beliefId) @@ -423,7 +423,7 @@ public void LearnNewBelief(IAgentId beliefId, BeliefLevel beliefLevel) return; } - _ = new ActorBelief(_actorBeliefNetwork, _agentId, beliefId, beliefLevel); + ActorBelief.CreateInstance(_actorBeliefNetwork, _agentId, beliefId, beliefLevel); InitializeBeliefs(true); } } diff --git a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/KnowledgeModel.cs b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/KnowledgeModel.cs index 1aa30e94..b715ca3a 100644 --- a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/KnowledgeModel.cs +++ b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/KnowledgeModel.cs @@ -192,7 +192,7 @@ public void AddKnowledge(IAgentId knowledgeId, KnowledgeLevel level, float minim return; } - _ = new ActorKnowledge(_actorKnowledgeNetwork, _agentId, knowledgeId, level, minimumKnowledge, timeToLive); + ActorKnowledge.CreateInstance(_actorKnowledgeNetwork, _agentId, knowledgeId, level, minimumKnowledge, timeToLive); } /// @@ -209,8 +209,7 @@ public void AddKnowledge(IAgentId knowledgeId, float[] knowledgeBits, float mini return; } - var actorKnowledge = new ActorKnowledge(_agentId, knowledgeId, knowledgeBits, minimumKnowledge, timeToLive); - _actorKnowledgeNetwork.Add(actorKnowledge); + ActorKnowledge.CreateInstance(_actorKnowledgeNetwork, _agentId, knowledgeId, knowledgeBits, minimumKnowledge, timeToLive); } diff --git a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ResourceTaskModel.cs b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ResourceTaskModel.cs index 5ab794dd..df25aae4 100644 --- a/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ResourceTaskModel.cs +++ b/SourceCode/Symu/Classes/Agents/Models/CognitiveModels/ResourceTaskModel.cs @@ -88,7 +88,7 @@ public void AddResourceTasks(IEnumerable tasks) foreach (var task in tasks) { - _ = new ResourceTask(_resourceTaskNetwork, _resourceId, task.EntityId); + ResourceTask.CreateInstance(_resourceTaskNetwork, _resourceId, task.EntityId); } } } diff --git a/SourceCode/Symu/Classes/Organization/MainOrganization.cs b/SourceCode/Symu/Classes/Organization/MainOrganization.cs index ec04ed27..39a8541c 100644 --- a/SourceCode/Symu/Classes/Organization/MainOrganization.cs +++ b/SourceCode/Symu/Classes/Organization/MainOrganization.cs @@ -26,17 +26,17 @@ namespace Symu.Classes.Organization /// You must define your own organization derived classes. /// //TODO should be an abstract class - public class MainOrganization //: Entity + public class MainOrganization { public const byte Class = ClassIdCollection.Organization; + public static IClassId ClassId => new ClassId(Class); - public MainOrganization(string name) //: base(new MetaNetwork(), Class, name) + public MainOrganization(string name) { Name = name; MetaNetwork = new GraphMetaNetwork(Models.InteractionSphere); } - public static IClassId ClassId => new ClassId(Class); public string Name { get; set; } diff --git a/SourceCode/Symu/Repository/Edges/ActorBelief.cs b/SourceCode/Symu/Repository/Edges/ActorBelief.cs index 59207dac..e3be02a1 100644 --- a/SourceCode/Symu/Repository/Edges/ActorBelief.cs +++ b/SourceCode/Symu/Repository/Edges/ActorBelief.cs @@ -41,10 +41,23 @@ public class ActorBelief : OrgMod.Edges.ActorBelief /// private const int RangeMax = 1; + public ActorBelief(IAgentId actorId, IAgentId beliefId, BeliefLevel beliefLevel) : base(actorId, beliefId) { BeliefLevel = beliefLevel; } + /// + /// Factory + /// + /// + /// + /// + /// + /// + public static ActorBelief CreateInstance(ActorBeliefNetwork network, IAgentId actorId, IAgentId beliefId, BeliefLevel beliefLevel) + { + return new ActorBelief(network, actorId, beliefId, beliefLevel); + } public ActorBelief(ActorBeliefNetwork network, IAgentId actorId, IAgentId beliefId, BeliefLevel beliefLevel) : base(network, actorId, beliefId) { BeliefLevel = beliefLevel; diff --git a/SourceCode/Symu/Repository/Edges/ActorKnowledge.cs b/SourceCode/Symu/Repository/Edges/ActorKnowledge.cs index 5641e599..18cadc37 100644 --- a/SourceCode/Symu/Repository/Edges/ActorKnowledge.cs +++ b/SourceCode/Symu/Repository/Edges/ActorKnowledge.cs @@ -29,6 +29,10 @@ namespace Symu.Repository.Edges /// Dev Java, test, project management, sociology, ... public class ActorKnowledge : EntityKnowledge { + public static ActorKnowledge CreateInstance(TwoModesNetwork network, IAgentId actorId, IAgentId knowledgeId, KnowledgeBits knowledgeBits) + { + return new ActorKnowledge(network, actorId, knowledgeId, knowledgeBits); + } /// /// Constructor used by WorkerCognitiveAgent for ForgettingKnowledge /// @@ -41,8 +45,7 @@ public ActorKnowledge(TwoModesNetwork network, IAgentId actorI { KnowledgeBits = knowledgeBits; Length = KnowledgeBits?.Length ?? 0; - } - + } /// /// Constructor used by Agent.Cognitive for ForgettingKnowledge /// @@ -62,7 +65,11 @@ public ActorKnowledge(IAgentId actorId, IAgentId knowledgeId, float[] knowledgeB KnowledgeBits.SetBits(knowledgeBits, step); Length = KnowledgeBits.Length; } - + public static ActorKnowledge CreateInstance(TwoModesNetwork network, IAgentId actorId, IAgentId knowledgeId, float[] knowledgeBits, float minimumKnowledge, + short timeToLive, ushort step = 0) + { + return new ActorKnowledge(network, actorId, knowledgeId, knowledgeBits, minimumKnowledge, timeToLive, step); + } /// /// Constructor used by Agent.Cognitive for ForgettingKnowledge /// @@ -74,8 +81,7 @@ public ActorKnowledge(IAgentId actorId, IAgentId knowledgeId, float[] knowledgeB /// /// public ActorKnowledge(TwoModesNetwork network, IAgentId actorId, IAgentId knowledgeId, float[] knowledgeBits, float minimumKnowledge, - short timeToLive, - ushort step = 0) : base(network, actorId, knowledgeId) + short timeToLive, ushort step = 0) : base(network, actorId, knowledgeId) { MinimumKnowledge = minimumKnowledge; TimeToLive = timeToLive; @@ -83,7 +89,6 @@ public ActorKnowledge(TwoModesNetwork network, IAgentId actorI KnowledgeBits.SetBits(knowledgeBits, step); Length = KnowledgeBits.Length; } - /// /// Constructor based on the knowledge Id and the knowledge Level. /// KnowledgeBits is not yet initialized. @@ -103,7 +108,11 @@ public ActorKnowledge(IAgentId actorId, IAgentId knowledgeId, KnowledgeLevel lev KnowledgeBits = new KnowledgeBits(minimumKnowledge, timeToLive); Length = KnowledgeBits.Length; } - + public static ActorKnowledge CreateInstance(TwoModesNetwork network, IAgentId actorId, IAgentId knowledgeId, KnowledgeLevel level, float minimumKnowledge, + short timeToLive) + { + return new ActorKnowledge(network, actorId, knowledgeId, level, minimumKnowledge, timeToLive); + } /// /// Constructor based on the knowledge Id and the knowledge Level. /// KnowledgeBits is not yet initialized. diff --git a/SourceCode/Symu/Repository/Edges/ActorPortfolio.cs b/SourceCode/Symu/Repository/Edges/ActorPortfolio.cs deleted file mode 100644 index 46a2c24a..00000000 --- a/SourceCode/Symu/Repository/Edges/ActorPortfolio.cs +++ /dev/null @@ -1,30 +0,0 @@ -#region Licence - -// Description: SymuBiz - Symu -// 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 Symu.Common.Interfaces; -using Symu.OrgMod.Edges; -using Symu.OrgMod.Entities; - -#endregion - -namespace Symu.Repository.Edges -{ - /// - /// Define who is using a component or a product and how - /// - public class ActorPortfolio : ActorResource - { - public ActorPortfolio(IAgentId actorId, IAgentId resourceId, IResourceUsage resourceUsage, float weight) : base( - actorId, resourceId, resourceUsage, weight) - { - } - } -} \ No newline at end of file diff --git a/SourceCode/Symu/Repository/Entities/Belief.cs b/SourceCode/Symu/Repository/Entities/Belief.cs index 887b5d39..eeecc5b3 100644 --- a/SourceCode/Symu/Repository/Entities/Belief.cs +++ b/SourceCode/Symu/Repository/Entities/Belief.cs @@ -40,6 +40,25 @@ public Belief() { } + + public static Belief CreateInstance(GraphMetaNetwork metaNetwork, byte length, RandomGenerator model, + BeliefWeightLevel beliefWeightLevel) + { + return new Belief(metaNetwork, length, model, beliefWeightLevel); + } + + public static Belief CreateInstance(GraphMetaNetwork metaNetwork, byte length, RandomGenerator model, + BeliefWeightLevel beliefWeightLevel, string name) + { + return new Belief(metaNetwork, length, model, beliefWeightLevel, name); + } + + public static Belief CreateInstance(GraphMetaNetwork metaNetwork, IKnowledge knowledge, byte length, RandomGenerator model, + BeliefWeightLevel beliefWeightLevel) + { + return new Belief(metaNetwork, knowledge, length, model, beliefWeightLevel); + } + public Belief(GraphMetaNetwork metaNetwork, byte length, RandomGenerator model, BeliefWeightLevel beliefWeightLevel) : base(metaNetwork) { diff --git a/SourceCode/Symu/Repository/Entities/CyclicalEvent.cs b/SourceCode/Symu/Repository/Entities/CyclicalEvent.cs index d24544cc..a0ac97bf 100644 --- a/SourceCode/Symu/Repository/Entities/CyclicalEvent.cs +++ b/SourceCode/Symu/Repository/Entities/CyclicalEvent.cs @@ -24,6 +24,10 @@ public class CyclicalEvent : EventEntity public CyclicalEvent() { } + public static CyclicalEvent CreateInstance(GraphMetaNetwork metaNetwork) + { + return new CyclicalEvent(metaNetwork); + } public CyclicalEvent(GraphMetaNetwork metaNetwork) : base(metaNetwork) { diff --git a/SourceCode/Symu/Repository/Entities/Database.cs b/SourceCode/Symu/Repository/Entities/Database.cs index a1a81bd7..c544887c 100644 --- a/SourceCode/Symu/Repository/Entities/Database.cs +++ b/SourceCode/Symu/Repository/Entities/Database.cs @@ -51,6 +51,12 @@ public Database() CognitiveArchitecture = new CognitiveArchitecture(); } + public static Database CreateInstance(GraphMetaNetwork metaNetwork, MainOrganizationModels models, CommunicationTemplate medium, + byte classId) + { + return new Database(metaNetwork, models, medium, classId); + } + public Database(GraphMetaNetwork metaNetwork, MainOrganizationModels models, CommunicationTemplate medium, byte classId) : base(metaNetwork, classId) { diff --git a/SourceCode/Symu/Repository/Entities/EventEntity.cs b/SourceCode/Symu/Repository/Entities/EventEntity.cs index bff03d98..6cd3f234 100644 --- a/SourceCode/Symu/Repository/Entities/EventEntity.cs +++ b/SourceCode/Symu/Repository/Entities/EventEntity.cs @@ -29,7 +29,10 @@ public class EventEntity : OrgMod.Entities.EventEntity public EventEntity() { } - + public new static EventEntity CreateInstance(GraphMetaNetwork metaNetwork) + { + return new EventEntity(metaNetwork); + } public EventEntity(GraphMetaNetwork metaNetwork) : base(metaNetwork) { } diff --git a/SourceCode/Symu/Repository/Entities/Knowledge.cs b/SourceCode/Symu/Repository/Entities/Knowledge.cs index 4ae1f9dc..3899989b 100644 --- a/SourceCode/Symu/Repository/Entities/Knowledge.cs +++ b/SourceCode/Symu/Repository/Entities/Knowledge.cs @@ -33,6 +33,10 @@ public class Knowledge : KnowledgeEntity //IKnowledge public Knowledge() { } + public static Knowledge CreateInstance(GraphMetaNetwork metaNetwork, MainOrganizationModels models, string name, byte length) + { + return new Knowledge(metaNetwork, models, name, length); + } public Knowledge(GraphMetaNetwork metaNetwork, MainOrganizationModels models, string name, byte length) : base( metaNetwork, name) diff --git a/SourceCode/Symu/Repository/Entities/RandomEvent.cs b/SourceCode/Symu/Repository/Entities/RandomEvent.cs index ae4f0fb8..334dc0c5 100644 --- a/SourceCode/Symu/Repository/Entities/RandomEvent.cs +++ b/SourceCode/Symu/Repository/Entities/RandomEvent.cs @@ -28,7 +28,10 @@ public class RandomEvent : EventEntity public RandomEvent() { } - + public new static RandomEvent CreateInstance(GraphMetaNetwork metaNetwork) + { + return new RandomEvent(metaNetwork); + } public RandomEvent(GraphMetaNetwork metaNetwork) : base(metaNetwork) { } diff --git a/SourceCode/SymuTests/Classes/Agents/CognitiveAgentTests.cs b/SourceCode/SymuTests/Classes/Agents/CognitiveAgentTests.cs index 4c58cf0e..6dda23dd 100644 --- a/SourceCode/SymuTests/Classes/Agents/CognitiveAgentTests.cs +++ b/SourceCode/SymuTests/Classes/Agents/CognitiveAgentTests.cs @@ -120,7 +120,7 @@ public void HasEmailTest() Assert.IsFalse(_agent.HasEmail); var email = EmailEntity.CreateInstance(Environment.MainOrganization.MetaNetwork, MainOrganization.Models); var usage = new ResourceUsage(0); - _ = new ActorResource(Environment.MainOrganization.MetaNetwork.ActorResource, _agent.AgentId, email.EntityId, usage); + ActorResource.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorResource, _agent.AgentId, email.EntityId, usage); _agent.EmailId = email.EntityId; Assert.IsTrue(_agent.HasEmail); Assert.IsNotNull(_agent.Email); @@ -270,7 +270,7 @@ private void SetExpertise(KnowledgeBits bit0S) { _agent.Cognitive.KnowledgeAndBeliefs.HasKnowledge = true; var knowledge = new Knowledge(Environment.MainOrganization.MetaNetwork, MainOrganization.Models, "1", 1); - _ = new ActorKnowledge(Environment.MainOrganization.MetaNetwork.ActorKnowledge, _agent.AgentId, knowledge.EntityId, bit0S); + ActorKnowledge.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorKnowledge, _agent.AgentId, knowledge.EntityId, bit0S); } #endregion @@ -832,7 +832,7 @@ public void AcceptNewInteractionTest() public void AcceptNewInteractionTest1() { _agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true; - _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, _agent2.AgentId); + ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, _agent2.AgentId); Assert.IsTrue(_agent.AcceptNewInteraction(_agent2.AgentId)); } @@ -958,7 +958,7 @@ public void GetAgentIdsForInteractionsTest1() [TestMethod] public void GetAgentIdsForInteractionsTest2() { - _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, _agent2.AgentId); + ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, _agent2.AgentId); Environment.MainOrganization.MetaNetwork.InteractionSphere.SetSphere(true, Environment.WhitePages.AllAgentIds().ToList(), Environment.MainOrganization.MetaNetwork); Assert.IsTrue(_agent.GetAgentIdsForInteractions(InteractionStrategy.Homophily).Any()); @@ -1358,9 +1358,9 @@ public void TryRecoverBlockerIncompleteKnowledgeTest() var teammate = AddAgent(); var group = TestCognitiveAgent.CreateInstance(2, Environment); group.Start(); - _ = new ActorOrganization(Environment.MainOrganization.MetaNetwork.ActorOrganization, _agent.AgentId, group.AgentId); - _ = new ActorOrganization(Environment.MainOrganization.MetaNetwork.ActorOrganization, teammate.AgentId, group.AgentId); - _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, teammate.AgentId); + ActorOrganization.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorOrganization, _agent.AgentId, group.AgentId); + ActorOrganization.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorOrganization, teammate.AgentId, group.AgentId); + ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, _agent.AgentId, teammate.AgentId); teammate.KnowledgeModel.AddKnowledge(_knowledge.EntityId, KnowledgeLevel.FullKnowledge, 0, -1); teammate.KnowledgeModel.InitializeExpertise(0); _agent.KnowledgeModel.SetKnowledge(_knowledge.EntityId, 0, 1, 0); @@ -1581,7 +1581,7 @@ public void TryRecoverBlockerIncompleteBeliefTest1() { var knowledge2 = new Knowledge(Environment.MainOrganization.MetaNetwork, Environment.MainOrganization.Models, "2", 1); - _ = new Belief(Environment.MainOrganization.MetaNetwork, knowledge2, knowledge2.Length, + Belief.CreateInstance(Environment.MainOrganization.MetaNetwork, knowledge2, knowledge2.Length, MainOrganization.Models.Generator, MainOrganization.Models.BeliefWeightLevel); MainOrganization.Murphies.IncompleteBelief.On = true; diff --git a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/BeliefsModelTests.cs b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/BeliefsModelTests.cs index 62fda1d6..8dc7570e 100644 --- a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/BeliefsModelTests.cs +++ b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/BeliefsModelTests.cs @@ -103,7 +103,7 @@ public void AddBeliefsTest2() { _cognitiveArchitecture.KnowledgeAndBeliefs.HasBelief = true; var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {0}, 0, -1); - _ = new Belief(Network, _knowledge, _knowledge.Length, RandomGenerator.RandomUniform, + Belief.CreateInstance(Network, _knowledge, _knowledge.Length, RandomGenerator.RandomUniform, BeliefWeightLevel.RandomWeight); var expertise = new List {actorKnowledge}; _beliefsModel.AddBeliefsFromKnowledge(expertise); diff --git a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/ForgettingModelTests.cs b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/ForgettingModelTests.cs index 02b9676e..701ad6e2 100644 --- a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/ForgettingModelTests.cs +++ b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/ForgettingModelTests.cs @@ -175,8 +175,7 @@ public void InitializeForgettingProcessTest1() { InitializeModel(true, 0); _forgettingModel.InternalCharacteristics.ForgettingMean = 1; - var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {0}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + ActorKnowledge.CreateInstance(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {0}, 0, -1); _forgettingModel.InitializeForgettingProcess(); Assert.AreEqual(1, _forgettingModel.ForgettingExpertise.Count); } @@ -190,8 +189,7 @@ public void FinalizeForgettingProcessTest() InitializeModel(true, 0); _forgettingModel.InternalCharacteristics.ForgettingMean = 0; _forgettingModel.InternalCharacteristics.PartialForgettingRate = 1; - var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {1}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + var actorKnowledge = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {1}, 0, -1); _forgettingModel.InitializeForgettingProcess(); _forgettingModel.FinalizeForgettingProcess(0); Assert.AreEqual(1, actorKnowledge.GetKnowledgeSum()); @@ -203,8 +201,7 @@ public void FinalizeForgettingProcessTest() [TestMethod] public void FinalizeForgettingProcessTest1() { - var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {1}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + var actorKnowledge = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {1}, 0, -1); InitializeModel(true, 0); _forgettingModel.InternalCharacteristics.ForgettingMean = 1; // ForgettingRate < minimumRemainingLevel @@ -336,8 +333,7 @@ public void UpdateForgettingKnowledgeTest1() [TestMethod] public void FinalizeForgettingKnowledgeTest() { - var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {1}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + var actorKnowledge = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {1}, 0, -1); InitializeModel(true, 0); // ForgettingBits value > minimumRemainingLevel var forgettingBits = new[] {0.1F}; diff --git a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/KnowledgeModelTests.cs b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/KnowledgeModelTests.cs index e95b7718..605be7f7 100644 --- a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/KnowledgeModelTests.cs +++ b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/KnowledgeModelTests.cs @@ -370,7 +370,7 @@ public void HasTest() { float[] bits = {0, 1}; var knowledgeBits = new KnowledgeBits(bits, 0, -1); - _ = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, knowledgeBits); + ActorKnowledge.CreateInstance(Network.ActorKnowledge, _agentId, _knowledge.EntityId, knowledgeBits); Assert.IsFalse(_knowledgeModel.KnowsEnough(_knowledge.EntityId, 0, 0.1F, 0)); Assert.IsTrue(_knowledgeModel.KnowsEnough(_knowledge.EntityId, 1, 0.1F, 0)); } diff --git a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/LearningModelTests.cs b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/LearningModelTests.cs index 29a44268..5cb7cf64 100644 --- a/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/LearningModelTests.cs +++ b/SourceCode/SymuTests/Classes/Agents/Models/CognitiveModels/LearningModelTests.cs @@ -38,8 +38,7 @@ public void Initialize() { _knowledge = new Knowledge(Network, MainOrganization.Models, "1", 1); InitializeModel(0, true); - _actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {0, 0}, 0, -1); - Network.ActorKnowledge.Add(_actorKnowledge); + _actorKnowledge = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {0, 0}, 0, -1); } public void InitializeModel(RandomLevel randomLevelLevel, bool modelOn) @@ -60,8 +59,7 @@ public void InitializeModel(RandomLevel randomLevelLevel, bool modelOn) public void LearnByDoingTest0() { _learningModel.On = false; - var actorKnowledge = new ActorKnowledge(_agentId, _knowledge.EntityId, new float[] {0}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + var actorKnowledge = new ActorKnowledge(Network.ActorKnowledge, _agentId, _knowledge.EntityId, new float[] {0}, 0, -1); var realLearning = _learningModel.LearnByDoing(_knowledge.EntityId, 0, 0, -1, 0); Assert.AreEqual(0, actorKnowledge.GetKnowledgeSum()); Assert.AreEqual(0, realLearning); diff --git a/SourceCode/SymuTests/Classes/Murphies/MurphyIncompleteKnowledgeTests.cs b/SourceCode/SymuTests/Classes/Murphies/MurphyIncompleteKnowledgeTests.cs index dc392516..fe13b366 100644 --- a/SourceCode/SymuTests/Classes/Murphies/MurphyIncompleteKnowledgeTests.cs +++ b/SourceCode/SymuTests/Classes/Murphies/MurphyIncompleteKnowledgeTests.cs @@ -104,8 +104,7 @@ public void CheckKnowledgeTest1() byte mandatoryIndex = 0; byte requiredIndex = 0; _murphy.On = true; - var actorKnowledge = new ActorKnowledge(Uid1, _knowledge.EntityId, new float[] {0}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + ActorKnowledge.CreateInstance(Network.ActorKnowledge, Uid1, _knowledge.EntityId, new float[] {0}, 0, -1); _murphy.CheckKnowledge(_knowledge.EntityId, _taskBits, _knowledgeModel, ref mandatoryCheck, ref requiredCheck, ref mandatoryIndex, ref requiredIndex, 0); @@ -123,8 +122,7 @@ public void CheckKnowledgeTest2() byte mandatoryIndex = 0; byte requiredIndex = 0; _murphy.On = true; - var actorKnowledge = new ActorKnowledge(Uid1, _knowledge.EntityId, new float[] {1}, 0, -1); - Network.ActorKnowledge.Add(actorKnowledge); + ActorKnowledge.CreateInstance(Network.ActorKnowledge, Uid1, _knowledge.EntityId, new float[] {1}, 0, -1); _murphy.CheckKnowledge(_knowledge.EntityId, _taskBits, _knowledgeModel, ref mandatoryCheck, ref requiredCheck, ref mandatoryIndex, ref requiredIndex, 0); diff --git a/SourceCode/SymuTests/Repository/Entities/PortfolioTests.cs b/SourceCode/SymuTests/Repository/Entities/PortfolioTests.cs deleted file mode 100644 index f435070f..00000000 --- a/SourceCode/SymuTests/Repository/Entities/PortfolioTests.cs +++ /dev/null @@ -1,37 +0,0 @@ -#region Licence - -// Description: SymuBiz - SymuTests -// 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 Microsoft.VisualStudio.TestTools.UnitTesting; -using Symu.Common.Interfaces; -using Symu.OrgMod.Entities; -using Symu.Repository.Edges; - -#endregion - -namespace SymuTests.Repository.Entities -{ - [TestClass] - public class PortfolioTests - { - private readonly IAgentId _agentId = new AgentId(1, 1); - private readonly IResourceUsage _isSupportOn = new ResourceUsage(2); - private readonly IResourceUsage _isUsing = new ResourceUsage(3); - private readonly IAgentId _resourceId = new AgentId(1, 0); - - [TestMethod] - public void EqualsTest() - { - var portfolio = new ActorPortfolio(_agentId, _resourceId, _isSupportOn, 100); - Assert.IsTrue(portfolio.Equals(_isSupportOn)); - Assert.IsFalse(portfolio.Equals(_isUsing)); - } - } -} \ No newline at end of file diff --git a/SourceCode/SymuTests/Results/Organization/organizationFlexibilityTests.cs b/SourceCode/SymuTests/Results/Organization/organizationFlexibilityTests.cs index 6cb42c60..c821beef 100644 --- a/SourceCode/SymuTests/Results/Organization/organizationFlexibilityTests.cs +++ b/SourceCode/SymuTests/Results/Organization/organizationFlexibilityTests.cs @@ -84,7 +84,7 @@ private void SetAgents(int count) for (var j = i + 1; j < count; j++) { var agentId2 = agentIds[j]; - _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, agentId1, agentId2); + ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, agentId1, agentId2); } } diff --git a/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleEnvironment.cs b/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleEnvironment.cs index 26edbb39..0978f5cb 100644 --- a/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleEnvironment.cs @@ -56,7 +56,7 @@ public override void SetAgents() { for (var j = i + 1; j < actorIds.Count; j++) { - _ = new ActorActor(MainOrganization.MetaNetwork.ActorActor, actorIds[i], actorIds[j]); + ActorActor.CreateInstance(MainOrganization.MetaNetwork.ActorActor, actorIds[i], actorIds[j]); } } } diff --git a/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleOrganization.cs b/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleOrganization.cs index 8b0dac3c..2fb0c65f 100644 --- a/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleOrganization.cs +++ b/Symu examples/SymuBeliefsAndInfluence/Classes/ExampleOrganization.cs @@ -75,7 +75,7 @@ public void AddBeliefs() for (var i = 0; i < BeliefCount; i++) { // knowledge length of 10 is arbitrary in this example - _ = new Knowledge(MetaNetwork, Models, i.ToString(), 10); + Knowledge.CreateInstance(MetaNetwork, Models, i.ToString(), 10); } } } diff --git a/Symu examples/SymuExamplesTests/SymuLearnAndForgetTests.cs b/Symu examples/SymuExamplesTests/SymuLearnAndForgetTests.cs index 92d1c1a3..63799b0f 100644 --- a/Symu examples/SymuExamplesTests/SymuLearnAndForgetTests.cs +++ b/Symu examples/SymuExamplesTests/SymuLearnAndForgetTests.cs @@ -36,7 +36,7 @@ public class SymuLearnAndForgetTests [TestInitialize] public void Initialize() { - _ = new Knowledge(_mainOrganization.MetaNetwork, _mainOrganization.Models, "1", 50); + Knowledge.CreateInstance(_mainOrganization.MetaNetwork, _mainOrganization.Models, "1", 50); _environment.SetOrganization(_mainOrganization); _simulation.SetEnvironment(_environment); _environment.SetDebug(true); diff --git a/Symu examples/SymuGroupAndInteraction/Classes/ExampleOrganization.cs b/Symu examples/SymuGroupAndInteraction/Classes/ExampleOrganization.cs index 20705e8d..edbfeca3 100644 --- a/Symu examples/SymuGroupAndInteraction/Classes/ExampleOrganization.cs +++ b/Symu examples/SymuGroupAndInteraction/Classes/ExampleOrganization.cs @@ -53,7 +53,7 @@ public void AddKnowledge() for (ushort i = 0; i < GroupsCount; i++) { // knowledge length of 10 is arbitrary in this example - _ = new Knowledge(MetaNetwork, Models, i.ToString(), 10); + Symu.Repository.Entities.Knowledge.CreateInstance(MetaNetwork, Models, i.ToString(), 10); //Beliefs are created based on knowledge } } @@ -65,7 +65,7 @@ public void AddTasks() { for (ushort i = 0; i < GroupsCount; i++) { - _ = new TaskEntity(MetaNetwork); + TaskEntity.CreateInstance(MetaNetwork); } } } diff --git a/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs b/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs index f4735138..c75f5cd7 100644 --- a/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs +++ b/Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs @@ -61,10 +61,10 @@ public void AddPerson(PersonAgent newPerson) // this new person is member of the group newPerson.GroupId = AgentId; - _ = new ActorOrganization(Environment.MainOrganization.MetaNetwork.ActorOrganization, newPerson.AgentId, AgentId); + ActorOrganization.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorOrganization, newPerson.AgentId, AgentId); // All the members of this group have interactions var actorIds = Environment.MainOrganization.MetaNetwork.ActorOrganization.SourcesFilteredByTarget(AgentId).ToList(); - actorIds.ForEach(actorId => _ = new ActorActor(Environment.MainOrganization.MetaNetwork.ActorActor, actorId, newPerson.AgentId)); + actorIds.ForEach(actorId => ActorActor.CreateInstance(Environment.MainOrganization.MetaNetwork.ActorActor, actorId, newPerson.AgentId)); } } } \ No newline at end of file diff --git a/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs b/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs index a9db6f75..39fd96ef 100644 --- a/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs @@ -47,7 +47,7 @@ public override void SetAgents() DoesNotLearnAgent = LearnAgent.CreateInstance(this, MainOrganization.Templates.Human); ExpertAgent = ExpertAgent.CreateInstance(this, MainOrganization.Templates.Human); // Active link between expert and LearnByAskingAgent to be able to exchange information - _ = new ActorActor(MainOrganization.MetaNetwork.ActorActor, LearnByAskingAgent.AgentId, ExpertAgent.AgentId); + ActorActor.CreateInstance(MainOrganization.MetaNetwork.ActorActor, LearnByAskingAgent.AgentId, ExpertAgent.AgentId); } } } \ No newline at end of file diff --git a/Symu examples/SymuLearnAndForget/Home.cs b/Symu examples/SymuLearnAndForget/Home.cs index 85eeb02d..59afc353 100644 --- a/Symu examples/SymuLearnAndForget/Home.cs +++ b/Symu examples/SymuLearnAndForget/Home.cs @@ -584,7 +584,7 @@ private void tbKnowledgeLength_TextChanged(object sender, EventArgs e) throw new ArgumentOutOfRangeException("Knowledge should be < " + Bits.MaxBits); } - _ = new Knowledge(_mainOrganization.MetaNetwork, _mainOrganization.Models, "1", value); + Knowledge.CreateInstance(_mainOrganization.MetaNetwork, _mainOrganization.Models, "1", value); tbKnowledgeLength.BackColor = SystemColors.Window; } catch (FormatException) diff --git a/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs b/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs index 484acf41..bedb427b 100644 --- a/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuMessageAndTask/Classes/ExampleEnvironment.cs @@ -40,8 +40,8 @@ public override void SetAgents() var actor = PersonAgent.CreateInstance(this, MainOrganization.Templates.Human); actor.GroupId = group.AgentId; var email = EmailEntity.CreateInstance(MainOrganization.MetaNetwork, MainOrganization.Models); - _ = new ActorResource(MainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); - _ = new ActorOrganization(MainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, group.AgentId); + ActorResource.CreateInstance(MainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); + ActorOrganization.CreateInstance(MainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, group.AgentId); } } } diff --git a/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleEnvironment.cs b/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleEnvironment.cs index 48aa1ad9..7649d769 100644 --- a/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleEnvironment.cs @@ -47,8 +47,8 @@ public override void SetAgents() var actor = PersonAgent.CreateInstance(this, ExampleMainOrganization.Templates.Human); actor.GroupId = group.AgentId; var email = EmailEntity.CreateInstance(ExampleMainOrganization.MetaNetwork, MainOrganization.Models); - _ = new ActorResource(ExampleMainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); - _ = new ActorOrganization(ExampleMainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, group.AgentId); + ActorResource.CreateInstance(ExampleMainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); + ActorOrganization.CreateInstance(ExampleMainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, group.AgentId); } } } diff --git a/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleOrganization.cs b/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleOrganization.cs index b1f1e6ab..073ba7be 100644 --- a/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleOrganization.cs +++ b/Symu examples/SymuMurphiesAndBlockers/Classes/ExampleOrganization.cs @@ -58,7 +58,7 @@ public void AddKnowledge() for (var i = 0; i < KnowledgeCount; i++) { // knowledge length of 10 is arbitrary in this example - _ = new Knowledge(MetaNetwork, Models, i.ToString(), 10); + Knowledge.CreateInstance(MetaNetwork, Models, i.ToString(), 10); } } } diff --git a/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs b/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs index 67c2b6c2..a48f31c3 100644 --- a/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs @@ -55,8 +55,8 @@ private PersonAgent AddPersonAgent() var actor = PersonAgent.CreateInstance(this, ExampleMainOrganization.Templates.Human); actor.GroupId = _groupId; var email = EmailEntity.CreateInstance(ExampleMainOrganization.MetaNetwork, MainOrganization.Models); - _ = new ActorResource(ExampleMainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); - _ = new ActorOrganization(ExampleMainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, _groupId); + ActorResource.CreateInstance(ExampleMainOrganization.MetaNetwork.ActorResource, actor.AgentId, email.EntityId, new ResourceUsage(0)); + ActorOrganization.CreateInstance(ExampleMainOrganization.MetaNetwork.ActorOrganization, actor.AgentId, _groupId); return actor; } diff --git a/Symu examples/SymuScenariosAndEvents/Classes/ExampleOrganization.cs b/Symu examples/SymuScenariosAndEvents/Classes/ExampleOrganization.cs index abc66bbf..111ed79d 100644 --- a/Symu examples/SymuScenariosAndEvents/Classes/ExampleOrganization.cs +++ b/Symu examples/SymuScenariosAndEvents/Classes/ExampleOrganization.cs @@ -45,7 +45,7 @@ public void AddKnowledge() for (var i = 0; i < KnowledgeCount; i++) { // knowledge length of 10 is arbitrary in this example - _ = new Knowledge(MetaNetwork, Models, i.ToString(), 10); + Knowledge.CreateInstance(MetaNetwork, Models, i.ToString(), 10); } } }