Scippy

UG

Ubiquity Generator framework

scipParaDiffSubproblem.h
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.h
27 * @brief ParaInitialStat 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
37#ifndef __SCIP_PARA_DIFF_SUBPROBLEM_H__
38#define __SCIP_PARA_DIFF_SUBPROBLEM_H__
39
40#include <cstring>
41#include <iostream>
42#include <fstream>
43#include "ug/paraComm.h"
44#ifdef UG_WITH_ZLIB
45#include "ug/gzstream.h"
46#endif
49#include "scip/scip.h"
50#include "scip/history.h"
51#include "scip/cons_bounddisjunction.h"
52
53namespace ParaSCIP
54{
55
56class ScipParaSolver;
57
59{
60 /********************************
61 * for branching constraint *
62 * *****************************/
63 char * consName; /**< name of this constraint */
64 SCIP_Real linearLhs; /**< array of lhs */
65 SCIP_Real linearRhs; /**< array of rhs */
66 int nLinearCoefs; /**< array of number of coefficient values for linear constrains */
67 SCIP_Real *linearCoefs; /**< array of non-zero coefficient values of linear constrains */
68 int *idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
71
73{
74 /********************************
75 * for branching constraint *
76 * *****************************/
77 char * consName; /**< name of this constraint */
78 int nSetppcVars; /**< array of numbers of indices of variables for setppc constrains */
79 int setppcType; /**< setppc Type */
80 int *idxSetppcVars; /**< array of indices of variables for setppc constrains */
83
85{
86public:
87 int nLinearConss; /**< number of linear constrains */
88 SCIP_Real *linearLhss; /**< array of lhs */
89 SCIP_Real *linearRhss; /**< array of rhs */
90 int *nLinearCoefs; /**< array of number of coefficient values for linear constrains */
91 SCIP_Real **linearCoefs; /**< array of non-zero coefficient values of linear constrains */
92 int **idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
93 int lConsNames; /**< length of cons names space: each name is separated by \0 */
94 char *consNames; /**< constraint names */
95
96 /** default constructor */
98 ) :nLinearConss(0),
99 linearLhss(0),
100 linearRhss(0),
101 nLinearCoefs(0),
102 linearCoefs(0),
104 lConsNames(0),
105 consNames(0)
106 {
107 }
108 /** destractor */
110 )
111 {
112 if( linearLhss ) delete[] linearLhss;
113 if( linearRhss ) delete[] linearRhss;
114 for( int c = 0; c < nLinearConss; c++ )
115 {
116 if( nLinearCoefs[c] > 0 )
117 {
118 if( linearCoefs[c] ) delete[] linearCoefs[c];
119 if( idxLinearCoefsVars[c] ) delete[] idxLinearCoefsVars[c];
120 }
121 }
122 if( nLinearCoefs ) delete[] nLinearCoefs;
123 if( linearCoefs ) delete[] linearCoefs;
125 if( consNames ) delete[] consNames;
126 }
127};
128
130{
131public:
132 int nSetppcConss; /**< number of setppc constrains */
133 int *nSetppcVars; /**< array of numbers of indices of variables for setppc constrains */
134 int *setppcTypes; /**< setppc Types */
135 int **idxSetppcVars; /**< array of indices of variables for setppc constrains */
136 int lConsNames; /**< length of cons names space: each name is separated by \0 */
137 char *consNames; /**< constraint names */
138 /** default constructor */
140 ) :nSetppcConss(0),
141 nSetppcVars(0),
142 setppcTypes(0),
143 idxSetppcVars(0),
144 lConsNames(0),
145 consNames(0)
146 {
147 }
148 /** destractor */
150 )
151 {
152 if( nSetppcVars ) delete[] nSetppcVars;
153 if( setppcTypes ) delete[] setppcTypes;
154 for( int c = 0; c < nSetppcConss; c++ )
155 {
156 if( idxSetppcVars[c] ) delete[] idxSetppcVars[c];
157 }
158 if (idxSetppcVars ) delete [] idxSetppcVars;
159 if( consNames ) delete[] consNames;
160 }
161};
162
164{
165public:
166 int nLinearConss; /**< number of linear constrains */
167 SCIP_Real *linearLhss; /**< array of lhs */
168 SCIP_Real *linearRhss; /**< array of rhs */
169 int *nLinearCoefs; /**< array of number of coefficient values for linear constrains */
170 SCIP_Real **linearCoefs; /**< array of non-zero coefficient values of linear constrains */
171 int **idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
172
173 /** default constructor */
175 ) :nLinearConss(0),
176 linearLhss(0),
177 linearRhss(0),
178 nLinearCoefs(0),
179 linearCoefs(0),
181 {
182 }
183 /** destractor */
185 )
186 {
187 if( linearLhss ) delete[] linearLhss;
188 if( linearRhss ) delete[] linearRhss;
189 for( int c = 0; c < nLinearConss; c++ )
190 {
191 if( nLinearCoefs[c] > 0 )
192 {
193 if( linearCoefs[c] ) delete[] linearCoefs[c];
194 if( idxLinearCoefsVars[c] ) delete[] idxLinearCoefsVars[c];
195 }
196 }
197 if( nLinearCoefs ) delete[] nLinearCoefs;
198 if( linearCoefs ) delete[] linearCoefs;
200 }
201};
202
204{
205public:
206 int nBoundDisjunctions; /**< number of bound disjunction constraints */
207 int nTotalVarsBoundDisjunctions; /**< total number of vars in bound disjunction constraints */
208 int *nVarsBoundDisjunction;/**< number of variables in bound disjunction constraint */
209 SCIP_Bool *flagBoundDisjunctionInitial; /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
210 SCIP_Bool *flagBoundDisjunctionSeparate; /**< should the constraint be separated during LP processing? Usually set to TRUE. */
211 SCIP_Bool *flagBoundDisjunctionEnforce; /**< should the constraint be enforced during node processing? TRUE for model constraints, FALSE for additional, redundant constraints. */
212 SCIP_Bool *flagBoundDisjunctionCheck; /**< should the constraint be checked for feasibility? TRUE for model constraints, FALSE for additional, redundant constraints. */
213 SCIP_Bool *flagBoundDisjunctionPropagate; /**< should the constraint be propagated during node processing? Usually set to TRUE. */
214 SCIP_Bool *flagBoundDisjunctionLocal; /**< is constraint only valid locally? Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
215 SCIP_Bool *flagBoundDisjunctionModifiable;/**< is constraint modifiable (subject to column generation)? Usually set to FALSE. In column generation applications, set to TRUE if pricing adds coefficients to this constraint. */
216 SCIP_Bool *flagBoundDisjunctionDynamic; /**< is constraint subject to aging? Usually set to FALSE. Set to TRUE for own cuts which are separated as constraints.*/
217 SCIP_Bool *flagBoundDisjunctionRemovable; /**< should the relaxation be removed from the LP due to aging or cleanup? Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'.*/
218 SCIP_Bool *flagBoundDisjunctionStickingatnode; /**< should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
219 int **idxBoundDisjunctionVars; /**< index of bound disjunction vars */
220 SCIP_BOUNDTYPE **boundTypesBoundDisjunction; /**< array of bound types in bound disjunction constraint */
221 SCIP_Real **boundsBoundDisjunction; /**< array of bounds in bound disjunction constraint */
222
223 /** default constructor */
225 ) : nBoundDisjunctions(0),
241 {
242 }
243 /** destractor */
245 )
246 {
247 for( int i = 0; i < nBoundDisjunctions; i++ )
248 {
249 if( nVarsBoundDisjunction[i] > 0 )
250 {
254 }
255 }
270 }
271};
272
274{
275public:
276 int offset; /**< root node depth of the collected nodes */
277 int nVarBranchStats; /**< number of branch stats */
278 int *idxBranchStatsVars; /**< indices of branch stats vars */
279 SCIP_Real *downpscost; /**< values to which pseudocosts for downwards branching */
280 SCIP_Real *uppscost; /**< values to which pseudocosts for upwards branching */
281 SCIP_Real *downvsids; /**< values to which VSIDS score for downwards branching */
282 SCIP_Real *upvsids; /**< values to which VSIDS score for upwards branching */
283 SCIP_Real *downconflen; /**< values to which conflict length score for downwards branching */
284 SCIP_Real *upconflen; /**< values to which conflict length score for upwards branching */
285 SCIP_Real *downinfer; /**< values to which inference counter for downwards branching */
286 SCIP_Real *upinfer; /**< values to which inference counter for upwards branching */
287 SCIP_Real *downcutoff; /**< values to which cutoff counter for downwards branching */
288 SCIP_Real *upcutoff; /**< values to which cutoff counter for upwards branching */
289
290 /** default constructor */
292 ) : offset(0),
295 downpscost(0),
296 uppscost(0),
297 downvsids(0),
298 upvsids(0),
299 downconflen(0),
300 upconflen(0),
301 downinfer(0),
302 upinfer(0),
303 downcutoff(0),
304 upcutoff(0)
305 {
306 }
307 /** destractor */
309 )
310 {
312 if( downpscost ) delete[] downpscost;
313 if( uppscost ) delete[] uppscost;
314 if( downvsids ) delete[] downvsids;
315 if( upvsids ) delete[] upvsids;
316 if( downconflen ) delete[] downconflen;
317 if( upconflen ) delete[] upconflen;
318 if( downinfer ) delete[] downinfer;
319 if( upinfer ) delete[] upinfer;
320 if( downcutoff ) delete[] downcutoff;
321 if( upcutoff ) delete[] upcutoff;
322 }
323};
324
326{
327public:
328 int nVarValueVars; /**< number of variable value variables */
329 int nVarValues; /**< number of variable values, for getting statistics */
330 int *idxVarValueVars; /**< indicies of variable value vars */
331 int *nVarValueValues; /**< number of values for a variable */
332 SCIP_Real **varValue; /**< domain value, or SCIP_UNKNOWN */
333 SCIP_Real **varValueDownvsids; /**< value to which VSIDS score for downwards branching should be initialized */
334 SCIP_Real **varVlaueUpvsids; /**< value to which VSIDS score for upwards branching should be initialized */
335 SCIP_Real **varValueDownconflen; /**< value to which conflict length score for downwards branching should be initialized */
336 SCIP_Real **varValueUpconflen; /**< value to which conflict length score for upwards branching should be initialized */
337 SCIP_Real **varValueDowninfer; /**< value to which inference counter for downwards branching should be initialized */
338 SCIP_Real **varValueUpinfer; /**< value to which inference counter for upwards branching should be initialized */
339 SCIP_Real **varValueDowncutoff; /**< value to which cutoff counter for downwards branching should be initialized */
340 SCIP_Real **varValueUpcutoff; /**< value to which cutoff counter for upwards branching should be initialized */
341 /** default constructor */
343 ) : nVarValueVars(0),
344 nVarValues(0),
347 varValue(0),
356 {
357 }
358 /** destractor */
360 )
361 {
362 for( int i = 0; i < nVarValueVars; i++ )
363 {
364 if( nVarValueValues[i] > 0 )
365 {
366 if( varValue[i] ) delete[] varValue[i];
367 if( varValueDownvsids[i] ) delete[] varValueDownvsids[i];
368 if( varVlaueUpvsids[i] ) delete[] varVlaueUpvsids[i];
369 if( varValueDownconflen[i] ) delete[] varValueDownconflen[i];
370 if( varValueUpconflen[i] ) delete[] varValueUpconflen[i];
371 if( varValueDowninfer[i] ) delete[] varValueDowninfer[i];
372 if( varValueUpinfer[i] ) delete[] varValueUpinfer[i];
373 if( varValueDowncutoff[i] ) delete[] varValueDowncutoff[i];
374 if( varValueUpcutoff[i] ) delete[] varValueUpcutoff[i];
375 }
376 }
377 if( varValue ) delete [] varValue;
379 if( varVlaueUpvsids ) delete[] varVlaueUpvsids;
383 if( varValueUpinfer ) delete[] varValueUpinfer;
385 if( varValueUpcutoff ) delete[] varValueUpcutoff;
386 if( idxVarValueVars ) delete[] idxVarValueVars;
387 if( nVarValueValues ) delete[] nVarValueValues;
388 }
389};
390
391/** The difference between instance and subproblem: this is base class */
393{
394protected:
395 int localInfoIncluded; /**< 0 (0000 0000): not included
396 1 (0000 0001): if local cuts are included
397 2 (0000 0010): if conflicts are included
398 3 (0000 0011): if local cuts and conflicts are included */
399 /******************************
400 * for variable bound changes *
401 * ***************************/
402 int nBoundChanges; /**< number of branching variables */
403 int *indicesAmongSolvers; /**< array of variable indices ( unique index ) */
404 SCIP_Real *branchBounds; /**< array of bounds which the branchings */
405 SCIP_BOUNDTYPE *boundTypes; /**< array of boundtypes which the branchings */
406 /*******************************************
407 * for the case of branching by constraint *
408 * ****************************************/
409 ScipParaDiffSubproblemBranchLinearCons *branchLinearConss; /**< point to branch constraints */
410 ScipParaDiffSubproblemBranchSetppcCons *branchSetppcConss; /**< point to branch constraints */
411 /************************************
412 * for local cuts and conflict cuts *
413 * *********************************/
414 ScipParaDiffSubproblemLinearCons *linearConss; /**< point to linear constraint data */
415 /************************************
416 * for benders cuts *
417 * *********************************/
418 ScipParaDiffSubproblemLinearCons *bendersLinearConss; /**< point to benders linear constraint data */
419 /********************************
420 * for conflicts *
421 * *****************************/
422 ScipParaDiffSubproblemBoundDisjunctions *boundDisjunctions; /**< point to bound disjunctions */
423 /********************************
424 * for local var brnach stats *
425 * *****************************/
426 ScipParaDiffSubproblemVarBranchStats *varBranchStats; /**< point to varialbe branch stats */
427 /**************************************
428 * for local var value brnach stats *
429 * ***********************************/
430 ScipParaDiffSubproblemVarValues *varValues; /**< point to variable values */
431#ifdef UG_DEBUG_SOLUTION
432 int includeOptimalSol; /**< indicate if sub-MIP includes optimal solution or not. 1: include, 0: not */
433#endif
434public:
435 /** default constructor */
437 )
442 linearConss(0),
446 varValues(0)
447 {
448#ifdef UG_DEBUG_SOLUTION
449 includeOptimalSol = 0;
450#endif
451 }
452
454 SCIP *scip,
455 ScipParaSolver *scipParaSolver,
456 int nNewBranchVars,
457 SCIP_VAR **newBranchVars,
458 SCIP_Real *newBranchBounds,
459 SCIP_BOUNDTYPE *newBoundTypes,
460 int nAddedConss,
461 SCIP_CONS **addedConss
462 );
463
465 ScipParaDiffSubproblem *diffSubproblem
466 ) : localInfoIncluded(0),
470 linearConss(0),
474 varValues(0)
475
476 {
477 if( !diffSubproblem ) return;
478
479 localInfoIncluded = diffSubproblem->localInfoIncluded;
480 nBoundChanges = diffSubproblem->nBoundChanges;
481 if( nBoundChanges )
482 {
484 branchBounds = new SCIP_Real[nBoundChanges];
485 boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
486 for( int i = 0; i < nBoundChanges; i++ )
487 {
488 indicesAmongSolvers[i] = diffSubproblem->indicesAmongSolvers[i];
489 branchBounds[i] = diffSubproblem->branchBounds[i];
490 boundTypes[i] = diffSubproblem->boundTypes[i];
491 }
492 }
493
494 if( diffSubproblem->branchLinearConss )
495 {
498 assert( branchLinearConss->nLinearConss > 0 );
504 for( int c = 0; c < branchLinearConss->nLinearConss; c++ )
505 {
511 for( int v = 0; v < branchLinearConss->nLinearCoefs[c]; v++ )
512 {
513 branchLinearConss->linearCoefs[c][v] = diffSubproblem->branchLinearConss->linearCoefs[c][v];
515 }
516 }
519 for( int c = 0; c < branchLinearConss->lConsNames; c++ )
520 {
521 branchLinearConss->consNames[c] = diffSubproblem->branchLinearConss->consNames[c];
522 }
524 }
525
526 if( diffSubproblem->branchSetppcConss )
527 {
530 assert( branchSetppcConss->nSetppcConss > 0 );
534 for( int c = 0; c < branchSetppcConss->nSetppcConss; c++ )
535 {
539 for( int v = 0; v < branchSetppcConss->nSetppcVars[c]; v++ )
540 {
541 branchSetppcConss->idxSetppcVars[c][v] = diffSubproblem->branchSetppcConss->idxSetppcVars[c][v];
542 }
543 }
546 for( int c = 0; c < branchSetppcConss->lConsNames; c++ )
547 {
548 branchSetppcConss->consNames[c] = diffSubproblem->branchSetppcConss->consNames[c];
549 }
551 }
552
553 if( diffSubproblem->linearConss )
554 {
557 assert( linearConss->nLinearConss > 0 );
558 // std::cout << "linearConss->nLinearConss = " << linearConss->nLinearConss << std::endl;
564 for( int c = 0; c < linearConss->nLinearConss; c++ )
565 {
566 linearConss->linearLhss[c] = diffSubproblem->linearConss->linearLhss[c];
567 linearConss->linearRhss[c] = diffSubproblem->linearConss->linearRhss[c];
568 linearConss->nLinearCoefs[c] = diffSubproblem->linearConss->nLinearCoefs[c];
569 linearConss->linearCoefs[c] = new SCIP_Real[linearConss->nLinearCoefs[c]];
571 for( int v = 0; v < linearConss->nLinearCoefs[c]; v++ )
572 {
573 linearConss->linearCoefs[c][v] = diffSubproblem->linearConss->linearCoefs[c][v];
574 linearConss->idxLinearCoefsVars[c][v] = diffSubproblem->linearConss->idxLinearCoefsVars[c][v];
575 }
576 }
577 }
578
579 if( diffSubproblem->bendersLinearConss )
580 {
583 assert( bendersLinearConss->nLinearConss > 0 );
584 // std::cout << "bendersLinearConss->nLinearConss = " << bendersLinearConss->nLinearConss << std::endl;
590 for( int c = 0; c < bendersLinearConss->nLinearConss; c++ )
591 {
597 for( int v = 0; v < bendersLinearConss->nLinearCoefs[c]; v++ )
598 {
599 bendersLinearConss->linearCoefs[c][v] = diffSubproblem->bendersLinearConss->linearCoefs[c][v];
601 }
602 }
603 }
604
605 if( diffSubproblem->boundDisjunctions )
606 {
624 for( int i = 0; i < boundDisjunctions->nBoundDisjunctions; i++ )
625 {
639 {
643 for( int j = 0; j < boundDisjunctions->nVarsBoundDisjunction[i]; j++ )
644 {
648 }
649 }
650 }
651 }
652
653
654 if( diffSubproblem->varBranchStats )
655 {
657 varBranchStats->offset = diffSubproblem->varBranchStats->offset;
670 for( int i = 0; i < varBranchStats->nVarBranchStats; ++i )
671 {
673 varBranchStats->downpscost[i] = diffSubproblem->varBranchStats->downpscost[i];
674 varBranchStats->uppscost[i] = diffSubproblem->varBranchStats->uppscost[i];
675 varBranchStats->downvsids[i] = diffSubproblem->varBranchStats->downvsids[i];
676 varBranchStats->upvsids[i] = diffSubproblem->varBranchStats->upvsids[i];
677 varBranchStats->downconflen[i] = diffSubproblem->varBranchStats->downconflen[i];
678 varBranchStats->upconflen[i] = diffSubproblem->varBranchStats->upconflen[i];
679 varBranchStats->downinfer[i] = diffSubproblem->varBranchStats->downinfer[i];
680 varBranchStats->upinfer[i] = diffSubproblem->varBranchStats->upinfer[i];
681 varBranchStats->downcutoff[i] = diffSubproblem->varBranchStats->downcutoff[i];
682 varBranchStats->upcutoff[i] = diffSubproblem->varBranchStats->upcutoff[i];
683 }
684 }
685
686 if( diffSubproblem->varValues )
687 {
690 varValues->nVarValues = diffSubproblem->varValues->nVarValues;
693 varValues->varValue = new SCIP_Real*[varValues->nVarValueVars];
702 for( int i = 0; i < varValues->nVarValueVars; i++ )
703 {
704 varValues->idxVarValueVars[i] = diffSubproblem->varValues->idxVarValueVars[i];
705 varValues->nVarValueValues[i] = diffSubproblem->varValues->nVarValueValues[i];
706 if( varValues->nVarValueValues[i] > 0 )
707 {
708 varValues->varValue[i] = new SCIP_Real[varValues->nVarValueValues[i]];
709 varValues->varValueDownvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
710 varValues->varVlaueUpvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
712 varValues->varValueUpconflen[i] = new SCIP_Real[varValues->nVarValueValues[i]];
713 varValues->varValueDowninfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
714 varValues->varValueUpinfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
715 varValues->varValueDowncutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
716 varValues->varValueUpcutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
717 for( int j = 0; j < varValues->nVarValueValues[i]; j++ )
718 {
719 varValues->varValue[i][j] = diffSubproblem->varValues->varValue[i][j];
720 varValues->varValueDownvsids[i][j] = diffSubproblem->varValues->varValueDownvsids[i][j];
721 varValues->varVlaueUpvsids[i][j] = diffSubproblem->varValues->varVlaueUpvsids[i][j];
722 varValues->varValueDownconflen[i][j] = diffSubproblem->varValues->varValueDownconflen[i][j];
723 varValues->varValueUpconflen[i][j] = diffSubproblem->varValues->varValueUpconflen[i][j];
724 varValues->varValueDowninfer[i][j] = diffSubproblem->varValues->varValueDowninfer[i][j];
725 varValues->varValueUpinfer[i][j] = diffSubproblem->varValues->varValueUpinfer[i][j];
726 varValues->varValueDowncutoff[i][j] = diffSubproblem->varValues->varValueDowncutoff[i][j];
727 varValues->varValueUpcutoff[i][j] = diffSubproblem->varValues->varValueUpcutoff[i][j];
728 }
729 }
730 }
731 }
732#ifdef UG_DEBUG_SOLUTION
733 includeOptimalSol = diffSubproblem->includeOptimalSol;
734#endif
735 }
736
737 /** destractor */
739 {
741 if( branchBounds ) delete[] branchBounds;
742 if( boundTypes ) delete[] boundTypes;
744 {
745 delete branchLinearConss;
746 }
748 {
749 delete branchSetppcConss;
750 }
751 if( linearConss )
752 {
753 delete linearConss;
754 }
756 {
757 delete bendersLinearConss;
758 }
760 {
761 delete boundDisjunctions;
762 }
763
764 if( varBranchStats )
765 {
766 delete varBranchStats;
767 }
768 if( varValues )
769 {
770 delete varValues;
771 }
772 }
773
775 int getIndex(int i){ return indicesAmongSolvers[i]; }
776 SCIP_Real getBranchBound(int i){ return branchBounds[i]; }
777 SCIP_BOUNDTYPE getBoundType(int i){ return boundTypes[i]; }
778
780 {
781 return branchLinearConss;
782 }
783
785 {
786 return branchSetppcConss;
787 }
788
790 {
792 {
794 }
795 else
796 {
797 return 0;
798 }
799 }
800
801 SCIP_Real getBranchConsLinearLhs(int i)
802 {
803 assert(branchLinearConss);
804 return branchLinearConss->linearLhss[i];
805 }
806
807 SCIP_Real getBranchConsLinearRhs(int i)
808 {
809 assert(branchLinearConss);
810 return branchLinearConss->linearRhss[i];
811 }
812
814 {
815 assert(branchLinearConss);
817 }
818
819 SCIP_Real getBranchConsLinearCoefs(int i, int j)
820 {
821 assert(branchLinearConss);
822 return branchLinearConss->linearCoefs[i][j];
823 }
824
826 {
827 assert(branchLinearConss);
829 }
830
832 {
833 assert(branchLinearConss);
835 }
836
838 {
839 char *name = branchLinearConss->consNames;
840 for( int j = 0; j < i; j++)
841 {
842 assert(*name);
843 name += (std::strlen(name) + 1);
844 }
845 assert(*name);
846 return name;
847 }
848
849
851 {
853 {
855 }
856 else
857 {
858 return 0;
859 }
860 }
861
863 {
864 assert(branchSetppcConss);
866 }
867
869 {
870 assert(branchSetppcConss);
872 }
873
874 int getBranchConsSetppcVars(int i, int j)
875 {
876 assert(branchSetppcConss);
877 return branchSetppcConss->idxSetppcVars[i][j];
878 }
879
881 {
882 assert(branchSetppcConss);
884 }
885
887 {
888 char *name = branchSetppcConss->consNames;
889 for( int j = 0; j < i; j++)
890 {
891 assert(*name);
892 name += (std::strlen(name) + 1);
893 }
894 assert(*name);
895 return name;
896 }
897
898
900 {
901 if( linearConss )
902 {
904 }
905 else
906 {
907 return 0;
908 }
909 }
910
911
912 SCIP_Real getLinearLhs(int i)
913 {
914 assert(linearConss);
915 return linearConss->linearLhss[i];
916 }
917
918 SCIP_Real getLinearRhs(int i)
919 {
920 assert(linearConss);
921 return linearConss->linearRhss[i];
922 }
923
925 {
926 assert(linearConss);
927 return linearConss->nLinearCoefs[i];
928 }
929
930 SCIP_Real getLinearCoefs(int i, int j)
931 {
932 assert(linearConss);
933 return linearConss->linearCoefs[i][j];
934 }
935
936 int getIdxLinearCoefsVars(int i, int j)
937 {
938 assert(linearConss);
939 return linearConss->idxLinearCoefsVars[i][j];
940 }
941
943 {
945 {
947 }
948 else
949 {
950 return 0;
951 }
952 }
953
954 SCIP_Real getBendersLinearLhs(int i)
955 {
956 assert(bendersLinearConss);
958 }
959
960 SCIP_Real getBendersLinearRhs(int i)
961 {
962 assert(bendersLinearConss);
964 }
965
967 {
968 assert(bendersLinearConss);
970 }
971
972 SCIP_Real getBendersLinearCoefs(int i, int j)
973 {
974 assert(bendersLinearConss);
975 return bendersLinearConss->linearCoefs[i][j];
976 }
977
979 {
980 assert(bendersLinearConss);
982 }
983
985 {
987 {
989 }
990 else
991 {
992 return 0;
993 }
994 }
995
997 {
998 assert(boundDisjunctions);
1000 }
1001
1003 assert(boundDisjunctions);
1004 assert( boundDisjunctions->nVarsBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1006 }
1008 {
1009 assert(boundDisjunctions);
1010 assert( boundDisjunctions->flagBoundDisjunctionInitial && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1012 }
1014 {
1015 assert(boundDisjunctions);
1016 assert( boundDisjunctions->flagBoundDisjunctionSeparate && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1018 }
1020 {
1021 assert(boundDisjunctions);
1022 assert( boundDisjunctions->flagBoundDisjunctionEnforce && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1024 }
1026 {
1027 assert(boundDisjunctions);
1028 assert( boundDisjunctions->flagBoundDisjunctionCheck && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1030 }
1032 {
1033 assert(boundDisjunctions);
1034 assert( boundDisjunctions->flagBoundDisjunctionPropagate && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1036 }
1038 {
1039 assert( boundDisjunctions->flagBoundDisjunctionLocal && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1041 }
1043 {
1044 assert(boundDisjunctions);
1045 assert( boundDisjunctions->flagBoundDisjunctionModifiable && i >= 0 && i <boundDisjunctions->nBoundDisjunctions );
1047 }
1049 {
1050 assert(boundDisjunctions);
1051 assert( boundDisjunctions->flagBoundDisjunctionDynamic && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1053 }
1055 {
1056 assert(boundDisjunctions);
1057 assert( boundDisjunctions->flagBoundDisjunctionRemovable && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1059 }
1061 {
1062 assert(boundDisjunctions);
1063 assert( boundDisjunctions->flagBoundDisjunctionStickingatnode && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1065 }
1066
1068 {
1069 assert(boundDisjunctions);
1070 assert( boundDisjunctions->idxBoundDisjunctionVars && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1071 assert( boundDisjunctions->idxBoundDisjunctionVars[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1073 }
1074 SCIP_BOUNDTYPE getBoundTypesBoundDisjunction(int i, int j)
1075 {
1076 assert(boundDisjunctions);
1077 assert( boundDisjunctions->boundTypesBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1078 assert( boundDisjunctions->boundTypesBoundDisjunction[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1080 }
1081 SCIP_Real getBoundsBoundDisjunction(int i, int j)
1082 {
1083 assert(boundDisjunctions);
1084 assert( boundDisjunctions->boundsBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1085 assert( boundDisjunctions->boundsBoundDisjunction[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1087 }
1088
1090 {
1091
1092 if( varBranchStats )
1093 {
1095 }
1096 else
1097 {
1098 return 0;
1099 }
1100 }
1101
1103 {
1104 assert(varBranchStats);
1105 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1107 }
1108
1109 SCIP_Real getDownpscost(int i)
1110 {
1111 assert(varBranchStats);
1112 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1113 return varBranchStats->downpscost[i];
1114 }
1115
1116 SCIP_Real getUppscost(int i)
1117 {
1118 assert(varBranchStats);
1119 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1120 return varBranchStats->uppscost[i];
1121 }
1122
1123 SCIP_Real getDownvsids(int i)
1124 {
1125 assert(varBranchStats);
1126 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1127 return varBranchStats->downvsids[i];
1128 }
1129
1130 SCIP_Real getUpvsids(int i)
1131 {
1132 assert(varBranchStats);
1133 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1134 return varBranchStats->upvsids[i];
1135 }
1136
1137 SCIP_Real getDownconflen(int i)
1138 {
1139 assert(varBranchStats);
1140 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1141 return varBranchStats->downconflen[i];
1142 }
1143
1144 SCIP_Real getUpconflen(int i)
1145 {
1146 assert(varBranchStats);
1147 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1148 return varBranchStats->upconflen[i];
1149 }
1150
1151 SCIP_Real getDowninfer(int i)
1152 {
1153 assert(varBranchStats);
1154 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1155 return varBranchStats->downinfer[i];
1156 }
1157
1158 SCIP_Real getUpinfer(int i)
1159 {
1160 assert(varBranchStats);
1161 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1162 return varBranchStats->upinfer[i];
1163 }
1164
1165 SCIP_Real getDowncutoff(int i)
1166 {
1167 assert(varBranchStats);
1168 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1169 return varBranchStats->downcutoff[i];
1170 }
1171
1172 SCIP_Real getUpcutoff(int i)
1173 {
1174 assert(varBranchStats);
1175 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1176 return varBranchStats->upcutoff[i];
1177 }
1178
1179
1181 {
1182 if( varValues )
1183 {
1184 return varValues->nVarValueVars;
1185 }
1186 else
1187 {
1188 return 0;
1189 }
1190 }
1191
1193 {
1194 assert(varValues);
1195 return varValues->nVarValues;
1196 }
1197
1199 {
1200 assert(varValues);
1201 assert(varValues->idxVarValueVars && i >= 0 && i < varValues->nVarValueVars );
1202 return varValues->idxVarValueVars[i];
1203 }
1204
1206 {
1207 assert(varValues);
1208 assert(varValues->idxVarValueVars && i >= 0 && i < varValues->nVarValueVars );
1209 return varValues->nVarValueValues[i];
1210 }
1211
1212 SCIP_Real getVarValue(int i, int j)
1213 {
1214 assert(varValues);
1215 assert(varValues->varValue && i >= 0 && i < varValues->nVarValueVars );
1216 assert(varValues->varValue[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1217 return varValues->varValue[i][j];
1218 }
1219
1220 SCIP_Real getVarValueDownvsids(int i, int j)
1221 {
1222 assert(varValues);
1223 assert(varValues->varValueDownvsids && i >= 0 && i < varValues->nVarValueVars );
1224 assert(varValues->varValueDownvsids[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1225 return varValues->varValueDownvsids[i][j];
1226 }
1227
1228 SCIP_Real getVarVlaueUpvsids(int i, int j)
1229 {
1230 assert(varValues);
1231 assert(varValues->varVlaueUpvsids && i >= 0 && i < varValues->nVarValueVars );
1232 assert(varValues->varVlaueUpvsids[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1233 return varValues->varVlaueUpvsids[i][j];
1234 }
1235
1236 SCIP_Real getVarValueDownconflen(int i, int j)
1237 {
1238 assert(varValues);
1239 assert(varValues->varValueDownconflen && i >= 0 && i < varValues->nVarValueVars );
1240 assert(varValues->varValueDownconflen[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1241 return varValues->varValueDownconflen[i][j];
1242 }
1243
1244 SCIP_Real getVarValueUpconflen(int i, int j)
1245 {
1246 assert(varValues);
1247 assert(varValues->varValueUpconflen && i >= 0 && i < varValues->nVarValueVars );
1248 assert(varValues->varValueUpconflen[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1249 return varValues->varValueUpconflen[i][j];
1250 }
1251
1252 SCIP_Real getVarValueDowninfer(int i, int j)
1253 {
1254 assert(varValues);
1255 assert(varValues->varValueDowninfer && i >= 0 && i < varValues->nVarValueVars );
1256 assert(varValues->varValueDowninfer[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1257 return varValues->varValueDowninfer[i][j];
1258 }
1259
1260 SCIP_Real getVarValueUpinfer(int i, int j)
1261 {
1262 assert(varValues);
1263 assert(varValues->varValueUpinfer && i >= 0 && i < varValues->nVarValueVars );
1264 assert(varValues->varValueUpinfer[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1265 return varValues->varValueUpinfer[i][j];
1266 }
1267
1268 SCIP_Real getVarValueDowncutoff(int i, int j)
1269 {
1270 assert(varValues);
1271 assert(varValues->varValueDowncutoff && i >= 0 && i < varValues->nVarValueVars );
1272 assert(varValues->varValueDowncutoff[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1273 return varValues->varValueDowncutoff[i][j];
1274 }
1275
1276 SCIP_Real getVarValueUpcutoff(int i, int j)
1277 {
1278 assert(varValues);
1279 assert(varValues->varValueUpcutoff && i >= 0 && i < varValues->nVarValueVars );
1280 assert(varValues->varValueUpcutoff[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1281 return varValues->varValueUpcutoff[i][j];
1282 }
1283
1285 SCIP *scip,
1286 ScipParaSolver *scipParaSolver,
1287 int nLenarConss,
1288 int nAddedConss,
1289 SCIP_CONS **addedConss
1290 );
1291
1293 SCIP *scip,
1294 ScipParaSolver *scipParaSolver,
1295 int nSetpartConss,
1296 int nAddedConss,
1297 SCIP_CONS **addedConss
1298 );
1299
1300 void addLocalNodeInfo(
1301 SCIP *scip,
1302 ScipParaSolver *scipParaSolver
1303 );
1304
1306 SCIP *scip,
1307 ScipParaSolver *scipParaSolver
1308 );
1309
1310 void addBranchVarStats(
1311 SCIP *scip,
1312 ScipParaSolver *scipParaSolver
1313 );
1314
1315 void addVarValueStats(
1316 SCIP *scip,
1317 ScipParaSolver *scipParaSolver
1318 );
1319
1321 int minDepth,
1322 int maxDepth,
1323 SCIP *scip
1324 );
1325
1327 {
1328 assert(varBranchStats);
1329 return varBranchStats->offset;
1330 }
1331
1332#ifdef UG_WITH_ZLIB
1333 void write(gzstream::ogzstream &out);
1334 void read(UG::ParaComm *comm, gzstream::igzstream &in, bool onlyBoundChanges);
1335#endif
1336
1337 /** get fixed variables **/
1339 UG::ParaInstance *instance,
1340 UG::BbParaFixedVariable **fixedVars );
1341
1342 /** create new ParaDiffSubproblem using fixed variables information */
1345 UG::ParaInitiator *initiator,
1346 int n,
1347 UG::BbParaFixedVariable *fixedVars );
1348
1349 /** stringfy ParaCalculationState */
1350 const std::string toString(
1351 );
1352
1353 /** stringfy statistics to log file */
1354 const std::string toStringStat(){
1355 std::ostringstream s;
1357 {
1358 s << ", blc: " << branchLinearConss->nLinearConss;
1359 s << "," << branchLinearConss->lConsNames;
1360 }
1361 else
1362 {
1363 s << ", blc: 0";
1364 }
1366 {
1367 s << ", bsc: " << branchSetppcConss->nSetppcConss;
1368 s << "," << branchSetppcConss->lConsNames;
1369 }
1370 else
1371 {
1372 s << ", bsc: 0";
1373 }
1374 if( linearConss )
1375 {
1376 s << ", nl: " << linearConss->nLinearConss;
1377 }
1378 else
1379 {
1380 s << ", nl: 0";
1381 }
1382 if( bendersLinearConss )
1383 {
1384 s << ", bnl: " << bendersLinearConss->nLinearConss;
1385 }
1386 else
1387 {
1388 s << ", nl: 0";
1389 }
1390
1391
1392 if ( boundDisjunctions )
1393 {
1395 }
1396 else
1397 {
1398 s << ", nbd: 0, nbdt: 0";
1399 }
1400
1401 if( varBranchStats )
1402 {
1403 s << ", nbs: " << varBranchStats->nVarBranchStats;
1404 }
1405 else
1406 {
1407 s << ", nbs: 0";
1408 }
1409
1410 if( varValues )
1411 {
1412 s << ", nvv: " << varValues->nVarValueVars << ", nvvt: " << varValues->nVarValues;
1413 }
1414 else
1415 {
1416 s << ", nvv: 0, nvvt: 0";
1417 }
1418 return s.str();
1419 }
1420
1421#ifdef UG_DEBUG_SOLUTION
1422 bool isOptimalSolIncluded(){ return (includeOptimalSol != 0); }
1423 void setOptimalSolIndicator(int i){ includeOptimalSol = i; }
1424#endif
1425
1426};
1427
1428}
1429
1430#endif // __SCIP_PARA_DIFF_SUBPROBLEM_H__
1431
Base class for a container which has difference between instance and subproblem.
Base class for instance data.
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)
SCIP_Real getBoundsBoundDisjunction(int i, int j)
void read(UG::ParaComm *comm, gzstream::igzstream &in, bool onlyBoundChanges)
ScipParaDiffSubproblemBranchLinearCons * getBranchLinearConss()
ScipParaDiffSubproblemBranchLinearCons * branchLinearConss
SCIP_Real getVarValueUpinfer(int i, int j)
ScipParaDiffSubproblemBoundDisjunctions * boundDisjunctions
SCIP_Real getBendersLinearCoefs(int i, int j)
SCIP_Real getVarValueDownconflen(int i, int j)
ScipParaDiffSubproblem(ScipParaDiffSubproblem *diffSubproblem)
void addBranchVarStats(SCIP *scip, ScipParaSolver *scipParaSolver)
void addLocalNodeInfo(SCIP *scip, ScipParaSolver *scipParaSolver)
ScipParaDiffSubproblemVarBranchStats * varBranchStats
int getFixedVariables(UG::ParaInstance *instance, UG::BbParaFixedVariable **fixedVars)
SCIP_Real getVarValueDownvsids(int i, int j)
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)
SCIP_BOUNDTYPE getBoundTypesBoundDisjunction(int i, int j)
SCIP_Real getVarValueUpcutoff(int i, int j)
SCIP_Real getBranchConsLinearCoefs(int i, int j)
ScipParaDiffSubproblemLinearCons * linearConss
SCIP_Real getVarValueDowninfer(int i, int j)
SCIP_Real getVarValueUpconflen(int i, int j)
ScipParaDiffSubproblemLinearCons * bendersLinearConss
ScipParaDiffSubproblemBranchSetppcCons * getBranchSetppcConss()
void addVarValueStats(SCIP *scip, ScipParaSolver *scipParaSolver)
SCIP_Real getVarValueDowncutoff(int i, int j)
SCIP_Real getVarVlaueUpvsids(int i, int j)
Class for the difference between instance and subproblem.
BbParaDiffSubproblem()
DO NOT HAVE DATA MEMBER!!
Base class of communicator object.
Definition: paraComm.h:102
Class for initiator.
Definition: paraInitiator.h:63
class for instance data
Definition: paraInstance.h:51
static ScipParaCommTh * comm
Definition: fscip.cpp:73
Utilities for handling gzipped input and output streams.
struct ParaSCIP::BranchConsSetppcInfo_t BranchConsSetppcInfo
BranchConsSetppcInfo * BranchConsSetppcInfoPtr
BranchConsLinearInfo * BranchConsLinearInfoPtr
struct ParaSCIP::BranchConsLinearInfo_t BranchConsLinearInfo
Base class of communicator for UG Framework.
Fixed variable struct.