|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmonotonic.Monotonic
Monotonic object generates monotonicly increasing points.
Points are kept in a TreeMap and new points could only be added
to this TreeMap by either using
passesThru
method or
gety
method.
gety
method is the main method of this object. When
an x coordinate is supplied, it will randomly generate coresponding
y coordinate. This y value will be made comply with monotonicity
rule and will be between upper and lower envelopes if defined.
When gety is called one of the following algorithms are being
called: extrapolation left, extrapolation right or interpolation.
If the x coordinate is greatest or smallest the extrapolation right
or left is called and a point at x with randomly generated
corresponding y value is created and added to the TreeMap.
If the x coordinate is between two existing points then
interpolation is called. Interpolation algorithm uses a step
halving method where it approaches the x value by dividing the
gap between two nearest points on the left and right to halve.
When the distance between x coordinates of the nearest left
and right points are less then a parameter called sNear then
a line is drawn between these points and the requested value
is calculated from this line and returned. Interpolation only
stores the points created during the step halving.
Monotonic objects could keep an upper and/or lower envelope
which are limiting the generated point list. User has to enter
at least one point using passesThru
method before
calling gety
method. Please note that user has to
check if the envelopes are suitable to the monotonicity
princible. There are no checks if the points entered using
passesThru
are obeying monotonicity. Therefore
user has to ensure that the points entered are proper.
This object uses java.util.Random to obtain psuedo-random numbers. If you will created new Monotonic functions repeatedly consider using deletePoints. This will delete only the TreeMap leaving Random object intact. Random numbers has the risk of repeating the sequence if they are re-constructed at the same time slice since Random uses current time as the seed during construction.
Field Summary | |
protected Envelope |
lowerEnvelope
|
protected java.util.TreeMap |
points
|
protected java.util.Random |
rand
|
protected double |
sNear
|
protected Envelope |
upperEnvelope
|
Constructor Summary | |
Monotonic()
Constructor sets upper and lower envelopes to null and sNear to 0.01 |
|
Monotonic(double sNear)
Monotonic function constructor for no upper and lower envelops. |
|
Monotonic(Envelope upperEnvelope,
Envelope lowerEnvelope,
double sNear)
Monotonic constructor lets user to define upper and lower envelope and sNear. |
Method Summary | |
protected double |
angleLeft(double r)
Creates a random number on the left most of the line. |
protected double |
angleRight(double r)
Creates a random number on the right of the line. |
void |
deletePoints()
Deletes the point list |
int |
getNumberOfPoints()
Returns number of points stored in the point list. |
java.util.TreeMap |
getPoints()
Returns map of points (point list) |
double |
getSNear()
|
double |
gety(double r)
Randomly generates a y value for the r value and stores it to the point list using MOCASSIM algorithm. |
boolean |
hasBothEnvelopes()
|
boolean |
hasLowerEnvelope()
|
boolean |
hasUpperEnvelope()
|
protected double |
interpolate(double r)
Interpolate algorithm to find a new point which is close to r. |
java.lang.Double |
leftOf(double r)
Returns x value of the first point on the left of r. |
java.lang.Double |
leftOf(java.lang.Double r)
Returns x value of the first point on the left of r. |
void |
passesThru(double x,
double y)
Add this x, y pair to the point list. |
double |
pointOnLine(double ax,
double ay,
double bx,
double by,
double x)
Returns the y value of a point on a line when x value of the point and two points on this line is given. |
double |
pointOnLine(java.lang.Double a_x,
java.lang.Double a_y,
java.lang.Double b_x,
java.lang.Double b_y,
double x)
Returns the y value of a point on a line when x value of the point and two points on this line is given. |
protected double |
randomBetween(double up,
double low)
Creates a random number between up and low |
private void |
readObject(java.io.ObjectInputStream in)
Read this object from the given input stream. |
java.lang.Double |
rightOf(double r)
Returns x value of the first point on the right of r. |
java.lang.Double |
rightOf(java.lang.Double r)
Returns x value of the first point on the right of r. |
void |
setLowerEnvelope(Envelope envelope)
Sets lower envelope |
void |
setSNear(double d)
Sets sNear parameter |
void |
setUpperEnvelope(Envelope envelope)
Sets upper envelope |
java.lang.String |
toString()
|
private void |
writeObject(java.io.ObjectOutputStream out)
To write this object to the given out sream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Envelope upperEnvelope
protected Envelope lowerEnvelope
protected java.util.TreeMap points
protected double sNear
protected transient java.util.Random rand
Constructor Detail |
public Monotonic(Envelope upperEnvelope, Envelope lowerEnvelope, double sNear)
upperEnvelope
- upper envelope functionlowerEnvelope
- lower envelope funtionsNear
- length of line segmentpublic Monotonic(double sNear)
sNear
- length of line segmentspublic Monotonic()
Method Detail |
public final void passesThru(double x, double y)
x
- coordinate of pointy
- coordinate of pointpublic final void deletePoints()
public final int getNumberOfPoints()
public final java.lang.Double leftOf(double r)
null
r
- value which x coordinate of the point immediately left of it
be returned
r
public final java.lang.Double leftOf(java.lang.Double r)
null
r
- value which x coordinate of the point immediately left
of it be returned.
r
public final java.lang.Double rightOf(double r)
null
r
- value which x coordinate of the point immediately right of it
be returned.
r
public final java.lang.Double rightOf(java.lang.Double r)
null
r
- value which x coordinate of the point immediately right
of it be returned.
r
public final java.util.TreeMap getPoints()
public final double pointOnLine(java.lang.Double a_x, java.lang.Double a_y, java.lang.Double b_x, java.lang.Double b_y, double x)
a_x
- x value of first point on the linea_y
- y value of first point on the lineb_x
- x value of second point on the lineb_y
- y value of second point on the linex
- is the value whoes y value be returned
public final double pointOnLine(double ax, double ay, double bx, double by, double x)
ax
- x value of first point on the lineay
- y value of first point on the linebx
- x value of second point on the lineby
- y value of second point on the linex
- is the value whoes y value be returned
protected final double randomBetween(double up, double low)
up
- upper bound of the random numberlow
- lower bound of the random number
protected final double angleLeft(double r)
r
- is the x value where the new line point to be created
protected final double angleRight(double r)
r
- is the x value of the new point
public final boolean hasBothEnvelopes()
public final boolean hasUpperEnvelope()
public final boolean hasLowerEnvelope()
protected final double interpolate(double r)
r
- x coordinate where we want to create a new point.
r
public double gety(double r)
r
- x coordinate where the new point will be created
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
out
-
java.io.IOException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
in
-
java.io.IOException
java.lang.ClassNotFoundException
public final double getSNear()
public void setLowerEnvelope(Envelope envelope)
envelope
- public void setSNear(double d)
d
- public void setUpperEnvelope(Envelope envelope)
envelope
- public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |