Commit 9f384106 authored by incardon's avatar incardon

Adding PS-CMA-ES

parent 8c7a988c
master
#ifndef F15_CEC_CONST
#define F15_CEC_CONST
#include "Eigen/Dense"
const double f15_const[10][100] = {3.3253000e+000,-1.2835000e+000,1.8984000e+000,-4.0950000e-001,8.8100000e-002,2.7580000e+000,9.7760000e-001,-1.8090000e+000,-2.4957000e+000,2.7367000e+000,-2.8961000e+000,-2.9413000e+000,3.2682000e+000,3.6495000e+000,5.0310000e-001,-4.2187000e+000,-7.8880000e-001,3.8384000e+000,1.3397000e+000,2.9312000e+000,-3.2869000e+000,3.6213000e+000,3.4834000e+000,-4.2260000e+000,-1.0784000e+000,-4.4730000e-001,2.7601000e+000,4.6200000e-002,4.3606000e+000,-2.0347000e+000,-3.5089000e+000,-2.2028000e+000,-1.6626000e+000,-1.7293000e+000,1.8300000e-002,-4.0478000e+000,-1.4034000e+000,-1.7866000e+000,-2.4212000e+000,-7.4340000e-001,-1.5438000e+000,-3.0272000e+000,2.6055000e+000,-3.1007000e+000,2.8010000e+000,1.4532000e+000,2.9887000e+000,1.2490000e-001,3.0169000e+000,-1.3140000e+000,3.4259000e+000,2.4992000e+000,9.7940000e-001,-1.8358000e+000,-3.8253000e+000,2.7079000e+000,1.9604000e+000,1.3197000e+000,-2.4128000e+000,-4.7550000e-001,2.1681000e+000,3.2344000e+000,3.3590000e+000,-1.4400000e-002,-1.8732000e+000,-1.9496000e+000,4.7110000e-001,8.2110000e-001,-1.9980000e-001,3.7350000e+000,-3.3720000e-001,-1.7267000e+000,-6.5950000e-001,-3.0531000e+000,-4.1052000e+000,2.3991000e+000,-3.2670000e-001,1.3279000e+000,3.7907000e+000,-1.8800000e+000,2.9056000e+000,1.8643000e+000,-5.2800000e-001,-1.9298000e+000,-8.5830000e-001,6.0570000e-001,-1.4152000e+000,4.0411000e+000,2.1519000e+000,3.6699000e+000,-1.3395000e+000,1.5661000e+000,-2.4511000e+000,-2.3292000e+000,1.2750000e-001,-3.0202000e+000,-1.0900000e+000,-3.6965000e+000,-1.1674000e+000,1.5488000e+000\
,-2.2465000e+000,3.9382000e+000,-7.9990000e-001,-4.2205000e+000,-2.9393000e+000,-4.3433000e+000,1.6348000e+000,3.1011000e+000,-9.2690000e-001,-2.5328000e+000,1.1839000e+000,-2.9094000e+000,2.8157000e+000,-2.2581000e+000,-1.2020000e-001,4.1264000e+000,-3.5397000e+000,9.9270000e-001,-3.5492000e+000,3.5247000e+000,1.3420000e-001,-3.6413000e+000,1.8572000e+000,-3.8112000e+000,-5.1770000e-001,-4.3274000e+000,-3.9499000e+000,1.6129000e+000,-3.6689000e+000,3.7438000e+000,-2.7323000e+000,-3.7832000e+000,-8.9120000e-001,2.7046000e+000,4.3176000e+000,1.6330000e+000,-7.3310000e-001,-1.7864000e+000,7.8770000e-001,-7.4840000e-001,-4.2517000e+000,1.9060000e+000,-2.8498000e+000,-1.5533000e+000,4.6900000e-001,-2.4370000e+000,-1.4181000e+000,2.5617000e+000,2.5139000e+000,1.4288000e+000,-4.4704000e+000,1.7249000e+000,-3.3660000e+000,-3.3114000e+000,3.7927000e+000,4.3542000e+000,-4.1577000e+000,-2.0797000e+000,-4.1467000e+000,9.2950000e-001,-3.0638000e+000,3.2160000e-001,-3.3978000e+000,-1.0110000e+000,2.9571000e+000,-2.8415000e+000,3.9917000e+000,-8.3070000e-001,-2.4358000e+000,-4.4600000e-001,-4.3041000e+000,-1.6925000e+000,2.2654000e+000,3.4818000e+000,4.1474000e+000,-2.9950000e-001,-3.9534000e+000,4.3495000e+000,-1.9537000e+000,4.3235000e+000,1.8070000e+000,1.8991000e+000,4.3600000e-001,-2.7083000e+000,-2.8008000e+000,-3.8717000e+000,-2.8596000e+000,3.3523000e+000,1.0176000e+000,3.0750000e-001,1.0646000e+000,-2.1500000e+000,-2.8102000e+000,-4.4798000e+000,5.4910000e-001,-3.5628000e+000,-2.9116000e+000,4.2015000e+000,-4.0054000e+000,-1.7860000e+000\
,1.7378000e+000,-4.4943000e+000,3.1910000e-001,-3.2414000e+000,1.2388000e+000,2.4878000e+000,-4.1218000e+000,-2.6083000e+000,-2.8100000e-001,3.4336000e+000,-9.1790000e-001,1.8598000e+000,3.0641000e+000,-3.6210000e-001,5.5760000e-001,-2.4441000e+000,-2.2366000e+000,-5.2660000e-001,4.3657000e+000,1.9230000e+000,4.1786000e+000,-4.0957000e+000,-3.1427000e+000,3.2389000e+000,1.5794000e+000,-4.2122000e+000,3.6131000e+000,-3.7048000e+000,-1.1209000e+000,-1.3074000e+000,3.3170000e-001,-7.8830000e-001,-4.1121000e+000,3.4491000e+000,8.0040000e-001,4.6400000e-001,-2.3190000e+000,-1.5837000e+000,2.6929000e+000,-1.0506000e+000,2.1719000e+000,-1.4665000e+000,2.9197000e+000,1.1862000e+000,2.7782000e+000,-1.8744000e+000,3.7281000e+000,-1.9880000e+000,1.7553000e+000,-2.2000000e-003,1.8093000e+000,-1.8750000e-001,1.0918000e+000,1.4909000e+000,-3.6830000e-001,-2.6889000e+000,3.4836000e+000,-3.8560000e+000,2.1800000e+000,2.3080000e-001,-3.9911000e+000,1.7939000e+000,2.1553000e+000,-6.7330000e-001,3.1100000e-002,3.1810000e-001,1.1508000e+000,4.0126000e+000,3.3660000e-001,1.6810000e-001,-2.7874000e+000,-2.8053000e+000,2.0216000e+000,-1.2160000e+000,-1.0253000e+000,-4.3512000e+000,1.0470000e+000,-4.2517000e+000,1.1389000e+000,1.9587000e+000,-2.1917000e+000,-3.0772000e+000,1.7597000e+000,-1.8843000e+000,6.5440000e-001,-3.1522000e+000,-2.9200000e+000,3.8666000e+000,-3.8922000e+000,8.7910000e-001,-3.5768000e+000,-8.5390000e-001,2.5625000e+000,4.2585000e+000,-4.4818000e+000,-3.8622000e+000,3.3085000e+000,-4.3596000e+000,8.1780000e-001,9.1200000e-001\
,-1.5504000e+000,-4.3339000e+000,8.9780000e-001,-1.3839000e+000,4.2338000e+000,2.6283000e+000,-8.5900000e-001,-1.8942000e+000,1.7407000e+000,-1.2537000e+000,1.3161000e+000,-3.1738000e+000,2.8559000e+000,5.5400000e-002,4.4044000e+000,-9.9420000e-001,-4.2987000e+000,3.1463000e+000,2.7438000e+000,5.7790000e-001,-1.4390000e-001,1.2750000e-001,6.6570000e-001,-4.2310000e+000,-9.9960000e-001,-5.8970000e-001,-4.5240000e-001,1.2225000e+000,-2.2496000e+000,-8.3210000e-001,3.0274000e+000,-2.5083000e+000,-2.9410000e-001,4.0227000e+000,5.5750000e-001,-1.7082000e+000,-3.4266000e+000,-1.3186000e+000,-4.4435000e+000,3.8150000e+000,-2.4026000e+000,-1.9805000e+000,-3.9941000e+000,1.7521000e+000,-2.4486000e+000,-3.5640000e+000,2.8962000e+000,-4.0694000e+000,-2.1251000e+000,-6.6470000e-001,8.6770000e-001,1.6697000e+000,-3.1888000e+000,2.2569000e+000,-4.0996000e+000,-2.2851000e+000,3.3932000e+000,-2.1120000e+000,-4.2880000e-001,-2.5799000e+000,1.4335000e+000,1.8559000e+000,3.8649000e+000,-2.8086000e+000,-4.2600000e+000,3.8483000e+000,-1.1864000e+000,3.9864000e+000,3.1897000e+000,-3.5196000e+000,5.1700000e-002,-1.6459000e+000,6.2250000e-001,1.6034000e+000,-2.5510000e-001,2.3951000e+000,-2.9564000e+000,3.4064000e+000,-2.6920000e+000,-2.0972000e+000,-4.2272000e+000,-4.2909000e+000,-1.9785000e+000,2.6433000e+000,-2.4360000e+000,-3.6061000e+000,-3.3946000e+000,1.2882000e+000,1.3625000e+000,-2.2262000e+000,-5.2730000e-001,2.1000000e-002,-2.2951000e+000,3.5702000e+000,2.3550000e+000,-3.5396000e+000,4.3945000e+000,-7.5000000e-003,1.5150000e+000,-1.8038000e+000\
,-2.7358000e+000,4.8530000e-001,2.8932000e+000,1.7750000e-001,1.5936000e+000,2.3591000e+000,3.4123000e+000,-3.1076000e+000,3.8696000e+000,2.3145000e+000,-3.7018000e+000,-4.3772000e+000,-2.1313000e+000,-1.1746000e+000,2.2956000e+000,1.3502000e+000,3.2284000e+000,1.6749000e+000,-4.3424000e+000,-1.0206000e+000,-4.3462000e+000,-1.7030000e+000,1.6973000e+000,-1.5694000e+000,-3.0295000e+000,4.1132000e+000,-2.1307000e+000,-3.9905000e+000,-4.0260000e-001,-1.6620000e+000,-2.4780000e-001,-3.2789000e+000,-1.6622000e+000,-1.2509000e+000,3.8842000e+000,-1.5414000e+000,3.8323000e+000,3.8892000e+000,9.1310000e-001,1.0501000e+000,9.8150000e-001,-2.0173000e+000,-1.4322000e+000,-2.4151000e+000,1.0046000e+000,-3.6765000e+000,-1.1788000e+000,2.7020000e-001,-2.8760000e-001,-9.5390000e-001,2.1957000e+000,-1.2470000e-001,-4.1052000e+000,3.5400000e+000,-4.3878000e+000,2.9056000e+000,4.2666000e+000,3.9671000e+000,3.5829000e+000,3.9816000e+000,-1.4905000e+000,-1.0256000e+000,2.7029000e+000,2.6330000e-001,-1.1798000e+000,2.3091000e+000,-2.5930000e-001,-7.0060000e-001,4.3161000e+000,3.7458000e+000,4.0370000e-001,-2.0975000e+000,4.3694000e+000,2.4717000e+000,4.1478000e+000,-3.5657000e+000,-1.0330000e-001,3.7534000e+000,1.9894000e+000,3.4790000e+000,-1.8541000e+000,3.8470000e+000,1.1231000e+000,4.4799000e+000,-3.9805000e+000,1.8823000e+000,-1.0147000e+000,4.1805000e+000,4.3017000e+000,1.4542000e+000,2.0347000e+000,2.7745000e+000,-1.6727000e+000,3.5495000e+000,-1.1870000e-001,-3.1237000e+000,-3.2825000e+000,-2.3430000e-001,1.4084000e+000,2.5355000e+000\
,-1.8717000e+000,1.8285000e+000,-3.7085000e+000,2.1660000e+000,2.7980000e-001,-2.5635000e+000,-2.1321000e+000,-2.9868000e+000,-2.5391000e+000,-1.3354000e+000,-2.7000000e-001,-3.0712000e+000,-1.7479000e+000,4.2000000e-002,-3.8396000e+000,-3.3518000e+000,3.2361000e+000,3.9031000e+000,-3.8211000e+000,-9.0720000e-001,-4.2347000e+000,-3.2265000e+000,-1.3196000e+000,-4.0690000e-001,2.2933000e+000,-1.8828000e+000,-1.7421000e+000,-1.3624000e+000,2.2034000e+000,-1.5554000e+000,3.9148000e+000,3.0060000e+000,-2.7808000e+000,3.1430000e+000,-4.3288000e+000,3.1607000e+000,2.9885000e+000,3.4770000e+000,-3.2540000e+000,3.5659000e+000,-2.3289000e+000,-6.3320000e-001,-1.3463000e+000,1.4149000e+000,-3.1376000e+000,2.8234000e+000,-1.7904000e+000,1.4993000e+000,-2.8887000e+000,2.1925000e+000,-2.6683000e+000,-4.2745000e+000,3.9368000e+000,3.6760000e+000,3.2610000e-001,1.3481000e+000,-2.0259000e+000,-3.5200000e-001,4.5020000e-001,1.2222000e+000,-1.7436000e+000,3.0571000e+000,1.5054000e+000,5.9900000e-001,-3.7241000e+000,3.8567000e+000,-1.6305000e+000,-1.7861000e+000,-4.2061000e+000,3.1688000e+000,-2.5142000e+000,1.4365000e+000,-4.2584000e+000,-2.9095000e+000,-2.7201000e+000,-3.9780000e+000,-3.8197000e+000,3.2116000e+000,-2.0274000e+000,3.3790000e+000,2.0176000e+000,3.7376000e+000,-1.7626000e+000,3.1218000e+000,1.6559000e+000,3.3415000e+000,1.5242000e+000,1.7250000e+000,2.0883000e+000,3.4093000e+000,-1.7778000e+000,-2.4508000e+000,-1.7771000e+000,2.9953000e+000,-9.4000000e-003,-1.5103000e+000,4.3057000e+000,-1.2379000e+000,2.5305000e+000,-5.9280000e-001\
,-3.9243000e+000,-2.7541000e+000,-2.9730000e-001,1.3850000e-001,-1.8557000e+000,-2.6559000e+000,-3.6582000e+000,-7.3010000e-001,-1.1095000e+000,3.3570000e+000,3.0578000e+000,-9.7650000e-001,3.6632000e+000,4.0256000e+000,-3.2321000e+000,-1.0683000e+000,-2.4430000e-001,-2.6259000e+000,-3.6503000e+000,-2.2150000e-001,3.5501000e+000,1.5428000e+000,-2.3871000e+000,3.3152000e+000,-3.1084000e+000,-6.1890000e-001,1.6179000e+000,-4.4262000e+000,3.7020000e-001,2.6440000e+000,-2.1320000e-001,-3.0420000e+000,3.9154000e+000,1.1186000e+000,-4.2283000e+000,-6.9900000e-002,-2.6670000e+000,-2.9021000e+000,8.3800000e-002,5.8690000e-001,4.4932000e+000,-2.5687000e+000,2.3839000e+000,-5.0720000e-001,-2.3617000e+000,-2.2267000e+000,-1.8803000e+000,4.0205000e+000,-4.3917000e+000,-1.3007000e+000,2.2299000e+000,-3.8293000e+000,-2.6600000e-002,-4.1760000e-001,3.4822000e+000,-4.3770000e+000,1.7739000e+000,-3.0710000e+000,-1.9767000e+000,2.6253000e+000,4.2554000e+000,-2.3100000e-002,9.2870000e-001,1.5838000e+000,-3.7755000e+000,-1.7040000e-001,-3.5334000e+000,1.5598000e+000,1.9987000e+000,8.3790000e-001,-4.3789000e+000,-9.0710000e-001,-2.3975000e+000,-3.0816000e+000,-2.6495000e+000,-1.1391000e+000,1.1763000e+000,-4.3940000e-001,-2.1198000e+000,-1.2030000e-001,3.7726000e+000,2.3534000e+000,-3.5806000e+000,4.4012000e+000,-2.5145000e+000,-3.7623000e+000,-2.4466000e+000,-1.0585000e+000,-3.6637000e+000,-3.1811000e+000,-2.3190000e-001,-3.0277000e+000,4.3686000e+000,-3.8050000e-001,5.2390000e-001,-3.1020000e+000,3.6013000e+000,-3.2767000e+000,8.7490000e-001,3.7456000e+000\
,-4.4362000e+000,-1.0142000e+000,2.6180000e-001,2.5649000e+000,9.5110000e-001,-1.2742000e+000,-2.0990000e+000,2.0800000e-001,-2.2216000e+000,1.9331000e+000,-3.0628000e+000,2.5846000e+000,-3.4871000e+000,-1.4314000e+000,2.9744000e+000,-1.6853000e+000,1.7319000e+000,1.1900000e-002,-2.2333000e+000,-3.6649000e+000,6.9610000e-001,-1.3300000e+000,-4.0811000e+000,2.3000000e-001,1.0150000e+000,2.4349000e+000,2.6735000e+000,-4.0300000e+000,6.6320000e-001,-4.3627000e+000,3.9411000e+000,-2.8084000e+000,-1.2894000e+000,3.2805000e+000,8.7000000e-002,7.1320000e-001,1.8993000e+000,2.5630000e+000,-3.2035000e+000,1.8894000e+000,-1.0149000e+000,4.3570000e+000,2.6677000e+000,-3.4265000e+000,-2.6617000e+000,1.4306000e+000,-3.2000000e-001,3.4067000e+000,-6.8620000e-001,-2.6620000e-001,-2.2974000e+000,6.6110000e-001,-1.1390000e-001,-2.7930000e-001,-4.0534000e+000,-2.9895000e+000,2.4600000e+000,4.0680000e+000,6.1130000e-001,-2.1785000e+000,3.5749000e+000,4.2679000e+000,7.2050000e-001,-3.4930000e-001,-2.4683000e+000,2.8913000e+000,-2.7926000e+000,-4.4259000e+000,1.6203000e+000,-7.0780000e-001,6.6900000e-002,3.3265000e+000,-8.9650000e-001,3.8144000e+000,1.8644000e+000,-3.8740000e+000,-4.4329000e+000,-2.7533000e+000,1.5199000e+000,2.4951000e+000,-4.0784000e+000,-1.5782000e+000,2.4547000e+000,1.3106000e+000,-1.6517000e+000,-2.7385000e+000,-1.8217000e+000,2.5841000e+000,3.5956000e+000,-4.4051000e+000,1.9856000e+000,-1.0218000e+000,1.1335000e+000,3.2501000e+000,-1.1250000e-001,-3.3356000e+000,7.3370000e-001,8.1000000e-001,-3.4267000e+000,-1.7573000e+000\
,-1.4198000e+000,3.6078000e+000,2.0771000e+000,2.7252000e+000,-3.3609000e+000,-2.0665000e+000,-3.8042000e+000,-3.9882000e+000,1.9212000e+000,2.7170000e+000,-3.6992000e+000,3.0584000e+000,3.1365000e+000,2.5994000e+000,-2.2861000e+000,3.2691000e+000,-4.3166000e+000,1.5112000e+000,-3.4301000e+000,-3.1168000e+000,-4.8610000e-001,-2.1520000e-001,-4.4595000e+000,-4.4585000e+000,2.7490000e+000,-3.6245000e+000,-4.0940000e+000,3.0953000e+000,1.8911000e+000,3.3585000e+000,1.4740000e-001,5.5140000e-001,-4.1774000e+000,2.6014000e+000,-1.8385000e+000,-3.6295000e+000,-2.1696000e+000,-8.1170000e-001,2.7015000e+000,-3.0258000e+000,-3.0333000e+000,-8.4910000e-001,-2.6945000e+000,2.5817000e+000,-3.9572000e+000,1.5827000e+000,4.4099000e+000,-1.1827000e+000,2.0778000e+000,-4.1023000e+000,-8.0790000e-001,-4.3809000e+000,-3.5968000e+000,3.3155000e+000,-2.2298000e+000,3.5023000e+000,-1.4810000e-001,1.9668000e+000,-2.9158000e+000,2.4857000e+000,4.1099000e+000,-4.1160000e+000,-1.6791000e+000,-3.2401000e+000,1.3775000e+000,9.0580000e-001,3.7376000e+000,2.2668000e+000,3.8236000e+000,-9.9970000e-001,1.4778000e+000,1.6980000e-001,-1.4464000e+000,7.0470000e-001,-2.8071000e+000,-8.7970000e-001,-1.8638000e+000,1.7548000e+000,-1.9996000e+000,1.5675000e+000,2.9245000e+000,-1.1090000e-001,-2.0504000e+000,-1.2071000e+000,-2.4366000e+000,-3.8301000e+000,4.1004000e+000,-4.1967000e+000,-9.3300000e-002,-1.1239000e+000,2.9965000e+000,9.2280000e-001,-1.4416000e+000,-9.5000000e-003,-3.3145000e+000,3.4467000e+000,-9.8670000e-001,2.5468000e+000,3.5220000e-001,3.4812000e+000\
,-2.4369000e+000,-2.3015000e+000,1.1539000e+000,1.5121000e+000,-2.4170000e-001,2.0860000e-001,-1.4078000e+000,3.2117000e+000,1.6180000e-001,-2.6028000e+000,-5.2800000e-001,-1.7132000e+000,-4.4610000e-001,-3.6180000e+000,2.4411000e+000,1.5120000e+000,6.9000000e-002,-1.1301000e+000,-1.9017000e+000,-2.7420000e+000,-2.6130000e+000,-3.4728000e+000,2.7522000e+000,4.2066000e+000,-6.1710000e-001,-2.9867000e+000,3.4816000e+000,3.3065000e+000,-3.1555000e+000,2.4976000e+000,1.4455000e+000,-1.9139000e+000,-2.4110000e+000,-3.8611000e+000,4.4870000e+000,3.3597000e+000,1.9467000e+000,-3.0049000e+000,2.6107000e+000,3.7599000e+000,-2.3608000e+000,-4.4512000e+000,-2.7817000e+000,3.6587000e+000,-4.3400000e-002,1.3095000e+000,-4.2113000e+000,1.0998000e+000,1.5087000e+000,1.8103000e+000,2.7342000e+000,1.6980000e-001,4.1891000e+000,-4.2409000e+000,4.1945000e+000,-1.4423000e+000,2.0603000e+000,3.5687000e+000,2.2500000e-001,2.9241000e+000,3.2211000e+000,2.0296000e+000,2.3792000e+000,2.8299000e+000,1.1196000e+000,3.5512000e+000,-3.7236000e+000,4.1712000e+000,-7.0130000e-001,-3.1732000e+000,3.7700000e-002,4.3992000e+000,-1.0487000e+000,-3.2646000e+000,4.1234000e+000,-1.2268000e+000,3.0004000e+000,2.2522000e+000,-1.4002000e+000,2.0008000e+000,2.7492000e+000,3.2190000e-001,2.3040000e-001,1.9087000e+000,6.6720000e-001,9.4710000e-001,-1.3234000e+000,-1.1531000e+000,1.6404000e+000,3.7113000e+000,1.1623000e+000,2.8554000e+000,-2.2389000e+000,-1.4650000e+000,-3.6592000e+000,-7.3410000e-001,-2.8758000e+000,2.2515000e+000,1.5780000e+000,-3.7634000e+000};
const double f15_cec_bias = 120;
const double job_lambda[10] = {1.0,1.0,10.0,10.0,5.0/60.0,5.0/60.0,5.0/32.0,5.0/32.0,5.0/100.0,5.0/100.0};
Eigen::VectorXd f15_o[10];
double f15_max[10];
double bias[10] = {0,100,200,300,400,500,600,700,800,900};
#endif
/*
* f15_cec_fun.hpp
*
* Created on: Jan 14, 2018
* Author: i-bird
*/
#ifndef EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_
#define EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_
#include "f15_cec_const.hpp"
#include <limits>
#include <math.h>
template<unsigned int dim>
void Job15(int funcnr,Eigen::VectorXd & vars,double & res)
{
// local used vars
double sum,sum1,sum2,prod,e1,e2;
int i,j,k;
// weierstrass vars
int Kmax = 20;
const double a_c = 0.5;
const double b_c = 3.0;
if (funcnr < 2)
{
// rastrigin
sum = 10.0 * dim;
for (size_t i = 0 ; i < dim ; i++)
{
sum += vars(i)*vars(i);
sum -= 10.0*cos(2*M_PI*vars[i]);
}
res = sum;
}
else if (funcnr < 4)
{
// weierstrass
sum1 = 0.0;
sum2 = 0.0;
double a_k = 1.0;
double b_k = 1.0;
for (size_t i = 0 ; i < dim ; i++)
{
a_k = 1.0;
b_k = 1.0;
for (size_t j = 0 ; j <= Kmax ; j++, a_k *= a_c,b_k *= b_c)
{
sum1 = sum1 + a_k * cos((M_PI)*2.0 * b_k * (vars(i)+0.5));
}
}
a_k = 1.0;
b_k = 1.0;
for (size_t j = 0 ; j <= Kmax ; j++, a_k *= a_c, b_k *= b_c)
{
sum2 = sum2 + a_k * cos((M_PI)*2.0 * b_k * (0.5));
}
res = sum1 - sum2*dim;
}
else if (funcnr < 6)
{
// griewank
prod = 1;
sum = 0.0;
for (size_t i = 1 ; i <= dim ; i++)
{
sum= sum + (vars(i-1)*vars(i-1))/4000.0;
prod=prod * cos(vars(i-1)/(sqrt(double(i))));
}
res = sum-prod+1;
}
else if (funcnr < 8)
{
// ackley
e1 = 0.0;
e2 = 0.0;
for (size_t i = 0 ; i < dim ; i++)
{
e1 = e1 + vars(i)*vars(i);
e2 = e2 + cos(2.0*M_PI*vars(i));
}
res = exp(1.0) + 20.0 - 20*exp(-0.2*sqrt(e1/dim));
res = res - exp(e2/dim);
}
else if (funcnr <= 10)
{
// sphere
sum = vars.transpose() * vars;
res = sum;
}
}
template<unsigned int dim>
double hybrid_composition(Eigen::VectorXd & vars)
{
double ZBQLNOR;
//local used vars
double wMax,sumSqr,wSum,w1mMaxPow;
int i,j,k;
double sumF,t_res;
Eigen::VectorXd job_z[10];
for (size_t i = 0 ; i < 10 ; i++)
{job_z[i].resize(dim);}
double job_w[10];
double res = 0.0;
for (size_t i = 0 ; i < dim ; i++)
{
if (vars[i] < -5.0 || vars[i] > 5.0)
{return std::numeric_limits<double>::infinity();}
}
// get the raw weights
wMax = - std::numeric_limits<double>::max();
for (size_t i = 0; i < 10 ; i++)
{
sumSqr = 0.0;
//Shift the Input
job_z[i] = vars - f15_o[i];
sumSqr += (job_z[i].transpose() * job_z[i]);
job_w[i] = exp(-1.0 * sumSqr / (2.0 * dim));
if (wMax < job_w[i])
{wMax = job_w[i];}
}
// Modify the weights
wSum = 0.0;
w1mMaxPow = 1.0 - wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax;
for (size_t i = 0; i < 10 ; i++)
{
if (job_w[i] != wMax)
{job_w[i] = job_w[i]* w1mMaxPow;};
wSum = wSum + job_w[i];
}
// Normalize the weights
for (size_t i = 0; i < 10 ; i++)
{job_w[i] /= wSum;}
sumF = 0.0;
for (size_t i = 0; i < 10 ; i++)
{
job_z[i] = job_z[i] / job_lambda[i];
//calling the basic functions
Job15<dim>(i,job_z[i],t_res);
sumF = sumF + job_w[i] * (2000.0*t_res/f15_max[i] + bias[i]);
}
res = sumF + 120;
return res;
}
template<unsigned int dim>
void prepare_f15()
{
// load f15_o
for (size_t j = 0 ; j < 10 ; j++)
{
Eigen::VectorXd fmp(dim);
f15_o[j].resize(dim);
for (size_t i = 0 ; i < dim ; i++)
{
f15_o[j](i) = f15_const[j][i];
fmp(i) = 5.0 / job_lambda[j];
}
double result;
Job15<dim>(j,fmp,result);
f15_max[j] = fabs(result);
}
}
#endif /* EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_ */
This diff is collapsed.
......@@ -877,9 +877,9 @@ template<typename grid> void calc_rhs(grid & g_vort, grid & g_vel, grid & g_dwp)
// calculate several pre-factors for the stencil finite
// difference
float fac1 = 2.0f*nu/(g_vort.spacing(0)*g_vort.spacing(0));
float fac2 = 2.0f*nu/(g_vort.spacing(1)*g_vort.spacing(1));
float fac3 = 2.0f*nu/(g_vort.spacing(2)*g_vort.spacing(2));
float fac1 = 1.0f*nu/(g_vort.spacing(0)*g_vort.spacing(0));
float fac2 = 1.0f*nu/(g_vort.spacing(1)*g_vort.spacing(1));
float fac3 = 1.0f*nu/(g_vort.spacing(2)*g_vort.spacing(2));
float fac4 = 0.5f/(g_vort.spacing(0));
float fac5 = 0.5f/(g_vort.spacing(1));
......
......@@ -121,7 +121,7 @@ class domain_nn_calculator_cart
// +2 is padding
for (size_t j = 0 ; j < dim ; j++)
sz[j] = proc_box.getHigh(j) - proc_box.getLow(j) + 2 + 1;
{sz[j] = proc_box.getHigh(j) - proc_box.getLow(j) + 2 + 1;}
gs.setDimensions(sz);
......@@ -130,7 +130,7 @@ class domain_nn_calculator_cart
g.setMemory();
for (size_t i = 0 ; i < dim ; i++)
one.set_d(i,1);
{one.set_d(i,1);}
// Calculate the csr neighborhood
openfpm::vector<std::pair<grid_key_dx<dim>,grid_key_dx<dim>>> csr;
......@@ -191,7 +191,7 @@ class domain_nn_calculator_cart
sub_keys.last().NN_subsub.resize(g.template get<0>(key).size());
for (size_t i = 0 ; i < g.template get<0>(key).size() ; i++)
sub_keys.last().NN_subsub.get(i) = g.template get<0>(key).get(i) - one;
{sub_keys.last().NN_subsub.get(i) = g.template get<0>(key).get(i) - one;}
}
++it;
......
......@@ -83,6 +83,12 @@ struct Box_sub
//! see ie_ghost follow sector explanation
comb<dim> cmb;
//! Constructor reset cmb
Box_sub()
{
cmb.zero();
}
};
//! Particular case for local internal ghost boxes
......
......@@ -602,18 +602,6 @@ class grid_dist_id : public grid_dist_id_comm<dim,St,T,Decomposition,Memory,devi
protected:
/*! \brief Get the point where it start the origin of the grid of the sub-domain i
*
* \param i sub-domain
*
* \return the point
*
*/
Point<dim,St> getOffset(size_t i)
{
return pmul(Point<dim,St>(gdb_ext.get(i).origin), cd_sm.getCellBox().getP2());
}
/*! \brief Given a local sub-domain i with a local grid Domain + ghost return the part of the local grid that is domain
*
* \param i sub-domain
......@@ -687,6 +675,18 @@ public:
return domain;
}
/*! \brief Get the point where it start the origin of the grid of the sub-domain i
*
* \param i sub-domain
*
* \return the point
*
*/
Point<dim,St> getOffset(size_t i)
{
return pmul(Point<dim,St>(gdb_ext.get(i).origin), cd_sm.getCellBox().getP2()) + getDomain().getP1();
}
/*! \brief Get the spacing of the grid in direction i
*
* \param i dimension
......
......@@ -568,11 +568,6 @@ public:
while (it.isNext())
{
//auto key = it.get();
//if (g.template get<0>(key) != 1)
//std::cout << "WRONG???????" << std::endl;
++it;
count++;
}
......@@ -581,13 +576,11 @@ public:
Point<dim,St> p;
for (size_t n = 0; n < dim; n++)
p.get(n) = g.getGrid().getBox().getHigh(n);
//std::cout << "G after resize: (" << g.getGrid().getBox().getLow(0) << "; " << g.getGrid().getBox().getLow(1) << "); (" << g.getGrid().getBox().getHigh(0) << "; " << g.getGrid().getBox().getHigh(1) << ")" << std::endl;
{p.get(n) = g.getGrid().getBox().getHigh(n);}
Point<dim,St> point;
for (size_t n = 0; n < dim; n++)
point.get(n) = (b.getHigh(n) + b.getLow(n))/2;
{point.get(n) = (b.getHigh(n) + b.getLow(n))/2;}
for (size_t j = 0; j < gdb_ext.size(); j++)
{
......@@ -612,7 +605,6 @@ public:
std::string str = key.to_string();
grid_key_dx<dim> key2 = key - start;
//std::cout << "Key: " << str << std::endl;
loc_grid.get(j).get_o(key) = g.get_o(key2);
count2++;
......@@ -622,7 +614,6 @@ public:
}
}
}
//std::cout << "Count after: " << count2 << std::endl;
}
/*! \brief Label intersection grids for mappings
......
......@@ -1871,6 +1871,27 @@ BOOST_AUTO_TEST_CASE ( grid_ghost_correction )
Test_ghost_correction(domain,k,4);
}
BOOST_AUTO_TEST_CASE ( grid_basic_functions )
{
auto & v_cl = create_vcluster();
if (v_cl.getProcessingUnits() != 1)
{return;}
size_t sz[2] = {(size_t)8,(size_t)8};
periodicity<2> bc = {PERIODIC,PERIODIC};
Ghost<2,long int> g(1);
Box<2,double> domain({-1.0,-1.0},{1.0,1.0});
grid_dist_id<2, double, aggregate<double>> grid(sz,domain,g,bc);
std::cout << "Offset: " << grid.getOffset(0).toString() << std::endl;
BOOST_REQUIRE_EQUAL(grid.getOffset(0)[0],-1.25);
BOOST_REQUIRE_EQUAL(grid.getOffset(0)[1],-1.25);
}
BOOST_AUTO_TEST_CASE ( grid_overflow_round_off_error )
{
size_t numGridPoint = 100;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment