Skip to content

Commit

Permalink
Removed Rice conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 7, 2024
1 parent e2c3168 commit c8f3c88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
32 changes: 11 additions & 21 deletions ext/or-tools/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,6 @@ namespace Rice::detail
return expr;
}
};

template<>
class From_Ruby<std::vector<BoolVar>>
{
public:
std::vector<BoolVar> convert(VALUE v)
{
auto a = Array(v);
std::vector<BoolVar> vec;
vec.reserve(a.size());
for (const Object v : a) {
if (v.is_a(rb_cSatIntVar)) {
vec.push_back(From_Ruby<IntVar>().convert(v.value()).ToBoolVar());
} else {
vec.push_back(From_Ruby<BoolVar>().convert(v.value()));
}
}
return vec;
}
};
}

void init_constraint(Rice::Module& m) {
Expand All @@ -110,7 +90,17 @@ void init_constraint(Rice::Module& m) {
return self.OnlyEnforceIf(Rice::detail::From_Ruby<IntVar>().convert(literal).ToBoolVar());
} else if (literal.is_a(rb_cArray)) {
// TODO support IntVarSpan
return self.OnlyEnforceIf(Rice::detail::From_Ruby<std::vector<BoolVar>>().convert(literal));
auto a = Array(literal);
std::vector<BoolVar> vec;
vec.reserve(a.size());
for (const Object v : a) {
if (v.is_a(rb_cSatIntVar)) {
vec.push_back(Rice::detail::From_Ruby<IntVar>().convert(v.value()).ToBoolVar());
} else {
vec.push_back(Rice::detail::From_Ruby<BoolVar>().convert(v.value()));
}
}
return self.OnlyEnforceIf(vec);
} else {
return self.OnlyEnforceIf(Rice::detail::From_Ruby<BoolVar>().convert(literal));
}
Expand Down
13 changes: 0 additions & 13 deletions ext/or-tools/routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ namespace Rice::detail
};
}

namespace Rice::detail
{
template<class T, class U>
class To_Ruby<std::pair<T, U>>
{
public:
VALUE convert(std::pair<T, U> const & x)
{
return rb_ary_new3(2, To_Ruby<T>().convert(x.first), To_Ruby<U>().convert(x.second));
}
};
}

void init_routing(Rice::Module& m) {
auto rb_cRoutingSearchParameters = Rice::define_class_under<RoutingSearchParameters>(m, "RoutingSearchParameters");
auto rb_cIntVar = Rice::define_class_under<operations_research::IntVar>(m, "IntVar");
Expand Down

0 comments on commit c8f3c88

Please sign in to comment.