void simulate_state_init(SimulateState_ptr const self, DDMgr_ptr const dd_mgr, bdd_ptr const bdd, TraceLabel const trace_label) { /* base class initialization */ object_init(OBJECT(self)); /* members initialization */ self->dd_mgr = dd_mgr; self->bdd = bdd_dup(bdd); self->trace_label = trace_label; /* virtual methods settings */ OVERRIDE(Object, finalize) = simulate_state_finalize; }
void SimulateState_set_all(SimulateState_ptr const self, bdd_ptr const state, TraceLabel const label) { SIMULATE_STATE_CHECK_INSTANCE(self); check_integrity(self); if ((bdd_ptr)NULL != self->bdd) { bdd_free(self->dd_mgr, self->bdd); self->bdd = (bdd_ptr)NULL; } self->bdd = bdd_dup(state); self->trace_label = label; check_integrity(self); }
bdd_ptr SimulateState_get_bdd(SimulateState_ptr const self) { bdd_ptr result; SIMULATE_STATE_CHECK_INSTANCE(self); check_integrity(self); if ((bdd_ptr)NULL != self->bdd && TRACE_LABEL_INVALID != self->trace_label) { result = bdd_dup(self->bdd); } else result = (bdd_ptr)NULL; check_integrity(self); return result; }
static void current_state_bdd_set(bdd_ptr state) { if (current_state_exist()) { current_state_bdd_free(); } current_state_bdd = bdd_dup(state); }
bdd_ptr current_state_bdd_get() { return (current_state_exist() == true) ? bdd_dup(current_state_bdd) : (bdd_ptr) NULL; }
/**Function******************************************************************** Synopsis [Executes a trace on the fsm given at construction time using BDDs] Description [The trace is executed using BDDs, that is a proof that the fsm is compatible with the trace is built (if such proof exists). Incomplete traces are filled-in with compatible values for state and input variables. Given trace can be either complete or incomplete. The number of performed steps (transitions) is returned in *n_steps, if a non-NULL pointer is given. If the initial state is not compatible -1 is written.] SideEffects [None] SeeAlso [] ******************************************************************************/ static Trace_ptr bdd_partial_trace_executor_execute (const PartialTraceExecutor_ptr partial_executor, const Trace_ptr trace, const NodeList_ptr language, int* n_steps) { /* local references to self */ const BDDPartialTraceExecutor_ptr self = \ BDD_PARTIAL_TRACE_EXECUTOR(partial_executor); const BaseTraceExecutor_ptr executor = \ BASE_TRACE_EXECUTOR(partial_executor); Trace_ptr res = TRACE(NULL); /* failure */ int count = -1; boolean success = true; DdManager* dd; BddStates trace_states; TraceIter step = TRACE_END_ITER; BddStates fwd_image = (BddStates) NULL; node_ptr path = Nil; /* forward constrained images will be used later to compute the complete trace */ const char* trace_description = "BDD Execution"; /* 0- Check prerequisites */ BDD_PARTIAL_TRACE_EXECUTOR_CHECK_INSTANCE(self); TRACE_CHECK_INSTANCE(trace); BDD_FSM_CHECK_INSTANCE(self->fsm); BDD_ENC_CHECK_INSTANCE(self->enc); dd = BddEnc_get_dd_manager(self->enc); step = trace_first_iter(trace); nusmv_assert(TRACE_END_ITER != step); trace_states = TraceUtils_fetch_as_bdd(trace, step, TRACE_ITER_SF_SYMBOLS, self->enc); /* 1- Check Start State */ { bdd_ptr init_bdd = BddFsm_get_init(self->fsm); bdd_ptr invar_bdd = BddFsm_get_state_constraints(self->fsm); BddStates source_states; /* last known states */ source_states = bdd_and(dd, init_bdd, invar_bdd); bdd_and_accumulate(dd, &source_states, trace_states); bdd_free(dd, invar_bdd); bdd_free(dd, init_bdd); bdd_free(dd, trace_states); if (!bdd_is_false(dd, source_states)) { boolean terminate = false; path = cons(NODE_PTR(bdd_dup(source_states)), Nil); ++ count; /* 2- Check Consecutive States are related by transition relation */ do { BddStates last_state; /* (unshifted) next state */ BddStates next_state; /* next state constraints */ BddInputs next_input; /* next input constraints */ BddStatesInputsNexts next_combo; /* state-input-next constraints */ BddStatesInputsNexts constraints; step = TraceIter_get_next(step); if (TRACE_END_ITER != step) { next_input = \ TraceUtils_fetch_as_bdd(trace, step, TRACE_ITER_I_SYMBOLS, self->enc); next_combo = \ TraceUtils_fetch_as_bdd(trace, step, TRACE_ITER_COMBINATORIAL, self->enc); last_state = \ TraceUtils_fetch_as_bdd(trace, step, TRACE_ITER_SF_SYMBOLS, self->enc); next_state = BddEnc_state_var_to_next_state_var(self->enc, last_state); if (0 < BaseTraceExecutor_get_verbosity(executor)) { fprintf(BaseTraceExecutor_get_output_stream(executor), "-- executing step %d ... ", 1 + count); fflush(BaseTraceExecutor_get_output_stream(executor)); } /* building constrained fwd image */ constraints = bdd_and(dd, next_input, next_combo); bdd_and_accumulate(dd, &constraints, next_state); fwd_image = BddFsm_get_sins_constrained_forward_image(self->fsm, source_states, constraints); /* test whether the constrained fwd image is not empty */ if (!bdd_is_false(dd, fwd_image)) { if (0 < BaseTraceExecutor_get_verbosity(executor)) { fprintf(BaseTraceExecutor_get_output_stream(executor), "done\n"); } path = cons(NODE_PTR(fwd_image), path); ++ count; } else { if (0 < BaseTraceExecutor_get_verbosity(executor)) { fprintf(BaseTraceExecutor_get_output_stream(executor), "failed!\n"); } terminate = true; success = false; } /* no longer used bdd refs */ bdd_free(dd, next_input); bdd_free(dd, next_combo); bdd_free(dd, last_state); bdd_free(dd, next_state); bdd_free(dd, source_states); source_states = bdd_dup(fwd_image); } else { if (0 == count) { fprintf(BaseTraceExecutor_get_error_stream(executor), "Warning: trace has no transitions.\n"); } terminate = true; } } while (!terminate); /* loop on state/input pairs */ } /* if has initial state */ else { fprintf(BaseTraceExecutor_get_error_stream(executor), "Error: starting state is not initial state.\n"); success = false; } /* 3- If last state could be reached a complete trace exists */ if (success) { if (0 < count) { res = \ bdd_partial_trace_executor_generate(self, fwd_image, path, count, language, trace_description); } else { /* generates a complete state of trace of length 0 */ res = \ bdd_partial_trace_executor_generate(self, source_states, Nil, 0, language, trace_description); } nusmv_assert(TRACE(NULL) != res); /* cleanup */ walk_dd(dd, bdd_free, path); free_list(path); } bdd_free(dd, source_states); } /* as a final stage, verify loopbacks consistency using internal service. The incomplete trace is compatible (that is, a valid completion exists) iff exactly len(Trace) steps have been performed *and* loopback data for the incomplete trace applies to the complete one as well. */ if (TRACE(NULL) != res) { if (Trace_get_length(trace) == count && partial_trace_executor_check_loopbacks(partial_executor, trace, res)) { fprintf(BaseTraceExecutor_get_output_stream(executor), "-- Trace was successfully completed.\n"); } else { Trace_destroy(res); res = TRACE(NULL); } } if (TRACE(NULL) == res) { fprintf(BaseTraceExecutor_get_output_stream(executor), "-- Trace could not be completed.\n"); } if (NIL(int) != n_steps) { *n_steps = count; } return res; }