Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cvrptw_lib.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// This header provides functions to help create random instances of the
15// vehicle routing problem; random capacities and random time windows.
16#ifndef OR_TOOLS_ROUTING_PARSERS_CVRPTW_LIB_H_
17#define OR_TOOLS_ROUTING_PARSERS_CVRPTW_LIB_H_
18
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <random>
23
26
27namespace operations_research {
28
29typedef std::function<int64_t(RoutingNodeIndex, RoutingNodeIndex)>
31
32// Random seed generator.
33int32_t GetSeed(bool deterministic);
34
35// Location container, contains positions of orders and can be used to obtain
36// Manhattan distances/times between locations.
38 public:
39 LocationContainer(int64_t speed, bool use_deterministic_seed);
40 void AddLocation(int64_t x, int64_t y) {
41 locations_.push_back(Location(x, y));
42 }
43 void AddRandomLocation(int64_t x_max, int64_t y_max);
44 void AddRandomLocation(int64_t x_max, int64_t y_max, int duplicates);
51
54 int64_t SameLocationFromIndex(int64_t node1, int64_t node2) const;
55
56 private:
57 class Location {
58 public:
59 Location();
60 Location(int64_t x, int64_t y);
61 int64_t DistanceTo(const Location& location) const;
62 bool IsAtSameLocation(const Location& location) const;
63
64 private:
65 static int64_t Abs(int64_t value);
66
67 int64_t x_;
68 int64_t y_;
69 };
70
71 std::mt19937 randomizer_;
72 const int64_t speed_;
74};
75
76// Random demand.
78 public:
80 bool use_deterministic_seed);
81 void Initialize();
84
85 private:
86 std::unique_ptr<int64_t[]> demand_;
87 const int size_;
89 const bool use_deterministic_seed_;
90};
91
92// Service time (proportional to demand) + transition time callback.
94 public:
96 int64_t time_per_demand_unit,
101
102 private:
103 const int64_t time_per_demand_unit_;
106};
107
108// Stop service time + transition time callback.
110 public:
112 int64_t stop_time, const LocationContainer& location_container,
116
117 private:
118 const int64_t stop_time_;
119 const LocationContainer& location_container_;
122};
123
124// Route plan displayer.
125// TODO(user): Move the display code to the routing library.
128 const operations_research::RoutingModel& routing,
129 const operations_research::Assignment& plan, bool use_same_vehicle_costs,
130 int64_t max_nodes_per_group, int64_t same_vehicle_cost,
131 const operations_research::RoutingDimension& capacity_dimension,
132 const operations_research::RoutingDimension& time_dimension);
133
134} // namespace operations_research
135
136#endif // OR_TOOLS_ROUTING_PARSERS_CVRPTW_LIB_H_
IntegerValue y
IntegerValue size
int64_t ManhattanDistance(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
Definition cvrptw_lib.cc:62
void AddRandomLocation(int64_t x_max, int64_t y_max)
Definition cvrptw_lib.cc:49
int64_t ManhattanTime(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
Definition cvrptw_lib.cc:72
bool SameLocation(RoutingIndexManager::NodeIndex node1, RoutingIndexManager::NodeIndex node2) const
Definition cvrptw_lib.cc:76
void AddLocation(int64_t x, int64_t y)
Definition cvrptw_lib.h:40
LocationContainer(int64_t speed, bool use_deterministic_seed)
Definition cvrptw_lib.cc:44
int64_t NegManhattanDistance(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
Definition cvrptw_lib.cc:67
int64_t SameLocationFromIndex(int64_t node1, int64_t node2) const
Definition cvrptw_lib.cc:82
int64_t Demand(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
RandomDemand(int size, RoutingIndexManager::NodeIndex depot, bool use_deterministic_seed)
Service time (proportional to demand) + transition time callback.
Definition cvrptw_lib.h:93
ServiceTimePlusTransition(int64_t time_per_demand_unit, operations_research::RoutingNodeEvaluator2 demand, operations_research::RoutingNodeEvaluator2 transition_time)
int64_t Compute(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
Stop service time + transition time callback.
Definition cvrptw_lib.h:109
StopServiceTimePlusTransition(int64_t stop_time, const LocationContainer &location_container, operations_research::RoutingNodeEvaluator2 transition_time)
int64_t Compute(RoutingIndexManager::NodeIndex from, RoutingIndexManager::NodeIndex to) const
void push_back(const value_type &val)
int64_t value
In SWIG mode, we don't want anything besides these top-level includes.
int32_t GetSeed(bool deterministic)
Random seed generator.
Definition cvrptw_lib.cc:35
std::function< int64_t(RoutingNodeIndex, RoutingNodeIndex)> RoutingNodeEvaluator2
Definition cvrptw_lib.h:30
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)
trees with all degrees equal to
const Variable x
Definition qp_tests.cc:127
int64_t demand
Definition resource.cc:126