Ejemplo n.º 1
0
 public override bool GetMaxCommonFragments(
     HasseNode Node1, HasseNode Node2,
     bool dbg, HasseFragmentInsertionQueue NewFragmentList,
     int MinimumOverlap)
 {
     return(ChemObject.GetMaxCommonFragments(this, Node1, Node2, dbg, NewFragmentList, MinimumOverlap));
 }
Ejemplo n.º 2
0
        public override bool GetMaxCommonFragments(
            HasseNode Node1, HasseNode Node2,
            bool dbg, HasseFragmentInsertionQueue NewFragmentList,
            int MinimumOverlap)
        {
            string           debugInfo = "";
            HasseFingerprint fp1       = ((FingerprintChemHasseNode)Node1).hFingerprint;
            HasseFingerprint fp1_clone = fp1.CloneHasseFingerprint();
            HasseFingerprint fp2       = ((FingerprintChemHasseNode)Node2).hFingerprint;

            fp1_clone.AndBits(fp2);
            if (fp1_clone.bitCount >= MinimumOverlap)
            {
                string strMCS = fp1_clone.ToHex();

                HasseFingerprint test = new HasseFingerprint();
                test.FromHex(strMCS);

                NewFragmentList.Add(
                    new HasseNode[1] {
                    this
                },                                    // this is lower than new frag
                    new HasseNode[2] {
                    Node1, Node2
                },                                                                                               // those are higher than new frag
                    strMCS,                                                                                      // string to use for new node creation later
                    debugInfo, HasseNode.HasseNodeTypes.FRAGMENT | HasseNode.HasseNodeTypes.MAX_COMMON_FRAGMENT, // type of frag
                    null                                                                                         // this new frag is not associated with a single edge
                    );
                return(true);
            }
            return(false);
        }
        private bool ProcessMatch(Match M, int MinimumOverlap, HasseFragmentInsertionQueue NewFragmentList, HasseNode [] PartlyMatchingNodes, string debugInfo)
        {
            string StringMCS   = M.GetMatchString();
            bool   matchWasNew = false;

            if (StringMCS.Length >= MinimumOverlap)
            {
                //  if (M.StrA.Equals("*t")) System.Diagnostics.Debugger.Break();

                // deal with the max common substructure:
                // star to left? Both strings must then have one pos matching star
                if (M.FirstPosInA > 0 && M.FirstPosInB > 0)
                {
                    StringMCS = "*" + StringMCS;
                }
                // star to right? Both strings must then have one pos matching star
                if ((M.LastPosInA < M.StrA.Length - 1) && (M.LastPosInB < M.StrB.Length - 1))
                {
                    StringMCS = StringMCS + "*";
                }

                // Do not return back what was started from:
                if (StringMCS.Equals(PartlyMatchingNodes[0].KeyString) | StringMCS.Equals(PartlyMatchingNodes[1].KeyString))
                {
                    return(false);
                }
                if (StringMCS.Equals("**"))
                {
                    System.Diagnostics.Debugger.Break();
                }
                if (!StringMCS.Equals("*"))
                {
                    if (true == NewFragmentList.Add(new HasseNode[1] {
                        this
                    }, PartlyMatchingNodes,
                                                    StringMCS, debugInfo,
                                                    HasseNodeTypes.FRAGMENT | HasseNodeTypes.MAX_COMMON_FRAGMENT, null))
                    {
                        matchWasNew = true;
                    }
                }
            }
            //if (matchWasNew) { System.Diagnostics.Debugger.Break(); }
            return(matchWasNew);
        }
Ejemplo n.º 4
0
        // ==========================================


        public HasseDiagram(HasseNodeFactory.NodeType t)
        {
            // construct new HasseDiagram
            HasseDiagramNodes = new HasseNodeCollection();  //collection nodes in diagram
            DifferenceNodes   = new HasseNodeCollection();  //collection of objects expressing difference
            //ElementaryHasseNodes = new HasseNodeCollection(); // collection of elements

            // factory for nodes, set its nodetype and let it have access to global elements collection
            diagramNodeFactory    = new HasseNodeFactory(t);
            differenceNodeFactory = new HasseNodeFactory(t);

            // a queue for nodes to be created after current node is fully processed
            FragmentInsertionQueue = new HasseFragmentInsertionQueue(HasseDiagramNodes);

            // create the root node as part of construction
            RootNode = diagramNodeFactory.NewNode("", HasseNode.HasseNodeTypes.ROOT, "");
            HasseDiagramNodes.Add("{}", RootNode);
        }
        public bool GetMaxCommonFragmentsNotUsed(HasseNode Node1, HasseNode Node2, bool dbg,
                                                 HasseFragmentInsertionQueue NewFragmentList, int MinimumOverlap)
        {
            // this Node is directly below both Node1 and Node2
            // it can match several places
            CountMCS++;
            string strSeed  = this.KeyString.Replace("*", "");
            string str1     = Node1.KeyString;
            string str2     = Node2.KeyString;
            bool   FoundMCS = false;

            // we are only interested in matches strictly larger than seed
            if (strSeed.Length + 1 > MinimumOverlap)
            {
                MinimumOverlap = strSeed.Length + 1;
            }

            int MatchPosA = GetNextMatch(0, strSeed, str1);

            while (MatchPosA > -1)
            {
                int MatchPosB = GetNextMatch(0, strSeed, str2);
                while (MatchPosB > -1)
                {
                    Match M = new Match(strSeed, MatchPosA, 0, str1, MatchPosB, 0, str2);
                    M.ExpandMCSMatch();
                    //MatchPosA= M.LastPosInA;
                    //MatchPosB = M.LastPosInB;
                    string debugInfo = "MCS " + Node1.GetID().ToString() + " " + Node2.GetID().ToString();
                    if (true == ProcessMatch(M, MinimumOverlap, NewFragmentList, new HasseNode[2] {
                        Node1, Node2
                    }, debugInfo))
                    {
                        FoundMCS = true;
                    }
                    MatchPosB = GetNextMatch(MatchPosB + 1, strSeed, str2);
                }
                MatchPosA = GetNextMatch(MatchPosA + 1, strSeed, str1);
            }

            return(FoundMCS);
        }
        public override bool GetMaxCommonFragments(HasseNode Node1, HasseNode Node2, bool dbg,
                                                   HasseFragmentInsertionQueue NewFragmentList, int MinimumOverlap)
        {
            CountMCS++;
            string str1     = Node1.KeyString;
            string str2     = Node2.KeyString;
            bool   FoundMCS = false;

            StringMatcher sm = new StringMatcher();

            sm.Initialise(str1, str2);
            Match m = null;

            do
            {
                m = sm.nextMatch();
                if (m == null)
                {
                    break;
                }
                if (m.LastPosInA - m.FirstPosInA < MinimumOverlap - 1)
                {
                    continue;
                }
                //System.Diagnostics.Debug.WriteLine(m.StrA.Substring(m.FirstPosInA, m.LastPosInA - m.FirstPosInA + 1));
                //System.Diagnostics.Debug.WriteLine(m.StrB.Substring(m.FirstPosInB, m.LastPosInB - m.FirstPosInB + 1));
                string debugInfo = "MCS " + Node1.GetID().ToString() + " " + Node2.GetID().ToString();
                if (true == ProcessMatch(m, MinimumOverlap, NewFragmentList, new HasseNode[2] {
                    Node1, Node2
                }, debugInfo))
                {
                    FoundMCS = true;
                }
            } while (true);
            return(FoundMCS);
        }
Ejemplo n.º 7
0
 public abstract bool GetMaxCommonFragments(HasseNode Node1, HasseNode Node2, bool dbg, HasseFragmentInsertionQueue NewFragmentList, int MinimumOverlap);