Project2/BreadthFirstSearchAlgorithm.class010066600431230000012000000007130652330036300214730ustar00novikstaff00000400000023-     ()V (LWNode;)V(Ljava/lang/Object;)VBreadthFirstSearchAlgorithm BreadthFirstSearchAlgorithm.javaCode ConstantValue ExceptionsLineNumberTableLjava/util/Vector;LocalVariablesSearchAlgorithm SourceFile addElementenqueuejava/util/Vector nodeQueue! % *+  * Project2/BreadthFirstSearchAlgorithm.html010066600431230000012000000045010652330036500213330ustar00novikstaff00000400000023 Class BreadthFirstSearchAlgorithm

Class BreadthFirstSearchAlgorithm

java.lang.Object
   |
   +----SearchAlgorithm
           |
           +----BreadthFirstSearchAlgorithm

public class BreadthFirstSearchAlgorithm
extends SearchAlgorithm
Extends SearchAlgorithm class to use Breadth-First method, searching through all nodes on a particular level of the tree before going deeper.


Constructor Index

 o BreadthFirstSearchAlgorithm()

Method Index

 o enqueue(WNode)
This method will be called to enqueue a new node.

Constructors

 o BreadthFirstSearchAlgorithm
 public BreadthFirstSearchAlgorithm()

Methods

 o enqueue
 protected void enqueue(WNode newNode)
This method will be called to enqueue a new node. BreadthFirstSearch: enqueue new nodes at the end.

Overrides:
enqueue in class SearchAlgorithm
Project2/DepthFirstSearchAlgorithm.class010066600431230000012000000007160652330036600211740ustar00novikstaff00000400000023-     ()V (LWNode;)V(Ljava/lang/Object;I)VCode ConstantValueDepthFirstSearchAlgorithmDepthFirstSearchAlgorithm.java ExceptionsLineNumberTableLjava/util/Vector;LocalVariablesSearchAlgorithm SourceFileenqueueinsertElementAtjava/util/Vector nodeQueue! & *+   * Project2/DepthFirstSearchAlgorithm.html010066600431230000012000000044070652330037000210270ustar00novikstaff00000400000023 Class DepthFirstSearchAlgorithm

Class DepthFirstSearchAlgorithm

java.lang.Object
   |
   +----SearchAlgorithm
           |
           +----DepthFirstSearchAlgorithm

public class DepthFirstSearchAlgorithm
extends SearchAlgorithm
Extends SearchAlgorithm class to use Depth-First method, searching the deepest nodes in the tree first.


Constructor Index

 o DepthFirstSearchAlgorithm()

Method Index

 o enqueue(WNode)
This method will be called to enqueue a new node.

Constructors

 o DepthFirstSearchAlgorithm
 public DepthFirstSearchAlgorithm()

Methods

 o enqueue
 protected void enqueue(WNode newNode)
This method will be called to enqueue a new node. DepthFirstSearch: enqueue new nodes at the front.

Overrides:
enqueue in class SearchAlgorithm
Project2/DepthLimitedSearchAlgorithm.class010066600431230000012000000017250652330037100214710ustar00novikstaff00000400000023-J/079@AB            ! " # ,( :3 ;) <* =+ >' ?$ C( D% E% F5 G$ H& I(()I ()LWNode;()Ljava/lang/String;()Ljava/util/Vector;()V(I)Ljava/lang/Object; (LWNode;)V(Ljava/lang/Object;)ZCode ConstantValueDepthFirstSearchAlgorithmDepthLimitedSearchAlgorithm DepthLimitedSearchAlgorithm.java ExceptionsILineNumberTableLjava/lang/String;LocalVariablesSearchAlgorithm SourceFileWNodedepth elementAtenqueueequalsexpand getNodeDepthjava/lang/Exceptionjava/lang/Stringjava/util/Vectorpausepop searchQueue searchStringsizetoStringvisit!E%-Y**M,,,*, ,,* *, L>*+  +*46  !!"##.%3(8)=*I)T,2,(-*481Project2/DepthLimitedSearchAlgorithm.html010066600431230000012000000050710652330037300213300ustar00novikstaff00000400000023 Class DepthLimitedSearchAlgorithm

Class DepthLimitedSearchAlgorithm

java.lang.Object
   |
   +----SearchAlgorithm
           |
           +----DepthFirstSearchAlgorithm
                   |
                   +----DepthLimitedSearchAlgorithm

public class DepthLimitedSearchAlgorithm
extends DepthFirstSearchAlgorithm
Extends the DepthFirstSearchAlgorithm class to use the Depth-Limited search algorithm, which performs depth-first search but stops at a specified depth before going any further.


Constructor Index

 o DepthLimitedSearchAlgorithm()

Method Index

 o searchQueue()
Override searchQueue (from the SearchAlgorithm class) to return when a specific depth is reached.

Constructors

 o DepthLimitedSearchAlgorithm
 public DepthLimitedSearchAlgorithm()

Methods

 o searchQueue
 protected WNode searchQueue() throws Exception
Override searchQueue (from the SearchAlgorithm class) to return when a specific depth is reached.

Overrides:
searchQueue in class SearchAlgorithm
Project2/IterativeDeepeningSearchAlgorithm.class010066600431230000012000000020260652330037600226700ustar00novikstaff00000400000023-E 5,-/68=>?            )# )( 9# :% ;' <! @3 B" C2 D$()I ()LWNode;()V(I)V (LWNode;)V"(LWNode;Ljava/lang/String;)LWNode;(Ljava/lang/Object;)Z(Ljava/lang/String;)VCode ConstantValueDepthFirstSearchAlgorithmDepthLimitedSearchAlgorithm Exceptions!IterativeDeepeningSearchAlgorithm&IterativeDeepeningSearchAlgorithm.javaLineNumberTableLjava/lang/String;Ljava/util/Vector;LocalVariablesNo search string specified.SearchAlgorithm SourceFileWNode clearSearchenqueueequals getTreeDepthjava/lang/Exceptionjava/lang/Stringjava/util/Vector nodeQueuesearch searchQueue searchStringsetDepth!A&*aN* Y , , Y +-*,+66 *+***N---1F $(*/$5%;&@'F(J)O*S+U%_/.)#** 170Project2/IterativeDeepeningSearchAlgorithm.html010066600431230000012000000055340652330040000225220ustar00novikstaff00000400000023 Class IterativeDeepeningSearchAlgorithm

Class IterativeDeepeningSearchAlgorithm

java.lang.Object
   |
   +----SearchAlgorithm
           |
           +----DepthFirstSearchAlgorithm
                   |
                   +----DepthLimitedSearchAlgorithm
                           |
                           +----IterativeDeepeningSearchAlgorithm

public class IterativeDeepeningSearchAlgorithm
extends DepthLimitedSearchAlgorithm
Extends the DepthLimitedSearchAlgorithm class to use the Iterative Deepening search algorithm, which performs depth-limited search repeatedly, increasing the depth limit each time, until the tree is empty or the desired node is found.


Constructor Index

 o IterativeDeepeningSearchAlgorithm()

Method Index

 o search(WNode, String)
Override search method from SearchAlgorithm class.

Constructors

 o IterativeDeepeningSearchAlgorithm
 public IterativeDeepeningSearchAlgorithm()

Methods

 o search
 public WNode search(WNode root,
                     String searchString) throws Exception
Override search method from SearchAlgorithm class.

Overrides:
search in class SearchAlgorithm
Project2/PolyLine.class010066600431230000012000000005650652330040300156500ustar00novikstaff00000400000023-       ()V(IILPolyLine;)VCode ConstantValue ExceptionsI LPolyLine;LineNumberTableLocalVariablesPolyLine PolyLine.java SourceFiledxdyjava/lang/Objectlink  <****-  Project2/Polygon.class010066600431230000012000000005130652330040200155340ustar00novikstaff00000400000023-   ()VCode ConstantValue Exceptions LPolyLine;LineNumberTableLocalVariablesPolygon Polygon.java SourceFilejava/lang/Object lower_head lower_tail upper_head upper_tail     * Project2/README010066400431230000012000000043550652336222300137550ustar00novikstaff00000400000023Naomi Novik novik@staff.juno.com 05/04/1998 CS4701: Artificial Intelligence Project 2: SearchApplet ======================== This project demonstrates the operation of several blind-search algorithms, including breadth-first, depth-first, depth-limited, and iterative deepening. It provides a framework which makes adding new search algorithms easy, and demonstrates how they work by displaying the algorithm's progress through a small tree. To see the project, simply open up the index.html file in a Java-capable browser. The applet is Java 1.0 compliant and has been successfully tested with the following browsers and platforms: IE 3.02 under WinNT 4.0 Netscape 3.0 under Solaris Netscape 4.0 under WinNT 4.0 and Win95 FILELIST (pathnames from the top-level directory) ======== HTML files ---------- index.html The web page containing the applet. javadoc-generated class documentation: tree.html packages.html AllNames.html BreadthFirstSearchAlgorithm.html DepthFirstSearchAlgorithm.html DepthLimitedSearchAlgorithm.html IterativeDeepeningSearchAlgorithm.html SearchAlgorithm.html SearchApplet.html WNode.html WTFactory.html WalTreeCanvas.html Source code ----------- source/BreadthFirstSearchAlgorithm.java source/DepthFirstSearchAlgorithm.java source/DepthLimitedSearchAlgorithm.java source/IterativeDeepeningSearchAlgorithm.java source/PolyLine.java source/Polygon.java source/SearchAlgorithm.java source/SearchApplet.java source/WNode.java source/WTFactory.java source/WalTreeCanvas.java Class files ----------- BreadthFirstSearchAlgorithm.class DepthFirstSearchAlgorithm.class DepthLimitedSearchAlgorithm.class IterativeDeepeningSearchAlgorithm.class PolyLine.class Polygon.class SearchAlgorithm.class SearchApplet.class WNode.class WTFactory.class WalTreeCanvas.class Image files (used by javadoc-generated HTML files) ----------- images/blue-ball-small.gif images/blue-ball.gif images/class-index.gif images/constructor-index.gif images/constructors.gif images/error-index.gif images/exception-index.gif images/interface-index.gif images/method-index.gif images/methods.gif images/package-index.gif images/red-ball-small.gif images/red-ball.gif images/variable-index.gif images/variables.gif images/yellow-ball-small.gif images/yellow-ball.gif Project2/SearchAlgorithm.class010066600431230000012000000043170652330040400171710ustar00novikstaff00000400000023->OXYZ\^ijklmn ( ( ) ) * + , - . / 0 1 2 3 3 4 5 6 7 8 9 : ; < < = LC LK `E aR bC cQ dD eH fJ gB oV pC r@ sF u@ vU yK z? {T }_ ~A C()I ()LWNode;()Ljava/lang/String;()Ljava/util/Vector;()V(I)Ljava/lang/Object;(I)Ljava/lang/StringBuffer;(I)V(LSearchApplet;)V (LWNode;)V"(LWNode;Ljava/lang/String;)LWNode;(Ljava/lang/Object;)Z(Ljava/lang/String;)VCode ConstantValueDepth limit set to:  ExceptionsILSearchApplet;LineNumberTableLjava/awt/TextField;Ljava/lang/String;Ljava/util/Vector;LocalVariablesNo search string specified.Search AlgorithmSearchAlgorithmSearchAlgorithm.java SearchApplet SourceFileWNodeZappendcaller clearSearchdepth elementAtenqueueequalsexpandinitjava/awt/TextComponentjava/lang/Exceptionjava/lang/Objectjava/lang/Stringjava/lang/StringBufferjava/util/Vector nodeQueuepausepeekpopremoveElementAtsearch searchQueue searchString setCallersetDepthsetTextsize statusBarstop stopRequestedtoStringvisit! aR}_oVvUcQ LCM4**$* S. (-wGM"*+S 65xFM@ **# Y&!S=><bCM$*S GF|CM"*$S NMhCM"*$S UTr@ML$L*"+*L*+S\]^_"`q@M@L*"+*L+SghijpCM=*$ Y*SqrtpP tIMw;N* Y, , Y+-*, *+*N-S* {| ~$(*/49P u@MI**M,,,'* ,%,,L>*++"*S.  !#(-9DP eHMS][Project2/SearchAlgorithm.html010066600431230000012000000176540652330040700170430ustar00novikstaff00000400000023 Class SearchAlgorithm

Class SearchAlgorithm

java.lang.Object
   |
   +----SearchAlgorithm

public class SearchAlgorithm
extends Object
A generic search algorithm, implementing the basic methods needed for a search. The three main methods that need to be overridden in order to make a specific search algorithm are search(), searchQueue(), and enqueue().

Author:
Naomi Novik

Variable Index

 o depth
Maximum depth in the tree to search until, used in depth-limited and iterative-deepening search algorithms.
 o nodeQueue
Vector containing the queue of nodes to search.
 o searchString
What to look for.
 o stopRequested
When true stop searching.

Constructor Index

 o SearchAlgorithm()
Constructor.

Method Index

 o clearSearch()
Clear the search.
 o enqueue(WNode)
This method will be called to enqueue a new node.
 o init()
Initialize
 o pause()
Pause for a while.
 o peek()
Peek at the top value of nodeQueue.
 o pop()
Pop off the top value of nodeQueue.
 o search(WNode, String)
This method will be called to search through a tree.
 o searchQueue()
Recursively called to search through the queue of nodes.
 o setCaller(SearchApplet)
Set the caller.
 o setDepth(int)
Set depth.
 o stop()
Stop searching.

Variables

 o stopRequested
 protected boolean stopRequested
When true stop searching.

 o nodeQueue
 protected Vector nodeQueue
Vector containing the queue of nodes to search.

 o searchString
 protected String searchString
What to look for.

 o depth
 protected int depth
Maximum depth in the tree to search until, used in depth-limited and iterative-deepening search algorithms.

Constructors

 o SearchAlgorithm
 public SearchAlgorithm()
Constructor.

Methods

 o setCaller
 public void setCaller(SearchApplet c)
Set the caller.

 o setDepth
 public void setDepth(int d)
Set depth.

 o clearSearch
 protected void clearSearch()
Clear the search.

 o stop
 public void stop()
Stop searching.

 o init
 public void init()
Initialize

 o pop
 protected WNode pop()
Pop off the top value of nodeQueue.

 o peek
 protected WNode peek()
Peek at the top value of nodeQueue.

 o pause
 protected void pause() throws Exception
Pause for a while.

 o search
 public WNode search(WNode root,
                     String searchString) throws Exception
This method will be called to search through a tree.

 o searchQueue
 protected WNode searchQueue() throws Exception
Recursively called to search through the queue of nodes. Return the node if searchString found.

 o enqueue
 protected void enqueue(WNode newNode)
This method will be called to enqueue a new node. Should be overridden by child classes.

Project2/SearchApplet.class010066600431230000012000000142210652330041200164620ustar00novikstaff00000400000023-p      2NOh456789:;<=>?@ABCDEFGHIJ  ! " ( 7 * 4 # ' . 3 6 % % 7    3 3         7 2  +  ! ) 6 &     . 4    + 6  $      ) %   )   7 4 4    4 &  3 5   2                 ! " # $ & ' ) + , - . / 0 1 3 K L M P Q R T U W X Y Z [ \ ] ^ _ ` a b c d e f g i j k l m o()I()Ljava/lang/Object;()Ljava/lang/String;()Ljava/util/Vector;()V()Z()[[Ljava/lang/String;(I)Ljava/lang/Object;(I)Ljava/lang/StringBuffer;(I)V(J)V(LSearchApplet;)V (LWNode;)V"(LWNode;Ljava/lang/String;)LWNode;*(Ljava/awt/Component;)Ljava/awt/Component;(Ljava/awt/Event;)Z(Ljava/awt/LayoutManager;)V&(Ljava/lang/Object;)Ljava/lang/String;(Ljava/lang/Object;)V(Ljava/lang/Object;)Z(Ljava/lang/Runnable;)V%(Ljava/lang/String;)Ljava/lang/Class;&(Ljava/lang/String;)Ljava/lang/String;,(Ljava/lang/String;)Ljava/lang/StringBuffer;(Ljava/lang/String;)V0(Ljava/lang/String;LWNode;LWNode;LWNode;)LWNode;<(Ljava/lang/String;Ljava/awt/Component;)Ljava/awt/Component;(Z)V Algorithm BreadthFirstCenterClearCode ConstantValueError in search: Exception caught in pause:  ExceptionsFIXED_FONT_ASCENTFIXED_FONT_HEIGHTILSearchAlgorithm;LWNode;LWalTreeCanvas;LineNumberTableLjava/awt/Button;Ljava/awt/Panel;Ljava/awt/TextField;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Thread;Ljava/util/Vector;LocalVariablesNo search string entered!NorthSearch String: Search failed.Search string found at depth SearchAlgorithm SearchAppletSearchApplet initializing...SearchApplet ready: ,SearchApplet v. 0.1. Written by Naomi Novik.SearchApplet.java SourceFileSouth Start SearchStarting search.UThis is a string used to build a tree of strings for the search algorithms to work onWNode WalTreeCanvas[Ljava/lang/String;[[Ljava/lang/String;add addElement addStringalgalgName algorithmappend branchFactor btn_clear btn_start buildTreechild clearSearch clearTreedepth elementAtequalsexpandforName getAppletInfo getNodeDepth getParametergetParameterInfogetText handleEventhasMoreElementsidinfoinit inputPanel insertNodeintValueintegerisAlivejava/applet/Appletjava/awt/BorderLayoutjava/awt/Buttonjava/awt/Componentjava/awt/Containerjava/awt/Eventjava/awt/Labeljava/awt/Paneljava/awt/TextComponentjava/awt/TextFieldjava/lang/Classjava/lang/Exception%java/lang/IllegalThreadStateExceptionjava/lang/Integerjava/lang/InterruptedExceptionjava/lang/NumberFormatExceptionjava/lang/Runnablejava/lang/Stringjava/lang/StringBufferjava/lang/Threadjava/lang/Throwablejava/util/StringTokenizerjava/util/VectorkickerleavemakeNode&maximum depth to search to in the treename of search algorithm to use newInstance nextTokenparentpauserepaintrootrunsearch searchString setCallersetDepth setEditable setLayoutsetParentDistancesetSearchStringsetTextsetTreesiblingsizesleepstart startSearch statusBarstopstringtarget textToFindtoString treeCanvas treeNodes treeStringvalueOf!!1nKlUm/jXf-%^(*]b.{ *l*L*YL+L*3Y+BKH*"Y:p**Y8ZEW**Y(=z*zo*zs**zEW*q*(Y;_*_'Y @DW*_**Y =Z~DW*_*#Y?ZMDW*_*#Y?ZNDW* *_EW*j*O*z3YB*HKs^pq tuvx/{:|M}Z~bkv~ l*c+\+}*M *QH+\<+}*N1**~Zr*l*z s*zs*y6 1<CLOX\_a^- +*+l !g)*c*c|W*c*I *I{W-%&-6 %&'("eQ)*c *cb*i*4Y*>c*cx!(V:M*IG**HWfI*I*m*YN-#.Y*YAL*I+anW*I^*I*j*lkM*i, ,X>*z3YBJs*z sN*z3YB-Ks-FI0,f ")--;FIJMTdkotSm1*c *iwL*z3Y B+Ks/"0b.*S*7Y<6YCL +gM*,G+["#$%'(!)&'-"9*j*t*i12 40Z+U*j **+ej**jF*+eM*,`*,F**jt*i2 = > AB C+A.E:F?GGJRKY;0J6:*TM,VN-v6*L+,h+,Pu,+P*v. WXYZ['],^4_9`:WIRN***jR*i*z3YB*HKsijk)hT ++d+PM *,R,uM,"wx y{|}{ti9*9* Y2YSYSYSSY2YSYSYSS].d ed!f4d8. ClearCode ConstantValueError in search: Exception caught in pause:  ExceptionsFIXED_FONT_ASCENTFIXED_FONT_HEIGHTILSearchAlgorithm;LWNode;LWalTreeCanvas;LineNumberTableLjava/awt/Button;Ljava/awt/Panel;Ljava/awt/TextField;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Thread;Ljava/util/Vector;LocalVariablesProject2/SearchApplet.html010066600431230000012000000210530652330041500163250ustar00novikstaff00000400000023 Class SearchApplet

Class SearchApplet

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----SearchApplet

public class SearchApplet
extends Applet
implements Runnable
This applet runs a search algorithm on a tree, taking user input to determine what to search for within the tree and producing a visual representation of the search's progress through the tree. Uses some of the ideas demonstrated in the sort demo included with Sun's JDK 1.1. To use this applet, you would add a tag like the following into your HTML:
 <applet code="SearchApplet.class" width=400 height=350> 
 <PARAM name=alg value="BreadthFirstSearch"> 
 </applet>
 
If you are using the Depth-Limited algorithm, which takes a depth limit, you could also add another PARAM tag to specify that limit:
 <PARAM name=depth value="3">
 
To-do list of improvements
  • Allow the user to enter a block of text to be used as the tree instead of having it hardwired in.
  • Along the lines of the first one, have a randomly-generated "numeric" tree used.
  • Allow the user to input the branching factor of the tree, or perhaps just make this an optional parameter of the applet.

Author:
Naomi Novik

Variable Index

 o statusBar

Constructor Index

 o SearchApplet()

Method Index

 o addString(String)
Add the specified string to the displayed tree.
 o clearSearch()
Clear the search information while still preserving the tree.
 o clearTree()
Clear the tree completely.
 o getAppletInfo()
 o getParameterInfo()
 o handleEvent(Event)
Handle events that occur in the applet as a result of user action.
 o init()
Initialize the applet.
 o insertNode(WNode)
Insert the specified node into the tree at the next available spot (depends on branchFactor).
 o pause()
Pause a while, to make the search progress visually clearer.
 o run()
Main event loop.
 o stop()
Stop the applet.

Variables

 o statusBar
 public TextField statusBar

Constructors

 o SearchApplet
 public SearchApplet()

Methods

 o getAppletInfo
 public String getAppletInfo()
Overrides:
getAppletInfo in class Applet
 o getParameterInfo
 public String[][] getParameterInfo()
Overrides:
getParameterInfo in class Applet
 o init
 public void init()
Initialize the applet.

Overrides:
init in class Applet
 o handleEvent
 public boolean handleEvent(Event e)
Handle events that occur in the applet as a result of user action.

Overrides:
handleEvent in class Component
 o stop
 public synchronized void stop()
Stop the applet. Kill any algorithm that is still searching.

Overrides:
stop in class Applet
 o run
 public void run()
Main event loop. This will be called by the Thread forked off in startSearch. We need to set the search algorithm to be used, using the name specified in the applet's params.

 o pause
 public void pause()
Pause a while, to make the search progress visually clearer.

See Also:
SearchAlgorithm
 o clearTree
 public void clearTree()
Clear the tree completely.

 o addString
 public void addString(String s)
Add the specified string to the displayed tree.

 o insertNode
 public void insertNode(WNode n)
Insert the specified node into the tree at the next available spot (depends on branchFactor).

 o clearSearch
 public void clearSearch()
Clear the search information while still preserving the tree.

into your HTML:
 <applet code="SearchApplet.class" width=400 height=350> 
 <PARAM name=alg value="BreadthFirstSearch"> 
 </applet>
 
If you are using the Depth-Limited algorithm, which takes a depth limit, you could also add another PARAM tag to specify that limit:
 <PARAM name=depth value="3">
 
To-do list of improvements
  • Allow the user to enter a block of text to be used as the tree instead of haviProject2/WNode.class010066600431230000012000000026150652330042400151320ustar00novikstaff00000400000023-P68CDE              ! " # +' +( ;) </ =1 >0 B/ F4 H3 I1 J3 K1 N: O/()I()Ljava/lang/String;()Ljava/util/Vector;()V(II)V(Ljava/lang/Object;)V-(Ljava/lang/String;LWNode;LWNode;LWNode;III)VCode ConstantValue ExceptionsI LPolygon;LWNode;LineNumberTableLjava/awt/Point;Ljava/lang/String;LocalVariablesPolygon SourceFileWNode WNode.javaZ addElementborderchildcontourexpand getNodeDepth getTreeDepthheightjava/awt/Pointjava/lang/Objectjava/util/VectorlabelleaveoffsetparentpossiblingtoStringvisitvisitedwidth! F4I1=1K1O/B/</N:J3H3>0+*,V**+*,*- **** **Y *Y *Y 26 %& '()*+%,+-0.=/J0U%L%,*27M',"*2 >=G',"*2 ED?&,P YL* M +, ,M,+2MP QRSQV@$,H=*L +L+2`bc d echA$,E=*L + L+2rtuv wuz79Project2/WNode.html010066600431230000012000000120520652330042600147670ustar00novikstaff00000400000023 Class WNode

    Class WNode

    java.lang.Object
       |
       +----WNode
    

    public class WNode
    extends Object
    Represents a node (or tree) in the WalTree. This is part of the WalTree package, created by Walter Korman to enable the visually appealing display of M-ary trees. More documentation is available at his web site; follow the link below to get to it.

    Documentation

    Added by Naomi Novik:
    The boolean field "visited" and the "visit" and "leave" methods were added for use in displaying a search as it progresses through a tree. The methods expand(), getNodeDepth(), and getTreeDepth() were added to help with searching functions, so that calling classes don't need to know what the member fields of the WNode are. The toString() method was added for the same reason.

    Author:
    Walter Korman, Naomi Novik

    Constructor Index

     o WNode(String, WNode, WNode, WNode, int, int, int)

    Method Index

     o expand()
    Expand a node, returning a Vector containing its children.
     o getNodeDepth()
    Determine depth of node within the tree.
     o getTreeDepth()
    Determine maximum depth of tree rooted at this node.
     o leave()
    Change the visited status of the node to false.
     o toString()
    Return the label of the node.
     o visit()
    Change the visited status of the node to true.

    Constructors

     o WNode
     public WNode(String l,
                  WNode p,
                  WNode c,
                  WNode s,
                  int w,
                  int h,
                  int b)
    

    Methods

     o toString
     public String toString()
    
    Return the label of the node.

    Overrides:
    toString in class Object
     o visit
     public void visit()
    
    Change the visited status of the node to true.

     o leave
     public void leave()
    
    Change the visited status of the node to false.

     o expand
     public Vector expand()
    
    Expand a node, returning a Vector containing its children.

     o getNodeDepth
     public int getNodeDepth()
    
    Determine depth of node within the tree. The number of parents the node has represents its depth, assuming the root has depth 0.

     o getTreeDepth
     public int getTreeDepth()
    
    Determine maximum depth of tree rooted at this node. Assuming an even distribution, this is until there are no more children in a straight line from the root.

    Project2/WTFactory.class010066600431230000012000000103060652330043000157710ustar00novikstaff00000400000023-  9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b sc sg l ~ y h | { e e r y y y j k k ~ z z z i f  o | y m  q ~ n | p z z y y y()V(I)V(IIII)V (IIIIII)I(IILPolyLine;)V$(LPolyLine;IILPolyLine;II)LPolyLine;(LPolygon;LPolygon;)I (LWNode;)I (LWNode;)V (LWNode;I)V (LWNode;II)V(Ljava/awt/Color;)V3(Ljava/awt/Graphics;Ljava/awt/FontMetrics;LWNode;)V(Ljava/lang/String;)I(Ljava/lang/String;)V(Ljava/lang/String;II)VCode ConstantValue ExceptionsFIXED_FONT_ASCENTFIXED_FONT_HEIGHTI LPolyLine; LPolygon;LWNode;LineNumberTableLjava/awt/Color;Ljava/awt/Point;Ljava/io/PrintStream;Ljava/lang/String;LocalVariablesPolyLinePolygon SourceFileWNode WTFactoryWTFactory.javaZ attachParentblackborderbridgechildcontourdrawLinedrawRect drawStringdxdyheightjava/awt/Colorjava/awt/FontMetricsjava/awt/Graphicsjava/awt/Pointjava/io/PrintStreamjava/lang/Objectjava/lang/Systemjoinlabellayout layoutLeaf lightGraylink lower_head lower_tailmergeoffsetout paintFullTreepaintFullTree::null tree. paintTreeparent parent_dist plantTreeposprintlnredsetColorsetParentDistancesibling stringWidth upper_head upper_tailvisitedwidthxy! xyuwyuy dt"*+} &%ktw3++M *,,1M,+*+*+*+ }2 /03 4 5649":,9-<2,lt +*+`>+dl+d6+`+h`d6+'+6`7+'8+Y+6Y+33+Y+6Y+##}2 F GH+I;JGK[LbKkMNMCktg+Y+6+h`4++43+Y+t+hd$+Y+6+h`+$#}UV)WEXYY`XfTjtg+M+,,,h`Y66,1M>*+,%>,'`8,'7,,h`6``6,1M,}6 cd ef"g%h2i=jEkRl[m`gdpitl Y6Y6>+#:,3:r*&6`6`6``6`>":d6d>":4*+4: + " ,4 4+,$$"*,$:  " + $+,##}jz{|~4;BQ[cjmw~ft  `hhd6  5h6ld6gh6ld6Qt6J`dh6l`d6+``h6l`d6 `d6}j #)148>GJNQYbmpxht b`d6 6h6  l6Y": +Y`dd " }& (2D_mt+-+'7`7+-+'8`8+:d*+-7+-8,1:+-8'8`6/*+-7'7`,'8`61:ұ}6  &+?FX[sotH- (.+0*+,-)} ot(+!0+--7`--8-``--7-6`--8-``+--7-6``--8-``--7-6``--8`-*F+--7--8-l``-*-7-*6`-*-8-*l``-5 +/0 +0+--7--8-6-+---7-6,-2dl`--8-`- dld+0-*B+--7--8-l`-*-7-*6`-*-8-*l`-1 *+,-1)- *+,-)}   +9 <Ypsz  !$!+$2%H&Z'n%q+x,01 sct+ **+} Project2/WTFactory.html010066600431230000012000000040760652330043200156410ustar00novikstaff00000400000023 Class WTFactory

    Class WTFactory

    java.lang.Object
       |
       +----WTFactory
    

    public class WTFactory
    extends Object
    Encapsulates all operations performed on a WalTree. This is part of the WalTree package, created by Walter Korman to enable the visually appealing display of M-ary trees. More documentation is available at his web site; follow the link below to get to it.

    Documentation

    Author:
    Walter Korman

    Constructor Index

     o WTFactory()

    Method Index

     o setParentDistance(int)
    Allows setting of the distance between levels in the tree.

    Constructors

     o WTFactory
     public WTFactory()
    

    Methods

     o setParentDistance
     public void setParentDistance(int val)
    
    Allows setting of the distance between levels in the tree.

    Project2/WalTreeCanvas.class010066600431230000012000000044230652330042000166100ustar00novikstaff00000400000023-U^_`ijklmno & & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > QA QC QM QP cV db eD f@ gH hV pE s[ uJ vK wF yV zG |I }B ? L W Z V X()Ljava/awt/Dimension;()Ljava/awt/Font;()V(I)V(II)V(IIII)V (LWNode;)V (LWNode;II)V(Ljava/awt/Color;)V'(Ljava/awt/Font;)Ljava/awt/FontMetrics;(Ljava/awt/Font;)V(Ljava/awt/Graphics;)V3(Ljava/awt/Graphics;Ljava/awt/FontMetrics;LWNode;)V(Ljava/lang/String;)I(Ljava/lang/String;II)V1(Ljava/lang/String;ILWNode;LWNode;LWNode;)LWNode;0(Ljava/lang/String;LWNode;LWNode;LWNode;)LWNode;-(Ljava/lang/String;LWNode;LWNode;LWNode;III)VCode ConstantValue Exceptions HelveticaILWNode; LWTFactory;LineNumberTableLjava/awt/Color;Ljava/awt/FontMetrics;LocalVariables SourceFileWNode WTFactory WalTreeCanvasWalTreeCanvas.javaZdefault_borderdirtyfillRectgetFontgetFontMetricsheightjava/awt/Canvasjava/awt/Colorjava/awt/Componentjava/awt/Dimension java/awt/Fontjava/awt/FontMetricsjava/awt/GraphicslayoutmakeNodemakeNodeOfWidthmetrics minimumSizepaint paintFullTree plantTree preferredSizeroot_xsetColorsetDefaultBordersetFontsetParentDistance setRootOffsetsetTreesize stringWidthtwhitewidth wt_factory!cVs[XWdbyV QARx@* * Y ****Y %*"***Y& ,./ 1+20354:5?+x?R&YY9t?R$ Y((Y=qOR> Y+,-*+! `*YEFErNR5 Y+- *YN ONER+ *+"*YVW U{BR"*Y ^]}BR% *%Y ed~BR"*Y lkuJRh*+* M+#+,$,*"*+*%*"*%*"*,dl**%+**"Y:su xy{&|'/:MORWgr]aL W Z V X()Ljava/awt/Dimension;()Ljava/awt/Font;()V(I)V(II)V(IIII)V (LWNode;)V (LWNode;II)V(Ljava/awt/Color;)V'(Ljava/awt/Font;)Ljava/awt/FontMetrics;(Ljava/awt/Font;)V(Ljava/awt/Graphics;)VProject2/WalTreeCanvas.html010066600431230000012000000157500652330042300164570ustar00novikstaff00000400000023 Class WalTreeCanvas

    Class WalTreeCanvas

    java.lang.Object
       |
       +----java.awt.Component
               |
               +----java.awt.Canvas
                       |
                       +----WalTreeCanvas
    

    public class WalTreeCanvas
    extends Canvas
    Basic canvas for creating and displaying a WalTree. This is part of the WalTree package, created by Walter Korman to enable the visually appealing display of M-ary trees. More documentation is available at his web site; follow the link below to get to it.

    Documentation

    Author:
    Walter Korman

    Constructor Index

     o WalTreeCanvas()
    Constructs new WalTreeCanvas, an associated WTFactory, and inits state.

    Method Index

     o makeNode(String, WNode, WNode, WNode)
    Create a new node with the given attributes, calculating width to match the displayed node name text.
     o makeNodeOfWidth(String, int, WNode, WNode, WNode)
    Create a new node with the given attributes and the specified width.
     o minimumSize()
     o paint(Graphics)
    Draw the tree associated with this canvas.
     o preferredSize()
     o setDefaultBorder(int)
    Set the default border size for nodes
     o setParentDistance(int)
    Set the distance between parent nodes.
     o setRootOffset(int)
    Set the horizontal offset between edge of canvas and root node.
     o setTree(WNode)
    Set the tree to be displayed by this canvas.

    Constructors

     o WalTreeCanvas
     public WalTreeCanvas()
    
    Constructs new WalTreeCanvas, an associated WTFactory, and inits state.

    Methods

     o preferredSize
     public Dimension preferredSize()
    
    Overrides:
    preferredSize in class Component
     o minimumSize
     public Dimension minimumSize()
    
    Overrides:
    minimumSize in class Component
     o makeNode
     public WNode makeNode(String name,
                           WNode p,
                           WNode c,
                           WNode s)
    
    Create a new node with the given attributes, calculating width to match the displayed node name text.

     o makeNodeOfWidth
     public WNode makeNodeOfWidth(String name,
                                  int width,
                                  WNode p,
                                  WNode c,
                                  WNode s)
    
    Create a new node with the given attributes and the specified width.

     o setTree
     public void setTree(WNode t)
    
    Set the tree to be displayed by this canvas.

     o setDefaultBorder
     public void setDefaultBorder(int b)
    
    Set the default border size for nodes

     o setParentDistance
     public void setParentDistance(int val)
    
    Set the distance between parent nodes.

     o setRootOffset
     public void setRootOffset(int val)
    
    Set the horizontal offset between edge of canvas and root node.

     o paint
     public void paint(Graphics g)
    
    Draw the tree associated with this canvas.

    Overrides:
    paint in class Canvas
    Project2/images/004077700431230000012000000000000652330032200143305ustar00novikstaff00000400000023Project2/images/blue-ball-small.gif010066600431230000012000000003770652330027600200000ustar00novikstaff00000400000023GIF89a*!{GBlc{{14(!Zc ZJssJKJec!,@p0 a@B\NGX,%IHl;Project2/images/blue-ball.gif010066600431230000012000000016350652330027700166710ustar00novikstaff00000400000023GIF89a ·fffooo[VVV?{ddd[xpkZSWq*!1ovbQQKQ׵ѷq@6]A&)2 ^7{Bc{1̂!WZ^cƽZYJJssqsEJJckk1{BkJc{BRJB9{9Z1{RB)R9)1!cB)ZB1cƽ11Z!Js1s!JJcck!1J{GBlc{{/OOiii޳ڥ PE\\**R- /222n#^pqIoV<9^ao7ηמ}1=bɣϭ~}qgu߁v2[`E7Wsw#}$vngtzoqEu=k/:fJ!_#mahb1([f8_I" $OR19>E`9Hr}PcBgAe:Vii&"yΦ5RW&(B)ڧ ()~fV i,*h"ڣTM9!?Ry觖騸J묺fتKq&iרJ٢JXF쯦F*&IVjkТբK.N}K.Ȋ,+5{f$.jݦD)L0 qwܱ clеzlɑ$@Ң 4#$j8\P:@P;Project2/images/constructor-index.gif010066600431230000012000000032570652330030200205130ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\ȰÇ#^@ŋ3jȱcBC"Rɓ(SHʍ-]|Xr͛*[Ĩs'C)e(Q=L*ҧ4B]tTUj]zu+ג11׳-Y]CEKԭݟEk Xm8xܜk;gDž'Wa[.yM;KX0Rɞ<#㴯e-3e;Z4lͨc3:x` Vqk_ޭ79FWSC~NƟH~}=:^(zyןux2`E6m~59WrXXp7q b7^'u}*'|ȹxa^}0$H/N8ZE8fh}9פ Z7"&^9&58'!i!GN6|h[J݂}gIhڍ7w>'J jqf'} ɧ)kz:[Jdg>-ٗYfB*`Ҧ%~9&Fi, H%yȣD/IƤ+[+{n){~͢ pX_oK|qڥ$ zY鸪7~^nq<2?LpGmt;4뮛kgp4Erc}>M0*7=2L.hd0u&L`Dln,w[|SX_7B 8tte~^˝vؖ'+)k:Z/n6Nf36ʫ{CxyƻoIhOw7PkzWognwOއ/Mo觯~;Project2/images/constructors.gif010066600431230000012000000030350652330030300175640ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\ȰaAJHŋ3jxbD -B Iɓ =~Drʖ0cTrI+mI'Ϟ 1(Q>*]j浤L:J'ΫPjjբ_bHgMذ 4RAe*p*]| ۍl5Wզ1cq ly1[ƒK[h/6r叩A)4Zʇ5ߞYݘ.znÑ>7U/zrlԩ o~=%z\!gġÿ=4i~]s}'|9]ۥ߁'^_y-i_E(ngxwلu8^~XK$"h *6&brg^Yb-.~;ږsC淢dAƇctǝF!Z[cybn  k+0+lqbm6oJ2$nHYZ-+w1j3/%E!7`A7T#oNWm@![1WwuAdȨ`Sp tm;Project2/images/error-index.gif010066600431230000012000000026360652330030400172610ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\ȰC8(0"ŋ3jȱbD~ IɓGʗ0cl̛8MD2@!ٳŅ;z Ti͢H*l:)PRE:ҔTu ֪WB*Q,^:Vdΰh]M[OQ= xYK x Zi kīx㽖+ѠUBːugύm2FMYBgμ]-N;qiޢCN'#O^3qУGW;3r]ӕ>}tױ8ԟ/o).}ԗ%g~Rd}wm^DUw[z=Ba%_mHZu9x(au)b7h+HyIhc!'~}>rH_}%)p o^=:i8|?r9$nȖ4 fpfKk҉@m;V$YUn)l:2(hgf Ԣ!iv饃U(fv=zh}z꧴ >)f*g5멱wVA:,ف檩j+f|.*(v-Ƃ{ 듮kK*;RXXI+|ͧ\'L 7nG\n@;Project2/images/exception-index.gif010066600431230000012000000032530652330030600201240ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\ȰÇHHŋ3jȱG'6 @&S\ɲeĐFtq&͛8s|r͝$ QBŒyTiҔOJ̞Ty2e4ׯ'.j+ԋ][F:-Xmiڏiʽ ֹ ,kuF٪ ~̶Vőx0cc-Mw3笍Zֺs\¥M[y늣v릻Y̛rٴN rWǃ~ZЅ;luyN^{8{^$exSkr&.xȷ~V|9u^f3'aXfgqEwB1!C- VݧxX*wn^]+~(_2%}1c}K^yy8V9dx&s(e=iA e|Wʸ\rߙl8_)ҏZbmzv:^E^P o)zY#hUV)]sh5ꨩEiB'hjjݣx`nz}vkwO;론bVj(wʩ6j-kvfm+Eͻ.LʻW \#; dBkb5ko[>R@o_.0솫ivlqW/Wq3,.׌3<tC{(KmFl2C=cYll,ADoTvkx_M3ˈ% b-w}oFq]8e urʌwnsM6Y^xN+ݞNQ]o猲֮:a\pM@y|GOWkyK/Ouqq~/o;Project2/images/interface-index.gif010066600431230000012000000031600652330030700200640ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\ȰB8Hŋ3jȱcň =qɓ(SrRK-]B|Is̚ Yi%͒<*T`HEETI4iMI[.u*ӦTeb tkVSQz3,NdIyڴ+KZ(Ѡη>[[KVûs)8]:F u#9ѢﲽܙПSk~:ti=kFU,W쵮&ܶt밨m=<3MF[SktLÍml}1nW;n[vw~ dcuE%{-vu|ށ ݅ Vwۅ fo0܉ vW(BXqe|5޴!^t=֚.N睓9bEJ؄IGub>QBi_bā%(YމlV7\Y FјFvbIߤZj*"|x (I"**t]ShbʨiN䫥BG!V'zV&]F*hF&k.J5bQr"jY4F.i٣-Hzmޖo[p۞f(9Bݻ/c̒{lpw0#pqJzJ$r!,l23sC,0tX73u=LZaV5 ]4R<HMsVމҖ+|MijPmjm}'Fx|6?'|W.`wOc礗NAAהvn{;Project2/images/method-index.gif010066600431230000012000000030640652330031100174020ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H*\p #* ŋ/BQƆ?vRȑ(S:`Lq-*Oā-{r)'|@P?zLguAN_H cd=[RfvfU t}@ۭky߀tnሷ;Project2/images/methods.gif010066600431230000012000000025730652330031200164650ustar00novikstaff00000400000023GIF89a&3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,& H@*\p! >Hŋ'bƊ!rIҢG"KJ iʋ_fL0k!ity3"ϞY2gK@LsB*D ԞRg,)4֦DʼzhGlU_˶5hڻJMvܕ};ޠ;}+ο:> q2]g1d??=v0ѧ-ziw%̚vdiF=ѩmӻ=&Kwio{s£ָ<6ƫ unޗwݺh욑rWOzr?*sE#y,^d!qY@Rk\ ej首]ћĦGc]oIszJr3RarW:襘N*W^J$agmZ.XhܪJJYmi)*,GfE ,lZkUAf&;BfZKk@䞫Ү.Լ+[U@;Project2/images/package-index.gif010066600431230000012000000031070652330031400175160ustar00novikstaff00000400000023GIF89a%3f3333f333ff3fffff3f3f̙3f3333f3333333333f3333333f3f33ff3f3f3f3333f3333333f3̙333333f333ff3ffffff3f33f3ff3f3f3ffff3fffffffffff3fffffff3fff̙ffff3fffff3f̙3333f33̙3ff3ffff̙f3f̙3f̙̙3f̙3f3333f333ff3fffff̙̙3̙f̙̙̙3f̙3f3f3333f333ff3fffff3f3f̙3f (((555CCCPPP]]]kkkxxx!,% H*\#J!ŋ3jȱÇC$qB&Sʗ[(s͛$Kܙ̚<*&ї-}TѥH] uaҤKV5cӆ]^+ugX*j< VmBE J[V⽸gA'nm X`RpO5츱ffAd?]7Z4KWOâ\9hמ-羆ȼ[㮽lZw]{c̓WY]o8Ejv.xAU_=kڷ;7ᙗyմz޹wvYTTw[~:W`y_sZ%`'^@gm JXbzg]Mg~W!|(7݃!15$~#t)˜s4ߑX^y_ 6)bAQhN2٠o yA!r`J!Whsvc eIau7慁n .97x䁔~ii'5J\檫mz')J*UjīC:djmYlJaJ'uv9Ufmܢ{VK^ oJIXo޻ +1"0&{曱lFng&.'r5*f|0C\+R,Ķv$t=мj45Œiq*5Nt\K?:@AHŋ3jqÉ ?B#ɓ(S^$C* ŒIJg:SȞ,m cфGS&EsӗAF-ϚUjؔh׃Y;m9ψeŦEXk6|-ո[ڕ^} ռ|LzX1ae6r,OY?utv\HqE}j ).gJ:߶g'_wkܷ?[3搱MnqC~}]୛w;>޶eghI[cGwɗ'eVQG!sQ~YmݧI*'\W)|*n.B4YJhi:M硑Lr݈0c@Jh؏9Ġ{@)yיW'VyO#jWz%)Ecȧt9w#k%Rٟ&R(m]jlإg8)o)gbvdl:7rOj"݊+mZꚬ)uꤲz櫳MV+jK͒%.`k)y~-fznKyW!ij :!ۭ"+ Kpf 6qa./|+qU!s)^+2%׌Ѻ2)v~D#&1+mPG Z.RgH[-ju4aգNf3íV{jX[ɢ5ShY8ͮfTj=YRo׽9u5߂\'M<]^/qE)s<4hěK[Ǎ ǮKԩؚkBvlղo7YӘ1Ǭd>cSZ׍`B1 yf)SA$TTbe,XHٚeRS(bE)A* ;Project2/index.html010066600431230000012000000117360652336501500150770ustar00novikstaff00000400000023 Blind Search Demonstration

    Blind Search Algorithms

    Blind search, also called uninformed search, works with no information about the search space, other than to distinguish the goal state from all the others. The following applets demonstrate four different blind search strategies, using a small binary tree whose nodes contain words. Just enter a word in the text input field (your word doesn't have to be in the tree) and click on the "Start Search" button in order to begin the search. The nodes will change color to red as they are visited by the search.


    Breadth-First Search
    Breadth-first search goes through the tree level by level, visiting all of the nodes on the top level first, then all the nodes on the second level, and so on. This strategy has the benefit of being complete (if there's a solution, it will be found), and optimal as long as the shallowest solution is the best solution. However, the way breadth-first search achieves this is by keeping all of the leaf nodes in memory, which requires a prohibitive amount of memory when searching anything more than a very small tree. The time complexity of breadth-first search is O(b^d) where b is the branching factor (2 for the binary trees below) and d is the depth of the solution.
    Depth-First Search
    Depth-first search goes through the tree branch by branch, going all the way down to the leaf nodes at the bottom of the tree before trying the next branch over. This strategy requires much less memory than breadth-first search, since it only needs to store a single path from the root of the tree down to the leaf node. However, it is potentially incomplete, since it will keep going on down one branch until it finds a dead-end, and it is nonoptimal -- if there's a solution at the fourth level in the first branch tried, and a solution at the second level in the next one over, the solution at the fourth level will be returned. The time complexity of depth-first search is O(b^m) where b is the branching factor (2 for the binary trees below) and m is the maximum depth of the tree. Its space complexity is only b*m.

    Try searching for "a" and see which of the two solutions is found when using depth-first search.

    Depth-Limited Search
    Depth-limited search essentially does a depth-first search with a cutoff at a specified depth limit. When the search hits a node at that depth, it stops going down that branch and moves over to the next one. This avoids the potential problem with depth-first search of going down one branch indefinitely. However, depth-limited search is incomplete -- if there is a solution, but only at a level deeper than the limit, it will not be found. It is also nonoptimal in the same way as depth-first search is. The time complexity of depth-first search is O(b^l) where b is the branching factor (2 for the binary trees below) and l is the depth limit. Its space complexity is only b*l.

    The depth limit in this instance of the algorithm (set using the PARAM tag within the APPLET tag; view the source of the file to see) is 2. (The depth of the root node is 0.)

    Iterative Deepening Search
    Iterative deepening does repeated depth-limited searches, starting with a limit of zero and incrementing once each time. As a result, it has the space-saving benefits of depth-first search, but is also complete and optimal, since it will visit all the nodes on the same level first before continuing on to the next level in the next round when the depth is incremented. The time complexity of iterative deepening search is O(b^d) where b is the branching factor (2 for the binary trees below) and d is the depth of the solution. The space complexity is O(bd).

    SearchApplet was created by Naomi Novik Project2/packages.html010066600431230000012000000007320652330040100155240ustar00novikstaff00000400000023 Package Index
    API User's Guide  Class Hierarchy  Index

    Package Index

    Project2/source/004077700431230000012000000000000652330035000143645ustar00novikstaff00000400000023Project2/source/BreadthFirstSearchAlgorithm.java010066600431230000012000000011430652330033000225770ustar00novikstaff00000400000023/** * BreadthFirstSearchAlgorithm.java * * Expands on the generic SearchAlgorithm to search for a specified * string within a tree. */ /** * Extends SearchAlgorithm class to use Breadth-First method, searching * through all nodes on a particular level of the tree before going deeper. */ public class BreadthFirstSearchAlgorithm extends SearchAlgorithm { /** * This method will be called to enqueue a new node. * BreadthFirstSearch: enqueue new nodes at the end. */ protected void enqueue(WNode newNode) { this.nodeQueue.addElement(newNode); } } Project2/source/DepthFirstSearchAlgorithm.java010066600431230000012000000011030652330033100222670ustar00novikstaff00000400000023/** * DepthFirstSearchAlgorithm.java * * Expands on the generic SearchAlgorithm to search for a specified * string within a tree. */ /** * Extends SearchAlgorithm class to use Depth-First method, searching * the deepest nodes in the tree first. */ public class DepthFirstSearchAlgorithm extends SearchAlgorithm { /** * This method will be called to enqueue a new node. * DepthFirstSearch: enqueue new nodes at the front. */ protected void enqueue(WNode newNode) { this.nodeQueue.insertElementAt(newNode, 0); } } Project2/source/DepthLimitedSearchAlgorithm.java010066600431230000012000000024760652330033300226070ustar00novikstaff00000400000023/** * DepthLimitedSearchAlgorithm.java * * Expands on the generic SearchAlgorithm to search for a specified * string within a tree. */ import java.util.Vector; /** * Extends the DepthFirstSearchAlgorithm class to use the Depth-Limited * search algorithm, which performs depth-first search but stops at * a specified depth before going any further. */ public class DepthLimitedSearchAlgorithm extends DepthFirstSearchAlgorithm { /** * Override searchQueue (from the SearchAlgorithm class) to return * when a specific depth is reached. */ protected WNode searchQueue() throws Exception { Vector newNodes; WNode top; pause(); top = pop(); if (top == null) {return top;} top.visit(); if (searchString.equals(top.toString())) { return top; } else if (top.getNodeDepth() == depth) { // Keep searching without adding children to the queue. return searchQueue(); } else { // Keep searching; add the children of this node to the queue. newNodes = top.expand(); for (int i=0; i < newNodes.size(); i++) { enqueue((WNode) newNodes.elementAt(i)); } return searchQueue(); } } } Project2/source/IterativeDeepeningSearchAlgorithm.java010066600431230000012000000024370652330033400240040ustar00novikstaff00000400000023/** * IterativeDeepeningSearchAlgorithm * Expands on the generic SearchAlgorithm to search for a specified * string within a tree. */ import java.util.Vector; /** * Extends the DepthLimitedSearchAlgorithm class to use the Iterative Deepening * search algorithm, which performs depth-limited search repeatedly, increasing * the depth limit each time, until the tree is empty or the desired node is * found. */ public class IterativeDeepeningSearchAlgorithm extends DepthLimitedSearchAlgorithm { /** * Override search method from SearchAlgorithm class. */ public WNode search(WNode root, String searchString) throws Exception { WNode n = null; nodeQueue = new Vector(); if (searchString == null || searchString.equals("")) { throw new Exception("No search string specified."); } else if (root == null) { return n; } else { this.searchString = searchString; } // Increase the depth until we find the target or exceed the // maximum depth of the tree. int maxDepth = root.getTreeDepth(); for (int i=0; i <= maxDepth ; i++) { enqueue(root); setDepth(i); clearSearch(); n = searchQueue(); if (n != null) { return n; } } return n; } } Project2/source/Polygon.java010066600431230000012000000002600652330033500166540ustar00novikstaff00000400000023/** * Represents a polygon area for use in spacing/positioning calculations. */ class Polygon { PolyLine lower_head, lower_tail; PolyLine upper_head, upper_tail; }; Project2/source/PolyLine.java010066600431230000012000000003060652330033600167620ustar00novikstaff00000400000023/** * Used to build Polygons. */ class PolyLine { int dx, dy; PolyLine link; PolyLine(int dx, int dy, PolyLine link) { this.dx = dx; this.dy = dy; this.link = link; } }; Project2/source/SearchAlgorithm.java010066600431230000012000000070060652330034000203020ustar00novikstaff00000400000023/* * SearchAlgorithm.java */ import java.util.Vector; /** * A generic search algorithm, implementing the basic methods needed * for a search. The three main methods that need to be overridden in * order to make a specific search algorithm are search(), searchQueue(), * and enqueue(). *

    * @author Naomi Novik */ public class SearchAlgorithm { /** * The search applet. */ private SearchApplet caller; /** * When true stop searching. */ protected boolean stopRequested = false; /** * Vector containing the queue of nodes to search. */ protected Vector nodeQueue; /** * What to look for. */ protected String searchString; /** * Maximum depth in the tree to search until, used in depth-limited * and iterative-deepening search algorithms. */ protected int depth = 10; /** * Constructor. */ public SearchAlgorithm() { super(); } /** * Set the caller. */ public void setCaller(SearchApplet c) { caller = c; } /** * Set depth. */ public void setDepth(int d) { this.depth = d; caller.statusBar.setText("Depth limit set to: " + d); } /** * Clear the search. */ protected void clearSearch() { caller.clearSearch(); } /** * Stop searching. */ public void stop() { stopRequested = true; } /** * Initialize */ public void init() { stopRequested = false; } /** * Pop off the top value of nodeQueue. */ protected WNode pop() { WNode top = null; if (nodeQueue.size() <=0) {return top;} top = (WNode) this.nodeQueue.elementAt(0); // Top of the queue nodeQueue.removeElementAt(0); return top; } /** * Peek at the top value of nodeQueue. */ protected WNode peek() { WNode top = null; if (nodeQueue.size() <=0) {return top;} top = (WNode) this.nodeQueue.elementAt(0); return top; } /** * Pause for a while. */ protected void pause() throws Exception { if (stopRequested) { throw new Exception("Search Algorithm"); } caller.pause(); } /** * This method will be called to search through a tree. */ public WNode search(WNode root, String searchString) throws Exception { WNode n = null; nodeQueue = new Vector(); if (searchString == null || searchString.equals("")) { throw new Exception("No search string specified."); } else if (root == null) { return n; } else { this.searchString = searchString; enqueue(root); } n = searchQueue(); return n; } /** * Recursively called to search through the queue of nodes. * Return the node if searchString found. */ protected WNode searchQueue() throws Exception { Vector newNodes; WNode top; pause(); top = pop(); if (top == null) {return top;} top.visit(); if (searchString.equals(top.toString())) { return top; } else { /* Keep searching; add the children of this node to the queue. */ newNodes = top.expand(); for (int i=0; i < newNodes.size(); i++) { enqueue((WNode) newNodes.elementAt(i)); } return searchQueue(); } } /** * This method will be called to enqueue a new node. * Should be overridden by child classes. */ protected void enqueue(WNode newNode) { } } } /** * Pop off the top value of nodeQueue. */ protected WNode pop() { WNode top = null; if (nodeQueue.size() <=0) {return top;} top = (WNode) this.nodeQueue.elementAt(0); // Top of the queue nodeQueue.removeElementAt(0); return top; } /** * Peek at the top value of nodeQueue. */ protected WNode peek() { WNode top = null; if (nodeQueue.size() <=0) {return top;} top = (WNode) this.nodeQueue.elementAt(0); return tProject2/source/SearchApplet.java010066600431230000012000000234160652330034400176100ustar00novikstaff00000400000023/**************************************************************** * SearchApplet.java * * Applet that runs a search algorithm on a specified tree. */ import java.applet.Applet; import java.awt.*; import java.util.StringTokenizer; import java.util.Vector; /** * This applet runs a search algorithm on a tree, taking * user input to determine what to search for within the tree and * producing a visual representation of the search's progress through * the tree. * Uses some of the ideas demonstrated in the sort demo included * with Sun's JDK 1.1. * * To use this applet, you would add a tag like the following into your * HTML: *

     * <applet code="SearchApplet.class" width=400 height=350> 
     * <PARAM name=alg value="BreadthFirstSearch"> 
     * </applet>
     * 
    * * If you are using the Depth-Limited algorithm, which takes a depth * limit, you could also add another PARAM tag to specify that limit: *
     * <PARAM name=depth value="3">
     * 
    * * To-do list of improvements *
      *
    • Allow the user to enter a block of text to be used as the tree * instead of having it hardwired in. *
    • Along the lines of the first one, have a randomly-generated * "numeric" tree used. *
    • Allow the user to input the branching factor of the tree, or * perhaps just make this an optional parameter of the applet. *
    * * @author Naomi Novik */ public class SearchApplet extends Applet implements Runnable { /* Following are workarounds for font size calculations, as Netscape * reports unappealing font height/ascents on varying platforms. */ static final int FIXED_FONT_HEIGHT = 10; static final int FIXED_FONT_ASCENT = 3; static final String treeString = "This is a string used to build a tree of strings for the search algorithms to work on"; /** * Thread to run the search algorithm. */ Thread kicker; /** * @see WalTreeCanvas */ WalTreeCanvas treeCanvas; /** * @see WNode */ WNode root; /** * Store the nodes of the tree in order for easier insertion * of new nodes. */ Vector treeNodes; /** * Branching factor of the tree. */ int branchFactor; /** * @see SearchAlgorithm */ SearchAlgorithm algorithm; String algName; /* User input widgets */ Panel inputPanel; Button btn_clear; Button btn_start; TextField textToFind; String searchString; /* Status bar */ public TextField statusBar; // Some basic info about the applet. public String getAppletInfo() { return "SearchApplet v. 0.1.\nWritten by Naomi Novik."; } // Information about the supported parameters public String[][] getParameterInfo() {return info;} private String[][] info = { {"alg", "string", "name of search algorithm to use"}, {"depth", "integer", "maximum depth to search to in the tree"} }; /** * Initialize the applet. */ public void init () { String str; searchString = null; // initially branchFactor = 2; // default /* Get the algorithm to use from the PARAM tag in HTML. */ String algParam = getParameter("alg"); if (algParam == null) { algParam = "BreadthFirst"; } algName = algParam + "Algorithm"; /* Set up the tree display */ setLayout(new BorderLayout()); add("Center", treeCanvas = new WalTreeCanvas()); statusBar = new TextField(40); statusBar.setEditable(false); statusBar.setText("SearchApplet initializing..."); add("South",statusBar); /* Set distance between node and child. */ treeCanvas.setParentDistance(5); /* Add the user input widgets. */ inputPanel = new Panel(); inputPanel.add(new Label("Search String: ")); inputPanel.add(textToFind = new TextField(10)); inputPanel.add(btn_clear = new Button("Clear")); inputPanel.add(btn_start = new Button("Start Search")); add("North", inputPanel); /* Initialize the tree. */ root = null; buildTree(); // We want to construct a tree to search in. statusBar.setText("SearchApplet ready: " + algName); } /** * Handle events that occur in the applet as a result of user action. */ public boolean handleEvent(Event e) { if(e.id == Event.ACTION_EVENT && e.target == btn_clear) { clearSearch(); } else if (e.id == Event.ACTION_EVENT && e.target == btn_start) { // set the value of the searchString setSearchString(textToFind.getText()); // Throw an error or print a warning here if the searchString is // null. if (searchString == null) { statusBar.setText("No search string entered!"); } else { statusBar.setText("Starting search."); startSearch(); } } else { return false; } return true; } /** * Set the value of the searchString. */ void setSearchString(String s) { if (s == "") {return;} searchString = s; } /** * Stop the applet. Kill any algorithm that is still * searching. */ public synchronized void stop() { if (kicker != null) { try { kicker.stop(); } catch (IllegalThreadStateException e) { // ignore this exception } kicker = null; } if (algorithm != null){ try { algorithm.stop(); } catch (IllegalThreadStateException e) { // ignore this exception } } } /** * Start a search of the tree by starting off a new Thread. The * Thread will then call the run() procedure below. This shouldn't * get called if the searchString variable is null! * It needs to be synchronized with the stop() method because they * both manipulate the common kicker variable. */ private synchronized void startSearch() { if (kicker == null || !kicker.isAlive()) { repaint(); kicker = new Thread(this); kicker.start(); } } /** * Main event loop. This will be called by the Thread forked * off in startSearch. * We need to set the search algorithm to be used, using the * name specified in the applet's params. */ public void run () { Integer d; WNode n = null; try { if (algorithm == null) { algorithm = (SearchAlgorithm)Class.forName(algName).newInstance(); algorithm.setCaller(this); // Get the depth limit to search to from the PARAM tag in HTML. // If present and not null, call setDepth() procedure of // searchAlgorithm. String dstring = getParameter("depth"); if (dstring != null) { try { d = new Integer(getParameter("depth")); algorithm.setDepth(d.intValue()); } catch (NumberFormatException nfe) { // Ignore the error; it'll just use the default. } } } algorithm.init(); // Pass the tree and the string to find along to the search alg. n = algorithm.search(root, searchString); // Print out results treeCanvas.repaint(); if (n != null) { int nd = n.getNodeDepth(); statusBar.setText("Search string found at depth " + nd); } else { statusBar.setText("Search failed."); } //} catch (ArrayIndexOutOfBoundsException oob) { // n = null; // statusBar.setText("Search failed."); } catch(Exception e) { statusBar.setText("Error in search: " + e.toString()); } } /** * Pause a while, to make the search progress visually clearer. * @see SearchAlgorithm */ public void pause() { if (kicker != null) { treeCanvas.repaint(); } try { Thread.sleep(1000); } catch (InterruptedException e) { statusBar.setText("Exception caught in pause: " + e.toString()); } } /** * Construct a tree to search in, based on the treeString variable, * by tokenizing that variable and adding each token from the string * to the tree. We clear the tree first before building it. */ private void buildTree() { clearTree(); treeNodes = new Vector(); StringTokenizer treeTokenizer = new StringTokenizer(treeString); String tok; while (treeTokenizer.hasMoreElements()) { tok = treeTokenizer.nextToken(); addString(tok); } } /** * Clear the tree completely. */ public void clearTree() { root = null; treeCanvas.setTree(null); treeCanvas.repaint(); } /** * Add the specified string to the displayed tree. */ public void addString(String s) { if(s.equals("")) { return; } if(root == null) { root = treeCanvas.makeNode(s, null, null, null); treeNodes.addElement(root); } else { WNode n = treeCanvas.makeNode(s, null, null, null); insertNode(n); treeNodes.addElement(n); } treeCanvas.setTree(root); treeCanvas.repaint(); } /** * Insert the specified node into the tree at the next available * spot (depends on branchFactor). */ public void insertNode(WNode n) { WNode t; Vector allChildren; int childCount; for (int i = 0; i < treeNodes.size(); i++) { t = (WNode) treeNodes.elementAt(i); allChildren = t.expand(); childCount = allChildren.size(); if (childCount < branchFactor) { // n becomes child of t n.parent = t; n.sibling = t.child; t.child = n; return; } } } /** * Clear the search information while still preserving the tree. */ public void clearSearch() { clearSearch(root); treeCanvas.repaint(); statusBar.setText("SearchApplet ready: " + algName); } /** * Iterate through the tree, calling the 'leave()' member * function on each node to clear the visited information. * * @see WNode#leave */ private void clearSearch(WNode t) { WNode n; if (t==null) {return;} t.leave(); n = t.child; while (n != null) { clearSearch(n); n = n.sibling; } } }; gorithm algorithm; String algName; /* User input widgets */ Panel inputPanel; Button btn_clear; Button btn_start; TextField textToFind; String searchString; /* Status bar */ public TextField staProject2/source/WalTreeCanvas.java010066600431230000012000000062260652330034500177350ustar00novikstaff00000400000023/**************************************************************** * WalTreeCanvas.java * * Canvas used to display M-ary trees within an applet. */ import java.awt.*; /** * Basic canvas for creating and displaying a WalTree. * This is part of the WalTree package, created by Walter Korman to enable * the visually appealing display of M-ary trees. More documentation is * available at his web site; follow the link below to get to it. *

    * Documentation *

    * @author Walter Korman * */ public class WalTreeCanvas extends Canvas { int default_border; FontMetrics metrics; /** * @see WTFactory */ WTFactory wt_factory; /** * @see WNode */ WNode t; /** * Determines if we have anything to draw. */ boolean dirty; /** * X-coordinate position of the root of the tree. */ int root_x; /** * Constructs new WalTreeCanvas, an associated WTFactory, and inits state. */ public WalTreeCanvas() { super(); setFont(new Font("Helvetica", Font.PLAIN, WTFactory.FIXED_FONT_HEIGHT)); this.metrics = getFontMetrics(getFont()); wt_factory = new WTFactory(); t = null; default_border = 5; root_x = 5; dirty = false; } public Dimension preferredSize() { return new Dimension(1000, 1000); } public Dimension minimumSize() { return new Dimension(40, 40); } /** * Create a new node with the given attributes, calculating width * to match the displayed node name text. */ public WNode makeNode(String name, WNode p, WNode c, WNode s) { return new WNode(name, p, c, s, metrics.stringWidth(name) + 10, 2 * WTFactory.FIXED_FONT_HEIGHT, default_border); } /** * Create a new node with the given attributes and the specified width. */ public WNode makeNodeOfWidth(String name, int width, WNode p, WNode c, WNode s) { return new WNode(name, p, c, s, width, WTFactory.FIXED_FONT_HEIGHT, default_border); } /** * Set the tree to be displayed by this canvas. */ public void setTree(WNode t) { this.t = t; dirty = true; } /** * Set the default border size for nodes */ public void setDefaultBorder(int b) { default_border = b; } /** * Set the distance between parent nodes. */ public void setParentDistance(int val) { wt_factory.setParentDistance(val); } /** * Set the horizontal offset between edge of canvas and root node. */ public void setRootOffset(int val) { root_x = 5; } /** * Draw the tree associated with this canvas. */ public void paint(Graphics g) { super.paint(g); Dimension d = size(); /* Wipe background */ g.setColor(Color.white); g.fillRect(0, 0, d.width, d.height); if(t == null) { return; } if(dirty == true) { /* Calculate node offsets */ wt_factory.layout(t); /* Calculate absolute node positions */ wt_factory.plantTree(t, root_x, (d.height - 2 * WTFactory.FIXED_FONT_HEIGHT) / 2); dirty = false; } /* Paint the beastie */ wt_factory.paintFullTree(g, metrics, t); } }; Project2/source/WNode.java010066600431230000012000000056240652330034700162550ustar00novikstaff00000400000023/**************************************************************** * WNode.java * * Code to represent a node in an M-ary tree. */ import java.awt.Point; import java.util.Vector; /** * Represents a node (or tree) in the WalTree. * This is part of the WalTree package, created by Walter Korman to enable * the visually appealing display of M-ary trees. More documentation is * available at his web site; follow the link below to get to it. *

    * Documentation *

    * Added by Naomi Novik:
    * The boolean field "visited" and the "visit" and "leave" methods were added * for use in displaying a search as it progresses through a tree. The * methods expand(), getNodeDepth(), and getTreeDepth() were added to help * with searching functions, * so that calling classes don't need to know what the member fields of the WNode * are. The toString() method was added for the same reason. *

    * @author Walter Korman * @author Naomi Novik */ public class WNode { String label; WNode parent, child, sibling; int width, height, border; boolean visited; Point pos, offset; Polygon contour; public WNode(String l, WNode p, WNode c, WNode s, int w, int h, int b) { label = l; parent = p; child = c; sibling = s; width = w; height = h; border = b; visited = false; pos = new Point(0, 0); offset = new Point(0, 0); contour = new Polygon(); } /** * Return the label of the node. */ public String toString() { return label; } /** * Change the visited status of the node to true. */ public void visit() { visited = true; } /** * Change the visited status of the node to false. */ public void leave() { visited = false; } /** * Expand a node, returning a Vector containing its * children. */ public Vector expand() { Vector allChildren = new Vector(); WNode currentChild; currentChild = this.child; while (currentChild != null) { allChildren.addElement(currentChild); currentChild = currentChild.sibling; } return allChildren; } /** * Determine depth of node within the tree. * The number of parents the node has represents its depth, * assuming the root has depth 0. */ public int getNodeDepth() { WNode p; int depth = 0; p = this.parent; while (p != null) { depth++; p = p.parent; } return depth; } /** * Determine maximum depth of tree rooted at this node. * Assuming an even distribution, this is until there * are no more children in a straight line from the root. */ public int getTreeDepth() { WNode p; int depth = 0; p = this; while (p != null) { depth++; p = p.child; } return depth; } }; Project2/source/WTFactory.java010066600431230000012000000157320652330035200171200ustar00novikstaff00000400000023/** * WTFactory.java * * Code for drawing and generating a WalTree. * * A direct port from Sven Moen's "Drawing Dynamic Trees" article in * IEEE Software, July 1990. Thanks to Allan Brighton for commenting the * Brighton Tree Widget source code with the aforementioned reference. */ import java.awt.*; /** * Encapsulates all operations performed on a WalTree. * This is part of the WalTree package, created by Walter Korman to enable * the visually appealing display of M-ary trees. More documentation is * available at his web site; follow the link below to get to it. *

    * Documentation *

    * @author Walter Korman */ public class WTFactory { /* Following are workarounds for font size calculations, as Netscape * reports unappealing font height/ascents on varying platforms. */ static final int FIXED_FONT_HEIGHT = 10; static final int FIXED_FONT_ASCENT = 3; /** * Distance between levels in the tree. */ int parent_dist = 30; /** * Allows setting of the distance between levels in the tree. */ public void setParentDistance(int val) { parent_dist = val; } /** * Lays out the tree node spacing in typical tidy fashion. */ void layout(WNode t) { WNode c; if(t == null) { return; } c = t.child; while(c != null) { layout(c); c = c.sibling; } if(t.child != null) { attachParent(t, join(t)); } else { layoutLeaf(t); } } /** * Attaches the specified node to its children, setting offsets. */ void attachParent(WNode t, int h) { int x, y1, y2; x = t.border + parent_dist; y2 = (h - t.height) / 2 - t.border; y1 = y2 + t.height + 2 * t.border - h; t.child.offset.x = x + t.width; t.child.offset.y = y1; t.contour.upper_head = new PolyLine(t.width, 0, new PolyLine(x, y1, t.contour.upper_head)); t.contour.lower_head = new PolyLine(t.width, 0, new PolyLine(x, y2, t.contour.lower_head)); } /** * Arranges contour for leaf node appropriately. */ void layoutLeaf(WNode t) { t.contour.upper_tail = new PolyLine(t.width + 2 * t.border, 0, null); t.contour.upper_head = t.contour.upper_tail; t.contour.lower_tail = new PolyLine(0, -t.height - 2 * t.border, null); t.contour.lower_head = new PolyLine(t.width + 2 * t.border, 0, t.contour.lower_tail); } /** * Joins children/siblings together, merging contours. */ int join(WNode t) { WNode c; int d, h, sum; c = t.child; t.contour = c.contour; sum = h = c.height + 2 * c.border; c = c.sibling; while(c != null) { d = merge(t.contour, c.contour); c.offset.y = d + h; c.offset.x = 0; h = c.height + 2 * c.border; sum += d + h; c = c.sibling; } return sum; } /** * Merges two polygons together. Returns total height of final polygon. */ int merge(Polygon c1, Polygon c2) { int x, y, total, d; PolyLine lower, upper, b; x = y = total = 0; upper = c1.lower_head; lower = c2.upper_head; while(lower != null && upper != null) { /* compute offset total */ d = offset(x, y, lower.dx, lower.dy, upper.dx, upper.dy); y += d; total += d; if(x + lower.dx <= upper.dx) { y += lower.dy; x += lower.dx; lower = lower.link; } else { y -= upper.dy; x -= upper.dx; upper = upper.link; } } /* store result in c1 */ if(lower != null) { b = bridge(c1.upper_tail, 0, 0, lower, x, y); c1.upper_tail = (b.link != null) ? c2.upper_tail : b; c1.lower_tail = c2.lower_tail; } else { /* (upper) */ b = bridge(c2.lower_tail, x, y, upper, 0, 0); if(b.link == null) { c1.lower_tail = b; } } c1.lower_head = c2.lower_head; return total; } /** * Calculates the offset for specified points. */ int offset(int p1, int p2, int a1, int a2, int b1, int b2) { int d, s, t; if(b1 <= p1 || p1 + a1 <= 0) { return 0; } t = b1 * a2 - a1 * b2; if(t > 0) { if(p1 < 0) { s = p1 * a2; d = s / a1 - p2; } else if(p1 > 0) { s = p1 * b2; d = s / b1 - p2; } else { d = -p2; } } else if(b1 < p1 + a1) { s = (b1 - p1) * a2; d = b2 - (p2 + s / a1); } else if(b1 > p1 + a1) { s = (a1 + p1) * b2; d = s / b1 - (p2 + a2); } else { d = b2 - (p2 + a2); } if(d > 0) { return d; } else { return 0; } } /** * Create a PolyLine bridge between links. */ PolyLine bridge(PolyLine line1, int x1, int y1, PolyLine line2, int x2, int y2) { int dy, dx, s; PolyLine r; dx = x2 + line2.dx - x1; if(line2.dx == 0) { dy = line2.dy; } else { s = dx * line2.dy; dy = s / line2.dx; } r = new PolyLine(dx, dy, line2.link); line1.link = new PolyLine(0, y2 + line2.dy - dy - y1, r); return r; } /** * Set the position of the nodes of the tree. */ void plantTree(WNode t, int off_x, int off_y) { WNode c, s; int cur_y; t.pos.x = off_x + t.offset.x; t.pos.y = off_y + t.offset.y; /* Plant child node */ c = t.child; if(c != null) { plantTree(c, t.pos.x, t.pos.y); /* Plant sibling nodes */ s = c.sibling; cur_y = t.pos.y + c.offset.y; while(s != null) { plantTree(s, t.pos.x + c.offset.x, cur_y); cur_y += s.offset.y; s = s.sibling; } } } /** * Draw the M-ary tree on screen. */ void paintFullTree(Graphics g, FontMetrics metrics, WNode t) { if(t == null) { System.out.println("paintFullTree::null tree."); return; } g.setColor(Color.black); paintTree(g, metrics, t); } /** * Recursively called to draw nodes of the M-ary tree. * Modified by Naomi Novik to draw the node in a different color * depending on the status of the WNode member variable "visited", */ void paintTree(Graphics g, FontMetrics metrics, WNode t) { /* Draw highlights */ g.setColor(Color.lightGray); g.drawLine(t.pos.x + 2, t.pos.y + t.height + 1, t.pos.x + t.width, t.pos.y + t.height + 1); g.drawLine(t.pos.x + t.width + 1, t.pos.y + t.height + 1, t.pos.x + t.width + 1, t.pos.y + 2); if(t.parent != null) { g.drawLine(t.pos.x, t.pos.y + t.height / 2 + 1, t.parent.pos.x + t.parent.width, t.parent.pos.y + t.parent.height / 2 + 1); } /* Draw this node */ if (t.visited) { g.setColor(Color.red); } else { g.setColor(Color.black); } g.drawRect(t.pos.x, t.pos.y, t.width, t.height); g.drawString(t.label, t.pos.x + (t.width - metrics.stringWidth(t.label)) / 2, t.pos.y + t.height - (t.height - FIXED_FONT_HEIGHT) / 2); g.setColor(Color.black); /* Draw line to parent */ if(t.parent != null) { g.drawLine(t.pos.x, t.pos.y + t.height / 2, t.parent.pos.x + t.parent.width, t.parent.pos.y + t.parent.height / 2); } /* Draw siblings, using the main child's x-offset. */ if(t.sibling != null) { paintTree(g, metrics, t.sibling); } /* Draw children */ if(t.child != null) { paintTree(g, metrics, t.child); } } }; Project2/tree.html010066600431230000012000000032210652330041700147100ustar00novikstaff00000400000023 Class Hierarchy

    All Packages  Index

    Class Hierarchy