Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Ranking/sorting algorithm?

 
Post new topic   Reply to topic Printable version
 View previous topic  MERVBot sending checksum errors? Post :: Post Watch damage?  View next topic  
Author Message
tansey
Novice


Joined: Nov 03 2004
Posts: 53
Offline

PostPosted: Thu Mar 03, 2005 12:28 am    Post subject: Ranking/sorting algorithm? Reply to topic Reply with quote

I have a list of stats for players in a txt file. The format is name:stat1:stat2:...:statn:rating:rank such that the players are ranked by their rating, with higher ratings corresponding to lower rankings (rating of 1000 may be ranked #1 where 999 would be #2, etc). The stats are updated after the event is run and therefore the list is in random order.

Can anyone think of a good way to sort/rank the players in the file that's better than (n^2)*logn?

--tansey
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Thu Mar 03, 2005 1:15 am    Post subject: Reply to topic Reply with quote

Quicksort or Mergesort. Will do it in n * log n. If those sources don't help you, google will find source code for you.
Back to top
View users profile Send private message Add User to Ignore List Send email
tansey
Novice


Joined: Nov 03 2004
Posts: 53
Offline

PostPosted: Thu Mar 03, 2005 2:31 am    Post subject: Reply to topic Reply with quote

right, i was assuming that i would use quicksort in my analysis.....
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Mar 03, 2005 9:29 am    Post subject: Reply to topic Reply with quote

if you use STL, you can use the sort() function (#include <algrothim>, hybrid quick/heap sort) or load them into a list and call list.sort (mergesort).
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Thu Mar 03, 2005 9:50 am    Post subject: Reply to topic Reply with quote

Note that neither quicksort nor mergesort are stable. That is, they do not preserve the order of equal items. So if you want a list sorted by two things, you can't simply sort by the second, then sort again by the first. Make your compare function check for both "keys" simultaneously.

Code: Show/Hide
(a1 > a2) || (a1 == a2 && b1 > b2)

_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Mar 03, 2005 12:28 pm    Post subject: Reply to topic Reply with quote

merge sort is stable, and in fact stl's stable_sort function uses merge sort
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Thu Mar 03, 2005 12:46 pm    Post subject: Reply to topic Reply with quote

Well, it might depend on which implementation then I suppose. I never did make sense to me why merge sort wouldn't be stable.
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Thu Mar 03, 2005 3:44 pm    Post subject: Reply to topic Reply with quote

Mr Ekted wrote:
Well, it might depend on which implementation then I suppose. I never did make sense to me why merge sort wouldn't be stable.

Here is a good list of which sorts are stable and which are not.
Back to top
View users profile Send private message Add User to Ignore List Send email
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Thu Mar 03, 2005 4:37 pm    Post subject: Reply to topic Reply with quote

Yea.. as Mr. Ekted said.. Better to write your own. I did a few times too; simple for loop comparing chars. icon_smile.gif
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Thu Mar 03, 2005 6:03 pm    Post subject: Reply to topic Reply with quote

I didn't say write your own. I always use qsort() and implement the compare such that the sort is stable.
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 217 page(s) served in previous 5 minutes.

phpBB Created this page in 0.550416 seconds : 34 queries executed (88.8%): GZIP compression disabled