Skip to content

Commit 5d278dd

Browse files
committed
Add parts of IntView interface to NegBoolView, and fix min/max methods
1 parent 7390b0b commit 5d278dd

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

gecode/int/view.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,39 @@ namespace Gecode { namespace Int {
16191619
ModEvent zero_none(Space& home);
16201620
//@}
16211621

1622+
/// \name Domain update by value
1623+
//@{
1624+
/// Restrict domain values to be less or equal than \a n
1625+
ModEvent lq(Space& home, int n);
1626+
/// Restrict domain values to be less or equal than \a n
1627+
ModEvent lq(Space& home, long long int n);
1628+
1629+
/// Restrict domain values to be less than \a n
1630+
ModEvent le(Space& home, int n);
1631+
/// Restrict domain values to be less than \a n
1632+
ModEvent le(Space& home, long long int n);
1633+
1634+
/// Restrict domain values to be greater or equal than \a n
1635+
ModEvent gq(Space& home, int n);
1636+
/// Restrict domain values to be greater or equal than \a n
1637+
ModEvent gq(Space& home, long long int n);
1638+
1639+
/// Restrict domain values to be greater than \a n
1640+
ModEvent gr(Space& home, int n);
1641+
/// Restrict domain values to be greater than \a n
1642+
ModEvent gr(Space& home, long long int n);
1643+
1644+
/// Restrict domain values to be different from \a n
1645+
ModEvent nq(Space& home, int n);
1646+
/// Restrict domain values to be different from \a n
1647+
ModEvent nq(Space& home, long long int n);
1648+
1649+
/// Restrict domain values to be equal to \a n
1650+
ModEvent eq(Space& home, int n);
1651+
/// Restrict domain values to be equal to \a n
1652+
ModEvent eq(Space& home, long long int n);
1653+
//@}
1654+
16221655
/// \name Value access
16231656
//@{
16241657
/// Return minimum of domain

gecode/int/view/neg-bool.hpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,70 @@ namespace Gecode { namespace Int {
9797
return x.zero(home);
9898
}
9999

100+
/* Domain update by value
101+
*
102+
*/
100103

104+
forceinline ModEvent
105+
NegBoolView::lq(Space& home, int n) {
106+
return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
107+
}
108+
forceinline ModEvent
109+
NegBoolView::lq(Space& home, long long int n) {
110+
return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
111+
}
112+
forceinline ModEvent
113+
NegBoolView::le(Space& home, int n) {
114+
return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
115+
}
116+
forceinline ModEvent
117+
NegBoolView::le(Space& home, long long int n) {
118+
return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
119+
}
120+
forceinline ModEvent
121+
NegBoolView::gq(Space& home, int n) {
122+
return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
123+
}
124+
forceinline ModEvent
125+
NegBoolView::gq(Space& home, long long int n) {
126+
return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
127+
}
128+
forceinline ModEvent
129+
NegBoolView::gr(Space& home, int n) {
130+
return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
131+
}
132+
forceinline ModEvent
133+
NegBoolView::gr(Space& home, long long int n) {
134+
return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
135+
}
136+
forceinline ModEvent
137+
NegBoolView::nq(Space& home, int n) {
138+
return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
139+
}
140+
forceinline ModEvent
141+
NegBoolView::nq(Space& home, long long int n) {
142+
return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
143+
}
144+
forceinline ModEvent
145+
NegBoolView::eq(Space& home, int n) {
146+
return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
147+
}
148+
forceinline ModEvent
149+
NegBoolView::eq(Space& home, long long int n) {
150+
return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
151+
}
152+
101153
/*
102154
* Value access
103155
*
104156
*/
105157
forceinline int
106158
NegBoolView::min(void) const {
107-
return x.max();
159+
return 1-x.max();
108160
}
109161
forceinline int
110162
NegBoolView::max(void) const {
111-
return x.min();
163+
return 1-x.min();
112164
}
113165
forceinline int
114166
NegBoolView::val(void) const {

0 commit comments

Comments
 (0)