Java Reference

Java Reference

ReservoirConstraint.java
Go to the documentation of this file.
1// Copyright 2010-2021 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
14package com.google.ortools.sat;
15
16import com.google.ortools.sat.ReservoirConstraintProto;
17
24public class ReservoirConstraint extends Constraint {
26 super(model.getBuilder());
27 this.model = model;
28 }
29
36 public ReservoirConstraint addEvent(LinearArgument time, long levelChange) {
37 ReservoirConstraintProto.Builder reservoir = getBuilder().getReservoirBuilder();
38 reservoir.addTimeExprs(
39 model.getLinearExpressionProtoBuilderFromLinearArgument(time, /*negate=*/false));
40 reservoir.addLevelChanges(levelChange);
41 reservoir.addActiveLiterals(model.trueLiteral().getIndex());
42 return this;
43 }
44
50 public ReservoirConstraint addEvent(long time, long levelChange) {
51 ReservoirConstraintProto.Builder reservoir = getBuilder().getReservoirBuilder();
52 reservoir.addTimeExprs(model.getLinearExpressionProtoBuilderFromLong(time));
53 reservoir.addLevelChanges(levelChange);
54 reservoir.addActiveLiterals(model.trueLiteral().getIndex());
55 return this;
56 }
57
64 public ReservoirConstraint addOptionalEvent(LinearExpr time, long levelChange, Literal isActive) {
65 ReservoirConstraintProto.Builder reservoir = getBuilder().getReservoirBuilder();
66 reservoir.addTimeExprs(
67 model.getLinearExpressionProtoBuilderFromLinearArgument(time, /*negate=*/false));
68 reservoir.addLevelChanges(levelChange);
69 reservoir.addActiveLiterals(isActive.getIndex());
70 return this;
71 }
72
78 public ReservoirConstraint addOptionalEvent(long time, long levelChange, Literal isActive) {
79 ReservoirConstraintProto.Builder reservoir = getBuilder().getReservoirBuilder();
80 reservoir.addTimeExprs(model.getLinearExpressionProtoBuilderFromLong(time));
81 reservoir.addLevelChanges(levelChange);
82 reservoir.addActiveLiterals(isActive.getIndex());
83 return this;
84 }
85
86 private final CpModel model;
87}
Wrapper around a ConstraintProto.
Definition: Constraint.java:25
ConstraintProto.Builder getBuilder()
Returns the constraint builder.
Definition: Constraint.java:49
Main modeling class.
Definition: CpModel.java:43
Literal trueLiteral()
Returns the true literal.
Definition: CpModel.java:104
CpModelProto.Builder getBuilder()
Returns the model builder.
Definition: CpModel.java:1025
ReservoirConstraint addEvent(LinearArgument time, long levelChange)
Adds a mandatory event.
ReservoirConstraint addEvent(long time, long levelChange)
Adds a mandatory event at a fixed time.
ReservoirConstraint addOptionalEvent(long time, long levelChange, Literal isActive)
Adds an optional event at a fixed time.
ReservoirConstraint addOptionalEvent(LinearExpr time, long levelChange, Literal isActive)
Adds an optional event.
A object that can build a LinearExpr object.
A linear expression (sum (ai * xi) + b).
Definition: LinearExpr.java:19
Interface to describe a boolean variable or its negation.
Definition: Literal.java:17