Esempio n. 1
0
        public TableColumn(int index, Consumer consumer)
            : base(index)
        {
            _consumer = consumer;

            _requirement = consumer.GetRequirement();
        }
        public void OptimizeTestCaseOne()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 2, 3, 2, 4 }, 30);
            suppliers[1] = new Supplier(new int[4] { 3, 2, 5, 1 }, 40);
            suppliers[2] = new Supplier(new int[4] { 4, 3, 2, 6 }, 20);

            consumers[0] = new Consumer(20);
            consumers[1] = new Consumer(30);
            consumers[2] = new Consumer(30);
            consumers[3] = new Consumer(10);

            NorthwestCornerMethod ncMethod = new NorthwestCornerMethod(suppliers, consumers);

            Table solution = ncMethod.GetSolution();

            PotentialsMethod potentialsMethod = new PotentialsMethod(solution);

            while (!potentialsMethod.IsOptimal())
            {
                potentialsMethod.Otimize();
            }

            Assert.AreEqual(solution.GetTotalTransportationsPrice(), 170);
        }
Esempio n. 3
0
        public Table(Supplier[] suppliers, Consumer[] consumers)
        {
            _rows = new TableRow[suppliers.Length];
            _columns = new TableColumn[consumers.Length];

            CreateRows(suppliers);
            CreateColumns(consumers);
        }
        public void TotalPriceTestCaseOne()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[3];

            suppliers[0] = new Supplier(new int[3]{2, 5, 2}, 180);
            suppliers[1] = new Supplier(new int[3] { 7, 7, 13 }, 300);
            suppliers[2] = new Supplier(new int[3] { 3, 6, 8 }, 120);

            consumers[0] = new Consumer(110);
            consumers[1] = new Consumer(350);
            consumers[2] = new Consumer(140);

            VogelsMethod method = new VogelsMethod(suppliers, consumers);

            Assert.AreEqual(2970, method.GetSolution().GetTotalTransportationsPrice());
        }
        public void TotalPriceTestCaseTwo()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 5, 2, 1, 8 }, 10);
            suppliers[1] = new Supplier(new int[4] { 2, 1, 2, 3 }, 10);
            suppliers[2] = new Supplier(new int[4] { 4, 8, 1, 4 }, 20);

            consumers[0] = new Consumer(14);
            consumers[1] = new Consumer(15);
            consumers[2] = new Consumer(5);
            consumers[3] = new Consumer(6);

            VogelsMethod method = new VogelsMethod(suppliers, consumers);

            Assert.AreEqual(100, method.GetSolution().GetTotalTransportationsPrice());
        }
        public void TotalPriceTestCaseThree()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 2, 3, 2, 4 }, 30);
            suppliers[1] = new Supplier(new int[4] { 3, 2, 5, 1 }, 40);
            suppliers[2] = new Supplier(new int[4] { 4, 3, 2, 6 }, 20);

            consumers[0] = new Consumer(20);
            consumers[1] = new Consumer(30);
            consumers[2] = new Consumer(30);
            consumers[3] = new Consumer(10);

            VogelsMethod method = new VogelsMethod(suppliers, consumers);

            Assert.AreEqual(170, method.GetSolution().GetTotalTransportationsPrice());
        }
        public void IsOptimalTestCaseTwo()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 2, 3, 2, 4 }, 30);
            suppliers[1] = new Supplier(new int[4] { 3, 2, 5, 1 }, 40);
            suppliers[2] = new Supplier(new int[4] { 4, 3, 2, 6 }, 20);

            consumers[0] = new Consumer(20);
            consumers[1] = new Consumer(30);
            consumers[2] = new Consumer(30);
            consumers[3] = new Consumer(10);

            NorthwestCornerMethod ncMethod = new NorthwestCornerMethod(suppliers, consumers);

            Table solution = ncMethod.GetSolution();

            PotentialsMethod potentialsMethod = new PotentialsMethod(solution);

            Assert.False(potentialsMethod.IsOptimal());
        }
        public void IsOptimalTestCaseOne()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 2, 3, 2, 4 }, 30);
            suppliers[1] = new Supplier(new int[4] { 3, 2, 5, 1 }, 40);
            suppliers[2] = new Supplier(new int[4] { 4, 3, 2, 6 }, 20);

            consumers[0] = new Consumer(20);
            consumers[1] = new Consumer(30);
            consumers[2] = new Consumer(30);
            consumers[3] = new Consumer(10);

            VogelsMethod vogelsMethod = new VogelsMethod(suppliers, consumers);

            Table solution = vogelsMethod.GetSolution();

            PotentialsMethod potentialsMethod = new PotentialsMethod(solution);

            Assert.True(potentialsMethod.IsOptimal());
        }
        public void OptimizeTestCaseThree()
        {
            Supplier[] suppliers = new Supplier[3];
            Consumer[] consumers = new Consumer[4];

            suppliers[0] = new Supplier(new int[4] { 5, 2, 1, 8 }, 10);
            suppliers[1] = new Supplier(new int[4] { 2, 1, 2, 3 }, 10);
            suppliers[2] = new Supplier(new int[4] { 4, 8, 1, 4 }, 20);

            consumers[0] = new Consumer(14);
            consumers[1] = new Consumer(15);
            consumers[2] = new Consumer(5);
            consumers[3] = new Consumer(6);

            NorthwestCornerMethod ncMethod = new NorthwestCornerMethod(suppliers, consumers);

            Table solution = ncMethod.GetSolution();

            PotentialsMethod potentialsMethod = new PotentialsMethod(solution);

            while (!potentialsMethod.IsOptimal())
            {
                potentialsMethod.Otimize();
            }

            Assert.AreEqual(solution.GetTotalTransportationsPrice(), 100);
        }
        public void OptimizeTestCaseTwo()
        {
            Supplier[] suppliers = new Supplier[4];
            Consumer[] consumers = new Consumer[5];

            suppliers[0] = new Supplier(new int[5] { 9, 5, 7, 10, 18 }, 78);
            suppliers[1] = new Supplier(new int[5] { 36, 29, 6, 38, 40 }, 94);
            suppliers[2] = new Supplier(new int[5] { 41, 20, 11, 25, 19 }, 29);
            suppliers[3] = new Supplier(new int[5] { 30, 28, 13, 39, 50 }, 86);

            consumers[0] = new Consumer(49);
            consumers[1] = new Consumer(60);
            consumers[2] = new Consumer(78);
            consumers[3] = new Consumer(50);
            consumers[4] = new Consumer(50);

            NorthwestCornerMethod ncMethod = new NorthwestCornerMethod(suppliers, consumers);

            Table solution = ncMethod.GetSolution();

            PotentialsMethod potentialsMethod = new PotentialsMethod(solution);

            while (!potentialsMethod.IsOptimal())
            {
                potentialsMethod.Otimize();
            }

            Assert.AreEqual(solution.GetTotalTransportationsPrice(), 4870);
        }
 protected FirstlySolutionMethod(Supplier[] suppliers, Consumer[] consumers)
 {
     _table = new Table.Table(suppliers, consumers);
 }
Esempio n. 12
0
 public VogelsMethod(Supplier[] suppliers, Consumer[] consumers)
     : base(suppliers, consumers)
 {
 }
 public NorthwestCornerMethod(Supplier[] suppliers, Consumer[] consumers)
     : base(suppliers, consumers)
 {
 }
Esempio n. 14
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;
            }
        }