#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 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.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.ConditionActionEncoding;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.DataAnalysis;
namespace HeuristicLab.Problems.ConditionActionClassification {
public class ConditionActionClassificationProblemData : ParameterizedNamedItem, IConditionActionProblemData {
#region default data
public static string[] defaultVariableNames = new string[] { "a", "b", "c", "d", "e", "f", "g" };
public static double[,] defaultData = new double[,]{
{0,0,1,1,0,0,0},
{0,1,1,1,0,0,0},
{0,0,1,0,0,0,0},
{1,0,1,0,1,1,0}
};
#endregion
#region parameter properites
public IFixedValueParameter DatasetParameter {
get { return (IFixedValueParameter)Parameters["Dataset"]; }
}
public IFixedValueParameter> ConditionVariablesParameter {
get { return (IFixedValueParameter>)Parameters["ConditionVariables"]; }
}
public IFixedValueParameter> ActionVariablesParameter {
get { return (IFixedValueParameter>)Parameters["ActionVariables"]; }
}
#endregion
public Dataset Dataset {
get { return DatasetParameter.Value; }
}
public ICheckedItemList ConditionVariables {
get { return ConditionVariablesParameter.Value; }
}
public ICheckedItemList ActionVariables {
get { return ActionVariablesParameter.Value; }
}
public IEnumerable AllowedConditionVariables {
get { return ConditionVariables.CheckedItems.Select(x => x.Value.Value); }
}
public IEnumerable AllowedActionVariables {
get { return ActionVariables.CheckedItems.Select(x => x.Value.Value); }
}
[StorableConstructor]
protected ConditionActionClassificationProblemData(bool deserializing) : base(deserializing) { }
protected ConditionActionClassificationProblemData(ConditionActionClassificationProblemData original, Cloner cloner)
: base(original, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new ConditionActionClassificationProblemData(this, cloner);
}
public ConditionActionClassificationProblemData(Dataset dataset, IEnumerable allowedConditionVariables, IEnumerable allowedActionVariables) {
if (dataset == null) throw new ArgumentNullException("The dataset must not be null.");
if (allowedActionVariables == null) throw new ArgumentNullException("The allowedActionVariables must not be null.");
if (allowedConditionVariables == null) throw new ArgumentNullException("The allowedActionVariables must not be null.");
if (allowedActionVariables.Except(dataset.DoubleVariables).Any())
throw new ArgumentException("All allowed action variables must be present in the dataset and of type double.");
if (allowedConditionVariables.Except(dataset.DoubleVariables).Any())
throw new ArgumentException("All allowed condition variables must be present in the dataset and of type double.");
var actionVariables = new CheckedItemList(dataset.DoubleVariables.Select(x => new StringValue(x)));
var conditionVariables = new CheckedItemList(actionVariables);
foreach (StringValue x in actionVariables) {
actionVariables.SetItemCheckedState(x, allowedActionVariables.Contains(x.Value));
conditionVariables.SetItemCheckedState(x, allowedConditionVariables.Contains(x.Value));
}
Parameters.Add(new FixedValueParameter("Dataset", "", dataset));
Parameters.Add(new FixedValueParameter>("ActionVariables", "", actionVariables.AsReadOnly()));
Parameters.Add(new FixedValueParameter>("ConditionVariables", "", conditionVariables.AsReadOnly()));
((ValueParameter)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
}
}
}