Browse Source

Better greedy

Olivier Marty 8 years ago
parent
commit
5c98cf57fa
4 changed files with 34 additions and 12 deletions
  1. 10 4
      Olivier/Makefile
  2. 1 1
      Olivier/instance.cpp
  3. 1 1
      Olivier/instance.h
  4. 22 6
      Olivier/main.cpp

+ 10 - 4
Olivier/Makefile

@@ -1,5 +1,5 @@
 GUROBI_DIR=/opt/gurobi650/linux64
-CPP=g++ -D_GLIBCXX_USE_CXX11_ABI=0 -m64 -g
+CPP=g++ -O2 -D_GLIBCXX_USE_CXX11_ABI=0 -m64 -g
 INC=-I$(GUROBI_DIR)/include
 LIBS=-L $(GUROBI_DIR)/lib -lgurobi_c++ -lgurobi65 -lpthread -lm
 SOURCES=instance.cpp main.cpp
@@ -8,13 +8,19 @@ SOURCES_GUROBI=gurobi.cpp
 all: source.zip bd.out moaw.out red.out
 
 bd.out: main
-	./main < ../busy_day.in > bd.out
+	./main < ../busy_day.in > /tmp/hashcode
+	wc -l /tmp/hashcode | cut -d' ' -f1 > bd.out
+	cat /tmp/hashcode >> bd.out
 
 moaw.out: main
-	./main < ../mother_of_all_warehouses.in > moaw.out
+	./main < ../mother_of_all_warehouses.in > /tmp/hashcode
+	wc -l /tmp/hashcode | cut -d' ' -f1 > moaw.out
+	cat /tmp/hashcode >> moaw.out
 
 red.out: main
-	./main < ../redundancy.in > red.out
+	./main < ../redundancy.in > /tmp/hashcode
+	wc -l /tmp/hashcode | cut -d' ' -f1 > red.out
+	cat /tmp/hashcode >> red.out
 
 source.zip: $(SOURCES)
 	zip source.zip $(wildcard *.cpp)  $(wildcard *.h)

+ 1 - 1
Olivier/instance.cpp

@@ -48,7 +48,7 @@ instance::instance() {
   }
 }
 
-int instance::find(pos p, int id) { // cherche une warehouse proche de x/y
+int instance::find(pos p, int id, int quantity) { // cherche une warehouse proche de x/y
   int best = -1;
   int d = 1000000000.;
   for(int i = 0; i < W; i++) {

+ 1 - 1
Olivier/instance.h

@@ -28,7 +28,7 @@ class order {
 class instance {
   public:
     instance(); // read from stdin
-    int find(pos p, int id); // cherche une warehouse proche de x/y
+    int find(pos p, int id, int quantity); // cherche une warehouse proche de x/y
     int row, col, drones, max_load;
     int T; // deadline
     int P; // # products

+ 22 - 6
Olivier/main.cpp

@@ -3,7 +3,7 @@
 using namespace std;
 
 int next(instance &ins) {
-  int best;
+  int best = -1;
   for(int i = 0; i < ins.orders.size(); i++) {
     if(!ins.orders[i].ord.empty()) {
       best = i;
@@ -14,16 +14,21 @@ int next(instance &ins) {
 }
 
 void glouton(instance &ins) {
-  int tour = 1000;
-  cout << 2*tour << endl;
-  for(int i = 0; i < tour; i++) {
+  vector<int> drone_temps(ins.drones);
+  vector<pos> drone_pos;
+  int score = 0;
+  for(int i = 0; i < ins.drones; i++)
+    drone_pos.push_back(ins.wh[0].p);
+  while(true) {
     int next_i = next(ins);
+    if(next_i < 0)
+      break;
     int drone = rand()%ins.drones;
     order &ord = ins.orders[next_i];
     assert(!ord.ord.empty());
     pair<const int, int> &type = *ord.ord.begin();
-    int wa = ins.find(pos(0, 0), type.first);
     int quantity = min(type.second, ins.max_load/ins.weights[type.first]);
+    int wa = ins.find(drone_pos[drone], type.first, quantity);
     quantity = min(quantity, ins.wh[wa].disp[type.first]);
     ins.wh[wa].disp[type.first] -= quantity;
     // decrease order / stock
@@ -31,14 +36,25 @@ void glouton(instance &ins) {
     if(!type.second)
       ord.ord.erase(type.first);
 
+    // augment drone_temps
+    drone_temps[drone] += 1+ceil(sqrt(drone_pos[drone].dist2(ins.wh[wa].p)));
+    drone_temps[drone] += 1+ceil(sqrt(ins.wh[wa].p.dist2(ord.p)));
+    drone_pos[drone] = ord.p;
+    if(drone_temps[drone] > ins.T)
+      break;
+
     // pass order
     cout << drone << " L " << wa << " " << type.first << " " << quantity << endl;
     cout << drone << " D " << next_i << " " << type.first << " " << quantity << endl;
+    score += ceil(100.*(ins.T-drone_temps[drone])/ins.T);
   }
+  cerr << "Score : " << score << endl;
 }
 
 int main() {
-  srand(time(NULL));
+  int seed = time(NULL);
+  srand(seed);
+  cerr << "seed : " << seed << endl;
   instance ins;
   glouton(ins);
   return 0;