请帮助创建一个具有以下条件的 initial_solution 变量:
结构
population_list = {"LHS":[], "RHS": []}
字典元素数= population_size = 20
对于每个population_list
元素"LHS"
和"RHS"
元素。
对于"LHS"
,有两个job_count = 10
元素,每个元素的长度都精确列出一个列表:
max_sublot = [3, 5, 7, 6, 4, 2, 7, 9, 3, 5]
它的值是一个随机值[0,1),四舍五入到两位小数。
因为"RHS"
总共有max_sublot * mc_op
个元素。
max_sublot = [3, 5, 7, 6, 4, 2, 7, 9, 3, 5]
mc_op = [6, 14, 8, 5, 6, 9, 4, 6, 7, 2]
每个元素长度= 4,根据random of range job_count
的每个值,1值为max_sublot
,根据每个值operation_count = 10
的2为随机数,根据mc_op
的范围为3的随机数,根据每个的长度为4 import numpy as np
population_size = 20
job_count = 10
operation_count = 10
max_sublot = [3, 5, 7, 6, 4, 2, 7, 9, 3, 5]
mc_op = [6, 14, 8, 5, 6, 9, 4, 6, 7, 2]
class Population_list(object):
def __init__(self, LHS, RHS):
self.LHS = LHS
self.RHS = RHS
population_list = {"LHS":[], "RHS": []}
for i in range (population_size):
for j in range(job_count):
for s in max_sublot:
lhs_random_num = list(np.random.random())
population_list.update("LHS")
print(population_list)
git rm --cached `git ls-files -i --exclude-from=.gitignore`
答案 0 :(得分:0)
我认为您需要这样的东西
population_size = 20
job_count = 10
operation_count = 10
max_sublot = [3, 5, 7, 6, 4, 2, 7, 9, 3, 5]
mc_op = [6, 14, 8, 5, 6, 9, 4, 6, 7, 2]
import numpy as np
def gen_population(population_size, max_sublot, mc_op, job_count):
return tuple({'LHS': [gen_lhs(length) for length in max_sublot],
'RHS': gen_rhs(np.dot(max_sublot, mc_op), job_count, max_sublot, 10, mc_op)} for _ in range(population_size))
def gen_lhs(length):
return [round(np.random.uniform(0,1),2) for _ in range(length)]
def gen_rhs(length, job_count, max_sublot, operation_count, mc_op):
ret = []
for i in range(length):
new = []
new.append(np.random.randint(job_count))
new.append(np.random.choice(max_sublot))
new.append(np.random.randint(operation_count))
new.append(np.random.choice(mc_op))
ret.append(new)
return ret
gen_population(population_size, max_sublot, mc_op, job_count)