home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Pascal / BFTGPH.ZIP / BFT.DOC next >
Encoding:
Text File  |  1991-09-09  |  11.2 KB  |  358 lines

  1. External Documentation BFT
  2.  
  3. I.   Problem Specifications
  4.  
  5.      A. Input specifications
  6.         
  7.         1. The input will consist of the following graphs:
  8.  
  9.            a. Graph 1
  10.  
  11.                       A - 1 - B - 2 - C - 3 - D
  12.                        \     / \     / \     /
  13.                         4   7   4   1   5   4
  14.                          \ /     \ /     \ /
  15.                           E - 2 - F - 3 - G
  16.                            \     / \     /
  17.                             3   3   1   5
  18.                              \ /     \ /
  19.                               H - 5 - I
  20.                                \     /
  21.                                 2   6
  22.                                  \ /
  23.                                   J 
  24.  
  25.            b. Graph 2
  26.  
  27.                        A - 1 - B       C
  28.  
  29.         2. The procedures NewVertex and WtdJoin will be
  30.            used to enter the structure into memory.  The
  31.            syntax is a follows:
  32.  
  33.                  NewVertex( GraphName , VertexName )
  34.                  WtdJoin( Vertex1 , Vertex2 )
  35.  
  36.            Where Graphname is the graph, Vertexname is     
  37.            the name of the new vertex, vertex1 is the      
  38.            emanating vertex, and vertex2 is the            
  39.            terminating vertex.
  40.  
  41.      B. Processing Requirments and Goal Summary
  42.        
  43.         1. Using the graph data supplied, the program is to
  44.            process it into a corresponding spanning tree as
  45.            well as an adjacency matrix.
  46.  
  47.      C. Ouptut Specifications
  48.          
  49.         1. The output will be formated to be clear and     
  50.             understandable.  A spanning tree will be
  51.             displayed as follows on the left side of the
  52.             screen:
  53.  
  54.                   BFT Spanning Tree
  55.                   ─────────────────
  56.                         Level
  57.                   0 1 2 3 4 5 6 7 8
  58.                   ─────────────────
  59.                   C
  60.                     A
  61.                       B
  62.                       D
  63.                         E
  64.                       F
  65.                     H
  66.                     I 
  67.                      J
  68.    
  69.            Where C would be the root of the following tree
  70.                           
  71.                             _C
  72.                            / │ \
  73.                          /   │   \
  74.                         A    H    I
  75.                       / │ \       │
  76.                      B  D  F      J
  77.                         │
  78.                         E
  79.  
  80.            The adjacency matrix will be displayed in       
  81.            standard form with 1's representing an arc
  82.            0's representing no arc.  It will be on the     
  83.            right hand side of the screen.
  84.  
  85.  
  86. II.  Algorithms and Data Structures
  87.  
  88.      A. The solution to this problem broken into 4 parts.
  89.         
  90.         1. The Graph unit
  91.         2. The Tree unit
  92.         3. The Queue unit
  93.         4. The Main program
  94.  
  95.      B. High-level Psuedocode
  96.  
  97.            1. The Graph unit
  98.  
  99.                 a. NewGraph
  100.                       point graph to nil
  101.  
  102.                 b. NewVrtx
  103.                       make new vertex
  104.                       add to end of vertexlist
  105.  
  106.                 c. FirstSuccessor
  107.                       find first vertex
  108.                       does it exist?
  109.                          yes return successor
  110.                          no return null
  111.  
  112.                 d. NextSuccessor
  113.                       Find first vertex
  114.                       find second vertex
  115.                          does it exist?
  116.                             yes does it have successor?
  117.                                yes return successor
  118.                                no return nil
  119.                             no return nil
  120.  
  121.                 e. Adjacent
  122.                       do vertices exist?
  123.                          yes see if arc exists
  124.                              yes return true
  125.                              no return false
  126.                          no return fasle
  127.  
  128.                 f. ArcWeight
  129.                       are they adjacent?
  130.                          yes find arc
  131.                              display weight
  132.                          no weight = 0
  133.  
  134.                 g. WtdJoin
  135.                       are they adjacent?
  136.                          yes end procedure
  137.                          no do vertices exist
  138.                             yes join vertices
  139.                                 add arc to lists
  140.                                 set weight
  141.  
  142.                 h. RemoveArc
  143.                       are they adjacent?
  144.                          yes remove the arc node from vertice lists
  145.                          no do nothing
  146.  
  147.                 i. PrintGraph
  148.                       does graph exist?
  149.                          yes print colum names
  150.                              while vertices left
  151.                                 print row vertice name
  152.                                 compare row with each column
  153.                                 print result
  154.  
  155.                 j. PrintArc
  156.                       are they adjacent?
  157.                          yes print vertex names and arc weight
  158.  
  159.           2. The Tree unit
  160.  
  161.                 a. NewTree
  162.                      make new tree node
  163.                      point root at it
  164.  
  165.                 b. Root
  166.                      return root of tree
  167.  
  168.                 c. AddTreeNode
  169.                      does node exist?
  170.                         yes make new treenode
  171.                             add to old node
  172.  
  173.                 d. DeleteTreeNode
  174.                      Does node exist?
  175.                         yes is it a leaf?
  176.                             no remove node from list
  177.  
  178.                 e. Parent, FirstChild, Nextbrother
  179.                      does node exist?
  180.                         yes does it have (p,f, or n)
  181.                             yes return node
  182.                 f. PrintTree
  183.                      Does tree exist?
  184.                         yes while not done
  185.                               write tree node name
  186.                               PrintTree brother
  187.                               PrintTree son
  188.  
  189.           3. The Queue unit
  190.  
  191.                 a. NewQueue
  192.                      Set tail to 0
  193.                      set head to 0
  194.                      set length to 0
  195.  
  196.                 b. EnQueue
  197.                      is queue full?
  198.                        no add data to end
  199.                        yes overflow
  200.  
  201.                 c. DelQueue
  202.                      is queue empty?
  203.                         yes underflow
  204.                         no remove data from front
  205.  
  206.                 d. Empty
  207.                      is length = 0?
  208.                         yes true
  209.                         no false
  210.  
  211.           3. The Queue unit
  212.  
  213.                 a. Visit
  214.                      Add vertex to tree
  215.                      set visited to true
  216.                      put tree on queue
  217.  
  218.                 b. SelectFatherNode
  219.                      is node^.son nil
  220.                         yes node = parent
  221.                             is node^.brother nil
  222.                                yes node = son
  223.  
  224.                 c. SelectGraphNode
  225.                      while not nil do
  226.                         has vertex been visited?
  227.                            no return node
  228.                            yes goto next vertex and continue
  229.  
  230.                 d. GetVertex
  231.                      search list for vertex of that name
  232.                         found return node
  233.                         not found return nil
  234.  
  235.                 e. BFT
  236.                     intialize q and tree
  237.                     visit first node
  238.                     while q not empty do
  239.                        remove name from queue
  240.                        visit node
  241.  
  242.                 f. Main
  243.                      enter all vertices
  244.                      enter all arcs
  245.                      do bft graph1
  246.                      print adj matrix graph1
  247.                      do bft graph2
  248.                      print adj matrix graph2
  249.                      end
  250.  
  251.  
  252.      C. The graph will be stored in a multilist linked     
  253.         configuration. Each vertex contains the           
  254.         following information:
  255.  
  256.                 Name - the name of the vertex
  257.                 Emanate - pointer to list of emanating arcs
  258.                 Terminate - pointer to terminating arc
  259.                 Next - pointer to next vertex in list
  260.                 Visited - boolean to determine if vertex   
  261.                        has been visited for BFT
  262.  
  263.         Each ArcNode will consist of the following:
  264.                  
  265.                 Weight - the weight of the arc
  266.                 Vertex1 - Name of the emanating vertex
  267.                 Vertex2 - name of the terminating vertex
  268.                 Emanate - pointer to next emanating arc
  269.                 Terminate - pointer to next terminating arc
  270.  
  271.         The spanning tree produced by the BFT algoritm     
  272.         will be stored as an ordered tree using linked     
  273.         lists.  Each Tree node will be structured as       
  274.         follows:
  275.  
  276.                 Data - the data to stored at that node
  277.                 Parent - pointer to parent node
  278.                 Brother - pointer to next brother of node
  279.                 Son - pointer to first son of node
  280.                 
  281.         The BFT algorithm requires the use of a queue.  The
  282.         queue was implemented as a circular list in        
  283.         contiguous storage:
  284.         
  285.                 Data - array of datatype to store data
  286.                 head - location of head in data array
  287.                 tail - location of tail in data array
  288.                 length - length of thee queue
  289.  
  290. III.   Status Reporting
  291.  
  292.        A. Each unit was tested with a file. The listing are
  293.           included with the unit listings.
  294.  
  295.        B. Error analysis - errors could exist if the       
  296.           followings condtions are met for each procedure
  297.  
  298.           1. NewQueue, NewTree, NewGraph, NewVrtx
  299.                no error conditions
  300.  
  301.           2. First Successor
  302.                vertex DNE
  303.                No 1st successor
  304.  
  305.           3. NextSuccessor
  306.                1st vert DNE
  307.                2nd vert DNE
  308.                No next successor
  309.  
  310.           4. Adjacent
  311.                V1 or V2 DNE
  312.  
  313.           5. ArcWeight, RemoveArc, PrintArc
  314.                V1 or V2 DNE
  315.                Arc DNE
  316.  
  317.           6. WtdJoin
  318.                V1 or V2 DNE
  319.                Arc already exists
  320.  
  321.           7. PrintGraph
  322.                Graph DNE
  323.  
  324.           8. AddTreeNode
  325.                Node DNE
  326.  
  327.           9. DeleteTreeNode
  328.                Node DNE
  329.                Node is not leaf
  330.  
  331.          10. Parent, FirstChild, NextSibling
  332.                Node DNE
  333.                Respective node DNE
  334.  
  335.          11. PrintTree, Root 
  336.                Tree DNE
  337.  
  338.          12. EnQueue
  339.                 Q is full
  340.                 Q DNE
  341.  
  342.          13. DeQueue
  343.                 Q is empty
  344.                 Q DNE
  345.  
  346.          14. Empty
  347.                 Q DNE
  348.  
  349.        C. The program could be improved in the following
  350.            ways:
  351.   
  352.           1. New algoritm to print tree in standard tree form
  353.  
  354.           2. Algorithm to print graph in readble form
  355.  
  356.           3. use different faster routines where performance
  357.              is poor
  358.