0

I recently started working with genetic algorithm, and to understand it better, I decided to use it to solve a problem. I'm working on using genetic algorithm to generate test cases for a path testing question. I have everything figured out, except for how to choose the best fitness function. So, I could use some help :)

Here is an overview of my problem: In each generation, 100 test cases are being generated. Each path in the CFG has been assigned a weight, depending on how rare the test cases for that path are. For example, take the following CFG:

enter image description here

There are 4 independent paths. Let's say the weights of the path are as follows-

Path 1: 10

Path 2: 5

Path 3: 4

Path 4: 5

Right now, for each test case in the generation, I'm considering the avg fitness the entire generation can have.

(10*100 - 4*100)/2 = 300 [Since there are 100 test cases]

So, I'm diving the weight of that test case (the weight of the path which it covers) by 300. Although the result is satisfactory, the logic for this is extremely flawed. I think a better fitness function, so that the fitness of the test case is directly proportional to the weight of the path it covers, would be the weight divided by the sum of the weights of all paths. So for this problem,

w/(10+5+5+4) = w/24

What do you think would be a better approach to calculate the fitness of each test case?

  1. w/300

  2. w/24

Or would you suggest a completely different approach? Can a better fitness function be generated for this problem?

I would be grateful for your help :)

Kruti Joshi
  • 384
  • 3
  • 16
  • I cannot understand the problem statement you specified. The population that you are generating at each generation(the test cases), does it contain randomly generated path? So, that would mean you are generating 100 paths at each generation. Also, are you trying to minimize the cost or maximize the cost(this would be the fitness)? Please clarify these. – Shubhashis May 01 '16 at 17:03
  • Yes the population contains randomly generated paths. And I'm trying to maximize the fitness. – Kruti Joshi May 01 '16 at 18:33
  • In order to help, I need to understand if you are actually doing **Genetic Programming** or using a **Genetic Algorithm**. Could you let me know what is your final output? Is it a set of shortest paths for a given set of graphs, or is it a Program that's applicable to any graph with similar characteristics? Another way to think about it: Do you intend to do a Genetic Search every time you need to Solve a shortest path problem or do you intend to find a "General Solution" that you can code? ...Let me know... – Milton Hernandez Jul 20 '16 at 14:04
  • Also, if the goal is to use GA to generate test cases, what's the **main characteristic** you want for those cases to have? In other words, what makes for a "good test case" in your problem space? – Milton Hernandez Jul 20 '16 at 14:08

0 Answers0