예제 #1
0
 public void RemoveOneHead(R head, Action <T> removeOne)   //移除 R 中所有值,每删除一个值调用一次 removeOne
 {
     if (headK_NodeV.Count == 0)
     {
         MyLog.Orange("已经没有数据了,还Remove?");
         return;
     }
     if (headK_NodeV.ContainsKey(head))
     {
         NodeBean node = headK_NodeV[head];
         while (node.NextNode != null)
         {
             NodeBean curNode = node;
             node = node.NextNode;
             if (null != removeOne)
             {
                 removeOne(curNode.Bean);
             }
         }
         if (null != removeOne)
         {
             removeOne(node.Bean);
         }
         headK_NodeV.Remove(head);
     }
     else
     {
         MyLog.Orange("都没有注册过这个火车头,Remove什么 —— " + head);
     }
 }
예제 #2
0
        //重写函数----------------------------------------------------------------------------------


        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (headK_NodeV.Count == 0)
            {
                sb.Append("没有数据".AddYellow());
            }
            else
            {
                sb.Append("当前总数有:".AddGreen()).Append(headK_NodeV.Count).Append("\n");
                foreach (R r in headK_NodeV.Keys)
                {
                    NodeBean node = headK_NodeV[r];
                    while (node.NextNode != null)
                    {
                        NodeBean curNode = node;
                        node = node.NextNode;
                        sb.Append("火车头: ".AddGreen()).Append(r).Append("   数据:".AddGreen()).Append(curNode.Bean).Append("\n");
                    }
                    sb.Append("火车头: ".AddGreen()).Append(r).Append("   数据:".AddGreen()).Append(node.Bean).Append("\n");
                }
            }
            return(sb.ToString());
        }
예제 #3
0
 private PointDrawer DrawConverter(NodeBean nodebean)
 {
     return(new PointDrawer(nodebean.id,
                            nodebean.attributes["name"].ToString(),
                            RandomShuffle.RandDouble(),
                            RandomShuffle.RandDouble()));
 }
예제 #4
0
        //操作----------------------------------------------------------------------------------
        public void DoOneHead(R head, Action <T> action, bool isLogRed)  //对一个火车头做操作
        {
            if (null == action)
            {
                MyLog.Red("传个Null值进来有什么意义?");
                return;
            }

            if (headK_NodeV.ContainsKey(head))
            {
                NodeBean node = headK_NodeV[head];
                while (node.NextNode != null)
                {
                    NodeBean curNode = node;
                    node = node.NextNode;
                    action(curNode.Bean);
                }
                action(node.Bean);
            }
            else
            {
                if (isLogRed)
                {
                    MyLog.Red("这个火车头没有添加过 —— " + head);
                }
            }
        }
예제 #5
0
        public void DrawPointer(NodeBean nodebean)
        {
            List <PointDrawer> lpd_temp = new List <PointDrawer>();
            List <RouteDrawer> lrd_temp = new List <RouteDrawer>();

            foreach (RouteDrawer rd in lrd)
            {
                if (rd.spoint.id.Equals(nodebean.id))
                {
                    lpd_temp.Add(rd.epoint);
                    lrd_temp.Add(rd);
                }
                if (rd.epoint.id.Equals(nodebean.id))
                {
                    lpd_temp.Add(rd.spoint);
                    lrd_temp.Add(rd);
                }
            }

            PointDrawer p     = findPointerById(nodebean.id);
            PointDrawer p_new = new PointDrawer(p.id, p.name, p.Longtitude * width, p.Latitude * height);

            Draw(DrawItem.POINT, PointType.CENTER, p_new);

            List <PointDrawer> lpp = convertToTrueListPoints(lpd_temp);

            Draw(DrawItem.POINT, PointType.EDAGE, lpp.ToArray());

            List <RouteDrawer> ll = convertToTrueListRoutes(lrd_temp, lpp, p_new);

            Draw(DrawItem.ROUTE, RouteType.EDAGE, ll.ToArray());
            graph.Flush();
        }
예제 #6
0
        Matrix graph;   // A

        /// <summary>
        ///   ?? 包含本身嘛?
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private int getEdgesCount(NodeBean node)
        {
            int r     = int.Parse(node.id);
            int count = 0;

            for (int j = 0; j < graph.Cols; j++)
            {
                if (!graph.getMNode(r, j).Value.Equals(0))
                {
                    count++;
                }
            }
            return(count);
        }
예제 #7
0
 //删----------------------------------------------------------------------------------
 public void RemoveOneValue(R head, T value)              // 移除 R 中一个值
 {
     if (headK_NodeV.Count == 0)
     {
         //                MyLog.Red("已经没有数据了,还Remove?");
         return;
     }
     if (headK_NodeV.ContainsKey(head))
     {
         NodeBean firstNode = headK_NodeV[head];
         if (firstNode.Bean.Equals(value))                //删除头节点
         {
             if (firstNode.NextNode != null)              //头节点中后面还有数据
             {
                 headK_NodeV[head] = firstNode.NextNode;  //指向头节点的指向下一个
             }
             else                                         //只有头节点后面没有跟,直接删除就行
             {
                 headK_NodeV.Remove(head);
             }
         }
         else                                              //这个节点在中间或者在尾部
         {
             while (!firstNode.NextNode.Bean.Equals(value) && firstNode.NextNode != null)
             {
                 firstNode = firstNode.NextNode;
             }
             if (!firstNode.NextNode.Bean.Equals(value))
             {
                 throw new Exception("怎么是不等于这个值? 那删除有什么意义?" + value);
             }
             //此时要删除firstNode.NextNode的NodeData和firstNode.NextNode.NextNode变成
             if (firstNode.NextNode.NextNode != null)     //表示是在中间
             {
                 firstNode.NextNode = firstNode.NextNode.NextNode;
             }
             else                                        //是尾部,直接去掉
             {
                 firstNode.NextNode = null;
             }
         }
     }
     else
     {
         MyLog.Orange("都没有注册过这个火车头,Remove什么 —— " + head);
     }
 }
예제 #8
0
        /// <summary>
        /// 鼠标单击节点时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            SimulatePaint(); //
            TreeNode node = e.Node;

            if (node.Level == 0)
            {
                // 为Group
                string[] elements = node.Text.Split(new char[] { ':' });
                string   id       = elements[1].Trim();

                GroupBean gbean = null;
                if (!hasCalculated)
                {
                    gbean = MyXml.findGroupById(id);
                }
                else
                {
                    try
                    {
                        int grp_count        = int.Parse(comboBox_GroupNum.SelectedItem.ToString());
                        List <GroupBean> lgb = agnes.getPartionSolution(grp_count);
                        gbean = lgb.Find(delegate(GroupBean gb)
                        {
                            return(gb.id.Equals(id));
                        });
                    }
                    catch
                    {
                        MessageBox.Show("请先选择分区数目", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }


                drawer.DrawGroup(gbean);
            }
            else
            {
                string[] elements = node.Text.Split(new char[] { ':' });
                string   id       = elements[0].Trim();
                NodeBean nbean    = MyXml.findNodeById(id);
                drawer.DrawPointer(nbean);
            }
            myPictureBox1.UpdateImg();
        }
예제 #9
0
        private List <NodeBean> getStOfNode(NodeBean node)
        {
            List <NodeBean> lres = new List <NodeBean>();

            int r = int.Parse(node.id);

            // 找邻居节点
            for (int j = 0; j < graph.Cols; j++)
            {
                if (!graph.getMNode(r, j).Value.Equals(0)) // 当A(r, j) != 0
                {
                    lres.Add(MyXml.findNodeById(j.ToString()));
                }
            }

            return(lres);
        }
예제 #10
0
 public void DoAllValue(Action <T> action)                 //对所有Value作操作
 {
     if (null == action)
     {
         MyLog.Red("传个Null值进来有什么意义?");
         return;
     }
     foreach (R r in headK_NodeV.Keys)
     {
         NodeBean node = headK_NodeV[r];
         while (node.NextNode != null)
         {
             NodeBean curNode = node;
             node = node.NextNode;
             action(curNode.Bean);
         }
         action(node.Bean);
     }
 }
예제 #11
0
        private List <NodeBean> getCrossSt(List <NodeBean> lst1, List <NodeBean> lst2)
        {
            List <NodeBean> lsCrt = new List <NodeBean>();

            foreach (NodeBean bean in lst1)
            {
                NodeBean b = lst2.Find(delegate(NodeBean nodebean)
                {
                    return(nodebean.id.Equals(bean.id));
                });

                if (b != null)
                {
                    lsCrt.Add(bean);
                }
                //if (lst2.Contains(bean)) // pay attention!
                //    lsCrt.Add(bean);
            }

            return(lsCrt);
        }
예제 #12
0
 //增----------------------------------------------------------------------------------
 public bool Add(R head, T value)
 {
     if (headK_NodeV.ContainsKey(head))                    //加过头的时候就向尾添加去
     {
         NodeBean node = headK_NodeV[head];
         while (node.NextNode != null)
         {
             if (node.Bean.Equals(value))
             {
                 MyLog.Red("添加包车头,出现同head,同value情况");
                 return(false);
             }
             node = node.NextNode;
         }
         node.NextNode = new NodeBean(value);
     }
     else                                                 //没加过头就加个头
     {
         headK_NodeV.Add(head, new NodeBean(value));
     }
     return(true);
 }
예제 #13
0
        public void RemoveLastHead(Action <T> removeTou, Action <T> removeWei) //removeTou:移除头的情况  removeWei:移除尾的情况
        {
            if (headK_NodeV.Count == 0)
            {
                MyLog.Orange("已经没有数据了,还Remove?");
                return;
            }
            List <R> l_Tmp   = new List <R>(headK_NodeV.Keys);
            R        lastOne = l_Tmp[l_Tmp.Count - 1];
            NodeBean node    = headK_NodeV[lastOne];

            if (node.NextNode == null)    //移除头的情况
            {
                if (null != removeTou)
                {
                    removeTou(node.Bean);
                }
                headK_NodeV.Remove(lastOne);
            }
            else
            {
                //1
                NodeBean proNode = node;
                //2
                NodeBean nextNode = proNode.NextNode;
                while (nextNode.NextNode != null)
                {
                    proNode  = nextNode;
                    nextNode = proNode.NextNode;
                }
                if (null != removeWei)
                {
                    removeWei(nextNode.Bean);
                }
                proNode.NextNode = null;
            }
        }
예제 #14
0
 public NodeBean(T bean)
 {
     Bean     = bean;
     NextNode = null;
 }
예제 #15
0
        private double getSimilarity(int i, int j)
        {
            NodeBean node_i = MyXml.findNodeById(i.ToString());
            NodeBean node_j = MyXml.findNodeById(j.ToString());

            List <NodeBean> lSt_i  = getStOfNode(node_i);      // St(i)
            List <NodeBean> lSt_j  = getStOfNode(node_j);      // St(j)
            List <NodeBean> lSt_ij = getCrossSt(lSt_i, lSt_j); // 获取St(i)和St(j)的交集

            double numerator = 0;

            // 分子
            foreach (NodeBean node in lSt_ij)
            {
                int count = getEdgesCount(node);
                if (count == 0)
                {
                    numerator = double.MaxValue;
                }
                else
                {
                    numerator += (1 / (double)(getEdgesCount(node)));
                }
            }

            // 分母
            double denominator = 0;
            double temp_1 = 0, temp_2 = 0;

            foreach (NodeBean node in lSt_i)
            {
                int c = (getEdgesCount(node));
                if (c == 0)
                {
                    temp_1 = double.MaxValue;
                }
                else
                {
                    temp_1 += (1 / (double)c);
                }
            }

            foreach (NodeBean node in lSt_j)
            {
                int c = (getEdgesCount(node));
                if (c == 0)
                {
                    temp_2 = double.MaxValue;
                }
                else
                {
                    temp_2 += (1 / (double)c);
                }
            }

            denominator = (Math.Sqrt(temp_1) * Math.Sqrt(temp_2));

            if (denominator.Equals(0))
            {
                return(double.MaxValue);
            }
            return(numerator / denominator);
        }