public BestMatch LocateTheBestAproximateMatchForGivenRootPixel(PixelLocation encoderPoint, PixelLocation rootPoint) { BestMatch bestMatch = new BestMatch(); int rowOffset = 0; var widthOfTheMatchInThePreviousRow = _width - 1 - encoderPoint.X; do { int colOffset = 0; var nextRootPoint = new PixelLocation(rootPoint.X, rootPoint.Y + rowOffset); if (IsPixelEncoded[nextRootPoint.Y, nextRootPoint.X] || nextRootPoint.Y >= encoderPoint.Y && nextRootPoint.X >= encoderPoint.X) { colOffset = CoverColumns(encoderPoint, colOffset, rowOffset, nextRootPoint, widthOfTheMatchInThePreviousRow); } widthOfTheMatchInThePreviousRow = colOffset; rowOffset++; var matchSize = widthOfTheMatchInThePreviousRow * rowOffset; var blockDimensions = new Dimension(widthOfTheMatchInThePreviousRow, rowOffset); var matchMse = GetMse(encoderPoint, rootPoint, blockDimensions); if (matchSize >= bestMatch.Size && matchMse <= Constants.MaxMse) { bestMatch.Height = rowOffset; bestMatch.Width = widthOfTheMatchInThePreviousRow; bestMatch.Size = matchSize; } } while (widthOfTheMatchInThePreviousRow != 0 && encoderPoint.Y + rowOffset != _height - 1); return(bestMatch); }
public void LocateTheBestAproximateMatchForGivenRootPixelGivesTheExpectedBestMatch() { _gz2DlzEncoderFacade.InputFilePath = One3X4MatchBlockBmpPath; _gz2DlzEncoderFacade.AbstractPredictor = new ABasedPredictor(); _gz2DlzEncoderFacade.ImageReader = _bmpReader; _gz2DlzEncoderFacade.Archiver = new Paq6V2Archiver(); _encoder = new Gz2DlzEncoder(_gz2DlzEncoderFacade); var originalImage = _encoder.WorkImage; var width = originalImage.GetLength(0); for (int i = 0; i < width; i++) { _encoder.IsPixelEncoded[0, i] = true; _encoder.IsPixelEncoded[1, i] = true; _encoder.IsPixelEncoded[2, i] = true; _encoder.IsPixelEncoded[3, i] = true; _encoder.IsPixelEncoded[4, i] = true; } for (int i = 0; i < 5; i++) { _encoder.IsPixelEncoded[0, i] = true; } var encoderPosition = new PixelLocation(5, 5); var rootPosition = new PixelLocation(1, 1); BestMatch bestMatch = _encoder.LocateTheBestAproximateMatchForGivenRootPixel(encoderPosition, rootPosition); Assert.AreEqual(4, bestMatch.Height); Assert.AreEqual(4, bestMatch.Width); Assert.AreEqual(16, bestMatch.Size); }
public void GetMatches(int[] inputValues) { if (!inputValues.Any()) { BestMatch.Add(new List <int>()); return; } var numberOfTwenties = inputValues.Count(i => i == MaxSingleScore); if (numberOfTwenties > 0) { BestMatch.AddRange(Enumerable.Repeat(new List <int> { MaxSingleScore }, numberOfTwenties)); Total += numberOfTwenties * MaxSingleScore; } var strippedInputList = new List <int>(from i in inputValues where i > 0 && i < MaxSingleScore select i); var strippedSum = strippedInputList.Sum(); Total += strippedSum; bool NoTwentiesAndStrippedSumBelowThreshold(int x) => numberOfTwenties < 1 && (!strippedInputList.Any() || strippedSum < x); if (NoTwentiesAndStrippedSumBelowThreshold(BestTotal)) { BestMatch.Add(new List <int>()); return; } var minSum = FindMinFortyCombo(strippedInputList); while (minSum.Any()) { BestMatch.Add(minSum); minSum.ForEach(i => strippedInputList.Remove(i)); minSum = FindMinFortyCombo(strippedInputList); } }
private void ReadBestMatch() { var bestMatchNode = XmlDocument.SelectSingleNode("//configuration/bestmatch"); var bestMatch = new BestMatch(); var nameParts = bestMatchNode.SelectNodes("//preferences/nameparts/namepart"); var preferences = new Preferences { IgnoreMustHaveForOneRom = GetInnerTextAsBool(bestMatchNode.SelectSingleNode("//preferences/ignore_musthaves_for_one_rom")), IgnoreNeverUseForOneRom = GetInnerTextAsBool(bestMatchNode.SelectSingleNode("//preferences/ignore_neveruse_for_one_rom")) }; foreach (XmlNode namePartNode in nameParts) { var name = GetAttributeAsString(namePartNode, "name"); var value = GetAttributeAsString(namePartNode, "value"); var system = GetAttributeAsString(namePartNode, "system"); var type = GetAttributeAsString(namePartNode, "type"); var description = GetAttributeAsString(namePartNode, "description"); var position = GetAttributeAsInt(namePartNode, "position", -1); var behaviour = GetAttributeAsString(namePartNode, "behaviour"); var namePart = new NamePart(name, value, system, type, description, position, behaviour); preferences.NameParts.Add(namePart); } RearangeElements(preferences); bestMatch.Preferences = preferences; bestMatch.RomSourceDirectory = GetAttributeAsString(bestMatchNode.SelectSingleNode("//rom_source_directory"), "value"); bestMatch.RomDestinationDirectory = GetAttributeAsString(bestMatchNode.SelectSingleNode("//rom_destination_directory"), "value"); _configuration.BestMatch = bestMatch; }
public void CalculateMinimumShippingSpace(Inputs input) { try { List <Output> outputobj = new List <Output>(); string itemcode = input.itemcode; int noofitems = input.quantity; var itemstock = ProductData.GetItemStocks(); List <Sales> salesobj = new List <Sales>(); double totalprice = 0; var availablepacks = itemstock.Where(x => x.itemcode == itemcode).Select(x => x.packs).ToList(); if (availablepacks.Count == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(itemcode + ":\t" + noofitems.ToString()); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Product does not exists in stock"); Console.ResetColor(); return; } List <List <int> > res = ProductBusiness.CombinationSum(availablepacks, noofitems); if (res.Count == 0 || noofitems == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(itemcode + ":\t" + noofitems.ToString()); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Items with { noofitems} packs can not be added for the item code:- {itemcode}"); Console.ResetColor(); return; } else { List <BestMatch> bestmatchObj = new List <BestMatch>(); var resFilt = res.ToList().Min(x => x.Count); res = res.Where(x => x.Count == resFilt).ToList(); int resindex = 0; if (res.Count > 1) { string str; int index = 0; foreach (var listItm in res) { str = ""; BestMatch objbest = new BestMatch(); foreach (var item in listItm.OrderByDescending(x => x)) { str += item.ToString(); } objbest.index = index; objbest.Value = Convert.ToInt64(str); bestmatchObj.Add(objbest); index++; } resindex = bestmatchObj.OrderByDescending(item => item.Value).First().index; } Output objout = new Output(); objout.Sales = new List <Sales>(); foreach (var item in res[resindex]) { Sales objs = new Sales(); objs.itemcode = itemcode; objs.price = itemstock.Where(x => x.packs == item && x.itemcode == itemcode).Select(x => x.price).FirstOrDefault(); objs.quantity = item; objout.Sales.Add(objs); totalprice += itemstock.Where(x => x.packs == item && x.itemcode == itemcode).Select(x => x.price).FirstOrDefault(); } objout.itemcode = itemcode; objout.quantity = noofitems; objout.totalprice = totalprice; outputobj.Add(objout); } foreach (var result in outputobj) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(result.itemcode + " " + result.quantity.ToString()); Console.ResetColor(); var sales = result.Sales.Where(a => a.itemcode == itemcode).GroupBy(a => a.quantity) .Select(g => new { g.Key, TotalSales = g.Sum(pv => pv.price), price = g.Select(x => x.price).First(), Count = g.Count() }); foreach (var item in sales) { Console.WriteLine(itemcode + "\t\t\t" + item.Count.ToString() + " X " + item.Key.ToString() + "($" + item.price + ")" + "\t\t\t" + "$" + item.TotalSales.ToString()); } Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Total amount \t\t\t\t\t\t" + "$" + result.totalprice.ToString()); Console.ResetColor(); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message.ToString() + "\n\n"); Console.ResetColor(); } }
public int CompareTo(Peptide other) { return(BestMatch.CompareTo(other.BestMatch)); }