From 8300076c7161bdc056489a21c975ec2d31dff6b1 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Tue, 10 Jul 2018 16:40:12 -0700 Subject: [PATCH] cleanup --- ortools/sat/cp_model_lns.cc | 9 +++++---- ortools/sat/lns.h | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ortools/sat/cp_model_lns.cc b/ortools/sat/cp_model_lns.cc index 362c693095..736a007f5c 100644 --- a/ortools/sat/cp_model_lns.cc +++ b/ortools/sat/cp_model_lns.cc @@ -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 visited_variables_set(num_model_vars, false); std::vector relaxed_variables; - std::vector added_constraints(helper_.ConstraintToVar().size(), false); + std::vector added_constraints(num_constraints, false); std::vector next_constraints; // Start by a random constraint. { - std::uniform_int_distribution random_start( - 0, helper_.ConstraintToVar().size() - 1); + std::uniform_int_distribution 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) { diff --git a/ortools/sat/lns.h b/ortools/sat/lns.h index 4ca407e462..f5cbd9b3ca 100644 --- a/ortools/sat/lns.h +++ b/ortools/sat/lns.h @@ -14,6 +14,8 @@ #ifndef OR_TOOLS_SAT_LNS_H_ #define OR_TOOLS_SAT_LNS_H_ +#include +#include #include #include @@ -77,7 +79,7 @@ class AdaptiveParameterValue { } double value_; - int64 num_changes_ = 0; + int64_t num_changes_ = 0; }; // ============================================================================ @@ -88,7 +90,7 @@ template 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) {