def GetConnectionData(inputFile): d = EPANetSimulation(inputFile) ret, nnodes = d.ENgetcount(d.EN_NODECOUNT) ret, llinks = d.ENgetcount(d.EN_LINKCOUNT) Conn = [] NoConn = [] h_degree = 0 if (len(Conn) == 0): for n in range(0, nnodes + 1): c = [] Conn.append(c) # generate mapping used later for resilience calculation for i in range(0, (llinks + 1)): if (len(Conn) == (nnodes + 1)): nodes = d.ENgetlinknodes(i + 1) if (nodes[0] == 0): Conn[nodes[1]].append(i + 1) Conn[nodes[2]].append(i + 1) h_degree = max(len(Conn[nodes[0]]), len(Conn[nodes[1]]), h_degree) for idx in range(0, nnodes + 1): NoConn.append(len(Conn[idx])) while (len(Conn[idx]) < h_degree): Conn[idx].append(0) del Conn[0] del NoConn[0] return Conn, NoConn
import scipy from sklearn.metrics import mean_squared_error from math import sqrt import matplotlib.pyplot as plt import setPROPERTY #leer la red file = os.path.join(os.path.dirname(simple.__file__), 'test.inp') es = EPANetSimulation(file) #instanciar clases y metodos cond = es.network.links nod = es.network.nodes #obtener la cantidad de conductos ret, num_links = es.ENgetcount(es.EN_LINKCOUNT) #numero de links #leer propiedades de la red diametros = Link.value_type['EN_DIAMETER'] scabrezze = Link.value_type['EN_ROUGHNESS'] presiones = Node.value_type['EN_PRESSURE'] flow = Link.value_type['EN_FLOW'] elevations = Node.value_type['EN_ELEVATION'] velocities = Link.value_type['EN_VELOCITY'] #Raccogliere ixs condotte in Cast Iron e listare le loro scabrezze lista_IX_CI_PIPES = [] for i in range(num_links): C = es.ENgetlinkvalue(i, scabrezze) if C[1] != 0 and 70 < C[1] < 101: lista_IX_CI_PIPES.append(i)