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.
<strong>and</strong> flipACell(&node, row, column) defined in NineTailModel are inherited in<br />
<strong>Weighted</strong>NineTailModel. The getNumberOfFlips(int u) function returns the number of<br />
flips from node u to the target node.<br />
Listing <strong>25</strong>.10 implements <strong>Weighted</strong>NineTailModel.<br />
Listing <strong>25</strong>.10 <strong>Weighted</strong>NineTailModel.h<br />
1 #ifndef WEIGHTEDNINETAILMODEL_H<br />
2 #define WEIGHTEDNINETAILMODEL_H<br />
3<br />
4 #include "NineTailModel.h" // Defined in Listing 24.9<br />
5 #include "<strong>Weighted</strong>Graph.h" // Defined in Listing <strong>25</strong>.2<br />
6<br />
7 using namespace std;<br />
8<br />
9 class <strong>Weighted</strong>NineTailModel : public NineTailModel<br />
10 {<br />
11 public:<br />
12 // Construct a model for the Nine Tail problem<br />
13 <strong>Weighted</strong>NineTailModel();<br />
14<br />
15 // Get the number of flips from the target to u<br />
16 int getNumberOfFlips(int u);<br />
17<br />
18 private:<br />
19 // Return a vector of Edge objects for the graph<br />
20 // Create edges among nodes<br />
21 vector getEdges();<br />
22<br />
23 // Get the number of flips from u to v<br />
24 int getNumberOfFlips(int u, int v);<br />
<strong>25</strong> };<br />
26<br />
27 <strong>Weighted</strong>NineTailModel::<strong>Weighted</strong>NineTailModel()<br />
28 {<br />
29 // Create edges<br />
30 vector edges = getEdges();<br />
31<br />
32 // Build a graph<br />
33 <strong>Weighted</strong>Graph graph(NUMBER_OF_NODES, edges);<br />
34<br />
35 // Build a shortest path tree rooted at the target node<br />
36 tree = new ShortestPathTree(graph.getShortestPath(511));<br />
37 }<br />
38<br />
39 vector <strong>Weighted</strong>NineTailModel::getEdges()<br />
40 {<br />
41 vector edges;<br />
42<br />
43 for (int u = 0; u < NUMBER_OF_NODES; u++)<br />
44 {<br />
41