#region License Information
/* HeuristicLab
* Copyright (C) 2002-2014 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.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Problems.Programmable {
[Item("RealParameterConfiguration", "")]
[StorableClass]
public class RealParameterConfiguration : ParameterConfiguration {
[Storable]
private IntValue length;
public IntValue Length {
get { return length; }
set {
if (length == value) return;
length = value;
OnParameterConfigurationChanged();
}
}
[Storable]
private DoubleMatrix bounds;
public DoubleMatrix Bounds {
get { return bounds; }
set {
if (bounds == value) return;
bounds = value;
OnParameterConfigurationChanged();
}
}
[StorableConstructor]
protected RealParameterConfiguration(bool deserializing) : base(deserializing) { }
protected RealParameterConfiguration(RealParameterConfiguration original, Cloner cloner)
: base(original, cloner) {
length = cloner.Clone(original.length);
bounds = cloner.Clone(original.bounds);
}
public RealParameterConfiguration(int length, double min, double max) {
if (min >= max) throw new ArgumentException("min must be less than max", "min");
this.length = new IntValue(length);
bounds = new DoubleMatrix(1, 2);
bounds[0, 0] = min;
bounds[0, 1] = max;
}
public RealParameterConfiguration(int length, IList min, IList max) {
if (min.Count == 0) throw new ArgumentException("Bounds must be given for the real parameters.");
if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
if (min.Zip(max, (mi, ma) => mi >= ma).Any()) throw new ArgumentException("min must be less than max in each dimension", "min");
this.length = new IntValue(length);
bounds = new DoubleMatrix(min.Count, 2);
for (int i = 0; i < min.Count; i++) {
bounds[i, 0] = min[i];
bounds[i, 1] = max[i];
}
}
public override IDeepCloneable Clone(Cloner cloner) {
return new RealParameterConfiguration(this, cloner);
}
}
}