Part 2 of the project requires the implementation of a B+-tree for the data dictionary; use of the PR quadtree and an adjacency list in an application; and the addition of the required commands to the command decoder.
Note that for full credit on part 2, the functions listed below must replace any with the same command name, as we will be adding parameters and changing the underlying structures from those used in part 1.
As before, each command spans exactly one line; commands will be uppercase, and reasonably sloppy syntax is to be supported (spaces and empty lines are allowed). Documentation and conformance is worth DOC points. Don't forget to check the BNF in section as well.
Error: B+ tree already initialized. The current order is:<current-order>
As before, creating a cell that exists already is an error. However, there is no need to detect that two cells with different names have identical coordinates, and, there is no intention to put this specific error in the test data until Part 3.
{(bar)}
{(CELL3),(foo)}
{(CELL1,CELL2),(CELL3),(bar),(foo)}
Even at the leaves print only the key (the cellname). If the tree is empty, print
"Tree is empty." Your tree is not expected to match mine exactly. Your grade will
be based on your tree displaying the following properties(this does deviate somewhat
from shaffer, you are required do what what is listed below):
For our order m tree:
The leaves contain between 1 and m-1 keys. They may not have m keys.
Internal node internal nodes must have between ceiling(m/2) and m children. There must
be one fewer guide than children (no 'extra' key on the far left should be printed, even
if you used one in your implementation). Your tree, of course, must also contain the correct
data at the leaves!
Note: At the same time that a cell is inserted in the PR quadtree, the EnviroBot (EBOT) net connecting existing cells is extended to include the additional cell. Details of EBOT net development are included here for your convenience. When a cell is inserted in the PR quadtree successfully, the cell must be added to the EBOT net by finding the cheapest edge between the existing cell and all other cells already in the net.
The edge cost is computed according to the following algorithm for inserting the j-th cell into the path.
If
the cost is
. For
, the edge cost between cells A and
B having coordinates
and
, respectively, is
where
and
is defined similarly.
So, if cell B is being inserted in the PR quadtree and there are already
cells in the
service path, an edge will be inserted from cell B to the existing cell A
for which
is minimal. And, yes, that means the number
of cells already in the EBOT net also contributes to the cost. However,
once an edge has been inserted in the EBOT net, no attempt should be made
to recompute the cost.
Furthermore, as the cost increases, it may be more reasonable to keep the cost in two pieces--the portion that dominates, with the j-th power tucked in, and the portion from the difference in x and y coordinates...this will keep the need to use double precision to store humongous integers from introducing unneeded errors. Do what you think is right.
Were this a REAL application, you might suggest that the developers consider using a disconnected EBOT net once the number of cells makes the cost prohibitively large-on the other hand, we really don't know the units of the cost function, now do we, so these values might be what the customer expects.
Full credit will be given for brute force (meaning always compute all the distances to all cells in the net). However, up to 10 points extra credit may be given if your algorithm need not always check all known cells to find the closest-and sometimes, reasoning based on the size of a given portion of the cost function can allow you to prune the PR quadtree.
If you do choose this option, make sure you describe your algorithm within your code, and explain your algorithm and why it is better than brute force in the README. p.s. The cost function doesn't have any particular rationale, but ya gotta live with it ;)
Important: Last Minute Clarification of Ebot Net cost function
Since the last term of the cost function blows up quickly, the client has agreed to accept the following modification. Floating point may be used as an approximation to the cost and double precision gives best results. The BNF now reflects this change, with <float> replacing <int> as needed.
Furthermore, suppose you are adding cellname
to the EBOT NET.
When comparing cost
, the cost of a potential
edge connecting
to
, to cost
, the cost of a potential edge
between
and
, you find that the following is true:
Then, you may continue as if the cost to connect
to either
or
were identical, and use strcmp order of the cell name
to discern which of
or
gets
the connection. Please note that if you compute the function as written,
you will have a loss of precision when
and
differ by only a few
low order digits.
So, you might want to consider the following alternative if you need to preserve the actual difference for some other reason. This method can be evaluated without the loss of precision caused by subtracting two nearly equal floating point numbers.
If
, then the cost of the edge to A is treated as matching
that to B whenever
(Note that the previous
discussion assumes that
and
are non-negative.)
The cells should be listed in strcmp order, with the nodes linked to each individual cell listed in strcmp order afterwards. (Ok, not too helpful.) Try:
CELL1: CELL2 CELL 3 CELL2: CELL1 CELL3: CELL1 CELL4 CELL4: CELL3
NW NE Foo at (5.000,6.000) SW Bar at (1023.000,1023.000) SEthe output of RADIUS_CELL(Foo,1000,1000) should be
NW NE Foo at (5.000,6.000) SW SE
even though NW and SE may actually be NULL pointers. Please don't mess this up, I'll have no sympathy if you do.
***** ==> CREATE_PSEUDO_CELLS(...) New pseudo cells: +PS001 at (...,...) . . . or ***** ==> CREATE_PSEUDO_CELLS(...) No new pseudo cells discovered in the specified region.
Note that you will need either the C++ utilities on our 420 webpage, or SWING in Java. Please note that this ability will be very helpful for part 3. And, this function description will need to be updated, because the TA's have to decide how to grade this piece.