Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17767


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

#3073

  • fixed a bug which caused a NullPointerException
  • added a storable constructor in Region
Location:
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval
Files:
2 edited

Legend:

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

    r17765 r17767  
    2323using System;
    2424using System.Collections.Generic;
     25using System.Linq;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    114115    }
    115116
    116     [Storable]
    117     private /*IDictionary<string, Interval>*/ IEnumerable<Region> regions; //= new Dictionary<string, Interval>();
    118     public IEnumerable<Region> Regions
    119     {
     117    [Storable] private IEnumerable<Region> regions;
     118    public IEnumerable<Region> Regions {
    120119      get => regions;
    121       set
    122       {
    123         if (regions != value)
    124         {
     120      set {
     121        if (regions != value) {
    125122          regions = value;
    126123          UpdateExpression();
     
    132129    [Storable]
    133130    private double weight = 1.0;
    134     public double Weight
    135     {
     131    public double Weight {
    136132      get => weight;
    137       set
    138       {
    139         if(weight != value)
    140         {
     133      set {
     134        if (weight != value) {
    141135          weight = value;
    142136          UpdateExpression();
     
    149143    private IntervalConstraint(StorableConstructorFlag _) : base(_) { }
    150144
    151     public IntervalConstraint(string   expression, string variable, string target, int numberOfDerivations,
    152                               Interval interval, double weight, bool enabled)
    153       : this(expression, variable, target, numberOfDerivations,
    154              interval, new List<Region>(), weight, enabled) { }
    155 
    156145    public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations,
    157                               Interval interval, IEnumerable<Region> regions, double weight, bool enabled)
    158     {
     146                              Interval interval, double weight, bool enabled)
     147      : this(expression, variable, target, numberOfDerivations,
     148             interval, Enumerable.Empty<Region>(), weight, enabled) { }
     149
     150    public IntervalConstraint(string expression, string variable, string target, int numberOfDerivations,
     151                              Interval interval, IEnumerable<Region> regions, double weight, bool enabled) {
     152      this.regions = regions;
     153      this.weight = weight;
    159154      this.expression = expression;
    160155      this.variable = variable;
     
    162157      this.numberOfDerivations = numberOfDerivations;
    163158      this.interval = interval;
    164       this.regions = regions;
    165       this.weight = weight;
    166159      this.enabled = enabled;
    167160    }
     
    173166    private IntervalConstraint(IntervalConstraint original, Cloner cloner)
    174167      : base(original, cloner) {
    175       Expression          = original.Expression;
    176       Variable            = original.Variable;
    177       Target              = original.Target;
     168      Regions = new List<Region>(original.Regions?.Select(r => cloner.Clone(r)) ?? Enumerable.Empty<Region>());
     169      Expression = original.Expression;
     170      Variable = original.Variable;
     171      Target = original.Target;
    178172      NumberOfDerivations = original.NumberOfDerivations;
    179       Interval            = original.Interval;
    180       Regions             = original.Regions;
    181       Enabled             = original.Enabled;
     173      Interval = original.Interval;
     174      Enabled = original.Enabled;
    182175    }
    183176
     
    213206                                   Interval?.UpperBound,
    214207                                   "]");
    215         foreach(var region in Regions)
    216           expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     208        if(Regions != null) {
     209          foreach (var region in Regions)
     210            expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     211        }
     212       
    217213        Expression = expression;
    218214        return;
    219215      }
    220216
    221       expression = string.Format("∂{6}{1}/∂{0}{6} in {2}{3} .. {4}{5}", 
     217      expression = string.Format("∂{6}{1}/∂{0}{6} in {2}{3} .. {4}{5}",
    222218                                 Variable,
    223219                                 Target,
     
    227223                                 "]",
    228224                                 GetDerivationString(numberOfDerivations));
    229       foreach (var region in Regions)
    230         expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     225      if (Regions != null) {
     226        foreach (var region in Regions)
     227          expression += $", {region.VariableName}=({region.Interval.LowerBound} .. {region.Interval.UpperBound})";
     228      }
    231229      Expression = expression;
    232230    }
  • branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Region.cs

    r17765 r17767  
    1717      get => variableName;
    1818      private set {
    19         if(variableName != value) {
     19        if(variableName == null || variableName != value) {
    2020          variableName = value;
    2121          OnChanged();
     
    2626    [Storable] private Interval interval;
    2727    public Interval Interval {
    28       get => Interval;
     28      get => interval;
    2929      private set {
    30         if (!interval.Equals(value)) {
     30        if (interval == null || !interval.Equals(value)) {
    3131          interval = value;
    3232          OnChanged();
     
    3434      }
    3535    }
     36
     37    [StorableConstructor]
     38    private Region(StorableConstructorFlag _) : base(_) { }
    3639
    3740    public Region(string variableName, Interval interval) {
Note: See TracChangeset for help on using the changeset viewer.