/// <summary> /// Construct the object, un-weighted problems. /// </summary> /// <param name="optimizer">Optimize to be used.</param> /// <param name="problems">Array of problems to be optimized.</param> /// <param name="numRuns">Number of optimization runs per problem.</param> public MetaFitness(Optimizer optimizer, Problem[] problems, int numRuns) : base() { Optimizer = optimizer; NumRuns = numRuns; ProblemIndex = new ProblemIndex(problems); }
/// <summary> /// Create the object. /// </summary> /// <param name="problem">Problem-object to be wrapped.</param> /// <param name="capacity">Log capacity.</param> public LogSolutions(Problem problem, int capacity) : base(problem) { Capacity = capacity; _log = new SortedList<double, Solution>(capacity); }
/// <summary> /// Create the object. /// </summary> /// <param name="problem">Problem-object to be wrapped.</param> /// <param name="capacity">Log capacity.</param> /// <param name="onlyFeasible">Only log feasible solutions.</param> public LogSolutions(Problem problem, int capacity, bool onlyFeasible) : base(problem) { Capacity = capacity; OnlyFeasible = onlyFeasible; Log = new List<Solution>(capacity); }
/// <summary> /// Construct the ProblemIndex-object. /// </summary> /// <param name="problems">The problems to be indexed.</param> public ProblemIndex(Problem[] problems) : base() { int numProblems = problems.Count(); double weight = 1.0 / numProblems; Index = new List<ProblemFitness>(numProblems); foreach (Problem problem in problems) { Index.Add(new ProblemFitness(problem, weight)); } }
/// <summary> /// Print parameters using names associated with an optimization problem. /// </summary> /// <param name="problem">Optimization problem with associated parameter-names.</param> /// <param name="parameters">Parameters to be printed.</param> public static void PrintParameters(Problem problem, double[] parameters) { int NumParameters = problem.Dimensionality; if (NumParameters > 0) { Debug.Assert(parameters.Length == NumParameters); for (int i = 0; i < NumParameters; i++) { string parameterName = problem.ParameterName[i]; double p = parameters[i]; string pStr = p.ToString("0.####", _cultureInfo); Console.WriteLine("\t{0} = {1}", parameterName, pStr); } } else { Console.WriteLine("\tN/A"); } }
/// <summary> /// Create new object. /// </summary> /// <param name="problems">Problems to be optimized.</param> /// <param name="repeat">Repeat-object.</param> public Multi(Problem[] problems, Repeat repeat) : base() { Repeat = repeat; ProblemIndex = new ProblemIndex(problems); }
/// <summary> /// Constructs a new object. /// </summary> /// <param name="problem">The problem being wrapped.</param> /// <param name="formatAsArray">Format output string as C# array.</param> public FitnessPrint(Problem problem, bool formatAsArray) : base(problem) { FormatAsArray = formatAsArray; }
/// <summary> /// Constructs a new object. /// </summary> /// <param name="problem">The problem being wrapped.</param> public FitnessPrint(Problem problem) : this(problem, false) { }
/// <summary> /// Optimize the given problem and output result-statistics. /// </summary> static void Optimize(Problem problem) { // Create a fitness trace for tracing the progress of optimization, mean. int NumMeanIntervals = 3000; FitnessTrace fitnessTraceMean = new FitnessTraceMean(NumIterations, NumMeanIntervals); // Create a fitness trace for tracing the progress of optimization, quartiles. // Note that fitnessTraceMean is chained to this object by passing it to the // constructor, this causes both fitness traces to be used. int NumQuartileIntervals = 10; FitnessTrace fitnessTraceQuartiles = new FitnessTraceQuartiles(NumRuns, NumIterations, NumQuartileIntervals, fitnessTraceMean); // Assign the problem etc. to the optimizer. Optimizer.Problem = problem; Optimizer.RunCondition = RunCondition; Optimizer.FitnessTrace = fitnessTraceQuartiles; // Wrap the optimizer in a logger of result-statistics. Statistics Statistics = new Statistics(Optimizer); // Wrap it again in a repeater. Repeat Repeat = new RepeatSum(Statistics, NumRuns); // Perform the optimization runs. double fitness = Repeat.Fitness(Parameters); // Compute result-statistics. Statistics.Compute(); // Output result-statistics. Console.WriteLine("{0} & {1} & {2} & {3} & {4} & {5} & {6} & {7} \\\\", problem.Name, Tools.FormatNumber(Statistics.FitnessMean), Tools.FormatNumber(Statistics.FitnessStdDev), Tools.FormatNumber(Statistics.FitnessQuartiles.Min), Tools.FormatNumber(Statistics.FitnessQuartiles.Q1), Tools.FormatNumber(Statistics.FitnessQuartiles.Median), Tools.FormatNumber(Statistics.FitnessQuartiles.Q3), Tools.FormatNumber(Statistics.FitnessQuartiles.Max)); // Output fitness trace, mean. string traceFilenameMean = Optimizer.Name + "-FitnessTraceMean-" + problem.Name + ".txt"; fitnessTraceMean.WriteToFile(traceFilenameMean); // Output fitness trace, quartiles. string traceFilenameQuartiles = Optimizer.Name + "-FitnessTraceQuartiles-" + problem.Name + ".txt"; fitnessTraceQuartiles.WriteToFile(traceFilenameQuartiles); }
/// <summary> /// Constructs a new object. /// </summary> /// <param name="problem">The problem being wrapped.</param> public FitnessPrint(Problem problem) : base(problem) { }
public ProblemFitness(Problem problem, double weight) { Problem = problem; Weight = weight; Fitness = problem.MaxFitness; }