remove ortools/base/random.h|cc; adapt code everywhere; increase robustness of glop preprocessor
This commit is contained in:
@@ -28,15 +28,16 @@
|
||||
#include <memory>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/integral_types.h"
|
||||
#include "ortools/base/random.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.pb.h"
|
||||
#include "ortools/util/random_engine.h"
|
||||
|
||||
ABSL_FLAG(int, tsp_size, 10, "Size of Traveling Salesman Problem instance.");
|
||||
ABSL_FLAG(bool, tsp_use_random_matrix, true, "Use random cost matrix.");
|
||||
@@ -57,9 +58,9 @@ namespace operations_research {
|
||||
// Random seed generator.
|
||||
int32_t GetSeed() {
|
||||
if (absl::GetFlag(FLAGS_tsp_use_deterministic_random_seed)) {
|
||||
return ACMRandom::DeterministicSeed();
|
||||
return 0;
|
||||
} else {
|
||||
return ACMRandom::HostnamePidTimeSeed();
|
||||
return std::random_device()();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,11 +80,11 @@ class RandomMatrix {
|
||||
void Initialize() {
|
||||
matrix_ = absl::make_unique<int64_t[]>(size_ * size_);
|
||||
const int64_t kDistanceMax = 100;
|
||||
ACMRandom randomizer(GetSeed());
|
||||
random_engine_t randomizer(GetSeed());
|
||||
for (RoutingIndexManager::NodeIndex from(0); from < size_; ++from) {
|
||||
for (RoutingIndexManager::NodeIndex to(0); to < size_; ++to) {
|
||||
if (to != from) {
|
||||
matrix_[MatrixIndex(from, to)] = randomizer.Uniform(kDistanceMax);
|
||||
matrix_[MatrixIndex(from, to)] = absl::Uniform(randomizer, 0, kDistanceMax);
|
||||
} else {
|
||||
matrix_[MatrixIndex(from, to)] = 0LL;
|
||||
}
|
||||
@@ -139,13 +140,13 @@ void Tsp() {
|
||||
routing.SetArcCostEvaluatorOfAllVehicles(vehicle_cost);
|
||||
}
|
||||
// Forbid node connections (randomly).
|
||||
ACMRandom randomizer(GetSeed());
|
||||
random_engine_t randomizer(GetSeed());
|
||||
int64_t forbidden_connections = 0;
|
||||
while (forbidden_connections <
|
||||
absl::GetFlag(FLAGS_tsp_random_forbidden_connections)) {
|
||||
const int64_t from = randomizer.Uniform(absl::GetFlag(FLAGS_tsp_size) - 1);
|
||||
const int64_t from = absl::Uniform(randomizer, 0, absl::GetFlag(FLAGS_tsp_size) - 1);
|
||||
const int64_t to =
|
||||
randomizer.Uniform(absl::GetFlag(FLAGS_tsp_size) - 1) + 1;
|
||||
absl::Uniform(randomizer, 0 , absl::GetFlag(FLAGS_tsp_size) - 1) + 1;
|
||||
if (routing.NextVar(from)->Contains(to)) {
|
||||
LOG(INFO) << "Forbidding connection " << from << " -> " << to;
|
||||
routing.NextVar(from)->RemoveValue(to);
|
||||
|
||||
Reference in New Issue
Block a user