Google OR-Tools
v9.15
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 ORTOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
19
#define ORTOOLS_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
28
namespace
operations_research::routing
{
29
30
class
PdTspParser
{
31
public
:
32
PdTspParser
();
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
// ORTOOLS_ROUTING_PARSERS_PDTSP_PARSER_H_
operations_research::routing::PdTspParser::depot
int depot() const
Definition
pdtsp_parser.h:37
operations_research::routing::PdTspParser::Distances
std::function< int64_t(int, int)> Distances() const
Definition
pdtsp_parser.cc:40
operations_research::routing::PdTspParser::DeliveryFromPickup
int DeliveryFromPickup(int index) const
Definition
pdtsp_parser.h:43
operations_research::routing::PdTspParser::IsPickup
bool IsPickup(int index) const
Definition
pdtsp_parser.h:41
operations_research::routing::PdTspParser::PdTspParser
PdTspParser()
Definition
pdtsp_parser.cc:30
operations_research::routing::PdTspParser::Size
int Size() const
Definition
pdtsp_parser.h:39
operations_research::routing::PdTspParser::LoadFile
bool LoadFile(absl::string_view file_name)
Definition
pdtsp_parser.cc:32
operations_research::routing::PdTspParser::~PdTspParser
~PdTspParser()=default
operations_research::routing
Definition
carp_parser.cc:32
types.h
ortools
routing
parsers
pdtsp_parser.h
Generated by
1.15.0