1
#region License Information
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 * This file is part of HeuristicLab.
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
22 using HeuristicLab
.Common
;
23 using HeuristicLab
.Core
;
24 using HeuristicLab
.Data
;
25 using HeuristicLab
.Operators
;
26 using HeuristicLab
.Parameters
;
27 using HeuristicLab
.Persistence
.Default
.CompositeSerializers
.Storable
;
29 namespace HeuristicLab
.Optimization
.Operators
{
31 /// Base class for modifying a double value according to a certain function in discrete intervalls.
33 [Item("DiscreteDoubleValueModifier", "Base class for modifying a double value according to a certain function in discrete intervalls.")]
35 public abstract class DiscreteDoubleValueModifier
: SingleSuccessorOperator
, IDiscreteDoubleValueModifier
{
36 #region parameter properties
38 /// The parameter that should be modified.
40 public ILookupParameter
<DoubleValue
> ValueParameter
{
41 get { return (ILookupParameter<DoubleValue>)Parameters["Value"]; }
44 /// The start value of the parameter, will be assigned to <see cref="ValueParameter"/> as soon as <see cref="IndexParamter"/> equals <see cref="StartIndexParameter"/>.
46 public IValueLookupParameter
<DoubleValue
> StartValueParameter
{
47 get { return (IValueLookupParameter<DoubleValue>)Parameters["StartValue"]; }
50 /// The end value of the parameter, will be assigned to <see cref="ValueParameter"/> as soon as <see cref="IndexParamter"/> equals <see cref="EndIndexParameter"/>.
52 public IValueLookupParameter
<DoubleValue
> EndValueParameter
{
53 get { return (IValueLookupParameter<DoubleValue>)Parameters["EndValue"]; }
56 /// The index that denotes from which point in the function (relative to <see cref="StartIndexParameter"/> and <see cref="EndIndexParameter"/> the value should be assigned.
58 public ILookupParameter
<IntValue
> IndexParameter
{
59 get { return (ILookupParameter<IntValue>)Parameters["Index"]; }
62 /// As soon as <see cref="IndexParameter"/> is >= this parameter the value will start to be modified.
64 public IValueLookupParameter
<IntValue
> StartIndexParameter
{
65 get { return (IValueLookupParameter<IntValue>)Parameters["StartIndex"]; }
68 /// As long as <see cref="IndexParameter"/> is <= this parameter the value will start to be modified.
70 public IValueLookupParameter
<IntValue
> EndIndexParameter
{
71 get { return (IValueLookupParameter<IntValue>)Parameters["EndIndex"]; }
75 protected DiscreteDoubleValueModifier(bool deserializing
) : base(deserializing
) { }
76 protected DiscreteDoubleValueModifier(DiscreteDoubleValueModifier original
, Cloner cloner
) : base(original
, cloner
) { }
78 /// Initializes a new instance of <see cref="DiscreteDoubleValueModifier"/> with 6 parameters
79 /// (<c>Value</c>, <c>StartValue</c>, <c>EndValue</c>, <c>Index</c>, <c>StartIndex</c>, <c>EndIndex</c>).
81 protected DiscreteDoubleValueModifier()
83 Parameters
.Add(new LookupParameter
<DoubleValue
>("Value", "The double value to modify."));
84 Parameters
.Add(new ValueLookupParameter
<DoubleValue
>("StartValue", "The start value of 'Value'."));
85 Parameters
.Add(new ValueLookupParameter
<DoubleValue
>("EndValue", "The end value of 'Value'."));
86 Parameters
.Add(new LookupParameter
<IntValue
>("Index", "The current index."));
87 Parameters
.Add(new ValueLookupParameter
<IntValue
>("StartIndex", "The start index at which to start modifying 'Value'."));
88 Parameters
.Add(new ValueLookupParameter
<IntValue
>("EndIndex", "The end index by which 'Value' should have reached 'EndValue'."));
92 /// Checks whether index is between start and end and forwards the call to <see cref="Modify"/> if startIndex < index < endIndex.
95 /// If index = startIndex the call will not be forwarded and startValue will be used. The same with endIndex and endValue.
97 /// <returns>What the base class returns.</returns>
98 public override IOperation
Apply() {
99 int index
= IndexParameter
.ActualValue
.Value
, startIndex
= StartIndexParameter
.ActualValue
.Value
;
100 if (index
>= startIndex
) {
101 int endIndex
= EndIndexParameter
.ActualValue
.Value
;
102 DoubleValue
value = ValueParameter
.ActualValue
;
104 value = new DoubleValue();
105 ValueParameter
.ActualValue
= value;
107 double newValue
= value.Value
;
108 if (index
== startIndex
) {
109 newValue
= StartValueParameter
.ActualValue
.Value
;
110 } else if (index
== endIndex
) {
111 newValue
= EndValueParameter
.ActualValue
.Value
;
112 } else if (index
< endIndex
) {
113 double start
= StartValueParameter
.ActualValue
.Value
, end
= EndValueParameter
.ActualValue
.Value
;
114 newValue
= Modify(value.Value
, start
, end
, index
, startIndex
, endIndex
);
116 value.Value
= newValue
;
122 /// Modifies a given value according to two support points denoted by (startIndex; startValue) and (endIndex; endValue).
123 /// The current 'index' and the last value of 'value' is also given.
125 /// <param name="value">The last value.</param>
126 /// <param name="startValue">The start value.</param>
127 /// <param name="endValue">The end value.</param>
128 /// <param name="index">The current index.</param>
129 /// <param name="startIndex">The start index.</param>
130 /// <param name="endIndex">The end index.</param>
131 /// <returns>The new value.</returns>
132 protected abstract double Modify(double value, double startValue
, double endValue
, int index
, int startIndex
, int endIndex
);