-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathfap_utilities.h
71 lines (59 loc) · 3 KB
/
fap_utilities.h
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
// Copyright 2010-2025 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.
//
// Utilities used by frequency_assignment_problem.cc.
//
#ifndef OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_
#define OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_
#include <cstdint>
#include <vector>
#include "absl/container/btree_map.h"
#include "absl/types/span.h"
#include "examples/cpp/fap_parser.h"
#include "ortools/constraint_solver/constraint_solver.h"
namespace operations_research {
// Checks if the solution given from the Solver satisfies all
// the hard binary constraints specified in the ctr.txt.
bool CheckConstraintSatisfaction(
absl::Span<const FapConstraint> data_constraints,
absl::Span<const int> variables,
const absl::btree_map<int, int>& index_from_key);
// Checks if the solution given from the Solver has not modified the values of
// the variables that were initially assigned and denoted as hard in var.txt.
bool CheckVariablePosition(
const absl::btree_map<int, FapVariable>& data_variables,
absl::Span<const int> variables,
const absl::btree_map<int, int>& index_from_key);
// Counts the number of different values in the variable vector.
int NumberOfAssignedValues(absl::Span<const int> variables);
// Prints the duration of the solving process.
void PrintElapsedTime(int64_t time1, int64_t time2);
// Prints the solution found by the Hard Solver for feasible instances.
void PrintResultsHard(SolutionCollector* collector,
const std::vector<IntVar*>& variables,
IntVar* objective_var,
const absl::btree_map<int, FapVariable>& data_variables,
absl::Span<const FapConstraint> data_constraints,
const absl::btree_map<int, int>& index_from_key,
absl::Span<const int> key_from_index);
// Prints the solution found by the Soft Solver for unfeasible instances.
void PrintResultsSoft(SolutionCollector* collector,
const std::vector<IntVar*>& variables, IntVar* total_cost,
const absl::btree_map<int, FapVariable>& hard_variables,
absl::Span<const FapConstraint> hard_constraints,
const absl::btree_map<int, FapVariable>& soft_variables,
absl::Span<const FapConstraint> soft_constraints,
const absl::btree_map<int, int>& index_from_key,
absl::Span<const int> key_from_index);
} // namespace operations_research
#endif // OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_