Changeset 17891 for branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
- Timestamp:
- 03/12/21 16:41:42 (3 years ago)
- Location:
- branches/3073_IA_constraint_splitting_reintegration
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting_reintegration
- Property svn:ignore
-
old new 1 1 bin 2 TestResults
-
- Property svn:ignore
-
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
r17887 r17891 6 6 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 7 7 public static class IntervalUtil { 8 public static double IntervalConstraintViolation(9 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection,8 public static IEnumerable<double> GetConstraintViolations( 9 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection, 10 10 ISymbolicExpressionTree solution) { 11 var variableRanges = intervalCollection.GetReadonlyDictionary(); 11 return constraints.Select(constraint => GetConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList(); 12 } 12 13 13 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) { 14 public static double GetConstraintViolation( 15 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection variableRanges, 16 ISymbolicExpressionTree tree) { 17 var varRanges = variableRanges.GetReadonlyDictionary(); 18 19 if (constraint.Variable != null && !varRanges.ContainsKey(constraint.Variable)) { 14 20 throw new ArgumentException( 15 21 $"The given variable {constraint.Variable} in the constraint does not exist in the model.", 16 nameof( ShapeConstraintsParser));22 nameof(constraint)); 17 23 } 18 24 19 // Create new variable ranges for defined regions25 // Create new variable ranges for defined regions 20 26 var regionRanges = new IntervalCollection(); 21 foreach (var kvp in var iableRanges) {22 if ( kvp.Key != constraint.Target &&constraint.Regions.GetReadonlyDictionary().TryGetValue(kvp.Key, out var val)) {27 foreach (var kvp in varRanges) { 28 if (constraint.Regions.GetReadonlyDictionary().TryGetValue(kvp.Key, out var val)) { 23 29 regionRanges.AddInterval(kvp.Key, val); 24 30 } else { … … 27 33 } 28 34 29 var error = 0.0;30 35 if (!constraint.IsDerivative) { 31 error = estimator.CheckConstraint(solution, regionRanges, constraint);36 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 32 37 } else { 33 var tree = solution;34 38 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 35 39 if (!estimator.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) { 36 throw new ArgumentException(" Cube, Root, Power symbols are not supported.");40 throw new ArgumentException("The tree contains an unsupported symbol."); 37 41 } 38 42 … … 40 44 } 41 45 42 error = estimator.CheckConstraint(tree, regionRanges, constraint);46 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 43 47 } 44 45 return error;46 48 } 47 49 48 public static IEnumerable<double> IntervalConstraintsViolation(49 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection,50 ISymbolicExpressionTree solution) {51 return constraints.Select(constraint => IntervalConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList();52 }53 50 } 54 51 }
Note: See TracChangeset
for help on using the changeset viewer.