#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 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.Collections.Generic;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Optimization;
using System;
namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
///
/// Abstract base class symbolic data analysis solutions
///
[StorableClass]
public abstract class SymbolicDataAnalysisSolution : ResultCollection, ISymbolicDataAnalysisSolution {
private const string ModelResultName = "Model";
private const string ProblemDataResultName = "ProblemData";
#region properties
public ISymbolicDataAnalysisModel Model {
get { return (ISymbolicDataAnalysisModel)this[ModelResultName].Value; }
set {
if (this[ModelResultName].Value != value) {
if (value != null) {
this[ModelResultName].Value = value;
OnModelChanged(EventArgs.Empty);
}
}
}
}
IDataAnalysisModel IDataAnalysisSolution.Model {
get { return Model; }
}
public IDataAnalysisProblemData ProblemData {
get { return (IDataAnalysisProblemData)this[ProblemDataResultName].Value; }
set {
if (this[ProblemDataResultName].Value != value) {
if (value != null) {
this[ProblemDataResultName].Value = value;
OnProblemDataChanged(EventArgs.Empty);
}
}
}
}
#endregion
[StorableConstructor]
protected SymbolicDataAnalysisSolution(bool deserializing) : base(deserializing) { }
protected SymbolicDataAnalysisSolution(SymbolicDataAnalysisSolution original, Cloner cloner)
: base(original, cloner) {
name = original.Name;
description = original.Description;
}
public SymbolicDataAnalysisSolution()
: base() {
name = string.Empty;
description = string.Empty;
Add(new Result(ModelResultName, "The symbolic data analysis model.", typeof(IDataAnalysisModel)));
Add(new Result(ProblemDataResultName, "The symbolic data analysis problem data.", typeof(IDataAnalysisProblemData)));
}
public event EventHandler ModelChanged;
protected virtual void OnModelChanged(EventArgs e) {
var listeners = ModelChanged;
if (listeners != null) listeners(this, e);
}
public event EventHandler ProblemDataChanged;
protected virtual void OnProblemDataChanged(EventArgs e) {
var listeners = ProblemDataChanged;
if (listeners != null) listeners(this, e);
}
#region INamedItem Members
[Storable]
protected string name;
public string Name {
get { return name; }
set {
if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
CancelEventArgs e = value == null ? new CancelEventArgs(string.Empty) : new CancelEventArgs(value);
OnNameChanging(e);
if (!e.Cancel) {
name = value == null ? string.Empty : value;
OnNameChanged();
}
}
}
}
public virtual bool CanChangeName {
get { return true; }
}
[Storable]
protected string description;
public string Description {
get { return description; }
set {
if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
description = value == null ? string.Empty : value;
OnDescriptionChanged();
}
}
}
public virtual bool CanChangeDescription {
get { return true; }
}
public override string ToString() {
return Name;
}
public event EventHandler> NameChanging;
protected virtual void OnNameChanging(CancelEventArgs e) {
var handler = NameChanging;
if (handler != null) handler(this, e);
}
public event EventHandler NameChanged;
protected virtual void OnNameChanged() {
var handler = NameChanged;
if (handler != null) handler(this, EventArgs.Empty);
OnToStringChanged();
}
public event EventHandler DescriptionChanged;
protected virtual void OnDescriptionChanged() {
var handler = DescriptionChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
#endregion
}
}