-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlexStrategy.java
More file actions
97 lines (88 loc) · 3.17 KB
/
AlexStrategy.java
File metadata and controls
97 lines (88 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package hashcode.strategy;/*
User: ShvedA
Date: 11.02.2016
Time: 21:08
repo
*/
import hashcode.Main;
import hashcode.model.Drone;
import hashcode.model.Order;
import hashcode.model.ProductType;
import hashcode.model.Warehouse;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
public class AlexStrategy extends Strategy {
public static int dronToUse = 19;
public Drone getNextDron(){
dronToUse++;
if (dronToUse > 19) {
dronToUse = 0;
}
return Drone.drones[dronToUse];
}
public void countForAllOrders(){
Warehouse firstWarehouse = Warehouse.warehouses[0];
for (Order order : Order.orders) {
int distance = order.point.distanceTo(firstWarehouse.position);
int overalQty = 0;
for (int productId : order.products.keySet()){
int quantity = Main.TURNS / ProductType.productTypes[productId].weight;
overalQty += quantity;
}
order.time = distance * overalQty;
/*
int totalQty = 0;
for (int productId : order.products.keySet()){
totalQty += ProductType.productTypes[productId].weight * order.products.get(productId);
}
order.time = distance * (totalQty / Drone.MAX_WEIGHT) + (totalQty / Drone.MAX_WEIGHT) * 2;*/
}
Arrays.sort(Order.orders, new Comparator<Order>() {
@Override
public int compare(Order o1, Order o2) {
return o1.time - o2.time;
}
});
Drone drone = getNextDron();
int weight;
int nrOfProducts;
for(Warehouse warehouse: Warehouse.warehouses){
outer: for (Order order: Order.orders) {
Set<Integer> integers = order.products.keySet();
int[] values = new int[order.products.keySet().size()];
int varrr = 0;
for (Integer productId : integers){
values[varrr] = productId;
varrr++;
}
for (int productId : values) {
weight = ProductType.productTypes[productId].weight;
if (drone.freeSpace < weight) {
drone.DeliverAll(warehouse, order);
drone = getNextDron();
}
Integer productQty = order.products.get(productId);
nrOfProducts = StrictMath.min(productQty, drone.freeSpace / weight);
if (nrOfProducts == productQty) {
order.products.remove(productId);
} else {
order.products.put(productId, productQty - nrOfProducts);
}
if (!drone.Load(warehouse, productId, nrOfProducts)) {
drone.UnLoadAll(warehouse);
drone.freeSpace = Drone.MAX_WEIGHT;
continue outer;
}
}
drone.DeliverAll(warehouse, order);
drone = getNextDron();
} }
out.print(Main.CommandCount);
out.print(Main.sb.toString());
}
@Override
public void run() {
//out.print("AlexStrategy started");
}
}