-
Notifications
You must be signed in to change notification settings - Fork 1
/
mechanism_names.py
40 lines (32 loc) · 1.49 KB
/
mechanism_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from approximate_confluent_flow import OnePlusLogTwoApproximation, OnePlusLnApproximation
from fractional_integral_flow import ConfluentFlow, SplittableFlow
from simple_mechanisms import GreedyNewestDelegate, GreedyRandomDelegation, GreedyPowerOfChoice, NoChoice, \
GeneralizedPowerOfChoice
MECHANISMS_LIST = [NoChoice, GreedyNewestDelegate, GreedyPowerOfChoice, GreedyRandomDelegation, ConfluentFlow,
SplittableFlow, OnePlusLogTwoApproximation, OnePlusLnApproximation, GeneralizedPowerOfChoice]
MECHANISMS = {m.PLOT_ABBREVIATION: m for m in MECHANISMS_LIST}
def describe_mechanisms(including_single):
descriptions = []
for m in MECHANISMS_LIST:
if m is NoChoice and not including_single:
continue
descriptions.append(f"{m.PLOT_ABBREVIATION}: {m.PLOT_LABEL};")
return "\n".join(descriptions)
def parse_mechanisms(argument, allow_single):
single_mechanisms = []
mechanisms = []
for x in argument:
if MECHANISMS[x] is NoChoice:
if not allow_single:
exit(f"Single delegation is not allowed in this script. Call with '-h' for usage.")
else:
single_mechanisms.append(MECHANISMS[x])
continue
if x not in MECHANISMS:
exit(f"Invalid mechanism designation '{x}'. Call with '-h' for usage.")
else:
mechanisms.append(MECHANISMS[x])
if allow_single:
return single_mechanisms, mechanisms
else:
return mechanisms