@@ -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
7099void init_routing (Rice::Module& m) {
@@ -297,9 +326,6 @@ void init_routing(Rice::Module& m) {
297326 return operations_research::DefaultRoutingModelParameters ();
298327 });
299328
300- // keep Rice happy
301- Rice::define_enum_under<RoutingModel::PenaltyCostBehavior>(" PenaltyCostBehavior" , m);
302-
303329 Rice::define_class_under<RoutingModel::ResourceGroup>(m, " ResourceGroup" );
304330
305331 Rice::define_class_under<RoutingModel>(m, " RoutingModel" )
@@ -350,7 +376,7 @@ void init_routing(Rice::Module& m) {
350376 .define_method (" add_resource_group" , &RoutingModel::AddResourceGroup)
351377 .define_method (" dimension_resource_group_indices" , &RoutingModel::GetDimensionResourceGroupIndices)
352378 .define_method (" dimension_resource_group_index" , &RoutingModel::GetDimensionResourceGroupIndex)
353- .define_method (" add_disjunction " , &RoutingModel::AddDisjunction, Rice::Arg ( " _indices " ), Rice::Arg ( " _penalty " ), Rice::Arg ( " _max_cardinality " ) = static_cast < int64_t >( 1 ), Rice::Arg ( " _penalty_cost_behavior " ) = RoutingModel::PenaltyCostBehavior:: PENALIZE_ONCE )
379+ .define_method (" _add_disjunction " , &RoutingModel::AddDisjunction)
354380 .define_method (" disjunction_indices" , &RoutingModel::GetDisjunctionIndices)
355381 .define_method (" disjunction_penalty" , &RoutingModel::GetDisjunctionPenalty)
356382 .define_method (" disjunction_max_cardinality" , &RoutingModel::GetDisjunctionMaxCardinality)
0 commit comments