instance.cpp 1.2 KB

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