MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / findModelObjects

Function findModelObjects

src/model/Loop.cpp:185–224  ·  view source on GitHub ↗

Recursive depth first search start algorithm with one source node in the visited vector when complete, paths will be populated with all nodes between the source node and sink

Source from the content-addressed store, hash-verified

183 // start algorithm with one source node in the visited vector
184 // when complete, paths will be populated with all nodes between the source node and sink
185 void findModelObjects(const HVACComponent& sink, std::vector<HVACComponent>& visited, std::vector<HVACComponent>& paths,
186 bool isDemandComponents) {
187 boost::optional<HVACComponent> prev;
188 if (visited.size() >= 2u) {
189 prev = visited.rbegin()[1];
190 }
191
192 std::vector<HVACComponent> nodes = visited.back().getImpl<HVACComponent_Impl>()->edges(prev);
193
194 for (const auto& node : nodes) {
195 // if it node has already been visited then continue
196 if (std::find(visited.begin(), visited.end(), node) != visited.end()) {
197 continue;
198 }
199 if (node == sink) {
200 visited.push_back(node);
201 // Avoid pushing duplicate nodes into paths
202 if (paths.empty()) {
203 paths.insert(paths.end(), visited.begin(), visited.end());
204 } else {
205 for (const auto& visitedit : visited) {
206 if (std::find(paths.begin(), paths.end(), visitedit) == paths.end()) {
207 paths.push_back(visitedit);
208 }
209 }
210 }
211 visited.pop_back();
212 }
213 }
214
215 for (const auto& node : nodes) {
216 // if it node has already been visited or node is sink then continue
217 if (std::find(visited.begin(), visited.end(), node) != visited.end() || node == sink) {
218 continue;
219 }
220 visited.push_back(node);
221 findModelObjects(sink, visited, paths, isDemandComponents);
222 visited.pop_back();
223 }
224 }
225
226 std::vector<ModelObject> Loop_Impl::demandComponents(const HVACComponent& inletComp, const HVACComponent& outletComp,
227 openstudio::IddObjectType type) const {

Callers 2

demandComponentsMethod · 0.85
supplyComponentsMethod · 0.85

Calls 8

beginMethod · 0.80
pop_backMethod · 0.80
sizeMethod · 0.45
edgesMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected