Exemplo n.º 1
0
        private void CreateRegularColumns()
        {
            foreach (ContainerStack cs in _toBePlacedStacks)
            {
                bool stackIsAdded = false;

                for (int i = 0; i < ContainerColumns.Count && !stackIsAdded; i++)
                {
                    try
                    {
                        ContainerColumns[i].AddStack(cs);
                        stackIsAdded = true;
                    }catch
                    {
                        //If it can't be placed in any column, create a new column
                        if (i == ContainerColumns.Count - 1)
                        {
                            ContainerColumn newColumn = new ContainerColumn(_maxRows);
                            newColumn.AddStack(cs);
                            ContainerColumns.Add(newColumn);
                            stackIsAdded = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 //Constructor
 public Ship(int rows, int columns, int maxWeight)
 {
     //Init
     CurrentWeight      = 0;
     this.RowsAmount    = rows;
     this.ColumnsAmount = columns;
     ColumnGrid         = new ContainerColumn[columns];
     this.MaxWeight     = maxWeight;
 }
Exemplo n.º 3
0
        private void CreateCooledColumns()
        {
            //Creates new columns for each cooled stack
            List <ContainerStack> cooledStacks = _toBePlacedStacks.FindAll(cs => cs.IsCooled).ToList();

            foreach (ContainerStack cs in cooledStacks)
            {
                ContainerColumn cooledColumn = new ContainerColumn(_maxRows);
                cooledColumn.AddStack(cs);
                _toBePlacedStacks.Remove(cs);
                ContainerColumns.Add(cooledColumn);
            }
        }
Exemplo n.º 4
0
 private void PlaceColumnInGrid(ContainerColumn containerColumn, int position)
 {
     if (ColumnGrid[position] == null && containerColumn.TotalWeight + CurrentWeight <= MaxWeight)
     {
         ColumnGrid[position] = containerColumn;
         ToBePlacedColumns.Remove(containerColumn);
     }
     else
     {
         if (ColumnGrid[position] != null)
         {
             throw new Exception("Position already occupied.");
         }
         else
         {
             throw new Exception("Exceeding max weight.");
         }
     }
 }
Exemplo n.º 5
0
        private void CreatePreciousColumns()
        {
            List <ContainerStack> preciousStacks = _toBePlacedStacks.FindAll(cs => cs.IsPrecious).ToList();
            int preciousStacksAmount             = preciousStacks.Count;


            //Creates at least two columns
            while (ContainerColumns.Count < 2)
            {
                ContainerColumn cc = new ContainerColumn(_maxRows);
                ContainerColumns.Add(cc);
            }

            ContainerColumns = ContainerColumns.OrderByDescending(cc => cc.TotalWeight).ToList();
            ContainerColumn heaviest1 = ContainerColumns[0];
            ContainerColumn heaviest2 = ContainerColumns[1];

            foreach (ContainerStack cs in preciousStacks)
            {
                if (heaviest1.TotalWeight > heaviest2.TotalWeight)
                {
                    try
                    {
                        heaviest2.AddStack(cs);
                        _toBePlacedStacks.Remove(cs);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            heaviest1.AddStack(cs);
                            _toBePlacedStacks.Remove(cs);
                        }
                        catch
                        {
                            _unplaceableStacks.Add(cs);
                            _toBePlacedStacks.Remove(cs);
                        }
                    }
                }
                else
                {
                    try
                    {
                        heaviest1.AddStack(cs);
                        _toBePlacedStacks.Remove(cs);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            heaviest2.AddStack(cs);
                            _toBePlacedStacks.Remove(cs);
                        }
                        catch
                        {
                            _unplaceableStacks.Add(cs);
                            _toBePlacedStacks.Remove(cs);
                        }
                    }
                }
            }
        }