Пример #1
0
def getState(transition_time):  # made the order changes
    newState = []
    for _ in range(transition_time):
        traci.simulationStep()

        state = [
            cross_read.leftgetLowerQlength() /
            80,  # issi sequnce main left and right
            cross_read.leftgetRightQlength() / 80,
            cross_read.leftgetUpperQlength() / 80,
            cross_read.leftgetLeftQlength() / 80,
            cross_read.rightgetLowerQlength() /
            80,  # issi sequnce main left and right
            cross_read.rightgetRightQlength() / 80,
            cross_read.rightgetUpperQlength() / 80,
            cross_read.rightgetLeftQlength() / 80,
        ]

        newState.insert(0, state)
    # print (state)
    newState = np.array(newState)
    phaseState = getPhaseState(transition_time)
    newState = np.dstack((newState, phaseState))
    newState = np.expand_dims(newState, axis=0)  # tensor format conversion
    return newState
def getStates(transition_time):
    newLeftState = []
    newRightState = []

    for _ in range(transition_time):
        traci.simulationStep()

        leftState = [
            cross_read.leftgetLowerQlength() / 80,  # issi sequnce main left and right
            cross_read.leftgetRightQlength() / 80,
            cross_read.leftgetUpperQlength() / 80,
            cross_read.leftgetLeftQlength() / 80
        ]

        rightState = [
            cross_read.rightgetLowerQlength() / 80,  # issi sequnce main left and right
            cross_read.rightgetRightQlength() / 80,
            cross_read.rightgetUpperQlength() / 80,
            cross_read.rightgetLeftQlength() / 80
        ]

        newLeftState.insert(0, leftState)
        newRightState.insert(0, rightState)

    newLeftState = np.array(newLeftState)
    leftPhaseState = getLeftPhaseState(transition_time)
    newLeftState = np.dstack((newLeftState, leftPhaseState))
    newLeftState = np.expand_dims(newLeftState, axis=0)

    newRightState = np.array(newRightState)
    rightPhaseState = getRightPhaseState(transition_time)
    newRightState = np.dstack((newRightState, rightPhaseState))
    newRightState = np.expand_dims(newRightState, axis=0)

    return newLeftState, newRightState