voting-tools / pref_voting

pref_voting is a Python package that can be used to study and run elections with different preferential voting methods (graded voting methods and cardinal voting methods are also included for comparison).
https://pref-voting.readthedocs.io/
MIT License
11 stars 4 forks source link

Preflib export should use the cmap #68

Closed DominikPeters closed 5 months ago

DominikPeters commented 5 months ago

The abif, json, and csv exporters all include cmap information; here is an example of an abif export:

# 4 candidates
=0 : [a]
=1 : [b]
=2 : [c]
=3 : [d]
1:0>3>2>1
1:0>2>3>1

However, the Preflib export does not do so:

# FILE NAME: profile.soc
# TITLE: 
# DESCRIPTION: 
# DATA TYPE: soc
# MODIFICATION TYPE: 
# RELATES TO: 
# RELATED FILES: 
# PUBLICATION DATE: 
# MODIFICATION DATE: 
# NUMBER ALTERNATIVES: 4
# NUMBER VOTERS: 2
# NUMBER UNIQUE ORDERS: 2
# ALTERNATIVE NAME 0: Alternative 0
# ALTERNATIVE NAME 3: Alternative 3
# ALTERNATIVE NAME 2: Alternative 2
# ALTERNATIVE NAME 1: Alternative 1
1: 0, 3, 2, 1
1: 0, 2, 3, 1

It should instead say, for example, # ALTERNATIVE NAME 0: a. Also the alternative names appear to be listed in the order of preference of the first voter; not sure if that's the intended behavior.

This probably needs to be done when passing the profile to preflibtools. https://github.com/voting-tools/pref_voting/blob/3da023508de791abec895f643eb2167c3501ee71/pref_voting/io/writers.py#L17-L39

@Simon-Rey: is it intentional that this code generates so many plausibly-unnecessary empty metadata fields?

epacuit commented 5 months ago

Thanks. I fixed this in the current version. It now export the cmap when converting to a preflib instance.