[1898] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure;
|
---|
| 27 | using System.Net;
|
---|
| 28 | using System.ServiceModel;
|
---|
| 29 | using System.ServiceModel.Description;
|
---|
| 30 | using System.Linq;
|
---|
| 31 | using HeuristicLab.CEDMA.Core;
|
---|
| 32 | using HeuristicLab.Data;
|
---|
| 33 | using HeuristicLab.Grid;
|
---|
| 34 | using System.Diagnostics;
|
---|
| 35 | using HeuristicLab.Core;
|
---|
| 36 | using System.Threading;
|
---|
[1922] | 37 | using HeuristicLab.Modeling;
|
---|
[2223] | 38 | using HeuristicLab.Modeling.Database;
|
---|
[1898] | 39 |
|
---|
| 40 | namespace HeuristicLab.CEDMA.Server {
|
---|
| 41 | public abstract class ExecuterBase : IExecuter {
|
---|
[2094] | 42 | internal event EventHandler Changed;
|
---|
| 43 |
|
---|
[1898] | 44 | private IDispatcher dispatcher;
|
---|
| 45 | protected IDispatcher Dispatcher {
|
---|
| 46 | get { return dispatcher; }
|
---|
[2238] | 47 | }
|
---|
[2223] | 48 | private IModelingDatabase databaseService;
|
---|
[1898] | 49 |
|
---|
| 50 | private int maxActiveJobs;
|
---|
| 51 | public int MaxActiveJobs {
|
---|
| 52 | get { return maxActiveJobs; }
|
---|
| 53 | set {
|
---|
| 54 | if (value < 0) throw new ArgumentException("Only positive values are allowed for MaxActiveJobs");
|
---|
| 55 | maxActiveJobs = value;
|
---|
[2094] | 56 | OnChanged();
|
---|
[1898] | 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[2290] | 60 | public int CalculatedJobs {
|
---|
| 61 | get;
|
---|
| 62 | set;
|
---|
| 63 | }
|
---|
| 64 | public int StoredJobs {
|
---|
| 65 | get;
|
---|
| 66 | set;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[2223] | 69 | public ExecuterBase(IDispatcher dispatcher, IModelingDatabase databaseService) {
|
---|
[2290] | 70 | CalculatedJobs = 0;
|
---|
[1898] | 71 | maxActiveJobs = 10;
|
---|
| 72 | this.dispatcher = dispatcher;
|
---|
[2223] | 73 | this.databaseService = databaseService;
|
---|
[2290] | 74 | StoredJobs = databaseService.GetAllModels().Count();
|
---|
[1898] | 75 | }
|
---|
| 76 |
|
---|
| 77 | public void Start() {
|
---|
| 78 | new Thread(StartJobs).Start();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | protected abstract void StartJobs();
|
---|
| 82 |
|
---|
[2057] | 83 | protected void SetResults(IScope src, IScope target) {
|
---|
[2223] | 84 | foreach (HeuristicLab.Core.IVariable v in src.Variables) {
|
---|
[2057] | 85 | target.AddVariable(v);
|
---|
| 86 | }
|
---|
| 87 | foreach (IScope subScope in src.SubScopes) {
|
---|
| 88 | target.AddSubScope(subScope);
|
---|
| 89 | }
|
---|
| 90 | foreach (KeyValuePair<string, string> alias in src.Aliases) {
|
---|
| 91 | target.AddAlias(alias.Key, alias.Value);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[2223] | 95 | protected void StoreResults(HeuristicLab.Modeling.IAlgorithm finishedAlgorithm) {
|
---|
[2290] | 96 | CalculatedJobs++;
|
---|
[2223] | 97 | databaseService.Persist(finishedAlgorithm);
|
---|
[2290] | 98 | StoredJobs++;
|
---|
| 99 | OnChanged();
|
---|
[1898] | 100 | }
|
---|
| 101 |
|
---|
| 102 | public abstract string[] GetJobs();
|
---|
[2088] | 103 |
|
---|
[2094] | 104 | protected internal void OnChanged() {
|
---|
| 105 | if (Changed != null) Changed(this, new EventArgs());
|
---|
| 106 | }
|
---|
[2088] | 107 |
|
---|
| 108 | #region IViewable Members
|
---|
| 109 |
|
---|
| 110 | public IView CreateView() {
|
---|
| 111 | return new ExecuterView(this);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | #endregion
|
---|
[1898] | 115 | }
|
---|
| 116 | }
|
---|