38 #include "scip/type_misc.h" 40 #include "scip/pub_message.h" 41 #include "scip/pub_misc.h" 48 #define SORTTPL_NAMEEXT IntIntReal 49 #define SORTTPL_KEYTYPE int 50 #define SORTTPL_FIELD1TYPE SCIP_Real 64 SCIPlexSortIntIntReal(row, col, val, length);
69 for (j = 0; j < length-1; ++j)
71 assert( row[j] <= row[j+1] );
72 assert( row[j] != row[j+1] || col[j] <= col[j+1] );
93 SCIP_Bool originsorted,
114 assert ( blkmem != NULL );
115 assert ( originlength == 0 || (originlength > 0 && originrow != NULL && origincol != NULL && originval != NULL) );
116 assert ( targetrow != NULL );
117 assert ( targetcol != NULL );
118 assert ( targetval != NULL );
119 assert ( targetlength != NULL );
120 assert ( *targetlength >= 0 );
125 if ( ! originsorted )
134 for (i = 0; i < originlength; i++)
140 while (ind < *targetlength && (targetrow[ind] < originrow[i] || (targetrow[ind] == originrow[i] && targetcol[ind] < origincol[i])))
143 if ( nleftshifts > 0 )
145 targetrow[ind - nleftshifts] = targetrow[ind];
146 targetcol[ind - nleftshifts] = targetcol[ind];
147 targetval[ind - nleftshifts] = targetval[ind];
152 if ( ind < *targetlength && (targetrow[ind] == originrow[i] && targetcol[ind] == origincol[i]) )
157 if ( nleftshifts > 0 )
159 targetrow[ind - nleftshifts] = targetrow[ind];
160 targetcol[ind - nleftshifts] = targetcol[ind];
162 targetval[ind - nleftshifts] = targetval[ind] + scalar * originval[i];
166 while (i + 1 < originlength && originrow[i + 1] == targetrow[ind - nleftshifts] && origincol[i + 1] == targetcol[ind - nleftshifts])
168 targetval[ind - nleftshifts] += scalar * originval[i + 1];
172 if ( REALABS(targetval[ind - nleftshifts]) < epsilon )
181 if ( nleftshifts > 0 )
184 insertionpos = ind - nleftshifts;
190 insertionpos = *targetlength + naddednonz;
194 if ( insertionpos < targetmemory )
197 targetrow[insertionpos] = originrow[i];
198 targetcol[insertionpos] = origincol[i];
199 targetval[insertionpos] = scalar * originval[i];
202 while (i + 1 < originlength && originrow[i + 1] == targetrow[insertionpos] && origincol[i + 1] == targetcol[insertionpos])
204 targetval[insertionpos] += scalar * originval[i + 1];
209 if ( REALABS(targetval[insertionpos]) < epsilon )
212 if ( insertionpos < ind )
223 if ( nleftshifts > 0 )
225 while (ind < *targetlength + naddednonz && ind < targetmemory)
227 targetrow[ind - nleftshifts] = targetrow[ind];
228 targetcol[ind - nleftshifts] = targetcol[ind];
229 targetval[ind - nleftshifts] = targetval[ind];
235 SCIPdebugMessage(
"insufficient memory given for SCIPsdpVarfixerMergeArrays, targetmemorys had length %d, would have needed up to %d\n",
236 targetmemory, *targetlength + naddednonz);
238 *targetlength = *targetlength + naddednonz - nleftshifts;
261 SCIP_Real* secondval,
265 SCIP_Real* targetval,
275 assert ( blkmem != NULL );
276 assert ( firstlength == 0 || (firstlength > 0 && firstrow != NULL && firstcol != NULL && firstval != NULL ) );
277 assert ( secondlength == 0 || (secondlength > 0 && secondrow != NULL && secondcol != NULL && secondval != NULL ) );
278 assert ( targetrow != NULL );
279 assert ( targetcol != NULL );
280 assert ( targetval != NULL );
281 assert ( targetlength != NULL );
282 assert ( *targetlength >= 0 );
296 while (firstind < firstlength && secondind < secondlength)
300 if ( firstrow[firstind] < secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] < secondcol[secondind]) )
302 if ( targetind < *targetlength )
304 targetrow[targetind] = firstrow[firstind];
305 targetcol[targetind] = firstcol[firstind];
306 targetval[targetind] = firstval[firstind];
315 else if ( firstrow[firstind] > secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] > secondcol[secondind]) )
317 if ( targetind < *targetlength )
319 targetrow[targetind] = secondrow[secondind];
320 targetcol[targetind] = secondcol[secondind];
321 targetval[targetind] = secondval[secondind];
329 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
331 if ( targetind < *targetlength )
332 targetval[targetind] += secondval[secondind];
338 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
344 if ( targetind < *targetlength )
346 targetrow[targetind] = firstrow[firstind];
347 targetcol[targetind] = firstcol[firstind];
348 targetval[targetind] = firstval[firstind] + secondval[secondind];
357 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
359 if ( targetind < *targetlength )
360 targetval[targetind] += secondval[secondind];
366 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
373 while (firstind < firstlength)
375 if ( targetind < *targetlength )
377 targetrow[targetind] = firstrow[firstind];
378 targetcol[targetind] = firstcol[firstind];
379 targetval[targetind] = firstval[firstind];
387 while (secondind < secondlength)
389 if ( targetind < *targetlength )
391 targetrow[targetind] = secondrow[secondind];
392 targetcol[targetind] = secondcol[secondind];
393 targetval[targetind] = secondval[secondind];
401 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
403 if ( targetind < *targetlength )
404 targetval[targetind] += secondval[secondind];
410 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
416 SCIPdebugMessage(
"Insufficient arraylength in SCIPsdpVarfixerMergeArraysIntoNew, given targetarray-length was %d, would have needed %d",
417 *targetlength, targetind);
420 *targetlength = targetind;
void SCIPsdpVarfixerSortRowCol(int *row, int *col, SCIP_Real *val, int length)
template functions for lexicographic sorting
adds the main functionality to fix/unfix/(multi-)aggregate variables by merging two three-tuple-array...
SCIP_RETCODE SCIPsdpVarfixerMergeArrays(BMS_BLKMEM *blkmem, SCIP_Real epsilon, 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)
SCIP_RETCODE SCIPsdpVarfixerMergeArraysIntoNew(BMS_BLKMEM *blkmem, SCIP_Real epsilon, 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)