Changeset 4119 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3
- Timestamp:
- 07/28/10 17:48:10 (14 years ago)
- Location:
- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HeuristicLab.Hive.Experiment-3.3.csproj
r4116 r4119 42 42 <PlatformTarget>AnyCPU</PlatformTarget> 43 43 <OutputPath>bin\Debug\</OutputPath> 44 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 44 45 </PropertyGroup> 45 46 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"> 46 47 <PlatformTarget>AnyCPU</PlatformTarget> 47 48 <OutputPath>bin\Release\</OutputPath> 49 </PropertyGroup> 50 <PropertyGroup> 51 <SignAssembly>true</SignAssembly> 52 </PropertyGroup> 53 <PropertyGroup> 54 <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile> 48 55 </PropertyGroup> 49 56 <ItemGroup> … … 89 96 </ItemGroup> 90 97 <ItemGroup> 98 <Compile Include="OptimizerJob.cs" /> 91 99 <Compile Include="HeuristicLabHiveExperimentPlugin.cs" /> 92 100 <Compile Include="HiveExperiment.cs" /> … … 102 110 <ItemGroup> 103 111 <None Include="app.config" /> 112 <None Include="HeuristicLab.snk" /> 104 113 <None Include="Properties\AssemblyInfo.frame" /> 105 114 <None Include="Properties\Settings.settings"> … … 112 121 <Project>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</Project> 113 122 <Name>HeuristicLab.Hive.Contracts-3.3</Name> 123 </ProjectReference> 124 <ProjectReference Include="..\..\HeuristicLab.Hive.JobBase\3.3\HeuristicLab.Hive.JobBase-3.3.csproj"> 125 <Project>{21187322-52DD-4243-80A4-A85F0263E63B}</Project> 126 <Name>HeuristicLab.Hive.JobBase-3.3</Name> 114 127 </ProjectReference> 115 128 </ItemGroup> -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
r4116 r4119 38 38 using System.Threading; 39 39 using HeuristicLab.Tracing; 40 using HeuristicLab.Hive.JobBase; 41 using System.Diagnostics; 42 using System.Collections; 40 43 41 44 namespace HeuristicLab.Hive.Experiment { … … 50 53 private const string itemDescription = "An experiment which contains multiple batch runs of algorithms which are executed in the Hive."; 51 54 private const int resultPollingIntervalMs = 10000; 55 52 56 private const int maxSnapshotRetries = 20; 53 57 54 private IDictionary<Guid, SerializedJob> jobs = null; 58 [Storable] 59 private IDictionary<Guid, IOptimizer> sentOptimizers = null; 60 55 61 private object locker = new object(); 56 62 private DateTime startTime; 63 64 [Storable] 57 65 private string serverUrl; 58 66 public string ServerUrl { … … 60 68 set { serverUrl = value; OnServerUrlChanged(); } 61 69 } 62 public event EventHandler ServerUrlChanged; 63 protected virtual void OnServerUrlChanged() { 64 EventHandler handler = ServerUrlChanged; 65 if (handler != null) handler(this, EventArgs.Empty); 66 } 67 70 71 [Storable] 68 72 private string resourceIds; 69 73 public string ResourceIds { … … 71 75 set { resourceIds = value; OnResourceIdsChanged(); } 72 76 } 73 public event EventHandler ResourceIdsChanged; 74 protected virtual void OnResourceIdsChanged() { 75 EventHandler handler = ResourceIdsChanged; 76 if (handler != null) handler(this, EventArgs.Empty); 77 78 [Storable] 79 private HeuristicLab.Optimization.Experiment experiment; 80 public HeuristicLab.Optimization.Experiment Experiment { 81 get { return experiment; } 82 set { experiment = value; OnExperimentChanged(); } 83 } 84 85 [StorableConstructor] 86 public HiveExperiment(bool deserializing) 87 : base(deserializing) { 88 } 89 90 public HiveExperiment() 91 : base(itemName, itemDescription) { 92 this.ServerUrl = HeuristicLab.Hive.Experiment.Properties.Settings.Default.HiveServerUrl; 93 this.ResourceIds = HeuristicLab.Hive.Experiment.Properties.Settings.Default.ResourceIds; 94 } 95 96 public override IDeepCloneable Clone(Cloner cloner) { 97 HiveExperiment clone = (HiveExperiment)base.Clone(cloner); 98 clone.resourceIds = this.resourceIds; 99 clone.serverUrl = this.serverUrl; 100 clone.experiment = (HeuristicLab.Optimization.Experiment)cloner.Clone(experiment); 101 clone.executionState = this.executionState; 102 clone.executionTime = this.executionTime; 103 clone.sentOptimizers = new Dictionary<Guid, IOptimizer>(); 104 foreach (var pair in this.sentOptimizers) 105 clone.sentOptimizers[pair.Key] = (IOptimizer)cloner.Clone(pair.Value); 106 return clone; 77 107 } 78 108 … … 86 116 } 87 117 } 88 89 private HeuristicLab.Optimization.Experiment experiment;90 public HeuristicLab.Optimization.Experiment Experiment {91 get { return experiment; }92 set { experiment = value; OnExperimentChanged(); }93 }94 public event EventHandler ExperimentChanged;95 protected virtual void OnExperimentChanged() {96 EventHandler handler = ExperimentChanged;97 if (handler != null) handler(this, EventArgs.Empty);98 }99 100 public HiveExperiment()101 : base(itemName, itemDescription) {102 this.ServerUrl = HeuristicLab.Hive.Experiment.Properties.Settings.Default.HiveServerUrl;103 this.ResourceIds = HeuristicLab.Hive.Experiment.Properties.Settings.Default.ResourceIds;104 }105 106 118 #region IExecutable Members 107 119 108 public event EventHandler<EventArgs<Exception>> ExceptionOccurred;109 120 [Storable] 121 private Core.ExecutionState executionState; 110 122 public ExecutionState ExecutionState { 111 get { return Core.ExecutionState.Stopped; } // [chn] todo 112 } 113 114 public event EventHandler ExecutionStateChanged; 115 123 get { return executionState; } 124 private set { 125 if (executionState != value) { 126 executionState = value; 127 OnExecutionStateChanged(); 128 } 129 } 130 } 131 132 [Storable] 133 private TimeSpan executionTime; 116 134 public TimeSpan ExecutionTime { 117 get { return new TimeSpan(); } // [chn] todo 118 } 119 120 public event EventHandler ExecutionTimeChanged; 135 get { return executionTime; } 136 private set { 137 executionTime = value; 138 OnExecutionTimeChanged(); 139 } 140 } 121 141 122 142 public void Pause() { … … 124 144 } 125 145 126 public event EventHandler Paused;127 128 146 public void Prepare() { 129 130 } 131 132 public event EventHandler Prepared; 147 // [chn] needed? 148 if (experiment != null) { 149 experiment.Prepare(); 150 OnPrepared(); 151 } 152 } 133 153 134 154 public void Start() { 155 this.startTime = DateTime.Now; 156 this.ExecutionState = Core.ExecutionState.Started; 135 157 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl); 136 158 137 IList<SerializedJob> serializedJobs = new List<SerializedJob>(); 159 sentOptimizers = new Dictionary<Guid, IOptimizer>(); 160 IEnumerable<string> groups = ResourceGroups; 161 138 162 foreach (IOptimizer optimizer in Experiment.Optimizers) { 139 serializedJobs.Add(CreateJob(optimizer)); 140 } 141 142 jobs = new Dictionary<Guid, SerializedJob>(); 143 144 IEnumerable<string> groups = ResourceGroups; 145 foreach (SerializedJob job in serializedJobs) { 146 ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(job, groups); 147 148 jobs.Add(response.Obj.Id, job); 163 SerializedJob serializedJob = CreateSerializedJob(optimizer); 164 ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(serializedJob, groups); 165 sentOptimizers.Add(response.Obj.Id, optimizer); 149 166 StartResultPollingThread(response.Obj); 150 167 } 151 168 } 152 153 public event EventHandler Started;154 169 155 170 public void Stop() { … … 157 172 } 158 173 159 public event EventHandler Stopped;160 174 private bool abortRequested; 161 175 162 176 #endregion 163 177 164 private SerializedJob CreateJob(IOptimizer optimizer) { 165 // serialize optimizer 178 private SerializedJob CreateSerializedJob(IOptimizer optimizer) { 179 IJob job = new OptimizerJob() { 180 Optimizer = optimizer 181 }; 182 183 // serialize job 166 184 MemoryStream memStream = new MemoryStream(); 167 XmlGenerator.Serialize(optimizer, memStream); 185 XmlGenerator.Serialize(job, memStream); 186 byte[] jobByteArray = memStream.ToArray(); 187 memStream.Dispose(); 168 188 169 189 // find out which which plugins are needed for the given object … … 172 192 select new HivePluginInfoDto() { 173 193 Name = p.Name, 174 Version = p.Version, 175 BuildDate = p.BuildDate, 194 Version = p.Version 176 195 }).ToList(); 177 196 … … 186 205 SerializedJob serializedJob = new SerializedJob() { 187 206 JobInfo = jobDto, 188 SerializedJobData = memStream.ToArray()207 SerializedJobData = jobByteArray 189 208 }; 190 memStream.Dispose();191 209 192 210 return serializedJob; … … 196 214 Thread t = new Thread(() => { 197 215 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl); 198 I OptimizerrestoredObject = null;216 IJob restoredObject = null; 199 217 200 218 do { … … 211 229 // 4. the result that we get from the server is a snapshot and not the final result 212 230 if (response.Success && response.Obj != null && response.StatusMessage != ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) { 213 231 214 232 // [chn] todo: deserialization into interface is not possible! how to find out correct static type? 215 restoredObject = XmlParser.Deserialize<I Optimizer>(new MemoryStream(response.Obj.SerializedJobData));233 restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(response.Obj.SerializedJobData)); 216 234 } 217 235 } 218 } while (restoredObject == null || restoredObject.ExecutionState == Core.ExecutionState.Stopped);236 } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped); 219 237 220 238 // job retrieved... replace the existing optimizers with the finished one 221 // todo 239 IOptimizer originalOptimizer = sentOptimizers[job.Id]; 240 IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer; 241 242 int originalOptimizerIndex = experiment.Optimizers.IndexOf(originalOptimizer); 243 experiment.Optimizers[originalOptimizerIndex] = restoredOptimizer; 244 sentOptimizers.Remove(job.Id); 245 246 if (sentOptimizers.Count == 0) { 247 // finished 248 this.ExecutionState = Core.ExecutionState.Stopped; 249 OnStopped(); 250 } 222 251 }); 223 252 224 253 Logger.Debug("HiveEngine: Starting results-polling thread"); 225 254 t.Start(); 226 255 } 256 227 257 228 258 #region Required Plugin Search … … 310 340 } 311 341 #endregion 342 343 #region Eventhandler 344 345 public event EventHandler ExecutionTimeChanged; 346 private void OnExecutionTimeChanged() { 347 EventHandler handler = ExecutionTimeChanged; 348 if (handler != null) handler(this, EventArgs.Empty); 349 } 350 351 public event EventHandler ExecutionStateChanged; 352 private void OnExecutionStateChanged() { 353 EventHandler handler = ExecutionStateChanged; 354 if (handler != null) handler(this, EventArgs.Empty); 355 } 356 357 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 358 359 public event EventHandler Started; 360 private void OnStarted() { 361 EventHandler handler = Started; 362 if (handler != null) handler(this, EventArgs.Empty); 363 } 364 365 public event EventHandler Stopped; 366 private void OnStopped() { 367 EventHandler handler = Stopped; 368 if (handler != null) handler(this, EventArgs.Empty); 369 } 370 371 public event EventHandler Paused; 372 private void OnPaused() { 373 EventHandler handler = Paused; 374 if (handler != null) handler(this, EventArgs.Empty); 375 } 376 377 public event EventHandler Prepared; 378 protected virtual void OnPrepared() { 379 EventHandler handler = Prepared; 380 if (handler != null) handler(this, EventArgs.Empty); 381 } 382 383 public event EventHandler ResourceIdsChanged; 384 protected virtual void OnResourceIdsChanged() { 385 EventHandler handler = ResourceIdsChanged; 386 if (handler != null) handler(this, EventArgs.Empty); 387 } 388 389 public event EventHandler ExperimentChanged; 390 protected virtual void OnExperimentChanged() { 391 EventHandler handler = ExperimentChanged; 392 if (handler != null) handler(this, EventArgs.Empty); 393 } 394 395 public event EventHandler ServerUrlChanged; 396 protected virtual void OnServerUrlChanged() { 397 EventHandler handler = ServerUrlChanged; 398 if (handler != null) handler(this, EventArgs.Empty); 399 } 400 401 402 #endregion 312 403 } 313 404 } -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/Properties/AssemblyInfo.cs
r4116 r4119 55 55 // You can specify all the values or you can default the Revision and Build Numbers 56 56 // by using the '*' as shown below: 57 [assembly: AssemblyVersion("3.3.0.411 1")]58 [assembly: AssemblyFileVersion("3.3.0.411 1")]59 [assembly: AssemblyBuildDate("2010/07/2 7 18:31:34")]57 [assembly: AssemblyVersion("3.3.0.4116")] 58 [assembly: AssemblyFileVersion("3.3.0.4116")] 59 [assembly: AssemblyBuildDate("2010/07/28 17:42:02")]
Note: See TracChangeset
for help on using the changeset viewer.