示例#1
0
        /*
         * Function: ER_AddEdge_Edge
         * Description:随机加边函数
         * Parameters:
         *      ref cNet cNetwork   待处理网络
         *      int iNum    网络节点总数
         * Return Value:
         */
        private void ER_AddEdge_Edge(ref cNet cNetwork, int iNum)
        {
            Random magic1 = new Random(DateTime.Now.Millisecond * iNum);
            Random magic2;
            int intSource, intTarget;

            magic2 = new Random(DateTime.Now.Millisecond * magic1.Next(0, 1000));
            magic1 = new Random(DateTime.Now.Millisecond * magic2.Next(1000, 2000));

            intSource = magic1.Next(0, iNum - 1);
            intTarget = magic2.Next(0, iNum - 1);
            if (cNetwork.Network[intSource].Contains(intTarget) == false)
            {
                cNetwork.AddEdge(intSource, intTarget, 1);
            }
        }
示例#2
0
        /*
         * Function: SW_CreateNNC
         * Description:创建最近邻网络函数
         * Parameters:
         *      ref cNet cNetwork   待处理网络
         *      int iNum    网络节点总数
         *      int iNei   待连接邻居数
         * Return Value:
         */
        private void SW_CreateNNC(ref cNet cNetwork, int iNum, int iNei)//生成最近邻网络
        {

            int intCount;
            int intTarget;
            int i, j;

            intCount = iNei / 2;
            for (i = 0; i < iNum; i++)
            {
                for (j = 1; j <= intCount; j++)
                {
                    intTarget = i - j;
                    if (intTarget < 0)
                    {
                        intTarget += iNum;
                    }
                    cNetwork.AddEdge(i, intTarget, 1);
                }
            }
        }
示例#3
0
 /*
  * Function: Edge
  * Description:BA网络初始化函数
  * Parameters:
  *      ref cNet cNetwork 待初始化网络
  *      int iInit 初始处理节点
  *      string sType 初始算法类型
  * Return Value:
  */
 private void BA_InitNet(ref cNet cNetwork, int iInit, string sType)
 {
     int i, j;
     Random magic1;
     //两两遍历初始节点
     for (i = 1; i < iInit; i++)
     {
         for (j = 0; j < iInit - 1; j++)
         {
             if (i > j)
             {//全联通策略直接加边,ER策略根据概率随机加边。
                 if (sType == "ER")
                 {
                     magic1 = new Random(DateTime.Now.Millisecond * i * j);
                     if (magic1.Next(0, 100) > 50)
                     {
                         continue;
                     }
                 }
                 cNetwork.AddEdge(i, j, 1);
             }
         }
     }
 }
示例#4
0
        /*
         * Function: Edge
         * Description:BA网络初始化函数
         * Parameters:
         *      ref cNet cNetwork 待初始化网络
         *      int iNum 节点编号
         *      int iLimit 连边上限
         * Return Value:
         */
        private void BA_AddEdge(ref cNet cNetwork, int iNum, int iLimit)
        {
            Random magic1;
            int i, intLink, intCount;
            double dubLink;

            intCount = 0;
            while (intCount < iLimit)
            {//每个节点加的边小于用户限制
                for (i = 0; i < iNum; i++)
                {
                    if (cNetwork.Network[iNum].Contains(i) == false)
                    {//如果当前节点和目标节点间没有连边
                        dubLink = cNetwork.Network[i].Degree * 1.0 / (cNetwork.intEdge * 2);
                        intLink = Convert.ToInt32(Math.Round(dubLink, 2) * 100);
                        magic1 = new Random(DateTime.Now.Millisecond * intLink);
                        if (magic1.Next(0, 100) < intLink)
                        {//如果概率满足设置则加边
                            cNetwork.AddEdge(iNum, i, 1);
                            intCount += 1;
                        }
                    }
                }
            }
        }
示例#5
0
        /*
         * Function: SW_RandomReLink
         * Description:随机重连函数
         * Parameters:
         *      ref cNet cNetwork   待处理网络
         *      int iNum    网络节点总数
         *      int iNei   待连接邻居数
         *      int iPro   重连概率
         * Return Value:
         */
        private void SW_RandomReLink(ref cNet cNetwork, int iNum, int iNei, int iPro)//随机重连
        {
            int intTarget, newTarget, intPoint, intCount;
            Random magic1, magic2;
            int[] tmp, mapTmp;
            int i, j;

            for (i = 0; i < iNum; i++)
            {//遍历网络中所有节点
                intPoint = cNetwork.Network[i].Degree;
                tmp = new int[intPoint];
                mapTmp = new int[intPoint];
                intCount = 0;
                foreach (Edge edge in cNetwork.Network[i])
                {//遍历节点所有连边,并记录下来
                    tmp[intCount] = edge.Target;
                    mapTmp[intCount] = 0;
                    intCount += 1;
                }
                for (j = 0; j < intPoint; j++)
                {//针对每条边计算是否需要重连
                    intTarget = tmp[j];
                    magic1 = new Random(DateTime.Now.Millisecond * i * intTarget);
                    if (magic1.Next(0, 100) < iPro)
                    {
                        do
                        {
                            magic2 = new Random(DateTime.Now.Millisecond * magic1.Next(10, 100));
                            newTarget = magic1.Next(0, iNum-1);
                        } while (intTarget == newTarget || cNetwork.Network[i].Contains(newTarget) == true);
                    }
                }
                for (j = 0; j < intPoint; j++)
                {
                    if (mapTmp[j] > 0)
                    {//符合重连条件的进行重连
                        cNetwork.DecEdge(i, tmp[j]);
                        cNetwork.AddEdge(i, mapTmp[j], 1);
                    }
                }
            }
        }
示例#6
0
        /*
         * Function: SW_RandomAddEdge
         * Description:随机加边函数
         * Parameters:
         *      ref cNet cNetwork   待处理网络
         *      int iNum    网络节点总数
         *      int iNei   待连接邻居数
         *      int iPro   加边概率
         * Return Value:
         */
        private void SW_RandomAddEdge(ref cNet cNetwork, int iNum, int iNei, int iPro)//随机加边
        {
            Random magic1 = new Random(DateTime.Now.Millisecond * iNum);
            Random magic2;
            int intSource, intTarget;

            while (cNetwork.intEdge < iNum * iNei)
            {
                magic2 = new Random(DateTime.Now.Millisecond * magic1.Next(0, 1000));
                magic1 = new Random(DateTime.Now.Millisecond * magic2.Next(1000, 2000));

                intSource = magic1.Next(0, iNum - 1);
                intTarget = magic2.Next(0, iNum - 1);
                if (cNetwork.Network[intSource].Contains(intTarget) == false && intSource != intTarget)
                {
                    cNetwork.AddEdge(intSource, intTarget, 1);
                }
            }
        }
示例#7
0
 /*
  * Function: Edge
  * Description:根据概率加边函数
  * Parameters:
  *      ref cNet cNetwork   待处理网络
  *      int iNum    网络节点总数
  *      int iLink   预设概率
  * Return Value:
  */
 private void ER_AddEdge_Pro(ref cNet cNetwork, int iNum, int iLink)
 {
     int i, j;
     Random magic1;
     for (i = 0; i < iNum; i++)
     {
         for (j =i + 1; j < iNum - 1; j++)
         {
             magic1 = new Random(DateTime.Now.Millisecond * (i+1) * j);
             if (magic1.Next(0, 100) > iLink)
             {
                 continue;
             }
             cNetwork.AddEdge(i, j, 1);
         }
     }
 }