backport fixup from main
This commit is contained in:
5
go.mod
5
go.mod
@@ -3,7 +3,6 @@ module github.com/google/or-tools
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
github.com/golang/glog v1.2.4
|
||||
github.com/google/go-cmp v0.6.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
github.com/golang/glog v1.2.4
|
||||
google.golang.org/protobuf v1.36.5
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -4,3 +4,5 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
|
||||
@@ -430,6 +430,7 @@ cc_test(
|
||||
deps = [
|
||||
":n_choose_k",
|
||||
"//ortools/base:dump_vars",
|
||||
"//ortools/base:fuzztest",
|
||||
"//ortools/base:gmock_main",
|
||||
"//ortools/base:mathutil",
|
||||
"//ortools/util:flat_matrix",
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
|
||||
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
|
||||
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
|
||||
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_python//python:defs.bzl", "py_library")
|
||||
load("@rules_python//python:proto.bzl", "py_proto_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
@@ -188,6 +188,7 @@ cc_library(
|
||||
":solver_parameters_cc_proto",
|
||||
":routing_parameters_cc_proto",
|
||||
"//ortools/base",
|
||||
"//ortools/base:base_export",
|
||||
"//ortools/base:bitmap",
|
||||
"//ortools/base:file",
|
||||
"//ortools/base:int_type",
|
||||
|
||||
@@ -22,7 +22,6 @@ This problem has 72 different solutions in base 10.
|
||||
"""
|
||||
# [START import]
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
|
||||
# [END import]
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# [START import]
|
||||
import sys
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
|
||||
# [END import]
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
# [START import]
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
|
||||
# [END import]
|
||||
|
||||
|
||||
|
||||
@@ -18,13 +18,18 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/btree_set.h"
|
||||
#include "absl/random/distributions.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
|
||||
@@ -157,12 +162,17 @@ int64_t StopServiceTimePlusTransition::Compute(NodeIndex from,
|
||||
: stop_time_ + transition_time_(from, to);
|
||||
}
|
||||
|
||||
void DisplayPlan(
|
||||
const RoutingIndexManager& manager, const RoutingModel& routing,
|
||||
const operations_research::Assignment& plan, bool use_same_vehicle_costs,
|
||||
int64_t max_nodes_per_group, int64_t same_vehicle_cost,
|
||||
const operations_research::RoutingDimension& capacity_dimension,
|
||||
const operations_research::RoutingDimension& time_dimension) {
|
||||
void DisplayPlan(const RoutingIndexManager& manager,
|
||||
const RoutingModel& routing,
|
||||
const operations_research::Assignment& plan,
|
||||
bool use_same_vehicle_costs, int64_t max_nodes_per_group,
|
||||
int64_t same_vehicle_cost,
|
||||
absl::Span<const std::string> dimension_names) {
|
||||
std::vector<const operations_research::RoutingDimension*> dimensions;
|
||||
for (const std::string& dimension_name : dimension_names) {
|
||||
dimensions.push_back(&routing.GetDimensionOrDie(dimension_name));
|
||||
}
|
||||
|
||||
// Display plan cost.
|
||||
std::string plan_output = absl::StrFormat("Cost %d\n", plan.ObjectiveValue());
|
||||
|
||||
@@ -207,6 +217,18 @@ void DisplayPlan(
|
||||
}
|
||||
|
||||
// Display actual output for each vehicle.
|
||||
const auto str_append_variable =
|
||||
[&plan, &plan_output](const IntVar* var, absl::string_view name) {
|
||||
if (var == nullptr || !plan.Contains(var)) return;
|
||||
const int64_t var_min = plan.Min(var);
|
||||
const int64_t var_max = plan.Max(var);
|
||||
if (var_min == var_max) {
|
||||
absl::StrAppendFormat(&plan_output, "%s(%d) ", name, var_min);
|
||||
} else {
|
||||
absl::StrAppendFormat(&plan_output, "%s(%d, %d) ", name, var_min,
|
||||
var_max);
|
||||
}
|
||||
};
|
||||
for (int route_number = 0; route_number < routing.vehicles();
|
||||
++route_number) {
|
||||
int64_t order = routing.Start(route_number);
|
||||
@@ -215,26 +237,16 @@ void DisplayPlan(
|
||||
plan_output += "Empty\n";
|
||||
} else {
|
||||
while (true) {
|
||||
operations_research::IntVar* const load_var =
|
||||
capacity_dimension.CumulVar(order);
|
||||
operations_research::IntVar* const time_var =
|
||||
time_dimension.CumulVar(order);
|
||||
operations_research::IntVar* const slack_var =
|
||||
routing.IsEnd(order) ? nullptr : time_dimension.SlackVar(order);
|
||||
if (slack_var != nullptr && plan.Contains(slack_var)) {
|
||||
absl::StrAppendFormat(
|
||||
&plan_output, "%d Load(%d) Time(%d, %d) Slack(%d, %d)",
|
||||
manager.IndexToNode(order).value(), plan.Value(load_var),
|
||||
plan.Min(time_var), plan.Max(time_var), plan.Min(slack_var),
|
||||
plan.Max(slack_var));
|
||||
} else {
|
||||
absl::StrAppendFormat(&plan_output, "%d Load(%d) Time(%d, %d)",
|
||||
manager.IndexToNode(order).value(),
|
||||
plan.Value(load_var), plan.Min(time_var),
|
||||
plan.Max(time_var));
|
||||
absl::StrAppendFormat(&plan_output, "%d ",
|
||||
manager.IndexToNode(order).value());
|
||||
for (const operations_research::RoutingDimension* dimension : dimensions) {
|
||||
str_append_variable(dimension->CumulVar(order), dimension->name());
|
||||
operations_research::IntVar* const slack_var =
|
||||
routing.IsEnd(order) ? nullptr : dimension->SlackVar(order);
|
||||
str_append_variable(slack_var, dimension->name() + "Slack");
|
||||
}
|
||||
if (routing.IsEnd(order)) break;
|
||||
plan_output += " -> ";
|
||||
plan_output += "-> ";
|
||||
order = plan.Value(routing.NextVar(order));
|
||||
}
|
||||
plan_output += "\n";
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/span.h"
|
||||
#include "ortools/base/strong_vector.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
|
||||
@@ -128,8 +131,7 @@ void DisplayPlan(
|
||||
const operations_research::RoutingModel& routing,
|
||||
const operations_research::Assignment& plan, bool use_same_vehicle_costs,
|
||||
int64_t max_nodes_per_group, int64_t same_vehicle_cost,
|
||||
const operations_research::RoutingDimension& capacity_dimension,
|
||||
const operations_research::RoutingDimension& time_dimension);
|
||||
absl::Span<const std::string> dimension_names);
|
||||
|
||||
} // namespace operations_research
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ std::string RoutingSolution::SerializeToNEARPLIBSolutionFile() const {
|
||||
|
||||
namespace {
|
||||
RoutingSolution::Route RouteFromVector(
|
||||
const std::vector<int64_t>& route_int,
|
||||
absl::Span<const int64_t> route_int,
|
||||
std::optional<int64_t> depot = std::nullopt);
|
||||
|
||||
std::vector<RoutingSolution::Route> RoutesFromVector(
|
||||
@@ -355,7 +355,7 @@ std::vector<RoutingSolution::Route> RoutesFromVector(
|
||||
return solution_routes;
|
||||
}
|
||||
|
||||
RoutingSolution::Route RouteFromVector(const std::vector<int64_t>& route_int,
|
||||
RoutingSolution::Route RouteFromVector(absl::Span<const int64_t> route_int,
|
||||
std::optional<int64_t> forced_depot) {
|
||||
// One route in input: from the node indices, create a Route object (not yet
|
||||
// a RoutingSolution one).
|
||||
|
||||
@@ -24,15 +24,19 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -170,12 +174,13 @@ int main(int argc, char** argv) {
|
||||
order < manager.num_nodes(); ++order) {
|
||||
group.push_back(manager.NodeToIndex(order));
|
||||
if (group.size() == kMaxNodesPerGroup) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group),
|
||||
kSameVehicleCost);
|
||||
group.clear();
|
||||
}
|
||||
}
|
||||
if (!group.empty()) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group), kSameVehicleCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,9 +192,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution,
|
||||
absl::GetFlag(FLAGS_vrp_use_same_vehicle_costs),
|
||||
kMaxNodesPerGroup, kSameVehicleCost,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
kMaxNodesPerGroup, kSameVehicleCost, {kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -22,15 +22,19 @@
|
||||
// to be in meters and times in seconds.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -155,12 +159,13 @@ int main(int argc, char** argv) {
|
||||
order < manager.num_nodes(); ++order) {
|
||||
group.push_back(manager.NodeToIndex(order));
|
||||
if (group.size() == kMaxNodesPerGroup) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group),
|
||||
kSameVehicleCost);
|
||||
group.clear();
|
||||
}
|
||||
}
|
||||
if (!group.empty()) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group), kSameVehicleCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,9 +177,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution,
|
||||
absl::GetFlag(FLAGS_vrp_use_same_vehicle_costs),
|
||||
kMaxNodesPerGroup, kSameVehicleCost,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
kMaxNodesPerGroup, kSameVehicleCost, {kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -21,15 +21,19 @@
|
||||
// distance. Distances are assumed to be in meters and times in seconds.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -179,12 +183,13 @@ int main(int argc, char** argv) {
|
||||
order < manager.num_nodes(); ++order) {
|
||||
group.push_back(manager.NodeToIndex(order));
|
||||
if (group.size() == kMaxNodesPerGroup) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group),
|
||||
kSameVehicleCost);
|
||||
group.clear();
|
||||
}
|
||||
}
|
||||
if (!group.empty()) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group), kSameVehicleCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,9 +201,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution,
|
||||
absl::GetFlag(FLAGS_vrp_use_same_vehicle_costs),
|
||||
kMaxNodesPerGroup, kSameVehicleCost,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
kMaxNodesPerGroup, kSameVehicleCost, {kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -26,17 +26,20 @@
|
||||
// day or two smaller ones which can be taken during a longer period of the day.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.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/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_enums.pb.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
@@ -227,9 +230,7 @@ int main(int argc, char** argv) {
|
||||
LOG(INFO) << break_interval.Var()->name() << " unperformed";
|
||||
}
|
||||
}
|
||||
DisplayPlan(manager, routing, *solution, false, 0, 0,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
DisplayPlan(manager, routing, *solution, false, 0, 0, {kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -23,15 +23,17 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -165,12 +167,13 @@ int main(int argc, char** argv) {
|
||||
order < manager.num_nodes(); ++order) {
|
||||
group.push_back(manager.NodeToIndex(order));
|
||||
if (group.size() == kMaxNodesPerGroup) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group),
|
||||
kSameVehicleCost);
|
||||
group.clear();
|
||||
}
|
||||
}
|
||||
if (!group.empty()) {
|
||||
routing.AddSoftSameVehicleConstraint(group, kSameVehicleCost);
|
||||
routing.AddSoftSameVehicleConstraint(std::move(group), kSameVehicleCost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,9 +204,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution,
|
||||
absl::GetFlag(FLAGS_vrp_use_same_vehicle_costs),
|
||||
kMaxNodesPerGroup, kSameVehicleCost,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
kMaxNodesPerGroup, kSameVehicleCost, {kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -20,15 +20,18 @@
|
||||
// reaches zero. Fuel consumption is proportional to the distance traveled.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -46,10 +49,11 @@ using operations_research::RoutingModel;
|
||||
using operations_research::RoutingNodeIndex;
|
||||
using operations_research::RoutingSearchParameters;
|
||||
using operations_research::ServiceTimePlusTransition;
|
||||
using operations_research::Solver;
|
||||
|
||||
ABSL_FLAG(int, vrp_orders, 100, "Nodes in the problem.");
|
||||
ABSL_FLAG(int, vrp_vehicles, 20,
|
||||
"Size of Traveling Salesman Problem instance.");
|
||||
ABSL_FLAG(int, vrp_orders, 20, "Nodes in the problem.");
|
||||
ABSL_FLAG(int, vrp_vehicles, 4,
|
||||
"Size of the Vehicle Routing Problem instance.");
|
||||
ABSL_FLAG(bool, vrp_use_deterministic_random_seed, false,
|
||||
"Use deterministic random seeds.");
|
||||
ABSL_FLAG(std::string, routing_search_parameters, "",
|
||||
@@ -84,6 +88,7 @@ int main(int argc, char** argv) {
|
||||
const int64_t kXMax = 100000;
|
||||
const int64_t kYMax = 100000;
|
||||
const int64_t kSpeed = 10;
|
||||
const int64_t kRefuelCost = 10;
|
||||
LocationContainer locations(
|
||||
kSpeed, absl::GetFlag(FLAGS_vrp_use_deterministic_random_seed));
|
||||
for (int location = 0; location <= absl::GetFlag(FLAGS_vrp_orders);
|
||||
@@ -95,7 +100,8 @@ int main(int argc, char** argv) {
|
||||
const int vehicle_cost = routing.RegisterTransitCallback(
|
||||
[&locations, &manager](int64_t i, int64_t j) {
|
||||
return locations.ManhattanDistance(manager.IndexToNode(i),
|
||||
manager.IndexToNode(j));
|
||||
manager.IndexToNode(j)) +
|
||||
(IsRefuelNode(i) ? kRefuelCost : 0);
|
||||
});
|
||||
routing.SetArcCostEvaluatorOfAllVehicles(vehicle_cost);
|
||||
|
||||
@@ -162,9 +168,21 @@ int main(int argc, char** argv) {
|
||||
// Only let slack free for refueling nodes.
|
||||
if (!IsRefuelNode(order) || routing.IsStart(order)) {
|
||||
fuel_dimension.SlackVar(order)->SetValue(0);
|
||||
} else {
|
||||
// Ensure that we do not refuel more than the capacity.
|
||||
Solver* solver = routing.solver();
|
||||
solver->AddConstraint(solver->MakeSumLessOrEqual(
|
||||
{fuel_dimension.SlackVar(order), fuel_dimension.CumulVar(order)},
|
||||
kFuelCapacity));
|
||||
routing.AddToAssignment(fuel_dimension.SlackVar(order));
|
||||
}
|
||||
// Needed to instantiate fuel quantity at each node.
|
||||
routing.AddVariableMinimizedByFinalizer(fuel_dimension.CumulVar(order));
|
||||
// Needed to instantiate fuel quantity at each node. Deciding to refuel as
|
||||
// much as possible to minimize the risk of running out of fuel.
|
||||
routing.AddVariableMaximizedByFinalizer(fuel_dimension.CumulVar(order));
|
||||
}
|
||||
for (int vehicle = 0; vehicle < routing.vehicles(); ++vehicle) {
|
||||
routing.AddVariableMaximizedByFinalizer(
|
||||
fuel_dimension.CumulVar(routing.End(vehicle)));
|
||||
}
|
||||
|
||||
// Adding penalty costs to allow skipping orders.
|
||||
@@ -173,7 +191,8 @@ int main(int argc, char** argv) {
|
||||
for (RoutingIndexManager::NodeIndex order = kFirstNodeAfterDepot;
|
||||
order < routing.nodes(); ++order) {
|
||||
std::vector<int64_t> orders(1, manager.NodeToIndex(order));
|
||||
routing.AddDisjunction(orders, kPenalty);
|
||||
routing.AddDisjunction(
|
||||
orders, IsRefuelNode(manager.NodeToIndex(order)) ? 0 : kPenalty);
|
||||
}
|
||||
|
||||
// Solve, returns a solution if any (owned by RoutingModel).
|
||||
@@ -184,8 +203,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution, /*use_same_vehicle_costs=*/false,
|
||||
/*max_nodes_per_group=*/0, /*same_vehicle_cost=*/0,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
{kTime, kCapacity, kFuel});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -22,15 +22,18 @@
|
||||
// with variable demands.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -179,8 +182,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution, /*use_same_vehicle_costs=*/false,
|
||||
/*max_nodes_per_group=*/0, /*same_vehicle_cost=*/0,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
{kCapacity, kTime});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -20,16 +20,19 @@
|
||||
// to one.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.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/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -209,8 +212,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution, /*use_same_vehicle_costs=*/false,
|
||||
/*max_nodes_per_group=*/0, /*same_vehicle_cost=*/0,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
{kCapacity, kTime});
|
||||
LOG(INFO) << "Stop intervals:";
|
||||
for (IntervalVar* const interval : intervals) {
|
||||
if (solution->PerformedValue(interval)) {
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/functional/bind_front.h"
|
||||
#include "absl/random/random.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "ortools/base/commandlineflags.h"
|
||||
#include "ortools/base/init_google.h"
|
||||
#include "ortools/base/logging.h"
|
||||
#include "ortools/base/types.h"
|
||||
#include "ortools/constraint_solver/constraint_solver.h"
|
||||
#include "ortools/constraint_solver/routing.h"
|
||||
#include "ortools/constraint_solver/routing_index_manager.h"
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
@@ -239,8 +239,7 @@ int main(int argc, char** argv) {
|
||||
if (solution != nullptr) {
|
||||
DisplayPlan(manager, routing, *solution, /*use_same_vehicle_costs=*/false,
|
||||
/*max_nodes_per_group=*/0, /*same_vehicle_cost=*/0,
|
||||
routing.GetDimensionOrDie(kCapacity),
|
||||
routing.GetDimensionOrDie(kTime));
|
||||
{kCapacity, kTime, kTimeDependentCost});
|
||||
} else {
|
||||
LOG(INFO) << "No solution found.";
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ def create_section_data():
|
||||
'input_files':
|
||||
'ortools/graph/christofides.h ' + 'ortools/graph/cliques.h ' +
|
||||
'ortools/graph/connected_components.h ' +
|
||||
'ortools/graph/connectivity.h ' + 'ortools/graph/ebert_graph.h ' +
|
||||
'ortools/graph/connectivity.h ' +
|
||||
'ortools/graph/eulerian_path.h ' + 'ortools/graph/graph.h ' +
|
||||
'ortools/graph/graphs.h ' + 'ortools/graph/hamiltonian_path.h ' +
|
||||
'ortools/graph/graph_io.h ' + 'ortools/graph/iterators.h ' +
|
||||
|
||||
@@ -191,9 +191,7 @@ for idx, (c_block, s, e) in enumerate(
|
||||
)
|
||||
FULL_TEXT += "\n".join(filtered_lines) + "\n"
|
||||
|
||||
nbook["cells"].append(
|
||||
v4.new_code_cell(source=FULL_TEXT, id="code")
|
||||
)
|
||||
nbook["cells"].append(v4.new_code_cell(source=FULL_TEXT, id="code"))
|
||||
|
||||
jsonform = v4.writes(nbook) + "\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user