OR-Tools  9.6
tsptw_parser_test.cc
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 
15 
16 #include <string>
17 
18 #include "absl/flags/flag.h"
19 #include "gtest/gtest.h"
20 #include "ortools/base/helpers.h"
22 #include "ortools/base/path.h"
23 
24 #if defined(_MSC_VER)
25 #define ROOT_DIR "../../../../../../../"
26 #else
27 #define ROOT_DIR
28 #endif // _MSC_VER
29 
30 ABSL_FLAG(std::string, test_srcdir, "", "REQUIRED: src dir");
31 
32 namespace operations_research {
33 namespace {
34 
35 TEST(TspTWParserTest, LoadDataSet) {
36  const int sizes[] = {26, 21, 21};
37  const double distances[] = {25166.316, 9538, 9006};
38  const double times[] = {25166.316, 9538, 9006};
39  const double starts[] = {9362, 2388, 2392};
40  const double ends[] = {13322, 3131, 3146};
41  const double service_times[] = {250, 0, 0};
42  const bool has_coordinates[] = {false, false, true};
43  int count = 0;
44  for (const std::string& data :
45  {ROOT_DIR "ortools/routing/testdata/rc201.0",
46  ROOT_DIR "ortools/routing/testdata/n20w20.001.txt",
47  ROOT_DIR "ortools/routing/testdata/n20w20.002.txt"}) {
48  TspTWParser parser;
49  EXPECT_TRUE(parser.LoadFile(
50  file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), data)));
51  EXPECT_EQ(0, parser.depot());
52  const int size = sizes[count];
53  EXPECT_EQ(size, parser.size());
54  double total_distances = 0;
55  double total_times = 0;
56  for (int i = 0; i < size; ++i) {
57  for (int j = 0; j < size; ++j) {
58  total_distances += parser.distance_function()(i, j);
59  total_times += parser.time_function()(i, j);
60  }
61  }
62  EXPECT_NEAR(distances[count], total_distances, 1e-6);
63  EXPECT_NEAR(times[count], total_times, 1e-6);
64  EXPECT_EQ(service_times[count], parser.total_service_time());
65  EXPECT_EQ(has_coordinates[count], !parser.coordinates().empty());
66  double total_starts = 0;
67  double total_ends = 0;
68  for (int i = 0; i < size; ++i) {
69  EXPECT_EQ(0, parser.service_times()[i]);
70  total_starts += parser.time_windows()[i].start;
71  total_ends += parser.time_windows()[i].end;
72  }
73  EXPECT_EQ(starts[count], total_starts);
74  EXPECT_EQ(ends[count], total_ends);
75  ++count;
76  }
77 }
78 
79 } // namespace
80 } // namespace operations_research
std::string JoinPath(absl::string_view path1, absl::string_view path2)
Definition: path.cc:25
Collection of objects used to extend the Constraint Solver library.
TEST(LinearAssignmentTest, NullMatrix)
#define ROOT_DIR
ABSL_FLAG(std::string, test_srcdir, "", "REQUIRED: src dir")