Skip to content

Commit a54aabb

Browse files
SaGagnonchschulte
authored andcommitted
Using regions in distinct/cbs.hpp instead of std::vectors.
1 parent c56aa25 commit a54aabb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

gecode/int/distinct/cbs.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#ifdef GECODE_HAS_CBS
3535

36-
#include <vector>
3736
#include <limits>
3837
#include <algorithm>
3938

@@ -75,14 +74,18 @@ class ValToUpdate {
7574
private:
7675
const size_t width;
7776
const int minVal;
78-
std::vector<double> mincUpdate;
79-
std::vector<double> liangUpdate;
77+
Region r;
78+
double* mincUpdate;
79+
double* liangUpdate;
8080
public:
8181
template<class View>
8282
ValToUpdate(const ViewArray<View>& x, int minDomVal, int maxDomVal)
83-
: width(maxDomVal - minDomVal + 1), minVal(minDomVal),
84-
mincUpdate(width, 1.0),
85-
liangUpdate(width, 1.0) {
83+
: width(maxDomVal - minDomVal + 1),
84+
minVal(minDomVal) {
85+
mincUpdate = r.alloc<double>(width);
86+
std::fill(mincUpdate, mincUpdate + width, 1);
87+
liangUpdate = r.alloc<double>(width);
88+
std::fill(liangUpdate, liangUpdate + width, 1);
8689

8790
for (int i=0; i<x.size(); i++) {
8891
if (x[i].assigned()) continue;
@@ -120,7 +123,7 @@ void cbsdistinct(Space&, unsigned int prop_id, const ViewArray<View>& x,
120123
UB ub{1,1};
121124
for (int i=0; i<x.size(); i++) {
122125
unsigned int s = x[i].size();
123-
if (s >= MAX_MINC_FACTORS || s >= WIDTH_LIANG_BAI_FACTORS)
126+
if ((s >= MAX_MINC_FACTORS) || (s >= WIDTH_LIANG_BAI_FACTORS))
124127
throw Gecode::Exception("Int::Distinct::cbsdistinct",
125128
"Variable cardinality too big for using counting-based"
126129
"search with distinct constraints");
@@ -143,7 +146,8 @@ void cbsdistinct(Space&, unsigned int prop_id, const ViewArray<View>& x,
143146

144147
// Preallocated memory for holding solution counts for all values of a
145148
// variable during computation
146-
std::vector<double> solCounts(maxVal - minVal + 1);
149+
Region r;
150+
double* solCounts = r.alloc<double>(maxVal - minVal + 1);
147151

148152
for (int i=0; i<x.size(); i++) {
149153
if (x[i].assigned()) continue;

0 commit comments

Comments
 (0)