@@ -744,6 +744,79 @@ class Callback
744744 MatType& /* coordinates */ )
745745 { return false ; }
746746
747+ /* *
748+ * Invoke the GenerationalStepTaken() callback if it exists.
749+ * Specialization for MultiObjective case.
750+ *
751+ * @param callback The callback to call.
752+ * @param optimizer The optimizer used to update the function.
753+ * @param function Function to optimize.
754+ * @param coordinates Starting point.
755+ * @param objectives The set of calculated objectives so far.
756+ * @param frontIndices The indices of the members belonging to Pareto Front.
757+ */
758+ template <typename CallbackType,
759+ typename OptimizerType,
760+ typename FunctionType,
761+ typename MatType,
762+ typename ObjectivesVecType,
763+ typename IndicesType>
764+ static typename std::enable_if<
765+ callbacks::traits::HasGenerationalStepTakenSignature<
766+ CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
767+ IndicesType>::hasBool, bool >::type
768+ GenerationalStepTakenFunction (CallbackType& callback,
769+ OptimizerType& optimizer,
770+ FunctionType& function,
771+ MatType& coordinates,
772+ ObjectivesVecType& objectives,
773+ IndicesType& frontIndices)
774+ {
775+ return const_cast <CallbackType&>(callback).GenerationalStepTaken (
776+ optimizer, function, coordinates, objectives, frontIndices);
777+ }
778+
779+ template <typename CallbackType,
780+ typename OptimizerType,
781+ typename FunctionType,
782+ typename MatType,
783+ typename ObjectivesVecType,
784+ typename IndicesType>
785+ static typename std::enable_if<
786+ callbacks::traits::HasGenerationalStepTakenSignature<
787+ CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
788+ IndicesType>::hasVoid, bool >::type
789+ GenerationalStepTakenFunction (CallbackType& callback,
790+ OptimizerType& optimizer,
791+ FunctionType& function,
792+ MatType& coordinates,
793+ ObjectivesVecType& objectives,
794+ IndicesType& frontIndices)
795+ {
796+ const_cast <CallbackType&>(callback).GenerationalStepTaken (
797+ optimizer, function, coordinates, objectives, frontIndices);
798+
799+ return false ;
800+ }
801+
802+ template <typename CallbackType,
803+ typename OptimizerType,
804+ typename FunctionType,
805+ typename MatType,
806+ typename ObjectivesVecType,
807+ typename IndicesType>
808+ static typename std::enable_if<
809+ callbacks::traits::HasGenerationalStepTakenSignature<
810+ CallbackType, OptimizerType, FunctionType, MatType, ObjectivesVecType,
811+ IndicesType>::hasNone, bool >::type
812+ GenerationalStepTakenFunction (CallbackType& /* callback */ ,
813+ OptimizerType& /* optimizer */ ,
814+ FunctionType& /* function */ ,
815+ MatType& /* coordinates */ ,
816+ ObjectivesVecType& /* objectives */ ,
817+ IndicesType& /* frontIndices */ )
818+ { return false ; }
819+
747820 /* *
748821 * Iterate over the callbacks and invoke the StepTaken() callback if it
749822 * exists.
@@ -769,8 +842,41 @@ class Callback
769842 function, coordinates)... };
770843 return result;
771844 }
772- };
773845
846+ /* *
847+ * Iterate over the callbacks and invoke the GenerationalStepTaken() callback if it
848+ * exists.
849+ *
850+ * Specialization for MultiObjective case.
851+ *
852+ * @param optimizer The optimizer used to update the function.
853+ * @param function Function to optimize.
854+ * @param coordinates Starting point.
855+ * @param objectives The set of calculated objectives so far.
856+ * @param frontIndices The indices of the members belonging to Pareto Front.
857+ * @param callbacks The callbacks container.
858+ */
859+ template <typename OptimizerType,
860+ typename FunctionType,
861+ typename ObjectivesVecType,
862+ typename IndicesType,
863+ typename MatType,
864+ typename ...CallbackTypes>
865+ static bool GenerationalStepTaken (OptimizerType& optimizer,
866+ FunctionType& functions,
867+ MatType& coordinates,
868+ ObjectivesVecType& objectives,
869+ IndicesType& frontIndices,
870+ CallbackTypes&... callbacks)
871+ {
872+ // This will return immediately once a callback returns true.
873+ bool result = false ;
874+ (void )std::initializer_list<bool >{ result =
875+ result || Callback::GenerationalStepTakenFunction (callbacks, optimizer,
876+ functions, coordinates, objectives, frontIndices)... };
877+ return result;
878+ }
879+ };
774880} // namespace ens
775881
776882#endif
0 commit comments