-
Notifications
You must be signed in to change notification settings - Fork 97
Changes in StandardGeneticAlgorithm: Freeze targets per generation; add GASolutionSource #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arcuri82
merged 23 commits into
WebFuzzing:pr-remote-francastagna
from
francastagna:master
Oct 20, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d313f00
feat(core/ga): freeze targets per generation; add GASolutionSource + …
fncastagna 8fb5bbf
fix cp error in StandardGeneticAlgorithmTest.kt
fncastagna 8288e69
add tests to StandardGeneticAlgorithmTest.kt
fncastagna b5e7283
added publisher observer pattern
fncastagna 916290a
rename crossover and mutator operator method names
fncastagna 23c0060
applyMutation renamed to mutateIndividual and DefaultCrossoveOperator…
fncastagna f8cd208
added DefaultMutationOperator javadoc
fncastagna d111925
added TournamentSelectionStrategy javadocs
fncastagna 19f5c41
fix matching brackets
fncastagna 08e98b0
add tournament selection strategy javadocs
fncastagna a0dc76c
deleted accidentaly commited file MonotonicGeneticAlgorithmTest
fncastagna 0259fe2
Merge pull request #3 from francastagna/feature/genetics-algorithms
francastagna 46e4164
Merge branch 'master' into master
francastagna 8749385
remove GA bindings from BaseModule
fncastagna 7bcac3b
improve explanation of GASolutionSource i
fncastagna 7edce0d
remove injection of GA operators, changed inline for loop to multilin…
fncastagna e931072
added suite to GA operators package name
fncastagna 14ffc21
added @BeforeEach to tests in StandardGeneticAlgorithmTest
fncastagna 28d9e72
added suite to GA operators package name
fncastagna 40869f9
minor fixes
fncastagna 4c82ab9
compilation and test fixes
fncastagna 013a774
renamed mutation operator
fncastagna 7bf221f
Merge pull request #7 from francastagna/feature/standard-genetic-algo…
francastagna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/src/main/kotlin/org/evomaster/core/search/algorithms/observer/GAObserver.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.evomaster.core.search.algorithms.observer | ||
|
|
||
| import org.evomaster.core.search.Individual | ||
| import org.evomaster.core.search.algorithms.wts.WtsEvalIndividual | ||
|
|
||
| /** | ||
| * Observer for GA internal events used primarily for testing/telemetry. | ||
| * Default methods are no-ops so listeners can implement only what they need. | ||
| */ | ||
| interface GAObserver<T : Individual> { | ||
| /** Called when one parent is selected. */ | ||
| fun onSelection(sel: WtsEvalIndividual<T>) {} | ||
| /** Called immediately after crossover is applied to [x] and [y]. */ | ||
| fun onCrossover(x: WtsEvalIndividual<T>, y: WtsEvalIndividual<T>) {} | ||
|
|
||
| /** Called immediately after mutation is applied to [wts]. */ | ||
| fun onMutation(wts: WtsEvalIndividual<T>) {} | ||
| } | ||
|
|
||
|
|
11 changes: 11 additions & 0 deletions
11
.../src/main/kotlin/org/evomaster/core/search/algorithms/strategy/suite/CrossoverOperator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.evomaster.core.search.algorithms.strategy.suite | ||
|
|
||
| import org.evomaster.core.search.Individual | ||
| import org.evomaster.core.search.algorithms.wts.WtsEvalIndividual | ||
| import org.evomaster.core.search.service.Randomness | ||
|
|
||
| interface CrossoverOperator { | ||
| fun <T : Individual> applyCrossover(x: WtsEvalIndividual<T>, y: WtsEvalIndividual<T>, randomness: Randomness) | ||
| } | ||
|
|
||
|
|
35 changes: 35 additions & 0 deletions
35
...in/kotlin/org/evomaster/core/search/algorithms/strategy/suite/DefaultCrossoverOperator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package org.evomaster.core.search.algorithms.strategy.suite | ||
|
|
||
| import org.evomaster.core.search.Individual | ||
| import org.evomaster.core.search.algorithms.wts.WtsEvalIndividual | ||
| import org.evomaster.core.search.service.Randomness | ||
| import kotlin.math.min | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * Default crossover operator for GA test suites. | ||
| * | ||
| * Behavior: | ||
| * - Takes the two suites as input, named x and y. | ||
| * - Picks a split point uniformly at random in [0, min(len(x), len(y)) - 1]. | ||
| * - Swaps all elements from index 0 up to the split point (i ∈ [0, split]). | ||
| */ | ||
| class DefaultCrossoverOperator : CrossoverOperator { | ||
| override fun <T : Individual> applyCrossover( | ||
| x: WtsEvalIndividual<T>, | ||
| y: WtsEvalIndividual<T>, | ||
| randomness: Randomness | ||
| ) { | ||
| val nx = x.suite.size | ||
| val ny = y.suite.size | ||
| val splitPoint = randomness.nextInt(min(nx, ny)) | ||
| (0..splitPoint).forEach { | ||
| val k = x.suite[it] | ||
| x.suite[it] = y.suite[it] | ||
| y.suite[it] = k | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
70 changes: 70 additions & 0 deletions
70
.../org/evomaster/core/search/algorithms/strategy/suite/DefaultMutationEvaluationOperator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package org.evomaster.core.search.algorithms.strategy.suite | ||
|
|
||
| import org.evomaster.core.EMConfig | ||
| import org.evomaster.core.search.Individual | ||
| import org.evomaster.core.search.algorithms.wts.WtsEvalIndividual | ||
| import org.evomaster.core.search.service.Archive | ||
| import org.evomaster.core.search.service.FitnessFunction | ||
| import org.evomaster.core.search.service.Randomness | ||
| import org.evomaster.core.search.service.Sampler | ||
| import org.evomaster.core.search.service.mutator.Mutator | ||
|
|
||
| /** | ||
| * Default mutation operator acting at the test suite level for GA. | ||
| * | ||
| * Behavior: | ||
| * - Randomly applies one of: "del", "add", "mod" (selected randomly) | ||
| * - del: if size > 1, remove a random test from the suite. | ||
| * - add: if size < maxSearchSuiteSize, sample + evaluate; add new test to suite (and archive if needed). | ||
| * - mod: mutate one random test in the suite; re-evaluate (or mutateAndSave if GASolutionSource = ARCHIVE). | ||
| */ | ||
| class DefaultMutationEvaluationOperator : MutationEvaluationOperator { | ||
| companion object { | ||
| private const val OP_DELETE = "del" | ||
| private const val OP_ADD = "add" | ||
| private const val OP_MOD = "mod" | ||
| } | ||
|
|
||
| override fun <T : Individual> mutateEvaluateAndArchive( | ||
| wts: WtsEvalIndividual<T>, | ||
| config: EMConfig, | ||
| randomness: Randomness, | ||
| mutator: Mutator<T>, | ||
| ff: FitnessFunction<T>, | ||
| sampler: Sampler<T>, | ||
| archive: Archive<T> | ||
| ) { | ||
| val op = randomness.choose(listOf(OP_DELETE, OP_ADD, OP_MOD)) | ||
| val n = wts.suite.size | ||
|
|
||
| when (op) { | ||
| OP_DELETE -> if (n > 1) { | ||
| val i = randomness.nextInt(n) | ||
| wts.suite.removeAt(i) | ||
| } | ||
|
|
||
| OP_ADD -> if (n < config.maxSearchSuiteSize) { | ||
| ff.calculateCoverage(sampler.sample(), modifiedSpec = null)?.run { | ||
| if (config.gaSolutionSource == EMConfig.GASolutionSource.ARCHIVE) { | ||
| archive.addIfNeeded(this) | ||
| } | ||
| wts.suite.add(this) | ||
| } | ||
| } | ||
|
|
||
| OP_MOD -> { | ||
| val i = randomness.nextInt(n) | ||
| val ind = wts.suite[i] | ||
|
|
||
| if (config.gaSolutionSource == EMConfig.GASolutionSource.ARCHIVE) { | ||
| mutator.mutateAndSave(ind, archive)?.let { wts.suite[i] = it } | ||
| } else { | ||
| val mutated = mutator.mutate(ind) | ||
| ff.calculateCoverage(mutated, modifiedSpec = null)?.let { wts.suite[i] = it } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this? @jgaleotti did we explicitly speak about this? i don't remember... ie, whether we want to evaluated test-level archive for suite generation