@@ -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,11 @@ 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+ /*
429+ TODO weird... if we return here (as logically we should do), few tests start failing...
430+ is there really a logical bug? or those are just brittle, seed-dependent tests?
431+ */
432+ // return
404433 }
405434
406435 val p = randomness.nextDouble()
@@ -473,6 +502,9 @@ class StringGene(
473502 return false
474503 }
475504
505+ // we start with a high value for probability of using a tained value.
506+ // however, during search we decrease it, but not lower than specified minimum here, until start of focused search.
507+ // when focus search starts, we no longer use taint values
476508 val minPforTaint = 0.1
477509 val tp = apc.getBaseTaintAnalysisProbability(minPforTaint)
478510
@@ -1079,7 +1111,8 @@ class StringGene(
10791111 }
10801112
10811113 override fun evolve () {
1082- // TODO need refactoring
1114+ // there are a lot of edge cases here...
1115+ throw IllegalStateException (" String genes should not be evolved directly, but via mutation" )
10831116 }
10841117
10851118 /* *
0 commit comments