Skip to content

Commit 5b27d23

Browse files
committed
Improved code [skip ci]
1 parent f14d8df commit 5b27d23

7 files changed

Lines changed: 30 additions & 30 deletions

File tree

ext/or-tools/assignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void init_assignment(Rice::Module& m) {
3030
} else if (status == SimpleLinearSumAssignment::Status::POSSIBLE_OVERFLOW) {
3131
return Symbol("possible_overflow");
3232
} else {
33-
throw std::runtime_error("Unknown status");
33+
throw std::runtime_error{"Unknown status"};
3434
}
3535
});
3636
}

ext/or-tools/constraint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void init_constraint(Rice::Module& m) {
402402
} else if (status == CpSolverStatus::UNKNOWN) {
403403
return Symbol("unknown");
404404
} else {
405-
throw std::runtime_error("Unknown solver status");
405+
throw std::runtime_error{"Unknown solver status"};
406406
}
407407
})
408408
.define_method(
@@ -434,7 +434,7 @@ void init_constraint(Rice::Module& m) {
434434
m.Add(NewFeasibleSolutionObserver(
435435
[&callback](const CpSolverResponse& r) {
436436
if (!ruby_native_thread_p()) {
437-
throw std::runtime_error("Non-Ruby thread");
437+
throw std::runtime_error{"Non-Ruby thread"};
438438
}
439439

440440
callback.call("response=", r);

ext/or-tools/ext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void init_routing(Rice::Module& m);
1616

1717
extern "C"
1818
void Init_ext() {
19-
auto m = Rice::define_module("ORTools");
19+
Rice::Module m = Rice::define_module("ORTools");
2020

2121
m.define_singleton_function("lib_version", &operations_research::OrToolsVersionString);
2222

ext/or-tools/linear.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ namespace Rice::detail {
3434
double is_convertible(VALUE value) { return Convertible::Exact; }
3535

3636
static MPSolver::OptimizationProblemType convert(VALUE x) {
37-
auto s = Symbol(x).str();
37+
std::string s = Symbol(x).str();
3838
if (s == "glop") {
3939
return MPSolver::OptimizationProblemType::GLOP_LINEAR_PROGRAMMING;
4040
} else if (s == "cbc") {
4141
return MPSolver::OptimizationProblemType::CBC_MIXED_INTEGER_PROGRAMMING;
4242
} else {
43-
throw std::runtime_error("Unknown optimization problem type: " + s);
43+
throw std::runtime_error{"Unknown optimization problem type: " + s};
4444
}
4545
}
4646

@@ -175,7 +175,7 @@ void init_linear(Rice::Module& m) {
175175
[](const std::string& name, MPSolver::OptimizationProblemType problem_type) {
176176
MPSolver* solver = new MPSolver(name, problem_type);
177177
if (!solver) {
178-
throw std::runtime_error("Unrecognized solver type");
178+
throw std::runtime_error{"Unrecognized solver type"};
179179
}
180180
return solver;
181181
}, Rice::Return().takeOwnership())
@@ -184,7 +184,7 @@ void init_linear(Rice::Module& m) {
184184
[](const std::string& solver_id) {
185185
MPSolver* solver = MPSolver::CreateSolver(solver_id);
186186
if (!solver) {
187-
throw std::runtime_error("Unrecognized solver type");
187+
throw std::runtime_error{"Unrecognized solver type"};
188188
}
189189
return solver;
190190
}, Rice::Return().takeOwnership())
@@ -239,15 +239,15 @@ void init_linear(Rice::Module& m) {
239239
} else if (status == MPSolver::ResultStatus::NOT_SOLVED) {
240240
return Symbol("not_solved");
241241
} else {
242-
throw std::runtime_error("Unknown status");
242+
throw std::runtime_error{"Unknown status"};
243243
}
244244
})
245245
.define_method(
246246
"export_model_as_lp_format",
247247
[](MPSolver& self, bool obfuscate) {
248248
std::string model_str;
249249
if (!self.ExportModelAsLpFormat(obfuscate, &model_str)) {
250-
throw std::runtime_error("Export failed");
250+
throw std::runtime_error{"Export failed"};
251251
}
252252
return model_str;
253253
})
@@ -256,7 +256,7 @@ void init_linear(Rice::Module& m) {
256256
[](MPSolver& self, bool fixed_format, bool obfuscate) {
257257
std::string model_str;
258258
if (!self.ExportModelAsMpsFormat(fixed_format, obfuscate, &model_str)) {
259-
throw std::runtime_error("Export failed");
259+
throw std::runtime_error{"Export failed"};
260260
}
261261
return model_str;
262262
});

ext/or-tools/math_opt.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Rice::detail {
3232
double is_convertible(VALUE value) { return Convertible::Exact; }
3333

3434
static SolverType convert(VALUE x) {
35-
auto s = Symbol(x).str();
35+
std::string s = Symbol(x).str();
3636
if (s == "gscip") {
3737
return SolverType::kGscip;
3838
} else if (s == "gurobi") {
@@ -54,7 +54,7 @@ namespace Rice::detail {
5454
} else if (s == "santorini") {
5555
return SolverType::kSantorini;
5656
} else {
57-
throw std::runtime_error("Unknown solver type: " + s);
57+
throw std::runtime_error{"Unknown solver type: " + s};
5858
}
5959
}
6060

@@ -71,7 +71,7 @@ void init_math_opt(Rice::Module& m) {
7171
.define_method(
7272
"name",
7373
[](Variable& self) {
74-
return std::string(self.name());
74+
return std::string{self.name()};
7575
})
7676
.define_method(
7777
"_eql?",
@@ -106,7 +106,7 @@ void init_math_opt(Rice::Module& m) {
106106
} else if (reason == TerminationReason::kOtherError) {
107107
return Rice::Symbol("other");
108108
} else {
109-
throw std::runtime_error("Unknown termination reason");
109+
throw std::runtime_error{"Unknown termination reason"};
110110
}
111111
});
112112

@@ -143,18 +143,18 @@ void init_math_opt(Rice::Module& m) {
143143
})
144144
.define_method(
145145
"_set_upper_bound",
146-
[](Model& self, LinearConstraint constraint, double upper_bound) {
146+
[](Model& self, const LinearConstraint& constraint, double upper_bound) {
147147
self.set_upper_bound(constraint, upper_bound);
148148
})
149149
.define_method(
150150
"_set_lower_bound",
151-
[](Model& self, LinearConstraint constraint, double upper_bound) {
151+
[](Model& self, const LinearConstraint& constraint, double upper_bound) {
152152
self.set_lower_bound(constraint, upper_bound);
153153
})
154154
.define_method("_set_coefficient", &Model::set_coefficient)
155155
.define_method(
156156
"_set_objective_coefficient",
157-
[](Model& self, Variable variable, double value) {
157+
[](Model& self, const Variable& variable, double value) {
158158
self.set_objective_coefficient(variable, value);
159159
})
160160
.define_method("_clear_objective", &Model::clear_objective)

ext/or-tools/network_flows.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void init_network_flows(Rice::Module& m) {
3636
} else if (status == SimpleMaxFlow::Status::BAD_RESULT) {
3737
return Symbol("bad_result");
3838
} else {
39-
throw std::runtime_error("Unknown status");
39+
throw std::runtime_error{"Unknown status"};
4040
}
4141
})
4242
.define_method(
@@ -98,7 +98,7 @@ void init_network_flows(Rice::Module& m) {
9898
} else if (status == SimpleMinCostFlow::Status::BAD_COST_RANGE) {
9999
return Symbol("bad_cost_range");
100100
} else {
101-
throw std::runtime_error("Unknown status");
101+
throw std::runtime_error{"Unknown status"};
102102
}
103103
});
104104
}

ext/or-tools/routing.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ namespace Rice::detail {
8181
double is_convertible(VALUE value) { return Convertible::Exact; }
8282

8383
RoutingModel::PenaltyCostBehavior convert(VALUE x) {
84-
auto s = Symbol(x).str();
84+
std::string s = Symbol(x).str();
8585
if (s == "penalize_once") {
8686
return RoutingModel::PenaltyCostBehavior::PENALIZE_ONCE;
8787
} else if (s == "penalize_per_inactive") {
8888
return RoutingModel::PenaltyCostBehavior::PENALIZE_PER_INACTIVE;
8989
} else {
90-
throw std::runtime_error("Unknown penalty cost behavior: " + s);
90+
throw std::runtime_error{"Unknown penalty cost behavior: " + s};
9191
}
9292
}
9393

@@ -138,7 +138,7 @@ void init_routing(Rice::Module& m) {
138138
} else if (s == "first_unbound_min_value") {
139139
v = FirstSolutionStrategy::FIRST_UNBOUND_MIN_VALUE;
140140
} else {
141-
throw std::runtime_error("Unknown first solution strategy: " + s);
141+
throw std::runtime_error{"Unknown first solution strategy: " + s};
142142
}
143143

144144
return self.set_first_solution_strategy(v);
@@ -158,7 +158,7 @@ void init_routing(Rice::Module& m) {
158158
} else if (s == "simulated_annealing") {
159159
v = LocalSearchMetaheuristic::SIMULATED_ANNEALING;
160160
} else {
161-
throw std::runtime_error("Unknown local search metaheuristic: " + s);
161+
throw std::runtime_error{"Unknown local search metaheuristic: " + s};
162162
}
163163

164164
return self.set_local_search_metaheuristic(v);
@@ -192,7 +192,7 @@ void init_routing(Rice::Module& m) {
192192
})
193193
.define_singleton_function(
194194
"_new_starts_ends",
195-
[](int num_nodes, int num_vehicles, std::vector<RoutingNodeIndex> starts, std::vector<RoutingNodeIndex> ends) {
195+
[](int num_nodes, int num_vehicles, const std::vector<RoutingNodeIndex>& starts, const std::vector<RoutingNodeIndex>& ends) {
196196
return RoutingIndexManager(num_nodes, num_vehicles, starts, ends);
197197
})
198198
.define_method("index_to_node", &RoutingIndexManager::IndexToNode)
@@ -279,7 +279,7 @@ void init_routing(Rice::Module& m) {
279279
} else if (op == "<=") {
280280
constraint = self.MakeLessOrEqual(left, right);
281281
} else {
282-
throw std::runtime_error("Unknown operator");
282+
throw std::runtime_error{"Unknown operator"};
283283
}
284284
} else {
285285
constraint = Rice::detail::From_Ruby<operations_research::Constraint*>().convert(o);
@@ -293,7 +293,7 @@ void init_routing(Rice::Module& m) {
293293
})
294294
.define_method(
295295
"cumulative",
296-
[](operations_research::Solver& self, Array rb_intervals, std::vector<int64_t> demands, int64_t capacity, const std::string& name) {
296+
[](operations_research::Solver& self, Array rb_intervals, const std::vector<int64_t>& demands, int64_t capacity, const std::string& name) {
297297
std::vector<operations_research::IntervalVar*> intervals;
298298
for (const auto& v : rb_intervals) {
299299
intervals.push_back(Rice::detail::From_Ruby<operations_research::IntervalVar*>().convert(v.value()));
@@ -338,7 +338,7 @@ void init_routing(Rice::Module& m) {
338338
return self.RegisterUnaryTransitCallback(
339339
[callback](int64_t from_index) -> int64_t {
340340
if (!ruby_native_thread_p()) {
341-
throw std::runtime_error("Non-Ruby thread");
341+
throw std::runtime_error{"Non-Ruby thread"};
342342
}
343343

344344
return Rice::detail::From_Ruby<int64_t>().convert(callback.call("call", from_index));
@@ -353,7 +353,7 @@ void init_routing(Rice::Module& m) {
353353
return self.RegisterTransitCallback(
354354
[callback](int64_t from_index, int64_t to_index) -> int64_t {
355355
if (!ruby_native_thread_p()) {
356-
throw std::runtime_error("Non-Ruby thread");
356+
throw std::runtime_error{"Non-Ruby thread"};
357357
}
358358

359359
return Rice::detail::From_Ruby<int64_t>().convert(callback.call("call", from_index, to_index));
@@ -451,7 +451,7 @@ void init_routing(Rice::Module& m) {
451451
} else if (status == RoutingSearchStatus::ROUTING_INVALID) {
452452
return Symbol("invalid");
453453
} else {
454-
throw std::runtime_error("Unknown solver status");
454+
throw std::runtime_error{"Unknown solver status"};
455455
}
456456
})
457457
.define_method("apply_locks", &RoutingModel::ApplyLocks)

0 commit comments

Comments
 (0)