#uses util.awk table.awk effort.awk risk.awk defects.awk grammar.awk #Data Structure Breakdown #see lib.awk for accessor functions # #model : contains all rules for making rojects including: #ranges/slopes for cocomo attributes (effort mults, scale factors) #ranges/slopes coqualmo defect removal attributes # #project : a generated cocomo project #project[getRating(attr)] = rating of that attribute (1, 2, 3, 4, 5, 6) #project[getTuning(attr)] = tuning value of that attribute's rating (float) #grammar : a set of weighted, rewritable rules for generating a random projects #ex: grammar[getProd("project")] = scalefactors effortmultipliers #cache : the collected projects from multiple runs and their rankings BEGIN { #"globals" gcntr numGenerations = 15 makeArray(model) makeArray(modelRisks) makeArray(grammar) makeArray(project) makeArray(projRisks) makeArray(cache) if (seed) {srand(seed)} else {srand()} if (numRuns) {} else {numRuns = 1000} init(model, grammar) makeArray(savedScores) if(T) #testing much? eg(T, model, grammar) else { gcntr = 1 while (gcntr <= numGenerations) { makeRuns(model, grammar, cache, seed, numRuns) gcntr++ } attrstr = model[getKeys()] split(attrstr,attributes," ") print numGenerations " generations of " numRuns " runs each generation:" >> "results/results-log.txt" for (indx in attributes) { attr = attributes[indx] formatted = grammar[attr] sub(/:1/,"",formatted) printf attr "=" formatted " " >> "results/results-log.txt" } print "\n" >> "results/results-log.txt" #print medians for (i = 1; i <= numGenerations; i++) print i " " savedScores[i] >> "results/"numGenerations"x"numRuns"score-medians.dat" #print spreads for (i = 1; i <= numGenerations; i++) print i " " savedScores[-1 * i] >> "results/"numGenerations"x"numRuns"score-spreads.dat" } } function init(model, grammar) { readModel("grammars/model.txt", model) formalize("grammars/ingrammar.txt", "grammars/outgrammar.txt") readGrammar("grammars/outgrammar.txt", grammar) readRisks("grammars/risks.txt", modelRisks) } #Clear working memory function zap() { split ("",project,"") split ("",projRisks,"") } function makeRuns(model, grammar, cache, seed, numRuns, percentDone,rewritten,\ effort,def,months,scores,score2run,run,cutoff,sortedScores,restRuns,\ bestRuns,BestFreq,RestFreq,indx,i,j,pairs,attr,tmp,value,r,b,avpair,\ avScores,avScoresTotal,attrstr,attributes,attribute,oddstr,attrmin,\ attrmax,freq,newoddstr,freqtotal) { percentDone = 0 for (run = 1; run <= numRuns; run++) { zap() #clear working memory rewritten = rewrite("project") getRatings(rewritten, project) #rating ex: sced = 3 (nominal) getTunings(project, model) #tuning example sced = 0.835123 effort = getEffort(project, model) def = totalDefects(project, model) months = getMonths(effort, project, model) scores[run] = score(effort, def, months, project[getRating("rely")]) cache[run] = rewritten score2run[scores[run]] = run #needed for later proj lookups # print "Run Number: " run " Score: " scores[run] if ( (run % (numRuns/10)) == 0 ) { percentDone += 10 printf percentDone "%..." } } ###TODO: break each of the below sections out after reworking globals #--------------separate into best/rest-------------# asort(scores, sortedScores) #split between rest/best cutoff = numRuns * 0.1 #store the best runs in best and the rest in rest for (j = 1; j <= cutoff; j++) bestRuns[j] = cache[score2run[sortedScores[j]]] for (i = 1; i <= numRuns - cutoff; i++) restRuns[i] = cache[score2run[sortedScores[i+cutoff]]] #-------generate frequency counts for each attr/value pair---------# makeArray(BestFreq) for (indx in bestRuns) { pairs[size()] = split(bestRuns[indx],pairs," ") for (i = 1; i <= pairs[size()]; i++) { split (pairs[i],tmp,"[") value = tmp[1] sub(/\]/,"",tmp[2]) attr = tmp[2] BestFreq[attr,value]++ } } makeArray(RestFreq) for (indx in restRuns) { pairs[size()] = split(restRuns[indx],pairs," ") for (i = 1; i <= pairs[size()]; i++) { split (pairs[i],tmp,"[") value = tmp[1] sub(/\]/,"",tmp[2]) attr = tmp[2] RestFreq[attr,value]++ } } #function scoreAVPair(cache, r,b,avpair,avScores,avScoresTotal) #-------score each avpair------------------------------------------# for (avpair in BestFreq) { r = RestFreq[avpair] b = BestFreq[avpair] avScores[avpair] = (b^2)/(b+r) avScoresTotal += avScores[avpair] } #rewriteGrammar(cache, grammar, attrstr,attributes,indx,attribute,\ # oddstr,attrmin,attrmax,freq,newoddstr,freqtotal,i) { attrstr = model[getKeys()] split(attrstr,attributes," ") for (indx in attributes) { attribute = attributes[indx] oddstr = grammar[attribute] attrmin = model[getRangeMin(attribute)] attrmax = model[getRangeMax(attribute)] makeArray(freq) newoddstr = "" freqtotal = 0 for (i = attrmin; i <= attrmax; i++) { if(BestFreq[attribute,i]) {freq[i] = BestFreq[attribute,i]} else {freq[i] = 0} freqtotal += freq[i] } #make new odds for (i = attrmin; i <= attrmax; i++) { if (freq[i] != 0) { if (newoddstr == "") newoddstr = i ":" freq[i] / freqtotal else newoddstr = newoddstr "|" i ":" freq[i] / freqtotal #mark best current rating if(freq[i] / freqtotal > freq[favorite]) favorite = i } } # print "\n" attribute ":" # print "old odds: " grammar[attribute] # grammar[attribute] = newoddstr # print "new odds: " grammar[attribute] grammar[attribute] = newoddstr print attribute ": " grammar[attribute] } savedScores[gcntr] = sortedScores[numRuns*0.5] savedScores[-1*gcntr] = sortedScores[numRuns*0.75] - sortedScores[numRuns*0.5] print "Run #" gcntr print "median score: "sortedScores[numRuns*0.5] print "score spread: " (sortedScores[numRuns*0.75] - sortedScores[numRuns*0.5]) ##screwing around getRatings(cache[numRuns*0.5],tmpProj) getTunings(tmpProj, model) tmpEffort = getEffort(tmpProj, model) tmpDefects = totalDefects(tmpProj, model) tmpMonths = getMonths(tmpEffort, tmpProj, model) print "median effort: " tmpEffort print "median defects: " tmpDefects print "median months: " tmpMonths print gcntr " " tmpEffort >> "results/"numGenerations"x"numRuns"effort-median.dat" print gcntr " " tmpDefects >> "results/"numGenerations"x"numRuns"defects-median.dat" print gcntr " " tmpMonths*10 >> "results/"numGenerations"x"numRuns"months-x10-median.dat" #------------adjust grammar weights based on avpair scores---------# }