Ejemplo n.º 1
0
    def modify_workplace_accessibility(self):
        
        study_zone = 908
        
        # set workplace accessibility for the preferered zone and other zones
        min_wpa = '3.0'    # time in minutes
        max_wpa = '15.0'    # travel const in ???
        
        logger.log_status("Zone ID study zone = %s" %study_zone)
        
        in_file = open(self.workplace_accessibility_destination, 'r')
        str_list = []
        # read header of travel data to get the indices of the colums (from_zone, to_zone, single_vehicle_travel_time)
        line = in_file.readline()
        # init indices
        get_indices = GetIndices(line)
        index_zone_id = get_indices.get_zone_id_index()
        index_wpa   = get_indices.get_workplace_asseccibility_index()
        number_of_colums = get_indices.get_number_of_colums()
        
        # prepare header line for the output file
        row = line.split(',')
        str_list.append( row[index_zone_id].strip('\r\n') +','+ row[index_wpa].strip('\r\n') +'\r\n')
        
        # get first line of the table content
        line = in_file.readline()
        
        # replaces the travel times as decribed above...
        while line:
            row = line.split(',')
            # consistency check
            if len(row) != number_of_colums:
                raise StandardError('Error in number of colums: %s' %row)
            
            zone_id = int(row[index_zone_id].strip('\r\n'))
            
            if zone_id == study_zone:
                row[index_wpa] = max_wpa
            else:
                row[index_wpa] = min_wpa
                
            # append modified row to the new travel data content
            str_list.append( row[index_zone_id].strip('\r\n') +','+ row[index_wpa].strip('\r\n') +'\r\n')

            line = in_file.readline()
        
        # finished modifying traval data
        in_file.close()
        # now write new travel data onto disc
        out_file = open(self.workplace_accessibility_destination, 'w')
        logger.log_status("Copying modified travel data onto disc.")
        for row in str_list:
            out_file.write(row)
        out_file.close();
        logger.log_status("Finished copy process.")
Ejemplo n.º 2
0
    def modify_travel_data(self):
        """ Modifies the travel times and costs between cbd and study zone 909
            
            @old version
            Modifies the travel times from zone to zone.
            For zone 20 the travel times to all other zones is set to min_travel_time.
            For all other zones the trvel time will be set on 31min if the origin travel time
            is less than 30min, otherwise it's not modified.
        """
        
        # using default cbd 
        cbd = 129
        # set the preferred zone
        study_zone = 908
        # set travel times for the preferered zone and other zones
        min_travel_time = '0.40'    # time in minutes
        min_travel_cost = '3.47'    # travel const in ???
        
        logger.log_status("Set the following travel time and cost between cbd and study zone:")
        logger.log_status("Zone ID cbd = %s" %cbd)
        logger.log_status("Zone ID study zone = %s" %study_zone)
        logger.log_status("Travel time = %s" %min_travel_time)
        logger.log_status("Travel cost = %s" %min_travel_cost)
        
        travel_data = paths.get_opus_home_path( "opus_matsim", "tmp", "travel_data.csv" )
        if not self.travel_data_exsists(travel_data):
            raise StandardError('Travel data not found! %s' % travel_data)
            
        in_file = open(travel_data, 'r')
        str_list = []
        # read header of travel data to get the indices of the colums (from_zone, to_zone, single_vehicle_travel_time)
        line = in_file.readline()
        # init indices
        get_indices = GetIndices(line)
        index_from_zone = get_indices.get_from_zone_index()
        index_to_zone   = get_indices.get_to_zone_index()
        index_travel_times = get_indices.get_am_single_vehicle_to_work_travel_time_index()
        index_travel_costs = get_indices.get_single_vehicle_to_work_travel_cost_index()
        number_of_colums = get_indices.get_number_of_colums()
        
        # prepare header line for the output file
        row = line.split(',')
        str_list.append( row[index_from_zone].strip('\r\n') +','+ row[index_to_zone].strip('\r\n') +','+ row[index_travel_times].strip('\r\n') + ',' + row[index_travel_costs].strip('\r\n') +'\r\n')
        
        # get first line of the table content
        line = in_file.readline()
        
        # replaces the travel times as decribed above...
        while line:
            row = line.split(',')
            # consistency check
            if len(row) != number_of_colums:
                raise StandardError('Error in number of colums: %s' %row)
                
            from_zone_id = int(row[index_from_zone].strip('\r\n'))
            to_zone_id = int(row[index_to_zone].strip('\r\n'))
            
            
            # just sets the travel time and cost from cbd2studyzone and 
            # from stuyzone2cbd to the defined values above
            if (from_zone_id == cbd and to_zone_id == study_zone):
                row[index_travel_times] = min_travel_time
                row[index_travel_costs] = min_travel_cost
            
            elif (from_zone_id == study_zone and to_zone_id == cbd):
                row[index_travel_times] = min_travel_time
                row[index_travel_costs] = min_travel_cost
        
            # append modified row to the new travel data content
            str_list.append( row[index_from_zone].strip('\r\n') +','+ row[index_to_zone].strip('\r\n') +','+ row[index_travel_times].strip('\r\n') + ',' + row[index_travel_costs].strip('\r\n') +'\r\n')

            line = in_file.readline()
        
        # finished modifying traval data
        in_file.close()
        # now write new travel data onto disc
        out_file = open(travel_data, 'w')
        logger.log_status("Copying modified travel data onto disc.")
        for row in str_list:
            out_file.write(row)
        out_file.close();
        logger.log_status("Finished copy process.")