Skip to content

Commit 7d7a2fc

Browse files
committed
updates
1 parent 535fead commit 7d7a2fc

18 files changed

+3534
-782
lines changed

.ipynb_checkpoints/PI-checkpoint.ipynb

Lines changed: 206 additions & 391 deletions
Large diffs are not rendered by default.

PI.ipynb

Lines changed: 194 additions & 391 deletions
Large diffs are not rendered by default.

PI.tex

Lines changed: 2097 additions & 0 deletions
Large diffs are not rendered by default.

Présentation du rendu.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Conserver la partie texte dans le Jupyter Notebook qui sera converti en LateX avec Overleaf.
2+
3+
Mettre les fichier Python dans un zip de fichiers Python.
4+
5+
Préparer une présentation.

Task02.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class student2:
2+
"""Definition of the class student"""
3+
4+
def __init__(self, prefStud):
5+
"""
6+
prefStud is a list that associates to each school its rank for the student.
7+
A case is added for including the choice of not joining any school at all.
8+
"""
9+
self.prefStud = prefStud
10+
self.schlStud = len(prefStud) - 1
11+
12+
class school2:
13+
"""Definition of the school class"""
14+
idx = 0
15+
n = 0
16+
def __init__(self, prefer, quota):
17+
"""
18+
prefer contains the students ordered according to the preference of the school.
19+
"""
20+
self.prefer = prefer
21+
self.quota = quota
22+
23+
24+
25+
26+
def mate2(schools, students):
27+
N = len(students)
28+
m = len(schools)
29+
i = -1
30+
# since the algorithm goes through the preferences of the schools in decreasing order of
31+
# preference, we have a stable matching when all quotas are met.
32+
while True:
33+
for j in range(m):
34+
if schools[j].n < schools[j].quota and schools[i].idx < N:
35+
i = j
36+
break
37+
else:
38+
break
39+
while schools[i].n < schools[i].quota and schools[i].idx < N:
40+
stud = schools[i].prefer[schools[i].idx]
41+
if stud.prefStud[i] < stud.prefStud[stud.schlStud]:
42+
if stud.schlStud < m:
43+
schools[stud.schlStud].n -= 1
44+
schools[i].n += 1
45+
stud.schlStud = i
46+
schools[i].idx += 1
47+
res = [list() for k in range(m + 1)]
48+
for k in range(N):
49+
res[students[k].schlStud].append(k)
50+
return res

Task03.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class student3:
2+
"""Definition of the class student"""
3+
4+
def __init__(self, prefStud, grp):
5+
"""
6+
prefStud is a list that associates to each school its rank for the student.
7+
A case is added for including the choice of not joining any school at all.
8+
"""
9+
self.prefStud = prefStud
10+
self.schlStud = len(prefStud) - 1
11+
self.grp = grp
12+
13+
class school3:
14+
"""Definition of the school class"""
15+
idx = 0
16+
n = 0
17+
def __init__(self, prefer, quota, quota_grp):
18+
"""
19+
prefer contains the students ordered according to the preference of the school.
20+
"""
21+
self.prefer = prefer
22+
self.quota = quota
23+
self.quota_grp = quota_grp
24+
self.n_grp = [0] * len(quota_grp)
25+
26+
27+
28+
29+
def mate3(schools, students):
30+
N = len(students)
31+
m = len(schools)
32+
i = -1
33+
# since the algorithm goes through the preferences of the schools in decreasing order of
34+
# preference, we have a stable matching when all quotas are met.
35+
while True: # stop condition unmodified
36+
for j in range(m):
37+
if schools[j].n < schools[j].quota and schools[i].idx < N:
38+
i = j
39+
break
40+
else:
41+
break
42+
while schools[i].n < schools[i].quota and schools[i].idx < N:
43+
stud = schools[i].prefer[schools[i].idx]
44+
if schools[i].n_grp[stud.grp] < schools[i].quota_grp[stud.grp]:
45+
if stud.prefStud[i] < stud.prefStud[stud.schlStud]:
46+
if stud.schlStud < m:
47+
schools[stud.schlStud].n -= 1
48+
schools[i].n_grp[stud.grp] -= 1
49+
schools[i].n += 1
50+
stud.schlStud = i
51+
schools[i].idx += 1
52+
res = [list() for k in range(m + 1)]
53+
for k in range(N):
54+
res[students[k].schlStud].append(k)
55+
return res

0 commit comments

Comments
 (0)