//! Start Pseudo BruteForce method /*! * /param SChedulerInterface scheduler to run * /param SchedulingProblem to solve * /param Main mainform to update Information * Currently can only be called with the greedy scheduler */ public static void startBruteForce(SchedulerInterface scheduler, SchedulingProblem problem, Main mainform) { if (scheduler.GetType() == typeof(GreedyScheduler)) { TimeMeasurement tm = new TimeMeasurement(); GreedyScheduler greedy = (GreedyScheduler)scheduler; double bestFitness = 0.0; for (int iteration = 0; iteration < problem.getContactWindows().Count(); iteration++) { tm.activate(); greedy.BruteForceSchedule(problem, iteration); mainform.updateCalculationTime(tm.getValueAndDeactivate()); ObjectiveFunction obj = problem.getObjectiveFunction(); obj.calculateValues(greedy.getFinischedSchedule()); mainform.updateCalculationTime(tm.getValueAndDeactivate()); mainform.setNumberOfGeneration(iteration); if (bestFitness <= obj.getObjectiveResults()) { bestFitness = obj.getObjectiveResults(); displayResults(mainform, scheduler, iteration); } } } //else do nothing }
public GeneticAlgorithm(int maxIterations, int populationCount, SchedulingProblem schedulingProblem, float mutationProbability = 1) { _maxIterations = maxIterations; _populationCount = populationCount; _schedulingProblem = schedulingProblem; _mutationProbability = mutationProbability; _population = CreatePopulation(); }
public CockroachAlgorithm(int maxStep, int visual, int maxIterations, int populationCount, SchedulingProblem schedulingProblem) : base() { _maxStep = maxStep; _visual = visual; _maxIterations = maxIterations; _schedulingProblem = schedulingProblem; _populationCount = populationCount; _population = CreatePopulation(); FindGlobalOptimum(); }
public void test_creating_scheduling_problem_from_string_input(string dataString, int jobs, int machines, int timeSeed, int machineSeed, int upperBound, int lowerBound) { // Act var schedulingProblem = new SchedulingProblem(dataString); // Assert Assert.AreEqual(jobs, schedulingProblem.Jobs.Count); Assert.IsTrue(schedulingProblem.Jobs.TrueForAll(j => j.Operations.Count == machines)); Assert.AreEqual(timeSeed, schedulingProblem.ComparativeData.TimeSeed); Assert.AreEqual(machineSeed, schedulingProblem.ComparativeData.MachineSeed); Assert.AreEqual(upperBound, schedulingProblem.ComparativeData.UpperBound); Assert.AreEqual(lowerBound, schedulingProblem.ComparativeData.LowerBound); }
//! set the Scheduling Problem /*! * /param ContactWindowsVector contacts to schedule * /param ObjectiveFunction obective to solve problems */ public static SchedulingProblem setSchedulingProblem(ContactWindowsVector contacts, ObjectiveFunction objective) { SchedulingProblem problem = new SchedulingProblem(); problem.setContactWindows(contacts); problem.removeUnwantedContacts(Properties.Settings.Default.orbit_Minimum_Contact_Duration_sec); problem.setObjectiveFunction(objective); /* * The contact windows that have been calculate are randomized * to imporve the result of the greedy algorithms. If the * turning the randomiziation off will lead to the greedy * algorithms to only schedule contacts for the first few * groundstation ignoring others. */ problem.getContactWindows().randomize(Properties.Settings.Default.global_Random_Seed); return(problem); }
//! get Selected Scenario /*! * Generates the Scenario selected */ private void getScenario(SchedulingProblem problem) { /* * Generate the selected Scenarios * These are defined in the SchedulingProblem Class * Other Scenarios can be selected here if they are added */ if (comboScenarioBox.SelectedIndex == 0) { problem.GenerateSzenarioA(); } if (comboScenarioBox.SelectedIndex == 1) { problem.GenerateSzenarioB(Properties.Settings.Default.global_Random_Seed); } if (comboScenarioBox.SelectedIndex == 2) { problem.GenerateSzenarioC(Properties.Settings.Default.global_Random_Seed); } if (comboScenarioBox.SelectedIndex == 3) { problem.GenerateSzenarioD(Properties.Settings.Default.global_Random_Seed); } }
//! Calculate Schedule /*! * Calculates the orbit positions of the selected Satellites for the * given time period and then the contact windows for each selected * ground station. The calculation of the orbits and contact windows * is done in multiple threads to save time. Afterwards the selected * scheduler will compute a solution. * New schedulers can be added inside this function below. */ private void startSchedule(bool useBruteForce = false) { string logFile = MainFunctions.getLogFileName(); prepareStart(); updateLog(logFile, "Starting"); //Set Start and Stop Time One_Sgp4.EpochTime startTime = getStartTime(); One_Sgp4.EpochTime stopTime = getStopTime(); updateLog(logFile, "StartTime: " + startTime.ToString()); updateLog(logFile, "StartTime: " + stopTime.ToString()); // create empty Lists and data containers for Data satTleData = new List <One_Sgp4.Tle>(); stationData = new List <Ground.Station>(); //check if contacts vector has not been already created or loaded //from save file bool resetScenario = true; if (contactsVector == null || changedParameters == true) { contactsVector = new Definition.ContactWindowsVector(); contactsVector.setStartTime(startTime); contactsVector.setStopTime(stopTime); //get selected Satellites to calculate Orbits satTleData = getSatelliteData(logFile); stationData = getStationData(logFile); //starting with the orbit calculations updateLog(logFile, "Staring Orbit Calculations"); //Calculate Orbits and Contact Windows CalculateContacts(startTime, stopTime, logFile); } else { // resuse old ContactWindows startTime = contactsVector.getStartTime(); stopTime = contactsVector.getStopTime(); resetScenario = false; } AutoSave(logFile); updateLog(logFile, "Setting Up Scheduler"); //Set Scheduling Problem //set Objective Function setObjectiveFunction(); string test = objectivefunct.ToString(); //objectivefunct = new ObjectiveFunction(Global.Structs.ObjectiveEnum.DURATION, // Global.Structs.ObjectiveEnum.FAIRNESSATELITE, Global.Structs.ObjectiveEnum.FAIRNESSTATION, // Global.Structs.ObjectiveEnum.SCHEDULEDCONTACTS); SchedulingProblem problem = RunScheduler.setSchedulingProblem(contactsVector, objectivefunct); /* Generate the selected Scenarios * These are defined in the SchedulingProblem Class * Other Scenarios can be selected here if they are added */ if (resetScenario != false) { getScenario(problem); } //enable time measurment Class TimeMeasurement tm = new Performance.TimeMeasurement(); startScheduleButton.Enabled = true; scheduler = null; //create new scheduler object and set settings if (radioGenetic.Checked) { scheduler = RunScheduler.setScheduler(new GeneticScheduler(), this); } if (radioEFTGreedy.Checked) { scheduler = RunScheduler.setScheduler(new EftGreedyScheduler(), this); } if (radioGreedy.Checked) { scheduler = RunScheduler.setScheduler(new GreedyScheduler(), this); } if (radioHillClimber.Checked) { scheduler = RunScheduler.setScheduler(new HillClimberScheduler(), this); } //----------------------------------------------------------------- //---------------------------Add New SCHEDULER HERE----------------- //----------------------------------------------------------------- /* * if (radioNEW.Checked * { * scheduler = RunScheduler.setScheduler(new Scheduler.ExampleScheduler(), this); * } */ //----------------------------------------------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- updateLog(logFile, "starting " + scheduler.ToString()); //start Time Meassurment tm.activate(); if (!useBruteForce) { RunScheduler.startScheduler(scheduler, problem); } else { RunScheduler.startBruteForce(scheduler, problem, this); } //get Time Measurment updateCalculationTime(tm.getValueAndDeactivate()); //display resulst on main Page RunScheduler.displayResults(this, scheduler); //finisch clean up and write to logs if necesarry finischSchedule(scheduler.ToString(), logFile); }
public bool runThisRun() { results = new List <string>(); DataBase.DataBase db = new DataBase.DataBase(); bool status = true; List <Ground.Station> stationData = new List <Ground.Station>(); for (int i = 0; i < stationList.Count; i++) { Ground.Station station = db.getStationFromDB(stationList[i]); stationData.Add(station); //updateLog(logfile, "Adding Station: " + station.getName()); } System.Windows.Forms.Application.DoEvents(); List <One_Sgp4.Tle> tleData = new List <Tle>(); for (int i = 0; i < satelliteList.Count; i++) { One_Sgp4.Tle sattle = db.getTleDataFromDB(satelliteList[i]); tleData.Add(sattle); //updateLog(logfile, "Adding Satellite: " + sattle.getName()); } System.Windows.Forms.Application.DoEvents(); ContactWindowsVector contactsVector = MainFunctions2.calculateContactWindows(tleData, stationData, startTime, stopTime); System.Windows.Forms.Application.DoEvents(); scheduler = null; switch (schedulerName) { case "Genetic": string[] settString = settings.Split(';'); scheduler = new GeneticScheduler(Convert.ToInt32(settString[0]), Convert.ToInt32(settString[1]), Convert.ToInt32(settString[2]), Convert.ToInt32(settString[4]), Convert.ToBoolean(settString[5]), Convert.ToDouble(settString[6]), Convert.ToBoolean(settString[7]), Convert.ToBoolean(settString[8])); break; case "Greedy": scheduler = new GreedyScheduler(); break; case "EFT-Greedy": scheduler = new EftGreedyScheduler(); break; case "Hill-Climber": string[] settString2 = settings.Split(';'); scheduler = new HillClimberScheduler(Convert.ToBoolean(settString2[0]), Convert.ToBoolean(settString2[2]), Convert.ToInt32(settString2[1])); break; } ObjectiveFunction objective = new ObjectiveFunction(Forms.ObjectiveBuilderForm.getObjectiveEnumsByName(objectiveFunction)); System.Windows.Forms.Application.DoEvents(); SchedulingProblem problem = new SchedulingProblem(); problem.setContactWindows(contactsVector); problem.removeUnwantedContacts(Properties.Settings.Default.orbit_Minimum_Contact_Duration_sec); problem.setObjectiveFunction(objective); problem.getContactWindows().randomize(Properties.Settings.Default.global_Random_Seed); getScenario(problem, scenario); System.Windows.Forms.Application.DoEvents(); TimeMeasurement tm = new TimeMeasurement(); tm.activate(); scheduler.CalculateSchedule(problem); string time = tm.getValueAndDeactivate(); System.Windows.Forms.Application.DoEvents(); contactsVector = scheduler.getFinischedSchedule(); System.Windows.Forms.Application.DoEvents(); if (scheduler != null) { ObjectiveFunction objfunc = scheduler.getObjectiveFunction(); if (objfunc == null) { objfunc = new ObjectiveFunction(); } objfunc.calculateValues(scheduler.getFinischedSchedule()); double fitness = objfunc.getObjectiveResults(); int _H = scheduler.getFinischedSchedule().getNrOfScheduled(); double _H1 = objfunc.getScheduledContactsValue(); int _H2 = GeneralMeasurments.getNrOfConflicts(scheduler.getFinischedSchedule()); double _H3 = objfunc.getStationFairnessValue(); double _H4 = objfunc.getSatelliteFairnessValue(); double _H5 = GeneralMeasurments.getDurationOfScheduledContacts(scheduler.getFinischedSchedule()); results.Add("Run: " + schedulerName); results.Add("Fitness Value:" + objfunc.getObjectiveResults().ToString()); results.Add("Scheduled Contacts: " + scheduler.getFinischedSchedule().getNrOfScheduled().ToString() + " / " + contactsVector.Count().ToString()); results.Add("Collisions: " + GeneralMeasurments.getNrOfConflicts(scheduler.getFinischedSchedule()).ToString()); results.Add("Fairnes Stations: " + objfunc.getStationFairnessValue().ToString()); results.Add("Fairnes Satellites: " + objfunc.getSatelliteFairnessValue().ToString()); results.Add("Duration: " + GeneralMeasurments.getDurationOfScheduledContacts(scheduler.getFinischedSchedule()).ToString() + " sec."); results.Add("Calculation Time: " + time); results.Add("Scheduled By Priority: " + GeneralMeasurments.getNrOfPrioritysScheduled(scheduler.getFinischedSchedule())); results.Add("Scheduled UWE-3: " + GeneralMeasurments.getNrOfUweContacts(scheduler.getFinischedSchedule()).ToString()); //Log.writeResults(logfile, schedulerName, results); if (results == null) { status = false; } } else { status = false; } cancel = false; return(status); }
//! Start Scheduler /*! * /param SchedulerInterface scheduler to run * /param SchedulingProblems problem to solve */ public static void startScheduler(SchedulerInterface scheduler, SchedulingProblem problem) { scheduler.setObjectiveFunktion(problem.getObjectiveFunction()); scheduler.CalculateSchedule(problem); }