/// <summary> /// Ensures that the best chromosome gets carried over to the new generation. /// </summary> private void EnsureSurvival() { for (int i = 0; i < FittestChromosome.GetNumberOfGenes(); i++) { _population[0].SetGene(FittestChromosome, i); } }
public FittestChromosomeView(FittestChromosome fittest) { InitializeComponent(); // THIS CAN CAUSE PROBLEMS! Order every persons shift assignments OrderPersonsShifts(fittest.Chromosome.TimePeriod); // Add information to the datagrids CreateResultsDataGrid(fittest); }
/// <summary> /// Creates a new resultview with the generated timeperiod /// </summary> /// <param name="fittest"></param> private void CreateResultsDataGrid(FittestChromosome fittest) { //Creating shift assignment datagrid foreach (Objects.Day day in fittest.Chromosome.TimePeriod.Days) { int row = shiftGridView.Rows.Add(); shiftGridView.Rows[row].Cells[0].Value = "Day " + (row + 1).ToString(); shiftGridView.Rows[row].Cells[1].Value = day.Shifts[0].PersonnelRequirement.ToString(); shiftGridView.Rows[row].Cells[2].Value = day.Shifts[1].PersonnelRequirement.ToString(); shiftGridView.Rows[row].Cells[3].Value = day.Shifts[2].PersonnelRequirement.ToString(); shiftGridView.Rows[row].Cells[4].Value = day.Shifts[0].AssignedPersons.Count.ToString(); shiftGridView.Rows[row].Cells[5].Value = day.Shifts[1].AssignedPersons.Count.ToString(); shiftGridView.Rows[row].Cells[6].Value = day.Shifts[2].AssignedPersons.Count.ToString(); } CheckShiftAssignments(); //Creating person assignment datagrid foreach (Person person in fittest.Chromosome.TimePeriod.AvailablePersons) { int row = personGridView.Rows.Add(); personGridView.Rows[row].Cells[0].Value = "Person " + person.ID.ToString(); personGridView.Rows[row].Cells[1].Value = person.AssignedShifts.Count.ToString(); foreach (Shift assignedShift in person.AssignedShifts) { personGridView.Rows[row].Cells[2].Value = personGridView.Rows[row].Cells[2].Value + "Day " + assignedShift.Day.ID.ToString() + " Shift " + assignedShift.ID.ToString() + " "; } } CheckPersonAssignments(fittest.Chromosome.TimePeriod); //Adding the costs and other information of this solution to the resultview shiftAssignmentCostTextBox.Text = fittest.Chromosome.ShiftAssignmentConstraintCost.ToString(); personAssignmentCostTextBox.Text = fittest.Chromosome.PersonAssignmentConstraintCost.ToString(); generationTextBox.Text = fittest.Generation.ToString(); timeTextBox.Text = fittest.TimeToFind.ToString(); objectiveCostTextBox.Text = fittest.Chromosome.ObjectiveCost.ToString(); calculationSpeedTextBox.Text = ((double)fittest.Generation / (double)fittest.TimeToFind.TotalSeconds).ToString(); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Start the search fittest = Optimize.FindOptimal(timePeriod, (int)timeLimit.Value, (int)generationLimit.Value, e, sender as BackgroundWorker); }