Example #1
0
        //Initializes all the objects in main_form
        private void Initialization()
        {
            int BoardersWidth = 2 * SystemInformation.Border3DSize.Width;

            if (Globals._FirstFormLoad)
            {
                if (File.Exists("info.txt"))
                {
                    StreamReader reader = new StreamReader("info.txt");
                    try {
                        Globals._WidthBlocks  = Convert.ToInt32(reader.ReadLine());
                        Globals._HeightBlocks = Convert.ToInt32(reader.ReadLine());
                        Globals._BlockSide    = Convert.ToInt32(reader.ReadLine());
                    } catch { MessageBox.Show("An error has occured while parsing the file to initialize form.\nPlease delete the file."); }
                    reader.Dispose();
                }
                Globals._FirstFormLoad = false;
            }


            isLoad = new int[Globals._WidthBlocks, Globals._HeightBlocks];
            //m_rectangels is an array of two 1d arrays
            //declares the length of the first 1d array
            m_rectangles = new GridBox[Globals._WidthBlocks][];


            for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
            {
                //declares the length of the seconds 1d array
                m_rectangles[widthTrav] = new GridBox[Globals._HeightBlocks];
                for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                {
                    //dynamically add the gridboxes into the m_rectangles.
                    //size of the m_rectangels is constantly increasing (while adding
                    //the gridbox values) until size=height or size = width.
                    //if (imported) { //this IF is executed as long as the user has imported a map of his choice
                    //    m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals._BlockSide) - BoardersWidth, heightTrav * Globals._BlockSide + Globals._TopBarOffset, importmap[widthTrav, heightTrav]);
                    //if (importmap[widthTrav, heightTrav] == BoxType.Load) {
                    //     isLoad[widthTrav, heightTrav] = 1;
                    // }
                    //} else {
                    m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals._BlockSide) - BoardersWidth, heightTrav * Globals._BlockSide + Globals._TopBarOffset, BoxType.Normal);
                    isLoad[widthTrav, heightTrav]       = 2;
                    //}
                }
            }
            if (imported)
            {
                imported = false;
            }


            searchGrid = new StaticGrid(Globals._WidthBlocks, Globals._HeightBlocks);
            jumpParam  = new AStarParam(searchGrid, Convert.ToSingle(Globals._AStarWeight)); //Default value until user edit it
            jumpParam.SetHeuristic(HeuristicMode.MANHATTAN);                                 //default value until user edit it

            ConfigUI();
        }
Example #2
0
        //function that resets all of the used objects so they are ready for reuse, preventing memory leaks
        private void FullyRestore()
        {
            if (trappedStatus != null)
            {
                Array.Clear(trappedStatus, 0, trappedStatus.GetLength(0));
            }

            //if (importmap != null) {
            //    Array.Clear(importmap, 0, importmap.GetLength(0));
            //     Array.Clear(importmap, 0, importmap.GetLength(1));
            // }

            if (BackgroundImage != null)
            {
                BackgroundImage = null;
            }

            startPos      = new List <GridPos>();
            selectedColor = Color.DarkGray;

            for (int i = 0; i < startPos.Count(); i++)
            {
                AGVs[i].JumpPoints = new List <GridPos>();
            }


            searchGrid = new StaticGrid(Globals._WidthBlocks, Globals._HeightBlocks);

            alwaysCross =
                aGVIndexToolStripMenuItem.Checked =
                    beforeStart        =
                        allowHighlight = true;

            atLeastOneObstacle                    =
                ifNoObstacles                     =
                    never                         =
                        imported                  =
                            calibrated            =
                                isMouseDown       =
                                    mapHasLoads   =
                                        overImage = false;

            menuPanel.Enabled = false;

            use_Halt = false;
            priorityRulesbetaToolStripMenuItem.Checked = false;

            importedLayout = null;
            jumpParam      = null;
            paper          = null;

            a
                  = b
                  = new int();


            AGVs = new List <Vehicle>();

            allowHighlight = true;
            highlightOverCurrentBoxToolStripMenuItem.Enabled = true;
            highlightOverCurrentBoxToolStripMenuItem.Checked = true;



            isLoad       = new int[Globals._WidthBlocks, Globals._HeightBlocks];
            m_rectangles = new GridBox[Globals._WidthBlocks][];
            for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[Globals._HeightBlocks];
            }

            //jagged array has to be resetted like this
            for (int i = 0; i < Globals._WidthBlocks; i++)
            {
                for (int j = 0; j < Globals._HeightBlocks; j++)
                {
                    m_rectangles[i][j] = new GridBox(i * Globals._BlockSide, j * Globals._BlockSide + Globals._TopBarOffset, BoxType.Normal);
                }
            }


            Initialization();

            main_form_Load(new object(), new EventArgs());

            for (int i = 0; i < AGVs.Count; i++)
            {
                AGVs[i].Status.Busy = false;
            }

            Globals._TimerStep = 0;

            nUD_AGVs.Value = AGVs.Count;
        }
Example #3
0
        //function that resets all of the used objects so they are ready for reuse, preventing memory leaks
        private void FullyRestore()
        {
            if (tree_stats.Nodes[1].IsExpanded)
            {
                tree_stats.Nodes[1].Collapse();
            }

            tree_stats.Nodes[1].Nodes[0].Text = "CO: -";
            tree_stats.Nodes[1].Nodes[1].Text = "CO2: -";
            tree_stats.Nodes[1].Nodes[2].Text = "NOx: -";
            tree_stats.Nodes[1].Nodes[3].Text = "THC: -";
            tree_stats.Nodes[1].Nodes[4].Text = "Global Warming eq: -";

            _labeled_loads = 0;

            if (_onWhichStep != null)
            {
                Array.Clear(_onWhichStep, 0, _onWhichStep.GetLength(0));
            }

            if (_trappedStatus != null)
            {
                Array.Clear(_trappedStatus, 0, _trappedStatus.GetLength(0));
            }


            for (short i = 0; i < _AGVs.Count; i++)
            {
                _AGVs[i].KillIcon();
            }


            if (_importmap != null)
            {
                Array.Clear(_importmap, 0, _importmap.GetLength(0));
                Array.Clear(_importmap, 0, _importmap.GetLength(1));
            }

            if (BackgroundImage != null)
            {
                BackgroundImage = null;
            }

            StackTrace trace = new StackTrace();

            if (trace.GetFrame(1).GetMethod().Name != "Import")
            {
                Globals.SemiTransparency = false;
                _boxDefaultColor         = (Globals.SemiTransparency) ? Color.FromArgb(Globals.Opacity, Color.WhiteSmoke) : Color.WhiteSmoke;
            }

            _fromstart = new bool[Globals.MaximumAGVs];


            _startPos       = new List <GridPos>();
            _endPointCoords = new Point(-1, -1);
            _selectedColor  = Color.DarkGray;

            for (short i = 0; i < _startPos.Count(); i++)
            {
                _AGVs[i].JumpPoints = new List <GridPos>();
            }


            _searchGrid = new StaticGrid(Globals.WidthBlocks, Globals.HeightBlocks);

            _alwaysCross =
                aGVIndexToolStripMenuItem.Checked =
                    _beforeStart        =
                        _allowHighlight = true;

            _atLeastOneObstacle                  =
                _ifNoObstacles                   =
                    _never                       =
                        _imported                =
                            _calibrated          =
                                _isMouseDown     =
                                    _mapHasLoads = false;

            _useHalt = false;
            priorityRulesbetaToolStripMenuItem.Checked = false;

            _importedLayout = null;
            _jumpParam      = null;
            _paper          = null;
            _loads          = _posIndex = 0;

            _a
                  = _b
                  = new int();


            _AGVs = new List <Vehicle>();
            _CO2  = _CO = _NOx = _THC = _globalWarming = 0;

            _allowHighlight = true;
            highlightOverCurrentBoxToolStripMenuItem.Enabled = true;
            highlightOverCurrentBoxToolStripMenuItem.Checked = true;



            _isLoad     = new int[Globals.WidthBlocks, Globals.HeightBlocks];
            _rectangles = new GridBox[Globals.WidthBlocks][];
            for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
            {
                _rectangles[widthTrav] = new GridBox[Globals.HeightBlocks];
            }

            //jagged array has to be resetted like this
            for (var i = 0; i < Globals.WidthBlocks; i++)
            {
                for (var j = 0; j < Globals.HeightBlocks; j++)
                {
                    _rectangles[i][j] = new GridBox(i * Globals.BlockSide, j * Globals.BlockSide + Globals.TopBarOffset, BoxType.Normal);
                }
            }


            Initialization();

            main_form_Load(new object(), new EventArgs());

            for (short i = 0; i < _AGVs.Count; i++)
            {
                _AGVs[i].Status.Busy = false;
            }

            Globals.TimerStep = 0;
            timer0.Interval   = timer1.Interval = timer2.Interval = timer3.Interval = timer4.Interval = Globals.TimerInterval;


            nUD_AGVs.Value           = _AGVs.Count;
            tree_stats.Nodes[2].Text = "Loads remaining: ";
        }
Example #4
0
        //Initializes all the objects in main_form
        private void Initialization()
        {
            DiagonalMovement diagonalMovement = DiagonalMovement.Always;
            HeuristicMode    heuristicMode    = HeuristicMode.Manhattan;

            char[] delim = { ':', ' ', '(' };
            if (File.Exists("info.txt"))
            {
                if (Globals.FirstFormLoad)
                {
                    StreamReader reader = new StreamReader("info.txt");
                    try {
                        Globals.WidthBlocks              = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        Globals.HeightBlocks             = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        Globals.BlockSide                = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        diagonalMovement                 = (DiagonalMovement)Enum.Parse(typeof(DiagonalMovement), reader.ReadLine().Split(delim)[1]);
                        heuristicMode                    = (HeuristicMode)Enum.Parse(typeof(HeuristicMode), reader.ReadLine().Split(delim)[2]);
                        stepsToolStripMenuItem.Checked   = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        linesToolStripMenuItem.Checked   = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        dotsToolStripMenuItem.Checked    = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        bordersToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        highlightOverCurrentBoxToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        aGVIndexToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                    } catch {
                        MessageBox.Show("An error has occured while parsing the file to initialize form.\nPlease delete the file.");
                    }
                    reader.Close();
                }
                Globals.FirstFormLoad = false;
            }



            _isLoad = new int[Globals.WidthBlocks, Globals.HeightBlocks];
            //m_rectangels is an array of two 1d arrays
            //declares the length of the first 1d array
            _rectangles = new GridBox[Globals.WidthBlocks][];


            for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
            {
                //declares the length of the seconds 1d array
                _rectangles[widthTrav] = new GridBox[Globals.HeightBlocks];
                for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                {
                    //dynamically add the gridboxes into the _rectangles.
                    //size of the m_rectangels is constantly increasing (while adding
                    //the gridbox values) until size=height or size = width.
                    if (_imported)   //this IF is executed as long as the user has imported a map of his choice
                    {
                        _rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals.BlockSide) + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, _importmap[widthTrav, heightTrav]);
                        if (_importmap[widthTrav, heightTrav] == BoxType.Load)
                        {
                            _isLoad[widthTrav, heightTrav] = 1;
                            _loads++;
                        }
                    }
                    else
                    {
                        _rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals.BlockSide) + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, BoxType.Normal);
                        _isLoad[widthTrav, heightTrav]     = 2;
                    }
                }
            }
            if (_imported)
            {
                _imported = false;
            }


            _searchGrid = new StaticGrid(Globals.WidthBlocks, Globals.HeightBlocks);
            _jumpParam  = new AStarParam(
                _searchGrid,
                Convert.ToSingle(Globals.AStarWeight),
                diagonalMovement,
                heuristicMode
                );

            ConfigUi();
        }