local tom_dist_coefficient = { --ASECNA International coefficient derived from weight/distance multiplied by unit_rate { 14001, { -- MTOM upper limit (exclusive) {750000, 0}, -- distance upper limit (exclusive), coefficient {2000000, 0}, -- ... {3500000, 0}, -- ... {math.huge, 0} -- ... } }, { 20001, { {750000, 1}, {2000000, 5}, {3500000, 12}, {math.huge, 20} } }, { 50001, { {750000, 1.2}, {2000000, 6}, {3500000, 14.4}, {math.huge, 24}} }, { 90001, { {750000, 1.4}, {2000000, 7}, {3500000, 16.8}, {math.huge, 28}} }, { 140001, { {750000, 1.6}, {2000000, 8}, {3500000, 19.2}, {math.huge, 32}} }, { 200001, { {750000, 1.8}, {2000000, 9}, {3500000, 21.6}, {math.huge, 36}} }, { 270001, { {750000, 2}, {2000000, 10}, {3500000, 24}, {math.huge, 40}} }, { 350001, { {750000, 2.15}, {2000000, 10.75}, {3500000, 25.8}, {math.huge, 43}} }, { 440001, { {750000, 2.3}, {2000000, 11.5}, {3500000, 27.6}, {math.huge, 46}} }, { 540001, { {750000, 2.45}, {2000000, 12.25}, {3500000, 29.4}, {math.huge, 49}} }, { math.huge, { -- greater 540Tonnes {750000, 2.6}, {2000000, 13}, {3500000, 31.2}, {math.huge, 52}} } } -- find the first entry in an array of pairs, where pair[1] > value function upper_bound(value, table) for index, item in ipairs(table) do if item[1] > value then return item[2] end end end -- find the matching coefficient for a given mass and distance function coefficient(tom, dist) return upper_bound(dist, upper_bound(tom, tom_dist_coefficient)) end local lib = {}; lib.distance_method = Distance_method.great_circle; function lib:calculate(flight_context, route_context, distance) return self:estimate(flight_context, distance); end function lib:estimate(flight_context, distance) if flight_context:origin_icao_code == NZAA then return 10000 else return self.unit_rate * coefficient(flight_context.mtom, distance); end end return lib;
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more