コード例 #1
0
        public Neighborhood GetNeighborhood(Vertex v)
        {
            List <Vertex> SortedNeighbors = new List <Vertex>(v.AdjacentVertices);

            SortedNeighbors.Sort(new EdgeWeightComparer(v));

            HashSet <Vertex> NN = new HashSet <Vertex>();

            if (SortedNeighbors.Count > 0)
            {
                double w      = v.GetEdge(SortedNeighbors[0]).Weight;
                double maxSim = this.GetSimilarity(v, SortedNeighbors[0]);
                foreach (Vertex vv in SortedNeighbors)
                {
                    if (this.GetSimilarity(v, vv) == maxSim) //NN jsou soudedi s maximalni vahou hrany
                    {
                        NN.Add(vv);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Neighborhood nh = new Neighborhood(SortedNeighbors, NN);

            return(nh);
        }
コード例 #2
0
        private void calculateNetworkRepresentativeness()
        {
            foreach (Vertex v in this.network.Vertices.Values)
            {
                this.Representatives.Add(v, new Representative(v, this));
            }

            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Network.MAX_DEGREE_OF_PARALLELISM
            };

            Parallel.ForEach(this.network.Vertices.Values, options, v => //parallel
            {
                Neighborhood nh = this.SimilarityStrategy.GetNeighborhood(v);
                foreach (Vertex v2 in nh.Neighbors)
                {
                    this.Representatives[v].AllSortedEdges.Add(v.GetEdge(v2));
                    this.Representatives[v2].IncNeighborsWeight(1);

                    if (nh.NearestNeighbors.Contains(v2)) //nejblizsi sousede
                    {
                        this.Representatives[v2].IncNearestNeighborsWeight(1);
                        this.Representatives[v].RepresentativeEdges.Add(v.GetEdge(v2)); //hrany s maximalni vahou
                    }
                }
            });
        }