This commit is contained in:
Laurent Perron
2018-07-10 16:40:12 -07:00
parent ef5a2a2775
commit 8300076c71
2 changed files with 9 additions and 6 deletions

View File

@@ -187,6 +187,8 @@ CpModelProto ConstraintGraphNeighborhoodGenerator::Generate(
const int num_active_vars = helper_.ActiveVariables().size();
const int num_model_vars = helper_.ModelProto().variables_size();
const int target_size = std::ceil(difficulty * num_active_vars);
const int num_constraints = helper_.ConstraintToVar().size();
if (num_constraints == 0) return helper_.ModelProto();
if (target_size == num_active_vars) return helper_.ModelProto();
CHECK_GT(target_size, 0);
@@ -195,13 +197,12 @@ CpModelProto ConstraintGraphNeighborhoodGenerator::Generate(
std::vector<bool> visited_variables_set(num_model_vars, false);
std::vector<int> relaxed_variables;
std::vector<bool> added_constraints(helper_.ConstraintToVar().size(), false);
std::vector<bool> added_constraints(num_constraints, false);
std::vector<int> next_constraints;
// Start by a random constraint.
{
std::uniform_int_distribution<int> random_start(
0, helper_.ConstraintToVar().size() - 1);
std::uniform_int_distribution<int> random_start(0, num_constraints - 1);
next_constraints.push_back(random_start(random));
added_constraints[next_constraints.back()] = true;
}
@@ -221,7 +222,7 @@ CpModelProto ConstraintGraphNeighborhoodGenerator::Generate(
// Add all the variable of this constraint and increase the set of next
// possible constraints.
CHECK_LT(contraint_index, helper_.ConstraintToVar().size());
CHECK_LT(contraint_index, num_constraints);
random_variables = helper_.ConstraintToVar()[contraint_index];
std::shuffle(random_variables.begin(), random_variables.end(), random);
for (const int var : random_variables) {

View File

@@ -14,6 +14,8 @@
#ifndef OR_TOOLS_SAT_LNS_H_
#define OR_TOOLS_SAT_LNS_H_
#include <cmath>
#include <cstdint>
#include <functional>
#include <vector>
@@ -77,7 +79,7 @@ class AdaptiveParameterValue {
}
double value_;
int64 num_changes_ = 0;
int64_t num_changes_ = 0;
};
// ============================================================================
@@ -88,7 +90,7 @@ template <class StopFunction, class SolveNeighborhoodFunction>
inline void OptimizeWithLNS(
int num_threads, StopFunction stop_function,
SolveNeighborhoodFunction generate_and_solve_function) {
int64 seed = 0;
int64_t seed = 0;
#if !defined(__PORTABLE_PLATFORM__)
while (!stop_function()) {
if (num_threads > 1) {