Exemple #1
0
def runFlowSims(f, numIters):
    global myRoad
    simStats = []
    simStats.append(params)
    #   for flow in [x * 0.5 for x in range (1,11)]:
    for flow in [x * 0.5 for x in range(1, 13)]:
        print 'flow: ' + str(flow)

        stats.reset()
        myRoad = road.Road()
        params.flow = 0.5
        timeSim(f, 100)
        myRoad.turn = -1

        print
        print "****************************************************"
        print

        stats.reset()
        params.flow = flow
        timeSim(f, numIters)
        simStats.append(copy.copy(stats))
    fileName = str(f.__name__) + "_flow_0.5-6.0_2_8_2016_data.p"
    writeToFile(fileName, simStats)
    return simStats
    def __init__(self, n, config_filename, auto_trace, ped_trace,
                 button_trace):
        # N is the number of vehicles and pedestrians to create
        self.n = n

        # initialize time
        self.time = 0

        # note on priority queue:
        # each entry is of the form (time, function, params).
        self.q = PriorityQueue()

        # set up trace readers
        self.auto_tr = TraceReader(auto_trace)
        self.ped_tr = TraceReader(ped_trace)
        self.button_tr = TraceReader(button_trace)

        # read config variables
        self.read_config_variables(config_filename)

        # create a road
        self.road = road.Road(0, self.t_red, self.t_yellow, self.t_green)

        # initialize welford variables
        self.avg_auto_delay = 0
        self.auto_i = 0
        self.auto_delay_variance = 0
        self.avg_ped_delay = 0
        self.ped_i = 0

        # set up simulation state
        self.setup_sim()
Exemple #3
0
def runKTSims(f, numIters):
    global myRoad
    simStats = []
    simStats.append(params)
    for k_t in [10, 15, 20, 25, 30]:  # 5
        print 'k_t: ' + str(k_t)
        for flow in [float(x) for x in range(6, 7)]:  # 5
            print 'flow: ' + str(flow)

            stats.reset()
            myRoad = road.Road()
            params.flow = 0.5
            timeSim(f, 100)
            myRoad.turn = -1

            print
            print "****************************************************"
            print

            stats.reset()
            params.flow = flow
            params.maxEpsilonLook = k_t
            params.turnTime = params.getTurnTime(max(params.laneVels))
            print "Turn time: ", params.turnTime
            timeSim(f, numIters)
            simStats.append(copy.copy(stats))
    fileName = str(f.__name__) + "_k_thresh_10-30_flow_6.0_2_8_2016_data.p"
    writeToFile(fileName, simStats)
    return simStats
Exemple #4
0
def runAlphaSims(f, numIters):
    global myRoad
    simStats = []
    simStats.append(params)
    for r_alpha in [1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]:  # 9
        for flow in [x * 0.5 for x in range(1, 12)]:  # 11
            print 'flow: ' + str(flow)

            stats.reset()
            myRoad = road.Road()
            params.flow = 0.5
            timeSim(f, 100)
            myRoad.turn = -1

            print
            print "****************************************************"
            print

            stats.reset()
            params.flow = flow
            params.rAlpha = r_alpha
            timeSim(f, numIters)
            simStats.append(copy.copy(stats))
    fileName = str(
        f.__name__) + "_rAlpha_1.0-3.0_flow_0.5-5.5_1_18_2016_data.p"
    writeToFile(fileName, simStats)
    return simStats
 def __init__(self,size_road,  number_of_turn, x, y, n, p, init_pos = (0,0),
              size_matrix = (360,360)):
     self.my_road = road.Road(size_road,  number_of_turn, init_pos = (0,0),
              size_matrix = (360,360))
     self.car = Voiture.Voiture(x, y, n, p,size_matrix = (360,360))
     self.window = self.my_road.map + self.car.map
     self.score = 0
     self.game_over = False
     self.data = [self.score, self.window, self.game_over]
     self.DeltaAngle=0.05
     self.vitesse=5
     self.acc=1
     self.decelaration=-1
     self.vitesseMin=5
Exemple #6
0
 def parse_line(self, line):
     """
     Parses a line in a track description file.
         line    (string)    :   the line of text to be parsed
     """
     parse_errors = []
     elements = line.replace(',', ' ').split()
     if elements[0] == self.ROUNDABOUT:
         args = [int(item) for item in elements[1:]]
         self.track.roundabouts.append(
             __roundabout__.Roundabout(self.track, *args))
     elif elements[0] == self.ROAD:
         args = [int(item) for item in elements[1:]]
         new_road = __road__.Road(self.track.roundabouts[args[0]],
                                  self.track.roundabouts[args[1]])
         self.track.roads.append(new_road)
     else:
         raise Exception("ERROR : unknown element type '" + elements[0] +
                         "' !")
Exemple #7
0
def runEpSims(f, numIters):
    global myRoad
    simStats = []
    simStats.append(params)
    for r_alpha in [1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]:

        stats.reset()
        myRoad = road.Road()
        params.flow = 0.5
        timeSim(f, 100)
        myRoad.turn = -1

        print 'r_alpha: ' + str(r_alpha)
        stats.reset()
        #myRoad = road.Road()
        params.flow = 3.0
        params.rAlpha = r_alpha
        timeSim(f, numIters)
        simStats.append(copy.copy(stats))
    fileName = str(
        f.__name__) + "_r_alpha_changing_1.0-3.0_flow3_1-15-2016_data.p"
    writeToFile(fileName, simStats)
    return simStats
Exemple #8
0
            self.direction = Dirs.doDir(self.direction)
            self.roadChange = False

    def update(self, init=False):
        super().update()
        if init:
            return
        self.cur.pad.move(21, 20)
        self.cur.pad.addstr(21, 20, Dirs.__str__(self.direction))


cur._class_update_list = [Car, road.Road]

if __name__ == "__main__":
    a = cur.Cur()
    r0 = road.Road(1, 2, 15, 2, False, "r0")
    r1 = road.Road(r0.xPos2, r0.yPos-1, 9, 2, True, "r1")
    r2 = road.Road(r1.xPos - 8, r1.yPos2, 15, 2, False, "r2")
    r3 = road.Road(r2.xPos - 2, r0.yPos2, 12, 2, True, "r3")
    c0 = SimpleCar(4, 3)
    co0 = road.SimpleConnector(r0, r1)
    co1 = road.SimpleConnector(r1, r2)
    co2 = road.SimpleConnector(r0, r3)
    co3 = road.SimpleConnector(r2, r3)

    c0.road = r0
    c0.direction = Dirs._RIGHT
    a.objs.append(r0)
    a.objs.append(r1)
    a.objs.append(r2)
    a.objs.append(r3)
Exemple #9
0
def runSim(display=True, maxSimTime=None, seed=None):
    gV.carCount = []
    gV.avgVelocityTotal = []
    gV.avgVelocityLanes = []
    gV.velocityDistribution = []
    gV.tempCarCount = {}
    for x in gV.flowrateChecks:
        gV.tempCarCount[x] = [0 for _ in range(gV.laneCount)]
    if seed is not None:
        gV.seed = seed
        np.random.seed(gV.seed)

    print("Seed is", gV.seed)

    gV.runTimer = 0
    gV.vehicleCrossingTimes = []

    if maxSimTime is None:
        maxSimTime = 2 ** 31

    # Main loop flag
    simQuit = False

    # Create Objects for simulation
    roadObject = road.Road(pos=[0, (gV.displaySize[1] / 2) - gV.roadWidth / 2], laneCount=gV.laneCount,
                           laneWidth=gV.roadWidth, meanArrivalRate=gV.arrivalRate)

    # Add obstacle
    for obstacleObj in gV.obstacles:
        roadObject.obstructionArray.append(obstacle.Obstacle(road=roadObject, x=obstacleObj['x'], lane=obstacleObj['lane']))

    # Main loop
    while not simQuit and gV.runTimer < maxSimTime:
        gV.runTimer += gV.deltaTime
        if display:
            simQuit = visualiseSimulation(roadObject)

        # generate traffic coming down road frequency dependent on poisson distribution
        if round(gV.runTimer, 1) % 1 == 0:
            roadObject.generateTraffic()

        if gV.runTimer % 60 < 0.1: # every 60 seconds
            gV.carCount.append(gV.tempCarCount)
            gV.tempCarCount = {}
            for x in gV.flowrateChecks:
                gV.tempCarCount[x] = [0 for _ in range(gV.laneCount)]

        # vehicle handling loop
        for vehicleObject in roadObject.vehicleArray:
            vehicleObject.checkHazards(roadObject, roadObject.vehicleArray, roadObject.obstructionArray)
            vehicleFinishTime = vehicleObject.move()

            if vehicleFinishTime is not None and vehicleFinishTime > 0:
                gV.vehicleCrossingTimes.append(vehicleFinishTime)

        # Recalculates the average velocity of all vehicles in each lane
        for laneNum in range(roadObject.laneCount):
            roadObject.calcLaneFlowRate(laneNum)

        velocities = averageVelocity(roadObject)

        gV.avgVelocityTotal.append(velocities[0])
        gV.avgVelocityLanes.append(velocities[1])

        velocities = [x.velocity for x in roadObject.vehicleArray]

        if len(velocities) > 0:
            gV.velocityDistribution.append(stats.norm.fit(velocities))
        else:
            gV.velocityDistribution.append((0, 0))

    return processData(gV.vehicleCrossingTimes, roadObject)
Exemple #10
0
#maybe for final results have a "max road length" parameter to change and compare to find how well it scales.
#6km roads do X fast,  10km roads do X fast
def timeSim(f, numIters):
    totalTime = 0
    for i in range(numIters):
        noTime(myRoad)
        turn = timer(f, myRoad)
        stats.turnTime[myRoad.turn] = turn
        totalTime += turn


#        print str(turn) + " : " + str(totalTime)
#        print ''

myRoad = road.Road()


def runBothPc(numIters):
    runPcSims(tests, numIters)
    runPcSims(baseCaseTests, numIters)


def runBothFlow(numIters):
    runFlowSims(tests, numIters)
    runFlowSims(baseCaseTests, numIters)


### Runs sensitivity analysis for k_threshold parameter
def runKTSims(f, numIters):
    global myRoad
Exemple #11
0
import sys
import os
import road
import road_convert


road_file = (sys.argv[sys.argv.index('--file')+1]
             if '--file' in sys.argv else None)
out_file = (sys.argv[sys.argv.index('--out')+1]
            if '--out' in sys.argv else None)
format = (sys.argv[sys.argv.index('--format')+1]
          if '--format' in sys.argv else None)
format = os.path.splitext(out_file)[1] if out_file else format

rd = road.Road()
rd.load_file(road_file)
if format == 'svg':
    road_convert.write_road_svg(rd, road_file + '.svg')
else:
    arg_center = '--no_center' not in sys.argv
    arg_yup = '--z_up' not in sys.argv
    unproj = road_convert.CurveUnproj3D()
    arg_lane_width = (int(sys.argv[sys.argv.index('--lane_width')+1])
                      if '--lane_width' in sys.argv else 10.0)
    road_convert.write_road_obj(rd, road_file + '.obj',
                                unproj, arg_center, arg_yup)
    road_convert.write_road_obj_mesh(rd, road_file + '.mesh.obj',
                                     arg_lane_width,
                                     unproj, arg_center, arg_yup)