Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pulp
- # Base score
- managerValues = {
- "beryl": 70,
- "sereniel": 23,
- "maribell": 48,
- "narja": 42,
- "tiphera": 54,
- "nine": 50,
- "tenebria": 60,
- "heidemarie": 40,
- "mika": 66,
- "rei": 75,
- "owen": 64,
- "luke": 51,
- "lucas": 32,
- "cassius": 39,
- "yuki": 40,
- "haru": 46,
- "fei": 59,
- "renoa": 54,
- "rossweisse": 90,
- "orlea": 62,
- "hilde": 48,
- "arabella": 100,
- "olga": 64
- }
- # Bonus
- managerBonus = {
- ("sereniel", "narja"): 200/5,
- ("sereniel", "heidemarie"): 250/5,
- ("maribell", "nine"): 200/4,
- ("maribell", "beryl"): 100/4,
- ("narja", "sereniel"): 150/4,
- ("tiphera", "nine"): 200/7,
- ("nine", "tiphera"): 200/6,
- ("tenebria", "heidemarie"): 150/5,
- ("heidemarie", "tenebria"): 100/3,
- ("heidemarie", "tiphera"): 100/3,
- ("mika", "renoa"): 180/5,
- ("rei", "renoa"): 200/6,
- ("owen", "renoa"): 150/4,
- ("luke", "lucas"): 200/4,
- ("lucas", "luke"): 300/6,
- ("cassius", "heidemarie"): 100/3,
- ("cassius", "olga"): 100/3,
- ("yuki", "fei"): 200/5,
- ("yuki", "haru"): 100/5,
- ("haru", "rei"): 200/6,
- ("fei", "hilde"): 200/4,
- ("renoa", "rossweisse"): 80/4,
- ("renoa", "orlea"): 80/4,
- ("orlea", "fei"): 120/4,
- ("hilde", "arabella"): 200/7,
- ("hilde", "olga"): 200/7,
- ("olga", "hilde"): 200/6
- }
- SLOTS = 8
- # Problem definition
- prob = pulp.LpProblem("managers", pulp.LpMaximize)
- # Add variables - adds a variable with a label, keyed against the "for x in selection" part
- x = {m: prob.add_variable(f"x_{m}", cat="Binary") for m in managerValues}
- y = {p: prob.add_variable(f"y_{p[0]}_{p[1]}", cat="Binary") for p in managerBonus}
- # Add objective
- prob += (pulp.lpSum(x[m]*managerValues[m] for m in managerValues)
- + pulp.lpSum(y[p]*managerBonus[p] for p in managerBonus))
- # Add constraints
- prob += pulp.lpSum(x.values()) <= SLOTS
- for (i, j) in managerBonus:
- prob += y[(i, j)] <= x[i]
- prob += y[(i, j)] <= x[j]
- # Solve
- result = prob.solve(pulp.HiGHS(msg=False))
- print("Status:", result.status.name)
- print("Score: ", pulp.value(prob.objective))
- print("Team: ", [m for m in managerValues if x[m].value() > 0.5])
Add Comment
Please, Sign In to add comment