This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
forked from rte-france/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csfz.cs
95 lines (89 loc) · 3.03 KB
/
csfz.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2010-2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using Google.OrTools.Flatzinc;
public class CsFz
{
/**
* Loads a flatzinc file (passed as the first argument) and solves it.
*/
private static void Solve(String filename)
{
Model model = new Model(filename);
model.LoadFromFile(filename);
// Uncomment to see the model.
// Console.WriteLine(model.ToString());
// This is mandatory.
model.PresolveForCp(/*verbose=*/false);
// Display basic statistics on the model.
model.PrintStatistics();
FlatzincParameters parameters = new FlatzincParameters();
// Initialize to default values as in the C++ runner.
parameters.all_solutions = false;
parameters.free_search = false;
parameters.last_conflict = false;
parameters.heuristic_period = 100;
parameters.ignore_unknown = false;
parameters.log_period = 10000000;
parameters.luby_restart = -1;
parameters.num_solutions = 0;
parameters.restart_log_size = -1;
parameters.threads = 0;
parameters.time_limit_in_ms = 10000;
parameters.logging = false;
parameters.verbose_impact = false;
parameters.thread_id = -1;
parameters.search_type = FlatzincParameters.DEFAULT;
// Mandatory to retrieve solutions.
parameters.store_all_solutions = true;
Solver solver = new Solver(model);
solver.Solve(parameters);
int last = solver.NumStoredSolutions() - 1;
if (last >= 0) {
SolutionOutputSpecsVector output_vector = model.output();
foreach (SolutionOutputSpecs output in output_vector) {
if (output.variable != null) {
IntegerVariable var = output.variable;
Console.WriteLine(output.name + " = " +
solver.StoredValue(last, var));
}
if (output.flat_variables.Count > 0) {
String line = output.name;
foreach (SolutionOutputSpecs.Bounds b in output.bounds) {
line += "[" + b.ToString() + "]";
}
line += " = {";
bool start = true;
foreach (IntegerVariable var in output.flat_variables) {
if (start) {
start = false;
} else {
line += ", ";
}
line += solver.StoredValue(last, var);
}
line += "}";
Console.WriteLine(line);
}
}
}
}
public static void Main(String[] args)
{
if (args.Length == 0) {
Console.WriteLine("A file name is required!");
} else {
Solve(args[0]);
}
}
}