|
14 | 14 | #include "ortools/flatzinc/checker.h" |
15 | 15 |
|
16 | 16 | #include <algorithm> |
| 17 | +#include <compare> |
17 | 18 | #include <cstdint> |
18 | 19 | #include <cstdlib> |
19 | 20 | #include <functional> |
@@ -1404,6 +1405,32 @@ bool CheckSetNe( |
1404 | 1405 | return values_x != values_y; |
1405 | 1406 | } |
1406 | 1407 |
|
| 1408 | +bool CheckSetLe( |
| 1409 | + const Constraint& ct, const std::function<int64_t(Variable*)>& evaluator, |
| 1410 | + const std::function<std::vector<int64_t>(Variable*)>& set_evaluator) { |
| 1411 | + const std::vector<int64_t> values_x = SetEval(ct.arguments[0], set_evaluator); |
| 1412 | + const std::vector<int64_t> values_y = SetEval(ct.arguments[1], set_evaluator); |
| 1413 | + const int min_size = std::min(values_x.size(), values_y.size()); |
| 1414 | + for (int i = 0; i < min_size; ++i) { |
| 1415 | + if (values_x[i] < values_y[i]) return true; |
| 1416 | + if (values_x[i] > values_y[i]) return false; |
| 1417 | + } |
| 1418 | + return values_y.size() >= values_x.size(); |
| 1419 | +} |
| 1420 | + |
| 1421 | +bool CheckSetLt( |
| 1422 | + const Constraint& ct, const std::function<int64_t(Variable*)>& evaluator, |
| 1423 | + const std::function<std::vector<int64_t>(Variable*)>& set_evaluator) { |
| 1424 | + const std::vector<int64_t> values_x = SetEval(ct.arguments[0], set_evaluator); |
| 1425 | + const std::vector<int64_t> values_y = SetEval(ct.arguments[1], set_evaluator); |
| 1426 | + const int min_size = std::min(values_x.size(), values_y.size()); |
| 1427 | + for (int i = 0; i < min_size; ++i) { |
| 1428 | + if (values_x[i] < values_y[i]) return true; |
| 1429 | + if (values_x[i] > values_y[i]) return false; |
| 1430 | + } |
| 1431 | + return values_y.size() > values_x.size(); |
| 1432 | +} |
| 1433 | + |
1407 | 1434 | bool CheckSetNeReif( |
1408 | 1435 | const Constraint& ct, const std::function<int64_t(Variable*)>& evaluator, |
1409 | 1436 | const std::function<std::vector<int64_t>(Variable*)>& set_evaluator) { |
@@ -1668,6 +1695,8 @@ CallMap CreateCallMap() { |
1668 | 1695 | m["set_in_reif"] = CheckSetInReif; |
1669 | 1696 | m["set_in"] = CheckSetIn; |
1670 | 1697 | m["set_intersect"] = CheckSetIntersect; |
| 1698 | + m["set_le"] = CheckSetLe; |
| 1699 | + m["set_lt"] = CheckSetLt; |
1671 | 1700 | m["set_ne_reif"] = CheckSetNeReif; |
1672 | 1701 | m["set_ne"] = CheckSetNe; |
1673 | 1702 | m["set_not_in"] = CheckSetNotIn; |
|
0 commit comments