The problem is well suited for formulation in the form of a mathematical program and can be solved using various optimization libraries.
k-item-.
, PuLP. , .
easy_install pulp
, , , PuLP .
PuLP :
from pulp import *
players = ["William Smith", "Robert Thompson", "Joseph Robinson", "Richard Johnson", "Richard Hall"]
vote = [0.67, 0.31, 0.61, 0.88, 0.28]
price = [8.6, 6.7, 6.2, 4.3, 9.7]
P = range(len(players))
prob = LpProblem("Portfolio", LpMaximize)
x = LpVariable.matrix("x", list(P), 0, 1, LpInteger)
prob += sum(vote[p] * x[p] for p in P)
prob += sum(x[p] for p in P) == 3
prob += sum(price[p] * x[p] for p in P) <= 30
prob.solve()
portfolio = [players[p] for p in P if x[p].varValue]
print(portfolio)
, 3 125 , , 0,5 .