/// <summary> /// adds the load command immediately to the commands queue, /// and stores the delivery command for later /// </summary> public void LoadForDelivery(Drone d, WareHouse wh, Order o, int item) { var load = String.Format("{0} L {1} {2} {3}", d.id, wh.id, item, 1); var deli = String.Format("{0} D {1} {2} {3}", d.id, o.id, item, 1); _validatedCommands.AppendLine(load); _deliveryOrders[d.id].AppendLine(deli); }
public bool Load(WareHouse wh, int itemType) { turn += Helper.Distance(X, Y, wh.X, wh.Y) + 1; X = wh.X; Y = wh.Y; payload += input.ProductTypes[itemType]; return turn <= input.NbTurns; }
public bool CheckLoad(WareHouse wh, int itemType) { var tmpturn = turn + Helper.Distance(X, Y, wh.X, wh.Y) + 1; if (tmpturn > input.NbTurns) { turn++; //send it to the future return false; } var tmppayload = payload + input.ProductTypes[itemType]; return tmppayload < input.MaxPayload; }
private static Order GetBestOrder(Drone d, Input input, out WareHouse goThere) { goThere = null; int bestCost = Int32.MaxValue; Order best = null; foreach (var order in input.Orders) { if(order.ItemsWanted == null) continue; //already delivered int cost = Int32.MaxValue; WareHouse bestWh = null; var totalWeight = order.TotalWeight; if (totalWeight < input.MaxPayload) //one drone can take care of this order { var eligibleWareHouses = input.WareHouses.Where(wh => wh.CanFullfillOrder(order.ItemsWanted) == order.NbItemsRemaining); if (eligibleWareHouses.Any()) //everything is in the same warehouse { foreach (var wh in eligibleWareHouses) { var dist = Helper.Distance(d.X, d.Y, wh.X, wh.Y) + Helper.Distance(wh.X, wh.Y, order.X, order.Y); if (dist < cost) { cost = dist; bestWh = wh; } } } else //one drone can do everything, but has to go to several warehouses { //simulate going to 3 different wh int dist = 0; var wh = input.WareHouses[Helper.Rand.Next(input.NbWareHouses)]; dist += Helper.Distance(d.X, d.Y, wh.X, wh.Y) * 3; dist += Helper.Distance(order.X, order.Y, wh.X, wh.Y); if (dist < cost) { cost = dist; } } } else //we'll need several drones to complete this order { //simulate going to 3 different wh int dist = 0; var wh = input.WareHouses[Helper.Rand.Next(input.NbWareHouses)]; dist += Helper.Distance(d.X, d.Y, wh.X, wh.Y)*3; dist += Helper.Distance(order.X, order.Y, wh.X, wh.Y); dist = (int)(_multidroneMalus * dist * totalWeight/input.MaxPayload); //apply a malus for estimated nb of drones needed if (dist < cost) { cost = dist; } } if (cost < bestCost) { bestCost = cost; best = order; goThere = bestWh; } } return best; }