def run():
    if len(sys.argv) < 2:
        print('Please provide the path to the .sumocfg of a SUMO scenario')
        exit()

    print('started')

    ## GUI / CLI
    #     traci.start(["sumo-gui", "-c", sys.argv[1]])
    traci.start(["sumo", "-W", "-c", sys.argv[1]])
    print('traci init')

    step = 0

    startTime = datetime.now()
    print('started at ', startTime.strftime('%Y-%m-%dT%H:%M:%SZ'))
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        step += 1

        if (step % 1000 == 0):
            print('\nTime: ',
                  datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'), '\n')
    traci.close()

    endTime = datetime.now()
    print("Simulation Time:", startTime.strftime('%Y-%m-%dT%H:%M:%SZ'),
          endTime.strftime('%Y-%m-%dT%H:%M:%SZ'), "differnce:",
          (endTime - startTime).strftime('%Y-%m-%dT%H:%M:%SZ'))

    sys.stdout.flush()
Example #2
0
 def _simulation_end(self):
     if self.visual == False:
         libsumo.close()
         return
     else:
         traci.close()
         return
Example #3
0
    def reset(self):
        """Resets the state of the environment and returns an initial observation.

        Returns: observation (object): the initial observation of the
            space.
        """
        traci.close()

        traci.start(self.cmd)
        self._step = self.begin_time
        # Begin with action id of 1 
        if not self.idle:
            self._action = 1
            self._setTrafficLights(self._action)
        else:
            self._action = self._getTrafficLights()
        
        return (np.zeros(shape=(21,)), 1)
Example #4
0
def main():
    # CAUTION! step is in MILLISECONDS in version 0.30.0, but in SECONDS in version 1.1.0
    #step = BEGIN_TIME*1000
    step = BEGIN_TIME
    #while step < END_TIME*1000:
    while step <= END_TIME:
        
##        if step%(3600*1000) == 0:
##            print("Current Time: {}:00".format(step//(3600*1000)))
         
##        for edge in edge_charoenRat:
##            for lane in range(0,NUM_LANES[edge]):
##                print("{}: {}".format(lane, traci.lanearea.getLastStepOccupancy("e2_{}_{}_0".format(edge,lane))))
        
        traci.simulationStep(step=step)
##        traci.simulationStep()
##        step += STEP_SIZE*1000
        step += STEP_SIZE
    
    
    print(step)
    traci.close()
Example #5
0
def main():
    step = float(BEGIN_TIME)

    SIMULATION_STEPS = (END_TIME -
                        BEGIN_TIME) // 5 + 1  # 1 for the beginning step
    print()

    while step < END_TIME:
        #break
        if step % 3600 == 0:
            print("Current Time: {}:00".format(step // 3600))

        for edge in edge_charoenRat:
            for lane in range(0, NUM_LANES[edge]):
                print("{}: {}".format(
                    lane,
                    traci.lanearea.getLastStepOccupancy("e2_{}_{}_0".format(
                        edge, lane))))

        traci.simulationStep(step=step)
        step += STEP_SIZE

    print(step)
    traci.close()
Example #6
0
      traci.edge.getAdaptedTraveltime(edgeID, 25))

traci.edge.setEffort(edgeID, 1234.)
print("effort after adaption", traci.edge.getEffort(edgeID, 0))

traci.edge.setEffort(edgeID, 2468., 10, 20)
print("effort after adaption in interval (check time 0)",
      traci.edge.getEffort(edgeID, 0))
print("effort after adaption in interval (check time 15)",
      traci.edge.getEffort(edgeID, 15))
print("effort after adaption in interval (check time 25)",
      traci.edge.getEffort(edgeID, 25))

traci.edge.setMaxSpeed(edgeID, 23.)
print("max speed after adaption", traci.lane.getMaxSpeed(edgeID + "_0"))

traci.edge.subscribe(edgeID)
print(traci.edge.getSubscriptionResults(edgeID))
for step in range(3, 6):
    print("step", step)
    traci.simulationStep()
    print(traci.edge.getSubscriptionResults(edgeID))
for step in range(10):
    traci.simulationStep()
    print("3si count=%s meanSpeed=%s travelTime=%s" %
          (traci.edge.getLastStepVehicleNumber("3si"),
           traci.edge.getLastStepMeanSpeed("3si"),
           traci.edge.getTraveltime("3si")))

traci.close()
Example #7
0
 def close(self):
     """Override _close in your subclass to perform any necessary cleanup.
     Environments will automatically close() themselves when
     garbage collected or when the program exits.
     """
     traci.close()
Example #8
0
    parser.add_argument('--episodes', default=1500000, type=int)

    args = parser.parse_args()
    print(args)

    background, shift = get_background(
        'simulation_files/networks/simple.net.xml')

    net = sumolib.net.readNet('simulation_files/networks/simple.net.xml')
    bounding_box = net.getBBoxXY()

    sumocfg = "simulation_files/networks/simple.net.xml"
    libsumo.start(['-c', sumocfg])
    edges = libsumo.edge.getIDList()
    print(edges)
    libsumo.close()
    '''

    all_episodes = []
    for step_range in range(1, 150, 3):
        total_reward = step = action = 0
        action = 1
        s = env.reset()
        terminal = False
        mistakes = 0; total_est = 0
        while not terminal:
            if step % step_range == 0:
                action = not action
                action = np.random.choice(range(2))
                ns, r, terminal, _ = env.step(action)
                cars = s[1]