OR-Tools 7.2
Main Page
Namespaces
Classes
Files
File List
File Members
ortools
sat
samples
SimpleSatProgram.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
// [START program]
15
using
System;
16
using
Google
.
OrTools
.
Sat
;
17
18
public
class
SimpleSatProgram
19
{
20
static
void
Main()
21
{
22
// Creates the model.
23
// [START model]
24
CpModel
model =
new
CpModel
();
25
// [END model]
26
27
// Creates the variables.
28
// [START variables]
29
int
num_vals = 3;
30
31
IntVar
x = model.
NewIntVar
(0, num_vals - 1,
"x"
);
32
IntVar
y = model.
NewIntVar
(0, num_vals - 1,
"y"
);
33
IntVar
z = model.
NewIntVar
(0, num_vals - 1,
"z"
);
34
// [END variables]
35
36
// Creates the constraints.
37
// [START constraints]
38
model.
Add
(x != y);
39
// [END constraints]
40
41
// Creates a solver and solves the model.
42
// [START solve]
43
CpSolver
solver =
new
CpSolver
();
44
CpSolverStatus
status = solver.
Solve
(model);
45
// [END solve]
46
47
if
(status ==
CpSolverStatus
.Feasible)
48
{
49
Console.WriteLine(
"x = "
+ solver.
Value
(x));
50
Console.WriteLine(
"y = "
+ solver.
Value
(y));
51
Console.WriteLine(
"z = "
+ solver.
Value
(z));
52
}
53
}
54
}
55
// [END program]
SimpleSatProgram
Definition:
SimpleSatProgram.cs:18
Google.OrTools.Sat.CpSolver.Value
long Value(LinearExpr e)
Definition:
CpSolver.cs:96
Google.OrTools.Sat.IntVar
Definition:
IntegerExpressions.cs:495
Google
Definition:
KInt64Vector.cs:11
Google.OrTools.Sat.CpModel.Add
Constraint Add(BoundedLinearExpression lin)
Definition:
CpModel.cs:104
Google.OrTools
Definition:
KInt64Vector.cs:11
Google.OrTools.Sat.CpModel
Wrapper class around the cp_model proto.
Definition:
CpModel.cs:23
Google.OrTools.Sat.CpSolver.Solve
CpSolverStatus Solve(CpModel model)
Definition:
CpSolver.cs:22
Google.OrTools.Sat.CpSolverStatus
CpSolverStatus
The status returned by a solver trying to solve a CpModelProto.
Definition:
CpModel.pb.cs:172
Google.OrTools.Sat.CpModel.NewIntVar
IntVar NewIntVar(long lb, long ub, string name)
Definition:
CpModel.cs:45
Google.OrTools.Sat
Definition:
CpModel.pb.cs:12
Google.OrTools.Sat.CpSolver
Definition:
CpSolver.cs:19