/// <summary> /// Do the move of cars from next(s) split(s) to the 's' split. /// regads to the 'carsToUp' dictionnary /// </summary> /// <param name="s">the target split we want to fill</param> /// <param name="carsToUp">Cars we need to move up. /// KEY is classId /// VALUE is number of cars /// </param> internal static void UpCarsToSplit(List <int> carClassesIds, List <Split> splits, Split s, Dictionary <int, int> carsToUp) { // for each class foreach (int classId in carsToUp.Keys) { // get missing cars count and class Id int classMissing = carsToUp[classId]; int classIndex = carClassesIds.IndexOf(classId); // --> // foreach missing car for (int i = 0; i < classMissing; i++) { // find a lower split containig the same class var nextSplitContainingSameClassCars = (from r in splits where r.Number > s.Number && r.CountClassCars(classIndex) > 0 select r).FirstOrDefault(); // doest we got one ? if (nextSplitContainingSameClassCars != null) { // pick the top car of the next split (the highest IR of it) var pick = nextSplitContainingSameClassCars.PickClassCars(classIndex, 1, false); // doest the the target split 's' already contains this class ? if (s.GetClassId(classIndex) != classIndex) { // no, we will create id s.SetClass(classIndex, classId); } // append the car in the target split 's' s.AppendClassCars(classIndex, pick); } else { // no... // we can not to the move // never mind we will fix that later // :-D } } // end of foreach missing car } // end of foreach class }
/// <summary> /// Add cars to split /// </summary> /// <param name="split">split to fill</param> /// <param name="carClassIndex">class index to fill</param> /// <param name="cars">cars to append</param> private void AppendCarsToSplit(Split split, int carClassIndex, List <Line> cars) { split.SetClass(carClassIndex, carClassesIds[carClassIndex]); split.AppendClassCars(carClassIndex, cars); }