예제 #1
0
        static public void ExportToAtr(HClusterNode node, string fileName)
        {
            List <HClusterNode>   leafs    = node.GetLeaves();
            List <List <string> > clusters = new List <List <string> >();

            foreach (var cl in leafs)
            {
                clusters.Add(cl.setStruct);
            }

            string       newName = Path.GetFileNameWithoutExtension(fileName) + "_leafs.dat";
            StreamWriter stream  = new StreamWriter(newName);

            Save(clusters, stream, true);
            stream.Close();
            stream = new StreamWriter(fileName);
            Queue <HClusterNode> ww = new Queue <HClusterNode>();
            Dictionary <HClusterNode, string> nodeName = new Dictionary <HClusterNode, string>();
            Dictionary <string, int>          leafNum  = new Dictionary <string, int>();
            int counter = 1;

            ww.Enqueue(node);
            while (ww.Count != 0)
            {
                HClusterNode aux = ww.Dequeue();
                if (aux.joined != null)
                {
                    foreach (var item in aux.joined)
                    {
                        ww.Enqueue(item);
                        item.parent = aux;
                    }
                }
            }


            foreach (var item in leafs)
            {
                //ww.Enqueue(item);
                leafNum.Add(item.refStructure, counter++);
            }
            ww.Enqueue(node);
            int nodeCounter = 0;

            while (ww.Count != 0)
            {
                HClusterNode aux = ww.Dequeue();


                string parentNode;
                if (!nodeName.ContainsKey(aux))
                {
                    parentNode = "Node_" + (++nodeCounter);
                    nodeName.Add(aux, parentNode);
                }
                else
                {
                    parentNode = nodeName[aux];
                }
                if (aux.joined != null)
                {
                    List <HClusterNode> hList = aux.joined;

                    for (int i = 0; i < hList.Count; i++)
                    {
                        string name1;
                        if (nodeName.ContainsKey(hList[i]))
                        {
                            name1 = nodeName[hList[i]];
                        }
                        else
                        {
                            name1 = hList[i].refStructure + "_" + leafNum[hList[i].refStructure];
                            if (hList[i].joined != null)
                            {
                                name1 = "Node_" + (++nodeCounter);
                            }
                            nodeName.Add(hList[i], name1);
                        }
                        for (int j = i + 1; j < hList.Count; j++)
                        {
                            string name2;
                            if (nodeName.ContainsKey(hList[j]))
                            {
                                name2 = nodeName[hList[j]];
                            }
                            else
                            {
                                name2 = hList[j].refStructure + "_" + leafNum[hList[j].refStructure];
                                if (hList[j].joined != null)
                                {
                                    name2 = "Node_" + (++nodeCounter);
                                }
                                nodeName.Add(hList[j], name2);
                            }

                            stream.WriteLine(parentNode + " " + name1 + " " + name2 + " " + aux.realDist);
                        }
                        ww.Enqueue(aux.joined[i]);
                    }
                }
            }
            stream.Close();
        }