CS141:    Assignment 3

 version 1.0   check the mailing list for updates and corrections and hints.

   Due on:
   Written part:             Thu 30 by 3:00 (end of my office hours)
   Programming part:  We 29  by 11:59

Written Part.  [30]

1.  [20]  Assume a weighted  connected undirected graph $G(V,E, w())$ and assume
that all the weights of the edges are distinct integers (no two weights are equal).
   Prove or disprove the following statements:
   a. The minimum spanning tree of the graph is unique.
   b.  For any node of the graph v, the shortest path tree rooted at v is unique.

2. [10] Exercise 27.3-4  p.604

Programming part.  [50]

In the alien world of Faloutsonia,  there is a river, and the creatures cross this river daily.
The only way to cross is a boat with a guard and the boat has 2 positions for passengers.
There are two  species  tha cross the river: the Xerons and the Omons.  The Xerons can eat
 the Omons. (The Omons are vegetarians.)
The guard has to transfer Xerons and Omons across the river with the following rules:
    * There must never be more Xerons than Omons in one side of the river without the guard,
        because then the Xerons will eat the Omons.
        Note: if the guard is present, she can make sure that none gets eaten.
         Also, if Omons are equal to or more than the Xerons, then none gets eaten.
    * The passengers in the boat  can not exceed the boat capacity (2)
        However, they can be less than 2. You can have passengers from either species.

Assume that we start with N creatures, X Xerons, and O=N-X Omons, and the guard with
the boat on the A side of the river, and we want to see if we can transfer everybody to the B
side of the river without anybody getting eaten.

You are commanded by the supreme ruler of Faloutsonia, Michalorg, to write a C++ program to help the guard: what is the sequence of moves that guarantee safe-for-all transportation?
In case of failure or segmentation fault, the ruthless Michalorg will destroy earth.

  The input of the program is the total number of creatures N and  the  number of
Xerons X.  Obviously,  N-X is the Omons. Everybody is on the A side of the river.

  The output should be:
    a. [5] if there is a way to transfer everybody across (Print Yes or No).
    b. [5] the minimum number of times that the boat has to cross the river
         (total crossings in either direction).
    c. [15] the exact sequence of states and moves of a safe for all trip.
         The output should look like:
        A->B:     X_a  O_a       | Move:    XO                    |   X-X_a      O-O_a
        A<-B:    X_a'  O_a'     |                        Move: XX |   X-X_a'     O-O_a'  (Note: the tabbing here)
        A->B:    X_a''  O_a''   | Move:  OO                      |   X-X_a''    O-O_a''

    where  each line X_a and O_a are the number of Xerons and Omons that are currently
on side A of the river.  The  "XO"  "XX" are strings that indicate what will be the next two
passengers (among the creatures currently reported on the population of the river bank).
For the move, obviously an "X" ("O") stands for a Xeron (Omon).
    This way in the above example:  X_a' = X_a -1, and  O_a' = O_a -1.
In the next state  X_a'' = X_a' + 2,    and O_a'' = O_a'

Also,  no makefile and no report will severely reduce your grade!!!!!

In more detail, your executable should be named "run" and it should be run as follows:

$ run  N_creatures  X_xerons

Note the two numbers as passed as parameters this time. And not as a redirected input!

The other 25 points: are the report, the makefile, the programming style, programming efficiency etc.   More specifically from the 25 points we have:
  The report [15 points] is a very important file since you need to describe
     a. how you model the problem
     b. what is your solution like
     c. why do you think your solution is correct (arguments not proof)
     d. Main data structures, classes and methods
The report should not be more than two pages (maximum three).

Hints: 1. How can you model the problem? How can you model a state?
You may not need more than three variables for a given N and X.
            2.  You may want to explore all possible moves, unless you come
up with a clever technique. However,  the technique should work for all possible
inputs (N=2 X=1,  N=12 X=7 etc)
            3. Make sure your program does not fall into infinite loops. How many times
do you want to consider or visit one state?

Programs and output


         a. your program ready to compile and your executable named: run
         b. your makefile
         c. a README file for instructions on how to run it
         f. the report in ascii, also handed in with the written part.
         e. the output of your program in the following cases.
            You should have the output of  7 number of  executions nicely
separated in one file. These executions should have as input parameters:

        7  1
        7  2
        7  7

A hard copy of your report should be given with the written of the assignment.

WARNING: A report that makes false claims about the program will be considered as cheating.
                        An output sample that is not generated by the submitted program will also be considered  as cheating.

Check:  http://www.cs.ucr.edu/~klick/    the links for linux (for makefiles) and programming for
stylistic and programming suggestions.