12 #ifndef AllDifferentViolationValueToValueHppIncluded 13 #define AllDifferentViolationValueToValueHppIncluded 35 template <
typename paramValue,
typename value = paramValue>
58 Dim
const ParamCount,
Expression *
const * pParamExprs);
77 #if SimulDownwardCache 78 virtual void syncSimulCacheClock() override final;
93 virtual void executeBacklog() override final;
94 virtual
void emulateBacklog() override final;
95 virtual
void undoScalars(Serial const ParamSerial) override final;
105 #if SimulDownwardCache 106 Int cacheSimulateValue;
107 #endif//SimulDownward 112 Int cacheEmulateValue;
113 #endif // ComputeLazy 129 nhsc<paramValue> cacheEmulParamValues;
130 kb<Dim> cacheEmulValueFreqs;
133 #if SimulDownwardCache 135 nhsc<paramValue> cacheSimulParamValues;
136 kb<Dim> cacheSimulValueFreqs;
144 template <
typename paramValue,
typename value>
154 template <
typename paramValue,
typename value>
166 template <
typename paramValue,
typename value>
178 if (tFuncSerial != InvalidSerial)
179 return scast<AllDifferentViolationValueToValue<paramValue,value> *>(pSystem->LocateFunc(tFuncSerial));
191 template <
typename paramValue,
typename value>
195 #if SimulDownwardCache 196 , cacheSimulateValue()
200 , cacheEmulateValue()
207 , cacheEmulParamValues(ParamCount), cacheEmulValueFreqs(cacheEmulParamValues.SlotCount())
210 , cacheSimulParamValues(ParamCount), cacheSimulValueFreqs(cacheSimulParamValues.SlotCount())
218 for(Serial tParamSerial = 0; tParamSerial < ParamCount; ++tParamSerial)
228 template <
typename paramValue,
typename value>
234 for(Serial tParamSerial = 1; tParamSerial < this->
ParamExprs.ItemCount(); ++tParamSerial)
246 Index tExecValueIndex;
268 template <
typename paramValue,
typename value>
281 Index tExecValueIndex;
296 #if ExecUpwardOrLazyDownward 297 this->runPostExecAnew();
307 template <
typename paramValue,
typename value>
317 #endif//SimulDownward 324 this->runPostSimulAnew();
335 template <
typename paramValue,
typename value>
348 #endif // ComputeLazy 355 template <
typename paramValue,
typename value>
360 if (this->mExecChangedParams.TagCount())
362 for(Index tIndex = 0; tIndex < this->mExecChangedParams.TagCount(); ++tIndex)
364 Serial
const tParamSerial = this->mExecChangedParams.TaggedSerial(tIndex);
366 if (tParamExprValueRecord->
PrevDiff(this->SysMaster->ExecClock()))
403 this->runPostExecIncr();
408 if (!this->BacklogExists())
410 #endif // ComputeLazy 411 if (this->needExecParamComputation()) this->listExecParams();
412 if (this->mBlockExecParams->ItemCount())
414 for(Index tIndex = 0; tIndex < this->mBlockExecParams->ItemCount(); ++tIndex)
416 Serial
const tParamSerial = this->mBlockExecParams->Item(tIndex);
419 if (tParamExprValueRecord->
PrevDiff(this->SysMaster->ExecClock()))
459 if (this->needExecParamComputation()) this->markExecParams();
460 for(Index tIndex = 0; tIndex < this->mBlockExecParams->ItemCount(); ++tIndex)
462 Serial
const tParamSerial = this->mBlockExecParams->Item(tIndex);
466 if (this->mScalarUndoneParams->Tagged(tParamSerial))
469 Index tParamValIndex;
482 else if (tParamExprValueRecord->
PrevDiff(this->SysMaster->ExecClock()))
507 for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
509 Serial
const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
510 if (this->mLabelExecParams.Tagged(tParamSerial))
continue;
512 Expression::performExecBacklog(this->
ParamExprs[tParamSerial]);
515 if (this->mScalarUndoneParams->Tagged(tParamSerial))
518 Index tParamValIndex;
532 else if (tParamExprValueRecord->
PrevDiff(this->SysMaster->ExecClock()))
567 this->runPostExecIncr();
568 #endif // ComputeLazy 579 template <
typename paramValue,
typename value>
583 for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
585 Serial
const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
587 Expression::performExecBacklog(this->
ParamExprs[tParamSerial]);
590 if (this->mScalarUndoneParams->Tagged(tParamSerial))
593 Index tParamValIndex;
607 else if (tParamExprValueRecord->
PrevDiff(this->SysMaster->ExecClock()))
643 this->runPostExecBacklog();
646 #endif // ComputeLazy 653 template <
typename paramValue,
typename value>
658 if (this->mSimulChangedParams.TagCount())
662 for(Index tIndex = 0; tIndex < this->mSimulChangedParams.TagCount(); ++tIndex)
664 Serial
const tParamSerial = this->mSimulChangedParams.TaggedSerial(tIndex);
666 if (tParamExprValueRecord->
SimulDiff(this->SysMaster->SimulClock()))
692 this->runPostSimulIncr();
697 if (!this->BacklogExists())
699 #endif // ComputeLazy 701 if (this->needSimulFlexiParamComputation()) this->listSimulFlexiParams();
704 if (this->needSimulFixedParamComputation())
705 this->enumSimulFixedParams(this->mBlockSimulFlexiParams->ItemCount());
707 if (this->needSimulFixedParamComputation()) this->listSimulFixedParams();
711 if (this->needSimulCacheComputation())
714 cacheSimulParamValues.clear(this->
SysMaster->SimulCacheClock());
715 for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
718 Serial
const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
720 if (cacheSimulParamValues.insertBool(tParamExecValue, tSimulIndex))
725 --cacheSimulValueFreqs[tSimulIndex];
726 if (!cacheSimulValueFreqs[tSimulIndex]) ++cacheSimulateValue;
732 if (this->mBlockSimulFixedParams->ItemCount() || this->mBlockSimulFlexiParams->ItemCount())
734 if (this->mBlockSimulFixedParams->ItemCount())
736 if (this->mBlockSimulFlexiParams->ItemCount())
742 Int tSimulValue = cacheSimulateValue;
747 for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
749 Serial
const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
756 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamSimulValue);
757 if (tSimulCacheIndex != InvalidIndex)
773 for(Index tIndex = 0; tIndex < this->mBlockSimulFlexiParams->ItemCount(); ++tIndex)
775 Serial
const tParamSerial = this->mBlockSimulFlexiParams->Item(tIndex);
777 if (this->mLabelSimulFixedParams.Tagged(tParamSerial))
continue;
781 if (tParamExprValueRecord->
SimulDiff(this->SysMaster->SimulClock()))
789 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamExecValue);
790 if (tSimulCacheIndex != InvalidIndex)
807 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamSimulValue);
808 if (tSimulCacheIndex != InvalidIndex)
830 if (this->needSimulFlexiParamComputation()) this->listSimulFlexiParams();
833 if (this->needSimulFixedParamComputation()) this->markSimulFixedParams();
836 if (this->needSimulCacheComputation())
838 cacheSimulParamValues.clear(this->
SysMaster->SimulCacheClock());
839 if (!this->ChangedSystemEmulClock())
841 cacheSimulateValue = cacheEmulateValue;
843 for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
845 Serial
const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
848 paramValue
const & tParamEmulValue =
850 if (cacheSimulParamValues.insertBool(tParamEmulValue, tSimulIndex))
852 Index tEmulIndex = cacheEmulParamValues.KeyIndex(tParamEmulValue);
853 if (tEmulIndex != InvalidIndex)
854 cacheSimulValueFreqs[tSimulIndex] = cacheEmulValueFreqs[tEmulIndex];
861 --cacheSimulValueFreqs[tSimulIndex];
862 if (!cacheSimulValueFreqs[tSimulIndex]) ++cacheSimulateValue;
870 for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
872 Serial
const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
873 if (!this->mScalarUndoneParams->Tagged(tParamSerial))
877 if (cacheSimulParamValues.insertBool(tParamExecValue, tSimulIndex))
882 --cacheSimulValueFreqs[tSimulIndex];
883 if (!cacheSimulValueFreqs[tSimulIndex]) ++cacheSimulateValue;
887 for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
889 Serial
const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
891 if (this->mLabelSimulFixedParams.Tagged(tParamSerial))
continue;
893 Expression::performEmulBacklog(this->
ParamExprs[tParamSerial]);
897 if (this->mScalarUndoneParams->Tagged(tParamSerial))
900 paramValue
const & tParamEmulValue =
901 tParamExprValueRecord->EmulData(this->
SysMaster->EmulClock());
902 if (cacheSimulParamValues.insertBool(tParamEmulValue, tSimulIndex))
905 if (tExecIndex == InvalidIndex) cacheSimulValueFreqs[tSimulIndex] = 0;
908 if (!cacheSimulValueFreqs[tSimulIndex]) --cacheSimulateValue;
909 ++cacheSimulValueFreqs[tSimulIndex];
911 else if (tParamExprValueRecord->EmulDiff(this->SysMaster->EmulClock()))
916 if (cacheSimulParamValues.insertBool(tParamExecValue, tSimulIndex))
921 --cacheSimulValueFreqs[tSimulIndex];
922 if (!cacheSimulValueFreqs[tSimulIndex]) ++cacheSimulateValue;
926 if (cacheSimulParamValues.insertBool(tParamEmulValue, tSimulIndex))
929 if (tExecIndex == InvalidIndex) cacheSimulValueFreqs[tSimulIndex] = 0;
932 if (!cacheSimulValueFreqs[tSimulIndex]) --cacheSimulateValue;
933 ++cacheSimulValueFreqs[tSimulIndex];
940 Int tSimulValue = cacheSimulateValue;
943 for(Index tIndex = 0; tIndex < this->mBlockSimulFixedParams->ItemCount(); ++tIndex)
945 Serial
const tParamSerial = this->mBlockSimulFixedParams->Item(tIndex);
949 paramValue
const & tParamSimulValue =
953 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamSimulValue);
954 if (tSimulCacheIndex != InvalidIndex)
958 Index tEmulIndex = InvalidIndex;
959 if (!this->ChangedSystemEmulClock())
961 tEmulIndex = cacheEmulParamValues.KeyIndex(tParamSimulValue);
962 if (tEmulIndex != InvalidIndex)
965 if (tEmulIndex == InvalidIndex)
979 for(Index tIndex = 0; tIndex < this->mBlockSimulFlexiParams->ItemCount(); ++tIndex)
981 Serial
const tParamSerial = this->mBlockSimulFlexiParams->Item(tIndex);
984 if (this->mLabelSimulFixedParams.Tagged(tParamSerial))
continue;
987 Expression::performEmulBacklog(this->
ParamExprs[tParamSerial]);
991 if (tParamExprValueRecord->EmulSimulDiff(this->SysMaster->EmulClock(), this->
SysMaster->
SimulClock()))
994 tParamExprValueRecord->EmulData(this->SysMaster->EmulClock());
998 paramValue
const & tParamEmulValue =
999 tParamExprValueRecord->EmulData(this->
SysMaster->EmulClock());
1002 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamEmulValue);
1003 if (tSimulCacheIndex != InvalidIndex)
1007 Index tEmulIndex = InvalidIndex;
1008 if (!this->ChangedSystemEmulClock())
1010 tEmulIndex = cacheEmulParamValues.KeyIndex(tParamEmulValue);
1011 if (tEmulIndex != InvalidIndex)
1014 if (tEmulIndex == InvalidIndex)
1025 paramValue
const & tParamSimulValue =
1029 Index tSimulCacheIndex = cacheSimulParamValues.KeyIndex(tParamSimulValue);
1030 if (tSimulCacheIndex != InvalidIndex)
1034 Index tEmulIndex = InvalidIndex;
1035 if (!this->ChangedSystemEmulClock())
1037 tEmulIndex = cacheEmulParamValues.KeyIndex(tParamSimulValue);
1038 if (tEmulIndex != InvalidIndex)
1041 if (tEmulIndex == InvalidIndex)
1056 #endif // ComputeLazy 1057 #endif//SimulDownward 1067 template <
typename paramValue,
typename value>
1072 cacheEmulParamValues.clear(this->
SysMaster->EmulClock());
1073 for(Index tIndex = 0; tIndex < this->mBacklogParams.TagCount(); ++tIndex)
1075 Serial
const tParamSerial = this->mBacklogParams.TaggedSerial(tIndex);
1076 Expression::performEmulBacklog(this->
ParamExprs[tParamSerial]);
1079 if (this->mScalarUndoneParams->Tagged(tParamSerial))
1083 if (cacheEmulParamValues.insertBool(tParamEmulValue, tEmulIndex))
1086 if (tExecIndex == InvalidIndex) cacheEmulValueFreqs[tEmulIndex] = 0;
1089 if (!cacheEmulValueFreqs[tEmulIndex]) --cacheEmulateValue;
1090 ++cacheEmulValueFreqs[tEmulIndex];
1092 else if (tParamExprValueRecord->EmulDiff(this->SysMaster->EmulClock()))
1097 if (cacheEmulParamValues.insertBool(tParamExecValue, tEmulIndex))
1102 --cacheEmulValueFreqs[tEmulIndex];
1103 if (!cacheEmulValueFreqs[tEmulIndex]) ++cacheEmulateValue;
1107 if (cacheEmulParamValues.insertBool(tParamEmulValue, tEmulIndex))
1110 if (tExecIndex == InvalidIndex) cacheEmulValueFreqs[tEmulIndex] = 0;
1113 if (!cacheEmulValueFreqs[tEmulIndex]) --cacheEmulateValue;
1114 ++cacheEmulValueFreqs[tEmulIndex];
1121 #endif // ComputeLazy 1128 template <
typename paramValue,
typename value>
1134 cacheEmulParamValues.syncClock();
1144 template <
typename paramValue,
typename value>
1154 #if SimulDownwardCache 1158 template <
typename paramValue,
typename value>
1162 cacheSimulParamValues.syncClock();
1166 #endif//SimulDownwardCache 1171 #endif//AllDifferentViolationValueToValueHppIncluded void updateExecData(Clock const ExecClock, data const &Data)
Update the execution data.
Definition: scalarrecord.hpp:228
All different violation value to value function.
Definition: alldifferentViolationValueToValue.hpp:36
static void performExecIncr(Expression *const pExpression)
Execute in incremental mode.
Definition: expression1.hpp:287
virtual void simulateAnew() overridefinal
Simulate the expression.
Definition: alldifferentViolationValueToValue.hpp:308
void setExprHash(Hash const pHash)
Set expression hash value.
Definition: expression1.hpp:607
virtual void syncSimulClock() override
synchronise the simulation clock.
Definition: valueFunction.hpp:242
AllDifferentViolationValueToValue(System *const pSystem, Dim const ParamCount, Expression *const *pParamExprs)
Param constructor.
Definition: alldifferentViolationValueToValue.hpp:193
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
virtual void executeIncr() overridefinal
Execute the expression.
Definition: alldifferentViolationValueToValue.hpp:356
kb< ParamSpecType > const *const ParamSpecs
Parameter specifications i.e. how to use values and metrics.
Definition: function0.hpp:172
kb< Index > tempPrevParamIndexes
Indexes for the previous values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:123
static AllDifferentViolationValueToValue< paramValue, value > * define(System *const pSystem, Dim const ParamCount, Expression *const *pParamExprs)
Define an all different violation value to value function in the system.
Definition: alldifferentViolationValueToValue.hpp:169
nhsc< paramValue > tempSimulParamValues
Simulation values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:125
#define openKangarooSpace
Open the project namespace.
Definition: project.hpp:74
void updateSimulData(Clock const SimulClock, data const &Data)
Update the simulation data.
Definition: valuerecord.hpp:299
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
virtual void syncSimulClock() overridefinal
Sync the simulation clock.
Definition: alldifferentViolationValueToValue.hpp:1145
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< 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
Hash calcExprHash() const
Calculate expression hash value.
Definition: function1.hpp:855
Int cacheExecuteValue
Execution cache value.
Definition: alldifferentViolationValueToValue.hpp:109
nhsf< paramValue > cacheExecParamValues
Execution values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:116
Flexible arity value functions.
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
kb< Dim > cachePrevValueFreqs
Frequencies of the previous values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:118
virtual void simulateIncr() overridefinal
Simulate the expression.
Definition: alldifferentViolationValueToValue.hpp:654
void setExprFormat(Identifier const pFormat)
Set expression format.
Definition: expression1.hpp:577
#define ComputeLazy
Perform lazy computation.
Definition: options.hpp:112
virtual void syncExecClock() overridefinal
Sync the execution clock.
Definition: alldifferentViolationValueToValue.hpp:1129
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
kb< ValueRecord< paramValue > const * > mParamExprValueRecords
Parameter value record pointers.
Definition: alldifferentViolationValueToValue.hpp:103
~AllDifferentViolationValueToValue()
Destructor.
Definition: alldifferentViolationValueToValue.hpp:155
kb< Dim > cacheExecValueFreqs
Fequencies of the execution values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:117
kb< Dim > tempSimulValueFreqs
Frequencies of the simulation values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:126
Unique identifier of a class.
void defineRootWithinSystem()
Define as a root within the system.
Definition: function1.hpp:1605
value ValueType
Value type.
Definition: alldifferentViolationValueToValue.hpp:41
Clock ExecClock() const
Get the execution clock.
Definition: system1.hpp:237
virtual void syncExecClock() override
Synchronise the execution clock.
Definition: valueFunction.hpp:229
void setUpdatable(Bool const SetNotUnset)
Set expression updatablity.
Definition: expression1.hpp:646
kb< Index > cacheExecParamIndexes
Indexes for the execution values of the parameters.
Definition: alldifferentViolationValueToValue.hpp:122
Unordered parameters.
Definition: parameter.hpp:66
ValueRecord< value > * mExprValueRecord
Expression value.
Definition: valueFunction.hpp:100
static void performSimulIncr(Expression *const pExpression)
Simulate in incremental mode.
Definition: expression1.hpp:326
Constraint-based local search systems.
Definition: system0.hpp:45
kll< Index > cacheParamValueIndexes
Indexes of the parameter values having changes.
Definition: alldifferentViolationValueToValue.hpp:119
System *const SysMaster
The system that contains this expression.
Definition: expression0.hpp:281
#define SimulFixedOnly
Use fixed simulation only, not flexi one.
Definition: options.hpp:165
virtual void computeFinal() overridefinal
Compute the expression.
Definition: alldifferentViolationValueToValue.hpp:229
#define closeKangarooSpace
Close the project namespace.
Definition: project.hpp:75
void defineExprValueRecord()
Define expression value.
Definition: valueFunction.hpp:216
virtual void executeAnew() overridefinal
Execute the expression.
Definition: alldifferentViolationValueToValue.hpp:269
data const & SimulData(Clock const SimulClock) const
SimulDiff ? SimulBuffer : ExecBuffer().
Definition: valuerecord.hpp:408
#define SimulDownwardCache
Use cache in lazy or fixed downward simulation.
Definition: options.hpp:308
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
Flexible arity value functions.
Definition: naryValueFunc.hpp:31
paramValue ParamValueType
Parameter value type.
Definition: alldifferentViolationValueToValue.hpp:40