1+ #include < string>
2+ #include < vector>
3+
14#include < google/protobuf/text_format.h>
25#include < ortools/sat/cp_model.h>
3-
4- #include " ext.h "
6+ # include < rice/rice.hpp >
7+ #include < rice/stl.hpp >
58
69using operations_research::Domain;
710using operations_research::sat::BoolVar;
811using operations_research::sat::Constraint;
12+ using operations_research::sat::TableConstraint;
913using operations_research::sat::CpModelBuilder;
1014using operations_research::sat::CpSolverResponse;
1115using operations_research::sat::CpSolverStatus;
@@ -27,23 +31,22 @@ using Rice::Symbol;
2731Class rb_cBoolVar;
2832Class rb_cSatIntVar;
2933
30- namespace Rice ::detail
31- {
34+ namespace Rice ::detail {
3235 template <>
33- struct Type <LinearExpr>
34- {
35- static bool verify ()
36- {
37- return true ;
38- }
36+ struct Type <LinearExpr> {
37+ static bool verify () { return true ; }
3938 };
4039
4140 template <>
42- class From_Ruby <LinearExpr>
43- {
41+ class From_Ruby <LinearExpr> {
4442 public:
45- LinearExpr convert (VALUE v)
46- {
43+ From_Ruby () = default ;
44+
45+ explicit From_Ruby (Arg* arg) : arg_(arg) { }
46+
47+ double is_convertible (VALUE value) { return Convertible::Exact; }
48+
49+ LinearExpr convert (VALUE v) {
4750 LinearExpr expr;
4851
4952 Rice::Object utils = Rice::define_module (" ORTools" ).const_get (" Utils" );
@@ -64,12 +67,16 @@ namespace Rice::detail
6467
6568 return expr;
6669 }
70+
71+ private:
72+ Arg* arg_ = nullptr ;
6773 };
68- }
74+ } // namespace Rice::detail
6975
7076void init_constraint (Rice::Module& m) {
7177 Rice::define_class_under<Domain>(m, " Domain" )
7278 .define_constructor (Rice::Constructor<Domain, int64_t , int64_t >())
79+ .define_singleton_function (" from_values" , &Domain::FromValues)
7380 .define_method (" min" , &Domain::Min)
7481 .define_method (" max" , &Domain::Max);
7582
@@ -104,6 +111,13 @@ void init_constraint(Rice::Module& m) {
104111 }
105112 });
106113
114+ Rice::define_class_under<TableConstraint, Constraint>(m, " SatTableConstraint" )
115+ .define_method (
116+ " add_tuple" ,
117+ [](TableConstraint& self, std::vector<int64_t > tuple) {
118+ self.AddTuple (tuple);
119+ });
120+
107121 rb_cBoolVar = Rice::define_class_under<BoolVar>(m, " SatBoolVar" )
108122 .define_method (" name" , &BoolVar::Name)
109123 .define_method (" index" , &BoolVar::index)
@@ -252,6 +266,16 @@ void init_constraint(Rice::Module& m) {
252266 [](CpModelBuilder& self, std::vector<IntVar> vars) {
253267 return self.AddAllDifferent (vars);
254268 })
269+ .define_method (
270+ " add_allowed_assignments" ,
271+ [](CpModelBuilder& self, std::vector<LinearExpr> expressions) {
272+ return self.AddAllowedAssignments (expressions);
273+ })
274+ .define_method (
275+ " add_forbidden_assignments" ,
276+ [](CpModelBuilder& self, std::vector<LinearExpr> expressions) {
277+ return self.AddForbiddenAssignments (expressions);
278+ })
255279 .define_method (
256280 " add_inverse_constraint" ,
257281 [](CpModelBuilder& self, std::vector<IntVar> variables, std::vector<IntVar> inverse_variables) {
@@ -392,7 +416,7 @@ void init_constraint(Rice::Module& m) {
392416 auto a = Array ();
393417 auto assumptions = self.sufficient_assumptions_for_infeasibility ();
394418 for (const auto & v : assumptions) {
395- a.push (v);
419+ a.push (v, false );
396420 }
397421 return a;
398422 });
0 commit comments