本文整理汇总了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)
示例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)
示例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
示例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')
示例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