main.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "instance.h"
  2. using namespace std;
  3. int next(instance &ins) {
  4. int best;
  5. for(int i = 0; i < ins.orders.size(); i++) {
  6. if(!ins.orders[i].ord.empty()) {
  7. best = i;
  8. break;
  9. }
  10. }
  11. return best;
  12. }
  13. void glouton(instance &ins) {
  14. int tour = 1000;
  15. cout << 2*tour << endl;
  16. for(int i = 0; i < tour; i++) {
  17. int next_i = next(ins);
  18. int drone = rand()%ins.drones;
  19. order &ord = ins.orders[next_i];
  20. assert(!ord.ord.empty());
  21. pair<const int, int> &type = *ord.ord.begin();
  22. int wa = ins.find(pos(0, 0), type.first);
  23. int quantity = min(type.second, ins.max_load/ins.weights[type.first]);
  24. quantity = min(quantity, ins.wh[wa].disp[type.first]);
  25. ins.wh[wa].disp[type.first] -= quantity;
  26. // decrease order / stock
  27. type.second -= quantity;
  28. if(!type.second)
  29. ord.ord.erase(type.first);
  30. // pass order
  31. cout << drone << " L " << wa << " " << type.first << " " << quantity << endl;
  32. cout << drone << " D " << next_i << " " << type.first << " " << quantity << endl;
  33. }
  34. }
  35. int main() {
  36. srand(time(NULL));
  37. instance ins;
  38. glouton(ins);
  39. return 0;
  40. }