Okay, so I've been looking at this. My current understanding is this:
1. Any cell can move it's parcel to any adjacent neighbor (NSEW).
2. Every cell must have exactly one parcel -- an outgoing parcel must be balanced with an incoming parcel.
3. The goal of the assignment is to find
an optimal solution -- defined as the minimum number of simultaneous transitions...
at least cost.
optimal solution vs any solution
The whole point behind algorithms is to find "optimal solutions". In many instances, there may be more than one optimal solution, and for many classes of problems we don't actually know what the true optimal solution is (or if it exists). The point is to find a reasonably close to optimal solution.
cost analysis
The purpose is because these algorithms are applied to doing things that cost money. In your example problem, that translates to the amount of time the entire group of people must be standing on the roof chucking boxes at each other. Ideally, a person should have to throw and catch as few boxes as possible...
Hence, I am not enamored of your professor's solution because it minimizes transitions without regard to cost. (I am defining cost as the total number of individual moves. For example, to swap two cells requires a single transition composed of two simultaneous moves -- the cost is 2.)
Here's an ASCII infographic for you :O)
the initial state
0,1 1,0 0,2
1,1 2,0 1,2
2,2 2,1 0,0
chaos 12
your professor's solution: 4 transitions, 20 moves
□ → ← □ □ ↓ □ → ← → ← □
□ ↓ ← □ □ ↑ □ → ← → ← □
□ → ↑ → ← □ □ → ← □ □ □
chaos 14 chaos 10 chaos 4 chaos 0
solution 1: 4 transitions, 14 moves
→ ← □ □ □ □ □ □ □ ↓ □ □
→ ← □ □ □ □ ↓ □ □ ↑ □ □
□ → ← → ← □ ↑ → ← □ □ □
chaos 8 chaos 6 chaos 2 chaos 0
solution 2: 4 transitions, 22 moves
→ ← □ ↓ ← □ → ↓ □ ↓ □ □
→ ← ↓ ↓ ↑ ← ↑ ← □ ↑ □ □
□ □ ↑ → → ↑ □ → ← □ □ □
chaos 8 chaos 6 chaos 2 chaos 0
|
You will notice that the current cost of the board can be calculated as what I've (blithely) called "chaos": the sum of the distances each parcel must travel. This "chaos" has a 1:2 ratio with the maximal number of moves needed to solve the system.
You'll notice that your professor's solution
increases the amount of chaos (or
cost) in the system. I haven't given any thought as to why his algorithm does that... (and I don't care). You'll also notice that solution 2, while it does not increase the amount of chaos, nevertheless increases the final cost to worse than your professor's solution!
Solution 1 is an optimal solution because it has minimal cost.
methodology
For such a small dataset, it is possible to simply calculate
every solution to find the optimal one. But as you know, this is an O(nⁿ) problem, so adding a few rows is exponentially detrimental to a brute-force computation.
The goal, then, is to try to develop a method that only moves us closer to an optimal solution -- that is, it should not ever decrease the "chaos".
For example, a common subproblem is a parcel two steps out of place in the same direction, but the adjacent parcel is already in its final location. By simply swapping the two, you do not increase the "chaos" of the system, but you do move it toward a
solvable state.
Some backtracking is acceptable.
Well, I hope this helps move you along. Let me know what you think.
Do this by identifying subproblems that can be solved easily. Be prepared to backtrack.