25#include "absl/container/btree_map.h"
26#include "absl/container/flat_hash_map.h"
27#include "absl/container/flat_hash_set.h"
28#include "absl/meta/type_traits.h"
29#include "absl/strings/str_cat.h"
32#include "ortools/sat/cp_model.pb.h"
34#include "ortools/sat/sat_parameters.pb.h"
47#define RETURN_IF_NOT_EMPTY(statement) \
49 const std::string error_message = statement; \
50 if (!error_message.empty()) return error_message; \
53template <
typename ProtoWithDomain>
54bool DomainInProtoIsValid(
const ProtoWithDomain&
proto) {
55 if (
proto.domain().size() % 2)
return false;
56 std::vector<ClosedInterval> domain;
57 for (
int i = 0; i <
proto.domain_size(); i += 2) {
58 if (
proto.domain(i) >
proto.domain(i + 1))
return false;
59 domain.push_back({
proto.domain(i),
proto.domain(i + 1)});
64bool VariableReferenceIsValid(
const CpModelProto&
model,
int reference) {
66 if (reference >=
model.variables_size())
return false;
67 return reference >= -
static_cast<int>(
model.variables_size());
74bool VariableIndexIsValid(
const CpModelProto&
model,
int var) {
78bool LiteralReferenceIsValid(
const CpModelProto&
model,
int reference) {
79 if (!VariableReferenceIsValid(
model, reference))
return false;
81 const int64_t min_domain = var_proto.domain(0);
82 const int64_t max_domain = var_proto.domain(var_proto.domain_size() - 1);
83 return min_domain >= 0 && max_domain <= 1;
86std::string ValidateIntegerVariable(
const CpModelProto&
model,
int v) {
87 const IntegerVariableProto&
proto =
model.variables(v);
88 if (
proto.domain_size() == 0) {
89 return absl::StrCat(
"var #", v,
92 if (
proto.domain_size() % 2 != 0) {
93 return absl::StrCat(
"var #", v,
" has an odd domain() size: ",
96 if (!DomainInProtoIsValid(
proto)) {
97 return absl::StrCat(
"var #", v,
" has and invalid domain() format: ",
104 const int64_t lb =
proto.domain(0);
105 const int64_t ub =
proto.domain(
proto.domain_size() - 1);
109 "var #", v,
" domain do not fall in [kint64min + 2, kint64max - 1]. ",
118 " has a domain that is too large, i.e. |UB - LB| overflow an int64_t: ",
125std::string ValidateVariablesUsedInConstraint(
const CpModelProto&
model,
127 const ConstraintProto&
ct =
model.constraints(c);
129 for (
const int v : references.variables) {
130 if (!VariableReferenceIsValid(
model, v)) {
131 return absl::StrCat(
"Out of bound integer variable ", v,
132 " in constraint #", c,
" : ",
136 for (
const int lit :
ct.enforcement_literal()) {
137 if (!LiteralReferenceIsValid(
model, lit)) {
138 return absl::StrCat(
"Invalid enforcement literal ", lit,
139 " in constraint #", c,
" : ",
143 for (
const int lit : references.literals) {
144 if (!LiteralReferenceIsValid(
model, lit)) {
145 return absl::StrCat(
"Invalid literal ", lit,
" in constraint #", c,
" : ",
152std::string ValidateIntervalsUsedInConstraint(
bool after_presolve,
153 const CpModelProto&
model,
155 const ConstraintProto&
ct =
model.constraints(c);
157 if (i < 0 || i >=
model.constraints_size()) {
158 return absl::StrCat(
"Out of bound interval ", i,
" in constraint #", c,
161 if (after_presolve && i >= c) {
162 return absl::StrCat(
"Interval ", i,
" in constraint #", c,
163 " must appear before in the list of constraints :",
166 if (
model.constraints(i).constraint_case() !=
167 ConstraintProto::ConstraintCase::kInterval) {
170 " does not refer to an interval constraint. Problematic constraint #",
177template <
class LinearExpressionProto>
178bool PossibleIntegerOverflow(
const CpModelProto&
model,
179 const LinearExpressionProto&
proto,
180 int64_t offset = 0) {
182 int64_t sum_min = -std::abs(offset);
183 int64_t sum_max = +std::abs(offset);
184 for (
int i = 0; i <
proto.vars_size(); ++i) {
185 const int ref =
proto.vars(i);
187 const int64_t min_domain = var_proto.domain(0);
188 const int64_t max_domain = var_proto.domain(var_proto.domain_size() - 1);
190 const int64_t
coeff =
200 for (
const int64_t v : {prod1, prod2, sum_min, sum_max}) {
215int64_t MinOfRef(
const CpModelProto&
model,
int ref) {
218 return var_proto.domain(0);
220 return -var_proto.domain(var_proto.domain_size() - 1);
224int64_t MaxOfRef(
const CpModelProto&
model,
int ref) {
227 return var_proto.domain(var_proto.domain_size() - 1);
229 return -var_proto.domain(0);
233template <
class LinearExpressionProto>
234int64_t MinOfExpression(
const CpModelProto&
model,
235 const LinearExpressionProto&
proto) {
236 int64_t sum_min =
proto.offset();
237 for (
int i = 0; i <
proto.vars_size(); ++i) {
238 const int ref =
proto.vars(i);
248template <
class LinearExpressionProto>
249int64_t MaxOfExpression(
const CpModelProto&
model,
250 const LinearExpressionProto&
proto) {
251 int64_t sum_max =
proto.offset();
252 for (
int i = 0; i <
proto.vars_size(); ++i) {
253 const int ref =
proto.vars(i);
263int64_t IntervalSizeMin(
const CpModelProto&
model,
int interval_index) {
264 DCHECK_EQ(ConstraintProto::ConstraintCase::kInterval,
265 model.constraints(interval_index).constraint_case());
266 const IntervalConstraintProto&
proto =
267 model.constraints(interval_index).interval();
271int64_t IntervalSizeMax(
const CpModelProto&
model,
int interval_index) {
272 DCHECK_EQ(ConstraintProto::ConstraintCase::kInterval,
273 model.constraints(interval_index).constraint_case());
274 const IntervalConstraintProto&
proto =
275 model.constraints(interval_index).interval();
279Domain DomainOfRef(
const CpModelProto&
model,
int ref) {
284std::string ValidateLinearExpression(
const CpModelProto&
model,
285 const LinearExpressionProto& expr) {
286 if (expr.coeffs_size() != expr.vars_size()) {
287 return absl::StrCat(
"coeffs_size() != vars_size() in linear expression: ",
290 if (PossibleIntegerOverflow(
model, expr, expr.offset())) {
291 return absl::StrCat(
"Possible overflow in linear expression: ",
297std::string ValidateAffineExpression(
const CpModelProto&
model,
298 const LinearExpressionProto& expr) {
299 if (expr.vars_size() > 1) {
300 return absl::StrCat(
"expression must be affine: ",
303 return ValidateLinearExpression(
model, expr);
306std::string ValidateLinearConstraint(
const CpModelProto&
model,
307 const ConstraintProto&
ct) {
308 if (!DomainInProtoIsValid(
ct.linear())) {
309 return absl::StrCat(
"Invalid domain in constraint : ",
312 if (
ct.linear().coeffs_size() !=
ct.linear().vars_size()) {
313 return absl::StrCat(
"coeffs_size() != vars_size() in constraint: ",
316 const LinearConstraintProto& arg =
ct.linear();
317 if (PossibleIntegerOverflow(
model, arg)) {
318 return "Possible integer overflow in constraint: " +
324std::string ValidateIntModConstraint(
const CpModelProto&
model,
325 const ConstraintProto&
ct) {
326 if (
ct.int_mod().exprs().size() != 2) {
327 return absl::StrCat(
"An int_mod constraint should have exactly 2 terms: ",
330 if (!
ct.int_mod().has_target()) {
331 return absl::StrCat(
"An int_mod constraint should have a target: ",
339 const LinearExpressionProto mod_expr =
ct.int_mod().exprs(1);
340 if (MinOfExpression(
model, mod_expr) <= 0) {
342 "An int_mod must have a strictly positive modulo argument: ",
349std::string ValidateIntProdConstraint(
const CpModelProto&
model,
350 const ConstraintProto&
ct) {
351 if (
ct.int_prod().exprs().size() != 2) {
352 return absl::StrCat(
"An int_prod constraint should have exactly 2 terms: ",
355 if (!
ct.int_prod().has_target()) {
356 return absl::StrCat(
"An int_prod constraint should have a target: ",
365 const LinearExpressionProto& expr0 =
ct.int_prod().exprs(0);
366 const LinearExpressionProto& expr1 =
ct.int_prod().exprs(1);
367 const Domain product_domain =
368 Domain({MinOfExpression(
model, expr0), MaxOfExpression(
model, expr0)})
369 .ContinuousMultiplicationBy(Domain(
370 {MinOfExpression(
model, expr1), MaxOfExpression(
model, expr1)}));
372 product_domain.Min() < 0) ||
374 product_domain.Max() > 0)) {
375 return absl::StrCat(
"Potential integer overflow in constraint: ",
381std::string ValidateIntDivConstraint(
const CpModelProto&
model,
382 const ConstraintProto&
ct) {
383 if (
ct.int_div().exprs().size() != 2) {
384 return absl::StrCat(
"An int_div constraint should have exactly 2 terms: ",
387 if (!
ct.int_div().has_target()) {
388 return absl::StrCat(
"An int_div constraint should have a target: ",
396 const LinearExpressionProto& divisor_proto =
ct.int_div().exprs(1);
397 if (MinOfExpression(
model, divisor_proto) <= 0 &&
398 MaxOfExpression(
model, divisor_proto) >= 0) {
399 return absl::StrCat(
"The divisor cannot span across zero in constraint: ",
406std::string ValidateTableConstraint(
const CpModelProto&
model,
407 const ConstraintProto&
ct) {
408 const TableConstraintProto& arg =
ct.table();
409 if (arg.vars().empty())
return "";
410 if (arg.values().size() % arg.vars().size() != 0) {
412 "The flat encoding of a table constraint must be a multiple of the "
413 "number of variable: ",
419std::string ValidateAutomatonConstraint(
const CpModelProto&
model,
420 const ConstraintProto&
ct) {
421 const int num_transistions =
ct.automaton().transition_tail().size();
422 if (num_transistions !=
ct.automaton().transition_head().size() ||
423 num_transistions !=
ct.automaton().transition_label().size()) {
425 "The transitions repeated fields must have the same size: ",
428 absl::flat_hash_map<std::pair<int64_t, int64_t>, int64_t> tail_label_to_head;
429 for (
int i = 0; i < num_transistions; ++i) {
430 const int64_t
tail =
ct.automaton().transition_tail(i);
431 const int64_t
head =
ct.automaton().transition_head(i);
432 const int64_t label =
ct.automaton().transition_label(i);
435 return absl::StrCat(
"labels in the automaton constraint are too big: ",
438 const auto [it, inserted] =
439 tail_label_to_head.insert({{
tail, label},
head});
441 if (it->second ==
head) {
442 return absl::StrCat(
"automaton: duplicate transition ",
tail,
" --(",
443 label,
")--> ",
head);
445 return absl::StrCat(
"automaton: incompatible transitions ",
tail,
446 " --(", label,
")--> ",
head,
" and ",
tail,
" --(",
447 label,
")--> ", it->second);
454template <
typename GraphProto>
455std::string ValidateGraphInput(
bool is_route,
const CpModelProto&
model,
456 const GraphProto& graph) {
457 const int size = graph.tails().size();
458 if (graph.heads().size() != size || graph.literals().size() != size) {
459 return absl::StrCat(
"Wrong field sizes in graph: ",
464 absl::flat_hash_set<int> self_loops;
465 for (
int i = 0; i < size; ++i) {
466 if (graph.heads(i) != graph.tails(i))
continue;
467 if (!self_loops.insert(graph.heads(i)).second) {
469 "Circuit/Route constraint contains multiple self-loop involving "
473 if (is_route && graph.tails(i) == 0) {
475 "A route constraint cannot have a self-loop on the depot (node 0)");
482std::string ValidateRoutesConstraint(
const CpModelProto&
model,
483 const ConstraintProto&
ct) {
485 absl::flat_hash_set<int>
nodes;
486 for (
const int node :
ct.routes().tails()) {
488 return "All node in a route constraint must be in [0, num_nodes)";
491 max_node =
std::max(max_node, node);
493 for (
const int node :
ct.routes().heads()) {
495 return "All node in a route constraint must be in [0, num_nodes)";
498 max_node =
std::max(max_node, node);
500 if (!
nodes.empty() && max_node !=
nodes.size() - 1) {
502 "All nodes in a route constraint must have incident arcs");
505 return ValidateGraphInput(
true,
model,
ct.routes());
508std::string ValidateDomainIsPositive(
const CpModelProto&
model,
int ref,
509 const std::string& ref_name) {
511 const IntegerVariableProto& var_proto =
model.variables(
NegatedRef(ref));
512 if (var_proto.domain(var_proto.domain_size() - 1) > 0) {
513 return absl::StrCat(
"Negative value in ", ref_name,
514 " domain: negation of ",
518 const IntegerVariableProto& var_proto =
model.variables(ref);
519 if (var_proto.domain(0) < 0) {
520 return absl::StrCat(
"Negative value in ", ref_name,
527void AppendToOverflowValidator(
const LinearExpressionProto&
input,
528 LinearExpressionProto* output) {
529 output->mutable_vars()->Add(
input.vars().begin(),
input.vars().end());
530 output->mutable_coeffs()->Add(
input.coeffs().begin(),
input.coeffs().end());
535 CapAdd(std::abs(output->offset()), std::abs(
input.offset())));
538std::string ValidateIntervalConstraint(
const CpModelProto&
model,
539 const ConstraintProto&
ct) {
540 if (
ct.enforcement_literal().size() > 1) {
542 "Interval with more than one enforcement literals are currently not "
546 const IntervalConstraintProto& arg =
ct.interval();
548 if (!arg.has_start()) {
549 return absl::StrCat(
"Interval must have a start expression: ",
552 if (!arg.has_size()) {
553 return absl::StrCat(
"Interval must have a size expression: ",
556 if (!arg.has_end()) {
557 return absl::StrCat(
"Interval must have a end expression: ",
561 LinearExpressionProto for_overflow_validation;
562 if (arg.start().vars_size() > 1) {
563 return "Interval with a start expression containing more than one "
564 "variable are currently not supported.";
567 AppendToOverflowValidator(arg.start(), &for_overflow_validation);
568 if (arg.size().vars_size() > 1) {
569 return "Interval with a size expression containing more than one "
570 "variable are currently not supported.";
573 if (
ct.enforcement_literal().empty() &&
574 MinOfExpression(
model, arg.size()) < 0) {
576 "The size of an performed interval must be >= 0 in constraint: ",
579 AppendToOverflowValidator(arg.size(), &for_overflow_validation);
580 if (arg.end().vars_size() > 1) {
581 return "Interval with a end expression containing more than one "
582 "variable are currently not supported.";
585 AppendToOverflowValidator(arg.end(), &for_overflow_validation);
587 if (PossibleIntegerOverflow(
model, for_overflow_validation,
588 for_overflow_validation.offset())) {
589 return absl::StrCat(
"Possible overflow in interval: ",
596std::string ValidateCumulativeConstraint(
const CpModelProto&
model,
597 const ConstraintProto&
ct) {
598 if (
ct.cumulative().intervals_size() !=
ct.cumulative().demands_size()) {
599 return absl::StrCat(
"intervals_size() != demands_size() in constraint: ",
604 ValidateLinearExpression(
model,
ct.cumulative().capacity()));
605 for (
const LinearExpressionProto&
demand :
ct.cumulative().demands()) {
609 for (
const LinearExpressionProto& demand_expr :
ct.cumulative().demands()) {
610 if (MinOfExpression(
model, demand_expr) < 0) {
612 "Demand ", demand_expr.DebugString(),
615 if (demand_expr.vars_size() > 1) {
616 return absl::StrCat(
"Demand ", demand_expr.DebugString(),
617 " must be affine or constant in constraint: ",
621 if (
ct.cumulative().capacity().vars_size() > 1) {
623 "capacity ",
ct.cumulative().capacity().DebugString(),
627 int64_t sum_max_demands = 0;
628 for (
const LinearExpressionProto& demand_expr :
ct.cumulative().demands()) {
629 const int64_t demand_max = MaxOfExpression(
model, demand_expr);
631 sum_max_demands =
CapAdd(sum_max_demands, demand_max);
633 return "The sum of max demands do not fit on an int64_t in constraint: " +
641std::string ValidateNoOverlap2DConstraint(
const CpModelProto&
model,
642 const ConstraintProto&
ct) {
643 const int size_x =
ct.no_overlap_2d().x_intervals().size();
644 const int size_y =
ct.no_overlap_2d().y_intervals().size();
645 if (size_x != size_y) {
646 return absl::StrCat(
"The two lists of intervals must have the same size: ",
651 int64_t sum_max_areas = 0;
652 for (
int i = 0; i <
ct.no_overlap_2d().x_intervals().size(); ++i) {
653 const int64_t max_size_x =
654 IntervalSizeMax(
model,
ct.no_overlap_2d().x_intervals(i));
655 const int64_t max_size_y =
656 IntervalSizeMax(
model,
ct.no_overlap_2d().y_intervals(i));
657 sum_max_areas =
CapAdd(sum_max_areas,
CapProd(max_size_x, max_size_y));
659 return "Integer overflow when summing all areas in "
667std::string ValidateReservoirConstraint(
const CpModelProto&
model,
668 const ConstraintProto&
ct) {
669 if (
ct.enforcement_literal_size() > 0) {
670 return "Reservoir does not support enforcement literals.";
672 if (
ct.reservoir().time_exprs().size() !=
673 ct.reservoir().level_changes().size()) {
675 "time_exprs and level_changes fields must be of the same size: ",
678 for (
const LinearExpressionProto& expr :
ct.reservoir().time_exprs()) {
681 if (
ct.reservoir().min_level() > 0) {
683 "The min level of a reservoir must be <= 0. Please use fixed events to "
684 "setup initial state: ",
687 if (
ct.reservoir().max_level() < 0) {
689 "The max level of a reservoir must be >= 0. Please use fixed events to "
690 "setup initial state: ",
695 for (
const int64_t
demand :
ct.reservoir().level_changes()) {
698 return "Possible integer overflow in constraint: " +
703 return "Possible integer overflow in constraint: " +
707 if (
ct.reservoir().active_literals_size() > 0 &&
708 ct.reservoir().active_literals_size() !=
709 ct.reservoir().time_exprs_size()) {
710 return "Wrong array length of active_literals variables";
712 if (
ct.reservoir().level_changes_size() > 0 &&
713 ct.reservoir().level_changes_size() !=
ct.reservoir().time_exprs_size()) {
714 return "Wrong array length of level_changes variables";
719std::string ValidateObjective(
const CpModelProto&
model,
720 const CpObjectiveProto& obj) {
721 if (!DomainInProtoIsValid(obj)) {
722 return absl::StrCat(
"The objective has and invalid domain() format: ",
725 if (obj.vars().size() != obj.coeffs().size()) {
726 return absl::StrCat(
"vars and coeffs size do not match in objective: ",
729 for (
const int v : obj.vars()) {
730 if (!VariableReferenceIsValid(
model, v)) {
731 return absl::StrCat(
"Out of bound integer variable ", v,
735 if (PossibleIntegerOverflow(
model, obj)) {
736 return "Possible integer overflow in objective: " +
742std::string ValidateFloatingPointObjective(
double max_valid_magnitude,
743 const CpModelProto&
model,
744 const FloatObjectiveProto& obj) {
745 if (obj.vars().size() != obj.coeffs().size()) {
746 return absl::StrCat(
"vars and coeffs size do not match in objective: ",
749 for (
const int v : obj.vars()) {
750 if (!VariableIndexIsValid(
model, v)) {
751 return absl::StrCat(
"Out of bound integer variable ", v,
755 for (
const double coeff : obj.coeffs()) {
756 if (!std::isfinite(
coeff)) {
757 return absl::StrCat(
"Coefficients must be finite in objective: ",
760 if (std::abs(
coeff) > max_valid_magnitude) {
762 "Coefficients larger than params.mip_max_valid_magnitude() [value = ",
767 if (!std::isfinite(obj.offset())) {
768 return absl::StrCat(
"Offset must be finite in objective: ",
774std::string ValidateSearchStrategies(
const CpModelProto&
model) {
775 for (
const DecisionStrategyProto& strategy :
model.search_strategy()) {
776 const int vss = strategy.variable_selection_strategy();
777 if (vss != DecisionStrategyProto::CHOOSE_FIRST &&
778 vss != DecisionStrategyProto::CHOOSE_LOWEST_MIN &&
779 vss != DecisionStrategyProto::CHOOSE_HIGHEST_MAX &&
780 vss != DecisionStrategyProto::CHOOSE_MIN_DOMAIN_SIZE &&
781 vss != DecisionStrategyProto::CHOOSE_MAX_DOMAIN_SIZE) {
783 "Unknown or unsupported variable_selection_strategy: ", vss);
785 const int drs = strategy.domain_reduction_strategy();
786 if (drs != DecisionStrategyProto::SELECT_MIN_VALUE &&
787 drs != DecisionStrategyProto::SELECT_MAX_VALUE &&
788 drs != DecisionStrategyProto::SELECT_LOWER_HALF &&
789 drs != DecisionStrategyProto::SELECT_UPPER_HALF &&
790 drs != DecisionStrategyProto::SELECT_MEDIAN_VALUE) {
791 return absl::StrCat(
"Unknown or unsupported domain_reduction_strategy: ",
794 for (
const int ref : strategy.variables()) {
795 if (!VariableReferenceIsValid(
model, ref)) {
796 return absl::StrCat(
"Invalid variable reference in strategy: ",
799 if (drs == DecisionStrategyProto::SELECT_MEDIAN_VALUE &&
802 return absl::StrCat(
"Variable #",
PositiveRef(ref),
803 " has a domain too large to be used in a"
804 " SELECT_MEDIAN_VALUE value selection strategy");
807 int previous_index = -1;
808 for (
const auto& transformation : strategy.transformations()) {
809 if (transformation.positive_coeff() <= 0) {
810 return absl::StrCat(
"Affine transformation coeff should be positive: ",
813 if (transformation.index() <= previous_index ||
814 transformation.index() >= strategy.variables_size()) {
816 "Invalid indices (must be sorted and valid) in transformation: ",
819 previous_index = transformation.index();
825std::string ValidateSolutionHint(
const CpModelProto&
model) {
826 if (!
model.has_solution_hint())
return "";
827 const auto& hint =
model.solution_hint();
828 if (hint.vars().size() != hint.values().size()) {
829 return "Invalid solution hint: vars and values do not have the same size.";
831 for (
const int ref : hint.vars()) {
832 if (!VariableReferenceIsValid(
model, ref)) {
833 return absl::StrCat(
"Invalid variable reference in solution hint: ", ref);
838 absl::flat_hash_set<int> indices;
839 for (
const int var : hint.vars()) {
841 if (!insert.second) {
843 "The solution hint contains duplicate variables like the variable "
850 for (
const int64_t
value : hint.values()) {
853 return "The solution hint cannot contains the INT_MIN or INT_MAX values.";
863 for (
int v = 0; v <
model.variables_size(); ++v) {
869 std::vector<int> constraints_using_intervals;
871 for (
int c = 0; c <
model.constraints_size(); ++c) {
876 bool support_enforcement =
false;
879 const ConstraintProto&
ct =
model.constraints(c);
880 switch (
ct.constraint_case()) {
881 case ConstraintProto::ConstraintCase::kBoolOr:
882 support_enforcement =
true;
884 case ConstraintProto::ConstraintCase::kBoolAnd:
885 support_enforcement =
true;
887 case ConstraintProto::ConstraintCase::kLinear:
888 support_enforcement =
true;
891 case ConstraintProto::ConstraintCase::kLinMax: {
893 ValidateLinearExpression(
model,
ct.lin_max().target()));
894 for (
const LinearExpressionProto& expr :
ct.lin_max().exprs()) {
899 case ConstraintProto::ConstraintCase::kIntProd:
902 case ConstraintProto::ConstraintCase::kIntDiv:
905 case ConstraintProto::ConstraintCase::kIntMod:
908 case ConstraintProto::ConstraintCase::kInverse:
909 if (
ct.inverse().f_direct().size() !=
ct.inverse().f_inverse().size()) {
910 return absl::StrCat(
"Non-matching fields size in inverse: ",
914 case ConstraintProto::ConstraintCase::kAllDiff:
915 for (
const LinearExpressionProto& expr :
ct.all_diff().exprs()) {
919 case ConstraintProto::ConstraintCase::kTable:
922 case ConstraintProto::ConstraintCase::kAutomaton:
925 case ConstraintProto::ConstraintCase::kCircuit:
927 ValidateGraphInput(
false,
model,
ct.circuit()));
929 case ConstraintProto::ConstraintCase::kRoutes:
932 case ConstraintProto::ConstraintCase::kInterval:
934 support_enforcement =
true;
936 case ConstraintProto::ConstraintCase::kCumulative:
937 constraints_using_intervals.push_back(c);
939 case ConstraintProto::ConstraintCase::kNoOverlap:
940 constraints_using_intervals.push_back(c);
942 case ConstraintProto::ConstraintCase::kNoOverlap2D:
943 constraints_using_intervals.push_back(c);
945 case ConstraintProto::ConstraintCase::kReservoir:
948 case ConstraintProto::ConstraintCase::kDummyConstraint:
949 return "The dummy constraint should never appear in a model.";
957 if (!support_enforcement && !
ct.enforcement_literal().empty()) {
958 for (
const int ref :
ct.enforcement_literal()) {
961 if (domain.
Size() != 1) {
963 "Enforcement literal not supported in constraint: ",
971 for (
const int c : constraints_using_intervals) {
973 ValidateIntervalsUsedInConstraint(after_presolve,
model, c));
975 const ConstraintProto&
ct =
model.constraints(c);
976 switch (
ct.constraint_case()) {
977 case ConstraintProto::ConstraintCase::kCumulative:
980 case ConstraintProto::ConstraintCase::kNoOverlap:
982 case ConstraintProto::ConstraintCase::kNoOverlap2D:
986 LOG(DFATAL) <<
"Shouldn't be here";
990 if (
model.has_objective() &&
model.has_floating_point_objective()) {
991 return "A model cannot have both an objective and a floating point "
994 if (
model.has_objective()) {
999 for (
const int ref :
model.assumptions()) {
1000 if (!LiteralReferenceIsValid(
model, ref)) {
1001 return absl::StrCat(
"Invalid literal reference ", ref,
1002 " in the 'assumptions' field.");
1009 const CpModelProto&
model) {
1011 if (
model.has_floating_point_objective()) {
1013 ValidateFloatingPointObjective(params.mip_max_valid_magnitude(),
model,
1014 model.floating_point_objective()));
1019#undef RETURN_IF_NOT_EMPTY
1027class ConstraintChecker {
1029 explicit ConstraintChecker(
const std::vector<int64_t>& variable_values)
1030 : variable_values_(variable_values) {}
1032 bool LiteralIsTrue(
int l)
const {
1033 if (l >= 0)
return variable_values_[l] != 0;
1034 return variable_values_[-l - 1] == 0;
1037 bool LiteralIsFalse(
int l)
const {
return !LiteralIsTrue(l); }
1040 if (
var >= 0)
return variable_values_[
var];
1041 return -variable_values_[-
var - 1];
1044 bool ConstraintIsEnforced(
const ConstraintProto&
ct) {
1045 for (
const int lit :
ct.enforcement_literal()) {
1046 if (LiteralIsFalse(lit))
return false;
1051 bool BoolOrConstraintIsFeasible(
const ConstraintProto&
ct) {
1052 for (
const int lit :
ct.bool_or().literals()) {
1053 if (LiteralIsTrue(lit))
return true;
1058 bool BoolAndConstraintIsFeasible(
const ConstraintProto&
ct) {
1059 for (
const int lit :
ct.bool_and().literals()) {
1060 if (LiteralIsFalse(lit))
return false;
1065 bool AtMostOneConstraintIsFeasible(
const ConstraintProto&
ct) {
1066 int num_true_literals = 0;
1067 for (
const int lit :
ct.at_most_one().literals()) {
1068 if (LiteralIsTrue(lit)) ++num_true_literals;
1070 return num_true_literals <= 1;
1073 bool ExactlyOneConstraintIsFeasible(
const ConstraintProto&
ct) {
1074 int num_true_literals = 0;
1075 for (
const int lit :
ct.exactly_one().literals()) {
1076 if (LiteralIsTrue(lit)) ++num_true_literals;
1078 return num_true_literals == 1;
1081 bool BoolXorConstraintIsFeasible(
const ConstraintProto&
ct) {
1083 for (
const int lit :
ct.bool_xor().literals()) {
1084 sum ^= LiteralIsTrue(lit) ? 1 : 0;
1089 bool LinearConstraintIsFeasible(
const ConstraintProto&
ct) {
1091 const int num_variables =
ct.linear().coeffs_size();
1092 for (
int i = 0; i < num_variables; ++i) {
1093 sum +=
Value(
ct.linear().vars(i)) *
ct.linear().coeffs(i);
1098 int64_t LinearExpressionValue(
const LinearExpressionProto& expr)
const {
1099 int64_t sum = expr.offset();
1100 const int num_variables = expr.vars_size();
1101 for (
int i = 0; i < num_variables; ++i) {
1102 sum +=
Value(expr.vars(i)) * expr.coeffs(i);
1107 bool LinMaxConstraintIsFeasible(
const ConstraintProto&
ct) {
1108 const int64_t
max = LinearExpressionValue(
ct.lin_max().target());
1110 for (
int i = 0; i <
ct.lin_max().exprs_size(); ++i) {
1111 const int64_t expr_value = LinearExpressionValue(
ct.lin_max().exprs(i));
1112 actual_max =
std::max(actual_max, expr_value);
1114 return max == actual_max;
1117 bool IntProdConstraintIsFeasible(
const ConstraintProto&
ct) {
1118 const int64_t prod = LinearExpressionValue(
ct.int_prod().target());
1119 int64_t actual_prod = 1;
1120 for (
const LinearExpressionProto& expr :
ct.int_prod().exprs()) {
1121 actual_prod =
CapProd(actual_prod, LinearExpressionValue(expr));
1123 return prod == actual_prod;
1126 bool IntDivConstraintIsFeasible(
const ConstraintProto&
ct) {
1127 return LinearExpressionValue(
ct.int_div().target()) ==
1128 LinearExpressionValue(
ct.int_div().exprs(0)) /
1129 LinearExpressionValue(
ct.int_div().exprs(1));
1132 bool IntModConstraintIsFeasible(
const ConstraintProto&
ct) {
1133 return LinearExpressionValue(
ct.int_mod().target()) ==
1134 LinearExpressionValue(
ct.int_mod().exprs(0)) %
1135 LinearExpressionValue(
ct.int_mod().exprs(1));
1138 bool AllDiffConstraintIsFeasible(
const ConstraintProto&
ct) {
1139 absl::flat_hash_set<int64_t> values;
1140 for (
const LinearExpressionProto& expr :
ct.all_diff().exprs()) {
1141 const int64_t
value = LinearExpressionValue(expr);
1142 const auto [it, inserted] = values.insert(
value);
1143 if (!inserted)
return false;
1148 int64_t IntervalStart(
const IntervalConstraintProto&
interval)
const {
1149 return LinearExpressionValue(
interval.start());
1152 int64_t IntervalSize(
const IntervalConstraintProto&
interval)
const {
1153 return LinearExpressionValue(
interval.size());
1156 int64_t IntervalEnd(
const IntervalConstraintProto&
interval)
const {
1157 return LinearExpressionValue(
interval.end());
1160 bool IntervalConstraintIsFeasible(
const ConstraintProto&
ct) {
1161 const int64_t size = IntervalSize(
ct.interval());
1162 if (size < 0)
return false;
1163 return IntervalStart(
ct.interval()) + size == IntervalEnd(
ct.interval());
1166 bool NoOverlapConstraintIsFeasible(
const CpModelProto&
model,
1167 const ConstraintProto&
ct) {
1168 std::vector<std::pair<int64_t, int64_t>> start_durations_pairs;
1169 for (
const int i :
ct.no_overlap().intervals()) {
1170 const ConstraintProto& interval_constraint =
model.constraints(i);
1171 if (ConstraintIsEnforced(interval_constraint)) {
1172 const IntervalConstraintProto&
interval =
1173 interval_constraint.interval();
1174 start_durations_pairs.push_back(
1178 std::sort(start_durations_pairs.begin(), start_durations_pairs.end());
1180 for (
const auto& pair : start_durations_pairs) {
1181 if (pair.first < previous_end)
return false;
1182 previous_end = pair.first + pair.second;
1187 bool IntervalsAreDisjoint(
const IntervalConstraintProto& interval1,
1188 const IntervalConstraintProto& interval2) {
1189 return IntervalEnd(interval1) <= IntervalStart(interval2) ||
1190 IntervalEnd(interval2) <= IntervalStart(interval1);
1193 bool IntervalIsEmpty(
const IntervalConstraintProto&
interval) {
1197 bool NoOverlap2DConstraintIsFeasible(
const CpModelProto&
model,
1198 const ConstraintProto&
ct) {
1199 const auto& arg =
ct.no_overlap_2d();
1202 std::vector<std::pair<
const IntervalConstraintProto*
const,
1203 const IntervalConstraintProto*
const>>
1204 enforced_intervals_xy;
1206 const int num_intervals = arg.x_intervals_size();
1207 CHECK_EQ(arg.y_intervals_size(), num_intervals);
1208 for (
int i = 0; i < num_intervals; ++i) {
1209 const ConstraintProto& x =
model.constraints(arg.x_intervals(i));
1210 const ConstraintProto& y =
model.constraints(arg.y_intervals(i));
1211 if (ConstraintIsEnforced(x) && ConstraintIsEnforced(y) &&
1212 (!arg.boxes_with_null_area_can_overlap() ||
1213 (!IntervalIsEmpty(x.interval()) &&
1214 !IntervalIsEmpty(y.interval())))) {
1215 enforced_intervals_xy.push_back({&x.interval(), &y.interval()});
1219 const int num_enforced_intervals = enforced_intervals_xy.size();
1220 for (
int i = 0; i < num_enforced_intervals; ++i) {
1221 for (
int j = i + 1; j < num_enforced_intervals; ++j) {
1222 const auto& xi = *enforced_intervals_xy[i].first;
1223 const auto& yi = *enforced_intervals_xy[i].second;
1224 const auto& xj = *enforced_intervals_xy[j].first;
1225 const auto& yj = *enforced_intervals_xy[j].second;
1226 if (!IntervalsAreDisjoint(xi, xj) && !IntervalsAreDisjoint(yi, yj) &&
1227 !IntervalIsEmpty(xi) && !IntervalIsEmpty(xj) &&
1228 !IntervalIsEmpty(yi) && !IntervalIsEmpty(yj)) {
1229 VLOG(1) <<
"Interval " << i <<
"(x=[" << IntervalStart(xi) <<
", "
1230 << IntervalEnd(xi) <<
"], y=[" << IntervalStart(yi) <<
", "
1231 << IntervalEnd(yi) <<
"]) and " << j <<
"(x=["
1232 << IntervalStart(xj) <<
", " << IntervalEnd(xj) <<
"], y=["
1233 << IntervalStart(yj) <<
", " << IntervalEnd(yj)
1234 <<
"]) are not disjoint.";
1242 bool CumulativeConstraintIsFeasible(
const CpModelProto&
model,
1243 const ConstraintProto&
ct) {
1245 const int64_t
capacity = LinearExpressionValue(
ct.cumulative().capacity());
1246 const int num_intervals =
ct.cumulative().intervals_size();
1247 absl::flat_hash_map<int64_t, int64_t> usage;
1248 for (
int i = 0; i < num_intervals; ++i) {
1249 const ConstraintProto& interval_constraint =
1250 model.constraints(
ct.cumulative().intervals(i));
1251 if (ConstraintIsEnforced(interval_constraint)) {
1252 const IntervalConstraintProto&
interval =
1253 interval_constraint.interval();
1255 const int64_t duration = IntervalSize(
interval);
1257 LinearExpressionValue(
ct.cumulative().demands(i));
1258 for (int64_t t =
start; t <
start + duration; ++t) {
1261 VLOG(1) <<
"time: " << t <<
" usage: " << usage[t]
1271 bool ElementConstraintIsFeasible(
const ConstraintProto&
ct) {
1272 if (
ct.element().vars().empty())
return false;
1274 if (index < 0 || index >=
ct.element().vars_size())
return false;
1278 bool TableConstraintIsFeasible(
const ConstraintProto&
ct) {
1279 const int size =
ct.table().vars_size();
1280 if (size == 0)
return true;
1281 for (
int row_start = 0; row_start <
ct.table().values_size();
1282 row_start += size) {
1284 while (
Value(
ct.table().vars(i)) ==
ct.table().values(row_start + i)) {
1286 if (i == size)
return !
ct.table().negated();
1289 return ct.table().negated();
1292 bool AutomatonConstraintIsFeasible(
const ConstraintProto&
ct) {
1294 absl::flat_hash_map<std::pair<int64_t, int64_t>, int64_t> transition_map;
1295 const int num_transitions =
ct.automaton().transition_tail().size();
1296 for (
int i = 0; i < num_transitions; ++i) {
1297 transition_map[{
ct.automaton().transition_tail(i),
1298 ct.automaton().transition_label(i)}] =
1299 ct.automaton().transition_head(i);
1303 int64_t current_state =
ct.automaton().starting_state();
1304 const int num_steps =
ct.automaton().vars_size();
1305 for (
int i = 0; i < num_steps; ++i) {
1306 const std::pair<int64_t, int64_t> key = {current_state,
1307 Value(
ct.automaton().vars(i))};
1308 if (!transition_map.contains(key)) {
1311 current_state = transition_map[key];
1315 for (
const int64_t
final :
ct.automaton().final_states()) {
1316 if (current_state ==
final)
return true;
1321 bool CircuitConstraintIsFeasible(
const ConstraintProto&
ct) {
1324 const int num_arcs =
ct.circuit().tails_size();
1325 absl::flat_hash_set<int>
nodes;
1326 absl::flat_hash_map<int, int> nexts;
1327 for (
int i = 0; i < num_arcs; ++i) {
1328 const int tail =
ct.circuit().tails(i);
1329 const int head =
ct.circuit().heads(i);
1332 if (LiteralIsFalse(
ct.circuit().literals(i)))
continue;
1333 if (nexts.contains(
tail)) {
1334 VLOG(1) <<
"Node with two outgoing arcs";
1343 for (
const int node :
nodes) {
1344 if (!nexts.contains(node)) {
1345 VLOG(1) <<
"Node with no next: " << node;
1348 if (nexts[node] == node)
continue;
1352 if (cycle_size == 0)
return true;
1356 absl::flat_hash_set<int> visited;
1357 int current = in_cycle;
1358 int num_visited = 0;
1359 while (!visited.contains(current)) {
1361 visited.insert(current);
1362 current = nexts[current];
1364 if (current != in_cycle) {
1365 VLOG(1) <<
"Rho shape";
1368 if (num_visited != cycle_size) {
1369 VLOG(1) <<
"More than one cycle";
1371 return num_visited == cycle_size;
1374 bool RoutesConstraintIsFeasible(
const ConstraintProto&
ct) {
1375 const int num_arcs =
ct.routes().tails_size();
1376 int num_used_arcs = 0;
1377 int num_self_arcs = 0;
1379 std::vector<int> tail_to_head;
1380 std::vector<int> depot_nexts;
1381 for (
int i = 0; i < num_arcs; ++i) {
1382 const int tail =
ct.routes().tails(i);
1383 const int head =
ct.routes().heads(i);
1386 tail_to_head.resize(num_nodes, -1);
1387 if (LiteralIsTrue(
ct.routes().literals(i))) {
1389 if (
tail == 0)
return false;
1395 depot_nexts.push_back(
head);
1397 if (tail_to_head[
tail] != -1)
return false;
1404 if (num_nodes == 0)
return true;
1408 for (
int start : depot_nexts) {
1410 while (
start != 0) {
1411 if (tail_to_head[
start] == -1)
return false;
1417 if (count != num_used_arcs) {
1418 VLOG(1) <<
"count: " << count <<
" != num_used_arcs:" << num_used_arcs;
1426 if (count - depot_nexts.size() + 1 + num_self_arcs != num_nodes) {
1427 VLOG(1) <<
"Not all nodes are covered!";
1434 bool InverseConstraintIsFeasible(
const ConstraintProto&
ct) {
1435 const int num_variables =
ct.inverse().f_direct_size();
1436 if (num_variables !=
ct.inverse().f_inverse_size())
return false;
1438 for (
int i = 0; i < num_variables; i++) {
1439 const int fi =
Value(
ct.inverse().f_direct(i));
1440 if (fi < 0 || num_variables <= fi)
return false;
1441 if (i !=
Value(
ct.inverse().f_inverse(fi)))
return false;
1446 bool ReservoirConstraintIsFeasible(
const ConstraintProto&
ct) {
1447 const int num_variables =
ct.reservoir().time_exprs_size();
1448 const int64_t min_level =
ct.reservoir().min_level();
1449 const int64_t max_level =
ct.reservoir().max_level();
1450 absl::btree_map<int64_t, int64_t> deltas;
1451 const bool has_active_variables =
ct.reservoir().active_literals_size() > 0;
1452 for (
int i = 0; i < num_variables; i++) {
1453 const int64_t
time = LinearExpressionValue(
ct.reservoir().time_exprs(i));
1454 if (!has_active_variables ||
1455 Value(
ct.reservoir().active_literals(i)) == 1) {
1456 deltas[
time] +=
ct.reservoir().level_changes(i);
1459 int64_t current_level = 0;
1460 for (
const auto&
delta : deltas) {
1461 current_level +=
delta.second;
1462 if (current_level < min_level || current_level > max_level) {
1463 VLOG(1) <<
"Reservoir level " << current_level
1464 <<
" is out of bounds at time" <<
delta.first;
1472 std::vector<int64_t> variable_values_;
1478 const std::vector<int64_t>& variable_values,
1479 const CpModelProto* mapping_proto,
1480 const std::vector<int>* postsolve_mapping) {
1481 if (variable_values.size() !=
model.variables_size()) {
1482 VLOG(1) <<
"Wrong number of variables (" << variable_values.size()
1483 <<
") in the solution vector. It should be "
1484 <<
model.variables_size() <<
".";
1489 for (
int i = 0; i <
model.variables_size(); ++i) {
1491 VLOG(1) <<
"Variable #" << i <<
" has value " << variable_values[i]
1492 <<
" which do not fall in its domain: "
1499 ConstraintChecker checker(variable_values);
1501 for (
int c = 0; c <
model.constraints_size(); ++c) {
1502 const ConstraintProto&
ct =
model.constraints(c);
1504 if (!checker.ConstraintIsEnforced(
ct))
continue;
1506 bool is_feasible =
true;
1507 const ConstraintProto::ConstraintCase type =
ct.constraint_case();
1509 case ConstraintProto::ConstraintCase::kBoolOr:
1510 is_feasible = checker.BoolOrConstraintIsFeasible(
ct);
1512 case ConstraintProto::ConstraintCase::kBoolAnd:
1513 is_feasible = checker.BoolAndConstraintIsFeasible(
ct);
1515 case ConstraintProto::ConstraintCase::kAtMostOne:
1516 is_feasible = checker.AtMostOneConstraintIsFeasible(
ct);
1518 case ConstraintProto::ConstraintCase::kExactlyOne:
1519 is_feasible = checker.ExactlyOneConstraintIsFeasible(
ct);
1521 case ConstraintProto::ConstraintCase::kBoolXor:
1522 is_feasible = checker.BoolXorConstraintIsFeasible(
ct);
1524 case ConstraintProto::ConstraintCase::kLinear:
1525 is_feasible = checker.LinearConstraintIsFeasible(
ct);
1527 case ConstraintProto::ConstraintCase::kIntProd:
1528 is_feasible = checker.IntProdConstraintIsFeasible(
ct);
1530 case ConstraintProto::ConstraintCase::kIntDiv:
1531 is_feasible = checker.IntDivConstraintIsFeasible(
ct);
1533 case ConstraintProto::ConstraintCase::kIntMod:
1534 is_feasible = checker.IntModConstraintIsFeasible(
ct);
1536 case ConstraintProto::ConstraintCase::kLinMax:
1537 is_feasible = checker.LinMaxConstraintIsFeasible(
ct);
1539 case ConstraintProto::ConstraintCase::kAllDiff:
1540 is_feasible = checker.AllDiffConstraintIsFeasible(
ct);
1542 case ConstraintProto::ConstraintCase::kInterval:
1543 if (!checker.IntervalConstraintIsFeasible(
ct)) {
1544 if (
ct.interval().has_start()) {
1550 LOG(
ERROR) <<
"Warning, an interval constraint was likely used "
1551 "without a corresponding linear constraint linking "
1552 "its start, size and end.";
1554 is_feasible =
false;
1558 case ConstraintProto::ConstraintCase::kNoOverlap:
1559 is_feasible = checker.NoOverlapConstraintIsFeasible(
model,
ct);
1561 case ConstraintProto::ConstraintCase::kNoOverlap2D:
1562 is_feasible = checker.NoOverlap2DConstraintIsFeasible(
model,
ct);
1564 case ConstraintProto::ConstraintCase::kCumulative:
1565 is_feasible = checker.CumulativeConstraintIsFeasible(
model,
ct);
1567 case ConstraintProto::ConstraintCase::kElement:
1568 is_feasible = checker.ElementConstraintIsFeasible(
ct);
1570 case ConstraintProto::ConstraintCase::kTable:
1571 is_feasible = checker.TableConstraintIsFeasible(
ct);
1573 case ConstraintProto::ConstraintCase::kAutomaton:
1574 is_feasible = checker.AutomatonConstraintIsFeasible(
ct);
1576 case ConstraintProto::ConstraintCase::kCircuit:
1577 is_feasible = checker.CircuitConstraintIsFeasible(
ct);
1579 case ConstraintProto::ConstraintCase::kRoutes:
1580 is_feasible = checker.RoutesConstraintIsFeasible(
ct);
1582 case ConstraintProto::ConstraintCase::kInverse:
1583 is_feasible = checker.InverseConstraintIsFeasible(
ct);
1585 case ConstraintProto::ConstraintCase::kReservoir:
1586 is_feasible = checker.ReservoirConstraintIsFeasible(
ct);
1588 case ConstraintProto::ConstraintCase::CONSTRAINT_NOT_SET:
1597 VLOG(1) <<
"Failing constraint #" << c <<
" : "
1599 if (mapping_proto !=
nullptr && postsolve_mapping !=
nullptr) {
1600 std::vector<int> reverse_map(mapping_proto->variables().size(), -1);
1601 for (
int var = 0;
var < postsolve_mapping->size(); ++
var) {
1602 reverse_map[(*postsolve_mapping)[
var]] =
var;
1605 VLOG(1) <<
"var: " <<
var <<
" mapped_to: " << reverse_map[
var]
1606 <<
" value: " << variable_values[
var] <<
" initial_domain: "
1608 <<
" postsolved_domain: "
1613 VLOG(1) <<
"var: " <<
var <<
" value: " << variable_values[
var];
1625 if (
model.has_objective()) {
1626 int64_t inner_objective = 0;
1627 const int num_variables =
model.objective().coeffs_size();
1628 for (
int i = 0; i < num_variables; ++i) {
1629 inner_objective += checker.Value(
model.objective().vars(i)) *
1630 model.objective().coeffs(i);
1632 if (!
model.objective().domain().empty()) {
1634 VLOG(1) <<
"Objective value not in domain!";
1638 double factor =
model.objective().scaling_factor();
1639 if (factor == 0.0) factor = 1.0;
1640 const double scaled_objective =
1642 (
static_cast<double>(inner_objective) +
model.objective().offset());
1643 VLOG(2) <<
"Checker inner objective = " << inner_objective;
1644 VLOG(2) <<
"Checker scaled objective = " << scaled_objective;
#define CHECK_EQ(val1, val2)
#define DCHECK_GE(val1, val2)
#define DCHECK_EQ(val1, val2)
#define VLOG(verboselevel)
We call domain any subset of Int64 = [kint64min, kint64max].
int64_t Size() const
Returns the number of elements in the domain.
#define RETURN_IF_NOT_EMPTY(statement)
std::vector< int > UsedVariables(const ConstraintProto &ct)
bool RefIsPositive(int ref)
std::vector< int > UsedIntervals(const ConstraintProto &ct)
std::string ValidateInputCpModel(const SatParameters ¶ms, const CpModelProto &model)
bool DomainInProtoContains(const ProtoWithDomain &proto, int64_t value)
std::string ValidateCpModel(const CpModelProto &model, bool after_presolve)
std::function< int64_t(const Model &)> Value(IntegerVariable v)
Domain ReadDomainFromProto(const ProtoWithDomain &proto)
IndexReferences GetReferencesUsedByConstraint(const ConstraintProto &ct)
std::string ConstraintCaseName(ConstraintProto::ConstraintCase constraint_case)
bool SolutionIsFeasible(const CpModelProto &model, const std::vector< int64_t > &variable_values, const CpModelProto *mapping_proto, const std::vector< int > *postsolve_mapping)
Collection of objects used to extend the Constraint Solver library.
int64_t CapAdd(int64_t x, int64_t y)
std::string ProtobufShortDebugString(const P &message)
int64_t CapProd(int64_t x, int64_t y)
std::string ProtobufDebugString(const P &message)
bool IntervalsAreSortedAndNonAdjacent(absl::Span< const ClosedInterval > intervals)
Returns true iff we have:
static int input(yyscan_t yyscanner)