Changeset 17995 for branches/3119_AdditionalShapeConstraintFeatures/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 06/22/21 18:28:36 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3119_AdditionalShapeConstraintFeatures/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
r17906 r17995 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 29 public static class IntervalUtil { 30 public static IEnumerable<Interval> GetModelBounds( 31 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection, 32 ISymbolicExpressionTree solution) { 33 return constraints.Select(constraint => GetModelBound(constraint, estimator, intervalCollection, solution)).ToList(); 34 } 35 36 public static Interval GetModelBound( 37 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection variableRanges, 38 ISymbolicExpressionTree tree) { 39 var regionRanges = GetRegionRanges(constraint, variableRanges); 40 tree = DeriveTree(tree, constraint, estimator); 41 return estimator.GetModelBound(tree, regionRanges); 42 } 43 30 44 public static IEnumerable<double> GetConstraintViolations( 31 45 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection, … … 37 51 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection variableRanges, 38 52 ISymbolicExpressionTree tree) { 53 54 var regionRanges = GetRegionRanges(constraint, variableRanges); 55 tree = DeriveTree(tree, constraint, estimator); 56 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 57 /* 58 if (!constraint.IsDerivative) { 59 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 60 } else { 61 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 62 if (!estimator.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) { 63 throw new ArgumentException("The tree contains an unsupported symbol."); 64 } 65 66 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 67 } 68 69 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 70 } 71 */ 72 } 73 74 private static ISymbolicExpressionTree DeriveTree(ISymbolicExpressionTree tree, ShapeConstraint constraint, IBoundsEstimator estimator) { 75 if (constraint.IsDerivative) { 76 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 77 if (!estimator.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) 78 throw new ArgumentException("The tree contains an unsupported symbol."); 79 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 80 } 81 } 82 return tree; 83 } 84 85 private static IntervalCollection GetRegionRanges(ShapeConstraint constraint, IntervalCollection variableRanges) { 39 86 var varRanges = variableRanges.GetReadonlyDictionary(); 40 87 … … 55 102 } 56 103 57 if (!constraint.IsDerivative) { 58 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 59 } else { 60 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 61 if (!estimator.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) { 62 throw new ArgumentException("The tree contains an unsupported symbol."); 63 } 64 65 tree = DerivativeCalculator.Derive(tree, constraint.Variable); 66 } 67 68 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 69 } 104 return regionRanges; 70 105 } 71 106 }
Note: See TracChangeset
for help on using the changeset viewer.