Exemple #1
0
def main(options):
    if options.seed:
        random.seed(options.seed)

    net = sumolib.net.readNet(options.netfile)
    if options.min_distance > net.getBBoxDiameter() * (options.intermediate +
                                                       1):
        options.intermediate = int(
            math.ceil(options.min_distance / net.getBBoxDiameter())) - 1
        print(
            "Warning: setting number of intermediate waypoints to %s to achieve a minimum trip length of %s in a network with diameter %s."
            % (options.intermediate, options.min_distance,
               net.getBBoxDiameter()))

    edge_generator = RandomTripGenerator(
        RandomEdgeGenerator(net, get_prob_fun(options, "_incoming",
                                              "_outgoing")),
        RandomEdgeGenerator(net, get_prob_fun(options, "_outgoing",
                                              "_incoming")),
        RandomEdgeGenerator(net, get_prob_fun(options, None, None)),
        options.intermediate)

    idx = 0
    with open(options.tripfile, 'w') as fouttrips:
        print >> fouttrips, """<?xml version="1.0"?>
<!-- generated on %s by $Id: randomTrips.py 16365 2014-05-13 08:50:42Z namdre $ 
  options: %s
-->
<trips>""" % (datetime.datetime.now(),
              (' '.join(sys.argv[1:]).replace('--', '<doubleminus>')))
        depart = options.begin
        while depart < options.end:
            label = "%s%s" % (options.tripprefix, idx)
            try:
                source_edge, sink_edge, intermediate = edge_generator.get_trip(
                    options.min_distance, options.max_distance,
                    options.maxtries)
                via = ""
                if len(intermediate) > 0:
                    via = 'via="%s" ' % ' '.join(
                        [e.getID() for e in intermediate])
                if options.pedestrians:
                    print >> fouttrips, '    <person id="%s" depart="%.2f" %s>' % (
                        label, depart, options.tripattrs)
                    print >> fouttrips, '        <walk from="%s" to="%s"/>' % (
                        source_edge.getID(), sink_edge.getID())
                    print >> fouttrips, '    </person>'
                else:
                    print >> fouttrips, '    <trip id="%s" depart="%.2f" from="%s" to="%s" %s%s/>' % (
                        label, depart, source_edge.getID(), sink_edge.getID(),
                        via, options.tripattrs)
            except Exception, exc:
                print exc
            idx += 1
            depart += options.period
        fouttrips.write("</trips>")
Exemple #2
0
def main(options):
    if options.seed:
        random.seed(options.seed)

    net = sumolib.net.readNet(options.netfile)
    if options.min_distance > net.getBBoxDiameter():
        sys.exit("Cannot find trips with min-distance %s for net with diamter %s" % (
            options.min_distance, self.net_diameter))


    edge_generator = RandomTripGenerator(
            RandomEdgeGenerator(net, get_prob_fun(options, "_incoming", "_outgoing")),
            RandomEdgeGenerator(net, get_prob_fun(options, "_outgoing", "_incoming")))

    idx = 0
    with open(options.tripfile, 'w') as fouttrips:
        print >> fouttrips, """<?xml version="1.0"?>
<!-- generated on %s by $Id$ -->
<trips>""" % datetime.datetime.now()
        depart = options.begin
        while depart < options.end:
            label = "%s%s" % (options.tripprefix, idx)
            source_edge, sink_edge = edge_generator.get_trip(options.min_distance)
            print >> fouttrips, '    <trip id="%s" depart="%.2f" from="%s" to="%s" %s/>' % (
                    label, depart, source_edge.getID(), sink_edge.getID(), options.trippar)
            idx += 1
            depart += options.period
        fouttrips.write("</trips>")

    if options.routefile:
        subprocess.call(['duarouter', '-n', options.netfile, '-t', options.tripfile, '-o', options.routefile, '--ignore-errors',
            '--begin', str(options.begin), '--end', str(options.end)])
def main(options):
    if options.seed:
        random.seed(options.seed)

    net = sumolib.net.readNet(options.netfile)
    if options.min_distance > net.getBBoxDiameter() * (options.intermediate + 1):
        options.intermediate = int(math.ceil(options.min_distance / net.getBBoxDiameter())) - 1
        print("Warning: setting number of intermediate waypoints to %s to achieve a minimum trip length of %s in a network with diameter %s." % (
                options.intermediate, options.min_distance, net.getBBoxDiameter()))

    edge_generator = RandomTripGenerator(
            RandomEdgeGenerator(net, get_prob_fun(options, "_incoming", "_outgoing")),
            RandomEdgeGenerator(net, get_prob_fun(options, "_outgoing", "_incoming")),
            RandomEdgeGenerator(net, get_prob_fun(options, None, None)),
            options.intermediate)

    idx = 0
    with open(options.tripfile, 'w') as fouttrips:
        print >> fouttrips, """<?xml version="1.0"?>
<!-- generated on %s by $Id: randomTrips.py 16365 2014-05-13 08:50:42Z namdre $ 
  options: %s
-->
<trips>""" % (datetime.datetime.now(), (' '.join(sys.argv[1:]).replace('--','<doubleminus>')))
        depart = options.begin
        while depart < options.end:
            label = "%s%s" % (options.tripprefix, idx)
            try:
                source_edge, sink_edge, intermediate = edge_generator.get_trip(options.min_distance, options.max_distance, options.maxtries)
                via = ""
                if len(intermediate) > 0:
                    via='via="%s" ' % ' '.join([e.getID() for e in intermediate])
                if options.pedestrians:
                    print >> fouttrips, '    <person id="%s" depart="%.2f" %s>' % (label, depart, options.tripattrs)
                    print >> fouttrips, '        <walk from="%s" to="%s"/>' % (source_edge.getID(), sink_edge.getID())
                    print >> fouttrips, '    </person>' 
                else:
                    print >> fouttrips, '    <trip id="%s" depart="%.2f" from="%s" to="%s" %s%s/>' % (
                            label, depart, source_edge.getID(), sink_edge.getID(), via, options.tripattrs)
            except Exception, exc:
                print exc
            idx += 1
            depart += options.period
        fouttrips.write("</trips>")
def main(options):
    if options.seed:
        random.seed(options.seed)

    net = sumolib.net.readNet(options.netfile)
    if options.min_distance > net.getBBoxDiameter() * (options.intermediate + 1):
        options.intermediate = int(math.ceil(options.min_distance / net.getBBoxDiameter())) - 1
        print("Warning: setting number of intermediate waypoints to %s to achieve a minimum trip length of %s in a network with diameter %s." % (
                options.intermediate, options.min_distance, net.getBBoxDiameter()))

    edge_generator = RandomTripGenerator(
            RandomEdgeGenerator(net, get_prob_fun(options, "_incoming", "_outgoing")),
            RandomEdgeGenerator(net, get_prob_fun(options, "_outgoing", "_incoming")),
            RandomEdgeGenerator(net, get_prob_fun(options, None, None)),
            options.intermediate)

    idx = 0
    with open(options.tripfile, 'w') as fouttrips:
        print >> fouttrips, """<?xml version="1.0"?>
<!-- generated on %s by $Id: randomTrips-new.py 16365 2014-05-13 08:50:42Z namdre $ 
  options: %s
-->
<trips>""" % (datetime.datetime.now(), (' '.join(sys.argv[1:]).replace('--','<doubleminus>')))
        # (smendez) March 11, 2015

        # According to our source documents, weekend flow is different, and
        # depends also on day of the weekend, saturday is more trafficked (may
        # mainly be because of people working saturday)

        #              0      3       6      9       12     15      18     21
        demandsVector=[1,0,0, 0,0,1,  2,4,8, 4,2,2,  2,3,4, 3,3,2,  3,4,5, 4,3,2]
        if options.day == 5 or options.day == 6:
          '''
          demandsVector=
             NIGHT             MORNING           AFTERNOON         EVENING
             0-1h    3-4h      6-7h    9-10h     12-13h  15-16h    18-19h  21-22h
            [0,0,0,  0,0,0,    1,2,3,  2,1,1,    1,2,3,  3,2,1,    1,2,2,  2,1,1]
          '''
          #              0     3     6     9     12    15    18    21
          demandsVector = [1,0,0,0,0,1,2,3,4,4,3,2,2,3,3,3,3,3,4,5,5,4,3,2]
          if options.day == 5:
            #                0     3     6     9     12    15    18    21
            demandsVector = [1,0,0,0,0,1,2,3,4,4,3,2,2,3,3,3,3,3,3,4,4,4,3,2]
        # Flows are different for friday
        if options.day == 4:
          #                0     3     6     9     12    15    18    21
          demandsVector = [1,0,0,0,0,1,2,3,6,3,2,2,2,3,4,3,3,3,4,5,5,4,3,2]
        # There also less people at tuesday, wednesday and thursday morning
        if options.day == 1 or options.day == 2 or options.day == 3:
          demandsVector = [1,0,0,0,0,1,2,3,7,3,2,2,2,3,4,3,3,2,3,4,5,4,3,2]

        for depart in range(options.begin, options.end, options.period):
            if depart%3600==0:
                print str(dt.now())+': Now entering the '+ str((int(options.startTime)+depart/3600)%24)+' timeframe'

            actualMultiplier = 0
            # print 'str(int(options.startTime)+depart/3600){'+ str((int(options.startTime)+depart/3600)%24)+'}'
            # print 'str(demandsVector[int(options.startTime)+depart/3600]){'+ str(demandsVector[(int(options.startTime)+depart/3600)%24])+'}'
            actualMultiplier+=demandsVector[(int(options.startTime)+depart/3600)%24]

            for i in range(actualMultiplier):
                label = "%s%s" % (options.tripprefix, idx)
                try:
                    source_edge, sink_edge, intermediate = edge_generator.get_trip(options.min_distance, options.max_distance, options.maxtries)
                    via = ""
                    if len(intermediate) > 0:
                        via='via="%s" ' % ' '.join([e.getID() for e in intermediate])
                    if options.pedestrians:
                        print >> fouttrips, '    <person id="%s" depart="%.2f" %s>' % (label, depart, options.tripattrs)
                        print >> fouttrips, '        <walk from="%s" to="%s"/>' % (source_edge.getID(), sink_edge.getID())
                        print >> fouttrips, '    </person>' 
                    else:
                        print >> fouttrips, '    <trip id="%s" depart="%.2f" from="%s" to="%s" %s%s/>' % (
                                label, depart, source_edge.getID(), sink_edge.getID(), via, options.tripattrs)
                except Exception, exc:
                    print exc
                idx += 1

        fouttrips.write("</trips>")