/// <summary>
        /// Saves a Disease to the given Location if it exists and the file not exists
        /// </summary>
        /// <param name="disease">The Disease to be saved</param>
        /// <param name="fileName">The Destination for the File</param>
        /// <param name="overwrite">Should existing files get overriden?</param>
        public static void Save(Disease disease, string fileName, bool overwrite)
        {
            if (File.Exists(fileName) && !overwrite)
                throw new ArgumentException("File already exists (" + fileName + ")!", "fileName");
            if (!fileName.EndsWith(FILEEXTENSION))
                throw new ArgumentException("File must have extension " + FILEEXTENSION, "fileName");

            new ArchiveBinaryWriter().WriteToFile(disease, fileName, overwrite);
        }
Exemple #2
0
 private SimulationInfo(Disease disease, int mapX, int mapY, int simintervall, int snapintervall, long duration)
 {
     Disease = disease;
     Name = Disease.Name;
     MapX = mapX;
     MapY = mapY;
     SimulationInvervall = simintervall;
     SnapshotIntervall = snapintervall;
     SimulationDuration = duration;
 }
Exemple #3
0
        /// <summary>
        /// Initializes the logging of a new Simulation
        /// </summary>
        /// <param name="destination">Where to save the data</param>
        /// <param name="disease">The Disease used in the Simulation</param>
        public void Initialize(string destination, Disease disease, int mapX, int mapY, int simintervall, int snapintervall, long duration)
        {
            _simInfo = SimulationInfo.InitializeFromRuntime(disease, mapX, mapY, simintervall, snapintervall, duration);

            _target = destination;
            _snapshots = new Queue<TickSnapshot>();

            _writer = new SnapshotWriter();
            _writer.QueueEmptied += (s, e) => WriterQueueEmpty.Raise(s, e);
            _writer.SnapshotWritten += (s, e) => SnapshotWritten.Raise(s, e);
            TookSnapshot += _writer.Recieve;
        }
Exemple #4
0
        /// <summary>
        /// Returns a new Disease from an Byte[]
        /// </summary>
        /// <param name="bytes">The [] containing the diseases information</param>
        public static Disease FromBytes(byte[] bytes)
        {
            if (bytes[0] != HEADER)
                throw new HeaderCorruptException("Header damaged, should " + HEADER);

            Disease disease = new Disease();

            disease.IncubationPeriod = BitConverter.ToInt32(bytes, 1);
            disease.IdleTime = BitConverter.ToInt32(bytes, 5);
            disease.SpreadingTime = BitConverter.ToInt32(bytes, 9);
            disease.Transferability = BitConverter.ToInt32(bytes, 13);

            int mortMaleBaby = BitConverter.ToInt32(bytes, 17);
            int mortMaleChild = BitConverter.ToInt32(bytes, 21);
            int mortMaleAdult = BitConverter.ToInt32(bytes, 25);
            int mortMaleSenior = BitConverter.ToInt32(bytes, 29);
            int mortFemaleBaby = BitConverter.ToInt32(bytes, 33);
            int mortFemaleChild = BitConverter.ToInt32(bytes, 37);
            int mortFemaleAdult = BitConverter.ToInt32(bytes, 41);
            int mortFemaleSenior = BitConverter.ToInt32(bytes, 45);

            disease.MortalityRate =
                new FactorContainer(new[] {
                mortMaleBaby, mortMaleChild, mortMaleAdult, mortMaleSenior,
                mortFemaleBaby, mortFemaleChild, mortFemaleAdult, mortFemaleSenior });

            int healMaleBaby = BitConverter.ToInt32(bytes, 49);
            int healMaleChild = BitConverter.ToInt32(bytes, 53);
            int healMaleAdult = BitConverter.ToInt32(bytes, 57);
            int healMaleSenior = BitConverter.ToInt32(bytes, 61);
            int healFemaleBaby = BitConverter.ToInt32(bytes, 65);
            int healFemaleChild = BitConverter.ToInt32(bytes, 69);
            int healFemaleAdult = BitConverter.ToInt32(bytes, 73);
            int healFemaleSenior = BitConverter.ToInt32(bytes, 77);

            disease.HealingFactor =
                new FactorContainer(new[] {
                healMaleBaby, healMaleChild, healMaleAdult, healMaleSenior,
                healFemaleBaby, healFemaleChild, healFemaleAdult, healFemaleSenior });

            int restMaleBaby = BitConverter.ToInt32(bytes, 81);
            int restMaleChild = BitConverter.ToInt32(bytes, 85);
            int restMaleAdult = BitConverter.ToInt32(bytes, 89);
            int restMaleSenior = BitConverter.ToInt32(bytes, 93);
            int restFemaleBaby = BitConverter.ToInt32(bytes, 97);
            int restFemaleChild = BitConverter.ToInt32(bytes, 101);
            int restFemaleAdult = BitConverter.ToInt32(bytes, 105);
            int restFemaleSenior = BitConverter.ToInt32(bytes, 109);

            disease.ResistanceFactor =
                new FactorContainer(new[] {
                restMaleBaby, restMaleChild, restMaleAdult, restMaleSenior,
                restFemaleBaby, restFemaleChild, restFemaleAdult, restFemaleSenior });

            string name = Encoding.UTF8.GetString(bytes, 113, bytes.Length - 113);
            disease.Name = name;

            return disease;
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new SimulationInfo from Runtime
 /// </summary>
 /// <param name="name">The Simulations Name</param>
 /// <param name="disease">The used Disease</param>
 /// <returns></returns>
 public static SimulationInfo InitializeFromRuntime(Disease disease, int x, int y, int simintervall, int snapintervall, long duration)
 {
     return new SimulationInfo(disease, x, y, simintervall, snapintervall, duration);
 }
Exemple #6
0
        public static void TestComponents()
        {
            string dep = "../../../EpidemicSim_InputDataParsers/germany.dep";

            var disease = new Disease()
            {
                Name = "ComponentTest_InfectionComponent",
                IdleTime = 1,
                IncubationPeriod = 1,
                SpreadingTime = 6,
                Transferability = 100,
                MortalityRate = new FactorContainer(new []{ 1, 2, 14, 151, 11515, 123, 123, 120}),
                HealingFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
                ResistanceFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 })
            };

            string[] componentNames =
                {"AgeingComponent", "DiseaseEffectComponent", "MindsetComponent", "MovementComponent"};
            SimulationComponent[] components =
                { new AgeingComponent(110), new DiseaseTickComponent(), new MindsetComponent(), new MovementComponent() };
            var debugComp = new DebugInfectionComponent();

            EpidemicSimulator sim;
            Console.WriteLine("Testing all Components seperately");
            Console.WriteLine("Testing InfectionComponent");
            for (int i = -1; i < components.Length; i++)
            {
                if (i == -1)
                    sim = EpidemicSimulator.Create(disease, dep, new ConsoleOutputTarget(), DateTime.Now, new InfectionComponent());
                else
                {
                    disease.Name = "ComponentTest_" + componentNames[i];
                    sim = EpidemicSimulator.Create(disease, dep, new ConsoleOutputTarget(), DateTime.Now, debugComp);
                    sim.AddSimulationComponent(components[i]);
                    Console.WriteLine("Testing " + componentNames[i]);
                }
                sim.SetSimulationIntervall(1);
                sim.SetSnapshotIntervall(1);
                sim.ProcessFinished += FinishedComponentSimulation;
                sim.StartSimulation(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/componentTests/" + "\\dat.sim", GetExampleInitialInfection(), 4);
                running = true;

                while (running) ;
                Console.WriteLine("Finished component!");
            }
            Console.WriteLine("All done!");
        }
Exemple #7
0
        public static void TestSimulation()
        {
            var disease = new Disease
            {
                Name = "Dat",
                IncubationPeriod = 1,
                IdleTime = 1,
                SpreadingTime = 12,
                Transferability = 100,
                MortalityRate = new FactorContainer(new[] { 10, 20, 20, 10, 10, 20, 20, 10 }),
                HealingFactor = new FactorContainer(new[] { 0, 5, 5, 0, 0, 3, 3, 0 }),
                ResistanceFactor = new FactorContainer(new[] { 0, 5, 5, 0, 0, 3, 3, 0})
            };
            var sim = EpidemicSimulator.Create(disease,
                "../../../EpidemicSim_InputDataParsers/germany.dep",
                new ConsoleOutputTarget(),
                DateTime.Now,
                new AgeingComponent(110),
                new DiseaseTickComponent(),
                new DiseaseDeathComponent(),
                new DiseaseHealingComponent(),
                new MindsetComponent(),
                new MovementComponent(),
                new InfectionComponent()
                );
            sim.SetSimulationIntervall(1);
            sim.SetSnapshotIntervall(1);
            sim.SimulationStarted += OnSimStartEvent;
            sim.TickFinished += OnTickfinishedEvent;
            sim.SimulationEnded += OnSimEndedEvent;

            sim.StartSimulation(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\dat.sim", GetExampleInitialInfection(), 48);
        }
Exemple #8
0
        public static void TestInfectionComponent()
        {
            string dep = "../../../EpidemicSim_InputDataParsers/germany.dep";

            var disease = new Disease()
            {
                Name = "Inf_Test",
                IdleTime = 6,
                IncubationPeriod = 6,
                SpreadingTime = 12,
                Transferability = 100,
                MortalityRate = new FactorContainer(new []{ 1, 2, 14, 151, 11515, 123, 123, 120}),
                HealingFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
                ResistanceFactor = new FactorContainer(new[] { 0, 0, 0, 0, 0, 0, 0, 0 })
            };

            var sim = EpidemicSimulator.Create(disease, dep, new ConsoleOutputTarget(), DateTime.Now, new InfectionComponent());
            sim.AddSimulationComponent(new DiseaseTickComponent());
            sim.SetSimulationIntervall(3);
            sim.SetSnapshotIntervall(3);
            sim.StartSimulation(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\dat.sim", GetExampleInitialInfection(), 24);
        }
Exemple #9
0
        public static void TestDiseaseIO()
        {
            var disease = new Disease
                {
                    Name = "Test_Disease",
                    IncubationPeriod = 238475,
                    IdleTime = 123415,
                    SpreadingTime = 123123,
                    Transferability = 901237,
                    MortalityRate = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
                    HealingFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
                    ResistanceFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 })
                };
            DiseaseIOService.Save(disease, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), true);

            var dis = DiseaseIOService.Load(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test_Disease.dis"));
            Console.WriteLine("Done");
        }
        private unsafe void TryInfection(Human* human, Disease disease, int probability)
        {
            // get index for FactorContainer
            int ageIndex = (byte)human->GetAge() / 32;
            ageIndex += human->GetGender() == EGender.Male ? 0 : 4;

            int resistance = disease.ResistanceFactor.Data[ageIndex];

            if (resistance < probability)
            {
                int factor = probability - resistance;
                int rand = RANDOM.Next(100);
                if (rand <= factor)
                {
                    human->Infect((short)disease.IncubationPeriod, (short)disease.IdleTime);
                    lock (_data.Cells[human->CurrentCell])
                        _data.Cells[human->CurrentCell].Infecting++;
                }
            }
        }
 public void Start()
 {
     _disease = new Disease
     {
         Name = "Disease",
         IncubationPeriod = 238475,
         IdleTime = 123415,
         SpreadingTime = 123123,
         Transferability = 901237,
         MortalityRate = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
         HealingFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 }),
         ResistanceFactor = new FactorContainer(new[] { 1, 2, 14, 151, 11515, 123, 123, 120 })
     };
 }