Esempio n. 1
0
        //! Get station data for a groundstation from DataBase

        /*!
         * \param String name of the Station
         */
        public Ground.Station getStationFromDB(string StaName)
        {
            if (!isConnected)
            {
                connectDB();
            }
            SQLiteCommand command = new SQLiteCommand(m_dbConnection);

            Ground.Station station;
            command.CommandText = String.Format("SELECT * FROM {0} WHERE name='{1}';",
                                                Constants.StationDB, StaName);
            using (SQLiteDataReader read = command.ExecuteReader())
            {
                while (read.Read())
                {
                    station = new Ground.Station(
                        read.GetString(0),
                        read.GetDouble(1),
                        read.GetDouble(2),
                        read.GetDouble(3));
                    return(station);
                }
            }
            return(null);
        }
Esempio n. 2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                //Manual Input
                DataBase.DataBase db      = new DataBase.DataBase();
                double            lat     = double.Parse(textLat.Text, CultureInfo.GetCultureInfo("en-US"));
                double            lon     = double.Parse(textLon.Text, CultureInfo.GetCultureInfo("en-US"));
                double            height  = double.Parse(textHeight.Text, CultureInfo.GetCultureInfo("en-US"));
                Ground.Station    station = new Ground.Station(textStationName.Text, lat, lon, height);

                db.writeStation(station);
                this.Close();
            }
            if (radioButton1.Checked)
            {
                using (var reader = new StreamReader(stationFilePath))
                {
                    DataBase.DataBase db = new DataBase.DataBase();
                    string            line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string   _name;
                        double   _latitude;
                        double   _longitude;
                        double   _height;
                        string[] res = line.Split(' ');
                        if (res.Count() >= 3)
                        {
                            _name      = res[0];
                            _latitude  = Convert.ToDouble(res[1]);
                            _longitude = Convert.ToDouble(res[2]);
                            if (res.Count() == 4)
                            {
                                _height = Convert.ToDouble(res[3]);
                            }
                            else
                            {
                                _height = 0.0;
                            }
                            Ground.Station station = new Ground.Station(_name, _latitude, _longitude, _height);
                            db.writeStation(station);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        //! Draw Stations from Database onto image.

        /*!
         * \param DataGridViewRowCollections rows of stations to draw
         * \param DataBase database that holds all the information
         * \return Image bmp-Image
         */
        public static Image drawStation(DataGridViewRowCollection rows, DataBase.DataBase db)
        {
            Image imgStation = Properties.Resources.worldsmaller;

            Pen penRest = new Pen(Color.Orange, 2);

            using (var graphics = Graphics.FromImage(imgStation))
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    Ground.Station item = db.getStationFromDB(rows[i].Cells[0].Value.ToString());
                    Point          p    = item.getGeoCoordinate().toPoint(imgStation.Width, imgStation.Height);
                    graphics.DrawRectangle(penRest, p.X - 10, p.Y - 10, 20, 20);
                }
            }

            return(imgStation);
        }
Esempio n. 4
0
        //! Write GroundStation data to Database

        /*!
         * \param Station groundstation data to write into DataBase
         */
        public void writeStation(Ground.Station station)
        {
            if (!isConnected)
            {
                connectDB();
            }
            SQLiteCommand command = new SQLiteCommand(m_dbConnection);
            int           count   = 0;

            command.CommandText = String.Format("SELECT count(*) FROM {0} WHERE name='{1}';",
                                                Constants.StationDB, station.getName());
            count = Convert.ToInt32(command.ExecuteScalar());
            if (count == 0)
            {
                command.CommandText = String.Format(
                    Constants.insertSta,
                    Constants.StationDB, station.getName(), station.getLatitude(),
                    station.getLongitude(), station.getHeight(), station.getNrOfAntennas());
                command.ExecuteNonQuery();
            }
        }
Esempio n. 5
0
        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);
        }