Class gpjpp.GPGenePrint
All Packages Class Hierarchy This Package Previous Next Index
Class gpjpp.GPGenePrint
java.lang.Object
|
+----gpjpp.GPObject
|
+----gpjpp.GPContainer
|
+----gpjpp.GPGene
|
+----gpjpp.GPGenePrint
- public class GPGenePrint
- extends GPGene
Formats a gene tree for printing in graphic or pseudo-graphic
format. GPGenePrint extends GPGene to add an x position which
it computes by spreading out the nodes of the tree just enough
to prevent them from overlapping at all levels of the tree.
Note that GPGenePrint formats just a single branch of a
complete GP, which would frequently be too wide to print
on standard paper.
The three key methods of the class are the constructor,
GPGenePrint(GPGene),
which clones a GPGene tree onto a new tree with the extra fields,
printOn(),
which prints the tree in pseudo-graphic format to a PrintStream, and
drawOn(),
which prints the tree as a true graphic gif file.
Several static public fields of the class can be used to
adjust the appearance of the tree:
xMargin,
xSpacing,
rectMargin,
arcRadius,
rowsPerNode.
- Version:
- 1.0
-
arcRadius
- The pixel radius of the arc at each corner of a node rectangle.
-
peer
- A reference to the original gene of which the GPGenePrint
object is an extended copy.
-
rectMargin
- The number of pixels separating the node rectangle from the
node text that it surrounds in a graphic tree.
-
rowsPerNode
- The number of character heights per node level in a graphic
tree.
-
x
- The computed x position of this node, in character units.
-
xMargin
- The number of blank columns printed at the left edge of the
tree by printOn().
-
xSpacing
- The minimum number of columns (character widths) that separate
adjacent nodes.
-
adjustOverlaps(double[], double[], int)
- Adjusts the x coordinate of this node and its children whenever
the node overlaps the region of the node to its left.
-
calcContainerCenter()
- Returns the x coordinate of the horizontal center of the
arguments to this node at their current positions.
-
calcMaxX()
- Returns the largest x value anywhere in the tree.
-
calcMaxX(double)
- Returns the largest x value anywhere in the tree.
-
calcMinX()
- Returns the smallest x value anywhere in the tree.
-
calcMinX(double)
- Returns the smallest x value anywhere in the tree.
-
calcPackedContainerWidth()
- Returns the minimum width of the arguments to this node
taking into account the node width of each argument and the
minimum spacing between nodes,
xSpacing.
-
calcPackedPos(double[], int)
- Calculates the x coordinates of all the nodes below this
level assuming that all can be packed to minimum spacing
and each container is centered under its parent.
-
calcXPositions()
- Calculates the x coordinates of all nodes so that none
overlap, otherwise-unconstrained nodes are evenly spaced,
and parent nodes are centered over their children as much
as possible.
-
clone()
- Disables the cloning operation inherited from GPGene,
since GPGenePrint does not need to be cloned.
-
drawGifNode(GPDrawing, int)
- Draws all the nodes recursively starting with this one,
including each node's text, a rounded rectangle surrounding it,
and connectors to all of its children.
-
drawOn(GPDrawing, String, String, GPVariables)
- Computes the x coordinates for all nodes in this gene tree
and writes the tree in gif format to the specified file.
-
getNodeRight()
- Returns the x coordinate of the right edge of the node
text in characters.
-
getNodeWidth()
- Returns the length of the node representation string in
characters.
-
hBox(GPDrawing)
- Computes the pixel height of the node rectangle.
-
isA()
- Returns a code identifying the class.
-
load(DataInputStream)
- Disables the load operation inherited from GPGene, since
GPGenePrint does not need to be streamed.
-
printConnectors(PrintStream, int, int, double[])
- Prints pseudo-graphic connectors between nodes at
level depToPrint and nodes at level depToPrint+1.
-
printLevel(PrintStream, int, int, double[])
- Prints all nodes at level depToPrint in left-to-right order.
-
printOn(PrintStream, GPVariables)
- Computes the x coordinates for all nodes in this gene tree
and writes the tree in pseudo-graphic format to the
specified PrintStream.
-
save(DataOutputStream)
- Disables the save operation inherited from GPGene, since
GPGenePrint does not need to be streamed.
-
shiftX(double)
- Shifts the x coordinates of all nodes by subtracting dx.
-
spaceTo(PrintStream, int, double[], double)
- Prints spaces until curX[curDepth] equals or exceeds rx.
-
spreadTerminals()
- Spreads terminal nodes so that they are equally spaced within
the boundaries of the container.
-
wBox(GPDrawing, String)
- Computes the pixel width of the node rectangle given
the string to appear within the rectangle.
-
xBox(GPDrawing, double)
- Converts the x coordinate of a node to the corresponding
x pixel position for the left edge of the surrounding
node rectangle.
-
xText(GPDrawing, double)
- Converts the x coordinate of a node to the corresponding
x pixel position for the start of the node text.
-
yBox(GPDrawing, int)
- Converts the depth of a node to the corresponding
y pixel position for the top edge of the surrounding
node rectangle.
-
yText(GPDrawing, int)
- Converts the depth of a node to the corresponding y pixel
position for the node text.
xMargin
public static double xMargin
- The number of blank columns printed at the left edge of the
tree by printOn(). Default 2.
xSpacing
public static double xSpacing
- The minimum number of columns (character widths) that separate
adjacent nodes. Default 3.
rectMargin
public static int rectMargin
- The number of pixels separating the node rectangle from the
node text that it surrounds in a graphic tree. Default 2.
arcRadius
public static int arcRadius
- The pixel radius of the arc at each corner of a node rectangle.
Default 10.
rowsPerNode
public static int rowsPerNode
- The number of character heights per node level in a graphic
tree. Default 3.
x
protected double x
- The computed x position of this node, in character units. The
number is non-negative when the algorithm is finished.
It is a floating point number that is rounded to integer
columns by printOn() and converted to integer pixels by
drawOn().
peer
protected GPGene peer
- A reference to the original gene of which the GPGenePrint
object is an extended copy. The purpose for peer is to
call methods in a user subclass of GPGene. Specifically,
GPGenePrint calls the
geneRep() method of
GPGene to get the string representation of each node.
When the gene represents a randomly generated constant,
geneRep() can return the constant value instead of the generic
representation of the node type.
See the Lawnmower problem for an example.
clone
protected synchronized Object clone()
- Disables the cloning operation inherited from GPGene,
since GPGenePrint does not need to be cloned. This
version of clone() always returns null.
- Overrides:
- clone in class GPGene
isA
public byte isA()
- Returns a code identifying the class. GPGenePrint is
not stored in streams, but it is given the unique code
GENEPRINTID just for completeness.
- Overrides:
- isA in class GPGene
load
protected synchronized void load(DataInputStream is)
- Disables the load operation inherited from GPGene, since
GPGenePrint does not need to be streamed. This version
of load() does nothing.
- Overrides:
- load in class GPGene
save
protected void save(DataOutputStream os)
- Disables the save operation inherited from GPGene, since
GPGenePrint does not need to be streamed. This version
of save() does nothing.
- Overrides:
- save in class GPGene
getNodeWidth
protected double getNodeWidth()
- Returns the length of the node representation string in
characters.
- See Also:
- peer
getNodeRight
protected double getNodeRight()
- Returns the x coordinate of the right edge of the node
text in characters.
calcPackedContainerWidth
protected double calcPackedContainerWidth()
- Returns the minimum width of the arguments to this node
taking into account the node width of each argument and the
minimum spacing between nodes,
xSpacing.
calcContainerCenter
protected double calcContainerCenter()
- Returns the x coordinate of the horizontal center of the
arguments to this node at their current positions.
calcPackedPos
protected void calcPackedPos(double minX[],
int curDepth)
- Calculates the x coordinates of all the nodes below this
level assuming that all can be packed to minimum spacing
and each container is centered under its parent. This is
a first-order approximation to the final position but
generally leads to overlaps between adjacent node groups.
The x coordinate of this node must be initialized before
calling calcPackedPos().
- Parameters:
- minX - an array holding the minimum x coordinate
at each level of the tree. This array is
updated for every node that is processed here.
- curDepth - the current node depth, where the root of
the tree is depth 0.
adjustOverlaps
protected boolean adjustOverlaps(double minX[],
double curX[],
int curDepth)
- Adjusts the x coordinate of this node and its children whenever
the node overlaps the region of the node to its left. This
spreads the nodes to the right just enough to get rid of
overlaps. Two additional adjustments are also made: terminal
nodes dangling at more than minimum spacing to the left or
right of their node groups are tightened to minimum spacing;
and parent nodes are recentered over their children after
the other adjustments have been made.
This method is called repeatedly until no further adjustments
are needed or an iteration limit is reached.
- Parameters:
- minX - an array holding the minimum x coordinate
at each level of the tree. This array is
updated for every node that is processed here.
- curX - an array holding the largest x coordinate
used by a node at each depth level so far. This
allows the detection of overlaps.
- curDepth - the current node depth, where the root of
the tree is depth 0.
- Returns:
- true if the position of any node was adjusted.
spreadTerminals
protected void spreadTerminals()
- Spreads terminal nodes so that they are equally spaced within
the boundaries of the container.
calcMinX
protected double calcMinX()
- Returns the smallest x value anywhere in the tree.
calcMinX
protected double calcMinX(double minSoFar)
- Returns the smallest x value anywhere in the tree.
calcMaxX
protected double calcMaxX()
- Returns the largest x value anywhere in the tree.
calcMaxX
protected double calcMaxX(double maxSoFar)
- Returns the largest x value anywhere in the tree.
shiftX
protected void shiftX(double dx)
- Shifts the x coordinates of all nodes by subtracting dx.
calcXPositions
protected int calcXPositions()
- Calculates the x coordinates of all nodes so that none
overlap, otherwise-unconstrained nodes are evenly spaced,
and parent nodes are centered over their children as much
as possible. The minimum x value is 0.0 upon return.
- Returns:
- the depth of the tree.
spaceTo
protected void spaceTo(PrintStream os,
int curDepth,
double curX[],
double rx)
- Prints spaces until curX[curDepth] equals or exceeds rx.
printLevel
protected void printLevel(PrintStream os,
int depToPrint,
int curDepth,
double curX[])
- Prints all nodes at level depToPrint in left-to-right order.
This forms one line of pseudo-graphic output.
printConnectors
protected void printConnectors(PrintStream os,
int depToPrint,
int curDepth,
double curX[])
- Prints pseudo-graphic connectors between nodes at
level depToPrint and nodes at level depToPrint+1.
printOn
public void printOn(PrintStream os,
GPVariables cfg)
- Computes the x coordinates for all nodes in this gene tree
and writes the tree in pseudo-graphic format to the
specified PrintStream. None of the configuration variables
in cfg are used by default.
- Overrides:
- printOn in class GPGene
xText
protected final int xText(GPDrawing ods,
double x)
- Converts the x coordinate of a node to the corresponding
x pixel position for the start of the node text.
yText
protected final int yText(GPDrawing ods,
int depth)
- Converts the depth of a node to the corresponding y pixel
position for the node text.
xBox
protected final int xBox(GPDrawing ods,
double x)
- Converts the x coordinate of a node to the corresponding
x pixel position for the left edge of the surrounding
node rectangle.
yBox
protected final int yBox(GPDrawing ods,
int depth)
- Converts the depth of a node to the corresponding
y pixel position for the top edge of the surrounding
node rectangle.
wBox
protected final int wBox(GPDrawing ods,
String nodeName)
- Computes the pixel width of the node rectangle given
the string to appear within the rectangle.
hBox
protected final int hBox(GPDrawing ods)
- Computes the pixel height of the node rectangle.
drawGifNode
protected void drawGifNode(GPDrawing ods,
int curDepth)
- Draws all the nodes recursively starting with this one,
including each node's text, a rounded rectangle surrounding it,
and connectors to all of its children.
drawOn
public void drawOn(GPDrawing ods,
String fname,
String title,
GPVariables cfg) throws IOException
- Computes the x coordinates for all nodes in this gene tree
and writes the tree in gif format to the specified file.
- Parameters:
- ods - a surface to draw on.
- fname - the name of a gif file to create.
- title - a title to draw on the image, usually "RPB",
"ADF0", etc. The title is always placed on the
first row of the drawing, to the left of the root
node if possible, otherwise at the right edge
of the image.
- cfg - a set of global configuration variables. Only the
TreeFontSize variable is used here, to set the font
size for text within the image.
- Overrides:
- drawOn in class GPGene
All Packages Class Hierarchy This Package Previous Next Index