TrafficState DCPAUrgencyStrategy::mostUrgentAircraft(Detection3D* detector, const TrafficState& ownship, const std::vector<TrafficState>& traffic, double T) { TrafficState repac = TrafficState::INVALID; if (!ownship.isValid() || traffic.empty()) { return repac; } double mindcpa = 0; double mintcpa = 0; double D = ACCoRDConfig::NMAC_D; double H = ACCoRDConfig::NMAC_H; Vect3 so = ownship.get_s(); Velocity vo = ownship.get_v(); for (TrafficState::nat ac = 0; ac < traffic.size(); ++ac) { Vect3 si = traffic[ac].get_s(); Velocity vi = traffic[ac].get_v(); Vect3 s = so.Sub(si); Velocity v = vo.Sub(vi); ConflictData det = detector->conflictDetection(so,vo,si,vi,0,T); if (det.conflict()) { double tcpa = CD3D::tccpa(s,vo,vi,D,H); double dcpa = v.ScalAdd(tcpa,s).cyl_norm(D,H); // If aircraft have almost same tcpa, select the one with smallest dcpa // Otherwise, select aircraft with smallest tcpa bool tcpa_strategy = Util::almost_equals(tcpa,mintcpa,PRECISION5) ? dcpa < mindcpa : tcpa < mintcpa; // If aircraft have almost same dcpa, select the one with smallest tcpa // Otherwise, select aircraft with smallest dcpa bool dcpa_strategy = Util::almost_equals(dcpa,mindcpa,PRECISION5) ? tcpa < mintcpa : dcpa < mindcpa; // If aircraft are both in a min recovery trajectory, follows tcpa strategy. Otherwise follows dcpa strategy if (!repac.isValid() || // There are no candidates (dcpa <= 1 ? mindcpa > 1 || tcpa_strategy : dcpa_strategy)) { repac = traffic[ac]; mindcpa = dcpa; mintcpa = tcpa; } } } return repac; }
ConflictData WCV_tvar::conflictDetection(const Vect3& so, const Velocity& vo, const Vect3& si, const Velocity& vi, double B, double T) const { LossData ret = WCV3D(so,vo,si,vi,B,T); double t_tca = (ret.getTimeIn() + ret.getTimeOut())/2; double dist_tca = so.linear(vo, t_tca).Sub(si.linear(vi, t_tca)).cyl_norm(table.getDTHR(),table.getZTHR()); return ConflictData(ret, t_tca,dist_tca,so.Sub(si),vo.Sub(vi)); }
bool VectFuns::divergent(const Vect3& so, const Velocity& vo, const Vect3& si, const Velocity& vi) { return so.Sub(si).dot(vo.Sub(vi)) > 0; }