Fitness Normalizers
The following describes how to use fitness normalizers.
A normalizer's purpose is for reducing the fitness data to its canonical form to bring the fitnesses evaluated according to different factors to a common scale. This is achieved by calculating the percentage that a fitness value represents out of the total of the fitnesses for all locations according to a factor.
Reverse Normalizers
Some factors have a negative correlation with fitness. For example, a shorter distance (although more fit) will have a lower numerical value. By using fractional arithmetic logic (complement of a proper fraction) we compute the complement of the real fitness which will yield a higher numerical value that positively correlates with fitness.
API
FitnessNormalizer.java:
public interface FitnessNormalizer
{
/**
* Normalize the fitness out of 100.
*
* @param fitness
* - the evaluated fitness value or {@link Double#NaN} if undefined
* @param total
* - the sum of all evaluated fitness values for a given sourcing factor or {@link Double#NaN} if
* undefined; must be greater than 0
* @return the normalized fitness or zero if the fitness is {@link Double#NaN}
* @throws IllegalArgumentException
* when the fitness is null or negative or when the total is null, zero or negative
*/
Double normalize(Double fitness, Double total) throws IllegalArgumentException;
}
Default Implementation
Out-of-the-box, SAP Commerce Cloud provides two implementations of the normalizer:
- Default normalizer: Normalize the fitness value by dividing it by the given total and multiplying by 100 to produce a percentage.
- Reverse normalizer: Normalize the fitness value by dividing it by the given total and multiplying by 100 to produce a percentage. Then subtracting that percentage from 100 to produce a reverse value. This is useful for when a smaller fitness value should be better than a large fitness value.
Fitness Normalizer Factory
The FitnessNormalizerFactory gets the proper normalizer for a sourcing factor.
FitnessNormalizerFactory.java:
public interface FitnessNormalizerFactory
{
/**
* Gets the appropriate normalizer implementation for a sourcing factor
*
* @param factorId
* the sourcing factor id
* @return the normalizer
*/
FitnessNormalizer getNormalizer(SourcingFactorIdentifiersEnum factorId);
}
Spring Configuration
warehousing-spring.xml:
... <!-- Fitness Normalizing --> <bean id="defaultNormalizer" class="de.hybris.platform.warehousing.sourcing.fitness.normalize.impl.DefaultFitnessNormalizer" /> <bean id="reverseNormalizer" class="de.hybris.platform.warehousing.sourcing.fitness.normalize.impl.ReverseFitnessNormalizer" /> <alias name="defaultFitnessNormalizerMap" alias="fitnessNormalizerMap" /> <util:map id="defaultFitnessNormalizerMap"> <entry value-ref="reverseNormalizer"> <key> <util:constant static-field="de.hybris.platform.warehousing.data.sourcing.SourcingFactorIdentifiersEnum.DISTANCE"/> </key> </entry> <entry value-ref="reverseNormalizer"> <key> <util:constant static-field="de.hybris.platform.warehousing.data.sourcing.SourcingFactorIdentifiersEnum.PRIORITY"/> </key> </entry> <entry value-ref="reverseNormalizer"> <key> <util:constant static-field="de.hybris.platform.warehousing.data.sourcing.SourcingFactorIdentifiersEnum.ALLOCATION"/> </key> </entry> </util:map> <alias name="defaultFitnessNormalizerFactory" alias="fitnessNormalizerFactory" /> <bean id="defaultFitnessNormalizerFactory" class="de.hybris.platform.warehousing.sourcing.fitness.normalize.impl.DefaultFitnessNormalizerFactory"> <property name="fitnessNormalizerMap" ref="fitnessNormalizerMap" /> </bean> ...
Extending Normalizers
You can add more Normalizers by doing the following:
- Create a new Spring bean defining your new implementation of the FitnessNormalizer interface.
-
Add it to the fitnessNormalizerMap.
Example:
warehousing-spring.xml
... <alias name="defaultCustomNormalizer" alias="customNormalizer" /> <bean id="defaultCustomNormalizer" class="package.DefaultCustomNormalizer" /> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"><ref local="fitnessNormalizerMap"/></property> <property name="targetMethod"><value>put</value></property> <property name="arguments"> <list> <value> <util:constant static-field="de.hybris.platform.warehousing.data.sourcing.SourcingFactorIdentifiersEnum.CUSTOMFACTOR"/> </value> <ref bean="customNormalizer"/> </list> </property> </bean> ...