Skip to content

Commit 747d260

Browse files
committed
Started update to Rice 4.8
1 parent 14fdc94 commit 747d260

8 files changed

Lines changed: 40 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.16.2 (unreleased)
2+
3+
- Fixed error with Rice 4.8
4+
15
## 0.16.1 (2025-10-26)
26

37
- Added `add_allowed_assignments` and `add_forbidden_assignments` methods to `CpModel`

ext/or-tools/bin_packing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Rice::detail {
2424

2525
explicit From_Ruby(Arg* arg) : arg_(arg) { }
2626

27-
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
27+
double is_convertible(VALUE value) { return Convertible::Exact; }
2828

2929
KnapsackSolver::SolverType convert(VALUE x) {
3030
auto s = Symbol(x).str();

ext/or-tools/constraint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace Rice::detail {
4444

4545
explicit From_Ruby(Arg* arg) : arg_(arg) { }
4646

47-
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
47+
double is_convertible(VALUE value) { return Convertible::Exact; }
4848

4949
LinearExpr convert(VALUE v) {
5050
LinearExpr expr;

ext/or-tools/linear.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Rice::detail {
3030

3131
explicit From_Ruby(Arg* arg) : arg_(arg) { }
3232

33-
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
33+
double is_convertible(VALUE value) { return Convertible::Exact; }
3434

3535
static MPSolver::OptimizationProblemType convert(VALUE x) {
3636
auto s = Symbol(x).str();

ext/or-tools/math_opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Rice::detail {
2929

3030
explicit From_Ruby(Arg* arg) : arg_(arg) { }
3131

32-
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
32+
double is_convertible(VALUE value) { return Convertible::Exact; }
3333

3434
static SolverType convert(VALUE x) {
3535
auto s = Symbol(x).str();

ext/or-tools/routing.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Rice::detail {
4040

4141
explicit From_Ruby(Arg* arg) : arg_(arg) { }
4242

43-
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
43+
double is_convertible(VALUE value) { return Convertible::Exact; }
4444

4545
RoutingNodeIndex convert(VALUE x) {
4646
const RoutingNodeIndex index{From_Ruby<int>().convert(x)};
@@ -65,6 +65,35 @@ namespace Rice::detail {
6565
private:
6666
Arg* arg_ = nullptr;
6767
};
68+
69+
template<>
70+
struct Type<RoutingModel::PenaltyCostBehavior> {
71+
static bool verify() { return true; }
72+
};
73+
74+
template<>
75+
class From_Ruby<RoutingModel::PenaltyCostBehavior> {
76+
public:
77+
From_Ruby() = default;
78+
79+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
80+
81+
double is_convertible(VALUE value) { return Convertible::Exact; }
82+
83+
RoutingModel::PenaltyCostBehavior convert(VALUE x) {
84+
auto s = Symbol(x).str();
85+
if (s == "penalize_once") {
86+
return RoutingModel::PenaltyCostBehavior::PENALIZE_ONCE;
87+
} else if (s == "penalize_per_inactive") {
88+
return RoutingModel::PenaltyCostBehavior::PENALIZE_PER_INACTIVE;
89+
} else {
90+
throw std::runtime_error("Unknown penalty cost behavior: " + s);
91+
}
92+
}
93+
94+
private:
95+
Arg* arg_ = nullptr;
96+
};
6897
} // namespace Rice::detail
6998

7099
void init_routing(Rice::Module& m) {

or-tools.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Gem::Specification.new do |spec|
1616

1717
spec.required_ruby_version = ">= 3.1"
1818

19-
spec.add_dependency "rice", ">= 4.7"
19+
spec.add_dependency "rice", ">= 4.8"
2020
end

test/constraint_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_add_hint
232232
error = assert_raises(RuntimeError) do
233233
model.add_hint("z", 1)
234234
end
235-
assert_equal "The provided Ruby object does not wrap a C++ object", error.message
235+
assert_equal "The Ruby object does not wrap a C++ object. It is actually a String.", error.message
236236
end
237237

238238
def test_int_var_domain

0 commit comments

Comments
 (0)