bool LinkSum::Get_Location_Data (Location_File &file, Location_Data &data)
{
	int i, field, link, lvalue1, lvalue2, zone;
	double dvalue1, dvalue2;
	String buffer;

	Db_Field *fld;
	Link_Location loc_rec;
	Int_Itr int_itr;
	Int_Map_Itr map_itr;

	//---- get the link number ----

	link = file.Link ();
	if (link == 0) return (false);
	data.Link (link);

	//---- sum the activities on links ----

	if (activity_flag) {
		if (!link_db.Read_Record (link)) {
			Error (String ("Reading Link Database Record %d") % link);
		}

		//---- sum the data fields ----

		for (i=1, int_itr = field_list.begin (); int_itr != field_list.end (); int_itr++, i++) {
			field = *int_itr;

			fld = file.Field (field);

			if (fld->Type () == DB_INTEGER) {
				lvalue1 = file.Get_Integer (field);
				lvalue2 = link_db.Get_Integer (i);

				lvalue2 += lvalue1;
				link_db.Put_Field (i, lvalue2);
			} else if (fld->Type () == DB_DOUBLE) {
				dvalue1 = file.Get_Double (field);
				dvalue2 = link_db.Get_Double (i);

				dvalue2 += dvalue1;
				link_db.Put_Field (i, dvalue2);
			} else if (fld->Type () == DB_STRING) {
				link_db.Put_Field (i, file.Get_String (field));
			}
		}

		//---- save the changes ----

		if (!link_db.Write_Record (link)) {
			Error (String ("Writing Link Database Record %d") % link);
		}
	}

	//---- add a link location record ----

	if (zone_flag || group_flag) {
		zone = file.Zone ();

		if (zone > 0) {
			map_itr = link_map.find (link);
			if (map_itr == link_map.end ()) return (false);
			link = map_itr->second;

			loc_rec.link = link;
			loc_rec.location = i = file.Location ();
			loc_rec.zone = zone;
			loc_rec.count = 0;

			link_location.insert (Link_Loc_Map_Data (Int2_Key (link, i), loc_rec));
		}
	}

	//---- don't save the location data ----

	return (false);
}
Beispiel #2
0
bool Converge_Service::Get_Location_Data (Location_File &file, Location_Data &data)
{
	if (Data_Service::Get_Location_Data (file, data)) {
		if (capacity_flag) {
			int next, num;
			double share, total;
			Loc_Cap_Data loc_cap_data;
			Int_Itr itr;

			loc_cap_data.capacity = file.Get_Integer (loc_cap_field);
			loc_cap_data.demand = 0;
			loc_cap_data.failed = 0;
			num = 0;

			for (itr = next_des_field.begin (); itr != next_des_field.end (); itr++) {
				next = file.Get_Integer (*itr);
				if (next > 0) {
					loc_cap_data.next_des.push_back (next);
					num++;
				}
			}
			if (num > 1) {
				if (des_share_field.size () > 0) {
					total = 0.0;

					for (next=0; next < num; next++) {
						if (next < (int) des_share_field.size ()) {
							share = file.Get_Double (des_share_field [next]);
							if (share == 0) share = 1.0;
						} else {
							share = 1.0;
						}
						loc_cap_data.shares.push_back (share);
						total += share;
					}
					if (total != 1.0) {
						if (total > 0.0) {
							for (next=0; next < num; next++) {
								loc_cap_data.shares [next] /= total;
							}
						} else {
							share = 1.0 / num;
							for (next=0; next < num; next++) {
								loc_cap_data.shares [next] = share;
							}
						}
					}
				} else {
					share = 1.0 / num;
					for (next=0; next < num; next++) {
						loc_cap_data.shares.push_back (share);
					}
				}
			}
			loc_cap_array.push_back (loc_cap_data);
		}
		if (fuel_flag) {
			Loc_Fuel_Data loc_fuel_data;
			Int_Itr itr;

			loc_fuel_data.supply = Round (file.Get_Integer (loc_fuel_field));
			loc_fuel_data.consumed = 0;
			loc_fuel_data.failed = 0;
			loc_fuel_data.ran_out = 0;

			loc_fuel_array.push_back (loc_fuel_data);
		}
		return (true);
	}
	return (false);
}