Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/21 16:41:42 (3 years ago)
Author:
gkronber
Message:

#3073 refactoring to prepare for trunk reintegration

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  
        11bin
         2TestResults
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs

    r17887 r17891  
    66namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    77  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,
    1010      ISymbolicExpressionTree solution) {
    11       var variableRanges = intervalCollection.GetReadonlyDictionary();
     11      return constraints.Select(constraint => GetConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList();
     12    }
    1213
    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)) {
    1420        throw new ArgumentException(
    1521          $"The given variable {constraint.Variable} in the constraint does not exist in the model.",
    16           nameof(ShapeConstraintsParser));
     22          nameof(constraint));
    1723      }
    1824
    19       //Create new variable ranges for defined regions
     25      // Create new variable ranges for defined regions
    2026      var regionRanges = new IntervalCollection();
    21       foreach (var kvp in variableRanges) {
    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)) {
    2329          regionRanges.AddInterval(kvp.Key, val);
    2430        } else {
     
    2733      }
    2834
    29       var error = 0.0;
    3035      if (!constraint.IsDerivative) {
    31         error = estimator.CheckConstraint(solution, regionRanges, constraint);
     36        return estimator.GetConstraintViolation(tree, regionRanges, constraint);
    3237      } else {
    33         var tree = solution;
    3438        for (var i = 0; i < constraint.NumberOfDerivations; ++i) {
    3539          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.");
    3741          }
    3842
     
    4044        }
    4145
    42         error = estimator.CheckConstraint(tree, regionRanges, constraint);
     46        return estimator.GetConstraintViolation(tree, regionRanges, constraint);
    4347      }
    44 
    45       return error;
    4648    }
    4749
    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     }
    5350  }
    5451}
Note: See TracChangeset for help on using the changeset viewer.