reorganize routing flags, remove redundant trail compression flag

This commit is contained in:
Laurent Perron
2016-10-12 12:04:32 -07:00
parent 592e4878ca
commit cc76b0b63a
6 changed files with 41 additions and 47 deletions

View File

@@ -75,6 +75,9 @@ DEFINE_bool(cp_use_cumulative_edge_finder, true,
"Resources in O(kn log n)' by Petr Vilim, CP 2009.");
DEFINE_bool(cp_use_cumulative_time_table, true,
"Use a O(n^2) cumulative time table propagation algorithm.");
DEFINE_bool(cp_use_cumulative_time_table_sync, false,
"Use a synchronized O(n^2 log n) cumulative time table propagation "
"algorithm.");
DEFINE_bool(cp_use_sequence_high_demand_tasks, true,
"Use a sequence constraints for cumulative tasks that have a "
"demand greater than half of the capacity of the resource.");
@@ -139,6 +142,8 @@ ConstraintSolverParameters Solver::DefaultSolverParameters() {
params.set_use_mdd_table(FLAGS_cp_use_mdd_table);
params.set_use_cumulative_edge_finder(FLAGS_cp_use_cumulative_edge_finder);
params.set_use_cumulative_time_table(FLAGS_cp_use_cumulative_time_table);
params.set_use_cumulative_time_table_sync(
FLAGS_cp_use_cumulative_time_table_sync);
params.set_use_sequence_high_demand_tasks(
FLAGS_cp_use_sequence_high_demand_tasks);
params.set_use_all_possible_disjunctions(
@@ -1085,11 +1090,11 @@ class Search {
#define CP_DO_FAIL(search) longjmp(search->fail_buffer_, 1)
#else // CP_USE_EXCEPTIONS_FOR_BACKTRACK
class FailException {};
#define CP_TRY(search) \
CHECK(!search->jmpbuf_filled_) << "Fail() called outside search"; \
search->jmpbuf_filled_ = true; \
#define CP_TRY(search) \
CHECK(!search->jmpbuf_filled_) << "Fail() called outside search"; \
search->jmpbuf_filled_ = true; \
try
#define CP_ON_FAIL catch(FailException&)
#define CP_ON_FAIL catch (FailException&)
#define CP_DO_FAIL(search) throw FailException()
#endif // CP_USE_EXCEPTIONS_FOR_BACKTRACK

View File

@@ -59,13 +59,6 @@ DEFINE_int64(sweep_sectors, 1,
"The number of sectors the space is divided before it is sweeped "
"by the ray.");
// Cache settings.
// TODO(user): Investigate if these settings could be moved to
// RoutingSearchParameters or if we can get rid of them entirely.
DEFINE_bool(routing_cache_callbacks, false, "Cache callback calls.");
DEFINE_int64(routing_max_cache_size, 1000,
"Maximum cache size when callback caching is on.");
// Trace settings
// TODO(user): Move most of the following settings to a model parameter
@@ -1029,19 +1022,6 @@ class ConstantEvaluator : public BaseObject {
private:
const T value_;
};
ConstraintSolverParameters::TrailCompression GetTrailCompression(
RoutingModelParameters::TrailCompression trail_compression) {
switch (trail_compression) {
case RoutingModelParameters::NONE:
return ConstraintSolverParameters::NO_COMPRESSION;
case RoutingModelParameters::ZLIB:
return ConstraintSolverParameters::COMPRESS_WITH_ZLIB;
default:
return ConstraintSolverParameters::NO_COMPRESSION;
}
}
} // namespace
// ----- Routing model -----
@@ -1081,6 +1061,7 @@ RoutingModel::RoutingModel(int nodes, int vehicles,
cost_classes_(),
costs_are_homogeneous_across_vehicles_(
parameters.reduce_vehicle_cost_model()),
cache_callbacks_(nodes <= parameters.max_callback_cache_size()),
vehicle_class_index_of_vehicle_(vehicles_, VehicleClassIndex(-1)),
starts_(vehicles),
ends_(vehicles),
@@ -1099,8 +1080,6 @@ RoutingModel::RoutingModel(int nodes, int vehicles,
ConstraintSolverParameters solver_parameters =
parameters.has_solver_parameters() ? parameters.solver_parameters()
: Solver::DefaultSolverParameters();
solver_parameters.set_compress_trail(
GetTrailCompression(parameters.trail_compression()));
solver_.reset(new Solver("Routing", solver_parameters));
InitializeBuilders(solver_.get());
CHECK_EQ(vehicles, start_ends.size());
@@ -1133,6 +1112,7 @@ RoutingModel::RoutingModel(int nodes, int vehicles,
cost_classes_(),
costs_are_homogeneous_across_vehicles_(
parameters.reduce_vehicle_cost_model()),
cache_callbacks_(nodes <= parameters.max_callback_cache_size()),
vehicle_class_index_of_vehicle_(vehicles_, VehicleClassIndex(-1)),
starts_(vehicles),
ends_(vehicles),
@@ -1151,8 +1131,6 @@ RoutingModel::RoutingModel(int nodes, int vehicles,
ConstraintSolverParameters solver_parameters =
parameters.has_solver_parameters() ? parameters.solver_parameters()
: Solver::DefaultSolverParameters();
solver_parameters.set_compress_trail(
GetTrailCompression(parameters.trail_compression()));
solver_.reset(new Solver("Routing", solver_parameters));
InitializeBuilders(solver_.get());
CHECK_EQ(vehicles, starts.size());
@@ -1210,13 +1188,13 @@ RoutingModel::~RoutingModel() {
}
RoutingModelParameters RoutingModel::DefaultModelParameters() {
static const char* const kModelParameters =
"reduce_vehicle_cost_model: true "
"trail_compression: ZLIB";
RoutingModelParameters parameters;
if (!google::protobuf::TextFormat::ParseFromString(kModelParameters, &parameters)) {
LOG(ERROR) << "Unsupported default model parameters: " << kModelParameters;
}
ConstraintSolverParameters* const solver_parameters =
parameters.mutable_solver_parameters();
*solver_parameters = Solver::DefaultSolverParameters();
solver_parameters->set_compress_trail(
ConstraintSolverParameters::COMPRESS_WITH_ZLIB);
parameters.set_reduce_vehicle_cost_model(true);
return parameters;
}
@@ -4880,7 +4858,7 @@ void RoutingModel::AddIntervalToAssignment(IntervalVar* const interval) {
RoutingModel::NodeEvaluator2* RoutingModel::NewCachedCallback(
NodeEvaluator2* callback) {
const int size = node_to_index_.size();
if (FLAGS_routing_cache_callbacks && size <= FLAGS_routing_max_cache_size) {
if (cache_callbacks_) {
NodeEvaluator2* cached_evaluator = nullptr;
if (!FindCopy(cached_node_callbacks_, callback, &cached_evaluator)) {
cached_evaluator = new RoutingCache(callback, size);

View File

@@ -1231,6 +1231,7 @@ class RoutingModel {
ITIVector<CostClassIndex, CostClass> cost_classes_;
#endif // SWIG
bool costs_are_homogeneous_across_vehicles_;
bool cache_callbacks_;
std::vector<CostCacheElement> cost_cache_; // Index by source index.
std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
#ifndef SWIG

View File

@@ -17,6 +17,7 @@
#include <vector>
#include "base/map_util.h"
#include "constraint_solver/constraint_solver.h"
// --- Routing search flags ---
@@ -78,6 +79,11 @@ DEFINE_int64(routing_optimization_step, 1, "Optimization step.");
DEFINE_bool(routing_use_light_propagation, true,
"Use constraints with light propagation in routing model.");
// Cache settings.
DEFINE_bool(routing_cache_callbacks, false, "Cache callback calls.");
DEFINE_int64(routing_max_cache_size, 1000,
"Maximum cache size when callback caching is on.");
// Misc
DEFINE_bool(routing_fingerprint_arc_cost_evaluators, true,
"Compare arc-cost evaluators using the fingerprint of their "
@@ -197,7 +203,13 @@ RoutingSearchParameters BuildSearchParametersFromFlags() {
RoutingModelParameters BuildModelParametersFromFlags() {
RoutingModelParameters parameters;
ConstraintSolverParameters* const solver_parameters =
parameters.mutable_solver_parameters();
*solver_parameters = Solver::DefaultSolverParameters();
parameters.set_reduce_vehicle_cost_model(FLAGS_routing_use_homogeneous_costs);
if (FLAGS_routing_cache_callbacks) {
parameters.set_max_callback_cache_size(FLAGS_routing_max_cache_size);
}
return parameters;
}
} // namespace operations_research

View File

@@ -57,6 +57,10 @@ DECLARE_int64(routing_optimization_step);
// Propagation control
DECLARE_bool(routing_use_light_propagation);
// Cache settings.
DECLARE_bool(routing_cache_callbacks);
DECLARE_int64(routing_max_cache_size);
// Misc
DECLARE_bool(routing_fingerprint_arc_cost_evaluators);
DECLARE_bool(routing_trace);

View File

@@ -262,20 +262,14 @@ message RoutingSearchParameters {
// Parameters which have to be set when creating a RoutingModel.
message RoutingModelParameters {
// Parameters to use in the underlying constraint solver.
ConstraintSolverParameters solver_parameters = 1;
// Advanced settings.
// If set to true reduction of the underlying constraint model will be
// attempted when all vehicles have exactly the same cost structure. This can
// result in significant speedups.
bool reduce_vehicle_cost_model = 1;
// Algorithm to use to compress the constraint solver trail.
// TODO(user): This field is obsolete as it is redudant with the
// solver_parameters field which contains trail compression settings.
// Remove it.
enum TrailCompression {
NONE = 0;
ZLIB = 1;
}
TrailCompression trail_compression = 2;
// Parameters to use in the underlying constraint solver.
ConstraintSolverParameters solver_parameters = 3;
bool reduce_vehicle_cost_model = 2;
// Cache callback calls if the number of nodes in the model is less or equal
// to this value.
int32 max_callback_cache_size = 3;
}