Included Problems
The Moving Peaks Benchmark (MPB) for dynamic optimization problems.
This module provides an implementation of the Moving Peaks Benchmark (MPB) generator, a widely used tool for creating dynamic, multi-peaked optimization landscapes. It is designed to test the ability of optimization algorithms to adapt to changing environments.
The MPB landscape is defined by a number of peaks, each with its own height,
width, and position. At specified intervals (controlled by change_frequency),
these peak properties are updated, causing the landscape to shift, change shape,
or both.
While the benchmark is naturally a maximization problem, this implementation negates the fitness value upon evaluation, allowing it to be used directly with standard minimization algorithms.
The 28 Standard Problem Classes & The generate_mpb_configs Function
This module also includes the generate_mpb_configs helper function, which
programmatically creates parameter dictionaries for the 28 standard problem
classes defined by Duhain and Engelbrecht.
These classes are identified by a 3-letter acronym (e.g., 'A1L'), which combines one code from each of the three classification schemes detailed below.
1. Duhain & Engelbrecht: Spatial and Temporal Severity (First Letter)
Defines the magnitude and frequency of changes.
-
Progressive ('P'): Frequent, small changes.
change_frequency: Low value (high temporal change).change_severity(s): Low value.height_severity: Low value.
-
Abrupt ('A'): Infrequent, large changes.
change_frequency: High value (low temporal change).change_severity(s): High value.height_severity: High value.
-
Chaotic ('C'): Frequent, large changes.
change_frequency: Low value (high temporal change).change_severity(s): High value.height_severity: High value.
2. Hu & Eberhart / Shi & Eberhart: Optima Modification (Second Letter)
Defines what changes about the peaks (position, value, or both).
-
Type I ('1'): Locations change, heights are constant.
height_severity: Set to 0.0.- Requires
change_severity(s) != 0 for movement.
-
Type II ('2'): Locations are static, heights change.
height_severity: Set to a non-zero value.- Requires
change_severity(s) = 0 to prevent movement.
-
Type III ('3'): Both locations and heights change.
height_severity: Set to a non-zero value.- Requires
change_severity(s) != 0 for movement.
3. Angeline: Optima Trajectory (Third Letter)
Defines the pattern of peak movement.
-
Linear ('L'): Peaks move in a straight, correlated line.
lambda_param: Set to 1.0.- Requires
change_severity(s) != 0 for movement.
-
Circular ('C'): Peaks have a periodic movement pattern. This is achieved in the parameterization by preventing translational movement.
- Requires
change_severity(s) = 0.
- Requires
-
Random ('R'): Peaks move randomly without a discernible pattern.
lambda_param: Set to 0.0.- Requires
change_severity(s) != 0 for movement.
Conflict Resolution
Some combinations are impossible (e.g., a Type II problem, which requires
s = 0, cannot have Linear movement, which requires s != 0). The
generate_mpb_configs function marks these impossible configurations by setting
the change_severity parameter to the string 'XXX'.
MovingPeaksBenchmark
Bases: Problem[ndarray, float]
An implementation of the Moving Peaks Benchmark (MPB) generator.
This class conforms to the Problem interface and produces dynamic,
unconstrained optimization problems. The objective is to find the maximum
value in a landscape composed of several moving peaks.
Note
Since most solvers are minimizers, the evaluate method returns the
negated value of the MPB function. Minimizing this value is
equivalent to maximizing the original function.
Attributes:
| Name | Type | Description |
|---|---|---|
peaks |
List[_Peak]
|
A list of the peak objects in the landscape. |
Source code in cilpy/problem/mpb.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
__init__(dimension=2, num_peaks=10, domain=(0.0, 100.0), min_height=30.0, max_height=70.0, min_width=1.0, max_width=12.0, change_frequency=5000, change_severity=1.0, height_severity=7.0, width_severity=1.0, lambda_param=0.0, name='MovingPeaksBenchmark')
Initializes the Moving Peaks Benchmark problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension
|
int
|
The dimensionality of the search landscape. |
2
|
num_peaks
|
int
|
The number of peaks in the landscape. |
10
|
domain
|
Tuple[float, float]
|
The |
(0.0, 100.0)
|
min_height
|
float
|
The minimum initial height of a peak. |
30.0
|
max_height
|
float
|
The maximum initial height of a peak. |
70.0
|
min_width
|
float
|
The minimum initial width of a peak. |
1.0
|
max_width
|
float
|
The maximum initial width of a peak. |
12.0
|
change_frequency
|
int
|
The number of evaluations between landscape changes. |
5000
|
change_severity
|
float
|
Controls how severely peak positions change. |
1.0
|
height_severity
|
float
|
Controls how severely peak heights change. |
7.0
|
width_severity
|
float
|
Controls how severely peak widths change. |
1.0
|
lambda_param
|
float
|
Correlates peak movement over time. A value of 0.0 results in random movement direction at each change. |
0.0
|
name
|
str
|
The name of the problem instance. |
'MovingPeaksBenchmark'
|
Source code in cilpy/problem/mpb.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
begin_iteration()
This method is called by the runner once per iteration. It handles the logic for changing the environment.
Source code in cilpy/problem/mpb.py
309 310 311 312 313 314 315 316 317 318 319 320 321 | |
evaluate(solution)
Evaluates a solution and returns its fitness.
This method checks if the environment should change based on the evaluation count. It then calculates the function value as the maximum of all peak evaluations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
ndarray
|
The candidate solution to be evaluated. |
required |
Returns:
| Type | Description |
|---|---|
Evaluation[float]
|
Evaluation[float]: An Evaluation object containing the negated fitness value for use with minimization solvers. |
Source code in cilpy/problem/mpb.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
get_fitness_bounds()
Returns the known theoretical min and max fitness values for the problem.
This is used for calculating normalized performance metrics.
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
A tuple containing (global_minimum_fitness, global_maximum_fitness). |
Source code in cilpy/problem/mpb.py
323 324 325 326 327 328 329 330 331 332 333 | |
is_dynamic()
Indicates that the problem's objectives are dynamic.
Returns:
| Type | Description |
|---|---|
Tuple[bool, bool]
|
Tuple[bool, bool]: A tuple |
Source code in cilpy/problem/mpb.py
296 297 298 299 300 301 302 303 | |
is_multi_objective()
Indicates that the problem is not multi-objective.
Source code in cilpy/problem/mpb.py
305 306 307 | |
update_all_peaks()
Updates all peaks of the mpb.
Source code in cilpy/problem/mpb.py
335 336 337 338 339 340 341 342 343 344 345 | |
demonstrate_mpb(params)
Helper function to run and print a scenario.
Source code in cilpy/problem/mpb.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
generate_mpb_configs(dimension=5, num_peaks=10, domain=(0.0, 100.0), min_height=30.0, max_height=70.0, min_width=1.0, max_width=12.0, width_severity=0.05, s_for_random=1.0)
Programmatically generates parameter dictionaries for all 28 MPB classes.
This function combines the rules from three classification schemes to generate 27 dynamic problem configurations and 1 static configuration. It handles contradictions between rules as specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s_for_random
|
float
|
The non-zero value to use for the change_severity
parameter |
1.0
|
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
Dict[str, Dict]: A dictionary where keys are the 3-letter acronyms (e.g., "A1C", "P3L") and values are the corresponding parameter dictionaries for the MovingPeaksBenchmark constructor. A "STA" key is included for the static case. |
Source code in cilpy/problem/mpb.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
The Constrained Moving Peaks Benchmark (CMPB).
This module provides an implementation of the CMPB generator, a dynamic and constrained optimization problem.
ConstrainedMovingPeaksBenchmark
Bases: Problem[ndarray, float]
An implementation of the Constrained Moving Peaks Benchmark (CMPB).
This class generates a dynamic constrained optimization problem by composing
two independent MovingPeaksBenchmark instances: one for the objective
function landscape (f) and one for the constraint landscape (g).
The problem is naturally a maximization problem defined as: Maximize: h(x) = f(x) - g(x) A solution is considered feasible if h(x) >= 0 (i.e., f(x) >= g(x)).
To align with standard minimization solvers, this class formulates the problem as: Minimize: g(x) - f(x) Subject to: g(x) - f(x) <= 0
This formulation correctly models the problem, where the objective function and the single inequality constraint are the same.
Attributes:
| Name | Type | Description |
|---|---|---|
f_landscape |
MovingPeaksBenchmark
|
The MPB instance for the objective function landscape. |
g_landscape |
MovingPeaksBenchmark
|
The MPB instance for the constraint function landscape. |
Source code in cilpy/problem/cmpb.py
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 | |
__init__(f_params, g_params, name='ConstrainedMovingPeaksBenchmark')
Initializes the Constrained Moving Peaks Benchmark generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_params
|
Dict[str, Any]
|
A dictionary of parameters for the
objective landscape (f), which will be passed to the
|
required |
g_params
|
Dict[str, Any]
|
A dictionary of parameters for the
constraint landscape (g), which will be passed to the
|
required |
name
|
str
|
The name for the problem instance. |
'ConstrainedMovingPeaksBenchmark'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the 'dimension' parameter is not specified or is
different for |
Source code in cilpy/problem/cmpb.py
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 | |
begin_iteration()
Notifies the underlying landscapes that a new solver iteration is beginning.
This method acts as a delegate, calling the begin_iteration method on
both the objective (f) and constraint (g) landscapes. This ensures
that their internal iteration counters are incremented and environmental
changes are triggered correctly and in sync.
Source code in cilpy/problem/cmpb.py
136 137 138 139 140 141 142 143 144 145 146 147 | |
evaluate(solution)
Evaluates a solution against the composed objective and constraint.
This method calls the evaluate method of the underlying f and g
landscapes exactly once, ensuring that their internal evaluation
counters are updated correctly. It then composes the results to form the
final fitness and constraint violation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
ndarray
|
The candidate solution to be evaluated. |
required |
Returns:
| Type | Description |
|---|---|
Evaluation[float]
|
Evaluation[float]: An Evaluation object containing the composed fitness and the single inequality constraint violation. |
Source code in cilpy/problem/cmpb.py
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 | |
get_fitness_bounds()
Returns the known theoretical min and max fitness values for the problem.
This is used for calculating normalized performance metrics.
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
A tuple containing (global_minimum_fitness, global_maximum_fitness). |
Source code in cilpy/problem/cmpb.py
149 150 151 152 153 154 155 156 157 158 159 | |
is_dynamic()
Indicates whether the objective or constraint landscapes can change.
The composed objective g(x) - f(x) is dynamic if either f or g
is dynamic. Similarly, the composed constraint is dynamic if either
f or g is dynamic.
Returns:
| Type | Description |
|---|---|
Tuple[bool, bool]
|
Tuple[bool, bool]: A tuple |
Source code in cilpy/problem/cmpb.py
121 122 123 124 125 126 127 128 129 130 131 | |
demonstrate_cmpb(name, f_params, g_params)
Helper function to run and print a constrained scenario.
Source code in cilpy/problem/cmpb.py
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |