Skip to content

Commit 181b688

Browse files
authored
Add way to get upper and lower bounds of SatIntVar (#45)
1 parent f7da633 commit 181b688

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.1 (2023-03-17)
2+
3+
- Add way to get upper and lower bounds of `SatIntVar`
4+
15
## 0.10.0 (2023-03-15)
26

37
- Updated OR-Tools to 9.6

ext/or-tools/constraint.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "ext.h"
55

6+
using operations_research::Domain;
67
using operations_research::sat::BoolVar;
78
using operations_research::sat::Constraint;
89
using operations_research::sat::CpModelBuilder;
@@ -98,8 +99,13 @@ namespace Rice::detail
9899
}
99100

100101
void init_constraint(Rice::Module& m) {
102+
Rice::define_class_under<Domain>(m, "Domain")
103+
.define_method("min", &Domain::Min)
104+
.define_method("max", &Domain::Max);
105+
101106
rb_cSatIntVar = Rice::define_class_under<IntVar>(m, "SatIntVar")
102-
.define_method("name", &IntVar::Name);
107+
.define_method("name", &IntVar::Name)
108+
.define_method("domain", &IntVar::Domain);
103109

104110
Rice::define_class_under<IntervalVar>(m, "SatIntervalVar")
105111
.define_method("name", &IntervalVar::Name);

test/constraint_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ def test_add_hint
234234
end
235235
end
236236

237+
def test_int_var_domain
238+
model = ORTools::CpModel.new
239+
240+
lower_bound = (0..9).to_a.sample
241+
upper_bound = (10..19).to_a.sample
242+
x = model.new_int_var(lower_bound, upper_bound, "x")
243+
244+
assert_equal lower_bound, x.domain.min
245+
assert_equal upper_bound, x.domain.max
246+
end
247+
237248
def test_sum_empty_true
238249
model = ORTools::CpModel.new
239250
model.add([].sum < 2)

0 commit comments

Comments
 (0)