CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Recall that we created a class NineTailModel in Section 24.8 for modeling the nine tail problem. We<br />
now create a new class named <strong>Weighted</strong>NineTailModel that extends NineTailModel, as shown<br />
in Figure <strong>25</strong>.22.<br />
NineTailModel<br />
#tree: Tree*<br />
+NineTailMod el()<br />
+get Shortes tPath(nodeIndex: i nt):<br />
vector<br />
+getNode(index: int): vector<br />
+getIndex(node: vector&): int<br />
+printNode(node: vector&): void<br />
#getEdges(): vector<br />
#getFlippedNode(nod e: vector&,<br />
position: int): int<br />
#flipACell(&node: vector&, row:<br />
int, column: int): void<br />
A tree rooted at node 511.<br />
Constructs a model for th e Nine Tail problem <strong>and</strong> obtains<br />
th e tree.<br />
Returns a path from the specified n ode to the root. The<br />
path returned consists of the node labels in a vector.<br />
Returns a node consists of nine characters of H’s <strong>and</strong> T’s.<br />
Returns the index of the specified node.<br />
Displays the node to the console.<br />
Returns a vector of Edge objects for the graph.<br />
Flip the node at the specified position <strong>and</strong> returns the<br />
index of the flipped node.<br />
Flips th e node at th e specified row <strong>and</strong> colu mn.<br />
<strong>Weighted</strong>NineTailModel<br />
+Wei ghted Ni neTai lModel()<br />
+getNumberOfFlips(u: int): int<br />
-getNumberOfFlips(u: int, v: int): int<br />
-getEdges(): vector<br />
Constructs a model for the weighted nine tail problem<br />
<strong>and</strong> obtains a ShortestPathTree rooted from the target<br />
node.<br />
Returns the number of flips from node u to the target<br />
node 511.<br />
Ret urns the number of di fferen t cells between the two<br />
nodes.<br />
Gets the weigh ted edges for the weighted nine tail<br />
problem.<br />
Figure <strong>25</strong>.22<br />
<strong>Weighted</strong>NineTailModel extends NineTailModel.<br />
The NineTailModel class creates a Graph <strong>and</strong> obtains a Tree rooted at the target node 511.<br />
<strong>Weighted</strong>NineTailModel is the same as NineTailModel except that it creates a<br />
<strong>Weighted</strong>Graph <strong>and</strong> obtains a ShortestPathTree rooted at the target node 511. The functions<br />
getShortestPath(int),<br />
getNode(int), getIndex(node), getFlippedNode(node, position),<br />
40