Exemplo n.º 1
0
 public static Bin_node get_min(ref Bin_node a, ref Bin_node b, ref int i)
 {
     if (a.weight < b.weight)
     {
         pos = i;
         return(a);
     }
     else if (a.weight > b.weight)
     {
         return(b);
     }
     else
     {
         if (a.node < b.node)
         {
             pos = i;
             return(a);
         }
         else
         {
             return(b);
         }
     }
 }
Exemplo n.º 2
0
 public static void swap_Bin(ref int i, ref int j)
 {
     tmp_swap    = Bin_heap[i];
     Bin_heap[i] = Bin_heap[j];
     Bin_heap[j] = tmp_swap;
 }
Exemplo n.º 3
0
        public static void Set_Mst()
        {
            size_Bin           = distinct.Count;
            Bin_heap           = new Bin_node[size_Bin];
            From_To            = new Bin_node[size_Bin];
            Bin_heap[0].weight = 0.0; Bin_heap[0].node = 0;
            pos = 0;
            tmp = Bin_heap[0];
            while (size_Bin != 0)
            {
                last = size_Bin - 1;
                swap_Bin(ref pos, ref last);
                pmp.weight = 10000000000.0; pmp.node = 1000000000;
                for (int i = 0; i < size_Bin - 1; i++)
                {
                    val = Bin_heap[i];
                    if (tmp.node != 0)
                    {
                        cost = generate_dif(ref tmp.node, ref val.node);
                    }
                    if (tmp.node == 0)   // start node
                    {
                        if (i != 0)
                        {
                            cost = generate_dif(ref tmp.node, ref i);
                            From_To[i].weight  = cost;
                            From_To[i].node    = tmp.node;
                            Bin_heap[i].weight = cost;
                            Bin_heap[i].node   = i;
                            pmp = get_min(ref Bin_heap[i], ref pmp, ref i);
                        }
                        else
                        {
                            cost = generate_dif(ref tmp.node, ref last);
                            From_To[last].weight = cost;
                            From_To[last].node   = tmp.node;
                            Bin_heap[i].weight   = cost;
                            Bin_heap[i].node     = last;
                            pmp = get_min(ref Bin_heap[i], ref pmp, ref i);
                        }
                    }
                    else if (cost < val.weight)
                    {
                        From_To[val.node].weight = cost;
                        From_To[val.node].node   = tmp.node;
                        Bin_heap[i].weight       = cost;
                        pmp = get_min(ref Bin_heap[i], ref pmp, ref i);
                    }
                    else
                    {
                        pmp = get_min(ref Bin_heap[i], ref pmp, ref i);
                    }
                }
                tmp = pmp;
                size_Bin--;
            }
            double sum = 0;

            for (int i = 1; i < distinct.Count; i++)
            {
                sum += From_To[i].weight;
                //   MessageBox.Show(From_To[i].weight.ToString());
            }
            MessageBox.Show(sum.ToString());
        }