Ejemplo n.º 1
0
        public static OrderCalculationResponse CalculateOrder(OrderCalculationRequest request, bool hasAutoOrder = false)
        {
            var result = new OrderCalculationResponse();
            if (request.Items.Count() == 0) return result;
            if (request.Address == null) request.Address = GlobalSettings.Company.Address;
            if (request.ShipMethodID == 0) request.ShipMethodID = request.Configuration.DefaultShipMethodID;

            var apirequest = new CalculateOrderRequest();

            apirequest.WarehouseID       = request.Configuration.WarehouseID;
            apirequest.CurrencyCode      = request.Configuration.CurrencyCode;
            apirequest.PriceType         = request.Configuration.PriceTypeID;
            apirequest.ShipMethodID      = request.ShipMethodID;
            apirequest.ReturnShipMethods = request.ReturnShipMethods;
            apirequest.City              = request.Address.City;
            apirequest.State             = request.Address.State;
            apirequest.Zip               = request.Address.Zip;
            apirequest.Country           = request.Address.Country;
            apirequest.Details           = request.Items.Select(c => new OrderDetailRequest(c)).ToArray();
            if(hasAutoOrder){

                apirequest.OrderType = Common.Api.ExigoWebService.OrderType.AutoOrder;

            }
            var apiresponse = Exigo.WebService().CalculateOrder(apirequest);

            result.Subtotal = apiresponse.SubTotal;
            result.Shipping = apiresponse.ShippingTotal;
            result.Tax      = apiresponse.TaxTotal;
            result.Discount = apiresponse.DiscountTotal;
            result.Total    = apiresponse.Total;

            // Assemble the ship methods
            var shipMethods = new List<ShipMethod>();
            if (apiresponse.ShipMethods != null && apiresponse.ShipMethods.Length > 0)
            {
                foreach (var shipMethod in apiresponse.ShipMethods)
                {
                    shipMethods.Add((ShipMethod)shipMethod);
                }

                // Ensure that at least one ship method is selected
                var shipMethodID = (request.ShipMethodID != 0) ? request.ShipMethodID : request.Configuration.DefaultShipMethodID;
                if (shipMethods.Any(c => c.ShipMethodID == (int)shipMethodID))
                {
                    shipMethods.First(c => c.ShipMethodID == shipMethodID).Selected = true;
                }
                else
                {
                    shipMethods.First().Selected = true;
                }
            }
            result.ShipMethods = shipMethods.AsEnumerable();

            return result;
        }
Ejemplo n.º 2
0
        public double[] search()
        {
            List<Bee> bee = new List<Bee>();
            Bee best = new Bee(argCnt);
            List<Bee> workBee = new List<Bee>();
            List<Bee> newWorkBee = new List<Bee>();
            Bee tmp;

            //Step 2
            for (int i = 0; i < B; i++)
            {
                tmp = getRandBee();
                bee.Add(tmp);
            }
            iter = 1;
            //Step 3
            best.Copy(bee.First());
            while (T != TFinal && iter != iterMax)
            {
                newWorkBee.Clear();
                workBee.Clear();
                for (int i = 0; i < bee.Count; i++)
                {
                    if (best.profit < bee[i].profit)
                    {
                        best.Copy(bee[i]);
                    }
                }
                for (int i = 0; i < bee.Count; i++)
                {
                    if (Math.Exp(-Math.Abs(bee[i].profit - best.profit) / T) > rand.NextDouble())
                    {
                        workBee.Add(bee[i]);
                    }
                }
                workBee.Add(best);
                //Step 4
                foreach (Bee currBee in workBee)
                {
                    tmp = new Bee(argCnt);
                    for (int i = 0; i < argCnt; i++)
                    {
                        tmp.point[i] = currBee.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
                    }
                    checkRange(ref tmp);
                    tmp.profit = getProfit(tmp);
                    newWorkBee.Add(tmp);
                }
                foreach (Bee currBee in workBee)
                {
                    tmp = new Bee(argCnt);
                    for (int i = 0; i < argCnt; i++)
                    {
                        tmp.point[i] = best.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
                    }
                    checkRange(ref tmp);
                    tmp.profit = getProfit(tmp);
                    newWorkBee.Add(tmp);
                }
                newWorkBee.AddRange(workBee);
                foreach (Bee currBee in newWorkBee)
                {
                    if (best.profit < currBee.profit)
                    {
                        best.Copy(currBee);
                    }
                }
                //Step 5
                double fullProfit = 0;
                foreach (Bee currBee in newWorkBee)
                {
                    fullProfit += currBee.profit;
                }
                double d;
                double L;
                bee.Clear();
                for (int i = 0; i < newWorkBee.Count; i++)
                {
                    d = newWorkBee[i].profit / fullProfit;
                    d += getRandSign() * rand.NextDouble() * wMax;
                    d = d > 1 ? 1 : d;
                    d = d < eMax ? 0 : d;
                    L = (d - eta * fullProfit / newWorkBee.Count) < 0 ? 0 : (d - eta * fullProfit / newWorkBee.Count);
                    if (L / beta > (gamma * fullProfit / newWorkBee.Count))
                    {
                        bee.Add(newWorkBee[i]); //danced bee are added

                        tmp = new Bee(argCnt);
                        for (int j = 0; j < argCnt; j++)
                        {
                            tmp.point[j] = newWorkBee[i].point[j] + range * rand.NextDouble() - range / 2;
                        }
                        checkRange(ref tmp);
                        tmp.profit = getProfit(tmp);
                        bee.Add(tmp);
                    }
                    else
                    {
                        tmp = getRandBee();
                        bee.Add(tmp);
                    }

                }
                iter++;
                T *= alpha;
                range *= (1 - (double)iter / iterMax);
            }
            return (best.point.x);
        }