38 #include "scip/type_misc.h"
40 #include "scip/pub_misc.h"
61 SCIPsortIntIntReal(row, col, val, length);
65 while (nextentry < length)
67 firstentry = nextentry;
69 while (nextentry < length && row[nextentry] == row[firstentry])
75 SCIPsortIntReal(col + firstentry, val + firstentry, nextentry - firstentry);
95 SCIP_Bool originsorted,
116 assert ( blkmem != NULL );
117 assert ( originlength == 0 || (originlength > 0 && originrow != NULL && origincol != NULL && originval != NULL) );
118 assert ( targetrow != NULL );
119 assert ( targetcol != NULL );
120 assert ( targetval != NULL );
121 assert ( targetlength != NULL );
122 assert ( *targetlength >= 0 );
127 if ( ! (originsorted) )
136 for (i = 0; i < originlength; i++)
142 while (ind < *targetlength && (targetrow[ind] < originrow[i] || (targetrow[ind] == originrow[i] && targetcol[ind] < origincol[i])))
145 if ( nleftshifts > 0 )
147 targetrow[ind - nleftshifts] = targetrow[ind];
148 targetcol[ind - nleftshifts] = targetcol[ind];
149 targetval[ind - nleftshifts] = targetval[ind];
154 if ( ind < *targetlength && (targetrow[ind] == originrow[i] && targetcol[ind] == origincol[i]) )
159 if ( nleftshifts > 0 )
161 targetrow[ind - nleftshifts] = targetrow[ind];
162 targetcol[ind - nleftshifts] = targetcol[ind];
164 targetval[ind - nleftshifts] = targetval[ind] + scalar * originval[i];
168 while (i + 1 < originlength && originrow[i + 1] == targetrow[ind - nleftshifts] && origincol[i + 1] == targetcol[ind - nleftshifts])
170 targetval[ind - nleftshifts] += scalar * originval[i + 1];
174 if ( REALABS(targetval[ind - nleftshifts]) < feastol )
183 if ( nleftshifts > 0 )
186 insertionpos = ind - nleftshifts;
192 insertionpos = *targetlength + naddednonz;
196 if ( insertionpos < targetmemory )
199 targetrow[insertionpos] = originrow[i];
200 targetcol[insertionpos] = origincol[i];
201 targetval[insertionpos] = scalar * originval[i];
204 while (i + 1 < originlength && originrow[i + 1] == targetrow[insertionpos] && origincol[i + 1] == targetcol[insertionpos])
206 targetval[insertionpos] += scalar * originval[i + 1];
211 if ( REALABS(targetval[insertionpos]) < feastol )
214 if ( insertionpos < ind )
225 if ( nleftshifts > 0 )
227 while (ind < *targetlength + naddednonz && ind < targetmemory)
229 targetrow[ind - nleftshifts] = targetrow[ind];
230 targetcol[ind - nleftshifts] = targetcol[ind];
231 targetval[ind - nleftshifts] = targetval[ind];
237 SCIPdebugMessage(
"insufficient memory given for SCIPsdpVarfixerMergeArrays, targetmemorys had length %d, would have needed up to %d\n",
238 targetmemory, *targetlength + naddednonz);
240 *targetlength = *targetlength + naddednonz - nleftshifts;
264 SCIP_Real* secondval,
268 SCIP_Real* targetval,
278 assert ( blkmem != NULL );
279 assert ( firstlength == 0 || (firstlength > 0 && firstrow != NULL && firstcol != NULL && firstval != NULL ) );
280 assert ( secondlength == 0 || (secondlength > 0 && secondrow != NULL && secondcol != NULL && secondval != NULL ) );
281 assert ( targetrow != NULL );
282 assert ( targetcol != NULL );
283 assert ( targetval != NULL );
284 assert ( targetlength != NULL );
285 assert ( *targetlength >= 0 );
299 while (firstind < firstlength && secondind < secondlength)
303 if ( firstrow[firstind] < secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] < secondcol[secondind]) )
305 if ( targetind < *targetlength )
307 targetrow[targetind] = firstrow[firstind];
308 targetcol[targetind] = firstcol[firstind];
309 targetval[targetind] = firstval[firstind];
318 else if ( firstrow[firstind] > secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] > secondcol[secondind]) )
320 if ( targetind < *targetlength )
322 targetrow[targetind] = secondrow[secondind];
323 targetcol[targetind] = secondcol[secondind];
324 targetval[targetind] = secondval[secondind];
332 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
334 if ( targetind < *targetlength )
335 targetval[targetind] += secondval[secondind];
341 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
347 if ( targetind < *targetlength )
349 targetrow[targetind] = firstrow[firstind];
350 targetcol[targetind] = firstcol[firstind];
351 targetval[targetind] = firstval[firstind] + secondval[secondind];
360 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
362 if ( targetind < *targetlength )
363 targetval[targetind] += secondval[secondind];
369 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
376 while (firstind < firstlength)
378 if ( targetind < *targetlength )
380 targetrow[targetind] = firstrow[firstind];
381 targetcol[targetind] = firstcol[firstind];
382 targetval[targetind] = firstval[firstind];
390 while (secondind < secondlength)
392 if ( targetind < *targetlength )
394 targetrow[targetind] = secondrow[secondind];
395 targetcol[targetind] = secondcol[secondind];
396 targetval[targetind] = secondval[secondind];
404 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
406 if ( targetind < *targetlength )
407 targetval[targetind] += secondval[secondind];
413 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= feastol )
419 SCIPdebugMessage(
"Insufficient arraylength in SCIPsdpVarfixerMergeArraysIntoNew, given targetarray-length was %d, would have needed %d",
420 *targetlength, targetind);
423 *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...