예제 #1
0
bool Travel_Time_File::Create_Fields (void) 
{
	Add_Field ("HHOLD", DB_INTEGER, 4, NO_UNITS, true);
	Add_Field ("PERSON", DB_INTEGER, 2, NO_UNITS, true);
	Add_Field ("TOUR", DB_INTEGER, 1, NO_UNITS, true);
	Add_Field ("TRIP", DB_INTEGER, 1, NO_UNITS, true);
	if (Code_Flag ()) {
		Add_Field ("MODE", DB_INTEGER, 1, MODE_CODE, true);
		Add_Field ("PURPOSE", DB_INTEGER, 1, NO_UNITS, true);
		Add_Field ("CONSTRAINT", DB_INTEGER, 1, CONSTRAINT_CODE, true);
	} else {
		Add_Field ("MODE", DB_STRING, 12, MODE_CODE);
		Add_Field ("PURPOSE", DB_INTEGER, 2);
		Add_Field ("CONSTRAINT", DB_STRING, 14, CONSTRAINT_CODE);
	}
	Add_Field ("START_LINK", DB_INTEGER, 10);
	Add_Field ("END_LINK", DB_INTEGER, 10);

	Add_Field ("TRIP_START", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("BASE_START", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("STARTED", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("START_DIFF", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("TRIP_END", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("BASE_END", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("ENDED", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("END_DIFF", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("MID_TRIP", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("TTIME", DB_TIME, TIME_FIELD_SIZE, Time_Format ());

	return (Set_Field_Numbers ());
}
예제 #2
0
파일: Dtime.cpp 프로젝트: kravitz/transims5
string Dtime::Time_Label (bool pad_flag)
{
	if (!pad_flag) return (Time_Label ());

	int hour, minute, seconds, min_time, hour_time;
	double time;
	String text;
	Units_Type time_format = Time_Format ();

	time = UnRound (DTOI (dtime));

	min_time = 60;
	hour_time = min_time * 60;

	if (time > 3 * MIDNIGHT) {
		time = 3 * MIDNIGHT;
	}
	if (time_format == HOURS) {
		text ("%09.6lf") % (time / hour_time);
	} else if (time_format == SECONDS) {
		text ("%05d") % time;
	} else {
		seconds = DTOI (time);
		hour = seconds / hour_time;
		seconds -= hour * hour_time;
		minute = seconds / min_time;
		seconds -= minute * min_time;

		text ("%02d%02d%02d") % hour % minute % seconds;
	}
	return (text);
}
예제 #3
0
파일: Dtime.cpp 프로젝트: kravitz/transims5
string Dtime::Time_Label (Units_Type time_format)
{
	int hour, minute, seconds, min_time, hour_time;
	double time;
	String text;

	if (time_format == NO_UNITS) time_format = Time_Format ();

	time = UnRound (DTOI (dtime));

	min_time = 60;
	hour_time = min_time * 60;

	if (time > 3 * MIDNIGHT) {
		time = 3 * MIDNIGHT;
	}
	if (time_format == HOURS) {
		text (time / hour_time);
	} else if (time_format == SECONDS) {
		text (time);
	} else {
		seconds = DTOI (time);
		hour = seconds / hour_time;
		seconds -= hour * hour_time;
		minute = seconds / min_time;
		seconds -= minute * min_time;

		if (seconds > 0) {
			text ("%d%02d%02d") % hour % minute % seconds;
		} else {
			text ("%d%02d") % hour % minute;
		}
	}
	return (text);
}
예제 #4
0
Db_Base::Db_Base (string filename, Access_Type access, Format_Type format) : 
	Db_File (access, format)
{
	Time_Format (NO_UNITS);
	Dbase_Format (format);

	Open (filename);
}
예제 #5
0
bool Skim_File::Create_Fields (void) 
{
	Clear_Fields ();

	Matrix_File::Create_Fields ();

	if (time_flag) {
		Add_Field ("TIME", DB_TIME, 4, Time_Format (), true);
	} else {
		if (mode == WAIT_MODE) {
			Add_Field ("WAIT", DB_TIME, 2, Time_Format (), true);
		} else if (mode == BIKE_MODE || mode == OTHER_MODE) {
			Add_Field ("OTHER", DB_TIME, 2, Time_Format (), true);
		} else {
			Add_Field ("WALK", DB_TIME, 2, Time_Format (), true);

			if (mode != WALK_MODE) {
				if (mode != RIDE_MODE && mode != TRANSIT_MODE && mode != TAXI_MODE) {
					Add_Field ("DRIVE", DB_TIME, 4, Time_Format (), true);
				}
				if (mode != DRIVE_MODE) {
					if (mode != RIDE_MODE && mode != TAXI_MODE) {
						Add_Field ("TRANSIT", DB_TIME, 4, Time_Format (), true);
					}
					Add_Field ("WAIT", DB_TIME, 2, Time_Format (), true);
				}
				Add_Field ("OTHER", DB_TIME, 2, Time_Format (), true);
			}
		}
	}
	if (Length_Format () == MILES || Length_Format () == KILOMETERS) {
		Add_Field ("LENGTH", DB_DOUBLE, 4.2, Length_Format (), true);
	} else {
		Add_Field ("LENGTH", DB_INTEGER, 4, Length_Format (), true);
	}
	if (len_flag) {
		Db_Field *fld = Field ("LENGTH");

		if (fld->Units () != Length_Format ()) {
			fld->Units (Length_Format ());
		}
	}
	Add_Field ("COST", DB_INTEGER, 2, CENTS, true);
	Add_Field ("IMPEDANCE", DB_INTEGER, 4, IMPEDANCE, true);

	return (Set_Field_Numbers ());
}
예제 #6
0
bool Link_Delay_File::Create_Fields (void) 
{
	Add_Field ("LINK", DB_INTEGER, 10);
	Add_LinkDir_Field ();
	if (type_flag) {
		Add_Field ("TYPE", DB_INTEGER, 1);
	}
	Add_Field ("START", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("END", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
	Add_Field ("FLOW", DB_DOUBLE, 9.2, flow_units);
	Add_Field ("TIME", DB_TIME, 8.1, SECONDS);
	if (turn_flag) {
		Nest (NESTED);
		Header_Lines (2);
		Add_Field ("NCONNECT", DB_INTEGER, 2);
		Add_Field ("OUT_LINK", DB_INTEGER, 10, NO_UNITS, false, NESTED);
		Add_Field ("OUT_FLOW", DB_DOUBLE, 9.2, flow_units, false, NESTED);
		Add_Field ("OUT_TIME", DB_TIME, 8.1, SECONDS, false, NESTED);
	} else {
		Nest (NO_NEST);
		Header_Lines (1);
	}
	return (Set_Field_Numbers ());
}
예제 #7
0
파일: Dtime.cpp 프로젝트: kravitz/transims5
void Dtime::Time_Label (string label, Units_Type time_format)
{
	String time;

	if (time_format == NO_UNITS) time_format = Time_Format ();

	dtime = 0;
	time = label;
	time.Trim (" \t");

	if (time.empty ()) {
		exe->Warning ("Time Label Conversion ");
		return;
	}
	if (time.find_first_of (".:") == time.npos) {
		size_t len = time.length ();
			
		//---- scan for clock time ----

		if (len >= 3 && len <= 4) {
			bool flag = false;

			if (time [0] == '0') {
				flag = true;
			} else if (len == 4) {
				if (time [0] <= '2' && time [2] <= '5') {
					flag = true;
				}
			} else if (time [1] <= '5') {
				flag = true;
			}
			if (flag) {
				if (len == 4) {
					time.insert (2, ":");
				} else {
					time.insert (1, ":");
				}
			}
		}
	}
	Time_String (time, time_format);
	return;
}
예제 #8
0
bool Snapshot_File::Create_Fields (void)
{
    if (compress) {
        Add_Field ("COMPRESS", DB_STRING, (int) sizeof (Compressed_Snapshot), METERS, true);
    } else {
        Add_Field ("HHOLD", DB_INTEGER, 10);
        Add_Field ("VEHICLE", DB_INTEGER, 4);
        if (Cell_Flag ()) {
            Add_Field ("CELL", DB_INTEGER, 1, NO_UNITS, true);
        }
        Add_Field ("TIME", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
        Add_Field ("LINK", DB_INTEGER, 10);
        Add_LinkDir_Field ();
        if (Code_Flag ()) {
            Add_Field ("LANE", DB_UNSIGNED, 1, LANE_ID_CODE, true);
        } else {
            Add_Field ("LANE", DB_STRING, 4, LANE_ID_CODE);
        }
        Add_Field ("OFFSET", DB_DOUBLE, 8.1, METERS);
        Add_Field ("SPEED", DB_DOUBLE, 8.1, KPH);
        Add_Field ("PASSENGERS", DB_INTEGER, 4);
        Add_Field ("TYPE", DB_INTEGER, 4, VEH_TYPE);
        if (Status_Flag ()) {
            Add_Field ("WAIT", DB_INTEGER, 6, SECONDS);
            Add_Field ("TIME_DIFF", DB_INTEGER, 10, SECONDS);
            Add_Field ("USER", DB_INTEGER, 3);
        }
        if (Location_Flag ()) {
            Add_Field ("X_COORD", DB_DOUBLE, 14.1, METERS);
            Add_Field ("Y_COORD", DB_DOUBLE, 14.1, METERS);
            Add_Field ("Z_COORD", DB_DOUBLE, 14.1, METERS);
            Add_Field ("BEARING", DB_DOUBLE, 6.1, DEGREES);
        }
    }
    return (Set_Field_Numbers ());
}
예제 #9
0
void ArcSnapshot::Set_Veh_Types (void)
{
	int type, fld;
	double size;
	String buffer;
	Integers int_rec;

	Veh_Type_Itr veh_type_itr;

	//---- process vehicle type data ----

	max_type = 0;

	for (veh_type_itr = veh_type_array.begin (); veh_type_itr != veh_type_array.end (); veh_type_itr++) {
		type = veh_type_itr->Type ();
		if (type > max_type) max_type = type;
	}
	max_type++;

	//---- initialize the vehicle length array ----

	veh_length.assign (max_type, cell_size);

	//---- set vehicle length and cell size ----

	size = 1000;

	for (veh_type_itr = veh_type_array.begin (); veh_type_itr != veh_type_array.end (); veh_type_itr++) {
		type = veh_type_itr->Type ();
		veh_length [type] = UnRound (veh_type_itr->Length ());

		if (veh_length [type] < size) {
			size = veh_length [type];
		}
	}
	if (size < cell_size) cell_size = size;

	//---- allocate link arrays ----

	if (sum_flag) {
		num_links = (int) link_array.size ();

		vehicles.assign (max_type, int_rec);
		persons.assign (max_type, int_rec);
		veh_fld.assign (max_type, -1);
		per_fld.assign (max_type, -1);

		summary_file.Add_Field ("LINK", DB_INTEGER, 10);
		summary_file.Add_Field ("START", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
		summary_file.Add_Field ("END", DB_TIME, TIME_FIELD_SIZE, Time_Format ());
		summary_file.Add_Field ("VEHICLES", DB_INTEGER, 10);
		summary_file.Add_Field ("PERSONS", DB_INTEGER, 10);

		link_fld = summary_file.Field_Number ("LINK");
		start_fld = summary_file.Field_Number ("START");
		end_fld = summary_file.Field_Number ("END");

		veh_fld [0] = summary_file.Field_Number ("VEHICLES");
		per_fld [0] = fld = summary_file.Field_Number ("PERSONS");

		for (type=0; type < max_type; type++) {
			if (type > 0 && select_vehicles && !vehicle_range.In_Range (type)) continue;

			if (type > 0) {
				buffer = String ("VEH%d") % type;
				summary_file.Add_Field (buffer, DB_INTEGER, 10);
				veh_fld [type] = fld++;

				buffer = String ("PER%d") % type;
				summary_file.Add_Field (buffer, DB_INTEGER, 10);
				per_fld [type] = fld++;
			}
			vehicles [type].assign (num_links, 0);
			persons [type].assign (num_links, 0);
		}
		summary_file.Write_Header ();
	}
}
예제 #10
0
Db_Base::Db_Base (Access_Type access, Format_Type format) : 
	Db_File (access, format)
{
	Time_Format (NO_UNITS);
	Dbase_Format (format);
}
예제 #11
0
파일: Dtime.cpp 프로젝트: kravitz/transims5
void  Dtime::Time_String (string text, bool duration, Units_Type time_format)
{
	//---- NOON ----
	//---- MIDNIGHT ----
	//---- d@hh:mm:ss.x -----
	//---- d@hh:mm -----
	//---- [email protected] ----
	//---- d@ssssss ----
	//---- hh:mm:ss -----
	//---- hh:mm -----
	//---- hh:mmpm -----
	//---- hh.xxx ----
	//---- ssssss ----
	//---- dddhh:mm ----
	
	static const char *day_text [] = {
		"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "WKE", "WKD", "ALL", 0
	};
	int hour, min_time, hour_time, day_time;
	size_t index;
	char ch;
	bool sign;
	String result, time;
	Strings clock;
	Str_Itr itr;

	if (time_format == NO_UNITS) time_format = Time_Format ();

	dtime = 0;
	time = text;
	time.Trim (" \t");

	if (time.empty ()) return;

	//---- negative ----

	if (time [0] == '-') {
		if (!duration && time_format != SECONDS && time_format != MINUTES) {
			if (!warning_flag) goto time_error;
			return;
		}
		time.erase (0, 1);
		sign = true;
	} else {
		sign = false;
	}
	min_time = Round (60);
	hour_time = min_time * 60;
	day_time = hour_time * 24;

	//---- day ----

	if (time.find ("@") != time.npos) {
		if (time.Split (result, "@")) {
			if (result.empty () || result [0] < '0' || result [0] > '9') goto time_error;

			dtime = result.Integer () * day_time;
			if (time.empty ()) goto finish;
		}
	}

	//---- check for special codes ----

	if (time [0] < '0' || time [0] > '9') {
		if (time.Equals ("NOON")) {
			dtime += day_time / 2;
			goto finish;
		} 
		if (time.Equals ("MIDNIGHT")) {
			goto finish;
		}

		//---- VERSION3 Time Codes ----

		for (int i=0; day_text [i] != 0; i++) {
			if (time.Starts_With (day_text [i])) {
				time.erase (0, strlen (day_text [i]));

				if (time.empty ()) goto finish;
				if (time.find (":") != time.npos) {
					if (time.Split (result, ":")) {
						dtime = Round (result.Integer () * 3600 + time.Integer () * 60);
					}
				} else if (time [0] < '0' || time [0] > '9') {
					goto time_error;
				} else {
					dtime = Round (time.Integer () * 3600);
				}
				goto finish;
			}
		}
	}

	//---- check time units ----

	if (time.Parse (clock, ":") < 1) goto finish;

	itr = clock.begin ();
	ch = (*itr) [0];

	if (clock.size () == 1) {
		if ((ch < '0' || ch > '9') && ch != '.') goto time_error;

		if (time_format == SECONDS) {
			dtime += Round (itr->Double ()); 
		} else if (time_format == MINUTES) {
			dtime += DTOI (itr->Double () * min_time);
		} else if (time_format == HOURS) {
			dtime += DTOI (itr->Double () * hour_time); 
		} else if (itr->find ('.') != itr->npos) {
			dtime += DTOI (itr->Double () * hour_time); 
		} else {
			dtime += Round (itr->Double ());
		}
		goto finish;
	}

	//---- hour of the day ----

	if (ch < '0' || ch > '9') goto time_error;

	hour = itr->Integer ();

	dtime += hour * hour_time;

	if (++itr == clock.end ()) goto finish;

	//---- minute of the hour ----
	
	ch = (*itr) [0];
	if (ch < '0' || ch > '5' || itr->length () != 2) goto time_error;

	dtime += itr->Integer () * min_time;

	if (++itr == clock.end ()) goto finish;

	//---- seconds of the minute ----

	ch = (*itr) [0];
	if (ch < '0' || ch > '5') goto time_error;

	index = itr->find ('.');

	if (index != itr->npos) {
		if (index != 2) goto time_error;
		dtime += Round (itr->Double ()); 
	} else {
		if (itr->length () != 2) goto time_error;
		dtime += Round (itr->Double ());
	}
finish:
	if (sign) dtime = -dtime;
	return;

time_error:
	exe->Warning ("Time Conversion ") << text;
	warning_flag = true;
}
예제 #12
0
파일: Dtime.cpp 프로젝트: kravitz/transims5
string Dtime::Time_String (Units_Type time_format)
{
	int day, hour, minute, min_time, hour_time, day_time;
	double time;
	String text;

	if (time_format == NO_UNITS) time_format = Time_Format ();

	time = UnRound (dtime);
	min_time = 60;
	hour_time = min_time * 60;
	day_time = hour_time * 24;

	if (time >= MAX_INTEGER) {
		time = MIDNIGHT;
	} else if (time > 3 * MIDNIGHT) {
		time = 3 * MIDNIGHT;
	}
	if (time_format == HOURS) {
		text (time / hour_time);

		if (text.find ('.') == text.npos) {
			text += ".0";
		}
		return (text);
	} else if (time_format == MINUTES) {
		return (text (time / min_time, 2));
	} else if (time_format == SECONDS) {
		return (text (time));
	} else if (time_format == TIME_CODE) {
		hour = (int) (time / hour_time);
		time -= hour * hour_time;
		minute = (int) (time / 60);
		return (text ("ALL%02d:%02d") % hour % minute);
	}

	//---- check for negative values ----

	if (time < 0) {
		text = "-";
		time = -time;
	}

	//---- clock formating ----

	if (time >= day_time) {
		if (time == day_time) {
			text += "24:00";
			return (text);
		}
		if (time_format == DAY_TIME) {
			text += "%d@";
			day = (int) (time / day_time);
			text % day;
			time -= day * day_time;
		}
	}
	hour = (int) (time / hour_time);
	time -= hour * hour_time;
	minute = (int) (time / min_time);
	time -= minute * min_time;

	text += "%d:%02d";
	text % hour % minute;

	if (time > 0) {
		int second = (int) time;
		time -= second;

		text += ":%02d";
		text % second;

		if (time > 0) {
			text += ".%d";
			text % Round (time);
		}
	}
	return (text);
}