Example #1
0
        public Destination(MiniDestination miniDestination)
        {
            this.BucketTable  = miniDestination.BucketTable;
            this.Best         = miniDestination.Best;
            this.BestNew      = miniDestination.BestNew;
            this.BestRelation = miniDestination.BestRelation;
            this.L            = miniDestination.L;
            this.destination  = miniDestination.destination;


            //rehydrate the parts of the object not passed in text.
            this.ChosenParent = new UInt32[this.Best.Length];
            this.ChosenPath   = new List <UInt32> [this.Best.Length];

            this.SecP = new bool[this.Best.Length];
            this.U    = new Int64[this.Best.Length];
            for (int i = 0; i < SecP.Length; i++)
            {
                SecP[i] = false;
            }
            //init the destination path to itself to kick things off
            //this.SecP[this.destination] = true; //*bug*
            this.ChosenPath[this.destination] = new List <UInt32>();
            this.ChosenPath[this.destination].Add(this.destination);
            this.ChosenParent[this.destination] = this.destination;
        }
Example #2
0
        public Destination(MiniDestination miniDestination)
        {
            this.BucketTable = miniDestination.BucketTable;
            this.Best = miniDestination.Best;
            this.BestNew = miniDestination.BestNew;
            this.BestRelation = miniDestination.BestRelation;
            this.L = miniDestination.L;
            this.destination = miniDestination.destination;

            //rehydrate the parts of the object not passed in text.
            this.ChosenParent = new UInt32[this.Best.Length];
            this.ChosenPath = new List<UInt32>[this.Best.Length];

            this.SecP = new bool[this.Best.Length];
            this.U = new Int64[this.Best.Length];
            for (int i = 0; i < SecP.Length; i++)
                SecP[i] = false;
            //init the destination path to itself to kick things off
            //this.SecP[this.destination] = true; //*bug*
            this.ChosenPath[this.destination] = new List<UInt32>();
            this.ChosenPath[this.destination].Add(this.destination);
            this.ChosenParent[this.destination] = this.destination;
        }
Example #3
0
        private static void miniDestinationToStream(MiniDestination d, StreamWriter output)
        {
            output.WriteLine("#destination " + d.destination);
            /*** output
               * i j as1 as2 as3
               * for each non-null element [i,j] in buckettable
               * ***/
            //this will barf if bucket table is null.
            output.WriteLine("#buckettable " + d.BucketTable.GetLength(0) + " " + d.BucketTable[0].GetLength(0));
            for (int i = 0; i < d.BucketTable.GetLength(0); i++)
            {
                for (int j = 0; j < d.BucketTable[0].GetLength(0); j++)
                {
                    if (d.BucketTable[i][ j] != null)
                    {
                        output.Write(i + " " + j + " ");
                        for (int k = 0; k < d.BucketTable[i][ j].Count; k++)
                            output.Write(d.BucketTable[i][ j][k] + " ");
                        output.Write("\n");
                    }
                }
            }
            /** output i as1 as2 as3
             * for each non-null list in the best[i] array. **/
            output.WriteLine("#best " + d.Best.Length);
            for (int i = 0; i < d.Best.Length; i++)
            {
                if (d.Best[i] != null)
                {
                    output.Write(i + " ");
                    for (int j = 0; j < d.Best[i].Count; j++)
                        output.Write(d.Best[i][j] + " ");
                    output.Write("\n");
                }
            }
            /*** output 1 line with all the values of bestrelation separated by ' ' since
             * it is a simple object **/
            output.WriteLine("#bestrelation " + d.BestRelation.Length);
            for (int i = 0; i < d.BestRelation.Length; i++)
                output.Write(d.BestRelation[i] + " ");
            output.Write("\n");

            output.WriteLine("#L " + d.L.Length);
            for (int i = 0; i < d.L.Length; i++)
                output.Write(d.L[i] + " ");
            output.Write("\n");
        }
Example #4
0
        private static MiniDestination miniDestinationFromStream(StreamReader input)
        {
            MiniDestination toreturn = new MiniDestination();
            //some constants to make this a little nicer.
            int currentlyReading = -1;
            const int buckettable = 0;
            const int best = 1;
            const int bestrelation = 2;
            const int l = 3;

            while (!input.EndOfStream)
            {
                string line = input.ReadLine().ToLower();
                string[] pieces = line.Split(space, StringSplitOptions.RemoveEmptyEntries);
                if (line[0] == '#')
                {
                    if (line.IndexOf("buckettable") >= 0)
                    {
                        currentlyReading = buckettable;
                        int numRows = int.Parse(pieces[1]);
                        int numCols = int.Parse(pieces[2]);
                        toreturn.BucketTable = new List<UInt32>[numRows][];
                        for (int i = 0; i < toreturn.BucketTable.Length; i++)
                            toreturn.BucketTable[i] = new List<UInt32>[numCols];

                    }
                    else if (line.IndexOf("bestrelation") >= 0)
                    {
                        currentlyReading = bestrelation;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.BestRelation = new byte[numRows];
                    }
                    else if (line.IndexOf("destination") >= 0)
                    {

                        UInt32 destNum = UInt32.Parse(pieces[1]);
                        toreturn.destination = destNum;
                    }
                    else if (line.IndexOf("best") >= 0)
                    {
                        currentlyReading = best;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.Best = new List<UInt32>[numRows];
                    }
                    else if (line.IndexOf("l") >= 0)
                    {
                        currentlyReading = l;
                        int numRows = int.Parse(pieces[1]);
                        toreturn.L = new byte[numRows];
                    }
                }
                else
                {
                    int row, col;
                    switch (currentlyReading)
                    {
                        case buckettable:
                            row = int.Parse(pieces[0]);
                            col = int.Parse(pieces[1]);
                            toreturn.BucketTable[row][ col] = new List<UInt32>();
                            for (int i = 2; i < pieces.Length; i++)
                                toreturn.BucketTable[row][col].Add(UInt32.Parse(pieces[i]));
                            break;
                        case best:
                            row = int.Parse(pieces[0]);
                            toreturn.Best[row] = new List<UInt32>();
                            for (int i = 1; i < pieces.Length; i++)
                                toreturn.Best[row].Add(UInt32.Parse(pieces[i]));
                            break;
                        case bestrelation:
                            for (int i = 0; i < pieces.Length; i++)
                                toreturn.BestRelation[i] = byte.Parse(pieces[i]);
                            break;
                        case l:
                            for (int i = 0; i < pieces.Length; i++)
                                toreturn.L[i] = byte.Parse(pieces[i]);
                            break;
                    }
                }
            }

            return toreturn;
        }
Example #5
0
 public static void miniDestinationToBlob(MiniDestination d, string containerName, string blobName)
 {
     //set up streamwriter for the blob.
     StreamWriter output = new StreamWriter(BlobLibrary.getBlobWriteStream(containerName, blobName));
     miniDestinationToStream(d, output);
     output.Close();
 }
Example #6
0
 private static double getAverageBestSize(MiniDestination d,List<UInt32> careAbout)
 {
     double avg = 0;
     double points = 0;
     for (int i = 0; i < d.Best.Length; i++)
     {
         if (careAbout.Contains((UInt32)i))
         {
             if (d.Best[i] != null)
             {
                 avg += d.Best[i].Count;
                 points++;
             }
         }
     }
     return avg / points;
 }
Example #7
0
 private static double getAverageBestSize(MiniDestination d)
 {
     double avg=0;
     double points=0;
     for (int i = 0; i < d.Best.Length; i++)
     {
         if(d.Best[i]!=null)
         {
             avg+=d.Best[i].Count;
             points++;
         }
     }
     return avg/points;
 }