Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ReservoirConstraint.java
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
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(model.getLinearExpressionProtoBuilderFromLong(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(model.getLinearExpressionProtoBuilderFromLong(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(model.getLinearExpressionProtoBuilderFromLong(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(model.getLinearExpressionProtoBuilderFromLong(levelChange));
82 reservoir.addActiveLiterals(isActive.getIndex());
83 return this;
84 }
85
86 private final CpModel model;
87}
ConstraintProto.Builder getBuilder()
CpModelProto.Builder getBuilder()
ReservoirConstraint addOptionalEvent(LinearExpr time, long levelChange, Literal isActive)
ReservoirConstraint addEvent(long time, long levelChange)
ReservoirConstraint addEvent(LinearArgument time, long levelChange)
ReservoirConstraint addOptionalEvent(long time, long levelChange, Literal isActive)