Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
pdtsp_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 TSPPD parser used to parse instances of Traveling Salesman Problems with
15// pickup and delivery constraints. This format was created by Stefan Ropke.
16// https://link.springer.com/article/10.1007%2Fs10107-008-0234-9
17
18#ifndef OR_TOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
19#define OR_TOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
20
21#include <functional>
22#include <string>
23#include <vector>
24
25#include "absl/strings/string_view.h"
26#include "ortools/base/types.h"
27
29
31 public:
33 ~PdTspParser() = default;
34 // Loads and parse a PDTSP from a given file.
35 bool LoadFile(absl::string_view file_name);
36 // Returns the index of the depot.
37 int depot() const { return depot_; }
38 // Returns the number of nodes in the PDTSP.
39 int Size() const { return x_.size(); }
40 // Returns true if the index corresponding to a node is a pickup.
41 bool IsPickup(int index) const { return deliveries_[index] >= 0; }
42 // Returns the delivery corresponding to a pickup.
43 int DeliveryFromPickup(int index) const { return deliveries_[index]; }
44 // Returns a function returning distances between nodes.
45 std::function<int64_t(int, int)> Distances() const;
46
47 private:
48 enum Sections { SIZE_SECTION, DEPOT_SECTION, NODE_SECTION, EOF_SECTION };
49 void ProcessNewLine(const std::string& line);
50
51 int depot_;
52 Sections section_;
53 std::vector<double> x_;
54 std::vector<double> y_;
55 std::vector<int> deliveries_;
56};
57
58} // namespace operations_research::routing
59
60#endif // OR_TOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
int depot() const
Returns the index of the depot.
std::function< int64_t(int, int)> Distances() const
Returns a function returning distances between nodes.
int DeliveryFromPickup(int index) const
Returns the delivery corresponding to a pickup.
bool IsPickup(int index) const
Returns true if the index corresponding to a node is a pickup.
int Size() const
Returns the number of nodes in the PDTSP.
bool LoadFile(absl::string_view file_name)
Loads and parse a PDTSP from a given file.
Common utilities for parsing routing instances.