Example #1
0
    /// <summary>
    /// 生成旅游天数的链接
    /// </summary>
    /// <returns></returns>
    protected string CreateDaysSearchLink()
    {
        string         link  = "<a href='{0}' class='{1}'>{2}</a>";
        LineSearchInfo model = CurrentSearchInfo;

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i <= 10; i++)
        {
            string title = i + "天";
            if (i == 0)
            {
                title = "不限";
            }
            if (i == 10)
            {
                title += "以上";
            }

            model.Days = i;
            string href   = LineSearch.CreateQueryParas(model);
            string reqVal = Request.QueryString["days"];
            if (reqVal.IsNullOrEmpty())
            {
                reqVal = "0";
            }
            string cls = reqVal == i.ToString() ? "selected" : "";
            sb.AppendLine(string.Format(link, href, cls, title));
        }
        return(sb.ToString());
    }
Example #2
0
    protected void ddlSecondCat_SelectedIndexChanged(object sender, EventArgs e)
    {
        LineSearchInfo model = CurrentSearchInfo;

        model.SecondID = ddlSecondCat.SelectedValue.ToArrowInt();
        LineSearch.GoSearch(model);
    }
Example #3
0
 public LineSearchBasedMethod(LineSearch lineSearch)
 {
     lineSearch_ = lineSearch;
     if (lineSearch_ == null)
     {
         lineSearch_ = new ArmijoLineSearch();
     }
 }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request.QueryString["Type"].ToArrowString();

        switch (type.ToLower())
        {
        case "line":
            int      id   = Request.QueryString["id"].ToArrowInt();
            string   date = Request.QueryString["date"];
            DateTime dt   = date.ToArrowDateTime();
            List <TMS.TravelGroupInfo> groups = new TMS.TravelGroup().SelectList("IsDel=0 And LineID=" + id + " Order By GoDate");
            var model = groups.Find(s => s.GoDate == dt);
            if (model != null)
            {
                Response.Redirect("LineDetail.aspx?ID=" + id + "&GroupID=" + model.ID);
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
            break;

        case "promotion":
            int      id1         = Request.QueryString["id"].ToArrowInt();
            DateTime date1       = Request.QueryString["date"].ToArrowDateTime();
            int      promotionID = Request.QueryString["PromotionID"].ToArrowInt();
            int      lineID      = Request.QueryString["LineID"].ToArrowInt();
            List <TMS.V_Promotion_GroupInfo> promotionGroups = new TMS.V_Promotion_Group().SelectList("IsDel=0 And PromotionID=" + promotionID + " And LineID=" + lineID);
            var model1 = promotionGroups.Find(s => s.GoDate == date1);
            if (model1 != null)
            {
                Response.Redirect("PromotionGroupDetail.aspx?ID=" + id1 + "&PromotionID=" + promotionID + "&GroupID=" + model1.GroupID + "&LineID=" + lineID);
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
            break;

        case "search":
            string keywords = Request["keywords"].ToArrowString();
            if (!string.IsNullOrEmpty(keywords))
            {
                LineSearchInfo searchModel = new LineSearchInfo();
                searchModel.KeyWord = keywords;
                LineSearch.GoSearch(searchModel);
            }
            Response.Redirect("Line.aspx");
            break;

        default:
            Response.Redirect("Default.aspx");
            break;
        }
    }
Example #5
0
    protected void btnReset_Click(object sender, EventArgs e)
    {
        LineSearchInfo model = CurrentSearchInfo;

        model.KeyWord        = "";
        model.MinGoDate      = GlobalSetting.MinTime;
        model.MaxGoDate      = GlobalSetting.MinTime;
        model.MinCustomPrice = 0M;
        model.MaxCustomPrice = 0M;

        LineSearch.GoSearch(model);
    }
Example #6
0
 public void MinBrent2()
 {
     double xmin = 0;
     //local minimum
     double realXmin = 4.057968;
     double eps = 1e-5;
     int maxCount = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     int counter = ls.FindMinimumViaBrent(f,1,4,5,maxCount,eps,ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Example #7
0
 public void MinGold2()
 {
     double xmin=0;
     //local minimum
     double realXmin = 4.057968;
     double eps = 1e-5;
     int counterMax = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     int counter = ls.FindMinimumViaGoldenSection(f,1,4,5,counterMax,eps,ref xmin);
     Assert.IsTrue(counter<counterMax);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Example #8
0
 public void MinInterval3()
 {
     int maxCount=30;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     double[] res = new double[3];
     int counter = ls.FindMinInterval(f,4,2,maxCount, ref res);
     double aVal = f.GetVal(res[0]);
     double bVal = f.GetVal(res[1]);
     double cVal = f.GetVal(res[2]);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue((aVal>bVal)&&(cVal>bVal));
 }
Example #9
0
        public void MinGold2()
        {
            double xmin = 0;
            //local minimum
            double        realXmin   = 4.057968;
            double        eps        = 1e-5;
            int           counterMax = 50;
            LineSearch    ls         = new LineSearch();
            TestFunction1 f          = new TestFunction1();
            int           counter    = ls.FindMinimumViaGoldenSection(f, 1, 4, 5, counterMax, eps, ref xmin);

            Assert.IsTrue(counter < counterMax);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Example #10
0
        public void MinBrent2()
        {
            double xmin = 0;
            //local minimum
            double        realXmin = 4.057968;
            double        eps      = 1e-5;
            int           maxCount = 50;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();
            int           counter  = ls.FindMinimumViaBrent(f, 1, 4, 5, maxCount, eps, ref xmin);

            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Example #11
0
 public void MinGold3()
 {
     double xmin=0;
     double eps = 1e-5;
     double realXmin = -0.75;
     int counterMax = 50;
     LineSearch ls = new LineSearch();
     TestFunction2 f = new TestFunction2();
     double [] res = new double[3];
     int counter1 = ls.FindMinInterval(f,-10,1,30,ref res);
     int counter2 = ls.FindMinimumViaGoldenSection(f,res[0],res[1],res[2],counterMax,eps, ref xmin);
     Assert.IsTrue(counter2<counterMax);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Example #12
0
 public void MinBrent3()
 {
     double xmin=0;
     double eps = 1e-5;
     double realXmin = -0.75;
     int maxCount = 50;
     LineSearch ls = new LineSearch();
     TestFunction2 f = new TestFunction2();
     double[] res = new double[3];
     int counter = ls.FindMinInterval(f,-10,1,30,ref res);
     counter = ls.FindMinimumViaBrent(f,res[0],res[1],res[2],maxCount,eps, ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Example #13
0
        public void MinInterval3()
        {
            int           maxCount = 30;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, 4, 2, maxCount, ref res);
            double   aVal    = f.GetVal(res[0]);
            double   bVal    = f.GetVal(res[1]);
            double   cVal    = f.GetVal(res[2]);

            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue((aVal > bVal) && (cVal > bVal));
        }
Example #14
0
        public void MinBrent4()
        {
            double        xmin     = 0;
            double        eps      = 1e-5;
            double        realXmin = -0.75;
            int           maxCount = 50;
            LineSearch    ls       = new LineSearch();
            TestFunction2 f        = new TestFunction2();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, 1000, 1, 30, ref res);

            counter = ls.FindMinimumViaBrent(f, res[0], res[1], res[2], 50, eps, ref xmin);
            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Example #15
0
        public void MinBrent1()
        {
            double        xmin     = 0;
            int           maxCount = 50;
            double        realXmin = -1.364641;
            double        eps      = 1e-5;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, -10, 1, maxCount, ref res);

            counter = ls.FindMinimumViaBrent(f, res[0], res[1], res[2], maxCount, eps, ref xmin);
            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Example #16
0
        public void MinGold4()
        {
            double        xmin       = 0;
            double        eps        = 1e-5;
            double        realXmin   = -0.75;
            int           counterMax = 50;
            LineSearch    ls         = new LineSearch();
            TestFunction2 f          = new TestFunction2();

            double[] res      = new double[3];
            int      counter1 = ls.FindMinInterval(f, 1000, 1, 30, ref res);
            int      counter2 = ls.FindMinimumViaGoldenSection(f, res[0], res[1], res[2], counterMax, eps, ref xmin);

            Assert.IsTrue(counter2 < counterMax);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Example #17
0
        public void TestLineSearchDeterminesSaneStepLength2()
        {
            var objectiveFunction = new QuadraticFunction2();
            // given
            var testX         = new double[] { -2 };
            var testValueX    = objectiveFunction.ValueAt(testX);
            var testGradX     = objectiveFunction.GradientAt(testX);
            var testDirection = new double[] { 1 };

            // when
            var lsr = LineSearchResult.GetInitialObject(testValueX, testGradX, testX);

            LineSearch.DoLineSearch(objectiveFunction, testDirection, lsr, 1.0);
            var stepSize = lsr.StepSize;

            // then
            Assert.True(Tolerance < stepSize && stepSize <= 1);
        }
Example #18
0
        public Edge PerpendicularOnPerimeter(Ellipse ellipse)
        {
            Class12.point_0   = new Point2(this.double_0, this.double_1, this.double_2);
            Class12.ellipse_0 = ellipse.DeepCopy();
            LineSearch.ObjectiveFunction function = new LineSearch.ObjectiveFunction(Class12.smethod_0);
            double parameterAtPoint = ellipse.GetParameterAtPoint(Class12.point_0);
            double tetha;

            if (parameterAtPoint <= 3.1415926535897931)
            {
                tetha = LineSearch.GoldenSection(0.001 * Global.AbsoluteEpsilon, 0.0, 3.1415926535897931, function);
            }
            else
            {
                tetha = LineSearch.GoldenSection(0.001 * Global.AbsoluteEpsilon, 3.1415926535897931, 6.2831853071795862, function);
            }
            return(new Edge(this, ellipse.GetPointAtParameter(tetha)));
        }
Example #19
0
    /// <summary>
    /// 生成单价区间的搜索链接
    /// </summary>
    /// <param name="value"></param>
    /// <param name="title"></param>
    /// <returns></returns>
    protected string CreateFixPriceSearchLink(string value, string title)
    {
        string         link  = "<a href='{0}' class='{1}'>{2}</a>";
        LineSearchInfo model = CurrentSearchInfo;

        model.FixPrice       = value.ToArrowInt();
        model.MinCustomPrice = 0M;
        model.MaxCustomPrice = 0M;
        string href   = LineSearch.CreateQueryParas(model);
        string reqVal = Request.QueryString["fprice"];

        if (reqVal.IsNullOrEmpty())
        {
            reqVal = "0";
        }
        string cls = reqVal == value ? "selected" : "";

        link = string.Format(link, href, cls, title);
        return(link);
    }
Example #20
0
        public void TestLineSearchFailsAtMinimum1()
        {
            var objectiveFunction = new QuadraticFunction2();

            // given
            double[] testX      = { 0 };
            var      testValueX = objectiveFunction.ValueAt(testX);
            var      testGradX  = objectiveFunction.GradientAt(testX);

            double[] testDirection = { -1 };
            // when
            var lsr = LineSearchResult.GetInitialObject(testValueX, testGradX, testX);

            LineSearch.DoLineSearch(objectiveFunction, testDirection, lsr, 1.0);
            var stepSize = lsr.StepSize;

            // then
            Assert.False(Tolerance < stepSize && stepSize <= 1);

            Assert.AreEqual(0.0, stepSize, Tolerance);
        }
Example #21
0
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string   keyword = Request.Form["keyword"].ToArrowString().Trim();
        DateTime cdate1  = Request.Form["cdate1"].ToArrowDateTime(GlobalSetting.MinTime);
        DateTime cdate2  = Request.Form["cdate2"].ToArrowDateTime(GlobalSetting.MinTime);
        decimal  cprice1 = Request.Form["cprice1"].ToArrowDecimal();
        decimal  cprice2 = Request.Form["cprice2"].ToArrowDecimal();

        LineSearchInfo model = CurrentSearchInfo;

        if (cprice1 > 0 || cprice2 > 0)
        {
            model.FixPrice = 0;
        }
        model.KeyWord        = keyword;
        model.MinGoDate      = cdate1;
        model.MaxGoDate      = cdate2;
        model.MaxCustomPrice = cprice2;
        model.MinCustomPrice = cprice1;

        LineSearch.GoSearch(model);
    }
Example #22
0
    /// <summary>
    /// 价格
    /// </summary>
    /// <returns></returns>
    protected string CreatePriceSort()
    {
        string         downArrow   = "sort-category-2";
        string         upArrow     = "sort-category-1";
        string         doubleArrow = "sort-category-3";
        LineSearchInfo model       = CurrentSearchInfo;
        int            priceSort   = Request.QueryString["pricesort"].ToArrowInt();
        string         css         = doubleArrow;

        if (priceSort == 0)
        {
            css             = doubleArrow;
            model.PriceSort = 1;
            model.SellSort  = 0;
            model.NewSort   = 0;
        }
        else if (priceSort == 1)
        {
            css             = downArrow;
            model.PriceSort = -1;
            model.SellSort  = 0;
            model.NewSort   = 0;
        }
        else if (priceSort == -1)
        {
            css             = upArrow;
            model.PriceSort = 1;
            model.SellSort  = 0;
            model.NewSort   = 0;
        }

        string href = LineSearch.CreateQueryParas(model);
        string link = "<a class='sort-item {0}' href='{1}'>价格</a>";

        link = string.Format(link, css, href);

        return(link);
    }
Example #23
0
        /// <summary>
        /// Finds approximate minimum of the function
        /// </summary>
        /// <param name="function">Function to minimize</param>
        /// <param name="initial">Initial point</param>
        /// <param name="result">Approximate minimum</param>
        public void Minimize(DifferentiableFunction function, ref VBuffer <Float> initial, ref VBuffer <Float> result)
        {
            Contracts.Check(FloatUtils.IsFinite(initial.Values, initial.Count), "The initial vector contains NaNs or infinite values.");
            LineFunc        lineFunc = new LineFunc(function, ref initial, UseCG);
            VBuffer <Float> prev     = default(VBuffer <Float>);

            initial.CopyTo(ref prev);

            for (int n = 0; _maxSteps == 0 || n < _maxSteps; ++n)
            {
                Float step         = LineSearch.Minimize(lineFunc.Eval, lineFunc.Value, lineFunc.Deriv);
                var   newPoint     = lineFunc.NewPoint;
                bool  terminateNow = n > 0 && TerminateTester.ShouldTerminate(ref newPoint, ref prev);
                if (terminateNow || Terminate(ref newPoint))
                {
                    break;
                }
                newPoint.CopyTo(ref prev);
                lineFunc.ChangeDir();
            }

            lineFunc.NewPoint.CopyTo(ref result);
        }
Example #24
0
        public void ProcessRequest(HttpContext context)
        {
            string m_Type   = context.Request["request"].ToLower();
            string m_Key    = context.Request["where"];
            int    m_Page   = Convert.ToInt32(context.Request["page"]);
            int    m_Size   = Convert.ToInt32(context.Request["maxfeatures"]);
            string callback = Convert.ToString(context.Request["callback"]);

            context.Response.ContentType = "text/plain";
            switch (m_Type)
            {
            case "query":
                switch (context.Request.QueryString["type"])
                {
                case "poi":
                    context.Response.Write(callback + "(" + KeywordSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "station":
                    context.Response.Write(callback + "(" + StationSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "line":
                    context.Response.Write(callback + "(" + LineSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "switch":
                    context.Response.Write(callback + "(" + SwitchSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;
                }
                if (context.Request.QueryString["type"] == "poi")
                {
                }
                else if (context.Request.QueryString["type"] == "station")
                {
                }
                else if (context.Request.QueryString["type"] == "line")
                {
                }
                else if (context.Request.QueryString["type"] == "switch")
                {
                }
                break;

            case "buff":
                double m_X      = Convert.ToDouble(context.Request["x"]);
                double m_Y      = Convert.ToDouble(context.Request["y"]);
                double m_Radius = Convert.ToDouble(context.Request["r"]);

                context.Response.Write(callback + "(" + KeywordBuffer.GetFeature(m_Key, m_Size, m_Page, m_X, m_Y, m_Radius) + ")");
                break;

            case "spatialquery":
                if (context.Request.QueryString["bbox"] != null)
                {
                    string   bbox = context.Request["bbox"];
                    string[] ls   = bbox.Split(new char[] { ',' });
                    double   m_l  = Convert.ToDouble(ls[0]);
                    double   m_b  = Convert.ToDouble(ls[1]);
                    double   m_r  = Convert.ToDouble(ls[2]);
                    double   m_t  = Convert.ToDouble(ls[3]);
                    context.Response.Write(callback + "(" + KeywordRectangle.GetFeature(m_Key, m_Size, m_Page, m_l, m_b, m_r, m_t) + ")");
                }
                else if (context.Request.QueryString["point"] != null)
                {
                    string   paras = context.Request["point"];
                    string[] parms = paras.Split(new char[] { ',' });
                    double   m_x   = Convert.ToDouble(parms[0]);
                    double   m_y   = Convert.ToDouble(parms[1]);
                    double   m_r   = Convert.ToDouble(parms[2]);
                    context.Response.Write(callback + "(" + KeywordBuffer.GetFeature(m_Key, m_Size, m_Page, m_x, m_y, m_r) + ")");
                }
                break;
            }
        }
Example #25
0
        private double[] CalculateNextPoint(double[] pX, double[] pGrad, GeneralMatrix hessian)
        {
            int i=0;
            double xmin=0;
            double step = _step;
            GeneralMatrix alfaX = new GeneralMatrix(_nDim,1);
            GeneralMatrix prevX = new GeneralMatrix(pX,_nDim);
            GeneralMatrix prevGrad = new GeneralMatrix(pGrad,_nDim);
            double[] intermediate = new double[_nDim];;

            alfaX = hessian.Multiply(prevGrad);

            //doing a line search to minimize alpha
            OneDWrapper wrapper = new OneDWrapper(_f,prevX,alfaX);
            LineSearch search = new LineSearch();
            double[] interval = new double[Constants.BRACKET_POINTS];
            int it1 = search.FindMinInterval(wrapper,_alpha,step,50,ref interval);
            int it2 = search.FindMinimumViaBrent(wrapper,interval[0],interval[1],interval[2],50,_epsilon, ref xmin);

            for (i=0;i<_nDim; i++)
                intermediate[i] = prevX.GetElement(i,0) - xmin*alfaX.GetElement(i,0);

            _alpha = xmin;

            return intermediate;
        }
Example #26
0
 public ConjugateGradient(LineSearch lineSearch = null)
     : base(lineSearch)
 {
 }
Example #27
0
 public SteepestDescent(LineSearch lineSearch = null)
     : base(lineSearch)
 {
 }