/// <summary> /// This function will add an order at the end of the current Order list. /// </summary> /// <param name="order">The order id to be added at the end of the list </param> public void AddOrder(Order order, OrdersCounter ordersCounter) { int matrixIDA = 287; // the previous coordinate int matrixIDB = order.MatrixID; // new added coordinate int matrixIDC = 287; // the dropping coordinate if (Orders.Count < 2) { matrixIDA = matrixIDC; // dropping coordinate } else { matrixIDA = Orders[Orders.Count - 2].MatrixID; // last coordinate } Weight += order.VolumePerContainer * order.NumberOfContainers; //adds the weight of this order TravelTime += order.EmptyingTimeInSeconds; //adds empty time //now we need to calculate back drive times as well TravelTime -= FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDC].TravelTime; //removes the old travel time to base // if midA = 0 it will remove 0 so no extra if check needed TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDB].TravelTime; //adds the travel time from last node to this node TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDB, matrixIDC].TravelTime; //adds the new travel time to base from the added node //Orders.Add(order); // adds the order to the order list Orders.Insert(Orders.Count - 1, order); ordersCounter.AddOccurrence(order.OrderNumber); }
/// <summary> /// This function will add a new order afther the specified order in the orderlist. /// </summary> /// <param name="newOrder"> The new Order to be added </param> /// <param name="afterOrder"> The Order the new it will be placed after </param> public void AddOrder(Order newOrder, Order afterOrder, OrdersCounter ordersCounter) { int matrixIDA = afterOrder.MatrixID; //the coord this order will be placed afhter int matrixIDB = newOrder.MatrixID; // new added coordinate int matrixIDC = 287; // the dropping coordinate int Ordernext = Orders.Count - 2; if (Orders.FindIndex(o => o.OrderNumber == afterOrder.OrderNumber) == Orders.Count - 2) //if order is added on the end of the list { TravelTime -= FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDC].TravelTime; //remove travel time to end if was last item on list TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDB, matrixIDC].TravelTime; //adds the new travel time to base from the added node TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDB].TravelTime; //adds the new travel time from the prev to the added node TravelTime += newOrder.EmptyingTimeInSeconds; //adds empty time } else { Ordernext = Orders.FindIndex(o => o.OrderNumber == afterOrder.OrderNumber) + 1; //gets the orderid in the orderlist matrixIDC = Orders[Ordernext].MatrixID; // gets the matric id of the obtained orderid TravelTime -= FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDC].TravelTime; //remove travel time to next node from previous node TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDA, matrixIDB].TravelTime; //adds the new travel time from previous to the new node TravelTime += FilesInitializer._DistanceMatrix.Matrix[matrixIDB, matrixIDC].TravelTime; //adds the new travel time from the new node to the next node TravelTime += newOrder.EmptyingTimeInSeconds; //adds empty time } Weight += newOrder.VolumePerContainer * newOrder.NumberOfContainers; //adds the weight of this order Orders.Insert(Ordernext, newOrder); // adds the order to the order list ordersCounter.AddOccurrence(newOrder.OrderNumber); }
/// <summary> /// This function removes the specified order from the order list and updates the traveltime and weight /// </summary> /// <param name="order"> Removes the given order from the list </param> public void RemoveOrder(Order order, OrdersCounter ordersCounter) { int previousOrder = 287; //node before the removed node int currentOrder = order.MatrixID; // the removed node int nextOrder = 287; //node after the removed node int indexNumber = Orders.FindIndex(o => o.OrderNumber == order.OrderNumber); if (indexNumber > 0) //if the removed node is not the first node { previousOrder = Orders[indexNumber - 1].MatrixID; } if (indexNumber < Orders.Count - 2) //if the removed node is not the last node { nextOrder = Orders[indexNumber + 1].MatrixID; } //update travel time TravelTime -= FilesInitializer._DistanceMatrix.Matrix[previousOrder, currentOrder].TravelTime; TravelTime -= FilesInitializer._DistanceMatrix.Matrix[currentOrder, nextOrder].TravelTime; TravelTime += FilesInitializer._DistanceMatrix.Matrix[previousOrder, nextOrder].TravelTime; TravelTime -= order.EmptyingTimeInSeconds; //remove empty time Weight -= order.VolumePerContainer * order.NumberOfContainers; //adds the weight of this order Orders.Remove(order); ordersCounter.RemoveOccurrence(order.OrderNumber); }