diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c064542..20666fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ ## Unreleased +## 0.7.0 [☰](https://github.com/lmorisse/symu/compare/v0.7.0..v0.6.0) * Renaming namespaces by [lmorisse](https://github.com/lmorisse) * Update SymuForm, IterationResult for multiple iterations by [lmorisse](https://github.com/lmorisse) -* Add new project example: [SymuScenariosAndMonteCarlo](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuScenariosAndMonteCarlo) by [lmorisse](https://github.com/lmorisse) -* Add new project example: [SymuScenariosAndMonteCarloTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuScenariosAndMonteCarloTests) by [lmorisse](https://github.com/lmorisse) +* Add new project example: [SymuScenariosAndEvents](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuScenariosAndEvents) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuScenariosAndEventsTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuScenariosAndEventsTests) by [lmorisse](https://github.com/lmorisse) ## 0.6.0 [☰](https://github.com/lmorisse/symu/compare/v0.6.0..v0.5.0) @@ -14,26 +15,26 @@ * Refactoring Murphies by [lmorisse](https://github.com/lmorisse) * Add Agent.TimeSpent by [lmorisse](https://github.com/lmorisse) * Add new project example: [SymuMurphiesAndBlockers](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMurphiesAndBlockers) by [lmorisse](https://github.com/lmorisse) -* Add new project example: [SymuMurphiesAndBlockersTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMurphiesAndBlockersTests) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuMurphiesAndBlockersTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMurphiesAndBlockersTests) by [lmorisse](https://github.com/lmorisse) ## 0.5.0 [☰](https://github.com/lmorisse/symu/compare/v0.5.0..v0.4.0) * Add new models : knowledge, Beliefs, Influence by [lmorisse](https://github.com/lmorisse) * Add SymuTask.SetKnowledgesBits by [lmorisse](https://github.com/lmorisse) * Refactoring NetworkBeliefs by [lmorisse](https://github.com/lmorisse) * Add new project example: [SymuGroupAndInteraction](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuBeliefsAndInfluence) by [lmorisse](https://github.com/lmorisse) -* Add new project example: [SymuGroupAndInteractionTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuBeliefsAndInfluenceTests) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuGroupAndInteractionTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuBeliefsAndInfluenceTests) by [lmorisse](https://github.com/lmorisse) ## 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](https://github.com/lmorisse) -* Add new project example: [SymuGroupAndInteractionTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuGroupAndInteractionTests) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuGroupAndInteractionTests](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuGroupAndInteractionTests) by [lmorisse](https://github.com/lmorisse) * SymuEngine - add InteractionSphereModel by [lmorisse](https://github.com/lmorisse) * SymuEngine - update InteractionPatterns by [lmorisse](https://github.com/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](https://github.com/lmorisse) -* Add new project example: [SymuMessageAndTaskTest](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMessageAndTaskTests) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuMessageAndTaskTest](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMessageAndTaskTests) by [lmorisse](https://github.com/lmorisse) * SymuEngine - delete EnvironmentEntity => OrganizationModels by [lmorisse](https://github.com/lmorisse) ## 0.2.0 [☰](https://github.com/lmorisse/symu/compare/v0.2.0..v0.1.0) * Add new project example: [SymuLearnAndForget](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuLearnAndForget) by [lmorisse](https://github.com/lmorisse) -* Add new project example: [SymuLearnAndForgetTest](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuLearnAndForgetTests) by [lmorisse](https://github.com/lmorisse) +* Add new project test: [SymuLearnAndForgetTest](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuLearnAndForgetTests) by [lmorisse](https://github.com/lmorisse) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 64b275f2..e460d23c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,8 @@ # Release notes +## 0.7.0 +This release contains a new project example: [SymuScenariosAndEvents](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuScenariosAndEvents). + ## 0.6.0 This release contains a new project example: [SymuMurphiesAndBlockers](https://github.com/lmorisse/Symu/tree/master/Symu%20examples/SymuMurphiesAndBlockers). diff --git a/Symu examples/SymuBeliefsAndInfluence/Home.cs b/Symu examples/SymuBeliefsAndInfluence/Home.cs index 3b5f3b31..c5f46e20 100644 --- a/Symu examples/SymuBeliefsAndInfluence/Home.cs +++ b/Symu examples/SymuBeliefsAndInfluence/Home.cs @@ -16,7 +16,6 @@ using System.Linq; using System.Windows.Forms; using Symu.Classes.Scenario; -using Symu.Common; using Symu.Environment; using Symu.Forms; using Symu.Repository.Networks.Beliefs; @@ -454,7 +453,9 @@ private void BeliefsRateOfAgentsOn_TextChanged(object sender, EventArgs e) MessageBox.Show(exception.Message); } } + #region Menu + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://symu.org"); @@ -474,6 +475,7 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("http://github.symu.org/issues"); } + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs b/Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs index e502dd65..403cd7be 100644 --- a/Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs +++ b/Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs @@ -15,8 +15,8 @@ using Symu.Classes.Scenario; using Symu.Engine; using Symu.Repository.Networks.Beliefs; -using SymuBeliefsAndInfluence.Classes; using Symu.Tools; +using SymuBeliefsAndInfluence.Classes; #endregion diff --git a/Symu examples/SymuExamples.sln b/Symu examples/SymuExamples.sln index a18cd68f..59fc9c56 100644 --- a/Symu examples/SymuExamples.sln +++ b/Symu examples/SymuExamples.sln @@ -23,9 +23,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SymuMurphiesAndBlockers", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SymuMurphiesAndBlockersTests", "SymuMurphiesAndBlockersTests\SymuMurphiesAndBlockersTests.csproj", "{979382EC-EC34-4284-9E6A-018A40CA82F1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SymuScenariosAndMonteCarlo", "SymuScenariosAndMonteCarlo\SymuScenariosAndMonteCarlo.csproj", "{5E1F9690-2B9C-4354-9AD7-9D9CD873965B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SymuScenariosAndEvents", "SymuScenariosAndEvents\SymuScenariosAndEvents.csproj", "{5E1F9690-2B9C-4354-9AD7-9D9CD873965B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SymuScenariosAndMonteCarloTests", "SymuScenariosAndMonteCarloTests\SymuScenariosAndMonteCarloTests.csproj", "{35B38D26-104A-45AC-A13B-EAD8F4CC088A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SymuScenariosAndEventsTests", "SymuScenariosAndEventsTests\SymuScenariosAndEventsTests.csproj", "{1117A229-1A21-477D-A580-AAB984884F92}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests projects", "Tests projects", "{CDF38E4B-8B2A-4110-8404-3DB5F276940D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -77,14 +79,22 @@ Global {5E1F9690-2B9C-4354-9AD7-9D9CD873965B}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E1F9690-2B9C-4354-9AD7-9D9CD873965B}.Release|Any CPU.ActiveCfg = Release|Any CPU {5E1F9690-2B9C-4354-9AD7-9D9CD873965B}.Release|Any CPU.Build.0 = Release|Any CPU - {35B38D26-104A-45AC-A13B-EAD8F4CC088A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {35B38D26-104A-45AC-A13B-EAD8F4CC088A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {35B38D26-104A-45AC-A13B-EAD8F4CC088A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {35B38D26-104A-45AC-A13B-EAD8F4CC088A}.Release|Any CPU.Build.0 = Release|Any CPU + {1117A229-1A21-477D-A580-AAB984884F92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1117A229-1A21-477D-A580-AAB984884F92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1117A229-1A21-477D-A580-AAB984884F92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1117A229-1A21-477D-A580-AAB984884F92}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {03DD3D3E-58EA-47C9-8AE3-B35D0E3DE5DB} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + {4A229EF5-31C6-4B55-902A-9FAFDE901595} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + {CBAC9A57-6A83-4F7B-8254-BE452BDE5468} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + {49C4CE6F-AA8D-46D0-AB88-C3E3D754606A} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + {979382EC-EC34-4284-9E6A-018A40CA82F1} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + {1117A229-1A21-477D-A580-AAB984884F92} = {CDF38E4B-8B2A-4110-8404-3DB5F276940D} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F00944D1-83EF-4E6C-BDD2-784EC80CE225} EndGlobalSection diff --git a/Symu examples/SymuGroupAndInteraction/Home.cs b/Symu examples/SymuGroupAndInteraction/Home.cs index 839d85f7..4f506fb8 100644 --- a/Symu examples/SymuGroupAndInteraction/Home.cs +++ b/Symu examples/SymuGroupAndInteraction/Home.cs @@ -17,7 +17,6 @@ using System.Windows.Forms; using Symu.Classes.Agents.Models.CognitiveModel; using Symu.Classes.Scenario; -using Symu.Common; using Symu.Environment; using Symu.Forms; using Symu.Repository.Networks.Knowledges; @@ -489,7 +488,9 @@ private void Homophily_CheckedChanged(object sender, EventArgs e) InteractionKnowledge.Text = "0"; InteractionSocialDemographics.Text = "0"; } + #region Menu + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://symu.org"); @@ -509,6 +510,7 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("http://github.symu.org/issues"); } + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuLearnAndForget/Home.cs b/Symu examples/SymuLearnAndForget/Home.cs index 98734c24..268c07d4 100644 --- a/Symu examples/SymuLearnAndForget/Home.cs +++ b/Symu examples/SymuLearnAndForget/Home.cs @@ -299,7 +299,6 @@ private void button3_Click(object sender, EventArgs e) private void DisplayButtons() { - DisplayButtons(btnStart, btnStop, btnPause, btnResume); } @@ -618,6 +617,7 @@ private void tbSteps_TextChanged(object sender, EventArgs e) } #region Menu + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://symu.org"); @@ -637,6 +637,7 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("http://github.symu.org/issues"); } + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuMessageAndTask/Home.cs b/Symu examples/SymuMessageAndTask/Home.cs index 83637193..8322c7cf 100644 --- a/Symu examples/SymuMessageAndTask/Home.cs +++ b/Symu examples/SymuMessageAndTask/Home.cs @@ -210,7 +210,6 @@ private void button3_Click(object sender, EventArgs e) private void DisplayButtons() { - DisplayButtons(btnStart, btnStop, btnPause, btnResume); } @@ -391,6 +390,7 @@ private void tbWorkers_TextChanged(object sender, EventArgs e) #region Menu + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://symu.org"); @@ -410,6 +410,7 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("http://github.symu.org/issues"); } + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuMurphiesAndBlockers/Home.cs b/Symu examples/SymuMurphiesAndBlockers/Home.cs index 1aee39e5..3338555d 100644 --- a/Symu examples/SymuMurphiesAndBlockers/Home.cs +++ b/Symu examples/SymuMurphiesAndBlockers/Home.cs @@ -15,7 +15,6 @@ using System.Globalization; using System.Windows.Forms; using Symu.Classes.Scenario; -using Symu.Common; using Symu.Environment; using Symu.Forms; using Symu.Messaging.Messages; @@ -182,7 +181,8 @@ protected override void UpdateSettings() OrganizationEntity.Models.Learning.On = EmailSearching.Checked; - OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = EmailComm.Checked ? CommunicationMediums.Email : CommunicationMediums.FaceToFace; + OrganizationEntity.Templates.Human.Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = + EmailComm.Checked ? CommunicationMediums.Email : CommunicationMediums.FaceToFace; var scenario = new TimeBasedScenario(_environment) @@ -810,6 +810,7 @@ private void InformationLimitOfTries_CheckedChanged(object sender, EventArgs e) } #region Menu + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("https://symu.org"); @@ -829,6 +830,7 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e) { Process.Start("http://github.symu.org/issues"); } + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuMurphiesAndBlockersTests/IntegrationTests.cs b/Symu examples/SymuMurphiesAndBlockersTests/IntegrationTests.cs index ea3745c8..e923da7b 100644 --- a/Symu examples/SymuMurphiesAndBlockersTests/IntegrationTests.cs +++ b/Symu examples/SymuMurphiesAndBlockersTests/IntegrationTests.cs @@ -16,8 +16,8 @@ using Symu.Messaging.Messages; using Symu.Repository.Networks.Beliefs; using Symu.Repository.Networks.Knowledges; -using SymuMurphiesAndBlockers.Classes; using Symu.Tools; +using SymuMurphiesAndBlockers.Classes; #endregion diff --git a/Symu examples/SymuScenariosAndEvents/ChartAppearance.cs b/Symu examples/SymuScenariosAndEvents/ChartAppearance.cs index 31f85140..da82bc0c 100644 --- a/Symu examples/SymuScenariosAndEvents/ChartAppearance.cs +++ b/Symu examples/SymuScenariosAndEvents/ChartAppearance.cs @@ -1,15 +1,21 @@ -#region Copyright Syncfusion Inc. 2001-2020. -// Copyright Syncfusion Inc. 2001-2020. All rights reserved. -// Use of this code is subject to the terms of our license. -// A copy of the current license can be obtained at any time by e-mailing -// licensing@syncfusion.com. Any infringement will be prosecuted under -// applicable laws. +#region Licence + +// Description: Symu - SymuScenariosAndEvents +// 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.Drawing.Drawing2D; using Syncfusion.Windows.Forms.Chart; +#endregion + namespace SymuScenariosAndEvents { public static class ChartAppearance @@ -26,7 +32,7 @@ public static void ApplyChartStyles(ChartControl chart) chart.Skins = Skins.Metro; chart.BorderAppearance.SkinStyle = ChartBorderSkinStyle.None; chart.BorderAppearance.FrameThickness = new ChartThickness(-2, -2, 2, 2); - chart.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + chart.SmoothingMode = SmoothingMode.AntiAlias; chart.ChartArea.PrimaryXAxis.HidePartialLabels = true; chart.ElementsSpacing = 5; @@ -40,6 +46,7 @@ public static void ApplyChartStyles(ChartControl chart) { return; } + var max = chart.Series[0].Points[0].YValues[0]; for (var i = 0; i < chart.Series.Count; i++) { @@ -48,6 +55,7 @@ public static void ApplyChartStyles(ChartControl chart) max = Math.Max(max, chart.Series[i].Points[j].YValues[0]); } } + chart.PrimaryYAxis.Range = new MinMaxInfo(0, max + 1, Math.Round(max / 10)); var min = chart.Series[0].Points[0].X; max = min; @@ -59,7 +67,8 @@ public static void ApplyChartStyles(ChartControl chart) max = Math.Max(max, chart.Series[i].Points[j].X); } } - chart.PrimaryXAxis.Range = new MinMaxInfo(min-10, max+10, Math.Round((max-min)/10)); + + chart.PrimaryXAxis.Range = new MinMaxInfo(min - 10, max + 10, Math.Round((max - min) / 10)); chart.PrimaryXAxis.LabelRotate = true; chart.PrimaryXAxis.LabelRotateAngle = 270; @@ -67,8 +76,6 @@ public static void ApplyChartStyles(ChartControl chart) chart.Series[0].Style.Border.Color = Color.Transparent; #endregion - - } } -} +} \ No newline at end of file diff --git a/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs b/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs index 1828fad4..b28c3890 100644 --- a/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs +++ b/Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // 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,12 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; using Symu.Classes.Agents; using Symu.Classes.Agents.Models.Templates.Communication; using Symu.Classes.Organization; using Symu.Classes.Task; using Symu.Common; using Symu.Environment; -using Symu.Environment.Events; -using Symu.Messaging.Messages; using Symu.Repository.Networks.Knowledges; #endregion @@ -34,7 +31,7 @@ public class ExampleEnvironment : SymuEnvironment public List Knowledges { get; private set; } public MurphyTask Model => Organization.Murphies.IncompleteKnowledge; - + public override void SetOrganization(OrganizationEntity organization) { if (organization == null) @@ -45,6 +42,7 @@ public override void SetOrganization(OrganizationEntity organization) base.SetOrganization(organization); #region Template + organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasKnowledge = true; organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true; organization.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasBelief = true; @@ -56,11 +54,14 @@ public override void SetOrganization(OrganizationEntity organization) organization.Templates.Human.Cognitive.InteractionPatterns.IsolationIsRandom = false; organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true; + #endregion #region Results + IterationResult.Blockers.On = true; IterationResult.Tasks.On = true; + #endregion SetDebug(false); @@ -99,6 +100,7 @@ private void SetKnowledge(Agent actor, IReadOnlyList knowledges) actor.BeliefsModel.AddBelief(knowledges[i].Id); } } + private PersonAgent AddPersonAgent() { var actor = new PersonAgent(Organization.NextEntityIndex(), this) diff --git a/Symu examples/SymuScenariosAndEvents/Classes/GroupAgent.cs b/Symu examples/SymuScenariosAndEvents/Classes/GroupAgent.cs index 830b6766..87e1845e 100644 --- a/Symu examples/SymuScenariosAndEvents/Classes/GroupAgent.cs +++ b/Symu examples/SymuScenariosAndEvents/Classes/GroupAgent.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // 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/SymuScenariosAndEvents/Classes/PersonAgent.cs b/Symu examples/SymuScenariosAndEvents/Classes/PersonAgent.cs index bbba9770..69165a77 100644 --- a/Symu examples/SymuScenariosAndEvents/Classes/PersonAgent.cs +++ b/Symu examples/SymuScenariosAndEvents/Classes/PersonAgent.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -39,13 +39,13 @@ public PersonAgent(ushort agentKey, SymuEnvironment environment) : base( private MurphyTask Model => ((ExampleEnvironment) Environment).Model; public List Knowledges => ((ExampleEnvironment) Environment).Knowledges; - + public override void GetNewTasks() { var task = new SymuTask(Schedule.Step) { // Weight is randomly distributed around 1, but has a minimum of 0 - Weight = Math.Max(0,Normal.Sample(1,0.1F*Environment.Organization.Models.RandomLevelValue)), + Weight = Math.Max(0, Normal.Sample(1, 0.1F * Environment.Organization.Models.RandomLevelValue)), // Creator is randomly a person of the group - for the incomplete information murphy Creator = Environment.WhitePages.FilteredAgentIdsByClassKey(ClassKey).Shuffle().First() }; diff --git a/Symu examples/SymuScenariosAndEvents/Home.cs b/Symu examples/SymuScenariosAndEvents/Home.cs index 280311b1..bf819317 100644 --- a/Symu examples/SymuScenariosAndEvents/Home.cs +++ b/Symu examples/SymuScenariosAndEvents/Home.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // 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 System.Diagnostics; using System.Drawing; using System.Globalization; using System.Linq; @@ -45,6 +46,7 @@ private void LoadSettings() chartControl2.Series[0].PrepareStyle += Form1_PrepareStyle; #region Legend Customization + chartControl1.PrimaryXAxis.Title = "Step"; //chartControl1.PrimaryYAxis.Title = "Tasks"; chartControl1.Legend.Visible = true; @@ -55,12 +57,13 @@ private void LoadSettings() chartControl2.Title.Text = "Simulation (Monte Carlo)"; chartControl2.Title.Visible = true; chartControl2.DropSeriesPoints = true; + #endregion tbWorkers.Text = _environment.WorkersCount.ToString(CultureInfo.InvariantCulture); - } - void Form1_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args) + + private void Form1_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args) { var series = chartControl1.Series[0]; if (series == null) @@ -91,6 +94,7 @@ protected override void UpdateSettings() }; AddScenario(scenario); } + if (TaskBased.Checked) { var scenario = new TaskBasedScenario(_environment) @@ -99,6 +103,7 @@ protected override void UpdateSettings() }; AddScenario(scenario); } + if (MessageBased.Checked) { var scenario = new MessageBasedScenario(_environment) @@ -107,6 +112,7 @@ protected override void UpdateSettings() }; AddScenario(scenario); } + cbIterations.Items.Clear(); for (var i = 0; i < Iterations.Max; i++) { @@ -213,10 +219,10 @@ private void SetEvents() symuEvent = new SymuEvent {Step = eventStep}; break; case SymuEventType.Cyclical: - symuEvent = new CyclicalEvent {EveryStep = cyclicalStep }; + symuEvent = new CyclicalEvent {EveryStep = cyclicalStep}; break; case SymuEventType.Random: - symuEvent = new RandomEvent {Ratio = randomRatio }; + symuEvent = new RandomEvent {Ratio = randomRatio}; break; default: throw new ArgumentOutOfRangeException(); @@ -253,7 +259,7 @@ private ushort SetCyclicalStep() private float SetRandomRatio() { - float randomRatio=0; + float randomRatio = 0; try { randomRatio = float.Parse(RandomRatio.Text); @@ -323,12 +329,13 @@ public override void DisplayIteration() var tasksResults = SimulationResults.List.Select(x => x.Tasks.Done).ToList(); var capacityResults = SimulationResults.List.Select(x => x.Capacity).ToList(); - var seriesTasks = new ChartSeries("tasks", ChartSeriesType.Histogram) ; + var seriesTasks = new ChartSeries("tasks", ChartSeriesType.Histogram); var count = Math.Max(tasksResults.Count, capacityResults.Count); foreach (var tasksResult in tasksResults) { seriesTasks.Points.Add(tasksResult, count); } + seriesTasks.Text = seriesTasks.Name; seriesTasks.ConfigItems.HistogramItem.NumberOfIntervals = 10; //seriesTasks.ConfigItems.HistogramItem.ShowNormalDistribution = true; @@ -339,13 +346,14 @@ public override void DisplayIteration() { seriesCapacity.Points.Add(capacityResult, count); } + seriesCapacity.Text = seriesCapacity.Name; seriesCapacity.ConfigItems.HistogramItem.NumberOfIntervals = 10; //seriesCapacity.ConfigItems.HistogramItem.ShowNormalDistribution = true; //seriesCapacity.ConfigItems.HistogramItem.ShowDataPoints = true; - WriteChartSafe(chartControl2, new[] { seriesTasks, seriesCapacity }); - + WriteChartSafe(chartControl2, new[] {seriesTasks, seriesCapacity}); } + protected void WriteChartSafe(ChartControl chartControl, ChartSeries[] chartSeries) { if (chartControl is null) @@ -370,6 +378,7 @@ protected void WriteChartSafe(ChartControl chartControl, ChartSeries[] chartSeri { chartControl.Series.Add(chartSerie); } + ChartAppearance.ApplyChartStyles(chartControl); } } @@ -386,7 +395,7 @@ private void button3_Click(object sender, EventArgs e) private void DisplayButtons() { - DisplayButtons(btnStart,btnStop, btnPause, btnResume); + DisplayButtons(btnStart, btnStop, btnPause, btnResume); } protected override void PostProcess() @@ -419,58 +428,61 @@ private void tbWorkers_TextChanged(object sender, EventArgs e) } } - #region Menu - - private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start("https://symu.org"); - } - - private void documentationToolStripMenuItem1_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start("http://docs.symu.org/"); - } - - private void sourceCodeToolStripMenuItem1_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start("http://github.symu.org/"); - } - - private void issuesToolStripMenuItem_Click(object sender, EventArgs e) - { - System.Diagnostics.Process.Start("http://github.symu.org/issues"); - } - - #endregion - - #region Nested type: SafeCallButtonDelegate - - protected delegate void SafeCallChartDelegate(ChartControl chartControl, ChartSeries[] chartSeries); - - #endregion - private void cbIterations_SelectedIndexChanged(object sender, EventArgs e) { - var index = (int)cbIterations.SelectedItem; - var seriesTasks = new ChartSeries { Name = "Tasks" }; + var index = (int) cbIterations.SelectedItem; + var seriesTasks = new ChartSeries {Name = "Tasks"}; if (SimulationResults.Count == 0) { return; } + foreach (var tasksResult in SimulationResults[index].Tasks.Results) { seriesTasks.Points.Add(tasksResult.Key, tasksResult.Value.Done); } + seriesTasks.Type = ChartSeriesType.Column; seriesTasks.Text = seriesTasks.Name; - var seriesBlockers = new ChartSeries { Name = "Blockers" }; + var seriesBlockers = new ChartSeries {Name = "Blockers"}; foreach (var blockerResults in SimulationResults[index].Blockers.Results) { seriesBlockers.Points.Add(blockerResults.Key, blockerResults.Value.Done); } + seriesBlockers.Type = ChartSeriesType.Column; seriesBlockers.Text = seriesBlockers.Name; - WriteChartSafe(chartControl1, new[] { seriesTasks, seriesBlockers }); + WriteChartSafe(chartControl1, new[] {seriesTasks, seriesBlockers}); } + + #region Nested type: SafeCallChartDelegate + + protected delegate void SafeCallChartDelegate(ChartControl chartControl, ChartSeries[] chartSeries); + + #endregion + + #region Menu + + private void symuorgToolStripMenuItem_Click(object sender, EventArgs e) + { + Process.Start("https://symu.org"); + } + + private void documentationToolStripMenuItem1_Click(object sender, EventArgs e) + { + Process.Start("http://docs.symu.org/"); + } + + private void sourceCodeToolStripMenuItem1_Click(object sender, EventArgs e) + { + Process.Start("http://github.symu.org/"); + } + + private void issuesToolStripMenuItem_Click(object sender, EventArgs e) + { + Process.Start("http://github.symu.org/issues"); + } + + #endregion } } \ No newline at end of file diff --git a/Symu examples/SymuScenariosAndEvents/Program.cs b/Symu examples/SymuScenariosAndEvents/Program.cs index 23953918..5ba5c9cf 100644 --- a/Symu examples/SymuScenariosAndEvents/Program.cs +++ b/Symu examples/SymuScenariosAndEvents/Program.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // 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/SymuScenariosAndEvents/Properties/AssemblyInfo.cs b/Symu examples/SymuScenariosAndEvents/Properties/AssemblyInfo.cs index e72d54a9..7577a514 100644 --- a/Symu examples/SymuScenariosAndEvents/Properties/AssemblyInfo.cs +++ b/Symu examples/SymuScenariosAndEvents/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockers +// Description: Symu - SymuScenariosAndEvents // 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/SymuScenariosAndEventsTests/IntegrationTests.cs b/Symu examples/SymuScenariosAndEventsTests/IntegrationTests.cs index 2782f08e..aaeee483 100644 --- a/Symu examples/SymuScenariosAndEventsTests/IntegrationTests.cs +++ b/Symu examples/SymuScenariosAndEventsTests/IntegrationTests.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuMurphiesAndBlockersTests +// Description: Symu - SymuScenariosAndEventsTests // Website: https://symu.org // Copyright: (c) 2020 laurent morisseau // License : the program is distributed under the terms of the GNU General Public License @@ -53,17 +53,19 @@ private void SuccessTest() { var result = _simulation.SimulationResults[i]; Assert.IsTrue(result.Success); - Assert.IsTrue(result.Tasks.Done>0); + Assert.IsTrue(result.Tasks.Done > 0); Assert.AreEqual(i + 1, result.Iteration); } } + [TestMethod] public void SuccessTest0() { SuccessTest(); } + /// - /// Iteration = 0 + /// Iteration = 0 /// [TestMethod] public void SuccessTest1() @@ -73,7 +75,7 @@ public void SuccessTest1() } /// - /// Workers = 0 + /// Workers = 0 /// [TestMethod] public void SuccessTest2() @@ -92,7 +94,7 @@ public void SuccessTest2() } /// - /// Models On + /// Models On /// [TestMethod] public void SuccessTest3() @@ -101,8 +103,9 @@ public void SuccessTest3() _organization.Models.Generator = RandomGenerator.RandomUniform; SuccessTest(); } + /// - /// Murphies On + /// Murphies On /// [TestMethod] public void SuccessTest4() @@ -110,8 +113,9 @@ public void SuccessTest4() _organization.Murphies.On(1); SuccessTest(); } + /// - /// Murphies/Models On + /// Murphies/Models On /// [TestMethod] public void SuccessTest5() @@ -121,13 +125,14 @@ public void SuccessTest5() _organization.Models.Generator = RandomGenerator.RandomUniform; SuccessTest(); } + /// - /// No scenarios + /// No scenarios /// [TestMethod] public void SuccessTest6() { - _simulation.Scenarii.Clear(); + _simulation.Scenarii.Clear(); _simulation.Process(); for (var i = 0; i < _simulation.SimulationResults.List.Count; i++) { @@ -137,8 +142,9 @@ public void SuccessTest6() Assert.AreEqual(i + 1, result.Iteration); } } + /// - /// All scenarios + /// All scenarios /// [TestMethod] public void SuccessTest7() @@ -162,73 +168,81 @@ public void SuccessTest7() _simulation.AddScenario(scenario2); SuccessTest(); } + #region Events + /// - /// Event worker one shot + /// Event worker one shot /// [TestMethod] public void EventWorkerTest() { - var symuEvent = new SymuEvent { Step = 10 }; + var symuEvent = new SymuEvent {Step = 10}; symuEvent.OnExecute += _environment.PersonEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + /// - /// Event worker cyclical + /// Event worker cyclical /// [TestMethod] public void EventWorkerTest1() { - var symuEvent = new CyclicalEvent { EveryStep = 5 }; + var symuEvent = new CyclicalEvent {EveryStep = 5}; symuEvent.OnExecute += _environment.PersonEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + /// - /// Event worker random + /// Event worker random /// [TestMethod] public void EventWorkerTest2() { - var symuEvent = new RandomEvent { Ratio= 0.1F }; + var symuEvent = new RandomEvent {Ratio = 0.1F}; symuEvent.OnExecute += _environment.PersonEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + /// - /// Event knowledge one shot + /// Event knowledge one shot /// [TestMethod] public void EventKnowledgeTest() { - var symuEvent = new SymuEvent { Step = 10 }; + var symuEvent = new SymuEvent {Step = 10}; symuEvent.OnExecute += _environment.KnowledgeEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + /// - /// Event knowledge cyclical + /// Event knowledge cyclical /// [TestMethod] public void EventKnowledgeTest1() { - var symuEvent = new CyclicalEvent { EveryStep = 5 }; + var symuEvent = new CyclicalEvent {EveryStep = 5}; symuEvent.OnExecute += _environment.KnowledgeEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + /// - /// Event knowledge random + /// Event knowledge random /// [TestMethod] public void EventKnowledgeTest2() { - var symuEvent = new RandomEvent { Ratio = 0.1F }; + var symuEvent = new RandomEvent {Ratio = 0.1F}; symuEvent.OnExecute += _environment.KnowledgeEvent; _environment.AddEvent(symuEvent); SuccessTest(); } + #endregion } } \ No newline at end of file diff --git a/Symu source code/Symu/Classes/Agents/Agent.TaskManagement.cs b/Symu source code/Symu/Classes/Agents/Agent.TaskManagement.cs index d85a3cc8..6bd6ffe9 100644 --- a/Symu source code/Symu/Classes/Agents/Agent.TaskManagement.cs +++ b/Symu source code/Symu/Classes/Agents/Agent.TaskManagement.cs @@ -635,7 +635,8 @@ public virtual void ImpactOfBlockersOnCapacity() /// public void CheckBlockerIncompleteKnowledge(SymuTask task) { - if (!Environment.Organization.Murphies.IncompleteKnowledge.On || !Environment.Organization.Models.Knowledge.On) + if (!Environment.Organization.Murphies.IncompleteKnowledge.On || + !Environment.Organization.Models.Knowledge.On) { return; } diff --git a/Symu source code/Symu/Classes/Agents/Models/CognitiveModel/KnowledgeModel.cs b/Symu source code/Symu/Classes/Agents/Models/CognitiveModel/KnowledgeModel.cs index f5fca3f2..8f8e886f 100644 --- a/Symu source code/Symu/Classes/Agents/Models/CognitiveModel/KnowledgeModel.cs +++ b/Symu source code/Symu/Classes/Agents/Models/CognitiveModel/KnowledgeModel.cs @@ -231,6 +231,5 @@ public AgentKnowledge GetKnowledge(ushort knowledgeId) { return Expertise.GetKnowledge(knowledgeId); } - } } \ No newline at end of file diff --git a/Symu source code/Symu/Classes/Organization/OrganizationEntity.cs b/Symu source code/Symu/Classes/Organization/OrganizationEntity.cs index 078fd76b..6a6130d2 100644 --- a/Symu source code/Symu/Classes/Organization/OrganizationEntity.cs +++ b/Symu source code/Symu/Classes/Organization/OrganizationEntity.cs @@ -94,8 +94,9 @@ public void AddKnowledge(Knowledge knowledge) Knowledges.Add(knowledge); } } + /// - /// Clear organization for multiple iterations simulation + /// Clear organization for multiple iterations simulation /// public void Clear() { diff --git a/Symu source code/Symu/Classes/Organization/OrganizationModels.cs b/Symu source code/Symu/Classes/Organization/OrganizationModels.cs index b3370f69..1466a40c 100644 --- a/Symu source code/Symu/Classes/Organization/OrganizationModels.cs +++ b/Symu source code/Symu/Classes/Organization/OrganizationModels.cs @@ -107,6 +107,7 @@ public void CopyTo(OrganizationModels entity) entity.Generator = Generator; entity.ImpactOfBeliefOnTask = ImpactOfBeliefOnTask; } + /// /// Set all models on /// diff --git a/Symu source code/Symu/Engine/SymuEngine.cs b/Symu source code/Symu/Engine/SymuEngine.cs index eebdf185..e59b4c8a 100644 --- a/Symu source code/Symu/Engine/SymuEngine.cs +++ b/Symu source code/Symu/Engine/SymuEngine.cs @@ -30,31 +30,48 @@ namespace Symu.Engine /// public class SymuEngine { - public List Scenarii { get; }= new List(); + public List Scenarii { get; } = new List(); /// /// Environment of the simulation /// public SymuEnvironment Environment { get; set; } + /// /// The state of the SymuEngine /// public AgentState State { get; set; } = AgentState.Stopped; + /// /// Manage the multiple iterations of the simulation /// A interaction is a number of interaction steps /// Multiple iterations are used to replay a simulation for MonteCarlo process or to vary parameters /// public Iterations Iterations { get; set; } = new Iterations(); + /// /// Store the results of each iteration /// public SimulationResults SimulationResults { get; set; } = new SimulationResults(); + /// /// The result of the actual iteration /// public IterationResult IterationResult => Environment.IterationResult; + #region Step level + + /// + /// Used when Event OnNextDay is triggered by this class + /// + public virtual void OnNextStep() + { + Environment.OnNextStep(); + Environment.ManageAgentsToStop(); + } + + #endregion + #region Initialize / set /// @@ -73,6 +90,7 @@ public void AddScenario(SimulationScenario scenario) Scenarii.Add(scenario); } } + public void AddEvent(SymuEvent symuEvent) { Environment.AddEvent(symuEvent); @@ -123,6 +141,7 @@ public virtual void Process() { Iteration(); } + PostProcess(); } @@ -157,6 +176,7 @@ public void Iteration() { OnNextStep(); } + PostIteration(); } @@ -177,21 +197,21 @@ public void PostIteration() { AnalyzeIteration(); } + State = AgentState.Stopped; } /// - /// Called during the PostIteration if the iteration is a success - /// Override this method to analyze specifics results of the iteration + /// Called during the PostIteration if the iteration is a success + /// Override this method to analyze specifics results of the iteration /// protected virtual void AnalyzeIteration() { - } /// - /// Called during the PreIteration - /// Override this method if you need to initialize specifics iteration's objects + /// Called during the PreIteration + /// Override this method if you need to initialize specifics iteration's objects /// public virtual void InitializeIteration() { @@ -236,18 +256,5 @@ protected void SetScenariiAndTimeStep() } #endregion - - #region Step level - - /// - /// Used when Event OnNextDay is triggered by this class - /// - public virtual void OnNextStep() - { - Environment.OnNextStep(); - Environment.ManageAgentsToStop(); - } - - #endregion } } \ No newline at end of file diff --git a/Symu source code/Symu/Engine/SymuEngines.cs b/Symu source code/Symu/Engine/SymuEngines.cs index 3d9b72ad..21f90983 100644 --- a/Symu source code/Symu/Engine/SymuEngines.cs +++ b/Symu source code/Symu/Engine/SymuEngines.cs @@ -10,7 +10,6 @@ #region using directives using System.Collections.Generic; -using Symu.Results; #endregion diff --git a/Symu source code/Symu/Environment/Events/RandomEvent.cs b/Symu source code/Symu/Environment/Events/RandomEvent.cs index 6ac2ecf1..13e2aa6c 100644 --- a/Symu source code/Symu/Environment/Events/RandomEvent.cs +++ b/Symu source code/Symu/Environment/Events/RandomEvent.cs @@ -7,9 +7,13 @@ #endregion +#region using directives + using System; using Symu.Tools.Math.ProbabilityDistributions; +#endregion + namespace Symu.Environment.Events { /// @@ -32,6 +36,7 @@ public float Ratio _ratio = value; } } + public override bool Trigger(ushort step) { return Bernoulli.Sample(_ratio); diff --git a/Symu source code/Symu/Environment/Events/SymuEvent.cs b/Symu source code/Symu/Environment/Events/SymuEvent.cs index 25fdc87a..74bb3fa3 100644 --- a/Symu source code/Symu/Environment/Events/SymuEvent.cs +++ b/Symu source code/Symu/Environment/Events/SymuEvent.cs @@ -11,8 +11,11 @@ #endregion +#region using directives + using System; -using Symu.Classes.Task.Manager; + +#endregion namespace Symu.Environment.Events { @@ -30,6 +33,7 @@ public virtual void Schedule(ushort step) OnExecute?.Invoke(this, null); } } + /// /// EventHandler triggered after the event SetTaskInProgress /// diff --git a/Symu source code/Symu/Environment/Events/SymuEventType.cs b/Symu source code/Symu/Environment/Events/SymuEventType.cs index 4033a41c..da575b83 100644 --- a/Symu source code/Symu/Environment/Events/SymuEventType.cs +++ b/Symu source code/Symu/Environment/Events/SymuEventType.cs @@ -1,6 +1,6 @@ #region Licence -// Description: Symu - SymuScenariosAndEvents +// Description: Symu - Symu // 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 @@ namespace Symu.Environment.Events { /// - /// Type of SymuEvent used to schedule event during the simulation + /// Type of SymuEvent used to schedule event during the simulation /// public enum SymuEventType { diff --git a/Symu source code/Symu/Environment/SymuEnvironment.cs b/Symu source code/Symu/Environment/SymuEnvironment.cs index 177a2053..7574f0fd 100644 --- a/Symu source code/Symu/Environment/SymuEnvironment.cs +++ b/Symu source code/Symu/Environment/SymuEnvironment.cs @@ -430,8 +430,9 @@ public virtual void SetDatabases() #endregion #region Events + /// - /// Schedule Events from the list Events + /// Schedule Events from the list Events /// public void ScheduleEvents() { @@ -450,6 +451,7 @@ public void AddEvent(SymuEvent symuEvent) Events.Add(symuEvent); } + #endregion } } \ No newline at end of file diff --git a/Symu source code/Symu/Results/IterationResult.cs b/Symu source code/Symu/Results/IterationResult.cs index 8911cbe0..80d2e4cb 100644 --- a/Symu source code/Symu/Results/IterationResult.cs +++ b/Symu source code/Symu/Results/IterationResult.cs @@ -51,7 +51,7 @@ public IterationResult(SymuEnvironment environment) /// Focus on the time at which stability is reached /// In nonlinear stochastics systems with noise, a standard measure is the 90 % point (90% of its final theoretical) /// - public OrganizationFlexibility OrganizationFlexibility { get; } + public OrganizationFlexibility OrganizationFlexibility { get; } /// /// Get the knowledge and Belief performance for the group @@ -100,21 +100,6 @@ public void PostStep() Blockers.SetResults(_environment); } - #region todo : refactor in SpecificResults - - /// - /// Symu has been stopped SpecificResults - /// - public bool HasItemsNotDone { get; set; } - - public bool SeemsToBeBlocked { get; set; } - - //public bool NotFastEnoughAtHalfReplay; - public bool NotFinishedInTime { get; set; } - public ushort NumberOfItemsNotDone { get; set; } - - #endregion - public IterationResult Clone() { var clone = new IterationResult(_environment); @@ -134,8 +119,9 @@ public IterationResult Clone() //NumberOfItemsNotDone = 0; return clone; } + /// - /// Set all results to On + /// Set all results to On /// public void On() { @@ -144,8 +130,9 @@ public void On() Tasks.On = true; Blockers.On = true; } + /// - /// Set all results to Off + /// Set all results to Off /// public void Off() { @@ -154,5 +141,20 @@ public void Off() Tasks.On = false; Blockers.On = false; } + + #region todo : refactor in SpecificResults + + /// + /// Symu has been stopped SpecificResults + /// + public bool HasItemsNotDone { get; set; } + + public bool SeemsToBeBlocked { get; set; } + + //public bool NotFastEnoughAtHalfReplay; + public bool NotFinishedInTime { get; set; } + public ushort NumberOfItemsNotDone { get; set; } + + #endregion } } \ No newline at end of file diff --git a/Symu source code/Symu/Results/Organization/OrganizationFlexibility.cs b/Symu source code/Symu/Results/Organization/OrganizationFlexibility.cs index 73428e54..6dd3d6f4 100644 --- a/Symu source code/Symu/Results/Organization/OrganizationFlexibility.cs +++ b/Symu source code/Symu/Results/Organization/OrganizationFlexibility.cs @@ -35,6 +35,7 @@ public OrganizationFlexibility(SymuEnvironment environment) { _environment = environment; } + /// /// If set to true, OrganizationFlexibility will be filled with value and stored during the simulation /// @@ -124,16 +125,19 @@ public void CopyTo(OrganizationFlexibility cloneOrganizationFlexibility) { throw new ArgumentNullException(nameof(cloneOrganizationFlexibility)); } + cloneOrganizationFlexibility.Links = new List(); foreach (var result in Links) { cloneOrganizationFlexibility.Links.Add(result); } + cloneOrganizationFlexibility.Sphere = new List(); foreach (var result in Sphere) { cloneOrganizationFlexibility.Sphere.Add(result); } + cloneOrganizationFlexibility.Triads = new List(); foreach (var result in Triads) { diff --git a/Symu source code/Symu/Results/Organization/OrganizationKnowledgeAndBelief.cs b/Symu source code/Symu/Results/Organization/OrganizationKnowledgeAndBelief.cs index 674e990b..f5f33b9b 100644 --- a/Symu source code/Symu/Results/Organization/OrganizationKnowledgeAndBelief.cs +++ b/Symu source code/Symu/Results/Organization/OrganizationKnowledgeAndBelief.cs @@ -14,7 +14,6 @@ using System.Linq; using MathNet.Numerics.Statistics; using Symu.Environment; -using Symu.Repository.Networks; #endregion @@ -25,7 +24,6 @@ namespace Symu.Results.Organization /// public class OrganizationKnowledgeAndBelief { - private readonly SymuEnvironment _environment; public OrganizationKnowledgeAndBelief(SymuEnvironment environment) @@ -61,7 +59,8 @@ public OrganizationKnowledgeAndBelief(SymuEnvironment environment) /// /// List of Global Knowledge obsolescence : 1 - LastTouched.Average()/LastStep /// - public List KnowledgeObsolescence { get; private set; } = new List(); + public List KnowledgeObsolescence { get; private set; } = + new List(); /// /// Initialize of results @@ -95,21 +94,24 @@ public void HandlePerformance(ushort step) public void HandleLearning(ushort step) { - var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values.Select(e => e.Learning).ToList(); + var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values.Select(e => e.Learning) + .ToList(); var learning = SetStructKnowledgeAndBeliefStruct(step, sum); Learning.Add(learning); } public void HandleForgetting(ushort step) { - var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values.Select(e => e.Forgetting).ToList(); + var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values + .Select(e => e.Forgetting).ToList(); var forgetting = SetStructKnowledgeAndBeliefStruct(step, sum); Forgetting.Add(forgetting); } public void HandleKnowledgeObsolescence(ushort step) { - var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values.Select(e => e.Obsolescence).ToList(); + var sum = _environment.WhitePages.Network.NetworkKnowledges.AgentsRepository.Values + .Select(e => e.Obsolescence).ToList(); var obsolescence = SetStructKnowledgeAndBeliefStruct(step, sum); KnowledgeObsolescence.Add(obsolescence); } @@ -122,7 +124,8 @@ public void HandleKnowledge(ushort step) Knowledge.Add(knowledge); } - private static KnowledgeAndBeliefStruct SetStructKnowledgeAndBeliefStruct(ushort step, IReadOnlyList sumKnowledge) + private static KnowledgeAndBeliefStruct SetStructKnowledgeAndBeliefStruct(ushort step, + IReadOnlyList sumKnowledge) { float sum; float mean; @@ -152,7 +155,8 @@ private static KnowledgeAndBeliefStruct SetStructKnowledgeAndBeliefStruct(ushort public void HandleBelief(ushort step) { - var sum = _environment.WhitePages.Network.NetworkBeliefs.AgentsRepository.Values.Select(beliefs => beliefs.GetBeliefsSum()) + var sum = _environment.WhitePages.Network.NetworkBeliefs.AgentsRepository.Values + .Select(beliefs => beliefs.GetBeliefsSum()) .ToList(); var belief = SetStructKnowledgeAndBeliefStruct(step, sum); Beliefs.Add(belief); @@ -170,21 +174,25 @@ public void CopyTo(OrganizationKnowledgeAndBelief cloneOrganizationKnowledgeAndB { cloneOrganizationKnowledgeAndBelief.Knowledge.Add(result); } + cloneOrganizationKnowledgeAndBelief.Beliefs = new List(); foreach (var result in Beliefs) { cloneOrganizationKnowledgeAndBelief.Beliefs.Add(result); } + cloneOrganizationKnowledgeAndBelief.Learning = new List(); foreach (var result in Learning) { cloneOrganizationKnowledgeAndBelief.Learning.Add(result); } + cloneOrganizationKnowledgeAndBelief.Forgetting = new List(); foreach (var result in Forgetting) { cloneOrganizationKnowledgeAndBelief.Forgetting.Add(result); } + cloneOrganizationKnowledgeAndBelief.KnowledgeObsolescence = new List(); foreach (var result in KnowledgeObsolescence) { diff --git a/Symu source code/Symu/Results/Task/TaskResults.cs b/Symu source code/Symu/Results/Task/TaskResults.cs index 71a238c7..65083164 100644 --- a/Symu source code/Symu/Results/Task/TaskResults.cs +++ b/Symu source code/Symu/Results/Task/TaskResults.cs @@ -28,7 +28,7 @@ public class TaskResults /// Key => step /// Value => TaskResult for the step /// - public ConcurrentDictionary Results { get; private set; } = + public ConcurrentDictionary Results { get; private set; } = new ConcurrentDictionary(); /// diff --git a/Symu source code/SymuForm/SymuForm.cs b/Symu source code/SymuForm/SymuForm.cs index 94ea8c51..3745f45a 100644 --- a/Symu source code/SymuForm/SymuForm.cs +++ b/Symu source code/SymuForm/SymuForm.cs @@ -10,9 +10,7 @@ #region using directives using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using System.Windows.Forms; using Symu.Classes.Organization; using Symu.Classes.Scenario; @@ -33,15 +31,16 @@ namespace Symu.Forms public partial class SymuForm : Form { private bool _pauseWorker; - public SymuEngine Engine { get; }= new SymuEngine(); public SymuForm() { InitializeComponent(); } + public SymuEngine Engine { get; } = new SymuEngine(); + protected OrganizationEntity OrganizationEntity { get; set; } = new OrganizationEntity("symu"); - + /// /// Manage the multiple iterations of the simulation /// A interaction is a number of interaction steps @@ -54,10 +53,24 @@ public SymuForm() /// public SimulationResults SimulationResults => Engine.SimulationResults; + #region Nested type: SafeCallButtonDelegate + + protected delegate void SafeCallButtonDelegate(Button button, bool enabled); + + #endregion + + #region Nested type: SafeCallTextDelegate + + protected delegate void SafeCallTextDelegate(Label label, string text); + + #endregion + #region Display + public virtual void DisplayStep() { } + public virtual void DisplayIteration() { } @@ -79,6 +92,7 @@ protected void WriteTextSafe(Label label, string text) label.Text = text; } } + protected void DisplayButtons(Button btnStart, Button btnStop, Button btnPause, Button btnResume) { switch (Engine.State) @@ -113,6 +127,7 @@ protected void DisplayButtons(Button btnStart, Button btnStop, Button btnPause, throw new ArgumentOutOfRangeException(); } } + protected void WriteButtonSafe(Button button, bool enabled) { if (button is null) @@ -130,6 +145,7 @@ protected void WriteButtonSafe(Button button, bool enabled) button.Enabled = enabled; } } + #endregion #region Engine @@ -223,14 +239,16 @@ private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) worker.ReportProgress(i); } } + PostIteration(); } } OnStopped(); } + /// - /// Trigger after the event Stopped + /// Trigger after the event Stopped /// protected virtual void OnStopped() { @@ -268,12 +286,6 @@ protected void Resume() _pauseWorker = false; Engine.State = AgentState.Started; } - #endregion - - #region Nested type: SafeCallDelegate - - protected delegate void SafeCallTextDelegate(Label label, string text); - protected delegate void SafeCallButtonDelegate(Button button, bool enabled); #endregion @@ -337,7 +349,7 @@ protected virtual void PreIteration() /// /// When to stop the iteration based on the scenario agents. - /// You can add custom control + /// You can add custom control /// /// protected virtual bool StopIteration() @@ -364,6 +376,7 @@ protected virtual void PostProcess() { Engine.PostProcess(); } + protected virtual bool StopProcess() { return Engine.StopProcess(); diff --git a/Symu source code/SymuTests/Classes/Agents/Models/CognitiveModel/KnowledgeModelTests.cs b/Symu source code/SymuTests/Classes/Agents/Models/CognitiveModel/KnowledgeModelTests.cs index 47057c41..0e62a61a 100644 --- a/Symu source code/SymuTests/Classes/Agents/Models/CognitiveModel/KnowledgeModelTests.cs +++ b/Symu source code/SymuTests/Classes/Agents/Models/CognitiveModel/KnowledgeModelTests.cs @@ -302,7 +302,7 @@ public void InitializeKnowledgeTest() _knowledgeModel.AddKnowledge(_knowledge.Id, KnowledgeLevel.FullKnowledge, 0, -1); _knowledgeModel.InitializeKnowledge(_knowledge.Id, 0); Assert.IsTrue(_network.NetworkKnowledges.Exists(_agentId, _knowledge.Id)); - var agentKnowledge=_network.NetworkKnowledges.GetAgentKnowledge(_agentId, _knowledge.Id); + var agentKnowledge = _network.NetworkKnowledges.GetAgentKnowledge(_agentId, _knowledge.Id); Assert.AreEqual(1, agentKnowledge.KnowledgeBits.GetBit(0)); } } diff --git a/Symu source code/SymuTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs b/Symu source code/SymuTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs index 81c56149..0d3c8dda 100644 --- a/Symu source code/SymuTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs +++ b/Symu source code/SymuTests/Results/Organization/OrganizationKnowledgeAndBeliefTests.cs @@ -11,10 +11,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Symu.Classes.Agents; -using Symu.Classes.Agents.Models; using Symu.Classes.Organization; -using Symu.Environment; -using Symu.Repository.Networks; using Symu.Repository.Networks.Beliefs; using Symu.Repository.Networks.Knowledges; using Symu.Results.Organization; @@ -29,16 +26,18 @@ public class OrganizationKnowledgeAndBeliefTests { private readonly AgentId _agentId = new AgentId(1, 1); private readonly AgentId _agentId2 = new AgentId(2, 1); + private readonly TestEnvironment _environment = new TestEnvironment(); 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 OrganizationKnowledgeAndBelief _result; - private readonly TestEnvironment _environment = new TestEnvironment(); [TestInitialize] public void Initialize() { + var organization = new OrganizationEntity("1"); + _environment.SetOrganization(organization); _result = new OrganizationKnowledgeAndBelief(_environment); _environment.WhitePages.Network.AddKnowledge(_knowledge); _environment.WhitePages.Network.AddKnowledge(_knowledge2); @@ -110,9 +109,11 @@ public void HandleBelief0Test() public void HandleBelief1Test() { _expertise.Add(_knowledge.Id, KnowledgeLevel.FullKnowledge, 0, -1); - _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId, _expertise, BeliefLevel.NeitherAgreeNorDisagree); + _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId, _expertise, + BeliefLevel.NeitherAgreeNorDisagree); _environment.WhitePages.Network.NetworkBeliefs.InitializeBeliefs(_agentId, false); - _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge.Id).BeliefBits.SetBit(0, 1); + _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge.Id).BeliefBits + .SetBit(0, 1); _result.HandleBelief(0); Assert.AreEqual(1, _result.Beliefs[0].Mean); } @@ -125,14 +126,20 @@ public void HandleBelief2Test() { _expertise.Add(_knowledge.Id, KnowledgeLevel.FullKnowledge, 0, -1); _expertise.Add(_knowledge2.Id, KnowledgeLevel.FullKnowledge, 0, -1); - _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId, _expertise, BeliefLevel.NeitherAgreeNorDisagree); - _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId2, _expertise, BeliefLevel.NeitherAgreeNorDisagree); + _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId, _expertise, + BeliefLevel.NeitherAgreeNorDisagree); + _environment.WhitePages.Network.NetworkBeliefs.Add(_agentId2, _expertise, + BeliefLevel.NeitherAgreeNorDisagree); _environment.WhitePages.Network.NetworkBeliefs.InitializeBeliefs(_agentId, false); _environment.WhitePages.Network.NetworkBeliefs.InitializeBeliefs(_agentId2, false); - _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge.Id).BeliefBits.SetBit(0, 1); - _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge2.Id).BeliefBits.SetBit(0, 1); - _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId2, _knowledge.Id).BeliefBits.SetBit(0, 1); - _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId2, _knowledge2.Id).BeliefBits.SetBit(0, 1); + _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge.Id).BeliefBits + .SetBit(0, 1); + _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId, _knowledge2.Id).BeliefBits + .SetBit(0, 1); + _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId2, _knowledge.Id).BeliefBits + .SetBit(0, 1); + _environment.WhitePages.Network.NetworkBeliefs.GetAgentBelief(_agentId2, _knowledge2.Id).BeliefBits + .SetBit(0, 1); _result.HandleBelief(0); Assert.AreEqual(2, _result.Beliefs[0].Mean); Assert.AreEqual(0, _result.Beliefs[0].StandardDeviation); diff --git a/docs/_static/SymuScenariosAndEvents.PNG b/docs/_static/SymuScenariosAndEvents.PNG new file mode 100644 index 00000000..55b865df Binary files /dev/null and b/docs/_static/SymuScenariosAndEvents.PNG differ diff --git a/docs/_static/SymuScenariosAndEventsSmall.png b/docs/_static/SymuScenariosAndEventsSmall.png new file mode 100644 index 00000000..fffee5a8 Binary files /dev/null and b/docs/_static/SymuScenariosAndEventsSmall.png differ diff --git a/docs/models/simulation.rst b/docs/models/simulation.rst index 454c22b5..f28b68b2 100644 --- a/docs/models/simulation.rst +++ b/docs/models/simulation.rst @@ -10,8 +10,23 @@ In this approach, properties can emerge of the system during the simulation. The .. seealso:: :doc:`agent` -Models and mechanisms -********************* +Engine +****** +The engine of this simulator offers the possibility to performe or multiple iterations. Multiple iterations is useful in a Monte Carlo approach. +This method is aiming to calculate an approximate numerical value using random methods. + +Events +****** +To add variability, you can schedule events during the simulation. You will find by design one shot, cyclical and random events. + +.. topic:: Examples + + You can add a new agent every 100 steps, or randomly add an event that affect the beliefs of the agents. + +.. seealso:: :doc:`../userguides/symuscenariosandevents` + +Models +****** ``Symu`` is a time-based. It contains a discrete event schedule on which you can schedule various agents to be called at some specific time. But it is ont space-based, it has no 2D nor 3D features to localize agents in the space. Of course, Simulation is at the heart of this framework. It is based on two asynchronous models: diff --git a/docs/userguides/examples_guide.rst b/docs/userguides/examples_guide.rst index 4f99e30d..427e7b5c 100644 --- a/docs/userguides/examples_guide.rst +++ b/docs/userguides/examples_guide.rst @@ -14,4 +14,6 @@ So that you will be able to configure models for your own use cases. symugroupandinteraction symulearnandforget symumessageandtask - symumurphiesandblockers \ No newline at end of file + symumurphiesandblockers + symubeliefsandinfluence + symuscenariosandevents \ No newline at end of file diff --git a/docs/userguides/symuscenariosandevents.rst b/docs/userguides/symuscenariosandevents.rst new file mode 100644 index 00000000..41f3f1dc --- /dev/null +++ b/docs/userguides/symuscenariosandevents.rst @@ -0,0 +1,38 @@ +.. index:: Beliefs, influence + +******************************* +SymuBeliefsAndInfluence example +******************************* + +.. image:: ../_static/SymuBeliefsAndInfluence.PNG + :align: center + +Different models are implemented in this simulator. SymuBeliefsAndInfluence demonstrate the use of two of them: the beliefs and the influence model. + +You can use this example to discover and understand the impact of all the setups on the agents. That will help you setup you own interaction model. + +Beliefs model +************* + +Symu is a multi-agent system for the co-evolution of agents and socio-cultural environments with an interaction model between agents. +These interactions are based on the information exchanged but also the beliefs. + +.. seealso:: :doc:`../models/cognitivearchitecture/Knowledgeandbeliefs` + +Influence model +*************** +This model define how an agent will reinforce its belief or change its belief from influencer. +.. seealso:: :doc:`../models/agent` + + +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 interaction. +Play with the interaction 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 interactions. + +Find the `source code `_ \ No newline at end of file