Exemplo n.º 1
0
 public int GetSign(int i, Query2 query)
 {
     if (i != Time)
     {
         Time = i;
         Sign = query.ToLine(i, V[0], V[1]);
     }
     return(Sign);
 }
        public void CannotDispatchUnregisteredQuery()
        {
            var query = new Query2(Guid.NewGuid());

            try
            {
                var result = _dispatcher.Dispatch(query);
                Assert.Fail();
            }
            catch (QueryHandlingException exception)
            {
                Assert.AreEqual(query, exception.Query);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 计算输入点的凸包。
        /// Compute convex hull of input points.
        /// epsilon仅用于检查点是否位于一条线(1d船体)上,而不用于其余计算。
        /// epsilon is only used for check if points lie on a line (1d hull), not for rest of compute.
        /// </summary>
        public ConvexHull2(IList <Vector2d> vertices, double epsilon, QueryNumberType queryType)
        {
            //mQueryType = queryType;
            mVertices     = vertices;
            mNumVertices  = vertices.Count;
            mDimension    = 0;
            mNumSimplices = 0;
            mIndices      = null;
            mSVertices    = null;

            mEpsilon = epsilon;

            mQuery = null;

            mLineOrigin    = Vector2d.Zero;
            mLineDirection = Vector2d.Zero;

            Vector2d.Information info;
            Vector2d.GetInformation(mVertices, mEpsilon, out info);
            if (info.mDimension == 0)
            {
                mDimension = 0;
                mIndices   = null;
                return;
            }

            if (info.mDimension == 1)
            {
                // The set is (nearly) collinear.  The caller is responsible for
                // creating a ConvexHull1 object.
                mDimension     = 1;
                mLineOrigin    = info.mOrigin;
                mLineDirection = info.mDirection0;
                return;
            }

            mDimension = 2;

            int i0 = info.mExtreme[0];
            int i1 = info.mExtreme[1];
            int i2 = info.mExtreme[2];

            mSVertices = new Vector2d[mNumVertices];

            if (queryType != QueryNumberType.QT_RATIONAL && queryType != QueryNumberType.QT_FILTERED)
            {
                // Transform the vertices to the square [0,1]^2.
                Vector2d minValue = new Vector2d(info.mMin[0], info.mMin[1]);
                double   scale    = ((double)1) / info.mMaxRange;
                for (int i = 0; i < mNumVertices; ++i)
                {
                    mSVertices[i] = (mVertices[i] - minValue) * scale;
                }

                double expand;
                if (queryType == QueryNumberType.QT_INT64)
                {
                    // Scale the vertices to the square [0,2^{20}]^2 to allow use of
                    // 64-bit integers.
                    expand = (double)(1 << 20);
                    mQuery = new Query2Int64(mSVertices);
                }
                else if (queryType == QueryNumberType.QT_INTEGER)
                {
                    throw new NotImplementedException("ConvexHull2: Query type QT_INTEGER not currently supported");
                    // Scale the vertices to the square [0,2^{24}]^2 to allow use of
                    // Integer.
                    //expand = (double)(1 << 24);
                    //mQuery = new Query2Integer(mNumVertices, mSVertices);
                }
                else
                {  // queryType == Query::QT_double
                    // No scaling for floating point.
                    expand = (double)1;
                    mQuery = new Query2d(mSVertices);
                }

                for (int i = 0; i < mNumVertices; ++i)
                {
                    mSVertices[i] *= expand;
                }
            }
            else
            {
                throw new NotImplementedException("ConvexHull2: Query type QT_RATIONAL/QT_FILTERED not currently supported");

                // No transformation needed for exact rational arithmetic or filtered
                // predicates.
                //for (int i = 0; i < mSVertices.Length; ++i)
                //    mSVertices[i] = mVertices[i];

                //if (queryType == Query::QT_RATIONAL) {
                //    mQuery = new Query2Rational(mNumVertices, mSVertices);
                //} else { // queryType == Query::QT_FILTERED
                //    mQuery = new Query2Filtered(mNumVertices, mSVertices,
                //        mEpsilon);
                //}
            }


            Edge edge0 = null;
            Edge edge1 = null;
            Edge edge2 = null;

            if (info.mExtremeCCW)
            {
                edge0 = new Edge(i0, i1);
                edge1 = new Edge(i1, i2);
                edge2 = new Edge(i2, i0);
            }
            else
            {
                edge0 = new Edge(i0, i2);
                edge1 = new Edge(i2, i1);
                edge2 = new Edge(i1, i0);
            }

            edge0.Insert(edge2, edge1);
            edge1.Insert(edge0, edge2);
            edge2.Insert(edge1, edge0);

            Edge hull = edge0;

            // ideally we insert points in random order. but instead of
            // generating a permutation, just insert them using modulo-indexing,
            // which is in the ballpark...
            int ii = 0;

            do
            {
                if (!Update(ref hull, ii))
                {
                    return;
                }
                ii = (ii + 31337) % mNumVertices;
            } while (ii != 0);

            // original code, vastly slower in pathological cases
            //for (int i = 0; i < mNumVertices; ++i) {
            //    if ( ! Update(ref hull, i) )
            //        return;
            //}

            hull.GetIndices(ref mNumSimplices, ref mIndices);
        }
Exemplo n.º 4
0
 public static void ReadQuery2Data(string str)
 {
     IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
       var line = lines.Where(x => (x != ""));
       object lock_query = new object();
       Parallel.ForEach(line, l =>
       {
     try
     {
       string[] datas = l.Split('\t', ',');
       int k1 = Convert.ToInt32(datas[0].Trim('"'));
       int k2 = Convert.ToInt32(datas[1].Trim('"'));
       int p = Convert.ToInt32(datas[2].Trim('"'));
       double lkp = Convert.ToDouble(datas[3].Trim('"'));
       double pagerank = Convert.ToDouble(datas[5].Trim('"'));
       double ukp = Convert.ToDouble(datas[6].Trim('"'));
       double rcm = CalculateRCM(k1, k2, p);
       Tuple<int, int> keywords = Tuple.Create(k1, k2);
       lock (lock_query)
       {
     if (dicQuery2.Keys.Contains(keywords))
     {
       dicQuery2[keywords].dicResultsLKP.Add(p, lkp);
       dicQuery2[keywords].dicResultsUKP.Add(p, ukp);
       dicQuery2[keywords].dicResultsPagerank.Add(p, pagerank);
       dicQuery2[keywords].dicResultsRCM.Add(p, rcm);
     }
     else
     {
       Query2 q = new Query2(k1, k2);
       q.dicResultsLKP.Add(p, lkp);
       q.dicResultsUKP.Add(p, ukp);
       q.dicResultsPagerank.Add(p, pagerank);
       q.dicResultsRCM.Add(p, rcm);
       dicQuery2.Add(keywords, q);
     }
       }
     }
     catch (Exception ex)
     {
       Console.WriteLine("Error {0} at line:{1}", ex.Message, line);
     }
       });
 }
Exemplo n.º 5
0
 public Result()
 {
     InitializeComponent();
     controller = new Query2(ConnectionString.ConnStr);
 }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            sqlConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["academiaADBConnection"].ConnectionString;

            command.Connection = sqlConnection;

            command.CommandType = System.Data.CommandType.Text;



            SqlDataAdapter reader = new SqlDataAdapter("SELECT r.firstName+' '+r.lastName as 'Full Name',a.ArticalName  ,a.ArticalPublishDate,m.MagazineName,r.AcademicRank FROM Researchers r join ResearcherArticals ra on ra.ResearcherId = r.ResearcherId join Articals a on a.ArticalId = ra.ArticalId join Magazine m on m.MagazineId = ra.MagazineId", sqlConnection);
            DataTable      dbtl   = new DataTable();

            reader.Fill(dbtl);
            Query1.DataSource = dbtl;
            Query1.DataBind();


            SqlDataAdapter reader1 = new SqlDataAdapter("SELECT  r.firstName+' '+r.lastName as 'Full Name',a.ArticalName  ,a.ArticalPublishDate,m.MagazineName,r.AcademicRank FROM Researchers r join ResearcherArticals ra on ra.ResearcherId = r.ResearcherId join Articals a on a.ArticalId = ra.ArticalId join Magazine m on m.MagazineId = ra.MagazineId ORDER BY r.AcademicRank", sqlConnection);
            DataTable      dbtl2   = new DataTable();

            reader1.Fill(dbtl2);
            Query2.DataSource = dbtl2;
            Query2.DataBind();


            string         strQuery = "SELECT  * FROM Researchers ";
            SqlCommand     cmd      = new SqlCommand(strQuery, sqlConnection);
            SqlDataAdapter d        = new SqlDataAdapter(cmd);

            DataSet dataTable = new DataSet();

            d.Fill(dataTable, "Researchers");
            DropDownList1.DataSource = dataTable.Tables["Researchers"];
            if (!IsPostBack)
            {
                DropDownList1.DataTextField  = "ResearcherId";
                DropDownList1.DataValueField = "ResearcherId";
                RemoveDuplicateItems(DropDownList1);
            }
            DropDownList1.DataBind();


            SqlDataAdapter reader2 = new SqlDataAdapter("SELECT  * FROM  Articals", sqlConnection);
            DataSet        dbtl1   = new DataSet();

            reader2.Fill(dbtl1, "Articals");
            ArticalDropdwon.DataSource = dbtl1.Tables["Articals"];
            if (!IsPostBack)
            {
                ArticalDropdwon.DataTextField  = "ArticalId";
                ArticalDropdwon.DataValueField = "ArticalId";
                RemoveDuplicateItems(ArticalDropdwon);
            }
            ArticalDropdwon.DataBind();

            SqlDataAdapter reader3 = new SqlDataAdapter("SELECT  *  FROM  Magazine", sqlConnection);
            DataSet        dbtl3   = new DataSet();

            reader3.Fill(dbtl3, "Magazine");
            mgDropDownList.DataSource = dbtl3.Tables["Magazine"];
            if (!IsPostBack)
            {
                mgDropDownList.DataTextField  = "MagazineId";
                mgDropDownList.DataValueField = "MagazineId";
                RemoveDuplicateItems(mgDropDownList);
            }
            mgDropDownList.DataBind();

            sqlConnection.Close();
        }