public VMTaskFitnessCalculator asSoftConstraint() {
        return new VMTaskFitnessCalculator() {
            @Override
            public String getName() {
                return name;
            }

            @Override
            public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
                String targetHostAttrVal = AttributeUtilities.getAttrValue(targetVM.getCurrAvailableResources(), hostAttributeName);
                if(targetHostAttrVal==null || targetHostAttrVal.isEmpty()) {
                    return 0.0;
                }
                Set<String> coTasks = coTasksGetter.call(taskRequest.getId());
                Map<String, Integer> usedAttribsMap = null;
                try {
                    usedAttribsMap = getUsedAttributesMap(coTasks, taskTrackerState);
                } catch (Exception e) {
                    return 0.0;
                }
                final Integer integer = usedAttribsMap.get(targetHostAttrVal);
                if(integer==null)
                    return 1.0;
                if(usedAttribsMap.isEmpty())
                    return 1.0;
                double avg=0.0;
                for(Integer i: usedAttribsMap.values())
                    avg += i;
                avg = Math.ceil(avg+1 / Math.max(expectedValues, usedAttribsMap.size()));
                if(integer<=avg)
                    return (avg-(double)integer) / avg;
                return 0.0;
            }
        };
    }
public VMTaskFitnessCalculator asSoftConstraint() {
        return new VMTaskFitnessCalculator() {
            @Override
            public String getName() {
                return name;
            }

            @Override
            public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
                String targetHostAttrVal = AttributeUtilities.getAttrValue(targetVM.getCurrAvailableResources(), hostAttributeName);
                if(targetHostAttrVal==null || targetHostAttrVal.isEmpty()) {
                    return 0.0;
                }
                Set<String> coTasks = coTasksGetter.call(taskRequest.getId());
                Map<String, Integer> usedAttribsMap = null;
                try {
                    usedAttribsMap = getUsedAttributesMap(coTasks, taskTrackerState);
                } catch (Exception e) {
                    return 0.0;
                }
                final Integer integer = usedAttribsMap.get(targetHostAttrVal);
                if(integer==null)
                    return 1.0;
                if(usedAttribsMap.isEmpty())
                    return 1.0;
                double avg=0.0;
                for(Integer i: usedAttribsMap.values())
                    avg += i;
                avg = Math.ceil(avg+1 / Math.max(expectedValues, usedAttribsMap.size()));
                if(integer<=avg)
                    return (avg-(double)integer) / avg;
                return 0.0;
            }
        };
    }
public VMTaskFitnessCalculator asSoftConstraint ( ) { return new VMTaskFitnessCalculator ( ) { @ Override public String getName ( ) { return name ; } @ Override public double calculateFitness ( TaskRequest taskRequest , VirtualMachineCurrentState targetVM , TaskTrackerState taskTrackerState ) { String targetHostAttrVal = AttributeUtilities . getAttrValue ( targetVM . getCurrAvailableResources ( ) , hostAttributeName ) ; if ( targetHostAttrVal == null || targetHostAttrVal . isEmpty ( ) ) { return 0.0 ; } Set < String > coTasks = coTasksGetter . call ( taskRequest . getId ( ) ) ; Map < String , Integer > usedAttribsMap = null ; try { usedAttribsMap = getUsedAttributesMap ( coTasks , taskTrackerState ) ; } catch ( Exception e ) { return 0.0 ; } final Integer integer = usedAttribsMap . get ( targetHostAttrVal ) ; if ( integer == null ) return 1.0 ; if ( usedAttribsMap . isEmpty ( ) ) return 1.0 ; double avg = 0.0 ; for ( Integer i : usedAttribsMap . values ( ) ) avg += i ; avg = Math . ceil ( avg + 1 / Math . max ( expectedValues , usedAttribsMap . size ( ) ) ) ; if ( integer <= avg ) return ( avg - ( double ) integer ) / avg ; return 0.0 ; } } ; }
Converts this constraint into a "soft" constraint. By default, a balanced host attribute constraint is a
"hard" constraint, which is to say that Fenzo will guarantee that the constraint is applied and will fail
to place a task if the only way it can do so is to violate the constraint. This method returns a
{@link VMTaskFitnessCalculator} that represents this constraint as a "soft" constraint that will permit
Fenzo to place a task in violation of the constraint if it cannot do so otherwise.

@return a task fitness calculator that represents the balanced host attribute constraint as a soft
constraint
Converts this constraint into a soft constraint . By default a balanced host attribute constraint is a hard constraint which is to say that Fenzo will guarantee that the constraint is applied and will fail to place a task if the only way it can do so is to violate the constraint . This method returns a { @link VMTaskFitnessCalculator } that represents this constraint as a soft constraint that will permit Fenzo to place a task in violation of the constraint if it cannot do so otherwise .