kangaroo  1.0
the cbls library
summationValueScalarOptiSwapToValueFactorVector.hpp
Go to the documentation of this file.
1 
12 #ifndef SummationValueScalarOptiSwapToValueFactorVectorHppIncluded
13 #define SummationValueScalarOptiSwapToValueFactorVectorHppIncluded
14 
15 
16 
18 
19 
20 
22 
23 
24 
39 template <Order MaxiOrMini, typename paramValue, typename value = paramValue,
40  typename paramMetric = paramValue, typename metric = paramMetric>
42 {
43  public:
44 
45  typedef paramValue ParamValueType;
46  typedef paramMetric ParamMetricType;
47  typedef value ValueType;
48  typedef metric MetricType;
49 
52 
55  define(System * const pSystem, Dim const ParamCount, Expression * const * pParamExprs, ParamSpecType * const pParamSpecs=nullptr);
56 
58 
59  private:
60 
63 
65  SummationValueScalarOptiSwapToValueFactorVector(System * const pSystem, Dim const ParamCount,
66  Expression * const * pParamExprs, ParamSpecType * const pParamSpecs);
67 
71  (SummationValueScalarOptiSwapToValueFactorVector<MaxiOrMini,paramValue,value,paramMetric,metric> const & that) = delete;
73  (SummationValueScalarOptiSwapToValueFactorVector<MaxiOrMini,paramValue,value,paramMetric,metric> && that) noexcept = delete;
75  (SummationValueScalarOptiSwapToValueFactorVector<MaxiOrMini,paramValue,value,paramMetric,metric> const & that) = delete;
76 
78 
81 
82  virtual void computeFinal();
83  virtual void executeAnew();
84  virtual void simulateAnew();
85  virtual void executeIncr();
86  virtual void simulateIncr();
87 
88  #if ComputeLazy
89  virtual void executeBacklog();
90  virtual void emulateBacklog();
91  virtual void undoScalars(Serial const ParamSerial);
92  #endif // ComputeLazy
93 
95 
98 
101 
102  kb<ValueRecord<paramValue> const * > mParamExprValueRecords;
103  kb<ScalarRecord<paramMetric> const * > mParamExprScalarRecords;
104  kb< OptiSwap<paramMetric,MetricBuffType> > mParamOptiSwapOperators;
105 
106  #if SimulDownward
107  ValueBuffType cacheSimulValue;
108  #endif//SimulDownward
109 
110  ValueBuffType cacheExecValue;
111 
112  #if ComputeLazy
113  ValueBuffType cacheEmulValue;
114  #endif // ComputeLazy
115 
116  kb<MetricBuffType> * cacheExecVector;
117  kll<Serial> * tempChangedVector;
118 
120 };
121 
122 
123 
127 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
129 {
130  WatchError
131  if (cacheExecVector) delete cacheExecVector;
133  CatchError
134 }
135 
136 
137 
141 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
144  Dim const ParamCount, Expression * const * pParamExprs, ParamSpecType * const pParamSpecs)
145 {
146  WatchError
147  Warn(ParamCount < 2 || ParamCount > MaxDim, kFuncNotRequiredParams);
148 
151 
152  Serial const tFuncSerial = Function::defineWithinSystem(tFunction);
153  if (tFuncSerial != InvalidSerial)
154  return scast<SummationValueScalarOptiSwapToValueFactorVector<MaxiOrMini,paramValue,value,paramMetric,metric> *>(pSystem->LocateFunc(tFuncSerial));
155 
156  tFunction->defineRootWithinSystem();
157  return tFunction;
158 
159  CatchError
160 }
161 
162 
163 
167 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
169  Dim const ParamCount, Expression * const * pParamExprs, ParamSpecType * pParamSpecs) :
170  NaryValueScalarToValueFactorVectorFunc<value,metric>(pSystem, MaxiOrMini, ParamCount), mParamExprValueRecords(ParamCount),
171  mParamExprScalarRecords(ParamCount), mParamOptiSwapOperators(ParamCount)
172  #if SimulDownward
173  , cacheSimulValue()
174  #endif//SimulDownward
175  , cacheExecValue()
176  #if ComputeLazy
177  , cacheEmulValue()
178  #endif // ComputeLazy
179  , cacheExecVector(nullptr)
180  , tempChangedVector(nullptr)
181 {
182  WatchError
184  this->setParameters(UnorderedParams, ParamCount, pParamExprs, pParamSpecs);
185  this->setExprHash(this->calcExprHash());
186  this->defineExprValueRecord();
187  this->defineExprVectorRecord(this->FactorVars.ItemCount());
188  for(Serial tParamSerial = 0; tParamSerial < ParamCount; ++tParamSerial)
189  {
190  this->mParamExprValueRecords[tParamSerial] = getExprValueRecord<paramValue>(this->ParamExprs[tParamSerial]);
191 
192  ParamSpecType tParamSpecType = this->ParamSpecs ? this->ParamSpecs->Item(tParamSerial) : DefaultParam;
193 
194  this->mParamExprScalarRecords[tParamSerial] = getExprScalarRecord<paramMetric>(this->ParamExprs[tParamSerial], MaxiOrMini, tParamSpecType);
195 
196  this->mParamOptiSwapOperators[tParamSerial] = OptiSwap<paramMetric,MetricBuffType>(tParamSpecType);
197  }
198 
199  this->cacheExecVector = new kb<MetricBuffType>(this->FactorVars.ItemCount());
200  this->tempChangedVector = new kll<Serial>(this->FactorVars.ItemCount());
201  CatchError
202 }
203 
204 
205 
206 
210 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
212 {
213  WatchError
214  if (!this->Updatable())
215  {
216  cacheExecValue = 0;
217  for(Serial tFactorSerial = 0; tFactorSerial < this->FactorVars.ItemCount(); ++tFactorSerial)
218  cacheExecVector->Item(tFactorSerial) = 0;
219 
220  for(Serial tParamSerial = 0; tParamSerial < mParamExprValueRecords.ItemCount(); ++tParamSerial)
221  {
222  cacheExecValue += mParamExprValueRecords[tParamSerial]->ExecData();
223 
224  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
225  {
226  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
227  cacheExecVector->Item(tFactorSerial) += mParamOptiSwapOperators[tParamSerial](
228  mParamExprScalarRecords[tParamSerial]->ExecData());
229  }
230  }
231  this->mExprValueRecord->finaliseRecord(tc<ValueBuffType,value>::iof(cacheExecValue));
232  for(Serial tFactorSerial = 0; tFactorSerial < this->FactorVars.ItemCount(); ++tFactorSerial)
233  this->mExprVectorRecord->finaliseField(tFactorSerial, tc<MetricBuffType,metric>::iof(cacheExecVector->Item(tFactorSerial)));
234  }
235  CatchError
236 }
237 
238 
239 
243 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
245 {
246  WatchError
247  cacheExecValue = 0;
248  for(Serial tFactorSerial = 0; tFactorSerial < this->FactorVars.ItemCount(); ++tFactorSerial)
249  cacheExecVector->Item(tFactorSerial) = 0;
250 
251  for(Serial tParamSerial = 0; tParamSerial < mParamExprValueRecords.ItemCount(); ++tParamSerial)
252  {
253  #if ExecDownward
254  Expression::performExecAnew(this->ParamExprs[tParamSerial]);
255  #endif//ExecDownward
256 
257  cacheExecValue += mParamExprValueRecords[tParamSerial]->ExecData();
258 
259  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
260  {
261  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
262  cacheExecVector->Item(tFactorSerial) += mParamOptiSwapOperators[tParamSerial](
263  mParamExprScalarRecords[tParamSerial]->ExecData());
264  }
265  }
266 
267  this->mExprValueRecord->initialiseExecData(tc<ValueBuffType,value>::iof(cacheExecValue));
268  for(Serial tFactorSerial = 0; tFactorSerial < this->FactorVars.ItemCount(); ++tFactorSerial)
269  this->mExprVectorRecord->initialiseExecData(tFactorSerial,tc<MetricBuffType,metric>::iof(cacheExecVector->Item(tFactorSerial)));
270  #if ExecUpwardOrLazyDownward
271  this->runPostExecAnew();
272  #endif
273  CatchError
274 }
275 
276 
277 
281 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
283 {
284  WatchError
285  ValueBuffType tSimulValue = 0;
286  for(Serial tParamSerial = 0; tParamSerial < mParamExprValueRecords.ItemCount(); ++tParamSerial)
287  {
288  #if SimulDownward
289  Expression::performSimulAnew(this->ParamExprs[tParamSerial]);
290  #endif//SimulDownward
291 
292  tSimulValue += mParamExprValueRecords[tParamSerial]->SimulData(this->SysMaster->SimulClock());
293  }
294  this->mExprValueRecord->updateSimulData(this->SysMaster->SimulClock(), tc<ValueBuffType,value>::iof(tSimulValue));
295  #if SimulUpward
296  this->runPostSimulAnew();
297  #endif
298  CatchError
299 }
300 
301 
302 #if ComputeLazy
303 
306 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
308 {
309  WatchError
310  cacheExecValue -= mParamExprValueRecords[ParamSerial]->PrevData(this->SysMaster->ExecClock());
311  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[ParamSerial].ItemCount(); ++tParamFactorSerial)
312  {
313  Serial const tFactorSerial = this->ParamFactors[ParamSerial][tParamFactorSerial];
314  cacheExecVector->Item(tFactorSerial) -= mParamOptiSwapOperators[ParamSerial](
315  mParamExprScalarRecords[ParamSerial]->PrevData(this->SysMaster->ExecClock()));
316  }
317  CatchError
318 }
319 #endif // ComputeLazy
320 
321 
322 
326 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
328 {
329  WatchError
330  #if ExecUpward
331  if (this->mExecChangedParams.TagCount())
332  {
333  tempChangedVector->sweep(this->SysMaster->ExecClock());
334  for(Index tIndex = 0; tIndex < this->mExecChangedParams.TagCount(); ++tIndex)
335  {
336  Serial const tParamSerial = this->mExecChangedParams.TaggedSerial(tIndex);
337 
338  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
339  if (tParamExprValueRecord->PrevDiff(this->SysMaster->ExecClock()))
340  cacheExecValue += tParamExprValueRecord->ExecBuffer() - tParamExprValueRecord->PrevBuffer();
341 
342  if (mParamExprScalarRecords[tParamSerial]->PrevDiff(this->SysMaster->ExecClock()))
343  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
344  {
345  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
346  cacheExecVector->Item(tFactorSerial) +=
347  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecBuffer()) -
348  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->PrevBuffer());
349  tempChangedVector->tagBool(tFactorSerial);
350  }
351  }
352  this->mExprValueRecord->updateExecData(this->SysMaster->ExecClock(), tc<ValueBuffType,value>::iof(cacheExecValue));
353 
355  for(Index tIndex = 0; tIndex < tempChangedVector->TagCount(); ++tIndex)
356  {
357  Serial const tFactorSerial = tempChangedVector->TaggedSerial(tIndex);
358  this->mExprVectorRecord->updateExecData(tFactorSerial, this->SysMaster->ExecClock(),
359  tc<MetricBuffType,value>::iof(cacheExecVector->Item(tFactorSerial)));
360  }
361  this->runPostExecIncr();
362  }
363  #endif//ExecUpward
364  #if ExecDownward
365 
366  #if ComputeLazy
367  if (!this->BacklogExists())
368  {
369  #endif // ComputeLazy
370 
371  if (this->needExecParamComputation()) this->listExecParams();
372  if (this->mBlockExecParams->ItemCount())
373  {
374 
375  tempChangedVector->sweep(this->SysMaster->ExecClock());
376  for(Index tIndex = 0; tIndex < this->mBlockExecParams->ItemCount(); ++tIndex)
377  {
378  Serial const tParamSerial = this->mBlockExecParams->Item(tIndex);
379  Expression::performExecIncr(this->ParamExprs[tParamSerial]);
380  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
381  if (tParamExprValueRecord->PrevDiff(this->SysMaster->ExecClock()))
382  cacheExecValue += tParamExprValueRecord->ExecBuffer() - tParamExprValueRecord->PrevBuffer();
383 
384  if (mParamExprScalarRecords[tParamSerial]->PrevDiff(this->SysMaster->ExecClock()))
385  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
386  {
387  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
388  cacheExecVector->Item(tFactorSerial) +=
389  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecBuffer()) -
390  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->PrevBuffer());
391  tempChangedVector->tagBool(tFactorSerial);
392  }
393  }
394  this->mExprValueRecord->updateExecData(this->SysMaster->ExecClock(), tc<ValueBuffType,value>::iof(cacheExecValue));
395 
397  for(Index tIndex = 0; tIndex < tempChangedVector->TagCount(); ++tIndex)
398  {
399  Serial const tFactorSerial = tempChangedVector->TaggedSerial(tIndex);
400  this->mExprVectorRecord->updateExecData(tFactorSerial,this->SysMaster->ExecClock(),
401  tc<MetricBuffType,metric>::iof(cacheExecVector->Item(tFactorSerial)));
402  }
403  }
404  #if ComputeLazy
405  }
406  else
407  {
408  if (this->needExecParamComputation()) this->markExecParams();
409  tempChangedVector->sweep(this->SysMaster->ExecClock());
410  for(Index tIndex = 0; tIndex < this->mBlockExecParams->ItemCount(); ++tIndex)
411  {
412  Serial const tParamSerial = this->mBlockExecParams->Item(tIndex);
413  Expression::performExecIncr(this->ParamExprs[tParamSerial]);
414  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
415 
416  if (this->mScalarUndoneParams->Tagged(tParamSerial))
417  {
418  cacheExecValue += tParamExprValueRecord->ExecData();
419  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
420  {
421  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
422  cacheExecVector->Item(tFactorSerial) +=
423  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecData());
424  tempChangedVector->tagBool(tFactorSerial);
425  }
426  }
427  else
428  {
429  if (tParamExprValueRecord->PrevDiff(this->SysMaster->ExecClock()))
430  cacheExecValue += tParamExprValueRecord->ExecBuffer() - tParamExprValueRecord->PrevBuffer();
431  if (mParamExprScalarRecords[tParamSerial]->PrevDiff(this->SysMaster->ExecClock()))
432  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
433  {
434  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
435  cacheExecVector->Item(tFactorSerial) +=
436  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecBuffer()) -
437  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->PrevBuffer());
438  tempChangedVector->tagBool(tFactorSerial);
439  }
440  }
441  }
442 
443  for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
444  {
445  Serial const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
446  if (this->mLabelExecParams.Tagged(tParamSerial)) continue;
447  Expression::performExecBacklog(this->ParamExprs[tParamSerial]);
448  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
449 
450  if (this->mScalarUndoneParams->Tagged(tParamSerial))
451  {
452  cacheExecValue += tParamExprValueRecord->ExecData();
453  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
454  {
455  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
456  cacheExecVector->Item(tFactorSerial) +=
457  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecData());
458  tempChangedVector->tagBool(tFactorSerial);
459  }
460  }
461  else
462  {
463  if (tParamExprValueRecord->PrevDiff(this->SysMaster->ExecClock()))
464  cacheExecValue += tParamExprValueRecord->ExecBuffer() - tParamExprValueRecord->PrevBuffer();
465  if (mParamExprScalarRecords[tParamSerial]->PrevDiff(this->SysMaster->ExecClock()))
466  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
467  {
468  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
469  cacheExecVector->Item(tFactorSerial) +=
470  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecBuffer()) -
471  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->PrevBuffer());
472  tempChangedVector->tagBool(tFactorSerial);
473  }
474  }
475  }
476 
477  this->mExprValueRecord->updateExecData(this->SysMaster->ExecClock(), tc<ValueBuffType,value>::iof(cacheExecValue));
479  for(Index tIndex = 0; tIndex < tempChangedVector->TagCount(); ++tIndex)
480  {
481  Serial const tFactorSerial = tempChangedVector->TaggedSerial(tIndex);
482  this->mExprVectorRecord->updateExecData(tFactorSerial, this->SysMaster->ExecClock(),
483  tc<MetricBuffType,metric>::iof(cacheExecVector->Item(tFactorSerial)));
484  }
485  }
486  this->runPostExecIncr();
487  #endif // ComputeLazy
488  #endif//ExecDownward
489  CatchError
490 }
491 
492 
493 #if ComputeLazy
494 
497 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
499 {
500  WatchError
501  for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
502  {
503  Serial const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
504  Expression::performExecBacklog(this->ParamExprs[tParamSerial]);
505  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
506 
507  if (this->mScalarUndoneParams->Tagged(tParamSerial))
508  {
509  cacheExecValue += tParamExprValueRecord->ExecData();
510  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
511  {
512  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
513  cacheExecVector->Item(tFactorSerial) +=
514  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecData());
515  tempChangedVector->tagBool(tFactorSerial);
516  }
517  }
518  else
519  {
520  if (tParamExprValueRecord->PrevDiff(this->SysMaster->ExecClock()))
521  cacheExecValue += tParamExprValueRecord->ExecBuffer() - tParamExprValueRecord->PrevBuffer();
522  if (mParamExprScalarRecords[tParamSerial]->PrevDiff(this->SysMaster->ExecClock()))
523  for(Serial tParamFactorSerial = 0; tParamFactorSerial < this->ParamFactors[tParamSerial].ItemCount(); ++tParamFactorSerial)
524  {
525  Serial const tFactorSerial = this->ParamFactors[tParamSerial][tParamFactorSerial];
526  cacheExecVector->Item(tFactorSerial) +=
527  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->ExecBuffer()) -
528  mParamOptiSwapOperators[tParamSerial](mParamExprScalarRecords[tParamSerial]->PrevBuffer());
529  tempChangedVector->tagBool(tFactorSerial);
530  }
531  }
532  }
533 
534  this->mExprValueRecord->updateExecData(this->SysMaster->ExecClock(), tc<ValueBuffType,value>::iof(cacheExecValue));
536  for(Index tIndex = 0; tIndex < tempChangedVector->TagCount(); ++tIndex)
537  {
538  Serial const tFactorSerial = tempChangedVector->TaggedSerial(tIndex);
539  this->mExprVectorRecord->updateExecData(tFactorSerial, this->SysMaster->ExecClock(),
540  tc<MetricBuffType,metric>::iof(cacheExecVector->Item(tFactorSerial)));
541  }
542  this->runPostExecBacklog();
543  CatchError
544 }
545 #endif // ComputeLazy
546 
547 
548 
552 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
554 {
555  WatchError
556  #if SimulUpward
557  if (this->mSimulChangedParams.TagCount())
558  {
559  ValueBuffType tSimulValue = cacheExecValue;
560  for(Index tIndex = 0; tIndex < this->mSimulChangedParams.TagCount(); ++tIndex)
561  {
562  Serial const tParamSerial = this->mSimulChangedParams.TaggedSerial(tIndex);
563  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
564  if (tParamExprValueRecord->SimulDiff(this->SysMaster->SimulClock()))
565  tSimulValue += tParamExprValueRecord->SimulBuffer() - tParamExprValueRecord->ExecBuffer();
566  }
567  this->mExprValueRecord->updateSimulData(this->SysMaster->SimulClock(), tc<ValueBuffType,value>::iof(tSimulValue));
568  this->runPostSimulIncr();
569  }
570  #endif //SimulUpward
571  #if SimulDownward
572  #if ComputeLazy
573  if (!this->BacklogExists())
574  {
575  #endif // ComputeLazy
576  #if SimulFlexi
577  if (this->needSimulFlexiParamComputation()) this->listSimulFlexiParams();
578  #endif
579  #if SimulFixedFlexi
580  if (this->needSimulFixedParamComputation())
581  this->enumSimulFixedParams(this->mBlockSimulFlexiParams->ItemCount());
582  #elif SimulFixedOnly
583  if (this->needSimulFixedParamComputation()) this->listSimulFixedParams();
584  #endif
585 
586  #if SimulFixed
587  if (this->needSimulCacheComputation())
588  {
589  cacheSimulValue = cacheExecValue;
590  for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
591  {
592  Serial const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
593  cacheSimulValue -= mParamExprValueRecords[tParamSerial]->ExecData();
594  }
595  }
596  #endif//SimulFixed
597 
598  #if SimulFixedFlexi
599  if (this->mBlockSimulFixedParams->ItemCount() || this->mBlockSimulFlexiParams->ItemCount())
600  #elif SimulFixedOnly
601  if (this->mBlockSimulFixedParams->ItemCount())
602  #elif SimulFlexiOnly
603  if (this->mBlockSimulFlexiParams->ItemCount())
604  #endif
605  {
606  #if SimulFixed
607  ValueBuffType tSimulValue = cacheSimulValue;
608  #else
609  ValueBuffType tSimulValue = cacheExecValue;
610  #endif
611 
612  #if SimulFixed
613  for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
614  {
615  Serial const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
616  Expression::performSimulIncr(this->ParamExprs[tParamSerial]);
617  tSimulValue += mParamExprValueRecords[tParamSerial]->SimulData(this->SysMaster->SimulClock()); //not SimulBuffer!
618  }
619  #endif//SimulFixed
620 
621  #if SimulFlexi
622  for(Index tIndex = 0; tIndex < this->mBlockSimulFlexiParams->ItemCount(); ++tIndex)
623  {
624  Serial const tParamSerial = this->mBlockSimulFlexiParams->Item(tIndex);
625  #if SimulFixed
626  if (this->mLabelSimulFixedParams.Tagged(tParamSerial)) continue;
627  #endif
628  Expression::performSimulIncr(this->ParamExprs[tParamSerial]);
629 
630  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
631  if (tParamExprValueRecord->SimulDiff(this->SysMaster->SimulClock()))
632  tSimulValue += tParamExprValueRecord->SimulBuffer() - tParamExprValueRecord->ExecBuffer();
633  }
634  #endif //SimulFlexi
635 
636  this->mExprValueRecord->updateSimulData(this->SysMaster->SimulClock(), tc<ValueBuffType,value>::iof(tSimulValue));
637  }
638  #if ComputeLazy
639  }
640  else // defered
641  {
642  #if SimulFlexi
643  if (this->needSimulFlexiParamComputation()) this->listSimulFlexiParams();
644  #endif
645  #if SimulFixed
646  if (this->needSimulFixedParamComputation()) this->markSimulFixedParams();
647  #endif
648 
649  if (this->needSimulCacheComputation())
650  {
651  if (!this->ChangedSystemEmulClock())
652  {
653  cacheSimulValue = cacheEmulValue;
654  #if SimulFixed
655  for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
656  {
657  Serial const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
658  cacheSimulValue -= mParamExprValueRecords[tParamSerial]->EmulData(this->SysMaster->EmulClock());
659  }
660  #endif //SimulFixed
661  }
662  else
663  {
664  cacheSimulValue = cacheExecValue;
665  #if SimulFixed
666  for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
667  {
668  Serial const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
669  if (!this->mScalarUndoneParams->Tagged(tParamSerial))
670  cacheSimulValue -= mParamExprValueRecords[tParamSerial]->ExecData();
671  }
672  #endif //SimulFixed
673  for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
674  {
675  Serial const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
676  #if SimulFixed
677  if (this->mLabelSimulFixedParams.Tagged(tParamSerial)) continue;
678  #endif //SimulFixed
679  Expression::performEmulBacklog(this->ParamExprs[tParamSerial]);
680  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
681 
682  if (this->mScalarUndoneParams->Tagged(tParamSerial))
683  cacheSimulValue += tParamExprValueRecord->EmulData(this->SysMaster->EmulClock()); // emulation data, not buff.
684  else if (tParamExprValueRecord->EmulDiff(this->SysMaster->EmulClock()))
685  cacheSimulValue += tParamExprValueRecord->EmulBuffer() - tParamExprValueRecord->ExecBuffer();
686  }
687  }
688  }
689 
690  ValueBuffType tSimulValue = cacheSimulValue;
691 
692  #if SimulFixed
693  for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
694  {
695  Serial const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
696  Expression::performSimulIncr(this->ParamExprs[tParamSerial]);
697  tSimulValue += mParamExprValueRecords[tParamSerial]->SimulData(this->SysMaster->SimulClock()); //not SimulBuffer!
698  }
699  #endif//SimulFixed
700 
701  #if SimulFlexi
702  for(Index tIndex = 0; tIndex < this->mBlockSimulFlexiParams->ItemCount(); ++tIndex)
703  {
704  Serial const tParamSerial = this->mBlockSimulFlexiParams->Item(tIndex);
705 
706  #if SimulFixed
707  if (this->mLabelSimulFixedParams.Tagged(tParamSerial)) continue;
708  #endif
709 
710  Expression::performEmulBacklog(this->ParamExprs[tParamSerial]);
711  Expression::performSimulIncr(this->ParamExprs[tParamSerial]);
712  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
713  if (tParamExprValueRecord->EmulSimulDiff(this->SysMaster->EmulClock(), this->SysMaster->SimulClock()))
714  tSimulValue += tParamExprValueRecord->SimulData(this->SysMaster->SimulClock()) -
715  tParamExprValueRecord->EmulData(this->SysMaster->EmulClock());
716  }
717  #endif
718  this->mExprValueRecord->updateSimulData(this->SysMaster->SimulClock(), tc<ValueBuffType,value>::iof(tSimulValue));
719  }
720  #endif // ComputeLazy
721  #endif//SimulDownward
722  CatchError
723 }
724 
725 
726 
727 #if ComputeLazy
728 
731 template <Order MaxiOrMini, typename paramValue, typename value, typename paramMetric, typename metric>
733 {
734  WatchError
735  cacheEmulValue = cacheExecValue;
736  for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
737  {
738  Serial const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
739  Expression::performEmulBacklog(this->ParamExprs[tParamSerial]);
740  ValueRecord<paramValue> const * tParamExprValueRecord = mParamExprValueRecords[tParamSerial];
741 
742  if (this->mScalarUndoneParams->Tagged(tParamSerial))
743  cacheEmulValue += tParamExprValueRecord->EmulData(this->SysMaster->EmulClock());
744  else if (tParamExprValueRecord->EmulDiff(this->SysMaster->EmulClock()))
745  cacheEmulValue += tParamExprValueRecord->EmulBuffer() - tParamExprValueRecord->ExecBuffer();
746  }
747  this->mExprValueRecord->updateEmulData(this->SysMaster->EmulClock(), tc<ValueBuffType,value>::iof(cacheEmulValue));
748  CatchError
749 }
750 #endif // ComputeLazy
751 
753 
754 
755 #endif//SummationValueScalarOptiSwapToValueFactorVectorHppIncluded
void updateExecData(Clock const ExecClock, data const &Data)
Update the execution data.
Definition: scalarrecord.hpp:228
static void performExecIncr(Expression *const pExpression)
Execute in incremental mode.
Definition: expression1.hpp:287
Order
Orders.
Definition: datatypes.hpp:156
void setExprHash(Hash const pHash)
Set expression hash value.
Definition: expression1.hpp:607
kll< Serial > * tempChangedVector
Vector that undergone changes.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:117
Bool Updatable() const
Whether the expression updatable—variables are updatable, functions may be updatable.
Definition: expression1.hpp:44
Clock SimulClock() const
Get the simulation clock.
Definition: system1.hpp:249
#define SimulFlexiOnly
Use flexi simulation only, not fixed one.
Definition: options.hpp:166
DataTempBuff< paramValue, value >::Type ValueBuffType
Value buff type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:99
kb< ParamSpecType > const *const ParamSpecs
Parameter specifications i.e. how to use values and metrics.
Definition: function0.hpp:172
SummationValueScalarOptiSwapToValueFactorVector(System *const pSystem, Dim const ParamCount, Expression *const *pParamExprs, ParamSpecType *const pParamSpecs)
Param constructor.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:168
void finaliseField(Serial const FieldSerial, data const &Data)
Finalise the field particularly for unupdatable expressions.
Definition: vectorrecord.hpp:324
ValueRecord< value > * mExprValueRecord
Point to the value record.
Definition: valueVectorFunction.hpp:81
#define openKangarooSpace
Open the project namespace.
Definition: project.hpp:74
xb< Variable * > const FactorVars
Factor variables that this function transitively depends on.
Definition: function0.hpp:177
void updateSimulData(Clock const SimulClock, data const &Data)
Update the simulation data.
Definition: valuerecord.hpp:299
value ValueType
Value type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:47
constexpr char const * kFuncNotRequiredParams
Function does not have required parameters.
Definition: messages.hpp:247
void initialiseExecData(data const &Data)
Initialise the execution data.
Definition: scalarrecord.hpp:214
ValueBuffType cacheExecValue
Execution cache value.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:110
Bool SimulDiff(Clock const SimulClock) const
SimulDiff = (SimulClock == SimulClock).
Definition: valuerecord.hpp:420
Bool PrevDiff(Clock const ExecClock) const
PrevDiff = (PrevClock == ExecClock).
Definition: scalarrecord.hpp:313
kb< ScalarRecord< paramMetric > const * > mParamExprScalarRecords
Parameter expresion scalar records.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:103
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
kb< ValueRecord< paramValue > const * > mParamExprValueRecords
Parameter expression value records.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:102
Hash calcExprHash() const
Calculate expression hash value.
Definition: function1.hpp:855
Compatible temporary buffer type for two given data types.
Definition: datatypes.hpp:294
Use default parameter option which is just null.
Definition: parameter.hpp:32
virtual void simulateAnew()
Simulate the expression.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:282
~SummationValueScalarOptiSwapToValueFactorVector()
Destructor.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:128
data const & SimulBuffer() const
Return simulation buffer; validity depends on SimulDiff.
Definition: valuerecord.hpp:365
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
data const & ExecData() const
Return execution data in execution buffer.
Definition: scalarrecord.hpp:287
void initialiseExecData(Serial const FieldSerial, data const &Data)
Initialise the execution buffer, particularly for anew execution.
Definition: vectorrecord.hpp:336
void setExprFormat(Identifier const pFormat)
Set expression format.
Definition: expression1.hpp:577
#define ComputeLazy
Perform lazy computation.
Definition: options.hpp:112
Summation value scalar optimisation swap to value factor vector.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:41
void finaliseRecord(data const &Data)
Finalise the record.
Definition: valuerecord.hpp:262
static void performExecAnew(Expression *const pExpression)
Execute in anew mode.
Definition: expression1.hpp:271
data const & PrevBuffer() const
Return previous data in previous buffer: validity depends on PrevDiff.
Definition: scalarrecord.hpp:339
paramValue ParamValueType
Parameter value type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:45
void defineExprValueRecord()
Define expression value.
Unique identifier of a class.
void defineRootWithinSystem()
Define as a root within the system.
Definition: function1.hpp:1605
kb< MetricBuffType > * cacheExecVector
Execution cache vector.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:116
DataTempBuff< paramMetric, metric >::Type MetricBuffType
Metric buff type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:100
Clock ExecClock() const
Get the execution clock.
Definition: system1.hpp:237
Bool updateExecData(Serial const FieldSerial, Clock const ExecClock, data const &Data)
Update the execution buffer and insert into previous fields if needed.
Definition: vectorrecord.hpp:348
#define SimulDownward
Perform simulation downward.
Definition: options.hpp:114
void defineExprVectorRecord(Dim const FieldCount)
Define vector record.
void resetPrevSerials(Clock const ExecClock)
Reset the list of fields having previous data.
Definition: vectorrecord.hpp:309
Unordered parameters.
Definition: parameter.hpp:66
virtual void executeIncr()
Execute the expression.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:327
static void performSimulIncr(Expression *const pExpression)
Simulate in incremental mode.
Definition: expression1.hpp:326
data const & ExecBuffer() const
Return execution data in execution buffer.
Definition: scalarrecord.hpp:326
Constraint-based local search systems.
Definition: system0.hpp:45
BitStr ParamSpecType
Parameter specification type.
Definition: parameter.hpp:76
kb< OptiSwap< paramMetric, MetricBuffType > > mParamOptiSwapOperators
Parameter optimisation swap operators.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:104
System *const SysMaster
The system that contains this expression.
Definition: expression0.hpp:281
Flexible arity value and scalar to value and vector function.
void Type
Temporary buffer type.
Definition: datatypes.hpp:297
paramMetric ParamMetricType
Parameter metric type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:46
#define SimulFixedOnly
Use fixed simulation only, not flexi one.
Definition: options.hpp:165
virtual void computeFinal()
Compute the expression.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:211
#define closeKangarooSpace
Close the project namespace.
Definition: project.hpp:75
virtual void simulateIncr()
Simulate the expression.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:553
virtual void executeAnew()
Execute the expression.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:244
metric MetricType
Metric type.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:48
VectorRecord< metric > * mExprVectorRecord
Point to the vector record.
Definition: valueVectorFunction.hpp:82
data const & SimulData(Clock const SimulClock) const
SimulDiff ? SimulBuffer : ExecBuffer().
Definition: valuerecord.hpp:408
Optimisation swap operator that is used if maxi and mini are swapped or vice versa.
Definition: optiswap.hpp:33
Abstract expressions.
Definition: expression0.hpp:41
Value records store expression values.
Definition: valuerecord.hpp:32
static void performSimulAnew(Expression *const pExpression)
Simulate in anew mode.
Definition: expression1.hpp:310
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
Flexible arity value and scalar to value and vector functions.
Definition: naryValueScalarToValueFactorVectorFunc.hpp:30
static SummationValueScalarOptiSwapToValueFactorVector< MaxiOrMini, paramValue, value, paramMetric, metric > * define(System *const pSystem, Dim const ParamCount, Expression *const *pParamExprs, ParamSpecType *const pParamSpecs=nullptr)
Define a summation of value scalar to value factor vector with optimisation swapping.
Definition: summationValueScalarOptiSwapToValueFactorVector.hpp:143