38 #include "scip/type_misc.h"
40 #include "scip/pub_misc.h"
57 SCIPsortIntIntReal(row, col, val, length);
61 while (nextentry < length)
63 firstentry = nextentry;
65 while (nextentry < length && row[nextentry] == row[firstentry])
71 SCIPsortIntReal(col + firstentry, val + firstentry, nextentry - firstentry);
90 SCIP_Bool originsorted,
111 assert ( blkmem != NULL );
112 assert ( originlength == 0 || (originlength > 0 && originrow != NULL && origincol != NULL && originval != NULL) );
113 assert ( targetrow != NULL );
114 assert ( targetcol != NULL );
115 assert ( targetval != NULL );
116 assert ( targetlength != NULL );
117 assert ( *targetlength >= 0 );
122 if ( ! (originsorted) )
131 for (i = 0; i < originlength; i++)
137 while (ind < *targetlength && (targetrow[ind] < originrow[i] || (targetrow[ind] == originrow[i] && targetcol[ind] < origincol[i])))
140 if ( nleftshifts > 0 )
142 targetrow[ind - nleftshifts] = targetrow[ind];
143 targetcol[ind - nleftshifts] = targetcol[ind];
144 targetval[ind - nleftshifts] = targetval[ind];
149 if ( ind < *targetlength && (targetrow[ind] == originrow[i] && targetcol[ind] == origincol[i]) )
154 if ( nleftshifts > 0 )
156 targetrow[ind - nleftshifts] = targetrow[ind];
157 targetcol[ind - nleftshifts] = targetcol[ind];
159 targetval[ind - nleftshifts] = targetval[ind] + scalar * originval[i];
163 while (i + 1 < originlength && originrow[i + 1] == targetrow[ind - nleftshifts] && origincol[i + 1] == targetcol[ind - nleftshifts])
165 targetval[ind - nleftshifts] += scalar * originval[i + 1];
169 if ( REALABS(targetval[ind - nleftshifts]) < feastol )
178 if ( nleftshifts > 0 )
181 insertionpos = ind - nleftshifts;
187 insertionpos = *targetlength + naddednonz;
191 if ( insertionpos < targetmemory )
194 targetrow[insertionpos] = originrow[i];
195 targetcol[insertionpos] = origincol[i];
196 targetval[insertionpos] = scalar * originval[i];
199 while (i + 1 < originlength && originrow[i + 1] == targetrow[insertionpos] && origincol[i + 1] == targetcol[insertionpos])
201 targetval[insertionpos] += scalar * originval[i + 1];
206 if ( REALABS(targetval[insertionpos]) < feastol )
209 if ( insertionpos < ind )
220 if ( nleftshifts > 0 )
222 while (ind < *targetlength + naddednonz && ind < targetmemory)
224 targetrow[ind - nleftshifts] = targetrow[ind];
225 targetcol[ind - nleftshifts] = targetcol[ind];
226 targetval[ind - nleftshifts] = targetval[ind];
232 SCIPdebugMessage(
"insufficient memory given for SCIPsdpVarfixerMergeArrays, targetmemorys had length %d, would have needed up to %d\n",
233 targetmemory, *targetlength + naddednonz);
235 *targetlength = *targetlength + naddednonz - nleftshifts;
258 SCIP_Real* secondval,
262 SCIP_Real* targetval,
272 assert ( blkmem != NULL );
273 assert ( firstlength == 0 || (firstlength > 0 && firstrow != NULL && firstcol != NULL && firstval != NULL ) );
274 assert ( secondlength == 0 || (secondlength > 0 && secondrow != NULL && secondcol != NULL && secondval != NULL ) );
275 assert ( targetrow != NULL );
276 assert ( targetcol != NULL );
277 assert ( targetval != NULL );
278 assert ( targetlength != NULL );
279 assert ( *targetlength >= 0 );
293 while (firstind < firstlength && secondind < secondlength)
297 if ( firstrow[firstind] < secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] < secondcol[secondind]) )
299 if ( targetind < *targetlength )
301 targetrow[targetind] = firstrow[firstind];
302 targetcol[targetind] = firstcol[firstind];
303 targetval[targetind] = firstval[firstind];
312 else if ( firstrow[firstind] > secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] > secondcol[secondind]) )
314 if ( targetind < *targetlength )
316 targetrow[targetind] = secondrow[secondind];
317 targetcol[targetind] = secondcol[secondind];
318 targetval[targetind] = secondval[secondind];
326 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
328 if ( targetind < *targetlength )
329 targetval[targetind] += secondval[secondind];
335 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
341 if ( targetind < *targetlength )
343 targetrow[targetind] = firstrow[firstind];
344 targetcol[targetind] = firstcol[firstind];
345 targetval[targetind] = firstval[firstind] + secondval[secondind];
354 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
356 if ( targetind < *targetlength )
357 targetval[targetind] += secondval[secondind];
363 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
370 while (firstind < firstlength)
372 if ( targetind < *targetlength )
374 targetrow[targetind] = firstrow[firstind];
375 targetcol[targetind] = firstcol[firstind];
376 targetval[targetind] = firstval[firstind];
384 while (secondind < secondlength)
386 if ( targetind < *targetlength )
388 targetrow[targetind] = secondrow[secondind];
389 targetcol[targetind] = secondcol[secondind];
390 targetval[targetind] = secondval[secondind];
398 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
400 if ( targetind < *targetlength )
401 targetval[targetind] += secondval[secondind];
407 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
413 SCIPdebugMessage(
"Insufficient arraylength in SCIPsdpVarfixerMergeArraysIntoNew, given targetarray-length was %d, would have needed %d",
414 *targetlength, targetind);
417 *targetlength = targetind;
void SCIPsdpVarfixerSortRowCol(int *row, int *col, SCIP_Real *val, int length)
SCIP_RETCODE SCIPsdpVarfixerMergeArraysIntoNew(BMS_BLKMEM *blkmem, SCIP_Real feastol, int *firstrow, int *firstcol, SCIP_Real *firstval, int firstlength, int *secondrow, int *secondcol, SCIP_Real *secondval, int secondlength, int *targetrow, int *targetcol, SCIP_Real *targetval, int *targetlength)
SCIP_RETCODE SCIPsdpVarfixerMergeArrays(BMS_BLKMEM *blkmem, SCIP_Real feastol, int *originrow, int *origincol, SCIP_Real *originval, int originlength, SCIP_Bool originsorted, SCIP_Real scalar, int *targetrow, int *targetcol, SCIP_Real *targetval, int *targetlength, int targetmemory)
adds the main functionality to fix/unfix/(multi-)aggregate variables by merging two three-tuple-array...