Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
tsptw_parser.h
Go to the documentation of this file.
1// Copyright 2010-2025 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_PARSERS_TSPTW_PARSER_H_
22#define OR_TOOLS_ROUTING_PARSERS_TSPTW_PARSER_H_
23
24#include <functional>
25#include <string>
26#include <vector>
27
28#include "absl/strings/string_view.h"
29#include "ortools/base/types.h"
31
33
34class TspTWParser final {
35 public:
37 // Loads and parses a routing problem from a given file.
38 bool LoadFile(absl::string_view file_name);
39 // Returns a function returning the distance between nodes. On some instances
40 // service times are already included in values returned by this function.
41 // The actual distance of a route can be obtained by removing
42 // total_service_time() from the sum of distances in that case.
43 const std::function<double(int, int)>& distance_function() const {
44 return distance_function_;
45 }
46 // Returns a function returning the time between nodes (equivalent to
47 // distance_function(i, j) + service_time(j)).
48 const std::function<double(int, int)>& time_function() const {
49 return time_function_;
50 }
51 // Returns the index of the depot.
52 int depot() const { return depot_; }
53 // Returns the number of nodes in the current routing problem.
54 int size() const { return size_; }
55 // Returns the total service time already included in distance_function.
56 double total_service_time() const { return total_service_time_; }
57 // Returns the coordinates of the nodes in the current routing problem.
58 const std::vector<Coordinates2<double>>& coordinates() const {
59 return coords_;
60 }
61 // Returns the time windows of the nodes in the current routing problem.
62 const std::vector<SimpleTimeWindow<double>>& time_windows() const {
63 return time_windows_;
64 }
65 // Returns the service times of the nodes in the current routing problem.
66 const std::vector<double>& service_times() const { return service_times_; }
67
68 private:
69#ifndef SWIG
70 TspTWParser(const TspTWParser&) = delete;
71 void operator=(const TspTWParser&) = delete;
72#endif
73 bool ParseLopezIbanezBlum(absl::string_view file_name);
74 bool ParseDaSilvaUrrutia(absl::string_view file_name);
75
76 int64_t size_;
77 int depot_;
78 double total_service_time_;
79 std::function<double(int, int)> distance_function_;
80 std::function<double(int, int)> time_function_;
81 std::vector<Coordinates2<double>> coords_;
82 std::vector<SimpleTimeWindow<double>> time_windows_;
83 std::vector<double> service_times_;
84 std::vector<double> distance_matrix_;
85};
86
87} // namespace operations_research::routing
88
89#endif // OR_TOOLS_ROUTING_PARSERS_TSPTW_PARSER_H_
const std::vector< double > & service_times() const
Returns the service times of the nodes in the current routing problem.
int depot() const
Returns the index of the depot.
const std::vector< Coordinates2< double > > & coordinates() const
Returns the coordinates of the nodes in the current routing problem.
const std::function< double(int, int)> & time_function() const
double total_service_time() const
Returns the total service time already included in distance_function.
bool LoadFile(absl::string_view file_name)
Loads and parses a routing problem from a given file.
int size() const
Returns the number of nodes in the current routing problem.
const std::function< double(int, int)> & distance_function() const
const std::vector< SimpleTimeWindow< double > > & time_windows() const
Returns the time windows of the nodes in the current routing problem.
Common utilities for parsing routing instances.