Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
IntervalVariables.cs
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
14namespace Google.OrTools.Sat
15{
23public class IntervalVar
24{
26 LinearExpressionProto end, int is_present_index, string name)
27 {
28 model_ = model;
29 index_ = model.Constraints.Count;
30 interval_ = new IntervalConstraintProto();
31 interval_.Start = start;
32 interval_.Size = size;
33 interval_.End = end;
34
36 ct.Interval = interval_;
37 ct.Name = name;
38 ct.EnforcementLiteral.Capacity = 1;
39 ct.EnforcementLiteral.Add(is_present_index);
40 model.Constraints.Add(ct);
41 }
42
44 LinearExpressionProto end, string name)
45 {
46 model_ = model;
47 index_ = model.Constraints.Count;
48 interval_ = new IntervalConstraintProto();
49 interval_.Start = start;
50 interval_.Size = size;
51 interval_.End = end;
52
54 ct.Interval = interval_;
55 ct.Name = name;
56 model_.Constraints.Add(ct);
57 }
58
60 public int GetIndex()
61 {
62 return index_;
63 }
64
67 {
68 return LinearExpr.RebuildLinearExprFromLinearExpressionProto(interval_.Start, model_);
69 }
70
73 {
74 return LinearExpr.RebuildLinearExprFromLinearExpressionProto(interval_.Size, model_);
75 }
76
79 {
80 return LinearExpr.RebuildLinearExprFromLinearExpressionProto(interval_.End, model_);
81 }
82
85 {
86 get {
87 return interval_;
88 }
89 set {
90 interval_ = value;
91 }
92 }
93
94 public override string ToString()
95 {
96 return model_.Constraints[index_].ToString();
97 }
98
99 public string Name()
100 {
101 return model_.Constraints[index_].Name;
102 }
103
104 private CpModelProto model_;
105 private int index_;
106 private IntervalConstraintProto interval_;
107}
108
109} // namespace Google.OrTools.Sat
pbc::RepeatedField< int > EnforcementLiteral
The constraint will be enforced iff all literals listed here are true. If this is empty,...
A constraint programming problem.
pbc::RepeatedField< global::Google.OrTools.Sat.ConstraintProto > Constraints
This is not really a constraint. It is there so it can be referred by other constraints using this "i...
global::Google.OrTools.Sat.LinearExpressionProto End
global::Google.OrTools.Sat.LinearExpressionProto Start
global::Google.OrTools.Sat.LinearExpressionProto Size
int GetIndex()
The Index of the interval in the model proto.
IntervalVar(CpModelProto model, LinearExpressionProto start, LinearExpressionProto size, LinearExpressionProto end, string name)
LinearExpr EndExpr()
The end expression of the interval.
LinearExpr SizeExpr()
The size expression of the interval.
IntervalVar(CpModelProto model, LinearExpressionProto start, LinearExpressionProto size, LinearExpressionProto end, int is_present_index, string name)
LinearExpr StartExpr()
The start expression of the interval.
IntervalConstraintProto Proto
The underlying interval proto.
Holds a linear expression: sum (ai * xi) + b.
Some constraints supports linear expression instead of just using a reference to a variable....