-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_args.py
67 lines (52 loc) · 2.93 KB
/
parse_args.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import argparse
from typing import List
from utils.comp_range import Range
run_keys = ['T_onset', 'T_record']
save_keys = ['save_filename']
def pop_keys(dict: dict, keys: List[str]):
items = {k: dict.pop(k) for k in list(dict.keys()) if k in keys}
return items
def parse_args(print_args=False):
parser = argparse.ArgumentParser(description='MAS for trust in exchange')
parser.add_argument('-a', '--agent-class', dest='AgentClass', default='MSAgent',
choices=['MSAgent', 'WHAgent', 'RLAgent', 'GossipAgent', 'RLGossipAgent'])
parser.add_argument('-m', '--mobility-rate', default=0.2,
type=float, choices=[Range(0.0, 1.0)])
parser.add_argument('-N', '--number-of-agents', default=1000,
type=int, choices=[Range(0, 10000)])
parser.add_argument('-n', '--neighbourhood-size',
default=30, type=int, choices=[Range(0, 10000)])
parser.add_argument('-l', '--learning-rate', default=0.02,
type=float, choices=[Range(0.0, 1.0)], help='Only for RLAgent and RLGossipAgent')
parser.add_argument('-sl', '--social-learning-rate', default=0.5,
type=float, choices=[Range(0.0, 1.0)], help='Only for RLAgent and RLGossipAgent')
parser.add_argument('-df', '--discount-factor', default=1.0,
type=float, choices=[Range(0.0, 1.0)], help='Only for RLAgent and RLGossipAgent')
parser.add_argument('-r', '--relative-reward', default=True,
type=bool, choices=[True, False], help='Only for RLAgent and RLGossipAgent')
parser.add_argument('-ms', '--memory-size', default=25,
type=bool, choices=[Range(0, 10000)], help='Only for GossipAgent and RLGossipAgent')
parser.add_argument('-t1', '--T_onset', default='100',
type=int, choices=[Range(0, int(1e6))])
parser.add_argument('-t2', '--T_record', default='1000',
type=int, choices=[Range(1, int(1e6))])
parser.add_argument('--save-filename', default='data.csv',
help='Saves to /m_SAVE-FILENAME and /a_SAVE-FILENAME')
args = parser.parse_args()
if args.neighbourhood_size > args.number_of_agents:
raise ValueError(
f'neighbourhood-size={args.neighbourhood_size} is larger than number-of-agents={args.number_of_agents}')
if args.AgentClass not in ['RLAgent', 'RLGossipAgent']:
del args.learning_rate
del args.social_learning_rate
del args.discount_factor
del args.relative_reward
if args.AgentClass not in ['GossipAgent', 'RLGossipAgent']:
del args.memory_size
kwargs = vars(args)
run_args = pop_keys(kwargs, run_keys)
save_filename = pop_keys(kwargs, save_keys)[save_keys[0]]
if print_args:
print("Model params: " + str(kwargs))
print("Run params: " + str(run_args))
return kwargs, run_args, save_filename