Merge remote-tracking branch 'refs/remotes/origin/main'
commit
d8c7a27214
241
.idea/editor.xml
241
.idea/editor.xml
|
@ -240,244 +240,7 @@
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexRemoved" />
|
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Enums/@EntryIndexedValue" value="<NamingElement Priority="3"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="enum" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexRemoved" />
|
<option name="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020fields/@EntryIndexedValue" value="<NamingElement Priority="11"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="m_" Suffix="" Style="aa_bb" /></NamingElement>" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexRemoved" />
|
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexRemoved" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -27,7 +27,7 @@ macro(compile_options target_name)
|
||||||
sanitizers(${target_name})
|
sanitizers(${target_name})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
project(blt-gp VERSION 0.3.32)
|
project(blt-gp VERSION 0.4.9)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
|
@ -122,5 +122,6 @@ if (${BUILD_GP_TESTS})
|
||||||
|
|
||||||
blt_add_project(blt-symbolic-regression tests/symbolic_regression_test.cpp test)
|
blt_add_project(blt-symbolic-regression tests/symbolic_regression_test.cpp test)
|
||||||
blt_add_project(blt-drop tests/drop_test.cpp test)
|
blt_add_project(blt-drop tests/drop_test.cpp test)
|
||||||
|
blt_add_project(blt-drop-2-type tests/2_type_drop_test.cpp test)
|
||||||
|
|
||||||
endif ()
|
endif ()
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!python3
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#define BLT_GP_EXAMPLE_SYMBOLIC_REGRESSION_H
|
#define BLT_GP_EXAMPLE_SYMBOLIC_REGRESSION_H
|
||||||
|
|
||||||
#include "examples_base.h"
|
#include "examples_base.h"
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <blt/format/format.h>
|
#include <blt/format/format.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ namespace blt::gp::example
|
||||||
constexpr static double value_cutoff = 1.e15;
|
constexpr static double value_cutoff = 1.e15;
|
||||||
for (auto& fitness_case : training_cases)
|
for (auto& fitness_case : training_cases)
|
||||||
{
|
{
|
||||||
|
BLT_GP_UPDATE_CONTEXT(fitness_case);
|
||||||
const auto diff = std::abs(fitness_case.y - current_tree.get_evaluation_value<float>(fitness_case));
|
const auto diff = std::abs(fitness_case.y - current_tree.get_evaluation_value<float>(fitness_case));
|
||||||
if (diff < value_cutoff)
|
if (diff < value_cutoff)
|
||||||
{
|
{
|
||||||
fitness.raw_fitness += diff;
|
fitness.raw_fitness += diff;
|
||||||
if (diff <= 0.01)
|
if (diff <= 0.01)
|
||||||
fitness.hits++;
|
fitness.hits++;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fitness.raw_fitness += value_cutoff;
|
fitness.raw_fitness += value_cutoff;
|
||||||
}
|
}
|
||||||
fitness.standardized_fitness = fitness.raw_fitness;
|
fitness.standardized_fitness = fitness.raw_fitness;
|
||||||
|
@ -75,8 +75,7 @@ namespace blt::gp::example
|
||||||
fitness_case = {x, y};
|
fitness_case = {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
fitness_function_ref = [this](const tree_t& t, fitness_t& f, const size_t i)
|
fitness_function_ref = [this](const tree_t& t, fitness_t& f, const size_t i) {
|
||||||
{
|
|
||||||
return fitness_function(t, f, i);
|
return fitness_function(t, f, i);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -84,21 +83,40 @@ namespace blt::gp::example
|
||||||
void setup_operations()
|
void setup_operations()
|
||||||
{
|
{
|
||||||
BLT_DEBUG("Setup Types and Operators");
|
BLT_DEBUG("Setup Types and Operators");
|
||||||
static operation_t add{[](const float a, const float b) { return a + b; }, "add"};
|
static operation_t add{
|
||||||
static operation_t sub([](const float a, const float b) { return a - b; }, "sub");
|
// this is the function used by the operation
|
||||||
static operation_t mul([](const float a, const float b) { return a * b; }, "mul");
|
[](const float a, const float b) {
|
||||||
static operation_t pro_div([](const float a, const float b) { return b == 0.0f ? 0.0f : a / b; }, "div");
|
return a + b;
|
||||||
static operation_t op_sin([](const float a) { return std::sin(a); }, "sin");
|
},
|
||||||
static operation_t op_cos([](const float a) { return std::cos(a); }, "cos");
|
// this name is optional and is used if you print an individual
|
||||||
static operation_t op_exp([](const float a) { return std::exp(a); }, "exp");
|
"add"
|
||||||
static operation_t op_log([](const float a) { return a <= 0.0f ? 0.0f : std::log(a); }, "log");
|
};
|
||||||
static auto lit = operation_t([this]()
|
static operation_t sub([](const float a, const float b) {
|
||||||
{
|
return a - b;
|
||||||
|
}, "sub");
|
||||||
|
static operation_t mul([](const float a, const float b) {
|
||||||
|
return a * b;
|
||||||
|
}, "mul");
|
||||||
|
static operation_t pro_div([](const float a, const float b) {
|
||||||
|
return b == 0.0f ? 0.0f : a / b;
|
||||||
|
}, "div");
|
||||||
|
static operation_t op_sin([](const float a) {
|
||||||
|
return std::sin(a);
|
||||||
|
}, "sin");
|
||||||
|
static operation_t op_cos([](const float a) {
|
||||||
|
return std::cos(a);
|
||||||
|
}, "cos");
|
||||||
|
static operation_t op_exp([](const float a) {
|
||||||
|
return std::exp(a);
|
||||||
|
}, "exp");
|
||||||
|
static operation_t op_log([](const float a) {
|
||||||
|
return a <= 0.0f ? 0.0f : std::log(a);
|
||||||
|
}, "log");
|
||||||
|
static auto lit = operation_t([this]() {
|
||||||
return program.get_random().get_float(-1.0f, 1.0f);
|
return program.get_random().get_float(-1.0f, 1.0f);
|
||||||
}, "lit").set_ephemeral();
|
}, "lit").set_ephemeral();
|
||||||
|
|
||||||
static operation_t op_x([](const context& context)
|
static operation_t op_x([](const context& context) {
|
||||||
{
|
|
||||||
return context.x;
|
return context.x;
|
||||||
}, "x");
|
}, "x");
|
||||||
|
|
||||||
|
@ -117,8 +135,9 @@ namespace blt::gp::example
|
||||||
mutation_sel = &sel;
|
mutation_sel = &sel;
|
||||||
if (reproduction_sel == nullptr)
|
if (reproduction_sel == nullptr)
|
||||||
reproduction_sel = &sel;
|
reproduction_sel = &sel;
|
||||||
program.generate_population(program.get_typesystem().get_type<float>().id(), fitness_function_ref, *crossover_sel, *mutation_sel,
|
program.generate_initial_population(program.get_typesystem().get_type<float>().id());
|
||||||
*reproduction_sel);
|
program.setup_generational_evaluation(fitness_function_ref, *crossover_sel,
|
||||||
|
*mutation_sel, *reproduction_sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_generation_loop()
|
void run_generation_loop()
|
||||||
|
@ -126,12 +145,12 @@ namespace blt::gp::example
|
||||||
BLT_DEBUG("Begin Generation Loop");
|
BLT_DEBUG("Begin Generation Loop");
|
||||||
while (!program.should_terminate())
|
while (!program.should_terminate())
|
||||||
{
|
{
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto cross = crossover_calls.start_measurement();
|
auto cross = crossover_calls.start_measurement();
|
||||||
auto mut = mutation_calls.start_measurement();
|
auto mut = mutation_calls.start_measurement();
|
||||||
auto repo = reproduction_calls.start_measurement();
|
auto repo = reproduction_calls.start_measurement();
|
||||||
#endif
|
#endif
|
||||||
BLT_TRACE("------------{Begin Generation %ld}------------", program.get_current_generation());
|
BLT_TRACE("------------\\{Begin Generation {}}------------", program.get_current_generation());
|
||||||
BLT_TRACE("Creating next generation");
|
BLT_TRACE("Creating next generation");
|
||||||
program.create_next_generation();
|
program.create_next_generation();
|
||||||
BLT_TRACE("Move to next generation");
|
BLT_TRACE("Move to next generation");
|
||||||
|
@ -139,17 +158,17 @@ namespace blt::gp::example
|
||||||
BLT_TRACE("Evaluate Fitness");
|
BLT_TRACE("Evaluate Fitness");
|
||||||
program.evaluate_fitness();
|
program.evaluate_fitness();
|
||||||
const auto& stats = program.get_population_stats();
|
const auto& stats = program.get_population_stats();
|
||||||
BLT_TRACE("Avg Fit: %lf, Best Fit: %lf, Worst Fit: %lf, Overall Fit: %lf",
|
BLT_TRACE("Avg Fit: {:0.6f}, Best Fit: {:0.6f}, Worst Fit: {:0.6f}, Overall Fit: {:0.6f}", stats.average_fitness.load(std::memory_order_relaxed),
|
||||||
stats.average_fitness.load(std::memory_order_relaxed), stats.best_fitness.load(std::memory_order_relaxed),
|
stats.best_fitness.load(std::memory_order_relaxed), stats.worst_fitness.load(std::memory_order_relaxed),
|
||||||
stats.worst_fitness.load(std::memory_order_relaxed), stats.overall_fitness.load(std::memory_order_relaxed));
|
stats.overall_fitness.load(std::memory_order_relaxed));
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
crossover_calls.stop_measurement(cross);
|
crossover_calls.stop_measurement(cross);
|
||||||
mutation_calls.stop_measurement(mut);
|
mutation_calls.stop_measurement(mut);
|
||||||
reproduction_calls.stop_measurement(repo);
|
reproduction_calls.stop_measurement(repo);
|
||||||
const auto total = (cross.get_call_difference() * 2) + mut.get_call_difference() + repo.get_call_difference();
|
const auto total = (cross.get_call_difference() * 2) + mut.get_call_difference() + repo.get_call_difference();
|
||||||
BLT_TRACE("Calls Crossover: %ld, Mutation %ld, Reproduction %ld; %ld", cross.get_call_difference(), mut.get_call_difference(), repo.get_call_difference(), total);
|
BLT_TRACE("Calls Crossover: {}, Mutation {}, Reproduction {}; {}", cross.get_call_difference(), mut.get_call_difference(), repo.get_call_difference(), total);
|
||||||
BLT_TRACE("Value Crossover: %ld, Mutation %ld, Reproduction %ld; %ld", cross.get_value_difference(), mut.get_value_difference(), repo.get_value_difference(), (cross.get_value_difference() * 2 + mut.get_value_difference() + repo.get_value_difference()) - total);
|
BLT_TRACE("Value Crossover: {}, Mutation {}, Reproduction {}; {}", cross.get_value_difference(), mut.get_value_difference(), repo.get_value_difference(), (cross.get_value_difference() * 2 + mut.get_value_difference() + repo.get_value_difference()) - total);
|
||||||
#endif
|
#endif
|
||||||
BLT_TRACE("----------------------------------------------");
|
BLT_TRACE("----------------------------------------------");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +182,7 @@ namespace blt::gp::example
|
||||||
for (auto& i_ref : best)
|
for (auto& i_ref : best)
|
||||||
{
|
{
|
||||||
auto& i = i_ref.get();
|
auto& i = i_ref.get();
|
||||||
BLT_DEBUG("Fitness: %lf, stand: %lf, raw: %lf", i.fitness.adjusted_fitness, i.fitness.standardized_fitness, i.fitness.raw_fitness);
|
BLT_DEBUG("Fitness: {:0.6f}, stand: {:0.6f}, raw: {:0.6f}", i.fitness.adjusted_fitness, i.fitness.standardized_fitness, i.fitness.raw_fitness);
|
||||||
i.tree.print(std::cout);
|
i.tree.print(std::cout);
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
|
@ -176,10 +195,10 @@ namespace blt::gp::example
|
||||||
// TODO: make stats helper
|
// TODO: make stats helper
|
||||||
const auto& stats = program.get_population_stats();
|
const auto& stats = program.get_population_stats();
|
||||||
BLT_INFO("Stats:");
|
BLT_INFO("Stats:");
|
||||||
BLT_INFO("Average fitness: %lf", stats.average_fitness.load());
|
BLT_INFO("Average fitness: {:0.6f}", stats.average_fitness.load());
|
||||||
BLT_INFO("Best fitness: %lf", stats.best_fitness.load());
|
BLT_INFO("Best fitness: {:0.6f}", stats.best_fitness.load());
|
||||||
BLT_INFO("Worst fitness: %lf", stats.worst_fitness.load());
|
BLT_INFO("Worst fitness: {:0.6f}", stats.worst_fitness.load());
|
||||||
BLT_INFO("Overall fitness: %lf", stats.overall_fitness.load());
|
BLT_INFO("Overall fitness: {:0.6f}", stats.overall_fitness.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
void execute()
|
void execute()
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#define BLT_GP_ALLOCATOR_H
|
#define BLT_GP_ALLOCATOR_H
|
||||||
|
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <blt/gp/util/trackers.h>
|
#include <blt/gp/util/trackers.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -63,9 +63,10 @@ namespace blt::gp
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void call_drop(stack_allocator& read_allocator, const size_t offset)
|
static void call_drop(stack_allocator& read_allocator, const size_t offset)
|
||||||
{
|
{
|
||||||
if constexpr (blt::gp::detail::has_func_drop_v<T>)
|
if constexpr (blt::gp::detail::has_func_drop_v<detail::remove_cv_ref<T>>)
|
||||||
{
|
{
|
||||||
auto [type, ptr] = read_allocator.access_pointer<detail::remove_cv_ref<T>>(offset);
|
auto [type, ptr] = read_allocator.access_pointer<detail::remove_cv_ref<T>>(offset);
|
||||||
|
// type is not ephemeral, so we must drop it.
|
||||||
if (!ptr.bit(0))
|
if (!ptr.bit(0))
|
||||||
type.drop();
|
type.drop();
|
||||||
}
|
}
|
||||||
|
@ -200,7 +201,7 @@ namespace blt::gp
|
||||||
|
|
||||||
[[nodiscard]] bool return_has_ephemeral_drop() const
|
[[nodiscard]] bool return_has_ephemeral_drop() const
|
||||||
{
|
{
|
||||||
return detail::has_func_drop_v<Return>;
|
return detail::has_func_drop_v<detail::remove_cv_ref<Return>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator_id id = -1;
|
operator_id id = -1;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#ifndef BLT_GP_PROGRAM_H
|
#ifndef BLT_GP_PROGRAM_H
|
||||||
#define BLT_GP_PROGRAM_H
|
#define BLT_GP_PROGRAM_H
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -124,9 +123,8 @@ namespace blt::gp
|
||||||
blt::size_t largest_returns = 0;
|
blt::size_t largest_returns = 0;
|
||||||
blt::u32 largest_argc = 0;
|
blt::u32 largest_argc = 0;
|
||||||
operator_metadata_t meta;
|
operator_metadata_t meta;
|
||||||
((meta = add_operator(operators), largest_argc = std::max(meta.argc.argc, largest_argc),
|
((meta = add_operator(operators), largest_argc = std::max(meta.argc.argc, largest_argc), largest_args =
|
||||||
largest_args = std::max(meta.arg_size_bytes, largest_args), largest_returns = std::max(meta.return_size_bytes,
|
std::max(meta.arg_size_bytes, largest_args), largest_returns = std::max(meta.return_size_bytes, largest_returns)), ...);
|
||||||
largest_returns)), ...);
|
|
||||||
|
|
||||||
// largest = largest * largest_argc;
|
// largest = largest * largest_argc;
|
||||||
size_t largest = largest_args * largest_argc * largest_returns * largest_argc;
|
size_t largest = largest_args * largest_argc * largest_returns * largest_argc;
|
||||||
|
@ -177,16 +175,14 @@ namespace blt::gp
|
||||||
"(that is all input types are terminals) for return type " + std::to_string(return_type)).c_str());
|
"(that is all input types are terminals) for return type " + std::to_string(return_type)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(ordered_terminals.begin(), ordered_terminals.end(), [](const auto& a, const auto& b)
|
std::sort(ordered_terminals.begin(), ordered_terminals.end(), [](const auto& a, const auto& b) {
|
||||||
{
|
|
||||||
return a.second > b.second;
|
return a.second > b.second;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto first_size = *ordered_terminals.begin();
|
auto first_size = *ordered_terminals.begin();
|
||||||
auto iter = ordered_terminals.begin();
|
auto iter = ordered_terminals.begin();
|
||||||
while (++iter != ordered_terminals.end() && iter->second == first_size.second)
|
while (++iter != ordered_terminals.end() && iter->second == first_size.second)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
ordered_terminals.erase(iter, ordered_terminals.end());
|
ordered_terminals.erase(iter, ordered_terminals.end());
|
||||||
|
|
||||||
|
@ -242,20 +238,17 @@ namespace blt::gp
|
||||||
meta.argc = info.argc;
|
meta.argc = info.argc;
|
||||||
|
|
||||||
storage.operator_metadata.push_back(meta);
|
storage.operator_metadata.push_back(meta);
|
||||||
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack)
|
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack) {
|
||||||
{
|
|
||||||
if constexpr (blt::meta::is_streamable_v<Return>)
|
if constexpr (blt::meta::is_streamable_v<Return>)
|
||||||
{
|
{
|
||||||
out << stack.from<Return>(0);
|
out << stack.from<Return>(0);
|
||||||
(void)(op); // remove warning
|
(void) (op); // remove warning
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
storage.destroy_funcs.push_back([](const detail::destroy_t type, u8* data)
|
storage.destroy_funcs.push_back([](const detail::destroy_t type, u8* data) {
|
||||||
{
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case detail::destroy_t::PTR:
|
case detail::destroy_t::PTR:
|
||||||
|
@ -294,16 +287,20 @@ namespace blt::gp
|
||||||
*
|
*
|
||||||
* @param seed
|
* @param seed
|
||||||
*/
|
*/
|
||||||
explicit gp_program(blt::u64 seed): seed_func([seed] { return seed; })
|
explicit gp_program(blt::u64 seed): seed_func([seed] {
|
||||||
|
return seed;
|
||||||
|
})
|
||||||
{
|
{
|
||||||
create_threads();
|
create_threads();
|
||||||
selection_probabilities.update(config);
|
set_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit gp_program(blt::u64 seed, const prog_config_t& config): seed_func([seed] { return seed; }), config(config)
|
explicit gp_program(blt::u64 seed, const prog_config_t& config): seed_func([seed] {
|
||||||
|
return seed;
|
||||||
|
})
|
||||||
{
|
{
|
||||||
create_threads();
|
create_threads();
|
||||||
selection_probabilities.update(config);
|
set_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -314,13 +311,13 @@ namespace blt::gp
|
||||||
explicit gp_program(std::function<blt::u64()> seed_func): seed_func(std::move(seed_func))
|
explicit gp_program(std::function<blt::u64()> seed_func): seed_func(std::move(seed_func))
|
||||||
{
|
{
|
||||||
create_threads();
|
create_threads();
|
||||||
selection_probabilities.update(config);
|
set_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit gp_program(std::function<blt::u64()> seed_func, const prog_config_t& config): seed_func(std::move(seed_func)), config(config)
|
explicit gp_program(std::function<blt::u64()> seed_func, const prog_config_t& config): seed_func(std::move(seed_func))
|
||||||
{
|
{
|
||||||
create_threads();
|
create_threads();
|
||||||
selection_probabilities.update(config);
|
set_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
~gp_program()
|
~gp_program()
|
||||||
|
@ -337,16 +334,16 @@ namespace blt::gp
|
||||||
|
|
||||||
void create_next_generation()
|
void create_next_generation()
|
||||||
{
|
{
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto gen_alloc = blt::gp::tracker.start_measurement();
|
auto gen_alloc = blt::gp::tracker.start_measurement();
|
||||||
#endif
|
#endif
|
||||||
// should already be empty
|
// should already be empty
|
||||||
thread_helper.next_gen_left.store(config.population_size, std::memory_order_release);
|
thread_helper.next_gen_left.store(selection_probabilities.replacement_amount.value_or(config.population_size), std::memory_order_release);
|
||||||
(*thread_execution_service)(0);
|
(*thread_execution_service)(0);
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
blt::gp::tracker.stop_measurement(gen_alloc);
|
blt::gp::tracker.stop_measurement(gen_alloc);
|
||||||
gen_alloc.pretty_print("Generation");
|
gen_alloc.pretty_print("Generation");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void next_generation()
|
void next_generation()
|
||||||
|
@ -357,11 +354,11 @@ namespace blt::gp
|
||||||
|
|
||||||
void evaluate_fitness()
|
void evaluate_fitness()
|
||||||
{
|
{
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto fitness_alloc = blt::gp::tracker.start_measurement();
|
auto fitness_alloc = blt::gp::tracker.start_measurement();
|
||||||
#endif
|
#endif
|
||||||
evaluate_fitness_internal();
|
evaluate_fitness_internal();
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
blt::gp::tracker.stop_measurement(fitness_alloc);
|
blt::gp::tracker.stop_measurement(fitness_alloc);
|
||||||
fitness_alloc.pretty_print("Fitness");
|
fitness_alloc.pretty_print("Fitness");
|
||||||
evaluation_calls.call();
|
evaluation_calls.call();
|
||||||
|
@ -370,14 +367,15 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
evaluation_allocations.call(fitness_alloc.getAllocatedByteDifference());
|
evaluation_allocations.call(fitness_alloc.getAllocatedByteDifference());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_program(type_id root_type, bool eval_fitness_now = true)
|
void reset_program(type_id root_type, bool eval_fitness_now = true)
|
||||||
{
|
{
|
||||||
current_generation = 0;
|
current_generation = 0;
|
||||||
current_pop = config.pop_initializer.get().generate(
|
current_pop = config.pop_initializer.get().generate({
|
||||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size
|
||||||
|
});
|
||||||
next_pop = population_t(current_pop);
|
next_pop = population_t(current_pop);
|
||||||
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
||||||
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
||||||
|
@ -392,6 +390,18 @@ namespace blt::gp
|
||||||
thread_helper.lifetime_over = true;
|
thread_helper.lifetime_over = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void generate_initial_population(const type_id root_type)
|
||||||
|
{
|
||||||
|
current_pop = config.pop_initializer.get().generate({
|
||||||
|
*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size
|
||||||
|
});
|
||||||
|
next_pop = population_t(current_pop);
|
||||||
|
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
||||||
|
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
||||||
|
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
||||||
|
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* takes in a reference to a function for the fitness evaluation function (must return a value convertable to double)
|
* takes in a reference to a function for the fitness evaluation function (must return a value convertable to double)
|
||||||
* The lambda must accept a tree for evaluation, and an index (current tree)
|
* The lambda must accept a tree for evaluation, and an index (current tree)
|
||||||
|
@ -400,61 +410,31 @@ namespace blt::gp
|
||||||
*
|
*
|
||||||
* Container must be concurrently accessible from multiple threads using operator[]
|
* Container must be concurrently accessible from multiple threads using operator[]
|
||||||
*
|
*
|
||||||
* NOTE: 0 is considered the best, in terms of standardized fitness
|
* NOTE: the larger the adjusted fitness, the better.
|
||||||
*/
|
*/
|
||||||
template <typename FitnessFunc, typename Crossover, typename Mutation, typename Reproduction>
|
template <typename FitnessFunc, typename Crossover, typename Mutation, typename Reproduction>
|
||||||
void generate_population(type_id root_type, FitnessFunc& fitness_function,
|
void setup_generational_evaluation(FitnessFunc& fitness_function, Crossover& crossover_selection, Mutation& mutation_selection,
|
||||||
Crossover& crossover_selection, Mutation& mutation_selection, Reproduction& reproduction_selection,
|
Reproduction& reproduction_selection, bool eval_fitness_now = true)
|
||||||
bool eval_fitness_now = true)
|
|
||||||
{
|
{
|
||||||
using LambdaReturn = std::invoke_result_t<decltype(fitness_function), const tree_t&, fitness_t&, size_t>;
|
|
||||||
current_pop = config.pop_initializer.get().generate(
|
|
||||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
|
||||||
next_pop = population_t(current_pop);
|
|
||||||
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
|
||||||
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
|
||||||
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
|
||||||
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
|
||||||
if (config.threads == 1)
|
if (config.threads == 1)
|
||||||
{
|
{
|
||||||
BLT_INFO("Starting with single thread variant!");
|
BLT_INFO("Starting generational with single thread variant!");
|
||||||
thread_execution_service = std::unique_ptr<std::function<void(size_t)>>(new std::function(
|
thread_execution_service = std::unique_ptr<std::function<void(size_t)>>(new std::function(
|
||||||
[this, &fitness_function, &crossover_selection, &mutation_selection, &reproduction_selection](size_t)
|
[this, &fitness_function, &crossover_selection, &mutation_selection, &reproduction_selection](size_t) {
|
||||||
{
|
single_threaded_fitness_eval<FitnessFunc>()(fitness_function);
|
||||||
if (thread_helper.evaluation_left > 0)
|
|
||||||
|
if (thread_helper.next_gen_left > 0)
|
||||||
{
|
{
|
||||||
current_stats.normalized_fitness.clear();
|
current_stats.normalized_fitness.clear();
|
||||||
double sum_of_prob = 0;
|
double sum_of_prob = 0;
|
||||||
for (const auto& [index, ind] : blt::enumerate(current_pop.get_individuals()))
|
for (const auto& ind : current_pop)
|
||||||
{
|
{
|
||||||
ind.fitness = {};
|
const auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
||||||
if constexpr (std::is_same_v<LambdaReturn, bool> || std::is_convertible_v<LambdaReturn, bool>)
|
|
||||||
{
|
|
||||||
if (fitness_function(ind.tree, ind.fitness, index))
|
|
||||||
fitness_should_exit = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fitness_function(ind.tree, ind.fitness, index);
|
|
||||||
|
|
||||||
if (ind.fitness.adjusted_fitness > current_stats.best_fitness)
|
|
||||||
current_stats.best_fitness = ind.fitness.adjusted_fitness;
|
|
||||||
|
|
||||||
if (ind.fitness.adjusted_fitness < current_stats.worst_fitness)
|
|
||||||
current_stats.worst_fitness = ind.fitness.adjusted_fitness;
|
|
||||||
|
|
||||||
current_stats.overall_fitness = current_stats.overall_fitness + ind.fitness.adjusted_fitness;
|
|
||||||
}
|
|
||||||
for (auto& ind : current_pop)
|
|
||||||
{
|
|
||||||
auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
|
||||||
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
||||||
sum_of_prob += prob;
|
sum_of_prob += prob;
|
||||||
}
|
}
|
||||||
thread_helper.evaluation_left = 0;
|
|
||||||
}
|
const auto args = get_selector_args();
|
||||||
if (thread_helper.next_gen_left > 0)
|
|
||||||
{
|
|
||||||
auto args = get_selector_args();
|
|
||||||
|
|
||||||
crossover_selection.pre_process(*this, current_pop);
|
crossover_selection.pre_process(*this, current_pop);
|
||||||
mutation_selection.pre_process(*this, current_pop);
|
mutation_selection.pre_process(*this, current_pop);
|
||||||
|
@ -474,73 +454,16 @@ namespace blt::gp
|
||||||
thread_helper.next_gen_left = 0;
|
thread_helper.next_gen_left = 0;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
BLT_INFO("Starting thread execution service!");
|
BLT_INFO("Starting generational thread execution service!");
|
||||||
std::scoped_lock lock(thread_helper.thread_function_control);
|
std::scoped_lock lock(thread_helper.thread_function_control);
|
||||||
thread_execution_service = std::unique_ptr<std::function<void(blt::size_t)>>(new std::function(
|
thread_execution_service = std::unique_ptr<std::function<void(size_t)>>(new std::function(
|
||||||
[this, &fitness_function, &crossover_selection, &mutation_selection, &reproduction_selection](size_t id)
|
[this, &fitness_function, &crossover_selection, &mutation_selection, &reproduction_selection](const size_t id) {
|
||||||
{
|
|
||||||
thread_helper.barrier.wait();
|
thread_helper.barrier.wait();
|
||||||
|
|
||||||
if (thread_helper.evaluation_left > 0)
|
multi_threaded_fitness_eval<FitnessFunc>()(fitness_function, id);
|
||||||
{
|
|
||||||
while (thread_helper.evaluation_left > 0)
|
|
||||||
{
|
|
||||||
blt::size_t size = 0;
|
|
||||||
blt::size_t begin = 0;
|
|
||||||
blt::size_t end = thread_helper.evaluation_left.load(std::memory_order_relaxed);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
size = std::min(end, config.evaluation_size);
|
|
||||||
begin = end - size;
|
|
||||||
}
|
|
||||||
while (!thread_helper.evaluation_left.compare_exchange_weak(end, end - size,
|
|
||||||
std::memory_order::memory_order_relaxed,
|
|
||||||
std::memory_order::memory_order_relaxed));
|
|
||||||
for (blt::size_t i = begin; i < end; i++)
|
|
||||||
{
|
|
||||||
auto& ind = current_pop.get_individuals()[i];
|
|
||||||
|
|
||||||
ind.fitness = {};
|
|
||||||
if constexpr (std::is_same_v<LambdaReturn, bool> || std::is_convertible_v<LambdaReturn, bool>)
|
|
||||||
{
|
|
||||||
auto result = fitness_function(ind.tree, ind.fitness, i);
|
|
||||||
if (result)
|
|
||||||
fitness_should_exit = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fitness_function(ind.tree, ind.fitness, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto old_best = current_stats.best_fitness.load(std::memory_order_relaxed);
|
|
||||||
while (ind.fitness.adjusted_fitness > old_best &&
|
|
||||||
!current_stats.best_fitness.compare_exchange_weak(old_best, ind.fitness.adjusted_fitness,
|
|
||||||
std::memory_order_relaxed,
|
|
||||||
std::memory_order_relaxed))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
auto old_worst = current_stats.worst_fitness.load(std::memory_order_relaxed);
|
|
||||||
while (ind.fitness.adjusted_fitness < old_worst &&
|
|
||||||
!current_stats.worst_fitness.compare_exchange_weak(old_worst, ind.fitness.adjusted_fitness,
|
|
||||||
std::memory_order_relaxed,
|
|
||||||
std::memory_order_relaxed))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
auto old_overall = current_stats.overall_fitness.load(std::memory_order_relaxed);
|
|
||||||
while (!current_stats.overall_fitness.compare_exchange_weak(old_overall,
|
|
||||||
ind.fitness.adjusted_fitness + old_overall,
|
|
||||||
std::memory_order_relaxed,
|
|
||||||
std::memory_order_relaxed))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (thread_helper.next_gen_left > 0)
|
if (thread_helper.next_gen_left > 0)
|
||||||
{
|
{
|
||||||
thread_helper.barrier.wait();
|
thread_helper.barrier.wait();
|
||||||
|
@ -549,9 +472,9 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
current_stats.normalized_fitness.clear();
|
current_stats.normalized_fitness.clear();
|
||||||
double sum_of_prob = 0;
|
double sum_of_prob = 0;
|
||||||
for (auto& ind : current_pop)
|
for (const auto& ind : current_pop)
|
||||||
{
|
{
|
||||||
auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
const auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
||||||
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
||||||
sum_of_prob += prob;
|
sum_of_prob += prob;
|
||||||
}
|
}
|
||||||
|
@ -575,10 +498,8 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
size = std::min(end, config.evaluation_size);
|
size = std::min(end, config.evaluation_size);
|
||||||
begin = end - size;
|
begin = end - size;
|
||||||
}
|
} while (!thread_helper.next_gen_left.compare_exchange_weak(
|
||||||
while (!thread_helper.next_gen_left.compare_exchange_weak(end, end - size,
|
end, end - size, std::memory_order::memory_order_relaxed, std::memory_order::memory_order_relaxed));
|
||||||
std::memory_order::memory_order_relaxed,
|
|
||||||
std::memory_order::memory_order_relaxed));
|
|
||||||
|
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
{
|
{
|
||||||
|
@ -599,6 +520,116 @@ namespace blt::gp
|
||||||
evaluate_fitness_internal();
|
evaluate_fitness_internal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename FitnessFunc, typename SelectionStrat, typename Crossover, typename Mutation, typename Reproduction>
|
||||||
|
void setup_steady_state_evaluation(FitnessFunc& fitness_function, SelectionStrat& replacement_strategy, size_t replacement_amount,
|
||||||
|
Crossover& crossover_selection, Mutation& mutation_selection, Reproduction& reproduction_selection,
|
||||||
|
const bool eval_fitness_now = true)
|
||||||
|
{
|
||||||
|
selection_probabilities.replacement_amount = replacement_amount;
|
||||||
|
if (config.threads == 1)
|
||||||
|
{
|
||||||
|
BLT_INFO("Starting steady state with single thread variant!");
|
||||||
|
thread_execution_service = std::unique_ptr<std::function<void(size_t)>>(new std::function(
|
||||||
|
[this, &fitness_function, &replacement_strategy, &crossover_selection, &mutation_selection, &reproduction_selection](size_t) {
|
||||||
|
single_threaded_fitness_eval<FitnessFunc>()(fitness_function);
|
||||||
|
|
||||||
|
if (thread_helper.next_gen_left > 0)
|
||||||
|
{
|
||||||
|
current_stats.normalized_fitness.clear();
|
||||||
|
double sum_of_prob = 0;
|
||||||
|
for (const auto& ind : current_pop)
|
||||||
|
{
|
||||||
|
const auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
||||||
|
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
||||||
|
sum_of_prob += prob;
|
||||||
|
}
|
||||||
|
|
||||||
|
next_pop = population_t(current_pop);
|
||||||
|
|
||||||
|
replacement_strategy.pre_process(*this, next_pop);
|
||||||
|
crossover_selection.pre_process(*this, current_pop);
|
||||||
|
mutation_selection.pre_process(*this, current_pop);
|
||||||
|
reproduction_selection.pre_process(*this, current_pop);
|
||||||
|
|
||||||
|
while (thread_helper.next_gen_left > 0)
|
||||||
|
{
|
||||||
|
tree_t& c1 = replacement_strategy.select(*this, next_pop);
|
||||||
|
tree_t* c2 = nullptr;
|
||||||
|
if (thread_helper.next_gen_left > 1)
|
||||||
|
while (c2 != &c1)
|
||||||
|
c2 = &replacement_strategy.select(*this, next_pop);
|
||||||
|
thread_helper.next_gen_left -= perform_selection(crossover_selection, mutation_selection, reproduction_selection, c1,
|
||||||
|
c2);
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_helper.next_gen_left = 0;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
BLT_INFO("Starting steady state thread execution service!");
|
||||||
|
std::scoped_lock lock(thread_helper.thread_function_control);
|
||||||
|
thread_execution_service = std::unique_ptr<std::function<void(size_t)>>(new std::function(
|
||||||
|
[this, &fitness_function, &replacement_strategy, &crossover_selection, &mutation_selection, &reproduction_selection](
|
||||||
|
const size_t id) {
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
|
||||||
|
multi_threaded_fitness_eval<FitnessFunc>()(fitness_function, id);
|
||||||
|
|
||||||
|
if (thread_helper.next_gen_left > 0)
|
||||||
|
{
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
if (id == 0)
|
||||||
|
{
|
||||||
|
current_stats.normalized_fitness.clear();
|
||||||
|
double sum_of_prob = 0;
|
||||||
|
for (const auto& ind : current_pop)
|
||||||
|
{
|
||||||
|
const auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
||||||
|
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
||||||
|
sum_of_prob += prob;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_pop = population_t(next_pop);
|
||||||
|
|
||||||
|
replacement_strategy.pre_process(*this, next_pop);
|
||||||
|
crossover_selection.pre_process(*this, current_pop);
|
||||||
|
if (&crossover_selection != &mutation_selection)
|
||||||
|
mutation_selection.pre_process(*this, current_pop);
|
||||||
|
if (&crossover_selection != &reproduction_selection)
|
||||||
|
reproduction_selection.pre_process(*this, current_pop);
|
||||||
|
}
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
|
||||||
|
while (thread_helper.next_gen_left > 0)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
size_t end = thread_helper.next_gen_left.load(std::memory_order_relaxed);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size = std::min(end, config.evaluation_size);
|
||||||
|
} while (!thread_helper.next_gen_left.compare_exchange_weak(
|
||||||
|
end, end - size, std::memory_order::memory_order_relaxed, std::memory_order::memory_order_relaxed));
|
||||||
|
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
tree_t& c1 = replacement_strategy.select(*this, next_pop);
|
||||||
|
tree_t* c2 = nullptr;
|
||||||
|
if (thread_helper.next_gen_left > 1)
|
||||||
|
while (c2 != &c1)
|
||||||
|
c2 = &replacement_strategy.select(*this, next_pop);
|
||||||
|
size -= perform_selection(crossover_selection, mutation_selection, reproduction_selection, c1, c2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
}));
|
||||||
|
thread_helper.thread_function_condition.notify_all();
|
||||||
|
}
|
||||||
|
if (eval_fitness_now)
|
||||||
|
evaluate_fitness_internal();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool should_terminate() const
|
[[nodiscard]] bool should_terminate() const
|
||||||
{
|
{
|
||||||
return current_generation >= config.max_generations || fitness_should_exit;
|
return current_generation >= config.max_generations || fitness_should_exit;
|
||||||
|
@ -646,6 +677,12 @@ namespace blt::gp
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_config(const prog_config_t& config)
|
||||||
|
{
|
||||||
|
this->config = config;
|
||||||
|
selection_probabilities.update(this->config);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] type_provider& get_typesystem()
|
[[nodiscard]] type_provider& get_typesystem()
|
||||||
{
|
{
|
||||||
return storage.system;
|
return storage.system;
|
||||||
|
@ -666,7 +703,7 @@ namespace blt::gp
|
||||||
return storage.destroy_funcs[id];
|
return storage.destroy_funcs[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::optional<std::string_view> get_name(operator_id id)
|
[[nodiscard]] std::optional<std::string_view> get_name(operator_id id) const
|
||||||
{
|
{
|
||||||
return storage.names[id];
|
return storage.names[id];
|
||||||
}
|
}
|
||||||
|
@ -727,8 +764,7 @@ namespace blt::gp
|
||||||
for (const auto& [index, value] : blt::enumerate(current_pop.get_individuals()))
|
for (const auto& [index, value] : blt::enumerate(current_pop.get_individuals()))
|
||||||
values.emplace_back(index, value.fitness.adjusted_fitness);
|
values.emplace_back(index, value.fitness.adjusted_fitness);
|
||||||
|
|
||||||
std::sort(values.begin(), values.end(), [](const auto& a, const auto& b)
|
std::sort(values.begin(), values.end(), [](const auto& a, const auto& b) {
|
||||||
{
|
|
||||||
return a.second > b.second;
|
return a.second > b.second;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -746,8 +782,7 @@ namespace blt::gp
|
||||||
return convert_array<std::array<std::reference_wrapper<individual_t>, size>>(get_best_indexes<size>(),
|
return convert_array<std::array<std::reference_wrapper<individual_t>, size>>(get_best_indexes<size>(),
|
||||||
[this](auto&& arr, blt::size_t index) -> tree_t& {
|
[this](auto&& arr, blt::size_t index) -> tree_t& {
|
||||||
return current_pop.get_individuals()[arr[index]].tree;
|
return current_pop.get_individuals()[arr[index]].tree;
|
||||||
},
|
}, std::make_integer_sequence<blt::size_t, size>());
|
||||||
std::make_integer_sequence<blt::size_t, size>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <blt::size_t size>
|
template <blt::size_t size>
|
||||||
|
@ -756,11 +791,102 @@ namespace blt::gp
|
||||||
return convert_array<std::array<std::reference_wrapper<individual_t>, size>>(get_best_indexes<size>(),
|
return convert_array<std::array<std::reference_wrapper<individual_t>, size>>(get_best_indexes<size>(),
|
||||||
[this](auto&& arr, blt::size_t index) -> individual_t& {
|
[this](auto&& arr, blt::size_t index) -> individual_t& {
|
||||||
return current_pop.get_individuals()[arr[index]];
|
return current_pop.get_individuals()[arr[index]];
|
||||||
},
|
}, std::make_integer_sequence<blt::size_t, size>());
|
||||||
std::make_integer_sequence<blt::size_t, size>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template <typename FitnessFunc>
|
||||||
|
auto single_threaded_fitness_eval()
|
||||||
|
{
|
||||||
|
return [this](FitnessFunc& fitness_function) {
|
||||||
|
if (thread_helper.evaluation_left > 0)
|
||||||
|
{
|
||||||
|
current_stats.normalized_fitness.clear();
|
||||||
|
double sum_of_prob = 0;
|
||||||
|
perform_fitness_function(0, current_pop.get_individuals().size(), fitness_function);
|
||||||
|
for (const auto& ind : current_pop)
|
||||||
|
{
|
||||||
|
const auto prob = (ind.fitness.adjusted_fitness / current_stats.overall_fitness);
|
||||||
|
current_stats.normalized_fitness.push_back(sum_of_prob + prob);
|
||||||
|
sum_of_prob += prob;
|
||||||
|
}
|
||||||
|
std::sort(current_pop.begin(), current_pop.end(), [](const auto& a, const auto& b)
|
||||||
|
{
|
||||||
|
return a.fitness.adjusted_fitness > b.fitness.adjusted_fitness;
|
||||||
|
});
|
||||||
|
thread_helper.evaluation_left = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FitnessFunc>
|
||||||
|
auto multi_threaded_fitness_eval()
|
||||||
|
{
|
||||||
|
return [this](FitnessFunc& fitness_function, size_t thread_id) {
|
||||||
|
if (thread_helper.evaluation_left > 0)
|
||||||
|
{
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
while (thread_helper.evaluation_left > 0)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
size_t begin = 0;
|
||||||
|
size_t end = thread_helper.evaluation_left.load(std::memory_order_relaxed);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size = std::min(end, config.evaluation_size);
|
||||||
|
begin = end - size;
|
||||||
|
} while (!thread_helper.evaluation_left.compare_exchange_weak(end, end - size, std::memory_order::memory_order_relaxed,
|
||||||
|
std::memory_order::memory_order_relaxed));
|
||||||
|
perform_fitness_function(begin, end, fitness_function);
|
||||||
|
}
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
if (thread_id == 0)
|
||||||
|
{
|
||||||
|
std::sort(current_pop.begin(), current_pop.end(), [](const auto& a, const auto& b)
|
||||||
|
{
|
||||||
|
return a.fitness.adjusted_fitness > b.fitness.adjusted_fitness;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
thread_helper.barrier.wait();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FitnessFunction>
|
||||||
|
void perform_fitness_function(const size_t begin, const size_t end, FitnessFunction& fitness_function)
|
||||||
|
{
|
||||||
|
using LambdaReturn = std::invoke_result_t<decltype(fitness_function), const tree_t&, fitness_t&, size_t>;
|
||||||
|
for (size_t i = begin; i < end; i++)
|
||||||
|
{
|
||||||
|
auto& ind = current_pop.get_individuals()[i];
|
||||||
|
|
||||||
|
ind.fitness = {};
|
||||||
|
if constexpr (std::is_same_v<LambdaReturn, bool> || std::is_convertible_v<LambdaReturn, bool>)
|
||||||
|
{
|
||||||
|
if (fitness_function(ind.tree, ind.fitness, i))
|
||||||
|
fitness_should_exit = true;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
fitness_function(ind.tree, ind.fitness, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto old_best = current_stats.best_fitness.load(std::memory_order_relaxed);
|
||||||
|
while (ind.fitness.adjusted_fitness > old_best && !current_stats.best_fitness.compare_exchange_weak(
|
||||||
|
old_best, ind.fitness.adjusted_fitness, std::memory_order_relaxed, std::memory_order_relaxed))
|
||||||
|
{}
|
||||||
|
|
||||||
|
auto old_worst = current_stats.worst_fitness.load(std::memory_order_relaxed);
|
||||||
|
while (ind.fitness.adjusted_fitness < old_worst && !current_stats.worst_fitness.compare_exchange_weak(
|
||||||
|
old_worst, ind.fitness.adjusted_fitness, std::memory_order_relaxed, std::memory_order_relaxed))
|
||||||
|
{}
|
||||||
|
|
||||||
|
auto old_overall = current_stats.overall_fitness.load(std::memory_order_relaxed);
|
||||||
|
while (!current_stats.overall_fitness.compare_exchange_weak(old_overall, ind.fitness.adjusted_fitness + old_overall,
|
||||||
|
std::memory_order_relaxed, std::memory_order_relaxed))
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Crossover, typename Mutation, typename Reproduction>
|
template <typename Crossover, typename Mutation, typename Reproduction>
|
||||||
size_t perform_selection(Crossover& crossover, Mutation& mutation, Reproduction& reproduction, tree_t& c1, tree_t* c2)
|
size_t perform_selection(Crossover& crossover, Mutation& mutation, Reproduction& reproduction, tree_t& c1, tree_t* c2)
|
||||||
{
|
{
|
||||||
|
@ -769,9 +895,9 @@ namespace blt::gp
|
||||||
auto ptr = c2;
|
auto ptr = c2;
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
ptr = &tree_t::get_thread_local(*this);
|
ptr = &tree_t::get_thread_local(*this);
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto state = tracker.start_measurement_thread_local();
|
auto state = tracker.start_measurement_thread_local();
|
||||||
#endif
|
#endif
|
||||||
const tree_t* p1;
|
const tree_t* p1;
|
||||||
const tree_t* p2;
|
const tree_t* p2;
|
||||||
size_t runs = 0;
|
size_t runs = 0;
|
||||||
|
@ -788,12 +914,11 @@ namespace blt::gp
|
||||||
|
|
||||||
if (++runs >= config.crossover.get().get_config().max_crossover_iterations)
|
if (++runs >= config.crossover.get().get_config().max_crossover_iterations)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
crossover_calls.value(1);
|
crossover_calls.value(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
} while (!config.crossover.get().apply(*this, *p1, *p2, c1, *ptr));
|
||||||
while (!config.crossover.get().apply(*this, *p1, *p2, c1, *ptr));
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
|
||||||
tracker.stop_measurement_thread_local(state);
|
tracker.stop_measurement_thread_local(state);
|
||||||
crossover_calls.call();
|
crossover_calls.call();
|
||||||
if (state.getAllocatedByteDifference() != 0)
|
if (state.getAllocatedByteDifference() != 0)
|
||||||
|
@ -801,7 +926,7 @@ namespace blt::gp
|
||||||
crossover_allocations.call(state.getAllocatedByteDifference());
|
crossover_allocations.call(state.getAllocatedByteDifference());
|
||||||
crossover_allocations.set_value(std::max(crossover_allocations.get_value(), state.getAllocatedByteDifference()));
|
crossover_allocations.set_value(std::max(crossover_allocations.get_value(), state.getAllocatedByteDifference()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (c2 == nullptr)
|
if (c2 == nullptr)
|
||||||
{
|
{
|
||||||
tree_t::get_thread_local(*this).clear(*this);
|
tree_t::get_thread_local(*this).clear(*this);
|
||||||
|
@ -811,21 +936,20 @@ namespace blt::gp
|
||||||
}
|
}
|
||||||
if (get_random().choice(selection_probabilities.mutation_chance))
|
if (get_random().choice(selection_probabilities.mutation_chance))
|
||||||
{
|
{
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto state = tracker.start_measurement_thread_local();
|
auto state = tracker.start_measurement_thread_local();
|
||||||
#endif
|
#endif
|
||||||
// mutation
|
// mutation
|
||||||
const tree_t* p;
|
const tree_t* p;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
p = &mutation.select(*this, current_pop);
|
p = &mutation.select(*this, current_pop);
|
||||||
c1.copy_fast(*p);
|
c1.copy_fast(*p);
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
mutation_calls.value(1);
|
mutation_calls.value(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
} while (!config.mutator.get().apply(*this, *p, c1));
|
||||||
while (!config.mutator.get().apply(*this, *p, c1));
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
|
||||||
tracker.stop_measurement_thread_local(state);
|
tracker.stop_measurement_thread_local(state);
|
||||||
mutation_calls.call();
|
mutation_calls.call();
|
||||||
if (state.getAllocationDifference() != 0)
|
if (state.getAllocationDifference() != 0)
|
||||||
|
@ -833,17 +957,17 @@ namespace blt::gp
|
||||||
mutation_allocations.call(state.getAllocatedByteDifference());
|
mutation_allocations.call(state.getAllocatedByteDifference());
|
||||||
mutation_allocations.set_value(std::max(mutation_allocations.get_value(), state.getAllocatedByteDifference()));
|
mutation_allocations.set_value(std::max(mutation_allocations.get_value(), state.getAllocatedByteDifference()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (selection_probabilities.reproduction_chance > 0)
|
if (selection_probabilities.reproduction_chance > 0)
|
||||||
{
|
{
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto state = tracker.start_measurement_thread_local();
|
auto state = tracker.start_measurement_thread_local();
|
||||||
#endif
|
#endif
|
||||||
// reproduction
|
// reproduction
|
||||||
c1.copy_fast(reproduction.select(*this, current_pop));
|
c1.copy_fast(reproduction.select(*this, current_pop));
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
tracker.stop_measurement_thread_local(state);
|
tracker.stop_measurement_thread_local(state);
|
||||||
reproduction_calls.call();
|
reproduction_calls.call();
|
||||||
reproduction_calls.value(1);
|
reproduction_calls.value(1);
|
||||||
|
@ -852,7 +976,7 @@ namespace blt::gp
|
||||||
reproduction_allocations.call(state.getAllocatedByteDifference());
|
reproduction_allocations.call(state.getAllocatedByteDifference());
|
||||||
reproduction_allocations.set_value(std::max(reproduction_allocations.get_value(), state.getAllocatedByteDifference()));
|
reproduction_allocations.set_value(std::max(reproduction_allocations.get_value(), state.getAllocatedByteDifference()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,8 +989,7 @@ namespace blt::gp
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Return, blt::size_t size, typename Accessor, blt::size_t... indexes>
|
template <typename Return, blt::size_t size, typename Accessor, blt::size_t... indexes>
|
||||||
Return convert_array(std::array<blt::size_t, size>&& arr, Accessor&& accessor,
|
Return convert_array(std::array<blt::size_t, size>&& arr, Accessor&& accessor, std::integer_sequence<blt::size_t, indexes...>)
|
||||||
std::integer_sequence<blt::size_t, indexes...>)
|
|
||||||
{
|
{
|
||||||
return Return{accessor(arr, indexes)...};
|
return Return{accessor(arr, indexes)...};
|
||||||
}
|
}
|
||||||
|
@ -895,6 +1018,8 @@ namespace blt::gp
|
||||||
double mutation_chance = 0;
|
double mutation_chance = 0;
|
||||||
double reproduction_chance = 0;
|
double reproduction_chance = 0;
|
||||||
|
|
||||||
|
std::optional<size_t> replacement_amount;
|
||||||
|
|
||||||
void update(const prog_config_t& config)
|
void update(const prog_config_t& config)
|
||||||
{
|
{
|
||||||
const auto total = config.crossover_chance + config.mutation_chance + config.reproduction_chance;
|
const auto total = config.crossover_chance + config.mutation_chance + config.reproduction_chance;
|
||||||
|
@ -928,8 +1053,7 @@ namespace blt::gp
|
||||||
blt::barrier barrier;
|
blt::barrier barrier;
|
||||||
|
|
||||||
explicit concurrency_storage(blt::size_t threads): barrier(threads, lifetime_over)
|
explicit concurrency_storage(blt::size_t threads): barrier(threads, lifetime_over)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
} thread_helper{config.threads == 0 ? std::thread::hardware_concurrency() : config.threads};
|
} thread_helper{config.threads == 0 ? std::thread::hardware_concurrency() : config.threads};
|
||||||
|
|
||||||
std::unique_ptr<std::function<void(blt::size_t)>> thread_execution_service = nullptr;
|
std::unique_ptr<std::function<void(blt::size_t)>> thread_execution_service = nullptr;
|
||||||
|
|
|
@ -61,16 +61,16 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < config.elites; i++)
|
for (size_t i = 0; i < config.elites; i++)
|
||||||
{
|
{
|
||||||
if (ind.value.fitness.adjusted_fitness >= values[i].second)
|
if (ind.second.fitness.adjusted_fitness >= values[i].second)
|
||||||
{
|
{
|
||||||
bool doesnt_contain = true;
|
bool doesnt_contain = true;
|
||||||
for (blt::size_t j = 0; j < config.elites; j++)
|
for (blt::size_t j = 0; j < config.elites; j++)
|
||||||
{
|
{
|
||||||
if (ind.index == values[j].first)
|
if (ind.first == values[j].first)
|
||||||
doesnt_contain = false;
|
doesnt_contain = false;
|
||||||
}
|
}
|
||||||
if (doesnt_contain)
|
if (doesnt_contain)
|
||||||
values[i] = {ind.index, ind.value.fitness.adjusted_fitness};
|
values[i] = {ind.first, ind.second.fitness.adjusted_fitness};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,21 +21,16 @@
|
||||||
|
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
#include <blt/std/bump_allocator.h>
|
#include <blt/std/bump_allocator.h>
|
||||||
#include <blt/std/assert.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <blt/std/logging.h>
|
|
||||||
#include <blt/std/allocator.h>
|
#include <blt/std/allocator.h>
|
||||||
#include <blt/std/ranges.h>
|
|
||||||
#include <blt/meta/meta.h>
|
#include <blt/meta/meta.h>
|
||||||
#include <blt/gp/fwdecl.h>
|
#include <blt/gp/util/meta.h>
|
||||||
#include <blt/gp/util/trackers.h>
|
|
||||||
#include <blt/gp/allocator.h>
|
#include <blt/gp/allocator.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <stdexcept>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace blt::gp
|
namespace blt::gp
|
||||||
{
|
{
|
||||||
|
@ -87,7 +82,7 @@ namespace blt::gp
|
||||||
static constexpr size_t aligned_size() noexcept
|
static constexpr size_t aligned_size() noexcept
|
||||||
{
|
{
|
||||||
const auto bytes = detail::aligned_size(sizeof(NO_REF_T<T>));
|
const auto bytes = detail::aligned_size(sizeof(NO_REF_T<T>));
|
||||||
if constexpr (blt::gp::detail::has_func_drop_v<T>)
|
if constexpr (blt::gp::detail::has_func_drop_v<gp::detail::remove_cv_ref<T>>)
|
||||||
return bytes + detail::aligned_size(sizeof(std::atomic_uint64_t*));
|
return bytes + detail::aligned_size(sizeof(std::atomic_uint64_t*));
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +174,7 @@ namespace blt::gp
|
||||||
const auto ptr = static_cast<char*>(allocate_bytes_for_size(aligned_size<NO_REF>()));
|
const auto ptr = static_cast<char*>(allocate_bytes_for_size(aligned_size<NO_REF>()));
|
||||||
std::memcpy(ptr, &t, sizeof(NO_REF));
|
std::memcpy(ptr, &t, sizeof(NO_REF));
|
||||||
|
|
||||||
if constexpr (gp::detail::has_func_drop_v<T>)
|
if constexpr (gp::detail::has_func_drop_v<gp::detail::remove_cv_ref<T>>)
|
||||||
{
|
{
|
||||||
new(ptr + sizeof(NO_REF)) mem::pointer_storage<std::atomic_uint64_t>{nullptr};
|
new(ptr + sizeof(NO_REF)) mem::pointer_storage<std::atomic_uint64_t>{nullptr};
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ namespace blt::gp
|
||||||
|
|
||||||
~evaluation_ref()
|
~evaluation_ref()
|
||||||
{
|
{
|
||||||
if constexpr (detail::has_func_drop_v<T>)
|
if constexpr (detail::has_func_drop_v<detail::remove_cv_ref<T>>)
|
||||||
{
|
{
|
||||||
if (m_value.get() != nullptr)
|
if (m_value.get() != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace blt::gp
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static type make_type(const type_id id)
|
static type make_type(const type_id id)
|
||||||
{
|
{
|
||||||
return type(stack_allocator::aligned_size<T>(), id, blt::type_string<T>(), detail::has_func_drop_v<T>);
|
return type(stack_allocator::aligned_size<T>(), id, blt::type_string<T>(), detail::has_func_drop_v<detail::remove_cv_ref<T>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] size_t size() const
|
[[nodiscard]] size_t size() const
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
#include <blt/gp/generators.h>
|
#include <blt/gp/generators.h>
|
||||||
#include <blt/gp/program.h>
|
#include <blt/gp/program.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
namespace blt::gp
|
namespace blt::gp
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
|
|
||||||
namespace blt::gp
|
namespace blt::gp
|
||||||
{
|
{
|
||||||
void select_best_t::pre_process(gp_program&, population_t& pop)
|
void select_best_t::pre_process(gp_program&, population_t&)
|
||||||
{
|
{
|
||||||
std::sort(pop.begin(), pop.end(), [](const auto& a, const auto& b)
|
// std::sort(pop.begin(), pop.end(), [](const auto& a, const auto& b)
|
||||||
{
|
// {
|
||||||
return a.fitness.adjusted_fitness > b.fitness.adjusted_fitness;
|
// return a.fitness.adjusted_fitness > b.fitness.adjusted_fitness;
|
||||||
});
|
// });
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,19 +35,19 @@ namespace blt::gp
|
||||||
return pop.get_individuals()[index.fetch_add(1, std::memory_order_relaxed) % size].tree;
|
return pop.get_individuals()[index.fetch_add(1, std::memory_order_relaxed) % size].tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_worst_t::pre_process(gp_program&, population_t& pop)
|
void select_worst_t::pre_process(gp_program&, population_t&)
|
||||||
{
|
{
|
||||||
std::sort(pop.begin(), pop.end(), [](const auto& a, const auto& b)
|
// std::sort(pop.begin(), pop.end(), [](const auto& a, const auto& b)
|
||||||
{
|
// {
|
||||||
return a.fitness.adjusted_fitness < b.fitness.adjusted_fitness;
|
// return a.fitness.adjusted_fitness < b.fitness.adjusted_fitness;
|
||||||
});
|
// });
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tree_t& select_worst_t::select(gp_program&, const population_t& pop)
|
const tree_t& select_worst_t::select(gp_program&, const population_t& pop)
|
||||||
{
|
{
|
||||||
const auto size = pop.get_individuals().size();
|
const auto size = pop.get_individuals().size();
|
||||||
return pop.get_individuals()[index.fetch_add(1, std::memory_order_relaxed) % size].tree;
|
return pop.get_individuals()[(size - 1) - (index.fetch_add(1, std::memory_order_relaxed) % size)].tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tree_t& select_random_t::select(gp_program& program, const population_t& pop)
|
const tree_t& select_random_t::select(gp_program& program, const population_t& pop)
|
||||||
|
|
|
@ -145,15 +145,34 @@ namespace blt::gp
|
||||||
size_t mutation_t::mutate_point(gp_program& program, tree_t& c, const tree_t::subtree_point_t node) const
|
size_t mutation_t::mutate_point(gp_program& program, tree_t& c, const tree_t::subtree_point_t node) const
|
||||||
{
|
{
|
||||||
auto& new_tree = tree_t::get_thread_local(program);
|
auto& new_tree = tree_t::get_thread_local(program);
|
||||||
|
#if BLT_DEBUG_LEVEL >= 2
|
||||||
|
auto previous_size = new_tree.size();
|
||||||
|
auto previous_bytes = new_tree.total_value_bytes();
|
||||||
|
#endif
|
||||||
config.generator.get().generate(new_tree, {program, node.type, config.replacement_min_depth, config.replacement_max_depth});
|
config.generator.get().generate(new_tree, {program, node.type, config.replacement_min_depth, config.replacement_max_depth});
|
||||||
|
|
||||||
|
#if BLT_DEBUG_LEVEL >= 2
|
||||||
|
const auto old_op = c.get_operator(node.pos);
|
||||||
|
if (!new_tree.check(detail::debug::context_ptr))
|
||||||
|
{
|
||||||
|
BLT_ERROR("Mutate point new tree check failed!");
|
||||||
|
BLT_ERROR("Old Op: {} got replaced with New Op: {}", program.get_name(old_op.id()).value_or("Unknown"),
|
||||||
|
program.get_name(new_tree.get_operator(0).id()).value_or("Unknown"));
|
||||||
|
BLT_ERROR("Tree started with size: {} and bytes: {}", previous_size, previous_bytes);
|
||||||
|
throw std::runtime_error("Mutate Point tree check failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
c.replace_subtree(node, new_tree);
|
c.replace_subtree(node, new_tree);
|
||||||
|
|
||||||
// this will check to make sure that the tree is in a correct and executable state. it requires that the evaluation is context free!
|
// this will check to make sure that the tree is in a correct and executable state. it requires that the evaluation is context free!
|
||||||
#if BLT_DEBUG_LEVEL >= 2
|
#if BLT_DEBUG_LEVEL >= 2
|
||||||
|
const auto new_op = c.get_operator(node.pos);
|
||||||
if (!c.check(detail::debug::context_ptr))
|
if (!c.check(detail::debug::context_ptr))
|
||||||
{
|
{
|
||||||
print_mutate_stats();
|
print_mutate_stats();
|
||||||
|
BLT_ERROR("Old Op: {} got replaced with New Op: {}", program.get_name(old_op.id()).value_or("Unknown"),
|
||||||
|
program.get_name(new_op.id()).value_or("Unknown"));
|
||||||
throw std::runtime_error("Mutate Point tree check failed");
|
throw std::runtime_error("Mutate Point tree check failed");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
17
src/tree.cpp
17
src/tree.cpp
|
@ -18,7 +18,7 @@
|
||||||
#include <blt/gp/tree.h>
|
#include <blt/gp/tree.h>
|
||||||
#include <blt/gp/stack.h>
|
#include <blt/gp/stack.h>
|
||||||
#include <blt/std/assert.h>
|
#include <blt/std/assert.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <blt/gp/program.h>
|
#include <blt/gp/program.h>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
@ -501,6 +501,7 @@ namespace blt::gp
|
||||||
tree_t& tree_t::get_thread_local(gp_program& program)
|
tree_t& tree_t::get_thread_local(gp_program& program)
|
||||||
{
|
{
|
||||||
thread_local tree_t tree{program};
|
thread_local tree_t tree{program};
|
||||||
|
tree.clear(program);
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,8 +545,8 @@ namespace blt::gp
|
||||||
|
|
||||||
if (bytes_expected != bytes_size)
|
if (bytes_expected != bytes_size)
|
||||||
{
|
{
|
||||||
BLT_ERROR_STREAM << "Stack state: " << values.size() << "\n";
|
BLT_ERROR("Stack state: {}", values.size());
|
||||||
BLT_ERROR("Child tree bytes %ld vs expected %ld, difference: %ld", bytes_size, bytes_expected,
|
BLT_ERROR("Child tree bytes {} vs expected {}, difference: {}", bytes_size, bytes_expected,
|
||||||
static_cast<ptrdiff_t>(bytes_expected) - static_cast<ptrdiff_t>(bytes_size));
|
static_cast<ptrdiff_t>(bytes_expected) - static_cast<ptrdiff_t>(bytes_size));
|
||||||
BLT_ERROR("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
BLT_ERROR("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||||
return false;
|
return false;
|
||||||
|
@ -588,18 +589,18 @@ namespace blt::gp
|
||||||
if (v1 != v2)
|
if (v1 != v2)
|
||||||
{
|
{
|
||||||
const auto vd = std::abs(v1 - v2);
|
const auto vd = std::abs(v1 - v2);
|
||||||
BLT_ERROR("found %ld bytes expected %ld bytes, total difference: %ld", v1, v2, vd);
|
BLT_ERROR("found {} bytes expected {} bytes, total difference: {}", v1, v2, vd);
|
||||||
BLT_ERROR("Total Produced %ld || Total Consumed %ld || Total Difference %ld", total_produced, total_consumed,
|
BLT_ERROR("Total Produced {} || Total Consumed {} || Total Difference {}", total_produced, total_consumed,
|
||||||
std::abs(static_cast<blt::ptrdiff_t>(total_produced) - static_cast<blt::ptrdiff_t>(total_consumed)));
|
std::abs(static_cast<blt::ptrdiff_t>(total_produced) - static_cast<blt::ptrdiff_t>(total_consumed)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
BLT_ERROR("Exception occurred \"%s\"", e.what());
|
BLT_ERROR("Exception occurred \"{}\"", e.what());
|
||||||
BLT_ERROR("Total Produced %ld || Total Consumed %ld || Total Difference %ld", total_produced, total_consumed,
|
BLT_ERROR("Total Produced {} || Total Consumed {} || Total Difference {}", total_produced, total_consumed,
|
||||||
std::abs(static_cast<blt::ptrdiff_t>(total_produced) - static_cast<blt::ptrdiff_t>(total_consumed)));
|
std::abs(static_cast<blt::ptrdiff_t>(total_produced) - static_cast<blt::ptrdiff_t>(total_consumed)));
|
||||||
BLT_ERROR("We failed at index %lu", index);
|
BLT_ERROR("We failed at index {}", index);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <blt/gp/util/trackers.h>
|
#include <blt/gp/util/trackers.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include "blt/format/format.h"
|
#include "blt/format/format.h"
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,194 @@
|
||||||
|
/*
|
||||||
|
* <Short Description>
|
||||||
|
* Copyright (C) 2025 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "../examples/symbolic_regression.h"
|
||||||
|
#include <blt/gp/program.h>
|
||||||
|
#include <blt/logging/logging.h>
|
||||||
|
|
||||||
|
using namespace blt::gp;
|
||||||
|
|
||||||
|
std::atomic_uint64_t normal_construct = 0;
|
||||||
|
std::atomic_uint64_t ephemeral_construct = 0;
|
||||||
|
std::atomic_uint64_t normal_drop = 0;
|
||||||
|
std::atomic_uint64_t ephemeral_drop = 0;
|
||||||
|
std::atomic_uint64_t max_allocated = 0;
|
||||||
|
|
||||||
|
struct drop_type
|
||||||
|
{
|
||||||
|
float* m_value;
|
||||||
|
bool ephemeral = false;
|
||||||
|
|
||||||
|
drop_type() : m_value(new float(0))
|
||||||
|
{
|
||||||
|
++normal_construct;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit drop_type(const float silly) : m_value(new float(silly))
|
||||||
|
{
|
||||||
|
++normal_construct;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit drop_type(const float silly, bool) : m_value(new float(silly)), ephemeral(true)
|
||||||
|
{
|
||||||
|
// BLT_TRACE("Constructor with value %f", silly);
|
||||||
|
++ephemeral_construct;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] float value() const
|
||||||
|
{
|
||||||
|
return *m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drop() const
|
||||||
|
{
|
||||||
|
if (ephemeral)
|
||||||
|
{
|
||||||
|
std::cout << ("Ephemeral drop") << std::endl;
|
||||||
|
++ephemeral_drop;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++normal_drop;
|
||||||
|
delete m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const drop_type& dt)
|
||||||
|
{
|
||||||
|
os << dt.m_value;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct context
|
||||||
|
{
|
||||||
|
float x, y;
|
||||||
|
};
|
||||||
|
|
||||||
|
prog_config_t config = prog_config_t()
|
||||||
|
.set_initial_min_tree_size(2)
|
||||||
|
.set_initial_max_tree_size(6)
|
||||||
|
.set_elite_count(2)
|
||||||
|
.set_crossover_chance(0.8)
|
||||||
|
.set_mutation_chance(0.1)
|
||||||
|
.set_reproduction_chance(0.1)
|
||||||
|
.set_max_generations(50)
|
||||||
|
.set_pop_size(500)
|
||||||
|
.set_thread_count(1);
|
||||||
|
|
||||||
|
|
||||||
|
example::symbolic_regression_t regression{691ul, config};
|
||||||
|
|
||||||
|
operation_t add{[](const drop_type a, const drop_type b) { return drop_type{a.value() + b.value()}; }, "add"};
|
||||||
|
operation_t addf{[](const float a, const float b) { return a + b; }, "addf"};
|
||||||
|
operation_t sub([](const drop_type a, const drop_type b) { return drop_type{a.value() - b.value()}; }, "sub");
|
||||||
|
operation_t subf([](const float a, const float b) { return a - b; }, "subf");
|
||||||
|
operation_t mul([](const drop_type a, const drop_type b) { return drop_type{a.value() * b.value()}; }, "mul");
|
||||||
|
operation_t mulf([](const float a, const float b) { return a * b; }, "mulf");
|
||||||
|
operation_t pro_div([](const drop_type a, const drop_type b) { return drop_type{b.value() == 0.0f ? 0.0f : a.value() / b.value()}; }, "div");
|
||||||
|
operation_t pro_divf([](const float a, const float b) { return b == 0.0f ? 0.0f : a / b; }, "divf");
|
||||||
|
operation_t op_sin([](const drop_type a) { return drop_type{std::sin(a.value())}; }, "sin");
|
||||||
|
operation_t op_sinf([](const float a) { return std::sin(a); }, "sinf");
|
||||||
|
operation_t op_cos([](const drop_type a) { return drop_type{std::cos(a.value())}; }, "cos");
|
||||||
|
operation_t op_cosf([](const float a) { return std::cos(a); }, "cosf");
|
||||||
|
operation_t op_exp([](const drop_type a) { return drop_type{std::exp(a.value())}; }, "exp");
|
||||||
|
operation_t op_expf([](const float a) { return std::exp(a); }, "expf");
|
||||||
|
operation_t op_log([](const drop_type a) { return drop_type{a.value() <= 0.0f ? 0.0f : std::log(a.value())}; }, "log");
|
||||||
|
operation_t op_logf([](const float a) { return a <= 0.0f ? 0.0f : std::log(a); }, "logf");
|
||||||
|
operation_t op_tof([](const drop_type a) { return a.value(); }, "to_f");
|
||||||
|
operation_t op_todrop([](const float a) { return drop_type{a}; }, "to_drop");
|
||||||
|
operation_t op_mixed_input([](const drop_type a, const float f)
|
||||||
|
{
|
||||||
|
return a.value() + f;
|
||||||
|
}, "mixed_input");
|
||||||
|
auto lit = operation_t([]()
|
||||||
|
{
|
||||||
|
return drop_type{regression.get_program().get_random().get_float(-1.0f, 1.0f), true};
|
||||||
|
}, "lit").set_ephemeral();
|
||||||
|
|
||||||
|
auto litf = operation_t([]()
|
||||||
|
{
|
||||||
|
return regression.get_program().get_random().get_float(-1.0f, 1.0f);
|
||||||
|
}, "litf").set_ephemeral();
|
||||||
|
|
||||||
|
operation_t op_x([](const context& context)
|
||||||
|
{
|
||||||
|
return drop_type{context.x};
|
||||||
|
}, "x");
|
||||||
|
|
||||||
|
operation_t op_xf([](const context& context)
|
||||||
|
{
|
||||||
|
return context.x;
|
||||||
|
}, "xf");
|
||||||
|
|
||||||
|
bool fitness_function(const tree_t& current_tree, fitness_t& fitness, size_t)
|
||||||
|
{
|
||||||
|
if (normal_construct - normal_drop > max_allocated)
|
||||||
|
max_allocated = normal_construct - normal_drop;
|
||||||
|
constexpr static double value_cutoff = 1.e15;
|
||||||
|
for (auto& fitness_case : regression.get_training_cases())
|
||||||
|
{
|
||||||
|
BLT_GP_UPDATE_CONTEXT(fitness_case);
|
||||||
|
auto val = current_tree.get_evaluation_ref<drop_type>(fitness_case);
|
||||||
|
const auto diff = std::abs(fitness_case.y - val.get().value());
|
||||||
|
if (diff < value_cutoff)
|
||||||
|
{
|
||||||
|
fitness.raw_fitness += diff;
|
||||||
|
if (diff <= 0.01)
|
||||||
|
fitness.hits++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fitness.raw_fitness += value_cutoff;
|
||||||
|
}
|
||||||
|
fitness.standardized_fitness = fitness.raw_fitness;
|
||||||
|
fitness.adjusted_fitness = (1.0 / (1.0 + fitness.standardized_fitness));
|
||||||
|
return static_cast<size_t>(fitness.hits) == regression.get_training_cases().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
operator_builder<context> builder{};
|
||||||
|
builder.build(add, sub, mul, pro_div, op_sin, op_cos, op_exp, op_log, op_mixed_input, lit, op_x, addf, subf, mulf, pro_divf, op_sinf, op_cosf,
|
||||||
|
op_expf, op_logf,
|
||||||
|
litf, op_xf, op_tof, op_todrop);
|
||||||
|
regression.get_program().set_operations(builder.grab());
|
||||||
|
|
||||||
|
auto& program = regression.get_program();
|
||||||
|
static auto sel = select_tournament_t{};
|
||||||
|
program.generate_initial_population(program.get_typesystem().get_type<drop_type>().id());
|
||||||
|
program.setup_generational_evaluation(fitness_function, sel, sel, sel);
|
||||||
|
while (!program.should_terminate())
|
||||||
|
{
|
||||||
|
BLT_TRACE("---------------\\{Begin Generation {}}---------------", program.get_current_generation());
|
||||||
|
BLT_TRACE("Creating next generation");
|
||||||
|
program.create_next_generation();
|
||||||
|
BLT_TRACE("Move to next generation");
|
||||||
|
program.next_generation();
|
||||||
|
BLT_TRACE("Evaluate Fitness");
|
||||||
|
program.evaluate_fitness();
|
||||||
|
}
|
||||||
|
|
||||||
|
// program.get_best_individuals<1>()[0].get().tree.print(program, std::cout, true, true);
|
||||||
|
|
||||||
|
regression.get_program().get_current_pop().clear();
|
||||||
|
regression.get_program().next_generation();
|
||||||
|
regression.get_program().get_current_pop().clear();
|
||||||
|
|
||||||
|
BLT_TRACE("Created {} times", normal_construct.load());
|
||||||
|
BLT_TRACE("Dropped {} times", normal_drop.load());
|
||||||
|
BLT_TRACE("Ephemeral created {} times", ephemeral_construct.load());
|
||||||
|
BLT_TRACE("Ephemeral dropped {} times", ephemeral_drop.load());
|
||||||
|
BLT_TRACE("Max allocated {} times", max_allocated.load());
|
||||||
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
#include "../examples/symbolic_regression.h"
|
#include "../examples/symbolic_regression.h"
|
||||||
#include <blt/gp/program.h>
|
#include <blt/gp/program.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
|
|
||||||
using namespace blt::gp;
|
using namespace blt::gp;
|
||||||
|
|
||||||
|
@ -140,10 +140,11 @@ int main()
|
||||||
|
|
||||||
auto& program = regression.get_program();
|
auto& program = regression.get_program();
|
||||||
static auto sel = select_tournament_t{};
|
static auto sel = select_tournament_t{};
|
||||||
program.generate_population(program.get_typesystem().get_type<drop_type>().id(), fitness_function, sel, sel, sel);
|
program.generate_initial_population(program.get_typesystem().get_type<drop_type>().id());
|
||||||
|
program.setup_generational_evaluation(fitness_function, sel, sel, sel);
|
||||||
while (!program.should_terminate())
|
while (!program.should_terminate())
|
||||||
{
|
{
|
||||||
BLT_TRACE("---------------{Begin Generation %lu}---------------", program.get_current_generation());
|
BLT_TRACE("---------------\\{Begin Generation {}}---------------", program.get_current_generation());
|
||||||
BLT_TRACE("Creating next generation");
|
BLT_TRACE("Creating next generation");
|
||||||
program.create_next_generation();
|
program.create_next_generation();
|
||||||
BLT_TRACE("Move to next generation");
|
BLT_TRACE("Move to next generation");
|
||||||
|
@ -158,10 +159,10 @@ int main()
|
||||||
regression.get_program().next_generation();
|
regression.get_program().next_generation();
|
||||||
regression.get_program().get_current_pop().clear();
|
regression.get_program().get_current_pop().clear();
|
||||||
|
|
||||||
BLT_TRACE("Created %ld times", normal_construct.load());
|
BLT_TRACE("Created {} times", normal_construct.load());
|
||||||
BLT_TRACE("Dropped %ld times", normal_drop.load());
|
BLT_TRACE("Dropped {} times", normal_drop.load());
|
||||||
BLT_TRACE("Ephemeral created %ld times", ephemeral_construct.load());
|
BLT_TRACE("Ephemeral created {} times", ephemeral_construct.load());
|
||||||
BLT_TRACE("Ephemeral dropped %ld times", ephemeral_drop.load());
|
BLT_TRACE("Ephemeral dropped {} times", ephemeral_drop.load());
|
||||||
BLT_TRACE("Max allocated %ld times", max_allocated.load());
|
BLT_TRACE("Max allocated {} times", max_allocated.load());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <sstream>
|
||||||
#include <blt/profiling/profiler_v2.h>
|
#include <blt/profiling/profiler_v2.h>
|
||||||
|
|
||||||
static const auto SEED_FUNC = [] { return std::random_device()(); };
|
static const auto SEED_FUNC = [] { return std::random_device()(); };
|
||||||
|
@ -56,7 +57,7 @@ void run(const blt::gp::prog_config_t& config)
|
||||||
auto mut = mutation_calls.start_measurement();
|
auto mut = mutation_calls.start_measurement();
|
||||||
auto repo = reproduction_calls.start_measurement();
|
auto repo = reproduction_calls.start_measurement();
|
||||||
#endif
|
#endif
|
||||||
BLT_TRACE("------------{Begin Generation %ld}------------", program.get_current_generation());
|
BLT_TRACE("------------\\{Begin Generation {}}------------", program.get_current_generation());
|
||||||
BLT_TRACE("Creating next generation");
|
BLT_TRACE("Creating next generation");
|
||||||
BLT_START_INTERVAL("Symbolic Regression", "Create Next Generation");
|
BLT_START_INTERVAL("Symbolic Regression", "Create Next Generation");
|
||||||
program.create_next_generation();
|
program.create_next_generation();
|
||||||
|
@ -71,7 +72,7 @@ void run(const blt::gp::prog_config_t& config)
|
||||||
BLT_END_INTERVAL("Symbolic Regress", "Evaluate Fitness");
|
BLT_END_INTERVAL("Symbolic Regress", "Evaluate Fitness");
|
||||||
BLT_START_INTERVAL("Symbolic Regress", "Fitness Print");
|
BLT_START_INTERVAL("Symbolic Regress", "Fitness Print");
|
||||||
const auto& stats = program.get_population_stats();
|
const auto& stats = program.get_population_stats();
|
||||||
BLT_TRACE("Avg Fit: %lf, Best Fit: %lf, Worst Fit: %lf, Overall Fit: %lf",
|
BLT_TRACE("Avg Fit: {}, Best Fit: {}, Worst Fit: {}, Overall Fit: {}",
|
||||||
stats.average_fitness.load(std::memory_order_relaxed), stats.best_fitness.load(std::memory_order_relaxed),
|
stats.average_fitness.load(std::memory_order_relaxed), stats.best_fitness.load(std::memory_order_relaxed),
|
||||||
stats.worst_fitness.load(std::memory_order_relaxed), stats.overall_fitness.load(std::memory_order_relaxed));
|
stats.worst_fitness.load(std::memory_order_relaxed), stats.overall_fitness.load(std::memory_order_relaxed));
|
||||||
BLT_END_INTERVAL("Symbolic Regress", "Fitness Print");
|
BLT_END_INTERVAL("Symbolic Regress", "Fitness Print");
|
||||||
|
@ -123,17 +124,8 @@ void do_run()
|
||||||
.set_pop_size(population_sizes)
|
.set_pop_size(population_sizes)
|
||||||
.set_thread_count(0);
|
.set_thread_count(0);
|
||||||
|
|
||||||
BLT_INFO_STREAM << "Run: Crossover (";
|
BLT_INFO("Run: Crossover ({}) Mutation ({}) Reproduction ({}) Elite ({}) Population Size ({})", crossover_chance,
|
||||||
BLT_INFO_STREAM << crossover_chance;
|
mutation_chance, reproduction_chance, elite_amount, population_sizes);
|
||||||
BLT_INFO_STREAM << ") Mutation (";
|
|
||||||
BLT_INFO_STREAM << mutation_chance;
|
|
||||||
BLT_INFO_STREAM << ") Reproduction (";
|
|
||||||
BLT_INFO_STREAM << reproduction_chance;
|
|
||||||
BLT_INFO_STREAM << ") Elite (";
|
|
||||||
BLT_INFO_STREAM << elite_amount;
|
|
||||||
BLT_INFO_STREAM << ") Population Size (";
|
|
||||||
BLT_INFO_STREAM << population_sizes;
|
|
||||||
BLT_INFO_STREAM << ")" << "\n";
|
|
||||||
run(config);
|
run(config);
|
||||||
|
|
||||||
results << "Run: Crossover (";
|
results << "Run: Crossover (";
|
||||||
|
|
Loading…
Reference in New Issue