Changeset 1217 for branches/CEDMA-Refactoring-Ticket419
- Timestamp:
- 02/12/09 15:19:34 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server
- Files:
-
- 1 added
- 1 deleted
- 3 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/DispatcherBase.cs
r1216 r1217 37 37 38 38 namespace HeuristicLab.CEDMA.Server { 39 public class Dispatcher { 40 private List<Execution> dispatchQueue; 41 public IList<string> DispatchQueue { 42 get { return dispatchQueue.Select(t => "StandardGP").ToList(); } 39 public abstract class DispatcherBase :IDispatcher { 40 public enum ModelComplexity { Low, Medium, High }; 41 public enum Algorithm { StandardGP }; 42 43 private IStore store; 44 private ModelComplexity[] possibleComplexities = new ModelComplexity[] { ModelComplexity.Low, ModelComplexity.Medium, ModelComplexity.High }; 45 private Dictionary<LearningTask, Algorithm[]> possibleAlgorithms = new Dictionary<LearningTask, Algorithm[]>() { 46 {LearningTask.Classification, new Algorithm[] {}}, 47 {LearningTask.Regression, new Algorithm[] { Algorithm.StandardGP }}, 48 {LearningTask.TimeSeries, new Algorithm[] { }} 49 }; 50 51 public DispatcherBase(IStore store) { 52 this.store = store; 43 53 } 44 54 45 private IStore store; 46 47 public Dispatcher(IStore store) { 48 this.store = store; 49 this.dispatchQueue = new List<Execution>(); 50 } 51 52 private void FillDispatchQueue() { 55 public Execution GetNextJob() { 53 56 // find and select a dataset 54 57 var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet"); … … 57 60 }; 58 61 59 var dataSetBindings = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> ."); 62 Entity[] datasets = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> .") 63 .Select(x => (Entity)x.Get("DataSet")) 64 .ToArray(); 60 65 61 66 // no datasets => do nothing 62 if (data SetBindings.Count() == 0) return;67 if (datasets.Length == 0) return null; 63 68 64 // assume last dataset is the most interesting one 65 // find and select all results for this dataset 66 var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet"); 69 Entity dataSetEntity = SelectDataSet(datasets); 67 70 DataSet dataSet = new DataSet(store, dataSetEntity); 68 Random random = new Random(); 69 int targetVariable = dataSet.Problem.AllowedInputVariables[random.Next(0, dataSet.Problem.AllowedInputVariables.Count)]; 71 72 int targetVariable = SelectTargetVariable(dataSet, dataSet.Problem.AllowedInputVariables.ToArray()); 73 Algorithm selectedAlgorithm = SelectAlgorithm(dataSet, targetVariable, possibleAlgorithms[dataSet.Problem.LearningTask]); 70 74 string targetVariableName = dataSet.Problem.GetVariableName(targetVariable); 71 Execution exec = CreateExecution(dataSet.Problem, targetVariable); 75 ModelComplexity selectedComplexity = SelectComplexity(dataSet, targetVariable, selectedAlgorithm, possibleComplexities); 76 77 Execution exec = CreateExecution(dataSet.Problem, targetVariable, selectedAlgorithm, selectedComplexity); 72 78 if (exec != null) { 73 79 exec.DataSetEntity = dataSetEntity; 74 80 exec.TargetVariable = targetVariableName; 75 QueueJob(exec); 81 } 82 return exec; 83 } 84 85 public abstract Entity SelectDataSet(Entity[] datasets); 86 public abstract int SelectTargetVariable(DataSet dataSet, int[] targetVariables); 87 public abstract Algorithm SelectAlgorithm(DataSet dataSet, int targetVariable, Algorithm[] possibleAlgorithms); 88 public abstract ModelComplexity SelectComplexity(DataSet dataSet, int targetVariable, Algorithm algorithm, ModelComplexity[] possibleComplexities); 89 90 private Execution CreateExecution(Problem problem, int targetVariable, Algorithm algorithm, ModelComplexity complexity) { 91 switch (algorithm) { 92 case Algorithm.StandardGP: { 93 return CreateStandardGpExecution(problem, targetVariable, complexity); 94 } 95 default: { 96 return null; 97 } 76 98 } 77 99 } 78 100 79 private void QueueJob(Execution execution) { 80 dispatchQueue.Add(execution); 81 } 82 83 public Execution GetNextJob() { 84 if (dispatchQueue.Count == 0) { 85 FillDispatchQueue(); 86 } 87 if (dispatchQueue.Count > 0) { 88 Execution next = dispatchQueue[0]; 89 dispatchQueue.RemoveAt(0); 90 return next; 91 } else 92 return null; 93 } 94 95 internal void Start() { 96 FillDispatchQueue(); 97 } 98 99 private Execution CreateExecution(Problem problem, int targetVariable) { 100 switch (problem.LearningTask) { 101 case LearningTask.Classification: return null; 102 case LearningTask.Regression: { 103 return CreateStandardGpExecution(problem, targetVariable, 100, 10); 104 } 105 case LearningTask.TimeSeries: return null; 106 case LearningTask.Clustering: return null; 107 default: return null; 108 } 109 } 110 111 private Execution CreateStandardGpExecution(Problem problem, int targetVariable, int maxTreeSize, int maxTreeHeight) { 101 private Execution CreateStandardGpExecution(Problem problem, int targetVariable, ModelComplexity complexity) { 112 102 ProblemInjector probInjector = new ProblemInjector(problem); 113 103 probInjector.TargetVariable = targetVariable; … … 118 108 sgp.Elites = 1; 119 109 sgp.ProblemInjector = probInjector; 110 111 int maxTreeHeight = 10; 112 int maxTreeSize = 100; 113 switch (complexity) { 114 case ModelComplexity.Low: { 115 maxTreeHeight = 5; 116 maxTreeSize = 20; 117 break; 118 } 119 case ModelComplexity.Medium: { 120 maxTreeHeight = 10; 121 maxTreeSize = 100; 122 break; 123 } 124 case ModelComplexity.High: { 125 maxTreeHeight = 12; 126 maxTreeSize = 200; 127 break; 128 } 129 } 130 120 131 sgp.MaxTreeHeight = maxTreeHeight; 121 132 sgp.MaxTreeSize = maxTreeSize; 122 133 Execution exec = new Execution(sgp.Engine); 123 exec.Description = "StandardGP - Medium Complexity";134 exec.Description = "StandardGP - Complexity: " + complexity; 124 135 return exec; 125 136 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs
r1216 r1217 41 41 namespace HeuristicLab.CEDMA.Server { 42 42 public class Executer { 43 private Dispatcher dispatcher;43 private IDispatcher dispatcher; 44 44 private JobManager jobManager; 45 45 private IStore store; … … 63 63 } 64 64 65 public Executer( Dispatcher dispatcher, IStore store, string gridUrl) {65 public Executer(IDispatcher dispatcher, IStore store, string gridUrl) { 66 66 activeExecutions = new Dictionary<WaitHandle, Execution>(); 67 67 maxActiveJobs = 10; -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj
r1060 r1217 75 75 </ItemGroup> 76 76 <ItemGroup> 77 <Compile Include="DispatcherBase.cs" /> 78 <Compile Include="IDispatcher.cs" /> 77 79 <Compile Include="Execution.cs" /> 78 80 <Compile Include="Executer.cs" /> 79 <Compile Include=" Dispatcher.cs" />81 <Compile Include="RandomDispatcher.cs" /> 80 82 <Compile Include="Server.cs" /> 81 83 <Compile Include="ServerApplication.cs" /> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/RandomDispatcher.cs
r1216 r1217 37 37 38 38 namespace HeuristicLab.CEDMA.Server { 39 public class Dispatcher { 40 private List<Execution> dispatchQueue; 41 public IList<string> DispatchQueue { 42 get { return dispatchQueue.Select(t => "StandardGP").ToList(); } 39 public class RandomDispatcher : DispatcherBase { 40 private Random random; 41 public RandomDispatcher(IStore store) 42 : base(store) { 43 random = new Random(); 43 44 } 44 45 45 private IStore store; 46 47 public Dispatcher(IStore store) { 48 this.store = store; 49 this.dispatchQueue = new List<Execution>(); 46 public override Algorithm SelectAlgorithm(DataSet dataSet, int targetVariable, Algorithm[] possibleAlgorithms) { 47 return possibleAlgorithms[random.Next(possibleAlgorithms.Length)]; 50 48 } 51 49 52 private void FillDispatchQueue() { 53 // find and select a dataset 54 var dataSetVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("DataSet"); 55 var dataSetQuery = new Statement[] { 56 new Statement(dataSetVar, Ontology.PredicateInstanceOf, Ontology.TypeDataSet) 57 }; 58 59 var dataSetBindings = store.Query("?DataSet <" + Ontology.PredicateInstanceOf.Uri + "> <" + Ontology.TypeDataSet.Uri + "> ."); 60 61 // no datasets => do nothing 62 if (dataSetBindings.Count() == 0) return; 63 64 // assume last dataset is the most interesting one 65 // find and select all results for this dataset 66 var dataSetEntity = (Entity)dataSetBindings.Last().Get("DataSet"); 67 DataSet dataSet = new DataSet(store, dataSetEntity); 68 Random random = new Random(); 69 int targetVariable = dataSet.Problem.AllowedInputVariables[random.Next(0, dataSet.Problem.AllowedInputVariables.Count)]; 70 string targetVariableName = dataSet.Problem.GetVariableName(targetVariable); 71 Execution exec = CreateExecution(dataSet.Problem, targetVariable); 72 if (exec != null) { 73 exec.DataSetEntity = dataSetEntity; 74 exec.TargetVariable = targetVariableName; 75 QueueJob(exec); 76 } 50 public override ModelComplexity SelectComplexity(DataSet dataSet, int targetVariable, Algorithm algorithm, ModelComplexity[] possibleComplexities) { 51 return possibleComplexities[random.Next(possibleComplexities.Length)]; 77 52 } 78 53 79 p rivate void QueueJob(Execution execution) {80 dispatchQueue.Add(execution);54 public override Entity SelectDataSet(Entity[] datasets) { 55 return datasets[random.Next(datasets.Length)]; 81 56 } 82 57 83 public Execution GetNextJob() { 84 if (dispatchQueue.Count == 0) { 85 FillDispatchQueue(); 86 } 87 if (dispatchQueue.Count > 0) { 88 Execution next = dispatchQueue[0]; 89 dispatchQueue.RemoveAt(0); 90 return next; 91 } else 92 return null; 93 } 94 95 internal void Start() { 96 FillDispatchQueue(); 97 } 98 99 private Execution CreateExecution(Problem problem, int targetVariable) { 100 switch (problem.LearningTask) { 101 case LearningTask.Classification: return null; 102 case LearningTask.Regression: { 103 return CreateStandardGpExecution(problem, targetVariable, 100, 10); 104 } 105 case LearningTask.TimeSeries: return null; 106 case LearningTask.Clustering: return null; 107 default: return null; 108 } 109 } 110 111 private Execution CreateStandardGpExecution(Problem problem, int targetVariable, int maxTreeSize, int maxTreeHeight) { 112 ProblemInjector probInjector = new ProblemInjector(problem); 113 probInjector.TargetVariable = targetVariable; 114 StandardGP sgp = new StandardGP(); 115 sgp.SetSeedRandomly = true; 116 sgp.MaxGenerations = 2; 117 sgp.PopulationSize = 100; 118 sgp.Elites = 1; 119 sgp.ProblemInjector = probInjector; 120 sgp.MaxTreeHeight = maxTreeHeight; 121 sgp.MaxTreeSize = maxTreeSize; 122 Execution exec = new Execution(sgp.Engine); 123 exec.Description = "StandardGP - Medium Complexity"; 124 return exec; 58 public override int SelectTargetVariable(DataSet dataSet, int[] targetVariables) { 59 return targetVariables[random.Next(targetVariables.Length)]; 125 60 } 126 61 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/ServerForm.cs
r1216 r1217 44 44 private Server server; 45 45 private Store store; 46 private Dispatcher dispatcher;46 private IDispatcher dispatcher; 47 47 private Executer executer; 48 48 … … 63 63 64 64 private void connectButton_Click(object sender, EventArgs e) { 65 dispatcher = new Dispatcher(store); 66 dispatcher.Start(); 65 dispatcher = new RandomDispatcher(store); 67 66 executer = new Executer(dispatcher, store, gridAddress.Text); 68 67 executer.Start();
Note: See TracChangeset
for help on using the changeset viewer.