fn check_goals_fast(
    s: &SPState, goals: &[&Predicate], plan: &SPPlan, ts_model: &TransitionSystemModel
) -> bool {
    if goals.iter().all(|g| g.eval(s)) {
        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);

    // we need to make sure goals can be ticked off when reached.
    let mut goals = goals.to_vec();

    let mut state = s.clone();
    let mut counter = 0;
    loop {
        // println!("NEW STATE:\n{}", state);
        let state_changed = tm
            .iter()
            .flat_map(|ts| {
                if ts.iter().all(|t| {
                    let x = t.eval(&state);
                    if !t.path().to_string().contains("Blocked") {
                        // println!("for {}: eval: {}, trans: {}", t.path(), x, t);
                    }
                    x
                }) {
                    // transitions enabled.
                    counter += 1;
                    if counter > 1000 {
                        // there is a self loop in the model
                        let t_names = ts
                            .iter()
                            .map(|t| t.path().to_string())
                            .collect::<Vec<_>>()
                            .join(",");
                        panic!("self loop with transitions {}", t_names);
                    }

                    // take all actions
                    ts.iter().flat_map(|t| t.actions.iter()).for_each(|a| {
                        // println!("applied action: {}", a);
                        let _res = a.next(&mut state);
                    });

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

                    // next -> cur
                    let changed = state.take_transition();

                    //println!("THE STATE\n{}", state);

                    if bad_state(&state, ts_model) {
                        // println!("for {}: eval: {}, trans: {}", t.path(), x, t);
                        None
                    } else {
                        Some(changed)
                    }
                } else {
                    None
                }
            })
            .any(|x| x);

        // if SPRunner::bad_state(&state, ts_model) {
        //     println!("final state is bad!");
        //     return false;
        // }

        goals.retain(|g| !g.eval(&state));
        if goals.is_empty() {
            return true;
        } else if !state_changed {
            // double check with complete search in the normal
            // case where we fail early in the plan this is still
            // fast, but it saves us from the issue descibed
            // above. worst case we waste some time here but but
            // it should be faster than replanning anyway.
            //
            // actually this becomes quite expensive... for now just replan

            // println!("NOT CHECKING GOALS COMPLETE, replan instead.");
            // return self.check_goals_complete(s, &goals, plan, ts_model);
            return false; // think about how we want to do it...
        }
    }
}
/// Checks wheter we can reach the current goal As it doesnt
/// exactly follow the plan but instead simulated the runner, it
/// can fail if the plan contains two "choices" involving the same
/// transitions. Then the "wrong" one might be taken first.
Checks wheter we can reach the current goal As it doesnt
exactly follow the plan but instead simulated the runner, it
can fail if the plan contains two "choices" involving the same
transitions. Then the "wrong" one might be taken first.
Checks wheter we can reach the current goal As it doesnt exactly follow the plan but instead simulated the runner it can fail if the plan contains two " choices " involving the same transitions . Then the " wrong " one might be taken first .
fn check_goals_fast(
    s: &SPState, goals: &[&Predicate], plan: &SPPlan, ts_model: &TransitionSystemModel
) -> bool {
    if goals.iter().all(|g| g.eval(s)) {
        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);
    // we need to make sure goals can be ticked off when reached.
    let mut goals = goals.to_vec();
    let mut state = s.clone();
    let mut counter = 0;
    loop {
        // println!("NEW STATE:\n{}", state);
        let state_changed = tm
            .iter()
            .flat_map(|ts| {
                if ts.iter().all(|t| {
                    let x = t.eval(&state);
                    if !t.path().to_string().contains("Blocked") {
                        // println!("for {}: eval: {}, trans: {}", t.path(), x, t);
                    }
                    x
                }) {
                    // transitions enabled.
                    counter += 1;
                    if counter > 1000 {
                        // there is a self loop in the model
                        let t_names = ts
                            .iter()
                            .map(|t| t.path().to_string())
                            .collect::<Vec<_>>()
                            .join(",");
                        panic!("self loop with transitions {}", t_names);
                    }
                    // take all actions
                    ts.iter().flat_map(|t| t.actions.iter()).for_each(|a| {
                        // println!("applied action: {}", a);
                        let _res = a.next(&mut state);
                    });
                    // update state predicates
                    update_predicates(&mut state, &ts_model.state_predicates);
                    // next -> cur
                    let changed = state.take_transition();
                    //println!("THE STATE\n{}", state);
                    if bad_state(&state, ts_model) {
                        // println!("for {}: eval: {}, trans: {}", t.path(), x, t);
                        None
                    } else {
                        Some(changed)
                    }
                } else {
                    None
                }
            })
            .any(|x| x);
        // if SPRunner::bad_state(&state, ts_model) {
        //     println!("final state is bad!");
        //     return false;
        // }
        goals.retain(|g| !g.eval(&state));
        if goals.is_empty() {
            return true;
        } else if !state_changed {
            // double check with complete search in the normal
            // case where we fail early in the plan this is still
            // fast, but it saves us from the issue descibed
            // above. worst case we waste some time here but but
            // it should be faster than replanning anyway.
            //
            // actually this becomes quite expensive... for now just replan
            // println!("NOT CHECKING GOALS COMPLETE, replan instead.");
            // return self.check_goals_complete(s, &goals, plan, ts_model);
            return false; // think about how we want to do it...
        }
    }
}
fn check_goals_fast ( s : & SPState , goals : & [ & Predicate ] , plan : & SPPlan , ts_model : & TransitionSystemModel ) -> bool { if goals . iter ( ) . all ( | g | g . eval ( s ) ) { 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 ) ; // we need to make sure goals can be ticked off when reached. let mut goals = goals . to_vec ( ) ; let mut state = s . clone ( ) ; let mut counter = 0 ; loop { // println!("NEW STATE:\n{}", state); let state_changed = tm . iter ( ) . flat_map ( | ts | { if ts . iter ( ) . all ( | t | { let x = t . eval ( & state ) ; if ! t . path ( ) . to_string ( ) . contains ( " " ) { // println!("for {}: eval: {}, trans: {}", t.path(), x, t); } x } ) { // transitions enabled. counter += 1 ; if counter > 1000 { // there is a self loop in the model let t_names = ts . iter ( ) . map ( | t | t . path ( ) . to_string ( ) ) . collect :: < Vec < _ > > ( ) . join ( " " ) ; panic ! ( " " t_names ) ; } // take all actions ts . iter ( ) . flat_map ( | t | t . actions . iter ( ) ) . for_each ( | a | { // println!("applied action: {}", a); let _res = a . next ( & mut state ) ; } ) ; // update state predicates update_predicates ( & mut state , & ts_model . state_predicates ) ; // next -> cur let changed = state . take_transition ( ) ; //println!("THE STATE\n{}", state); if bad_state ( & state , ts_model ) { // println!("for {}: eval: {}, trans: {}", t.path(), x, t); None } else { Some ( changed ) } } else { None } } ) . any ( | x | x ) ; // if SPRunner::bad_state(&state, ts_model) { //     println!("final state is bad!"); //     return false; // } goals . retain ( | g | ! g . eval ( & state ) ) ; if goals . is_empty ( ) { return true ; } else if ! state_changed { // double check with complete search in the normal // case where we fail early in the plan this is still // fast, but it saves us from the issue descibed // above. worst case we waste some time here but but // it should be faster than replanning anyway. // // actually this becomes quite expensive... for now just replan // println!("NOT CHECKING GOALS COMPLETE, replan instead."); // return self.check_goals_complete(s, &goals, plan, ts_model); return false ; // think about how we want to do it... } } }
Checks wheter we can reach the current goal As it doesnt
exactly follow the plan but instead simulated the runner, it
can fail if the plan contains two "choices" involving the same
transitions.
Checks wheter we can reach the current goal As it doesnt exactly follow the plan but instead simulated the runner it can fail if the plan contains two " choices " involving the same transitions .
s
&SPState
goals
&[&Predicate]
plan
&SPPlan
ts_model
&TransitionSystemModel