"Verbesserter Algorithmus, der automatisch die Hand von" Mirijan "" mithilfe von Kombinationsoptimierung in Python behoben. Ich versuchte es.
Verwenden Sie Muster 2 aus dem Originalartikel.
#Muster 2
hands = ['Haruka', 'Chihaya', 'Miki', 'wahr', 'Takane', 'Yayoi', 'Festival', 'wahr美', 'Emily', 'Ami', 'Momoko', 'Iori', 'Erziehen']
hand_unit_list = [
{'member': {'Iori', 'Emily'}, 'name': 'little trip around the world'},
{'member': {'Emily', 'Festival'}, 'name': 'Charlotte Charlotte'},
{'member': {'Mami', 'Yayoi'}, 'name': 'Möchte →'},
{'member': {'Chihaya', 'Haruka'}, 'name': 'CRIMSON LOVERS'},
{'member': {'Miki', 'Iori'}, 'name': "Erster Don't worry"},
{'member': {'Erziehen', 'Iori', 'Momoko'}, 'name': 'Kyun! Vampir-Mädchen'},
{'member': {'wahr', 'Iori', 'Yayoi'}, 'name': 'Bereitschaftsprinz'},
{'member': {'Miki', 'Iori', 'Takane'}, 'name': '99 Nights'},
{'member': {'wahr', 'wahr美', 'Haruka'}, 'name': 'Nicht blühen! !! Jungfrau Juku'},
{'member': {'Miki', 'Chihaya', 'Haruka'}, 'name': 'Fate of the World'},
{'member': {'Mami', 'Ami', 'Yayoi'}, 'name': 'Funny Logic'},
{'member': {'Miki', 'Mami', 'Ami', 'Iori'}, 'name': 'Hoshisai Stepper'},
{'member': {'Miki', 'Haruka', 'wahr', 'Chihaya', 'Yayoi'}, 'name': 'Fröhlich'},
{'member': {'Miki', 'Haruka', 'wahr', 'Chihaya', 'Emily'}, 'name': 'World changer'},
{'member': {'Iori', 'Haruka', 'wahr', 'wahr美', 'Ami'}, 'name': 'Miracle Night'},
{'member': {'Miki', 'Takane', 'wahr', 'wahr美', 'Yayoi', 'Ami'}, 'name': 'SHOW bei der Live Revolution!'}
]
Lösen wir es als Kombinationsauktionsproblem.
import pandas as pd
from pulp import lpSum
from ortoolpy import model_max, addbinvars, addvals
df = pd.DataFrame([hand_unit['name'] for hand_unit in hand_unit_list],
columns=['name'])
for hand in hands:
df[hand] = False
for i, hand_unit in enumerate(hand_unit_list):
for member in hand_unit['member']:
df.loc[i, member] = True
addbinvars(df)
m = model_max()
m += lpSum(df.Var)
for hand in hands:
m += lpSum(df[df[hand] == True].Var) <= 1
m.solve()
addvals(df)
print(df[df.Val > 0])
name | Haruka | Chihaya | Miki | wahr | Takane | Yayoi | Festival | Mami | Emily | Ami | Momoko | Iori | Erziehen | Var | Val | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Charlotte Charlotte | False | False | False | False | False | False | True | False | True | False | False | False | False | v000002 | 1 |
2 | Möchte → | False | False | False | False | False | True | False | True | False | False | False | False | False | v000003 | 1 |
3 | CRIMSON LOVERS | True | True | False | False | False | False | False | False | False | False | False | False | False | v000004 | 1 |
5 | Kyun! Vampir-Mädchen | False | False | False | False | False | False | False | False | False | False | True | True | True | v000006 | 1 |
Ich habe das gleiche Ergebnis wie der Originalartikel erhalten.
Recommended Posts