Пример #1
0
        /*
         * Function: Create
         * Description:实现IfCreateStrategy接口
         * Parameters:
         *      CreateParameter cParam
         * Return Value:cNet
         */
        cNet IfCreateStrategy.Create(CreateParameter cParam)
        {
            cNet NewNet = null;
            int intNum, intInit, intLimit;
            int i;

            intNum = cParam.Number;
            intInit = cParam.Para1;
            intLimit = cParam.Para2;
            //生成网络实例,并初始化每个节点实例
            NewNet = new cNet(intNum);
            for (i = 0; i < intNum; i++)
            {
                NewNet.Network.Add (new cNode(i));
            }
            //根据用户选择,确定使用的初始化策略
            if (cParam.Option== true)
            {
                BA_InitNet(ref NewNet, intInit, "FULL");
            }
            else
            {
                BA_InitNet(ref NewNet, intInit, "ER");
            }
            //遍历节点,进行加边操作
            for (i = intInit ; i < intNum; i++)
            {
                BA_AddEdge(ref NewNet, i, intLimit);
            }
            //返回处理完毕的节点
            return NewNet;
        }
Пример #2
0
 /*
  * Function: Create
  * Description:实现IfCreateStrategy接口
  * Parameters:
  *      CreateParameter cParam
  * Return Value:cNet
  */
 cNet IfCreateStrategy.Create(CreateParameter cParam)
 {
     cNet NewNet = null;
     int intNum, intNei, intPro;
     int i;
     //获取参数
     intNum = cParam.Number;
     intNei = cParam.Para1;
     intPro = cParam.Para2;
     //构建网络并初始化节点实例
     NewNet = new cNet(intNum);
     for (i = 0; i < intNum; i++)
     {
         NewNet.Network.Add(new cNode(i));
     }
     //创建最近邻网络
     SW_CreateNNC(ref NewNet, intNum, intNei);
     //根据用户选项选择WS小世界或NW小世界
     if (cParam.Option == true)
     {
         SW_RandomReLink(ref NewNet, intNum, intNei, intPro);
     }
     else
     {
         SW_RandomAddEdge(ref NewNet, intNum, intNei, intPro);
     }
     return NewNet;
 }
Пример #3
0
 /*
  * Function: Create
  * Description:实现IfCreateStrategy接口
  * Parameters:
  *      CreateParameter cParam
  * Return Value:cNet
  */
 cNet IfCreateStrategy.Create(CreateParameter cParam)
 {
     cNet NewNet = null;
     int intNum, intEdge, intLink;
     int i;
     //获取参数
     intNum = cParam.Number;
     intEdge = cParam.Para1;
     intLink = cParam.Para2;
     //生成网络,并初始化节点
     NewNet = new cNet(intNum);
     for (i = 0; i < intNum; i++)
     {
         NewNet.Network.Add(new cNode(i));
     }
     //根据用户选项确定加边算法
     if (cParam.Option == true)
     {
         while (NewNet.intEdge < intEdge)
         {
             ER_AddEdge_Edge(ref NewNet, intNum);
         }
     }
     else
     {
         ER_AddEdge_Pro(ref NewNet, intNum, intLink);
     }
     return NewNet;
 }
Пример #4
0
        //OK按钮响应函数
        private void OK_Button_Click(object sender, EventArgs e)
        {
            CreateParameter cParam;
            IfCreateStrategy Creator;
            int iNumber, iPara1, iPara2;
            bool bOption = true;

            if (TypeCombo.Text == "")
            {
                MessageBox.Show("请先选择一种网络类型!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
            }
            Cursor = Cursors.WaitCursor;
            this.Refresh();
            //根据用户选择项,装载不同参数
            switch (TypeCombo.Text) //选择网络类型
            {
                case "BA无标度网络":
                    iNumber = Convert.ToInt32(BANum.Value);
                    iPara1 = Convert.ToInt32(BAInit.Value);
                    iPara2 = Convert.ToInt32(BALimit.Value);
                    if (FullNet.Checked == true)
                    {
                        bOption = true;
                    }
                    else
                    {
                        bOption = false;
                    }
                    Creator = new BAStrategy();
                    break;
                case "ER随机图":
                    iNumber = Convert.ToInt32(ERNum.Value);
                    iPara1 = Convert.ToInt32(EREdge.Value);
                    iPara2 = Convert.ToInt32(ERPro.Value);
                    if (BaseEdge.Checked == true)
                    {
                        bOption = true;
                    }
                    else
                    {
                        bOption = false;
                    }
                    Creator = new ERStrategy();
                    break;
                case "小世界网络":
                    iNumber = Convert.ToInt32(SWNum.Value);
                    iPara1 = Convert.ToInt32(SWnei.Value);
                    iPara2 = Convert.ToInt32(SWPro.Value);
                    if (WS_SW.Checked == true)
                    {
                        bOption = true;
                    }
                    else if (NW_SW.Checked == true)
                    {
                        bOption = false;
                    }
                    Creator = new SWstrategy();
                    break;
                default:
                    return;
            }
            cParam = new CreateParameter(iNumber, iPara1, iPara2, bOption);
            //调用接口Create创建函数
            cNetwork = Creator.Create(cParam);
            Cursor = Cursors.Arrow;
            if (cNetwork == null)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Abort;
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            this.Close();
        }