Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/10 17:48:10 (14 years ago)
Author:
cneumuel
Message:

HiveExperiment is now able to send IOptimizers of an Experiment and receive the calculated result (#1115)

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  
    4242    <PlatformTarget>AnyCPU</PlatformTarget>
    4343    <OutputPath>bin\Debug\</OutputPath>
     44    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    4445  </PropertyGroup>
    4546  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    4647    <PlatformTarget>AnyCPU</PlatformTarget>
    4748    <OutputPath>bin\Release\</OutputPath>
     49  </PropertyGroup>
     50  <PropertyGroup>
     51    <SignAssembly>true</SignAssembly>
     52  </PropertyGroup>
     53  <PropertyGroup>
     54    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
    4855  </PropertyGroup>
    4956  <ItemGroup>
     
    8996  </ItemGroup>
    9097  <ItemGroup>
     98    <Compile Include="OptimizerJob.cs" />
    9199    <Compile Include="HeuristicLabHiveExperimentPlugin.cs" />
    92100    <Compile Include="HiveExperiment.cs" />
     
    102110  <ItemGroup>
    103111    <None Include="app.config" />
     112    <None Include="HeuristicLab.snk" />
    104113    <None Include="Properties\AssemblyInfo.frame" />
    105114    <None Include="Properties\Settings.settings">
     
    112121      <Project>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</Project>
    113122      <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>
    114127    </ProjectReference>
    115128  </ItemGroup>
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs

    r4116 r4119  
    3838using System.Threading;
    3939using HeuristicLab.Tracing;
     40using HeuristicLab.Hive.JobBase;
     41using System.Diagnostics;
     42using System.Collections;
    4043
    4144namespace HeuristicLab.Hive.Experiment {
     
    5053    private const string itemDescription = "An experiment which contains multiple batch runs of algorithms which are executed in the Hive.";
    5154    private const int resultPollingIntervalMs = 10000;
     55
    5256    private const int maxSnapshotRetries = 20;
    5357
    54     private IDictionary<Guid, SerializedJob> jobs = null;
     58    [Storable]
     59    private IDictionary<Guid, IOptimizer> sentOptimizers = null;
     60
    5561    private object locker = new object();
    56 
     62    private DateTime startTime;
     63
     64    [Storable]
    5765    private string serverUrl;
    5866    public string ServerUrl {
     
    6068      set { serverUrl = value; OnServerUrlChanged(); }
    6169    }
    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]
    6872    private string resourceIds;
    6973    public string ResourceIds {
     
    7175      set { resourceIds = value; OnResourceIdsChanged(); }
    7276    }
    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;
    77107    }
    78108
     
    86116      }
    87117    }
    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 
    106118    #region IExecutable Members
    107119
    108     public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
    109 
     120    [Storable]
     121    private Core.ExecutionState executionState;
    110122    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;
    116134    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    }
    121141
    122142    public void Pause() {
     
    124144    }
    125145
    126     public event EventHandler Paused;
    127 
    128146    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    }
    133153
    134154    public void Start() {
     155      this.startTime = DateTime.Now;
     156      this.ExecutionState = Core.ExecutionState.Started;
    135157      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl);
    136158
    137       IList<SerializedJob> serializedJobs = new List<SerializedJob>();
     159      sentOptimizers = new Dictionary<Guid, IOptimizer>();
     160      IEnumerable<string> groups = ResourceGroups;
     161
    138162      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);
    149166        StartResultPollingThread(response.Obj);
    150167      }
    151168    }
    152 
    153     public event EventHandler Started;
    154169
    155170    public void Stop() {
     
    157172    }
    158173
    159     public event EventHandler Stopped;
    160174    private bool abortRequested;
    161175
    162176    #endregion
    163177
    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
    166184      MemoryStream memStream = new MemoryStream();
    167       XmlGenerator.Serialize(optimizer, memStream);
     185      XmlGenerator.Serialize(job, memStream);
     186      byte[] jobByteArray = memStream.ToArray();
     187      memStream.Dispose();
    168188
    169189      // find out which which plugins are needed for the given object
     
    172192        select new HivePluginInfoDto() {
    173193          Name = p.Name,
    174           Version = p.Version,
    175           BuildDate = p.BuildDate,
     194          Version = p.Version
    176195        }).ToList();
    177196
     
    186205      SerializedJob serializedJob = new SerializedJob() {
    187206        JobInfo = jobDto,
    188         SerializedJobData = memStream.ToArray()
     207        SerializedJobData = jobByteArray
    189208      };
    190       memStream.Dispose();
    191209
    192210      return serializedJob;
     
    196214      Thread t = new Thread(() => {
    197215        IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl);
    198         IOptimizer restoredObject = null;
     216        IJob restoredObject = null;
    199217
    200218        do {
     
    211229            // 4. the result that we get from the server is a snapshot and not the final result
    212230            if (response.Success && response.Obj != null && response.StatusMessage != ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
    213              
     231
    214232              // [chn] todo: deserialization into interface is not possible! how to find out correct static type?
    215               restoredObject = XmlParser.Deserialize<IOptimizer>(new MemoryStream(response.Obj.SerializedJobData));
     233              restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(response.Obj.SerializedJobData));
    216234            }
    217235          }
    218         } while (restoredObject == null || restoredObject.ExecutionState == Core.ExecutionState.Stopped);
     236        } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped);
    219237
    220238        // 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        }
    222251      });
    223      
     252
    224253      Logger.Debug("HiveEngine: Starting results-polling thread");
    225254      t.Start();
    226255    }
     256
    227257
    228258    #region Required Plugin Search
     
    310340    }
    311341    #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
    312403  }
    313404}
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/Properties/AssemblyInfo.cs

    r4116 r4119  
    5555// You can specify all the values or you can default the Revision and Build Numbers
    5656// by using the '*' as shown below:
    57 [assembly: AssemblyVersion("3.3.0.4111")]
    58 [assembly: AssemblyFileVersion("3.3.0.4111")]
    59 [assembly: AssemblyBuildDate("2010/07/27 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.