OR-Tools 7.2
Main Page
Namespaces
Classes
Files
File List
File Members
ortools
sat
samples
SolveWithTimeLimitSampleSat.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
using
System;
15
using
Google
.
OrTools
.
Sat
;
16
17
public
class
SolveWithTimeLimitSampleSat
18
{
19
static
void
Main()
20
{
21
// Creates the model.
22
CpModel
model =
new
CpModel
();
23
// Creates the variables.
24
int
num_vals = 3;
25
26
IntVar
x = model.
NewIntVar
(0, num_vals - 1,
"x"
);
27
IntVar
y = model.
NewIntVar
(0, num_vals - 1,
"y"
);
28
IntVar
z = model.
NewIntVar
(0, num_vals - 1,
"z"
);
29
// Adds a different constraint.
30
model.
Add
(x != y);
31
32
// Creates a solver and solves the model.
33
CpSolver
solver =
new
CpSolver
();
34
35
// Adds a time limit. Parameters are stored as strings in the solver.
36
solver.
StringParameters
=
"max_time_in_seconds:10.0"
;
37
38
CpSolverStatus
status = solver.
Solve
(model);
39
40
if
(status ==
CpSolverStatus
.Feasible)
41
{
42
Console.WriteLine(
"x = "
+ solver.
Value
(x));
43
Console.WriteLine(
"y = "
+ solver.
Value
(y));
44
Console.WriteLine(
"z = "
+ solver.
Value
(z));
45
}
46
}
47
}
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.CpSolver.StringParameters
string StringParameters
Definition:
CpSolver.cs:86
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
SolveWithTimeLimitSampleSat
Definition:
SolveWithTimeLimitSampleSat.cs:17
Google.OrTools.Sat
Definition:
CpModel.pb.cs:12
Google.OrTools.Sat.CpSolver
Definition:
CpSolver.cs:19