首页 > 其他分享 >ML-for-AGV-Dispatching:run.py解读

ML-for-AGV-Dispatching:run.py解读

时间:2023-07-07 18:11:07浏览次数:41  
标签:le run ML py env import np AGV append

import simpy
from ShopFloor import Center
import Learn as Le
import numpy as np
import pandas as pd
import pickle
import time

Task = "None" #TestD, TestQ, TestDQN, TestSVM, CollectV, CollectW, TrainQ, TrainDQN
Task = "TestD"
'''
np.random.seed(124)
env = simpy. Environment()
Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=2, AGV_disRuleW=2, Ledispatch = "None")
env.run(until = 10000)
'''
if Task == "TestD":
    mt = []
    th = []
    method = []

    P = []
    startT = time.process_time()
    for v in range(6):
        for w in range(3):
            m = []
            t = []
            for i in range(30):
                np.random.seed(124+i)
                env = simpy. Environment()
                Controller = Center(env, x=16, y=16, routRule=1, AGV_num=6, WS_num=12, AGV_disRuleV=v, AGV_disRuleW=w, Ledispatch = "None")
                env.run(until = 10000)
                m.append(Controller.MeanTardiness)
                t.append(Controller.Throughput)
            print("V: {}, W: {}, Throughput: {}".format(v, w, np.mean(t)))
            print("V: {}, W: {}, MeanTardiness: {}".format(v, w, np.mean(m)))
            th.append(np.mean(t))
            mt.append(np.mean(m))
            method.append([v, w])
            P.append(m)
    t0 = pd.DataFrame(method)
    t0.columns = ["VehicleRule", "WorkstationRule"]
    t1 = pd.DataFrame(th)
    t1.columns = ["Throughput"]
    t2 = pd.DataFrame(mt)
    t2.columns = ["MeanTardiness"]
    R = pd.concat([t0, t1, t2], axis = 1)
    R.to_csv("Result/R.csv")
    Per = pd.DataFrame(P)
    Per.to_csv("Result/performance.csv")
    print("CPUtime:", time.clock()-startT)
    

elif Task == "TrainQ":
    le = []
    le.append(Le.QLearning([7, 7, 7, 7], 6, Alpha = 0.1, Gamma = 0.9, incre = 0.95))
    le.append(Le.QLearning([7, 7, 7, 7], 3, Alpha = 0.1, Gamma = 0.9, incre = 0.95))
    
    expt = []
    expm = []
    expaV = []
    expaW = []
    
    for i in range(500):
        np.random.seed(124)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=6, AGV_disRuleW=3, Ledispatch = le)
        env.run(until = 10001)
        
        if le[0].Epsilon + le[0].incre <= 0.95:
            le[0].Epsilon += le[0].incre
        if le[1].Epsilon + le[1].incre <= 0.95:
            le[1].Epsilon += le[1].incre
            
        expaV.append(list(le[0].Actions))
        for j in range(6):
            le[0].Actions[j] = 0
        expaW.append(list(le[1].Actions))
        for j in range(3):
            le[1].Actions[j] = 0
        expt.append(Controller.Throughput)
        expm.append(Controller.MeanTardiness)
        
        #print("Throughput: {}".format(Controller.Throughput))
        print("{}.MeanTardiness: {}".format(i, Controller.MeanTardiness))
    
    t1 = pd.DataFrame(expaV)
    t1.columns = ["STT", "MOQS", "MFCFS", "DS", "EDD", "DS"]
    t2 = pd.DataFrame(expaW)
    t2.columns = ["NV", "LIV", "LU"]
    t3 = pd.DataFrame(expt)
    t3.columns = ["Throughput"]
    t4 = pd.DataFrame(expm)
    t4.columns = ["MeanTardiness"]
    LER = pd.concat([t1, t2, t3, t4], axis = 1)
    
    with open('VID_Qtable', 'wb') as fp:
        pickle.dump(le[0].Qtable, fp)
    with open('WID_Qtable', 'wb') as fp:
        pickle.dump(le[1].Qtable, fp)
    
    LER.to_csv("Result/LER.csv")

elif Task == "TestQ":
    le = []
    le.append(Le.QLearning([7, 7, 7, 7], 6, Alpha = 0.1, Gamma = 0.9, incre = 0.95))
    le.append(Le.QLearning([7, 7, 7, 7], 3, Alpha = 0.1, Gamma = 0.9, incre = 0.95))
    
    with open('VID_Qtable', 'rb') as fp:
        le[0].Qtable = pickle.loads(fp)
    with open('WID_Qtable', 'rb') as fp:
        le[1].Qtable = pickle.loads(fp)

    le[0].Epsilon = 1
    le[1].Epsilon = 1
    performance = []
    for i in range(30):
        np.random.seed(124+i)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=6, AGV_disRuleW=3, Ledispatch = le)
        env.run(until = 10000)
        performance.append(Controller.MeanTardiness)
        print("{}. MeanTardiness: {}".format(i, Controller.MeanTardiness))
        
    P = pd.DataFrame(performance)
    P.columns = ["Mean Tardiness"]
    P.to_csv("Result/Performance.csv")
    
elif Task == "TuneDQN":
    D = [7, 0]
    
    PerA = []
    A_mean = []
    for A in [0.01, 0.03, 0.05, 0.07, 0.09]:
        le = []
        le.append(Le.DQN(n_actions = 6, n_features = 22, LR = A, R_disc = 0.9, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 3000, batch_size = 300, Type = "V"))
        le.append(Le.DQN(n_actions = 3, n_features = 22, LR = A, R_disc = 0.9, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 300, batch_size = 30, Type = "W"))
        
        for i in range(300):
            
            np.random.seed(124)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            env.run(until = 10001)
        
            le[0].Learning()
            
        le[0].epsilon = 1
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerA.append(performance)
        A_mean.append(np.mean(performance))
        print("A = ", A, ": ", np.mean(performance))
        
    bestA = [0.01, 0.03, 0.05, 0.07, 0.09][np.argmin(A_mean)]
    P = pd.DataFrame(PerA)
    P.index = [0.01, 0.03, 0.05, 0.07, 0.09]
    P.to_csv("Result/LearningRate.csv")
    
    PerG = []
    G_mean = []
    for G in [0.1, 0.3, 0.5, 0.7, 0.9]:
        le = []
        le.append(Le.DQN(n_actions = 6, n_features = 22, LR = bestA, R_disc = G, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 3000, batch_size = 300, Type = "V"))
        le.append(Le.DQN(n_actions = 3, n_features = 22, LR = bestA, R_disc = G, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 300, batch_size = 30, Type = "W"))
        
        for i in range(300):
            np.random.seed(124)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            env.run(until = 10001)
        
            le[0].Learning()
            
        le[0].epsilon = 1
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerG.append(performance)
        G_mean.append(np.mean(performance))
        print("G = ", G, ": ", np.mean(performance))
        
    bestG = [0.1, 0.3, 0.5, 0.7, 0.9][np.argmin(G_mean)]
    P = pd.DataFrame(PerG)
    P.index = [0.1, 0.3, 0.5, 0.7, 0.9]
    P.to_csv("Result/Gamma.csv")
    
    PerT = []
    T_mean = []
    for T in [500, 1000, 2000]:
        le = []
        le.append(Le.DQN(n_actions = 6, n_features = 22, LR = bestA, R_disc = bestG, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 3000, batch_size = 300, Type = "V"))
        le.append(Le.DQN(n_actions = 3, n_features = 22, LR = bestA, R_disc = bestG, greedy = 0.9\
                         , greedy_incre = 0.9, replace_iter = 25\
                         , memory_size = 300, batch_size = 30, Type = "W"))
        
        for i in range(300):
            np.random.seed(124)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = T
            Controller.Warmup = 2000
            env.run(until = 10001)
        
            le[0].Learning()
            
        le[0].epsilon = 1
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = T
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerT.append(performance)
        T_mean.append(np.mean(performance))
        print("T = ", T, ": ", np.mean(performance))
        
    bestT = [500, 1000, 2000][np.argmin(T_mean)]
    P = pd.DataFrame(PerT)
    P.index = [500, 1000, 2000]
    P.to_csv("Result/DeltaT.csv")
    
    PerE = []
    E_mean = []
    for E in [0, 0.01, 0.05, 0.1, 0.2]:
        le = []
        le.append(Le.DQN(n_actions = 6, n_features = 22, LR = bestA, R_disc = bestG, greedy = 1-E\
                         , greedy_incre = 1-E, replace_iter = 25\
                         , memory_size = 3000, batch_size = 300, Type = "V"))
        le.append(Le.DQN(n_actions = 3, n_features = 22, LR = bestA, R_disc = bestG, greedy = 1-E\
                         , greedy_incre = 1-E, replace_iter = 25\
                         , memory_size = 300, batch_size = 30, Type = "W"))
        
        for i in range(300):
            np.random.seed(124)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = bestT
            env.run(until = 10001)
        
            le[0].Learning()
            
        le[0].epsilon = 1
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = bestT
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerE.append(performance)
        E_mean.append(np.mean(performance))
        print("E = ", E, ": ", np.mean(performance))
        
    bestE = [0, 0.01, 0.05, 0.1, 0.2][np.argmin(E_mean)]
    P = pd.DataFrame(PerE)
    P.index = [0, 0.01, 0.05, 0.1, 0.2]
    P.to_csv("Result/Epsilon.csv")
            
            
        
        

elif Task == "TrainDQN":
    le = []
    le.append(Le.DQN(n_actions = 6, n_features = 22, LR = 0.01, R_disc = 0.9, greedy = 0.95\
                     , greedy_incre = 0.95, replace_iter = 25\
                     , memory_size = 3000, batch_size = 300, Type = "V"))
    le.append(Le.DQN(n_actions = 3, n_features = 22, LR = 0.01, R_disc = 0.9, greedy = 0.95\
                     , greedy_incre = 0.95, replace_iter = 25\
                     , memory_size = 300, batch_size = 30, Type = "W"))
    
    expt = []
    expm = []
    expaV = []
    expaW = []
    
    for i in range(300):
        np.random.seed(123)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=0, AGV_disRuleW=4, Ledispatch = le)
        env.run(until = 10001)
        
        le[1].Learning()
        print("{}.MeanTardiness: {}".format(i, Controller.MeanTardiness))
        le[1].performance_his.append(Controller.MeanTardiness)
        
        np.random.seed(123)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
        env.run(until = 10001)
        
            
        expaV.append(list(le[0].Actions))
        for j in range(6):
            le[0].Actions[j] = 0
        expaW.append(list(le[1].Actions))
        for j in range(3):
            le[1].Actions[j] = 0
        expt.append(Controller.Throughput)
        expm.append(Controller.MeanTardiness)
    
        le[0].Learning()
     
        #print("Throughput: {}".format(Controller.Throughput))
        print("{}.MeanTardiness: {}".format(i, Controller.MeanTardiness))
        le[0].performance_his.append(Controller.MeanTardiness)
    
    le[0].Save_net()
    le[0].plot_performance()
    
    t1 = pd.DataFrame(expaV)
    t1.columns = ["STT", "MOQS", "MFCFS", "DS", "EDD", "DS"]
    #t2 = pd.DataFrame(expaW)
    #t2.columns = ["NV", "LIV", "LU"]
    t3 = pd.DataFrame(expt)
    t3.columns = ["Throughput"]
    t4 = pd.DataFrame(expm)
    t4.columns = ["MeanTardiness"]
    LER = pd.concat([t1, t3, t4], axis = 1)

elif Task == "TestDQN":
    le = []
    le.append(Le.DQN(n_actions = 6, n_features = 22, LR = 0.01, R_disc = 0.9, greedy = 0.95\
                     , greedy_incre = 0.005, replace_iter = 25\
                     , memory_size = 3000, batch_size = 300, Type = "V"))
    le.append(Le.DQN(n_actions = 3, n_features = 22, LR = 0.01, R_disc = 0.9, greedy = 0.95\
                     , greedy_incre = 0.005, replace_iter = 25\
                     , memory_size = 300, batch_size = 30, Type = "W"))
    
    le[0].Load_net()
    le[1].Load_net()
    
    le[0].epsilon = 1
    le[1].epsilon = 1
    performance = []
    for i in range(10):
        np.random.seed(124+i)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=7, AGV_disRuleW=0, Ledispatch = le)
        env.run(until = 10000)
        performance.append(Controller.MeanTardiness)
        print("{}. MeanTardiness: {}".format(i, Controller.MeanTardiness))
        
    P = pd.DataFrame(performance)
    P.columns = ["Mean Tardiness"]
    P.to_csv("Result/Performance.csv")
    
elif Task == "CollectV":
    le = []
    le.append(Le.SVM())
    le.append(Le.SVM())
    
    for i in range(500):
        print("Collecting Sample({})".format(i+1))
        for j in range(6):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=j, AGV_disRuleW=0, Ledispatch = le, Task = ["Collect", "None"])
            Controller.Period = 2000
            Controller.Warmup = 1000
            env.run(until = 3001)
        R = []
        s = le[0].rawData[0][0]
        for k in le[0].rawData:
            R.append(k[1])
        le[0].Create_sample(s, R)
        le[0].rawData = []
    
        for j in range(6):
            np.random.seed(1000-i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=j, AGV_disRuleW=0, Ledispatch = le, Task = ["Collect", "None"])
            Controller.Period = 2000
            Controller.Warmup = 3000
            env.run(until = 5001)
        R = []
        s = le[0].rawData[0][0]
        for k in le[0].rawData:
            R.append(k[1])
        le[0].Create_sample(s, R)
        le[0].rawData = []
        
        for j in range(6):
            np.random.seed(2*i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=j, AGV_disRuleW=0, Ledispatch = le, Task = ["Collect", "None"])
            Controller.Period = 2000
            Controller.Warmup = 5000
            env.run(until = 7001)
        R = []
        s = le[0].rawData[0][0]
        for k in le[0].rawData:
            R.append(k[1])
        le[0].Create_sample(s, R)
        le[0].rawData = []
        
        for j in range(6):
            np.random.seed(5*i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=j, AGV_disRuleW=0, Ledispatch = le, Task = ["Collect", "None"])
            Controller.Period = 2000
            Controller.Warmup = 7000
            env.run(until = 9001)
        R = []
        s = le[0].rawData[0][0]
        for k in le[0].rawData:
            R.append(k[1])
        le[0].Create_sample(s, R)
        le[0].rawData = []
    
    le[0].Save_samples()

elif Task == "CollectW":
    le = []
    le.append(Le.SVM())
    le.append(Le.SVM())
    
    for i in range(500):
        print("Collecting Sample({})".format(i+1))
        for j in range(3):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=0, AGV_disRuleW=j, Ledispatch = le, Task = ["None", "Collect"])
            Controller.Period = 2000
            Controller.Warmup = 1000
            env.run(until = 3001)
        R = []
        s = le[1].rawData[0][0]
        for k in le[1].rawData:
            R.append(k[1])
        le[1].Create_sample(s, R)
        le[1].rawData = []
    
        for j in range(3):
            np.random.seed(1000-i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=0, AGV_disRuleW=j, Ledispatch = le, Task = ["None", "Collect"])
            Controller.Period = 2000
            Controller.Warmup = 3000
            env.run(until = 5001)
        R = []
        s = le[1].rawData[0][0]
        for k in le[1].rawData:
            R.append(k[1])
        le[1].Create_sample(s, R)
        le[1].rawData = []
        
        for j in range(3):
            np.random.seed(2*i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=0, AGV_disRuleW=j, Ledispatch = le, Task = ["None", "Collect"])
            Controller.Period = 2000
            Controller.Warmup = 5000
            env.run(until = 7001)
        R = []
        s = le[1].rawData[0][0]
        for k in le[1].rawData:
            R.append(k[1])
        le[1].Create_sample(s, R)
        le[1].rawData = []
        
        for j in range(3):
            np.random.seed(5*i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=0, AGV_disRuleW=j, Ledispatch = le, Task = ["None", "Collect"])
            Controller.Period = 2000
            Controller.Warmup = 7000
            env.run(until = 9001)
        R = []
        s = le[1].rawData[0][0]
        for k in le[1].rawData:
            R.append(k[1])
        le[1].Create_sample(s, R)
        le[1].rawData = []
    
    le[1].Save_samples()

elif Task == "TuneSVM":
    D500 = pd.read_csv("training_setD500.csv").iloc[: ,1:]
    D1000 = pd.read_csv("training_setD1000.csv").iloc[: ,1:]
    D2000 = pd.read_csv("training_setD2000.csv").iloc[: ,1:]
    '''
    PerC = []
    C_mean = []
    for C in range(-5, 6):
        le = []
        le.append(Le.SVM("rbf", 2**C, 1, 10))
        le.append(Le.SVM("rbf", 2**C, 1, 10))
        
        le[0].Load_samples(D2000)
        
        le[0].Learn_all()
            
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=8, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = 500
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerC.append(performance)
        C_mean.append(np.mean(performance))
        print("C = ", C, ": ", np.mean(performance))
        
    bestC = range(-5, 6)[np.argmin(C_mean)]
    P = pd.DataFrame(PerC)
    P.index = range(-5, 6)
    P.to_csv("Result/C.csv")
    
    PerR = []
    R_mean = []
    for R in range(-5, 6):
        le = []
        le.append(Le.SVM("rbf", 2**bestC, 2**R, 10))
        le.append(Le.SVM("rbf", 2**bestC, 2**R, 10))
        
        le[0].Load_samples(D2000)
        
        le[0].Learn_all()
            
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=8, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = 500
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerR.append(performance)
        R_mean.append(np.mean(performance))
        print("R = ", R, ": ", np.mean(performance))
        
    bestR = range(-5, 6)[np.argmin(R_mean)]
    P = pd.DataFrame(PerR)
    P.index = range(-5, 6)
    P.to_csv("Result/R.csv")
    '''
    PerT = []
    T_mean = []
    for T in [D1000, D2000]:
        le = []
        le.append(Le.SVM("rbf", 2**5, 2**0, 10))
        le.append(Le.SVM("rbf", 2**1, 2**0, 10))
        
        
        le[0].Load_samples(T)
        
        le[0].Learn_all()
            
        performance = []
        for i in range(30):
            np.random.seed(124+i)
            env = simpy. Environment()
            Controller = Center(env, x=16, y=16, routRule=1, AGV_num=7, WS_num=12, AGV_disRuleV=8, AGV_disRuleW=0, Ledispatch = le)
            Controller.Period = 500
            env.run(until = 10000)
            performance.append(Controller.MeanTardiness) 
            
        PerT.append(performance)
        T_mean.append(np.mean(performance))
        print("T = : ", np.mean(performance))
        
    bestT = [1000, 2000][np.argmin(T_mean)]
    P = pd.DataFrame(PerT)
    P.index = [1000, 2000]
    P.to_csv("Result/T.csv")
    
    
 
elif Task == "TestSVM":
    le = []
    le.append(Le.SVM("rbf", 2**2, 2**-2, 10))
    le.append(Le.SVM("rbf", 2**0, 2**2, 10))
    
    data1 = pd.read_csv("training_setV1.csv").iloc[: ,1:]
    #data2 = pd.read_csv("training_set2.csv").iloc[: ,1:]
    #data3 = pd.read_csv("training_set3.csv").iloc[: ,1:]
    #data4 = pd.read_csv("training_set4.csv").iloc[: ,1:]
    dataA = pd.read_csv("training_setW1.csv").iloc[: ,1:]
    #dataB = pd.read_csv("training_setB.csv").iloc[: ,1:]
    #dataC = pd.read_csv("training_setC.csv").iloc[: ,1:]
    #dataD = pd.read_csv("training_setD.csv").iloc[: ,1:]
    
    le[0].Load_samples(data1)
    #le[0].Load_samples(data2)
    #le[0].Load_samples(data3)
    #le[0].Load_samples(data4)
    le[1].Load_samples(dataA)
    #le[1].Load_samples(dataB)
    #le[1].Load_samples(dataC)
    #le[1].Load_samples(dataD)
    
    le[0].Learn_all()
    le[1].Learn_all()
    
    
    performance = []
    for i in range(30):
        np.random.seed(124+i)
        env = simpy. Environment()
        Controller = Center(env, x=16, y=16, routRule=1, AGV_num=1, WS_num=12, AGV_disRuleV=8, AGV_disRuleW=5, Ledispatch = le)
        Controller.Period = 500
        Controller.Warmup = 2000
        env.run(until = 10000)
        performance.append(Controller.MeanTardiness)
        print("TH: {}".format(Controller.Throughput))
        print("{}. Tardiness: {}".format(i, Controller.MeanTardiness))
        
    P = pd.DataFrame(performance)
    P.columns = ["Mean Tardiness"]
    P.to_csv("Result/VW.csv")

 

标签:le,run,ML,py,env,import,np,AGV,append
From: https://www.cnblogs.com/youlongxu/p/17535752.html

相关文章

  • Python 引用问题 - ImportError: attempted relative import with no known parent pa
    问题描述近日在尝试引用其他文件的代码时,遇到了错误:ImportError:attemptedrelativeimportwithnoknownparentpackage.问题大致是这样的:我想在code2.py中引用code1.py的函数,如from..folder1.code1importxxx,运行code2.py时出现错误。root├──folder1│......
  • python函数进阶
    Python函数进阶一、函数多返回值1.1多个返回值如果一个函数要有多个返回值,该如何书写代码?"""演示函数的多返回值示例"""#演示使用多个变量,接受多个返回值deftest_return():return1,"hello",Truex,y,z=test_return()print(x)#1print(y)#hello......
  • python multiprocessing库使用记录
    pythonmultiprocessing库使用记录需求是想并行调用形式化分析工具proverif,同时发起对多个query的分析(378个)。实验室有40核心80线程的服务器(双cpu,至强gold5218R*2)。观察到单个命令在分析时内存占用不大,且只使用单核心执行,因此考虑同时调用多个命令同时执行分析,加快结果输出。......
  • # Python_函数专题(一)
    目录函数基础基础函数调用参数返回值变量承接print定义函数定义函数的格式函数嵌套函数调用死循环函数参数单参数双参数报错指定参数类型函数文档注释函数返回值Return定义带有返回值的参数返回多个值函数基础基础函数的基础理论函数,即一段具有特定功能的代码块调用函数,即......
  • 如何利用 Python 自动发邮件,打工人福音
    在工作中,每天或者每周结束的时候我们都会发送相应的日报或者周报给上级领导,来汇报你做了那些工作,可是汇报工作内容的时候我们始终都是打开邮箱、写入内容,发送和抄送给固定的人,那么这么繁琐并且重复的一件事,我们能不能使用程序来简化?答案是可以的,接下来我们就使用Python来操作......
  • 如何解决Shell执行python文件,传参空格引起的问题
    这篇文章给大家分享的是有关如何解决Shell执行python文件,传参空格引起的问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。使用shell调用一个python文件,并向shell中传入参数,举例如下:p1='wang'p2='shuang'pythonpy文件$p1$p2 这种情况可以......
  • spring的工具类BeanUtils.copyProperties 非基本数据类型时的坑
    复现前准备三个类,Student、Source、Target。Source和Target里面包含一个相同的非基本类型的字段(如下面示例中的stu字段)publicclassStudent{privateStringname;publicStudent(Stringname){this.name=name;}publicStringgetName(){......
  • 性能测试工具loadrunner学习
    一、性能测试基础1.性能测试概述  性能测试分类 性能测试方式时通过模拟生产运行的业务压力量和使用场景组合,测试系统的性能是否满足生产性能要求,通俗地讲,这种方法就是要在特定的运行条件下验证系统的能力状况。 ......
  • 如何实现pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '
    解决“pymysql.err.OperationalError:(2003,"Can'tconnecttoMySQLserveron'10.1"错误的步骤概述当使用pymysql连接MySQL数据库时,有时会出现连接错误,其中一个常见的错误是pymysql.err.OperationalError:(2003,"Can'tconnecttoMySQLserveron'10.1'")......
  • 如何实现pso优化神经网络pytorch的具体操作步骤
    PSO优化神经网络(PyTorch)实现流程介绍本文将介绍如何使用粒子群优化(ParticleSwarmOptimization,PSO)算法来优化神经网络模型,并使用PyTorch框架来实现。PSO算法是一种基于群体智能的优化算法,通过模拟鸟群觅食行为,来搜索最优解。在神经网络中,我们可以将待优化的参数作为粒子,利用......