11using System . Diagnostics ;
22using System . Runtime . CompilerServices ;
3+ using Genbox . FastData . Internal . Abstracts ;
34using Genbox . FastData . Internal . Analysis ;
45using Genbox . FastData . Internal . Analysis . Analyzers ;
56using Genbox . FastData . Internal . Analysis . Properties ;
@@ -66,12 +67,9 @@ private static void RunBruteForce(string[] data, [CallerArgumentExpression(nameo
6667
6768 StringProperties props = DataAnalyzer . GetStringProperties ( data ) ;
6869 using SerilogLoggerFactory loggerFactory = new SerilogLoggerFactory ( _logConf ) ;
69- BruteForceAnalyzer analyzer = new BruteForceAnalyzer ( props , new BruteForceAnalyzerConfig ( ) , new Simulator ( new SimulatorConfig ( ) ) , loggerFactory . CreateLogger < BruteForceAnalyzer > ( ) ) ;
70- analyzer . GetCandidates ( data , candidate =>
71- {
72- PrintCandidate ( candidate ) ;
73- return false ;
74- } ) ;
70+ BruteForceAnalyzer analyzer = new BruteForceAnalyzer ( props , new BruteForceAnalyzerConfig ( ) , new Simulator ( ) , loggerFactory . CreateLogger < BruteForceAnalyzer > ( ) ) ;
71+ PrintCandidate ( GetCandidates ( analyzer ) . OrderByDescending ( x => x . Fitness ) . FirstOrDefault ( ) ) ;
72+
7573 }
7674
7775 private static void RunGeneticAnalysis ( string [ ] data , [ CallerArgumentExpression ( nameof ( data ) ) ] string ? source = null )
@@ -80,12 +78,9 @@ private static void RunGeneticAnalysis(string[] data, [CallerArgumentExpression(
8078
8179 StringProperties props = DataAnalyzer . GetStringProperties ( data ) ;
8280 using SerilogLoggerFactory loggerFactory = new SerilogLoggerFactory ( _logConf ) ;
83- GeneticAnalyzer analyzer = new GeneticAnalyzer ( props , new GeneticAnalyzerConfig ( ) , new Simulator ( new SimulatorConfig ( ) ) , loggerFactory . CreateLogger < GeneticAnalyzer > ( ) ) ;
84- analyzer . GetCandidates ( data , candidate =>
85- {
86- PrintCandidate ( candidate ) ;
87- return false ;
88- } ) ;
81+ GeneticAnalyzer analyzer = new GeneticAnalyzer ( props , new GeneticAnalyzerConfig ( ) , new Simulator ( ) , loggerFactory . CreateLogger < GeneticAnalyzer > ( ) ) ;
82+ PrintCandidate ( GetCandidates ( analyzer ) . OrderByDescending ( x => x . Fitness ) . FirstOrDefault ( ) ) ;
83+
8984 }
9085
9186 private static void RunGPerfAnalysis ( string [ ] data , [ CallerArgumentExpression ( nameof ( data ) ) ] string ? source = null )
@@ -94,17 +89,13 @@ private static void RunGPerfAnalysis(string[] data, [CallerArgumentExpression(na
9489
9590 StringProperties props = DataAnalyzer . GetStringProperties ( data ) ;
9691 using SerilogLoggerFactory loggerFactory = new SerilogLoggerFactory ( _logConf ) ;
97- GPerfAnalyzer analyzer = new GPerfAnalyzer ( data . Length , props , new GPerfAnalyzerConfig ( ) , new Simulator ( new SimulatorConfig ( ) ) , loggerFactory . CreateLogger < GPerfAnalyzer > ( ) ) ;
98- analyzer . GetCandidates ( data , candidate =>
99- {
100- PrintCandidate ( candidate ) ;
101- return false ;
102- } ) ;
92+ GPerfAnalyzer analyzer = new GPerfAnalyzer ( data . Length , props , new GPerfAnalyzerConfig ( ) , new Simulator ( ) , loggerFactory . CreateLogger < GPerfAnalyzer > ( ) ) ;
93+ PrintCandidate ( GetCandidates ( analyzer ) . OrderByDescending ( x => x . Fitness ) . FirstOrDefault ( ) ) ;
10394 }
10495
105- private static void Print ( string [ ] data , string ? source )
96+ private static void Print ( string [ ] data , string ? source , [ CallerMemberName ] string ? member = null )
10697 {
107- Console . WriteLine ( " ###############") ;
98+ Console . WriteLine ( $ "############### { member } ###############") ;
10899 Console . WriteLine ( source + ": " + string . Join ( ", " , data . Take ( 5 ) ) ) ;
109100 }
110101
@@ -155,8 +146,11 @@ private static string[] RunFunc(string[] str, double factor, Func<string, double
155146 return res ;
156147 }
157148
158- private static void PrintCandidate ( Candidate candidate )
149+ private static void PrintCandidate ( Candidate ? candidate )
159150 {
151+ if ( candidate == null )
152+ return ;
153+
160154 Console . WriteLine ( ) ;
161155 Console . WriteLine ( "#### Candidate ####" ) ;
162156 Console . WriteLine ( $ "{ nameof ( candidate . Fitness ) } : { candidate . Fitness } ") ;
@@ -175,4 +169,15 @@ private static void PrintCandidate(Candidate candidate)
175169 // Console.WriteLine(candidate.StringHash.GetExpression().ToReadableString());
176170 Console . WriteLine ( ExpressionHelper . Print ( candidate . StringHash . GetExpression ( ) ) ) ;
177171 }
172+
173+ private static IEnumerable < Candidate > GetCandidates ( IStringHashAnalyzer analyzer )
174+ {
175+ List < Candidate > candidates = new List < Candidate > ( ) ;
176+ analyzer . GetCandidates ( Data , candidate =>
177+ {
178+ candidates . Add ( candidate ) ;
179+ return true ;
180+ } ) ;
181+ return candidates ;
182+ }
178183}
0 commit comments