Package org.goplanit.gap
Class NormBasedGapFunction
- java.lang.Object
-
- org.goplanit.component.PlanitComponent<GapFunction>
-
- org.goplanit.gap.GapFunction
-
- org.goplanit.gap.NormBasedGapFunction
-
- All Implemented Interfaces:
Serializable
,Cloneable
,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 Summary
Fields Modifier and Type Field Description protected boolean
averaged
indicate if the result is to be averagedprotected double
count
Represents the total entries that were measured so farstatic boolean
DEFAULT_AVERAGED
default we average the resultstatic int
DEFAULT_NORM
default norm is set to 1protected double
gap
gapstatic double
MAX_GAP
maximum gap possibleprotected double
measuredValue
Current value as it standsprotected int
norm
which norm we are taking, e.g.-
Fields inherited from class org.goplanit.gap.GapFunction
LINK_BASED_RELATIVE_GAP, NORM_BASED_GAP, stopCriterion
-
-
Constructor Summary
Constructors Constructor Description NormBasedGapFunction(NormBasedGapFunction other)
Copy constructorNormBasedGapFunction(IdGroupingToken idToken, StopCriterion stopCriterion)
Constructor with defaults for norm and averagedNormBasedGapFunction(IdGroupingToken idToken, StopCriterion stopCriterion, int norm)
Constructor with default for averagedNormBasedGapFunction(IdGroupingToken idToken, StopCriterion stopCriterion, int norm, boolean averaged)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NormBasedGapFunction
clone()
Create a shallow copy of this entitydouble
computeGap()
Compute the gapdouble
getGap()
Returns the last computed gapdouble
getMeasuredValue()
Return the actual system travel timeint
getNorm()
void
increaseMeasuredValue(double[] vector1, double[] vector2)
Increase value by abs(value1-value2)^p, where p is the norm set.void
increaseMeasuredValue(double value1, double value2)
Increase value by abs(value1-value2)^p, where p is the norm set.boolean
isAveraged()
void
reset()
Resetvoid
setAveraged(boolean averaged)
void
setNorm(int norm)
-
Methods inherited from class org.goplanit.gap.GapFunction
getStopCriterion, hasConverged
-
Methods inherited from class org.goplanit.component.PlanitComponent
equals, getComponentType, getExternalId, getId, getIdGroupingToken, getKnownSupportedEventTypes, getXmlId, hashCode, onPlanitComponentEvent, setExternalId, setXmlId
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.goplanit.utils.event.EventListener
hasKnownSupportedEventTypes
-
Methods inherited from interface org.goplanit.utils.id.ExternalIdAble
hasExternalId, hasXmlId
-
Methods inherited from interface org.goplanit.utils.id.IdAble
compareTo, idEquals, idHashCode
-
-
-
-
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
-
MAX_GAP
public static final double MAX_GAP
maximum gap possible- See Also:
- Constant Field Values
-
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 idstopCriterion
- 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 idstopCriterion
- StopCriterion object being usednorm
- to use
-
NormBasedGapFunction
public NormBasedGapFunction(IdGroupingToken idToken, StopCriterion stopCriterion, int norm, boolean averaged)
Constructor- Parameters:
idToken
- to use for the generation of its idstopCriterion
- StopCriterion object being usednorm
- to useaveraged
- to use
-
NormBasedGapFunction
public NormBasedGapFunction(NormBasedGapFunction other)
Copy constructor- Parameters:
other
- to copy
-
-
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 vectorvector2
- 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 valuevalue2
- second value
-
reset
public void reset()
Reset- Specified by:
reset
in classGapFunction
-
computeGap
public double computeGap()
Compute the gap- Specified by:
computeGap
in classGapFunction
- Returns:
- the gap for the current iteration
-
getGap
public double getGap()
Returns the last computed gap- Specified by:
getGap
in classGapFunction
- Returns:
- latest gap
-
clone
public NormBasedGapFunction clone()
Create a shallow copy of this entity- Specified by:
clone
in interfaceIdAble
- Specified by:
clone
in classGapFunction
- Returns:
- shallow copy of entity
-
getNorm
public int getNorm()
-
setNorm
public void setNorm(int norm)
-
isAveraged
public boolean isAveraged()
-
setAveraged
public void setAveraged(boolean averaged)
-
-