dotnet: Remove reference to dotnet release command

- Currently not implemented...

Add abseil patch

- Add patches/absl-config.cmake

Makefile: Add abseil-cpp on unix

- Force abseil-cpp SHA1 to 45221cc
  note: Just before the PR #136 which break all CMake

Makefile: Add abseil-cpp on windows

- Force abseil-cpp SHA1 to 45221cc
  note: Just before the PR #136 which break all CMake

CMake: Add abseil-cpp

- Force abseil-cpp SHA1 to 45221cc
  note: Just before the PR #136 which break all CMake

port to absl: C++ Part

- Fix warning with the use of ABSL_MUST_USE_RESULT
  > The macro must appear as the very first part of a function
    declaration or definition:
    ...
    Note: past advice was to place the macro after the argument list.
  src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418
- Rename enum after windows clash
- Remove non compact table constraints
- Change index type from int64 to int in routing library
- Fix file_nonport compilation on windows
- Fix another naming conflict with windows (NO_ERROR is a macro)
- Cleanup hash containers; work on sat internals
- Add optional_boolean sub-proto

Sync cpp examples with internal code
- reenable issue173 after reducing number of loops

port to absl: Python Part

- Add back cp_model.INT32_MIN|MAX for examples

Update Python examples

- Add random_tsp.py
- Run words_square example
- Run magic_square in python tests

port to absl: Java Part

- Fix compilation of the new routing parameters in java
- Protect some code from SWIG parsing

Update Java Examples

port to absl: .Net Part

Update .Net examples

work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code

Remove VS 2015 in Appveyor-CI

- abseil-cpp does not support VS 2015...

improve tables

upgrade C++ sat examples to use the new API; work on sat internals

update license dates

rewrite jobshop_ft06_distance.py to use the CP-SAT solver

rename last example

revert last commit

more work on SAT internals

fix
This commit is contained in:
Corentin Le Molgat
2018-10-31 16:18:18 +01:00
parent 745906cb7c
commit b027e57e95
490 changed files with 92044 additions and 24779 deletions

View File

@@ -27,15 +27,17 @@
#include <memory>
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/callback.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/integral_types.h"
#include "ortools/base/join.h"
#include "ortools/base/random.h"
#include "ortools/constraint_solver/routing.h"
#include "ortools/constraint_solver/routing_enums.pb.h"
#include "ortools/constraint_solver/routing_flags.h"
#include "ortools/constraint_solver/routing_index_manager.h"
#include "ortools/constraint_solver/routing_parameters.h"
#include "ortools/constraint_solver/routing_parameters.pb.h"
DEFINE_int32(tsp_size, 10, "Size of Traveling Salesman Problem instance.");
DEFINE_bool(tsp_use_random_matrix, true, "Use random cost matrix.");
@@ -43,6 +45,13 @@ DEFINE_int32(tsp_random_forbidden_connections, 0,
"Number of random forbidden connections.");
DEFINE_bool(tsp_use_deterministic_random_seed, false,
"Use deterministic random seeds.");
DEFINE_string(routing_search_parameters,
"local_search_operators {"
" use_path_lns:BOOL_TRUE"
" use_inactive_lns:BOOL_TRUE"
"}",
"Text proto RoutingSearchParameters (possibly partial) that will "
"override the DefaultRoutingSearchParameters()");
namespace operations_research {
@@ -58,7 +67,8 @@ int32 GetSeed() {
// Cost/distance functions.
// Sample function.
int64 MyDistance(RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) {
int64 MyDistance(RoutingIndexManager::NodeIndex from,
RoutingIndexManager::NodeIndex to) {
// Put your distance code here.
return (from + to).value(); // for instance
}
@@ -68,13 +78,11 @@ class RandomMatrix {
public:
explicit RandomMatrix(int size) : size_(size) {}
void Initialize() {
matrix_.reset(new int64[size_ * size_]);
matrix_ = absl::make_unique<int64[]>(size_ * size_);
const int64 kDistanceMax = 100;
ACMRandom randomizer(GetSeed());
for (RoutingModel::NodeIndex from = RoutingModel::kFirstNode; from < size_;
++from) {
for (RoutingModel::NodeIndex to = RoutingModel::kFirstNode; to < size_;
++to) {
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);
} else {
@@ -83,14 +91,14 @@ class RandomMatrix {
}
}
}
int64 Distance(RoutingModel::NodeIndex from,
RoutingModel::NodeIndex to) const {
int64 Distance(RoutingIndexManager::NodeIndex from,
RoutingIndexManager::NodeIndex to) const {
return matrix_[MatrixIndex(from, to)];
}
private:
int64 MatrixIndex(RoutingModel::NodeIndex from,
RoutingModel::NodeIndex to) const {
int64 MatrixIndex(RoutingIndexManager::NodeIndex from,
RoutingIndexManager::NodeIndex to) const {
return (from * size_ + to).value();
}
std::unique_ptr<int64[]> matrix_;
@@ -103,11 +111,12 @@ void Tsp() {
// Second argument = 1 to build a single tour (it's a TSP).
// Nodes are indexed from 0 to FLAGS_tsp_size - 1, by default the start of
// the route is node 0.
RoutingModel routing(FLAGS_tsp_size, 1, RoutingModel::NodeIndex(0));
RoutingSearchParameters parameters = BuildSearchParametersFromFlags();
// Setting first solution heuristic (cheapest addition).
parameters.set_first_solution_strategy(
FirstSolutionStrategy::PATH_CHEAPEST_ARC);
RoutingIndexManager manager(FLAGS_tsp_size, 1,
RoutingIndexManager::NodeIndex(0));
RoutingModel routing(manager);
RoutingSearchParameters parameters = DefaultRoutingSearchParameters();
CHECK(google::protobuf::TextFormat::MergeFromString(
FLAGS_routing_search_parameters, &parameters));
// Setting the cost function.
// Put a permanent callback to the distance accessor here. The callback
@@ -116,11 +125,18 @@ void Tsp() {
RandomMatrix matrix(FLAGS_tsp_size);
if (FLAGS_tsp_use_random_matrix) {
matrix.Initialize();
routing.SetArcCostEvaluatorOfAllVehicles(
NewPermanentCallback(&matrix, &RandomMatrix::Distance));
const int vehicle_cost = routing.RegisterTransitCallback(
[&matrix, &manager](int64 i, int64 j) {
return matrix.Distance(manager.IndexToNode(i),
manager.IndexToNode(j));
});
routing.SetArcCostEvaluatorOfAllVehicles(vehicle_cost);
} else {
routing.SetArcCostEvaluatorOfAllVehicles(
NewPermanentCallback(MyDistance));
const int vehicle_cost =
routing.RegisterTransitCallback([&manager](int64 i, int64 j) {
return MyDistance(manager.IndexToNode(i), manager.IndexToNode(j));
});
routing.SetArcCostEvaluatorOfAllVehicles(vehicle_cost);
}
// Forbid node connections (randomly).
ACMRandom randomizer(GetSeed());
@@ -145,11 +161,11 @@ void Tsp() {
std::string route;
for (int64 node = routing.Start(route_number); !routing.IsEnd(node);
node = solution->Value(routing.NextVar(node))) {
absl::StrAppend(&route, routing.IndexToNode(node).value(), " (", node,
absl::StrAppend(&route, manager.IndexToNode(node).value(), " (", node,
") -> ");
}
const int64 end = routing.End(route_number);
absl::StrAppend(&route, routing.IndexToNode(end).value(), " (", end, ")");
absl::StrAppend(&route, manager.IndexToNode(end).value(), " (", end, ")");
LOG(INFO) << route;
} else {
LOG(INFO) << "No solution found.";