/// ------------------------------------------------------ /// 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/ /// ------------------------------------------------------ using System; using System.Collections.Generic; namespace SwarmOps { /// /// Candidate solution found during optimization, consisting of parameters /// and fitness value. /// public class Solution { #region Constructors. /// /// Construct the object. /// /// Candidate solution parameters. /// Fitness for candidate solution. /// Feasibility of candidate solution. public Solution(double[] parameters, double fitness, bool feasible) { Parameters = parameters.Clone() as double[]; Fitness = fitness; Feasible = feasible; } #endregion #region Public fields. /// /// Candidate solution parameters. /// public double[] Parameters { get; protected set; } /// /// Fitness of candidate solution. /// public double Fitness { get; protected set; } /// /// Feasibility of candidate solution. /// public bool Feasible { get; protected set; } #endregion #region Comparer. /// /// Comparer used for sorting a list of Solution-objects /// according to fitness and feasibility in ascending (worsening) order. /// public class FitnessComparer : IComparer { public int Compare(Solution x, Solution y) { int retVal; if (x.Fitness == y.Fitness && x.Feasible == y.Feasible) { retVal = 0; } else if (Tools.BetterFeasibleFitness(x.Feasible, y.Feasible, x.Fitness, y.Fitness)) { retVal = 1; } else { retVal = -1; } return retVal; } } #endregion } }