fn select_candidate(
        &mut self,
        return_len: usize,
        state: &AbstractState,
        candidates: &[(StackEffect, Bytecode)],
    ) -> Result<Bytecode, String> {
        debug!("Candidates: {:?}", candidates);
        let stack_len = state.stack_len();
        let prob_add = if stack_len > return_len {
            MUTATION_TOLERANCE / (stack_len as f32)
        } else {
            1.0
        };
        debug!("Pr[add] = {:?}", prob_add);
        let next_instruction_index;
        if self.rng.gen_range(0.0, 1.0) <= prob_add {
            let add_candidates: Vec<(StackEffect, Bytecode)> = candidates
                .iter()
                .filter(|(stack_effect, _)| {
                    *stack_effect == StackEffect::Add || *stack_effect == StackEffect::Nop
                })
                .cloned()
                .collect();
            // Add candidates should not be empty unless the list of bytecode instructions is
            // changed
            if add_candidates.is_empty() {
                return Err("Could not find valid add candidate".to_string());
            }
            next_instruction_index = self.rng.gen_range(0, add_candidates.len());
            Ok(add_candidates[next_instruction_index].1.clone())
        } else {
            let sub_candidates: Vec<(StackEffect, Bytecode)> = candidates
                .iter()
                .filter(|(stack_effect, _)| {
                    *stack_effect == StackEffect::Sub || *stack_effect == StackEffect::Nop
                })
                .cloned()
                .collect();
            // Sub candidates should not be empty unless the list of bytecode instructions is
            // changed
            if sub_candidates.is_empty() {
                return Err("Could not find sub valid candidate".to_string());
            }
            next_instruction_index = self.rng.gen_range(0, sub_candidates.len());
            Ok(sub_candidates[next_instruction_index].1.clone())
        }
    }
/// Select an instruction from the list of candidates based on the current state's
/// stack size and the expected number of function return parameters.
Select an instruction from the list of candidates based on the current state's
stack size and the expected number of function return parameters.
Select an instruction from the list of candidates based on the current state ' s stack size and the expected number of function return parameters .
fn select_candidate(
        &mut self,
        return_len: usize,
        state: &AbstractState,
        candidates: &[(StackEffect, Bytecode)],
    ) -> Result<Bytecode, String> {
        debug!("Candidates: {:?}", candidates);
        let stack_len = state.stack_len();
        let prob_add = if stack_len > return_len {
            MUTATION_TOLERANCE / (stack_len as f32)
        } else {
            1.0
        };
        debug!("Pr[add] = {:?}", prob_add);
        let next_instruction_index;
        if self.rng.gen_range(0.0, 1.0) <= prob_add {
            let add_candidates: Vec<(StackEffect, Bytecode)> = candidates
                .iter()
                .filter(|(stack_effect, _)| {
                    *stack_effect == StackEffect::Add || *stack_effect == StackEffect::Nop
                })
                .cloned()
                .collect();
            // Add candidates should not be empty unless the list of bytecode instructions is
            // changed
            if add_candidates.is_empty() {
                return Err("Could not find valid add candidate".to_string());
            }
            next_instruction_index = self.rng.gen_range(0, add_candidates.len());
            Ok(add_candidates[next_instruction_index].1.clone())
        } else {
            let sub_candidates: Vec<(StackEffect, Bytecode)> = candidates
                .iter()
                .filter(|(stack_effect, _)| {
                    *stack_effect == StackEffect::Sub || *stack_effect == StackEffect::Nop
                })
                .cloned()
                .collect();
            // Sub candidates should not be empty unless the list of bytecode instructions is
            // changed
            if sub_candidates.is_empty() {
                return Err("Could not find sub valid candidate".to_string());
            }
            next_instruction_index = self.rng.gen_range(0, sub_candidates.len());
            Ok(sub_candidates[next_instruction_index].1.clone())
        }
    }
fn select_candidate ( & mut self , return_len : usize , state : & AbstractState , candidates : & [ ( StackEffect , Bytecode ) ] , ) -> Result < Bytecode , String > { debug ! ( " " candidates ) ; let stack_len = state . stack_len ( ) ; let prob_add = if stack_len > return_len { MUTATION_TOLERANCE / ( stack_len as f32 ) } else { 1.0 } ; debug ! ( " " prob_add ) ; let next_instruction_index ; if self . rng . gen_range ( 0.0 , 1.0 ) <= prob_add { let add_candidates : Vec < ( StackEffect , Bytecode ) > = candidates . iter ( ) . filter ( | ( stack_effect , _ ) | { * stack_effect == StackEffect :: Add || * stack_effect == StackEffect :: Nop } ) . cloned ( ) . collect ( ) ; // Add candidates should not be empty unless the list of bytecode instructions is // changed if add_candidates . is_empty ( ) { return Err ( " " . to_string ( ) ) ; } next_instruction_index = self . rng . gen_range ( 0 , add_candidates . len ( ) ) ; Ok ( add_candidates [ next_instruction_index ] . 1 . clone ( ) ) } else { let sub_candidates : Vec < ( StackEffect , Bytecode ) > = candidates . iter ( ) . filter ( | ( stack_effect , _ ) | { * stack_effect == StackEffect :: Sub || * stack_effect == StackEffect :: Nop } ) . cloned ( ) . collect ( ) ; // Sub candidates should not be empty unless the list of bytecode instructions is // changed if sub_candidates . is_empty ( ) { return Err ( " " . to_string ( ) ) ; } next_instruction_index = self . rng . gen_range ( 0 , sub_candidates . len ( ) ) ; Ok ( sub_candidates [ next_instruction_index ] . 1 . clone ( ) ) } }
Select an instruction from the list of candidates based on the current state's
stack size and the expected number of function return parameters.
Select an instruction from the list of candidates based on the current state ' s stack size and the expected number of function return parameters .
&mut self
return_len
usize
state
&AbstractState
candidates
&[(StackEffect, Bytecode)]