org.hd.d.pg2k.ai.scorer
Class ScorerParamInteger

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.ScorerParamInteger
All Implemented Interfaces:
ScorerParam, MemoryTools.Internable

public final class ScorerParamInteger
extends java.lang.Object
implements ScorerParam, MemoryTools.Internable

Immutable (int) Scorer parameter. We make the class Internable to control instance count and thus save some memory for at least some values.


Field Summary
 boolean biasedLow
          If true, mutations are biased towards reducing the parameter value.
 int def
          Default value for this parameter; no smaller than min, no larger than max.
 int delta
          The size of a small change during mutation; strictly positive.
 int max
          Maximum legal value for this parameter; no smaller than min.
 int min
          Minimum legal value for this parameter; no larger than max.
 java.lang.String name
          Parameter name with allowed syntax as for Java variable name; never null.
 int value
          Parameter value in inclusive/closed range [min,max].
 
Constructor Summary
private ScorerParamInteger(int min, int def, int max, int delta, boolean biasedLow, java.lang.String name)
          Construct with the default value.
private ScorerParamInteger(int min, int def, int max, int delta, boolean biasedLow, java.lang.String name, int value)
          Construct with all components, validated and stored as-is.
private ScorerParamInteger(int min, int def, int max, java.lang.String name)
          Construct with the default value, no bias and a unit delta.
 
Method Summary
static ScorerParamInteger createScorerParamInteger(int min, int def, int max, int delta, boolean biasedLow, java.lang.String name)
          Get instance with the default value, and specified bias and delta; never null.
static ScorerParamInteger createScorerParamInteger(int min, int def, int max, int delta, boolean biasedLow, java.lang.String name, int value)
          Get instance with the default value, and specified bias and delta; never null.
static ScorerParamInteger createScorerParamInteger(int min, int def, int max, java.lang.String name)
          Get instance with the default value, no bias and a unit delta; never null.
 boolean equals(java.lang.Object obj)
          Equality depends on all fields.
 ScorerParam extract(ScorerParam p)
          Use the supplied parameter if possible (correct name/type/bounds), else return the default; never null.
 java.lang.String getName()
          Get the parameter name; never null or empty.
 int hashCode()
          The hash depends on the name and the value as the most variable components.
 ScorerParam parse(java.lang.String v)
          Parse the String representation of a parameter returning a value of the same type; never null.
 ScorerParam perturb()
          Perturb value, usually by a small amount.
 boolean similar(ScorerParam p)
          Returns true if the argument is signficantly different in value to this.
 java.lang.String toNameValueString()
          Generate the "name=value" text; never null or empty, though the value part may be empty.
 java.lang.String toString()
          Human-readable representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Parameter name with allowed syntax as for Java variable name; never null.


value

public final int value
Parameter value in inclusive/closed range [min,max].


min

public final int min
Minimum legal value for this parameter; no larger than max.


def

public final int def
Default value for this parameter; no smaller than min, no larger than max.


max

public final int max
Maximum legal value for this parameter; no smaller than min.


delta

public final int delta
The size of a small change during mutation; strictly positive.


biasedLow

public final boolean biasedLow
If true, mutations are biased towards reducing the parameter value.

Constructor Detail

ScorerParamInteger

private ScorerParamInteger(int min,
                           int def,
                           int max,
                           int delta,
                           boolean biasedLow,
                           java.lang.String name,
                           int value)
Construct with all components, validated and stored as-is.


ScorerParamInteger

private ScorerParamInteger(int min,
                           int def,
                           int max,
                           int delta,
                           boolean biasedLow,
                           java.lang.String name)
Construct with the default value.


ScorerParamInteger

private ScorerParamInteger(int min,
                           int def,
                           int max,
                           java.lang.String name)
Construct with the default value, no bias and a unit delta.

Method Detail

createScorerParamInteger

public static ScorerParamInteger createScorerParamInteger(int min,
                                                          int def,
                                                          int max,
                                                          java.lang.String name)
Get instance with the default value, no bias and a unit delta; never null. Always intern()ed since we assume that there will be few distinct 'default' values.


createScorerParamInteger

public static ScorerParamInteger createScorerParamInteger(int min,
                                                          int def,
                                                          int max,
                                                          int delta,
                                                          boolean biasedLow,
                                                          java.lang.String name)
Get instance with the default value, and specified bias and delta; never null. Always intern()ed since we assume that there will be few distinct 'default' values.


createScorerParamInteger

public static ScorerParamInteger createScorerParamInteger(int min,
                                                          int def,
                                                          int max,
                                                          int delta,
                                                          boolean biasedLow,
                                                          java.lang.String name,
                                                          int value)
Get instance with the default value, and specified bias and delta; never null. Only intern()s values close to the default since we assume that there will be relatively few distinct values; this means that we will likely capture/cache all values of small-range parameters. We use a similar notion of 'close' to that in the Integer (etc) autoboxing mechanism.


getName

public java.lang.String getName()
Get the parameter name; never null or empty.

Specified by:
getName in interface ScorerParam

perturb

public ScorerParam perturb()
Perturb value, usually by a small amount. We occasionally randomise completely to help a Scorer escape local minima. We do this with a frequency proportional to the time it would take to traverse the entire permitted range one delta at a time.

Specified by:
perturb in interface ScorerParam
Returns:
legal value of same type as this, possibly with small perturbation applied
See Also:
ScorerParam.perturb()

parse

public ScorerParam parse(java.lang.String v)
Parse the String representation of a parameter returning a value of the same type; never null. If the argument is null or unparsable or out of range, then the result has the default value, else an instance with the requested parameter value is returned.

Specified by:
parse in interface ScorerParam
Returns:
legal value of the same type as this, with the parsed input String's value if possible

extract

public ScorerParam extract(ScorerParam p)
Use the supplied parameter if possible (correct name/type/bounds), else return the default; never null. We return this to avoid creating a new instance whenever possible.

Specified by:
extract in interface ScorerParam

toNameValueString

public java.lang.String toNameValueString()
Generate the "name=value" text; never null or empty, though the value part may be empty.

Specified by:
toNameValueString in interface ScorerParam

toString

public java.lang.String toString()
Human-readable representation.

Overrides:
toString in class java.lang.Object

similar

public boolean similar(ScorerParam p)
Description copied from interface: ScorerParam
Returns true if the argument is signficantly different in value to this. The result is false if the argument is null or of a completely different parameter type; no ClassCastException should be thrown (ie behaves like equals() rather than compareTo()).

Specified by:
similar in interface ScorerParam

hashCode

public int hashCode()
The hash depends on the name and the value as the most variable components.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Equality depends on all fields.

Overrides:
equals in class java.lang.Object

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.