instance.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "instance.h"
  2. using namespace std;
  3. pos::pos(int x, int y) : x(x), y(y) {
  4. }
  5. pos::pos() : x(0), y(0) {}
  6. int pos::dist2(const pos &b) const {
  7. return x*b.x + y*b.y;
  8. }
  9. warehouse::warehouse(pos p, vector<int> disp) : p(p), disp(disp) {
  10. }
  11. order::order(int id, pos p, map<int, int> ord) : id(id), p(p), ord(ord) {
  12. }
  13. instance::instance() {
  14. int tmp;
  15. cin >> row >> col >> drones >> T >> max_load >> P;
  16. for(int i = 0; i < P; i++) {
  17. cin >> tmp;
  18. weights.push_back(tmp);
  19. }
  20. cin >> W;
  21. for(int i = 0; i < W; i++) {
  22. int x, y;
  23. vector<int> disp;
  24. cin >> y >> x;
  25. for(int j = 0; j < P; j++) {
  26. cin >> tmp;
  27. disp.push_back(tmp);
  28. }
  29. wh.push_back(warehouse(pos(x, y), disp));
  30. }
  31. cin >> C;
  32. for(int i = 0; i < C; i++) {
  33. int x, y, L;
  34. map<int, int> ord;
  35. cin >> y >> x >> L;
  36. for(int j = 0; j < L; j++) {
  37. cin >> tmp;
  38. ord[tmp]++;
  39. }
  40. orders.push_back(order(i, pos(x, y), ord));
  41. }
  42. }
  43. int instance::find(pos p, int id, int quantity) { // cherche une warehouse proche de x/y
  44. int best = -1, best_quantity = -1;
  45. int d = 1000000000.;
  46. for(int i = 0; i < W; i++) {
  47. if(wh[i].disp[id] >= best_quantity) {
  48. int d2 = p.dist2(wh[i].p);
  49. if(best_quantity == quantity) {
  50. if(d2 < d) {
  51. d = d2;
  52. best = i;
  53. }
  54. }
  55. else if(wh[i].disp[id] > best_quantity) {
  56. d = d2;
  57. best = i;
  58. }
  59. else if(wh[i].disp[id] == best_quantity && d2 < d) {
  60. d = d2;
  61. best = i;
  62. }
  63. best_quantity = min(quantity, wh[i].disp[id]);
  64. }
  65. }
  66. if(best < 0) {
  67. cerr << "error in find\n";
  68. exit(1);
  69. }
  70. return best;
  71. }