Skip to content

Commit 7b9626e

Browse files
committed
Fixed error with Rice 4.7
1 parent 5ce727d commit 7b9626e

File tree

8 files changed

+54
-7
lines changed

8 files changed

+54
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.16.1 (unreleased)
22

33
- Added `add_allowed_assignments` and `add_forbidden_assignments` methods to `CpModel`
4+
- Fixed error with Rice 4.7
45

56
## 0.16.0 (2025-06-19)
67

ext/or-tools/bin_packing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace Rice::detail {
2020
template<>
2121
class From_Ruby<KnapsackSolver::SolverType> {
2222
public:
23+
From_Ruby() = default;
24+
25+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
26+
2327
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
2428

2529
KnapsackSolver::SolverType convert(VALUE x) {
@@ -30,6 +34,9 @@ namespace Rice::detail {
3034
throw std::runtime_error("Unknown solver type: " + s);
3135
}
3236
}
37+
38+
private:
39+
Arg* arg_ = nullptr;
3340
};
3441
} // namespace Rice::detail
3542

ext/or-tools/constraint.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ namespace Rice::detail {
4040
template<>
4141
class From_Ruby<LinearExpr> {
4242
public:
43+
From_Ruby() = default;
44+
45+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
46+
4347
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
4448

4549
LinearExpr convert(VALUE v) {
@@ -63,6 +67,9 @@ namespace Rice::detail {
6367

6468
return expr;
6569
}
70+
71+
private:
72+
Arg* arg_ = nullptr;
6673
};
6774
} // namespace Rice::detail
6875

@@ -409,7 +416,7 @@ void init_constraint(Rice::Module& m) {
409416
auto a = Array();
410417
auto assumptions = self.sufficient_assumptions_for_infeasibility();
411418
for (const auto& v : assumptions) {
412-
a.push(v);
419+
a.push(v, false);
413420
}
414421
return a;
415422
});

ext/or-tools/linear.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace Rice::detail {
2626

2727
template<>
2828
struct From_Ruby<MPSolver::OptimizationProblemType> {
29+
From_Ruby() = default;
30+
31+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
32+
2933
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
3034

3135
static MPSolver::OptimizationProblemType convert(VALUE x) {
@@ -38,6 +42,9 @@ namespace Rice::detail {
3842
throw std::runtime_error("Unknown optimization problem type: " + s);
3943
}
4044
}
45+
46+
private:
47+
Arg* arg_ = nullptr;
4148
};
4249
} // namespace Rice::detail
4350

ext/or-tools/math_opt.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ namespace Rice::detail {
2525

2626
template<>
2727
struct From_Ruby<SolverType> {
28+
From_Ruby() = default;
29+
30+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
31+
2832
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
2933

3034
static SolverType convert(VALUE x) {
@@ -53,6 +57,9 @@ namespace Rice::detail {
5357
throw std::runtime_error("Unknown solver type: " + s);
5458
}
5559
}
60+
61+
private:
62+
Arg* arg_ = nullptr;
5663
};
5764
} // namespace Rice::detail
5865

@@ -61,7 +68,11 @@ void init_math_opt(Rice::Module& m) {
6168

6269
Rice::define_class_under<Variable>(mathopt, "Variable")
6370
.define_method("id", &Variable::id)
64-
.define_method("name", &Variable::name)
71+
.define_method(
72+
"name",
73+
[](Variable& self) {
74+
return std::string(self.name());
75+
})
6576
.define_method(
6677
"_eql?",
6778
[](Variable& self, Variable &other) {

ext/or-tools/network_flows.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void init_network_flows(Rice::Module& m) {
4747

4848
Array ret;
4949
for (const auto& it : result) {
50-
ret.push(it);
50+
ret.push(it, false);
5151
}
5252
return ret;
5353
})
@@ -59,7 +59,7 @@ void init_network_flows(Rice::Module& m) {
5959

6060
Array ret;
6161
for (const auto& it : result) {
62-
ret.push(it);
62+
ret.push(it, false);
6363
}
6464
return ret;
6565
});

ext/or-tools/routing.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,34 @@ namespace Rice::detail {
3636
template<>
3737
class From_Ruby<RoutingNodeIndex> {
3838
public:
39+
From_Ruby() = default;
40+
41+
explicit From_Ruby(Arg* arg) : arg_(arg) { }
42+
3943
Convertible is_convertible(VALUE value) { return Convertible::Cast; }
4044

4145
RoutingNodeIndex convert(VALUE x) {
4246
const RoutingNodeIndex index{From_Ruby<int>().convert(x)};
4347
return index;
4448
}
49+
50+
private:
51+
Arg* arg_ = nullptr;
4552
};
4653

4754
template<>
4855
class To_Ruby<RoutingNodeIndex> {
4956
public:
57+
To_Ruby() = default;
58+
59+
explicit To_Ruby(Arg* arg) : arg_(arg) { }
60+
5061
VALUE convert(RoutingNodeIndex const & x) {
5162
return To_Ruby<int>().convert(x.value());
5263
}
64+
65+
private:
66+
Arg* arg_ = nullptr;
5367
};
5468
} // namespace Rice::detail
5569

@@ -62,7 +76,7 @@ void init_routing(Rice::Module& m) {
6276
rb_cRoutingSearchParameters
6377
.define_method(
6478
"first_solution_strategy=",
65-
[](RoutingSearchParameters& self, Symbol value) {
79+
[](RoutingSearchParameters& self, Object value) {
6680
auto s = Symbol(value).str();
6781

6882
FirstSolutionStrategy::Value v;
@@ -102,7 +116,7 @@ void init_routing(Rice::Module& m) {
102116
})
103117
.define_method(
104118
"local_search_metaheuristic=",
105-
[](RoutingSearchParameters& self, Symbol value) {
119+
[](RoutingSearchParameters& self, Object value) {
106120
auto s = Symbol(value).str();
107121

108122
LocalSearchMetaheuristic::Value v;

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.5.0"
19+
spec.add_dependency "rice", ">= 4.7"
2020
end

0 commit comments

Comments
 (0)