Você está na página 1de 3

Part 2 Finding Station Numbers

by datr808 Mon Apr 30, 2012 12:17 pm

I've already found the minimum value in the green row where the station is already in the MST, but am having trouble finding the corresponding station numbers. How do i get the column of the value then the row of the matching value in the distance table?

Re: Part 2 Finding Station Numbers


by geoffw Mon Apr 30, 2012 4:33 pm

Finding the minimum of the green cells (which you must restrict to those cells with a Y below them) really means finding the column where the mininum exists, as you can easily retrieve the minimum value from the cell. That's one function. The station at the top of that column is the station in the MST that will be connected to one outside the tree. Once you've done that you must find out where in that column the min value occurs, that is the row or station number, that's the station to be added to the MST, and that's another function. The third step is to use the two station numbers to add the new station to the tree by filling in the appropriate cells in columns F and G and clearing the corresponding distance table row.

Part B by tsar868 Sun Apr 29, 2012 9:57 pm how do we know where to put Y in the MST column? I'm so confused lol....

Re: Part B
by apdo780 Sun Apr 29, 2012 11:24 pm

Start with station 1 - This must have a Y to begin with as it's the origin station From there the next closest station can be found, and a Y can be added to it's "In MST" column, Continue thru to each adjacent station, adding a Y to each column as you go

adjacent stn number


by kpen705 Sun Apr 29, 2012 4:35 pm

for the column adjacent stn number, can I just leave the first cell empty? as all other cells give enough information for the mst. and the total distance should not contain distance corresponding to the first cell anyway because the distances have been already taken into account in the following cells.

Re: adjacent stn number


by dvel654 Sun Apr 29, 2012 4:43 pm

yeah it should be empty for Port.

Re: adjacent stn number

by geoffw Sun Apr 29, 2012 7:14 pm

Dominique is correct, but my preference is for everyone to understand why things are this way. Each entry in the "answer" table represents a connection (in graph theory it's called an edge) back to a station (vertex in graph terms) that was previously added to the MST. There is no prior station to 1, so it can't be linked back to any other station. In any undirected graph N vertices can be connected by exactly N-1 edges*, so one entry must be blank. Again it's the first because of the structure of the algorithm (the same MST can be grown from a different vertex, and that entry would be blank instead of 1). It's always more satisfactory to understand the why rather than just the what and the how, necessary though they are. That's what university education is about. I hope that even if you've found the programming hard you've taken away something that will last, and it may not be how to write VBA. * A consequence of this rule is that the simplest graph has a single vertex (that is, one station is legal, zero stations is not). I wonder how many people tested their program with the simplest possible configuration?

Prim's Algorithm
by atcc540 Sat Apr 28, 2012 7:47 pm

In the adapted Prim's Algorithm, it says "Write k in j's adjacent station number cell". What does this really mean? Am having trouble understanding it. Thanks.
atcc540

Re: Prim's Algorithm


by geoffw Sat Apr 28, 2012 10:00 pm

The situation is that you have found the shortest distance between the first set of stations (those in the tree) and the second set (those not in the tree). This links two stations, k from the first set and j from the second (your variable names will be better selected of course). To complete the step of extending the tree by one connected station, find the row in the main table corresponding to j. It will have blank blue cells. Write the integer k into the first blue cell on that row and the distance to the second. Then do the add-Y-and-clear-row stuff for j.

part b
by kpen705 Sat Apr 28, 2012 12:10 pm

for part b we need to set Y for the stations in the algorithm, it says Add station 1 to the MST does this mean we can set the initial condition for port1 at column E as Y without any program or calculations? thanks
kpen705

Re: part b
by geoffw Sat Apr 28, 2012 8:35 pm

Yes that's right. The algorithom can only work when the MST has at least one station, and at the start we force that to be station 1. The tree always has one fewer connections than stations, so that's OK. Remember that as well as inserting the Y you have to clear the row in the distance table.

Do we need to make different subprograms and algorithms to make Prim's Algorithm simpler?

Re: Part B
by dvel654 Sat Apr 28, 2012 12:40 am

I'm able to write Y, clear the row and also find the minimum value in the mst. However, I'm having trouble on writing a code where you collect the column of the minimum value in the mst then find the row where that minimum value is in that column. anyone able to give me some pointers?

Re: Part B
by geoffw Sat Apr 28, 2012 10:53 am

Extra subprograms make the algorithm simpler to follow and implement, they don't change the algorithm itself. You seem to have just one step missing. You say you can find the minimum of the green cells where there is a Y below it. If instead of finding the min value you find the column where the min value is, then you're on the right track. Say that column is C and the min value is V (which you find by inspecting the appropriate cell). Then the missing step is just
Find the row R such that the cell at row R column C has the value V

It's perfectly set up to do as a function, because it needs to know three things: Which column you are looking at (or its station number) The value you are looking for The total number of stations

and the answer is a single value, the station corresponding to the matching row.

Q: I get how the algorithm works for Prims algorithm but do we need different subprograms for it? Like one for the algorithm itself and one for the "write "Y" then clear row". Because the clearing row algorithm is implemented within Prim's Algorithm and if we use two subprograms, is it okay to write a sub within a sub? or should i use a function for "write "Y" then clear row" and then include this function in the Sub which has Prim's Algorithm in it. w.s.l <3 A: Yes youll need multiple functions to do all the separate things With regards to programming, the more you break the problem down into simple individual task, the easier it will be

Você também pode gostar