#---------------------------------------------------------------------------# # File Name: MMS.awk # # Description: This awk program converts Markov diagrams into mathematica # # equations. Given input files with two sections: transitional and # # proability, this program outputs MTTDL and Variance equations in # # mathematica notation. # # Usage: awk -f MMS.awk # # # # University Of California, San Diego # # Computer Science Department # # Designer: Andrew H. Nguyen # # Course: Storage System 228B # # Last Modified: June 6, 1997 # #---------------------------------------------------------------------------# BEGIN { error = 0 numOfColumn = 0 initRow = 0 startProb = 0 startTrans = 0 probCounter = 0 mIsEmpty = 1 } 1 == 1 { if (NF == 0) next } /^[ \t]*[bB][eE][gG][iI][nN][ \t]+[pP][rR][oO][bB][aA][bB][iI][lL][iI][tT][yY]/ && (startProb == 0) { startProb = 1;next } /^[ \t]*[eE][nN][dD][ \t]+[pP][rR][oO][bB][aA][bB][iI][lL][iI][tT][yY]/ && (startProb == 1) { startProb = 2;next } /^[ \t]*[bB][eE][gG][iI][nN][ \t]+[tT][rR][aA][nN][sS][iI][tT][iI][oO][nN]/ && (startTrans == 0) { startTrans = 1;next } /^[ \t]*[eE][nN][dD][ \t]+[tT][rR][aA][nN][sS][iI][tT][iI][oO][nN]/ && (startTrans == 1) { startTrans = 2;next } startProb == 1 { if (NF < 2) { print "Error: Invalid probability entry." print "Line " NR ": " $0 error = 1 exit } if (probMatrix[$1] != "") { print "Error: Duplication of probability entry." print "Line " NR ": " $0 error = 1 exit } tempStr = $2 for(i = 3;i 1 ) { print "Error: There exist multiple failure states.";exit } if (startProb == 0) { print "Error: No probability section found.";exit} for (item in diag) diag[item] = "-(" diag[item] ")" for (item in diag1) diag1[item] = "S + (" diag1[item] ")" numOfState = 0 for (curState in states) numOfState++ i = 0 for (curState in states) { i++ pValue = "" p1Value = "" for (curColumn in states) { if (input[curColumn curState] == "") input[curColumn curState] = 0 if (curState == curColumn) { pValue = pValue ", " diag[curState] p1Value = p1Value ", " diag1[curState] } else { pValue = pValue ", " input[curColumn curState] p1Value = p1Value ", " input[curColumn curState] } } numOfColumn++ M[numOfColumn] = "{ " substr(pValue,3,length(pValue)) " }" VarM[numOfColumn] = "{ " substr(p1Value,3,length(p1Value)) " }" P[numOfColumn] = curState if (probMatrix[P[numOfColumn]] == "") { print "Error: No probability value for state " P[numOfColumn]"." ; exit } } print "M = {" print "\t "M[1] for (i = 2; i0]) . VarOneMatrix" print "MTTDL = Simplify[- OneMatrix . Inverse[M] . Prob]" print "Variance = Simplify[SecondMoment - MTTDL^2]" }