Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GAP
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Darshan Prabhu
GAP
Commits
544eea6a
Commit
544eea6a
authored
Nov 07, 2020
by
Rajiv Vaidyanathan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SPA algorithm implementation
parent
304031f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
GAP/mapper.py
GAP/mapper.py
+70
-0
No files found.
GAP/mapper.py
0 → 100644
View file @
544eea6a
from
functools
import
reduce
# Part 1 (get these from the webapp)
# get student list
# get student project priorities and let them apply to their top priority
S
=
{
"s1"
:[
"p1"
,
"p3"
,
"p2"
,
"p4"
],
"s2"
:[
"p1"
,
"p3"
,
"p2"
,
"p4"
]}
# S = {"s1":["p1", "p2", "p3", "p4"], "s2":["p1", "p4", "p3", "p2"], "s3":["p3", "p1", "p2", "p4"], "s4":["p3", "p2", "p1", "p4"]}
# get project list from profs, per project capactiy and total capacity
L
=
{
"l1"
:[
"p1"
,
"p2"
],
"l2"
:[
"p3"
,
"p4"
]}
# L = {"l1":["p1", "p2"], "l2":["p3", "p4"]}
P2L
=
{
"p1"
:
"l1"
,
"p2"
:
"l1"
,
"p3"
:
"l2"
,
"p4"
:
"l2"
}
# get priorities from profs about students
Lpref
=
{
"l1"
:
[
"s1"
,
"s2"
],
"l2"
:
[
"s2"
,
"s1"
]}
# Lpref = {"l1": ["s3", "s4", "s1", "s2"], "l2": ["s1", "s2", "s3", "s4"]}
# get max intake
Pc
=
{
"p1"
:
1
,
"p2"
:
1
,
"p3"
:
1
,
"p4"
:
1
}
# Pc = {"p1":2, "p2":1, "p3":2, "p4":1}
# matching structure
Ms
=
{
"s1"
:
[],
"s2"
:
[]}
# Ms = {"s1": [], "s2": [], "s3": [], "s4": []}
Mp
=
{
"p1"
:
[],
"p2"
:
[],
"p3"
:
[],
"p4"
:
[]}
# print("MS values: ", Ms.values())
# isStable = reduce(lambda x, y: (x and (len(y)>0), Ms.values(), True)
isStable
=
True
for
i
in
Ms
.
values
():
if
len
(
i
)
==
0
:
isStable
=
False
break
# print(isStable)
# Part 2 (compute and return to the webapp)
# Run algo
while
not
isStable
:
for
stud
in
Ms
.
keys
():
if
len
(
Ms
[
stud
])
==
0
:
# provisionally asigning
# print("Current student: ", stud)
proj
=
S
[
stud
][
0
]
lec
=
P2L
[
proj
]
Ms
[
stud
]
.
append
(
proj
)
Mp
[
proj
]
.
append
(
stud
)
# check if project is oversubscibed
while
len
(
Mp
[
proj
])
>
Pc
[
proj
]:
# find the least priority students assigned to the project
prefList
=
Lpref
[
lec
]
# pref order of lec
idx
=
len
(
prefList
)
-
1
found
=
False
while
not
found
:
if
prefList
[
idx
]
in
Mp
[
proj
]:
Mp
[
proj
]
.
remove
(
prefList
[
idx
])
Ms
[
prefList
[
idx
]]
.
remove
(
proj
)
S
[
prefList
[
idx
]]
.
remove
(
proj
)
prefList
.
remove
(
prefList
[
idx
])
# print("Removing project: ", proj)
# print("from student: ", prefList[idx])
found
=
True
else
:
idx
-=
1
# isStable = reduce(lambda x, y: (x and (len(y)>0), Ms.values(), True)
isStable
=
True
for
i
in
Ms
.
values
():
if
len
(
i
)
==
0
:
isStable
=
False
break
print
(
Ms
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment