Project 4: Partition

Implementing and analysing the Partition class

Version 09/23/17

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

Operational Objectives: Implement the Partition class along with selected analysis utilities.

Deliverables:

partition2.h       # contains template < typename N > class Partition
partition_util.h   # utilities for Partition class
makefile           # creates targets fpartion2.x
log.txt            # development and testing log

Procedural Requirements

  1. The official development/testing/assessment environment is specified in the Course Organizer. Code should compile without warnings or errors.

  2. In order not to confuse the submit system, create and work within a separate subdirectory cop4531/proj4.

  3. Maintain your work log in the text file log.txt as documentation of effort, testing results, and development history. This file may also be used to report on any relevant issues encountered during project development.

  4. General requirement on genericity. Use generics whenever possible. For example:

    1. If you need to sort, use a generic sort algorithm or a container with built-in sorting.
    2. If a sort requires a specialized notion of order, create a function object that captures the desired order property.
    3. In general, whenever a generic algorithm exists that can be deployed, do not circumvent that with specialized one-off code.
    4. Carefully choose all containers as the most appropriate for a particular purpose.

    In short: re-use components from LIB (or your own versions) whenever possible.

  5. Begin by copying all files from LIB/proj4 into your proj4 directory:

    LIB/proj4/deliverables.sh       # submission configuration file
    LIB/proj4/fpartition2.cpp       # test harness for Partition
    LIB/area51/fpartition1_i.x      # sample executable
    LIB/area51/fpartition2_i.x      # sample executable
    

    Execute fpartition2_i.x to gain understanding of expected behavior of your Partition class and associated utilities.

  6. Create the file partition2.h containing the definition and implementation of template<typename N> Partition. Test your class thoroughly using the supplied fpartition2.cpp.
  7. Be sure that you have established the submit script LIB/scripts/submit.sh as a command in your ~/.bin directory.

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

Code Requirements and Specifications - Partition

  1. Use the API defined by the following:

    namespace fsu
    {
      template < typename N = size_t >
      class Partition
      {
      public:
        explicit Partition       ( N size );         // create singletons {0} .. {size-1}
    
        void     Union           ( N x , N y )       { Link(Root(x),Root(y)); }
        bool     Find            ( N x , N y )       { return Root(x) == Root(y); }
        bool     Find            ( N x , N y ) const { return Root(x) == Root(y); }
    
        void     Reset           ();                 // revert to singletons
        void     Reset           ( N newsize );      // change size and Reset
        void     Expand          ( N newsize );      // increase size, maintain state
     
        size_t   Size            () const            { return rank_.Size(); }
        size_t   Components      () const;           // returns number of components
    
        void     Display         ( std::ostream& os ) const;
        void     Dump            ( std::ostream& os ) const;
    
        N        Root            ( N x );            // path compression changes state
        N        Root            ( N x ) const;      // no path compression
    
      private: // methods
        void Link   ( N root1 , N root2 );           // union assuming arguments are roots
    
      private: // objects
        fsu::Vector <N> parent_;
        fsu::Vector <N> rank_;
      };
      ...
    } // fsu
    

    Follow the implementation started here. This is distinct from that of the lecture notes in that

    1. N is assumed to be an unsigned type
    2. Root nodes are recognized by (parent_[i] == (N)i)
    3. Rank/height info is maintained in the separate vector rank_. Recall this starts out as the height of the tree rooted at i but is not maintained once i ceases to be a root in the forest.

    Only a few key implementations are lacking.

  2. Be sure that you implement path compression in the non-const version of Root. Of course, you will be forced to use the non-compression version for the const version of Root.

  3. The Display method should display the sets encoded by the Partition object:

    1. Enclose the entire partition in braces
    2. Enclose the individual sets of the partition in braces
    3. List the elements of each set in increasing order
    4. List the sets ordered by the value of the first element of the set

    Use LIB/area51/fpartition2_i.x as a model for display details.

  4. Use the distributed example executable area51/fpartition2_i.x to see what behavior is expected from Dump().

Code Requirements and Specifications - utilities

  1. Calculate the sizes of components in the partition and then rank them in order of decreasing size.

  2. Use the distributed example executable area51/fpartition2_i.x (and the source code fpartition2.cpp) to see what behavior is expected from ComponentSizeDistribution().

Hints - Partition

Hints - Partition Utilities