Files
ortools-clone/examples/cpp/fap_utilities.h

72 lines
3.0 KiB
C
Raw Normal View History

// 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>
#include "absl/container/btree_map.h"
2025-01-06 13:20:57 +01:00
#include "absl/types/span.h"
#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.
bool CheckConstraintSatisfaction(
2025-01-06 13:20:57 +01:00
absl::Span<const FapConstraint> data_constraints,
absl::Span<const int> variables,
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.
bool CheckVariablePosition(
const absl::btree_map<int, FapVariable>& data_variables,
2025-01-06 13:20:57 +01:00
absl::Span<const int> variables,
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.
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.
void PrintResultsHard(SolutionCollector* collector,
2020-10-29 14:25:39 +01:00
const std::vector<IntVar*>& variables,
IntVar* objective_var,
const absl::btree_map<int, FapVariable>& data_variables,
2025-01-06 13:20:57 +01:00
absl::Span<const FapConstraint> data_constraints,
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.
void PrintResultsSoft(SolutionCollector* collector,
const std::vector<IntVar*>& variables, IntVar* total_cost,
const absl::btree_map<int, FapVariable>& hard_variables,
2025-01-06 13:20:57 +01:00
absl::Span<const FapConstraint> hard_constraints,
const absl::btree_map<int, FapVariable>& soft_variables,
2025-01-06 13:20:57 +01:00
absl::Span<const FapConstraint> soft_constraints,
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_