Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
IntervalVar.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.ConstraintProto;
17import com.google.ortools.sat.CpModelProto;
18import com.google.ortools.sat.IntervalConstraintProto;
19import com.google.ortools.sat.LinearExpressionProto;
20
22public final class IntervalVar {
23 IntervalVar(CpModelProto.Builder builder, LinearExpressionProto.Builder startBuilder,
24 LinearExpressionProto.Builder sizeBuilder, LinearExpressionProto.Builder endBuilder,
25 String name) {
26 this.modelBuilder = builder;
27 this.constraintIndex = modelBuilder.getConstraintsCount();
28 ConstraintProto.Builder ct = modelBuilder.addConstraintsBuilder();
29 ct.setName(name);
30 this.intervalBuilder = ct.getIntervalBuilder();
31 this.intervalBuilder.setStart(startBuilder);
32 this.intervalBuilder.setSize(sizeBuilder);
33 this.intervalBuilder.setEnd(endBuilder);
34 }
35
36 IntervalVar(CpModelProto.Builder builder, LinearExpressionProto.Builder startBuilder,
37 LinearExpressionProto.Builder sizeBuilder, LinearExpressionProto.Builder endBuilder,
38 int isPresentIndex, String name) {
39 this.modelBuilder = builder;
40 this.constraintIndex = modelBuilder.getConstraintsCount();
41 ConstraintProto.Builder ct = modelBuilder.addConstraintsBuilder();
42 ct.setName(name);
43 ct.addEnforcementLiteral(isPresentIndex);
44 this.intervalBuilder = ct.getIntervalBuilder();
45 this.intervalBuilder.setStart(startBuilder);
46 this.intervalBuilder.setSize(sizeBuilder);
47 this.intervalBuilder.setEnd(endBuilder);
48 }
49
50 @Override
51 public String toString() {
52 return modelBuilder.getConstraints(constraintIndex).toString();
53 }
54
56 public int getIndex() {
57 return constraintIndex;
58 }
59
61 public IntervalConstraintProto.Builder getBuilder() {
62 return intervalBuilder;
63 }
64
66 public String getName() {
67 return modelBuilder.getConstraints(constraintIndex).getName();
68 }
69
73 }
74
77 return LinearExpr.rebuildFromLinearExpressionProto(intervalBuilder.getSize());
78 }
79
82 return LinearExpr.rebuildFromLinearExpressionProto(intervalBuilder.getEnd());
83 }
84
85 private final CpModelProto.Builder modelBuilder;
86 private final int constraintIndex;
87 private final IntervalConstraintProto.Builder intervalBuilder;
88}
com.google.ortools.sat.ConstraintProto getConstraints(int index)
com.google.ortools.sat.LinearExpressionProto getSize()
com.google.ortools.sat.LinearExpressionProto getEnd()
com.google.ortools.sat.LinearExpressionProto getStart()
IntervalConstraintProto.Builder getBuilder()
static LinearExpr rebuildFromLinearExpressionProto(LinearExpressionProto proto)