Added Ui to alter simulation settings and added paralell processing with huge performance benefits over little grids
This commit is contained in:
@@ -11,7 +11,7 @@ namespace PropagationRemasteredBeta
|
||||
{
|
||||
public class Terrain
|
||||
{
|
||||
const int DEFAULT_SIZE = 1000;
|
||||
const int DEFAULT_SIZE = 200;
|
||||
const int DEFAULT_INFECTED_PROPORTION = 10;
|
||||
const int DEFAULT_IMMUNE_PROPORTION = 10;
|
||||
const int DEFAULT_DEATH_RATE = 5;
|
||||
@@ -26,6 +26,7 @@ namespace PropagationRemasteredBeta
|
||||
|
||||
private Human[,] _population;
|
||||
private ConcurrentBag<Human> _peopleToCheck;
|
||||
private ConcurrentBag<Human> _infectedsToCheck;
|
||||
private Size _terrainSize;
|
||||
|
||||
private int _infectedProportion;
|
||||
@@ -62,6 +63,7 @@ namespace PropagationRemasteredBeta
|
||||
public int SimulationDuration { get => _simulationDuration; set => _simulationDuration = value; }
|
||||
public Random Rnd { get => rnd; set => rnd = value; }
|
||||
public ConcurrentBag<Human> PeopleToCheck { get => _peopleToCheck; set => _peopleToCheck = value; }
|
||||
public ConcurrentBag<Human> InfectedsToCheck { get => _infectedsToCheck; set => _infectedsToCheck = value; }
|
||||
|
||||
public Terrain(Size terrainSize, int infectedProportion, int resistantProportion, int deathRate, int infectionRate, int cureTime)
|
||||
{
|
||||
@@ -157,21 +159,22 @@ namespace PropagationRemasteredBeta
|
||||
DeadCount.Add(0);
|
||||
|
||||
PeopleToCheck = new ConcurrentBag<Human>();
|
||||
InfectedsToCheck = new ConcurrentBag<Human>();
|
||||
|
||||
//Parallel.For(0, TerrainSize.Width, width =>
|
||||
for (int width = 0; width < TerrainSize.Width; width += 1)
|
||||
Parallel.For(0, TerrainSize.Width, width =>
|
||||
//for (int width = 0; width < TerrainSize.Width; width += 1)
|
||||
{
|
||||
//Parallel.For(0, TerrainSize.Height, height =>
|
||||
for (int height = 0; height < TerrainSize.Height; height += 1)
|
||||
Parallel.For(0, TerrainSize.Height, height =>
|
||||
//for (int height = 0; height < TerrainSize.Height; height += 1)
|
||||
{
|
||||
//we also send the random so if one day we want to add a seed feature it will also affect the transmission
|
||||
switch (Population[width, height].State)
|
||||
{
|
||||
case Human.INFECTED:
|
||||
Population[width, height] = Population[width, height].Propagate(this);
|
||||
Population[width, height].Propagate(this);
|
||||
break;
|
||||
default:
|
||||
//nothing to do
|
||||
//nothing to do for now
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -191,14 +194,17 @@ namespace PropagationRemasteredBeta
|
||||
DeadCount[SimulationDuration] += 1;
|
||||
break;
|
||||
}
|
||||
}//);
|
||||
}//);
|
||||
});
|
||||
});
|
||||
|
||||
foreach (Human target in PeopleToCheck)
|
||||
{
|
||||
Population[target.Position.X,target.Position.Y] = target.CheckInfection(InfectionRate,Rnd);
|
||||
}
|
||||
|
||||
foreach (Human target in InfectedsToCheck)
|
||||
{
|
||||
Population[target.Position.X, target.Position.Y] = target.CheckDeath(DeathRate,CureTime,Rnd);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap Display()
|
||||
|
||||
Reference in New Issue
Block a user