Example #1
0
void RiderSum::Line_Sum_Report (void)
{
	int riders, max_load, board, alight, run, runs;

	Int_Map_Itr map_itr;
	Line_Data *line_ptr;
	Line_Stop_Itr stop_itr;
	Line_Run_Itr run_itr;

	Show_Message ("Line Summary Report -- Record");
	Set_Progress ();

	//---- print the report ----

	Header_Number (LINE_SUM);

	if (!Break_Check ((int) line_map.size () + 5)) {
		Print (1);
		Line_Sum_Header ();
	}

	//---- get the route data ----

	for (map_itr = line_map.begin (); map_itr != line_map.end (); map_itr++) {
		Show_Progress ();

		if (select_routes && !route_range.In_Range (map_itr->first)) continue;

		line_ptr = &line_array [map_itr->second];

		if (select_modes && !select_mode [line_ptr->Mode ()]) continue;

		//---- check the link criteria ----

		if (!Link_Selection (line_ptr)) continue;

		//---- set the run flags ----

		if (!Run_Selection (line_ptr)) continue;

		//---- save the route ridership data ----

		riders = board = alight = max_load = runs = 0;

		for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {
			for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
				if (run_flag [run] == 0) continue;
				if (run_period [run] < 0) continue;
				if (select_time_of_day && !time_range.In_Range (run_itr->Schedule ())) continue;

				if (run_itr->Board () > board) board = run_itr->Board ();
				if (run_itr->Alight () > alight) alight = run_itr->Alight ();
				if (run_itr->Load () > max_load)  max_load = run_itr->Load ();
				riders += run_itr->Board ();

				if (run_flag [run] == 1) {
					runs++;
					run_flag [run] = 2;
				}
			}
		}
		if (riders == 0) continue;
		
		Print (1, String ("%8d  %10.10s  %5d  %5d  %8d  %8d %8d %8d") % line_ptr->Route () %
			Transit_Code ((Transit_Type) line_ptr->Mode ()) % line_ptr->size () % runs %
			riders % max_load % board % alight);

		if (!line_ptr->Name ().empty ()) {
			Print (0, String ("  %s") % line_ptr->Name ());
		}
		if (Notes_Name_Flag ()) {
			if (!line_ptr->Notes ().empty ()) {
				Print (0, String ("  %s") % line_ptr->Notes ());
			}
		}
	}
	End_Progress ();

	Header_Number (0);
}
Example #2
0
void RiderSum::Line_Rider_Report (void)
{
	int riders, board, alight, run, runs, num, length, tot_len, period, num_periods;
	int max_riders, max_board, max_alight, max_runs, total, capacity, max_cap;
	double factor, max_fac, sum_time, tot_time, time, capfac, max_capfac;
	double vmt, vht, pmt, pht;
	Dtime low, high;

	Int_Map_Itr map_itr;
	Line_Data *line_ptr;
	Stop_Data *stop_ptr;
	Line_Stop_Itr stop_itr, next_itr;
	Line_Run_Itr run_itr;
	Veh_Type_Data *veh_type_ptr, *run_type_ptr;

	Show_Message ("Line Rider Profile -- Record");
	Set_Progress ();

	//---- print the report ----

	Header_Number (LINE_RIDERS);

	num_periods = sum_periods.Num_Periods ();
	if (num_periods == 0) num_periods = 1;

	num = (int) (line_map.size () * stop_map.size ());

	if (!Break_Check (num + 5)) {
		Print (1);
		Line_Rider_Header ();
	}

	//---- process each route ----

	for (map_itr = line_map.begin (); map_itr != line_map.end (); map_itr++) {
		Show_Progress ();

		if (select_routes && !route_range.In_Range (map_itr->first)) continue;

		line_ptr = &line_array [map_itr->second];

		if (select_modes && !select_mode [line_ptr->Mode ()]) continue;

		//---- check the link criteria ----

		if (!Link_Selection (line_ptr)) continue;

		//---- set the run flags ----

		if (!Run_Selection (line_ptr)) continue;

		//---- save the route ridership data ----
		
		veh_type_ptr = &veh_type_array [line_ptr->Type ()];

		for (period = 0; period < num_periods; period++) {
			if (period_flag [period] == 0) continue;

			if (!Break_Check ((int) line_ptr->size () + 15)) {
				Print (1);
				Line_Rider_Header ();
			}
			veh_type_ptr = &veh_type_array [line_ptr->Type ()];

			Print (1, "   Route    Mode     Type   Time Period  Name");

			Print (2, String ("%8d  %10.10s %4d  %12.12s") % line_ptr->Route () %
				Transit_Code ((Transit_Type) line_ptr->Mode ()) % veh_type_ptr->Type () % 
				sum_periods.Range_Format (period));

			if (!line_ptr->Name ().empty ()) {
				Print (0, String ("  %s") % line_ptr->Name ());
			}
			if (Notes_Name_Flag ()) {
				if (!line_ptr->Notes ().empty ()) {
					Print (0, String (" -- %s") % line_ptr->Notes ());
				}
			}
			Print (2, "    Stop  Length   TTime   Alight    Board   Riders  Runs  LoadFac Capacity CapFac");
			Print (1);

			time = tot_time = 0.0;
			max_alight = max_board = max_riders = max_runs = total = length = tot_len = max_cap = 0;
			max_fac = vmt = vht = pmt = pht = max_capfac = 0.0;

			sum_periods.Period_Range (period, low, high);

			for (stop_itr = line_ptr->begin (); stop_itr != line_ptr->end (); stop_itr++) {
				riders = board = alight = runs = capacity = 0;

				stop_ptr = &stop_array [stop_itr->Stop ()];

				next_itr = stop_itr + 1;

				if (next_itr != line_ptr->end ()) {
					length = next_itr->Length () - stop_itr->Length ();
				} else {
					length = 0;
				}
				sum_time = 0.0;
				num = 0;

				for (run=0, run_itr = stop_itr->begin (); run_itr != stop_itr->end (); run_itr++, run++) {
					if (run_flag [run] == 0) continue;
					if (run_period [run] != period) continue;

					board += run_itr->Board ();
					alight += run_itr->Alight ();
					riders += run_itr->Load ();
					runs++;

					if (line_ptr->run_types.size () > 0) {
						run_type_ptr = &veh_type_array [line_ptr->Run_Type (run)];
						capacity += run_type_ptr->Capacity ();
					} else {
						capacity += veh_type_ptr->Capacity ();
					}
					if (next_itr != line_ptr->end ()) {
						time = next_itr->at (run).Schedule ().Seconds () - run_itr->Schedule ().Seconds ();

						vmt += length;
						vht += time;
						pmt += length * run_itr->Load ();
						pht += time * run_itr->Load ();

						sum_time += time;
						num++;
					}
				}
				if (runs == 0) continue;
				if (capacity == 0) capacity = runs;

				factor = (double) riders / runs;
				capfac = DTOI (riders * 10.0 / capacity) / 10.0;

				if (next_itr == line_ptr->end ()) runs = 0;

				if (num > 0) {
					time = sum_time / num;
				} else {
					time = 0;
				}
				Print (1, String ("%8d %7.0lf %7.0lf %8d %8d %8d %5d %8.1lf %6d %8.1lf") % stop_ptr->Stop () % 
					UnRound (length) % time % alight % board % riders % runs % factor % capacity % capfac);

				if (Notes_Name_Flag ()) {
					if (!stop_ptr->Name ().empty ()) {
						Print (0, String ("  %s") % stop_ptr->Name ());
					}
					if (!stop_ptr->Notes ().empty ()) {
						Print (0, " -- ") << stop_ptr->Notes ();
					}
				}
				if (alight > max_alight) max_alight = alight;
				if (board > max_board) max_board = board;
				if (riders > max_riders) max_riders = riders;
				if (runs > max_runs) max_runs = runs;
				if (factor > max_fac) max_fac = factor;
				if (capacity > max_cap) max_cap = capacity;
				if (capfac > max_capfac) max_capfac = capfac;

				tot_len += length;
				tot_time += time;
				total += board;
			}
			if (max_runs == 0) continue;

			Print (2, String (" Maximum                 %8ld %8ld %8ld %5ld %8.1lf %6lf %8.1lf") %
				max_alight % max_board % max_riders % max_runs % max_fac % max_cap % max_capfac);

			Print (2, "Total Boardings = ") << total;

			if (total == 0 || tot_time == 0) continue;

			factor = UnRound (tot_len);
			vmt = UnRound (vmt) / 5280.0;
			vht = vht / 3600.0;
			pmt = UnRound (pmt) / 5280.0;
			pht = pht / 3600.0;


			Print (1, String ("Route Length = %.1lf miles, %.1lf minutes  Average Speed = %.1lf mph") %
				External_Units (factor, MILES) % (tot_time / 60.0) % External_Units ((factor / tot_time), MPH));
			Print (1, String ("Vehicle Miles = %.1lf  Vehicle Hours = %.1lf") % vmt % vht);
			Print (1, String ("Passenger Miles = %.1lf  Passenger Hours = %.1lf") %	pmt % pht);
			Print (1, String ("Passengers per Vehicle Mile = %.1lf  Passengers per Vehicle Hour = %.1lf") %	
				(pmt / vht) % (pht / vht));

			vmt = pmt / total;
			vht = pht * 60.0 / total;

			Print (1, String ("Average Trip Length = %.1lf miles, %.1lf minutes") % vmt % vht);
		}
	}
	End_Progress ();

	Header_Number (0);
}
Example #3
0
void TransitNet::Write_Route (void)
{
	int i, j, stop, time;
	bool new_flag;

	Line_Data *line_ptr;
	Stop_Data *stop_ptr;
	Link_Data *link_ptr;

	Line_File *line_file = (Line_File *) Network_Db_Base (NEW_TRANSIT_ROUTE);
	Schedule_File *schedule_file = (Schedule_File *) Network_Db_Base (NEW_TRANSIT_SCHEDULE);

	//---- write the route and schedule file ----

	Show_Message ("Writing %s -- Record", line_file->File_Type ());
	Set_Progress (1000);

	for (line_ptr = line_data.First_Key (); line_ptr; line_ptr = line_data.Next_Key ()) {
		Show_Progress ();

		new_flag = (edit_list.Get_Index (line_ptr->Route ()) != 0);

		//---- write the route file ----

		line_file->Route (line_ptr->Route ());
		line_file->Stops (line_ptr->Stops ());
		line_file->Mode (Transit_Code ((Transit_Type) line_ptr->Mode ()));
		line_file->Name ((char *) line_ptr->Name ());
		line_file->Notes ((char *) line_ptr->Notes ());

		if (!line_file->Write (false)) goto line_error;
		nroute++;
		if (new_flag) route_edit++;

		for (i=1; i <= line_ptr->Stops (); i++) {

			stop = line_ptr->Stop (i);
			line_file->Stop (stop);

			stop_ptr = stop_data.Get (stop);

			if (line_file->LinkDir_Type () == LINK_NODE) {
				line_file->Link (stop_ptr->Link ());

				link_ptr = link_data.Get (stop_ptr->Link ());

				if (stop_ptr->Dir () > 0) {
					line_file->Node (link_ptr->Anode ());
				} else {
					line_file->Node (link_ptr->Bnode ());
				}
			} else if (line_file->LinkDir_Type () == LINK_DIR) {
				line_file->Link (stop_ptr->Link ());
				line_file->Node (stop_ptr->Dir ());
			} else {
				if (stop_ptr->Dir () > 0) {
					line_file->Link (-(stop_ptr->Link ())); 
				} else {
					line_file->Link (stop_ptr->Link ());
				}
				line_file->Node (0);
			}
			line_file->Zone (line_ptr->Zone (i));
			line_file->Time_Flag (line_ptr->Time_Flag (i));

			if (!line_file->Write (true)) goto line_error;
			nroute++;
			if (new_flag) route_edit++;
		}

		//---- write the schedule file ----

		schedule_file->Route (line_ptr->Route ());

		for (i=1; i <= line_ptr->Runs (); i++) {
			for (j=1; j <= line_ptr->Stops (); j++) {

				stop = line_ptr->Stop (j);
				time = line_ptr->Schedule (i, j);

				schedule_file->Time (Resolve (time));
				schedule_file->Stop (stop);

				if (!schedule_file->Write ()) {
					Error ("Writing %s", schedule_file->File_Type ());
				}
				nschedule++;
				if (new_flag) schedule_edit++;
			}
		}
	}
	End_Progress ();

	line_file->Close ();
	schedule_file->Close ();
	return;

line_error:
	Error ("Writing %s", line_file->File_Type ());
}
Example #4
0
void NewFormat::Read_Routes (void)
{
	String field;
	int i, node, route, route_fld, mode_fld, ttime_fld, name_fld, note_fld, node_fld, dwell_fld, time_fld, spd_fld;
	int head_fld [24], offset_fld [24], ttim_fld [24];

	Int_Map_Stat map_stat;
	Int_Map_Itr map_itr;
	Route_Header route_rec, *route_ptr;

	//---- process the route header file ----

	Show_Message (String ("Reading %s -- Record") % route_header.File_Type ());
	Set_Progress ();

	route_fld = route_header.Required_Field ("ROUTE", "LINE");
	mode_fld = route_header.Required_Field ("MODE", "TYPE");
	ttime_fld = route_header.Optional_Field ("TTIME", "TIME", "MIN_TIME");
	name_fld = route_header.Optional_Field ("NAME", "ROUTE_NAME", "RTNAME", "DESCRIPTION");
	note_fld = route_header.Optional_Field (NOTES_FIELD_NAMES);
	
	for (i=1; i <= route_periods; i++) {
		field ("HEADWAY_%d") % i;
		head_fld [i-1] = route_header.Required_Field (field.c_str ());

		field ("OFFSET_%d") % i;
		offset_fld [i-1] = route_header.Optional_Field (field.c_str ());

		field ("TTIME_%d") % i;
		ttim_fld [i-1] = route_header.Optional_Field (field.c_str ());
		if (ttim_fld [i-1] < 0) ttim_fld [i-1] = ttime_fld;
	}

	while (route_header.Read ()) {
		Show_Progress ();
		route_rec.Clear ();

		route_rec.Route (route_header.Get_Integer (route_fld));
		if (route_rec.Route () == 0) continue;

		//---- set the parking type ----
		
		route_rec.Mode (Transit_Code (route_header.Get_String (mode_fld)));
		route_rec.Name (route_header.Get_String (name_fld));
		route_rec.Notes (route_header.Get_String (note_fld));

		switch (route_rec.Mode ()) {
			case LOCAL_BUS:
				route_rec.Veh_Type (4);
				break;
			case EXPRESS_BUS:
				route_rec.Veh_Type (5);
				break;
			case BRT:
				route_rec.Veh_Type (6);
				break;
			case STREETCAR:
				route_rec.Veh_Type (7);
				break;
			case LRT:
				route_rec.Veh_Type (8);
				break;
			case RAPIDRAIL:
				route_rec.Veh_Type (9);
				break;
			case REGIONRAIL:
				route_rec.Veh_Type (10);
				break;
		}
		if (veh_type_array.size () > 0) {
			route_rec.Veh_Type (VehType40_Map (route_rec.Veh_Type (), 0));

			if (route_rec.Veh_Type () > 0) {
				Int_Map_Itr map_itr = veh_type_map.find (route_rec.Veh_Type ());
				if (map_itr == veh_type_map.end ()) {
					Warning (String ("Transit Vehicle Type %d was Not Found") % route_rec.Veh_Type ());
					route_rec.Veh_Type (0);
				} else {
					route_rec.Veh_Type (map_itr->second);
				}
			} else {
				route_rec.Veh_Type (0);
			}
		}

		for (i=0; i < route_periods; i++) {
			Route_Period period_rec;

			period_rec.Headway (route_header.Get_Time (head_fld [i]));
			period_rec.Offset (route_header.Get_Time (offset_fld [i]));
			period_rec.TTime (route_header.Get_Integer (ttim_fld [i]));

			route_rec.periods.push_back (period_rec);
		}
		map_stat = route_map.insert (Int_Map_Data (route_rec.Route (), (int) route_nodes_array.size ()));

		if (!map_stat.second) {
			Warning ("Duplicate Route Number = ") << route_rec.Route ();
		} else {
			route_nodes_array.push_back (route_rec);
		}
	}
	End_Progress ();

	Print (2, String ("Number of %s Records = %d") % route_header.File_Type () % Progress_Count ());

	//---- process the route nodes file ----

	Show_Message (String ("Reading %s -- Record") % route_nodes.File_Type ());
	Set_Progress ();

	route_fld = route_nodes.Required_Field ("ROUTE", "LINE");
	node_fld = route_nodes.Required_Field ("NODE", "STOP");
	dwell_fld = route_nodes.Optional_Field ("DWELL", "DWELL_TIME", "STOP_TIME", "STOPTIME");
	time_fld = route_nodes.Optional_Field ("TIME", "TTIME", "RUNTIME", "RUN_TIME");
	spd_fld = route_nodes.Optional_Field ("SPEED", "SPD", "RUNSPD", "RUN_SPD", "RUN_SPEED");

	while (route_nodes.Read ()) {
		Show_Progress ();

		route = route_nodes.Get_Integer (route_fld);

		map_itr = route_map.find (route);
		if (map_itr == route_map.end ()) {
			Warning (String ("Route Nodes Route %d was Not Found in the Route Header File") % route);
			continue;
		}
		route_ptr = &route_nodes_array [map_itr->second];

		Route_Node node_rec;

		node = route_nodes.Get_Integer (node_fld);
		if (node < 0) {
			node_rec.Type (NO_STOP);
			node = -node;
		} else {
			node_rec.Type (STOP);
		}
		map_itr = node_map.find (node);
		if (map_itr == node_map.end ()) {
			Warning (String ("Route %d Node %d was Not Found") % route % node);
			continue;
		}
		node_rec.Node (map_itr->second);
		node_rec.Dwell (Dtime (route_nodes.Get_Integer (dwell_fld), SECONDS));
		node_rec.Time (Dtime (route_nodes.Get_Integer (time_fld), SECONDS));
		node_rec.Speed (Internal_Units (route_nodes.Get_Double (spd_fld), MPS));

		route_ptr->nodes.push_back (node_rec);
	}
	End_Progress ();

	Print (2, String ("Number of %s Records = %d") % route_nodes.File_Type () % Progress_Count ());
}
Example #5
0
void TransitNet::Read_Route (void)
{
    int i, node, node0, route, veh_type, mode, begin, end, num_in, tot_time, spd_time;
    int run_time, cum_time, offset, headway, speed, dwell;
    double ttime, factor;
    bool first, stop_flag;
    Use_Type use;

    AB_Data *ab_ptr;
    Dir_Path_Data *dir_ptr, *last_dir;
    Route_Node rnode_rec, *rnode_ptr;
    Driver_Data *driver_ptr;
    Path_Node *path_ptr;
    Route_Data *route_ptr;

    //---- read the route file ----

    Show_Message ("Reading Route Header and Nodes Files -- Record");
    Set_Progress (100);
    num_in = 0;

    for (route_ptr = route_data.First (); route_ptr; route_ptr = route_data.Next ()) {
        Show_Progress ();

        route_node.Reset ();

        first = true;
        begin = end = 0;

        route = route_ptr->Route ();
        mode = route_ptr->Mode ();

        use = (mode <= EXPRESS_BUS) ? BUS : RAIL;

        run_time = Round (route_ptr->Min_Time ());

        for (i=1; i <= num_periods; i++) {
            headway = route_ptr->Headway (i);
            if (headway <= 0) continue;

            offset = route_ptr->Offset (i);

            if (offset < 0) {
                offset = (int) (headway * random.Probability () + 0.5);
                route_ptr->Offset (i, offset);
            }
        }

        //---- read the node records ----

        rnode_rec.Dwell (0);
        rnode_rec.TTime (0);
        node0 = 0;

        for (i=1; i <= route_ptr->Nodes (); i++) {

            node = route_ptr->Node (i);

            if (node < 0) {
                stop_flag = false;
                node = -node;
            } else {
                stop_flag = true;
            }

            if (dwell_flag) {
                dwell = route_ptr->Dwell (i);
            } else {
                if (stop_flag) {
                    dwell = min_dwell;
                } else {
                    dwell = 0;
                }
            }
            ttime = route_ptr->Time (i);
            speed = route_ptr->Speed (i);

            //---- check the node file ----

            if (node_data.Get_Index (node) > 0) {
                if (first) {
                    rnode_rec.Node (node);
                    rnode_rec.Dir (0);

                    rnode_rec.Add_Dwell (Round (dwell));
                    rnode_rec.Add_TTime (Round (ttime));

                    if (!route_node.Add (&rnode_rec)) {
                        Error ("Insufficient Memory for Route Nodes");
                    }
                } else {

                    //---- find the link(s) between route nodes ----

                    ab_ptr = ab_key.Get (node0, node);

                    if (ab_ptr == NULL) {

                        //---- attempt to build a minimum distance path ----

                        Node_Path (node0, node, use);

                        if (path_node.Num_Records () == 0) {

                            //---- try to build an auto path ----

                            Node_Path (node0, node, CAR);

                            if (path_node.Num_Records () != 0) {
                                Warning ("Path from %d and %d on Route %d includes Use Restrinctions", node0, node, route);
                            }
                        }

                        if (path_node.Num_Records () == 0) {
                            Warning ("No Path between Nodes %d and %d on Route %d", node0, node, route);
                            break;
                        } else {

                            //---- calculate the network travel time for the path ----

                            tot_time = spd_time = 0;

                            for (path_ptr = path_node.First (); path_ptr; path_ptr = path_node.Next ()) {
                                dir_ptr = dir_data [path_ptr->Dir ()];

                                tot_time += dir_ptr->Time0 ();

                                if (speed_flag && speed > 0) {
                                    spd_time += Round ((double) dir_ptr->Length () / speed);
                                }
                            }

                            //---- check the transit travel time ----

                            if (ttime == 0.0) {
                                if (spd_time > 0) {
                                    ttime = UnRound (spd_time) + dwell;
                                    tot_time = spd_time;
                                } else {
                                    ttime = UnRound (tot_time) + dwell;
                                }
                            } else if (ttime < UnRound (tot_time)) {
                                Warning ("Route %d Node %d to %d travel time %.1lf < %.1lf", route,
                                         node0, node, ttime, UnRound (tot_time));
                            }

                            //---- distribute the transit travel time to each link on the path ----

                            if (tot_time < 1) tot_time = 1;
                            factor = ttime / UnRound (tot_time);

                            for (path_ptr = path_node.Last (); path_ptr; path_ptr = path_node.Previous ()) {
                                rnode_rec.Node (path_ptr->Node ());
                                rnode_rec.Dir (path_ptr->Dir ());

                                dir_ptr = dir_data [path_ptr->Dir ()];

                                ttime = dir_ptr->Time0 () * factor;

                                rnode_rec.TTime ((int) (ttime + 0.5));
                                rnode_rec.Dwell (Round (dwell));

                                if (!route_node.Add (&rnode_rec)) {
                                    Error ("Insufficient Memory for Route Nodes");
                                }
                            }
                        }

                    } else {

                        //---- calculate and check the transit travel time ----

                        rnode_rec.Node (node);
                        rnode_rec.Dir (ab_ptr->dir);

                        dir_ptr = dir_data [ab_ptr->dir];

                        if (!Use_Permission (dir_ptr->Use (), use)) {
                            Warning ("Link %d does Not Permit %s Service",
                                     dir_ptr->Link (), Transit_Code ((Transit_Type) mode));
                        }
                        if (ttime == 0.0) {
                            if (speed_flag && speed > 0) {
                                ttime = (double) dir_ptr->Length () / speed + dwell;
                            } else {
                                ttime = UnRound (dir_ptr->Time0 ()) + dwell;
                            }
                        } else if (ttime < UnRound (dir_ptr->Time0 ())) {
                            Warning ("Route %d Link %d travel time %.1lf < %.1lf", route,
                                     dir_ptr->Link (), ttime, UnRound (dir_ptr->Time0 ()));
                        }
                        rnode_rec.Add_Dwell (Round (dwell));
                        rnode_rec.Add_TTime (Round (ttime));

                        if (!route_node.Add (&rnode_rec)) {
                            Error ("Insufficient Memory for Route Nodes");
                        }
                    }
                }
                rnode_rec.Dwell (0);
                rnode_rec.TTime (0);
                first = false;
                end = 0;
                node0 = node;

            } else {

                //---- remove route nodes that were collapsed from the network ----

                if (first) {
                    begin++;
                } else {
                    rnode_rec.Add_Dwell (Round (dwell));
                    rnode_rec.Add_TTime (Round (ttime));
                }
                end++;
            }
        }

        if (route_node.Num_Records () <= 1) {
            Warning ("Route %d has Missing Node Records", route);
            continue;
        }
        if (begin) {
            Print (1, "%d Node%sat the Beginning of Route %d did Not Exist",
                   begin, ((begin > 1) ? "s " : " "), route);
            end_warnings++;
        }
        if (end) {
            Print (1, "%d Node%sat the End of Route %d did Not Exist",
                   end, ((end > 1) ? "s " : " "), route);
            end_warnings++;
        }

        //---- add route to the edit list ----

        if (!edit_list.Add (route)) {
            Error ("Adding Route to the Edit List");
        }

        //---- check for an existing route ----

        driver_ptr = driver_data.Get (route);

        if (driver_ptr == NULL) {
            driver_ptr = driver_data.New_Record (true);
            driver_ptr->Route (route);
            if (!driver_data.Add ()) {
                Error ("Adding Transit Driver Data");
            }
            driver_ptr = driver_data.Record ();
        }

        //---- create the driver data ---

        driver_ptr->Links (route_node.Num_Records () - 1);

        switch (mode) {
        case LOCAL_BUS:
            veh_type = 4;
            break;
        case EXPRESS_BUS:
            veh_type = 5;
            break;
        case TROLLEY:
            veh_type = 6;
            break;
        case STREETCAR:
            veh_type = 7;
            break;
        case LRT:
            veh_type = 8;
            break;
        case RAPIDRAIL:
            veh_type = 9;
            break;
        case REGIONRAIL:
            veh_type = 10;
            break;
        }
        driver_ptr->Type (veh_type);
        driver_ptr->Sub_Type (0);

        //---- process each route node ----

        node0 = 0;
        last_dir = NULL;
        cum_time = 0;

        for (i=0, rnode_ptr = route_node.First (); rnode_ptr; rnode_ptr = route_node.Next (), i++) {

            node = rnode_ptr->Node ();

            if (node0 == 0) {
                node0 = node;
                continue;
            }
            ab_ptr = ab_key.Get (node0, node);

            if (ab_ptr == NULL) {
                Error ("No Link between Nodes %d and %d on Route %d", node0, node, route);
            }
            node0 = node;
            rnode_ptr->Dir (ab_ptr->dir);

            dir_ptr = dir_data [ab_ptr->dir];

            //---- check the travel time ----

            if (rnode_ptr->TTime () == 0) {
                rnode_ptr->TTime (dir_ptr->Time0 () + rnode_ptr->Dwell ());
            }
            cum_time += rnode_ptr->TTime ();

            //---- save the driver link ----

            driver_ptr->Link_Dir (i, dir_ptr->Link_Dir ());

            //---- check the connection ----

            if (last_dir != NULL && connect_flag) {
                if (connect_data.Get (last_dir->Link_Dir (), dir_ptr->Link_Dir ()) == NULL) {
                    Warning ("No Connection from Link %d to %d on Route %d", last_dir->Link (), dir_ptr->Link (), route);
                    connect_warnings++;
                }
            }
            last_dir = dir_ptr;
        }

        //---- adjust the link travel times to match the run time ----

        if (run_time > 0 && cum_time > 0 && run_time != cum_time) {
            ttime = (double) run_time / cum_time;

            cum_time = 0;

            for (rnode_ptr = route_node.First (); rnode_ptr; rnode_ptr = route_node.Next ()) {
                cum_time += run_time = (int) (rnode_ptr->TTime () * ttime + 0.5);
                rnode_ptr->TTime (run_time);
            }
        }
        route_ptr->Min_Time (Resolve (cum_time));

        //---- save the transit route -----

        Save_Route (route_ptr);
        num_in++;
    }
    End_Progress ();

    Print (1, "Number of Transit Routes = %d", num_in);
}
Example #6
0
bool Network_Service::Line_Processing (Db_File *fh)
{
	static int id, nstops, stop_num; 
	int zone;

	bool stop_flag;
	
	Line_Data *line_ptr = NULL;

	Line_File *file = (Line_File *) fh;

	stop_flag = Network_Data_Flag (TRANSIT_STOP);

	//---- process a header line ----

	if (!file->Nest ()) {	
		id = file->Route ();

		if (id == 0) return (false);

		if (id < 1) {
			return (Check_Message ("Transit Route ID %d is Out of Range", id));
		}
		line_ptr = line_data.New_Record (true);
		if (line_ptr == NULL) goto mem_error;

		line_ptr->Route (id);

		stop_num = 1;
		nstops = file->Stops ();

		if (nstops < 2) {
			return (Check_Message ("Number of Stops %d on Route %d is Out of Range", nstops, id));
		}
		if (!line_ptr->Stops (nstops)) {
			Error ("Insufficient Memory for %d Stops on Router %d", nstops, id);
		}
		line_ptr->Mode (Transit_Code (file->Mode ()));
		line_ptr->Null_Name ();
		line_ptr->Null_Notes ();

		if (Notes_Name_Flag ()) {
			char *str_ptr = file->Name ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Name (str_ptr);
			}
			str_ptr = file->Notes ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Notes (str_ptr);
			}
		}
	} else {
		line_ptr = line_data.New_Record (false);
		if (line_ptr == NULL) goto mem_error;

		//---- process a stop record ----

		int stop = file->Stop ();

		if (stop_flag) {
			int index = stop_data.Get_Index (stop);

			if (index == 0) {
				return (Check_Message ("Transit Stop %d on Route %d was Not Found in the Stop File", stop, id));
			}
			if (Renumber ()) stop = index;
		}
		line_ptr->Stop (stop_num, stop);

		zone = file->Zone ();

		if (Num_Fare_Zones () > 0 && (zone < 1 || zone > Num_Fare_Zones ())) {
			if (zone != 0 || !Zero_Fare_Zone ()) {
				Warning ("Transit Zone %d on Route %d is Out of Range (1..%d)", zone, id, Num_Fare_Zones ());
				if (zone == 0) Zero_Fare_Zone (true);
			}
		}
		line_ptr->Zone (stop_num, zone);
		line_ptr->Time_Flag (stop_num, file->Time_Flag ());

		if (stop_num == nstops) {
			return (true);
		} else {
			stop_num++;
			return (false);
		}
	}
	return (false);

mem_error:
	Error ("Insuffienct Memory for Transit Line Data");
	return (false);
}
Example #7
0
void LineSum::Write_Capacity (void)
{
	int per_runs, cap_runs, max_run, run_max, run_tot, cap_tot, max_load;
	int stop, stops, run, runs, period, last_per, time, on, off, ride;
	double avg_fac, cap_fac, max_fac;
	bool check_flag, stop_flag;

	Rider_Data *rider_ptr;
	Driver_Data *driver_ptr;
	Offset_Data *offset_ptr;
	Veh_Type_Data *veh_type_ptr;

	Show_Message ("Writing the Capacity Constraint File -- Record");
	Set_Progress (100);

	//---- initialize the selection sets ----

	set_ptr = select_set [0];
	if (set_ptr == NULL) return;

	//---- process each route ----

	for (rider_ptr = rider_data.First_Key (); rider_ptr; rider_ptr = rider_data.Next_Key ()) {
		Show_Progress ();

		//---- check the selection criteria ----

		if (!set_ptr->Select_Modes (rider_ptr->Mode ())) continue;
		if (!set_ptr->Select_Routes (rider_ptr->Route ())) continue;

		driver_ptr = driver_data.Get (rider_ptr->Route ());
		if (driver_ptr == NULL) continue;

		veh_type_ptr = veh_type_data.Get (driver_ptr->Type (), driver_ptr->Sub_Type ());
		if (veh_type_ptr == NULL) continue;

		if (veh_type_ptr->Capacity () <= 0) continue;

		stops = rider_ptr->Stops ();
		runs = rider_ptr->Runs ();
		last_per = cap_runs = 0;

		//---- process each run ----

		for (run=1; ; run++) {
			if (run <= runs) {
				switch (set_ptr->Time_Method ()) {
					case RUN_START:
						time = rider_ptr->Time (run, 1);
						break;
					case RUN_END:
						time = rider_ptr->Time (run, stops);
						break;
					case RUN_MID:
						time = (rider_ptr->Time (run, 1) + rider_ptr->Time (run, stops)) / 2;
						break;
					case SCHED_START:
						time = rider_ptr->Schedule (run, 1);
						break;
					case SCHED_END:
						time = rider_ptr->Schedule (run, stops);
						break;
					case SCHED_MID:
						time = (rider_ptr->Schedule (run, 1) + rider_ptr->Schedule (run, stops)) / 2;
						break;
				}
				period = set_ptr->Time_Period (Resolve (time));
			} else {
				period = 0;
			}
			if (period != last_per) {
				if (last_per > 0 && cap_runs > 0) {
					if (per_runs > 0) {
						avg_fac = (double) run_tot / per_runs;
						run_tot = (int) (avg_fac + 0.5);
						avg_fac /= veh_type_ptr->Capacity ();
					} else {
						run_tot = 0;
						avg_fac = 0;
					}
					if (cap_runs > 0) {
						cap_fac = (double) cap_tot / cap_runs;
						cap_tot = (int) (cap_fac + 0.5);
						cap_fac /= veh_type_ptr->Capacity ();
					} else {
						cap_tot = 0;
						cap_fac = 0;
					}
					if (max_run > 0) {
						max_fac = (double) max_load / veh_type_ptr->Capacity ();
					} else {
						max_fac = 0.0;
					}
					cap_file.Put_Field (1, Transit_Code ((Transit_Type) rider_ptr->Mode ()));
					cap_file.Put_Field (2, rider_ptr->Route ());
					cap_file.Put_Field (3, (char *) set_ptr->Time_Format (last_per));
					cap_file.Put_Field (4, per_runs);
					cap_file.Put_Field (5, run_tot);
					cap_file.Put_Field (6, avg_fac);
					cap_file.Put_Field (7, cap_runs);
					cap_file.Put_Field (8, cap_tot);
					cap_file.Put_Field (9, cap_fac);
					cap_file.Put_Field (10, max_run);
					cap_file.Put_Field (11, max_load);
					cap_file.Put_Field (12, max_fac);

					if (!cap_file.Write ()) {
						Error ("Writing %s", cap_file.File_Type ());
					}
				}
				last_per = period;
				per_runs = cap_runs = max_run = run_tot = cap_tot = max_load = 0;
			}
			if (run > runs) break;
			if (last_per == 0) continue;

			//---- sum the line ridership ----

			stop_flag = true;
			check_flag = false;
			run_max = ride = 0;

			for (stop=1; stop <= stops; stop++) {
				on = rider_ptr->Board (run, stop);
				off = rider_ptr->Alight (run, stop);
				ride += on - off;

				if (offset_flag && set_ptr->Subarea_Flag ()) {
					offset_ptr = stop_offset.Get (rider_ptr->Stop (stop));
					if (offset_ptr == NULL) continue;

					stop_flag = set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ());
				}
				if (stop_flag) {
					check_flag = true;
					if (ride > run_max) run_max = ride;
				}
			}
			if (check_flag) {
				per_runs++;
				run_tot += run_max;
				if (run_max > veh_type_ptr->Capacity ()) {
					if (run_max > max_load) {
						max_load = run_max;
						max_run = run;
					}
					cap_runs++;
					cap_tot += run_max;
				}
			}
		}
	}
	End_Progress ();
}
Example #8
0
void LineSum::Line_Rider_Report (int number)
{
	int stop, stops, run, runs, period, per, num, time;
	int on, off, tot_on, tot_off, tot_ride, stop_id;
	bool first, last_stop_flag, stop_flag, line_flag;

	Rider_Data *rider_ptr;
	Offset_Data *offset_ptr;

	typedef struct {
		int ride;
		int tot_on;
		int tot_off;
		int tot_ride;
		int max_on;
		int max_off;
		int max_ride;
	} Period_Data;

	Period_Data *period_data, *period_ptr;

	Show_Message ("Creating a Line Ridership Report -- Record");
	Set_Progress (100);

	//---- initialize the selection sets ----

	set_ptr = select_set [number];
	if (set_ptr == NULL) return;

	Header_Number (LINE_RIDER);
	first = true;

	num = set_ptr->Num_Periods () + 1;
	period_data = new Period_Data [num];

	if (period_data == NULL) {
		Error ("Insufficient Space for %d Time Periods", num);
	}

	//---- process each route ----

	for (rider_ptr = rider_data.First_Key (); rider_ptr; rider_ptr = rider_data.Next_Key ()) {
		Show_Progress ();

		if (!set_ptr->Select_Modes (rider_ptr->Mode ())) continue;
		if (!set_ptr->Select_Routes (rider_ptr->Route ())) continue;

		stops = rider_ptr->Stops ();
		runs = rider_ptr->Runs ();

		memset (period_data, '\0', num * sizeof (Period_Data));
		line_flag = false;
		last_stop_flag = stop_flag = true;

		for (stop=1; stop <= stops; stop++) {
			stop_id = rider_ptr->Stop (stop);

			if (offset_flag && set_ptr->Subarea_Flag ()) {
				offset_ptr = stop_offset.Get (stop_id);
				if (offset_ptr == NULL) continue;

				stop_flag = set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ());
			}
			if (stop_flag) {
				if (!line_flag) {
					if (first) {
						New_Page ();
						first = false;
					} else {
						Break_Check (MIN ((stops - stop + 8), 15));
					}
					Print (1, "Line: %s %d  %s", Transit_Code ((Transit_Type) rider_ptr->Mode ()), 
						rider_ptr->Route (), rider_ptr->Name ());
					Print (1);
					line_flag = true;
				}
				Print (1, "%8d", stop_id);
			}
			tot_on = tot_off = tot_ride = 0;

			for (per=1; per < num; per++) {

				on = off = 0;
				period_ptr = period_data + per;

				for (run=1; run <= runs; run++) {
					switch (set_ptr->Time_Method ()) {
						case RUN_START:
							time = rider_ptr->Time (run, 1);
							break;
						case RUN_END:
							time = rider_ptr->Time (run, stops);
							break;
						case RUN_MID:
							time = (rider_ptr->Time (run, 1) + rider_ptr->Time (run, stops)) / 2;
							break;
						case SCHED_START:
							time = rider_ptr->Schedule (run, 1);
							break;
						case SCHED_END:
							time = rider_ptr->Schedule (run, stops);
							break;
						case SCHED_MID:
							time = (rider_ptr->Schedule (run, 1) + rider_ptr->Schedule (run, stops)) / 2;
							break;
					}
					period = set_ptr->Time_Period (Resolve (time));

					if (period < per) continue;
					if (period > per) break;

					on += rider_ptr->Board (run, stop);
					off += rider_ptr->Alight (run, stop);
				}
				if (stop_flag && !last_stop_flag) {
					period_ptr->tot_ride += period_ptr->ride;
				}
				period_ptr->ride += on - off;

				if (stop_flag) {
					Print (0, " %7d%7d%7d", on, off, period_ptr->ride);
				
					tot_on += on;
					tot_off += off;
					tot_ride += period_ptr->ride;

					period_ptr->tot_on += on;
					period_ptr->tot_off += off;
					period_ptr->tot_ride += on;
					if (on > period_ptr->max_on) period_ptr->max_on = on;
					if (off > period_ptr->max_off) period_ptr->max_off = off;
					if (period_ptr->ride > period_ptr->max_ride) period_ptr->max_ride = period_ptr->ride;
				}
			}
			if (stop_flag && num > 2) {
				Print (0, " %7d%7d%7d", tot_on, tot_off, tot_ride);

				period_ptr = period_data;

				period_ptr->tot_on += tot_on;
				period_ptr->tot_off += tot_off;
				period_ptr->tot_ride += tot_ride;
				if (tot_on > period_ptr->max_on) period_ptr->max_on = tot_on;
				if (tot_off > period_ptr->max_off) period_ptr->max_off = tot_off;
				if (tot_ride > period_ptr->max_ride) period_ptr->max_ride = tot_ride;
			}
			last_stop_flag = stop_flag;
		}
		if (line_flag) {
			Print (2, "   Total");

			for (per=1; per <= num; per++) {
				if (per == num) {
					if (num > 2) {
						per = 0;
					} else {
						break;
					}
				}
				period_ptr = period_data + per;

				Print (0, " %7d%7d%7d", period_ptr->tot_on, period_ptr->tot_off, period_ptr->tot_ride);
				if (per == 0) break;
			}

			Print (1, " Maximum");

			for (per=1; per <= num; per++) {
				if (per == num) {
					if (num > 2) {
						per = 0;
					} else {
						break;
					}
				}
				period_ptr = period_data + per;

				Print (0, " %7d%7d%7d", period_ptr->max_on, period_ptr->max_off, period_ptr->max_ride);
				if (per == 0) break;
			}
			Print (1);
		}
	}
	End_Progress ();

	Header_Number (0);

	if (period_data != NULL) {
		delete [] period_data;
	}
}
Example #9
0
void LineSum::Line_Sum_Report (int number)
{
    int stop, stops, run, runs, period, per, num, time;
    int on, off, ride, total, max_ride, *total_rider, *max_load;
    char buffer [FIELD_BUFFER];
    bool last_stop_flag, stop_flag, line_flag;

    Rider_Data *rider_ptr;
    Offset_Data *offset_ptr;

    Show_Message ("Creating a Line Summary Report -- Record");
    Set_Progress (100);

    //---- initialize the selection sets ----

    set_ptr = select_set [number];
    if (set_ptr == NULL) return;

    Header_Number (LINE_SUM);

    //---- initialize the report data ----

    if (!Break_Check (rider_data.Num_Records () + 6)) {
        Print (1);
        Line_Sum_Header ();
    }
    num = set_ptr->Num_Periods () + 1;

    total_rider = new int [num];
    max_load = new int [num];

    if (total_rider == NULL || max_load == NULL) {
        Error ("Insufficient Space for %d Time Periods", num);
    }
    memset (total_rider, '\0', num * sizeof (int));
    memset (max_load, '\0', num * sizeof (int));

    //---- process each route ----

    for (rider_ptr = rider_data.First_Key (); rider_ptr; rider_ptr = rider_data.Next_Key ()) {
        Show_Progress ();

        //---- check the selection criteria ----

        if (!set_ptr->Select_Modes (rider_ptr->Mode ())) continue;
        if (!set_ptr->Select_Routes (rider_ptr->Route ())) continue;

        stops = rider_ptr->Stops ();
        runs = rider_ptr->Runs ();

        //---- check for stops in the subarea ----

        if (offset_flag && set_ptr->Subarea_Flag ()) {
            line_flag = false;

            for (stop=1; stop <= stops; stop++) {
                offset_ptr = stop_offset.Get (rider_ptr->Stop (stop));
                if (offset_ptr == NULL) continue;

                if (set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ())) {
                    line_flag = true;
                    break;
                }
            }
            if (!line_flag) continue;
        }

        //---- print the line label ----

        str_fmt (buffer, sizeof (buffer), "%s %d", Transit_Code ((Transit_Type) rider_ptr->Mode ()), rider_ptr->Route ());

        Print (1, "%16.16s", buffer);

        //---- process each time period ----

        for (per=1; per < num; per++) {

            total = max_ride = 0;

            for (run=1; run <= runs; run++) {
                switch (set_ptr->Time_Method ()) {
                case RUN_START:
                    time = rider_ptr->Time (run, 1);
                    break;
                case RUN_END:
                    time = rider_ptr->Time (run, stops);
                    break;
                case RUN_MID:
                    time = (rider_ptr->Time (run, 1) + rider_ptr->Time (run, stops)) / 2;
                    break;
                case SCHED_START:
                    time = rider_ptr->Schedule (run, 1);
                    break;
                case SCHED_END:
                    time = rider_ptr->Schedule (run, stops);
                    break;
                case SCHED_MID:
                    time = (rider_ptr->Schedule (run, 1) + rider_ptr->Schedule (run, stops)) / 2;
                    break;
                }
                period = set_ptr->Time_Period (Resolve (time));

                if (period < per) continue;
                if (period > per) break;

                //---- sum the line ridership ----

                ride = 0;
                last_stop_flag = stop_flag = true;

                for (stop=1; stop <= stops; stop++) {
                    on = rider_ptr->Board (run, stop);
                    off = rider_ptr->Alight (run, stop);

                    if (offset_flag && set_ptr->Subarea_Flag ()) {
                        offset_ptr = stop_offset.Get (rider_ptr->Stop (stop));
                        if (offset_ptr == NULL) continue;

                        stop_flag = set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ());

                        if (stop_flag && !last_stop_flag) {
                            total += ride;
                        }
                        last_stop_flag = stop_flag;
                    }
                    ride += on - off;

                    if (stop_flag) {
                        total += on;
                        if (ride > max_ride) max_ride = ride;
                    }
                }
            }
            Print (0, "  %7d %7d", total, max_ride);

            total_rider [per] += total;
            if (max_ride > max_load [per]) max_load [per] = max_ride;
        }

        //---- add the row totals ----

        if (num > 2) {
            total = max_ride = 0;

            for (run=1; run <= runs; run++) {
                switch (set_ptr->Time_Method ()) {
                case RUN_START:
                    time = rider_ptr->Time (run, 1);
                    break;
                case RUN_END:
                    time = rider_ptr->Time (run, stops);
                    break;
                case RUN_MID:
                    time = (rider_ptr->Time (run, 1) + rider_ptr->Time (run, stops)) / 2;
                    break;
                case SCHED_START:
                    time = rider_ptr->Schedule (run, 1);
                    break;
                case SCHED_END:
                    time = rider_ptr->Schedule (run, stops);
                    break;
                case SCHED_MID:
                    time = (rider_ptr->Schedule (run, 1) + rider_ptr->Schedule (run, stops)) / 2;
                    break;
                }
                period = set_ptr->Time_Period (Resolve (time));
                if (period == 0) continue;

                //---- sum the line ridership ----

                ride = 0;
                last_stop_flag = stop_flag = true;

                for (stop=1; stop <= stops; stop++) {
                    on = rider_ptr->Board (run, stop);
                    off = rider_ptr->Alight (run, stop);

                    if (offset_flag && set_ptr->Subarea_Flag ()) {
                        offset_ptr = stop_offset.Get (rider_ptr->Stop (stop));
                        if (offset_ptr == NULL) continue;

                        stop_flag = set_ptr->In_Subarea (offset_ptr->X (), offset_ptr->Y ());

                        if (stop_flag && !last_stop_flag) {
                            total += ride;
                        }
                        last_stop_flag = stop_flag;
                    }
                    ride += on - off;

                    if (stop_flag) {
                        total += off;
                        if (ride > max_ride) max_ride = ride;
                    }
                }
            }
            Print (0, "  %7d %7d", total, max_ride);

            total_rider [0] += total;
            if (max_ride > max_load [0]) max_load [0] = max_ride;
        }
    }
    End_Progress ();

    //---- print the period totals ----

    Print (2, "           Total");

    for (per=1; per <= num; per++) {
        if (per == num) {
            if (num > 2) {
                per = 0;
            } else {
                break;
            }
        }
        Print (0, " %8d %7d", total_rider [per], max_load [per]);
        if (per == 0) break;
    }
    delete [] total_rider;
    delete [] max_load;

    Header_Number (0);
}