Пример #1
0
 def __init__(self, time):
     print("path:" + sys.path[0])
     #线路静态信息
     self.startPoint = trc.SLStartPoint[0]
     self.endPoint = trc.SLStartPoint[-1]
     self.S = self.endPoint - self.startPoint
     self.max_speed = 80 / 3.6
     self.T = time  #运行总时间
     self.avg_speed = self.S / self.T  #平均速度
     self.dt = 0.2  #运行时间步长
     self.low = np.array([0, 0])
     self.high = np.array([self.S, self.max_speed])
     self.ac = 0.8  #最大加速度
     self.de = 1  #最大减速度
     self.viewer = None
     self.n_actions = 9  #-0.8 :0.2 :0.8
     self.n_features = 4  #用于训练的特征,和self.state相对应
     self.action_space = [
         '-0.8', '-0.6', '-0.4', '-0.2', '0', '0.2', '0.4', '0.6', '0.8'
     ]
     self.action_space = spaces.Discrete(9)  #下标从0开始
     self.observation_space = spaces.Box(self.low, self.high)
     self.seed()
     self.done = False
     self.filterFactor = 0.8
     #线路动态信息
     self.trd = trc.TrainAndRoadData()
     self.reset()
 def __init__(self, start, destination, T, dt):
     super().__init__(dt, 0)
     #离线信息
     self.tripStart = start  #旅程起点
     self.tripDestination = destination  #旅程终点
     self.tripTime = T
     self.dv = 0.1  #允许速度误差
     self.MaxAcc = 1.5  #最大牵引加速度
     self.MinAcc = -1.5  #最大制动加速度
     self.dadt = 0.5  #加速度变化率,初始为0.5
     self.trd = trc.TrainAndRoadData()
     self.MinT = self.trd.getMinRestTime(self.tripDestination)
     #在线信息(状态)
     self.pos = self.tripStart  #位置
     self.veo = 0  #当前速度
     self.time = 0  #仿真时间步
     self.vbar = 0  #预测速度
 def __init__(self, start, destination, T, dt):
     super().__init__(dt, 0)
     #离线信息
     self.tripStart = start  #旅程起点
     self.tripDestination = destination  #旅程终点
     self.tripTime = T
     self.dv = 0.1  #允许速度误差
     self.MaxAcc = 1.5  #最大牵引加速度
     self.MinAcc = -1.5  #最大制动加速度
     self.dadt = 0.5  #加速度变化率,初始为0.5
     self.trd = trc.TrainAndRoadData()
     self.MinT = self.trd.getMinRestTime(self.tripDestination)
     #在线信息(状态)
     self.pos = self.tripStart  #位置
     self.veo = 0  #当前速度
     self.time = 0  #仿真时间步
     self.trueAcc = 0  #当前的加速度acc
     self.vbar = 0  #预测速度
     self.last_veo = 0
     self.last_pos = start
     self.last_out = 0
     self.step = 0
     #xgboost训练好的模型
     self.bst = xgb.Booster(model_file='./xgboost_algorithm/xgb.model')
def TanslationBySimulation(switchPoint, index):
    #模拟列车运行,将工况控制点转换成(s,v,t,u)组合
    dt = 0.2  #时间步长
    startPoint = trc.SLStartPoint[0]
    endPoint = trc.SLStartPoint[-1]
    sl = trc.getRoadspeedLimit(startPoint)
    gd = trc.getRoadGradinet(startPoint)
    nsl = trc.getNextSpeedLimit(startPoint)
    nsld = trc.getSpeedLimitEndPoint(startPoint)
    vList = [0]  #速度
    sList = [startPoint]  #位置
    tList = [0]  #时间
    uList = [1]  #加速度
    gdList = [gd]  #坡度  千分
    slList = [sl]  #路段限速(m/s)
    nslList = [nsl]  #下一限速的值(m/s)
    nsldList = [nsld]  #下一限速的距离(m)
    train = trm.Train_model(startPoint, 0, 0.6, dt)
    PIDC = atoController.PidController(dt, 8, 10, 1)
    trd = trc.TrainAndRoadData()
    t = 0
    accList = [0]
    stateList = [2]
    state = 2
    acc = 0.1
    while True:
        t = t + dt
        laststate = state
        state = trc.getRunState(sList[-1], switchPoint)
        if state == 1 and laststate != 1:
            vbar = vList[-1]
        if state == 2:
            #牵引
            acc = 1
        if state == 1:
            #巡航
            acc = PIDC.Step(vbar, vList[-1])
        elif state == 0:
            #惰行
            acc = 0
        elif state == -1:
            #制动
            acc = -1
        if vList[-1] > trd.getEmerencyBrakeSpeed(sList[-1]):
            acc = -1
        out = train.Step(acc)
        trueAcc = out['acc']
        stateList.append(state)
        accList.append(acc)
        sl = trc.getRoadspeedLimit(out['S'])
        gd = trc.getRoadGradinet(out['S'])
        nsl = trc.getNextSpeedLimit(out['S'])
        nsld = trc.getSpeedLimitEndPoint(out['S'])
        vList.append(out['v'])
        sList.append(out['S'])
        tList.append(t)
        uList.append(acc)
        gdList.append(gd)  #坡度  千分
        slList.append(sl)  #路段限速(m/s)
        nslList.append(nsl)  #下一限速的值(m/s)
        nsldList.append(nsld)  #下一限速的距离(m)
        if out['S'] > endPoint or out['v'] < 0:
            break
    #保存数据
    plt.plot(sList, accList)
    plt.plot(sList, stateList)
    plt.show()
    trc.plotSpeedLimitRoadGrad('abstract')
    plt.plot(sList, vList)
    plt.show()
    plt.plot(tList, vList)
    plt.show()
    print('-------------------%d---------------------' % index)
    dataList = []
    for i in range(0, len(vList)):
        s = sList[i]
        #        t=tList[i]
        sr = endPoint - sList[i]
        t = tList[i]
        tr = tList[-1] - t
        vn = vList[i]
        un = uList[i]
        sr = round(sr, 2)
        tr = round(tr, 2)
        vn = round(vn, 2)
        sl = slList[i]
        gd = gdList[i]
        nsl = nslList[i]
        nsld = nsldList[i]
        line = [s, sr, tList[-1], tr, sl, gd, nsl, nsld, un]
        #如果list是一维的,则是以列的形式来进行添加,如果list是二维的则是以行的形式进行添加的
        dataList.append(line)
    tC = np.mat([sList, vList])
    targetCurve = pds.DataFrame(data=tC.T, columns=['s', 'v'])
    pData = pds.DataFrame(
        data=dataList,
        columns=['s', 'sr', 't', 'tr', 'sl', 'gd', 'nsl', 'nsld', 'un'])
    return pData, targetCurve, tList[-1]