OR-Tools  9.6
tsptw_parser.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 // A TSPTW parser.
15 //
16 // Takes as input a data file, potentially gzipped. The data must
17 // follow the format described at
18 // http://lopez-ibanez.eu/tsptw-instances and
19 // https://homepages.dcc.ufmg.br/~rfsilva/tsptw.
20 
21 #ifndef OR_TOOLS_ROUTING_TSPTW_PARSER_H_
22 #define OR_TOOLS_ROUTING_TSPTW_PARSER_H_
23 
24 #include <functional>
25 #include <string>
26 #include <vector>
27 
30 
31 namespace operations_research {
32 
33 class TspTWParser final {
34  public:
35  TspTWParser();
36  // Loads and parses a routing problem from a given file.
37  bool LoadFile(const std::string& file_name);
38  // Returns a function returning the distance between nodes. On some instances
39  // service times are already included in values returned by this function.
40  // The actual distance of a route can be obtained by removing
41  // total_service_time() from the sum of distances in that case.
42  const std::function<double(int, int)>& distance_function() const {
43  return distance_function_;
44  }
45  // Returns a function returning the time between nodes (equivalent to
46  // distance_function(i, j) + service_time(j)).
47  const std::function<double(int, int)>& time_function() const {
48  return time_function_;
49  }
50  // Returns the index of the depot.
51  int depot() const { return depot_; }
52  // Returns the number of nodes in the current routing problem.
53  int size() const { return size_; }
54  // Returns the total service time already included in distance_function.
55  double total_service_time() const { return total_service_time_; }
56  // Returns the coordinates of the nodes in the current routing problem.
57  const std::vector<Coordinates2<double>>& coordinates() const {
58  return coords_;
59  }
60  // Returns the time windows of the nodes in the current routing problem.
61  const std::vector<SimpleTimeWindow<double>>& time_windows() const {
62  return time_windows_;
63  }
64  // Returns the service times of the nodes in the current routing problem.
65  const std::vector<double>& service_times() const { return service_times_; }
66 
67  private:
68 #ifndef SWIG
69  TspTWParser(const TspTWParser&) = delete;
70  void operator=(const TspTWParser&) = delete;
71 #endif
72  bool ParseLopezIbanezBlum(const std::string& file_name);
73  bool ParseDaSilvaUrrutia(const std::string& file_name);
74 
75  int64_t size_;
76  int depot_;
77  double total_service_time_;
78  std::function<double(int, int)> distance_function_;
79  std::function<double(int, int)> time_function_;
80  std::vector<Coordinates2<double>> coords_;
81  std::vector<SimpleTimeWindow<double>> time_windows_;
82  std::vector<double> service_times_;
83  std::vector<double> distance_matrix_;
84 };
85 
86 } // namespace operations_research
87 
88 #endif // OR_TOOLS_ROUTING_TSPTW_PARSER_H_
const std::vector< Coordinates2< double > > & coordinates() const
Definition: tsptw_parser.h:57
const std::vector< double > & service_times() const
Definition: tsptw_parser.h:65
const std::function< double(int, int)> & time_function() const
Definition: tsptw_parser.h:47
const std::vector< SimpleTimeWindow< double > > & time_windows() const
Definition: tsptw_parser.h:61
const std::function< double(int, int)> & distance_function() const
Definition: tsptw_parser.h:42
bool LoadFile(const std::string &file_name)
Definition: tsptw_parser.cc:68
Collection of objects used to extend the Constraint Solver library.