本文整理汇总了Python中problem.Problem.state方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.state方法的具体用法?Python Problem.state怎么用?Python Problem.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类problem.Problem
的用法示例。
在下文中一共展示了Problem.state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bruteforce_tsp
# 需要导入模块: from problem import Problem [as 别名]
# 或者: from problem.Problem import state [as 别名]
def bruteforce_tsp(announce_every=500000):
cities = {
'Holmesville': (31.7036111, -82.3208333),
'Jatipasir': (-8.2509, 113.9975),
'Tapalinna': (-2.923, 119.1626),
'Sahout el Ma': (16.9166667, -15.1666667),
'Isanganaka': (-0.683333, 24.083333),
'El Yerbanis': (29.45, -108.6),
'Gun-ob': (9.6289, 124.0517),
'Chak Seventy-five ML': (31.345362, 71.123454),
'Bakous': (13.7363889, -16.6080556),
'Metkow Maly': (50.05, 19.4)
}
problem_data = dict(
cities=cities,
start_city="Bakous",
updates_enabled=True
)
start = time.time()
t = Problem(cities.keys(), **problem_data)
fittest = [t.state, t.energy()]
announce_count = 0
for state in itertools.permutations(t.cities.keys()):
announce_count += 1
t.state = state
energy = t.energy()
if energy < fittest[1]:
fittest = [state, energy]
if announce_count:
if announce_count == announce_every:
print(fittest[1])
announce_count = 0
print("Best fitness: {}".format(fittest[1]))
print("Took {:.2f}s".format(time.time() - start))
return fittest[1]