コード例 #1
0
        private void TestTrileteration()
        {
            foreach (SystemClass System in SQLiteDBClass.globalSystems)
            {
                if (DateTime.Now.Subtract(System.CreateDate).TotalDays < 60)
                {
                    //var Distances = from SQLiteDBClass.globalDistances

                    var distances1 = from p in SQLiteDBClass.dictDistances where p.Value.NameA.ToLower() == System.SearchName select p.Value;
                    var distances2 = from p in SQLiteDBClass.dictDistances where p.Value.NameB.ToLower() == System.SearchName select p.Value;

                    int nr = distances1.Count();
                    //nr = distances2.Count();


                    if (nr > 4)
                    {
                        var trilateration = new Trilateration();
                        //                    trilateration.Logger = (s) => System.Console.WriteLine(s);

                        foreach (var item in distances1)
                        {
                            SystemClass distsys = SystemData.GetSystem(item.NameB);
                            if (distsys != null)
                            {
                                if (distsys.HasCoordinate)
                                {
                                    Trilateration.Entry entry = new Trilateration.Entry(distsys.x, distsys.y, distsys.z, item.Dist);
                                    trilateration.AddEntry(entry);
                                }
                            }
                        }

                        foreach (var item in distances2)
                        {
                            SystemClass distsys = SystemData.GetSystem(item.NameA);
                            if (distsys != null)
                            {
                                if (distsys.HasCoordinate)
                                {
                                    Trilateration.Entry entry = new Trilateration.Entry(distsys.x, distsys.y, distsys.z, item.Dist);
                                    trilateration.AddEntry(entry);
                                }
                            }
                        }


                        var csharpResult     = trilateration.Run(Trilateration.Algorithm.RedWizzard_Native);
                        var javascriptResult = trilateration.Run(Trilateration.Algorithm.RedWizzard_Emulated);
                        if (javascriptResult.State == Trilateration.ResultState.Exact)
                        {
                            nr++;
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void RunTrilaterationWorker()
        {
            var systemsEntries = new Dictionary<SystemClass, Trilateration.Entry>();

            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var systemCell = dataGridViewDistances[0, i];
                var distanceCell = dataGridViewDistances[1, i];

                if (systemCell.Tag == null || distanceCell.Value == null)
                {
                    continue;
                }

                var system = (SystemClass)systemCell.Tag;
                var culture = new CultureInfo("en-US");
                var distance = double.Parse(distanceCell.Value.ToString().Replace(",", "."), culture);

                var entry = new Trilateration.Entry(system.x, system.y, system.z, distance);

                systemsEntries.Add(system, entry);
            }

            if (systemsEntries.Count < 3)
            {
                return;
            }

            Invoke((MethodInvoker) delegate
            {
                LogText("Starting trilateration..." + Environment.NewLine);
                labelStatus.Text = "Calculating…";
                labelStatus.BackColor = Color.Gold;
            });

            var trilateration = new Trilateration {Logger = Console.WriteLine};

            foreach (var item in systemsEntries)
            {
                trilateration.AddEntry(item.Value);
            }

            //var trilaterationResultCS = trilateration.RunCSharp();
            var trilaterationAlgorithm = radioButtonAlgorithmJs.Checked
                ? Trilateration.Algorithm.RedWizzard_Emulated
                : Trilateration.Algorithm.RedWizzard_Native;

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var trilaterationResult = trilateration.Run(trilaterationAlgorithm);

            stopwatch.Stop();
            var spentTimeString = (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.0000") + "ms";

            lastTrilatelationResult = trilaterationResult;
            lastTrilatelationEntries = systemsEntries;

            if (trilaterationResult.State == Trilateration.ResultState.Exact)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration successful (" + spentTimeString + "), exact coordinates found." + Environment.NewLine);
                    //LogText("x=" + trilaterationResult.Coordinate.X + ", y=" + trilaterationResult.Coordinate.Y + ", z=" + trilaterationResult.Coordinate.Z + Environment.NewLine);
                    labelStatus.Text = "Success, coordinates found!";
                    labelStatus.BackColor = Color.LawnGreen;
                });
            } else if (trilaterationResult.State == Trilateration.ResultState.NotExact || trilaterationResult.State == Trilateration.ResultState.MultipleSolutions)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration not successful (" + spentTimeString + "), only approximate coordinates found." + Environment.NewLine);
                    //LogText("x=" + trilaterationResult.Coordinate.X + ", y=" + trilaterationResult.Coordinate.Y + ", z=" + trilaterationResult.Coordinate.Z + Environment.NewLine);
                    LogText("Enter more distances." + Environment.NewLine);
                    labelStatus.Text = "Enter More Distances";
                    labelStatus.BackColor = Color.Orange;
                });
            } else if (trilaterationResult.State == Trilateration.ResultState.NeedMoreDistances)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration not successful (" + spentTimeString + "), coordinates not found." + Environment.NewLine);
                    LogText("Enter more distances." + Environment.NewLine);
                    labelStatus.Text = "Enter More Distances";
                    labelStatus.BackColor = Color.Red;
                    ClearCalculatedDataGridViewDistancesRows();
                });
            }

            // update trilaterated coordinates
            if (trilaterationResult.Coordinate != null)
            {
                Invoke((MethodInvoker) delegate
                {
                    textBoxCoordinateX.Text = trilaterationResult.Coordinate.X.ToString();
                    textBoxCoordinateY.Text = trilaterationResult.Coordinate.Y.ToString();
                    textBoxCoordinateZ.Text = trilaterationResult.Coordinate.Z.ToString();
                    if (TargetSystem != null)
                    {
                        TargetSystem.x = trilaterationResult.Coordinate.X;
                        TargetSystem.y = trilaterationResult.Coordinate.Y;
                        TargetSystem.z = trilaterationResult.Coordinate.Z;
                    }
                    toolStripButtonMap.Enabled = (TargetSystem != null);

                });

                var suggestedSystems = GetListOfSuggestedSystems(trilaterationResult.Coordinate.X,
                                                                 trilaterationResult.Coordinate.Y,
                                                                 trilaterationResult.Coordinate.Z, 10);

                Invoke((MethodInvoker) (() => PopulateSuggestedSystems(suggestedSystems)));
            }
            else
            {
                Invoke((MethodInvoker) delegate
                {
                    textBoxCoordinateX.Text = "?";
                    textBoxCoordinateY.Text = "?";
                    textBoxCoordinateZ.Text = "?";
                });
            }

            var hasInvalidDistances = false;

            // update dataGrid with calculated distances and status
            var entriesDistances = trilaterationResult.EntriesDistances;

            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var systemCell = dataGridViewDistances[0, i];
                var calculatedDistanceCell = dataGridViewDistances[2, i];
                var statusCell = dataGridViewDistances[3, i];

                calculatedDistanceCell.Value = null;
                statusCell.Value = null;

                if (entriesDistances == null || systemCell.Value == null || systemCell.Tag == null)
                {
                    continue;
                }

                var system = (SystemClass) systemCell.Tag;

                if (!systemsEntries.ContainsKey(system)) // calculated without this system, so skip the row
                {
                    continue;
                }

                var systemEntry = systemsEntries[system];
                var calculatedDistance = entriesDistances[systemEntry];

                calculatedDistanceCell.Value = calculatedDistance.ToString();

                if (systemEntry.Distance == calculatedDistance)
                {
                    calculatedDistanceCell.Style.ForeColor = Color.Green;
                    statusCell.Value = "OK";
                    statusCell.Style.ForeColor = Color.Green;
                } else
                {
                        hasInvalidDistances = true;
                    calculatedDistanceCell.Style.ForeColor = Color.Salmon;
                    statusCell.Value = "Wrong distance?";
                    statusCell.Style.ForeColor = Color.Salmon;
                }
            }

            //// Always enable submiot so we can submit a partial result.
            //Invoke((MethodInvoker) delegate
            //{
            //    //buttonSubmitToEDSC.Enabled = true;  //trilaterationResult.State == Trilateration.ResultState.Exact && !hasInvalidDistances;
            //});
        }
コード例 #3
0
        private void TestTrileteration()
        {
            foreach (SystemClass System in SQLiteDBClass.globalSystems)
            {
                if (DateTime.Now.Subtract(System.CreateDate).TotalDays < 60)
                {
                    //var Distances = from SQLiteDBClass.globalDistances

                    var distances1 = from p in SQLiteDBClass.dictDistances where p.Value.NameA.ToLower() == System.SearchName select p.Value;
                    var distances2 = from p in SQLiteDBClass.dictDistances where p.Value.NameB.ToLower() == System.SearchName select p.Value;

                    int nr = distances1.Count();
                    //nr = distances2.Count();

                    if (nr > 4)
                    {
                        var trilateration = new Trilateration();
                        //                    trilateration.Logger = (s) => System.Console.WriteLine(s);

                        foreach (var item in distances1)
                        {
                            SystemClass distsys = SystemData.GetSystem(item.NameB);
                            if (distsys != null)
                            {
                                if (distsys.HasCoordinate)
                                {
                                    Trilateration.Entry entry = new Trilateration.Entry(distsys.x, distsys.y, distsys.z, item.Dist);
                                    trilateration.AddEntry(entry);
                                }
                            }
                        }

                        foreach (var item in distances2)
                        {
                            SystemClass distsys = SystemData.GetSystem(item.NameA);
                            if (distsys != null)
                            {
                                if (distsys.HasCoordinate)
                                {
                                    Trilateration.Entry entry = new Trilateration.Entry(distsys.x, distsys.y, distsys.z, item.Dist);
                                    trilateration.AddEntry(entry);
                                }
                            }
                        }

                        var csharpResult = trilateration.Run(Trilateration.Algorithm.RedWizzard_Native);
                        var javascriptResult = trilateration.Run(Trilateration.Algorithm.RedWizzard_Emulated);
                        if (javascriptResult.State == Trilateration.ResultState.Exact)
                            nr++;
                    }
                }
            }
        }
コード例 #4
0
        private void RunTrilaterationWorker()
        {
            var systemsEntries = new Dictionary <SystemClass, Trilateration.Entry>();

            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var systemCell   = dataGridViewDistances[0, i];
                var distanceCell = dataGridViewDistances[1, i];

                if (systemCell.Tag == null || distanceCell.Value == null)
                {
                    continue;
                }

                var system   = (SystemClass)systemCell.Tag;
                var culture  = new CultureInfo("en-US");
                var distance = double.Parse(distanceCell.Value.ToString().Replace(",", "."), culture);

                var entry = new Trilateration.Entry(system.x, system.y, system.z, distance);

                systemsEntries.Add(system, entry);
            }

            if (systemsEntries.Count < 3)
            {
                return;
            }

            Invoke((MethodInvoker) delegate
            {
                LogText("Starting trilateration..." + Environment.NewLine);
                labelStatus.Text      = "Calculating…";
                labelStatus.BackColor = Color.Gold;
            });

            var trilateration = new Trilateration {
                Logger = Console.WriteLine
            };

            foreach (var item in systemsEntries)
            {
                trilateration.AddEntry(item.Value);
            }

            //var trilaterationResultCS = trilateration.RunCSharp();
            var trilaterationAlgorithm = radioButtonAlgorithmJs.Checked
                ? Trilateration.Algorithm.RedWizzard_Emulated
                : Trilateration.Algorithm.RedWizzard_Native;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var trilaterationResult = trilateration.Run(trilaterationAlgorithm);

            stopwatch.Stop();
            var spentTimeString = (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.0000") + "ms";

            lastTrilatelationResult  = trilaterationResult;
            lastTrilatelationEntries = systemsEntries;

            if (trilaterationResult.State == Trilateration.ResultState.Exact)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration successful (" + spentTimeString + "), exact coordinates found." + Environment.NewLine);
                    //LogText("x=" + trilaterationResult.Coordinate.X + ", y=" + trilaterationResult.Coordinate.Y + ", z=" + trilaterationResult.Coordinate.Z + Environment.NewLine);
                    labelStatus.Text      = "Success, coordinates found!";
                    labelStatus.BackColor = Color.LawnGreen;
                });
            }
            else if (trilaterationResult.State == Trilateration.ResultState.NotExact || trilaterationResult.State == Trilateration.ResultState.MultipleSolutions)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration not successful (" + spentTimeString + "), only approximate coordinates found." + Environment.NewLine);
                    //LogText("x=" + trilaterationResult.Coordinate.X + ", y=" + trilaterationResult.Coordinate.Y + ", z=" + trilaterationResult.Coordinate.Z + Environment.NewLine);
                    LogText("Enter more distances." + Environment.NewLine);
                    labelStatus.Text      = "Enter More Distances";
                    labelStatus.BackColor = Color.Orange;
                });
            }
            else if (trilaterationResult.State == Trilateration.ResultState.NeedMoreDistances)
            {
                Invoke((MethodInvoker) delegate
                {
                    LogText("Trilateration not successful (" + spentTimeString + "), coordinates not found." + Environment.NewLine);
                    LogText("Enter more distances." + Environment.NewLine);
                    labelStatus.Text      = "Enter More Distances";
                    labelStatus.BackColor = Color.Red;
                    ClearCalculatedDataGridViewDistancesRows();
                });
            }

            // update trilaterated coordinates
            if (trilaterationResult.Coordinate != null)
            {
                Invoke((MethodInvoker) delegate
                {
                    textBoxCoordinateX.Text = trilaterationResult.Coordinate.X.ToString();
                    textBoxCoordinateY.Text = trilaterationResult.Coordinate.Y.ToString();
                    textBoxCoordinateZ.Text = trilaterationResult.Coordinate.Z.ToString();
                    if (TargetSystem != null)
                    {
                        TargetSystem.x = trilaterationResult.Coordinate.X;
                        TargetSystem.y = trilaterationResult.Coordinate.Y;
                        TargetSystem.z = trilaterationResult.Coordinate.Z;
                    }
                    toolStripButtonMap.Enabled = (TargetSystem != null);
                });


                var suggestedSystems = GetListOfSuggestedSystems(trilaterationResult.Coordinate.X,
                                                                 trilaterationResult.Coordinate.Y,
                                                                 trilaterationResult.Coordinate.Z, 10);

                Invoke((MethodInvoker)(() => PopulateSuggestedSystems(suggestedSystems)));
            }
            else
            {
                Invoke((MethodInvoker) delegate
                {
                    textBoxCoordinateX.Text = "?";
                    textBoxCoordinateY.Text = "?";
                    textBoxCoordinateZ.Text = "?";
                });
            }

            var hasInvalidDistances = false;

            // update dataGrid with calculated distances and status
            var entriesDistances = trilaterationResult.EntriesDistances;

            for (int i = 0, count = dataGridViewDistances.Rows.Count - 1; i < count; i++)
            {
                var systemCell             = dataGridViewDistances[0, i];
                var calculatedDistanceCell = dataGridViewDistances[2, i];
                var statusCell             = dataGridViewDistances[3, i];

                calculatedDistanceCell.Value = null;
                statusCell.Value             = null;

                if (entriesDistances == null || systemCell.Value == null || systemCell.Tag == null)
                {
                    continue;
                }

                var system = (SystemClass)systemCell.Tag;

                if (!systemsEntries.ContainsKey(system)) // calculated without this system, so skip the row
                {
                    continue;
                }

                var systemEntry        = systemsEntries[system];
                var calculatedDistance = entriesDistances[systemEntry];

                calculatedDistanceCell.Value = calculatedDistance.ToString();

                if (systemEntry.Distance == calculatedDistance)
                {
                    calculatedDistanceCell.Style.ForeColor = Color.Green;
                    statusCell.Value           = "OK";
                    statusCell.Style.ForeColor = Color.Green;
                }
                else
                {
                    hasInvalidDistances = true;
                    calculatedDistanceCell.Style.ForeColor = Color.Salmon;
                    statusCell.Value           = "Wrong distance?";
                    statusCell.Style.ForeColor = Color.Salmon;
                }
            }

            //// Always enable submiot so we can submit a partial result.
            //Invoke((MethodInvoker) delegate
            //{
            //    //buttonSubmitToEDSC.Enabled = true;  //trilaterationResult.State == Trilateration.ResultState.Exact && !hasInvalidDistances;
            //});
        }