Changeset 2223 for trunk/sources/HeuristicLab.CEDMA.Server
- Timestamp:
- 08/03/09 14:23:54 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.CEDMA.Server/3.3
- Files:
-
- 11 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r2222 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using System.Linq; … … 35 33 using HeuristicLab.Core; 36 34 using HeuristicLab.Modeling; 35 using HeuristicLab.Modeling.Database; 37 36 38 37 namespace HeuristicLab.CEDMA.Server { 39 38 public abstract class DispatcherBase : IDispatcher { 40 private IStore store; 41 private DataSet dataset; 39 private IModelingDatabase database; 42 40 private List<int> allowedTargetVariables; 43 41 private Dictionary<int, List<int>> activeInputVariables; 44 42 private Problem problem; 45 43 internal event EventHandler Changed; 46 44 private object locker = new object(); … … 48 46 public IEnumerable<string> TargetVariables { 49 47 get { 50 if ( dataset!= null) {51 return dataset.Problem.AllowedTargetVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));48 if (problem != null) { 49 return Enumerable.Range(0, problem.Dataset.Columns).Select(x => problem.Dataset.GetVariableName(x)); 52 50 } else return new string[0]; 53 51 } … … 56 54 public IEnumerable<string> InputVariables { 57 55 get { 58 if ( dataset!= null) {59 return dataset.Problem.AllowedInputVariables.Select(x => dataset.Problem.Dataset.GetVariableName(x));56 if (problem != null) { 57 return TargetVariables; 60 58 } else return new string[0]; 61 59 } 62 60 } 63 61 64 public DispatcherBase(I Store store) {65 this. store = store;62 public DispatcherBase(IModelingDatabase database, Problem problem) { 63 this.problem = problem; 66 64 allowedTargetVariables = new List<int>(); 67 65 activeInputVariables = new Dictionary<int, List<int>>(); 66 problem.Changed += (sender, args) => { 67 lock (locker) { 68 allowedTargetVariables.Clear(); 69 activeInputVariables.Clear(); 70 } 71 OnChanged(); 72 }; 73 this.database = database; 68 74 } 69 75 70 public IAlgorithm GetNextJob() { 71 if (dataset == null) { 72 var datasetEntities = store.Query("?DataSet <" + Ontology.InstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .", 0, 1) 73 .Select(x => (Entity)x.Get("DataSet")); 74 if (datasetEntities.Count() == 0) return null; 75 dataset = new DataSet(store, datasetEntities.ElementAt(0)); 76 foreach (int targetVar in dataset.Problem.AllowedTargetVariables) { 77 activeInputVariables.Add(targetVar, new List<int>()); 78 activeInputVariables[targetVar].AddRange(dataset.Problem.AllowedInputVariables); 79 } 80 OnChanged(); 81 } 76 public HeuristicLab.Modeling.IAlgorithm GetNextJob() { 82 77 if (allowedTargetVariables.Count > 0) { 83 78 int[] targetVariables, inputVariables; … … 92 87 } 93 88 94 IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, dataset.Problem);89 HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = SelectAndConfigureAlgorithm(targetVariable, inputVariables, problem); 95 90 96 91 return selectedAlgorithm; … … 102 97 return targetVariables[rand.Next(targetVariables.Length)]; 103 98 } 104 public abstract IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem);99 public abstract HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem); 105 100 106 101 #region IViewable Members … … 114 109 internal void EnableTargetVariable(string name) { 115 110 lock (locker) 116 allowedTargetVariables.Add( dataset.Problem.Dataset.GetVariableIndex(name));111 allowedTargetVariables.Add(problem.Dataset.GetVariableIndex(name)); 117 112 } 118 113 119 114 internal void DisableTargetVariable(string name) { 120 115 lock (locker) 121 allowedTargetVariables.Remove( dataset.Problem.Dataset.GetVariableIndex(name));116 allowedTargetVariables.Remove(problem.Dataset.GetVariableIndex(name)); 122 117 } 123 118 124 119 internal void EnableInputVariable(string target, string name) { 125 120 lock (locker) { 126 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 127 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 121 int targetIndex = problem.Dataset.GetVariableIndex(target); 122 int inputIndex = problem.Dataset.GetVariableIndex(name); 123 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 128 124 if (!activeInputVariables[targetIndex].Contains(inputIndex)) { 129 125 activeInputVariables[targetIndex].Add(inputIndex); … … 134 130 internal void DisableInputVariable(string target, string name) { 135 131 lock (locker) { 136 int targetIndex = dataset.Problem.Dataset.GetVariableIndex(target); 137 int inputIndex = dataset.Problem.Dataset.GetVariableIndex(name); 132 int targetIndex = problem.Dataset.GetVariableIndex(target); 133 int inputIndex = problem.Dataset.GetVariableIndex(name); 134 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 138 135 while (activeInputVariables[targetIndex].Remove(inputIndex)) { } 139 136 } … … 145 142 146 143 internal IEnumerable<string> GetInputVariables(string target) { 147 return activeInputVariables[dataset.Problem.Dataset.GetVariableIndex(target)] 148 .Select(i => dataset.Problem.Dataset.GetVariableName(i)); 144 int targetIndex = problem.Dataset.GetVariableIndex(target); 145 if (!activeInputVariables.ContainsKey(targetIndex)) activeInputVariables[targetIndex] = new List<int>(); 146 return activeInputVariables[targetIndex] 147 .Select(i => problem.Dataset.GetVariableName(i)); 149 148 } 150 149 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs
r2153 r2223 12 12 public partial class DispatcherView : ViewBase { 13 13 private DispatcherBase dispatcher; 14 public DispatcherView(DispatcherBase dispatcher) : base() { 14 public DispatcherView(DispatcherBase dispatcher) 15 : base() { 15 16 this.dispatcher = dispatcher; 16 17 InitializeComponent(); 17 18 UpdateControls(); 18 19 dispatcher.Changed += (sender, args) => UpdateControls(); 20 this.inputVariableList.CheckOnClick = true; 19 21 } 20 22 -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ExecuterBase.cs
r2222 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using System.Linq; … … 38 36 using System.Threading; 39 37 using HeuristicLab.Modeling; 38 using HeuristicLab.Modeling.Database; 40 39 41 40 namespace HeuristicLab.CEDMA.Server { … … 46 45 protected IDispatcher Dispatcher { 47 46 get { return dispatcher; } 48 } 49 private I Store store;47 } 48 private IModelingDatabase databaseService; 50 49 51 50 private int maxActiveJobs; … … 59 58 } 60 59 61 public ExecuterBase(IDispatcher dispatcher, I Store store) {60 public ExecuterBase(IDispatcher dispatcher, IModelingDatabase databaseService) { 62 61 maxActiveJobs = 10; 63 62 this.dispatcher = dispatcher; 64 this. store = store;63 this.databaseService = databaseService; 65 64 } 66 65 … … 72 71 73 72 protected void SetResults(IScope src, IScope target) { 74 foreach ( IVariable v in src.Variables) {73 foreach (HeuristicLab.Core.IVariable v in src.Variables) { 75 74 target.AddVariable(v); 76 75 } … … 83 82 } 84 83 85 protected void StoreResults(IAlgorithm finishedAlgorithm) { 86 Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid()); 87 IModel model = finishedAlgorithm.Model; 88 List<Statement> statements = new List<Statement>(); 89 statements.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel)); 90 statements.Add(new Statement(modelEntity, Ontology.TargetVariable, new Literal(model.TargetVariable))); 91 statements.Add(new Statement(modelEntity, Ontology.Name, new Literal(finishedAlgorithm.Name))); 84 protected void StoreResults(HeuristicLab.Modeling.IAlgorithm finishedAlgorithm) { 85 databaseService.Persist(finishedAlgorithm); 86 //Entity modelEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid()); 87 //IModel model = finishedAlgorithm.Model; 88 //List<Statement> statements = new List<Statement>(); 89 //statements.Add(new Statement(modelEntity, Ontology.InstanceOf, Ontology.TypeModel)); 90 //statements.Add(new Statement(modelEntity, Ontology.TargetVariable, new Literal(model.TargetVariable))); 91 //statements.Add(new Statement(modelEntity, Ontology.Name, new Literal(finishedAlgorithm.Name))); 92 92 93 statements.Add(new Statement(modelEntity, Ontology.TrainingMeanSquaredError, new Literal(model.TrainingMeanSquaredError)));94 statements.Add(new Statement(modelEntity, Ontology.ValidationMeanSquaredError, new Literal(model.ValidationMeanSquaredError)));95 statements.Add(new Statement(modelEntity, Ontology.TestMeanSquaredError, new Literal(model.TestMeanSquaredError)));96 statements.Add(new Statement(modelEntity, Ontology.TrainingCoefficientOfDetermination, new Literal(model.TrainingCoefficientOfDetermination)));97 statements.Add(new Statement(modelEntity, Ontology.ValidationCoefficientOfDetermination, new Literal(model.ValidationCoefficientOfDetermination)));98 statements.Add(new Statement(modelEntity, Ontology.TestCoefficientOfDetermination, new Literal(model.TestCoefficientOfDetermination)));99 statements.Add(new Statement(modelEntity, Ontology.TrainingVarianceAccountedFor, new Literal(model.TrainingVarianceAccountedFor)));100 statements.Add(new Statement(modelEntity, Ontology.ValidationVarianceAccountedFor, new Literal(model.ValidationVarianceAccountedFor)));101 statements.Add(new Statement(modelEntity, Ontology.TestVarianceAccountedFor, new Literal(model.TestVarianceAccountedFor)));102 statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, new Literal(model.TrainingMeanAbsolutePercentageError)));103 statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, new Literal(model.ValidationMeanAbsolutePercentageError)));104 statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageError, new Literal(model.TestMeanAbsolutePercentageError)));105 statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, new Literal(model.TrainingMeanAbsolutePercentageOfRangeError)));106 statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, new Literal(model.ValidationMeanAbsolutePercentageOfRangeError)));107 statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, new Literal(model.TestMeanAbsolutePercentageOfRangeError)));93 //statements.Add(new Statement(modelEntity, Ontology.TrainingMeanSquaredError, new Literal(model.TrainingMeanSquaredError))); 94 //statements.Add(new Statement(modelEntity, Ontology.ValidationMeanSquaredError, new Literal(model.ValidationMeanSquaredError))); 95 //statements.Add(new Statement(modelEntity, Ontology.TestMeanSquaredError, new Literal(model.TestMeanSquaredError))); 96 //statements.Add(new Statement(modelEntity, Ontology.TrainingCoefficientOfDetermination, new Literal(model.TrainingCoefficientOfDetermination))); 97 //statements.Add(new Statement(modelEntity, Ontology.ValidationCoefficientOfDetermination, new Literal(model.ValidationCoefficientOfDetermination))); 98 //statements.Add(new Statement(modelEntity, Ontology.TestCoefficientOfDetermination, new Literal(model.TestCoefficientOfDetermination))); 99 //statements.Add(new Statement(modelEntity, Ontology.TrainingVarianceAccountedFor, new Literal(model.TrainingVarianceAccountedFor))); 100 //statements.Add(new Statement(modelEntity, Ontology.ValidationVarianceAccountedFor, new Literal(model.ValidationVarianceAccountedFor))); 101 //statements.Add(new Statement(modelEntity, Ontology.TestVarianceAccountedFor, new Literal(model.TestVarianceAccountedFor))); 102 //statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageError, new Literal(model.TrainingMeanAbsolutePercentageError))); 103 //statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageError, new Literal(model.ValidationMeanAbsolutePercentageError))); 104 //statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageError, new Literal(model.TestMeanAbsolutePercentageError))); 105 //statements.Add(new Statement(modelEntity, Ontology.TrainingMeanAbsolutePercentageOfRangeError, new Literal(model.TrainingMeanAbsolutePercentageOfRangeError))); 106 //statements.Add(new Statement(modelEntity, Ontology.ValidationMeanAbsolutePercentageOfRangeError, new Literal(model.ValidationMeanAbsolutePercentageOfRangeError))); 107 //statements.Add(new Statement(modelEntity, Ontology.TestMeanAbsolutePercentageOfRangeError, new Literal(model.TestMeanAbsolutePercentageOfRangeError))); 108 108 109 for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) {110 try {111 string variableName = finishedAlgorithm.Dataset.GetVariableName(i);112 double qualImpact = model.GetVariableQualityImpact(variableName);113 double evalImpact = model.GetVariableEvaluationImpact(variableName);109 //for (int i = 0; i < finishedAlgorithm.Dataset.Columns; i++) { 110 // try { 111 // string variableName = finishedAlgorithm.Dataset.GetVariableName(i); 112 // double qualImpact = model.GetVariableQualityImpact(variableName); 113 // double evalImpact = model.GetVariableEvaluationImpact(variableName); 114 114 115 Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid());116 statements.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact));117 statements.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity));118 statements.Add(new Statement(inputVariableEntity, Ontology.EvaluationImpact, new Literal(evalImpact)));119 statements.Add(new Statement(inputVariableEntity, Ontology.QualityImpact, new Literal(qualImpact)));120 statements.Add(new Statement(inputVariableEntity, Ontology.Name, new Literal(variableName)));121 }122 catch (ArgumentException) {123 // ignore124 }125 }115 // Entity inputVariableEntity = new Entity(Ontology.CedmaNameSpace + Guid.NewGuid()); 116 // statements.Add(new Statement(inputVariableEntity, Ontology.InstanceOf, Ontology.TypeVariableImpact)); 117 // statements.Add(new Statement(modelEntity, Ontology.HasInputVariable, inputVariableEntity)); 118 // statements.Add(new Statement(inputVariableEntity, Ontology.EvaluationImpact, new Literal(evalImpact))); 119 // statements.Add(new Statement(inputVariableEntity, Ontology.QualityImpact, new Literal(qualImpact))); 120 // statements.Add(new Statement(inputVariableEntity, Ontology.Name, new Literal(variableName))); 121 // } 122 // catch (ArgumentException) { 123 // // ignore 124 // } 125 //} 126 126 127 byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data);128 statements.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel))));129 store.AddRange(statements);127 //byte[] serializedModel = PersistenceManager.SaveToGZip(model.Data); 128 //statements.Add(new Statement(modelEntity, Ontology.SerializedData, new Literal(Convert.ToBase64String(serializedModel)))); 129 //store.AddRange(statements); 130 130 } 131 131 -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2222 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using System.Linq; … … 38 36 using System.Threading; 39 37 using HeuristicLab.Modeling; 38 using HeuristicLab.Modeling.Database; 40 39 41 40 namespace HeuristicLab.CEDMA.Server { 42 41 public class GridExecuter : ExecuterBase { 43 42 private JobManager jobManager; 44 private Dictionary<AsyncGridResult, IAlgorithm> activeAlgorithms;43 private Dictionary<AsyncGridResult, HeuristicLab.Modeling.IAlgorithm> activeAlgorithms; 45 44 46 45 private TimeSpan StartJobInterval { … … 56 55 } 57 56 58 public GridExecuter(IDispatcher dispatcher, IStore store, IGridServer server)59 : base(dispatcher, store) {57 public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService) 58 : base(dispatcher, databaseService) { 60 59 this.jobManager = new JobManager(server); 61 activeAlgorithms = new Dictionary<AsyncGridResult, IAlgorithm>();60 activeAlgorithms = new Dictionary<AsyncGridResult, HeuristicLab.Modeling.IAlgorithm>(); 62 61 jobManager.Reset(); 63 62 } … … 71 70 Thread.Sleep(StartJobInterval); 72 71 // get an execution from the dispatcher and execute in grid via job-manager 73 IAlgorithm algorithm = Dispatcher.GetNextJob();72 HeuristicLab.Modeling.IAlgorithm algorithm = Dispatcher.GetNextJob(); 74 73 if (algorithm != null) { 75 74 AtomicOperation op = new AtomicOperation(algorithm.Engine.OperatorGraph.InitialOperator, algorithm.Engine.GlobalScope); … … 91 90 if (readyHandleIndex != WaitHandle.WaitTimeout) { 92 91 WaitHandle readyHandle = whArr[readyHandleIndex]; 93 IAlgorithm finishedAlgorithm = null;92 HeuristicLab.Modeling.IAlgorithm finishedAlgorithm = null; 94 93 AsyncGridResult finishedResult = null; 95 94 lock (activeAlgorithms) { … … 138 137 string[] retVal = new string[activeAlgorithms.Count]; 139 138 int i = 0; 140 foreach ( IAlgorithm a in activeAlgorithms.Values) {139 foreach (HeuristicLab.Modeling.IAlgorithm a in activeAlgorithms.Values) { 141 140 retVal[i++] = a.Name + " " + a.Dataset.GetVariableName(a.TargetVariable); 142 141 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLab.CEDMA.Server-3.3.csproj
r2094 r2223 91 91 </ItemGroup> 92 92 <ItemGroup> 93 <Compile Include="LearningTask.cs" /> 94 <Compile Include="Problem.cs" /> 95 <Compile Include="ProblemView.cs"> 96 <SubType>UserControl</SubType> 97 </Compile> 98 <Compile Include="ProblemView.Designer.cs"> 99 <DependentUpon>ProblemView.cs</DependentUpon> 100 </Compile> 93 101 <Compile Include="ExecuterView.cs"> 94 102 <SubType>UserControl</SubType> … … 125 133 <Name>HeuristicLab.CEDMA.Core-3.3</Name> 126 134 </ProjectReference> 127 <ProjectReference Include="..\..\HeuristicLab.CEDMA.DB.Interfaces\3.3\HeuristicLab.CEDMA.DB.Interfaces-3.3.csproj">128 <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>129 <Name>HeuristicLab.CEDMA.DB.Interfaces-3.3</Name>130 </ProjectReference>131 <ProjectReference Include="..\..\HeuristicLab.CEDMA.DB\3.3\HeuristicLab.CEDMA.DB-3.3.csproj">132 <Project>{B3D6D8D9-2B1F-47EC-9C73-77FAECF87310}</Project>133 <Name>HeuristicLab.CEDMA.DB-3.3</Name>134 </ProjectReference>135 135 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 136 136 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> … … 153 153 <Name>HeuristicLab.Grid-3.2</Name> 154 154 </ProjectReference> 155 <ProjectReference Include="..\..\HeuristicLab.Modeling.Database.SQLServerCompact\3.2\HeuristicLab.Modeling.Database.SQLServerCompact-3.2.csproj"> 156 <Project>{EC1AA756-D612-4FA6-AA52-25CF4F8E3836}</Project> 157 <Name>HeuristicLab.Modeling.Database.SQLServerCompact-3.2</Name> 158 </ProjectReference> 159 <ProjectReference Include="..\..\HeuristicLab.Modeling.Database\3.2\HeuristicLab.Modeling.Database-3.2.csproj"> 160 <Project>{E84E5717-79F8-498F-A5E0-A055C4EC086B}</Project> 161 <Name>HeuristicLab.Modeling.Database-3.2</Name> 162 </ProjectReference> 155 163 <ProjectReference Include="..\..\HeuristicLab.Modeling\3.2\HeuristicLab.Modeling-3.2.csproj"> 156 164 <Project>{80F7FADA-549D-4151-8856-79B620A50DBA}</Project> … … 171 179 </ItemGroup> 172 180 <ItemGroup> 181 <EmbeddedResource Include="ProblemView.resx"> 182 <DependentUpon>ProblemView.cs</DependentUpon> 183 </EmbeddedResource> 173 184 <EmbeddedResource Include="DispatcherView.resx"> 174 185 <DependentUpon>DispatcherView.cs</DependentUpon> -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/HeuristicLabCedmaServerPlugin.cs
r2058 r2223 28 28 [ClassInfo(Name = "HeuristicLab.CEDMA.Server-3.3")] 29 29 [PluginFile(Filename = "HeuristicLab.CEDMA.Server-3.3.dll", Filetype = PluginFileType.Assembly)] 30 [Dependency(Dependency = "HeuristicLab.CEDMA.DB.Interfaces-3.3")]31 [Dependency(Dependency = "HeuristicLab.CEDMA.DB-3.3")]32 30 [Dependency(Dependency = "HeuristicLab.Grid-3.2")] 33 31 [Dependency(Dependency = "HeuristicLab.Grid.HiveBridge-3.2")] … … 36 34 [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")] 37 35 [Dependency(Dependency = "HeuristicLab.Modeling-3.2")] 36 [Dependency(Dependency = "HeuristicLab.Modeling.Database-3.2")] 37 [Dependency(Dependency = "HeuristicLab.Modeling.Database.SQLServerCompact-3.2")] 38 38 [Dependency(Dependency = "HeuristicLab.Tracing-3.2")] 39 39 public class HeuristicLabCedmaServerPlugin : PluginBase { -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/Server.cs
r2094 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using HeuristicLab.Grid; 33 31 using HeuristicLab.Grid.HiveBridge; 34 32 using HeuristicLab.Core; 33 using HeuristicLab.Modeling.Database; 34 using HeuristicLab.Modeling.Database.SQLServerCompact; 35 35 36 36 namespace HeuristicLab.CEDMA.Server { 37 37 public class Server : IViewable { 38 private static readonly string rdfFile = AppDomain.CurrentDomain.BaseDirectory + "rdf_store.db3";39 private static readonly string rdfConnectionString = "sqlite:rdf:Data Source=\"" + rdfFile + "\"";38 private static readonly string sqlServerCompactFile = AppDomain.CurrentDomain.BaseDirectory + "HeuristicLab.Modeling.database.sdf"; 39 private static readonly string sqlServerCompactConnectionString = @"Data Source=" + sqlServerCompactFile; 40 40 41 private ServiceHost host; 42 private Store store; 43 41 private DatabaseService database; 44 42 private IDispatcher dispatcher; 45 43 public IDispatcher Dispatcher { get { return dispatcher; } } 46 44 private IExecuter executer; 47 45 public IExecuter Executer { get { return executer; } } 46 private Problem problem; 47 public Problem Problem { get { return problem; } } 48 48 49 49 private string gridServiceUrl; … … 53 53 } 54 54 55 private string cedmaServiceUrl;56 public string CedmaServiceUrl {57 get { return cedmaServiceUrl; }58 set { cedmaServiceUrl = value; }59 }60 61 55 public Server() { 62 IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName()); 63 // windows XP returns the external ip on index 0 while windows vista returns the external ip as one of the last entries 64 // also if IPv6 protocol is installed we want to find an entry that is IPv4 65 int index = 0; 66 if (System.Environment.OSVersion.Version.Major >= 6) { 67 for (index = addresses.Length - 1; index >= 0; index--) 68 if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) 69 break; 56 database = new DatabaseService(sqlServerCompactConnectionString); 57 problem = new Problem(); 58 try { 59 problem.Dataset = database.GetDataset(); 70 60 } 71 cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA"; 72 store = new Store(rdfConnectionString); 73 } 74 75 public void Start() { 76 host = new ServiceHost(store, new Uri(cedmaServiceUrl)); 77 ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior(); 78 throttlingBehavior.MaxConcurrentSessions = 20; 79 host.Description.Behaviors.Add(throttlingBehavior); 80 try { 81 NetTcpBinding binding = new NetTcpBinding(); 82 binding.SendTimeout = new TimeSpan(10, 0, 0); 83 binding.MaxReceivedMessageSize = int.MaxValue; 84 binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; 85 binding.ReaderQuotas.MaxArrayLength = int.MaxValue; 86 host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl); 87 host.Open(); 88 } 89 catch (CommunicationException ex) { 90 MessageBox.Show("An exception occurred: " + ex.Message); 91 host.Abort(); 61 catch (InvalidOperationException ex) { 92 62 } 93 63 } 94 64 95 65 internal void Connect(string serverUrl) { 96 dispatcher = new SimpleDispatcher( store);66 dispatcher = new SimpleDispatcher(database, problem); 97 67 IGridServer gridServer = null; 98 68 if (serverUrl.Contains("ExecutionEngine")) { … … 102 72 gridServer = new GridServerProxy(serverUrl); 103 73 } 104 executer = new GridExecuter(dispatcher, store, gridServer);74 executer = new GridExecuter(dispatcher, gridServer, database); 105 75 executer.Start(); 106 76 } … … 110 80 return new ServerView(this); 111 81 } 112 113 82 #endregion 114 83 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ServerApplication.cs
r2119 r2223 27 27 28 28 namespace HeuristicLab.CEDMA.Server { 29 [ClassInfo(Name = "CEDMA Server", Description = "Server to execute CEDMA agents.", AutoRestart=true)]29 [ClassInfo(Name = "CEDMA", Description = "Cooperative Evolutionary Data Mining.", AutoRestart=true)] 30 30 class ServerApplication : ApplicationBase { 31 31 public override void Run() { 32 32 Server server = new Server(); 33 server.Start();34 33 Form mainForm = new Form(); 35 34 UserControl serverControl = (UserControl)server.CreateView(); 36 35 serverControl.Dock = DockStyle.Fill; 37 36 mainForm.Controls.Add(serverControl); 38 mainForm.Name = "CEDMA Server";37 mainForm.Name = "CEDMA"; 39 38 Application.Run(mainForm); 40 39 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ServerView.cs
r2094 r2223 32 32 using HeuristicLab.PluginInfrastructure; 33 33 using System.Net; 34 using HeuristicLab.CEDMA.DB;35 using HeuristicLab.CEDMA.DB.Interfaces;36 34 using System.Data.Common; 37 35 using System.Threading; … … 47 45 this.server = server; 48 46 InitializeComponent(); 49 addressTextBox.Text = server.CedmaServiceUrl;50 47 } 51 48 … … 58 55 dispatcherControl.Dock = DockStyle.Fill; 59 56 dispatcherTabPage.Controls.Add(dispatcherControl); 57 UserControl problemControl = (UserControl)server.Problem.CreateView(); 58 problemControl.Dock = DockStyle.Fill; 59 problemPage.Controls.Add(problemControl); 60 60 connectButton.Enabled = false; 61 61 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/ServerView.designer.cs
r2094 r2223 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.addressTextBox = new System.Windows.Forms.TextBox();48 this.externalAddressLabel = new System.Windows.Forms.Label();49 47 this.gridAddressLabel = new System.Windows.Forms.Label(); 50 48 this.address = new System.Windows.Forms.TextBox(); … … 53 51 this.executerTabPage = new System.Windows.Forms.TabPage(); 54 52 this.dispatcherTabPage = new System.Windows.Forms.TabPage(); 53 this.problemPage = new System.Windows.Forms.TabPage(); 55 54 this.tabControl.SuspendLayout(); 56 55 this.SuspendLayout(); 57 //58 // addressTextBox59 //60 this.addressTextBox.Location = new System.Drawing.Point(106, 6);61 this.addressTextBox.Name = "addressTextBox";62 this.addressTextBox.ReadOnly = true;63 this.addressTextBox.Size = new System.Drawing.Size(229, 20);64 this.addressTextBox.TabIndex = 0;65 //66 // externalAddressLabel67 //68 this.externalAddressLabel.AutoSize = true;69 this.externalAddressLabel.Location = new System.Drawing.Point(12, 9);70 this.externalAddressLabel.Name = "externalAddressLabel";71 this.externalAddressLabel.Size = new System.Drawing.Size(48, 13);72 this.externalAddressLabel.TabIndex = 3;73 this.externalAddressLabel.Text = "&Address:";74 56 // 75 57 // gridAddressLabel … … 106 88 this.tabControl.Controls.Add(this.executerTabPage); 107 89 this.tabControl.Controls.Add(this.dispatcherTabPage); 90 this.tabControl.Controls.Add(this.problemPage); 108 91 this.tabControl.Location = new System.Drawing.Point(3, 58); 109 92 this.tabControl.Name = "tabControl"; … … 132 115 this.dispatcherTabPage.UseVisualStyleBackColor = true; 133 116 // 134 // ServerForm 117 // problemPage 118 // 119 this.problemPage.Location = new System.Drawing.Point(4, 22); 120 this.problemPage.Name = "problemPage"; 121 this.problemPage.Padding = new System.Windows.Forms.Padding(3); 122 this.problemPage.Size = new System.Drawing.Size(565, 517); 123 this.problemPage.TabIndex = 2; 124 this.problemPage.Text = "Problem"; 125 this.problemPage.UseVisualStyleBackColor = true; 126 // 127 // ServerView 135 128 // 136 129 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); … … 140 133 this.Controls.Add(this.gridAddressLabel); 141 134 this.Controls.Add(this.address); 142 this.Controls.Add(this.externalAddressLabel); 143 this.Controls.Add(this.addressTextBox); 144 this.Name = "ServerForm"; 135 this.Name = "ServerView"; 145 136 this.Size = new System.Drawing.Size(579, 604); 146 137 this.tabControl.ResumeLayout(false); … … 152 143 #endregion 153 144 154 private System.Windows.Forms.TextBox addressTextBox;155 private System.Windows.Forms.Label externalAddressLabel;156 145 private System.Windows.Forms.Label gridAddressLabel; 157 146 private System.Windows.Forms.TextBox address; … … 160 149 private System.Windows.Forms.TabPage executerTabPage; 161 150 private System.Windows.Forms.TabPage dispatcherTabPage; 151 private System.Windows.Forms.TabPage problemPage; 162 152 } 163 153 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs
r2222 r2223 27 27 using System.Net; 28 28 using System.ServiceModel; 29 using HeuristicLab.CEDMA.DB.Interfaces;30 using HeuristicLab.CEDMA.DB;31 29 using System.ServiceModel.Description; 32 30 using System.Linq; … … 35 33 using HeuristicLab.Core; 36 34 using HeuristicLab.Modeling; 35 using HeuristicLab.Modeling.Database; 37 36 38 37 namespace HeuristicLab.CEDMA.Server { … … 44 43 } 45 44 46 private Random random; 47 private IStore store; 45 private Random random; 48 46 private Dictionary<int, List<AlgorithmConfiguration>> finishedAndDispatchedRuns; 49 47 50 public SimpleDispatcher(IStore store) 51 : base(store) { 52 this.store = store; 48 public SimpleDispatcher(IModelingDatabase database, Problem problem) 49 : base(database, problem) { 53 50 random = new Random(); 54 51 finishedAndDispatchedRuns = new Dictionary<int, List<AlgorithmConfiguration>>(); … … 56 53 } 57 54 58 public override IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem) {55 public override HeuristicLab.Modeling.IAlgorithm SelectAndConfigureAlgorithm(int targetVariable, int[] inputVariables, Problem problem) { 59 56 DiscoveryService ds = new DiscoveryService(); 60 IAlgorithm[] algos = ds.GetInstances<IAlgorithm>();61 IAlgorithm selectedAlgorithm = null;57 HeuristicLab.Modeling.IAlgorithm[] algos = ds.GetInstances<HeuristicLab.Modeling.IAlgorithm>(); 58 HeuristicLab.Modeling.IAlgorithm selectedAlgorithm = null; 62 59 switch (problem.LearningTask) { 63 60 case LearningTask.Regression: { … … 86 83 } 87 84 88 private IAlgorithm ChooseDeterministic(int targetVariable, int[] inputVariables, IEnumerable<IAlgorithm> algos) {85 private HeuristicLab.Modeling.IAlgorithm ChooseDeterministic(int targetVariable, int[] inputVariables, IEnumerable<HeuristicLab.Modeling.IAlgorithm> algos) { 89 86 var deterministicAlgos = algos 90 87 .Where(a => (a as IStochasticAlgorithm) == null) … … 95 92 } 96 93 97 private IAlgorithm ChooseStochastic(IEnumerable<IAlgorithm> regressionAlgos) {94 private HeuristicLab.Modeling.IAlgorithm ChooseStochastic(IEnumerable<HeuristicLab.Modeling.IAlgorithm> regressionAlgos) { 98 95 var stochasticAlgos = regressionAlgos.Where(a => (a as IStochasticAlgorithm) != null); 99 96 if (stochasticAlgos.Count() == 0) return null; … … 102 99 103 100 private void PopulateFinishedRuns() { 104 Dictionary<Entity, Entity> processedModels = new Dictionary<Entity, Entity>();105 var datasetBindings = store106 .Query(107 "?Dataset <" + Ontology.InstanceOf + "> <" + Ontology.TypeDataSet + "> .", 0, 1)108 .Select(x => (Entity)x.Get("Dataset"));109 110 if (datasetBindings.Count() > 0) {111 var datasetEntity = datasetBindings.ElementAt(0);112 113 DataSet ds = new DataSet(store, datasetEntity);114 var result = store115 .Query(116 "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." + Environment.NewLine +117 "?Model <" + Ontology.Name + "> ?AlgoName .",118 0, 1000)119 .Select(x => new Resource[] { (Literal)x.Get("TargetVariable"), (Literal)x.Get("AlgoName"), (Entity)x.Get("Model") });120 121 foreach (Resource[] row in result) {122 Entity model = ((Entity)row[2]);123 if (!processedModels.ContainsKey(model)) {124 processedModels.Add(model, model);125 126 string targetVariable = (string)((Literal)row[0]).Value;127 string algoName = (string)((Literal)row[1]).Value;128 int targetVariableIndex = ds.Problem.Dataset.GetVariableIndex(targetVariable);129 130 var inputVariableLiterals = store131 .Query(132 "<" + model.Uri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." + Environment.NewLine +133 "?InputVariable <" + Ontology.Name + "> ?Name .",134 0, 1000)135 .Select(x => (Literal)x.Get("Name"))136 .Select(l => (string)l.Value)137 .Distinct();138 139 List<int> inputVariables = new List<int>();140 foreach (string variableName in inputVariableLiterals) {141 int variableIndex = ds.Problem.Dataset.GetVariableIndex(variableName);142 inputVariables.Add(variableIndex);143 }144 if (!AlgorithmFinishedOrDispatched(targetVariableIndex, inputVariables.ToArray(), algoName)) {145 AddDispatchedRun(targetVariableIndex, inputVariables.ToArray(), algoName);146 }147 }148 }149 }150 } 151 152 private void SetProblemParameters( IAlgorithm algo, Problem problem, int targetVariable, int[] inputVariables) {101 //Dictionary<Entity, Entity> processedModels = new Dictionary<Entity, Entity>(); 102 //var datasetBindings = store 103 // .Query( 104 // "?Dataset <" + Ontology.InstanceOf + "> <" + Ontology.TypeDataSet + "> .", 0, 1) 105 // .Select(x => (Entity)x.Get("Dataset")); 106 107 //if (datasetBindings.Count() > 0) { 108 // var datasetEntity = datasetBindings.ElementAt(0); 109 110 // DataSet ds = new DataSet(store, datasetEntity); 111 // var result = store 112 // .Query( 113 // "?Model <" + Ontology.TargetVariable + "> ?TargetVariable ." + Environment.NewLine + 114 // "?Model <" + Ontology.Name + "> ?AlgoName .", 115 // 0, 1000) 116 // .Select(x => new Resource[] { (Literal)x.Get("TargetVariable"), (Literal)x.Get("AlgoName"), (Entity)x.Get("Model") }); 117 118 // foreach (Resource[] row in result) { 119 // Entity model = ((Entity)row[2]); 120 // if (!processedModels.ContainsKey(model)) { 121 // processedModels.Add(model, model); 122 123 // string targetVariable = (string)((Literal)row[0]).Value; 124 // string algoName = (string)((Literal)row[1]).Value; 125 // int targetVariableIndex = ds.Problem.Dataset.GetVariableIndex(targetVariable); 126 127 // var inputVariableLiterals = store 128 // .Query( 129 // "<" + model.Uri + "> <" + Ontology.HasInputVariable + "> ?InputVariable ." + Environment.NewLine + 130 // "?InputVariable <" + Ontology.Name + "> ?Name .", 131 // 0, 1000) 132 // .Select(x => (Literal)x.Get("Name")) 133 // .Select(l => (string)l.Value) 134 // .Distinct(); 135 136 // List<int> inputVariables = new List<int>(); 137 // foreach (string variableName in inputVariableLiterals) { 138 // int variableIndex = ds.Problem.Dataset.GetVariableIndex(variableName); 139 // inputVariables.Add(variableIndex); 140 // } 141 // if (!AlgorithmFinishedOrDispatched(targetVariableIndex, inputVariables.ToArray(), algoName)) { 142 // AddDispatchedRun(targetVariableIndex, inputVariables.ToArray(), algoName); 143 // } 144 // } 145 // } 146 //} 147 } 148 149 private void SetProblemParameters(HeuristicLab.Modeling.IAlgorithm algo, Problem problem, int targetVariable, int[] inputVariables) { 153 150 algo.Dataset = problem.Dataset; 154 151 algo.TargetVariable = targetVariable;
Note: See TracChangeset
for help on using the changeset viewer.