Demo entry 6787658

代码示例

   

Submitted by anonymous on Apr 14, 2019 at 15:50
Language: Python. Code size: 13.1 kB.

"""
解决滑橇,零件调度问题
2019 4 14
"""


products = {
    '上格栅A': {'铱银': 135},
    '上格栅B': {'铱银': 150},
    '中间扰流板A': {'光耀蓝': 39, '曜岩黑': 72, '极地白': 149, '米兰银': 76},
    '前保A': {'光耀蓝': 249, '宝石蓝': 80, '曜岩黑': 212, '极地白': 885, '米兰银': 84, '铱银': 40},
    '前保B': {'宝石蓝': 27, '极地白': 28, '铱银': 24},
    '前保C': {'光耀蓝': 12, '宝石蓝': 3, '曜岩黑': 424, '钻石白': 78},
    '前保D': {'宝石蓝': 15, '曜岩黑': 992},
    '前保E': {'光耀蓝': 115, '宝石红': 99, '曜岩黑': 373, '米兰银': 75, '钻石白': 475},
    '前保F': {'光耀蓝': 128, '极地白': 961},
    '前保G': {'宇宙黑': 43, '米兰银': 20, '钻石白': 121},
    '后保A': {'光耀蓝': 174, '宝石红': 372, '宝石蓝': 3, '极地白': 565, '铱银': 35},
    '后保B': {'米兰银': 75},
    '后保C': {'宝石蓝': 85, '曜岩黑': 808, '钻石白': 87},
    '后保D': {'曜岩黑': 3, '铱银': 11},
    '后保E': {'极地白': 6},
    '后保F': {'光耀蓝': 115, '宝石红': 101, '曜岩黑': 278, '米兰银': 41, '钻石白': 323},
    '后保G': {'米兰银': 79, '钻石白': 427},
    '外壳A': {'光耀蓝': 13, '宝石红': 7, '宝石蓝':	18, '极地白': 87, '牛仔蓝': 6, '米兰银': 3},
    '轮口装饰件A': {'光耀蓝': 51, '宝石蓝': 6, '极地白': 168},
    '轮口装饰件B': {'牛仔蓝': 4, '钻石白': 26},
    '门槛A': {'光耀蓝': 204, '宝石红': 351, '宝石蓝':	86, '曜岩黑': 47, '极地白': 505, '米兰银': 83, '铱银': 10},
    '门槛B': {'宝石蓝': 94, '曜岩黑': 579, '钻石白': 177},
    '门槛C': {'曜岩黑': 276},
    '门槛D': {'极地白': 468},
    '门槛E': {'米兰银': 12},
    '门槛装饰条A': {'铱银': 299},
    '雷达支架A':	{'宝石红': 5},
    '雷达支架B': {'宝石蓝': 12, '极地白':	32},
    '雷达支架C':	{'钻石白': 26},
    '雷达支架D': {'曜岩黑': 4, '米兰银': 3},
    '雷达支架E': {'牛仔蓝': 5, '钻石白': 6}
    }
number = {
      '上格栅A': 34,
      '上格栅B': 39,
      '中间扰流板A': 95,
      '前保A': 400,
      '前保B': 28,
      '前保C': 141,
      '前保D': 255,
      '前保E': 297,
      '前保F': 280,
      '前保G': 51,
      '后保A': 304,
      '后保B': 21,
      '后保C': 251,
      '后保D': 11,
      '后保E': 3,
      '后保F': 225,
      '后保G': 131,
      '外壳A': 52,
      '轮口装饰件A': 63,
      '轮口装饰件B': 15,
      '门槛A': 341,
      '门槛B': 219,
      '门槛C': 69,
      '门槛D': 118,
      '门槛E': 3,
      '门槛装饰条A': 76,
      '雷达支架A': 5,
      '雷达支架B': 16,
      '雷达支架C': 9,
      '雷达支架D': 10,
      '雷达支架E': 11
        }
the_products = {
    '上格栅A': {'铱银': 135},
    '上格栅B': {'铱银': 150},
    '中间扰流板A': {'光耀蓝': 39, '曜岩黑': 72, '极地白': 149, '米兰银': 76},
    '前保A': {'光耀蓝': 249, '宝石蓝': 80, '曜岩黑': 212, '极地白': 885, '米兰银': 84, '铱银': 40},
    '前保B': {'宝石蓝': 27, '极地白': 28, '铱银': 24},
    '前保C': {'光耀蓝': 12, '宝石蓝': 3, '曜岩黑': 424, '钻石白': 78},
    '前保D': {'宝石蓝': 15, '曜岩黑': 992},
    '前保E': {'光耀蓝': 115, '宝石红': 99, '曜岩黑': 373, '米兰银': 75, '钻石白': 475},
    '前保F': {'光耀蓝': 128, '极地白': 961},
    '前保G': {'宇宙黑': 43, '米兰银': 20, '钻石白': 121},
    '后保A': {'光耀蓝': 174, '宝石红': 372, '宝石蓝': 3, '极地白': 565, '铱银': 35},
    '后保B': {'米兰银': 75},
    '后保C': {'宝石蓝': 85, '曜岩黑': 808, '钻石白': 87},
    '后保D': {'曜岩黑': 3, '铱银': 11},
    '后保E': {'极地白': 6},
    '后保F': {'光耀蓝': 115, '宝石红': 101, '曜岩黑': 278, '米兰银': 41, '钻石白': 323},
    '后保G': {'米兰银': 79, '钻石白': 427},
    '外壳A': {'光耀蓝': 13, '宝石红': 7, '宝石蓝':	18, '极地白': 87, '牛仔蓝': 6, '米兰银': 3},
    '轮口装饰件A': {'光耀蓝': 51, '宝石蓝': 6, '极地白': 168},
    '轮口装饰件B': {'牛仔蓝': 4, '钻石白': 26},
    '门槛A': {'光耀蓝': 204, '宝石红': 351, '宝石蓝':	86, '曜岩黑': 47, '极地白': 505, '米兰银': 83, '铱银': 10},
    '门槛B': {'宝石蓝': 94, '曜岩黑': 579, '钻石白': 177},
    '门槛C': {'曜岩黑': 276},
    '门槛D': {'极地白': 468},
    '门槛E': {'米兰银': 12},
    '门槛装饰条A': {'铱银': 299},
    '雷达支架A':	{'宝石红': 5},
    '雷达支架B': {'宝石蓝': 12, '极地白':	32},
    '雷达支架C':	{'钻石白': 26},
    '雷达支架D': {'曜岩黑': 4, '米兰银': 3},
    '雷达支架E': {'牛仔蓝': 5, '钻石白': 6}
    }
notes = []
less_notes = []


def analysis():
    # 创建数组用于记录
    global products
    global notes
    global less_notes
    # 遍历所有产品--第一次查找
    for product in products.keys():
        # 遍历所有颜色
        for p in products[product].keys():
            if not products[product][p]:
                continue
            if not round(products[product][p] / 6):
                less_notes.append([product, p, products[product][p]])
                products[product][p] = 0
                continue
            # notes.append(['过度零件', '底色', 1])
            notes.append([product, p, round(products[product][p] / 6)])
            products[product][p] = 0
            for the_product in products.keys():
                for the_p in products[the_product].keys():
                    if not products[the_product][the_p]:
                        continue
                    if not round(products[the_product][the_p] / 6):
                        less_notes.append([the_product, the_p, products[the_product][the_p]])
                        products[the_product][the_p] = 0
                        continue
                    if the_p == p:
                        notes.append([the_product, the_p, round(products[the_product][the_p] / 6)])
                        products[the_product][the_p] = 0
                    else:
                        continue


analysis()
print(notes)


def del_by_color(ls, color):
    i = 0
    s = 0
    trash_1 = []
    while i <= len(ls) - 1:
        if color in ls[i]:
            s += ls[i][2]
            trash_1.append(ls[i])
            del ls[i]
        else:
            i += 1
    return ls, s, trash_1


def del_by_color_number(ls, color, num):
    i = 0
    s = num
    trash_2 = []
    while i < len(ls):
        if color in ls[i]:
            if s - ls[i][2] >= 0:
                s -= ls[i][2]
                trash_2.append(ls[i])
                del ls[i]
            else:
                trash_2.append([ls[i][0], ls[i][1], s])
                ls[i][2] = ls[i][2] - s
                break
        else:
            i += 1
    return ls, trash_2


def name_judge(last, the_next):
    last_index = ''
    next_index = ''
    special = [['门槛B'], ['门槛C'], ['门槛A', '门槛D', '后保A', '门槛装饰条A']]
    if '雷达支架' in last:
        last_index = 3
    if '雷达支架' in the_next:
        next_index = 3
    for index, s in enumerate(special):
        if last in s:
            last_index = index
            break
    for index, s in enumerate(special):
        if the_next in s:
            next_index = index
            break
    if last_index == '' or next_index == '':
        return False
    elif last_index == next_index:
        return False
    elif (last_index in [0, 1] and next_index == 3) or (next_index in [0, 1] and last_index == 3):
        return True
    elif (last_index == 2 and next_index == 3) or (last_index == 3 and next_index == 2):
        return False
    else:
        # last_index, next_index有值但不相等
        return True
    # 返回True 存在不合理;返回False 存在合理


def color_judge(last, the_next):
    # 红 蓝 不加 白
    # 极地白 不加任何黑色
    # 极地白 + 钻石白
    if ('红' in last or '蓝' in last) and '白' in the_next:
        return True
    ##########################################
    elif last == '极地白' and '黑' in the_next:
        return True
    ###########################################
    else:
        return False
    # 返回True 存在不合理;返回False 存在合理


def num_judge(last_name, last_color):
    # last 应为产品名称
    global number
    global products
    n = int(number[last_name]/6)
    # n 为一次最大滑橇数量
    # 产品数量大于所有滑橇数量
    if products[last_name][last_color] > n:
        products[last_name][last_color] -= n
        number[last_name] = 0
    # 产品数量小于所有滑橇数量
    else:
        number[last_name] -= products[last_name][last_color]
        products[last_name][last_color] = 0


def neuron(last, the_next):
    boolean = name_judge(last[0], the_next[0]) or color_judge(last[1], the_next[1])
    return boolean


def simplify(ls):
    # 删除所有钻石白
    ls, sno, trash_1 = del_by_color(ls, '钻石白')
    # print('------------------')
    # print(ls)
    ls, trash_2 = del_by_color_number(ls, '极地白', 290)
    # print('--------------')
    # print('-------------------len---------------------')
    # print(len(ls))
    index = 0
    while index < len(ls) - 1:
        # print(index)
        last = ls[index]
        the_next = ls[index + 1]
        boolean = neuron(last, the_next)
        # print(color_judge(last[1], the_next[1]), name_judge(last[0], the_next[0]))
        if boolean:
            if color_judge(last[1], the_next[1]):
                # print(last, the_next)
                # print('不符合,待确认...')
                # if color_judge(last[1], the_next[1]):
                # print('进入颜色替换')
                the_next = ls[index + 1]
                del ls[index + 1]
                j = index
                while j > 0:
                    last = ls[j - 1]
                    next_next = ls[j]
                    if (not neuron(last, the_next)) and (not neuron(the_next, next_next)):
                        ls.insert(ls.index(next_next), the_next)
                        break
                    else:
                        j = j - 1
                        # print(j)
            elif name_judge(last[0], the_next[0]):
                # print('进入名称替换')
                # print(last, the_next)
                the_next = ls[index]
                del ls[index]
                j = index - 1
                while j > 0:
                    last = ls[j - 1]
                    next_next = ls[j]
                    if (not neuron(last, the_next)) and (not neuron(the_next, next_next)):
                        ls.insert(ls.index(next_next), the_next)
                        break
                    else:
                        j = j - 1
                        # print(j)

        # 如果不冲突则进入下一次循环
        else:
            index += 1
    # print('-------------------len---------------------')
    # print(len(ls))
    return ls, trash_1, trash_2


# 得到无冲突的列表 但是已删除极地白 钻石白需要添加
lis, trash1, trash2 = simplify(notes)
# trash1为所有钻石白, trash2为对应极地白


def circle(ls):
    global the_products
    global number
    circles = []
    for i in range(8):
        print('第' + str(i+1) + '圈, 重置计数字典...\n重置临时列表')
        n = dict()
        n.update(number)
        c = []
        total = 0
        print(ls)
        for product in ls:
            if (n[product[0]] == 0) or (the_products[product[0]][product[1]] == 0):
                continue
            if not len(c) == 0:
                print(len(c))
                last_color = c[-1][1]
                next_color = product[1]
                if not last_color == next_color:
                    total += 1
                    c.append(['过度零件', '底色', 1])
            else:
                c.append(['过度零件', '底色', 1])
                total += 1
            print(the_products)
            print(n)
            name, color = product[0], product[1]
            print(name, color)
            need = the_products[name][color]
            have_num = n[name]
            print(need, have_num)
            print(total)

            if (total + min(int(have_num/6), int(need/6))) > 303:
                if need <= have_num:
                    print('3出口')
                    the_products[name][color] = need - 303 + total
                    c.append([name, color, 303 - total])
                    circles.append(c)
                    break
                else:
                    print('4出口')
                    the_products[name][color] -= int(have_num / 6)
                    c.append([name, color, 303 - total])
                    circles.append(c)
                    break
            elif (total + min(have_num/6, need/6)) > 303 == 0:
                if need <= have_num:
                    c.append([name, color, min(int(have_num / 6), int(need / 6))])
                    the_products[name][color] = 0
                    circles.append(c)
                else:
                    c.append([name, color, min(int(have_num / 6), int(need / 6))])
                    the_products[name][color] = need - int(have_num / 6)*6
                    circles.append(c)
            if need <= have_num:
                print('1出口')
                the_products[name][color] = 0
                n[name] -= need
                if int(need / 6) == 0:
                    x = 1
                else:
                    x = int(need / 6)
                c.append([name, color, x])
                total += x
            else:
                print('2出口')
                n[name] = 0
                the_products[name][color] -= int(have_num / 6)*6
                total += int(have_num / 6)
                if not int(have_num / 6):
                    continue
                c.append([name, color, int(have_num / 6)])
    print('--------------the_products---------------')
    print(the_products)
    return circles


ll = circle(lis)
print(ll)
print('trash-----------------')
print(trash1, trash2)
# 输出除极地白,钻石白特殊情况的智能流程排序处理结果

with open('123.txt', 'a') as f:
    for l in ll:
        l, a, b = simplify(l)
        n = 1
        for i in l:
            for j in range(i[2]):
                f.write(str(n) + '\t' + str(i[1]) + '\t' + str(i[0]))
                f.write('\n')
                n += 1
        f.write('\n\n\n')

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).