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-2025 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/cons_bounddisjunction.h"
51
52namespace ParaSCIP
53{
54
55class ScipParaSolver;
56
58{
59 /********************************
60 * for branching constraint *
61 * *****************************/
62 char * consName; /**< name of this constraint */
63 SCIP_Real linearLhs; /**< array of lhs */
64 SCIP_Real linearRhs; /**< array of rhs */
65 int nLinearCoefs; /**< array of number of coefficient values for linear constrains */
66 SCIP_Real *linearCoefs; /**< array of non-zero coefficient values of linear constrains */
67 int *idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
70
72{
73 /********************************
74 * for branching constraint *
75 * *****************************/
76 char * consName; /**< name of this constraint */
77 int nSetppcVars; /**< array of numbers of indices of variables for setppc constrains */
78 int setppcType; /**< setppc Type */
79 int *idxSetppcVars; /**< array of indices of variables for setppc constrains */
82
84{
85public:
86 int nLinearConss; /**< number of linear constrains */
87 SCIP_Real *linearLhss; /**< array of lhs */
88 SCIP_Real *linearRhss; /**< array of rhs */
89 int *nLinearCoefs; /**< array of number of coefficient values for linear constrains */
90 SCIP_Real **linearCoefs; /**< array of non-zero coefficient values of linear constrains */
91 int **idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
92 int lConsNames; /**< length of cons names space: each name is separated by \0 */
93 char *consNames; /**< constraint names */
94
95 /** default constructor */
97 ) :nLinearConss(0),
98 linearLhss(0),
99 linearRhss(0),
100 nLinearCoefs(0),
101 linearCoefs(0),
103 lConsNames(0),
104 consNames(0)
105 {
106 }
107 /** destractor */
109 )
110 {
111 if( linearLhss ) delete[] linearLhss;
112 if( linearRhss ) delete[] linearRhss;
113 for( int c = 0; c < nLinearConss; c++ )
114 {
115 if( nLinearCoefs[c] > 0 )
116 {
117 if( linearCoefs[c] ) delete[] linearCoefs[c];
118 if( idxLinearCoefsVars[c] ) delete[] idxLinearCoefsVars[c];
119 }
120 }
121 if( nLinearCoefs ) delete[] nLinearCoefs;
122 if( linearCoefs ) delete[] linearCoefs;
124 if( consNames ) delete[] consNames;
125 }
126};
127
129{
130public:
131 int nSetppcConss; /**< number of setppc constrains */
132 int *nSetppcVars; /**< array of numbers of indices of variables for setppc constrains */
133 int *setppcTypes; /**< setppc Types */
134 int **idxSetppcVars; /**< array of indices of variables for setppc constrains */
135 int lConsNames; /**< length of cons names space: each name is separated by \0 */
136 char *consNames; /**< constraint names */
137 /** default constructor */
139 ) :nSetppcConss(0),
140 nSetppcVars(0),
141 setppcTypes(0),
142 idxSetppcVars(0),
143 lConsNames(0),
144 consNames(0)
145 {
146 }
147 /** destractor */
149 )
150 {
151 if( nSetppcVars ) delete[] nSetppcVars;
152 if( setppcTypes ) delete[] setppcTypes;
153 for( int c = 0; c < nSetppcConss; c++ )
154 {
155 if( idxSetppcVars[c] ) delete[] idxSetppcVars[c];
156 }
157 if (idxSetppcVars ) delete [] idxSetppcVars;
158 if( consNames ) delete[] consNames;
159 }
160};
161
163{
164public:
165 int nLinearConss; /**< number of linear constrains */
166 SCIP_Real *linearLhss; /**< array of lhs */
167 SCIP_Real *linearRhss; /**< array of rhs */
168 int *nLinearCoefs; /**< array of number of coefficient values for linear constrains */
169 SCIP_Real **linearCoefs; /**< array of non-zero coefficient values of linear constrains */
170 int **idxLinearCoefsVars; /**< array of indices of no-zero coefficient values of linear constrains */
171
172 /** default constructor */
174 ) :nLinearConss(0),
175 linearLhss(0),
176 linearRhss(0),
177 nLinearCoefs(0),
178 linearCoefs(0),
180 {
181 }
182 /** destractor */
184 )
185 {
186 if( linearLhss ) delete[] linearLhss;
187 if( linearRhss ) delete[] linearRhss;
188 for( int c = 0; c < nLinearConss; c++ )
189 {
190 if( nLinearCoefs[c] > 0 )
191 {
192 if( linearCoefs[c] ) delete[] linearCoefs[c];
193 if( idxLinearCoefsVars[c] ) delete[] idxLinearCoefsVars[c];
194 }
195 }
196 if( nLinearCoefs ) delete[] nLinearCoefs;
197 if( linearCoefs ) delete[] linearCoefs;
199 }
200};
201
203{
204public:
205 int nBoundDisjunctions; /**< number of bound disjunction constraints */
206 int nTotalVarsBoundDisjunctions; /**< total number of vars in bound disjunction constraints */
207 int *nVarsBoundDisjunction;/**< number of variables in bound disjunction constraint */
208 SCIP_Bool *flagBoundDisjunctionInitial; /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
209 SCIP_Bool *flagBoundDisjunctionSeparate; /**< should the constraint be separated during LP processing? Usually set to TRUE. */
210 SCIP_Bool *flagBoundDisjunctionEnforce; /**< should the constraint be enforced during node processing? TRUE for model constraints, FALSE for additional, redundant constraints. */
211 SCIP_Bool *flagBoundDisjunctionCheck; /**< should the constraint be checked for feasibility? TRUE for model constraints, FALSE for additional, redundant constraints. */
212 SCIP_Bool *flagBoundDisjunctionPropagate; /**< should the constraint be propagated during node processing? Usually set to TRUE. */
213 SCIP_Bool *flagBoundDisjunctionLocal; /**< is constraint only valid locally? Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
214 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. */
215 SCIP_Bool *flagBoundDisjunctionDynamic; /**< is constraint subject to aging? Usually set to FALSE. Set to TRUE for own cuts which are separated as constraints.*/
216 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'.*/
217 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. */
218 int **idxBoundDisjunctionVars; /**< index of bound disjunction vars */
219 SCIP_BOUNDTYPE **boundTypesBoundDisjunction; /**< array of bound types in bound disjunction constraint */
220 SCIP_Real **boundsBoundDisjunction; /**< array of bounds in bound disjunction constraint */
221
222 /** default constructor */
224 ) : nBoundDisjunctions(0),
240 {
241 }
242 /** destractor */
244 )
245 {
246 for( int i = 0; i < nBoundDisjunctions; i++ )
247 {
248 if( nVarsBoundDisjunction[i] > 0 )
249 {
253 }
254 }
269 }
270};
271
273{
274public:
275 int offset; /**< root node depth of the collected nodes */
276 int nVarBranchStats; /**< number of branch stats */
277 int *idxBranchStatsVars; /**< indices of branch stats vars */
278 SCIP_Real *downpscost; /**< values to which pseudocosts for downwards branching */
279 SCIP_Real *uppscost; /**< values to which pseudocosts for upwards branching */
280 SCIP_Real *downvsids; /**< values to which VSIDS score for downwards branching */
281 SCIP_Real *upvsids; /**< values to which VSIDS score for upwards branching */
282 SCIP_Real *downconflen; /**< values to which conflict length score for downwards branching */
283 SCIP_Real *upconflen; /**< values to which conflict length score for upwards branching */
284 SCIP_Real *downinfer; /**< values to which inference counter for downwards branching */
285 SCIP_Real *upinfer; /**< values to which inference counter for upwards branching */
286 SCIP_Real *downcutoff; /**< values to which cutoff counter for downwards branching */
287 SCIP_Real *upcutoff; /**< values to which cutoff counter for upwards branching */
288
289 /** default constructor */
291 ) : offset(0),
294 downpscost(0),
295 uppscost(0),
296 downvsids(0),
297 upvsids(0),
298 downconflen(0),
299 upconflen(0),
300 downinfer(0),
301 upinfer(0),
302 downcutoff(0),
303 upcutoff(0)
304 {
305 }
306 /** destractor */
308 )
309 {
311 if( downpscost ) delete[] downpscost;
312 if( uppscost ) delete[] uppscost;
313 if( downvsids ) delete[] downvsids;
314 if( upvsids ) delete[] upvsids;
315 if( downconflen ) delete[] downconflen;
316 if( upconflen ) delete[] upconflen;
317 if( downinfer ) delete[] downinfer;
318 if( upinfer ) delete[] upinfer;
319 if( downcutoff ) delete[] downcutoff;
320 if( upcutoff ) delete[] upcutoff;
321 }
322};
323
325{
326public:
327 int nVarValueVars; /**< number of variable value variables */
328 int nVarValues; /**< number of variable values, for getting statistics */
329 int *idxVarValueVars; /**< indicies of variable value vars */
330 int *nVarValueValues; /**< number of values for a variable */
331 SCIP_Real **varValue; /**< domain value, or SCIP_UNKNOWN */
332 SCIP_Real **varValueDownvsids; /**< value to which VSIDS score for downwards branching should be initialized */
333 SCIP_Real **varVlaueUpvsids; /**< value to which VSIDS score for upwards branching should be initialized */
334 SCIP_Real **varValueDownconflen; /**< value to which conflict length score for downwards branching should be initialized */
335 SCIP_Real **varValueUpconflen; /**< value to which conflict length score for upwards branching should be initialized */
336 SCIP_Real **varValueDowninfer; /**< value to which inference counter for downwards branching should be initialized */
337 SCIP_Real **varValueUpinfer; /**< value to which inference counter for upwards branching should be initialized */
338 SCIP_Real **varValueDowncutoff; /**< value to which cutoff counter for downwards branching should be initialized */
339 SCIP_Real **varValueUpcutoff; /**< value to which cutoff counter for upwards branching should be initialized */
340 /** default constructor */
342 ) : nVarValueVars(0),
343 nVarValues(0),
346 varValue(0),
355 {
356 }
357 /** destractor */
359 )
360 {
361 for( int i = 0; i < nVarValueVars; i++ )
362 {
363 if( nVarValueValues[i] > 0 )
364 {
365 if( varValue[i] ) delete[] varValue[i];
366 if( varValueDownvsids[i] ) delete[] varValueDownvsids[i];
367 if( varVlaueUpvsids[i] ) delete[] varVlaueUpvsids[i];
368 if( varValueDownconflen[i] ) delete[] varValueDownconflen[i];
369 if( varValueUpconflen[i] ) delete[] varValueUpconflen[i];
370 if( varValueDowninfer[i] ) delete[] varValueDowninfer[i];
371 if( varValueUpinfer[i] ) delete[] varValueUpinfer[i];
372 if( varValueDowncutoff[i] ) delete[] varValueDowncutoff[i];
373 if( varValueUpcutoff[i] ) delete[] varValueUpcutoff[i];
374 }
375 }
376 if( varValue ) delete [] varValue;
378 if( varVlaueUpvsids ) delete[] varVlaueUpvsids;
382 if( varValueUpinfer ) delete[] varValueUpinfer;
384 if( varValueUpcutoff ) delete[] varValueUpcutoff;
385 if( idxVarValueVars ) delete[] idxVarValueVars;
386 if( nVarValueValues ) delete[] nVarValueValues;
387 }
388};
389
390/** The difference between instance and subproblem: this is base class */
392{
393protected:
394 int localInfoIncluded; /**< 0 (0000 0000): not included
395 1 (0000 0001): if local cuts are included
396 2 (0000 0010): if conflicts are included
397 3 (0000 0011): if local cuts and conflicts are included */
398 /******************************
399 * for variable bound changes *
400 * ***************************/
401 int nBoundChanges; /**< number of branching variables */
402 int *indicesAmongSolvers; /**< array of variable indices ( unique index ) */
403 SCIP_Real *branchBounds; /**< array of bounds which the branchings */
404 SCIP_BOUNDTYPE *boundTypes; /**< array of boundtypes which the branchings */
405 /*******************************************
406 * for the case of branching by constraint *
407 * ****************************************/
408 ScipParaDiffSubproblemBranchLinearCons *branchLinearConss; /**< point to branch constraints */
409 ScipParaDiffSubproblemBranchSetppcCons *branchSetppcConss; /**< point to branch constraints */
410 /************************************
411 * for local cuts and conflict cuts *
412 * *********************************/
413 ScipParaDiffSubproblemLinearCons *linearConss; /**< point to linear constraint data */
414 /************************************
415 * for benders cuts *
416 * *********************************/
417 ScipParaDiffSubproblemLinearCons *bendersLinearConss; /**< point to benders linear constraint data */
418 /********************************
419 * for conflicts *
420 * *****************************/
421 ScipParaDiffSubproblemBoundDisjunctions *boundDisjunctions; /**< point to bound disjunctions */
422 /********************************
423 * for local var brnach stats *
424 * *****************************/
425 ScipParaDiffSubproblemVarBranchStats *varBranchStats; /**< point to varialbe branch stats */
426 /**************************************
427 * for local var value brnach stats *
428 * ***********************************/
429 ScipParaDiffSubproblemVarValues *varValues; /**< point to variable values */
430#ifdef UG_DEBUG_SOLUTION
431 int includeOptimalSol; /**< indicate if sub-MIP includes optimal solution or not. 1: include, 0: not */
432#endif
433public:
434 /** default constructor */
436 )
441 linearConss(0),
445 varValues(0)
446 {
447#ifdef UG_DEBUG_SOLUTION
448 includeOptimalSol = 0;
449#endif
450 }
451
453 SCIP *scip,
454 ScipParaSolver *scipParaSolver,
455 int nNewBranchVars,
456 SCIP_VAR **newBranchVars,
457 SCIP_Real *newBranchBounds,
458 SCIP_BOUNDTYPE *newBoundTypes,
459 int nAddedConss,
460 SCIP_CONS **addedConss
461 );
462
464 ScipParaDiffSubproblem *diffSubproblem
465 ) : localInfoIncluded(0),
469 linearConss(0),
473 varValues(0)
474
475 {
476 if( !diffSubproblem ) return;
477
478 localInfoIncluded = diffSubproblem->localInfoIncluded;
479 nBoundChanges = diffSubproblem->nBoundChanges;
480 if( nBoundChanges )
481 {
483 branchBounds = new SCIP_Real[nBoundChanges];
484 boundTypes = new SCIP_BOUNDTYPE[nBoundChanges];
485 for( int i = 0; i < nBoundChanges; i++ )
486 {
487 indicesAmongSolvers[i] = diffSubproblem->indicesAmongSolvers[i];
488 branchBounds[i] = diffSubproblem->branchBounds[i];
489 boundTypes[i] = diffSubproblem->boundTypes[i];
490 }
491 }
492
493 if( diffSubproblem->branchLinearConss )
494 {
497 assert( branchLinearConss->nLinearConss > 0 );
503 for( int c = 0; c < branchLinearConss->nLinearConss; c++ )
504 {
510 for( int v = 0; v < branchLinearConss->nLinearCoefs[c]; v++ )
511 {
512 branchLinearConss->linearCoefs[c][v] = diffSubproblem->branchLinearConss->linearCoefs[c][v];
514 }
515 }
518 for( int c = 0; c < branchLinearConss->lConsNames; c++ )
519 {
520 branchLinearConss->consNames[c] = diffSubproblem->branchLinearConss->consNames[c];
521 }
523 }
524
525 if( diffSubproblem->branchSetppcConss )
526 {
529 assert( branchSetppcConss->nSetppcConss > 0 );
533 for( int c = 0; c < branchSetppcConss->nSetppcConss; c++ )
534 {
538 for( int v = 0; v < branchSetppcConss->nSetppcVars[c]; v++ )
539 {
540 branchSetppcConss->idxSetppcVars[c][v] = diffSubproblem->branchSetppcConss->idxSetppcVars[c][v];
541 }
542 }
545 for( int c = 0; c < branchSetppcConss->lConsNames; c++ )
546 {
547 branchSetppcConss->consNames[c] = diffSubproblem->branchSetppcConss->consNames[c];
548 }
550 }
551
552 if( diffSubproblem->linearConss )
553 {
556 assert( linearConss->nLinearConss > 0 );
557 // std::cout << "linearConss->nLinearConss = " << linearConss->nLinearConss << std::endl;
563 for( int c = 0; c < linearConss->nLinearConss; c++ )
564 {
565 linearConss->linearLhss[c] = diffSubproblem->linearConss->linearLhss[c];
566 linearConss->linearRhss[c] = diffSubproblem->linearConss->linearRhss[c];
567 linearConss->nLinearCoefs[c] = diffSubproblem->linearConss->nLinearCoefs[c];
568 linearConss->linearCoefs[c] = new SCIP_Real[linearConss->nLinearCoefs[c]];
570 for( int v = 0; v < linearConss->nLinearCoefs[c]; v++ )
571 {
572 linearConss->linearCoefs[c][v] = diffSubproblem->linearConss->linearCoefs[c][v];
573 linearConss->idxLinearCoefsVars[c][v] = diffSubproblem->linearConss->idxLinearCoefsVars[c][v];
574 }
575 }
576 }
577
578 if( diffSubproblem->bendersLinearConss )
579 {
582 assert( bendersLinearConss->nLinearConss > 0 );
583 // std::cout << "bendersLinearConss->nLinearConss = " << bendersLinearConss->nLinearConss << std::endl;
589 for( int c = 0; c < bendersLinearConss->nLinearConss; c++ )
590 {
596 for( int v = 0; v < bendersLinearConss->nLinearCoefs[c]; v++ )
597 {
598 bendersLinearConss->linearCoefs[c][v] = diffSubproblem->bendersLinearConss->linearCoefs[c][v];
600 }
601 }
602 }
603
604 if( diffSubproblem->boundDisjunctions )
605 {
623 for( int i = 0; i < boundDisjunctions->nBoundDisjunctions; i++ )
624 {
638 {
642 for( int j = 0; j < boundDisjunctions->nVarsBoundDisjunction[i]; j++ )
643 {
647 }
648 }
649 }
650 }
651
652
653 if( diffSubproblem->varBranchStats )
654 {
656 varBranchStats->offset = diffSubproblem->varBranchStats->offset;
669 for( int i = 0; i < varBranchStats->nVarBranchStats; ++i )
670 {
672 varBranchStats->downpscost[i] = diffSubproblem->varBranchStats->downpscost[i];
673 varBranchStats->uppscost[i] = diffSubproblem->varBranchStats->uppscost[i];
674 varBranchStats->downvsids[i] = diffSubproblem->varBranchStats->downvsids[i];
675 varBranchStats->upvsids[i] = diffSubproblem->varBranchStats->upvsids[i];
676 varBranchStats->downconflen[i] = diffSubproblem->varBranchStats->downconflen[i];
677 varBranchStats->upconflen[i] = diffSubproblem->varBranchStats->upconflen[i];
678 varBranchStats->downinfer[i] = diffSubproblem->varBranchStats->downinfer[i];
679 varBranchStats->upinfer[i] = diffSubproblem->varBranchStats->upinfer[i];
680 varBranchStats->downcutoff[i] = diffSubproblem->varBranchStats->downcutoff[i];
681 varBranchStats->upcutoff[i] = diffSubproblem->varBranchStats->upcutoff[i];
682 }
683 }
684
685 if( diffSubproblem->varValues )
686 {
689 varValues->nVarValues = diffSubproblem->varValues->nVarValues;
692 varValues->varValue = new SCIP_Real*[varValues->nVarValueVars];
701 for( int i = 0; i < varValues->nVarValueVars; i++ )
702 {
703 varValues->idxVarValueVars[i] = diffSubproblem->varValues->idxVarValueVars[i];
704 varValues->nVarValueValues[i] = diffSubproblem->varValues->nVarValueValues[i];
705 if( varValues->nVarValueValues[i] > 0 )
706 {
707 varValues->varValue[i] = new SCIP_Real[varValues->nVarValueValues[i]];
708 varValues->varValueDownvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
709 varValues->varVlaueUpvsids[i] = new SCIP_Real[varValues->nVarValueValues[i]];
711 varValues->varValueUpconflen[i] = new SCIP_Real[varValues->nVarValueValues[i]];
712 varValues->varValueDowninfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
713 varValues->varValueUpinfer[i] = new SCIP_Real[varValues->nVarValueValues[i]];
714 varValues->varValueDowncutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
715 varValues->varValueUpcutoff[i] = new SCIP_Real[varValues->nVarValueValues[i]];
716 for( int j = 0; j < varValues->nVarValueValues[i]; j++ )
717 {
718 varValues->varValue[i][j] = diffSubproblem->varValues->varValue[i][j];
719 varValues->varValueDownvsids[i][j] = diffSubproblem->varValues->varValueDownvsids[i][j];
720 varValues->varVlaueUpvsids[i][j] = diffSubproblem->varValues->varVlaueUpvsids[i][j];
721 varValues->varValueDownconflen[i][j] = diffSubproblem->varValues->varValueDownconflen[i][j];
722 varValues->varValueUpconflen[i][j] = diffSubproblem->varValues->varValueUpconflen[i][j];
723 varValues->varValueDowninfer[i][j] = diffSubproblem->varValues->varValueDowninfer[i][j];
724 varValues->varValueUpinfer[i][j] = diffSubproblem->varValues->varValueUpinfer[i][j];
725 varValues->varValueDowncutoff[i][j] = diffSubproblem->varValues->varValueDowncutoff[i][j];
726 varValues->varValueUpcutoff[i][j] = diffSubproblem->varValues->varValueUpcutoff[i][j];
727 }
728 }
729 }
730 }
731#ifdef UG_DEBUG_SOLUTION
732 includeOptimalSol = diffSubproblem->includeOptimalSol;
733#endif
734 }
735
736 /** destractor */
738 {
740 if( branchBounds ) delete[] branchBounds;
741 if( boundTypes ) delete[] boundTypes;
743 {
744 delete branchLinearConss;
745 }
747 {
748 delete branchSetppcConss;
749 }
750 if( linearConss )
751 {
752 delete linearConss;
753 }
755 {
756 delete bendersLinearConss;
757 }
759 {
760 delete boundDisjunctions;
761 }
762
763 if( varBranchStats )
764 {
765 delete varBranchStats;
766 }
767 if( varValues )
768 {
769 delete varValues;
770 }
771 }
772
774 int getIndex(int i){ return indicesAmongSolvers[i]; }
775 SCIP_Real getBranchBound(int i){ return branchBounds[i]; }
776 SCIP_BOUNDTYPE getBoundType(int i){ return boundTypes[i]; }
777
779 {
780 return branchLinearConss;
781 }
782
784 {
785 return branchSetppcConss;
786 }
787
789 {
791 {
793 }
794 else
795 {
796 return 0;
797 }
798 }
799
800 SCIP_Real getBranchConsLinearLhs(int i)
801 {
802 assert(branchLinearConss);
803 return branchLinearConss->linearLhss[i];
804 }
805
806 SCIP_Real getBranchConsLinearRhs(int i)
807 {
808 assert(branchLinearConss);
809 return branchLinearConss->linearRhss[i];
810 }
811
813 {
814 assert(branchLinearConss);
816 }
817
818 SCIP_Real getBranchConsLinearCoefs(int i, int j)
819 {
820 assert(branchLinearConss);
821 return branchLinearConss->linearCoefs[i][j];
822 }
823
825 {
826 assert(branchLinearConss);
828 }
829
831 {
832 assert(branchLinearConss);
834 }
835
837 {
838 char *name = branchLinearConss->consNames;
839 for( int j = 0; j < i; j++)
840 {
841 assert(*name);
842 name += (std::strlen(name) + 1);
843 }
844 assert(*name);
845 return name;
846 }
847
848
850 {
852 {
854 }
855 else
856 {
857 return 0;
858 }
859 }
860
862 {
863 assert(branchSetppcConss);
865 }
866
868 {
869 assert(branchSetppcConss);
871 }
872
873 int getBranchConsSetppcVars(int i, int j)
874 {
875 assert(branchSetppcConss);
876 return branchSetppcConss->idxSetppcVars[i][j];
877 }
878
880 {
881 assert(branchSetppcConss);
883 }
884
886 {
887 char *name = branchSetppcConss->consNames;
888 for( int j = 0; j < i; j++)
889 {
890 assert(*name);
891 name += (std::strlen(name) + 1);
892 }
893 assert(*name);
894 return name;
895 }
896
897
899 {
900 if( linearConss )
901 {
903 }
904 else
905 {
906 return 0;
907 }
908 }
909
910
911 SCIP_Real getLinearLhs(int i)
912 {
913 assert(linearConss);
914 return linearConss->linearLhss[i];
915 }
916
917 SCIP_Real getLinearRhs(int i)
918 {
919 assert(linearConss);
920 return linearConss->linearRhss[i];
921 }
922
924 {
925 assert(linearConss);
926 return linearConss->nLinearCoefs[i];
927 }
928
929 SCIP_Real getLinearCoefs(int i, int j)
930 {
931 assert(linearConss);
932 return linearConss->linearCoefs[i][j];
933 }
934
935 int getIdxLinearCoefsVars(int i, int j)
936 {
937 assert(linearConss);
938 return linearConss->idxLinearCoefsVars[i][j];
939 }
940
942 {
944 {
946 }
947 else
948 {
949 return 0;
950 }
951 }
952
953 SCIP_Real getBendersLinearLhs(int i)
954 {
955 assert(bendersLinearConss);
957 }
958
959 SCIP_Real getBendersLinearRhs(int i)
960 {
961 assert(bendersLinearConss);
963 }
964
966 {
967 assert(bendersLinearConss);
969 }
970
971 SCIP_Real getBendersLinearCoefs(int i, int j)
972 {
973 assert(bendersLinearConss);
974 return bendersLinearConss->linearCoefs[i][j];
975 }
976
978 {
979 assert(bendersLinearConss);
981 }
982
984 {
986 {
988 }
989 else
990 {
991 return 0;
992 }
993 }
994
996 {
997 assert(boundDisjunctions);
999 }
1000
1002 assert(boundDisjunctions);
1003 assert( boundDisjunctions->nVarsBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1005 }
1007 {
1008 assert(boundDisjunctions);
1009 assert( boundDisjunctions->flagBoundDisjunctionInitial && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1011 }
1013 {
1014 assert(boundDisjunctions);
1015 assert( boundDisjunctions->flagBoundDisjunctionSeparate && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1017 }
1019 {
1020 assert(boundDisjunctions);
1021 assert( boundDisjunctions->flagBoundDisjunctionEnforce && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1023 }
1025 {
1026 assert(boundDisjunctions);
1027 assert( boundDisjunctions->flagBoundDisjunctionCheck && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1029 }
1031 {
1032 assert(boundDisjunctions);
1033 assert( boundDisjunctions->flagBoundDisjunctionPropagate && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1035 }
1037 {
1038 assert( boundDisjunctions->flagBoundDisjunctionLocal && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1040 }
1042 {
1043 assert(boundDisjunctions);
1044 assert( boundDisjunctions->flagBoundDisjunctionModifiable && i >= 0 && i <boundDisjunctions->nBoundDisjunctions );
1046 }
1048 {
1049 assert(boundDisjunctions);
1050 assert( boundDisjunctions->flagBoundDisjunctionDynamic && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1052 }
1054 {
1055 assert(boundDisjunctions);
1056 assert( boundDisjunctions->flagBoundDisjunctionRemovable && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1058 }
1060 {
1061 assert(boundDisjunctions);
1062 assert( boundDisjunctions->flagBoundDisjunctionStickingatnode && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1064 }
1065
1067 {
1068 assert(boundDisjunctions);
1069 assert( boundDisjunctions->idxBoundDisjunctionVars && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1070 assert( boundDisjunctions->idxBoundDisjunctionVars[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1072 }
1073 SCIP_BOUNDTYPE getBoundTypesBoundDisjunction(int i, int j)
1074 {
1075 assert(boundDisjunctions);
1076 assert( boundDisjunctions->boundTypesBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1077 assert( boundDisjunctions->boundTypesBoundDisjunction[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1079 }
1080 SCIP_Real getBoundsBoundDisjunction(int i, int j)
1081 {
1082 assert(boundDisjunctions);
1083 assert( boundDisjunctions->boundsBoundDisjunction && i >= 0 && i < boundDisjunctions->nBoundDisjunctions );
1084 assert( boundDisjunctions->boundsBoundDisjunction[i] && j >= 0 && j < boundDisjunctions->nVarsBoundDisjunction[i] );
1086 }
1087
1089 {
1090
1091 if( varBranchStats )
1092 {
1094 }
1095 else
1096 {
1097 return 0;
1098 }
1099 }
1100
1102 {
1103 assert(varBranchStats);
1104 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1106 }
1107
1108 SCIP_Real getDownpscost(int i)
1109 {
1110 assert(varBranchStats);
1111 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1112 return varBranchStats->downpscost[i];
1113 }
1114
1115 SCIP_Real getUppscost(int i)
1116 {
1117 assert(varBranchStats);
1118 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1119 return varBranchStats->uppscost[i];
1120 }
1121
1122 SCIP_Real getDownvsids(int i)
1123 {
1124 assert(varBranchStats);
1125 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1126 return varBranchStats->downvsids[i];
1127 }
1128
1129 SCIP_Real getUpvsids(int i)
1130 {
1131 assert(varBranchStats);
1132 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1133 return varBranchStats->upvsids[i];
1134 }
1135
1136 SCIP_Real getDownconflen(int i)
1137 {
1138 assert(varBranchStats);
1139 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1140 return varBranchStats->downconflen[i];
1141 }
1142
1143 SCIP_Real getUpconflen(int i)
1144 {
1145 assert(varBranchStats);
1146 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1147 return varBranchStats->upconflen[i];
1148 }
1149
1150 SCIP_Real getDowninfer(int i)
1151 {
1152 assert(varBranchStats);
1153 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1154 return varBranchStats->downinfer[i];
1155 }
1156
1157 SCIP_Real getUpinfer(int i)
1158 {
1159 assert(varBranchStats);
1160 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1161 return varBranchStats->upinfer[i];
1162 }
1163
1164 SCIP_Real getDowncutoff(int i)
1165 {
1166 assert(varBranchStats);
1167 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1168 return varBranchStats->downcutoff[i];
1169 }
1170
1171 SCIP_Real getUpcutoff(int i)
1172 {
1173 assert(varBranchStats);
1174 assert( i >= 0 && i <varBranchStats->nVarBranchStats );
1175 return varBranchStats->upcutoff[i];
1176 }
1177
1178
1180 {
1181 if( varValues )
1182 {
1183 return varValues->nVarValueVars;
1184 }
1185 else
1186 {
1187 return 0;
1188 }
1189 }
1190
1192 {
1193 assert(varValues);
1194 return varValues->nVarValues;
1195 }
1196
1198 {
1199 assert(varValues);
1200 assert(varValues->idxVarValueVars && i >= 0 && i < varValues->nVarValueVars );
1201 return varValues->idxVarValueVars[i];
1202 }
1203
1205 {
1206 assert(varValues);
1207 assert(varValues->idxVarValueVars && i >= 0 && i < varValues->nVarValueVars );
1208 return varValues->nVarValueValues[i];
1209 }
1210
1211 SCIP_Real getVarValue(int i, int j)
1212 {
1213 assert(varValues);
1214 assert(varValues->varValue && i >= 0 && i < varValues->nVarValueVars );
1215 assert(varValues->varValue[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1216 return varValues->varValue[i][j];
1217 }
1218
1219 SCIP_Real getVarValueDownvsids(int i, int j)
1220 {
1221 assert(varValues);
1222 assert(varValues->varValueDownvsids && i >= 0 && i < varValues->nVarValueVars );
1223 assert(varValues->varValueDownvsids[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1224 return varValues->varValueDownvsids[i][j];
1225 }
1226
1227 SCIP_Real getVarVlaueUpvsids(int i, int j)
1228 {
1229 assert(varValues);
1230 assert(varValues->varVlaueUpvsids && i >= 0 && i < varValues->nVarValueVars );
1231 assert(varValues->varVlaueUpvsids[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1232 return varValues->varVlaueUpvsids[i][j];
1233 }
1234
1235 SCIP_Real getVarValueDownconflen(int i, int j)
1236 {
1237 assert(varValues);
1238 assert(varValues->varValueDownconflen && i >= 0 && i < varValues->nVarValueVars );
1239 assert(varValues->varValueDownconflen[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1240 return varValues->varValueDownconflen[i][j];
1241 }
1242
1243 SCIP_Real getVarValueUpconflen(int i, int j)
1244 {
1245 assert(varValues);
1246 assert(varValues->varValueUpconflen && i >= 0 && i < varValues->nVarValueVars );
1247 assert(varValues->varValueUpconflen[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1248 return varValues->varValueUpconflen[i][j];
1249 }
1250
1251 SCIP_Real getVarValueDowninfer(int i, int j)
1252 {
1253 assert(varValues);
1254 assert(varValues->varValueDowninfer && i >= 0 && i < varValues->nVarValueVars );
1255 assert(varValues->varValueDowninfer[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1256 return varValues->varValueDowninfer[i][j];
1257 }
1258
1259 SCIP_Real getVarValueUpinfer(int i, int j)
1260 {
1261 assert(varValues);
1262 assert(varValues->varValueUpinfer && i >= 0 && i < varValues->nVarValueVars );
1263 assert(varValues->varValueUpinfer[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1264 return varValues->varValueUpinfer[i][j];
1265 }
1266
1267 SCIP_Real getVarValueDowncutoff(int i, int j)
1268 {
1269 assert(varValues);
1270 assert(varValues->varValueDowncutoff && i >= 0 && i < varValues->nVarValueVars );
1271 assert(varValues->varValueDowncutoff[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1272 return varValues->varValueDowncutoff[i][j];
1273 }
1274
1275 SCIP_Real getVarValueUpcutoff(int i, int j)
1276 {
1277 assert(varValues);
1278 assert(varValues->varValueUpcutoff && i >= 0 && i < varValues->nVarValueVars );
1279 assert(varValues->varValueUpcutoff[i] && j >= 0 && j < varValues->nVarValueValues[i] );
1280 return varValues->varValueUpcutoff[i][j];
1281 }
1282
1284 SCIP *scip,
1285 ScipParaSolver *scipParaSolver,
1286 int nLenarConss,
1287 int nAddedConss,
1288 SCIP_CONS **addedConss
1289 );
1290
1292 SCIP *scip,
1293 ScipParaSolver *scipParaSolver,
1294 int nSetpartConss,
1295 int nAddedConss,
1296 SCIP_CONS **addedConss
1297 );
1298
1299 void addLocalNodeInfo(
1300 SCIP *scip,
1301 ScipParaSolver *scipParaSolver
1302 );
1303
1305 SCIP *scip,
1306 ScipParaSolver *scipParaSolver
1307 );
1308
1309 void addBranchVarStats(
1310 SCIP *scip,
1311 ScipParaSolver *scipParaSolver
1312 );
1313
1314 void addVarValueStats(
1315 SCIP *scip,
1316 ScipParaSolver *scipParaSolver
1317 );
1318
1320 int minDepth,
1321 int maxDepth,
1322 SCIP *scip
1323 );
1324
1326 {
1327 assert(varBranchStats);
1328 return varBranchStats->offset;
1329 }
1330
1331#ifdef UG_WITH_ZLIB
1332 void write(gzstream::ogzstream &out);
1333 void read(UG::ParaComm *comm, gzstream::igzstream &in, bool onlyBoundChanges);
1334#endif
1335
1336 /** get fixed variables **/
1338 UG::ParaInstance *instance,
1339 UG::BbParaFixedVariable **fixedVars );
1340
1341 /** create new ParaDiffSubproblem using fixed variables information */
1344 UG::ParaInitiator *initiator,
1345 int n,
1346 UG::BbParaFixedVariable *fixedVars );
1347
1348 /** stringfy ParaCalculationState */
1349 const std::string toString(
1350 );
1351
1352 /** stringfy statistics to log file */
1353 const std::string toStringStat(){
1354 std::ostringstream s;
1356 {
1357 s << ", blc: " << branchLinearConss->nLinearConss;
1358 s << "," << branchLinearConss->lConsNames;
1359 }
1360 else
1361 {
1362 s << ", blc: 0";
1363 }
1365 {
1366 s << ", bsc: " << branchSetppcConss->nSetppcConss;
1367 s << "," << branchSetppcConss->lConsNames;
1368 }
1369 else
1370 {
1371 s << ", bsc: 0";
1372 }
1373 if( linearConss )
1374 {
1375 s << ", nl: " << linearConss->nLinearConss;
1376 }
1377 else
1378 {
1379 s << ", nl: 0";
1380 }
1381 if( bendersLinearConss )
1382 {
1383 s << ", bnl: " << bendersLinearConss->nLinearConss;
1384 }
1385 else
1386 {
1387 s << ", nl: 0";
1388 }
1389
1390
1391 if ( boundDisjunctions )
1392 {
1394 }
1395 else
1396 {
1397 s << ", nbd: 0, nbdt: 0";
1398 }
1399
1400 if( varBranchStats )
1401 {
1402 s << ", nbs: " << varBranchStats->nVarBranchStats;
1403 }
1404 else
1405 {
1406 s << ", nbs: 0";
1407 }
1408
1409 if( varValues )
1410 {
1411 s << ", nvv: " << varValues->nVarValueVars << ", nvvt: " << varValues->nVarValues;
1412 }
1413 else
1414 {
1415 s << ", nvv: 0, nvvt: 0";
1416 }
1417 return s.str();
1418 }
1419
1420#ifdef UG_DEBUG_SOLUTION
1421 bool isOptimalSolIncluded(){ return (includeOptimalSol != 0); }
1422 void setOptimalSolIndicator(int i){ includeOptimalSol = i; }
1423#endif
1424
1425};
1426
1427}
1428
1429#endif // __SCIP_PARA_DIFF_SUBPROBLEM_H__
1430
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.