Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/20 10:16:11 (4 years ago)
Author:
dpiringe
Message:

#3073

  • added new class Region and refactored the relevant code in IntervalConstraint and IntervalConstraintsParser
  • added the .editorconfig file from trunk (to satisfy the coding guidelines)
File:
1 edited

Legend:

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

    r17736 r17765  
    9393            if (match.Groups[10].Success)
    9494            {
    95               IDictionary<string, Interval> pairs = new Dictionary<string, Interval>();
     95              IList<Region> regions = new List<Region>();
    9696              // option variables found
    9797              for(int idx = 0; idx < match.Groups[10].Captures.Count; ++idx)
    9898              {
    99                 AddRegion(pairs,
     99                Region region = ParseRegion(
    100100                  match.Groups[11].Captures[idx].Value,
    101101                  match.Groups[13].Captures[idx].Value,
    102102                  match.Groups[15].Captures[idx].Value);
     103                if(!regions.Any(r => r.VariableName == region.VariableName))
     104                  regions.Add(region);
     105                else
     106                  throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
    103107              }
    104               yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);
     108              yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, regions, weight, isEnabled);
    105109            }
    106110            else
     
    180184            if(match.Groups[17].Success)
    181185            {
    182               IDictionary<string, Interval> pairs = new Dictionary<string, Interval>();
     186              IList<Region> regions = new List<Region>();
    183187              // option variables found
    184188              for (int idx = 0; idx < match.Groups[17].Captures.Count; ++idx)
    185189              {
    186                 AddRegion(pairs,
    187                   match.Groups[18].Captures[idx].Value, 
    188                   match.Groups[20].Captures[idx].Value, 
     190                Region region = ParseRegion(
     191                  match.Groups[18].Captures[idx].Value,
     192                  match.Groups[20].Captures[idx].Value,
    189193                  match.Groups[22].Captures[idx].Value);
     194                if (!regions.Any(r => r.VariableName == region.VariableName))
     195                  regions.Add(region);
     196                else
     197                  throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
    190198              }
    191               yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);
     199              yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, regions, weight, isEnabled);
    192200            } else
    193201              yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, weight, isEnabled);
     
    209217    }
    210218
    211     private static void AddRegion(IDictionary<string, Interval> dict, string variable, string lb, string ub)
     219    private static Region ParseRegion(string variable, string lb, string ub)
    212220    {
    213221      var regionLb = ParseIntervalBounds(lb);
    214222      var regionUb = ParseIntervalBounds(ub);
    215       if (dict.ContainsKey(variable))
    216         throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
    217       dict.Add(variable, new Interval(regionLb, regionUb));
     223      return new Region(variable, new Interval(regionLb, regionUb));
    218224    }
    219225
Note: See TracChangeset for help on using the changeset viewer.