>>56216273
public static void run()
{
int startsize = 8000;
int targetsize = 5000;
int maxiterations = 1000;
//conn = new SqlConnection(logconstr);
//conn.Open();
organisms = new ConcurrentBag<Organism>();
for (int i = 0; i < startsize; i++)
organisms.Add(new Organism(i));
int count = 0;
bool fail = false;
while (count < maxiterations)
{
ConcurrentBag<Organism> temp = new ConcurrentBag<Organism>();
Parallel.ForEach(organisms, (i) =>
{
var t = i.run();
if (t != null && t.isAlive)
temp.Add(t);
if (i.isAlive)
temp.Add(i);
});
if (temp.Count > targetsize && count > 100)
organisms = new ConcurrentBag<Organism>(temp.OrderByDescending(i => i.getHealth()).Take((int)(temp.Count * (-temp.Count / (targetsize * 10) + 0.90))).ToList());
else
organisms = temp;
//new Task(() =>
//{
// sqlInsert(temp.ToList(), count);
//}).Start();
Console.WriteLine("iteration: " + count + " total: " + temp.Count);
if (organisms.Count <= 100 || organisms.Count > 500000 || fail)
break;
count++;
}
generateAndInsertSummaryData(organisms);
}