Google OR-Tools v9.11
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-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// 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 "ortools/base/types.h"
26
27namespace operations_research {
28
30 public:
32 ~PdTspParser() = default;
33 // Loads and parse a PDTSP from a given file.
34 bool LoadFile(const std::string& file_name);
35 // Returns the index of the depot.
36 int depot() const { return depot_; }
37 // Returns the number of nodes in the PDTSP.
38 int Size() const { return x_.size(); }
39 // Returns true if the index corresponding to a node is a pickup.
40 bool IsPickup(int index) const { return deliveries_[index] >= 0; }
41 // Returns the delivery corresponding to a pickup.
42 int DeliveryFromPickup(int index) const { return deliveries_[index]; }
43 // Returns a function returning distances between nodes.
44 std::function<int64_t(int, int)> Distances() const;
45
46 private:
47 enum Sections { SIZE_SECTION, DEPOT_SECTION, NODE_SECTION, EOF_SECTION };
48 void ProcessNewLine(const std::string& line);
49
50 int depot_;
51 Sections section_;
52 std::vector<double> x_;
53 std::vector<double> y_;
54 std::vector<int> deliveries_;
55};
56
57} // namespace operations_research
58
59#endif // OR_TOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
std::function< int64_t(int, int)> Distances() const
Returns a function returning distances between nodes.
int Size() const
Returns the number of nodes in the PDTSP.
int depot() const
Returns the index of the depot.
int DeliveryFromPickup(int index) const
Returns the delivery corresponding to a pickup.
bool LoadFile(const std::string &file_name)
Loads and parse a PDTSP from a given file.
bool IsPickup(int index) const
Returns true if the index corresponding to a node is a pickup.
int index
In SWIG mode, we don't want anything besides these top-level includes.
int line