public void PostSolutionsForSameProblems3() { var repo = new ProblemsRepo(); var solutions = new Dictionary <int, Tuple <string, double, int> >(); Console.Out.WriteLine($"calculating"); foreach (var problemSpec in repo.GetAll().Where(p => repo.FindSolution(p.id) != null)) { var perms = GetAllPerms(problemSpec); var polygonsHashCode = perms.Select(p => p.MoveToOrigin().GetPolygonsHashCode()).ToList().Min(); Tuple <string, double, int> prev; if (!solutions.TryGetValue(polygonsHashCode, out prev) || prev.Item2 < repo.GetProblemResemblance(problemSpec.id)) { solutions[polygonsHashCode] = Tuple.Create(repo.FindSolution(problemSpec.id), repo.GetProblemResemblance(problemSpec.id), problemSpec.id); } } foreach (var problemSpec in repo.GetAll()) { var perms = GetAllPerms(problemSpec); var polygonsHashCode = perms.Select(p => p.MoveToOrigin().GetPolygonsHashCode()).ToList().Min(); Tuple <string, double, int> best; if (solutions.TryGetValue(polygonsHashCode, out best)) { if (repo.GetProblemResemblance(problemSpec.id) < best.Item2) { Console.Out.Write($"{problemSpec.id} -> {best.Item3}: "); Console.Out.Write($"{repo.GetProblemResemblance(problemSpec.id)} -> {best.Item2}"); Console.Out.WriteLine(); } } // ProblemsSender.Post(new SolutionSpec(best.Item1), problemSpec.id, pack: false); } }
public void PostSolutionsForSameProblems() { var repo = new ProblemsRepo(); var solutions = new Dictionary <int, Tuple <string, double, int> >(); foreach (var problemSpec in repo.GetAll().Where(p => repo.FindSolution(p.id) != null)) { var polygonsHashCode = problemSpec.GetPolygonsHashCode(); Tuple <string, double, int> prev; if (!solutions.TryGetValue(polygonsHashCode, out prev) || prev.Item2 < repo.GetProblemResemblance(problemSpec.id)) { solutions[polygonsHashCode] = Tuple.Create(repo.FindSolution(problemSpec.id), repo.GetProblemResemblance(problemSpec.id), problemSpec.id); } } foreach (var problemSpec in repo.GetAll()) { var polygonsHashCode = problemSpec.GetPolygonsHashCode(); Tuple <string, double, int> best; if (solutions.TryGetValue(polygonsHashCode, out best) && repo.GetProblemResemblance(problemSpec.id) < best.Item2) { Console.Write($"{problemSpec.id}->{best.Item3}: "); ProblemsSender.Post(new SolutionSpec(best.Item1), problemSpec.id, pack: false); Console.WriteLine(); } } }
public void CalcImperfectScore2() { var repo = new ProblemsRepo(); var c = repo.GetAllNotSolvedPerfectly().Count(); Console.WriteLine(c); Console.WriteLine(repo.GetAll().Count()); }
public void DoSomething_WhenSomething() { var repo = new ProblemsRepo(); var apiClient = new ApiClient(); foreach (var problemSpec in repo.GetAll() .Where(x => repo.GetProblemResemblance(x.id) == 1.0) .Reverse().Take(3)) { Console.Out.WriteLine(problemSpec.id); var solutionSpec = ConvexPolygonSolver.TrySolveSingleProblem(problemSpec); if (solutionSpec != null) { var response = apiClient.PostSolution(problemSpec.id, solutionSpec.Normalize().Pack()); Console.Out.WriteLine(response); } } }
public void CalculateOurScore() { var repo = new ProblemsRepo(); var sn = repo.GetSnapshot(null); var ourScore1 = 0.0; var ourScore2 = 0.0; var ourScore3 = 0.0; foreach (var pr in sn.Problems) { var solutions = pr.Ranking.Count(r => r.resemblance == 1.0); var part = pr.SolutionSize / (solutions + 1.0); var myR = repo.GetProblemResemblance(pr.Id); if (myR == 1.0) { ourScore1 += part; } else { var rSum = pr.Ranking.Where(r => r.resemblance != 1.0).Sum(r => r.resemblance); ourScore2 += part * myR / rSum; } if (pr.Owner == "89") { ourScore3 += (5000 - pr.SolutionSize) / Math.Max(6, solutions + 1.0); } } Console.WriteLine(ourScore1); Console.WriteLine(ourScore2); Console.WriteLine(ourScore3); Console.WriteLine(ourScore1 + ourScore2 + ourScore3); var prCount = repo.GetAll().Count(); var noSolvedCount = repo.GetAllNotSolvedPerfectly().Count(); Console.WriteLine(prCount - noSolvedCount); Console.WriteLine(prCount); }
private object[] GetItems(Func <IEnumerable <ProblemListItem>, IEnumerable <ProblemListItem> > sortAndFilter) { IEnumerable <ProblemListItem> allItems = repo.GetAll().Select(CreateItem); return(sortAndFilter(allItems).Cast <object>().ToArray()); }