当前位置: 首页>>代码示例>>Python>>正文


Python Graph.addNode方法代码示例

本文整理汇总了Python中Graph.Graph.addNode方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.addNode方法的具体用法?Python Graph.addNode怎么用?Python Graph.addNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph.Graph的用法示例。


在下文中一共展示了Graph.addNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parseGraphFromFile

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addNode [as 别名]
def parseGraphFromFile(fileName):
    file = open(fileName, 'r')
    line = file.readline()
    
    graph = Graph()
    # take out any extra whitespace, such as 1   $  2  , 3...
    line = re.sub("\s*", "", line)
    # partition returns a 3-tuple of the string before the
    # specified delimiter, the delimiter, and the string after
    # the delimiter
    parts = line.partition('$')
    # the first part contains the list of nodes
    # add each node to the graph
    numNodes = parts[0]
    for i in range(int(numNodes)):
        graph.addNode()

    # each edge has the form node1, node2, cost
    edgeList = parts[2].split(';')
    for edge in edgeList:
        n1, n2, cost = edge.split(',')
        n1 = int(n1)
        n2 = int(n2)
        cost = int(cost)
        graph.addEdge(n1, n2, cost)
        
    return graph
开发者ID:carolinedanzi,项目名称:CSE464_Graph_Algorithms,代码行数:29,代码来源:Main.py

示例2: MapPoint

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addNode [as 别名]
if __name__ == '__main__':
    # Start and goal positions of the robot
    start_position = MapPoint(6, 1)  # Column (x) 6 and row (y) 1
    goal_position = MapPoint(1, 6)  # Column (x) 1 and row (y) 6

    # Create graph with associated grid map
    map_graph = Graph('map.png', goal_position)

    # Create root node at the given position
    # map_graph - graph this node belongs to
    # None - no parent
    # 0 - no cost
    # heuristic function
    # start_position
    # None - no action needed to reach this node
    root = Node(map_graph, None, 0, heuristic, start_position, None)
    map_graph.addNode(root, True)

    # Perform the map search and, if successful, show the resulting path in the
    # terminal output as text
    if(doSearch(map_graph, root, goal_position, SearchMethods.A_STAR)):
        map_graph.showGraph()
        map_graph.showPath(goal_position)
    else:
        eprint('There is no solution for the specified problem!')

    # We're done, lets leave successfully, after pressing any key
    # Keep figures open until the user presses 'q' to quit. This is a blocking
    #  statement
    plt.show()
开发者ID:ipleiria-robotics,项目名称:adv_robotics,代码行数:32,代码来源:tw06.py

示例3: formSemanticNet

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addNode [as 别名]
    def formSemanticNet(self, problem):
        graph = Graph()
        inCard = {}
        pp = pprint.PrettyPrinter(indent=4)

        #populate all inCard[obects] = figure, before parsing other things
        # example inCards[b] = A
        for figName, figure in problem.figures.iteritems():
            # print "Figure: "+figName
            # pp.pprint(figure.objects)

            for objName, obj in figure.objects.iteritems():
                inCard[obj.name] = figure.name
                #pp.pprint(obj.attributes)

        # print "inCards are: "
        # pp.pprint(inCard)
        graph.inCard = inCard

        print "done building inCards. Initiating SemNet construction..."
        # now we can identify which attribute is an attribute and which attribute is a relation
        for figName, figure in problem.figures.iteritems():
            # print "Parsing Figure: "+figName
            # print figure.visualFilename
            # pp.pprint(figure.objects)

            card = Card(figure.name)
            for objName, obj in figure.objects.iteritems():
                properties = {}
                properties['inCard'] = figure.name # add the additional property to identify the parent figure
                relations = {}
                #clientForMigration.php

                #print "Object attributes:"
                #pprint.pprint(obj.attributes)
                for attrib, val in obj.attributes.iteritems():
                    vals = val.split(",")
                    isNode = True
                    #print "Adding "+attrib+"==>"+val
                    for v in vals:
                        if v in inCard:
                            # relations are saved in the format: relation['inside'] = 'b',
                            # where inside is the relation and 'b; is the target node
                            if attrib in relations:
                                relations[attrib].append(v)
                            else:
                                relations[attrib] = [v]
                        else:
                            isNode = False
                            break

                    if not isNode:
                        # properties are saved in the format: properties['filled'] = 'yes'
                        properties[attrib] = val

                # got all relations and properties of the object. form the node now.
                graph.addNode(obj.name, relations, properties)
                card.addNode(graph.getNode(obj.name))
            # end of for
            graph.addCard(card)

        return graph
开发者ID:hay-wire,项目名称:ra1,代码行数:64,代码来源:Agent.py


注:本文中的Graph.Graph.addNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。