OR-Tools
9.6
pdtsp_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 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_PDTSP_PARSER_H_
19
#define OR_TOOLS_ROUTING_PDTSP_PARSER_H_
20
21
#include <functional>
22
#include <string>
23
#include <vector>
24
25
#include "
ortools/base/integral_types.h
"
26
27
namespace
operations_research
{
28
29
class
PdTspParser
{
30
public
:
31
PdTspParser
();
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_PDTSP_PARSER_H_
operations_research::PdTspParser
Definition:
pdtsp_parser.h:29
operations_research::PdTspParser::IsPickup
bool IsPickup(int index) const
Definition:
pdtsp_parser.h:40
operations_research::PdTspParser::Size
int Size() const
Definition:
pdtsp_parser.h:38
operations_research::PdTspParser::depot
int depot() const
Definition:
pdtsp_parser.h:36
operations_research::PdTspParser::~PdTspParser
~PdTspParser()=default
operations_research::PdTspParser::LoadFile
bool LoadFile(const std::string &file_name)
Definition:
pdtsp_parser.cc:45
operations_research::PdTspParser::DeliveryFromPickup
int DeliveryFromPickup(int index) const
Definition:
pdtsp_parser.h:42
operations_research::PdTspParser::Distances
std::function< int64_t(int, int)> Distances() const
Definition:
pdtsp_parser.cc:53
operations_research::PdTspParser::PdTspParser
PdTspParser()
Definition:
pdtsp_parser.cc:43
integral_types.h
index
int index
Definition:
local_search.cc:2724
operations_research
Collection of objects used to extend the Constraint Solver library.
Definition:
dense_doubly_linked_list.h:21
line
int line
Definition:
parse_proto.cc:31
ortools
routing
pdtsp_parser.h
Generated by
1.9.1