public static double ObjectiveFunction(DiseaseSimulation simulation)
        {
            var simResults = simulation.RunSimulation();

            //var infectionAttempts = 0;

            while (simResults[0].Last() < 100)
            {
                simResults = simulation.RunSimulation();
            }

            if (simResults[0].Last() == -1)
            {
                return(bigNumber);
            }

            //if (simResults[0].Count < simulation.maxSimulationLength)
            //{
            //    return bigNumber;
            //}

            //Console.WriteLine("Difference in total infected: " + (simResults[0].Last() - infectionsByGovernorate[0]));
            //Console.WriteLine("Difference in infections in the capital: " + (simResults[3].Last() - infectionsByGovernorate[3]));

            //var objValue = Math.Abs(simResults[0].Last() - infectionsByGovernorate[0]) + Math.Abs(simResults[3].Last() - infectionsByGovernorate[3]);
            var objValue = simResults[0].Last();

            //var objValue = 0; //simResults[0].Last();


            //foreach (var governorate in simulation.nodeProbsByAdmin1.Keys)
            //{
            //    objValue += Math.Abs(simResults[governorate].Last() - infectionsByGovernorate[governorate]);
            //}

            return(Convert.ToDouble(objValue));
        }
Exemplo n.º 2
0
        static void RunSimulations()
        {
            var diseaseNetwork = new ConnectionNetwork(Data.GenPopData(), Data.GenWaterData(), Data.GenAdminData());

            string file = Directory.GetCurrentDirectory();

            file = Path.GetFullPath(Path.Combine(file, @"..\..\")) + "simResultsTimeUnscaled.csv";
            string header = string.Join(",", Enumerable.Range(0, 496).Select(x => x.ToString()).ToArray()) + "\n";


            for (int i = 0; i < 999; i++)
            {
                //Console.WriteLine(i);

                var simulation = new DiseaseSimulation(diseaseNetwork);

                var simResults = simulation.RunSimulation();

                while (simResults[0].Last() < 1000)
                {
                    simResults = simulation.RunSimulation();
                }

                if (!File.Exists(file))
                {
                    File.WriteAllText(file, header);
                }

                Console.WriteLine(i.ToString() + ": " + simResults[0].Last().ToString());
                //var line = string.Concat(simResults.Select(l => l.Last().ToString() + ","));
                var line = string.Concat(simResults[0].Select(dInfectious => dInfectious.ToString() + ","));
                line = line.Remove(line.Length - 1) + "\n";

                File.AppendAllText(file, line);
            }
        }