#!/usr/bin/gawk -f BEGIN { FS = OFS = ","; Seed = 1; Best = 10; TotalMitigations = 31; Debug = 0; #1 is to show the final results. 2 is to show the debug stuff. 3 is to show the 25% to 75% values. } END { #start init stuff srand(Seed); m[0] = TotalMitigations; Results[0] = 2; #set all mitigations to non-fixed value of -1 for (mCounter = 1; mCounter <= m[0]; mCounter++) FixedMitigations[mCounter] = -1; #end init stuff for (round = 1; round <= TotalMitigations; round++) { TotalInstances = 0; MinCost = 10^20; MaxCost = -(10^20); MinAtt = 10^20; MaxAtt = -(10^20); for (run = 1; run <= 500; run++) { for (mCounter = 1; mCounter <= m[0]; mCounter++) { #if in the previous runs the mitigation is fixed to a certain value (0 or 1) then use that value. otherwise, select it at random if (FixedMitigations[mCounter] == -1) m[mCounter] = select(0,1); else m[mCounter] = FixedMitigations[mCounter]; } #find the cost and att using these mitigations model(Results); #store the current instance addInstance(Results); } #the previousMinAtt allows improving the att each time previousMinAtt = MinAtt; #find the sweet spot and distances from sweet spot for each distance sweetSpot(); #rank the mitigations and find the mitigation that should be fixed rankMitigations(); #report some of the results if (Debug == 3) report(); #prepare for the next round delete Data; delete Distance; } #show the final results if (Debug == 1) { for (mCounter = 1; mCounter <= m[0]; mCounter++) m[mCounter] = FixedMitigations[mCounter]; model(Results); print "final results using these mitigations are:" for (i=1; i<=m[0]; i++) printf("%s,",m[i]); print " with cost = " Results[1] " and attainment = " Results[2]; } } function report(tempCostArray,tempAttArray) { # thirdQCost = (MaxCost - MinCost) * 3 / 4 + MinCost; # meanCost = (MaxCost - MinCost) / 2 + MinCost; # spreadCost = thirdQCost - meanCost; # thirdQAtt = (MaxAtt - MinAtt) * 3 / 4 + MinAtt; # meanAtt = (MaxAtt - MinAtt) / 2 + MinAtt; # spreadAtt = thirdQAtt - meanAtt; # print round,meanCost,spreadCost,meanAtt,spreadAtt; for (instanceCounter = 1; instanceCounter <= TotalInstances; instanceCounter++) { tempCostArray[instanceCounter] = Data[instanceCounter,1]; tempAttArray[instanceCounter] = Data[instanceCounter,2]; } nCost = asort(tempCostArray); nAtt = asort(tempAttArray); print round,tempCostArray[nCost/2],tempCostArray[3*nCost/4]-tempCostArray[nCost/2],tempAttArray[nAtt/2],tempAttArray[3*nAtt/4]-tempAttArray[nAtt/2]; } function rankMitigations(tempDistanceArray,tempBestFreqCount,tempRestFreqCount,tempScoreOff,tempScoreOn) { asort(Distance,tempDistanceArray); bestValue = tempDistanceArray[Best]; for (instanceCounter = 1; instanceCounter <= TotalInstances; instanceCounter++) { if (Debug == 2){ for (i=1; i<=m[0]; i++) printf("%s,",Data[instanceCounter,i+2]); printf("%s,%s,\t", Data[instanceCounter,1],Data[instanceCounter,2]);} #if it is in the Best distance from the sweet spot, count the frequency of each mitigation (0 and 1) for the best instances if (Distance[instanceCounter] <= bestValue) { if (Debug == 2) print Distance[instanceCounter] " --> best from " bestValue; for (mCounter = 1; mCounter <= m[0]; mCounter++) { #keep track of the mitigation's counts if it is not already fixed if (FixedMitigations[mCounter] == -1) { if (Data[instanceCounter,mCounter+2] == 0) tempBestFreqCount[mCounter,0]++; else if (Data[instanceCounter,mCounter+2] == 1) tempBestFreqCount[mCounter,1]++; } } } #else it is in the Rest distance from the sweet spot and so count the frequency of each mitigation (0 and 1) for the rest instances else { if (Debug == 2) print Distance[instanceCounter] " --> rest from " bestValue; for (mCounter = 1; mCounter <= m[0]; mCounter++) { #keep track of the mitigation's counts if it is not already fixed if (FixedMitigations[mCounter] == -1) { if (Data[instanceCounter,mCounter+2] == 0) tempRestFreqCount[mCounter,0]++; else if (Data[instanceCounter,mCounter+2] == 1) tempRestFreqCount[mCounter,1]++; } } } } maxScore = -(10^20); maxScoredMitigation = 0; maxScoredMitigationStatus = -1; #normalize each frequency count by dividing it by the total number of instances and score each mitigation using the best^2/(best+rest) and keep min and max for (mCounter = 1; mCounter <= m[0]; mCounter++) { #do this only if mitigation is not fixed already if (FixedMitigations[mCounter] == -1) { #find the score of the mitigation when it is off best = tempBestFreqCount[mCounter,0]/TotalInstances; rest = tempRestFreqCount[mCounter,0]/TotalInstances; if (best == 0 && rest == 0) tempScoreOff[mCounter] = 0; else tempScoreOff[mCounter] = best^2/(best+rest); if (Debug == 2) print "m"mCounter " with 0 has best: "best " and rest: "rest; #keep its information if it is the max score seen so far if (tempScoreOff[mCounter] > maxScore) { maxScore = tempScoreOff[mCounter]; maxScoredMitigation = mCounter; maxScoredMitigationStatus = 0; } #find the score of the mitigation when it is on best = tempBestFreqCount[mCounter,1]/TotalInstances; rest = tempRestFreqCount[mCounter,1]/TotalInstances; if (best == 0 && rest == 0) tempScoreOn[mCounter] = 0; else tempScoreOn[mCounter] = best^2/(best+rest); if (Debug == 2) print "m"mCounter " with 1 has best: "best " and rest: "rest; #keep its information if it is the max score seen so far if (tempScoreOn[mCounter] > maxScore) { maxScore = tempScoreOn[mCounter]; maxScoredMitigation = mCounter; maxScoredMitigationStatus = 1; } if (Debug == 2) print "m"mCounter " for being 0 has score: " tempScoreOff[mCounter] " and for being 1 has score: "tempScoreOn[mCounter]; } } if (Debug == 2) print "chosen mitigation is m"maxScoredMitigation " with status " maxScoredMitigationStatus " has score " maxScore; FixedMitigations[maxScoredMitigation] = maxScoredMitigationStatus; } function sweetSpot() { if (Debug == 2) print "cost max = " MaxCost " and min = " MinCost; if (Debug == 2) print "att max = " MaxAtt " and min = " MinAtt; #normalize the att and cost using their for (instanceCounter = 1; instanceCounter <= TotalInstances; instanceCounter++) { if (Data[instanceCounter,1] < 5000) { #calculate the normalized cost and att (if max and min are the same, the small numbers added allow the distance to be correct) normalizedCost = (Data[instanceCounter,1] - MinCost)/(MaxCost - MinCost + 10^(-20)); normalizedAtt = (Data[instanceCounter,2] - MinAtt + 10^(-20))/(MaxAtt - MinAtt + 10^(-20)); #distance of each instance is measured from normalized (cost=0,att=1) which is the sweet spot Distance[instanceCounter] = sqrt(((normalizedCost - 0)^2 + (normalizedAtt - 1)^2)/2); } else Distance[instanceCounter] = sqrt(2); } } function addInstance(resultsArray) { TotalInstances++; #this is the cost Data[TotalInstances,1] = resultsArray[1]; #this is the att Data[TotalInstances,2] = resultsArray[2]; for (mCounter = 1; mCounter <= m[0]; mCounter++) Data[TotalInstances,mCounter+2] = m[mCounter]; if (MinCost > Data[TotalInstances,1]) MinCost = Data[TotalInstances,1]; if (MaxCost < Data[TotalInstances,1]) MaxCost = Data[TotalInstances,1]; if (MinAtt > Data[TotalInstances,2]) MinAtt = Data[TotalInstances,2]; if (MaxAtt < Data[TotalInstances,2]) MaxAtt = Data[TotalInstances,2]; } function select(val1,val2) { if (rand() < 0.5) return val1; else return val2; } function model(resultsArray) { mCost[1]= 100; mCost[2]= 75; mCost[3]= 1250; mCost[4]= 2600; mCost[5]= 2000; mCost[6]= 900; mCost[7]= 2500; mCost[8]= 0; mCost[9]= 0; mCost[10]= 200; mCost[11]= 10000; mCost[12]= 1000; mCost[13]= 100; mCost[14]= 0; mCost[15]= 0; mCost[16]= 0; mCost[17]= 25; mCost[18]= 800; mCost[19]= 25; mCost[20]= 750; mCost[21]= 0; mCost[22]= 2000; mCost[23]= 100; mCost[24]= 25; mCost[25]= 25; mCost[26]= 2000; mCost[27]= 75; mCost[28]= 75; mCost[29]= 100; mCost[30]= 0; mCost[31]= 40; rAPL[1]=1; rAPL[2]=1; rAPL[3]=1; rAPL[4]=1; rAPL[5]=1; rAPL[6]=1; rAPL[7]=1; rAPL[8]=1; rAPL[9]=1; rAPL[10]=1; rAPL[11]=1; rAPL[12]=1; rAPL[13]=1; rAPL[14]=1; rAPL[15]=1; rAPL[16]=1; rAPL[17]=1; rAPL[18]=1; rAPL[19]=1; rAPL[20]=1; rAPL[21]=1; rAPL[22]=1; rAPL[23]=1; rAPL[24]=1; rAPL[25]=1; rAPL[26]=1; rAPL[27]=1; rAPL[28]=1; rAPL[29]=1; rAPL[30]=1; oWeight[1]=1; roImpact[1,1] = 0.3; roImpact[2,1] = 0.9; roImpact[4,1] = 0.3; roImpact[10,1] = 0.7; roImpact[15,1] = 0.7; roImpact[17,1] = 0.9; roImpact[18,1] = 0.7; roImpact[19,1] = 0.1; roImpact[20,1] = 0.7; roImpact[21,1] = 0.1; roImpact[22,1] = 0.3; roImpact[25,1] = 0.9; roImpact[26,1] = 0.7; roImpact[28,1] = 0.3; roImpact[29,1] = 0.3; roImpact[30,1] = 0.1; mrEffect[4,1] = 0.7; mrEffect[5,1] = 0.1; mrEffect[6,1] = 0.3; mrEffect[13,1] = 0.1; mrEffect[16,1] = 0.7; mrEffect[22,1] = 0.3; mrEffect[23,1] = 0.3; mrEffect[1,2] = 0.3; mrEffect[2,2] = 0.1; mrEffect[3,2] = 0.3; mrEffect[4,2] = 0.3; mrEffect[5,2] = 0.3; mrEffect[6,2] = 0.3; mrEffect[7,2] = 0.3; mrEffect[11,2] = 0.3; mrEffect[12,2] = 0.7; mrEffect[22,2] = 0.3; mrEffect[26,2] = 0.9; mrEffect[31,2] = 0.9; mrEffect[5,3] = 0.1; mrEffect[5,4] = 0.1; mrEffect[6,4] = 0.9; mrEffect[13,4] = 0.9999; mrEffect[23,4] = 0.9; mrEffect[31,4] = 0.9; mrEffect[2,5] = 0.7; mrEffect[3,5] = 0.3; mrEffect[7,5] = 0.3; mrEffect[13,6] = 0.9; mrEffect[2,7] = 0.7; mrEffect[7,7] = 0.4; mrEffect[12,7] = 0.3; mrEffect[3,8] = 0.1; mrEffect[7,8] = 0.3; mrEffect[12,8] = 0.7; mrEffect[11,9] = 0.1; mrEffect[17,9] = 0.3; mrEffect[18,9] = 0.7; mrEffect[5,10] = 0.3; mrEffect[26,10] = 0.9; mrEffect[31,10] = 0.3; mrEffect[4,11] = 0.1; mrEffect[5,11] = 0.1; mrEffect[13,11] = 0.3; mrEffect[2,15] = 0.1; mrEffect[5,15] = 0.1; mrEffect[6,15] = 0.1; mrEffect[13,15] = 1; mrEffect[23,15] = 0.3; mrEffect[1,16] = 0.1; mrEffect[10,16] = 0.7; mrEffect[15,16] = 0.3; mrEffect[2,17] = 0.1; mrEffect[5,17] = 0.3; mrEffect[13,17] = 0.3; mrEffect[23,17] = 0.9; mrEffect[10,18] = 0.1; mrEffect[13,18] = 0.7; mrEffect[24,18] = 0.9; mrEffect[1,19] = 0.1; mrEffect[2,19] = 0.3; mrEffect[3,19] = 0.7; mrEffect[4,19] = 0.1; mrEffect[5,19] = 0.1; mrEffect[6,19] = 0.3; mrEffect[7,19] = 0.7; mrEffect[13,19] = 0.3; mrEffect[31,19] = 0.7; mrEffect[5,20] = 0.3; mrEffect[8,20] = 0.3; mrEffect[9,20] = 0.7; mrEffect[20,20] = 0.2; mrEffect[27,20] = 0.7; mrEffect[3,21] = 0.3; mrEffect[13,21] = 0.1; mrEffect[26,21] = 0.9; mrEffect[31,21] = 0.3; mrEffect[5,22] = 0.1; mrEffect[13,22] = 0.9; mrEffect[22,22] = 0.3; mrEffect[1,23] = 0.1; mrEffect[2,23] = 0.1; mrEffect[3,23] = 0.1; mrEffect[6,23] = 0.1; mrEffect[11,23] = 0.1; mrEffect[12,23] = 0.3; mrEffect[26,23] = 0.3; mrEffect[2,24] = 0.3; mrEffect[3,24] = 0.3; mrEffect[19,24] = 0.9; mrEffect[26,24] = 0.7; mrEffect[5,25] = 0.9; mrEffect[6,25] = 0.7; mrEffect[22,25] = 0.3; mrEffect[25,25] = 0.9; mrEffect[13,26] = 0.1; mrEffect[26,26] = 0.1; mrEffect[27,26] = 0.3; mrEffect[28,26] = 0.7; mrEffect[29,26] = 0.3; mrEffect[30,26] = 0.7; mrEffect[31,26] = 0.7; mrEffect[3,27] = 0.1; mrEffect[12,27] = 0.7; mrEffect[1,28] = 0.7; mrEffect[2,28] = 0.7; mrEffect[3,28] = 0.3; mrEffect[7,28] = 0.7; mrEffect[12,28] = 0.3; mrEffect[13,28] = 0.8; mrEffect[31,28] = 0.3; mrEffect[1,29] = 0.1; mrEffect[3,29] = 0.1; mrEffect[7,29] = 0.1; mrEffect[12,29] = 0.7; mrEffect[13,29] = 0.7; mrEffect[1,30] = 0.3; mrEffect[2,30] = 0.1; mrEffect[3,30] = 0.1; mrEffect[4,30] = 0.3; mrEffect[6,30] = 0.7; mrEffect[7,30] = 0.3; mrEffect[11,30] = 0.1; mrEffect[12,30] = 0.9; mrEffect[14,30] = 0.7; mrEffect[21,30] = 0.3; mrEffect[22,30] = 0.3; mrEffect[31,30] = 0.3; rLikelihood[1] = rAPL[1] * (1 - m[4] * mrEffect[4,1]) * (1 - m[5] * mrEffect[5,1]) * (1 - m[6] * mrEffect[6,1]) * (1 - m[13] * mrEffect[13,1]) * (1 - m[16] * mrEffect[16,1]) * (1 - m[22] * mrEffect[22,1]) * (1 - m[23] * mrEffect[23,1]); rLikelihood[2] = rAPL[2] * (1 - m[1] * mrEffect[1,2]) * (1 - m[2] * mrEffect[2,2]) * (1 - m[3] * mrEffect[3,2]) * (1 - m[4] * mrEffect[4,2]) * (1 - m[5] * mrEffect[5,2]) * (1 - m[6] * mrEffect[6,2]) * (1 - m[7] * mrEffect[7,2]) * (1 - m[11] * mrEffect[11,2]) * (1 - m[12] * mrEffect[12,2]) * (1 - m[22] * mrEffect[22,2]) * (1 - m[26] * mrEffect[26,2]) * (1 - m[31] * mrEffect[31,2]); rLikelihood[3] = rAPL[3] * (1 - m[5] * mrEffect[5,3]); rLikelihood[4] = rAPL[4] * (1 - m[5] * mrEffect[5,4]) * (1 - m[6] * mrEffect[6,4]) * (1 - m[13] * mrEffect[13,4]) * (1 - m[23] * mrEffect[23,4]) * (1 - m[31] * mrEffect[31,4]); rLikelihood[5] = rAPL[5] * (1 - m[2] * mrEffect[2,5]) * (1 - m[3] * mrEffect[3,5]) * (1 - m[7] * mrEffect[7,5]); rLikelihood[6] = rAPL[6] * (1 - m[13] * mrEffect[13,6]); rLikelihood[7] = rAPL[7] * (1 - m[2] * mrEffect[2,7]) * (1 - m[7] * mrEffect[7,7]) * (1 - m[12] * mrEffect[12,7]); rLikelihood[8] = rAPL[8] * (1 - m[3] * mrEffect[3,8]) * (1 - m[7] * mrEffect[7,8]) * (1 - m[12] * mrEffect[12,8]); rLikelihood[9] = rAPL[9] * (1 - m[11] * mrEffect[11,9]) * (1 - m[17] * mrEffect[17,9]) * (1 - m[18] * mrEffect[18,9]); rLikelihood[10] = rAPL[10] * (1 - m[5] * mrEffect[5,10]) * (1 - m[26] * mrEffect[26,10]) * (1 - m[31] * mrEffect[31,10]); rLikelihood[11] = rAPL[11] * (1 - m[4] * mrEffect[4,11]) * (1 - m[5] * mrEffect[5,11]) * (1 - m[13] * mrEffect[13,11]); rLikelihood[12] = rAPL[12]; rLikelihood[13] = rAPL[13]; rLikelihood[14] = rAPL[14]; rLikelihood[15] = rAPL[15] * (1 - m[2] * mrEffect[2,15]) * (1 - m[5] * mrEffect[5,15]) * (1 - m[6] * mrEffect[6,15]) * (1 - m[13] * mrEffect[13,15]) * (1 - m[23] * mrEffect[23,15]); rLikelihood[16] = rAPL[16] * (1 - m[1] * mrEffect[1,16]) * (1 - m[10] * mrEffect[10,16]) * (1 - m[15] * mrEffect[15,16]); rLikelihood[17] = rAPL[17] * (1 - m[2] * mrEffect[2,17]) * (1 - m[5] * mrEffect[5,17]) * (1 - m[13] * mrEffect[13,17]) * (1 - m[23] * mrEffect[23,17]); rLikelihood[18] = rAPL[18] * (1 - m[10] * mrEffect[10,18]) * (1 - m[13] * mrEffect[13,18]) * (1 - m[24] * mrEffect[24,18]); rLikelihood[19] = rAPL[19] * (1 - m[1] * mrEffect[1,19]) * (1 - m[2] * mrEffect[2,19]) * (1 - m[3] * mrEffect[3,19]) * (1 - m[4] * mrEffect[4,19]) * (1 - m[5] * mrEffect[5,19]) * (1 - m[6] * mrEffect[6,19]) * (1 - m[7] * mrEffect[7,19]) * (1 - m[13] * mrEffect[13,19]) * (1 - m[31] * mrEffect[31,19]); rLikelihood[20] = rAPL[20] * (1 - m[5] * mrEffect[5,20]) * (1 - m[8] * mrEffect[8,20]) * (1 - m[9] * mrEffect[9,20]) * (1 - m[20] * mrEffect[20,20]) * (1 - m[27] * mrEffect[27,20]); rLikelihood[21] = rAPL[21] * (1 - m[3] * mrEffect[3,21]) * (1 - m[13] * mrEffect[13,21]) * (1 - m[26] * mrEffect[26,21]) * (1 - m[31] * mrEffect[31,21]); rLikelihood[22] = rAPL[22] * (1 - m[5] * mrEffect[5,22]) * (1 - m[13] * mrEffect[13,22]) * (1 - m[22] * mrEffect[22,22]); rLikelihood[23] = rAPL[23] * (1 - m[1] * mrEffect[1,23]) * (1 - m[2] * mrEffect[2,23]) * (1 - m[3] * mrEffect[3,23]) * (1 - m[6] * mrEffect[6,23]) * (1 - m[11] * mrEffect[11,23]) * (1 - m[12] * mrEffect[12,23]) * (1 - m[26] * mrEffect[26,23]); rLikelihood[24] = rAPL[24] * (1 - m[2] * mrEffect[2,24]) * (1 - m[3] * mrEffect[3,24]) * (1 - m[19] * mrEffect[19,24]) * (1 - m[26] * mrEffect[26,24]); rLikelihood[25] = rAPL[25] * (1 - m[5] * mrEffect[5,25]) * (1 - m[6] * mrEffect[6,25]) * (1 - m[22] * mrEffect[22,25]) * (1 - m[25] * mrEffect[25,25]); rLikelihood[26] = rAPL[26] * (1 - m[13] * mrEffect[13,26]) * (1 - m[26] * mrEffect[26,26]) * (1 - m[27] * mrEffect[27,26]) * (1 - m[28] * mrEffect[28,26]) * (1 - m[29] * mrEffect[29,26]) * (1 - m[30] * mrEffect[30,26]) * (1 - m[31] * mrEffect[31,26]); rLikelihood[27] = rAPL[27] * (1 - m[3] * mrEffect[3,27]) * (1 - m[12] * mrEffect[12,27]); rLikelihood[28] = rAPL[28] * (1 - m[1] * mrEffect[1,28]) * (1 - m[2] * mrEffect[2,28]) * (1 - m[3] * mrEffect[3,28]) * (1 - m[7] * mrEffect[7,28]) * (1 - m[12] * mrEffect[12,28]) * (1 - m[13] * mrEffect[13,28]) * (1 - m[31] * mrEffect[31,28]); rLikelihood[29] = rAPL[29] * (1 - m[1] * mrEffect[1,29]) * (1 - m[3] * mrEffect[3,29]) * (1 - m[7] * mrEffect[7,29]) * (1 - m[12] * mrEffect[12,29]) * (1 - m[13] * mrEffect[13,29]); rLikelihood[30] = rAPL[30] * (1 - m[1] * mrEffect[1,30]) * (1 - m[2] * mrEffect[2,30]) * (1 - m[3] * mrEffect[3,30]) * (1 - m[4] * mrEffect[4,30]) * (1 - m[6] * mrEffect[6,30]) * (1 - m[7] * mrEffect[7,30]) * (1 - m[11] * mrEffect[11,30]) * (1 - m[12] * mrEffect[12,30]) * (1 - m[14] * mrEffect[14,30]) * (1 - m[21] * mrEffect[21,30]) * (1 - m[22] * mrEffect[22,30]) * (1 - m[31] * mrEffect[31,30]); oAtRiskProp[1] = (rLikelihood[1] * roImpact[1,1]) + (rLikelihood[2] * roImpact[2,1]) + (rLikelihood[4] * roImpact[4,1]) + (rLikelihood[10] * roImpact[10,1]) + (rLikelihood[15] * roImpact[15,1]) + (rLikelihood[17] * roImpact[17,1]) + (rLikelihood[18] * roImpact[18,1]) + (rLikelihood[19] * roImpact[19,1]) + (rLikelihood[20] * roImpact[20,1]) + (rLikelihood[21] * roImpact[21,1]) + (rLikelihood[22] * roImpact[22,1]) + (rLikelihood[25] * roImpact[25,1]) + (rLikelihood[26] * roImpact[26,1]) + (rLikelihood[28] * roImpact[28,1]) + (rLikelihood[29] * roImpact[29,1]) + (rLikelihood[30] * roImpact[30,1]); oAttainment[1] = oWeight[1] * (1 - minValue(1, oAtRiskProp[1])); attTotal = oAttainment[1]; costTotal = 1710 + m[1] * mCost[1] + m[2] * mCost[2] + m[3] * mCost[3] + m[4] * mCost[4] + m[5] * mCost[5] + m[6] * mCost[6] + m[7] * mCost[7] + m[8] * mCost[8] + m[9] * mCost[9] + m[10] * mCost[10] + m[11] * mCost[11] + m[12] * mCost[12] + m[13] * mCost[13] + m[14] * mCost[14] + m[15] * mCost[15] + m[16] * mCost[16] + m[17] * mCost[17] + m[18] * mCost[18] + m[19] * mCost[19] + m[20] * mCost[20] + m[21] * mCost[21] + m[22] * mCost[22] + m[23] * mCost[23] + m[24] * mCost[24] + m[25] * mCost[25] + m[26] * mCost[26] + m[27] * mCost[27] + m[28] * mCost[28] + m[29] * mCost[29] + m[30] * mCost[30] + m[31] * mCost[31]; resultsArray[1] = costTotal; resultsArray[2] = attTotal; } function minValue(val1,val2) { if (val1 < val2) return val1; else return val2; }