38 #include "scip/type_misc.h" 40 #include "scip/pub_message.h" 41 #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);
94 SCIP_Bool originsorted,
115 assert ( blkmem != NULL );
116 assert ( originlength == 0 || (originlength > 0 && originrow != NULL && origincol != NULL && originval != NULL) );
117 assert ( targetrow != NULL );
118 assert ( targetcol != NULL );
119 assert ( targetval != NULL );
120 assert ( targetlength != NULL );
121 assert ( *targetlength >= 0 );
126 if ( ! originsorted )
135 for (i = 0; i < originlength; i++)
141 while (ind < *targetlength && (targetrow[ind] < originrow[i] || (targetrow[ind] == originrow[i] && targetcol[ind] < origincol[i])))
144 if ( nleftshifts > 0 )
146 targetrow[ind - nleftshifts] = targetrow[ind];
147 targetcol[ind - nleftshifts] = targetcol[ind];
148 targetval[ind - nleftshifts] = targetval[ind];
153 if ( ind < *targetlength && (targetrow[ind] == originrow[i] && targetcol[ind] == origincol[i]) )
158 if ( nleftshifts > 0 )
160 targetrow[ind - nleftshifts] = targetrow[ind];
161 targetcol[ind - nleftshifts] = targetcol[ind];
163 targetval[ind - nleftshifts] = targetval[ind] + scalar * originval[i];
167 while (i + 1 < originlength && originrow[i + 1] == targetrow[ind - nleftshifts] && origincol[i + 1] == targetcol[ind - nleftshifts])
169 targetval[ind - nleftshifts] += scalar * originval[i + 1];
173 if ( REALABS(targetval[ind - nleftshifts]) < epsilon )
182 if ( nleftshifts > 0 )
185 insertionpos = ind - nleftshifts;
191 insertionpos = *targetlength + naddednonz;
195 if ( insertionpos < targetmemory )
198 targetrow[insertionpos] = originrow[i];
199 targetcol[insertionpos] = origincol[i];
200 targetval[insertionpos] = scalar * originval[i];
203 while (i + 1 < originlength && originrow[i + 1] == targetrow[insertionpos] && origincol[i + 1] == targetcol[insertionpos])
205 targetval[insertionpos] += scalar * originval[i + 1];
210 if ( REALABS(targetval[insertionpos]) < epsilon )
213 if ( insertionpos < ind )
224 if ( nleftshifts > 0 )
226 while (ind < *targetlength + naddednonz && ind < targetmemory)
228 targetrow[ind - nleftshifts] = targetrow[ind];
229 targetcol[ind - nleftshifts] = targetcol[ind];
230 targetval[ind - nleftshifts] = targetval[ind];
236 SCIPdebugMessage(
"insufficient memory given for SCIPsdpVarfixerMergeArrays, targetmemorys had length %d, would have needed up to %d\n",
237 targetmemory, *targetlength + naddednonz);
239 *targetlength = *targetlength + naddednonz - nleftshifts;
262 SCIP_Real* secondval,
266 SCIP_Real* targetval,
276 assert ( blkmem != NULL );
277 assert ( firstlength == 0 || (firstlength > 0 && firstrow != NULL && firstcol != NULL && firstval != NULL ) );
278 assert ( secondlength == 0 || (secondlength > 0 && secondrow != NULL && secondcol != NULL && secondval != NULL ) );
279 assert ( targetrow != NULL );
280 assert ( targetcol != NULL );
281 assert ( targetval != NULL );
282 assert ( targetlength != NULL );
283 assert ( *targetlength >= 0 );
297 while (firstind < firstlength && secondind < secondlength)
301 if ( firstrow[firstind] < secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] < secondcol[secondind]) )
303 if ( targetind < *targetlength )
305 targetrow[targetind] = firstrow[firstind];
306 targetcol[targetind] = firstcol[firstind];
307 targetval[targetind] = firstval[firstind];
316 else if ( firstrow[firstind] > secondrow[secondind] || (firstrow[firstind] == secondrow[secondind] && firstcol[firstind] > secondcol[secondind]) )
318 if ( targetind < *targetlength )
320 targetrow[targetind] = secondrow[secondind];
321 targetcol[targetind] = secondcol[secondind];
322 targetval[targetind] = secondval[secondind];
330 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
332 if ( targetind < *targetlength )
333 targetval[targetind] += secondval[secondind];
339 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
345 if ( targetind < *targetlength )
347 targetrow[targetind] = firstrow[firstind];
348 targetcol[targetind] = firstcol[firstind];
349 targetval[targetind] = firstval[firstind] + secondval[secondind];
358 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
360 if ( targetind < *targetlength )
361 targetval[targetind] += secondval[secondind];
367 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
374 while (firstind < firstlength)
376 if ( targetind < *targetlength )
378 targetrow[targetind] = firstrow[firstind];
379 targetcol[targetind] = firstcol[firstind];
380 targetval[targetind] = firstval[firstind];
388 while (secondind < secondlength)
390 if ( targetind < *targetlength )
392 targetrow[targetind] = secondrow[secondind];
393 targetcol[targetind] = secondcol[secondind];
394 targetval[targetind] = secondval[secondind];
402 while (secondind < secondlength && (secondrow[secondind] == targetrow[targetind] && secondcol[secondind] == targetcol[targetind]))
404 if ( targetind < *targetlength )
405 targetval[targetind] += secondval[secondind];
411 if ( targetind >= *targetlength || REALABS(targetval[targetind]) >= epsilon )
417 SCIPdebugMessage(
"Insufficient arraylength in SCIPsdpVarfixerMergeArraysIntoNew, given targetarray-length was %d, would have needed %d",
418 *targetlength, targetind);
421 *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)