Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17822


Ignore:
Timestamp:
01/20/21 09:26:09 (3 years ago)
Author:
chaider
Message:

#3073 Fixed double parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r17818 r17822  
    2424using System;
    2525using System.Collections.Generic;
    26 using System.Globalization;
    2726using System.Linq;
    2827using System.Text.RegularExpressions;
     28using HeuristicLab.Data;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis {
     
    8989
    9090            if (match.Groups[18].Success && !string.IsNullOrWhiteSpace(match.Groups[18].Value))
    91               weight = ParseWeight(match.Groups[18].Value);
     91              weight = ParseAndValidateDouble(match.Groups[18].Value);
    9292
    9393            if (match.Groups[10].Success)
     
    180180
    181181            if(match.Groups[25].Success && !string.IsNullOrWhiteSpace(match.Groups[25].Value))
    182               weight = ParseWeight(match.Groups[25].Value);
     182              weight = ParseAndValidateDouble(match.Groups[25].Value);
    183183
    184184            if(match.Groups[17].Success)
     
    222222      var regionUb = ParseIntervalBounds(ub);
    223223      return new KeyValuePair<string, Interval>(variable, new Interval(regionLb, regionUb));
    224       //return new Region(variable, new Interval(regionLb, regionUb));
    225224    }
    226225
     
    234233          return double.NegativeInfinity;
    235234        default: {
    236           if (double.TryParse(input.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
    237             return value;
    238           throw new ArgumentException("The given boundary is not a double value!");
    239         }
    240       }
    241     }
    242 
    243     private static double ParseWeight(string input)
    244     {
    245       if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
    246         return value;
    247       throw new ArgumentException("The given weight is not a double value!");
     235          return ParseAndValidateDouble(input);
     236        }
     237      }
     238    }
     239
     240    private static double ParseAndValidateDouble(string input) {
     241      var valid = double.TryParse(input, out var value);
     242      if (!valid) {
     243        throw new ArgumentException("Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")");
     244      }
     245
     246      return value;
    248247    }
    249248
Note: See TracChangeset for help on using the changeset viewer.