Ejemplo n.º 1
0
        public void RemoveEffect(ChainNode toRemove)
        {
            int i = 0;

            while (i < _effect.Count)
            {
                if (toRemove.Identifier == _effect[i].Identifier)
                {
                    _effect.RemoveAt(i);
                }

                else
                {
                    i += 1;
                }
            }
        }
Ejemplo n.º 2
0
        public void RemoveCause(ChainNode toRemove)
        {
            int i = 0;

            while (i < _cause.Count)
            {
                if (toRemove.Identifier == _cause[i].Identifier)
                {
                    _cause.RemoveAt(i);
                }

                else
                {
                    i += 1;
                }
            }
        }
Ejemplo n.º 3
0
        public bool CheckCausedBy(ChainNode b)
        {
            if (this.IsOr)
            {
                foreach (ChainNode c in this.Causes)
                {
                    if (c == b)//if a cause node is b then this is caused by b
                    {
                        return(true);
                    }

                    else if (c.CheckCausedBy(b))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            else
            {
                bool result = true;

                foreach (ChainNode c in this.Causes)
                {
                    if (c != b)//if a cause node is b then this is caused by b
                    {
                        return(true);
                    }

                    else if (c.CheckCausedBy(b))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
Ejemplo n.º 4
0
 public void AddEffect(ChainNode toAdd)
 {
     _effect.Add(toAdd);
 }
Ejemplo n.º 5
0
 public void AddCause(ChainNode toAdd)
 {
     _cause.Add(toAdd);
 }
Ejemplo n.º 6
0
        public static void EstablishRelationship(ChainNode parent, ChainNode child)
        {
            parent.AddEffect(child);

            child.AddCause(parent);
        }
Ejemplo n.º 7
0
        public void Populate()
        {
            _nodes.Clear();

            foreach (Statement stat in _kB.Universe) // populate with all (includes assertions and queieries)
            {
                if ((stat as Implication) != null)   //implications express relationships not nodes
                {
                    //don't add implications
                }

                else
                {
                    ChainNode toAdd = new ChainNode(stat);

                    if ((stat as Variable) != null)
                    {
                        toAdd.IsOr = true;
                    }

                    _nodes.Add(toAdd);
                }
            }

            foreach (Statement stat in _kB.Assertions)// set assertions
            {
                foreach (ChainNode chan in _nodes)
                {
                    if (chan.Identifier == stat.Identifier)
                    {
                        chan.Asserted = true;
                    }
                }
            }

            foreach (Statement stat in _kB.Universe)// set relationships
            {
                if ((stat as Variable) != null)
                {
                    //no self evident causes
                }

                else if ((stat as And) != null)
                {
                    And a = (stat as And);

                    int toFind = a.Stats.Length;

                    int         index   = 0;
                    ChainNode[] parents = new ChainNode[toFind];

                    ChainNode child = null;

                    foreach (ChainNode n in _nodes)
                    {
                        if (n.Stat.Identifier != a.Identifier)
                        {
                            if (a.ComprisedOf(n.Identifier))
                            {
                                parents[index] = n;

                                index += 1;
                            }
                        }

                        else
                        {
                            child = n;
                        }
                    }

                    foreach (ChainNode p in parents)
                    {
                        ChainNode.EstablishRelationship(p, child);
                    }
                }

                else if ((stat as Implication) != null)
                {
                    Implication i = (stat as Implication);

                    ChainNode parent = null;
                    ChainNode child  = null;

                    foreach (ChainNode n in _nodes)
                    {
                        if (i.ComprisedOf(n.Identifier))
                        {
                            //relationship always established after here
                            if (i.CausedBy(n.Identifier))
                            {
                                parent = n;
                            }

                            else
                            {
                                child = n;
                            }
                        }
                    }

                    ChainNode.EstablishRelationship(parent, child);
                }

                else//exaustive list
                {
                    throw new Exception("Unknown statement: " + stat.Identifier);
                }
            }

            /*int j = 0;
             * while (j < _nodes.Count)//remove non-variables
             * {
             *  List<ChainNode> causes = new List<ChainNode>();
             *  List<ChainNode> effects = new List<ChainNode>();
             *
             *  if ((_nodes[j].Stat as Variable) == null)//non variable
             *  {
             *      foreach (ChainNode c in _nodes[j].Causes)
             *      {
             *          causes.Add(c);
             *
             *          c.RemoveEffect(_nodes[j]);//disassociate
             *      }
             *
             *      foreach (ChainNode e in _nodes[j].Effects)
             *      {
             *          effects.Add(e);
             *
             *          e.RemoveCause(_nodes[j]);//disassociate
             *      }
             *
             *      _nodes.RemoveAt(j);
             *
             *      foreach (ChainNode c in causes)
             *      {
             *          foreach (ChainNode e in effects)
             *          {
             *              e.AddCause(c);//associate
             *              c.AddEffect(e);
             *          }
             *      }
             *  }
             *
             *  else
             *  {
             *      j += 1;
             *  }
             * }*/

            foreach (ChainNode n in _nodes) // fill queries
            {
                foreach (Statement q in _kB.Queries)
                {
                    if (q.Identifier == n.Identifier)
                    {
                        _queries.Add(n);
                    }
                }
            }
        }