[Comprehensive] Ladder Algorithm

Source: Internet
Author: User

<! -- Copyright notice! Reprinted, please describe the source. Thank you :) -->

<! -- By polo Shen: http://www.cnblogs.com/polossk/->

 

Target

Today, I heard people say that the ACM team of a school has developed a rating system, which is similar to the rating of topcoder and codeforces. the intuitive points are more likely to reflect the results of the competition and recent performances of everyone. They are also said to regard this as one of the assessment criteria.

It sounds awesome!

But we have a school !!!

Then I thought of Zuckerberg's "little girl" activity when I watched "Social Networking.

Programmers have a new idea. It's a waste of their work!

Create your own rating system.

Ladder algorithm Overview

It's better to make up your knowledge first. The so-called ladder algorithm is actually very simple, although the mathematical proof is very complicated... The foundation of the ladder algorithm is that the population level basically satisfies the normal distribution. To put it simply, it is assumed that most people are quite arrogant, and a small number of elites and low-level people exist at the same time. At the same time, the core operations are self-evident. Simply put, if a person matches at the same level, the winner points out and the loser points out. When the gap between two players is relatively large, the points to be deducted after the storm will be higher than the same level, but it will not soar.

Here I use ELO rating system.

The general algorithm is as follows:

1. Assume that the current score of the two persons has been given:

2. Calculate the expected result:

3. Modify the score based on the actual result:

Here, s indicates the result, that is, 1, 0.5, 0, and K indicates the match coefficient. Generally, the amount of score changes in a single game is not too large.

Actual implementation

However, this is different from the model we just created. The model just now was prepared for the chess player, that is, two casual hands, and then the score is rising. In other words, the more games you play, the better your score.

Not understood? Dota and LOL have been playing, and the competition will always be between two teams.

But codeforces is different. Maybe hundreds of people and thousands of people are playing this game at the same time. What should we do?

The simplest idea I gave was to share the game coefficient. Everyone was involved in the comparison and finally compared with myself.

What does it mean? I assume that there are n contestants participating in one competition at the same time. For contestant I, it is equivalent to having the same question with n-1 contestants at the same time. So I shared the coefficient of the competition to the contestants (of course, there is a better way to allocate according to the gap between the two before the competition, which is closer to reality, just let them "Compare" each other.

However, this will cause some people to keep increasing points, and the increase is larger than once. Therefore, the self-comparison method must be introduced. To put it simply, if a person with a score of 1700 participates in a 800-Person Competition, the highest score of all contestants is 1700. if this person has a score of 2nd in the previous game, the entire audience is 12th. Although his ranking is very high, but he lost to his last game, it will still "Drop" some scores. However, the decline here is not an absolute decline, that is, the "increase" decline. That is to say, his score will basically remain at this level, but will not suddenly fall or suddenly increase the score.

This is my general idea. After all, it's not a big project. Just do it.

Code

The code I used is Ruby. I passed in a text document to record the content of the contestant:

<Rank> <Name> <rating> <solvedproblem>

4 data for calculation. (In fact, the number of questions is unnecessary ...)

Finally, output a text document, which records

<Rank> <Name> <newrating>

# Encoding = UTF-8class student attr_accessor: Name attr_accessor: rating attr_accessor: rank partition: _ solve partition: _ drating def initialize (name = "unknown", Rak = 100, RTG = 1500, solve = 0) @ Rank = RAK. to_ I @ name = Name @ rating = RTG. to_ I @ _ drating = 0 @ _ solve = solve. to_ I end def initialize (str2) STR = str2.to _ s data = Str. split ('') @ Rank = data [0]. to_ I @ name = data [1] @ rating = Data [2]. to_ I @ _ solve = data [3]. to_ I @ _ drating = 0 end def Update (d) # accumulate rating changes @ _ drating + = d end def modify # update rating @ rating + = @ _ drating = 0 @ rating = @ rating. to_ I end def tostringline return "# {@ rank} \ t # {@ name} \ t # {@ rating} \ n" End def print # puts "# {@ rank }\ T # {@ name} \ t # {@ rating} "puts" # {@ rating} "end $ kcef = 60 # coefficient of competition = beginrating algorithm: compare two contestants. Each comparison is updated with _ drating. Comparison Method: Compare the number of questions first: the number of questions wins, the number of questions is negative, and the number of questions is negative. If the number is equal, the ranking is compared. The coefficient is selected based on the comparison result for calculation. Update coefficient rule: Calculate the coefficient of the competition by the number of participating students as follows: CEF = $ kcef/SZ update Rule: when updating, the two students will compare each other, the incremental calculation method is as follows: A: da = CEF * (SA-ea) B: DB = CEF * (Sb-EB) at last, you can accumulate the data directly. = Enddef calc_ea_eb (RA, Rb) da = (RB-ra) /400.0 DB =-Da ta = 10.0 ** da + 1.0 TB = 10.0 ** dB + 1.0 Ea = 1.0/Ta EB = 1.0/TB return [EA, EB] enddef calc_sa_sb (a, B) solvea =. _ solve solveb = B. _ solve Pa =. rank Pb = B. rank if solvea <solveb return [0.0, 1.0] elsif solvea> solveb return [1.0, 0.0] elsif Pa <Pb return [1.0, 0.0] else return [0.0, 1.0] endenddef calc_cef (RA, Rb, SZ) return $ kcef/szenddef competition (a, B, SZ) # modify the incremental Ea of two persons, EB = calc_ea_eb (. rating. to_f, B. rating. to_f) SA, SB = calc_sa_sb (a, B) CEF = calc_cef (. rank. to_f, B. rank. to_f, Sz. to_f) da = (SA-ea) * cef db = (Sb-EB) * cef. update (DA) B. update (db) enddef read (PATH) items = array. new file. open (path,: encoding => 'utf-8 '). each_line do | Line | item = student. new (line) Items <item end SZ = items. size # Compare for I in 0 one by one... SZ for J in 0... SZ if I = J then next else competition (items [I], items [J], Sz. to_ I); end # Compare items. each do | data | temp = data temp. modify # update the rating competition (temp, Data, SZ) temp. modify # rating data after self-comparison. modify # calculate the average value data for rating. rating = (temp. rating. to_ I + data. rating. to_ I)/2 ). to_ I end file = file. new ("result.txt", "W +") items. each do | data. modify file. print data. tostringline endendread ("contest1.txt ")
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.