2025-01-10 11:33:35 +01:00
|
|
|
// Copyright 2010-2025 Google LLC
|
2012-09-13 16:25:28 +00:00
|
|
|
// 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.
|
2016-10-05 14:08:27 +02:00
|
|
|
|
2012-09-13 16:25:28 +00:00
|
|
|
//
|
|
|
|
|
// Utilities used by frequency_assignment_problem.cc.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_
|
|
|
|
|
#define OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_
|
|
|
|
|
|
2021-08-23 14:46:12 +02:00
|
|
|
#include <cstdint>
|
2012-09-13 16:25:28 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2023-02-01 14:14:30 +01:00
|
|
|
#include "absl/container/btree_map.h"
|
2025-01-06 13:20:57 +01:00
|
|
|
#include "absl/types/span.h"
|
2017-04-26 17:30:25 +02:00
|
|
|
#include "examples/cpp/fap_parser.h"
|
2020-09-23 11:45:03 +02:00
|
|
|
#include "ortools/constraint_solver/constraint_solver.h"
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
namespace operations_research {
|
|
|
|
|
|
|
|
|
|
// Checks if the solution given from the Solver satisfies all
|
|
|
|
|
// the hard binary constraints specified in the ctr.txt.
|
2016-11-16 18:20:16 +01:00
|
|
|
bool CheckConstraintSatisfaction(
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const FapConstraint> data_constraints,
|
|
|
|
|
absl::Span<const int> variables,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, int>& index_from_key);
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
// 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.
|
2023-06-21 17:31:06 +02:00
|
|
|
bool CheckVariablePosition(
|
|
|
|
|
const absl::btree_map<int, FapVariable>& data_variables,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const int> variables,
|
2023-06-21 17:31:06 +02:00
|
|
|
const absl::btree_map<int, int>& index_from_key);
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
// Counts the number of different values in the variable vector.
|
2025-01-06 13:20:57 +01:00
|
|
|
int NumberOfAssignedValues(absl::Span<const int> variables);
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
// Prints the duration of the solving process.
|
2023-06-21 17:31:06 +02:00
|
|
|
void PrintElapsedTime(int64_t time1, int64_t time2);
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
// Prints the solution found by the Hard Solver for feasible instances.
|
2023-06-21 17:31:06 +02:00
|
|
|
void PrintResultsHard(SolutionCollector* collector,
|
2020-10-29 14:25:39 +01:00
|
|
|
const std::vector<IntVar*>& variables,
|
2023-06-21 17:31:06 +02:00
|
|
|
IntVar* objective_var,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, FapVariable>& data_variables,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const FapConstraint> data_constraints,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, int>& index_from_key,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const int> key_from_index);
|
2012-09-13 16:25:28 +00:00
|
|
|
|
|
|
|
|
// Prints the solution found by the Soft Solver for unfeasible instances.
|
2023-06-21 17:31:06 +02:00
|
|
|
void PrintResultsSoft(SolutionCollector* collector,
|
|
|
|
|
const std::vector<IntVar*>& variables, IntVar* total_cost,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, FapVariable>& hard_variables,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const FapConstraint> hard_constraints,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, FapVariable>& soft_variables,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const FapConstraint> soft_constraints,
|
2023-02-01 14:14:30 +01:00
|
|
|
const absl::btree_map<int, int>& index_from_key,
|
2025-01-06 13:20:57 +01:00
|
|
|
absl::Span<const int> key_from_index);
|
2018-11-23 08:52:59 +01:00
|
|
|
|
2020-10-22 23:36:58 +02:00
|
|
|
} // namespace operations_research
|
|
|
|
|
#endif // OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_
|