private double calculateLSLocalSolutionValue(ArrayList acList) { double lsSolutionValue = 0; foreach (ACourse ac in acList) { ATeacher at = ac.MyATeacher; foreach (AbstractSoftConstraint sc in at.MySoftConstraints) { lsSolutionValue = lsSolutionValue + sc.evaluateSC(); } if (!ac.IsHTCourse)//?? check this for AEP soft constraints { foreach (AbstractSoftConstraint sc in ac.MySoftConstraints) { lsSolutionValue = lsSolutionValue + sc.evaluateSC(); } AEduProgram aep = (AEduProgram)ac.MyAEduProgram; foreach (AbstractSoftConstraint sc in aep.MySoftConstraints) { lsSolutionValue = lsSolutionValue + sc.evaluateSC(); } } } return(lsSolutionValue); }
public override double evaluateSC() { try { ATeacher at = (ATeacher)_theObj; int mySC_MaxHoursDaily = (int)_myArgs[0]; double myWeight = (double)_myArgs[1]; int numOfIncludedDaysPerWeek = AGlobal.NUM_OF_INCLUDED_DAYS_PER_WEEK; int numOfTermsPerDay = AGlobal.NUM_OF_INCLUDED_TERMS_PER_DAY; int numOfSlotsPerRoom = numOfIncludedDaysPerWeek * numOfTermsPerDay; int[] occupDays = new int[numOfIncludedDaysPerWeek]; if (at.MyFixedLessonNodes != null) { foreach (ALessonNode aln in at.MyFixedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupDays[indexCol]++; } } } if (at.MyTempAllocatedLessonNodes != null) { foreach (ALessonNode aln in at.MyTempAllocatedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupDays[indexCol]++; } } } for (int j = 0; j < numOfIncludedDaysPerWeek; j++) { if (occupDays[j] > mySC_MaxHoursDaily) { return(myWeight); } } return(0); } catch (Exception ex) { Console.WriteLine("Ошибка: " + ex.Message); return(0); } }
public override double evaluateSC() { ATeacher at = (ATeacher)_theObj; int mySC_MaxDaysPerWeek = (int)_myArgs[0]; double myWeight = (double)_myArgs[1]; int numOfIncludedDaysPerWeek = AGlobal.NUM_OF_INCLUDED_DAYS_PER_WEEK; int numOfTermsPerDay = AGlobal.NUM_OF_INCLUDED_TERMS_PER_DAY; int numOfSlotsPerRoom = numOfIncludedDaysPerWeek * numOfTermsPerDay; bool[] occupDaysBool = new bool[numOfIncludedDaysPerWeek]; if (at.MyFixedLessonNodes != null) { foreach (ALessonNode aln in at.MyFixedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupDaysBool[indexCol] = true; } } } if (at.MyTempAllocatedLessonNodes != null) { foreach (ALessonNode aln in at.MyTempAllocatedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupDaysBool[indexCol] = true; } } } int usedDays = 0; for (int j = 0; j < numOfIncludedDaysPerWeek; j++) { if (occupDaysBool[j]) { usedDays++; } } if (usedDays > mySC_MaxDaysPerWeek) { return(myWeight); } return(0); }
public ACourse(AEduProgram myAEduProgram, ATeacher myATeacher, string groupName, bool[] myBoolPosTS, string name) { _name = name; _myAEduProgram = myAEduProgram; _myATeacher = myATeacher; _groupName = groupName; _myAllLessonNodesForAllocation = new ArrayList(); _myBoolPosTS = myBoolPosTS; _numOfPossTSAtStart = AGlobal.getNumOfPossTS(_myBoolPosTS); _mySoftConstraints = new ArrayList(); }
public int selectNewTimeSlot(ArrayList partialSolution, bool[] acMyBoolPossTSTemp, Random randObj) { int totalLen = _pheromoneTable.GetLength(0); int myPredecessor; int count = partialSolution.Count; if (count > 0) { myPredecessor = ((ALessonNode)partialSolution[count - 1]).CurrPosition - 1; } else { myPredecessor = 0; } //_myCurrentPredecessor = myPredecessor; double[] totalProbabilityTable = new double[totalLen]; double totalSumPheromoneT = 0.0; double totalSumTotalSquareProbT = 0.0; ACourse ac = this.MyACourse; ATeacher at = ac.MyATeacher; for (int n = 0; n < totalLen; n++) { if (acMyBoolPossTSTemp[n]) { //totalSumPheromoneT += _pheromoneTable[myPredecessor, n]; totalSumPheromoneT += _pheromoneTable[n]; } } for (int n = 0; n < totalLen; n++) { if (acMyBoolPossTSTemp[n]) { //totalProbabilityTable[n] = Math.Pow(((double)_pheromoneTable[myPredecessor, n] / (double)totalSumPheromoneT), 2.0); totalProbabilityTable[n] = Math.Pow(((double)_pheromoneTable[n] / (double)totalSumPheromoneT), 2.0); totalSumTotalSquareProbT += totalProbabilityTable[n]; } } double runningtotal = 0.0; double randValue = randObj.Next(0, 100000); randValue = randValue / 100000.0; int winningIndex = 0; for (int n = 0; n < totalLen; n++) { if (acMyBoolPossTSTemp[n]) { runningtotal += totalProbabilityTable[n] / totalSumTotalSquareProbT; if (runningtotal > randValue) { winningIndex = n + 1; return(winningIndex); } } } return(winningIndex); }
public override double evaluateSC() { ATeacher at = (ATeacher)_theObj; int mySC_MaxHoursContinuously = (int)_myArgs[0]; double myWeight = (double)_myArgs[1]; int numOfIncludedDaysPerWeek = AGlobal.NUM_OF_INCLUDED_DAYS_PER_WEEK; int numOfTermsPerDay = AGlobal.NUM_OF_INCLUDED_TERMS_PER_DAY; int numOfSlotsPerRoom = numOfIncludedDaysPerWeek * numOfTermsPerDay; bool[,] occupTSBool = new bool[numOfTermsPerDay, numOfIncludedDaysPerWeek]; if (at.MyFixedLessonNodes != null) { foreach (ALessonNode aln in at.MyFixedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexRow = (tsIndex - 1) % numOfTermsPerDay; int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupTSBool[indexRow, indexCol] = true; } } } if (at.MyTempAllocatedLessonNodes != null) { foreach (ALessonNode aln in at.MyTempAllocatedLessonNodes) { int tsIndex = aln.CurrPosition; if (tsIndex > 0) { int indexRow = (tsIndex - 1) % numOfTermsPerDay; int indexCol = (int)Math.Floor((decimal)((tsIndex - 1) % numOfSlotsPerRoom) / numOfTermsPerDay); occupTSBool[indexRow, indexCol] = true; } } } for (int j = 0; j < occupTSBool.GetLength(1); j++) { int hoursCont = 0; bool blockCheckStarted = false; int lastRowIndex = 0; for (int k = 0; k < occupTSBool.GetLength(0); k++) { if (occupTSBool[k, j] == true) { if (!blockCheckStarted) { blockCheckStarted = true; lastRowIndex = k; hoursCont = 1; } else { lastRowIndex = k; hoursCont++; } } else { if (blockCheckStarted) { if (hoursCont > mySC_MaxHoursContinuously) { return(myWeight); } hoursCont = 0; } } } //end of column if (hoursCont > mySC_MaxHoursContinuously) { return(myWeight); } } return(0); }