我试图通过添加多维“大小”(demand)和“total\ size\ max”来详细说明任务大小示例的赋值。你知道吗
解决方案似乎决定只将所有资源分配给一个工人,尽管其他工人也可以使用。run将所有内容分配给worker(机器18)时的结果。你知道吗
样本输出:
Machine 18 is assigned to produce Component 0 with minimum Cycle_Time = 10000000
Machine 18 is assigned to produce Component 1 with minimum Cycle_Time = 10000000
Machine 18 is assigned to produce Component 2 with minimum Cycle_Time = 10000000
Machine 18 is assigned to produce Component 3 with minimum Cycle_Time = 10000000
Machine 18 is assigned to produce Component 4 with minimum Cycle_Time = 10000000
Machine 18 is assigned to produce Component 5 with minimum Cycle_Time = 10000000
代码:
# -*- coding: utf-8 -*-
from __future__ import print_function
from ortools.sat.python import cp_model
import time
import numpy as np
def main():
model = cp_model.CpModel()
start = time.time()
# cost = machines on rows and components on columns with least cycle_time
cost = [[7.995722268,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.995722268,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.995722268,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.995722268,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.764712938,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.64179678,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.764712938,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,26.10110138,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,26.10110138,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,24.79202174,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,27.72432227,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,29.63946277,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,29.4907994,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,24.79202174,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,27.72432227,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,29.63946277,10000000,10000000,10000000],
[10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.271052178,10000000,10000000,10000000,10000000,10000000,10000000],
[8.213437897,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.213437897,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.213437897,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.213437897,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.372568825,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.282863934,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,15.49746661,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,14.36944353,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,14.95278777,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,13.33333333,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,13.33333333,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,6.194286893,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,14.56521739,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,17.57157641,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.194286893,10000000,14.56521739,10000000,10000000,10000000,10000000],
[8.076237035,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.076237035,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.076237035,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.076237035,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.400797794,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[8.019304639,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.019304639,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.019304639,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.019304639,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.496583613,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,3.778990587,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,11.51228733,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,11.06301248,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,4.492667454,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,5.512785364,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358,10000000,10000000,10000000,10000000,10000000,10000000,10000000,1.780837358,10000000,1.780837358],
[10000000,10000000,10000000,10000000,10000000,7.755011055,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.755011055,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.755011055,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,7.755011055,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,25.45422456,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,29.69460764,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,32.00169225,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,25.45422456,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,29.69460764,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,10000000,10000000,10000000,10000000,10000000,28.19319991,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,27.13193117,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,26.59704717,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,28.19319991,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,27.13193117,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,21.5723175,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,8.455696203,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000],
[10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000,6.776314217,10000000,10000000,10000000,10000000,10000000,10000000,10000000,10000000]
]
#costList = [round(x) for x in cost]
costlist = np.round(cost).astype(int).tolist()
# demand for each component
demand = [28,28,28,28,28,28,28,28,28,56,28,30,30,30,30,30,30,30,30,30,60,176,176,176,176,176,176,176,176,176,352,194,194,194,194,194,194,194,194,194,388,56,56,56,56,56,56,56,56,56,112,56,149,149,149,149,149,149,149,149,149,298,911,911,911,911,911,911,911,911,911,1822]
# convert to numpy array for division
arr = np.array(cost)
# total available hours
available_hrs = 2592000
total_size_max = available_hrs / arr
total_size_max = total_size_max.astype(int)
num_workers = len(cost)
num_tasks = len(cost[1])
# Variables
x = []
for i in range(num_workers):
t = []
for j in range(num_tasks):
t.append(model.NewIntVar(0, 1, "x[%i,%i]" % (i, j)))
x.append(t)
x_array = [x[i][j] for i in range(num_workers) for j in range(num_tasks)]
# Constraints
# Each component is assigned to at least one machine.
[model.Add(sum(x[i][j] for i in range(num_workers)) >= 1)
for j in range(num_tasks)]
# Total demand of component for each machine is at most total_size_max(available_hrs/cycle_time).
[model.Add(sum(demand[j] * x[i][j] for j in range(num_tasks)) <= total_size_max[i][j])
for i in range(num_workers)]
model.Minimize(sum([np.dot(x_row, cost_row) for (x_row, cost_row) in zip(x, costlist)]))
solver = cp_model.CpSolver()
status = solver.Solve(model)
if status == cp_model.OPTIMAL:
print('Minimum cost = %i' % solver.ObjectiveValue())
print()
for i in range(num_workers):
for j in range(num_tasks):
if solver.Value(x[i][j]) == 1:
print('Machine ', i, ' is assigned to produce Component ', j, ' with minimum Cycle_Time = ', cost[i][j])
print()
end = time.time()
print("Time = ", round(end - start, 4), "seconds")
if __name__ == '__main__':
main()
我从示例中获取了这个,并根据需要调整了输入数据。有人能帮忙解决这个问题吗?你知道吗
期望的结果是根据需求分配时间最短的机器
以下是完整答案:
我添加了成本缩放以提高精度
以下是输出:
这将在https://github.com/google/or-tools/issues/1578中讨论
如有交叉,请注明。你知道吗
谢谢
相关问题 更多 >
编程相关推荐