Exemplo n.º 1
0
 private void CreateCells()
 {
     for (int i = 0; i < Cells.Length; i++)
     {
         Cells[i] = new Cell(this, _supplier.GetRates()[i]);
     }
 }
        protected void AddTransportation(Cell cell)
        {
            int rate = cell.GetRate();
            int supplierStock = cell.GetRow().GetStock();
            int consumerNeeds = cell.GetColumn().GetRequirement();

            Transportation transportation;

            if (consumerNeeds > supplierStock)
            {
                transportation = new Transportation(supplierStock, rate);
                cell.AddTransportation(transportation);

                _table.RemoveRow(cell.GetRow());
                cell.GetColumn().SetRequirement(consumerNeeds - supplierStock);
                cell.GetRow().SetStock(0);
            }
            else
            {
                transportation = new Transportation(consumerNeeds, rate);
                cell.AddTransportation(transportation);

                _table.RemoveColumn(cell.GetColumn());
                cell.GetColumn().SetRequirement(0);
                cell.GetRow().SetStock(supplierStock - consumerNeeds);
            }
        }
Exemplo n.º 3
0
        public void BindCells(Cell[] cells)
        {
            Cells = cells;

            foreach (Cell cell in Cells)
            {
                cell.BindColumn(this);
            }
        }
Exemplo n.º 4
0
        public TableRow(int index, Supplier supplier)
            : base(index)
        {
            _supplier = supplier;
            _stock = supplier.GetStock();

            Cells = new Cell[supplier.GetRates().Length];
            CreateCells();
        }
Exemplo n.º 5
0
        private int GetMinTransportationCargo(Cell[] cycle)
        {
            int min = cycle[1].GetTransportation().GetCargo();

            for (int i = 1; i < cycle.Length; i++)
            {
                Cell cell = cycle[i];

                if (i%2 != 0 && cell.GetTransportation().GetCargo() < min)
                    min = cell.GetTransportation().GetCargo();

            }

            return min;
        }
Exemplo n.º 6
0
        private void DoRedistribution(Cell[] cycle)
        {
            ArrayList calculated = new ArrayList();
            int min = GetMinTransportationCargo(cycle);

            var arr = cycle.ToArray();

            for (int i = 0; i < cycle.Length; i++)
            {
                Cell cell = (Cell) arr[i];

                if (calculated.Contains(cell))
                    continue;

                Transportation transportation = cell.GetTransportation();

                if (i == 0)
                {
                    cell.AddTransportation(new Transportation(min, cell.GetRate()));
                    calculated.Add(cell);
                    continue;
                }

                cell.AddTransportation(i%2 == 0
                    ? new Transportation(transportation.GetCargo() + min,
                        cell.GetRate())
                    : new Transportation(transportation.GetCargo() - min,
                        cell.GetRate()));

                calculated.Add(cell);

                if(cell.GetTransportation().GetCargo() == 0)
                    cell.RemoveTransportation();
            }
        }
Exemplo n.º 7
0
        private Cell[] BuildRedistributionCycle(Cell top)
        {
            ArrayList cycles = new ArrayList();
            ArrayList firstCycle = new ArrayList {top};

            cycles.Add(firstCycle);

            do
            {

                foreach (ArrayList cycle in cycles.ToArray())
                {
                    if (CheckCycleFinal(cycle))
                    {
                        return cycle.Cast<Cell>().Reverse().Skip(1).Reverse().ToArray();
                    }

                    MakeCycleBranches(cycles, cycle);

                }

            } while (true);
        }
Exemplo n.º 8
0
        private void CreateColumns(Consumer[] consumers)
        {
            for (int i = 0; i < _columns.Length; i++)
            {
                TableColumn column = new TableColumn(i, consumers[i]);
                Cell[] cells = new Cell[_rows.Length];

                for (int j = 0; j < _rows.Length; j++)
                {
                    cells[j] = _rows[j].GetCell(i);
                }

                column.BindCells(cells);
                _columns[i] = column;
            }
        }
 public void UnbindCell(Cell cell)
 {
     cell.Disable();
 }