Class NormBasedGapFunction

  • All Implemented Interfaces:
    Serializable, Comparable<IdAble>, EventListener, PlanitComponentListener, EventListener, ExternalIdAble, IdAble

    public class NormBasedGapFunction
    extends GapFunction
    Gap function based on the norm, e.g. ||x||_p where p indicates which norm (norm 1, norm 2 etc) and x represents a vector of differences between two values. When averaged (default) we divide the result by the number of elements in the vector. e.g. for the average norm 1 we would compute: 1/|x| * ( (x_1-x_1_alt) + (x_2-x_2_alt) + .... + (x_n-x_n_alt)), whereas for the averaged norm 2 we would do: 1/|x| * sqrt( (x_1-x_1_alt)^2 + (x_2-x_2_alt)^2 + .... + (x_n-x_n_alt)^2) etc.
    Author:
    markr
    See Also:
    Serialized Form
    • Field Detail

      • norm

        protected int norm
        which norm we are taking, e.g. 1,2,p
      • averaged

        protected boolean averaged
        indicate if the result is to be averaged
      • measuredValue

        protected double measuredValue
        Current value as it stands
      • count

        protected double count
        Represents the total entries that were measured so far
      • gap

        protected double gap
        gap
      • DEFAULT_NORM

        public static final int DEFAULT_NORM
        default norm is set to 1
        See Also:
        Constant Field Values
      • DEFAULT_AVERAGED

        public static final boolean DEFAULT_AVERAGED
        default we average the result
        See Also:
        Constant Field Values
    • Constructor Detail

      • NormBasedGapFunction

        public NormBasedGapFunction​(IdGroupingToken idToken,
                                    StopCriterion stopCriterion)
        Constructor with defaults for norm and averaged
        Parameters:
        idToken - to use for the generation of its id
        stopCriterion - StopCriterion object being used
      • NormBasedGapFunction

        public NormBasedGapFunction​(IdGroupingToken idToken,
                                    StopCriterion stopCriterion,
                                    int norm)
        Constructor with default for averaged
        Parameters:
        idToken - to use for the generation of its id
        stopCriterion - StopCriterion object being used
        norm - to use
      • NormBasedGapFunction

        public NormBasedGapFunction​(IdGroupingToken idToken,
                                    StopCriterion stopCriterion,
                                    int norm,
                                    boolean averaged)
        Constructor
        Parameters:
        idToken - to use for the generation of its id
        stopCriterion - StopCriterion object being used
        norm - to use
        averaged - to use
      • NormBasedGapFunction

        public NormBasedGapFunction​(NormBasedGapFunction other,
                                    boolean deepCopy)
        Copy constructor
        Parameters:
        other - to copy
        deepCopy - when true, create a deep copy, shallow copy otherwise
    • Method Detail

      • getMeasuredValue

        public double getMeasuredValue()
        Return the actual system travel time
        Returns:
        the actual system travel time
      • increaseMeasuredValue

        public void increaseMeasuredValue​(double[] vector1,
                                          double[] vector2)
        Increase value by abs(value1-value2)^p, where p is the norm set. Note that every call to this method also increases the count
        Parameters:
        vector1 - first value vector
        vector2 - second value vector
      • increaseMeasuredValue

        public void increaseMeasuredValue​(double value1,
                                          double value2)
        Increase value by abs(value1-value2)^p, where p is the norm set. Note that every call to this method also increases the count
        Parameters:
        value1 - first value
        value2 - second value
      • computeGap

        public double computeGap()
        Compute the gap
        Specified by:
        computeGap in class GapFunction
        Returns:
        the gap for the current iteration
      • getGap

        public double getGap()
        Returns the last computed gap
        Specified by:
        getGap in class GapFunction
        Returns:
        latest gap
      • deepClone

        public NormBasedGapFunction deepClone()
        deep clone on planit component should attempt to also update internal dependencies between deep cloned containers where possible
        Specified by:
        deepClone in interface IdAble
        Specified by:
        deepClone in class GapFunction
        Returns:
        deep copy of entity
      • collectSettingsAsKeyValueMap

        public Map<String,​String> collectSettingsAsKeyValueMap()
        Provide all the settings of this particular component by name and value, where each value is a string representation of the underlying entity
        Overrides:
        collectSettingsAsKeyValueMap in class GapFunction
        Returns:
        name-value map of all (user configurable) settings
      • getNorm

        public int getNorm()
      • setNorm

        public void setNorm​(int norm)
      • isAveraged

        public boolean isAveraged()
      • setAveraged

        public void setAveraged​(boolean averaged)