예제 #1
0
파일: HSP_app.cs 프로젝트: KeithNel/natix
        // Computes the edges of an object (static mode)
        public static IList<int> ComputeEdges(object q,MetricDB db, bool[] subset=null)
        {
            IList<int> edges=new List<int>();
            Set Candidates;
            if (subset==null) Candidates=new Set(db.Count);
            else Candidates=new Set(db.Count,subset);

            double[] distances=new double[db.Count];
            int[] objs=new int[db.Count]; // <-- used in the sorting
            for(int j=0;j<db.Count;j++)
            {
                distances[j]=db.Dist(q,db[j]);
                objs[j]=j;
            }
            Sorting.Sort(distances,objs);

            while (Candidates.Cardinality>0 && distances[Candidates.First]==0 )
                Candidates.Remove(Candidates.First);

            int outdegree=0;

            while (Candidates.Cardinality>0)
            {
                //Console.WriteLine("Candidates:{0}",Candidates.Cardinality);

                // get closest element
                int closest_id=objs[Candidates.First];
                outdegree++;
                Candidates.actual=Candidates.First;
                edges.Add(closest_id);

                // remove elements in the forbidden area
                while(Candidates.actual != -1)
                {
                    //Console.WriteLine(Candidates.actual);
                    if ( distances[Candidates.actual] > db.Dist(db[closest_id],db[objs[Candidates.actual]]))
                    {
                        Candidates.Remove(Candidates.actual);
                        continue;
                        //Console.WriteLine("Removed");
                    }
                    Candidates.Next();
                }

            }
            //this.sum_out_degree+=edges.Count;
            //if (edges.Count > this.max_out_degree)
            //	this.max_out_degree=edges.Count;
            //if (edges.Count < this.min_out_degree || this.min_out_degree==0)
            //	this.min_out_degree=edges.Count;

            return edges;
        }
예제 #2
0
파일: HSP_app.cs 프로젝트: KeithNel/natix
        // Computes the edges of an object
        public IList<int> ComputeEdges(int obj_id)
        {
            IList<int> edges=new List<int>();
            Set Candidates=new Set(this.space.Count);

            double[] distances=new double[this.space.Count];
            int[] objs=new int[this.space.Count]; // <-- used in the sorting
            for(int j=0;j<this.space.Count;j++)
            {
                distances[j]=this.space.Dist(this.space[obj_id],this.space[j]);
                objs[j]=j;
            }
            Sorting.Sort(distances,objs);

            while (Candidates.Cardinality>0 && distances[Candidates.First]==0)
                Candidates.Remove(Candidates.First);

            int outdegree=0;

            while (Candidates.Cardinality>0)
            {
                //Console.WriteLine("Candidates:{0}",Candidates.Cardinality);

                // get closest element
                int closest_id=objs[Candidates.First];
                outdegree++;
                Candidates.actual=Candidates.First;
                edges.Add(closest_id);

                // remove elements in the forbidden area
                while(Candidates.actual != -1)
                {
                    //Console.WriteLine(Candidates.actual);
                    if ( distances[Candidates.actual] > space.Dist(space[closest_id],space[objs[Candidates.actual]]))
                    {
                        Candidates.Remove(Candidates.actual);
                        continue;
                        //Console.WriteLine("Removed");
                    }
                    Candidates.Next();
                }

            }
            this.sum_out_degree+=edges.Count;
            if (edges.Count > this.max_out_degree)
                this.max_out_degree=edges.Count;
            if (edges.Count < this.min_out_degree || this.min_out_degree==0)
                this.min_out_degree=edges.Count;

            return edges;
        }