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