Changeset 16895 for branches/2971_named_intervals
- Timestamp:
- 05/06/19 13:01:29 (6 years ago)
- 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 124 124 } 125 125 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 175 126 #endregion 176 127 … … 198 149 if (!double.IsNaN(value)) { 199 150 Content.Interval = new Interval(value, Content.Interval.UpperBound); 200 var exp = UpdateExpression(Content);201 Content.Name = exp;202 Content.Expression = exp;203 151 } 204 152 } … … 226 174 if (!double.IsNaN(value)) { 227 175 Content.Interval = new Interval(Content.Interval.LowerBound, value); 228 var exp = UpdateExpression(Content);229 Content.Name = exp;230 Content.Expression = exp;231 176 } 232 177 } … … 234 179 private void incllowerboundInput_CheckedChanged(object sender, EventArgs e) { 235 180 Content.InclusiveLowerBound = incllowerboundInput.Checked; 236 var exp = UpdateExpression(Content);237 Content.Name = exp;238 Content.Expression = exp;239 181 } 240 182 241 183 private void inclupperboundInput_CheckedChanged(object sender, EventArgs e) { 242 184 Content.InclusiveUpperBound = inclupperboundInput.Checked; 243 var exp = UpdateExpression(Content);244 Content.Name = exp;245 Content.Expression = exp;246 185 } 247 186 … … 257 196 else if ((int)numberderivationInput.SelectedItem == 3) 258 197 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;265 198 } 266 199 -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs
r16886 r16895 27 27 [StorableType("8109BE58-CCFB-4462-A2F4-EEE5DFADAFF7")] 28 28 [Item("Interval Constraint", "Constraint on intervals.")] 29 public class IntervalConstraint : NamedItem {29 public sealed class IntervalConstraint : Item { 30 30 private string expression; 31 31 [Storable] 32 32 public string Expression { 33 33 get => expression; 34 set {35 if ( value != expression) {34 private set { 35 if (expression != value) { 36 36 expression = value; 37 OnChanged( EventArgs.Empty);38 }39 }40 }41 private string definition;42 [Storable] 37 OnChanged(); 38 OnToStringChanged(); 39 } 40 } 41 } 42 43 43 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 } 54 91 private bool inclusiveLowerBound; 55 92 [Storable] … … 57 94 get => inclusiveLowerBound; 58 95 set { 59 if ( value != inclusiveLowerBound) {96 if (inclusiveLowerBound != value) { 60 97 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(); 90 114 } 91 115 } … … 99 123 if (value != enabled) { 100 124 enabled = value; 101 OnChanged( EventArgs.Empty);125 OnChanged(); 102 126 } 103 127 } … … 105 129 106 130 [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; 121 142 } 122 143 … … 125 146 } 126 147 127 pr otectedIntervalConstraint(IntervalConstraint original, Cloner cloner)148 private IntervalConstraint(IntervalConstraint original, Cloner cloner) 128 149 : base(original, cloner) { 129 150 this.Expression = original.Expression; 130 this.Definition = original.Definition;131 151 this.Interval = original.Interval; 132 152 this.InclusiveLowerBound = original.InclusiveLowerBound; 133 153 this.InclusiveUpperBound = original.InclusiveUpperBound; 134 this.IsDerivation = original.IsDerivation;135 154 this.Variable = original.Variable; 136 155 this.NumberOfDerivation = original.NumberOfDerivation; … … 139 158 140 159 public event EventHandler Changed; 141 pr otected virtual void OnChanged(EventArgs e) {160 private void OnChanged() { 142 161 EventHandler handlers = Changed; 143 162 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; 145 212 } 146 213 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraintsParser.cs
r16881 r16895 59 59 var interval = new Interval(lowerBound, upperBound); 60 60 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); 63 62 64 63 yield return constraint; … … 106 105 var interval = new Interval(lowerBound, upperBound); 107 106 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); 110 108 111 109 yield return constraint;
Note: See TracChangeset
for help on using the changeset viewer.