<commit_before>#include "network_demand_data.h"

using namespace std;
using namespace network_models::network_information;

void demand_data_information::read_demand_vehicle(string input_dir_name,ScenarioData& scenario_data,DemandData& demand_data,NetworkData &network_data)
{
	//node
	//string time_file_name = input_dir_name + "demand_time.csv";
	//fstream time_file;
	//time_file.open(time_file_name,fstream::out);
	//double time_in_second_open_file_start = get_current_cpu_time_in_seconds();
	string file_name = input_dir_name + "vehicle";
	string line;
	ifstream input_file(file_name);

	//initialization
	demand_data.vehilce_data_array.clear();
	demand_data.vehicle_id_index_map.clear();

	demand_data.time_dependent_vehicle_index_array.resize(scenario_data.num_simulation_intervals*scenario_data.simulation_interval_length);

	demand_data.first_vehicle_departure_time = 24*60*60;
	demand_data.last_vehicle_departure_time = 0;
	int num_vehicles = 0;
	//double time_in_second_open_file = get_current_cpu_time_in_seconds() - time_in_second_open_file_start;

	if(input_file.is_open()) 
	{ 
		int iline = 0;
		int vehicle_index = -1;
		vector<string> tokens;
		int token_size =0;
		while (input_file.good())
		{
			//double time_in_second_read_getline_start = get_current_cpu_time_in_seconds();
			getline(input_file,line);
			//double time_in_second_getline = get_current_cpu_time_in_seconds() - time_in_second_read_getline_start;

			iline = iline + 1;

			//double time_in_second_read_parse_start = get_current_cpu_time_in_seconds();

			//double time_in_second_parse_tokens = 0.0;
			//double time_in_second_parse_tokens_start;
			if (iline == 2)
			{
				//time_in_second_parse_tokens_start = get_current_cpu_time_in_seconds();
				token_size = 3;
				string_split(tokens, line, token_size, "\t");
				//time_in_second_parse_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_tokens_start;

				demand_data.demand_vehicle_size = stoi(tokens[0]);
				demand_data.vehilce_data_array.resize(demand_data.demand_vehicle_size);
			}
			
			//double time_in_second_parse_read_tokens = 0.0;
			//double time_in_second_parse_map = 0.0;
			//double time_in_second_parse_vehicle_data = 0.0;

			if(iline > 3) // skip the first line
			{
				
				//time_in_second_parse_tokens_start = get_current_cpu_time_in_seconds();
				token_size = 8;
				string_split(tokens, line, token_size, "\t");
				//time_in_second_parse_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_tokens_start;

				//double time_in_second_parse_read_tokens_start = get_current_cpu_time_in_seconds();
				int vehicle_id = stoi(tokens[0]);
				int origin_zone_id = stoi(tokens[1]);
				int destination_zone_id = stoi(tokens[2]);
				int origin_activity_location_id = stoi(tokens[3]);
				int destination_activity_location_id = stoi(tokens[4]);
				int origin_link_id = stoi(tokens[5]);
				int destination_link_id = stoi(tokens[6]);
				int departure_time = convert_hhmmss_to_seconds(tokens[7]);
				
				//time_in_second_parse_read_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_read_tokens_start;

				//double time_in_second_parse_map_start = get_current_cpu_time_in_seconds();
				int origin_zone_index = network_data.zone_id_index_map[origin_zone_id];
				int destination_zone_index = network_data.zone_id_index_map[destination_zone_id];
				int origin_activity_location_index = network_data.activity_location_id_index_map[origin_activity_location_id];
				int destination_activity_location_index = network_data.activity_location_id_index_map[destination_activity_location_id];
				int origin_link_index = network_data.link_id_index_map[origin_link_id];
				int destination_link_index = network_data.link_id_index_map[destination_link_id];
				//time_in_second_parse_map = get_current_cpu_time_in_seconds() - time_in_second_parse_map_start;

				//double time_in_second_parse_vehicle_data_start = get_current_cpu_time_in_seconds() ;
				if (departure_time < scenario_data.simulation_start_time || departure_time >= scenario_data.simulation_end_time)
				{
					continue;
				}
				else
				{
					departure_time = departure_time -scenario_data.simulation_start_time;
				}
				
				vehicle_index = vehicle_index + 1;
				VehicleData& vehicle_data = demand_data.vehilce_data_array[vehicle_index];

				num_vehicles++;
				vehicle_data.set_vehicle_index(vehicle_index);
				vehicle_data.set_vehicle_id(vehicle_id);

				vehicle_data.set_origin_zone_index(origin_zone_index);
				vehicle_data.set_destination_zone_index(destination_zone_index);
				vehicle_data.set_origin_activity_location_index(origin_activity_location_index);
				vehicle_data.set_destination_activity_location_index(destination_activity_location_index);
				vehicle_data.set_origin_link_index(origin_link_index);
				vehicle_data.set_destination_link_index(destination_link_index);
				vehicle_data.set_seed(scenario_data.iseed+vehicle_index);
				
				int simulation_interval_index;
				simulation_interval_index = departure_time/scenario_data.simulation_interval_length;
				int assignment_interval_index;
				assignment_interval_index = int((simulation_interval_index+1) *scenario_data.simulation_interval_length / scenario_data.assignment_interval_length);

				vehicle_data.set_departure_assignment_interval_index(assignment_interval_index);
				vehicle_data.set_departure_simulation_interval_index(simulation_interval_index);
				vehicle_data.set_departure_time(departure_time);
				vehicle_data.init();

				if (demand_data.first_vehicle_departure_time>=departure_time+scenario_data.simulation_start_time)
				{
					demand_data.first_vehicle_departure_time = departure_time+scenario_data.simulation_start_time;
				}

				if (demand_data.last_vehicle_departure_time<=departure_time+scenario_data.simulation_start_time)
				{
					demand_data.last_vehicle_departure_time = departure_time+scenario_data.simulation_start_time;
				}

				demand_data.time_dependent_vehicle_index_array[departure_time].push_back(vehicle_index);
				//time_in_second_parse_vehicle_data = get_current_cpu_time_in_seconds() - time_in_second_parse_vehicle_data_start;
			}
			//double time_in_second_parse = get_current_cpu_time_in_seconds() - time_in_second_read_parse_start;
			//time_file
			//	<<time_in_second_open_file << ","
			//	<<time_in_second_getline << ","
			//	<<time_in_second_parse_tokens << ","
			//	<<time_in_second_parse << ","
			//	<<time_in_second_parse_read_tokens << ","
			//	<<time_in_second_parse_map << ","
			//	<<time_in_second_parse_vehicle_data << ","
			//	<<endl;
		}
		demand_data.vehilce_data_array.shrink_to_fit();
		demand_data.demand_vehicle_size = (int)demand_data.vehilce_data_array.size();
	}
	else
	{<commit_msg>new feature of start simulation from any time<commit_after>#include "network_demand_data.h"

using namespace std;
using namespace network_models::network_information;

void demand_data_information::read_demand_vehicle(string input_dir_name,ScenarioData& scenario_data,DemandData& demand_data,NetworkData &network_data)
{
	//node
	//string time_file_name = input_dir_name + "demand_time.csv";
	//fstream time_file;
	//time_file.open(time_file_name,fstream::out);
	//double time_in_second_open_file_start = get_current_cpu_time_in_seconds();
	string file_name = input_dir_name + "vehicle";
	string line;
	ifstream input_file(file_name);

	//initialization
	demand_data.vehilce_data_array.clear();
	demand_data.vehicle_id_index_map.clear();

	demand_data.time_dependent_vehicle_index_array.resize(scenario_data.num_simulation_intervals*scenario_data.simulation_interval_length);

	demand_data.first_vehicle_departure_time = 24*60*60;
	demand_data.last_vehicle_departure_time = 0;
	int num_vehicles = 0;
	//double time_in_second_open_file = get_current_cpu_time_in_seconds() - time_in_second_open_file_start;

	if(input_file.is_open()) 
	{ 
		int iline = 0;
		int vehicle_index = -1;
		vector<string> tokens;
		int token_size =0;
		while (input_file.good())
		{
			//double time_in_second_read_getline_start = get_current_cpu_time_in_seconds();
			getline(input_file,line);
			//double time_in_second_getline = get_current_cpu_time_in_seconds() - time_in_second_read_getline_start;

			iline = iline + 1;

			//double time_in_second_read_parse_start = get_current_cpu_time_in_seconds();

			//double time_in_second_parse_tokens = 0.0;
			//double time_in_second_parse_tokens_start;
			if (iline == 2)
			{
				//time_in_second_parse_tokens_start = get_current_cpu_time_in_seconds();
				token_size = 3;
				string_split(tokens, line, token_size, "\t");
				//time_in_second_parse_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_tokens_start;

				demand_data.demand_vehicle_size = stoi(tokens[0]);
				demand_data.vehilce_data_array.resize(demand_data.demand_vehicle_size);
			}
			
			//double time_in_second_parse_read_tokens = 0.0;
			//double time_in_second_parse_map = 0.0;
			//double time_in_second_parse_vehicle_data = 0.0;

			if(iline > 3) // skip the first line
			{
				
				//time_in_second_parse_tokens_start = get_current_cpu_time_in_seconds();
				token_size = 8;
				string_split(tokens, line, token_size, "\t");
				//time_in_second_parse_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_tokens_start;

				//double time_in_second_parse_read_tokens_start = get_current_cpu_time_in_seconds();
				int vehicle_id = stoi(tokens[0]);
				int origin_zone_id = stoi(tokens[1]);
				int destination_zone_id = stoi(tokens[2]);
				int origin_activity_location_id = stoi(tokens[3]);
				int destination_activity_location_id = stoi(tokens[4]);
				int origin_link_id = stoi(tokens[5]);
				int destination_link_id = stoi(tokens[6]);
				int departure_time = convert_hhmmss_to_seconds(tokens[7]);
				
				//time_in_second_parse_read_tokens = get_current_cpu_time_in_seconds() - time_in_second_parse_read_tokens_start;

				//double time_in_second_parse_map_start = get_current_cpu_time_in_seconds();
				int origin_zone_index = network_data.zone_id_index_map[origin_zone_id];
				int destination_zone_index = network_data.zone_id_index_map[destination_zone_id];
				int origin_activity_location_index = network_data.activity_location_id_index_map[origin_activity_location_id];
				int destination_activity_location_index = network_data.activity_location_id_index_map[destination_activity_location_id];
				int origin_link_index = network_data.link_id_index_map[origin_link_id];
				int destination_link_index = network_data.link_id_index_map[destination_link_id];
				//time_in_second_parse_map = get_current_cpu_time_in_seconds() - time_in_second_parse_map_start;

				//double time_in_second_parse_vehicle_data_start = get_current_cpu_time_in_seconds() ;
				if (departure_time < scenario_data.simulation_start_time || departure_time >= scenario_data.simulation_end_time)
				{
					continue;
				}
				else
				{
					departure_time = departure_time -scenario_data.simulation_start_time;
				}
				
				vehicle_index = vehicle_index + 1;
				VehicleData& vehicle_data = demand_data.vehilce_data_array[vehicle_index];

				num_vehicles++;
				vehicle_data.set_vehicle_index(vehicle_index);
				vehicle_data.set_vehicle_id(vehicle_id);

				vehicle_data.set_origin_zone_index(origin_zone_index);
				vehicle_data.set_destination_zone_index(destination_zone_index);
				vehicle_data.set_origin_activity_location_index(origin_activity_location_index);
				vehicle_data.set_destination_activity_location_index(destination_activity_location_index);
				vehicle_data.set_origin_link_index(origin_link_index);
				vehicle_data.set_destination_link_index(destination_link_index);
				vehicle_data.set_seed(scenario_data.iseed+vehicle_index);
				
				int simulation_interval_index;
				simulation_interval_index = departure_time/scenario_data.simulation_interval_length;
				int assignment_interval_index;
				assignment_interval_index = int((simulation_interval_index+1) *scenario_data.simulation_interval_length / scenario_data.assignment_interval_length);

				vehicle_data.set_departure_assignment_interval_index(assignment_interval_index);
				vehicle_data.set_departure_simulation_interval_index(simulation_interval_index);
				vehicle_data.set_departure_time(departure_time);
				vehicle_data.init();

				if (demand_data.first_vehicle_departure_time>=departure_time+scenario_data.simulation_start_time)
				{
					demand_data.first_vehicle_departure_time = departure_time+scenario_data.simulation_start_time;
				}

				if (demand_data.last_vehicle_departure_time<=departure_time+scenario_data.simulation_start_time)
				{
					demand_data.last_vehicle_departure_time = departure_time+scenario_data.simulation_start_time;
				}

				demand_data.time_dependent_vehicle_index_array[departure_time].push_back(vehicle_index);
				//time_in_second_parse_vehicle_data = get_current_cpu_time_in_seconds() - time_in_second_parse_vehicle_data_start;
			}
			//double time_in_second_parse = get_current_cpu_time_in_seconds() - time_in_second_read_parse_start;
			//time_file
			//	<<time_in_second_open_file << ","
			//	<<time_in_second_getline << ","
			//	<<time_in_second_parse_tokens << ","
			//	<<time_in_second_parse << ","
			//	<<time_in_second_parse_read_tokens << ","
			//	<<time_in_second_parse_map << ","
			//	<<time_in_second_parse_vehicle_data << ","
			//	<<endl;
		}
		demand_data.vehilce_data_array.shrink_to_fit();
		//demand_data.demand_vehicle_size = (int)demand_data.vehilce_data_array.size();
		demand_data.demand_vehicle_size = num_vehicles;
	}
	else
	{
{'fraction_non_alphanumeric': 0.08723592849756241, 'fraction_numerical': 0.005170630816959669, 'mean_word_length': 6.081066945606694, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493529', 'n_tokens_mistral': 5404, 'n_tokens_neox': 4625, 'n_words': 509}