Example #1
0
        public void QuickSortTest()
        {
            DPP dPP = new DPP();

            Saving[] savings = new Saving[]
            {
                new Saving()
                {
                    start = 1, end = 3, savingValue = "12345"
                },
                new Saving()
                {
                    start = 2, end = 3, savingValue = "12525"
                },
                new Saving()
                {
                    start = 3, end = 3, savingValue = "21345"
                },
                new Saving()
                {
                    start = 4, end = 3, savingValue = "10045"
                },
                new Saving()
                {
                    start = 5, end = 3, savingValue = "12745"
                }
            };
            dPP.QuickSort(ref savings, 0, savings.Length - 1);
            Saving[] saving2 = new Saving[]
            {
                new Saving()
                {
                    start = 4, end = 3, savingValue = "10045"
                },
                new Saving()
                {
                    start = 1, end = 3, savingValue = "12345"
                },
                new Saving()
                {
                    start = 2, end = 3, savingValue = "12525"
                },
                new Saving()
                {
                    start = 5, end = 3, savingValue = "12745"
                },
                new Saving()
                {
                    start = 3, end = 3, savingValue = "21345"
                }
            };
            Assert.AreEqual(savings[0].savingValue, saving2[0].savingValue);
        }
Example #2
0
        public ActionResult DynamicPathPlaning(string para, string orderId, string truckId, string name, string type)
        {
            string[]  paraArray = para.Split('/');
            const int STNum = 3, WorkHour = 11, AvgTime = 2;
            var       staffManager = new StaffManager();
            Guid      id;                                                                                                                                                                       //the website's id
            string    location = string.Empty;                                                                                                                                                  //the website's location
            //get order's data
            List <LogisticsSystem.DTO.OrderListDto> datas = staffManager.GetOrderByWebsite(out id, out location, name, type).Where(p => long.Parse(p.OrderId) <= long.Parse(orderId)).ToList(); //避免处理期间有新的订单生成
            //get truck's data
            var truck = staffManager.GetTruckByWebsite(id).Where(p => p.TruckId == Guid.Parse(truckId)).FirstOrDefault();

            if (truck.ContainerHeight == "0")
            {
                truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.TruckHeight)).ToString("f2");
            }
            else
            {
                truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.ContainerHeight)).ToString("f2");
            }

            string[] locations = new string[paraArray.Length];               //the location matrix
            double[,] dist = new double[paraArray.Length, paraArray.Length]; //the distance matrix
            double[] valueCoefficient = new double[paraArray.Length];        //The Value Coefficient Matrix
            double[,] coefficients = new double[STNum, paraArray.Length];    //The Restraint Coefficient Matrix
            locations[0]           = location;
            valueCoefficient[0]    = 0;
            coefficients[0, 0]     = double.MaxValue;
            coefficients[1, 0]     = double.MaxValue;
            coefficients[2, 0]     = double.MaxValue;
            //initialize matrix
            for (int i = 1; i < paraArray.Length; i++)
            {
                var num = int.Parse(paraArray[i]) - 1;
                valueCoefficient[i] = Convert.ToDouble(datas[num].Income);
                locations[i]        = datas[num].Location;
                coefficients[0, i]  = Convert.ToDouble(datas[num].CargoWeight) * Convert.ToDouble(datas[num].UnitNUm);
                coefficients[1, i]  = Convert.ToDouble(datas[num].CargoVolume) * Convert.ToDouble(datas[num].UnitNUm);
                coefficients[2, i]  = 0.25;
            }
            coefficients[0, paraArray.Length - 1] = Convert.ToDouble(truck.Load) * 1000;
            coefficients[1, paraArray.Length - 1] = Convert.ToDouble(truck.Volumn);
            coefficients[2, paraArray.Length - 1] = WorkHour - AvgTime;
            //calculate distance
            string key  = ConfigurationManager.AppSettings["GdAppKey"];
            string skey = ConfigurationManager.AppSettings["GdSecretKey"];

            for (int i = 0; i < paraArray.Length; i++)
            {
                var aimLocation = locations[i];
                locations.ToList().Remove(aimLocation);
                var           orignLocationStr = string.Join("|", locations);
                List <string> distances        = WebRequestService.CalcGroupDistance(orignLocationStr, aimLocation, key, skey, "1");
                for (int j = 0; j < distances.Count; j++)
                {
                    dist[i, j] = double.Parse(distances[j]);
                }
                dist[i, i] = 0;
            }

            //Analyze soulation
            DPP           dPP = new DPP();
            double        _maxValue;
            List <string> soulation = dPP.GetSulotion(dist, valueCoefficient, coefficients, out _maxValue);
            string        _path     = string.Join("/", soulation);

            return(Json(new { path = _path.Trim('/'), maxValue = _maxValue }, JsonRequestBehavior.AllowGet));
        }