private void AssignNextToCurrentIfBecameBetter() { if ((_next.FitnessFuntionValue > _current.FitnessFuntionValue) && ValidateDescendant(_next)) { _current = _next; ++_successAmount; } }
private void TryGeneratingBetterDescendant() { for (var i = 0; i < _mIteration; i++) { _current = new DescendantSecond(RandomInitializer.Rand.Next(Scheduler.RealizationsAmount), RandomInitializer.Rand.Next(Scheduler.RoomsAmount)); _current.CalculateFitnessFunction(); if (ValidateDescendant(_current)) { break; } _swappingDescendant = _current; _current = null; } }
public void AssignDescendant(DescendantSecond descendant) { var thisRealization = Scheduler.Realizations[descendant.RealizationId]; var thisRoom = Scheduler.Rooms[descendant.RoomId]; thisRealization.RoomId = thisRoom.RoomId; var k = 0; var assignmentSuccessfulFlag = false; foreach (var daysHours in thisRoom.FreeHoursInEachDay) { if (daysHours >= thisRealization.CourseLength) //if(thisRoom.getFreeHoursInEachDay()[dayHours] >= thisRealization.courseLength) { for (var j = 0; j <= (thisRoom.MaxHoursADay - thisRealization.CourseLength); j++) { if (thisRoom.HoursSchedule[k, j] == -1) { for (var x = 0; x < thisRealization.CourseLength; x++) { thisRoom.HoursSchedule[k, j + x] = thisRealization.RealizationId; } assignmentSuccessfulFlag = true; } if (assignmentSuccessfulFlag) { break; } } break; } ++k; } thisRoom.CountOccupiedHoursNumber(); thisRealization.RecalculateFitnessFunction(); }
public bool ValidateDescendant(DescendantSecond descendant) { var thisRealization = Scheduler.Realizations[descendant.RealizationId]; var thisRoom = Scheduler.Rooms[descendant.RoomId]; thisRoom.CountOccupiedHoursNumber(); if (thisRealization.RoomId != -1) { return(false); } // this realization is already assigned to a room if (thisRealization.EnrolledParticipantAmount > thisRoom.SeatsNumber) { return(false); } // not enough seats for participants var fitFlag = false; for (var i = 0; i < thisRoom.FreeHoursInEachDay.Length; i++) { if (thisRoom.FreeHoursInEachDay[i] >= thisRealization.CourseLength) { fitFlag = true; break; } } if (!fitFlag) { return(false); } // not enough free hours for running realization in the room return(true); }
private void GenerateNextDescendant(int newRealizationId, int newRoomId) { _next = new DescendantSecond(newRealizationId, newRoomId); _next.CalculateFitnessFunction(); }