Example #1
0
 public void addConnection(TransportConnection c)
 {
     if (!Connections.Contains(c))
     {
         Connections.Add(c);
     }
 }
Example #2
0
        private void relocateSuppliesByRelocationPath(LinkedList <TransportConnection> relocatePath)
        {
            double AmountToMove = countAmountToMoveForRelocationPath(relocatePath);

            for (int i = 0; i < relocatePath.Count; i++)
            {
                TransportConnection c = relocatePath.ElementAt(i);
                c.Amount += Math.Pow(-1, i) * AmountToMove;
            }
        }
Example #3
0
 private void init()
 {
     demand = 0.0;
     supply = 0.0;
     foreach (Supplier s in suppliers)
     {
         supply += s.Supply;
     }
     foreach (Customer c in customers)
     {
         demand += c.Demand;
     }
     if (demand < supply)
     {
         Customer cust = new Customer(supply - demand, 0);
         cust.IsFake = true;
         customers.Add(cust);
     }
     else if (supply < demand)
     {
         Supplier supp = new Supplier(demand - supply, 0);
         supp.IsFake = true;
         suppliers.Add(supp);
     }
     customersAmount = customers.Count;
     suppliersAmount = suppliers.Count;
     if (demand != supply)
     {
         TransportConnection[,] tmp = new TransportConnection[suppliersAmount, customersAmount];
         for (int i = 0; i < suppliersAmount; i++)
         {
             for (int j = 0; j < customersAmount; j++)
             {
                 if (i < connections.Length && j < connections.Rank)
                 {
                     tmp[i, j] = connections[i, j];
                 }
                 else
                 {
                     tmp[i, j] = new TransportConnection(suppliers[i], customers[j], 0, i, j);
                 }
                 if (tmp[i, j].Supplier.IsFake && tmp[i, j].Customer.IsPrivileged ||
                     tmp[i, j].Customer.IsFake && tmp[i, j].Supplier.IsPrivileged)
                 {
                     tmp[i, j].Blocked = true;
                 }
             }
         }
         connections = tmp;
     }
     matrixD = new double[suppliersAmount, customersAmount];
     vectorA = new double[suppliersAmount];
     vectorB = new double[customersAmount];
 }
Example #4
0
        private double countUnitProfitForRelocationPath(LinkedList <TransportConnection> tmpList)
        {
            double UnitProfit = 0;

            for (int i = 1; i < tmpList.Count; i++)
            {
                TransportConnection c = tmpList.ElementAt(i);
                if (i % 2 == 1)
                {
                    UnitProfit += matrixD[c.X, c.Y];
                }
            }
            return(UnitProfit);
        }
Example #5
0
        private double countAmountToMoveForRelocationPath(LinkedList <TransportConnection> tmpList)
        {
            double AmountToMove = tmpList.ElementAt(1).Amount;

            for (int i = 1; i < tmpList.Count; i++)
            {
                TransportConnection c = tmpList.ElementAt(i);
                if (i % 2 == 0)
                {
                    AmountToMove = Math.Min(AmountToMove, c.Amount);
                }
            }
            return(AmountToMove);
        }
Example #6
0
        private LinkedList <TransportConnection> findBestLoopedRelocationPath(TransportConnection currentConn, LinkedList <TransportConnection> listMain, bool verticalDirection, bool nextNeedSupply)
        {
            listMain.AddLast(currentConn);
            List <TransportConnection> toCheck = null;

            if (verticalDirection)
            {
                toCheck = Utils.getColumnAsList(currentConn.X, connections);
            }
            else
            {
                toCheck = Utils.getRowAsList(currentConn.Y, connections);
            }
            if (currentConn != listMain.First() && toCheck.Contains(listMain.First()) && !nextNeedSupply)
            {
                return(listMain);
            }

            LinkedList <TransportConnection> bestList = null, tmpList = null;

            foreach (TransportConnection c in toCheck)
            {
                if (c != currentConn && !listMain.Contains(c) && !c.Blocked)
                {
                    if (!nextNeedSupply || c.Amount > 0)
                    {
                        LinkedList <TransportConnection> tmp = new LinkedList <TransportConnection>(listMain);
                        tmpList = findBestLoopedRelocationPath(c, tmp,
                                                               !verticalDirection, !nextNeedSupply);
                        if (tmpList != null && (bestList == null || countTotalProfitForRelocationPath(tmpList) > countTotalProfitForRelocationPath(bestList)))
                        {
                            bestList = tmpList;
                        }
                    }
                }
            }
            return(bestList);
        }
Example #7
0
        public Logic()
        {
            suppliers = new List <Supplier>();
            customers = new List <Customer>();
            //            FileHandler.LoadData("InitialData.txt", Providers, Recipients);


            suppliers.Add(new Supplier(1, 0));
            suppliers.Add(new Supplier(1, 0));
            suppliers.Add(new Supplier(1, 0));

            customers.Add(new Customer(2, 0));
            customers.Add(new Customer(1, 0));
            customers.Add(new Customer(1, 0));

            TransportConnection[,] connections = new TransportConnection[3, 3];
            double[,] connectionCosts          = new double[3, 3];

            connectionCosts[0, 0] = 3;
            connectionCosts[0, 1] = 7;
            connectionCosts[0, 2] = 6;
            connectionCosts[1, 0] = 5;
            connectionCosts[1, 1] = 6;
            connectionCosts[1, 2] = 2;
            connectionCosts[2, 0] = 2;
            connectionCosts[2, 1] = 5;
            connectionCosts[2, 2] = 4;

            for (int i = 0; i < suppliers.Count; i++)
            {
                for (int j = 0; j < customers.Count; j++)
                {
                    connections[i, j] = new TransportConnection(suppliers[i], customers[j], connectionCosts[i, j], i, j);
                }
            }
            Solve();
        }
Example #8
0
        private LinkedList <TransportConnection> findBestRelocationPath(TransportConnection start)
        {
            LinkedList <TransportConnection> list = new LinkedList <TransportConnection>();

            return(findBestLoopedRelocationPath(start, list, true, true));
        }