Skip to content

Commit

Permalink
merge with weight-based solution
Browse files Browse the repository at this point in the history
  • Loading branch information
man-zhang committed Jun 3, 2020
1 parent 1e0b92c commit 5b9b88b
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class EvaluatedIndividual<T>(val fitness: FitnessValue,

}

fun getSizeOfActionImpact(fromInitialization : Boolean) : Int{
fun getSizeOfImpact(fromInitialization : Boolean) : Int{
impactInfo?: return -1
return impactInfo.getSizeOfActionImpacts(fromInitialization)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ArrayGene<T>(
SubsetGeneSelectionStrategy.ADAPTIVE_WEIGHT -> {
if(additionalGeneMutationInfo?.impact != null
&& additionalGeneMutationInfo.impact is ArrayGeneImpact
&& additionalGeneMutationInfo.impact.sizeImpact.noImprovement.any { it.value < 2 } //if there is recent improvement by manipulating size
&& additionalGeneMutationInfo.impact.sizeImpact.getNoImpactsFromImpactCounter().any { it.value < 2 } //if there is recent improvement by manipulating size
){
0.3 // increase probability to mutate size
}else MODIFY_SIZE
Expand Down
23 changes: 12 additions & 11 deletions core/src/main/kotlin/org/evomaster/core/search/gene/EnumGene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ class EnumGene<T : Comparable<T>>(
return true
}

if (additionalGeneMutationInfo?.impact != null && additionalGeneMutationInfo.impact is EnumGeneImpact){
val candidates = (0 until values.size).filter { index != it }.map {
Pair(it, additionalGeneMutationInfo.impact.values[it])
}
val selects = additionalGeneMutationInfo.archiveMutator.selectGenesByArchive(candidates, 1.0/(values.size - 1), additionalGeneMutationInfo.targets)
index = randomness.choose(selects)

return true
}

throw IllegalArgumentException("impact is null or not DisruptiveGeneImpact")
// archive-based mutation
// if (additionalGeneMutationInfo?.impact != null && additionalGeneMutationInfo.impact is EnumGeneImpact){
// val candidates = (0 until values.size).filter { index != it }.map {
// Pair(it, additionalGeneMutationInfo.impact.values[it])
// }
// val selects = additionalGeneMutationInfo.archiveMutator.selectGenesByArchive(candidates, 1.0/(values.size - 1), additionalGeneMutationInfo.targets)
// index = randomness.choose(selects)
//
// return true
// }

throw IllegalArgumentException("impact is null or not EnumGeneImpact")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MapGene<T>(
SubsetGeneSelectionStrategy.ADAPTIVE_WEIGHT -> {
if(additionalGeneMutationInfo?.impact != null
&& additionalGeneMutationInfo.impact is MapGeneImpact
&& additionalGeneMutationInfo.impact.sizeImpact.noImprovement.any { it.value < 2 } //if there is recent improvement by manipulating size
&& additionalGeneMutationInfo.impact.sizeImpact.getNoImpactsFromImpactCounter().any { it.value < 2 } //if there is recent improvement by manipulating size
){
0.3 // increase probability to mutate size
}else MODIFY_SIZE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class OptionalGene(name: String,
if (additionalGeneMutationInfo?.impact != null && additionalGeneMutationInfo.impact is OptionalGeneImpact){
//we only set 'active' false from true when the mutated times is more than 5 and its impact times of a falseValue is more than 1.5 times of a trueValue.
val inactive = additionalGeneMutationInfo.impact.activeImpact.run {
this.timesToManipulate > 5
this.getTimesToManipulate() > 5
&&
(this.falseValue.timesOfImpact.filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) > ((this.trueValue.timesOfImpact.filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) * 1.5)
(this.falseValue.getTimesOfImpacts().filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) > ((this.trueValue.getTimesOfImpacts().filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) * 1.5)
}
if (inactive) return emptyList() else listOf(gene)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class SqlNullable(name: String,
if (additionalGeneMutationInfo?.impact != null && additionalGeneMutationInfo.impact is SqlNullableImpact){
//we only set 'active' false from true when the mutated times is more than 5 and its impact times of a falseValue is more than 1.5 times of a trueValue.
val inactive = additionalGeneMutationInfo.impact.presentImpact.run {
this.timesToManipulate > 5
this.getTimesToManipulate() > 5
&&
(this.falseValue.timesOfImpact.filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) > ((this.trueValue.timesOfImpact.filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) * 1.5)
(this.falseValue.getTimesOfImpacts().filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) > ((this.trueValue.getTimesOfImpacts().filter { additionalGeneMutationInfo.targets.contains(it.key) }.map { it.value }.max()?:0) * 1.5)
}
if (inactive) return emptyList() else listOf(gene)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ abstract class Mutator<T> : TrackOperator where T : Individual {
*/
private fun getTargetForCoverageCalculation(archive: Archive<T>, mutatedGenes: MutatedGeneSpecification, evi: EvaluatedIndividual<T>) : Set<Int> {

if (!config.enablePrioritizeTargetsByImpact || config.geneSelectionMethod == GeneMutationSelectionMethod.NONE || mutatedGenes.geneSelectionStrategy == GeneMutationSelectionMethod.NONE) return setOf()
if (!config.enablePrioritizeTargetsByImpact || config.adaptiveGeneSelectionMethod == GeneMutationSelectionMethod.NONE || mutatedGenes.geneSelectionStrategy == GeneMutationSelectionMethod.NONE) return setOf()

val all = archive.notCoveredTargets().filter { !IdMapper.isLocal(it) }.toSet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ open class StandardMutator<T> : Mutator<T>() where T : Individual {
//root gene reference
val id = ImpactUtils.generateGeneId(copy, gene)
//root gene impact
val impact = individual.getImpactOfGenes()[id]
val impact = individual.getImpact(copy, gene)
gene.standardMutation(randomness, apc, mwc, allGenes, selectionStrategy, enableAdaptiveMutation, AdditionalGeneSelectionInfo(config.adaptiveGeneSelectionMethod, impact, id, archiveMutator, individual,targets ))
} else {
gene.standardMutation(randomness, apc, mwc, allGenes, selectionStrategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class IndividualGeneImpactTest {

val evi_ind1 = simulatedMutator.getFakeEvaluatedIndividual()

assert(evi_ind1.getSizeOfActionImpact(fromInitialization = false) == 2)
assert(evi_ind1.getSizeOfImpact(fromInitialization = false) == 2)
val mutatedIndex = 1
val spec = MutatedGeneSpecification()

Expand Down Expand Up @@ -95,7 +95,7 @@ class IndividualGeneImpactTest {
impactTargets = impactTarget
)

assert(tracked_evi_ind2.getSizeOfActionImpact(false) == 2)
assert(tracked_evi_ind2.getSizeOfImpact(false) == 2)
val evi_ind1impactInfo = evi_ind1.getImpactByAction(mutatedIndex, false)
assert(evi_ind1impactInfo!= null)
val ind1impact = evi_ind1impactInfo!![mutatedGeneId]
Expand Down Expand Up @@ -129,7 +129,7 @@ class IndividualGeneImpactTest {

val evi_ind1 = simulatedMutator.getFakeEvaluatedIndividual()

assert(evi_ind1.getSizeOfActionImpact(false) == 2)
assert(evi_ind1.getSizeOfImpact(false) == 2)
val mutatedIndex = 1
val spec = MutatedGeneSpecification()

Expand Down Expand Up @@ -168,7 +168,7 @@ class IndividualGeneImpactTest {
impactTargets = impactTarget
)

assert(tracked_evi_ind2.getSizeOfActionImpact(false) == 1)
assert(tracked_evi_ind2.getSizeOfImpact(false) == 1)


}
Expand Down
13 changes: 10 additions & 3 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,45 @@ There are 3 types of options:
|`S1iR`| __Double__. Specify a probability to apply S1iR when resource sampling strategy is 'Customized'. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.25`.|
|`S2dR`| __Double__. Specify a probability to apply S2dR when resource sampling strategy is 'Customized'. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.25`.|
|`SMdR`| __Double__. Specify a probability to apply SMdR when resource sampling strategy is 'Customized'. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.25`.|
|`abstractInitializationGeneToMutate`| __Boolean__. whether to abstract genes that exist initialization actions to mutate. *Default value*: `false`.|
|`adaptiveGeneSelectionMethod`| __Enum__. Specify whether to enable archive-based selection for selecting genes to mutate. *Valid values*: `NONE, AWAY_NOIMPACT, APPROACH_IMPACT, APPROACH_LATEST_IMPACT, APPROACH_LATEST_IMPROVEMENT, BALANCE_IMPACT_NOIMPACT, ALL_FIXED_RAND`. *Default value*: `NONE`.|
|`adaptivePerOfCandidateGenesToMutate`| __Boolean__. Specify whether to decide a top percent of genes to mutate adaptively. *Default value*: `false`.|
|`archiveGeneMutation`| __Enum__. Whether to enable archive-based gene mutation. *Valid values*: `NONE, SPECIFIED, ADAPTIVE`. *Default value*: `NONE`.|
|`coveredTargetFile`| __String__. Specify a file which saves covered targets info regarding generated test suite. *Default value*: `coveredTargets.txt`.|
|`coveredTargetSortedBy`| __Enum__. Specify a format to organize the covered targets by the search. *Valid values*: `NAME, TEST`. *Default value*: `NAME`.|
|`d`| __Double__. Specify a starting percentage of genes of an individual to mutate. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.5`.|
|`dependencyFile`| __String__. Specify a file that saves derived dependencies. *Default value*: `dependencies.csv`.|
|`disableStructureMutationDuringFocusSearch`| __Boolean__. Specify whether to disable structure mutation during focus search. *Default value*: `false`.|
|`doesApplyNameMatching`| __Boolean__. Whether to apply text/name analysis with natural language parser to derive relationships between name entities, e.g., a resource identifier with a name of table. *Default value*: `false`.|
|`enableCompleteObjects`| __Boolean__. Enable EvoMaster to generate, use, and attach complete objects to REST calls, rather than just the needed fields/values. *Default value*: `false`.|
|`enableGeneSelectionMethodForGene`| __Boolean__. Specify whether to enable archive-based selection for selecting genes to mutate inside a gene, e.g., ObjectGene. *Default value*: `true`.|
|`enablePrioritizeTargetsByImpact`| __Boolean__. Specify whether to prioritize targets to be evaluated regarding impacts. *Default value*: `false`.|
|`enableProcessMonitor`| __Boolean__. Whether or not enable a search process monitor for archiving evaluated individuals and Archive regarding an evaluation of search. This is only needed when running experiments with different parameter settings. *Default value*: `false`.|
|`enableTrackEvaluatedIndividual`| __Boolean__. Whether to enable tracking the history of modifications of the individuals with its fitness values (i.e., evaluated individual) during the search. Note that we enforced that set enableTrackIndividual false when enableTrackEvaluatedIndividual is true since information of individual is part of evaluated individual. *Default value*: `false`.|
|`enableTrackIndividual`| __Boolean__. Whether to enable tracking the history of modifications of the individuals during the search. *Default value*: `false`.|
|`endPerOfCandidateGenesToMutate`| __Double__. Specify a percentage (after starting a focus search) which is used by archived-based gene selection method (e.g., APPROACH_IMPACT) for selecting top percent of genes as potential candidates to mutate. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.1`.|
|`endPerOfCandidateGenesToMutate`| __Double__. Specify a percentage after starting a focus search) which is used by archived-based gene selection method (e.g., APPROACH_IMPACT) for selecting top percent of genes as potential candidates to mutate. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.5`.|
|`executiveSummary`| __Boolean__. Generate an executive summary, containing an example of each category of potential fault found. *Default value*: `false`.|
|`expectationsActive`| __Boolean__. Enable Expectation Generation. If enabled, expectations will be generated. A variable called expectationsMasterSwitch is added to the test suite, with a default value of false. If set to true, an expectation that fails will cause the test case containing it to fail. *Default value*: `false`.|
|`exportCoveredTarget`| __Boolean__. Specify whether to export covered targets info. *Default value*: `false`.|
|`exportDependencies`| __Boolean__. Specify whether to export derived dependencies among resources. *Default value*: `false`.|
|`exportImpacts`| __Boolean__. Specify whether to export derived impacts among genes. *Default value*: `false`.|
|`generateSqlDataWithDSE`| __Boolean__. Enable EvoMaster to generate SQL data with direct accesses to the database. Use Dynamic Symbolic Execution. *Default value*: `false`.|
|`impactFile`| __String__. Specify a file that saves derived genes. *Default value*: `impact.csv`.|
|`impactGeneSelection`| __Enum__. Specify a solution to prioritize gene selection by impacts, e.g., percentage or subset. *Valid values*: `PROBABILITY, SUBSET_PROBABILITY, ADAPTIVE_SUBSET_PROBABILITY`. *Default value*: `PROBABILITY`.|
|`maxLengthOfTraces`| __Int__. Specify a maxLength of tracking when enableTrackIndividual or enableTrackEvaluatedIndividual is true. Note that the value should be specified with a non-negative number or -1 (for tracking all history). *Constraints*: `min=-1.0`. *Default value*: `10`.|
|`maxMutationRate`| __Double__. Specify a maximum mutation rate when enabling 'adaptiveMutationRate'. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.9`.|
|`minRowOfTable`| __Int__. Specify a minimal number of rows in a table that enables selection (i.e., SELECT sql) to prepare resources for REST Action. In other word, if the number is less than the specified, insertion is always applied. *Constraints*: `min=0.0`. *Default value*: `10`.|
|`prioritizeNotVisit`| __Boolean__. Specify a solution to prioritize gene selection by impacts, e.g., percentage or subset. *Default value*: `true`.|
|`probOfApplySQLActionToCreateResources`| __Double__. Specify a probability to apply SQL actions for preparing resources for REST Action. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.0`.|
|`probOfArchiveMutation`| __Double__. Specify a probability to enable archive-based mutation. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.0`.|
|`probOfEnablingResourceDependencyHeuristics`| __Double__. Specify whether to enable resource dependency heuristics, i.e, probOfEnablingResourceDependencyHeuristics > 0.0. Note that the option is available to be enabled only if resource-based smart sampling is enable. This option has an effect on sampling multiple resources and mutating a structure of an individual. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.0`.|
|`probOfSelectFromDatabase`| __Double__. Specify a probability that enables selection (i.e., SELECT sql) of data from database instead of insertion (i.e., INSERT sql) for preparing resources for REST actions. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.1`.|
|`processFiles`| __String__. Specify a folder to save results when a search monitor is enabled. *Default value*: `process_data`.|
|`processInterval`| __Int__. Specify how often to save results when a search monitor is enabled. *Default value*: `100`.|
|`resourceSampleStrategy`| __Enum__. Specify whether to enable resource-based strategy to sample an individual during search. Note that resource-based sampling is only applicable for REST problem with MIO algorithm. *Valid values*: `NONE, Customized, EqualProbability, Actions, TimeBudgets, Archive, ConArchive`. *Default value*: `NONE`.|
|`saveMutatedGene`| __Boolean__. Specify whether to save mutated genes during search. *Default value*: `false`.|
|`saveMutatedGeneFile`| __String__. Specify file path to save mutated genes. *Default value*: `mutatedGenes.csv`.|
|`sortedByCounter`| __Boolean__. Specify a solution to prioritize gene selection by impacts, e.g., percentage or subset. *Default value*: `false`.|
|`specializeSQLGeneSelection`| __Boolean__. Whether to specialize sql gene selection to mutation. *Default value*: `false`.|
|`startArchiveMutation`| __Double__. Specify a percentage of used budget to start archive-based mutation when archive-based mutation is enabled. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.0`.|
|`startPerOfCandidateGenesToMutate`| __Double__. Specify a percentage (before starting a focus search) which is used by archived-based gene selection method (e.g., APPROACH_IMPACT) for selecting top percent of genes as potential candidates to mutate. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.9`.|
|`startingPerOfGenesToMutate`| __Double__. Specify a starting percentage of genes of an individual to mutate. *Constraints*: `probability 0.0-1.0`. *Default value*: `0.5`.|
|`testSuiteSplitType`| __Enum__. Instead of generating a single test file, it could be split in several files, according to different strategies. *Valid values*: `NONE, CLUSTER, SUMMARY_ONLY, CODE`. *Default value*: `NONE`.|
Expand Down
Loading

0 comments on commit 5b9b88b

Please sign in to comment.