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


Python Maze.from_file方法代码示例

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


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

示例1: __init__

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import from_file [as 别名]
    def __init__(self, filename='../data/gc-maze.txt', refine=False):
        self.maze = Maze.from_file(filename)
        self.original_start = tuple(self.maze.start)
        self.original_end = tuple(self.maze.end)

        self.cachefile = filename + '.tsp-results.pickle'
        self.refine = refine
        self.do_reconnaissance = 10000

        self.maze.load_products(filename='../data/gc-products.txt')
        self.num = self.maze.product_count
        self.products = self.maze.products_dict

        # initialize array for the distances.
        if os.path.exists(self.cachefile):
            print 'Loading from cachefile: %s' % self.cachefile
            self.load_cache()
        else:
            size = len(self.locations())
            self.results = map(list, [[TSPMaze.EMPTY] * size] * size)
开发者ID:jieter,项目名称:computational-intelligence,代码行数:22,代码来源:tspmaze.py

示例2: wait

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import from_file [as 别名]
        if label is not None:
            self.ax2.set_title(label)

        pher = self.ax2.imshow(
            self.maze.pheromone,
            extent=extent,
            interpolation='nearest'
        )
        if self.cbar is None:
            self.cbar = self.fig.colorbar(pher, shrink=.75)

        self.cbar.on_mappable_changed(pher)

        plt.draw()
        plt.axis('off')

    def wait(self):
        print 'Waiting for image to be closed...'
        plt.ioff()
        plt.show()

    def save(self, filename):
        plt.savefig(os.path.join('output', filename))

if __name__ == '__main__':
    from maze import Maze

    maze = Maze.from_file('../data/easy-maze.txt')
    print maze
    Visualizer(maze)
开发者ID:jieter,项目名称:computational-intelligence,代码行数:32,代码来源:visualize.py

示例3: Maze

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import from_file [as 别名]
from maze import Maze
import sys

"""
For reference:
DIRECTION
0 - Above
1 - Right
2 - Down
3 - Left
"""


# LET'S DO IT!
maze = Maze()
maze.from_file(sys.argv[1])

current = maze.start

solved = False
while solved is False:
	# Scan around us
	around = maze.scan(current)
	
	# First, let's see if we're finished with the maze
	try:
		finish = around.index('F')
		# Mark off the last breadcrumb
		maze.set(current, '.')
		solved = True
		break
开发者ID:stevenleeg,项目名称:Maze-Solver,代码行数:33,代码来源:solver.py

示例4: dict

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import from_file [as 别名]
            ant_count=20,
        ),
        'test2': dict(
            Q=100,
            iterations=20,
        )
    }

    if len(sys.argv) > 1:
        maze_name = sys.argv[1]
    else:
        maze_name = 'test2'

    maze = test_mazes(maze_name)
    if maze is None:
        maze = Maze.from_file(os.path.join('..', 'data', '%s-maze.txt' % maze_name), name=maze_name)

    print '"%s"' % maze_name
    if maze_name in settings:
        settings = settings[maze_name]
    else:
        settings = dict()

    print 'Maze "%s" (%d, %d)' % (maze.name, maze.width, maze.height)
    print 'start:', maze.start, 'end:', maze.end

    start_time = time.time()

    aco = ACO(maze, **settings)
    aco.reconnaissance()
    aco.visualizer.update('Maze after reconnaissance')
开发者ID:jieter,项目名称:computational-intelligence,代码行数:33,代码来源:aco.py

示例5: parameter_compare

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import from_file [as 别名]
def parameter_compare(maze_name, vary_parameter, compute=True):
    filename = '../data/%s-maze.txt' % maze_name
    outputfile = 'compare-graphs/%s/param-compare-%%s.pickle' % maze_name

    iterations = 10

    if compute:
        start_time = time.time()
        print 'Running ACO on %s maze %d times for each %d different values of %s: ' % (
            maze_name,
            iterations,
            len(parameters[vary_parameter]),
            vary_parameter
        )
        print parameters[vary_parameter]

        results = []
        for param in parameters[vary_parameter]:
            print '%s = %s: ' % (vary_parameter, str(param)),

            param_result = dict(
                best_trail=[],
                best_at_iteration=[],
                running_time=[]
            )
            for i in range(iterations):
                settings = default_settings.copy()
                settings.update({
                    vary_parameter: param
                })
                aco_start = time.time()
                maze = Maze.from_file(filename)
                aco = ACO(maze=maze, **settings)
                best_ant = aco.run()
                print len(best_ant.trail),

                param_result['best_trail'].append(len(best_ant.trail))
                param_result['best_at_iteration'].append(aco.get_first_iteration_with_best_trail())
                param_result['running_time'].append(time.time() - aco_start)

            results.append(param_result)
            print

        print '%d runs done in %0.2fs' % (
            iterations * len(parameters[vary_parameter]),
            start_time - time.time()
        )
        with open(outputfile % vary_parameter, 'w') as f:
            pickle.dump(results, f)
    else:
        results = pickle.load(open(outputfile % vary_parameter))

    for metric, labely in (
            ('best_trail', 'Trail length of best trail'),
            ('best_at_iteration', 'First iteration best occurs'),
            ('running_time', 'Running time of ACO'), ):

        make_boxplot(
            basename='compare-graphs/' + maze_name + '/aco-compare-' + vary_parameter + '-' + metric,
            data=[x[metric] for x in results],
            plot_title='ACO on maze %s (%d times)' % (maze_name, iterations),
            xvalues=parameters[vary_parameter],
            labelx='Values for %s' % vary_parameter,
            labely=labely
        )

    return results
开发者ID:jieter,项目名称:computational-intelligence,代码行数:69,代码来源:aco-parameter-compare.py


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