Scippy

UG

Ubiquity Generator framework

scipParaDiffSubproblem.cpp
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2024 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file scipParaDiffSubproblem.cpp
27 * @brief ParaDiffSubproblem extension for SCIP solver.
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#include <cstring>
37#include "ug/paraComm.h"
38#include "scipParaSolver.h"
39#include "scipParaInstance.h"
41#include "scipParaInitiator.h"
42
43using namespace UG;
44using namespace ParaSCIP;
45
46ScipParaDiffSubproblem::ScipParaDiffSubproblem(
47 SCIP *scip,
48 ScipParaSolver *scipParaSolver,
49 int nNewBranchVars,
50 SCIP_VAR **newBranchVars,
51 SCIP_Real *newBranchBounds,
52 SCIP_BOUNDTYPE *newBoundTypes,
53 int nAddedConss,
54 SCIP_CONS **addedConss
55 ) : localInfoIncluded(0),
56 nBoundChanges(0), indicesAmongSolvers(0), branchBounds(0), boundTypes(0),
57 branchLinearConss(0),
58 branchSetppcConss(0),
59 linearConss(0),
60 bendersLinearConss(0),
61 boundDisjunctions(0),
62 varBranchStats(0),
63 varValues(0)
64{
65 // int nOrigVars = SCIPgetNOrigVars(scip);
66 // std::cout << "the number of original variables = " << nOrigVars << std::endl;
67
68 nBoundChanges = nNewBranchVars;
69 int nParentBranchVars = 0;
70 int i = 0;
71
72 ScipParaDiffSubproblem *parentDiffSubproblem = scipParaSolver->getParentDiffSubproblem();
73
74 if( parentDiffSubproblem )
75 {
76 nParentBranchVars = parentDiffSubproblem->getNBoundChanges();
77 nBoundChanges += nParentBranchVars;
78 }
79
80 if( nBoundChanges > 0 )
81 {
83 branchBounds = new SCIP_Real[nBoundChanges];
84 boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
85 if( parentDiffSubproblem )
86 {
87 for( i = 0; i < nParentBranchVars; i ++ )
88 {
89 indicesAmongSolvers[i] = parentDiffSubproblem->getIndex(i);
90 branchBounds[i] = parentDiffSubproblem->getBranchBound(i);
91 boundTypes[i] = parentDiffSubproblem->getBoundType(i);
92 }
93 }
94 }
95
96 for( int v = nNewBranchVars -1 ; v >= 0; --v )
97 {
98 SCIP_VAR *transformVar = newBranchVars[v];
99 SCIP_Real scalar = 1.0;
100 SCIP_Real constant = 0.0;
101 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) );
102 if( transformVar == NULL ) continue;
103 if( SCIPvarGetIndex(transformVar) >= scipParaSolver->getNOrgVars() ) continue;
104 assert( (!scipParaSolver->getParaParamSet()->getBoolParamValue(NoSolverPresolvingAtRoot) ) ||
105 (!scipParaSolver->getCurrentNode()->isRootTask() ) ||
107 scipParaSolver->getCurrentNode()->isRootTask() &&
108 scalar == 1.0 && constant == 0.0 )
109 );
110 if( scipParaSolver->isOriginalIndeciesMap() )
111 {
112 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
113 {
114 indicesAmongSolvers[i] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
115 }
116 else
117 {
118 continue;
119 }
120 }
121 else
122 {
123 indicesAmongSolvers[i] = SCIPvarGetIndex(transformVar);
124 }
125 if( indicesAmongSolvers[i] < 0 || indicesAmongSolvers[i] >= scipParaSolver->getNOrgVars() )
126 {
127 continue;
128 }
129 assert( indicesAmongSolvers[i] >= 0 );
130 branchBounds[i] = ( newBranchBounds[v] - constant ) / scalar;
131 if( scalar > 0.0 )
132 {
133 boundTypes[i] = newBoundTypes[v];
134 }
135 else
136 {
137 boundTypes[i] = SCIP_BoundType(1 - newBoundTypes[v]);
138 }
139 if( SCIPvarGetType(transformVar) != SCIP_VARTYPE_CONTINUOUS )
140 {
141 if( scipParaSolver->isCopyIncreasedVariables() )
142 {
143 if( SCIPvarGetProbindex(transformVar) >= scipParaSolver->getNOrgVars() )
144 {
145 continue;
146 }
147 // if( !(SCIPisLE(scip,scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) &&
148 // SCIPisGE(scip,scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i])) )
149 // continue; // this is a workaround
150 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
151 {
152 branchBounds[i] = SCIPfeasCeil(scip, branchBounds[i]);
153 if( scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)) > branchBounds[i] ||
154 scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) < branchBounds[i] )
155 {
156 std::cout << "ORG(L):"
157 << SCIPvarGetName(transformVar) << ":"
158 << scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar))
159 << "<= "
160 << branchBounds[i]
161 << " <= "
162 << scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) << std::endl;
163 branchBounds[i] = scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)); // this is a workaround
164 }
165 // this does not work in case of multi-aggregated
166 // assert( scipParaSolver->getOrgVarLb(indicesAmongSolvers[i]) <= branchBounds[i] );
167 }
168 else
169 {
170 branchBounds[i] = SCIPfeasFloor(scip, branchBounds[i]);
171 if( scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) < branchBounds[i] ||
172 scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)) > branchBounds[i] )
173 {
174 std::cout << "ORG(U):"
175 << SCIPvarGetName(transformVar) << ":"
176 << scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar))
177 << "<= "
178 << branchBounds[i]
179 << " <= "
180 << scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) << std::endl;
181 branchBounds[i] = scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)); // this is a workaround
182 }
183 // this does not work in case of multi-aggregated
184 // assert( scipParaSolver->getOrgVarUb(indicesAmongSolvers[i]) >= branchBounds[i] );
185 }
186 }
187 else
188 {
189 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
190 {
191 branchBounds[i] = SCIPfeasCeil(scip, branchBounds[i]);
192 // this does not work in case of multi-aggregated
193 // assert( scipParaSolver->getOrgVarLb(indicesAmongSolvers[i]) <= branchBounds[i] );
194 }
195 else
196 {
197 branchBounds[i] = SCIPfeasFloor(scip, branchBounds[i]);
198 // this does not work in case of multi-aggregated
199 // assert( scipParaSolver->getOrgVarUb(indicesAmongSolvers[i]) >= branchBounds[i] );
200 }
201 }
202 // This does not work in case of multi-aggregated
203 // std::cout << "SCIPvarGetType(transformVar) = " << SCIPvarGetType(transformVar) << std::endl;
204 // std::cout << scipParaSolver->getOrgVarLb(indicesAmongSolvers[i]) << " <= "
205 // << branchBounds[i] << " <= "
206 // << scipParaSolver->getOrgVarUb(indicesAmongSolvers[i]) << std::endl;
207 assert( SCIPisLE(scip,scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) &&
208 SCIPisGE(scip,scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) );
209 assert( SCIPvarGetType(transformVar) != SCIP_VARTYPE_BINARY
210 || ( ( SCIPvarGetType(transformVar) == SCIP_VARTYPE_BINARY && boundTypes[i] == SCIP_BOUNDTYPE_LOWER && EPSEQ(branchBounds[i], 1.0, DEFAULT_NUM_EPSILON) ) ||
211 ( SCIPvarGetType(transformVar) == SCIP_VARTYPE_BINARY && boundTypes[i] == SCIP_BOUNDTYPE_UPPER && EPSEQ(branchBounds[i], 0.0, DEFAULT_NUM_EPSILON) ) ) );
212 i++;
213 }
214 else // SCIPvarGetType(transformVar) == SCIP_VARTYPE_CONTINUOUS
215 {
216 if( scipParaSolver->isCopyIncreasedVariables() )
217 {
218 if( SCIPvarGetProbindex(transformVar) >= scipParaSolver->getNOrgVars() )
219 {
220 continue;
221 }
222 // if( !(SCIPisLE(scip,scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) &&
223 // SCIPisGE(scip,scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i])) )
224 // continue; // this is a workaround
225 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
226 {
227 if( SCIPisLT(scip, scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i] ) )
228 {
229 // branchBounds[i] = SCIPfeasCeil(scip, branchBounds[i]);
230 if( SCIPisGE(scip,scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)),branchBounds[i]) ||
231 SCIPisLE(scip,scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i] ) )
232 {
233 std::cout << "ORG(L):"
234 << SCIPvarGetName(transformVar) << ":"
235 << scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar))
236 << "<= "
237 << branchBounds[i]
238 << " <= "
239 << scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) << std::endl;
240 branchBounds[i] = scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)); // this is a workaround
241 }
242 i++;
243 // this does not work in case of multi-aggregated
244 // assert( scipParaSolver->getOrgVarLb(indicesAmongSolvers[i]) <= branchBounds[i] );
245 }
246 }
247 else
248 {
249 if( SCIPisGT(scip, scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i] ) )
250 {
251 // branchBounds[i] = SCIPfeasFloor(scip, branchBounds[i]);
252 if( SCIPisLE(scip, scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) ||
253 SCIPisGE(scip, scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i]) )
254 {
255 std::cout << "ORG(U):"
256 << SCIPvarGetName(transformVar) << ":"
257 << scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar))
258 << "<= "
259 << branchBounds[i]
260 << " <= "
261 << scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)) << std::endl;
262 branchBounds[i] = scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)); // this is a workaround
263 }
264 i++;
265 // this does not work in case of multi-aggregated
266 // assert( scipParaSolver->getOrgVarUb(indicesAmongSolvers[i]) >= branchBounds[i] );
267 }
268 }
269 }
270 else
271 {
272 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
273 {
274 if( SCIPisLT(scip, scipParaSolver->getOrgVarLb(SCIPvarGetProbindex(transformVar)), branchBounds[i] ) )
275 {
276 i++;
277 }
278 // branchBounds[i] = SCIPfeasCeil(scip, branchBounds[i]);
279 // this does not work in case of multi-aggregated
280 // assert( scipParaSolver->getOrgVarLb(indicesAmongSolvers[i]) <= branchBounds[i] );
281 }
282 else
283 {
284 if( SCIPisGT(scip, scipParaSolver->getOrgVarUb(SCIPvarGetProbindex(transformVar)), branchBounds[i] ) )
285 {
286 i++;
287 }
288 // branchBounds[i] = SCIPfeasFloor(scip, branchBounds[i]);
289 // this does not work in case of multi-aggregated
290 // assert( scipParaSolver->getOrgVarUb(indicesAmongSolvers[i]) >= branchBounds[i] );
291 }
292 }
293 }
294 }
295 nBoundChanges = i;
296
297 if( nAddedConss > 0 )
298 {
299 assert(addedConss);
300 int nLinearConss = 0;
301 int nSetppcConss = 0;
302 for( int c = 0; c < nAddedConss; c++ )
303 {
304 SCIP_CONS* cons = addedConss[c];
305 assert(cons != NULL);
306 const char *conshdlrname = SCIPconshdlrGetName(SCIPconsGetHdlr(cons));
307 if( std::strcmp(conshdlrname, "linear") == 0 )
308 {
309 nLinearConss++;
310 }
311 else if( std::strcmp(conshdlrname, "setppc") == 0 )
312 {
313 nSetppcConss++;
314 }
315 else if( std::strcmp(conshdlrname, "conjunction") == 0 )
316 {
317 // this should not be for branching
318 }
319 else
320 {
321 THROW_LOGICAL_ERROR2("invalid constraint type sets on ScipParaDiffSubproblem; consname = ", conshdlrname);
322 }
323 }
324 addBranchLinearConss(scip, scipParaSolver, nLinearConss, nAddedConss, addedConss);
325 addBranchSetppcConss(scip, scipParaSolver, nSetppcConss, nAddedConss, addedConss);
326 }
327
328 if( scipParaSolver->getParaParamSet()->getBoolParamValue(TransferLocalCuts) ||
331 )
332 {
333 addLocalNodeInfo(scip, scipParaSolver);
334 }
335
336 if( scipParaSolver->getParaParamSet()->getBoolParamValue(TransferConflicts) )
337 {
338 addBoundDisjunctions(scip, scipParaSolver);
339 }
340
341 if( scipParaSolver->getParaParamSet()->getBoolParamValue(TransferBranchStats) &&
342 (!( scipParaSolver->isRacingStage()
343 && scipParaSolver->getParaParamSet()->getBoolParamValue(RacingStatBranching) ) )
344 )
345 {
346 addBranchVarStats(scip, scipParaSolver);
347 }
348
350 (!( scipParaSolver->isRacingStage()
351 && scipParaSolver->getParaParamSet()->getBoolParamValue(RacingStatBranching) ) )
352 )
353 {
354 addVarValueStats(scip, scipParaSolver);
355 }
356#ifdef UG_DEBUG_SOLUTION
357 includeOptimalSol = 0;
358#endif
359}
360
361void
363 SCIP *scip,
364 ScipParaSolver *scipParaSolver,
365 int nLinearConss,
366 int nAddedConss,
367 SCIP_CONS **addedConss
368 )
369{
370 std::list<BranchConsLinearInfoPtr> branchConsList;
371
372 int lNewConsNames = 0;
373 int nRemoved = 0;
374 for( int c = 0; c < nAddedConss; ++c )
375 {
376 SCIP_CONS* cons = addedConss[c];
377 assert(cons != NULL);
378 const char *conshdlrname = SCIPconshdlrGetName(SCIPconsGetHdlr(cons));
379 if( std::strcmp(conshdlrname, "linear") != 0 ) continue;
380
381 /* create a constraint */
382 SCIP_Bool success = FALSE;
383 int ncols = 0;
384 SCIP_CALL_ABORT(SCIPgetConsNVars(scip,cons,&ncols, &success));
385 if( !success )
386 {
387 THROW_LOGICAL_ERROR1("SCIPgetConsNVars failed");
388 }
389
390 BranchConsLinearInfo *branchConsLinearInfo = new BranchConsLinearInfo;
391 branchConsLinearInfo->nLinearCoefs = ncols;
392 branchConsLinearInfo->idxLinearCoefsVars = new int[ncols];
393 branchConsLinearInfo->linearCoefs = new double[ncols];
394 double lhs, rhs;
395 if( !SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, cons)) )
396 {
397 lhs = SCIPgetLhsLinear(scip, addedConss[c]);
398 }
399 else
400 {
401 lhs = -SCIPinfinity(scip);
402 }
403 if( !SCIPisInfinity(scip, SCIPgetRhsLinear(scip, cons)) )
404 {
405 rhs = SCIPgetRhsLinear(scip, addedConss[c]);
406 }
407 else
408 {
409 rhs = SCIPinfinity(scip);
410 }
411
412 SCIP_VAR** vars = SCIPgetVarsLinear(scip, cons);
413 SCIP_Real* vals = SCIPgetValsLinear(scip, cons);
414
415 int i = 0;
416 bool removeConss = false;
417 for( i = 0; i < ncols; ++i )
418 {
419 SCIP_VAR *transformVar = vars[i];
420 SCIP_Real scalar = vals[i];
421 SCIP_Real constant = 0.0;
422 if( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) == SCIP_INVALIDDATA )
423 break;
424 if( transformVar == NULL )
425 break;
426 // assert(transformVar != NULL);
427 if( !SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, cons)) )
428 {
429 lhs -= constant;
430 }
431 if( !SCIPisInfinity(scip, SCIPgetRhsLinear(scip, cons)) )
432 {
433 rhs -= constant;
434 }
435 if( scipParaSolver->isOriginalIndeciesMap() )
436 {
437 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
438 {
439 branchConsLinearInfo->idxLinearCoefsVars[i] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
440 }
441 else
442 {
443 removeConss = true;
444 break;
445 }
446 }
447 else
448 {
449 branchConsLinearInfo->idxLinearCoefsVars[i] = SCIPvarGetIndex(transformVar);
450 }
451 branchConsLinearInfo->linearCoefs[i] = scalar;
452 }
453 if( i == ncols )
454 {
455 assert( !SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, cons)) == !SCIPisInfinity(scip, -lhs) );
456 assert( !SCIPisInfinity(scip, SCIPgetRhsLinear(scip, cons)) == !SCIPisInfinity(scip, rhs) );
457 branchConsLinearInfo->linearLhs = lhs;
458 branchConsLinearInfo->linearRhs = rhs;
459 branchConsLinearInfo->consName = new char[std::strlen(SCIPconsGetName(cons))+1];
460 lNewConsNames += ( std::strlen(SCIPconsGetName(cons)) + 1);
461 std::strcpy(branchConsLinearInfo->consName, SCIPconsGetName(cons));
462 branchConsList.push_back(branchConsLinearInfo);
463 }
464 else
465 {
466 delete [] branchConsLinearInfo->idxLinearCoefsVars;
467 delete [] branchConsLinearInfo->linearCoefs;
468 delete branchConsLinearInfo;
469 if( removeConss == true )
470 {
471 nRemoved++;
472 continue;
473 }
474 else
475 {
476 THROW_LOGICAL_ERROR1("Something wrong to make a branching linear constraint for original problem");
477 }
478 }
479 }
480 assert( static_cast<int>(branchConsList.size()) == (nLinearConss - nRemoved) );
481
482 ScipParaDiffSubproblem *parentDiffSubproblem = scipParaSolver->getParentDiffSubproblem();
483
484 int nParentConss = 0;
485 if( parentDiffSubproblem && parentDiffSubproblem->branchLinearConss )
486 {
487 nParentConss += parentDiffSubproblem->branchLinearConss->nLinearConss;
488 }
489 if( nParentConss > 0 || branchConsList.size() > 0 )
490 {
492 branchLinearConss->nLinearConss = nParentConss + branchConsList.size();
493 if( nParentConss > 0 )
494 {
495 branchLinearConss->lConsNames = parentDiffSubproblem->branchLinearConss->lConsNames + lNewConsNames;
496 }
497 else
498 {
499 branchLinearConss->lConsNames = lNewConsNames;
500 }
502 {
508 assert( branchLinearConss->lConsNames > 0 );
510
511 char *parentConsName = 0;
512 char *destConsName = branchLinearConss->consNames;
513 int i = 0;
514 if( nParentConss > 0 )
515 {
516 parentConsName = parentDiffSubproblem->branchLinearConss->consNames;
517 i = 0;
518 for(; i < nParentConss; i++ )
519 {
520 branchLinearConss->linearLhss[i] = parentDiffSubproblem->branchLinearConss->linearLhss[i];
521 branchLinearConss->linearRhss[i] = parentDiffSubproblem->branchLinearConss->linearRhss[i];
522 branchLinearConss->nLinearCoefs[i] = parentDiffSubproblem->branchLinearConss->nLinearCoefs[i];
525 for( int j = 0; j < branchLinearConss->nLinearCoefs[i]; j++ )
526 {
527 branchLinearConss->linearCoefs[i][j] = parentDiffSubproblem->branchLinearConss->linearCoefs[i][j];
528 branchLinearConss->idxLinearCoefsVars[i][j] = parentDiffSubproblem->branchLinearConss->idxLinearCoefsVars[i][j];
529 }
530 std::strcpy(destConsName,parentConsName);
531 destConsName += (std::strlen(parentConsName) + 1);
532 parentConsName += (std::strlen(parentConsName) + 1);
533 }
534 }
535
536 int nNewBranchLinearConss = branchConsList.size();
537 for(; i < ( nParentConss + nNewBranchLinearConss ); i++ )
538 {
539 assert(!branchConsList.empty());
540 BranchConsLinearInfo *branchConsLinearInfo = branchConsList.front();
541 branchConsList.pop_front();
542 branchLinearConss->linearLhss[i] = branchConsLinearInfo->linearLhs;
543 branchLinearConss->linearRhss[i] = branchConsLinearInfo->linearRhs;
544 branchLinearConss->nLinearCoefs[i] = branchConsLinearInfo->nLinearCoefs;
547 for( int j = 0; j < branchLinearConss->nLinearCoefs[i]; j++ )
548 {
549 branchLinearConss->linearCoefs[i][j] = branchConsLinearInfo->linearCoefs[j];
550 branchLinearConss->idxLinearCoefsVars[i][j] = branchConsLinearInfo->idxLinearCoefsVars[j];
551 }
552
553 std::strcpy(destConsName, branchConsLinearInfo->consName);
554 destConsName += std::strlen(branchConsLinearInfo->consName) + 1;
555 delete [] branchConsLinearInfo->idxLinearCoefsVars;
556 delete [] branchConsLinearInfo->linearCoefs;
557 delete [] branchConsLinearInfo->consName;
558 delete branchConsLinearInfo;
559 }
560 }
561 }
562}
563
564void
566 SCIP *scip,
567 ScipParaSolver *scipParaSolver,
568 int nSetppcConss,
569 int nAddedConss,
570 SCIP_CONS **addedConss
571 )
572{
573 std::list<BranchConsSetppcInfoPtr> branchConsList;
574
575 int lNewConsNames = 0;
576 int nRemoved = 0;
577 for( int c = 0; c < nAddedConss; ++c )
578 {
579 SCIP_CONS* cons = addedConss[c];
580 assert(cons != NULL);
581 const char *conshdlrname = SCIPconshdlrGetName(SCIPconsGetHdlr(cons));
582 if( std::strcmp(conshdlrname, "setppc") != 0 ) continue;
583
584 /* create a constraint */
585 SCIP_Bool success = FALSE;
586 int ncols = 0;
587 SCIP_CALL_ABORT(SCIPgetConsNVars(scip,cons,&ncols, &success));
588 if( !success )
589 {
590 THROW_LOGICAL_ERROR1("SCIPgetConsNVars failed");
591 }
592
593 BranchConsSetppcInfo *branchConsSetppcInfo = new BranchConsSetppcInfo;
594 branchConsSetppcInfo->nSetppcVars = ncols;
595 branchConsSetppcInfo->setppcType = SCIPgetTypeSetppc(scip, cons);
596 branchConsSetppcInfo->idxSetppcVars = new int[ncols];
597
598 SCIP_VAR** vars = SCIPgetVarsSetppc(scip, cons);
599
600 int i = 0;
601 bool removeConss = false;
602 for( i = 0; i < ncols; ++i )
603 {
604 SCIP_VAR *transformVar = vars[i];
605 SCIP_Real scalar = 1.0;
606 SCIP_Real constant = 0.0;
607 if( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) == SCIP_INVALIDDATA )
608 break;
609 if( transformVar == NULL )
610 break;
611 // assert(transformVar != NULL);
612 if( scipParaSolver->isOriginalIndeciesMap() )
613 {
614 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
615 {
616 branchConsSetppcInfo->idxSetppcVars[i] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
617 }
618 else
619 {
620 removeConss = true;
621 break;
622 }
623
624 }
625 else
626 {
627 branchConsSetppcInfo->idxSetppcVars[i] = SCIPvarGetIndex(transformVar);
628 }
629 // std::cout << "idxSetppcVars[" << i << "] = " << branchConsSetppcInfo->idxSetppcVars[i] << std::endl;
630 }
631 if( i == ncols )
632 {
633 branchConsSetppcInfo->consName = new char[std::strlen(SCIPconsGetName(cons))+1];
634 lNewConsNames += std::strlen(SCIPconsGetName(cons))+1;
635 std::strcpy(branchConsSetppcInfo->consName, SCIPconsGetName(cons));
636 branchConsList.push_back(branchConsSetppcInfo);
637 }
638 else
639 {
640 delete [] branchConsSetppcInfo->idxSetppcVars;
641 delete branchConsSetppcInfo;
642 if( removeConss == true )
643 {
644 nRemoved++;
645 continue;
646 }
647 else
648 {
649 THROW_LOGICAL_ERROR1("Something wrong to make a branching linear constraint for original problem");
650 }
651 }
652 }
653 assert( static_cast<int>(branchConsList.size()) == (nSetppcConss - nRemoved) );
654
655 ScipParaDiffSubproblem *parentDiffSubproblem = scipParaSolver->getParentDiffSubproblem();
656
657 int nParentConss = 0;
658 if( parentDiffSubproblem && parentDiffSubproblem->branchSetppcConss )
659 {
660 nParentConss += parentDiffSubproblem->branchSetppcConss->nSetppcConss;
661 }
662 if( nParentConss > 0 || branchConsList.size() > 0 )
663 {
665 branchSetppcConss->nSetppcConss = nParentConss + branchConsList.size();
666 if( nParentConss > 0 )
667 {
668 branchSetppcConss->lConsNames = parentDiffSubproblem->branchSetppcConss->lConsNames + lNewConsNames;
669 }
670 else
671 {
672 branchSetppcConss->lConsNames = lNewConsNames;
673 }
675 {
679 assert( branchSetppcConss->lConsNames > 0 );
681
682 char *parentConsName = 0;
683 char *destConsName = branchSetppcConss->consNames;
684 int i = 0;
685 if( nParentConss > 0 )
686 {
687 parentConsName = parentDiffSubproblem->branchSetppcConss->consNames;
688 i = 0;
689 for(; i < nParentConss; i++ )
690 {
691 branchSetppcConss->nSetppcVars[i] = parentDiffSubproblem->branchSetppcConss->nSetppcVars[i];
692 branchSetppcConss->setppcTypes[i] = parentDiffSubproblem->branchSetppcConss->setppcTypes[i];
694 for( int j = 0; j < branchSetppcConss->nSetppcVars[i]; j++ )
695 {
696 branchSetppcConss->idxSetppcVars[i][j] = parentDiffSubproblem->branchSetppcConss->idxSetppcVars[i][j];
697 }
698 std::strcpy(destConsName,parentConsName);
699 destConsName += (std::strlen(parentConsName) + 1);
700 parentConsName += (std::strlen(parentConsName) + 1);
701 }
702 }
703
704 int nNewBranchSetppcConss = branchConsList.size();
705 for(; i < ( nParentConss + nNewBranchSetppcConss ); i++ )
706 {
707 assert(!branchConsList.empty());
708 BranchConsSetppcInfo *branchConsSetppcInfo = branchConsList.front();
709 branchConsList.pop_front();
710 branchSetppcConss->nSetppcVars[i] = branchConsSetppcInfo->nSetppcVars;
711 branchSetppcConss->setppcTypes[i] = branchConsSetppcInfo->setppcType;
713 for( int j = 0; j < branchSetppcConss->nSetppcVars[i]; j++ )
714 {
715 branchSetppcConss->idxSetppcVars[i][j] = branchConsSetppcInfo->idxSetppcVars[j];
716 }
717 std::strcpy(destConsName, branchConsSetppcInfo->consName);
718 destConsName += (std::strlen(branchConsSetppcInfo->consName) + 1);
719 delete [] branchConsSetppcInfo->idxSetppcVars;
720 delete [] branchConsSetppcInfo->consName;
721 delete branchConsSetppcInfo;
722 }
723 }
724 }
725}
726
727void
729 SCIP *scip,
730 ScipParaSolver *scipParaSolver
731 )
732{
733 std::list<LocalNodeInfoPtr> localCutsList;
734
735 if( scipParaSolver->getParaParamSet()->getBoolParamValue(TransferLocalCuts) )
736 {
737 SCIP_CUT** cuts;
738 int ncuts;
739
740 cuts = SCIPgetPoolCuts(scip);
741 ncuts = SCIPgetNPoolCuts(scip);
742 int nRemoved = 0;
743
744 int *orgVarIndexies = new int[scipParaSolver->getNOrgVars()];
745 double *orgVarCoefficients = new double[scipParaSolver->getNOrgVars()];
746
747 for( int c = 0; c < ncuts; ++c )
748 {
749 SCIP_ROW* row;
750 bool removeConss = false;
751 row = SCIPcutGetRow(cuts[c]);
752 assert(!SCIProwIsLocal(row));
753 assert(!SCIProwIsModifiable(row));
754 if( SCIPcutGetAge(cuts[c]) == 0 && SCIProwIsInLP(row) )
755 {
756 SCIP_COL** cols;
757 int ncols;
758 int i;
759
760 /* create a linear constraint out of the cut */
761 cols = SCIProwGetCols(row);
762 ncols = SCIProwGetNNonz(row);
763
764 LocalNodeInfo *localNodeInfo = new LocalNodeInfo;
765 localNodeInfo->nLinearCoefs = ncols;
766 localNodeInfo->idxLinearCoefsVars = new int[ncols];
767 localNodeInfo->linearCoefs = new double[ncols];
768 double lhs, rhs;
769 if( !SCIPisInfinity(scip, -SCIProwGetLhs(row)) )
770 {
771 lhs = SCIProwGetLhs(row) - SCIProwGetConstant(row);
772 }
773 else
774 {
775 lhs = -SCIPinfinity(scip);
776 }
777 if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) )
778 {
779 rhs = SCIProwGetRhs(row) - SCIProwGetConstant(row);
780 }
781 else
782 {
783 rhs = SCIPinfinity(scip);
784 }
785
786 for( int j = 0; j < scipParaSolver->getNOrgVars(); j++ )
787 {
788 orgVarIndexies[j] = -1;
789 orgVarCoefficients[j] = 0.0;
790 }
791 SCIP_Real *vals = SCIProwGetVals(row);
792 for( i = 0; i < ncols; ++i )
793 {
794 int index = -1;
795 SCIP_VAR *transformVar = SCIPcolGetVar(cols[i]);
796 SCIP_Real scalar = vals[i];
797 SCIP_Real constant = 0.0;
798 if( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) == SCIP_INVALIDDATA )
799 {
800 removeConss = true;
801 break;
802 }
803 if( transformVar == NULL )
804 {
805 removeConss = true;
806 break;
807 }
808 // assert(transformVar != NULL);
809 if( !SCIPisInfinity(scip, -SCIProwGetLhs(row)) )
810 {
811 lhs -= constant;
812 }
813 if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) )
814 {
815 rhs -= constant;
816 }
817 if( scipParaSolver->isOriginalIndeciesMap() )
818 {
819 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
820 {
821 // localNodeInfo->idxLinearCoefsVars[i] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
822 index = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
823 }
824 else
825 {
826 removeConss = true;
827 break;
828 }
829 }
830 else
831 {
832 // localNodeInfo->idxLinearCoefsVars[i] = SCIPvarGetIndex(transformVar);
833 index = SCIPvarGetIndex(transformVar);
834 }
835 // localNodeInfo->linearCoefs[i] = scalar;
836 assert( index >= 0 && index < scipParaSolver->getNOrgVars() );
837 if( orgVarIndexies[index] == -1 )
838 {
839 orgVarIndexies[index] = index;
840 orgVarCoefficients[index] = scalar;
841 }
842 else
843 {
844 orgVarCoefficients[index] += scalar;
845 std::cout << "*** Duplicate index = " << index << ", value = " << scalar << std::endl;
846 }
847 }
848 if( i == ncols )
849 {
850 assert( !SCIPisInfinity(scip, -SCIProwGetLhs(row)) == !SCIPisInfinity(scip, -lhs) );
851 assert( !SCIPisInfinity(scip, SCIProwGetRhs(row)) == !SCIPisInfinity(scip, rhs) );
852 int nRowCols = 0;;
853 for (int j = 0; j < scipParaSolver->getNOrgVars(); j++ )
854 {
855 if( orgVarIndexies[j] >= 0 )
856 {
857 localNodeInfo->idxLinearCoefsVars[nRowCols] = j;
858 localNodeInfo->linearCoefs[nRowCols] = orgVarCoefficients[j];
859 nRowCols++;
860 }
861 }
862 assert( nRowCols > 0 );
863 // std::cout << "i = " << i << ", nRows = " << nRowCols << std::endl;
864 localNodeInfo->nLinearCoefs = nRowCols;
865 localNodeInfo->linearLhs = lhs;
866 localNodeInfo->linearRhs = rhs;
867 localCutsList.push_back(localNodeInfo);
868 }
869 else
870 {
871 delete [] localNodeInfo->idxLinearCoefsVars;
872 delete [] localNodeInfo->linearCoefs;
873 delete localNodeInfo;
874 if( removeConss == true )
875 {
876 nRemoved++;
877 continue;
878 }
879 else
880 {
881 THROW_LOGICAL_ERROR1("Something wrong to make a local node info for original problem");
882 }
883 }
884 }
885 }
886 delete [] orgVarIndexies;
887 delete [] orgVarCoefficients;
888 }
889
890
891 ScipParaDiffSubproblem *parentDiffSubproblem = scipParaSolver->getParentDiffSubproblem();
892 std::list<LocalNodeInfoPtr> *conflictConsList = scipParaSolver->getConflictConsList();
893
894 int nParentConss = 0;
895 if( parentDiffSubproblem && parentDiffSubproblem->linearConss )
896 {
897 nParentConss += parentDiffSubproblem->linearConss->nLinearConss;
898 }
899 int nConflicts = 0;
900 if( conflictConsList ) nConflicts += conflictConsList->size();
901 if( nParentConss > 0 || nConflicts > 0 || localCutsList.size() > 0 )
902 {
904 linearConss->nLinearConss = nParentConss + localCutsList.size() + nConflicts;
906 if( linearConss->nLinearConss > 0 )
907 {
913
914 int i = 0;
915 for(; i < nParentConss; i++ )
916 {
917 linearConss->linearLhss[i] = parentDiffSubproblem->linearConss->linearLhss[i];
918 linearConss->linearRhss[i] = parentDiffSubproblem->linearConss->linearRhss[i];
919 linearConss->nLinearCoefs[i] = parentDiffSubproblem->linearConss->nLinearCoefs[i];
920 linearConss->linearCoefs[i] = new SCIP_Real[linearConss->nLinearCoefs[i]];
922 for( int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
923 {
924 linearConss->linearCoefs[i][j] = parentDiffSubproblem->linearConss->linearCoefs[i][j];
925 linearConss->idxLinearCoefsVars[i][j] = parentDiffSubproblem->linearConss->idxLinearCoefsVars[i][j];
926 }
927 }
928
929 int nLocalCuts = localCutsList.size();
930 for(; i < ( nParentConss + nLocalCuts ); i++ )
931 {
932 assert(!localCutsList.empty());
933 LocalNodeInfo *cutInfo = localCutsList.front();
934 localCutsList.pop_front();
935 linearConss->linearLhss[i] = cutInfo->linearLhs;
936 linearConss->linearRhss[i] = cutInfo->linearRhs;
938 linearConss->linearCoefs[i] = new SCIP_Real[linearConss->nLinearCoefs[i]];
940 for( int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
941 {
942 linearConss->linearCoefs[i][j] = cutInfo->linearCoefs[j];
944 }
945 delete [] cutInfo->idxLinearCoefsVars;
946 delete [] cutInfo->linearCoefs;
947 delete cutInfo;
948 }
949
950 if( i < linearConss->nLinearConss )
951 {
952 assert( conflictConsList );
953 std::list<LocalNodeInfoPtr>::iterator pos;
954 pos = conflictConsList->begin();
955 for(; i < linearConss->nLinearConss; i++ )
956 {
957 assert( pos != conflictConsList->end() );
958 linearConss->linearLhss[i] = (*pos)->linearLhs;
959 linearConss->linearRhss[i] = (*pos)->linearRhs;
960 linearConss->nLinearCoefs[i] = (*pos)->nLinearCoefs;
961 linearConss->linearCoefs[i] = new SCIP_Real[linearConss->nLinearCoefs[i]];
963 for( int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
964 {
965 linearConss->linearCoefs[i][j] = (*pos)->linearCoefs[j];
966 linearConss->idxLinearCoefsVars[i][j] = (*pos)->idxLinearCoefsVars[j];
967 }
968 pos++;
969 }
970 }
971 }
972 }
973
974#if SCIP_APIVERSION > 39
975 std::list<LocalNodeInfoPtr> bendersCutsList;
976
978 {
979 int nVars = SCIPgetNVars(scip);
980 SCIP_Var **vars = new SCIP_Var*[nVars];
981 SCIP_Real *values = new SCIP_Real[nVars];
982 int nActiveBenders = SCIPgetNActiveBenders(scip);
983 SCIP_BENDERS** benders = SCIPgetBenders(scip);
984
985 for( int i = 0; i < nActiveBenders; i++ )
986 {
987 int nCuts = SCIPbendersGetNStoredCuts(benders[i]);
988 for (int cutidx = 0; cutidx < nCuts; cutidx++ )
989 {
990 int nVarsInCut = 0;
991 SCIP_Real lhs = 0.0;
992 SCIP_Real rhs = 0.0;
993 SCIP_CALL_ABORT( SCIPbendersGetStoredCutOrigData(benders[i], cutidx, &vars, &values, &lhs, &rhs, &nVarsInCut, nVars) );
994 assert(nVarsInCut <= nVars);
995 LocalNodeInfo *localNodeInfo = new LocalNodeInfo;
996 localNodeInfo->nLinearCoefs = nVarsInCut;
997 localNodeInfo->idxLinearCoefsVars = new int[nVarsInCut];
998 localNodeInfo->linearCoefs = new double[nVarsInCut];
999 for( int j = 0; j < nVarsInCut; j++ )
1000 {
1001 if( scipParaSolver->isOriginalIndeciesMap() )
1002 {
1003 localNodeInfo->idxLinearCoefsVars[j] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(vars[j]));
1004 }
1005 else
1006 {
1007 localNodeInfo->idxLinearCoefsVars[j] = SCIPvarGetIndex(vars[j]);
1008 }
1009 localNodeInfo->linearCoefs[j] = values[j];
1010 }
1011 localNodeInfo->linearLhs = lhs;
1012 localNodeInfo->linearRhs = rhs;
1013 bendersCutsList.push_back(localNodeInfo);
1014 }
1015 }
1016 delete [] vars;
1017 delete [] values;
1018 }
1019
1020 nParentConss = 0;
1021 if( parentDiffSubproblem && parentDiffSubproblem->bendersLinearConss )
1022 {
1023 nParentConss += parentDiffSubproblem->bendersLinearConss->nLinearConss;
1024 }
1025
1026 if( nParentConss > 0 || bendersCutsList.size() > 0 )
1027 {
1029 bendersLinearConss->nLinearConss = nParentConss + bendersCutsList.size();
1032 {
1038
1039 int i = 0;
1040 for(; i < nParentConss; i++ )
1041 {
1042 bendersLinearConss->linearLhss[i] = parentDiffSubproblem->bendersLinearConss->linearLhss[i];
1043 bendersLinearConss->linearRhss[i] = parentDiffSubproblem->bendersLinearConss->linearRhss[i];
1044 bendersLinearConss->nLinearCoefs[i] = parentDiffSubproblem->bendersLinearConss->nLinearCoefs[i];
1047 for( int j = 0; j < bendersLinearConss->nLinearCoefs[i]; j++ )
1048 {
1049 bendersLinearConss->linearCoefs[i][j] = parentDiffSubproblem->bendersLinearConss->linearCoefs[i][j];
1050 bendersLinearConss->idxLinearCoefsVars[i][j] = parentDiffSubproblem->bendersLinearConss->idxLinearCoefsVars[i][j];
1051 }
1052 }
1053
1054 int nBendersCuts = bendersCutsList.size();
1055 for(; i < ( nParentConss + nBendersCuts ); i++ )
1056 {
1057 assert(!bendersCutsList.empty());
1058 LocalNodeInfo *cutInfo = bendersCutsList.front();
1059 bendersCutsList.pop_front();
1065 for( int j = 0; j < bendersLinearConss->nLinearCoefs[i]; j++ )
1066 {
1067 bendersLinearConss->linearCoefs[i][j] = cutInfo->linearCoefs[j];
1069 }
1070 delete [] cutInfo->idxLinearCoefsVars;
1071 delete [] cutInfo->linearCoefs;
1072 delete cutInfo;
1073 }
1074 assert( i == bendersLinearConss->nLinearConss );
1075 }
1076 }
1077#endif
1078
1079}
1080
1081void
1083 SCIP *scip,
1084 ScipParaSolver *scipParaSolver
1085 )
1086{
1089 for( int i = 0; i < SCIPgetNConshdlrs(scip); ++i )
1090 {
1091 SCIP_CONSHDLR* conshdlr = SCIPgetConshdlrs(scip)[i];
1092 int nactiveconss = SCIPconshdlrGetNActiveConss(conshdlr);
1093 if( nactiveconss > 0
1094 && std::string(SCIPconshdlrGetName(conshdlr)) == std::string("bounddisjunction") )
1095 {
1096 boundDisjunctions->nBoundDisjunctions = nactiveconss;
1097 SCIP_CONS **conss = SCIPconshdlrGetConss(conshdlr);
1112 int nConss = 0;
1113 int nTotalVars = 0;
1114 for( int c = 0; c < nactiveconss; c++ )
1115 {
1116 boundDisjunctions->nVarsBoundDisjunction[nConss] = SCIPgetNVarsBounddisjunction (scip, conss[c]);
1117 boundDisjunctions->flagBoundDisjunctionInitial[nConss] = SCIPconsIsInitial(conss[c]);
1118 boundDisjunctions->flagBoundDisjunctionSeparate[nConss] = SCIPconsIsSeparated(conss[c]);
1119 boundDisjunctions->flagBoundDisjunctionEnforce[nConss] = SCIPconsIsEnforced(conss[c]);
1120 boundDisjunctions->flagBoundDisjunctionCheck[nConss] = SCIPconsIsChecked(conss[c]);
1121 boundDisjunctions->flagBoundDisjunctionPropagate[nConss] = SCIPconsIsPropagated(conss[c]);
1122 boundDisjunctions->flagBoundDisjunctionLocal[nConss] = SCIPconsIsLocal(conss[c]);
1123 boundDisjunctions->flagBoundDisjunctionModifiable[nConss] = SCIPconsIsModifiable(conss[c]);
1124 boundDisjunctions->flagBoundDisjunctionDynamic[nConss] = SCIPconsIsDynamic(conss[c]);
1125 boundDisjunctions->flagBoundDisjunctionRemovable[nConss] = SCIPconsIsRemovable(conss[c]);
1126 boundDisjunctions->flagBoundDisjunctionStickingatnode[nConss] =SCIPconsIsStickingAtNode(conss[c]);
1127 if( boundDisjunctions->nVarsBoundDisjunction[nConss] > 0 )
1128 {
1132 int v = 0;
1133 SCIP_VAR **vars = SCIPgetVarsBounddisjunction(scip, conss[c]);
1134 SCIP_BOUNDTYPE *types = SCIPgetBoundtypesBounddisjunction(scip, conss[c]);
1135 SCIP_Real *bounds = SCIPgetBoundsBounddisjunction(scip, conss[c]);
1136 for( ; v < boundDisjunctions->nVarsBoundDisjunction[nConss]; v++ )
1137 {
1138 if( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_MULTAGGR )
1139 {
1140 break;
1141 }
1142 SCIP_VAR *transformVar = vars[v];
1143 SCIP_Real scalar = 1.0;
1144 SCIP_Real constant = 0.0;
1145 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) );
1146 if( transformVar )
1147 {
1148 if( scipParaSolver->isOriginalIndeciesMap( ))
1149 {
1150 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
1151 {
1152 boundDisjunctions->idxBoundDisjunctionVars[nConss][v] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
1153 }
1154 else
1155 {
1156 break;
1157 }
1158 }
1159 else
1160 {
1161 boundDisjunctions->idxBoundDisjunctionVars[nConss][v] = SCIPvarGetIndex(transformVar);
1162 }
1163 // assert( boundDisjunctions->idxBoundDisjunctionVars[nConss][v] >= 0 );
1164 if( boundDisjunctions->idxBoundDisjunctionVars[nConss][v] < 0 ||
1165 ( scipParaSolver->isCopyIncreasedVariables() &&
1166 boundDisjunctions->idxBoundDisjunctionVars[nConss][v] >= scipParaSolver->getNOrgVars() )
1167 )
1168 {
1169 break;
1170 }
1171 if( scalar > 0 )
1172 {
1173 boundDisjunctions->boundTypesBoundDisjunction[nConss][v] = types[v];
1174 }
1175 else
1176 {
1177 boundDisjunctions->boundTypesBoundDisjunction[nConss][v] = SCIP_BoundType(1 - types[v]);
1178 }
1179 boundDisjunctions->boundsBoundDisjunction[nConss][v] = ( bounds[v] - constant ) / scalar;
1180 // nTotalVars++;
1181 }
1182 else
1183 {
1184 break;
1185 }
1186 }
1187 if( v == boundDisjunctions->nVarsBoundDisjunction[nConss] )
1188 {
1189 nTotalVars += v;
1190 nConss++;
1191 }
1192 else
1193 {
1194 delete [] boundDisjunctions->boundsBoundDisjunction[nConss];
1196 delete [] boundDisjunctions->idxBoundDisjunctionVars[nConss];
1211 }
1212 }
1213 }
1216 }
1217 }
1219 {
1220 delete boundDisjunctions;
1222 }
1223}
1224
1225void
1227 SCIP *scip,
1228 ScipParaSolver *scipParaSolver
1229 )
1230{
1231 int nvars; /* number of variables */
1232 int nbinvars; /* number of binary variables */
1233 int nintvars; /* number of integer variables */
1234 SCIP_VAR** vars; /* transformed problem's variables */
1235 SCIP_CALL_ABORT( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
1236 int ngenvars = nbinvars+nintvars;
1238 varBranchStats->idxBranchStatsVars = new int[ngenvars];
1239 varBranchStats->downpscost = new SCIP_Real[ngenvars];
1240 varBranchStats->uppscost = new SCIP_Real[ngenvars];
1241 varBranchStats->downvsids = new SCIP_Real[ngenvars];
1242 varBranchStats->upvsids = new SCIP_Real[ngenvars];
1243 varBranchStats->downconflen = new SCIP_Real[ngenvars];
1244 varBranchStats->upconflen = new SCIP_Real[ngenvars];
1245 varBranchStats->downinfer = new SCIP_Real[ngenvars];
1246 varBranchStats->upinfer = new SCIP_Real[ngenvars];
1247 varBranchStats->downcutoff = new SCIP_Real[ngenvars];
1248 varBranchStats->upcutoff = new SCIP_Real[ngenvars];
1249 int nOrgVars = 0;
1250 for( int i = 0; i < ngenvars; ++i )
1251 {
1252 assert( SCIPvarGetType(vars[i]) == SCIP_VARTYPE_BINARY || SCIPvarGetType(vars[i]) == SCIP_VARTYPE_INTEGER );
1253 SCIP_VAR *transformVar = vars[i];
1254 SCIP_Real scalar = 1.0;
1255 SCIP_Real constant = 0.0;
1256 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) );
1257 // assert(transformVar != NULL);
1258 if( transformVar ) // The variable in the transformed space
1259 {
1260 if( scipParaSolver->isOriginalIndeciesMap() )
1261 {
1262 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
1263 {
1264 varBranchStats->idxBranchStatsVars[nOrgVars] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
1265 }
1266 else
1267 {
1268 continue;
1269 }
1270 }
1271 else
1272 {
1273 varBranchStats->idxBranchStatsVars[nOrgVars] = SCIPvarGetIndex(transformVar);
1274 }
1275
1276 if( varBranchStats->idxBranchStatsVars[nOrgVars] < 0 || varBranchStats->idxBranchStatsVars[nOrgVars] >= scipParaSolver->getNOrgVars() )
1277 {
1278 continue;
1279 }
1280
1281 SCIP_BRANCHDIR branchdir1;
1282 SCIP_BRANCHDIR branchdir2;
1283 if( scalar > 0.0 )
1284 {
1285 branchdir1 = SCIP_BRANCHDIR_DOWNWARDS;
1286 branchdir2 = SCIP_BRANCHDIR_UPWARDS;
1287 }
1288 else
1289 {
1290 branchdir1 = SCIP_BRANCHDIR_UPWARDS;
1291 branchdir2 = SCIP_BRANCHDIR_DOWNWARDS;
1292 }
1293 varBranchStats->downpscost[nOrgVars] = SCIPgetVarPseudocost(scip, vars[i], branchdir1);
1294 varBranchStats->uppscost[nOrgVars] = SCIPgetVarPseudocost(scip, vars[i], branchdir2);
1295 varBranchStats->downvsids[nOrgVars] = SCIPgetVarVSIDS(scip, vars[i], branchdir1);
1296 varBranchStats->upvsids[nOrgVars] = SCIPgetVarVSIDS(scip, vars[i], branchdir2);
1297 varBranchStats->downconflen[nOrgVars] = SCIPgetVarAvgConflictlength(scip, vars[i], branchdir1);
1298 varBranchStats->upconflen[nOrgVars] = SCIPgetVarAvgConflictlength(scip, vars[i], branchdir2);
1299 varBranchStats->downinfer[nOrgVars] = SCIPgetVarAvgInferences(scip, vars[i], branchdir1);
1300 varBranchStats->upinfer[nOrgVars] = SCIPgetVarAvgInferences(scip, vars[i], branchdir2);
1301 varBranchStats->downcutoff[nOrgVars] = SCIPgetVarAvgCutoffs(scip, vars[i], branchdir1);
1302 varBranchStats->upcutoff[nOrgVars] = SCIPgetVarAvgCutoffs(scip, vars[i], branchdir2);
1303 nOrgVars++;
1304 }
1305 }
1306 // assert( nOrgVars == scipParaSolver->getNOrgVars() ); This is true.
1307 varBranchStats->nVarBranchStats = nOrgVars;
1308}
1309
1310void
1312 SCIP *scip,
1313 ScipParaSolver *scipParaSolver
1314 )
1315{
1316 int nvars; /* number of variables */
1317 int nbinvars; /* number of binary variables */
1318 int nintvars; /* number of integer variables */
1319 SCIP_VAR** vars; /* transformed problem's variables */
1320 SCIP_CALL_ABORT( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
1321 int ngenvars = nbinvars+nintvars;
1322
1324
1326 varValues->nVarValues = 0;
1327
1328 if( ngenvars > 0 )
1329 {
1330 varValues->idxVarValueVars = new int[ngenvars];
1331 varValues->nVarValueValues = new int[ngenvars];
1332
1333 varValues->varValue = new SCIP_Real*[ngenvars];
1334 varValues->varValueDownvsids = new SCIP_Real*[ngenvars];
1335 varValues->varVlaueUpvsids = new SCIP_Real*[ngenvars];
1336 varValues->varValueDownconflen = new SCIP_Real*[ngenvars];
1337 varValues->varValueUpconflen = new SCIP_Real*[ngenvars];
1338 varValues->varValueDowninfer = new SCIP_Real*[ngenvars];
1339 varValues->varValueUpinfer = new SCIP_Real*[ngenvars];
1340 varValues->varValueDowncutoff = new SCIP_Real*[ngenvars];
1341 varValues->varValueUpcutoff = new SCIP_Real*[ngenvars];
1342
1343
1344 for( int i = 0; i < ngenvars; i++ )
1345 {
1346 assert( SCIPvarGetType(vars[i]) == SCIP_VARTYPE_BINARY || SCIPvarGetType(vars[i]) == SCIP_VARTYPE_INTEGER );
1347
1348 SCIP_VAR *transformVar = vars[i];
1349 SCIP_Real scalar = 1.0;
1350 SCIP_Real constant = 0.0;
1351 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&transformVar, &scalar, &constant ) );
1352 // assert(transformVar != NULL);
1353
1354 if( transformVar ) // The variable in the transformed space
1355 {
1356 SCIP_VALUEHISTORY* valuehistory = SCIPvarGetValuehistory(vars[i]);
1357 if( valuehistory != NULL )
1358 {
1359 SCIP_HISTORY** histories;
1360 SCIP_Real* values;
1361
1362 histories = SCIPvaluehistoryGetHistories(valuehistory);
1363 values = SCIPvaluehistoryGetValues(valuehistory);
1364
1365 if( scipParaSolver->isOriginalIndeciesMap() )
1366 {
1367 if( scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar)) >= 0 )
1368 {
1369 varValues->idxVarValueVars[varValues->nVarValueVars] = scipParaSolver->getOriginalIndex(SCIPvarGetIndex(transformVar));
1370 }
1371 else
1372 {
1373 continue;
1374 }
1375 }
1376 else
1377 {
1378 varValues->idxVarValueVars[varValues->nVarValueVars] = SCIPvarGetIndex(transformVar);
1379 }
1380
1382 {
1383 continue;
1384 }
1385
1386 varValues->nVarValueValues[varValues->nVarValueVars] = SCIPvaluehistoryGetNValues(valuehistory);
1387
1389 {
1399 for( int j = 0; j < varValues->nVarValueValues[varValues->nVarValueVars]; j++ )
1400 {
1401 varValues->varValue[varValues->nVarValueVars][j] = values[j];
1402 varValues->varValueDownvsids[varValues->nVarValueVars][j] = SCIPhistoryGetVSIDS( histories[j], SCIP_BRANCHDIR_DOWNWARDS );
1403 varValues->varVlaueUpvsids[varValues->nVarValueVars][j] = SCIPhistoryGetVSIDS( histories[j], SCIP_BRANCHDIR_UPWARDS );
1404 varValues->varValueDownconflen[varValues->nVarValueVars][j] = SCIPhistoryGetAvgConflictlength( histories[j], SCIP_BRANCHDIR_DOWNWARDS );
1405 varValues->varValueUpconflen[varValues->nVarValueVars][j] = SCIPhistoryGetAvgConflictlength( histories[j], SCIP_BRANCHDIR_UPWARDS );
1406 varValues->varValueDowninfer[varValues->nVarValueVars][j] = SCIPhistoryGetInferenceSum( histories[j], SCIP_BRANCHDIR_DOWNWARDS );
1407 varValues->varValueUpinfer[varValues->nVarValueVars][j] = SCIPhistoryGetInferenceSum( histories[j], SCIP_BRANCHDIR_UPWARDS );
1408 varValues->varValueDowncutoff[varValues->nVarValueVars][j] = SCIPhistoryGetCutoffSum( histories[j], SCIP_BRANCHDIR_DOWNWARDS );
1409 varValues->varValueUpcutoff[varValues->nVarValueVars][j] = SCIPhistoryGetCutoffSum( histories[j], SCIP_BRANCHDIR_UPWARDS );
1411 }
1412 }
1414 }
1415 }
1416 }
1417 }
1418 if( varValues->nVarValueVars == 0 )
1419 {
1420 delete varValues;
1421 varValues = 0;
1422 }
1423}
1424
1425void
1427 int inMinDepth,
1428 int inMaxDepth,
1429 SCIP *scip
1430 )
1431{
1432 if( varBranchStats ) return; /* if this is not initial transfer to the other solvers, do nothing */
1433
1435 varBranchStats->offset = inMinDepth;
1436
1437 int nvars; /* number of variables */
1438 int nbinvars; /* number of binary variables */
1439 int nintvars; /* number of integer variables */
1440 SCIP_VAR** vars; /* transformed problem's variables */
1441 SCIP_CALL_ABORT( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
1442 int ngenvars = nbinvars+nintvars;
1443 varBranchStats->nVarBranchStats = ngenvars;
1444 varBranchStats->idxBranchStatsVars = new int[ngenvars];
1445 varBranchStats->downpscost = new SCIP_Real[ngenvars];
1446 varBranchStats->uppscost = new SCIP_Real[ngenvars];
1447 varBranchStats->downvsids = new SCIP_Real[ngenvars];
1448 varBranchStats->upvsids = new SCIP_Real[ngenvars];
1449 varBranchStats->downconflen = new SCIP_Real[ngenvars];
1450 varBranchStats->upconflen = new SCIP_Real[ngenvars];
1451 varBranchStats->downinfer = new SCIP_Real[ngenvars];
1452 varBranchStats->upinfer = new SCIP_Real[ngenvars];
1453 varBranchStats->downcutoff = new SCIP_Real[ngenvars];
1454 varBranchStats->upcutoff = new SCIP_Real[ngenvars];
1455 for( int i = 0; i < ngenvars; ++i )
1456 {
1457 assert( SCIPvarGetType(vars[i]) == SCIP_VARTYPE_BINARY || SCIPvarGetType(vars[i]) == SCIP_VARTYPE_INTEGER );
1458 varBranchStats->idxBranchStatsVars[i] = SCIPvarGetProbindex(vars[i]);
1459 varBranchStats->downpscost[i] = SCIPgetVarPseudocost(scip, vars[i], SCIP_BRANCHDIR_DOWNWARDS);
1460 varBranchStats->uppscost[i] = SCIPgetVarPseudocost(scip, vars[i], SCIP_BRANCHDIR_UPWARDS);
1461 varBranchStats->downvsids[i] = SCIPgetVarVSIDS(scip, vars[i], SCIP_BRANCHDIR_DOWNWARDS);
1462 varBranchStats->upvsids[i] = SCIPgetVarVSIDS(scip, vars[i], SCIP_BRANCHDIR_UPWARDS);
1463 varBranchStats->downconflen[i] = SCIPgetVarAvgConflictlength(scip, vars[i], SCIP_BRANCHDIR_DOWNWARDS);
1464 varBranchStats->upconflen[i] = SCIPgetVarAvgConflictlength(scip, vars[i], SCIP_BRANCHDIR_UPWARDS);
1465 varBranchStats->downinfer[i] = SCIPgetVarAvgInferences(scip, vars[i], SCIP_BRANCHDIR_DOWNWARDS);
1466 varBranchStats->upinfer[i] = SCIPgetVarAvgInferences(scip, vars[i], SCIP_BRANCHDIR_UPWARDS);
1467 varBranchStats->downcutoff[i] = SCIPgetVarAvgCutoffs(scip, vars[i], SCIP_BRANCHDIR_DOWNWARDS);
1468 varBranchStats->upcutoff[i] = SCIPgetVarAvgCutoffs(scip, vars[i], SCIP_BRANCHDIR_UPWARDS);
1469 }
1470}
1471
1472#ifdef UG_WITH_ZLIB
1473void
1475 gzstream::ogzstream &out
1476 )
1477{
1478
1479 // std::cout << toString() << std::endl;
1480
1481 int dummyZero = 0;
1482
1483#ifdef UG_SCIP_V31_CHECK_POINT_FILES
1484
1485 out.write((char *)&localInfoIncluded, sizeof(int));
1486 out.write((char *)&nBoundChanges, sizeof(int));
1487 for(int i = 0; i < nBoundChanges; i++ )
1488 {
1489 out.write((char *)&indicesAmongSolvers[i], sizeof(int));
1490 out.write((char *)&branchBounds[i], sizeof(SCIP_Real));
1491 out.write((char *)&boundTypes[i], sizeof(int));
1492 }
1493
1494 if( linearConss )
1495 {
1496 out.write((char *)&(linearConss->nLinearConss), sizeof(int));
1497 for(int i = 0; i < linearConss->nLinearConss; i++ )
1498 {
1499 out.write((char *)&(linearConss->linearLhss[i]), sizeof(SCIP_Real));
1500 out.write((char *)&(linearConss->linearRhss[i]), sizeof(SCIP_Real));
1501 out.write((char *)&(linearConss->nLinearCoefs[i]), sizeof(int));
1502 for(int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
1503 {
1504 out.write((char *)&(linearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1505 out.write((char *)&(linearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1506 }
1507 }
1508 }
1509 else
1510 {
1511 out.write((char *)&dummyZero, sizeof(int));
1512 }
1513
1514 if( varBranchStats )
1515 {
1516 out.write((char *)&(varBranchStats->offset), sizeof(int));
1517 out.write((char *)&(varBranchStats->nVarBranchStats), sizeof(int));
1518 for(int i = 0; i < varBranchStats->nVarBranchStats; i++ )
1519 {
1520 out.write((char *)&(varBranchStats->idxBranchStatsVars[i]), sizeof(int));
1521 out.write((char *)&(varBranchStats->downpscost[i]), sizeof(SCIP_Real));
1522 out.write((char *)&(varBranchStats->uppscost[i]), sizeof(SCIP_Real));
1523 out.write((char *)&(varBranchStats->downvsids[i]), sizeof(SCIP_Real));
1524 out.write((char *)&(varBranchStats->upvsids[i]), sizeof(SCIP_Real));
1525 out.write((char *)&(varBranchStats->downconflen[i]), sizeof(SCIP_Real));
1526 out.write((char *)&(varBranchStats->upconflen[i]), sizeof(SCIP_Real));
1527 out.write((char *)&(varBranchStats->downinfer[i]), sizeof(SCIP_Real));
1528 out.write((char *)&(varBranchStats->upinfer[i]), sizeof(SCIP_Real));
1529 out.write((char *)&(varBranchStats->downcutoff[i]), sizeof(SCIP_Real));
1530 out.write((char *)&(varBranchStats->upcutoff[i]), sizeof(SCIP_Real));
1531 }
1532 }
1533 else
1534 {
1535 /* for backward consistency */
1536 out.write((char *)&dummyZero, sizeof(int));
1537 out.write((char *)&dummyZero, sizeof(int));
1538 }
1539
1540#else
1541
1542
1543 out.write((char *)&localInfoIncluded, sizeof(int));
1544 out.write((char *)&nBoundChanges, sizeof(int));
1545 for(int i = 0; i < nBoundChanges; i++ )
1546 {
1547 out.write((char *)&indicesAmongSolvers[i], sizeof(int));
1548 out.write((char *)&branchBounds[i], sizeof(SCIP_Real));
1549 out.write((char *)&boundTypes[i], sizeof(int));
1550 }
1551
1552 if( branchLinearConss )
1553 {
1554 out.write((char *)&(branchLinearConss->nLinearConss), sizeof(int));
1555 for(int i = 0; i < branchLinearConss->nLinearConss; i++ )
1556 {
1557 out.write((char *)&(branchLinearConss->linearLhss[i]), sizeof(SCIP_Real));
1558 out.write((char *)&(branchLinearConss->linearRhss[i]), sizeof(SCIP_Real));
1559 out.write((char *)&(branchLinearConss->nLinearCoefs[i]), sizeof(int));
1560 assert( branchLinearConss->nLinearCoefs[i] > 0 );
1561 for(int j = 0; j < branchLinearConss->nLinearCoefs[i]; j++ )
1562 {
1563 out.write((char *)&(branchLinearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1564 out.write((char *)&(branchLinearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1565 }
1566 }
1567 out.write((char *)&(branchLinearConss->lConsNames), sizeof(int));
1568 out.write((char *)&(branchLinearConss->consNames[0]), branchLinearConss->lConsNames);
1569 }
1570 else
1571 {
1572 out.write((char *)&dummyZero, sizeof(int));
1573 }
1574
1575 if( branchSetppcConss )
1576 {
1577 out.write((char *)&(branchSetppcConss->nSetppcConss), sizeof(int));
1578 for(int i = 0; i < branchSetppcConss->nSetppcConss; i++ )
1579 {
1580 out.write((char *)&(branchSetppcConss->nSetppcVars[i]), sizeof(int));
1581 out.write((char *)&(branchSetppcConss->setppcTypes[i]), sizeof(int));
1582 assert( branchSetppcConss->nSetppcVars[i] > 0 );
1583 for(int j = 0; j < branchSetppcConss->nSetppcVars[i]; j++ )
1584 {
1585 out.write((char *)&(branchSetppcConss->idxSetppcVars[i][j]), sizeof(int));
1586 }
1587 }
1588 out.write((char *)&(branchSetppcConss->lConsNames), sizeof(int));
1589 out.write((char *)&(branchSetppcConss->consNames[0]), branchSetppcConss->lConsNames);
1590 }
1591 else
1592 {
1593 out.write((char *)&dummyZero, sizeof(int));
1594 }
1595
1596 if( linearConss )
1597 {
1598 out.write((char *)&(linearConss->nLinearConss), sizeof(int));
1599 for(int i = 0; i < linearConss->nLinearConss; i++ )
1600 {
1601 out.write((char *)&(linearConss->linearLhss[i]), sizeof(SCIP_Real));
1602 out.write((char *)&(linearConss->linearRhss[i]), sizeof(SCIP_Real));
1603 out.write((char *)&(linearConss->nLinearCoefs[i]), sizeof(int));
1604 assert( linearConss->nLinearCoefs[i]> 0 );
1605 for(int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
1606 {
1607 out.write((char *)&(linearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1608 out.write((char *)&(linearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1609 }
1610 }
1611 }
1612 else
1613 {
1614 out.write((char *)&dummyZero, sizeof(int));
1615 }
1616
1617 if( boundDisjunctions )
1618 {
1619 out.write((char *)&(boundDisjunctions->nBoundDisjunctions), sizeof(int));
1620 out.write((char *)&(boundDisjunctions->nTotalVarsBoundDisjunctions), sizeof(int));
1621 for(int i = 0; i < boundDisjunctions->nBoundDisjunctions; i++ )
1622 {
1623 out.write((char *)&(boundDisjunctions->nVarsBoundDisjunction[i]), sizeof(int));
1624 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionInitial[i]), sizeof(SCIP_Bool));
1625 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionSeparate[i]), sizeof(SCIP_Bool));
1626 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionEnforce[i]), sizeof(SCIP_Bool));
1627 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionCheck[i]), sizeof(SCIP_Bool));
1628 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionPropagate[i]), sizeof(SCIP_Bool));
1629 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionLocal[i]), sizeof(SCIP_Bool));
1630 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionModifiable[i]), sizeof(SCIP_Bool));
1631 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionDynamic[i]), sizeof(SCIP_Bool));
1632 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionRemovable[i]), sizeof(SCIP_Bool));
1633 out.write((char *)&(boundDisjunctions->flagBoundDisjunctionStickingatnode[i]), sizeof(SCIP_Bool));
1634 for( int j = 0; j < boundDisjunctions->nVarsBoundDisjunction[i]; j++ )
1635 {
1636 out.write((char *)&(boundDisjunctions->idxBoundDisjunctionVars[i][j]), sizeof(int));
1637 out.write((char *)&(boundDisjunctions->boundTypesBoundDisjunction[i][j]), sizeof(SCIP_BOUNDTYPE));
1638 out.write((char *)&(boundDisjunctions->boundsBoundDisjunction[i][j]), sizeof(SCIP_Real));
1639 }
1640 }
1641 }
1642 else
1643 {
1644 out.write((char *)&dummyZero, sizeof(int));
1645 }
1646
1647
1648 if( varBranchStats )
1649 {
1650 out.write((char *)&(varBranchStats->offset), sizeof(int));
1651 out.write((char *)&(varBranchStats->nVarBranchStats), sizeof(int));
1652 for(int i = 0; i < varBranchStats->nVarBranchStats; i++ )
1653 {
1654 out.write((char *)&(varBranchStats->idxBranchStatsVars[i]), sizeof(int));
1655 out.write((char *)&(varBranchStats->downpscost[i]), sizeof(SCIP_Real));
1656 out.write((char *)&(varBranchStats->uppscost[i]), sizeof(SCIP_Real));
1657 out.write((char *)&(varBranchStats->downvsids[i]), sizeof(SCIP_Real));
1658 out.write((char *)&(varBranchStats->upvsids[i]), sizeof(SCIP_Real));
1659 out.write((char *)&(varBranchStats->downconflen[i]), sizeof(SCIP_Real));
1660 out.write((char *)&(varBranchStats->upconflen[i]), sizeof(SCIP_Real));
1661 out.write((char *)&(varBranchStats->downinfer[i]), sizeof(SCIP_Real));
1662 out.write((char *)&(varBranchStats->upinfer[i]), sizeof(SCIP_Real));
1663 out.write((char *)&(varBranchStats->downcutoff[i]), sizeof(SCIP_Real));
1664 out.write((char *)&(varBranchStats->upcutoff[i]), sizeof(SCIP_Real));
1665 }
1666 }
1667 else
1668 {
1669 /* for backward consistency */
1670 out.write((char *)&dummyZero, sizeof(int));
1671 out.write((char *)&dummyZero, sizeof(int));
1672 }
1673
1674
1675 if( varValues )
1676 {
1677 out.write((char *)&(varValues->nVarValueVars), sizeof(int));
1678 out.write((char *)&(varValues->nVarValues), sizeof(int));
1679 for(int i = 0; i < varValues->nVarValueVars; i++)
1680 {
1681 out.write((char *)&(varValues->idxVarValueVars[i]), sizeof(int));
1682 out.write((char *)&(varValues->nVarValueValues[i]), sizeof(int));
1683 if( varValues->nVarValueValues[i] > 0 )
1684 {
1685 for(int j = 0; j < varValues->nVarValueValues[i]; j++ )
1686 {
1687 out.write((char *)&(varValues->varValue[i][j]), sizeof(SCIP_Real));
1688 out.write((char *)&(varValues->varValueDownvsids[i][j]), sizeof(SCIP_Real));
1689 out.write((char *)&(varValues->varVlaueUpvsids[i][j]), sizeof(SCIP_Real));
1690 out.write((char *)&(varValues->varValueDownconflen[i][j]), sizeof(SCIP_Real));
1691 out.write((char *)&(varValues->varValueUpconflen[i][j]), sizeof(SCIP_Real));
1692 out.write((char *)&(varValues->varValueDowninfer[i][j]), sizeof(SCIP_Real));
1693 out.write((char *)&(varValues->varValueUpinfer[i][j]), sizeof(SCIP_Real));
1694 out.write((char *)&(varValues->varValueDowncutoff[i][j]), sizeof(SCIP_Real));
1695 out.write((char *)&(varValues->varValueUpcutoff[i][j]), sizeof(SCIP_Real));
1696 }
1697 }
1698 }
1699 }
1700 else
1701 {
1702 out.write((char *)&dummyZero, sizeof(int));
1703 }
1704
1705#endif
1706
1707#ifdef UG_DEBUG_SOLUTION
1708 out.write((char *)&includeOptimalSol, sizeof(int));
1709#endif
1710
1711}
1712
1713void
1715 ParaComm *comm,
1716 gzstream::igzstream &in,
1717 bool onlyBoundChanges
1718 )
1719{
1720
1721 int dummyInt1 = 0;
1722 int dummyInt2 = 0;
1723
1724#ifdef UG_SCIP_V31_CHECK_POINT_FILES
1725
1726 in.read((char *)&localInfoIncluded, sizeof(int));
1727 in.read((char *)&nBoundChanges, sizeof(int));
1728 if( nBoundChanges > 0 )
1729 {
1731 branchBounds = new SCIP_Real[nBoundChanges];
1732 boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
1733 }
1734 for(int i = 0; i < nBoundChanges; i++ )
1735 {
1736 in.read((char *)&indicesAmongSolvers[i], sizeof(int));
1737 in.read((char *)&branchBounds[i], sizeof(SCIP_Real));
1738 in.read((char *)&boundTypes[i], sizeof(int));
1739 }
1740
1741 if( !onlyBoundChanges )
1742 {
1743 in.read((char *)&dummyInt1, sizeof(int));
1744 if( dummyInt1 > 0 )
1745 {
1747 linearConss->nLinearConss = dummyInt1;
1751 linearConss->linearCoefs = new SCIP_Real*[linearConss->nLinearConss];
1753 for(int i = 0; i < linearConss->nLinearConss; i++ )
1754 {
1755 in.read((char *)&(linearConss->linearLhss[i]), sizeof(SCIP_Real));
1756 in.read((char *)&(linearConss->linearRhss[i]), sizeof(SCIP_Real));
1757 in.read((char *)&(linearConss->nLinearCoefs[i]), sizeof(int));
1758 assert(linearConss->nLinearCoefs[i] > 0);
1759 linearConss->linearCoefs[i] = new SCIP_Real[linearConss->nLinearCoefs[i]];
1761 for(int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
1762 {
1763 in.read((char *)&(linearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1764 in.read((char *)&(linearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1765 }
1766 }
1767 }
1768
1769 in.read((char *)&dummyInt1, sizeof(int));
1770 in.read((char *)&dummyInt2, sizeof(int));
1771 if( dummyInt2 > 0)
1772 {
1774 varBranchStats->offset = dummyInt1;
1775 varBranchStats->nVarBranchStats = dummyInt2;
1787 for(int i = 0; i < varBranchStats->nVarBranchStats; i++ )
1788 {
1789 in.read((char *)&(varBranchStats->idxBranchStatsVars[i]), sizeof(int));
1790 in.read((char *)&(varBranchStats->downpscost[i]), sizeof(SCIP_Real));
1791 in.read((char *)&(varBranchStats->uppscost[i]), sizeof(SCIP_Real));
1792 in.read((char *)&(varBranchStats->downvsids[i]), sizeof(SCIP_Real));
1793 in.read((char *)&(varBranchStats->upvsids[i]), sizeof(SCIP_Real));
1794 in.read((char *)&(varBranchStats->downconflen[i]), sizeof(SCIP_Real));
1795 in.read((char *)&(varBranchStats->upconflen[i]), sizeof(SCIP_Real));
1796 in.read((char *)&(varBranchStats->downinfer[i]), sizeof(SCIP_Real));
1797 in.read((char *)&(varBranchStats->upinfer[i]), sizeof(SCIP_Real));
1798 in.read((char *)&(varBranchStats->downcutoff[i]), sizeof(SCIP_Real));
1799 in.read((char *)&(varBranchStats->upcutoff[i]), sizeof(SCIP_Real));
1800 }
1801 }
1802
1803 }
1804 else
1805 {
1806 assert( linearConss == 0);
1807 SCIP_Real dummyReal;
1808 int dummyInt;
1809 int nConss;
1810 in.read((char *)&nConss, sizeof(int));
1811 if( nConss > 0 )
1812 {
1813 for(int i = 0; i < nConss; i++ )
1814 {
1815 int nCoefs;
1816 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1817 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1818 in.read((char *)&nCoefs, sizeof(int));
1819 assert(nCoefs > 0);
1820 for(int j = 0; j < nCoefs; j++ )
1821 {
1822 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1823 in.read((char *)&dummyInt, sizeof(int));
1824 }
1825 }
1826 }
1827 assert( varBranchStats == 0 );
1828 int nStats;
1829 in.read((char *)&dummyInt, sizeof(int));
1830 in.read((char *)&nStats, sizeof(int));
1831
1832 for(int i = 0; i < nStats; i++ )
1833 {
1834 in.read((char *)&dummyInt, sizeof(int));
1835 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1836 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1837 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1838 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1839 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1840 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1841 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1842 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1843 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1844 in.read((char *)&dummyReal, sizeof(SCIP_Real));
1845 }
1846 }
1847
1848#else
1849
1850 in.read((char *)&localInfoIncluded, sizeof(int));
1851 in.read((char *)&nBoundChanges, sizeof(int));
1852 if( nBoundChanges > 0 )
1853 {
1855 branchBounds = new SCIP_Real[nBoundChanges];
1856 boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
1857 }
1858 for(int i = 0; i < nBoundChanges; i++ )
1859 {
1860 in.read((char *)&indicesAmongSolvers[i], sizeof(int));
1861 in.read((char *)&branchBounds[i], sizeof(SCIP_Real));
1862 in.read((char *)&boundTypes[i], sizeof(int));
1863 }
1864
1865 in.read((char *)&dummyInt1, sizeof(int));
1866 if( dummyInt1 > 0 )
1867 {
1869 branchLinearConss->nLinearConss = dummyInt1;
1870 assert( branchLinearConss->nLinearConss > 0 );
1876 for(int i = 0; i < branchLinearConss->nLinearConss; i++ )
1877 {
1878 in.read((char *)&(branchLinearConss->linearLhss[i]), sizeof(SCIP_Real));
1879 in.read((char *)&(branchLinearConss->linearRhss[i]), sizeof(SCIP_Real));
1880 in.read((char *)&(branchLinearConss->nLinearCoefs[i]), sizeof(int));
1881 assert(branchLinearConss->nLinearCoefs[i] > 0);
1884 for(int j = 0; j < branchLinearConss->nLinearCoefs[i]; j++ )
1885 {
1886 in.read((char *)&(branchLinearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1887 in.read((char *)&(branchLinearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1888 }
1889 }
1890 in.read((char *)&(branchLinearConss->lConsNames), sizeof(int));
1892 in.read((char *)&(branchLinearConss->consNames[0]), branchLinearConss->lConsNames);
1893 }
1894
1895 in.read((char *)&dummyInt1, sizeof(int));
1896 if( dummyInt1 > 0 )
1897 {
1899 branchSetppcConss->nSetppcConss = dummyInt1;
1900 assert( branchSetppcConss->nSetppcConss > 0 );
1904 for(int i = 0; i < branchSetppcConss->nSetppcConss; i++ )
1905 {
1906 in.read((char *)&(branchSetppcConss->nSetppcVars[i]), sizeof(int));
1907 in.read((char *)&(branchSetppcConss->setppcTypes[i]), sizeof(int));
1908 assert( branchSetppcConss->nSetppcVars[i] > 0 );
1910 for(int j = 0; j < branchSetppcConss->nSetppcVars[i]; j++ )
1911 {
1912 in.read((char *)&(branchSetppcConss->idxSetppcVars[i][j]), sizeof(int));
1913 }
1914 }
1915 in.read((char *)&(branchSetppcConss->lConsNames), sizeof(int));
1917 in.read((char *)&(branchSetppcConss->consNames[0]), branchSetppcConss->lConsNames);
1918 }
1919
1920 if( !onlyBoundChanges )
1921 {
1922 in.read((char *)&dummyInt1, sizeof(int));
1923 if( dummyInt1 > 0 )
1924 {
1926 linearConss->nLinearConss = dummyInt1;
1930 linearConss->linearCoefs = new SCIP_Real*[linearConss->nLinearConss];
1932 for(int i = 0; i < linearConss->nLinearConss; i++ )
1933 {
1934 in.read((char *)&(linearConss->linearLhss[i]), sizeof(SCIP_Real));
1935 in.read((char *)&(linearConss->linearRhss[i]), sizeof(SCIP_Real));
1936 in.read((char *)&(linearConss->nLinearCoefs[i]), sizeof(int));
1937 assert(linearConss->nLinearCoefs[i] > 0);
1938 linearConss->linearCoefs[i] = new SCIP_Real[linearConss->nLinearCoefs[i]];
1940 for(int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
1941 {
1942 in.read((char *)&(linearConss->linearCoefs[i][j]), sizeof(SCIP_Real));
1943 in.read((char *)&(linearConss->idxLinearCoefsVars[i][j]), sizeof(int));
1944 }
1945 }
1946 }
1947
1948 in.read((char *)&dummyInt1, sizeof(int));
1949 if( dummyInt1 > 0 )
1950 {
1953 in.read((char *)&(boundDisjunctions->nTotalVarsBoundDisjunctions), sizeof(int));
1968 for(int i = 0; i < boundDisjunctions->nBoundDisjunctions; i++ )
1969 {
1970 in.read((char *)&(boundDisjunctions->nVarsBoundDisjunction[i]), sizeof(int));
1971 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionInitial[i]), sizeof(SCIP_Bool));
1972 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionSeparate[i]), sizeof(SCIP_Bool));
1973 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionEnforce[i]), sizeof(SCIP_Bool));
1974 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionCheck[i]), sizeof(SCIP_Bool));
1975 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionPropagate[i]), sizeof(SCIP_Bool));
1976 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionLocal[i]), sizeof(SCIP_Bool));
1977 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionModifiable[i]), sizeof(SCIP_Bool));
1978 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionDynamic[i]), sizeof(SCIP_Bool));
1979 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionRemovable[i]), sizeof(SCIP_Bool));
1980 in.read((char *)&(boundDisjunctions->flagBoundDisjunctionStickingatnode[i]), sizeof(SCIP_Bool));
1982 {
1986 for( int j = 0; j < boundDisjunctions->nVarsBoundDisjunction[i]; j++ )
1987 {
1988 in.read((char *)&(boundDisjunctions->idxBoundDisjunctionVars[i][j]), sizeof(int));
1989 in.read((char *)&(boundDisjunctions->boundTypesBoundDisjunction[i][j]), sizeof(SCIP_BOUNDTYPE));
1990 in.read((char *)&(boundDisjunctions->boundsBoundDisjunction[i][j]), sizeof(SCIP_Real));
1991 }
1992 }
1993 }
1994 }
1995
1996
1997 in.read((char *)&dummyInt1, sizeof(int));
1998 in.read((char *)&dummyInt2, sizeof(int));
1999 if( dummyInt2 > 0)
2000 {
2002 varBranchStats->offset = dummyInt1;
2003 varBranchStats->nVarBranchStats = dummyInt2;
2015 for(int i = 0; i < varBranchStats->nVarBranchStats; i++ )
2016 {
2017 in.read((char *)&(varBranchStats->idxBranchStatsVars[i]), sizeof(int));
2018 in.read((char *)&(varBranchStats->downpscost[i]), sizeof(SCIP_Real));
2019 in.read((char *)&(varBranchStats->uppscost[i]), sizeof(SCIP_Real));
2020 in.read((char *)&(varBranchStats->downvsids[i]), sizeof(SCIP_Real));
2021 in.read((char *)&(varBranchStats->upvsids[i]), sizeof(SCIP_Real));
2022 in.read((char *)&(varBranchStats->downconflen[i]), sizeof(SCIP_Real));
2023 in.read((char *)&(varBranchStats->upconflen[i]), sizeof(SCIP_Real));
2024 in.read((char *)&(varBranchStats->downinfer[i]), sizeof(SCIP_Real));
2025 in.read((char *)&(varBranchStats->upinfer[i]), sizeof(SCIP_Real));
2026 in.read((char *)&(varBranchStats->downcutoff[i]), sizeof(SCIP_Real));
2027 in.read((char *)&(varBranchStats->upcutoff[i]), sizeof(SCIP_Real));
2028 }
2029 }
2030
2031 in.read((char *)&dummyInt1, sizeof(int));
2032 if( dummyInt1 > 0 )
2033 {
2035 varValues->nVarValueVars = dummyInt1;
2036 in.read((char *)&(varValues->nVarValues), sizeof(int));
2039 varValues->varValue = new SCIP_Real*[varValues->nVarValueVars];
2048 for(int i = 0; i < varValues->nVarValueVars; i++)
2049 {
2050 in.read((char *)&varValues->idxVarValueVars[i], sizeof(int));
2051 in.read((char *)&varValues->nVarValueValues[i], sizeof(int));
2052 if( varValues->nVarValueValues[i] > 0 )
2053 {
2054 varValues->varValue[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2055 varValues->varValueDownvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2056 varValues->varVlaueUpvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2057 varValues->varValueDownconflen[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2058 varValues->varValueUpconflen[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2059 varValues->varValueDowninfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2060 varValues->varValueUpinfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2061 varValues->varValueDowncutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2062 varValues->varValueUpcutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
2063 for(int j = 0; j < varValues->nVarValueValues[i]; j++ )
2064 {
2065 in.read((char *)&(varValues->varValue[i][j]), sizeof(SCIP_Real));
2066 in.read((char *)&(varValues->varValueDownvsids[i][j]), sizeof(SCIP_Real));
2067 in.read((char *)&(varValues->varVlaueUpvsids[i][j]), sizeof(SCIP_Real));
2068 in.read((char *)&(varValues->varValueDownconflen[i][j]), sizeof(SCIP_Real));
2069 in.read((char *)&(varValues->varValueUpconflen[i][j]), sizeof(SCIP_Real));
2070 in.read((char *)&(varValues->varValueDowninfer[i][j]), sizeof(SCIP_Real));
2071 in.read((char *)&(varValues->varValueUpinfer[i][j]), sizeof(SCIP_Real));
2072 in.read((char *)&(varValues->varValueDowncutoff[i][j]), sizeof(SCIP_Real));
2073 in.read((char *)&(varValues->varValueUpcutoff[i][j]), sizeof(SCIP_Real));
2074 }
2075 }
2076 }
2077 }
2078 }
2079 else
2080 {
2081 assert( linearConss == 0);
2082 SCIP_Real dummyReal;
2083 int dummyInt;
2084 int nConss;
2085 in.read((char *)&nConss, sizeof(int));
2086 if( nConss > 0 )
2087 {
2088 for(int i = 0; i < nConss; i++ )
2089 {
2090 int nCoefs;
2091 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2092 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2093 in.read((char *)&nCoefs, sizeof(int));
2094 assert(nCoefs > 0);
2095 for(int j = 0; j < nCoefs; j++ )
2096 {
2097 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2098 in.read((char *)&dummyInt, sizeof(int));
2099 }
2100 }
2101 }
2102 int nBTemp = 0;
2103 int bInt = 0;
2104 SCIP_Bool bBool = 0;
2105 SCIP_Real bReal = 0.0;
2106 SCIP_BOUNDTYPE bType = SCIP_BOUNDTYPE_LOWER;
2107 in.read((char *)&nBTemp, sizeof(int));
2108 if( nBTemp > 0 )
2109 {
2110 in.read((char *)&bInt, sizeof(int));
2111 for(int i = 0; i < nBTemp; i++ )
2112 {
2113 int nBtemp2 = 0;
2114 in.read((char *)&nBtemp2, sizeof(int));
2115 in.read((char *)&bBool, sizeof(SCIP_Bool));
2116 in.read((char *)&bBool, sizeof(SCIP_Bool));
2117 in.read((char *)&bBool, sizeof(SCIP_Bool));
2118 in.read((char *)&bBool, sizeof(SCIP_Bool));
2119 in.read((char *)&bBool, sizeof(SCIP_Bool));
2120 in.read((char *)&bBool, sizeof(SCIP_Bool));
2121 in.read((char *)&bBool, sizeof(SCIP_Bool));
2122 in.read((char *)&bBool, sizeof(SCIP_Bool));
2123 in.read((char *)&bBool, sizeof(SCIP_Bool));
2124 in.read((char *)&bBool, sizeof(SCIP_Bool));
2125 if( nBtemp2 > 0 )
2126 {
2127 for( int j = 0; j < nBtemp2; j++ )
2128 {
2129 in.read((char *)&bInt, sizeof(int));
2130 in.read((char *)&bType, sizeof(SCIP_BOUNDTYPE));
2131 in.read((char *)&bReal, sizeof(SCIP_Real));
2132 }
2133 }
2134 }
2135 }
2136
2137
2138 assert( varBranchStats == 0 );
2139 int nStats;
2140 in.read((char *)&dummyInt, sizeof(int));
2141 in.read((char *)&nStats, sizeof(int));
2142
2143 if( nStats > 0 )
2144 {
2145 for(int i = 0; i < nStats; i++ )
2146 {
2147 in.read((char *)&dummyInt, sizeof(int));
2148 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2149 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2150 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2151 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2152 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2153 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2154 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2155 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2156 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2157 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2158 }
2159 }
2160 int nTemp1 = 0;
2161 in.read((char *)&nTemp1, sizeof(int));
2162 if( nTemp1 > 0 )
2163 {
2164 in.read((char *)&dummyInt, sizeof(int));
2165 for(int i = 0; i < nTemp1; i++)
2166 {
2167 int nTemp2 = 0;
2168 in.read((char *)&dummyInt, sizeof(int));
2169 in.read((char *)&nTemp2, sizeof(int));
2170 if( nTemp2 > 0 )
2171 {
2172 for(int j = 0; j < nTemp2; j++ )
2173 {
2174 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2175 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2176 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2177 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2178 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2179 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2180 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2181 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2182 in.read((char *)&dummyReal, sizeof(SCIP_Real));
2183 }
2184 }
2185 }
2186 }
2187 }
2188#endif
2189
2190#ifdef UG_DEBUG_SOLUTION
2191 in.read((char *)&includeOptimalSol, sizeof(int));
2192#endif
2193}
2194#endif // End of UG_WITH_ZLIB
2195
2196/** get fixed variables **/
2197int
2199 ParaInstance *instance,
2200 BbParaFixedVariable **fixedVars
2201 )
2202{
2203 ScipParaInstance *scipInstance = dynamic_cast< ScipParaInstance* >(instance);
2204 *fixedVars = new BbParaFixedVariable[nBoundChanges]; // allocate space for the maximum possible numbers
2205 int n = 0;
2206 int k = 0;
2207 for( int i = 0; i < nBoundChanges; i++ )
2208 {
2209 int probindex = indicesAmongSolvers[i];
2210 if( scipInstance->isOriginalIndeciesMap() )
2211 {
2212 probindex = scipInstance->getOrigProbIndex(indicesAmongSolvers[i]);
2213 }
2214 /* skip inactive varibales */
2215 if( probindex < 0 ) continue;
2216
2217 switch( static_cast<SCIP_VARTYPE>(scipInstance->getVarType( probindex ) ) )
2218 {
2219 case SCIP_VARTYPE_BINARY:
2220 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
2221 {
2222 assert( EPSEQ(branchBounds[i], scipInstance->getVarUb(probindex), DEFAULT_NUM_EPSILON ) );
2223 }
2224 else
2225 {
2226 assert( EPSEQ(branchBounds[i], scipInstance->getVarLb(probindex), DEFAULT_NUM_EPSILON ) );
2227 }
2228 for( k = 0 ; k < n; k++ )
2229 {
2230 if( indicesAmongSolvers[i] == (*fixedVars)[k].index ) // when I checked, this case happened!
2231 break;
2232 }
2233 if( k != n ) break;
2234 (*fixedVars)[n].nSameValue = 0;
2235 (*fixedVars)[n].index = indicesAmongSolvers[i];
2236 (*fixedVars)[n].value = branchBounds[i];
2237 (*fixedVars)[n].mnode = 0;
2238 (*fixedVars)[n].next = 0;
2239 (*fixedVars)[n].prev = 0;
2240 n++;
2241 break;
2242 case SCIP_VARTYPE_INTEGER:
2243 case SCIP_VARTYPE_IMPLINT:
2244 case SCIP_VARTYPE_CONTINUOUS:
2245 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER )
2246 {
2247 if( !EPSEQ(branchBounds[i], scipInstance->getVarUb(probindex), DEFAULT_NUM_EPSILON ) )
2248 {
2249 int j = i + 1;
2250 for( ; j < nBoundChanges; j++ )
2251 {
2253 boundTypes[j] == SCIP_BOUNDTYPE_UPPER &&
2255 )
2256 {
2257 break;
2258 }
2259 }
2260 if( j >= nBoundChanges ) break;
2261 }
2262 }
2263 else
2264 {
2265 if( !EPSEQ(branchBounds[i], scipInstance->getVarLb(probindex), DEFAULT_NUM_EPSILON ) )
2266 {
2267 int j = i + 1;
2268 for( ; j < nBoundChanges; j++ )
2269 {
2271 boundTypes[j] == SCIP_BOUNDTYPE_LOWER &&
2273 )
2274 {
2275 break;
2276 }
2277 }
2278 if( j >= nBoundChanges ) break;
2279 }
2280 }
2281 for(k = 0; k < n; k++ )
2282 {
2283 if( indicesAmongSolvers[i] == (*fixedVars)[k].index ) // when I checked, this case happened!
2284 break;
2285 }
2286 if( k != n ) break;
2287 (*fixedVars)[n].nSameValue = 0;
2288 (*fixedVars)[n].index = indicesAmongSolvers[i];
2289 (*fixedVars)[n].value = branchBounds[i];
2290 (*fixedVars)[n].mnode = 0;
2291 (*fixedVars)[n].next = 0;
2292 (*fixedVars)[n].prev = 0;
2293 n++;
2294
2295 break;
2296 default:
2297 THROW_LOGICAL_ERROR2("Invalid Variable Type = ", static_cast<int>(scipInstance->getVarType(probindex) ) );
2298 }
2299 }
2300 if( n == 0 )
2301 {
2302 delete [] *fixedVars;
2303 *fixedVars = 0;
2304 }
2305 return n;
2306}
2307
2308/** create new ParaDiffSubproblem using fixed variables information */
2311 ParaComm *comm,
2312 ParaInitiator *initiator,
2313 int n,
2314 BbParaFixedVariable *fixedVars
2315 )
2316{
2317 ScipParaDiffSubproblem *diffSubproblem = dynamic_cast<ScipParaDiffSubproblem*>( comm->createParaDiffSubproblem() );
2318 int nNewBranches = 0;
2319 diffSubproblem->indicesAmongSolvers = new int[nBoundChanges];
2320 diffSubproblem->branchBounds = new SCIP_Real[nBoundChanges];
2321 diffSubproblem->boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
2322
2323 if( initiator && dynamic_cast<ScipParaInitiator*>(initiator)->areTightenedVarBounds() )
2324 {
2325
2326 ScipParaInitiator *scipParaInitiator = dynamic_cast<ScipParaInitiator*>(initiator);
2327
2328 for( int i = 0; i < nBoundChanges; i++ )
2329 {
2330 bool updated = false;
2331 for( int j = 0; j < n; j++ )
2332 {
2333 if( indicesAmongSolvers[i] == fixedVars[j].index )
2334 {
2335 diffSubproblem->indicesAmongSolvers[nNewBranches] = indicesAmongSolvers[i];
2336 diffSubproblem->branchBounds[nNewBranches] = branchBounds[i];
2337 diffSubproblem->boundTypes[nNewBranches] = boundTypes[i];
2338 nNewBranches++;
2339 updated = true;
2340 break;
2341 }
2342 }
2343 // tightened local bound changes including global bound changes must be received already
2344 if( !updated )
2345 {
2346 if( boundTypes[i] == SCIP_BOUNDTYPE_LOWER &&
2348 )
2349 {
2350 diffSubproblem->indicesAmongSolvers[nNewBranches] = indicesAmongSolvers[i];
2351 diffSubproblem->branchBounds[nNewBranches] = scipParaInitiator->getTightenedVarLbs(indicesAmongSolvers[i]);
2352 diffSubproblem->boundTypes[nNewBranches] = boundTypes[i];
2353 nNewBranches++;
2354 }
2355 if( boundTypes[i] == SCIP_BOUNDTYPE_UPPER &&
2357 )
2358 {
2359 diffSubproblem->indicesAmongSolvers[nNewBranches] = indicesAmongSolvers[i];
2360 diffSubproblem->branchBounds[nNewBranches] = scipParaInitiator->getTightenedVarUbs(indicesAmongSolvers[i]);
2361 diffSubproblem->boundTypes[nNewBranches] = boundTypes[i];
2362 nNewBranches++;
2363 }
2364 }
2365 }
2366 }
2367 else
2368 {
2369 for( int i = 0; i < nBoundChanges; i++ )
2370 {
2371 for( int j = 0; j < n; j++ )
2372 {
2373 if( indicesAmongSolvers[i] == fixedVars[j].index )
2374 {
2375 diffSubproblem->indicesAmongSolvers[nNewBranches] = indicesAmongSolvers[i];
2376 diffSubproblem->branchBounds[nNewBranches] = branchBounds[i];
2377 diffSubproblem->boundTypes[nNewBranches] = boundTypes[i];
2378 nNewBranches++;
2379 break;
2380 }
2381 }
2382 }
2383 }
2384 diffSubproblem->nBoundChanges = nNewBranches;
2385#ifdef UG_DEBUG_SOLUTION
2386 diffSubproblem->includeOptimalSol = includeOptimalSol;
2387#endif
2388 return diffSubproblem;
2389}
2390
2391/** stringfy ParaCalculationState */
2392const std::string
2394 )
2395{
2396 std::ostringstream s;
2397
2398 s << "localInfoIncluded = " << localInfoIncluded << std::endl;
2399 s << "nBranches = " << nBoundChanges << std::endl;
2400 for(int i = 0; i < nBoundChanges; i++ )
2401 {
2402 s << "indicesAmongSolvers[" << i << "] = " << indicesAmongSolvers[i] << std::endl;
2403 s << "branchBounds[" << i << "] = " << branchBounds[i] << std::endl;
2404 s << "boudTypes[" << i << "] = " << static_cast<int>(boundTypes[i]) << std::endl;
2405 }
2406
2407 if( linearConss )
2408 {
2409 s << "nLinearConss = " << linearConss->nLinearConss << std::endl;
2410 for(int i = 0; i < linearConss->nLinearConss; i++ )
2411 {
2412 s << "linearLhss[" << i << "] = " << linearConss->linearLhss[i] << std::endl;
2413 s << "linearRhss[" << i << "] = " << linearConss->linearRhss[i] << std::endl;
2414 s << "nLinearCoefs[" << i << "] = " << linearConss->nLinearCoefs[i] << std::endl;
2415 for( int j = 0; j < linearConss->nLinearCoefs[i]; j++ )
2416 {
2417 s << "linearCoefs[" << i << "][" << j << "] = " << linearConss->linearCoefs[i][j] << std::endl;
2418 s << "idxLinearCoefsVars[" << i << "][" << j << "] = " << linearConss->idxLinearCoefsVars[i][j] << std::endl;
2419 }
2420 }
2421 }
2422
2423 if( boundDisjunctions )
2424 {
2425 s << "nBoundDisjunctions = " << boundDisjunctions->nBoundDisjunctions << std::endl;
2426 s << "nTotalVarsBoundDisjunctions = " << boundDisjunctions->nTotalVarsBoundDisjunctions << std::endl;
2427 for(int i = 0; i < boundDisjunctions->nBoundDisjunctions; i++ )
2428 {
2429 s << "nVarsBoundDisjunction[" << i << "] = " << boundDisjunctions->nVarsBoundDisjunction[i] << std::endl;
2430 s << "flagBoundDisjunctionInitial[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionInitial[i] << std::endl;
2431 s << "flagBoundDisjunctionSeparate[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionSeparate[i] << std::endl;
2432 s << "flagBoundDisjunctionEnforce[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionEnforce[i] << std::endl;
2433 s << "flagBoundDisjunctionCheck[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionCheck[i] << std::endl;
2434 s << "flagBoundDisjunctionPropagate[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionPropagate[i] << std::endl;
2435 s << "flagBoundDisjunctionLocal[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionLocal[i] << std::endl;
2436 s << "flagBoundDisjunctionModifiable[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionModifiable[i] << std::endl;
2437 s << "flagBoundDisjunctionDynamic[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionDynamic[i] << std::endl;
2438 s << "flagBoundDisjunctionRemovable[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionRemovable[i] << std::endl;
2439 s << "flagBoundDisjunctionStickingatnode[" << i << "] = " << boundDisjunctions->flagBoundDisjunctionStickingatnode[i] << std::endl;
2440 for(int j = 0; j < boundDisjunctions->nVarsBoundDisjunction[i]; j++ )
2441 {
2442 s << "idxBoundDisjunctionVars[" << i << "][" << j << "] = " << boundDisjunctions->idxBoundDisjunctionVars[i][j] << std::endl;
2443 s << "boundTypesBoundDisjunction[" << i << "][" << j << "] = " << static_cast<int>(boundDisjunctions->boundTypesBoundDisjunction[i][j]) << std::endl;
2444 s << "boundsBoundDisjunction[" << i << "][" << j << "] = " << boundDisjunctions->boundsBoundDisjunction[i][j] << std::endl;
2445 }
2446 }
2447 }
2448
2449 if( varBranchStats )
2450 {
2451 s << "offset = " << varBranchStats->offset << std::endl;
2452 s << "nVarBranchStats = " << varBranchStats->nVarBranchStats << std::endl;
2453 for(int i = 0; i < varBranchStats->nVarBranchStats; i++ )
2454 {
2455 s << "idxLBranchStatsVars[" << i << "] = " << varBranchStats->idxBranchStatsVars[i] << std::endl;
2456 s << "downpscost[" << i << "] = " << varBranchStats->downpscost[i] << std::endl;
2457 s << "uppscost[" << i << "] = " << varBranchStats->uppscost[i] << std::endl;
2458 s << "downvsids[" << i << "] = " << varBranchStats->downvsids[i] << std::endl;
2459 s << "upvsids[" << i << "] = " << varBranchStats->upvsids[i] << std::endl;
2460 s << "downconflen[" << i << "] = " << varBranchStats->downconflen[i] << std::endl;
2461 s << "upconflen[" << i << "] = " << varBranchStats->upconflen[i] << std::endl;
2462 s << "downinfer[" << i << "] = " << varBranchStats->downinfer[i] << std::endl;
2463 s << "upinfer[" << i << "] = " << varBranchStats->upinfer[i] << std::endl;
2464 s << "downcutoff[" << i << "] = " << varBranchStats->downcutoff[i] << std::endl;
2465 s << "upcutoff[" << i << "] = " << varBranchStats->upcutoff[i] << std::endl;
2466 }
2467 }
2468
2469 if( varValues )
2470 {
2471 s << "nVarValueVars = " << varValues->nVarValueVars << std::endl;
2472 for(int i = 0; i < varValues->nVarValueVars; i++ )
2473 {
2474 s << "idxVarValueVars[" << i << "] = " << varValues->idxVarValueVars[i] << std::endl;
2475 s << "nVarValueValues[" << i << "] = " << varValues->nVarValueValues[i] << std::endl;
2476 if( varValues->nVarValueValues[i] > 0 )
2477 {
2478 for( int j = 0; j < varValues->nVarValueValues[i]; j++ )
2479 {
2480 s << "varValue[" << i << "][" << j << "] = " << varValues->varValue[i][j] << std::endl;
2481 s << "varValueDownvsids[" << i << "][" << j << "] = " << varValues->varValueDownvsids[i][j] << std::endl;
2482 s << "varVlaueUpvsids[" << i << "][" << j << "] = " << varValues->varVlaueUpvsids[i][j] << std::endl;
2483 s << "varValueDownconflen[" << i << "][" << j << "] = " << varValues->varValueDownconflen[i][j] << std::endl;
2484 s << "varValueUpconflen[" << i << "][" << j << "] = " << varValues->varValueUpconflen[i][j] << std::endl;
2485 s << "varValueDowninfer[" << i << "][" << j << "] = " << varValues->varValueDowninfer[i][j] << std::endl;
2486 s << "varValueUpinfer[" << i << "][" << j << "] = " << varValues->varValueUpinfer[i][j] << std::endl;
2487 s << "varValueDowncutoff[" << i << "][" << j << "] = " << varValues->varValueDowncutoff[i][j] << std::endl;
2488 s << "varValueUpcutoff[" << i << "][" << j << "] = " << varValues->varValueUpcutoff[i][j] << std::endl;
2489 }
2490 }
2491 }
2492
2493 }
2494 return s.str();
2495}
2496
2497
UG::ParaDiffSubproblem * createParaDiffSubproblem()
void addBranchLinearConss(SCIP *scip, ScipParaSolver *scipParaSolver, int nLenarConss, int nAddedConss, SCIP_CONS **addedConss)
BbParaDiffSubproblem * createDiffSubproblem(UG::ParaComm *comm, UG::ParaInitiator *initiator, int n, UG::BbParaFixedVariable *fixedVars)
void read(UG::ParaComm *comm, gzstream::igzstream &in, bool onlyBoundChanges)
ScipParaDiffSubproblemBranchLinearCons * branchLinearConss
ScipParaDiffSubproblemBoundDisjunctions * boundDisjunctions
void addBranchVarStats(SCIP *scip, ScipParaSolver *scipParaSolver)
void addLocalNodeInfo(SCIP *scip, ScipParaSolver *scipParaSolver)
ScipParaDiffSubproblemVarBranchStats * varBranchStats
int getFixedVariables(UG::ParaInstance *instance, UG::BbParaFixedVariable **fixedVars)
void addBranchSetppcConss(SCIP *scip, ScipParaSolver *scipParaSolver, int nSetpartConss, int nAddedConss, SCIP_CONS **addedConss)
ScipParaDiffSubproblemVarValues * varValues
void addInitialBranchVarStats(int minDepth, int maxDepth, SCIP *scip)
ScipParaDiffSubproblemBranchSetppcCons * branchSetppcConss
void write(gzstream::ogzstream &out)
void addBoundDisjunctions(SCIP *scip, ScipParaSolver *scipParaSolver)
ScipParaDiffSubproblemLinearCons * linearConss
ScipParaDiffSubproblemLinearCons * bendersLinearConss
void addVarValueStats(SCIP *scip, ScipParaSolver *scipParaSolver)
int getOriginalIndex(int index)
std::list< LocalNodeInfoPtr > * getConflictConsList()
ScipParaDiffSubproblem * getParentDiffSubproblem()
Class for the difference between instance and subproblem.
double getTightenedVarLbs(int i)
get tightened variable lower bound TODO: this function should be in inherited class
bool areTightenedVarBounds()
check if there are tightened lower or upper bound TODO: this function should be in inherited class
double getTightenedVarUbs(int i)
get tightened variable upper bound TODO: this function should be in inherited class
void updateNTransferredLocalCuts(int n)
update number of transferred local cuts
ParaTask * getCurrentNode()
get current ParaNode object
Definition: bbParaSolver.h:981
void updateNTransferredBendersCuts(int n)
update number of transferred benders cuts
ParaParamSet * getParaParamSet()
get ParaParamSet object
bool isRacingStage()
check if Solver is in racing stage or not
Base class of communicator object.
Definition: paraComm.h:102
Class for initiator.
Definition: paraInitiator.h:63
class for instance data
Definition: paraInstance.h:51
bool getBoolParamValue(int param)
get bool parameter value
bool isRootTask()
check if root task or not
Definition: paraTask.h:624
static ScipParaCommTh * comm
Definition: fscip.cpp:73
struct ParaSCIP::BranchConsSetppcInfo_t BranchConsSetppcInfo
struct ParaSCIP::LocalNodeInfo_t LocalNodeInfo
struct ParaSCIP::BranchConsLinearInfo_t BranchConsLinearInfo
static const int TransferBendersCuts
static const int TransferBranchStats
static const int TransferVarValueStats
static const int TransferConflicts
static const int TransferConflictCuts
static const int TransferLocalCuts
static const int RacingStatBranching
static const int NoSolverPresolvingAtRoot
Base class of communicator for UG Framework.
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
#define THROW_LOGICAL_ERROR2(msg1, msg2)
Definition: paraDef.h:69
#define DEFAULT_NUM_EPSILON
Definition: paraDef.h:49
#define EPSLT(x, y, eps)
Definition: paraDef.h:167
#define MINEPSILON
Definition: paraDef.h:50
#define EPSEQ(x, y, eps)
Definition: paraDef.h:166
#define EPSGT(x, y, eps)
Definition: paraDef.h:169
ParaInitialStat extension for SCIP solver.
ParaInitiator extension for SCIP solver.
ParaInstance extenstion for SCIP solver.
ParaSolver extension for SCIP: Parallelized solver implementation for SCIP.
Fixed variable struct.