当前位置: 首页>>代码示例>>Python>>正文


Python sumolib.checkBinary函数代码示例

本文整理汇总了Python中sumolib.checkBinary函数的典型用法代码示例。如果您正苦于以下问题:Python checkBinary函数的具体用法?Python checkBinary怎么用?Python checkBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了checkBinary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_start_cmd

 def get_start_cmd(self, init_time, gui=False, withdet=False):
     """
     Raise SUMO and run the simulation.
     :param init_time: strategy to controll traffic light
     :param gui: with GUI
     :param withdet: with detector(e1,e2,e3)
     :return:
     """
     self.init_time = init_time
     if gui:
         sumoBinary = checkBinary('sumo-gui')
     else:
         sumoBinary = checkBinary('sumo')
     if withdet:
         sumocfg = self.sumocfg
     else:
         sumocfg = self.sumocfg_nodet
     # self.task_record_dir = os.path.join(self.output_dir, init_time)
     self.task_record_dir = self.output_dir
     if not os.path.isdir(self.task_record_dir):
         os.makedirs(self.task_record_dir)
     self.summary_file = os.path.join(self.task_record_dir, self.netname+'_summary.xml')
     self.gen_detectors()
     self.sumocfg = self.gen_sumocfg()
     self.sumocfg_nodet = self.gen_sumocfg(withdetector=False)
     sumo_env = os.environ.copy()
     sumo_env['SUMO_HOME'] = sumo_root
     # sumoProcess = subprocess.Popen([sumoBinary, '-c', sumocfg, '--remote-port', str(port),
     #                                 '--summary', self.summary_file],
     #                                env=sumo_env, stdout=PIPE, stderr=PIPE)
     sumoCMD = [sumoBinary, '-c', sumocfg, '--summary', self.summary_file,
                '--time-to-teleport', '-1']
     # sumoProcess.wait()
     return sumoCMD, sumo_env
开发者ID:allenwoods,项目名称:parasys,代码行数:34,代码来源:create_cfg.py

示例2: build

def build(args=None, bindir=None):
    (options, args) = optParser.parse_args(args=args)

    if ((options.oldapi_prefix and options.osm_file) or
            not (options.oldapi_prefix or options.osm_file)):
        optParser.error(
            "exactly one of the options --osm-file and --oldapi-prefix must be supplied")
    if options.typemap and not path.isfile(options.typemap):
        # fail early because netconvert may take a long time
        optParser.error('typemap file "%s" not found' % options.typemap)
    if not (options.vehicle_classes in vclassRemove):
        optParser.error('invalid vehicle class "%s" given' %
                        options.vehicle_classes)
    if not path.isdir(options.output_directory):
        optParser.error('output directory "%s" does not exist' %
                        options.output_directory)

    netconvert = sumolib.checkBinary('netconvert', bindir)
    polyconvert = sumolib.checkBinary('polyconvert', bindir)

    netconvertOpts = [netconvert]
    if options.pedestrians:
        netconvertOpts += ['--sidewalks.guess', '--crossings.guess']
    if options.netconvert_typemap:
        netconvertOpts += ["-t", options.netconvert_typemap]
    netconvertOpts += options.netconvert_options.split(',') + ['--osm-files']
    polyconvertOpts = ([polyconvert] + options.polyconvert_options.split(',') +
                       ['--type-file', options.typemap, '--osm-files'])

    prefix = options.oldapi_prefix
    if prefix:  # used old API
        num = options.tiles
        tiles = ",".join(["%s%s_%s.osm.xml" % (prefix, i, num)
                          for i in range(num)])
        netconvertOpts += [tiles]
        polyconvertOpts += [tiles]
    else:  # used new API
        netconvertOpts += [options.osm_file]
        polyconvertOpts += [options.osm_file]
        prefix = path.basename(options.osm_file).replace('.osm.xml', '')

    if options.prefix:
        prefix = options.prefix

    basename = path.join(options.output_directory, prefix)
    netfile = prefix + '.net.xml'
    netconvertOpts += vclassRemove[options.vehicle_classes] + ["-o", netfile]

    # write config
    cfg = basename + ".netccfg"
    subprocess.call(netconvertOpts + ["--save-configuration", cfg])
    subprocess.call([netconvert, "-c", cfg])

    if options.typemap:
        # write config
        cfg = basename + ".polycfg"
        polyconvertOpts += ["-n", netfile, "-o", prefix + '.poly.xml']
        subprocess.call(polyconvertOpts + ["--save-configuration", cfg])
        subprocess.call([polyconvert, "-c", cfg])
开发者ID:fieryzig,项目名称:sumo,代码行数:59,代码来源:osmBuild.py

示例3: build

def build(args=None, bindir=None):
    (options, args) = optParser.parse_args(args=args)
    netconvert = sumolib.checkBinary('netconvert', bindir)
    polyconvert = sumolib.checkBinary('polyconvert', bindir)

    if ((options.oldapi_prefix and options.osm_file) or
            not (options.oldapi_prefix or options.osm_file)):
        optParser.error(
            "exactly one of the options --osm-file and --oldapi-prefix must be supplied")
    if options.typemap and not path.isfile(options.typemap):
        # fail early because netconvert may take a long time
        optParser.error('typemap file "%s" not found' % options.typemap)
    if not (options.vehicle_classes in vclassRemove):
        optParser.error('invalid vehicle class "%s" given' %
                        options.vehicle_classes)
    if not path.isdir(options.output_directory):
        optParser.error('output directory "%s" does not exist' %
                        options.output_directory)

    netconvertOpts = ' ' + \
        ' '.join(options.netconvert_options.split(',')) + ' --osm-files '
    if options.pedestrians:
        netconvertOpts = " --sidewalks.guess --crossings.guess" + \
            netconvertOpts
    if options.netconvert_typemap:
        netconvertOpts = " -t " + options.netconvert_typemap + netconvertOpts
    polyconvertOpts = ' ' + \
        ' '.join(options.polyconvert_options.split(',')) + \
        ' --type-file %s --osm-files ' % options.typemap

    prefix = options.oldapi_prefix
    if prefix:  # used old API
        num = options.tiles
        for i in range(num):
            if i != 0:
                netconvertOpts += ","
                polyconvertOpts += ","
            netconvertOpts += "%s%s_%s.osm.xml" % (prefix, i, num)
            polyconvertOpts += "%s%s_%s.osm.xml" % (prefix, i, num)

    else:  # used new API
        netconvertOpts += options.osm_file
        polyconvertOpts += options.osm_file
        prefix = path.basename(options.osm_file).replace('.osm.xml', '')

    if options.prefix:
        prefix = options.prefix

    remove = vclassRemove[options.vehicle_classes]
    netfile = path.join(options.output_directory, prefix + '.net.xml')
    polyfile = path.join(options.output_directory, prefix + '.poly.xml')

    call(netconvert + netconvertOpts + remove + " -o %s" % netfile)
    if options.typemap:
        call(polyconvert + polyconvertOpts + " -n %s -o %s" %
             (netfile, polyfile))
开发者ID:RamonHPSilveira,项目名称:urbansim,代码行数:56,代码来源:osmBuild.py

示例4: __inner_run__

    def __inner_run__(self, output_file):
        if self._options.gui:
            sumoBinary = checkBinary('sumo-gui')
            self.__sumoProcess = subprocess.Popen(
                [sumoBinary,"-W",
                "-n", self.conf.network_file,
                "-r", self.conf.route_file,
                "--tripinfo-output", output_file,
                "--remote-port", str(self.conf.port),
                "--gui-settings-file", self.conf.gui_setting_file,
                "--step-length", "1",
                "-v", "true",
                "--time-to-teleport", "-1"],
                stdout = sys.stdout, stderr=sys.stderr)
            time.sleep(20)

        else:
            sumoBinary = checkBinary('sumo')
            self.__sumoProcess = subprocess.Popen(
                [sumoBinary, "-W",
                "-n", self.conf.network_file,
                "-r", self.conf.route_file,
                "--tripinfo-output", output_file,
                "--remote-port", str(self.conf.port),
                "--step-length", "1",
                "-v", "true",
                "--time-to-teleport", "-1"],
                stdout = sys.stdout, stderr=sys.stderr)
            time.sleep(20)

        traci.init(self.conf.port)
        self.initIteration()

        while True:
            traci.simulationStep()

            if traci.simulation.getMinExpectedNumber() <= 0:
                break

            self.stepProcess()

            if traci.simulation.getCurrentTime() % self.conf.short_term_sec == 0:
                self.can_change_lane_list = []
                self.want_chage_vehicle_list = []

        self.endIteration()
        traci.close()

        if self._options.gui:
            os.system('pkill sumo-gui')
        sys.stdout.flush()
开发者ID:gg-uah,项目名称:ParkiNego,代码行数:51,代码来源:simulator.py

示例5: main

def main(options):
    if options.sumo is None:
        SUMO = sumolib.checkBinary('sumo')
    else:
        SUMO = options.sumo

    statsRetrievers = [(Statistics("%11s" % key), build_retriever(key)) for key in [
        'Inserted',
        'Running',
        'RouteLength',
        'Duration',
        'WaitingTime',
        'TimeLoss',
        'DepartDelay',
    ]]

    for i in range(options.numRuns):
        sys.stdout.write('.')
        sys.stdout.flush()
        seed = str(random.randint(0, 2**31))
        output = check_output([SUMO, '-c', options.config,
                               '--duration-log.statistics',
                               '--no-duration-log', 'false',
                               '--seed', seed])
        for stats, retriever in statsRetrievers:
            stats.add(retriever(output), seed)
    print()
    for stats, retriever in statsRetrievers:
        print(stats)
开发者ID:behrisch,项目名称:sumo,代码行数:29,代码来源:averageRuns.py

示例6: __init__

    def __init__(self, params, withDefaultDemand=True):
        Scenario.__init__(self, self.THIS_DIR)
        self.params = params
        if "equipment-rate" not in self.params:
            self.params["equipment-rate"] = 1
        # network
        if fileNeedsRebuild(os.path.join(self.THIS_DIR, self.NET_FILE), "netconvert"):
            netconvert = sumolib.checkBinary("netconvert")
            subprocess.call([netconvert, "-c", os.path.join(self.THIS_DIR, "build.netc.cfg")])
        # build the demand model (streams)
        if withDefaultDemand:
            self.demand = demandGenerator.Demand()
            for f in flowsRiLSA1:
                for rel in f[1]:
                    prob = rel[2] / 100.
                    iprob = 1. - prob

                    pkwEprob = iprob * self.params["equipment-rate"]
                    pkwNprob = iprob - pkwEprob
                    lkwEprob = prob * self.params["equipment-rate"]
                    lkwNprob = prob - lkwEprob

                    self.demand.addStream(demandGenerator.Stream(f[0] + "__" + rel[0], 0, 3600, rel[1], f[0], rel[0],
                                                                 {"passenger": pkwEprob,
                                                                  "COLOMBO_undetectable_passenger": pkwNprob,
                                                                  "hdv": lkwEprob,
                                                                  "COLOMBO_undetectable_hdv": lkwNprob}))
            if fileNeedsRebuild(self.fullPath("routes.rou.xml"), "duarouter"):
                self.demand.build(
                    0, 3600, self.fullPath(self.NET_FILE), self.fullPath("routes.rou.xml"))
            self.demandName = self.fullPath("routes.rou.xml")

        self.netName = self.sandboxPath(self.NET_FILE)
        shutil.copy(
            self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
开发者ID:fieryzig,项目名称:sumo,代码行数:35,代码来源:rilsa1_out_tls24.py

示例7: makeConfigFile

    def makeConfigFile(self):
        "Save the configuration for SUMO in a file"

        self.report("Generating configuration file")

        self.filename("guisettings", ".view.xml")
        with open(self.files["guisettings"], 'w') as f:
            f.write("""
<viewsettings>
    <scheme name="real world"/>
    <delay value="20"/>
</viewsettings>
""")
        sumo = sumolib.checkBinary("sumo")

        self.filename("config", ".sumocfg")
        opts = [sumo, "-n", self.files["net"], "--gui-settings-file", self.files["guisettings"],
                "--duration-log.statistics",
                "--device.rerouting.adaptation-steps", "180",
                "-v", "--no-step-log", "--save-configuration", self.files["config"], "--ignore-route-errors"]

        if self.routenames:
            opts += ["-r", ",".join(self.routenames)]

        if len(self.additionalFiles) > 0:
            opts += ["-a", ",".join(self.additionalFiles)]

        subprocess.call(opts)
开发者ID:fieryzig,项目名称:sumo,代码行数:28,代码来源:osmWebWizard.py

示例8: setUpClass

    def setUpClass(cls):
        """ setup generates all sumo files - once. """
        
        netcon_bin = sumolib.checkBinary('netconvert')
#        print ('xxxxxxxxxxxxxxxxxxx', netcon_bin)
        
        for node_file, net_file in [
                #(NODEFILE_2D, NETFILE_2D),
                (NODEFILE_3D, NETFILE_3D)
        ]:
            
            command    = [netcon_bin,
                          "-n", node_file,
                          "-e", EDGEFILE,
                          "-o", net_file,
                          "--offset.disable-normalization"]

            netconvertProcess = subprocess.call(
                command,
                stdout=sys.stdout,
                stderr=sys.stderr)
            
#        cls.sumo_net_2d = sumolib.net.readNet(
#            NETFILE_2D,
#            withInternal=True)

        cls.sumo_net = sumolib.net.readNet(
            NETFILE_3D,
            withInternal=True)
开发者ID:planetsumo,项目名称:sumo,代码行数:29,代码来源:unittests_shapes_coords_3d.py

示例9: build

 def build(self, b, e, netName="net.net.xml", routesName="input_routes.rou.xml", sampleFactor=None):
     vehicles = []
     running = 0
     for s in self.streams:
         vehicles.extend(s.toVehicles(b, e, len(vehicles), sampleFactor))
     fdo = tempfile.NamedTemporaryFile(mode="w", delete=False)
     fdo.write("<routes>\n")
     for v in sorted(vehicles, key=lambda veh: veh.depart):
         via = ""
         if v._via != None:
             via = ' via="%s"' % v._via
         if v.vType == "pedestrian":
             fdo.write('    <person id="%s" depart="%s" type="pedestrian"><walk from="%s" to="%s"/></person>\n' %
                       (v.id, v.depart, v.fromEdge, v.toEdge))
         else:
             fdo.write('    <trip id="%s" depart="%s" from="%s" to="%s" type="%s" %s/>\n' %
                       (v.id, v.depart, v.fromEdge, v.toEdge, v.vType, via))
     fdo.write("</routes>")
     fdo.close()
     duarouter = sumolib.checkBinary("duarouter")
     print "netName > %s" % netName
     print "routesName > %s" % routesName
     # aeh, implicitly setting --no-warnings is not nice, is it?; and the
     # need to dump generated vtypes to a temporary file as well
     retCode = subprocess.call([duarouter, "-v", "-n", netName,  "-t", fdo.name, "-o", routesName,
                                "--no-warnings", "--additional-files", "vtypes.add.xml", "--vtype-output", "tmp.add.xml"])
     os.remove(fdo.name)
开发者ID:sequielo,项目名称:sumo,代码行数:27,代码来源:demand.py

示例10: gen_network

 def gen_network(self, xnumber, ynumber, xlength, ylength,
                 nettype='grid', tlstype='static'):
     """
     Generate network model
     :param xnumber: nodes on x axis
     :param ynumber: nodes on y axis
     :param xlength: length of each edge on x axis
     :param ylength: length of each edge on y axis
     :param nettype: type of network, sumo support 'grid', 'spider', 'random'.
     :param tlstype:
     :return:
     """
     if int(xnumber) < 2 or int(ynumber) < 2:
         if xnumber == ynumber == str(1) and xlength == ylength:
             self.gen_intersection(xlength, tlstype)
             return 0
         else:
             raise ValueError('Grid sharp is not supported(yet)')
     netgenerate = checkBinary('netgenerate')
     netgenProcessor = subprocess.Popen([netgenerate, '--%s' % nettype,
                                         '--grid.x-number', xnumber, '--grid.y-number', ynumber,
                                         '--grid.x-length', xlength, '--grid.y-length', ylength,
                                         '--tls.guess', 'true', '--tls.default-type', tlstype,
                                         '--default.lanenumber', '2',
                                         '--check-lane-foes.all', 'true',
                                         '--%s.attach-length' % nettype, xlength,
                                         '--plain-output-prefix',
                                         os.path.join(self.data_dir, self.netname, self.netname),
                                         '-o', self.netfile], stdout=sys.stdout, stderr=sys.stderr)
开发者ID:allenwoods,项目名称:parasys,代码行数:29,代码来源:create_cfg.py

示例11: main

def main(args):
    sumoBinary = sumolib.checkBinary('sumo')
    sumo_call = [sumoBinary, "-c", "data/hello.sumocfg",
                 "--remote-port", str(PORT_TRACI),
                 "--netstate-dump", "rawdump.xml",
                 "--no-step-log"]
    sumoProcess = subprocess.Popen(
        sumo_call, stdout=sys.stdout, stderr=sys.stderr)
    traci.init(PORT_TRACI)

    for step in range(161):
        traci.simulationStep()
        if step == 120:
            print(traci.vehicle.getDistance('Stapler_00'))
            traci.vehicle.setRoute('Stapler_00', ('ed1', 'ed5'))
            print(traci.vehicle.getRoute('Stapler_00'))
            assert(traci.vehicle.getRoute('Stapler_00')
                   == ['ed0', 'ed1', 'ed5'])
            print(traci.vehicle.getDistance('Stapler_00'))
        if step == 122:
            assert(traci.vehicle.getRoute('Stapler_00')
                   == ['ed0', 'ed1', 'ed5'])
            print(traci.vehicle.getDistance('Stapler_00'))
            traci.vehicle.setRouteID('Stapler_00', "short")
            print(traci.vehicle.getRoute('Stapler_00'))
            print(traci.vehicle.getDistance('Stapler_00'))
    traci.close()
    sumoProcess.wait()
开发者ID:planetsumo,项目名称:sumo,代码行数:28,代码来源:runner.py

示例12: computeRoutesFromFlows

def computeRoutesFromFlows(netFile, detFile, flowFile, tazFile, grpFile, dfrouFile, emittFile, poiFile, vssFile,
                           beginSecs, endSecs, departPos, keepLongerRoutes, incUnusedRoutes, xmlValidation, routesForAll):
    shortRate = 0.1
    removeEmpty = True

    logger.info("............... Run the garouter ...")
    logger.info("Net file           : %s" % netFile)
    logger.info("Detection file     : %s" % detFile)
    logger.info("Flow measure file  : %s" % flowFile)
    logger.info("Taz file           : %s" % tazFile)
    logger.info("O/D group file     : %s" % grpFile)
    logger.info("DFRoute file       : %s" % dfrouFile)
    logger.info("Emitter file       : %s" % emittFile)
    logger.info("POI file           : %s" % poiFile)
    #logger.info("VSS file           : %s" % vssFile)
    logger.info("Begin secs         : %d" % beginSecs)
    logger.info("End secs           : %d" % endSecs)
    logger.info("Depart pos         : %s" % departPos)
    #logger.info("Keep longer routes : %s" % keepLongerRoutes)
    #logger.info("Inc. unused routes : %s" % incUnusedRoutes)
    logger.info("XML validation     : %s" % xmlValidation)
    logger.info("Shortest routes rate: %f" % shortRate)
    logger.info("Remove empty dets  : %s" % str(removeEmpty))
    #logger.info("Routes for all     : %s" % routesForAll)


    # Run the garouter
    garouterBin = checkBinary('garouter')
    options = ["--net-file", netFile,
               "--taz-file", tazFile,
               "--od-groups-file", grpFile,
               "--detector-files", detFile,
               "--measure-files", flowFile,
               "--routes-output", dfrouFile,
               "--emitters-output", emittFile,
              #"--routes-for-all", routesForAll,
               "--detectors-poi-output", poiFile,
               #"--variable-speed-sign-output", vssFile,
               "--departpos", departPos,
               "--shortest-routes-rate", str(shortRate),
               "--remove-empty-detectors", str(removeEmpty),
                #"--keep-longer-routes", keepLongerRoutes,
               #"--include-unused-routes", incUnusedRoutes,
               "--begin", str(beginSecs),
               "--end", str(endSecs),
               #"--xml-validation", xmlValidation,
               "--verbose"]
    #options = ["-c", os.path.join(const.BASE_DIR, const.CONFIG_DIR, "garouter.garcfg")]
    status = subprocess.call([garouterBin] + options,
                             stdout = sys.stdout,
                             stderr = sys.stderr)

    if status != 0:
        logger.critical("Fail: garouter terminated with error status [%s]" % status)
        sys.exit(1)
    else:
        logger.info("Success: garouter finished with status [%s]" % status)

    sys.stdout.flush()
开发者ID:gg-uah,项目名称:GARouter,代码行数:59,代码来源:runner.py

示例13: main

def main():
    # initialize all the required arguments
    args = get_options()
    if args.gui_enabled:
        sumo_path = checkBinary('sumo-gui')
    else:
        sumo_path = checkBinary('sumo')
    cfg_path = load_cfg(args.scenario)
    traci_port = args.traci_port

    sumo_process = subprocess.Popen("%s -c %s --remote-port %s" % (sumo_path, cfg_path, traci_port), stdout=sys.stdout)
    traci.init(int(traci_port))
    if args.event_enabled:
        run_ere(args.scenario, args.closed_roads.split(","), 300, 1200)
    else:
        run()
    sumo_process.wait()
开发者ID:ShenWangDCU,项目名称:adanrr,代码行数:17,代码来源:runner.py

示例14: __init__

 def __init__(self, options):
          # this script has been called from the command line. It will start sumo as a
     # server, then connect and run
     if options.gui:
         sumoBinary = checkBinary('sumo-gui')
     else:
         sumoBinary = checkBinary('sumo')
          
     self.rounds = 1000
     self.sumoProcess = subprocess.Popen([sumoBinary, "-n", self.PATH+"/"+self.CASENAME+".net.xml",'-r',self.PATH+"/"+self.CASENAME+".rou.xml",'-a',self.PATH+"/sensors.xml", "--remote-port", str(self.PORT)], stdout=DEVNULL#stdout=sys.stdout,
     ,stderr=sys.stderr)
 
     print "Opening a port at", self.PORT
     traci.init(self.PORT)
     print "Connection made with sumo"
     self.laneAreaList = traci.areal.getIDList()
     self.stoppedVehicleID = None
开发者ID:baumfalk,项目名称:SumoSensors,代码行数:17,代码来源:test.py

示例15: get_options

    def get_options(self):
        '''Get command line options'''

        optParser = OptionParser()
        optParser.add_option('--nogui', action='store_true', default=False, help='run the command line version of sumo')
        optParser.add_option('--nogen', action='store_true', default=False, help='run without road network generation')
        optParser.add_option('-p', '--prefix', dest='prefix', default='random', help='files names prefix')
        optParser.add_option('-s', '--size', dest='size', default='10', help='road network size')
        optParser.add_option('-a', '--alpha', dest='alpha', default='0.05', help='alpha parameter')
        optParser.add_option('-r', '--rate', dest='rate', default='2', help='repetition rate')
        optParser.add_option('-v', '--verbose', action='store_true', default=False, help='run with detailed information')
        optParser.add_option('-d', '--max-distance', dest='distance', default='500', help='maximum length of edge')
        self.options, args = optParser.parse_args()

        if self.options.nogui:
            self.sumoBinary = checkBinary('sumo')
        else:
            self.sumoBinary = checkBinary('sumo-gui')
开发者ID:OR2013,项目名称:OnlinePathOptimalization,代码行数:18,代码来源:simulation.py


注:本文中的sumolib.checkBinary函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。