Project 7: Graph Search & Survey

Basic graph tools for representation, search, survey, and analysis

Revision dated 04/10/17 [Hint added]

Educational Objectives: After completing this assignment, the student should be able to accomplish the following:

  • Show both an adjacency matrix and an adjancency list representation of a graph from a graphical illustration.
  • Show both an adjacency matrix and an adjancency list representation of a graph from a graph data file.
  • Implement classes representing both undirected and directed graphs using an adjacency list.
  • Calculate survey data for a graph by hand, in 4 settings: BFS/DFS and Directed/Undirected cases.
  • Define and implement graph survey classes for both breadth-first and depth-first search.
  • ==============================================================
    rubric to be used in assessment
    --------------------------------------------------------------
    graph.h                 (16 total points)
     build fgraph.x w student makefile               [0..2]:    x
     build fgraph.x w assess makefile                [0..2]:    x
     fgraph.x graph1                                 [0..4]:    x
     fgraph.x graph2                                 [0..4]:    x
     fgraph.x graph3                                 [0..4]:    x
    bfsurvey.h and dfsurvey (25 total points)                
     build 4 test executables w student makefile     [0..2]:    x
     build 4 test executables w assess makefile      [0..3]:    x
     fbfs_ug.x graph4                                [0..5]:    x
     fbfs_dg.x graph5                                [0..5]:    x
     fdfs_ug.x graph6                                [0..5]:    x
     fdfs_dg.x graph7                                [0..5]:    x
    log.txt solutions       (9 total points)
     Exercise 11                                     [0..3]:    x
     Exercise 12                                     [0..3]:    x
     Exercise 13                                     [0..3]:    x
    points subtracted:      (subjective)
     log.txt testing diary                         [-10..0]:  ( x)
     requirements and SE                           [-10..0]:  ( x)
    dated submissions deduction                [2 pts each]:  ( x)
                                                               --
    total:                                          [0..50]:   xx
    ==============================================================
    

Background Knowledge Required: Be sure that you have mastered the material in this notes chapter before beginning the assignment:
Introduction to Graphs

Operational Objectives: Define and implement fsu::ALUGraph<N>, fsu::ALDGraph<N>, fsu::BFSurvey<G>, and fsu::DFSurvey<G> as class templates.

Deliverables:

graph.h         # fsu::ALUGraph<N> and fsu::ALDGraph<N>
bfsurvey.h      # fsu::BFSurvey<G>
dfsurvey.h      # fsu::DFSurvey<G>
makefile        # builds fgraph.x, agraph.x, rangraph.x, fbfs_ug.x, fbfs_dg.x, fdfs_ug.x, fdfs_dg.x
log.txt         # your project work log

Procedural Requirements

  1. The official development/testing/assessment environment is specified in the Course Organizer.

  2. Create and work within a separate subdirectory cop4530/proj7.

  3. Begin by copying the entire directory LIB/proj7 into your proj7 directory. At this point you should see these files in your directory:

    fgraph.cpp       # basic graph functionality test
    fbfsurvey.cpp    # BFS functionality test
    fdfsurvey.cpp    # DFS functionality test
    check_survey.sh  # unix script to check all 4 survey tests against area51 versions
    deliverables.sh  # assignment-specific configuration file
    

    Then copy these relevant executables:

    LIB/area51/fgraph_i.x
    LIB/area51/fbfs_ug_i.x
    LIB/area51/fbfs_dg_i.x
    LIB/area51/fdfs_ug_i.x
    LIB/area51/fdfs_dg_i.x
    

  4. Work Exercises 1-17 in the Intro to Graphs notes. Non-code exercises should be answered or documented in your log.txt. Code should be in the specified deliverable files.

  5. Test your code thoroughly, and be sure to document your testing in the log.txt file. There should be a brief narrative describing your test plan, and then documentation of the results of carrying out that plan.

  6. Submit the assignment using the script LIB/scripts/submit.sh. Be sure you have a copy of LIB/proj7/deliverables.sh in your directory.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit assignments. If you do not receive the second confirmation with the contents of your assignment, there has been a malfunction.

Code Requirements and Specifications

  1. Be sure to put all the graph and survey templates in the fsu namespace and protect against multiple reads.

  2. The API for undirected graphs ALUGraph<N> should be:

    
    typedef N                                      Vertex;
    typedef typename fsu::List<Vertex>             SetType;
    typedef typename SetType::ConstIterator        AdjIterator;
    
    void   SetVrtxSize  (N n);
    size_t VrtxSize     () const;
    void   AddEdge      (Vertex from, Vertex to);
    bool   HasEdge      (Vertex from, Vertex to) const;
    size_t EdgeSize     () const;
    size_t OutDegree    (Vertex v) const;
    size_t InDegree     (Vertex v) const;
    
    AdjIterator Begin   (Vertex v) const;
    AdjIterator End     (Vertex v) const;
    
    void Clear          ();
    void Dump           (std::ostream& os);
        
    ALUGraph            ();
    explicit ALUGraph   (N n);
    

    in order to accomodate existing client code. Type this code, do not copy/paste.

  3. The directed graph class ALDGraph<N> should be derived from the undirected case ALUGraph<N> with no new data or private members and an API that is expanded to include the new method Reverse(). Only the following require re-defining in the derived class:

    
    typedef N                                          Vertex;
    typedef typename ALUGraph<N>::SetType              SetType;
    typedef typename ALUGraph<N>::AdjIterator          AdjIterator;
    
    void   AddEdge      (Vertex from, Vertex to);
    size_t EdgeSize     () const;          // Theta (|V| + |E|)
    size_t InDegree     (Vertex v) const;  // Theta (|V| + |E|)
    void   Reverse      (ALDGraph& d) const;
    
    ALDGraph ( );
    explicit ALDGraph ( N n );
    

    in order to accomodate existing client code. Type this code, do not copy/paste.

  4. The API for BFSurvey<G> should be:

    
    typedef G                           Graph;
    typedef typename Graph::Vertex      Vertex;
    typedef typename Graph::AdjIterator AdjIterator;
    
    BFSurvey    ( const Graph& g );
    BFSurvey    ( const Graph& g , Vertex start );
    void Search ( );
    void Search ( Vertex v );
    void Reset  ( );
    void Reset  ( Vertex start );
    
    const fsu::Vector<Vertex>&   Distance () const { return distance_; }
    const fsu::Vector<Vertex>&   DTime    () const { return dtime_; }
    const fsu::Vector<Vertex>&   Parent   () const { return parent_; }
    const fsu::Vector<char>&     Color    () const { return color_; }
    
    size_t VrtxSize () const  { return g_.VrtxSize(); }
    size_t EdgeSize () const  { return g_.EdgeSize(); }
    
    size_t InfiniteTime     () const { return forever_; }
    size_t InfiniteDistance () const { return infinity_; }
    Vertex NullVertex       () const { return null_; }
    

    in order to accomodate existing client code. Type this code, do not copy/paste.

  5. The following development enhancements should be added to BFSurvey<G>:

    
    ...
    public: // trace support
      bool traceQue;
      void ShowQueSetup (std::ostream& os) const;
      void ShowQue      (std::ostream& os) const;
    };
    
    template < class G >
    void BFSurvey<G>::ShowQueSetup (std::ostream& os) const
    {
      os << "\n  conQueue\n"
         << "  <-------\n";
    }
    
    template < class G >
    void BFSurvey<G>::ShowQue (std::ostream& os) const
    {
      os << "  ";
      if (conQ_.Empty())
        os << "NULL";
      else
        conQ_.Display(os, ' ');
      os << '\n';
    }
    

    It is OK to copy/paste this add-on from the assignment document.

  6. The API for DFSurvey<G> should be:

    
    typedef G                           Graph;
    typedef typename Graph::Vertex      Vertex;
    typedef typename Graph::AdjIterator AdjIterator;
    
    DFSurvey    ( const Graph& g );
    DFSurvey    ( const Graph& g , Vertex start );
    void Search ( );
    void Search ( Vertex v );
    void Reset  ( );
    void Reset  ( Vertex start );
    
    const fsu::Vector<Vertex>&   DTime    () const { return dtime_; }
    const fsu::Vector<Vertex>&   FTime    () const { return ftime_; }
    const fsu::Vector<Vertex>&   Parent   () const { return parent_; }
    const fsu::Vector<char>&     Color    () const { return color_; }
    
    size_t VrtxSize () const  { return g_.VrtxSize(); }
    size_t EdgeSize () const  { return g_.EdgeSize(); }
    
    size_t InfiniteTime     () const { return forever_; }
    Vertex NullVertex       () const { return null_; }
    

    in order to accomodate existing client code. Type this code, do not copy/paste.

  7. The following development enhancements should be added to DFSurvey<G>:

    
    ...
    public:
      bool traceQue;
      void ShowQueSetup (std::ostream& os) const;
      void ShowQue      (std::ostream& os) const;
    };
    
    template < class G >
    void DFSurvey<G>::ShowQueSetup (std::ostream& os) const
    {
      os << "\n  conStack\n"
         << "  ------->\n";
    }
    
    template < class G >
    void DFSurvey<G>::ShowQue (std::ostream& os) const
    {
      os << "  ";
      if (conQ_.Empty())
        os << "NULL";
      else
        conQ_.Display(os, ' ');
      os << '\n';
    }
    

    It is OK to copy/paste this add-on from the assignment document.

  8. To implement the developer's data assistance, add this line immediately after "Reset();" in the implementation of Search():

    
    if (traceQue) { ShowQueSetup(std::cout);  ShowQue(std::cout); }
    

    and add this line immediately after each push/pop operation in the implementation of Search(v):

    
    if (traceQue) { ShowQue(std::cout); }
    

    These extra few lines of code will allow you to see the state of the control queue/stack at each stage of a survey. Plus they are expected as part of the test harnesses fbfsurvey.cpp and fdfsurvey.cpp.

Hints

  • The script check_survey.sh is handy. It does the following with the (required) argument $1 [which should be a graph data file]:

    1. Erases existing output files previosly created from $1 (if they exist)
    2. Re-builds all 4 test exacutables, if necessary, using your makefile
    3. Runs the 4 tests fbfs_dg.x, fbfs_ug.x, fdfs_dg.x, fdfs_ug.x on the graph coded in $1
    4. Copies the LIB/area51 versions of these 4 tests
    5. Runs the LIB versions on $1
    6. Calculates and displays the Unix diff of the 4 output files
    7. If you have a second command line argument (such as "verbose", but anything at all) cats the 4 output files from your tests with pauses in between

    You will appraeciate this as a time saver and test organizer!