Skip to content

Commit d4b04f1

Browse files
committed
Merge branch 'simplify_code_by_introducing_sortRealPtrPTr' into 'master'
Simplify code by introducing sort function RealPtrPtr See merge request integer/scip!3815
2 parents f0deb93 + e95c52f commit d4b04f1

File tree

5 files changed

+101
-43
lines changed

5 files changed

+101
-43
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Interface changes
7272
- the callback SCIP_DECL_EXPRINTEGRALITY, which returns the integrality of an expression, had its fourth argument change from SCIP_Bool* to SCIP_IMPLINTTYPE*, to represent implied integrality in nonlinear expressions, that is an implied integral type of an auxiliary variable if the expression were assigned to it
7373
- new event SCIP_EVENTTYPE_DUALBOUNDIMPROVED is generated whenever the global dual bound is improved
7474
- new event mask SCIP_EVENTTYPE_GAPUPDATED for catching updates in primal or dual bound
75+
- added new sorting functions SCIPsortRealPtrPtr(), ...
7576

7677
### Deleted and changed API methods
7778

src/scip/cons_cardinality.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -3754,21 +3754,11 @@ SCIP_RETCODE SCIPcreateConsCardinality(
37543754
/* check weights */
37553755
if( weights != NULL )
37563756
{
3757-
int* dummy;
3758-
37593757
/* store weights */
37603758
SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &consdata->weights, weights, nvars) );
37613759

3762-
/* create dummy array to make code compatible with SCIP 3.2.0
3763-
* (the function SCIPsortRealPtrPtr() is not available) */
3764-
SCIP_CALL( SCIPallocBufferArray(scip, &dummy, nvars) );
3765-
for( v = 0; v < nvars; ++v )
3766-
dummy[v] = 0;
3767-
37683760
/* sort variables - ascending order */
3769-
SCIPsortRealPtrPtrInt(consdata->weights, (void**)consdata->vars, (void**)consdata->indvars, dummy, nvars);
3770-
3771-
SCIPfreeBufferArray(scip, &dummy);
3761+
SCIPsortRealPtrPtr(consdata->weights, (void**)consdata->vars, (void**)consdata->indvars, nvars);
37723762
}
37733763
}
37743764
else

src/scip/misc.c

+8
Original file line numberDiff line numberDiff line change
@@ -5846,6 +5846,14 @@ void SCIPsort(
58465846
#include "scip/sorttpl.c" /*lint !e451*/
58475847

58485848

5849+
/* SCIPsortRealPtrPtr(), SCIPsortedvecInsert...(), SCIPsortedvecDelPos...(), SCIPsortedvecFind...() via sort template */
5850+
#define SORTTPL_NAMEEXT RealPtrPtr
5851+
#define SORTTPL_KEYTYPE SCIP_Real
5852+
#define SORTTPL_FIELD1TYPE void*
5853+
#define SORTTPL_FIELD2TYPE void*
5854+
#include "scip/sorttpl.c" /*lint !e451*/
5855+
5856+
58495857
/* SCIPsortRealRealPtr(), SCIPsortedvecInsert...(), SCIPsortedvecDelPos...(), SCIPsortedvecFind...() via sort template */
58505858
#define SORTTPL_NAMEEXT RealRealPtr
58515859
#define SORTTPL_KEYTYPE SCIP_Real

src/scip/pub_misc_select.h

+28
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,34 @@ void SCIPselectWeightedRealIntPtr(
911911
);
912912

913913

914+
/** partial sort of three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-decreasing order around the \p k-th element,
915+
* see \ref SelectionAlgorithms for more information.
916+
*/
917+
SCIP_EXPORT
918+
void SCIPselectRealPtrPtr(
919+
SCIP_Real* realarray, /**< SCIP_Real array to be sorted */
920+
void** ptrarray1, /**< first pointer array to be permuted in the same way */
921+
void** ptrarray2, /**< second pointer array to be permuted in the same way */
922+
int k, /**< the index of the desired element, must be between 0 (search for maximum/minimum) and len - 1 */
923+
int len /**< length of arrays */
924+
);
925+
926+
927+
/** partial sort of three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-decreasing order around the weighted median w.r.t. \p weights and capacity,
928+
* see \ref SelectionAlgorithms for more information.
929+
*/
930+
SCIP_EXPORT
931+
void SCIPselectWeightedRealPtrPtr(
932+
SCIP_Real* realarray, /**< SCIP_Real array to be sorted */
933+
void** ptrarray1, /**< first pointer array to be permuted in the same way */
934+
void** ptrarray2, /**< second pointer array to be permuted in the same way */
935+
SCIP_Real* weights, /**< (optional), nonnegative weights array for weighted median, or NULL (all weights are equal to 1) */
936+
SCIP_Real capacity, /**< the maximum capacity that is exceeded by the median */
937+
int len, /**< length of arrays */
938+
int* medianpos /**< pointer to store the index of the weighted median, or NULL, if not needed */
939+
);
940+
941+
914942
/** partial sort of three joint arrays of Reals/Reals/Pointer, sorted by first array in non-decreasing order around the \p k-th element,
915943
* see \ref SelectionAlgorithms for more information.
916944
*/

src/scip/pub_misc_sort.h

+63-32
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ void SCIPsortRealIntPtr(
361361
int len /**< length of arrays */
362362
);
363363

364+
/** sort of three joint arrays of Reals/Pointers/Pointers, sorted by first array in non-decreasing order */
365+
SCIP_EXPORT
366+
void SCIPsortRealPtrPtr(
367+
SCIP_Real* realarray, /**< SCIP_Real array to be sorted */
368+
void** ptrarray1, /**< first pointer array to be permuted in the same way */
369+
void** ptrarray2, /**< second pointer array to be permuted in the same way */
370+
int len /**< length of arrays */
371+
);
372+
364373
/** sort of three joint arrays of Reals/Reals/Pointer, sorted by first array in non-decreasing order */
365374
SCIP_EXPORT
366375
void SCIPsortRealRealPtr(
@@ -943,6 +952,15 @@ void SCIPsortDownRealIntPtr(
943952
int len /**< length of arrays */
944953
);
945954

955+
/** sort of three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-decreasing order */
956+
SCIP_EXPORT
957+
void SCIPsortDownRealPtrPtr(
958+
SCIP_Real* realarray, /**< SCIP_Real array to be sorted */
959+
void** ptrarray1, /**< first pointer array to be permuted in the same way */
960+
void** ptrarray2, /**< second pointer array to be permuted in the same way */
961+
int len /**< length of arrays */
962+
);
963+
946964
/** sort of three joint arrays of Reals/Reals/ints, sorted by first array in non-increasing order */
947965
SCIP_EXPORT
948966
void SCIPsortDownRealRealInt(
@@ -1033,15 +1051,6 @@ void SCIPsortDownRealRealRealPtr(
10331051
int len /**< length of arrays */
10341052
);
10351053

1036-
/** sort of three joint arrays of Reals/pointers, sorted by first array in non-decreasing order */
1037-
SCIP_EXPORT
1038-
void SCIPsortDownRealPtrPtr(
1039-
SCIP_Real* realarray, /**< SCIP_Real array to be sorted */
1040-
void** ptrarray1, /**< pointer array to be permuted in the same way */
1041-
void** ptrarray2, /**< pointer array to be permuted in the same way */
1042-
int len /**< length of arrays */
1043-
);
1044-
10451054
/** sort of five joint arrays of Reals/Reals/Reals/Bools/pointers, sorted by first array in non-increasing order */
10461055
SCIP_EXPORT
10471056
void SCIPsortDownRealRealRealBoolPtr(
@@ -1653,6 +1662,19 @@ void SCIPsortedvecInsertRealIntPtr(
16531662
int* pos /**< pointer to store the insertion position, or NULL */
16541663
);
16551664

1665+
/** insert a new element into three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-decreasing order */
1666+
SCIP_EXPORT
1667+
void SCIPsortedvecInsertRealPtrPtr(
1668+
SCIP_Real* realarray, /**< SCIP_Real array where an element is to be inserted */
1669+
void** ptrarray1, /**< first pointer array where an element is to be inserted */
1670+
void** ptrarray2, /**< second pointer array where an element is to be inserted */
1671+
SCIP_Real keyval, /**< key value of new element */
1672+
void* field1val, /**< additional value of new element */
1673+
void* field2val, /**< additional value of new element */
1674+
int* len, /**< pointer to length of arrays (will be increased by 1) */
1675+
int* pos /**< pointer to store the insertion position, or NULL */
1676+
);
1677+
16561678
/** insert a new element into three joint arrays of Reals/Reals/Pointer, sorted by first array in non-decreasing order */
16571679
SCIP_EXPORT
16581680
void SCIPsortedvecInsertRealRealPtr(
@@ -2435,19 +2457,6 @@ void SCIPsortedvecInsertDownRealPtr(
24352457
int* pos /**< pointer to store the insertion position, or NULL */
24362458
);
24372459

2438-
/** insert a new element into three joint arrays of Reals/pointers, sorted by first array in non-increasing order */
2439-
SCIP_EXPORT
2440-
void SCIPsortedvecInsertDownRealPtrPtr(
2441-
SCIP_Real* realarray, /**< SCIP_Real array where an element is to be inserted */
2442-
void** ptrarray1, /**< first pointer array where an element is to be inserted */
2443-
void** ptrarray2, /**< second pointer array where an element is to be inserted */
2444-
SCIP_Real keyval, /**< key value of new element */
2445-
void* field1val, /**< additional value of new element */
2446-
void* field2val, /**< additional value of new element */
2447-
int* len, /**< pointer to length of arrays (will be increased by 1) */
2448-
int* pos /**< pointer to store the insertion position, or NULL */
2449-
);
2450-
24512460
/** insert a new element into two joint arrays of Reals/ints, sorted by first array in non-increasing order */
24522461
SCIP_EXPORT
24532462
void SCIPsortedvecInsertDownRealInt(
@@ -2511,6 +2520,18 @@ void SCIPsortedvecInsertDownRealIntPtr(
25112520
int* pos /**< pointer to store the insertion position, or NULL */
25122521
);
25132522

2523+
/** insert a new element into three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-increasing order */
2524+
SCIP_EXPORT
2525+
void SCIPsortedvecInsertDownRealPtrPtr(
2526+
SCIP_Real* realarray, /**< SCIP_Real array where an element is to be inserted */
2527+
void** ptrarray1, /**< first pointer array where an element is to be inserted */
2528+
void** ptrarray2, /**< second pointer array where an element is to be inserted */
2529+
SCIP_Real keyval, /**< key value of new element */
2530+
void* field1val, /**< additional value of new element */
2531+
void* field2val, /**< additional value of new element */
2532+
int* len, /**< pointer to length of arrays (will be increased by 1) */
2533+
int* pos /**< pointer to store the insertion position, or NULL */
2534+
);
25142535

25152536
/** insert a new element into three joint arrays of Reals/Reals/Pointer, sorted by first array in non-increasing order */
25162537
SCIP_EXPORT
@@ -3270,6 +3291,16 @@ void SCIPsortedvecDelPosRealIntPtr(
32703291
int* len /**< pointer to length of arrays (will be decreased by 1) */
32713292
);
32723293

3294+
/** delete the element at the given position from three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-decreasing order */
3295+
SCIP_EXPORT
3296+
void SCIPsortedvecDelPosRealPtrPtr(
3297+
SCIP_Real* realarray, /**< SCIP_Real array where an element is to be deleted */
3298+
void** ptrarray1, /**< first pointer array where an element is to be deleted */
3299+
void** ptrarray2, /**< first pointer array where an element is to be deleted */
3300+
int pos, /**< array position of element to be deleted */
3301+
int* len /**< pointer to length of arrays (will be decreased by 1) */
3302+
);
3303+
32733304
/** delete the element at the given position from three joint arrays of Reals/Reals/Pointer, sorted by first array in non-decreasing order */
32743305
SCIP_EXPORT
32753306
void SCIPsortedvecDelPosRealRealPtr(
@@ -3903,6 +3934,16 @@ void SCIPsortedvecDelPosDownRealIntPtr(
39033934
int* len /**< pointer to length of arrays (will be decreased by 1) */
39043935
);
39053936

3937+
/** delete the element at the given position from three joint arrays of Reals/Pointer/Pointer, sorted by first array in non-increasing order */
3938+
SCIP_EXPORT
3939+
void SCIPsortedvecDelPosDownRealPtrPtr(
3940+
SCIP_Real* realarray, /**< SCIP_Real array where an element is to be deleted */
3941+
void** ptrarray1, /**< first pointer array where an element is to be deleted */
3942+
void** ptrarray2, /**< second pointer array where an element is to be deleted */
3943+
int pos, /**< array position of element to be deleted */
3944+
int* len /**< pointer to length of arrays (will be decreased by 1) */
3945+
);
3946+
39063947
/** delete the element at the given position from three joint arrays of Reals/Reals/ints, sorted by first array in non-increasing order */
39073948
SCIP_EXPORT
39083949
void SCIPsortedvecDelPosDownRealRealInt(
@@ -3934,16 +3975,6 @@ void SCIPsortedvecDelPosDownRealRealPtrPtr(
39343975
int* len /**< pointer to length of arrays (will be decreased by 1) */
39353976
);
39363977

3937-
/** delete the element at the given position from three joint arrays of Reals/Reals/Pointer, sorted by first array in non-increasing order */
3938-
SCIP_EXPORT
3939-
void SCIPsortedvecDelPosDownRealPtrPtr(
3940-
SCIP_Real* realarray, /**< first SCIP_Real array where an element is to be deleted */
3941-
void** ptrarray1, /**< first pointer array where an element is to be deleted */
3942-
void** ptrarray2, /**< second pointer array where an element is to be deleted */
3943-
int pos, /**< array position of element to be deleted */
3944-
int* len /**< pointer to length of arrays (will be decreased by 1) */
3945-
);
3946-
39473978
/** delete the element at the given position from four joint arrays of Reals/pointers/pointers/ints, sorted by first array in non-increasing order */
39483979
SCIP_EXPORT
39493980
void SCIPsortedvecDelPosDownRealPtrPtrInt(

0 commit comments

Comments
 (0)