public static DataTable buildIDMAP()
        {
            string    sql         = "";
            DataTable insertTable = new DataTable();

            insertTable.Columns.Add("Node", typeof(string));
            insertTable.Columns.Add("px", typeof(byte[]));
            sql = "select Node from NodeDegree2 order by Node collate Latin1_General_BIN";
            DataTable Nodes = DataHelpe.GetDataTable(sql);
            int       i     = 1;

            foreach (DataRow t in Nodes.Rows)
            {
                byte[] px = BitConverter.GetBytes(i);
                Array.Reverse(px, 0, px.Length);
                string node = (string)t["Node"];
                insertTable.Rows.Add(node, px);
                i++;
            }
            return(insertTable);
        }
예제 #2
0
        public void build3HopIndex(int nodes, string indexTable)
        {
            List <int> firstForwardLevelNeighbor   = new List <int>();
            List <int> firstBackwardLevelNeighbor  = new List <int>();
            List <int> secondForwardLevelNeighbor  = new List <int>();
            List <int> secondBackwardLevelNeighbor = new List <int>();
            List <int> thirdForwardLevelNeighbor   = new List <int>();
            List <int> thirdBackwardLevelNeighbor  = new List <int>();
            List <int> discoveredForwardIDs        = new List <int>();
            List <int> discoveredBackwardIDs       = new List <int>();
            int        j = 0;
            int        k = 0;
            //change the number of nodes in a dataset correspondingly
            int       numberOfNodes = nodes;
            DataTable insertTable   = new DataTable();

            insertTable.Columns.Add("ID", typeof(byte[]));
            insertTable.Columns.Add("Distance", typeof(int));
            insertTable.Columns.Add("Sigbyte", typeof(byte[]));
            insertTable.Columns.Add("Count", typeof(int));
            insertTable.Columns.Add("IDs", typeof(byte[]));
            List <List <int> > firstForwardNeighbors  = new List <List <int> >();
            List <List <int> > firstBackwardNeighbors = new List <List <int> >();
            string             sql     = "select ID1, ID2 from idGraph";
            DataTable          idGraph = DataHelpe.GetDataTable(sql);

            for (int i = 1; i < numberOfNodes + 1; i++)
            {
                firstForwardNeighbors.Add(directedNeighborhood.forwardFirstLevelNeighbor(i, idGraph));
                firstBackwardNeighbors.Add(directedNeighborhood.backwardFirstLevelNeighbor(i, idGraph));
                Console.WriteLine(i);
            }
            Console.WriteLine("OK");
            for (int i = 1; i < numberOfNodes + 1; i++)
            {
                firstForwardLevelNeighbor.AddRange(firstForwardNeighbors[i - 1]);
                if (!(firstForwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(firstForwardLevelNeighbor, i, 1));
                }
                firstBackwardLevelNeighbor.AddRange(firstBackwardNeighbors[i - 1]);
                if (!(firstBackwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(firstBackwardLevelNeighbor, i, -1));
                }
                secondForwardLevelNeighbor = directedNeighborhood.nextForwardLevelNeighbor(firstForwardLevelNeighbor, firstForwardLevelNeighbor, firstForwardNeighbors);
                if (!(secondForwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(secondForwardLevelNeighbor, i, 2));
                }
                secondBackwardLevelNeighbor = directedNeighborhood.nextBackwardLevelNeighbor(firstBackwardLevelNeighbor, firstBackwardLevelNeighbor, firstBackwardNeighbors);
                if (!(secondBackwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(secondBackwardLevelNeighbor, i, -2));
                }
                discoveredForwardIDs.AddRange(firstForwardLevelNeighbor);
                discoveredForwardIDs.AddRange(secondForwardLevelNeighbor);
                discoveredBackwardIDs.AddRange(firstBackwardLevelNeighbor);
                discoveredBackwardIDs.AddRange(secondBackwardLevelNeighbor);
                thirdForwardLevelNeighbor = directedNeighborhood.nextForwardLevelNeighbor(discoveredForwardIDs, secondForwardLevelNeighbor, firstForwardNeighbors);
                if (!(thirdForwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(thirdForwardLevelNeighbor, i, 3));
                }
                thirdBackwardLevelNeighbor = directedNeighborhood.nextBackwardLevelNeighbor(discoveredBackwardIDs, secondBackwardLevelNeighbor, firstBackwardNeighbors);
                if (!(thirdBackwardLevelNeighbor == null))
                {
                    insertTable.Merge(directedNeighborhood.insertIntoIndexing(thirdBackwardLevelNeighbor, i, -3));
                }
                j++;
                if (j > 99 | i == numberOfNodes)
                {
                    j = 0;
                    string      connection  = DataHelpe.Constr;
                    SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(connection);
                    sqlBulkCopy.DestinationTableName = indexTable;
                    sqlBulkCopy.BulkCopyTimeout      = 600;
                    sqlBulkCopy.WriteToServer(insertTable);
                    sqlBulkCopy.Close();
                    insertTable.Clear();
                    Console.WriteLine(k);
                    k++;
                }
                firstForwardLevelNeighbor.Clear();
                firstBackwardLevelNeighbor.Clear();
                secondForwardLevelNeighbor.Clear();
                secondBackwardLevelNeighbor.Clear();
                thirdForwardLevelNeighbor.Clear();
                thirdBackwardLevelNeighbor.Clear();
                discoveredForwardIDs.Clear();
                discoveredBackwardIDs.Clear();
            }
        }
예제 #3
0
        public static Dictionary <int, List <NBEntry> > loadNBIndex(string NBindexTable)
        {
            int       NBIDlength = 3;
            string    sql        = "select * from " + NBindexTable + " order by ID";
            DataTable NBTable    = DataHelpe.GetDataTable(sql);
            Dictionary <int, List <NBEntry> > NBindex = new Dictionary <int, List <NBEntry> >();
            int            currentID         = 0;
            List <NBEntry> indexforCurrentID = new List <NBEntry>();

            foreach (DataRow di in NBTable.Rows)
            {
                byte[] binaryNodeID = di.Field <byte[]>("ID");
                Array.Reverse(binaryNodeID, 0, binaryNodeID.Length);
                int rowID = BitConverter.ToInt32(binaryNodeID, 0);
                if (rowID != currentID)
                {
                    //when the node ID changes, copy all the index for this ID and move to next one
                    if (indexforCurrentID.Count != 0)
                    {
                        List <NBEntry> indexEntryCopy = new List <NBEntry>();
                        indexEntryCopy.AddRange(indexforCurrentID);
                        NBindex.Add(currentID, indexEntryCopy);
                        indexforCurrentID.Clear();
                    }
                    currentID = rowID;
                    NBEntry entry = new NBEntry();
                    entry.Distance = di.Field <int>("Distance");
                    byte[] SigbyteField = di.Field <byte[]>("Sigbyte");
                    entry.Sigbyte = SigbyteField[0];
                    entry.Count   = di.Field <int>("Count");
                    byte[]        IDsField  = di.Field <byte[]>("IDs");
                    List <byte[]> ListOfIDs = new List <byte[]>();
                    for (int i = 0; i < IDsField.Count() / (NBIDlength - 1); i++)
                    {
                        byte[] singleID = new byte[2];
                        singleID[0] = IDsField[2 * i];
                        singleID[1] = IDsField[2 * i + 1];
                        ListOfIDs.Add(singleID);
                    }
                    entry.IDs = ListOfIDs;
                    indexforCurrentID.Add(entry);
                }
                else
                {
                    NBEntry entry = new NBEntry();
                    entry.Distance = di.Field <int>("Distance");
                    byte[] SigbyteField = di.Field <byte[]>("Sigbyte");
                    entry.Sigbyte = SigbyteField[0];
                    entry.Count   = di.Field <int>("Count");
                    byte[]        IDsField  = di.Field <byte[]>("IDs");
                    List <byte[]> ListOfIDs = new List <byte[]>();
                    for (int i = 0; i < IDsField.Count() / (NBIDlength - 1); i++)
                    {
                        byte[] singleID = new byte[2];
                        singleID[0] = IDsField[2 * i];
                        singleID[1] = IDsField[2 * i + 1];
                        ListOfIDs.Add(singleID);
                    }
                    entry.IDs = ListOfIDs;
                    indexforCurrentID.Add(entry);
                }
            }
            NBTable.Clear();
            return(NBindex);
        }