|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectexe.VisualGraph
public class VisualGraph
This class is a tool for storing and manipulating graphs. A
VisualGraph is composed of vertices of type
VisNode and edges of type VisEdge. Methods are
provided for creating specific types of graphs, manipulating these graphs to
produce algorithm visualizations, and writing these graphs to the showfiles
used by the GAIGS visualizer.
Each vertex in a VisualGraph can have any unique alphanumeric
(A-Z, a-z, 0-9) value as its label. Therefore, the maximum number of nodes
in a VisualGraph is 62, which results in a maximum of 3844
edges. If the VisualGraph is a heuristic graph, the heuristic
value for each vertex will be printed beneath the node's label when it is
displayed in the GAIGS visualizer.
In order to use any of these graph classes in a script-producing program,
the script-producing program must import the package exe.
| Field Summary | |
|---|---|
protected boolean |
directed
Tracks whether this VisualGraph has directed edges or
if all edges are undirected. |
protected double |
font_size
Holds the minimum font size for this VisualGraph when drawn
in the new GAIGS XML format. |
protected boolean |
heuristics
Maitains whether this VisualGraph contains heuristic values
or whether it has no heuristic information. |
protected static int |
MAX_NODES
Stores the maximum number of nodes for this VisualGraph. |
protected VisEdge[][] |
my_edgeset
Stores the list of all possible edges in this VisualGraph. |
protected VisNode[] |
my_nodeset
Maintains the list of all possible nodes in this VisualGraph. |
protected int |
num_edges
Contains the current number of activated edges in this VisualGraph. |
protected int |
num_nodes
Tracks the current number of activated nodes in this VisualGraph. |
protected boolean |
weighted
Maintains whether this VisualGraph has weighted or
unweighted edges. |
protected double |
x1
Stores the left-most x-bound for this VisualGraph within
the normalized [0,1] space. |
protected double |
x2
Stores the right-most x-bound for this VisualGraph within
the normalized [0,1] space. |
protected double |
y1
Stores the lower y-bound for this VisualGraph within the
normalized [0,1] space. |
protected double |
y2
Stores the upper y-bound for this VisualGraph within the
normalized [0,1] space. |
| Constructor Summary | |
|---|---|
VisualGraph()
Constucts a VisualGraph with default information. |
|
VisualGraph(boolean weighted,
boolean directed,
boolean heuristics)
Constructs a VisualGraph by specifying whether or not it
has edge weights, directed edges, and heuristic values for nodes. |
|
| Method Summary | |
|---|---|
void |
addEdge(char start,
char end,
double weight,
java.lang.String my_col)
Adds a new edge to this VisualGraph by specifying its start
start node, end node, weight, and color. |
void |
addNode(char c,
double my_x,
double my_y,
java.lang.String my_col)
Adds a new node to this VisualGraph by specifying its
label, coordinates, and color. |
void |
addNode(char c,
java.lang.String my_col)
Adds a new node to this VisualGraph by specifying its
label and color. |
java.util.Enumeration |
allAdjacentNodes(char c)
Returns an Enumeration of all the nodes in this
VisualGraph that are connected to the given node via an
edge. |
java.util.Enumeration |
allNodes()
Returns an Enumeration of all the nodes in this
VisualGraph. |
void |
clearGraph()
Clears this VisualGraph by returning the data for all nodes
and edges to their default values. |
boolean |
edgeExists(char start,
char end)
Indicates if the specified edge is activated in this VisualGraph. |
double |
edgeWeight(char start,
char end)
Returns the weight of the specified edge in this VisualGraph. |
boolean |
empty()
Indicates whether this VisualGraph is empty or contains
some data. |
boolean |
full()
Indicates whether the maximum number of nodes has been reached or if there are still unused nodes available in this VisualGraph. |
boolean |
fullEdge()
Indicates whether the maximum number of edges has been reached or if there are still unused edges available in this VisualGraph. |
void |
gaigsChangeHexEdgeColors(java.lang.String search,
java.lang.String replace)
Changes any edges in this VisualGraph with the color
indicated by search to have the color specified by
replace. |
void |
gaigsChangeHexNodeColors(java.lang.String search,
java.lang.String replace)
Changes any nodes in this VisualGraph with the color
indicated by search to have the color specified by
replace. |
double |
gaigsDistPoints(double x1,
double y1,
double x2,
double y2)
Returns the Euclidean distance between two points specified by their Cartesian coordinates. |
boolean |
gaigsIsOverlap()
Checks to make sure this VisualGraph's layout does not have
any overlaps. |
VisEdge[][] |
getEdges()
Returns my_edgeset so that a script-producing program can
access the VisEdge objects that comprise this
VisualGraph. |
char |
getNextNode()
Gives the char name/label for the next unactivated node. |
VisNode[] |
getNodes()
Returns my_nodeset so that a script-producing program can
access the VisNode objects that comprise this
VisualGraph. |
int |
getNumEdges()
Returns the number of edges that are currently activated in this VisualGraph. |
int |
getNumNodes()
Returns the number of nodes that are currently activated in this VisualGraph. |
boolean |
hasHeuristics()
Indicates if this VisualGraph contains or does not contain
heuristic values. |
void |
initializeEdgeWeights()
Initializes the edge weights based on the the Euclidean distances between their start and goal nodes. |
void |
initializeHValues(int g)
Initializes the heuristic values of the nodes based on their Euclidean distances from the specified goal node. |
boolean |
isDirected()
Tells if this VisualGraph has directed or bidirectional
edges. |
boolean |
isWeighted()
Tells if this VisualGraph has weighted or unweighted edges. |
boolean |
nodeExists(char c)
Indicates if the specified node is activated in this VisualGraph. |
void |
OLDrandomDAcyclicGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
|
void |
organizeCircle()
Organizes the nodes of this VisualGraph around a unit
circle to produce a more readable layout. |
void |
organizeGraph()
Executes the Kamada Algorithm on the nodes and edges currently in this VisualGraph to produce a readable layout. |
char |
randomActiveNode()
Returns the name/label for a randomly selected activated node. |
int[] |
randomAStarSearchGraph(int node_c,
int edge_c)
Clears this VisualGraph and produces a randomly generated
sparsely connected heuristic graph that demonstrates the unique feature
of the A* Algorithm, namely the reopening of a closed node when a poor
heuristic value caused the node to be closed with a greater-than-optimal
cost. |
void |
randomCompleteGraph(int node_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
complete graph according to the supplied constraints. |
void |
randomConnectedGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
connected graph according to the supplied constraints. |
void |
randomDAcyclicGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
directed acyclic graph according to the supplied constraints. |
void |
randomGAIGSGraph(int numNodes,
int numEdges,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
sparsely connected graph suitable for many algorithm visualizations. |
void |
randomGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
graph according to the supplied constraints. |
void |
randomHamiltonianGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
Clears this VisualGraph and produces a randomly generated
graph containing a Hamiltonian Cycle according to the supplied
constraints. |
int[] |
randomHeuristicGraph(int node_c,
int edge_c)
Clears this VisualGraph and produces a randomly generated
sparsely connected graph with heuristic values for the nodes. |
char |
randomNewNode()
Returns the name/label for a randomly selected unactivated node. |
char |
randomNode()
Returns the name/label for a randomly selected node. |
void |
readGAIGSXMLGraph(java.lang.String filename)
Reads in a showfile and extracts the information contained within the first set of <graph> tags to initialize this
VisualGraph. |
int[] |
readStartGoal(java.lang.String filename)
Reads in a showfile in order to extract the start and goal nodes from the first <title> element in the showfile. |
void |
removeEdge(char start,
char end)
Removes an edge from this VisualGraph by giving its
starting and ending nodes. |
void |
removeNode(char c)
Removes a node from this VisualGraph by giving its label. |
void |
resetNodes()
Reinitializes the nodes after running a test algorithm for layout purposes. |
java.lang.String |
runAStar(char start,
char goal)
Runs the A* Algorithm on this VisualGraph to find the
shortest path to the specified goal node from the indicated start node. |
void |
setBounds(double x1,
double y1,
double x2,
double y2)
Sets the bounds in which this VisualGraph is to be drawn. |
void |
setDirected()
Indicates that this VisualGraph has at least one directed
edge. |
void |
setEdgeColor(char start,
char end,
java.lang.String my_col)
Modifies the color for the specified edge in this VisualGraph. |
void |
setEdgeWeight(char start,
char end,
double new_weight)
Changes the edge weight for the specified edge in this VisualGraph. |
void |
setFontSize(double size)
Sets the minimum font size to keep the fonts in this VisualGraph readable. |
void |
setHeuristics(boolean h)
Sets whether this VisualGraph uses or does not use
heuristic values. |
void |
setLimitedNodePos(char index,
double x,
double y)
Changes the coordinates for the specified node in this VisualGraph. |
void |
setNodeColor(char c,
java.lang.String my_col)
Modifies the color for the specified node in this VisualGraph. |
void |
setNodePos(char index,
double x,
double y)
Changes the coordinates for the specified node in this VisualGraph. |
void |
setUndirected()
Indicates that this VisualGraph has only bidirectional
edges. |
void |
setUnweighted()
Specifies that this VisualGraph has unweighted edges. |
void |
setWeighted()
Specifies that this VisualGraph has weighted edges. |
java.lang.String |
testAStar(char start,
char goal)
Runs the A* Algorithm on this VisualGraph to monitor if the
algorithm will have to reopen a closed node to find the shortest path to
the specified goal node from the indicated start node. |
int |
translateCharIndex(char c)
Returns the my_nodeset index that corresponds to the
specified name/label value. |
char |
translateIndexChar(int index)
Returns the name/label of the node at the specified index in my_nodeset. |
void |
writeGAIGSGraph(java.io.PrintWriter out,
java.lang.String title)
Writes this VisualGraph to the given
PrintWriter output stream using the original GAIGS
specifications for Graphs/Networks. |
void |
writeGAIGSXMLGraph(java.io.PrintWriter out)
Writes this VisualGraph to the given
PrintWriter output stream using the new GAIGS XML format. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int MAX_NODES
VisualGraph.
protected VisNode[] my_nodeset
VisualGraph.
Initialized with all VisNode objects in the default,
unactivated state. See default VisNode constructor for
details.
protected VisEdge[][] my_edgeset
VisualGraph.
Initialized with all VisEdge objects in the default,
unactivated state. See default VisEdge constructor for
details.
protected int num_nodes
VisualGraph.
Note that these activated nodes may not be consecutive within
my_nodeset.
protected int num_edges
VisualGraph.
protected double x1
VisualGraph within
the normalized [0,1] space. Defaults to 0.0 if no bounds
are set. The bounds variables can be used to localize this
VisualGraph in a section of the drawing window in the new
GAIGS XML format to allow multiple structures to appear in the same
snapshot.
protected double y1
VisualGraph within the
normalized [0,1] space. Defaults to 0.0 if no bounds are
set. The bounds variables can be used to localize this
VisualGraph in a section of the drawing window in the new
GAIGS XML format to allow multiple structures to appear in the same
snapshot.
protected double x2
VisualGraph within
the normalized [0,1] space. Defaults to 1.0 if no bounds
are set. The bounds variables can be used to localize this
VisualGraph in a section of the drawing window in the new
GAIGS XML format to allow multiple structures to appear in the same
snapshot.
protected double y2
VisualGraph within the
normalized [0,1] space. Defaults to 1.0 if no bounds are
set. The bounds variables can be used to localize this
VisualGraph in a section of the drawing window in the new
GAIGS XML format to allow multiple structures to appear in the same
snapshot.
protected double font_size
VisualGraph when drawn
in the new GAIGS XML format. Used to specify a font size that will be
readable when this VisualGraph is drawn in a smaller
portion of the screen.
protected boolean weighted
VisualGraph has weighted or
unweighted edges.
A value of true means that the edges are labeled with
weights, and false indicates they do not have labels.
protected boolean directed
VisualGraph has directed edges or
if all edges are undirected.
A value of true means that there is at least one directed
edge, and false indicates that all edges are bidirectional.
protected boolean heuristics
VisualGraph contains heuristic values
or whether it has no heuristic information.
A value of true means heuristics are used, and
false indicates there are no heuristic values.
| Constructor Detail |
|---|
public VisualGraph()
VisualGraph with default information.
public VisualGraph(boolean weighted,
boolean directed,
boolean heuristics)
VisualGraph by specifying whether or not it
has edge weights, directed edges, and heuristic values for nodes.
The bounds and font size are assigned default values and must be set via
separate method calls.
weighted - Indicates if this VisualGraph has
weighted edges. A value of true means
that the edges have weights that are displayed near
the edges; false indicates that no
edge weights are present.directed - Specifies whether the edges of this
VisualGraph are directed or
bidirectional. A value of true indicates
directed edges, and false means that all
edges are bidirectional.heuristics - Indicates if this VisualGraph contains
heuristic values. A value of true means
that the nodes have heuristic values that are
displayed under the node labels; false
indicates that no heuristic values should be shown.| Method Detail |
|---|
public void clearGraph()
VisualGraph by returning the data for all nodes
and edges to their default values.
public void setBounds(double x1,
double y1,
double x2,
double y2)
VisualGraph is to be drawn.
These bounds specify the area in the normalized [0,1] space within which
this VisualGraph should appear in the snapshot. Used to
draw this VisualGraph in a portion of the viewing window so
that multiple structures can appear in a snapshot in the new GAIGS XML
format.
x1 - Sets the left-most bound on the horizontal axis.y1 - Sets the lower bound on the vertical axis.x2 - Sets the right-most bound on the horizontal axis.y2 - Sets the upper bound on the vertical axis.public void setFontSize(double size)
VisualGraph readable. Used to upsize the font when drawing
this VisualGraph in a portion of the viewing window in the
new GAIGS XML format.
size - Indicates the minimum font size for the fonts in this
VisualGraph.public void setWeighted()
VisualGraph has weighted edges.
After calling this method, edges are labeled with their weights when
this VisualGraph is written to a showfile.
public void setUnweighted()
VisualGraph has unweighted edges.
After calling this method, edges will not have labels when this
VisualGraph is written to a showfile.
public void setDirected()
VisualGraph has at least one directed
edge.
If there are already edges activated in this VisualGraph,
this method returns without doing anything.
public void setUndirected()
VisualGraph has only bidirectional
edges.
Note that, after calling this method, this VisualGraph can
have no directed edges.
If there are already edges activated in this VisualGraph,
this method returns without doing anything.
public void setHeuristics(boolean h)
VisualGraph uses or does not use
heuristic values.
h - Indicates if heuristic values are used. A value of
true means that heuristic values are displayed
under the node labels, and false causes no
heuristic values to be shown.public boolean isWeighted()
VisualGraph has weighted or unweighted edges.
true if the edges are displayed with weights
and false if the edges are shown without weightspublic boolean isDirected()
VisualGraph has directed or bidirectional
edges.
true if there is at least one directed edge
in this VisualGraph and false if all edges are
bidirectional.public boolean hasHeuristics()
VisualGraph contains or does not contain
heuristic values.
true if heuristic values are shown under the
node labels and false if no heuristic values are
displayed.public int getNumNodes()
VisualGraph.
Note that these activated nodes do not necessarily occupy consecutive
indices within my_nodeset, the list of all possible nodes
in the graph.
VisualGraph.public int getNumEdges()
VisualGraph.
VisualGraph.public VisNode[] getNodes()
my_nodeset so that a script-producing program can
access the VisNode objects that comprise this
VisualGraph.
This allows convenient and efficient manipulation of the coloring and
other attributes of the nodes so that the showfile produced by this
VisualGraph matches the state of the script-producing
program.
my_nodeset.public VisEdge[][] getEdges()
my_edgeset so that a script-producing program can
access the VisEdge objects that comprise this
VisualGraph.
This allows convenient and efficient manipulation of the coloring and
other attributes of the edges so that the showfile produced by this
VisualGraph matches the state of the script-producing
program.
my_edgeset.
public void addNode(char c,
double my_x,
double my_y,
java.lang.String my_col)
VisualGraph by specifying its
label, coordinates, and color.
The indicated node in the graph is activated and modified according to
the values given. If the node with this label is already activated, this
method returns without doing anything.
c - Indicates which node is to be activated by giving its
unique name/label. The node with this character is
activated and modified according to the other parameters.my_x - Sets the Cartesian x-coordinate of the center of this
node in [0,1] space.my_y - Sets the Cartesian y-coordinate of the center of this
node in [0,1] space.my_col - Indicates the color of this newly activated node. The
value must be a six-digit hexadecimal color
String of the form #123456. The
symbol '#' must be included.
public void addNode(char c,
java.lang.String my_col)
VisualGraph by specifying its
label and color.
The indicated node in the graph is activated and modified according to
the values given. If the node with this label is already activated, this
method returns without doing anything.
c - Indicates which node is to be activated by giving its
unique name/label. The node with this character is
activated and modified according to the other parameter.my_col - Indicates the color of this newly activated node. The
value must be a six-digit hexadecimal color
String of the form #123456. The
symbol '#' must be included.
public void addEdge(char start,
char end,
double weight,
java.lang.String my_col)
VisualGraph by specifying its start
start node, end node, weight, and color.
The indicated edge in the graph is activated and modified according to
the values given. If the graph is directed, only the specified edge is
added; however, if the graph is not directed, the corresponding edge
from end to start is activated as well. If the
edge with these start and end nodes is already activated, this method
returns without doing anything.
start - Gives the label of the starting node for this edge.end - Gives the label of the ending node for this edge.weight - Specifies the weight for this new edge. This value is
ignored for an unweighted graph.my_col - Indicates the color of this newly activated edge. The
value must be a six-digit hexadecimal color
String of the form #123456. The
symbol '#' must be included.public void removeNode(char c)
VisualGraph by giving its label.
The indicated node is deactivated, along with any edges connected to it.
If the node is already deactivated, this method returns without doing
anything.
c - Indicates which node is to be deactivated by giving its unique
name/label. This node is deactivated so that it will not be
displayed.
public void removeEdge(char start,
char end)
VisualGraph by giving its
starting and ending nodes.
The given edge is deactivated so that it will not be displayed with the
graph. If the graph is directed, only the specified edge is removed;
however, if the graph is not directed, the corresponding edge from
end to start is deactivated as well. If the
edge with these start and end nodes is already deactivated, this method
returns without doing anything.
start - Gives the label for the starting node for this edge.end - Gives the label for the ending node for this edge.
public void setNodeColor(char c,
java.lang.String my_col)
VisualGraph.
If the indicated node is not activated, this method returns without
doing anything.
c - Indicates the node that should be changed by giving its
unique name/label.my_col - Gives the new color for this node. The value must be a
six-digit hexadecimal String of the form
#123456. The symbol '#' must be included.
public void setEdgeColor(char start,
char end,
java.lang.String my_col)
VisualGraph.
If the indicated edge is not activated, this method returns without
doing anything.
start - Indicates the starting node for the edge that should be
changed.end - Indicates the ending node for the edge that should be
changed.my_col - Gives the new color for this edge. The value must be a
six-digit hexadecimal String of the form
#123456. The symbol '#' must be included.
public void setEdgeWeight(char start,
char end,
double new_weight)
VisualGraph.
If the indicated edge is not activated, this method returns without
doing anything.
start - Indicates the starting node for the edge that should
be changed.end - Indicates the ending node for the edge that should be
changed.new_weight - Gives the new weight for the indicated edge.
public void setNodePos(char index,
double x,
double y)
VisualGraph.
Any edges connected to this node are adjusted so that they will still
properly connect to this node. If the indicated node is not activated,
this method returns without doing anything.
index - Indicates the node that should be changed by giving its
unique name/label.x - Gives the new Cartesian x-coordinate for the center of this
node in [0,1] space.y - Gives the new Cartesian y-coordinate for the center of this
node in [0,1] space.
public void setLimitedNodePos(char index,
double x,
double y)
VisualGraph.
The coordinate values are limited to [0,1]. Therefore, if the value
given is greater than 1.0, it will be changed to 1.0, and, if the value
given is less than 0.0, it will be changed to 0.0. Any edges connected
to this node are adjusted so that they will still properly connect to
this node. If the indicated node is not activated, this method returns
without doing anything.
index - Indicates the node that should be changed by giving its
unique name/label.x - Gives the new Cartesian x-coordinate for the center of this
node in [0,1] space.y - Gives the new Cartesian y-coordinate for the center of this
node in [0,1] space.
public double edgeWeight(char start,
char end)
VisualGraph.
The value returned for an unactivated edge will always be 0.0.
start - Indicates the starting node for the edge whose weight is to
be returned.end - Indicates the ending node for the edge whose weight is to
be returned.
start to
end.
public boolean edgeExists(char start,
char end)
VisualGraph.
start - Indicates the starting node for the edge whose existence is
in question.end - Indicates the ending node for the edge whose existence is
in question.
true if the specified edge is
activated; otherwise, false is returned.public boolean nodeExists(char c)
VisualGraph.
c - Indicates the node whose existence is in question.
true if the specified node is
activated; otherwise, false is returned.public java.util.Enumeration allNodes()
Enumeration of all the nodes in this
VisualGraph.
Enumeration that contains all the nodes in
this VisualGraph.public java.util.Enumeration allAdjacentNodes(char c)
Enumeration of all the nodes in this
VisualGraph that are connected to the given node via an
edge.
c - Indicates the node for which the connecting nodes should be
enumerated.
Enumeration that contains all the nodes
in this VisualGraph with an edge from
c.public boolean empty()
VisualGraph is empty or contains
some data.
true if there are no nodes and no
edges in this VisualGraph; otherwise,
false is returned.public boolean full()
VisualGraph.
true if the maximum number of
nodes has been reached; otherwise, false is
returned.public boolean fullEdge()
VisualGraph.
true if the maximum number of
edges has been reached; otherwise, false is
returned.
public void organizeGraph()
throws java.io.IOException
VisualGraph to produce a readable layout.
This method uses the following formulas:
java.io.IOException - Indicates that an error occurred while organizing
the graph. The graph may be left in an unreliable
state.public void organizeCircle()
VisualGraph around a unit
circle to produce a more readable layout.
Note that the graph must have more than three nodes to use this method.
public boolean gaigsIsOverlap()
VisualGraph's layout does not have
any overlaps.
This involves three steps:
The tolerances for the above checks can be adjusted by changing
NODE_TOEDGE_MIN, EDGE_LENGTH_MIN, and
EDGE_CENTER_MIN respectively.
true if one of the above checks
finds an overlap in the graph layout; otherwise,
false is returned.
public void randomGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
throws java.lang.RuntimeException
VisualGraph and produces a randomly generated
graph according to the supplied constraints.
node_c - Indicates the number of nodes to appear in the
graph. A value of 0 means that a random number
of nodes should be generated.edge_c - Indicates the number of edges to appear in the
graph. A value of -1 means that a random number
of edges should be generated.self_loop - Specifies if edges with the same start and goal
node are possible. A value of true
indicates that self-loops are allowed, and
false means they are not.weights - Specifies if the edges in the graph should be
weighted. Passing true results in
a weighted graph, and false yields
an unweighted graph.dircted - Indicates if the edges in the graph should be
directed. Giving a value of true
means that edges can be unidirectional, and
false makes all edges
bidirectional.min_weight - Specifies the minimum weight for edges in the
graph. Ignored if the graph is to be
unweighted.max_weight - Specifies the maximum weight for edges in the
graph. Ignored if the graph is to be
unweighted.
java.lang.RuntimeException - Indicates a problem finding a random edge. This
VisualGraph will be in an
unreliable state, and this method should be
called again to generate the desired random
graph.
public void randomCompleteGraph(int node_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
VisualGraph and produces a randomly generated
complete graph according to the supplied constraints.
node_c - Indicates the number of nodes to appear in the graph.
A value of 0 means that a random number of nodes
should be generated.self_loop - Specifies if edges with the same start and goal node
are possible. A value of true indicates
that self-loops are allowed, and false
means they are not.weights - Specifies if the edges in the graph should be
weighted. Passing true results in a
weighted graph, and false yields an
unweighted graph.min_weight - Specifies the minimum weight for edges in the graph.
Ignored if the graph is to be unweighted.max_weight - Specifies the maximum weight for edges in the graph.
Ignored if the graph is to be unweighted.
public void randomHamiltonianGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
throws java.lang.RuntimeException
VisualGraph and produces a randomly generated
graph containing a Hamiltonian Cycle according to the supplied
constraints.
node_c - Indicates the number of nodes to appear in the
graph. A value of 0 means that a random number
of nodes should be generated.edge_c - Indicates the number of edges to appear in the
graph. A value of -1 means that a random number
of edges should be generated.self_loop - Specifies if edges with the same start and goal
node are possible. A value of true
indicates that self-loops are allowed, and
false means they are not.weights - Specifies if the edges in the graph should be
weighted. Passing true results in
a weighted graph, and false yields
an unweighted graph.dircted - Indicates if the edges in the graph should be
directed. Giving a value of true
means that edges can be unidirectional, and
false makes all edges
bidirectional.min_weight - Specifies the minimum weight for edges in the
graph. Ignored if the graph is to be
unweighted.max_weight - Specifies the maximum weight for edges in the
graph. Ignored if the graph is to be
unweighted.
java.lang.RuntimeException - Indicates a problem finding a random edge. This
VisualGraph will be in an
unreliable state, and this method should be
called again to generate the desired random
graph.
public void randomConnectedGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
boolean dircted,
double min_weight,
double max_weight)
throws java.lang.RuntimeException
VisualGraph and produces a randomly generated
connected graph according to the supplied constraints.
node_c - Indicates the number of nodes to appear in the
graph. A value of 0 means that a random number
of nodes should be generated.edge_c - Indicates the number of edges to appear in the
graph. A value of -1 means that a random number
of edges should be generated. Note that more
edges than specified may have to be added to
make the graph connected.self_loop - Specifies if edges with the same start and goal
node are possible. A value of true
indicates that self-loops are allowed, and
false means they are not.weights - Specifies if the edges in the graph should be
weighted. Passing true results in
a weighted graph, and false yields
an unweighted graph.dircted - Indicates if the edges in the graph should be
directed. Giving a value of true
means that edges can be unidirectional, and
false makes all edges
bidirectional.min_weight - Specifies the minimum weight for edges in the
graph. Ignored if the graph is to be
unweighted.max_weight - Specifies the maximum weight for edges in the
graph. Ignored if the graph is to be
unweighted.
java.lang.RuntimeException - Indicates a problem finding a random edge. This
VisualGraph will be in an
unreliable state, and this method should be
called again to generate the desired random
graph.
public void randomDAcyclicGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
VisualGraph and produces a randomly generated
directed acyclic graph according to the supplied constraints.
node_c - Indicates the number of nodes to appear in the graph.
A value of 0 means that a random number of nodes
should be generated.edge_c - Indicates the number of edges to appear in the graph.
A value of -1 means that a random number of edges
should be generated. Note that more or fewer edges
than specified may have to be added to produce a
directed acyclic graph.self_loop - Specifies if edges with the same start and goal node
are possible. A value of true indicates
that self-loops are allowed, and false
means they are not.weights - Specifies if the edges in the graph should be
weighted. Passing true results in a
weighted graph, and false yields an
unweighted graph.min_weight - Specifies the minimum weight for edges in the graph.
Ignored if the graph is to be unweighted.max_weight - Specifies the maximum weight for edges in the graph.
Ignored if the graph is to be unweighted.
public void OLDrandomDAcyclicGraph(int node_c,
int edge_c,
boolean self_loop,
boolean weights,
double min_weight,
double max_weight)
public void randomGAIGSGraph(int numNodes,
int numEdges,
double min_weight,
double max_weight)
VisualGraph and produces a randomly generated
sparsely connected graph suitable for many algorithm visualizations.
numNodes - Indicates the number of nodes to appear in the graph.
Note that, unlike the other graph generation methods,
a value of 0 does not indicate that a random
number of nodes should be added.numEdges - Indicates the number of edges to appear in the graph.
This number may be changed to produce a connected
graph. Note that, unlike the other graph generation
methods, a value of -1 does not indicate that a
random number of edges should be added.min_weight - Specifies the minimum weight for edges in the graph.max_weight - Specifies the maximum weight for edges in the graph.
public int[] randomHeuristicGraph(int node_c,
int edge_c)
VisualGraph and produces a randomly generated
sparsely connected graph with heuristic values for the nodes.
This method uses the A* Algorithm to test for the shortest path through
this graph that has the greatest number of nodes. It then initializes
the heuristic values for the nodes based on their Euclidean distances
from the goal node for this path and returns the start and goal nodes
for this path.
node_c - Indicates the number of nodes to appear in the graph. A
value of 0 means that a random number of nodes should be
generated.edge_c - Indicates the number of edges to appear in the graph. A
value of -1 means that a random number of edges should be
generated.
ints
that give the nodes' indices in my_nodeset.
public int[] randomAStarSearchGraph(int node_c,
int edge_c)
VisualGraph and produces a randomly generated
sparsely connected heuristic graph that demonstrates the unique feature
of the A* Algorithm, namely the reopening of a closed node when a poor
heuristic value caused the node to be closed with a greater-than-optimal
cost. It then returns the start and goal nodes for this path.
node_c - Indicates the number of nodes to appear in the graph. A
value of 0 means that a random number of nodes should be
generated.edge_c - Indicates the number of edges to appear in the graph. A
value of -1 means that a random number of edges should be
generated.
ints
that give the nodes' indices in my_nodeset.public char randomNode()
char name/label value for a randomly
chosen node.public char randomActiveNode()
char name/label value for a randomly
chosen activated node. If there are currently no activated
nodes, the value returned is the invalid char '~'.public char randomNewNode()
char name/label value for a randomly
chosen unactivated node. If there are currently no unactivated
nodes, the value returned is the invalid char '~'.public int translateCharIndex(char c)
my_nodeset index that corresponds to the
specified name/label value.
c - Indicates the name/label of the node for which the index is to
be found.
my_nodeset. If the value passed to c
is not a valid node name/label, this method returns
-1.public char translateIndexChar(int index)
my_nodeset.
index - Indicates the index in my_nodeset for which
the name/label is to be found.
index in
my_nodeset. If the value passed to
index is invalid, this method returns
'~'.public char getNextNode()
char name/label for the next unactivated node.
char value that serves as the unique
name/label for the next unactivated node in this
VisualGraph. Returns '~' if all
available nodes are already activated.
public void gaigsChangeHexNodeColors(java.lang.String search,
java.lang.String replace)
VisualGraph with the color
indicated by search to have the color specified by
replace.
search - Gives the color that should be changed to the new color.
This value must be a six-digit hexadecimal
String of the form #123456. The
symbol '#' must be included.replace - Indicates the new color for the nodes that should be
changed. This value must be a six-digit hexadecimal
String of the form #123456. The
symbol '#' must be included.
public void gaigsChangeHexEdgeColors(java.lang.String search,
java.lang.String replace)
VisualGraph with the color
indicated by search to have the color specified by
replace.
search - Gives the color that should be changed to the new color.
This value must be a six-digit hexadecimal
String of the form #123456. The
symbol '#' must be included.replace - Indicates the new color for the edges that should be
changed. This value must be a six-digit hexadecimal
String of the form #123456. The
symbol '#' must be included.
public double gaigsDistPoints(double x1,
double y1,
double x2,
double y2)
x1 - Indicates the x-coordinate of the first point for which the
Euclidean distance is to be found.y1 - Specifies the y-coordinate of the first point for which the
Euclidean distance is to be found.x2 - Indicates the x-coordinate of the second point for which the
Euclidean distance is to be found.y2 - Specifies the y-coordinate of the second point for which the
Euclidean distance is to be found.public void initializeHValues(int g)
g - Indicates the goal node for which the heuristic values should
be initialized. This value is the goal node's index in
my_nodeset.public void initializeEdgeWeights()
Note that this method sets edge weights bidirectionally and is not intended for directed graphs.
public void resetNodes()
#FFFFFF
(white), making each node's closed data member
false, setting each node's cost to be a large
number, and reseting each node's pred to the default value.
Heuristic values are left unchanged because it is assumed that any
changes to heuristic values are meant to bring about the desired
operation when the actual script-producing program is run.
public java.lang.String testAStar(char start,
char goal)
VisualGraph to monitor if the
algorithm will have to reopen a closed node to find the shortest path to
the specified goal node from the indicated start node.
After calling this method, the nodes in the graph will contain the
information from running the search. Therefore, resetNodes()
should be called before running the script-producing program to produce
the GAIGS animation so that the script-producing program will execute
correctly.
start - Indicates the start node for this A* Search by giving its
name/label.goal - Specifies the goal node for this A* Search by giving its
name/label.
"ABC"
(the path from A to B to C). If a node was not reopened to
find the shortest path, returns the empty
String, "".
public java.lang.String runAStar(char start,
char goal)
VisualGraph to find the
shortest path to the specified goal node from the indicated start node.
After calling this method, the nodes in the graph will contain the
information from running the search. Therefore, resetNodes()
should be called before running the script-producing program to produce
the GAIGS animation so that the script-producing program will execute
correctly.
start - Indicates the start node for this A* Search by giving its
name/label.goal - Specifies the goal node for this A* Search by giving its
name/label.
"ABC" (the path from A to B
to C).
public void writeGAIGSGraph(java.io.PrintWriter out,
java.lang.String title)
VisualGraph to the given
PrintWriter output stream using the original GAIGS
specifications for Graphs/Networks.
If the graph is weighted, a Network structure will be produced;
otherwise, a Graph structure will be printed to the indicated output
stream. This method also takes the slide's title so that it can be
inserted into the appropriate place in the snapshot.
out - Specifies the output stream to which the Graph/Network
snapshot is to be written.title - Indicates the title for the Graph/Network snapshot that is
written to this output stream.public void writeGAIGSXMLGraph(java.io.PrintWriter out)
VisualGraph to the given
PrintWriter output stream using the new GAIGS XML format.
This method only writes the <graph> portion of a
snapshot so that other structures can accompany the graph in the
snapshot.
out - Indicates the output stream to which the graph should be
written.
public void readGAIGSXMLGraph(java.lang.String filename)
throws java.io.FileNotFoundException,
java.io.IOException
<graph> tags to initialize this
VisualGraph.
Note that this method is meant to read in a graph that was written to
the showfile using writeGAIGSXMLGraph and may not work for
graph showfiles produced in another manner because it assumes that all
attributes will be explicitly listed.
filename - Indicates the file from which the graph
should be read.
java.io.FileNotFoundException - Indicates that the file specified by
filename could not be found
when trying to open it.
java.io.IOException - Indicates that the format of the
<graph> specification
was not as expected. This method is only
assured to work with showfiles produced
using writeGAIGSXMLGraph.
public int[] readStartGoal(java.lang.String filename)
throws java.io.FileNotFoundException,
java.io.IOException,
java.util.NoSuchElementException
<title> element in the showfile.
This method was intended to accompany the readGAIGSXMLGraph
method for the AStarSearch, BestFirstSearch, and LeastCostSearch
programs. It will only be useful to find the start and goal nodes in a
graph-search showfile if the first title in the show is of the form:
". . . Start Node {start node's name} . . .
Goal Node {goal node's name} . . .".
filename - Indicates the file from which the title
should be read.
my_nodeset of the start and
goal nodes in a two-element array. The
first element is the start node's index,
and the second element is the goal node's
index.
java.io.FileNotFoundException - Indicates that the file specified by
filename could not be found
when trying to open it.
java.io.IOException - Indicates that the first title was not in
the correct format for this method to
extract the start and goal nodes.
java.util.NoSuchElementException - Indicates that the first title was not in
the correct format for this method to
extract the start and goal nodes.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||