update examples

This commit is contained in:
Corentin Le Molgat
2021-04-02 14:58:16 +02:00
parent 7a4f8e242c
commit baf02eca7e
33 changed files with 381 additions and 380 deletions

View File

@@ -332,12 +332,12 @@ bool ConstraintImpactComparator(FapConstraint constraint1,
return (constraint1.impact > constraint2.impact);
}
int64 ValueEvaluator(
absl::flat_hash_map<int64, std::pair<int64, int64>>* value_evaluator_map,
int64 variable_index, int64 value) {
int64_t ValueEvaluator(
absl::flat_hash_map<int64_t, std::pair<int64_t, int64_t>>* value_evaluator_map,
int64_t variable_index, int64_t value) {
CHECK(value_evaluator_map != nullptr);
// Evaluate the choice. Smaller ranking denotes a better choice.
int64 ranking = -1;
int64_t ranking = -1;
for (const auto& it : *value_evaluator_map) {
if ((it.first != variable_index) && (it.second.first == value)) {
ranking = -2;
@@ -346,12 +346,12 @@ int64 ValueEvaluator(
}
// Update the history of assigned values and their rankings of each variable.
absl::flat_hash_map<int64, std::pair<int64, int64>>::iterator it;
int64 new_value = value;
int64 new_ranking = ranking;
absl::flat_hash_map<int64_t, std::pair<int64_t, int64_t>>::iterator it;
int64_t new_value = value;
int64_t new_ranking = ranking;
if ((it = value_evaluator_map->find(variable_index)) !=
value_evaluator_map->end()) {
std::pair<int64, int64> existing_value_ranking = it->second;
std::pair<int64_t, int64_t> existing_value_ranking = it->second;
// Replace only if the current choice for this variable has smaller
// ranking or same ranking but smaller value of the existing choice.
if (!(existing_value_ranking.second > ranking ||
@@ -361,7 +361,7 @@ int64 ValueEvaluator(
new_ranking = existing_value_ranking.second;
}
}
std::pair<int64, int64> new_value_ranking =
std::pair<int64_t, int64_t> new_value_ranking =
std::make_pair(new_value, new_ranking);
gtl::InsertOrUpdate(value_evaluator_map, variable_index, new_value_ranking);
@@ -370,12 +370,12 @@ int64 ValueEvaluator(
// The variables which participate in more constraints and have the
// smaller domain should be in higher priority for assignment.
int64 VariableEvaluator(const std::vector<int>& key_from_index,
int64_t VariableEvaluator(const std::vector<int>& key_from_index,
const std::map<int, FapVariable>& data_variables,
int64 variable_index) {
int64_t variable_index) {
FapVariable variable =
gtl::FindOrDie(data_variables, key_from_index[variable_index]);
int64 result = -(variable.degree * 100 / variable.domain_size);
int64_t result = -(variable.degree * 100 / variable.domain_size);
return result;
}
@@ -583,11 +583,11 @@ void HardFapSolver(const std::map<int, FapVariable>& data_variables,
ChooseVariableStrategy(&variable_strategy);
// Choose the value selection strategy.
DecisionBuilder* db;
absl::flat_hash_map<int64, std::pair<int64, int64>> history;
absl::flat_hash_map<int64_t, std::pair<int64_t, int64_t>> history;
if (absl::GetFlag(FLAGS_value_evaluator) == "value_evaluator") {
LOG(INFO) << "Using ValueEvaluator for value selection strategy.";
Solver::IndexEvaluator2 index_evaluator2 = [&history](int64 var,
int64 value) {
Solver::IndexEvaluator2 index_evaluator2 = [&history](int64_t var,
int64_t value) {
return ValueEvaluator(&history, var, value);
};
LOG(INFO) << "Using ValueEvaluator for value selection strategy.";
@@ -611,9 +611,9 @@ void HardFapSolver(const std::map<int, FapVariable>& data_variables,
// Solve.
LOG(INFO) << "Solving...";
const int64 time1 = solver.wall_time();
const int64_t time1 = solver.wall_time();
solver.Solve(final_db, monitors);
const int64 time2 = solver.wall_time();
const int64_t time2 = solver.wall_time();
// Display Time.
if (absl::GetFlag(FLAGS_display_time)) {
@@ -785,7 +785,7 @@ int SoftFapSolver(const std::map<int, FapVariable>& data_variables,
LOG(INFO) << "Using VariableEvaluator for variable selection strategy and "
"Solver::ASSIGN_MIN_VALUE for value selection strategy.";
Solver::IndexEvaluator1 var_evaluator = [&key_from_index,
&data_variables](int64 index) {
&data_variables](int64_t index) {
return VariableEvaluator(key_from_index, data_variables, index);
};
db = solver.MakePhase(variables, var_evaluator, Solver::ASSIGN_MIN_VALUE);
@@ -809,9 +809,9 @@ int SoftFapSolver(const std::map<int, FapVariable>& data_variables,
// Solve.
LOG(INFO) << "Solving...";
const int64 time1 = solver.wall_time();
const int64_t time1 = solver.wall_time();
solver.Solve(final_db, monitors);
const int64 time2 = solver.wall_time();
const int64_t time2 = solver.wall_time();
int violation_sum =
collector->Value(collector->solution_count() - 1, objective_var);