- Timestamp:
- 03/16/21 14:23:41 (3 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
r17884 r17902 1 using System; 1 #region License Information 2 3 /* HeuristicLab 4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #endregion 23 using System; 2 24 using System.Collections.Generic; 3 25 using System.Linq; … … 6 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 7 29 public static class IntervalUtil { 8 public static double IntervalConstraintViolation(9 I ntervalConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection,30 public static IEnumerable<double> GetConstraintViolations( 31 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection, 10 32 ISymbolicExpressionTree solution) { 11 var variableRanges = intervalCollection.GetReadonlyDictionary(); 33 return constraints.Select(constraint => GetConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList(); 34 } 12 35 13 if (constraint.Variable != null && !variableRanges.ContainsKey(constraint.Variable)) { 36 public static double GetConstraintViolation( 37 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection variableRanges, 38 ISymbolicExpressionTree tree) { 39 var varRanges = variableRanges.GetReadonlyDictionary(); 40 41 if (constraint.Variable != null && !varRanges.ContainsKey(constraint.Variable)) { 14 42 throw new ArgumentException( 15 43 $"The given variable {constraint.Variable} in the constraint does not exist in the model.", 16 nameof( IntervalConstraintsParser));44 nameof(constraint)); 17 45 } 18 46 19 // Create new variable ranges for defined regions47 // Create new variable ranges for defined regions 20 48 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)) {49 foreach (var kvp in varRanges) { 50 if (constraint.Regions.GetReadonlyDictionary().TryGetValue(kvp.Key, out var val)) { 23 51 regionRanges.AddInterval(kvp.Key, val); 24 52 } else { … … 27 55 } 28 56 29 var error = 0.0;30 57 if (!constraint.IsDerivative) { 31 error = estimator.CheckConstraint(solution, regionRanges, constraint);58 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 32 59 } else { 33 var tree = solution;34 60 for (var i = 0; i < constraint.NumberOfDerivations; ++i) { 35 61 if (!estimator.IsCompatible(tree) || !DerivativeCalculator.IsCompatible(tree)) { 36 throw new ArgumentException(" Cube, Root, Power symbols are not supported.");62 throw new ArgumentException("The tree contains an unsupported symbol."); 37 63 } 38 64 … … 40 66 } 41 67 42 error = estimator.CheckConstraint(tree, regionRanges, constraint);68 return estimator.GetConstraintViolation(tree, regionRanges, constraint); 43 69 } 44 45 return error;46 }47 48 public static IEnumerable<double> IntervalConstraintsViolation(49 IEnumerable<IntervalConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection,50 ISymbolicExpressionTree solution) {51 return constraints.Select(constraint => IntervalConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList();52 70 } 53 71 }
Note: See TracChangeset
for help on using the changeset viewer.