Skip to content

Commit 88c4463

Browse files
committed
cleaning and clarifications
1 parent 20c2da9 commit 88c4463

4 files changed

Lines changed: 49 additions & 16 deletions

File tree

core/src/main/kotlin/org/evomaster/core/search/gene/string/StringGene.kt

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ class StringGene(
178178
// }
179179
// return true
180180
return maxLength > 0 //otherwise there is only 1 value, the empty string ""
181+
&& !isDependentTaint()
181182
}
182183

183184
override fun randomize(randomness: Randomness, tryToForceNewValue: Boolean) {
184185

186+
/*
187+
randomization does not apply any taint, and remove it if any is there
188+
*/
189+
185190
/*
186191
Even if through mutation we can get large string, we should
187192
avoid sampling very large strings by default
@@ -227,7 +232,7 @@ class StringGene(
227232
*/
228233
//assert(!tainted)
229234

230-
if(name == TaintInputName.TAINTED_MAP_EM_LABEL_IDENTIFIER){
235+
if(isDependentTaint()){
231236
/*
232237
TODO should have a better check to specify a StringGene is immutable.
233238
If we end up in other cases for this, should add an "immutable" field to this gene
@@ -267,6 +272,12 @@ class StringGene(
267272
//not applied if used data pool
268273
if (!successfulDataPool && config.taintOnSampling) {
269274

275+
/*
276+
the method is called when gene is globally initialized, which is done when sampling.
277+
when sampling a new gene, and we want to use taint, when we can check if using
278+
global info or a direct taint value
279+
*/
280+
270281
if (state.spa.hasInfoFor(name) && randomness.nextDouble() < state.config.useGlobalTaintInfoProbability) {
271282
val spec = state.spa.chooseSpecialization(name, randomness)!!
272283
assert(specializations.size == 0)
@@ -305,27 +316,40 @@ class StringGene(
305316
}
306317

307318

308-
override fun shallowMutate(randomness: Randomness, apc: AdaptiveParameterControl, mwc: MutationWeightControl,
309-
selectionStrategy: SubsetGeneMutationSelectionStrategy, enableAdaptiveGeneMutation: Boolean, additionalGeneMutationInfo: AdditionalGeneMutationInfo?) : Boolean{
319+
override fun shallowMutate(
320+
randomness: Randomness,
321+
apc: AdaptiveParameterControl,
322+
mwc: MutationWeightControl,
323+
selectionStrategy: SubsetGeneMutationSelectionStrategy,
324+
enableAdaptiveGeneMutation: Boolean,
325+
additionalGeneMutationInfo: AdditionalGeneMutationInfo?
326+
) : Boolean{
310327

311328
val allGenes = getAllGenesInIndividual()
312329

313330
if (enableAdaptiveGeneMutation){
314-
additionalGeneMutationInfo?:throw IllegalArgumentException("archive-based gene mutation cannot be applied without AdditionalGeneMutationInfo")
331+
additionalGeneMutationInfo
332+
?: throw IllegalArgumentException("archive-based gene mutation cannot be applied without AdditionalGeneMutationInfo")
333+
315334
additionalGeneMutationInfo.archiveGeneMutator.mutateStringGene(
316-
this, allGenes = allGenes, selectionStrategy = selectionStrategy, targets = additionalGeneMutationInfo.targets, additionalGeneMutationInfo = additionalGeneMutationInfo, changeSpecSetting = PROB_CHANGE_SPEC
335+
this,
336+
allGenes = allGenes,
337+
selectionStrategy = selectionStrategy,
338+
targets = additionalGeneMutationInfo.targets,
339+
additionalGeneMutationInfo = additionalGeneMutationInfo,
340+
changeSpecSetting = PROB_CHANGE_SPEC
317341
)
318342
return true
319343
}
320344

321345
val didSpecializationMutation = standardSpecializationMutation(
322346
randomness, apc, mwc, selectionStrategy, allGenes, enableAdaptiveGeneMutation, additionalGeneMutationInfo
323347
)
348+
324349
if (!didSpecializationMutation){
325-
standardValueMutation(
326-
randomness, allGenes, apc
327-
)
350+
standardValueMutation(randomness, allGenes, apc)
328351
}
352+
329353
return true
330354
}
331355

@@ -401,6 +425,7 @@ class StringGene(
401425
if(TaintInputName.isTaintInput(value)){
402426
//standard mutation on a tainted value makes little sense, so randomize instead
403427
randomize(randomness, true)
428+
return
404429
}
405430

406431
val p = randomness.nextDouble()
@@ -473,6 +498,9 @@ class StringGene(
473498
return false
474499
}
475500

501+
// we start with a high value for probability of using a tained value.
502+
// however, during search we decrease it, but not lower than specified minimum here, until start of focused search.
503+
// when focus search starts, we no longer use taint values
476504
val minPforTaint = 0.1
477505
val tp = apc.getBaseTaintAnalysisProbability(minPforTaint)
478506

@@ -1079,7 +1107,8 @@ class StringGene(
10791107
}
10801108

10811109
override fun evolve() {
1082-
//TODO need refactoring
1110+
//there are a lot of edge cases here...
1111+
throw IllegalStateException("String genes should not be evolved directly, but via mutation")
10831112
}
10841113

10851114
/**

core/src/main/kotlin/org/evomaster/core/search/service/mutator/StandardMutator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ open class StandardMutator<T> : Mutator<T>() where T : Individual {
165165

166166
if(config.taintForceSelectionOfGenesWithSpecialization){
167167
/*
168-
FIXME this should be removed, and rather handled with an "evolve".
169-
but need refactoring of StringGene mutation
168+
Note that some gene are directly "evolved()" in TaintAnalysis.
169+
however, StringGene is very special, and treated ad-hoc, by forcing
170+
selection here
170171
*/
171172
TaintAnalysis.dormantGenes(individual)
172173
.forEach {

core/src/main/kotlin/org/evomaster/core/search/service/mutator/genemutation/ArchiveGeneMutator.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ class ArchiveGeneMutator{
297297
*/
298298
fun mutateStringGene(
299299
gene: StringGene, targets: Set<Int>,
300-
allGenes : List<Gene>, selectionStrategy: SubsetGeneMutationSelectionStrategy, additionalGeneMutationInfo: AdditionalGeneMutationInfo, changeSpecSetting: Double){
300+
allGenes : List<Gene>,
301+
selectionStrategy: SubsetGeneMutationSelectionStrategy,
302+
additionalGeneMutationInfo: AdditionalGeneMutationInfo,
303+
changeSpecSetting: Double
304+
){
305+
301306
var employBinding = true
302307
if (additionalGeneMutationInfo.impact == null){
303308
val ds = gene.standardSpecializationMutation(

core/src/main/kotlin/org/evomaster/core/taint/TaintAnalysis.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ object TaintAnalysis {
5959
fun evolveIndividual(individual: Individual, evolveMaps: Boolean, evolveArrays: Boolean) {
6060

6161
/*
62-
TODO ideally, StringGene specializations should be handled here as well,
63-
but that would need quite a bit of refactoring... :(
64-
especially in mutation code of StringGene.
65-
a technical debt for another day...
62+
string gene is not handled here.
63+
it is handled directly via mutation
6664
*/
6765

6866
val allGenes = individual.seeFullTreeGenes()

0 commit comments

Comments
 (0)