public IList<Violation> GetOrderViolations(GPRecordSet layer, int solveHR) { Debug.Assert(layer != null); var violations = new List<Violation>(); foreach (GPFeature feature in layer.Features) { int vc; if (_GetViolatedConstraint(feature, out vc)) { // order id Guid orderId = _AttrToObjectId(NAAttribute.NAME, feature.Attributes); // find order Order order = _project.Orders.SearchById(orderId); if (order == null) { string message = Properties.Messages.Error_InvalidGPFeatureMapping; throw new RouteException(message); // exception } // create violation objects violations.AddRange(_CreateViolations(vc, solveHR, order, ORDER_VC)); } } return violations; }
public IList<Violation> GetRestrictedOrderViolations(GPRecordSet layer) { Debug.Assert(layer != null); var violations = new List<Violation>(); foreach (GPFeature feature in layer.Features) { // status var status = (NAObjectStatus)feature.Attributes.Get<int>(NAAttribute.STATUS); if (_IsRestrictedOrNotLocated(status)) { // order id Guid orderId = _AttrToObjectId(NAAttribute.NAME, feature.Attributes); Order order = _project.Orders.SearchById(orderId); if (order == null) { continue; } // create violation object violations.Add(_CreateRestrictedObjViolation(status, order)); } } return violations; }
public IList<Violation> GetDepotViolations(GPRecordSet layer) { Debug.Assert(layer != null); var violations = new List<Violation>(); foreach (GPFeature feature in layer.Features) { // status var status = (NAObjectStatus)feature.Attributes.Get<int>(NAAttribute.STATUS); if (_IsRestrictedOrNotLocated(status)) { // location id Guid locId = _AttrToObjectId(NAAttribute.NAME, feature.Attributes); // find location Location loc = _project.LocationManager.SearchById(locId); if (loc == null) { continue; } // create violation object violations.Add(_CreateRestrictedObjViolation(status, loc)); } } return violations; }
/// <summary> /// Method converts network parameters.into GPRecordSet. /// </summary> /// <returns>Network parameters GPRecordSet.</returns> private GPRecordSet _ConvertNetworkParams() { List<GPFeature> features = new List<GPFeature>(); foreach (NetworkAttribute attr in _context.NetworkDescription.NetworkAttributes) { foreach (NetworkAttributeParameter param in attr.Parameters) { object value = null; if (_context.SolverSettings.GetNetworkAttributeParameterValue( attr.Name, param.Name, out value)) { // Skip null value overrides, let the service to use defaults. if (value != null) { GPFeature feature = new GPFeature(); feature.Attributes = new AttrDictionary(); feature.Attributes.Add(NAAttribute.NETWORK_ATTR_NAME, attr.Name); feature.Attributes.Add(NAAttribute.NETWORK_ATTR_PARAM_NAME, param.Name); feature.Attributes.Add(NAAttribute.NETWORK_ATTR_PARAM_VALUE, value); features.Add(feature); } } } } GPRecordSet rs = null; if (features.Count > 0) { rs = new GPRecordSet(); rs.Features = features.ToArray(); } return rs; }
/// <summary> /// Method converts routes collection into GPRecordSet. /// </summary> /// <param name="routes">Routes collection.</param> /// <returns>Routes GPRecordSet.</returns> /// <exception cref="RouteException">If Fuel Economy in routes is 0.0.</exception> private GPRecordSet _ConvertRoutes(ICollection<Route> routes) { Debug.Assert(routes != null); List<GPFeature> features = new List<GPFeature>(); foreach (Route route in routes) features.Add(_ConvertRoute(route)); GPRecordSet rs = new GPRecordSet(); rs.Features = features.ToArray(); return rs; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Method converts renewal locations from routes collection into GPRecordSet. /// </summary> /// <param name="routes">Routes collection to get renewals.</param> /// <returns>Renewals GPRecordSet.</returns> private GPRecordSet _ConvertRenewals(ICollection<Route> routes) { Debug.Assert(routes != null); List<GPFeature> features = new List<GPFeature>(); foreach (Route route in routes) { foreach (Location loc in route.RenewalLocations) features.Add(_ConvertRenewal(loc, route)); } GPRecordSet rs = null; if (features.Count > 0) { rs = new GPRecordSet(); rs.Features = features.ToArray(); } return rs; }
/// <summary> /// Method converts orders collection into GPRecordSet containing order pairs. /// The rule is when a pickup order has a matching delivery order by order number /// we have an order pair. /// </summary> /// <param name="orders">Orders collection.</param> /// <returns>Orders GPRecordSet.</returns> private GPRecordSet _ConvertOrderPairs(ICollection<Order> orders) { Debug.Assert(orders != null); List<GPFeature> features = new List<GPFeature>(); List<Order> pickupOrders = new List<Order>(); Dictionary<string, Order> deliveryOrders = new Dictionary<string, Order>(); foreach (Order orderItem in orders) { string orderKey = orderItem.PairKey(); if (string.IsNullOrEmpty(orderKey)) continue; if (orderItem.Type == OrderType.Pickup) pickupOrders.Add(orderItem); else if (orderItem.Type == OrderType.Delivery && !deliveryOrders.ContainsKey(orderKey)) deliveryOrders.Add(orderKey, orderItem); else continue; } foreach (Order pickupOrder in pickupOrders) { string pickupOrderKey = pickupOrder.PairKey(); // do we have a matching delivery order? Order deliveryOrder = null; if (!deliveryOrders.TryGetValue(pickupOrderKey, out deliveryOrder)) continue; features.Add(_ConvertOrderPair(pickupOrder, deliveryOrder)); } GPRecordSet rs = new GPRecordSet(); rs.Features = features.ToArray(); return rs; }