Beispiel #1
0
def place_by_sumo(antenna,
                  car_material_id,
                  lane_boundary_dict,
                  margin_dict,
                  cars_with_antenna=None):
    antenna = copy.deepcopy(antenna)
    antenna.clear()

    structure_group = objects.StructureGroup()
    structure_group.name = 'SUMO cars'

    veh_i = None
    c_present = False
    for veh_i, veh in enumerate(traci.vehicle.getIDList()):
        (x, y), angle, lane_id, length, width, height = [
            f(veh) for f in [
                traci.vehicle.getPosition, traci.vehicle.getAngle,
                traci.vehicle.getLaneID, traci.vehicle.getWidth,
                traci.vehicle.getLength, traci.vehicle.getHeight
            ]
        ]

        x, y = coord.convert_distances(lane_id, (x, y),
                                       lane_boundary_dict=lane_boundary_dict,
                                       margin_dict=margin_dict)
        #print((x, y, -angle, veh))

        car = objects.RectangularPrism(length,
                                       width,
                                       height,
                                       material=car_material_id)

        # na posição final do carro a coordenada do SUMO vai ficar levemente deslocada, digo, ele passa no x, y o
        # centro da frente do carro, e eu assumo que essa coordenada é o centro do carro, senão eu teria que ver a
        # direção, acha ok se ficar assim?
        car.translate((-length / 2, -width / 2, 0))
        car.rotate(-angle)
        car.translate((x, y, 0))

        car_structure = objects.Structure(name=veh)
        car_structure.add_sub_structures(car)
        structure_group.add_structures(car_structure)

        #antenna_vertice
        if cars_with_antenna is None or veh in cars_with_antenna:
            c_present = True
            antenna.add_vertice((x, y, height))

    if not c_present:
        return None, None

    if veh_i is None:
        return None, None

    return structure_group, antenna
Beispiel #2
0
    import config as c

    with open(os.path.join("example", "SimpleFunciona",
                           "base.object")) as infile:
        obj = objects.ObjectFile.from_file(infile)

    x3d_xml = X3dXmlFile(
        os.path.join("example", "SimpleFunciona", "model.Study.xml"))

    with open(os.path.join("example", 'SimpleFunciona',
                           'base.txrx')) as infile:
        txrxFile = txrx.TxRxFile.from_file(infile)
    obj.clear()

    car = objects.RectangularPrism(1.76, 4.54, 1.47, material=0)
    car_structure = objects.Structure(name="car")
    car_structure.add_sub_structures(car)
    car_structure.dimensions = car.dimensions

    city_origin = np.array((648, 456, 0.2))
    antenna_origin = np.array((car.height / 2, car.width / 2, car.height))
    vertice_list = txrxFile['Rx'].location_list[0]

    structure_group, placed_vertice_list = place_on_line(
        city_origin, 531, 1, lambda: np.random.uniform(1, 3), car_structure,
        vertice_list, antenna_origin)
    obj.add_structure_groups(structure_group)
    obj.write(os.path.join('example', "SimpleFunciona", "random-line.object"))

    x3d_xml.add_vertice_list(placed_vertice_list, c.dst_txrx_xpath)
    x3d_xml.write(os.path.join("example", "SimpleFunciona", 'gen.study.xml'))
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        '--place-only',
                        action='store_true',
                        help='Run only the objects placement')
    parser.add_argument('-c',
                        '--run-calcprop',
                        action='store_true',
                        help='Run using calcprop')
    parser.add_argument('-s',
                        '--pause-each-run',
                        action='store_true',
                        help='Interactive run')
    parser.add_argument('-o',
                        '--remove-results-dir',
                        action='store_true',
                        help='ONLY IF YOU KNOW WHAT YOU ARE DOING')
    args = parser.parse_args()

    insite_project = insite.InSiteProject(setup_path=c.setup_path,
                                          xml_path=c.dst_x3d_xml_path.replace(
                                              ' ', '\ '),
                                          output_dir=c.project_output_dir,
                                          calcprop_bin=c.calcprop_bin,
                                          wibatch_bin=c.wibatch_bin)

    with open(os.path.join(c.base_insite_project_path,
                           "base.object")) as infile:
        objFile = objects.ObjectFile.from_file(infile)
    with open(os.path.join(c.base_insite_project_path, 'base.txrx')) as infile:
        txrxFile = txrx.TxRxFile.from_file(infile)
    x3d_xml_file = X3dXmlFile(c.base_x3d_xml_path)

    car = objects.RectangularPrism(*c.car_dimensions,
                                   material=c.car_material_id)
    car_structure = objects.Structure(name=c.car_structure_name)
    car_structure.add_sub_structures(car)
    car_structure.dimensions = car.dimensions

    antenna = txrxFile[c.antenna_points_name].location_list[0]

    try:
        shutil.copytree(
            c.base_insite_project_path,
            c.results_base_model_dir,
        )
    except FileExistsError:
        shutil.rmtree(c.results_dir)
        shutil.copytree(
            c.base_insite_project_path,
            c.results_base_model_dir,
        )

    if c.use_sumo:
        traci.start(c.sumo_cmd)

    scene_i = None
    episode_i = None
    for i in c.n_run:
        run_dir = os.path.join(c.results_dir, c.base_run_dir_fn(i))
        #os.makedirs(run_dir)

        objFile.clear()

        if c.use_sumo:

            # when to start a new episode
            if scene_i is None or scene_i >= c.time_of_episode:
                if episode_i is None:
                    episode_i = 0
                else:
                    episode_i += 1
                scene_i = 0
                # step time_between_episodes from the last one
                for count in range(c.time_between_episodes):
                    traci.simulationStep()
                # ensure that there enough cars to place antennas
                while len(traci.vehicle.getIDList()) < c.n_antenna_per_episode:
                    logging.error('not enough cars')
                    traci.simulationStep()
                cars_with_antenna = np.random.choice(traci.vehicle.getIDList(),
                                                     c.n_antenna_per_episode,
                                                     replace=False)
            else:
                traci.simulationStep()

            structure_group, location = place_by_sumo(
                antenna,
                c.car_material_id,
                lane_boundary_dict=c.lane_boundary_dict,
                margin_dict=c.margin_dict,
                cars_with_antenna=cars_with_antenna)
            print(traci.simulation.getCurrentTime())
            # no cars in the environment
            if location is None:
                logging.error(
                    "all antennas are out of the simulation, aborting episode")
                scene_i = np.inf
                continue
        else:
            structure_group, location = place_on_line(
                c.line_origin, c.line_destination, c.line_dimension,
                c.car_distances, car_structure, antenna, c.antenna_origin)

        objFile.add_structure_groups(structure_group)
        objFile.write(c.dst_object_file_name)
        #shutil.copy(c.dst_object_file_name, run_dir)

        x3d_xml_file.add_vertice_list(location, c.dst_x3d_txrx_xpath)
        x3d_xml_file.write(c.dst_x3d_xml_path)
        #shutil.copy(c.dst_x3d_xml_path, run_dir)

        txrxFile[c.antenna_points_name].location_list[0] = location
        txrxFile.write(c.dst_txrx_file_name)
        #shutil.copy(c.dst_txrx_file_name, run_dir)

        if not args.place_only:
            insite_project.run_x3d(output_dir=c.project_output_dir)

        if not args.place_only and args.run_calcprop:
            insite_project.run_calcprop(output_dir=run_dir, delete_temp=True)

        shutil.copytree(c.base_insite_project_path, run_dir)

        with open(os.path.join(run_dir, c.simulation_info_file_name),
                  'w') as infofile:
            info_dict = dict(
                cars_with_antenna=list(cars_with_antenna),
                scene_i=scene_i,
            )
            json.dump(info_dict, infofile)

        scene_i += 1

        if args.pause_each_run:
            input('Enter to step')
            sys.stdin.readline()

    traci.close()
def place_by_sumo(antenna, car_material_id, lane_boundary_dict, cars_with_antenna, use_fixed_receivers=False, use_pedestrians=False):
    antenna = copy.deepcopy(antenna)
    antenna.clear()

    structure_group = objects.StructureGroup()
    structure_group.name = 'SUMO cars'

    str_vehicles = ''
    veh_i = None
    c_present = False

    if use_pedestrians:
        for ped_i, ped in enumerate(traci.person.getIDList()):
            (x, y), angle, length, width = [f(ped) for f in [
                traci.person.getPosition,
                traci.person.getAngle, #Returns the angle of the named vehicle within the last step [degrees]
                traci.person.getLength,
                traci.person.getWidth
            ]]
            xinsite, yinsite = traci.simulation.convertGeo(x, y)
            pedestrian = objects.RectangularPrism(length, width, 1.72, material=car_material_id)
            pedestrian.translate((-length/2, -width/2, 0))
            pedestrian.rotate(90-angle) #use 90 degrees - angle to convert from y to x-axis the reference

            thisAngleInRad = np.radians(angle) #*np.pi/180
            deltaX = (length/2.0) * np.sin(thisAngleInRad)
            deltaY = (length/2.0) * np.cos(thisAngleInRad)
            pedestrian.translate((xinsite-deltaX, yinsite-deltaY, 0)) #now can translate

            pedestrian_structure = objects.Structure(name=ped)
            pedestrian_structure.add_sub_structures(pedestrian)
            structure_group.add_structures(pedestrian_structure)

            # 1.72 size of a perdestrian
            if c.use_vehicles_template:
                str_vehicles = get_model(str_vehicles,ped,xinsite-deltaX,yinsite-deltaY,0,90-angle,1.72) 

    for veh_i, veh in enumerate(traci.vehicle.getIDList()):
        (x, y), (x3,y3,z3), angle, lane_id, length, width, height = [f(veh) for f in [
            traci.vehicle.getPosition,
            traci.vehicle.getPosition3D, #Returns the 3D-position(three doubles) of the named vehicle (center of the front bumper) within the last step [m,m,m]
            traci.vehicle.getAngle,
            traci.vehicle.getLaneID,
            traci.vehicle.getLength,
            traci.vehicle.getWidth,
            traci.vehicle.getHeight
        ]]

        #x, y = coord.convert_distances(lane_id, (x,y), lane_boundary_dict=lane_boundary_dict)
        x, y = traci.simulation.convertGeo(x, y)
        #x2, y2 = traci.simulation.convertGeo(lon, lat, fromGeo=True)

        #the prism is draw using the first coordinate aligned with x, then y and z. Length is initially along x
        #and later the object will be rotates
        car = objects.RectangularPrism(length, width, height, material=car_material_id)

        #for proper rotation, first centralize the object on plane xy
        car.translate((-length/2, -width/2, 0))
        #now can rotate, but note SUMO assumes y-axis as the reference, and angle increases towards x-axis,
        #while we assume angles start from x-axis in our rotate method (see https://en.wikipedia.org/wiki/Rotation_matrix)
        car.rotate(90-angle) #use 90 degrees - angle to convert from y to x-axis the reference

        #SUMO reports position of middle of front bumper. We need to reposition to the middle of the vehicle
        #for that, use the angle to find to where the vehicle is facing and then translate
        thisAngleInRad = np.radians(angle) #*np.pi/180
        deltaX = (length/2.0) * np.sin(thisAngleInRad)
        deltaY = (length/2.0) * np.cos(thisAngleInRad)
        car.translate((x-deltaX, y-deltaY, z3)) #now can translate

        car_structure = objects.Structure(name=veh)
        car_structure.add_sub_structures(car)
        structure_group.add_structures(car_structure)

        if c.use_vehicles_template:
            str_vehicles = get_model(str_vehicles,veh,x-deltaX,y-deltaY,z3,90-angle,height,length,width) 

        #antenna_vertice
        if veh in cars_with_antenna:
            c_present = True
            #translate the antenna as the vehicle. Note the antenna is not rotated (we are using isotropic anyways)
            #adding Rx 0.1 above car's height, to ensure that it will not be blocked by the vehicle itself
            # if drone
            if ( veh.startswith('dflow') ):
                antenna.add_vertice((x-deltaX, y-deltaY, z3 - 0.1))
            else:
                antenna.add_vertice((x-deltaX, y-deltaY, z3 + height + 0.1))



    if c.use_vehicles_template:
        all_vehicles = str(vt.vehicles_template(searchList=[{'a':str_vehicles,'long':c.longitude,'lat':c.latitude}]))
    else:
        all_vehicles = ''
    if use_fixed_receivers:
        return structure_group, None, all_vehicles

    if not c_present: #there are no vehicles with antennas
        return None, None, None

    if veh_i is None: #there are no vehicles in the scene according to SUMO (traci)
        return None, None, None

    return structure_group, antenna, all_vehicles
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-p',
        '--place-only',
        action='store_true',
        help='Run only the objects placement and save files for ray-tracing')
    parser.add_argument(
        '-j',
        '--jump',
        action='store_true',
        help=
        'Jumping runs that already have results (works only if utilized with the option \'-r\' )'
    )
    parser.add_argument(
        '-r',
        '--ray-tracing-only',
        action='store_true',
        help='Run only ray-tracing with previoulsy generated files')
    parser.add_argument(
        '-c',
        '--run-calcprop',
        action='store_true',
        help='Ray-tracing with InSite calcprop instead of the default wibatch')
    parser.add_argument('-s',
                        '--pause-each-run',
                        action='store_true',
                        help='Interactive run')
    parser.add_argument(
        '-o',
        '--remove-results-dir',
        action='store_true',
        help=
        'ONLY IF YOU KNOW WHAT YOU ARE DOING: it will remove the whole results folder'
    )
    parser.add_argument(
        '-m',
        '--mimo-only',
        action='store_true',
        help=
        'Run only ray-tracing with native mimo from InSite previoulsy generated files'
    )
    args = parser.parse_args()

    #check consistency of user input
    if c.use_fixed_receivers:
        if c.n_antenna_per_episode != 0:
            print(
                'ERROR: if use_fixed_receivers=True, n_antenna_per_episode must be 0 but it is',
                c.n_antenna_per_episode)
            raise Exception()

    #setup_path=c.setup_path, xml_path=c.dst_x3d_xml_path.replace(' ', '\ ')
    #AK: now the constructor has fewer parameters
    insite_project = insite.InSiteProject(project_name='model',
                                          calcprop_bin=c.calcprop_bin,
                                          wibatch_bin=c.wibatch_bin)

    print('########## Start simulation #############################')
    if args.ray_tracing_only:
        if args.run_calcprop:
            print('Option -r is not compatible with -c')
            exit(-1)
        print(
            'Will run only ray-tracing. I am assuming all files have been placed.'
        )
        for i in c.n_run:
            run_dir = os.path.join(c.results_dir, c.base_run_dir_fn(i))
            #Ray-tracing output folder (where InSite will store the results (Study Area name)).
            #They will be later copied to the corresponding output folder specified by results_dir
            project_output_dir = os.path.join(
                run_dir, c.insite_study_area_name)  #output InSite folder

            p2mpaths_file = os.path.join(
                project_output_dir,
                c.insite_setup_name + '.paths.t001_01.r002.p2m')
            if not os.path.exists(p2mpaths_file) or args.remove_results_dir:
                xml_full_path = os.path.join(
                    run_dir, c.dst_x3d_xml_file_name)  #input InSite folder
                xml_full_path = xml_full_path.replace(' ', '\ ')
                insite_project.run_x3d(xml_full_path, project_output_dir)
            elif os.path.exists(p2mpaths_file) and args.jump:
                continue
            else:
                print("ERROR: " + p2mpaths_file +
                      " already exists, aborting simulation!")
                raise Exception()

        print('Finished running ray-tracing')
        exit(1)

    if args.mimo_only:
        if args.run_calcprop:
            print('Option -r is not compatible with -c')
            exit(-1)
        print(
            'Will run MIMO ray-tracing. I am assuming all files have been placed.'
        )
        for i in c.n_run:
            run_dir = os.path.join(c.results_dir, c.base_run_dir_fn(i))
            #Ray-tracing output folder (where InSite will store the results (Study Area name)).
            #They will be later copied to the corresponding output folder specified by results_dir
            project_output_dir = os.path.join(
                run_dir, c.insite_study_area_name)  #output InSite folder

            db_file = os.path.join(project_output_dir,
                                   c.insite_setup_name + '.study.sqlite')
            if not os.path.exists(db_file) or args.remove_results_dir:
                xml_full_path = os.path.join(
                    run_dir, c.dst_x3d_xml_file_name)  #input InSite folder
                xml_full_path = xml_full_path.replace(' ', '\ ')
                insite_project.run_x3d(xml_full_path, project_output_dir)
            elif os.path.exists(p2mpaths_file) and args.jump:
                continue
            else:
                print("ERROR: " + db_file +
                      " already exists, aborting simulation!")
                raise Exception()

        print('Finished running MIMO ray-tracing')
        exit(1)

    #copy files from initial (source folder) to results base folder
    try:
        shutil.copytree(
            c.base_insite_project_path,
            c.results_base_model_dir,
        )
    except FileExistsError:
        if args.remove_results_dir:
            shutil.rmtree(c.results_dir)
            print('Removed folder', c.results_dir)
            shutil.copytree(
                c.base_insite_project_path,
                c.results_base_model_dir,
            )
        else:
            print('### ERROR: folder / file exists:', c.results_base_model_dir)
            raise FileExistsError
    print('Copied folder ', c.base_insite_project_path, 'into',
          c.results_base_model_dir)

    #open InSite files that are used as the base to create each new scene / simulation
    with open(c.base_object_file_name) as infile:
        objFile = objects.ObjectFile.from_file(infile)
    print('Opened file with objects:', c.base_object_file_name)
    with open(c.base_txrx_file_name) as infile:
        txrxFile = txrx.TxRxFile.from_file(infile)
    print('Opened file with transmitters and receivers:',
          c.base_txrx_file_name)
    if c.insite_version == '3.3':
        x3d_xml_file = X3dXmlFile3_3(c.base_x3d_xml_path)
    else:
        x3d_xml_file = X3dXmlFile(c.base_x3d_xml_path)
    print('Opened file with InSite XML:', c.base_x3d_xml_path)

    #AK-TODO document and comment the methods below.
    car = objects.RectangularPrism(*c.car_dimensions,
                                   material=c.car_material_id)
    car_structure = objects.Structure(
        name=c.car_structure_name
    )  #AK-TODO what is the role of c.car_structure_name ?
    car_structure.add_sub_structures(car)
    car_structure.dimensions = car.dimensions

    antenna = txrxFile[c.antenna_points_name].location_list[0]

    if c.use_sumo:
        print('Starting SUMO Traci')
        traci.start(c.sumo_cmd)

    scene_i = None
    episode_i = None

    # Trick to start simulations from a given run as it was started from 0
    if c.n_run[0] != 0:
        tmp_var = 0
        while (tmp_var < int(c.n_run[0])):
            if c.use_sumo:
                # when to start a new episode
                if scene_i is None or scene_i >= c.time_of_episode:
                    #first scene of an episode
                    if episode_i is None:
                        episode_i = 0
                    else:
                        episode_i += 1
                    scene_i = 0
                    # step time_between_episodes from the last one
                    for count in range(c.time_between_episodes):
                        traci.simulationStep()

                    traci_vehicle_IDList = traci.vehicle.getIDList()
                    # Filter list to have only drones
                    if c.drone_simulation:
                        traci_vehicle_IDList = onlyDronesList(
                            traci.vehicle.getIDList())
                    while len(traci_vehicle_IDList) < c.n_antenna_per_episode:
                        traci_vehicle_IDList = traci.vehicle.getIDList()
                        if c.drone_simulation:
                            traci_vehicle_IDList = onlyDronesList(
                                traci.vehicle.getIDList())

                        logging.warning('not enough vehicles at time ' +
                                        str(traci.simulation.getCurrentTime()))
                        traci.simulationStep()
                    cars_with_antenna = np.random.choice(
                        traci_vehicle_IDList,
                        c.n_antenna_per_episode,
                        replace=False)
                else:
                    traci.simulationStep()
                scene_i += 1  #update scene counter
            tmp_var += 1
            print('Jump until the step ' + str(c.n_run[0]) + ': ' +
                  str(int((tmp_var / c.n_run[0]) * 100)) + '%')

    count_nar = 0  # Number of Runs without cars with antenna while mobile
    for i in c.n_run:

        run_dir = os.path.join(c.results_dir, c.base_run_dir_fn(i - count_nar))
        #Ray-tracing output folder (where InSite will store the results (Study Area name)).
        #They will be later copied to the corresponding output folder specified by results_dir
        project_output_dir = os.path.join(
            run_dir, c.insite_study_area_name)  #output InSite folder

        #Disabled below because the paths will be created later on by shutil.copytree
        #and shutil.copytree does not support folders that already exist
        #if not os.path.exists(run_dir):
        #os.makedirs(run_dir)

        objFile.clear()

        #if it's the beginning of the episode, the code searches for a minimium number of cars. After the
        #episode starts, then it does not do that. But it does not simulate scenarios without vehicles
        if c.use_sumo:
            # when to start a new episode
            if scene_i is None or scene_i >= c.time_of_episode:
                #first scene of an episode
                if episode_i is None:
                    episode_i = 0
                else:
                    episode_i += 1
                scene_i = 0
                # step time_between_episodes from the last one
                for count in range(
                        c.time_between_episodes
                ):  #AK-TODO should rename it and avoid calling "time"
                    traci.simulationStep()
                if c.use_fixed_receivers:
                    cars_with_antenna = []
                else:
                    # ensure that there enough cars to place antennas. If use_fixed_receivers, then wait to have at least
                    # one vehicle

                    traci_vehicle_IDList = traci.vehicle.getIDList()
                    # Filter list to have only drones
                    if c.drone_simulation:
                        traci_vehicle_IDList = onlyDronesList(
                            traci.vehicle.getIDList())
                    while len(traci_vehicle_IDList) < c.n_antenna_per_episode:
                        traci_vehicle_IDList = traci.vehicle.getIDList()
                        if c.drone_simulation:
                            traci_vehicle_IDList = onlyDronesList(
                                traci.vehicle.getIDList())
                        logging.warning('not enough vehicles at time ' +
                                        str(traci.simulation.getCurrentTime()))
                        traci.simulationStep()
                    cars_with_antenna = np.random.choice(
                        traci_vehicle_IDList,
                        c.n_antenna_per_episode,
                        replace=False)

            else:
                traci.simulationStep()

            structure_group, location, str_vehicles = place_by_sumo(
                antenna,
                c.car_material_id,
                lane_boundary_dict=c.lane_boundary_dict,
                cars_with_antenna=cars_with_antenna,
                use_fixed_receivers=c.use_fixed_receivers,
                use_pedestrians=c.use_pedestrians)

            #if location is None:  #there are not cars with antennas in this episode (all have left)
            # no vehicles in the environment (not only the ones without antennas, but no vehicles at all)
            if traci.vehicle.getIDList() is None:
                logging.warning("No vehicles in scene " + str(scene_i) +
                                " time " +
                                str(traci.simulation.getCurrentTime()))
                os.makedirs(
                    run_dir + '_novehicles'
                )  #create an empty folder to "indicate" the situation
                #save SUMO information for this scene as text CSV file
                #sumoOutputInfoFileName = os.path.join(run_dir,'sumoOutputInfoFileName_novehicles.txt')
                #writeSUMOInfoIntoFile(sumoOutputInfoFileName, episode_i, scene_i, c.lane_boundary_dict, cars_with_antenna)
                scene_i += 1  #update scene counter
                continue

            if location is None:  #there are not cars with antennas in this episode (all have left)
                if not c.use_fixed_receivers:
                    count_nar = count_nar + 1
                    #abort, there is not reason to continue given that there will be no receivers along the whole episode
                    logging.warning("No vehicles with antennas in scene " +
                                    str(scene_i) + " time " +
                                    str(traci.simulation.getCurrentTime()))
                    os.makedirs(
                        run_dir + '_noAntennaVehicles'
                    )  #create an empty folder to "indicate" the situation
                    scene_i = np.Infinity  #update scene counter
                    continue
        else:  #in case we should not use SUMO to position vehicles, then get a fixed position
            structure_group, location = place_on_line(
                c.line_origin, c.line_destination, c.line_dimension,
                c.car_distances, car_structure, antenna, c.antenna_origin)

        #Prepare the files for the input folder, where InSite will find them to execute the simulation
        #(obs: now InSite is writing directly to the output folder)
        shutil.copytree(c.base_insite_project_path, run_dir)
        print('Copied', c.base_insite_project_path, 'into', run_dir)

        #Writing to the final run folder
        objFile.add_structure_groups(structure_group)
        dst_object_full_path = os.path.join(run_dir, c.dst_object_file_name)
        objFile.write(dst_object_full_path)

        #write new model of vehicles to the final folder
        if c.use_vehicles_template:
            dst_new_object_full_path = os.path.join(
                run_dir, c.insite_vehicles_name_model + '.object')
            f_dst_new_object = open(dst_new_object_full_path, 'w')
            f_dst_new_object.write(str_vehicles)
            f_dst_new_object.close()

        #get name of XML
        xml_full_path = os.path.join(
            run_dir, c.dst_x3d_xml_file_name)  #input InSite folder
        xml_full_path = xml_full_path.replace(' ', '\ ')

        if not c.use_fixed_receivers:  #Marcus' workaround
            if not args.mimo_only:  #Ailton workaround
                x3d_xml_file.add_vertice_list(location, c.dst_x3d_txrx_xpath)
                x3d_xml_file.write(xml_full_path)

                txrxFile[c.antenna_points_name].location_list[0] = location
                # txrx modified in the RWI project
                dst_txrx_full_path = os.path.join(run_dir,
                                                  c.dst_txrx_file_name)
                txrxFile.write(dst_txrx_full_path)
            else:
                x3d_xml_file.add_vertice_list(location, c.dst_x3d_txrx_xpath)
                x3d_xml_file.write(xml_full_path)

                txrxFile[c.antenna_points_name].location_list[0] = location
                # txrx modified in the RWI project
                dst_txrx_full_path = os.path.join(run_dir,
                                                  c.dst_txrx_file_name)
                txrxFile.write(dst_txrx_full_path)

        #check if we should run ray-tracing
        if not args.place_only:
            if args.run_calcprop:
                #AK-TODO: Need to fix run_calcprop in insite.py: should not copy unless necessary (need to check)
                insite_project.run_calcprop(output_dir=project_output_dir,
                                            delete_temp=True)
            else:
                insite_project.run_x3d(xml_full_path, project_output_dir)

        with open(os.path.join(run_dir, c.simulation_info_file_name),
                  'w') as infofile:
            #if c.use_fixed_receivers:  #AK-TODO take in account fixed receivers
            #    listToBeSaved = list('only_fixed_receivers')
            #else:
            listToBeSaved = list(cars_with_antenna)
            info_dict = dict(
                cars_with_antenna=listToBeSaved,
                scene_i=scene_i,
            )
            json.dump(info_dict, infofile)  #write JSON infofile

        #save SUMO information for this scene as text CSV file
        sumoOutputInfoFileName = os.path.join(run_dir,
                                              'sumoOutputInfoFileName.txt')
        writeSUMOInfoIntoFile(sumoOutputInfoFileName, episode_i, scene_i,
                              c.lane_boundary_dict, cars_with_antenna,
                              c.use_fixed_receivers, c.use_pedestrians)

        scene_i += 1  #update scene counter

        if args.pause_each_run:
            input('Enter to step')
            sys.stdin.readline()

    traci.close()