

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object hu.birot.OTKit.dataType.violation.Violation hu.birot.OTKit.dataType.violation.FloatViolation
public class FloatViolation
A violation with a (double) floating point value.
This subclass of the class Violation
is a generalization of
the traditional violations, allowing not only integer, and not only nonnegative
values. Yet, if traditional constraints are used, the subclass
IntegerViolation
is recommended, which makes computations faster and
more precise.
Note the method v(double)
, which returns an already constructed
violation, unless no such violation was needed so far. Using this method instead
of the constructor FloatViolation(double violation_level)
is more
efficient, because of several reasons: the time needed for constructing new
violations (and for the corresponding garbage collection) is saved, and the
Violation.isEqual(Violation,Violation)
is also faster if the two
violations refer to the same object. So, the use of the static method v
is highly recommended, unless extremely many different violation levels are needed.
Concerning possible errors due to rounding errors in
floating point arithmetics: see the documentation of
the constant field EPSILON
. In short: make sure you always
use doubles and not floats to construct realvalued
violations.
Two constant violations complement this class:
FloatViolation.nullViolation
(corresponding to the case when the
constraint is satisfied), and FloatViolation.oneViolation
(corresponding
to a single violation).
Violation
,
IntegerViolation
Field Summary  

static java.lang.RuntimeException 
ArgumentNotFloatViolation
Exception "Argument is not FloatViolation". 
protected java.util.regex.Pattern 
delete_after_comma

static double 
EPSILON
A constant used to avoid errors due to inexact floating point arithmetics. 
static FloatViolation 
nullViolation
Zero violation level: the constraint is satisfied. 
static FloatViolation 
oneViolation
One violation level: the constraint is violated once. 
Fields inherited from class hu.birot.OTKit.dataType.violation.Violation 

thisclass 
Constructor Summary  

FloatViolation(double f)
Construct a Violation (that is, a subclass FloatViolation) with value f . 
Method Summary  

boolean 
betterEqual(Violation v)
Compares the present Violation to Violation v , and returns true if and only if
this violation is better than or equal to v . 
Violation 
clone()
Creates a clone of the Violation, with the same value. 
double 
difference(Violation v)
Returns the difference of this violation and of violation v (in this order: "thisv "). 
boolean 
equals(java.lang.Object o)
Equality of two violations. 
int 
hashCode()
A hash code corresponding to the Violation. 
java.lang.String 
toString()
Transforms a Violation into a String, returning the decimal representation of the violation. 
static FloatViolation 
v(double v)
"Quick constructor". 
java.lang.Double 
value()
Returns the value of the violation. 
Methods inherited from class hu.birot.OTKit.dataType.violation.Violation 

isBetter, isEqual, notComparable 
Methods inherited from class java.lang.Object 

finalize, getClass, notify, notifyAll, wait, wait, wait 
Field Detail 

public static final FloatViolation nullViolation
public static final FloatViolation oneViolation
public static final double EPSILON
A constant used to avoid errors due to inexact floating
point arithmetics. If a violation is constructed using
a value less than EPSILON
(and larger than EPSILON
),
then the resulting violation is a 0 violation.
EPSILON = 10^(9) = 0.000000001.
Note that other possible errors resulting from
inaccuracies in floating point arithmetics is solved by
the fact that the constructor FloatViolation(double r)
recasts r
into float. So, if you use double float
arithmetics instead of single float arithmetics, you
should not have any problem. (If you do, please let me
know about it.) For example, 1.10.9
will not be 0.2 exactly,
but at least it will be equal to 1.51.3
.
Otherwise, you can have unfortunate situations in OT such as candidate 1 becomes better than candidate 2, simply because candidate 1 violates a constraint 1.000 times, whereas candidate 2 violates it (due to rounding errors) 1.000000000000014 times.
public static java.lang.RuntimeException ArgumentNotFloatViolation
FloatViolation.difference(Violation v)
whenever the argument
is not a FloatViolation
. To be more precise, whenever
v.value()
for the argument v
cannot be cast to
Double
.
difference(Violation)
protected final java.util.regex.Pattern delete_after_comma
Constructor Detail 

public FloatViolation(double f)
f
.
To be more exact, f is recast to float, and to 0.0f, if
the absolute value of f is less than EPSILON
.
f
 : The float value defining the violation level.EPSILON
Method Detail 

public java.lang.Double value()
Returns the value of the violation.
value
in class Violation
IntegerViolation.value()
,
value()
public static FloatViolation v(double v)
"Quick constructor". Returns the violation with value v
that
has been already constructed earlier. If no violation with that value has ever
been constructed, then it is first created.
With equal arguments, this method always returns the same violation; that is,
not only equal violations, with respect to the equals
method.
Subsequently, several methods comparing two violations run more efficiently,
and less time is spent on constructing new violations, and then on collecting garbage.
Therefore it is recommended to use this static method in the definition of
constraints, and not the standard constructor of the violations.
If the number of different violation levels is extremely high, and each of them is used only very seldom, then keeping all of them in memory may nevertheless be less efficient.
v
 Value of the violation to be returned.
v
, the only one constructed.public boolean betterEqual(Violation v)
Compares the present Violation to Violation
v
, and returns true
if and only if
this violation is better than or equal to v
.
More specifically, it returns true
if and only if
the floating point value of this violation is less than or equal to
v.value()
– provided that v
is also an instance
of the FLoatViolation
class. For other types of violations,
the method always returns false
. For instance, an
instance of IntegerViolation
cannot be compared to an instance
of FloatViolation
, even if everyday arithmetics would make
their comparison possible.
This method implements Violation.betterEqual
, and is
used in the static comparison methods in Violation
.
betterEqual
in class Violation
v
 The second violation, to which this violation is compared.
true
if this violation is better than or
equal to v
, and if they are both instances of
FloatViolation
. Otherwise false
is returned.Violation.betterEqual(Violation)
,
Violation.isBetter(Violation, Violation)
,
Violation.isEqual(Violation, Violation)
,
Violation.notComparable(Violation, Violation)
public double difference(Violation v)
Returns the difference of this violation
and of violation v
(in this order: "thisv
").
If violation v
is not an instance of FloatViolation
,
or if v.value()
cannot be cast to Double
, then
exception FloatViolation.ArgumentNotFloatViolation
is thrown.
This happens even if v
belongs to another numeric violation
subclass, such as IntegerViolation
.
Otherwise, the arithmetic difference of the two values is returned:
this.value()v.value()
(the value of the present violation
minus the value of v
).
difference
in class Violation
v
 The subtrahend violation.
this  v
).ArgumentNotFloatViolation
,
Violation.difference(Violation)
public boolean equals(java.lang.Object o)
true
if and only if
o
belongs to the same class (FloatViolation
) and
the value()
of the two violations are equal.
This method overrides java.lang.Object.equals.
equals
in class Violation
o
 Object to be compared to the current violation.
true
for FloatViolations whose value are
equal to the value of the current violation; false
in all other cases.Violation.equals(Object)
public Violation clone()
clone
in class Violation
public java.lang.String toString()
Transforms a Violation into a String, returning the decimal representation of the violation. Overrides the method java.lang.Object.toString.
toString
in class Violation
public int hashCode()
A hash code corresponding to the Violation. It is the hash code produced by the string representation of value.
hashCode
in class Violation


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 