Python Forum

Full Version: Help Getting Started - Optimisation Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all

I am getting stuck having searched for about an hour through various forums, Stack oveflow posts and online articles!

I have a simple CSV file which has three columns: baseline-id, comparison-id and score.

[Image: yX2fCMD]


The file contains every possible combination of baseline-id and comparison-id, so I have already done the 'permutations' to get all the possible score.

There are 191 baseline-ids and 196 comparison-ids, so 37.4k permutations.

I'd now like to 'optimise' this to get the maximum score. The only constraint that I have is to make sure that I do not use an ID more than once. Ideally, my results should have the 191 distinct baseline-ids, a distinct comparison-id (cannot use the same id twice) and the score.

I cannot find an accessible tutorial for this but expect this is because I am not quite sure what to search for.

Thanks for any help!!
We probably give 'optimise' a different meaning. For me optimising means that I have working code which delivers expected results but is too slow and I have to refactor it.

Simple brute-force (not optimised) idea: read the file with csv.DictReader into list of dictionaries, find unique pair values of baseline/comparison id-s using set comprehension and find maximum value for every unique pair using list comprehesion. This is very brute force but should deliver desired result.