示例#1
0
        public bool AddCargo(CargoInfo Cargo, Point Index)
        {
            int row = 0, col = 0;
            int dimY = data.GetLength(0);                                                  // Max height of the container
            int dimX = data.GetLength(1);                                                  // Max width of the container

            if (Index.Y + Cargo.Space.Width < dimX && Index.X + Cargo.Space.Height < dimY) // if it fits to container
            {                                                                              // While Index.Y is the column number of index.. Index.X is the row number
                for (int i = 0; i < Cargo.Space.Height; i++)                               // start scanfor rows
                {
                    for (int j = 0; j < Cargo.Space.Width; j++)                            // start scan for columns
                    {
                        row = i + Index.X; col = j + Index.Y;
                        data[row, col].StartIndex = false;
                        data[row, col].IsLoaded   = true;
                        data[row, col].Owner      = Cargo.Name;
                    }
                }
                // data[Cargo.Space.X, col + 1].StartIndex = true;
                ResetIndexes();
                cargoes.Add(Cargo.Name);
                return(true);
            }
            else
            { // give out of size err.here
                return(false);
            }
        }
示例#2
0
        public bool TestCargo(CargoInfo Cargo, Point Index)
        {
            //int row=0, col=0;
            int dimY = data.GetLength(0);                                                  // Max width of the container
            int dimX = data.GetLength(1);                                                  // Max heigth of the container

            if (Index.Y + Cargo.Space.Width < dimX && Index.X + Cargo.Space.Height < dimY) // if it fits to container
            {                                                                              // While Index.Y is the column number of index.. Index.X is the row number
                return(true);
            }
            else
            { // give out of size err.here
                return(false);
            }
        }
示例#3
0
        public bool TestCargo(CargoInfo Cargo, Point Index)
        {
            //int row=0, col=0;
            int dimY = data.GetLength(0); // Max width of the container
            int dimX = data.GetLength(1); // Max heigth of the container

            if (Index.Y + Cargo.Space.Width < dimX && Index.X + Cargo.Space.Height < dimY) // if it fits to container
            { // While Index.Y is the column number of index.. Index.X is the row number

                return true;
            }
            else
            { // give out of size err.here
                return false;
            }
        }
示例#4
0
        public bool AddCargo(CargoInfo Cargo, Point Index)
        {
            int row = 0, col = 0;
            int dimY = data.GetLength(0); // Max height of the container
            int dimX = data.GetLength(1); // Max width of the container

            if (Index.Y + Cargo.Space.Width < dimX && Index.X + Cargo.Space.Height < dimY) // if it fits to container
            { // While Index.Y is the column number of index.. Index.X is the row number
                for (int i = 0; i < Cargo.Space.Height; i++) // start scanfor rows
                {
                    for (int j = 0; j < Cargo.Space.Width; j++) // start scan for columns
                    {
                        row = i + Index.X; col = j + Index.Y;
                        data[row, col].StartIndex = false;
                        data[row, col].IsLoaded = true;
                        data[row, col].Owner = Cargo.Name;
                    }
                }
                // data[Cargo.Space.X, col + 1].StartIndex = true;
                ResetIndexes();
                cargoes.Add(Cargo.Name);
                return true;
            }
            else
            { // give out of size err.here
                return false;
            }
        }
示例#5
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            /* ***********************************
             * CAPCALC ALGORITHYM achieved by Rectgangels
             * to hold the cargo size and positions in its container
             *
             * Not:
             * the space property of CargoInfo class uses System.Drawing.Rectangel item
             * to hold the position and floor area of cargo. Pls, take attention while you
             * assigning new values as;
             *
             * Cargo.Space = new Rectangle(x,y, m,n);
             * x => Left of Cargo in Container space
             * y => Top of Cargo in Container space
             * m => is the Long  (x dimention of cargo floor area while you look from top)
             * n => is the Width (y dimention of cargo floor area while you look from top)
             *
             * *********************************** */
            var             secim = (ContainerInfo)cmbConSelector.SelectedItem;
            ContainerMatrix Ambar = new ContainerMatrix(secim);

            CargoInfo[] Kargolar;
            // Create the cargo list and sort them.
            if (ds.Tables[0].Rows.Count > 0)
            {
                Kargolar = new CargoInfo[ds.Tables[0].Rows.Count]; // size the cargo list
                // Read the cargoes from data table
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var crg = new CargoInfo();
                    crg.Name   = ds.Tables[0].Rows[i].Field <string>("Name");
                    crg.Long   = ds.Tables[0].Rows[i].Field <double>("Long");
                    crg.Width  = ds.Tables[0].Rows[i].Field <double>("Width");
                    crg.Height = ds.Tables[0].Rows[i].Field <double>("Height");
                    crg.Weight = ds.Tables[0].Rows[i].Field <double>("Weight");
                    crg.Level  = ds.Tables[0].Rows[i].Field <int>("Level");

                    Kargolar[i] = crg;
                }

                // Now Sort a copy of them based on CBM
                object[] sort = new object[Kargolar.Length];
                for (int i = 0; i < sort.Length; i++)
                {
                    sort[i] = Kargolar[i];
                }

                Helper.QuickSort(ref sort, "CBM");

                // Now check the Gravity Offset to start writing in container
                // (do that later, lets say "Top Left" for now)

                for (int i = sort.Length - 1; i >= 0; i--)  // Big to Small
                {
                    CargoInfo crg = (CargoInfo)sort[i];
                    if (Ambar.StartIndexes.Count > 0)
                    {
                        int indx = 0;
                        do
                        {
                            bool chk = Ambar.TestCargo(crg, Ambar.StartIndexes[indx]);
                            if (chk)  // cargo is availible to write in
                            {         // lets add it to matrix
                                Ambar.AddCargo(crg, Ambar.StartIndexes[indx]);
                                break;
                            }
                            else
                            {           // try to rotate or skip to the next index
                                indx++; // skip next index
                            }
                        } while (indx < Ambar.StartIndexes.Count);
                        // so far we just write the posible cargoes, until now.
                    }
                }

                // Try to take a snapshot for debug purpose
                DebuggerDisplay(Ambar); //shows loaded areas on selected cargo container matrix
            }
        }
示例#6
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            /* ***********************************
             * CAPCALC ALGORITHYM achieved by Rectgangels
             * to hold the cargo size and positions in its container
             *
             * Not:
             * the space property of CargoInfo class uses System.Drawing.Rectangel item
             * to hold the position and floor area of cargo. Pls, take attention while you
             * assigning new values as;
             *
             * Cargo.Space = new Rectangle(x,y, m,n);
             * x => Left of Cargo in Container space
             * y => Top of Cargo in Container space
             * m => is the Long  (x dimention of cargo floor area while you look from top)
             * n => is the Width (y dimention of cargo floor area while you look from top)
             *
             * *********************************** */
            var secim = (ContainerInfo)cmbConSelector.SelectedItem;
            ContainerMatrix Ambar = new ContainerMatrix(secim);

            CargoInfo[] Kargolar;
            // Create the cargo list and sort them.
            if (ds.Tables[0].Rows.Count > 0)
            {
                Kargolar = new CargoInfo[ds.Tables[0].Rows.Count]; // size the cargo list
                // Read the cargoes from data table
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var crg = new CargoInfo();
                    crg.Name = ds.Tables[0].Rows[i].Field<string>("Name");
                    crg.Long = ds.Tables[0].Rows[i].Field<double>("Long");
                    crg.Width = ds.Tables[0].Rows[i].Field<double>("Width");
                    crg.Height = ds.Tables[0].Rows[i].Field<double>("Height");
                    crg.Weight = ds.Tables[0].Rows[i].Field<double>("Weight");
                    crg.Level  = ds.Tables[0].Rows[i].Field<int>("Level");

                    Kargolar[i] = crg;
                }

                // Now Sort a copy of them based on CBM
                object[] sort = new object[Kargolar.Length];
                for (int i = 0; i < sort.Length; i++)
                {
                    sort[i] = Kargolar[i];
                }

                Helper.QuickSort(ref sort, "CBM");

                // Now check the Gravity Offset to start writing in container
                // (do that later, lets say "Top Left" for now)

                for (int i = sort.Length -1 ; i >= 0; i--)  // Big to Small
                {
                    CargoInfo crg = (CargoInfo)sort[i];
                    if (Ambar.StartIndexes.Count > 0)
                    {
                        int indx = 0;
                        do
                        {
                            bool chk = Ambar.TestCargo(crg, Ambar.StartIndexes[indx]);
                            if (chk)  // cargo is availible to write in
                            {         // lets add it to matrix
                                Ambar.AddCargo(crg, Ambar.StartIndexes[indx]);
                                break;
                            }
                            else
                            {       // try to rotate or skip to the next index
                                indx++;// skip next index
                            }
                        } while (indx < Ambar.StartIndexes.Count);
                        // so far we just write the posible cargoes, until now.
                    }
                }

                // Try to take a snapshot for debug purpose
                DebuggerDisplay(Ambar); //shows loaded areas on selected cargo container matrix
            }
        }