Skip to content

Commit

Permalink
Different log prints
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPalasek committed May 1, 2019
1 parent 996ffa3 commit b4608c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions JobShopScheduling/JobShopGeneticAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ public JobShopGeneticAlgorithm(JobShop jobShop)

public void Run(int iterationsCount, bool adaptive = true)
{
if (iterationsCount < 1)
{
return;
}

ScheduleChromosome bestChromosome = null;
for (int i = 0; i < iterationsCount; i++)
{
var chromosome = RunOnce(adaptive);
Console.WriteLine();

if (bestChromosome == null)
{
Expand All @@ -38,9 +44,8 @@ public void Run(int iterationsCount, bool adaptive = true)
{
bestChromosome = chromosome.Fitness > bestChromosome.Fitness ? chromosome : bestChromosome;
}

Console.WriteLine($"Best chromosome for all iterations: {bestChromosome.ScheduleLength}");
}
Console.WriteLine($"Best chromosome for all iterations: {bestChromosome.ScheduleLength}");
}

private ScheduleChromosome RunOnce(bool adaptive = true)
Expand Down Expand Up @@ -89,12 +94,12 @@ private ScheduleChromosome RunOnce(bool adaptive = true)
private void Print(IPopulation population, TimeSpan totalTime)
{
var bestChromosome = (ScheduleChromosome)population.BestChromosome;
Console.WriteLine($"Generation: {population.GenerationsNumber}");
Console.WriteLine($"Best schedule length: {bestChromosome.ScheduleLength:F}");
Console.Write($"Generation: {population.GenerationsNumber}, ");
Console.Write($"Best schedule length: {bestChromosome.ScheduleLength:F}, ");
var chromosomes = population.CurrentGeneration.Chromosomes.Cast<ScheduleChromosome>().ToList();
Console.WriteLine($"Average schedule length: {chromosomes.Average(x => x.ScheduleLength):F}");
Console.WriteLine($"Population std deviation: {chromosomes.StandardDeviation(x => (decimal)x.ScheduleLength.Value):F}");
Console.WriteLine($"Time evolving: {totalTime.TotalSeconds:F}");
Console.Write($"Average schedule length: {chromosomes.Average(x => x.ScheduleLength):F}, ");
Console.Write($"Population std deviation: {chromosomes.StandardDeviation(x => (decimal)x.ScheduleLength.Value):F}, ");
Console.Write($"Time evolving: {totalTime.TotalSeconds:F}");
Console.WriteLine();
}

Expand Down
2 changes: 1 addition & 1 deletion JobShopScheduling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class Program
{
private static void Main(string[] args)
{
JobShop jobShop = LoadJobShop("Examples/la19.in");
JobShop jobShop = LoadJobShop("Examples/ft06.in");
//JobShop jobShop = GenerateJobShop();

var jobShopGeneticAlgorithm = new JobShopGeneticAlgorithm(jobShop);
Expand Down

0 comments on commit b4608c7

Please sign in to comment.