/// <summary> /// Get the next example on which to learn, if one exists. The next example is the first /// unused example on which the currently learned program fails. If no program has been found yet, /// the next example is simply the first unused example. /// </summary> /// <param name="nextExample">The next example.</param> /// <returns>true if there exists a next example, otherwise false.</returns> protected bool TryGetNextExample(out TExample nextExample) { if (UsedExamples.Count == AllExamples.Count) { nextExample = null; return(false); } if (Program == null) { nextExample = AllExamples.Except(UsedExamples).FirstOrDefault(); return(nextExample != null); } var firstFailedIndex = AllExamples.Select(e => Valid(e, Program)).IndexOf(false); if (firstFailedIndex.HasValue) { nextExample = AllExamples[firstFailedIndex.Value]; return(true); } nextExample = null; return(false); }
public override void Run() { if (!Directory.Exists(ReportDirPath)) { Directory.CreateDirectory(ReportDirPath); } Console.WriteLine($"Learning Extraction.Text sequence program for {SubBenchmarkName}"); while (!Success && TryGetNextExample(out SequenceExample nextConstraint)) { var session = new SequenceSession(); UsedExamples.Add(nextConstraint); session.Constraints.Add(UsedExamples); Program = session.Learn(); Success = Program != null && AllExamples.All(e => Valid(e, Program)); } RecordResult(); }