MCPcopy Create free account
hub / github.com/Gecode/gecode / prop_val

Function prop_val

gecode/int/gcc/val.hpp:91–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90 template<class Card>
91 ExecStatus
92 prop_val(Space& home, Propagator& p,
93 ViewArray<IntView>& x, ViewArray<Card>& k) {
94 assert(x.size() > 0);
95
96 Region r;
97 // count[i] denotes how often value k[i].card() occurs in x
98 int* count = r.alloc<int>(k.size());
99
100 // initialization
101 int sum_min = 0;
102 int removed = 0;
103 for (int i=0; i<k.size(); i++) {
104 removed += k[i].counter();
105 sum_min += k[i].min();
106 count[i] = 0;
107 }
108
109 // less than or equal than the total number of free variables
110 // to satisfy the required occurrences
111 for (int i=0; i<k.size(); i++)
112 GECODE_ME_CHECK(k[i].lq(home, x.size()+removed-(sum_min - k[i].min())));
113
114 // number of unassigned views
115 int non = x.size();
116
117 for (int i=0; i<x.size(); i++)
118 if (x[i].assigned()) {
119 int idx;
120 if (!lookupValue(k,x[i].val(),idx)) {
121 return ES_FAILED;
122 }
123 count[idx]++;
124 non--;
125 }
126
127 // check for subsumption
128 if (non == 0) {
129 for (int i=0; i<k.size(); i++)
130 GECODE_ME_CHECK((k[i].eq(home, count[i] + k[i].counter())));
131 return home.ES_SUBSUMED(p);
132 }
133
134 // total number of unsatisfied miminum occurrences
135 int req = 0;
136 // number of values whose min requirements are not yet met
137 int n_r = 0;
138 // if only one value is unsatisified single holds the index of that value
139 int single = -1;
140 // total number of assigned views wrt. the original problem size
141 int t_noa = 0;
142
143 for (int i = k.size(); i--; ) {
144 int ci = count[i] + k[i].counter();
145 t_noa += ci;
146 if (ci == 0) { // this works
147 req += k[i].min();
148 n_r++;

Callers

nothing calls this directly

Calls 15

lookupValueFunction · 0.85
quicksortFunction · 0.85
counterMethod · 0.80
ES_SUBSUMEDMethod · 0.80
iFunction · 0.50
sizeMethod · 0.45
minMethod · 0.45
lqMethod · 0.45
assignedMethod · 0.45
valMethod · 0.45
eqMethod · 0.45
cardMethod · 0.45

Tested by

no test coverage detected