33::absl::Status
ReadFile(absl::string_view file_name,
34 CapacityPlanningInstance* request) {
36 return absl::NotFoundError(absl::StrCat(file_name,
" not found"));
41 int num_commodities = 0;
43 int commodity_num = 0;
44 for (
const std::string&
line :
46 if (
line ==
"MULTIGEN.DAT:") {
47 CHECK_EQ(line_num, 0);
51 const std::vector<std::string> fields =
52 absl::StrSplit(
line, absl::ByAnyChar(
" \t"), absl::SkipEmpty());
53 if (fields.size() == 3) {
55 CHECK(absl::SimpleAtoi(fields[0], &num_nodes));
56 CHECK(absl::SimpleAtoi(fields[1], &num_arcs));
57 CHECK(absl::SimpleAtoi(fields[2], &num_commodities));
58 VLOG(1) <<
"num_nodes = " << num_nodes <<
", num_arcs = " << num_arcs
59 <<
", num_commodities = " << num_commodities;
61 CHECK_GT(line_num, num_arcs + 1);
62 CHECK_LE(line_num, num_arcs + num_commodities + 1);
64 CHECK(absl::SimpleAtoi(fields[0], &from_node));
66 CHECK(absl::SimpleAtoi(fields[1], &to_node));
68 CHECK(absl::SimpleAtoi(fields[2], &
demand));
71 request->mutable_commodities()->add_from_node(from_node);
72 request->mutable_commodities()->add_to_node(to_node);
73 request->mutable_commodities()->add_demand(
demand);
75 }
else if (fields.size() == 7) {
77 CHECK_GT(line_num, 1);
78 CHECK_LE(line_num, num_arcs + 1);
79 CHECK_LT(arc_num, num_arcs);
81 CHECK(absl::SimpleAtoi(fields[0], &from_node));
83 CHECK(absl::SimpleAtoi(fields[1], &to_node));
85 CHECK(absl::SimpleAtoi(fields[2], &variable_cost));
87 CHECK(absl::SimpleAtoi(fields[3], &capacity));
89 CHECK(absl::SimpleAtoi(fields[4], &
fixed_cost));
91 CHECK(absl::SimpleAtoi(fields[5], &unused));
92 CHECK(absl::SimpleAtoi(fields[6], &unused));
94 request->mutable_topology()->add_from_node(from_node);
95 request->mutable_topology()->add_to_node(to_node);
96 request->mutable_topology()->add_variable_cost(variable_cost);
97 request->mutable_topology()->add_capacity(capacity);
98 request->mutable_topology()->add_fixed_cost(
fixed_cost);
102 CHECK_EQ(commodity_num, num_commodities);
103 return absl::OkStatus();