private static void Test() { int threshold = 400 * 1000 * 1000; while (true) { var gsc = new GameServerClient(); TrainResponse problem = gsc.Train(TrainProblemType.Any, 15); Console.Out.WriteLine("==== TrainProblem: {0}", problem); Task <int> countTask = Task.Run(() => { IEnumerable <byte[]> trees = new BinaryBruteForcer(problem.operators).Enumerate(problem.size - 1); return(trees.TakeWhile((t, i) => i < threshold).Count()); }); Stopwatch sw = Stopwatch.StartNew(); string answer = ConcurrentWithoutShitAlphaProtocol.PostSolution(problem.id, problem.size, problem.operators); sw.Stop(); Console.Out.WriteLine("==== Solved, waiting for TreeSize..."); countTask.Wait(); Console.Out.WriteLine("==== SolvedIn: {0} ms, Answer: {1}, TreeSize: {2}", sw.ElapsedMilliseconds, answer, countTask.Result); } }
public string TrainProblemFilename(TrainResponse trainProblem, Problem problem) { bool isRelevant = trainProblem.operators.OrderBy(t => t).SequenceEqual(problem.AllOperators.OrderBy(t => t)); string filename = String.Format(isRelevant ? "{0}.txt" : "{0}.unrelevant.txt", problem.Id); return(Path.Combine(TrainProblemsPath, filename)); }
public bool Test(TrainResponse trainProblem, Problem problem) { var results = Source.ReadResultsForTrainProblem(trainProblem, problem); var test = new TestResult() { problem = problem, trainProblem = trainProblem, isSuccess = results.Count > 0 ? 1 : 0 }; try { var expr = Expr.ParseFunction(trainProblem.challenge); foreach (var xy in results) { var x = xy.Key; var y = xy.Value; var real = expr.Eval(new Vars(x)); if (real != y) { test.isSuccess = -1; test.x_expected_real.Add(new Tuple <ulong, ulong, ulong>(x, y, real)); } } } catch (Exception ex) { test.isSuccess = -1; test.exeption = ex.Message; } Tests.Add(test); return(test.isSuccess >= 0); }
public void MeasureMaskOptimization(string line) { var trainProblem = TrainResponse.Parse(line); byte[] p = Parser.ParseFunction(trainProblem.challenge); var ans = p.Printable(); var operations = trainProblem.operators; var random = new Random(); var answers = Enumerable.Range(0, 100).Select(i => random.NextUInt64()).Select(p.Eval).ToArray(); var mask = new Mask(answers); Console.WriteLine(" answers mask: {0}", mask); Console.WriteLine("challenge program mask: {0}", p.GetMask()); Console.WriteLine("answer: {0}", ans); var sw = Stopwatch.StartNew(); Assert.IsTrue(new BinaryBruteForcer(mask, 3, 1, operations).Enumerate(trainProblem.size - 1) .Select(f => f.Printable()) .Any(found => found == ans)); Console.WriteLine(sw.Elapsed); sw.Restart(); Assert.IsTrue( new BinaryBruteForcer(operations).Enumerate(trainProblem.size - 1) .Any(found => found.Printable() == ans)); Console.WriteLine(sw.Elapsed); }
public void DownloadTrainProblemsResults(Problem[] problems, bool onlyRelevant, UInt64[] arguments) { webApi = new WebApi(); for (int i = 0; i < problems.Length; ++i) { var problem = problems[i]; TrainResponse[] trainProblems = Source.ReadTrainProblems(problem, true); TrainResponse[] unrelevantTrainProblems = new TrainResponse[0]; if (!onlyRelevant) { unrelevantTrainProblems = Source.ReadTrainProblems(problem, false); } foreach (var trainProblem in trainProblems.Union(unrelevantTrainProblems)) { var currentResults = Source.ReadResultsForTrainProblem(trainProblem, problem); if (arguments.Any(arg => !currentResults.ContainsKey(arg))) { for (int k = 0; k < arguments.Length / 255; ++k) { var args = arguments.Skip(k * 255).Take(255).ToArray(); var results = DownloadTrainProblemResult(trainProblem, args); Source.SaveResultsForTrainProblem(trainProblem, problem, results); } } } } }
private void DownloadTrainProblems(IEnumerable <Problem> problems) { foreach (Problem problem in problems.Where(p => p.Size > 3).Shuffle()) { var trainRequest = new TrainRequest(problem.Size, problem.FoldOperators); TrainResponse trainProblem = webApi.Train(trainRequest); Source.SaveTrainProblem(trainProblem, problem); } }
private static void Create(params Departure[] departures) { _expectedResponse = new TrainResponse { Departures = new Departures { All = departures } }; }
public void MeasureMaskOptimization(string line) { var trainProblem = TrainResponse.Parse(line); Console.WriteLine(trainProblem.id); var prog = trainProblem.challenge; var operations = trainProblem.operators; var maxSize = trainProblem.size - 1; var minSize = maxSize; TrySolve(prog, operations, minSize, maxSize, false); // CheckResult(ans, new SmartGenerator(inputs, answers, operations).Enumerate(trainProblem.size - 1)); }
private async void Search_Click(object sender, RoutedEventArgs e) { if (trainRequest.from.StationID != 0 && trainRequest.to.StationID != 0) { //debugOutput.Text = trainRequest.getParameters().ToQueryString(); string data = await Requests.makeRequestAsync( Requests.TRAIN_URL, trainRequest.getParameters()); //debugOutput.Text = data; TrainResponse resp = Factory.Instance.getTrainResponse(data); results.DataContext = null; results.DataContext = resp.Trains; } }
public void Debug() { var problem = new TrainResponse { id = "lHObnL0KiFVC3c8vPkDDzAUc", challenge = "(lambda (x_12074) (shr4 (shr4 (if0 (or (shr16 x_12074) 1) (shl1 (shr1 x_12074)) x_12074))))", size = 12, operators = "if0,or,shl1,shr1,shr16,shr4".Split(','), }; Console.Out.WriteLine("==== TrainProblem: {0}", problem); var solver = new Solver(); var sw = Stopwatch.StartNew(); var answer = solver.SolveBinaryBrute(problem.id, problem.size, problem.OperatorsExceptBonus); sw.Stop(); Console.Out.WriteLine("==== SolvedIn: {0} ms, Answer: {1}", sw.ElapsedMilliseconds, answer); }
private IDictionary <UInt64, UInt64> DownloadTrainProblemResult(TrainResponse trainProblem, UInt64[] arguments) { EvalRequest request = new EvalRequest() { program = trainProblem.challenge, arguments = arguments.Select(i => i.ToString("X")).ToArray() }; var response = webApi.Eval(request); Dictionary <UInt64, UInt64> results = new Dictionary <ulong, ulong>(); if (response.outputs.Length != arguments.Length) { return(null); } for (int i = 0; i < response.outputs.Length; ++i) { UInt64 result = Convert.ToUInt64(response.outputs[i], 16); results[arguments[i]] = result; } return(results); }
public void SaveTrainProblem(TrainResponse trainProblem, Problem problem) { File.AppendAllText(TrainProblemFilename(trainProblem, problem), trainProblem + Environment.NewLine); }
public void SaveResultsForTrainProblem(TrainResponse trainProblem, Problem problem, IDictionary <UInt64, UInt64> results, bool rewrite = false) { string path = TrainProblemResultFilename(trainProblem, problem); SaveResults(path, results, rewrite); }
public Dictionary <UInt64, UInt64> ReadResultsForTrainProblem(TrainResponse trainProblem, Problem problem) { string path = TrainProblemResultFilename(trainProblem, problem); return(ReadResults(path)); }