Python Forum
Loop to find the best combination/score
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop to find the best combination/score
#21
I wrote a quick-n-dirty test by hand just to see how quick it would be. A little optimization will make it much faster. I wrote it in C, so the players list is dynamically allocated array of pointers. An array of player structs would be faster as would a C++ vector. I am using a new compiler and trying to learn how to wirte C/C++ using VSCode instead of Visual Studio or the gnu compiler and command line tools. Not sure what compiler optimization settings are, but I doubt that my executable is "highly optimized".

I modified my code to use structs and arrays of structs instead of pointers. This allows certain optimizations by the compiler. When I run my new, very ugly but optimized code it takes 2 minutes to find the best team that can be made from 400 players. I ran my timing test multiple times because the player list will affect timing. The fastest time was 1 minute 42 seconds. The worst was 3 minutes 17 seconds.

A really fun comparison is looking at the time for 60 teams. You posted that your numpy code for solving the problem ran for 3366 seconds to come up with a solution. My C program solves it in 0.016 seconds. 210,375 times faster. The C program is also 724 times faster than my solution that used combinations and 47 times faster than my Python program that uses loops.
Reply
#22
Thanks for all your tests.

I started to do a C++ program, so far I succeeded to get my 400 players almost instantly with some rand% for the values.

Now I am looking for the loop/combinations, my few tests are taking too long at the moment (or bad alloc), need to do more research for that :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 2,476 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  Algorithm to generate a combination guvinicius2 5 2,565 Aug-15-2020, 10:42 PM
Last Post: deanhystad
  loops in combination with lists Juru 4 2,822 May-07-2020, 02:58 PM
Last Post: Marbelous
  Average score MartinEvtimov 5 6,852 Apr-02-2017, 07:35 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020