#region License Information /* HeuristicLab * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; namespace HeuristicLab.Problems.DataAnalysis { [StorableType("A56BFB05-8F11-4766-9FBF-20C7010F1CA3")] [Item("ProblemDataConstraints", "Represents constraints associated with a problem data.")] public class ProblemDataConstraint : Item { private static readonly string exampleInput = "# Example for a target variable constraint:" + Environment.NewLine + "Target:'y' in [0 .. 100]" + Environment.NewLine + Environment.NewLine + "# Example for constraints on model parameters: " + Environment.NewLine + "d'y'/d'x' in [0 .. 10]" + Environment.NewLine + "∂²'y'/∂'x'² in [-1 .. inf.]"; [Storable] private string input; public string Input { get => input; set { if (input == value) return; input = value; OnChanged(); } } [Storable] private string infoText; public string InfoText { get => infoText; set { if (infoText == value) return; infoText = value; OnChanged(); } } [Storable] private Color infoColor; public Color InfoColor { get => infoColor; set { if (infoColor == value) return; infoColor = value; OnChanged(); } } [Storable] private IEnumerable constraints; public IEnumerable Constraints { get => constraints; set { if (constraints == value) return; constraints = value.ToList(); OnChanged(); } } public IEnumerable EnabledConstraints => Constraints.Where(c => c.Enabled); [Storable] public IRegressionProblemData ProblemData { get; private set; } [StorableConstructor] protected ProblemDataConstraint(StorableConstructorFlag _) : base(_) { } protected ProblemDataConstraint(ProblemDataConstraint original, Cloner cloner) : base(original, cloner) { Input = original.Input; InfoText = original.InfoText; infoColor = original.InfoColor; constraints = original.Constraints.Select(cloner.Clone).ToList(); ProblemData = cloner.Clone(original.ProblemData); } public override IDeepCloneable Clone(Cloner cloner) { return new ProblemDataConstraint(this, cloner); } public ProblemDataConstraint() { Input = exampleInput; InfoText = ""; InfoColor = Color.DarkOrange; constraints = new List(); ProblemData = null; } public ProblemDataConstraint(IRegressionProblemData problemData) { Input = exampleInput; InfoText = infoText; InfoColor = InfoColor; constraints = new List(); ProblemData = problemData; } public event EventHandler Changed; protected virtual void OnChanged() { var handlers = Changed; if (handlers != null) handlers(this, EventArgs.Empty); } } }