示例#1
0
bool ModeChoice::Household_Processing (Db_File *fh)
{
	Household_File *file = (Household_File *) fh;

	if (hhlist_flag) {
		if (First_Record ()) {
			if (!household_db.Max_Records (hhold_list.Num_Records ())) goto mem_error;
		}
		if (hhold_list.Get_Index (file->Household ()) == 0) return (false);
	} else if (First_Record ()) {
		if (!household_db.Max_Records (file->Max_Record_Number ())) goto mem_error;
	}

	//---- copy the data for user programs ----

	household_db.Copy_Fields (file);

	if (!household_db.Add_Record ()) {
		Error ("Writing Household Database");
	}
	return (false);

mem_error:
	Error ("Insufficient Memory for Household Database");
	return (false);
}
示例#2
0
bool LocationChoice::Household_Processing (Db_File *fh)
{
	Household_Data *household_ptr;
	Household_File *file;

	file = (Household_File *) fh;

	if (First_Record ()) {
		int max_rec;

		if (hhlist_flag) {
			max_rec = hhold_list.Num_Records ();
		} else {
			max_rec = file->Estimate_Records ();
		}
		if (!household_data.Max_Records (max_rec)) goto mem_error;

		if (choice_flag) {
			if (!household_db.Max_Records (max_rec)) goto mem_error;
		}
	}
	if (hhlist_flag) {
		if (hhold_list.Get_Index (file->Household ()) == 0) return (false);
	}
	if (Demand_Service::Household_Processing (fh)) {
		household_ptr = household_data.New_Record ();
		household_ptr->Type (0);

		//---- copy the data for user programs ----

		if (choice_flag) {
			household_db.Copy_Fields (file);

			if (!household_db.Add_Record ()) {
				Error ("Writing Household Database");
			}
		}
		return (true);
	}
	return (false);

mem_error:
	Error ("Insufficient Memory for Household Data");
	return (false);
}
示例#3
0
bool RandomSelect::Get_Household_Data (Household_File &file, Household_Data &data, int partition)
{
	if (!file.Nested ()) {
		int hhold, person, persons;
		Trip_Index trip_index;
		Select_Data select_data;
		Select_Map_Stat map_stat;

		hhold = file.Household ();
		if (hhold <= 0) return (false);

		if (select_households && !hhold_range.In_Range (hhold)) return (false);
		if (percent_flag && random.Probability () > select_percent) return (false);

		persons = file.Persons ();
		if (persons < 1) persons = 1;

		data.Household (hhold);
		data.Persons (persons);
			
		trip_index.Household (hhold);
		trip_index.Tour (0);
		trip_index.Trip (0);
		select_data.Type (0);
		select_data.Partition (partition);

		//---- save each person ----

		for (person = 1; person <= persons; person++) {
			trip_index.Person (person);

			map_stat = select_map.insert (Select_Map_Data (trip_index, select_data));

			if (!map_stat.second) {
				Warning (String ("Duplicate Selection Record = %d-%d-%d-%d") % 
					trip_index.Household () % trip_index.Person () % trip_index.Tour () % trip_index.Trip ());
			}
		}
	}
	return (false);
}
示例#4
0
void Data_Service::Write_Households (void)
{
	int part, num_part, count;

	Household_File *file = System_Household_File (true);

	Int_Map_Itr itr;
	Household_Data *hhold_ptr;
	Household_Itr hhold_itr;
	Partition_Files <Household_File> new_file_set;

	if (file->Part_Flag ()) {
		for (num_part=0, hhold_itr = hhold_array.begin (); hhold_itr != hhold_array.end (); hhold_itr++) {
			part = Partition_Index (hhold_itr->Partition ());
			if (part > num_part) num_part = part;
		}
		new_file_set.Initialize (file, ++num_part);
		Show_Message (String ("Writing %ss -- Record") % file->File_Type ());
	} else {
		num_part = 1;
		Show_Message (String ("Writing %s -- Record") % file->File_Type ());
	}
	Set_Progress ();

	for (count=0, itr = hhold_map.begin (); itr != hhold_map.end (); itr++) {
		Show_Progress ();

		hhold_ptr = &hhold_array [itr->second];
		if (hhold_ptr->Partition () < 0) continue;

		if (file->Part_Flag ()) {
			part = Partition_Index (hhold_ptr->Partition ());
			if (part < 0) continue;
			file = new_file_set [part];
		}
		count += Put_Household_Data (*file, *hhold_ptr);
	}
	End_Progress ();

	file->Close ();
	
	Print (2, String ("%s Records = %d") % file->File_Type () % count);
	if (num_part > 1) Print (0, String (" (%d files)") % num_part);
}
示例#5
0
int Data_Service::Put_Household_Data (Household_File &file, Household_Data &data)
{
	Person_Itr person_itr;
	Location_Data *loc_ptr;

	int count = 0;

	loc_ptr = &location_array [data.Location ()];

	file.Household (data.Household ());
	file.Location (loc_ptr->Location ());
	file.Persons (data.Persons ());
	file.Workers (data.Workers ());
	file.Vehicles (data.Vehicles ());
	file.Type (data.Type ());
	file.Partition (data.Partition ());
	file.Num_Nest ((int) data.size ());
	//file.Notes (data.Notes ());

	if (!file.Write (false)) {
		Error (String ("Writing %s") % file.File_Type ());
	}
	count++;

	for (person_itr = data.begin (); person_itr != data.end (); person_itr++) {
		file.Person (person_itr->Person ());
		file.Age (person_itr->Age ());
		file.Relate (person_itr->Relate ());
		file.Gender (person_itr->Gender ());
		file.Work (person_itr->Work ());
		file.Drive (person_itr->Drive ());

		if (!file.Write (true)) {
			Error (String ("Writing %s") % file.File_Type ());
		}
		count++;
	}
	return (count);
}