Exemplo n.º 1
0
        /// <summary>
        /// neighbors: list all neighbors of a given vertex.
        /// </summary>
        /// <param name="vertexId"></param>
        /// <returns></returns>
        public SortedSet <UInt32> Neighbors(UInt32 vertexId)
        {
            Debug.WriteLine("Getting vertexes' neighbors");
            GraphVertex uv = this.Vertices[vertexId];

            return(uv.Neighbors);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set a vertexe's value
        /// </summary>
        /// <param name="vertexId"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        public Boolean SetVertexValue(UInt32 vertexId, Int32 newValue)
        {
            Debug.WriteLine("setting vertex value");
            if (!this.VertexExists(vertexId))
            {
                return(false);
            }
            GraphVertex uv = this.Vertices[vertexId];

            uv.Value = newValue;
            OnVerticesChanged(new VertexChangedEventArgs {
                ChangedVertex = uv
            });
            this.LastVertexChange = ChangeType.Modified;
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove a vertex
        /// </summary>
        public Boolean RemoveVertex(UInt32 vertexToRemove)
        {
            Debug.WriteLine("Removing vertex");
            if (!VertexExists(vertexToRemove))
            {
                return(false);
            }
            GraphVertex RemovedVertex = this.Vertices[vertexToRemove];

            this.Vertices.Remove(vertexToRemove);
            //this.AdjacencyMatrix.Remove(vertexToRemove);
            this.LastVertexChange = ChangeType.Removed;
            OnVerticesChanged(new VertexChangedEventArgs {
                ChangedVertex = RemovedVertex
            });
            return(true);
        }
Exemplo n.º 4
0
        private void ToggleSelectVertex(GraphVertex dv)
        {
            // Locate the clicked vertex
            Debug.WriteLine("Toggle select vertex");
            Int32 listIndex = GetVertexListIndex(dv.VertexId);

            if (dv.Selected)
            {
                this.VertexList.SelectRange(new ItemIndexRange(listIndex, 1));
                dv.Deselect();
            }
            else
            {
                this.VertexList.SelectRange(new ItemIndexRange(listIndex, 1));
                dv.Select();
            }

            VertexList.Items.F
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a vertex
        /// </summary>
        /// <param name="vertexToAdd"></param>
        /// <returns></returns>
        public Boolean AddVertex(GraphVertex vertexToAdd)
        {
            Debug.WriteLine("Adding vertex");
            //if (VertexExists(vertexToAdd.VertexId) == true)
            //{
            //    return false;
            //}

            vertexToAdd.VertexId = this.VertexCounter;
            this.Vertices.Add(vertexToAdd.VertexId, vertexToAdd);
            //this.AdjacencyMatrix.Add(vertexToAdd.VertexId, new List<Guid>());
            //this.IncidenceMatrix.Add(vertexToAdd.VertexId, new List<Guid>());
            this.LastVertexChange = ChangeType.Added;
            OnVerticesChanged(new VertexChangedEventArgs {
                ChangedVertex = vertexToAdd
            });
            this.VertexCounter++;
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// adjacent: whether there is an edge from vertex x to vertex y
        /// </summary>
        /// <param name="headVertexId"></param>
        /// <param name="tailVertexId"></param>
        /// <returns></returns>
        public Boolean Adjacent(UInt32 headVertexId, UInt32 tailVertexId)
        {
            Debug.WriteLine("checking if vertices are adjacent");
            if (this.Vertices.ContainsKey(headVertexId) == false)
            {
                return(false);
            }

            GraphVertex uv = this.Vertices[headVertexId];

            return(uv.Neighbors.Contains(tailVertexId));
            //foreach (UInt32 neighId in uv.Neighbors)
            //{
            //    if (neighId == tailVertexId)
            //    {
            //        return true;
            //    }
            //}

            //return false;
        }
Exemplo n.º 7
0
        public static Graph GenerateRandomGraph(
            UInt32 minNumVerts,
            UInt32 maxNumVerts,
            Double edgeProb)
        {
            Debug.WriteLine("generate random graph");

            Random rng      = new Random();
            Int32  numVerts = rng.Next((Int32)minNumVerts, (Int32)maxNumVerts);
            Graph  outGraph = new Graph();

            // Create the desired number of vertices
            for (int i = 0; i < numVerts; i++)
            {
                GraphVertex gv = new GraphVertex
                {
                    Value = rng.Next()
                };
                outGraph.AddVertex(gv);
            }

            int minNumEdges = 0;
            int maxNumEdges = (int)((outGraph.Vertices.Count * outGraph.Vertices.Count) * edgeProb);
            int numEdges    = rng.Next(minNumEdges, maxNumEdges);
            SortedSet <Tuple <uint, uint> > edgePairs = new SortedSet <Tuple <uint, uint> >();

            for (int i = 0; i < numEdges; i++)
            {
                Tuple <uint, uint> edgeTuple = GenerateEdge(rng, edgePairs, outGraph.VertexCounter);
                GraphEdge          ge        = new GraphEdge
                {
                    HeadVertexId = edgeTuple.Item1,
                    TailVertexId = edgeTuple.Item2,
                    Value        = rng.Next()
                };
                outGraph.AddEdge(ge);
            }


            //foreach (KeyValuePair<UInt32, GraphVertex> kvp1 in outGraph.Vertices)
            //{
            //    foreach (KeyValuePair<UInt32, GraphVertex> kvp2 in outGraph.Vertices)
            //    {
            //        if (kvp1.Value.VertexId != kvp2.Value.VertexId)
            //        {
            //            Double val = rng.NextDouble();
            //            if (val >= edgeProb)
            //            {
            //                GraphEdge ge = new GraphEdge
            //                {
            //                    HeadVertexId = kvp1.Value.VertexId,
            //                    TailVertexId = kvp2.Value.VertexId,
            //                    Value = rng.Next()
            //                };
            //                outGraph.AddEdge(ge);
            //            }
            //        }

            //    }
            //}

            return(outGraph);
        }