//returns if an airline wants to have code sharing with another airline public static bool AcceptCodesharing(Airline airline, Airline asker, CodeshareAgreement.CodeshareType type) { double coeff = type == CodeshareAgreement.CodeshareType.OneWay ? 0.25 : 0.40; IEnumerable<Country> sameCountries = asker.Airports.Select(a => a.Profile.Country).Distinct().Intersect(airline.Airports.Select(a => a.Profile.Country).Distinct()); IEnumerable<Airport> sameDestinations = asker.Airports.Distinct().Intersect(airline.Airports); IEnumerable<Country> sameCodesharingCountries = airline.GetCodesharingAirlines().SelectMany(a => a.Airports).Select(a => a.Profile.Country).Distinct().Intersect(airline.Airports.Select(a => a.Profile.Country).Distinct()); double airlineDestinations = airline.Airports.Count; double airlineRoutes = airline.Routes.Count; double airlineCountries = airline.Airports.Select(a => a.Profile.Country).Distinct().Count(); double airlineCodesharings = airline.Codeshares.Count; double airlineAlliances = airline.Alliances.Count; //declines if asker is much smaller than the invited airline if (airlineRoutes > 3*asker.Routes.Count) return false; //declines if there is a match for x% of the airlines if (sameDestinations.Count() >= airlineDestinations*coeff) return false; //declines if there is a match for 75% of the airlines if (sameCountries.Count() >= airlineCountries*0.75) return false; //declines if the airline already has a code sharing or alliance in that area if (sameCodesharingCountries.Count() >= airlineCountries*coeff) return false; return true; }