2018数学建模国赛B题 --python实现情况1

2018年国赛B题

2018数学建模国赛B题 --python实现情况1

数据

2018数学建模国赛B题 --python实现情况1

code:只采用第一组数据

# -*- coding: utf-8 -*-
"""
Created on Sun Feb 23 11:23:49 2020

@author: t4ngw
"""

import numpy as np
import math
Move = [0, 20, 33, 46]#rgv移动每一个位置的时间
Work = 560
Switch = np.tile([28, 31], (1, 4))
Wash = 25#洗料时间
Position = 1#初始的时候在1号位
left = np.zeros((1, 8))
sitution = np.zeros((1, 8))
Time = 0
expect = np.ones((4, 8))
#第一行记录RGV运动到各CNC的时间,第三行记录洗料的时间;
rec = np.array([[0, 0]])
while Time <=28800:
    #进入循环结束后,Time为28802(RGV工作28800便停止)前一个循环是28725s
    #75s(28800-28725)内Rgv还是能给CNC上料,所以这块物料算在物料数内
    for i in range(1, 9):
        expect[0, i - 1] = Move[0 + abs(Position - math.ceil(i/2))]
        if left[0, i - 1] <= expect[0, i - 1]:
            expect[1, i - 1] = 0
        else:
            expect[1, i - 1] = left[0, i - 1] - expect[0, i - 1]
        expect[2, i - 1] = Switch[0, i - 1]
        expect[3, i - 1] = np.sum(expect[0:3, i - 1], axis=0)
    MinNumber = np.argmin(expect[3, :])
    Time = Time + expect[0, MinNumber] + expect[1, MinNumber]
    flag = 0
    if flag == 0:
        rec1 = np.array([[MinNumber, Time]])
        rec = np.append(rec, rec1, axis=0)
        
    if sitution[0][MinNumber] == 0:
        sitution[0][MinNumber] = 1
        Time = Time + expect[2, MinNumber]     
        for i in range(0, 8):
            if left[0, i] - expect[3, MinNumber] < 0:
                left[0, i] = 0
            else:
                left[0, i] = left[0, i] - expect[3, MinNumber]
        left[0, MinNumber] = Work
    else:
        Time = Time + expect[2, MinNumber] + Wash
        for i in range(0, 8):
            if left[0, i] - expect[3, MinNumber] - Wash < 0 :
                left[0, i] = 0
            else:
                left[0, i] = left[0, i] - expect[3, MinNumber] - Wash
        left[0, MinNumber] = Work - Wash
    Position = math.ceil((MinNumber + 1)/2)
    while (rec[-1][1] + expect[0, MinNumber] + Wash) > 28800:
        rec=np.delete(rec,-1, axis=0)
    
a = rec[1:385, 0]    
print("物料数量:{}".format(np.size(rec, 0) - 1))        
print("rgv运动轨迹:")  
print(a.reshape(-1, 8)) 
print(rec[385:,0])
#经过最后一次print(expect)可知0-7位置的CNC都没有洗料完成,所以最终成料数是
#物料数量-(正在洗料+刚上料)的数量
print("最终成料数:{}".format(np.size(rec, 0) - 1 - 8 )) 

结果

物料数量:391
rgv运动轨迹:
[[0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3. 4. 5. 6. 7.]
 [0. 1. 2. 3.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