public static SearchSetDTO Import(string filepath) { var ResultSet = new SearchSetDTO(); var file = File.ReadAllLines(filepath); var headertext = file.First(); ResultSet.InputFilename = filepath; ResultSet.Header = headertext; bool istabsplit; var commaheader = headertext.Split(','); var tabheader = headertext.Split('\t'); string[] header; if (commaheader.Count() > tabheader.Count()) { istabsplit = false; header = commaheader; } else { istabsplit = true; header = tabheader; } try { ResultSet.Items = file.Skip(1).AsParallel().Select(item => { string[] elements; if (istabsplit) { elements = item.Split('\t'); } else { elements = item.Split(','); } if (elements.Count() != header.Count()) { throw new FileFormatException("Count mismatch in file"); } var uniqueid = elements[0].Trim(); var alias = elements[1].Trim(); bool required = false; var requiredstring = elements[2].Trim().ToUpper(); if (requiredstring.StartsWith("T") || requiredstring == "1") { required = true; } SearchItemDTO searchitem = new SearchItemDTO(uniqueid, alias, required, elements.Skip(3).Select(x => x.Trim()).ToArray(), item); return(searchitem); }).ToList(); } catch (AggregateException e) { throw e.InnerException; } return(ResultSet); }
private SearchItemDTO ConvertSearchDocumentToDTO(Document document) { var dto = new SearchItemDTO() { ParentPlanId = Guid.Parse((string)document["parentPlanId"]), Name = (string)document["name"], Description = (string)document["description"], Owner = (string)document["owner"] }; return(dto); }
private int CalculateDifferences(SearchItemDTO r1, SearchItemDTO r2) { int num = 0; if (r1.UniqueID != r2.UniqueID) { for (int index = 0; index < r1.Datapoints.Count(); ++index) { if (r1.Datapoints[index].Length > 0 && r2.Datapoints[index].Length > 0 && !r1.Datapoints[index].Equals(r2.Datapoints[index])) { ++num; } } } return(num); }
private void DoWork(SearchResultDTO previousBestIfExists) { var candidateSetDictionary = new Dictionary <string, SearchItemDTO>(); if (previousBestIfExists != null) { foreach (var item in previousBestIfExists.Items) { if (item.Required || item.PctMissing < m_SearchParams.AllowedPctMissing) { if (candidateSetDictionary.Count < m_SearchParams.ResultSize) { candidateSetDictionary[item.UniqueID] = item; } } if (item.Required) { candidateSetDictionary[item.UniqueID] = item; } } } foreach (var item in m_Data.Items) { if (item.Required) { candidateSetDictionary[item.UniqueID] = item; } } int loops = 0; while (candidateSetDictionary.Count < m_SearchParams.ResultSize) { var candidate = PickRandomItem(); if (!candidateSetDictionary.ContainsKey(candidate.UniqueID)) { candidateSetDictionary[candidate.UniqueID] = candidate; } loops++; if (loops > m_Data.Items.Count * 10) { throw new Exception("wtf"); } } // Got starting set and make it the best so far m_BestResult = new SearchResultDTO(); m_BestResult.Items = candidateSetDictionary.Values.ToList(); m_BestResult.Result = Measure(m_BestResult.Items); new System.Threading.Tasks.Task(() => BestResultFoundEvent(m_BestResult)).Start(m_sched); while (m_keepworking) { loops = 0; SearchItemDTO candidate = null; while (candidate == null) { loops++; if (loops > m_Data.Items.Count * 10) { throw new Exception("wtf"); } var temp = PickRandomItem(); if (!candidateSetDictionary.ContainsKey(temp.UniqueID)) { candidate = temp; } } // We have a new candidate, try it out in every slot and measure var testArray = candidateSetDictionary.Values.ToArray(); int improved = 0; for (int idx = 0; idx < candidateSetDictionary.Keys.Count; idx++) { var itemSubbedOut = testArray[idx]; if (!itemSubbedOut.Required) { testArray[idx] = candidate; var candidateResult = new SearchResultDTO(); candidateResult.Items = testArray.ToList(); candidateResult.Result = Measure(candidateResult.Items); if (!m_BestResult.IsBetterThan(candidateResult, m_SearchParams.SearchType) || RandomNumber.Next(100000) == 66666) { m_BestResult = candidateResult; improved++; new System.Threading.Tasks.Task(() => BestResultFoundEvent(m_BestResult)).Start(m_sched); } testArray[idx] = itemSubbedOut; } } if (improved > 0) { candidateSetDictionary.Clear(); foreach (var item in m_BestResult.Items) { candidateSetDictionary[item.UniqueID] = item; } loops++; if (loops > m_Data.Items.Count * 10) { throw new Exception("wtf"); } } } }