Exemplo n.º 1
0
 def geneticoptimize(self):
     mm = sensitive_path_info.build_m()
     # 初始化种群
     popsize = 30
     pc = 0.85
     pm = 0.1
     datapop = []
     dataM = []
     searchFlag = 0
     for i in range(popsize):
         datapop.append(self.Initial_data(self.varType))
     #评估初始种群
     for data in datapop:
         seq_to_script.runcase(self.tevent, self.pathT, data)  # 执行当前序列
         test_fit, coverage = cal_data_fit.array_spath(
         )  # 获取对各条路径的覆盖情况 test_fit,及完全覆盖路径的覆盖率
         if test_fit[self.objectPathIndex] == 0.0:
             print "满足结果的测试数据为", zip(self.pathT, data)
             searchFlag = 1
             return searchFlag, data
         else:
             if len(test_fit) == 0:  # 构造覆盖矩阵dataM
                 dataM.append(mm)
             else:
                 dataM.append(test_fit)
     iteration = 0
     while iteration <= 500:
         temp = copy.deepcopy(datapop)  # 保留父代
         oldM = dataM
         # 选择
         selectpop = self.selection(datapop, dataM)
         # 交叉
         crosspop = self.crossover(selectpop, pc)
         # 变异
         mutanpop = self.mutantion(crosspop, pm)
         # 评估新种群
         dataM = []
         for data in mutanpop:
             seq_to_script.runcase(self.tevent, self.pathT, data)  # 执行当前序列
             test_fit, coverage = cal_data_fit.array_spath(
             )  # 获取对各条路径的覆盖情况 test_fit,及完全覆盖路径的覆盖率
             if test_fit[self.objectPathIndex] == 0.0:
                 print "满足结果的测试数据为", data
                 searchFlag = 1
                 return searchFlag, zip(self.pathT, data)
             else:
                 if len(test_fit) == 0:  # 构造覆盖矩阵dataM
                     dataM.append(mm)
                 else:
                     dataM.append(test_fit)
         # 更新
         datapop = self.updata(temp, mutanpop, oldM, dataM, popsize)
         iteration += 1
Exemplo n.º 2
0
def array_spath():
    pbdict, pcdict = hand_instru()  # schoolmate,faqforge
    # pbdict, pcdict = hand_instru_webchess() #webchess
    path_fit = judge_new(pcdict, pbdict)
    spath = sensitive_path_info.obtain_spath()
    m = sensitive_path_info.build_m()
    # print "m",m
    for key in path_fit:
        # print "path_fit_key",key
        index = spath.index(key)
        # print "index in spath"
        # print index
        m[index] = path_fit[key]
    t= m.count(0.0)
    covrage = t / len(m)
    print m,t,"个体覆盖率",covrage
    return m,covrage  #返回该个体对各条路径的覆盖情况matrix,及完全覆盖路径的覆盖率
Exemplo n.º 3
0
#encoding:utf-8
from __future__ import division
import recordFun
import generate_data_ga  #数据生成器-----序列上的变量产生数据
import sensitive_path_info
mm = sensitive_path_info.build_m()
# uncp = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
def table_handle(M):
    # 所有敏感路径入口点检测:pot = 1已完全覆盖所有的入口点;pot =0为未完全覆盖
    # 方法:查看table中是不是至少每一列都有一个在[0,1]之间的个体
    # 所有敏感路径完全覆盖检测:flag = 1为完全覆盖;flag=0为未完全覆盖。
    # 方法:查看二维表中的0是否已全覆盖上所有的敏感路径,每一列至少有一个0
    count = 0
    count1 = 0
    flag = 0
    pot = 0
    uncoverp = []
    potlist = []
    statistic = []
    print "M ==",len(M)
    for i in range(len(M)):
        # print len(M[i])
        print M[i]
    for k in range(len(M[0])):
        # print "第",k,"条路径"
        for j in range(len(M)):
            # print "第", j, "个测试用例的fit值",M[j][k]
            # print "table[j][k]", table[j][k]
            if M[j][k] == 0.0:  #table里面的fit值都是浮点数
                count = count + 1
            if M[j][k] >=0.0 and M[j][k] < 2:   # 这里实际上是<=2,cal_data_fit时,忘记归一化了,先这样