38 #include "scip/type_misc.h"
40 #include "scip/pub_message.h"
41 #include "scip/pub_misc.h"
62 SCIPsortIntIntReal(row, col, val, length);
66 while (nextentry < length)
68 firstentry = nextentry;
70 while (nextentry < length && row[nextentry] == row[firstentry])
76 SCIPsortIntReal(col + firstentry, val + firstentry, nextentry - firstentry);
96 SCIP_Bool originsorted,
100 SCIP_Real* targetval,
117 assert ( blkmem != NULL );
118 assert ( originlength == 0 || (originlength > 0 && originrow != NULL && origincol != NULL && originval != NULL) );
119 assert ( targetrow != NULL );
120 assert ( targetcol != NULL );
121 assert ( targetval != NULL );
122 assert ( targetlength != NULL );
123 assert ( *targetlength >= 0 );
128 if ( ! (originsorted) )
137 for (i = 0; i < originlength; i++)
143 while (ind < *targetlength && (targetrow[ind] < originrow[i] || (targetrow[ind] == originrow[i] && targetcol[ind] < origincol[i])))
146 if ( nleftshifts > 0 )
148 targetrow[ind - nleftshifts] = targetrow[ind];
149 targetcol[ind - nleftshifts] = targetcol[ind];
150 targetval[ind - nleftshifts] = targetval[ind];
155 if ( ind < *targetlength && (targetrow[ind] == originrow[i] && targetcol[ind] == origincol[i]) )
160 if ( nleftshifts > 0 )
162 targetrow[ind - nleftshifts] = targetrow[ind];
163 targetcol[ind - nleftshifts] = targetcol[ind];
165 targetval[ind - nleftshifts] = targetval[ind] + scalar * originval[i];
169 while (i + 1 < originlength && originrow[i + 1] == targetrow[ind - nleftshifts] && origincol[i + 1] == targetcol[ind - nleftshifts])
171 targetval[ind - nleftshifts] += scalar * originval[i + 1];
175 if ( REALABS(targetval[ind - nleftshifts]) < epsilon )
184 if ( nleftshifts > 0 )
187 insertionpos = ind - nleftshifts;
193 insertionpos = *targetlength + naddednonz;
197 if ( insertionpos < targetmemory )
200 targetrow[insertionpos] = originrow[i];
201 targetcol[insertionpos] = origincol[i];
202 targetval[insertionpos] = scalar * originval[i];
205 while (i + 1 < originlength && originrow[i + 1] == targetrow[insertionpos] && origincol[i + 1] == targetcol[insertionpos])
207 targetval[insertionpos] += scalar * originval[i + 1];
212 if ( REALABS(targetval[insertionpos]) < epsilon )
215 if ( insertionpos < ind )
226 if ( nleftshifts > 0 )
228 while (ind < *targetlength + naddednonz && ind < targetmemory)
230 targetrow[ind - nleftshifts] = targetrow[ind];
231 targetcol[ind - nleftshifts] = targetcol[ind];
232 targetval[ind - nleftshifts] = targetval[ind];
238 SCIPdebugMessage(
"insufficient memory given for SCIPsdpVarfixerMergeArrays, targetmemorys had length %d, would have needed up to %d\n",
239 targetmemory, *targetlength + naddednonz);
241 *targetlength = *targetlength + naddednonz - nleftshifts;
265 SCIP_Real* secondval,
269 SCIP_Real* targetval,
279 assert ( blkmem != NULL );
280 assert ( firstlength == 0 || (firstlength > 0 && firstrow != NULL && firstcol != NULL && firstval != NULL ) );
281 assert ( secondlength == 0 || (secondlength > 0 && secondrow != NULL && secondcol != NULL && secondval != NULL ) );
282 assert ( targetrow != NULL );
283 assert ( targetcol != NULL );
284 assert ( targetval != NULL );
285 assert ( targetlength != NULL );
286 assert ( *targetlength >= 0 );
300 while (firstind < firstlength && secondind < secondlength)
304 if ( firstrow[firstind] < secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] < secondcol[secondind]) )
306 if ( targetind < *targetlength )
308 targetrow[targetind] = firstrow[firstind];
309 targetcol[targetind] = firstcol[firstind];
310 targetval[targetind] = firstval[firstind];
319 else if ( firstrow[firstind] > secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] > secondcol[secondind]) )
321 if ( targetind < *targetlength )
323 targetrow[targetind] = secondrow[secondind];
324 targetcol[targetind] = secondcol[secondind];
325 targetval[targetind] = secondval[secondind];
333 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
335 if ( targetind < *targetlength )
336 targetval[targetind] += secondval[secondind];
342 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
348 if ( targetind < *targetlength )
350 targetrow[targetind] = firstrow[firstind];
351 targetcol[targetind] = firstcol[firstind];
352 targetval[targetind] = firstval[firstind] + secondval[secondind];
361 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
363 if ( targetind < *targetlength )
364 targetval[targetind] += secondval[secondind];
370 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
377 while (firstind < firstlength)
379 if ( targetind < *targetlength )
381 targetrow[targetind] = firstrow[firstind];
382 targetcol[targetind] = firstcol[firstind];
383 targetval[targetind] = firstval[firstind];
391 while (secondind < secondlength)
393 if ( targetind < *targetlength )
395 targetrow[targetind] = secondrow[secondind];
396 targetcol[targetind] = secondcol[secondind];
397 targetval[targetind] = secondval[secondind];
405 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
407 if ( targetind < *targetlength )
408 targetval[targetind] += secondval[secondind];
414 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
420 SCIPdebugMessage(
"Insufficient arraylength in SCIPsdpVarfixerMergeArraysIntoNew, given targetarray-length was %d, would have needed %d",
421 *targetlength, targetind);
424 *targetlength = targetind;
void SCIPsdpVarfixerSortRowCol(int *row, int *col, SCIP_Real *val, int length)
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)