Java Reference

Java Reference

java/com/google/ortools/sat/IntervalVar.java
Go to the documentation of this file.
1 // Copyright 2010-2018 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 package com.google.ortools.sat;
15 
19 
21 public final class IntervalVar {
23  CpModelProto.Builder builder, int startIndex, int sizeIndex, int endIndex, String name) {
24  this.modelBuilder = builder;
25  this.constraintIndex = modelBuilder.getConstraintsCount();
26  ConstraintProto.Builder ct = modelBuilder.addConstraintsBuilder();
27  ct.setName(name);
28  this.intervalBuilder = ct.getIntervalBuilder();
29  this.intervalBuilder.setStart(startIndex);
30  this.intervalBuilder.setSize(sizeIndex);
31  this.intervalBuilder.setEnd(endIndex);
32  }
33 
34  IntervalVar(CpModelProto.Builder builder, int startIndex, int sizeIndex, int endIndex,
35  int isPresentIndex, String name) {
36  this.modelBuilder = builder;
37  this.constraintIndex = modelBuilder.getConstraintsCount();
38  ConstraintProto.Builder ct = modelBuilder.addConstraintsBuilder();
39  ct.setName(name);
40  ct.addEnforcementLiteral(isPresentIndex);
41  this.intervalBuilder = ct.getIntervalBuilder();
42  this.intervalBuilder.setStart(startIndex);
43  this.intervalBuilder.setSize(sizeIndex);
44  this.intervalBuilder.setEnd(endIndex);
45  }
46 
47  @Override
48  public String toString() {
49  return modelBuilder.getConstraints(constraintIndex).toString();
50  }
51 
53  public int getIndex() {
54  return constraintIndex;
55  }
56 
59  return intervalBuilder;
60  }
61 
63  public String getName() {
64  return modelBuilder.getConstraints(constraintIndex).getName();
65  }
66 
67  private final CpModelProto.Builder modelBuilder;
68  private final int constraintIndex;
69  private final IntervalConstraintProto.Builder intervalBuilder;
70 }
String toString()
.lang.Override com.google.ortools.sat.ConstraintProto getConstraints(int index)
repeated .operations_research.sat.ConstraintProto constraints = 3;
IntervalConstraintProto.Builder getBuilder()
Returns the interval builder.
.lang.Override java.lang.String getName()
int getIndex()
Returns the index of the interval constraint in the model.
String getName()
Returns the name passed in the constructor.
.lang.Override int getConstraintsCount()
repeated .operations_research.sat.ConstraintProto constraints = 3;
An interval variable.