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

Function findModelObject

src/model/Loop.cpp:84–111  ·  view source on GitHub ↗

Recursive depth first search start algorithm with one source node in the visited vector searches all paths of nodes between the source and sink until a handle match is found

Source from the content-addressed store, hash-verified

82 // start algorithm with one source node in the visited vector
83 // searches all paths of nodes between the source and sink until a handle match is found
84 boost::optional<ModelObject> findModelObject(const openstudio::Handle& handle, const HVACComponent& sink, std::vector<HVACComponent>& visited,
85 bool isDemandComponents) {
86 HVACComponent hvacComponent = visited.back();
87 if (handle == hvacComponent.handle()) {
88 return hvacComponent;
89 }
90
91 boost::optional<HVACComponent> prev;
92 if (visited.size() >= 2u) {
93 prev = visited.rbegin()[1];
94 }
95
96 std::vector<HVACComponent> nodes = hvacComponent.getImpl<HVACComponent_Impl>()->edges(prev);
97
98 for (auto& node : nodes) {
99 // if it node has already been visited or node is sink then continue
100 if (std::find(visited.begin(), visited.end(), node) != visited.end() || node == sink) {
101 continue;
102 }
103 visited.push_back(node);
104 boost::optional<ModelObject> foundHandle = findModelObject(handle, sink, visited, isDemandComponents);
105 if (foundHandle) {
106 return *foundHandle;
107 }
108 visited.pop_back();
109 }
110 return boost::none;
111 }
112
113 OptionalModelObject Loop_Impl::component(openstudio::Handle handle) const {
114 boost::optional<ModelObject> supplyComp = this->supplyComponent(handle);

Callers

nothing calls this directly

Calls 7

beginMethod · 0.80
pop_backMethod · 0.80
handleMethod · 0.45
sizeMethod · 0.45
edgesMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected