def store_nodes(values, thalist, key_dict): n = Node(try_convert(values[0], int)) n.type = try_convert(values[1], int) n.vec = numpy.array(map(lambda x: try_convert(x, float), values[2:5])) n.force = numpy.array( map(lambda x: try_convert(x, float), values[5:8])) thalist.append(n)
def start_new_node(self, node_id, start_num=1): # node = self.graph.get_node_by_id(node_id) nodestr, node_id = node_id.split('_') for i in range(start_num): new_node = Node(node_id) new_node.start() print("[manager]start pod,", node_id, start_num) logger.info("[manager]start node, %s, %s", start_num, node_id)
def inner(): current_object = None current_tags = None with open_optional_compression(filename) as fp: for event, elem in ElementTree.iterparse(fp, events=["start", "end"]): if elem.tag in ["osm", "bounds"]: # ignore continue elif elem.tag == "node": if event == "start": current_object = Node() current_object.attrs = elem.attrib current_object.tags = {} elif event == "end": yield current_object elif elem.tag == "tag": if event == "start": key, value = elem.attrib["k"], elem.attrib["v"] current_object.tags[key] = value elif elem.tag == "way": if event == "start": current_object = Way() current_object.attrs = elem.attrib current_object.tags = {} elif event == "end": yield current_object elif elem.tag == "relation": if event == "start": current_object = Relation() current_object.attrs = elem.attrib current_object.tags = {} elif event == "end": yield current_object elif elem.tag == "nd": if event == "start": current_object.node_ids.append(elem.attrib["ref"]) elif elem.tag == "member": if event == "start": current_object.members.append(elem.attrib) else: import pdb pdb.set_trace()
def insertNode(self, e): newnode = Node(self.nextId, e) self.nextId += 1 if self.nodes == None: self.nodes = {newnode.elem: newnode} self.adj = {newnode.elem: Lista()} else: self.nodes[newnode.elem] = newnode self.adj[newnode.elem] = Lista() return newnode
def parse(xml): tokens = tokenize(xml) #skip anything before root node start_i = 0 while start_i < len(tokens) and not isinstance(tokens[start_i], StartTag): start_i += 1 end_i = findEnd(tokens, start_i) root = Node() root.tagname = tokens[start_i].tagname root.attributes = tokens[start_i].attributes children = parse_node(tokens, start_i+1, end_i-1) root.childNodes = children doc = XMLDocument(root) if isinstance(tokens[0], Prolog): doc.prolog = tokens[0] return doc
def get_possible_node(houses, constraints): cnt = 0 for houses in itertools.combinations(houses, 5): node = Node(houses) cnt += 1 if check(node, constraints): print('valid node {0}'.format(node)) return node if cnt % 100000 == 0: print("Step {0}".format(cnt))
def parse_node(elements, start_i, end_i): """ start_i end_i <tag>................</tag> """ nodes = [] i = start_i while i <= end_i: if isinstance(elements[i], TextNode): nodes.append(elements[i]) i += 1 elif isinstance(elements[i], StartTag): end_j = findEnd(elements, i) n = Node() n.tagname = elements[i].tagname n.attributes = elements[i].attributes children = parse_node(elements, i+1, end_j-1) n.childNodes = children nodes.append(n) i = end_j+1 elif isinstance(elements[i], SelfClosingTag): n = Node(True) n.tagname = elements[i].tagname n.attributes = elements[i].attributes nodes.append(n) i += 1 elif isinstance(elements[i], EndTag): i += 1 else: raise ValueError("unknown element", elements[i]) return nodes
def node_mode(self, pos): self.current_element = Node(pos)
def insertNode(self, elem): newnode = Node(self.nextId, elem) self.nextId += 1 return newnode
def inner(): current_object = None current_tags = None with open_optional_compression(filename) as fp: for event, elem in ElementTree.iterparse(fp, events=['start', 'end']): if elem.tag in ['osm', 'bounds']: # ignore continue elif elem.tag == 'node': if event == 'start': current_object = Node() current_object.attrs = elem.attrib current_object.tags = {} elif event == 'end': yield current_object elif elem.tag == 'tag': if event == 'start': key, value = elem.attrib['k'], elem.attrib['v'] current_object.tags[key] = value elif elem.tag == 'way': if event == 'start': current_object = Way() current_object.attrs = elem.attrib current_object.tags = {} elif event == 'end': yield current_object elif elem.tag == 'relation': if event == 'start': current_object = Relation() current_object.attrs = elem.attrib current_object.tags = {} elif event == 'end': yield current_object elif elem.tag == 'nd': if event == 'start': current_object.node_ids.append(elem.attrib['ref']) elif elem.tag == 'member': if event == 'start': current_object.members.append(elem.attrib) else: import pdb pdb.set_trace()
def store_nodes(values, thalist, key_dict): n = Node(try_convert(values[0], int)) n.type = try_convert(values[1], int) n.vec = numpy.array(map(lambda x: try_convert(x, float), values[2:5])) n.force = numpy.array(map(lambda x: try_convert(x, float), values[5:8])) thalist.append(n)
def read(self, filePath): """ Reads text file with nodes and returns the result dict with all objects and their nested properties """ result = { 'coordinates': { 'count': 0, 'nodes': [] }, 'element_groups': { 'number_of_elements': 0, 'count': 0, 'groups': [] }, 'bars': [], 'materials': { 'count': 0, 'materials': [] }, 'geometric_properties': { 'count': 0 }, 'bcnodes': { 'count': 0 }, 'loads': { 'count': 0 } } # print(result['coordinates']['nodes']) with open(filePath, 'r') as f: lines = f.readlines() elementCounter = 0 groupCounter = 0 geometricCounter = 0 for line in lines: line = line.strip() el = line.split(' ') if len(line) == 0: continue if len(line) != 0 and line[0] == "*": section = line[1:].lower() continue if section == 'coordinates': if len(el) == 1: result[section]['count'] = el[0] else: result[section]['nodes'].append( Node(int(el[0]), float(el[1]), float(el[2]))) elif section == 'element_groups': if len(line) == 1: result[section]['count'] = int(el[0]) else: result[section]['groups'].append( Group(el[0], el[1], el[2])) result[section]['number_of_elements'] += int(el[1]) elif section == 'incidences': groups = result['element_groups']['groups'] nodes = result['coordinates']['nodes'] print(el) currentGroup = groups[groupCounter] if (currentGroup.amount == 0): groupCounter += 1 currentGroup = groups[groupCounter] print("Group n: {} count: {}".format( currentGroup.n, currentGroup.amount)) bar = Bar(el[0], nodes[int(el[1]) - 1], nodes[int(el[2]) - 1], groups[groupCounter]) print(""" Bar {} created Start node: {} End Node: {} Group: {} """.format(bar.id, bar.startNode.n, bar.endNode.n, bar.group)) result['bars'].append(bar) currentGroup.amount -= 1 elif section == 'materials': if len(el) == 1: result[section]['count'] = el[0] groupCounter = 0 else: material = Material(el[0], el[1], el[2]) result[section]['materials'].append(material) result['element_groups']['groups'][ groupCounter].setMaterial(material) groupCounter += 1 elif section == 'geometric_properties': if geometricCounter == 0: result[section]['count'] = el[0] else: result['element_groups']['groups'][geometricCounter - 1].setSectionArea( el[0]) geometricCounter += 1 elif section == 'bcnodes': if len(el) == 1: result[section]['count'] = el[0] else: nodeIndex = next((e for e, item in enumerate( result['coordinates']['nodes']) if item.n == int(el[0])), None) result['coordinates']['nodes'][ nodeIndex].setRestriction(int(el[1])) elif section == 'loads': if len(el) == 1: result[section]['count'] = el[0] else: load = Load(el[1], el[2]) nodeIndex = next((e for e, item in enumerate( result['coordinates']['nodes']) if item.n == int(el[0])), None) result['coordinates']['nodes'][nodeIndex].addLoad(load) for bar in result['bars']: bar.createLocalArray() print('---------- Parsing complete! ----------') pprint(result) print('---------------------------------------') return result