Example #1
0
def p_type(p): 
    '''type : TYPENAME
            | typename'''
    if (isinstance(p[1], str)) :
        p[0] = c.Node('type', [], p[1])
    else:
        p[0] = c.Node('type', [p[1]])
Example #2
0
def p_term(p):
    '''term : identifier
            | LEFT_PARENS operation args RIGHT_PARENS'''
    if (len(p) == 2) :
        p[0] = c.Node('term', [p[1]])
    else :
        p[0] = c.Node('term', [p[2], p[3]]) 
Example #3
0
def p_rhs(p): 
    '''rhs : BOOLEAN
           | uinteger_10
           | identifier 
           | LEFT_PARENS primitive rhs_args RIGHT_PARENS
           | LEFT_PARENS operation rhs_args RIGHT_PARENS'''
    if len(p) == 2: 
        p[0] = c.Node('rhs', [p[1]])
    else :
        p[0] = c.Node('rhs', [p[2], p[3]])
Example #4
0
def make_tray_edges():
    global tray_edges
    tray_edges = []
    for tray in range(inputs.TRAYS):
        for hole in range(inputs.HOLES):
            for t in range(inputs.HORIZON):
                # WITHOUT DIAGONAL EDGES #
                node_from = classes.Node('hole', tray, hole, t)
                node_to = classes.Node('hole', tray, hole, t + 1)
                edge = Edge(node_from, node_to,
                            get_bounds_per_edge(tray, t, plants_array.plants),
                            get_sizes_per_edge(tray, t, plants_array.plants))
                tray_edges.append(edge)
def make_tray_edges():
    number_tray_edges = 0
    global tray_edges
    tray_edges = []
    for modules_type in range(inputs.NB_TYPE_MODULE):
        for t in range(inputs.HORIZON):
            node_from = classes.Node('modules', modules_type, t)
            node_to = classes.Node('modules', modules_type, t + 1)
            edge = Edge(
                node_from, node_to,
                get_bounds_per_edge(modules_type, t, plants_array.plants),
                get_sizes_per_edge(modules_type, t, plants_array.plants))
            tray_edges.append(edge)
            number_tray_edges += 1
    print("number_tray_edges:", number_tray_edges)
Example #6
0
def p_equations(p): 
    '''equations : equation equations 
                 | empty'''
    if (len(p) == 2) :
        p[0] = p[1]
    else :
        p[0] = c.Node('equations', [p[1], p[2]])
Example #7
0
def p_primitive(p):
    '''primitive : NOT 
                 | SPECIAL_PRIMITIVE
                 | STAR
                 | PLUS
                 | MINUS'''
    p[0] = c.Node('primitive', [], p[1])
Example #8
0
def p_operation_spec2(p):
    '''operation_spec2 : ARROW type 
                       | arg_types ARROW type'''
    if len(p) == 3 :
        p[0] = p[2]
    else :
        p[0] = c.Node('operation-spec-args', [p[1], p[3]])
Example #9
0
def p_args(p):
    '''args : term args
            | empty'''
    if (len(p) == 2) :
        p[0] = p[1]
    else :
        p[0] = c.Node('args', [p[1], p[2]])
Example #10
0
def p_rhs_args(p): 
    '''rhs_args : rhs rhs_args 
                | empty'''
    if (len(p) == 2) :
        p[0] = p[1]
    else :
        p[0] = c.Node('rhs_args', [p[1], p[2]])
Example #11
0
    def get_nature(self):
        url = self.base_url + '[natural=*]'
        logging.info(url)
        root = self.get_data(url)
        #empty node dict
        nodes = {}
        natures = []

        for child in root:
            if child.tag == 'node':
                #nodes should be at the top
                geo = ndb.GeoPt(child.attrib['lat'], child.attrib['lon'])
                node = classes.Node(geo_point=geo)
                nodes.update({child.attrib["id"]: node})
            elif child.tag == 'way':
                way_nodes = []
                subname = ""
                subtype = ""
                for way_child in child:
                    # 					logging.info(child.tag)
                    if way_child.tag == 'nd':
                        #save node rederence in order
                        way_nodes.append(
                            copy.copy(nodes[way_child.attrib['ref']]))
# 						logging.info(nodes[child.attrib['ref']])

#this covers coastline, wetland, beach, etc etc
                    elif way_child.attrib['k'] == 'natural':
                        subtype = way_child.attrib['v']
                        logging.info(subtype)

                    #this covers parks (in-city)
                    elif way_child.attrib['k'] == 'leisure':
                        subtype = way_child.attrib['v']
                        logging.info(subtype)

                    elif way_child.attrib['k'] == 'name':
                        subname = way_child.attrib['v']
                        logging.info(subname)

                #grab the required nodes and create the entity
                for idx, way_node in enumerate(way_nodes):
                    way_node.idx = idx

                #create the nature
                nature = classes.Nature(nodes=way_nodes,
                                        subtype=subtype,
                                        subname=subname,
                                        parent=self.ghash_entity.key,
                                        id=child.attrib["id"])

                #push the nature onto the array
                natures.append(nature)

        #store the array in the db
        ndb.put_multi(natures)

        #return the count
        return len(natures)
Example #12
0
    def get_roads(self):
        url = self.base_url + '[highway=*]'
        logging.info(url)
        root = self.get_data(url)
        #empty node dict
        nodes = {}
        roads = []

        for child in root:
            if child.tag == 'node':
                #nodes should be at the top
                geo = ndb.GeoPt(child.attrib['lat'], child.attrib['lon'])
                node = classes.Node(geo_point=geo)
                nodes.update({child.attrib["id"]: node})
            elif child.tag == 'way':
                way_nodes = []
                subtype = ""
                subname = ""
                for way_child in child:
                    # 					logging.info(child.tag)
                    if way_child.tag == 'nd':
                        #save node rederence in order
                        way_nodes.append(
                            copy.copy(nodes[way_child.attrib['ref']]))
# 						logging.info(nodes[child.attrib['ref']])

                    elif way_child.attrib['k'] == 'highway':
                        subtype = way_child.attrib['v']
                        logging.info(subtype)
                    elif way_child.attrib['k'] == 'name':
                        subname = way_child.attrib['v']
                        logging.info(subname)

                #grab the required nodes and create the entity
                for idx, way_node in enumerate(way_nodes):
                    way_node.idx = idx

                #create the road
                road = classes.Road(nodes=way_nodes,
                                    subtype=subtype,
                                    subname=subname,
                                    parent=self.ghash_entity.key,
                                    id=child.attrib["id"])

                #push the road onto the array
                roads.append(road)

        #store the array in the db
        ndb.put_multi(roads)

        #return the count
        return len(roads)
Example #13
0
def make_transfer_edges():
    global transfer_edges
    transfer_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]

        for i in range(len(plant_type.transfers) - 1):

            from_ = plant_type.transfers[i]
            to_ = plant_type.transfers[i + 1]

            t = plant_type.transfer_days[i][1] + plant[1]
            for hole in range(inputs.HOLES):
                node_from = classes.Node('hole', from_, hole, t)

                for hole_to in range(inputs.HOLES):
                    node_to = classes.Node('hole', to_, hole_to, t + 1)
                    edge = Edge(
                        node_from, node_to,
                        get_bounds_per_edge(to_, t, plants_array.plants),
                        get_sizes_per_edge(to_, t, plants_array.plants))
                    transfer_edges.append(edge)
Example #14
0
def make_transfer_edges():
    number_transfer_edges = 0
    global transfer_edges
    transfer_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]

        for i in range(len(plant_type.transfers) - 1):

            from_ = plant_type.transfers[i]
            to_ = plant_type.transfers[i + 1]

            t = plant_type.transfer_days[i][1] + plant[1]

            node_from = classes.Node('module', from_, t)

            node_to = classes.Node('module', to_, t + 1)
            edge = Edge(node_from, node_to,
                        get_bounds_per_edge(to_, t, plants_array.plants),
                        get_sizes_per_edge(to_, t, plants_array.plants))
            transfer_edges.append(edge)
            number_transfer_edges += 1
Example #15
0
def make_source_edges():
    number_source_edges = 0
    global source_edges
    source_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]
        tray = plant_type.transfers[0]
        bounds = {p: 1 * (p == plant) for p in plants_array.plants}

        source = meta_nodes[get_plant_type(plant_type)][0]
        node_to = classes.Node('module', tray, plant[1])
        edge = Edge(source, node_to, bounds, 0)
        source_edges.append(edge)
        number_source_edges += 1
Example #16
0
def make_source_edges():
    global source_edges
    source_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]
        tray = plant_type.transfers[0]
        bounds = {p: 1 * (p == plant) for p in plants_array.plants}

        source = meta_nodes[get_plant_type(plant_type)][0]

        for hole in range(inputs.HOLES):
            node_to = classes.Node('hole', tray, hole, plant[1])
            edge = Edge(source, node_to, bounds, 0)
            source_edges.append(edge)
Example #17
0
def generate_successors(node):
    print "\n\n\n"

    attr_list = list(node.attribute_list)

    if len(attr_list) == 0 or m.pure_check(node.data, class_attribute):
        leaf_label = m.pure_check(node.data, class_attribute)
        if not leaf_label:
            leaf_label = random.choice(attribute_label_set[class_attribute])
        print "-------Leaf 노드입니다.-------"
        node.label = leaf_label
        # 데이터가 있는 경우와 없는 경우 구분
        if len(node.data) != 0:
            for data in node.data:
                print data
                print "라벨은 " + leaf_label

        else:
            print "데이터가 없으므로 랜덤으로 배정합니다."
            print "라벨은 " + leaf_label
        print "---------------------------"
        return node
    else:
        # 최적의 attribute값을 찾는 로직 필요.
        selected_attribute = m.splitting_criteria_decision(
            node.data, attr_list, class_attribute)
        # selected_attribute = random.choice(attr_list)

        # 현재 노드의 분류 기준 세팅
        node.set_current_node_criteria(selected_attribute)
        print "노드 분류 기준 " + node.classifying_attribute
        print "남은 분류 기준 " + str(
            attr_list) + "중에 " + selected_attribute + " 선택!"
        # 해당 attribute의 라벨 종류를 가져온다.
        labels_of_selected_attribute = attribute_label_set[selected_attribute]

        print '해당 attribtute의 라벨 종류 가져오기'
        print labels_of_selected_attribute

        for label in labels_of_selected_attribute:
            data = m.filter(node.data, selected_attribute, label)
            new_node = classes.Node(attr_list, selected_attribute, data)
            print "분류 기준이 " + selected_attribute + "이고 그 값이 " + label + "인 데이터 노드 생성"
            if generate_successors(new_node):
                node.children[label] = new_node
        print 'node.children'
        print node.children
    return node
Example #18
0
def make_sink_edges():
    global sink_edges
    sink_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]
        size_tray = len(plant_type.transfers)
        tray = plant_type.transfers[size_tray - 1]
        bounds = {p: 1 * (p == plant) for p in plants_array.plants}

        sink = meta_nodes[get_plant_type(plant_type)][1]

        for hole in range(inputs.HOLES):
            node_from = classes.Node('hole', tray, hole,
                                     plant[1] + plant_type.total_days)
            edge = Edge(node_from, sink, bounds, 0)
            sink_edges.append(edge)
Example #19
0
def make_sink_edges():
    number_sink_edges = 0
    global sink_edges
    sink_edges = []
    for plant in plants_array.plants:
        plant_type = plant[0]
        size_tray = len(plant_type.transfers)
        tray = plant_type.transfers[size_tray - 1]
        bounds = {p: 1 * (p == plant) for p in plants_array.plants}

        sink = meta_nodes[get_plant_type(plant_type)][1]

        node_from = classes.Node('module', tray,
                                 plant[1] + plant_type.total_days)
        edge = Edge(node_from, sink, bounds, 0)
        sink_edges.append(edge)
        number_sink_edges += 1
def make_source_edges():  
	number_source_edges  = 0
	global source_edges            
	source_edges = []
	for plant in plants_array.plants:
		plant_type = plant[0]
		module_type = plant_type.transfers[0]
		bounds = {p: 1*(p == plant) for p in plants_array.plants}

		source = meta_nodes[get_plant_type(plant_type)][0]

		for module_number in range(inputs.MODULES[module_type]):
			node_to = classes.Node('module', module_type, module_number, plant[1])
			edge = Edge(source, node_to, bounds, 0)
			source_edges.append(edge)
			number_source_edges +=1
	print("number_source_edges:", number_source_edges)	
def make_sink_edges():
	number_sink_edges = 0    
	global sink_edges  
	sink_edges = []
	for plant in plants_array.plants:
		plant_type = plant[0]
		size_module_type = len(plant_type.transfers)
		module_type = plant_type.transfers[size_module_type - 1]
		bounds = {p: 1*(p == plant) for p in plants_array.plants}

		sink = meta_nodes[get_plant_type(plant_type)][1]

		for module_number in range(inputs.MODULES[module_type]):
			node_from = classes.Node('module', module_type, module_number,
							 plant[1] + plant_type.total_days)
			edge = Edge(node_from, sink, bounds, 0)
			sink_edges.append(edge)
			number_sink_edges += 1
	print("number_sink_edges:", number_sink_edges)	
Example #22
0
def create_AGDS(filename):

    [data, columns] = dataParser.read_xls_iris(filename)

    nr_samples = data.shape[0]
    nr_attributes = data.shape[1]

    # Create objects
    samples = []
    for sample_nr in range(nr_samples):
        samples.append(classes.Sample(name=str(sample_nr), nodes=[]))

    # Create attributes and nodes
    attributes = []
    for category in range(nr_attributes):
        nodes = []
        unique_values = np.unique(data[:, category])
        for node in range(len(unique_values)):
            # New node
            nodes.append(
                classes.Node(attribute=None,
                             value=unique_values[node],
                             samples=[]))
            # Indexes of objects whose value matches this node
            sample_indexes = np.where(data[:,
                                           category] == unique_values[node])[0]
            for sample in range(len(sample_indexes)):
                # Adding the objects to the node
                nodes[-1].add_objects(samples[sample_indexes[sample]])
                # Adding the node to the object
                samples[sample_indexes[sample]].add_nodes(nodes[-1])
        # New attribute
        attributes.append(
            classes.Attribute(name=columns[category], nodes=nodes))
        for i in range(len(nodes)):
            nodes[i].attribute = attributes[-1]

    return classes.Tree(tree_type='AGDS',
                        attributes=attributes,
                        samples=samples)
Example #23
0
def create_node(ws, data):
    node = classes.Node(ws, data["payload"]["name"])
    nodes[node.id] = node
    return node
Example #24
0
def beFGS(problem):
    """Searches the nodes with the lowest f scores first.
    The function f(node) is the heuristic estimate to the goal in this case
    """
    node = cla.Node(problem.initialState, None, None)

    frontier = []
    frontier.append(node)

    #explored set is an unordered collection with no duplicate elements.
    explored = set()

    while frontier:
        node = frontier.pop()
        if problem.checkGoal(
                node.state):  # return the end state if goal is reached
            return node
        explored.add(node.stringBoard)  # otherwise add it to the explored set
        for child in node.expand(problem):
            #if child.stringBoard not in explored and child not in frontier: # add child to frontier if not there or in explored
            if child.stringBoard not in explored:

                #here we loop through frontier and look for the board
                foundState = False  #this will stop iterating through the frontier
                currentState = None  #this is a copy of the current node
                iterFrontier = 0  #this saves where the node is in the frontier so it can be deleted later
                for frontNode in frontier:

                    if (frontNode.stringBoard == child.stringBoard):
                        #print("Found the board in frontier")
                        #print("frontNode.stringboard:", frontNode.stringBoard)
                        #print("iterFrontier:", iterFrontier)
                        foundState = True
                        currentState = frontNode
                        break
                    iterFrontier += 1

                #if the board is not in the frontier
                if foundState == False:

                    #f applies the heuristic + pathcost and adds this value to the node class. f(x) = g(x) + h(x)
                    problem.f(child)
                    frontier.append(child)
                    frontier.sort(
                        key=lambda x: x.fValue, reverse=True
                    )  #this should sort the list in order of small to large heuristic value

                else:  # if the state was already in the frontier, then check the heuristic value
                    #print("Already in the frontier, looking to change val")

                    if child.fValue < currentState.fValue:
                        #print('better option found')
                        #del frontier[currentState] #? does not delete this node. need to iterate through frontier
                        del frontier[
                            iterFrontier]  #proper way of deleting the node from the frontier
                        frontier.append(child)
                        frontier.sort(
                            key=lambda x: x.fValue, reverse=True
                        )  #this should sort the list in order of small to large heuristic value

            # if already explored do nothing
    return None
Example #25
0
def p_arg_types(p):
    '''arg_types : type arg_types2'''
    p[0] = c.Node('arg-types', [p[1], p[2]])
Example #26
0
def p_operation(p):
    'operation : identifier'
    p[0] = c.Node('operation', [p[1]])
Example #27
0
def p_operation_spec(p):
    '''operation_spec : operation COLON operation_spec2'''
    p[0] = c.Node('operation-spec', [p[1], p[3]])
Example #28
0
def p_operation_specs(p):
    '''operation_specs : operation_spec operation_specs2'''
    p[0] = c.Node('operation-specs', [p[1], p[2]])
Example #29
0
def p_signature(p): 
    'signature : ADT typename operation_specs'
    p[0] = c.Node('signature', [p[2], p[3]])
Example #30
0
def p_signatures(p): 
    '''signatures : signature signatures2'''
    p[0] = c.Node('signatures', [p[1], p[2]])