- Timestamp:
- 08/07/09 16:50:07 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.CEDMA.Server/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherBase.cs
r2223 r2258 38 38 public abstract class DispatcherBase : IDispatcher { 39 39 private IModelingDatabase database; 40 public IModelingDatabase Database { 41 get { 42 return database; 43 } 44 } 40 45 private List<int> allowedTargetVariables; 41 46 private Dictionary<int, List<int>> activeInputVariables; 42 47 private Problem problem; 48 public Problem Problem { 49 get { 50 return problem; 51 } 52 } 43 53 internal event EventHandler Changed; 44 54 private object locker = new object(); -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.Designer.cs
r2153 r2258 29 29 this.inputVariablesLabel = new System.Windows.Forms.Label(); 30 30 this.splitContainer = new System.Windows.Forms.SplitContainer(); 31 this.setAllButton = new System.Windows.Forms.Button(); 31 32 this.splitContainer.Panel1.SuspendLayout(); 32 33 this.splitContainer.Panel2.SuspendLayout(); … … 57 58 this.inputVariableList.Location = new System.Drawing.Point(2, 16); 58 59 this.inputVariableList.Name = "inputVariableList"; 59 this.inputVariableList.Size = new System.Drawing.Size(221, 4 54);60 this.inputVariableList.Size = new System.Drawing.Size(221, 439); 60 61 this.inputVariableList.TabIndex = 1; 61 62 this.inputVariableList.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputVariableList_ItemCheck); … … 92 93 // splitContainer.Panel2 93 94 // 95 this.splitContainer.Panel2.Controls.Add(this.setAllButton); 94 96 this.splitContainer.Panel2.Controls.Add(this.inputVariablesLabel); 95 97 this.splitContainer.Panel2.Controls.Add(this.inputVariableList); … … 98 100 this.splitContainer.SplitterWidth = 1; 99 101 this.splitContainer.TabIndex = 4; 102 // 103 // setAllButton 104 // 105 this.setAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 106 this.setAllButton.Location = new System.Drawing.Point(3, 456); 107 this.setAllButton.Name = "setAllButton"; 108 this.setAllButton.Size = new System.Drawing.Size(91, 23); 109 this.setAllButton.TabIndex = 4; 110 this.setAllButton.Text = "Use as default"; 111 this.setAllButton.UseVisualStyleBackColor = true; 112 this.setAllButton.Click += new System.EventHandler(this.setAllButton_Click); 100 113 // 101 114 // DispatcherView … … 122 135 private System.Windows.Forms.Label inputVariablesLabel; 123 136 private System.Windows.Forms.SplitContainer splitContainer; 137 private System.Windows.Forms.Button setAllButton; 124 138 } 125 139 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs
r2223 r2258 71 71 inputVariableList.Enabled = true; 72 72 } 73 74 private void setAllButton_Click(object sender, EventArgs e) { 75 foreach (string targetVar in dispatcher.TargetVariables) { 76 for (int i = 0; i < inputVariableList.Items.Count; i++) { 77 if (inputVariableList.GetItemChecked(i)) { 78 dispatcher.EnableInputVariable(targetVar, (string)inputVariableList.Items[i]); 79 } else { 80 dispatcher.DisableInputVariable(targetVar, (string)inputVariableList.Items[i]); 81 } 82 } 83 } 84 } 73 85 } 74 86 } -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2223 r2258 44 44 45 45 private TimeSpan StartJobInterval { 46 get { return TimeSpan.FromMilliseconds( 500); }46 get { return TimeSpan.FromMilliseconds(3000); } 47 47 } 48 48 … … 51 51 } 52 52 53 private TimeSpan WaitForNewJobsInterval { 54 get { return TimeSpan.FromSeconds(3); } 55 } 56 57 public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService) 53 public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService) 58 54 : base(dispatcher, databaseService) { 59 55 this.jobManager = new JobManager(server); … … 64 60 protected override void StartJobs() { 65 61 Dictionary<WaitHandle, AsyncGridResult> asyncResults = new Dictionary<WaitHandle, AsyncGridResult>(); 62 // inifinite loop: 63 // 1. try to dispatch one algo 64 // 2. when at least one run is dispatched try to get the result 65 // 3. sleep 66 66 while (true) { 67 67 try { 68 // start new jobs as long as there are less than MaxActiveJobs 69 while (asyncResults.Count < MaxActiveJobs) { 70 Thread.Sleep(StartJobInterval); 68 // if allowed then try to dispatch another run 69 if (asyncResults.Count < MaxActiveJobs) { 71 70 // get an execution from the dispatcher and execute in grid via job-manager 72 71 HeuristicLab.Modeling.IAlgorithm algorithm = Dispatcher.GetNextJob(); … … 85 84 } 86 85 } 86 // when there are active runs 87 87 if (asyncResults.Count > 0) { 88 88 WaitHandle[] whArr = asyncResults.Keys.ToArray(); 89 89 int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout); 90 // if the wait didn't timeout, a new result is ready 90 91 if (readyHandleIndex != WaitHandle.WaitTimeout) { 92 // request the finished run and clean up 91 93 WaitHandle readyHandle = whArr[readyHandleIndex]; 94 AsyncGridResult finishedResult = asyncResults[readyHandle]; 95 asyncResults.Remove(readyHandle); 92 96 HeuristicLab.Modeling.IAlgorithm finishedAlgorithm = null; 93 AsyncGridResult finishedResult = null;94 97 lock (activeAlgorithms) { 95 finishedResult = asyncResults[readyHandle];96 98 finishedAlgorithm = activeAlgorithms[finishedResult]; 97 99 activeAlgorithms.Remove(finishedResult); 98 asyncResults.Remove(readyHandle);99 100 } 100 101 OnChanged(); … … 105 106 } 106 107 catch (Exception badEx) { 107 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message +Environment.NewLine+badEx.StackTrace);108 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message + Environment.NewLine + badEx.StackTrace); 108 109 } 109 110 } 110 } else {111 Thread.Sleep(WaitForNewJobsInterval);112 111 } 112 // when there are no active runs then sleep until we try to start a new run (to prevent excessive looping) 113 Thread.Sleep(StartJobInterval); 113 114 } 114 115 115 catch (Exception ex) { 116 116 HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message + Environment.NewLine + ex.StackTrace); 117 117 } 118 } 118 } // end while(true) 119 119 } 120 120 -
trunk/sources/HeuristicLab.CEDMA.Server/3.3/SimpleDispatcher.cs
r2223 r2258 60 60 case LearningTask.Regression: { 61 61 var regressionAlgos = algos.Where(a => (a as IClassificationAlgorithm) == null && (a as ITimeSeriesAlgorithm) == null); 62 selectedAlgorithm = ChooseDeterministic(targetVariable, inputVariables, regressionAlgos) ?? ChooseStochastic(regressionAlgos);62 selectedAlgorithm = ChooseDeterministic(targetVariable, inputVariables, regressionAlgos); // ?? ChooseStochastic(regressionAlgos); 63 63 break; 64 64 } … … 99 99 100 100 private void PopulateFinishedRuns() { 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 //} 101 var dispatchedAlgos = from model in Database.GetAllModels() 102 select new { 103 TargetVariable = model.TargetVariable.Name, 104 Algorithm = model.Algorithm.Name, 105 Inputvariables = Database.GetInputVariableResults(model).Select(x => x.Variable.Name).Distinct() }; 106 foreach (var algo in dispatchedAlgos) { 107 AddDispatchedRun(algo.TargetVariable, algo.Inputvariables, algo.Algorithm); 108 } 147 109 } 148 110 … … 180 142 } 181 143 144 private void AddDispatchedRun(string targetVariable, IEnumerable<string> inputVariables, string algorithm) { 145 AddDispatchedRun( 146 Problem.Dataset.GetVariableIndex(targetVariable), 147 inputVariables.Select(x => Problem.Dataset.GetVariableIndex(x)).ToArray(), 148 algorithm); 149 } 150 182 151 private void AddDispatchedRun(int targetVariable, int[] inputVariables, string algoName) { 183 152 if (!finishedAndDispatchedRuns.ContainsKey(targetVariable)) {
Note: See TracChangeset
for help on using the changeset viewer.