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

Function dopost

gecode/float/linear/post.cpp:118–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116 }
117
118 void
119 dopost(Home home, Term* t, int n, FloatRelType frt, FloatVal c) {
120 Limits::check(c,"Float::linear");
121
122 for (int i=n; i--; ) {
123 if ((t[i].a.min() < 0.0) && (t[i].a.max() > 0.0))
124 throw ValueMixedSign("Float::linear[coefficient]");
125 if (t[i].x.assigned()) {
126 c -= t[i].a * t[i].x.val();
127 t[i]=t[--n];
128 }
129 }
130
131 if ((c < Limits::min) || (c > Limits::max) || overflow(t, n, c))
132 throw OutOfLimits("Float::linear");
133
134 /*
135 * Join coefficients for aliased variables:
136 *
137 */
138 {
139 // Group same variables
140 TermLess tl;
141 Support::quicksort<Term,TermLess>(t,n,tl);
142
143 // Join adjacent variables
144 int i = 0;
145 int j = 0;
146 while (i < n) {
147 Limits::check(t[i].a,"Float::linear");
148 FloatVal a = t[i].a;
149 FloatView x = t[i].x;
150 while ((++i < n) && (t[i].x == x)) {
151 a += t[i].a;
152 Limits::check(a,"Float::linear");
153 }
154 if (a != 0.0) {
155 t[j].a = a; t[j].x = x; j++;
156 }
157 }
158 n = j;
159 }
160
161 Term *t_p, *t_n;
162 int n_p, n_n;
163
164 /*
165 * Partition into positive/negative coefficients
166 *
167 */
168 if (n > 0) {
169 int i = 0;
170 int j = n-1;
171 while (true) {
172 while ((t[j].a < 0) && (--j >= 0)) ;
173 while ((t[i].a > 0) && (++i < n)) ;
174 if (j <= i) break;
175 std::swap(t[i],t[j]);

Callers 1

postFunction · 0.85

Calls 9

overflowFunction · 0.85
checkFunction · 0.50
ScaleViewClass · 0.50
minMethod · 0.45
maxMethod · 0.45
assignedMethod · 0.45
valMethod · 0.45
inMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected