- Timestamp:
- 02/06/19 14:37:02 (6 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/NamedIntervals.cs
r16588 r16590 13 13 [Item("NamedIntervals", "Represents variables with their interval ranges.")] 14 14 [StorableClass] 15 public class NamedIntervals : Item { 15 public class NamedIntervals : Item { 16 16 Dictionary<string, Interval> variableIntervals = new Dictionary<string, Interval>(); 17 17 public Dictionary<string, Interval> VariableIntervals => variableIntervals; 18 18 19 19 [Storable(Name = "StorableIntervalInformation")] 20 private IEnumerable<Tuple<string, double, double>>StorableIntervalInformation {20 private KeyValuePair<string, double[]>[] StorableIntervalInformation { 21 21 get { 22 var l = new List<KeyValuePair<string, double[]>>(); 22 23 foreach (var varInt in variableIntervals) 23 yield return Tuple.Create(varInt.Key, varInt.Value.LowerBound, varInt.Value.UpperBound); 24 25 l.Add(new KeyValuePair<string, double[]>(varInt.Key, 26 new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound })); 27 return l.ToArray(); 24 28 } 25 29 26 30 set { 27 31 foreach (var varInt in value) 28 variableIntervals.Add(varInt. Item1,new Interval(varInt.Item2,varInt.Item3));32 variableIntervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1])); 29 33 } 30 34 } 31 35 32 public NamedIntervals() : base() {}36 public NamedIntervals() : base() { } 33 37 protected NamedIntervals(bool deserializing) : base(deserializing) { } 34 38 … … 62 66 return true; 63 67 } 64 68 65 69 } 66 70 } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraint.cs
r16587 r16590 7 7 namespace HeuristicLab.Problems.DataAnalysis { 8 8 public class IntervalConstraint { 9 public string Derivaiton { get; set; } 9 10 public string Definition { get; set; } 10 11 public Interval Interval { get; set; } -
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Parser/IntervalConstraintsParser.cs
r16587 r16590 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Globalization; 3 4 using System.IO; 4 5 using System.Linq; … … 14 15 public List<IntervalConstraint> Parse(string input) { 15 16 var options = RegexOptions.Multiline | RegexOptions.IgnoreCase; 16 var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r? $", options);17 var matches = Regex.Matches(input, @"^(.*)\bin\b\s*([\[\]])(.*[^\s])(\s*\.\.\s*)([^\s].*)([\[\]])\r?\s*$", options); 17 18 18 19 for (var i = 0; i < matches.Count; ++i) { … … 22 23 var definition = Regex.Replace(matches[i].Groups[1].Value, @"\s *", ""); 23 24 if (Regex.IsMatch(definition, @"\/")) { 24 var splitted = Regex.Split(definition. ToLower().Replace(" ", string.Empty), @"\/");25 var splitted = Regex.Split(definition.Replace(" ", string.Empty), @"\/"); 25 26 var match = Regex.Match(splitted[0], @"([d∂])([0-9]|[²³])?(.*[^\s*])"); 26 27 if (match.Success) { … … 28 29 intervalConstraint.Definition = match.Groups[3].Value; 29 30 intervalConstraint.IsDerivation = true; 30 var formulation = Regex.Match(splitted[1], @"([d∂])(.*[^ \s*][^²³])([²³])?");31 var formulation = Regex.Match(splitted[1], @"([d∂])(.*[^²³])([²³])?"); 31 32 if (formulation.Success) { 32 33 intervalConstraint.Variable = formulation.Groups[2].Success ? formulation.Groups[2].Value : ""; … … 38 39 intervalConstraint.Definition = Regex.Match(definition, @".*[^.\s]*").Value; 39 40 intervalConstraint.IsDerivation = false; 40 } 41 } 42 intervalConstraint.Derivaiton = matches[i].Groups[0].Value; 41 43 intervalConstraint.InclusiveLowerBound = (matches[i].Groups[2].Value == "["); 42 44 intervalConstraint.InclusiveUpperBound = (matches[i].Groups[6].Value == "]"); … … 62 64 return double.NegativeInfinity; 63 65 default: { 64 if (double.TryParse(input, out var value)) {66 if (double.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { 65 67 return value; 66 68 } else {
Note: See TracChangeset
for help on using the changeset viewer.