1 | using HeuristicLab.Algorithms.Bandits;
|
---|
2 | using HeuristicLab.Algorithms.GrammaticalOptimization;
|
---|
3 | using HeuristicLab.Algorithms.MonteCarloTreeSearch.Base;
|
---|
4 | using HeuristicLab.Problems.GrammaticalOptimization;
|
---|
5 | using System;
|
---|
6 | using System.Collections.Generic;
|
---|
7 | using System.ComponentModel;
|
---|
8 |
|
---|
9 | namespace Evaluation
|
---|
10 | {
|
---|
11 |
|
---|
12 | public enum RunState
|
---|
13 | {
|
---|
14 | NotStarted,
|
---|
15 | Running,
|
---|
16 | Analyzing,
|
---|
17 | Finished
|
---|
18 | }
|
---|
19 |
|
---|
20 | public class Run : INotifyPropertyChanged
|
---|
21 | {
|
---|
22 | public Run()
|
---|
23 | {
|
---|
24 |
|
---|
25 | }
|
---|
26 |
|
---|
27 | public Run(ISymbolicExpressionTreeProblem problem, IBanditPolicy banditPolicy, ISolver solver, int runNumber,
|
---|
28 | int maxEvaluations, int maxLen)
|
---|
29 | {
|
---|
30 | Problem = problem;
|
---|
31 | BanditPolicy = banditPolicy;
|
---|
32 | Solver = solver;
|
---|
33 | RunNumber = runNumber;
|
---|
34 | MaxEvaluations = maxEvaluations;
|
---|
35 | MaxLen = maxLen;
|
---|
36 |
|
---|
37 | Evaluations = 0;
|
---|
38 | BestQuality = double.MinValue;
|
---|
39 | RunState = RunState.NotStarted;
|
---|
40 | FoundSolutions = new List<FoundSolution>();
|
---|
41 |
|
---|
42 | BestKnownQuality = problem.BestKnownQuality(maxLen);
|
---|
43 | solver.SolutionEvaluated += (sentence, quality) =>
|
---|
44 | {
|
---|
45 | Evaluations++;
|
---|
46 | if (quality > BestQuality)
|
---|
47 | {
|
---|
48 | BestQuality = quality;
|
---|
49 | BestSolution = sentence;
|
---|
50 | BestSolutionFoundAt = evaluations;
|
---|
51 | FoundSolutions.Add(new FoundSolution(DateTime.Now, Evaluations, quality, sentence));
|
---|
52 | }
|
---|
53 | };
|
---|
54 | }
|
---|
55 |
|
---|
56 | private ISymbolicExpressionTreeProblem problem;
|
---|
57 |
|
---|
58 | public ISymbolicExpressionTreeProblem Problem
|
---|
59 | {
|
---|
60 | get { return this.problem; }
|
---|
61 | set
|
---|
62 | {
|
---|
63 | this.problem = value;
|
---|
64 | this.OnPropertyChanged("Problem");
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | private IBanditPolicy banditPolicy;
|
---|
69 |
|
---|
70 | public IBanditPolicy BanditPolicy
|
---|
71 | {
|
---|
72 | get { return this.banditPolicy; }
|
---|
73 | set
|
---|
74 | {
|
---|
75 | this.banditPolicy = value;
|
---|
76 | this.OnPropertyChanged("BanditPolicy");
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | private ISolver solver;
|
---|
81 |
|
---|
82 | public ISolver Solver
|
---|
83 | {
|
---|
84 | get { return this.solver; }
|
---|
85 | set
|
---|
86 | {
|
---|
87 | this.solver = value;
|
---|
88 | this.OnPropertyChanged("Solver");
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | private int runNumber;
|
---|
93 |
|
---|
94 | public int RunNumber
|
---|
95 | {
|
---|
96 | get { return this.runNumber; }
|
---|
97 | set
|
---|
98 | {
|
---|
99 | this.runNumber = value;
|
---|
100 | this.OnPropertyChanged("RunNumber");
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | private int maxEvaluations;
|
---|
105 |
|
---|
106 | public int MaxEvaluations
|
---|
107 | {
|
---|
108 | get { return this.maxEvaluations; }
|
---|
109 | set
|
---|
110 | {
|
---|
111 | this.maxEvaluations = value;
|
---|
112 | this.OnPropertyChanged("MaxEvaluations");
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | private int maxLen;
|
---|
117 |
|
---|
118 | public int MaxLen
|
---|
119 | {
|
---|
120 | get { return this.maxLen; }
|
---|
121 | set
|
---|
122 | {
|
---|
123 | this.maxLen = value;
|
---|
124 | this.OnPropertyChanged("MaxLen");
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | private int evaluations;
|
---|
129 |
|
---|
130 | public int Evaluations
|
---|
131 | {
|
---|
132 | get { return this.evaluations; }
|
---|
133 | set
|
---|
134 | {
|
---|
135 | this.evaluations = value;
|
---|
136 | this.OnPropertyChanged("Evaluations");
|
---|
137 | if (endTime > startTime)
|
---|
138 | {
|
---|
139 | // endTime is set...
|
---|
140 | EvaluationsPerSecond = Math.Round(evaluations / TotalTime.TotalSeconds, 2);
|
---|
141 | }
|
---|
142 | else if (startTime > endTime)
|
---|
143 | {
|
---|
144 | // only startTime is set...
|
---|
145 | TimeSpan currentTimeNeeded = DateTime.Now - startTime;
|
---|
146 | EvaluationsPerSecond = Math.Round(evaluations / currentTimeNeeded.TotalSeconds, 2);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | private double bestQuality;
|
---|
152 |
|
---|
153 | public double BestQuality
|
---|
154 | {
|
---|
155 | get { return this.bestQuality; }
|
---|
156 | set
|
---|
157 | {
|
---|
158 | this.bestQuality = value;
|
---|
159 | this.OnPropertyChanged("BestQuality");
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | private string bestSolution;
|
---|
164 |
|
---|
165 | public string BestSolution
|
---|
166 | {
|
---|
167 | get { return this.bestSolution; }
|
---|
168 | set
|
---|
169 | {
|
---|
170 | this.bestSolution = value;
|
---|
171 | this.OnPropertyChanged("BestSolution");
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | private double bestKnownQuality;
|
---|
176 |
|
---|
177 | public double BestKnownQuality
|
---|
178 | {
|
---|
179 | get { return this.bestKnownQuality; }
|
---|
180 | set
|
---|
181 | {
|
---|
182 | this.bestKnownQuality = value;
|
---|
183 | this.OnPropertyChanged("BestKnownQuality");
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | private int bestSolutionFoundAt;
|
---|
188 |
|
---|
189 | public int BestSolutionFoundAt
|
---|
190 | {
|
---|
191 | get { return this.bestSolutionFoundAt; }
|
---|
192 | set
|
---|
193 | {
|
---|
194 | this.bestSolutionFoundAt = value;
|
---|
195 | this.OnPropertyChanged("BestSolutionFoundAt");
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | private double evaluationsPerSecond;
|
---|
200 |
|
---|
201 | public double EvaluationsPerSecond
|
---|
202 | {
|
---|
203 | get { return this.evaluationsPerSecond; }
|
---|
204 | set
|
---|
205 | {
|
---|
206 | this.evaluationsPerSecond = value;
|
---|
207 | this.OnPropertyChanged("EvaluationsPerSecond");
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | private DateTime startTime;
|
---|
212 |
|
---|
213 | public DateTime StartTime
|
---|
214 | {
|
---|
215 | get { return this.startTime; }
|
---|
216 | set
|
---|
217 | {
|
---|
218 | this.startTime = value;
|
---|
219 | this.OnPropertyChanged("StartTime");
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | private DateTime endTime;
|
---|
224 |
|
---|
225 | public DateTime EndTime
|
---|
226 | {
|
---|
227 | get { return this.endTime; }
|
---|
228 | set
|
---|
229 | {
|
---|
230 | this.endTime = value;
|
---|
231 | this.OnPropertyChanged("EndTime");
|
---|
232 | TotalTime = EndTime - StartTime;
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | private TimeSpan totalTime;
|
---|
237 |
|
---|
238 | public TimeSpan TotalTime
|
---|
239 | {
|
---|
240 | get { return this.totalTime; }
|
---|
241 | set
|
---|
242 | {
|
---|
243 | this.totalTime = value;
|
---|
244 | this.OnPropertyChanged("TotalTime");
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | private TimeSpan bestSolutionTime;
|
---|
249 |
|
---|
250 | public TimeSpan BestSolutionTime
|
---|
251 | {
|
---|
252 | get { return this.bestSolutionTime; }
|
---|
253 | set
|
---|
254 | {
|
---|
255 | this.bestSolutionTime = value;
|
---|
256 | this.OnPropertyChanged("BestSolutionTime");
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | public List<FoundSolution> FoundSolutions { get; set; }
|
---|
261 |
|
---|
262 | public string SvgFile { get; set; }
|
---|
263 |
|
---|
264 | private TreeInfos treeInfos;
|
---|
265 |
|
---|
266 | public TreeInfos TreeInfos
|
---|
267 | {
|
---|
268 | get { return this.treeInfos; }
|
---|
269 | set
|
---|
270 | {
|
---|
271 | this.treeInfos = value;
|
---|
272 | this.OnPropertyChanged("TreeInfos");
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | private RunState runState;
|
---|
277 |
|
---|
278 | public RunState RunState
|
---|
279 | {
|
---|
280 | get { return this.runState; }
|
---|
281 | set
|
---|
282 | {
|
---|
283 | this.runState = value;
|
---|
284 | this.OnPropertyChanged("RunState");
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | public override string ToString()
|
---|
289 | {
|
---|
290 | return string.Format("Run #{0}", this.RunNumber);
|
---|
291 | }
|
---|
292 |
|
---|
293 | #region INotifyPropertyChanged members
|
---|
294 |
|
---|
295 | public event PropertyChangedEventHandler PropertyChanged;
|
---|
296 |
|
---|
297 | protected void OnPropertyChanged(string propertyName)
|
---|
298 | {
|
---|
299 | if (PropertyChanged != null)
|
---|
300 | this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
---|
301 | }
|
---|
302 |
|
---|
303 | #endregion INotifyPropertyChanged members
|
---|
304 | }
|
---|
305 | }
|
---|