public void TestOpen(Int32 ProblemID, Int32 SolutionID, string SolutionName, ProgrammingLanguages PL, TournamentFormats TF, out TestResults Result, out int Score) { // TODO: FL Result = TestResults.RTE; Score = 0; File.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\checker.exe", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", true); // Test CheckSolutionOutput( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\OpenProblemResult", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + SolutionName, LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\OpenProblemResult", out Result); if (Result == TestResults.OK) { Score = 100; } }
public SolutionObject(Int32 ProblemID, Int32 SolutionID, ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT, string RelativePathToFile, string FileName) { this.ProblemID = ProblemID; this.SolutionID = SolutionID; this.PL = PL; this.TF = TF; this.PT = PT; this.RelativePathToFile = RelativePathToFile; this.FileName = FileName; }
/// <summary> /// Add solution for checking /// </summary> public void AddSolutionForChecking(Int32 problemID, Int32 solutionID, ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT, string relativePathToFile, string fileName) { lock (this._lockSolutionsQueue) { _solutionsQueue.Enqueue(new SolutionObject(problemID, solutionID, PL, TF, PT, relativePathToFile, fileName)); _solutionAdded.Set(); _logger.Info("Solution " + solutionID + " for problem " + problemID + " on PL " + PL + " added to queue"); } }
public void Test(Int32 ProblemID, Int32 SolutionID, string SolutionName, ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT, out TestResults Result, out int Score, out List <Tuple <long, long, TestResults> > testResults) { CanTest.Wait(); AllDone.Reset(); Interlocked.Increment(ref threadCount); logger.Debug("Start {0} thread", threadCount); if (logger.IsDebugEnabled) { Console.WriteLine(DateTime.Now.ToString(culture) + " - Start {0} thread", threadCount); } // TODO: FL Result = TestResults.RTE; Score = 0; testResults = null; logger.Trace("Start testing solution {0}", SolutionID); if (logger.IsTraceEnabled) { Console.WriteLine(DateTime.Now.ToString(culture) + " - Start testing solution {0}", SolutionID); } try { switch (PT) { case ProblemTypes.Standart: TestStandart(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score, out testResults); break; case ProblemTypes.Open: TestOpen(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score); break; } } catch (Exception ex) { logger.Error("Error occurred on solution {0} testing: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} testing: {1}", SolutionID, ex.Message); } Interlocked.Decrement(ref threadCount); if (threadCount == 0) { AllDone.Set(); } }
private static void SaveSolution(byte[] Data, out int ProblemID, out int SolutionID, out string FileName, out ProgrammingLanguages PL, out TournamentFormats TF, out ProblemTypes PT) { ProblemID = BitConverter.ToInt32(Data, 8); SolutionID = BitConverter.ToInt32(Data, 12); PL = (ProgrammingLanguages)BitConverter.ToInt32(Data, 16); TF = (TournamentFormats)BitConverter.ToInt32(Data, 20); PT = (ProblemTypes)BitConverter.ToInt32(Data, 24); Int32 FileNameLength = BitConverter.ToInt32(Data, 28); FileName = Encoding.ASCII.GetString(Data, 32, FileNameLength); try { if (!Directory.Exists(LocalPath.SolutionsDirectory)) { Directory.CreateDirectory(LocalPath.SolutionsDirectory); } if (Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString())) { Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString(), true); } Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString()); using (BinaryWriter bw = new BinaryWriter( File.Open(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + FileName, FileMode.Create))) { bw.Write(Data, FileNameLength + 32, Data.Length - FileNameLength - 32); } logger.Trace("Solution {0} saved", SolutionID); if (logger.IsTraceEnabled) { Console.WriteLine(DateTime.Now.ToString(culture) + " - Solution {0} saved", SolutionID); } } catch (Exception ex) { logger.Error("Error occurred on solution {0} saving: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} saving: {1}", SolutionID, ex.Message); } }
public void Test(Int32 ProblemID, Int32 SolutionID, string SolutionName, ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT, out TestResults Result, out int Score, out List<Tuple<long, long, TestResults>> testResults) { CanTest.Wait(); AllDone.Reset(); Interlocked.Increment(ref threadCount); logger.Debug("Start {0} thread", threadCount); if (logger.IsDebugEnabled) Console.WriteLine(DateTime.Now.ToString(culture) + " - Start {0} thread", threadCount); // TODO: FL Result = TestResults.RTE; Score = 0; testResults = null; logger.Trace("Start testing solution {0}", SolutionID); if (logger.IsTraceEnabled) Console.WriteLine(DateTime.Now.ToString(culture) + " - Start testing solution {0}", SolutionID); try { switch (PT) { case ProblemTypes.Standart: TestStandart(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score, out testResults); break; case ProblemTypes.Open: TestOpen(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score); break; } } catch (Exception ex) { logger.Error("Error occurred on solution {0} testing: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} testing: {1}", SolutionID, ex.Message); } Interlocked.Decrement(ref threadCount); if (threadCount == 0) AllDone.Set(); }
/// <summary> /// Send information about solution to client. /// </summary> public void SendSolutionFile(Int32 problemID, Int32 solutionID, ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT, string relativePathToFile, string fileName) { _canSendRequest.Wait(); ClientFreeThreadsCount--; string absolutePath = Path.Combine(LocalPath.RootDirectory, relativePathToFile); if (!File.Exists(absolutePath)) { throw new FileNotFoundException(absolutePath); } string extension = Path.GetExtension(fileName); if (extension == "") { switch (PL) { case ProgrammingLanguages.C: extension = ".c"; break; case ProgrammingLanguages.CPP: extension = ".cpp"; break; case ProgrammingLanguages.CS: extension = ".cs"; break; case ProgrammingLanguages.Pascal: extension = ".pas"; break; case ProgrammingLanguages.Python: extension = ".py"; break; case ProgrammingLanguages.VB: extension = ".vb"; break; default: _logger.Warn("Send solution " + solutionID + " file without extension"); break; } } string fName = PL == ProgrammingLanguages.Java ? fileName : solutionID.ToString() + extension; byte[] name = Encoding.ASCII.GetBytes(fName); byte[] fileData = File.ReadAllBytes(absolutePath); byte[] clientData = new byte[4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + name.Length + fileData.Length]; byte[] fileNameLen = BitConverter.GetBytes(name.Length); BitConverter.GetBytes(clientData.Length).CopyTo(clientData, 0); BitConverter.GetBytes((Int32)RequestCodes.SolutionFile).CopyTo(clientData, 4); BitConverter.GetBytes(problemID).CopyTo(clientData, 8); BitConverter.GetBytes(solutionID).CopyTo(clientData, 12); BitConverter.GetBytes((Int32)PL).CopyTo(clientData, 16); BitConverter.GetBytes((Int32)TF).CopyTo(clientData, 20); BitConverter.GetBytes((Int32)PT).CopyTo(clientData, 24); fileNameLen.CopyTo(clientData, 28); name.CopyTo(clientData, 32); fileData.CopyTo(clientData, 32 + name.Length); Send(clientData, clientData.Length); _logger.Debug(Address + ": Send solution " + solutionID + " file"); }
private static void SaveSolution(byte[] Data, out int ProblemID, out int SolutionID, out string FileName, out ProgrammingLanguages PL, out TournamentFormats TF, out ProblemTypes PT) { ProblemID = BitConverter.ToInt32(Data, 8); SolutionID = BitConverter.ToInt32(Data, 12); PL = (ProgrammingLanguages)BitConverter.ToInt32(Data, 16); TF = (TournamentFormats)BitConverter.ToInt32(Data, 20); PT = (ProblemTypes)BitConverter.ToInt32(Data, 24); Int32 FileNameLength = BitConverter.ToInt32(Data, 28); FileName = Encoding.ASCII.GetString(Data, 32, FileNameLength); try { if (!Directory.Exists(LocalPath.SolutionsDirectory)) { Directory.CreateDirectory(LocalPath.SolutionsDirectory); } if (Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString())) { Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString(), true); } Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString()); using (BinaryWriter bw = new BinaryWriter( File.Open(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + FileName, FileMode.Create))) { bw.Write(Data, FileNameLength + 32, Data.Length - FileNameLength - 32); } logger.Trace("Solution {0} saved", SolutionID); if (logger.IsTraceEnabled) Console.WriteLine(DateTime.Now.ToString(culture) + " - Solution {0} saved", SolutionID); } catch (Exception ex) { logger.Error("Error occurred on solution {0} saving: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} saving: {1}", SolutionID, ex.Message); } }
public void TestStandart(Int32 ProblemID, Int32 SolutionID, string SolutionName, ProgrammingLanguages PL, TournamentFormats TF, out TestResults Result, out int Score, out List<Tuple<long, long, TestResults>> TestResults) { // TODO: FL Result = Solomon.TypesExtensions.TestResults.RTE; TestResults = null; Score = 0; File.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\checker.exe", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", true); DirectoryExtensions.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\Tests", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", false); if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe")) { Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe"); } if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output")) { Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output"); } CompilerSingleton.Instance.Compile( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + SolutionName, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe", PL, out Result, SolutionID); if (Result != Solomon.TypesExtensions.TestResults.OK) { //Interlocked.Decrement(ref threadCount); return; } // Testing // TODO: FL Result = Solomon.TypesExtensions.TestResults.RTE; TestResults = new List<Tuple<long, long, TestResults>>(); Tuple<long, long, TestResults> tempTuple; // Get all "in" files String[] inFiles = null; inFiles = Directory.GetFiles( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", "*.in"); double timeLimit; int memoryLimit; string name; long solutionTime, solutionMemory; DateTime lastModifiedTime; ProblemLegend.Read(LocalPath.ProblemsDirectory + ProblemID.ToString(), out name, out timeLimit, out memoryLimit, out lastModifiedTime); int testOK = 0; foreach (String inFile in inFiles) { solutionTime = 0; solutionMemory = 0; try { if (PL == ProgrammingLanguages.Java) { RunSolutionClass( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName, inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } else if (PL == ProgrammingLanguages.Python) { RunSolutionPython( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName, inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } else { RunSolutionExe( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe", inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } } catch (Exception ex) { logger.Error("Warning on solution {0} running: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Warning on solution {0} running: {1}", SolutionID, ex.Message); } if (Result != Solomon.TypesExtensions.TestResults.OK) { tempTuple = new Tuple<long, long, TestResults>(solutionTime, solutionMemory, Result); TestResults.Add(tempTuple); if (TF == TournamentFormats.ACM) break; else continue; } Result = Solomon.TypesExtensions.TestResults.Executing; for (int i = 0; i < 5 && (int)Result >= 4; i++) { CheckSolutionOutput( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests\\" + Path.GetFileNameWithoutExtension(inFile) + ".out", out Result); } tempTuple = new Tuple<long, long, TestResults>(solutionTime, solutionMemory, Result); TestResults.Add(tempTuple); if (Result != Solomon.TypesExtensions.TestResults.OK) { if (TF == TournamentFormats.ACM) break; } else { testOK++; } } if (TF == TournamentFormats.IOI) { Score = 100 * testOK / inFiles.Length; Result = testOK == inFiles.Length ? Solomon.TypesExtensions.TestResults.OK : Solomon.TypesExtensions.TestResults.PS; } if (File.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt")) File.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt"); for (int i = 0; i < 5; i++) { try { Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", true); break; } catch (Exception) { Thread.Sleep(100); } } }
public void TestStandart(Int32 ProblemID, Int32 SolutionID, string SolutionName, ProgrammingLanguages PL, TournamentFormats TF, out TestResults Result, out int Score, out List <Tuple <long, long, TestResults> > TestResults) { // TODO: FL Result = Solomon.TypesExtensions.TestResults.RTE; TestResults = null; Score = 0; File.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\checker.exe", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", true); DirectoryExtensions.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\Tests", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", false); if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe")) { Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe"); } if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output")) { Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output"); } CompilerSingleton.Instance.Compile( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + SolutionName, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe", PL, out Result, SolutionID); if (Result != Solomon.TypesExtensions.TestResults.OK) { //Interlocked.Decrement(ref threadCount); return; } // Testing // TODO: FL Result = Solomon.TypesExtensions.TestResults.RTE; TestResults = new List <Tuple <long, long, TestResults> >(); Tuple <long, long, TestResults> tempTuple; // Get all "in" files String[] inFiles = null; inFiles = Directory.GetFiles( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", "*.in"); double timeLimit; int memoryLimit; string name; long solutionTime, solutionMemory; DateTime lastModifiedTime; ProblemLegend.Read(LocalPath.ProblemsDirectory + ProblemID.ToString(), out name, out timeLimit, out memoryLimit, out lastModifiedTime); int testOK = 0; foreach (String inFile in inFiles) { solutionTime = 0; solutionMemory = 0; try { if (PL == ProgrammingLanguages.Java) { RunSolutionClass( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName, inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } else if (PL == ProgrammingLanguages.Python) { RunSolutionPython( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName, inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } else { RunSolutionExe( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe", inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory); } } catch (Exception ex) { logger.Error("Warning on solution {0} running: {1}", SolutionID, ex.Message); Console.WriteLine(DateTime.Now.ToString(culture) + " - Warning on solution {0} running: {1}", SolutionID, ex.Message); } if (Result != Solomon.TypesExtensions.TestResults.OK) { tempTuple = new Tuple <long, long, TestResults>(solutionTime, solutionMemory, Result); TestResults.Add(tempTuple); if (TF == TournamentFormats.ACM) { break; } else { continue; } } Result = Solomon.TypesExtensions.TestResults.Executing; for (int i = 0; i < 5 && (int)Result >= 4; i++) { CheckSolutionOutput( LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", inFile, LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt", LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests\\" + Path.GetFileNameWithoutExtension(inFile) + ".out", out Result); } tempTuple = new Tuple <long, long, TestResults>(solutionTime, solutionMemory, Result); TestResults.Add(tempTuple); if (Result != Solomon.TypesExtensions.TestResults.OK) { if (TF == TournamentFormats.ACM) { break; } } else { testOK++; } } if (TF == TournamentFormats.IOI) { Score = 100 * testOK / inFiles.Length; Result = testOK == inFiles.Length ? Solomon.TypesExtensions.TestResults.OK : Solomon.TypesExtensions.TestResults.PS; } if (File.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt")) { File.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt"); } for (int i = 0; i < 5; i++) { try { Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", true); break; } catch (Exception) { Thread.Sleep(100); } } }