1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Drawing;
|
---|
26 |
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.Common.Resources;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
34 | [Item("Expert-System Optimizer", "Currently in experimental phase, an expert system that makes algorithm suggestions based on fitness landscape analysis features and an optimization knowledge base.")]
|
---|
35 | [StorableClass]
|
---|
36 | [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 118)]
|
---|
37 | public sealed class ExpertSystemOptimizer : ParameterizedNamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged {
|
---|
38 |
|
---|
39 | public string Filename { get; set; }
|
---|
40 |
|
---|
41 | public static new Image StaticItemImage {
|
---|
42 | get { return VSImageLibrary.Library; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [Storable]
|
---|
46 | private RunCollection runs;
|
---|
47 | public RunCollection Runs {
|
---|
48 | get { return runs; }
|
---|
49 | private set {
|
---|
50 | if (value == null) throw new ArgumentNullException("value");
|
---|
51 | if (runs == value) return;
|
---|
52 | runs = value;
|
---|
53 | OnPropertyChanged("Runs");
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | [Storable]
|
---|
58 | private ExecutionState executionState;
|
---|
59 | public ExecutionState ExecutionState {
|
---|
60 | get { return executionState; }
|
---|
61 | private set {
|
---|
62 | if (executionState != value) {
|
---|
63 | executionState = value;
|
---|
64 | OnPropertyChanged("ExecutionState");
|
---|
65 | OnExecutionStateChanged();
|
---|
66 | OnItemImageChanged();
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | [Storable]
|
---|
72 | private TimeSpan executionTime;
|
---|
73 | public TimeSpan ExecutionTime {
|
---|
74 | get { return executionTime; }
|
---|
75 | private set {
|
---|
76 | if (executionTime == value) return;
|
---|
77 | executionTime = value;
|
---|
78 | OnPropertyChanged("ExecutionTime");
|
---|
79 | OnExecutionTimeChanged();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | [Storable]
|
---|
84 | private RunCollection knowledgeBase;
|
---|
85 | public RunCollection KnowledgeBase {
|
---|
86 | get { return knowledgeBase; }
|
---|
87 | private set {
|
---|
88 | if (value == null) throw new ArgumentNullException("value");
|
---|
89 | if (knowledgeBase == value) return;
|
---|
90 | knowledgeBase = value;
|
---|
91 | OnPropertyChanged("KnowledgeBase");
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | [Storable]
|
---|
96 | private IProblem problem;
|
---|
97 | public IProblem Problem {
|
---|
98 | get { return problem; }
|
---|
99 | set {
|
---|
100 | if (problem == value) return;
|
---|
101 | problem = value;
|
---|
102 | OnPropertyChanged("Problem");
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | public IEnumerable<IOptimizer> NestedOptimizers {
|
---|
107 | get { yield break; }
|
---|
108 | }
|
---|
109 |
|
---|
110 | [StorableConstructor]
|
---|
111 | private ExpertSystemOptimizer(bool deserializing) : base(deserializing) { }
|
---|
112 | private ExpertSystemOptimizer(ExpertSystemOptimizer original, Cloner cloner)
|
---|
113 | : base(original, cloner) {
|
---|
114 | runs = cloner.Clone(original.runs);
|
---|
115 | executionState = original.executionState;
|
---|
116 | executionTime = original.executionTime;
|
---|
117 | knowledgeBase = cloner.Clone(original.knowledgeBase);
|
---|
118 | problem = cloner.Clone(original.problem);
|
---|
119 | }
|
---|
120 | public ExpertSystemOptimizer() {
|
---|
121 | Runs = new RunCollection();
|
---|
122 | ExecutionState = ExecutionState.Stopped;
|
---|
123 | ExecutionTime = TimeSpan.Zero;
|
---|
124 | }
|
---|
125 |
|
---|
126 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
127 | return new ExpertSystemOptimizer(this, cloner);
|
---|
128 | }
|
---|
129 |
|
---|
130 | public void Prepare() {
|
---|
131 | Prepare(false);
|
---|
132 | }
|
---|
133 |
|
---|
134 | public void Prepare(bool clearRuns) {
|
---|
135 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
|
---|
136 | throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
|
---|
137 | if (clearRuns) Runs.Clear();
|
---|
138 | ExecutionTime = TimeSpan.Zero;
|
---|
139 | ExecutionState = ExecutionState.Prepared;
|
---|
140 | OnPrepared();
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void Start() {
|
---|
144 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
|
---|
145 | throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
|
---|
146 | ExecutionState = ExecutionState.Started;
|
---|
147 | OnStarted();
|
---|
148 | }
|
---|
149 |
|
---|
150 | public void Pause() {
|
---|
151 | if (ExecutionState != ExecutionState.Started)
|
---|
152 | throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
|
---|
153 | ExecutionState = ExecutionState.Paused;
|
---|
154 | OnPaused();
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | public void Stop() {
|
---|
159 | if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
|
---|
160 | throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
|
---|
161 | ExecutionState = ExecutionState.Stopped;
|
---|
162 | OnStopped();
|
---|
163 | }
|
---|
164 |
|
---|
165 | public event EventHandler Prepared;
|
---|
166 | private void OnPrepared() {
|
---|
167 | var handler = Prepared;
|
---|
168 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
169 | }
|
---|
170 |
|
---|
171 | public event EventHandler Started;
|
---|
172 | private void OnStarted() {
|
---|
173 | var handler = Started;
|
---|
174 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
175 | }
|
---|
176 |
|
---|
177 | public event EventHandler Paused;
|
---|
178 | private void OnPaused() {
|
---|
179 | var handler = Paused;
|
---|
180 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
181 | }
|
---|
182 |
|
---|
183 | public event EventHandler Stopped;
|
---|
184 | private void OnStopped() {
|
---|
185 | var handler = Stopped;
|
---|
186 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
187 | }
|
---|
188 |
|
---|
189 | public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
|
---|
190 | private void OnExceptionOccurred(Exception e) {
|
---|
191 | var handler = ExceptionOccurred;
|
---|
192 | if (handler != null) handler(this, new EventArgs<Exception>(e));
|
---|
193 | }
|
---|
194 |
|
---|
195 | public event EventHandler ExecutionStateChanged;
|
---|
196 | private void OnExecutionStateChanged() {
|
---|
197 | var handler = ExecutionStateChanged;
|
---|
198 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
199 | }
|
---|
200 |
|
---|
201 | public event EventHandler ExecutionTimeChanged;
|
---|
202 | private void OnExecutionTimeChanged() {
|
---|
203 | var handler = ExecutionTimeChanged;
|
---|
204 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
205 | }
|
---|
206 |
|
---|
207 | public event PropertyChangedEventHandler PropertyChanged;
|
---|
208 | private void OnPropertyChanged(string propertyName) {
|
---|
209 | var handler = PropertyChanged;
|
---|
210 | if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|