//! calculate the fitness value of the given contactvectors if a contact is added

        /*!
         * \param ContactWindowsVector contact windows to check
         * \param CotnactWindowsVector contacts of the complete problem
         * \param int max number of Contacts of the Scheduling problem
         * \param ContactWindow to add
         */
        // Call to calculate Objective Values for Fitness
        public void calculateValues(ContactWindowsVector currentSolution, ContactWindowsVector completeContacts, int numberOfAllContacts,
                                    ContactWindow contactToAdd)
        {
            currentSolution.add(contactToAdd);
            calculate(currentSolution, calcualteMaxPrioValue(completeContacts), numberOfAllContacts, null, completeContacts);
            currentSolution.deleteAt(currentSolution.Count() - 1);
        }
        //! 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()
        }
Beispiel #3
0
        //! Open and Load saved scheduling data

        /*!
         * \param string path to Load file
         * \param Main Form to update loading bar
         */
        public static ContactWindowsVector loadFile(string filepath, Main f)
        {
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filepath);
            XmlNodeList dataNodes = xmlDoc.SelectNodes("//Contacts/ContactWindow");

            f.setProgressBar(dataNodes.Count);

            int    startYear  = Int32.Parse(xmlDoc.SelectSingleNode("//Contacts/StartYear").InnerText);
            double startEpoch = double.Parse(xmlDoc.SelectSingleNode("//Contacts/StartEpoch").InnerText);
            int    stopYear   = Int32.Parse(xmlDoc.SelectSingleNode("//Contacts/StopYear").InnerText);
            double stopEpoch  = double.Parse(xmlDoc.SelectSingleNode("//Contacts/StopEpoch").InnerText);

            One_Sgp4.EpochTime start = new One_Sgp4.EpochTime(startYear, startEpoch);
            One_Sgp4.EpochTime stop  = new One_Sgp4.EpochTime(stopYear, stopEpoch);

            ContactWindowsVector saved = new ContactWindowsVector();

            saved.setStartTime(start);
            saved.setStopTime(stop);
            int count = 0;

            foreach (XmlNode node in dataNodes)
            {
                string             sa        = node.SelectSingleNode("SatName").InnerText;
                string             st        = node.SelectSingleNode("StaName").InnerText;
                int                year      = Int32.Parse(node.SelectSingleNode("StartYear").InnerText);
                double             epoch     = double.Parse(node.SelectSingleNode("StartTime").InnerText);
                ContactWindow      cw        = new ContactWindow(sa, st);
                One_Sgp4.EpochTime starttime = new One_Sgp4.EpochTime(year, epoch);
                cw.setStartTime(starttime);
                year  = Int32.Parse(node.SelectSingleNode("StopYear").InnerText);
                epoch = double.Parse(node.SelectSingleNode("StopTime").InnerText);
                One_Sgp4.EpochTime stoptime = new One_Sgp4.EpochTime(year, epoch);
                cw.setStopTime(stoptime);
                if (node.SelectSingleNode("Scheduled").InnerText != "False")
                {
                    cw.setSheduled();
                }
                cw.setExclusion(bool.Parse(node.SelectSingleNode("Scheduled").InnerText));
                cw.setID(Guid.Parse(node.SelectSingleNode("ID").InnerText));
                cw.setRequestID(Guid.Parse(node.SelectSingleNode("RequID").InnerText));
                cw.setPriority(Global.Funktions.ParseEnum <Global.Structs.priority>(node.SelectSingleNode("Priority").InnerText));

                XmlNodeList children = node.SelectNodes("TrackingData/Data");
                foreach (XmlNode childNode in children)
                {
                    double       azi  = double.Parse(childNode.SelectSingleNode("Azimuth").InnerText);
                    double       ele  = double.Parse(childNode.SelectSingleNode("Elevation").InnerText);
                    double       ran  = double.Parse(childNode.SelectSingleNode("Range").InnerText);
                    double       ranR = double.Parse(childNode.SelectSingleNode("RangeRate").InnerText);
                    string       time = childNode.SelectSingleNode("TimeStamp").InnerText;
                    TrackingData td   = new TrackingData(azi, ele, ran, time);
                    cw.addTrackingData(td);
                }
                f.updateProgressBar(count++);
                System.Windows.Forms.Application.DoEvents();
                saved.add(cw);
            }
            f.resetProgressBar();
            return(saved);
        }
Beispiel #4
0
        //! 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;
        }
Beispiel #5
0
        //! Calculate Contact windows

        /*!
         * /param List<TLE> list of Tle data
         * /param List<Statons> list of Stations
         * /param EpochTime starting time
         * /param Epoch Time stoping time
         * /param string Logfile = null
         * /param Main mainform to update = null
         * cacluated the orbits of selected satellites and then the contact windows
         * for each station in the given time frame
         */
        public static ContactWindowsVector calculateContactWindows(List <Tle> tleData,
                                                                   List <Station> stations, EpochTime start, EpochTime stop, string logfile = null,
                                                                   Main mainform = null)
        {
            ContactWindowsVector contacts = new ContactWindowsVector();
            double accuracy = Properties.Settings.Default.orbit_Calculation_Accuracy;

            //Calculate Orbits of the selected Satellites

            Sgp4[] tasks   = new Sgp4[tleData.Count()];
            Task[] threads = new Task[tleData.Count()];
            for (int i = 0; i < tleData.Count(); i++)
            {
                tasks[i] = new One_Sgp4.Sgp4(tleData[i], Properties.Settings.Default.orbit_Wgs);
                tasks[i].setStart(start, stop, accuracy / 60.0);
                threads[i] = new Task(tasks[i].starThread);
            }
            for (int i = 0; i < threads.Count(); i++)
            {
                //start each Thread
                threads[i].Start();
            }
            try
            {
                //wait till all threads are finished
                Task.WaitAll(threads);
            }
            catch (AggregateException ae)
            {
                //Logg any exceptions thrown
                if (logfile != null)
                {
                    MainFunctions.updateLog(logfile, "Orbit Predictions Exception: " + ae.InnerExceptions[0].Message, mainform);
                }
            }

            //Calculate Contact Windows
            if (logfile != null)
            {
                MainFunctions.updateLog(logfile, "Starting Contact Window Calculation:", mainform);
            }
            for (int i = 0; i < tleData.Count(); i++)
            {
                Ground.InView[] inViews   = new Ground.InView[stations.Count()];
                Task[]          inThreads = new Task[stations.Count()];
                for (int k = 0; k < stations.Count(); k++)
                {
                    inViews[k]   = new Ground.InView(stations[k], start, tasks[i].getRestults(), tleData[i].getName(), accuracy);
                    inThreads[k] = new Task(inViews[k].calcContactWindows);
                }
                for (int k = 0; k < stations.Count(); k++)
                {
                    //start every thread
                    inThreads[k].Start();
                }
                try
                {
                    //whait for all threads to finish
                    Task.WaitAll(inThreads);
                }
                catch (AggregateException ae)
                {
                    if (logfile != null)
                    {
                        MainFunctions.updateLog(logfile, "Contact Windows Calculation Exception: " + ae.InnerExceptions[0].Message, mainform);
                    }
                }
                for (int k = 0; k < stations.Count(); k++)
                {
                    contacts.add(inViews[k].getResults());
                }
            }
            contacts.setStartTime(start);
            contacts.setStopTime(stop);
            return(contacts);
        }
Beispiel #6
0
        //! 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();
            }
        }