text
stringlengths
0
601k
let regular_loop_body ~ debugMode ~ outputs ~ maxConsecutiveClash env counter graph state dt = let ( ) = let outputs counter ' time = let cand = observables_values env graph ( Counter . fake_time counter ' time ) in if Array . length cand > 1 then outputs ( Data . Plot cand ) in Counter . fill ~ outputs counter ~ dt in...
let a_loop ~ debugMode ~ outputs ~ dumpIfDeadlocked ~ maxConsecutiveClash env counter graph state = let activity = Rule_interpreter . activity graph in let rd = Random . State . float ( Rule_interpreter . get_random_state graph ) 1 . 0 in let dt = abs_float ( log rd . / activity ) in let out = if not ( activity > 0 . )...
let end_of_simulation ~ outputs env counter graph state = let _ = state . init_stopping_times in let ( ) = let outputs counter ' time = let cand = observables_values env graph ( Counter . fake_time counter ' time ) in if Array . length cand > 1 then outputs ( Data . Plot cand ) in Counter . fill ~ outputs counter ~ dt ...
module Make3 ( State : State_or_error_intf . State_intf2 ) State_intf2 : State_or_error_intf . S3 with type ( ' a , ' b ) ' b state = ( ' a , ' b ) ' b State . t = struct module T = struct type ( ' a , ' b ) ' b state = ( ' a , ' b ) ' b State . t type ( ' c , ' a , ' b ) ' b t = ( ' a , ' b ) ' b state -> ( ' c * ( ' ...
module S3_to_S2 ( X : State_or_error_intf . S3 ) S3 : State_or_error_intf . S2 with type ( ' a , ' b ) ' b t := ( ' a , ' b , unit ) unit X . t and type ' a state := ( ' a , unit ) unit X . state = struct include ( X : State_or_error_intf . S3 with type ( ' a , ' b , ' e ) ' e t := ( ' a , ' b , ' e ) ' e X . t and typ...
module S2_to_S ( X : State_or_error_intf . S2 ) S2 : State_or_error_intf . S with type ' a t := ( ' a , unit ) unit X . t and type state := unit X . state = struct include ( X : State_or_error_intf . S2 with type ( ' a , ' b ) ' b t := ( ' a , ' b ) ' b X . t and type ' a state := ' a X . state ) end
module Make2 ( State : State_or_error_intf . State_intf1 ) State_intf1 : State_or_error_intf . S2 = struct module M = Make3 ( struct type ( ' a , ' b ) ' b t = ' a State . t end ) end type ( ' a , ' b ) ' b t = ( ' a , ' b , unit ) unit M . t type ' a state = ( ' a , unit ) unit M . state include S3_to_S2 ( M ) M end
module Make ( State : State_or_error_intf . State_intf ) State_intf : State_or_error_intf . S = struct module M = Make2 ( struct type ' a t = State . t end ) end type ' a t = ( ' a , unit ) unit M . t type state = unit M . state include S2_to_S ( M ) M end
module type State_intf = sig type t end
module type State_intf1 = sig type ' a t end
module type State_intf2 = sig type ( ' a , ' b ) ' b t end
module type S = sig include Monad . S type state val run_state : ' a t -> state : state -> ( ' a * state ) state Or_error . t val get : state t val put : state -> unit t val error_if : bool -> message : string -> value : ' a -> ' a t end
module type S2 = sig include Monad . S2 type ' a state val run_state : ( ' b , ' a ) ' a t -> state : ' a state -> ( ' b * ' a state ) state Or_error . t val get : ( ' a state , ' a ) ' a t val put : ' a state -> ( unit , ' a ) ' a t val error_if : bool -> message : string -> value : ' a -> ( ' a , _ ) _ t end
module type S3 = sig include Monad . S3 type ( ' a , ' b ) ' b state val run_state : ( ' c , ' a , ' b ) ' b t -> state ( : ' a , ' b ) ' b state -> ( ' c * ( ' a , ' b ) ' b state ) state Or_error . t val get : ( ( ' a , ' b ) ' b state , ' a , ' b ) ' b t val put : ( ' a , ' b ) ' b state -> ( unit , ' a , ' b ) ' b ...
let plotPeriodParamId = Js . string " kappappPlotPeriod "
let pauseConditionParamId = Js . string " kappappPauseCondition "
let seedParamId = Js . string " kappappDefaultSeed "
let storeTraceParamId = Js . string " kappappStoreTrace "
let showDeadRulesParamId = Js . string " kappappShowDeadRules "
let showDeadAgentsParamId = Js . string " kappappShowDeadAgents "
let showIrreversibleTransitionsParamId = Js . string " kappappShowIrreversibleTransition "
type parameters = { plot_period : float ; pause_condition : string ; seed : int option ; store_trace : bool ; show_dead_rules : bool ; show_dead_agents : bool ; show_non_weakly_reversible_transitions : bool ; }
type a_project = { project_id : string ; project_is_computing : bool React . S . t ; project_watcher_cancel : bool ref ; project_manager : Api . concrete_manager ; }
type state = { project_current : a_project option ; project_catalog : a_project list ; project_version : int ; default_parameters : parameters ; project_parameters : parameters Mods . StringMap . t ; }
type project_model = { model_project_id : string ; model_project_is_computing : bool React . S . t ; }
type model = { model_current_id : string option ; model_catalog : project_model list ; model_project_version : int ; model_parameters : parameters ; }
let project_equal a b = a . project_id = b . project_id
let catalog_equal x y = try List . for_all2 project_equal x y with Invalid_argument _ -> false
let state_equal a b = Option_util . equal project_equal a . project_current b . project_current && a . project_version = b . project_version && a . default_parameters = b . default_parameters && Mods . StringMap . equal ( fun x y -> compare x y = 0 ) a . project_parameters b . project_parameters && catalog_equal a . pr...
let model_equal a b = Option_util . equal ( fun x y -> String . compare x y = 0 ) a . model_current_id b . model_current_id && ( try List . for_all2 ( fun x y -> x . model_project_id = y . model_project_id ) a . model_catalog b . model_catalog with Invalid_argument _ -> false ) && a . model_project_version = b . model_...
let init_default_parameters = { plot_period = 1 . ; pause_condition = " [ false ] " ; seed = None ; store_trace = false ; show_dead_rules = true ; show_dead_agents = true ; show_non_weakly_reversible_transitions = false ; }
let init_state = { project_current = None ; project_catalog = [ ] ; project_version = - 1 ; default_parameters = init_default_parameters ; project_parameters = Mods . StringMap . empty ; }
let state , set_state = React . S . create ~ eq : state_equal init_state
let update_parameters handler = let st = React . S . value state in let default_parameters , project_parameters = match st . project_current with | None -> handler st . default_parameters , st . project_parameters | Some proj -> st . default_parameters , Mods . StringMap . add proj . project_id ( handler ( Mods . Strin...
let set_parameters_as_default ( ) = let st = React . S . value state in let pa = match st . project_current with | None -> st . default_parameters | Some proj -> Mods . StringMap . find_default st . default_parameters proj . project_id st . project_parameters in let ( ) = Js . Optdef . iter Dom_html . window . ## local...
let set_plot_period plot_period = update_parameters ( fun param -> { param with plot_period } )
let set_pause_condition pause_condition = update_parameters ( fun param -> { param with pause_condition } )
let set_seed seed = update_parameters ( fun param -> { param with seed } )
let set_store_trace store_trace = update_parameters ( fun param -> { param with store_trace } )
let set_show_dead_rules show_dead_rules = update_parameters ( fun param -> { param with show_dead_rules } )
let set_show_dead_agents show_dead_agents = update_parameters ( fun param -> { param with show_dead_agents } )
let set_show_non_weakly_reversible_transitions show_non_weakly_reversible_transitions = update_parameters ( fun param -> { param with show_non_weakly_reversible_transitions } )
let update_state me project_catalog default_parameters project_parameters = me . project_manager # project_parse ~ patternSharing : Pattern . Compatible_patterns [ ] >>= fun out -> let ( ) = set_state { project_current = Some me ; project_catalog ; default_parameters ; project_parameters ; project_version = 1 ; } in Lw...
let computing_watcher manager setter = let delay = 1 . in let cancelled = ref false in let rec loop ( ) = let ( ) = setter manager # is_computing in if ! cancelled then Lwt . return_unit else Js_of_ocaml_lwt . Lwt_js . sleep delay >>= loop in let ( ) = Lwt . async loop in cancelled
let add_project is_new project_id : unit Api . result Lwt . t = let state_va = React . S . value state in let catalog = state_va . project_catalog in ( try Lwt . return ( Result_util . ok ( List . find ( fun x -> x . project_id = project_id ) catalog , catalog , state_va . project_parameters ) ) with Not_found -> State...
let create_project project_id = add_project true project_id
let set_project project_id = add_project false project_id
let dummy_model = { model_current_id = None ; model_catalog = [ ] ; model_project_version = - 1 ; model_parameters = init_default_parameters ; }
let model : model React . signal = React . S . map ~ eq : model_equal ( fun state -> let model_catalog = List . map ( fun p -> { model_project_id = p . project_id ; model_project_is_computing = p . project_is_computing ; } ) state . project_catalog in let model_parameters = match state . project_current with | None -> ...
let sync ( ) : unit Api . result Lwt . t = match ( React . S . value state ) . project_current with | None -> Lwt . return ( Result_util . ok ( ) ) | Some current -> current . project_manager # project_parse ~ patternSharing : Pattern . Compatible_patterns [ ] >>= fun out -> let st = React . S . value state in let ( ) ...
let remove_files manager = manager # file_catalog >>= ( Api_common . result_bind_lwt ~ ok ( : fun catalog -> Lwt_list . iter_p ( fun m -> manager # file_delete m . Kfiles . id >>= ( fun _ -> Lwt . return_unit ) ) catalog >>= ( fun ( ) -> Lwt . return ( Result_util . ok ( ) ) ) ) )
let remove_project project_id = let state = React . S . value state in try let current = List . find ( fun x -> x . project_id = project_id ) state . project_catalog in remove_files current . project_manager >>= ( fun out ' -> let ( ) = current . project_watcher_cancel := true in let project_catalog = List . filter ( f...
let rec init_plot_period ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: t -> try set_plot_period ( float_of_string h ) with Failure _ -> let msg = Format . sprintf " failed to parse init_plot_period ' % s ' " h in let ( ) = Common . debug ( Js . string msg ) in init_plot_period t
let init_pause_condition ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: _ -> set_pause_condition h
let rec init_model_seed ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: t -> try set_plot_period ( float_of_string h ) with Failure _ -> let msg = Format . sprintf " failed to parse model_seed ' % s ' " h in let ( ) = Common . debug ( Js . string msg ) in init_model_seed t
let init_store_trace ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: _ -> set_store_trace ( h <> " false " )
let init_show_dead_rules ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: _ -> set_show_dead_rules ( h <> " false " )
let init_show_dead_agents ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: _ -> set_show_dead_agents ( h <> " false " )
let init_show_non_weakly_reversible_transitions ( arg : string list ) : unit = match arg with | [ ] -> ( ) | h :: _ -> set_show_non_weakly_reversible_transitions ( h <> " false " )
let init existing_projects : unit Lwt . t = let arg_plot_period = let default = Js . Optdef . case Dom_html . window . ## localStorage ( fun ( ) -> [ ] ) ( fun st -> Js . Opt . case ( st ## getItem plotPeriodParamId ) ( fun ( ) -> [ ] ) ( fun x -> [ Js . to_string x ] ) ) in Common_state . url_args ~ default " plot_per...
let with_project : ' a . label : string -> ( Api . concrete_manager -> ' a Api . result Lwt . t ) -> ' a Api . result Lwt . t = fun ~ label handler -> match ( React . S . value state ) . project_current with | None -> let error_msg : string = Format . sprintf " Failed % s due to unavailable project . " label in Lwt . r...
let on_project_change_async ? eq ~ on ( ? others_eq = ( ) ) = init_others others default handler = let eq_pair = Mods . pair_equal state_equal others_eq in React . S . hold ? eq default ( Lwt_react . E . map_p ( fun ( st , oth ) -> match st . project_current with | None -> Lwt . return default | Some current -> handler...
type cli = { url : string ; command : string ; args : string list }
type protocol = HTTP of string | CLI of cli
type remote = { label : string ; protocol : protocol ; }
type spec = WebWorker | Embedded | Remote of remote
type state = { state_current : spec ; state_runtimes : spec list ; }
type model = { model_current : spec ; model_runtimes : spec list ; }
let spec_label : spec -> string = function | WebWorker -> " WebWorker " | Embedded -> " Embedded " | Remote remote -> remote . label
let spec_id : spec -> string = function | WebWorker -> " WebWorker " | Embedded -> " Embedded " | Remote { label = _ ; protocol = HTTP http } -> http | Remote { label = _ ; protocol = CLI cli } -> cli . url
let read_spec : string -> spec option = function | " WebWorker " -> Some WebWorker | " Embedded " -> Some Embedded | url -> let ( ) = Common . debug ( Js . string ( Format . sprintf " parse_remote : % s " url ) ) in let format_url url = let length = String . length url in if length > 0 && String . get url ( length - 1 ...
let state , set_state = React . S . create { state_current = WebWorker ; state_runtimes = [ WebWorker ; Embedded ; ] ; }
let create_manager ~ is_new project_id = match ( React . S . value state ) . state_current with | WebWorker -> let ( ) = State_settings . set_synch false in Lwt . return ( Result_util . ok ( new Web_worker_api . manager ( ) : Api . concrete_manager ) ) | Embedded -> let ( ) = State_settings . set_synch false in Lwt . r...
let set_spec runtime = let current_state = React . S . value state in set_state { state_current = runtime ; state_runtimes = current_state . state_runtimes }
let create_spec ~ load ( id : string ) : unit Api . result = match read_spec id with | None -> let error_msg : string = Format . sprintf " Failed to create spec : could not parse identifier % s " id in Api_common . result_error_msg error_msg | Some runtime -> let current_state = React . S . value state in let ( ) = if ...
let model : model React . signal = React . S . map ( fun state -> { model_current = state . state_current ; model_runtimes = state . state_runtimes ; } ) state
let init ( ) = let hosts = Common_state . url_args " host " in let rec add_urls urls load = match urls with | [ ] -> ( ) | url :: urls -> match create_spec ~ load url with | { Result_util . value = Result . Ok ( ) ; _ } -> add_urls urls false | { Result_util . value = Result . Error _ ; _ } -> add_urls urls load in let...
let sync ( ) = Lwt . return_unit
let clientIdParamId = Js . string " kappappClientId "
let _client_id : string ref = ref " "
let get_client_id ( ) : string = ! _client_id
let set_client_id ( client_id : string ) : unit = _client_id := client_id
let fontSizeParamId = Js . string " kappappFontSize "
let currentFontSize = ref 1 . 4
let initFromStorage ( ) = Js . Optdef . case Dom_html . window . ## localStorage ( fun ( ) -> let ( ) = currentFontSize := 1 . 4 in _client_id := ( Common . guid ( ) ) ) ( fun st -> let ( ) = currentFontSize := Js . Opt . case ( st ## getItem fontSizeParamId ) ( fun ( ) -> 1 . 4 ) Js . parseFloat in _client_id := ( Js ...
let set_parameters_as_default ( ) = let v ' = string_of_float ! currentFontSize in let ( ) = Js . Optdef . iter Dom_html . window . ## localStorage ( fun st -> st ## setItem fontSizeParamId ( Js . string v ' ) ) in Js . Optdef . iter Dom_html . window . ## localStorage ( fun st -> st ## setItem clientIdParamId ( Js . s...
let updateFontSize ~ delta = let ( ) = currentFontSize := max 0 . 2 ( min ( ! currentFontSize . + delta ) 3 . ) in let v ' = string_of_float ! currentFontSize in let ( ) = Dom_html . document . ## body . ## style . ## fontSize := Js . string ( v ' " ^ em " ) in ( )
let synch , set_synch = React . S . create false
let agent_coloring = Js . Unsafe . obj [ ] ||
let init ( ) : unit Lwt . t = let ( ) = initFromStorage ( ) in let client_ids = Common_state . url_args " client_id " in let synch = Common_state . url_args " synch " in let ( ) = match client_ids with | client_id :: _ -> set_client_id client_id | [ ] -> ( ) in let ( ) = set_synch ( [ " true " ] = synch ) in Lwt . retu...
let sync ( ) : unit Lwt . t = Lwt . return_unit
type simulation_state = | SIMULATION_STATE_STOPPED | SIMULATION_STATE_INITALIZING | SIMULATION_STATE_READY of Api_types_j . simulation_info
type t = { simulation_state : simulation_state ; }
let t_simulation_state simulation = simulation . simulation_state
let t_simulation_info simulation : Api_types_j . simulation_info option = match simulation . simulation_state with | SIMULATION_STATE_STOPPED -> None | SIMULATION_STATE_INITALIZING -> None | SIMULATION_STATE_READY simulation_info -> Some simulation_info
type model_state = STOPPED | INITALIZING | RUNNING | PAUSED
let model_state_to_string = function STOPPED -> " Stopped " | INITALIZING -> " Initalizing " | RUNNING -> " Running " | PAUSED -> " Paused "
let dummy_model = { simulation_state = SIMULATION_STATE_STOPPED }
let model_simulation_info model : Api_types_j . simulation_info option = t_simulation_info model
let model_simulation_state model : model_state = match t_simulation_state model with | SIMULATION_STATE_STOPPED -> STOPPED | SIMULATION_STATE_INITALIZING -> INITALIZING | SIMULATION_STATE_READY simulation_info -> if simulation_info . Api_types_j . simulation_info_progress . Api_types_j . simulation_progress_is_running ...