| 567 | size_t ProblemData::numLoadDimensions() const { return numLoadDimensions_; } |
| 568 | |
| 569 | void ProblemData::validate() const |
| 570 | { |
| 571 | // Client checks. |
| 572 | for (size_t idx = numDepots(); idx != numLocations(); ++idx) |
| 573 | { |
| 574 | ProblemData::Client const &client = location(idx); |
| 575 | |
| 576 | if (client.delivery.size() != numLoadDimensions_) |
| 577 | { |
| 578 | auto const *msg = "Client has inconsistent delivery size."; |
| 579 | throw std::invalid_argument(msg); |
| 580 | } |
| 581 | |
| 582 | if (client.pickup.size() != numLoadDimensions_) |
| 583 | { |
| 584 | auto const *msg = "Client has inconsistent pickup size."; |
| 585 | throw std::invalid_argument(msg); |
| 586 | } |
| 587 | |
| 588 | if (!client.group) |
| 589 | continue; |
| 590 | |
| 591 | if (*client.group >= numGroups()) |
| 592 | throw std::out_of_range("Client references invalid group."); |
| 593 | |
| 594 | auto const &group = groups_[*client.group]; |
| 595 | if (std::find(group.begin(), group.end(), idx) == group.end()) |
| 596 | { |
| 597 | auto const *msg = "Client not in the group it references."; |
| 598 | throw std::invalid_argument(msg); |
| 599 | } |
| 600 | |
| 601 | if (client.required && group.mutuallyExclusive) |
| 602 | { |
| 603 | auto const *msg = "Required client in mutually exclusive group."; |
| 604 | throw std::invalid_argument(msg); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // Depot checks. |
| 609 | if (depots_.empty()) |
| 610 | throw std::invalid_argument("Expected at least one depot."); |
| 611 | |
| 612 | // Group checks. |
| 613 | for (size_t idx = 0; idx != numGroups(); ++idx) |
| 614 | { |
| 615 | auto const &group = groups_[idx]; |
| 616 | |
| 617 | if (group.empty()) |
| 618 | throw std::invalid_argument("Empty client group not understood."); |
| 619 | |
| 620 | for (auto const client : group) |
| 621 | { |
| 622 | if (client < numDepots() || client >= numLocations()) |
| 623 | throw std::out_of_range("Group references invalid client."); |
| 624 | |
| 625 | ProblemData::Client const &clientData = location(client); |
| 626 | if (!clientData.group || *clientData.group != idx) |