问题描述
我开发了一种结合随机搜索和模拟退火的算法来解决电影场景调度问题,该问题包括提出最佳拍摄序列以最小化成本(演员每次拍摄的工资),考虑到您有一个最大值您每天(每个会话)可以拍摄的镜头数。
现在,我需要找出所提出算法的复杂度。
该算法执行以下操作。
def search_and_sim_annealing(costs,max_takes,temp,N,reps: int=3):
best_solution = []
best_cost = 100
for rep in range(reps):
solution = random_search(costs,N)
SA_sol = Simulated_Annealing(solution,costs,temp)
cost_SA = calculate_cost(SA_sol,costs)
if cost_SA < best_cost:
best_solution = SA_sol
best_cost = cost_SA
return best_solution
- 使用 random.shuffle (O(n)) 生成随机解决方案。
- 计算解决方案的成本 (O(n*m))
- 重复 N 次以生成 N 个随机解决方案,计算每个解决方案的成本。
- 保存启动模拟退火算法的最佳解决方案。
据我所知,直到这个函数,复杂度是 O(N.n.n.m)=O(N.m.n^2)
第二个功能(模拟退火)
def generate_neighbor(solution):
i,j = sorted(random.sample( range(1,len(solution)),2))
sol_list = list(solution)
vecina = tuple(sol_list[:i] + [sol_list[j]] + sol_list[i+1:j] + [sol_list[i]] + sol_list[j+1:])
return neighbor
所以它会是 O(R.n.m.n.m.(n^2).(log I))... O(R.n^4.m^2.log I)
如果我们将这两个连接起来,它将等于 O(Nmn^2).O(Rn^4.m^2.log I)...但是我不确定如何去做。 .. 我从来没有为这样的算法做过这种类型的微积分。
这个算法的想法是让复杂度明显低于n!,这是我之前编码的贪心算法的复杂度。
感谢您的见解。
模拟退火:
def simulated_annealing(solution,temp):
ref_solution = solution
ref_cost = calculate_cost(ref_solution,costs)
best_solution = []
best_cost = 100
K=0
while temp > .0001:
K+=1
neighbor = generate_neighbor(ref_solution)
n_cost = calculate_cost(neighbor,costs)
if n_cost < ref_cost:
best_solution = neighbor
best_cost = n_cost
if n_cost < ref_cost or prob(temp,abs(ref_cost - n_cost)):
ref_solution = copy.deepcopy(neighbor)
ref_cost = n_cost
temp = lower_temp(temp)
return best_solution
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)