from mip import Model, xsum, maximize, INTEGER
def optModel(m, n, g, h, a, b):
model = Model("machine_load_distribution")
x1 = [model.add_var(var_type=INTEGER) for i in range(n)] #高负荷运行的机器数量
x2 = [model.add_var(var_type=INTEGER) for i in range(n)] #低负荷运行的机器数量
model.objective = maximize(xsum(x1[i] * g + x2[i] * h for i in range(n)))
model += x1[0] + x2[0] == m
for i in range(1,n):
model += x1[i] + x2[i] == x1[i-1] * a + x2[i-1] * b
model.verbose = 0
model.optimize()
print(model.objective_value)
lis1 = []
lis2 = []
for i in range(n):
lis1.append(x1[i].x)
lis2.append(x2[i].x)
print(lis1)
print(lis2)
if __name__ == '__main__':
m, n, g, h, a, b = 1000, 5, 8, 5, 0.7, 0.9
optModel(m, n, g, h, a, b)
动态规划--机器负荷分配问题
最新推荐文章于 2022-03-18 20:33:00 发布