@@ -598,27 +598,32 @@ function limit_change(
598598 return limited_value
599599end
600600
601- """
602- $(TYPEDSIGNATURES)
603- """
604- function async_qn_step! (qn:: QN )
605- entity_labels = entities (qn)
606- entity = rand (entity_labels)
601+ function _compute_next_state! (qn:: QN , entity)
607602 (min_level, max_level) = extrema (get_domain (qn, entity))
608603 t = target_functions (qn)[entity]
609604 old_state = get_state (qn, entity)
610605 new_state = interpret (t, qn)
611606 new_state = isnan (new_state) ? min_level : new_state
612607 new_state = isinf (new_state) ? max_level : new_state
613608 limited_state = limit_change (old_state, floor (Int, new_state), min_level, max_level)
614- set_state! (qn, entity, limited_state)
609+ end
610+
611+ """
612+ $(TYPEDSIGNATURES)
613+ """
614+ function async_qn_step! (qn:: QN )
615+ entity_labels = entities (qn)
616+ entity = rand (entity_labels)
617+ next_state = _compute_next_state! (qn, entity)
618+ set_state! (qn, entity, next_state)
615619end
616620
617621"""
618622 $(TYPEDSIGNATURES)
619623"""
620624function sync_qn_step! (qn:: QN )
621- throw (ErrorException (" Synchronous step function not yet implemented" ))
625+ next_states = _compute_next_state! .((qn,), entities (qn))
626+ set_state! .((qn,), entities (qn), next_states)
622627end
623628
624629extract_state (model:: QN ) = model. state
@@ -706,7 +711,7 @@ function bma_dict_to_qn(bma_model::JSONModel)
706711 ) for e in bma_entities
707712 ]
708713
709- return QualitativeNetwork (entities_with_functions; schedule = Asynchronous )
714+ return QualitativeNetwork (entities_with_functions; schedule = Synchronous )
710715end
711716
712717"""
@@ -753,6 +758,47 @@ function swap_entity_names_to_var_ids(ex)
753758 end
754759end
755760
761+ """
762+ stringify_fn(ex, lower_bound, upper_bound)
763+
764+ Take an `ex` and if it's of the form of a default function, return "".
765+ """
766+ function stringify_fn (ex, lower_bound, upper_bound)
767+ if is_default_function (ex, lower_bound, upper_bound)
768+ return " "
769+ else
770+ string (ex)
771+ end
772+ end
773+
774+ function is_default_function (ex, lower_bound, upper_bound)
775+ @match ex begin
776+ # single activator
777+ :(var ($ id)) => true
778+
779+ # multiple activators
780+ Expr (:call , :/ , Expr (:call , :+ , vars... ), denom) && (
781+ if length (vars) == denom
782+ end
783+ ) => true
784+
785+ # only inhibitor(s)
786+ :($ bound - $ inh) && (
787+ if bound == upper_bound
788+ end
789+ ) => is_default_function (inh, lower_bound, upper_bound)
790+
791+ # both inhibitor(s) and activator(s)
792+ :(max ($ bound, $ act - $ inh)) && (
793+ if bound == lower_bound
794+ end
795+ ) =>
796+ is_default_function (@show (act), lower_bound, upper_bound) &&
797+ is_default_function (@show (inh), lower_bound, upper_bound)
798+ _ => false
799+ end
800+ end
801+
756802"""
757803 $(SIGNATURES)
758804
@@ -767,13 +813,14 @@ function qn_to_bma_dict(qn::QN{N,S,M}) where {N,S,C,G,L<:EntityIdName,M<:MetaGra
767813 functions = [target_functions (qn)[e] for e in entities (qn)]
768814 activator_inhibitor_pairs = classify_activators_inhibitors (target_functions (qn))
769815 functions = swap_entity_names_to_var_ids .(functions)
816+ functions = stringify_fn .(functions, first .(lower_upper), last .(lower_upper))
770817
771818 variables = [
772819 Dict (
773820 " RangeFrom" => d[1 ],
774821 " RangeTo" => d[2 ],
775822 " Id" => i,
776- " Formula" => string (f) ,
823+ " Formula" => f ,
777824 " Name" => n,
778825 ) for (d, i, n, f) in zip (lower_upper, ids, entity_names, functions)
779826 ]
0 commit comments