Skip to content

Commit

Permalink
routing/parser: change namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Nov 15, 2024
1 parent 3e1ca39 commit f73a92c
Show file tree
Hide file tree
Showing 35 changed files with 1,394 additions and 207 deletions.
12 changes: 9 additions & 3 deletions ortools/routing/parsers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -59,18 +60,23 @@ cc_library(
"//ortools/base:zipfile",
"//ortools/util:filelineiter",
"@com_google_absl//absl/strings",
"@com_google_re2//:re2",
],
)

cc_test(
name = "solomon_parser_test",
size = "small",
srcs = ["solomon_parser_test.cc"],
data = ["//ortools/routing/parsers/testdata:solomon.zip"],
data = [
"//ortools/routing/parsers/testdata:c1_10_2-90-42222.96.txt",
"//ortools/routing/parsers/testdata:solomon.zip",
],
deps = [
":solomon_parser",
"//ortools/base",
"//ortools/base:file",
"//ortools/base:gmock",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
6 changes: 5 additions & 1 deletion ortools/routing/parsers/capacity_planning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

syntax = "proto3";

package operations_research;
option java_package = "com.google.ortools.routing.parser";
option java_multiple_files = true;
option csharp_namespace = "Google.OrTools.Routing.Parser";

package operations_research.routing;

// This is the proto for describing the multicommodity fixed-charged network
// design problem.
Expand Down
9 changes: 5 additions & 4 deletions ortools/routing/parsers/carp_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ortools/base/numbers.h"
#include "ortools/util/filelineiter.h"

namespace operations_research {
namespace operations_research::routing {

CarpParser::CarpParser() { Initialize(); }

Expand All @@ -44,12 +45,12 @@ void CarpParser::Initialize() {
section_ = METADATA;
}

bool CarpParser::LoadFile(const std::string& file_name) {
bool CarpParser::LoadFile(absl::string_view file_name) {
Initialize();
return ParseFile(file_name);
}

bool CarpParser::ParseFile(const std::string& file_name) {
bool CarpParser::ParseFile(absl::string_view file_name) {
static auto section_headers = std::array<const char*, 12>({
"NOMBRE",
"COMENTARIO",
Expand Down Expand Up @@ -246,4 +247,4 @@ std::optional<int64_t> ParseNodeIndex(std::string_view text) {
return {node - 1};
}
} // namespace
} // namespace operations_research
} // namespace operations_research::routing
9 changes: 5 additions & 4 deletions ortools/routing/parsers/carp_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@
#include <string_view>
#include <vector>

#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ortools/base/linked_hash_map.h"
#include "ortools/base/logging.h"
#include "ortools/routing/parsers/simple_graph.h"

namespace operations_research {
namespace operations_research::routing {
class CarpParser {
public:
CarpParser();
Expand All @@ -76,7 +77,7 @@ class CarpParser {
#endif

// Loads instance from a file into this parser object.
bool LoadFile(const std::string& file_name);
bool LoadFile(absl::string_view file_name);

// Returns the name of the instance being solved.
const std::string& name() const { return name_; }
Expand Down Expand Up @@ -156,7 +157,7 @@ class CarpParser {
};

void Initialize();
bool ParseFile(const std::string& file_name);
bool ParseFile(absl::string_view file_name);
bool ParseMetadataLine(absl::Span<const std::string> words);
bool ParseEdge(std::string_view line, bool with_servicing);

Expand All @@ -181,6 +182,6 @@ class CarpParser {
int64_t n_vehicles_;
int64_t capacity_;
};
} // namespace operations_research
} // namespace operations_research::routing

#endif // OR_TOOLS_ROUTING_PARSERS_CARP_PARSER_H_
49 changes: 20 additions & 29 deletions ortools/routing/parsers/carp_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
#include <string>

#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/scoped_mock_log.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/path.h"

#if defined(_MSC_VER)
#define ROOT_DIR "../../../../../../../"
#else
#define ROOT_DIR
#endif // _MSC_VER
#define ROOT_DIR "_main/"

ABSL_FLAG(std::string, test_srcdir, "", "REQUIRED: src dir");

namespace operations_research {
namespace operations_research::routing {
namespace {
TEST(CarpParserTest, Constructor) {
CarpParser parser;
Expand Down Expand Up @@ -69,7 +62,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectNumberOfNodes) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_vertices.dat")));
}
Expand All @@ -86,7 +79,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectNumberOfArcsWithServicings) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_arireq.dat")));
}
Expand All @@ -103,7 +96,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectNumberOfArcsWithoutServicings) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_arinoreq.dat")));
}
Expand All @@ -120,7 +113,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectNumberOfVehicles) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_vehiculos.dat")));
}
Expand All @@ -137,7 +130,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectCapacity) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_capacidad.dat")));
}
Expand All @@ -154,7 +147,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectTypeOfArcCost) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_tipo.dat")));
}
Expand All @@ -170,7 +163,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectTotalServicingCost) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_coste.dat")));
}
Expand All @@ -189,7 +182,7 @@ TEST(CarpParserTest, LoadInvalidFileIncorrectDepot) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecto_deposito.dat")));
}
Expand All @@ -207,7 +200,7 @@ TEST(CarpParserTest, LoadInvalidFileNoEdgeWithServicing) {

CarpParser parser;
EXPECT_FALSE(parser.LoadFile(
file::JoinPath(absl::GetFlag(FLAGS_test_srcdir),
file::JoinPath(::testing::SrcDir(),
ROOT_DIR "ortools/routing/parsers"
"/testdata/carp_gdb19_no_arista_req.dat")));
}
Expand All @@ -223,7 +216,7 @@ TEST(CarpParserTest, LoadInvalidFileServicingForArcsWithoutServicing) {

CarpParser parser;
EXPECT_FALSE(
parser.LoadFile(file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
parser.LoadFile(file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers"
"/testdata/carp_gdb19_mixed_arcs.dat")));
}
Expand All @@ -239,16 +232,15 @@ TEST(CarpParserTest, LoadInvalidFileServicingForArcsInWrongOrder) {

CarpParser parser;
EXPECT_FALSE(parser.LoadFile(
file::JoinPath(absl::GetFlag(FLAGS_test_srcdir),
file::JoinPath(::testing::SrcDir(),
ROOT_DIR "ortools/routing/parsers/testdata/"
"carp_gdb19_incorrecta_lista_aristas_req.dat")));
}

TEST(CarpParserTest, LoadInstanceFile) {
std::string file_name =
file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19.dat");
std::string file_name = file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19.dat");
CarpParser parser;
EXPECT_TRUE(parser.LoadFile(file_name));
EXPECT_EQ(parser.name(), "gdb19");
Expand All @@ -271,13 +263,12 @@ TEST(CarpParserTest, LoadInstanceFile) {
}

TEST(CarpParserTest, LoadInstanceFileWithDifferentDepot) {
std::string file_name =
file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_diferente_deposito.dat");
std::string file_name = file::JoinPath(::testing::SrcDir(), ROOT_DIR
"ortools/routing/parsers/testdata/"
"carp_gdb19_diferente_deposito.dat");
CarpParser parser;
EXPECT_TRUE(parser.LoadFile(file_name));
EXPECT_EQ(parser.depot(), 4);
}
} // namespace
} // namespace operations_research
} // namespace operations_research::routing
4 changes: 2 additions & 2 deletions ortools/routing/parsers/dow_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "ortools/routing/parsers/capacity_planning.pb.h"
#include "ortools/util/filelineiter.h"

namespace operations_research {
namespace operations_research::routing {
::absl::Status ReadFile(absl::string_view file_name,
CapacityPlanningInstance* request) {
if (!file::Exists(file_name, file::Defaults()).ok()) {
Expand Down Expand Up @@ -103,4 +103,4 @@ ::absl::Status ReadFile(absl::string_view file_name,
return absl::OkStatus();
}

} // namespace operations_research
} // namespace operations_research::routing
4 changes: 2 additions & 2 deletions ortools/routing/parsers/dow_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// Reader for Multicommodity fixed-charge Network Design (MCND) files using the
// .dow format.

namespace operations_research {
namespace operations_research::routing {
::absl::Status ReadFile(absl::string_view file_name,
CapacityPlanningInstance* request);
} // namespace operations_research
} // namespace operations_research::routing

#endif // OR_TOOLS_ROUTING_PARSERS_DOW_PARSER_H_
25 changes: 12 additions & 13 deletions ortools/routing/parsers/dow_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@

#include <string>

#include "absl/flags/flag.h"
#include "absl/status/status.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/path.h"
#include "ortools/routing/parsers/capacity_planning.pb.h"

namespace operations_research {
namespace operations_research::routing {
namespace {
TEST(CapacityPlanningReaderTest, C33PassesOK) {
CapacityPlanningInstance request;
::absl::Status status = ReadFile(
file::JoinPathRespectAbsolute(
absl::GetFlag(FLAGS_test_srcdir), "operations_research_data/",
"MULTICOM_FIXED_CHARGE_NETWORK_DESIGN/C/c33.dow"),
&request);
::absl::Status status =
ReadFile(file::JoinPathRespectAbsolute(
::testing::SrcDir(), "operations_research_data/",
"MULTICOM_FIXED_CHARGE_NETWORK_DESIGN/C/c33.dow"),
&request);
EXPECT_OK(status);
const NetworkTopology& topology = request.topology();
const int num_arcs = topology.from_node_size();
Expand All @@ -48,14 +47,14 @@ TEST(CapacityPlanningReaderTest, C33PassesOK) {

TEST(CapacityPlanningReaderTest, C34DoesNotExist) {
CapacityPlanningInstance request;
::absl::Status status = ReadFile(
file::JoinPathRespectAbsolute(
absl::GetFlag(FLAGS_test_srcdir), "operations_research_data/",
"MULTICOM_FIXED_CHARGE_NETWORK_DESIGN/C/c34.dow"),
&request);
::absl::Status status =
ReadFile(file::JoinPathRespectAbsolute(
::testing::SrcDir(), "operations_research_data/",
"MULTICOM_FIXED_CHARGE_NETWORK_DESIGN/C/c34.dow"),
&request);
EXPECT_THAT(::util::StatusToString(status),
testing::HasSubstr("generic::not_found"));
}

} // namespace
} // namespace operations_research
} // namespace operations_research::routing
4 changes: 2 additions & 2 deletions ortools/routing/parsers/lilim_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "ortools/base/zipfile.h"
#include "ortools/util/filelineiter.h"

namespace operations_research {
namespace operations_research::routing {

bool LiLimParser::LoadFile(absl::string_view file_name) {
Initialize();
Expand Down Expand Up @@ -126,4 +126,4 @@ bool LiLimParser::ParseFile(absl::string_view file_name) {

#undef PARSE_AND_RETURN_IF_NEGATIVE

} // namespace operations_research
} // namespace operations_research::routing
4 changes: 2 additions & 2 deletions ortools/routing/parsers/lilim_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "absl/strings/string_view.h"
#include "ortools/routing/parsers/simple_graph.h"

namespace operations_research {
namespace operations_research::routing {

// Li&Lim parser class
class LiLimParser {
Expand Down Expand Up @@ -122,6 +122,6 @@ class LiLimParser {
std::vector<SimpleTimeWindow<int64_t>> time_windows_;
std::vector<int64_t> service_times_;
};
} // namespace operations_research
} // namespace operations_research::routing

#endif // OR_TOOLS_ROUTING_PARSERS_LILIM_PARSER_H_
Loading

0 comments on commit f73a92c

Please sign in to comment.