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

Support the Condorcet Election Format as input #58

Open
julien-boudry opened this issue May 11, 2023 · 10 comments
Open

Support the Condorcet Election Format as input #58

julien-boudry opened this issue May 11, 2023 · 10 comments

Comments

@julien-boudry
Copy link

julien-boudry commented May 11, 2023

The Condorcet Election Format (.cvotes) is a tentative to standardize election input (configuration & vote data) in a human-readable and editable format, but also a precise definition that is easy to parse for a program.

https://github.com/CondorcetVote/CondorcetElectionFormat

@andrewcmyers
Copy link
Owner

Since CIVS already has a format, one easy initial step would be write a converter from this format to the CIVS input format.

I guess there's some some PHP code to parse this? And interpret it? Not the language I'd pick for the job, to be honest.

@julien-boudry
Copy link
Author

There is one here:

But it is strongly coupled with the Condorcet library of the same project. It is therefore not a pure parser, as its purpose is to convert into an Election object but not expose raw data into data structure.

However, it would be easy to add a tiny wrapper to export it in Civs format.
If it's in PHP, I could even take care of this abstraction which would perform these tasks:
Input => CondorcetElection object => Export to Civs format (to define ?)

This is less elegant than a more agnostic parser. And possibly a PERL one.

And also, some protection must be planned, because the Condorcet PHP can manage billions of votes.
But in the context of a web service, limits must be set because it can be an attack, I have just to write the following:
A > B > C * 10000000000000000

@andrewcmyers
Copy link
Owner

The CIVS input format does support weighting votes. The tabulation algorithms don't, but that is a separate problem.

@julien-boudry
Copy link
Author

julien-boudry commented May 11, 2023

With the CondorcetElectionFormat, you have:

Weight:
A > B ^100 # One vote with a weight of 100

Quantifier:
A > B *100 # 100 identical votes

Both:
A > B ^10 *100 # 100 identical votes with for each a weight of 10

Weight can be unsupported with a warning (or better: silently converted to a quantifier, because it s the same for the results calculation).
But the quantifier cannot be ignored because it's change the result.

@julien-boudry
Copy link
Author

julien-boudry commented May 11, 2023

The main problem should be that Civs format uses an order to identify a candidate, but Cef format uses the candidate's name.
So, the conversion should know in which order the candidate are registered first.
Actual Condorcet libraries can do it because internally the candidates have an Id, but it's a little bit hacky.

Another problem is the ties, Cef supports ties on a rank.

And also: implicit ranking. How absence of choice is implemented.
With the Condorcet logic, it's filled as a last rank per default, unless implicit ranking is false. This choice can change the result.


An illustration of the conversion could be:

Cef:

#/Candidates: A ; B ; C ; D
#/Weight allowed: true
#/Implicit Ranking: true

A > B > C * 2
C > B > A ^2
B > A > C ^2 *2

Civs:

2X1,2,3,4
2X3,2,1,4
4X2,1,3,4

Or if Cef set: #/Implicit Ranking: false

Civs:

2X1,2,3,-
2X3,2,1,-
4X2,1,3,-

But the following, I don't know how to do it:

Cef:

#/Candidates: A ; B ; C ; D

A > B = C > D

@andrewcmyers
Copy link
Owner

CIVS will let you specify ties. Your example would be

1,2,2,3

@julien-boudry
Copy link
Author

Is there a comment system, where I can put additional information, such as the identity of the candidates?

@andrewcmyers
Copy link
Owner

Lines beginning with a # are treated as comments and ignored.

@julien-boudry
Copy link
Author

julien-boudry commented May 12, 2023

Just wrote a PR to add a Converter (export only) to the Civs format inside the Condorcet project: julien-boudry/Condorcet#134

Can you read, especially the test file, and validate it?

Then, it should be easy to write a conversion routine from Cef to Civs.
Something like this:

$election = (new CondorcetElectionFormat(<string or file input>))->setDataToAnElection();

CivsFormat::createFromElection(election: $election, file: null); // return string unless file is set

Or, a little bit more ambitious: add a Converter command to the Condorcet command line version.

@julien-boudry
Copy link
Author

Condorcet v4.4 just release with support of exporting to Civs format.
And also a new console command convert.

https://www.condorcet.io/2.AsCommandLineApplication/3.ImportFromElectionFormat?id=convert-formats

As command line application:

condorcet convert --from-condorcet-election-format --to-civs-format pathToInput pathToOutput

As PHP library:

$election = (new CondorcetElectionFormat(<string or file input>))->setDataToAnElection();

CivsFormat::createFromElection(election: $election, file: null); // return string unless file is set

Examples of conversions can be seen in the test file:
https://github.com/julien-boudry/Condorcet/blob/master/Tests/src/Tools/Converters/CivsFormatTest.php

Better: should be the first alternative implementation in Perl of this standard.

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

2 participants