SCIP Doxygen Documentation
Loading...
Searching...
No Matches
boundstore.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* SCIP --- Solving Constraint Integer Programs */
5/* */
6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file boundstore.c
26 * @ingroup PARALLEL
27 * @brief the implementation of the bound store data structure
28 * @author Leona Gottwald
29 */
30
31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
33#include "scip/boundstore.h"
36#include "scip/scip.h"
37
38/** create bound store data structure */
40 SCIP* scip, /**< scip main data structure */
41 SCIP_BOUNDSTORE** boundstore, /**< pointer to store the bound store data structure */
42 int nvars /**< number of variables for which bounds may be stored */
43 )
44{
45 assert(scip != NULL);
46 assert(boundstore != NULL);
47
48 SCIP_CALL( SCIPallocMemory(scip, boundstore) );
49
50 (*boundstore)->bndchg = NULL;
51 (*boundstore)->bndchgsize = 0;
52 (*boundstore)->nbndchg = 0;
53 (*boundstore)->nvars = nvars;
54 SCIP_CALL( SCIPallocClearBlockMemoryArray(scip, &(*boundstore)->bndpos, nvars) );
55
56 return SCIP_OKAY;
57}
58
59/** free bound store data structure */
61 SCIP* scip, /**< scip main data structure */
62 SCIP_BOUNDSTORE** boundstore /**< pointer to the bound store data structure */
63 )
64{
65 assert(scip != NULL);
66 assert(boundstore != NULL);
67 assert((*boundstore) != NULL);
68
69 SCIPfreeBlockMemoryArray(scip, &(*boundstore)->bndpos, (*boundstore)->nvars);
70 SCIPfreeBlockMemoryArrayNull(scip, &(*boundstore)->bndchg, (*boundstore)->bndchgsize);
71 SCIPfreeMemory(scip, boundstore);
72}
73
74/** add bound change to bound store data structure */
76 SCIP* scip, /**< scip main data structure */
77 SCIP_BOUNDSTORE* boundstore, /**< the bound store data structure */
78 int varidx, /**< variable index of bound change, must be smaller than the
79 * number of variables given during creation of bound store */
80 SCIP_Real newbound, /**< bound value of variable */
81 SCIP_BOUNDTYPE boundtype /**< type of new bound */
82 )
83{
84 /* check if already stored a bound of same type for this variable */
85 int pos;
86
87 assert(scip != NULL);
88 assert(boundstore != NULL);
89
90 /* ignore indices larger than nvars (may happen for (multi-)aggregated/fixed variables) */
91 if( varidx >= boundstore->nvars )
92 return SCIP_OKAY;
93
94 pos = boundstore->bndpos[varidx].pos[boundtype];
95 assert(pos >= 0);
96
97 if( pos == 0 )
98 {
99 /* variable has no bound stored yet so store this bound */
100 int i;
101 i = boundstore->nbndchg++;
102 SCIP_CALL( SCIPensureBlockMemoryArray(scip, &boundstore->bndchg, &boundstore->bndchgsize, boundstore->nbndchg) );
103 boundstore->bndchg[i].varidx = varidx;
104 boundstore->bndchg[i].newbound = newbound;
105 boundstore->bndchg[i].boundtype = boundtype;
106 boundstore->bndpos[varidx].pos[boundtype] = boundstore->nbndchg;
107 }
108 else
109 {
110 /* since pos == 0 is reserved if no bound is stored
111 * the index is pos-1
112 */
113 --pos;
114 assert(boundstore->bndchg[pos].boundtype == boundtype);
115 assert(boundstore->bndchg[pos].varidx == varidx);
116
117 /* if the bound is better overwrite the old one */
118 if( (boundtype == SCIP_BOUNDTYPE_LOWER && newbound > boundstore->bndchg[pos].newbound) ||
119 (boundtype == SCIP_BOUNDTYPE_UPPER && newbound < boundstore->bndchg[pos].newbound) )
120 {
121 boundstore->bndchg[pos].newbound = newbound;
122 }
123 }
124
125 return SCIP_OKAY;
126}
127
128/** add all bound changes of source to target */
130 SCIP* scip, /**< scip main data structure for target boundstore */
131 SCIP_BOUNDSTORE* target, /**< the bound store data structure where the bounds get merged in */
132 SCIP_BOUNDSTORE* source /**< the bound store data structure from which the bounds get merged in */
133 )
134{
135 int i;
136
137 assert(scip != NULL);
138 assert(source != NULL);
139 assert(target != NULL);
140
141 /* just iterate over the boundchanges in the source and add them to the target */
142 for( i = 0; i < source->nbndchg; ++i )
143 {
144 assert(source->bndchg[i].varidx < source->nvars);
145 SCIP_CALL( SCIPboundstoreAdd(scip, target, source->bndchg[i].varidx, source->bndchg[i].newbound, source->bndchg[i].boundtype) );
146 }
147
148 return SCIP_OKAY;
149}
150
151/** remove all boundchanges from bound store */
153 SCIP_BOUNDSTORE* boundstore /**< the bound store data structure */
154 )
155{
156 assert(boundstore != NULL);
157
158 /* clearing the positions is enough */
159 if( boundstore->nbndchg > 0 )
160 {
161 BMSclearMemoryArray(boundstore->bndpos, boundstore->nvars);
162 boundstore->nbndchg = 0;
163 }
164}
165
166/** gets variable index of the i'th stored boundchange */
168 SCIP_BOUNDSTORE* boundstore, /**< the bound store data structure */
169 int i /**< the index of the bound change */
170 )
171{
172 assert(boundstore != NULL);
173 assert(i < boundstore->nbndchg);
174
175 return boundstore->bndchg[i].varidx;
176}
177
178/** gets the type of the i'th stored boundchange */
180 SCIP_BOUNDSTORE* boundstore, /**< the bound store data structure */
181 int i /**< the index of the bound change */
182 )
183{
184 assert(boundstore != NULL);
185 assert(i < boundstore->nbndchg);
186
187 return boundstore->bndchg[i].boundtype;
188}
189
190/** gets the bound value of the i'th stored boundchange */
192 SCIP_BOUNDSTORE* boundstore, /**< the bound store data structure */
193 int i /**< the index of the bound change */
194 )
195{
196 assert(boundstore != NULL);
197 assert(i < boundstore->nbndchg);
198
199 return boundstore->bndchg[i].newbound;
200}
201
202/** gets the number of stored bound changes */
204 SCIP_BOUNDSTORE* boundstore /**< the bound store data structure */
205 )
206{
207 assert(boundstore != NULL);
208
209 return boundstore->nbndchg;
210}
SCIP_Real SCIPboundstoreGetChgVal(SCIP_BOUNDSTORE *boundstore, int i)
Definition boundstore.c:191
SCIP_BOUNDTYPE SCIPboundstoreGetChgType(SCIP_BOUNDSTORE *boundstore, int i)
Definition boundstore.c:179
SCIP_RETCODE SCIPboundstoreMerge(SCIP *scip, SCIP_BOUNDSTORE *target, SCIP_BOUNDSTORE *source)
Definition boundstore.c:129
SCIP_RETCODE SCIPboundstoreAdd(SCIP *scip, SCIP_BOUNDSTORE *boundstore, int varidx, SCIP_Real newbound, SCIP_BOUNDTYPE boundtype)
Definition boundstore.c:75
int SCIPboundstoreGetChgVaridx(SCIP_BOUNDSTORE *boundstore, int i)
Definition boundstore.c:167
void SCIPboundstoreFree(SCIP *scip, SCIP_BOUNDSTORE **boundstore)
Definition boundstore.c:60
SCIP_RETCODE SCIPboundstoreCreate(SCIP *scip, SCIP_BOUNDSTORE **boundstore, int nvars)
Definition boundstore.c:39
void SCIPboundstoreClear(SCIP_BOUNDSTORE *boundstore)
Definition boundstore.c:152
int SCIPboundstoreGetNChgs(SCIP_BOUNDSTORE *boundstore)
Definition boundstore.c:203
the interface of the bound store data structure
#define NULL
Definition def.h:255
#define SCIP_Real
Definition def.h:163
#define SCIP_CALL(x)
Definition def.h:362
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition scip_mem.h:110
#define SCIPensureBlockMemoryArray(scip, ptr, arraysizeptr, minsize)
Definition scip_mem.h:107
#define SCIPallocClearBlockMemoryArray(scip, ptr, num)
Definition scip_mem.h:97
#define SCIPallocMemory(scip, ptr)
Definition scip_mem.h:60
#define SCIPfreeMemory(scip, ptr)
Definition scip_mem.h:78
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition scip_mem.h:111
return SCIP_OKAY
assert(minobj< SCIPgetCutoffbound(scip))
int nvars
memory allocation routines
#define BMSclearMemoryArray(ptr, num)
Definition memory.h:130
SCIP callable library.
SCIP_Real newbound
SCIP_BOUNDTYPE boundtype
the struct definitions for the synchronization store
@ SCIP_BOUNDTYPE_UPPER
Definition type_lp.h:58
@ SCIP_BOUNDTYPE_LOWER
Definition type_lp.h:57
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition type_lp.h:60
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
Definition type_scip.h:39
struct SCIP_BoundStore SCIP_BOUNDSTORE