12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "instance.h"
- using namespace std;
- pos::pos(int x, int y) : x(x), y(y) {
- }
- int pos::dist2(pos &b) {
- return x*b.x + y*b.y;
- }
- warehouse::warehouse(pos p, vector<int> disp) : p(p), disp(disp) {
- }
- order::order(pos p, map<int, int> ord) : p(p), ord(ord) {
- }
- instance::instance() {
- int tmp;
- cin >> row >> col >> drones >> T >> max_load >> P;
- for(int i = 0; i < P; i++) {
- cin >> tmp;
- weights.push_back(tmp);
- }
- cin >> W;
- for(int i = 0; i < W; i++) {
- int x, y;
- vector<int> disp;
- cin >> y >> x;
- for(int j = 0; j < P; j++) {
- cin >> tmp;
- disp.push_back(tmp);
- }
- wh.push_back(warehouse(pos(x, y), disp));
- }
- cin >> C;
- for(int i = 0; i < C; i++) {
- int x, y, L;
- map<int, int> ord;
- cin >> y >> x >> L;
- for(int j = 0; j < L; j++) {
- cin >> tmp;
- ord[tmp]++;
- }
- orders.push_back(order(pos(x, y), ord));
- }
- }
- int instance::find(pos p, int id, int quantity) { // cherche une warehouse proche de x/y
- int best = -1, best_quantity = -1;
- int d = 1000000000.;
- for(int i = 0; i < W; i++) {
- if(wh[i].disp[id] >= best_quantity) {
- int d2 = p.dist2(wh[i].p);
- if(best_quantity == quantity) {
- if(d2 < d) {
- d = d2;
- best = i;
- }
- }
- else if(wh[i].disp[id] > best_quantity) {
- d = d2;
- best = i;
- }
- else if(wh[i].disp[id] == best_quantity && d2 < d) {
- d = d2;
- best = i;
- }
- best_quantity = min(quantity, wh[i].disp[id]);
- }
- }
- if(best < 0) {
- cerr << "error in find\n";
- exit(1);
- }
- return best;
- }
|