id3
Class CatGraph

java.lang.Object
  |
  +--id3.CatGraph
Direct Known Subclasses:
RootedCatGraph

public class CatGraph
extends java.lang.Object

CatGraph is a directed graph whose nodes have references to Categorizers. Edges are labelled with the category number they match. The CatGraph can be either complete or sparse. This is decided at the time of creation and cannot be changed thereafter.

For complete graphs:

Each node's first edge must be labelled either UNKNOWN_CATEGORY_VAL or FIRST_CATEGORY_VAL. Each additional edge must be labelled with the next category in ascending order.

For sparse graphs:

A node may have zero or more children. Detection of a child can be done using the get_child_if_exists() function, which returns a reference to the child node if it exists, and otherwise returns a NULL reference.


Field Summary
protected  CGraph cGraph
          The CGraph object containing the graph used for this CatGraph.
protected  boolean defaultDistDisp
          The default value for distribution display.
protected  java.lang.String distDispHelp
          Distribution display help string.
protected  LogOptions logOptions
          Logging options for this class.
 
Constructor Summary
CatGraph(boolean isGraphSparse)
          Constructor.
CatGraph(CGraph aGraph, boolean isGraphSparse)
          Constructor.
 
Method Summary
 boolean check_node_in_graph(Node node, boolean fatalOnFalse)
          Checks if specified Node is in this NatGraph object.
 void connect(Node from, Node to, AugCategory edgeLabel)
          Creates a directed Edge from Node "from" to Node "to".
protected  void convertToDotFormat(java.io.Writer stream, DisplayPref pref, boolean hasNodeLosses, boolean hasLossMatrix)
          Returns a representation of the graph to dot format.
 Node create_node(NodeCategorizer[] cat, int level)
          Creates a new Node.
 void display(boolean hasNodeLosses, boolean hasLossMatrix, java.io.Writer stream, DisplayPref dp)
          Prints a representation of the CatGraph to the specified stream, using the Categorizer descriptions to label the nodes.
 NodeCategorizer get_categorizer(Node nodePtr)
          Returns the NodeCategorizer stored in the specified Node.
 CGraph get_graph()
          Returns the CGraph stored in this CatGraph object.
 int get_log_level()
          Returns the logging level for this object.
 LogOptions get_log_options()
          Returns the LogOptions object for this object.
 java.io.Writer get_log_stream()
          Returns the stream to which logs for this object are written.
 boolean is_sparse()
          Checks if this CatGraph is sparsely populated.
 int num_attr(int maxAttr)
          Returns the number of attributes stored in this CatGraph.
 int num_children(Node parent)
          Returns the number of children the specified Node has.
 int num_leaves()
          Returns the number of leaves in this CatGraph.
 int num_nodes()
          Returns the number of Nodes in this CatGraph.
protected  void process_DotGraph_display(java.io.Writer stream, DisplayPref dp, boolean hasNodeLosses, boolean hasLossMatrix)
          Creates a postscript file of the receiving graph via a dot description.
protected  void process_DotPostscript_display(java.io.Writer stream, DisplayPref dp, boolean hasNodeLosses, boolean hasLossMatrix)
          Creates a postscript file of the receiving graph in a graphical form.
 void set_log_level(int level)
          Sets the logging level for this object.
 void set_log_options(LogOptions opt)
          Sets the LogOptions object for this object.
 void set_log_prefixes(java.lang.String file, int line, int lvl1, int lvl2)
          Sets the logging message prefix for this object.
 void set_log_stream(java.io.Writer strm)
          Sets the stream to which logging options are displayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cGraph

protected CGraph cGraph
The CGraph object containing the graph used for this CatGraph.

logOptions

protected LogOptions logOptions
Logging options for this class.

distDispHelp

protected java.lang.String distDispHelp
Distribution display help string.

defaultDistDisp

protected boolean defaultDistDisp
The default value for distribution display. The default is FALSE.
Constructor Detail

CatGraph

public CatGraph(boolean isGraphSparse)
Constructor.
Parameters:
isGraphSparse - TRUE if this CatGraph is sparsely populated. FALSE otherwise.

CatGraph

public CatGraph(CGraph aGraph,
                boolean isGraphSparse)
Constructor.
Parameters:
aGraph - CGraph on which all operations will take place. It should remain unchanged while a part of this CatGraph object.
isGraphSparse - TRUE if this CatGraph is sparsely populated. FALSE otherwise.
Method Detail

set_log_level

public void set_log_level(int level)
Sets the logging level for this object.
Parameters:
level - The new logging level.

get_log_level

public int get_log_level()
Returns the logging level for this object.
Returns:
The logging level for this object.

set_log_stream

public void set_log_stream(java.io.Writer strm)
Sets the stream to which logging options are displayed.
Parameters:
strm - The stream to which logs will be written.

get_log_stream

public java.io.Writer get_log_stream()
Returns the stream to which logs for this object are written.
Returns:
The stream to which logs for this object are written.

get_log_options

public LogOptions get_log_options()
Returns the LogOptions object for this object.
Returns:
The LogOptions object for this object.

set_log_options

public void set_log_options(LogOptions opt)
Sets the LogOptions object for this object.
Parameters:
opt - The new LogOptions object.

set_log_prefixes

public void set_log_prefixes(java.lang.String file,
                             int line,
                             int lvl1,
                             int lvl2)
Sets the logging message prefix for this object.
Parameters:
file - The file name to be displayed in the prefix of log messages.
line - The line number to be displayed in the prefix of log messages.
lvl1 - The log level of the statement being logged.
lvl2 - The level of log messages being displayed.

is_sparse

public boolean is_sparse()
Checks if this CatGraph is sparsely populated.
Returns:
TRUE if this CatGraph is sparsely populated.

num_nodes

public int num_nodes()
Returns the number of Nodes in this CatGraph.
Returns:
The number of Nodes in this CatGraph.

num_leaves

public int num_leaves()
Returns the number of leaves in this CatGraph.
Returns:
The number of leaves in this CatGraph.

get_graph

public CGraph get_graph()
Returns the CGraph stored in this CatGraph object.
Returns:
The CGraph stored in this CatGraph object.

num_attr

public int num_attr(int maxAttr)
Returns the number of attributes stored in this CatGraph.
Parameters:
maxAttr - The maximum number of attributes stored in the CatGraph.
Returns:
The number of attributes stored in this CatGraph.

create_node

public Node create_node(NodeCategorizer[] cat,
                        int level)
Creates a new Node.
Parameters:
cat - The Categorizer to be stored in the new Node.
level - The level for the new node placement.
Returns:
The new Node.

connect

public void connect(Node from,
                    Node to,
                    AugCategory edgeLabel)
Creates a directed Edge from Node "from" to Node "to". Assigns the Edge the value "edgeLabel" and gets ownership of the AugCategory.

For non-sparse graphs:
The category given must be the category following the category for the previous Edge.
The first Edge must have label UNKNOWN_CATEGORY_VAL or FIRST_CATEGORY_VAL.

Parameters:
from - The Node that is the source of the directed Edge.
to - The Node that is the destination of the directed Edge.
edgeLabel - The category to be assigned to the new Edge.

num_children

public int num_children(Node parent)
Returns the number of children the specified Node has.
Parameters:
parent - The specified Node.
Returns:
The number of children the specified Node has.

get_categorizer

public NodeCategorizer get_categorizer(Node nodePtr)
Returns the NodeCategorizer stored in the specified Node.
Parameters:
nodePtr - The Node containing the NodeCategorizer.
Returns:
The NodeCategorizer stored in the specified Node.

check_node_in_graph

public boolean check_node_in_graph(Node node,
                                   boolean fatalOnFalse)
Checks if specified Node is in this NatGraph object.
Parameters:
node - The Node to be looked for.
fatalOnFalse - TRUE if an error message should be displayed if the specified Node is not in the CatGraph, FALSE otherwise.
Returns:
TRUE if the Node is a node that is in the CatGraph. Otherwise, returns FALSE.

process_DotGraph_display

protected void process_DotGraph_display(java.io.Writer stream,
                                        DisplayPref dp,
                                        boolean hasNodeLosses,
                                        boolean hasLossMatrix)
Creates a postscript file of the receiving graph via a dot description. This method applies only to the DotGraph DisplayPref.
Parameters:
stream - The stream to be written to.
dp - The preferences for display.
hasNodeLosses - TRUE if this Node contains loss values.
hasLossMatrix - TRUE if this CatGraph has a loss matrix assigned to it, FALSE otherwise.

process_DotPostscript_display

protected void process_DotPostscript_display(java.io.Writer stream,
                                             DisplayPref dp,
                                             boolean hasNodeLosses,
                                             boolean hasLossMatrix)
Creates a postscript file of the receiving graph in a graphical form. This method applies only to the DotPostscript DisplayPref.
Parameters:
stream - The stream to be written to.
dp - The preferences for display.
hasNodeLosses - TRUE if this Node contains loss values.
hasLossMatrix - TRUE if this CatGraph has a loss matrix assigned to it, FALSE otherwise.

display

public void display(boolean hasNodeLosses,
                    boolean hasLossMatrix,
                    java.io.Writer stream,
                    DisplayPref dp)
Prints a representation of the CatGraph to the specified stream, using the Categorizer descriptions to label the nodes. This mehtod takes into account the different combinations of streams and display preferences. See DisplayPref.java for more details with regards to valid combinations, functionality, and options.
Parameters:
hasNodeLosses - TRUE if this Node contains loss values.
hasLossMatrix - TRUE if this CatGraph has a loss matrix assigned to it, FALSE otherwise.
stream - The stream to be written to.
dp - The preferences for display.

convertToDotFormat

protected void convertToDotFormat(java.io.Writer stream,
                                  DisplayPref pref,
                                  boolean hasNodeLosses,
                                  boolean hasLossMatrix)
Returns a representation of the graph to dot format.
Parameters:
stream - The stream to be written to.
pref - The preferences for display.
hasNodeLosses - TRUE if this Node contains loss values.
hasLossMatrix - TRUE if this CatGraph has a loss matrix assigned to it, FALSE otherwise.