Exemple #1
0
 // Constructor
 public AlgTopNH(PathPlanningRequest _curRequest, int _ModeCount, RtwMatrix _mModes, RtwMatrix _mDistReachable, 
     RtwMatrix _mDiffReachable, double _Efficiency_UB)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
 {
     ModeCount = _ModeCount;
     mModes = _mModes;
 }
 // Constructor
 public ComputeEfficiencyUB(PathPlanningRequest _curRequest, RtwMatrix _mDistReachable, RtwMatrix _mDiffReachable)
 {
     curRequest = _curRequest;
     mDistReachable = _mDistReachable;
     mDiffReachable = _mDiffReachable;
     Compute();
 }
Exemple #3
0
 // Constructor
 public AlgSearchReverse(PathPlanningRequest _curRequest, int _ModeCount, RtwMatrix _mMode, 
     RtwMatrix _mDistReachable, RtwMatrix _mDiffReachable, double _Efficiency_UB)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
 {
     ModeCount = _ModeCount;
     mMode = _mMode;
 }
Exemple #4
0
 // Constructor
 public MapModes(int _ModeCount, RtwMatrix _mModes, PathPlanningRequest _curRequest)
 {
     ModeCount = _ModeCount;
     mModes = _mModes;
     curRequest = _curRequest;
     N = curRequest.TopN;
     FindTopNModes();
 }
Exemple #5
0
 // Constructor
 public PathPlanningTask(PathPlanningRequest _curRequest, int _ModeCount, RtwMatrix _mModes,
     RtwMatrix _mDistReachable, RtwMatrix _mDiffReachable, double _Efficiency_UB)
 {
     curRequest = _curRequest;
     ModeCount = _ModeCount;
     mModes = _mModes;
     mDistReachable = _mDistReachable;
     mDiffReachable = _mDiffReachable;
     Efficiency_UB = _Efficiency_UB;
 }
Exemple #6
0
 // Constructor
 public AlgGlobalWarming(PathPlanningRequest _curRequest, int _ModeCount, 
     RtwMatrix _mDistReachable, RtwMatrix _mDiffReachable, double _Efficiency_UB)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
 {
     ModeCount = _ModeCount;
     GWCount = ProjectConstants.GWCount;
     ConvCount = ProjectConstants.ConvCount;
     CTFGWCoraseLevel = ProjectConstants.CTFGWCoraseLevel;
     CTFGWLevelCount = ProjectConstants.CTFGWLevelCount;
     PFCount = ProjectConstants.PFCount;
 }
Exemple #7
0
        // Constructor
        public AlgPathPlanning(PathPlanningRequest _curRequest,
            RtwMatrix _mDist, RtwMatrix _mDiff, double _Efficiency_UB)
        {
            // Start timer
            startTime = DateTime.Now;

            curRequest = _curRequest;
            mDist = _mDist;
            mDiff = _mDiff;
            // Clone distribution map so we can modify it
            mCurDist = mDist.Clone();
            Efficiency_UB = _Efficiency_UB;
        }
Exemple #8
0
        public AlgTopTwo(MapModes _curModes, PathPlanningRequest _curRequest, int _ModeCount, RtwMatrix _mModes, RtwMatrix _mDistReachable,
            RtwMatrix _mDiffReachable, double _Efficiency_UB)
            : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
        {
            // Start timer
            //DateTime startTime = DateTime.Now;
            myModes = _curModes;
            //DateTime stopTime = DateTime.Now;
            //TimeSpan duration = stopTime - startTime;
            //double RunTime = duration.TotalSeconds;
            //System.Windows.Forms.MessageBox.Show("Run time " + RunTime + " seconds!");

            CTFTTCoraseLevel = ProjectConstants.CTFTTCoraseLevel;
            CTFTTLevelCount = ProjectConstants.CTFTTLevelCount;
            mDistAfterSeg1Seg4 = mDist;
        }
Exemple #9
0
        public AlgTopN(MapModes _curModes, PathPlanningRequest _curRequest, int _ModeCount, RtwMatrix _mModes, RtwMatrix _mDistReachable,
            RtwMatrix _mDiffReachable, double _Efficiency_UB)
            : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
        {
            //DateTime startTime = DateTime.Now;
            myModes = _curModes;
            //DateTime stopTime = DateTime.Now;
            //TimeSpan duration = stopTime - startTime;
            //double RunTime = duration.TotalSeconds;
            //System.Windows.Forms.MessageBox.Show("Run time " + RunTime + " seconds!");

            Start = new Point(curRequest.pStart.column, curRequest.pStart.row);
            if (curRequest.UseEndPoint)
            {
                End = new Point(curRequest.pEnd.column, curRequest.pEnd.row);
            }
            N = curRequest.TopN;
        }
Exemple #10
0
 public AlgCC(PathPlanningRequest _curRequest, RtwMatrix _mDistReachable,
     RtwMatrix _mDiffReachable, double _Efficiency_UB)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB)
 {
 }
Exemple #11
0
        // Function to actually generate seeds of various algorithms
        private bool GenerateSeeds(List<EAPath> AllPaths, PathPlanningRequest newRequest, AlgPathPlanning myAlg, int count)
        {
            for (int i = 0; i < count; i++)
            {
                switch (newRequest.AlgToUse)
                {
                    case AlgType.CC:
                        myAlg = new AlgCC(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCGWCONV:
                        myAlg = new AlgGlobalWarming(newRequest, ModeCount, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCGWPF:
                        myAlg = new AlgGlobalWarming(newRequest, ModeCount, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCRandom:
                        myAlg = new AlgLHCRandom(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.Random:
                        myAlg = new AlgRandom(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.TopTwoH:
                        myAlg = new AlgTopTwo(newRequest, ModeCount, mModes, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.TopNH:
                        myAlg = new AlgTopTwo(newRequest, ModeCount, mModes, mDist, mDiff, Efficiency_UB);
                        break;
                    default:
                        break;
                }

                DateTime startTime2 = DateTime.Now;
                myAlg.PlanPath();
                DateTime stopTime2 = DateTime.Now;
                TimeSpan duration2 = stopTime2 - startTime2;
                double RunTime2 = duration2.TotalSeconds;
                if (ProjectConstants.DebugMode)
                {
                    curRequest.SetLog("Algorithm " + newRequest.AlgToUse + " took " + RunTime2 + " seconds.\n");
                }

                EAPath eap = new EAPath();
                eap.CDF = myAlg.GetCDF();
                eap.Path.AddRange(myAlg.GetPath());
                myAlg = null;

                // Add EAPath to population
                AllPaths.Add(eap);

                // If we already have the best path, then no need to continue
                CDF = eap.CDF;
                Path = eap.Path;
                if (Math.Abs(CDF - Efficiency_UB) < 0.001)
                {
                    return true;
                }
            }
            return false;
        }
Exemple #12
0
 // Constructor
 public AlgCONV(PathPlanningRequest _curRequest, RtwMatrix _mDistReachable, 
     RtwMatrix _mDiffReachable, double _Efficiency_UB, int _KernalSize)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB, _KernalSize)
 {
 }
Exemple #13
0
        // When the test button is pressed (Count how many modes)
        private void btnTest_Click(object sender, EventArgs e)
        {
            #region Test Mode Count
            //DateTime startTime = DateTime.Now;
            //CountDistModes myCount;
            //if (chkUseDiff.Checked)
            //{
            //    RtwMatrix mDistReachable = test.DistMap.Clone();
            //    RtwMatrix mDiffReachable = test.DiffMap.Clone();

            //    RtwMatrix mRealModes = new RtwMatrix(CurDiffMap.Rows, CurDiffMap.Columns);
            //    for (int i = 0; i < mRealModes.Rows; i++)
            //    {
            //        for (int j = 0; j < mRealModes.Columns; j++)
            //        {
            //            mRealModes[i, j] = mDistReachable[i, j] *
            //                (float)test.DiffRates[Convert.ToInt32(mDiffReachable[i, j])];
            //        }
            //    }
            //    myCount = new CountDistModes(mRealModes);

            //    // Debug code: Showing the product of dist and diff
            //    frmMap mapReal = new frmMap();
            //    Bitmap CurBMPReal = new Bitmap(mRealModes.Columns, mRealModes.Rows);
            //    ImgLib.MatrixToImage(ref mRealModes, ref CurBMPReal);
            //    mapReal.Text = "Real probability distribution with respect to difficulty map";
            //    mapReal.setImage(CurBMPReal);
            //    mapReal.Show();
            //    mapReal.resetImage();
            //}
            //else
            //{
            //    myCount = new CountDistModes(CurDistMap);
            //}

            //Log(myCount.GetCount().ToString() + "\n");
            //DateTime stopTime = DateTime.Now;
            //TimeSpan duration = stopTime - startTime;
            //Log("Computation took " + duration.ToString() + " seconds.\n");
            //// Show mode nodes
            //RtwMatrix myModes = myCount.GetModes().Clone();
            //for (int i = 0; i < myModes.Rows; i++)
            //{
            //    for (int j = 0; j < myModes.Columns; j++)
            //    {
            //        if (myModes[i, j] > 0)
            //        {
            //            myModes[i, j] = 255;
            //        }
            //    }
            //}
            //// Convert matrix to image
            //Bitmap CurBMP = new Bitmap(myModes.Columns, myModes.Rows);
            //ImgLib.MatrixToImage(ref myModes, ref CurBMP);
            //// Showing map in map form
            //frmMap myModesForm = new frmMap(this);
            //myModesForm.Text = "Modes Map";
            //myModesForm.setImage(CurBMP);
            //myModesForm.Show();

            //myCount = null;
            #endregion

            #region Test permutation

            //int[] intInput = { 1, 2, 3, 4};
            //Log(ShowPermutations<int>(intInput, 3));

            //string[] stringInput = { "Hello", "World", "Foo" };
            //Log(ShowPermutations<string>(stringInput, 2));

            #endregion

            #region Test MATLAB
            //////////////////////
            //// Input Parameters
            //////////////////////

            //// create an array ar for the real part of "a"
            //System.Array ar = new double[2];
            //ar.SetValue(11, 0);
            //ar.SetValue(12, 1);

            //// create an array ai for the imaginary part of "a"
            //System.Array ai = new double[2];
            //ai.SetValue(1, 0);
            //ai.SetValue(2, 1);

            //// create an array br for the real part of "b"
            //System.Array br = new double[2];
            //br.SetValue(21, 0);
            //br.SetValue(22, 1);

            //// create an array bi for the imaginary part of "b"
            //System.Array bi = new double[2];
            //bi.SetValue(3, 0);
            //bi.SetValue(4, 1);

            ///////////////////////
            //// Output Parameters
            ///////////////////////

            //// initialize variables for return value from ML
            //System.Array cr = new double[2];
            //System.Array ci = new double[2];
            //System.Array dr = new double[2];
            //System.Array di = new double[2];

            //////////////////////////
            //// Call MATLAB function
            //////////////////////////
            //// call appropriate function/method based on Mode
            //// use MATLAB engine
            //UseEngine(ar, ai, br, bi, ref cr, ref ci, ref dr, ref di);

            //Log("ar = " + ar.GetValue(0).ToString() + " " + ar.GetValue(1).ToString() + "\n");
            //Log("ai = " + ai.GetValue(0).ToString() + " " + ai.GetValue(1).ToString() + "\n");
            //Log("br = " + br.GetValue(0).ToString() + " " + br.GetValue(1).ToString() + "\n");
            //Log("bi = " + bi.GetValue(0).ToString() + " " + bi.GetValue(1).ToString() + "\n");
            //Log("cr = " + cr.GetValue(0).ToString() + " " + cr.GetValue(1).ToString() + "\n");
            //Log("ci = " + ci.GetValue(0).ToString() + " " + ci.GetValue(1).ToString() + "\n");
            //Log("dr = " + dr.GetValue(0).ToString() + " " + dr.GetValue(1).ToString() + "\n");
            //Log("di = " + di.GetValue(0).ToString() + " " + di.GetValue(1).ToString() + "\n");
            #endregion

            #region Test MATH.NET EVD

            //DenseMatrix m = new DenseMatrix(new[,] { { 81.1887, -18.4630 }, { -18.4630, 115.9033 } });
            //System.Numerics.Complex[] d = m.Evd().EigenValues().ToArray();
            //double a = d[0].Real;
            //double b = d[1].Real;
            //Log(a + " " + b);

            #endregion

            #region Test Arrays

            //int n = 3;
            //Array arrModes = new double[n];
            //Array arrMUs = new double[n, 2];
            //Array arrSigmaXSigmaY = new double[n];

            //for (int i = 0; i < n; i++)
            //{
            //    // Means
            //    arrMUs.SetValue(21, i, 0);
            //    arrMUs.SetValue(22, i, 1);
            //}

            #endregion

            #region Compute Efficiency with existing path

            #region Sanity Check
            // Make sure maps are loaded
            if (chkUseDist.Checked && CurDistMap == null)
            {
                System.Windows.Forms.MessageBox.Show("Please load a probability distribution map first!");
                return;
            }
            if (chkUseDiff.Checked && CurDiffMap == null)
            {
                System.Windows.Forms.MessageBox.Show("Please load a task-difficulty map first!");
                return;
            }

            // Make sure distribution map and task-difficulty map have same size
            if (chkUseDiff.Checked && chkUseDist.Checked)
            {
                if (CurDistMap.Rows != CurDiffMap.Rows || CurDistMap.Columns != CurDiffMap.Columns)
                {
                    System.Windows.Forms.MessageBox.Show("Please make sure the distribution map and the " +
                    "task-difficulty map must be the same size!");
                    return;
                }
            }

            // Use default distribution map or task-difficulty map if only one is checked
            if (chkUseDiff.Checked && !chkUseDist.Checked)
            {
                CurDistMap = new RtwMatrix(CurDiffMap.Rows, CurDiffMap.Columns);
            }
            if (!chkUseDiff.Checked && chkUseDist.Checked)
            {
                CurDiffMap = new RtwMatrix(CurDistMap.Rows, CurDistMap.Columns);
            }

            #endregion

            // Create request object
            PathPlanningRequest newRequest = new PathPlanningRequest();

            #region Setting Request Object Properties

            newRequest.UseDistributionMap = chkUseDist.Checked;
            newRequest.UseTaskDifficultyMap = chkUseDiff.Checked;
            newRequest.UseHierarchy = chkHierarchy.Checked;
            newRequest.UseCoarseToFineSearch = chkCoaseToFine.Checked;
            newRequest.UseParallelProcessing = chkParallel.Checked;
            if (rbtnFixWing.Checked)
            {
                newRequest.VehicleType = UAVType.FixWing;
            }
            if (rbtnCopter.Checked)
            {
                newRequest.VehicleType = UAVType.Copter;
            }
            if (rbtnFixedAmount.Checked)
            {
                newRequest.DetectionType = DType.FixAmount;
            }
            if (rbtnFixedAmountPercent.Checked)
            {
                newRequest.DetectionType = DType.FixAmountInPercentage;
            }
            if (rbtnFixedPercent.Checked)
            {
                newRequest.DetectionType = DType.FixPercentage;
            }
            newRequest.DetectionRate = Convert.ToDouble(ntxtDetectionRate.Value);
            newRequest.DistMap = CurDistMap;
            newRequest.DiffMap = CurDiffMap;
            newRequest.UseEndPoint = chkUseEndPoint.Checked;
            newRequest.T = trbFlightTime.Value;
            newRequest.pStart.column = Convert.ToInt16(ntxtSX.Value);
            newRequest.pStart.row = Convert.ToInt16(ntxtSY.Value);
            newRequest.pEnd.column = Convert.ToInt16(ntxtEX.Value);
            newRequest.pEnd.row = Convert.ToInt16(ntxtEY.Value);
            newRequest.AlgToUse = AlgType.LHCGWCONV;
            newRequest.DrawPath = chkShowPath.Checked;

            #endregion

            #region Find max task-difficulty and compute diff rates only once

            if (chkUseDiff.Checked)
            {
                newRequest.MaxDifficulty = Convert.ToInt32(CurDiffMap.MinMaxValue()[1]);
                // Set task-difficulty rates
                double[] DiffRates = new double[newRequest.MaxDifficulty + 1];
                double rate = 1.0 / (newRequest.MaxDifficulty + 1);
                for (int i = 0; i < newRequest.MaxDifficulty + 1; i++)
                {
                    DiffRates[i] = 1 - i * rate;
                }
                newRequest.DiffRates = DiffRates;
            }

            if (!newRequest.SanityCheck())
            {
                System.Windows.Forms.MessageBox.Show(newRequest.GetLog());
                return;
            }

            #endregion

            // Read in existing path using hard-coded file path
            string BAPathFileName = @"H:\Research\20 New IPPAs for Partial Detection Conference Paper\Selected Cases Maps\BAPath.csv";
            RtwMatrix BAPath = MISCLib.ReadInMap(BAPathFileName);

            #region First do reachable area (Dist and Diff)

            RtwMatrix mDistReachable;
            RtwMatrix mDiffReachable;

            if (newRequest.T < newRequest.DistMap.Rows + newRequest.DistMap.Columns)
            {
                mDistReachable = newRequest.DistMap.Clone();
                mDiffReachable = newRequest.DiffMap.Clone();
                if (!ComputeReachableArea(newRequest, mDistReachable, mDiffReachable))
                {
                    // Cannot plan path.
                    return;
                }
            }
            else
            {
                mDistReachable = newRequest.DistMap.Clone();
                mDiffReachable = newRequest.DiffMap.Clone();
            }

            #endregion

            // Then do efficiency lower bound
            ComputeEfficiencyUB myELB = new ComputeEfficiencyUB(newRequest, mDistReachable, mDiffReachable);
            double Efficiency_UB = myELB.GetEfficiency_UB();
            List<Point> TeleportPath = myELB.GetTeleportPath();
            myELB = null;

            // Creating path planning object
            AlgPathPlanning curAlg = new AlgGlobalWarming(newRequest, 1, mDistReachable, mDiffReachable, Efficiency_UB);

            // Call method to compute existing path CDF
            List<Point> Path = new List<Point>();
            for(int i=0; i<BAPath.Rows; i++)
            {
                Point p = new Point(Convert.ToInt16(BAPath[i,0]), Convert.ToInt16(BAPath[i,1]));
                Path.Add(p);
            }

            float CDF = curAlg.GetTrueCDF(Path);

            // Compute efficiency
            double Efficiency = 0;
            if (Efficiency_UB == 0)
            {
                Efficiency = 1;
            }
            else
            {
                Efficiency = CDF / Efficiency_UB;
            }

            // Compute CDF for graph
            Console.WriteLine("Print Existing Path CDF Graph:");
            curAlg.PrintCDFGraph(TeleportPath, newRequest.DistMap);
            Console.WriteLine("Print BAPath CDF Graph:");
            curAlg.PrintCDFGraph(Path, newRequest.DistMap);
            curAlg.SetPath(Path);

            // Show results
            Log("----------------------------------------------\n");
            Log("Efficiency: " + Efficiency.ToString() + "\n");
            Log("----------------------------------------------");
            Log("----------------------------------------------\n");

            #region Show path

            if (newRequest.DrawPath)
            {
                // Draw path with map remains
                Bitmap CurBMP3 = new Bitmap(mDistReachable.Columns, mDistReachable.Rows);
                ImgLib.MatrixToImage(ref mDistReachable, ref CurBMP3);
                frmMap map3 = new frmMap();
                map3.Text = "UAV trajectory and coverage";
                map3.setImage(CurBMP3);
                map3.Show();
                map3.resetImage();
                List<float> remains = curAlg.ShowCoverage();
                Color c = Color.FromArgb(255, 0, 0);
                for (int i = 0; i < Path.Count; i++)
                {
                    Point p = Path[i];
                    map3.setPointColor(p, c);
                    map3.Refresh();
                    map3.setPointColor(p, remains[i]);
                    map3.Refresh();
                }

                // Drawing real path
                MISCLib.ShowImage(MISCLib.DrawPath(Path), "Real Path");
            }

            #endregion

            #endregion
        }
Exemple #14
0
        // Plan Flight Path button is pressed
        private void btnExecute_Click(object sender, EventArgs e)
        {
            #region Sanity Check

            // Make sure there are tasks in queue
            if (lvQueue.Items.Count < 1)
            {
                System.Windows.Forms.MessageBox.Show("Please select a task first!");
                return;
            }

            // Make sure maps are loaded
            if (chkUseDist.Checked && CurDistMap == null)
            {
                System.Windows.Forms.MessageBox.Show("Please load a probability distribution map first!");
                return;
            }
            if (chkUseDiff.Checked && CurDiffMap == null)
            {
                System.Windows.Forms.MessageBox.Show("Please load a task-difficulty map first!");
                return;
            }

            // Sanity check to make sure distribution map and task-difficulty map have same size
            if (chkUseDiff.Checked && chkUseDist.Checked)
            {
                if (CurDistMap.Rows != CurDiffMap.Rows || CurDistMap.Columns != CurDiffMap.Columns)
                {
                    System.Windows.Forms.MessageBox.Show("Please make sure the distribution map and the " +
                    "task-difficulty map must be the same size!");
                    return;
                }
            }

            // Use default distribution map or task-difficulty map if only one is checked
            if (chkUseDiff.Checked && !chkUseDist.Checked)
            {
                CurDistMap = new RtwMatrix(CurDiffMap.Rows, CurDiffMap.Columns);
            }
            if (!chkUseDiff.Checked && chkUseDist.Checked)
            {
                CurDiffMap = new RtwMatrix(CurDistMap.Rows, CurDistMap.Columns);
            }

            #endregion

            // Generate path planning requests
            foreach (ListViewItem item in lvQueue.Items)
            {
                PathPlanningRequest newRequest = new PathPlanningRequest();

                #region Setting Request Object Properties

                newRequest.UseDistributionMap = chkUseDist.Checked;
                newRequest.UseTaskDifficultyMap = chkUseDiff.Checked;
                newRequest.UseHierarchy = chkHierarchy.Checked;
                newRequest.UseCoarseToFineSearch = chkCoaseToFine.Checked;
                newRequest.UseParallelProcessing = chkParallel.Checked;
                if (rbtnFixWing.Checked)
                {
                    newRequest.VehicleType = UAVType.FixWing;
                }
                if (rbtnCopter.Checked)
                {
                    newRequest.VehicleType = UAVType.Copter;
                }
                if (rbtnFixedAmount.Checked)
                {
                    newRequest.DetectionType = DType.FixAmount;
                }
                if (rbtnFixedAmountPercent.Checked)
                {
                    newRequest.DetectionType = DType.FixAmountInPercentage;
                }
                if (rbtnFixedPercent.Checked)
                {
                    newRequest.DetectionType = DType.FixPercentage;
                }
                newRequest.DetectionRate = Convert.ToDouble(ntxtDetectionRate.Value);
                newRequest.DistMap = CurDistMap;
                newRequest.DiffMap = CurDiffMap;
                newRequest.UseEndPoint = chkUseEndPoint.Checked;
                newRequest.T = trbFlightTime.Value;
                newRequest.pStart.column = Convert.ToInt16(ntxtSX.Value);
                newRequest.pStart.row = Convert.ToInt16(ntxtSY.Value);
                newRequest.pEnd.column = Convert.ToInt16(ntxtEX.Value);
                newRequest.pEnd.row = Convert.ToInt16(ntxtEY.Value);
                if (chkUseEndPoint.Checked)
                {
                    switch (item.Text)
                    {
                        case "CC":
                            newRequest.AlgToUse = AlgType.CC_E;
                            break;
                        case "LHC-GW-CONV":
                            newRequest.AlgToUse = AlgType.LHCGWCONV_E;
                            break;
                        case "LHC-GW-PF":
                            newRequest.AlgToUse = AlgType.LHCGWPF_E;
                            break;
                        case "LHC-Random":
                            newRequest.AlgToUse = AlgType.LHCRandom_E;
                            break;
                        case "Random":
                            newRequest.AlgToUse = AlgType.Random_E;
                            break;
                        case "CONV":
                            newRequest.AlgToUse = AlgType.CONV_E;
                            break;
                        case "PF":
                            newRequest.AlgToUse = AlgType.PF_E;
                            break;
                        case "TopTwo":
                            newRequest.AlgToUse = AlgType.TopTwo_E;
                            break;
                        case "TopN":
                            newRequest.AlgToUse = AlgType.TopN_E;
                            break;
                        case "TopTwoH":
                            newRequest.AlgToUse = AlgType.TopTwoH_E;
                            break;
                        case "TopNH":
                            newRequest.AlgToUse = AlgType.TopNH_E;
                            break;
                        case "EA":
                            newRequest.AlgToUse = AlgType.EA_E;
                            break;
                        case "RealTime":
                            newRequest.AlgToUse = AlgType.RealTime_E;
                            break;
                    }
                }
                else
                {
                    switch (item.Text)
                    {
                        case "CC":
                            newRequest.AlgToUse = AlgType.CC;
                            break;
                        case "LHC-GW-CONV":
                            newRequest.AlgToUse = AlgType.LHCGWCONV;
                            break;
                        case "LHC-GW-PF":
                            newRequest.AlgToUse = AlgType.LHCGWPF;
                            break;
                        case "LHC-Random":
                            newRequest.AlgToUse = AlgType.LHCRandom;
                            break;
                        case "Random":
                            newRequest.AlgToUse = AlgType.Random;
                            break;
                        case "CONV":
                            newRequest.AlgToUse = AlgType.CONV;
                            break;
                        case "PF":
                            newRequest.AlgToUse = AlgType.PF;
                            break;
                        case "TopTwo":
                            newRequest.AlgToUse = AlgType.TopTwo;
                            break;
                        case "TopN":
                            newRequest.AlgToUse = AlgType.TopN;
                            break;
                        case "TopTwoH":
                            newRequest.AlgToUse = AlgType.TopTwoH;
                            break;
                        case "TopNH":
                            newRequest.AlgToUse = AlgType.TopNH;
                            break;
                        case "EA":
                            newRequest.AlgToUse = AlgType.EA;
                            break;
                        case "RealTime":
                            newRequest.AlgToUse = AlgType.RealTime;
                            break;
                    }
                }
                newRequest.DrawPath = chkShowPath.Checked;
                if (chkBatchRun.Checked)
                {
                    newRequest.BatchRun = true;
                    newRequest.RunTimes = Convert.ToInt16(ntxtRunTimes.Value);
                }

                // Find max task-difficulty and compute diff rates only once
                if (chkUseDiff.Checked)
                {
                    newRequest.MaxDifficulty = Convert.ToInt32(CurDiffMap.MinMaxValue()[1]);
                    // Set task-difficulty rates
                    double[] DiffRates = new double[newRequest.MaxDifficulty + 1];
                    double rate = 1.0 / (newRequest.MaxDifficulty + 1);
                    for (int i = 0; i < newRequest.MaxDifficulty + 1; i++)
                    {
                        DiffRates[i] = 1 - i * rate;
                    }
                    newRequest.DiffRates = DiffRates;
                }

                // Remember TopN parameter for TopTwo and TopN algorithms
                if (newRequest.AlgToUse == AlgType.TopTwo || newRequest.AlgToUse == AlgType.TopTwo_E)
                {
                    newRequest.TopN = 2;
                }
                if (newRequest.AlgToUse == AlgType.TopN || newRequest.AlgToUse == AlgType.TopN_E)
                {
                    newRequest.TopN = Convert.ToInt32(ntxtTopNCount.Value);
                }

                if (!newRequest.SanityCheck())
                {
                    System.Windows.Forms.MessageBox.Show(newRequest.GetLog());
                    return;
                }
                #endregion

                // Debug: Test
                test = newRequest;

                // Add to server queue and pass alone the object
                frmParent.SubmitToRequestQueue(newRequest);
            }

            // Clear task queue
            lvQueue.Clear();
            lvQueue.Columns.Add("Task");
            lvQueue.Columns[0].Width = lvQueue.Width - 5;
        }
Exemple #15
0
        // Compute the reachable area and might as well compute distance to closest non-zero node
        private bool ComputeReachableArea(PathPlanningRequest curRequest, RtwMatrix mDistReachable, RtwMatrix mDiffReachable)
        {
            // Code is cleaner to just deal two cases seperately.
            if (!curRequest.UseEndPoint)
            {
                Point Start = new Point(curRequest.pStart.column, curRequest.pStart.row);
                int d = curRequest.T;
                for (int y = 0; y < mDistReachable.Rows; y++)
                {
                    for (int x = 0; x < mDistReachable.Columns; x++)
                    {
                        int dist = MISCLib.ManhattanDistance(x, y, Start.X, Start.Y);
                        if (dist >= curRequest.T)
                        {
                            // Wipe cell in both maps clean
                            mDistReachable[y, x] = 0;
                            mDiffReachable[y, x] = 0;
                        }
                        if (dist < d && mDistReachable[y, x] != 0)
                        {
                            d = dist;
                        }
                    }
                }
                curRequest.d = d;
            }
            else
            {
                Point Start = new Point(curRequest.pStart.column, curRequest.pStart.row);
                Point End = new Point(curRequest.pEnd.column, curRequest.pEnd.row);
                int d = curRequest.T;
                int dist = MISCLib.ManhattanDistance(Start.X, Start.Y, End.X, End.Y);

                if (dist > curRequest.T)
                {
                    // Impossible to get from A to B in allowed flight time
                    System.Windows.Forms.MessageBox.Show("Impossible! Extend flight time!");
                    return false;
                }

                if (curRequest.T % 2 != dist % 2)
                {
                    // Impossible to get from A to B in the exact allowed flight time
                    System.Windows.Forms.MessageBox.Show("Impossible to reach end point at time T! Add 1 or minus 1!");
                    return false;
                }

                for (int y = 0; y < mDistReachable.Rows; y++)
                {
                    for (int x = 0; x < mDistReachable.Columns; x++)
                    {
                        int dist_AC = MISCLib.ManhattanDistance(x, y, Start.X, Start.Y);
                        int dist_BC = MISCLib.ManhattanDistance(x, y, End.X, End.Y);
                        if ((dist_AC + dist_BC) > curRequest.T)
                        {
                            // Wipe cell in both maps clean
                            mDistReachable[y, x] = 0;
                            mDiffReachable[y, x] = 0;
                        }
                        dist = MISCLib.ManhattanDistance(x, y, Start.X, Start.Y);
                        if (dist < d && mDistReachable[y, x] != 0)
                        {
                            d = dist;
                        }
                    }
                }
                curRequest.d = d;

            }
            return true;
        }
Exemple #16
0
 // Constructor
 public ServerQueueItem(PathPlanningRequest _curRequest, string _CallerIP)
 {
     curRequest = _curRequest;
     CallerIP = _CallerIP;
 }
Exemple #17
0
 // Clone self with deep copy
 public PathPlanningRequest DeepClone()
 {
     PathPlanningRequest clonedRequest = new PathPlanningRequest();
     clonedRequest.UseTaskDifficultyMap = this.UseTaskDifficultyMap;
     clonedRequest.UseHierarchy = this.UseHierarchy;
     clonedRequest.UseCoarseToFineSearch = this.UseCoarseToFineSearch;
     clonedRequest.UseParallelProcessing = this.UseParallelProcessing;
     clonedRequest.VehicleType = this.VehicleType;
     clonedRequest.DetectionType = this.DetectionType;
     clonedRequest.DetectionRate = this.DetectionRate;
     clonedRequest.DistMap = this.DistMap.Clone();
     clonedRequest.DiffMap = this.DiffMap.Clone();
     clonedRequest.UseEndPoint = this.UseEndPoint;
     clonedRequest.T = this.T;
     clonedRequest.pStart = new DistPoint(pStart.row, pStart.column);
     clonedRequest.pEnd = new DistPoint(pEnd.row, pEnd.column);
     clonedRequest.AlgToUse = this.AlgToUse;
     clonedRequest.BatchRun = this.BatchRun;
     clonedRequest.RunTimes = this.RunTimes;
     clonedRequest.MaxDifficulty = this.MaxDifficulty;
     if (this.DiffRates != null)
     {
         double[] DiffRatesCopy = new double[DiffRates.Length];
         Array.Copy(DiffRates, 0, DiffRatesCopy, 0, DiffRates.Length);
         clonedRequest.DiffRates = DiffRatesCopy;
     }
     clonedRequest.DrawPath = this.DrawPath;
     clonedRequest.d = this.d;
     clonedRequest.TopN = this.TopN;
     return clonedRequest;
 }
Exemple #18
0
 // Constructor
 public AlgPF(PathPlanningRequest _curRequest, 
     RtwMatrix _mDistReachable, RtwMatrix _mDiffReachable, 
     double _Efficiency_UB, int _Sigma)
     : base(_curRequest, _mDistReachable, _mDiffReachable, _Efficiency_UB, _Sigma)
 {
 }
Exemple #19
0
        // Method to construct Path Planning Request object from byte array
        private static PathPlanningRequest ByteArrayToRequest(byte[] byteTrimmed)
        {
            // Construct Protocol Buffer object form byte array
            ProtoBuffer.ServerQueueItem restored = ProtoBuffer.ServerQueueItem.CreateBuilder().MergeFrom(byteTrimmed).Build();

            // Construct PathPlanningRequest object
            ProtoBuffer.PathPlanningRequest PBRequest = restored.CurRequest;
            PathPlanningRequest curRequest = new PathPlanningRequest();
            // Easy stuff first
            curRequest.UseDistributionMap = PBRequest.UseDistributionMap;
            curRequest.UseTaskDifficultyMap = PBRequest.UseTaskDifficultyMap;
            curRequest.UseHierarchy = PBRequest.UseHierarchy;
            curRequest.UseCoarseToFineSearch = PBRequest.UseCoarseToFineSearch;
            curRequest.UseParallelProcessing = PBRequest.UseParallelProcessing;
            curRequest.VehicleType = (UAVType)PBRequest.VehicleType;
            curRequest.DetectionType = (DType)PBRequest.DetectionType;
            curRequest.DetectionRate = PBRequest.DetectionRate;
            curRequest.UseEndPoint = PBRequest.UseEndPoint;
            curRequest.T = PBRequest.T;
            curRequest.pStart = new DistPoint(PBRequest.PStart.Row, PBRequest.PStart.Column);
            curRequest.pEnd = new DistPoint(PBRequest.PEnd.Row, PBRequest.PEnd.Column);
            curRequest.AlgToUse = (AlgType)PBRequest.AlgToUse;
            curRequest.BatchRun = PBRequest.BatchRun;
            curRequest.RunTimes = PBRequest.RunTimes;
            curRequest.MaxDifficulty = PBRequest.MaxDifficulty;
            curRequest.DrawPath = PBRequest.DrawPath;
            curRequest.d = PBRequest.D;
            curRequest.TopN = PBRequest.TopNCount;
            // DiffRates array next
            double[] DiffRates = null;
            if (PBRequest.DiffRateList.Count > 0)
            {
                DiffRates = new double[PBRequest.DiffRateList.Count];
            }
            for (int i = 0; i < PBRequest.DiffRateList.Count; i++)
            {
                DiffRates[i] = PBRequest.DiffRateList[i];
            }
            curRequest.DiffRates = DiffRates;
            // Last the matrices
            curRequest.DistMap = PBMatrixToRtwMatrix(PBRequest.DistMap);
            curRequest.DiffMap = PBMatrixToRtwMatrix(PBRequest.DiffMap);

            return curRequest;
        }
Exemple #20
0
 public MapModes(int _GCount, int _ModeCount, RtwMatrix _mModes, PathPlanningRequest _curRequest, RtwMatrix _mDist, RtwMatrix _mDiff)
 {
     GCount = _GCount;
     mDist = _mDist;
     mDiff = _mDiff;
     ModeCount = _ModeCount;
     mModes = _mModes;
     curRequest = _curRequest;
     N = curRequest.TopN;
     FindTopNModes();
 }
Exemple #21
0
 // Constructor
 public PathPlanningHandler(PathPlanningRequest _curRequest)
 {
     curRequest = _curRequest;
 }
Exemple #22
0
        // Function to add item to queue
        public void SubmitToRequestQueue(PathPlanningRequest newRequest)
        {
            // Add to server queue
            ServerQueueItem newItem = new ServerQueueItem(newRequest, "127.0.0.1");
            myServer.AddRequest(newItem);

            // Add request item to queue
            lstQueue.Items.Add(newRequest.AlgToUse.ToString());
            lstRequestQueue.Add(newRequest);

            // Log activity
            Log("New path planning request queued...\n");
            if (ProjectConstants.DebugMode)
            {
                Log("----------------------------------------------");
                Log("----------------------------------------------\n");
                Log(GetRequestDetail(lstRequestQueue.Count - 1) + "\n\n");
            }
        }