Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/20 11:36:34 (4 years ago)
Author:
chaider
Message:

#3073

  • Removed Region class and used IntervallCollection instead
  • Changed Parser to work with IntervalColletions
  • Moved CheckConstraint methods from Analyzer to IntervalUtil class
  • Added CheckConstraint method to interface to check if an interval is in a given constraint
  • Added possibility to stop splitting as soon as a constraint is fulfiled
Location:
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4
Files:
1 deleted
3 edited

Legend:

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

    r17765 r17768  
    192192    <Compile Include="Implementation\Interval\IntervalConstraint.cs" />
    193193    <Compile Include="Implementation\Interval\IntervalConstraintsParser.cs" />
    194     <Compile Include="Implementation\Interval\Region.cs" />
    195194    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    196195    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraint.cs

    r17767 r17768  
    115115    }
    116116
    117     [Storable] private IEnumerable<Region> regions;
    118     public IEnumerable<Region> Regions {
     117    [Storable] private IntervalCollection regions;
     118    public IntervalCollection Regions {
    119119      get => regions;
    120120      set {
     
    146146                              Interval interval, double weight, bool enabled)
    147147      : this(expression, variable, target, numberOfDerivations,
    148              interval, Enumerable.Empty<Region>(), weight, enabled) { }
     148             interval, new IntervalCollection(), weight, enabled) { }
    149149
    150150    public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations,
    151                               Interval interval, IEnumerable<Region> regions, double weight, bool enabled) {
     151                              Interval interval, IntervalCollection regions, double weight, bool enabled) {
    152152      this.regions = regions;
    153153      this.weight = weight;
     
    166166    private IntervalConstraint(IntervalConstraint original, Cloner cloner)
    167167      : base(original, cloner) {
    168       Regions = new List<Region>(original.Regions?.Select(r => cloner.Clone(r)) ?? Enumerable.Empty<Region>());
     168      Regions = original.Regions;
    169169      Expression = original.Expression;
    170170      Variable = original.Variable;
     
    207207                                   "]");
    208208        if(Regions != null) {
    209           foreach (var region in Regions)
    210             expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     209          foreach (var region in Regions.GetReadonlyDictionary())
     210            expression += $", {region.Key}=({region.Value.LowerBound} .. {region.Value.UpperBound})";
    211211        }
    212212       
     
    224224                                 GetDerivationString(numberOfDerivations));
    225225      if (Regions != null) {
    226         foreach (var region in Regions)
    227           expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     226        foreach (var region in Regions.GetReadonlyDictionary())
     227          expression += $", {region.Key}=({region.Value.LowerBound} .. {region.Value.UpperBound})";
    228228      }
    229229      Expression = expression;
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r17765 r17768  
    9393            if (match.Groups[10].Success)
    9494            {
    95               IList<Region> regions = new List<Region>();
     95              IntervalCollection regions = new IntervalCollection();
    9696              // option variables found
    9797              for(int idx = 0; idx < match.Groups[10].Captures.Count; ++idx)
    9898              {
    99                 Region region = ParseRegion(
     99                KeyValuePair<string, Interval> 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);
     103                if (regions.GetReadonlyDictionary().All(r => r.Key != region.Key))
     104                  regions.AddInterval(region.Key, region.Value);
    105105                else
    106106                  throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     
    184184            if(match.Groups[17].Success)
    185185            {
    186               IList<Region> regions = new List<Region>();
     186              IntervalCollection regions = new IntervalCollection();
    187187              // option variables found
    188188              for (int idx = 0; idx < match.Groups[17].Captures.Count; ++idx)
    189189              {
    190                 Region region = ParseRegion(
     190                KeyValuePair<string, Interval> region = ParseRegion(
    191191                  match.Groups[18].Captures[idx].Value,
    192192                  match.Groups[20].Captures[idx].Value,
    193193                  match.Groups[22].Captures[idx].Value);
    194                 if (!regions.Any(r => r.VariableName == region.VariableName))
    195                   regions.Add(region);
     194                if (regions.GetReadonlyDictionary().All(r => r.Key != region.Key))
     195                  regions.AddInterval(region.Key, region.Value);
    196196                else
    197197                  throw new ArgumentException("A constraint cannot contain multiple regions of the same variable.");
     
    217217    }
    218218
    219     private static Region ParseRegion(string variable, string lb, string ub)
     219    private static KeyValuePair<string, Interval> ParseRegion(string variable, string lb, string ub)
    220220    {
    221221      var regionLb = ParseIntervalBounds(lb);
    222222      var regionUb = ParseIntervalBounds(ub);
    223       return new Region(variable, new Interval(regionLb, regionUb));
     223      return new KeyValuePair<string, Interval>(variable, new Interval(regionLb, regionUb));
     224      //return new Region(variable, new Interval(regionLb, regionUb));
    224225    }
    225226
Note: See TracChangeset for help on using the changeset viewer.