Skip to content

Commit

Permalink
Fix a bug in the guided operators
Browse files Browse the repository at this point in the history
  • Loading branch information
pderakhshanfar committed Mar 8, 2019
1 parent c411f79 commit 8bbcf81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,18 @@ public class GuidedMutation<T extends Chromosome> {

public void mutateOffspring(T offspring) {
boolean isValid = false;
// let's try one single mutation
try {
doRandomMutation(offspring);
} catch (AssertionError e) {
LOG.debug("First try for insertion mutation was unsuccessful.");
}
// if the chromosome has no public call, we insert new random statements
isValid = utility.includesPublicCall(offspring);

// if the chromosome has no public call, we insert new random statements
if (!isValid) {
int nTrials = 0; // we try maximum 50 insertion mutations (to avoid infinite loop)
while (!isValid && nTrials < 50) {
try {
int nTrials = 0; // we try maximum 50 insertion mutations (to avoid infinite loop)
while (!isValid && nTrials < 5) {
try {
doRandomMutation(offspring);
isValid = utility.includesPublicCall(offspring);
} catch (AssertionError e) {
LOG.debug("Random insertion mutation was unsuccessful.");
} finally {
nTrials++;
}
isValid = utility.includesPublicCall(offspring);
} catch (AssertionError e) {
LOG.debug("Random insertion mutation was unsuccessful.");
} finally {
nTrials++;
}
}
offspring.setChanged(true);
offspring.updateAge(offspring.getAge() + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class GuidedSearchUtility<T extends Chromosome> {
public Set<String> publicCalls = new HashSet<String>();

public boolean includesPublicCall (T individual) {
if(publicCalls.size()==0){
getPublicCalls();
}
Iterator<String> publicCallsIterator = publicCalls.iterator();
TestChromosome candidateChrom = (TestChromosome) individual;
TestCase candidate = candidateChrom.getTestCase();
Expand Down

3 comments on commit 8bbcf81

@p-hamann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really intended to reduce the trials from 50 to 5?

@pderakhshanfar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We noticed that using 50 trials leads to more time taking mutation operation, thereby slowing down the search process. Also, reducing the trials helps Botsing to generate and evaluate more tests without losing guidance.

@p-hamann
Copy link
Contributor

@p-hamann p-hamann commented on 8bbcf81 Mar 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I understand. My guess would be that it does not happen very often that a mutation loses a public call. In that case it should not come to slowing down. If it occurs frequently in a specific case and several test cases are affected, there is a risk that reducing the number of trials will lower the mutation rate. In this case, it would be interesting to know how large the proportion of non-mutated test cases is that would have mutated in 50 trials.

Btw, thanks for this commit. I only noticed the fault at the crossover operator, but together with this fix, Botsing finally achieves expected effectiveness based on your evaluations 👍

Please sign in to comment.