Scippy

UG

Ubiquity Generator framework

bbParaNodesMerger.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 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 paraMergeNodesStructs.h
27  * @brief Structs used for merging nodes.
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 __BB_PARA_NODES_MERGER_H__
38 #define __BB_PARA_NODES_MERGER_H__
39 
40 #include<cassert>
41 #include<ug/paraTimer.h>
42 #include<ug/paraInitiator.h>
43 #include<ug/paraParamSet.h>
44 #include "bbParaInstance.h"
45 
46 namespace UG
47 {
48 
49 class BbParaNode;
50 class BbParaDiffSubproblem;
51 class BbParaNodePool;
52 
59 
60 ///
61 /// Fixed value struct
62 ///
64  double value; ///< value for a fixed variable
65  BbParaFixedVariable *head; ///< point the head of the ParaFixedVariable
66  BbParaFixedVariable *tail; ///< point the tail of the ParaFixedVarialbe
67  BbParaFixedValue *next; ///< point next ParaFixedValue struct
68 };
69 
70 ///
71 /// Merge node information struct
72 ///
74  enum {
75  PARA_MERGING, ///< in merging process
76  PARA_MERGED_RPRESENTATIVE, ///< representative node for merging
77  PARA_MERGE_CHECKING_TO_OTHER_NODE, ///< checking possibility to merge with the other nodes
78  PARA_MERGED_TO_OTHER_NODE, ///< merged to the other node
79  PARA_CANNOT_MERGE, ///< cannot merge to the other node
80  PARA_DELETED ///< this node is deleted
81  } status; ///< status of this ParaMargeNodeInfo
82  int nSameValueVariables; ///< the number of fixed values which are the same as those of the merged node
83  ///< - This value < 0 means that this node is not merging target
84  int nMergedNodes; ///< the number of merged nodes with this node.
85  ///< - This value > 0 : head
86  ///< - This value = 0 : merging to the other node
87  ///< - This value < 0 : no merging node
88  int keyIndex; ///< The fixedVar of this index can reach all merging nodes
89  int nFixedVariables; ///< the number of fixed variables
90  BbParaFixedVariable *fixedVariables; ///< array of fixed variable info
91  BbParaMergeNodeInfo *mergedTo; ///< pointer to merge node info to which this node is merged */
92  BbParaNode *paraNode; ///< BbParaNode corresponding to this ParaMergeModeInfo */
93  BbParaDiffSubproblem *origDiffSubproblem; ///< original DiffSubproblem */
94  BbParaDiffSubproblem *mergedDiffSubproblem; ///< merged DiffSubproblem, in case this node is merged and this is the head */
95  BbParaMergeNodeInfo *next; ///< pointer to the next ParaMergeNodeInfo */
96 };
97 
98 ///
99 /// Fixed variable struct
100 ///
102  int nSameValue; ///< the number of same value fixed variables in the following nodes
103  int index; ///< index of the variable among all solvers
104  double value; ///< fixed value
105  BbParaMergeNodeInfo *mnode; ///< pointer to merge node info struct to which this info is belonging
106  BbParaFixedVariable *next; ///< pointer to the next node which has the same fixed value
107  BbParaFixedVariable *prev; ///< pointer to the previous node which has the same fixed value
108 };
109 
110 ///
111 /// Sorted variable struct
112 ///
114  int idxInFixedVariabes; ///< index in the fixedVariables array
115  BbParaFixedVariable *fixedVariable; ///< pointer to the fixedVariable
116 };
117 
118 ///
119 /// merged node list element stract
121  BbParaNode *node; ///< pointer to BbParaNode object
122  BbParaMergedNodeListElement *next; ///< pointer to the next ParaMergedNodeListElement
123 };
124 
126 {
127  int varIndexRange; ///< variable index range
128  int nBoundChangesOfBestNode; ///< bound changes of the best node
129  ParaTimer *paraTimer; ///< normal timer used
130  BbParaInstance *instance; ///< pointer to ParaInstance object
131  ParaParamSet *paraParamSet; ///< pointer to ParaParamSet object
132  BbParaFixedValue **varIndexTable; ///< variable indices table.
133  BbParaMergeNodeInfo *mergeInfoHead; ///< head of BbParaMergeNodeInfo list
134  BbParaMergeNodeInfo *mergeInfoTail; ///< tail of BbParaMergeNodeInfo list
135  /// times
136  double addingNodeToMergeStructTime; ///< accumulate time to add Node to merge struct
137  double generateMergeNodesCandidatesTime; ///< accumulate time to generate merge nodes candidates
138  double regenerateMergeNodesCandidatesTime; ///< accumulate time to regenerate merge nodes candidates
139  double mergeNodeTime; ///< accumulate time to make a merged node
140 
141 public:
142 
144  int inVarIndexRange,
145  int inNBoundChangesOfBestNode,
146  ParaTimer *inParaTimer,
147  BbParaInstance *inParaInstance,
148  ParaParamSet *inParaParamSet
149  )
150  :
151  varIndexRange(inVarIndexRange),
152  nBoundChangesOfBestNode(inNBoundChangesOfBestNode),
153  paraTimer(inParaTimer),
154  instance(inParaInstance),
155  paraParamSet(inParaParamSet),
156  varIndexTable(0),
157  mergeInfoHead(0),
158  mergeInfoTail(0),
159  addingNodeToMergeStructTime(0.0),
160  generateMergeNodesCandidatesTime(0.0),
161  regenerateMergeNodesCandidatesTime(0.0),
162  mergeNodeTime(0.0)
163  {
164  assert( varIndexRange > 0 );
165  varIndexTable = new BbParaFixedValuePtr[varIndexRange];
166  for( int i = 0; i < varIndexRange; i++ )
167  {
168  varIndexTable[i] = 0;
169  }
170  mergeInfoHead = 0;
171  mergeInfoTail = 0;
172  }
173 
175  )
176  {
177  }
178 
179  ///
180  /// add a node to nodes merger
181  ///
182  void addNodeToMergeNodeStructs(
183  BbParaNode *node ///< pointer to BbParaNode object to be merged
184  );
185 
186  ///
187  /// generate merge nodes candidates
188  ///
189  void generateMergeNodesCandidates(
190  ParaComm *paraComm, ///< pointer to paraComm object
191  ParaInitiator *paraInitiator ///< pointer to ParaInitiatior object, this can be 0, if it is not
192  );
193 
194  ///
195  /// regenerate merge nodes candidates
196  ///
197  void regenerateMergeNodesCandidates(
198  BbParaNode *node, ///< pointer to BbParaNode object to be removed from this merger
199  ParaComm *paraComm, ///< pointer to paraComm object
200  ParaInitiator *paraInitiator ///< pointer to ParaInitiatior object, this can be 0, if it is not
201  );
202 
203  ///
204  /// delete merge node info
205  ///
206  void deleteMergeNodeInfo(
207  BbParaMergeNodeInfo *mNode ///< pointer to BbParaMergeNodeInfo object to be removed
208  );
209 
210  ///
211  /// make a merge node
212  /// @return the number of nodes merged
213  ///
214  int mergeNodes(
215  BbParaNode *node, ///< pointer to BbParaNode object which is the representative
216  BbParaNodePool *paraNodePool ///< pointer to BbParaNodePool object
217  );
218 
219  ///
220  /// getter of addingNodeToMergeStructTime
221  /// @return addingNodeToMergeStructTime
222  ///
224  )
225  {
226  return addingNodeToMergeStructTime;
227  }
228 
229  ///
230  /// getter of generateMergeNodesCandidatesTime
231  /// @return generateMergeNodesCandidatesTime
232  ///
234  )
235  {
236  return generateMergeNodesCandidatesTime;
237  }
238 
239  ///
240  /// getter of regenerateMergeNodesCandidatesTime
241  /// @return regenerateMergeNodesCandidatesTime
242  ///
244  )
245  {
246  return regenerateMergeNodesCandidatesTime;
247  }
248 
249  ///
250  /// getter of mergeNodeTime
251  /// @return mergeNodeTime
252  ///
254  )
255  {
256  return mergeNodeTime;
257  }
258 
259 };
260 
261 }
262 
263 #endif // __BB_PARA_NODES_MERGER_H__
BbParaFixedVariable * prev
pointer to the previous node which has the same fixed value
BbParaFixedVariable * head
point the head of the ParaFixedVariable
int nMergedNodes
the number of merged nodes with this node.
Fixed variable struct.
double generateMergeNodesCandidatesTime
accumulate time to generate merge nodes candidates
double value
value for a fixed variable
BbParaInstance * instance
pointer to ParaInstance object
static ScipParaInitiator * paraInitiator
Definition: fscip.cpp:76
BbParaFixedVariable * fixedVariables
array of fixed variable info
double getRegenerateMergeNodesCandidatesTime()
getter of regenerateMergeNodesCandidatesTime
int nBoundChangesOfBestNode
bound changes of the best node
int index
index of the variable among all solvers
BbParaMergeNodeInfo * mnode
pointer to merge node info struct to which this info is belonging
merged node list element stract
int nSameValue
the number of same value fixed variables in the following nodes
ParaTimer * paraTimer
normal timer used
double getAddingNodeToMergeStructTime()
getter of addingNodeToMergeStructTime
Class for initiator.
Definition: paraInitiator.h:62
BbParaMergeNodeInfo * mergeInfoTail
tail of BbParaMergeNodeInfo list times
double addingNodeToMergeStructTime
accumulate time to add Node to merge struct
Base class for Timer.
Sorted variable struct.
Fixed value struct.
BbParaDiffSubproblem * origDiffSubproblem
original DiffSubproblem */
BbParaFixedVariable * fixedVariable
pointer to the fixedVariable
Parameter set for UG framework.
int keyIndex
The fixedVar of this index can reach all merging nodes.
double mergeNodeTime
accumulate time to make a merged node
BbParaMergedNodeListElement * next
pointer to the next ParaMergedNodeListElement
Class for the difference between instance and subproblem.
BbParaNode * node
pointer to BbParaNode object
BbParaFixedVariable * next
pointer to the next node which has the same fixed value
BbParaFixedVariable * tail
point the tail of the ParaFixedVarialbe
class ParaParamSet
Definition: paraParamSet.h:850
BbParaDiffSubproblem * mergedDiffSubproblem
merged DiffSubproblem, in case this node is merged and this is the head */
int varIndexRange
variable index range
BbParaFixedValue * next
point next ParaFixedValue struct
BbParaNodesMerger(int inVarIndexRange, int inNBoundChangesOfBestNode, ParaTimer *inParaTimer, BbParaInstance *inParaInstance, ParaParamSet *inParaParamSet)
class BbParaNode
Definition: bbParaNode.h:61
int idxInFixedVariabes
index in the fixedVariables array
Base class of initiator that maintains original problem and incumbent solution.
BbParaMergeNodeInfo * mergeInfoHead
head of BbParaMergeNodeInfo list
ParaParamSet * paraParamSet
pointer to ParaParamSet object
class for instance data
struct BbParaFixedValue_ * BbParaFixedValuePtr
double value
fixed value
int nFixedVariables
the number of fixed variables
checking possibility to merge with the other nodes
double getMergeNodeTime()
getter of mergeNodeTime
class BbParaNodePool
BbParaFixedValue ** varIndexTable
variable indices table.
BbParaMergeNodeInfo * next
pointer to the next ParaMergeNodeInfo */
Merge node information struct.
class ParaTimer
Definition: paraTimer.h:48
BbParaMergeNodeInfo * mergedTo
pointer to merge node info to which this node is merged */
double getGenerateMergeNodesCandidatesTime()
getter of generateMergeNodesCandidatesTime
double regenerateMergeNodesCandidatesTime
accumulate time to regenerate merge nodes candidates
Base class of communicator object.
Definition: paraComm.h:101
BbParaNode * paraNode
BbParaNode corresponding to this ParaMergeModeInfo */.
int nSameValueVariables
the number of fixed values which are the same as those of the merged node