File size: 3,842 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
/// ------------------------------------------------------
/// 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;

namespace SwarmOps.Problems
{
    /// <summary>
    /// Contains list of all implemented benchmark problems.
    /// </summary>
    public static class Benchmarks
    {
        /// <summary>
        /// Enumeration of all benchmark problem IDs.
        /// </summary>
        public enum ID
        { 
            Ackley, 
            Griewank, 
            Penalized1, 
            Penalized2, 
            QuarticNoise, 
            Rastrigin, 
            Rosenbrock, 
            Schwefel12, 
            Schwefel221, 
            Schwefel222, 
            Sphere, 
            Step 
        }

        /// <summary>
        /// Array containing all benchmark problem IDs.
        /// </summary>
        public static ID[] IDs =
        {
            ID.Ackley, 
            ID.Griewank, 
            ID.Penalized1, 
            ID.Penalized2, 
            ID.QuarticNoise, 
            ID.Rastrigin, 
            ID.Rosenbrock, 
            ID.Schwefel12, 
            ID.Schwefel221, 
            ID.Schwefel222, 
            ID.Sphere, 
            ID.Step 
        };

        /// <summary>
        /// Create a new instance of a benchmark problem.
        /// </summary>
        /// <param name="id">Benchmark problem ID.</param>
        /// <param name="dimensionality">Dimensionality of problem.</param>
        /// <returns></returns>
        public static Benchmark CreateInstance(this ID id, int dimensionality, int maxIterations)
        {
            Benchmark benchmark;

            switch (id)
            {
                case ID.Ackley:
                    benchmark = new Ackley(dimensionality, maxIterations);
                    break;

                case ID.Griewank:
                    benchmark = new Griewank(dimensionality, maxIterations);
                    break;

                case ID.Penalized1:
                    benchmark = new Penalized1(dimensionality, maxIterations);
                    break;

                case ID.Penalized2:
                    benchmark = new Penalized2(dimensionality, maxIterations);
                    break;

                case ID.QuarticNoise:
                    benchmark = new QuarticNoise(dimensionality, maxIterations);
                    break;

                case ID.Rastrigin:
                    benchmark = new Rastrigin(dimensionality, maxIterations);
                    break;

                case ID.Rosenbrock:
                    benchmark = new Rosenbrock(dimensionality, maxIterations);
                    break;

                case ID.Schwefel12:
                    benchmark = new Schwefel12(dimensionality, maxIterations);
                    break;

                case ID.Schwefel221:
                    benchmark = new Schwefel221(dimensionality, maxIterations);
                    break;

                case ID.Schwefel222:
                    benchmark = new Schwefel222(dimensionality, maxIterations);
                    break;

                case ID.Sphere:
                    benchmark = new Sphere(dimensionality, maxIterations);
                    break;

                case ID.Step:
                    benchmark = new Step(dimensionality, maxIterations);
                    break;

                default:
                    throw new ArgumentException();
            }

            return benchmark;
        }
    }
}