Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/19 13:01:29 (6 years ago)
Author:
chaider
Message:

#2971 Changed IntervalConstraint

Location:
branches/2971_named_intervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/IntervalConstraintView.cs

    r16885 r16895  
    124124    }
    125125
    126     private static string UpdateExpression(IntervalConstraint constraint) {
    127       var expression = "";
    128 
    129       if (!constraint.IsDerivation) {
    130         expression = string.Format("{0} in {1}{2} .. {3}{4}",
    131           constraint.Variable,
    132           (constraint.InclusiveLowerBound) ? "[" : "]",
    133           constraint.Interval.LowerBound,
    134           constraint.Interval.UpperBound,
    135           (constraint.InclusiveUpperBound) ? "]" : "[");
    136       } else {
    137         expression = string.Format("\u2202{5}Target/\u2202{0}{6} in {1}{2} .. {3}{4}",
    138           constraint.Variable,
    139           (constraint.InclusiveLowerBound) ? "[" : "]",
    140           constraint.Interval.LowerBound,
    141           constraint.Interval.UpperBound,
    142           (constraint.InclusiveUpperBound) ? "]" : "[",
    143           GetDerivationString(constraint.numberOfDerivation),
    144           GetDerivationString(constraint.numberOfDerivation));
    145       }
    146 
    147       return expression;
    148     }
    149 
    150     private static string UpdateDefintion(IntervalConstraint constraint) {
    151       var definition = "";
    152 
    153       if (!constraint.IsDerivation) {
    154         return "Target " + constraint.Variable;
    155       }
    156 
    157       definition = $"\u2202{GetDerivationString(constraint.numberOfDerivation)}Target/\u2202{constraint.Variable}{GetDerivationString(constraint.numberOfDerivation)}";
    158 
    159       return definition;
    160     }
    161 
    162     private static string GetDerivationString(int derivation) {
    163       switch (derivation) {
    164         case 1:
    165           return "";
    166         case 2:
    167           return "²";
    168         case 3:
    169           return "³";
    170         default:
    171           return "";
    172       }
    173     }
    174 
    175126    #endregion
    176127
     
    198149      if (!double.IsNaN(value)) {
    199150        Content.Interval = new Interval(value, Content.Interval.UpperBound);
    200         var exp = UpdateExpression(Content);
    201         Content.Name = exp;
    202         Content.Expression = exp;
    203151      }
    204152    }
     
    226174      if (!double.IsNaN(value)) {
    227175        Content.Interval = new Interval(Content.Interval.LowerBound, value);
    228         var exp = UpdateExpression(Content);
    229         Content.Name = exp;
    230         Content.Expression = exp;
    231176      }
    232177    }
     
    234179    private void incllowerboundInput_CheckedChanged(object sender, EventArgs e) {
    235180        Content.InclusiveLowerBound = incllowerboundInput.Checked;
    236         var exp = UpdateExpression(Content);
    237         Content.Name = exp;
    238         Content.Expression = exp;
    239181    }
    240182
    241183    private void inclupperboundInput_CheckedChanged(object sender, EventArgs e) {
    242184        Content.InclusiveUpperBound = inclupperboundInput.Checked;
    243         var exp = UpdateExpression(Content);
    244         Content.Name = exp;
    245         Content.Expression = exp;
    246185    }
    247186
     
    257196      else if ((int)numberderivationInput.SelectedItem == 3)
    258197        Content.numberOfDerivation = 3;
    259 
    260       var exp = UpdateExpression(Content);
    261       var def = UpdateDefintion(Content);
    262       Content.Name = exp;
    263       Content.Expression = exp;
    264       Content.Definition = def;
    265198    }
    266199
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs

    r16886 r16895  
    2727  [StorableType("8109BE58-CCFB-4462-A2F4-EEE5DFADAFF7")]
    2828  [Item("Interval Constraint", "Constraint on intervals.")]
    29   public class IntervalConstraint : NamedItem {
     29  public sealed class IntervalConstraint : Item {
    3030    private string expression;
    3131    [Storable]
    3232    public string Expression {
    3333      get => expression;
    34       set {
    35         if (value != expression) {
     34      private set {
     35        if (expression != value) {
    3636          expression = value;
    37           OnChanged(EventArgs.Empty);
    38         }
    39       }
    40     }
    41     private string definition;
    42     [Storable]
     37          OnChanged();
     38          OnToStringChanged();
     39        }
     40      }
     41    }
     42
    4343    public string Definition {
    44       get => definition;
    45       set {
    46         if (value != definition) {
    47           definition = value;
    48           OnChanged(EventArgs.Empty);
    49         }
    50       }
    51     }
    52     [Storable]
    53     public Interval Interval { get; set; }
     44      get { return GetDefinitionString(); }
     45    }
     46
     47    private string variable;
     48    [Storable]
     49    public string Variable {
     50      get => variable;
     51      private set {
     52        if (variable != value) {
     53          variable = value;
     54          UpdateExpression();
     55          OnChanged();
     56        }
     57      }
     58    }
     59
     60    public bool IsDerivation {
     61      get => numberOfDerivation > 0;
     62    }
     63
     64    public int numberOfDerivation;
     65    [Storable]
     66    public int NumberOfDerivation {
     67      get => numberOfDerivation;
     68      set {
     69        if (value < 0 || value > 3)
     70          throw new ArgumentException("Number of derivation has to be between 0 - 3.");
     71        if (value != numberOfDerivation) {
     72          numberOfDerivation = value;
     73          UpdateExpression();
     74          OnChanged();
     75        }
     76      }
     77    }
     78
     79    private Interval interval;
     80    [Storable]
     81    public Interval Interval {
     82      get => interval;
     83      set {
     84        if (interval != value) {
     85          interval = value;
     86          UpdateExpression();
     87          OnChanged();
     88        }
     89      }
     90    }
    5491    private bool inclusiveLowerBound;
    5592    [Storable]
     
    5794      get => inclusiveLowerBound;
    5895      set {
    59         if (value != inclusiveLowerBound) {
     96        if (inclusiveLowerBound != value) {
    6097          inclusiveLowerBound = value;
    61           OnChanged(EventArgs.Empty);
    62         }
    63       }
    64     }
    65     [Storable]
    66     public bool InclusiveUpperBound { get; set; }
    67     [Storable]
    68     public bool IsDerivation { get; set; }
    69 
    70     private string variable;
    71     [Storable]
    72     public string Variable {
    73       get => variable;
    74       set {
    75         if (value != variable) {
    76           variable = value;
    77           OnChanged(EventArgs.Empty);
    78         }
    79       }
    80     }
    81 
    82     public int numberOfDerivation;
    83     [Storable]
    84     public int NumberOfDerivation {
    85       get => numberOfDerivation;
    86       set {
    87         if (value != numberOfDerivation) {
    88           numberOfDerivation = value;
    89           OnChanged(EventArgs.Empty);
     98          UpdateExpression();
     99          OnChanged();
     100        }
     101      }
     102    }
     103
     104    private bool inclusiveUpperBound;
     105
     106    [Storable]
     107    public bool InclusiveUpperBound {
     108      get => inclusiveUpperBound;
     109      set {
     110        if (inclusiveUpperBound != value) {
     111          inclusiveUpperBound = value;
     112          UpdateExpression();
     113          OnChanged();
    90114        }
    91115      }
     
    99123        if (value != enabled) {
    100124          enabled = value;
    101           OnChanged(EventArgs.Empty);
     125          OnChanged();
    102126        }
    103127      }
     
    105129
    106130    [StorableConstructor]
    107     protected IntervalConstraint(StorableConstructorFlag _) : base(_) { }
    108 
    109     public IntervalConstraint(string expression, string definition, Interval interval, bool inclusiveLowerBound,
    110       bool inclusiveUpperBound, bool isDerivation, string variable, int numberOfDerivation, bool isChecked) {
    111       base.name = expression;
    112       Expression = expression;
    113       Definition = definition;
    114       Interval = interval;
    115       InclusiveLowerBound = inclusiveLowerBound;
    116       InclusiveUpperBound = inclusiveUpperBound;
    117       IsDerivation = isDerivation;
    118       Variable = variable;
    119       NumberOfDerivation = numberOfDerivation;
    120       enabled = isChecked;
     131    private IntervalConstraint(StorableConstructorFlag _) : base(_) { }
     132
     133    public IntervalConstraint(string expression, string variable, int numberOfDerivation, Interval interval, bool inclusiveLowerBound,
     134      bool inclusiveUpperBound, bool enabled) : base(){
     135      this.expression = expression;
     136      this.variable = variable;
     137      this.numberOfDerivation = numberOfDerivation;
     138      this.interval = interval;
     139      this.inclusiveLowerBound = inclusiveLowerBound;
     140      this.inclusiveUpperBound = inclusiveUpperBound;
     141      this.enabled = enabled;
    121142    }
    122143
     
    125146    }
    126147
    127     protected IntervalConstraint(IntervalConstraint original, Cloner cloner)
     148    private IntervalConstraint(IntervalConstraint original, Cloner cloner)
    128149      : base(original, cloner) {
    129150      this.Expression = original.Expression;
    130       this.Definition = original.Definition;
    131151      this.Interval = original.Interval;
    132152      this.InclusiveLowerBound = original.InclusiveLowerBound;
    133153      this.InclusiveUpperBound = original.InclusiveUpperBound;
    134       this.IsDerivation = original.IsDerivation;
    135154      this.Variable = original.Variable;
    136155      this.NumberOfDerivation = original.NumberOfDerivation;
     
    139158
    140159    public event EventHandler Changed;
    141     protected virtual void OnChanged(EventArgs e) {
     160    private void OnChanged() {
    142161      EventHandler handlers = Changed;
    143162      if (handlers != null)
    144         handlers(this, e);
     163        handlers(this, EventArgs.Empty);
     164    }
     165
     166    private static string GetDerivationString(int derivation) {
     167      switch (derivation) {
     168        case 1:
     169          return "";
     170        case 2:
     171          return "²";
     172        case 3:
     173          return "³";
     174        default:
     175          return "";
     176      }
     177    }
     178
     179    private void UpdateExpression() {
     180      var expression = "";
     181
     182      if (!IsDerivation) {
     183        expression = string.Format("{0} in {1}{2} .. {3}{4}",
     184          Variable,
     185          (InclusiveLowerBound) ? "[" : "]",
     186          Interval.LowerBound,
     187          Interval.UpperBound,
     188          (InclusiveUpperBound) ? "]" : "[");
     189        Expression = expression;
     190        return;
     191      }
     192      expression = string.Format("\u2202{5}Target/\u2202{0}{5} in {1}{2} .. {3}{4}",
     193        Variable,
     194        (InclusiveLowerBound) ? "[" : "]",
     195        Interval.LowerBound,
     196        Interval.UpperBound,
     197        (InclusiveUpperBound) ? "]" : "[",
     198        GetDerivationString(numberOfDerivation));
     199        Expression = expression;
     200    }
     201
     202    private string GetDefinitionString() {
     203      if (!IsDerivation) {
     204        return "Target " + Variable;
     205      }
     206      var definition = $"\u2202{GetDerivationString(numberOfDerivation)}Target/\u2202{Variable}{GetDerivationString(numberOfDerivation)}";
     207      return definition;
     208    }
     209
     210    public override string ToString() {
     211      return Expression;
    145212    }
    146213  }
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraintsParser.cs

    r16881 r16895  
    5959              var interval = new Interval(lowerBound, upperBound);
    6060
    61               var constraint = new IntervalConstraint(expression, definition, interval, inclLowerBound, inclUpperBound, isDerivation, variable, numberOfDerivation, true);
    62               constraint.Name = expression;
     61              var constraint = new IntervalConstraint(expression, variable, numberOfDerivation, interval, inclLowerBound, inclUpperBound, true);
    6362
    6463              yield return constraint;
     
    106105              var interval = new Interval(lowerBound, upperBound);
    107106
    108               var constraint = new IntervalConstraint(expression, definition, interval, inclLowerBound, inclUpperBound, isDerivation, variable, numberOfDerivation, true);
    109               constraint.Name = expression;
     107              var constraint = new IntervalConstraint(expression, variable, numberOfDerivation, interval, inclLowerBound, inclUpperBound, true);
    110108
    111109              yield return constraint;
Note: See TracChangeset for help on using the changeset viewer.