Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_model.proto
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// Proto describing a general Constraint Programming (CP) problem.
15
16syntax = "proto3";
17
18package operations_research.sat;
19
20option csharp_namespace = "Google.OrTools.Sat";
21option java_package = "com.google.ortools.sat";
22option java_multiple_files = true;
23option java_outer_classname = "CpModelProtobuf";
24
25// An integer variable.
26//
27// It will be referred to by an int32 corresponding to its index in a
28// CpModelProto variables field.
29//
30// Depending on the context, a reference to a variable whose domain is in [0, 1]
31// can also be seen as a Boolean that will be true if the variable value is 1
32// and false if it is 0. When used in this context, the field name will always
33// contain the word "literal".
34//
35// Negative reference (advanced usage): to simplify the creation of a model and
36// for efficiency reasons, all the "literal" or "variable" fields can also
37// contain a negative index. A negative index i will refer to the negation of
38// the integer variable at index -i -1 or to NOT the literal at the same index.
39//
40// Ex: A variable index 4 will refer to the integer variable model.variables(4)
41// and an index of -5 will refer to the negation of the same variable. A literal
42// index 4 will refer to the logical fact that model.variable(4) == 1 and a
43// literal index of -5 will refer to the logical fact model.variable(4) == 0.
44message IntegerVariableProto {
45 // For debug/logging only. Can be empty.
46 string name = 1;
47
48 // The variable domain given as a sorted list of n disjoint intervals
49 // [min, max] and encoded as [min_0, max_0, ..., min_{n-1}, max_{n-1}].
50 //
51 // The most common example being just [min, max].
52 // If min == max, then this is a constant variable.
53 //
54 // We have:
55 // - domain_size() is always even.
56 // - min == domain.front();
57 // - max == domain.back();
58 // - for all i < n : min_i <= max_i
59 // - for all i < n-1 : max_i + 1 < min_{i+1}.
60 //
61 // Note that we check at validation that a variable domain is small enough so
62 // that we don't run into integer overflow in our algorithms. Because of that,
63 // you cannot just have "unbounded" variable like [0, kint64max] and should
64 // try to specify tighter domains.
65 repeated int64 domain = 2;
66}
67
68// Argument of the constraints of the form OP(literals).
69message BoolArgumentProto {
70 repeated int32 literals = 1;
71}
72
73// Some constraints supports linear expression instead of just using a reference
74// to a variable. This is especially useful during presolve to reduce the model
75// size.
76message LinearExpressionProto {
77 repeated int32 vars = 1;
78 repeated int64 coeffs = 2;
79 int64 offset = 3;
80}
81
82message LinearArgumentProto {
83 LinearExpressionProto target = 1;
84 repeated LinearExpressionProto exprs = 2;
85}
86
87// All affine expressions must take different values.
88message AllDifferentConstraintProto {
89 repeated LinearExpressionProto exprs = 1;
90}
91
92// The linear sum vars[i] * coeffs[i] must fall in the given domain. The domain
93// has the same format as the one in IntegerVariableProto.
94//
95// Note that the validation code currently checks using the domain of the
96// involved variables that the sum can always be computed without integer
97// overflow and throws an error otherwise.
98message LinearConstraintProto {
99 repeated int32 vars = 1;
100 repeated int64 coeffs = 2; // Same size as vars.
101 repeated int64 domain = 3;
102}
103
104// The constraint target = vars[index].
105// This enforces that index takes one of the value in [0, vars_size()).
106message ElementConstraintProto {
107 int32 index = 1;
108 int32 target = 2;
109 repeated int32 vars = 3;
110}
111
112// This is not really a constraint. It is there so it can be referred by other
113// constraints using this "interval" concept.
114//
115// IMPORTANT: For now, this constraint do not enforce any relations on the
116// components, and it is up to the client to add in the model:
117// - enforcement => start + size == end.
118// - enforcement => size >= 0 // Only needed if size is not already >= 0.
119//
120// IMPORTANT: For now, we just support affine relation. We could easily
121// create an intermediate variable to support full linear expression, but this
122// isn't done currently.
123message IntervalConstraintProto {
124 LinearExpressionProto start = 4;
125 LinearExpressionProto end = 5;
126 LinearExpressionProto size = 6;
127}
128
129// All the intervals (index of IntervalConstraintProto) must be disjoint. More
130// formally, there must exist a sequence so that for each consecutive intervals,
131// we have end_i <= start_{i+1}. In particular, intervals of size zero do matter
132// for this constraint. This is also known as a disjunctive constraint in
133// scheduling.
134message NoOverlapConstraintProto {
135 repeated int32 intervals = 1;
136}
137
138// The boxes defined by [start_x, end_x) * [start_y, end_y) cannot overlap.
139// Furthermore, one box is optional if at least one of the x or y interval is
140// optional.
141//
142// Note that the case of boxes of size zero is special. The following cases
143// violate the constraint:
144// - a point box inside a box with a non zero area
145// - a line box overlapping a box with a non zero area
146// - one vertical line box crossing an horizontal line box.
147message NoOverlap2DConstraintProto {
148 repeated int32 x_intervals = 1;
149 repeated int32 y_intervals = 2; // Same size as x_intervals.
150}
151
152// The sum of the demands of the intervals at each interval point cannot exceed
153// a capacity. Note that intervals are interpreted as [start, end) and as
154// such intervals like [2,3) and [3,4) do not overlap for the point of view of
155// this constraint. Moreover, intervals of size zero are ignored.
156//
157// All demands must not contain any negative value in their domains. This is
158// checked at validation. The capacity can currently contains negative values,
159// but it will be propagated to >= 0 right away.
160message CumulativeConstraintProto {
161 LinearExpressionProto capacity = 1;
162 repeated int32 intervals = 2;
163 repeated LinearExpressionProto demands = 3; // Same size as intervals.
164}
165
166// Maintain a reservoir level within bounds. The water level starts at 0, and at
167// any time, it must be within [min_level, max_level].
168//
169// If the variable active_literals[i] is true, and if the expression
170// time_exprs[i] is assigned a value t, then the current level changes by
171// level_changes[i] at the time t. Therefore, at any time t:
172//
173// sum(level_changes[i] * active_literals[i] if time_exprs[i] <= t)
174// in [min_level, max_level]
175//
176// Note that min level must be <= 0, and the max level must be >= 0. Please use
177// fixed level_changes to simulate initial state.
178//
179// The array of boolean variables 'actives', if defined, indicates which actions
180// are actually performed. If this array is not defined, then it is assumed that
181// all actions will be performed.
182message ReservoirConstraintProto {
183 int64 min_level = 1;
184 int64 max_level = 2;
185 repeated LinearExpressionProto time_exprs = 3; // affine expressions.
186 // Currently, we only support constant level changes.
187 repeated LinearExpressionProto level_changes = 6; // affine expressions.
188 repeated int32 active_literals = 5;
189 reserved 4;
190}
191
192// The circuit constraint is defined on a graph where the arc presence are
193// controlled by literals. Each arc is given by an index in the
194// tails/heads/literals lists that must have the same size.
195//
196// For now, we ignore node indices with no incident arc. All the other nodes
197// must have exactly one incoming and one outgoing selected arc (i.e. literal at
198// true). All the selected arcs that are not self-loops must form a single
199// circuit. Note that multi-arcs are allowed, but only one of them will be true
200// at the same time. Multi-self loop are disallowed though.
201message CircuitConstraintProto {
202 repeated int32 tails = 3;
203 repeated int32 heads = 4;
204 repeated int32 literals = 5;
205}
206
207// The "VRP" (Vehicle Routing Problem) constraint.
208//
209// The direct graph where arc #i (from tails[i] to head[i]) is present iff
210// literals[i] is true must satisfy this set of properties:
211// - #incoming arcs == 1 except for node 0.
212// - #outgoing arcs == 1 except for node 0.
213// - for node zero, #incoming arcs == #outgoing arcs.
214// - There are no duplicate arcs.
215// - Self-arcs are allowed except for node 0.
216// - There is no cycle in this graph, except through node 0.
217//
218// Note: Currently this constraint expect all the nodes in [0, num_nodes) to
219// have at least one incident arc. The model will be considered invalid if it
220// is not the case. You can add self-arc fixed to one to ignore some nodes if
221// needed.
222//
223// TODO(user): It is probably possible to generalize this constraint to a
224// no-cycle in a general graph, or a no-cycle with sum incoming <= 1 and sum
225// outgoing <= 1 (more efficient implementation). On the other hand, having this
226// specific constraint allow us to add specific "cuts" to a VRP problem.
227message RoutesConstraintProto {
228 repeated int32 tails = 1;
229 repeated int32 heads = 2;
230 repeated int32 literals = 3;
231
232 // EXPERIMENTAL. The demands for each node, and the maximum capacity for each
233 // route. Note that this is currently only used for the LP relaxation and one
234 // need to add the corresponding constraint to enforce this outside of the LP.
235 //
236 // TODO(user): Ideally, we should be able to extract any dimension like these
237 // (i.e. capacity, route_length, etc..) automatically from the encoding. The
238 // classical way to encode that is to have "current_capacity" variables along
239 // the route and linear equations of the form:
240 // arc_literal => (current_capacity_tail + demand <= current_capacity_head)
241 repeated int32 demands = 4;
242 int64 capacity = 5;
243}
244
245// The values of the n-tuple formed by the given variables can only be one of
246// the listed n-tuples in values. The n-tuples are encoded in a flattened way:
247// [tuple0_v0, tuple0_v1, ..., tuple0_v{n-1}, tuple1_v0, ...].
248message TableConstraintProto {
249 repeated int32 vars = 1;
250 repeated int64 values = 2;
251
252 // If true, the meaning is "negated", that is we forbid any of the given
253 // tuple from a feasible assignment.
254 bool negated = 3;
255}
256
257// The two arrays of variable each represent a function, the second is the
258// inverse of the first: f_direct[i] == j <=> f_inverse[j] == i.
259message InverseConstraintProto {
260 repeated int32 f_direct = 1;
261 repeated int32 f_inverse = 2;
262}
263
264// This constraint forces a sequence of variables to be accepted by an
265// automaton.
266message AutomatonConstraintProto {
267 // A state is identified by a non-negative number. It is preferable to keep
268 // all the states dense in says [0, num_states). The automaton starts at
269 // starting_state and must finish in any of the final states.
270 int64 starting_state = 2;
271 repeated int64 final_states = 3;
272
273 // List of transitions (all 3 vectors have the same size). Both tail and head
274 // are states, label is any variable value. No two outgoing transitions from
275 // the same state can have the same label.
276 repeated int64 transition_tail = 4;
277 repeated int64 transition_head = 5;
278 repeated int64 transition_label = 6;
279
280 // The sequence of variables. The automaton is ran for vars_size() "steps" and
281 // the value of vars[i] corresponds to the transition label at step i.
282 repeated int32 vars = 7;
283}
284
285// A list of variables, without any semantics.
286message ListOfVariablesProto {
287 repeated int32 vars = 1;
288}
289
290// Next id: 31
291message ConstraintProto {
292 // For debug/logging only. Can be empty.
293 string name = 1;
294
295 // The constraint will be enforced iff all literals listed here are true. If
296 // this is empty, then the constraint will always be enforced. An enforced
297 // constraint must be satisfied, and an un-enforced one will simply be
298 // ignored.
299 //
300 // This is also called half-reification. To have an equivalence between a
301 // literal and a constraint (full reification), one must add both a constraint
302 // (controlled by a literal l) and its negation (controlled by the negation of
303 // l).
304 //
305 // Important: as of September 2018, only a few constraint support enforcement:
306 // - bool_or, bool_and, linear: fully supported.
307 // - interval: only support a single enforcement literal.
308 // - other: no support (but can be added on a per-demand basis).
309 repeated int32 enforcement_literal = 2;
310
311 // The actual constraint with its arguments.
312 oneof constraint {
313 // The bool_or constraint forces at least one literal to be true.
314 BoolArgumentProto bool_or = 3;
315
316 // The bool_and constraint forces all of the literals to be true.
317 //
318 // This is a "redundant" constraint in the sense that this can easily be
319 // encoded with many bool_or or at_most_one. It is just more space efficient
320 // and handled slightly differently internally.
321 BoolArgumentProto bool_and = 4;
322
323 // The at_most_one constraint enforces that no more than one literal is
324 // true at the same time.
325 //
326 // Note that an at most one constraint of length n could be encoded with n
327 // bool_and constraint with n-1 term on the right hand side. So in a sense,
328 // this constraint contribute directly to the "implication-graph" or the
329 // 2-SAT part of the model.
330 //
331 // This constraint does not support enforcement_literal. Just use a linear
332 // constraint if you need to enforce it. You also do not need to use it
333 // directly, we will extract it from the model in most situations.
334 BoolArgumentProto at_most_one = 26;
335
336 // The exactly_one constraint force exactly one literal to true and no more.
337 //
338 // Anytime a bool_or (it could have been called at_least_one) is included
339 // into an at_most_one, then the bool_or is actually an exactly one
340 // constraint, and the extra literal in the at_most_one can be set to false.
341 // So in this sense, this constraint is not really needed. it is just here
342 // for a better description of the problem structure and to facilitate some
343 // algorithm.
344 //
345 // This constraint does not support enforcement_literal. Just use a linear
346 // constraint if you need to enforce it. You also do not need to use it
347 // directly, we will extract it from the model in most situations.
348 BoolArgumentProto exactly_one = 29;
349
350 // The bool_xor constraint forces an odd number of the literals to be true.
351 BoolArgumentProto bool_xor = 5;
352
353 // The int_div constraint forces the target to equal exprs[0] / exprs[1].
354 // The division is "rounded" towards zero, so we can have for instance
355 // (2 = 12 / 5) or (-3 = -10 / 3). If you only want exact integer division,
356 // then you should use instead of t = a / b, the int_prod constraint
357 // a = b * t.
358 //
359 // If 0 belongs to the domain of exprs[1], then the model is deemed invalid.
360 LinearArgumentProto int_div = 7;
361
362 // The int_mod constraint forces the target to equal exprs[0] % exprs[1].
363 // The domain of exprs[1] must be strictly positive. The sign of the target
364 // is the same as the sign of exprs[0].
365 LinearArgumentProto int_mod = 8;
366
367 // The int_prod constraint forces the target to equal the product of all
368 // variables. By convention, because we can just remove term equal to one,
369 // the empty product forces the target to be one.
370 //
371 // Note that the solver checks for potential integer overflow. So the
372 // product of the maximum absolute value of all the terms (using the initial
373 // domain) should fit on an int64. Otherwise the model will be declared
374 // invalid.
375 LinearArgumentProto int_prod = 11;
376
377 // The lin_max constraint forces the target to equal the maximum of all
378 // linear expressions.
379 // Note that this can model a minimum simply by negating all expressions.
380 LinearArgumentProto lin_max = 27;
381
382 // The linear constraint enforces a linear inequality among the variables,
383 // such as 0 <= x + 2y <= 10.
384 LinearConstraintProto linear = 12;
385
386 // The all_diff constraint forces all variables to take different values.
387 AllDifferentConstraintProto all_diff = 13;
388
389 // The element constraint forces the variable with the given index
390 // to be equal to the target.
391 ElementConstraintProto element = 14;
392
393 // The circuit constraint takes a graph and forces the arcs present
394 // (with arc presence indicated by a literal) to form a unique cycle.
395 CircuitConstraintProto circuit = 15;
396
397 // The routes constraint implements the vehicle routing problem.
398 RoutesConstraintProto routes = 23;
399
400 // The table constraint enforces what values a tuple of variables may
401 // take.
402 TableConstraintProto table = 16;
403
404 // The automaton constraint forces a sequence of variables to be accepted
405 // by an automaton.
406 AutomatonConstraintProto automaton = 17;
407
408 // The inverse constraint forces two arrays to be inverses of each other:
409 // the values of one are the indices of the other, and vice versa.
410 InverseConstraintProto inverse = 18;
411
412 // The reservoir constraint forces the sum of a set of active demands
413 // to always be between a specified minimum and maximum value during
414 // specific times.
415 ReservoirConstraintProto reservoir = 24;
416
417 // Constraints on intervals.
418 //
419 // The first constraint defines what an "interval" is and the other
420 // constraints use references to it. All the intervals that have an
421 // enforcement_literal set to false are ignored by these constraints.
422 //
423 // TODO(user): Explain what happen for intervals of size zero. Some
424 // constraints ignore them; others do take them into account.
425
426 // The interval constraint takes a start, end, and size, and forces
427 // start + size == end.
428 IntervalConstraintProto interval = 19;
429
430 // The no_overlap constraint prevents a set of intervals from
431 // overlapping; in scheduling, this is called a disjunctive
432 // constraint.
433 NoOverlapConstraintProto no_overlap = 20;
434
435 // The no_overlap_2d constraint prevents a set of boxes from overlapping.
436 NoOverlap2DConstraintProto no_overlap_2d = 21;
437
438 // The cumulative constraint ensures that for any integer point, the sum
439 // of the demands of the intervals containing that point does not exceed
440 // the capacity.
441 CumulativeConstraintProto cumulative = 22;
442
443 // This constraint is not meant to be used and will be rejected by the
444 // solver. It is meant to mark variable when testing the presolve code.
445 ListOfVariablesProto dummy_constraint = 30;
446 }
447}
448
449// Optimization objective.
450message CpObjectiveProto {
451 // The linear terms of the objective to minimize.
452 // For a maximization problem, one can negate all coefficients in the
453 // objective and set scaling_factor to -1.
454 repeated int32 vars = 1;
455 repeated int64 coeffs = 4;
456
457 // The displayed objective is always:
458 // scaling_factor * (sum(coefficients[i] * objective_vars[i]) + offset).
459 // This is needed to have a consistent objective after presolve or when
460 // scaling a double problem to express it with integers.
461 //
462 // Note that if scaling_factor is zero, then it is assumed to be 1, so that by
463 // default these fields have no effect.
464 double offset = 2;
465 double scaling_factor = 3;
466
467 // If non-empty, only look for an objective value in the given domain.
468 // Note that this does not depend on the offset or scaling factor, it is a
469 // domain on the sum of the objective terms only.
470 repeated int64 domain = 5;
471
472 // Internal field. Do not set. When we scale a FloatObjectiveProto to a
473 // integer version, we set this to true if the scaling was exact (i.e. all
474 // original coeff were integer for instance).
475 //
476 // TODO(user): Put the error bounds we computed instead?
477 bool scaling_was_exact = 6;
478
479 // Internal fields to recover a bound on the original integer objective from
480 // the presolved one. Basically, initially the integer objective fit on an
481 // int64 and is in [Initial_lb, Initial_ub]. During presolve, we might change
482 // the linear expression to have a new domain [Presolved_lb, Presolved_ub]
483 // that will also always fit on an int64.
484 //
485 // The two domain will always be linked with an affine transformation between
486 // the two of the form:
487 // old = (new + before_offset) * integer_scaling_factor + after_offset.
488 // Note that we use both offsets to always be able to do the computation while
489 // staying in the int64 domain. In particular, the after_offset will always
490 // be in (-integer_scaling_factor, integer_scaling_factor).
491 int64 integer_before_offset = 7;
492 int64 integer_after_offset = 9;
493 int64 integer_scaling_factor = 8;
494}
495
496// A linear floating point objective: sum coeffs[i] * vars[i] + offset.
497// Note that the variable can only still take integer value.
498message FloatObjectiveProto {
499 repeated int32 vars = 1;
500 repeated double coeffs = 2;
501 double offset = 3;
502
503 // The optimization direction. The default is to minimize
504 bool maximize = 4;
505}
506
507// Define the strategy to follow when the solver needs to take a new decision.
508// Note that this strategy is only defined on a subset of variables.
509message DecisionStrategyProto {
510 // The variables to be considered for the next decision. The order matter and
511 // is always used as a tie-breaker after the variable selection strategy
512 // criteria defined below.
513 repeated int32 variables = 1;
514
515 // If this is set, then the variables field must be empty.
516 // We currently only support affine expression.
517 //
518 // Note that this is needed so that if a variable has an affine
519 // representative, we can properly transform a DecisionStrategyProto through
520 // presolve.
521 repeated LinearExpressionProto exprs = 5;
522
523 // The order in which the variables (resp. affine expression) above should be
524 // considered. Note that only variables that are not already fixed are
525 // considered.
526 //
527 // TODO(user): extend as needed.
528 enum VariableSelectionStrategy {
529 CHOOSE_FIRST = 0;
530 CHOOSE_LOWEST_MIN = 1;
531 CHOOSE_HIGHEST_MAX = 2;
532 CHOOSE_MIN_DOMAIN_SIZE = 3;
533 CHOOSE_MAX_DOMAIN_SIZE = 4;
534 }
535 VariableSelectionStrategy variable_selection_strategy = 2;
536
537 // Once a variable (resp. affine expression) has been chosen, this enum
538 // describe what decision is taken on its domain.
539 //
540 // TODO(user): extend as needed.
541 enum DomainReductionStrategy {
542 SELECT_MIN_VALUE = 0;
543 SELECT_MAX_VALUE = 1;
544 SELECT_LOWER_HALF = 2;
545 SELECT_UPPER_HALF = 3;
546 SELECT_MEDIAN_VALUE = 4;
547 }
548 DomainReductionStrategy domain_reduction_strategy = 3;
549}
550
551// This message encodes a partial (or full) assignment of the variables of a
552// CpModelProto. The variable indices should be unique and valid variable
553// indices.
554message PartialVariableAssignment {
555 repeated int32 vars = 1;
556 repeated int64 values = 2;
557}
558
559// A permutation of integers encoded as a list of cycles, hence the "sparse"
560// format. The image of an element cycle[i] is cycle[(i + 1) % cycle_length].
561message SparsePermutationProto {
562 // Each cycle is listed one after the other in the support field.
563 // The size of each cycle is given (in order) in the cycle_sizes field.
564 repeated int32 support = 1;
565 repeated int32 cycle_sizes = 2;
566}
567
568// A dense matrix of numbers encoded in a flat way, row by row.
569// That is matrix[i][j] = entries[i * num_cols + j];
570message DenseMatrixProto {
571 int32 num_rows = 1;
572 int32 num_cols = 2;
573 repeated int32 entries = 3;
574}
575
576// EXPERIMENTAL. For now, this is meant to be used by the solver and not filled
577// by clients.
578//
579// Hold symmetry information about the set of feasible solutions. If we permute
580// the variable values of any feasible solution using one of the permutation
581// described here, we should always get another feasible solution.
582//
583// We usually also enforce that the objective of the new solution is the same.
584//
585// The group of permutations encoded here is usually computed from the encoding
586// of the model, so it is not meant to be a complete representation of the
587// feasible solution symmetries, just a valid subgroup.
588message SymmetryProto {
589 // A list of variable indices permutations that leave the feasible space of
590 // solution invariant. Usually, we only encode a set of generators of the
591 // group.
592 repeated SparsePermutationProto permutations = 1;
593
594 // An orbitope is a special symmetry structure of the solution space. If the
595 // variable indices are arranged in a matrix (with no duplicates), then any
596 // permutation of the columns will be a valid permutation of the feasible
597 // space.
598 //
599 // This arise quite often. The typical example is a graph coloring problem
600 // where for each node i, you have j booleans to indicate its color. If the
601 // variables color_of_i_is_j are arranged in a matrix[i][j], then any columns
602 // permutations leave the problem invariant.
603 repeated DenseMatrixProto orbitopes = 2;
604}
605
606// A constraint programming problem.
607message CpModelProto {
608 // For debug/logging only. Can be empty.
609 string name = 1;
610
611 // The associated Protos should be referred by their index in these fields.
612 repeated IntegerVariableProto variables = 2;
613 repeated ConstraintProto constraints = 3;
614
615 // The objective to minimize. Can be empty for pure decision problems.
616 CpObjectiveProto objective = 4;
617
618 // Advanced usage.
619 // It is invalid to have both an objective and a floating point objective.
620 //
621 // The objective of the model, in floating point format. The solver will
622 // automatically scale this to integer during expansion and thus convert it to
623 // a normal CpObjectiveProto. See the mip* parameters to control how this is
624 // scaled. In most situation the precision will be good enough, but you can
625 // see the logs to see what are the precision guaranteed when this is
626 // converted to a fixed point representation.
627 //
628 // Note that even if the precision is bad, the returned objective_value and
629 // best_objective_bound will be computed correctly. So at the end of the solve
630 // you can check the gap if you only want precise optimal.
631 FloatObjectiveProto floating_point_objective = 9;
632
633 // Defines the strategy that the solver should follow when the
634 // search_branching parameter is set to FIXED_SEARCH. Note that this strategy
635 // is also used as a heuristic when we are not in fixed search.
636 //
637 // Advanced Usage: if not all variables appears and the parameter
638 // "instantiate_all_variables" is set to false, then the solver will not try
639 // to instantiate the variables that do not appear. Thus, at the end of the
640 // search, not all variables may be fixed. Currently, we will set them to
641 // their lower bound in the solution.
642 repeated DecisionStrategyProto search_strategy = 5;
643
644 // Solution hint.
645 //
646 // If a feasible or almost-feasible solution to the problem is already known,
647 // it may be helpful to pass it to the solver so that it can be used. The
648 // solver will try to use this information to create its initial feasible
649 // solution.
650 //
651 // Note that it may not always be faster to give a hint like this to the
652 // solver. There is also no guarantee that the solver will use this hint or
653 // try to return a solution "close" to this assignment in case of multiple
654 // optimal solutions.
655 PartialVariableAssignment solution_hint = 6;
656
657 // A list of literals. The model will be solved assuming all these literals
658 // are true. Compared to just fixing the domain of these literals, using this
659 // mechanism is slower but allows in case the model is INFEASIBLE to get a
660 // potentially small subset of them that can be used to explain the
661 // infeasibility.
662 //
663 // Think (IIS), except when you are only concerned by the provided
664 // assumptions. This is powerful as it allows to group a set of logically
665 // related constraint under only one enforcement literal which can potentially
666 // give you a good and interpretable explanation for infeasiblity.
667 //
668 // Such infeasibility explanation will be available in the
669 // sufficient_assumptions_for_infeasibility response field.
670 repeated int32 assumptions = 7;
671
672 // For now, this is not meant to be filled by a client writing a model, but
673 // by our preprocessing step.
674 //
675 // Information about the symmetries of the feasible solution space.
676 // These usually leaves the objective invariant.
677 SymmetryProto symmetry = 8;
678}
679
680// The status returned by a solver trying to solve a CpModelProto.
681enum CpSolverStatus {
682 // The status of the model is still unknown. A search limit has been reached
683 // before any of the statuses below could be determined.
684 UNKNOWN = 0;
685
686 // The given CpModelProto didn't pass the validation step. You can get a
687 // detailed error by calling ValidateCpModel(model_proto).
688 MODEL_INVALID = 1;
689
690 // A feasible solution has been found. But the search was stopped before we
691 // could prove optimality or before we enumerated all solutions of a
692 // feasibility problem (if asked).
693 FEASIBLE = 2;
694
695 // The problem has been proven infeasible.
696 INFEASIBLE = 3;
697
698 // An optimal feasible solution has been found.
699 //
700 // More generally, this status represent a success. So we also return OPTIMAL
701 // if we find a solution for a pure feasibility problem or if a gap limit has
702 // been specified and we return a solution within this limit. In the case
703 // where we need to return all the feasible solution, this status will only be
704 // returned if we enumerated all of them; If we stopped before, we will return
705 // FEASIBLE.
706 OPTIMAL = 4;
707}
708
709// Just a message used to store dense solution.
710// This is used by the additional_solutions field.
711message CpSolverSolution {
712 repeated int64 values = 1;
713}
714
715// The response returned by a solver trying to solve a CpModelProto.
716//
717// Next id: 31
718message CpSolverResponse {
719 // The status of the solve.
720 CpSolverStatus status = 1;
721
722 // A feasible solution to the given problem. Depending on the returned status
723 // it may be optimal or just feasible. This is in one-to-one correspondence
724 // with a CpModelProto::variables repeated field and list the values of all
725 // the variables.
726 repeated int64 solution = 2;
727
728 // Only make sense for an optimization problem. The objective value of the
729 // returned solution if it is non-empty. If there is no solution, then for a
730 // minimization problem, this will be an upper-bound of the objective of any
731 // feasible solution, and a lower-bound for a maximization problem.
732 double objective_value = 3;
733
734 // Only make sense for an optimization problem. A proven lower-bound on the
735 // objective for a minimization problem, or a proven upper-bound for a
736 // maximization problem.
737 double best_objective_bound = 4;
738
739 // If the parameter fill_additional_solutions_in_response is set, then we
740 // copy all the solutions from our internal solution pool here.
741 //
742 // Note that the one returned in the solution field will likely appear here
743 // too. Do not rely on the solutions order as it depends on our internal
744 // representation (after postsolve).
745 repeated CpSolverSolution additional_solutions = 27;
746
747 // Advanced usage.
748 //
749 // If the option fill_tightened_domains_in_response is set, then this field
750 // will be a copy of the CpModelProto.variables where each domain has been
751 // reduced using the information the solver was able to derive. Note that this
752 // is only filled with the info derived during a normal search and we do not
753 // have any dedicated algorithm to improve it.
754 //
755 // Warning: if you didn't set keep_all_feasible_solutions_in_presolve, then
756 // these domains might exclude valid feasible solution. Otherwise for a
757 // feasibility problem, all feasible solution should be there.
758 //
759 // Warning: For an optimization problem, these will correspond to valid bounds
760 // for the problem of finding an improving solution to the best one found so
761 // far. It might be better to solve a feasibility version if one just want to
762 // explore the feasible region.
763 repeated IntegerVariableProto tightened_variables = 21;
764
765 // A subset of the model "assumptions" field. This will only be filled if the
766 // status is INFEASIBLE. This subset of assumption will be enough to still get
767 // an infeasible problem.
768 //
769 // This is related to what is called the irreducible inconsistent subsystem or
770 // IIS. Except one is only concerned by the provided assumptions. There is
771 // also no guarantee that we return an irreducible (aka minimal subset).
772 // However, this is based on SAT explanation and there is a good chance it is
773 // not too large.
774 //
775 // If you really want a minimal subset, a possible way to get one is by
776 // changing your model to minimize the number of assumptions at false, but
777 // this is likely an harder problem to solve.
778 //
779 // Important: Currently, this is minimized only in single-thread and if the
780 // problem is not an optimization problem, otherwise, it will always include
781 // all the assumptions.
782 //
783 // TODO(user): Allows for returning multiple core at once.
784 repeated int32 sufficient_assumptions_for_infeasibility = 23;
785
786 // Contains the integer objective optimized internally. This is only filled if
787 // the problem had a floating point objective, and on the final response, not
788 // the ones given to callbacks.
789 CpObjectiveProto integer_objective = 28;
790
791 // Advanced usage.
792 //
793 // A lower bound on the inner integer expression of the objective. This is
794 // either a bound on the expression in the returned integer_objective or on
795 // the integer expression of the original objective if the problem already has
796 // an integer objective.
797 int64 inner_objective_lower_bound = 29;
798
799 // Some statistics about the solve.
800 //
801 // Important: in multithread, this correspond the statistics of the first
802 // subsolver. Which is usually the one with the user defined parameters. Or
803 // the default-search if none are specified.
804 int64 num_integers = 30;
805 int64 num_booleans = 10;
806 int64 num_conflicts = 11;
807 int64 num_branches = 12;
808 int64 num_binary_propagations = 13;
809 int64 num_integer_propagations = 14;
810 int64 num_restarts = 24;
811 int64 num_lp_iterations = 25;
812
813 // The time counted from the beginning of the Solve() call.
814 double wall_time = 15;
815 double user_time = 16;
816 double deterministic_time = 17;
817
818 // The integral of log(1 + absolute_objective_gap) over time.
819 double gap_integral = 22;
820
821 // Additional information about how the solution was found. It also stores
822 // model or parameters errors that caused the model to be invalid.
823 string solution_info = 20;
824
825 // The solve log will be filled if the parameter log_to_response is set to
826 // true.
827 string solve_log = 26;
828}