-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimizeBenchmark.c
More file actions
83 lines (70 loc) · 2.48 KB
/
OptimizeBenchmark.c
File metadata and controls
83 lines (70 loc) · 2.48 KB
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
/* ================================================================
*
* SwarmOps - Black-Box Optimization in ANSI C.
* Copyright (C) 2003-2008 Magnus Erik Hvass Pedersen.
* Published under the GNU Lesser General Public License.
* Please see the file license.txt for license details.
* SwarmOps on the internet: http://www.Hvass-Labs.org/
*
* OptimizeBenchmark
*
* Please see header-file for description.
*
* ================================================================ */
#include <SwarmOps/OptimizeBenchmark.h>
#include <SwarmOps/Optimize.h>
#include <SwarmOps/Tools/Vector.h>
#include <SwarmOps/Problems/Benchmarks.h>
#include <SwarmOps/Methods/Methods.h>
#include <assert.h>
/* ---------------------------------------------------------------- */
struct SO_Statistics SO_OptimizeBenchmark (
size_t methodId,
size_t numRuns,
size_t numIterations,
void *settings,
size_t problemId,
SO_TDim n,
int displaceOptimum,
int initFullRange,
const char *traceFilename)
{
/* Results and statistics to be returned. */
struct SO_Results results;
struct SO_Statistics stat;
/* Initialization and search-space boundaries for the given benchmark problem. */
SO_TElm* lowerInit;
SO_TElm* upperInit;
SO_TElm* lowerBound = SO_BenchmarkLowerBound(problemId, n);
SO_TElm* upperBound = SO_BenchmarkUpperBound(problemId, n);
/* Create context for benchmark problem. */
struct SO_BenchmarkContext context = SO_MakeBenchmarkContext(n, displaceOptimum);
/* Initialization boundaries. */
if (initFullRange)
{
lowerInit = lowerBound;
upperInit = upperBound;
}
else
{
lowerInit = SO_BenchmarkLowerInit(problemId, n);
upperInit = SO_BenchmarkUpperInit(problemId, n);
}
/* Perform optimization. */
results = SO_Optimize(methodId, numRuns, numIterations, settings, SO_kBenchmarkProblems[problemId], SO_kBenchmarkGradients[problemId], (void*) &context, n, lowerInit, upperInit, lowerBound, upperBound, traceFilename);
/* Copy statistics from results of optimization. */
stat = SO_CopyStatistics(&results.stat);
/* Free contents of results-struct. */
SO_FreeResults(&results);
/* Free boundary vectors. */
SO_FreeVector(lowerBound);
SO_FreeVector(upperBound);
/* Free initialization vectors, if not using full search-space boundaries. */
if (!initFullRange)
{
SO_FreeVector(lowerInit);
SO_FreeVector(upperInit);
}
return results.stat;
}
/* ---------------------------------------------------------------- */