File size: 5,841 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
/// ------------------------------------------------------
/// SwarmOps - Numeric and heuristic optimization for C#
/// Copyright (C) 2003-2011 Magnus Erik Hvass Pedersen.
/// Please see the file license.txt for license details.
/// SwarmOps on the internet: http://www.Hvass-Labs.org/
/// ------------------------------------------------------
namespace SwarmOps
{
/// <summary>
/// Transparently wrap a Problem-object.
/// </summary>
public abstract class ProblemWrapper : Problem
{
#region Constructors.
/// <summary>
/// Create the object.
/// </summary>
/// <param name="problem">Problem-object to be wrapped.</param>
public ProblemWrapper(Problem problem)
: base()
{
Problem = problem;
}
#endregion
#region Public fields.
/// <summary>
/// The problem that is being wrapped.
/// </summary>
public Problem Problem
{
get;
private set;
}
#endregion
#region Problem base-class overrides.
/// <summary>
/// Return Name of the wrapped problem.
/// </summary>
public override string Name
{
get { return Problem.Name; }
}
/// <summary>
/// Return LowerBound of wrapped problem.
/// </summary>
public override double[] LowerBound
{
get { return Problem.LowerBound; }
}
/// <summary>
/// Return UpperBound of wrapped problem.
/// </summary>
public override double[] UpperBound
{
get { return Problem.UpperBound; }
}
/// <summary>
/// Return LowerInit of wrapped problem.
/// </summary>
public override double[] LowerInit
{
get { return Problem.LowerInit; }
}
/// <summary>
/// Return UpperInit of wrapped problem.
/// </summary>
public override double[] UpperInit
{
get { return Problem.UpperInit; }
}
/// <summary>
/// Return Dimensionality of wrapped problem.
/// </summary>
public override int Dimensionality
{
get { return Problem.Dimensionality; }
}
/// <summary>
/// Return MinFitness of wrapped problem.
/// </summary>
public override double MinFitness
{
get { return Problem.MinFitness; }
}
/// <summary>
/// Return MaxFitness of wrapped problem.
/// </summary>
public override double MaxFitness
{
get { return Problem.MaxFitness; }
}
/// <summary>
/// Return AcceptableFitness of wrapped problem.
/// </summary>
public override double AcceptableFitness
{
get { return Problem.AcceptableFitness; }
}
/// <summary>
/// Return ParameterName of wrapped problem.
/// </summary>
public override string[] ParameterName
{
get { return Problem.ParameterName; }
}
/// <summary>
/// Return HasGradient of wrapped problem.
/// </summary>
public override bool HasGradient
{
get { return Problem.HasGradient; }
}
/// <summary>
/// Compute the gradient of the wrapped problem.
/// </summary>
/// <param name="x">Candidate solution.</param>
/// <param name="v">Array for holding the gradient.</param>
/// <returns>
/// Computation time-complexity factor. E.g. if fitness takes
/// time O(n) to compute and gradient takes time O(n*n) to compute,
/// then return n.
/// </returns>
public override int Gradient(double[] x, ref double[] v)
{
return Problem.Gradient(x, ref v);
}
/// <summary>
/// Enforce constraints and evaluate feasiblity of the wrapped problem.
/// </summary>
/// <param name="parameters">Candidate solution.</param>
public override bool EnforceConstraints(ref double[] parameters)
{
return Problem.EnforceConstraints(ref parameters);
}
/// <summary>
/// Evaluate feasibility (constraint satisfaction) of the wrapped problem.
/// </summary>
/// <param name="parameters">Candidate solution.</param>
public override bool Feasible(double[] parameters)
{
return Problem.Feasible(parameters);
}
/// <summary>
/// Propagate signal to wrapped problem.
/// </summary>
public override void BeginOptimizationRun()
{
Problem.BeginOptimizationRun();
}
/// <summary>
/// Propagate signal to wrapped problem.
/// </summary>
public override void EndOptimizationRun()
{
Problem.EndOptimizationRun();
}
/// <summary>
/// Return whether optimization of wrapped problem is allowed to continue.
/// </summary>
/// <param name="iterations">Number of iterations performed in optimization run.</param>
/// <param name="fitness">Best fitness found in optimization run.</param>
/// <param name="feasible">Feasibility of best found candidate solution.</param>
public override bool Continue(int iterations, double fitness, bool feasible)
{
return Problem.Continue(iterations, fitness, feasible);
}
#endregion
}
}
|