0% found this document useful (0 votes)
1 views

Search-based engineering exercises

The document provides an overview of Search-Based Software Engineering (SBSE), which utilizes search algorithms to address software engineering challenges by framing them as optimization problems. It discusses metaheuristics, their classifications, and various techniques such as genetic algorithms and particle swarm optimization, along with their applications in software testing and design. Additionally, it outlines the processes for developing optimization algorithms, selection and mutation operators, and the balance between exploitation and exploration in search strategies.

Uploaded by

suzukisonoko294
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Search-based engineering exercises

The document provides an overview of Search-Based Software Engineering (SBSE), which utilizes search algorithms to address software engineering challenges by framing them as optimization problems. It discusses metaheuristics, their classifications, and various techniques such as genetic algorithms and particle swarm optimization, along with their applications in software testing and design. Additionally, it outlines the processes for developing optimization algorithms, selection and mutation operators, and the balance between exploitation and exploration in search strategies.

Uploaded by

suzukisonoko294
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Exercise

1.​ What do you understand by the term Search-based Software Engineering?


2.​ What are Meta-heuristics?
3.​ What are the differences between Meta-heuristics and heuristics?
4.​ Define the term Optimization as used in SBSE
5.​ When SBSE is applied to Software Testing, it is called ---------- and when it is
applied to Software Design, it is called ----------
6.​ In search-based optimization, given a problem, the set of all possible
solutions is called the ------------------ or -----------------------or -------------------
7.​ In Search Based Software Engineering, a search problem is one in which optimal or
near optimal solutions are sought in a search space of candidate solutions, guided
by a --------------------that distinguishes between better and worse solutions.
8.​ An example of a Population-based Meta-heuristics technique is?
9.​ What are the two sub-types of Population-based Meta-heuristics technique?
10.​ Explain the processes involve to develop an optimization algorithm in SBSE.
11.​ List three selection scheme and hence explain one
12.​List three crossover search operator and hence explain one.
13.​List five types of mutation search operator and hence explain one.
14.​ Effective search balances exploitation of the best solutions so far and exploration
of the search space. Explain
15.​-Differentiate between the following terms as used in meta-heuristics with two in
each case
a.​ --Greedy algorithms vs Optimization algorithms
b.​ --Degree of exploitation and degree of exploration
c.​ --single-solution meta-heuristics and evolutionary computing
(population-based methods)
d.​ --Genotype and phenotype
e.​ --Genetics Algorithm and Tabu search
f.​ --Genetics Algorithm and Traditional Algorithms
16.​-Explain the process involved in order to develop an optimization algorithm
17.​-List five variants of Evolutionary algorithms and hence explain them
18.​-Explain three key ingredients for developing optimization algorithms for
search-based software engineering problems
19.​-Particle Swarn Optimization
a.​ --Define the term Particle Swarn Optimization
b.​ --What are the properties of this technique
c.​ --List two techniques used in Particle Swarn Optimization, choose one, and
explain its principles with real-life case study
d.​ --What are the advantages and disadvantages of Particle Swarn
Optimization
e.​ --What are heuristics optimization techniques
20.​-With respect to a generalized annotated evolutionary algorithm diagram, explain
the concept of evolutionary algorithm
21.​-List two classifications of Meta-heuristics algorithms with three examples i each
category
22.​-Explain the role of different memories in a Tabu Search
23.​-List five types of mutation search operators used in heuristic optimization and
explain them
24.​-List three selection schemes used in heuristic optimization and explain them
25.​-Explain two disadvantages of hill climbing algorithm
26.​-Effective search balances exploitation of the best solution so far and exploration of
the search space. Explain this state explicitly

Search-Based Software Engineering (SBSE)​


Definition: An approach that uses search algorithms (e.g., genetic algorithms) to solve
software engineering problems by transforming them into optimization problems.​
Example: Automatically generating test cases to achieve 90 % code coverage.​

Metaheuristics​
Definition: General-purpose strategies for efficiently exploring a complex solution space.​
Examples:​

●​ Genetic Algorithm (inspired by biological evolution)​

●​ Particle Swarm Optimization (inspired by animal group behavior)​


Metaheuristics vs. Heuristics​

Heuristics Metaheuristics

Problem‑specific rules (e.g., A general framework applicable to many


“schedule the shortest tasks problems (e.g., simulated annealing for
first”). scheduling or design).

Optimization in SBSE​
Finding the optimal solution—or a good approximation—according to some criterion (e.g.,
minimizing test cost while maximizing bug detection).​

Applications of SBSE​

●​ Software Testing: Search‑Based Software Testing (SBST)​

●​ Software Design: Search‑Based Software Design (SBSD)​

Solution Space​
Also called the search space or state space—the set of all possible solutions.​

Fitness Function​
The function guiding the search (evaluation function).​
Example: In testing, measure how many code branches are covered.​

Population‑Based Metaheuristic​
Example: Genetic Algorithm—simulates natural selection using crossover and mutation.​

Subtypes of Population‑Based Metaheuristics​

●​ Evolutionary Algorithms (e.g., Genetic Algorithms)​

●​ Swarm Intelligence (e.g., Particle Swarm Optimization)​

Algorithm Development Process​


1.​ Define the problem (e.g., minimize cost).​

2.​ Represent candidate solutions (e.g., binary strings, trees).​

3.​ Create a fitness function.​

4.​ Choose a metaheuristic (e.g., Genetic Algorithm).​

5.​ Test and tune parameters.​

Selection Schemes​

●​ Roulette Wheel: Probability proportional to fitness.​

●​ Tournament: From k random solutions, select the best.​

●​ Ranking: Selection based on sorted ranks.​

Tournament example:​

1.​ Randomly pick three solutions.​

2.​ Keep the one with the highest fitness.​

Crossover Operators​

●​ Single‑Point: Cut two parents at one point and swap tails.​

●​ Uniform: Mix genes randomly.​

●​ Multi‑Point: Perform cuts at multiple positions.​

Single‑Point example:​
Parents “ABCDE” and “VWXYZ” → Children “ABXYZ” and “VWCDE”.​

Mutation Operators​
●​ Bit‑Flip: Invert a bit (0→1 or 1→0).​

●​ Swap: Exchange two elements.​

●​ Inversion: Reverse a subsequence.​

●​ Scramble: Randomly shuffle a segment.​

●​ Creep: Add a small random value.​

Bit‑Flip example: “1010” → “1000” (third bit flipped).​

Exploitation vs. Exploration​

●​ Exploitation: Refine existing solutions (e.g., hill climbing).​

●​ Exploration: Discover new regions (e.g., random mutation).​


Balance: Too much exploitation risks local optima; too much exploration is
inefficient.​

Key Differentiations​
a. Greedy Algorithms vs. Optimization​

●​ Greedy: Makes the best local choice (e.g., pack the heaviest item first).​

●​ Optimization: Seeks the global best (e.g., evaluate all combinations).​


b. Degree of Exploitation/Exploration​
c. Single‑Solution vs. Population‑Based​

●​ Single‑Solution: Operates on one candidate at a time (e.g., simulated annealing).​

●​ Population: Works with a group of candidates (e.g., genetic algorithms).​


d. Genotype vs. Phenotype​

●​ Genotype: Internal representation (e.g., binary chromosome).​

●​ Phenotype: Observable expression (e.g., actual route in a routing problem).​


e. Genetic Algorithm vs. Tabu Search​
●​ GA: Uses population and genetic operators.​

●​ Tabu: Uses a memory structure to avoid revisiting solutions.​


f. GA vs. Traditional Algorithms​

●​ GA: Stochastic, finds approximate solutions.​

●​ Traditional: Deterministic, seeks exact solutions.​

Variants of Evolutionary Algorithms​

●​ Genetic Algorithm (binary strings)​

●​ Genetic Programming (evolves syntax trees, e.g., mathematical formulas)​

●​ Evolution Strategies (adaptive mutation rates)​

●​ Differential Evolution (uses differences between solutions)​

●​ Neuroevolution (evolves neural networks)​

Key Ingredients in SBSE​

●​ Solution Representation (efficient coding)​

●​ Fitness Function (accurate quality measure)​

●​ Suitable Metaheuristic (choose based on problem, e.g., PSO for continuous


domains)​

Particle Swarm Optimization (PSO)​


a. Definition: Inspired by fish schools; each “particle” adjusts its trajectory toward the
best-known positions.​
b. Properties: No crossover or mutation; uses velocity and position updates.​
c. Variants:​

●​ Global Best: All particles follow the global best.​


●​ Local Best: Particles follow the best in their neighborhood.​
d. Pros & Cons:​

●​ Simple, adaptable, few parameters​


– Can converge prematurely​
e. Optimization Heuristics: Empirical rules to speed convergence (e.g., prioritize
tests covering critical functions).​

Evolutionary Algorithm Workflow​

1.​ Initialization: Generate a random population.​

2.​ Evaluation: Compute fitness for each individual.​

3.​ Selection: Choose the fittest for reproduction.​

4.​ Crossover/Mutation: Create offspring.​

5.​ Replacement: Form the next generation.​

6.​ Repeat until convergence.​

Metaheuristic Classification​

●​ Single‑Solution: Simulated Annealing, Tabu Search, Hill Climbing.​

●​ Population‑Based: Genetic Algorithms, PSO, Ant Colony Optimization.​

Memory in Tabu Search​

●​ Short‑Term Memory: List of recent moves/solutions to avoid.​

●​ Long‑Term Memory: Encourages exploration of under‑visited regions.​

Mutation Operators (Detailed)​

●​ Bit‑Flip, Swap, Inversion, Scramble, Creep (as above).​


Selection Schemes (Detailed)​

●​ Roulette Wheel, Tournament, Ranking (as above).​

Disadvantages of Hill Climbing​

●​ Can get stuck in local optima.​

●​ Plateaus where no local moves improve fitness.​

Balancing Exploitation and Exploration​


Example:​

●​ Exploitation: Use crossover to refine current solutions.​

●​ Exploration: Use mutation to probe new regions.​


Goal: Avoid stagnation while still converging toward an optimum.
Genetic Algorithm – Summary of Operators

Genetic algorithms evolve a population of candidate solutions using selection and


mutation operators.

A. Selection Operators

1. Roulette Wheel Selection

●​ Each individual is assigned a probability of being selected based on its fitness.​

●​ Better fitness = higher chance of selection.​

●​ Simulates a spinning wheel where larger sections belong to fitter individuals.​

Example:​
If A, B, and C have fitness values of 5, 3, and 2 → A has a 50% chance, B 30%, C 20%.

2. Boltzmann Selection

●​ Inspired by simulated annealing.​

●​ Uses a temperature parameter T that decreases over time.​

●​ High T → random selection (exploration).​

●​ Low T → favors high-fitness individuals (exploitation).​

Example:​
At high T, fitness 100 and 80 are nearly equal; at low T, 100 is clearly preferred.

B. Mutation Operators

1. Random Resetting
●​ Selects one or more genes and replaces them with random values.​

●​ Helps avoid local optima by exploring new regions.​

Example:​
Binary string 1010110 → change a bit → 1011110.

2. Inversion Mutation

●​ Selects a sequence in the chromosome and reverses its order.​

Example:​
1234567 → invert positions 2–5 → 1543267.

3. Scramble Mutation

●​ Selects a subsequence and shuffles its genes randomly.​

Example:​
1234567 → scramble 2–5 → 1534267 (random permutation).

Summary Table

Operator Purpose

Roulette Wheel Select based on fitness

Boltzmann Adaptive selection over


time

Random Local diversity


Resetting

Inversion Reorder genes (mild


change)

Scramble Stronger randomization


Conclusion

Selection chooses the fittest individuals to reproduce. Mutation keeps genetic diversity and
helps explore new solutions. Both are key to the success of genetic algorithms.

🌟 MAIN IDEA​
Instead of tweaking one solution, keep a population of solutions and let them evolve
together to find a very good (often near‑optimal) answer to hard optimization problems ​.

🧱 BASIC CONCEPTS
1.​ Population​
A group of candidate solutions you improve over time.​

2.​ Individual (Chromosome)​


How you encode one solution (e.g., a bit‑string like 1011001) ​.​
3.​ Fitness Function​
A score telling you how good each solution is (higher = better).​

4.​ Operators​

○​ Selection: Pick the stronger individuals to “reproduce.”​

○​ Crossover: Mix two parents (e.g., swap halves of their bit‑strings).​

○​ Mutation: Randomly tweak bits to keep variety. ​

🧠 WHY SOME PROBLEMS ARE HARD


●​ Huge search space: Millions or billions of possible solutions.​

●​ Complex interactions: Changing one bit can have big ripple effects.​

●​ Constraints: Rules you must obey (hard) or prefer (soft).​

●​ Dynamic conditions: The “fitness” might change over time (e.g., traffic patterns).​

🔍 EXAMPLE: Traveling Salesperson (TSP)


●​ Representation: A tour is a list of cities, e.g. [3,1,5,2,4].​

●​ Fitness: Total distance (lower is better).​

●​ Crossover: Pick a cut‑point, swap tails of two tours to make kids.​

●​ Mutation: Swap two cities in the list to get a new route.​

🚚 EXAMPLE: Function Optimization with PSO


●​ Population: Particles, each with a position in space.​
●​ Update rule: Each particle moves toward its own best‑found spot and the swarm’s
best.​

●​ Goal: Find the minimum of a mathematical function.​

🔑 KEY COMPONENTS IN META‑HEURISTICS


●​ Representation → How you describe a solution (bit‑string, real vector,
permutation).​

●​ Objective Function → What you want to optimize (distance, cost, error).​

●​ Fitness Function → Numerical score derived from the objective.​

●​ Neighborhood → Small tweaks you can make (swap two genes, flip one bit).​

●​ Population Size & Parameters → How many solutions to keep,


crossover/mutation rates ​.​

🧰 TYPES OF SEARCH ALGORITHMS



1.​ Exhaustive Search​


Finds the best solution​
Impossible on big problems​

2.​ Backtracking​
Smart pruning of bad branches​

3.​ Heuristic​
Rules of thumb for speed (no optimality guarantee)​

4.​ Meta‑heuristic​
Population + randomness + strategy (e.g., GA, PSO)​

🔥 POPULAR META‑HEURISTIC METHODS (in SBSE and beyond)


●​ Genetic Algorithms (GA)​

●​ Particle Swarm Optimization (PSO)​

●​ Ant Colony Optimization (ACO)​

●​ Simulated Annealing (SA)​

●​ Hill Climbing / Tabu Search ​

🧮 MODELING A PROBLEM (2 STEPS)


1.​ Create a Model​

○​ Encode your problem as chromosomes/particles/etc.​

2.​ Choose a Solver​

○​ Exact small → traditional math/DP.​

○​ Meta‑heuristic big/complex → GA, PSO, ACO… ​.​

🧪 FINAL TIPS
●​ Use meta‑heuristics when exact methods choke on size or complexity.​

●​ Define your fitness clearly—this steers the whole search.​

●​ Pick representations & operators that fit your problem (bits for binary, swaps for
ordering).​

●​ Tune parameters (population size, mutation rate) by small experiments.​

●​ Remember: good & fast > perfect & slow.


🌟 MAIN IDEA​
Single‑solution meta‑heuristics start with one candidate solution and iteratively improve it
by exploring its “neighbors” in the solution space. ​

🧱 BASIC CONCEPTS
1.​ Trajectory (Local) Search​
Handle just one solution at a time, moving it around to find better spots.​

2.​ Neighborhood​
All solutions you can reach by a small tweak (e.g., flip one bit, swap two cities).​

3.​ Objective / Fitness Function​


A formula that scores how good a solution is (higher = better or lower = better,
depending).​

4.​ Exploration vs. Exploitation​


Exploration = trying new areas; exploitation = digging deeper around promising
spots. ​

🧠 WHY THESE MATTER


●​ Fast & Simple: Great when you need a quick, decent answer.​

●​ Easy to Code: Just tweak one solution, no big population bookkeeping.​

●​ Local Optima Risk: Without extra tricks, you can get stuck on a “hill” that isn’t the
highest.​

🔍 KEY ALGORITHMS
1.​ Hill Climbing (HC)​
○​ Idea: From the current solution, jump to the best neighbor until no better
neighbor exists.​

○​ Pros: Very fast; minimal code.​

○​ Cons: Gets stuck in local peaks or flat plateaus.​

○​ Example: Maximize f(x)=−(x−3)²+10. Start at x=0; check x=−1,1; move to 1;


keep moving toward 3 until you can’t improve further. ​

2.​ Tabu Search (TS)​

○​ Idea: Like HC, but keep a “tabu list” of recent moves or solutions so you
don’t cycle back immediately.​

○​ Pros: Can escape small loops and revisit promising regions later.​

○​ Cons: You must choose how many past moves to remember (tabu list size).​

○​ Example: In TSP, if you swapped city A⇄B, mark that swap taboo for the
next 5 moves—forces exploring other swaps. ​

3.​ Simulated Annealing (SA)​

○​ Idea: Like HC but sometimes accept a worse neighbor with probability


e^(−Δ/T), where Δ = fitness drop and T = “temperature” that cools over time.​

○​ Pros: Good at jumping out of local peaks early on.​

○​ Cons: Needs a good cooling schedule (start high, cool slowly enough).​

○​ Example: For f(x)=−(x−3)²+10, at high T you might move from x=3 to x=2
even though worse—later this lets you jump to new peaks. ​

🛠 WORKFLOW TEMPLATE
1.​ Initialize one random solution.​

2.​ Repeat until stopping condition (max steps, no improvement, time limit):​
○​ Generate a neighbor (tweak your single solution).​

○​ Decide to move:​

■​ HC → only if better.​

■​ TS → if not in tabu list (or via aspiration criteria).​

■​ SA → if better, or with probability e^(−Δ/T).​

○​ Update memory (tabu list, temperature).​

3.​ Return the best solution found. ​

✏️ FINAL TIPS
●​ Multi‑start HC: Run hill climbing from different random seeds to avoid bad local
peaks.​

●​ Tune parameters: Tabu list length, initial temperature & cooling rate, neighbor
generation strategy.​

●​ Define neighborhood & fitness clearly—they steer the entire search.​

●​ Remember: the goal is good & fast, not perfect & slow.

You might also like