Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17765


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)
Location:
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17607 r17765  
    192192    <Compile Include="Implementation\Interval\IntervalConstraint.cs" />
    193193    <Compile Include="Implementation\Interval\IntervalConstraintsParser.cs" />
     194    <Compile Include="Implementation\Interval\Region.cs" />
    194195    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    195196    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
     
    300301    <Compile Include="Implementation\Classification\ThresholdCalculators\NormalDistributionCutPointsThresholdCalculator.cs" />
    301302    <Compile Include="Implementation\Classification\ThresholdCalculators\ThresholdCalculator.cs" />
     303    <None Include=".editorconfig" />
    302304    <None Include="HeuristicLab.snk" />
    303305    <None Include="Plugin.cs.frame" />
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraint.cs

    r17728 r17765  
    115115
    116116    [Storable]
    117     private IDictionary<string, Interval> regions = new Dictionary<string, Interval>();
    118     public IDictionary<string, Interval> Regions
     117    private /*IDictionary<string, Interval>*/ IEnumerable<Region> regions; //= new Dictionary<string, Interval>();
     118    public IEnumerable<Region> Regions
    119119    {
    120120      get => regions;
     
    152152                              Interval interval, double weight, bool enabled)
    153153      : this(expression, variable, target, numberOfDerivations,
    154              interval, new Dictionary<string, Interval>(), weight, enabled) { }
     154             interval, new List<Region>(), weight, enabled) { }
    155155
    156156    public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations,
    157                               Interval interval, IDictionary<string, Interval> regions, double weight, bool enabled)
     157                              Interval interval, IEnumerable<Region> regions, double weight, bool enabled)
    158158    {
    159159      this.expression = expression;
     
    213213                                   Interval?.UpperBound,
    214214                                   "]");
    215         foreach(var kvp in Regions)
    216           expression += $", {kvp.Key}=({kvp.Value.LowerBound} .. {kvp.Value.UpperBound})";
     215        foreach(var region in Regions)
     216          expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
    217217        Expression = expression;
    218218        return;
     
    227227                                 "]",
    228228                                 GetDerivationString(numberOfDerivations));
    229       foreach (var kvp in Regions)
    230         expression += $", {kvp.Key}=({kvp.Value.LowerBound} .. {kvp.Value.UpperBound})";
     229      foreach (var region in Regions)
     230        expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
    231231      Expression = expression;
    232232    }
  • 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.