fn check_goals_complete(
    state: &SPState, goals: &[&Predicate], plan: &SPPlan, ts_model: &TransitionSystemModel,
    disabled_paths: &[SPPath]
) -> bool {
    if goals.iter().all(|g| g.eval(state)) {
        return true;
    }

    let trans: Vec<Transition> = ts_model
        .transitions
        .iter()
        .filter(|t| plan.included_trans.contains(t.path()))
        .cloned()
        .collect();

    let tm = SPTicker::create_transition_map(&trans, &plan.plan);

    fn rec<'a>(
        state: &SPState, goals: &[&Predicate], tm: &Vec<Vec<&'a Transition>>,
        visited: &mut Vec<SPState>, ts_model: &TransitionSystemModel,
    ) -> bool {
        if goals.iter().all(|g| g.eval(&state)) {
            return true;
        }

        let new_states: Vec<SPState> = tm
            .iter()
            .flat_map(|ts| {
                if ts
                    .iter()
                    .all(|t| t.eval(&state) && !bad_state(&state, ts_model))
                {
                    // transitions enabled. clone the state to start a new search branch.
                    let mut state = state.clone();

                    // take all actions
                    ts.iter().flat_map(|t| t.actions.iter()).for_each(|a| {
                        // if actions write to the same path, only the first will be used
                        let _res = a.next(&mut state);
                    });

                    // update state predicates
                    update_predicates(&mut state, &ts_model.state_predicates);

                    // next -> cur
                    if state.take_transition() && !visited.contains(&state) {
                        visited.push(state.clone());
                        Some(state)
                    } else {
                        None
                    }
                } else {
                    None
                }
            })
            .collect();

        new_states
            .iter()
            .any(|s| rec(&s, goals, tm, visited, ts_model))
    }

    let mut visited = vec![state.clone()];
    rec(state, &goals, &tm, &mut visited, ts_model)
}
/// A slower, but more forgiving forward search to goal.
/// This handles the case described in check_goals_fast.
A slower, but more forgiving forward search to goal.
This handles the case described in check_goals_fast.
A slower but more forgiving forward search to goal . This handles the case described in check_goals_fast .
fn check_goals_complete(
    state: &SPState, goals: &[&Predicate], plan: &SPPlan, ts_model: &TransitionSystemModel,
    disabled_paths: &[SPPath]
) -> bool {
    if goals.iter().all(|g| g.eval(state)) {
        return true;
    }
    let trans: Vec<Transition> = ts_model
        .transitions
        .iter()
        .filter(|t| plan.included_trans.contains(t.path()))
        .cloned()
        .collect();
    let tm = SPTicker::create_transition_map(&trans, &plan.plan);
    fn rec<'a>(
        state: &SPState, goals: &[&Predicate], tm: &Vec<Vec<&'a Transition>>,
        visited: &mut Vec<SPState>, ts_model: &TransitionSystemModel,
    ) -> bool {
        if goals.iter().all(|g| g.eval(&state)) {
            return true;
        }
        let new_states: Vec<SPState> = tm
            .iter()
            .flat_map(|ts| {
                if ts
                    .iter()
                    .all(|t| t.eval(&state) && !bad_state(&state, ts_model))
                {
                    // transitions enabled. clone the state to start a new search branch.
                    let mut state = state.clone();
                    // take all actions
                    ts.iter().flat_map(|t| t.actions.iter()).for_each(|a| {
                        // if actions write to the same path, only the first will be used
                        let _res = a.next(&mut state);
                    });
                    // update state predicates
                    update_predicates(&mut state, &ts_model.state_predicates);
                    // next -> cur
                    if state.take_transition() && !visited.contains(&state) {
                        visited.push(state.clone());
                        Some(state)
                    } else {
                        None
                    }
                } else {
                    None
                }
            })
            .collect();
        new_states
            .iter()
            .any(|s| rec(&s, goals, tm, visited, ts_model))
    }
    let mut visited = vec![state.clone()];
    rec(state, &goals, &tm, &mut visited, ts_model)
}
fn check_goals_complete ( state : & SPState , goals : & [ & Predicate ] , plan : & SPPlan , ts_model : & TransitionSystemModel , disabled_paths : & [ SPPath ] ) -> bool { if goals . iter ( ) . all ( | g | g . eval ( state ) ) { return true ; } let trans : Vec < Transition > = ts_model . transitions . iter ( ) . filter ( | t | plan . included_trans . contains ( t . path ( ) ) ) . cloned ( ) . collect ( ) ; let tm = SPTicker :: create_transition_map ( & trans , & plan . plan ) ; fn rec < ' a > ( state : & SPState , goals : & [ & Predicate ] , tm : & Vec < Vec < & ' a Transition > > , visited : & mut Vec < SPState > , ts_model : & TransitionSystemModel , ) -> bool { if goals . iter ( ) . all ( | g | g . eval ( & state ) ) { return true ; } let new_states : Vec < SPState > = tm . iter ( ) . flat_map ( | ts | { if ts . iter ( ) . all ( | t | t . eval ( & state ) && ! bad_state ( & state , ts_model ) ) { // transitions enabled. clone the state to start a new search branch. let mut state = state . clone ( ) ; // take all actions ts . iter ( ) . flat_map ( | t | t . actions . iter ( ) ) . for_each ( | a | { // if actions write to the same path, only the first will be used let _res = a . next ( & mut state ) ; } ) ; // update state predicates update_predicates ( & mut state , & ts_model . state_predicates ) ; // next -> cur if state . take_transition ( ) && ! visited . contains ( & state ) { visited . push ( state . clone ( ) ) ; Some ( state ) } else { None } } else { None } } ) . collect ( ) ; new_states . iter ( ) . any ( | s | rec ( & s , goals , tm , visited , ts_model ) ) } let mut visited = vec ! [ state clone ( ) ] ; rec ( state , & goals , & tm , & mut visited , ts_model ) }
A slower, but more forgiving forward search to goal.
A slower but more forgiving forward search to goal .
state
&SPState
goals
&[&Predicate]
plan
&SPPlan
ts_model
&TransitionSystemModel
disabled_paths
&[SPPath]