@@ -9,23 +9,26 @@ let usage_msg =
99 /dev/ttyUSB0 -s 3.0 \n\n \
1010 \ Options:"
1111
12+ let parse_ip raw_addr =
13+ try
14+ match String. split_on_char ':' raw_addr with
15+ | [ ip; port ] ->
16+ Unix. ADDR_INET (Unix. inet_addr_of_string ip, int_of_string port)
17+ | _ -> raise @@ Failure " Network addresses must have exactly one ':'."
18+ with Failure msg ->
19+ failwith
20+ @@ Printf. sprintf
21+ " Failed parsing address: '%s'.\n \
22+ \ Error: %s\n \
23+ \ Accepted format is e.g. '172.0.1.1:8081'" raw_addr msg
24+
1225let parse_addr raw_addr =
1326 if String. contains raw_addr ':' then
14- try
15- match String. split_on_char ':' raw_addr with
16- | [ ip; port ] ->
17- Unix. ADDR_INET (Unix. inet_addr_of_string ip, int_of_string port)
18- | _ -> raise @@ Failure " Network addresses must have exactly one ':'."
19- with Failure msg ->
20- failwith
21- @@ Printf. sprintf
22- " Failed parsing response signal address: '%s'. Accepted formats are \
23- e.g. '/dev/ttyUSB0' or '172.0.1.1:8081'. %s"
24- raw_addr msg
27+ try parse_ip raw_addr
28+ with Failure msg -> failwith @@ msg ^ " or '/dev/USB0'"
2529 else Unix. ADDR_UNIX raw_addr
2630
2731let _log_path = ref " "
28- let _n_exploration_steps = ref 300
2932let _obs_time_delay = ref 5.0
3033let _acceptable_fraction = ref 0.8
3134let _request_interval = ref 1.
@@ -34,6 +37,9 @@ let _red_ip = ref "172.0.0.3"
3437let _response_signal_addr = ref " /dev/ttyUSB0"
3538let _parsed_response_signal_addr = ref (parse_addr ! _response_signal_addr)
3639let _rolling_window_secs = ref 3.0
40+ let _n_exploration_steps = ref 300
41+ let _server_policy_addr = ref " "
42+ let _parsed_server_policy_addr = ref None
3743
3844let speclist =
3945 [
@@ -42,10 +48,6 @@ let speclist =
4248 " : Optionally write a log file in the specified directory with \
4349 information about the sequence of states observed and actions taken. If \
4450 no log file is specified, the information is written to stdout.\n " );
45- ( " -e" ,
46- Arg. Set_int _n_exploration_steps,
47- " : Set the number of observations used by the policy for exploration, \
48- after which actions are selected for exploitation. Defaults to 300.\n " );
4951 ( " -t" ,
5052 Arg. Set_float _obs_time_delay,
5153 " : Set the constant time delay between observations in seconds. Defaults \
@@ -82,22 +84,36 @@ let speclist =
8284 " : Set the length of the rolling window used to evaluate the average OK \
8385 response rate indicated by the data received over the out-of-band \
8486 channel with the client. Defaults to 3.0.\n " );
87+ ( " -e" ,
88+ Arg. Set_int _n_exploration_steps,
89+ " : Set the number of observations used by the policy for exploration, \
90+ after which actions are selected for exploitation. Defaults to 300.\n " );
91+ ( " --server-policy" ,
92+ Arg. Set_string _server_policy_addr,
93+ " : Set the IP address of a policy server, overriding the \
94+ CountBasedPolicy. Serialised observations and rewards are sent as POST \
95+ requests to the configured address and actions are parsed from the \
96+ responses. The '-e' flag, used to configure the CountBasedPolicy, is \
97+ ignored when '--server-policy' is used.\n " );
8598 ]
8699
87100let log_path () =
88101 if String. length ! _log_path == 0 then None else Some ! _log_path
89102
90- let n_exploration_steps () = ! _n_exploration_steps
91103let obs_time_delay () = ! _obs_time_delay
92104let acceptable_fraction () = ! _acceptable_fraction
93105let request_interval () = ! _request_interval
94106let green_ip () = ! _green_ip
95107let red_ip () = ! _red_ip
96108let response_signal_addr () = ! _parsed_response_signal_addr
97109let rolling_window_secs () = ! _rolling_window_secs
110+ let n_exploration_steps () = ! _n_exploration_steps
111+ let server_policy () = ! _parsed_server_policy_addr
98112
99113let arg_parse () =
100114 let parse_positional_args _ = () in
101115 Arg. parse speclist parse_positional_args usage_msg;
102116 let raw_addr = ! _response_signal_addr in
103- _parsed_response_signal_addr := parse_addr raw_addr
117+ _parsed_response_signal_addr := parse_addr raw_addr;
118+ if String. length ! _server_policy_addr > 0 then
119+ _parsed_server_policy_addr := Some (parse_ip ! _server_policy_addr)
0 commit comments