kangaroo  1.0
the cbls library
function0.hpp
Go to the documentation of this file.
1 
13 #ifndef Function0HppIncluded
14 #define Function0HppIncluded
15 
16 
17 
19 
20 
21 /*
22  Forward Declarations
23 */
24 class Variable; // Variable class
25 
31 class Function : public Expression
32 {
35 
36  public:
37 
38  Serial const FuncSerial;
39 
40  protected:
41 
42  void setFuncSerial(Serial const pSerial);
43  Hash calcExprHash() const;
44  virtual Bool equate(Expression const & that) const override;
45 
47 
50 
51  public:
52 
53  virtual Identifier CareTabuModel() const;
54  virtual Bool CareLockEffect() const;
55  virtual Bool CareFactorSerial() const;
56 
57  protected:
58 
59  virtual TabuBase const * CareTabuInstance() const;
60  virtual void computeTabuEffect();
61  virtual void computeLockEffect();
62 
64 
67 
68  public:
69 
70  virtual ~Function();
71 
72  protected:
73 
74  Function(System * const pSystem, Dim const ParamCount);
75 
76  Function(Function && that) noexcept = delete;
77  Function(Function const & that) = delete;
78  Function & operator = (Function && that) noexcept = delete;
79  Function & operator = (Function const & that) = delete;
80 
82 
85 
86  protected:
87 
88  friend class System;
89  friend class Expression;
90  friend class VarLock;
91  friend class TabuBase;
92 
94 
97 
98  protected:
99 
100  virtual void computeFinal() = 0;
101  virtual void setupComputation();
102 
104 
107 
108  public:
109 
110  Bool ActiveLazyHalfAutoExec() const;
111  void activateLazyHalfAutoExec(Bool const SetNotUnset);
112 
113  #if ComputeLazyHalf
114  protected:
115 
116  Serial RequiredFuncSerial() const;
117  void setRequiredFuncSerial(Serial const RequiredFuncSerial);
118 
119  static void setRequirement(Function * const pFunction);
120  static void unsetRequirement(Function * const pFunction);
121  static void setEnforcement(Function * const pFunction);
122  static void unsetEnforcement(Function * const pFunction);
123 
124  Bool RequiredFunc() const;
125  Bool EnforcedFunc() const;
126  Bool DeferedFunc() const;
127 
128  Dim mRequiredCount;
129  Dim mEnforcedCount;
130  Bool mDeferedNotPrompt;
131  Serial mRequiredFuncSerial;
132 
133  #endif // ComputeLazyHalf
134 
138 
139  protected:
140 
141  virtual void adjustMemAuto() override;
142 
144 
147 
148  protected:
149 
150  virtual void syncExecClock() override;
151  #if ExecDownward
152  virtual void syncExecBatchClock() override;
153  #endif
154  #if SimulDownward
155  virtual void syncSimulBatchClock() override;
156  #endif
157  #if SimulDownwardCache
158  virtual void syncSimulCacheClock();
159  #endif
160 
162 
168 
169  public:
170 
171  kb<Expression *> const ParamExprs;
172  kb<ParamSpecType> const * const ParamSpecs;
173  #if ComputeDownward
174  kb<Serial> const ParamPatrons;
175  #endif
176 
177  xb<Variable *> const FactorVars;
178  nrl< xb<Serial> > const ParamFactors;
179 
180  Serial FuncVarToFactorSerial(Serial const VarSerial) const;
181 
182  protected:
183 
189  class ExprOrder
190  {
191  public:
192  typedef Expression * InputType;
193  static Bool iof(InputType const & Left, InputType const & Right);
194  };
195 
202  {
203  public:
204  typedef t2<Expression *,ParamSpecType> InputType;
205  static Bool iof(InputType const & Left, InputType const & Right);
206  };
207 
208 
209  void setParameters(ParamOrder const pParamOrder, Dim const ParamCount,
210  Expression * const * const pParamExprs,
211  ParamSpecType const * const pParamSpecs = nullptr,
212  Index * const pParamIndexes = nullptr);
213 
214  #if ComputeDownward
215  void setParamPatron(Serial const ParamSerial, Serial const PatronSerial);
216  xrl< xb<Serial> > const mVarUpdatableParams;
217  #endif//ComputeDownward
218 
219  #if ComputeUpward
220  #if UpwardFuncVarToFactorSerialArrayMapNotHash
221  kb<Serial> const * mFuncVarToFactorSerialMap;
222  #else
223  xhmi<Serial,Serial> const mFuncVarToFactorSerialMap;
224  #endif
225  #endif
226  #if ComputeDownward && !ComputeUpward
227  #if DownwardFuncVarToFactorSerialMap == FuncVarToFactorSerialArrayMapAtFunc
228  kb<Serial> const * mFuncVarToFactorSerialMap;
229  #elif DownwardFuncVarToFactorSerialMap == FuncVarToFactorSerialHashMapAtFunc
230  xhmi<Serial,Serial> const mFuncVarToFactorSerialMap;
231  #endif
232  #endif
233 
235  #if ComputeDownward
236 
239  protected:
240 
241  #if ExecDownward
242  Clock mExecBatchClock;
243  #endif
244  #if SimulDownwardFixed
245  Clock mSimulFixedClock;
246  #endif
247  #if SimulDownwardFlexi
248  #if UseOrnamentalFuncFlexiClock
249  Clock mSimulFlexiClock;
250  #endif
251  #endif // SimulDownwardFlexi
252  #if SimulDownwardCache
253  Clock mSimulCacheClock;
254  #endif
255 
256  #if ExecDownward
257  Bool needExecParamComputation();
258  #endif
259  #if SimulDownwardCache
260  Bool needSimulCacheComputation();
261  #endif
262  #if SimulDownwardFixed
263  Bool needSimulFixedParamComputation();
264  #endif
265  #if SimulDownwardFlexi
266  Bool needSimulFlexiParamComputation();
267  #endif
268  #endif
270 
273 
274  public:
275 
276  Index const NestingIndex;
277 
279 
280  #if ComputeUpward
281 
284  protected:
285  #if ExecUpward
286  kll<Serial> mExecChangedParams;
287  void clearExecChangedParams();
288  #endif
289  #if SimulUpward
290  kll<Serial> mSimulChangedParams;
291  void clearSimulChangedParams();
292  #endif
293 
295  #endif //ComputeUpward
296 
297  #if ComputeLazy
298 
301  protected:
302 
303  Bool BacklogExists() const;
304 
305  void performLikelyUndo(Serial const ParamSerial);
306  void performScalarUndo(Serial const ParamSerial);
307  void performVectorUndo(Serial const ParamSerial);
308 
309  virtual void undoScalars(Serial const ParamSerial) = 0;
310  virtual void undoVectors(Serial const ParamSerial) = 0;
311 
312  void setScalarUndoDefined(Bool const SetNotUnset);
313  void setVectorUndoDefined(Bool const SetNotUnset);
314 
315  void setupScalarUndoParams();
316  virtual void setupUndoParams() = 0;
317 
318  #if ComputeLazyHalf
319  virtual void notifyDeferedParams() = 0;
320  virtual void notifyEnforcedParams() = 0;
321  #endif //ComputeLazyHalf
322 
323  kll<Serial> mBacklogParams;
324  klf<Serial> * mScalarUndoneParams;
325 
326  Bool const mScalarUndoDefined;
327  Bool const mVectorUndoDefined;
328 
330  #endif
331 
332  #if ComputeDownward
333 
336  protected:
337 
338  #if ExecDownward
339  void listExecParams();
340  void markExecParams();
341 
342  klf<Serial> mLabelExecParams;
343  xb<Serial> const * mBlockExecParams;
344  #endif//ExecDownward
345 
346  #if SimulDownwardFixed
347  void listSimulFixedParams();
348  void markSimulFixedParams();
349  void enumSimulFixedParams(Bool const MarkNotList);
350 
351  klf<Serial> mLabelSimulFixedParams;
352  xb<Serial> const * mBlockSimulFixedParams;
353  #endif
354 
355  #if SimulDownwardFlexi
356  void setupSimulFlexiLabels();
357  void listSimulFlexiParams();
358  void markSimulFlexiParams();
359  void enumSimulFlexiParams(Bool const MarkNotList);
360 
361  klf<Serial> * mLabelSimulFlexiParams;
362  xb<Serial> const * mBlockSimulFlexiParams;
363  #endif//SimulDownwardFlexi
364 
365  private:
366 
367  static xb<Serial> const * ProxyParamBlock();
368 
369  #if MultiVarExecDownward
370  xb<Serial> * mExecMergeBlock;
371  #endif
372 
373  #if MultiVarFixedSimulDownward
374  xb<Serial> * mSimulFixedMergeBlock;
375  #endif
376  #if MultiVarFlexiSimulDownward
377  xb<Serial> * mSimulFlexiMergeBlock;
378  #endif
379 
381  #endif
382 
385 
386  protected:
387 
388  static Serial defineWithinSystem(Function * const pFunction);
389 
391 
392  void defineRootWithinSystem();
393  Serial RootFuncSerial() const;
394  void setRootFuncSerial(Serial const RootFuncSerial);
395 
397 };
398 
399 
400 typedef Function Func;
401 
402 
404 
405 
406 
407 
408 #endif//Function0HppIncluded
virtual void syncSimulBatchClock()
Synchronize the simulation batch clock.
Definition: expression1.hpp:797
Functions that depend on other expressions.
Definition: function0.hpp:31
virtual void syncExecBatchClock()
Synchronize the execution batch clock.
Definition: expression1.hpp:785
kb< ParamSpecType > const *const ParamSpecs
Parameter specifications i.e. how to use values and metrics.
Definition: function0.hpp:172
virtual ~Function()
Destructor.
Definition: function1.hpp:55
#define openKangarooSpace
Open the project namespace.
Definition: project.hpp:74
virtual void setupComputation()
Set up various things for computation.
Definition: function1.hpp:1098
ParamOrder
Parameter specification ordering.
Definition: parameter.hpp:63
virtual Identifier CareTabuModel() const
Care for any tabu model?
Definition: function1.hpp:1533
xb< Variable * > const FactorVars
Factor variables that this function transitively depends on.
Definition: function0.hpp:177
Variable locking manager.
Definition: varlock0.hpp:36
void setFuncSerial(Serial const pSerial)
Set function serial.
Definition: function1.hpp:39
kb< Expression * > const ParamExprs
Parameter expressions that this function immediately depends on.
Definition: function0.hpp:171
static Serial defineWithinSystem(Function *const pFunction)
Define the function in the system.
Definition: function1.hpp:1619
void setRootFuncSerial(Serial const RootFuncSerial)
Set the root function serial with the system.
Definition: function1.hpp:510
Hash calcExprHash() const
Calculate expression hash value.
Definition: function1.hpp:855
virtual Bool CareFactorSerial() const
Care factor serial?
Definition: function1.hpp:1588
Tabu heuristic base class.
Definition: tabubase0.hpp:40
SizeTypes< sizeof(void *)>::UnsignedType Identifier
Class identifiers.
Definition: datatypes.hpp:349
void setParameters(ParamOrder const pParamOrder, Dim const ParamCount, Expression *const *const pParamExprs, ParamSpecType const *const pParamSpecs=nullptr, Index *const pParamIndexes=nullptr)
Set the parameters, if unordered then expression pointers along with indexes (if given) are sorted...
Definition: function1.hpp:927
Abstract variable class.
Definition: variable0.hpp:86
Serial FuncVarToFactorSerial(Serial const VarSerial) const
Find the factor serial for a given variable serial.
Definition: function1.hpp:1155
static Bool iof(InputType const &Left, InputType const &Right)
Ordering operator.
Definition: function1.hpp:903
Serial const FuncSerial
Unique over all functions.
Definition: function0.hpp:38
Serial mRootFuncSerial
Root function serial in the system.
Definition: function0.hpp:390
Serial RootFuncSerial() const
The root function serial within the system.
Definition: function1.hpp:498
virtual void computeTabuEffect()
Compute the tabu effect upon callback.
Definition: function1.hpp:1544
void defineRootWithinSystem()
Define as a root within the system.
Definition: function1.hpp:1605
Dereferenced order for expressions.
Definition: function0.hpp:201
virtual Bool equate(Expression const &that) const override
Compare expressions for equality.
Definition: function1.hpp:879
virtual TabuBase const * CareTabuInstance() const
Which tabu instance to care for.
Definition: function1.hpp:1555
void activateLazyHalfAutoExec(Bool const SetNotUnset)
Activate auto execution in lazy half mode.
Definition: function1.hpp:155
virtual void computeLockEffect()
Compute the lock effect up on callback.
Definition: function1.hpp:1577
virtual void adjustMemAuto() override
Adjust memory requirement automatically.
Definition: function1.hpp:551
Constraint-based local search systems.
Definition: system0.hpp:45
BitStr ParamSpecType
Parameter specification type.
Definition: parameter.hpp:76
Bool ActiveLazyHalfAutoExec() const
Whether auto execution in lazy half mode is active?
Definition: function1.hpp:138
Index const NestingIndex
Function nesting index; starts from 0.
Definition: function0.hpp:276
virtual void computeFinal()=0
Computation when function is final.
Function(System *const pSystem, Dim const ParamCount)
Param constructor.
Definition: function1.hpp:763
#define closeKangarooSpace
Close the project namespace.
Definition: project.hpp:75
virtual Bool CareLockEffect() const
Care for lock effect?
Definition: function1.hpp:1566
Dereferenced order for expressions.
Definition: function0.hpp:189
virtual void syncExecClock() override
Synchronize the execution clock.
Definition: function1.hpp:304
Abstract expressions.
Definition: expression0.hpp:41
nrl< xb< Serial > > const ParamFactors
Variables that parameters depend on. Factor serial of the function are use to represent parameter var...
Definition: function0.hpp:178