Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/20 15:55:13 (4 years ago)
Author:
mkommend
Message:

#2521: Merged trunk changes into problem refactoring branch.

Location:
branches/2521_ProblemRefactoring
Files:
1 deleted
60 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring

  • branches/2521_ProblemRefactoring/HeuristicLab.Clients.Hive.Slave

  • branches/2521_ProblemRefactoring/HeuristicLab.Clients.Hive.Slave/3.3/Core.cs

    r17226 r17586  
    251251        TaskData taskData = wcfService.GetTaskData(taskId);
    252252        if (taskData == null) throw new TaskDataNotFoundException(taskId);
    253         task = wcfService.UpdateJobState(taskId, TaskState.Calculating, null);
     253        task = wcfService.UpdateTaskState(taskId, TaskState.Calculating, null);
    254254        if (task == null) throw new TaskNotFoundException(taskId);
    255255        taskManager.StartTaskAsync(task, taskData);
     
    268268      }
    269269      catch (OutOfCoresException) {
    270         wcfService.UpdateJobState(taskId, TaskState.Waiting, "No more cores available");
     270        wcfService.UpdateTaskState(taskId, TaskState.Waiting, "No more cores available");
    271271        throw;
    272272      }
    273273      catch (OutOfMemoryException) {
    274         wcfService.UpdateJobState(taskId, TaskState.Waiting, "No more memory available");
     274        wcfService.UpdateTaskState(taskId, TaskState.Waiting, "No more memory available");
    275275        throw;
    276276      }
    277277      catch (Exception e) {
    278278        SlaveStatusInfo.DecrementUsedCores(usedCores);
    279         wcfService.UpdateJobState(taskId, TaskState.Failed, e.ToString());
     279        wcfService.UpdateTaskState(taskId, TaskState.Failed, e.ToString());
    280280        throw;
    281281      }
     
    391391          wcfService.UpdateTaskData(task, taskData, configManager.GetClientInfo().Id, TaskState.Failed, exception.ToString());
    392392        } else {
    393           wcfService.UpdateJobState(task.Id, TaskState.Failed, exception.ToString());
     393          wcfService.UpdateTaskState(task.Id, TaskState.Failed, exception.ToString());
    394394        }
    395395        SlaveClientCom.Instance.LogMessage(exception.Message);
     
    408408      var slaveTask = e.Value;
    409409      var task = wcfService.GetTask(slaveTask.TaskId);
    410       wcfService.UpdateJobState(task.Id, TaskState.Aborted, null);
     410      wcfService.UpdateTaskState(task.Id, TaskState.Aborted, null);
    411411      SlaveStatusInfo.DecrementUsedCores(e.Value.CoresNeeded);
    412412    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Clients.Hive.Slave/3.3/WcfService.cs

    r17226 r17586  
    8282    }
    8383
    84     public Task UpdateJobState(Guid taskId, TaskState taskState, string exception) {
     84    public Task UpdateTaskState(Guid taskId, TaskState taskState, string exception) {
    8585      return CallHiveService(s => s.UpdateTaskState(taskId, taskState, ConfigManager.Instance.GetClientInfo().Id, null, exception));
    8686    }
  • branches/2521_ProblemRefactoring/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r17226 r17586  
    170170    }
    171171
     172
    172173    private void OnViewTypeChanged() {
    173       if (viewType != null) {
    174         if (!ViewCanShowContent(viewType, Content))
    175           throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".",
    176                                                             viewType, Content.GetType()));
    177         IContentView view = MainFormManager.CreateView(viewType);
    178         view.Locked = Locked;
    179         view.ReadOnly = ReadOnly;
    180         ActiveView = view; //necessary to allow the views to change the status of the viewhost
    181         view.Content = Content;
    182 
    183         UpdateActiveMenuItem();
    184       }
     174      if (viewType == null) return;
     175      if (!ViewCanShowContent(viewType, Content))
     176        throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", viewType, Content.GetType()));
     177
     178      IContentView view = MainFormManager.CreateView(viewType);
     179      view.Locked = Locked;
     180      view.ReadOnly = ReadOnly;
     181      ActiveView = view; //necessary to allow the views to change the status of the viewhost
     182      view.Content = Content;
     183
     184      UpdateActiveMenuItem();
     185
    185186    }
    186187
     
    188189      activeView.CaptionChanged += new EventHandler(activeView_CaptionChanged);
    189190      activeView.LockedChanged += new EventHandler(activeView_LockedChanged);
     191      activeView.ReadOnlyChanged += new EventHandler(activeView_ReadOnlyChanged);
    190192      activeView.Changed += new EventHandler(activeView_Changed);
    191193    }
     
    193195      activeView.CaptionChanged -= new EventHandler(activeView_CaptionChanged);
    194196      activeView.LockedChanged -= new EventHandler(activeView_LockedChanged);
     197      activeView.ReadOnlyChanged -= new EventHandler(activeView_ReadOnlyChanged);
    195198      activeView.Changed -= new EventHandler(activeView_Changed);
    196199    }
     
    202205      configurationLabel.Enabled = !activeView.Locked;
    203206    }
     207    private void activeView_ReadOnlyChanged(object sender, EventArgs e) {
     208      ReadOnly = activeView.ReadOnly;
     209    }
     210
    204211    private void activeView_Changed(object sender, EventArgs e) {
    205212      OnChanged();
     
    228235
    229236    #region forwarding of view events
    230     internal protected override void OnShown(ViewShownEventArgs e) {
     237    protected internal override void OnShown(ViewShownEventArgs e) {
    231238      base.OnShown(e);
    232239      View view = ActiveView as View;
     
    234241        view.OnShown(e);
    235242    }
    236     internal protected override void OnHidden(EventArgs e) {
     243    protected internal override void OnHidden(EventArgs e) {
    237244      base.OnHidden(e);
    238245      View view = ActiveView as View;
     
    240247        view.OnHidden(e);
    241248    }
    242     internal protected override void OnClosing(FormClosingEventArgs e) {
     249    protected internal override void OnClosing(FormClosingEventArgs e) {
    243250      base.OnClosing(e);
    244251      View view = ActiveView as View;
     
    246253        view.OnClosing(e);
    247254    }
    248     internal protected override void OnClosed(FormClosedEventArgs e) {
     255    protected internal override void OnClosed(FormClosedEventArgs e) {
    249256      base.OnClosed(e);
    250257      View view = ActiveView as View;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblemDefinition.cs

    r17226 r17586  
    2323
    2424namespace HeuristicLab.Optimization {
     25
     26  //TODO add non-generic for bwerths problem modifiers
     27  public interface IProblemDefinition {
     28    //IEncoding Encoding { get; }
     29  }
     30
    2531  [StorableType("747a3cea-b9ba-4322-a5c2-050cd7e16e2a")]
    26   public interface IProblemDefinition<TEncoding, TEncodedSolution>
     32  public interface IProblemDefinition<TEncoding, TEncodedSolution> : IProblemDefinition
    2733    where TEncoding : class, IEncoding<TEncodedSolution>
    2834    where TEncodedSolution : class, IEncodedSolution {
    2935    TEncoding Encoding { get; }
     36
    3037  }
    3138}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionEvaluator.cs

    r17226 r17586  
    1 using HEAL.Attic;
    2 #region License Information
     1#region License Information
    32/* HeuristicLab
    43 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    2019 */
    2120#endregion
    22 
     21using HEAL.Attic;
    2322
    2423namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionModel.cs

    r17226 r17586  
    1 using HEAL.Attic;
    2 #region License Information
     1#region License Information
    32/* HeuristicLab
    43 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    2120#endregion
    2221
     22using HEAL.Attic;
     23
    2324namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    2425  [StorableType("a411e2b5-f926-41a6-b55b-1aef862db2fb")]
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSolution.cs

    r17226 r17586  
    2222
    2323
     24
    2425namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    2526  [StorableType("dff1a450-e958-454f-bf8e-6b763fdcaff3")]
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r17226 r17586  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    2121
    2222using System.Linq;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2728using HeuristicLab.Optimization;
    28 using HEAL.Attic;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    4747    private const string TestNaNEvaluationsResultName = "Test NaN Evaluations";
    4848
     49    private const string ModelBoundsResultName = "Model Bounds";
     50
    4951    public new ISymbolicRegressionModel Model {
    5052      get { return (ISymbolicRegressionModel)base.Model; }
     
    9597      private set { ((IntValue)EstimationLimitsResultCollection[TestNaNEvaluationsResultName].Value).Value = value; }
    9698    }
     99
     100    public IntervalCollection ModelBoundsCollection {
     101      get {
     102        if (!ContainsKey(ModelBoundsResultName)) return null;
     103        return (IntervalCollection)this[ModelBoundsResultName].Value;
     104      }
     105      private set {
     106        if (ContainsKey(ModelBoundsResultName)) {
     107          this[ModelBoundsResultName].Value = value;
     108        } else {
     109          Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", value));
     110        }
     111
     112      }
     113    }
     114
     115
    97116
    98117    [StorableConstructor]
     
    118137      estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
    119138      Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
     139
     140      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
     141        Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection()));
     142
    120143      RecalculateResults();
    121144    }
     
    139162        CalculateResults();
    140163      }
     164
     165      if (!ContainsKey(ModelBoundsResultName)) {
     166        if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree)) {
     167          Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection()));
     168          CalculateResults();
     169        }
     170      }
    141171    }
    142172
     
    159189      TrainingNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TrainingIndices).Count(double.IsNaN);
    160190      TestNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TestIndices).Count(double.IsNaN);
     191
     192      //Check if the tree contains unknown symbols for the interval calculation
     193      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
     194        ModelBoundsCollection = CalculateModelIntervals(this);
     195    }
     196
     197    private static IntervalCollection CalculateModelIntervals(ISymbolicRegressionSolution solution) {
     198      var intervalEvaluation = new IntervalCollection();
     199      var interpreter = new IntervalInterpreter();
     200      var problemData = solution.ProblemData;
     201      var model = solution.Model;
     202      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
     203
     204      intervalEvaluation.AddInterval($"Target {problemData.TargetVariable}", new Interval(variableRanges[problemData.TargetVariable].LowerBound, variableRanges[problemData.TargetVariable].UpperBound));
     205      intervalEvaluation.AddInterval("Model", interpreter.GetSymbolicExpressionTreeInterval(model.SymbolicExpressionTree, variableRanges));
     206
     207      if (DerivativeCalculator.IsCompatible(model.SymbolicExpressionTree)) {
     208        foreach (var inputVariable in model.VariablesUsedForPrediction.OrderBy(v => v, new NaturalStringComparer())) {
     209          var derivedModel = DerivativeCalculator.Derive(model.SymbolicExpressionTree, inputVariable);
     210          var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derivedModel, variableRanges);
     211
     212          intervalEvaluation.AddInterval(" ∂f/∂" + inputVariable, new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound));
     213        }
     214      }
     215
     216      return intervalEvaluation;
    161217    }
    162218  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17457 r17586  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3636  public abstract partial class InteractiveSymbolicDataAnalysisSolutionSimplifierView : AsynchronousContentView {
    37     private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes;
    38     private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes;
    39     private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
     37    private readonly Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     38    private readonly Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     39    private readonly Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     40    private readonly Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4041
    4142    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
     
    4950    protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) {
    5051      InitializeComponent();
    51       foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    52       changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    53       nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    5452      this.Caption = "Interactive Solution Simplifier";
    5553      this.impactCalculator = impactCalculator;
     
    173171    protected override void OnContentChanged() {
    174172      base.OnContentChanged();
    175       foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     173      foldedNodes.Clear();
     174      changedNodes.Clear();
     175      nodeIntervals.Clear();
     176      nodeImpacts.Clear();
    176177      UpdateView();
    177178      viewHost.Content = this.Content;
     
    205206          foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    206207        }
    207 
    208         nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
     208       
     209        foreach (var pair in impactAndReplacementValues) {
     210          nodeImpacts[pair.Key] = pair.Value.Item1;
     211        }
     212
     213        if (IntervalInterpreter.IsCompatible(tree)) {
     214          var regressionProblemData = Content.ProblemData as IRegressionProblemData;
     215          if (regressionProblemData != null) {
     216            var interpreter = new IntervalInterpreter();
     217            var variableRanges = regressionProblemData.VariableRanges.GetReadonlyDictionary();
     218            IDictionary<ISymbolicExpressionTreeNode, Interval> intervals;
     219            interpreter.GetSymbolicExpressionTreeIntervals(tree, variableRanges, out intervals);
     220            foreach (var kvp in intervals) {
     221              nodeIntervals[kvp.Key] = kvp.Value;
     222            }
     223          }
     224        }
    209225      } finally {
    210226        progress.Finish();
     
    303319          }
    304320        }
    305         if (visualTree != null)
     321        if (visualTree != null) {
     322          if (nodeIntervals.ContainsKey(treeNode))
     323            visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{nodeIntervals[treeNode].LowerBound:G5} ... {nodeIntervals[treeNode].UpperBound:G5}]");
    306324          if (changedNodes.ContainsKey(treeNode)) {
    307325            visualTree.LineColor = Color.DodgerBlue;
     
    309327            visualTree.LineColor = Color.DarkOrange;
    310328          }
     329        }
    311330      }
    312331      treeChart.RepaintNodes();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r17226 r17586  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Globalization;
    2425using System.Linq;
    2526using System.Text;
     27using HEAL.Attic;
    2628using HeuristicLab.Common;
    2729using HeuristicLab.Core;
    2830using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HEAL.Attic;
    3031
    3132namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    32   /// <summary>
    33   /// Formats mathematical expressions in infix form. E.g. x1 * (3.0 * x2 + x3)
    34   /// </summary>
    35   [StorableType("6FE2C83D-A594-4ABF-B101-5AEAEA6D3E3D")]
    36   [Item("Infix Symbolic Expression Tree Formatter", "A string formatter that converts symbolic expression trees to infix expressions.")]
    37 
    38   public sealed class InfixExpressionFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    39 
    40 
    41     [StorableConstructor]
    42     private InfixExpressionFormatter(StorableConstructorFlag _) : base(_) { }
    43     private InfixExpressionFormatter(InfixExpressionFormatter original, Cloner cloner) : base(original, cloner) { }
    44     public InfixExpressionFormatter()
    45       : base() {
    46       Name = ItemName;
    47       Description = ItemDescription;
    48     }
    49     public override IDeepCloneable Clone(Cloner cloner) {
    50       return new InfixExpressionFormatter(this, cloner);
    51     }
    52 
    53     /// <summary>
    54     /// Produces an infix expression for a given expression tree.
    55     /// </summary>
    56     /// <param name="symbolicExpressionTree">The tree representation of the expression.</param>
    57     /// <param name="numberFormat">Number format that should be used for numeric parameters (e.g. NumberFormatInfo.InvariantInfo (default)).</param>
    58     /// <param name="formatString">The format string for numeric parameters (e.g. \"G4\" to limit to 4 digits, default is \"G\")</param>
    59     /// <returns>Infix expression</returns>
    60     public string Format(ISymbolicExpressionTree symbolicExpressionTree, NumberFormatInfo numberFormat, string formatString="G") {
    61       // skip root and start symbols
    62       StringBuilder strBuilder = new StringBuilder();
    63       FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), strBuilder, numberFormat, formatString);
    64       return strBuilder.ToString();
    65     }
    66 
    67     public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
    68       return Format(symbolicExpressionTree, NumberFormatInfo.InvariantInfo);
    69     }
    70 
    71     private static void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, NumberFormatInfo numberFormat, string formatString) {
     33  public static class BaseInfixExpressionFormatter {
     34    public static void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder,
     35                                          NumberFormatInfo numberFormat, string formatString, List<KeyValuePair<string, double>> constants = null) {
    7236      if (node.SubtreeCount > 1) {
    7337        var token = GetToken(node.Symbol);
     
    7741            token == "^") {
    7842          strBuilder.Append("(");
    79           FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString);
     43          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
    8044
    8145          foreach (var subtree in node.Subtrees.Skip(1)) {
    8246            strBuilder.Append(" ").Append(token).Append(" ");
    83             FormatRecursively(subtree, strBuilder, numberFormat, formatString);
    84           }
     47            FormatRecursively(subtree, strBuilder, numberFormat, formatString, constants);
     48          }
     49
    8550          strBuilder.Append(")");
    8651        } else {
    8752          // function with multiple arguments
    8853          strBuilder.Append(token).Append("(");
    89           FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString);
     54          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
    9055          foreach (var subtree in node.Subtrees.Skip(1)) {
    9156            strBuilder.Append(", ");
    92             FormatRecursively(subtree, strBuilder, numberFormat, formatString);
    93           }
     57            FormatRecursively(subtree, strBuilder, numberFormat, formatString, constants);
     58          }
     59
    9460          strBuilder.Append(")");
    9561        }
     
    9864        if (token == "-" || token == "NOT") {
    9965          strBuilder.Append("(").Append(token).Append("(");
    100           FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
     66          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, constants);
    10167          strBuilder.Append("))");
    10268        } else if (token == "/") {
    10369          strBuilder.Append("1/");
    104           FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
     70          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, constants);
    10571        } else if (token == "+" || token == "*") {
    106           FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
     72          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, constants);
    10773        } else {
    10874          // function with only one argument
    10975          strBuilder.Append(token).Append("(");
    110           FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString);
     76          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, constants);
    11177          strBuilder.Append(")");
    11278        }
     
    11783          if (!varNode.Weight.IsAlmost(1.0)) {
    11884            strBuilder.Append("(");
    119             strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
     85            if (constants != null) {
     86              strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", varNode.Weight);
     87            } else {
     88              strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
     89            }
    12090            strBuilder.Append("*");
    12191          }
     92
    12293          strBuilder.Append("LAG(");
    123           if (varNode.VariableName.Contains("'")) {
     94          if (varNode.VariableName.Contains("'"))
    12495            strBuilder.AppendFormat("\"{0}\"", varNode.VariableName);
    125           } else {
     96          else
    12697            strBuilder.AppendFormat("'{0}'", varNode.VariableName);
    127           }
     98
    12899          strBuilder.Append(", ")
    129             .AppendFormat(numberFormat, "{0}", varNode.Lag)
    130             .Append(")");
     100                    .AppendFormat(numberFormat, "{0}", varNode.Lag)
     101                    .Append(")");
    131102        } else if (node.Symbol is Variable) {
    132103          var varNode = node as VariableTreeNode;
    133104          if (!varNode.Weight.IsAlmost(1.0)) {
    134105            strBuilder.Append("(");
    135             strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
     106            if (constants != null) {
     107              string constantKey = $"c_{constants.Count}";
     108              strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", constantKey);
     109              constants.Add(new KeyValuePair<string, double>(constantKey, varNode.Weight));
     110            } else {
     111              strBuilder.Append(varNode.Weight.ToString(formatString, numberFormat));
     112            }
     113
    136114            strBuilder.Append("*");
    137115          }
    138           if (varNode.VariableName.Contains("'")) {
     116
     117          if (varNode.VariableName.Contains("'"))
    139118            strBuilder.AppendFormat("\"{0}\"", varNode.VariableName);
    140           } else {
     119          else
    141120            strBuilder.AppendFormat("'{0}'", varNode.VariableName);
    142           }
    143           if (!varNode.Weight.IsAlmost(1.0)) {
    144             strBuilder.Append(")");
    145           }
     121
     122          if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
    146123        } else if (node.Symbol is FactorVariable) {
    147124          var factorNode = node as FactorVariableTreeNode;
    148           if (factorNode.VariableName.Contains("'")) {
     125          if (factorNode.VariableName.Contains("'"))
    149126            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
    150           } else {
     127          else
    151128            strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
    152           }
     129
    153130          strBuilder.AppendFormat("[{0}]",
    154131            string.Join(", ", factorNode.Weights.Select(w => w.ToString(formatString, numberFormat))));
     
    157134          if (!factorNode.Weight.IsAlmost(1.0)) {
    158135            strBuilder.Append("(");
    159             strBuilder.Append(factorNode.Weight.ToString(formatString, numberFormat));
     136            if (constants != null) {
     137              strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", factorNode.Weight);
     138            } else {
     139              strBuilder.Append(factorNode.Weight.ToString(formatString, numberFormat));
     140            }
     141
    160142            strBuilder.Append("*");
    161143          }
    162           if (factorNode.VariableName.Contains("'")) {
     144
     145          if (factorNode.VariableName.Contains("'"))
    163146            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
    164           } else {
     147          else
    165148            strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
    166           }
     149
    167150          strBuilder.Append(" = ");
    168           if (factorNode.VariableValue.Contains("'")) {
     151          if (factorNode.VariableValue.Contains("'"))
    169152            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableValue);
    170           } else {
     153          else
    171154            strBuilder.AppendFormat("'{0}'", factorNode.VariableValue);
    172           }
    173 
    174           if (!factorNode.Weight.IsAlmost(1.0)) {
    175             strBuilder.Append(")");
    176           }
    177 
     155
     156          if (!factorNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
    178157        } else if (node.Symbol is Constant) {
    179158          var constNode = node as ConstantTreeNode;
    180           if (constNode.Value >= 0.0)
    181             strBuilder.Append(constNode.Value.ToString(formatString, numberFormat));
    182           else
    183             strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat)).Append(")"); // (-1
     159          if (constants != null) {
     160            string constantKey = $"c_{constants.Count}";
     161
     162            strBuilder.AppendFormat(CultureInfo.InvariantCulture, constantKey);
     163            constants.Add(new KeyValuePair<string, double>(constantKey, constNode.Value));
     164          } else {
     165            if (constNode.Value >= 0.0)
     166              strBuilder.Append(constNode.Value.ToString(formatString, numberFormat));
     167            else
     168              strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat))
     169                        .Append(")"); // (-1
     170          }
    184171        }
    185172      }
     
    193180    }
    194181  }
     182
     183  /// <summary>
     184  /// Formats mathematical expressions in infix form. E.g. x1 * (3.0 * x2 + x3)
     185  /// </summary>
     186  [StorableType("6FE2C83D-A594-4ABF-B101-5AEAEA6D3E3D")]
     187  [Item("Infix Symbolic Expression Tree Formatter",
     188    "A string formatter that converts symbolic expression trees to infix expressions.")]
     189  public sealed class InfixExpressionFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
     190    [StorableConstructor]
     191    private InfixExpressionFormatter(StorableConstructorFlag _) : base(_) { }
     192
     193    private InfixExpressionFormatter(InfixExpressionFormatter original, Cloner cloner) : base(original, cloner) { }
     194
     195    public InfixExpressionFormatter()
     196      : base() {
     197      Name = ItemName;
     198      Description = ItemDescription;
     199    }
     200
     201    public override IDeepCloneable Clone(Cloner cloner) {
     202      return new InfixExpressionFormatter(this, cloner);
     203    }
     204
     205    /// <summary>
     206    /// Produces an infix expression for a given expression tree.
     207    /// </summary>
     208    /// <param name="symbolicExpressionTree">The tree representation of the expression.</param>
     209    /// <param name="numberFormat">Number format that should be used for numeric parameters (e.g. NumberFormatInfo.InvariantInfo (default)).</param>
     210    /// <param name="formatString">The format string for numeric parameters (e.g. \"G4\" to limit to 4 digits, default is \"G\")</param>
     211    /// <returns>Infix expression</returns>
     212    public string Format(ISymbolicExpressionTree symbolicExpressionTree, NumberFormatInfo numberFormat,
     213                         string formatString = "G") {
     214      // skip root and start symbols
     215      StringBuilder strBuilder = new StringBuilder();
     216      BaseInfixExpressionFormatter.FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0),
     217        strBuilder, numberFormat, formatString);
     218      return strBuilder.ToString();
     219    }
     220
     221    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     222      return Format(symbolicExpressionTree, NumberFormatInfo.InvariantInfo);
     223    }
     224  }
     225
     226  [StorableType("54D917E8-134E-4066-9A60-2737C12D81DC")]
     227  [Item("Infix String Formater", "Formatter for symbolic expressions, which produces an infix expression " +
     228                                 "as well as a list of all coefficient values")]
     229  public sealed class InfixExpressionStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
     230    [StorableConstructor]
     231    private InfixExpressionStringFormatter(StorableConstructorFlag _) : base(_) { }
     232
     233    private InfixExpressionStringFormatter(InfixExpressionStringFormatter original, Cloner cloner) : base(original, cloner) { }
     234
     235    public InfixExpressionStringFormatter() : base() {
     236      Name = ItemName;
     237      Description = ItemDescription;
     238    }
     239
     240    public override IDeepCloneable Clone(Cloner cloner) {
     241      return new InfixExpressionStringFormatter(this, cloner);
     242    }
     243
     244    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     245      StringBuilder strBuilder = new StringBuilder();
     246      var constants = new List<KeyValuePair<string, double>>();
     247      BaseInfixExpressionFormatter.FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0),
     248        strBuilder, NumberFormatInfo.InvariantInfo, "G", constants);
     249      strBuilder.Append($"{Environment.NewLine}{Environment.NewLine}");
     250
     251      int maxDigits = GetDigits(constants.Count);
     252      int padding = constants.Max(x => x.Value.ToString("F12", CultureInfo.InvariantCulture).Length);
     253      foreach (var constant in constants) {
     254        int digits = GetDigits(Int32.Parse(constant.Key.Substring(2)));
     255        strBuilder.Append($"{constant.Key}{new String(' ', maxDigits - digits)} = " +
     256                          string.Format($"{{0,{padding}:F12}}", constant.Value, CultureInfo.InvariantCulture) +
     257                          Environment.NewLine);
     258      }
     259
     260      return strBuilder.ToString();
     261    }
     262
     263    private int GetDigits(int x) {
     264      if (x == 0) return 1;
     265      return (int)Math.Floor(Math.Log10(x) + 1);
     266    }
     267  }
    195268}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17226 r17586  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HEAL.Attic;
    3030using HeuristicLab.Parameters;
    3131
     
    8080    }
    8181
    82     public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) {
     82    public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IReadOnlyDictionary<string, Interval> variableRanges) {
    8383      lock (syncRoot) {
    8484        EvaluatedSolutions++;
     
    9797
    9898    public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree,
    99       IDictionary<string, Interval> variableRanges, out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {
     99      IReadOnlyDictionary<string, Interval> variableRanges, out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {
    100100      lock (syncRoot) {
    101101        EvaluatedSolutions++;
     
    124124
    125125
    126     private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) {
     126    private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IReadOnlyDictionary<string, Interval> variableRanges) {
    127127      if (variableRanges == null)
    128128        throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges));
     
    234234            break;
    235235          }
    236         case OpCodes.Power: {
    237             result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    238             for (int i = 1; i < currentInstr.nArguments; i++) {
    239               var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    240               result = Interval.Power(result, argumentInterval);
    241             }
    242             break;
    243           }
    244236        case OpCodes.Square: {
    245237            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     
    247239            break;
    248240          }
    249         case OpCodes.Root: {
    250             result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    251             for (int i = 1; i < currentInstr.nArguments; i++) {
    252               var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    253               result = Interval.Root(result, argumentInterval);
    254             }
    255             break;
    256           }
    257241        case OpCodes.SquareRoot: {
    258242            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    259243            result = Interval.SquareRoot(argumentInterval);
     244            break;
     245          }
     246        case OpCodes.Cube: {
     247            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     248            result = Interval.Cube(argumentInterval);
     249            break;
     250          }
     251        case OpCodes.CubeRoot: {
     252            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     253            result = Interval.CubicRoot(argumentInterval);
     254            break;
     255          }
     256        case OpCodes.Absolute: {
     257            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     258            result = Interval.Absolute(argumentInterval);
     259            break;
     260          }
     261        case OpCodes.AnalyticQuotient: {
     262            result = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     263            for (var i = 1; i < currentInstr.nArguments; i++) {
     264              var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     265              result = Interval.AnalyticalQuotient(result, argumentInterval);
     266            }
     267
    260268            break;
    261269          }
     
    274282        from n in tree.Root.GetSubtree(0).IterateNodesPrefix()
    275283        where
     284          !(n.Symbol is Problems.DataAnalysis.Symbolic.Variable) &&
     285          !(n.Symbol is Constant) &&
    276286          !(n.Symbol is StartSymbol) &&
    277287          !(n.Symbol is Addition) &&
     
    284294          !(n.Symbol is Logarithm) &&
    285295          !(n.Symbol is Exponential) &&
    286           !(n.Symbol is Power) &&
    287296          !(n.Symbol is Square) &&
    288           !(n.Symbol is Root) &&
    289297          !(n.Symbol is SquareRoot) &&
    290           !(n.Symbol is Problems.DataAnalysis.Symbolic.Variable) &&
    291           !(n.Symbol is Constant)
     298          !(n.Symbol is Cube) &&
     299          !(n.Symbol is CubeRoot) &&
     300          !(n.Symbol is Absolute) &&
     301          !(n.Symbol is AnalyticQuotient)
    292302        select n).Any();
    293303      return !containsUnknownSyumbol;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Views

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs

    r17226 r17586  
    3636namespace HeuristicLab.Problems.DataAnalysis.Views {
    3737  public partial class PartialDependencePlot : UserControl, IPartialDependencePlot {
    38     private ModifiableDataset sharedFixedVariables; // used for syncronising variable values between charts
     38    private ModifiableDataset sharedFixedVariables; // used for synchronizing variable values between charts
    3939    private ModifiableDataset internalDataset; // holds the x values for each point drawn
    4040
     
    351351
    352352    private void RecalculateTrainingLimits(bool initializeAxisRanges) {
    353       trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Where(x => !double.IsNaN(x)).Min()).Max();
    354       trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Where(x => !double.IsNaN(x)).Max()).Min();
     353      //Set min and max to the interval ranges
     354      trainingMin = solutions.Select(s => s.ProblemData.VariableRanges.GetInterval(freeVariable).LowerBound).Max();
     355      trainingMax = solutions.Select(s => s.ProblemData.VariableRanges.GetInterval(freeVariable).UpperBound).Min();
    355356
    356357      if (initializeAxisRanges) {
     
    438439      chart.Palette = ChartColorPalette.None;
    439440
    440       // Add confidence interval series before its coresponding series for correct z index
     441      // Add confidence interval series before its corresponding series for correct z index
    441442      foreach (var solution in solutions) {
    442443        Series ciSeries;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r17520 r17586  
    222222    <Compile Include="Interfaces\IDataPreprocessorStarter.cs" />
    223223    <Compile Include="Interfaces\IPartialDependencePlot.cs" />
     224    <Compile Include="IntervalCollectionView.cs">
     225      <SubType>UserControl</SubType>
     226    </Compile>
     227    <Compile Include="IntervalCollectionView.Designer.cs">
     228      <DependentUpon>IntervalCollectionView.cs</DependentUpon>
     229    </Compile>
    224230    <Compile Include="MenuItems\ChangeDataOfOptimizersMenuItem.cs" />
    225231    <Compile Include="MenuItems\ShrinkDataAnalysisRunsMenuItem.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17515 r17586  
    143143    <Compile Include="Implementation\ConstantModel.cs" />
    144144    <Compile Include="Implementation\DataAnalysisModel.cs" />
    145     <Compile Include="Implementation\Interval.cs" />
     145    <Compile Include="Implementation\Interval\Interval.cs" />
     146    <Compile Include="Implementation\Interval\IntervalCollection.cs" />
    146147    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    147148    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17226 r17586  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis {
     
    3434  public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData, IStorableContent {
    3535    protected const string TargetVariableParameterName = "TargetVariable";
     36    protected const string VariableRangesParameterName = "VariableRanges";
     37    protected const string IntervalConstraintsParameterName = "IntervalConstraints";
    3638    public string Filename { get; set; }
    3739
     
    9193      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
    9294      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     95      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
    9396      emptyProblemData = problemData;
    9497    }
     
    98101      get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
    99102    }
     103
     104    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
     105
     106    public IntervalCollection VariableRanges {
     107      get => VariableRangesParameter.Value;
     108    }
     109
     110
    100111    public string TargetVariable {
    101112      get { return TargetVariableParameter.Value.Value; }
     
    125136    [StorableHook(HookType.AfterDeserialization)]
    126137    private void AfterDeserialization() {
     138      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
     139        var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     140        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
     141      }
    127142      RegisterParameterEvents();
    128143    }
     
    152167      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    153168      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
     169      var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     170      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    154171      RegisterParameterEvents();
     172    }
     173
     174    private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
     175      IntervalCollection intervalCollection = new IntervalCollection();
     176      foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
     177        var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
     178        intervalCollection.AddInterval(variable, variableInterval);
     179      }
     180
     181      return intervalCollection;
    155182    }
    156183
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs

    r17226 r17586  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   [StorableType("f85ccf7a-7df5-431e-bc4d-be6f3c4c2338")]
    2827  /// <summary>
    2928  /// Interface for all data-analysis models (regression/classification/clustering).
    3029  /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks>
    3130  /// </summary>
     31  [StorableType("f85ccf7a-7df5-431e-bc4d-be6f3c4c2338")]
    3232  public interface IDataAnalysisModel : INamedItem {
    3333    IEnumerable<string> VariablesUsedForPrediction { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblem.cs

    r17520 r17586  
    3535  [StorableType("c2f6fcdd-ab62-4423-be75-01aa694df411")]
    3636  public interface IDataAnalysisProblem<T> : IDataAnalysisProblem
    37   where T : class, IDataAnalysisProblemData {
     37    where T : class, IDataAnalysisProblemData {
    3838    IValueParameter<T> ProblemDataParameter { get; }
    3939    new T ProblemData { get; set; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs

    r17226 r17586  
    2222using System;
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis {
     27  [StorableType("3283B3FB-8467-4B99-9B6E-23BF3D1B8505")]
    2628  public interface IDependencyCalculator {
    2729    double Maximum { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs

    r17226 r17586  
    2222
    2323using System;
     24using HEAL.Attic;
     25
    2426namespace HeuristicLab.Problems.DataAnalysis {
    2527  [Flags]
     28  [StorableType("8A28DDA1-4814-4B77-9457-0EE930BE9C73")]
    2629  public enum OnlineCalculatorError {
    2730    /// <summary>
     
    3841    InsufficientElementsAdded = 2
    3942  }
     43
     44  [StorableType("119C8242-3EE7-4C34-A7AC-68ABF76EB11B")]
    4045  public interface IOnlineCalculator {
    4146    OnlineCalculatorError ErrorState { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17515 r17586  
    2626  [StorableType("1ef22b8b-f3b4-494b-8cdd-f08e84e316e0")]
    2727  public interface IRegressionProblemData : ISupervisedDataAnalysisProblemData {
     28    IntervalCollection VariableRanges { get;}
     29
    2830    IEnumerable<double> TargetVariableValues { get; }
    2931    IEnumerable<double> TargetVariableTrainingValues { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/IOnlineTimeSeriesCalculator.cs

    r17226 r17586  
    2222
    2323using System.Collections.Generic;
     24using HEAL.Attic;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis {
     27  [StorableType("7461AC5D-9D9A-4DCD-B32F-602260E58FFC")]
    2628  public interface IOnlineTimeSeriesCalculator {
    2729    OnlineCalculatorError ErrorState { get; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive

  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess

  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimJobDao.cs

    r17226 r17586  
    4444    }
    4545
     46    public void UpdateExistingDimJobs() {
     47      DataContext.ExecuteCommand(UpdateExistingDimJobsQuery);
     48    }
     49
    4650    #region Compiled queries
    4751    private static readonly Func<DataContext, Guid, DimJob> GetByIdQuery =
     
    5155         select dimJob).SingleOrDefault());
    5256    #endregion
     57
     58    #region String queries
     59    private const string UpdateExistingDimJobsQuery = @"
     60UPDATE u
     61SET
     62  u.JobName = case when x.JobId is null then u.JobName else x.JobName end,
     63  u.TotalTasks = x.TotalTasks,
     64  u.CompletedTasks = x.CompletedTasks,
     65  u.DateCompleted =
     66    case when x.totaltasks = x.CompletedTasks
     67      then (case when x.JobId is null and x.DateCompleted is null then GETDATE() else x.DateCompleted end)
     68    else u.DateCompleted
     69  end,
     70  u.ProjectId = case when x.JobId is null then u.ProjectId else x.ProjectId end
     71FROM [statistics].dimjob u
     72JOIN (
     73  SELECT
     74    dj.JobId as DimJobId,
     75    j.JobId as JobId,
     76    j.Name as JobName,
     77    COUNT(*) as TotalTasks,
     78    SUM(
     79    CASE
     80    WHEN TaskState in ('Finished', 'Aborted', 'Failed') then 1
     81    ELSE 0
     82    END) as CompletedTasks,
     83    MAX(EndTime) as DateCompleted,
     84    dp.ProjectId as ProjectId
     85  from [statistics].DimJob dj
     86  join [statistics].FactTask ft on dj.JobId = ft.JobId
     87  left join Job j on j.JobId = dj.JobId
     88  left join [statistics].DimProject dp on j.ProjectId = dp.ProjectId
     89  where dj.DateCompleted is null and dp.DateExpired is null
     90  group by dj.JobId, j.JobId, j.Name, dp.ProjectId
     91) as x on u.JobId = x.DimJobId";
     92    #endregion
    5393  }
    5494}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobDao.cs

    r17226 r17586  
    3737    }
    3838
     39    public int DeleteByState(JobState state, int batchSize) {
     40      return DataContext.ExecuteCommand(DeleteTopNByStateQueryString, batchSize, Enum.GetName(typeof(JobState), state));
     41    }
     42
    3943    public IEnumerable<Job> GetByProjectId(Guid id) {
    4044      return GetByProjectIdQuery(DataContext, id);
     
    4347    public IEnumerable<Job> GetByProjectIds(IEnumerable<Guid> projectIds) {
    4448      string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x)));
    45       if(!string.IsNullOrWhiteSpace(paramProjectIds)) {
     49      if (!string.IsNullOrWhiteSpace(paramProjectIds)) {
    4650        string queryString = string.Format(GetByProjectIdsQueryString, paramProjectIds);
    4751        return DataContext.ExecuteQuery<Job>(queryString);
     
    5155
    5256    public IEnumerable<Job> GetByState(JobState state) {
    53       return GetByStateQuery(DataContext, state);
     57      return GetByStateQuery(DataContext, state.ToString());
    5458    }
    5559
    5660    public IEnumerable<Guid> GetJobIdsByState(JobState state) {
    57       return GetJobIdsByStateQuery(DataContext, state);
     61      return GetJobIdsByStateQuery(DataContext, state.ToString());
    5862    }
    5963
     
    7478         where job.ProjectId == projectId
    7579         select job));
    76     private static readonly Func<DataContext, JobState, IEnumerable<Job>> GetByStateQuery =
    77       CompiledQuery.Compile((DataContext db, JobState jobState) =>
     80    private static readonly Func<DataContext, string, IEnumerable<Job>> GetByStateQuery =
     81      CompiledQuery.Compile((DataContext db, string jobState) =>
    7882        (from job in db.GetTable<Job>()
    79          where job.State == jobState
     83         where job.State.ToString() == jobState
    8084         select job));
    81     private static readonly Func<DataContext, JobState, IEnumerable<Guid>> GetJobIdsByStateQuery =
    82       CompiledQuery.Compile((DataContext db, JobState jobState) =>
     85    private static readonly Func<DataContext, string, IEnumerable<Guid>> GetJobIdsByStateQuery =
     86      CompiledQuery.Compile((DataContext db, string jobState) =>
    8387        (from job in db.GetTable<Job>()
    84          where job.State == jobState
     88         where job.State.ToString() == jobState
    8589         select job.JobId));
    8690    private static readonly Func<DataContext, IEnumerable<Job>> GetJobsReadyForDeletionQuery =
     
    101105      WHERE JobState = {0}
    102106    ";
     107    private const string DeleteTopNByStateQueryString = @"
     108      DELETE TOP ({0})
     109      FROM [Job]
     110      WHERE JobState = {1}
     111    ";
    103112    private const string GetStatisticsPendingJobs = @"
    104113      SELECT DISTINCT j.*
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/StateLogDao.cs

    r17226 r17586  
    4040    }
    4141
     42    public int DeleteObsolete(int batchSize) {
     43      return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize);
     44    }
     45
    4246    #region Compiled queries
    4347    private static readonly Func<DataContext, Guid, StateLog> GetByIdQuery =
     
    5458         select stateLog).First(x => x.SlaveId != null));
    5559    #endregion
     60
     61    #region String queries
     62    private const string DeleteObsoleteQueryString = @"
     63delete top ({0}) s
     64from statelog s
     65  join task t on t.taskid = s.taskid
     66  join job j on j.jobid = t.jobid
     67where j.jobstate = 'deletionpending'
     68    ";
     69    #endregion
    5670  }
    5771}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs

    r17226 r17586  
    5050      //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated),
    5151      //we skip this step because it's wasted runtime
    52       return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, 
    53         slave.ResourceId, 
    54         Enum.GetName(typeof(TaskState), TaskState.Waiting), 
    55         slave.FreeCores, 
     52      return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString,
     53        slave.ResourceId,
     54        Enum.GetName(typeof(TaskState), TaskState.Waiting),
     55        slave.FreeCores,
    5656        slave.FreeMemory).ToList();
    5757    }
     
    6565    /// <returns></returns>
    6666    public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) {
    67     var query = from t in Table
    68                 where t.State == TaskState.Waiting
    69                     && t.IsParentTask
    70                     && t.Job.AssignedJobResources.All(x => resourceIds.ToList().Contains(x.ResourceId))
    71                     && t.FinishWhenChildJobsFinished == finished
    72                     && t.ChildJobs.Any()
    73                     && t.ChildJobs.All(x =>
    74                       x.State == TaskState.Finished
    75                       || x.State == TaskState.Aborted
    76                       || x.State == TaskState.Failed)
     67      var query = from t in Table
     68                  where t.State == TaskState.Waiting
     69                      && t.IsParentTask
     70                      && t.Job.AssignedJobResources.All(x => resourceIds.ToList().Contains(x.ResourceId))
     71                      && t.FinishWhenChildJobsFinished == finished
     72                      && t.ChildJobs.Any()
     73                      && t.ChildJobs.All(x =>
     74                        x.State == TaskState.Finished
     75                        || x.State == TaskState.Aborted
     76                        || x.State == TaskState.Failed)
    7777                  orderby t.Priority descending
    7878                  select t;
     
    8282    public void UpdateExecutionTime(Guid taskId, double executionTime) {
    8383      DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId);
     84    }
     85
     86    public int DeleteObsolete(int batchSize) {
     87      return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize);
    8488    }
    8589
     
    129133       WHERE TaskId = {2}
    130134    ";
     135
     136    private const string DeleteObsoleteQueryString = @"
     137delete top ({0}) t1
     138from task t1
     139  left join task t2 on t1.taskid = t2.parenttaskid
     140  join job j on j.jobid = t1.jobid
     141where j.jobstate = 'deletionpending' and t2.taskid is null
     142";
    131143    #endregion
    132144  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDataDao.cs

    r17226 r17586  
    3232    }
    3333
     34    public int DeleteObsolete(int batchSize) {
     35      return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize);
     36    }
     37
    3438    #region Compiled queries
    3539    private static readonly Func<DataContext, Guid, TaskData> GetByIdQuery =
     
    3943         select taskData).SingleOrDefault());
    4044    #endregion
     45
     46    #region String queries
     47    private const string DeleteObsoleteQueryString = @"
     48delete top ({0}) td
     49from taskdata td
     50  join task t on t.taskid = td.taskid
     51  join job j on j.jobid = t.jobid
     52where j.jobstate = 'deletionpending'
     53    ";
     54    #endregion
    4155  }
    4256}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs

    r17226 r17586  
    6464    #region Transaction management
    6565    void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false);
     66    void UseTransactionAndSubmit(Action call, bool repeatableRead = false, bool longRunning = false);
    6667    T UseTransaction<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false);
     68    T UseTransactionAndSubmit<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false);
    6769    #endregion
    6870
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs

    r17226 r17586  
    184184    #region Transaction management
    185185    public void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false) {
    186       UseTransaction<object>(() => {
    187         call();
    188         return null;
    189       });
     186      UseTransaction<object>(() => { call(); return null; }, repeatableRead, longRunning);
     187    }
     188
     189    public void UseTransactionAndSubmit(Action call, bool repeatableRead = false, bool longRunning = false) {
     190      UseTransaction(() => { call(); SubmitChanges(); }, repeatableRead, longRunning);
    190191    }
    191192
     
    211212    }
    212213
     214    public T UseTransactionAndSubmit<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false) {
     215      return UseTransaction(() => { var res = call(); SubmitChanges(); return res; }, repeatableRead, longRunning);
     216    }
     217
    213218    private static TransactionScope CreateTransaction(bool repeatableRead, bool longRunning) {
    214219      var options = new TransactionOptions {
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql

    r16723 r17586  
    141141INCLUDE ([TaskId],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[Command],[JobId])
    142142GO
    143 
    144 
    145 
    146 -- OBSOLETE - DO NOT PERFORM (start)
    147 /****** Object:  Trigger [dbo].[tr_JobDeleteCascade]    Script Date: 04/19/2011 16:31:53 ******/
    148 SET ANSI_NULLS ON
    149 GO
    150 SET QUOTED_IDENTIFIER ON
    151 GO
    152 -- =============================================
    153 -- Author:    cneumuel
    154 -- Create date: 19.04.2011
    155 -- Description: (1) Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics
    156 --        (2) Deletes all associated jobs. This cannot be done with cascading delete,
    157 --              because the job table defines a INSTEAD OF DELETE trigger itself, which
    158 --              is not compatible with cascading deletes.
    159 -- =============================================
    160 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS
    161 BEGIN
    162     DELETE Task FROM deleted, Task WHERE deleted.JobId = Task.JobId
    163     DELETE Job FROM deleted, Job WHERE deleted.JobId = Job.JobId
    164 END
    165 GO
    166 
    167 -- =============================================
    168 -- Author:    cneumuel
    169 -- Create date: 11.11.2010
    170 -- Description: Recursively deletes all child-jobs of a job when it is deleted. (Source: http://devio.wordpress.com/2008/05/23/recursive-delete-in-sql-server/)
    171 -- =============================================DeletedJobStatistics
    172 CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS
    173 BEGIN
    174     -- recursively delete jobs
    175     CREATE TABLE #Table(
    176         TaskId uniqueidentifier
    177     )
    178     INSERT INTO #Table (TaskId)
    179     SELECT TaskId FROM deleted
    180    
    181     DECLARE @c INT
    182     SET @c = 0
    183    
    184     WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN
    185         SELECT @c = COUNT(TaskId) FROM #Table
    186        
    187         INSERT INTO #Table (TaskId)
    188             SELECT Task.TaskId
    189             FROM Task
    190             LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId
    191             WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table)
    192                 AND #Table.TaskId IS NULL
    193     END
    194    
    195     DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId
    196     DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId
    197 END
    198 GO
    199 -- OBSOLETE (end)
    200 
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.JanitorService

  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive.JanitorService/3.3/JanitorService.cs

    r17226 r17586  
    2626  public partial class JanitorService : ServiceBase {
    2727    private HiveJanitor janitor;
    28     private Thread janitorCleanupThread;
    29     private Thread janitorGenerateStatisticsThread;
     28    private Thread janitorThread;
    3029
    3130    public JanitorService() {
     
    3635      janitor = new HiveJanitor();
    3736
    38       janitorCleanupThread = new Thread(janitor.RunCleanup) {
    39         IsBackground = true
    40       };
    41       janitorGenerateStatisticsThread = new Thread(janitor.RunGenerateStatistics) {
     37      janitorThread = new Thread(janitor.Run) {
    4238        IsBackground = true
    4339      };
    4440
    45       janitorCleanupThread.Start();
    46       janitorGenerateStatisticsThread.Start();
     41      janitorThread.Start();
    4742    }
    4843
    4944    protected override void OnStop() {
    5045      janitor.StopJanitor();
    51       janitorCleanupThread.Join();
    52       janitorGenerateStatisticsThread.Join();
     46      janitorThread.Join();
    5347    }
    5448  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r16723 r17586  
    173173      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    174174    </Compile>
     175    <Compile Include="Scheduler\TaskScheduler.cs" />
    175176    <Compile Include="ServiceContracts\IHiveService.cs" />
    176177    <Compile Include="ServiceFaults\PluginAlreadyExistsFault.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs

    r17226 r17586  
    2828  public class HiveJanitor {
    2929    private bool stop;
    30     private AutoResetEvent cleanupWaitHandle;
    31     private AutoResetEvent generateStatisticsWaitHandle;
     30    private AutoResetEvent runWaitHandle;
    3231
    3332    private IPersistenceManager PersistenceManager {
     
    4443    public HiveJanitor() {
    4544      stop = false;
    46       cleanupWaitHandle = new AutoResetEvent(false);
    47       generateStatisticsWaitHandle = new AutoResetEvent(false);
     45      runWaitHandle = new AutoResetEvent(false);
    4846    }
    4947
    5048    public void StopJanitor() {
    5149      stop = true;
    52       cleanupWaitHandle.Set();
    53       generateStatisticsWaitHandle.Set();
     50      runWaitHandle.Set();
     51    }
     52
     53    public void Run() {
     54      while (!stop) {
     55        RunCleanup();
     56        RunGenerateStatistics();
     57        runWaitHandle.WaitOne(Properties.Settings.Default.GenerateStatisticsInterval);
     58      }
     59      runWaitHandle.Close();
    5460    }
    5561
    5662    public void RunCleanup() {
    5763      var pm = PersistenceManager;
    58       while (!stop) {
    59         try {
    60           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup.");
    61           bool cleanup = false;
     64      try {
     65        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting cleanup.");
     66        bool cleanup = false;
    6267
    63           var lifecycleDao = pm.LifecycleDao;
    64           pm.UseTransaction(() => {
    65             var lifecycle = lifecycleDao.GetLastLifecycle();
    66             if (lifecycle == null
    67                 || DateTime.Now - lifecycle.LastCleanup > Properties.Settings.Default.CleanupInterval) {
    68               lifecycleDao.UpdateLifecycle();
    69               cleanup = true;
    70             }
    71             pm.SubmitChanges();
    72           }, true);
     68        var lifecycleDao = pm.LifecycleDao;
     69        pm.UseTransaction(() => {
     70          var lifecycle = lifecycleDao.GetLastLifecycle();
     71          if (lifecycle == null
     72              || DateTime.Now - lifecycle.LastCleanup > Properties.Settings.Default.CleanupInterval) {
     73            lifecycleDao.UpdateLifecycle();
     74            cleanup = true;
     75          }
     76          pm.SubmitChanges();
     77        }, true);
    7378
    74           if (cleanup) {
    75             EventManager.Cleanup();
    76           }
    77           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished.");
     79        if (cleanup) {
     80          EventManager.Cleanup();
    7881        }
    79         catch (Exception e) {
    80           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
    81         }
    82         cleanupWaitHandle.WaitOne(Properties.Settings.Default.CleanupInterval);
     82        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: cleanup finished.");
     83      } catch (Exception e) {
     84        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e.ToString()));
    8385      }
    84       cleanupWaitHandle.Close();
    8586    }
    8687
    8788    public void RunGenerateStatistics() {
    88       while (!stop) {
    89         try {
    90           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting generate statistics.");
    91           StatisticsGenerator.GenerateStatistics();
    92           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: generate statistics finished.");
    93         }
    94         catch (Exception e) {
    95           LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e));
    96         }
    97 
    98         generateStatisticsWaitHandle.WaitOne(Properties.Settings.Default.GenerateStatisticsInterval);
     89      try {
     90        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: starting generate statistics.");
     91        StatisticsGenerator.GenerateStatistics();
     92        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: generate statistics finished.");
     93      } catch (Exception e) {
     94        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log(string.Format("HiveJanitor: The following exception occured: {0}", e));
    9995      }
    100 
    101       generateStatisticsWaitHandle.Close();
    10296    }
    10397  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r17457 r17586  
    209209    }
    210210
     211    private bool IsAuthorizedForTask(DA.Task task, Guid? slaveId) {
     212      var lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault(x => x.State == DA.TaskState.Transferring);
     213      return lastStateLog == null || slaveId == null || lastStateLog.SlaveId == slaveId;
     214    }
     215
    211216    public DT.Task UpdateTaskState(Guid taskId, DT.TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
    212217      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave);
     
    217222        return pm.UseTransaction(() => {
    218223          var task = taskDao.GetById(taskId);
    219           UpdateTaskState(pm, task, taskState, slaveId, userId, exception);
    220           pm.SubmitChanges();
     224          if (IsAuthorizedForTask(task, slaveId)) {
     225            UpdateTaskState(pm, task, taskState, slaveId, userId, exception);
     226            pm.SubmitChanges();
     227          }
    221228          return task.ToDto();
    222229        });
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs

    r17226 r17586  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Data.Linq;
    2524using System.Linq;
    2625using HeuristicLab.Services.Access.DataAccess;
     
    3635
    3736    public void GenerateStatistics() {
    38       using (var pm = new PersistenceManager()) {
    39 
    40         pm.UseTransaction(() => {
    41           UpdateDimProjectTable(pm);
    42           pm.SubmitChanges();
     37      Console.WriteLine("started generate statistics");
     38
     39      using (var pm = new PersistenceManager(true)) {
     40        var sw = new System.Diagnostics.Stopwatch();
     41
     42        sw.Start();
     43        pm.UseTransactionAndSubmit(() => { UpdateDimProjectTable(pm); });
     44        sw.Stop();
     45        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateDimProjectTable: {sw.Elapsed}");
     46        Console.WriteLine($"UpdateDimProjectTable: {sw.Elapsed}");
     47        sw.Reset();
     48
     49        pm.UseTransactionAndSubmit(() => {
     50          sw.Start();
     51          UpdateDimUserTable(pm);
     52          sw.Stop();
     53          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateDimUserTable: {sw.Elapsed}");
     54          Console.WriteLine($"UpdateDimUserTable: {sw.Elapsed}");
     55          sw.Reset();
     56
     57          sw.Start();
     58          UpdateDimJobTable(pm);
     59          sw.Stop();
     60          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateDimJobTable: {sw.Elapsed}");
     61          Console.WriteLine($"UpdateDimJobTable: {sw.Elapsed}");
     62          sw.Reset();
     63
     64          sw.Start();
     65          UpdateDimClientsTable(pm);
     66          sw.Stop();
     67          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateDimClientsTable: {sw.Elapsed}");
     68          Console.WriteLine($"UpdateDimClientsTable: {sw.Elapsed}");
     69          sw.Reset();
    4370        });
    4471
    45         pm.UseTransaction(() => {
    46           UpdateDimUserTable(pm);
    47          
    48           UpdateDimJobTable(pm);
    49           UpdateDimClientsTable(pm);
    50           pm.SubmitChanges();
    51         });
    52 
    53         DimTime time = null;
    54         pm.UseTransaction(() => {
    55           time = UpdateDimTimeTable(pm);
    56           pm.SubmitChanges();
    57         });
    58 
    59         if (time != null) {
    60           pm.UseTransaction(() => {
    61             UpdateFactClientInfoTable(time, pm);
    62             pm.SubmitChanges();
    63             UpdateFactProjectInfoTable(time, pm);
    64             pm.SubmitChanges();
    65           });
    66 
    67           pm.UseTransaction(() => {
    68             try {
    69               UpdateFactTaskTable(pm);
    70               UpdateExistingDimJobs(pm);
    71               FlagJobsForDeletion(pm);
    72               pm.SubmitChanges();
    73             }
    74             catch (DuplicateKeyException e) {
    75               var logger = LogFactory.GetLogger(typeof(HiveStatisticsGenerator).Namespace);
    76               logger.Log(string.Format(
    77                 @"Propable change from summertime to wintertime, resulting in overlapping times.
    78                           On wintertime to summertime change, slave timeouts and a fact gap will occur.
    79                           Exception Details: {0}", e));
    80             }
    81           });
    82         }
     72        pm.UseTransactionAndSubmit(() => {
     73          sw.Start();
     74          var time = UpdateDimTimeTable(pm);
     75          sw.Stop();
     76          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateDimTimeTable: {sw.Elapsed}");
     77          Console.WriteLine($"UpdateDimTimeTable: {sw.Elapsed}");
     78          sw.Reset();
     79
     80          sw.Start();
     81          UpdateFactClientInfoTable(time, pm);
     82          sw.Stop();
     83          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateFactClientInfoTable: {sw.Elapsed}");
     84          Console.WriteLine($"UpdateFactClientInfoTable: {sw.Elapsed}");
     85          sw.Reset();
     86
     87          sw.Start();
     88          UpdateFactProjectInfoTable(time, pm);
     89          sw.Stop();
     90          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateFactProjectInfoTable: {sw.Elapsed}");
     91          Console.WriteLine($"UpdateFactProjectInfoTable: {sw.Elapsed}");
     92          sw.Reset();
     93
     94
     95          sw.Start();
     96          UpdateFactTaskTable(pm);
     97          sw.Stop();
     98          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateFactTaskTable: {sw.Elapsed}");
     99          Console.WriteLine($"UpdateFactTaskTable: {sw.Elapsed}");
     100          sw.Reset();
     101
     102          sw.Start();
     103          UpdateExistingDimJobs(pm);
     104          sw.Stop();
     105          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"UpdateExistingDimJobs: {sw.Elapsed}");
     106          Console.WriteLine($"UpdateExistingDimJobs: {sw.Elapsed}");
     107          sw.Reset();
     108
     109          sw.Start();
     110          FlagJobsForDeletion(pm);
     111          sw.Stop();
     112          LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"FlagJobsForDeletion: {sw.Elapsed}");
     113          Console.WriteLine($"FlagJobsForDeletion: {sw.Elapsed}");
     114          sw.Reset();
     115        }, longRunning: true);
    83116      }
    84117    }
     
    207240
    208241    private void UpdateExistingDimJobs(PersistenceManager pm) {
    209       var dimProjectDao = pm.DimProjectDao;
    210       var jobDao = pm.JobDao;
    211242      var dimJobDao = pm.DimJobDao;
    212       var factTaskDao = pm.FactTaskDao;
    213       foreach (var dimJob in dimJobDao.GetNotCompletedJobs()) {
    214         var taskStates = factTaskDao.GetByJobId(dimJob.JobId)
    215             .GroupBy(x => x.TaskState)
    216             .Select(x => new {
    217               State = x.Key,
    218               Count = x.Count()
    219             }).ToList();
    220         int totalTasks = 0, completedTasks = 0;
    221         foreach (var state in taskStates) {
    222           totalTasks += state.Count;
    223           if (CompletedStates.Contains(state.State)) {
    224             completedTasks += state.Count;
    225           }
    226         }
    227         var job = jobDao.GetById(dimJob.JobId);
    228         if (totalTasks == completedTasks) {
    229           var completeDate = factTaskDao.GetLastCompletedTaskFromJob(dimJob.JobId);
    230           if (completeDate == null) {
    231             if (job == null) {
    232               completeDate = DateTime.Now;
    233             }
    234           }
    235           dimJob.DateCompleted = completeDate;
    236         }
    237         if(job != null) {
    238           dimJob.JobName = job.Name;
    239           dimJob.ProjectId = dimProjectDao.GetLastValidIdByProjectId(job.ProjectId);
    240         }
    241 
    242         dimJob.TotalTasks = totalTasks;
    243         dimJob.CompletedTasks = completedTasks;
    244       }
     243      dimJobDao.UpdateExistingDimJobs();
    245244    }
    246245
     
    248247      var jobDao = pm.JobDao;
    249248      var jobs = jobDao.GetJobsReadyForDeletion();
    250       foreach(var job in jobs) {
     249      foreach (var job in jobs) {
    251250        job.State = JobState.DeletionPending;
    252251      }
     
    257256      var resourceDao = pm.ResourceDao;
    258257
    259       var resources = resourceDao.GetAll().ToList();
    260       var dimClients = dimClientDao.GetAllOnlineClients().ToList();
     258      var resources = resourceDao.GetAll().ToList(); // all live now
     259      var dimClients = dimClientDao.GetAllOnlineClients().ToList(); // all in statistics which are online (i.e. not expired)
    261260
    262261      var onlineClients = dimClients.Where(x => resources.Select(y => y.ResourceId).Contains(x.ResourceId));
     
    265264
    266265      // set expiration time of removed resources
    267       foreach(var r in removedResources) {
     266      foreach (var r in removedResources) {
    268267        r.DateExpired = DateTime.Now;
    269268      }
     
    281280      // expire client if its parent has changed and create a new entry
    282281      // otherwise perform "normal" update
    283       foreach(var dimc in onlineClients) {
     282      foreach (var dimc in onlineClients) {
    284283        var r = resources.Where(x => x.ResourceId == dimc.ResourceId).SingleOrDefault();
    285         if(r != null) {
    286           if(dimc.ParentResourceId == null ? r.ParentResourceId != null : dimc.ParentResourceId != r.ParentResourceId) {
     284        if (r != null) {
     285          if (dimc.ParentResourceId == null ? r.ParentResourceId != null : dimc.ParentResourceId != r.ParentResourceId) {
    287286            var now = DateTime.Now;
    288287            dimc.DateExpired = now;
     
    416415        let uStats = projectUsageStats.Where(x => x.ProjectId == dimp.ProjectId).SingleOrDefault()
    417416        select new FactProjectInfo {
    418             ProjectId = dimp.Id,
    419             DimTime = newTime,
    420             NumTotalCores = aStats != null ? aStats.Cores : 0,
    421             TotalMemory = aStats != null ? aStats.Memory : 0,
    422             NumUsedCores = uStats != null ? uStats.Cores : 0,
    423             UsedMemory = uStats != null ? uStats.Memory : 0
    424           }
     417          ProjectId = dimp.Id,
     418          DimTime = newTime,
     419          NumTotalCores = aStats != null ? aStats.Cores : 0,
     420          TotalMemory = aStats != null ? aStats.Memory : 0,
     421          NumUsedCores = uStats != null ? uStats.Cores : 0,
     422          UsedMemory = uStats != null ? uStats.Memory : 0
     423        }
    425424        );
    426425    }
     
    431430      var dimClientDao = pm.DimClientDao;
    432431
    433       var factTaskIds = factTaskDao.GetAll().Select(x => x.TaskId);
    434       var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks();
    435       //var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks().Select(x => new {
    436       //  x.TaskId,
    437       //  x.LastClientId
    438       //});
    439 
    440       // query several properties for all new and not finished tasks
    441       // in order to use them later either...
    442       // (1) to update the fact task entry of not finished tasks
    443       // (2) to insert a new fact task entry for new tasks
     432      var preselectedNewAndNotFinishedTasks =
     433        (from task in taskDao.GetAll()
     434         from factTask in factTaskDao.GetAll().Where(f => task.TaskId == f.TaskId).DefaultIfEmpty()
     435         let stateLogs = task.StateLogs.OrderByDescending(x => x.DateTime).ToList()
     436         let lastSlaveId = stateLogs.First(x => x.SlaveId != null)
     437         where !task.IsParentTask && (factTask.TaskId == null || factTask.EndTime == null)
     438         select new { Task = task, StateLogs = stateLogs, LastSlaveId = lastSlaveId }).ToList();
     439
     440      Console.WriteLine("preselectedNewAndNotFinishedTasks.Count = {0}", preselectedNewAndNotFinishedTasks.Count);
     441
     442      // jkarder: maybe we can split this query into multiple ones to retrieve state logs and the last slave
     443
     444      var clients = dimClientDao.GetAllOnlineClients().ToList();
     445      Console.WriteLine("clients.Count = {0}", clients.Count);
     446      var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks().ToList();
     447      Console.WriteLine("notFinishedFactTasks.Count = {0}", notFinishedFactTasks.Count);
     448
    444449      var newAndNotFinishedTasks =
    445         (from task in taskDao.GetAllChildTasks()
    446          let stateLogs = task.StateLogs.OrderByDescending(x => x.DateTime)
    447          let lastSlaveId = stateLogs.First(x => x.SlaveId != null).SlaveId
    448          where (!factTaskIds.Contains(task.TaskId)
    449                 || notFinishedFactTasks.Select(x => x.TaskId).Contains(task.TaskId))
     450        (from x in preselectedNewAndNotFinishedTasks
     451         let task = x.Task
     452         let stateLogs = x.StateLogs // jkarder: if multiple join results in multiple rows, statelogs of all equal tasks must be the same ...
     453         let lastSlaveId = x.LastSlaveId
    450454         join lastFactTask in notFinishedFactTasks on task.TaskId equals lastFactTask.TaskId into lastFactPerTask
    451455         from lastFact in lastFactPerTask.DefaultIfEmpty()
    452          join client in dimClientDao.GetAllOnlineClients() on lastSlaveId equals client.ResourceId into clientsPerSlaveId
    453          from client in clientsPerSlaveId.DefaultIfEmpty()
     456           // jkarder:
     457           // we can still fix this another way, if we only select that one row from dimclients that fits the given statelog/lastslave entry
     458           // dimclient has multiple entires for one and the same client, because we track changes in resource group hierarchies
     459           // -> left join from task/statelog to dimclient results in multiple rows because multiple rows in dimclient with the same resource id exist
     460           // -> further down the road we call singleordefault to single out tasks to get the data for the update
     461           // -> dimclient should only contain one valid row for a given time span that fits to the lastslaveid.datetime
     462           // -> client.datecreated <= lastslaveid.datetime <= client.dateexpired
     463           // it's aweful ...
     464         from client in clients.Where(c => lastSlaveId != null && lastSlaveId.SlaveId == c.ResourceId && c.DateCreated <= lastSlaveId.DateTime && (c.DateExpired == null || lastSlaveId.DateTime <= c.DateExpired)).DefaultIfEmpty()
     465           // jkarder:
     466           //join client in clients on lastSlaveId.SlaveId equals client.ResourceId into clientsPerSlaveId
     467           //from client in clientsPerSlaveId.DefaultIfEmpty()
    454468         select new {
    455469           TaskId = task.TaskId,
     
    459473           MemoryRequired = task.MemoryNeeded,
    460474           State = task.State,
    461            StateLogs = stateLogs.OrderBy(x => x.DateTime),
     475           StateLogs = stateLogs.OrderBy(x => x.DateTime).ToList(),
    462476           LastClientId = client != null
    463                           ? client.Id : lastFact != null
    464                           ? lastFact.LastClientId : (Guid?)null,
     477                        ? client.Id : lastFact != null
     478                        ? lastFact.LastClientId : (Guid?)null,
    465479           NotFinishedTask = notFinishedFactTasks.Any(y => y.TaskId == task.TaskId)
    466480         }).ToList();
     481
     482      Console.WriteLine("newAndNotFinishedTasks.Count = {0}", newAndNotFinishedTasks.Count);
     483
    467484
    468485      // (1) update data of already existing facts
    469486      // i.e. for all in newAndNotFinishedTasks where NotFinishedTask = true
    470487      foreach (var notFinishedFactTask in notFinishedFactTasks) {
    471         var nfftUpdate = newAndNotFinishedTasks.Where(x => x.TaskId == notFinishedFactTask.TaskId).SingleOrDefault();
    472         if(nfftUpdate != null) {
     488        // jkarder: firstordefault should work too, because statelogs of multiple task rows that result from the earlier join have to be the same
     489        var nfftUpdate = newAndNotFinishedTasks.Where(x => x.TaskId == notFinishedFactTask.TaskId).FirstOrDefault();
     490        if (nfftUpdate != null) {
    473491          var taskData = CalculateFactTaskData(nfftUpdate.StateLogs);
    474492
     
    487505          notFinishedFactTask.Exception = taskData.Exception;
    488506          notFinishedFactTask.InitialWaitingTime = taskData.InitialWaitingTime;
     507        } else {
     508          //Console.WriteLine("could not update task {0}", notFinishedFactTask.TaskId);
    489509        }
    490510      }
     511
     512      Console.WriteLine("nfft update complete");
    491513
    492514      // (2) insert facts for new tasks
    493515      // i.e. for all in newAndNotFinishedTasks where NotFinishedTask = false
    494       factTaskDao.Save(
    495         from x in newAndNotFinishedTasks
    496         where !x.NotFinishedTask
    497         let taskData = CalculateFactTaskData(x.StateLogs)
    498         select new FactTask {
    499           TaskId = x.TaskId,
    500           JobId = x.JobId,
    501           StartTime = taskData.StartTime,
    502           EndTime = taskData.EndTime,
    503           LastClientId = x.LastClientId,
    504           Priority = x.Priority,
    505           CoresRequired = x.CoresRequired,
    506           MemoryRequired = x.MemoryRequired,
    507           NumCalculationRuns = taskData.CalculationRuns,
    508           NumRetries = taskData.Retries,
    509           WaitingTime = taskData.WaitingTime,
    510           CalculatingTime = taskData.CalculatingTime,
    511           TransferTime = taskData.TransferTime,
    512           TaskState = x.State,
    513           Exception = taskData.Exception,
    514           InitialWaitingTime = taskData.InitialWaitingTime
    515         });
    516 
    517 
    518       ////update data of already existing facts
    519       //foreach (var notFinishedTask in factTaskDao.GetNotFinishedTasks()) {
    520       //  var ntc = newTasks.Where(x => x.TaskId == notFinishedTask.TaskId);
    521       //  if (ntc.Any()) {
    522       //    var x = ntc.Single();
    523       //    var taskData = CalculateFactTaskData(x.StateLogs);
    524 
    525       //    notFinishedTask.StartTime = taskData.StartTime;
    526       //    notFinishedTask.EndTime = taskData.EndTime;
    527       //    notFinishedTask.LastClientId = x.LastClientId;
    528       //    notFinishedTask.Priority = x.Priority;
    529       //    notFinishedTask.CoresRequired = x.CoresRequired;
    530       //    notFinishedTask.MemoryRequired = x.MemoryRequired;
    531       //    notFinishedTask.NumCalculationRuns = taskData.CalculationRuns;
    532       //    notFinishedTask.NumRetries = taskData.Retries;
    533       //    notFinishedTask.WaitingTime = taskData.WaitingTime;
    534       //    notFinishedTask.CalculatingTime = taskData.CalculatingTime;
    535       //    notFinishedTask.TransferTime = taskData.TransferTime;
    536       //    notFinishedTask.TaskState = x.State;
    537       //    notFinishedTask.Exception = taskData.Exception;
    538       //    notFinishedTask.InitialWaitingTime = taskData.InitialWaitingTime;
    539       //  }
    540       //}
     516      var newFactTasks = (from x in newAndNotFinishedTasks
     517                          where !x.NotFinishedTask
     518                          let taskData = CalculateFactTaskData(x.StateLogs)
     519                          select new FactTask {
     520                            TaskId = x.TaskId,
     521                            JobId = x.JobId,
     522                            StartTime = taskData.StartTime,
     523                            EndTime = taskData.EndTime,
     524                            LastClientId = x.LastClientId,
     525                            Priority = x.Priority,
     526                            CoresRequired = x.CoresRequired,
     527                            MemoryRequired = x.MemoryRequired,
     528                            NumCalculationRuns = taskData.CalculationRuns,
     529                            NumRetries = taskData.Retries,
     530                            WaitingTime = taskData.WaitingTime,
     531                            CalculatingTime = taskData.CalculatingTime,
     532                            TransferTime = taskData.TransferTime,
     533                            TaskState = x.State,
     534                            Exception = taskData.Exception,
     535                            InitialWaitingTime = taskData.InitialWaitingTime
     536                          }).ToList();
     537      Console.WriteLine("newFactTasks.Count = {0}", newFactTasks.Count);
     538      factTaskDao.Save(newFactTasks);
     539      Console.WriteLine("save of new fact tasks completed");
    541540    }
    542541
     
    551550          return user != null ? user.UserName : UnknownUserName;
    552551        }
    553       }
    554       catch (Exception) {
     552      } catch (Exception) {
    555553        return UnknownUserName;
    556554      }
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Interfaces/ITaskScheduler.cs

    r17226 r17586  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    23 using HeuristicLab.Services.Hive.DataTransfer;
     24using HeuristicLab.Services.Hive.DataAccess;
    2425
    2526namespace HeuristicLab.Services.Hive {
    2627  public interface ITaskScheduler {
    27     IEnumerable<TaskInfoForScheduler> Schedule(IEnumerable<TaskInfoForScheduler> tasks, int count = 1);
     28    IEnumerable<Guid> Schedule(Slave slave, int count = 1);
    2829  }
    2930}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Manager/EventManager.cs

    r17226 r17586  
    2828  public class EventManager : IEventManager {
    2929    private const string SlaveTimeout = "Slave timed out.";
     30    private static readonly TaskState[] CompletedStates = { TaskState.Finished, TaskState.Aborted, TaskState.Failed };
     31
    3032    private IPersistenceManager PersistenceManager {
    3133      get { return ServiceLocator.Instance.PersistenceManager; }
     
    3335
    3436    public void Cleanup() {
     37      Console.WriteLine("started cleanup");
    3538      var pm = PersistenceManager;
    3639
    37       pm.UseTransaction(() => {
    38         FinishJobDeletion(pm);
    39         pm.SubmitChanges();
    40       });
     40      // preemptiv delete obsolete entities
     41      // speeds up job deletion
     42      BatchDelete((p, s) => p.StateLogDao.DeleteObsolete(s), 100, 100, true, pm, "DeleteObsoleteStateLogs");
     43      BatchDelete((p, s) => p.TaskDataDao.DeleteObsolete(s), 100, 20, true, pm, "DeleteObsoleteTaskData");
     44      BatchDelete((p, s) => p.TaskDao.DeleteObsolete(s), 100, 20, false, pm, "DeleteObsoleteTasks");
     45      BatchDelete((p, s) => p.JobDao.DeleteByState(JobState.DeletionPending, s), 100, 20, true, pm, "DeleteObsoleteJobs");
    4146
    42       pm.UseTransaction(() => {
    43         SetTimeoutSlavesOffline(pm);
    44         SetTimeoutTasksWaiting(pm);
    45         DeleteObsoleteSlaves(pm);
    46         pm.SubmitChanges();
    47       });
     47      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: SetTimeoutSlavesOffline");
     48      Console.WriteLine("5");
     49      pm.UseTransactionAndSubmit(() => { SetTimeoutSlavesOffline(pm); });
     50      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: SetTimeoutTasksWaiting");
     51      Console.WriteLine("6");
     52      pm.UseTransactionAndSubmit(() => { SetTimeoutTasksWaiting(pm); });
     53      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: DeleteObsoleteSlaves");
     54      Console.WriteLine("7");
     55      pm.UseTransactionAndSubmit(() => { DeleteObsoleteSlaves(pm); });
     56      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: AbortObsoleteTasks");
     57      Console.WriteLine("8");
     58      pm.UseTransactionAndSubmit(() => { AbortObsoleteTasks(pm); });
     59      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: FinishParentTasks");
     60      Console.WriteLine("9");
     61      pm.UseTransactionAndSubmit(() => { FinishParentTasks(pm); });
     62      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log("HiveJanitor: DONE");
     63      Console.WriteLine("10");
     64    }
    4865
    49       pm.UseTransaction(() => {
    50         FinishParentTasks(pm);
    51         pm.SubmitChanges();
    52       });
     66    private void BatchDelete(
     67      Func<IPersistenceManager, int, int> deletionFunc,
     68      int batchSize,
     69      int maxCalls,
     70      bool limitIsBatchSize,
     71      IPersistenceManager pm,
     72      string logMessage
     73    ) {
     74      int totalDeleted = 0;
     75      while (maxCalls > 0) {
     76        maxCalls--;
     77        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"HiveJanitor: {logMessage}");
     78        Console.WriteLine($"HiveJanitor: {logMessage}");
     79        var deleted = pm.UseTransactionAndSubmit(() => { return deletionFunc(pm, batchSize); });
     80        LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"HiveJanitor: {logMessage} DONE (deleted {deleted}, {maxCalls} calls left)");
     81        Console.WriteLine($"HiveJanitor: {logMessage} DONE (deleted {deleted}, {maxCalls} calls left)");
     82        totalDeleted += deleted;
     83        if (limitIsBatchSize && deleted < batchSize || deleted <= 0) return;
     84      }
     85      LogFactory.GetLogger(typeof(HiveJanitor).Namespace).Log($"HiveJanitor: Possible rows left to delete (total deleted: {totalDeleted}).");
     86      Console.WriteLine($"HiveJanitor: Possible rows left to delete (total deleted: {totalDeleted}).");
    5387    }
    5488
     
    136170      }
    137171    }
     172
     173    /// <summary>
     174    /// Aborts tasks whose jobs have already been marked for deletion
     175    /// </summary>
     176    /// <param name="pm"></param>
     177    private void AbortObsoleteTasks(IPersistenceManager pm) {
     178      var jobDao = pm.JobDao;
     179      var taskDao = pm.TaskDao;
     180
     181      var obsoleteTasks = (from jobId in jobDao.GetJobIdsByState(JobState.StatisticsPending)
     182                           join task in taskDao.GetAll() on jobId equals task.JobId
     183                           where !CompletedStates.Contains(task.State) && task.Command == null
     184                           select task).ToList();
     185
     186      foreach (var t in obsoleteTasks) {
     187        t.State = TaskState.Aborted;
     188      }
     189    }
    138190  }
    139191}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs

    r17226 r17586  
    8383            mutexAquired = mutex.WaitOne(Properties.Settings.Default.SchedulingPatience);
    8484            if (mutexAquired) {
    85               var waitingTasks = pm.UseTransaction(() => taskDao.GetWaitingTasks(slave)
    86                   .Select(x => new TaskInfoForScheduler {
    87                     TaskId = x.TaskId,
    88                     JobId = x.JobId,
    89                     Priority = x.Priority
    90                   })
    91                   .ToList()
    92               );
    93               var availableTasks = TaskScheduler.Schedule(waitingTasks).ToArray();
    94               if (availableTasks.Any()) {
    95                 var task = availableTasks.First();
    96                 AssignTask(pm, slave, task.TaskId);
    97                 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, task.TaskId));
     85              var scheduledTaskIds = TaskScheduler.Schedule(slave, 1).ToArray();
     86              foreach (var id in scheduledTaskIds) {
     87                actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, id));
    9888              }
    9989            } else {
    100               LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired.");
     90              LogFactory.GetLogger(this.GetType().Namespace).Log($"HeartbeatManager: The mutex used for scheduling could not be aquired. (HB from Slave {slave.ResourceId})");
    10191            }
    102           }
    103           catch (AbandonedMutexException) {
    104             LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned.");
    105           }
    106           catch (Exception ex) {
    107             LogFactory.GetLogger(this.GetType().Namespace).Log(string.Format("HeartbeatManager threw an exception in ProcessHeartbeat: {0}", ex));
    108           }
    109           finally {
     92          } catch (AbandonedMutexException) {
     93            LogFactory.GetLogger(this.GetType().Namespace).Log($"HeartbeatManager: The mutex used for scheduling has been abandoned. (HB from Slave {slave.ResourceId})");
     94          } catch (Exception ex) {
     95            LogFactory.GetLogger(this.GetType().Namespace).Log($"HeartbeatManager threw an exception in ProcessHeartbeat (HB from Slave {slave.ResourceId}): {ex}");
     96          } finally {
    11097            if (mutexAquired) mutex.ReleaseMutex();
    11198          }
     
    113100      }
    114101      return actions;
    115     }
    116 
    117     private void AssignTask(IPersistenceManager pm, DA.Slave slave, Guid taskId) {
    118       const DA.TaskState transferring = DA.TaskState.Transferring;
    119       DateTime now = DateTime.Now;
    120       var taskDao = pm.TaskDao;
    121       var stateLogDao = pm.StateLogDao;
    122       pm.UseTransaction(() => {
    123         var task = taskDao.GetById(taskId);
    124         stateLogDao.Save(new DA.StateLog {
    125           State = transferring,
    126           DateTime = now,
    127           TaskId = taskId,
    128           SlaveId = slave.ResourceId,
    129           UserId = null,
    130           Exception = null
    131         });
    132         task.State = transferring;
    133         task.LastHeartbeat = now;
    134         pm.SubmitChanges();
    135       });
    136102    }
    137103
     
    154120      var taskInfos = pm.UseTransaction(() =>
    155121        (from task in taskDao.GetAll()
    156           where taskIds.Contains(task.TaskId)
    157           let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault()
    158           select new {
    159             TaskId = task.TaskId,
    160             JobId = task.JobId,
    161             State = task.State,
    162             Command = task.Command,
    163             SlaveId = lastStateLog != null ? lastStateLog.SlaveId : default(Guid)
    164           }).ToList()
     122         where taskIds.Contains(task.TaskId)
     123         let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault(x => x.State == DA.TaskState.Transferring)
     124         select new {
     125           TaskId = task.TaskId,
     126           JobId = task.JobId,
     127           State = task.State,
     128           Command = task.Command,
     129           SlaveId = lastStateLog != null ? lastStateLog.SlaveId : Guid.Empty
     130         }).ToList()
    165131      );
    166132
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/MessageContainer.cs

    r17226 r17586  
    2424using HEAL.Attic;
    2525using HeuristicLab.Common;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726
    2827namespace HeuristicLab.Services.Hive {
     
    3130  /// the actual message itself and the TaskId, refered by the message
    3231  /// </summary>
    33   [StorableClass]
     32  [StorableType("67DEE81F-81FA-4B47-B043-93DBC2028DB5")]
    3433  [Serializable]
    3534  [DataContract]
    3635  public class MessageContainer : IDeepCloneable {
    37 
     36    [StorableType("A907BDB0-99E3-4EE2-BA31-72FFD29F7B19")]
    3837    public enum MessageType {
    3938      // *** commands from hive server ***
     
    6261
    6362    [StorableConstructor]
    64     protected MessageContainer(bool deserializing) { }
     63    protected MessageContainer(StorableConstructorFlag _) { }
    6564    protected MessageContainer() { }
    6665    public MessageContainer(MessageType message) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Properties/Settings.Designer.cs

    r12961 r17586  
    11//------------------------------------------------------------------------------
    22// <auto-generated>
    3 //     Dieser Code wurde von einem Tool generiert.
    4 //     Laufzeitversion:4.0.30319.42000
     3//     This code was generated by a tool.
     4//     Runtime Version:4.0.30319.42000
    55//
    6 //     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
    7 //     der Code erneut generiert wird.
     6//     Changes to this file may cause incorrect behavior and will be lost if
     7//     the code is regenerated.
    88// </auto-generated>
    99//------------------------------------------------------------------------------
     
    1313   
    1414    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    15     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
     15    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")]
    1616    public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    1717       
     
    8080        [global::System.Configuration.ApplicationScopedSettingAttribute()]
    8181        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    82         [global::System.Configuration.DefaultSettingValueAttribute("00:00:20")]
     82        [global::System.Configuration.DefaultSettingValueAttribute("00:01:10")]
    8383        public global::System.TimeSpan SchedulingPatience {
    8484            get {
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Properties/Settings.settings

    r12961 r17586  
    2222    </Setting>
    2323    <Setting Name="SchedulingPatience" Type="System.TimeSpan" Scope="Application">
    24       <Value Profile="(Default)">00:00:20</Value>
     24      <Value Profile="(Default)">00:01:10</Value>
    2525    </Setting>
    2626    <Setting Name="ProfileServicePerformance" Type="System.Boolean" Scope="Application">
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs

    r17226 r17586  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using HeuristicLab.Services.Hive.DataAccess.Interfaces;
    2625using DA = HeuristicLab.Services.Hive.DataAccess;
    2726
    2827namespace HeuristicLab.Services.Hive {
    29   public class RoundRobinTaskScheduler : ITaskScheduler {
    30     private IPersistenceManager PersistenceManager {
    31       get { return ServiceLocator.Instance.PersistenceManager; }
     28  public class RoundRobinTaskScheduler : TaskScheduler {
     29    private class TaskPriorityResult {
     30      public Guid TaskId { get; set; }
     31      public Guid OwnerUserId { get; set; }
    3232    }
    3333
    34     public IEnumerable<TaskInfoForScheduler> Schedule(IEnumerable<TaskInfoForScheduler> tasks, int count = 1) {
    35       if (!tasks.Any()) return Enumerable.Empty<TaskInfoForScheduler>();
     34    protected override IReadOnlyList<Guid> ScheduleInternal(DA.Slave slave, int count) {
     35      var pm = PersistenceManager;
    3636
    37       var pm = PersistenceManager;
    38       var userPriorityDao = pm.UserPriorityDao;
    39       var jobDao = pm.JobDao;
     37      var result = pm.DataContext.ExecuteQuery<TaskPriorityResult>(
     38        GetHighestPriorityWaitingTasksQuery, slave.ResourceId, count, slave.FreeCores, slave.FreeMemory).ToList();
    4039
    41       var userPriorities = pm.UseTransaction(() => userPriorityDao.GetAll()
    42         .OrderBy(x => x.DateEnqueued)
    43         .ToArray()
    44       );
     40      foreach (var row in result) {
     41        pm.DataContext.ExecuteCommand("UPDATE UserPriority SET DateEnqueued = SYSDATETIME() WHERE UserId = {0}", row.OwnerUserId);
     42      }
    4543
    46       var userIds = userPriorities.Select(x => x.UserId).ToList();
    47       var jobs = pm.UseTransaction(() => {
    48         return jobDao.GetAll()
    49           .Where(x => userIds.Contains(x.OwnerUserId))
    50           .Select(x => new {
    51             Id = x.JobId,
    52             DateCreated = x.DateCreated,
    53             OwnerUserId = x.OwnerUserId
    54           })
    55           .ToList();
    56       });
    57 
    58       var taskJobRelations = tasks.Join(jobs,
    59         task => task.JobId,
    60         job => job.Id,
    61         (task, job) => new { Task = task, JobInfo = job })
    62         .OrderByDescending(x => x.Task.Priority)
    63         .ToList();
    64 
    65       var scheduledTasks = new List<TaskInfoForScheduler>();
    66       int priorityIndex = 0;
    67 
    68       if (count == 0 || count > taskJobRelations.Count) count = taskJobRelations.Count;
    69 
    70       for (int i = 0; i < count; i++) {
    71         var defaultEntry = taskJobRelations.First(); // search first task which is not included yet
    72         var priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].UserId).ToArray(); // search for tasks with desired user priority
    73         while (!priorityEntries.Any() && priorityIndex < userPriorities.Length - 1) {
    74           priorityIndex++;
    75           priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].UserId).ToArray();
    76         }
    77         if (priorityEntries.Any()) { // tasks with desired user priority found
    78           var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.JobInfo.DateCreated).First();
    79           if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) {
    80             taskJobRelations.Remove(priorityEntry);
    81             scheduledTasks.Add(priorityEntry.Task);
    82             UpdateUserPriority(pm, userPriorities[priorityIndex]);
    83             priorityIndex++;
    84           } else { // there are other tasks with higher priorities
    85             taskJobRelations.Remove(defaultEntry);
    86             scheduledTasks.Add(defaultEntry.Task);
    87           }
    88         } else {
    89           taskJobRelations.Remove(defaultEntry);
    90           scheduledTasks.Add(defaultEntry.Task);
    91         }
    92         if (priorityIndex >= (userPriorities.Length - 1)) priorityIndex = 0;
    93       }
    94       return scheduledTasks;
    95 
     44      return result.Select(x => x.TaskId).ToArray();
    9645    }
    9746
    98     private void UpdateUserPriority(IPersistenceManager pm, DA.UserPriority up) {
    99       pm.UseTransaction(() => {
    100         up.DateEnqueued = DateTime.Now;
    101         pm.SubmitChanges();
    102       });
    103     }
     47    #region Query Strings
     48    private string GetHighestPriorityWaitingTasksQuery = @"
     49WITH rbranch AS(
     50  SELECT ResourceId, ParentResourceId
     51  FROM [Resource]
     52  WHERE ResourceId = {0}
     53  UNION ALL
     54  SELECT r.ResourceId, r.ParentResourceId
     55  FROM [Resource] r
     56  JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId
     57)
     58SELECT TOP ({1}) t.TaskId, j.OwnerUserId
     59FROM Task t
     60  JOIN Job j on t.JobId = j.JobId
     61  JOIN AssignedJobResource ajr on j.JobId = ajr.JobId
     62  JOIN rbranch on ajr.ResourceId = rbranch.ResourceId
     63  JOIN UserPriority u on j.OwnerUserId = u.UserId
     64WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1)
     65AND t.TaskState = 'Waiting'
     66AND t.CoresNeeded <= {2}
     67AND t.MemoryNeeded <= {3}
     68AND j.JobState = 'Online'
     69ORDER BY t.Priority DESC, u.DateEnqueued ASC, j.DateCreated ASC";
     70    #endregion
    10471  }
    10572}
  • branches/2521_ProblemRefactoring/HeuristicLab.Services.Hive/3.3/app.config

    r16692 r17586  
    2828      </setting>
    2929      <setting name="SchedulingPatience" serializeAs="String">
    30         <value>00:00:20</value>
     30        <value>00:01:10</value>
    3131      </setting>
    3232      <setting name="ProfileServicePerformance" serializeAs="String">
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests

  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/IntervalTest.cs

    r17457 r17586  
    11using System;
     2using System.Collections.Generic;
    23using Microsoft.VisualStudio.TestTools.UnitTesting;
    34
     
    141142    [TestProperty("Time", "short")]
    142143    public void SquarerootIntervalTest() {
    143       Assert.AreEqual<Interval>(new Interval(1, 2), Interval.SquareRoot(new Interval(1, 4)));
     144      Assert.AreEqual<Interval>(new Interval(-2, 2), Interval.SquareRoot(new Interval(1, 4)));
    144145      Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1)));
    145146    }
     
    192193
    193194      //Second interval goes over zero
    194       Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound), Interval.AnalyticalQuotient(aPos, bZero));
    195       Assert.AreEqual(new Interval(aZero.LowerBound, aZero.UpperBound), Interval.AnalyticalQuotient(aZero, bZero));
    196       Assert.AreEqual(new Interval(aNeg.LowerBound, aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bZero));
    197       //Second interval is positive
    198       Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bPos));
    199       Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bPos));
    200       Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bPos));
    201       //Second interval is negative
    202       Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bNeg));
    203       Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bNeg));
    204       Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bNeg));
     195      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound), Interval.AnalyticalQuotient(aPos, bZero));
     196      //Assert.AreEqual(new Interval(aZero.LowerBound, aZero.UpperBound), Interval.AnalyticalQuotient(aZero, bZero));
     197      //Assert.AreEqual(new Interval(aNeg.LowerBound, aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bZero));
     198      ////Second interval is positive
     199      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bPos));
     200      //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bPos));
     201      //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bPos));
     202      ////Second interval is negative
     203      //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bNeg));
     204      //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bNeg));
     205      //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bNeg));
     206      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aPos, bZero));
     207      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aPos, bPos));
     208      Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticalQuotient(aZero, bNeg));
    205209    }
    206210
     
    247251      Assert.AreEqual(0, zeroInterval.LowerBound);
    248252      Assert.AreEqual(0, zeroInterval.UpperBound);
    249 
    250     }
     253    }
     254
     255    [TestMethod]
     256    [TestCategory("Problems.DataAnalysis")]
     257    [TestProperty("Time", "short")]
     258    public void ContaintsTest() {
     259      var negativeInterval = new Interval(-10, -5);
     260      var positiveInterval = new Interval(5, 10);
     261      var overZeroInterval = new Interval(-5, 5);
     262
     263      //Tests for negative intervals
     264      Assert.AreEqual(true, negativeInterval.Contains(new Interval(-9, -7)));
     265      Assert.AreEqual(false, negativeInterval.Contains(new Interval(-11, -3)));
     266      Assert.AreEqual(false, negativeInterval.Contains(positiveInterval));
     267      Assert.AreEqual(false, negativeInterval.Contains(overZeroInterval));
     268      Assert.AreEqual(true, negativeInterval.Contains(-8));
     269      Assert.AreEqual(false, negativeInterval.Contains(-12));
     270      Assert.AreEqual(false, negativeInterval.Contains(0));
     271      //Testes for positive intervals
     272      Assert.AreEqual(true, positiveInterval.Contains(new Interval(6, 10)));
     273      Assert.AreEqual(false, positiveInterval.Contains(new Interval(6, 12)));
     274      Assert.AreEqual(false, positiveInterval.Contains(negativeInterval));
     275      Assert.AreEqual(false, positiveInterval.Contains(overZeroInterval));
     276      Assert.AreEqual(true, positiveInterval.Contains(7));
     277      Assert.AreEqual(false, positiveInterval.Contains(11));
     278      Assert.AreEqual(false, positiveInterval.Contains(0));
     279      //Tests for over zero intervals
     280      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-3, 3)));
     281      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-4, -1)));
     282      Assert.AreEqual(true, overZeroInterval.Contains(new Interval(1, 5)));
     283      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-6, 0)));
     284      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(0, 6)));
     285      Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-7, 7)));
     286      Assert.AreEqual(true, overZeroInterval.Contains(-3));
     287      Assert.AreEqual(true, overZeroInterval.Contains(0));
     288      Assert.AreEqual(true, overZeroInterval.Contains(3));
     289      Assert.AreEqual(false, overZeroInterval.Contains(12));
     290      Assert.AreEqual(false, overZeroInterval.Contains(-7));
     291    }
     292
     293    [TestMethod]
     294    [TestCategory("Problems.DataAnalysis")]
     295    [TestProperty("Time", "short")]
     296    public void GetIntervalTest() {
     297      var values = new List<double>() { -2.5, -9, 2, 7, 0 ,12, 12.4, 12.4, 9.29, 1002, -29.9};
     298      var valuesNan = new List<double>() { double.NaN, 2, 4, 19, -2, -12.2};
     299      var valuesInf = new List<double>() {double.NegativeInfinity, double.PositiveInfinity, 12, 2, -2, -12.2};
     300
     301      var valuesInterval = new Interval(-29.9, 1002);
     302      var valuesNanInterval = new Interval(double.NaN, double.NaN);
     303      var valuesInfInterval = new Interval(double.NegativeInfinity, double.PositiveInfinity);
     304
     305
     306      Assert.AreEqual(valuesInterval, Interval.GetInterval(values));
     307      Assert.AreEqual(valuesNanInterval, Interval.GetInterval(valuesNan));
     308      Assert.AreEqual(valuesInfInterval, Interval.GetInterval(valuesInf));
     309    }
     310
     311    [TestMethod]
     312    [TestCategory("Problems.DataAnalysis")]
     313    [TestProperty("Time", "short")]
     314    public void EqualsTest() {
     315      var interval1 = new Interval(0, 12);
     316      var interval2 = new Interval(-12, 8);
     317      var interval3 = new Interval(double.NegativeInfinity, 0);
     318
     319      Assert.AreEqual(true, interval1.Equals(new Interval(0, 12)));
     320      Assert.AreEqual(false, interval1.Equals(interval2));
     321      Assert.AreEqual(true, interval3 == new Interval(double.NegativeInfinity, 0));
     322      Assert.AreEqual(true, interval1 != interval2);
     323      Assert.AreEqual(false, interval2 == interval3);
     324      Assert.AreEqual(false, interval1 != new Interval(0, 12));
     325    }
     326    //[TestMethod]
     327    //[TestCategory("Problems.DataAnalysis")]
     328    //[TestProperty("Time", "short")]
     329    //public void RootTest() {
     330    //  var posInterval = new Interval(3, 5);
     331    //  var negInterval = new Interval(-6, -2);
     332    //  var posIntervalConst = new Interval(5, 5);
     333    //  var negIntervalConst = new Interval(-3, -3);
     334    //  var zeroIntervalConst = new Interval(0, 0);
     335    //  var zeroPosInterval = new Interval(0, 2);
     336    //  var zeroNegInterval = new Interval(-2, 0);
     337
     338    //  var posRoot = new Interval(4, 4);
     339    //  var negRoot = new Interval(-4, -4);
     340    //  var zeroRoot = new Interval(0, 0);
     341    //  var oneRoot = new Interval(1, 1);
     342
     343    //  Assert.AreEqual(Interval.Root(posInterval, posRoot), new Interval(Math.Pow(3, (1.0/4)), Math.Pow(5, (1.0/4))));
     344    //  Assert.AreEqual(Interval.Root(posInterval, negRoot), new Interval(Math.Pow(5, -(1.0/4)), Math.Pow(3, -(1.0/4))));
     345    //  Assert.AreEqual(Interval.Root(posInterval, zeroRoot), new Interval(double.NaN, double.NaN));
     346    //  Assert.AreEqual(Interval.Root(posInterval, oneRoot), new Interval(3, 5));
     347
     348    //  Assert.AreEqual(Interval.Root(negInterval, posRoot), new Interval(Math.Pow(-6, (1.0 / 4)), Math.Pow(-2, (1.0 / 4))));
     349    //  Assert.AreEqual(Interval.Root(negInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), Math.Pow(-6, -(1.0 / 4))));
     350    //  Assert.AreEqual(Interval.Root(negInterval, zeroRoot), new Interval(double.NaN, double.NaN));
     351    //  Assert.AreEqual(Interval.Root(negInterval, oneRoot), new Interval(-6, -2));
     352
     353    //  Assert.AreEqual(Interval.Root(posIntervalConst, posRoot), new Interval(Math.Pow(5, (1.0 / 4)), Math.Pow(5, (1.0 / 4))));
     354    //  Assert.AreEqual(Interval.Root(posIntervalConst, negRoot), new Interval(Math.Pow(5, -(1.0 / 4)), Math.Pow(5, -(1.0 / 4))));
     355    //  Assert.AreEqual(Interval.Root(posIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
     356    //  Assert.AreEqual(Interval.Root(posIntervalConst, oneRoot), new Interval(5, 5));
     357
     358    //  Assert.AreEqual(Interval.Root(negIntervalConst, posRoot), new Interval(Math.Pow(-3, (1.0 / 4)), Math.Pow(-3, (1.0 / 4))));
     359    //  Assert.AreEqual(Interval.Root(negIntervalConst, negRoot), new Interval(Math.Pow(-3, -(1.0 / 4)), Math.Pow(-3, -(1.0 / 4))));
     360    //  Assert.AreEqual(Interval.Root(negIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN));
     361    //  Assert.AreEqual(Interval.Root(negIntervalConst, oneRoot), new Interval(-3, -3));
     362
     363    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, posRoot), new Interval(0, 0));
     364    //  //Compley Infinity https://www.wolframalpha.com/input/?i=root%28-4%2C+0%29
     365    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, negRoot), new Interval(double.PositiveInfinity, double.PositiveInfinity));
     366    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, zeroRoot), new Interval(0, 0));
     367    //  Assert.AreEqual(Interval.Root(zeroIntervalConst, oneRoot), new Interval(0, 0));
     368
     369    //  Assert.AreEqual(Interval.Root(zeroPosInterval, posRoot), new Interval(0, Math.Pow(2, (1.0 / 4))));
     370    //  //Check for complex infinity
     371    //  Assert.AreEqual(Interval.Root(zeroPosInterval, negRoot), new Interval(Math.Pow(2, -(1.0 / 4)), double.PositiveInfinity));
     372    //  Assert.AreEqual(Interval.Root(zeroPosInterval, zeroRoot), new Interval(0, 0));
     373    //  Assert.AreEqual(Interval.Root(zeroPosInterval, oneRoot), new Interval(0, 2));
     374
     375    //  Assert.AreEqual(Interval.Root(zeroNegInterval, posRoot), new Interval(Math.Pow(-2, (1.0 / 4)),0));
     376    //  //Check for complex infinity
     377    //  Assert.AreEqual(Interval.Root(zeroNegInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), double.PositiveInfinity));
     378    //  Assert.AreEqual(Interval.Root(zeroNegInterval, zeroRoot), new Interval(double.NaN, double.NaN));
     379    //  Assert.AreEqual(Interval.Root(zeroNegInterval, oneRoot), new Interval(-2, 0));
     380    //}
    251381  }
    252382}
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalInterpreterTest.cs

    r16801 r17586  
    4040      Interval result;
    4141      if (variableRanges == null)
    42         result = interpreter.GetSymbolicExpressionTreeInterval(tree, problemData.Dataset, problemData.AllIndices);
     42        result = interpreter.GetSymbolicExpressionTreeInterval(tree, problemData.Dataset, rows:problemData.AllIndices);
    4343      else
    4444        result = interpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges);
     
    163163    }
    164164
    165     [TestMethod]
    166     [TestCategory("Problems.DataAnalysis.Symbolic")]
    167     [TestProperty("Time", "short")]
    168     public void TestIntervalInterpreterExpRoot() {
    169       EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(6)), Math.Exp(Math.Sqrt(48))));
    170       EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(4)), Math.Exp(Math.Sqrt(60))), variableRanges);
    171     }
    172 
    173     [TestMethod]
    174     [TestCategory("Problems.DataAnalysis.Symbolic")]
    175     [TestProperty("Time", "short")]
    176     public void TestIntervalInterpreterPower() {
    177       EvaluateTest("pow(x1, 2)", new Interval(Math.Pow(3, 1), Math.Pow(8, 3)));
    178     }
    179165  }
    180166}
  • branches/2521_ProblemRefactoring/Installers/HiveJanitorServiceInstaller.nsi

    r17226 r17586  
    4646  SetOutPath $INSTDIR
    4747
    48   File "${JANITORBUILDPATH}\GeoIP.dat"
     48  File "${JANITORBUILDPATH}\Google.Protobuf.dll"
     49  File "${JANITORBUILDPATH}\HEAL.Attic.dll"
     50  ;File "${JANITORBUILDPATH}\GeoIP.dat"
    4951  File "${JANITORBUILDPATH}\HeuristicLab.Common-3.3.dll"
    50   File "${JANITORBUILDPATH}\HeuristicLab.Persistence-3.3.dll"
     52  ;File "${JANITORBUILDPATH}\HeuristicLab.Persistence-3.3.dll"
    5153  File "${JANITORBUILDPATH}\HeuristicLab.PluginInfrastructure-3.3.dll"
    5254  File "${JANITORBUILDPATH}\HeuristicLab.Services.Access.dll"
     
    5658  File "${JANITORBUILDPATH}\HeuristicLab.Services.Hive.JanitorService-3.3.exe.config"
    5759  File "${JANITORBUILDPATH}\HeuristicLab.Services.Hive-3.3.dll"
    58   File "${JANITORBUILDPATH}\HeuristicLab.Tracing-3.3.dll"
     60  ;File "${JANITORBUILDPATH}\HeuristicLab.Tracing-3.3.dll"
    5961 
    6062  WriteRegStr HKLM SOFTWARE\HeuristicLabHiveJanitorService "Install_Dir" "$INSTDIR"
     
    7678  nsExec::ExecToLog '"$INSTDIR\HeuristicLab.Services.Hive.JanitorService-3.3.exe" --uninstall'
    7779   
    78   Delete "$INSTDIR\GeoIP.dat"
     80  Delete "$INSTDIR\Google.Protobuf.dll"
     81  Delete "$INSTDIR\HEAL.Attic.dll"
     82  ;Delete "$INSTDIR\GeoIP.dat"
    7983  Delete "$INSTDIR\HeuristicLab.Common-3.3.dll"
    80   Delete "$INSTDIR\HeuristicLab.Persistence-3.3.dll"
     84  ;Delete "$INSTDIR\HeuristicLab.Persistence-3.3.dll"
    8185  Delete "$INSTDIR\HeuristicLab.PluginInfrastructure-3.3.dll"
    8286  Delete "$INSTDIR\HeuristicLab.Services.Access.dll"
     87  Delete "$INSTDIR\HeuristicLab.Services.Access.DataAccess.dll"
    8388  Delete "$INSTDIR\HeuristicLab.Services.Hive.DataAccess-3.3.dll"
    8489  Delete "$INSTDIR\HeuristicLab.Services.Hive.JanitorService-3.3.exe"
    8590  Delete "$INSTDIR\HeuristicLab.Services.Hive.JanitorService-3.3.exe.config"
    8691  Delete "$INSTDIR\HeuristicLab.Services.Hive-3.3.dll"
    87   Delete "$INSTDIR\HeuristicLab.Tracing-3.3.dll"
     92  ;Delete "$INSTDIR\HeuristicLab.Tracing-3.3.dll"
    8893  Delete "$INSTDIR\uninstall.exe"
    8994
  • branches/2521_ProblemRefactoring/Installers/HiveSlaveInstaller.nsi

    r17226 r17586  
    4646  SetOutPath $INSTDIR
    4747
     48  File "${SLAVEBUILDPATH}\Google.Protobuf.dll"
     49  File "${SLAVEBUILDPATH}\HEAL.Attic.dll"
     50  File "${SLAVEBUILDPATH}\HeuristicLab.Clients.Common-3.3.dll"
    4851  File "${SLAVEBUILDPATH}\HeuristicLab.Clients.Hive.Slave.WindowsService.exe"
    49   File "${SLAVEBUILDPATH}\HeuristicLab.Clients.Common-3.3.dll"
    5052  File "${SLAVEBUILDPATH}\HeuristicLab.Clients.Hive.Slave.WindowsService.exe.config"
    5153  File "${SLAVEBUILDPATH}\HeuristicLab.Clients.Hive.SlaveCore-3.3.dll"
     
    8284
    8385  nsExec::ExecToLog '"$INSTDIR\HeuristicLab.Clients.Hive.Slave.WindowsService.exe" --uninstall'
    84    
    85   Delete $INSTDIR\HeuristicLab.Clients.Hive.Slave.WindowsService.exe
    86   Delete $INSTDIR\HeuristicLab.Clients.Common-3.3.dll
    87   Delete $INSTDIR\HeuristicLab.Clients.Hive.Slave.WindowsService.exe.config
    88   Delete $INSTDIR\HeuristicLab.Clients.Hive.SlaveCore-3.3.dll
    89   Delete $INSTDIR\HeuristicLab.Clients.Hive-3.3.dll
    90   Delete $INSTDIR\HeuristicLab.Collections-3.3.dll
    91   Delete $INSTDIR\HeuristicLab.Common.Resources-3.3.dll
    92   Delete $INSTDIR\HeuristicLab.Common-3.3.dll
    93   Delete $INSTDIR\HeuristicLab.Core-3.3.dll
    94   Delete $INSTDIR\HeuristicLab.Data-3.3.dll
    95   Delete $INSTDIR\HeuristicLab.Hive-3.3.dll
    96   Delete $INSTDIR\HeuristicLab.MainForm-3.3.dll
    97   Delete $INSTDIR\HeuristicLab.Optimization-3.3.dll
    98   Delete $INSTDIR\HeuristicLab.Parameters-3.3.dll
    99   Delete $INSTDIR\HeuristicLab.Persistence-3.3.dll
    100   Delete $INSTDIR\HeuristicLab.PluginInfrastructure-3.3.dll
    101   Delete $INSTDIR\HeuristicLab.Tracing-3.3.dll
    102   Delete $INSTDIR\uninstall.exe
    10386
    104   RMDir "$INSTDIR"
     87  RMDir /r "$INSTDIR"
    10588SectionEnd
    10689
Note: See TracChangeset for help on using the changeset viewer.