0

I have three lists, each list has 200,000 item. The first list titled 'config' is a list of configuration names (these are window blind configuration). The second list has the illuminance performance of each configuration (same order, meaning that config_a001 yields illuminance value of 350). The last list has a value for each config (same order as well, so config_002 has a value of 0.24)

config = ['config_a001', 'config_a002', ......]
illuminnace = [350, 376, 260, 500, 450,......]
LUR_value = [0.3,0.24,.7,.1,.....]

I need to pick the best 5 configurations that yield the highest illuminance and lowest LUR value. If this is not possible, I need to pick the best 5 configurations with the lowest LUR value but their illuminance should be higher than a specific threshold, let's say 450.

I know that things like this should be solved using a genetic algorithm but I'm experienced in this area, I'd appreciate it if anyone here provides a suggestion.

Julia_arch
  • 376
  • 2
  • 4
  • 15
  • 1
    `zip` the lists together, and then use `(illuminance, -LUR_value)` as your key function. Then you can just take the slice of the first 5 elements. See: https://stackoverflow.com/questions/6666748/python-sort-list-of-lists-ascending-and-then-decending – Patrick Haugh Dec 10 '18 at 15:58

2 Answers2

1

You might consider organizing the data into a pandas DataFrame:

import pandas as pd

config = ['config_a001', 'config_a002', 'config_a003', 'config_a004', 'config_a005', 'config_a006']
il = [350, 376, 310, 340, 290, 375]
lur = [0.3, 0.24, 0.21, 0.31, 0.24, 0.28]

Create a Dictionary of your lists

d = {'config': config, 'il': il, 'lur': lur}

Create a DataFrame object from your dictionary

df = pd.DataFrame(d)

Use sort_values() and slice the top 5 results from the config column:

res = df.sort_values(['il', 'lur'], ascending=[False, True])[:5]['config'].values

This provides a numpy array with config values.

list(res)
# Result: ['config_a002', 'config_a006', 'config_a001', 'config_a004', 'config_a003']
Wes Doyle
  • 2,199
  • 3
  • 17
  • 32
1

Given:

config = ['config_a001', 'config_a002', 'config_a003', 'config_a004','config_a005']
illuminnace = [350, 376, 260, 500, 450]
LUR_value = [0.3,0.24,.7,.1,.3]

If 'optimization' is the highest illuminnace with the lowest LUR_value you can zip the lists together to form tuples of the data:

>>> list(zip(config,illuminnace,LUR_value))
[('config_a001', 350, 0.3), ('config_a002', 376, 0.24), ('config_a003', 260, 0.7), ('config_a004', 500, 0.1), ('config_a005', 450, 0.3)]

And then sort those with a key function:

>>> sorted(zip(config,illuminnace,LUR_value),key=lambda t: (-t[1],t[2]))
[('config_a004', 500, 0.1), ('config_a005', 450, 0.3), ('config_a002', 376, 0.24), ('config_a001', 350, 0.3), ('config_a003', 260, 0.7)]

If you want to filter, add a expression after the zip but before sorted to filter on the relevant criteria:

>>> sorted((t for t in zip(config,illuminnace,LUR_value) if t[1]>=450),key=lambda t: (-t[1],t[2]))
[('config_a004', 500, 0.1), ('config_a005', 450, 0.3)]

If you have more complicated grouping criteria, either write a custom key function for sort that expresses it or consider using itertools.groupby. Your current example data is not complete enough to give an example.

dawg
  • 98,345
  • 23
  • 131
  • 206