Skip to content

Commit 97d9c74

Browse files
committed
v2.1.4
1 parent 25a6c58 commit 97d9c74

File tree

10 files changed

+93
-38
lines changed

10 files changed

+93
-38
lines changed

mapel-all/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mapel"
7-
version = "2.1.3"
7+
version = "2.1.4"
88
authors = [
99
{name = "Stanislaw Szufa", email = "s.szufa@gmail.com"},
1010
{name = "Niclas Boehmer", email = "niclas.boehmer@tu-berlin.de"},

mapel-all/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mapel-core==2.1.3
2-
mapel-elections==2.1.3
3-
mapel-roommates==2.1.3
4-
mapel-marriages==2.1.3
1+
mapel-core==2.1.4
2+
mapel-elections==2.1.4
3+
mapel-roommates==2.1.4
4+
mapel-marriages==2.1.4

mapel-core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mapel-core"
7-
version = "2.1.3"
7+
version = "2.1.4"
88
authors = [
99
{name = "Stanislaw Szufa", email = "s.szufa@gmail.com"},
1010
{name = "Niclas Boehmer", email = "niclas.boehmer@tu-berlin.de"},

mapel-core/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ scikit-learn~=1.3.0
77
tikzplotlib~=0.10.1
88
tqdm~=4.66.0
99
gurobipy~=10.0.2
10-
prefsampling~=0.1.2
10+
prefsampling>=0.1.2

mapel-elections/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mapel-elections"
7-
version = "2.1.3"
7+
version = "2.1.4"
88
authors = [
99
{name = "Stanislaw Szufa", email = "s.szufa@gmail.com"},
1010
{name = "Niclas Boehmer", email = "niclas.boehmer@tu-berlin.de"},

mapel-elections/src/mapel/elections/__init__.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import Counter
2+
13
from .distances_ import get_distance
24
import mapel.core.printing as pr
35
from .objects.ApprovalElectionExperiment import ApprovalElectionExperiment
@@ -115,21 +117,33 @@ def generate_ordinal_election_from_votes(votes=None):
115117
election.num_candidates = len(votes[0])
116118
election.num_voters = len(votes)
117119
election.votes = votes
120+
election.is_exported = False
121+
c = Counter(map(tuple, votes))
122+
counted_votes = [[count, list(row)] for row, count in c.items()]
123+
counted_votes = sorted(counted_votes, reverse=True)
124+
election.quantites = [a[0] for a in counted_votes]
125+
election.distinct_votes = [a[1] for a in counted_votes]
126+
election.num_options = len(counted_votes)
118127
return election
119128

120129

121-
def generate_approval_election_from_votes(votes=None):
130+
def generate_approval_election_from_votes(votes=None, num_candidates=None):
122131
election = ApprovalElection()
123-
election.num_candidates = len(set().union(*votes))
132+
if num_candidates is None:
133+
election.num_candidates = len(set().union(*votes))
134+
else:
135+
election.num_candidates = num_candidates
124136
election.num_voters = len(votes)
125137
election.votes = votes
138+
election.is_exported = False
139+
c = Counter(map(tuple, votes))
140+
counted_votes = [[count, list(row)] for row, count in c.items()]
141+
counted_votes = sorted(counted_votes, reverse=True)
142+
election.quantites = [a[0] for a in counted_votes]
143+
election.distinct_votes = [a[1] for a in counted_votes]
144+
election.num_options = len(counted_votes)
126145
return election
127146

128147

129148
def compute_distance(*args, **kwargs):
130149
return get_distance(*args, **kwargs)
131-
132-
133-
# # # # # # # # # # # # # # # #
134-
# LAST CLEANUP ON: 11.07.2023 #
135-
# # # # # # # # # # # # # # # #

mapel-elections/src/mapel/elections/objects/ApprovalElection.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import logging
33
from abc import ABC
4+
from collections import Counter
45

56
from matplotlib import pyplot as plt
67
from mapel.elections.cultures_ import generate_approval_votes
@@ -44,7 +45,8 @@ def import_approval_election(self):
4445
imports.import_fake_app_election(self.experiment_id, self.election_id)
4546
else:
4647
self.votes, self.num_voters, self.num_candidates, self.params, \
47-
self.culture_id = imports.import_real_app_election(
48+
self.culture_id, self.num_options, self.quantites, self.distinct_votes \
49+
= imports.import_real_app_election(
4850
experiment_id=self.experiment_id,
4951
election_id=self.election_id,
5052
is_shifted=self.is_shifted)
@@ -79,10 +81,21 @@ def prepare_instance(self, is_exported=None, is_aggregated=True):
7981
num_candidates=self.num_candidates,
8082
num_voters=self.num_voters,
8183
params=self.params)
84+
if not self.fake:
85+
c = Counter(map(tuple, self.votes))
86+
counted_votes = [[count, list(row)] for row, count in c.items()]
87+
counted_votes = sorted(counted_votes, reverse=True)
88+
self.quantites = [a[0] for a in counted_votes]
89+
self.distinct_votes = [a[1] for a in counted_votes]
90+
self.num_options = len(counted_votes)
91+
else:
92+
self.quantites = [self.num_voters]
93+
self.num_options = 1
94+
8295
if is_exported:
8396
exports.export_approval_election(self, is_aggregated=is_aggregated)
8497

85-
def compute_distances_between_votes(self, distance_id='hamming'):
98+
def _compute_distances_between_votes(self, distance_id='hamming'):
8699
distances = np.zeros([self.num_voters, self.num_voters])
87100
for v1 in range(self.num_voters):
88101
for v2 in range(self.num_voters):
@@ -103,7 +116,7 @@ def compute_distances_between_votes(self, distance_id='hamming'):
103116

104117
return distances
105118

106-
def compute_distances_between_candidates(self, distance_id='hamming'):
119+
def _compute_distances_between_candidates(self, distance_id='hamming'):
107120

108121
distances = np.zeros([self.num_candidates, self.num_candidates])
109122
for c1 in range(self.num_candidates):
@@ -125,14 +138,21 @@ def compute_distances_between_candidates(self, distance_id='hamming'):
125138
if self.is_exported:
126139
exports.export_distances(self, object_type='candidate')
127140

141+
return distances
142+
143+
def compute_distances(self, object_type=None, distance_id='hamming'):
144+
if object_type == 'vote':
145+
return self._compute_distances_between_votes(distance_id=distance_id)
146+
elif object_type == 'candidate':
147+
return self._compute_distances_between_candidates(distance_id=distance_id)
148+
128149
def print_map(
129150
self,
130151
show=True,
131152
radius=None,
132153
name=None,
133154
alpha=0.1,
134155
s=30,
135-
circles=False,
136156
object_type=None,
137157
double_gradient=False,
138158
saveas=None,

mapel-elections/src/mapel/elections/persistence/election_imports.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ def import_real_old_soc_election(experiment_id: str = None,
213213
first_line = my_file.readline()
214214

215215
if first_line[0] != '#':
216-
model_name = 'empty'
216+
culture_id = 'empty'
217217
num_candidates = int(first_line)
218218
else:
219219
first_line = first_line.strip().split()
220-
model_name = first_line[1]
220+
culture_id = first_line[1]
221221
if experiment_id == 'original_ordinal_map':
222222
params = {}
223-
model_name = _old_name_extractor(first_line)
223+
culture_id = _old_name_extractor(first_line)
224224
else:
225225
if len(first_line) <= 2:
226226
params = {}
@@ -266,7 +266,7 @@ def import_real_old_soc_election(experiment_id: str = None,
266266
num_voters, \
267267
num_candidates, \
268268
params, \
269-
model_name, \
269+
culture_id, \
270270
alliances, \
271271
num_options, \
272272
quantites, \
@@ -289,7 +289,7 @@ def import_fake_soc_election(experiment_id, name):
289289

290290
first_line = my_file.readline()
291291
first_line = first_line.strip().split()
292-
model_name = first_line[1]
292+
culture_id = first_line[1]
293293
if len(first_line) <= 2:
294294
params = {}
295295
else:
@@ -300,7 +300,7 @@ def import_fake_soc_election(experiment_id, name):
300300

301301
my_file.close()
302302

303-
return model_name, params, num_voters, num_candidates
303+
return culture_id, params, num_voters, num_candidates
304304

305305

306306
def import_real_new_app_election(experiment_id: str = None,
@@ -361,8 +361,6 @@ def import_real_new_app_election(experiment_id: str = None,
361361

362362
file.close()
363363

364-
alliances = None
365-
366364
c = Counter(map(tuple, votes))
367365
counted_votes = [[count, list(row)] for row, count in c.items()]
368366
counted_votes = sorted(counted_votes, reverse=True)
@@ -373,7 +371,16 @@ def import_real_new_app_election(experiment_id: str = None,
373371
if is_shifted:
374372
votes = [[vote - 1 for vote in voter] for voter in votes]
375373

376-
return votes, len(votes), num_candidates, params, culture_id
374+
num_voters = len(votes)
375+
376+
return votes, \
377+
num_voters, \
378+
num_candidates, \
379+
params, \
380+
culture_id, \
381+
num_options, \
382+
quantites, \
383+
distinct_votes
377384

378385

379386
def import_real_old_app_election(experiment_id: str, election_id: str, is_shifted=False):
@@ -425,7 +432,21 @@ def import_real_old_app_election(experiment_id: str, election_id: str, is_shifte
425432
votes = [{c - 1 for c in vote} for vote in votes]
426433
my_file.close()
427434

428-
return votes, num_voters, num_candidates, params, culture_id
435+
c = Counter(map(tuple, votes))
436+
counted_votes = [[count, list(row)] for row, count in c.items()]
437+
counted_votes = sorted(counted_votes, reverse=True)
438+
quantites = [a[0] for a in counted_votes]
439+
distinct_votes = [a[1] for a in counted_votes]
440+
num_options = len(counted_votes)
441+
442+
return votes, \
443+
num_voters, \
444+
num_candidates, \
445+
params, \
446+
culture_id, \
447+
num_options, \
448+
quantites, \
449+
distinct_votes
429450

430451

431452
def import_real_app_election(**kwargs):
@@ -443,7 +464,7 @@ def import_fake_app_election(experiment_id: str, name: str):
443464
my_file = open(path, 'r')
444465
first_line = my_file.readline()
445466
first_line = first_line.strip().split()
446-
fake_model_name = first_line[1]
467+
fake_culture_id = first_line[1]
447468
if len(first_line) <= 2:
448469
params = {}
449470
else:
@@ -452,7 +473,7 @@ def import_fake_app_election(experiment_id: str, name: str):
452473
num_candidates = int(my_file.readline().strip())
453474
num_voters = int(my_file.readline().strip())
454475

455-
return fake_model_name, params, num_voters, num_candidates
476+
return fake_culture_id, params, num_voters, num_candidates
456477

457478

458479
def check_if_fake(experiment_id, name, extention):
@@ -466,11 +487,11 @@ def check_if_fake(experiment_id, name, extention):
466487

467488
def _old_name_extractor(first_line):
468489
if len(first_line) == 4:
469-
model_name = f'{first_line[1]} {first_line[2]} {first_line[3]}'
490+
culture_id = f'{first_line[1]} {first_line[2]} {first_line[3]}'
470491
elif len(first_line) == 3:
471-
model_name = f'{first_line[1]} {first_line[2]}'
492+
culture_id = f'{first_line[1]} {first_line[2]}'
472493
elif len(first_line) == 2:
473-
model_name = first_line[1]
494+
culture_id = first_line[1]
474495
else:
475-
model_name = 'noname'
476-
return model_name
496+
culture_id = 'noname'
497+
return culture_id

mapel-marriages/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mapel-marriages"
7-
version = "2.1.3"
7+
version = "2.1.4"
88
authors = [
99
{name = "Stanislaw Szufa", email = "s.szufa@gmail.com"},
1010
{name = "Niclas Boehmer", email = "niclas.boehmer@tu-berlin.de"},

mapel-roommates/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mapel-roommates"
7-
version = "2.1.3"
7+
version = "2.1.4"
88
authors = [
99
{name = "Stanislaw Szufa", email = "s.szufa@gmail.com"},
1010
{name = "Niclas Boehmer", email = "niclas.boehmer@tu-berlin.de"},

0 commit comments

Comments
 (0)