MCPcopy Create free account
hub / github.com/GeoDaCenter/geoda / ComputeDiameterThread

Method ComputeDiameterThread

Algorithms/spatial_validation.cpp:147–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147void SpatialValidationComponent::ComputeDiameterThread(int start, int end)
148{
149 int n = (int)elements.size();
150
151
152 for (int i = start; i <= end; ++i) {
153 int e = elements[i];
154 int longest_shortestpath = 0;
155
156 // steps from e to others
157 std::map<int, int> steps;
158 for (int j = 0; j < n; ++j) {
159 steps[elements[j]] = elements[j] == e ? 0 :INT_MAX;
160 }
161
162 std::map<int, bool> visited;
163
164 std::vector<Step> cands;
165 cands.push_back(Step(e, steps));
166
167 std::queue<int> q;
168 q.push(e);
169
170 while (!q.empty()) {
171 int tmpid = q.front();
172 q.pop();
173
174 //std::make_heap(cands.begin(), cands.end());
175 //std::pop_heap(cands.begin(), cands.end());
176
177 //Step item = cands.back();
178 //cands.pop_back();
179
180 //int tmpid = item.eid;
181 visited[tmpid] = true;
182
183 std::vector<int> nbrs = edges[tmpid];
184 for (int j = 0; j < (int)nbrs.size(); ++j) {
185 int nb = nbrs[j];
186
187 // steps from e -> nb
188 int new_steps = steps[tmpid] + 1;
189 if (new_steps < steps[nb]) {
190 steps[nb] = new_steps;
191 if (new_steps > longest_shortestpath) {
192 longest_shortestpath = new_steps;
193 }
194 }
195
196 if (visited.find(nb) == visited.end()) {
197 //cands.push_back(Step(nb, steps));
198 q.push(nb);
199 visited[nb] = true;
200 }
201 }
202 }
203 shortest_paths[i] = longest_shortestpath;
204 }

Callers 1

diameter_thread_helperFunction · 0.80

Calls 6

StepClass · 0.85
pushMethod · 0.80
popMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected