예제 #1
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;
        }
예제 #2
0
 public void SetmDist(RtwMatrix m)
 {
     mDist = m;
     mCurDist = mDist.Clone();
 }
예제 #3
0
        // Print to console CDF progress for graphing purposes
        public void PrintCDFGraph(List<Point> curPath, RtwMatrix curDist)
        {
            float curCDF = 0;

            RtwMatrix mCDF = curDist.Clone();
            Console.Write("curCDF=");
            for (int i = 0; i < curRequest.T + 1; i++)
            {
                curCDF += GetPartialDetection(curPath[i], mCDF);
                mCDF[curPath[i].Y, curPath[i].X] = VacuumProbability(curPath[i], mCDF);
                // Write out CDF as time progresses for chart
                Console.Write(curCDF + " ");
            }
            Console.Write("\n");
            // Cleaning up
            mCDF = null;
        }
예제 #4
0
        // At current GW do LHC
        private bool PlanPathAtCurrentGW(RtwMatrix mGW, int index)
        {
            #region Deal with LHCGWCONV and LHCGWCONV_E algorithms
            // Console.WriteLine("Doing PlanPathAtCurrentGW once!");
            if (curRequest.AlgToUse == AlgType.LHCGWCONV || curRequest.AlgToUse == AlgType.LHCGWCONV_E)
            {
                // If LHCGWCONV, search multiple convolution kernal sizes
                int dim = Math.Max(mDist.Rows, mDist.Columns);
                for (int j = 5; j < dim; j += (int)(dim / ConvCount))
                {
                    // Console.Write("j=" + j + "\n");
                    AlgLHCGWCONV myAlg = null;
                    if (curRequest.UseParallelProcessing)
                    {
                        PathPlanningRequest curRequestCopy = curRequest.DeepClone();
                        RtwMatrix mGWCopy = mGW.Clone();
                        RtwMatrix mDiffCopy = mDiff.Clone();
                        myAlg = new AlgLHCGWCONV(curRequestCopy, mGWCopy, mDiffCopy, Efficiency_UB, j);
                        myAlg.SetBeforeStart(BeforeStart);
                        // Debug code
                        myAlg.conv = j;
                        myAlg.index = index;
                        lstThreads.Add(myAlg);
                    }
                    else
                    {
                        myAlg = new AlgLHCGWCONV(curRequest, mGW, mDiff, Efficiency_UB, j);
                        myAlg.SetBeforeStart(BeforeStart);
                        myAlg.PlanPath();

                        // Remember if true CDF is better
                        RememberBestPath(myAlg);

                        // Cleaning up
                        myAlg = null;

                        // If we already have the best path, then no need to continue
                        if (Math.Abs(Efficiency_UB - CDF) < 0.001)
                        {
                            return true;
                        }
                    }
                }
                //// Print one GW per line (3 conv each line)
                //curRequest.SetLog("\n");
            }
            #endregion

            #region Deal with LHCGWPF and LHCGWPF_E algorithms
            if (curRequest.AlgToUse == AlgType.LHCGWPF || curRequest.AlgToUse == AlgType.LHCGWPF_E)
            {
                // If LHCGWPF, search three convolution kernal sizes
                int dim = Math.Max(mDist.Rows, mDist.Columns);
                int Sigma = 0;
                for (int j = 0; j < PFCount; j++)
                {
                    //Console.Write("j=" + j + "\n");
                    Sigma += Convert.ToInt16(dim / 3);
                    AlgLHCGWCONV myAlg = null;
                    if (curRequest.UseParallelProcessing)
                    {
                        PathPlanningRequest curRequestCopy = curRequest.DeepClone();
                        RtwMatrix mGWCopy = mGW.Clone();
                        RtwMatrix mDiffCopy = mDiff.Clone();
                        myAlg = new AlgLHCGWCONV(curRequestCopy, mGWCopy, mDiffCopy, Efficiency_UB, Sigma);
                        myAlg.SetBeforeStart(BeforeStart);
                        // Debug code
                        myAlg.conv = j;
                        myAlg.index = index;
                        lstThreads.Add(myAlg);
                    }
                    else
                    {
                        myAlg = new AlgLHCGWCONV(curRequest, mGW, mDiff, Efficiency_UB, Sigma);
                        myAlg.SetBeforeStart(BeforeStart);
                        myAlg.PlanPath();

                        // Remember if true CDF is better
                        RememberBestPath(myAlg);

                        // Cleaning up
                        myAlg = null;

                        // If we already have the best path, then no need to continue
                        if (Math.Abs(Efficiency_UB - CDF) < 0.001)
                        {
                            return true;
                        }
                    }
                }
                // Print one GW per line (3 conv each line)
                //curRequest.SetLog("\n");
            }
            #endregion

            #region Deal with CONV and CONV_E algorithms
            if (curRequest.AlgToUse == AlgType.CONV || curRequest.AlgToUse == AlgType.CONV_E)
            {
                // If CONV, search multiple convolution kernal sizes
                int dim = Math.Max(mDist.Rows, mDist.Columns);
                for (int j = 3; j < dim; j += (int)(dim / ConvCount))
                {
                    //Console.Write("j=" + j + "\n");
                    AlgCONV myAlg = null;
                    if (curRequest.UseParallelProcessing)
                    {
                        PathPlanningRequest curRequestCopy = curRequest.DeepClone();
                        RtwMatrix mGWCopy = mGW.Clone();
                        RtwMatrix mDiffCopy = mDiff.Clone();
                        myAlg = new AlgCONV(curRequestCopy, mGWCopy, mDiffCopy, Efficiency_UB, j);
                        myAlg.SetBeforeStart(BeforeStart);
                        // Debug code
                        myAlg.conv = j;
                        myAlg.index = index;
                        lstThreads.Add(myAlg);
                    }
                    else
                    {
                        myAlg = new AlgCONV(curRequest, mGW, mDiff, Efficiency_UB, j);
                        myAlg.SetBeforeStart(BeforeStart);
                        myAlg.PlanPath();

                        // Remember if true CDF is better
                        RememberBestPath(myAlg);

                        // Cleaning up
                        myAlg = null;

                        // If we already have the best path, then no need to continue
                        if (Math.Abs(Efficiency_UB - CDF) < 0.001)
                        {
                            return true;
                        }
                    }
                }
                //// Print one GW per line (3 conv each line)
                //curRequest.SetLog("\n");
            }
            #endregion

            //// Debug code:
            //arrResponses = new PathPlanningResponse[lstThreads.Count];

            //for (int i = 0; i < lstThreads.Count; i++)
            //{
            //    int cur_i = i;
            //    StoreResults(cur_i);
            //}
            //// Now that all threads/tasks are done, find the best one
            //FindBestPath();

            return false;
        }
예제 #5
0
        // When the Load button for task-difficulty map is clicked.
        private void btnLoad2_Click(object sender, EventArgs e)
        {
            // Read in map file to matrix
            CurDiffMap = MISCLib.ReadInMap(txtFileName2.Text);

            // Scale so RGB range [0,255]
            RtwMatrix TempDiffMap = CurDiffMap.Clone();
            ImgLib.ScaleImageValues(ref TempDiffMap);

            // Convert matrix to image
            Bitmap CurBMP = new Bitmap(CurDiffMap.Columns, CurDiffMap.Rows);
            ImgLib.MatrixToImage(ref TempDiffMap, ref CurBMP);

            // Showing map in map form
            frmDiffMap = new frmMap(this);
            frmDiffMap.Text = "Task-Difficulty Map";
            frmDiffMap.setImage(CurBMP);
            // Also show start end points
            Start.X = Convert.ToInt32(ntxtSX.Value);
            Start.Y = Convert.ToInt32(ntxtSY.Value);
            SetDestPoint(true, Start);
            End.X = Convert.ToInt32(ntxtEX.Value);
            End.Y = Convert.ToInt32(ntxtEY.Value);
            SetDestPoint(false, End);
            frmDiffMap.DrawingStartEndPoints();
            frmDiffMap.Show();
        }
예제 #6
0
        // When the Load button for task-difficulty map is clicked.
        private void btnLoad2_Click(object sender, EventArgs e)
        {
            // Read in map file to matrix
            CurDiffMap = MISCLib.ReadInMap(txtFileName2.Text);

            // Scale so RGB range [0,255]
            RtwMatrix TempDiffMap = CurDiffMap.Clone();
            ImgLib.ScaleImageValues(ref TempDiffMap);

            // Convert matrix to image
            Bitmap CurBMP = new Bitmap(CurDiffMap.Columns, CurDiffMap.Rows);
            ImgLib.MatrixToImage(ref TempDiffMap, ref CurBMP);

            // Showing map in map form
            frmDiffMap = new frmMap(this);
            frmDiffMap.Text = "Task-Difficulty Map";
            frmDiffMap.setImage(CurBMP);
            // Also show start end points
            Start.X = Convert.ToInt32(ntxtSX.Value);
            Start.Y = Convert.ToInt32(ntxtSY.Value);
            SetDestPoint(true, Start);
            End.X = Convert.ToInt32(ntxtEX.Value);
            End.Y = Convert.ToInt32(ntxtEY.Value);
            SetDestPoint(false, End);
            frmDiffMap.DrawingStartEndPoints();
            frmDiffMap.Show();

            // Set dimensions for controls
            // BUG: if distmap is not loaded, this crashes.
            ProjectConstants.DefaultHeight = CurDistMap.Rows;
            ProjectConstants.DefaultWidth = CurDistMap.Columns;
            ntxtSX.Maximum = ProjectConstants.DefaultWidth;
            ntxtSY.Maximum = ProjectConstants.DefaultHeight;
            ntxtEX.Maximum = ProjectConstants.DefaultWidth;
            ntxtEY.Maximum = ProjectConstants.DefaultHeight;
        }