Skip to content

Conversation

@shlomiasraf
Copy link
Contributor

Full implementation of the Greedy Phragmén algorithm (GPseq) with doctests and logging.

@Simon-Rey
Copy link
Member

The test should be implemented with unittest2. Take inspiration from the other tests in the package.

"""

from __future__ import annotations
from typing import List
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the builtin type list and not this. The package typing should not be used now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it

from pabutools.election.ballot.approvalballot import ApprovalBallot
from pabutools.tiebreaking import TieBreakingRule, lexico_tie_breaking
import numpy as np
import logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it

logging.info(f"project: {project.name} with cost {project.cost} and {float(max(new_loads))} max load")
return float(max(new_loads))

if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the main

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it.

@@ -0,0 +1,83 @@
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be migrated to unittest2. The package does not use pytest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it.

@Simon-Rey
Copy link
Member

See the comments I have left in the code and also for the other PR: (#43).

@Simon-Rey
Copy link
Member

Looks good, two more things: first please remove all the DS_Store files, second remove the setup.py. We use the pyproject.toml to handle all the details of the package itself, there is no need for a setup.py.

@shlomiasraf
Copy link
Contributor Author

Looks good, two more things: first please remove all the DS_Store files, second remove the setup.py. We use the pyproject.toml to handle all the details of the package itself, there is no need for a setup.py.

Ok, I deleted it.

@Simon-Rey
Copy link
Member

Nice! Few extra things, sorry I had not paid attention to that before:

  • For fraction please don't use "/" but always frac from pabutools.fractions. That ensures proper support for the fractions functionnalities.
  • The rule should return a BudgetAlloction instance, not a list of Project.
  • Don't use len(profile) but profile.num_ballots() because if it's a MultiProfile then the two are different.
  • If the implementation does not work for MultiProfile, please check for that at the beginning and raise an error.
  • If the implementation also works for MultiProfile you probably want to make use of profile.multiplicity(ballot) to get the multiplicity of each ballot.
  • The profile type should be AbstractApprovalProfile

@shlomiasraf
Copy link
Contributor Author

I added everything, please lets do it quickly.

@Simon-Rey
Copy link
Member

Your code has indentation problems.

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2025

Codecov Report

Attention: Patch coverage is 92.06349% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.24%. Comparing base (1f89f0e) to head (7a4727a).
Report is 29 commits behind head on main.

Files with missing lines Patch % Lines
pabutools/rules/gpseq.py 92.06% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #44      +/-   ##
==========================================
- Coverage   89.67%   85.24%   -4.43%     
==========================================
  Files          49       50       +1     
  Lines        3641     3708      +67     
==========================================
- Hits         3265     3161     -104     
- Misses        376      547     +171     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Simon-Rey Simon-Rey merged commit 98d8bdd into COMSOC-Community:main Jun 15, 2025
5 checks passed
@shlomiasraf
Copy link
Contributor Author

Fixed it, check now.

@Simon-Rey
Copy link
Member

Simon-Rey commented Jun 15, 2025

Sorry, I'm now confused what rule is it that you implemented? The article you refer to does not exist. I'm confused as to what the difference is compared to the Phragmén's rule already implemented. Maybe @erelsgl knows?

@erelsgl
Copy link
Contributor

erelsgl commented Jun 15, 2025

@Simon-Rey it is Algorithm 1 in this paper: https://arxiv.org/abs/1711.08226
@shlomiasraf there is a mistake in the author names - please fix

@Simon-Rey
Copy link
Member

So for now the implementation is not that of Algo 1 from Aziz et al. (which, by the way, is the maximin support rule despite the name they gave it, see the survey). The current implementation does:

  • Choose greedily the projects one after the other
  • Select the project that minimises the maximum load of its approvers
  • The load is defined iteratively, starting from 0, each time a project is approved its supporters increase their load by c / num_supporters.

This is not the maximin support rule because in the latter the load is constantly recompute, i.e., the LP in Algo 1 is run at each iteration so the spread of the load of a project (uniform in the current implementation) can change at each iteration.

This is also not Sequential Phragmén as for the latter when selecting a project, the total load of its approvers is redistributed among them so that they all end up with the same load. Note that I have already implemented Sequential Phragmén in the package.

The implementation is a simplified version of sequential phragmen in which the load of a voter is monotonic. I am not aware of this rule having been studied and I'm now not super sure of the usefulness of having it in the package.

There may be something I missed in the implementation, please correct me if I'm wrong.

@shlomiasraf
Copy link
Contributor Author

You're right, I've now updated the implementation so that the load is distributed optimally rather than uniformly, and it now matches the algorithm described in the paper.

@Simon-Rey
Copy link
Member

Since the PR has been merged already you need to open a new one for me to see your code. Note that I have cleaned things around after the merge and that your code is now in the phragmen.py file.

@shlomiasraf
Copy link
Contributor Author

Okay, I’ve opened another one.

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

Successfully merging this pull request may close these issues.

4 participants