public void AddOption(PathType type, Delivery delivery) { if (delivery == null) throw new ArgumentException("Delivery cannot be null", "delivery"); options[type] = delivery; }
public override double GetValue(RouteInstance route, Delivery delivery) { double routeCost = route.Route.CostPerCm3 * delivery.VolumeInCm3; routeCost += route.Route.CostPerGram * delivery.WeightInGrams; routeCost += outer.nodeCost[route.Route.Origin]; return route.ArrivalTime.Ticks + (1.0 - (1.0 / routeCost));//TODO }
public abstract double GetValue(RouteInstance route, Delivery delivery);
//, Excluder excluder) private List<RouteInstance> findPath(DateTime requestTime, RouteNode origin, RouteNode goal, int weight, int volume, NodeEvaluator evaluator, RouteExcluder excluder) { Delivery delivery = new Delivery(); delivery.Origin = origin; delivery.Destination = goal; delivery.WeightInGrams = weight; delivery.VolumeInCm3 = volume; delivery.TimeOfRequest = requestTime; originPath = new Dictionary<RouteNode, RouteInstance>(); nodeCost = new Dictionary<RouteNode, double>(); closed = new HashSet<RouteNode>(); var rc = new RouteComparer(); fringe = new SortedList<RouteNode, double>(rc); fringe.Add(origin, 0); originPath.Add(origin, new OriginRouteInstance(requestTime)); //if the queue is empty return null (no path) while (fringe.Count > 0) { //take new node off the top of the stack //this is guaranteed to be the best way to the node RouteNode curNode = fringe.Keys[0]; if (closed.Contains(curNode)) continue; nodeCost.Add(curNode, fringe.Values[0]); closed.Add(curNode); fringe.RemoveAt(0); //if it's the goal node exit and return path if (curNode.Equals(goal)) return completeDelivery(curNode); //grab a list of all of the routes where the given node is the origin IEnumerable<Route> routes = routeService.GetAll(curNode); //take each route that hasn't been ommited and evaluate foreach (Route path in excluder.Omit(routes)) { RouteInstance nextInstance = evaluator.GetNextInstance(path); RouteNode nextNode = path.Destination; double totalCost = evaluator.GetValue(nextInstance, delivery); //if the node is not in the fringe //or the current value is lower than //the new cost then set the new parent if (!fringe.ContainsKey(nextNode)) { originPath.Add(nextNode, nextInstance); fringe.Add(nextNode, totalCost); } else if (fringe[nextNode] > totalCost) { originPath.Remove(nextNode); fringe.Remove(nextNode); originPath.Add(nextNode, nextInstance); fringe.Add(nextNode, totalCost); } } } return null; }
private void BenDBTests(CountryService countryService, RouteService routeService) { try { CountryDataHelper cdh = new CountryDataHelper(); // create country if doesn't exist Country country = new Country { ID = 1, Name = "Wellington", Code = "WLG" }; if (!countryService.Exists(country)) { country = countryService.Create("Wellington", "WLG"); } country = countryService.Update(country.ID, "WLN"); country = countryService.Update(country.ID, "BEN"); // get latest version Country loadedCountry = countryService.Get(country.ID); cdh.LoadAll(DateTime.Now); // create new zealand country = new Country { Name = "New Zealand", Code = "NZ" }; if (!countryService.Exists(country)) { country = countryService.Create(country.Name, country.Code); } // create australia country = new Country { Name = "Australia", Code = "AUS" }; if (!countryService.Exists(country)) { country = countryService.Create(country.Name, country.Code); } // load all countries var allCountries = countryService.GetAll(); // create christchurch depot RouteNode routeNode = new DistributionCentre("Christchurch"); if (!locationService.Exists(routeNode)) { routeNode = locationService.CreateDistributionCentre("Christchurch"); } // wellington depot routeNode = new DistributionCentre("Wellington"); if (!locationService.Exists(routeNode)) { routeNode = locationService.CreateDistributionCentre("Wellington"); } // australia port country = countryService.GetAll().AsQueryable().First(t => t.Name == "Australia"); var destination = new InternationalPort(country); if (!locationService.Exists(destination)) { destination = locationService.CreateInternationalPort(country.ID); } // get a company var company = new Company() { Name = "NZ Post" }; if (!companyService.Exists(company)) { company = companyService.Create(company.Name); } // create a new route Route route = new Route() { Origin = routeNode, Destination = destination, Company = company, Duration = 300, MaxVolume = 5000, MaxWeight = 5000, CostPerCm3 = 3, CostPerGram = 5, TransportType = TransportType.Air, DepartureTimes = new List<WeeklyTime> { new WeeklyTime(DayOfWeek.Monday, 5, 30) } }; var routeDataHelper = new RouteDataHelper(); int id = routeDataHelper.GetId(route); Logger.WriteLine("Route id is: " + id); if (id == 0) { routeDataHelper.Create(route); } //route = routeDataHelper.Load(1); // edit departure times route.DepartureTimes.Add(new WeeklyTime(DayOfWeek.Wednesday, 14, 35)); // update //routeDataHelper.Update(route); // delete routeDataHelper.Delete(route.ID); var routes = routeDataHelper.LoadAll(); var delivery = new Delivery { Origin = routeNode, Destination = destination, Priority = Priority.Air, WeightInGrams = 200, VolumeInCm3 = 2000, TotalPrice = 2500, TotalCost = 1000, TimeOfRequest = DateTime.UtcNow, TimeOfDelivery = DateTime.UtcNow.AddHours(5.5), Routes = new List<RouteInstance> { new RouteInstance(route, DateTime.UtcNow)} }; var deliveryDataHelper = new DeliveryDataHelper(); deliveryDataHelper.Create(delivery); deliveryDataHelper.Load(delivery.ID); deliveryDataHelper.LoadAll(); var price = new Price { Origin = routeNode, Destination = destination, Priority = Priority.Air, PricePerCm3 = 3, PricePerGram = 5 }; var priceDataHelper = new PriceDataHelper(); //priceDataHelper.Create(price); price.PricePerGram = 10; price.ID = 1; Logger.WriteLine(price.ToString()); } catch (Exception e) { Logger.WriteLine(e.Message); Logger.Write(e.StackTrace); } }
public virtual Order Convert([NotNull] DomainModel.Orders.Order source) { Assert.ArgumentNotNull(source, "source"); Order destination = new Order(); const int Period = 7; DateTime tempEndDate = source.OrderDate.AddDays(Period); destination.IssueDate = source.OrderDate; destination.OrderId = source.OrderNumber; destination.State = new State(); destination.PaymentMeans = new PaymentMeans { PaymentChannelCode = source.PaymentSystem.Code, PaymentDueDate = source.OrderDate, PaymentID = source.TransactionNumber, PaymentMeansCode = source.CustomerInfo.CustomProperties[TransactionConstants.CardType] }; destination.Note = source.Comment; destination.PricingCurrencyCode = source.Currency.Code; destination.TaxCurrencyCode = source.Currency.Code; destination.TaxTotal = new TaxTotal { RoundingAmount = new Amount(0, source.Currency.Code) }; destination.DestinationCountryCode = source.CustomerInfo.BillingAddress.Country.Code; this.MapAmounts(source, destination); destination.BuyerCustomerParty = new CustomerParty { Party = new Party { Contact = new Contact { Name = source.CustomerInfo.BillingAddress.Name, ElectronicMail = source.CustomerInfo.Email, Telefax = source.CustomerInfo.Fax, Telephone = source.CustomerInfo.Phone, }, PostalAddress = new Address { StreetName = source.CustomerInfo.BillingAddress.Address, PostalZone = source.CustomerInfo.BillingAddress.Zip, CityName = source.CustomerInfo.BillingAddress.City, CountrySubentity = source.CustomerInfo.BillingAddress.State, Country = source.CustomerInfo.BillingAddress.Country.Code, AddressTypeCode = string.Empty }, PartyName = source.CustomerInfo.BillingAddress.Name, LanguageCode = Sitecore.Context.Language.Name, Person = new Person(), }, SupplierAssignedAccountID = source.CustomerInfo.CustomerId }; destination.BuyerCustomerParty.Party.Contact.OtherCommunications = new List<Communication> { new Communication { Channel = source.CustomerInfo.Email2, Value = source.CustomerInfo.Email2 }, new Communication { Channel = source.CustomerInfo.Mobile, Value = source.CustomerInfo.Mobile } }; destination.AccountingCustomerParty = new CustomerParty { Party = new Party { Contact = new Contact { Name = source.CustomerInfo.BillingAddress.Name, ElectronicMail = source.CustomerInfo.Email }, PostalAddress = new Address { StreetName = source.CustomerInfo.BillingAddress.Address, PostalZone = source.CustomerInfo.BillingAddress.Zip, CityName = source.CustomerInfo.BillingAddress.City, CountrySubentity = source.CustomerInfo.BillingAddress.State, Country = source.CustomerInfo.BillingAddress.Country.Code, AddressTypeCode = string.Empty }, PartyName = source.CustomerInfo.BillingAddress.Name, Person = new Person() } }; destination.Delivery = new List<Delivery>(1); Delivery delivery = new Delivery { DeliveryParty = new Party { Contact = new Contact { Name = source.CustomerInfo.ShippingAddress.Name, }, PostalAddress = new Address { StreetName = source.CustomerInfo.ShippingAddress.Address, PostalZone = source.CustomerInfo.ShippingAddress.Zip, CityName = source.CustomerInfo.ShippingAddress.City, CountrySubentity = source.CustomerInfo.ShippingAddress.State, Country = source.CustomerInfo.ShippingAddress.Country.Code, AddressTypeCode = string.Empty }, Person = new Person(), PartyName = source.CustomerInfo.ShippingAddress.Name, }, TrackingID = source.TrackingNumber, RequestedDeliveryPeriod = new Period { EndDate = tempEndDate, EndTime = tempEndDate.TimeOfDay, StartDate = source.OrderDate, StartTime = source.OrderDate.TimeOfDay, }, LatestDeliveryDate = tempEndDate, LatestDeliveryTime = tempEndDate.TimeOfDay, DeliveryLocation = new Location { ValidityPeriod = new Period { EndDate = tempEndDate, EndTime = tempEndDate.TimeOfDay, StartDate = source.OrderDate, StartTime = source.OrderDate.TimeOfDay, }, Address = new Address { StreetName = source.CustomerInfo.ShippingAddress.Address, PostalZone = source.CustomerInfo.ShippingAddress.Zip, CityName = source.CustomerInfo.ShippingAddress.City, CountrySubentity = source.CustomerInfo.ShippingAddress.State, Country = source.CustomerInfo.ShippingAddress.Country.Code, AddressTypeCode = string.Empty } } }; destination.Delivery.Add(delivery); destination.FreightForwarderParty = new List<Party>(1); Party freightForwarderParty = new Party { Person = new Person(), PartyIdentification = source.ShippingProvider.Code, PostalAddress = new Address { AddressTypeCode = string.Empty } }; destination.FreightForwarderParty.Add(freightForwarderParty); destination.State = this.GetState(source.Status); uint i = 0; foreach (DomainModel.Orders.OrderLine line in source.OrderLines) { OrderLine orderLine = new OrderLine { LineItem = new LineItem { Item = new Item { Code = line.Product.Code, Name = line.Product.Title, Description = line.Product is Product ? ((Product)line.Product).Description : string.Empty, AdditionalInformation = line.ImageUrl, Keyword = line.FriendlyUrl, PackQuantity = 1, PackSizeNumeric = 1 }, Price = new Price(new Amount(line.Totals.PriceExVat, destination.PricingCurrencyCode), line.Quantity), TotalTaxAmount = new Amount(line.Totals.TotalVat, destination.PricingCurrencyCode), Quantity = line.Quantity } }; destination.OrderLines.Add(orderLine); destination.TaxTotal.TaxSubtotal.Add( new TaxSubTotal { TransactionCurrencyTaxAmount = new Amount(0, source.Currency.Code), TaxCategory = new TaxCategory { Name = source.CustomerInfo.BillingAddress.Country.VatRegion.Code, BaseUnitMeasure = new Measure(), PerUnitAmount = new Amount(0, source.Currency.Code), TaxScheme = new TaxScheme(), ID = "SimpleTaxCategory", Percent = line.Totals.VAT * 100 }, TaxableAmount = new Amount(line.Totals.TotalPriceExVat, source.Currency.Code), CalculationSequenceNumeric = i }); i++; } this.MapSellerSupplierParty(destination); this.MapReservationTicket(source, destination); return destination; }
// Current State method overrides public override void SaveDelivery(Delivery delivery) { throw new NotSupportedException("Client state does not store Deliveries."); }
public virtual void SaveDelivery(Delivery delivery) { deliveries[delivery.ID] = delivery; }