コード例 #1
0
        public Tuple <List <int>, double> gs(double b, List <int> range)
        {
            HashSet <int> seeds   = new HashSet <int>();
            List <int>    seedSet = new List <int>();
            //CELF Algorithm
            PriorityQueue <VNode> pq     = new PriorityQueue <VNode>(range.Count + 1, new VNodeComparer());
            List <bool>           update = new List <bool>();

            foreach (int u in range)
            {
                VNode node = new VNode(u, bg.numS);
                pq.Push(node);
            }
            for (int u = 0; u < bg.numV; ++u)
            {
                update.Add(false);
            }
            double total_gain = 0.0;

            while (b > 0.0 && pq.Count > 0)
            {
                for (int u = 0; u < bg.numV; ++u)
                {
                    update[u] = false;
                }
                int    next = 0;
                double gain = 0;
                while (true)
                {
                    VNode node  = pq.Pop();
                    int   max_u = node.id;
                    if (update[max_u])
                    {
                        next = max_u;
                        gain = node.val;
                        break;
                    }
                    else
                    {
                        double sum = 0;
                        foreach (int sid in bg.V2S[max_u])
                        {
                            sum += prob_edge[sid];
                        }
                        VNode n1 = new VNode(max_u, sum);
                        pq.Push(n1);
                        update[max_u] = true;
                    }
                }
                b          -= 1.0;
                total_gain += gain;
                ChangeAllocation(next, 1.0);
                seeds.Add(next);
                seedSet.Add(next);
            }
            foreach (int point in seedSet)
            {
                ChangeAllocation(point, 0.0);
            }
            return(new Tuple <List <int>, double>(seedSet, total_gain * bg.numV / bg.numS));
        }
コード例 #2
0
ファイル: Bipartite.cs プロジェクト: Planet-B612/Limited_IM
        //Given seed probability P, find the best k nodes that can maximize influence spread
        public Tuple <List <int>, double> Greedy(int k, List <double> P)
        {
            HashSet <int> seeds   = new HashSet <int> ();
            List <int>    seedSet = new List <int> ();
            List <double> edgeW   = new List <double> ();

            for (int h = 0; h < numS; ++h)
            {
                edgeW.Add(1.0);
            }


            //CELF Algorithm
            PriorityQueue <VNode> pq     = new PriorityQueue <VNode> (numV + 1, new VNodeComparer());
            List <bool>           update = new List <bool> ();

            for (int u = 0; u < numV; ++u)
            {
                VNode node = new VNode(u, numS);
                pq.Push(node);
                update.Add(false);
            }

            double total_gain = 0.0;

            for (int i = 0; i < k; ++i)
            {
                for (int u = 0; u < numV; ++u)
                {
                    update [u] = false;
                }
                int    next = 0;
                double gain = 0;
                while (true)
                {
                    VNode node  = pq.Pop();
                    int   max_u = node.id;

                    if (update [max_u])
                    {
                        next = max_u;
                        gain = node.val;
                        break;
                    }
                    else
                    {
                        double sum = 0;
                        if (i == 0)
                        {
                            sum = V2S[max_u].Count * P[max_u];
                        }
                        else
                        {
                            foreach (int sid in V2S[max_u])
                            {
                                sum += edgeW[sid] * P[max_u];
                            }
                        }
                        VNode n1 = new VNode(max_u, sum);
                        pq.Push(n1);
                        update [max_u] = true;
                    }
                }
                total_gain += gain;
                foreach (int sid in V2S[next])
                {
                    edgeW [sid] = edgeW [sid] * (1 - P [next]);
                }
                seeds.Add(next);
                seedSet.Add(next);
            }

            return(new Tuple <List <int>, double> (seedSet, total_gain * numV / numS));
        }