Beispiel #1
0
bool Sim_Method::Output_Step (Travel_Step &step)
{
	int cell_offset, index, cell, lane, to_index, to_cell, to_lane, last_index, pce;
	int first_cell, last_cell, to_part, from_index;
	bool reload_flag, bound_flag, remove_flag = false;
	bool transfer_flag = false;

	Sim_Plan_Ptr plan_ptr;
	Sim_Leg_Itr leg_itr;
	Sim_Dir_Ptr sim_dir_ptr;
	Sim_Cap_Ptr sim_cap_ptr = 0;
	Sim_Veh_Ptr sim_veh_ptr;
	Cell_Itr cell_itr, veh_cell_itr, end_itr;
	Problem_Data problem_data;

	if (step.Vehicle () >= 0 && step.sim_veh_ptr == 0) {
		step.sim_veh_ptr = exe->sim_veh_array [step.Vehicle ()];
	}
	plan_ptr = step.sim_traveler_ptr->plan_ptr;

	//---- check for lost problems ----

	if (step.Status () == 1 || step.Problem () == DEPARTURE_PROBLEM || step.Problem () == ARRIVAL_PROBLEM) {
		if (plan_ptr->Person () == 0) {
			stats.num_run_lost++;
		} else {
			stats.num_veh_lost++;

			//---- check the lost vehicle event ----

			if (step.sim_veh_ptr != 0) {
				if (exe->Check_Event (VEH_LOST_EVENT, plan_ptr->Mode (), subarea)) {
					Event_Data event_data;

					event_data.Household (plan_ptr->Household ());
					event_data.Person (plan_ptr->Person ());
					event_data.Tour (plan_ptr->Tour ());
					event_data.Trip (plan_ptr->Trip ());
					event_data.Mode (plan_ptr->Mode ());

					if (step.Problem () == ARRIVAL_PROBLEM) {
						event_data.Schedule (plan_ptr->Arrive ());
					} else if (step.Problem () == DEPARTURE_PROBLEM) {
						event_data.Schedule (plan_ptr->Depart ());
					} else {
						event_data.Schedule (plan_ptr->Schedule ());
					}
					event_data.Actual (exe->step);
					event_data.Event (VEH_LOST_EVENT);

					veh_cell_itr = step.sim_veh_ptr->begin ();
					veh_cell_itr->Location (&to_index, &to_lane, &to_cell);

					event_data.Dir_Index (to_index);

					if (to_index >= 0 || to_cell > 0) {
						cell_offset = to_cell * param.cell_size + (param.cell_size >> 1);

						event_data.Offset (UnRound (cell_offset));
					} else {
						event_data.Offset (0);
					}
					event_data.Lane (to_lane);
					event_data.Route (-1);

					exe->Output_Event (event_data);
				}
			}
Beispiel #2
0
bool Sim_Method::Cell_Use (Travel_Step &step)
{
	int lane, lanes, cell;

	Sim_Dir_Ptr sim_dir_ptr;
	Sim_Lane_Ptr lane_ptr = 0;
	
	Cell_Data cell_rec = step.sim_veh_ptr->front ();

	if (cell_rec.Index () == step.Dir_Index ()) {
		if (step.sim_dir_ptr == 0) {
			step.sim_dir_ptr = &exe->sim_dir_array [cell_rec.Index ()];
		}
		sim_dir_ptr = step.sim_dir_ptr;
	} else {
		sim_dir_ptr = &exe->sim_dir_array [cell_rec.Index ()];
	}
	if (sim_dir_ptr->Method () != MESOSCOPIC) return (true);

	lanes = sim_dir_ptr->Lanes ();
	cell = cell_rec.Cell ();

	for (lane = 0; lane < lanes; lane++) {
		lane_ptr = sim_dir_ptr->Lane (lane);

		if (Cell_Use (lane_ptr, lane, cell, step)) return (true);
	}
	Dtime max_time = exe->step + param.max_wait_time;

	if (use_update_time < max_time) {
		int i, index, num;
		Lane_Use_Data *use_ptr;
		Lane_Use_Period *period_ptr;
		Link_Dir_Data *use_index;

		Use_Type use = step.veh_type_ptr->Use ();
		int veh_type = step.sim_veh_ptr->Type ();
		int type = step.sim_traveler_ptr->Type ();

		Dir_Data *dir_ptr = &exe->dir_array [cell_rec.Index ()];

		index = dir_ptr->First_Lane_Use ();
		if (index < 0) goto use_error;

		for (period_ptr = &exe->use_period_array [index]; ; period_ptr = &exe->use_period_array [++index]) {
			if (period_ptr->Start () >= use_update_time && period_ptr->Start () <= max_time) break;
			if (period_ptr->Periods () == 0) goto use_error;
		}
		num = period_ptr->Records ();
		index = period_ptr->Index ();

		for (i=0; i < num; i++, index++) {
			use_index = &exe->use_period_index [index];
			use_ptr = &exe->lane_use_array [use_index->Link ()];

			if (use_ptr->Offset () > 0 || use_ptr->Length () > 0) {
				int offset = cell * param.cell_size;

				if (use_ptr->Offset () > offset || offset > (use_ptr->Offset () + use_ptr->Length ())) continue;
			}
			if (use_ptr->Type () == PROHIBIT) {
				if (!Use_Permission (use_ptr->Use (), use)) {
					if (veh_type >= 0 && use_ptr->Min_Veh_Type () >= 0) {
						if (veh_type < use_ptr->Min_Veh_Type () || veh_type > use_ptr->Max_Veh_Type ()) {
							if (type > 0 && use_ptr->Min_Traveler () > 0) {
								if (type < use_ptr->Min_Traveler () || type > use_ptr->Max_Traveler ()) return (true);
							} else {
								return (true);
							}
						}
					} else if (type > 0 && use_ptr->Min_Traveler () > 0) {
						if (type < use_ptr->Min_Traveler () || type > use_ptr->Max_Traveler ()) return (true);
					} else {
						return (true);
					}
				}
			} else {
				if (Use_Permission (use_ptr->Use (), use)) {
					if (veh_type >= 0 && use_ptr->Min_Veh_Type () >= 0) {
						if (veh_type >= use_ptr->Min_Veh_Type () && veh_type <= use_ptr->Max_Veh_Type ()) {
							if (type > 0 && use_ptr->Min_Traveler () > 0) {
								if (type >= use_ptr->Min_Traveler () && type <= use_ptr->Max_Traveler ()) return (true);
							} else {
								return (true);
							}
						}
					} else if (type > 0 && use_ptr->Min_Traveler () > 0) {
						if (type >= use_ptr->Min_Traveler () && type <= use_ptr->Max_Traveler ()) return (true);
					} else {
						return (true);
					}
				}
			}
		}
	}
use_error:
	step.Problem (USE_PROBLEM);
	step.Status (1);
	return (false);
}
	virtual void Check_Output (Travel_Step &travel)      { travel.Status (1); }