File: problem_type_traits.cpp

package info (click to toggle)
pagmo 2.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 85,228 kB
  • sloc: cpp: 1,753,592; makefile: 223; sh: 121; python: 46
file content (524 lines) | stat: -rw-r--r-- 11,438 bytes parent folder | download | duplicates (2)
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
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
160
161
162
163
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
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
346
347
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
513
514
515
516
517
518
519
520
521
522
523
524
/* Copyright 2017-2021 PaGMO development team

This file is part of the PaGMO library.

The PaGMO library is free software; you can redistribute it and/or modify
it under the terms of either:

  * the GNU Lesser General Public License as published by the Free
    Software Foundation; either version 3 of the License, or (at your
    option) any later version.

or

  * the GNU General Public License as published by the Free Software
    Foundation; either version 3 of the License, or (at your option) any
    later version.

or both in parallel, as here.

The PaGMO library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the PaGMO library.  If not,
see https://www.gnu.org/licenses/. */

#define BOOST_TEST_MODULE problem_type_traits_test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include <string>
#include <utility>
#include <vector>

#include <pagmo/problem.hpp>
#include <pagmo/type_traits.hpp>
#include <pagmo/types.hpp>

using namespace pagmo;

// No fitness.
struct f_00 {
};

// Various types of wrong fitness.
struct f_01 {
    void fitness();
};

struct f_02 {
    void fitness(const vector_double &);
};

struct f_03 {
    vector_double fitness(const vector_double &);
};

struct f_04 {
    vector_double fitness(vector_double &) const;
};

// Good one.
struct f_05 {
    vector_double fitness(const vector_double &) const;
};

BOOST_AUTO_TEST_CASE(has_fitness_test)
{
    BOOST_CHECK((!has_fitness<f_00>::value));
    BOOST_CHECK((!has_fitness<f_01>::value));
    BOOST_CHECK((!has_fitness<f_02>::value));
    BOOST_CHECK((!has_fitness<f_03>::value));
    BOOST_CHECK((!has_fitness<f_04>::value));
    BOOST_CHECK((has_fitness<f_05>::value));
}

// No fitness.
struct no_00 {
};

// Various types of wrong get_nobj.
struct no_01 {
    vector_double::size_type get_nobj();
};

struct no_02 {
    int get_nobj() const;
};

// Good one.
struct no_03 {
    vector_double::size_type get_nobj() const;
};

BOOST_AUTO_TEST_CASE(has_get_nobj_test)
{
    BOOST_CHECK((!has_fitness<no_00>::value));
    BOOST_CHECK((!has_fitness<no_01>::value));
    BOOST_CHECK((!has_fitness<no_02>::value));
    BOOST_CHECK((!has_fitness<no_03>::value));
}

struct db_00 {
};

// The good one.
struct db_01 {
    std::pair<vector_double, vector_double> get_bounds() const;
};

struct db_02 {
    std::pair<vector_double, vector_double> get_bounds();
};

struct db_03 {
    vector_double get_bounds() const;
};

struct db_04 {
};

BOOST_AUTO_TEST_CASE(has_bounds_test)
{
    BOOST_CHECK((!has_bounds<db_00>::value));
    BOOST_CHECK((has_bounds<db_01>::value));
    BOOST_CHECK((!has_bounds<db_02>::value));
    BOOST_CHECK((!has_bounds<db_03>::value));
    BOOST_CHECK((!has_bounds<db_04>::value));
}

struct c_00 {
};

// The good one.
struct c_01 {
    vector_double::size_type get_nec() const;
    vector_double::size_type get_nic() const;
};

struct c_02 {
    vector_double::size_type get_nec();
    vector_double::size_type get_nic() const;
};

struct c_03 {
    int get_nec() const;
    vector_double::size_type get_nic() const;
};

struct c_04 {
    vector_double::size_type get_nec() const;
    vector_double::size_type get_nic();
};

struct c_05 {
    vector_double::size_type get_nec() const;
    void get_nic() const;
};

struct c_06 {
    vector_double::size_type get_nec() const;
};

struct c_07 {
    vector_double::size_type get_nic() const;
};

BOOST_AUTO_TEST_CASE(has_e_constraints_test)
{
    BOOST_CHECK((!has_e_constraints<c_00>::value));
    BOOST_CHECK((has_e_constraints<c_01>::value));
    BOOST_CHECK((!has_e_constraints<c_02>::value));
    BOOST_CHECK((!has_e_constraints<c_03>::value));
    BOOST_CHECK((has_e_constraints<c_04>::value));
    BOOST_CHECK((has_e_constraints<c_05>::value));
    BOOST_CHECK((has_e_constraints<c_06>::value));
    BOOST_CHECK((!has_e_constraints<c_07>::value));
}

BOOST_AUTO_TEST_CASE(has_i_constraints_test)
{
    BOOST_CHECK((!has_i_constraints<c_00>::value));
    BOOST_CHECK((has_i_constraints<c_01>::value));
    BOOST_CHECK((has_i_constraints<c_02>::value));
    BOOST_CHECK((has_i_constraints<c_03>::value));
    BOOST_CHECK((!has_i_constraints<c_04>::value));
    BOOST_CHECK((!has_i_constraints<c_05>::value));
    BOOST_CHECK((!has_i_constraints<c_06>::value));
    BOOST_CHECK((has_i_constraints<c_07>::value));
}

struct i_00 {
};

// The good one.
struct i_01 {
    vector_double::size_type get_nix() const;
};

struct i_02 {
    vector_double::size_type get_nix();
};

struct i_03 {
    void get_nix() const;
};

struct i_04 {
    vector_double::size_type get_nixx() const;
};

BOOST_AUTO_TEST_CASE(has_integer_part_test)
{
    BOOST_CHECK((!has_integer_part<i_00>::value));
    BOOST_CHECK((has_integer_part<i_01>::value));
    BOOST_CHECK((!has_integer_part<i_02>::value));
    BOOST_CHECK((!has_integer_part<i_03>::value));
    BOOST_CHECK((!has_integer_part<i_04>::value));
}

struct n_00 {
};

// The good one.
struct n_01 {
    std::string get_name() const;
};

struct n_02 {
    std::string get_name();
};

struct n_03 {
    void get_name() const;
};

BOOST_AUTO_TEST_CASE(has_name_test)
{
    BOOST_CHECK((!has_name<n_00>::value));
    BOOST_CHECK((has_name<n_01>::value));
    BOOST_CHECK((!has_name<n_02>::value));
    BOOST_CHECK((!has_name<n_03>::value));
}

struct ei_00 {
};

// The good one.
struct ei_01 {
    std::string get_extra_info() const;
};

struct ei_02 {
    std::string get_extra_info();
};

struct ei_03 {
    void get_extra_info() const;
};

BOOST_AUTO_TEST_CASE(has_extra_info_test)
{
    BOOST_CHECK((!has_extra_info<ei_00>::value));
    BOOST_CHECK((has_extra_info<ei_01>::value));
    BOOST_CHECK((!has_extra_info<ei_02>::value));
    BOOST_CHECK((!has_extra_info<ei_03>::value));
}

struct grad_00 {
};

// The good one.
struct grad_01 {
    vector_double gradient(const vector_double &) const;
};

struct grad_02 {
    vector_double gradient(const vector_double &);
};

struct grad_03 {
    vector_double gradient(vector_double &) const;
};

struct grad_04 {
    void gradient(const vector_double &) const;
};

BOOST_AUTO_TEST_CASE(has_gradient_test)
{
    BOOST_CHECK((!has_gradient<grad_00>::value));
    BOOST_CHECK((has_gradient<grad_01>::value));
    BOOST_CHECK((!has_gradient<grad_02>::value));
    BOOST_CHECK((!has_gradient<grad_03>::value));
    BOOST_CHECK((!has_gradient<grad_04>::value));
}

struct ov_grad_00 {
};

// The good one.
struct ov_grad_01 {
    bool has_gradient() const;
};

struct ov_grad_02 {
    bool has_gradient();
};

struct ov_grad_03 {
    void has_gradient() const;
};

BOOST_AUTO_TEST_CASE(override_has_gradient_test)
{
    BOOST_CHECK((!override_has_gradient<ov_grad_00>::value));
    BOOST_CHECK((override_has_gradient<ov_grad_01>::value));
    BOOST_CHECK((!override_has_gradient<ov_grad_02>::value));
    BOOST_CHECK((!override_has_gradient<ov_grad_03>::value));
}

struct gs_00 {
};

// The good one.
struct gs_01 {
    sparsity_pattern gradient_sparsity() const;
};

struct gs_02 {
    sparsity_pattern gradient_sparsity();
};

struct gs_03 {
    int gradient_sparsity() const;
};

BOOST_AUTO_TEST_CASE(has_gradient_sparsity_test)
{
    BOOST_CHECK((!has_gradient_sparsity<gs_00>::value));
    BOOST_CHECK((has_gradient_sparsity<gs_01>::value));
    BOOST_CHECK((!has_gradient_sparsity<gs_02>::value));
    BOOST_CHECK((!has_gradient_sparsity<gs_03>::value));
}

struct ov_gs_00 {
};

// The good one.
struct ov_gs_01 {
    bool has_gradient_sparsity() const;
};

struct ov_gs_02 {
    bool has_gradient_sparsity();
};

struct ov_gs_03 {
    void has_gradient_sparsity() const;
};

BOOST_AUTO_TEST_CASE(override_has_gradient_sparsity_test)
{
    BOOST_CHECK((!override_has_gradient_sparsity<ov_gs_00>::value));
    BOOST_CHECK((override_has_gradient_sparsity<ov_gs_01>::value));
    BOOST_CHECK((!override_has_gradient_sparsity<ov_gs_02>::value));
    BOOST_CHECK((!override_has_gradient_sparsity<ov_gs_03>::value));
}

struct hess_00 {
};

// The good one.
struct hess_01 {
    std::vector<vector_double> hessians(const vector_double &) const;
};

struct hess_02 {
    std::vector<vector_double> hessians(const vector_double &);
};

struct hess_03 {
    std::vector<vector_double> hessians(vector_double &) const;
};

struct hess_04 {
    void hessians(const vector_double &) const;
};

BOOST_AUTO_TEST_CASE(has_hessians_test)
{
    BOOST_CHECK((!has_hessians<hess_00>::value));
    BOOST_CHECK((has_hessians<hess_01>::value));
    BOOST_CHECK((!has_hessians<hess_02>::value));
    BOOST_CHECK((!has_hessians<hess_03>::value));
    BOOST_CHECK((!has_hessians<hess_04>::value));
}

struct ov_hess_00 {
};

// The good one.
struct ov_hess_01 {
    bool has_hessians() const;
};

struct ov_hess_02 {
    bool has_hessians();
};

struct ov_hess_03 {
    void has_hessians() const;
};

BOOST_AUTO_TEST_CASE(override_has_hessians_test)
{
    BOOST_CHECK((!override_has_hessians<ov_hess_00>::value));
    BOOST_CHECK((override_has_hessians<ov_hess_01>::value));
    BOOST_CHECK((!override_has_hessians<ov_hess_02>::value));
    BOOST_CHECK((!override_has_hessians<ov_hess_03>::value));
}

struct hs_00 {
};

// The good one.
struct hs_01 {
    std::vector<sparsity_pattern> hessians_sparsity() const;
};

struct hs_02 {
    std::vector<sparsity_pattern> hessians_sparsity();
};

struct hs_03 {
    int hessians_sparsity() const;
};

BOOST_AUTO_TEST_CASE(has_hessians_sparsity_test)
{
    BOOST_CHECK((!has_hessians_sparsity<hs_00>::value));
    BOOST_CHECK((has_hessians_sparsity<hs_01>::value));
    BOOST_CHECK((!has_hessians_sparsity<hs_02>::value));
    BOOST_CHECK((!has_hessians_sparsity<hs_03>::value));
}

struct ov_hs_00 {
};

// The good one.
struct ov_hs_01 {
    bool has_hessians_sparsity() const;
};

struct ov_hs_02 {
    bool has_hessians_sparsity();
};

struct ov_hs_03 {
    void has_hessians_sparsity() const;
};

BOOST_AUTO_TEST_CASE(override_has_hessians_sparsity_test)
{
    BOOST_CHECK((!override_has_hessians_sparsity<ov_hs_00>::value));
    BOOST_CHECK((override_has_hessians_sparsity<ov_hs_01>::value));
    BOOST_CHECK((!override_has_hessians_sparsity<ov_hs_02>::value));
    BOOST_CHECK((!override_has_hessians_sparsity<ov_hs_03>::value));
}

struct hss_00 {
};

// The good one.
struct hss_01 {
    void set_seed(unsigned);
};

struct hss_02 {
    void set_seed(unsigned) const;
};

struct hss_03 {
    void set_seed(int);
};

struct hss_04 {
    double set_seed(unsigned);
};

BOOST_AUTO_TEST_CASE(has_set_seed_test)
{
    BOOST_CHECK((!has_set_seed<hss_00>::value));
    BOOST_CHECK((has_set_seed<hss_01>::value));
    BOOST_CHECK((has_set_seed<hss_02>::value));
    BOOST_CHECK((has_set_seed<hss_03>::value));
    BOOST_CHECK((!has_set_seed<hss_04>::value));
}

struct ov_hss_00 {
};

// The good one.
struct ov_hss_01 {
    bool has_set_seed() const;
};

struct ov_hss_02 {
    bool has_set_seed();
};

struct ov_hss_03 {
    void has_set_seed() const;
};

BOOST_AUTO_TEST_CASE(override_has_set_seed_test)
{
    BOOST_CHECK((!override_has_set_seed<ov_hss_00>::value));
    BOOST_CHECK((override_has_set_seed<ov_hss_01>::value));
    BOOST_CHECK((!override_has_set_seed<ov_hss_02>::value));
    BOOST_CHECK((!override_has_set_seed<ov_hss_03>::value));
}