public void SetBigrams(Tuple<string, string>[] bigrams) { this.Bigrams = bigrams.Aggregate( new List<BigramItem>(), (list, tup) => { list.Add(new BigramItem(tup)); return list; }) .ToArray(); }
protected RouteSet ParallelMultiStartPenalization <TProcedure, TParameters>(Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, TProcedure procedure, TParameters parameters, List <RouteSet> initialPool) where TProcedure : LocalSearchProcedure <RouteSet, TParameters> { OverloadFactor = overloadFactor; Stopwatch timer = new Stopwatch(); Tuple <RouteSet, double>[] solutions = new Tuple <RouteSet, double> [initialPool.Count]; Parallel.For(0, initialPool.Count, i => { Random pRdObj = new Random((i + 1) * (i + 2) * Environment.TickCount); RouteSet current = procedure.Solve(parameters, initialPool[i], neighborhoods, expCondition, GetCost, pRdObj); double cost = GetCost(current); solutions[i] = new Tuple <RouteSet, double>(current, cost); }); return(solutions.Aggregate((min, x) => min.Item2 < x.Item2 ? min : x).Item1); }
public IndexMode GetIndexMode() { var lists = new Tuple <IReadOnlyList <PointRecord>, string>[] { CreateTuple(binaries, "binary"), CreateTuple(doubleBinaries, "analog"), CreateTuple(counters, "counter"), CreateTuple(frozenCounters, "frozen counter"), CreateTuple(analogs, "analog"), CreateTuple(binaryOutputStatii, "binary output status"), CreateTuple(analogOutputStatii, "analog output status"), CreateTuple(timeAndIntervals, "time and interval") }; // this can throw an exception if any of the sub lists have bad discontiguous indices var allContiguous = lists.Aggregate(true, (sum, pair) => sum && IsContiguous(pair.Item1, pair.Item2)); return(allContiguous ? IndexMode.Contiguous : IndexMode.Discontiguous); }
public static MvcHtmlString SvgPolyLine( this HtmlHelper htmlHelper, Tuple<float, float>[] points, string id = null, string cssClass = null, string stroke = null, double strokeWidth = DefaultStrokeWidth, string fill = null, string styles = null) { var tagBuilder = new TagBuilder("polyline"); string pointValues = points.Aggregate(string.Empty, (x, p) => x + string.Format("{0}, {1} ", p.Item1.ToString(), p.Item2.ToString())); if (!string.IsNullOrWhiteSpace(pointValues)) { tagBuilder.Attributes.Add("points", pointValues); } if (!string.IsNullOrWhiteSpace(id)) { tagBuilder.Attributes.Add("id", htmlHelper.Encode(id)); } if (!string.IsNullOrWhiteSpace(cssClass)) { tagBuilder.Attributes.Add("class", htmlHelper.Encode(cssClass)); } string style = string.Empty; style += !string.IsNullOrWhiteSpace(stroke) ? string.Format("stroke: {0};", stroke) : string.Empty; style += string.Format("stroke-width: {0};", strokeWidth); style += !string.IsNullOrWhiteSpace(fill) ? string.Format("fill: {0};", fill) : string.Empty; style += !string.IsNullOrWhiteSpace(styles) ? styles : string.Empty; if (!string.IsNullOrWhiteSpace(style)) { tagBuilder.Attributes.Add("style", htmlHelper.Encode(style)); } return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal)); }
public void Run(bool log = true) { Console.WriteLine($"Running Sorting test with {Generations} data sets."); const int offset = 2; int length = _runners.Count + offset; var headers = new string[length]; headers[0] = "No."; headers[1] = "Count"; for (int i = 0; i < _runners.Count; i++) { headers[i + offset] = _runners[i].Id; } _logger = new ConsoleLogger(headers); if (log) { _logger.WriteHeader(); } string path = string.Format(CsvFilePattern, DateTime.Now.ToString().Replace('/', '-')).Replace(':', '.'); using var csvWriter = new StreamWriter(path); for (int i = 1; i <= Generations; i++) { if (!log) { Console.WriteLine($"Running Generation {i}..."); } int pos = offset; var entries = new Tuple <string, bool> [length]; entries[0] = new Tuple <string, bool>(i.ToString(), true); entries[1] = new Tuple <string, bool>(CalculateEntries(i).ToString(), true); foreach (var runner in _runners) { runner.Run(i.ToString()); GC.Collect(); GC.WaitForPendingFinalizers(); var sw = new Stopwatch(); sw.Start(); runner.Sort(); sw.Stop(); entries[pos++] = new Tuple <string, bool>(sw.ElapsedMilliseconds.ToString(), true); } if (log) { _logger.WriteEntry(entries); } csvWriter.WriteLine(entries.Aggregate(string.Empty, (current, entry) => current + $"{entry.Item1};")); } if (!log) { Console.WriteLine("Test complete!"); } }