protected virtual int SetHighBound() { var bound = 0; var time = 0; var selectedDeliveries = SelectedVertices.ToList(); var notSelectedDeliveries = AvailableVertices.ToList(); for (var i = 0; i < selectedDeliveries.Count - 1; i++) { time += selectedDeliveries[i].TimeToOther[selectedDeliveries[i + 1]]; if (selectedDeliveries[i + 1].DirectiveTime < time) { bound++; } } bound += notSelectedDeliveries.RemoveAll(x => x.DirectiveTime <= time + selectedDeliveries.Last().TimeToOther[x]); while (notSelectedDeliveries.Any()) { var delivery = notSelectedDeliveries.OrderBy(x => selectedDeliveries.Last().TimeToOther[x]).First(); time += selectedDeliveries.Last().TimeToOther[delivery]; selectedDeliveries.Add(delivery); notSelectedDeliveries.Remove(delivery); bound += notSelectedDeliveries.RemoveAll(x => x.DirectiveTime <= time + selectedDeliveries.Last().TimeToOther[x]); } selectedDeliveries.AddRange(AvailableVertices.Where(x => !selectedDeliveries.Contains(x))); HighResponse = AvailableVertices.Count == 0 ? this : new DeiveryVerticeBase(selectedDeliveries, notSelectedDeliveries); return(bound); }
public IEnumerable <ITreeVertice <Delivery> > GetNextVertices() { foreach (var delivery in AvailableVertices) { var newSelected = SelectedVertices.ToList(); newSelected.Add(delivery); var newAvailable = AvailableVertices.Where(x => x.Id != delivery.Id).ToList(); yield return(new DeiveryVerticeBase(newSelected, newAvailable)); } }