Esempio n. 1
0
        public override void Populate(IGraph <TItem, TEdge> graph)
        {
            var lastNode1 = default(TItem);
            var lastNode2 = default(TItem);;
            var lastNode3 = default(TItem);;

            for (int i = 0; i < Count; i++)
            {
                if (i > 0)
                {
                    lastNode1 = Nodes[1];
                    lastNode2 = Nodes[5];
                    lastNode3 = Nodes[8];
                }
                Populate(graph, Start + 1);
                if (i > 0)
                {
                    var edge = CreateEdge(lastNode1, Nodes[1]);
                    graph.Add(edge);
                    if (SeperateLattice)
                    {
                        edge = CreateEdge(lastNode2, Nodes[5]);
                        graph.Add(edge);
                    }
                    if (AddDensity)
                    {
                        edge = CreateEdge(Nodes[2], lastNode3);
                        graph.Add(edge);
                    }
                }
            }
        }
Esempio n. 2
0
        public void TestSaveGraphWithUnknownNode()
        {
            graph = new Graph();

            var A = new TestSubNode()
            {
                Label = "A"
            };
            var B = new Node()
            {
                Label = "B"
            };
            var C = new Node()
            {
                Label = "C"
            };
            var D = new TestSubNode()
            {
                Label = "D"
            };
            var E = new TesteSubNode2()
            {
                Label = "E"
            };

            graph.Add(A);
            graph.Add(B);
            graph.Add(C);
            graph.Add(D);
            graph.Add(E);

            graph.ConnectNodeToWith(A, B, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 8
            }));
            graph.ConnectNodeToWith(A, D, new TestSubEdge(9));
            graph.ConnectNodeToWith(A, E, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 4
            }));
            graph.ConnectNodeToWith(B, C, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 1
            }));
            graph.ConnectNodeToWith(C, B, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 2
            }));
            graph.ConnectNodeToWith(C, D, new TestSubEdge(3));
            graph.ConnectNodeToWith(D, C, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 2
            }));
            graph.ConnectNodeToWith(D, E, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 7
            }));
            graph.ConnectNodeToWith(E, C, new Edge(new AttributePair <Double> {
                Name = "Weight", Attribute = 1
            }));

            writer.Save(graphExoticNodePath, graph);
        }
Esempio n. 3
0
        public override void Populate(IGraph <TItem, TEdge> graph, int start)
        {
            var item = CreateItem <int>((start++));

            graph.Add(item);
            Nodes[1] = item;

            item = CreateItem <int>((start++));
            graph.Add(item);
            Nodes[2] = item;

            Edges[1] = CreateEdge(Nodes[1], Nodes[2]);
            graph.Add(Edges[1]);
        }
Esempio n. 4
0
        public void AdjacentTest()
        {
            IGraph <int> graph = GraphMap.New <int>();

            for (int i = 1; i <= 5; i++)
            {
                graph.Add(i);
            }
            graph.Add(1, 5);
            graph.Add(2, 5);
            graph.Add(3, 5);
            graph.Add(4, 5);
            Assert.IsTrue(graph.Adjacent(1, 5));
        }
Esempio n. 5
0
        public void TestWriter1000NodeGraph()
        {
            graph = new Graph();
            List <INode> nodes = new List <INode>();

            for (int i = 0; i != 1000; ++i)
            {
                var node = new TesteSubNode2();
                nodes.Add(node);
                graph.Add(node);
            }
            Assert.AreEqual(nodes.Count, graph.NodeCount);
            Assert.AreEqual(1000, graph.NodeCount);

            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                var index1 = random.Next(0, 1000);
                var index2 = random.Next(0, 1000);
                while (index2 == index1)
                {
                    index2 = random.Next(0, 1000);
                }
                graph.ConnectNodeToWith(nodes[index1], nodes[index2], new Edge(new AttributePair <Double> {
                    Name = "Weight", Attribute = random.Next(1, 600)
                }));
            }
            Assert.AreEqual(graph.AllEdges.Count, 1000);

            writer.Save("Large Graph.xml", graph);
        }
Esempio n. 6
0
 public void FillGraph(IGraph <TItem, TEdge> graph, BasicGraphTestDataFactory <TItem, TEdge> data)
 {
     foreach (var edge in data.Edges)
     {
         graph.Add(edge);
     }
 }
        public NNValue Activate(NNValue input, IGraph g)
        {
            NNValue sum       = g.Add(g.Mul(_w, input), _b);
            NNValue returnObj = g.Nonlin(_f, sum);

            return(returnObj);
        }
Esempio n. 8
0
 public virtual void AddSamplesToGraph(IGraph <TItem, TEdge> graph)
 {
     foreach (var item in Nodes)
     {
         if (item != null)
         {
             graph.Add(item);
         }
     }
     foreach (var item in Edges)
     {
         if (item != null)
         {
             graph.Add(item);
         }
     }
 }
Esempio n. 9
0
 public static void AddRange <TItem, TEdge>(this IGraph <TItem, TEdge> graph, IEnumerable <TItem> items)
     where TEdge : IEdge <TItem>
 {
     foreach (var item in items)
     {
         graph.Add(item);
     }
 }
        private GraphNode <GraphNodeAnnotationData> AddVertex(PropGraphNodeDescriptor analysisNode)
        {
            long index;
            GraphNode <GraphNodeAnnotationData> node = null;

            if (!vIndex.TryGetValue(analysisNode, out index))
            {
                var data = new GraphNodeAnnotationData(analysisNode);
                index = (long)vIndex.Count;

                vIndex[analysisNode] = index;
                graph.Add(index, data);
            }

            node = graph.GetNode(index);
            return(node);
        }
Esempio n. 11
0
        /// <summary>
        /// Adds a node to the graph.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>The added node.</returns>
        public static Node <NodeData, EdgeData> AddNode(this IGraph <NodeData, EdgeData> graph, NodeData nodeData)
        {
            var node = new Node <NodeData, EdgeData>(nodeData);

            graph.Add(node);

            return(node);
        }
Esempio n. 12
0
        /// <summary>
        /// Adds an edge to the graph.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <param name="firstNode">The first node.</param>
        /// <param name="secondNode">The second node.</param>
        /// <param name="edgeData">The data attached to the edge.</param>
        /// <returns>The added edge.</returns>
        public static Edge <NodeData, EdgeData> AddEdge(this IGraph <NodeData, EdgeData> graph, Node <NodeData, EdgeData> firstNode, Node <NodeData, EdgeData> secondNode, EdgeData edgeData)
        {
            var edge = new Edge <NodeData, EdgeData>(firstNode, secondNode, edgeData);

            graph.Add(edge);

            return(edge);
        }
Esempio n. 13
0
        public void RemoveTest()
        {
            IGraph <int> graph = GraphMap.New <int>();

            for (int i = 1; i <= 5; i++)
            {
                graph.Add(i);
            }
            graph.Add(1, 5);
            graph.Add(2, 5);
            graph.Add(3, 5);
            graph.Add(4, 5);
            graph.Remove(3);
            ListArray <(int, int)> RemainingEdges = new();

            graph.Edges(edge => RemainingEdges.Add((edge.Item1, edge.Item2)));
            Assert.IsTrue(EquateSet <(int, int)>(new[] { (1, 5), (2, 5), (4, 5) }, RemainingEdges.ToArray()));
Esempio n. 14
0
        internal static IVertex AddNamedNode(this IGraph graph, string name)
        {
            var vertex = new Vertex
            {
                Name = name,
            };

            graph.Add(vertex);
            return(vertex);
        }
Esempio n. 15
0
        public NNValue Activate(NNValue input, IGraph g)
        {
            NNValue concat = g.ConcatVectors(input, _context);
            NNValue sum    = g.Mul(_w, concat); sum = g.Add(sum, _b);
            NNValue output = g.Nonlin(_f, sum);

            //rollover activations for next iteration
            _context = output;

            return(output);
        }
Esempio n. 16
0
        private void ConstructGraph()
        {
            var u1 = _sut.Add(new Tag {
                Name = "U1"
            });
            var u2 = _sut.Add(new Tag {
                Name = "U2"
            });
            var s1 = _sut.Add(new Tag {
                Name = "S1"
            });
            var a1 = _sut.Add(new Tag {
                Name = "A1"
            });
            var a2 = _sut.Add(new Tag {
                Name = "A2"
            });
            var b1 = _sut.Add(new Tag {
                Name = "B1"
            });

            _sut.SaveChanges();

            s1.AddParent(u1);
            a1.AddParent(s1);
            b1.AddParent(a2);
            a2.AddParent(s1);
            b1.AddParent(a1);
            s1.AddParent(u2);

            _sut.CommitAllChanges();
        }
Esempio n. 17
0
        private void ConstructGraph()
        {
            _sut.Add(new Tag {
                Name = "0"
            });
            _sut.Add(new Tag {
                Name = "1"
            });
            _sut.Add(new Tag {
                Name = "2"
            });
            _sut.Add(new Tag {
                Name = "3"
            });
            _sut.Add(new Tag {
                Name = "4"
            });
            _sut.Add(new Tag {
                Name = "5"
            });
            _sut.SaveChanges();

            _sut["2"].AddParent(_sut["3"]);
            _sut["0"].AddParent(_sut["1"]);
            _sut["3"].AddParent(_sut["4"]);
            _sut["4"].AddParent(_sut["5"]);
            _sut["1"].AddParent(_sut["2"]);
            _sut.CommitAllChanges();
        }
Esempio n. 18
0
        private void CreateNonexistentTags(IEnumerable <string> tagNames)
        {
            var existingNames = _graph.Vertices.Select(vertex => vertex.Entity.Name);

            foreach (var tagName in tagNames.Except(existingNames))
            {
                _graph.Add(new Tag {
                    Name = tagName
                });
            }

            _graph.SaveChanges();
        }
 public void Initialize()
 {
     src = new Node()
     {
         Label = "A"
     };
     graph = new Graph();
     graph.Add(src);
     nodes    = new Node[5];
     nodes[0] = src;
     for (int i = 1; i != nodes.Length; ++i)
     {
         int val = 'A';
         nodes[i] = new Node
         {
             Label = Convert.ToString(Convert.ToChar(val + i))
         };
         graph.Add(nodes[i]);
     }
     route1 = new Route(src, "Weight");
     route2 = new Route(src, "Weight");
 }
Esempio n. 20
0
        public virtual IThing SetThingByData(IGraph <IThing, ILink> graph, IThing thing, object data)
        {
            var itemToChange = graph.ThingToDisplay(thing);

            if (thing != null && itemToChange == thing && SchemaFacade.DescriptionableThing(thing))
            {
                itemToChange = ThingFactory.CreateItem(data);
                graph.Add(new Link(thing, itemToChange, CommonSchema.DescriptionMarker));
            }
            else
            {
                graph.DoChangeData(itemToChange, data);
            }
            return(itemToChange);
        }
Esempio n. 21
0
        public override void Populate(IGraph <TItem, TEdge> graph, int start)
        {
            base.Populate(graph, start);

            var edge = default(TEdge);;

            #region Binarytree Edges

            edge = CreateEdge(Nodes[1], Nodes[2]);
            graph.Add(edge);
            Edges[1] = edge;

            edge = CreateEdge(Nodes[4], Nodes[3]);
            graph.Add(edge);
            Edges[2] = edge;

            edge = CreateEdge(Nodes[1], Edges[2]);
            graph.Add(edge);
            Edges[3] = edge;

            edge = CreateEdge(Nodes[5], Nodes[8]);
            graph.Add(edge);
            Edges[4] = edge;


            edge = CreateEdge(Nodes[5], Nodes[6]);
            graph.Add(edge);
            Edges[5] = edge;

            edge = CreateEdge(Nodes[5], Nodes[7]);
            graph.Add(edge);
            Edges[6] = edge;

            edge = CreateEdge(Nodes[8], Nodes[9]);
            graph.Add(edge);
            Edges[7] = edge;

            if (!SeperateLattice)
            {
                edge = CreateEdge(Edges[2], Edges[4]);
                graph.Add(edge);
                Edges[8] = edge;
            }

            #endregion
        }
Esempio n. 22
0
        public virtual void Populate(IGraph <TItem, TEdge> graph, int start)
        {
            var item = CreateItem <int> ((start++));

            graph.Add(item);
            Nodes[1] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[2] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[3] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[4] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[5] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[6] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[7] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[8] = item;

            item = CreateItem <int> ((start++));
            graph.Add(item);
            Nodes[9]   = item;
            this.Start = start;
        }
Esempio n. 23
0
        public void GivenSelfReferencingVertex_ThenThrowsCycleException()
        {
            var tag = _sut.Add(new Tag {
                Name = "Sample tag"
            });

            _sut.SaveChanges();

            Action act = () => tag.AddParent(tag);

            act.Should().Throw <CycleException>();
        }
Esempio n. 24
0
        public NNValue Activate(NNValue input, IGraph g)
        {
            //input gate
            NNValue sum0      = g.Mul(_wix, input);
            NNValue sum1      = g.Mul(_wih, _hiddenContext);
            NNValue inputGate = g.Nonlin(_inputGateActivation, g.Add(g.Add(sum0, sum1), _inputBias));

            //forget gate
            NNValue sum2       = g.Mul(_wfx, input);
            NNValue sum3       = g.Mul(_wfh, _hiddenContext);
            NNValue forgetGate = g.Nonlin(_forgetGateActivation, g.Add(g.Add(sum2, sum3), _forgetBias));

            //output gate
            NNValue sum4       = g.Mul(_wox, input);
            NNValue sum5       = g.Mul(_woh, _hiddenContext);
            NNValue outputGate = g.Nonlin(_outputGateActivation, g.Add(g.Add(sum4, sum5), _outputBias));

            //write operation on cells
            NNValue sum6      = g.Mul(_wcx, input);
            NNValue sum7      = g.Mul(_wch, _hiddenContext);
            NNValue cellInput = g.Nonlin(_cellInputActivation, g.Add(g.Add(sum6, sum7), _cellWriteBias));

            //compute new cell activation
            NNValue retainCell = g.Elmul(forgetGate, _cellContext);
            NNValue writeCell  = g.Elmul(inputGate, cellInput);
            NNValue cellAct    = g.Add(retainCell, writeCell);

            //compute hidden state as gated, saturated cell activations
            NNValue output = g.Elmul(outputGate, g.Nonlin(_cellOutputActivation, cellAct));

            //rollover activations for next iteration
            _hiddenContext = output;
            _cellContext   = cellAct;

            return(output);
        }
Esempio n. 25
0
        /// <summary>
        /// Restores from a **XElement** node to
        /// a <see cref="IGraph"/>.
        /// </summary>
        /// <param name="root">
        /// The root node where the Xml representation of **graph** is stored at.
        /// </param>
        /// <remarks>
        /// > [!Note]
        /// > This method utilises <see cref="LoadNode(XElement)"/>,
        /// > <see cref="LoadEdge(XElement)"/>, <see cref="SetIdsStartFrom(XElement)"/>
        /// > and <see cref="CreateXElementIdGenerator"/> to restore all the details
        /// > of a **graph**.
        /// </remarks>
        protected virtual IGraph Dump(XElement root)
        {
            XElement dependencies = root.Element("Dependencies");

            foreach (var dependency in dependencies.Elements())
            {
                String assemPath = dependency.Attribute("Name").Value;

                foreach (var type in dependency.Elements("Type"))
                {
                    DependencyMap[type.Value] = Assembly.LoadFrom(assemPath);
                }
            }

            XElement xgraph = root.Element("Graph");

            var  graphTypeName = xgraph.Attribute("Type").Value;
            Type graphType     = DependencyMap[graphTypeName].GetType(graphTypeName);

            IGraph graph = Activator.CreateInstance(graphType) as IGraph;

            IEnumerable <XElement> xnodes = xgraph.Element("Nodes").Elements();

            foreach (XElement xnode in xnodes)
            {
                graph.Add(LoadNode(xnode));
            }

            IEnumerable <XElement> xedges = xgraph.Element("Edges").Elements();

            foreach (XElement xedge in xedges)
            {
                var tuple = LoadEdge(xedge);
                var from  = graph.AllNodes[tuple.From];
                var to    = graph.AllNodes[tuple.To];
                var edge  = tuple.Through;
                graph.ConnectNodeToWith(from, to, edge);
            }

            SetIdsStartFrom(root);

            return(graph);
        }
Esempio n. 26
0
        public override void Populate(IGraph <TItem, TEdge> graph, int start)
        {
            var node = default(TItem);
            var edge = default(TEdge);


            node = CreateItem <string>("Tags");
            graph.Add(node);
            Nodes[1] = node;


            node = CreateItem <string>("Word");
            graph.Add(node);
            Nodes[2] = node;

            edge = CreateEdge(Nodes[1], Nodes[2]);
            graph.Add(edge);
            Edges[1] = edge;


            node = CreateItem <string>("Game");
            graph.Add(node);
            Nodes[3] = node;

            edge = CreateEdge(Nodes[2], Nodes[3]);
            graph.Add(edge);
            Edges[2] = edge;

            node = CreateItem <string>("Something");
            graph.Add(node);
            Nodes[4] = node;

            edge = CreateEdge(Edges[2], Nodes[4]);
            graph.Add(edge);
            Edges[3] = edge;

            edge = CreateEdge(Nodes[1], Edges[2]);
            graph.Add(edge);
            Edges[4] = edge;
        }
Esempio n. 27
0
        public void NeighborsTest()
        {
            IGraph <int> graph = GraphMap.New <int>();

            for (int i = 1; i <= 5; i++)
            {
                graph.Add(i);
            }
            graph.Add(1, 5);
            graph.Add(2, 5);
            graph.Add(3, 5);
            graph.Add(4, 5);
            graph.Add(5, 2);
            graph.Add(5, 3);
            int sum = 0;

            graph.Neighbors(5, (x) => sum += x);
            Assert.IsTrue(sum is 5);
        }
Esempio n. 28
0
        public void RefreshCompression(IGraph <IThing, ILink> graph, IThing thing, bool act)
        {
            var streamThing = thing as IStreamThing;

            if (streamThing == null || streamThing.Compression != CompressionType.None)
            {
                return;
            }

            var comp = CompressionType.None;

            if (!_compressions.TryGetValue(streamThing.StreamType, out comp))
            {
                var info = ContentInfoPool.FirstOrDefault(i => i.ContentType == streamThing.StreamType);
                if (info != null)
                {
                    comp = info.Compression;
                    _compressions[info.ContentType] = info.Compression;
                    WriteLog("Comp for {0}: {1} | {2}", info.Description, comp, streamThing.StreamType.ToString("X"));
                }
            }
            if (comp != CompressionType.None)
            {
                WriteLog("{0} -> {1} |{2}:{3}", streamThing.Compression, comp, streamThing.Id.ToString("X"), streamThing.StreamType.ToString("X"));
                streamThing.DeCompress();
                var oldSize = streamThing.Data.Length;
                if (act)
                {
                    streamThing.Compression = comp;
                    if (comp != CompressionType.neverCompress)
                    {
                        streamThing.Compress();
                        streamThing.Flush();
                        streamThing.ClearRealSubject();
                        WriteLog("\t{0} -> {1}", oldSize, streamThing.Data.Length);
                    }
                    graph.Add(streamThing);
                }
            }
        }
Esempio n. 29
0
        public static void Main()
        {
            Console.WriteLine("You are runnning the GraphSearch example.");
            Console.WriteLine("======================================================");
            Console.WriteLine();

            #region Simple Example
            {
                Console.WriteLine("  Graph Searching----------------------");
                Console.WriteLine();
                Console.WriteLine("    Graph:");
                Console.WriteLine();
                Console.WriteLine("      [0]-----(1)---->[1]  ");
                Console.WriteLine("       |               |   ");
                Console.WriteLine("       |               |   ");
                Console.WriteLine("      (99)            (2)  ");
                Console.WriteLine("       |               |   ");
                Console.WriteLine("       |               |   ");
                Console.WriteLine("       v               v   ");
                Console.WriteLine("      [3]<----(5)-----[2]  ");
                Console.WriteLine();
                Console.WriteLine("      [nodes in brackets]");
                Console.WriteLine("      (edge costs in parenthases)");
                Console.WriteLine();

                // make a graph
                IGraph <int> graph = GraphSetOmnitree.New <int>();
                // add nodes
                graph.Add(0);
                graph.Add(1);
                graph.Add(2);
                graph.Add(3);
                // add edges
                graph.Add(0, 1);
                graph.Add(1, 2);
                graph.Add(2, 3);
                graph.Add(0, 3);
Esempio n. 30
0
        private void ConstructGraph()
        {
            foreach (var name in new[] { "0", "1", "2", "3", "4", "5", "6", "7" })
            {
                _sut.Add(new Tag {
                    Name = name
                });
            }
            _sut.SaveChanges();

            _sut["0"].AddParent(_sut["1"]);
            _sut["1"].AddParent(_sut["2"]);
            _sut["1"].AddParent(_sut["3"]);
            _sut["3"].AddParent(_sut["4"]);

            _sut["5"].AddParent(_sut["0"]);
            _sut["6"].AddParent(_sut["5"]);
            _sut["7"].AddParent(_sut["5"]);
            _sut.SaveChanges();

            _sut["0"].DeleteParent(_sut["1"]);
            _sut.CommitAllChanges();
        }