Scippy

UG

Ubiquity Generator framework

scipDiffParamSet.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 scipDiffParamSet.h
27  * @brief SCIP parameter set to be transferred ( Only keep difference between default settings ).
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_DIFF_PARAM_SET_H__
38 #define __SCIP_DIFF_PARAM_SET_H__
39 #include <cstring>
40 #include "ug/paraDef.h"
41 #ifdef UG_WITH_ZLIB
42 #include "ug/gzstream.h"
43 #endif
44 #include "ug/paraComm.h"
45 #include "scip/scip.h"
46 
47 namespace ParaSCIP
48 {
49 
50 /** ScipDiffParamSet class */
52 protected:
53  int numBoolParams; /**< the number of bool parameters */
54  size_t boolParamNamesSize; /**< size of boolParameterNames area */
55  char *boolParamNames; /**< boolean parameter names: names are concatenated */
56  unsigned int *boolParamValues; /**< boolean parameter values */
57 
58  int numIntParams; /**< the number of int parameters */
59  size_t intParamNamesSize; /**< size of intParameterNames area */
60  char *intParamNames; /**< int parameter names: names are concatenated */
61  int *intParamValues; /**< int parameter values */
62 
63  int numLongintParams; /**< the number of longint parameters */
64  size_t longintParamNamesSize; /**< size of longintParameterNames area */
65  char *longintParamNames; /**< longint parameter names: names are concatenated */
66  long long *longintParamValues; /**< longint parameter values */
67 
68  int numRealParams; /**< the number of real parameters */
69  size_t realParamNamesSize; /**< size of realParameterNames area */
70  char *realParamNames; /**< real parameter names: names are concatenated */
71  double *realParamValues; /**< real parameter values */
72 
73  int numCharParams; /**< the number of char parameters */
74  size_t charParamNamesSize; /**< size of charParameterNames area */
75  char *charParamNames; /**< char parameter names: names are concatenated */
76  char *charParamValues; /**< char parameter values */
77 
78  int numStringParams; /**< the number of string parameters */
79  size_t stringParamNamesSize; /**< size of stringParameterNames area */
80  char *stringParamNames; /**< string parameter names: names are concatenated */
81  size_t stringParamValuesSize; /**< size of stringParameterValues area */
82  char *stringParamValues; /**< string parameter values: values are concatenated */
83 
84  /** allocate memory for names and values */
85  void allocateMemoty();
86 
87 public:
88  /** constructor */
90  )
91  : numBoolParams(0), boolParamNamesSize(0), boolParamNames(0), boolParamValues(0),
92  numIntParams(0), intParamNamesSize(0), intParamNames(0), intParamValues(0),
93  numLongintParams(0), longintParamNamesSize(0), longintParamNames(0), longintParamValues(0),
94  numRealParams(0), realParamNamesSize(0), realParamNames(0), realParamValues(0),
95  numCharParams(0), charParamNamesSize(0), charParamNames(0), charParamValues(0),
96  numStringParams(0), stringParamNamesSize(0), stringParamNames(0), stringParamValuesSize(0), stringParamValues(0)
97  {
98  }
99 
100  /** constructor with scip */
102  SCIP *scip
103  );
104 
105  /** destructor */
107  )
108  {
109  if( boolParamNames ) delete[] boolParamNames;
110  if( boolParamValues ) delete[] boolParamValues;
111  if( intParamNames ) delete[] intParamNames;
112  if( intParamValues ) delete[] intParamValues;
113  if( longintParamNames ) delete[] longintParamNames;
114  if( longintParamValues ) delete[] longintParamValues;
115  if( realParamNames ) delete[] realParamNames;
116  if( realParamValues ) delete[] realParamValues;
117  if( charParamNames ) delete[] charParamNames;
118  if( charParamValues ) delete[] charParamValues;
119  if( stringParamNames ) delete[] stringParamNames;
120  if( stringParamValues ) delete[] stringParamValues;
121  }
122 
123  /** set these parameter values in scip environment */
124  void setParametersInScip(
125  SCIP *scip
126  );
127 
128  /** get number of different parameters between their default values */
130  )
131  {
132  return (numBoolParams + numIntParams + numLongintParams + numRealParams + numCharParams + numStringParams);
133  }
134 
135  /** check if this parameter setting contains the argument name real parameter or not **/
136  /** NOTE: this function is not tested */
137  bool doesContainRealParam(char *string)
138  {
139  char *paramName = realParamNames;
140  for( int i = 0; i < numRealParams; i++ )
141  {
142  if( std::strcmp(paramName, string) == 0 )
143  {
144  return true;
145  }
146  paramName += std::strlen(paramName) + 1;
147  }
148  return false;
149  }
150 
151  /** stringfy DiffParamSet */
152  std::string toString();
153 
154  /** broadcast scipDiffParamSet */
155  virtual int bcast(UG::ParaComm *comm, int root) = 0;
156 
157  /** end scipDiffParamSet to the rank */
158  virtual int send(UG::ParaComm *comm, int destination) = 0;
159 
160  /** receive scipDiffParamSet from the source rank */
161  virtual int receive(UG::ParaComm *comm, int source) = 0;
162 
163 #ifdef UG_WITH_ZLIB
164  /** write ScipDiffParamSet */
165  void write(gzstream::ogzstream &out);
166 
167  /** read ScipDiffParamSet */
168  bool read(UG::ParaComm *comm, gzstream::igzstream &in);
169 #endif
170 
171 };
172 
173 }
174 
175 #endif // _SCIP_DIFF_PARAM_SET_H__
virtual int receive(UG::ParaComm *comm, int source)=0
virtual int send(UG::ParaComm *comm, int destination)=0
virtual int bcast(UG::ParaComm *comm, int root)=0
static ScipParaCommTh * comm
Definition: fscip.cpp:73
void setParametersInScip(SCIP *scip)
Defines for UG Framework.
Base class of communicator for UG Framework.
void read(ParaComm *comm, const char *filename)
read ParaParams from file
bool doesContainRealParam(char *string)
Base class of communicator object.
Definition: paraComm.h:101