source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/ParsedConstraint.cs @ 16841

Last change on this file since 16841 was 16841, checked in by chaider, 5 months ago

#2971 added getter and setter for variable ranges and interval constraints

File size: 3.5 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23using System;
24using System.Collections.Generic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HEAL.Attic;
28
29namespace HeuristicLab.Problems.DataAnalysis {
30  [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")]
31  [Item("ParsedConstraint", "Represents parsed constraints.")]
32  public class ParsedConstraint : Item {
33    private static readonly string exampleInput = "#Example for a target variable constraint:" + Environment.NewLine +
34                                                  "Target:y in [0 .. 100]" + Environment.NewLine + Environment.NewLine +
35                                                  "#Example for constraint on model parameter: " + Environment.NewLine +
36                                                  "dy / dx in [0 .. 10]" + Environment.NewLine +
37                                                  "\u2202²y / \u2202x² in ]-1 .. inf.[";
38     
39    public string Input { get; set; }
40
41    private IEnumerable<IntervalConstraint> constraints;
42    public IEnumerable<IntervalConstraint> Constraints {
43      get => constraints;
44      set { 
45        constraints = value;
46        OnChanged(EventArgs.Empty);
47      }
48  }
49    public IRegressionProblemData ProblemData { get; set; }
50
51    [StorableConstructor]
52    protected ParsedConstraint(StorableConstructorFlag _) : base(_) { }
53
54    protected ParsedConstraint(ParsedConstraint original, Cloner cloner)
55      : base(original, cloner) {
56      this.Input = original.Input;
57      this.constraints = original.Constraints;
58      this.ProblemData = original.ProblemData;
59    }
60
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new ParsedConstraint(this, cloner);
63    }
64
65    public ParsedConstraint() {
66      this.Input = exampleInput;
67      this.constraints = new CheckedItemList<IntervalConstraint>();
68      this.ProblemData = null;
69    }
70
71    public ParsedConstraint(IRegressionProblemData problemData) {
72      this.Input = exampleInput;
73      this.constraints = new List<IntervalConstraint>();
74      this.ProblemData = problemData;
75    }
76
77    public ParsedConstraint(string input, IRegressionProblemData problemData) {
78      this.Input = input;
79      this.constraints = new CheckedItemList<IntervalConstraint>();
80      this.ProblemData = problemData;
81    }
82
83    public ParsedConstraint(string input, IEnumerable<IntervalConstraint> constraints) {
84      this.Input = input;
85      this.constraints = constraints;
86    }
87
88    public event EventHandler Changed;
89    protected virtual void OnChanged(EventArgs e) {
90      EventHandler handlers = Changed;
91      if (handlers != null)
92        handlers(this, e);
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.