Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with FAI scoring rules #94

Open
hyperknot opened this issue Jun 17, 2022 · 79 comments
Open

How to use with FAI scoring rules #94

hyperknot opened this issue Jun 17, 2022 · 79 comments
Labels
help wanted Extra attention is needed

Comments

@hyperknot
Copy link

hyperknot commented Jun 17, 2022

I'd like to use this with FAI scoring rules, to evaluate record flights. With FAI rules triangle closing needs to be within 400 meter radius fixed. How can I modify it?

So far I find no solution other than copying cli.js and hard coding a different value in my version of cli.js

@mmomtchev
Copy link
Owner

You need to edit scoring-rules.config.js and add a scoring rule with a closingDistanceFixed: 0.4

@hyperknot
Copy link
Author

I added the change to the scoring rules here:
https://github.com/hyperknot/igc-xc-score/blob/6bca0fe83ed608a09261b2eb8eab982f4ce5e167/scoring-rules.config.js#L124

My problem is that it's not doing the optimal calculation. The best point would not be on the track, but between the "head" and the "tail" of the tracklog, as illustrated here. Do you think you can modify the app to make such calculations?

geojson io 2022-06-20 16-17-24

Are FFVL and XContest calculating the closing differently? Also, what is the difference between code: fai and tri?

@mmomtchev
Copy link
Owner

An fai triangle must be almost equilateral with none of its sides being smaller than 28% of the total perimeter.
Do you have a link to a document explaining those rules? Normally all points must lie on the track.

@hyperknot
Copy link
Author

Sure, it's here: https://www.fai.org/sites/default/files/civl/documents/sporting_code_s7_d_-_records_and_badges_2022.pdf

It's not an easy read, but I believe it's like on my drawing:
image

@mmomtchev
Copy link
Owner

Ok, so in fact all turnpoints and the start/finish points are 400m cylinders?

@hyperknot
Copy link
Author

Yes. But for the turnpoints it makes no sense to make them cylinders, it's easier to calculate them as points. The trick is the start/end cylinder.

image

@mmomtchev
Copy link
Owner

In fact this rule can be interpreted as a 800m closing rule? It is a bijection:

  • All points that a separated by 800m or less can be inside a 400m radius cylinder
  • No points separated by more than 800m can be inside a 400m radius cylinder

@hyperknot
Copy link
Author

hyperknot commented Jun 20, 2022

I think a straight 800 meter line is not optimal. The optimal solution would be a "buffer" operation around both polylines and then finding the furthest point on this polygon.

@mmomtchev
Copy link
Owner

I think that it is. You think that a 800m rule will leave out points that will be included in the buffers? I don't see any case where this is possible?

@hyperknot
Copy link
Author

hyperknot commented Jun 20, 2022

It's very close to optimal but not optimal. I don't know how much we want to optimise those few meters though. I made a Geogebra sketch. The left point is the 800 meter midpoint, the right point is the optimal one.

image

A very simple algorithm I could imagine is:

  1. Calculate the start/endpoint as it does currently.
  2. In a loop: Move the start/end 1 meter in a random direction, check if still FAI and still within 400 meter of both. If yes and score is bigger than the previous one, move it.

@mmomtchev
Copy link
Owner

2r is a better closing then the angled r+r - it keeps more of the track

@hyperknot
Copy link
Author

It's true but FAI calculates by the triangle sides, which in our case is determined by the center of the circle.

@mmomtchev
Copy link
Owner

Do you mean the turnpoints or the closing? The placement of the closing center does not influence the score, only the part of the track that is included or not influences the score. But this is not true for the turnpoints, this was my first question?

@hyperknot
Copy link
Author

hyperknot commented Jun 20, 2022

The FAI document is really quite low in details, but here is how I understand it:

  • You put 3 circles, such that they are 400 meter radius and they include 1-1-2 points of the track.
  • You select the closest point of each circle to make up the triangle.
  • For the 2 mid-points, this basically makes no sense, you select a point, put a circle and then select the original point again. Instead it makes sense to select the track point itself.
  • For the start/end point, now I believe it'd be point K on this updated sketch:

FAI calc

@mmomtchev
Copy link
Owner

All FAI rules use 400m cylinders. This means that if you are following a predefined task, you must cross into the 400m cylinder for the turnpoint to be considered attained.
When scoring a free triangle - which means that you define the best possible task given your existing flight track - it is in your best interest to define the turnpoint 400m away from the actual triangle vertex. This rule will require some adapting of igc-xc-score.
The closing is defined as a single point that must be not further than 400m from each side of the track. This rule should be perfectly satisfied by using 800m as closing distance.

I wonder if there is some clever way to calculate the size of the biggest triangle that has vertices lying on equal circles around the given triangle - there probably is - as this will be much easier to implement.

@mmomtchev
Copy link
Owner

mmomtchev commented Jun 20, 2022

I am positive that these are similar triangles but I do not see any easy proof
trtiangle

The inside triangle is the actual triangle on the flight track. The outside triangle is the biggest triangle that fits if its vertices lie on the 400m circles of the inside triangle vertices.

@hyperknot
Copy link
Author

In the FAI rules, every time they calculate using the center of a cylinder (in declared records), you always have to subtract 2 * 400 meters for that cylinder. With straight or straight-with-3-points free distance records, you don't use cylinders, thus you don't need to subtract 2*400 meters for them.

Now for this case, it's really not clear. I'd believe that we cannot cheat, thus if we don't subtract then we have to take the closest points of those circles. (This is the reason why I wrote that for the 2 mid-points it doesn't make any sense to add a circle and then select the original point in the next step).

I'll ask them about clarification, it makes no sense to develop the wrong method :-)

@mmomtchev
Copy link
Owner

Do you have any examples of scored flights?

@hyperknot
Copy link
Author

Unfortunately here they don't provide any details: https://www.fai.org/records?f%5B0%5D=field_record_sport%3A2026&f%5B1%5D=field_record_category%3A125&f%5B2%5D=field_subclass%3A231&f%5B3%5D=field_type_of_record%3A330

I wrote them an email asking for clarifications.

@hyperknot
Copy link
Author

I got an answer from FAI:

5.2.5. Validation Using Start, Turn or Finish Cylinders
The record or badge distance shall be calculated as the minimum distance it is possible to fly by entering the cylinder observation zones. See 1.5.13.3.1. The minimum distance is defined as the straight-line distance between each pair of turn points, decreased by 800 meters for each turn point and 400 meters for each Start/Finish point.

So I believe we can put these circles wherever we want, the calculation is through the centers - 3 * 800 meters.

@mmomtchev
Copy link
Owner

The way I understand this is that the current scoring method is the right one - because it measures the triangle from the points on the flight track - which are 400m away from the turnpoint - however the placement of the turnpoints is not - because they must be further away. But I don't understand the significance of the 400m for the Start/Finish point since the placement of the Start/Finish point is not supposed to have any effect on the score - except for yes/no validity of the triangle. Can you find at least one example of a scored triangle flight?

@hyperknot
Copy link
Author

hyperknot commented Jun 24, 2022

The writing "400 meters for each Start/Finish point." I believe is from the straight distance flights, where the points are different. In our case they are the same and it's 800 meters.

I'll ask them if they can share a scored triangle flight, it's not published on the website.

Now I think we need to optimise all 3 points, as the record is calculated by the center points. I don't think it makes sense but the rules say this so we have no choice.
tri

@mmomtchev
Copy link
Owner

If this is indeed the case, I think this may be done without modifying the underlying search algorithm - once the inner triangle is found, the outer one can be directly computed.

@hyperknot
Copy link
Author

hyperknot commented Jun 25, 2022

I think for the mid-points we can do that, yes. For the start/endpoint I have no other idea but to make a one-off gradient descent-like algorithm.

FAI replied that they use SeeYou, which optimises the distances totally bad. So it's good to know that there is no software which can actually optimise for what FAI is writing in Section 7D. If we can modify igc-xc-score it'd be the first software to do this correctly.

@mmomtchev
Copy link
Owner

I don't think there is anything to do for the start finish point? It does not participate in the score at all - it is only about validity - yes/no.

Those triangles can be calculated from their medians - the medians of the outer triangle are exactly the medians of the inner triangle + 400m.

This means that:

Ma = sqrt(2 * AC**2 + 2*AB**2 - BC**2)
Md = sqrt(2 * DF**2 + 2*DE**2 - EF**2) = sqrt(2 * AC**2 + 2*AB**2 - BC**2) + 400m

for each median

@hyperknot
Copy link
Author

I think I just figured it out. Basically igc-xc-score is doing everything perfect as it is now, with closingDistanceFixed: 0.8.

The drawing in Section 7D about the triangle are wrong.

Free distance around a triangle:
• a closed course flight via 3 position checkpoints, independent of the position of the start/finish
point. The official distance is given by the sum of the legs of the triangle formed by the position
checkpoints.

Basically the question is if the "Mercedes star" type FAI triangles are allowed or not. I really believe they are, and this simplifies our calculation a lot!

Here is an example current world record which is a "Mercedes star" like:
https://www.xcontest.org/2019/world/en/flights/detail:brigitte.kurbel/24.06.2019/07:01
image
and the record: https://www.fai.org/record/18974

igc-xc-score calculates 269.12 km, the FAI record was 269.13 km.

So we have 5 points to optimise: TP1, TP2, TP3, start (cp_in), end (cp_out), which is working perfectly in the current version.

@mmomtchev
Copy link
Owner

I just did run this IGC and my results are 269.12 when using Vincenty's method (hp=true) and 269.13 - the same as the FAI record - when using the much faster approximative formula known as the US FTC method (it was first published by the US FTC in some document about measuring distance between radio emitters and it is famous for being mistaken in the first edition).

I think that it is up to the FAI to clarify this situation.

Their official document states that distances are to be measured according the WGS84 ellipsoid. However (there is a very length explanation about this in the project's README), there is no analytical method for calculating this distance. There is the FTC approximation and there is the iterative Vincenty's method which can be repeated as many times as it is needed to obtain arbitrary precision - igc-xc-score stops at 60cm.

Most practical applications use the FTC method which is much faster since normally a distance of 10m won't matter that much over 270km - but since this is a world record, there should probably be a very strict official method for measuring it.

Also, when it comes to scoring the flight, there is one more point that I forgot about - the closingDistanceFree parameter - because according to some governing bodies, the closing distance is to be substracted from the total distance, while for others (the French FFVL), there is a free (3km) closing distance that does not incur a penalty at all. I am sorry, but I totally forgot about this.

@hyperknot
Copy link
Author

I think for the measurement it has to be Vincenty, that is the reference calculation for geographic distances. FAI currently uses SeeYou which from my experimenting produces the least precise calculation, GPSDump does a much more precise one for example.

For closingDistanceFree in our case it's equal to closingDistanceFixed, as the 800 meter is not subtracted at the end.
BTW from what I've seen on the cli, it seems like the distance value is not subtracted (in km), but the point is subtracted (when using 1.0 scoring). So if I looked at the distance value it's the same with or without closingDistanceFree, is that right?

@hyperknot
Copy link
Author

hyperknot commented Jun 28, 2022

Not strictly this ticket, but related: this flight gets calculated as 141 km in igc-xc-score (XContest profile) and 138 km in XContest. Do you know what could be the reason? Better optimisation or some rules are wrong?
https://www.xcontest.org/world/en/flights/detail:szabbbolcs/27.6.2022/09:20

@mmomtchev
Copy link
Owner

I am sorry for the late reply, but I was exceptionally busy.

The two programs produce a nearly identical scoring: 220.88 for XContest and 221.15 for igc-xc-score.

The 3km difference comes from the fact that igc-xc-score displays the total distance of the triangle and the penalty for the closing distance while XContest displays the total distance of the triangle minus the penalty.

The 200m difference comes from the higher resolution used by igc-xc-score - the XContest scoring has simplified the line, eliminating some points. igc-xc-score considers every point coming from the GPS.

@mmomtchev
Copy link
Owner

@hyperknot After going once again very carefully through the FAI sporting code, section 5.2.5:
https://www.fai.org/sites/default/files/civl/documents/sporting_code_s7_d_-_records_and_badges_2022.pdf

I concluded that when closing an out-and-return distance to one turnpoint, the actual point used must lie on the middle of the 800m closing line - not on the best end. Can you confirm this?

Only the FAI OaR is concerned by this rule - this is the only type of flight where the exact position of the closing line matters.

@mmomtchev
Copy link
Owner

@hyperknot I implemented the cylinders, but alas, I don't have any ideal solution for Free distance around 3 TPs - I will continue trying, but I am afraid that the current approach cannot be applied to those flights when they are scored using cylinders...

@mmomtchev
Copy link
Owner

@hyperknot I have implemented what I think is the perfect scoring according to all FAI rules in the sporting code, section 7D.
I have focused on obtaining a perfect result, and unless there is a bug, this should be the case.
I haven't implemented all time-saving optimizations and currently FAI scoring is very slow. I will release a beta1 in the current state as I cannot afford to invest any more time in this.
If you can test and confirm that everything works as expected, I will proceed with the final release.

@mmomtchev mmomtchev added the help wanted Extra attention is needed label Sep 22, 2022
@hyperknot
Copy link
Author

@mmomtchev this sounds great, thanks a lot for the huge effort! I'll need time to properly test these things, I'll try to look at them in detail over the weekend.

@hyperknot
Copy link
Author

@mmomtchev I'm looking at it now, trying to score this flight as FAI out-and-return.
https://www.xcontest.org/2022/world/en/flights/detail:justACRO/14.8.2022/08:47

What is the difference between OAR1 and 2 (and boundOutAndReturn, scoreOutAndReturn)?

@hyperknot
Copy link
Author

I get

Cannot read properties of undefined (reading 'value')

for oar2.

@hyperknot
Copy link
Author

I think it works perfectly! OAR1:

image

@hyperknot
Copy link
Author

My only problem is with TP0:
image

I think it should be on the track. Basically it's totally not clear from FAI, but I recommend going with on track TP0 and let's see what FAI answers after the next plenary meeting.

@mmomtchev
Copy link
Owner

I get

Cannot read properties of undefined (reading 'value')

for oar2.

Can you post the config file you used? OAR2 is the XCLeague definition of an out-and-return distance flight - which is equivalent to the 2 turnpoints FAI flight.

@mmomtchev
Copy link
Owner

I think it should be on the track. Basically it's totally not clear from FAI, but I recommend going with on track TP0 and let's see what FAI answers after the next plenary meeting.

You can simply remove cylinders: 0.4 from this rule - and performance will be back to what it was before

@hyperknot
Copy link
Author

I get

Cannot read properties of undefined (reading 'value')

for oar2.

Can you post the config file you used? OAR2 is the XCLeague definition of an out-and-return distance flight - which is equivalent to the 2 turnpoints FAI flight.

I used FAI-OAR2 in cli.js:

'FAI-OAR2': [

@hyperknot
Copy link
Author

You can simply remove cylinders: 0.4 from this rule - and performance will be back to what it was before

Thanks, that's it. I think with that it's perfect!

@hyperknot
Copy link
Author

Actually there is a possible bug:

  • setting cylinders: 0 works perfect and quick
  • removing the cylinders key on the other hand triggers some kind of infinite-loop, where the bound is already smaller then the final distance and gets lower and lower

@mmomtchev
Copy link
Owner

Sorry, my bad, if you are removing cylinders you should also remove post: scoring.adjustFAICylinders

@hyperknot
Copy link
Author

Clear. I think we can settle on FAI-OAR like this:

 'FAI-OAR': [
        {
            /**
             * This is the FAI definition of Out-and-Return Distance
             * with a single TP
             */
            name: 'Out-and-Return Distance',
            multiplier: 1,
            bound: scoring.boundOutAndReturn1,
            score: scoring.scoreOutAndReturn1,
            closingDistance: scoring.closingWithLimit,
            closingDistanceFree: 0.8,
            closingDistanceFixed: 0.8,
            rounding: round2,
            finalRounding: round1,
            cardinality: 3,
            code: 'oar',
        }
    ],

One question: what does the (400m) in the bracket mean? I guess it's the non-subtracted closing distance, but it's a bit confusing in those lines:

TP1 : TP2 : 103.73km (0.400km)
TP2 : TP1 : 103.73km (0.400km)

@mmomtchev
Copy link
Owner

@hyperknot, what about the cylinders for the triangles?

@hyperknot
Copy link
Author

hyperknot commented Oct 19, 2022

@hyperknot, what about the cylinders for the triangles?

I believe this should be it:

  'FAI-Tri': [
    {
      name: 'FAI Triangle',
      multiplier: 1,
      bound: scoring.boundTriangle,
      score: scoring.scoreTriangle,
      minSide: 0.28,
      closingDistance: scoring.closingWithLimit,
      closingDistanceFree: 0.8,
      closingDistanceFixed: 0.8,
      rounding: round2,
      finalRounding: round1,
      cardinality: 3,
      code: 'fai',
    },
  ],

I compared it with Brigitte's record in this post and this is what gives consistent answers to the official score:
#94 (comment)

@hyperknot
Copy link
Author

So I currently believe that neither for Triangle nor for OAR the cylinders should be used. Their current "reference" software is SeeYou, which doesn't do anything with cylinder.

For OAR the closing point at the midpoint is I believe the optimal point. For Triangle what is your opinion? It would be optimal at midpoint but too expensive to calculate or implement?

@mmomtchev
Copy link
Owner

For triangles, the closing does not require optimization - it is a deterministic problem that can be solved by a direct approach - a classical nearest-neighbor problem - which is a very well studied problem in computational geometry.

Currently, for all flights except OAR1, once the turn points have been selected, the shortest closing is found.
In OAR1, the closing is part of the optimization. In OAR1, the best placement would be the furthest away point, but the FAI rules say that it must be the point in the middle. OAR1 is the only type of flight where the shortest closing might not be the highest scoring one.

@hyperknot
Copy link
Author

I understand, thanks. I've plotted OAR1 and OAR2 on top of each other, but I don't quite understand it yet.

image

@mmomtchev
Copy link
Owner

OAR1 has only 1 turnpoint and a closing which also serves as the second turnpoint - placed on the middle of the closing line.

OAR2 is a classical circuit flight - it has two turnpoints - and a triangle-style closing which is the other line.

@hyperknot
Copy link
Author

OAR1: Best solution is optimal Out-and-Return Distance 207.5 points, 207.5km, multiplier is 1 [ closing distance is 0.8km ]

OAR2: Best solution is optimal Out-and-Return Flight around 2 TPs 207 points, 207.8km, multiplier is 1 [ closing distance is 0.8km ] [ penalty is 0.8km ]

So OAR2's point precisely is 207.8 - 0.8 and OAR1's point is 207.5 without any penalty right? So OAR1 is a tiny bit better always right?

@mmomtchev
Copy link
Owner

OAR2 should always have a higher score. In this particular example the OAR2 flight has the closing distance as a penalty - because these are the British XCLeague rules, while the OAR1 flight has no penalty, because these are the FAI rules.
The FAI OAR2 should (probably?) have closingDistanceFree: 0.8 - in this case its score will be slightly higher.

@mmomtchev
Copy link
Owner

The reason why the cylinders were so computationally expensive is that I didn't rewrite the bounding function - which was a huge task. With a good bounding function, the cylinders should not be more expensive than the rest.

@hyperknot
Copy link
Author

But what is OAR2 closing doing exactly? Finding the best point on the second half of the track which is <=800 meter from the first half?

@mmomtchev
Copy link
Owner

Sorry for the late reply, OAR2 is distance around two turn points. XCLeague has it - as the only out-and-return type and FAI has it - as one of its out-and-return types. FAI calls it Distance around two turn points. The optimization selects two turn points so as to maximize the distance between them, and a separate closing, the shortest possible one. The closing is not part of the scoring unless there is a penalty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants