Example #1
0
        public void DFS(T from, GraphEventHandler _method)
        {
            GraphEventHandler GraphHandler = _method;
            List <T>          F            = new List <T>();

            DFPrec(from, GraphHandler, ref F);
        }
Example #2
0
        public void BFS(T from, GraphEventHandler _method)
        {
            GraphEventHandler GraphHandler = _method;
            Queue <T>         S            = new Queue <T>();
            List <T>          F            = new List <T>();

            S.Enqueue(from);
            F.Add(from);
            List <int> distance = new List <int>();

            distance.Add(0);
            int index = 0;

            while (S.Count != 0)
            {
                T k = S.Dequeue();
                GraphHandler?.Invoke(k, distance[index]);
                foreach (T item in Neighbors(k))
                {
                    if (!F.Contains(item))
                    {
                        S.Enqueue(item);
                        F.Add(item);
                        distance.Add(distance[index] + 1);
                    }
                }
                index++;
            }
        }
Example #3
0
        /// <summary>
        /// Helper method for raising the <see cref="Merged">Merged</see> event
        /// </summary>
        protected void RaiseMerged()
        {
            GraphEventHandler d = this.Merged;

            if (d != null)
            {
                d(this, new GraphEventArgs(this));
            }
        }
Example #4
0
        /// <summary>
        /// Helper method for raising the <see cref="Changed">Changed</see> event
        /// </summary>
        /// <param name="args">Triple Event Arguments</param>
        protected void RaiseGraphChanged(TripleEventArgs args)
        {
            GraphEventHandler d = this.Changed;

            if (d != null)
            {
                d(this, new GraphEventArgs(this, args));
            }
        }
Example #5
0
        /// <summary>
        /// Helper method which raises the <see cref="GraphRemoved">Graph Removed</see> event manually
        /// </summary>
        /// <param name="g">Graph</param>
        protected virtual void RaiseGraphRemoved(IGraph g)
        {
            GraphEventHandler d = this.GraphRemoved;

            if (d != null)
            {
                d(this, new GraphEventArgs(g));
            }
        }
Example #6
0
        /// <summary>
        /// Helper method for raising the <see cref="Cleared">Cleared</see> event
        /// </summary>
        protected void RaiseCleared()
        {
            GraphEventHandler d = Cleared;

            if (d != null)
            {
                d(this, new GraphEventArgs(this));
            }
        }
Example #7
0
 private void DFPrec(T node, GraphEventHandler GraphHandler, ref List <T> F)
 {
     F.Add(node);
     GraphHandler?.Invoke(node);
     foreach (T item in Neighbors(node))
     {
         if (!F.Contains(item))
         {
             DFPrec(item, GraphHandler, ref F);
         }
     }
 }
Example #8
0
        /// <summary>
        /// Creates a wrapper around the default Graph implementation, primarily required only for deserialization and requires that the caller call <see cref="WrapperGraph.AttachEventHandlers"/> to properly wire up event handling
        /// </summary>
        protected WrapperGraph()
        {
            this._g = new Graph();

            // Create Event Handlers and attach to relevant events so the wrapper propogates events upwards
            this.TripleAssertedHandler      = new TripleEventHandler(this.OnTripleAsserted);
            this.TripleRetractedHandler     = new TripleEventHandler(this.OnTripleRetracted);
            this.GraphChangedHandler        = new GraphEventHandler(this.OnChanged);
            this.GraphClearedHandler        = new GraphEventHandler(this.OnCleared);
            this.GraphMergedHandler         = new GraphEventHandler(this.OnMerged);
            this.GraphClearRequestedHandler = new CancellableGraphEventHandler(this.OnClearRequested);
            this.GraphMergeRequestedHandler = new CancellableGraphEventHandler(this.OnMergeRequested);
        }
Example #9
0
        protected void RaiseClearedEvent()
        {
            GraphEventHandler d    = this.Cleared;
            GraphEventHandler e    = this.Changed;
            GraphEventArgs    args = new GraphEventArgs(this);

            if (d != null)
            {
                d(this, args);
            }
            if (e != null)
            {
                e(this, args);
            }
        }
        /// <summary>
        /// Creates a new Base Triple Store
        /// </summary>
        /// <param name="graphCollection">Graph Collection to use</param>
        protected BaseTripleStore(BaseGraphCollection graphCollection)
        {
            if (graphCollection == null) throw new ArgumentNullException("graphCollection", "Graph Collection must be an non-null instance of a class which derives from BaseGraphCollection");
            this._graphs = graphCollection;

            this.GraphAddedHandler = new GraphEventHandler(this.OnGraphAdded);
            this.GraphRemovedHandler = new GraphEventHandler(this.OnGraphRemoved);
            this.GraphChangedHandler = new GraphEventHandler(this.OnGraphChanged);
            this.GraphMergedHandler = new GraphEventHandler(this.OnGraphMerged);
            this.GraphClearedHandler = new GraphEventHandler(this.OnGraphCleared);

            //Attach Handlers to the Graph Collection
            this._graphs.GraphAdded += this.GraphAddedHandler;
            this._graphs.GraphRemoved += this.GraphRemovedHandler;
        }
Example #11
0
        /// <summary>
        /// Helper method for raising the <see cref="TripleRetracted">Triple Retracted</see> event manually
        /// </summary>
        /// <param name="t">Triple</param>
        protected void RaiseTripleRetracted(Triple t)
        {
            TripleEventHandler d = this.TripleRetracted;
            GraphEventHandler  e = this.Changed;

            if (d != null || e != null)
            {
                TripleEventArgs args = new TripleEventArgs(t, this, false);
                if (d != null)
                {
                    d(this, args);
                }
                if (e != null)
                {
                    e(this, new GraphEventArgs(this, args));
                }
            }
        }
Example #12
0
        /// <summary>
        /// Helper method for raising the triple events manually
        /// </summary>
        /// <param name="t">Triple</param>
        protected void RaiseTripleEvent(Triple t, bool asserted)
        {
            TripleEventHandler d = asserted ? this.TripleAsserted : this.TripleRetracted;
            GraphEventHandler  e = this.Changed;

            if (d != null || e != null)
            {
                TripleEventArgs args = new TripleEventArgs(t, this, asserted);
                if (d != null)
                {
                    d(this, args);
                }
                if (e != null)
                {
                    e(this, new GraphEventArgs(this, args));
                }
            }
        }
Example #13
0
        /// <summary>
        /// Creates a new Base Triple Store
        /// </summary>
        /// <param name="graphCollection">Graph Collection to use</param>
        protected BaseTripleStore(BaseGraphCollection graphCollection)
        {
            if (graphCollection == null)
            {
                throw new ArgumentNullException("graphCollection", "Graph Collection must be an non-null instance of a class which derives from BaseGraphCollection");
            }
            this._graphs = graphCollection;

            this.GraphAddedHandler   = new GraphEventHandler(this.OnGraphAdded);
            this.GraphRemovedHandler = new GraphEventHandler(this.OnGraphRemoved);
            this.GraphChangedHandler = new GraphEventHandler(this.OnGraphChanged);
            this.GraphMergedHandler  = new GraphEventHandler(this.OnGraphMerged);
            this.GraphClearedHandler = new GraphEventHandler(this.OnGraphCleared);

            //Attach Handlers to the Graph Collection
            this._graphs.GraphAdded   += this.GraphAddedHandler;
            this._graphs.GraphRemoved += this.GraphRemovedHandler;
        }
Example #14
0
        /// <summary>
        /// Helper method for raising the <see cref="TripleAsserted">Triple Asserted</see> event manually
        /// </summary>
        /// <param name="t">Triple</param>
        protected void RaiseTripleAsserted(Triple t)
        {
            TripleEventHandler d = TripleAsserted;
            GraphEventHandler  e = Changed;

            if (d != null || e != null)
            {
                TripleEventArgs args = new TripleEventArgs(t, this);
                if (d != null)
                {
                    d(this, args);
                }
                if (e != null)
                {
                    e(this, new GraphEventArgs(this, args));
                }
            }
        }