Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17736 for branches


Ignore:
Timestamp:
08/28/20 17:29:31 (4 years ago)
Author:
dpiringe
Message:

#3073

  • added a check in Interval/IntervalConstraintsParser to throw an exception for multiple variables with the same key
File:
1 edited

Legend:

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

    r17728 r17736  
    9797              for(int idx = 0; idx < match.Groups[10].Captures.Count; ++idx)
    9898              {
    99                 var inputVar = match.Groups[11].Captures[idx].Value;
    100                 var regionLb = ParseIntervalBounds(match.Groups[13].Captures[idx].Value);
    101                 var regionUb = ParseIntervalBounds(match.Groups[15].Captures[idx].Value);
    102                 pairs.Add(inputVar, new Interval(regionLb, regionUb));
     99                AddRegion(pairs,
     100                  match.Groups[11].Captures[idx].Value,
     101                  match.Groups[13].Captures[idx].Value,
     102                  match.Groups[15].Captures[idx].Value);
    103103              }
    104104              yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);
     
    184184              for (int idx = 0; idx < match.Groups[17].Captures.Count; ++idx)
    185185              {
    186                 var inputVar = match.Groups[18].Captures[idx].Value;
    187                 var regionLb = ParseIntervalBounds(match.Groups[20].Captures[idx].Value);
    188                 var regionUb = ParseIntervalBounds(match.Groups[22].Captures[idx].Value);
    189                 pairs.Add(inputVar, new Interval(regionLb, regionUb));
     186                AddRegion(pairs,
     187                  match.Groups[18].Captures[idx].Value,
     188                  match.Groups[20].Captures[idx].Value,
     189                  match.Groups[22].Captures[idx].Value);
    190190              }
    191191              yield return new IntervalConstraint(expression, variable, parsedTarget, numberOfDerivation, interval, pairs, weight, isEnabled);
     
    207207        }
    208208      }
     209    }
     210
     211    private static void AddRegion(IDictionary<string, Interval> dict, string variable, string lb, string ub)
     212    {
     213      var regionLb = ParseIntervalBounds(lb);
     214      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));
    209218    }
    210219
Note: See TracChangeset for help on using the changeset viewer.