- Timestamp:
- 11/25/19 13:39:43 (5 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
r17368 r17370 71 71 } 72 72 73 public bool Contains(Interval other, bool lowerBoundInclusive = true, bool upperBoundInclusive = false) { 74 if (double.IsNegativeInfinity(this.LowerBound) && double.IsPositiveInfinity(this.UpperBound)) 75 return true; 76 //Left-unbounded and right-bounded: 77 if (double.IsNegativeInfinity(this.LowerBound)) { 78 if (upperBoundInclusive) 79 return other.LowerBound <= this.UpperBound && other.UpperBound <= this.UpperBound; 80 return other.LowerBound < this.UpperBound && other.UpperBound < this.UpperBound; 81 } 82 83 //Left-bounded and right-unbounded: 84 if (double.IsPositiveInfinity(this.UpperBound)) { 85 if (lowerBoundInclusive) 86 return other.LowerBound >= this.LowerBound && other.UpperBound >= this.LowerBound; 87 return other.LowerBound > this.LowerBound && other.UpperBound > this.LowerBound; 88 } 89 90 //Proper and bounded: 91 //Closed: 92 if (lowerBoundInclusive && upperBoundInclusive) { 93 return this.LowerBound <= other.LowerBound && other.UpperBound <= this.UpperBound; 94 } 95 96 //Open: 97 if (!lowerBoundInclusive && !upperBoundInclusive) { 98 return this.LowerBound < other.LowerBound && other.UpperBound < this.UpperBound; 99 } 100 101 //Left-closed, right-open: 102 if (lowerBoundInclusive) { 103 return this.LowerBound <= other.LowerBound && other.UpperBound < this.UpperBound; 104 } 105 106 //Left-open, right-closed: 107 return this.LowerBound < other.LowerBound && other.UpperBound <= this.UpperBound; 73 public bool Contains(Interval other) { 74 if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true; 75 if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true; 76 77 return false; 108 78 } 109 79 -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraint.cs
r16964 r17370 98 98 99 99 [Storable] 100 private bool inclusiveLowerBound;101 public bool InclusiveLowerBound {102 get => inclusiveLowerBound;103 set {104 if (inclusiveLowerBound == value) return;105 inclusiveLowerBound = value;106 UpdateExpression();107 OnChanged();108 }109 }110 111 [Storable]112 private bool inclusiveUpperBound;113 public bool InclusiveUpperBound {114 get => inclusiveUpperBound;115 set {116 if (inclusiveUpperBound == value) return;117 inclusiveUpperBound = value;118 UpdateExpression();119 OnChanged();120 }121 }122 123 [Storable]124 100 private bool enabled; 125 101 public bool Enabled { … … 135 111 private IntervalConstraint(StorableConstructorFlag _) : base(_) { } 136 112 137 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivation, Interval interval, bool inclusiveLowerBound, 138 bool inclusiveUpperBound, bool enabled) : base(){ 113 public IntervalConstraint(string expression, string variable, string target, int numberOfDerivation, Interval interval, bool enabled) : base(){ 139 114 this.expression = expression; 140 115 this.variable = variable; … … 142 117 this.numberOfDerivation = numberOfDerivation; 143 118 this.interval = interval; 144 this.inclusiveLowerBound = inclusiveLowerBound;145 this.inclusiveUpperBound = inclusiveUpperBound;146 119 this.enabled = enabled; 147 120 } … … 158 131 this.NumberOfDerivation = original.NumberOfDerivation; 159 132 this.Interval = original.Interval; 160 this.InclusiveLowerBound = original.InclusiveLowerBound;161 this.InclusiveUpperBound = original.InclusiveUpperBound;162 133 this.Enabled = original.Enabled; 163 134 } … … 189 160 expression = string.Format("Target:{0} in {1}{2} .. {3}{4}", 190 161 Variable, 191 (InclusiveLowerBound) ? "[" : "]",162 "[", 192 163 Interval?.LowerBound, 193 164 Interval?.UpperBound, 194 (InclusiveUpperBound) ? "]" : "[");165 "]"); 195 166 Expression = expression; 196 167 return; … … 199 170 Variable, 200 171 Target, 201 (InclusiveLowerBound) ? "[" : "]",172 "[", 202 173 Interval?.LowerBound, 203 174 Interval?.UpperBound, 204 (InclusiveUpperBound) ? "]" : "[",175 "]", 205 176 GetDerivationString(numberOfDerivation)); 206 177 Expression = expression; -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r17250 r17370 33 33 if (string.IsNullOrEmpty(target)) throw new ArgumentNullException("No target variable has been provided."); 34 34 if (variables == null) throw new ArgumentNullException("No variables have been provided."); 35 if (!variables.Any()) throw new ArgumentException("Varia lbes are empty.");35 if (!variables.Any()) throw new ArgumentException("Variables are empty."); 36 36 37 37 var lines = inputText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); … … 44 44 var targetConstraint = trimmedLine.Substring(start, end - start); 45 45 var match = Regex.Match(targetConstraint, 46 @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[ \]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");46 @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])"); 47 47 if (match.Success) { 48 48 if (match.Groups.Count != 10) { … … 63 63 var parsedTarget = match.Groups[1].Value.Trim(); 64 64 var variable = targetVariable; 65 var inclLowerBound = match.Groups[5].Value.Trim() == "[";66 var inclUpperBound = match.Groups[9].Value.Trim() == "]";67 65 var isEnabled = true; 68 66 var numberOfDerivation = 0; 69 67 var interval = new Interval(lowerBound, upperBound); 70 68 71 var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, i nclLowerBound, inclUpperBound, isEnabled);69 var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 72 70 73 71 yield return constraint; … … 79 77 } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("\u2202")) { 80 78 var match = Regex.Match(trimmedLine, 81 @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[ \]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");79 @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\]])"); 82 80 83 81 if (match.Success) { … … 115 113 var parsedTarget = derivationTarget; 116 114 var isEnabled = true; 117 var inclLowerBound = match.Groups[12].Value.Trim() == "[";118 var inclUpperBound = match.Groups[16].Value.Trim() == "]";119 115 var variable = derivationVariable; 120 116 var numberOfDerivation = ParseDerivationCount(match.Groups[2].Value.Trim()); 121 117 var interval = new Interval(lowerBound, upperBound); 122 118 123 var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, i nclLowerBound, inclUpperBound, isEnabled);119 var constraint = new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, isEnabled); 124 120 125 121 yield return constraint; -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/ProblemDataConstraint.cs
r17256 r17370 37 37 "# Example for constraint on model parameter: " + Environment.NewLine + 38 38 "d'y'/d'x' in [0 .. 10]" + Environment.NewLine + 39 "∂²'y'/∂'x'² in ]-1 .. inf.[";39 "∂²'y'/∂'x'² in [-1 .. inf.]"; 40 40 41 41 [Storable]
Note: See TracChangeset
for help on using the changeset viewer.