1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*                  This file is part of the program and library             */
4 /*         SCIP --- Solving Constraint Integer Programs                      */
5 /*                                                                           */
6 /*    Copyright (C) 2002-2021 Konrad-Zuse-Zentrum                            */
7 /*                            fuer Informationstechnik Berlin                */
8 /*                                                                           */
9 /*  SCIP is distributed under the terms of the ZIB Academic License.         */
10 /*                                                                           */
11 /*  You should have received a copy of the ZIB Academic License              */
12 /*  along with SCIP; see the file COPYING. If not visit scipopt.org.         */
13 /*                                                                           */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file   scip_datastructures.c
17  * @ingroup OTHER_CFILES
18  * @brief  public methods for data structures
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "scip/misc.h"
37 #include "scip/pub_message.h"
38 #include "scip/scip_datastructures.h"
39 #include "scip/scip_mem.h"
40 #include "scip/struct_mem.h"
41 #include "scip/struct_scip.h"
42 #include "scip/struct_set.h"
43 
44 /** creates a dynamic array of real values
45  *
46  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
47  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
48  */
SCIPcreateRealarray(SCIP * scip,SCIP_REALARRAY ** realarray)49 SCIP_RETCODE SCIPcreateRealarray(
50    SCIP*                 scip,               /**< SCIP data structure */
51    SCIP_REALARRAY**      realarray           /**< pointer to store the real array */
52    )
53 {
54    assert(scip != NULL);
55 
56    SCIP_CALL( SCIPrealarrayCreate(realarray, SCIPblkmem(scip)) );
57 
58    return SCIP_OKAY;
59 }
60 
61 /** frees a dynamic array of real values
62  *
63  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
64  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
65  */
SCIPfreeRealarray(SCIP * scip,SCIP_REALARRAY ** realarray)66 SCIP_RETCODE SCIPfreeRealarray(
67    SCIP*                 scip,               /**< SCIP data structure */
68    SCIP_REALARRAY**      realarray           /**< pointer to the real array */
69    )
70 {
71    assert(scip != NULL);
72 
73    SCIP_CALL( SCIPrealarrayFree(realarray) );
74 
75    return SCIP_OKAY;
76 }
77 
78 /** extends dynamic array to be able to store indices from minidx to maxidx
79  *
80  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
81  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
82  */
SCIPextendRealarray(SCIP * scip,SCIP_REALARRAY * realarray,int minidx,int maxidx)83 SCIP_RETCODE SCIPextendRealarray(
84    SCIP*                 scip,               /**< SCIP data structure */
85    SCIP_REALARRAY*       realarray,          /**< dynamic real array */
86    int                   minidx,             /**< smallest index to allocate storage for */
87    int                   maxidx              /**< largest index to allocate storage for */
88    )
89 {
90    assert(scip != NULL);
91 
92    SCIP_CALL( SCIPrealarrayExtend(realarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, minidx, maxidx) );
93 
94    return SCIP_OKAY;
95 }
96 
97 /** clears a dynamic real array
98  *
99  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
100  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
101  */
SCIPclearRealarray(SCIP * scip,SCIP_REALARRAY * realarray)102 SCIP_RETCODE SCIPclearRealarray(
103    SCIP*                 scip,               /**< SCIP data structure */
104    SCIP_REALARRAY*       realarray           /**< dynamic real array */
105    )
106 {
107    assert(scip != NULL);
108 
109    SCIP_CALL( SCIPrealarrayClear(realarray) );
110 
111    return SCIP_OKAY;
112 }
113 
114 /** gets value of entry in dynamic array
115  *
116  *  @return  value of entry in dynamic array
117  */
SCIPgetRealarrayVal(SCIP * scip,SCIP_REALARRAY * realarray,int idx)118 SCIP_Real SCIPgetRealarrayVal(
119    SCIP*                 scip,               /**< SCIP data structure */
120    SCIP_REALARRAY*       realarray,          /**< dynamic real array */
121    int                   idx                 /**< array index to get value for */
122    )
123 {
124    assert(scip != NULL);
125 
126    return SCIPrealarrayGetVal(realarray, idx);
127 }
128 
129 /** sets value of entry in dynamic array
130  *
131  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
132  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
133  */
SCIPsetRealarrayVal(SCIP * scip,SCIP_REALARRAY * realarray,int idx,SCIP_Real val)134 SCIP_RETCODE SCIPsetRealarrayVal(
135    SCIP*                 scip,               /**< SCIP data structure */
136    SCIP_REALARRAY*       realarray,          /**< dynamic real array */
137    int                   idx,                /**< array index to set value for */
138    SCIP_Real             val                 /**< value to set array index to */
139    )
140 {
141    assert(scip != NULL);
142 
143    SCIP_CALL( SCIPrealarraySetVal(realarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, val) );
144 
145    return SCIP_OKAY;
146 }
147 
148 /** increases value of entry in dynamic array
149  *
150  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
151  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
152  */
SCIPincRealarrayVal(SCIP * scip,SCIP_REALARRAY * realarray,int idx,SCIP_Real incval)153 SCIP_RETCODE SCIPincRealarrayVal(
154    SCIP*                 scip,               /**< SCIP data structure */
155    SCIP_REALARRAY*       realarray,          /**< dynamic real array */
156    int                   idx,                /**< array index to increase value for */
157    SCIP_Real             incval              /**< value to increase array index */
158    )
159 {
160    assert(scip != NULL);
161 
162    SCIP_CALL( SCIPrealarrayIncVal(realarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, incval) );
163 
164    return SCIP_OKAY;
165 }
166 
167 /** returns the minimal index of all stored non-zero elements
168  *
169  *  @return the minimal index of all stored non-zero elements
170  */
SCIPgetRealarrayMinIdx(SCIP * scip,SCIP_REALARRAY * realarray)171 int SCIPgetRealarrayMinIdx(
172    SCIP*                 scip,               /**< SCIP data structure */
173    SCIP_REALARRAY*       realarray           /**< dynamic real array */
174    )
175 {
176    assert(scip != NULL);
177 
178    return SCIPrealarrayGetMinIdx(realarray);
179 }
180 
181 /** returns the maximal index of all stored non-zero elements
182  *
183  *  @return the maximal index of all stored non-zero elements
184  */
SCIPgetRealarrayMaxIdx(SCIP * scip,SCIP_REALARRAY * realarray)185 int SCIPgetRealarrayMaxIdx(
186    SCIP*                 scip,               /**< SCIP data structure */
187    SCIP_REALARRAY*       realarray           /**< dynamic real array */
188    )
189 {
190    assert(scip != NULL);
191 
192    return SCIPrealarrayGetMaxIdx(realarray);
193 }
194 
195 /** creates a dynamic array of int values
196  *
197  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
198  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
199  */
SCIPcreateIntarray(SCIP * scip,SCIP_INTARRAY ** intarray)200 SCIP_RETCODE SCIPcreateIntarray(
201    SCIP*                 scip,               /**< SCIP data structure */
202    SCIP_INTARRAY**       intarray            /**< pointer to store the int array */
203    )
204 {
205    assert(scip != NULL);
206 
207    SCIP_CALL( SCIPintarrayCreate(intarray, SCIPblkmem(scip)) );
208 
209    return SCIP_OKAY;
210 }
211 
212 /** frees a dynamic array of int values
213  *
214  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
215  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
216  */
SCIPfreeIntarray(SCIP * scip,SCIP_INTARRAY ** intarray)217 SCIP_RETCODE SCIPfreeIntarray(
218    SCIP*                 scip,               /**< SCIP data structure */
219    SCIP_INTARRAY**       intarray            /**< pointer to the int array */
220    )
221 {
222    assert(scip != NULL);
223 
224    SCIP_CALL( SCIPintarrayFree(intarray) );
225 
226    return SCIP_OKAY;
227 }
228 
229 /** extends dynamic array to be able to store indices from minidx to maxidx
230  *
231  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
232  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
233  */
SCIPextendIntarray(SCIP * scip,SCIP_INTARRAY * intarray,int minidx,int maxidx)234 SCIP_RETCODE SCIPextendIntarray(
235    SCIP*                 scip,               /**< SCIP data structure */
236    SCIP_INTARRAY*        intarray,           /**< dynamic int array */
237    int                   minidx,             /**< smallest index to allocate storage for */
238    int                   maxidx              /**< largest index to allocate storage for */
239    )
240 {
241    assert(scip != NULL);
242 
243    SCIP_CALL( SCIPintarrayExtend(intarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, minidx, maxidx) );
244 
245    return SCIP_OKAY;
246 }
247 
248 /** clears a dynamic int array
249  *
250  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
251  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
252  */
SCIPclearIntarray(SCIP * scip,SCIP_INTARRAY * intarray)253 SCIP_RETCODE SCIPclearIntarray(
254    SCIP*                 scip,               /**< SCIP data structure */
255    SCIP_INTARRAY*        intarray            /**< dynamic int array */
256    )
257 {
258    assert(scip != NULL);
259 
260    SCIP_CALL( SCIPintarrayClear(intarray) );
261 
262    return SCIP_OKAY;
263 }
264 
265 /** gets value of entry in dynamic array
266  *
267  *  @return value of entry in dynamic array
268  */
SCIPgetIntarrayVal(SCIP * scip,SCIP_INTARRAY * intarray,int idx)269 int SCIPgetIntarrayVal(
270    SCIP*                 scip,               /**< SCIP data structure */
271    SCIP_INTARRAY*        intarray,           /**< dynamic int array */
272    int                   idx                 /**< array index to get value for */
273    )
274 {
275    assert(scip != NULL);
276 
277    return SCIPintarrayGetVal(intarray, idx);
278 }
279 
280 /** sets value of entry in dynamic array
281  *
282  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
283  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
284  */
SCIPsetIntarrayVal(SCIP * scip,SCIP_INTARRAY * intarray,int idx,int val)285 SCIP_RETCODE SCIPsetIntarrayVal(
286    SCIP*                 scip,               /**< SCIP data structure */
287    SCIP_INTARRAY*        intarray,           /**< dynamic int array */
288    int                   idx,                /**< array index to set value for */
289    int                   val                 /**< value to set array index to */
290    )
291 {
292    assert(scip != NULL);
293 
294    SCIP_CALL( SCIPintarraySetVal(intarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, val) );
295 
296    return SCIP_OKAY;
297 }
298 
299 /** increases value of entry in dynamic array
300  *
301  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
302  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
303  */
SCIPincIntarrayVal(SCIP * scip,SCIP_INTARRAY * intarray,int idx,int incval)304 SCIP_RETCODE SCIPincIntarrayVal(
305    SCIP*                 scip,               /**< SCIP data structure */
306    SCIP_INTARRAY*        intarray,           /**< dynamic int array */
307    int                   idx,                /**< array index to increase value for */
308    int                   incval              /**< value to increase array index */
309    )
310 {
311    assert(scip != NULL);
312 
313    SCIP_CALL( SCIPintarrayIncVal(intarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, incval) );
314 
315    return SCIP_OKAY;
316 }
317 
318 /** returns the minimal index of all stored non-zero elements
319  *
320  *  @return the minimal index of all stored non-zero elements
321  */
SCIPgetIntarrayMinIdx(SCIP * scip,SCIP_INTARRAY * intarray)322 int SCIPgetIntarrayMinIdx(
323    SCIP*                 scip,               /**< SCIP data structure */
324    SCIP_INTARRAY*        intarray            /**< dynamic int array */
325    )
326 {
327    assert(scip != NULL);
328 
329    return SCIPintarrayGetMinIdx(intarray);
330 }
331 
332 /** returns the maximal index of all stored non-zero elements
333  *
334  *  @return the maximal index of all stored non-zero elements
335  */
SCIPgetIntarrayMaxIdx(SCIP * scip,SCIP_INTARRAY * intarray)336 int SCIPgetIntarrayMaxIdx(
337    SCIP*                 scip,               /**< SCIP data structure */
338    SCIP_INTARRAY*        intarray            /**< dynamic int array */
339    )
340 {
341    assert(scip != NULL);
342 
343    return SCIPintarrayGetMaxIdx(intarray);
344 }
345 
346 /** creates a dynamic array of bool values
347  *
348  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
349  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
350  */
SCIPcreateBoolarray(SCIP * scip,SCIP_BOOLARRAY ** boolarray)351 SCIP_RETCODE SCIPcreateBoolarray(
352    SCIP*                 scip,               /**< SCIP data structure */
353    SCIP_BOOLARRAY**      boolarray           /**< pointer to store the bool array */
354    )
355 {
356    assert(scip != NULL);
357 
358    SCIP_CALL( SCIPboolarrayCreate(boolarray, SCIPblkmem(scip)) );
359 
360    return SCIP_OKAY;
361 }
362 
363 /** frees a dynamic array of bool values
364  *
365  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
366  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
367  */
SCIPfreeBoolarray(SCIP * scip,SCIP_BOOLARRAY ** boolarray)368 SCIP_RETCODE SCIPfreeBoolarray(
369    SCIP*                 scip,               /**< SCIP data structure */
370    SCIP_BOOLARRAY**      boolarray           /**< pointer to the bool array */
371    )
372 {
373    assert(scip != NULL);
374 
375    SCIP_CALL( SCIPboolarrayFree(boolarray) );
376 
377    return SCIP_OKAY;
378 }
379 
380 /** extends dynamic array to be able to store indices from minidx to maxidx
381  *
382  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
383  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
384  */
SCIPextendBoolarray(SCIP * scip,SCIP_BOOLARRAY * boolarray,int minidx,int maxidx)385 SCIP_RETCODE SCIPextendBoolarray(
386    SCIP*                 scip,               /**< SCIP data structure */
387    SCIP_BOOLARRAY*       boolarray,          /**< dynamic bool array */
388    int                   minidx,             /**< smallest index to allocate storage for */
389    int                   maxidx              /**< largest index to allocate storage for */
390    )
391 {
392    assert(scip != NULL);
393 
394    SCIP_CALL( SCIPboolarrayExtend(boolarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, minidx, maxidx) );
395 
396    return SCIP_OKAY;
397 }
398 
399 /** clears a dynamic bool array
400  *
401  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
402  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
403  */
SCIPclearBoolarray(SCIP * scip,SCIP_BOOLARRAY * boolarray)404 SCIP_RETCODE SCIPclearBoolarray(
405    SCIP*                 scip,               /**< SCIP data structure */
406    SCIP_BOOLARRAY*       boolarray           /**< dynamic bool array */
407    )
408 {
409    assert(scip != NULL);
410 
411    SCIP_CALL( SCIPboolarrayClear(boolarray) );
412 
413    return SCIP_OKAY;
414 }
415 
416 /** gets value of entry in dynamic array
417  *
418  *  @return value of entry in dynamic array at position idx
419  */
SCIPgetBoolarrayVal(SCIP * scip,SCIP_BOOLARRAY * boolarray,int idx)420 SCIP_Bool SCIPgetBoolarrayVal(
421    SCIP*                 scip,               /**< SCIP data structure */
422    SCIP_BOOLARRAY*       boolarray,          /**< dynamic bool array */
423    int                   idx                 /**< array index to get value for */
424    )
425 {
426    assert(scip != NULL);
427 
428    return SCIPboolarrayGetVal(boolarray, idx);
429 }
430 
431 /** sets value of entry in dynamic array
432  *
433  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
434  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
435  */
SCIPsetBoolarrayVal(SCIP * scip,SCIP_BOOLARRAY * boolarray,int idx,SCIP_Bool val)436 SCIP_RETCODE SCIPsetBoolarrayVal(
437    SCIP*                 scip,               /**< SCIP data structure */
438    SCIP_BOOLARRAY*       boolarray,          /**< dynamic bool array */
439    int                   idx,                /**< array index to set value for */
440    SCIP_Bool             val                 /**< value to set array index to */
441    )
442 {
443    assert(scip != NULL);
444 
445    SCIP_CALL( SCIPboolarraySetVal(boolarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, val) );
446 
447    return SCIP_OKAY;
448 }
449 
450 /** returns the minimal index of all stored non-zero elements
451  *
452  *  @return the minimal index of all stored non-zero elements
453  */
SCIPgetBoolarrayMinIdx(SCIP * scip,SCIP_BOOLARRAY * boolarray)454 int SCIPgetBoolarrayMinIdx(
455    SCIP*                 scip,               /**< SCIP data structure */
456    SCIP_BOOLARRAY*       boolarray           /**< dynamic bool array */
457    )
458 {
459    assert(scip != NULL);
460 
461    return SCIPboolarrayGetMinIdx(boolarray);
462 }
463 
464 /** returns the maximal index of all stored non-zero elements
465  *
466  *  @return the maximal index of all stored non-zero elements
467  */
SCIPgetBoolarrayMaxIdx(SCIP * scip,SCIP_BOOLARRAY * boolarray)468 int SCIPgetBoolarrayMaxIdx(
469    SCIP*                 scip,               /**< SCIP data structure */
470    SCIP_BOOLARRAY*       boolarray           /**< dynamic bool array */
471    )
472 {
473    assert(scip != NULL);
474 
475    return SCIPboolarrayGetMaxIdx(boolarray);
476 }
477 
478 /** creates a dynamic array of pointers
479  *
480  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
481  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
482  */
SCIPcreatePtrarray(SCIP * scip,SCIP_PTRARRAY ** ptrarray)483 SCIP_RETCODE SCIPcreatePtrarray(
484    SCIP*                 scip,               /**< SCIP data structure */
485    SCIP_PTRARRAY**       ptrarray            /**< pointer to store the int array */
486    )
487 {
488    assert(scip != NULL);
489 
490    SCIP_CALL( SCIPptrarrayCreate(ptrarray, SCIPblkmem(scip)) );
491 
492    return SCIP_OKAY;
493 }
494 
495 /** frees a dynamic array of pointers
496  *
497  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
498  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
499  */
SCIPfreePtrarray(SCIP * scip,SCIP_PTRARRAY ** ptrarray)500 SCIP_RETCODE SCIPfreePtrarray(
501    SCIP*                 scip,               /**< SCIP data structure */
502    SCIP_PTRARRAY**       ptrarray            /**< pointer to the int array */
503    )
504 {
505    assert(scip != NULL);
506 
507    SCIP_CALL( SCIPptrarrayFree(ptrarray) );
508 
509    return SCIP_OKAY;
510 }
511 
512 /** extends dynamic array to be able to store indices from minidx to maxidx
513  *
514  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
515  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
516  */
SCIPextendPtrarray(SCIP * scip,SCIP_PTRARRAY * ptrarray,int minidx,int maxidx)517 SCIP_RETCODE SCIPextendPtrarray(
518    SCIP*                 scip,               /**< SCIP data structure */
519    SCIP_PTRARRAY*        ptrarray,           /**< dynamic int array */
520    int                   minidx,             /**< smallest index to allocate storage for */
521    int                   maxidx              /**< largest index to allocate storage for */
522    )
523 {
524    assert(scip != NULL);
525 
526    SCIP_CALL( SCIPptrarrayExtend(ptrarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, minidx, maxidx) );
527 
528    return SCIP_OKAY;
529 }
530 
531 /** clears a dynamic pointer array
532  *
533  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
534  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
535  */
SCIPclearPtrarray(SCIP * scip,SCIP_PTRARRAY * ptrarray)536 SCIP_RETCODE SCIPclearPtrarray(
537    SCIP*                 scip,               /**< SCIP data structure */
538    SCIP_PTRARRAY*        ptrarray            /**< dynamic int array */
539    )
540 {
541    assert(scip != NULL);
542 
543    SCIP_CALL( SCIPptrarrayClear(ptrarray) );
544 
545    return SCIP_OKAY;
546 }
547 
548 /** gets value of entry in dynamic array */
SCIPgetPtrarrayVal(SCIP * scip,SCIP_PTRARRAY * ptrarray,int idx)549 void* SCIPgetPtrarrayVal(
550    SCIP*                 scip,               /**< SCIP data structure */
551    SCIP_PTRARRAY*        ptrarray,           /**< dynamic int array */
552    int                   idx                 /**< array index to get value for */
553    )
554 {
555    assert(scip != NULL);
556 
557    return SCIPptrarrayGetVal(ptrarray, idx);
558 }
559 
560 /** sets value of entry in dynamic array
561  *
562  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
563  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
564  */
SCIPsetPtrarrayVal(SCIP * scip,SCIP_PTRARRAY * ptrarray,int idx,void * val)565 SCIP_RETCODE SCIPsetPtrarrayVal(
566    SCIP*                 scip,               /**< SCIP data structure */
567    SCIP_PTRARRAY*        ptrarray,           /**< dynamic int array */
568    int                   idx,                /**< array index to set value for */
569    void*                 val                 /**< value to set array index to */
570    )
571 {
572    assert(scip != NULL);
573 
574    SCIP_CALL( SCIPptrarraySetVal(ptrarray, scip->set->mem_arraygrowinit, scip->set->mem_arraygrowfac, idx, val) );
575 
576    return SCIP_OKAY;
577 }
578 
579 /** returns the minimal index of all stored non-zero elements
580  *
581  *  @return the minimal index of all stored non-zero elements
582  */
SCIPgetPtrarrayMinIdx(SCIP * scip,SCIP_PTRARRAY * ptrarray)583 int SCIPgetPtrarrayMinIdx(
584    SCIP*                 scip,               /**< SCIP data structure */
585    SCIP_PTRARRAY*        ptrarray            /**< dynamic ptr array */
586    )
587 {
588    assert(scip != NULL);
589 
590    return SCIPptrarrayGetMinIdx(ptrarray);
591 }
592 
593 /** returns the maximal index of all stored non-zero elements
594  *
595  *  @return the maximal index of all stored non-zero elements
596  */
SCIPgetPtrarrayMaxIdx(SCIP * scip,SCIP_PTRARRAY * ptrarray)597 int SCIPgetPtrarrayMaxIdx(
598    SCIP*                 scip,               /**< SCIP data structure */
599    SCIP_PTRARRAY*        ptrarray            /**< dynamic ptr array */
600    )
601 {
602    assert(scip != NULL);
603 
604    return SCIPptrarrayGetMaxIdx(ptrarray);
605 }
606 
607 /** creates directed graph structure */
SCIPcreateDigraph(SCIP * scip,SCIP_DIGRAPH ** digraph,int nnodes)608 SCIP_RETCODE SCIPcreateDigraph(
609    SCIP*                 scip,               /**< SCIP data structure */
610    SCIP_DIGRAPH**        digraph,            /**< pointer to store the created directed graph */
611    int                   nnodes              /**< number of nodes */
612    )
613 {
614    assert(scip != NULL);
615    assert(digraph != NULL);
616 
617    SCIP_CALL( SCIPdigraphCreate(digraph, scip->mem->probmem, nnodes) );
618 
619    return SCIP_OKAY;
620 }
621 
622 /** copies directed graph structure
623  *
624  *  The copying procedure uses the memory of the passed SCIP instance. The user must ensure that the digraph lives
625  *  as most as long as the SCIP instance.
626  *
627  *  @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.
628  */
SCIPcopyDigraph(SCIP * scip,SCIP_DIGRAPH ** targetdigraph,SCIP_DIGRAPH * sourcedigraph)629 SCIP_RETCODE SCIPcopyDigraph(
630    SCIP*                 scip,               /**< SCIP data structure */
631    SCIP_DIGRAPH**        targetdigraph,      /**< pointer to store the copied directed graph */
632    SCIP_DIGRAPH*         sourcedigraph       /**< source directed graph */
633    )
634 {
635    assert(scip != NULL);
636    assert(sourcedigraph != NULL);
637    assert(targetdigraph != NULL);
638 
639    SCIP_CALL( SCIPdigraphCopy(targetdigraph, sourcedigraph, scip->mem->probmem) );
640 
641    return SCIP_OKAY;
642 }
643 
644 /** creates a disjoint set (union find) structure \p uf for \p ncomponents many components (of size one) */
SCIPcreateDisjointset(SCIP * scip,SCIP_DISJOINTSET ** djset,int ncomponents)645 SCIP_RETCODE SCIPcreateDisjointset(
646    SCIP*                 scip,               /**< SCIP data structure */
647    SCIP_DISJOINTSET**    djset,              /**< disjoint set (union find) data structure */
648    int                   ncomponents         /**< number of components */
649    )
650 {
651    assert(scip != NULL);
652    assert(djset != NULL);
653 
654    SCIP_CALL( SCIPdisjointsetCreate(djset, scip->mem->probmem, ncomponents) );
655 
656    return SCIP_OKAY;
657 }
658 
659 /** frees the disjoint set (union find) data structure */
SCIPfreeDisjointset(SCIP * scip,SCIP_DISJOINTSET ** djset)660 void SCIPfreeDisjointset(
661    SCIP*                 scip,               /**< SCIP data structure */
662    SCIP_DISJOINTSET**    djset               /**< disjoint set (union find) data structure */
663    )
664 {
665    assert(scip != NULL);
666 
667    SCIPdisjointsetFree(djset, scip->mem->probmem);
668 }
669