class Node { constructor() { this.sName = ""; this.children = []; this.mother = 0; this.sType = ""; this.isMarked = false; this.isNewPage = false; } } let nodes; let nNodes; let isSilent = 0; let showCut = 1; let verifyStructure = -1 function verify(silent=false){ verifyString = findMCS(verifyStructure); if (verifyString != ""){ ret = "

Verification:

There are errors in your diagram

"; ret += verifyString; ret += "

"; localStorage.setItem("RBDresult",ret); localStorage.setItem("closeTxt","Close error report"); setLocalStorage(); // RBD + data window.location.href = "RBDresult.html" } } function findMCS(option = showCut){ let i; initFTAstru(); nodes = []; let dummy =new Node(); dummy.mother = 0; // nodes.push(dummy); // Convert block to FTA page, note page start at 1, Block start at 0 for (let block of Blocks){ let node = new Node(); node.sName = block.name switch(block.type) { case "series": node.sType = "OR"; break; case "parallel": if (block.k >1){ node.sType = "K"+(block.k).toString(); } else { node.sType = "AND"; } break; default: node.sType = "Basic" } if (block.mother < 0){ //"TOPP" node.mother = 0; } else { node.mother = block.mother + 1; } console.log(node.sName,node.mother,node.sType); nodes.push(node); } i=0; nNodes = nodes.length-1; // remember dummy first element verifyString = ""; for (let n of nodes){ // Translate "K" in RBD to "K" in FTA, check for # children, for "gates" if (i>0){ let N = getNumberOfChildren(i); if ((n.sType).substring(0, 1) == "K"){ let k = Number((n.sType).substring( 1)); if (k > N){ verifyString += 'Invalid value of k in symbol: "' + n.sName + '"!
'; } nodes[i].sType = (N - k + 1).toString() + "ooN"; } if (n.sType != "Basic"){ if (N < 2) { verifyString += 'Symbol: "' + n.sName + '" has less than 2 sub-elements!
'; } } } i++; } i = 0; for (let n of nodes){ if (i>0){ let name = n.sName.toUpperCase(); for (let j = i+1; j <= nNodes; j++){ if (nodes[j].mother > 0 ){ if (name == (nodes[j].sName).toUpperCase()){ console.log ( name , nodes[j].sName ); console.log ( nodes[j].sType , nodes[i].sType); if (nodes[j].sType != nodes[i].sType){ verifyString += 'Symbol: "' + n.sName + '" used with different symbol type!
'; } else if (nodes[j].sType != "Basic"){ // Find list of children names, and check they are equal childrenNames1=[]; childrenNames2=[]; children1 = getChildren(i); children2 = getChildren(j); for (let ch1 of children1){ childrenNames1.push(nodes[ch1]); } for (let ch2 of children2){ childrenNames2.push(nodes[ch2]); } if (!setsAreEqual(childrenNames1,childrenNames2)){ verifyString += 'Symbol: "' + n.sName + '" used several times with different sub-elements!
'; } } } } } } i++; } if (verifyString != ""){ if (option == verifyStructure){ return verifyString; } alert("There are one or more errors in yor diagram, run Verify to view these errors!"); return false; } if (option == verifyStructure && verifyString == ""){ alert("No errors in the diagram"); return ""; } pageToFTApage(nodes,nNodes); if (option == isSilent){ return getMCS("binary"); } ret = "

Minimal cut sets:

"; ret += getMCS(); ret += "

"; ret += loadRBDdata(); ret += "

Common cause definitions

" h = structureToBeta(); h = h.replace(/\n/,"
"); h = h.replace(/beta/,"β"); ret += h; ret += postProcessMCSs(); openReport(ret); } function openReport(ret,closeTxt="Close report"){ localStorage.setItem("RBDresult",ret); localStorage.setItem("closeTxt",closeTxt); setLocalStorage(); // RBD + data window.location.href = "RBDresult.html" } function getNumberOfChildren(id){ n=0; for (let i = 1; i <= nNodes; i++) { if (nodes[i].mother == id) {n++;} } return n; } function getChildren(id){ // Note that getChildren is for the FTA structure, not the RBD structure! nChild = getNumberOfChildren(id); let children = new Array(nChild); n=0; for (let i = 1; i <= nNodes; i++) { if (nodes[i].mother == id) { children[n] = i; n++; } } return children; } function postProcessMCSs(MCSs){ i = 0; for (let CCFelement of CCFelements){ let components = [] for (let name of CCFelement.componentNames){ components.push(basic2num(name)); } CCFelement.components = components; i += 1; for (let cut of MCSs){ if (isSubset(components, cut)){ let BE = "C_"; CCFcut = []; for (let j of components){ } } } return JSON.stringify(CCFelements) }