public static SmSchedulePricePath Build(int weekMin, int weekMax, int[] markdownWeeks, SmPriceLadderType ladderType, decimal[] prices) { var weekCount = weekMax - weekMin + 1; if (markdownWeeks.Length == 0) { return(new SmSchedulePricePath { Prices = Enumerable.Repeat((decimal?)null, weekCount).ToArray(), Weeks = Enumerable.Range(weekMin, weekCount).ToArray(), MarkdownCount = markdownWeeks.Length, LadderType = ladderType }); } var result = new decimal?[weekCount]; var pricePathIndex = -1; var weekNextMarkdown = markdownWeeks[0]; var weekNextMarkdownIndex = 0; for (var i = 0; i < weekCount; i++) { var week = weekMin + i; if (weekNextMarkdownIndex == 0 && week < weekNextMarkdown) { result[i] = null; continue; } if (week == weekNextMarkdown) { if (prices.Length - 1 >= pricePathIndex + 1) { pricePathIndex++; } if (markdownWeeks.Length - 1 >= weekNextMarkdownIndex + 1) { weekNextMarkdownIndex++; weekNextMarkdown = markdownWeeks[weekNextMarkdownIndex]; } } result[i] = prices[pricePathIndex]; } return(new SmSchedulePricePath { Prices = result, Weeks = Enumerable.Range(weekMin, weekCount).ToArray(), MarkdownCount = markdownWeeks.Length, LadderType = ladderType }); }
public static SmSchedulePricePath[] CrossProduct(int[] weeks, int weekMin, int weekMax, SmPriceLadderType ladderType, List <Tuple <int, decimal> > weekPries) { var query = weekPries .GroupBy(x => x.Item1, (x, g) => g.Select(y => y.Item2).ToArray()) .ToArray() .CartesianProduct() .Where(x => x.ToPairs().All(y => y.Item1 <= y.Item2)) .Select(x => x.ToArray()) .Where(x => x.Length == x.Distinct().Count()) .Select(x => SmSchedulePricePath.Build(weekMin, weekMax, weeks, ladderType, x)); return(query.ToArray()); }