예제 #1
0
        /// <summary>
        /// Adds a relationship to the list
        /// </summary>
        /// <param name="r"></param>
        public void Add(Relationship r)
        {
            RelationKey key = r.GetRelationKey();

            if (knowledge.ContainsKey(key))
            {
                bool bNew = true;
                //sadly will need to do a for-loop here to prevent duplicates
                foreach (Relationship oldrelationship in knowledge[key])
                {
                    if (oldrelationship.Relation == r.Relation
                        && oldrelationship.A == r.A
                        && oldrelationship.B == r.B
                        )
                    {
                        bNew = false;
                    }
                }

                // If the rules already added don't do it again.
                //if (knowledge[key].Contains(r)) return; DID NOT WORK (Probably because of the weights being different?)
                if (bNew == true)
                {
                    knowledge[key].Add(r);
                }
                return;
            }
            else
            {
                List<Relationship> relationList = new List<Relationship>();
                relationList.Add(r);
                knowledge.Add(key, relationList);
            }
        }
예제 #2
0
        private bool CanFireRule(Relationship ifTrue, Relationship[] knowledgePieces)
        {
            foreach (Relationship r in knowledgePieces)
            {
                if (r.B == ifTrue.B)
                    return true;
            }

            return false;
        }
예제 #3
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // create a brand new table
            // building teh columns based on rules
            Relationship temp = new Relationship();

            // The commented out line worked in previous version but would not compile here so I had to
            // change it, to the following, which I'm not sure if it is correct.
            System.Reflection.PropertyInfo[] names = typeof(Relationship).GetProperties (BindingFlags.Public| BindingFlags.Static);

               // System.Reflection.PropertyInfo[] names = Reflection.GetPropertyNames(temp);
            if (names == null)
            {
                throw new Exception("Relationship does not have any names!?");
            }
            DataTable table = new DataTable();
            foreach (System.Reflection.PropertyInfo pInfo in names)
            {
                table.Columns.Add(pInfo.Name, pInfo.PropertyType);
            }

            dataGridView1.DataSource = table;
            FixTableOrder();
        }
예제 #4
0
        private void DeduceRule(Relationship relationship,
            List<Relationship> potentialNewKnowledge)
        {
            Relationship aIs = relationship;

            //Get the B's
            List<Relationship> theBs = knowledge[aIs.GetRelationKey()];

            // june 12 2009 - was having trouble with foreach working so I did a normal for

            //foreach (Relationship secondRelation in theBs)
            for (int i = 0 ; i < theBs.Count; i++)
            {
                Relationship secondRelation = theBs[i];
                // A is B1, B2, B3 ...
                string b = secondRelation.B;

                RelationKey bRelation = new RelationKey(b, DEDUCED_IS);

                if (!knowledge.ContainsKey(bRelation))
                {
                    // do nothing if we don't have any 'deductions' to make
                    // removed the break beacuse it was messing with looping?
                    //break;
                }
                else
                {

                    List<Relationship> theCs = knowledge[bRelation];

                    foreach (Relationship bIs in theCs)
                    {
                        double newWeight = (aIs.Weight + bIs.Weight) /2 ;
                        int newPriority = Math.Max(aIs.Priority, bIs.Priority);
                        //Create A is C, if it doesn't exist add it.
                        Relationship newRule
                            = new Relationship(aIs.A, DEDUCED_IS, bIs.B
                            , "", newWeight, newPriority, false);

                        potentialNewKnowledge.Add(newRule);
                    }
                }
            }
        }