Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weighted voters #28

Open
oriyalperin opened this issue Jun 2, 2024 · 6 comments
Open

Weighted voters #28

oriyalperin opened this issue Jun 2, 2024 · 6 comments

Comments

@oriyalperin
Copy link

Does the library support assigning weights to voters?

@erelsgl
Copy link
Contributor

erelsgl commented Jun 9, 2024

This could be useful, for example, for checking settings such as: a city has 100 voters; 60 support projects A1,...,A10 and 40 support projects B1,...,B10. We expect 60% of the budget to go to projects A1,...,A10.

In abcvoting, many algorithms allow a weight parameter. It is possible in pabutools?

@Simon-Rey
Copy link
Member

Well for your example there is no need for weights Erel, you can just multiply the ballots.

For the general answer: every rule support both Profile and MultiProfile (see the docs) where the latter is a mapping from ballots to multiplicity of the ballots. I believe that putting non-integer values would not break anything but one would need to be check that.

@Simon-Rey
Copy link
Member

@oriyalperin
Copy link
Author

Thanks @Simon-Rey,
I tried using float values similarly to the example here, but they aren't supported.
According to the docs, the MultiProfile class inherits from the Python class Counter, so this makes sense to me.
Is there another way to define MultiProfile that allows using non-integer values?

@Simon-Rey
Copy link
Member

Simon-Rey commented Jun 14, 2024

I am not sure what you tried, this works for me:

from pabutools.election import Project, ApprovalBallot, ApprovalProfile

projects = [Project("p" + str(i), cost=2) for i in range(10)]
b1 = ApprovalBallot(projects[:2])
b2 = ApprovalBallot(projects[:5])

f1 = b1.frozen()
f2 = b2.frozen()

profile = ApprovalProfile([b1] * 4 + [b2] * 10)

m = profile.as_multiprofile()

m[f1] = 0.75
m[f2] = 0.84

m.total()  # => 1.5899999999999999

The counter class does not force int.

@Simon-Rey
Copy link
Member

In general though, it is pretty ugly and could be implemented in a better fashion. But at least since the support for multiprofile is there for almost everything, it should not be difficult to have weights as well. If someone wants to implement that, I'm happy to help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants