Fault Tree Algorithm introduction:
[A typographical problem occurs. Click view plain at the top of the code box to view the code]
For the calculation of the minimum cut set of a fault tree like Figure 1, my idea is to use the downlink method and the prime number method:
Figure 1 Fault Tree
The basic principle of the so-called downlink method is to increase the number of cutover sets in the fault tree or door, and increase the capacity of the cutover set in the door. Starting from the top event of the fault tree, from top to bottom, we replace the top-level event with the next-level event in sequence. When we encounter an event, we write it horizontally in parallel with the door. When we encounter an event or door, we write the input event vertically in series, until all the logic gates are replaced with the bottom event, the last column represents all the cut sets. The cut set absorbs the smallest cut set and uses the prime number method. The idea is to assign a prime number to each bottom event, the cut set Division removes the cut set that can be used as the divisor to obtain the minimum cut set. This part is easy to implement without further explanation. The specific analysis steps are shown in table 1:
Table 1 minimum cutover set analysis procedure
The following are some definitions of data storage, and the calculation process in an instance [This was edited later. I am sorry to have read it before]
[I don't understand how the csdn editing function is so bad.] lines-are manually edited, and there are still problems. It's crazy...
If you do not want to complete the process, you can directly upload the source code. For more information, see [http://download.csdn.net/detail/conquerwave/5713163].
/** To change this template, choose tools | templates * and open the template in the editor. * Author: inmen. wang * mail: hugewave@yeah.net * build Date: 2012.11.25 * Last EDIT: 2012.11.27 */package mytree; /***** @ author inmen *//***************************** * ****** the mytree () function that needs to be called externally in the current class () initialize this class and allocate space for each data. setsubtree () passes the required parameters for processing to setlabelname () of this object and passes the required parameters for processing to settreemap () of this object () pass the parameters required for processing to getfat () of this object to obtain the minimum cut set getfat_n () after processing () obtain the minimum number of cut sets after processing ********************************* * **/public class mytree {// Private Static int counter = 0; private Static int subtree; // how many sub-trees are saved: Private Static string [] label = new string [100]; // The node name should be Private Static int [] [] treemap = new int [100] [50]; // Save the corresponding relationship of the tree. Private Static int [] [] subnode = new int [500] [100]; // save all cutover sets without duplicates, remove Private Static int [] [] middletable = new int [100] [20]; Private Static int middletable_n; Private Static int subnode_n; // subnode) number of Cut Sets Private Static int [] [] subnode_sole = new int [400] [20]; // save all cut sets, remove duplicates, remove Private Static int subnode_sole_n by prime number; // Number of subnode_sole cut sets corresponding to the record Private Static int [] [] subnode_result = new int [300] [20]; // save all cut sets, the maximum result is Private Static int subnode_result_n; // The number of subnode_result cut sets corresponding to the record. Private Static int [] [] subnode_ouput = new int [100] [50]; private Static int subnode_output_n; Private Static int [] Prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};/*** @ Param ARGs the command line arguments */public static void main (string [] ARGs) {/************************************** **************************************** * *************************** sample data * int subt = 13; int [] [] tree; tree = new int [] [] {2,-1, 1, 11}, // 0 {3,-2, 2, 3, 4}, // 1 {2,-1, 5, 6}, // 2 {2,-1, 7, 8}, // 3 {2,-1, 9, 10}, // 4 {0, 0}, // 5 {0, 0}, // 6 {0, 0}, // 7 {0, 0}, // 8 {0, 0}, // 9 {0, 0}, // 10 {2,-2, 12, 13 }, // 11 {0, 0}, // 12 {0, 0}; // 13 string [] lab = new string [] {"T", "h2 ", "H4", "H5", "H6", "X7", "X2", "X7", "X3", "X2", "X3", "H3 ", "X4", "X5 "}; /*********************************** the end sample Data ************************************** **************//************************ * *************/INT subt = 14; int [] [] tree; tree = new int [] [] {2,-1, 1, 10}, // 0 {2,-2, 2, 3}, // 1 {2,-1, 4, 5}, // 2 {2,-1, 6, 7}, // 3 {0, 0 }, // 4 {2,-2, 8, 9}, // 5 {0, 0}, // 6 {0, 0}, // 7 {0, 0}, // 8 {0, 0}, // 9 {2,-2, 11, 12}, // 10 {2,-1, 13, 14 }, // 11 {0, 0}, // 12 {0, 0}, // 13 {0, 0 }}; // 14 string [] lab = new string [] {"T", "E1", "E3", "E4", "B2", "E6 ", "B3", "B7", "B8", "E2", "E5", "B1", "B5", "B6"}; // */mytree. getsubtree (subt); mytree. getlabel (LAB); mytree. gettreemap (tree); // display the saved fault tree for (INT I = 0; I <= subt; I ++) {for (Int J = 0; j <= mytree. treemap [I] [0] + 1; j ++) {system. out. print (mytree. treemap [I] [J] + "");} system. out. println ();} system. out. println ("******************************"); // callayer (); mytree. getallsubnode (); buildupmiddletable (); mytree. cutrepet (); mytree. getend (); // system. out. println (subtree );} /*************************************** * ***** function: after the class is initialized, obtain the parameter passing parameter required for processing: the number of all subt events, including the top event, count from 0 and return: no *************************************** * *****/public static void getsubtree (INT subt) {mytree. subtree = subt ;} /*************************************** * ****** function: after the class is initialized, obtain the event name required for processing to eliminate the same event passing parameter: lab [] string array. The corresponding event name of the number in the array is returned: no *************************************** * *****/public static void getlabel (string [] Lab) {for (INT I = 0; I <lab. length; I ++) {mytree. label [I] = lab [I] ;}} /*************************************** * ****** function: after the class is initialized, obtain the structure of the tree required for processing for calculation and obtain the minimum cut set passing parameter: Tree [] [] Two-Dimensional integer array. Save the structure relationship of the tree and return: no *************************************** * *****/public static void gettreemap (INT [] [] tree) {for (INT I = 0; I <tree. length; I ++) {for (Int J = 0; j <= tree [I] [0] + 1; j ++) {mytree. treemap [I] [J] = tree [I] [J] ;}} Private Static void getallsubnode () {mytree. calculateallsubnode (treemap [0]); printarray (subnode, subnode_n, 5 );} /*********************************** calculate all minimum Cut Set and save it to subnode [] [] array **/Private Static void calculateallsubnode (INT [] ARR) {int position = feedbackposition (ARR); int men_p = Position + 1; int new_position = position; int length = getmyarraylength (ARR); If (position = length) // if the current position is equal to the length of the array, it indicates that there is no gate mark in the array {printarray1v (ARR, 0, Length + 1 ); subnode [subnode_n] [0] = Length + 1; mytree. copyarray1v (ARR, 0, Length + 1, subnode [subnode_n ++], 1);} else if (ARR [men_p] =-1) // or {// if the gate sign is or, you need to create a new array for each symbol (INT I = men_p + 1; I <= men_p + arr [position]; I ++) {int [] array = new int [100]; mytree. copyarray1v (ARR, 0, position-1, array, 0);/** the process is skipped here, because it is an outsourced Code and is confidential */mytree. copyarray1v (ARR, Position + arr [position] + 2, length-position-Arr [position]-2, array, new_position); calculateallsubnode (array );}} else if (ARR [men_p] =-2) // and {int [] array = new int [100]; mytree. copyarray1v (ARR, 0, position-1, array, 0 );/** The process is omitted here because it is outsourced Code and is confidential */
Mytree. copyarray1v (ARR, Position + arr [position] + 2, length-position-Arr [position]-2, array, new_position); calculateallsubnode (array );}}
Private Static void buildupmiddletable (){
Int [] temp = new int [label. Length];
For (INT I = 1; I <= subtree; I ++ ){
If (treemap [I] [0] = 0) // if there is no node in the future, determine whether the last node needs to be stored in the middletable
{
//
If (temp [I] = 0) // check whether the name already exists in the middletable. If the name does not exist, store it in another row.
{
Middletable [middletable_n] [0] ++;
Middletable [middletable_n] [middletable [middletable_n] [0] = I;
Temp [I] = 1;
For (Int J = 0; j <subtree; j ++)
// If it is itself, move one unit to the back
{
If (I = J) // if it is itself, move one unit to the back
{
J ++;
}//
Int Len = label. length;
If (j <subtree) // determines whether the length of the array is exceeded.
{// Int TT = comparestr (Label [I], Label [J]) = 0
If (Label [I] = Label [J] & temp [J] = 0 ){
Middletable [middletable_n] [0] ++;
Middletable [middletable_n] [middletable [middletable_n] [0] = J;
// Middletable_n ++;
Temp [J] = 1;
}
}
}
Middletable_n ++;
}
}
}
// Add the prime number and row number
For (INT I = 0; I <middletable_n; I ++ ){
Middletable [I] [middletable [I] [0] + 1] = prime [I];
Middletable [I] [middletable [I] [0] + 2] = I;
} Printarray (middletable, middletable_n, 5 );}
/*************************************** * Remove repeated cutover sets, and save it to subnode_sole [] [] array ******************************** ******/
Private Static void cutrepet (){
// Use middletable to replace the same item of different numbers
// Int tempflag [] [] = new int [subnode_n] [50];
// The number 50 maybe need changed
For (INT I = 0; I <subnode_n; I ++ ){
// Directly copy 0th Columns
Subnode_sole [I] [0] = subnode [I] [0];
For (Int J = 1; j <= subnode [I] [0]; j ++ ){
Int tempflag = 0;
For (int K = 0; k <middletable_n; k ++) {// determines whether the current number is in the 1st column of buildtable
If (subnode [I] [J] = middletable [k] [1]) // do not replace the value in column 1st
{
Tempflag = 1;
}
}
If (tempflag = 0) // If the column is not 1st, you need to find the row in which the Column exists.
{
For (INT m = 0; m <middletable_n; m ++ ){
For (INT n = 2; n <= middletable [m] [0]; n ++ ){
If (subnode [I] [J] = middletable [m] [N]) {
Subnode_sole [I] [J] = middletable [m] [1]; n = middletable [m] [0];
}
}
}
}
Else // replace {
Subnode_sole [I] [J] = subnode [I] [J];
}
}
}
Subnode_sole_n = subnode_n;
// Printarray (subnode_sole, subnode_sole_n, 5 );
// Eliminate repeated items in a row
For (INT I = 0; I <subnode_sole_n; I ++)
{
For (Int J = 1; j <subnode_sole [I] [0]; j ++)
{
For (int K = J + 1; k <= subnode_sole [I] [0]; k ++)
{
If (subnode_sole [I] [J] = subnode_sole [I] [k] & subnode_sole [I] [k]! =-1)
{
Subnode_sole [I] [k] =-1;
}
}
}
For (Int J = 1; j <subnode_sole [I] [0]; j ++)
{
Int K = J + 1;
If (subnode_sole [I] [J] =-1)
{
If (subnode_sole [I] [k]! =-1)
{
Subnode_sole [I] [J] = subnode_sole [I] [k];
Subnode_sole [I] [k] =-1;
Subnode_sole [I] [0] --;
}
Else
{
K ++;
}
}
}
If (subnode_sole [I] [subnode_sole [I] [0] =-1)
{
Subnode_sole [I] [0] --;
}
}
// Printarray (subnode_sole, subnode_sole_n, 5 );
// Sort rows
For (INT I = 0; I <subnode_sole_n; I ++)
{
For (Int J = 0; j <subnode_sole [I] [0]; j ++)
{
For (int K = 1; k <subnode_sole [I] [0]; k ++)
{
If (subnode_sole [I] [k]> subnode_sole [I] [k + 1])
{
Int temp = subnode_sole [I] [k + 1];
Subnode_sole [I] [k + 1] = subnode_sole [I] [k];
Subnode_sole [I] [k] = temp;
}
}
}
}
// Eliminate the same row
For (INT I = 0; I <subnode_sole_n-1; I ++)
{
For (Int J = I + 1; j <subnode_sole_n; j ++)
{
Int temp = comparearray (subnode_sole [I], subnode_sole [I] [0], subnode_sole [J], subnode_sole [J] [0]);
If (temp = 0 & subnode_sole [I] [0]! = 0)
{
Subnode_sole [J] [0] = 0;
}
}
}
For (INT I = 0; I <subnode_sole_n; I ++)
{
If (subnode_sole [I] [0]! = 0)
{
For (Int J = 0; j <= subnode_sole [I] [0]; j ++)
{
Subnode_result [subnode_result_n] [J] = subnode_sole [I] [J];
}
Subnode_result_n ++;
}
}
// Printarray (subnode_sole, subnode_sole_n, 5 );
Printarray (subnode_result, subnode_result_n, 5 );
}
/*************************************** * ***** Use the prime number method, obtain the final cut set and save it to subnode_result [] [] array ***************************** **********/
, Private Static void getend (){
// Generate a ing queue to prevent excessive numbers and insufficient prime numbers
Int [] map = new int [200];
Int number = 0;
For (INT I = 0; I <subnode_result_n; I ++)
{
For (Int J = 1; j <= subnode_result [I] [0]; j ++)
{
If (Map [subnode_result [I] [J] = 0)
{
Map [subnode_result [I] [J] = number; number ++;
}
}
}
For (INT I = 0; I <subnode_result_n; I ++)
{
Int multi = 1;
For (Int J = 1; j <= subnode_result [I] [0]; j ++)
{
Multi * = prime [map [subnode_result [I] [J];
}
Subnode_result [I] [subnode_result [I] [0] + 1] = multi;
} // Eliminates non-least hour prime number product items
/** The process is omitted here because it is outsourced code and confidential */printarray (subnode_result, subnode_result_n, 5); subnode_output_n = 0; For (INT I = 0; I <subnode_result_n; I ++) {If (subnode_result [I] [0]! = 0) {for (Int J = 0; j <= subnode_result [I] [0]; j ++) {subnode_ouput [subnode_output_n] [J] = subnode_result [I] [J];} subnode_output_n ++;} printarray (subnode_ouput, subnode_output_n, 5 );} private Static void printarray (INT [] [] arr, int X, int y) {for (INT I = 0; I <X; I ++) {for (Int J = 0; j <Y; j ++) {system. out. print (ARR [I] [J] + "");} system. out. println ();} system. out. println ("*********** *******************");} /** The copy length from the array str1 SX1 is Len to str2 from sx2 */Private Static void copyarray1v (INT [] str1, int SX1, int Len, int [] str2, int sx2) {// For (INT I = SX1; I <= SX1 + Len; I ++) for (INT I = 0; I <= Len; I ++) {str2 [sx2 + I] = str1 [SX1 + I] ;}}/** example: array as 2-1 1 11 * return 3 */Private Static int getmyarraylength (INT [] myarr) {int I = 0; // while (myarr [I]! = 0) while (myarr [I]! = 0) {I ++;} return I-1;}/** example: array as 2-1 1 11 * return 0 * array as 2 12 13 * return 3 * position positioned as the first entry position in the array */Private Static int feedbackposition (int [] ARR) {int I = 0; while (ARR [I]> 0 & arr [I]! = 0) {I ++;} return I-1;}/** if same return 0 * else return 1 */Private Static int comparearray (INT [] str1, int len1, int [] str2, int len2) {If (len1! = Len2) {return 1 ;}else {for (INT I = 0; I <= len1; I ++) {If (str1 [I]! = Str2 [I]) {return 1 ;}} return 0;} Private Static void printarray1v (INT [] arr, int St, int Len) {for (INT I = sT; I <Len + st; I ++) {system. out. print (ARR [I] + "");} system. out. println ("***************");}}