public void test3() { // Type type = Type.GetType("StringHasseNode"); HasseDiagram HDM = new HasseDiagram(HasseNodeFactory.NodeType.STRING); System.Random rnd = new System.Random(1); //HasseNodeCollection Elements1 = new HasseNodeCollection(); //HasseNodeCollection elements = new HasseNodeCollection(); StringHasseNode Node1 = new StringHasseNode("CA*", HasseNode.HasseNodeTypes.REAL, ""); StringHasseNode Node2 = new StringHasseNode("DCCCA*", HasseNode.HasseNodeTypes.REAL, ""); bool test = Node2.IsLargerThan(Node1); System.Diagnostics.Debug.Assert(test); System.Collections.Queue q = new System.Collections.Queue(); for (int i = 1; i <= 1000; i++) { string buf = ""; int strLen = Convert.ToInt32(rnd.Next(1, 10)); //random string length for (int j = 1; j <= strLen; j++) { float r = rnd.Next(0, 4); //random character choice '4 switch ((Int32)Math.Truncate(r)) { case 0: buf += "A"; break; case 1: buf += "B"; break; case 2: buf += "C"; break; case 3: buf += "D"; break; default: throw new Exception("error in Test3"); } } HDM.AddNode(buf); } System.Diagnostics.Debug.WriteLine(HasseDiagramStats.Report(HDM.HasseDiagramNodes, HDM.RootNode)); }
// make node based on string public HasseNode NewNode(string s, HasseNode.HasseNodeTypes e, string debugInfo) { switch (nType) { case NodeType.STRING : StringHasseNode SN = new StringHasseNode(s, e, debugInfo); return SN; case NodeType.CHEM : ChemHasseNode CN = new ChemHasseNode(s, e, debugInfo); return CN; case NodeType.FINGERPRINTCHEM : FingerprintChemHasseNode FPC = new FingerprintChemHasseNode(s, e, debugInfo); return FPC; default : throw new Exception ("HasseNodeFactory: unhandled NodeType"); } }
public HasseNode NewNode(object o, HasseNode.HasseNodeTypes e, string debugInfo) { // make node based on object of a class that the node implementing class knows about switch (nType) { case NodeType.STRING: StringHasseNode SN = new StringHasseNode((string) o, e, debugInfo); return SN; case NodeType.CHEM: ChemHasseNode CN = new ChemHasseNode((IndigoChemistry )o, e, debugInfo); return CN; case NodeType.FINGERPRINTCHEM: FingerprintChemHasseNode FPC = new FingerprintChemHasseNode((IndigoChemistry)o, e, debugInfo); return FPC; default: throw new Exception("HasseNodeFactory: unhandled NodeType"); } }
public HasseNode NewNode(object o, HasseNode.HasseNodeTypes e, string debugInfo) { // make node based on object of a class that the node implementing class knows about switch (nType) { case NodeType.STRING: StringHasseNode SN = new StringHasseNode((string)o, e, debugInfo); return(SN); case NodeType.CHEM: ChemHasseNode CN = new ChemHasseNode((IndigoChemistry )o, e, debugInfo); return(CN); case NodeType.FINGERPRINTCHEM: FingerprintChemHasseNode FPC = new FingerprintChemHasseNode((IndigoChemistry)o, e, debugInfo); return(FPC); default: throw new Exception("HasseNodeFactory: unhandled NodeType"); } }
public HasseNode NewNode(string s, HasseNode.HasseNodeTypes e, string debugInfo) // make node based on string { switch (nType) { case NodeType.STRING: StringHasseNode SN = new StringHasseNode(s, e, debugInfo); return(SN); case NodeType.CHEM: ChemHasseNode CN = new ChemHasseNode(s, e, debugInfo); return(CN); case NodeType.FINGERPRINTCHEM: FingerprintChemHasseNode FPC = new FingerprintChemHasseNode(s, e, debugInfo); return(FPC); default: throw new Exception("HasseNodeFactory: unhandled NodeType"); } }
public override bool IsLargerThan(HasseNode smallHasseElement) { if (this.NodeType == HasseNodeTypes.ROOT) { return(false); } if (smallHasseElement.NodeType == HasseNodeTypes.ROOT) { return(true); } #if DEBUG if (this.KeyString.Equals("*en*") && smallHasseElement.KeyString.Contains("en")) { // System.Diagnostics.Debugger.Break(); } #endif // we require that this is strictly larger than Node2 const bool DBG = false; CountComparisons++; if (CountComparisons % 10000 == 0) { System.Diagnostics.Debug.WriteLine("comparisons: \t" + CountComparisons.ToString() + "\t of which where '>';\t" + WasLargerThan.ToString()); } // rules: // B < ABC // BC < *BC // BC <> *B* // A !> A // *A < BA // *A !> *A //with stars taken away Node must be a substring or identical //also something must correspond to the stars //we test all matchings /* * if (smallHasseElement.elementCount() > this.elementCount()) * { * // must be smaller * Debug.WriteLineIf(DBG, this.KeyString + " is not larger than " + smallHasseElement.KeyString + " (0)"); * return false; * } */ StringHasseNode smallStringHasseNode = (StringHasseNode)smallHasseElement; //remove stars string SmallString = smallStringHasseNode.str; string StrippedSmallString = SmallString.Replace("*", ""); bool SmallStringHasStars = true; if (StrippedSmallString.Equals(smallStringHasseNode.str)) { SmallStringHasStars = false; } if (SmallStringHasStars == false) { if (str.Contains(StrippedSmallString) && StrippedSmallString.Length < str.Length) { Debug.WriteLineIf(DBG, this.KeyString + " is larger than " + smallHasseElement.KeyString + " (II)"); WasLargerThan += 1; return(true); } else { Debug.WriteLineIf(DBG, this.KeyString + " is not larger than " + smallHasseElement.KeyString + " (III)"); return(false); } } // small string has stars, different rules // find occurrences of small string in large string. int offset = 0; offset = str.IndexOf(StrippedSmallString); while (offset != -1 && (offset <= str.Length)) { Boolean IsMatch = TestStringMappingForMatch(str, SmallString, StrippedSmallString, offset); if (IsMatch) { Debug.WriteLineIf(DBG, this.KeyString + " is larger than " + smallHasseElement.KeyString + " (IV)"); WasLargerThan += 1; return(true); } offset = str.IndexOf(StrippedSmallString, offset + 1); } Debug.WriteLineIf(DBG, this.KeyString + " is not larger than " + smallHasseElement.KeyString + " (V)"); return(false); }