//! Calculates a schedule from the defined problem /*! * \pram ScheduleProblemInterface defined problem with contactwindows * This Function will calculate the solution to the problem defined in * Schedule Problem Interface */ public void CalculateSchedule(ScheduleProblemInterface problem) { //retrive all the contactwindows that need to be scheduled //ContactWindowsVector set = problem.getContactWindows(); //Scheduler Magic until is Complete returns true //No Element of the ContactWindowsVector set should be deleted //To Schedule a item call set.getAt(index).setSheduled() //To Unschedule a item call set.getAt(index).unShedule() }
//! Calculates a schedule from the defined problem /*! * \pram ScheduleProblemInterface defined problem with contactwindows * This Function will calculate the solution to the problem defined in * Schedule Problem Interface */ public void CalculateSchedule(ScheduleProblemInterface problem) { set = problem.getContactWindows(); schedule = new ContactWindowsVector(); set.sort(Structs.sortByField.TIME); while (!isComplete()) { for (int i = 0; i < set.Count(); i++) { bool collisionFound = false; List <int> collisionSet = new List <int>(); collisionSet.Add(i); for (int j = 1; j < set.Count() - 1; j++) { collisionFound = checkCollision(set.getAt(i), set.getAt(j)); collisionSet.Add(j); } if (collisionFound) { set.getAt(i).setSheduled(); for (int k = 0; k < collisionSet.Count - 1; k++) { set.getAt(collisionSet[k]).unShedule(); } } else { schedule.add(set.getAt(i)); set.deleteAt(i); i--; } } } //retrive all the contactwindows that need to be scheduled //ContactWindowsVector set = problem.getContactWindows(); //Scheduler Magic until is Complete returns true //No Element of the ContactWindowsVector set should be deleted //To Schedule a item call set.getAt(index).setSheduled() //To Unschedule a item call set.getAt(index).unShedule() }
//! Calculate scheduling solution from certain startpoint /*! * calculate a schedule from a certain starting point * if iterating trhough every contact window can be used to brute force * the scheduling solution * \param ScheduleProblemInterface to solve scheduling problem * \param int point from which to start from */ public void BruteForceSchedule(ScheduleProblemInterface problem, int step) { objective = problem.getObjectiveFunction(); set = problem.getContactWindows(); int nrOfAllContacts = set.Count(); ContactWindowsVector set1 = new ContactWindowsVector(); ContactWindowsVector set2 = new ContactWindowsVector(); //double maxFitness = 0.0; int count = 0; set1.add(set.getAt(step)); set.deleteAt(step); while (!isComplete()) { int pos = -1; double maxFitness = 0.0; for (int i = 0; i < set.Count(); i++) { objective.calculateValues(set1, set, nrOfAllContacts, set.getAt(i)); double fitness = objective.getObjectiveResults(); if (fitness > maxFitness) { maxFitness = fitness; pos = i; } if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } } bool found = false; if (pos >= 0) { for (int i = 0; i < set1.Count(); i++) { if (set.getAt(pos).checkConflikt(set1.getAt(i))) { if (set.getAt(pos).getSatName() == set1.getAt(i).getSatName() || set.getAt(pos).getStationName() == set1.getAt(i).getStationName()) { set2.add(set.getAt(pos)); set2.getLast().unShedule(); set.deleteAt(pos); found = true; break; } } if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } } if (!found) { set1.add(set.getAt(pos)); set1.getLast().setSheduled(); set.deleteAt(pos); } } else { count++; } } set.add(set1); set.add(set2); schedule = set; }
//! Calculates a schedule from the defined problem /*! * \pram ScheduleProblemInterface defined problem with contactwindows * This Function will calculate the solution to the problem defined in * Schedule Problem Interface */ public void CalculateSchedule(ScheduleProblemInterface problem) { objective = problem.getObjectiveFunction(); result = problem.getContactWindows(); if (adaptiveMaxIterations) { maxNumberOfIteration = result.Count() * 4; } if (randomStart) { result.randomize(); fillContacts(result); } if (mainform != null) { mainform.setProgressBar(maxNumberOfIteration); } currentFitness = 0.0; result.getAt(0).setSheduled(); while (!isComplete()) { for (int i = 0; i < result.Count(); i++) { iterations++; for (int j = 0; j < result.Count(); j++) { if (i != j && result.getAt(i).checkConflikt(result.getAt(j))) { if (result.getAt(i).getStationName() == result.getAt(j).getStationName() || result.getAt(i).getSatName() == result.getAt(j).getSatName()) { //collision detected result.getAt(i).unShedule(); result.getAt(j).setSheduled(); double newFitness = getFitness(result); if (newFitness < currentFitness) { result.getAt(j).unShedule(); result.getAt(i).setSheduled(); } else { currentFitness = newFitness; break; } } } } } if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } if (mainform != null) { mainform.updateProgressBar(iterations); } currentFitness = getFitness(result); fillContacts(result); } }
//! Starts the process of finding the best solution through genetor /*! * \param ScheduleProblemInterface definition of the problem to solve */ public void CalculateSchedule(ScheduleProblemInterface problem) { objective = problem.getObjectiveFunction(); set = problem.getContactWindows(); //Sort by time set.sort(Structs.sortByField.TIME); nrOfContacts = set.Count(); nrOfStation = set.getNumberOfStation(); nrOfSatellites = set.getNumberOfSatellites(); satelliteList = new List <string>(set.getSatelliteNames()); stationList = new List <string>(set.getStationNames()); fitness = new double[popSize]; bestSolution = new int[nrOfContacts]; if (runUnitlTime) { startrunTime = DateTime.Now; double h = hours; startrunTime = startrunTime.AddHours(h); } generation = 0; //create 5-10 random schedules from the Data population = new List <int[]>(); for (int i = 0; i < popSize; i++) { population.Add(new int[nrOfContacts]); fitness[i] = Constants.maxInt; } //Randomize the starting Population Random rnd = new Random(); for (int k = 0; k < popSize; k++) { for (int i = 0; i < nrOfContacts; i++) { int randStart = rnd.Next(0, 100); if (randStart <= genCrea) { population[k][i] = 1; } } } //-- bool foundSolution = false; while (!foundSolution) { generation++; //Console.WriteLine("Generation: " + generation.ToString() ); //elliminate all collsions either by using random chance or //by priority. //check fitness of each one (survival rate) for (int i = 0; i < popSize; i++) { surviveConflicts(population[i], rnd, conflictValue); fitness[i] = checkFitness(population[i]); } if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } //take only the fittest survivalOfFittest(fitness, population); //Combine randomly and generate children createChildren(population, fitness, rnd); //Mutate (remove or add requests by slight change) for (int i = 0; i < popSize; i++) { mutate(population[i], rnd); } //check if Solution has been found foundSolution = isComplete(); if (generatePlotData > 0) { WriteLog(); } if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } if (f != null) { f.incrementProgressBar(); } } if (solveConflict) { surviveConflicts(bestSolution, rnd, conflictValue); } // //surviveConflicts(bestSolution, rnd); setSchedule(bestSolution, set); Console.WriteLine("Found Solution after " + generation.ToString() + " Generations"); result = set; result.randomize(); fillGaps(); if (generatePlotData > 0) { plotWr.Close(); } if (f != null) { f.resetProgressBar(); } }
//! Calculates a schedule from the defined problem /*! * \pram ScheduleProblemInterface defined problem with contactwindows * Greedy approach earliest job first. */ public void CalculateSchedule(ScheduleProblemInterface problem) { set = problem.getContactWindows(); ContactWindowsVector set1 = new ContactWindowsVector(); ContactWindowsVector set2 = new ContactWindowsVector(); List <string> staName = set.getStationNames(); //while set is not empty do while (!isComplete()) { //loop through all Stations for (int i = 0; i < staName.Count(); i++) { int pos = -1; double earliest = 9999.99; int priority = 4; //loop through all Contacts and find the item that finisches //first and has the highest priority. for (int k = 0; k < set.Count(); k++) { if (set.getAt(k).getStationName() == staName[i]) { if (set.getAt(k).getStopTime().getEpoch() < earliest && (int)set.getAt(k).getPriority() <= priority) { pos = k; earliest = set.getAt(k).getStopTime().getEpoch(); priority = (int)set.getAt(k).getPriority(); } } } //update Progress Bar on Main Form if (Properties.Settings.Default.global_MaxPerf == false) { System.Windows.Forms.Application.DoEvents(); } if (f != null) { f.incrementProgressBar(); } //the found earliest job is added to set1 if its empty //or no other contact in set1 is conflicting with it //if there is a conflict add this element to set2 //Then the element is deleted from set1 if (pos > -1) { if (set1.isEmpty()) { set1.add(set.getAt(pos)); set.deleteAt(pos); } else { bool found = false; for (int k = 0; k < set1.Count(); k++) { if (set.getAt(pos).checkConflikt(set1.getAt(k))) { if (set.getAt(pos).getSatName() == set1.getAt(k).getSatName()) { set2.add(set.getAt(pos)); set.deleteAt(pos); found = true; break; } } } if (!found) { set1.add(set.getAt(pos)); set.deleteAt(pos); } } } } } for (int i = 0; i < set1.Count(); i++) { set1.getAt(i).setSheduled(); } for (int i = 0; i < set2.Count(); i++) { set2.getAt(i).unShedule(); } set.add(set1); set.add(set2); schedule = set; solveConflictsByPriority(); if (f != null) { f.resetProgressBar(); } }