注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
backtracking 最优解法,可以比较突出
解法,先根据productID 对order分类使用group方法
然后利用getFastest每个仓库找到最快的到其他任何一个地方的运输方法
最后新建一个类Max里面,把一堆order和有该product的仓库,扔到使用backtrack对每个订单进行搜索,比较暴力,不过数据量不大,所以可以达到满足100%,cost也非常低
最后得到的List<OrderProcess> 可以进行订单的处理
这里只是大概的代码,具体的你就还需要小修改
public class MileStone{
static List<Order> orders;
static List<ProductInventory> inventory;
static List<ShippingCost> costs;
public static void milestone2() {
Map<ProductInventory, Map<Region, ShippingCost>> map = new HashMap<>();
for(ProductInventory productInventory : inventory){
Map<Region, ShippingCost> fastShipping = getFastest(productInventory);
map.put(productInventory, fastShipping);
}
Map<Integer, List<Order>> orders = group(orders);
for(int productID : orders.keySet()){
List<Order> orderList = groupOrder.get(productID);
Max max = new Max();
List<OrderProcess> res = new LinkedList<to)));
dfs(orderGroup, inventoryList,map,i+1, temp);
temp.remove(temp.size()-1);
inv.reduceQuantity(0-order.quantity);
}
}
if(!found){
//dfs(orderGroup, inventoryList,map,i+1, temp); //此处为拼单
}
}
}
class OrderProcess{
Order order;
ProductInventory inventory;
ShippingCost cost;
public OrderProcess(Order order,ProductInventory inventory,ShippingCost cost){
this.order = order;
this.inventory = inventory;
this.cost = cost;
}
}
|