bim2sim.elements.graphs package
Submodules
bim2sim.elements.graphs.hvac_graph module
This module represents the elements of a HVAC system in form of a network graph where each node represents a hvac-component.
- class bim2sim.elements.graphs.hvac_graph.HvacGraph(elements=None, **attr)
Bases:
Graph
HVAC related graph manipulations based on ports.
- static detect_bypasses_to_wanted(graph, wanted, inert, blockers)
Returns a list of nodes which build a bypass to the wanted elements and blockers. E.g. used to find bypasses between generator and distributor. :returns: list of nodes
- dump_to_cytoscape_json(path: Path, ports: bool = True)
Dumps the current state of the graph to a json file in cytoscape format.
- Args:
path: Pathlib path to where to dump the JSON file. ports: if True the ports graph will be serialized, else the element_graph.
- property element_graph: Graph
View of graph with elements instead of ports
- property elements
List of elements present in graph
- static find_bypasses_in_cycle(graph: Graph, cycle, wanted)
Detects bypasses in the given cycle of the given graph.
Bypasses are any direct connections between edge elements which don’t hold wanted elements.
- Args:
graph: The graph in which the cycle belongs. cycle: A list of nodes representing a cycle in the graph. wanted: A list of classes of the desired node type.
- Returns:
List: A list of bypasses, where each bypass is a list of elements in the bypass.
- Raises:
None
- classmethod from_serialized(data)
Sets grapg from serialized data
- static get_all_cycles_with_wanted(graph, wanted)
Returns a list of cycles with wanted element in it.
- get_connections()
Returns connections between different parent elements
- static get_connections_between(graph, wanted: Set[Type[ProductBased]], inert: Set[Type[ProductBased]] = {})
Detect simple connections between wanted items. All graph nodes not in inert or wanted are counted as blocking :returns: list of none overlapping subgraphs
- get_contractions(node)
Returns a list of contracted nodes for the passed node. :param node: node in whose connections you are interested :return:
- get_cycles()
Find cycles in the graph. :return cycles:
- static get_dir_paths_between(graph, nodes, include_edges=False)
get direct connection between list of nodes in a graph.
- static get_not_contracted_neighbors(graph, node)
- static get_parallels(graph, wanted: Set[Type[ProductBased]], inert: Set[Type[ProductBased]] = None, grouping=None, grp_threshold=None)
- Detect parallel occurrences of wanted items.
All graph nodes not in inert or wanted are counted as blocking. Grouping can hold additional arguments like only same size.
- Grouping:
dict with parameter to be grouped and condition. e.g. (
rated_power: equal) :grp_threshold: float for minimum group size :returns: list of none overlapping subgraphs
- static get_path_without_junctions(graph, root, include_edges=False)
Get not orientated list of nodes for paths that includes the defined root element. The edges areany junction elements. These edges are not included by default. Return all nodes in thisde path. # todo make this correct! :graph = :root = element which must be in path :include_edges = include edges of path or not
- static get_type_chains(element_graph: Graph, types: Iterable[Type[ProductBased]], include_singles: bool = False)
Get lists of consecutive elements of the given types. Elements are ordered in the same way as the are connected.
- Args:
element_graph: Graph object with elements as nodes. types: Items the chains are built of. include_singles:
- Returns:
chain_lists: Lists of consecutive elements.
- merge(mapping: dict, inner_connections: list, add_connections=None)
Merge port nodes in graph
according to mapping dict port nodes are removed {port: None} or replaced {port: new_port} ceeping connections. adds also inner connections to graph and if passed additional connections.
WARNING: connections from removed port nodes are also removed
- Parameters:
add_connections – additional connections to add
mapping – replacement dict. ports as keys and replacement ports
or None as values :param inner_connections: connections to add
- plot(path: Path = None, ports: bool = False, dpi: int = 400, use_pyvis=False)
Plot graph and either display or save as pdf file.
- Args:
- path: If provided, the graph is saved there as pdf file or html
if use_pyvis=True.
ports: If True, the port graph is plotted, else the element graph. dpi: dots per inch, increase for higher quality (takes longer to
render)
use_pyvis: exports graph to interactive html
- recurse_set_side(port, side, known: dict = None, raise_error=True)
Recursive set flow_side to connected ports
- recurse_set_unknown_sides(port, visited: list = None, masters: list = None)
Recursive checks neighbours flow_side. :returns tuple of
common flow_side (None if conflict) list of checked ports list of ports on which flow_side s are determined
- static remove_classes_from(graph: Graph, classes_to_remove: Set[Type[ProductBased]]) Graph | HvacGraph
Removes nodes from a given graph based on their class.
- Args:
graph: The graph to remove nodes from. classes_to_remove: A set of classes to remove from the graph.
- Returns:
The modified graph as a new instance.
- static remove_not_wanted_nodes(graph: element_graph, wanted: Set[Type[ProductBased]], inert: Set[Type[ProductBased]] = None)
Removes not wanted and not inert nodes from the given graph.
- Args:
graph: element_graph wanted: set of all elements that are wanted and should persist in
graph
inert: set all inert elements. Are treated the same as wanted.
- subgraph_from_elements(elements: list)
- Returns a subgraph of the current graph containing only the ports
associated with the provided elements.
- Args:
elements: A list of elements to include in the subgraph.
- Returns:
A subgraph of the current graph that contains only the ports associated with the provided elements.
- Raises:
AssertionError: If the provided elements are not part of the graph.
- to_serializable()
Returns a json serializable object