DotNet Reference

.Net 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  {
37  constraint_.EnforcementLiteral.Add(lit.GetIndex());
38  }
39  }
40 
41  public int Index
42  {
43  get {
44  return index_;
45  }
46  }
47 
49  {
50  get {
51  return constraint_;
52  }
53  set {
54  constraint_ = value;
55  }
56  }
57 
58  private int index_;
59  private ConstraintProto constraint_;
60  }
61 
62 } // namespace Google.OrTools.Sat
ConstraintProto Proto
Definition: Constraints.cs:49
pbc::RepeatedField< int > EnforcementLiteral
The constraint will be enforced iff all literals listed here are true.
Definition: CpModel.pb.cs:4530
int Index
Definition: Constraints.cs:42
void OnlyEnforceIf(ILiteral lit)
Definition: Constraints.cs:28
Constraint(CpModelProto model)
Definition: Constraints.cs:21
void OnlyEnforceIf(ILiteral[] lits)
Definition: Constraints.cs:33
using System
Definition: Program.cs:14
A constraint programming problem.
Definition: CpModel.pb.cs:7044
Next id: 29
Definition: CpModel.pb.cs:4384
pbc::RepeatedField< global::Google.OrTools.Sat.ConstraintProto > Constraints
Definition: CpModel.pb.cs:7117
int GetIndex()
Definition: Constraints.cs:20
Definition: CpModel.pb.cs:12