HOG2
Width.cpp
Go to the documentation of this file.
1 /*
2  * $Id: width.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 09/18/06.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "GraphAbstraction.h"
13 #include "Map.h"
14 #include "Width.h"
15 
16 using namespace std;
17 
19 // * Finds the node with the given x and y coordinates
20 // *
21 // * This is quite inefficient and should be done in a better way.
22 // */
23 //node* findNodeAt(int x, int y, Graph* g)
24 //{
25 // node_iterator i = g->getNodeIter();
26 //
27 // for (node* n = g->nodeIterNext(i); n; n = g->nodeIterNext(i))
28 // {
29 // if (n->GetLabelL(kFirstData) == x && n->GetLabelL(kFirstData+1) == y)
30 // return n;
31 // }
32 // return 0;
33 //}
34 //
36 // * Finds the minimum edge width of all edges from the node
37 // */
38 //float findMin(node* n)
39 //{
40 // float min;
41 // edge_iterator i = n->getEdgeIter();
42 // edge* e = n->edgeIterNext(i);
43 //
44 // if (!e) return 0.0f;
45 //
46 // min = e->getWidth();
47 //
48 // for (e = n->edgeIterNext(i); e; e = n->edgeIterNext(i))
49 // {
50 // if (e->getWidth() < min) min = e->getWidth();
51 // }
52 //
53 // return min;
54 //}
55 //
56 //
58 // * Finds the maximum edge width of all edges from the node
59 // */
60 //float findMax(node* n)
61 //{
62 // if (!n)
63 // {
64 // return 0.0f;
65 // }
66 //
67 // float max;
68 // edge_iterator i = n->getEdgeIter();
69 // edge* e = n->edgeIterNext(i);
70 //
71 // if (!e)
72 // {
73 // return 0.0f;
74 // }
75 //
76 // max = e->getWidth();
77 //
78 // for (e = n->edgeIterNext(i); e; e = n->edgeIterNext(i))
79 // {
80 // if (e->getWidth() > max)
81 // {
82 // max = e->getWidth();
83 // }
84 // }
85 //
86 // return max;
87 //}
88 //
89 //
90 //
92 // * Finds the maximum edge width of all nodes abstracted by x.
93 // */
94 //float findMaxAbstracted(node* x, Graph* g)
95 //{
96 // float max = 0.0f;
97 // float tempMax;
98 // int numNodes = x->GetLabelL(kNumAbstractedNodes);
99 // node* n;
100 //
101 // for (int i = 0; i < numNodes; i++)
102 // {
103 // n = g->GetNode(x->GetLabelL(kFirstData+i));
104 // tempMax = findMax(n);
105 //
106 // if (tempMax > max)
107 // {
108 // max = tempMax;
109 // }
110 // }
111 //
112 // return max;
113 //}
114 //
115 //
117 // * Finds the minimum node width of all nodes abstracted by x
118 // */
119 //float findMinAbstractedNode(node* x, Graph* g)
120 //{
121 // float min = 0.0f;
122 // int numNodes = x->GetLabelL(kNumAbstractedNodes);
123 // node* n;
124 //
125 // n = g->GetNode(x->GetLabelL(kFirstData));
126 // min = n->getWidth();
127 //
128 // edge_iterator ei;
129 //
130 // for (int i = 0; i < numNodes; i++)
131 // {
132 // n = g->GetNode(x->GetLabelL(kFirstData+i));
133 //
134 // ei = n->getEdgeIter();
135 // for (edge* e = n->edgeIterNext(ei); e; e = n->edgeIterNext(ei))
136 // {
137 // if (g->GetNode(e->getTo())->getWidth() < min)
138 // min = g->GetNode(e->getTo())->getWidth();
139 //
140 // if (g->GetNode(e->getFrom())->getWidth() < min)
141 // min = g->GetNode(e->getFrom())->getWidth();
142 // }
143 //
144 // if (n->getWidth() < min)
145 // {
146 // min = n->getWidth();
147 // }
148 // }
149 //
150 // return min;
151 //}
152 //
153 //
155 // * Finds the minimum edge width in a spanning tree of maximal weight constructed from
156 // * the edges between the nodes abstracted within n.
157 // *
158 // * The Graph g should be the abstracted Graph level one below that of which 'n' is in.
159 // */
160 //float minSpanningTree(node* n, Graph* g)
161 //{
162 // int numNodes = n->GetLabelL(kNumAbstractedNodes);
163 //
164 // if (numNodes <= 0) return 0.0f;
165 //
166 // node* current;
167 // edge_iterator ei;
168 // vector<edge*> edges;
169 //
170 // // Put all the edges in a vector
171 // for (int i = 0; i < numNodes; i++)
172 // {
173 // current = g->GetNode(n->GetLabelL(kFirstData+i));
174 //
175 // ei = current->getEdgeIter();
176 // for (edge* e = current->edgeIterNext(ei); e; e = current->edgeIterNext(ei))
177 // {
178 // if (!edgeInVector(e, edges)) edges.push_back(e);
179 // }
180 // }
181 //
182 // // Sort the edges based on their width (from increasing to decreasing)
183 // sortEdgeWidths(&edges);
184 //
185 // // Calculate the spanning tree of maximal weight
186 // vector<edge*> tree;
187 // vector<int> nodes;
188 //
189 // for (unsigned int i = 0; i < edges.size(); i++)
190 // {
191 // if (!hasCycle(edges[i], nodes))
192 // {
193 // tree.push_back(edges[i]);
194 // nodes.push_back(edges[i]->getTo());
195 // nodes.push_back(edges[i]->getFrom());
196 // }
197 // }
198 //
199 // if (tree.empty())
200 // return 0.0f;
201 //
202 // return tree.back()->getWidth();
203 //}
204 //
205 //
207 // * Returns true if 'e' is in 'edges' (based on it's from and to values),
208 // * false otherwise.
209 // */
210 //bool edgeInVector(edge* e, vector<edge*> edges)
211 //{
212 // for (unsigned int i = 0; i < edges.size(); i++)
213 // {
214 // if ((e->getFrom() == edges[i]->getFrom() && e->getTo() == edges[i]->getTo()) ||
215 // (e->getFrom() == edges[i]->getTo() && e->getTo() == edges[i]->getFrom()))
216 // {
217 // return true;
218 // }
219 // }
220 // return false;
221 //}
222 //
223 //
225 // * Sort all the edges in descending order, based on their edge width.
226 // * Insertion sort (shouldn't be many values in the vector).
227 // */
228 //void sortEdgeWidths(vector<edge*>* edges)
229 //{
230 // unsigned int i, j;
231 // edge* v;
232 //
233 // for (i=1; i < edges->size(); i++)
234 // {
235 // v = (*edges)[i];
236 // j = i;
237 //
238 // while ( (*edges)[j-1]->getWidth() < v->getWidth() )
239 // {
240 // (*edges)[j] = (*edges)[j-1];
241 // j = j-1;
242 // if (j <= 0) break;
243 // }
244 // (*edges)[j] = v;
245 // }
246 //}
247 //
248 //
250 // * Returns true if adding e will cause a cycle, false otherwise
251 // */
252 //bool hasCycle(edge* e, vector<int> nodes)
253 //{
254 // bool b_to = false;
255 // bool b_from = false;
256 // int to = e->getTo();
257 // int from = e->getFrom();
258 //
259 // for (unsigned int i = 0; i < nodes.size(); i++)
260 // {
261 // if (to == nodes[i])
262 // b_to = true;
263 // else if (from == nodes[i])
264 // b_from = true;
265 // }
266 //
267 // return b_to && b_from;
268 //}
269 //
std
Definition: CanonicalGraphEnvironment.h:26
Map.h
GraphAbstraction.h
Width.h