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
The official development/testing/assessment environment is specified in the Course Organizer. Code should compile without warnings or errors.
In order not to confuse the submit system, create and work within a separate subdirectory cop4531/proj4.
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.
General requirement on genericity. Use generics whenever possible. For example:
In short: re-use components from LIB (or your own versions) whenever possible.
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.
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.
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
Only a few key implementations are lacking.
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.
The Display method should display the sets encoded by the Partition object:
Use LIB/area51/fpartition2_i.x as a model for display details.
Use the distributed example executable area51/fpartition2_i.x to see what behavior is expected from Dump().
Calculate the sizes of components in the partition and then rank them in order of decreasing size.
Use the distributed example executable area51/fpartition2_i.x (and the source code fpartition2.cpp) to see what behavior is expected from ComponentSizeDistribution().
The Partition constructor needs to call the correct Vector constructors in order to get the representation initialized to singletons:
Partition::Partition ( N size ) : parent_((size_t)size, 0) , rank_((size_t)size, 0) { // loop setting parent values }
Be sure to explicitly cast when mixing the two types N and size_t.
ComponentSizeDistribution is overloaded in three versions:
void ComponentSizeDistribution (const P& p, fsu::VectorThe second and third are variations depending on how the client wants to display the results. The first does the actual calculation of the distribution and places the results in the vector v passed by reference. You supply the implementation of the first one only, the other two are supplied in partition_util_stub.h. Note that a partition object p is supplied by const reference (input) and a vector is supplied by reference (output).& v); void ComponentSizeDistribution (const P& p, size_t maxToDisplay, std::ostream& os = std::cout); bool ComponentSizeDistribution (const P& p, size_t maxToDisplay, const char* filename);
Use the distributed executable area51/fpartition2_i.x to see the expected behavior of ComponentSizeDistribution.