COP4530 Fall 2004: Assignment 2
Due: 5 Oct 2004
Educational objectives:
Statement of work: (i) Implement a self-organizing linked list based on
the count method, (ii) implement a simple generic vector class, and (iii) use
the above containers to write a program that will provide certain features
useful in computational nanotechnology, as described below.
Deliverables: Turn in a makefile, LOG.txt
file, and all header and cpp files that are needed to build your project, as described in www.cs.fsu.edu/~asriniva/courses/DS04/HWinstructions.html.
Background: Nanotechnology deals with
understanding matter at the level of a nanometer (at the level of atoms), and
turning this fundamental understanding into useful products. It promises to
revolutionize science and engineering, and much research effort and funding
have been targeted to this area. Computation plays a crucial role here, since
experiments are often difficult and expensive. We deal with one aspect of the
computations. In a large class of computations, we need to track the motion of
a set of atoms. The motion of an atom is influenced mostly by the positions of
atoms close to it. Consequently, for each atom, we need to determine atoms
close to it, and then compute their interaction. For our purposes, an atom is
close to another if it is within a specified distance, called a cutoff
distance. This assignment deals with the issue of how we can determine which
atoms are close to a specified atom. One way to accomplish this task is to
compute the distance between the specified atom and all other atoms, and
determine which atoms are close. This requires Q(n) time per atom, if we have n atoms.
A popular alternative is to use a cell-based approach, which you will implement in your program. The space being studied is divided into cells, whose length is equal to the cutoff distance. Atoms are placed in cells, with a linked list being used in each cell to store the atoms belonging to that cell. In order to compute the neighbors of an atom, distances need to be checked only for the atoms in the cell to which it belongs, and in its 26 neighboring cells (boundary cells have fewer neighboring cells). This number is typically small.
Requirements:
-
vector.h: This file implements a simple generic vector class
with template parameter T. The following features must be implemented:(i) a
default constructor that
initializes an array of size 10, (ii) a destructor, (iii) void push_back(const T &e), (iv) the operator[], and (v) int size( ) const. You may implement additional features, if you wish
to. If you do not implement a copy constructor and an assignment operator, then
you should prevent their use by making them private.
-
AtomList.h/cpp: These files implement a doubly-linked self adjusting
list using the count method. This class need not be generic; it is sufficient
to implement it so that it can store information regarding atoms. The exact
information stored depends on the design of your program. Each node of the list
will include a variable called count,
which counts the number of times an atom has been accessed. We will give more
details below on when an atom is considered accessed. You are free to choose
the specific features you wish to implement. But they should be reasonable. For
example, you will certainly need to implement an insert and a delete function.
-
Other files: You may use more files. You will need a
three-dimensional array of linked lists. Each element of the array will
correspond to a cell in space. You will also use a vector that will point to
nodes in the linked lists. This is used to make certain operations faster. We
will give more information later.
-
main.cpp: This is the main program. It will read the following
simulation parameters from a file called cells.in, where each of the following is a floating point
number on a separate line of the file: x0, x1, y0,
y1, z0, z1, c1, c2, c3. The region of space the program keeps track of is
the cube consisting of all point (x, y, z) such that x0 < x < x1, y0
< y < y1, and z0
< z < z1. Two types
of atoms are permitted, C
(representing Carbon) and H
(representing Hydrogen). The cut-off distance for C-C interactions is c1, for C-H
and H-C c2, and for H-H
c3. Your cells should use
have lengths equal to the largest cutoff distance. If the user wants to give
these parameters in a file with a different name, then the user will give the
command line arguments: -f <filename>.
The
program will behave as follows. It accepts a series of commands from the user,
with each command terminated by a newline. It takes an appropriate action on encountering each command, as
described below. In the time complexities given below, m is the total number of atoms in the system.
-
quit: causes the program to be terminated
-
insert <Type> x
y z: <Type> is either the character C (indicating Carbon) or H (indicating Hydrogen). x, y, and z
are floating point numbers giving the position of this atom. On reading this
command, this atom will be given a label I, if this is the I th
insert operation, with I starting
at 0. Information regarding this
atom is placed in a linked list in the appropriate cell. Location I in the vector is made to point to the node in the
linked list where information regarding this atom is stored. The time
complexity for this operation is O(1).
-
delete n: It causes information regarding the atom labeled n to be deleted from the cell where it is present.
Location n in the vector should be
assigned a suitable value so that it does not point to a freed memory location.
The time complexity for this operation is O(1).
-
move n x y z: If the current position of the atom labeled n is (xn, yn, zn), then the new position will be (xn+x, yn+y,
zn+z). Note that the atom
may now belong to a different cell. The count field for this atom is increment by one. The
time complexity for this operation is O(# of elements in its cell).
-
place n x y z: The new position of the atom labeled n should become (x, y, z). Note that the atom may now belong to a different
cell. The count field for this
atom is increment by one. The time complexity for this operation is O(#
of elements in its cell).
-
Neighbors n: This causes all neighbors of the atom labeled n to be output to standard output on a separate line,
terminated by a newline, in the following format:
where
n is the label of the atom, and n1,
n2, ... nk are
the labels of its neighbors. The '...'
is not a part of the actual output. The count fields for atoms n, n1, ..., nk are increment by one. Note that atom ni is a neighbor of atom n if the distance between them is smaller than the
cutoff for their types. For example, if n is Carbon and ni
is Hydrogen, then they are neighbors if their cutoff distance is less than c2. The time complexity for finding the neighbors is O(#
of elements in its cell and in neighboring cells).
-
makefile
Notes:
1.
Your program should not
have any output other than those specified above.
2.
You should not use the
STL list or vector classes. You may use the string class. Please get my
permission before using any other STL feature.
3.
We have provided a sample executable at ~cop4530/fall04/bin/proj2
on linprog
. A sample cells.in
file is available in the same directory. This program works correctly for the input provided in test.in
. You can cd
to the above directory and run: ./proj2 < test.in
to see the desired output. Once you build test cases for the program, you should test them with the above program and see if you find some errors, and likely causes for the errors. The first person to report a new error and suggest a suitable likely cause for the error with get bonus points!
4.
It is a good idea to
create sample test cases to test your program, early in the software
development process.
5.
We will test your vector class on an entirely different application. So it is
important for this class to be generic and exactly as specified.
6.
It will be helpful for
you to draw the cells array, the linked lists, and the vector for a
two-dimensional version of this problem, and some sample input, so that you get
a better idea of what the program does.