DotNet Reference

DotNet Reference

Constraints.cs
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 namespace Google.OrTools.Sat
15 {
16 using System;
17 using System.Collections.Generic;
18 
19 public class Constraint
20 {
21  public Constraint(CpModelProto model)
22  {
23  index_ = model.Constraints.Count;
24  constraint_ = new ConstraintProto();
25  model.Constraints.Add(constraint_);
26  }
27 
28  public void OnlyEnforceIf(ILiteral lit)
29  {
30  constraint_.EnforcementLiteral.Add(lit.GetIndex());
31  }
32 
33  public void OnlyEnforceIf(ILiteral[] lits)
34  {
35  foreach (ILiteral lit in lits) {
36  constraint_.EnforcementLiteral.Add(lit.GetIndex());
37  }
38  }
39 
40  public int Index
41  {
42  get { return index_; }
43  }
44 
46  {
47  get { return constraint_; }
48  set { constraint_ = value; }
49  }
50 
51  private int index_;
52  private ConstraintProto constraint_;
53 }
54 
55 } // namespace Google.OrTools.Sat
ConstraintProto Proto
Definition: Constraints.cs:46
pbc::RepeatedField< int > EnforcementLiteral
The constraint will be enforced iff all literals listed here are true.
Definition: CpModel.pb.cs:3711
int Index
Definition: Constraints.cs:41
void OnlyEnforceIf(ILiteral lit)
Definition: Constraints.cs:28
Constraint(CpModelProto model)
Definition: Constraints.cs:21
void OnlyEnforceIf(ILiteral[] lits)
Definition: Constraints.cs:33
A constraint programming problem.
Definition: CpModel.pb.cs:5663
Next id: 29
Definition: CpModel.pb.cs:3562
pbc::RepeatedField< global::Google.OrTools.Sat.ConstraintProto > Constraints
Definition: CpModel.pb.cs:5736
int GetIndex()
Definition: Constraints.cs:20
Definition: CpModel.pb.cs:12