diff --git a/ChangeLog b/ChangeLog index 6af6b2645499284e06c57227c21d5632d52d5738..b2f50301d2ac181ab2609daba62233ed3d6ba57e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-03: NOMAD 3.7 + -Anisotropic scaling + -Block evaluations 2013-03: NOMAD 3.6 -ortho n+1 2011-01: NOMAD 3.5 diff --git a/README b/README index 96df2cf5b1780d15a5667ef47fc3758e112241ca..4966d0ca513aa3232b18f363a00667390907fe0d 100644 --- a/README +++ b/README @@ -1,115 +1,114 @@ -####################################################################################### -# # -# README # -# # -####################################################################################### -# # -# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search # -# V 3.6.1 # -# 2013/05 # -# # -# Copyright (C) 2001-2013 # -# # -# Mark Abramson - the Boeing Company, Seattle # -# Charles Audet - Ecole Polytechnique, Montreal # -# Gilles Couture - Ecole Polytechnique, Montreal # -# John Dennis - Rice University, Houston # -# Sebastien Le Digabel - Ecole Polytechnique, Montreal # -# Christophe Tribes - Ecole Polytechnique, Montreal # -# # -#-------------------------------------------------------------------------------------# -# # -# Contact information: # -# Ecole Polytechnique de Montreal - GERAD # -# C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada # -# e-mail: nomad@gerad.ca # -# phone : 1-514-340-6053 #6928 # -# fax : 1-514-340-5665 # -# # -# This program is free software: you can redistribute it and/or modify it under the # -# terms of 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. # -# # -# This program 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 Lesser General Public License for more details. # -# # -# -# You should have received a copy of the GNU Lesser General Public License along # -# with this program. If not, see <http://www.gnu.org/licenses/>. # -# # -# You can find information on the NOMAD software at www.gerad.ca/nomad # -####################################################################################### - - - AUTHORS : - -* Mark A. Abramson (Mark.A.Abramson@boeing.com), The Boeing Company. - -* Charles Audet (www.gerad.ca/Charles.Audet), GERAD and Departement de -mathematiques et de genie industriel, ecole Polytechnique de Montreal. - -* J.E. Dennis Jr. (www.caam.rice.edu/~dennis), Computational and Applied -Mathematics Department, Rice University. - -* Sebastien Le Digabel (www.gerad.ca/Sebastien.Le.Digabel), GERAD and Departement -de mathematiques et de genie industriel, ecole Polytechnique de Montreal. - -* Christophe Tribes, GERAD, Departement -de mathematiques et de genie industriel, Department of mechanical engineering, ecole Polytechnique de Montreal. - - DESCRIPTION : - -NOMAD is a C++ implementation of the Mesh Adaptive Direct Search (MADS) algorithm, -designed for constrained optimization of black-box functions. - -The project started in 2001, and was funded in part by AFOSR, CRIAQ, FQRNT, LANL, -NSERC, the Boeing Company, and ExxonMobil Upstream Research Company. - - - WEB PAGE : - -http://www.gerad.ca/nomad/ - - - FURTHER INSTRUCTIONS : - -Please visit the web page for futher instruction on the following: - - * Downloading, configuring, compiling, and installing NOMAD - * Using NOMAD and setting the parameters - * Reports on NOMAD - * How to report bugs and make enhancement requests - * And more... - - - BATCH OR LIBRARY MODE : - -NOMAD is designed to be used in two different modes : batch and library. -The batch mode is intended for a basic ans simple usage of the MADS method, -while the library mode allows more flexibility. -For example, in batch mode, users must define their separate black-box program, -that will be called with system calls by NOMAD. -In library mode, users can define their black-box function as C++ code -that will be directly called by NOMAD, without system calls and temporary files. - - - TYPES OF USE : - -There are two ways of using NOMAD, one can directly use an executable or compile -the source code. - -NOMAD batch mode executable is located in directory $NOMAD_HOME/bin or %NOMAD_HOME%\bin. -In order to avoid compiling the code, you can simply use this executable. - - - HOW TO EXECUTE NOMAD : - -For informations about the execution of NOMAD, please read the user guide : - - $NOMAD_HOME/doc/user_guide.pdf or %NOMAD_HOME%\doc\user_guide.pdf - -or - - http://www.gerad.ca/NOMAD/Downloads/user_guide.pdf +####################################################################################### +# # +# README # +# # +####################################################################################### +# # +# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search # +# V 3.7.2 # +# # +# Copyright (C) 2001-2015 # +# # +# Mark Abramson - the Boeing Company, Seattle # +# Charles Audet - Ecole Polytechnique, Montreal # +# Gilles Couture - Ecole Polytechnique, Montreal # +# John Dennis - Rice University, Houston # +# Sebastien Le Digabel - Ecole Polytechnique, Montreal # +# Christophe Tribes - Ecole Polytechnique, Montreal # +# # +#-------------------------------------------------------------------------------------# +# # +# Contact information: # +# Ecole Polytechnique de Montreal - GERAD # +# C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada # +# e-mail: nomad@gerad.ca # +# phone : 1-514-340-6053 #6928 # +# fax : 1-514-340-5665 # +# # +# This program is free software: you can redistribute it and/or modify it under the # +# terms of 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. # +# # +# This program 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 Lesser General Public License for more details. # +# # +# +# You should have received a copy of the GNU Lesser General Public License along # +# with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +# You can find information on the NOMAD software at www.gerad.ca/nomad # +####################################################################################### + + + AUTHORS : + +* Mark A. Abramson (Mark.A.Abramson@boeing.com), The Boeing Company. + +* Charles Audet (www.gerad.ca/Charles.Audet), GERAD and Departement de +mathematiques et de genie industriel, ecole Polytechnique de Montreal. + +* J.E. Dennis Jr. (www.caam.rice.edu/~dennis), Computational and Applied +Mathematics Department, Rice University. + +* Sebastien Le Digabel (www.gerad.ca/Sebastien.Le.Digabel), GERAD and Departement +de mathematiques et de genie industriel, ecole Polytechnique de Montreal. + +* Christophe Tribes, GERAD, Departement +de mathematiques et de genie industriel, Department of mechanical engineering, ecole Polytechnique de Montreal. + + DESCRIPTION : + +NOMAD is a C++ implementation of the Mesh Adaptive Direct Search (MADS) algorithm, +designed for constrained optimization of black-box functions. + +The project started in 2001, and was funded in part by AFOSR, CRIAQ, FQRNT, LANL, +NSERC, the Boeing Company, and ExxonMobil Upstream Research Company. + + + WEB PAGE : + +http://www.gerad.ca/nomad/ + + + FURTHER INSTRUCTIONS : + +Please visit the web page for futher instruction on the following: + + * Downloading, configuring, compiling, and installing NOMAD + * Using NOMAD and setting the parameters + * Reports on NOMAD + * How to report bugs and make enhancement requests + * And more... + + + BATCH OR LIBRARY MODE : + +NOMAD is designed to be used in two different modes : batch and library. +The batch mode is intended for a basic ans simple usage of the MADS method, +while the library mode allows more flexibility. +For example, in batch mode, users must define their separate black-box program, +that will be called with system calls by NOMAD. +In library mode, users can define their black-box function as C++ code +that will be directly called by NOMAD, without system calls and temporary files. + + + TYPES OF USE : + +There are two ways of using NOMAD, one can directly use an executable or compile +the source code. + +NOMAD batch mode executable is located in directory $NOMAD_HOME/bin or %NOMAD_HOME%\bin. +In order to avoid compiling the code, you can simply use this executable. + + + HOW TO EXECUTE NOMAD : + +For informations about the execution of NOMAD, please read the user guide : + + $NOMAD_HOME/doc/user_guide.pdf or %NOMAD_HOME%\doc\user_guide.pdf + +or + + http://www.gerad.ca/NOMAD/Downloads/user_guide.pdf diff --git a/configure.ac b/configure.ac index 840291f4f274d142a869478fdb53a00afe5a5979..9ab8eb410f7070461442e5416d7cdd3da324814e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(nomad, 3.6.1, miroslav.shaltev@shaltev.de) +AC_INIT(nomad, 3.7.2, miroslav.shaltev@shaltev.de) AC_PREREQ([2.63]) AC_CONFIG_HEADERS([config.h]) diff --git a/doc/user_guide.pdf b/doc/user_guide.pdf index d36529e595ab18e41f6b5c7e09235f808e099b69..9d7d24922c4389db5d4da282552f411c8a276da8 100644 Binary files a/doc/user_guide.pdf and b/doc/user_guide.pdf differ diff --git a/examples/advanced/categorical/batch/bb.cpp b/examples/advanced/categorical/batch/bb.cpp index 96e7377e085e33e7ace10b7dc7740a637b0a9724..3e863594155c9f281544934ac969887dd70f2058 100644 --- a/examples/advanced/categorical/batch/bb.cpp +++ b/examples/advanced/categorical/batch/bb.cpp @@ -79,8 +79,8 @@ int main ( int argc , char ** argv ) { in.close(); } } - - cout << g1 << " " << g2 << " " << f << endl; + cout.precision(18); + cout << g1 << " " << g2 << " " << f << endl; return 0; } diff --git a/examples/advanced/categorical/batch/runExample.log b/examples/advanced/categorical/batch/runExample.log index 1b60451f871e5c325e61ce1082286f34e4be2c38..543c3aaa8d44d107dbfe215862739a41c25d0335 100644 --- a/examples/advanced/categorical/batch/runExample.log +++ b/examples/advanced/categorical/batch/runExample.log @@ -1,10 +1,13 @@ Warning: { Model use is disabled for problem with categorical variables. } +Warning: { + Anisotropic mesh are not supported with categorical and binary variables. +} -NOMAD - version 3.6.1 - www.gerad.ca/nomad +NOMAD - version 3.7.1 - www.gerad.ca/nomad -Copyright (C) 2001-2013 { +Copyright (C) 2001-2015 { Mark A. Abramson - The Boeing Company Charles Audet - Ecole Polytechnique de Montreal Gilles Couture - Ecole Polytechnique de Montreal @@ -26,31 +29,54 @@ MADS run { BBE ( SOL ) OBJ - 1 ( 0 100.0000000000 1 100.0000000000 ) 159.6460000000 - 3 ( 0 100.0000000000 1 1100.0000000000 ) 150.4540000000 - 4 ( 0 100.0000000000 1 4100.0000000000 ) 111.1390000000 - 6 ( 0 100.0000000000 1 6100.0000000000 ) 85.9544000000 - 14 ( 0 100.0000000000 1 8100.0000000000 ) 64.1532000000 - 24 ( 0 100.0000000000 1 9100.0000000000 ) 55.8612000000 - 32 ( 0 1100.0000000000 1 8100.0000000000 ) 52.5820000000 - 47 ( 0 1600.0000000000 1 8100.0000000000 ) 47.6450000000 - 55 ( 0 1850.0000000000 1 8100.0000000000 ) 45.3357000000 - 72 ( 0 1853.4179687500 1 8111.7187500000 ) 45.2005000000 - 75 ( 0 1833.8867187500 1 8132.2265625000 ) 45.1958000000 - 76 ( 0 1775.2929687500 1 8193.7500000000 ) 45.1911000000 - 80 ( 0 1900.2929687500 1 8068.7500000000 ) 45.1620000000 - 89 ( 0 1923.7304687500 1 8058.9843750000 ) 45.0398000000 - 98 ( 0 1899.3164062500 1 8083.3984375000 ) 45.0394000000 - 105 ( 0 1892.4804687500 1 8106.8359375000 ) 44.8919000000 - 114 ( 0 1923.7304687500 1 8075.5859375000 ) 44.8905000000 - 137 ( 0 1922.9360580444 1 8076.6168594360 ) 44.8884000000 - 146 ( 0 1922.1416473389 1 8077.6477813721 ) 44.8863000000 - 162 ( 0 1922.1003413200 1 8077.7624607086 ) 44.8856000000 - 169 ( 0 1922.0590353012 1 8077.8771400452 ) 44.8850000000 - 171 ( 0 1921.9208717346 1 8078.0774116516 ) 44.8844000000 - 294 ( 0 1921.9208717346 1 8078.0774116516 ) 44.8844000000 - -} end of run (mesh index limits (+/- 50)) - -blackbox evaluations : 294 -best feasible solution : ( 0 1921.920872 1 8078.077412 ) h=0 f=44.8844 + 1 ( 0 100.0000000000 1 100.0000000000 ) 159.6461296475 + 5+ 2 ( 0 1100.0000000000 2 100.0000000000 ) 152.8902369239 (ExtendedPoll) + 5+ 3 ( 0 4100.0000000000 2 100.0000000000 ) 134.5175377184 (ExtendedPoll) + 5+ 6 ( 0 8100.0000000000 2 1100.0000000000 ) 93.9098509400 (ExtendedPoll) + 5+ 13 ( 0 3600.0000000000 2 4600.0000000000 ) 72.2375927442 (ExtendedPoll) + 5+ 23 ( 0 4600.0000000000 2 4600.0000000000 ) 63.9850651149 (ExtendedPoll) + 5+ 29 ( 0 4100.0000000000 2 5100.0000000000 ) 62.0438640124 (ExtendedPoll) + 41+ 5 ( 0 3975.0000000000 1 5725.0000000000 ) 55.6086573370 (ExtendedPoll) + 66+ 6 ( 2 3881.2500000000 1 5975.0000000000 ) 58.7730353554 (ExtendedPoll) + 85+ 7 ( 0 3943.7500000000 2 5975.0000000000 ) 54.5634971325 (ExtendedPoll) + 110 ( 0 3943.7500000000 1 5975.0000000000 ) 52.5611211856 + 114+ 12 ( 0 3914.4531250000 2 6029.6875000000 ) 54.3636860906 (ExtendedPoll) + 114+ 14 ( 0 3836.3281250000 2 6131.2500000000 ) 54.2565794588 (ExtendedPoll) + 114+ 26 ( 0 3863.6718750000 2 6115.6250000000 ) 54.1218203970 (ExtendedPoll) + 114+ 28 ( 0 3908.5937500000 2 6072.6562500000 ) 54.0518889750 (ExtendedPoll) + 114+ 29 ( 0 4043.3593750000 2 5943.7500000000 ) 53.9097569796 (ExtendedPoll) + 114+ 42 ( 0 4017.9687500000 2 5979.8828125000 ) 53.8237647156 (ExtendedPoll) + 166+ 12 ( 0 3945.7031250000 2 6037.5000000000 ) 53.9997469058 (ExtendedPoll) + 166+ 23 ( 0 3945.2148437500 2 6053.1250000000 ) 53.8701209592 (ExtendedPoll) + 199+ 8 ( 0 4100.0000000000 2 5881.2500000000 ) 53.9564900102 (ExtendedPoll) + 199+ 24 ( 0 4107.8125000000 2 5881.4331054688 ) 53.8832486375 (ExtendedPoll) + 199+ 26 ( 0 4121.8505859375 2 5874.7192382812 ) 53.8169487483 (ExtendedPoll) + 238+ 10 ( 0 4006.2500000000 2 5980.8593750000 ) 53.9245869941 (ExtendedPoll) + 238+ 18 ( 0 4030.6640625000 2 5961.3281250000 ) 53.8703341236 (ExtendedPoll) + 238+ 30 ( 0 4028.8024902344 2 5968.9270019531 ) 53.8199810273 (ExtendedPoll) + 238+ 38 ( 0 4026.6967773438 2 5972.2152709961 ) 53.8103680832 (ExtendedPoll) + 286+ 8 ( 0 4006.2500000000 2 5973.0468750000 ) 53.9937648079 (ExtendedPoll) + 286+ 19 ( 0 4006.3720703125 2 5988.6718750000 ) 53.8544733742 (ExtendedPoll) + 286+ 24 ( 0 4017.6025390625 2 5977.8076171875 ) 53.8455562804 (ExtendedPoll) + 286+ 25 ( 0 4051.2939453125 2 5945.2148437500 ) 53.8230307642 (ExtendedPoll) + 286+ 40 ( 0 4049.3560791016 2 5948.6022949219 ) 53.8105786370 (ExtendedPoll) + 286+ 48 ( 0 4049.1615295410 2 5950.5458831787 ) 53.7949509311 (ExtendedPoll) + 344+ 11 ( 0 4092.1875000000 2 5889.0625000000 ) 53.9562156297 (ExtendedPoll) + 344+ 26 ( 0 4082.9101562500 2 5901.6357421875 ) 53.9261842233 (ExtendedPoll) + 344+ 27 ( 0 4055.0781250000 2 5939.3554687500 ) 53.8406875009 (ExtendedPoll) + 344+ 41 ( 0 4054.7653198242 2 5943.2464599609 ) 53.8085676438 (ExtendedPoll) + 344+ 52 ( 0 4055.7056427002 2 5943.5101509094 ) 53.7974893949 (ExtendedPoll) + 344+ 55 ( 0 4057.1723937988 2 5942.2207832336 ) 53.7955084222 (ExtendedPoll) + 344+ 56 ( 0 4061.5726470947 2 5938.3526802063 ) 53.7896289020 (ExtendedPoll) + 416+ 8 ( 0 4092.1875000000 2 5873.4375000000 ) 54.1002366323 (ExtendedPoll) + 416+24 ( 0 4104.6386718750 2 5891.7480468750 ) 53.8173417481 (ExtendedPoll) + 416+33 ( 0 4111.5356445312 2 5888.0859375000 ) 53.7878645675 (ExtendedPoll) + 416+47 ( 0 4112.3014450073 2 5887.4798774719 ) 53.7864363345 (ExtendedPoll) + 475 ( 0 4004.2968750000 1 5986.7187500000 ) 51.9855654455 + 481+19 ( 0 3994.9005859375 2 5999.2932421875 ) 53.8684879252 (ExtendedPoll) + 500 ( 0 4004.2968750000 1 5986.7187500000 ) 51.9855654455 + +} end of run (max number of blackbox evaluations) + +blackbox evaluations : 500 +best feasible solution : ( 0 4004.296875 1 5986.71875 ) h=0 f=51.98556545 diff --git a/examples/advanced/categorical/bi_obj/categorical.cpp b/examples/advanced/categorical/bi_obj/categorical.cpp index a0e042117bec197322d88e3fcbcda5f9c2921fa0..f37c44958ba0fe2eaafed132175e34384187488d 100644 --- a/examples/advanced/categorical/bi_obj/categorical.cpp +++ b/examples/advanced/categorical/bi_obj/categorical.cpp @@ -46,10 +46,6 @@ class My_Evaluator : public Multi_Obj_Evaluator { public: My_Evaluator ( const Parameters & p ) : Multi_Obj_Evaluator ( p ) { - - - - } ~My_Evaluator ( void ) {} @@ -263,12 +259,10 @@ My_Extended_Poll::My_Extended_Poll ( Parameters & p ) bbit_1[0] = bbit_1[1] = CATEGORICAL; bbit_1[2] = CONTINUOUS; - const Point & d0_1 = p.get_initial_mesh_size(); + const Point & d0_1 = p.get_initial_poll_size(); const Point & lb_1 = p.get_lb(); const Point & ub_1 = p.get_ub(); - int halton_seed = p.get_halton_seed(); - _s1 = new Signature ( 3 , bbit_1 , d0_1 , @@ -276,7 +270,6 @@ My_Extended_Poll::My_Extended_Poll ( Parameters & p ) ub_1 , p.get_direction_types () , p.get_sec_poll_dir_types() , - halton_seed++ , _p.out() ); // signature for 2 assets: @@ -302,7 +295,6 @@ My_Extended_Poll::My_Extended_Poll ( Parameters & p ) ub_2 , p.get_direction_types () , p.get_sec_poll_dir_types() , - halton_seed++ , _p.out() ); } @@ -329,7 +321,6 @@ My_Extended_Poll::My_Extended_Poll ( Parameters & p ) ub_3 , p.get_direction_types () , p.get_sec_poll_dir_types() , - halton_seed , _p.out() ); } } diff --git a/examples/advanced/categorical/bi_obj/runExample.log b/examples/advanced/categorical/bi_obj/runExample.log index 1b4a4d26e54415b567c841649be2f797c191895d..c73859fdd08a6e92f9df20ed127c12dea3016491 100644 --- a/examples/advanced/categorical/bi_obj/runExample.log +++ b/examples/advanced/categorical/bi_obj/runExample.log @@ -1,59 +1,45 @@ Warning: { Model use is disabled for problem with categorical variables. } +Warning: { + Default anisotropic mesh is disabled with categorical and binary variables. +} +Warning: { + Model use is disabled in parallel mode (MPI). +} +Warning: { + Asynchronous mode is disabled in parallel mode (MPI) when dynamic directions (ortho n+1) are used. +} multi-MADS run { - MADS run 1/30 ...... OK [bb eval= 60] [overall bb eval= 60] [# dominant pts= 5] [# new pts= 5] [f1=52.02241823 f2=52.95541823] - MADS run 2/30 ...... OK [bb eval= 66] [overall bb eval= 126] [# dominant pts= 5] [# new pts= 0] [f1=52.02241823 f2=51.05441823] - MADS run 3/30 ...... OK [bb eval= 57] [overall bb eval= 183] [# dominant pts= 6] [# new pts= 1] [f1=52.02241823 f2=51.56141823] - MADS run 4/30 ...... OK [bb eval= 49] [overall bb eval= 232] [# dominant pts= 6] [# new pts= 0] [f1=52.02241823 f2=51.70341823] - MADS run 5/30 ...... OK [bb eval=181] [overall bb eval= 413] [# dominant pts= 5] [# new pts= -1] [f1=44.95823059 f2=43.96223059] - MADS run 6/30 ...... OK [bb eval=203] [overall bb eval= 616] [# dominant pts= 5] [# new pts= 0] [f1=44.90686591 f2=43.90786591] - MADS run 7/30 ...... OK [bb eval=138] [overall bb eval= 754] [# dominant pts= 8] [# new pts= 3] [f1=44.90641676 f2=43.90741676] - MADS run 8/30 ...... OK [bb eval=124] [overall bb eval= 878] [# dominant pts= 8] [# new pts= 0] [f1=44.90640745 f2=43.91240745] - MADS run 9/30 ...... OK [bb eval=180] [overall bb eval= 1058] [# dominant pts= 8] [# new pts= 0] [f1=44.90640744 f2=43.91440744] - MADS run 10/30 ...... OK [bb eval= 96] [overall bb eval= 1154] [# dominant pts= 8] [# new pts= 0] [f1=44.90640744 f2=43.91340744] - MADS run 11/30 ...... OK [bb eval=168] [overall bb eval= 1322] [# dominant pts= 11] [# new pts= 3] [f1=44.90640744 f2=43.97340744] - MADS run 12/30 ...... OK [bb eval=201] [overall bb eval= 1523] [# dominant pts= 10] [# new pts= -1] [f1=44.89376891 f2=43.89876891] - MADS run 13/30 ...... OK [bb eval=204] [overall bb eval= 1727] [# dominant pts= 12] [# new pts= 2] [f1=44.88950881 f2=43.90550881] - MADS run 14/30 ...... OK [bb eval=202] [overall bb eval= 1929] [# dominant pts= 10] [# new pts= -2] [f1=44.88548533 f2=43.90048533] - MADS run 15/30 ...... OK [bb eval=212] [overall bb eval= 2141] [# dominant pts= 10] [# new pts= 0] [f1=44.88519731 f2=43.88619731] - MADS run 16/30 ...... OK [bb eval=209] [overall bb eval= 2350] [# dominant pts= 9] [# new pts= -1] [f1=44.88510307 f2=43.91210307] - MADS run 17/30 ...... OK [bb eval=203] [overall bb eval= 2553] [# dominant pts= 9] [# new pts= 0] [f1=44.88508265 f2=43.90208265] - MADS run 18/30 ...... OK [bb eval=239] [overall bb eval= 2792] [# dominant pts= 9] [# new pts= 0] [f1=44.88508168 f2=43.90108168] - MADS run 19/30 ...... OK [bb eval=222] [overall bb eval= 3014] [# dominant pts= 9] [# new pts= 0] [f1=44.8850816 f2=43.9070816] - MADS run 20/30 ...... OK [bb eval=207] [overall bb eval= 3221] [# dominant pts= 8] [# new pts= -1] [f1=44.8850816 f2=43.9610816] - MADS run 21/30 ...... OK [bb eval=180] [overall bb eval= 3401] [# dominant pts= 6] [# new pts= -2] [f1=44.8850816 f2=43.9010816] - MADS run 22/30 ...... OK [bb eval=174] [overall bb eval= 3575] [# dominant pts= 11] [# new pts= 5] [f1=44.8850816 f2=44.0440816] - MADS run 23/30 ...... OK [bb eval=176] [overall bb eval= 3751] [# dominant pts= 9] [# new pts= -2] [f1=44.8850816 f2=43.9800816] - MADS run 24/30 ...... OK [bb eval=187] [overall bb eval= 3938] [# dominant pts= 8] [# new pts= -1] [f1=44.8850816 f2=44.1020816] - MADS run 25/30 ...... OK [bb eval=166] [overall bb eval= 4104] [# dominant pts= 10] [# new pts= 2] [f1=44.8850816 f2=43.9460816] - MADS run 26/30 ...... OK [bb eval=176] [overall bb eval= 4280] [# dominant pts= 11] [# new pts= 1] [f1=44.8850816 f2=43.9870816] - MADS run 27/30 ...... OK [bb eval= 2] [overall bb eval= 4282] [# dominant pts= 11] [# new pts= 0] [f1=44.8850816 f2=43.9460816] - MADS run 28/30 ...... OK [bb eval= 0] [overall bb eval= 4282] [# dominant pts= 11] [# new pts= 0] [f1=44.8850816 f2=43.9870816] - MADS run 29/30 ...... OK [bb eval= 0] [overall bb eval= 4282] [# dominant pts= 11] [# new pts= 0] [f1=44.8850816 f2=43.9460816] - MADS run 30/30 ...... OK [bb eval= 0] [overall bb eval= 4282] [# dominant pts= 11] [# new pts= 0] [f1=44.8850816 f2=43.9870816] - -} end of run (max number of MADS runs) - - -blackbox evaluations : 4282 -number of MADS runs : 30 + MADS run 1 ...... OK [bb eval= 78] [overall bb eval= 78] [# dominant pts= 2] [# new pts= 2] [f1=52.02241823 f2=51.31041823] + MADS run 2 ...... OK [bb eval= 39] [overall bb eval= 117] [# dominant pts= 3] [# new pts= 1] [f1=52.0224221 f2=51.0754221] + MADS run 3 ...... OK [bb eval= 39] [overall bb eval= 156] [# dominant pts= 3] [# new pts= 0] [f1=52.02242186 f2=51.23342186] + MADS run 4 ...... OK [bb eval= 38] [overall bb eval= 194] [# dominant pts= 4] [# new pts= 1] [f1=52.02242186 f2=51.06242186] + MADS run 5 ...... OK [bb eval= 39] [overall bb eval= 233] [# dominant pts= 5] [# new pts= 1] [f1=52.02242186 f2=51.19342186] + MADS run 6 ...... OK [bb eval= 7] [overall bb eval= 240] [# dominant pts= 5] [# new pts= 0] [f1=52.02242186 f2=51.19342186] + MADS run 7 ...... OK [bb eval= 39] [overall bb eval= 279] [# dominant pts= 2] [# new pts= -3] [f1=45.36506988 f2=44.51306988] + MADS run 8 ...... OK [bb eval= 39] [overall bb eval= 318] [# dominant pts= 3] [# new pts= 1] [f1=45.36506988 f2=44.51306988] + MADS run 9 ...... OK [bb eval= 39] [overall bb eval= 357] [# dominant pts= 7] [# new pts= 4] [f1=44.99982416 f2=44.55082416] + MADS run 10 ...... OK [bb eval= 39] [overall bb eval= 396] [# dominant pts= 4] [# new pts= -3] [f1=44.97647101 f2=44.00347101] + MADS run 11 ...... OK [bb eval= 39] [overall bb eval= 435] [# dominant pts= 4] [# new pts= 0] [f1=44.9661848 f2=44.1371848] + MADS run 12 ...... OK [bb eval= 39] [overall bb eval= 474] [# dominant pts= 5] [# new pts= 1] [f1=44.9661848 f2=44.1371848] + MADS run 13 ...... OK [bb eval= 26] [overall bb eval= 500] [# dominant pts= 5] [# new pts= 0] [f1=44.96576761 f2=45.17076761] + +} end of run (max number of bb evaluations) + + +blackbox evaluations : 500 +number of MADS runs : 13 Pareto front { - 44.8849906075 45.5549906075 - 44.8850816013 45.5000816013 - 44.8850816013 45.2800816013 - 44.8850816013 44.2430816013 - 44.8850816013 43.9800816013 - 44.8850816013 43.9260816013 - 44.8850816013 43.9020816013 - 44.8850816013 43.9010816013 - 44.8850816075 43.8900816075 - 44.8850816076 43.8890816076 - 44.8851973070 43.8861973070 + 44.9348019953 45.4168019953 + 44.9657676108 45.1707676108 + 44.9661847951 44.1371847951 + 44.9738637269 44.0708637269 + 44.9764710086 44.0034710086 } -number of Pareto points: 11 +number of Pareto points: 5 diff --git a/examples/advanced/categorical/single_obj/categorical.cpp b/examples/advanced/categorical/single_obj/categorical.cpp index 861146918b2ecd57ba5c396f52f16db41e99dc89..c79bcc0e2a2c17577b2555571bd9e179bbb71108 100644 --- a/examples/advanced/categorical/single_obj/categorical.cpp +++ b/examples/advanced/categorical/single_obj/categorical.cpp @@ -44,404 +44,415 @@ using namespace std; using namespace NOMAD; -#define USE_SURROGATE false +#define USE_SURROGATE false /*----------------------------------------*/ /* the problem */ /*----------------------------------------*/ -class My_Evaluator : public Evaluator { +class My_Evaluator : public Evaluator +{ public: - My_Evaluator ( const Parameters & p ) : + My_Evaluator ( const Parameters & p ) : Evaluator ( p ) {} - - ~My_Evaluator ( void ) {} - - bool eval_x ( Eval_Point & x , - const Double & h_max , - bool & count_eval ) const; + + ~My_Evaluator ( void ) {} + + bool eval_x ( Eval_Point & x , + const Double & h_max , + bool & count_eval ) const; }; /*--------------------------------------------------*/ /* user class to define categorical neighborhoods */ /*--------------------------------------------------*/ -class My_Extended_Poll : public Extended_Poll { - +class My_Extended_Poll : public Extended_Poll +{ + private: - - // signatures for 1, 2, and 3 assets: - Signature * _s1 , * _s2 , * _s3; - + + // signatures for 1, 2, and 3 assets: + Signature * _s1 , * _s2 , * _s3; + public: - - // constructor: - My_Extended_Poll ( Parameters & ); - - // destructor: - virtual ~My_Extended_Poll ( void ) { delete _s1; delete _s2; delete _s3; } - - // construct the extended poll points: - virtual void construct_extended_points ( const Eval_Point & ); - + + // constructor: + My_Extended_Poll ( Parameters & ); + + // destructor: + virtual ~My_Extended_Poll ( void ) { delete _s1; delete _s2; delete _s3; } + + // construct the extended poll points: + virtual void construct_extended_points ( const Eval_Point & ); + }; /*------------------------------------------*/ /* NOMAD main function */ /*------------------------------------------*/ -int main ( int argc , char ** argv ) { - - // NOMAD initializations: - begin ( argc , argv ); - - // display: - Display out ( cout ); - out.precision ( DISPLAY_PRECISION_STD ); - - // check the number of processess: +int main ( int argc , char ** argv ) +{ + + // NOMAD initializations: + begin ( argc , argv ); + + // display: + Display out ( cout ); + out.precision ( DISPLAY_PRECISION_STD ); + + // check the number of processess: #ifdef USE_MPI - if ( Slave::get_nb_processes() < 2 ) { - if ( Slave::is_master() ) - cerr << "usage: \'mpirun -np p ./categorical\' with p>1" - << endl; - end(); - return EXIT_FAILURE; - } + if ( Slave::get_nb_processes() < 2 ) + { + if ( Slave::is_master() ) + cerr << "usage: \'mpirun -np p ./categorical\' with p>1" + << endl; + end(); + return EXIT_FAILURE; + } #endif - - try { - - // parameters creation: - Parameters p ( out ); - - if ( USE_SURROGATE ) - p.set_HAS_SGTE ( true ); - - // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); - p.set_MAX_BB_EVAL ( 200 ); - - p.set_DIMENSION (3); - - vector<bb_output_type> bbot (3); - bbot[0] = EB; // budget constraint - bbot[1] = EB; // total value >= 1$ - bbot[2] = OBJ; // objective - p.set_BB_OUTPUT_TYPE ( bbot ); - - // categorical variables: - p.set_BB_INPUT_TYPE ( 0 , CATEGORICAL ); - p.set_BB_INPUT_TYPE ( 1 , CATEGORICAL ); - - // initial point - Point x0 ( 3 , 0 ); - x0[0] = 1; // 1 asset - x0[1] = 0; // of type 0 - x0[2] = 100; // 100$ - p.set_X0 ( x0 ); - - Point lb ( 3 ); - Point ub ( 3 ); - // Categorical variables 0 and 1 don't need bounds - lb[2] = 0; ub[2] = 10000; - - p.set_LOWER_BOUND ( lb ); - p.set_UPPER_BOUND ( ub ); - - p.set_DISPLAY_STATS ( "bbe ( sol ) obj" ); - - // extended poll trigger: - p.set_EXTENDED_POLL_TRIGGER ( 10 , false ); - - // parameters validation: - p.check(); - - // custom evaluator creation: - My_Evaluator ev ( p ); - - // extended poll: - My_Extended_Poll ep ( p ); - - // algorithm creation and execution: - Mads mads ( p , &ev , &ep , NULL , NULL ); - mads.run(); - } - catch ( exception & e ) { - string error = string ( "NOMAD has been interrupted: " ) + e.what(); - if ( Slave::is_master() ) - cerr << endl << error << endl << endl; - } - - - Slave::stop_slaves ( out ); - end(); - - return EXIT_SUCCESS; + + try + { + + // parameters creation: + Parameters p ( out ); + + if ( USE_SURROGATE ) + p.set_HAS_SGTE ( true ); + + // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); + + p.set_DIMENSION (3); + + vector<bb_output_type> bbot (3); + bbot[0] = EB; // budget constraint + bbot[1] = EB; // total value >= 1$ + bbot[2] = OBJ; // objective + p.set_BB_OUTPUT_TYPE ( bbot ); + + + // categorical variables: + p.set_BB_INPUT_TYPE ( 0 , CATEGORICAL ); + p.set_BB_INPUT_TYPE ( 1 , CATEGORICAL ); + + // initial point + Point x0 ( 3 , 0 ); + x0[0] = 1; // 1 asset + x0[1] = 0; // of type 0 + x0[2] = 100; // 100$ + p.set_X0 ( x0 ); + + Point lb ( 3 ); + Point ub ( 3 ); + // Categorical variables 0 and 1 don't need bounds + lb[2] = 0; ub[2] = 10000; + + p.set_LOWER_BOUND ( lb ); + p.set_UPPER_BOUND ( ub ); + + p.set_DISPLAY_STATS ( "bbe ( sol ) obj" ); + + // extended poll trigger: + p.set_EXTENDED_POLL_TRIGGER ( 10 , false ); + + // parameters validation: + p.check(); + + // custom evaluator creation: + My_Evaluator ev ( p ); + + // extended poll: + My_Extended_Poll ep ( p ); + + // algorithm creation and execution: + Mads mads ( p , &ev , &ep , NULL , NULL ); + mads.run(); + } + catch ( exception & e ) { + string error = string ( "NOMAD has been interrupted: " ) + e.what(); + if ( Slave::is_master() ) + cerr << endl << error << endl << endl; + } + + + Slave::stop_slaves ( out ); + end(); + + return EXIT_SUCCESS; } /*----------------------------------------------------*/ /* eval_x */ /*----------------------------------------------------*/ bool My_Evaluator::eval_x ( Eval_Point & x , - const Double & h_max , - bool & count_eval ) const { - - // number of assets: - int n = static_cast<int> ( x[0].value() ); - - // get the asset types and values: - Point v ( 3 , 0.0 ); - Double vmin = 10000 , tmp; - for ( int i = 0 ; i < n ; ++i ) { - tmp = v [ static_cast<int> ( x[2*i+1].value() ) ] = x[2*i+2]; - if ( tmp < vmin ) - vmin = tmp; - } - - // constraints (budget and each asset is considered with at least 1$): - Double vt = v[0] + v[1] + v[2]; - Double h = vt - 10000; - x.set_bb_output ( 0 , h ); - x.set_bb_output ( 1 , 1-vmin ); - - if ( h <= 0 && vmin >= 1 ) { - - // compute the risk and revenue: - Double vt2 = vt.pow2(); - Double rev = v[0] * 0.0891 + v[1] * 0.2137 + v[2] * 0.2346; - Double risk = 0.01 * (v[0]/vt).pow2() + - 0.05 * (v[1]/vt).pow2() + - 0.09 * (v[2]/vt).pow2() + - 0.02 * (v[0]*v[1]/vt2) + - 0.02 * (v[0]*v[2]/vt2) + - 0.10 * (v[1]*v[2]/vt2); - - // the objective is taken as a scaled distance - // between (risk,revenue) and (risk_best,rev_best): - Double a = ( risk - 0.01 ) * 100 / 0.08; - Double b = ( rev - 891 ) * 100 / 1455; - - x.set_bb_output ( 2 , ( a.pow2() + (100-b).pow2() ).sqrt() ); - - count_eval = true; - } - else - x.set_bb_output ( 2 , 145 ); - - // simulation of a surrogate: - if ( USE_SURROGATE && x.get_eval_type() == SGTE ) { - Double f = x.get_bb_outputs()[2]; - f.round(); - f += ( (rand()%2) ? -1.0 : 1.0 ) * ( (rand()%1000) / 1000.0 ); - x.set_bb_output ( 2 , f ); - } - - return true; + const Double & h_max , + bool & count_eval ) const +{ + + // number of assets: + int n = static_cast<int> ( x[0].value() ); + + count_eval=false; + + // get the asset types and values: + Point v ( 3 , 0.0 ); + Double vmin = 10000 , tmp; + for ( int i = 0 ; i < n ; ++i ) + { + tmp = v [ static_cast<int> ( x[2*i+1].value() ) ] = x[2*i+2]; + if ( tmp < vmin ) + vmin = tmp; + } + + // constraints (budget and each asset is considered with at least 1$): + Double vt = v[0] + v[1] + v[2]; + Double h = vt - 10000; + x.set_bb_output ( 0 , h ); + x.set_bb_output ( 1 , 1-vmin ); + + if ( h <= 0 && vmin >= 1 ) + { + + // compute the risk and revenue: + Double vt2 = vt.pow2(); + Double rev = v[0] * 0.0891 + v[1] * 0.2137 + v[2] * 0.2346; + Double risk = 0.01 * (v[0]/vt).pow2() + + 0.05 * (v[1]/vt).pow2() + + 0.09 * (v[2]/vt).pow2() + + 0.02 * (v[0]*v[1]/vt2) + + 0.02 * (v[0]*v[2]/vt2) + + 0.10 * (v[1]*v[2]/vt2); + + // the objective is taken as a scaled distance + // between (risk,revenue) and (risk_best,rev_best): + Double a = ( risk - 0.01 ) * 100 / 0.08; + Double b = ( rev - 891 ) * 100 / 1455; + + x.set_bb_output ( 2 , ( a.pow2() + (100-b).pow2() ).sqrt() ); + + count_eval = true; + } + else + x.set_bb_output ( 2 , 145 ); + + // simulation of a surrogate: + if ( USE_SURROGATE && x.get_eval_type() == SGTE ) + { + Double f = x.get_bb_outputs()[2]; + f.round(); + f += ( (rand()%2) ? -1.0 : 1.0 ) * ( (rand()%1000) / 1000.0 ); + x.set_bb_output ( 2 , f ); + } + + return true; } /*-----------------------------------------*/ /* constructor: creates the 3 signatures */ /*-----------------------------------------*/ My_Extended_Poll::My_Extended_Poll ( Parameters & p ) - : Extended_Poll ( p ) , - _s1 ( NULL ) , - _s2 ( NULL ) , - _s3 ( NULL ) +: Extended_Poll ( p ) , +_s1 ( NULL ) , +_s2 ( NULL ) , +_s3 ( NULL ) { - - // signature for 1 asset: - // ---------------------- - vector<bb_input_type> bbit_1 (3); - bbit_1[0] = bbit_1[1] = CATEGORICAL; - bbit_1[2] = CONTINUOUS; - - const Point & d0_1 = p.get_initial_mesh_size(); - const Point & lb_1 = p.get_lb(); - const Point & ub_1 = p.get_ub(); - - - int halton_seed = p.get_halton_seed(); - - _s1 = new Signature ( 3 , - bbit_1 , - d0_1 , - lb_1 , - ub_1 , - p.get_direction_types () , - p.get_sec_poll_dir_types() , - halton_seed++ , - _p.out() ); - - // signature for 2 assets: - // ----------------------- - { - vector<bb_input_type> bbit_2 (5); - Point d0_2 (5); - Point lb_2 (5); - Point ub_2 (5); - - // Categorical variables don't need bounds - for ( int i = 0 ; i < 5 ; ++i ) + + // signature for 1 asset: + // ---------------------- + vector<bb_input_type> bbit_1 (3); + bbit_1[0] = bbit_1[1] = CATEGORICAL; + bbit_1[2] = CONTINUOUS; + + const Point & d0_1 = p.get_initial_poll_size(); + const Point & lb_1 = p.get_lb(); + const Point & ub_1 = p.get_ub(); + + _s1 = new Signature ( 3 , + bbit_1 , + d0_1 , + lb_1 , + ub_1 , + p.get_direction_types () , + p.get_sec_poll_dir_types() , + _p.out() ); + + // signature for 2 assets: + // ----------------------- { - bbit_2[i] = bbit_1[1+(i-1)%2]; - d0_2 [i] = d0_1 [1+(i-1)%2]; - lb_2 [i] = lb_1 [1+(i-1)%2]; - ub_2 [i] = ub_1 [1+(i-1)%2]; - } - - _s2 = new Signature ( 5 , - bbit_2 , - d0_2 , - lb_2 , - ub_2 , - p.get_direction_types () , - p.get_sec_poll_dir_types() , - halton_seed++ , - _p.out() ); - } - - // signature for 3 assets: - // ----------------------- - { - vector<bb_input_type> bbit_3 (7); - Point d0_3 (7); - Point lb_3 (7); - Point ub_3 (7); - - // Categorical variables don't need bounds - for ( int i = 0 ; i < 7 ; ++i ) + vector<bb_input_type> bbit_2 (5); + Point d0_2 (5); + Point lb_2 (5); + Point ub_2 (5); + + // Categorical variables don't need bounds + for ( int i = 0 ; i < 5 ; ++i ) + { + bbit_2[i] = bbit_1[1+(i-1)%2]; + d0_2 [i] = d0_1 [1+(i-1)%2]; + lb_2 [i] = lb_1 [1+(i-1)%2]; + ub_2 [i] = ub_1 [1+(i-1)%2]; + } + + _s2 = new Signature ( 5 , + bbit_2 , + d0_2 , + lb_2 , + ub_2 , + p.get_direction_types () , + p.get_sec_poll_dir_types() , + _p.out() ); + } + + // signature for 3 assets: + // ----------------------- { - bbit_3[i] = bbit_1[1+(i-1)%2]; - d0_3 [i] = d0_1 [1+(i-1)%2]; - lb_3 [i] = lb_1 [1+(i-1)%2]; - ub_3 [i] = ub_1 [1+(i-1)%2]; - } - - _s3 = new Signature ( 7 , - bbit_3 , - d0_3 , - lb_3 , - ub_3 , - p.get_direction_types () , - p.get_sec_poll_dir_types() , - halton_seed , - _p.out() ); - } + vector<bb_input_type> bbit_3 (7); + Point d0_3 (7); + Point lb_3 (7); + Point ub_3 (7); + + // Categorical variables don't need bounds + for ( int i = 0 ; i < 7 ; ++i ) + { + bbit_3[i] = bbit_1[1+(i-1)%2]; + d0_3 [i] = d0_1 [1+(i-1)%2]; + lb_3 [i] = lb_1 [1+(i-1)%2]; + ub_3 [i] = ub_1 [1+(i-1)%2]; + } + + _s3 = new Signature ( 7 , + bbit_3 , + d0_3 , + lb_3 , + ub_3 , + p.get_direction_types () , + p.get_sec_poll_dir_types() , + _p.out() ); + } } /*--------------------------------------*/ /* construct the extended poll points */ /* (categorical neighborhoods) */ /*--------------------------------------*/ -void My_Extended_Poll::construct_extended_points ( const Eval_Point & x ) { - - // number of assets: - int n = static_cast<int> ( x[0].value() ); - - // 1 asset: - // -------- - if ( n==1 ) { - - int cur_type = static_cast<int> ( x[1].value() ); - - // this vector contains the types of the other assets: - vector<int> other_types; - switch ( cur_type ) { - case 0: - case 2: - other_types.push_back(1); - break; - default: - other_types.push_back(0); - other_types.push_back(2); - } - - // add 1 asset (1 or 2 neighbors): - for ( size_t k = 0 ; k < other_types.size() ; ++k ) { - Point y (5); - y[0] = 2; - y[1] = cur_type; - y[3] = other_types[k]; - y[2] = y[4] = x[2]/2.0; - - add_extended_poll_point ( y , *_s2 ); - } - - // change the type of the asset to the other types (1 or 2 neighbors): - for ( size_t k = 0 ; k < other_types.size() ; ++k ) { - Point y = x ; - y[1] = other_types[k]; - - add_extended_poll_point ( y , *_s1 ); - } - } - - // 2 assets: - // --------- - else if ( n == 2 ) { - - int other_type = static_cast<int> ( (3 - x[1] - x[3]).value() ); - - // change the type of one asset (2 neighbors): - { - Point y1 = x; - Point y2 = x; - - y1[1] = y2[3] = other_type; - - add_extended_poll_point ( y1 , *_s2 ); - add_extended_poll_point ( y2 , *_s2 ); - } - - // remove 1 asset (2 neighbors): - { - Point y1(3) , y2(3); - y1[0] = y2[0] = 1; - y1[1] = x[1]; - y2[1] = x[3]; - y1[2] = y2[2] = x[2]+x[4]; - - add_extended_poll_point ( y1 , *_s1 ); - add_extended_poll_point ( y2 , *_s1 ); - } - - // add one asset (1 neighbor): - { - Point y(7); - y[0] = 3; - - y[1] = x[1]; - y[3] = x[3]; - y[5] = other_type; - - y[2] = y[4] = y[6] = (x[2]+x[4])/3.0; - - add_extended_poll_point ( y , *_s3 ); - } - - } - - // 3 assets: - // --------- - else { - - // remove one asset (3 neighbors): - Point y1(5); - Point y2(5); - Point y3(5); - - y1[0] = y2[0] = y3[0] = 2; - - y1[1] = x[1]; - y1[3] = x[3]; - - y2[1] = x[1]; - y2[3] = x[5]; - - y3[1] = x[3]; - y3[3] = x[5]; - - y1[2] = y1[4] = y2[2] = y2[4] = y3[2] = y3[4] = (x[2]+x[4]+x[6]) / 2.0; - - add_extended_poll_point ( y1 , *_s2 ); - add_extended_poll_point ( y2 , *_s2 ); - add_extended_poll_point ( y3 , *_s2 ); - } +void My_Extended_Poll::construct_extended_points ( const Eval_Point & x ) +{ + + // number of assets: + int n = static_cast<int> ( x[0].value() ); + + // 1 asset: + // -------- + if ( n==1 ) + { + + int cur_type = static_cast<int> ( x[1].value() ); + + // this vector contains the types of the other assets: + vector<int> other_types; + switch ( cur_type ) + { + case 0: + case 2: + other_types.push_back(1); + break; + default: + other_types.push_back(0); + other_types.push_back(2); + } + + // add 1 asset (1 or 2 neighbors): + for ( size_t k = 0 ; k < other_types.size() ; ++k ) + { + Point y (5); + y[0] = 2; + y[1] = cur_type; + y[3] = other_types[k]; + y[2] = y[4] = x[2]/2.0; + + add_extended_poll_point ( y , *_s2 ); + } + + // change the type of the asset to the other types (1 or 2 neighbors): + for ( size_t k = 0 ; k < other_types.size() ; ++k ) + { + Point y = x ; + y[1] = other_types[k]; + + add_extended_poll_point ( y , *_s1 ); + } + } + + // 2 assets: + // --------- + else if ( n == 2 ) + { + + int other_type = static_cast<int> ( (3 - x[1] - x[3]).value() ); + + // change the type of one asset (2 neighbors): + { + Point y1 = x; + Point y2 = x; + + y1[1] = y2[3] = other_type; + + add_extended_poll_point ( y1 , *_s2 ); + add_extended_poll_point ( y2 , *_s2 ); + } + + // remove 1 asset (2 neighbors): + { + Point y1(3) , y2(3); + y1[0] = y2[0] = 1; + y1[1] = x[1]; + y2[1] = x[3]; + y1[2] = y2[2] = x[2]+x[4]; + + add_extended_poll_point ( y1 , *_s1 ); + add_extended_poll_point ( y2 , *_s1 ); + } + + // add one asset (1 neighbor): + { + Point y(7); + y[0] = 3; + + y[1] = x[1]; + y[3] = x[3]; + y[5] = other_type; + + y[2] = y[4] = y[6] = (x[2]+x[4])/3.0; + + add_extended_poll_point ( y , *_s3 ); + } + + } + + // 3 assets: + // --------- + else { + + // remove one asset (3 neighbors): + Point y1(5); + Point y2(5); + Point y3(5); + + y1[0] = y2[0] = y3[0] = 2; + + y1[1] = x[1]; + y1[3] = x[3]; + + y2[1] = x[1]; + y2[3] = x[5]; + + y3[1] = x[3]; + y3[3] = x[5]; + + y1[2] = y1[4] = y2[2] = y2[4] = y3[2] = y3[4] = (x[2]+x[4]+x[6]) / 2.0; + + add_extended_poll_point ( y1 , *_s2 ); + add_extended_poll_point ( y2 , *_s2 ); + add_extended_poll_point ( y3 , *_s2 ); + } } diff --git a/examples/advanced/categorical/single_obj/runExample.log b/examples/advanced/categorical/single_obj/runExample.log index 8be251a6e9acec0d41af826cabea379d212ed51e..d4a89baa74bd3f7c1abacdd3e0515d145c52fd83 100644 --- a/examples/advanced/categorical/single_obj/runExample.log +++ b/examples/advanced/categorical/single_obj/runExample.log @@ -1,36 +1,761 @@ Warning: { Model use is disabled for problem with categorical variables. } +Warning: { + Anisotropic mesh are not supported with categorical and binary variables. +} MADS run { BBE ( SOL ) OBJ - 1 ( 1 0 100.0000000000 ) 160.6247422680 - 3 ( 1 0 1100.0000000000 ) 154.5010309278 - 4 ( 1 0 4100.0000000000 ) 136.1298969072 - 5 ( 1 0 10000.0000000000 ) 100.0000000000 - 7 ( 2 0 5000.0000000000 1 5000.0000000000 ) 58.5324359492 - 11 ( 2 0 5000.0000000000 2 5000.0000000000 ) 55.9016994375 - 17 ( 3 0 3333.3333333333 2 3333.3333333333 1 3333.3333333333 ) 47.1682905221 - 57+ 3 ( 2 0 4000.0000000000 2 6000.0000000000 ) 53.8144961883 (ExtendedPoll) - 85+ 3 ( 2 0 4937.5000000000 2 5062.5000000000 ) 55.6303106280 (ExtendedPoll) - 85+ 4 ( 2 0 4750.0000000000 2 5250.0000000000 ) 54.9175874038 (ExtendedPoll) - 85+ 12 ( 2 0 4125.0000000000 2 5875.0000000000 ) 53.7856009462 (ExtendedPoll) - 171 ( 3 0 3333.2365055879 2 3333.4012826284 1 3333.3571751912 ) 47.1681115325 - 172 ( 3 0 3332.9460223516 2 3333.6051305135 1 3333.4287007650 ) 47.1675747997 - 173 ( 3 0 3331.7840894063 2 3334.4205220540 1 3333.7148030599 ) 47.1654314112 - 174 ( 3 0 3327.1363576253 2 3337.6820882161 1 3334.8592122396 ) 47.1569145813 - 175 ( 3 0 3308.5454305013 2 3350.7283528646 1 3339.4368489583 ) 47.1237573269 - 176 ( 3 0 3234.1817220052 2 3402.9134114583 1 3357.7473958333 ) 47.0058461470 - 177 ( 3 0 2936.7268880208 2 3611.6536458333 1 3430.9895833333 ) 46.7791198645 - 180 ( 3 0 2939.6565755208 2 3626.3020833333 1 3433.4309895833 ) 46.5971165597 - 188+ 3 ( 2 0 4968.4448242188 2 5030.9448242188 ) 55.7700229860 (ExtendedPoll) - 188+ 4 ( 2 0 4874.6948242188 2 5124.6948242188 ) 55.3815102271 (ExtendedPoll) - 188+ 5 ( 2 0 4499.6948242188 2 5499.6948242188 ) 54.2281651973 (ExtendedPoll) - 200 ( 3 0 2939.6565755208 2 3626.3020833333 1 3433.4309895833 ) 46.5971165597 + 1 ( 1 0 100.0000000000 ) 160.6247422680 + 2 ( 1 0 1254.7005383793 ) 153.5536894866 + 3 ( 1 0 4718.8021535170 ) 132.3405311424 + 4 ( 1 0 10000.0000000000 ) 100.0000000000 + 6 ( 2 0 5000.0000000000 1 5000.0000000000 ) 58.5324359492 + 9 ( 2 0 5000.0000000000 2 5000.0000000000 ) 55.9016994375 + 13 ( 3 0 3333.3333333333 2 3333.3333333333 1 3333.3333333333 ) 47.1682905221 + 25+1 ( 2 0 4664.5898033750 2 5335.4101966250 ) 54.6460175208 (ExtendedPoll) + 25+2 ( 2 0 3658.3592135001 2 6341.6407864999 ) 54.3665216385 (ExtendedPoll) + 36+5 ( 2 0 4853.2580389766 2 5104.8156864453 ) 55.7859562011 (ExtendedPoll) + 46+6 ( 2 0 4952.8329410996 2 5040.1793464707 ) 55.7796437455 (ExtendedPoll) + 46+7 ( 2 0 4811.3317643985 2 5160.7173858828 ) 55.4595714411 (ExtendedPoll) + 46+8 ( 2 0 4245.3270575938 2 5642.8695435312 ) 54.9467100128 (ExtendedPoll) + 46+14 ( 2 0 4217.3762078751 2 5761.6606548359 ) 54.0237235981 (ExtendedPoll) + 68+2 ( 2 0 4105.5728090001 2 5894.4271909999 ) 53.7841727607 (ExtendedPoll) + 83+6 ( 2 0 4077.6219592813 2 5838.5254915624 ) 54.5583352238 (ExtendedPoll) + 83+13 ( 2 0 4079.3688873888 2 5901.4149034296 ) 53.9607874220 (ExtendedPoll) + 83+17 ( 2 0 4048.3609134820 2 5933.2963413900 ) 53.9575135294 (ExtendedPoll) + 83+20 ( 2 0 4114.7441815640 2 5872.1538576303 ) 53.9056113440 (ExtendedPoll) + 83+26 ( 2 0 4103.7166978859 2 5883.2905243151 ) 53.9036253851 (ExtendedPoll) + 83+27 ( 2 0 4070.6342468517 2 5916.7005243695 ) 53.9019093307 (ExtendedPoll) + 83+33 ( 2 0 4066.9220246234 2 5931.8769623028 ) 53.7986288783 (ExtendedPoll) + 135+3 ( 2 0 4552.7864045000 2 5447.2135955000 ) 54.3435557967 (ExtendedPoll) + 135+17 ( 2 0 4547.0542966476 2 5452.5362670773 ) 54.3341271736 (ExtendedPoll) + 135+18 ( 2 0 4529.8579730901 2 5468.5042818092 ) 54.3067391679 (ExtendedPoll) + 135+19 ( 2 0 4461.0726788604 2 5532.3763407368 ) 54.2108013388 (ExtendedPoll) + 135+20 ( 2 0 4185.9315019415 2 5787.8645764472 ) 54.0536810905 (ExtendedPoll) + 135+24 ( 2 0 4166.7152927598 2 5812.7583019780 ) 53.9898429352 (ExtendedPoll) + 135+25 ( 2 0 4109.0666652149 2 5887.4394785702 ) 53.8164151300 (ExtendedPoll) + 135+30 ( 2 0 4087.2300638722 2 5910.1495439667 ) 53.8086966314 (ExtendedPoll) + 135+31 ( 2 0 4021.7202598438 2 5978.2797401562 ) 53.8029621572 (ExtendedPoll) + 178+9 ( 2 0 4997.1817136392 2 5002.7091033541 ) 55.8904416155 (ExtendedPoll) + 178+10 ( 2 0 4988.7268545568 2 5010.8364134164 ) 55.8568544583 (ExtendedPoll) + 178+11 ( 2 0 4954.9074182272 2 5043.3456536654 ) 55.7253209743 (ExtendedPoll) + 178+12 ( 2 0 4819.6296729087 2 5173.3826146616 ) 55.2455191020 (ExtendedPoll) + 178+13 ( 2 0 4278.5186916348 2 5693.5304586464 ) 54.1478187840 (ExtendedPoll) + 178+17 ( 2 0 4250.5678419161 2 5749.4321580839 ) 53.8463541922 (ExtendedPoll) + 209+11 ( 2 0 4991.4018382213 2 5006.9604166780 ) 55.8833196229 (ExtendedPoll) + 209+12 ( 2 0 4965.6073528851 2 5027.8416667120 ) 55.8295760866 (ExtendedPoll) + 209+13 ( 2 0 4862.4294115405 2 5111.3666668481 ) 55.6359728814 (ExtendedPoll) + 209+14 ( 2 0 4449.7176461622 2 5445.4666673925 ) 55.2305749540 (ExtendedPoll) + 209+18 ( 2 0 4416.5260121211 2 5499.6214387226 ) 54.9360602700 (ExtendedPoll) + 209+19 ( 2 0 4316.9511099981 2 5662.0857527128 ) 54.1235694449 (ExtendedPoll) + 209+21 ( 2 0 4226.1108484122 2 5745.9383018691 ) 54.0981732449 (ExtendedPoll) + 209+28 ( 2 0 4295.9879727091 2 5690.0366024316 ) 54.0285296848 (ExtendedPoll) + 209+39 ( 2 0 4295.1963959104 2 5693.8580076666 ) 53.9975464791 (ExtendedPoll) + 209+40 ( 2 0 4292.8216655143 2 5705.3222233715 ) 53.9048916226 (ExtendedPoll) + 258+8 ( 2 0 4991.6202042347 2 5007.1787826914 ) 55.8789766881 (ExtendedPoll) + 258+9 ( 2 0 4966.4808169388 2 5028.7151307657 ) 55.8122316385 (ExtendedPoll) + 258+10 ( 2 0 4865.9232677554 2 5114.8605230630 ) 55.5670382161 (ExtendedPoll) + 258+11 ( 2 0 4463.6930710215 2 5459.4420922519 ) 54.9622403869 (ExtendedPoll) + 258+15 ( 2 0 4465.4399991290 2 5522.3315041191 ) 54.2792880205 (ExtendedPoll) + 258+22 ( 2 0 4465.8494354041 2 5530.1380890991 ) 54.1936457881 (ExtendedPoll) + 258+25 ( 2 0 4460.3083978134 2 5535.6518309382 ) 54.1829242335 (ExtendedPoll) + 258+26 ( 2 0 4443.6852850412 2 5552.1930564553 ) 54.1517073596 (ExtendedPoll) + 258+27 ( 2 0 4377.1928339525 2 5618.3579585239 ) 54.0411998177 (ExtendedPoll) + 258+28 ( 2 0 4111.2230295975 2 5883.0175667983 ) 53.8374230147 (ExtendedPoll) + 258+38 ( 2 0 4118.0196717655 2 5879.1961615633 ) 53.8105466009 (ExtendedPoll) + 258+41 ( 2 0 4124.3795819065 2 5874.6650667847 ) 53.7943634220 (ExtendedPoll) + 258+50 ( 2 0 4124.8617357702 2 5874.5877643630 ) 53.7906784892 (ExtendedPoll) + 258+51 ( 2 0 4125.6516065844 2 5874.0132740894 ) 53.7887889498 (ExtendedPoll) + 258+53 ( 2 0 4123.8654408339 2 5876.1201649220 ) 53.7855913617 (ExtendedPoll) + 345+4 ( 2 0 4926.6290194883 2 5050.6609151152 ) 55.8573545355 (ExtendedPoll) + 345+5 ( 2 0 4706.5160779532 2 5202.6436604609 ) 55.8124774768 (ExtendedPoll) + 345+9 ( 2 0 4650.6143785157 2 5314.4470593359 ) 54.9951723917 (ExtendedPoll) + 345+18 ( 2 0 4648.1031693612 2 5329.8418632826 ) 54.8434056052 (ExtendedPoll) + 345+21 ( 2 0 4663.2796072945 2 5326.0204580476 ) 54.7617474708 (ExtendedPoll) + 345+24 ( 2 0 4676.3815681001 2 5317.5041835239 ) 54.7500380050 (ExtendedPoll) + 345+31 ( 2 0 4680.0460227630 2 5316.1598677537 ) 54.7351963289 (ExtendedPoll) + 345+34 ( 2 0 4683.8264843704 2 5315.1840446312 ) 54.7152907223 (ExtendedPoll) + 345+39 ( 2 0 4684.6722261763 2 5314.6957065739 ) 54.7138745538 (ExtendedPoll) + 345+42 ( 2 0 4683.5902055200 2 5315.5546697595 ) 54.7130556687 (ExtendedPoll) + 345+43 ( 2 0 4680.3441435508 2 5318.1315593164 ) 54.7106238781 (ExtendedPoll) + 345+44 ( 2 0 4667.3598956743 2 5328.4391175440 ) 54.7012704968 (ExtendedPoll) + 345+45 ( 2 0 4615.4229041681 2 5369.6693504543 ) 54.6698883036 (ExtendedPoll) + 345+46 ( 2 0 4407.6749381433 2 5534.5902820956 ) 54.6440687766 (ExtendedPoll) + 345+48 ( 2 0 4390.6423890959 2 5560.7942037069 ) 54.5173881146 (ExtendedPoll) + 345+49 ( 2 0 4339.5447419538 2 5639.4059685409 ) 54.1546080629 (ExtendedPoll) + 345+53 ( 2 0 4329.0631733093 2 5668.6670143402 ) 53.9515249195 (ExtendedPoll) + 345+60 ( 2 0 4327.2889494502 2 5672.1472226792 ) 53.9321944673 (ExtendedPoll) + 345+66 ( 2 0 4327.7553229574 2 5672.0024272464 ) 53.9295614439 (ExtendedPoll) + 345+67 ( 2 0 4328.5409288104 2 5671.4219660272 ) 53.9284968785 (ExtendedPoll) + 345+75 ( 2 0 4328.4706502466 2 5671.5217727832 ) 53.9281125932 (ExtendedPoll) + 425+16 ( 2 0 4999.6291616237 2 5000.3176329854 ) 55.9006895585 (ExtendedPoll) + 425+17 ( 2 0 4998.5166464947 2 5001.2705319414 ) 55.8976626910 (ExtendedPoll) + 425+18 ( 2 0 4994.0665859789 2 5005.0821277656 ) 55.8855968012 (ExtendedPoll) + 425+19 ( 2 0 4976.2663439156 2 5020.3285110625 ) 55.8380009177 (ExtendedPoll) + 425+20 ( 2 0 4905.0653756623 2 5081.3140442501 ) 55.6584535115 (ExtendedPoll) + 425+21 ( 2 0 4620.2615026492 2 5325.2561770006 ) 55.1234133107 (ExtendedPoll) + 425+24 ( 2 0 4630.7430712937 2 5354.9539548267 ) 54.7064652424 (ExtendedPoll) + 425+27 ( 2 0 4621.4625157231 2 5367.5100005988 ) 54.6438867561 (ExtendedPoll) + 425+28 ( 2 0 4593.6208490110 2 5405.1781379151 ) 54.4600465872 (ExtendedPoll) + 425+29 ( 2 0 4549.9476463255 2 5448.8513406007 ) 54.3496410161 (ExtendedPoll) + 425+30 ( 2 0 4418.9280382689 2 5579.8709486573 ) 54.0763891883 (ExtendedPoll) + 425+31 ( 2 0 3894.8496060423 2 6103.9493808838 ) 53.9197049939 (ExtendedPoll) + 425+44 ( 2 0 3903.2294018076 2 6096.7705981924 ) 53.8996693169 (ExtendedPoll) + 425+51 ( 2 0 3903.5746504167 2 6096.4253495832 ) 53.8992666551 (ExtendedPoll) + 425+52 ( 2 0 3904.6103962441 2 6095.3896037559 ) 53.8980629375 (ExtendedPoll) + 425+53 ( 2 0 3908.7533795536 2 6091.2466204464 ) 53.8933120622 (ExtendedPoll) + 425+54 ( 2 0 3925.3253127913 2 6074.6746872087 ) 53.8753312613 (ExtendedPoll) + 425+55 ( 2 0 3991.6130457425 2 6008.3869542575 ) 53.8196897705 (ExtendedPoll) + 525+3 ( 2 0 4720.4915028125 2 5223.6067977500 ) 55.4583179735 (ExtendedPoll) + 525+4 ( 2 0 4385.0813061876 2 5559.0169943749 ) 54.5837536207 (ExtendedPoll) + 525+15 ( 2 0 4367.6120251133 2 5584.7841839594 ) 54.4682528290 (ExtendedPoll) + 525+16 ( 2 0 4315.2041818907 2 5662.0857527128 ) 54.1388753912 (ExtendedPoll) + 525+18 ( 2 0 4283.7594759571 2 5716.2405240429 ) 53.8770977719 (ExtendedPoll) + 566+16 ( 2 0 3661.9622527217 2 6337.4508886172 ) 54.3613643939 (ExtendedPoll) + 566+17 ( 2 0 3672.7713703864 2 6324.8811949693 ) 54.3464807033 (ExtendedPoll) + 566+18 ( 2 0 3716.0078410450 2 6274.6024203776 ) 54.2957519362 (ExtendedPoll) + 566+19 ( 2 0 3888.9537236798 2 6073.4873220106 ) 54.2325516547 (ExtendedPoll) + 566+23 ( 2 0 3910.7903250226 2 6051.2139886410 ) 54.2135842543 (ExtendedPoll) + 566+24 ( 2 0 3976.3001290509 2 5984.3939885321 ) 54.1740869612 (ExtendedPoll) + 566+28 ( 2 0 4033.9487565958 2 5959.9369950282 ) 53.8521950489 (ExtendedPoll) + 566+34 ( 2 0 4047.3782664216 2 5951.9666355381 ) 53.7987546224 (ExtendedPoll) + 566+46 ( 2 0 4047.6136123118 2 5951.9017281599 ) 53.7971533414 (ExtendedPoll) + 566+50 ( 2 0 4047.8134790560 2 5952.0419387593 ) 53.7940433602 (ExtendedPoll) + 566+52 ( 2 0 4047.6531698269 2 5952.2260518031 ) 53.7938806683 (ExtendedPoll) + 566+53 ( 2 0 4047.1722421396 2 5952.7783909345 ) 53.7933936767 (ExtendedPoll) + 566+59 ( 2 0 4047.2240480902 2 5952.7461205054 ) 53.7932021747 (ExtendedPoll) + 566+64 ( 2 0 4047.2545309008 2 5952.7446673365 ) 53.7929324376 (ExtendedPoll) + 638+17 ( 2 0 4999.9134679357 2 5000.0860989042 ) 55.9013177479 (ExtendedPoll) + 638+18 ( 2 0 4999.6538717426 2 5000.3443956169 ) 55.9001728626 (ExtendedPoll) + 638+19 ( 2 0 4998.6154869705 2 5001.3775824675 ) 55.8955960762 (ExtendedPoll) + 638+20 ( 2 0 4994.4619478821 2 5005.5103298701 ) 55.8773330446 (ExtendedPoll) + 638+21 ( 2 0 4977.8477915284 2 5022.0413194804 ) 55.8049893023 (ExtendedPoll) + 638+22 ( 2 0 4911.3911661138 2 5088.1652779214 ) 55.5271121019 (ExtendedPoll) + 638+23 ( 2 0 4645.5646644551 2 5352.6611116858 ) 54.6099568042 (ExtendedPoll) + 638+29 ( 2 0 4643.1899340591 2 5355.7660034392 ) 54.5949958366 (ExtendedPoll) + 638+37 ( 2 0 4643.2514561244 2 5356.2503964074 ) 54.5891116760 (ExtendedPoll) + 638+39 ( 2 0 4642.9300912980 2 5356.6179294388 ) 54.5876751049 (ExtendedPoll) + 638+40 ( 2 0 4641.9659968188 2 5357.7205285330 ) 54.5833690042 (ExtendedPoll) + 638+41 ( 2 0 4640.6472708158 2 5359.1620854185 ) 54.5782267385 (ExtendedPoll) + 638+46 ( 2 0 4639.9154034740 2 5359.8086535364 ) 54.5770790094 (ExtendedPoll) + 638+47 ( 2 0 4637.7198014483 2 5361.7483578901 ) 54.5736490458 (ExtendedPoll) + 638+48 ( 2 0 4628.9373933458 2 5369.5071753047 ) 54.5601278395 (ExtendedPoll) + 638+49 ( 2 0 4593.8077609356 2 5400.5424449631 ) 54.5092397286 (ExtendedPoll) + 638+50 ( 2 0 4453.2892312949 2 5524.6835235967 ) 54.3579916958 (ExtendedPoll) + 638+55 ( 2 0 4453.1800482882 2 5540.2966935568 ) 54.1950044054 (ExtendedPoll) + 638+59 ( 2 0 4449.7953750800 2 5547.3389974899 ) 54.1501982295 (ExtendedPoll) + 638+63 ( 2 0 4458.8302688856 2 5540.9790873488 ) 54.1396632915 (ExtendedPoll) + 638+73 ( 2 0 4458.3987614362 2 5541.5182850685 ) 54.1376935988 (ExtendedPoll) + 638+86 ( 2 0 4458.4198350926 2 5541.5559487575 ) 54.1371193459 (ExtendedPoll) + 638+88 ( 2 0 4458.4486331602 2 5541.5458498792 ) 54.1369795760 (ExtendedPoll) + 638+95 ( 2 0 4458.4524474032 2 5541.5457910551 ) 54.1369476680 (ExtendedPoll) + 738+11 ( 2 0 4695.1610452549 2 5241.9495428779 ) 55.4530370223 (ExtendedPoll) + 738+12 ( 2 0 4619.1696725821 2 5296.9777782617 ) 55.4492782592 (ExtendedPoll) + 738+15 ( 2 0 4772.8993460352 2 5199.1498042461 ) 55.3189871998 (ExtendedPoll) + 738+21 ( 2 0 4803.9073199419 2 5194.3457519507 ) 55.1267190068 (ExtendedPoll) + 738+24 ( 2 0 4779.8870584649 2 5214.4354251860 ) 55.0861821831 (ExtendedPoll) + 738+25 ( 2 0 4707.8262740337 2 5274.7044448921 ) 54.9771582390 (ExtendedPoll) + 738+26 ( 2 0 4419.5831363091 2 5515.7805237163 ) 54.7394753219 (ExtendedPoll) + 738+28 ( 2 0 4251.8780379967 2 5711.4364717475 ) 54.2065798938 (ExtendedPoll) + 738+29 ( 2 0 3916.4678413717 2 6046.8466683725 ) 54.1969206166 (ExtendedPoll) + 738+38 ( 2 0 3947.9125473053 2 6047.2834003993 ) 53.8946625323 (ExtendedPoll) + 738+43 ( 2 0 3960.2502270639 2 6037.7844788152 ) 53.8597225819 (ExtendedPoll) + 738+52 ( 2 0 3961.1262500944 2 6037.3528647418 ) 53.8551714185 (ExtendedPoll) + 738+53 ( 2 0 3963.7543191857 2 6036.0580225215 ) 53.8415309007 (ExtendedPoll) + 738+63 ( 2 0 3963.8724386189 2 6036.0888168742 ) 53.8401500357 (ExtendedPoll) + 738+69 ( 2 0 3963.8977126790 2 6036.0717128804 ) 53.8400591085 (ExtendedPoll) + 738+70 ( 2 0 3963.9735348593 2 6036.0204008990 ) 53.8397863412 (ExtendedPoll) + 738+71 ( 2 0 3964.0565483307 2 6035.9309033538 ) 53.8397753773 (ExtendedPoll) + 738+72 ( 2 0 3964.3055887447 2 6035.6624107183 ) 53.8397427557 (ExtendedPoll) + 738+73 ( 2 0 3965.3017504010 2 6034.5884401761 ) 53.8396163244 (ExtendedPoll) + 738+74 ( 2 0 3969.2863970259 2 6030.2925580077 ) 53.8391754528 (ExtendedPoll) + 738+75 ( 2 0 3985.2249835255 2 6013.1090293339 ) 53.8384482501 (ExtendedPoll) + 738+78 ( 2 0 3987.0145612449 2 6012.3276884421 ) 53.8284510125 (ExtendedPoll) + 738+83 ( 2 0 3987.3798551717 2 6012.0036580149 ) 53.8278471786 (ExtendedPoll) + 738+84 ( 2 0 3988.4757369520 2 6011.0315667334 ) 53.8260397128 (ExtendedPoll) + 738+86 ( 2 0 3986.7339267980 2 6013.1742832402 ) 53.8237018301 (ExtendedPoll) + 738+95 ( 2 0 3986.6783090383 2 6013.2829464548 ) 53.8232765676 (ExtendedPoll) + 738+99 ( 2 0 3986.8030524894 2 6013.1636141732 ) 53.8231454979 (ExtendedPoll) + 738+100 ( 2 0 3987.1772828427 2 6012.8056173285 ) 53.8227528066 (ExtendedPoll) + 738+110 ( 2 0 3987.1736824074 2 6012.8204452533 ) 53.8226572738 (ExtendedPoll) + 738+112 ( 2 0 3987.1869497063 2 6012.8129081631 ) 53.8225983976 (ExtendedPoll) + 738+113 ( 2 0 3987.2077526376 2 6012.7905795918 ) 53.8225977726 (ExtendedPoll) + 738+114 ( 2 0 3987.2701614317 2 6012.7235938779 ) 53.8225959146 (ExtendedPoll) + 738+115 ( 2 0 3987.5197966079 2 6012.4556510226 ) 53.8225887344 (ExtendedPoll) + 738+116 ( 2 0 3988.5183373128 2 6011.3838796011 ) 53.8225640459 (ExtendedPoll) + 738+117 ( 2 0 3992.5125001324 2 6007.0967939151 ) 53.8225297822 (ExtendedPoll) + 738+121 ( 2 0 3992.8719297375 2 6006.7662594221 ) 53.8220484338 (ExtendedPoll) + 738+122 ( 2 0 3993.9502185528 2 6005.7746559431 ) 53.8206084721 (ExtendedPoll) + 738+130 ( 2 0 3994.1935345893 2 6005.7947812288 ) 53.8181500804 (ExtendedPoll) + 738+138 ( 2 0 3994.2169631374 2 6005.7752257153 ) 53.8181014599 (ExtendedPoll) + 738+143 ( 2 0 3994.2052365766 2 6005.7933405549 ) 53.8180529267 (ExtendedPoll) + 738+149 ( 2 0 3994.2070325934 2 6005.7926984484 ) 53.8180416998 (ExtendedPoll) + 892+10 ( 2 0 4983.7317319996 2 5014.9580719198 ) 55.8453986667 (ExtendedPoll) + 892+11 ( 2 0 4934.9269279985 2 5059.8322876792 ) 55.6824111014 (ExtendedPoll) + 892+12 ( 2 0 4739.7077119942 2 5239.3291507168 ) 55.1228042284 (ExtendedPoll) + 892+13 ( 2 0 3958.8308479767 2 5957.3166028671 ) 54.5781023915 (ExtendedPoll) + 892+20 ( 2 0 3979.7939852657 2 6016.7121585194 ) 53.8581095439 (ExtendedPoll) + 892+27 ( 2 0 3988.6378088095 2 6010.1065866132 ) 53.8325947095 (ExtendedPoll) + 892+35 ( 2 0 3989.5633053899 2 6010.4187817731 ) 53.8211783096 (ExtendedPoll) + 892+45 ( 2 0 3989.5756322315 2 6010.4097884943 ) 53.8211411134 (ExtendedPoll) + 892+46 ( 2 0 3989.6126127563 2 6010.3828086579 ) 53.8210295286 (ExtendedPoll) + 892+51 ( 2 0 3989.6241534539 2 6010.3728265038 ) 53.8210083518 (ExtendedPoll) + 892+55 ( 2 0 3989.6276603588 2 6010.3713253267 ) 53.8209885364 (ExtendedPoll) + 957+13 ( 2 0 3659.6318779221 2 6340.1599919713 ) 54.3646950351 (ExtendedPoll) + 957+14 ( 2 0 3663.4498711882 2 6335.7176083856 ) 54.3592886738 (ExtendedPoll) + 957+15 ( 2 0 3678.7218442523 2 6317.9480740430 ) 54.3387643534 (ExtendedPoll) + 957+16 ( 2 0 3739.8097365087 2 6246.8699366722 ) 54.2742427310 (ExtendedPoll) + 957+22 ( 2 0 3747.2068852135 2 6244.3587275178 ) 54.2206960776 (ExtendedPoll) + 957+24 ( 2 0 3733.7773753877 2 6261.9371915988 ) 54.2169921066 (ExtendedPoll) + 957+28 ( 2 0 3729.6284211326 2 6268.5700592566 ) 54.2069023761 (ExtendedPoll) + 957+39 ( 2 0 3729.8079759991 2 6269.9395382979 ) 54.1945664870 (ExtendedPoll) + 957+46 ( 2 0 3730.0391102401 2 6269.8609297318 ) 54.1928795948 (ExtendedPoll) + 957+47 ( 2 0 3730.4171990505 2 6269.5520399169 ) 54.1915098832 (ExtendedPoll) + 957+54 ( 2 0 3730.5280413937 2 6269.4196928396 ) 54.1914305422 (ExtendedPoll) + 957+55 ( 2 0 3730.8605684232 2 6269.0226516079 ) 54.1911930941 (ExtendedPoll) + 957+56 ( 2 0 3732.1906765414 2 6267.4344866812 ) 54.1902519228 (ExtendedPoll) + 957+57 ( 2 0 3737.5111090140 2 6261.0818269741 ) 54.1866251399 (ExtendedPoll) + 957+58 ( 2 0 3758.7928389047 2 6235.6711881460 ) 54.1743221404 (ExtendedPoll) + 957+59 ( 2 0 3843.9197584675 2 6134.0286328333 ) 54.1602124163 (ExtendedPoll) + 957+61 ( 2 0 3850.7164006354 2 6130.1799318466 ) 54.1262487754 (ExtendedPoll) + 957+62 ( 2 0 3871.1063271392 2 6118.6338288866 ) 54.0252546165 (ExtendedPoll) + 957+68 ( 2 0 3874.9618520638 2 6118.0196744739 ) 53.9932699228 (ExtendedPoll) + 957+71 ( 2 0 3878.5580673474 2 6116.4979363178 ) 53.9713481391 (ExtendedPoll) + 957+74 ( 2 0 3882.4477119616 2 6116.1772112356 ) 53.9366512244 (ExtendedPoll) + 957+77 ( 2 0 3883.8176174990 2 6114.7851279000 ) 53.9350795566 (ExtendedPoll) + 957+78 ( 2 0 3887.9273341111 2 6110.6088778932 ) 53.9304333927 (ExtendedPoll) + 957+79 ( 2 0 3904.3662005594 2 6093.9038778659 ) 53.9128801378 (ExtendedPoll) + 957+80 ( 2 0 3970.1216663528 2 6027.0838777571 ) 53.8590909037 (ExtendedPoll) + 957+86 ( 2 0 3973.0218399687 2 6024.4703095339 ) 53.8544261587 (ExtendedPoll) + 957+87 ( 2 0 3981.7223608162 2 6016.6296048642 ) 53.8406919834 (ExtendedPoll) + 957+92 ( 2 0 3984.9637313280 2 6014.4459447299 ) 53.8292462452 (ExtendedPoll) + 957+97 ( 2 0 3985.8052081727 2 6013.9503562385 ) 53.8256595333 (ExtendedPoll) + 957+105 ( 2 0 3985.8396877184 2 6014.0674560795 ) 53.8243145748 (ExtendedPoll) + 957+108 ( 2 0 3985.9527091902 2 6014.0213411865 ) 53.8236546852 (ExtendedPoll) + 957+113 ( 2 0 3986.0162471161 2 6013.9629145501 ) 53.8235671131 (ExtendedPoll) + 957+114 ( 2 0 3986.2068608937 2 6013.7876346407 ) 53.8233045248 (ExtendedPoll) + 957+120 ( 2 0 3986.1976307305 2 6013.7997850945 ) 53.8232852967 (ExtendedPoll) + 957+126 ( 2 0 3986.2011589420 2 6013.7983347110 ) 53.8232647945 (ExtendedPoll) + 957+130 ( 2 0 3986.1999003828 2 6013.7997678928 ) 53.8232641222 (ExtendedPoll) + 957+133 ( 2 0 3986.1980746415 2 6013.8017534985 ) 53.8232639619 (ExtendedPoll) + 1130+15 ( 2 0 4999.7419965034 2 5000.2294282565 ) 55.9008939292 (ExtendedPoll) + 1130+16 ( 2 0 4998.9679860137 2 5000.9177130262 ) 55.8984788107 (ExtendedPoll) + 1130+17 ( 2 0 4995.8719440548 2 5003.6708521046 ) 55.8888394453 (ExtendedPoll) + 1130+18 ( 2 0 4983.4877762190 2 5014.6834084185 ) 55.8506205863 (ExtendedPoll) + 1130+19 ( 2 0 4933.9511048760 2 5058.7336336741 ) 55.7032178511 (ExtendedPoll) + 1130+20 ( 2 0 4735.8044195041 2 5234.9345346965 ) 55.2046851896 (ExtendedPoll) + 1130+21 ( 2 0 3943.2176780166 2 5939.7381387862 ) 54.8819022435 (ExtendedPoll) + 1130+23 ( 2 0 3935.3565015332 2 5969.8726486392 ) 54.6880709245 (ExtendedPoll) + 1130+24 ( 2 0 3911.7729720830 2 6060.2761781983 ) 54.1268308179 (ExtendedPoll) + 1130+30 ( 2 0 3902.3832335056 2 6072.7230409636 ) 54.1106121774 (ExtendedPoll) + 1130+31 ( 2 0 3874.2140177734 2 6110.0636292598 ) 54.0666592435 (ExtendedPoll) + 1130+34 ( 2 0 3854.9978085918 2 6134.5206227637 ) 54.0491056788 (ExtendedPoll) + 1130+41 ( 2 0 3852.6503739474 2 6141.9723629719 ) 54.0104767054 (ExtendedPoll) + 1130+45 ( 2 0 3860.8118036993 2 6134.5206227637 ) 53.9930000229 (ExtendedPoll) + 1130+46 ( 2 0 3885.2960929549 2 6112.1654021390 ) 53.9427035432 (ExtendedPoll) + 1130+54 ( 2 0 3886.8263610334 2 6110.9507411893 ) 53.9381441910 (ExtendedPoll) + 1130+55 ( 2 0 3891.4171652688 2 6107.3067583403 ) 53.9245293625 (ExtendedPoll) + 1130+56 ( 2 0 3897.5041178931 2 6102.3935230381 ) 53.9073073325 (ExtendedPoll) + 1130+66 ( 2 0 3897.7068634861 2 6102.2575240879 ) 53.9065051034 (ExtendedPoll) + 1130+74 ( 2 0 3897.7316573216 2 6102.2397316194 ) 53.9064167304 (ExtendedPoll) + 1130+75 ( 2 0 3897.8060388280 2 6102.1863542139 ) 53.9061516260 (ExtendedPoll) + 1130+81 ( 2 0 3897.8185626742 2 6102.1776373870 ) 53.9061047270 (ExtendedPoll) + 1130+87 ( 2 0 3897.8165360562 2 6102.1808692197 ) 53.9060970673 (ExtendedPoll) + 1130+90 ( 2 0 3897.8201618133 2 6102.1796835545 ) 53.9060722877 (ExtendedPoll) + 1130+103 ( 2 0 3897.8200835182 2 6102.1797734473 ) 53.9060722845 (ExtendedPoll) + 1130+104 ( 2 0 3897.8198486328 2 6102.1800431259 ) 53.9060722750 (ExtendedPoll) + 1241+5 ( 2 0 4966.3716339321 2 5028.8243137725 ) 55.8117570732 (ExtendedPoll) + 1241+6 ( 2 0 4865.4865357285 2 5115.2972550898 ) 55.5653095642 (ExtendedPoll) + 1241+7 ( 2 0 4461.9461429141 2 5461.1890203593 ) 54.9583349271 (ExtendedPoll) + 1241+13 ( 2 0 4468.9338553438 2 5524.0784322265 ) 54.2311656305 (ExtendedPoll) + 1241+14 ( 2 0 4385.0813061876 2 5614.9186938124 ) 54.0080105561 (ExtendedPoll) + 1291+22 ( 2 0 4999.9828435272 2 5000.0130887244 ) 55.9016722791 (ExtendedPoll) + 1291+23 ( 2 0 4999.9313741087 2 5000.0523548977 ) 55.9015908089 (ExtendedPoll) + 1291+24 ( 2 0 4999.7254964348 2 5000.2094195909 ) 55.9012650053 (ExtendedPoll) + 1291+25 ( 2 0 4998.9019857391 2 5000.8376783636 ) 55.8999630243 (ExtendedPoll) + 1291+26 ( 2 0 4995.6079429565 2 5003.3507134546 ) 55.8947748483 (ExtendedPoll) + 1291+27 ( 2 0 4982.4317718259 2 5013.4028538183 ) 55.8743389196 (ExtendedPoll) + 1291+28 ( 2 0 4929.7270873038 2 5053.6114152732 ) 55.7977153969 (ExtendedPoll) + 1291+29 ( 2 0 4718.9083492152 2 5214.4456610929 ) 55.5764644844 (ExtendedPoll) + 1291+32 ( 2 0 4720.0070032202 2 5218.1920030108 ) 55.5244848408 (ExtendedPoll) + 1291+33 ( 2 0 4723.3029652354 2 5229.4310287644 ) 55.3687307229 (ExtendedPoll) + 1291+34 ( 2 0 4734.5488149269 2 5240.3493294358 ) 55.1527367318 (ExtendedPoll) + 1291+35 ( 2 0 4725.8141743898 2 5270.4838392888 ) 54.8793050383 (ExtendedPoll) + 1291+43 ( 2 0 4724.6472810056 2 5274.2097093929 ) 54.8463890957 (ExtendedPoll) + 1291+48 ( 2 0 4723.8706315711 2 5274.8016860074 ) 54.8459531010 (ExtendedPoll) + 1291+49 ( 2 0 4721.5406832677 2 5276.5776158510 ) 54.8446571102 (ExtendedPoll) + 1291+50 ( 2 0 4712.2208900540 2 5283.6813352253 ) 54.8396533297 (ExtendedPoll) + 1291+51 ( 2 0 4674.9417171991 2 5312.0962127226 ) 54.8225390616 (ExtendedPoll) + 1291+52 ( 2 0 4525.8250257796 2 5425.7557227117 ) 54.8016355518 (ExtendedPoll) + 1291+55 ( 2 0 4527.5719538871 2 5456.7636966185 ) 54.4520740351 (ExtendedPoll) + 1291+59 ( 2 0 4517.3087512560 2 5468.5554613436 ) 54.4117744769 (ExtendedPoll) + 1291+60 ( 2 0 4486.5191433627 2 5503.9307555188 ) 54.2947627479 (ExtendedPoll) + 1291+61 ( 2 0 4439.3520844623 2 5545.8570300970 ) 54.2549299012 (ExtendedPoll) + 1291+62 ( 2 0 4297.8509077611 2 5671.6358538313 ) 54.1955288613 (ExtendedPoll) + 1291+64 ( 2 0 4130.1458094486 2 5867.2918018626 ) 53.8101176125 (ExtendedPoll) + 1291+75 ( 2 0 4128.0235647556 2 5870.5672920640 ) 53.7990789831 (ExtendedPoll) + 1291+79 ( 2 0 4127.0989211675 2 5872.2886304042 ) 53.7915583989 (ExtendedPoll) + 1291+85 ( 2 0 4128.1741178860 2 5871.4215637923 ) 53.7897866464 (ExtendedPoll) + 1291+88 ( 2 0 4127.2012802363 2 5872.4020783721 ) 53.7895735461 (ExtendedPoll) + 1291+89 ( 2 0 4124.2827672873 2 5875.3436221116 ) 53.7889669943 (ExtendedPoll) + 1291+90 ( 2 0 4112.6087154913 2 5887.1097970695 ) 53.7870326237 (ExtendedPoll) + 1291+103 ( 2 0 4112.6224699912 2 5887.2310885676 ) 53.7857898087 (ExtendedPoll) + 1291+105 ( 2 0 4112.6068429068 2 5887.3521534897 ) 53.7848179668 (ExtendedPoll) + 1291+111 ( 2 0 4112.6094751875 2 5887.3825571652 ) 53.7845139164 (ExtendedPoll) + 1291+115 ( 2 0 4112.6011895425 2 5887.3953703748 ) 53.7844717434 (ExtendedPoll) + 1291+121 ( 2 0 4112.6098291866 2 5887.3889072301 ) 53.7844522046 (ExtendedPoll) + 1291+126 ( 2 0 4112.6115497632 2 5887.3880840681 ) 53.7844440412 (ExtendedPoll) + 1291+133 ( 2 0 4112.6117769427 2 5887.3881564070 ) 53.7844412964 (ExtendedPoll) + 1291+139 ( 2 0 4112.6117384418 2 5887.3882019087 ) 53.7844412297 (ExtendedPoll) + 1291+140 ( 2 0 4112.6116229393 2 5887.3883384136 ) 53.7844410296 (ExtendedPoll) + 1291+144 ( 2 0 4112.6116767374 2 5887.3883127527 ) 53.7844407736 (ExtendedPoll) + 1291+147 ( 2 0 4112.6116387835 2 5887.3883587115 ) 53.7844406977 (ExtendedPoll) + 1444+2 ( 2 0 4902.1720259844 2 5076.8648367266 ) 55.7342800977 (ExtendedPoll) + 1444+3 ( 2 0 4608.6881039375 2 5307.4593469062 ) 55.4177822439 (ExtendedPoll) + 1444+6 ( 2 0 4440.9830056251 2 5503.1152949375 ) 54.6903788761 (ExtendedPoll) + 1444+9 ( 2 0 4273.2779073126 2 5698.7712429687 ) 54.1421759642 (ExtendedPoll) + 1444+10 ( 2 0 3937.8677106876 2 6034.1814395937 ) 54.1025876908 (ExtendedPoll) + 1444+19 ( 2 0 3985.0347695880 2 5992.2551650155 ) 54.0228541969 (ExtendedPoll) + 1444+20 ( 2 0 4126.5359462891 2 5866.4763412812 ) 53.8506010417 (ExtendedPoll) + 1444+30 ( 2 0 4130.4392387792 2 5866.5172849087 ) 53.8146342551 (ExtendedPoll) + 1444+32 ( 2 0 4128.6854867338 2 5870.0111411235 ) 53.7981997187 (ExtendedPoll) + 1444+38 ( 2 0 4129.0689067457 2 5870.9093419522 ) 53.7863749691 (ExtendedPoll) + 1444+51 ( 2 0 4129.0636273984 2 5870.9236583107 ) 53.7862903829 (ExtendedPoll) + 1444+56 ( 2 0 4129.0651471032 2 5870.9311348262 ) 53.7862072107 (ExtendedPoll) + 1444+60 ( 2 0 4129.0646772976 2 5870.9349204804 ) 53.7861763981 (ExtendedPoll) + 1444+66 ( 2 0 4129.0641711296 2 5870.9357287432 ) 53.7861735204 (ExtendedPoll) + 1444+74 ( 2 0 4129.0643025908 2 5870.9356231986 ) 53.7861733001 (ExtendedPoll) + 1444+77 ( 2 0 4129.0644472731 2 5870.9355366612 ) 53.7861727831 (ExtendedPoll) + 1444+82 ( 2 0 4129.0644281460 2 5870.9355595157 ) 53.7861727456 (ExtendedPoll) + 1444+83 ( 2 0 4129.0643707645 2 5870.9356280794 ) 53.7861726332 (ExtendedPoll) + 1626+2 ( 2 0 4867.2334638359 2 5118.7911113047 ) 55.5101747565 (ExtendedPoll) + 1626+3 ( 2 0 4468.9338553438 2 5475.1644452187 ) 54.7497453707 (ExtendedPoll) + 1626+10 ( 2 0 4531.8232672110 2 5468.1767327890 ) 54.2937328699 (ExtendedPoll) + 1626+12 ( 2 0 4406.0444434766 2 5593.9555565234 ) 54.0419580454 (ExtendedPoll) + 1626+13 ( 2 0 4028.7079722735 2 5971.2920277265 ) 53.7998378556 (ExtendedPoll) + 1626+19 ( 2 0 4154.4867960079 2 5845.5132039921 ) 53.7918826239 (ExtendedPoll) + 1690+27 ( 2 0 4999.9918793150 2 5000.0071042165 ) 55.9016755069 (ExtendedPoll) + 1690+28 ( 2 0 4999.9675172600 2 5000.0284168659 ) 55.9016037165 (ExtendedPoll) + 1690+29 ( 2 0 4999.8700690400 2 5000.1136674635 ) 55.9013165752 (ExtendedPoll) + 1690+30 ( 2 0 4999.4802761598 2 5000.4546698539 ) 55.9001683374 (ExtendedPoll) + 1690+31 ( 2 0 4997.9211046392 2 5001.8186794156 ) 55.8955806263 (ExtendedPoll) + 1690+32 ( 2 0 4991.6844185568 2 5007.2747176624 ) 55.8773137258 (ExtendedPoll) + 1690+33 ( 2 0 4966.7376742271 2 5029.0988706497 ) 55.8055960661 (ExtendedPoll) + 1690+34 ( 2 0 4866.9506969084 2 5116.3954825988 ) 55.5407618647 (ExtendedPoll) + 1690+35 ( 2 0 4467.8027876336 2 5465.5819303951 ) 54.8617064546 (ExtendedPoll) + 1690+37 ( 2 0 4466.8269645111 2 5469.3623920026 ) 54.8295561915 (ExtendedPoll) + 1690+38 ( 2 0 4463.8994951436 2 5480.7037768250 ) 54.7333779337 (ExtendedPoll) + 1690+39 ( 2 0 4452.1896176735 2 5526.0693161146 ) 54.3527873521 (ExtendedPoll) + 1690+40 ( 2 0 4432.0999444382 2 5550.0895775916 ) 54.2727755505 (ExtendedPoll) + 1690+41 ( 2 0 4371.8309247321 2 5622.1503620228 ) 54.0490159101 (ExtendedPoll) + 1690+48 ( 2 0 4367.1633511951 2 5628.4010891571 ) 54.0259049915 (ExtendedPoll) + 1690+52 ( 2 0 4367.4363087119 2 5632.2975577092 ) 53.9839463746 (ExtendedPoll) + 1690+64 ( 2 0 4367.5173563027 2 5632.3888412069 ) 53.9823156833 (ExtendedPoll) + 1690+67 ( 2 0 4367.5750698909 2 5632.4087032645 ) 53.9816128497 (ExtendedPoll) + 1690+77 ( 2 0 4367.5769053809 2 5632.4193356014 ) 53.9814889495 (ExtendedPoll) + 1690+82 ( 2 0 4367.5805624212 2 5632.4182502476 ) 53.9814682147 (ExtendedPoll) + 1690+86 ( 2 0 4367.5821046999 2 5632.4171280385 ) 53.9814662175 (ExtendedPoll) + 1690+90 ( 2 0 4367.5818878523 2 5632.4180567321 ) 53.9814586704 (ExtendedPoll) + 1690+104 ( 2 0 4367.5819056985 2 5632.4180679393 ) 53.9814584017 (ExtendedPoll) + 1690+105 ( 2 0 4367.5819346476 2 5632.4180608593 ) 53.9814582222 (ExtendedPoll) + 1690+109 ( 2 0 4367.5819216978 2 5632.4180774844 ) 53.9814581658 (ExtendedPoll) + 1690+115 ( 2 0 4367.5819257648 2 5632.4180741356 ) 53.9814581645 (ExtendedPoll) + 1690+120 ( 2 0 4367.5819244247 2 5632.4180754292 ) 53.9814581630 (ExtendedPoll) + 1690+121 ( 2 0 4367.5819204043 2 5632.4180793101 ) 53.9814581585 (ExtendedPoll) + 1690+122 ( 2 0 4367.5819043228 2 5632.4180948339 ) 53.9814581405 (ExtendedPoll) + 1690+123 ( 2 0 4367.5818399969 2 5632.4181569287 ) 53.9814580686 (ExtendedPoll) + 1690+124 ( 2 0 4367.5815826929 2 5632.4184053083 ) 53.9814577808 (ExtendedPoll) + 1690+125 ( 2 0 4367.5805534773 2 5632.4193988263 ) 53.9814566296 (ExtendedPoll) + 1690+126 ( 2 0 4367.5764366146 2 5632.4233728987 ) 53.9814520249 (ExtendedPoll) + 1690+127 ( 2 0 4367.5599691638 2 5632.4392691879 ) 53.9814336068 (ExtendedPoll) + 1690+128 ( 2 0 4367.4940993607 2 5632.5028543451 ) 53.9813599484 (ExtendedPoll) + 1690+129 ( 2 0 4367.2306201483 2 5632.7571949737 ) 53.9810655359 (ExtendedPoll) + 1690+130 ( 2 0 4366.1767032985 2 5633.7745574881 ) 53.9798914222 (ExtendedPoll) + 1690+131 ( 2 0 4361.9610358996 2 5637.8440075457 ) 53.9752515834 (ExtendedPoll) + 1690+132 ( 2 0 4345.0983663039 2 5654.1218077760 ) 53.9576001475 (ExtendedPoll) + 1690+133 ( 2 0 4277.6476879210 2 5719.2330086971 ) 53.9016513465 (ExtendedPoll) + 1690+135 ( 2 0 4277.6290591203 2 5719.2571811144 ) 53.9015782727 (ExtendedPoll) + 1690+136 ( 2 0 4277.5731727181 2 5719.3296983663 ) 53.9013590679 (ExtendedPoll) + 1690+137 ( 2 0 4277.3496271092 2 5719.6197673739 ) 53.9004824970 (ExtendedPoll) + 1690+138 ( 2 0 4276.4554446736 2 5720.7800434043 ) 53.8969801836 (ExtendedPoll) + 1690+139 ( 2 0 4272.8787149315 2 5725.4211475259 ) 53.8830344924 (ExtendedPoll) + 1690+140 ( 2 0 4272.2449416972 2 5726.1641037669 ) 53.8813532804 (ExtendedPoll) + 1690+141 ( 2 0 4270.3436219944 2 5728.3929724899 ) 53.8763261624 (ExtendedPoll) + 1690+145 ( 2 0 4269.8544309447 2 5729.2382877997 ) 53.8723721175 (ExtendedPoll) + 1690+146 ( 2 0 4268.9604950773 2 5730.9749800002 ) 53.8632736922 (ExtendedPoll) + 1690+157 ( 2 0 4268.9281879962 2 5731.0267642928 ) 53.8630526551 (ExtendedPoll) + 1690+162 ( 2 0 4268.9081672520 2 5731.0497967493 ) 53.8630044126 (ExtendedPoll) + 1690+163 ( 2 0 4268.8481050197 2 5731.1188941187 ) 53.8628597009 (ExtendedPoll) + 1690+167 ( 2 0 4268.9130457179 2 5731.0620335227 ) 53.8628413313 (ExtendedPoll) + 1690+168 ( 2 0 4269.1078678127 2 5730.8914517347 ) 53.8627863397 (ExtendedPoll) + 1690+172 ( 2 0 4268.9798523367 2 5731.0072720873 ) 53.8627858887 (ExtendedPoll) + 1690+173 ( 2 0 4268.5958059087 2 5731.3547331451 ) 53.8627850104 (ExtendedPoll) + 1690+182 ( 2 0 4268.5734598444 2 5731.3755169174 ) 53.8627794333 (ExtendedPoll) + 1690+183 ( 2 0 4268.5064216515 2 5731.4378682344 ) 53.8627627170 (ExtendedPoll) + 1690+184 ( 2 0 4268.2382688801 2 5731.6872735026 ) 53.8626960762 (ExtendedPoll) + 1690+185 ( 2 0 4267.1656577944 2 5732.6848945752 ) 53.8624331084 (ExtendedPoll) + 1690+186 ( 2 0 4262.8752134514 2 5736.6753788658 ) 53.8614387941 (ExtendedPoll) + 1690+187 ( 2 0 4245.7134360797 2 5752.6373160280 ) 53.8583843412 (ExtendedPoll) + 1690+190 ( 2 0 4247.8459166796 2 5750.8801520137 ) 53.8564841075 (ExtendedPoll) + 1690+191 ( 2 0 4254.2433584792 2 5745.6086599708 ) 53.8509013362 (ExtendedPoll) + 1690+203 ( 2 0 4254.3648432334 2 5745.5967180794 ) 53.8499381914 (ExtendedPoll) + 1690+208 ( 2 0 4254.3884937761 2 5745.5774316250 ) 53.8499159225 (ExtendedPoll) + 1690+209 ( 2 0 4254.4594454040 2 5745.5195722617 ) 53.8498491302 (ExtendedPoll) + 1690+216 ( 2 0 4254.4747041982 2 5745.5195660142 ) 53.8497136099 (ExtendedPoll) + 1690+222 ( 2 0 4254.4785171266 2 5745.5196821982 ) 53.8496785985 (ExtendedPoll) + 1690+225 ( 2 0 4254.4745684192 2 5745.5233580070 ) 53.8496778754 (ExtendedPoll) + 1690+226 ( 2 0 4254.4627222968 2 5745.5343854333 ) 53.8496757065 (ExtendedPoll) + 1690+227 ( 2 0 4254.4153378073 2 5745.5784951385 ) 53.8496670379 (ExtendedPoll) + 1690+228 ( 2 0 4254.2257998495 2 5745.7549339594 ) 53.8496324765 (ExtendedPoll) + 1690+229 ( 2 0 4253.4676480183 2 5746.4606892429 ) 53.8494960362 (ExtendedPoll) + 1690+230 ( 2 0 4250.4350406932 2 5749.2837103771 ) 53.8489791731 (ExtendedPoll) + 1690+231 ( 2 0 4238.3046113928 2 5760.5757949136 ) 53.8473747522 (ExtendedPoll) + 1690+233 ( 2 0 4237.9514726055 2 5760.9129400964 ) 53.8472576934 (ExtendedPoll) + 1690+234 ( 2 0 4236.8920562434 2 5761.9243756450 ) 53.8469104201 (ExtendedPoll) + 1690+235 ( 2 0 4232.6543907954 2 5765.9701178391 ) 53.8455799016 (ExtendedPoll) + 1690+236 ( 2 0 4215.7037290030 2 5782.1530866154 ) 53.8411968855 (ExtendedPoll) + 1690+237 ( 2 0 4147.9010818337 2 5846.8849617209 ) 53.8388064213 (ExtendedPoll) + 1690+239 ( 2 0 4139.4939903168 2 5859.9869225266 ) 53.7929039460 (ExtendedPoll) + 1690+243 ( 2 0 4134.1713187395 2 5865.6917346274 ) 53.7882968215 (ExtendedPoll) + 1690+250 ( 2 0 4133.4948958932 2 5866.3963062176 ) 53.7879136446 (ExtendedPoll) + 1690+251 ( 2 0 4131.4656273543 2 5868.5100209882 ) 53.7867806418 (ExtendedPoll) + 1690+261 ( 2 0 4131.5933562783 2 5868.3938874275 ) 53.7866942837 (ExtendedPoll) + 1690+270 ( 2 0 4131.5998202039 2 5868.3898345950 ) 53.7866729850 (ExtendedPoll) + 1690+271 ( 2 0 4131.6192119808 2 5868.3776760976 ) 53.7866090899 (ExtendedPoll) + 1690+279 ( 2 0 4131.6209541211 2 5868.3784525807 ) 53.7865860060 (ExtendedPoll) + 1690+284 ( 2 0 4131.6214166274 2 5868.3783365570 ) 53.7865828676 (ExtendedPoll) + 1690+287 ( 2 0 4131.6210066099 2 5868.3788719382 ) 53.7865816357 (ExtendedPoll) + 1690+293 ( 2 0 4131.6209362583 2 5868.3789681750 ) 53.7865813838 (ExtendedPoll) + 1690+294 ( 2 0 4131.6207252036 2 5868.3792568852 ) 53.7865806279 (ExtendedPoll) + 1690+298 ( 2 0 4131.6206891940 2 5868.3793043828 ) 53.7865805153 (ExtendedPoll) + 1690+304 ( 2 0 4131.6206796375 2 5868.3793158160 ) 53.7865804962 (ExtendedPoll) + 1690+308 ( 2 0 4131.6206768768 2 5868.3793227362 ) 53.7865804572 (ExtendedPoll) + 1690+313 ( 2 0 4131.6206782642 2 5868.3793214934 ) 53.7865804561 (ExtendedPoll) + 1690+315 ( 2 0 4131.6206745081 2 5868.3793251876 ) 53.7865804560 (ExtendedPoll) + 1690+316 ( 2 0 4131.6206632396 2 5868.3793362702 ) 53.7865804559 (ExtendedPoll) + 1690+317 ( 2 0 4131.6206181660 2 5868.3793806004 ) 53.7865804552 (ExtendedPoll) + 1690+318 ( 2 0 4131.6204378713 2 5868.3795579212 ) 53.7865804528 (ExtendedPoll) + 1690+319 ( 2 0 4131.6197166927 2 5868.3802672046 ) 53.7865804428 (ExtendedPoll) + 1690+320 ( 2 0 4131.6168319783 2 5868.3831043383 ) 53.7865804032 (ExtendedPoll) + 1690+321 ( 2 0 4131.6052931206 2 5868.3944528729 ) 53.7865802452 (ExtendedPoll) + 1690+322 ( 2 0 4131.5591376898 2 5868.4398470112 ) 53.7865796204 (ExtendedPoll) + 1690+323 ( 2 0 4131.3745159668 2 5868.6214235646 ) 53.7865772402 (ExtendedPoll) + 1690+324 ( 2 0 4130.6360290747 2 5869.3477297782 ) 53.7865696199 (ExtendedPoll) + 1690+325 ( 2 0 4127.6820815062 2 5872.2529546326 ) 53.7865695587 (ExtendedPoll) + 1690+328 ( 2 0 4127.6840140147 2 5872.2603352230 ) 53.7864835442 (ExtendedPoll) + 1690+329 ( 2 0 4127.6898115401 2 5872.2824769939 ) 53.7862255016 (ExtendedPoll) + 1690+330 ( 2 0 4127.6796235307 2 5872.3112438240 ) 53.7860518834 (ExtendedPoll) + 1690+338 ( 2 0 4127.6784943469 2 5872.3148875688 ) 53.7860284213 (ExtendedPoll) + 1690+339 ( 2 0 4127.6750287014 2 5872.3216844082 ) 53.7859970553 (ExtendedPoll) + 1690+345 ( 2 0 4127.6738721701 2 5872.3232011194 ) 53.7859935510 (ExtendedPoll) + 1690+346 ( 2 0 4127.6704025761 2 5872.3277512530 ) 53.7859830384 (ExtendedPoll) + 1690+352 ( 2 0 4127.6704920471 2 5872.3287007212 ) 53.7859734249 (ExtendedPoll) + 1690+357 ( 2 0 4127.6702519860 2 5872.3291127215 ) 53.7859717972 (ExtendedPoll) + 1690+358 ( 2 0 4127.6695318024 2 5872.3303487226 ) 53.7859669139 (ExtendedPoll) + 1690+364 ( 2 0 4127.6693723329 2 5872.3305259594 ) 53.7859667262 (ExtendedPoll) + 1690+365 ( 2 0 4127.6688939242 2 5872.3310576698 ) 53.7859661633 (ExtendedPoll) + 1690+372 ( 2 0 4127.6688751072 2 5872.3311142263 ) 53.7859658109 (ExtendedPoll) + 1690+374 ( 2 0 4127.6689990935 2 5872.3309999936 ) 53.7859657384 (ExtendedPoll) + 1690+382 ( 2 0 4127.6690021165 2 5872.3309978166 ) 53.7859657310 (ExtendedPoll) + 2080+20 ( 2 0 4999.9878997345 2 5000.0092959702 ) 55.9016794952 (ExtendedPoll) + 2080+21 ( 2 0 4999.9515989379 2 5000.0371838810 ) 55.9016196708 (ExtendedPoll) + 2080+22 ( 2 0 4999.8063957515 2 5000.1487355238 ) 55.9013804121 (ExtendedPoll) + 2080+23 ( 2 0 4999.2255830062 2 5000.5949420954 ) 55.9004239959 (ExtendedPoll) + 2080+24 ( 2 0 4996.9023320246 2 5002.3797683814 ) 55.8966082342 (ExtendedPoll) + 2080+25 ( 2 0 4987.6093280984 2 5009.5190735258 ) 55.8815039246 (ExtendedPoll) + 2080+26 ( 2 0 4950.4373123937 2 5038.0762941031 ) 55.8236448341 (ExtendedPoll) + 2080+27 ( 2 0 4801.7492495748 2 5152.3051764124 ) 55.6343152023 (ExtendedPoll) + 2080+28 ( 2 0 4206.9969982993 2 5609.2207056496 ) 55.6253373563 (ExtendedPoll) + 2080+32 ( 2 0 4217.9971862258 2 5610.1214654550 ) 55.5187948731 (ExtendedPoll) + 2080+33 ( 2 0 4250.9977500050 2 5612.8237448711 ) 55.2000072940 (ExtendedPoll) + 2080+34 ( 2 0 4279.8220637775 2 5600.5952481192 ) 55.0710067569 (ExtendedPoll) + 2080+35 ( 2 0 4366.2950050949 2 5563.9097578633 ) 54.6951789859 (ExtendedPoll) + 2080+39 ( 2 0 4393.3723907599 2 5548.1874048965 ) 54.6249740689 (ExtendedPoll) + 2080+40 ( 2 0 4474.6045477550 2 5501.0203459961 ) 54.4266469861 (ExtendedPoll) + 2080+42 ( 2 0 4525.2654628702 2 5464.3348557403 ) 54.3900963042 (ExtendedPoll) + 2080+48 ( 2 0 4514.4563452056 2 5483.6602479286 ) 54.2742359116 (ExtendedPoll) + 2080+49 ( 2 0 4491.7462798091 2 5505.0601172445 ) 54.2385084897 (ExtendedPoll) + 2080+50 ( 2 0 4423.6160836196 2 5569.2597251923 ) 54.1460338788 (ExtendedPoll) + 2080+51 ( 2 0 4151.0952988618 2 5826.0581569833 ) 54.0054730693 (ExtendedPoll) + 2080+57 ( 2 0 4119.6505929283 2 5880.2129283134 ) 53.7862527117 (ExtendedPoll) + 2080+75 ( 2 0 4119.5665931846 2 5880.3014995623 ) 53.7862021958 (ExtendedPoll) + 2080+76 ( 2 0 4119.3145939537 2 5880.5672133090 ) 53.7860509080 (ExtendedPoll) + 2080+77 ( 2 0 4118.3065970302 2 5881.6300682960 ) 53.7854496575 (ExtendedPoll) + 2080+88 ( 2 0 4118.3108711544 2 5881.6602849630 ) 53.7851316932 (ExtendedPoll) + 2080+96 ( 2 0 4118.3198847115 2 5881.6662155602 ) 53.7849945777 (ExtendedPoll) + 2080+97 ( 2 0 4118.3348277986 2 5881.6631276284 ) 53.7848865134 (ExtendedPoll) + 2080+99 ( 2 0 4118.3462668702 2 5881.6530292707 ) 53.7848751796 (ExtendedPoll) + 2080+108 ( 2 0 4118.3455932557 2 5881.6537043543 ) 53.7848751047 (ExtendedPoll) + 2080+109 ( 2 0 4118.3435724122 2 5881.6557296052 ) 53.7848748801 (ExtendedPoll) + 2080+110 ( 2 0 4118.3354890381 2 5881.6638306090 ) 53.7848739818 (ExtendedPoll) + 2080+111 ( 2 0 4118.3031555418 2 5881.6962346240 ) 53.7848703922 (ExtendedPoll) + 2080+112 ( 2 0 4118.1738215565 2 5881.8258506839 ) 53.7848560937 (ExtendedPoll) + 2080+122 ( 2 0 4118.1735085463 2 5881.8262104036 ) 53.7848556344 (ExtendedPoll) + 2080+123 ( 2 0 4118.1725695157 2 5881.8272895629 ) 53.7848542566 (ExtendedPoll) + 2080+132 ( 2 0 4118.1726545887 2 5881.8272060557 ) 53.7848542498 (ExtendedPoll) + 2080+133 ( 2 0 4118.1729098077 2 5881.8269555344 ) 53.7848542294 (ExtendedPoll) + 2080+134 ( 2 0 4118.1739306837 2 5881.8259534489 ) 53.7848541479 (ExtendedPoll) + 2080+135 ( 2 0 4118.1780141879 2 5881.8219451070 ) 53.7848538220 (ExtendedPoll) + 2080+151 ( 2 0 4118.1780093963 2 5881.8219592167 ) 53.7848537356 (ExtendedPoll) + 2080+152 ( 2 0 4118.1779950216 2 5881.8220015460 ) 53.7848534763 (ExtendedPoll) + 2080+159 ( 2 0 4118.1779947385 2 5881.8220052606 ) 53.7848534446 (ExtendedPoll) + 2251+6 ( 2 0 4168.4622208673 2 5740.6975175468 ) 54.6654457702 (ExtendedPoll) + 2251+7 ( 2 0 3937.8677106876 2 6034.1814395937 ) 54.1025876908 (ExtendedPoll) + 2251+15 ( 2 0 3968.8756845943 2 6029.8141193251 ) 53.8471893590 (ExtendedPoll) + 2251+23 ( 2 0 3966.3440036262 2 6032.7893562581 ) 53.8453293272 (ExtendedPoll) + 2251+29 ( 2 0 3967.2852805629 2 6032.5287671287 ) 53.8387026417 (ExtendedPoll) + 2251+32 ( 2 0 3966.9613567598 2 6032.8941676795 ) 53.8385991104 (ExtendedPoll) + 2251+33 ( 2 0 3965.9895853505 2 6033.9903693319 ) 53.8382928991 (ExtendedPoll) + 2251+45 ( 2 0 3966.0039197226 2 6033.9851390276 ) 53.8382028409 (ExtendedPoll) + 2251+46 ( 2 0 3966.0291479677 2 6033.9679675607 ) 53.8381131770 (ExtendedPoll) + 2251+52 ( 2 0 3966.0378553973 2 6033.9615960721 ) 53.8380860741 (ExtendedPoll) + 2251+64 ( 2 0 3966.0380469160 2 6033.9618735742 ) 53.8380818691 (ExtendedPoll) + 2251+69 ( 2 0 3966.0381004053 2 6033.9618472758 ) 53.8380815916 (ExtendedPoll) + 2251+74 ( 2 0 3966.0381302064 2 6033.9618470067 ) 53.8380813128 (ExtendedPoll) + 2251+79 ( 2 0 3966.0381451069 2 6033.9618471499 ) 53.8380811710 (ExtendedPoll) + 2251+84 ( 2 0 3966.0381513080 2 6033.9618430199 ) 53.8380811481 (ExtendedPoll) + 2251+86 ( 2 0 3966.0381381930 2 6033.9618595149 ) 53.8380811293 (ExtendedPoll) + 2251+91 ( 2 0 3966.0381418784 2 6033.9618557502 ) 53.8380811271 (ExtendedPoll) + 2251+92 ( 2 0 3966.0381529347 2 6033.9618444560 ) 53.8380811204 (ExtendedPoll) + 2251+93 ( 2 0 3966.0381971599 2 6033.9617992793 ) 53.8380810935 (ExtendedPoll) + 2251+94 ( 2 0 3966.0383740607 2 6033.9616185725 ) 53.8380809858 (ExtendedPoll) + 2251+95 ( 2 0 3966.0390816638 2 6033.9608957451 ) 53.8380805552 (ExtendedPoll) + 2251+96 ( 2 0 3966.0419120761 2 6033.9580044356 ) 53.8380788327 (ExtendedPoll) + 2251+97 ( 2 0 3966.0532337255 2 6033.9464391976 ) 53.8380719433 (ExtendedPoll) + 2251+98 ( 2 0 3966.0985203229 2 6033.9001782457 ) 53.8380443936 (ExtendedPoll) + 2251+99 ( 2 0 3966.2796667126 2 6033.7151344380 ) 53.8379343190 (ExtendedPoll) + 2251+100 ( 2 0 3967.0042522715 2 6032.9749592074 ) 53.8374960138 (ExtendedPoll) + 2251+101 ( 2 0 3969.9025945070 2 6030.0142582847 ) 53.8357746693 (ExtendedPoll) + 2251+102 ( 2 0 3981.4959634492 2 6018.1714545940 ) 53.8293988351 (ExtendedPoll) + 2251+103 ( 2 0 4027.8694392178 2 5970.8002398312 ) 53.8120165816 (ExtendedPoll) + 2251+105 ( 2 0 4027.8996279793 2 5970.7957732839 ) 53.8117751288 (ExtendedPoll) + 2251+106 ( 2 0 4027.9901942637 2 5970.7823736422 ) 53.8110507797 (ExtendedPoll) + 2251+107 ( 2 0 4028.3524594017 2 5970.7287750751 ) 53.8081535202 (ExtendedPoll) + 2251+108 ( 2 0 4028.5782890972 2 5970.8215646372 ) 53.8052259801 (ExtendedPoll) + 2251+109 ( 2 0 4029.0659874104 2 5970.8447020517 ) 53.8004791353 (ExtendedPoll) + 2251+117 ( 2 0 4029.1224148462 2 5970.8679660822 ) 53.7997469853 (ExtendedPoll) + 2251+125 ( 2 0 4029.1289146169 2 5970.8639709871 ) 53.7997219690 (ExtendedPoll) + 2251+129 ( 2 0 4029.1327113864 2 5970.8636015775 ) 53.7996898997 (ExtendedPoll) + 2251+134 ( 2 0 4029.1345329350 2 5970.8641672091 ) 53.7996679124 (ExtendedPoll) + 2251+136 ( 2 0 4029.1361890843 2 5970.8632210851 ) 53.7996608999 (ExtendedPoll) + 2251+142 ( 2 0 4029.1366590260 2 5970.8631402857 ) 53.7996572423 (ExtendedPoll) + 2251+146 ( 2 0 4029.1368554851 2 5970.8630052034 ) 53.7996566135 (ExtendedPoll) + 2251+147 ( 2 0 4029.1372198865 2 5970.8626976562 ) 53.7996559536 (ExtendedPoll) + 2251+158 ( 2 0 4029.1372434032 2 5970.8627159631 ) 53.7996555720 (ExtendedPoll) + 2251+159 ( 2 0 4029.1372160758 2 5970.8627689341 ) 53.7996553557 (ExtendedPoll) + 2251+165 ( 2 0 4029.1372107574 2 5970.8627828538 ) 53.7996552815 (ExtendedPoll) + 2251+168 ( 2 0 4029.1372020883 2 5970.8627949737 ) 53.7996552545 (ExtendedPoll) + 2251+172 ( 2 0 4029.1371973626 2 5970.8628007338 ) 53.7996552473 (ExtendedPoll) + 2251+179 ( 2 0 4029.1371969852 2 5970.8628025579 ) 53.7996552346 (ExtendedPoll) + 2251+181 ( 2 0 4029.1372006890 2 5970.8627988111 ) 53.7996552334 (ExtendedPoll) + 2251+182 ( 2 0 4029.1372118001 2 5970.8627875709 ) 53.7996552298 (ExtendedPoll) + 2251+183 ( 2 0 4029.1372562449 2 5970.8627426102 ) 53.7996552156 (ExtendedPoll) + 2251+184 ( 2 0 4029.1374340239 2 5970.8625627674 ) 53.7996551585 (ExtendedPoll) + 2251+185 ( 2 0 4029.1381451401 2 5970.8618433959 ) 53.7996549302 (ExtendedPoll) + 2251+186 ( 2 0 4029.1409896047 2 5970.8589659099 ) 53.7996540170 (ExtendedPoll) + 2251+187 ( 2 0 4029.1523674632 2 5970.8474559659 ) 53.7996503647 (ExtendedPoll) + 2251+188 ( 2 0 4029.1978788972 2 5970.8014161900 ) 53.7996357631 (ExtendedPoll) + 2251+189 ( 2 0 4029.3799246331 2 5970.6172570866 ) 53.7995774796 (ExtendedPoll) + 2251+190 ( 2 0 4030.1081075767 2 5969.8806206727 ) 53.7993463077 (ExtendedPoll) + 2251+191 ( 2 0 4033.0208393511 2 5966.9340750174 ) 53.7984530101 (ExtendedPoll) + 2251+192 ( 2 0 4044.6717664489 2 5955.1478923961 ) 53.7953815270 (ExtendedPoll) + 2251+193 ( 2 0 4091.2754748399 2 5908.0031619108 ) 53.7910882360 (ExtendedPoll) + 2251+196 ( 2 0 4091.3024169829 2 5908.0174949293 ) 53.7907097823 (ExtendedPoll) + 2251+197 ( 2 0 4091.3832434122 2 5908.0604939849 ) 53.7895744291 (ExtendedPoll) + 2251+198 ( 2 0 4091.7065491291 2 5908.2324902073 ) 53.7850331320 (ExtendedPoll) + 2251+201 ( 2 0 4091.7062625770 2 5908.2935241345 ) 53.7844786297 (ExtendedPoll) + 2251+218 ( 2 0 4091.7061814853 2 5908.2937483387 ) 53.7844773284 (ExtendedPoll) + 2251+225 ( 2 0 4091.7061774429 2 5908.2938078061 ) 53.7844768227 (ExtendedPoll) + 2251+228 ( 2 0 4091.7061404988 2 5908.2938545806 ) 53.7844767353 (ExtendedPoll) + 2251+237 ( 2 0 4091.7061392073 2 5908.2938580748 ) 53.7844767152 (ExtendedPoll) + 2251+242 ( 2 0 4091.7061402086 2 5908.2938596455 ) 53.7844766917 (ExtendedPoll) + 2251+251 ( 2 0 4091.7061402086 2 5908.2938597496 ) 53.7844766907 (ExtendedPoll) + 2507+6 ( 2 0 4987.7715032480 2 5009.7172875975 ) 55.8778410034 (ExtendedPoll) + 2507+7 ( 2 0 4951.0860129922 2 5038.8691503901 ) 55.8090330212 (ExtendedPoll) + 2507+8 ( 2 0 4804.3440519688 2 5155.4766015605 ) 55.5765193455 (ExtendedPoll) + 2507+9 ( 2 0 4217.3762078751 2 5621.9064062421 ) 55.4051303015 (ExtendedPoll) + 2507+11 ( 2 0 4105.5728090001 2 5845.5132039921 ) 54.2371769988 (ExtendedPoll) + 2507+17 ( 2 0 4084.6096717110 2 5904.9087596444 ) 53.8806341533 (ExtendedPoll) + 2507+25 ( 2 0 4086.4930785768 2 5912.4969786111 ) 53.7940773323 (ExtendedPoll) + 2507+28 ( 2 0 4089.6866815232 2 5910.2450790976 ) 53.7852355401 (ExtendedPoll) + 2507+40 ( 2 0 4089.7473972443 2 5910.2388432578 ) 53.7847342099 (ExtendedPoll) + 2507+48 ( 2 0 4089.7542955796 2 5910.2355843266 ) 53.7847005125 (ExtendedPoll) + 2507+49 ( 2 0 4089.7673972155 2 5910.2277626627 ) 53.7846513996 (ExtendedPoll) + 2507+51 ( 2 0 4089.7801055712 2 5910.2193169774 ) 53.7846115945 (ExtendedPoll) + 2507+62 ( 2 0 4089.7805040628 2 5910.2190551032 ) 53.7846103195 (ExtendedPoll) + 2507+63 ( 2 0 4089.7816995375 2 5910.2182694805 ) 53.7846064942 (ExtendedPoll) + 2507+73 ( 2 0 4089.7816945523 2 5910.2182988629 ) 53.7846062720 (ExtendedPoll) + 2507+80 ( 2 0 4089.7816938911 2 5910.2183025290 ) 53.7846062447 (ExtendedPoll) + 2507+83 ( 2 0 4089.7816931323 2 5910.2183061762 ) 53.7846062184 (ExtendedPoll) + 2507+86 ( 2 0 4089.7816946030 2 5910.2183050332 ) 53.7846062153 (ExtendedPoll) + 2507+97 ( 2 0 4089.7816947071 2 5910.2183050332 ) 53.7846062143 (ExtendedPoll) + 2609+6 ( 2 0 4993.6127941072 2 5004.5037990269 ) 55.8961392637 (ExtendedPoll) + 2609+7 ( 2 0 4974.4511764290 2 5018.0151961078 ) 55.8801113087 (ExtendedPoll) + 2609+8 ( 2 0 4897.8047057158 2 5072.0607844311 ) 55.8259328921 (ExtendedPoll) + 2609+9 ( 2 0 4591.2188228633 2 5288.2431377246 ) 55.7773330381 (ExtendedPoll) + 2609+12 ( 2 0 4584.2311104336 2 5414.0219614589 ) 54.4414663757 (ExtendedPoll) + 2609+22 ( 2 0 4587.3564740008 2 5411.6745268146 ) 54.4410956907 (ExtendedPoll) + 2609+29 ( 2 0 4587.5587397857 2 5412.1189357716 ) 54.4345618898 (ExtendedPoll) + 2609+33 ( 2 0 4587.4405737045 2 5412.3325570157 ) 54.4332122013 (ExtendedPoll) + 2609+34 ( 2 0 4587.0527821074 2 5412.6292916912 ) 54.4331973113 (ExtendedPoll) + 2609+35 ( 2 0 4585.8894073161 2 5413.5194957176 ) 54.4331558220 (ExtendedPoll) + 2609+36 ( 2 0 4581.2359081511 2 5417.0803118233 ) 54.4330376116 (ExtendedPoll) + 2609+38 ( 2 0 4579.3525012852 2 5420.4991047210 ) 54.4114704020 (ExtendedPoll) + 2609+39 ( 2 0 4573.3201401643 2 5425.4669315265 ) 54.4076771370 (ExtendedPoll) + 2609+40 ( 2 0 4555.2230568015 2 5440.3704119429 ) 54.3971432812 (ExtendedPoll) + 2609+41 ( 2 0 4482.8347233502 2 5499.9843336087 ) 54.3678394409 (ExtendedPoll) + 2609+49 ( 2 0 4485.3459325046 2 5507.3814823136 ) 54.2681454161 (ExtendedPoll) + 2609+50 ( 2 0 4475.1919128802 2 5519.2824300454 ) 54.2285251876 (ExtendedPoll) + 2609+51 ( 2 0 4444.7298540071 2 5554.9852732408 ) 54.1136470777 (ExtendedPoll) + 2609+58 ( 2 0 4443.9800738281 2 5555.6109430488 ) 54.1135341068 (ExtendedPoll) + 2609+59 ( 2 0 4441.7307332914 2 5557.4879524728 ) 54.1132091099 (ExtendedPoll) + 2609+60 ( 2 0 4432.7333711444 2 5564.9959901689 ) 54.1121181220 (ExtendedPoll) + 2609+61 ( 2 0 4396.7439225563 2 5595.0281409531 ) 54.1111148301 (ExtendedPoll) + 2609+63 ( 2 0 4386.2623539118 2 5606.6015396648 ) 54.0828747897 (ExtendedPoll) + 2609+64 ( 2 0 4354.8176479782 2 5641.3217357998 ) 54.0021675011 (ExtendedPoll) + 2609+67 ( 2 0 4332.5443146086 2 5663.1583371426 ) 53.9763377152 (ExtendedPoll) + 2609+68 ( 2 0 4265.7243144997 2 5728.6681411709 ) 53.9145504521 (ExtendedPoll) + 2609+69 ( 2 0 3998.4443140642 2 5990.7073572841 ) 53.9107416673 (ExtendedPoll) + 2609+77 ( 2 0 3977.9179088020 2 6014.2908867343 ) 53.8968485442 (ExtendedPoll) + 2609+85 ( 2 0 3977.6108315956 2 6018.1873552864 ) 53.8658100136 (ExtendedPoll) + 2609+87 ( 2 0 3985.4720080790 2 6010.4353618097 ) 53.8594585168 (ExtendedPoll) + 2609+88 ( 2 0 4009.0555375292 2 5987.1793813797 ) 53.8425419841 (ExtendedPoll) + 2609+89 ( 2 0 4103.3896553299 2 5894.1554596595 ) 53.8066758321 (ExtendedPoll) + 2609+98 ( 2 0 4105.0239884617 2 5893.0858073906 ) 53.8015202481 (ExtendedPoll) + 2609+99 ( 2 0 4109.9269878569 2 5889.8768505839 ) 53.7861093451 (ExtendedPoll) + 2609+108 ( 2 0 4110.1419152454 2 5889.7610302313 ) 53.7852071379 (ExtendedPoll) + 2609+116 ( 2 0 4110.1058896513 2 5889.8103005292 ) 53.7850837032 (ExtendedPoll) + 2609+117 ( 2 0 4109.9978128689 2 5889.9581114227 ) 53.7847134692 (ExtendedPoll) + 2609+120 ( 2 0 4110.1308929863 2 5889.8481353998 ) 53.7845067680 (ExtendedPoll) + 2609+123 ( 2 0 4110.2185046189 2 5889.7631360559 ) 53.7844866226 (ExtendedPoll) + 2609+124 ( 2 0 4110.4813395169 2 5889.5081380242 ) 53.7844264399 (ExtendedPoll) + 2609+134 ( 2 0 4110.4929230099 2 5889.4982056417 ) 53.7844117835 (ExtendedPoll) + 2609+135 ( 2 0 4110.5276734889 2 5889.4684084945 ) 53.7843678178 (ExtendedPoll) + 2609+142 ( 2 0 4110.5308528491 2 5889.4663005158 ) 53.7843581081 (ExtendedPoll) + 2609+143 ( 2 0 4110.5369402846 2 5889.4617014955 ) 53.7843446963 (ExtendedPoll) + 2609+148 ( 2 0 4110.5385864786 2 5889.4607381551 ) 53.7843384902 (ExtendedPoll) + 2609+154 ( 2 0 4110.5389368624 2 5889.4610615818 ) 53.7843323072 (ExtendedPoll) + 2609+174 ( 2 0 4110.5389372789 2 5889.4610615818 ) 53.7843323034 (ExtendedPoll) + 2609+179 ( 2 0 4110.5389372789 2 5889.4610619983 ) 53.7843322995 (ExtendedPoll) + 2609+185 ( 2 0 4110.5389372789 2 5889.4610621024 ) 53.7843322986 (ExtendedPoll) + 2609+186 ( 2 0 4110.5389372789 2 5889.4610624148 ) 53.7843322957 (ExtendedPoll) + 2609+193 ( 2 0 4110.5389373050 2 5889.4610624148 ) 53.7843322955 (ExtendedPoll) + 2609+194 ( 2 0 4110.5389373831 2 5889.4610624148 ) 53.7843322947 (ExtendedPoll) + 2808+6 ( 2 0 4329.1796067501 2 5670.8203932499 ) 53.9289318169 (ExtendedPoll) + 2867+10 ( 2 0 4992.1115277649 2 5007.7246977250 ) 55.8685413615 (ExtendedPoll) + 2867+11 ( 2 0 4968.4461110597 2 5030.8987909000 ) 55.7705699043 (ExtendedPoll) + 2867+12 ( 2 0 4873.7844442388 2 5123.5951636001 ) 55.4016911655 (ExtendedPoll) + 2867+13 ( 2 0 4495.1377769551 2 5494.3806544003 ) 54.3231819620 (ExtendedPoll) + 2867+15 ( 2 0 4411.2852277989 2 5585.2209159863 ) 54.0868469342 (ExtendedPoll) + 2867+22 ( 2 0 4407.4365268122 2 5592.0175581542 ) 54.0499159225 (ExtendedPoll) + 2867+28 ( 2 0 4405.3364599175 2 5593.8105478426 ) 54.0495510124 (ExtendedPoll) + 2867+29 ( 2 0 4399.0362592332 2 5599.1895169077 ) 54.0485700853 (ExtendedPoll) + 2867+30 ( 2 0 4373.8354564960 2 5620.7053931683 ) 54.0463593230 (ExtendedPoll) + 2867+33 ( 2 0 4369.7137979926 2 5627.3382608261 ) 54.0145749170 (ExtendedPoll) + 2867+40 ( 2 0 4368.6287918634 2 5628.9623580510 ) 54.0074781800 (ExtendedPoll) + 2867+41 ( 2 0 4365.3737734757 2 5633.8346497256 ) 53.9862560504 (ExtendedPoll) + 2867+43 ( 2 0 4362.6919658733 2 5636.6802318381 ) 53.9806946516 (ExtendedPoll) + 2867+44 ( 2 0 4354.6465430661 2 5645.2169781755 ) 53.9642607181 (ExtendedPoll) + 2867+50 ( 2 0 4354.0247117231 2 5645.9701703234 ) 53.9620624682 (ExtendedPoll) + 2867+61 ( 2 0 4354.0368388529 2 5645.9609094433 ) 53.9620504600 (ExtendedPoll) + 2867+65 ( 2 0 4354.0401585606 2 5645.9590302273 ) 53.9620405451 (ExtendedPoll) + 2867+71 ( 2 0 4354.0409392116 2 5645.9584824325 ) 53.9620392835 (ExtendedPoll) + 2867+74 ( 2 0 4354.0405359427 2 5645.9593466482 ) 53.9620340616 (ExtendedPoll) + 2867+87 ( 2 0 4354.0405617934 2 5645.9593318187 ) 53.9620339864 (ExtendedPoll) + 2867+88 ( 2 0 4354.0406393458 2 5645.9592873300 ) 53.9620337607 (ExtendedPoll) + 2867+89 ( 2 0 4354.0407417896 2 5645.9592263700 ) 53.9620334847 (ExtendedPoll) + 2867+98 ( 2 0 4354.0407563620 2 5645.9592294825 ) 53.9620333264 (ExtendedPoll) + 2867+99 ( 2 0 4354.0407811713 2 5645.9592129695 ) 53.9620332772 (ExtendedPoll) + 2867+106 ( 2 0 4354.0407786145 2 5645.9592156788 ) 53.9620332721 (ExtendedPoll) + 2867+107 ( 2 0 4354.0407709439 2 5645.9592238067 ) 53.9620332568 (ExtendedPoll) + 2867+108 ( 2 0 4354.0407402615 2 5645.9592563181 ) 53.9620331954 (ExtendedPoll) + 2867+114 ( 2 0 4354.0407434536 2 5645.9592543977 ) 53.9620331870 (ExtendedPoll) + 2867+122 ( 2 0 4354.0407434536 2 5645.9592560637 ) 53.9620331701 (ExtendedPoll) + 2867+123 ( 2 0 4354.0407422389 2 5645.9592574757 ) 53.9620331665 (ExtendedPoll) + 3058+8 ( 2 0 4991.1561764562 2 5006.6055719062 ) 55.8895337846 (ExtendedPoll) + 3058+9 ( 2 0 4964.6247058247 2 5026.4222876248 ) 55.8543769246 (ExtendedPoll) + 3058+10 ( 2 0 4858.4988232988 2 5105.6891504990 ) 55.7342678543 (ExtendedPoll) + 3058+11 ( 2 0 4433.9952931954 2 5422.7566019961 ) 55.6083992097 (ExtendedPoll) + 3058+16 ( 2 0 4468.9338553438 2 5473.4175171113 ) 54.7683907188 (ExtendedPoll) + 3058+17 ( 2 0 4371.1058813282 2 5557.2700662675 ) 54.7224471575 (ExtendedPoll) + 3058+22 ( 2 0 4374.5997375430 2 5620.1594781347 ) 54.0452990385 (ExtendedPoll) + 3058+26 ( 2 0 4353.6366002540 2 5643.3062755580 ) 53.9923716603 (ExtendedPoll) + 3058+34 ( 2 0 4352.3741717388 2 5647.0048499105 ) 53.9659824019 (ExtendedPoll) + 3058+41 ( 2 0 4352.7757178358 2 5646.7270943123 ) 53.9652910126 (ExtendedPoll) + 3058+42 ( 2 0 4353.9803561267 2 5645.8938275179 ) 53.9632201609 (ExtendedPoll) + 3058+50 ( 2 0 4353.8820221150 2 5646.1172848288 ) 53.9618183016 (ExtendedPoll) + 3058+67 ( 2 0 4353.8828862995 2 5646.1168814928 ) 53.9618148524 (ExtendedPoll) + 3058+70 ( 2 0 4353.8819301637 2 5646.1178326989 ) 53.9618135661 (ExtendedPoll) + 3058+71 ( 2 0 4353.8790617562 2 5646.1206863173 ) 53.9618097072 (ExtendedPoll) + 3058+72 ( 2 0 4353.8675881265 2 5646.1321007910 ) 53.9617942721 (ExtendedPoll) + 3058+73 ( 2 0 4353.8216936077 2 5646.1777586857 ) 53.9617325386 (ExtendedPoll) + 3058+74 ( 2 0 4353.6381155322 2 5646.3603902646 ) 53.9614857168 (ExtendedPoll) + 3058+75 ( 2 0 4352.9038032305 2 5647.0909165803 ) 53.9605002241 (ExtendedPoll) + 3058+76 ( 2 0 4349.9665540238 2 5650.0130218428 ) 53.9565869794 (ExtendedPoll) + 3058+77 ( 2 0 4338.2175571967 2 5661.7014428928 ) 53.9413943430 (ExtendedPoll) + 3058+78 ( 2 0 4291.2215698885 2 5708.4551270929 ) 53.8880355778 (ExtendedPoll) + 3058+79 ( 2 0 4103.2376206554 2 5895.4698638933 ) 53.7960048025 (ExtendedPoll) + 3058+83 ( 2 0 4103.0824826918 2 5895.9328254315 ) 53.7931789654 (ExtendedPoll) + 3058+84 ( 2 0 4102.6170688008 2 5897.3217100462 ) 53.7847063488 (ExtendedPoll) + 3058+88 ( 2 0 4102.3017815441 2 5897.6944676551 ) 53.7841793274 (ExtendedPoll) + 3058+104 ( 2 0 4102.3028217662 2 5897.6960663778 ) 53.7841551305 (ExtendedPoll) + 3058+106 ( 2 0 4102.3045951993 2 5897.6953642985 ) 53.7841453060 (ExtendedPoll) + 3058+116 ( 2 0 4102.3046242597 2 5897.6953709067 ) 53.7841449789 (ExtendedPoll) + 3058+126 ( 2 0 4102.3046246516 2 5897.6953727277 ) 53.7841449586 (ExtendedPoll) + 3058+128 ( 2 0 4102.3046253455 2 5897.6953744562 ) 53.7841449364 (ExtendedPoll) + 3058+140 ( 2 0 4102.3046253471 2 5897.6953744562 ) 53.7841449364 (ExtendedPoll) + 3058+141 ( 2 0 4102.3046253520 2 5897.6953744562 ) 53.7841449364 (ExtendedPoll) + 3058+142 ( 2 0 4102.3046253715 2 5897.6953744562 ) 53.7841449362 (ExtendedPoll) + 3058+143 ( 2 0 4102.3046254496 2 5897.6953744562 ) 53.7841449355 (ExtendedPoll) + 3211+9 ( 2 0 4999.2843395107 2 5000.6644809549 ) 55.8991235044 (ExtendedPoll) + 3211+10 ( 2 0 4997.1373580427 2 5002.6579238197 ) 55.8914071579 (ExtendedPoll) + 3211+11 ( 2 0 4988.5494321709 2 5010.6316952788 ) 55.8607138749 (ExtendedPoll) + 3211+12 ( 2 0 4954.1977286835 2 5042.5267811150 ) 55.7407142386 (ExtendedPoll) + 3211+13 ( 2 0 4816.7909147341 2 5170.1071244602 ) 55.3063592103 (ExtendedPoll) + 3211+14 ( 2 0 4267.1636589366 2 5680.4284978408 ) 54.3782156485 (ExtendedPoll) + 3211+16 ( 2 0 4258.4290183995 2 5741.5709816005 ) 53.8530873348 (ExtendedPoll) + 3275+16 ( 2 0 4999.4544048385 2 5000.4231907750 ) 55.9007514521 (ExtendedPoll) + 3275+17 ( 2 0 4997.8176193541 2 5001.6927631002 ) 55.8979127990 (ExtendedPoll) + 3275+18 ( 2 0 4991.2704774163 2 5006.7710524007 ) 55.8866378337 (ExtendedPoll) + 3275+19 ( 2 0 4965.0819096653 2 5027.0842096030 ) 55.8428188421 (ExtendedPoll) + 3275+20 ( 2 0 4860.3276386613 2 5108.3368384118 ) 55.6884538793 (ExtendedPoll) + 3275+21 ( 2 0 4441.3105546452 2 5433.3473536473 ) 55.4321933111 (ExtendedPoll) + 3275+24 ( 2 0 4440.4370905915 2 5464.7920595809 ) 55.1023491348 (ExtendedPoll) + 3275+25 ( 2 0 4437.8166984304 2 5559.1261773817 ) 54.1296401397 (ExtendedPoll) + 3275+28 ( 2 0 4394.1434957448 2 5604.5463081746 ) 54.0358312283 (ExtendedPoll) + 3275+31 ( 2 0 4348.7233649518 2 5648.2195108602 ) 53.9855229289 (ExtendedPoll) + 3275+32 ( 2 0 4212.4629725730 2 5779.2391189168 ) 53.8982210340 (ExtendedPoll) + 3275+39 ( 2 0 4246.9648026945 2 5751.7250012249 ) 53.8561122313 (ExtendedPoll) + 3275+44 ( 2 0 4253.1063468222 2 5746.8663574261 ) 53.8487569023 (ExtendedPoll) + 3275+54 ( 2 0 4253.0200213419 2 5746.9526629144 ) 53.8486838339 (ExtendedPoll) + 3275+55 ( 2 0 4252.7610449010 2 5747.2115793792 ) 53.8484648755 (ExtendedPoll) + 3275+56 ( 2 0 4251.7251391376 2 5748.2472452386 ) 53.8475927460 (ExtendedPoll) + 3275+57 ( 2 0 4247.5815160840 2 5752.3899086759 ) 53.8441635235 (ExtendedPoll) + 3275+58 ( 2 0 4231.0070238695 2 5768.9605624254 ) 53.8313972696 (ExtendedPoll) + 3275+59 ( 2 0 4164.7090550115 2 5835.2431774231 ) 53.7956619398 (ExtendedPoll) + 3275+72 ( 2 0 4164.7639497269 2 5835.2164964256 ) 53.7954160381 (ExtendedPoll) + 3275+76 ( 2 0 4164.7917332002 2 5835.2038710575 ) 53.7952833211 (ExtendedPoll) + 3275+77 ( 2 0 4164.8360404827 2 5835.1618928437 ) 53.7952771546 (ExtendedPoll) + 3275+85 ( 2 0 4164.8422068711 2 5835.1574002652 ) 53.7952636014 (ExtendedPoll) + 3275+97 ( 2 0 4164.8424175700 2 5835.1572886885 ) 53.7952627439 (ExtendedPoll) + 3275+102 ( 2 0 4164.8423842792 2 5835.1574031550 ) 53.7952619685 (ExtendedPoll) + 3275+109 ( 2 0 4164.8424622828 2 5835.1574351058 ) 53.7952609619 (ExtendedPoll) + 3275+110 ( 2 0 4164.8424186334 2 5835.1575460363 ) 53.7952603135 (ExtendedPoll) + 3275+117 ( 2 0 4164.8424468760 2 5835.1575365215 ) 53.7952601474 (ExtendedPoll) + 3275+121 ( 2 0 4164.8424209888 2 5835.1575697812 ) 53.7952600688 (ExtendedPoll) + 3275+129 ( 2 0 4164.8424239711 2 5835.1575675489 ) 53.7952600628 (ExtendedPoll) + 3275+130 ( 2 0 4164.8424329181 2 5835.1575608518 ) 53.7952600448 (ExtendedPoll) + 3275+135 ( 2 0 4164.8424361867 2 5835.1575626390 ) 53.7952599984 (ExtendedPoll) + 3275+138 ( 2 0 4164.8424402468 2 5835.1575592816 ) 53.7952599933 (ExtendedPoll) + 3275+145 ( 2 0 4164.8424410483 2 5835.1575588074 ) 53.7952599905 (ExtendedPoll) + 3275+147 ( 2 0 4164.8424392431 2 5835.1575607257 ) 53.7952599888 (ExtendedPoll) + 3436 ( 3 0 3333.3333333333 2 3333.3333333333 1 3333.3333333333 ) 47.1682905221 -} end of run (max number of blackbox evaluations) +} end of run (mesh size reached NOMAD precision) -blackbox evaluations : 200 -best feasible solution : ( 3 0 2939.656576 2 3626.302083 1 3433.43099 ) h=0 f=46.59711656 +blackbox evaluations : 3436 +best feasible solution : ( 3 0 3333.333333 2 3333.333333 1 3333.333333 ) h=0 f=47.16829052 diff --git a/examples/advanced/multi_start/best_x.txt b/examples/advanced/multi_start/best_x.txt index 665726732356c766af84b26fc74f61c783f6da67..7588ff3216d3708027e7f2604527f364b46422bd 100644 --- a/examples/advanced/multi_start/best_x.txt +++ b/examples/advanced/multi_start/best_x.txt @@ -1 +1 @@ -1.001496962026439119242127162579 0.00098876953124999995663191310057982 1.0009373918174639950251503250911 1.0017943110223916924894638214028 1.0001091153523589127871673554182 \ No newline at end of file +1.0065227779901828597530766273849 0.0061576008796691908409037807814457 0.99995827823866767491978180260048 1.0093326058145666301868459413527 1.0032484173774720570548879550188 \ No newline at end of file diff --git a/examples/advanced/multi_start/param.txt b/examples/advanced/multi_start/param.txt index 7a4df995884db1f315f72b9b0941a7055b4b88db..09df94229bef78206defdabb33a7244c132000ac 100644 --- a/examples/advanced/multi_start/param.txt +++ b/examples/advanced/multi_start/param.txt @@ -1,9 +1,7 @@ MAX_CACHE_MEMORY 750 -seed none - -#initial_mesh_size r0.1 +initial_mesh_size r0.1 opportunistic_eval no diff --git a/examples/advanced/multi_start/runExample.log b/examples/advanced/multi_start/runExample.log index 94584ab0f10fe5167ef3b39b67e9656620a3f7ef..51c3fae4cd73f2db08edfd9a5272e997f4854069 100644 --- a/examples/advanced/multi_start/runExample.log +++ b/examples/advanced/multi_start/runExample.log @@ -1,18 +1,21 @@ -starting point # 0: ( 1.442943417 0.369140625 0.9823972059 0.8663984208 1.488629702 ) -starting point # 1: ( 4.046907118 0.2179386209 0.3995457903 2.86002185 2.869872299 ) -starting point # 2: ( 2.730496038 4.019688198 2.015450408 3.887235003 1.919237215 ) -starting point # 3: ( 1.986593711 1.814325217 1.166098379 0.9517739273 0.4086947283 ) -starting point # 4: ( 1.072412482 2.713920967 3.075009451 0.3310437183 1.032300187 ) +starting point # 0: ( 1.311638583 0.3116009987 0.9520390845 0.8088161243 1.540724398 1.619263445 0.9519058983 ) +starting point # 1: ( 4.046907118 0.2179386209 0.3995457903 2.86002185 2.869872299 1.805805862 0.9241232544 ) +starting point # 2: ( 2.730496038 4.019688198 2.015450408 3.887235003 1.919237215 0.004176816764 2.788539635 ) +starting point # 3: ( 1.986593711 1.814325217 1.166098379 0.9517739273 0.4086947283 3.9836116 2.239536416 ) +starting point # 4: ( 1.072412482 2.713920967 3.075009451 0.3310437183 1.032300187 3.079123794 3.985637823 ) -run # 0: f=1.506294281 -run # 1: f=1.415934966 -run # 2: f=2.001223577 -run # 3: f=1.799944829 -run # 4: f=2.61048503 +Warning: { + Anisotropic mesh is disabled for direction types other than OrthoMads. +} +run # 0: f=1.619155361 +run # 1: f=1.890750373 +run # 2: f=2.267307514 +run # 3: f=1.998968772 +run # 4: f=2.24968126 bb eval : 5000 -best : 1.415934966 -worst : 2.61048503 -solution: x = ( 1.001496962 0.0009887695312 1.000937392 1.001794311 1.000109115 ) f(x) = 1.415934966 +best : 1.619155361 +worst : 2.267307514 +solution: x = ( 1.310592306 0.3106177009 0.9507953978 0.8088442339 1.538847818 1.618878923 0.951419131 ) f(x) = 1.619155361 diff --git a/examples/advanced/plot/problems/02/parameters.txt b/examples/advanced/plot/problems/02/param.txt similarity index 100% rename from examples/advanced/plot/problems/02/parameters.txt rename to examples/advanced/plot/problems/02/param.txt diff --git a/examples/advanced/restart/restart.cpp b/examples/advanced/restart/restart.cpp index ae5b7a82aea059cd505aa56b1a67b6358abb1b4a..e41b0dc24feab2bc43e8b1599c1426367e4267bb 100644 --- a/examples/advanced/restart/restart.cpp +++ b/examples/advanced/restart/restart.cpp @@ -11,32 +11,14 @@ using namespace NOMAD; class My_Evaluator : public Evaluator { private: - double _mesh_update_basis; - int _initial_mesh_index; - int _mesh_index; - Point _initial_mesh_size; - public: - My_Evaluator ( const Parameters & p ) : - Evaluator ( p ) , - _mesh_update_basis ( p.get_mesh_update_basis().value() ) , - _initial_mesh_index ( p.get_initial_mesh_index() ) , - _mesh_index ( _initial_mesh_index ) , - _initial_mesh_size ( p.get_initial_mesh_size() ) {} + + My_Evaluator ( const Parameters & p ) : Evaluator ( p ) { } + + ~My_Evaluator ( void ) {} - int get_mesh_index ( void ) const { return _mesh_index; } - - void get_mesh_size ( Point & mesh_size ) const - { - Mesh::get_delta_m ( mesh_size , - _initial_mesh_size , - _mesh_update_basis , - _initial_mesh_index , - _mesh_index ); - } - virtual bool eval_x ( Eval_Point & x , const Double & h_max , bool & count_eval ) const; @@ -82,7 +64,7 @@ void My_Evaluator::update_iteration ( success_type success , const Pareto_Front & pareto_front , bool & stop ) { - _mesh_index = Mesh::get_mesh_index(); + if ( success == UNSUCCESSFUL ) stop = true; } @@ -112,7 +94,7 @@ int main ( int argc , char ** argv ) bbot[2] = EB; p.set_BB_OUTPUT_TYPE ( bbot ); - // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); + p.set_DISPLAY_DEGREE ( 2 ); p.set_DISPLAY_STATS ( "bbe ( sol ) obj" ); @@ -127,9 +109,13 @@ int main ( int argc , char ** argv ) p.set_MAX_BB_EVAL (100); // the algorithm terminates after // 100 black-box evaluations + + // parameters validation: p.check(); + + OrthogonalMesh * oMesh=p.get_signature()->get_mesh(); // custom evaluator creation: My_Evaluator ev ( p ); @@ -140,8 +126,10 @@ int main ( int argc , char ** argv ) // algorithm creation: Mads mads ( p , &ev ); + // successive runs: - for ( int i = 0 ; i < 5 ; ++i ) { + for ( int i = 0 ; i < 5 ; ++i ) + { out << endl << open_block ( "MADS run #" + NOMAD::itos(i) ); @@ -161,18 +149,21 @@ int main ( int argc , char ** argv ) else p.set_LH_SEARCH(0,0); - - // initial mesh: - p.set_INITIAL_MESH_INDEX ( ev.get_mesh_index() ); - Point initial_mesh_size; - ev.get_mesh_size ( initial_mesh_size ); - p.set_INITIAL_MESH_SIZE ( initial_mesh_size ); - - // parameters validation: + // Update the mesh for an unsuccessful iteration and put current + // mesh and poll sizes as initial mesh and poll sizes for the next start. + oMesh->update(UNSUCCESSFUL); + Point delta_0, Delta_0; + oMesh->get_delta(delta_0); + oMesh->set_delta_0(delta_0); + oMesh->get_Delta(Delta_0); + oMesh->set_Delta_0(Delta_0); + + // parameters validation: p.check(); // reset the Mads object: mads.reset ( true , true ); + } // the run: diff --git a/examples/advanced/restart/runExample.log b/examples/advanced/restart/runExample.log index 08cd5d62a021f54e65508770f9a9dc2854837273..e0e3dcf66b2bfe235fa2fb5acb905702e32b6daf 100644 --- a/examples/advanced/restart/runExample.log +++ b/examples/advanced/restart/runExample.log @@ -5,15 +5,15 @@ MADS run { BBE ( SOL ) OBJ - 2 ( 1.1000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 275.2281000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 - 9 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 + 2 ( 0.0000000000 0.5366563146 0.5813776741 -0.2683281573 0.2683281573 ) 288.7937255854 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 0.0000000000 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 1.0733126292 + 9 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 1.0733126292 } end of run (terminated by the user inside Evaluator::update_iteration()) blackbox evaluations : 9 -best feasible solution : ( 4.4 0 0 0 0 ) h=0 f=0 +best feasible solution : ( 0 2.146625258 2.325510697 -1.073312629 1.073312629 ) h=0 f=1.073312629 } MADS run #1 { @@ -22,13 +22,18 @@ MADS run { BBE ( SOL ) OBJ - 9 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 - 15 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 + 9 ( -0.4919349550 2.6832815730 2.9068883707 -0.5366563146 1.0733126292 ) 1.0733126292 + 11 ( -0.4919349550 3.0857738089 2.9068883707 -0.5366563146 0.8720665112 ) 0.8720665112 + 12 ( -0.4919349550 4.2932505168 2.9068883707 -0.5366563146 0.2683281573 ) 0.2683281573 + 20 ( 0.0000000000 3.6224301235 2.6161995337 -0.0670820393 -1.0733126292 ) -1.0733126292 + 27 ( -0.2459674775 4.1590864381 2.9068883707 -0.6037383539 -1.4087228258 ) -1.4087228258 + 29 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 + 36 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 } end of run (terminated by the user inside Evaluator::update_iteration()) -blackbox evaluations : 15 -best feasible solution : ( 4.4 0 0 0 0 ) h=0 f=0 +blackbox evaluations : 36 +best feasible solution : ( 2.459674775 1.475804865 0.7267220927 -0.6708203932 -3.421184006 ) h=0 f=-3.421184006 } MADS run #2 { @@ -37,14 +42,13 @@ MADS run { BBE ( SOL ) OBJ - 15 ( 4.4000000000 -0.6000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 - 16 ( 4.5375000000 -0.1500000000 0.4875000000 0.7500000000 -1.5000000000 ) -1.5000000000 - 23 ( 4.5375000000 -0.1500000000 0.4875000000 0.7500000000 -1.5000000000 ) -1.5000000000 + 36 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 + 42 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 } end of run (terminated by the user inside Evaluator::update_iteration()) -blackbox evaluations : 23 -best feasible solution : ( 4.5375 -0.15 0.4875 0.75 -1.5 ) h=0 f=-1.5 +blackbox evaluations : 42 +best feasible solution : ( 2.459674775 1.475804865 0.7267220927 -0.6708203932 -3.421184006 ) h=0 f=-3.421184006 } MADS run #3 { @@ -53,14 +57,13 @@ MADS run { BBE ( SOL ) OBJ - 23 ( 4.5375000000 -0.7500000000 0.4875000000 0.7500000000 -1.5000000000 ) -1.5000000000 - 30 ( 4.1250000000 -0.9750000000 0.3250000000 0.7500000000 -2.2500000000 ) -2.2500000000 - 38 ( 4.1250000000 -0.9750000000 0.3250000000 0.7500000000 -2.2500000000 ) -2.2500000000 + 42 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 + 48 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 } end of run (terminated by the user inside Evaluator::update_iteration()) -blackbox evaluations : 38 -best feasible solution : ( 4.125 -0.975 0.325 0.75 -2.25 ) h=0 f=-2.25 +blackbox evaluations : 48 +best feasible solution : ( 2.459674775 1.475804865 0.7267220927 -0.6708203932 -3.421184006 ) h=0 f=-3.421184006 } MADS run #4 { @@ -69,11 +72,13 @@ MADS run { BBE ( SOL ) OBJ - 38 ( 3.5750000000 -0.9750000000 0.3250000000 0.7500000000 -2.2500000000 ) -2.2500000000 - 44 ( 3.5750000000 -0.9750000000 0.3250000000 0.7500000000 -2.2500000000 ) -2.2500000000 + 48 ( 2.4596747752 1.4758048651 0.7267220927 -0.6708203932 -3.4211840056 ) -3.4211840056 + 52 ( 2.4750477426 1.4674196102 0.8902345635 0.5282710597 -3.4505323978 ) -3.4505323978 + 54 ( 0.9915563938 0.9978453350 1.0174109298 1.0230010997 -3.9997665948 ) -3.9997665948 + 61 ( 0.9915563938 0.9978453350 1.0174109298 1.0230010997 -3.9997665948 ) -3.9997665948 } end of run (terminated by the user inside Evaluator::update_iteration()) -blackbox evaluations : 44 -best feasible solution : ( 3.575 -0.975 0.325 0.75 -2.25 ) h=0 f=-2.25 +blackbox evaluations : 61 +best feasible solution : ( 0.9915563938 0.997845335 1.01741093 1.0230011 -3.999766595 ) h=0 f=-3.999766595 } diff --git a/examples/advanced/user_search/runExample.log b/examples/advanced/user_search/runExample.log index 78b04cf5f7430fcf1ee3542a475d64d40b5191d0..60c785b24c7db1d2a4a8d55e442ca7d9b2a43da1 100644 --- a/examples/advanced/user_search/runExample.log +++ b/examples/advanced/user_search/runExample.log @@ -6,10 +6,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { + + point #1 ( 0.132741232 ) + mesh indices: ( 0 ) + + } - point #1 ( 0.132741232 ) + evaluation 1/1 { + point #1 user search dominating point #1 { x = ( 0.132741232 ) @@ -33,10 +39,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { - point #2 ( 0.061929856 ) + point #2 ( 0.061929856 ) + mesh indices: ( 0 ) + } + + evaluation 1/1 { + + point #2 user search dominating point #2 { x = ( 0.061929856 ) @@ -60,10 +72,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { - point #3 ( 0.052807552 ) + point #3 ( 0.052807552 ) + mesh indices: ( 0 ) + } + + evaluation 1/1 { + + point #3 user search dominating point #3 { x = ( 0.052807552 ) @@ -87,10 +105,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { - point #4 ( 0.003343488002 ) + point #4 ( 0.003343488002 ) + mesh indices: ( 0 ) + } + + evaluation 1/1 { + + point #4 user search dominating point #4 { x = ( 0.003343488002 ) @@ -114,10 +138,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { - point #5 ( 0.003046400592 ) + point #5 ( 0.003046400592 ) + mesh indices: ( 0 ) + } + + evaluation 1/1 { + + point #5 user search dominating point #5 { x = ( 0.003046400592 ) @@ -141,10 +171,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { - point #6 ( 0.002265794838 ) + point #6 ( 0.002265794838 ) + mesh indices: ( 0 ) + } + + evaluation 1/1 { + + point #6 user search dominating point #6 { x = ( 0.002265794838 ) @@ -168,10 +204,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { + + point #7 ( 0.001481318181 ) + mesh indices: ( 0 ) + + } - point #7 ( 0.001481318181 ) + evaluation 1/1 { + point #7 user search dominating point #7 { x = ( 0.001481318181 ) @@ -195,10 +237,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { + + point #8 ( 0.001371090082 ) + mesh indices: ( 0 ) - point #8 ( 0.001371090082 ) + } + + evaluation 1/1 { + point #8 user search dominating point #8 { x = ( 0.001371090082 ) @@ -222,10 +270,16 @@ MADS search { list of points evaluation (user search) { - evaluation 1/1 { + submitted evaluation 1/1 { + + point #9 ( 0.0008957599348 ) + mesh indices: ( 0 ) - point #9 ( 0.0008957599348 ) + } + + evaluation 1/1 { + point #9 user search dominating point #9 { x = ( 0.0008957599348 ) diff --git a/examples/advanced/user_search/user_search.cpp b/examples/advanced/user_search/user_search.cpp index 14d54e945a4d0fffab7b88bc51db0dd7f28c4388..8c4870c60930e59b2ead8e2e20a805ca1adc2908 100755 --- a/examples/advanced/user_search/user_search.cpp +++ b/examples/advanced/user_search/user_search.cpp @@ -100,6 +100,29 @@ void My_Search::search ( Mads & mads , tk->set_signature ( signature ); (*tk)[0] = static_cast<int>(ceil(1.0/xk)) * xk - 1.0; + + + // Projection maybe needed + // const NOMAD::Display & out= _p.out(); + // NOMAD::dd_type display_degree = out.get_search_dd(); + // if ( display_degree == NOMAD::FULL_DISPLAY ) + // { + // out << "candidate"; + // out << " (before projection)"; + // out << ": ( " << *tk << " )" << std::endl; + // } + // + // // Project to the mesh + // tk->project_to_mesh(*feas_inc,signature->get_mesh()->get_delta(),signature->get_lb(),signature->get_ub() ); + // + // if ( display_degree == NOMAD::FULL_DISPLAY ) + // { + // out << "candidate"; + // out << " (after projection)"; + // out << ": ( " << *tk << " )" << std::endl; + // } + + // Evaluator_Control: Evaluator_Control & ev_control = mads.get_evaluator_control(); diff --git a/examples/basic/batch/bi_obj/param.txt b/examples/basic/batch/bi_obj/param.txt index af13c770c0c04ee27bd340967d2189082bff7e55..cc0d85408e063e969ef884ce700498f06815aa21 100644 --- a/examples/basic/batch/bi_obj/param.txt +++ b/examples/basic/batch/bi_obj/param.txt @@ -17,7 +17,7 @@ upper_bound * 1.0 MULTI_OVERALL_BB_EVAL 500 # ADD_SEED_TO_FILE_NAMES no -# STATS_FILE front.txt OBJ +STATS_FILE front.txt OBJ # HISTORY_FILE history.txt DISPLAY_STATS BBE ( SOL ) OBJ diff --git a/examples/basic/batch/bi_obj/runExample.log b/examples/basic/batch/bi_obj/runExample.log index c88b554451ae29e781f2ae4c7663c7df2f0f0139..76994f3e581a8a8d5f2f03845cba2e9a79c68144 100644 --- a/examples/basic/batch/bi_obj/runExample.log +++ b/examples/basic/batch/bi_obj/runExample.log @@ -1,7 +1,7 @@ -NOMAD - version 3.6.1 - www.gerad.ca/nomad +NOMAD - version 3.7.2 - www.gerad.ca/nomad -Copyright (C) 2001-2013 { +Copyright (C) 2001-2015 { Mark A. Abramson - The Boeing Company Charles Audet - Ecole Polytechnique de Montreal Gilles Couture - Ecole Polytechnique de Montreal @@ -21,21 +21,21 @@ Please report bugs to nomad@gerad.ca multi-MADS run { - MADS run 1 ...... OK [bb eval= 64] [overall bb eval= 64] [# dominant pts= 5] [# new pts= 5] [f1=0 f2=8.036326991] - MADS run 2 ...... OK [bb eval= 32] [overall bb eval= 96] [# dominant pts= 12] [# new pts= 7] [f1=0.5676487984 f2=0.1148721239] - MADS run 3 ...... OK [bb eval= 32] [overall bb eval= 128] [# dominant pts= 15] [# new pts= 3] [f1=0 f2=1] - MADS run 4 ...... OK [bb eval= 32] [overall bb eval= 160] [# dominant pts= 25] [# new pts= 10] [f1=0.08125 f2=0.9210041574] - MADS run 5 ...... OK [bb eval= 32] [overall bb eval= 192] [# dominant pts= 37] [# new pts= 12] [f1=0.5164769234 f2=0.5254339031] - MADS run 6 ...... OK [bb eval= 32] [overall bb eval= 224] [# dominant pts= 51] [# new pts= 14] [f1=0.4954991402 f2=0.8104114832] - MADS run 7 ...... OK [bb eval= 32] [overall bb eval= 256] [# dominant pts= 58] [# new pts= 7] [f1=0.4887608589 f2=0.8973446571] - MADS run 8 ...... OK [bb eval= 32] [overall bb eval= 288] [# dominant pts= 65] [# new pts= 7] [f1=0.4876866402 f2=0.9106878852] - MADS run 9 ...... OK [bb eval= 32] [overall bb eval= 320] [# dominant pts= 71] [# new pts= 6] [f1=0.08327636719 f2=0.9208860571] - MADS run 10 ...... OK [bb eval= 32] [overall bb eval= 352] [# dominant pts= 77] [# new pts= 6] [f1=0.08300170898 f2=0.9208857342] - MADS run 11 ...... OK [bb eval= 32] [overall bb eval= 384] [# dominant pts= 83] [# new pts= 6] [f1=0.08300170898 f2=0.9208857342] - MADS run 12 ...... OK [bb eval= 32] [overall bb eval= 416] [# dominant pts= 93] [# new pts= 10] [f1=0.4872792305 f2=0.9157055455] - MADS run 13 ...... OK [bb eval= 32] [overall bb eval= 448] [# dominant pts= 100] [# new pts= 7] [f1=0.487021357 f2=0.9188689839] - MADS run 14 ...... OK [bb eval= 32] [overall bb eval= 480] [# dominant pts= 108] [# new pts= 8] [f1=0.4869359077 f2=0.9202170697] - MADS run 15 ...... OK [bb eval= 20] [overall bb eval= 500] [# dominant pts= 112] [# new pts= 4] [f1=0.08319091797 f2=0.9208854025] + MADS run 1 ...... OK [bb eval= 64] [overall bb eval= 64] [# dominant pts= 10] [# new pts= 10] [f1=0 f2=6.231313115] + MADS run 2 ...... OK [bb eval= 32] [overall bb eval= 96] [# dominant pts= 15] [# new pts= 5] [f1=0.8169729819 f2=-0.479260869] + MADS run 3 ...... OK [bb eval= 32] [overall bb eval= 128] [# dominant pts= 14] [# new pts= -1] [f1=0 f2=1] + MADS run 4 ...... OK [bb eval= 32] [overall bb eval= 160] [# dominant pts= 25] [# new pts= 11] [f1=0.5612660076 f2=0.1239843648] + MADS run 5 ...... OK [bb eval= 32] [overall bb eval= 192] [# dominant pts= 33] [# new pts= 8] [f1=0.3137786342 f2=0.5879263396] + MADS run 6 ...... OK [bb eval= 32] [overall bb eval= 224] [# dominant pts= 47] [# new pts= 14] [f1=0.7805127885 f2=-0.1507861609] + MADS run 7 ...... OK [bb eval= 32] [overall bb eval= 256] [# dominant pts= 54] [# new pts= 7] [f1=0.5299157655 f2=0.357255587] + MADS run 8 ...... OK [bb eval= 32] [overall bb eval= 288] [# dominant pts= 66] [# new pts= 12] [f1=0.07954951288 f2=0.9213144638] + MADS run 9 ...... OK [bb eval= 32] [overall bb eval= 320] [# dominant pts= 76] [# new pts= 10] [f1=0.2748325185 f2=0.7638619206] + MADS run 10 ...... OK [bb eval= 32] [overall bb eval= 352] [# dominant pts= 85] [# new pts= 9] [f1=0.5181766881 f2=0.5029223883] + MADS run 11 ...... OK [bb eval= 32] [overall bb eval= 384] [# dominant pts= 89] [# new pts= 4] [f1=0.7680831771 f2=0.07286356753] + MADS run 12 ...... OK [bb eval= 32] [overall bb eval= 416] [# dominant pts= 99] [# new pts= 10] [f1=0.5151038119 f2=0.5437967797] + MADS run 13 ...... OK [bb eval= 32] [overall bb eval= 448] [# dominant pts= 111] [# new pts= 12] [f1=0.2592955042 f2=0.8727383732] + MADS run 14 ...... OK [bb eval= 32] [overall bb eval= 480] [# dominant pts= 117] [# new pts= 6] [f1=0.5684216658 f2=0.1147587127] + MADS run 15 ...... OK [bb eval= 20] [overall bb eval= 500] [# dominant pts= 120] [# new pts= 3] [f1=0.5684216658 f2=0.1147587127] } end of run (max number of bb evaluations) @@ -46,117 +46,125 @@ number of MADS runs : 15 Pareto front { BBE ( 0.0000000000 0.0000000000 ) 0.0000000000 1.0000000000 - BBE ( 0.0000962840 0.0000000000 ) 0.0000962840 0.9999997577 - BBE ( 0.0003906250 0.0000000000 ) 0.0003906250 0.9999960125 - BBE ( 0.0031250000 0.0000000000 ) 0.0031250000 0.9997450497 - BBE ( 0.0046875000 0.0000000000 ) 0.0046875000 0.9994270708 - BBE ( 0.0250000000 0.0000000000 ) 0.0250000000 0.9846803687 - BBE ( 0.0500000000 0.0000000000 ) 0.0500000000 0.9499471742 - BBE ( 0.0546875000 0.0000000000 ) 0.0546875000 0.9433725823 - BBE ( 0.0580017090 0.0000000000 ) 0.0580017090 0.9390043666 - BBE ( 0.0582763672 0.0000000000 ) 0.0582763672 0.9386555226 - BBE ( 0.0593750000 0.0000000000 ) 0.0593750000 0.9372826427 - BBE ( 0.0625000000 0.0000000000 ) 0.0625000000 0.9335937500 - BBE ( 0.0687500000 0.0000000000 ) 0.0687500000 0.9273698641 - BBE ( 0.0705017090 0.0000000000 ) 0.0705017090 0.9259486581 - BBE ( 0.0707763672 0.0000000000 ) 0.0707763672 0.9257399750 - BBE ( 0.0718750000 0.0000000000 ) 0.0718750000 0.9249448963 - BBE ( 0.0734375000 0.0000000000 ) 0.0734375000 0.9239266272 - BBE ( 0.0750000000 0.0000000000 ) 0.0750000000 0.9230457613 - BBE ( 0.0765625000 0.0000000000 ) 0.0765625000 0.9223079094 - BBE ( 0.0767517090 0.0000000000 ) 0.0767517090 0.9222285264 - BBE ( 0.0770263672 0.0000000000 ) 0.0770263672 0.9221171830 - BBE ( 0.0781250000 0.0000000000 ) 0.0781250000 0.9217183959 - BBE ( 0.0796875000 0.0000000000 ) 0.0796875000 0.9212822432 - BBE ( 0.0798767090 0.0000000000 ) 0.0798767090 0.9212400670 - BBE ( 0.0799804688 0.0000000000 ) 0.0799804688 0.9212179253 - BBE ( 0.0800781250 0.0000000000 ) 0.0800781250 0.9211977263 - BBE ( 0.0801513672 0.0000000000 ) 0.0801513672 0.9211829851 - BBE ( 0.0812500000 0.0000000000 ) 0.0812500000 0.9210041574 - BBE ( 0.0817016602 0.0000000000 ) 0.0817016602 0.9209538533 - BBE ( 0.0818115234 0.0000000000 ) 0.0818115234 0.9209436812 - BBE ( 0.0821777344 0.0000000000 ) 0.0821777344 0.9209156366 - BBE ( 0.0825134277 0.0000000000 ) 0.0825134277 0.9208978855 - BBE ( 0.0825927734 0.0000000000 ) 0.0825927734 0.9208948063 - BBE ( 0.0827270508 0.0000000000 ) 0.0827270508 0.9208905705 - BBE ( 0.0828674316 0.0000000000 ) 0.0828674316 0.9208874553 - BBE ( 0.0830017090 0.0000000000 ) 0.0830017090 0.9208857342 - BBE ( 0.0830135345 0.0000000000 ) 0.0830135345 0.9208856417 - BBE ( 0.0830490112 0.0000000000 ) 0.0830490112 0.9208854215 - BBE ( 0.0831909180 0.0000000000 ) 0.0831909180 0.9208854025 - BBE ( 0.4868870796 0.0000000000 ) 0.4868870796 0.9205123238 - BBE ( 0.4868992866 0.0000061035 ) 0.4868992866 0.9204385441 - BBE ( 0.4869359077 0.0000244141 ) 0.4869359077 0.9202170697 - BBE ( 0.4870213570 0.0000000000 ) 0.4870213570 0.9188689839 - BBE ( 0.4870335640 0.0000061035 ) 0.4870335640 0.9187949686 - BBE ( 0.4871007027 0.0000000000 ) 0.4871007027 0.9178966625 - BBE ( 0.4871129097 0.0000000000 ) 0.4871129097 0.9177469920 - BBE ( 0.4871617378 0.0000000000 ) 0.4871617378 0.9171480902 - BBE ( 0.4872052254 0.0000177383 ) 0.4872052254 0.9168338789 - BBE ( 0.4872288765 0.0000000000 ) 0.4872288765 0.9163240271 - BBE ( 0.4872777046 0.0000000000 ) 0.4872777046 0.9157242928 - BBE ( 0.4872792305 0.0000000000 ) 0.4872792305 0.9157055455 - BBE ( 0.4872960152 0.0000000000 ) 0.4872960152 0.9154993024 - BBE ( 0.4873021187 0.0000030518 ) 0.4873021187 0.9154620588 - BBE ( 0.4873078407 0.0000000000 ) 0.4873078407 0.9153539700 - BBE ( 0.4873631538 0.0000000000 ) 0.4873631538 0.9146739180 - BBE ( 0.4874119820 0.0000000000 ) 0.4874119820 0.9140732253 - BBE ( 0.4876378120 0.0000000000 ) 0.4876378120 0.9112905197 - BBE ( 0.4876866402 0.0000000000 ) 0.4876866402 0.9106878852 - BBE ( 0.4880589546 0.0003417969 ) 0.4880589546 0.9103109499 - BBE ( 0.4880772652 0.0000000000 ) 0.4880772652 0.9058545422 - BBE ( 0.4884251655 0.0000000000 ) 0.4884251655 0.9015317160 - BBE ( 0.4887608589 0.0000000000 ) 0.4887608589 0.8973446571 - BBE ( 0.4888585152 0.0000000000 ) 0.4888585152 0.8961237074 - BBE ( 0.4892491402 0.0000000000 ) 0.4892491402 0.8912270369 - BBE ( 0.4892796577 0.0000000000 ) 0.4892796577 0.8908436249 - BBE ( 0.4895237984 0.0000000000 ) 0.4895237984 0.8877718960 - BBE ( 0.4898655952 0.0000000000 ) 0.4898655952 0.8834583797 - BBE ( 0.4899144234 0.0000000000 ) 0.4899144234 0.8828409301 - BBE ( 0.4900120796 0.0000000000 ) 0.4900120796 0.8816051142 - BBE ( 0.4901463570 0.0000000000 ) 0.4901463570 0.8799038821 - BBE ( 0.4904210152 0.0000000000 ) 0.4904210152 0.8764169969 - BBE ( 0.4908116402 0.0000000000 ) 0.4908116402 0.8714417071 - BBE ( 0.4910862984 0.0000000000 ) 0.4910862984 0.8679322951 - BBE ( 0.4915745796 0.0000000000 ) 0.4915745796 0.8616710988 - BBE ( 0.4917088570 0.0000000000 ) 0.4917088570 0.8599443688 - BBE ( 0.4919835152 0.0000000000 ) 0.4919835152 0.8564059578 - BBE ( 0.4926487984 0.0000000000 ) 0.4926487984 0.8477999690 - BBE ( 0.4927464546 0.0000000000 ) 0.4927464546 0.8465326082 - BBE ( 0.4942112984 0.0000000000 ) 0.4942112984 0.8274026124 - BBE ( 0.4946751655 0.0000000000 ) 0.4946751655 0.8213002814 - BBE ( 0.4951146187 0.0002746582 ) 0.4951146187 0.8189185849 - BBE ( 0.4954991402 0.0000000000 ) 0.4954991402 0.8104114832 - BBE ( 0.4957737984 0.0000000000 ) 0.4957737984 0.8067685071 - BBE ( 0.4961155952 0.0000000000 ) 0.4961155952 0.8022260697 - BBE ( 0.4961644234 0.0000000000 ) 0.4961644234 0.8015763555 - BBE ( 0.4969456734 0.0003417969 ) 0.4969456734 0.7954140614 - BBE ( 0.4988987984 0.0000000000 ) 0.4988987984 0.7649058572 - BBE ( 0.5001866402 0.0000000000 ) 0.5001866402 0.7474670688 - BBE ( 0.5004612984 0.0000000000 ) 0.5004612984 0.7437364245 - BBE ( 0.5035862984 0.0000000000 ) 0.5035862984 0.7010722736 - BBE ( 0.5055394234 0.0000000000 ) 0.5055394234 0.6742753824 - BBE ( 0.5098362984 0.0000000000 ) 0.5098362984 0.6153085893 - BBE ( 0.5118870796 0.0000000000 ) 0.5118870796 0.5873076456 - BBE ( 0.5120213570 0.0000000000 ) 0.5120213570 0.5854800910 - BBE ( 0.5122960152 0.0000000000 ) 0.5122960152 0.5817445301 - BBE ( 0.5129612984 0.0000000000 ) 0.5129612984 0.5727116847 - BBE ( 0.5133519234 0.0000000000 ) 0.5133519234 0.5674189894 - BBE ( 0.5145237984 0.0000000000 ) 0.5145237984 0.5515953642 - BBE ( 0.5160862984 0.0000000000 ) 0.5160862984 0.5306427628 - BBE ( 0.5164769234 0.0000000000 ) 0.5164769234 0.5254339031 - BBE ( 0.5168675484 0.0000000000 ) 0.5168675484 0.5202377465 - BBE ( 0.5176487984 0.0000000000 ) 0.5176487984 0.5098855127 - BBE ( 0.5207737984 0.0000000000 ) 0.5207737984 0.4690828690 - BBE ( 0.5289769234 0.0000000000 ) 0.5289769234 0.3681074167 - BBE ( 0.5410862984 0.0000000000 ) 0.5410862984 0.2426270547 - BBE ( 0.5457737984 0.0000000000 ) 0.5457737984 0.2038744975 - BBE ( 0.5535862984 0.0000000000 ) 0.5535862984 0.1537894775 - BBE ( 0.5551487984 0.0000000000 ) 0.5551487984 0.1461090174 - BBE ( 0.5582737984 0.0000000000 ) 0.5582737984 0.1332027875 - BBE ( 0.5645237984 0.0000000000 ) 0.5645237984 0.1175191667 - BBE ( 0.5660862984 0.0000000000 ) 0.5660862984 0.1157579047 - BBE ( 0.5676487984 0.0000000000 ) 0.5676487984 0.1148721239 + BBE ( 0.0027621359 0.0000000000 ) 0.0027621359 0.9998007770 + BBE ( 0.0088388348 0.0000000000 ) 0.0088388348 0.9979744889 + BBE ( 0.0132582521 0.0000000000 ) 0.0132582521 0.9954876562 + BBE ( 0.0353553391 0.0000000000 ) 0.0353553391 0.9713080680 + BBE ( 0.0441941738 0.0000000000 ) 0.0441941738 0.9584480584 + BBE ( 0.0574524260 0.0000000000 ) 0.0574524260 0.9397084727 + BBE ( 0.0618718434 0.0000000000 ) 0.0618718434 0.9343077419 + BBE ( 0.0707106781 0.0000000000 ) 0.0707106781 0.9257895286 + BBE ( 0.0729203868 0.0000000000 ) 0.0729203868 0.9242486972 + BBE ( 0.0734728140 0.0000000000 ) 0.0734728140 0.9239051795 + BBE ( 0.0765111634 0.0000000000 ) 0.0765111634 0.9223298234 + BBE ( 0.0783065517 0.0000000000 ) 0.0783065517 0.9216597507 + BBE ( 0.0795495129 0.0000000000 ) 0.0795495129 0.9213144638 + BBE ( 0.0801709935 0.0000000000 ) 0.0801709935 0.9211790945 + BBE ( 0.0804989971 0.0000000000 ) 0.0804989971 0.9211178038 + BBE ( 0.0814830080 0.0000000000 ) 0.0814830080 0.9209765043 + BBE ( 0.0839689303 0.0000000000 ) 0.0839689303 0.9209099136 + BBE ( 0.2546689267 0.0000000000 ) 0.2546689267 0.9053286734 + BBE ( 0.2554285140 0.0000000000 ) 0.2554285140 0.9000152969 + BBE ( 0.2559809412 0.0000000000 ) 0.2559809412 0.8961400979 + BBE ( 0.2592955042 0.0000000000 ) 0.2592955042 0.8727383732 + BBE ( 0.2601241450 0.0002762136 ) 0.2601241450 0.8698079048 + BBE ( 0.2624029071 0.0011048543 ) 0.2624029071 0.8624679573 + BBE ( 0.2633006012 0.0008286408 ) 0.2633006012 0.8531427520 + BBE ( 0.2634387080 0.0001898968 ) 0.2634387080 0.8453357823 + BBE ( 0.2635077614 0.0000000000 ) 0.2635077614 0.8428146572 + BBE ( 0.2643364022 0.0000000000 ) 0.2643364022 0.8369299127 + BBE ( 0.2673747516 0.0000000000 ) 0.2673747516 0.8154302217 + BBE ( 0.2679271788 0.0000000000 ) 0.2679271788 0.8115410603 + BBE ( 0.2695844603 0.0000000000 ) 0.2695844603 0.7999251464 + BBE ( 0.2740038777 0.0022097087 ) 0.2740038777 0.7931862207 + BBE ( 0.2748325185 0.0000000000 ) 0.2748325185 0.7638619206 + BBE ( 0.2762135864 0.0002762136 ) 0.2762135864 0.7575848978 + BBE ( 0.2773184407 0.0000000000 ) 0.2773184407 0.7473019205 + BBE ( 0.2828427125 0.0000000000 ) 0.2828427125 0.7121565043 + BBE ( 0.2872621299 0.0000000000 ) 0.2872621299 0.6860941024 + BBE ( 0.2900242657 0.0000000000 ) 0.2900242657 0.6709156096 + BBE ( 0.2961009646 0.0000000000 ) 0.2961009646 0.6410185691 + BBE ( 0.3005203820 0.0000000000 ) 0.3005203820 0.6226855524 + BBE ( 0.3016252363 0.0000000000 ) 0.3016252363 0.6185926969 + BBE ( 0.3088067896 0.0000000000 ) 0.3088067896 0.5971609072 + BBE ( 0.3093592168 0.0000000000 ) 0.3093592168 0.5959009619 + BBE ( 0.3137786342 0.0000000000 ) 0.3137786342 0.5879263396 + BBE ( 0.3165407700 0.0000000000 ) 0.3165407700 0.5848920973 + BBE ( 0.3167479302 0.0000000000 ) 0.3167479302 0.5847262751 + BBE ( 0.3176456244 0.0000000000 ) 0.3176456244 0.5841081818 + BBE ( 0.3181980515 0.0000000000 ) 0.3181980515 0.5838092475 + BBE ( 0.3226174689 0.0000000000 ) 0.3226174689 0.5836743517 + BBE ( 0.5127214698 0.0000000000 ) 0.5127214698 0.5759653136 + BBE ( 0.5137572707 0.0002762136 ) 0.5137572707 0.5654252540 + BBE ( 0.5140334843 0.0000000000 ) 0.5140334843 0.5582055541 + BBE ( 0.5150347585 0.0000172633 ) 0.5150347585 0.5449424207 + BBE ( 0.5151038119 0.0000000000 ) 0.5151038119 0.5437967797 + BBE ( 0.5153886572 0.0000000000 ) 0.5153886572 0.5399756398 + BBE ( 0.5165194066 0.0000000000 ) 0.5165194066 0.5248681601 + BBE ( 0.5169337269 0.0000000000 ) 0.5169337269 0.5193587219 + BBE ( 0.5173135206 0.0000000000 ) 0.5173135206 0.5143215129 + BBE ( 0.5179004745 0.0002762136 ) 0.5179004745 0.5100634344 + BBE ( 0.5181076347 0.0000690534 ) 0.5181076347 0.5047074913 + BBE ( 0.5181766881 0.0000000000 ) 0.5181766881 0.5029223883 + BBE ( 0.5183147949 0.0000000000 ) 0.5183147949 0.5011051160 + BBE ( 0.5192124890 0.0000000000 ) 0.5192124890 0.4893395607 + BBE ( 0.5203173434 0.0002762136 ) 0.5203173434 0.4784843660 + BBE ( 0.5211459841 0.0010358009 ) 0.5211459841 0.4774378717 + BBE ( 0.5214912511 0.0000000000 ) 0.5214912511 0.4598694955 + BBE ( 0.5228723191 0.0000000000 ) 0.5228723191 0.4423168011 + BBE ( 0.5261868821 0.0000000000 ) 0.5261868821 0.4012836645 + BBE ( 0.5272917364 0.0000000000 ) 0.5272917364 0.3879862090 + BBE ( 0.5292252315 0.0000000000 ) 0.5292252315 0.3652213546 + BBE ( 0.5299157655 0.0000000000 ) 0.5299157655 0.3572555870 + BBE ( 0.5303300859 0.0000000000 ) 0.5303300859 0.3525194343 + BBE ( 0.5317111538 0.0000000000 ) 0.5317111538 0.3369744453 + BBE ( 0.5350257169 0.0000000000 ) 0.5350257169 0.3012827434 + BBE ( 0.5358543576 0.0000000000 ) 0.5358543576 0.2927387374 + BBE ( 0.5361305712 0.0000000000 ) 0.5361305712 0.2899259708 + BBE ( 0.5391689207 0.0000000000 ) 0.5391689207 0.2601947270 + BBE ( 0.5480077554 0.0000000000 ) 0.5480077554 0.1876299330 + BBE ( 0.5513223185 0.0000000000 ) 0.5513223185 0.1663336683 + BBE ( 0.5535320271 0.0000000000 ) 0.5535320271 0.1540707094 + BBE ( 0.5557417358 0.0000000000 ) 0.5557417358 0.1434067848 + BBE ( 0.5568465902 0.0000000000 ) 0.5568465902 0.1386867395 + BBE ( 0.5590562989 0.0000000000 ) 0.5590562989 0.1304923502 + BBE ( 0.5604373668 0.0000000000 ) 0.5604373668 0.1262254672 + BBE ( 0.5612660076 0.0000000000 ) 0.5612660076 0.1239843648 + BBE ( 0.5620687533 0.0000000000 ) 0.5620687533 0.1220429764 + BBE ( 0.5640022484 0.0000000000 ) 0.5640022484 0.1183011565 + BBE ( 0.5645805706 0.0000000000 ) 0.5645805706 0.1174398964 + BBE ( 0.5652020512 0.0000000000 ) 0.5652020512 0.1166473780 + BBE ( 0.5654092114 0.0000000000 ) 0.5654092114 0.1164138826 + BBE ( 0.5656854249 0.0000000000 ) 0.5656854249 0.1161264470 + BBE ( 0.5659616385 0.0000000000 ) 0.5659616385 0.1158663392 + BBE ( 0.5666866992 0.0000000000 ) 0.5666866992 0.1153137493 + BBE ( 0.5669024911 0.0000000000 ) 0.5669024911 0.1151857400 + BBE ( 0.5674462866 0.0000000000 ) 0.5674462866 0.1149374124 + BBE ( 0.5684216658 0.0000000000 ) 0.5684216658 0.1147587127 + BBE ( 0.7661496820 0.0000000000 ) 0.7661496820 0.1105136967 + BBE ( 0.7669783228 0.0000000000 ) 0.7669783228 0.0943075051 + BBE ( 0.7680831771 0.0000000000 ) 0.7680831771 0.0728635675 + BBE ( 0.7691880314 0.0000000000 ) 0.7691880314 0.0516220389 + BBE ( 0.7694642450 0.0000000000 ) 0.7694642450 0.0463451418 + BBE ( 0.7704309926 0.0007941141 ) 0.7704309926 0.0406045540 + BBE ( 0.7705690994 0.0000000000 ) 0.7705690994 0.0253788803 + BBE ( 0.7738836624 0.0000000000 ) 0.7738836624 -0.0360307769 + BBE ( 0.7741598760 0.0000000000 ) 0.7741598760 -0.0410385581 + BBE ( 0.7758171575 0.0000000000 ) 0.7758171575 -0.0706993622 + BBE ( 0.7760933711 0.0000000000 ) 0.7760933711 -0.0755763386 + BBE ( 0.7766457983 0.0000000000 ) 0.7766457983 -0.0852712175 + BBE ( 0.7771982255 0.0000000000 ) 0.7771982255 -0.0948858036 + BBE ( 0.7805127885 0.0000000000 ) 0.7805127885 -0.1507861609 + BBE ( 0.7816176428 0.0004488471 ) 0.7816176428 -0.1614780263 + BBE ( 0.7849322059 0.0000000000 ) 0.7849322059 -0.2200658533 + BBE ( 0.7854846330 0.0000000000 ) 0.7854846330 -0.2282658189 + BBE ( 0.7882467689 0.0000000000 ) 0.7882467689 -0.2676209257 + BBE ( 0.7937710406 0.0000000000 ) 0.7937710406 -0.3375181059 + BBE ( 0.7948758950 0.0000000000 ) 0.7948758950 -0.3499937714 + BBE ( 0.7970856037 0.0000000000 ) 0.7970856037 -0.3733607572 + BBE ( 0.8059244384 0.0000000000 ) 0.8059244384 -0.4444581650 + BBE ( 0.8103438558 0.0000000000 ) 0.8103438558 -0.4658115097 + BBE ( 0.8169729819 0.0000000000 ) 0.8169729819 -0.4792608690 } -number of Pareto points: 112 +number of Pareto points: 120 diff --git a/examples/basic/batch/single_obj/runExample.log b/examples/basic/batch/single_obj/runExample.log index 85fbaec9493fada2649f8d8fb8698c71dd8979d7..129534c62d6d14517472e10b8a68c1e37251e170 100644 --- a/examples/basic/batch/single_obj/runExample.log +++ b/examples/basic/batch/single_obj/runExample.log @@ -1,7 +1,7 @@ -NOMAD - version 3.6.1 - www.gerad.ca/nomad +NOMAD - version 3.7.2 - www.gerad.ca/nomad -Copyright (C) 2001-2013 { +Copyright (C) 2001-2015 { Mark A. Abramson - The Boeing Company Charles Audet - Ecole Polytechnique de Montreal Gilles Couture - Ecole Polytechnique de Montreal @@ -23,15 +23,21 @@ MADS run { BBE ( SOL ) OBJ - 2 ( 1.1000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 275.2281000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 - 11 ( 4.6750000000 0.9000000000 0.9750000000 1.5000000000 -1.5000000000 ) -1.5000000000 - 55 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000 - 100 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000 + 2 ( 0.0000000000 0.5366563146 0.5813776741 -0.2683281573 0.2683281573 ) 288.7926372100 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 0.0000000000 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 1.0733100000 + 10 ( 0.4919349550 2.8174456516 2.1801662781 -0.8720665112 1.0062305899 ) 1.0062300000 + 11 ( 1.9677398202 4.8299068314 1.7441330224 -0.2683281573 0.8049844719 ) 0.8049840000 + 13 ( 0.0000000000 1.6099689438 2.9068883707 -0.8049844719 0.5366563146 ) 0.5366560000 + 17 ( 3.5241951349 1.7067494832 0.5813776741 -0.5366563146 0.2683281573 ) 0.2683280000 + 28 ( 2.0483902697 -2.5865010336 3.4882660449 1.8782971011 0.0000000000 ) 0.0000000000 + 67 ( 2.0483902697 1.7067494832 2.3255106966 -0.5366563146 -2.4149534157 ) -2.4149500000 + 86 ( 3.0322601798 0.6334368540 0.0000000000 2.6832815730 -2.9516097303 ) -2.9516100000 + 96 ( 1.5564553147 1.7067494832 -0.5813776741 1.6099689438 -3.4882660449 ) -3.4882700000 + 100 ( 1.5564553147 1.7067494832 -0.5813776741 1.6099689438 -3.4882660449 ) -3.4882700000 } end of run (max number of blackbox evaluations) blackbox evaluations : 100 -best infeasible solution (min. violation): ( 1.65 1.8 2.6 -1.5 -3 ) h=0.8725 f=-3 -best feasible solution : ( 1.65 1.8 1.95 -1.5 -3 ) h=0 f=-3 +best infeasible solution (min. violation): ( -0.9032194606 -0.4398757752 4.069643719 -0.2683281573 -1.878297101 ) h=0.0114496 f=-1.8783 +best feasible solution : ( 1.556455315 1.706749483 -0.5813776741 1.609968944 -3.488266045 ) h=0 f=-3.48827 diff --git a/examples/basic/batch/single_obj_parallel/bb.cpp b/examples/basic/batch/single_obj_parallel/bb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c3bf75f205e9e512839c9dd7530c9d64a410715 --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/bb.cpp @@ -0,0 +1,31 @@ +#include <cmath> +#include <iostream> +#include <fstream> +#include <cstdlib> +using namespace std; + +int main ( int argc , char ** argv ) { + + double f = 1e20, c1 = 1e20 , c2 = 1e20; + double x[5]; + + if ( argc >= 2 ) { + c1 = 0.0 , c2 = 0.0; + ifstream in ( argv[1] ); + for ( int i = 0 ; i < 5 ; i++ ) { + in >> x[i]; + c1 += pow ( x[i]-1 , 2 ); + c2 += pow ( x[i]+1 , 2 ); + } + f = x[4]; + if ( in.fail() ) + f = c1 = c2 = 1e20; + else { + c1 = c1 - 25; + c2 = 25 - c2; + } + in.close(); + } + cout << f << " " << c1 << " " << c2 << endl; + return 0; +} diff --git a/examples/basic/batch/single_obj_parallel/bb_parallel.cpp b/examples/basic/batch/single_obj_parallel/bb_parallel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c17a350dc66a5e27e49121fe8c6bea0de7a83f9d --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/bb_parallel.cpp @@ -0,0 +1,113 @@ +#include <cmath> +#include <iostream> +#include <fstream> +#include <cstdlib> +#include <vector> +#include <pthread.h> +#include <semaphore.h> + +using namespace std; + +// Number of threads to be used in parallel +#define NUM_THREADS 4 + +static void * eval_x ( void * dummy_eval_arg ) +{ + + double c1 = 0.0 , c2 = 0.0 ,f; + double * x = static_cast<double *>(dummy_eval_arg); + for ( int i = 0 ; i < 5 ; i++) + { + c1 += pow ( x[i]-1 , 2 ); + c2 += pow ( x[i]+1 , 2 ); + } + x[5]= x[4]; + x[6] = c1 - 25; + x[7] = 25 - c2; + + // cout << x[0] << " " << x[1] <<" " << x[2] <<" "<< x[3] <<" "<< x[4] << " " << x[5] << " " << x[6] << " " << x[7] << endl; + + pthread_exit(NULL); + +} + + + +int main ( int argc , char ** argv ) + { + + double f = 1e20, c1 = 1e20 , c2 = 1e20; + std::vector< double * > X; + + if ( argc >= 2 ) + { + + ifstream in ( argv[1] ); + + while( ! in.eof() ) + { + double *x = new double [8]; + for ( int i = 0 ; i < 5 ; i++ ) + in >> x[i]; + + X.push_back(x); + + //char c; + // in >> c; + + // cout << x[0] << " " << x[1] <<endl; + + } + in.close(); + X.pop_back(); + + int nb_pts=X.size(); + + // All threads are created + pthread_t threads[nb_pts]; + + // The semaphore will allow to run NUM_THREADS in parallel + sem_t *mySemaphore; + mySemaphore=sem_open("sem",0,NUM_THREADS); + + // The list of points is evaluated under the control of a semaphore + int i=0; + for (std::vector< double * >::iterator it_x=X.begin(); it_x!=X.end(); ++it_x,++i) + { + // cout << (*it_x)[0] << " " << (*it_x)[1] << " " << (*it_x)[2] << endl; + int rc=pthread_create(&threads[i], NULL, eval_x,(*it_x)); + if (rc) + { + cout << "Error:unable to create thread," << rc << endl; + return false; + } + // wait until value of semaphore is greater than 0 + // decrement the value of semaphore by 1 + sem_wait(mySemaphore); + + } + + int ret; + + // cout << nb_pts << endl; + for (i=0; i<nb_pts; ++i) + { + // Wait for all the threads to finish + ret=pthread_join(threads[i],0); + if (ret!=0) + { + perror("pthread join has failed"); + return false; + } + cout << (X[i])[5] << " " << (X[i])[6] << " " << (X[i])[7] << endl; + delete [](X[i]); + } + + sem_unlink("sem"); + + + } + + return 0; + +} diff --git a/examples/basic/batch/single_obj_parallel/parallel_BBWrapper.pl b/examples/basic/batch/single_obj_parallel/parallel_BBWrapper.pl new file mode 100755 index 0000000000000000000000000000000000000000..1de81320e898b538e21e86b622af308645f0a0d9 --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/parallel_BBWrapper.pl @@ -0,0 +1,117 @@ +#!/usr/bin/perl +# use strict; +use warnings; + +use Data::Dumper; + +use threads; +use threads::shared; +use Thread::Semaphore; + + +# quelques variables partagées +my $BBdotEXE:shared="./bb.exe"; ## The blackbox executable + +my $numberParallelJobs:shared=4; +my $semaphoreBBEval = Thread::Semaphore->new($numberParallelJobs); + + +if ( ! exists $ARGV[0]) { + $nameInputFile = ""; +} else { + $nameInputFile = $ARGV[0]; +} + +sub OneEvalBB($$$$$){ + my $x = shift; + my $index = shift; + my $completedEval = shift; + my $sema_ref = shift; + my $output = shift; + + + + my $input_file_name=""; + #if ($index > 3) { # arbitrarily reject evaluation with index > 3!!!!! THIS IS NOT A GOOF THING TO DO + # $$output="REJECT\n"; + #} else { + + # write single evaluation input file + $input_file_name="x.$$.$index.txt"; + open(SINGLE_INPUT_FILE,"> $input_file_name"); + print SINGLE_INPUT_FILE "$x \n"; + close(SINGLE_INPUT_FILE); + + + # start single evaluation and get output + open(OUTPUT_I,"$BBdotEXE $input_file_name |") ; # or die "Can't run blackbox executable: $!\n"; + $$output=<OUTPUT_I>; + close(OUTPUT_I); + #} + + + $$completedEval++; + + # on a une place de libre. Ne pas oublier de libérer le sémaphore même en cas d'erreur + $$sema_ref->up(); + + if ( -e $input_file_name) { + unlink $input_file_name ; + } + + return; +} + +open(LIST_INPUT_FILE,"$ARGV[0]") or die "Can't open input file: $ARGV[0]\n"; +@X = <LIST_INPUT_FILE>; +my $started = 0; +my $completedBBEval:shared =0; +my @output:shared; + +my @thrList= (); + + + +# démarre tous les jobs +while ( $started < scalar @X ){ + + my $x=$X[$started]; + + $started++; + + # avons nous une place de libre ? + $semaphoreBBEval->down(); + + # si le sémaphore est a 0, le processus principal va se bloquer en attendant une nouvelle place + my $thr= threads->create("OneEvalBB", ( + $x, + $started, + \$completedBBEval, + \$semaphoreBBEval, + \$output[$started-1] + ) + ); + + push(@thrList,$thr); + + # détache le job du thread principal, rend la main au thread principal + $thr->detach(); + +} + + +# attend les derniers jobs +while ( @thrList ){ + sleep(0.01); + + my $r=0; + foreach $thr (@thrList) + { + if ( $thr->is_running() ) { + $r=1; + last; + } + } + last if ($r==0); +} +print "@output"; diff --git a/examples/basic/batch/single_obj_parallel/param.txt b/examples/basic/batch/single_obj_parallel/param.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd843429ced1236a62d6338e0de16a939fe649ac --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/param.txt @@ -0,0 +1,20 @@ +DIMENSION 5 # number of variables + +BB_EXE "$perl parallel_BBWrapper.pl" +# BB_EXE bb_parallel.exe +BB_MAX_BLOCK_SIZE 2 + +BB_OUTPUT_TYPE OBJ PB EB + +X0 ( 0 0 0 0 0 ) # starting point + +LOWER_BOUND * -6.0 # all variables are >= -6 +UPPER_BOUND ( 5 6 7 - - ) # x_1 <= 5, x_2 <= 6, x_3 <= 7 + # x_4 and x_5 have no bounds + +MAX_BB_EVAL 100 # the algorithm terminates when + # 100 black-box evaluations have + # been made + +TMP_DIR /tmp +DISPLAY_DEGREE 2 diff --git a/examples/basic/batch/single_obj_parallel/runExample.log b/examples/basic/batch/single_obj_parallel/runExample.log new file mode 100644 index 0000000000000000000000000000000000000000..2cad6904c99be5720e8b8392513889fdf8e20e89 --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/runExample.log @@ -0,0 +1,43 @@ +Warning: { + The maximum number of evaluations may be exceeded when BB_MAX_BLOCK_SIZE>1. +} + +NOMAD - version 3.7.2 - www.gerad.ca/nomad + +Copyright (C) 2001-2015 { + Mark A. Abramson - The Boeing Company + Charles Audet - Ecole Polytechnique de Montreal + Gilles Couture - Ecole Polytechnique de Montreal + John E. Dennis, Jr. - Rice University + Sebastien Le Digabel - Ecole Polytechnique de Montreal + Christophe Tribes - Ecole Polytechnique de Montreal +} + +Funded in part by AFOSR and Exxon Mobil. + +License : '$NOMAD_HOME/src/lgpl.txt' +User guide: '$NOMAD_HOME/doc/user_guide.pdf' +Examples : '$NOMAD_HOME/examples' +Tools : '$NOMAD_HOME/tools' + +Please report bugs to nomad@gerad.ca + +MADS run { + + BBE OBJ + + 2 288.7926372100 (PhaseOne) + 3 254.0899760400 (PhaseOne) + 4 0.0000000000 (PhaseOne) + 4 -1.0733100000 + 10 -1.6099700000 + 23 -2.4149500000 + 26 -3.4882700000 + 48 -3.7565900000 + 101 -3.7565900000 + +} end of run (max number of blackbox evaluations) + +blackbox evaluations : 101 +best infeasible solution (min. violation): ( 1.106853649 0.9391485505 1.01741093 1.00623059 -4.024922359 ) h=0.265307 f=-4.02492 +best feasible solution : ( 0.9838699101 0.5366563146 1.744133022 1.341640786 -3.756594202 ) h=0 f=-3.75659 diff --git a/examples/basic/batch/single_obj_parallel/x.txt b/examples/basic/batch/single_obj_parallel/x.txt new file mode 100644 index 0000000000000000000000000000000000000000..64decd0991156b61e0ecb83309f4af6107ec5b51 --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/x.txt @@ -0,0 +1,4 @@ +1 2 3 4 5 +0 0 0 0 0 +2 2 2 2 2 +5 4 3 2 1 diff --git a/examples/basic/batch/single_obj_parallel/x0.txt b/examples/basic/batch/single_obj_parallel/x0.txt new file mode 100644 index 0000000000000000000000000000000000000000..f51ebb0c5e4fcd07f49f88719e04f692abde4b21 --- /dev/null +++ b/examples/basic/batch/single_obj_parallel/x0.txt @@ -0,0 +1 @@ +0 0 0 0 0 0 diff --git a/examples/basic/library/bi_obj/runExample.log b/examples/basic/library/bi_obj/runExample.log index 511ba6fe48869a3527d19693c2b32c21c7a38b91..368fa2ef0e8506c3e93de99319debf1d17551f7b 100644 --- a/examples/basic/library/bi_obj/runExample.log +++ b/examples/basic/library/bi_obj/runExample.log @@ -1,10 +1,10 @@ multi-MADS run { - MADS run 1 ...... OK [bb eval= 46] [overall bb eval= 46] [# dominant pts= 3] [# new pts= 3] [f1=-6 f2=94.436255] - MADS run 2 ...... OK [bb eval= 23] [overall bb eval= 69] [# dominant pts= 3] [# new pts= 0] [f1=-4.5 f2=16.5199438] - MADS run 3 ...... OK [bb eval= 23] [overall bb eval= 92] [# dominant pts= 3] [# new pts= 0] [f1=-5.25 f2=15.24515131] - MADS run 4 ...... OK [bb eval= 8] [overall bb eval= 100] [# dominant pts= 3] [# new pts= 0] [f1=-5.25 f2=15.24515131] + MADS run 1 ...... OK [bb eval= 46] [overall bb eval= 46] [# dominant pts= 3] [# new pts= 3] [f1=-6 f2=152.5555363] + MADS run 2 ...... OK [bb eval= 23] [overall bb eval= 69] [# dominant pts= 6] [# new pts= 3] [f1=-1.170093169 f2=-7.948136425] + MADS run 3 ...... OK [bb eval= 23] [overall bb eval= 92] [# dominant pts= 8] [# new pts= 2] [f1=-6 f2=27.18734544] + MADS run 4 ...... OK [bb eval= 8] [overall bb eval= 100] [# dominant pts= 9] [# new pts= 1] [f1=-4.390031056 f2=12.07995483] } end of run (max number of bb evaluations) @@ -14,9 +14,15 @@ number of MADS runs : 4 Pareto front { - -6.0000000000 25.1826513073 - -5.2500000000 15.2451513073 - 0.7500000000 12.8461452933 + -6.0000000000 27.1873454385 + -5.4633436854 20.4877802253 + -4.9266873708 17.7107260310 + -4.3900310562 12.0799548321 + -4.1217028989 4.6477802253 + -3.8533747416 1.3742832861 + -3.5850465843 -0.2031008969 + -3.3167184270 -3.6003194012 + -1.1700931686 -7.9481364246 } -number of Pareto points: 3 +number of Pareto points: 9 diff --git a/examples/basic/library/single_obj/basic_lib.cpp b/examples/basic/library/single_obj/basic_lib.cpp index 57a29c9c7301506535ac22459c402c468dad01de..ea99384fe47fab1920a84b6962168606c71f40f9 100644 --- a/examples/basic/library/single_obj/basic_lib.cpp +++ b/examples/basic/library/single_obj/basic_lib.cpp @@ -52,9 +52,6 @@ int main ( int argc , char ** argv ) { // NOMAD initializations: NOMAD::begin ( argc , argv ); - NOMAD::RNG::set_seed(12345); - - // parameters creation: NOMAD::Parameters p ( out ); @@ -66,7 +63,7 @@ int main ( int argc , char ** argv ) { bbot[2] = NOMAD::EB; p.set_BB_OUTPUT_TYPE ( bbot ); - //p.set_DISPLAY_ALL_EVAL(true); // displays all evaluations. +// p.set_DISPLAY_ALL_EVAL(true); // displays all evaluations. p.set_DISPLAY_STATS ( "bbe ( sol ) obj" ); p.set_X0 ( NOMAD::Point(5,0.0) ); // starting point @@ -80,8 +77,8 @@ int main ( int argc , char ** argv ) { p.set_MAX_BB_EVAL (100); // the algorithm terminates after // 100 black-box evaluations - - // p.set_TMP_DIR ("/tmp"); // directory for temporary files + p.set_DISPLAY_DEGREE(2); + p.set_SOLUTION_FILE("sol.txt"); // parameters validation: p.check(); diff --git a/examples/basic/library/single_obj/runExample.log b/examples/basic/library/single_obj/runExample.log index 3bb3b041752a0d571db148dbf51466ec94fc4057..062f2c3da6c7831a471eee9e8a055910f3031e8d 100644 --- a/examples/basic/library/single_obj/runExample.log +++ b/examples/basic/library/single_obj/runExample.log @@ -3,15 +3,20 @@ MADS run { BBE ( SOL ) OBJ - 2 ( 1.1000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 275.2281000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 (PhaseOne) - 3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 - 11 ( 4.6750000000 0.9000000000 0.9750000000 1.5000000000 -1.5000000000 ) -1.5000000000 - 55 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000 - 100 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000 + 2 ( 0.0000000000 0.5366563146 0.5813776741 -0.2683281573 0.2683281573 ) 288.7937255854 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 0.0000000000 (PhaseOne) + 3 ( 0.0000000000 2.1466252584 2.3255106966 -1.0733126292 1.0733126292 ) 1.0733126292 + 11 ( 0.1229837388 2.5491174943 2.6161995337 -1.0733126292 0.8720665112 ) 0.8720665112 + 12 ( 0.4919349550 3.7565942022 3.4882660449 -1.0733126292 0.2683281573 ) 0.2683281573 + 21 ( 0.4919349550 4.2932505168 4.0696437190 -0.2683281573 -0.2683281573 ) -0.2683281573 + 23 ( 1.9677398202 1.6099689438 3.4882660449 -0.8049844719 -1.3416407865 ) -1.3416407865 + 38 ( 1.4758048651 3.2199378876 -0.5813776741 -0.2683281573 -2.9516097303 ) -2.9516097303 + 56 ( 1.9677398202 1.0733126292 1.7441330224 0.5366563146 -3.7565942022 ) -3.7565942022 + 85 ( 1.4758048651 0.9391485505 1.1627553483 0.8049844719 -3.8907582808 ) -3.8907582808 + 100 ( 1.4758048651 0.9391485505 1.1627553483 0.8049844719 -3.8907582808 ) -3.8907582808 } end of run (max number of blackbox evaluations) blackbox evaluations : 100 -best infeasible solution (min. violation): ( 0.55 1.8 2.6 -1.5 -3 ) h=0.6525 f=-3 -best feasible solution : ( 1.65 1.8 1.95 -1.5 -3 ) h=0 f=-3 +best infeasible solution (min. violation): ( 3.443544685 2.683281573 1.744133022 0.8049844719 -2.95160973 ) h=0.0113319552 f=-2.95160973 +best feasible solution : ( 1.475804865 0.9391485505 1.162755348 0.8049844719 -3.890758281 ) h=0 f=-3.890758281 diff --git a/examples/basic/library/single_obj_parallel/basic_lib.cpp b/examples/basic/library/single_obj_parallel/basic_lib.cpp new file mode 100644 index 0000000000000000000000000000000000000000..408e841dc3442a35c94fcdaf8268a3d2f71d7e6f --- /dev/null +++ b/examples/basic/library/single_obj_parallel/basic_lib.cpp @@ -0,0 +1,203 @@ +/*-----------------------------------------------------*/ +/* how to use the NOMAD library with a user function */ +/*-----------------------------------------------------*/ +#include "nomad.hpp" +#include <pthread.h> +#include <semaphore.h> + +using namespace std; +// using namespace NOMAD; avoids putting NOMAD:: everywhere + +// Number of threads to be used in parallel +#define NUM_THREADS 4 + +// A semaphore to manage parallel evaluations with NUM_THREADS +sem_t *mySemaphore; + +// A structure to pass arguments to the evaluation wrapper function +class My_Evaluator; +typedef struct Arg_Eval_tag { + NOMAD::Eval_Point * x ; + NOMAD::Double h_max; + bool * count_eval; + const My_Evaluator * ev; +} Arg_Eval_t; + + + +class My_Evaluator : public NOMAD::Evaluator { +public: + My_Evaluator ( const NOMAD::Parameters & p ) : + NOMAD::Evaluator ( p ) {} + + ~My_Evaluator ( void ) {} + + /*----------------------------------------*/ + /* The problem evaluatiom */ + /*----------------------------------------*/ + // Provide the objective and constraints here + bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) const + { + + NOMAD::Double c1 = 0.0 , c2 = 0.0; + for ( int i = 0 ; i < 5 ; i++ ) + { + c1 += (x[i]-1).pow2(); + c2 += (x[i]+1).pow2(); + } + x.set_bb_output ( 0 , x[4] ); // objective value + x.set_bb_output ( 1 , c1-25 ); // constraint 1 + x.set_bb_output ( 2 , 25-c2 ); // constraint 2 + + count_eval = true; // count a black-box evaluation + + return true; // the evaluation succeeded + } + + // Wrapper of eval_x used for parallel evaluation (pthreads). + static void * wrapper_eval_x ( void * dummy_eval_arg ) + { + + Arg_Eval_t * eval_arg = static_cast<Arg_Eval_t *>(dummy_eval_arg); + + NOMAD::Eval_Point & x=*(eval_arg->x); + bool & count_eval = *(eval_arg->count_eval); + const NOMAD::Double & h_max = (eval_arg->h_max); + const My_Evaluator *ev=(eval_arg->ev); + + ev->eval_x(x,h_max,count_eval); + + pthread_exit(NULL); + + } + + // Implementation + bool eval_x ( std::list<NOMAD::Eval_Point *> &list_x , + const NOMAD::Double & h_max, + std::list<bool> & list_count_eval ) const + { + int rc; + + + + list_count_eval.assign(list_count_eval.size(),false); // Evaluations are not counted until eval_x is called and set count_eval + + // All threads are created + pthread_t threads[list_x.size()]; + + // The semaphore will allow to run NUM_THREADS in parallel + mySemaphore=sem_open("sem",0,NUM_THREADS); + + // Arguments passed to the evaluation wrapper + Arg_Eval_t * eval_arg=new Arg_Eval_t[list_x.size()]; + + std::list<NOMAD::Eval_Point *>::iterator it_x=list_x.begin(),end_x=list_x.end(); + std::list<bool>::iterator it_count=list_count_eval.begin(); + int i=0; + // The list of points is evaluated under the control of a semaphore + for (it_x=list_x.begin(); it_x!=end_x; ++it_x,++it_count,++i) + { + eval_arg[i].x=(*it_x); + eval_arg[i].h_max=h_max.value(); + eval_arg[i].count_eval=&(*it_count); + eval_arg[i].ev=this; + rc=pthread_create(&threads[i], NULL, wrapper_eval_x,&eval_arg[i]); + if (rc) + { + cout << "Error:unable to create thread," << rc << endl; + return false; + } + // wait until value of semaphore is greater than 0 + // decrement the value of semaphore by 1 + sem_wait(mySemaphore); + + } + + delete []eval_arg; + int ret; + for (i=0; i<list_x.size(); ++i) + { + // Wait for all the threads to finish + ret=pthread_join(threads[i],0); + if (ret!=0) + { + perror("pthread join has failed"); + return false; + } + } + + sem_unlink("sem"); + + return true; // the evaluation succeeded + } + + + +}; + +/*------------------------------------------*/ +/* NOMAD main function */ +/*------------------------------------------*/ +int main ( int argc , char ** argv ) { + + // display: + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + try { + + // NOMAD initializations: + NOMAD::begin ( argc , argv ); + + // parameters creation: + NOMAD::Parameters p ( out ); + + p.set_DIMENSION (5); // number of variables + + vector<NOMAD::bb_output_type> bbot (3); // definition of + bbot[0] = NOMAD::OBJ; // output types + bbot[1] = NOMAD::PB; + bbot[2] = NOMAD::EB; + p.set_BB_OUTPUT_TYPE ( bbot ); + +// p.set_DISPLAY_ALL_EVAL(true); // displays all evaluations. + p.set_DISPLAY_DEGREE(2); + p.set_DISPLAY_STATS ( "bbe ( sol ) obj" ); + + p.set_X0 ( NOMAD::Point(5,0.0) ); // starting point + + p.set_LOWER_BOUND ( NOMAD::Point ( 5 , -6.0 ) ); // all var. >= -6 + NOMAD::Point ub ( 5 ); // x_4 and x_5 have no bounds + ub[0] = 5.0; // x_1 <= 5 + ub[1] = 6.0; // x_2 <= 6 + ub[2] = 7.0; // x_3 <= 7 + p.set_UPPER_BOUND ( ub ); + + p.set_MAX_BB_EVAL (100); // the algorithm terminates after + // 100 black-box evaluations + + // Max number of points to be given as a block for evaluation + // This option is required to perform parallel evaluations + p.set_BB_MAX_BLOCK_SIZE(NUM_THREADS); + + // parameters validation: + p.check(); + + // custom evaluator creation: + My_Evaluator ev ( p ); + + // algorithm creation and execution: + NOMAD::Mads mads ( p , &ev ); + mads.run(); + } + catch ( exception & e ) { + cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; + } + + NOMAD::Slave::stop_slaves ( out ); + NOMAD::end(); + + return EXIT_SUCCESS; +} diff --git a/examples/basic/library/single_obj_parallel/makefile b/examples/basic/library/single_obj_parallel/makefile new file mode 100644 index 0000000000000000000000000000000000000000..d7af8590b39b753b2c1d7c9ff6a4a5a4412bf573 --- /dev/null +++ b/examples/basic/library/single_obj_parallel/makefile @@ -0,0 +1,50 @@ +EXE = basic_lib.exe + +COMPILATOR = g++ + +COMPILATOR_OPTIONS = -O2 -ansi +L1 = $(NOMAD_HOME)/lib/nomad.a +LIBS = $(L1) -lm +INCLUDE = -I$(NOMAD_HOME)/src -I. +COMPILE = $(COMPILATOR) $(COMPILATOR_OPTIONS) $(INCLUDE) -c +OBJS = basic_lib.o + + +ifndef NOMAD_HOME +define ECHO_NOMAD + @echo Please set NOMAD_HOME environment variable! + @false +endef +endif + + +$(EXE): $(L1) $(OBJS) + $(ECHO_NOMAD) + @echo " building the parallel (ptrhreads) version ..." + @echo " exe file : "$(EXE) + @$(COMPILATOR) -o $(EXE) $(OBJS) $(LIBS) $(COMPILATOR_OPTIONS) + @strip $(EXE) + +basic_lib.o: basic_lib.cpp + $(ECHO_NOMAD) + @$(COMPILE) basic_lib.cpp + +$(L1) : ; + $(ECHO_NOMAD) + + +all: $(EXE) + +clean: ; + @echo " cleaning obj files" + @rm -f $(OBJS) + +del: ; + @echo " cleaning trash files" + @rm -f core *~ + @echo " cleaning obj files" + @rm -f $(OBJS) + @echo " cleaning exe file" + @rm -f $(EXE) + + diff --git a/examples/basic/library/single_obj_parallel/runExample.log b/examples/basic/library/single_obj_parallel/runExample.log new file mode 100644 index 0000000000000000000000000000000000000000..c69008cbeebc23cc2077f1733abf03ee7482cff2 --- /dev/null +++ b/examples/basic/library/single_obj_parallel/runExample.log @@ -0,0 +1,27 @@ +Warning: { + The maximum number of evaluations may be exceeded when BB_MAX_BLOCK_SIZE>1. +} + +MADS run { + + BBE ( SOL ) OBJ + + 2 ( 0.0000000000 0.5366563146 0.5813776741 -0.2683281573 0.2683281573 ) 288.7937255854 (PhaseOne) + 3 ( 0.4919349550 1.0733126292 0.0000000000 0.0000000000 -0.2683281573 ) 254.0887373636 (PhaseOne) + 4 ( 0.4919349550 0.0000000000 1.1627553483 0.2683281573 -0.2683281573 ) 223.5808267209 (PhaseOne) + 6 ( 1.9677398202 0.0000000000 4.6510213932 1.0733126292 -1.0733126292 ) 0.0000000000 (PhaseOne) + 6 ( 1.9677398202 0.0000000000 4.6510213932 1.0733126292 -1.0733126292 ) -1.0733126292 + 12 ( 1.4758048651 -0.5366563146 4.0696437190 0.8049844719 -1.6099689438 ) -1.6099689438 + 14 ( 0.4919349550 0.5366563146 4.0696437190 0.2683281573 -2.4149534157 ) -2.4149534157 + 30 ( 1.9677398202 0.5366563146 1.1627553483 1.3416407865 -3.2199378876 ) -3.2199378876 + 52 ( 0.9838699101 0.5366563146 1.7441330224 1.3416407865 -3.7565942022 ) -3.7565942022 + 74 ( 0.9838699101 1.0733126292 1.7441330224 0.5366563146 -3.7565942022 ) -3.7565942022 + 92 ( 1.2298373876 1.2074767078 1.3080997668 1.0062305899 -3.8236762415 ) -3.8236762415 + 95 ( 0.8608861713 1.2074767078 1.1627553483 1.3416407865 -3.8907582808 ) -3.8907582808 + 101 ( 0.8608861713 1.2074767078 1.1627553483 1.3416407865 -3.8907582808 ) -3.8907582808 + +} end of run (max number of blackbox evaluations) + +blackbox evaluations : 101 +best infeasible solution (min. violation): ( 0.9838699101 1.073312629 1.162755348 1.073312629 -4.024922359 ) h=0.2873436854 f=-4.024922359 +best feasible solution : ( 0.8608861713 1.207476708 1.162755348 1.341640786 -3.890758281 ) h=0 f=-3.890758281 diff --git a/examples/interfaces/AMPL/runExample.log b/examples/interfaces/AMPL/runExample.log index 2e2d97d2c4b6551396131a8620ea40c53a80db63..4e5a25f286c6a2c883d09ef4ec2dc31774b49dcb 100644 --- a/examples/interfaces/AMPL/runExample.log +++ b/examples/interfaces/AMPL/runExample.log @@ -1,7 +1,7 @@ -NOMAD - version 3.6.1 - www.gerad.ca/nomad +NOMAD - version 3.7.1 - www.gerad.ca/nomad -Copyright (C) 2001-2013 { +Copyright (C) 2001-2015 { Mark A. Abramson - The Boeing Company Charles Audet - Ecole Polytechnique de Montreal Gilles Couture - Ecole Polytechnique de Montreal @@ -24,45 +24,57 @@ MADS run { BBE OBJ 1 0.0008855723 - 18 0.0008418472 - 27 0.0007858003 - 83 0.0007849247 - 107 0.0007587924 - 160 0.0007535678 - 177 0.0007479755 - 202 0.0007380410 - 245 0.0007340172 - 273 0.0007283297 - 338 0.0007280775 - 340 0.0007270988 - 341 0.0007260201 - 355 0.0007237479 - 375 0.0007236576 - 390 0.0007223485 - 404 0.0007218982 - 418 0.0007217642 - 462 0.0007206517 - 482 0.0007204212 - 523 0.0007202708 - 551 0.0007201867 - 591 0.0007200853 - 628 0.0007199875 - 673 0.0007199828 - 701 0.0007199638 - 730 0.0007199581 - 747 0.0007199510 - 748 0.0007199335 - 749 0.0007199166 - 758 0.0007198508 - 795 0.0007198372 - 853 0.0007198240 - 880 0.0007197980 - 887 0.0007197952 - 992 0.0007197935 - 1000 0.0007197935 + 13 0.0008629415 + 73 0.0007682919 + 158 0.0007674024 + 160 0.0007590596 + 176 0.0007580561 + 223 0.0007473508 + 238 0.0007418250 + 253 0.0007372242 + 313 0.0007347847 + 315 0.0007332118 + 317 0.0007326378 + 319 0.0007305500 + 349 0.0007267455 + 364 0.0007266172 + 387 0.0007257315 + 394 0.0007248895 + 435 0.0007231991 + 437 0.0007231585 + 439 0.0007228901 + 445 0.0007225342 + 475 0.0007215812 + 490 0.0007212792 + 505 0.0007211745 + 511 0.0007211392 + 532 0.0007207825 + 547 0.0007206714 + 606 0.0007200196 + 635 0.0007200045 + 653 0.0007198430 + 657 0.0007198134 + 684 0.0007197965 + 711 0.0007197807 + 712 0.0007197631 + 767 0.0007197518 + 783 0.0007197518 + 811 0.0007197377 + 825 0.0007197358 + 840 0.0007197336 + 841 0.0007197273 + 902 0.0007197266 + 904 0.0007197250 + 919 0.0007197244 + 920 0.0007197231 + 935 0.0007197211 + 963 0.0007197196 + 965 0.0007197191 + 993 0.0007197174 + 1000 0.0007197174 } end of run (max number of blackbox evaluations) blackbox evaluations : 1000 -best infeasible solution (min. violation): ( 0.848962364 2.324953675e-06 3.01413238e-06 2.850219607e-06 0.0001720577478 0.07897830494 0.03139281012 0.0110261865 ) h=0.05000000003 f=0.000719795225 -best feasible solution : ( 0.8489658805 0 0 0 0.0001777410507 0.07896998888 0.03139625052 0.01103117205 ) h=0 f=0.0007197935108 +best infeasible solution (min. violation): ( 0.8485876659 1.323962574e-06 2.55409902e-06 1.18495206e-06 4.478102654e-06 0.07926348224 0.03138097659 0.01128972406 ) h=0.05000000006 f=0.0007197247301 +best feasible solution : ( 0.8485431024 1.006379485e-06 7.250492715e-07 1.072192777e-06 2.36219915e-06 0.07937295341 0.03130849192 0.01130402409 ) h=0 f=0.0007197173872 diff --git a/examples/interfaces/CUTEr/parameters.txt b/examples/interfaces/CUTEr/param.txt similarity index 90% rename from examples/interfaces/CUTEr/parameters.txt rename to examples/interfaces/CUTEr/param.txt index a4e6a79c06a3a4657e3d18988d5fe253e989510d..05b0dfb619b0071309fc37e1c6af2ca23692039c 100644 --- a/examples/interfaces/CUTEr/parameters.txt +++ b/examples/interfaces/CUTEr/param.txt @@ -10,7 +10,7 @@ BB_EXE bb.exe BB_OUTPUT_TYPE OBJ MAX_BB_EVAL 100 -DIRECTION_TYPE ortho n+1 +DIRECTION_TYPE ortho 2n #stats_file ortho.stats TIME BBE OBJ #solution_file ortho.sol diff --git a/examples/interfaces/CUTEr/readme.txt b/examples/interfaces/CUTEr/readme.txt index 8af17eaddefdac6788353e27f164d2a2d4b91927..4e889806f7bcde57df1e8f4bdfcacaed8fb5eb68 100644 --- a/examples/interfaces/CUTEr/readme.txt +++ b/examples/interfaces/CUTEr/readme.txt @@ -23,4 +23,4 @@ Compile with the C wrapper 'bb.c' by running the script 'compile' The black-box executable 'bb.exe' should be created. You can test it with the command 'bb.exe x0.txt', and run nomad with the command -'nomad.exe parameters.txt'. +'nomad.exe param.txt'. diff --git a/examples/interfaces/DLL/bi_obj/nomad_for_DLL.cpp b/examples/interfaces/DLL/bi_obj/nomad_for_DLL.cpp index f5635682298eba8cb2a985612abbc8380524b848..316e94b2d4c1ff02bd76f7f22dcfa0675c34a8ef 100755 --- a/examples/interfaces/DLL/bi_obj/nomad_for_DLL.cpp +++ b/examples/interfaces/DLL/bi_obj/nomad_for_DLL.cpp @@ -1,212 +1,212 @@ -/*---------------------------------------------------------------*/ -/* NOMAD for a DLL-black-box */ -/*---------------------------------------------------------------*/ -#include "nomad.hpp" -#include <windows.h> -using namespace std; -using namespace NOMAD; - -// black-box outputs (m): -// ---------------------- -// . the first one is the objective function -// . all the others (1 to m-1) are PB constraints with format g(x) <= 0 - - -/*------------------------------------------*/ -/* DLL functions */ -/*------------------------------------------*/ -typedef int (_stdcall *GET_NM)( void ); -typedef void (_stdcall *EVAL_X)( double * , double * , bool * ); -typedef void (_stdcall *INIT )( void ); - -GET_NM get_n_dll; -GET_NM get_m_dll; -EVAL_X eval_x_dll; -//INIT init_dll; -//INIT clear_dll; - -// simulate the DLL functions (for tests): -/* -void init ( void ) {} -void clear ( void ) {} -int get_n_dll ( void ) { return 5; } -int get_m_dll ( void ) { return 3; } -void eval_x_dll ( double * x , double * fx , bool & cnt_eval ) { - double c1 = 0.0 , c2 = 0.0; - for ( int i = 0 ; i < 5 ; ++i ) { - c1 += pow ( x[i]-1 , 2 ); - c2 += pow ( x[i]+1 , 2 ); - } - fx[0] = x[4]; - fx[1] = c1 - 25; - fx[2] = 25 - c2; - cnt_eval = true; -} -*/ - -/*--------------------------------------*/ -/* custom evaluator */ -/*--------------------------------------*/ -class My_Evaluator : public Multi_Obj_Evaluator { - -private: - - int _n; - int _m; - double * _px; - double * _fx; - -public: - - // ctor: - My_Evaluator ( const Parameters & p , int n , int m ) - : Multi_Obj_Evaluator ( p ) , - _n ( n ) , - _m ( m ) , - _px ( new double [_n] ) , - _fx ( new double [_m] ) {} - - // dtor: - ~My_Evaluator ( void ) { delete [] _px; delete [] _fx; } - - // eval_x: - bool eval_x ( Eval_Point & x , - const NOMAD::Double & h_max , - bool & cnt_eval ) const; -}; - -// eval_x: -bool My_Evaluator::eval_x ( Eval_Point & x , - const NOMAD::Double & h_max , - bool & cnt_eval ) const { - int i; - for ( i = 0 ; i < _n ; ++i ) - _px[i] = x[i].value(); - eval_x_dll ( _px , _fx , &cnt_eval ); - for ( i = 0 ; i < _m ; ++i ) - x.set_bb_output ( i , _fx[i] ); - return true; -} - -/*------------------------------------------*/ -/* NOMAD main function */ -/*------------------------------------------*/ -int main ( int argc , char ** argv ) { - - // use: - if ( argc != 2 ) { - cerr << "\nuse: nomad_for_DLL.exe param.txt\n\n"; - return 1; - } - - // NOMAD initializations: - begin ( argc , argv ); - - // display: - NOMAD::Display out ( std::cout ); - out.precision ( NOMAD::DISPLAY_PRECISION_STD ); - - // random seed: - unsigned seed = 0; - srand(seed); - - // define DLL functions: - // get handle to dll: - HINSTANCE hdll = LoadLibrary ( TEXT("bb.dll") ); - if ( !hdll ) { - cerr << "ERROR: unable to open bb.dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - // get function pointers: - get_n_dll = (GET_NM)GetProcAddress(hdll, "GET_N"); - if ( !get_n_dll ) { - cerr << "ERROR: unable to find GET_N function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - get_m_dll = (GET_NM)GetProcAddress(hdll, "GET_M"); - if ( !get_m_dll ) { - cerr << "ERROR: unable to find GET_M function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - eval_x_dll = (EVAL_X)GetProcAddress(hdll, "EVAL_X"); - if ( !eval_x_dll ) { - cerr << "ERROR: unable to find EVAL_X function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - /* init_dll = (INIT)GetProcAddress(hdll, "INIT"); - if ( !init_dll ) { - cerr << "ERROR: unable to find INIT function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - clear_dll = (INIT)GetProcAddress(hdll, "CLEAR"); - if ( !clear_dll ) { - cerr << "ERROR: unable to find CLEAR function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - }*/ - - // MADS: - try { - - /* init_dll(); */ - - int n = get_n_dll(); - int m = get_m_dll(); - - // parameters creation: - // -------------------- - Parameters p ( out ); - - // dimension: - p.set_DIMENSION ( n ); - - // definition of output types: - vector<bb_output_type> bbot (m); - bbot[0] = bbot[1] = OBJ; - for ( int i = 2 ; i < m ; ++i ) - bbot[i] = PB; - p.set_BB_OUTPUT_TYPE ( bbot ); - - // read parameters file: - p.read ( argv[1] ); - - // parameters check: - p.check(); - - // display parameters: - // out << p << endl; - - // custom evaluator creation: - My_Evaluator ev ( p , n , m ); - - // algorithm creation and execution: - Mads mads ( p , &ev ); - mads.multi_run(); - - // algorithm display: - // out << mads << endl; - - /* clear_dll(); */ - } - catch ( exception & e ) { - cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; - } - - // Release the Dll: - FreeLibrary ( hdll ); - - NOMAD::Slave::stop_slaves ( out ); - NOMAD::end(); - - return EXIT_SUCCESS; -} +/*---------------------------------------------------------------*/ +/* NOMAD for a DLL-black-box */ +/*---------------------------------------------------------------*/ +#include "nomad.hpp" +#include <windows.h> +using namespace std; +using namespace NOMAD; + +// black-box outputs (m): +// ---------------------- +// . the first one is the objective function +// . all the others (1 to m-1) are PB constraints with format g(x) <= 0 + + +/*------------------------------------------*/ +/* DLL functions */ +/*------------------------------------------*/ +typedef int (_stdcall *GET_NM)( void ); +typedef void (_stdcall *EVAL_X)( double * , double * , bool * ); +typedef void (_stdcall *INIT )( void ); + +GET_NM get_n_dll; +GET_NM get_m_dll; +EVAL_X eval_x_dll; +//INIT init_dll; +//INIT clear_dll; + +// simulate the DLL functions (for tests): +/* +void init ( void ) {} +void clear ( void ) {} +int get_n_dll ( void ) { return 5; } +int get_m_dll ( void ) { return 3; } +void eval_x_dll ( double * x , double * fx , bool & cnt_eval ) { + double c1 = 0.0 , c2 = 0.0; + for ( int i = 0 ; i < 5 ; ++i ) { + c1 += pow ( x[i]-1 , 2 ); + c2 += pow ( x[i]+1 , 2 ); + } + fx[0] = x[4]; + fx[1] = c1 - 25; + fx[2] = 25 - c2; + cnt_eval = true; +} +*/ + +/*--------------------------------------*/ +/* custom evaluator */ +/*--------------------------------------*/ +class My_Evaluator : public Multi_Obj_Evaluator { + +private: + + int _n; + int _m; + double * _px; + double * _fx; + +public: + + // ctor: + My_Evaluator ( const Parameters & p , int n , int m ) + : Multi_Obj_Evaluator ( p ) , + _n ( n ) , + _m ( m ) , + _px ( new double [_n] ) , + _fx ( new double [_m] ) {} + + // dtor: + ~My_Evaluator ( void ) { delete [] _px; delete [] _fx; } + + // eval_x: + bool eval_x ( Eval_Point & x , + const NOMAD::Double & h_max , + bool & cnt_eval ) const; +}; + +// eval_x: +bool My_Evaluator::eval_x ( Eval_Point & x , + const NOMAD::Double & h_max , + bool & cnt_eval ) const { + int i; + for ( i = 0 ; i < _n ; ++i ) + _px[i] = x[i].value(); + eval_x_dll ( _px , _fx , &cnt_eval ); + for ( i = 0 ; i < _m ; ++i ) + x.set_bb_output ( i , _fx[i] ); + return true; +} + +/*------------------------------------------*/ +/* NOMAD main function */ +/*------------------------------------------*/ +int main ( int argc , char ** argv ) { + + // use: + if ( argc != 2 ) { + cerr << "\nuse: nomad_for_DLL.exe param.txt\n\n"; + return 1; + } + + // NOMAD initializations: + begin ( argc , argv ); + + // display: + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + // random seed: + unsigned seed = 0; + srand(seed); + + // define DLL functions: + // get handle to dll: + HINSTANCE hdll = LoadLibrary ( TEXT("bb.dll") ); + if ( !hdll ) { + cerr << "ERROR: unable to open bb.dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + // get function pointers: + get_n_dll = (GET_NM)GetProcAddress(hdll, "GET_N"); + if ( !get_n_dll ) { + cerr << "ERROR: unable to find GET_N function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + get_m_dll = (GET_NM)GetProcAddress(hdll, "GET_M"); + if ( !get_m_dll ) { + cerr << "ERROR: unable to find GET_M function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + eval_x_dll = (EVAL_X)GetProcAddress(hdll, "EVAL_X"); + if ( !eval_x_dll ) { + cerr << "ERROR: unable to find EVAL_X function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + /* init_dll = (INIT)GetProcAddress(hdll, "INIT"); + if ( !init_dll ) { + cerr << "ERROR: unable to find INIT function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + clear_dll = (INIT)GetProcAddress(hdll, "CLEAR"); + if ( !clear_dll ) { + cerr << "ERROR: unable to find CLEAR function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + }*/ + + // MADS: + try { + + /* init_dll(); */ + + int n = get_n_dll(); + int m = get_m_dll(); + + // parameters creation: + // -------------------- + Parameters p ( out ); + + // dimension: + p.set_DIMENSION ( n ); + + // definition of output types: + vector<bb_output_type> bbot (m); + bbot[0] = bbot[1] = OBJ; + for ( int i = 2 ; i < m ; ++i ) + bbot[i] = PB; + p.set_BB_OUTPUT_TYPE ( bbot ); + + // read parameters file: + p.read ( argv[1] ); + + // parameters check: + p.check(); + + // display parameters: + // out << p << endl; + + // custom evaluator creation: + My_Evaluator ev ( p , n , m ); + + // algorithm creation and execution: + Mads mads ( p , &ev ); + mads.multi_run(); + + // algorithm display: + // out << mads << endl; + + /* clear_dll(); */ + } + catch ( exception & e ) { + cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; + } + + // Release the Dll: + FreeLibrary ( hdll ); + + NOMAD::Slave::stop_slaves ( out ); + NOMAD::end(); + + return EXIT_SUCCESS; +} diff --git a/examples/interfaces/DLL/bi_obj/parameters.txt b/examples/interfaces/DLL/bi_obj/param.txt similarity index 91% rename from examples/interfaces/DLL/bi_obj/parameters.txt rename to examples/interfaces/DLL/bi_obj/param.txt index 7b6d6bb07dfbe5b6006ca390a31169ed7d2959c5..fea33eff08041ea0badd4c9fbe3af20959c45d8b 100755 --- a/examples/interfaces/DLL/bi_obj/parameters.txt +++ b/examples/interfaces/DLL/bi_obj/param.txt @@ -1,28 +1,28 @@ -#seed 100 - -initial_mesh_size r0.1 - -direction_type ortho 2n - - -multi_overall_bb_eval 1000 - -lower_bound * -10.0 - -upper_bound * 10.0 - - -x0 ( 2 3 4 5 6 ) - -display_degree 3 - - -add_seed_to_file_names no - -#stats_file toto.txt bbe obj -#solution_file "sol.txt" - -#LH_SEARCH 100 0 - -#OPPORTUNISTIC_LH no - +#seed 100 + +initial_mesh_size r0.1 + +direction_type ortho 2n + + +multi_overall_bb_eval 1000 + +lower_bound * -10.0 + +upper_bound * 10.0 + + +x0 ( 2 3 4 5 6 ) + +display_degree 3 + + +add_seed_to_file_names no + +#stats_file toto.txt bbe obj +#solution_file "sol.txt" + +#LH_SEARCH 100 0 + +#OPPORTUNISTIC_LH no + diff --git a/examples/interfaces/DLL/bi_obj/readme.txt b/examples/interfaces/DLL/bi_obj/readme.txt index a37fa9ce3daa29a495dedbeba3f3be4a78828c27..8889d3d20527bdcb3526d71a661f767b543d722c 100755 --- a/examples/interfaces/DLL/bi_obj/readme.txt +++ b/examples/interfaces/DLL/bi_obj/readme.txt @@ -1,54 +1,54 @@ - -This example illustrates how to use NOMAD with a black-box -problem that is coded inside a DLL file. - -The problem has two objective values to minimize. - -The example runs on windows with visual C++ and minGW. - - -DLL characteristics: - -/*----------*/ - -/* bb.dll */ - -/*----------*/ - - - -// init/clear: - -// ----------- - -void init_dll ( void ); - -void clear_dll ( void ); - -// problem characteristics: - -// ------------------------ - - -int get_n_dll ( void ); // number of variables - -int get_m _dll( void ); // number of outputs: output #0 and #1: objective values to minimize - - // output #2..m-1: PB constraints with format g(x) <= 0 - - - -// evaluation: f(x): - -// ----------------- - - -void eval_x_dll ( double * x , double * fx , bool & count_eval ); - - - -// x: input , double array of size n - -// fx: output, double array of size m - -// count_eval: output, set to true if the evaluation has to be counted, false else + +This example illustrates how to use NOMAD with a black-box +problem that is coded inside a DLL file. + +The problem has two objective values to minimize. + +The example runs on windows with visual C++ and minGW. + + +DLL characteristics: + +/*----------*/ + +/* bb.dll */ + +/*----------*/ + + + +// init/clear: + +// ----------- + +void init_dll ( void ); + +void clear_dll ( void ); + +// problem characteristics: + +// ------------------------ + + +int get_n_dll ( void ); // number of variables + +int get_m _dll( void ); // number of outputs: output #0 and #1: objective values to minimize + + // output #2..m-1: PB constraints with format g(x) <= 0 + + + +// evaluation: f(x): + +// ----------------- + + +void eval_x_dll ( double * x , double * fx , bool & count_eval ); + + + +// x: input , double array of size n + +// fx: output, double array of size m + +// count_eval: output, set to true if the evaluation has to be counted, false else diff --git a/examples/interfaces/DLL/single_obj/nomad_for_DLL.cpp b/examples/interfaces/DLL/single_obj/nomad_for_DLL.cpp index 968a4d7f2e031c39af4da8c3a9bfe451a37bc296..43f4dcf71045b68012a898e7e986eed4925995ab 100755 --- a/examples/interfaces/DLL/single_obj/nomad_for_DLL.cpp +++ b/examples/interfaces/DLL/single_obj/nomad_for_DLL.cpp @@ -1,212 +1,212 @@ -/*---------------------------------------------------------------*/ -/* NOMAD for a DLL-black-box */ -/*---------------------------------------------------------------*/ -#include "nomad.hpp" -#include <windows.h> -using namespace std; -using namespace NOMAD; - -// black-box outputs (m): -// ---------------------- -// . the first one is the objective function -// . all the others (1 to m-1) are PB constraints with format g(x) <= 0 - - -/*------------------------------------------*/ -/* DLL functions */ -/*------------------------------------------*/ -typedef int (_stdcall *GET_NM)( void ); -typedef void (_stdcall *EVAL_X)( double * , double * , bool * ); -typedef void (_stdcall *INIT )( void ); - -GET_NM get_n_dll; -GET_NM get_m_dll; -EVAL_X eval_x_dll; -//INIT init_dll; -//INIT clear_dll; - -// simulate the DLL functions (for tests): -/* -void init ( void ) {} -void clear ( void ) {} -int get_n_dll ( void ) { return 5; } -int get_m_dll ( void ) { return 3; } -void eval_x_dll ( double * x , double * fx , bool & cnt_eval ) { - double c1 = 0.0 , c2 = 0.0; - for ( int i = 0 ; i < 5 ; ++i ) { - c1 += pow ( x[i]-1 , 2 ); - c2 += pow ( x[i]+1 , 2 ); - } - fx[0] = x[4]; - fx[1] = c1 - 25; - fx[2] = 25 - c2; - cnt_eval = true; -} -*/ - -/*--------------------------------------*/ -/* custom evaluator */ -/*--------------------------------------*/ -class My_Evaluator : public Evaluator { - -private: - - int _n; - int _m; - double * _px; - double * _fx; - -public: - - // ctor: - My_Evaluator ( const Parameters & p , int n , int m ) - : Evaluator ( p ) , - _n ( n ) , - _m ( m ) , - _px ( new double [_n] ) , - _fx ( new double [_m] ) {} - - // dtor: - ~My_Evaluator ( void ) { delete [] _px; delete [] _fx; } - - // eval_x: - bool eval_x ( Eval_Point & x , - const Double & h_max , - bool & cnt_eval ) const; -}; - -// eval_x: -bool My_Evaluator::eval_x ( Eval_Point & x , - const Double & h_max , - bool & cnt_eval ) const { - int i; - for ( i = 0 ; i < _n ; ++i ) - _px[i] = x[i].value(); - eval_x_dll ( _px , _fx , &cnt_eval ); - for ( i = 0 ; i < _m ; ++i ) - x.set_bb_output ( i , _fx[i] ); - return true; -} - -/*------------------------------------------*/ -/* NOMAD main function */ -/*------------------------------------------*/ -int main ( int argc , char ** argv ) { - - // use: - if ( argc != 2 ) { - cerr << "\nuse: nomad_for_DLL.exe param.txt\n\n"; - return 1; - } - - // NOMAD initializations: - begin ( argc , argv ); - - // display: - NOMAD::Display out ( std::cout ); - out.precision ( NOMAD::DISPLAY_PRECISION_STD ); - - // random seed: - unsigned seed = 0; - srand(seed); - - // define DLL functions: - // get handle to dll: - HINSTANCE hdll = LoadLibrary ( TEXT("bb.dll") ); - if ( !hdll ) { - cerr << "ERROR: unable to open bb.dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - // get function pointers: - get_n_dll = (GET_NM)GetProcAddress(hdll, "GET_N"); - if ( !get_n_dll ) { - cerr << "ERROR: unable to find GET_N function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - get_m_dll = (GET_NM)GetProcAddress(hdll, "GET_M"); - if ( !get_m_dll ) { - cerr << "ERROR: unable to find GET_M function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - eval_x_dll = (EVAL_X)GetProcAddress(hdll, "EVAL_X"); - if ( !eval_x_dll ) { - cerr << "ERROR: unable to find EVAL_X function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - /* init_dll = (INIT)GetProcAddress(hdll, "INIT"); - if ( !init_dll ) { - cerr << "ERROR: unable to find INIT function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - } - - clear_dll = (INIT)GetProcAddress(hdll, "CLEAR"); - if ( !clear_dll ) { - cerr << "ERROR: unable to find CLEAR function in dll" << endl; - FreeLibrary ( hdll ); - return 1; - }*/ - - // MADS: - try { - - /* init_dll(); */ - - int n = get_n_dll(); - int m = get_m_dll(); - - // parameters creation: - // -------------------- - Parameters p ( out ); - - // dimension: - p.set_DIMENSION ( n ); - - // definition of output types: - vector<bb_output_type> bbot (m); - bbot[0] = OBJ; - for ( int i = 1 ; i < m ; ++i ) - bbot[i] = PB; - p.set_BB_OUTPUT_TYPE ( bbot ); - - // read parameters file: - p.read ( argv[1] ); - - // parameters check: - p.check(); - - // display parameters: - // out << p << endl; - - // custom evaluator creation: - My_Evaluator ev ( p , n , m ); - - // algorithm creation and execution: - Mads mads ( p , &ev ); - mads.run(); - - // algorithm display: - // out << mads << endl; - - /* clear_dll(); */ - } - catch ( exception & e ) { - cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; - } - - // Release the Dll: - FreeLibrary ( hdll ); - - NOMAD::Slave::stop_slaves ( out ); - NOMAD::end(); - - return EXIT_SUCCESS; -} +/*---------------------------------------------------------------*/ +/* NOMAD for a DLL-black-box */ +/*---------------------------------------------------------------*/ +#include "nomad.hpp" +#include <windows.h> +using namespace std; +using namespace NOMAD; + +// black-box outputs (m): +// ---------------------- +// . the first one is the objective function +// . all the others (1 to m-1) are PB constraints with format g(x) <= 0 + + +/*------------------------------------------*/ +/* DLL functions */ +/*------------------------------------------*/ +typedef int (_stdcall *GET_NM)( void ); +typedef void (_stdcall *EVAL_X)( double * , double * , bool * ); +typedef void (_stdcall *INIT )( void ); + +GET_NM get_n_dll; +GET_NM get_m_dll; +EVAL_X eval_x_dll; +//INIT init_dll; +//INIT clear_dll; + +// simulate the DLL functions (for tests): +/* +void init ( void ) {} +void clear ( void ) {} +int get_n_dll ( void ) { return 5; } +int get_m_dll ( void ) { return 3; } +void eval_x_dll ( double * x , double * fx , bool & cnt_eval ) { + double c1 = 0.0 , c2 = 0.0; + for ( int i = 0 ; i < 5 ; ++i ) { + c1 += pow ( x[i]-1 , 2 ); + c2 += pow ( x[i]+1 , 2 ); + } + fx[0] = x[4]; + fx[1] = c1 - 25; + fx[2] = 25 - c2; + cnt_eval = true; +} +*/ + +/*--------------------------------------*/ +/* custom evaluator */ +/*--------------------------------------*/ +class My_Evaluator : public Evaluator { + +private: + + int _n; + int _m; + double * _px; + double * _fx; + +public: + + // ctor: + My_Evaluator ( const Parameters & p , int n , int m ) + : Evaluator ( p ) , + _n ( n ) , + _m ( m ) , + _px ( new double [_n] ) , + _fx ( new double [_m] ) {} + + // dtor: + ~My_Evaluator ( void ) { delete [] _px; delete [] _fx; } + + // eval_x: + bool eval_x ( Eval_Point & x , + const Double & h_max , + bool & cnt_eval ) const; +}; + +// eval_x: +bool My_Evaluator::eval_x ( Eval_Point & x , + const Double & h_max , + bool & cnt_eval ) const { + int i; + for ( i = 0 ; i < _n ; ++i ) + _px[i] = x[i].value(); + eval_x_dll ( _px , _fx , &cnt_eval ); + for ( i = 0 ; i < _m ; ++i ) + x.set_bb_output ( i , _fx[i] ); + return true; +} + +/*------------------------------------------*/ +/* NOMAD main function */ +/*------------------------------------------*/ +int main ( int argc , char ** argv ) { + + // use: + if ( argc != 2 ) { + cerr << "\nuse: nomad_for_DLL.exe param.txt\n\n"; + return 1; + } + + // NOMAD initializations: + begin ( argc , argv ); + + // display: + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + // random seed: + unsigned seed = 0; + srand(seed); + + // define DLL functions: + // get handle to dll: + HINSTANCE hdll = LoadLibrary ( TEXT("bb.dll") ); + if ( !hdll ) { + cerr << "ERROR: unable to open bb.dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + // get function pointers: + get_n_dll = (GET_NM)GetProcAddress(hdll, "GET_N"); + if ( !get_n_dll ) { + cerr << "ERROR: unable to find GET_N function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + get_m_dll = (GET_NM)GetProcAddress(hdll, "GET_M"); + if ( !get_m_dll ) { + cerr << "ERROR: unable to find GET_M function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + eval_x_dll = (EVAL_X)GetProcAddress(hdll, "EVAL_X"); + if ( !eval_x_dll ) { + cerr << "ERROR: unable to find EVAL_X function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + /* init_dll = (INIT)GetProcAddress(hdll, "INIT"); + if ( !init_dll ) { + cerr << "ERROR: unable to find INIT function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + } + + clear_dll = (INIT)GetProcAddress(hdll, "CLEAR"); + if ( !clear_dll ) { + cerr << "ERROR: unable to find CLEAR function in dll" << endl; + FreeLibrary ( hdll ); + return 1; + }*/ + + // MADS: + try { + + /* init_dll(); */ + + int n = get_n_dll(); + int m = get_m_dll(); + + // parameters creation: + // -------------------- + Parameters p ( out ); + + // dimension: + p.set_DIMENSION ( n ); + + // definition of output types: + vector<bb_output_type> bbot (m); + bbot[0] = OBJ; + for ( int i = 1 ; i < m ; ++i ) + bbot[i] = PB; + p.set_BB_OUTPUT_TYPE ( bbot ); + + // read parameters file: + p.read ( argv[1] ); + + // parameters check: + p.check(); + + // display parameters: + // out << p << endl; + + // custom evaluator creation: + My_Evaluator ev ( p , n , m ); + + // algorithm creation and execution: + Mads mads ( p , &ev ); + mads.run(); + + // algorithm display: + // out << mads << endl; + + /* clear_dll(); */ + } + catch ( exception & e ) { + cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; + } + + // Release the Dll: + FreeLibrary ( hdll ); + + NOMAD::Slave::stop_slaves ( out ); + NOMAD::end(); + + return EXIT_SUCCESS; +} diff --git a/examples/interfaces/DLL/single_obj/parameters.txt b/examples/interfaces/DLL/single_obj/param.txt similarity index 92% rename from examples/interfaces/DLL/single_obj/parameters.txt rename to examples/interfaces/DLL/single_obj/param.txt index 42f7a6f39e4b373dfed15ceaaded67886883dcfd..ddbb51136f2cde23be9a7e425f27e43467ca3212 100755 --- a/examples/interfaces/DLL/single_obj/parameters.txt +++ b/examples/interfaces/DLL/single_obj/param.txt @@ -1,27 +1,27 @@ -#seed 100 - -initial_mesh_size r0.1 - -direction_type ortho 2n - -max_bb_eval 1000 - -lower_bound * -10.0 - -upper_bound * 10.0 - - -x0 ( 2 3 4 5 6 ) - -display_degree 1 - -display_stats bbe ( sol ) obj - -add_seed_to_file_names no - -#stats_file toto.txt bbe obj -#solution_file "sol.txt" - -#LH_SEARCH 100 0 - -#OPPORTUNISTIC_LH no +#seed 100 + +initial_mesh_size r0.1 + +direction_type ortho 2n + +max_bb_eval 1000 + +lower_bound * -10.0 + +upper_bound * 10.0 + + +x0 ( 2 3 4 5 6 ) + +display_degree 1 + +display_stats bbe ( sol ) obj + +add_seed_to_file_names no + +#stats_file toto.txt bbe obj +#solution_file "sol.txt" + +#LH_SEARCH 100 0 + +#OPPORTUNISTIC_LH no diff --git a/examples/interfaces/DLL/single_obj/readme.txt b/examples/interfaces/DLL/single_obj/readme.txt index 7c139cb507eac426a6d206cbdd5be6005e25881c..970c9be4a48c4892f02971a617270e3bd19faa34 100755 --- a/examples/interfaces/DLL/single_obj/readme.txt +++ b/examples/interfaces/DLL/single_obj/readme.txt @@ -1,52 +1,52 @@ - -This example illustrates how to use NOMAD with a black-box -problem that is coded inside a DLL file. - -The example runs on windows with visual C++ and minGW. - - -DLL characteristics: - -/*----------*/ - -/* bb.dll */ - -/*----------*/ - - - -// init/clear: - -// ----------- - -void init_dll ( void ); - -void clear_dll ( void ); - -// problem characteristics: - -// ------------------------ - - -int get_n_dll ( void ); // number of variables - -int get_m _dll( void ); // number of outputs: output #0 : objective value to minimize - - // output #1..m-1: PB constraints with format g(x) <= 0 - - - -// evaluation: f(x): - -// ----------------- - - -void eval_x_dll ( double * x , double * fx , bool & count_eval ); - - - -// x: input , double array of size n - -// fx: output, double array of size m - -// count_eval: output, set to true if the evaluation has to be counted, false else + +This example illustrates how to use NOMAD with a black-box +problem that is coded inside a DLL file. + +The example runs on windows with visual C++ and minGW. + + +DLL characteristics: + +/*----------*/ + +/* bb.dll */ + +/*----------*/ + + + +// init/clear: + +// ----------- + +void init_dll ( void ); + +void clear_dll ( void ); + +// problem characteristics: + +// ------------------------ + + +int get_n_dll ( void ); // number of variables + +int get_m _dll( void ); // number of outputs: output #0 : objective value to minimize + + // output #1..m-1: PB constraints with format g(x) <= 0 + + + +// evaluation: f(x): + +// ----------------- + + +void eval_x_dll ( double * x , double * fx , bool & count_eval ); + + + +// x: input , double array of size n + +// fx: output, double array of size m + +// count_eval: output, set to true if the evaluation has to be counted, false else diff --git a/examples/interfaces/GAMS/bb.gms b/examples/interfaces/GAMS/bb.gms index a68edb863bd70b2234b378f573dc87c7ac52f88c..7659730934efac3d55c21914ce54fdfcd276f3ec 100644 --- a/examples/interfaces/GAMS/bb.gms +++ b/examples/interfaces/GAMS/bb.gms @@ -1,321 +1,321 @@ - -Set t time periods -/ -2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095, -2105, 2115, 2125, 2135, 2145, 2155, 2165, 2175, 2185, 2195, -2205, 2215, 2225, 2235, 2245, 2255, 2265, 2275, 2285, 2295, -2305, 2315, 2325, 2335, 2345, 2355, 2365, 2375, 2385, 2395, -2405 -/ - -subtGDP(t) indice sommation GDP -/ -2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095 -/ - -subtem(t) indice sommation emissions -/ -2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085 -/ -; - -Set ts(t) time periods -/ -2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095, -2105, 2115, 2125, 2135, 2145, 2155, 2165, 2175, 2185, 2195, -2205, 2215, 2225, 2235, 2245, 2255, 2265, 2275, 2285, 2295, -2305, 2315, 2325, 2335, 2345, 2355, 2365, 2375, 2385, 2395, -2405 -/; - -Set tfirst(t) first time period; -tfirst(t) = YES$(ord(t) eq 1); - -Set tlast(t) last time period; -tlast(t) = YES$(ord(t) eq card(t)); - -Parameter nbp(t) number of periods since 2005 -/ - 2005 0, 2015 1, 2025 2, 2035 3, 2045 4, 2055 5, 2065 6, 2075 7, 2085 8, - 2095 9, 2105 10, 2115 11, 2125 12, 2135 13, 2145 14, 2155 15, 2165 16, - 2175 17, 2185 18, 2195 19, 2205 20, 2215 21, 2225 22, 2235 23, 2245 24, - 2255 25, 2265 26, 2275 27, 2285 28, 2295 29, 2305 30, 2315 31, 2325 32, - 2335 33, 2345 34, 2355 35, 2365 36, 2375 37, 2385 38, 2395 39, 2405 40 -/; - -Parameter nby(t) number of years since 2005 -/ - 2005 0, 2015 10, 2025 20, 2035 30, 2045 40, 2055 50, 2065 60, 2075 70, 2085 80, - 2095 90, 2105 100, 2115 110, 2125 120, 2135 130, 2145 140, 2155 150, 2165 160, - 2175 170, 2185 180, 2195 190, 2205 200, 2215 210, 2225 220, 2235 230, 2245 240, - 2255 250, 2265 260, 2275 270, 2285 280, 2295 290, 2305 300, 2315 310, 2325 320, - 2335 330, 2345 340, 2355 350, 2365 360, 2375 370, 2385 380, 2395 390, 2405 400 -/; - -Parameter xi(t) indicator for the clean economy -/ - 2005 1, 2015 1, 2025 1, 2035 1, 2045 1, 2055 1, 2065 1, 2075 1, 2085 1, - 2095 1, 2105 1, 2115 1, 2125 1, 2135 1, 2145 1, 2155 1, 2165 1, 2175 1, - 2185 1, 2195 1, 2205 1, 2215 1, 2225 1, 2235 1, 2245 1, 2255 1, 2265 1, - 2275 1, 2285 1, 2295 1, 2305 1, 2315 1, 2325 1, 2335 1, 2345 1, 2355 1, - 2365 1, 2375 1, 2385 1, 2395 1, 2405 1 -/; -$ontext -/ - 2005 0, 2015 0, 2025 0, 2035 0, 2045 0, 2055 0, 2065 0, 2075 0, 2085 0, - 2095 0, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, - 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, - 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, - 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 -/; -$offtext - -Parameter GDP(t) GDP donne par le scenario B2MESSAGE par moyenne simple -/ - 2005 49.84, 2015 66.53, 2025 86.94, 2035 112.9, 2045 145.3, 2055 182.0, 2065 220.7, 2075 259.1, 2085 295.5, - 2095 331.7, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, - 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, - 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, - 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 -/; - -Parameter emissionB2(t) emission CO2 par decennie donne par le scenario B2MESSAGE par moyenne simple -/ - 2005 8.65, 2015 9.19, 2025 9.88, 2035 10.57, 2045 11.05, 2055 11.40, 2065 11.72, 2075 12.18, 2085 12.76, - 2095 0, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, - 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, - 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, - 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 -/; - -Scalars - borneinf borne inferieure de DICE /0.9/ - bornesup borne superieure de DICE /1.1/ - deltaalpha ecart entre modeles DICE et GERAD /0/ - deltaGDP ecart DICE GERAD pour le GDP /0/ - deltaem idem /0/ - moyenneGDP moyenne GDP B2-message /175.05/ - moyenneem idem /10.82/ - - vb slope w.r.t K2(t) of the probability rate of discovery /0.0019/ - wb initial probability rate of discovery /0.05/ - beta marginal atmospheric retention rate /0.64/ - catM catastrophic carbon concentration /2059.0/ - delta_M carbon removal rate per decade /0.036/ -* mtargM target for carbon concentration /1025.00/ - mtargM target for carbon concentration /5000.00/ - piE1 initial energy price in dirty economy /0.35/ - piE2 initial energy price in clean economy /0.60/ - rhop discount rate /0.025/ - - prstp initial rate of social time preference per year /0.015/ - dr decline rate of social time preference per year /0.000001/ - rho discount rate /0.03/ - - L0 2005 world population (millions) /6409/ - gL0 initial value for growth rate of population /0.08/ - dgL rate of decrease for growth rate of population /0.3/ - - scale1 scaling coefficient in objective function /300/ - scale2 scaling coefficient in objective function /1.00E+07/ - -*Scalaires calibres -$include "input.txt"; - -; - -*Initialisation des parametres -Parameter L(t) labor - world population (millions); -L(t) = L0 * exp( (gl0/dgL)*(1-exp( -dgL*nbp(t) )) ); - -Parameter r(t) instantaeous rate of social time preference; -r(t)=prstp*EXP(-dr*10*(ord(t)-1)); - -Parameter rr(t) average utility social discount rate; -rr(tfirst)=1; -loop(t, rr(t+1) = rr(t) / ((1+r(t))**10) ); - -Parameter A(t) total factor productivity; -A(tfirst) = 1.38734*A0; -*loop(t, A(t+1) = A(t) / (1-gA0*exp(-dgA*10*nbp(t))) ); -A(t) = 1.38734*A0 * exp( (gA0/dgA)*(1-exp( -dgA*nbp(t) )) ); - -Parameter phid(t) energy efficiency in the dirty economy; -phid(t) = (phid0 * exp( (-gphid0/dgphid)*exp(-dgphid*(nbp(t)+1)) ) ) / - exp(-gphid0/dgphid); - -Parameter phic(t) energy efficiency in the clean economy; -phic(t) = (phic0 * exp( (-gphic0/dgphic)*exp(-dgphic*(nbp(t)+1)) ) ) / - exp(-gphic0/dgphic); - -Parameter thetad(t) dirty energy elasticity in production function; -thetad(t) = (thetad0 * exp( (gthetad0/dgthetad)*exp(-dgthetad*(nbp(t)+1)) ) ) / - exp(gthetad0/dgthetad); - -Parameter thetac(t) clean energy elasticity in production function; -thetac(t) = (thetac0 * exp( (gthetac0/dgthetac)*exp(-dgthetac*(nbp(t)+1)) ) ) / - exp(gthetac0/dgthetac); - -Parameter EM(t) total emissions (over 10 years); -EM(t) = 0; - -Parameter TK(t) total capital; -TK(t) = 0; - -Parameter deltaalphaGDP(t) ecart courant entre GDP de DICE et GERAD; -deltaalphaGDP(t) = 0; - -*Definition du modele -Positive variables - C(t) total consumption (trillion dollars) - ELF(t) economic loss factor (%) - E1(t) carbon emissions from the dirty economy (GtC) - E2(t) carbon emissions from the clean economy (GtC) - I1(t) investment in dirty capital K1 (trillion dollars) - I2(t) investment in clean capital K2 (trillion dollars) - K1(t) physical stock of dirty capital (trillion dollars) - K2(t) physical stock of clean capital (trillion dollars) - L1(t) labor for the dirty economy (millions) - L2(t) labor for the clean economy (millions) - M(t) atmospheric carbon concentration - Y(t) economic output (trillion dollars); - -Variables - PW(t) welfare of current period - W2 total discounted welfare after the last jump (V_2-1-l); - -Equations - ALOCLABOR(t) compute allocation of total labor - CARBDYNAM(t) compute evolution of carbon concentrations - E1FIRST(t) initial value for carbon emissions from dirty capital - E2FIRST(t) initial value for carbon emissions from clean capital - ELFCOMP(t) compute economic loss factor - I2MAX(t) bound for investment on clean capital - K1ACCUMUL(t) compute dirty capital accumulation - K1FIRST(t) initial value for dirty capital - K1LAST(t) final value for dirty capital - K2ACCUMUL(t) compute clean capital accumulation - K2FIRST(t) initial value for clean capital - K2LAST(t) final value for clean capital - MFIRST(t) initial value for carbon concentration - TARGETM(t) impose cap on atmospheric carbon concentrations - TOTALCONS(t) compute total consumption - TOTALPROD(t) compute total production - PWEQ(t) compute welfare of current period - WELFARE2 compute total welfare after the last jump; - -ALOCLABOR(t).. - L1(t) + L2(t) =l= L(t); - -CARBDYNAM(t+1).. - M(t+1) =e= beta*10*(E1(t)+E2(t)) + M(t)*(1-delta_M) + delta_M*590; - -MFIRST(tfirst).. -* 2005 value around 385 ppmv = 808.8 GtC - M(tfirst) =e= 808.8; - -ELFCOMP(t).. - ELF(t) =e= 1; - -E1FIRST(tfirst).. -* DICE-2007 value - E1(tfirst) =e= 6.7; - -E2FIRST(tfirst).. -* 0.0001 of DICE-2007 value - E2(tfirst) =e= 0.00067; - -I2MAX(t).. - I2(t) =l= 0.97*Y(t); - -K1FIRST(tfirst).. - K1(tfirst) =e= 137.0; - -K1ACCUMUL(t).. - K1(t+1) =l= K1(t)*(1-dk)**10 + 10*I1(t); - -K1LAST(tlast).. - 0.02*K1(tlast) =l= I1(tlast); - -K2FIRST(tfirst).. - K2(tfirst) =e= 0.0137; - -K2ACCUMUL(t).. - K2(t+1) =l= K2(t)*(1-dk)**10 + 10*I2(t); - -K2LAST(tlast).. - 0.02*K2(tlast) =l= I2(tlast); - -TARGETM(t).. -* Constraint is always active - M(t) =l= mtargM; - -TOTALPROD(t).. - Y(t) =e= A(t) * ( - K1(t)**alphad * (phid(t)*E1(t))**thetad(t) * L1(t)**(1-alphad-thetad(t)) + - xi(t)*K2(t)**alphac * (phic(t)*E2(t))**thetac(t) * L2(t)**(1-alphac-thetac(t)) - ); - -TOTALCONS(t).. - C(t) =e= Y(t) - I1(t) - I2(t) - piE1*phid(t)*E1(t) - piE2*phic(t)*E2(t); - -PWEQ(t).. - PW(t) =e= ( (ELF(t)*C(t)/L(t))**(1-elasmu) -1) / (1-elasmu); - -WELFARE2.. - W2 =e= sum(t, 10*exp(-rho*nby(t))*L(t)*(PW(t))/scale1) + scale2 ; - -Model ECM /all/ ; -ECM.OPTFILE =1; - -C.lo(t) = 1; -C.up(t) = 1000; -E1.lo(t) = 0.0000001; -E1.up(t) = 500; -E2.lo(t) = 0.0000001; -E2.up(t) = 100; -ELF.lo(t) = 0.5; -ELF.up(t) = 1.0; -I1.lo(t) = 0.000000001; -I1.up(t) = 1000; -I2.lo(t) = 0.000000001; -I2.up(t) = 1000; -K1.lo(t) = 0.01; -K1.up(t) = 3000; -K2.lo(t) = 0.000000001; -K2.up(t) = 3000; -L1.lo(t) = 0.1; -L1.up(t) = 10000; -L2.lo(t) = 0.000000001; -L2.up(t) = 10000; -M.lo(t) = 300; -M.up(t) = 4000; -Y.lo(t) = 50; -Y.up(t) = 1000; - -option iterlim = 99900; -option reslim = 99999; -option solprint = off; -option limrow = 0; -option limcol = 0; - -Solve ECM using nlp maximising W2; - -EM(t) = E1.L(t)+E2.L(t); -TK(t) = K1.L(t)+K2.L(t); - -deltaalphaGDP(t) = Y.L(t)-GDP(t); -deltaGDP = sum ( subtGDP(t) , sqr(deltaalphaGDP(t)) ); -deltaem = sum ( subtem(t) , sqr(EM(t)-emissionB2(t)) ); -deltaalpha = deltaGDP / moyenneGDP + deltaem / moyenneem ; - -file FOUT / output.txt /; -put FOUT; -put deltaalpha:13:6; -putclose; - - - - - - + +Set t time periods +/ +2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095, +2105, 2115, 2125, 2135, 2145, 2155, 2165, 2175, 2185, 2195, +2205, 2215, 2225, 2235, 2245, 2255, 2265, 2275, 2285, 2295, +2305, 2315, 2325, 2335, 2345, 2355, 2365, 2375, 2385, 2395, +2405 +/ + +subtGDP(t) indice sommation GDP +/ +2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095 +/ + +subtem(t) indice sommation emissions +/ +2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085 +/ +; + +Set ts(t) time periods +/ +2005, 2015, 2025, 2035, 2045, 2055, 2065, 2075, 2085, 2095, +2105, 2115, 2125, 2135, 2145, 2155, 2165, 2175, 2185, 2195, +2205, 2215, 2225, 2235, 2245, 2255, 2265, 2275, 2285, 2295, +2305, 2315, 2325, 2335, 2345, 2355, 2365, 2375, 2385, 2395, +2405 +/; + +Set tfirst(t) first time period; +tfirst(t) = YES$(ord(t) eq 1); + +Set tlast(t) last time period; +tlast(t) = YES$(ord(t) eq card(t)); + +Parameter nbp(t) number of periods since 2005 +/ + 2005 0, 2015 1, 2025 2, 2035 3, 2045 4, 2055 5, 2065 6, 2075 7, 2085 8, + 2095 9, 2105 10, 2115 11, 2125 12, 2135 13, 2145 14, 2155 15, 2165 16, + 2175 17, 2185 18, 2195 19, 2205 20, 2215 21, 2225 22, 2235 23, 2245 24, + 2255 25, 2265 26, 2275 27, 2285 28, 2295 29, 2305 30, 2315 31, 2325 32, + 2335 33, 2345 34, 2355 35, 2365 36, 2375 37, 2385 38, 2395 39, 2405 40 +/; + +Parameter nby(t) number of years since 2005 +/ + 2005 0, 2015 10, 2025 20, 2035 30, 2045 40, 2055 50, 2065 60, 2075 70, 2085 80, + 2095 90, 2105 100, 2115 110, 2125 120, 2135 130, 2145 140, 2155 150, 2165 160, + 2175 170, 2185 180, 2195 190, 2205 200, 2215 210, 2225 220, 2235 230, 2245 240, + 2255 250, 2265 260, 2275 270, 2285 280, 2295 290, 2305 300, 2315 310, 2325 320, + 2335 330, 2345 340, 2355 350, 2365 360, 2375 370, 2385 380, 2395 390, 2405 400 +/; + +Parameter xi(t) indicator for the clean economy +/ + 2005 1, 2015 1, 2025 1, 2035 1, 2045 1, 2055 1, 2065 1, 2075 1, 2085 1, + 2095 1, 2105 1, 2115 1, 2125 1, 2135 1, 2145 1, 2155 1, 2165 1, 2175 1, + 2185 1, 2195 1, 2205 1, 2215 1, 2225 1, 2235 1, 2245 1, 2255 1, 2265 1, + 2275 1, 2285 1, 2295 1, 2305 1, 2315 1, 2325 1, 2335 1, 2345 1, 2355 1, + 2365 1, 2375 1, 2385 1, 2395 1, 2405 1 +/; +$ontext +/ + 2005 0, 2015 0, 2025 0, 2035 0, 2045 0, 2055 0, 2065 0, 2075 0, 2085 0, + 2095 0, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, + 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, + 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, + 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 +/; +$offtext + +Parameter GDP(t) GDP donne par le scenario B2MESSAGE par moyenne simple +/ + 2005 49.84, 2015 66.53, 2025 86.94, 2035 112.9, 2045 145.3, 2055 182.0, 2065 220.7, 2075 259.1, 2085 295.5, + 2095 331.7, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, + 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, + 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, + 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 +/; + +Parameter emissionB2(t) emission CO2 par decennie donne par le scenario B2MESSAGE par moyenne simple +/ + 2005 8.65, 2015 9.19, 2025 9.88, 2035 10.57, 2045 11.05, 2055 11.40, 2065 11.72, 2075 12.18, 2085 12.76, + 2095 0, 2105 0, 2115 0, 2125 0, 2135 0, 2145 0, 2155 0, 2165 0, 2175 0, + 2185 0, 2195 0, 2205 0, 2215 0, 2225 0, 2235 0, 2245 0, 2255 0, 2265 0, + 2275 0, 2285 0, 2295 0, 2305 0, 2315 0, 2325 0, 2335 0, 2345 0, 2355 0, + 2365 0, 2375 0, 2385 0, 2395 0, 2405 0 +/; + +Scalars + borneinf borne inferieure de DICE /0.9/ + bornesup borne superieure de DICE /1.1/ + deltaalpha ecart entre modeles DICE et GERAD /0/ + deltaGDP ecart DICE GERAD pour le GDP /0/ + deltaem idem /0/ + moyenneGDP moyenne GDP B2-message /175.05/ + moyenneem idem /10.82/ + + vb slope w.r.t K2(t) of the probability rate of discovery /0.0019/ + wb initial probability rate of discovery /0.05/ + beta marginal atmospheric retention rate /0.64/ + catM catastrophic carbon concentration /2059.0/ + delta_M carbon removal rate per decade /0.036/ +* mtargM target for carbon concentration /1025.00/ + mtargM target for carbon concentration /5000.00/ + piE1 initial energy price in dirty economy /0.35/ + piE2 initial energy price in clean economy /0.60/ + rhop discount rate /0.025/ + + prstp initial rate of social time preference per year /0.015/ + dr decline rate of social time preference per year /0.000001/ + rho discount rate /0.03/ + + L0 2005 world population (millions) /6409/ + gL0 initial value for growth rate of population /0.08/ + dgL rate of decrease for growth rate of population /0.3/ + + scale1 scaling coefficient in objective function /300/ + scale2 scaling coefficient in objective function /1.00E+07/ + +*Scalaires calibres +$include "input.txt"; + +; + +*Initialisation des parametres +Parameter L(t) labor - world population (millions); +L(t) = L0 * exp( (gl0/dgL)*(1-exp( -dgL*nbp(t) )) ); + +Parameter r(t) instantaeous rate of social time preference; +r(t)=prstp*EXP(-dr*10*(ord(t)-1)); + +Parameter rr(t) average utility social discount rate; +rr(tfirst)=1; +loop(t, rr(t+1) = rr(t) / ((1+r(t))**10) ); + +Parameter A(t) total factor productivity; +A(tfirst) = 1.38734*A0; +*loop(t, A(t+1) = A(t) / (1-gA0*exp(-dgA*10*nbp(t))) ); +A(t) = 1.38734*A0 * exp( (gA0/dgA)*(1-exp( -dgA*nbp(t) )) ); + +Parameter phid(t) energy efficiency in the dirty economy; +phid(t) = (phid0 * exp( (-gphid0/dgphid)*exp(-dgphid*(nbp(t)+1)) ) ) / + exp(-gphid0/dgphid); + +Parameter phic(t) energy efficiency in the clean economy; +phic(t) = (phic0 * exp( (-gphic0/dgphic)*exp(-dgphic*(nbp(t)+1)) ) ) / + exp(-gphic0/dgphic); + +Parameter thetad(t) dirty energy elasticity in production function; +thetad(t) = (thetad0 * exp( (gthetad0/dgthetad)*exp(-dgthetad*(nbp(t)+1)) ) ) / + exp(gthetad0/dgthetad); + +Parameter thetac(t) clean energy elasticity in production function; +thetac(t) = (thetac0 * exp( (gthetac0/dgthetac)*exp(-dgthetac*(nbp(t)+1)) ) ) / + exp(gthetac0/dgthetac); + +Parameter EM(t) total emissions (over 10 years); +EM(t) = 0; + +Parameter TK(t) total capital; +TK(t) = 0; + +Parameter deltaalphaGDP(t) ecart courant entre GDP de DICE et GERAD; +deltaalphaGDP(t) = 0; + +*Definition du modele +Positive variables + C(t) total consumption (trillion dollars) + ELF(t) economic loss factor (%) + E1(t) carbon emissions from the dirty economy (GtC) + E2(t) carbon emissions from the clean economy (GtC) + I1(t) investment in dirty capital K1 (trillion dollars) + I2(t) investment in clean capital K2 (trillion dollars) + K1(t) physical stock of dirty capital (trillion dollars) + K2(t) physical stock of clean capital (trillion dollars) + L1(t) labor for the dirty economy (millions) + L2(t) labor for the clean economy (millions) + M(t) atmospheric carbon concentration + Y(t) economic output (trillion dollars); + +Variables + PW(t) welfare of current period + W2 total discounted welfare after the last jump (V_2-1-l); + +Equations + ALOCLABOR(t) compute allocation of total labor + CARBDYNAM(t) compute evolution of carbon concentrations + E1FIRST(t) initial value for carbon emissions from dirty capital + E2FIRST(t) initial value for carbon emissions from clean capital + ELFCOMP(t) compute economic loss factor + I2MAX(t) bound for investment on clean capital + K1ACCUMUL(t) compute dirty capital accumulation + K1FIRST(t) initial value for dirty capital + K1LAST(t) final value for dirty capital + K2ACCUMUL(t) compute clean capital accumulation + K2FIRST(t) initial value for clean capital + K2LAST(t) final value for clean capital + MFIRST(t) initial value for carbon concentration + TARGETM(t) impose cap on atmospheric carbon concentrations + TOTALCONS(t) compute total consumption + TOTALPROD(t) compute total production + PWEQ(t) compute welfare of current period + WELFARE2 compute total welfare after the last jump; + +ALOCLABOR(t).. + L1(t) + L2(t) =l= L(t); + +CARBDYNAM(t+1).. + M(t+1) =e= beta*10*(E1(t)+E2(t)) + M(t)*(1-delta_M) + delta_M*590; + +MFIRST(tfirst).. +* 2005 value around 385 ppmv = 808.8 GtC + M(tfirst) =e= 808.8; + +ELFCOMP(t).. + ELF(t) =e= 1; + +E1FIRST(tfirst).. +* DICE-2007 value + E1(tfirst) =e= 6.7; + +E2FIRST(tfirst).. +* 0.0001 of DICE-2007 value + E2(tfirst) =e= 0.00067; + +I2MAX(t).. + I2(t) =l= 0.97*Y(t); + +K1FIRST(tfirst).. + K1(tfirst) =e= 137.0; + +K1ACCUMUL(t).. + K1(t+1) =l= K1(t)*(1-dk)**10 + 10*I1(t); + +K1LAST(tlast).. + 0.02*K1(tlast) =l= I1(tlast); + +K2FIRST(tfirst).. + K2(tfirst) =e= 0.0137; + +K2ACCUMUL(t).. + K2(t+1) =l= K2(t)*(1-dk)**10 + 10*I2(t); + +K2LAST(tlast).. + 0.02*K2(tlast) =l= I2(tlast); + +TARGETM(t).. +* Constraint is always active + M(t) =l= mtargM; + +TOTALPROD(t).. + Y(t) =e= A(t) * ( + K1(t)**alphad * (phid(t)*E1(t))**thetad(t) * L1(t)**(1-alphad-thetad(t)) + + xi(t)*K2(t)**alphac * (phic(t)*E2(t))**thetac(t) * L2(t)**(1-alphac-thetac(t)) + ); + +TOTALCONS(t).. + C(t) =e= Y(t) - I1(t) - I2(t) - piE1*phid(t)*E1(t) - piE2*phic(t)*E2(t); + +PWEQ(t).. + PW(t) =e= ( (ELF(t)*C(t)/L(t))**(1-elasmu) -1) / (1-elasmu); + +WELFARE2.. + W2 =e= sum(t, 10*exp(-rho*nby(t))*L(t)*(PW(t))/scale1) + scale2 ; + +Model ECM /all/ ; +ECM.OPTFILE =1; + +C.lo(t) = 1; +C.up(t) = 1000; +E1.lo(t) = 0.0000001; +E1.up(t) = 500; +E2.lo(t) = 0.0000001; +E2.up(t) = 100; +ELF.lo(t) = 0.5; +ELF.up(t) = 1.0; +I1.lo(t) = 0.000000001; +I1.up(t) = 1000; +I2.lo(t) = 0.000000001; +I2.up(t) = 1000; +K1.lo(t) = 0.01; +K1.up(t) = 3000; +K2.lo(t) = 0.000000001; +K2.up(t) = 3000; +L1.lo(t) = 0.1; +L1.up(t) = 10000; +L2.lo(t) = 0.000000001; +L2.up(t) = 10000; +M.lo(t) = 300; +M.up(t) = 4000; +Y.lo(t) = 50; +Y.up(t) = 1000; + +option iterlim = 99900; +option reslim = 99999; +option solprint = off; +option limrow = 0; +option limcol = 0; + +Solve ECM using nlp maximising W2; + +EM(t) = E1.L(t)+E2.L(t); +TK(t) = K1.L(t)+K2.L(t); + +deltaalphaGDP(t) = Y.L(t)-GDP(t); +deltaGDP = sum ( subtGDP(t) , sqr(deltaalphaGDP(t)) ); +deltaem = sum ( subtem(t) , sqr(EM(t)-emissionB2(t)) ); +deltaalpha = deltaGDP / moyenneGDP + deltaem / moyenneem ; + +file FOUT / output.txt /; +put FOUT; +put deltaalpha:13:6; +putclose; + + + + + + diff --git a/examples/interfaces/GAMS/ed.hup b/examples/interfaces/GAMS/ed.hup index 85bca40488933e73f8614918ade854de303c9f6c..4cce1c4b0d1d384570ec7a81ccad22e6b6f4342d 100644 --- a/examples/interfaces/GAMS/ed.hup +++ b/examples/interfaces/GAMS/ed.hup @@ -1,13 +1,13 @@ - -This example illustrates how to use NOMAD with a GAMS black-box problem. - -The example runs on windows. - -The GAMS program is located in file bb.gms. - -The source code is in bb.cpp: it is a C++ wrapper that calls GAMS. -It can be compiled with visual C++ or minGW. - -The wrapper can be tested with the command 'bb.exe .\points\x0.txt'. - + +This example illustrates how to use NOMAD with a GAMS black-box problem. + +The example runs on windows. + +The GAMS program is located in file bb.gms. + +The source code is in bb.cpp: it is a C++ wrapper that calls GAMS. +It can be compiled with visual C++ or minGW. + +The wrapper can be tested with the command 'bb.exe .\points\x0.txt'. + Once the wrapper is compiled, use nomad with the parameters file parameters.txt. diff --git a/examples/interfaces/GAMS/lb.txt b/examples/interfaces/GAMS/lb.txt index a45ca61fa42c48388f5b15c92a96c752d2a95fb5..542b27db608f1312c27447e2a16a06d64772038b 100644 --- a/examples/interfaces/GAMS/lb.txt +++ b/examples/interfaces/GAMS/lb.txt @@ -1,19 +1,19 @@ -2.25 -0.027 -0.09 -0.18 -0.27 -0.27 -0.09 -0.9 -0.13 -0.27 -4.5 -0.13 -0.27 -0.045 -0 -0.007 -0.045 -0 +2.25 +0.027 +0.09 +0.18 +0.27 +0.27 +0.09 +0.9 +0.13 +0.27 +4.5 +0.13 +0.27 +0.045 +0 +0.007 +0.045 +0 0.007 \ No newline at end of file diff --git a/examples/interfaces/GAMS/parameters.txt b/examples/interfaces/GAMS/param.txt similarity index 94% rename from examples/interfaces/GAMS/parameters.txt rename to examples/interfaces/GAMS/param.txt index 62b72799943358931577ffad3d2f001fcd6d0a06..0c41dfa48c59e878e289c77051a276a345c7efac 100644 --- a/examples/interfaces/GAMS/parameters.txt +++ b/examples/interfaces/GAMS/param.txt @@ -1,31 +1,31 @@ ##### # NOMAD PARAMETERS # -#### +#### - -SEED NONE - -DIMENSION 19 -DISPLAY_DEGREE 1 -DISPLAY_STATS BBE OBJ -BB_EXE bb.exe +SEED NONE -BB_OUTPUT_TYPE OBJ +DIMENSION 19 +DISPLAY_DEGREE 1 +DISPLAY_STATS BBE OBJ -BB_INPUT_INCLUDE_SEED yes +BB_EXE bb.exe -BB_INPUT_INCLUDE_TAG yes +BB_OUTPUT_TYPE OBJ - +BB_INPUT_INCLUDE_SEED yes +BB_INPUT_INCLUDE_TAG yes -x0 x0.txt -lower_bound lb.txt -upper_bound ub.txt - + + +x0 x0.txt +lower_bound lb.txt + +upper_bound ub.txt + diff --git a/examples/interfaces/GAMS/points/x0.txt b/examples/interfaces/GAMS/points/x0.txt index d7b79a8906c82f586a2f24738a26d8b662fc9eca..d99f74ea0c3ddc86b453f7f4e8e4ee289dabbd87 100644 --- a/examples/interfaces/GAMS/points/x0.txt +++ b/examples/interfaces/GAMS/points/x0.txt @@ -1,22 +1,22 @@ -0 0 +0 0 2.5 - + 0.0302 - -0.1 -0.2 -0.3 -0.3 -0.1 -1.0 -0.15 -0.3 -5.0 -0.15 -0.3 -0.05 -0 -0.008 -0.05 -0 + +0.1 +0.2 +0.3 +0.3 +0.1 +1.0 +0.15 +0.3 +5.0 +0.15 +0.3 +0.05 +0 +0.008 +0.05 +0 0.008 \ No newline at end of file diff --git a/examples/interfaces/GAMS/points/x1.txt b/examples/interfaces/GAMS/points/x1.txt index d1a6bea77617e99533557a9a7c3e957f70a8cde1..1e6f158f2db1bdba38142513cda9865553033467 100644 --- a/examples/interfaces/GAMS/points/x1.txt +++ b/examples/interfaces/GAMS/points/x1.txt @@ -1,20 +1,20 @@ -0 0 -2.25 -0.027 -0.09 -0.18 -0.27 -0.27 -0.09 -0.9 -0.13 -0.27 -4.5 -0.13 -0.27 -0.045 -0 -0.007 -0.045 -0 +0 0 +2.25 +0.027 +0.09 +0.18 +0.27 +0.27 +0.09 +0.9 +0.13 +0.27 +4.5 +0.13 +0.27 +0.045 +0 +0.007 +0.045 +0 0.007 \ No newline at end of file diff --git a/examples/interfaces/GAMS/points/x2.txt b/examples/interfaces/GAMS/points/x2.txt index bdf4951e594d278de2d68bf5096d69f917bd4b1d..3242adc86ece9d1a0014d01212ad4afb33d5e29d 100644 --- a/examples/interfaces/GAMS/points/x2.txt +++ b/examples/interfaces/GAMS/points/x2.txt @@ -1,25 +1,25 @@ -0 0 +0 0 2.75 - -0.033 + +0.033 0.11 - + 0.22 - + 0.33 - + 0.33 - -0.11 -1.1 -0.17 -0.33 -5.5 -0.17 -0.33 -0.055 -0.5 -0.009 -0.055 -0.5 + +0.11 +1.1 +0.17 +0.33 +5.5 +0.17 +0.33 +0.055 +0.5 +0.009 +0.055 +0.5 0.009 \ No newline at end of file diff --git a/examples/interfaces/GAMS/readme.txt b/examples/interfaces/GAMS/readme.txt index 390c172f45a629bcf57d17debf701ca75187935c..4cce1c4b0d1d384570ec7a81ccad22e6b6f4342d 100644 --- a/examples/interfaces/GAMS/readme.txt +++ b/examples/interfaces/GAMS/readme.txt @@ -1,13 +1,13 @@ - -This example illustrates how to use NOMAD with a GAMS black-box problem. - -The example runs on windows. - -The GAMS program is located in file bb.gms. - -The source code is in bb.cpp: it is a C++ wrapper that calls GAMS. -It can be compiled with visual C++ or minGW. - -The wrapper can be tested with the command 'bb.exe .\points\x0.txt'. - -Once the wrapper is compiled, use nomad with the parameters file parameters.txt. + +This example illustrates how to use NOMAD with a GAMS black-box problem. + +The example runs on windows. + +The GAMS program is located in file bb.gms. + +The source code is in bb.cpp: it is a C++ wrapper that calls GAMS. +It can be compiled with visual C++ or minGW. + +The wrapper can be tested with the command 'bb.exe .\points\x0.txt'. + +Once the wrapper is compiled, use nomad with the parameters file parameters.txt. diff --git a/examples/interfaces/GAMS/ub.txt b/examples/interfaces/GAMS/ub.txt index b54338208aed9fe01c3b0611cd99c515ac9e7003..025836ad2c955c6d33d60b8353a1ea07d4c653c1 100644 --- a/examples/interfaces/GAMS/ub.txt +++ b/examples/interfaces/GAMS/ub.txt @@ -1,24 +1,24 @@ 2.75 - -0.033 + +0.033 0.11 - + 0.22 - + 0.33 - + 0.33 - -0.11 -1.1 -0.17 -0.33 -5.5 -0.17 -0.33 -0.055 -0.5 -0.009 -0.055 -0.5 + +0.11 +1.1 +0.17 +0.33 +5.5 +0.17 +0.33 +0.055 +0.5 +0.009 +0.055 +0.5 0.009 \ No newline at end of file diff --git a/examples/interfaces/GAMS/x0.txt b/examples/interfaces/GAMS/x0.txt index b6b39746c3362f21fb359f7f16f17c1f0edb6c82..e82d42d29d8c35d9663f0985db9548c959213dad 100644 --- a/examples/interfaces/GAMS/x0.txt +++ b/examples/interfaces/GAMS/x0.txt @@ -1,21 +1,21 @@ 2.5 - + 0.0302 - -0.1 -0.2 -0.3 -0.3 -0.1 -1.0 -0.15 -0.3 -5.0 -0.15 -0.3 -0.05 -0 -0.008 -0.05 -0 + +0.1 +0.2 +0.3 +0.3 +0.1 +1.0 +0.15 +0.3 +5.0 +0.15 +0.3 +0.05 +0 +0.008 +0.05 +0 0.008 \ No newline at end of file diff --git a/examples/interfaces/Matlab_MEX/GERAD_NOMAD_build.m b/examples/interfaces/Matlab_MEX/GERAD_NOMAD_build.m new file mode 100644 index 0000000000000000000000000000000000000000..36eee6c55f9768c7686e808a43f7d671d2ad41b3 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/GERAD_NOMAD_build.m @@ -0,0 +1,79 @@ +%% GERAD NOMAD Build for Matlab + +% This file will help you compile NOMAD for use with MATLAB. + +% To recompile you will need to get / do the following: + +% 1) Get NOMAD +% NOMAD is available from http://www.gerad.ca/NOMAD/PHP_Forms/Download.php. +% Complete the download form then download the latest version. Define the +% $NOMAD_HOME environment variable. + +% 2) NOMAD MEX Interface +% The NOMAD MEX Interface is a simple MEX interface written to use NOMAD. + +% 3) Compile the MEX File +% The code below will build the NOMAD MEX file. Once you have completed all the +% above steps, simply run this file to compile NOMAD! You MUST BE in the +% base directory of OPTI! + +clear nomad + +switch(computer) +case 'PCWIN' +libdir = ' -Lwin32\'; +case 'PCWIN64' +libdir = ' -Lwin64\'; +case 'GLNX86' +libdir = 'glnx86/'; +case 'GLNXA64' +libdir = 'glnxa64/'; +case 'MACI64' +libdir = 'maci64/'; +end + +clear nomad_home nomad_src; + + +fprintf('\n------------------------------------------------\n'); +fprintf('NOMAD MEX FILE BUILD --- GERAD VERSION \n\n'); + +nomad_home = getenv('NOMAD_HOME'); +if (length(nomad_home)<1) + error('opti:nomad','Please set NOMAD_HOME variables properly with the command setenv(''NOMAD_HOME'',ARG1)!'); +end +nomad_src=[nomad_home filesep 'src' filesep]; + + +%Get NOMAD Libraries +post = [' -I. -I' nomad_src ' -lm -lut -output nomad']; + +%CD to Source Directory +cdir = cd; +cd 'Source'; + +%Compile & Move +pre = ['mex -v -g -largeArrayDims nomadmex.cpp ' nomad_src 'Parameters.cpp ' nomad_src 'Barrier.cpp ' nomad_src 'Cache.cpp '... +nomad_src 'Cache_File_Point.cpp ' nomad_src 'Cache_Point.cpp ' nomad_src 'Cache_Search.cpp ' nomad_src 'Clock.cpp '... +nomad_src 'Direction.cpp ' nomad_src 'Directions.cpp ' nomad_src 'Display.cpp '... +nomad_src 'Double.cpp ' nomad_src 'Eval_Point.cpp ' nomad_src 'Evaluator.cpp ' nomad_src 'Evaluator_Control.cpp ' nomad_src 'Exception.cpp '... +nomad_src 'Extended_Poll.cpp ' nomad_src 'L_Curve.cpp ' nomad_src 'LH_Search.cpp ' nomad_src 'OrthogonalMesh.cpp ' nomad_src 'Mads.cpp ' nomad_src 'Model_Sorted_Point.cpp '... +nomad_src 'Model_Stats.cpp ' nomad_src 'Multi_Obj_Evaluator.cpp ' nomad_src 'Parameter_Entries.cpp '... +nomad_src 'Parameter_Entry.cpp ' nomad_src 'Pareto_Front.cpp ' nomad_src 'Pareto_Point.cpp ' nomad_src 'Phase_One_Evaluator.cpp '... +nomad_src 'Phase_One_Search.cpp ' nomad_src 'Point.cpp ' nomad_src 'Priority_Eval_Point.cpp ' nomad_src 'Quad_Model.cpp '... +nomad_src 'Quad_Model_Evaluator.cpp ' nomad_src 'Quad_Model_Search.cpp ' nomad_src 'Random_Pickup.cpp ' nomad_src 'RNG.cpp '... +nomad_src 'Signature.cpp ' nomad_src 'Slave.cpp ' nomad_src 'SMesh.cpp ' nomad_src 'Speculative_Search.cpp ' nomad_src 'Stats.cpp ' nomad_src 'utils.cpp '... +nomad_src 'Variable_Group.cpp ' nomad_src 'VNS_Search.cpp ' nomad_src 'XMesh.cpp']; + +try + eval([pre post]) + movefile(['nomad.' mexext],['..' filesep],'f') + cd(cdir); + clear nomad_home nomad_src cdir post pre libdir; + fprintf('Done!\n'); +catch ME + cd(cdir); + clear nomad_home nomad_src cdir post pre libdir; + error('opti:nomad','Error Compiling NOMAD!\n%s',ME.message); +end +fprintf('------------------------------------------------\n'); diff --git a/examples/interfaces/Matlab_MEX/Source/nomadmex.cpp b/examples/interfaces/Matlab_MEX/Source/nomadmex.cpp new file mode 100755 index 0000000000000000000000000000000000000000..cd8f3ec8fb80da882155a01dd4b42ded4f0c2623 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/Source/nomadmex.cpp @@ -0,0 +1,1635 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search MATLAB Interface */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* MEX Interface Author: Jonathan Currie 2012 (I2C2) */ +/* */ +/* MEX Interface Contact information: */ +/* jocurrie@aut.ac.nz */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ + +#define NOMADMEX_VERSION "1.24_ct [feb 12, 2015]" +//NOTE from Version 1.15 on this MEX file contains a dual interface: + +// 1) The default (GERAD) interface is: +// [x,fval,exitflag,iter] = nomad(fun,x0,lb,ub,opts) + +// 2) Otherwise if OPTI_VERSION is defined it will compile the OPTI Toolbox interface: +// [x,fval,exitflag,iter] = nomad(fun,x0,lb,ub,nlcon,nlrhs,xtype,opts) + +// Both contain near identical functionality, except the GERAD version includes nonlinear +// constraints with the objective (blackbox) function. The OPTI version separates them, +// and allows a user specified rhs. The OPTI version also rounds x0 for integer constraints. + +#include "mex.h" +#include "nomad.hpp" +#include "defines.hpp" +#include <stdio.h> +#include <string.h> + +using namespace std; + + +//Function handle structure +#define FLEN 128 /* max length of user function name */ +#define MAXRHS 3 /* max nrhs for user function */ +typedef struct { + char f[FLEN]; + mxArray *plhs[1]; + mxArray *prhs[MAXRHS]; + int xrhs, nrhs; + double *nlrhs; +} usrFcn; + +typedef struct { + char f[FLEN]; + mxArray *plhs[1]; + mxArray *prhs[2]; + bool enabled; +} neighborsFcn; + + +//Iteration callback structure +typedef struct { + char f[FLEN]; + mxArray *plhs[1]; + mxArray *prhs[4]; + bool enabled; +} iter_fun_data; + +//Ctrl-C Detection +#ifdef __cplusplus +extern "C" bool utIsInterruptPending(); +extern "C" void utSetInterruptPending(bool); +#else +extern bool utIsInterruptPending(); +extern void utSetInterruptPending(bool); +#endif + +//Argument Enums (in expected order of arguments) +#ifdef OPTI_VERSION +enum {eFUN, eX0, eLB, eUB, eNLCON, eNLRHS, eXTYPE, eOPTS}; +#else //GERAD VERSION +enum {eFUN, eX0, eLB, eUB, eOPTS}; +enum {eNLCON, eNLRHS, eXTYPE}; //placeholders +#endif +//PRHS Defines +#define pFUN prhs[eFUN] +#define pX0 prhs[eX0] +#define pLB prhs[eLB] +#define pUB prhs[eUB] +#define pNLCON prhs[eNLCON] +#define pNLRHS prhs[eNLRHS] +#define pXTYPE prhs[eXTYPE] +#define pOPTS prhs[eOPTS] + +//Function Prototypes +void printSolverInfo(); +int checkInputs(const mxArray *prhs[], int nrhs, mxArray *plhs[], int nlhs); +vector<NOMAD::bb_input_type> detInTypes(char *xtype, size_t n); +vector<NOMAD::bb_output_type> detRetTypes(usrFcn *fun, mxArray *out_types, int *nobj, usrFcn *con, int *ncon, double *x0, size_t n); +void setNOMADopts(NOMAD::Parameters &p, const mxArray *opts); +bool isNMDOption(const char *field); +NOMAD::bb_output_type getOutEnum(char *str); +void lower(char *str); +double getStatus(int stat); + + +// Matlab Extended_Poll Class +/*--------------------------------------------------*/ +/* Class to define categorical neighborhoods */ +/*--------------------------------------------------*/ +class Matlab_Extended_Poll : public NOMAD::Extended_Poll +{ + +private: + + // signatures for 1 asset: + NOMAD::Signature * _s1; + + neighborsFcn * _neighbors; + + +public: + + Matlab_Extended_Poll ( NOMAD::Parameters & p , neighborsFcn * neighbors ); + + virtual ~Matlab_Extended_Poll ( void ){} + + // construct the extended poll points: + virtual void construct_extended_points ( const NOMAD::Eval_Point & ); + +}; + +/*-----------------------------------------*/ +/* constructor: creates the signature */ +/*-----------------------------------------*/ +Matlab_Extended_Poll::Matlab_Extended_Poll ( NOMAD::Parameters & p , neighborsFcn * neighbors) +: Extended_Poll ( p ) , +_s1 ( NULL ), +_neighbors ( neighbors ) +{ + _s1 = p.get_signature(); + +} + +/*--------------------------------------*/ +/* construct the extended poll points */ +/* (categorical neighborhoods) */ +/*--------------------------------------*/ +void Matlab_Extended_Poll::construct_extended_points ( const NOMAD::Eval_Point & x ) +{ + double *xm; + char errstr[1024]; + + if ( !x.is_complete() ) + { + mexWarnMsgTxt("construct_extended_points: bad extended poll center\n%sExiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + } + + + xm = mxGetPr(_neighbors->prhs[1]); + int n=_s1->get_n(); + + for(int i=0;i<n;i++) + xm[i] = x[i].value(); + + //Call MATLAB neighbors + try + { + mexCallMATLAB(1, _neighbors->plhs, 2, _neighbors->prhs, _neighbors->f); + } + //Note if these errors occur it is due to errors in MATLAB code, no way to recover? + catch(exception &e) + { + sprintf(errstr,"Unrecoverable Error from neighbors callback:\n%sExiting NOMAD...\n\n",e.what()); + mexWarnMsgTxt(errstr); + //Force exit + raise(SIGINT); + } + catch(...) + { + mexWarnMsgTxt("Unrecoverable Error from neighbors callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + } + + + size_t nbNPoints=mxGetNumberOfElements(_neighbors->plhs[0])/n; + double *xr=mxGetPr(_neighbors->plhs[0]); + + for(int i=0;i<nbNPoints;i++) + { + NOMAD::Point nPoint(n); + + for(int j=0;j<n;j++) + nPoint[j]=xr[i+j*nbNPoints]; + + add_extended_poll_point(nPoint , *_s1 ); + } + +} + + +//MATLAB Evaluator Class +class matlabEval : public NOMAD::Evaluator { +private: + usrFcn *fun; + bool hasSur; + int nobj; + usrFcn *con; + int ncon; + iter_fun_data *iterF; + int citer; + +public: + //Constructor + matlabEval(const NOMAD::Parameters &p, usrFcn *_obj, int _nobj, usrFcn *_con, int _ncon, iter_fun_data *_iterF) : NOMAD::Evaluator(p) + { + fun = _obj; + hasSur = p.has_sgte(); + nobj = _nobj; + con = _con; + ncon = _ncon; + iterF = _iterF; + citer = 0; + +#ifdef OPTI_VERSION + if(hasSur) + mexWarnMsgTxt("Optimization using surrogates is not available in OPTI version of NOMAD\n"); +#endif + } + //Destructor + ~matlabEval(void) {} + + + // evaluating a list of points + bool eval_x(std::list<NOMAD::Eval_Point *> &x, const NOMAD::Double &h_max, std::list<bool> & list_count_eval ) + { + +#ifdef OPTI_VERSION + mexPrintf("Optimization using block of points evaluation is not available in OPTI version of NOMAD\n"); + //Force exit + raise(SIGINT); + return false; +#endif + + + char errstr[1024]; + bool stop = false; + int i, j; + size_t m, n; + double *fvals; + mxLogical *sur; + + m=x.size(); + n=(*(x.begin()))->size(); + + if ( m !=list_count_eval.size()) + { + mexPrintf("NomadMex Evaluator: inconsistent size of list" ); + //Force exit + raise(SIGINT); + return false; + } + + + //Check for Ctrl-C + if (utIsInterruptPending()) + { + utSetInterruptPending(false); /* clear Ctrl-C status */ + mexPrintf("\nCtrl-C Detected. Exiting NOMAD...\n\n"); + list_count_eval.assign(m,false); + raise(SIGINT); + return false; + } + + + fun->prhs[fun->xrhs] = mxCreateDoubleMatrix(m, n, mxREAL); //x + double *List_x = mxGetPr(fun->prhs[fun->xrhs]); + std::list<NOMAD::Eval_Point *>::iterator it_x=x.begin(); + j=0; + for (it_x=x.begin();it_x!=x.end();++it_x,++j) + for(i=0;i<n;i++) + List_x[i*m+j] = (*(*it_x))[i].value(); + + + //Add Surrogate if present and requested + if(hasSur) + { + sur=mxGetLogicals(fun->prhs[fun->xrhs+1]); + (x.front()->get_eval_type()==NOMAD::SGTE)? *sur=true:*sur=false; // all evaluations in a list have the same eval_type + } + + + // Count eval for bbox + // The case where the evaluation is rejected by user (and should not be counted) is not managed in the matlab version + list_count_eval.assign(m,true); + + + //Call MATLAB Objective + try + { + mexCallMATLAB(1, fun->plhs, fun->nrhs, fun->prhs, fun->f); + } + + //Note if these errors occur it is due to errors in MATLAB code, no way to recover? + catch(exception &e) + { + sprintf(errstr,"Unrecoverable Error from Objective / Blackbox Callback:\n%sExiting NOMAD...\n\n",e.what()); + mexPrintf(errstr); + //Force exit + raise(SIGINT); + return false; + } + catch(...) + { + mexPrintf("Unrecoverable Error from Objective / Blackbox Callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + return false; + } + + //Check we got the correct number of elements back + if(mxGetNumberOfElements(fun->plhs[0]) > (nobj+ncon)*m) + mexPrintf("Black box returns more elements than required. Please provide a BB_OUTPUT_TYPE consistent with your black box function or correct the black box function."); + else if(mxGetNumberOfElements(fun->plhs[0]) < (nobj+ncon)*m) + { + mexPrintf("Insufficient outputs provided by the black box function. Exiting NOMAD...\n\n"); + raise(SIGINT); + return false; + } + else if(mxGetM(fun->plhs[0]) != m ) + { + mexPrintf("Insufficient number of rows in the output of the black box function. The number of rows should be equal to the size of the block of evaluations. Exiting NOMAD...\n\n"); + raise(SIGINT); + return false; + } + else if(mxGetN(fun->plhs[0]) != (nobj+ncon) ) + { + mexPrintf("Insufficient number of columns in the output of the black box function. The number of columns should be the number of objectives plus the number of constraints. Exiting NOMAD...\n\n"); + raise(SIGINT); + return false; + } + + + + //Assign bb output + fvals = mxGetPr(fun->plhs[0]); + j=0; + for (it_x=x.begin();it_x!=x.end();++it_x,++j) + for(i=0;i<(nobj+ncon);i++) + (*it_x)->set_bb_output(i,fvals[m*i+j]); + + //Iteration Callback + if(iterF->enabled) + { + iterF->plhs[0] = NULL; + memcpy(mxGetData(iterF->prhs[1]), &citer, sizeof(int)); + memcpy(mxGetPr(iterF->prhs[2]), fvals, m*(nobj+ncon)*sizeof(double)); + memcpy(mxGetPr(iterF->prhs[3]), List_x, n * m * sizeof(double)); + try { + mexCallMATLAB(1, iterF->plhs, 4, iterF->prhs, iterF->f); + } + catch (...) + { + mexPrintf("Unrecoverable Error from Iteration Callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + return false; + } + + //Collect return argument + stop = *(bool*)mxGetData(iterF->plhs[0]); + //Clean up Ptr + mxDestroyArray(iterF->plhs[0]); + + } + + //Add Function Eval Counter + citer++; + + // Clean up LHS Fun Ptr + mxDestroyArray(fun->plhs[0]); + + //Check for iterfun stop + if(stop) + { + mexPrintf("\nIterFun Called Stop. Exiting NOMAD...\n\n"); + raise(SIGINT); + return false; + } + else + return true; + } + + + + //Function + Constraint Evaluation + bool eval_x(NOMAD::Eval_Point &x, const NOMAD::Double &h_max, bool &count_eval) + { + char errstr[1024]; + bool stop = false; + int i, n = x.size(); + double *xm, *fvals; + mxLogical *sur; + count_eval = true; //mexErrMsgTxt will kill MEX + + //Check for Ctrl-C + if (utIsInterruptPending()) { + utSetInterruptPending(false); /* clear Ctrl-C status */ + mexPrintf("\nCtrl-C Detected. Exiting NOMAD...\n\n"); + count_eval = false; + raise(SIGINT); + return false; + } + + //Blackbox / Objective Evaluation + xm = mxGetPr(fun->prhs[fun->xrhs]); + for(i=0;i<n;i++) + xm[i] = x[i].value(); + //Add Surrogate if present and requested + if(hasSur) { + sur=mxGetLogicals(fun->prhs[fun->xrhs+1]); + (x.get_eval_type()==NOMAD::SGTE)? *sur=true:*sur=false; + } + //Call MATLAB Objective + try { + mexCallMATLAB(1, fun->plhs, fun->nrhs, fun->prhs, fun->f); + } + //Note if these errors occur it is due to errors in MATLAB code, no way to recover? + catch(exception &e) { + sprintf(errstr,"Unrecoverable Error from Objective / Blackbox Callback:\n%sExiting NOMAD...\n\n",e.what()); + mexWarnMsgTxt(errstr); + //Force exit + raise(SIGINT); + return false; + } + catch(...) { + mexPrintf("Unrecoverable Error from Objective / Blackbox Callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + return false; + } + +#ifdef OPTI_VERSION + //Check we got the correct number back + if(mxGetM(fun->plhs[0]) != nobj) + mexErrMsgTxt("Incorrect number of elements returned from the objective function"); + //Set Objective (Or multi-objective) + fvals = mxGetPr(fun->plhs[0]); + for(i=0;i<nobj;i++) + x.set_bb_output(i,fvals[i]); + + //Constraint Evaluation + if(ncon) { + con->plhs[0] = NULL; + xm = mxGetPr(con->prhs[con->xrhs]); + for(i=0;i<n;i++) + xm[i] = x[i].value(); + //Call MATLAB Constraint + try { + mexCallMATLAB(1, con->plhs, con->nrhs, con->prhs, con->f); + } + catch(...) + { + mexWarnMsgTxt("Unrecoverable Error from Constraint Callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + return false; + } + //Check we got the correct number back + if(mxGetM(con->plhs[0]) != ncon) + mexErrMsgTxt("Incorrect number of elements returned from nonlinear constraint function"); + //Set Constraints + double *cons = mxGetPr(con->plhs[0]); + for(i=0,j=nobj;i<ncon;i++,j++) + x.set_bb_output(j,cons[i] - con->nlrhs[i]); //subtract nlrhs + // Clean up LHS Ptr + mxDestroyArray(con->plhs[0]); + } +#else //GERAD VERSION + //Check we got the correct number of elements back + if(mxGetNumberOfElements(fun->plhs[0]) > nobj+ncon) + mexWarnMsgTxt("Black box returns more elements than required. Please provide a BB_OUTPUT_TYPE consistent with your black box function"); + else if(mxGetNumberOfElements(fun->plhs[0]) < nobj+ncon) + { + mexPrintf("Insufficient outputs provided by the black box function. Exiting NOMAD...\n\n"); + raise(SIGINT); + return false; + } + //Assign bb output + fvals = mxGetPr(fun->plhs[0]); + for(i=0;i<(nobj+ncon);i++) + x.set_bb_output(i,fvals[i]); + +#endif + + //Iteration Callback + if(iterF->enabled) + { + iterF->plhs[0] = NULL; + memcpy(mxGetData(iterF->prhs[1]), &citer, sizeof(int)); + memcpy(mxGetPr(iterF->prhs[2]), fvals, sizeof(double)); + memcpy(mxGetPr(iterF->prhs[3]), xm, n * sizeof(double)); + try { + mexCallMATLAB(1, iterF->plhs, 4, iterF->prhs, iterF->f); + } + catch (...) + { + mexPrintf("Unrecoverable Error from Iteration Callback, Exiting NOMAD...\n\n"); + //Force exit + raise(SIGINT); + return false; + } + + //Collect return argument + stop = *(bool*)mxGetData(iterF->plhs[0]); + //Clean up Ptr + mxDestroyArray(iterF->plhs[0]); + } + + //Add Function Eval Counter + citer++; + + // Clean up LHS Fun Ptr + mxDestroyArray(fun->plhs[0]); + + //Check for iterfun stop + if(stop) + { + mexPrintf("\nIterFun Called Stop. Exiting NOMAD...\n\n"); + count_eval = false; + raise(SIGINT); + return false; + } + else + return true; + } +}; + +//MATLAB MultiObj Evaluator Class +class matlabMEval : public NOMAD::Multi_Obj_Evaluator { +private: + matlabEval *mEval; +public: + //Constructor + matlabMEval(const NOMAD::Parameters &p, usrFcn *_obj, int _nobj, usrFcn *_con, int _ncon, iter_fun_data *_iterF) : NOMAD::Multi_Obj_Evaluator(p) + { + mEval = new matlabEval(p,_obj,_nobj,_con,_ncon,_iterF); + } + //Destructor + ~matlabMEval(void) + { + delete mEval; + } + //Function + Constraint Information + bool eval_x(NOMAD::Eval_Point &x, const NOMAD::Double &h_max, bool &count_eval) + { + return mEval->eval_x(x,h_max,count_eval); + } + + //Function + Constraint Information + bool eval_x(std::list<NOMAD::Eval_Point *> &x, const NOMAD::Double &h_max, std::list<bool> & list_count_eval ) + { + return mEval->eval_x(x,h_max,list_count_eval); + } + +}; + +//cout Redirection +struct printfbuf : std::streambuf { +public: + //Constructor + printfbuf() + { + setp(m_buffer, m_buffer + s_size - 2); + } +private: + enum { s_size = 1024 }; //not sure on this size + char m_buffer[s_size]; + int_type overflow(int_type c) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) { + *pptr() = traits_type::to_char_type(c); + pbump(1); + } + return sync() != -1 ? traits_type::not_eof(c) : traits_type::eof(); + } + + int sync() { + *pptr() = 0; + mexPrintf(pbase()); + mexEvalString("drawnow;"); + setp(m_buffer, m_buffer + s_size - 2); + return 0; + } +}; + +// make the buffer static to have a single buffer when nested nomad optimizations +static printfbuf buf; + +// Main Entry Function +// ----------------------------------------------------------------- +void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + //Input Args + usrFcn fun, con; + double *x0, *lb = NULL, *ub = NULL; + char *xtype = NULL; + + //Outputs Args + double *exitflag, *iter, *nfval; + + //Internal Vars + size_t ndec; + int i, nobj = 1, ncon = 0; + char errstr[1024]; //used for returning error info + iter_fun_data iterF; + neighborsFcn neighborsF; + + //Check user inputs + if(!checkInputs(prhs,nrhs,plhs,nlhs)) + return; + + //Redirect cout + std::cout.rdbuf(&buf); //redirect buffer + + //NOMAD Vars + NOMAD::Mads *mads; + NOMAD::Display out(std::cout); + NOMAD::Parameters p(out); + NOMAD::Point px0; + NOMAD::Double *nx0; + NOMAD::stop_type stopflag; + //Evaluator Vars + matlabEval *mSEval = NULL; + matlabMEval *mBEval = NULL; + // Extended Poll Vars + Matlab_Extended_Poll *mEP = NULL; + + //Set Option Defaults + int printLevel = 0; + char *paramfile = NULL; + mxArray *bb_out_type = NULL; + iterF.enabled = false; + neighborsF.enabled=false; + + //Get Size + ndec = mxGetNumberOfElements(pX0); + + //Get Blackbox / Objective Function Handle + if (mxIsChar(pFUN)) + { + if(mxGetString(pFUN, fun.f, FLEN) != 0) + mexErrMsgTxt("error reading objective name string"); + fun.nrhs = 1; + fun.xrhs = 0; + } else + { + fun.prhs[0] = (mxArray*)pFUN; + strcpy(fun.f, "feval"); + fun.nrhs = 2; + fun.xrhs = 1; + } + fun.prhs[fun.xrhs] = mxCreateDoubleMatrix(ndec, 1, mxREAL); //x + + //Get x0 + x0 = mxGetPr(pX0); + + //Get xtype + if(nrhs > eXTYPE && !mxIsEmpty(pXTYPE)) + xtype = mxArrayToString(pXTYPE); + + //Get MEX Options if specified + if(nrhs > eOPTS && !mxIsEmpty(pOPTS)) { + if(mxGetField(pOPTS,0,"display_degree") && !mxIsEmpty(mxGetField(pOPTS,0,"display_degree"))) + printLevel = (int)*mxGetPr(mxGetField(pOPTS,0,"display_degree")); + if(mxGetField(pOPTS,0,"param_file") && !mxIsEmpty(mxGetField(pOPTS,0,"param_file"))) + paramfile = mxArrayToString(mxGetField(pOPTS,0,"param_file")); + if(mxGetField(pOPTS,0,"bb_output_type") && !mxIsEmpty(mxGetField(pOPTS,0,"bb_output_type"))) + bb_out_type = mxGetField(pOPTS,0,"bb_output_type"); + if(mxGetField(pOPTS,0,"iterfun") && !mxIsEmpty(mxGetField(pOPTS,0,"iterfun"))) + { + iterF.prhs[0] = (mxArray*)mxGetField(pOPTS,0,"iterfun"); + strcpy(iterF.f, "feval"); + iterF.enabled = true; + iterF.prhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + iterF.prhs[2] = mxCreateDoubleMatrix(1,1,mxREAL); + iterF.prhs[3] = mxCreateDoubleMatrix(ndec,1,mxREAL); + } + // This is for categorical variables + if(mxGetField(pOPTS,0,"neighbors_mat") && !mxIsEmpty(mxGetField(pOPTS,0,"neighbors_mat"))) + { + strcpy(neighborsF.f, "feval"); + neighborsF.enabled = true; + neighborsF.prhs[0] = (mxArray*)mxGetField(pOPTS,0,"neighbors_mat"); + neighborsF.prhs[1] = mxCreateDoubleMatrix(ndec,1,mxREAL); + } + + } + + + //Setup ndec + p.set_DIMENSION((int)ndec); + //Warn if >1000 + if(ndec > 1000 && printLevel) { + sprintf(errstr,"Warning: NOMAD is designed for problems with less than 1000 variables. Your model has %d.\nWhile unlikely, it is possible that NOMAD may not perform as intended on this problem.",static_cast<int>(ndec)); + mexWarnMsgTxt(errstr); + } + + //Setup Lower Bounds + if(nrhs > eLB && !mxIsEmpty(pLB)) { + NOMAD::Point ptLB; + NOMAD::Double *dLB = new NOMAD::Double[ndec]; + lb = mxGetPr(pLB); + for(i=0;i<ndec;i++) { + if(!mxIsInf(lb[i])) //if not initialized will not be used + dLB[i] = lb[i]; + } + ptLB.set((int)ndec,dLB); + p.set_LOWER_BOUND(ptLB); + delete [] dLB; + } + //Setup Upper Bounds + if(nrhs > eUB && !mxIsEmpty(pUB)) + { + NOMAD::Point ptUB; + NOMAD::Double *dUB = new NOMAD::Double[ndec]; + ub = mxGetPr(pUB); + for(i=0;i<ndec;i++) { + if(!mxIsInf(ub[i])) //if not initialized will not be used + dUB[i] = ub[i]; + } + ptUB.set((int)ndec,dUB); + p.set_UPPER_BOUND(ptUB); + delete [] dUB; + } + + //Setup x0 + nx0 = new NOMAD::Double[ndec]; +#ifdef OPTI_VERSION + double xl, xu; + //If integer variables declared, need to ensure x0[i] is an integer + if(xtype) + { + for(i=0;i<ndec;i++) + { + switch(tolower(xtype[i])) + { + case 'c': + //Ensure within bounds + if(lb && x0[i] < lb[i]) + nx0[i] = lb[i]; + else if(ub && x0[i] > ub[i]) + nx0[i] = ub[i]; + else + nx0[i] = x0[i]; //no rounding + break; + case 'i': + case 'b': + xl = floor(x0[i]); //First round is a floor + //If lower bounds exist + if(lb) { + //if lower bound broken + if(xl < lb[i]) { + xu = ceil(x0[i]); + //If upper bounds exist, check bound directions + if(ub && xu > ub[i]) { //if broken, no integer x0 exists + sprintf(errstr,"x0[%d] cannot be rounded to an integer value between lb: %g, ub %g",i,lb[i],ub[i]); + mexErrMsgTxt(errstr); + } + if(xu != x0[i]) { //If we changed something, warn user + sprintf(errstr,"x0[%d] was rounded up to %g to suit NOMAD interface",i,xu); + mexWarnMsgTxt(errstr); + } + //Save ceil value + nx0[i] = xu; + } + //Floor value did not break lower bounds, value OK + else { + if(xl != x0[i]) { //If we changed something, warn user + sprintf(errstr,"x0[%d] was rounded down to %g to suit NOMAD interface",i,xl); + mexWarnMsgTxt(errstr); + } + //Save floor value + nx0[i] = xl; + } + } + //No lower bounds, floor value assumed OK + else { + if(xl != x0[i]) { //If we changed something, warn user + sprintf(errstr,"x0[%d] was rounded down to %g to suit NOMAD interface",i,xl); + mexWarnMsgTxt(errstr); + } + //Save floor value + nx0[i] = xl; + } + break; + case 'r': + mexErrMsgTxt("Please specify continuous (real) variables using 'c' (as opposed to 'r') when using the OPTI version"); + break; + default: + sprintf(errstr,"Unknown xtype[%d] character: %c\n\nValid options are 'C', 'I', or 'B'\n",i,xtype[i]); + mexErrMsgTxt(errstr); + } + } + } + //Else user start position within bounds + else { + for(i=0;i<ndec;i++) { + if(lb && x0[i] < lb[i]) + nx0[i] = lb[i]; + else if(ub && x0[i] > ub[i]) + nx0[i] = ub[i]; + else + nx0[i] = x0[i]; + } + } + +#else //GERAD VERSION - no x0 checking + for(i=0;i<ndec;i++) + nx0[i] = x0[i]; +#endif + px0.set((int)ndec,nx0); + p.set_X0(px0); + delete [] nx0; + +#ifdef OPTI_VERSION + //Setup Nonlinear Constraints + if(nrhs > eNLCON && !mxIsEmpty(pNLCON)) { + if (mxIsChar(pNLCON)) { + if(mxGetString(pNLCON, con.f, FLEN) != 0) + mexErrMsgTxt("error reading constraint name string"); + con.nrhs = 1; + con.xrhs = 0; + } else { + con.prhs[0] = (mxArray*)pNLCON; + strcpy(con.f, "feval"); + con.nrhs = 2; + con.xrhs = 1; + } + con.prhs[con.xrhs] = mxCreateDoubleMatrix(ndec, 1, mxREAL); //x + if(nrhs < eNLRHS+1 || mxIsEmpty(pNLRHS)) {//we will default to <= 0 + ncon = -1; + con.nlrhs = NULL; + } + else { + ncon = (int)mxGetNumberOfElements(pNLRHS); + con.nlrhs = mxGetPr(pNLRHS); + } + } + //Setup Input Variable Types + if(xtype) + p.set_BB_INPUT_TYPE(detInTypes(xtype,ndec)); + + //Setup Evaluation Return Types + #'s of Obj + Con + p.set_BB_OUTPUT_TYPE(detRetTypes(&fun,bb_out_type,&nobj,&con,&ncon,x0,ndec)); + + //Set All Normal NOMAD Options + p.set_DISPLAY_DEGREE(0); //default + +#endif //GERAD Version does not have a separate constraint handler and handles input and output types using options + + // evaluation tags and numbers are reset + NOMAD::Eval_Point::reset_tags_and_bbes(); + + // Reset the random number generator for each mads run. + // The seed will always be to its default value + NOMAD::RNG::reset_seed_to_default(); + + //Set User Options + if(nrhs > eOPTS && !mxIsEmpty(pOPTS)) + setNOMADopts(p,pOPTS); + else + setNOMADopts(p,NULL); + + //If the user has specified a parameter file to read, see if it exists, and if so, read and parse it. + if(paramfile) + { + FILE *pFile = fopen(paramfile,"r"); + if(pFile==NULL) { + sprintf(errstr,"Cannot open parameter file: %s\n\nEnsure it exists!",paramfile); + mexErrMsgTxt(errstr); + } + else{ + fclose(pFile); //close file pointer (we don't need it) + try + { + p.read(paramfile); + } + catch(exception &e) + { + sprintf(errstr,"NOMAD Parameter File Read Error:\n\n%s",e.what()); + mexErrMsgTxt(errstr); + } + } + } + + //Check NOMAD parameters + try + { + p.check(); + } + catch(exception &e) { + sprintf(errstr,"NOMAD Parameter Error:\n\n%s",e.what()); + mexErrMsgTxt(errstr); + } + + //If GERAD version, obtain number of objectives and constraints from parameters +#ifndef OPTI_VERSION + nobj=p.get_nb_obj(); + ncon=(int)p.get_bb_output_type().size()-nobj; + if (p.has_sgte()) { + fun.prhs[fun.xrhs+1] = mxCreateLogicalMatrix(1,1); //extra logical indicating surrogate or not + fun.nrhs++; + } +#endif + + //Print Header + if(printLevel) { + mexPrintf("\n------------------------------------------------------------------\n"); + mexPrintf(" This is NOMAD v%s\n",NOMAD::VERSION.c_str()); + mexPrintf(" Authors: M. Abramson, C. Audet, G. Couture, J. Dennis, S. Le Digabel, C. Tribes\n"); +#ifdef OPTI_VERSION + mexPrintf(" MEX Interface (OPTI) J. Currie 2012\n\n"); +#else + mexPrintf(" MEX Interface (GERAD) J. Currie 2012 and C.Tribes 2015 \n\n"); +#endif + mexPrintf(" Problem Properties:\n"); + mexPrintf(" # Decision Variables: %4d\n",ndec); + mexPrintf(" # Number of Objectives: %4d\n",nobj); + mexPrintf(" # Number of Nonlinear Constraints: %4d\n",ncon); + + mexPrintf("------------------------------------------------------------------\n"); + mexEvalString("drawnow;"); //flush draw buffer + } + + //Create evaluator and run mads based on number of objectives + try + { + if(nobj > 1) + { + mBEval = new matlabMEval(p,&fun,nobj,&con,ncon,&iterF); //Bi-Objective Evaluator + + if ( p.get_signature()->has_categorical() ) + { + mEP = new Matlab_Extended_Poll ( p , &neighborsF); + mads = new NOMAD::Mads(p, mBEval , mEP , NULL , NULL); //Run NOMAD + + } + else + mads = new NOMAD::Mads(p, mBEval); //Run NOM + + stopflag = mads->multi_run(); + } + else + { + mSEval = new matlabEval(p,&fun,nobj,&con,ncon,&iterF); //Single Objective Evaluator + + if ( p.get_signature()->has_categorical() ) + { + mEP = new Matlab_Extended_Poll ( p, &neighborsF); + mads = new NOMAD::Mads(p, mSEval , mEP , NULL , NULL); //Run NOMAD + + } + else + mads = new NOMAD::Mads(p, mSEval); //Run NOMAD + + stopflag = mads->run(); + + } + } + catch(exception &e) + { + + //Free Memory + if(mSEval) + delete mSEval; + mSEval = NULL; + if(mBEval) + delete mBEval; + mBEval = NULL; + delete mads; + if(xtype) + mxFree(xtype); + xtype = NULL; + + delete mads; + + sprintf(errstr,"NOMAD Run Error:\n\n%s",e.what()); + mexErrMsgTxt(errstr); + } + + if(printLevel) + mexPrintf("------------------------------------------------------------------\n"); + + //Obtain Solution + + + //Create Outputs + plhs[2] = mxCreateDoubleMatrix(1,1, mxREAL); + plhs[3] = mxCreateDoubleMatrix(1,1, mxREAL); + plhs[4] = mxCreateDoubleMatrix(1,1, mxREAL); + exitflag = mxGetPr(plhs[2]); + iter = mxGetPr(plhs[3]); + nfval = mxGetPr(plhs[4]); + if (nobj>1) + { + + NOMAD::Pareto_Front * pareto_front=mads->get_pareto_front(); + + if ( pareto_front ) + { + + int nb_pareto_pts = pareto_front->size(); + plhs[0] = mxCreateDoubleMatrix(ndec,nb_pareto_pts, mxREAL); + plhs[1] = mxCreateDoubleMatrix(nobj,nb_pareto_pts, mxREAL); + double *x = mxGetPr(plhs[0]); + double *fval = mxGetPr(plhs[1]); + + const NOMAD::Eval_Point * cur = pareto_front->begin(); + int i=0; + while ( cur ) + { + + if ( cur->is_eval_ok() && cur->is_feasible ( p.get_h_min() ) ) + { + const std::list<int> & index_obj = p.get_index_obj(); + std::list<int>::const_iterator it , end = index_obj.end(); + const NOMAD::Point & bbo = cur->get_bb_outputs(); + int j = 0; + NOMAD::Point multi_obj ( static_cast<int>(index_obj.size()) ); + + for ( it = index_obj.begin() ; it != end ; ++it,j++ ) + fval[nobj*i+j] = bbo[*it].value(); + + for(j=0;j<ndec;j++) + x[ndec*i+j] = (*cur)[j].value(); + } + cur = pareto_front->next(); + i++; + } + *exitflag = getStatus(stopflag); + + } + else + { + stopflag = (NOMAD::stop_type)10; + *exitflag = -1; //No solution + } + //Save Status & Iterations + + *iter = mads->get_stats().get_iterations(); + *nfval = mads->get_stats().get_bb_eval(); + + } + else + { + + plhs[0] = mxCreateDoubleMatrix(ndec,1, mxREAL); + plhs[1] = mxCreateDoubleMatrix(1,1, mxREAL); //even bi-objectives return 1 fval + double *x = mxGetPr(plhs[0]); + double *fval = mxGetPr(plhs[1]); + + const NOMAD::Eval_Point *bestSol = mads->get_best_feasible(); + if(bestSol == NULL) + { + bestSol = mads->get_best_infeasible(); + //manually set as infeasible (no infeasible stop flag) + stopflag = (NOMAD::stop_type)10; + } + if(bestSol == NULL) + *exitflag = -1; //No solution + + //If we have a solution, save it + if(*exitflag != -1) { + //Save x + NOMAD::Point pt(*bestSol); + for(i=0;i<ndec;i++) + x[i] = pt[i].value(); + //Save fval + *fval = bestSol->get_f().value(); + + //Save Status & Iterations + *exitflag = getStatus(stopflag); + *iter = mads->get_stats().get_iterations(); + *nfval = mads->get_stats().get_bb_eval(); + } + } + + //Return error control to default + mexSetTrapFlag(0); + + + //Free Memory + if(mSEval) + delete mSEval; + mSEval = NULL; + if(mBEval) + delete mBEval; + mBEval = NULL; + + // Clean up of fun + mxDestroyArray(fun.prhs[fun.xrhs]); + + delete mads; + + if(xtype) + mxFree(xtype); + xtype = NULL; +} + +//Determine Variable Return Types + # Objectives + #NL Constraints (only OPTI Version) +vector<NOMAD::bb_output_type> detRetTypes(usrFcn *fun, mxArray *out_types, int *nobj, usrFcn *con, int *ncon, double *x0, size_t n) +{ + int i, j, stat; + + //Test Blackbox / Objective Evaluation + fun->plhs[0] = NULL; + memcpy(mxGetPr(fun->prhs[fun->xrhs]), x0, n * sizeof(double)); + //Call MATLAB Objective + stat = mexCallMATLAB(1, fun->plhs, fun->nrhs, fun->prhs, fun->f); + if(stat) + mexErrMsgTxt("Error calling Objective Function!"); + //Ensure we have a real column + if(mxGetN(fun->plhs[0]) > mxGetM(fun->plhs[0])) + mexErrMsgTxt("The objective function must return a scalar or column vector"); + if(mxIsSparse(fun->plhs[0]) || mxIsComplex(fun->plhs[0])) + mexErrMsgTxt("The objective function must return a real, dense, vector"); + + //Ensure 1 or 2 rows (max of bi-objective) + *nobj = (int)mxGetNumberOfElements(fun->plhs[0]); + if(*nobj < 1 || *nobj > 2) + mexErrMsgTxt("The objective function must return a scalar or 2x1 vector (bi-objective)"); + // Clean up LHS Ptr + mxDestroyArray(fun->plhs[0]); + + //Test Constraint Evaluation + if(*ncon) { + con->plhs[0] = NULL; + memcpy(mxGetPr(con->prhs[con->xrhs]), x0, n * sizeof(double)); + //Call MATLAB Objective + stat = mexCallMATLAB(1, con->plhs, con->nrhs, con->prhs, con->f); + if(stat) + mexErrMsgTxt("Error calling Constraint Function!"); + //Ensure we have a real column + if(mxGetN(con->plhs[0]) > mxGetM(con->plhs[0])) + mexErrMsgTxt("The constraint function must return a scalar or column vector"); + if(mxIsSparse(con->plhs[0]) || mxIsComplex(con->plhs[0])) + mexErrMsgTxt("The constraint function must return a real, dense, vector"); + + //If we have nlrhs, check against returned vector + if(*ncon > 0) { + if(mxGetM(con->plhs[0]) != *ncon) + mexErrMsgTxt("The vector returned from nlcon is not the same length as nlrhs!"); + } + else { + *ncon = (int)mxGetM(con->plhs[0]); + con->nlrhs = mxGetPr(mxCreateDoubleMatrix(*ncon,1, mxREAL)); //create dummy rhs + } + // Clean up LHS Ptr + mxDestroyArray(con->plhs[0]); + } + + //Create Return Vector + vector<NOMAD::bb_output_type> varType(*nobj+*ncon); + //Fill Objective Information + for(i=0;i<*nobj;i++) + varType[i] = NOMAD::OBJ; + //If the user has set bb_output_type use it to set constraint types + if(out_types) { + if(!mxIsCell(out_types)) + mexErrMsgTxt("Parameter bb_output_type must be a cell array of strings."); + if(mxGetNumberOfElements(out_types) != *ncon) + mexErrMsgTxt("You must specify a bb_output_type for each element returned by the constraint function (not objective)."); + //Process each element in the array + for(i=0,j=*nobj;i<*ncon;i++,j++){ + mxArray *ctype = mxGetCell(out_types,i); + if(!mxIsChar(ctype)) + mexErrMsgTxt("An element in the bb_output_type paramter is not a string"); + //Get the string + char *str = mxArrayToString(ctype); + //Set varType based on string + varType[j] = getOutEnum(str); + //Free local memory at each iteration + mxFree(str); + } + } + //Or Fill Constraint Information as Default all PB + else { + for(i=0,j=*nobj;i<*ncon;i++,j++) + varType[j] = NOMAD::PB; + } + + return varType; +} + +//Convert user string to NOMAD bb_output_type enum +NOMAD::bb_output_type getOutEnum(char *str) +{ + char errstr[1024]; + lower(str); //convert to lowercase + + if(!strcmp(str,"obj")) +#ifdef OPTI_VERSION + mexErrMsgTxt("The OPTI Version of NOMAD uses bb_output_type to describe CONSTRAINTS ONLY. Please remove any OBJ terms from the cell array."); +#else + return NOMAD::OBJ; +#endif + else if(!strcmp(str,"pb")) + return NOMAD::PB; + else if(!strcmp(str,"eb")) + return NOMAD::EB; + else if(!strcmp(str,"peb")) + return NOMAD::PEB_P; + else if(!strcmp(str,"f")) + return NOMAD::FILTER; + else if(!strcmp(str,"nothing") || !strcmp(str,"-")) + return NOMAD::UNDEFINED_BBO; + else { + sprintf(errstr,"Unknown BB_OUTPUT_TYPE %s",str); + mexErrMsgTxt(errstr); + } + //Default + return NOMAD::UNDEFINED_BBO; +} + +//Convert input string to lowercase +void lower(char *str) +{ + int i = 0; + while(str[i]) { + str[i] = tolower(str[i]); + i++; + } +} + +//Determine input variable types (only OPTI version) +vector<NOMAD::bb_input_type> detInTypes(char *xtype, size_t n) +{ + int i; + char msgbuf[1024]; + vector<NOMAD::bb_input_type> varType(n); + for(i=0;i<n;i++) { + switch(tolower(xtype[i])) + { + case 'c': + varType[i] = NOMAD::CATEGORICAL; break; + case 'r': + varType[i] = NOMAD::CONTINUOUS; break; + mexErrMsgTxt("Please specify continuous (real) variables using 'c' when using the OPTI version"); + case 'i': + varType[i] = NOMAD::INTEGER; break; + case 'b': + varType[i] = NOMAD::BINARY; break; + default: + sprintf(msgbuf,"Unknown xtype[%d] character: %c\n\nValid options are 'C', 'I', or 'B'\n",i,xtype[i]); + mexErrMsgTxt(msgbuf); + } + } + return varType; +} + +//User Input Checking + Version / Info / Help +int checkInputs(const mxArray *prhs[], int nrhs, mxArray *plhs[], int nlhs) +{ + size_t ndec; + char *str = NULL; + + //MEX Display Version (OPTI compatibility) + if (nrhs < 1) { + if(nlhs < 1) + printSolverInfo(); + else + plhs[0] = mxCreateString(NOMAD::VERSION.c_str()); + return 0; + } + + //Redirect cout + std::streambuf *cout_sbuf = std::cout.rdbuf(); //keep existing buffer + std::cout.rdbuf(&buf); //redirect buffer + + //NOMAD Display + NOMAD::Display out (std::cout); + + //Check for display on options passed as structure + if(nrhs == 1 && mxIsStruct(prhs[0])) { + int i, no = mxGetNumberOfFields(prhs[0]); + const char *field; + std::list<std::string> ls; + //For all fields, display nomad help + for(i=0;i<no;i++) { + field = mxGetFieldNameByNumber(prhs[0],i); + string st(field); + ls.push_back ( st ); + } + if(no>0) { + //NOMAD Display + NOMAD::Parameters p ( out ); + p.help(ls); + } + std::cout.rdbuf(cout_sbuf); //Return cout to initial buffer + return 0; + } + + //Check for Version / Information / Help Request + if(nrhs == 1 && mxIsChar(prhs[0])) { + str = mxArrayToString(prhs[0]); + //Check for Info Request + if(!strcmp(str,"-I") || !strcmp(str,"-INFO") || !strcmp(str,"-i") || !strcmp(str,"-info")) { + //Information to Print + mexPrintf("\nNOMAD Blackbox Optimization Software, v%s\n\n",NOMAD::VERSION.c_str()); + mexPrintf("Copyright (C) 2001-2015\n"); + mexPrintf("Mark A. Abramson - The Boeing Company\n"); + mexPrintf("Charles Audet - Ecole Polytechnique de Montreal\n"); + mexPrintf("Gilles Couture - Ecole Polytechnique de Montreal\n"); + mexPrintf("John E. Dennis, Jr. - Rice University\n"); + mexPrintf("Sebastien Le Digabel - Ecole Polytechnique de Montreal\n"); + mexPrintf("Christophe Tribes - Ecole Polytechnique de Montreal\n\n"); + mexPrintf("Funded in part by AFOSR and Exxon Mobil.\n\n"); + mexPrintf("License : \'%s\'\n",NOMAD::LGPL_FILE.c_str()); + mexPrintf("User guide: \'%s\'\n",NOMAD::USER_GUIDE_FILE.c_str()); + mexPrintf("Examples : \'%s\'\n",NOMAD::EXAMPLES_DIR.c_str()); + mexPrintf("Tools : \'%s\'\n\n",NOMAD::TOOLS_DIR.c_str()); + mexPrintf("Please report NOMAD bugs to nomad@gerad.ca and MEX Interface bugs to jocurrie@aut.ac.nz\n\n"); + + std::cout.rdbuf(cout_sbuf); //Return cout to initial buffer + return 0; + } + //Check for Ver Request + if(!strcmp(str,"-V") || !strcmp(str,"-v") || !strcmp(str,"-version")) + { + mexPrintf("NOMAD - version %s - www.gerad.ca/nomad\n\n",NOMAD::VERSION.c_str()); +#ifdef OPTI_VERSION + mexPrintf("MEX Interface (OPTI) v%s\n",NOMADMEX_VERSION); +#else + mexPrintf("MEX Interface (GERAD) v%s\n",NOMADMEX_VERSION); +#endif + + std::cout.rdbuf(cout_sbuf); //Return cout to initial buffer + return 0; + } + //Check for Help Request + if (strcmp(str,"-H")<0 || strcmp(str,"-HELP")<0 || strcmp(str,"-h")<0 || strcmp(str,"-help")<0 ) + { + NOMAD::Parameters p ( out ); + std::list<std::string> helpS; + const char * toks=" "; + char *w = strtok(str,toks) ; + for ( w = strtok(NULL,toks) ; w != NULL ; w = strtok(NULL,toks) ) + { + helpS.push_back(w); + } + p.help (helpS ); + + std::cout.rdbuf(cout_sbuf); //Return cout to initial buffer + return 0; + } + } + + //Otherwise assume we have a normal problem + if(nrhs < 2) + mexErrMsgTxt("You must supply at least 2 arguments to nomad!\n\nnomad(fun,x0)\n"); + + //Check Types + if(!mxIsFunctionHandle(pFUN) && !mxIsChar(pFUN)) + mexErrMsgTxt("fun must be a function handle or function name!"); + + if(!mxIsDouble(pX0) || mxIsComplex(pX0) || mxIsEmpty(pX0)) + mexErrMsgTxt("x0 must be a real double column vector!"); + + //Get ndec + ndec = mxGetNumberOfElements(prhs[1]); + + //Check Bounds + if(nrhs > 2) { + if(!mxIsDouble(pLB) || mxIsComplex(pLB)) + mexErrMsgTxt("lb must be a real double column vector!"); + if(nrhs > 3 && (!mxIsDouble(pUB) || mxIsComplex(pUB))) + mexErrMsgTxt("ub must be a real double column vector!"); + //Check Sizes + if(!mxIsEmpty(pLB) && (ndec != mxGetNumberOfElements(pLB))) + mexErrMsgTxt("lb is not the same length as x0! Ensure they are both Column Vectors"); + if(nrhs > 3 && !mxIsEmpty(pUB) && (ndec != mxGetNumberOfElements(pUB))) + mexErrMsgTxt("ub is not the same length as x0! Ensure they are both Column Vectors"); + } + +#ifdef OPTI_VERSION + //Version check + if(nrhs > eNLRHS && mxIsStruct(pNLRHS)) + mexErrMsgTxt("It appears you may be calling NOMAD using the GERAD NOMAD Syntax - nomad(bb,x0,lb,ub,opts). This is the OPTI NOMAD version and requires nomad(fun,x0,lb,ub,nlcon,nlrhs,xtype,opts)."); + + //Check Nonlinear Constraint Handle + if(nrhs > eNLCON && !mxIsEmpty(pNLCON)) { + if(!mxIsFunctionHandle(pNLCON) && !mxIsChar(pNLCON)) + mexErrMsgTxt("nlcon must be a function handle or function name!"); + if(nrhs > eNLRHS && (!mxIsDouble(pNLRHS) || mxIsComplex(pNLRHS))) + mexErrMsgTxt("nlrhs must be a real double column vector!"); + } + //Check for xtype + if(nrhs > eXTYPE && !mxIsEmpty(pXTYPE)) { + if(!mxIsChar(pXTYPE)) + mexErrMsgTxt("The xtype vector must be a char array!"); + if(ndec != mxGetNumberOfElements(pXTYPE)) + mexErrMsgTxt("xtype is not same length as x0! Ensure they are both Column Vectors"); + } +#else + //Version check + if(nrhs > 6) + mexErrMsgTxt("It appears you may be calling NOMAD using the OPTI NOMAD Syntax - nomad(fun,x0,lb,ub,nlcon,nlrhs,xtype,opts). This is the GERAD NOMAD version and requires nomad(bb,x0,lb,ub,opts)."); +#endif + + //Check Options + if(nrhs > eOPTS && !mxIsEmpty(pOPTS)) { + //Version check + if(mxIsDouble(pOPTS)) + mexErrMsgTxt("It appears you may be calling NOMAD using the OPTI NOMAD Syntax - nomad(fun,x0,lb,ub,nlcon,nlrhs,xtype,opts). This is the GERAD NOMAD version and requires nomad(bb,x0,lb,ub,opts)."); + + if(!mxIsStruct(pOPTS)) + mexErrMsgTxt("The specified options must be a structure!"); + } + + //Return Continue + return 1; + +} + +void setNOMADopts(NOMAD::Parameters &p, const mxArray *opts) +{ + char strbuf[1024]; + int i, no = 0; + NOMAD::Parameter_Entries entries; + const char *field; + mxArray *value; + bool doAdd = false; + size_t m; + double val; + bool has_BB_OUTPUT_TYPE = false; + bool has_categorical =false; + + if(opts) + no = mxGetNumberOfFields(opts); + + //For each field, check if it's empty, if not, set it within NOMAD + for(i=0;i<no;i++) { + field = mxGetFieldNameByNumber(opts,i); + value = mxGetFieldByNumber(opts,0,i); + //Check we don't have an empty or MEX option + if(!mxIsEmpty(value) && isNMDOption(field)) { + //Switch on data type + switch(mxGetClassID(value)) + { + + case mxDOUBLE_CLASS: + m = mxGetNumberOfElements(value); + //This interface doesn't write vectors as options + if(m > 1) { + sprintf(strbuf,"This interface does not support vector options for parameter %s. Please provide it as a string",field); + mexErrMsgTxt(strbuf); + } + val = *mxGetPr(value); + //Check if we have an integer parameter (I assume this check is ok!) + if(floor(val) == val) { + sprintf(strbuf,"%s %.0f",field,val); doAdd = true; //write with no decimal points and no exponent + } + else {//write as double (exponent ok) + sprintf(strbuf,"%s %g",field,val); doAdd = true; + } + break; + case mxFUNCTION_CLASS: + if ( strcmp(field,"NEIGHBORS_MAT") == 0 || strcmp(field,"neighbors_mat") == 0 ) + { + // sprintf(strbuf,"%s %s",field,mxArrayToString(value)); + has_categorical = true; + } + break; + case mxCHAR_CLASS: + sprintf(strbuf,"%s %s",field,mxArrayToString(value)); + doAdd = true; + //GERAD check for BB_OUTPUT_TYPE + if ( strcmp(field,"BB_OUTPUT_TYPE") == 0 || strcmp(field,"bb_output_type") == 0 ) + has_BB_OUTPUT_TYPE = true; + break; + + case mxCELL_CLASS: +#ifdef OPTI_VERSION + //Add each string for the specified field + m = mxGetNumberOfElements(value); + for(j=0;j<m;j++) { + mxArray *cellopt = mxGetCell(value,j); + if(!mxIsChar(cellopt)) { + sprintf(strbuf,"Element %d in the cell array of paramter %s is not a string",j+1,field); + mexErrMsgTxt(strbuf); + } + //Get the string and create the required option string + char *str = mxArrayToString(cellopt); + sprintf(strbuf,"%s %s",field,str); + //Add to our set of parameter entries + NOMAD::Parameter_Entry *pe = new NOMAD::Parameter_Entry(strbuf); // pe will be deleted by ~Parameter_Entries() + if(pe->is_ok()) + entries.insert(pe); + else { + sprintf(strbuf,"Parameter %s has an error",field); + mexErrMsgTxt(strbuf); + } + //Free local memory at each iteration + mxFree(str); + } +#else + sprintf(strbuf,"Parameter %s NOT SET!\nThe GERAD version of the NOMAD interface does not support cell arrays. Please specify them as strings, with spaces between arguments.",field); + mexWarnMsgTxt(strbuf); +#endif + break; + + default: + sprintf(strbuf,"Parameter %s NOT SET, CLASSID = %d which is not supported",field,mxGetClassID(value)); + mexWarnMsgTxt(strbuf); + } + + //If we have a valid parameter, add it to our set of entries + if(doAdd) { + //mexPrintf("NOMAD Option set as: %s\n",strbuf); //enable for debug + NOMAD::Parameter_Entry *pe = new NOMAD::Parameter_Entry(strbuf); + if(pe->is_ok()) + entries.insert(pe); // pe will be deleted by ~Parameter_Entries() + else + { + sprintf(strbuf,"Parameter %s has an error",field); + mexErrMsgTxt(strbuf); + } + + doAdd = false; + } + } + } + //GERAD default bb_output_type if not specified +#ifndef OPTI_VERSION + if(!has_BB_OUTPUT_TYPE) { + NOMAD::Parameter_Entry *pe = new NOMAD::Parameter_Entry("BB_OUTPUT_TYPE OBJ"); + entries.insert(pe); // pe will be deleted by ~Parameter_Entries() + } +#endif + + try + { + p.read(entries); + } + catch(exception &e) + { + sprintf(strbuf,"NOMAD Parameter Read Error:\n\n%s",e.what()); + mexErrMsgTxt(strbuf); + } +} + +//Separates MEX interface options from NOMAD ones +bool isNMDOption(const char *field) +{ + if(!strcmp(field,"param_file")) + return false; + else if(!strcmp(field,"iterfun")) + return false; +#ifdef OPTI_VERSION + else if(!strcmp(field,"bb_output_type")) + return false; +#endif + else + return true; +} + +double getStatus(int stat) +{ + switch((int)stat) + { + case 5: //mesh minimum + case 8: //min mesh size + case 9: //min poll size + case 20: //ftarget reached + case 19: //feas reached + return 1; + break; + case 12: //max time + case 13: //max bb eval + case 14: //max sur eval + case 15: //max evals + case 16: //max sim bb evals + case 17: //max iter + case 23: //max multi bb evals + case 24: //max mads runs + return 0; + break; + case 10: //max mesh index + case 11: //mesh index limits + case 18: //max consec fails + case 25: //stagnation + case 26: //no pareto + case 27: //max cache memory + return -1; + case 6: //x0 fail + case 7: //p1_fail + return -2; + case 2: //Unknown stop reason + return -3; + case 3: //Ctrl-C + case 4: //User-stopped + return -5; + default: //Not assigned flag + return -3; + } +} + +//Print Solver Information +void printSolverInfo() +{ + mexPrintf("\n-----------------------------------------------------------\n"); + mexPrintf(" NOMAD: Nonlinear Optimization using the MADS Algorithm [v%s]\n",NOMAD::VERSION.c_str()); + mexPrintf(" - Released under the GNU Lesser General Public License: http://www.gnu.org/copyleft/lesser.html\n"); + mexPrintf(" - Source available from: http://www.gerad.ca/NOMAD/Project/Home.html\n"); + + mexPrintf("\n MEX Interface J.Currie 2013 (www.i2c2.aut.ac.nz) and C.Tribes 2015 \n"); + mexPrintf("-----------------------------------------------------------\n"); +} diff --git a/examples/interfaces/Matlab_MEX/example_block_eval/fun.m b/examples/interfaces/Matlab_MEX/example_block_eval/fun.m new file mode 100644 index 0000000000000000000000000000000000000000..1c9c899f5aa4e02f1fed90977592d9366de711ba --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_block_eval/fun.m @@ -0,0 +1,26 @@ +function [ fout ] = fun( X ) + +% CRESCENT 5 --- Block evals version + +nb_points=size(X,1); +n=size(X,2); + +if ( n ~= 5) + error('Black box function must be provided with points of dimension 5 (=number of columns)'); +end + +% objective +obj=X(:,5); +% constraints +parfor m=1:nb_points + c1(m)=sum((X(m,:)-1).^2)-25; + c2(m)=25-sum((X(m,:)+1).^2); +end + +% Unlike in the standard nomad version, a point cannot be +% rejected in the matlab version. +% If some points cannot be evaluated, objective and constraints must be set +% to Inf, otherwise the nomad evaluator for block of evaluations cannot +% continue. +fout=[obj , c1' , c2']; + diff --git a/examples/interfaces/Matlab_MEX/example_block_eval/run_nomad.m b/examples/interfaces/Matlab_MEX/example_block_eval/run_nomad.m new file mode 100644 index 0000000000000000000000000000000000000000..4177fee092dea5a49285cac10bae2977b8b96ba4 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_block_eval/run_nomad.m @@ -0,0 +1,12 @@ +% CRESCENT 5 + + +% parpool(4); + +x0 = [0 0 0 0 0 ]'; +lb = [-6 -6 -6 -6 -6 ]'; +ub = [6 6 6 6 6]'; +opts = nomadset('display_degree',2,'max_bb_eval',500,'direction_type','ortho 2n','bb_output_type','OBJ PB PB','bb_max_block_size',4); + +% Start optimization +[x,fval] = nomad(@fun,x0,lb,ub,opts); diff --git a/examples/interfaces/Matlab_MEX/example_categorical/fun.m b/examples/interfaces/Matlab_MEX/example_categorical/fun.m new file mode 100644 index 0000000000000000000000000000000000000000..7fa3a28a2501be1d191d37217e2d59f4fe201217 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_categorical/fun.m @@ -0,0 +1,60 @@ +function [ out ] = fun( X ) + +t0=X(1); +v0=X(2); +t1=X(3); +v1=X(4); + +v=zeros(3,1); +vmin = 10000; + +if ( t0 < 0 || t1 < 0 ) + out(1)=Inf; + out(2)=Inf; + out(3)=Inf; + return; +end + +v(t0+1) = v0; +v(t1+1) = v1; + +if ( v0 < vmin ) + vmin = v0; +end +if ( v1 < vmin ) + vmin = v1; +end + +% constraints (budget and each asset is considered with at least 1$): +vt = v(1) + v(2) + v(3); +h = vt - 10000; +g1 = h; +g2 = 1-vmin; + +if ( h <= 0 && vmin >= 1 ) +%% compute the risk and revenue: + vt2 = vt*vt; + rev = v(1) * 0.0891 + v(2) * 0.2137 + v(3) * 0.2346; + risk = 0.01 * (v(1)/vt)*(v(1)/vt) + ... + 0.05 * (v(2)/vt)*(v(2)/vt) + ... + 0.09 * (v(3)/vt)*(v(3)/vt) + ... + 0.02 * (v(1)*v(2)/vt2) + ... + 0.02 * (v(1)*v(3)/vt2) + ... + 0.10 * (v(2)*v(3)/vt2); + + % the objective is taken as a scaled distance + % between (risk,revenue) and (risk_best,rev_best): + a = ( risk - 0.01 ) * 100 / 0.08; + b = ( rev - 891 ) * 100 / 1455; + + f = (a*a + (100-b)*(100-b))^0.5; +else + f = 145; +end + + out(1)=g1; + out(2)=g2; + out(3)=f; + +end + diff --git a/examples/interfaces/Matlab_MEX/example_categorical/neighbors.m b/examples/interfaces/Matlab_MEX/example_categorical/neighbors.m new file mode 100644 index 0000000000000000000000000000000000000000..a057d1ecc8767d1685b732a542a0c9aa9b66c548 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_categorical/neighbors.m @@ -0,0 +1,14 @@ +function [ Xout ] = neighbors ( X ) + +t0 = X(1); +v0 = X(2); +t1 = X(3); +v1 = X(4); + +t2 = ( 3 - t0 - t1 ); + +% neighbor #1: +Xout(1,:)=[ t2 ; v0 ; t1 ; v1 ]; + +% neighbor #2: +Xout(2,:)=[ t0 ; v0 ; t2 ; v1 ]; diff --git a/examples/interfaces/Matlab_MEX/example_categorical/run_nomad.m b/examples/interfaces/Matlab_MEX/example_categorical/run_nomad.m new file mode 100644 index 0000000000000000000000000000000000000000..c4d169f61475134275e8c334c5afe8964d0e0060 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_categorical/run_nomad.m @@ -0,0 +1,7 @@ +x0 = [0 100 1 100 ]'; +lb = [-100 0.0 0 0.0 ]'; +ub = [100 10000.0 100 10000]'; +opts = nomadset('display_degree',2,'max_bb_eval',200,'bb_output_type','EB EB OBJ','bb_input_type','[C R C R]','neighbors_mat',@neighbors); + +% Start optimization +[x,fval] = nomad(@fun,x0,lb,ub,opts); diff --git a/examples/interfaces/Matlab_MEX/example_surrogate/bbsur.m b/examples/interfaces/Matlab_MEX/example_surrogate/bbsur.m new file mode 100644 index 0000000000000000000000000000000000000000..a14643eb0126a08b06870ec51947c239b5fa9b1d --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_surrogate/bbsur.m @@ -0,0 +1,11 @@ +function eval = bbsur(x,sur) + +if (nargin==1) + sur=false; +end + +if (sur) + eval=[9.9*(x(2)-x(1)^2); 1 - x(1)]; +else + eval=[10*(x(2)-x(1)^2); 1 - x(1)]; +end diff --git a/examples/interfaces/Matlab_MEX/example_surrogate/run_nomad.m b/examples/interfaces/Matlab_MEX/example_surrogate/run_nomad.m new file mode 100644 index 0000000000000000000000000000000000000000..b7e58c9217d4f5fea526a09f3a55fb462c3101f6 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/example_surrogate/run_nomad.m @@ -0,0 +1,5 @@ +%% TEST SURROGATE +clc +x0 = [1;1]; +opts = nomadset('display_degree',2,'bb_output_type','OBJ EB','has_sgte',1) +[x,fval] = nomad(@bbsur,x0,[-10;-10],[10;10],opts) diff --git a/examples/interfaces/Matlab_MEX/nomad.m b/examples/interfaces/Matlab_MEX/nomad.m new file mode 100644 index 0000000000000000000000000000000000000000..b273d1cc294536af053e4ebd2fc3ccb7c07402c7 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/nomad.m @@ -0,0 +1,38 @@ +% NOMAD Solve a Global MINLP/NLP using NOMAD, a Blackbox Optimization Library +% +% min f(x) subject to: nlcon(x) <= 0 +% x lb <= x <= ub +% xi in Z +% xj in {0,1} +% +%%%%%%%%%%%%% GERAD VERSION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% [x,fval,exitflag,iter,nfval] = nomad(fun,x0,lb,ub,opts) +% +% Input arguments: +% fun - nonlinear function handle (f and nlcon) +% x0 - initial solution guess +% lb - decision variable lower bounds +% ub - decision variable upper bounds +% opts - solver options (see nomadset) +% +% Return arguments: +% x - solution vector +% fval - objective value at the solution +% exitflag - exit status (see below) +% iter - number of iterations taken by the solver +% nfval - number of function evaluations taken by the solver +% +% Return Status: +% 1 - converged / target reached +% 0 - maximum iterations / function evaluations exceeded +% -1 - infeasible / mesh limit reached +% -2 - initialization error +% -3 - nomad error +% -5 - user exit +% +% +% NOMAD is released under the Lesser GNU Public License (LGPL). +% Type nomad('-info') to see license and author details. +% +% MEX Interface Copyright (C) 2012 Jonathan Currie (I2C2) +% Modified for GERAD version by C.Tribes \ No newline at end of file diff --git a/examples/interfaces/Matlab_MEX/nomadset.m b/examples/interfaces/Matlab_MEX/nomadset.m new file mode 100755 index 0000000000000000000000000000000000000000..19b7aa00eba29391e31ac925fa1958e9c43ff7e5 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/nomadset.m @@ -0,0 +1,343 @@ +function options = nomadset(varargin) +%NOMADSET Create or alter the options for Optimization with NOMAD +% +% options = nomadset('param1',value1,'param2',value2,...) creates an +% NOMAD options structure with the parameters 'param' set to their +% corresponding values in 'value'. Parameters not specified will be set to +% the NOMAD default. +% +% options = nomadset(oldopts,'param1',value1,...) creates a copy of the old +% options 'oldopts' and then fills in (or writes over) the parameters +% specified by 'param' and 'value'. +% +% options = nomadset() creates an options structure with all fields set to +% NOMADSET defaults. +% +% nomadset() prints a list of all possible fields and their function. + +% Copyright (C) 2012 Jonathan Currie (I2C2) +% modif CT june 12, 2014 --->�version 1.22_ct +%Valid direction types +global dirtypes +dirtypes = {'ortho 1','ortho 2','ortho n+1','ortho n+1 quad','ortho n+1 neg','ortho','ortho 2n','lt 1','lt 2','lt 2n','lt n+1','gps binary','gps 2n static',... + 'gps 2n rand','gps n+1 static uniform','gps n+1 static','gps n+1 rand uniform','gps n+1 rand'}; + +% Print out possible values of properties. +if (nargin == 0) && (nargout == 0) + printfields(); + return +end + +%Names and Defaults +Names = {'bb_input_type','bb_output_type','direction_type','f_target','initial_mesh_size','lh_search','max_bb_eval','bb_max_block_size',... + 'max_time','model_eval_sort','model_search','multi_nb_mads_runs','multi_overall_bb_eval','opportunistic_eval','opportunistic_lh','seed','vns_search',... + 'cache_search','h_max_0','h_min','h_norm','initial_mesh_index','l_curve_target','max_cache_memory','max_consecutive_failed_iterations',... + 'max_eval','max_iterations','max_mesh_index','max_sim_bb_eval','mesh_coarsening_exponent','mesh_refining_exponent','mesh_update_basis',... + 'min_mesh_size','min_poll_size','model_eval_sort_cautious','model_search_max_trial_pts','model_search_optimistic','model_search_proj_to_mesh',... + 'model_quad_max_y_size','model_quad_min_y_size','model_quad_radius_factor','model_quad_use_wp','multi_f_bounds','multi_formulation','multi_use_delta_crit',... + 'neighbors_mat','opportunistic_cache_search','opportunistic_lucky_eval','opportunistic_min_eval','opportunistic_min_f_imprvmt','opportunistic_min_nb_success','rho','scaling','sec_poll_dir_type',... + 'snap_to_bounds','speculative_search','stat_sum_target','stop_if_feasible','add_seed_to_file_names','cache_file','cache_save_period','display_degree','display_all_eval',... + 'history_file','solution_file','stats_file','param_file','iterfun','disable','epsilon','opt_only_sgte','sgte_cost','sgte_eval_sort','has_sgte',... + 'sgte_cache_file','max_sgte_eval','anisotropic_mesh','fixed_variable'}'; +Defaults = {[],[],[],[],[],[],[],1,...%bb_max_block_size + [],1,1,[],[],1,1,[],0,... %vns_search + 0,1e20,[],'L2',[],[],2000,[],...%max_consecutive_failed_iterations + [],[],[],[],1,-1,4,... %mesh_update_basis + [],[],1,4,1,1,... %model_search_proj_to_mesh + [],500,2,0,[],'product',0,...%multi_use_delta_crit + [],0,0,[],[],[],0.1,[],[],...%sec_poll_dir_type + 1,1,[],0,1,[],25,0,0,... %display_all_eval + [],[],[],[],[],[],1e-13,0,[],1,0,...%has_sgte + [],[],1,''}'; + +%Collect Sizes and lowercase matches +m = size(Names,1); numberargs = nargin; +%Create structure with all names and default values +st = [Names,Defaults]'; options = struct(st{:}); + +% Check we have char or structure input. If structure, insert arguments +i = 1; +while i <= numberargs + arg = varargin{i}; + if ischar(arg) + break; + end + if ~isempty(arg) + if ~isa(arg,'struct') + error('An argument was supplied that wasn''t a string or struct!'); + end + for j = 1:m + if any(strcmp(fieldnames(arg),Names{j,:})) + val = arg.(Names{j,:}); + else + val = []; + end + if(~isempty(val)) + checkfield(Names{j,:},val); + options.(Names{j,:}) = val; + end + end + end + i = i + 1; +end + +%Check we have even number of args left +if rem(numberargs-i+1,2) ~= 0 + error('You do not have a value specified for each field!'); +end + +%Go through each argument pair and assign to correct field +expectval = 0; %first arg is a name +while i <= numberargs + arg = varargin{i}; + + switch(expectval) + case 0 %field + if ~ischar(arg) + error('Expected field name to be a string! - Argument %d',i); + end + j = find(strcmp(arg,Names) == 1); + if isempty(j) % if no matches + error('Unrecognised parameter %s',arg); + elseif(length(j) > 1) + error('Ambiguous parameter %s',arg); + end + expectval = 1; %next arg is a value + case 1 + if(~isempty(arg)) + if(iscell(arg)) + checkfield(Names{j,:},arg); + options.(Names{j,:}) = arg; + else + if(ischar(arg)), arg = lower(arg); end + checkfield(Names{j,:},arg); + options.(Names{j,:}) = arg; + end + end + expectval = 0; + end + i = i + 1; +end + +if expectval %fallen off end somehow + error('Missing value for %s',arg); +end +%Ensure we have absolute path +if(~isempty(options.param_file)) + options = checkParamFile(options); +end + + +function checkfield(field,value) +%Check a field contains correct data type +global dirtypes +err = []; + +switch lower(field) + %Scalar double + case {'f_target','max_bb_eval','bb_max_block_size','max_time','model_eval_sort',... + 'model_search','multi_nb_mads_runs','multi_overall_bb_eval','opportunistic_eval','opportunistic_lh','seed','vns_search',... + 'cache_search','h_max_0','h_min','initial_mesh_index','l_curve_target','max_cache_memory','max_consecutive_failed_iterations',... + 'max_eval','max_iterations','max_mesh_index','max_sim_bb_eval','mesh_coarsening_exponent','mesh_refining_exponent','mesh_update_basis',... + 'model_eval_sort_cautious','model_search_max_trial_pts','model_search_optimistic','model_search_proj_to_mesh',... + 'model_quad_max_y_size','model_quad_min_y_size','model_quad_radius_factor','model_quad_use_wp','multi_use_delta_crit',... + 'opportunistic_cache_search','opportunistic_lucky_eval','opportunistic_min_f_imprvmnt','opportunistic_min_nb_success','rho',... + 'snap_to_bounds','speculative_search','stat_sum_target','stop_if_feasible','add_seed_to_file_names','cache_save_period','display_degree',... + 'display_all_eval','has_sgte','sgte_cost','sgte_eval_sort','opt_only_sgte','epsilon','max_sgte_eval','anisotropic_mesh'} + if(~isscalar(value) || ~isnumeric(value) || ~isreal(value) || ~isa(value,'double')) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should be a real scalar double',field); + end + + %Direction Type + case {'direction_type','sec_poll_dir_type'} + if(~ischar(value) || ~any(strcmp(value,dirtypes))) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should match one of those displayed by nomadset()',field); + end + + %Disable + case 'disable' + if(~ischar(value) || ~any(strcmp(value,{'models'}))) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should be one of {''models''}',field); + end + + %String + case {'cache_file','history_file','solution_file','stats_file','param_file','multi_formulation','h_norm',... + 'lh_search','multi_f_bounds','sgte_cache_file'} + if(~ischar(value)) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should be a char array (string)',field); + end + + %string or cell of strings + case {'bb_output_type','bb_input_type','initial_mesh_size','min_mesh_size','min_poll_size','scaling','fixed_variable'} + if(~ischar(value) && ~iscell(value)) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should be a string or cell array of strings',field); + elseif(iscell(value)) + for i = 1:numel(value) + if(~ischar(value{i})) + err = MException('NOMAD:SetFieldError','Parameter ''%s'' cell(%d) should be a string',field,i); + break; + end + end + end + + %function_handle + case {'iterfun','neighbors_mat'} + if(~isa(value,'function_handle')) % C.Tribes june 12, 2014 ~isa instead of isa + err = MException('NOMAD:SetFieldError','Parameter ''%s'' should be a function handle',field); + end + + otherwise + err = MException('OPTI:SetFieldError','Unrecognized parameter name ''%s''.', field); +end +if(~isempty(err)), throw(err); end + + +function opts = checkParamFile(opts) +%Check parameter file exists and collect absolute path +filename = opts.param_file; +%See if we got an absolute path +switch(computer) + case {'PCWIN','PCWIN64'} + if(~isempty(strfind(filename,':'))) + p = filename; + %Check it exists + if(exist(filename,'file') ~= 2) + error('Cannot locate absolute file %s!',filename); + end + else + p = which(filename); + %Check it exists + if(isempty(p)) + error('Cannot locate file %s!',filename); + end + end + otherwise %Linux / Mac + if(filename(1) == '/') %absolute path (I think) + p = filename; + %Check it exists + if(exist(filename,'file') ~= 2) + error('Cannot locate absolute file %s!',filename); + end + else + p = which(filename); + %Check it exists + if(isempty(p)) + error('Cannot locate file %s!',filename); + end + end +end +%Save full path +opts.param_file = p; + + +function printfields() +%Print out fields with defaults + +global dirtypes + +fprintf('\nBASIC PROBLEM PARAMETERS:\n'); +fprintf(' bb_input_type: [ Blackbox input types, specified as a cell array of strings, overwrites xtype {[]} ] \n'); +fprintf(' bb_output_type: [ Blackbox output types, specified as a cell array of strings (see below) ] \n'); + +fprintf('\nBASIC ALGORITHMIC PARAMETERS:\n'); +fprintf(' direction_type: [ Type of directions for the poll (see below) {''ortho n+1 quad''} ] \n'); +fprintf(' f_target: [ Stop if f(x) < ftarget {[]} ] \n'); +fprintf(' initial_mesh_size: [ Initial Mesh Size (del_0^m) {[]} ]\n'); +fprintf(' lh_search: [ Latin-Hypercube Search (po and pi) {[]} ]\n'); +fprintf(' max_bb_eval: [ Maximum number of blackbox evaluations {[]} ] \n'); +fprintf(' max_time: [ Maximum execution time {[]} ] \n'); + +fprintf('\nADVANCED ALGORITHMIC PARAMETERS:\n'); +fprintf(' anisotropic_mesh: [ Use anisotropic mesh: No (0), Yes (1) = Default ] \n'); +fprintf(' bb_max_block_size: [ Maximum size of a block of evaluations given to the blackbox function {1} \n'); +fprintf(' cache_search: [ Use Cache search: Off {0}, On (1) ] \n'); +fprintf(' disable: [ Forcefully disable NOMAD features {[]} ] \n'); +fprintf(' fixed_variable: [ Fixed variable provided as ( 0.0 - 0.0 ) -> variables 0 and 2 are fixed; or as 1-10 0.0 -> variable 1 to 10 are fixed to 0.0 {[]} \n'); +fprintf(' h_max_0: [ Initial value of hmax {1e20} ] \n'); +fprintf(' h_min: [ x is feasible if h(x) >= v {0.0} ] \n'); +fprintf(' h_norm: [ Norm used to compute h: ''L1'', {''L2''}, ''Linf'' ] \n'); +fprintf(' has_sgte: [ Indicates if the problem has a surrogate function: No {0}, Yes {1} ] \n'); +fprintf(' initial_mesh_index: [ Initial Mesh Index {0} ] \n'); +fprintf(' l_curve_target: [ NOMAD terminates if objective may not reach this value {[]} ] \n'); +fprintf(' max_cache_memory: [ Maximum cache memory {2000} MB ] \n'); +fprintf(' max_consecutive_failed_iterations: [ Maximum number of failed MADS iterations {[]} ] \n'); +fprintf(' max_eval: [ Maximum number of evaluations (includes cache and bb) {[]} ] \n'); +fprintf(' max_iterations: [ Maximum number of iterations {[]} ] \n'); +fprintf(' max_mesh_index: [ Maximum Mesh Index {[]} ] \n'); +fprintf(' max_sgte_eval: [ Maximum Number of Surrogate Evaluations {[]} ] \n'); +fprintf(' max_sim_bb_eval: [ Maximum Simulated BB evaluations {[]} ] \n'); +fprintf(' mesh_coarsening_exponent: [ Mesh Coarsening Exponent {1} ] \n'); +fprintf(' mesh_refining_exponent: [ Mesh Refining Exponent {-1} ] \n'); +fprintf(' mesh_update_basis: [ Mesh Update Basis {4} ] \n'); +fprintf(' min_mesh_size: [ Minimum Mesh Size (del_min^m) {[]} ] \n'); +fprintf(' min_poll_size: [ Minimum Poll Size (del_min^p) {[]} ] \n'); +fprintf(' model_eval_sort: [ Use Quadratic Model to order points: Off (0), On {1} ] \n'); +fprintf(' model_search: [ Use Quadratic Model searches: Off (0), On {1} ] \n'); +fprintf(' model_search_optimistic: [ If the model search is optimistic : No (0), Yes {1} ] \n'); +fprintf(' multi_f_bounds: [ Vector of [f1min, f1max, f2min, f2max] for biobjective surf calculation {[]} ] \n'); +fprintf(' multi_nb_mads_runs: [ Number of MADS runs in Biobjective Optimization {[]} ] \n'); +fprintf(' multi_overall_bb_eval: [ Maximum number of BB evals for all MADS runs {[]} ] \n'); +fprintf(' neighbors_mat: [ Matlab function handle to obtain the neighboring points (use with categorical variables) {[]} ] \n'); +fprintf(' opportunistic_cache_search: [ Opportunistic cache search: Off {0}, On (1) ] \n'); +fprintf(' opportunistic_eval: [ Opportunistic strategy: Off (0), On {1} ] \n'); +fprintf(' opportunistic_lh: [ Opportunistic strategy for LH search: Off {0}, On (1)] \n'); +fprintf(' opportunistic_min_eval: [ Do not terminate below i evaluations {[]} ] \n'); +fprintf(' rho: [ Parameter of the progressive barrier {0.1} ] \n'); +fprintf(' scaling: [ Scaling on the variables (vector of scaling values for each variable) {[]} ] \n'); +fprintf(' seed: [ Random Seed: {[]} ] \n'); +fprintf(' sgte_cost: [ The cost of c surrogate evaluations is equivalent to one blackbox evaluation: {[]} ] \n'); +fprintf(' sgte_eval_sort: [ If surrogates are used to sort list of trial points: Off (0), On {1} ] \n'); +fprintf(' snap_to_bounds: [ Snap to boundary trial points that are generated outside of bounds: No (0), Yes {1} ] \n'); +fprintf(' speculative_search: [ MADS speculative search: No (0), Yes {1} ] \n'); +fprintf(' stat_sum_target: [ Terminates if stat_sum reaches this value {[]} ] \n'); +fprintf(' stop_if_feasible: [ Stop on first feasible solution: Off {0}, On (1) ] \n'); +fprintf(' vns_search: [ Variable Neighbourhood Search (Multiple Minima Problems): Off {0.0}, Max Searches (1.0) ] \n'); + + +fprintf('\nDEVELOPER PARAMETERS:\n'); +fprintf(' epsilon: [ Precision on real numbers {1e-13} ]\n'); +fprintf(' model_eval_sort_cautious: [ If the model ordering strategy is cautious: No (0), Yes {1} ] \n'); +fprintf(' model_search_max_trial_pts: [ Maximum trial points for one model search {4} ] \n'); +fprintf(' model_search_proj_to_mesh: [ If model search trial points are projected to mesh: No (0), Yes {1} ] \n'); +fprintf(' model_quad_max_y_size: [ Upper limit on the size of interpolation sets for quadratic models {500} ] \n'); +fprintf(' model_quad_min_y_size: [ Inf limit on the size of interpolation sets for quadratic models {[]} ] \n'); +fprintf(' model_quad_radius_factor: [ Quadratic Model search radius factor {2.0} ] \n'); +fprintf(' model_quad_use_wp: [ Enable strategy to maintain well-poised quadratic models: Off {0}, On (1) ] \n'); +fprintf(' multi_formulation: [ Single objective reformulation: ''normalized'', {''product''}, ''dist_l1'', ''dist_l2'', ''dist_linf'' ] \n'); +fprintf(' multi_use_delta_crit: [ Use stopping criterion based on the delta criterion: Off {0}, On (1) ] \n'); +fprintf(' opportunistic_lucky_eval: [ Perform an additional BB eval after an improvement: Off {0}, On (1) ] \n'); +fprintf(' opportunistic_min_f_imprvmt: [ Terminate only if f is reduced by r%% {[]} ] \n'); +fprintf('opportunistic_min_nb_success: [ Do not terminate before i successes {[]} ] \n'); +fprintf(' opt_only_sgte: [ Minimize only with surrogates: No {0}, Yes (1) ]\n'); +fprintf(' sec_poll_dir_type: [ Type of directions for the secondary poll (see below) {[]} ] \n'); + +fprintf('\nOUTPUT PARAMETERS:\n'); +fprintf(' add_seed_to_file_names: [ If the seed is added to the output file names: Off (0), On {1} ]\n'); +fprintf(' cache_file: [ Cache file: Off {[]}, On ''filename'' ]\n'); +fprintf(' cache_save_period: [ Cache files are saved every i iterations: {25} ]\n'); +fprintf(' display_degree: [ Display level: None {0}, Increasing (>0) ] \n'); +fprintf(' display_all_eval: [ Display all Points: Off {0}, On (1) ] \n'); +fprintf(' history_file: [ File containing all trial points: Off {[]}, On ''filename'' ]\n'); +fprintf(' solution_file: [ File to save the current best feasible point: Off {[]}, On ''filename'' ]\n'); +fprintf(' stats_file: [ File for screen dump: Off {[]}, On ''filename'' ]\n'); +fprintf(' sgte_cache_file: [ Surrogate cache file: Off {[]}, On ''filename'' ]\n'); + +fprintf('\nMEX INTERFACE PARAMETERS:\n'); +fprintf(' param_file: [ Read NOMAD options from a parameters file (overwrites these options): Off {[]}, On ''filename'' ]\n'); +fprintf(' iterfun: [ Callback function run every function evaluation: Off {[]}, On function_handle ]\n'); + + +fprintf('\n\nValid Direction Types (string):\n'); +for i = 1:length(dirtypes) + fprintf('''%s''\n',dirtypes{i}); +end +fprintf('\nValid BB_OUTPUT_TYPE types (cell array of strings):\n'); +fprintf('OBJ: Objective\n'); +fprintf(' PB: Progressive Barrier (default constraint type)\n'); +fprintf(' EB: Extreme Barrier\n'); +fprintf('PEB: Hybrid Constraint (PB/EB)\n'); +fprintf(' F: Filter\n'); + + + + diff --git a/examples/interfaces/Matlab_MEX/test_nomad_gerad.m b/examples/interfaces/Matlab_MEX/test_nomad_gerad.m new file mode 100755 index 0000000000000000000000000000000000000000..810ca83da05d0b6e2dd3882ade116bc912ff7487 --- /dev/null +++ b/examples/interfaces/Matlab_MEX/test_nomad_gerad.m @@ -0,0 +1,152 @@ +% GERAD VERSION TESTING + + +%% PROBLEM 1 +fun = @(x) (1-x(1))^2 + 100 *(x(2)-x(1)^2)^2; +x0 = [-2 1]'; +lb = [-Inf;-1.5]; +ub = [100;100]; +opts = nomadset('display_degree',2,'min_mesh_size','1e-004','initial_mesh_size','10'); + +% Start optimization +[x,fval] = nomad(fun,x0,lb,ub,opts); + + +%%Uncomment the following problems for further testing +% +% +% %% PROBLEM 2 +% %clc +% % Blackbox Function +% bb = @(x) [29.4*x(1) + 18*x(2); +% -(x(1) - 0.2458*x(1)^2/x(2)) + 6]; +% % Bounds +% lb = [0;1e-5]; +% ub = [115.8;30]; +% % Starting Guess +% x0 = [0;1e-5]; +% % Options +% opts = nomadset('display_degree',2,'bb_output_type','OBJ EB','max_bb_eval',50); +% +% [x,fval,ef,iter] = nomad(bb,x0,lb,ub,opts); +% +% +% +% +% %% PROBLEM 3 +% %clc +% % Blackbox Function +% bb = @(x) (1-x(1))^2 + 100 *(x(2)-x(1)^2)^2; +% % Starting Guess +% x0 = [0 0]'; +% opts = []; %not no nomadset just to keep user options +% opts.display_degree = 2; +% opts.direction_type = 'ortho n+1'; +% opts.max_bb_eval = 2; +% % Solve +% [x,fval,ef,iter] = nomad(bb,x0,[],[],opts) +% +% %% PROBLEM 4 [fval = -2.5] +% %clc +% fun = @(x) [-x(1) - x(2) - x(3); +% (x(2) - 1./2.)*(x(2) - 1./2.) + (x(3) - 1./2.)*(x(3) - 1./2.) - 1/4; +% x(1) - x(2); +% x(1) + x(3) + x(4) - 2]; +% ub = [1;10;10;5]; +% lb = [0;0;0;0]; +% x0 = [0;0;0;0]; +% +% opts = []; %not no nomadset just to keep user options +% opts.display_degree = 2; +% opts.bb_output_type = 'OBJ PB PB PB'; +% opts.bb_input_type = '[B R R I]'; +% opts.model_search = 'false'; +% opts.model_eval_sort = 'false'; +% +% [xr,fval,ef,iter] = nomad(fun,x0,lb,ub,opts) +% +% +% %% REMAINDER OF PROBLEMS OK +% +% %% Rosenbrock [x = 1,1, fval = 0] +% %clc +% % Blackbox Function +% bb = @(x) (1-x(1))^2 + 100 *(x(2)-x(1)^2)^2; +% % Starting Guess +% x0 = [0 0]'; +% % Solve +% [x,fval,ef,iter] = nomad(bb,x0) +% +% %% St_e01 [x = 6,0.6667, fval = -6.6667] +% %clc +% % Blackbox Function +% bb = @(x) [-x(1) - x(2); +% x(1)*x(2) - 4]; +% % Bounds +% lb = [0;0]; +% ub = [6;4]; +% % Starting Guess +% x0 = [1,1]'; +% % Options +% opts = nomadset('display_degree',2,'bb_output_type','OBJ PB'); +% % Solve +% [x,fval,ef,iter] = nomad(bb,x0,lb,ub,opts) +% +% %% St_e08 [x = 0.1294, 0.4830, fval = 0.7418] +% %clc +% % Blackbox Function +% bb = @(x) [2*x(1)+x(2); +% -16*x(1)*x(2) + 1; +% (-4*x(1)^2) - 4*x(2)^2 + 1]; +% % Bounds +% lb = [0;0]; +% ub = [1;1]; +% % Starting Guess +% x0 = [0;0]; +% % Options +% opts = nomadset('display_degree',2,'bb_output_type','OBJ PB PB'); +% +% [x,fval,ef,iter] = nomad(bb,x0,lb,ub,opts) +% +% %% Wolfram problem (multiple global minima fval = 0) +% %clc +% % Fitting Function +% obj = @(x) [x(1) - sin(2*x(1) + 3*x(2)) - cos(3*x(1) - 5*x(2)); +% x(2) - sin(x(1) - 2*x(2)) + cos(x(1) + 3*x(2))]; +% % Blackbox Function +% bb = @(x) norm(obj(x)); +% +% % Bounds +% lb = [-4;-4]; +% ub = [4;4]; +% % Starting Guess +% x0 = [0;-3]; +% % Options +% opts = nomadset('display_degree',2,'vns_search',0.9,'f_target',1e-6); +% +% [x,fval,ef,iter] = nomad(bb,x0,lb,ub,opts) +% +% %% MINLP 1 [fval = -5] +% clc +% fun = @(x) [ (x(1) - 5)^2 + x(2)^2 - 25; +% x(1)^2 - x(2) + 0.5 ]; +% x0 = [0;0]; +% opts = nomadset('display_degree',2,'bb_input_type','[I I]','bb_output_type','OBJ PB'); +% [xr,fval,ef,iter] = nomad(fun,x0,[],[],opts) +% +% %% Bi-Objective (NOMAD Example) +% %clc +% % Blackbox Function +% bb = @(x) [x(5); +% sum((x-1).^2)-25; +% 25-sum((x+1).^2)]; +% % Bounds +% lb = [-6;-6;-6;-6;-6]; +% ub = [5;6;7;Inf;Inf]; +% % Starting Guess +% x0 = [0;0;0;0;0]; +% % Options +% % note the setting of bb_output_type in order to specify two objectives +% opts = nomadset('display_degree',2,'multi_overall_bb_eval',100,'bb_output_type','obj obj eb'); +% +% [xr,fval,ef,iter] = nomad(bb,x0,lb,ub,opts) diff --git a/install/install.sh b/install/install.sh index b359c46dc93ad9a72e9606ca5544de979bb3f610..a38c84720e6b88b2f67fdc093cd212786dbc99f4 100755 --- a/install/install.sh +++ b/install/install.sh @@ -1,9 +1,9 @@ #!/bin/bash #-------------------------------------------------------------------------------------*/ -# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.5.1 */ +# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.7.2 */ # */ -# Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +# Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ # Charles Audet - Ecole Polytechnique, Montreal */ # Gilles Couture - Ecole Polytechnique, Montreal */ # John Dennis - Rice University, Houston */ @@ -38,7 +38,7 @@ # echo "*****************************************************" -echo " NOMAD 3.6.0 Installation Script " +echo " NOMAD 3.7.2 Installation Script " echo " usage: ./install.sh [nparallel] " echo " - nparallel : number of parallel process to make " echo "*****************************************************" @@ -56,16 +56,27 @@ echo "Testing gcc and mpi libraries" cd ${BASEDIR}/../src -VersionGCC=(`g++ -v 2>&1 | awk '$2 ~ /version/ {print $3}' | awk -F . '{print $1; print $2;print $3}'`) +VersionGCC=(`g++ -v 2>&1 | awk '$1 ~ /gcc/ && $2 ~ /version/ {print $3}' | awk -F . '{print $1; print $2;print $3}'`) if [ ${#VersionGCC[@]} -eq 0 ]; then - echo "======> gcc not installed. Failure of NOMAD installation " - exit 1; -fi - -if [ ${VersionGCC[0]} -gt 3 ]; then - echo "=======> gcc Version ${VersionGCC[0]}.${VersionGCC[1]}.${VersionGCC[2]} ---> ok" + echo "======> gcc not installed." + + VersionCLANG=(`g++ -v 2>&1 | awk '$1 ~ /Apple/ && $2 ~ /LLVM/ && $3 ~ /version/ {print $4}' | awk -F . '{print $1; print $2}'`) + if [ ${#VersionCLANG[@]} -eq 0 ]; then + echo "======> CLANG not installed. No supported compiler is available." + exit 1 + else + if [ ${VersionCLANG[0]} -gt 4 ]; then + echo "=======> CLANG Version ${VersionCLANG[0]}.${VersionCLANG[1]} ---> ok" + else + echo "=======> CLANG Version ${VersionCLANG[0]}.${VersionCLANG[1]} ---> Version of CLANG < 5 has not been tested for Nomad! Let us try to compile anyway." + fi + fi else - echo "=======> gcc Version ${VersionGCC[0]}.${VersionGCC[1]}.${VersionGCC[2]} ---> Version of gcc < 4 has not been tested for Nomad! Let us try to compile anyway." + if [ ${VersionGCC[0]} -gt 3 ]; then + echo "=======> gcc Version ${VersionGCC[0]}.${VersionGCC[1]}.${VersionGCC[2]} ---> ok" + else + echo "=======> gcc Version ${VersionGCC[0]}.${VersionGCC[1]}.${VersionGCC[2]} ---> Version of gcc < 4 has not been tested for Nomad! Let us try to compile anyway." + fi fi @@ -73,19 +84,32 @@ fi echo "Testing mpic++ " VersionMPICPP=(`mpic++ -v 2>&1 | awk '$2 ~ /version/ {print $3}' | awk -F . '{print $1; print $2;print $3}'`) if [ ${#VersionMPICPP[@]} -eq 0 ]; then - echo "======> mpic++ wrapper not available." - echo "Testing if MPI header available" - mpiHeaderAvailable=(`g++ -c nomad.cpp -DUSE_MPI 2>&1 | awk 'BEGIN{FS=":"} /mpi.h/ || /fatal error/ {Success=1;exit} END{print Success}' Success=0`) - if [ ${mpiHeaderAvailable} -eq 1 ]; then - echo "======> mpi.h not available. NOMAD Parallel version will not be compiled." - makeMPI=1 + echo "======> mpic++ (gcc) wrapper not available." + + VersionMPICLANG=(`mpic++ -v 2>&1 | awk '$1 ~ /Apple/ && $2 ~ /LLVM/ && $3 ~ /version/ {print $4}' | awk -F . '{print $1; print $2}'`) + if [ ${#VersionMPICLANG[@]} -eq 0 ]; then + echo "======> MPI wrapper for CLANG not installed." + echo "Testing if MPI header available" + mpiHeaderAvailable=(`g++ -c nomad.cpp -DUSE_MPI 2>&1 | awk 'BEGIN{FS=":"} /mpi.h/ || /fatal error/ {Success=1;exit} END{print Success}' Success=0`) + if [ ${mpiHeaderAvailable} -eq 1 ]; then + echo "======> mpi.h not available. NOMAD Parallel version will not be compiled." + makeMPI=1 + else + echo "======> mpi.h is present. Proper installation of MPI is supposed available and NOMAD parallel version will be compiled." + makeMPI=0 + COMPILATOR_MPI="g++" + fi else - echo "======> mpi.h is present. Proper installation of MPI is supposed available and NOMAD parallel version will be compiled." + if [ ${VersionMPICLANG[0]} -gt 4 ]; then + echo "=======> MPI wrapper for CLANG Version ${VersionCLANG[0]}.${VersionCLANG[1]} ---> ok" + else + echo "=======> MPI wrapper for CLANG Version ${VersionCLANG[0]}.${VersionCLANG[1]} ---> Version of CLANG < 5 has not been tested for Nomad! Let us try to compile anyway." + fi makeMPI=0 - COMPILATOR_MPI="g++" + COMPILATOR_MPI="mpic++" fi else - echo "=======> mpicc++ Version ${VersionMPICPP[0]}.${VersionMPICPP[1]}.${VersionMPICPP[2]} ---> ok" + echo "=======> mpicc++ wrapper for gcc version ${VersionMPICPP[0]}.${VersionMPICPP[1]}.${VersionMPICPP[2]} ---> ok" makeMPI=0 COMPILATOR_MPI="mpic++" fi diff --git a/nomad.spec b/nomad.spec index 6adc6aeb0a085a8e6c0be1ccf61b36975edae1ae..b324c318b5f1d91b15ea67dc5aad6173e11ca306 100644 --- a/nomad.spec +++ b/nomad.spec @@ -1,7 +1,7 @@ %define _prefix /usr Name: nomad -Version: 3.6.1 +Version: 3.7.2 Release: 1 Summary: NOMAD (Nonsmooth Optimization by Mesh Adaptive Direct Search) License: LGPL diff --git a/readme.txt b/readme.txt index 96df2cf5b1780d15a5667ef47fc3758e112241ca..4966d0ca513aa3232b18f363a00667390907fe0d 100644 --- a/readme.txt +++ b/readme.txt @@ -1,115 +1,114 @@ -####################################################################################### -# # -# README # -# # -####################################################################################### -# # -# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search # -# V 3.6.1 # -# 2013/05 # -# # -# Copyright (C) 2001-2013 # -# # -# Mark Abramson - the Boeing Company, Seattle # -# Charles Audet - Ecole Polytechnique, Montreal # -# Gilles Couture - Ecole Polytechnique, Montreal # -# John Dennis - Rice University, Houston # -# Sebastien Le Digabel - Ecole Polytechnique, Montreal # -# Christophe Tribes - Ecole Polytechnique, Montreal # -# # -#-------------------------------------------------------------------------------------# -# # -# Contact information: # -# Ecole Polytechnique de Montreal - GERAD # -# C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada # -# e-mail: nomad@gerad.ca # -# phone : 1-514-340-6053 #6928 # -# fax : 1-514-340-5665 # -# # -# This program is free software: you can redistribute it and/or modify it under the # -# terms of 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. # -# # -# This program 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 Lesser General Public License for more details. # -# # -# -# You should have received a copy of the GNU Lesser General Public License along # -# with this program. If not, see <http://www.gnu.org/licenses/>. # -# # -# You can find information on the NOMAD software at www.gerad.ca/nomad # -####################################################################################### - - - AUTHORS : - -* Mark A. Abramson (Mark.A.Abramson@boeing.com), The Boeing Company. - -* Charles Audet (www.gerad.ca/Charles.Audet), GERAD and Departement de -mathematiques et de genie industriel, ecole Polytechnique de Montreal. - -* J.E. Dennis Jr. (www.caam.rice.edu/~dennis), Computational and Applied -Mathematics Department, Rice University. - -* Sebastien Le Digabel (www.gerad.ca/Sebastien.Le.Digabel), GERAD and Departement -de mathematiques et de genie industriel, ecole Polytechnique de Montreal. - -* Christophe Tribes, GERAD, Departement -de mathematiques et de genie industriel, Department of mechanical engineering, ecole Polytechnique de Montreal. - - DESCRIPTION : - -NOMAD is a C++ implementation of the Mesh Adaptive Direct Search (MADS) algorithm, -designed for constrained optimization of black-box functions. - -The project started in 2001, and was funded in part by AFOSR, CRIAQ, FQRNT, LANL, -NSERC, the Boeing Company, and ExxonMobil Upstream Research Company. - - - WEB PAGE : - -http://www.gerad.ca/nomad/ - - - FURTHER INSTRUCTIONS : - -Please visit the web page for futher instruction on the following: - - * Downloading, configuring, compiling, and installing NOMAD - * Using NOMAD and setting the parameters - * Reports on NOMAD - * How to report bugs and make enhancement requests - * And more... - - - BATCH OR LIBRARY MODE : - -NOMAD is designed to be used in two different modes : batch and library. -The batch mode is intended for a basic ans simple usage of the MADS method, -while the library mode allows more flexibility. -For example, in batch mode, users must define their separate black-box program, -that will be called with system calls by NOMAD. -In library mode, users can define their black-box function as C++ code -that will be directly called by NOMAD, without system calls and temporary files. - - - TYPES OF USE : - -There are two ways of using NOMAD, one can directly use an executable or compile -the source code. - -NOMAD batch mode executable is located in directory $NOMAD_HOME/bin or %NOMAD_HOME%\bin. -In order to avoid compiling the code, you can simply use this executable. - - - HOW TO EXECUTE NOMAD : - -For informations about the execution of NOMAD, please read the user guide : - - $NOMAD_HOME/doc/user_guide.pdf or %NOMAD_HOME%\doc\user_guide.pdf - -or - - http://www.gerad.ca/NOMAD/Downloads/user_guide.pdf +####################################################################################### +# # +# README # +# # +####################################################################################### +# # +# NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search # +# V 3.7.2 # +# # +# Copyright (C) 2001-2015 # +# # +# Mark Abramson - the Boeing Company, Seattle # +# Charles Audet - Ecole Polytechnique, Montreal # +# Gilles Couture - Ecole Polytechnique, Montreal # +# John Dennis - Rice University, Houston # +# Sebastien Le Digabel - Ecole Polytechnique, Montreal # +# Christophe Tribes - Ecole Polytechnique, Montreal # +# # +#-------------------------------------------------------------------------------------# +# # +# Contact information: # +# Ecole Polytechnique de Montreal - GERAD # +# C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada # +# e-mail: nomad@gerad.ca # +# phone : 1-514-340-6053 #6928 # +# fax : 1-514-340-5665 # +# # +# This program is free software: you can redistribute it and/or modify it under the # +# terms of 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. # +# # +# This program 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 Lesser General Public License for more details. # +# # +# +# You should have received a copy of the GNU Lesser General Public License along # +# with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +# You can find information on the NOMAD software at www.gerad.ca/nomad # +####################################################################################### + + + AUTHORS : + +* Mark A. Abramson (Mark.A.Abramson@boeing.com), The Boeing Company. + +* Charles Audet (www.gerad.ca/Charles.Audet), GERAD and Departement de +mathematiques et de genie industriel, ecole Polytechnique de Montreal. + +* J.E. Dennis Jr. (www.caam.rice.edu/~dennis), Computational and Applied +Mathematics Department, Rice University. + +* Sebastien Le Digabel (www.gerad.ca/Sebastien.Le.Digabel), GERAD and Departement +de mathematiques et de genie industriel, ecole Polytechnique de Montreal. + +* Christophe Tribes, GERAD, Departement +de mathematiques et de genie industriel, Department of mechanical engineering, ecole Polytechnique de Montreal. + + DESCRIPTION : + +NOMAD is a C++ implementation of the Mesh Adaptive Direct Search (MADS) algorithm, +designed for constrained optimization of black-box functions. + +The project started in 2001, and was funded in part by AFOSR, CRIAQ, FQRNT, LANL, +NSERC, the Boeing Company, and ExxonMobil Upstream Research Company. + + + WEB PAGE : + +http://www.gerad.ca/nomad/ + + + FURTHER INSTRUCTIONS : + +Please visit the web page for futher instruction on the following: + + * Downloading, configuring, compiling, and installing NOMAD + * Using NOMAD and setting the parameters + * Reports on NOMAD + * How to report bugs and make enhancement requests + * And more... + + + BATCH OR LIBRARY MODE : + +NOMAD is designed to be used in two different modes : batch and library. +The batch mode is intended for a basic ans simple usage of the MADS method, +while the library mode allows more flexibility. +For example, in batch mode, users must define their separate black-box program, +that will be called with system calls by NOMAD. +In library mode, users can define their black-box function as C++ code +that will be directly called by NOMAD, without system calls and temporary files. + + + TYPES OF USE : + +There are two ways of using NOMAD, one can directly use an executable or compile +the source code. + +NOMAD batch mode executable is located in directory $NOMAD_HOME/bin or %NOMAD_HOME%\bin. +In order to avoid compiling the code, you can simply use this executable. + + + HOW TO EXECUTE NOMAD : + +For informations about the execution of NOMAD, please read the user guide : + + $NOMAD_HOME/doc/user_guide.pdf or %NOMAD_HOME%\doc\user_guide.pdf + +or + + http://www.gerad.ca/NOMAD/Downloads/user_guide.pdf diff --git a/src/Barrier.cpp b/src/Barrier.cpp index ffbe2b8340333084104433d9e92bf3f71d8062a4..ab768cdbd7fb1202821e41dac2c4c8276b42070e 100644 --- a/src/Barrier.cpp +++ b/src/Barrier.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Barrier.cpp - \brief Barrier for constraints handling (implementation) - \author Sebastien Le Digabel - \date 2010-04-12 - \see Barrier.hpp -*/ + \file Barrier.cpp + \brief Barrier for constraints handling (implementation) + \author Sebastien Le Digabel + \date 2010-04-12 + \see Barrier.hpp + */ #include "Barrier.hpp" /*---------------------------------------------------------*/ @@ -47,25 +47,25 @@ /*---------------------------------------------------------*/ void NOMAD::Barrier::reset ( void ) { - _prefilter.clear(); - _filter.clear(); - _h_max = _p.get_h_max_0(); - _best_feasible = NULL; - _ref = NULL; - _rho_leaps = 0; - _poll_center = NULL; - _sec_poll_center = NULL; - - if ( _peb_changes > 0 ) - _p.reset_PEB_changes(); - - _peb_changes = 0; - _peb_filter_reset = 0; - - _peb_lop.clear(); - _all_inserted.clear(); - - _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; + _prefilter.clear(); + _filter.clear(); + _h_max = _p.get_h_max_0(); + _best_feasible = NULL; + _ref = NULL; + _rho_leaps = 0; + _poll_center = NULL; + _sec_poll_center = NULL; + + if ( _peb_changes > 0 ) + _p.reset_PEB_changes(); + + _peb_changes = 0; + _peb_filter_reset = 0; + + _peb_lop.clear(); + _all_inserted.clear(); + + _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; } /*---------------------------------------------------------*/ @@ -73,49 +73,49 @@ void NOMAD::Barrier::reset ( void ) /*---------------------------------------------------------*/ void NOMAD::Barrier::display ( const Display & out ) const { - if ( _eval_type == NOMAD::SGTE ) - out << "surrogate barrier" << std::endl; - - if ( _p.get_barrier_type() == NOMAD::EB ) - out << "extreme barrier (EB)" << std::endl; - - else { - - out << "type : " - << ( (_p.get_barrier_type()==NOMAD::FILTER) ? "filter" : "progressive" ) - << std::endl - << "h_norm : " << _p.get_h_norm() << std::endl - << "h_min : " << _p.get_h_min() << std::endl - << "h_max : " << _h_max << std::endl; - if ( _p.get_barrier_type()==NOMAD::PB || _p.get_barrier_type()==NOMAD::PEB_P ) { - out << "poll center trigger rho : " << _p.get_rho() << std::endl - << "number of trigger leaps : " << _rho_leaps << std::endl; - if ( _p.get_barrier_type()==NOMAD::PEB_P ) - out << "number of PEB changes : " << _peb_changes << std::endl - << "number of PEB filter resets: " << _peb_filter_reset << std::endl; + if ( _eval_type == NOMAD::SGTE ) + out << "surrogate barrier" << std::endl; + + if ( _p.get_barrier_type() == NOMAD::EB ) + out << "extreme barrier (EB)" << std::endl; + + else { + + out << "type : " + << ( (_p.get_barrier_type()==NOMAD::FILTER) ? "filter" : "progressive" ) + << std::endl + << "h_norm : " << _p.get_h_norm() << std::endl + << "h_min : " << _p.get_h_min() << std::endl + << "h_max : " << _h_max << std::endl; + if ( _p.get_barrier_type()==NOMAD::PB || _p.get_barrier_type()==NOMAD::PEB_P ) { + out << "poll center trigger rho : " << _p.get_rho() << std::endl + << "number of trigger leaps : " << _rho_leaps << std::endl; + if ( _p.get_barrier_type()==NOMAD::PEB_P ) + out << "number of PEB changes : " << _peb_changes << std::endl + << "number of PEB filter resets: " << _peb_filter_reset << std::endl; + } + if ( out.get_gen_dd() == NOMAD::FULL_DISPLAY ) + out << "number of pre-filter points: " << static_cast<int>(_prefilter.size()) + << std::endl; + out << NOMAD::open_block ( "list of filter points (" + + NOMAD::itos ( _filter.size() ) + + ")" ) + << std::endl; + std::set<NOMAD::Filter_Point>::const_iterator end = _filter.end() , it; + for ( it = _filter.begin() ; it != end ; ++it ) + out << *it->get_point() << std::endl; + out.close_block(); } - if ( out.get_gen_dd() == NOMAD::FULL_DISPLAY ) - out << "number of pre-filter points: " << static_cast<int>(_prefilter.size()) - << std::endl; - out << NOMAD::open_block ( "list of filter points (" - + NOMAD::itos ( _filter.size() ) - + ")" ) - << std::endl; - std::set<NOMAD::Filter_Point>::const_iterator end = _filter.end() , it; - for ( it = _filter.begin() ; it != end ; ++it ) - out << *it->get_point() << std::endl; - out.close_block(); - } - + #ifdef DEBUG - out << NOMAD::open_block ( "list of inserted points (" - + NOMAD::itos ( _all_inserted.size() ) - + ")" ) - << std::endl; - std::list<const NOMAD::Eval_Point *>::const_iterator it2 , end2 = _all_inserted.end(); - for ( it2 = _all_inserted.begin() ; it2 != end2 ; ++it2 ) - out << **it2 << std::endl; - out.close_block(); + out << NOMAD::open_block ( "list of inserted points (" + + NOMAD::itos ( _all_inserted.size() ) + + ")" ) + << std::endl; + std::list<const NOMAD::Eval_Point *>::const_iterator it2 , end2 = _all_inserted.end(); + for ( it2 = _all_inserted.begin() ; it2 != end2 ; ++it2 ) + out << **it2 << std::endl; + out.close_block(); #endif } @@ -124,40 +124,40 @@ void NOMAD::Barrier::display ( const Display & out ) const /*------------------------------------------------------------*/ void NOMAD::Barrier::update_and_reset_success ( void ) { - if ( ( _p.get_barrier_type() == NOMAD::PB || _p.get_barrier_type() == NOMAD::PEB_P ) && - _success != NOMAD::UNSUCCESSFUL ) { - - if ( _success == NOMAD::PARTIAL_SUCCESS ) { - - if ( _filter.empty() ) - throw Barrier::Update_Error ( "Barrier.cpp" , __LINE__ , - "filter empty after a partial success" ); - - std::set<NOMAD::Filter_Point>::const_iterator it = _filter.end(); - --it; - - while ( true ) { - - if ( it->get_point()->get_h().value() < _h_max.value() ) { - set_h_max ( it->get_point()->get_h() ); - break; - } - - if ( it == _filter.begin() ) - throw Barrier::Update_Error ( "Barrier.cpp" , __LINE__ , - "could not find a filter point with h < h_max after a partial success" ); - - --it; - } + if ( ( _p.get_barrier_type() == NOMAD::PB || _p.get_barrier_type() == NOMAD::PEB_P ) && + _success != NOMAD::UNSUCCESSFUL ) { + + if ( _success == NOMAD::PARTIAL_SUCCESS ) { + + if ( _filter.empty() ) + throw Barrier::Update_Error ( "Barrier.cpp" , __LINE__ , + "filter empty after a partial success" ); + + std::set<NOMAD::Filter_Point>::const_iterator it = _filter.end(); + --it; + + while ( true ) { + + if ( it->get_point()->get_h().value() < _h_max.value() ) { + set_h_max ( it->get_point()->get_h() ); + break; + } + + if ( it == _filter.begin() ) + throw Barrier::Update_Error ( "Barrier.cpp" , __LINE__ , + "could not find a filter point with h < h_max after a partial success" ); + + --it; + } + } + + _ref = get_best_infeasible(); + if ( _ref ) + set_h_max ( _ref->get_h() ); } - - _ref = get_best_infeasible(); - if ( _ref ) - set_h_max ( _ref->get_h() ); - } - - // reset success types: - _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; + + // reset success types: + _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; } /*---------------------------------------------------------*/ @@ -165,45 +165,45 @@ void NOMAD::Barrier::update_and_reset_success ( void ) /*---------------------------------------------------------*/ void NOMAD::Barrier::insert ( const NOMAD::Eval_Point & x ) { - // we compare the eval types (_SGTE_ or _TRUTH_) of x and *this: - if ( x.get_eval_type() != _eval_type ) - throw Barrier::Insert_Error ( "Barrier.cpp" , __LINE__ , - "insertion of an Eval_Point into the bad Barrier object" ); - - // basic check: - if ( !x.is_eval_ok() ) { - _one_eval_succ = NOMAD::UNSUCCESSFUL; - return; - } - - // pre-filter: if tag(x) is already in the pre-filter, - // then return _UNSUCCESSFUL_: - size_t size_before = _prefilter.size(); - _prefilter.insert ( x.get_tag() ); - if ( _prefilter.size() == size_before ) { - _one_eval_succ = NOMAD::UNSUCCESSFUL; - return; - } - - // insertion in _all_inserted: - _all_inserted.push_back ( &x ); - - // other checks: - const NOMAD::Double & h = x.get_h(); - if ( !x.is_EB_ok () || - !x.get_f().is_defined () || - !h.is_defined () || - h.value() > _h_max.value() ) { - _one_eval_succ = NOMAD::UNSUCCESSFUL; - return; - } - - // insert_feasible or insert_infeasible: - _one_eval_succ = ( x.is_feasible ( _p.get_h_min() ) ) ? + // we compare the eval types (_SGTE_ or _TRUTH_) of x and *this: + if ( x.get_eval_type() != _eval_type ) + throw Barrier::Insert_Error ( "Barrier.cpp" , __LINE__ , + "insertion of an Eval_Point into the bad Barrier object" ); + + // basic check: + if ( !x.is_eval_ok() ) { + _one_eval_succ = NOMAD::UNSUCCESSFUL; + return; + } + + // pre-filter: if tag(x) is already in the pre-filter, + // then return _UNSUCCESSFUL_: + size_t size_before = _prefilter.size(); + _prefilter.insert ( x.get_tag() ); + if ( _prefilter.size() == size_before ) { + _one_eval_succ = NOMAD::UNSUCCESSFUL; + return; + } + + // insertion in _all_inserted: + _all_inserted.push_back ( &x ); + + // other checks: + const NOMAD::Double & h = x.get_h(); + if ( !x.is_EB_ok () || + !x.get_f().is_defined () || + !h.is_defined () || + h.value() > _h_max.value() ) { + _one_eval_succ = NOMAD::UNSUCCESSFUL; + return; + } + + // insert_feasible or insert_infeasible: + _one_eval_succ = ( x.is_feasible ( _p.get_h_min() ) ) ? insert_feasible ( x ) : insert_infeasible(x); - - if ( _one_eval_succ > _success ) - _success = _one_eval_succ; + + if ( _one_eval_succ > _success ) + _success = _one_eval_succ; } /*---------------------------------------------------------*/ @@ -212,26 +212,25 @@ void NOMAD::Barrier::insert ( const NOMAD::Eval_Point & x ) /*---------------------------------------------------------*/ void NOMAD::Barrier::insert ( const Barrier & b ) { - _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; - - NOMAD::Eval_Point * modifiable_x; - - std::list<const NOMAD::Eval_Point *>::const_iterator it , end = b._all_inserted.end(); - for ( it = b._all_inserted.begin() ; it != end ; ++it ) { - - modifiable_x = &NOMAD::Cache::get_modifiable_point ( **it ); - - modifiable_x->set_direction ( NULL ); - modifiable_x->set_mesh_index ( NULL ); - modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); - modifiable_x->set_user_eval_priority ( NOMAD::Double() ); - modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); - - insert ( **it ); - - if ( _one_eval_succ > _success ) - _success = _one_eval_succ; - } + _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; + + NOMAD::Eval_Point * modifiable_x; + + std::list<const NOMAD::Eval_Point *>::const_iterator it , end = b._all_inserted.end(); + for ( it = b._all_inserted.begin() ; it != end ; ++it ) { + + modifiable_x = &NOMAD::Cache::get_modifiable_point ( **it ); + + modifiable_x->set_direction ( NULL ); + modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); + modifiable_x->set_user_eval_priority ( NOMAD::Double() ); + modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); + + insert ( **it ); + + if ( _one_eval_succ > _success ) + _success = _one_eval_succ; + } } /*---------------------------------------------------------*/ @@ -239,11 +238,11 @@ void NOMAD::Barrier::insert ( const Barrier & b ) /*---------------------------------------------------------*/ NOMAD::success_type NOMAD::Barrier::insert_feasible ( const NOMAD::Eval_Point & x ) { - if ( !_best_feasible || ( x.get_f().value() < _best_feasible->get_f().value() ) ) { - _best_feasible = &x; - return NOMAD::FULL_SUCCESS; - } - return NOMAD::UNSUCCESSFUL; + if ( !_best_feasible || ( x.get_f().value() < _best_feasible->get_f().value() ) ) { + _best_feasible = &x; + return NOMAD::FULL_SUCCESS; + } + return NOMAD::UNSUCCESSFUL; } /*---------------------------------------------------------*/ @@ -251,38 +250,38 @@ NOMAD::success_type NOMAD::Barrier::insert_feasible ( const NOMAD::Eval_Point & /*---------------------------------------------------------*/ void NOMAD::Barrier::filter_insertion ( const NOMAD::Eval_Point & x , bool & insert ) { - if ( _filter.empty() ) { - _filter.insert (&x); - insert = true; - } - else { - - insert = false; - std::set<NOMAD::Filter_Point>::iterator it = _filter.begin(); - while ( it != _filter.end() ) { - if ( x < *(it->get_point()) ) { - _filter.erase(it++); - insert = true; - continue; - } - - ++it; + if ( _filter.empty() ) { + _filter.insert (&x); + insert = true; } - - if ( !insert ) { - insert = true; - std::set<NOMAD::Filter_Point>::iterator end = _filter.end(); - for ( it = _filter.begin() ; it != end ; ++it ) { - if ( *(it->get_point()) < x ) { - insert = false; - break; - } - } + else { + + insert = false; + std::set<NOMAD::Filter_Point>::iterator it = _filter.begin(); + while ( it != _filter.end() ) { + if ( x < *(it->get_point()) ) { + _filter.erase(it++); + insert = true; + continue; + } + + ++it; + } + + if ( !insert ) { + insert = true; + std::set<NOMAD::Filter_Point>::iterator end = _filter.end(); + for ( it = _filter.begin() ; it != end ; ++it ) { + if ( *(it->get_point()) < x ) { + insert = false; + break; + } + } + } + + if ( insert ) + _filter.insert (&x); } - - if ( insert ) - _filter.insert (&x); - } } /*---------------------------------------------------------*/ @@ -290,56 +289,56 @@ void NOMAD::Barrier::filter_insertion ( const NOMAD::Eval_Point & x , bool & ins /*---------------------------------------------------------*/ NOMAD::success_type NOMAD::Barrier::insert_infeasible ( const NOMAD::Eval_Point & x ) { - const NOMAD::Eval_Point * old_bi = get_best_infeasible(); - - // filter insertion: - // ----------------- - bool insert; - filter_insertion ( x , insert ); - - // filter: - // ------- - if ( _p.get_barrier_type() == NOMAD::FILTER ) { - const NOMAD::Eval_Point * bi = get_best_infeasible(); - if ( !bi ) - return NOMAD::UNSUCCESSFUL; - if ( old_bi ) { - if ( bi->get_h().value() < old_bi->get_h().value() ) - return NOMAD::FULL_SUCCESS; - if ( insert ) - return NOMAD::PARTIAL_SUCCESS; - return NOMAD::UNSUCCESSFUL; + const NOMAD::Eval_Point * old_bi = get_best_infeasible(); + + // filter insertion: + // ----------------- + bool insert; + filter_insertion ( x , insert ); + + // filter: + // ------- + if ( _p.get_barrier_type() == NOMAD::FILTER ) { + const NOMAD::Eval_Point * bi = get_best_infeasible(); + if ( !bi ) + return NOMAD::UNSUCCESSFUL; + if ( old_bi ) { + if ( bi->get_h().value() < old_bi->get_h().value() ) + return NOMAD::FULL_SUCCESS; + if ( insert ) + return NOMAD::PARTIAL_SUCCESS; + return NOMAD::UNSUCCESSFUL; + } + return NOMAD::FULL_SUCCESS; } + + // progressive barrier: + // -------------------- + + // with PEB constraints, we remember all points that we tried to insert: + if ( _p.get_barrier_type() == NOMAD::PEB_P ) + _peb_lop.push_back ( &x ); + + // first infeasible successes are considered as partial successes + // (improving iterations) + if ( !_ref ) + return NOMAD::PARTIAL_SUCCESS; + + double hx = x.get_h().value(); + double fx = x.get_f().value(); + double hr = _ref->get_h().value(); + double fr = _ref->get_f().value(); + + // failure: + if ( hx > hr || ( hx == hr && fx >= fr ) ) + return NOMAD::UNSUCCESSFUL; + + // partial success: + if ( fx > fr ) + return NOMAD::PARTIAL_SUCCESS; + + // full success: return NOMAD::FULL_SUCCESS; - } - - // progressive barrier: - // -------------------- - - // with PEB constraints, we remember all points that we tried to insert: - if ( _p.get_barrier_type() == NOMAD::PEB_P ) - _peb_lop.push_back ( &x ); - - // first infeasible successes are considered as partial successes - // (improving iterations) - if ( !_ref ) - return NOMAD::PARTIAL_SUCCESS; - - double hx = x.get_h().value(); - double fx = x.get_f().value(); - double hr = _ref->get_h().value(); - double fr = _ref->get_f().value(); - - // failure: - if ( hx > hr || ( hx == hr && fx >= fr ) ) - return NOMAD::UNSUCCESSFUL; - - // partial success: - if ( fx > fr ) - return NOMAD::PARTIAL_SUCCESS; - - // full success: - return NOMAD::FULL_SUCCESS; } /*---------------------------------------------------------*/ @@ -347,28 +346,28 @@ NOMAD::success_type NOMAD::Barrier::insert_infeasible ( const NOMAD::Eval_Point /*---------------------------------------------------------*/ const NOMAD::Eval_Point * NOMAD::Barrier::get_best_infeasible ( void ) const { - if ( _filter.empty() || _p.get_barrier_type() == NOMAD::EB ) - return NULL; - - if ( _p.get_barrier_type() == NOMAD::FILTER ) - return _filter.begin()->get_point(); // original - - return (--_filter.end())->get_point(); // original + if ( _filter.empty() || _p.get_barrier_type() == NOMAD::EB ) + return NULL; + + if ( _p.get_barrier_type() == NOMAD::FILTER ) + return _filter.begin()->get_point(); // original + + return (--_filter.end())->get_point(); // original } /*---------------------------------------------------------*/ -/* get_best_infeasible_min_viol() */ +/* get_best_infeasible_min_viol() */ /*---------------------------------------------------------*/ const NOMAD::Eval_Point * NOMAD::Barrier::get_best_infeasible_min_viol ( void ) const { - if ( _filter.empty() || _p.get_barrier_type() == NOMAD::EB ) - return NULL; - - if ( _p.get_barrier_type() == NOMAD::FILTER ) - return (--_filter.end())->get_point(); - - return _filter.begin()->get_point(); + if ( _filter.empty() || _p.get_barrier_type() == NOMAD::EB ) + return NULL; + + if ( _p.get_barrier_type() == NOMAD::FILTER ) + return (--_filter.end())->get_point(); + + return _filter.begin()->get_point(); } @@ -378,79 +377,79 @@ const NOMAD::Eval_Point * NOMAD::Barrier::get_best_infeasible_min_viol ( void ) /*---------------------------------------------------------*/ void NOMAD::Barrier::select_poll_center ( NOMAD::success_type last_it_success ) { - const NOMAD::Eval_Point * best_infeasible = get_best_infeasible(); - - _sec_poll_center = NULL; - if ( !_best_feasible && !best_infeasible ) { - _poll_center = NULL; - return; - } - if ( !best_infeasible ) { - _poll_center = _best_feasible; - return; - } - if ( !_best_feasible ) { - _poll_center = best_infeasible; - return; - } - - // filter: - if ( _p.get_barrier_type() == NOMAD::FILTER ) { - - if ( !_poll_center ) { - _poll_center = _best_feasible; - return; + const NOMAD::Eval_Point * best_infeasible = get_best_infeasible(); + + _sec_poll_center = NULL; + if ( !_best_feasible && !best_infeasible ) { + _poll_center = NULL; + return; } - - // switch: - if ( last_it_success == NOMAD::UNSUCCESSFUL ) - _poll_center = ( _poll_center==best_infeasible ) ? - _best_feasible : best_infeasible; - return; - } - - // progressive barrier: - if ( _p.get_barrier_type() == NOMAD::PB || _p.get_barrier_type() == NOMAD::PEB_P ) { - - const NOMAD::Point * last_poll_center = _poll_center; - - if ( best_infeasible->get_f() < (_best_feasible->get_f() - _p.get_rho()) ) { - _poll_center = best_infeasible; - _sec_poll_center = _best_feasible; + if ( !best_infeasible ) { + _poll_center = _best_feasible; + return; } - else { - _poll_center = _best_feasible; - _sec_poll_center = best_infeasible; + if ( !_best_feasible ) { + _poll_center = best_infeasible; + return; + } + + // filter: + if ( _p.get_barrier_type() == NOMAD::FILTER ) { + + if ( !_poll_center ) { + _poll_center = _best_feasible; + return; + } + + // switch: + if ( last_it_success == NOMAD::UNSUCCESSFUL ) + _poll_center = ( _poll_center==best_infeasible ) ? + _best_feasible : best_infeasible; + return; + } + + // progressive barrier: + if ( _p.get_barrier_type() == NOMAD::PB || _p.get_barrier_type() == NOMAD::PEB_P ) { + + const NOMAD::Point * last_poll_center = _poll_center; + + if ( best_infeasible->get_f() < (_best_feasible->get_f() - _p.get_rho()) ) { + _poll_center = best_infeasible; + _sec_poll_center = _best_feasible; + } + else { + _poll_center = _best_feasible; + _sec_poll_center = best_infeasible; + } + if ( _poll_center != last_poll_center ) + ++_rho_leaps; } - if ( _poll_center != last_poll_center ) - ++_rho_leaps; - } } /*---------------------------------------------------------*/ /* change the value of _h_max (private) */ /*---------------------------------------------------------*/ void NOMAD::Barrier::set_h_max ( const NOMAD::Double & h_max ) -{ - // _h_max update: - _h_max = h_max; - - // we remove all filter points x such that h(x) > h_max: - if ( !_filter.empty() ) { - - if ( _filter.begin()->get_point()->get_h().value() > _h_max.value() ) { - _filter.clear(); - return; +{ + // _h_max update: + _h_max = h_max; + + // we remove all filter points x such that h(x) > h_max: + if ( !_filter.empty() ) { + + if ( _filter.begin()->get_point()->get_h().value() > _h_max.value() ) { + _filter.clear(); + return; + } + + std::set<NOMAD::Filter_Point>::iterator it = _filter.end(); + do + --it; + while ( it != _filter.begin() && + it->get_point()->get_h().value() > _h_max.value() ); + ++it; + _filter.erase ( it , _filter.end() ); } - - std::set<NOMAD::Filter_Point>::iterator it = _filter.end(); - do - --it; - while ( it != _filter.begin() && - it->get_point()->get_h().value() > _h_max.value() ); - ++it; - _filter.erase ( it , _filter.end() ); - } } /*--------------------------------------------------------*/ @@ -459,88 +458,88 @@ void NOMAD::Barrier::set_h_max ( const NOMAD::Double & h_max ) /*--------------------------------------------------------*/ void NOMAD::Barrier::check_PEB_constraints ( const NOMAD::Eval_Point & x , bool display ) { - const NOMAD::Double & h_min = _p.get_h_min(); - const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); - const NOMAD::Point & bbo = x.get_bb_outputs(); - int nb = static_cast<int>(bbot.size()); - std::list<int> ks; - - for ( int k = 0 ; k < nb ; ++k ) { - if ( bbot[k] == NOMAD::PEB_P && bbo[k] <= h_min ) { - if ( display ) - _p.out() << std::endl - << "change status of blackbox output " << k - << " from progressive barrier constraint to extreme barrier constraint" - << std::endl; - ++_peb_changes; - _p.change_PEB_constraint_status (k); - ks.push_back(k); - } - } - - // at least one constraint changed status, so we have to update the filter - // and remove all points that have their h value changed to infinity - // (it can add new dominant points from the list _peb_lop): - if ( !ks.empty() ) { - - std::list<int>::const_iterator it_k , end_k = ks.end() , begin_k = ks.begin(); - - // we inspect the filter points if some have to be removed; if so, - // all filter candidates (stored in _peb_lop) will be re-inserted - // into the filter: - bool reset_filter = false; - std::set<NOMAD::Filter_Point>::const_iterator end = _filter.end() , it; - - for ( it = _filter.begin() ; it != end ; ++it ) { - - const NOMAD::Point & bbo_cur = it->get_point()->get_bb_outputs(); - for ( it_k = begin_k ; it_k != end_k ; ++it_k ) - if ( bbo_cur[*it_k] > h_min ) { - reset_filter = true; - break; - } - if ( reset_filter ) - break; + const NOMAD::Double & h_min = _p.get_h_min(); + const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); + const NOMAD::Point & bbo = x.get_bb_outputs(); + int nb = static_cast<int>(bbot.size()); + std::list<int> ks; + + for ( int k = 0 ; k < nb ; ++k ) { + if ( bbot[k] == NOMAD::PEB_P && bbo[k] <= h_min ) { + if ( display ) + _p.out() << std::endl + << "change status of blackbox output " << k + << " from progressive barrier constraint to extreme barrier constraint" + << std::endl; + ++_peb_changes; + _p.change_PEB_constraint_status (k); + ks.push_back(k); + } } - - if ( reset_filter ) { - - if ( display ) - _p.out() << std::endl << "PEB change of status: filter reset" << std::endl; - - ++_peb_filter_reset; - - _filter.clear(); - bool insert; - - std::list<const NOMAD::Eval_Point *>::const_iterator end2 = _peb_lop.end (); - std::list<const NOMAD::Eval_Point *>::iterator it2 = _peb_lop.begin(); - - while ( it2 != end2 ) { - - insert = true; - const NOMAD::Point & bbo_cur = (*it2)->get_bb_outputs(); - - for ( it_k = begin_k ; it_k != end_k ; ++it_k ) - if ( bbo_cur[*it_k] > h_min ) { - insert = false; - break; - } - - // if insert==true: this point is potentially a new filter point: - if ( insert ) { - filter_insertion ( **it2 , insert ); - ++it2; - } - - // if insert==false: it means that the current filter point - // has to be removed from filter and from _peb_lop, and - // in addition, its h is put to INF: - else { - NOMAD::Cache::get_modifiable_point ( **it2 ).set_h ( NOMAD::Double() ); - _peb_lop.erase(it2++); - } - } + + // at least one constraint changed status, so we have to update the filter + // and remove all points that have their h value changed to infinity + // (it can add new dominant points from the list _peb_lop): + if ( !ks.empty() ) { + + std::list<int>::const_iterator it_k , end_k = ks.end() , begin_k = ks.begin(); + + // we inspect the filter points if some have to be removed; if so, + // all filter candidates (stored in _peb_lop) will be re-inserted + // into the filter: + bool reset_filter = false; + std::set<NOMAD::Filter_Point>::const_iterator end = _filter.end() , it; + + for ( it = _filter.begin() ; it != end ; ++it ) { + + const NOMAD::Point & bbo_cur = it->get_point()->get_bb_outputs(); + for ( it_k = begin_k ; it_k != end_k ; ++it_k ) + if ( bbo_cur[*it_k] > h_min ) { + reset_filter = true; + break; + } + if ( reset_filter ) + break; + } + + if ( reset_filter ) { + + if ( display ) + _p.out() << std::endl << "PEB change of status: filter reset" << std::endl; + + ++_peb_filter_reset; + + _filter.clear(); + bool insert; + + std::list<const NOMAD::Eval_Point *>::const_iterator end2 = _peb_lop.end (); + std::list<const NOMAD::Eval_Point *>::iterator it2 = _peb_lop.begin(); + + while ( it2 != end2 ) { + + insert = true; + const NOMAD::Point & bbo_cur = (*it2)->get_bb_outputs(); + + for ( it_k = begin_k ; it_k != end_k ; ++it_k ) + if ( bbo_cur[*it_k] > h_min ) { + insert = false; + break; + } + + // if insert==true: this point is potentially a new filter point: + if ( insert ) { + filter_insertion ( **it2 , insert ); + ++it2; + } + + // if insert==false: it means that the current filter point + // has to be removed from filter and from _peb_lop, and + // in addition, its h is put to INF: + else { + NOMAD::Cache::get_modifiable_point ( **it2 ).set_h ( NOMAD::Double() ); + _peb_lop.erase(it2++); + } + } + } } - } } diff --git a/src/Barrier.hpp b/src/Barrier.hpp index 0d9df296d71050ea90b513492582b6435f4e23e0..2b303a47e2233545f94a1e407f7115c1cab54e4c 100644 --- a/src/Barrier.hpp +++ b/src/Barrier.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache.cpp b/src/Cache.cpp index 6fd9d3008e9e71a7e00506f492790ab7a1277399..dea9a346d00e993655d5bc28698d2eb939c7a39f 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Cache.cpp - \brief Cache memorizing all evaluations (implementation) - \author Sebastien Le Digabel - \date 2010-04-12 - \see Cache.hpp -*/ + \file Cache.cpp + \brief Cache memorizing all evaluations (implementation) + \author Sebastien Le Digabel + \date 2010-04-12 + \see Cache.hpp + */ #include "Cache.hpp" /*-----------------------------------*/ @@ -52,7 +52,7 @@ std::set<std::string> NOMAD::Cache::_locked_files; /*------------------------------------------------------*/ int NOMAD::Cache::sizeof_init ( void ) const { - return + return sizeof ( _cache1 ) + sizeof ( _cache2 ) + sizeof ( _cache3 ) + @@ -67,8 +67,8 @@ int NOMAD::Cache::sizeof_init ( void ) const /*---------------------------------------------------------------------*/ void NOMAD::Cache::insert_extern_point ( const NOMAD::Eval_Point & x ) const { - if ( !x.get_current_run() ) - _extern_pts.push_front ( &x ); + if ( !x.get_current_run() ) + _extern_pts.push_front ( &x ); } /*----------------------------------------------------------*/ @@ -77,11 +77,11 @@ void NOMAD::Cache::insert_extern_point ( const NOMAD::Eval_Point & x ) const /*----------------------------------------------------------*/ const NOMAD::Eval_Point * NOMAD::Cache::get_and_remove_extern_point ( void ) const { - if ( _extern_pts.empty() ) - return NULL; - const NOMAD::Eval_Point * extern_point = *_extern_pts.begin(); - _extern_pts.pop_front(); - return extern_point; + if ( _extern_pts.empty() ) + return NULL; + const NOMAD::Eval_Point * extern_point = *_extern_pts.begin(); + _extern_pts.pop_front(); + return extern_point; } /*------------------------------------------*/ @@ -90,18 +90,18 @@ const NOMAD::Eval_Point * NOMAD::Cache::get_and_remove_extern_point ( void ) con /*------------------------------------------*/ const NOMAD::Eval_Point * NOMAD::Cache::find ( const NOMAD::Eval_Point & x ) const { - // check the eval types: - if ( x.get_eval_type() != _eval_type ) - throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , - "NOMAD::Cache:find(x): x.eval_type != cache.eval_type" ); - - // find: - std::set<NOMAD::Cache_Point>::const_iterator it; - NOMAD::cache_index_type cache_index; - const NOMAD::Eval_Point * cache_x + // check the eval types: + if ( x.get_eval_type() != _eval_type ) + throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , + "NOMAD::Cache:find(x): x.eval_type != cache.eval_type" ); + + // find: + std::set<NOMAD::Cache_Point>::const_iterator it; + NOMAD::cache_index_type cache_index; + const NOMAD::Eval_Point * cache_x = NOMAD::Cache::find ( x , it , cache_index ); - - return cache_x; + + return cache_x; } /*----------------------------------------------------*/ @@ -113,33 +113,33 @@ const NOMAD::Eval_Point * NOMAD::Cache::find ( const NOMAD::Eval_Point & x ) con /*----------------------------------------------------*/ const NOMAD::Eval_Point * NOMAD::Cache::find ( const NOMAD::Eval_Point & x , - std::set<NOMAD::Cache_Point>::const_iterator & it , - NOMAD::cache_index_type & cache_index ) const + std::set<NOMAD::Cache_Point>::const_iterator & it , + NOMAD::cache_index_type & cache_index ) const { - // search in _cache2 (points to write in a cache file): - NOMAD::Cache_Point cp ( &x ); - it = _cache2.find ( cp ); - if ( it != _cache2.end() ) { - cache_index = NOMAD::CACHE_2; - return it->get_point(); - } - - // search in _cache3 (points saved in a file): - it = _cache3.find ( cp ); - if ( it != _cache3.end() ) { - cache_index = NOMAD::CACHE_3; - return it->get_point(); - } - - // search in _cache1 (points read in an initial cache file): - it = _cache1.find ( cp ); - if ( it != _cache1.end() ) { - cache_index = NOMAD::CACHE_1; - return it->get_point(); - } - - cache_index = NOMAD::UNDEFINED_CACHE; - return NULL; + // search in _cache2 (points to write in a cache file): + NOMAD::Cache_Point cp ( &x ); + it = _cache2.find ( cp ); + if ( it != _cache2.end() ) { + cache_index = NOMAD::CACHE_2; + return it->get_point(); + } + + // search in _cache3 (points saved in a file): + it = _cache3.find ( cp ); + if ( it != _cache3.end() ) { + cache_index = NOMAD::CACHE_3; + return it->get_point(); + } + + // search in _cache1 (points read in an initial cache file): + it = _cache1.find ( cp ); + if ( it != _cache1.end() ) { + cache_index = NOMAD::CACHE_1; + return it->get_point(); + } + + cache_index = NOMAD::UNDEFINED_CACHE; + return NULL; } /*-----------------------------------------------------*/ @@ -153,56 +153,56 @@ const NOMAD::Eval_Point * NOMAD::Cache::find /*-----------------------------------------------------*/ bool NOMAD::Cache::erase ( const NOMAD::Eval_Point & x ) { - // check the eval types: - if ( x.get_eval_type() != _eval_type ) - throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , - "NOMAD::Cache:erase(x): x.eval_type != cache.eval_type" ); - - std::set<NOMAD::Cache_Point>::iterator it; - NOMAD::cache_index_type cache_index; - - // search in cache: - const NOMAD::Eval_Point * cache_x = find ( x , it , cache_index ); - - // the point has been found: - if ( cache_x ) { - - // remove the point from the list of extern points: - if ( cache_x->get_current_run() || x.get_current_run() ) { - std::list<const NOMAD::Eval_Point*>::const_iterator end2 = _extern_pts.end(); - std::list<const NOMAD::Eval_Point*>::iterator it2 = _extern_pts.begin(); - while ( it2 != end2 ) { - if ( *it2 == cache_x || *it2 == &x ) { - _extern_pts.erase ( it2 ); - break; - } - ++it2; - } - } - - // erase the point in cache if its address is different from &x: - if ( cache_x != &x ) - delete cache_x; - - // remove the point from the cache: - _sizeof -= x.size_of(); - - switch ( cache_index ) { - case NOMAD::CACHE_1: - _cache1.erase ( it ); - break; - case NOMAD::CACHE_2: - _cache2.erase ( it ); - break; - case NOMAD::CACHE_3: - _cache3.erase ( it ); - break; - case NOMAD::UNDEFINED_CACHE: - break; + // check the eval types: + if ( x.get_eval_type() != _eval_type ) + throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , + "NOMAD::Cache:erase(x): x.eval_type != cache.eval_type" ); + + std::set<NOMAD::Cache_Point>::iterator it; + NOMAD::cache_index_type cache_index; + + // search in cache: + const NOMAD::Eval_Point * cache_x = find ( x , it , cache_index ); + + // the point has been found: + if ( cache_x ) { + + // remove the point from the list of extern points: + if ( cache_x->get_current_run() || x.get_current_run() ) { + std::list<const NOMAD::Eval_Point*>::const_iterator end2 = _extern_pts.end(); + std::list<const NOMAD::Eval_Point*>::iterator it2 = _extern_pts.begin(); + while ( it2 != end2 ) { + if ( *it2 == cache_x || *it2 == &x ) { + _extern_pts.erase ( it2 ); + break; + } + ++it2; + } + } + + // erase the point in cache if its address is different from &x: + if ( cache_x != &x ) + delete cache_x; + + // remove the point from the cache: + _sizeof -= x.size_of(); + + switch ( cache_index ) { + case NOMAD::CACHE_1: + _cache1.erase ( it ); + break; + case NOMAD::CACHE_2: + _cache2.erase ( it ); + break; + case NOMAD::CACHE_3: + _cache3.erase ( it ); + break; + case NOMAD::UNDEFINED_CACHE: + break; + } + return true; } - return true; - } - return false; + return false; } /*-----------------------------------------------------*/ @@ -210,19 +210,19 @@ bool NOMAD::Cache::erase ( const NOMAD::Eval_Point & x ) /*-----------------------------------------------------*/ void NOMAD::Cache::clear ( void ) { - const NOMAD::Eval_Point * x = begin(); - while ( x ) { - delete x; - x = next(); - } - _cache1.clear(); - _cache2.clear(); - _cache3.clear(); - unlock(); - - _extern_pts.clear(); - - _sizeof = static_cast<float> ( sizeof_init() ); + const NOMAD::Eval_Point * x = begin(); + while ( x ) { + delete x; + x = next(); + } + _cache1.clear(); + _cache2.clear(); + _cache3.clear(); + unlock(); + + _extern_pts.clear(); + + _sizeof = static_cast<float> ( sizeof_init() ); } /*------------------------------------------------*/ @@ -231,19 +231,19 @@ void NOMAD::Cache::clear ( void ) /*------------------------------------------------*/ void NOMAD::Cache::insert ( const NOMAD::Eval_Point & x ) { - // check the eval types: - if ( x.get_eval_type() != _eval_type ) - throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , - "NOMAD::Cache:insert(x): x.eval_type != cache.eval_type" ); - - // insertion in _extern_pts: - insert_extern_point ( x ); - - // insertion in _cache2: - NOMAD::Cache_Point cp ( &x ); - _cache2.insert ( cp ); - x.set_in_cache ( true ); - _sizeof += x.size_of(); + // check the eval types: + if ( x.get_eval_type() != _eval_type ) + throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , + "NOMAD::Cache:insert(x): x.eval_type != cache.eval_type" ); + + // insertion in _extern_pts: + insert_extern_point ( x ); + + // insertion in _cache2: + NOMAD::Cache_Point cp ( &x ); + _cache2.insert ( cp ); + x.set_in_cache ( true ); + _sizeof += x.size_of(); } /*-------------------------------------------------------------------------*/ @@ -253,42 +253,42 @@ void NOMAD::Cache::insert ( const NOMAD::Eval_Point & x ) /*-------------------------------------------------------------------------*/ void NOMAD::Cache::insert ( Cache & c ) { - if ( &c == this ) - return; - - // check the eval types: - if ( c._eval_type != _eval_type ) - throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , - "NOMAD::Cache:insert(c): c._eval_type != this->_eval_type" ); - - // insertion: - NOMAD::Point bbo_cache , bbo_cur; - const NOMAD::Eval_Point * cache_x; - const NOMAD::Eval_Point * cur = c.begin(); - - while ( cur ) { + if ( &c == this ) + return; - cache_x = find ( *cur ); - - // the current point is already in cache: - if ( cache_x ) { - update ( get_modifiable_point ( *cache_x ) , *cur ); - delete cur; + // check the eval types: + if ( c._eval_type != _eval_type ) + throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , + "NOMAD::Cache:insert(c): c._eval_type != this->_eval_type" ); + + // insertion: + NOMAD::Point bbo_cache , bbo_cur; + const NOMAD::Eval_Point * cache_x; + const NOMAD::Eval_Point * cur = c.begin(); + + while ( cur ) { + + cache_x = find ( *cur ); + + // the current point is already in cache: + if ( cache_x ) { + update ( get_modifiable_point ( *cache_x ) , *cur ); + delete cur; + } + + // point not in cache: + else + insert ( *cur ); + + cur = c.next(); } - - // point not in cache: - else - insert ( *cur ); - - cur = c.next(); - } - - c._sizeof = static_cast<float> ( sizeof_init() ); - - c._cache1.clear(); - c._cache2.clear(); - c._cache3.clear(); - c._extern_pts.clear(); + + c._sizeof = static_cast<float> ( sizeof_init() ); + + c._cache1.clear(); + c._cache2.clear(); + c._cache3.clear(); + c._extern_pts.clear(); } /*------------------------------------------------------------------*/ @@ -309,52 +309,52 @@ void NOMAD::Cache::insert ( Cache & c ) // -------- const NOMAD::Eval_Point * NOMAD::Cache::begin ( void ) const { - if ( !_cache2.empty() ) { - _it = _cache2.begin(); - return _it->get_point(); - } - if ( !_cache3.empty() ) { - _it = _cache3.begin(); - return _it->get_point(); - } - if ( !_cache1.empty() ) { - _it = _cache1.begin(); - return _it->get_point(); - } - return NULL; -} - -// next() (supposes that begin() has been called) -// ------- -const NOMAD::Eval_Point * NOMAD::Cache::next ( void ) const -{ - ++_it; - - if ( !_cache2.empty() && _it == _cache2.end() ) { + if ( !_cache2.empty() ) { + _it = _cache2.begin(); + return _it->get_point(); + } if ( !_cache3.empty() ) { - _it = _cache3.begin(); - return _it->get_point(); + _it = _cache3.begin(); + return _it->get_point(); } if ( !_cache1.empty() ) { - _it = _cache1.begin(); - return _it->get_point(); + _it = _cache1.begin(); + return _it->get_point(); } return NULL; - } - +} - if ( !_cache3.empty() && _it == _cache3.end() ) { - if ( !_cache1.empty() ) { - _it = _cache1.begin(); - return _it->get_point(); +// next() (supposes that begin() has been called) +// ------- +const NOMAD::Eval_Point * NOMAD::Cache::next ( void ) const +{ + ++_it; + + if ( !_cache2.empty() && _it == _cache2.end() ) { + if ( !_cache3.empty() ) { + _it = _cache3.begin(); + return _it->get_point(); + } + if ( !_cache1.empty() ) { + _it = _cache1.begin(); + return _it->get_point(); + } + return NULL; } - return NULL; - } - - if ( !_cache1.empty() && _it == _cache1.end() ) - return NULL; - - return _it->get_point(); + + + if ( !_cache3.empty() && _it == _cache3.end() ) { + if ( !_cache1.empty() ) { + _it = _cache1.begin(); + return _it->get_point(); + } + return NULL; + } + + if ( !_cache1.empty() && _it == _cache1.end() ) + return NULL; + + return _it->get_point(); } /*---------------------------------------------------------------------*/ @@ -362,9 +362,9 @@ const NOMAD::Eval_Point * NOMAD::Cache::next ( void ) const /*---------------------------------------------------------------------*/ bool NOMAD::Cache::is_locked ( const std::string & file_name ) { - if ( file_name == _locked_file ) - return true; - return ( Cache::_locked_files.find ( file_name ) != Cache::_locked_files.end() ); + if ( file_name == _locked_file ) + return true; + return ( Cache::_locked_files.find ( file_name ) != Cache::_locked_files.end() ); } /*---------------------------------------------------------------------*/ @@ -372,13 +372,13 @@ bool NOMAD::Cache::is_locked ( const std::string & file_name ) /*---------------------------------------------------------------------*/ bool NOMAD::Cache::lock ( const std::string & file_name ) { - if ( is_locked ( file_name ) ) - return false; - - Cache::_locked_files.insert ( file_name ); - _locked_file = file_name; - - return true; + if ( is_locked ( file_name ) ) + return false; + + Cache::_locked_files.insert ( file_name ); + _locked_file = file_name; + + return true; } /*---------------------------------------------------------------------*/ @@ -386,14 +386,14 @@ bool NOMAD::Cache::lock ( const std::string & file_name ) /*---------------------------------------------------------------------*/ void NOMAD::Cache::unlock ( void ) { - if ( _locked_file.empty() ) - return; - - std::set<std::string>::iterator it = Cache::_locked_files.find ( _locked_file ); - if ( it != Cache::_locked_files.end() ) - _locked_files.erase(it); - - _locked_file.clear(); + if ( _locked_file.empty() ) + return; + + std::set<std::string>::iterator it = Cache::_locked_files.find ( _locked_file ); + if ( it != Cache::_locked_files.end() ) + _locked_files.erase(it); + + _locked_file.clear(); } /*----------------------------------------------------*/ @@ -402,77 +402,77 @@ void NOMAD::Cache::unlock ( void ) /* . private method */ /*----------------------------------------------------*/ bool NOMAD::Cache::read_points_from_cache_file ( std::ifstream & fin , - const int * p_nb_bb_outputs , - bool display ) + const int * p_nb_bb_outputs , + bool display ) { - try { - - NOMAD::Clock c; - - // the stream is placed at the first point (after the CACHE_FILE_ID tag): - fin.seekg ( sizeof ( NOMAD::CACHE_FILE_ID ) , std::ios::beg ); - - NOMAD::Cache_File_Point cfp; - NOMAD::Eval_Point * cur; - const NOMAD::Eval_Point * cache_x; - - // main loop: - while ( !fin.eof() ) { - - // reading of the Cache_File_Point: - if ( !cfp.read ( fin ) ) { - if ( fin.eof() ) - break; - return false; - } - - // we ignore this cache file point if it has a different - // number of blackbox outputs than *p_nb_bb_outputs: - if ( p_nb_bb_outputs && cfp.get_m() != *p_nb_bb_outputs ) - continue; - - // creation of the Eval_Point: - cur = new NOMAD::Eval_Point ( cfp , _eval_type ); - - // we look if the current point is already in cache: - cache_x = find ( *cur ); - - // the current point is already in cache: - if ( cache_x ) { - update ( get_modifiable_point ( *cache_x ) , *cur ); - delete cur; - } - - // point not in cache: insertion: - else { - - // insertion in _extern_pts: - insert_extern_point ( *cur ); - - // insertion in _cache1: - NOMAD::Cache_Point cp ( cur ); - _cache1.insert ( cp ); - cur->set_in_cache ( true ); - _sizeof += cur->size_of(); - } - - } // end of main loop - - // display stats on the cache load: - if ( display ) { - _out << "number of points: " << static_cast<int>(_cache1.size()) << std::endl - << "size : "; - _out.display_size_of ( _sizeof ); - _out << std::endl - << "load time : " << c.get_real_time() << 's' << std::endl; + try { + + NOMAD::Clock c; + + // the stream is placed at the first point (after the CACHE_FILE_ID tag): + fin.seekg ( sizeof ( NOMAD::CACHE_FILE_ID ) , std::ios::beg ); + + NOMAD::Cache_File_Point cfp; + NOMAD::Eval_Point * cur; + const NOMAD::Eval_Point * cache_x; + + // main loop: + while ( !fin.eof() ) { + + // reading of the Cache_File_Point: + if ( !cfp.read ( fin ) ) { + if ( fin.eof() ) + break; + return false; + } + + // we ignore this cache file point if it has a different + // number of blackbox outputs than *p_nb_bb_outputs: + if ( p_nb_bb_outputs && cfp.get_m() != *p_nb_bb_outputs ) + continue; + + // creation of the Eval_Point: + cur = new NOMAD::Eval_Point ( cfp , _eval_type ); + + // we look if the current point is already in cache: + cache_x = find ( *cur ); + + // the current point is already in cache: + if ( cache_x ) { + update ( get_modifiable_point ( *cache_x ) , *cur ); + delete cur; + } + + // point not in cache: insertion: + else { + + // insertion in _extern_pts: + insert_extern_point ( *cur ); + + // insertion in _cache1: + NOMAD::Cache_Point cp ( cur ); + _cache1.insert ( cp ); + cur->set_in_cache ( true ); + _sizeof += cur->size_of(); + } + + } // end of main loop + + // display stats on the cache load: + if ( display ) { + _out << "number of points: " << static_cast<int>(_cache1.size()) << std::endl + << "size : "; + _out.display_size_of ( _sizeof ); + _out << std::endl + << "load time : " << c.get_real_time() << 's' << std::endl; + } } - } - catch ( ... ) { - return false; - } - return true; + catch ( ... ) { + return false; + } + return true; } - + /*---------------------------------------------------------------------*/ /* . load a cache file (fill the set _cache1) */ /* . lock the file 'file_name' */ @@ -490,78 +490,78 @@ bool NOMAD::Cache::read_points_from_cache_file ( std::ifstream & fin /* ignored */ /*---------------------------------------------------------------------*/ bool NOMAD::Cache::load ( const std::string & file_name , - const int * p_nb_bb_outputs , - bool display ) + const int * p_nb_bb_outputs , + bool display ) { - if ( !file_name.empty() && file_name == _locked_file ) - return true; - - if ( file_name.empty() || !_locked_file.empty() || is_locked(file_name) ) - return false; - - // the file exists: - if ( NOMAD::check_read_file ( file_name ) ) { - - int id; - std::ifstream fin ( file_name.c_str() , std::ios::binary ); - - fin.read ( (char *) &id , sizeof(int) ); + if ( !file_name.empty() && file_name == _locked_file ) + return true; - // it is a valid cache file: - if ( !fin.fail() && id == NOMAD::CACHE_FILE_ID ) { - - // display: - if ( display ) - _out << std::endl - << NOMAD::open_block ( "loading of \'" + file_name + "\'" ); - - // read the points: - if ( !read_points_from_cache_file ( fin , p_nb_bb_outputs , display ) ) { - fin.close(); - return false; // it is not a valid cache file - } - - // lock the file: - lock ( file_name ); - - fin.close(); - - if ( display ) - _out.close_block(); - - return true; + if ( file_name.empty() || !_locked_file.empty() || is_locked(file_name) ) + return false; + + // the file exists: + if ( NOMAD::check_read_file ( file_name ) ) { + + int id; + std::ifstream fin ( file_name.c_str() , std::ios::binary ); + + fin.read ( (char *) &id , sizeof(int) ); + + // it is a valid cache file: + if ( !fin.fail() && id == NOMAD::CACHE_FILE_ID ) { + + // display: + if ( display ) + _out << std::endl + << NOMAD::open_block ( "loading of \'" + file_name + "\'" ); + + // read the points: + if ( !read_points_from_cache_file ( fin , p_nb_bb_outputs , display ) ) { + fin.close(); + return false; // it is not a valid cache file + } + + // lock the file: + lock ( file_name ); + + fin.close(); + + if ( display ) + _out.close_block(); + + return true; + } + + // it is not a valid cache file: + else { + fin.close(); + return false; + } } - - // it is not a valid cache file: + + // the file does not exist: else { - fin.close(); - return false; - } - } - - // the file does not exist: - else { - - // display: - if ( display ) - _out << std::endl << "creating cache file \'" << file_name << "\'" << std::endl; - - // create the file as a valid cache file: - std::ofstream fout ( file_name.c_str() , std::ios::binary ); - - if ( fout.fail() ) { - fout.close(); - return false; - } - - fout.write ( (char *) &NOMAD::CACHE_FILE_ID , sizeof ( NOMAD::CACHE_FILE_ID ) ); - fout.close(); - - // lock: - lock ( file_name ); - } - - return true; + + // display: + if ( display ) + _out << std::endl << "creating cache file \'" << file_name << "\'" << std::endl; + + // create the file as a valid cache file: + std::ofstream fout ( file_name.c_str() , std::ios::binary ); + + if ( fout.fail() ) { + fout.close(); + return false; + } + + fout.write ( (char *) &NOMAD::CACHE_FILE_ID , sizeof ( NOMAD::CACHE_FILE_ID ) ); + fout.close(); + + // lock: + lock ( file_name ); + } + + return true; } /*------------------------------------------------------------------*/ @@ -574,69 +574,69 @@ bool NOMAD::Cache::load ( const std::string & file_name , /*------------------------------------------------------------------*/ bool NOMAD::Cache::save ( bool overwrite , bool display ) { - if ( _locked_file.empty() ) - return true; - - // display: - if ( display ) - _out << std::endl << "saving cache file \'" << _locked_file << "\'" << std::endl; - - std::ofstream fout; - - if ( overwrite ) { - - // open: - fout.open ( _locked_file.c_str() , std::ios::binary ); - if ( fout.fail() ) { - fout.close(); - return false; - } - - // cache file tag: - fout.write ( (char *) &NOMAD::CACHE_FILE_ID , sizeof ( NOMAD::CACHE_FILE_ID ) ); - - // save all cache points: - const NOMAD::Eval_Point * cur = begin(); - while ( cur ) { - NOMAD::Cache_File_Point cfp ( *cur ); - if ( !cfp.write ( fout ) ) { - fout.close(); - return false; - } - cur = next(); - } - } - - else { - - // open and go at the end of the file: - fout.open ( _locked_file.c_str() , std::ios::binary | std::ios::app ); - if ( fout.fail() ) { - fout.close(); - return false; + if ( _locked_file.empty() ) + return true; + + // display: + if ( display ) + _out << std::endl << "saving cache file \'" << _locked_file << "\'" << std::endl; + + std::ofstream fout; + + if ( overwrite ) { + + // open: + fout.open ( _locked_file.c_str() , std::ios::binary ); + if ( fout.fail() ) { + fout.close(); + return false; + } + + // cache file tag: + fout.write ( (char *) &NOMAD::CACHE_FILE_ID , sizeof ( NOMAD::CACHE_FILE_ID ) ); + + // save all cache points: + const NOMAD::Eval_Point * cur = begin(); + while ( cur ) { + NOMAD::Cache_File_Point cfp ( *cur ); + if ( !cfp.write ( fout ) ) { + fout.close(); + return false; + } + cur = next(); + } } - std::set<NOMAD::Cache_Point>::iterator it = _cache2.begin(); - while ( it != _cache2.end() ) { - - // write it->get_point() in 'fout': - NOMAD::Cache_File_Point cfp ( *it->get_point() ); - if ( !cfp.write ( fout ) ) { - fout.close(); - return false; - } - - // transfer the point from _cache2 to _cache3: - NOMAD::Cache_Point cp = *it; // ( it->get_point() ); - _cache3.insert ( cp ); - _cache2.erase ( it++ ); + else { + + // open and go at the end of the file: + fout.open ( _locked_file.c_str() , std::ios::binary | std::ios::app ); + if ( fout.fail() ) { + fout.close(); + return false; + } + + std::set<NOMAD::Cache_Point>::iterator it = _cache2.begin(); + while ( it != _cache2.end() ) { + + // write it->get_point() in 'fout': + NOMAD::Cache_File_Point cfp ( *it->get_point() ); + if ( !cfp.write ( fout ) ) { + fout.close(); + return false; + } + + // transfer the point from _cache2 to _cache3: + NOMAD::Cache_Point cp = *it; // ( it->get_point() ); + _cache3.insert ( cp ); + _cache2.erase ( it++ ); + } } - } - - // close the file: - fout.close(); - - return true; + + // close the file: + fout.close(); + + return true; } /*-----------------------------------------------------------------*/ @@ -647,65 +647,66 @@ bool NOMAD::Cache::save ( bool overwrite , bool display ) /* . private method */ /*-----------------------------------------------------------------*/ void NOMAD::Cache::update ( NOMAD::Eval_Point & cache_x , - const NOMAD::Eval_Point & x ) const + const NOMAD::Eval_Point & x ) const { - const NOMAD::Point & bbo_x = x.get_bb_outputs(); - - if ( &cache_x == &x || - !x.is_eval_ok() || - !cache_x.is_in_cache() || - bbo_x.empty() || - cache_x != x ) - return; - - // check the eval types: - if ( x.get_eval_type () != _eval_type || - cache_x.get_eval_type() != _eval_type ) - throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , - "NOMAD::Cache:update(): problem with the eval. types" ); - - const NOMAD::Point & bbo_cache_x = cache_x.get_bb_outputs(); - int m = bbo_cache_x.size(); - - _sizeof -= cache_x.size_of(); - - // if the current point could not evaluate and x did, - // or if the number of bb outputs is different, we set cache_x = x: - if ( !cache_x.is_eval_ok() || m != bbo_x.size() ) { - cache_x.set_eval_status ( NOMAD::EVAL_OK ); - cache_x.set_bb_output ( bbo_x ); - cache_x.set_signature ( x.get_signature () ); - cache_x.set_direction ( x.get_direction () ); - cache_x.set_mesh_index ( x.get_mesh_index() ); + const NOMAD::Point & bbo_x = x.get_bb_outputs(); + + if ( &cache_x == &x || + !x.is_eval_ok() || + !cache_x.is_in_cache() || + bbo_x.empty() || + cache_x != x ) + return; + + // check the eval types: + if ( x.get_eval_type () != _eval_type || + cache_x.get_eval_type() != _eval_type ) + throw NOMAD::Cache::Cache_Error ( "Cache.cpp" , __LINE__ , + "NOMAD::Cache:update(): problem with the eval. types" ); + + const NOMAD::Point & bbo_cache_x = cache_x.get_bb_outputs(); + int m = bbo_cache_x.size(); + + _sizeof -= cache_x.size_of(); + + // if the current point could not evaluate and x did, + // or if the number of bb outputs is different, we set cache_x = x: + if ( !cache_x.is_eval_ok() || m != bbo_x.size() ) + { + cache_x.set_eval_status ( NOMAD::EVAL_OK ); + cache_x.set_bb_output ( bbo_x ); + cache_x.set_signature ( x.get_signature () ); + cache_x.set_direction ( x.get_direction () ); + + _sizeof += cache_x.size_of(); + return; + } + + // we complete _bb_outputs: + int c1 = 0; + int c2 = 0; + + for ( int i = 0 ; i < m ; ++i ) { + + if ( bbo_cache_x[i].is_defined() ) + ++c1; + + if ( bbo_x[i].is_defined() ) + ++c2; + + if ( !bbo_cache_x[i].is_defined() && bbo_x[i].is_defined() ) + cache_x.set_bb_output ( i , bbo_x[i] ); + } + + // the two points are 'eval_ok' and have comparable outputs: + // we select the best as the one with the more defined bb_outputs: + if ( c2 > c1 ) { + cache_x.set_signature ( x.get_signature () ); + cache_x.set_direction ( x.get_direction () ); + + } + _sizeof += cache_x.size_of(); - return; - } - - // we complete _bb_outputs: - int c1 = 0; - int c2 = 0; - - for ( int i = 0 ; i < m ; ++i ) { - - if ( bbo_cache_x[i].is_defined() ) - ++c1; - - if ( bbo_x[i].is_defined() ) - ++c2; - - if ( !bbo_cache_x[i].is_defined() && bbo_x[i].is_defined() ) - cache_x.set_bb_output ( i , bbo_x[i] ); - } - - // the two points are 'eval_ok' and have comparable outputs: - // we select the best as the one with the more defined bb_outputs: - if ( c2 > c1 ) { - cache_x.set_signature ( x.get_signature () ); - cache_x.set_direction ( x.get_direction () ); - cache_x.set_mesh_index ( x.get_mesh_index() ); - } - - _sizeof += cache_x.size_of(); } /*---------------------------------------------------------*/ @@ -713,16 +714,16 @@ void NOMAD::Cache::update ( NOMAD::Eval_Point & cache_x , /*---------------------------------------------------------*/ void NOMAD::Cache::display_extern_pts ( const NOMAD::Display & out ) const { - int nb = static_cast<int>(_extern_pts.size()); - int cnt = 0; - std::list<const NOMAD::Eval_Point *>::const_iterator it , end = _extern_pts.end(); - for ( it = _extern_pts.begin() ; it != end ; ++it ) { - out << "point "; - out.display_int_w ( ++cnt , nb ); - out << "/" << nb << ": "; - (*it)->display ( out , false ); - out << std::endl; - } + int nb = static_cast<int>(_extern_pts.size()); + int cnt = 0; + std::list<const NOMAD::Eval_Point *>::const_iterator it , end = _extern_pts.end(); + for ( it = _extern_pts.begin() ; it != end ; ++it ) { + out << "point "; + out.display_int_w ( ++cnt , nb ); + out << "/" << nb << ": "; + (*it)->display_eval ( out , false ); + out << std::endl; + } } /*---------------------------------------------------------*/ @@ -730,40 +731,40 @@ void NOMAD::Cache::display_extern_pts ( const NOMAD::Display & out ) const /*---------------------------------------------------------*/ void NOMAD::Cache::display ( const NOMAD::Display & out ) const { - out << "number of cache points: " << size() << std::endl - << "size in memory : "; - out.display_size_of ( _sizeof ); - out << std::endl << "cache file : "; - if ( _locked_file.empty() ) - out << "-" << std::endl; - else - out << _locked_file << std::endl; - + out << "number of cache points: " << size() << std::endl + << "size in memory : "; + out.display_size_of ( _sizeof ); + out << std::endl << "cache file : "; + if ( _locked_file.empty() ) + out << "-" << std::endl; + else + out << _locked_file << std::endl; + #ifdef DEBUG - int nb = size(); - int cnt = 0; - out << NOMAD::open_block ( "cache points" ) << std::endl; - const NOMAD::Eval_Point * cur = begin(); - while ( cur ) { - out << "point "; - out.display_int_w ( ++cnt , nb ); - out << "/" << nb << ": "; - cur->display ( out , false ); + int nb = size(); + int cnt = 0; + out << NOMAD::open_block ( "cache points" ) << std::endl; + const NOMAD::Eval_Point * cur = begin(); + while ( cur ) { + out << "point "; + out.display_int_w ( ++cnt , nb ); + out << "/" << nb << ": "; + cur->display_eval ( out , false ); + out << std::endl; + cur = next(); + } + out.close_block(); + + // this display is repeated here as there can + // be a lot of points displayed just before: + out << "number of cache points: " << size() << std::endl + << "size in memory : "; + out.display_size_of ( _sizeof ); + out << std::endl << "cache file : "; + if ( _locked_file.empty() ) + out << "-"; + else + out << _locked_file; out << std::endl; - cur = next(); - } - out.close_block(); - - // this display is repeated here as there can - // be a lot of points displayed just before: - out << "number of cache points: " << size() << std::endl - << "size in memory : "; - out.display_size_of ( _sizeof ); - out << std::endl << "cache file : "; - if ( _locked_file.empty() ) - out << "-"; - else - out << _locked_file; - out << std::endl; #endif } diff --git a/src/Cache.hpp b/src/Cache.hpp index 1e3b13231eb25699e55450147b5fd090d7b64461..99cfbfbda65132d07e6cefd506eb05914dc06d92 100644 --- a/src/Cache.hpp +++ b/src/Cache.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache_File_Point.cpp b/src/Cache_File_Point.cpp index fdece5919d5e6852523d16b07629a024ba3ffddb..97aca5da5959c5a4c7ef6d962e85347d0daf101b 100644 --- a/src/Cache_File_Point.cpp +++ b/src/Cache_File_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -82,65 +82,68 @@ NOMAD::Cache_File_Point::Cache_File_Point ( const NOMAD::Eval_Point & x ) _bbo_def ( NULL ) , _bbo_index ( NULL ) { - int i; - - // eval_status: - switch ( x.get_eval_status() ) { - case NOMAD::EVAL_FAIL: - _eval_status = 0; - break; - case NOMAD::EVAL_OK: - _eval_status = 1; - break; - case NOMAD::EVAL_IN_PROGRESS: - _eval_status = 2; - break; - case NOMAD::UNDEFINED_STATUS: - _eval_status = 3; - break; - } - - // inputs: - if ( _n > 0 ) { - _coords = new double [_n]; - for ( i = 0 ; i < _n ; ++i ) - _coords[i] = x[i].value(); - } - else - _n = 0; - - // outputs: - const NOMAD::Point & bbo = x.get_bb_outputs(); - _m = bbo.size(); - if ( _m > 0 ) { - - std::vector<double> vd; - std::vector<int> vi; - - for ( i = 0 ; i < _m ; ++i ) - if ( bbo[i].is_defined() ) { - vd.push_back ( bbo[i].value() ); - vi.push_back ( i ); - } - - _m_def = static_cast<int> ( vd.size() ); - if ( _m_def > 0 ) { - _bbo_def = new double [_m_def]; - _bbo_index = new int [_m_def]; - for ( i = 0 ; i < _m_def ; ++i ) { - _bbo_def [i] = vd[i]; - _bbo_index[i] = vi[i]; - } - } - } - else - _m = 0; - + int i; + + // eval_status: + switch ( x.get_eval_status() ) { + case NOMAD::EVAL_FAIL: + _eval_status = 0; + break; + case NOMAD::EVAL_OK: + _eval_status = 1; + break; + case NOMAD::EVAL_IN_PROGRESS: + _eval_status = 2; + break; + case NOMAD::UNDEFINED_STATUS: + _eval_status = 3; + break; + case NOMAD::EVAL_USER_REJECT: + _eval_status = 3; + break; + } + + // inputs: + if ( _n > 0 ) { + _coords = new double [_n]; + for ( i = 0 ; i < _n ; ++i ) + _coords[i] = x[i].value(); + } + else + _n = 0; + + // outputs: + const NOMAD::Point & bbo = x.get_bb_outputs(); + _m = bbo.size(); + if ( _m > 0 ) { + + std::vector<double> vd; + std::vector<int> vi; + + for ( i = 0 ; i < _m ; ++i ) + if ( bbo[i].is_defined() ) { + vd.push_back ( bbo[i].value() ); + vi.push_back ( i ); + } + + _m_def = static_cast<int> ( vd.size() ); + if ( _m_def > 0 ) { + _bbo_def = new double [_m_def]; + _bbo_index = new int [_m_def]; + for ( i = 0 ; i < _m_def ; ++i ) { + _bbo_def [i] = vd[i]; + _bbo_index[i] = vi[i]; + } + } + } + else + _m = 0; + #ifdef MEMORY_DEBUG - ++NOMAD::Cache_File_Point::_cardinality; - if ( NOMAD::Cache_File_Point::_cardinality > - NOMAD::Cache_File_Point::_max_cardinality ) - ++NOMAD::Cache_File_Point::_max_cardinality; + ++NOMAD::Cache_File_Point::_cardinality; + if ( NOMAD::Cache_File_Point::_cardinality > + NOMAD::Cache_File_Point::_max_cardinality ) + ++NOMAD::Cache_File_Point::_max_cardinality; #endif } diff --git a/src/Cache_File_Point.hpp b/src/Cache_File_Point.hpp index 717849d246852cfc66b9627eca03eaac6fe16b8e..3fcf4f04a8e1f67446c766edd1f50e1599e41de0 100644 --- a/src/Cache_File_Point.hpp +++ b/src/Cache_File_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache_Point.cpp b/src/Cache_Point.cpp index 01073a2d39c7c767afe5e995b74ea5e826732505..9b177256b279454a81828f5badf3672941e72529 100644 --- a/src/Cache_Point.cpp +++ b/src/Cache_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache_Point.hpp b/src/Cache_Point.hpp index d4dfe624dbcacfdac474b76d59dd0d7827886fd3..eb76b6a6dd49a3744e0786c1775fb5979161dc76 100644 --- a/src/Cache_Point.hpp +++ b/src/Cache_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache_Search.cpp b/src/Cache_Search.cpp index 591c20dda5467279b58b2fa06c0f9011a83fdf14..58cbd700c3c93003da1216779317267a1f763251 100644 --- a/src/Cache_Search.cpp +++ b/src/Cache_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Cache_Search.hpp b/src/Cache_Search.hpp index 8b954fc0dec22e187f31167af71af06e252b8d34..25e2e51a6e57dea8b65c553e407d89e313e425d6 100644 --- a/src/Cache_Search.hpp +++ b/src/Cache_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Clock.cpp b/src/Clock.cpp index db4e8a5c41b4ef5e0e914ef329bf171b722c4e35..6f95c226f1776d73ec592f4d054d1363924b5089 100644 --- a/src/Clock.cpp +++ b/src/Clock.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -53,7 +53,8 @@ const double NOMAD::Clock::_D_CLOCKS_PER_SEC = static_cast<double>(CLOCKS_PER_SE /*---------------------------------------------------------*/ int NOMAD::Clock::get_real_time ( void ) const { - time_t t2; - time (&t2); - return static_cast<int> (difftime ( t2 , _real_t0 ) ); + time_t t2; + time (&t2); + int dti= static_cast<int>( difftime ( t2 , _real_t0 ) ); + return dti; } diff --git a/src/Clock.hpp b/src/Clock.hpp index da2fcdbdbdcdedfbffabc6bd1235041a901db304..adc303db112353a7da7df6eda32b60f9f95580bc 100644 --- a/src/Clock.hpp +++ b/src/Clock.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Direction.cpp b/src/Direction.cpp index 647dfd21bccb96af878dd454405501e3b0df918a..7eda2279e50aeed7ce09e1b4b603be292d0f18e9 100644 --- a/src/Direction.cpp +++ b/src/Direction.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Direction.hpp b/src/Direction.hpp index 6e9098441157911074f42920fa31412af61b0ef3..b6c192e28282dfb9c4e7a411758235c2514d1b08 100644 --- a/src/Direction.hpp +++ b/src/Direction.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Directions.cpp b/src/Directions.cpp index 6d75ab048a728e38378b2efb8675ba189fbfae0e..e52f61fcdd071faba862c4391efcf51886a2f923 100644 --- a/src/Directions.cpp +++ b/src/Directions.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,51 +34,47 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Directions.cpp - \brief Set of polling directions (implementation) - \author Sebastien Le Digabel - \date 2010-04-13 - \see Directions.hpp -*/ + \file Directions.cpp + \brief Set of polling directions (implementation) + \author Sebastien Le Digabel + \date 2010-04-13 + \see Directions.hpp + */ #include "Directions.hpp" - -/*-----------------------------------*/ -/* static members initialization */ -/*-----------------------------------*/ -int NOMAD::Directions::_max_halton_seed = -1; +#include <math.h> +#include "XMesh.hpp" +#include "SMesh.hpp" + /*---------------------------------------------------------*/ /* constructor */ /*---------------------------------------------------------*/ -/* the Halton seed will be automatically computed later */ -/* if Parameters::_halton_seed==-1 */ -/*---------------------------------------------------------*/ NOMAD::Directions::Directions ( int nc , - const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed , - const NOMAD::Display & out ) - : _nc ( nc ) , - _direction_types ( direction_types ) , - _sec_poll_dir_types ( sec_poll_dir_types ) , - _is_binary ( false ) , - _is_categorical ( false ) , - _lt_initialized ( false ) , - _primes ( NULL ) , - _halton_seed ( halton_seed ) , - _out ( out ) + const std::set<NOMAD::direction_type> & direction_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types , + const NOMAD::Display & out ) +: _nc ( nc ) , +_direction_types ( direction_types ) , +_sec_poll_dir_types ( sec_poll_dir_types ) , +_is_binary ( false ) , +_is_categorical ( false ) , +_lt_initialized ( false ) , +_out ( out ) { - // check the directions: - if ( _direction_types.find ( NOMAD::NO_DIRECTION ) != _direction_types.end() ) - _direction_types.clear(); - if ( _sec_poll_dir_types.find ( NOMAD::NO_DIRECTION ) != _sec_poll_dir_types.end() ) - _sec_poll_dir_types.clear(); - - // is_orthomads: true if at least one direction is of type Ortho-MADS: - _is_orthomads = NOMAD::dirs_have_orthomads ( _direction_types ); - if ( !_is_orthomads ) - _is_orthomads = NOMAD::dirs_have_orthomads ( _sec_poll_dir_types ); + // check the directions: + if ( _direction_types.find ( NOMAD::NO_DIRECTION ) != _direction_types.end() ) + _direction_types.clear(); + + if ( _sec_poll_dir_types.find ( NOMAD::NO_DIRECTION ) != _sec_poll_dir_types.end() ) + _sec_poll_dir_types.clear(); + + // is_orthomads: true if at least one direction is of type Ortho-MADS: + _is_orthomads = NOMAD::dirs_have_orthomads ( _direction_types ); + if ( !_is_orthomads ) + _is_orthomads = NOMAD::dirs_have_orthomads ( _sec_poll_dir_types ); + + } /*---------------------------------------------------------*/ @@ -86,12 +82,13 @@ NOMAD::Directions::Directions /*---------------------------------------------------------*/ NOMAD::Directions::~Directions ( void ) { - if ( _lt_initialized ) { - int n = 2 * NOMAD::L_LIMITS; - for ( int i = 0 ; i <= n ; ++i ) - delete _bl[i]; - } - delete [] _primes; + if ( _lt_initialized ) + { + int n = 2 * NOMAD::L_LIMITS; + for ( int i = 0 ; i <= n ; ++i ) + delete _bl[i]; + } + } /*---------------------------------------------------------*/ @@ -99,53 +96,13 @@ NOMAD::Directions::~Directions ( void ) /*---------------------------------------------------------*/ void NOMAD::Directions::lt_mads_init ( void ) { - int n = 2 * NOMAD::L_LIMITS; - for ( int i = 0 ; i <= n ; ++i ) { - _bl [i] = NULL; - _hat_i[i] = -1; - } - _lt_initialized = true; -} - -/*------------------------------------------------------*/ -/* static method for computing a Halton seed (static) */ -/*------------------------------------------------------*/ -int NOMAD::Directions::compute_halton_seed ( int n ) { - int * primes = new int [n]; - NOMAD::construct_primes ( n , primes ); - int halton_seed = primes[n-1]; - delete [] primes; - if ( halton_seed > NOMAD::Directions::_max_halton_seed ) - NOMAD::Directions::_max_halton_seed = halton_seed; - if ( halton_seed > NOMAD::Mesh::get_max_halton_index() ) - NOMAD::Mesh::set_max_halton_index ( halton_seed ); - return halton_seed; -} - -/*---------------------------------------------------------*/ -/* Ortho-MADS initializations (private) */ -/*---------------------------------------------------------*/ -void NOMAD::Directions::ortho_mads_init ( int halton_seed ) -{ - _is_orthomads = true; - - if ( !_primes ) { - _primes = new int[_nc]; - NOMAD::construct_primes ( _nc , _primes ); - } - - _halton_seed = ( halton_seed < 0 ) ? _primes[_nc-1] : halton_seed; - - if ( _halton_seed > NOMAD::Directions::_max_halton_seed ) - NOMAD::Directions::_max_halton_seed = _halton_seed; - -#ifdef DEBUG - _out << std::endl << "Ortho-MADS Halton seed (t0) = " - << _halton_seed << std::endl; -#endif - - if ( halton_seed > NOMAD::Mesh::get_max_halton_index() ) - NOMAD::Mesh::set_max_halton_index ( halton_seed ); + int n = 2 * NOMAD::L_LIMITS; + for ( int i = 0 ; i <= n ; ++i ) + { + _bl [i] = NULL; + _hat_i[i] = -1; + } + _lt_initialized = true; } /*---------------------------------------------------------*/ @@ -153,16 +110,15 @@ void NOMAD::Directions::ortho_mads_init ( int halton_seed ) /*---------------------------------------------------------*/ void NOMAD::Directions::set_binary ( void ) { - _is_binary = true; - _is_categorical = false; - _is_orthomads = false; - _halton_seed = -1; - _direction_types.clear(); - _direction_types.insert ( NOMAD::GPS_BINARY ); - if ( !_sec_poll_dir_types.empty() ) { - _sec_poll_dir_types.clear(); - _sec_poll_dir_types.insert ( NOMAD::GPS_BINARY ); - } + _is_binary = true; + _is_categorical = false; + _is_orthomads = false; + _direction_types.clear(); + _direction_types.insert ( NOMAD::GPS_BINARY ); + if ( !_sec_poll_dir_types.empty() ) { + _sec_poll_dir_types.clear(); + _sec_poll_dir_types.insert ( NOMAD::GPS_BINARY ); + } } /*---------------------------------------------------------*/ @@ -170,12 +126,11 @@ void NOMAD::Directions::set_binary ( void ) /*---------------------------------------------------------*/ void NOMAD::Directions::set_categorical ( void ) { - _is_categorical = true; - _is_binary = false; - _is_orthomads = false; - _halton_seed = -1; - _direction_types.clear(); - _sec_poll_dir_types.clear(); + _is_categorical = true; + _is_binary = false; + _is_orthomads = false; + _direction_types.clear(); + _sec_poll_dir_types.clear(); } /*----------------------------------------------------------------------*/ @@ -185,674 +140,532 @@ void NOMAD::Directions::set_categorical ( void ) void NOMAD::Directions::compute_binary_directions ( std::list<NOMAD::Direction> & d ) const { - // _GPS_BINARY_ n directions: - NOMAD::Direction * pd; - for ( int i = 0 ; i < _nc ; ++i ) { - d.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_BINARY ) ); - pd = &(*(--d.end())); - (*pd)[i] = 1.0; - } + // _GPS_BINARY_ n directions: + NOMAD::Direction * pd; + for ( int i = 0 ; i < _nc ; ++i ) { + d.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_BINARY ) ); + pd = &(*(--d.end())); + (*pd)[i] = 1.0; + } } -/*---------------------------------------------------------*/ -/* get the directions for a given mesh */ -/*---------------------------------------------------------*/ -void NOMAD::Directions::compute ( std::list<NOMAD::Direction> & dirs, - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index , - int halton_index , - const NOMAD::Direction & feas_success_dir , - const NOMAD::Direction & infeas_success_dir ) + +/*----------------------------------------------------------------------------*/ +/* get the directions on a unit n-sphere for a given mesh */ +/*----------------------------------------------------------------------------*/ +void NOMAD::Directions::compute ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::OrthogonalMesh & mesh ) { - - dirs.clear(); - - // categorical variables: do nothing: - if ( _is_categorical ) - return; - - // binary variables: we use special directions: - if ( _is_binary ) - { - compute_binary_directions ( dirs ); - return; - } - - NOMAD::Double pow_gps , cst; - const NOMAD::Direction * bl; - NOMAD::Direction * pd; - int i , j , k , hat_i; - std::list<NOMAD::Direction>::const_iterator it2 , end2; - - /*-----------------------------------*/ - /* loop on the types of directions */ - /*-----------------------------------*/ - const std::set<NOMAD::direction_type> & dir_types = + + dirs.clear(); + + // categorical variables: do nothing: + if ( _is_categorical ) + return; + + // binary variables: we use special directions: + if ( _is_binary ) + { + compute_binary_directions ( dirs ); + return; + } + + NOMAD::Double pow_gps , cst; + const NOMAD::Direction * bl; + NOMAD::Direction * pd; + int i , j , k , hat_i; + std::list<NOMAD::Direction>::iterator it2 , end2; + + const NOMAD::Point mesh_indices=mesh.get_mesh_indices(); + int mesh_index=int(mesh_indices[0].value()); // single mesh_index used only for isotropic mesh + + + /*-----------------------------------*/ + /* loop on the types of directions */ + /*-----------------------------------*/ + const std::set<NOMAD::direction_type> & dir_types = (poll == NOMAD::PRIMARY) ? _direction_types : _sec_poll_dir_types; - - std::set<NOMAD::direction_type>::const_iterator it , end = dir_types.end() ; - for ( it = dir_types.begin() ; it != end ; ++it ) - { - - if ( *it == NOMAD::UNDEFINED_DIRECTION || - *it == NOMAD::NO_DIRECTION || - *it == NOMAD::MODEL_SEARCH_DIR ) - continue; - - /*--------------*/ - /* Ortho-MADS */ - /*--------------*/ - if ( NOMAD::dir_is_orthomads (*it) ) - { - - // Ortho-MADS initializations: - if ( !_primes ) - ortho_mads_init ( _halton_seed ); - - // halton index: - if ( halton_index < 0 ) - { - int max_halton_index = NOMAD::Mesh::get_max_halton_index(); - - // mesh_index+ _halton_seed -> used to make sure that the sequence of strictly increasing mesh_index produces a non biased sequence of halton_index - halton_index = ( mesh_index >= NOMAD::Mesh::get_max_mesh_index() ) ? mesh_index + _halton_seed : max_halton_index + 1; - if ( halton_index > max_halton_index ) - NOMAD::Mesh::set_max_halton_index ( halton_index ); - } - - NOMAD::Direction halton_dir ( _nc , 0.0 , *it ); - NOMAD::Double alpha_t_l; - - if ( compute_halton_dir ( halton_index , - mesh_index , - alpha_t_l , - halton_dir ) ) { - + + std::set<NOMAD::direction_type>::const_iterator it , end = dir_types.end() ; + for ( it = dir_types.begin() ; it != end ; ++it ) + { + + if ( *it == NOMAD::UNDEFINED_DIRECTION || + *it == NOMAD::NO_DIRECTION || + *it == NOMAD::MODEL_SEARCH_DIR ) + continue; + + /*--------------------------------------------------*/ + /* Ortho-MADS */ + /* ---> dirs are on a unit n-sphere by construction */ + /*--------------------------------------------------*/ + if ( NOMAD::dir_is_orthomads (*it) ) + { + bool success_dir; + + + NOMAD::Direction dir ( _nc , 0.0 , *it ); + NOMAD::Double alpha_t_l; + + success_dir=compute_dir_on_unit_sphere ( dir ); + + if ( success_dir ) + { #ifdef DEBUG - _out << std::endl - << NOMAD::open_block ( "compute Ortho-MADS directions with" ) - << "type = " << *it << std::endl - << "Halton index (tk) = " << halton_index << std::endl - << "mesh index (lk) = " << mesh_index << std::endl - << "alpha (tk,lk) = " << alpha_t_l << std::endl - << "Halton direction = ( "; - halton_dir.NOMAD::Point::display ( _out , " " , -1 , -1 ); - _out << " )" << std::endl << NOMAD::close_block(); + if ( dynamic_cast<const NOMAD::XMesh*> ( &mesh ) ) + { + _out << std::endl + << NOMAD::open_block ( "compute Ortho-MADS directions with XMesh" ) + << "type = " << *it << std::endl; + NOMAD::Point mesh_indices=mesh.get_mesh_indices(); + _out<< "Mesh indices = ( "; + mesh_indices.NOMAD::Point::display( _out, " " , -1 , -1 ); + _out << " )" << std::endl; + _out<< "Unit sphere Direction = ( "; + dir.NOMAD::Point::display ( _out , " " , -1 , -1 ); + _out << " )" << std::endl << NOMAD::close_block(); + } + else if ( dynamic_cast<const NOMAD::SMesh*> ( &mesh ) ) + { + _out << std::endl + << NOMAD::open_block ( "compute Ortho-MADS directions with SMesh" ) + << "type = " << *it + << " on isotropic mesh " << std::endl + << "mesh index (lk) = " << mesh_index << std::endl + << "alpha (tk,lk) = " << alpha_t_l << std::endl + << "Unit sphere Direction = ( "; + dir.NOMAD::Point::display ( _out , " " , -1 , -1 ); + _out << " )" << std::endl << NOMAD::close_block(); + + } + #endif - - - - // Ortho-MADS 2n and n+1: - // ---------------------- - if ( *it == NOMAD::ORTHO_2N || *it == NOMAD::ORTHO_NP1_QUAD || *it == NOMAD::ORTHO_NP1_NEG ) - { - - // creation of the 2n directions: - // For ORTHO_NP1 the reduction from 2N to N+1 is done in MADS::POLL - NOMAD::Direction ** H = new NOMAD::Direction * [2*_nc]; - - // Ordering D_k alternates Hk and -Hk instead of [H_k -H_k] - for ( i = 0 ; i < _nc ; ++i ) - { - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); - H[i ] = &(*(--dirs.end())); - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); - H[i+_nc] = &(*(--dirs.end())); - } - - // Householder transformations on the 2n directions: - householder ( halton_dir , - true , // complete_to_2n = true - H ); - - delete [] H; - - - } - - // Ortho-MADS 1 or Ortho-MADS 2: - // ----------------------------- - else { - dirs.push_back ( halton_dir ); - if ( *it == NOMAD::ORTHO_2 ) - dirs.push_back ( -halton_dir ); - } - } - } - - /*-----------*/ - /* LT-MADS */ - /*-----------*/ - else if ( NOMAD::dir_is_ltmads (*it) ) { - - if ( !_lt_initialized) - lt_mads_init(); - - bl = get_bl ( mesh_index , *it , hat_i ); - - // LT-MADS 1 or LT-MADS 2: -b(l) and/or b(l): - // ------------------------------------------ - if ( *it == NOMAD::LT_1 || *it == NOMAD::LT_2 ) { - dirs.push_back ( - *bl ); - if ( *it == NOMAD::LT_2 ) - dirs.push_back ( *bl ); - } - - // LT-MADS 2n or LT-MADS n+1: - // -------------------------- - else { - - // row permutation vector: - int * row_permutation_vector = new int [_nc]; - row_permutation_vector[hat_i] = hat_i; - - NOMAD::Random_Pickup rp ( _nc ); - - for ( i = 0 ; i < _nc ; ++i ) - if ( i != hat_i ) { - j = rp.pickup(); - if ( j == hat_i ) - j = rp.pickup(); - row_permutation_vector[i] = j; - } - - rp.reset(); - - for ( j = 0 ; j < _nc ; ++j ) { - - i = rp.pickup(); - - if ( i != hat_i ) { - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); - pd = &(*(--dirs.end())); - - create_lt_direction ( mesh_index , *it , i , hat_i , pd ); - - permute_coords ( *pd , row_permutation_vector ); - } - else - dirs.push_back ( *bl ); - - // completion to maximal basis: - if ( *it == NOMAD::LT_2N ) - dirs.push_back ( NOMAD::Direction ( - *(--dirs.end()) , NOMAD::LT_2N ) ); - } - - delete [] row_permutation_vector; - - // completion to minimal basis: - if ( *it == NOMAD::LT_NP1 ) { - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::LT_NP1 ) ); - pd = &(*(--dirs.end())); - - end2 = --dirs.end(); - for ( it2 = dirs.begin() ; it2 != end2 ; ++it2 ) { - for ( i = 0 ; i < _nc ; ++i ) - (*pd)[i] -= (*it2)[i]; - } - } - } - } - - /*-------*/ - /* GPS */ - /*-------*/ - else { - - // GPS for binary variables: should'nt be here: - if ( *it == NOMAD::GPS_BINARY ) { + // Ortho-MADS 2n and n+1: + // ---------------------- + if ( *it == NOMAD::ORTHO_2N || *it == NOMAD::ORTHO_NP1_QUAD || *it == NOMAD::ORTHO_NP1_NEG ) + { + + // creation of the 2n directions: + // For ORTHO_NP1 the reduction from 2N to N+1 is done in MADS::POLL + NOMAD::Direction ** H = new NOMAD::Direction * [2*_nc]; + + // Ordering D_k alternates Hk and -Hk instead of [H_k -H_k] + for ( i = 0 ; i < _nc ; ++i ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); + H[i ] = &(*(--dirs.end())); + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); + H[i+_nc] = &(*(--dirs.end())); + } + + // Householder transformations on the 2n directions on a unit n-sphere: + householder ( dir , true , H ); + + + delete [] H; + + + } + + // Ortho-MADS 1 or Ortho-MADS 2: + // ----------------------------- + else + { + dirs.push_back ( dir ); + if ( *it == NOMAD::ORTHO_2 ) + dirs.push_back ( -dir ); + } + } + } + + /*--------------------------------*/ + /* LT-MADS */ + /* ---> dirs NOT on unit n-sphere */ + /*--------------------------------*/ + else if ( NOMAD::dir_is_ltmads (*it) ) + { + + if ( !_lt_initialized) + lt_mads_init(); + + bl = get_bl ( mesh , *it , hat_i ); + + // LT-MADS 1 or LT-MADS 2: -b(l) and/or b(l): + // ------------------------------------------ + if ( *it == NOMAD::LT_1 || *it == NOMAD::LT_2 ) + { + dirs.push_back ( - *bl ); + if ( *it == NOMAD::LT_2 ) + dirs.push_back ( *bl ); + } + + // LT-MADS 2n or LT-MADS n+1: + // -------------------------- + else { + + // row permutation vector: + int * row_permutation_vector = new int [_nc]; + row_permutation_vector[hat_i] = hat_i; + + NOMAD::Random_Pickup rp ( _nc ); + + for ( i = 0 ; i < _nc ; ++i ) + if ( i != hat_i ) + { + j = rp.pickup(); + if ( j == hat_i ) + j = rp.pickup(); + row_permutation_vector[i] = j; + } + + rp.reset(); + + for ( j = 0 ; j < _nc ; ++j ) + { + i = rp.pickup(); + if ( i != hat_i ) + { + + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , *it ) ); + pd = &(*(--dirs.end())); + + create_lt_direction ( mesh , *it , i , hat_i , pd ); + permute_coords ( *pd , row_permutation_vector ); + } + else + dirs.push_back ( *bl ); + + // completion to maximal basis: + if ( *it == NOMAD::LT_2N ) + dirs.push_back ( NOMAD::Direction ( - *(--dirs.end()) , NOMAD::LT_2N ) ); + + } + + delete [] row_permutation_vector; + + // completion to minimal basis: + if ( *it == NOMAD::LT_NP1 ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::LT_NP1 ) ); + pd = &(*(--dirs.end())); + + end2 = --dirs.end(); + for ( it2 = dirs.begin() ; it2 != end2 ; ++it2 ) + { + for ( i = 0 ; i < _nc ; ++i ) + (*pd)[i] -= (*it2)[i]; + } + } + } + + + } + + /*--------------------------------*/ + /* GPS */ + /* ---> dirs NOT on unit n-sphere */ + /*--------------------------------*/ + else + { + + // GPS for binary variables: should'nt be here: + if ( *it == NOMAD::GPS_BINARY ) + { #ifdef DEBUG - _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__ - << "): tried to generate binary directions at the wrong place)" - << std::endl << std::endl; + _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__ + << "): tried to generate binary directions at the wrong place)" + << std::endl << std::endl; #endif - dirs.clear(); - return; - } - - // this value represents the non-zero values in GPS directions - // (it is tau^{|ell_k|/2}, and it is such that Delta^m_k * pow_gps = Delta^p_k): - if ( !pow_gps.is_defined() ) - pow_gps = pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index) / 2.0 ); - - // GPS 2n, static: - // --------------- - if ( *it == NOMAD::GPS_2N_STATIC ) { - - for ( i = 0 ; i < _nc ; ++i ) { - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_STATIC ) ); - pd = &(*(--dirs.end())); - (*pd)[i] = pow_gps; - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_STATIC ) ); - pd = &(*(--dirs.end())); - (*pd)[i] = -pow_gps; - } - } - - // GPS 2n, random: - // --------------- - else if ( *it == NOMAD::GPS_2N_RAND ) { - - int v , cnt; - - std::list <int>::const_iterator end3; - std::list <int>::iterator it3; - std::list <int> rem_cols; - std::vector<int> rem_col_by_row ( _nc ); - - // creation of the 2n directions: - std::vector<NOMAD::Direction *> pdirs ( 2 * _nc ); - - for ( i = 0 ; i < _nc ; ++i ) { - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_RAND ) ); - pdirs[i] = &(*(--dirs.end())); - (*pdirs[i])[i] = pow_gps; - - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_RAND ) ); - pdirs[i+_nc] = &(*(--dirs.end())); - (*pdirs[i+_nc])[i] = -pow_gps; - - rem_cols.push_back(i); - rem_col_by_row[i] = i; - } - - // random perturbations: - for ( i = 1 ; i < _nc ; ++i ) { - if ( rem_col_by_row[i] > 0 ) { - v = NOMAD::RNG::rand()%3 - 1; // v in { -1 , 0 , 1 } - if ( v ) { - - // we decide a (i,j) couple: - k = NOMAD::RNG::rand()%(rem_col_by_row[i]); - cnt = 0; - end3 = rem_cols.end(); - it3 = rem_cols.begin(); - while ( cnt != k ) { - ++it3; - ++cnt; - } - j = *it3; - - // the perturbation: - (*pdirs[i])[j] = (*pdirs[j+_nc])[i] = -v * pow_gps; - (*pdirs[j])[i] = (*pdirs[i+_nc])[j] = v * pow_gps; - - // updates: - rem_cols.erase(it3); - it3 = rem_cols.begin(); - while ( *it3 != i ) - ++it3; - rem_cols.erase(it3); - for ( k = i+1 ; k < _nc ; ++k ) - rem_col_by_row[k] -= j<k ? 2 : 1; - } - } - } - } - - // GPS n+1, static: - // ---------------- - else if ( *it == NOMAD::GPS_NP1_STATIC ) { - - // (n+1)^st direction: - dirs.push_back ( NOMAD::Direction ( _nc , -pow_gps , NOMAD::GPS_NP1_STATIC ) ); - - // first n directions: - for ( i = 0 ; i < _nc ; ++i ) { - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC ) ); - pd = &(*(--dirs.end())); - (*pd)[i] = pow_gps; - } - } - - // GPS n+1, random: - // ---------------- - else if ( *it == NOMAD::GPS_NP1_RAND ) - { - - // (n+1)^st direction: - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_RAND ) ); - NOMAD::Direction * pd1 = &(*(--dirs.end())); - - NOMAD::Double d; - - // first n directions: - for ( i = 0 ; i < _nc ; ++i ) - { - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_RAND ) ); - pd = &(*(--dirs.end())); - - d = NOMAD::RNG::rand()%2 ? -pow_gps : pow_gps; - (*pd )[i] = d; - (*pd1)[i] = -d; - } - } - - // GPS n+1, static, uniform angles: - // -------------------------------- - else if ( *it == NOMAD::GPS_NP1_STATIC_UNIFORM ) - { - - cst = pow_gps * sqrt(static_cast<double>(_nc)*(_nc+1))/_nc; - - // n first directions: - for ( j = _nc-1 ; j >= 0 ; --j ) - { - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); - pd = &(*(--dirs.end())); - - k = _nc-j-1; - - for ( i = 0 ; i < k ; ++i ) - (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); - - (*pd)[k] = (cst * (j+1)) / sqrt(static_cast<double>(j+1)*(j+2)); - - } - - // (n+1)^st direction: - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); - pd = &(*(--dirs.end())); - for ( i = 0 ; i < _nc ; ++i ) - (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); - - } - - // GPS n+1, random, uniform angles: - // -------------------------------- - // (we apply the procedure defined in - // "Pattern Search Methods for user-provided points: - // application to molecular geometry problems", - // by Alberto, Nogueira, Rocha and Vicente, - // SIOPT 14-4, 1216-1236, 2004, doi:10.1137/S1052623400377955) - else if ( *it == NOMAD::GPS_NP1_RAND_UNIFORM ) - { - - cst = pow_gps * sqrt(static_cast<double>(_nc)*(_nc+1))/_nc; - - // n first directions: - for ( j = _nc-1 ; j >= 0 ; --j ) - { - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); - pd = &(*(--dirs.end())); - - k = _nc-j-1; - - for ( i = 0 ; i < k ; ++i ) - (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); - - (*pd)[k] = (cst * (j+1)) / sqrt(static_cast<double>(j+1)*(j+2)); - - } - - // (n+1)^st direction: - dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); - pd = &(*(--dirs.end())); - for ( i = 0 ; i < _nc ; ++i ) - (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); - - // random perturbations: - NOMAD::Random_Pickup rp ( _nc ); - std::vector<bool> done ( _nc ); - bool chg_sgn; - std::list<NOMAD::Direction>::iterator it; - NOMAD::Double tmp; - - end2 = dirs.end(); - for ( i = 0 ; i < _nc ; ++i ) - done[i] = false; - - for ( i = 0 ; i < _nc ; ++i ) - { - - k = rp.pickup(); - - if ( i != k && !done[i] ) - { - - chg_sgn = ( NOMAD::RNG::rand()%2 != 0 ); - - for ( it = dirs.begin() ; it != end2 ; ++it ) - { - tmp = (*it)[i]; - (*it)[i] = ( chg_sgn ? -1.0 : 1.0 ) * (*it)[k]; - (*it)[k] = tmp; - } - - done[i] = done[k] = true; - } - else - if ( NOMAD::RNG::rand()%2 ) - for ( it = dirs.begin() ; it != end2 ; ++it ) - (*it)[i] = -(*it)[i]; - } - } - } - } // end of loop on the types of directions -} - -/*----------------------------------------------------------------*/ -/* get just one direction for a given mesh (used by VNS search) */ -/*----------------------------------------------------------------*/ -bool NOMAD::Directions::compute_one_direction ( NOMAD::Direction & dir, - int mesh_index, - int halton_index ) -{ - dir.clear(); - - // categorical variables: do nothing: - if ( _is_categorical ) - return false; - - /*-------------------------------*/ - /* binary variables */ - /* (we use a random direction) */ - /*-------------------------------*/ - if ( _is_binary ) { - - dir.reset ( _nc , 0.0 ); - dir.set_type ( NOMAD::GPS_BINARY ); - dir[NOMAD::RNG::rand()%_nc] = (NOMAD::RNG::rand()%2) ? -1.0 : 1.0; - } - - /*----------------*/ - /* Ortho-MADS */ - /*----------------*/ - else if ( _is_orthomads ) { - - if ( !_primes ) - ortho_mads_init ( _halton_seed ); - - dir.reset ( _nc , 0.0 ); - dir.set_type ( NOMAD::ORTHO_1 ); - - NOMAD::Double alpha_t_l; - - if ( !compute_halton_dir ( halton_index , mesh_index , alpha_t_l , dir ) ) - return false; -// } - } - - /*-------------*/ - /* LT-MADS 1 */ - /*-------------*/ - else { - if ( !_lt_initialized) - lt_mads_init(); - int hat_i; - dir = *get_bl ( mesh_index , NOMAD::LT_1 , hat_i ); - } - - return true; + dirs.clear(); + return; + } + + // this value represents the non-zero values in GPS directions + // (it is tau^{|ell_k|/2}, and it is such that delta_k * pow_gps = Delta_k): + if ( !pow_gps.is_defined() ) + pow_gps = pow ( mesh.get_update_basis() , abs(mesh_index) / 2.0 ); + + // GPS 2n, static: + // --------------- + + if ( *it == NOMAD::GPS_2N_STATIC ) + { + for ( i = 0 ; i < _nc ; ++i ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_STATIC ) ); + pd = &(*(--dirs.end())); + (*pd)[i] = pow_gps; + + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_STATIC ) ); + pd = &(*(--dirs.end())); + (*pd)[i] = -pow_gps; + } + } + + // GPS 2n, random: + // --------------- + else if ( *it == NOMAD::GPS_2N_RAND ) + { + + int v , cnt; + + std::list <int>::const_iterator end3; + std::list <int>::iterator it3; + std::list <int> rem_cols; + std::vector<int> rem_col_by_row ( _nc ); + + // creation of the 2n directions: + std::vector<NOMAD::Direction *> pdirs ( 2 * _nc ); + + for ( i = 0 ; i < _nc ; ++i ) + { + + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_RAND ) ); + pdirs[i] = &(*(--dirs.end())); + (*pdirs[i])[i] = pow_gps; + + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_2N_RAND ) ); + pdirs[i+_nc] = &(*(--dirs.end())); + (*pdirs[i+_nc])[i] = -pow_gps; + + rem_cols.push_back(i); + rem_col_by_row[i] = i; + } + + // random perturbations: + for ( i = 1 ; i < _nc ; ++i ) + { + if ( rem_col_by_row[i] > 0 ) + { + v = NOMAD::RNG::rand()%3 - 1; // v in { -1 , 0 , 1 } + if ( v ) + { + + // we decide a (i,j) couple: + k = NOMAD::RNG::rand()%(rem_col_by_row[i]); + cnt = 0; + end3 = rem_cols.end(); + it3 = rem_cols.begin(); + while ( cnt != k ) + { + ++it3; + ++cnt; + } + j = *it3; + + // the perturbation: + (*pdirs[i])[j] = (*pdirs[j+_nc])[i] = -v * pow_gps; + (*pdirs[j])[i] = (*pdirs[i+_nc])[j] = v * pow_gps; + + // updates: + rem_cols.erase(it3); + it3 = rem_cols.begin(); + while ( *it3 != i ) + ++it3; + rem_cols.erase(it3); + for ( k = i+1 ; k < _nc ; ++k ) + rem_col_by_row[k] -= j<k ? 2 : 1; + } + } + } + } + + // GPS n+1, static: + // ---------------- + else if ( *it == NOMAD::GPS_NP1_STATIC ) + { + + // (n+1)^st direction: + dirs.push_back ( NOMAD::Direction ( _nc , -pow_gps , NOMAD::GPS_NP1_STATIC ) ); + + // first n directions: + for ( i = 0 ; i < _nc ; ++i ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC ) ); + pd = &(*(--dirs.end())); + (*pd)[i] = pow_gps; + } + } + + // GPS n+1, random: + // ---------------- + else if ( *it == NOMAD::GPS_NP1_RAND ) + { + + // (n+1)^st direction: + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_RAND ) ); + NOMAD::Direction * pd1 = &(*(--dirs.end())); + + NOMAD::Double d; + + // first n directions: + for ( i = 0 ; i < _nc ; ++i ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_RAND ) ); + pd = &(*(--dirs.end())); + + d = NOMAD::RNG::rand()%2 ? -pow_gps : pow_gps; + (*pd )[i] = d; + (*pd1)[i] = -d; + } + } + + // GPS n+1, static, uniform angles: + // -------------------------------- + else if ( *it == NOMAD::GPS_NP1_STATIC_UNIFORM ) + { + + cst = pow_gps * sqrt(static_cast<double>(_nc)*(_nc+1))/_nc; + + // n first directions: + for ( j = _nc-1 ; j >= 0 ; --j ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); + pd = &(*(--dirs.end())); + + k = _nc-j-1; + + for ( i = 0 ; i < k ; ++i ) + (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); + + (*pd)[k] = (cst * (j+1)) / sqrt(static_cast<double>(j+1)*(j+2)); + + } + + // (n+1)^st direction: + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); + pd = &(*(--dirs.end())); + for ( i = 0 ; i < _nc ; ++i ) + (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); + + } + + // GPS n+1, random, uniform angles: + // -------------------------------- + // (we apply the procedure defined in + // "Pattern Search Methods for user-provided points: + // application to molecular geometry problems", + // by Alberto, Nogueira, Rocha and Vicente, + // SIOPT 14-4, 1216-1236, 2004, doi:10.1137/S1052623400377955) + else if ( *it == NOMAD::GPS_NP1_RAND_UNIFORM ) + { + + cst = pow_gps * sqrt(static_cast<double>(_nc)*(_nc+1))/_nc; + + // n first directions: + for ( j = _nc-1 ; j >= 0 ; --j ) + { + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); + pd = &(*(--dirs.end())); + + k = _nc-j-1; + + for ( i = 0 ; i < k ; ++i ) + (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); + + (*pd)[k] = (cst * (j+1)) / sqrt(static_cast<double>(j+1)*(j+2)); + + } + + // (n+1)^st direction: + dirs.push_back ( NOMAD::Direction ( _nc , 0.0 , NOMAD::GPS_NP1_STATIC_UNIFORM ) ); + pd = &(*(--dirs.end())); + for ( i = 0 ; i < _nc ; ++i ) + (*pd)[i] = -cst / sqrt(static_cast<double>(_nc-i)*(_nc-i+1)); + + // random perturbations: + NOMAD::Random_Pickup rp ( _nc ); + std::vector<bool> done ( _nc ); + bool chg_sgn; + std::list<NOMAD::Direction>::iterator it; + NOMAD::Double tmp; + + end2 = dirs.end(); + for ( i = 0 ; i < _nc ; ++i ) + done[i] = false; + + for ( i = 0 ; i < _nc ; ++i ) + { + k = rp.pickup(); + if ( i != k && !done[i] ) + { + chg_sgn = ( NOMAD::RNG::rand()%2 != 0 ); + + for ( it = dirs.begin() ; it != end2 ; ++it ) + { + tmp = (*it)[i]; + (*it)[i] = ( chg_sgn ? -1.0 : 1.0 ) * (*it)[k]; + (*it)[k] = tmp; + } + + done[i] = done[k] = true; + } + else + if ( NOMAD::RNG::rand()%2 ) + for ( it = dirs.begin() ; it != end2 ; ++it ) + (*it)[i] = -(*it)[i]; + } + } + } + } // end of loop on the types of directions + + // The direction are unscaled on a unit n-sphere when necessary (that is directions that are not orthomads) + for ( it2 = dirs.begin() ; it2 != dirs.end() ; ++it2 ) + if ( ! NOMAD::dir_is_orthomads ( it2->get_type() ) ) + { + NOMAD::Double norm_dir=it2->norm(); + for (int i=0 ; i < _nc ; ++i ) + (*it2)[i] /= norm_dir; + } + } - - -/*---------------------------------------------------------*/ -/* compute the Halton direction q(t,l) (private) */ -/*---------------------------------------------------------*/ -bool NOMAD::Directions::compute_halton_dir ( int halton_index , - int mesh_index , - NOMAD::Double & alpha_t_l , - NOMAD::Direction & halton_dir ) const +/*-----------------------------------------------------------------------------*/ +/* compute a random direction on a unit N-Sphere */ +/* see http://en.wikipedia.org/wiki/N-sphere */ +/*-----------------------------------------------------------------------------*/ +bool NOMAD::Directions::compute_dir_on_unit_sphere ( NOMAD::Direction & random_dir ) const { - alpha_t_l.clear(); - - int i; - NOMAD::Double d , norm = 0.0; - NOMAD::Point b ( _nc ); - - for ( i = 0 ; i < _nc ; ++i ) { - d = Directions::get_phi ( halton_index , _primes[i] ); - b[i] = 2*d - 1.0; - norm += b[i].pow2(); - } - norm = norm.sqrt(); - - // desired squared norm for q: - - NOMAD::direction_type hdt = halton_dir.get_type(); - - NOMAD::Double target = ( hdt == NOMAD::ORTHO_2N || hdt == NOMAD::ORTHO_NP1_QUAD || hdt == NOMAD::ORTHO_NP1_NEG ) ? - pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index) / 2.0 ) : - pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index) ); - - - NOMAD::Double x = target.sqrt(); - NOMAD::Double fx = eval_ortho_norm ( x , norm , b , halton_dir ); - NOMAD::Double y = 1.0 , fy , delta_x , abs_dx , min , delta_min , diff , eps; - bool inc , possible , set_eps = false; - int cnt = 0; - - while ( fx != target ) - { - - // safety test: - if ( ++cnt > 1000 ) - { -#ifdef DEBUG - _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__ - << "): could not compute Halton direction for (t=" - << halton_index << ", ell=" << mesh_index - << ")" << std::endl << std::endl; -#endif - alpha_t_l.clear(); - halton_dir.clear(); - return false; - } - - if ( set_eps ) - { - eps = 1e-8; - set_eps = false; - } - else - eps = 0.0; - - inc = ( fx < target ); - - possible = false; - min = 1e+20; - for ( i = 0 ; i < _nc ; ++i ) - { - if ( b[i] != 0.0 ) - { - if ( b[i] > 0.0 ) - { - if ( inc ) - diff = 0.5+eps; - else - diff = -0.5-eps; - } - else - { - if ( inc ) - diff = -0.5-eps; - else - diff = 0.5+eps; - } - - delta_x = norm * ( halton_dir[i] + diff) / b[i] - x; - - y = x + delta_x; - - if ( y > 0 ) - { - abs_dx = delta_x.abs(); - if ( abs_dx < min ) - { - min = abs_dx; - delta_min = delta_x; - possible = true; - } - } - } - } - - if ( !possible ) { -#ifdef DEBUG - _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__ - << "): could not compute Halton direction for (t=" - << halton_index << ", ell=" << mesh_index << ")" - << std::endl << std::endl; -#endif - alpha_t_l.clear(); - halton_dir.clear(); - return false; - } - - y = x + delta_min; - fy = eval_ortho_norm ( y , norm , b , halton_dir ); - - if ( fx == fy ) { - set_eps = true; - continue; - } - - if ( fy==target ) - break; - - if ( inc && fy > target && fx > 0 ) { - eval_ortho_norm ( x , norm , b , halton_dir ); - break; - } - - if ( !inc && fy < target && fy > 0 ) - break; - - x = y; - fx = fy; - } - - alpha_t_l = y; - - return true; + + int i; + NOMAD::Double norm,d; + + for ( i = 0 ; i < _nc ; ++i ) + random_dir[i]=NOMAD::RNG::normal_rand(0,1); + + norm=random_dir.norm(); + + if ( norm==0 ) + return false; + + + for ( i = 0 ; i < _nc ; ++i ) + random_dir[i]/=norm; + + return true; + } + /*-----------------------------------------------------------------*/ /* compute the squared norm of normalized(2u_t-e) for Ortho-MADS */ /* (private) */ /*-----------------------------------------------------------------*/ NOMAD::Double NOMAD::Directions::eval_ortho_norm ( const NOMAD::Double & x , - const NOMAD::Double & norm , - const NOMAD::Point & b , - NOMAD::Point & new_b ) const + const NOMAD::Double & norm , + const NOMAD::Point & b , + NOMAD::Point & new_b ) const { - NOMAD::Double fx = 0.0; - - for ( int i = 0 ; i < _nc ; ++i ) { - new_b[i] = ( x * b[i] / norm ).round(); - fx += new_b[i]*new_b[i]; - } - - return fx; + NOMAD::Double fx = 0.0; + + for ( int i = 0 ; i < _nc ; ++i ) { + new_b[i] = ( x * b[i] / norm ).round(); + fx += new_b[i]*new_b[i]; + } + + return fx; } /*--------------------------------------------------------*/ @@ -861,66 +674,70 @@ NOMAD::Double NOMAD::Directions::eval_ortho_norm ( const NOMAD::Double & x /*--------------------------------------------------------*/ NOMAD::Double NOMAD::Directions::get_phi ( int t , int p ) { - int div; - int size = int ( ceil ( log(static_cast<double>(t+1)) / - log(static_cast<double>(p)) ) ); - int ll = t; - NOMAD::Double d = 0.0; - - for ( int i = 0 ; i < size ; ++i ) { - div = NOMAD::Double ( pow ( p , size-i-1.0 ) ).round(); - d += ( ll / div ) * pow ( static_cast<double>(p) , i-size ); - ll = ll % div; - } - return d; + int div; + int size = int ( ceil ( log(static_cast<double>(t+1)) / + log(static_cast<double>(p)) ) ); + int ll = t; + NOMAD::Double d = 0.0; + + for ( int i = 0 ; i < size ; ++i ) { + div = NOMAD::Double ( pow ( p , size-i-1.0 ) ).round(); + d += ( ll / div ) * pow ( static_cast<double>(p) , i-size ); + ll = ll % div; + } + return d; } /*----------------------------------------------------------------*/ /* . Householder transformation to generate _nc directions from */ -/* the Halton direction */ +/* a given direction */ /* . compute also H[i+nc] = -H[i] (completion to 2n directions) */ /* . private method */ /*----------------------------------------------------------------*/ -void NOMAD::Directions::householder ( const NOMAD::Direction & halton_dir , - bool complete_to_2n , - NOMAD::Direction ** H ) const +void NOMAD::Directions::householder ( const NOMAD::Direction & dir , + bool complete_to_2n , + NOMAD::Direction ** H ) const { - int i , j; - - NOMAD::Double norm2 = halton_dir.squared_norm() , v , h2i; - - for ( i = 0 ; i < _nc ; ++i ) { + int i , j; - h2i = 2 * halton_dir[i]; - - for ( j = 0 ; j < _nc ; ++j ) { - - // H[i]: - (*H[i])[j] = v = (i==j) ? norm2 - h2i * halton_dir[j] : - h2i * halton_dir[j]; - - // -H[i]: - if ( complete_to_2n ) - (*H[i+_nc])[j] = -v; + NOMAD::Double norm2 = dir.squared_norm() , v , h2i; + + for ( i = 0 ; i < _nc ; ++i ) { + + h2i = 2 * dir[i]; + + for ( j = 0 ; j < _nc ; ++j ) { + + // H[i]: + (*H[i])[j] = v = (i==j) ? norm2 - h2i * dir[j] : - h2i * dir[j]; + + // -H[i]: + if ( complete_to_2n ) + (*H[i+_nc])[j] = -v; + } } - } } /*---------------------------------------------------------*/ /* get the LT-MADS b(l) direction (private) */ /*---------------------------------------------------------*/ -const NOMAD::Direction * NOMAD::Directions::get_bl ( int mesh_index , - NOMAD::direction_type dtype , - int & hat_i ) +const NOMAD::Direction * NOMAD::Directions::get_bl ( const NOMAD::OrthogonalMesh & mesh, + NOMAD::direction_type dtype , + int & hat_i ) { - NOMAD::Direction * bl = _bl [ mesh_index + NOMAD::L_LIMITS ]; - hat_i = _hat_i [ mesh_index + NOMAD::L_LIMITS ]; - - if ( !bl ) { - hat_i = -1; - create_lt_direction ( mesh_index , dtype , -1 , hat_i , bl ); - } - - return bl; + + NOMAD::Point mesh_indices = mesh.get_mesh_indices(); + int mesh_index =static_cast<int>(mesh_indices[0].value()); + NOMAD::Direction * bl = _bl [ mesh_index + NOMAD::L_LIMITS ]; + hat_i = _hat_i [ mesh_index + NOMAD::L_LIMITS ]; + + if ( !bl ) + { + hat_i = -1; + create_lt_direction ( mesh , dtype , -1 , hat_i , bl ); + } + + return bl; } /*---------------------------------------------------------*/ @@ -929,40 +746,44 @@ const NOMAD::Direction * NOMAD::Directions::get_bl ( int mes /* (if hat_i == -1, a new b(l) direction */ /* is created and hat_i is set) */ /*---------------------------------------------------------*/ -void NOMAD::Directions::create_lt_direction ( int mesh_index , - NOMAD::direction_type dtype , - int diag_i , - int & hat_i , - NOMAD::Direction *& dir ) +void NOMAD::Directions::create_lt_direction ( const NOMAD::OrthogonalMesh & mesh , + NOMAD::direction_type dtype , + int diag_i , + int & hat_i , + NOMAD::Direction *& dir ) { - int i_pow_tau = + + int mesh_index=static_cast<int>(mesh.get_mesh_indices()[0].value()); + int i_pow_tau = static_cast<int> - ( ceil ( pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index) / 2.0 ) ) ); - - int j = diag_i+1; - - // new b(l) direction: - if ( hat_i < 0 ) { - _hat_i [ mesh_index + NOMAD::L_LIMITS ] = diag_i = hat_i = NOMAD::RNG::rand()%_nc; - _bl [ mesh_index + NOMAD::L_LIMITS ] = dir - = new NOMAD::Direction ( _nc, 0.0, dtype ); - - j = 0; - } - - (*dir)[diag_i] = (NOMAD::RNG::rand()%2) ? -i_pow_tau : i_pow_tau; - - for ( int k = j ; k < _nc ; ++k ) - if ( k != hat_i ) { - (*dir)[k] = NOMAD::RNG::rand()%i_pow_tau; - if ( NOMAD::RNG::rand()%2 && (*dir)[k] > 0.0 ) - (*dir)[k] = -(*dir)[k]; + ( ceil ( pow ( mesh.get_update_basis() , abs(mesh_index) / 2.0 ) ) ); + + int j = diag_i+1; + + // new b(l) direction: + if ( hat_i < 0 ) + { + _hat_i [ mesh_index + NOMAD::L_LIMITS ] = diag_i = hat_i = NOMAD::RNG::rand()%_nc; + _bl [ mesh_index + NOMAD::L_LIMITS ] = dir + = new NOMAD::Direction ( _nc, 0.0, dtype ); + + j = 0; } - + + (*dir)[diag_i] = (NOMAD::RNG::rand()%2) ? -i_pow_tau : i_pow_tau; + + for ( int k = j ; k < _nc ; ++k ) + if ( k != hat_i ) + { + (*dir)[k] = NOMAD::RNG::rand()%i_pow_tau; + if ( NOMAD::RNG::rand()%2 && (*dir)[k] > 0.0 ) + (*dir)[k] = -(*dir)[k]; + } + #ifdef DEBUG - if ( j==0 ) - _out << "new LT-MADS b(l) direction: b(" << mesh_index << ") = " - << *dir << std::endl << std::endl; + if ( j==0 ) + _out << "new LT-MADS b(l) direction: b(" << mesh_index << ") = " + << *dir << std::endl << std::endl; #endif } @@ -970,11 +791,11 @@ void NOMAD::Directions::create_lt_direction ( int mesh_index , /* permute the coordinates of a direction (private) */ /*---------------------------------------------------------*/ void NOMAD::Directions::permute_coords ( NOMAD::Direction & dir , - const int * permutation_vector ) const + const int * permutation_vector ) const { - NOMAD::Point tmp = dir; - for ( int i = 0 ; i < _nc ; ++i ) - dir [ permutation_vector[i] ] = tmp[i]; + NOMAD::Point tmp = dir; + for ( int i = 0 ; i < _nc ; ++i ) + dir [ permutation_vector[i] ] = tmp[i]; } @@ -983,26 +804,21 @@ void NOMAD::Directions::permute_coords ( NOMAD::Direction & dir , /*---------------------------------------------------------*/ void NOMAD::Directions::display ( const NOMAD::Display & out ) const { - out << "n : " << _nc << std::endl - << "types : { "; - std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); - for ( it = _direction_types.begin() ; it != end ; ++it ) - out << "[" << *it << "] "; - out << "}" << std::endl - << "sec poll types: { "; - end = _sec_poll_dir_types.end(); - for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) - out << "[" << *it << "] "; - out << "}" << std::endl; - if ( _is_orthomads ) - { - out << "halton_seed : "; - if ( _halton_seed >= 0 ) - out << _halton_seed; - else - out << "auto"; - out << std::endl; - } + out << "n : " << _nc << std::endl + << "types : { "; + std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); + for ( it = _direction_types.begin() ; it != end ; ++it ) + out << "[" << *it << "] "; + out << "}" << std::endl + << "sec poll types: { "; + end = _sec_poll_dir_types.end(); + for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) + out << "[" << *it << "] "; + out << "}" << std::endl; + if ( _is_orthomads ) + { + out << "seed : " << NOMAD::RNG::get_seed() << endl; + } } /*---------------------------------------------------------*/ @@ -1010,66 +826,60 @@ void NOMAD::Directions::display ( const NOMAD::Display & out ) const /*---------------------------------------------------------*/ bool NOMAD::Directions::operator < ( const NOMAD::Directions & d ) const { - // number of variables: - if ( _nc < d._nc ) - return true; - if ( d._nc < _nc ) - return false; - - // Halton seed: - if ( _halton_seed < d._halton_seed ) - return true; - if ( d._halton_seed < _halton_seed ) - return false; - - // boolean variables: - if ( _is_binary != d._is_binary ) - return _is_binary; - if ( _is_categorical != d._is_categorical ) - return _is_categorical; - if ( _is_orthomads != d._is_orthomads ) - return _is_orthomads; - - // direction types: - size_t nd = _direction_types.size(); - if ( nd < d._direction_types.size() ) - return true; - if ( d._direction_types.size() < nd ) - return false; - - size_t ns = _sec_poll_dir_types.size(); - if ( ns < d._sec_poll_dir_types.size() ) - return true; - if ( d._sec_poll_dir_types.size() < ns ) - return false; - - std::set<NOMAD::direction_type>::const_iterator + // number of variables: + if ( _nc < d._nc ) + return true; + if ( d._nc < _nc ) + return false; + + // boolean variables: + if ( _is_binary != d._is_binary ) + return _is_binary; + if ( _is_categorical != d._is_categorical ) + return _is_categorical; + if ( _is_orthomads != d._is_orthomads ) + return _is_orthomads; + + // direction types: + size_t nd = _direction_types.size(); + if ( nd < d._direction_types.size() ) + return true; + if ( d._direction_types.size() < nd ) + return false; + + size_t ns = _sec_poll_dir_types.size(); + if ( ns < d._sec_poll_dir_types.size() ) + return true; + if ( d._sec_poll_dir_types.size() < ns ) + return false; + + std::set<NOMAD::direction_type>::const_iterator it1 = _direction_types.begin() , it2 = d._direction_types.begin() , end = _direction_types.end(); - - while ( it1 != end ) { - if ( *it1 < *it2 ) - return true; - if ( *it2 < *it1 ) - return false; - ++it1; - ++it2; - } - - it1 = _sec_poll_dir_types.begin(); - it2 = d._sec_poll_dir_types.begin(); - end = _sec_poll_dir_types.end(); - - while ( it1 != end ) { - if ( *it1 < *it2 ) - return true; - if ( *it2 < *it1 ) - return false; - ++it1; - ++it2; - } - - return false; + + while ( it1 != end ) { + if ( *it1 < *it2 ) + return true; + if ( *it2 < *it1 ) + return false; + ++it1; + ++it2; + } + + it1 = _sec_poll_dir_types.begin(); + it2 = d._sec_poll_dir_types.begin(); + end = _sec_poll_dir_types.end(); + + while ( it1 != end ) { + if ( *it1 < *it2 ) + return true; + if ( *it2 < *it1 ) + return false; + ++it1; + ++it2; + } + + return false; } diff --git a/src/Directions.hpp b/src/Directions.hpp index 690be655a8ec6530ba3e6b84d466914051c5ec85..a9d87c85346afbdb609780e33a6e937b2d72e071 100644 --- a/src/Directions.hpp +++ b/src/Directions.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,322 +34,269 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Directions.hpp - \brief Set of polling directions (headers) - \author Sebastien Le Digabel - \date 2010-04-14 - \see Directions.cpp -*/ + \file Directions.hpp + \brief Set of polling directions (headers) + \author Sebastien Le Digabel + \date 2010-04-14 + \see Directions.cpp + */ #ifndef __DIRECTIONS__ #define __DIRECTIONS__ #include "Random_Pickup.hpp" #include "Direction.hpp" -#include "Mesh.hpp" -#include "RNG.hpp" +#include "OrthogonalMesh.hpp" +#include "RNG.hpp" namespace NOMAD { - - /// Set of polling directions. - class Directions { - - /*--------------------------------------------------------------*/ - private: - - int _nc; ///< Number of non-fixed variables. - - /// Types of the poll directions. - std::set<NOMAD::direction_type> _direction_types; - - /// Types of the secondary poll directions. - std::set<NOMAD::direction_type> _sec_poll_dir_types; - - bool _is_binary; ///< Flag equal to \c true if all variables are binary. - bool _is_categorical; ///< Flag equal to \c true if all variables are categorical. - - bool _is_orthomads; //< Flag equal to \c true if Ortho-MADS directions are used. - - // LT-MADS attributes: - NOMAD::Direction * _bl [1+2*NOMAD::L_LIMITS]; ///< Directions b(ell) (LT-MADS). - int _hat_i [1+2*NOMAD::L_LIMITS]; ///< b(ell) indexes (LT-MADS). - bool _lt_initialized; ///< Flag equal to \c true if LT-MADS has been initialized. - - // Ortho-MADS members: - int * _primes; ///< \c nc first prime numbers. - int _halton_seed; ///< Halton seed \c t_0. - - static int _max_halton_seed; ///< Max Halton seed for all NOMAD::Directions objects. - - const NOMAD::Display & _out; ///< Display. - - /*--------------------------------------------------------------*/ - - /// Affectation operator. - /** - \param d The right-hand side object -- \b IN. - */ - Directions & operator = ( const Directions & d ); - - /// Ortho-MADS initializations. - /** - \param halton_seed Halton seed -- \b IN. - */ - void ortho_mads_init ( int halton_seed ); - - /// LT-MADS initializations. - void lt_mads_init ( void ); - - /// Compute the squared norm of \c normalized(2u_t-e) for Ortho-MADS. - /** - \param x \b IN. - \param norm \b IN. - \param b \b IN. - \param new_b \b OUT. - \return The squared norm. - */ - NOMAD::Double eval_ortho_norm ( const NOMAD::Double & x , - const NOMAD::Double & norm , - const NOMAD::Point & b , - NOMAD::Point & new_b ) const; - - /// Householder transformation. - /** - - Generate \c _nc directions from the Halton direction. - - Computes also \c H[i+nc] \c = \c -H[i] (completion to 2n directions). - \param halton_dir The Halton direction -- \b IN. - \param complete_to_2n Complete or not to \c 2n directions -- \b IN. - \param H The \c _nc directions -- \b OUT. - */ - void householder ( const NOMAD::Direction & halton_dir , - bool complete_to_2n , - NOMAD::Direction ** H ) const; - - /// Get the expression of an integer \c t in inverse base \c p. - /** - \param t \b IN. - \param p \b IN. - \return The expression of \c t in inverse base \c p. - */ - static NOMAD::Double get_phi ( int t , int p ); - - /// Compute the Halton direction \c q(t,ell). - /** - \param halton_index Halton index \c t -- \b IN. - \param mesh_index Mesh index \c ell -- \b IN. - \param alpha_t_l Ortho-MADS \c alpha(t,ell) -- \b OUT. - \param halton_dir Halton direction -- \b OUT. - \return A boolean equal to \c true if the computation went well. - */ - bool compute_halton_dir ( int halton_index , - int mesh_index, - NOMAD::Double & alpha_t_l, - NOMAD::Direction & halton_dir ) const; - - /// Access to the LT-MADS \c b(ell) direction. - /** - \param mesh_index Mesh index \c ell -- \b IN. - \param dtype Direction type -- \b IN. - \param hat_i LT-MADS \c hat{i} index -- \b IN/OUT. - \return The LT-MADS \c b(ell) direction. - */ - const NOMAD::Direction * get_bl ( int mesh_index , - NOMAD::direction_type dtype , - int & hat_i ); - - /// Create a new LT-MADS direction. - /** - If \c hat_i \c == \c -1, a new \c b(ell) direction is created - and \c hat_i is set. - \param mesh_index Mesh index \c ell -- \b IN. - \param dtype Direction type -- \b IN. - \param diag_i Diagonal index -- \b IN. - \param hat_i LT-MADS \c hat{i} index -- \b IN/OUT. - \param dir LT-MADS \c b(ell) direction -- \b OUT. - */ - void create_lt_direction ( int mesh_index , - NOMAD::direction_type dtype , - int diag_i , - int & hat_i , - NOMAD::Direction *& dir ); - - /// Permute the coordinates of a direction. - /** - \param dir The direction -- \b IN/OUT. - \param permutation_vector Permutation vector -- \b IN. - */ - void permute_coords ( NOMAD::Direction & dir , - const int * permutation_vector ) const; - - /// Compute binary directions. - /** - Only if all groups of variables are binary. - \param dirs Set of directions -- \b OUT. - */ - void compute_binary_directions ( std::list<NOMAD::Direction> & dirs ) const; - - /*--------------------------------------------------------------*/ - - public: - - /// Constructor. - /** - The Halton seed will be automatically computed later - if NOMAD::Parameters::_halton_seed==-1. - \param nc Number of non-fixed variables -- \b IN. - \param direction_types Types of the poll directions -- \b IN. - \param sec_poll_dir_types Types of the secondary poll directions -- \b IN. - \param halton_seed Halton seed \c t_0 -- \b IN. - \param out The display -- \b IN. - */ - Directions ( int nc , - const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed , - const NOMAD::Display & out ); - - /// Copy constructor. - /** - \param d The copied object -- \b IN. - */ - Directions ( const Directions & d ) - : _nc ( d._nc ) , - _direction_types ( d._direction_types ) , - _sec_poll_dir_types ( d._sec_poll_dir_types ) , - _is_binary ( d._is_binary ) , - _is_categorical ( d._is_categorical ) , - _is_orthomads ( d._is_orthomads ) , - _lt_initialized ( false ) , - _primes ( NULL ) , - _halton_seed ( d._halton_seed ) , - _out ( d._out ) {} - /// Destructor. - virtual ~Directions ( void ); + /// Set of polling directions. + class Directions { + + /*--------------------------------------------------------------*/ + private: + + int _nc; ///< Number of non-fixed variables. + + /// Types of the poll directions. + std::set<NOMAD::direction_type> _direction_types; + + /// Types of the secondary poll directions. + std::set<NOMAD::direction_type> _sec_poll_dir_types; + + bool _is_binary; ///< Flag equal to \c true if all variables are binary. + bool _is_categorical; ///< Flag equal to \c true if all variables are categorical. + + bool _is_orthomads; //< Flag equal to \c true if Ortho-MADS directions are used. + + // LT-MADS attributes: + NOMAD::Direction * _bl [1+2*NOMAD::L_LIMITS]; ///< Directions b(ell) (LT-MADS). + int _hat_i [1+2*NOMAD::L_LIMITS]; ///< b(ell) indexes (LT-MADS). + bool _lt_initialized; ///< Flag equal to \c true if LT-MADS has been initialized. + + const NOMAD::Display & _out; ///< Display. + + /*--------------------------------------------------------------*/ + + /// Affectation operator. + /** + \param d The right-hand side object -- \b IN. + */ + Directions & operator = ( const Directions & d ); + + /// LT-MADS initializations. + void lt_mads_init ( void ); + + /// Compute the squared norm of \c normalized(2u_t-e) for Ortho-MADS. + /** + \param x \b IN. + \param norm \b IN. + \param b \b IN. + \param new_b \b OUT. + \return The squared norm. + */ + NOMAD::Double eval_ortho_norm ( const NOMAD::Double & x , + const NOMAD::Double & norm , + const NOMAD::Point & b , + NOMAD::Point & new_b ) const; + + /// Householder transformation. + /** + - Generate \c _nc directions. + - Computes also \c H[i+nc] \c = \c -H[i] (completion to 2n directions). + \param dir The given direction -- \b IN. + \param complete_to_2n Complete or not to \c 2n directions -- \b IN. + \param H The \c _nc directions -- \b OUT. + */ + void householder ( const NOMAD::Direction & dir , + bool complete_to_2n , + NOMAD::Direction ** H ) const; + + /// Get the expression of an integer \c t in inverse base \c p. + /** + \param t \b IN. + \param p \b IN. + \return The expression of \c t in inverse base \c p. + */ + static NOMAD::Double get_phi ( int t , int p ); + + + /// Access to the LT-MADS \c b(ell) direction. + /** + \param mesh the currenet OrthogonalMesh \c ell -- \b IN. + \param dtype Direction type -- \b IN. + \param hat_i LT-MADS \c hat{i} index -- \b IN/OUT. + \return The LT-MADS \c b(ell) direction. + */ + const NOMAD::Direction * get_bl ( const NOMAD::OrthogonalMesh & mesh , + NOMAD::direction_type dtype , + int & hat_i ); + + /// Create a new LT-MADS direction. + /** + If \c hat_i \c == \c -1, a new \c b(ell) direction is created + and \c hat_i is set. + \param mesh the current OrthogonalMesh index \c ell -- \b IN. + \param dtype Direction type -- \b IN. + \param diag_i Diagonal index -- \b IN. + \param hat_i LT-MADS \c hat{i} index -- \b IN/OUT. + \param dir LT-MADS \c b(ell) direction -- \b OUT. + */ + void create_lt_direction ( const NOMAD::OrthogonalMesh & mesh , + NOMAD::direction_type dtype , + int diag_i , + int & hat_i , + NOMAD::Direction *& dir ); + + /// Permute the coordinates of a direction. + /** + \param dir The direction -- \b IN/OUT. + \param permutation_vector Permutation vector -- \b IN. + */ + void permute_coords ( NOMAD::Direction & dir , + const int * permutation_vector ) const; + + /// Compute binary directions. + /** + Only if all groups of variables are binary. + \param dirs Set of directions -- \b OUT. + */ + void compute_binary_directions ( std::list<NOMAD::Direction> & dirs ) const; + + /*--------------------------------------------------------------*/ + + public: + + /// Constructor. + /** + \param nc Number of non-fixed variables -- \b IN. + \param direction_types Types of the poll directions -- \b IN. + \param sec_poll_dir_types Types of the secondary poll directions -- \b IN. + \param out The display -- \b IN. + */ + Directions ( int nc , + const std::set<NOMAD::direction_type> & direction_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types , + const NOMAD::Display & out ); + + /// Copy constructor. + /** + \param d The copied object -- \b IN. + */ + Directions ( const Directions & d ) + : _nc ( d._nc ) , + _direction_types ( d._direction_types ) , + _sec_poll_dir_types ( d._sec_poll_dir_types ) , + _is_binary ( d._is_binary ) , + _is_categorical ( d._is_categorical ) , + _is_orthomads ( d._is_orthomads ) , + _lt_initialized ( false ) , + _out ( d._out ) {} + + /// Destructor. + virtual ~Directions ( void ); + + /// Compute the directions for a given mesh. + /** + \param mesh The given mesh -- \b IN. + \param dirs Set of directions -- \b OUT. + \param poll Type of poll (primary or secondary) -- \b IN. + */ + void compute ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::OrthogonalMesh & mesh ); + + /// Compute a random direction on a N-Sphere. + /** + \param random_dir -- \b OUT. + \return A boolean equal to \c true if the computation went well. + */ + bool compute_dir_on_unit_sphere ( NOMAD::Direction & random_dir ) const; + + + /// Check if Ortho-MADS directions are used. + /** + \return A boolean equal to \c true if Ortho-MADS directions are used. + */ + bool is_orthomads ( void ) const + { + return _is_orthomads; + } + + /// Check if all variables are categorical. + /** + \return A boolean equal to \c true if all variables are categorical. + */ + bool is_categorical ( void ) const + { + return _is_categorical; + } + + /// Access to the poll direction types. + /** + \return Poll direction types. + */ + const std::set<NOMAD::direction_type> & get_direction_types ( void ) const + { + return _direction_types; + } + + /// Access to the secondary poll direction types. + /** + \return Secondary poll direction types. + */ + const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const + { + return _sec_poll_dir_types; + } + + /// Reset directions for binary variables. + void set_binary ( void ); + + /// Reset directions for categorical variables. + void set_categorical ( void ); + + /// Comparison operator. + /** + \param d The right-hand side object -- \b IN. + \return A boolean equal to \c true if \c *this \c < \c d . + */ + bool operator < ( const Directions & d ) const; + + /// Access to the NOMAD::Display member \c _out. + /** + \return The NOMAD::Display member \c _out. + */ + const NOMAD::Display & out ( void ) const { return _out; } + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + /// Display. + /** + Uses the \c this->_out member as NOMAD::Display object. + */ + void display ( void ) const + { + display ( _out ); + } + }; - /// Compute the directions for a given mesh. - /** - \param dirs Set of directions -- \b OUT. - \param poll Type of poll (primary or secondary) -- \b IN. - \param poll_center Poll center -- \b IN. - \param mesh_index Mesh index \c ell -- \b IN. - \param halton_index Halton index \c t (set to \c -1 for a default value) -- \b IN. - \param feas_success_dir Feasible success direction -- \b IN. - \param infeas_success_dir Infeasible success direction -- \b IN. - */ - void compute ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index , - int halton_index , - const NOMAD::Direction & feas_success_dir , - const NOMAD::Direction & infeas_success_dir ); - - - /// Compute just one direction for a given mesh and provided evaluated pts (used by VNS search and ortho_np1dyn). - /** - \param dir One direction -- \b OUT. - \param mesh_index Mesh index \c ell -- \b IN. - \param halton_index Halton index \c t (must be \c >0) -- \b IN. - \return A boolean equal to \c true if the computation went well. - */ - bool compute_one_direction ( NOMAD::Direction & dir, - int mesh_index, - int halton_index ); - - /// Method for computing a Halton seed. - /** - The Halton seed for \c n variables is computed as the \c n th prime number. - \param n Number of variables -- \b IN. - \return The Halton seed \c t_0. - */ - static int compute_halton_seed ( int n ); - - /// Access to the max value of the Halton index \c t. - /** - \return The max value of the Halton index \c t. - */ - static int get_max_halton_seed ( void ) { return Directions::_max_halton_seed; } - - /// Access to the Halton seed \c t_0. - /** - \return The Halton seed \c t_0. - */ - int get_halton_seed ( void ) const { return _halton_seed; } - - /// Check if Ortho-MADS directions are used. - /** - \return A boolean equal to \c true if Ortho-MADS directions are used. - */ - bool is_orthomads ( void ) const { return _is_orthomads; } - - /// Check if all variables are categorical. - /** - \return A boolean equal to \c true if all variables are categorical. - */ - bool is_categorical ( void ) const { return _is_categorical; } - - /// Access to the poll direction types. + /// Display a NOMAD::Directions object. /** - \return Poll direction types. - */ - const std::set<NOMAD::direction_type> & get_direction_types ( void ) const - { - return _direction_types; - } - - /// Access to the secondary poll direction types. - /** - \return Secondary poll direction types. - */ - const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const - { - return _sec_poll_dir_types; - } - - /// Reset directions for binary variables. - void set_binary ( void ); - - /// Reset directions for categorical variables. - void set_categorical ( void ); - - /// Comparison operator. - /** - \param d The right-hand side object -- \b IN. - \return A boolean equal to \c true if \c *this \c < \c d . - */ - bool operator < ( const Directions & d ) const; - - /// Access to the NOMAD::Display member \c _out. - /** - \return The NOMAD::Display member \c _out. - */ - const NOMAD::Display & out ( void ) const { return _out; } - - /// Display. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - - /// Display. - /** - Uses the \c this->_out member as NOMAD::Display object. - */ - void display ( void ) const { display ( _out ); } - }; - - /// Display a NOMAD::Directions object. - /** \param out The NOMAD::Display object -- \b IN. \param d The NOMAD::Directions object to be displayed -- \b IN. \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Directions & d ) - { - d.display ( out ); - return out; - } + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Directions & d ) + { + d.display ( out ); + return out; + } } #endif diff --git a/src/Display.cpp b/src/Display.cpp index 215f4f68c828adfd8cac59f43618b8074cefd2e5..e8b340f913c24afad048d433d91b82dce4a33687 100644 --- a/src/Display.cpp +++ b/src/Display.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Display.cpp - \brief Custom class for display (implementation) - \author Sebastien Le Digabel - \date 2010-03-30 - \see Display.hpp -*/ + \file Display.cpp + \brief Custom class for display (implementation) + \author Sebastien Le Digabel + \date 2010-03-30 + \see Display.hpp + */ #include "Display.hpp" /*---------------------------------------------------------*/ @@ -47,17 +47,17 @@ /*---------------------------------------------------------*/ void NOMAD::Display::open_block ( const std::string & msg ) const { - // open braces: - if ( _newline ) - _out << _indent_str; - if ( !msg.empty() ) - _out << msg << " "; - _out << _open_brace << std::endl; - - _newline = true; - - // add a tabulation to the indentation string: - _indent_str += '\t'; + // open braces: + if ( _newline ) + _out << _indent_str; + if ( !msg.empty() ) + _out << msg << " "; + _out << _open_brace << std::endl; + + _newline = true; + + // add a tabulation to the indentation string: + _indent_str += '\t'; } /*---------------------------------------------------------*/ @@ -65,54 +65,55 @@ void NOMAD::Display::open_block ( const std::string & msg ) const /*---------------------------------------------------------*/ void NOMAD::Display::close_block ( const std::string & msg ) const { - _newline = true; - - if ( _indent_str.empty() ) - return; - - // remove a tabulation to the indentation string: - _indent_str.erase ( 0 , 1 ); - - // close braces: - _out << _indent_str << _closed_brace << " " << msg << std::endl; + _newline = true; + + if ( _indent_str.empty() ) + return; + + // remove a tabulation to the indentation string: + _indent_str.erase ( 0 , 1 ); + + // close braces: + _out << _indent_str << _closed_brace << " " << msg << std::endl; } /*---------------------------------------------------------*/ /* set the display degrees */ /*---------------------------------------------------------*/ void NOMAD::Display::set_degrees ( NOMAD::dd_type gen_dd , - NOMAD::dd_type search_dd , - NOMAD::dd_type poll_dd , - NOMAD::dd_type iter_dd ) + NOMAD::dd_type search_dd , + NOMAD::dd_type poll_dd , + NOMAD::dd_type iter_dd ) { - // max = max { gen_dd , search_dd , poll_dd , iter_dd } : - NOMAD::dd_type max = gen_dd; - if ( search_dd > gen_dd ) - max = search_dd; - if ( poll_dd > max ) - max = poll_dd; - if ( iter_dd > max ) - max = iter_dd; - - // max=0: all to 0: - if ( max == NOMAD::NO_DISPLAY ) - _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::NO_DISPLAY; - - // max=1: all to 1: - else if ( max == NOMAD::MINIMAL_DISPLAY ) - _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::MINIMAL_DISPLAY; - - // max=2: all to 2: - else if ( max == NOMAD::NORMAL_DISPLAY ) - _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::NORMAL_DISPLAY; - - // max=3: 0-->0, 1-->0, 2->0 and 3-->3: - else { - _gen_dd = (gen_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; - _search_dd = (search_dd==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; - _poll_dd = (poll_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; - _iter_dd = (iter_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; - } + // max = max { gen_dd , search_dd , poll_dd , iter_dd } : + NOMAD::dd_type max = gen_dd; + if ( search_dd > gen_dd ) + max = search_dd; + if ( poll_dd > max ) + max = poll_dd; + if ( iter_dd > max ) + max = iter_dd; + + // max=0: all to 0: + if ( max == NOMAD::NO_DISPLAY ) + _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::NO_DISPLAY; + + // max=1: all to 1: + else if ( max == NOMAD::MINIMAL_DISPLAY ) + _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::MINIMAL_DISPLAY; + + // max=2: all to 2: + else if ( max == NOMAD::NORMAL_DISPLAY ) + _gen_dd = _search_dd = _poll_dd = _iter_dd = NOMAD::NORMAL_DISPLAY; + + // max=3: 0-->0, 1-->0, 2->0 and 3-->3: + else + { + _gen_dd = (gen_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; + _search_dd = (search_dd==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; + _poll_dd = (poll_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; + _iter_dd = (iter_dd ==NOMAD::FULL_DISPLAY)? NOMAD::FULL_DISPLAY:NOMAD::NO_DISPLAY; + } } /*---------------------------------------------------*/ @@ -120,11 +121,11 @@ void NOMAD::Display::set_degrees ( NOMAD::dd_type gen_dd , /*---------------------------------------------------*/ void NOMAD::Display::get_display_degree ( std::string & dd ) const { - dd.resize ( 4 ); - dd[0] = NOMAD::Display::dd_to_char ( _gen_dd ); - dd[1] = NOMAD::Display::dd_to_char ( _search_dd ); - dd[2] = NOMAD::Display::dd_to_char ( _poll_dd ); - dd[3] = NOMAD::Display::dd_to_char ( _iter_dd ); + dd.resize ( 4 ); + dd[0] = NOMAD::Display::dd_to_char ( _gen_dd ); + dd[1] = NOMAD::Display::dd_to_char ( _search_dd ); + dd[2] = NOMAD::Display::dd_to_char ( _poll_dd ); + dd[3] = NOMAD::Display::dd_to_char ( _iter_dd ); } /*---------------------------------------------*/ @@ -132,11 +133,11 @@ void NOMAD::Display::get_display_degree ( std::string & dd ) const /*---------------------------------------------*/ NOMAD::dd_type NOMAD::Display::get_display_degree ( NOMAD::search_type search ) const { - if ( search == NOMAD::X0_EVAL ) - return _gen_dd; - if ( search == NOMAD::POLL || search == NOMAD::EXTENDED_POLL ) - return _poll_dd; - return _search_dd; + if ( search == NOMAD::X0_EVAL ) + return _gen_dd; + if ( search == NOMAD::POLL || search == NOMAD::EXTENDED_POLL ) + return _poll_dd; + return _search_dd; } /*------------------------------------------*/ @@ -144,13 +145,13 @@ NOMAD::dd_type NOMAD::Display::get_display_degree ( NOMAD::search_type search ) /*------------------------------------------*/ char NOMAD::Display::dd_to_char ( NOMAD::dd_type dd ) { - if ( dd == NOMAD::NO_DISPLAY ) - return '0'; - if ( dd == NOMAD::MINIMAL_DISPLAY) - return '1'; - if ( dd == NOMAD::NORMAL_DISPLAY ) - return '2'; - return '3'; + if ( dd == NOMAD::NO_DISPLAY ) + return '0'; + if ( dd == NOMAD::MINIMAL_DISPLAY) + return '1'; + if ( dd == NOMAD::NORMAL_DISPLAY ) + return '2'; + return '3'; } /*------------------------------------------*/ @@ -158,13 +159,13 @@ char NOMAD::Display::dd_to_char ( NOMAD::dd_type dd ) /*------------------------------------------*/ int NOMAD::Display::dd_to_int ( NOMAD::dd_type dd ) { - if ( dd == NOMAD::NO_DISPLAY ) - return 0; - if ( dd == NOMAD::MINIMAL_DISPLAY ) - return 1; - if ( dd == NOMAD::NORMAL_DISPLAY ) - return 2; - return 3; + if ( dd == NOMAD::NO_DISPLAY ) + return 0; + if ( dd == NOMAD::MINIMAL_DISPLAY ) + return 1; + if ( dd == NOMAD::NORMAL_DISPLAY ) + return 2; + return 3; } /*------------------------------------------*/ @@ -172,14 +173,14 @@ int NOMAD::Display::dd_to_int ( NOMAD::dd_type dd ) /*------------------------------------------*/ NOMAD::dd_type NOMAD::Display::int_to_dd ( int dd ) { - if ( dd <= 0 ) - return NOMAD::NO_DISPLAY; - if ( dd == 1 ) - return NOMAD::MINIMAL_DISPLAY; - if ( dd == 2 ) - return NOMAD::NORMAL_DISPLAY; - - return NOMAD::FULL_DISPLAY; + if ( dd <= 0 ) + return NOMAD::NO_DISPLAY; + if ( dd == 1 ) + return NOMAD::MINIMAL_DISPLAY; + if ( dd == 2 ) + return NOMAD::NORMAL_DISPLAY; + + return NOMAD::FULL_DISPLAY; } /*---------------------------------------------------------*/ @@ -187,9 +188,9 @@ NOMAD::dd_type NOMAD::Display::int_to_dd ( int dd ) /*---------------------------------------------------------*/ void NOMAD::Display::display_int_w ( int i , int max_i ) const { - (*this) << std::setw ( (max_i > 0) ? - (1+int(log(static_cast<double>(max_i))/NOMAD::LOG10)) : 1 ) - << i; + (*this) << std::setw ( (max_i > 0) ? + (1+int(log(static_cast<double>(max_i))/NOMAD::LOG10)) : 1 ) + << i; } /*--------------------------------------------------------*/ @@ -199,22 +200,25 @@ void NOMAD::Display::display_int_w ( int i , int max_i ) const /*--------------------------------------------------------*/ void NOMAD::Display::extract_display_format ( std::string & s , std::string & format ) { - format.clear(); - if ( s.empty() ) - return; - size_t k = s.find("%"); - size_t n = s.size(); - if ( k < n ) { - if ( k > 0 && s[k-1]=='\\' ) { - std::string s1 = s.substr ( 0 , k-1 ); - std::string s2 = s.substr ( k , n-k ); - s = s1 + s2; - } - else { - format = s.substr ( k , n-k ); - s = s.substr ( 0 , k ); + format.clear(); + if ( s.empty() ) + return; + size_t k = s.find("%"); + size_t n = s.size(); + if ( k < n ) + { + if ( k > 0 && s[k-1]=='\\' ) + { + std::string s1 = s.substr ( 0 , k-1 ); + std::string s2 = s.substr ( k , n-k ); + s = s1 + s2; + } + else + { + format = s.substr ( k , n-k ); + s = s.substr ( 0 , k ); + } } - } } /*---------------------------------------------------------*/ @@ -223,19 +227,20 @@ void NOMAD::Display::extract_display_format ( std::string & s , std::string & fo /*---------------------------------------------------------*/ void NOMAD::Display::display_time ( int t ) const { - if ( t > 0 ) { - int h = t / 3600; - t = t % 3600; - int m = t / 60; - t = t % 60; - if ( h > 0 ) - (*this) << h << "h "; - if ( m > 0 || h > 0) - (*this) << m << "m "; - } - else - t = 0; - (*this) << t << "s"; + if ( t > 0 ) + { + int h = t / 3600; + t = t % 3600; + int m = t / 60; + t = t % 60; + if ( h > 0 ) + (*this) << h << "h "; + if ( m > 0 || h > 0) + (*this) << m << "m "; + } + else + t = 0; + (*this) << t << "s"; } /*-----------------------------------------------------------------*/ @@ -243,14 +248,14 @@ void NOMAD::Display::display_time ( int t ) const /*-----------------------------------------------------------------*/ void NOMAD::Display::display_size_of ( float size ) const { - if ( size < 1024 ) - (*this) << static_cast<int>(size) << " B"; - else if ( size < 1048576 ) - (*this) << static_cast<int> ( 10 * size / 1024.0 ) / 10.0 << " KB"; - else if ( size < 1073741824 ) - (*this) << static_cast<int> ( 10 * size / 1048576.0 ) / 10.0 << " MB"; - else - (*this) << static_cast<int> ( 10 * size / 1073741824.0 ) / 10.0 << " GB"; + if ( size < 1024 ) + (*this) << static_cast<int>(size) << " B"; + else if ( size < 1048576 ) + (*this) << static_cast<int> ( 10 * size / 1024.0 ) / 10.0 << " KB"; + else if ( size < 1073741824 ) + (*this) << static_cast<int> ( 10 * size / 1048576.0 ) / 10.0 << " MB"; + else + (*this) << static_cast<int> ( 10 * size / 1073741824.0 ) / 10.0 << " GB"; } /*-------------------------------------------------------------------*/ @@ -259,19 +264,20 @@ void NOMAD::Display::display_size_of ( float size ) const NOMAD::display_stats_type NOMAD::Display::get_display_stats_type ( const std::string & s ) { - int idst; - std::string ss = s , keyword; - NOMAD::toupper ( ss ); - NOMAD::display_stats_type dst = NOMAD::DS_OBJ; - while ( dst < NOMAD::DS_UNDEFINED ) { - keyword = get_display_stats_keyword ( dst ); - if ( keyword == ss ) - return dst; - idst = dst; - ++idst; - dst = static_cast<display_stats_type> ( idst ); - } - return NOMAD::DS_UNDEFINED; + int idst; + std::string ss = s , keyword; + NOMAD::toupper ( ss ); + NOMAD::display_stats_type dst = NOMAD::DS_OBJ; + while ( dst < NOMAD::DS_UNDEFINED ) + { + keyword = get_display_stats_keyword ( dst ); + if ( keyword == ss ) + return dst; + idst = dst; + ++idst; + dst = static_cast<display_stats_type> ( idst ); + } + return NOMAD::DS_UNDEFINED; } /*-------------------------------------------------------------------*/ @@ -281,57 +287,61 @@ NOMAD::display_stats_type NOMAD::Display::get_display_stats_type /*-------------------------------------------------------------------*/ std::string NOMAD::Display::get_display_stats_keyword ( NOMAD::display_stats_type dst ) { - std::string s; - switch ( dst ) { - case NOMAD::DS_OBJ: - s = "OBJ"; - break; - case NOMAD::DS_MESH_INDEX: - s = "MESH_INDEX"; - break; - case NOMAD::DS_DELTA_M: - case NOMAD::DS_MESH_SIZE: - s = "MESH_SIZE"; - break; - case NOMAD::DS_DELTA_P: - case NOMAD::DS_POLL_SIZE: - s = "POLL_SIZE"; - break; - case NOMAD::DS_EVAL: - s = "EVAL"; - break; - case NOMAD::DS_SIM_BBE: - s = "SIM_BBE"; - break; - case NOMAD::DS_BBE: - s = "BBE"; - break; - case NOMAD::DS_SGTE: - s = "SGTE"; - break; - case NOMAD::DS_BBO: - s = "BBO"; - break; - case NOMAD::DS_SOL: - s = "SOL"; - break; - case NOMAD::DS_VAR: - s = "VAR"; - break; - case NOMAD::DS_TIME: - s = "TIME"; - break; - case NOMAD::DS_STAT_SUM: - s = "STAT_SUM"; - break; - case NOMAD::DS_STAT_AVG: - s = "STAT_AVG"; - break; - case NOMAD::DS_UNDEFINED: - s = "undefined"; - break; - } - return s; + std::string s; + switch ( dst ) + { + case NOMAD::DS_OBJ: + s = "OBJ"; + break; + case NOMAD::DS_MESH_INDEX: + s = "MESH_INDEX"; + break; + case NOMAD::DS_DELTA_M: + case NOMAD::DS_MESH_SIZE: + s = "MESH_SIZE"; + break; + case NOMAD::DS_DELTA_P: + case NOMAD::DS_POLL_SIZE: + s = "POLL_SIZE"; + break; + case NOMAD::DS_EVAL: + s = "EVAL"; + break; + case NOMAD::DS_SIM_BBE: + s = "SIM_BBE"; + break; + case NOMAD::DS_BBE: + s = "BBE"; + break; + case NOMAD::DS_BLK_EVA: + s = "BLK_EVA"; + break; + case NOMAD::DS_SGTE: + s = "SGTE"; + break; + case NOMAD::DS_BBO: + s = "BBO"; + break; + case NOMAD::DS_SOL: + s = "SOL"; + break; + case NOMAD::DS_VAR: + s = "VAR"; + break; + case NOMAD::DS_TIME: + s = "TIME"; + break; + case NOMAD::DS_STAT_SUM: + s = "STAT_SUM"; + break; + case NOMAD::DS_STAT_AVG: + s = "STAT_AVG"; + break; + case NOMAD::DS_UNDEFINED: + s = "undefined"; + break; + } + return s; } /*-----------------------------------------------------------------*/ @@ -339,21 +349,22 @@ std::string NOMAD::Display::get_display_stats_keyword ( NOMAD::display_stats_typ /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::dd_type dd ) { - switch ( dd ) { - case NOMAD::NO_DISPLAY: - out << "no display (0)"; - break; - case NOMAD::MINIMAL_DISPLAY: - out << "minimal display (1)"; - break; - case NOMAD::NORMAL_DISPLAY: - out << "normal (2)"; - break; - case NOMAD::FULL_DISPLAY: - default: - out << "full (3)"; - } - return out; + switch ( dd ) + { + case NOMAD::NO_DISPLAY: + out << "no display (0)"; + break; + case NOMAD::MINIMAL_DISPLAY: + out << "minimal display (1)"; + break; + case NOMAD::NORMAL_DISPLAY: + out << "normal (2)"; + break; + case NOMAD::FULL_DISPLAY: + default: + out << "full (3)"; + } + return out; } /*-----------------------------------------------------*/ @@ -361,32 +372,33 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::dd_type dd ) /*-----------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::success_type st ) { - switch ( st ) { - case NOMAD::FULL_SUCCESS: - out << "dominating"; - break; - case NOMAD::PARTIAL_SUCCESS: - out << "improving"; - break; - case NOMAD::UNSUCCESSFUL: - out << "unsuccessful"; - } - return out; + switch ( st ) + { + case NOMAD::FULL_SUCCESS: + out << "dominating"; + break; + case NOMAD::PARTIAL_SUCCESS: + out << "improving"; + break; + case NOMAD::UNSUCCESSFUL: + out << "unsuccessful"; + } + return out; } /*-----------------------------------------------------------------*/ /* to display a vector of bb-input types */ /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , - const std::vector<NOMAD::bb_input_type> & bbits ) + const std::vector<NOMAD::bb_input_type> & bbits ) { - if ( bbits.empty() ) + if ( bbits.empty() ) + return out; + size_t n = bbits.size()-1; + for ( size_t k = 0 ; k < n ; ++k ) + out << std::setw(8) << bbits[k] << " "; + out << std::setw(8) << bbits[n]; return out; - size_t n = bbits.size()-1; - for ( size_t k = 0 ; k < n ; ++k ) - out << std::setw(8) << bbits[k] << " "; - out << std::setw(8) << bbits[n]; - return out; } /*-----------------------------------------------------------------*/ @@ -394,20 +406,20 @@ std::ostream & NOMAD::operator << ( std::ostream & ou /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::bb_input_type bi ) { - switch ( bi ) { - case NOMAD::CONTINUOUS: - out << "cont(R)"; - break; - case NOMAD::CATEGORICAL: - out << "cat(C)"; - break; - case NOMAD::INTEGER: - out << "int(I)"; - break; - case NOMAD::BINARY: - out << "bin(B)"; - } - return out; + switch ( bi ) { + case NOMAD::CONTINUOUS: + out << "cont(R)"; + break; + case NOMAD::CATEGORICAL: + out << "cat(C)"; + break; + case NOMAD::INTEGER: + out << "int(I)"; + break; + case NOMAD::BINARY: + out << "bin(B)"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -415,50 +427,51 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::bb_input_type bi /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::search_type st ) { - switch ( st ) { - case NOMAD::POLL: - out << "poll"; - break; - case NOMAD::EXTENDED_POLL: - out << "extended poll"; - break; - case NOMAD::SEARCH: - out << "search"; - break; - case NOMAD::CACHE_SEARCH: - out << "cache search"; - break; - case NOMAD::USER_SEARCH: - out << "user search"; - break; - case NOMAD::SPEC_SEARCH: - out << "speculative search"; - break; - case NOMAD::LH_SEARCH: - out << "LH search"; - break; - case NOMAD::LH_SEARCH_P1: - out << "LH search - Phase one"; - break; - case NOMAD::P1_SEARCH: - out << "Phase one search"; - break; - case NOMAD::MODEL_SEARCH: - out << "model search"; - break; - case NOMAD::VNS_SEARCH: - out << "VNS search"; - break; - case NOMAD::X0_EVAL: - out << "x0 evaluation"; - break; - case NOMAD::ASYNCHRONOUS: - out << "asynchronous final evaluations"; - break; - case NOMAD::UNDEFINED_SEARCH: - out << "undefined"; - } - return out; + switch ( st ) + { + case NOMAD::POLL: + out << "poll"; + break; + case NOMAD::EXTENDED_POLL: + out << "extended poll"; + break; + case NOMAD::SEARCH: + out << "search"; + break; + case NOMAD::CACHE_SEARCH: + out << "cache search"; + break; + case NOMAD::USER_SEARCH: + out << "user search"; + break; + case NOMAD::SPEC_SEARCH: + out << "speculative search"; + break; + case NOMAD::LH_SEARCH: + out << "LH search"; + break; + case NOMAD::LH_SEARCH_P1: + out << "LH search - Phase one"; + break; + case NOMAD::P1_SEARCH: + out << "Phase one search"; + break; + case NOMAD::MODEL_SEARCH: + out << "model search"; + break; + case NOMAD::VNS_SEARCH: + out << "VNS search"; + break; + case NOMAD::X0_EVAL: + out << "x0 evaluation"; + break; + case NOMAD::ASYNCHRONOUS: + out << "asynchronous final evaluations"; + break; + case NOMAD::UNDEFINED_SEARCH: + out << "undefined"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -466,17 +479,18 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::search_type st ) /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::model_type mt ) { - switch ( mt ) { - case NOMAD::QUADRATIC_MODEL: - out << "quadratic"; - break; - case NOMAD::TGP_MODEL: - out << "TGP"; - break; - case NOMAD::NO_MODEL: - out << "no models"; - } - return out; + switch ( mt ) + { + case NOMAD::QUADRATIC_MODEL: + out << "quadratic"; + break; + case NOMAD::TGP_MODEL: + out << "TGP"; + break; + case NOMAD::NO_MODEL: + out << "no models"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -484,18 +498,19 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::model_type mt ) /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::TGP_mode_type m ) { - switch ( m ) { - case NOMAD::TGP_FAST: - out << "fast"; - break; - case NOMAD::TGP_PRECISE: - out << "precise"; - break; - case NOMAD::TGP_USER: - out << "user"; - break; - } - return out; + switch ( m ) + { + case NOMAD::TGP_FAST: + out << "fast"; + break; + case NOMAD::TGP_PRECISE: + out << "precise"; + break; + case NOMAD::TGP_USER: + out << "user"; + break; + } + return out; } /*-----------------------------------------------------------------*/ @@ -503,14 +518,15 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::TGP_mode_type m /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::eval_type et ) { - switch ( et ) { - case NOMAD::TRUTH: - out << "truth"; - break; - case NOMAD::SGTE: - out << "surrogate"; - } - return out; + switch ( et ) + { + case NOMAD::TRUTH: + out << "truth"; + break; + case NOMAD::SGTE: + out << "surrogate"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -518,20 +534,26 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::eval_type et ) /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::eval_status_type est ) { - switch ( est ) { - case NOMAD::EVAL_FAIL: - out << "fail"; - break; - case NOMAD::EVAL_OK: - out << "ok"; - break; - case NOMAD::EVAL_IN_PROGRESS: - out << "in progress"; - break; - case NOMAD::UNDEFINED_STATUS: - out << "undefined"; - } - return out; + switch ( est ) + { + case NOMAD::EVAL_FAIL: + out << "fail"; + break; + case NOMAD::EVAL_OK: + out << "ok"; + break; + case NOMAD::EVAL_IN_PROGRESS: + out << "in progress"; + break; + case NOMAD::UNDEFINED_STATUS: + out << "undefined"; + break; + case NOMAD::EVAL_USER_REJECT: + out << "rejected"; + break; + + } + return out; } /*-----------------------------------------------------------------*/ @@ -539,91 +561,98 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::eval_status_type /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::stop_type st ) { - switch ( st ) { - case NOMAD::DELTA_M_MIN_REACHED: - out << "min mesh size"; - break; - case NOMAD::DELTA_P_MIN_REACHED: - out << "min poll size"; - break; - case NOMAD::L_MAX_REACHED: - out << "max mesh index"; - break; - case NOMAD::L_LIMITS_REACHED: - out << "mesh index limits (+/- " << NOMAD::L_LIMITS << ")"; - break; - case NOMAD::MAX_TIME_REACHED: - out << "max time"; - break; - case NOMAD::MAX_BB_EVAL_REACHED: - out << "max number of blackbox evaluations"; - break; - case NOMAD::MAX_SGTE_EVAL_REACHED: - out << "max number of sgte evaluations"; - break; - case NOMAD::MAX_EVAL_REACHED: - out << "max number of evaluations"; - break; - case NOMAD::MAX_SIM_BB_EVAL_REACHED: - out << "max number of sim. bb evaluations"; - break; - case NOMAD::MAX_ITER_REACHED: - out << "max number of iterations"; - break; - case NOMAD::MAX_CONS_FAILED_ITER: - out << "max number of consecutive failed iterations"; - break; - case NOMAD::FEAS_REACHED: - out << "feasibility achieved"; - break; - case NOMAD::F_TARGET_REACHED: - out << "objective target reached"; - break; - case NOMAD::L_CURVE_TARGET_REACHED: - out << "L-curve target reached"; - break; - case NOMAD::P1_FAIL: - out << "phase one failed"; - break; - case NOMAD::STAT_SUM_TARGET_REACHED: - out << "stat sum target reached"; - break; - case NOMAD::X0_FAIL: - out << "problem with starting point evaluation"; - break; - case NOMAD::MESH_PREC_REACHED: - out << "mesh size reached NOMAD precision"; - break; - case NOMAD::MULTI_MAX_BB_REACHED: - out << "max number of bb evaluations"; - break; - case NOMAD::MULTI_NB_MADS_RUNS_REACHED: - out << "max number of MADS runs"; - break; - case NOMAD::MULTI_STAGNATION: - out << "stagnation of the multi-obj. algo."; - break; - case NOMAD::MULTI_NO_PARETO_PTS: - out << "initial runs cannot find Pareto points"; - break; - case NOMAD::MAX_CACHE_MEMORY_REACHED: - out << "max cache memory reached"; - break; - case NOMAD::CTRL_C: - out << "terminated by ctrl-c"; - break; - case NOMAD::USER_STOPPED: - out << "terminated by the user inside Evaluator::update_iteration()"; - break; - case NOMAD::UNKNOWN_STOP_REASON: - case NOMAD::NO_STOP: - out << "unknown"; - break; - case NOMAD::ERROR: - out << "error"; - break; - } - return out; + switch ( st ) + { + case NOMAD::DELTA_M_MIN_REACHED: + out << "min mesh size"; + break; + case NOMAD::DELTA_P_MIN_REACHED: + out << "min poll size"; + break; + case NOMAD::L_MAX_REACHED: + out << "max mesh index"; + break; + case NOMAD::L_MIN_REACHED: + out << "min mesh index"; + break; + case NOMAD::L_LIMITS_REACHED: + out << "mesh index limits"; + break; + case NOMAD::XL_LIMITS_REACHED: + out << "mesh index limits"; + break; + case NOMAD::MAX_TIME_REACHED: + out << "max time"; + break; + case NOMAD::MAX_BB_EVAL_REACHED: + out << "max number of blackbox evaluations"; + break; + case NOMAD::MAX_SGTE_EVAL_REACHED: + out << "max number of sgte evaluations"; + break; + case NOMAD::MAX_EVAL_REACHED: + out << "max number of evaluations"; + break; + case NOMAD::MAX_SIM_BB_EVAL_REACHED: + out << "max number of sim. bb evaluations"; + break; + case NOMAD::MAX_ITER_REACHED: + out << "max number of iterations"; + break; + case NOMAD::MAX_CONS_FAILED_ITER: + out << "max number of consecutive failed iterations"; + break; + case NOMAD::FEAS_REACHED: + out << "feasibility achieved"; + break; + case NOMAD::F_TARGET_REACHED: + out << "objective target reached"; + break; + case NOMAD::L_CURVE_TARGET_REACHED: + out << "L-curve target reached"; + break; + case NOMAD::P1_FAIL: + out << "phase one failed"; + break; + case NOMAD::STAT_SUM_TARGET_REACHED: + out << "stat sum target reached"; + break; + case NOMAD::X0_FAIL: + out << "problem with starting point evaluation"; + break; + case NOMAD::MESH_PREC_REACHED: + out << "mesh size reached NOMAD precision"; + break; + case NOMAD::MULTI_MAX_BB_REACHED: + out << "max number of bb evaluations"; + break; + case NOMAD::MULTI_NB_MADS_RUNS_REACHED: + out << "max number of MADS runs"; + break; + case NOMAD::MULTI_STAGNATION: + out << "stagnation of the multi-obj. algo."; + break; + case NOMAD::MULTI_NO_PARETO_PTS: + out << "initial runs cannot find Pareto points"; + break; + case NOMAD::MAX_CACHE_MEMORY_REACHED: + out << "max cache memory reached"; + break; + case NOMAD::CTRL_C: + out << "terminated by ctrl-c"; + break; + case NOMAD::USER_STOPPED: + out << "terminated by the user inside Evaluator::update_iteration()"; + break; + case NOMAD::UNKNOWN_STOP_REASON: + case NOMAD::NO_STOP: + out << "unknown"; + break; + case NOMAD::ERROR: + out << "error"; + break; + } + return out; } /*-----------------------------------------------------------------*/ @@ -631,60 +660,62 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::stop_type st ) /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::bb_output_type bbt ) { - switch ( bbt ) { - case NOMAD::OBJ: - out << "OBJ"; - break; - case NOMAD::EB: - out << "EB"; - break; - case NOMAD::PB: - out << "PB"; - break; - case NOMAD::PEB_P: - out << "PEB(P)"; - break; - case NOMAD::PEB_E: - out << "PEB(E)"; - break; - case NOMAD::FILTER: - out << "F"; - break; - case NOMAD::CNT_EVAL: - out << "CNT_EVAL"; - break; - case NOMAD::STAT_AVG: - out << "STAT_AVG"; - break; - case NOMAD::STAT_SUM: - out << "STAT_SUM"; - break; - case NOMAD::UNDEFINED_BBO: - out << "-"; - } - return out; + switch ( bbt ) + { + case NOMAD::OBJ: + out << "OBJ"; + break; + case NOMAD::EB: + out << "EB"; + break; + case NOMAD::PB: + out << "PB"; + break; + case NOMAD::PEB_P: + out << "PEB(P)"; + break; + case NOMAD::PEB_E: + out << "PEB(E)"; + break; + case NOMAD::FILTER: + out << "F"; + break; + case NOMAD::CNT_EVAL: + out << "CNT_EVAL"; + break; + case NOMAD::STAT_AVG: + out << "STAT_AVG"; + break; + case NOMAD::STAT_SUM: + out << "STAT_SUM"; + break; + case NOMAD::UNDEFINED_BBO: + out << "-"; + } + return out; } /*-----------------------------------------------------------------*/ /* to display a interpolation_type */ /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , - NOMAD::interpolation_type it ) + NOMAD::interpolation_type it ) { - switch ( it ) { - case NOMAD::MFN: - out << "Minimum Frobenius Norm interpolation"; - break; - case NOMAD::REGRESSION: - out << "regression"; - break; - case NOMAD::WP_REGRESSION: - out << "well-poised regression"; - break; - case NOMAD::UNDEFINED_INTERPOLATION_TYPE: - out << "undefined"; - } - return out; + switch ( it ) + { + case NOMAD::MFN: + out << "Minimum Frobenius Norm interpolation"; + break; + case NOMAD::REGRESSION: + out << "regression"; + break; + case NOMAD::WP_REGRESSION: + out << "well-poised regression"; + break; + case NOMAD::UNDEFINED_INTERPOLATION_TYPE: + out << "undefined"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -692,17 +723,18 @@ std::ostream & NOMAD::operator << ( std::ostream & out , /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::hnorm_type hnorm ) { - switch ( hnorm ) { - case NOMAD::L1: - out << "L1"; - break; - case NOMAD::L2: - out << "L2"; - break; - case NOMAD::LINF: - out << "Linf"; - } - return out; + switch ( hnorm ) + { + case NOMAD::L1: + out << "L1"; + break; + case NOMAD::L2: + out << "L2"; + break; + case NOMAD::LINF: + out << "Linf"; + } + return out; } /*-----------------------------------------------------------------*/ @@ -710,101 +742,103 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::hnorm_type hnorm /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::multi_formulation_type f ) { - switch ( f ) { - case NOMAD::NORMALIZED: - out << "normalized"; - break; - case NOMAD::PRODUCT: - out << "product"; - break; - case NOMAD::DIST_L1: - out << "distance L1"; - break; - case NOMAD::DIST_L2: - out << "distance L2"; - break; - case NOMAD::DIST_LINF: - out << "distance Linf"; - break; - case NOMAD::UNDEFINED_FORMULATION: - out << "undefined"; - break; - } - return out; + switch ( f ) + { + case NOMAD::NORMALIZED: + out << "normalized"; + break; + case NOMAD::PRODUCT: + out << "product"; + break; + case NOMAD::DIST_L1: + out << "distance L1"; + break; + case NOMAD::DIST_L2: + out << "distance L2"; + break; + case NOMAD::DIST_LINF: + out << "distance Linf"; + break; + case NOMAD::UNDEFINED_FORMULATION: + out << "undefined"; + break; + } + return out; } /*-----------------------------------------------------------------*/ /* to display a direction_type */ /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , - NOMAD::direction_type dt ) + NOMAD::direction_type dt ) { - switch ( dt ) { - case NOMAD::ORTHO_1: - out << "Ortho-MADS 1"; - break; - case NOMAD::ORTHO_2: - out << "Ortho-MADS 2"; - break; - case NOMAD::ORTHO_NP1_QUAD: - out << "Ortho-MADS n+1 QUAD "; - break; - case NOMAD::ORTHO_NP1_NEG: - out << "Ortho-MADS n+1 NEG "; - break; - case NOMAD::DYN_ADDED: - out << "Dynamic n+1th direction"; - break; - case NOMAD::ORTHO_2N: - out << "Ortho-MADS 2n"; - break; - case NOMAD::LT_1: - out << "LT-MADS 1"; - break; - case NOMAD::LT_2: - out << "LT-MADS 2"; - break; - case NOMAD::LT_2N: - out << "LT-MADS 2n"; - break; - case NOMAD::LT_NP1: - out << "LT-MADS n+1"; - break; - case NOMAD::GPS_BINARY: - out << "GPS n, binary"; - break; - case NOMAD::GPS_2N_STATIC: - out << "GPS 2n, static"; - break; - case NOMAD::GPS_2N_RAND: - out << "GPS 2n, random"; - break; - case NOMAD::GPS_NP1_STATIC_UNIFORM: - out << "GPS n+1, static, uniform angles"; - break; - case NOMAD::GPS_NP1_STATIC: - out << "GPS n+1, static"; - break; - case NOMAD::GPS_NP1_RAND_UNIFORM: - out << "GPS n+1, random, uniform angles"; - break; - case NOMAD::GPS_NP1_RAND: - out << "GPS n+1, random"; - break; - case NOMAD::NO_DIRECTION: - out << "none"; - break; - case NOMAD::MODEL_SEARCH_DIR: - out << "model search direction"; - break; - case NOMAD::UNDEFINED_DIRECTION: - out << "undefined"; - break; - case NOMAD::PROSPECT_DIR: - out << "Prospect direction"; - break; - } - return out; + switch ( dt ) + { + case NOMAD::ORTHO_1: + out << "Ortho-MADS 1"; + break; + case NOMAD::ORTHO_2: + out << "Ortho-MADS 2"; + break; + case NOMAD::ORTHO_NP1_QUAD: + out << "Ortho-MADS n+1 QUAD"; + break; + case NOMAD::ORTHO_NP1_NEG: + out << "Ortho-MADS n+1 NEG"; + break; + case NOMAD::DYN_ADDED: + out << "Dynamic n+1th direction"; + break; + case NOMAD::ORTHO_2N: + out << "Ortho-MADS 2n"; + break; + case NOMAD::LT_1: + out << "LT-MADS 1"; + break; + case NOMAD::LT_2: + out << "LT-MADS 2"; + break; + case NOMAD::LT_2N: + out << "LT-MADS 2n"; + break; + case NOMAD::LT_NP1: + out << "LT-MADS n+1"; + break; + case NOMAD::GPS_BINARY: + out << "GPS n, binary"; + break; + case NOMAD::GPS_2N_STATIC: + out << "GPS 2n, static"; + break; + case NOMAD::GPS_2N_RAND: + out << "GPS 2n, random"; + break; + case NOMAD::GPS_NP1_STATIC_UNIFORM: + out << "GPS n+1, static, uniform angles"; + break; + case NOMAD::GPS_NP1_STATIC: + out << "GPS n+1, static"; + break; + case NOMAD::GPS_NP1_RAND_UNIFORM: + out << "GPS n+1, random, uniform angles"; + break; + case NOMAD::GPS_NP1_RAND: + out << "GPS n+1, random"; + break; + case NOMAD::NO_DIRECTION: + out << "none"; + break; + case NOMAD::MODEL_SEARCH_DIR: + out << "model search direction"; + break; + case NOMAD::UNDEFINED_DIRECTION: + out << "undefined"; + break; + case NOMAD::PROSPECT_DIR: + out << "Prospect direction"; + break; + } + return out; } /*-----------------------------------------------------------------*/ @@ -812,8 +846,8 @@ std::ostream & NOMAD::operator << ( std::ostream & out , /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::display_stats_type dst ) { - out << NOMAD::Display::get_display_stats_keyword ( dst ); - return out; + out << NOMAD::Display::get_display_stats_keyword ( dst ); + return out; } /*-----------------------------------------------------------------*/ @@ -821,28 +855,29 @@ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::display_stats_ty /*-----------------------------------------------------------------*/ std::ostream & NOMAD::operator << ( std::ostream & out , NOMAD::check_failed_type cf ) { - switch ( cf ) { - case NOMAD::CHECK_OK: - out << "ok"; - break; - case NOMAD::LB_FAIL: - out << "lower bound"; - break; - case NOMAD::UB_FAIL: - out << "upper bound"; - break; - case NOMAD::FIX_VAR_FAIL: - out << "fixed variable"; - break; - case NOMAD::BIN_FAIL: - out << "binary variable"; - break; - case NOMAD::CAT_FAIL: - out << "categorical variable"; - break; - case NOMAD::INT_FAIL: - out << "integer variable"; - break; - } - return out; + switch ( cf ) + { + case NOMAD::CHECK_OK: + out << "ok"; + break; + case NOMAD::LB_FAIL: + out << "lower bound"; + break; + case NOMAD::UB_FAIL: + out << "upper bound"; + break; + case NOMAD::FIX_VAR_FAIL: + out << "fixed variable"; + break; + case NOMAD::BIN_FAIL: + out << "binary variable"; + break; + case NOMAD::CAT_FAIL: + out << "categorical variable"; + break; + case NOMAD::INT_FAIL: + out << "integer variable"; + break; + } + return out; } diff --git a/src/Display.hpp b/src/Display.hpp index 593e0d2fe489e0aef072f9517d9519da4fdecf62..e88323bcc02882f7d3885ee21d33225bbb0c550c 100644 --- a/src/Display.hpp +++ b/src/Display.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Double.cpp b/src/Double.cpp index 561a685b6262891f9cbe90e7fc0b7f23b1274135..8a7c06714f85ece2d191ab9f51d06b400324ebd0 100644 --- a/src/Double.cpp +++ b/src/Double.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Double.cpp - \brief Custom class for double-precision reals (implementation) - \author Sebastien Le Digabel - \date 2010-04-02 - \see Double.hpp -*/ + \file Double.cpp + \brief Custom class for double-precision reals (implementation) + \author Sebastien Le Digabel + \date 2010-04-02 + \see Double.hpp + */ #include "Double.hpp" /*-----------------------------------*/ @@ -57,13 +57,13 @@ int NOMAD::Double::_max_cardinality = 0; /* constructor 1 */ /*-----------------------------------------------*/ NOMAD::Double::Double ( void ) - : _value ( 0.0 ) , - _defined ( false ) +: _value ( 0.0 ) , +_defined ( false ) { #ifdef MEMORY_DEBUG - ++NOMAD::Double::_cardinality; - if ( NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality ) - ++NOMAD::Double::_max_cardinality; + ++NOMAD::Double::_cardinality; + if ( NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality ) + ++NOMAD::Double::_max_cardinality; #endif } @@ -71,13 +71,13 @@ NOMAD::Double::Double ( void ) /* constructor 2 */ /*-----------------------------------------------*/ NOMAD::Double::Double ( double v ) - : _value ( v ) , - _defined ( true ) +: _value ( v ) , +_defined ( true ) { #ifdef MEMORY_DEBUG - ++NOMAD::Double::_cardinality; - if (NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality) - ++NOMAD::Double::_max_cardinality; + ++NOMAD::Double::_cardinality; + if (NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality) + ++NOMAD::Double::_max_cardinality; #endif } @@ -85,35 +85,35 @@ NOMAD::Double::Double ( double v ) /* constructor 3 */ /*-----------------------------------------------*/ NOMAD::Double::Double ( const NOMAD::Double & d ) - : _value ( d._value ) , - _defined ( d._defined ) +: _value ( d._value ) , +_defined ( d._defined ) { #ifdef MEMORY_DEBUG - ++NOMAD::Double::_cardinality; - if (NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality) - ++NOMAD::Double::_max_cardinality; + ++NOMAD::Double::_cardinality; + if (NOMAD::Double::_cardinality > NOMAD::Double::_max_cardinality) + ++NOMAD::Double::_max_cardinality; #endif } /*-----------------------------------------------*/ /* destructor */ /*-----------------------------------------------*/ -NOMAD::Double::~Double ( void ) +NOMAD::Double::~Double ( void ) { #ifdef MEMORY_DEBUG - --NOMAD::Double::_cardinality; + --NOMAD::Double::_cardinality; #endif } /*-----------------------------------------------*/ /* set epsilon (static) */ /*-----------------------------------------------*/ -void NOMAD::Double::set_epsilon ( double eps ) +void NOMAD::Double::set_epsilon ( double eps ) { - if ( eps <= 0.0 ) - throw NOMAD::Exception ( "Double.cpp" , __LINE__ , - "NOMAD::Double::set_epsilon(): invalid epsilon" ); - NOMAD::Double::_epsilon = eps; + if ( eps <= 0.0 ) + throw NOMAD::Exception ( "Double.cpp" , __LINE__ , + "NOMAD::Double::set_epsilon(): invalid epsilon" ); + NOMAD::Double::_epsilon = eps; } /*-----------------------------------------------*/ @@ -121,10 +121,10 @@ void NOMAD::Double::set_epsilon ( double eps ) /*-----------------------------------------------*/ double NOMAD::Double::value ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::value(): value not defined" ); - return _value; + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::value(): value not defined" ); + return _value; } /*------------------------------------------*/ @@ -132,13 +132,13 @@ double NOMAD::Double::value ( void ) const /*------------------------------------------*/ std::istream & NOMAD::operator >> ( std::istream & in , NOMAD::Double & d ) { - std::string s; - in >> s; - - if ( !in.fail() && !d.atof (s) ) - in.setstate ( std::ios::failbit ); - - return in; + std::string s; + in >> s; + + if ( !in.fail() && !d.atof (s) ) + in.setstate ( std::ios::failbit ); + + return in; } /*-----------------------------------------------*/ @@ -146,52 +146,52 @@ std::istream & NOMAD::operator >> ( std::istream & in , NOMAD::Double & d ) /*-----------------------------------------------*/ bool NOMAD::Double::atof ( const std::string & ss ) { - - std::string s = ss; - NOMAD::toupper(s); - - if ( s == "-" || ss == NOMAD::Double::_undef_str ) { - _value = 0.0; - _defined = false; - return true; - } - - if ( s == "INF" || s == "+INF" || - ss == NOMAD::Double::_inf_str || - ss == ("+" + NOMAD::Double::_inf_str) ) { - _value = NOMAD::INF; - _defined = true; - return true; - } - - if ( s == "-INF" || ss == ("-" + NOMAD::Double::_inf_str) ) { - _value = -NOMAD::INF; - _defined = true; - return true; - } - - if ( s.empty() || (s.size() == 1 && !isdigit(s[0])) ) - return false; - - if ( !isdigit(s[0]) && s[0] != '+' && s[0] != '-' && s[0] != '.' ) - return false; - - size_t n = s.size(); - for ( size_t k = 1 ; k < n ; ++k ) - if ( !isdigit(s[k]) && s[k] != '.' ) { - if ( s[k] == 'E' ) { - if ( s.size() == k+1 ) - return false; - ++k; - if ( !isdigit(s[k]) && s[k] != '+' && s[k] != '-' ) - return false; - } - else - return false; + + std::string s = ss; + NOMAD::toupper(s); + + if ( s == "-" || ss == NOMAD::Double::_undef_str ) { + _value = 0.0; + _defined = false; + return true; } - - *this = std::atof ( s.c_str() ); - return true; + + if ( s == "INF" || s == "+INF" || + ss == NOMAD::Double::_inf_str || + ss == ("+" + NOMAD::Double::_inf_str) ) { + _value = NOMAD::INF; + _defined = true; + return true; + } + + if ( s == "-INF" || ss == ("-" + NOMAD::Double::_inf_str) ) { + _value = -NOMAD::INF; + _defined = true; + return true; + } + + if ( s.empty() || (s.size() == 1 && !isdigit(s[0])) ) + return false; + + if ( !isdigit(s[0]) && s[0] != '+' && s[0] != '-' && s[0] != '.' ) + return false; + + size_t n = s.size(); + for ( size_t k = 1 ; k < n ; ++k ) + if ( !isdigit(s[k]) && s[k] != '.' ) { + if ( s[k] == 'E' ) { + if ( s.size() == k+1 ) + return false; + ++k; + if ( !isdigit(s[k]) && s[k] != '+' && s[k] != '-' ) + return false; + } + else + return false; + } + + *this = std::atof ( s.c_str() ); + return true; } /*-------------------------------------------------*/ @@ -200,16 +200,16 @@ bool NOMAD::Double::atof ( const std::string & ss ) /*-------------------------------------------------*/ bool NOMAD::Double::relative_atof ( const std::string & s , bool & relative ) { - if ( std::toupper(s[0]) == 'R' ) { - relative = true; - std::string ss = s; - ss.erase(ss.begin()); - if ( !atof(ss) ) - return false; - return ( *this >= 0.0 ); - } - relative = false; - return atof(s); + if ( std::toupper(s[0]) == 'R' ) { + relative = true; + std::string ss = s; + ss.erase(ss.begin()); + if ( !atof(ss) ) + return false; + return ( *this >= 0.0 ); + } + relative = false; + return atof(s); } /*-----------------------------------------------*/ @@ -217,9 +217,9 @@ bool NOMAD::Double::relative_atof ( const std::string & s , bool & relative ) /*-----------------------------------------------*/ bool NOMAD::Double::is_integer ( void ) const { - if ( !_defined ) - return false; - return ( NOMAD::Double(std::floor(_value))) == ( NOMAD::Double(std::ceil(_value)) ); + if ( !_defined ) + return false; + return ( NOMAD::Double(std::floor(_value))) == ( NOMAD::Double(std::ceil(_value)) ); } /*-----------------------------------------------*/ @@ -227,21 +227,21 @@ bool NOMAD::Double::is_integer ( void ) const /*-----------------------------------------------*/ bool NOMAD::Double::is_binary ( void ) const { - if ( !_defined ) - return false; - return ( NOMAD::Double(_value) == 0.0 || NOMAD::Double(_value) == 1.0 ); + if ( !_defined ) + return false; + return ( NOMAD::Double(_value) == 0.0 || NOMAD::Double(_value) == 1.0 ); } /*-------------------------------------*/ /* d = d1/d2 */ /*-------------------------------------*/ const NOMAD::Double NOMAD::operator / ( const NOMAD::Double & d1 , - const NOMAD::Double & d2 ) + const NOMAD::Double & d2 ) { - if ( d2.value() == 0.0 ) - throw NOMAD::Double::Invalid_Value ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 / d2: division by zero" ); - return NOMAD::Double ( d1.value() / d2.value() ); + if ( d2.value() == 0.0 ) + throw NOMAD::Double::Invalid_Value ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 / d2: division by zero" ); + return NOMAD::Double ( d1.value() / d2.value() ); } /*-------------------------------------*/ @@ -249,11 +249,11 @@ const NOMAD::Double NOMAD::operator / ( const NOMAD::Double & d1 , /*-------------------------------------*/ const NOMAD::Double & NOMAD::Double::operator += ( const NOMAD::Double & d2 ) { - if ( !_defined || !d2._defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 += d2: d1 or d2 not defined" ); - _value += d2._value; - return *this; + if ( !_defined || !d2._defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 += d2: d1 or d2 not defined" ); + _value += d2._value; + return *this; } /*-------------------------------------*/ @@ -261,11 +261,11 @@ const NOMAD::Double & NOMAD::Double::operator += ( const NOMAD::Double & d2 ) /*-------------------------------------*/ const NOMAD::Double & NOMAD::Double::operator -= ( const NOMAD::Double & d2 ) { - if ( !_defined || !d2._defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 -= d2: d1 or d2 not defined" ); - _value -= d2._value; - return *this; + if ( !_defined || !d2._defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 -= d2: d1 or d2 not defined" ); + _value -= d2._value; + return *this; } /*-------------------------------------*/ @@ -273,11 +273,11 @@ const NOMAD::Double & NOMAD::Double::operator -= ( const NOMAD::Double & d2 ) /*-------------------------------------*/ const NOMAD::Double & NOMAD::Double::operator *= ( const NOMAD::Double & d2 ) { - if ( !_defined || !d2._defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 *= d2: d1 or d2 not defined" ); - _value *= d2._value; - return *this; + if ( !_defined || !d2._defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 *= d2: d1 or d2 not defined" ); + _value *= d2._value; + return *this; } /*-------------------------------------*/ @@ -285,14 +285,14 @@ const NOMAD::Double & NOMAD::Double::operator *= ( const NOMAD::Double & d2 ) /*-------------------------------------*/ const NOMAD::Double & NOMAD::Double::operator /= ( const NOMAD::Double & d2 ) { - if ( !_defined || !d2._defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 /= d2: d1 or d2 not defined" ); - if ( d2._value == 0.0 ) - throw Invalid_Value ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d1 /= d2: division by zero" ); - _value /= d2._value; - return *this; + if ( !_defined || !d2._defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 /= d2: d1 or d2 not defined" ); + if ( d2._value == 0.0 ) + throw Invalid_Value ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d1 /= d2: division by zero" ); + _value /= d2._value; + return *this; } /*-------------------------------------*/ @@ -300,10 +300,10 @@ const NOMAD::Double & NOMAD::Double::operator /= ( const NOMAD::Double & d2 ) /*-------------------------------------*/ NOMAD::Double & NOMAD::Double::operator++ ( void ) { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: ++d: d not defined" ); - _value += 1; - return *this; + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: ++d: d not defined" ); + _value += 1; + return *this; } /*-------------------------------------*/ @@ -311,13 +311,13 @@ NOMAD::Double & NOMAD::Double::operator++ ( void ) /*-------------------------------------*/ NOMAD::Double NOMAD::Double::operator++ ( int n ) { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: d++: d not defined" ); - NOMAD::Double tmp = *this; - if( n <= 0 ) - n = 1; - _value += n; - return tmp; + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: d++: d not defined" ); + NOMAD::Double tmp = *this; + if( n <= 0 ) + n = 1; + _value += n; + return tmp; } /*-------------------------------------*/ @@ -325,10 +325,10 @@ NOMAD::Double NOMAD::Double::operator++ ( int n ) /*-------------------------------------*/ NOMAD::Double & NOMAD::Double::operator-- ( void ) { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: --d: d not defined" ); - _value -= 1; - return *this; + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , "NOMAD::Double: --d: d not defined" ); + _value -= 1; + return *this; } /*-------------------------------------*/ @@ -336,14 +336,14 @@ NOMAD::Double & NOMAD::Double::operator-- ( void ) /*-------------------------------------*/ NOMAD::Double NOMAD::Double::operator-- ( int n ) { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double: d--: d not defined" ); - NOMAD::Double tmp = *this; - if ( n <= 0 ) - n = 1; - _value -= n; - return tmp; + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double: d--: d not defined" ); + NOMAD::Double tmp = *this; + if ( n <= 0 ) + n = 1; + _value -= n; + return tmp; } /*-------------------------------------*/ @@ -351,16 +351,16 @@ NOMAD::Double NOMAD::Double::operator-- ( int n ) /*-------------------------------------*/ NOMAD::Double & NOMAD::Double::operator = ( const NOMAD::Double & d ) { - _value = d._value; - _defined = d._defined; - return *this; + _value = d._value; + _defined = d._defined; + return *this; } NOMAD::Double & NOMAD::Double::operator = ( double r ) { - _value = r; - _defined = true; - return *this; + _value = r; + _defined = true; + return *this; } /*------------------------------------------*/ @@ -368,176 +368,179 @@ NOMAD::Double & NOMAD::Double::operator = ( double r ) /*------------------------------------------*/ void NOMAD::Double::display ( const NOMAD::Display & out ) const { - if ( _defined ) { - if ( _value == NOMAD::INF ) - out << NOMAD::Double::_inf_str; - else if ( _value == -NOMAD::INF ) - out << "-" << NOMAD::Double::_inf_str; - else if ( std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) - out << static_cast<int>(_value); + if ( _defined ) { + if ( _value == NOMAD::INF ) + out << NOMAD::Double::_inf_str; + else if ( _value == -NOMAD::INF ) + out << "-" << NOMAD::Double::_inf_str; + else if ( std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) + out << static_cast<int>(_value); + else + out << _value; + } else - out << _value; - } - else - out << NOMAD::Double::_undef_str; + out << NOMAD::Double::_undef_str; } /*------------------------------------------*/ /* display with format */ /*------------------------------------------*/ void NOMAD::Double::display ( const NOMAD::Display & out , - const std::string & format ) const -{ - // interpret the format: - // --------------------- - - // %f w=-1 prec=-1 c='f' - // %4.5f w= 4 prec= 5 c='f' - // %4f w= 4 prec= 1 c='f' - // %.5f w=-1 prec= 5 c='f' - // %.f w=-1 prec= 0 c='f' - - // c may be in 'e', 'E', 'f', 'g', 'G', 'd', or 'i' - - // e Scientific notation (mantise/exponent) using e character 3.9265e+2 - // E Scientific notation (mantise/exponent) using E character 3.9265E+2 - // f Decimal floating point 392.65 - // g Use the shorter of %e or %f 392.65 - // G Use the shorter of %E or %f 392.65 - // d or i Integer rounded value 393 - - - std::string format2 = format; - - int w = -1; - int prec = -1; - char c = 0; - - if ( !format2.empty() && format2[0]=='%' ) - { - - size_t n = format2.size(); - - c = format2[n-1]; - - if ( c!='e' && c!='E' && c!='f' && c!='g' && c!='G' && c!='d' && c!='i' ) { - c = ( std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) ? - 'd' : 'f'; - format2.push_back(c); - ++n; - } - - if ( n > 2 ) - { - - std::string sw , sprec; - - size_t k = format2.find("."); - - if ( k > 0 && k < n-1 ) - { - if ( n==3 ) { - sprec = "0"; - } - else - { - if ( k > 1 ) - sw = format2.substr ( 1 , k-1 ); - sprec = format2.substr ( k+1 , n-k-2 ); - } - } - else { - sw = format2.substr ( 1 , n-2 ); - } - - if ( !NOMAD::atoi ( sw , w ) ) - w = -1; - - if ( !NOMAD::atoi ( sprec , prec ) ) - prec = -1; - } - - if ( c=='d' || c=='i' ) - prec = 0; - } - - // display the value: - out << std::setw(w); - if ( _defined ) - { - if ( _value == NOMAD::INF ) - out << NOMAD::Double::_inf_str; - else if ( c=='d' || c=='i' || - ( format2.empty() && - std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) ) - out << round(); - else - { - - int old_prec = out.precision(); - std::ios_base::fmtflags old_flags = out.flags(); - - if ( prec >= 0 ) - out.precision ( prec ); - - if ( c == 'f' ) - out.setf ( std::ios::fixed ); - - else if ( c == 'e' ) - { - out.unsetf ( std::ios::fixed ); - out.setf ( std::ios::scientific ); - } - - else if ( c == 'E' ) - { - out.unsetf ( std::ios::fixed ); - out.setf ( std::ios::scientific | std::ios::uppercase ); - } - - else if ( c == 'g' ) - { - std::ostringstream streamS,streamF; - streamS.precision ( prec ); - streamF.precision ( prec ); - streamF.unsetf(std::ios::scientific); - streamF.setf( std::ios::fixed ); - streamS.unsetf(std::ios::fixed); - streamS.setf( std::ios::scientific); - streamS << _value; - streamF << _value; - if (streamS.str().length() < streamF.str().length()) - out.setf(std::ios::scientific); - else - out.setf(std::ios::fixed); - } - - else if ( c == 'G' ) - { - std::ostringstream streamS,streamF; - streamS.precision ( prec ); - streamF.precision ( prec ); - streamF.unsetf(std::ios::scientific); - streamF.setf( std::ios::fixed ); - streamS.unsetf(std::ios::fixed); - streamS.setf( std::ios::scientific); - streamS << _value ; - streamF << _value ; - if (streamS.str().length() < streamF.str().length()) - out.setf(std::ios::scientific | std::ios::uppercase ); - else - out.setf(std::ios::fixed | std::ios::uppercase ); - - } - - out << _value; - - out.precision ( old_prec ); - out.flags ( old_flags ); - } - } - else - out << NOMAD::Double::_undef_str; + const std::string & format ) const +{ + // interpret the format: + // --------------------- + + // %f w=-1 prec=-1 c='f' + // %4.5f w= 4 prec= 5 c='f' + // %4f w= 4 prec= 1 c='f' + // %.5f w=-1 prec= 5 c='f' + // %.f w=-1 prec= 0 c='f' + + // c may be in 'e', 'E', 'f', 'g', 'G', 'd', or 'i' + + // e Scientific notation (mantise/exponent) using e character 3.9265e+2 + // E Scientific notation (mantise/exponent) using E character 3.9265E+2 + // f Decimal floating point 392.65 + // g Use the shorter of %e or %f 392.65 + // G Use the shorter of %E or %f 392.65 + // d or i Integer rounded value 393 + + + std::string format2 = format; + + int w = -1; + int prec = -1; + char c = 0; + + if ( !format2.empty() && format2[0]=='%' ) + { + + size_t n = format2.size(); + + c = format2[n-1]; + + if ( c!='e' && c!='E' && c!='f' && c!='g' && c!='G' && c!='d' && c!='i' ) + { + c = ( std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) ? + 'd' : 'f'; + format2.push_back(c); + ++n; + } + + if ( n > 2 ) + { + + std::string sw , sprec; + + size_t k = format2.find("."); + + if ( k > 0 && k < n-1 ) + { + if ( n==3 ) + { + sprec = "0"; + } + else + { + if ( k > 1 ) + sw = format2.substr ( 1 , k-1 ); + sprec = format2.substr ( k+1 , n-k-2 ); + } + } + else + { + sw = format2.substr ( 1 , n-2 ); + } + + if ( !NOMAD::atoi ( sw , w ) ) + w = -1; + + if ( !NOMAD::atoi ( sprec , prec ) ) + prec = -1; + } + + if ( c=='d' || c=='i' ) + prec = 0; + } + + // display the value: + out << std::setw(w); + if ( _defined ) + { + if ( _value == NOMAD::INF ) + out << NOMAD::Double::_inf_str; + else if ( c=='d' || c=='i' || + ( format2.empty() && + std::floor(_value) == std::ceil(_value) && fabs(_value) < INT_MAX-1 ) ) + out << round(); + else + { + + int old_prec = out.precision(); + std::ios_base::fmtflags old_flags = out.flags(); + + if ( prec >= 0 ) + out.precision ( prec ); + + if ( c == 'f' ) + out.setf ( std::ios::fixed ); + + else if ( c == 'e' ) + { + out.unsetf ( std::ios::fixed ); + out.setf ( std::ios::scientific ); + } + + else if ( c == 'E' ) + { + out.unsetf ( std::ios::fixed ); + out.setf ( std::ios::scientific | std::ios::uppercase ); + } + + else if ( c == 'g' ) + { + std::ostringstream streamS,streamF; + streamS.precision ( prec ); + streamF.precision ( prec ); + streamF.unsetf(std::ios::scientific); + streamF.setf( std::ios::fixed ); + streamS.unsetf(std::ios::fixed); + streamS.setf( std::ios::scientific); + streamS << _value; + streamF << _value; + if (streamS.str().length() < streamF.str().length()) + out.setf(std::ios::scientific); + else + out.setf(std::ios::fixed); + + } + + else if ( c == 'G' ) + { + std::ostringstream streamS,streamF; + streamS.precision ( prec ); + streamF.precision ( prec ); + streamF.unsetf(std::ios::scientific); + streamF.setf( std::ios::fixed ); + streamS.unsetf(std::ios::fixed); + streamS.setf( std::ios::scientific); + streamS << _value ; + streamF << _value ; + if (streamS.str().length() < streamF.str().length()) + out.setf(std::ios::scientific | std::ios::uppercase ); + else + out.setf(std::ios::fixed | std::ios::uppercase ); + } + + out << _value; + + out.precision ( old_prec ); + out.flags ( old_flags ); + } + } + else + out << NOMAD::Double::_undef_str; } /*------------------------------------------*/ @@ -545,10 +548,10 @@ void NOMAD::Double::display ( const NOMAD::Display & out , /*------------------------------------------*/ int NOMAD::Double::round ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::round(): value not defined" ); - return static_cast<int>(_value < 0.0 ? -std::floor(.5-_value) : std::floor(.5+_value)); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::round(): value not defined" ); + return static_cast<int>(_value < 0.0 ? -std::floor(.5-_value) : std::floor(.5+_value)); } @@ -557,10 +560,10 @@ int NOMAD::Double::round ( void ) const /*------------------------------------------*/ const NOMAD::Double NOMAD::Double::ceil ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::ceil(): value not defined" ); - return NOMAD::Double(std::ceil(_value)); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::ceil(): value not defined" ); + return NOMAD::Double(std::ceil(_value)); } /*------------------------------------------*/ @@ -568,10 +571,10 @@ const NOMAD::Double NOMAD::Double::ceil ( void ) const /*------------------------------------------*/ const NOMAD::Double NOMAD::Double::floor ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::floor(): value not defined" ); - return NOMAD::Double(std::floor(_value)); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::floor(): value not defined" ); + return NOMAD::Double(std::floor(_value)); } /*------------------------------------------*/ @@ -579,10 +582,10 @@ const NOMAD::Double NOMAD::Double::floor ( void ) const /*------------------------------------------*/ const NOMAD::Double NOMAD::Double::abs ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::abs(): value not defined" ); - return fabs ( _value ); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::abs(): value not defined" ); + return fabs ( _value ); } /*------------------------------------------*/ @@ -590,10 +593,10 @@ const NOMAD::Double NOMAD::Double::abs ( void ) const /*------------------------------------------*/ const NOMAD::Double NOMAD::Double::pow2 ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::pow2(): value not defined" ); - return pow ( _value , 2 ); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::pow2(): value not defined" ); + return pow ( _value , 2 ); } /*------------------------------------------*/ @@ -601,14 +604,14 @@ const NOMAD::Double NOMAD::Double::pow2 ( void ) const /*------------------------------------------*/ const NOMAD::Double NOMAD::Double::sqrt ( void ) const { - if ( !_defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::sqrt(): value not defined" ); - if ( *this < 0.0 ) - throw NOMAD::Double::Invalid_Value ( "Double.cpp" , __LINE__ , - "NOMAD::Double::sqrt(x): x < 0" ); - - return std::sqrt ( _value ); + if ( !_defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::sqrt(): value not defined" ); + if ( *this < 0.0 ) + throw NOMAD::Double::Invalid_Value ( "Double.cpp" , __LINE__ , + "NOMAD::Double::sqrt(x): x < 0" ); + + return std::sqrt ( _value ); } /*---------------------------------------------*/ @@ -622,45 +625,45 @@ const NOMAD::Double NOMAD::Double::sqrt ( void ) const // // The error will be in [0;2] // -// Modified: 2012-06-07, S. Le Digabel +// Modified: 2014-06-07, S. Le Digabel // const NOMAD::Double NOMAD::Double::rel_err ( const Double & x ) const { - if ( !_defined || !x._defined ) - throw Not_Defined ( "Double.cpp" , __LINE__ , - "NOMAD::Double::rel_err(): one of the values is not defined" ); - - // 1. test if x==y: - if ( this == &x || _value == x._value ) - return 0.0; - - double diff = fabs ( _value - x._value ); - - // 2. test if one of the values is zero: - if ( _value == 0.0 || x._value == 0.0 ) { - - // we return min{2,|x-y|} (instead of 1): - if ( diff > 2.0 ) - return 2.0; - return diff; - } - - // 3. compute the original error: - double a = fabs ( _value ); - double b = fabs ( x._value ); - double err = diff / ( (a<b) ? b : a ); - - // 4. test if we have opposite signs: - if ( _value * x._value < 0.0 ) { - - // the original error gives err in ]1;2] : we check if |x-y| < 1 - // and if so we return |x-y| : - if ( diff < 1.0 ) - return diff; - } - - // we return the original error: - return err; + if ( !_defined || !x._defined ) + throw Not_Defined ( "Double.cpp" , __LINE__ , + "NOMAD::Double::rel_err(): one of the values is not defined" ); + + // 1. test if x==y: + if ( this == &x || _value == x._value ) + return 0.0; + + double diff = fabs ( _value - x._value ); + + // 2. test if one of the values is zero: + if ( _value == 0.0 || x._value == 0.0 ) { + + // we return min{2,|x-y|} (instead of 1): + if ( diff > 2.0 ) + return 2.0; + return diff; + } + + // 3. compute the original error: + double a = fabs ( _value ); + double b = fabs ( x._value ); + double err = diff / ( (a<b) ? b : a ); + + // 4. test if we have opposite signs: + if ( _value * x._value < 0.0 ) { + + // the original error gives err in ]1;2] : we check if |x-y| < 1 + // and if so we return |x-y| : + if ( diff < 1.0 ) + return diff; + } + + // we return the original error: + return err; } @@ -669,22 +672,22 @@ const NOMAD::Double NOMAD::Double::rel_err ( const Double & x ) const /*---------------------------------------------------------------------*/ bool NOMAD::Double::comp_with_undef ( const NOMAD::Double & d ) const { - if ( this == &d ) - return false; - - bool d1d = is_defined(); - bool d2d = d.is_defined(); - - if ( !d1d && !d2d ) - return false; - - if ( !d1d ) - return true; - - if ( !d2d ) - return false; - - return ( *this < d ); + if ( this == &d ) + return false; + + bool d1d = is_defined(); + bool d2d = d.is_defined(); + + if ( !d1d && !d2d ) + return false; + + if ( !d1d ) + return true; + + if ( !d2d ) + return false; + + return ( *this < d ); } /*------------------------------------*/ @@ -692,23 +695,23 @@ bool NOMAD::Double::comp_with_undef ( const NOMAD::Double & d ) const /* ( *this = ref + k * delta ) */ /*------------------------------------*/ void NOMAD::Double::project_to_mesh ( const NOMAD::Double & ref , - const NOMAD::Double & delta , - const NOMAD::Double & lb , - const NOMAD::Double & ub ) -{ - if ( !_defined ) - return; - - NOMAD::Double v0 = ( ref._defined ) ? ref : 0.0; - - if ( delta._defined && delta != 0.0 ) { - - *this = v0 + ( (*this-v0) / delta).round() * delta; - - if ( ub._defined && *this > ub ) - *this = ub; - - if ( lb._defined && *this < lb ) - *this = lb; - } + const NOMAD::Double & delta , + const NOMAD::Double & lb , + const NOMAD::Double & ub ) +{ + if ( !_defined ) + return; + + NOMAD::Double v0 = ( ref._defined ) ? ref : 0.0; + + if ( delta._defined && delta != 0.0 ) { + + *this = v0 + ( (*this-v0) / delta).round() * delta; + + if ( ub._defined && *this > ub ) + *this = ub; + + if ( lb._defined && *this < lb ) + *this = lb; + } } diff --git a/src/Double.hpp b/src/Double.hpp index 305071055f9d39781d64b5d0553be13b8b4bb16e..5a9cf7f6ee92a74dd836d3cae54332b8c02f20d8 100644 --- a/src/Double.hpp +++ b/src/Double.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Eval_Point.cpp b/src/Eval_Point.cpp index 02ddbe717fcded7af6874f23f0f383cef165daab..fa193fe0ad3afcbb0eb020fe8d25134918a0519d 100644 --- a/src/Eval_Point.cpp +++ b/src/Eval_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Eval_Point.cpp - \brief Evaluation point (implementation) - \author Sebastien Le Digabel - \date 2010-04-14 - \see Eval_Point.hpp -*/ + \file Eval_Point.cpp + \brief Evaluation point (implementation) + \author Sebastien Le Digabel + \date 2010-04-14 + \see Eval_Point.hpp + */ #include "Cache_File_Point.hpp" #include "Eval_Point.hpp" #include "Slave.hpp" @@ -48,25 +48,25 @@ /* static members initialization */ /*-----------------------------------*/ int NOMAD::Eval_Point::_current_tag = 0; - +int NOMAD::Eval_Point::_current_bbe = 0; +int NOMAD::Eval_Point::_current_sgte_bbe = 0; /*---------------------------------------------------------------------*/ /* constructor 1 */ /*---------------------------------------------------------------------*/ NOMAD::Eval_Point::Eval_Point ( void ) - : _tag ( NOMAD::Eval_Point::_current_tag++ ) , - _signature ( NULL ) , - _in_cache ( false ) , - _current_run ( false ) , - _eval_type ( NOMAD::TRUTH ) , - _direction ( NULL ) , - _mesh_index ( NULL ) , - _poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , - _eval_status ( NOMAD::UNDEFINED_STATUS ) , - _EB_ok ( true ) +: _tag ( NOMAD::Eval_Point::_current_tag++ ) , +_signature ( NULL ) , +_in_cache ( false ) , +_current_run ( false ) , +_eval_type ( NOMAD::TRUTH ) , +_direction ( NULL ) , +_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , +_eval_status ( NOMAD::UNDEFINED_STATUS ) , +_EB_ok ( true ) { #ifdef MODEL_STATS - _mod_use = -1; - _nY = -1; + _mod_use = -1; + _nY = -1; #endif } @@ -74,22 +74,21 @@ NOMAD::Eval_Point::Eval_Point ( void ) /* constructor 2 */ /*---------------------------------------------------------------------*/ NOMAD::Eval_Point::Eval_Point ( int n , int m ) - : NOMAD::Point ( n ) , - _tag ( NOMAD::Eval_Point::_current_tag++ ) , - _signature ( NULL ) , - _in_cache ( false ) , - _current_run ( false ) , - _eval_type ( NOMAD::TRUTH ) , - _direction ( NULL ) , - _mesh_index ( NULL ) , - _poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , - _eval_status ( NOMAD::UNDEFINED_STATUS ) , - _EB_ok ( true ) , - _bb_outputs ( m ) +: NOMAD::Point ( n ) , +_tag ( NOMAD::Eval_Point::_current_tag++ ) , +_signature ( NULL ) , +_in_cache ( false ) , +_current_run ( false ) , +_eval_type ( NOMAD::TRUTH ) , +_direction ( NULL ) , +_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , +_eval_status ( NOMAD::UNDEFINED_STATUS ) , +_EB_ok ( true ) , +_bb_outputs ( m ) { #ifdef MODEL_STATS - _mod_use = -1; - _nY = -1; + _mod_use = -1; + _nY = -1; #endif } @@ -99,12 +98,11 @@ NOMAD::Eval_Point::Eval_Point ( int n , int m ) NOMAD::Eval_Point::Eval_Point ( const NOMAD::Point & x , int m ) : NOMAD::Point ( x ) , _direction ( NULL ) , -_mesh_index ( NULL ) , _bb_outputs ( m ) { #ifdef MODEL_STATS - _mod_use = -1; - _nY = -1; + _mod_use = -1; + _nY = -1; #endif } @@ -115,40 +113,39 @@ _bb_outputs ( m ) /* constructor 4 ( used in Cache::load() ) */ /*---------------------------------------------------------------------*/ NOMAD::Eval_Point::Eval_Point ( const NOMAD::Cache_File_Point & x , NOMAD::eval_type et ) - : NOMAD::Point ( x.get_n() ) , - _tag ( NOMAD::Eval_Point::_current_tag++ ) , - _signature ( NULL ) , - _in_cache ( false ) , - _current_run ( false ) , - _eval_type ( et ) , - _direction ( NULL ) , - _mesh_index ( NULL ) , - _poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , - _EB_ok ( true ) , - _bb_outputs ( x.get_bb_outputs() ) +: NOMAD::Point ( x.get_n() ) , +_tag ( NOMAD::Eval_Point::_current_tag++ ) , +_signature ( NULL ) , +_in_cache ( false ) , +_current_run ( false ) , +_eval_type ( et ) , +_direction ( NULL ) , +_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ) , +_EB_ok ( true ) , +_bb_outputs ( x.get_bb_outputs() ) { - int n = size(); - for ( int i = 0 ; i < n ; ++i ) - (*this)[i] = x.get_coord(i); - - switch ( x.get_eval_status() ) { - case 0: - _eval_status = NOMAD::EVAL_FAIL; - break; - case 1: - _eval_status = NOMAD::EVAL_OK; - break; - case 2: - _eval_status = NOMAD::EVAL_IN_PROGRESS; - break; - case 3: - _eval_status = NOMAD::UNDEFINED_STATUS; - break; - } - + int n = size(); + for ( int i = 0 ; i < n ; ++i ) + (*this)[i] = x.get_coord(i); + + switch ( x.get_eval_status() ) { + case 0: + _eval_status = NOMAD::EVAL_FAIL; + break; + case 1: + _eval_status = NOMAD::EVAL_OK; + break; + case 2: + _eval_status = NOMAD::EVAL_IN_PROGRESS; + break; + case 3: + _eval_status = NOMAD::UNDEFINED_STATUS; + break; + } + #ifdef MODEL_STATS - _mod_use = -1; - _nY = -1; + _mod_use = -1; + _nY = -1; #endif } @@ -157,40 +154,33 @@ NOMAD::Eval_Point::Eval_Point ( const NOMAD::Cache_File_Point & x , NOMAD::eval_ /* copy constructor */ /*---------------------------------------------------------------------*/ NOMAD::Eval_Point::Eval_Point ( const Eval_Point & x ) - : NOMAD::Point ( x.get_n() ) , - _tag ( NOMAD::Eval_Point::_current_tag++ ) , - _signature ( x._signature ) , - _f ( x._f ) , - _h ( x._h ) , - _in_cache ( x._in_cache ) , - _current_run ( x._current_run ) , - _eval_type ( x._eval_type ) , - _direction ( NULL ) , - _mesh_index ( NULL ) , - _poll_center_type ( x._poll_center_type ) , - _eval_status ( x._eval_status ) , - _EB_ok ( x._EB_ok ) , - _bb_outputs ( x.get_bb_outputs() ) , - _user_eval_priority ( x._user_eval_priority ) , - _rand_eval_priority ( x._rand_eval_priority ) -{ - // point coordinates: - int n = size(); - for ( int i = 0 ; i < n ; ++i ) - (*this)[i] = x[i]; - - // _direction: - if ( x._direction ) - _direction = new Direction ( *x._direction ); - - // _mesh_index: - if ( x._mesh_index ) { - _mesh_index = new int; - *_mesh_index = *x._mesh_index; - } - +: NOMAD::Point ( x.get_n() ) , +_tag ( NOMAD::Eval_Point::_current_tag++ ) , +_signature ( x._signature ) , +_f ( x._f ) , +_h ( x._h ) , +_in_cache ( x._in_cache ) , +_current_run ( x._current_run ) , +_eval_type ( x._eval_type ) , +_direction ( NULL ) , +_poll_center_type ( x._poll_center_type ) , +_eval_status ( x._eval_status ) , +_EB_ok ( x._EB_ok ) , +_bb_outputs ( x.get_bb_outputs() ) , +_user_eval_priority ( x._user_eval_priority ) , +_rand_eval_priority ( x._rand_eval_priority ) +{ + // point coordinates: + int n = size(); + for ( int i = 0 ; i < n ; ++i ) + (*this)[i] = x[i]; + + // _direction: + if ( x._direction ) + _direction = new Direction ( *x._direction ); + #ifdef MODEL_STATS - set_model_data ( x ); + set_model_data ( x ); #endif } @@ -199,10 +189,8 @@ NOMAD::Eval_Point::Eval_Point ( const Eval_Point & x ) /*---------------------------------------------------------------------*/ NOMAD::Eval_Point::~Eval_Point ( void ) { - if (_mesh_index) - delete _mesh_index; - if (_direction) - delete _direction; + if ( _direction ) + delete _direction; } /*-------------------------------------------------------*/ @@ -210,14 +198,14 @@ NOMAD::Eval_Point::~Eval_Point ( void ) /*-------------------------------------------------------*/ void NOMAD::Eval_Point::set ( int n , int m ) { - reset ( n ); - _bb_outputs.reset ( m ); + reset ( n ); + _bb_outputs.reset ( m ); } void NOMAD::Eval_Point::set ( const NOMAD::Point & x , int m ) { - NOMAD::Point::operator = ( x ); - _bb_outputs.reset ( m ); + NOMAD::Point::operator = ( x ); + _bb_outputs.reset ( m ); } /*-------------------------------------------------------*/ @@ -227,32 +215,41 @@ void NOMAD::Eval_Point::set ( const NOMAD::Point & x , int m ) /*-------------------------------------------------------*/ void NOMAD::Eval_Point::set_tag ( int tag ) { - _tag = tag; - NOMAD::Eval_Point::_current_tag = tag+1; + _tag = tag; + NOMAD::Eval_Point::_current_tag = tag+1; } -/*---------------------------------------------------------------------*/ -/* SET methods for _direction and _mesh_index */ -/*---------------------------------------------------------------------*/ -void NOMAD::Eval_Point::set_mesh_index ( const int * ell ) +/*-------------------------------------------------------*/ +/* increment counted black box evaluations */ +/* All points have unique tags */ +/*-------------------------------------------------------*/ +void NOMAD::Eval_Point::increment_bbe ( void ) +{ + NOMAD::Eval_Point::_current_bbe ++; + _bbe=_current_bbe; +} + + +/*-------------------------------------------------------*/ +/* increment counted black box evaluations */ +/* All points have unique tags */ +/*-------------------------------------------------------*/ +void NOMAD::Eval_Point::increment_sgte_bbe ( void ) { - delete _mesh_index; - _mesh_index = NULL; - if ( ell ) { - _mesh_index = new int; - *_mesh_index = *ell; - } + NOMAD::Eval_Point::_current_sgte_bbe ++; + _sgte_bbe=_current_sgte_bbe; } + void NOMAD::Eval_Point::set_direction ( const NOMAD::Direction * dir ) { - delete _direction; - _direction = ( dir ) ? new NOMAD::Direction ( *dir ) : NULL; + delete _direction; + _direction = ( dir ) ? new NOMAD::Direction ( *dir ) : NULL; } void NOMAD::Eval_Point::set_poll_center ( const NOMAD::Eval_Point * pc ) { - _poll_center=pc; + _poll_center=pc; } /*-------------------------------------------------------*/ @@ -260,16 +257,16 @@ void NOMAD::Eval_Point::set_poll_center ( const NOMAD::Eval_Point * pc ) /*-------------------------------------------------------*/ void NOMAD::Eval_Point::set_signature ( NOMAD::Signature * s ) { - if ( !s ) { - _signature = NULL; - return; - } - - if ( !s->is_compatible(*this) ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "x.Eval_Point::set_signature(s): x and s are incompatible" ); - - _signature = s; + if ( !s ) { + _signature = NULL; + return; + } + + if ( !s->is_compatible(*this) ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "x.Eval_Point::set_signature(s): x and s are incompatible" ); + + _signature = s; } /*------------------------------------------*/ @@ -278,11 +275,11 @@ void NOMAD::Eval_Point::set_signature ( NOMAD::Signature * s ) NOMAD::Signature * NOMAD::Eval_Point::get_signature ( void ) const { #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "Eval_Point::get_signature(): cannot be invoked by slave processes" ); + if ( !NOMAD::Slave::is_master() ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "Eval_Point::get_signature(): cannot be invoked by slave processes" ); #endif - return _signature; + return _signature; } /*-------------------------------------------------------*/ @@ -290,7 +287,7 @@ NOMAD::Signature * NOMAD::Eval_Point::get_signature ( void ) const /*-------------------------------------------------------*/ int NOMAD::Eval_Point::size_of ( void ) const { - return NOMAD::Point::size_of () + + return NOMAD::Point::size_of () + _bb_outputs.size_of () + _f.size_of () + _h.size_of () + @@ -303,10 +300,8 @@ int NOMAD::Eval_Point::size_of ( void ) const sizeof (_eval_type ) + sizeof (_eval_status ) + sizeof (_EB_ok ) + - sizeof (_mesh_index ) + sizeof (_direction ) + - (( _mesh_index ) ? sizeof(*_mesh_index) : 0) + - ((_direction ) ? _direction->size_of() : 0); + ((_direction ) ? _direction->size_of() : 0); } /*-------------------------------------------------------*/ @@ -314,10 +309,10 @@ int NOMAD::Eval_Point::size_of ( void ) const /*-------------------------------------------------------*/ void NOMAD::Eval_Point::scale ( void ) { - if ( !_signature ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "x.Eval_Point::scale(): x has no signature" ); - _signature->scale ( *this ); + if ( !_signature ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "x.Eval_Point::scale(): x has no signature" ); + _signature->scale ( *this ); } /*-------------------------------------------------------*/ @@ -325,10 +320,10 @@ void NOMAD::Eval_Point::scale ( void ) /*-------------------------------------------------------*/ void NOMAD::Eval_Point::unscale ( void ) { - if ( !_signature ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "x.Eval_Point::unscale(): x has no signature" ); - _signature->unscale ( *this ); + if ( !_signature ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "x.Eval_Point::unscale(): x has no signature" ); + _signature->unscale ( *this ); } /*-------------------------------------------------------*/ @@ -337,10 +332,10 @@ void NOMAD::Eval_Point::unscale ( void ) /*-------------------------------------------------------*/ bool NOMAD::Eval_Point::snap_to_bounds ( void ) { - if ( !_signature ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "x.Eval_Point::snap_to_bounds(): x has no signature" ); - return _signature->snap_to_bounds ( *this , _direction ); + if ( !_signature ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "x.Eval_Point::snap_to_bounds(): x has no signature" ); + return _signature->snap_to_bounds ( *this , _direction ); } /*-------------------------------------------------------*/ @@ -349,11 +344,11 @@ bool NOMAD::Eval_Point::snap_to_bounds ( void ) /*-------------------------------------------------------*/ bool NOMAD::Eval_Point::treat_periodic_variables ( NOMAD::Direction *& new_dir ) { - if (!_signature) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "x.Eval_Point::treat_periodic_variables(): x has no signature" ); - - return _signature->treat_periodic_variables ( *this , _direction , new_dir ); + if (!_signature) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "x.Eval_Point::treat_periodic_variables(): x has no signature" ); + + return _signature->treat_periodic_variables ( *this , _direction , new_dir ); } /*--------------------------------------------------*/ @@ -361,69 +356,72 @@ bool NOMAD::Eval_Point::treat_periodic_variables ( NOMAD::Direction *& new_dir ) /*--------------------------------------------------*/ bool NOMAD::Eval_Point::check ( int m , NOMAD::check_failed_type & cf ) const { - if ( size() <= 0 || !_signature || m != _bb_outputs.size() ) { - std::string err = "Eval_Point::check() could not procede"; - if ( !_signature ) - err += " (no signature)"; - else if ( m != _bb_outputs.size() ) - err += " (wrong number of blackbox outputs)"; - else - err += " (point size <= 0 !)"; - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , err ); - } - - cf = NOMAD::CHECK_OK; - - const std::vector<NOMAD::bb_input_type> - & input_types = _signature->get_input_types(); - const NOMAD::Point & lb = _signature->get_lb(); - const NOMAD::Point & ub = _signature->get_ub(); - const NOMAD::Point & fv = _signature->get_fixed_variables(); - int n = size(); - NOMAD::bb_input_type iti; - - for ( int i = 0 ; i < n ; ++i ) { - - const NOMAD::Double xi = (*this)[i]; - - // undefined coordinates ? - if ( !xi.is_defined() ) - throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , - "Eval_Point::check() could not procede (undefined coordinates)" ); - - // check the bounds: - const NOMAD::Double & lbi = lb[i]; - if ( lbi.is_defined() && xi < lbi ) { - cf = NOMAD::LB_FAIL; - return false; - } - - const NOMAD::Double & ubi = ub[i]; - if ( ubi.is_defined() && xi > ubi ) { - cf = NOMAD::UB_FAIL; - return false; + if ( size() <= 0 || !_signature || m != _bb_outputs.size() ) { + std::string err = "Eval_Point::check() could not procede"; + if ( !_signature ) + err += " (no signature)"; + else if ( m != _bb_outputs.size() ) + err += " (wrong number of blackbox outputs)"; + else + err += " (point size <= 0 !)"; + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , err ); } - - // check the integer/categorical/binary variables: - iti = input_types[i]; - if ( iti == NOMAD::BINARY && !xi.is_binary() ) { - cf = NOMAD::BIN_FAIL; - return false; - } - if ( ( iti == NOMAD::INTEGER || iti == NOMAD::CATEGORICAL ) - && !xi.is_integer() ) { - cf = ( iti == NOMAD::INTEGER ) ? NOMAD::INT_FAIL : NOMAD::CAT_FAIL; - return false; + + cf = NOMAD::CHECK_OK; + + const std::vector<NOMAD::bb_input_type> + & input_types = _signature->get_input_types(); + const NOMAD::Point & lb = _signature->get_lb(); + const NOMAD::Point & ub = _signature->get_ub(); + const NOMAD::Point & fv = _signature->get_fixed_variables(); + int n = size(); + NOMAD::bb_input_type iti; + + for ( int i = 0 ; i < n ; ++i ) + { + + const NOMAD::Double xi = (*this)[i]; + + // undefined coordinates ? + if ( !xi.is_defined() ) + throw NOMAD::Exception ( "Eval_Point.cpp" , __LINE__ , + "Eval_Point::check() could not procede (undefined coordinates)" ); + + // check the bounds: + const NOMAD::Double & lbi = lb[i]; + if ( lbi.is_defined() && xi < lbi ) + { + cf = NOMAD::LB_FAIL; + return false; + } + + const NOMAD::Double & ubi = ub[i]; + if ( ubi.is_defined() && xi > ubi ) + { + cf = NOMAD::UB_FAIL; + return false; + } + + // check the integer/categorical/binary variables: + iti = input_types[i]; + if ( iti == NOMAD::BINARY && !xi.is_binary() ) { + cf = NOMAD::BIN_FAIL; + return false; + } + if ( ( iti == NOMAD::INTEGER || iti == NOMAD::CATEGORICAL ) + && !xi.is_integer() ) { + cf = ( iti == NOMAD::INTEGER ) ? NOMAD::INT_FAIL : NOMAD::CAT_FAIL; + return false; + } + + // check the fixed-variables: + const NOMAD::Double & fvi = fv[i]; + if ( fvi.is_defined() && fvi != xi ) { + cf = NOMAD::FIX_VAR_FAIL; + return false; + } } - - // check the fixed-variables: - const NOMAD::Double & fvi = fv[i]; - if ( fvi.is_defined() && fvi != xi ) { - cf = NOMAD::FIX_VAR_FAIL; - return false; - } - } - return true; + return true; } /*--------------------------------------------------*/ @@ -431,44 +429,44 @@ bool NOMAD::Eval_Point::check ( int m , NOMAD::check_failed_type & cf ) const /*--------------------------------------------------*/ void NOMAD::Eval_Point::display_tag ( const NOMAD::Display & out ) const { - out << "#"; - out.display_int_w ( _tag , NOMAD::Eval_Point::_current_tag ); + out << "#"; + out.display_int_w ( _tag , NOMAD::Eval_Point::_current_tag ); } /*--------------------------------------------------*/ /* display */ /*--------------------------------------------------*/ -void NOMAD::Eval_Point::display ( const NOMAD::Display & out , bool in_block ) const +void NOMAD::Eval_Point::display_eval( const NOMAD::Display & out , bool in_block ) const { - if ( in_block ) { - - std::ostringstream oss; - oss << "#" << _tag; - out << NOMAD::open_block ( oss.str() ) - << "x = ( "; - NOMAD::Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl - << "F(x) = [ "; - _bb_outputs.display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " ]" << std::endl; - if ( _h.is_defined() ) - out << "h = " << _h << std::endl; - if ( _f.is_defined() ) - out << "f = " << _f << std::endl; - out.close_block(); - } - else { - display_tag ( out ); - out << " x=( "; - NOMAD::Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " ) F(x)=[ "; - _bb_outputs.display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " ]"; - if ( _h.is_defined() ) - out << " h=" << _h; - if ( _f.is_defined() ) - out << " f=" << _f; - } + if ( in_block ) { + + std::ostringstream oss; + oss << "#" << _tag; + out << NOMAD::open_block ( oss.str() ) + << "x = ( "; + NOMAD::Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl + << "F(x) = [ "; + _bb_outputs.display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " ]" << std::endl; + if ( _h.is_defined() ) + out << "h = " << _h << std::endl; + if ( _f.is_defined() ) + out << "f = " << _f << std::endl; + out.close_block(); + } + else { + display_tag ( out ); + out << " x=( "; + NOMAD::Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " ) F(x)=[ "; + _bb_outputs.display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " ]"; + if ( _h.is_defined() ) + out << " h=" << _h; + if ( _f.is_defined() ) + out << " f=" << _f; + } } /*--------------------------------------------------------------*/ @@ -477,21 +475,21 @@ void NOMAD::Eval_Point::display ( const NOMAD::Display & out , bool in_block ) c /*--------------------------------------------------------------*/ bool NOMAD::Eval_Point::operator < ( const NOMAD::Eval_Point & x ) const { - if ( this == &x || !is_eval_ok() || !_EB_ok ) + if ( this == &x || !is_eval_ok() || !_EB_ok ) + return false; + + double h = _h.value(); + double f = _f.value(); + double hx = x._h.value(); + double fx = x._f.value(); + + if ( h < hx ) + return ( f <= fx ); + + if ( h == hx ) + return ( f < fx ); + return false; - - double h = _h.value(); - double f = _f.value(); - double hx = x._h.value(); - double fx = x._f.value(); - - if ( h < hx ) - return ( f <= fx ); - - if ( h == hx ) - return ( f < fx ); - - return false; } /*--------------------------------------------------------------*/ @@ -499,19 +497,19 @@ bool NOMAD::Eval_Point::operator < ( const NOMAD::Eval_Point & x ) const /*--------------------------------------------------------------*/ bool NOMAD::Eval_Point::check_nan ( void ) const { - int m = _bb_outputs.size(); - for ( int i = 0 ; i < m ; ++i ) { - if ( _bb_outputs[i].is_defined() ) { + int m = _bb_outputs.size(); + for ( int i = 0 ; i < m ; ++i ) { + if ( _bb_outputs[i].is_defined() ) { #ifdef WINDOWS - if ( isnan ( _bb_outputs[i].value() ) ) - return true; + if ( isnan ( _bb_outputs[i].value() ) ) + return true; #else - if ( std::isnan ( _bb_outputs[i].value() ) ) - return true; + if ( std::isnan ( _bb_outputs[i].value() ) ) + return true; #endif + } } - } - return false; + return false; } #ifdef MODEL_STATS @@ -521,12 +519,12 @@ bool NOMAD::Eval_Point::check_nan ( void ) const /*--------------------------------------------------------------*/ void NOMAD::Eval_Point::set_model_data ( const NOMAD::Eval_Point & x ) const { - _mod_use = x._mod_use; - _nY = x._nY; - _cond = x._cond; - _Yw = x._Yw; - _mh = x._mh; - _mf = x._mf; + _mod_use = x._mod_use; + _nY = x._nY; + _cond = x._cond; + _Yw = x._Yw; + _mh = x._mh; + _mf = x._mf; } /*--------------------------------------------------------------*/ @@ -534,12 +532,12 @@ void NOMAD::Eval_Point::set_model_data ( const NOMAD::Eval_Point & x ) const /*--------------------------------------------------------------*/ void NOMAD::Eval_Point::clear_model_data ( void ) const { - _mod_use = -1; - _nY = -1; - _cond.clear(); - _Yw.clear(); - _mh.clear(); - _mf.clear(); + _mod_use = -1; + _nY = -1; + _cond.clear(); + _Yw.clear(); + _mh.clear(); + _mf.clear(); } #endif diff --git a/src/Eval_Point.hpp b/src/Eval_Point.hpp index 72e204f7b7c61407df8f06324d6c8779ac10fb87..64184038d35c779ebae5d33517c53f99188023a6 100644 --- a/src/Eval_Point.hpp +++ b/src/Eval_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Eval_Point.hpp - \brief Evaluation point (headers) - \author Sebastien Le Digabel - \date 2010-04-14 - \see Eval_Point.cpp -*/ + \file Eval_Point.hpp + \brief Evaluation point (headers) + \author Sebastien Le Digabel + \date 2010-04-14 + \see Eval_Point.cpp + */ #ifndef __EVAL_POINT__ #define __EVAL_POINT__ @@ -47,527 +47,570 @@ #include "Cache_File_Point.hpp" #include "Set_Element.hpp" -#ifdef WINDOWS +#ifdef WINDOWS #ifndef isnan inline bool isnan ( double x ) { return x != x; } #endif #endif namespace NOMAD { - - /// Class for the representation of an evaluation point. - /** - An evaluation point gathers the point coordinates \c x, and the blackbox - outputs at these coordinates \c f(x). - */ - class Eval_Point : public NOMAD::Point { - - private: - static int _current_tag; ///< Current tag for all NOMAD::Eval_Point objects. - int _tag; ///< Unique tag. - - NOMAD::Signature * _signature; ///< Signature of the point. - - /** - \c f is explicitely computed by a NOMAD::Evaluator object - and is not saved in the cache file. - */ - NOMAD::Double _f; - - /** - \c h is explicitely computed by a NOMAD::Evaluator object - and is not saved in the cache file. - */ - NOMAD::Double _h; - - /// Flag equal to \c true if this eval point is in the cache. - mutable bool _in_cache; - - /** - Flag equal to \c true if the point has been evaluated - during the current run. - */ - mutable bool _current_run; - - /// Type of the evaluation (true function or surrogate). - NOMAD::eval_type _eval_type; - - /// Direction from which the point has been constructed. - /** - May be \c NULL if no direction has been used. - */ - NOMAD::Direction * _direction; - - - /// Poll center from which the point has been constructed. - /** - May be \c NULL if no direction has been used. - */ - const NOMAD::Eval_Point * _poll_center; - - /** - - Pointer to the Mesh index \c ell from which - the point has been constructed. - - May be \c NULL if no mesh index has been used. - */ - int * _mesh_index; - - /** - Type of the poll center (feasible or not) - from which the point has been constructed. - */ - NOMAD::poll_center_type _poll_center_type; - - /// Evaluation status. + /// Class for the representation of an evaluation point. /** - Indicates if the evaluation failed, succeeded, - or is in progress. - */ - NOMAD::eval_status_type _eval_status; - - /// Flag equal to \c true if all EB constraints have been satisfied. - bool _EB_ok; - - /// Blackbox outputs. - NOMAD::Point _bb_outputs; - - /// User evaluation priority. - /** - - Decided by the user in his custom + An evaluation point gathers the point coordinates \c x, and the blackbox + outputs at these coordinates \c f(x). + */ + class Eval_Point : public NOMAD::Point { + + private: + + static int _current_tag; ///< Current tag for all NOMAD::Eval_Point objects. + int _tag; ///< Unique tag. + + static int _current_bbe; ///< Current bbe for all NOMAD::Eval_Point objects + static int _current_sgte_bbe; ///< Current sgte_bbe for all NOMAD::Eval_Point objects . + int _bbe; /// Recorded bbe for current NOMAD::Eval_Point object + int _sgte_bbe; /// Recorded sgte_bbe for current NOMAD::Eval_Point object + int _real_time; /// Recorded time for current NOMAD::Eval_Point object + + NOMAD::Signature * _signature; ///< Signature of the point. + + /** + \c f is explicitely computed by a NOMAD::Evaluator object + and is not saved in the cache file. + */ + NOMAD::Double _f; + + /** + \c h is explicitely computed by a NOMAD::Evaluator object + and is not saved in the cache file. + */ + NOMAD::Double _h; + + /// Flag equal to \c true if this eval point is in the cache. + mutable bool _in_cache; + + /** + Flag equal to \c true if the point has been evaluated + during the current run. + */ + mutable bool _current_run; + + /// Type of the evaluation (true function or surrogate). + NOMAD::eval_type _eval_type; + + /// Direction from which the point has been constructed. + /** + May be \c NULL if no direction has been used. + */ + NOMAD::Direction * _direction; + + + /// Poll center from which the point has been constructed. + /** + May be \c NULL if no direction has been used. + */ + const NOMAD::Eval_Point * _poll_center; + + /** + Type of the poll center (feasible or not) + from which the point has been constructed. + */ + NOMAD::poll_center_type _poll_center_type; + + /// Evaluation status. + /** + Indicates if the evaluation failed, succeeded, + or is in progress. + */ + NOMAD::eval_status_type _eval_status; + + /// Flag equal to \c true if all EB constraints have been satisfied. + bool _EB_ok; + + /// Blackbox outputs. + NOMAD::Point _bb_outputs; + + /// User evaluation priority. + /** + - Decided by the user in his custom NOMAD::Evaluator::eval_x() function, via \c set_user_eval_priority(). - - Points with higher priorities + - Points with higher priorities will be evaluated first. - */ - NOMAD::Double _user_eval_priority; - - /// Random evaluation priority. - /** - Same idea than \c _user_eval_priority - for a random ordering of trial points. - */ - NOMAD::Double _rand_eval_priority; - - /// Affectation operator. - /** - \param x The right-hand side object -- \b IN. - \return \c *this as the result of the affectation. - */ - Eval_Point & operator = ( const Eval_Point & x ); - - public: - - /// Constructor #1. - explicit Eval_Point ( void ); - - /// Constructor #2. - /** - \param n Number of variables -- \b IN. - \param m Number of blackbox outputs -- \b IN. - */ - Eval_Point ( int n , int m ); - - /// Constructor #3. - /** - \param x Coordinates of a point taken in a cache -- \b IN. - \param et Type of the evaluation (true or surrogate) -- \b IN. - */ - explicit Eval_Point ( const NOMAD::Cache_File_Point & x , - NOMAD::eval_type et ); - - - ///Constructor 4 - /** - \param x Coordinates of a point -- \b IN. - \param m Number of blackbox outputs -- \b IN. - */ - explicit Eval_Point ( const NOMAD::Point & x, int m ) ; - - - - /// Copy constructor. - /** - \param x The copied object. - */ - explicit Eval_Point ( const Eval_Point & x ); - - /// Destructor. - virtual ~Eval_Point ( void ); - - /// Check the evaluation point. - /** - \param m Number of blackbox outputs -- \b IN. - \param cf The reason for a check failure -- \b OUT. - \return A boolean equal to \c true if the point is valid. - */ - bool check ( int m , NOMAD::check_failed_type & cf ) const; - - /*---------------*/ - /* GET methods */ - /*---------------*/ - - /// Size of the point in memory. - /** - \return Size of the point in memory, in bytes. - */ - virtual int size_of ( void ) const; - - /// Access to the signature of the point. - /** - \return A pointer to the signature of the point. - */ - NOMAD::Signature * get_signature ( void ) const; - - /// Access to the number of blackbox outputs. - /** - \return Number of blackbox outputs. - */ - int get_m ( void ) const { return _bb_outputs.size(); } - - /// Access to the number of variables. - /** - \return Number of variables. - */ - int get_n ( void ) const { return size(); } - - /// Check if the evaluation at this point is valid. - /** - \return A boolean equal to \c true if the evaluation is valid. - */ - bool is_eval_ok ( void ) const { return (_eval_status == NOMAD::EVAL_OK); } - - /// Access to the tag of the point. - /** - \return The tag. - */ - int get_tag ( void ) const { return _tag; } - - /// Access to the objective value \c f. - /** - \return The objective value. - */ - const NOMAD::Double & get_f ( void ) const { return _f; } - - /// Access to the feasibility value \c h. - /** - \return The feasibility value. - */ - const NOMAD::Double & get_h ( void ) const { return _h; } - - /// Access to the blackbox outputs. - /** - \return The \c m blackblack outputs. - */ - const NOMAD::Point & get_bb_outputs ( void ) const { return _bb_outputs; } - - /// Access to the direction used to construct the point. - /** - \return The direction used to construct the point; - may be \c NULL if no direction has been used. - */ - const NOMAD::Direction * get_direction ( void ) const { return _direction; } - - /// Access to the poll_center used to construct the point. - /** - \return The poll center used to construct the point; - may be \c NULL if no poll center has been used. - */ - const NOMAD::Eval_Point * get_poll_center ( void ) const { return _poll_center ; } - - /// Access to the mesh index \c ell used to construct the point. - /** - \return A pointer to the mesh index value; - may be \c NULL if no mesh index was used. - */ - const int * get_mesh_index ( void ) const { return _mesh_index; } - - /// Check if the point has been generated during the current run. - /** - \return A boolean equal to \c true if the point has been - generated during the current run. - */ - bool get_current_run ( void ) const { return _current_run; } - - /// Check if the point is in cache. - /** - \return A boolean equal to \c true if the point is in cache. - */ - bool is_in_cache ( void ) const { return _in_cache; } - - /// Check if the point respects the EB constraints. - /** - \return A boolean equal to \c true if the point respects the EB constraints. - */ - bool is_EB_ok ( void ) const { return _EB_ok; } - - /// Access to the evaluation type. - /** - \return The evaluation type (true or surrogate). - */ - NOMAD::eval_type get_eval_type ( void ) const { return _eval_type; } - - /// Access to the poll center type. - /** - \return The poll center type (feasible or not). - */ - NOMAD::poll_center_type get_poll_center_type ( void ) const - { - return _poll_center_type; - } - - /// Access to the evaluation status. - /** - \return The evaluation status - (evaluation failed, succeeded, or is in progress). - */ - NOMAD::eval_status_type get_eval_status ( void ) const { return _eval_status; } - - /// Access to the user evaluation priority. - /** - \return The user evaluation priority. - */ - const NOMAD::Double & get_user_eval_priority ( void ) const - { - return _user_eval_priority; - } - - /// Access to the random evaluation priority. - /** - \return The random evaluation priority. - */ - const NOMAD::Double & get_rand_eval_priority ( void ) const - { - return _rand_eval_priority; - } - - /// Check the point feasibility. - /** - The point is feasible if \c h \c <= \c h_min. - \param h_min Feasibility threshold -- \b IN. - \return A boolean equal to \c true if the point is feasible. - */ - bool is_feasible ( const NOMAD::Double & h_min ) const - { - return ( _h.is_defined() && _h <= h_min ); - } - - /// Scaling. - void scale ( void ); - - /// Unscaling. - void unscale ( void ); - - /// Snap to bounds. - /** - \return A boolean equal to \c true if the snapping went well. - */ - bool snap_to_bounds ( void ); - - /// Treat the periodic variables. - /** - \param new_dir A pointer to the modified direction used to generate - this point from the poll center; may be \c NULL if no - direction has been used -- \b OUT. - \return A boolean equal to \c true if the treatment went well. - */ - bool treat_periodic_variables ( NOMAD::Direction *& new_dir ); - - /// Comparison operator. - /** - \param x Right-hand side object -- \b IN. - \return A boolean equal to \c true if \c *this \c < \c x . - */ - bool operator < ( const Eval_Point & x ) const; - - /*---------------*/ - /* SET methods */ - /*---------------*/ - - /// Set the \c n and \c m. - /** - \param n Number of variables -- \b IN. - \param m Number of blackbox outputs -- \b IN. - */ - void set ( int n , int m ); - - /// Set the coordinates and \c m. - /** - \param x Coordinates of the point -- \b IN. - \param m Number of blackbox outputs -- \b IN. - */ - void set ( const NOMAD::Point & x , int m ); - - /// Set the tag. - /** - \param tag The tag -- \b IN. - */ - void set_tag ( int tag ); - - /// Set the objective value \c f. - /** - \param f Objective value -- \b IN. - */ - void set_f ( const NOMAD::Double & f ) { _f = f; } - - /// Set the feasibility value \c h. - /** - \param h Feasibility value -- \b IN. - */ - void set_h ( const NOMAD::Double & h ) { _h = h; } - - /// Set the user evaluation priority. - /** - \param u User evaluation priority -- \b IN. - */ - void set_user_eval_priority ( const NOMAD::Double & u ) { _user_eval_priority = u; } - - /// Set the random evaluation priority. - /** - \param r Random evaluation priority -- \b IN. - */ - void set_rand_eval_priority ( const NOMAD::Double & r ) { _rand_eval_priority = r; } - - /// Set one blackbox output. - /** - \param i Index of the output to set -- \b IN. - \param v Value of the output -- \b IN. - */ - void set_bb_output ( int i , const NOMAD::Double & v ) { _bb_outputs[i]= v; } - - /// Set all blackbox outputs. - /** - \param b The \c m blackbox outputs -- \b IN. - */ - void set_bb_output ( const NOMAD::Point & b ) { _bb_outputs = b; } - - /// Set the evaluation status. - /** - \param e Evaluation status (failed, succeeded, or in progress) - -- \b IN. - */ - void set_eval_status ( const NOMAD::eval_status_type & e ) { _eval_status = e; } - - /// Set if the point respects the EB constraints. - /** - \param e A boolean equal to \c true if the point - respects the EB constraints. - */ - void set_EB_ok ( bool e ) { _EB_ok = e; } - - /// Set the evaluation type. - /** - \param e Evaluation type (true or surrogate) -- \b IN. - */ - void set_eval_type ( NOMAD::eval_type e ) { _eval_type = e; } - - /// Set the type of the poll center. - /** - \param p Type of the poll center (feasible or not) -- \b IN. - */ - void set_poll_center_type ( NOMAD::poll_center_type p ) { _poll_center_type = p; } - - /// Indicate if the point has been generated during the current run. - /** - \param c A boolean equal to \c true if the point - has been generated during the current run -- \b IN. - */ - void set_current_run ( bool c ) const { _current_run = c; } - - /// Indicate if the point is in cache. - /** - \param i A boolean equal to \c true if the point is in cache - -- \b IN. - */ - void set_in_cache ( bool i ) const { _in_cache = i; } - - /// Set the mesh index. - /** - \param ell A pointer to the mesh index; may be \c NULL -- \b IN. - */ - void set_mesh_index ( const int * ell ); - - /// Set the direction used to create the point. - /** - \param d A pointer to the direction; may be \c NULL -- \b IN. - */ - void set_direction ( const NOMAD::Direction * d ); - - - /// Set the poll center used to create the point. - /** - \param d A pointer to the poll center; may be \c NULL -- \b IN. - */ - void set_poll_center ( const NOMAD::Eval_Point * d ); - - /// Set the signature. - /** - \param s A pointer to the signature -- \b IN. - */ - void set_signature ( NOMAD::Signature * s ); - - /// Check if there are nan's in the blackbox outputs: - /** - \return \c true if there is at least a nan. - */ - bool check_nan ( void ) const; - + */ + NOMAD::Double _user_eval_priority; + + /// Random evaluation priority. + /** + Same idea than \c _user_eval_priority + for a random ordering of trial points. + */ + NOMAD::Double _rand_eval_priority; + + /// Affectation operator. + /** + \param x The right-hand side object -- \b IN. + \return \c *this as the result of the affectation. + */ + Eval_Point & operator = ( const Eval_Point & x ); + + public: + + /// Constructor #1. + explicit Eval_Point ( void ); + + /// Constructor #2. + /** + \param n Number of variables -- \b IN. + \param m Number of blackbox outputs -- \b IN. + */ + Eval_Point ( int n , int m ); + + /// Constructor #3. + /** + \param x Coordinates of a point taken in a cache -- \b IN. + \param et Type of the evaluation (true or surrogate) -- \b IN. + */ + explicit Eval_Point ( const NOMAD::Cache_File_Point & x , + NOMAD::eval_type et ); + + + ///Constructor 4 + /** + \param x Coordinates of a point -- \b IN. + \param m Number of blackbox outputs -- \b IN. + */ + explicit Eval_Point ( const NOMAD::Point & x, int m ) ; + + + + /// Copy constructor. + /** + \param x The copied object. + */ + explicit Eval_Point ( const Eval_Point & x ); + + /// Destructor. + virtual ~Eval_Point ( void ); + + /// Check the evaluation point. + /** + \param m Number of blackbox outputs -- \b IN. + \param cf The reason for a check failure -- \b OUT. + \return A boolean equal to \c true if the point is valid. + */ + bool check ( int m , NOMAD::check_failed_type & cf ) const; + + /*---------------*/ + /* GET methods */ + /*---------------*/ + + /// Size of the point in memory. + /** + \return Size of the point in memory, in bytes. + */ + virtual int size_of ( void ) const; + + /// Access to the signature of the point. + /** + \return A pointer to the signature of the point. + */ + NOMAD::Signature * get_signature ( void ) const; + + /// Access to the number of blackbox outputs. + /** + \return Number of blackbox outputs. + */ + int get_m ( void ) const { return _bb_outputs.size(); } + + /// Access to the number of variables. + /** + \return Number of variables. + */ + int get_n ( void ) const { return size(); } + + /// Check if the evaluation at this point is valid. + /** + \return A boolean equal to \c true if the evaluation is valid. + */ + bool is_eval_ok ( void ) const { return (_eval_status == NOMAD::EVAL_OK); } + + /// Check if the evaluation at this point has been rejected by the user. + /** + \return A boolean equal to \c true if the evaluation has been rejected by the user. + */ + bool check_rejected ( void ) const { return (_eval_status == NOMAD::EVAL_USER_REJECT); } + + + /// Access to the tag of the point. + /** + \return The tag. + */ + int get_tag ( void ) const { return _tag; } + + /// Access to the bbe of the point. + /** + \return The bbe. + */ + int get_bbe ( void ) const { return _bbe; } + + /// Access to the bbe of the point. + /** + \return The sgte_bbe. + */ + int get_sgte_bbe ( void ) const { return _sgte_bbe; } + + + /// Access to the real time of the point evaluation. + /** + \return The real time. + */ + int get_real_time( void ) const { return _real_time; } + + + /// Access to the objective value \c f. + /** + \return The objective value. + */ + const NOMAD::Double & get_f ( void ) const { return _f; } + + /// Access to the feasibility value \c h. + /** + \return The feasibility value. + */ + const NOMAD::Double & get_h ( void ) const { return _h; } + + /// Access to the blackbox outputs. + /** + \return The \c m blackblack outputs. + */ + const NOMAD::Point & get_bb_outputs ( void ) const { return _bb_outputs; } + + /// Access to the direction used to construct the point. + /** + \return The direction used to construct the point; + may be \c NULL if no direction has been used. + */ + const NOMAD::Direction * get_direction ( void ) const { return _direction; } + + /// Access to the poll_center used to construct the point. + /** + \return The poll center used to construct the point; + may be \c NULL if no poll center has been used. + */ + const NOMAD::Eval_Point * get_poll_center ( void ) const { return _poll_center ; } + + + /// Check if the point has been generated during the current run. + /** + \return A boolean equal to \c true if the point has been + generated during the current run. + */ + bool get_current_run ( void ) const { return _current_run; } + + /// Check if the point is in cache. + /** + \return A boolean equal to \c true if the point is in cache. + */ + bool is_in_cache ( void ) const { return _in_cache; } + + /// Check if the point respects the EB constraints. + /** + \return A boolean equal to \c true if the point respects the EB constraints. + */ + bool is_EB_ok ( void ) const { return _EB_ok; } + + /// Access to the evaluation type. + /** + \return The evaluation type (true or surrogate). + */ + NOMAD::eval_type get_eval_type ( void ) const { return _eval_type; } + + /// Access to the poll center type. + /** + \return The poll center type (feasible or not). + */ + NOMAD::poll_center_type get_poll_center_type ( void ) const + { + return _poll_center_type; + } + + /// Access to the evaluation status. + /** + \return The evaluation status + (evaluation failed, succeeded, or is in progress). + */ + NOMAD::eval_status_type get_eval_status ( void ) const { return _eval_status; } + + /// Access to the user evaluation priority. + /** + \return The user evaluation priority. + */ + const NOMAD::Double & get_user_eval_priority ( void ) const + { + return _user_eval_priority; + } + + /// Access to the random evaluation priority. + /** + \return The random evaluation priority. + */ + const NOMAD::Double & get_rand_eval_priority ( void ) const + { + return _rand_eval_priority; + } + + /// Check the point feasibility. + /** + The point is feasible if \c h \c <= \c h_min. + \param h_min Feasibility threshold -- \b IN. + \return A boolean equal to \c true if the point is feasible. + */ + bool is_feasible ( const NOMAD::Double & h_min ) const + { + return ( _h.is_defined() && _h <= h_min ); + } + + /// Scaling. + void scale ( void ); + + /// Unscaling. + void unscale ( void ); + + /// Snap to bounds. + /** + \return A boolean equal to \c true if the snapping went well. + */ + bool snap_to_bounds ( void ); + + /// Treat the periodic variables. + /** + \param new_dir A pointer to the modified direction used to generate + this point from the poll center; may be \c NULL if no + direction has been used -- \b OUT. + \return A boolean equal to \c true if the treatment went well. + */ + bool treat_periodic_variables ( NOMAD::Direction *& new_dir ); + + /// Comparison operator. + /** + \param x Right-hand side object -- \b IN. + \return A boolean equal to \c true if \c *this \c < \c x . + */ + bool operator < ( const Eval_Point & x ) const; + + /*---------------*/ + /* SET methods */ + /*---------------*/ + + /// Set the \c n and \c m. + /** + \param n Number of variables -- \b IN. + \param m Number of blackbox outputs -- \b IN. + */ + void set ( int n , int m ); + + /// Set the coordinates and \c m. + /** + \param x Coordinates of the point -- \b IN. + \param m Number of blackbox outputs -- \b IN. + */ + void set ( const NOMAD::Point & x , int m ); + + /// Set the tag. + /** + \param tag The tag -- \b IN. + */ + void set_tag ( int tag ); + + /// Set the real time. + /** + \param real_time The real time -- \b IN. + */ + void set_real_time ( int real_time ){_real_time=real_time;} + + /// increment sgte_bbe. + /** + */ + void increment_sgte_bbe (void); + + /// increment bbe. + /** + */ + void increment_bbe (void); + + /// Set the blackbox evaluation number. + /** + \param bbe the evaluation number + */ + void set_bbe (int bbe){_bbe=bbe;} + + /// Set the objective value \c f. + /** + \param f Objective value -- \b IN. + */ + void set_f ( const NOMAD::Double & f ) { _f = f; } + + /// Set the feasibility value \c h. + /** + \param h Feasibility value -- \b IN. + */ + void set_h ( const NOMAD::Double & h ) { _h = h; } + + /// Set the user evaluation priority. + /** + \param u User evaluation priority -- \b IN. + */ + void set_user_eval_priority ( const NOMAD::Double & u ) { _user_eval_priority = u; } + + /// Set the random evaluation priority. + /** + \param r Random evaluation priority -- \b IN. + */ + void set_rand_eval_priority ( const NOMAD::Double & r ) { _rand_eval_priority = r; } + + /// Set one blackbox output. + /** + \param i Index of the output to set -- \b IN. + \param v Value of the output -- \b IN. + */ + void set_bb_output ( int i , const NOMAD::Double & v ) { _bb_outputs[i]= v; } + + /// Set all blackbox outputs. + /** + \param b The \c m blackbox outputs -- \b IN. + */ + void set_bb_output ( const NOMAD::Point & b ) { _bb_outputs = b; } + + /// Set the evaluation status. + /** + \param e Evaluation status (failed, succeeded, or in progress) + -- \b IN. + */ + void set_eval_status ( const NOMAD::eval_status_type & e ) { _eval_status = e; } + + /// Set if the point respects the EB constraints. + /** + \param e A boolean equal to \c true if the point + respects the EB constraints. + */ + void set_EB_ok ( bool e ) { _EB_ok = e; } + + /// Set the evaluation type. + /** + \param e Evaluation type (true or surrogate) -- \b IN. + */ + void set_eval_type ( NOMAD::eval_type e ) { _eval_type = e; } + + /// Set the type of the poll center. + /** + \param p Type of the poll center (feasible or not) -- \b IN. + */ + void set_poll_center_type ( NOMAD::poll_center_type p ) { _poll_center_type = p; } + + /// Indicate if the point has been generated during the current run. + /** + \param c A boolean equal to \c true if the point + has been generated during the current run -- \b IN. + */ + void set_current_run ( bool c ) const { _current_run = c; } + + /// Indicate if the point is in cache. + /** + \param i A boolean equal to \c true if the point is in cache + -- \b IN. + */ + void set_in_cache ( bool i ) const { _in_cache = i; } + + + /// Set the direction used to create the point. + /** + \param d A pointer to the direction; may be \c NULL -- \b IN. + */ + void set_direction ( const NOMAD::Direction * d ); + + + /// Set the poll center used to create the point. + /** + \param d A pointer to the poll center; may be \c NULL -- \b IN. + */ + void set_poll_center ( const NOMAD::Eval_Point * d ); + + /// Set the signature. + /** + \param s A pointer to the signature -- \b IN. + */ + void set_signature ( NOMAD::Signature * s ); + + /// Check if there are nan's in the blackbox outputs: + /** + \return \c true if there is at least a nan. + */ + bool check_nan ( void ) const; + + + /// Reset the tags and bbes + /** + */ + static void reset_tags_and_bbes ( void ) {_current_tag = 0;_current_bbe = 0;_current_sgte_bbe = 0;} + #ifdef MODEL_STATS - - private: - - mutable int _mod_use; // 1: model search; 2: model eval sort - mutable int _nY; - mutable NOMAD::Double _cond , _Yw , _mh , _mf; - - public: - - void set_mod_use ( int mod_use ) const { _mod_use = mod_use; } - void set_nY ( int nY ) const { _nY = nY; } - void set_cond ( const NOMAD::Double & cond ) const { _cond = cond; } - void set_Yw ( const NOMAD::Double & Yw ) const { _Yw = Yw; } - void set_mh ( const NOMAD::Double & mh ) const { _mh = mh; } - void set_mf ( const NOMAD::Double & mf ) const { _mf = mf; } - - int get_mod_use ( void ) const { return _mod_use; } - int get_nY ( void ) const { return _nY; } - const NOMAD::Double & get_cond ( void ) const { return _cond; } - const NOMAD::Double & get_Yw ( void ) const { return _Yw; } - const NOMAD::Double & get_mh ( void ) const { return _mh; } - const NOMAD::Double & get_mf ( void ) const { return _mf; } - - void set_model_data ( const NOMAD::Eval_Point & x ) const; - void clear_model_data ( void ) const; - + + private: + + mutable int _mod_use; // 1: model search; 2: model eval sort + mutable int _nY; + mutable NOMAD::Double _cond , _Yw , _mh , _mf; + + public: + + void set_mod_use ( int mod_use ) const { _mod_use = mod_use; } + void set_nY ( int nY ) const { _nY = nY; } + void set_cond ( const NOMAD::Double & cond ) const { _cond = cond; } + void set_Yw ( const NOMAD::Double & Yw ) const { _Yw = Yw; } + void set_mh ( const NOMAD::Double & mh ) const { _mh = mh; } + void set_mf ( const NOMAD::Double & mf ) const { _mf = mf; } + + int get_mod_use ( void ) const { return _mod_use; } + int get_nY ( void ) const { return _nY; } + const NOMAD::Double & get_cond ( void ) const { return _cond; } + const NOMAD::Double & get_Yw ( void ) const { return _Yw; } + const NOMAD::Double & get_mh ( void ) const { return _mh; } + const NOMAD::Double & get_mf ( void ) const { return _mf; } + + void set_model_data ( const NOMAD::Eval_Point & x ) const; + void clear_model_data ( void ) const; + #endif - - /// Display the tag of the point. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display_tag ( const NOMAD::Display & out ) const; - - /// Display. + + /// Display the tag of the point. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display_tag ( const NOMAD::Display & out ) const; + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + \param in_block If \c true, the point is displayed into an indented block + -- \b IN -- \b optional (default = \c true ). + */ + virtual void display_eval ( const NOMAD::Display & out , bool in_block = true ) const; + }; + + /// Display a NOMAD::Eval_Point object. /** - \param out The NOMAD::Display object -- \b IN. - \param in_block If \c true, the point is displayed into an indented block - -- \b IN -- \b optional (default = \c true ). - */ - virtual void display ( const NOMAD::Display & out , bool in_block = true ) const; - }; - - /// Display a NOMAD::Eval_Point object. - /** \param out The NOMAD::Display object -- \b IN. \param x The NOMAD::Eval_Point object to be displayed -- \b IN. \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Eval_Point & x ) - { - x.display ( out , true ); - return out; - } + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Eval_Point & x ) + { + x.display_eval (out , true ); + return out; + } } #endif diff --git a/src/Evaluator.cpp b/src/Evaluator.cpp index 657a698a2b2246cb74bad2aaf2c954054db8247c..f0f8ca91374a2a05ea9ec05f51302e8593c85cd1 100644 --- a/src/Evaluator.cpp +++ b/src/Evaluator.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Evaluator.cpp - \brief Evaluation of blackbox functions (implementation) - \author Sebastien Le Digabel - \date 2010-04-14 - \see Evaluator.hpp -*/ + \file Evaluator.cpp + \brief Evaluation of blackbox functions (implementation) + \author Sebastien Le Digabel + \date 2010-04-14 + \see Evaluator.hpp + */ #include "Evaluator.hpp" /*-----------------------------------*/ @@ -56,473 +56,774 @@ bool NOMAD::Evaluator::_force_quit = false; /* . _bb_exe includes the blackbox path */ /*-----------------------------------------------------------------*/ NOMAD::Evaluator::Evaluator ( const NOMAD::Parameters & p ) - : _p ( p ) , - _is_multi_obj ( false ) +: _p ( p ) , +_is_multi_obj ( false ) , +_is_model_evaluator ( false ) { - NOMAD::Evaluator::_force_quit = false; - - if ( _p.get_bb_exe().empty() ) - return; - - // _bbe_exe and _bb_nbo construction: - std::list<std::string>::const_iterator it = _p.get_bb_exe().begin(); - _bb_exe.push_back(*it); - _bb_nbo.push_back(1); - ++it; - - std::list<std::string>::const_iterator end = _p.get_bb_exe().end(); - while ( it != end ) { - if ( *it != _bb_exe[_bb_exe.size()-1] ) { - _bb_exe.push_back(*it); - _bb_nbo.push_back(1); - } - else - ++_bb_nbo[_bb_exe.size()-1]; - ++it; - } - - // we check that _bb_exe contains unique names and we add the problem path: - size_t k , l , n = _bb_exe.size() , nm1 = n-1; - for ( k = 0 ; k < nm1 ; ++k ) { - for ( l = k+1 ; l < n ; ++l ) - if ( _bb_exe[k] == _bb_exe[l] ) - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , - "problem with executable names" ); - } - - // construction of _sgte_exe: - bool has_sgte_exe = _p.has_sgte_exe(); - std::string err; - if ( has_sgte_exe ) { - for ( k = 0 ; k < n ; ++k ) { - - _sgte_exe.push_back ( _p.get_sgte_exe(_bb_exe[k]) ); - - if ( _sgte_exe[_sgte_exe.size()-1].empty() ) { - err = "blackbox executable \'" + _bb_exe[k] + "\' has no surrogate"; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); - } - } - } - - // process blakc-box executables (check and add problem path): - for ( k = 0 ; k < n ; ++k ) { - process_bb_exe_name ( _bb_exe[k] ); - if ( has_sgte_exe ) - process_bb_exe_name ( _sgte_exe[k] ); - } - - // blackbox names and indexes display: + NOMAD::Evaluator::_force_quit = false; + + if ( _p.get_bb_exe().empty() ) + return; + + // _bbe_exe and _bb_nbo construction: + std::list<std::string>::const_iterator it = _p.get_bb_exe().begin(); + _bb_exe.push_back(*it); + _bb_nbo.push_back(1); + ++it; + + std::list<std::string>::const_iterator end = _p.get_bb_exe().end(); + while ( it != end ) + { + if ( *it != _bb_exe[_bb_exe.size()-1] ) + { + _bb_exe.push_back(*it); + _bb_nbo.push_back(1); + } + else + ++_bb_nbo[_bb_exe.size()-1]; + ++it; + } + + // we check that _bb_exe contains unique names and we add the problem path: + size_t k , l , n = _bb_exe.size() , nm1 = n-1; + for ( k = 0 ; k < nm1 ; ++k ) + { + for ( l = k+1 ; l < n ; ++l ) + if ( _bb_exe[k] == _bb_exe[l] ) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "problem with executable names" ); + } + + // construction of _sgte_exe: + bool has_sgte_exe = _p.has_sgte_exe(); + std::string err; + if ( has_sgte_exe ) + { + for ( k = 0 ; k < n ; ++k ) + { + + _sgte_exe.push_back ( _p.get_sgte_exe(_bb_exe[k]) ); + + if ( _sgte_exe[_sgte_exe.size()-1].empty() ) + { + err = "blackbox executable \'" + _bb_exe[k] + "\' has no surrogate"; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); + } + } + } + + // process blakc-box executables (check and add problem path): + for ( k = 0 ; k < n ; ++k ) + { + process_bb_exe_name ( _bb_exe[k] ); + if ( has_sgte_exe ) + process_bb_exe_name ( _sgte_exe[k] ); + } + + // blackbox names and indexes display: #ifdef DEBUG #ifdef USE_MPI - int rank; - MPI_Comm_rank ( MPI_COMM_WORLD, &rank); - if ( rank == 0 ) { + int rank; + MPI_Comm_rank ( MPI_COMM_WORLD, &rank); + if ( rank == 0 ) + { #else - { + { #endif - const NOMAD::Display & out = _p.out(); - if ( !_bb_exe.empty() ) { - out << std::endl - << NOMAD::open_block ( "blackbox executables" ); - for ( k = 0 ; k < n ; ++k ) { - out << NOMAD::open_block ( "bb #" + NOMAD::itos(k) ) - << _bb_exe[k] << std::endl - << "number of outputs=" << _bb_nbo[k] << std::endl - << NOMAD::close_block(); - } - out.close_block(); - } - if ( !_sgte_exe.empty() ) { - out << std::endl - << NOMAD::open_block ( "surrogate executables" ); - for ( k = 0 ; k < n ; ++k ) - out << "sgte #" << static_cast<int>(k) << ": " - << _sgte_exe[k] << std::endl; - out.close_block(); - } - } + const NOMAD::Display & out = _p.out(); + if ( !_bb_exe.empty() ) + { + out << std::endl + << NOMAD::open_block ( "blackbox executables" ); + for ( k = 0 ; k < n ; ++k ) + { + out << NOMAD::open_block ( "bb #" + NOMAD::itos(k) ) + << _bb_exe[k] << std::endl + << "number of outputs=" << _bb_nbo[k] << std::endl + << NOMAD::close_block(); + } + out.close_block(); + } + if ( !_sgte_exe.empty() ) + { + out << std::endl + << NOMAD::open_block ( "surrogate executables" ); + for ( k = 0 ; k < n ; ++k ) + out << "sgte #" << static_cast<int>(k) << ": " + << _sgte_exe[k] << std::endl; + out.close_block(); + } + } #endif -} - -/*----------------------------------------------------------------*/ -/* process a blackbox executable name (private) */ -/*----------------------------------------------------------------*/ -void NOMAD::Evaluator::process_bb_exe_name ( std::string & bb_exe ) const -{ - std::string err; - std::list<std::string> bb_exe_words; - - NOMAD::get_words ( bb_exe , bb_exe_words ); - - if ( bb_exe_words.empty() ) { - err = "problem with executable \'" + bb_exe + "\'"; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); - } - - std::string problem_dir = _p.get_problem_dir(); - - // bb_exe is composed of several words (it is a command): - if ( bb_exe_words.size() > 1 ) { - - bb_exe.clear(); - - std::list<std::string>::const_iterator it = bb_exe_words.begin() , - end = bb_exe_words.end(); - while (true) { - - if ( (*it)[0] != '$' ) { - bb_exe += "\"" + problem_dir; - bb_exe += *it + "\""; - } - else - bb_exe += it->substr ( 1 , it->size()-1 ); - - ++it; - - if ( it == end ) - break; - - bb_exe += " "; - } - } - - // bb_exe is just composed of one name (it is an executable): - else { - if ( bb_exe[0] != '$' ) - bb_exe = problem_dir + bb_exe; - else - bb_exe = bb_exe.substr ( 1 , bb_exe.size()-1 ); - if ( !NOMAD::check_exe_file ( bb_exe ) ) { - err = "\'" + bb_exe + "\' is not a valid executable file"; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); } - if ( bb_exe[0] != '$' ) - bb_exe = "\"" + bb_exe + "\""; - } -} - -/*-----------------------------------------------------------------------*/ -/* check the constraints to decide if an evaluation have to be stopped */ -/*-----------------------------------------------------------------------*/ -/* . checked when h > h_max or if a 'EB' constraint is violated */ -/* . private method */ -/*-----------------------------------------------------------------------*/ -bool NOMAD::Evaluator::interrupt_evaluations ( const NOMAD::Eval_Point & x , - const NOMAD::Double & h_max ) const -{ - int nbo = _p.get_bb_nb_outputs(); - const NOMAD::Point & bbo = x.get_bb_outputs(); - const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); - NOMAD::Double h = 0.0; - bool check_h = h_max.is_defined(); - - for ( int i = 0 ; i < nbo ; ++i ) { - - if ( bbo[i].is_defined() && - ( bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) && - bbo[i] > _p.get_h_min() ) - return true; - - if ( check_h && bbo[i].is_defined() && - (bbot[i] == NOMAD::FILTER || - bbot[i] == NOMAD::PB || - bbot[i] == NOMAD::PEB_P ) ) { - - if ( bbo[i] > _p.get_h_min() ) { - switch ( _p.get_h_norm() ) { - case NOMAD::L1: - h += bbo[i]; - break; - case NOMAD::L2: - h += bbo[i].pow2(); - break; - case NOMAD::LINF: - if ( bbo[i] > h ) - h = bbo[i]; - break; + + /*----------------------------------------------------------------*/ + /* process a blackbox executable name (private) */ + /*----------------------------------------------------------------*/ + void NOMAD::Evaluator::process_bb_exe_name ( std::string & bb_exe ) const + { + std::string err; + std::list<std::string> bb_exe_words; + + NOMAD::get_words ( bb_exe , bb_exe_words ); + + if ( bb_exe_words.empty() ) + { + err = "problem with executable \'" + bb_exe + "\'"; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); + } + + std::string problem_dir = _p.get_problem_dir(); + + // bb_exe is composed of several words (it is a command): + if ( bb_exe_words.size() > 1 ) + { + + bb_exe.clear(); + + std::list<std::string>::const_iterator it = bb_exe_words.begin() , + end = bb_exe_words.end(); + while (true) + { + + if ( (*it)[0] != '$' ) + { + bb_exe += "\"" + problem_dir; + bb_exe += *it + "\""; + } + else + bb_exe += it->substr ( 1 , it->size()-1 ); + + ++it; + + if ( it == end ) + break; + + bb_exe += " "; + } + } + + // bb_exe is just composed of one name (it is an executable): + else { + if ( bb_exe[0] != '$' ) + bb_exe = problem_dir + bb_exe; + else + bb_exe = bb_exe.substr ( 1 , bb_exe.size()-1 ); + if ( !NOMAD::check_exe_file ( bb_exe ) ) + { + err = "\'" + bb_exe + "\' is not a valid executable file"; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); + } + if ( bb_exe[0] != '$' ) + bb_exe = "\"" + bb_exe + "\""; + } } - - if ( _p.get_h_norm() == NOMAD::L2 ) { - if ( h > h_max.pow2() ) - return true; + + /*-----------------------------------------------------------------------*/ + /* check the constraints to decide if an evaluation have to be stopped */ + /*-----------------------------------------------------------------------*/ + /* . checked when h > h_max or if a 'EB' constraint is violated */ + /* . private method */ + /*-----------------------------------------------------------------------*/ + bool NOMAD::Evaluator::interrupt_evaluations ( const NOMAD::Eval_Point & x , + const NOMAD::Double & h_max ) const + { + int nbo = _p.get_bb_nb_outputs(); + const NOMAD::Point & bbo = x.get_bb_outputs(); + const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); + NOMAD::Double h = 0.0; + bool check_h = h_max.is_defined(); + + for ( int i = 0 ; i < nbo ; ++i ) { + + if ( bbo[i].is_defined() && + ( bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) && + bbo[i] > _p.get_h_min() ) + return true; + + if ( check_h && bbo[i].is_defined() && + (bbot[i] == NOMAD::FILTER || + bbot[i] == NOMAD::PB || + bbot[i] == NOMAD::PEB_P ) ) { + + if ( bbo[i] > _p.get_h_min() ) { + switch ( _p.get_h_norm() ) { + case NOMAD::L1: + h += bbo[i]; + break; + case NOMAD::L2: + h += bbo[i].pow2(); + break; + case NOMAD::LINF: + if ( bbo[i] > h ) + h = bbo[i]; + break; + } + + if ( _p.get_h_norm() == NOMAD::L2 ) { + if ( h > h_max.pow2() ) + return true; + } + else if ( h > h_max ) + return true; + } + } + } + return false; } - else if ( h > h_max ) - return true; - } - } - } - return false; -} - -/*--------------------------------------------------------*/ -/* compute f(x) from the blackbox outputs of a point */ -/* (define a Multi_Obj_Evaluator to treat more than */ -/* one objective) */ -/*--------------------------------------------------------*/ -void NOMAD::Evaluator::compute_f ( NOMAD::Eval_Point & x ) const -{ - if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) { - std::ostringstream err; - err << "Evaluator::compute_f(x): x has a wrong number of blackbox outputs (" - << x.get_bb_outputs().size() << " != " - << _p.get_bb_nb_outputs() << ")"; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() ); - } - - x.set_f ( x.get_bb_outputs()[*(_p.get_index_obj().begin())] ); -} - -/*--------------------------------------------------------*/ -/* compute h(x) from the blackbox outputs of a point */ -/* set also the flag 'EB_ok' of the point */ -/*--------------------------------------------------------*/ -void NOMAD::Evaluator::compute_h ( NOMAD::Eval_Point & x ) const -{ - if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) { - std::ostringstream err; - err << "Evaluator::compute_h(x): x has a wrong number of blackbox outputs (" - << x.get_bb_outputs().size() << " != " - << _p.get_bb_nb_outputs() << ")"; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() ); - } - - int nbo = _p.get_bb_nb_outputs(); - const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); - const NOMAD::Point & bbo = x.get_bb_outputs(); - NOMAD::Double h = 0.0 , bboi; - - x.set_EB_ok ( true ); - - for ( int i = 0 ; i < nbo ; ++i ) { - - bboi = bbo[i]; - - if ( bboi.is_defined() && - (bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) && - bboi > _p.get_h_min() ) { - h.clear(); - x.set_h ( h ); - x.set_EB_ok ( false ); - return; - } - - if ( bboi.is_defined() && - ( bbot[i] == NOMAD::FILTER || - bbot[i] == NOMAD::PB || - bbot[i] == NOMAD::PEB_P ) ) { - if ( bboi > _p.get_h_min() ) { - switch ( _p.get_h_norm() ) { - case NOMAD::L1: - h += bboi; - break; - case NOMAD::L2: - h += bboi * bboi; - break; - case NOMAD::LINF: - if ( bboi > h ) - h = bboi; - break; + + /*--------------------------------------------------------*/ + /* compute f(x) from the blackbox outputs of a point */ + /* (define a Multi_Obj_Evaluator to treat more than */ + /* one objective) */ + /*--------------------------------------------------------*/ + void NOMAD::Evaluator::compute_f ( NOMAD::Eval_Point & x ) const + { + if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) { + std::ostringstream err; + err << "Evaluator::compute_f(x): x has a wrong number of blackbox outputs (" + << x.get_bb_outputs().size() << " != " + << _p.get_bb_nb_outputs() << ")"; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() ); + } + + x.set_f ( x.get_bb_outputs()[*(_p.get_index_obj().begin())] ); } - } - } - } - - if ( _p.get_h_norm() == NOMAD::L2 ) - h = h.sqrt(); - - x.set_h ( h ); -} - -/*-------------------------------------------------------------------*/ -/* . evaluate the black boxes at a given Eval_Point */ -/* . the function returns true if the evaluation did not fail */ -/* . set count_eval=true to count the evaluation */ -/* (unless the output value CNT_EVAL is defined and set to 1 */ -/* by the blackbox) */ -/*-------------------------------------------------------------------*/ -bool NOMAD::Evaluator::eval_x ( NOMAD::Eval_Point & x , - const NOMAD::Double & h_max , - bool & count_eval ) const -{ - count_eval = false; - - if ( _bb_exe.empty() || !x.is_complete() ) - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , - "Evaluator: no BB_EXE is defined (blackbox executable names)" ); - - bool sgte = x.get_eval_type() == NOMAD::SGTE; - if ( sgte && _sgte_exe.empty() ) - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , - "Evaluator: no SGTE_EXE is defined (surrogate executable names)" ); - - int pid = NOMAD::get_pid(); - int seed = _p.get_seed(); - std::string tmp_dir = _p.get_tmp_dir(); - - std::ostringstream oss; - oss << "." << seed; - if ( pid != seed ) - oss << "." << pid; - oss << "." << x.get_tag() << "."; - const std::string & sint = oss.str(); - - // for the parallel version: no need to include the process rank in the names - // as the point tags are unique for all the processes: each process creates - // its own points and uses Eval_Point::set_tag() - - // blackbox input file writing: - // ---------------------------- - std::string bb_input_file_name = - tmp_dir + NOMAD::BLACKBOX_INPUT_FILE_PREFIX - + sint + NOMAD::BLACKBOX_INPUT_FILE_EXT; - - std::string bb_output_file_name = - tmp_dir + NOMAD::BLACKBOX_OUTPUT_FILE_PREFIX - + sint + NOMAD::BLACKBOX_OUTPUT_FILE_EXT; - - std::ofstream fout ( bb_input_file_name.c_str() ); - if ( fout.fail() ) { - std::string err = "could not open file blackbox input file " + bb_input_file_name; - throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); - } - - // include seed: - if ( _p.get_bb_input_include_seed() ) - fout << seed << " "; - - // include tag: - if ( _p.get_bb_input_include_tag() ) - fout << x.get_tag() << " "; - - fout.setf ( std::ios::fixed ); - fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); - x.Point::display ( fout , " " , -1 , -1 ); - fout << std::endl; - - fout.close(); - - if ( fout.fail() ) - return false; - - x.set_eval_status ( NOMAD::EVAL_IN_PROGRESS ); - - std::string cmd , bb_exe; - std::ifstream fin; - bool failed; - NOMAD::Double d; - int j , nbbok; - int ibbo = 0; - - // system call to evaluate the blackbox: - // ------------------------------------- - size_t bn = _bb_exe.size(); - for ( size_t k = 0 ; k < bn ; ++k ) + + /*--------------------------------------------------------*/ + /* compute h(x) from the blackbox outputs of a point */ + /* set also the flag 'EB_ok' of the point */ + /*--------------------------------------------------------*/ + void NOMAD::Evaluator::compute_h ( NOMAD::Eval_Point & x ) const { + if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) + { + std::ostringstream err; + err << "Evaluator::compute_h(x): x has a wrong number of blackbox outputs (" + << x.get_bb_outputs().size() << " != " + << _p.get_bb_nb_outputs() << ")"; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() ); + } - // executable name: - bb_exe = ( sgte ) ? _sgte_exe[k] : _bb_exe[k]; + int nbo = _p.get_bb_nb_outputs(); + const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); + const NOMAD::Point & bbo = x.get_bb_outputs(); + NOMAD::Double h = 0.0 , bboi; - // system command: - cmd = bb_exe + " " + bb_input_file_name; + x.set_EB_ok ( true ); - // redirection ? if no, the blackbox has to create - // the output file 'bb_output_file_name': - if ( _p.get_bb_redirection() ) - cmd += " > " + bb_output_file_name; + for ( int i = 0 ; i < nbo ; ++i ) + { + + bboi = bbo[i]; + + if ( bboi.is_defined() && + (bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) && + bboi > _p.get_h_min() ) + { + h.clear(); + x.set_h ( h ); + x.set_EB_ok ( false ); + return; + } + + if ( bboi.is_defined() && + ( bbot[i] == NOMAD::FILTER || + bbot[i] == NOMAD::PB || + bbot[i] == NOMAD::PEB_P ) ) + { + if ( bboi > _p.get_h_min() ) + { + switch ( _p.get_h_norm() ) + { + case NOMAD::L1: + h += bboi; + break; + case NOMAD::L2: + h += bboi * bboi; + break; + case NOMAD::LINF: + if ( bboi > h ) + h = bboi; + break; + } + } + } + } + if ( _p.get_h_norm() == NOMAD::L2 ) + h = h.sqrt(); + + x.set_h ( h ); + } + + /*-------------------------------------------------------------------*/ + /* . evaluate the black boxes at a given Eval_Point */ + /* . the function returns true if the evaluation did not fail */ + /* . set count_eval=true to count the evaluation */ + /* (unless the output value CNT_EVAL is defined and set to 1 */ + /* by the blackbox) */ + /*-------------------------------------------------------------------*/ + bool NOMAD::Evaluator::eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) const + { + count_eval = false; + + if ( _bb_exe.empty() || !x.is_complete() ) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: no BB_EXE is defined (blackbox executable names)" ); + + bool sgte = x.get_eval_type() == NOMAD::SGTE; + if ( sgte && _sgte_exe.empty() ) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: no SGTE_EXE is defined (surrogate executable names)" ); + + int pid = NOMAD::get_pid(); + int seed = _p.get_seed(); + std::string tmp_dir = _p.get_tmp_dir(); + + std::ostringstream oss; + oss << "." << seed; + if ( pid != seed ) + oss << "." << pid; + oss << "." << x.get_tag() << "."; + const std::string & sint = oss.str(); + + // for the parallel version: no need to include the process rank in the names + // as the point tags are unique for all the processes: each process creates + // its own points and uses Eval_Point::set_tag() + + // blackbox input file writing: + // ---------------------------- + std::string bb_input_file_name = + tmp_dir + NOMAD::BLACKBOX_INPUT_FILE_PREFIX + + sint + NOMAD::BLACKBOX_INPUT_FILE_EXT; + + std::string bb_output_file_name = + tmp_dir + NOMAD::BLACKBOX_OUTPUT_FILE_PREFIX + + sint + NOMAD::BLACKBOX_OUTPUT_FILE_EXT; + + std::ofstream fout ( bb_input_file_name.c_str() ); + if ( fout.fail() ) + { + std::string err = "could not create file blackbox input file " + bb_input_file_name + ". \n \n #### Please check that write permission are granted for the working directory. #### "; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); + } + + // include seed: + if ( _p.get_bb_input_include_seed() ) + fout << seed << " "; + + // include tag: + if ( _p.get_bb_input_include_tag() ) + fout << x.get_tag() << " "; + + fout.setf ( std::ios::fixed ); + fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); + x.Point::display ( fout , " " , -1 , -1 ); + fout << std::endl; + + fout.close(); + + if ( fout.fail() ) + return false; + + x.set_eval_status ( NOMAD::EVAL_IN_PROGRESS ); + + std::string cmd , bb_exe; + std::ifstream fin; + bool failed; + NOMAD::Double d; + int j , nbbok; + int ibbo = 0; + + // system call to evaluate the blackbox: + // ------------------------------------- + size_t bn = _bb_exe.size(); + for ( size_t k = 0 ; k < bn ; ++k ) + { + + // executable name: + bb_exe = ( sgte ) ? _sgte_exe[k] : _bb_exe[k]; + + // system command: + cmd = bb_exe + " " + bb_input_file_name; + + // redirection ? if no, the blackbox has to create + // the output file 'bb_output_file_name': + if ( _p.get_bb_redirection() ) + cmd += " > " + bb_output_file_name; + #ifdef DEBUG #ifdef USE_MPI - int rank; - MPI_Comm_rank ( MPI_COMM_WORLD, &rank); - _p.out() << "command(rank=" << rank - << ") = \'" << cmd << "\'" << std::endl; + int rank; + MPI_Comm_rank ( MPI_COMM_WORLD, &rank); + _p.out() << "command(rank=" << rank + << ") = \'" << cmd << "\'" << std::endl; #else - _p.out() << "command=\'" << cmd << "\'" << std::endl; + _p.out() << "command=\'" << cmd << "\'" << std::endl; #endif #endif - - // the evaluation: - { - int signal = system ( cmd.c_str() ); - // catch the ctrl-c signal: - if ( signal == SIGINT ) - raise ( SIGINT ); + // the evaluation: + { + int signal = system ( cmd.c_str() ); + + // catch the ctrl-c signal: + if ( signal == SIGINT ) + raise ( SIGINT ); + + // other evaluation error: + failed = ( signal != 0 ); + count_eval = true; + } - // other evaluation error: - failed = ( signal != 0 ); - count_eval = true; + // the evaluation failed (we stop the evaluations): + if ( failed ) + { + x.set_eval_status ( NOMAD::EVAL_FAIL ); + break; + } + + // reading of the blackbox output file: + // ------------------------------------ + else + { + + // bb-output file reading: + fin.open ( bb_output_file_name.c_str() ); + + failed = false; + bool is_defined = true; + bool is_inf = false; + + // loop on the number of outputs for this blackbox: + nbbok = _bb_nbo[k]; + for ( j = 0 ; j < nbbok ; ++j ) + { + + fin >> d; + + if ( !d.is_defined() ) + { + is_defined = false; + break; + } + + if ( fin.fail() ) + { + failed = true; + break; + } + + if ( d.value() >= NOMAD::INF ) + { + is_inf = true; + break; + } + + x.set_bb_output ( ibbo++ , d ); + } + + fin.close(); + + // the evaluation failed: + if ( failed || !is_defined || is_inf ) + { + x.set_eval_status ( NOMAD::EVAL_FAIL ); + break; + } + + // stop the evaluations if h > h_max or if a 'EB' constraint is violated: + if ( k < _bb_exe.size() - 1 && interrupt_evaluations ( x , h_max ) ) + break; + } } - // the evaluation failed (we stop the evaluations): - if ( failed ) { - x.set_eval_status ( NOMAD::EVAL_FAIL ); - break; + if ( x.get_eval_status() == NOMAD::EVAL_IN_PROGRESS ) + x.set_eval_status ( NOMAD::EVAL_OK ); + + // delete the blackbox input and output files: + // ------------------------------------------- + remove ( bb_input_file_name.c_str () ); + remove ( bb_output_file_name.c_str() ); + + // check the CNT_EVAL output: + // -------------------------- + int index_cnt_eval = _p.get_index_cnt_eval(); + if ( index_cnt_eval >= 0 && x.get_bb_outputs()[index_cnt_eval] == 0.0 ) + count_eval = false; + + return x.is_eval_ok(); + + + } + + + /*-------------------------------------------------------------------*/ + /* . evaluate the black boxes at a list of given Eval_Points */ + /*-------------------------------------------------------------------*/ + bool NOMAD::Evaluator::eval_x ( std::list<NOMAD::Eval_Point *> & list_eval, + const NOMAD::Double & h_max , + std::list<bool> & list_count_eval) const + { + + std::list<NOMAD::Eval_Point *>::iterator it; + std::list<NOMAD::Eval_Point *>::iterator it_begin=list_eval.begin(); + std::list<NOMAD::Eval_Point *>::iterator it_end=list_eval.end(); + std::list<bool>::iterator it_count=list_count_eval.begin(); + + if ( list_eval.size() !=list_count_eval.size()) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: inconsistent size of list" ); + + if ( _bb_exe.empty()) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: no BB_EXE is defined (blackbox executable names)" ); + + bool sgte = ((*it_begin)->get_eval_type() == NOMAD::SGTE); + if ( sgte && _sgte_exe.empty() ) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: no SGTE_EXE is defined (surrogate executable names)" ); + + + + int pid = NOMAD::get_pid(); + int seed = _p.get_seed(); + std::string tmp_dir = _p.get_tmp_dir(); + + std::ostringstream oss; + oss << "." << seed; + if ( pid != seed ) + oss << "." << pid; + + for (it=it_begin;it!=it_end;++it) + { + if (!(*it)->is_complete() ) + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , + "Evaluator: points provided for evaluations are incomplete " ); + } + // add the tag of the first point + oss << "." << (*it_begin)->get_tag(); - // reading of the blackbox output file: - // ------------------------------------ - else { + oss << "." ; + const std::string & sint = oss.str(); + + // for the parallel version: no need to include the process rank in the names + // as the point tags are unique for all the processes: each process creates + // its own points and uses Eval_Point::set_tag() + + // blackbox input file writing: + // ---------------------------- + std::string bb_input_file_name = + tmp_dir + NOMAD::BLACKBOX_INPUT_FILE_PREFIX + + sint + NOMAD::BLACKBOX_INPUT_FILE_EXT; + + std::string bb_output_file_name = + tmp_dir + NOMAD::BLACKBOX_OUTPUT_FILE_PREFIX + + sint + NOMAD::BLACKBOX_OUTPUT_FILE_EXT; + + std::ofstream fout ( bb_input_file_name.c_str() ); + if ( fout.fail() ) { + std::string err = "could not create file blackbox input file " + bb_input_file_name + ". \n \n #### Please check that write permission are granted for the working directory. #### "; + throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err ); + } + + + for (it=it_begin;it!=it_end;++it) + { + // include seed: + if ( _p.get_bb_input_include_seed() ) + fout << seed << " "; + + // include tag: + if ( _p.get_bb_input_include_tag() ) + fout << (*it)->get_tag() << " "; - // bb-output file reading: - fin.open ( bb_output_file_name.c_str() ); + fout.setf ( std::ios::fixed ); + fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); + (*it)->Point::display ( fout , " " , -1 , -1 ); + fout << std::endl; + } + + fout.close(); + + if ( fout.fail() ) + return false; + + for (it=it_begin;it!=it_end;++it) + (*it)->set_eval_status ( NOMAD::EVAL_IN_PROGRESS ); + + + std::string cmd , bb_exe; + std::ifstream fin; + bool failed; + NOMAD::Double d; + int j , nbbok; + int ibbo = 0; + + // system call to evaluate the blackboxes: + // ------------------------------------- + size_t bn = _bb_exe.size(); + for ( size_t k = 0 ; k < bn ; ++k ) + { + + // executable name: + bb_exe = ( sgte ) ? _sgte_exe[k] : _bb_exe[k]; - failed = false; - bool is_defined = true; - bool is_inf = false; + // system command: + cmd = bb_exe + " " + bb_input_file_name; - // loop on the number of outputs for this blackbox: - nbbok = _bb_nbo[k]; - for ( j = 0 ; j < nbbok ; ++j ) { + // redirection ? if no, the blackbox has to create + // the output file 'bb_output_file_name': + if ( _p.get_bb_redirection() ) + cmd += " > " + bb_output_file_name; + + + // the evaluation: + { + int signal = system ( cmd.c_str() ); - fin >> d; + // catch the ctrl-c signal: + if ( signal == SIGINT ) + raise ( SIGINT ); - if ( !d.is_defined() ) { - is_defined = false; - break; + // other evaluation error: + failed = ( signal != 0 ); + } + + // the evaluation failed (we stop the evaluations): + if ( failed ) + { + it_count=list_count_eval.begin(); + for (it=it_begin;it!=it_end;++it,++it_count) + { + (*it)->set_eval_status ( NOMAD::EVAL_FAIL ); + (*it_count)=true; // } + break; + } + + // reading of the blackbox output file: + // ------------------------------------ + else + { - if ( fin.fail() ) { - failed = true; - break; + // bb-output file reading: + fin.open ( bb_output_file_name.c_str() ); + + string s; + bool is_defined,is_inf; + + bool list_all_failed_eval=true; + bool list_all_interrupt=true; + + // loop on the points + it_count=list_count_eval.begin(); + for (it=it_begin;it!=it_end;++it,++it_count) + { + failed = false; + is_defined = true; + is_inf = false; + + // loop on the number of outputs for this blackbox: + nbbok = _bb_nbo[k]; + ibbo=0; + for ( j = 0 ; j < nbbok ; ++j ) + { + fin >> s; + + if ( fin.fail() ) + { + failed = true; + break; + } + + toupper(s); + if (s.compare("REJECT")==0) + { + *it_count=false; // Rejected points are not counted + (*it)->set_eval_status(NOMAD::EVAL_USER_REJECT); + break; + } + else + { + d.atof(s); + (*it_count)=true; + } + // + + if (s.compare("FAIL")==0) + { + failed = true; + break; + } + + + if ( !d.is_defined() ) + { + is_defined = false; + break; + } + + + if ( d.value() >= NOMAD::INF ) { + is_inf = true; + break; + } + + (*it)->set_bb_output ( ibbo++ , d ); + } + + + // the evaluation failed: + if ( failed || !is_defined || is_inf ) + { + (*it)->set_eval_status ( NOMAD::EVAL_FAIL ); + + } else + list_all_failed_eval=false; + + + // stop the evaluations if h > h_max or if a 'EB' constraint is violated: + if ( !( k < _bb_exe.size() - 1 && interrupt_evaluations ( *(*it) , h_max ) && list_all_interrupt )) + list_all_interrupt=false; } - if ( d.value() >= NOMAD::INF ) { - is_inf = true; + fin.close(); + if (list_all_failed_eval || list_all_interrupt) break; - } - x.set_bb_output ( ibbo++ , d ); } + } + + + // delete the blackbox input and output files: + // ------------------------------------------- + remove ( bb_input_file_name.c_str () ); + remove ( bb_output_file_name.c_str() ); + + bool at_least_one_eval_ok=false; + int index_cnt_eval = _p.get_index_cnt_eval(); + + + // update eval status and check that at least one was ok + it_count=list_count_eval.begin(); + for (it=it_begin;it!=it_end;++it,++it_count) + { + if ( (*it)->get_eval_status() == NOMAD::EVAL_IN_PROGRESS ) + (*it)->set_eval_status ( NOMAD::EVAL_OK ); - fin.close(); - - // the evaluation failed: - if ( failed || !is_defined || is_inf ) { - x.set_eval_status ( NOMAD::EVAL_FAIL ); - break; - } + if (!at_least_one_eval_ok && (*it)->is_eval_ok()) + at_least_one_eval_ok=true; - // stop the evaluations if h > h_max or if a 'EB' constraint is violated: - if ( k < _bb_exe.size() - 1 && interrupt_evaluations ( x , h_max ) ) - break; + // count_eval from bb_outputs: + // -------------------------- + if ( index_cnt_eval >= 0 && (*it)->get_bb_outputs()[index_cnt_eval]==0) + *it_count=false; } + + return at_least_one_eval_ok; } - - if ( x.get_eval_status() == NOMAD::EVAL_IN_PROGRESS ) - x.set_eval_status ( NOMAD::EVAL_OK ); - - // delete the blackbox input and output files: - // ------------------------------------------- - remove ( bb_input_file_name.c_str () ); - remove ( bb_output_file_name.c_str() ); - - // check the CNT_EVAL output: - // -------------------------- - int index_cnt_eval = _p.get_index_cnt_eval(); - if ( index_cnt_eval >= 0 && x.get_bb_outputs()[index_cnt_eval] == 0.0 ) - count_eval = false; - - return x.is_eval_ok(); -} diff --git a/src/Evaluator.hpp b/src/Evaluator.hpp index f637e7bff4d8624af5e5508775115863ccf15829..80119dffdf096da907174eb945ec622878999a3e 100644 --- a/src/Evaluator.hpp +++ b/src/Evaluator.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,187 +34,250 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Evaluator.hpp - \brief Evaluation of blackbox functions (headers) - \author Sebastien Le Digabel - \date 2010-04-14 - \see Evaluator.cpp -*/ + \file Evaluator.hpp + \brief Evaluation of blackbox functions (headers) + \author Sebastien Le Digabel + \date 2010-04-14 + \see Evaluator.cpp + */ #ifndef __EVALUATOR__ #define __EVALUATOR__ #include <csignal> #include "Priority_Eval_Point.hpp" #include "Stats.hpp" +#include <list> namespace NOMAD { - - // forward declarations: - class Barrier; - class Pareto_Front; - class Evaluator_Control; - - /// Evaluation of blackbox functions. - /** + + // forward declarations: + class Barrier; + class Pareto_Front; + class Evaluator_Control; + + /// Evaluation of blackbox functions. + /** This class allows the evaluation of one trial point. - */ - class Evaluator : private NOMAD::Uncopyable { - - protected: - - /// Parameters. - const NOMAD::Parameters & _p; - - /// Multi-objective flag. - /** - Identifies if a NOMAD::Evaluator object refers to - a NOMAD::Multi_Obj_Evaluator for more than one - objective function. - */ - bool _is_multi_obj; + */ + class Evaluator : private NOMAD::Uncopyable { + + protected: + + /// Parameters. + const NOMAD::Parameters & _p; + + /// Multi-objective flag. + /** + Identifies if a NOMAD::Evaluator object refers to + a NOMAD::Multi_Obj_Evaluator for more than one + objective function. + */ + bool _is_multi_obj; - private: - - /// Blackbox executable names. - /** - - Not the same as Parameters::_bb_exe. - - NOMAD::Evaluator::_bb_exe is constructed from + /// Model flag. + /** + Identifies if a NOMAD::Evaluator object refers to + a NOMAD::***_Model_Evaluator + */ + bool _is_model_evaluator; + + private: + + /// Blackbox executable names. + /** + - Not the same as Parameters::_bb_exe. + - NOMAD::Evaluator::_bb_exe is constructed from NOMAD::Parameters::_bb_exe. - */ - std::vector<std::string> _bb_exe; - - std::vector<std::string> _sgte_exe; ///< Surrogate executable names. - - /// Number of outputs for each blackbox executable. - std::vector<int> _bb_nbo; - - static bool _force_quit; ///< Flag equal to \c true if ctrl-c is pressed. - - /// Check the constraints to decide if the evaluations have to be stopped. - /** - \param x Point at which the constraints are checked -- \b IN. - \param h_max Maximal feasibility value \c h_max -- \b IN. - \return A boolean equal to \c true if - the evaluations have to be stopped. - */ - bool interrupt_evaluations ( const NOMAD::Eval_Point & x , - const NOMAD::Double & h_max ) const; - - /// Process a blackbox executable name. - /** - \param bb_exe Executable name -- \b IN/OUT. - */ - void process_bb_exe_name ( std::string & bb_exe ) const; + */ + std::vector<std::string> _bb_exe; + + std::vector<std::string> _sgte_exe; ///< Surrogate executable names. + + /// Number of outputs for each blackbox executable. + std::vector<int> _bb_nbo; + + static bool _force_quit; ///< Flag equal to \c true if ctrl-c is pressed. + + /// Check the constraints to decide if the evaluations have to be stopped. + /** + \param x Point at which the constraints are checked -- \b IN. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \return A boolean equal to \c true if + the evaluations have to be stopped. + */ + bool interrupt_evaluations ( const NOMAD::Eval_Point & x , + const NOMAD::Double & h_max ) const; + + /// Process a blackbox executable name. + /** + \param bb_exe Executable name -- \b IN/OUT. + */ + void process_bb_exe_name ( std::string & bb_exe ) const; + + public: + + /// Constructor. + /** + \param p Parameters -- \b IN. + */ + Evaluator ( const NOMAD::Parameters & p ); + + /// Destructor. + virtual ~Evaluator ( void ) {} + + /// Force quit (called by pressing ctrl-c). + static void force_quit ( void ) + { + NOMAD::Evaluator::_force_quit = true; + } + + /// Access to the \c force_quit flag. + /** + \return The \c force_quit flag. + */ + static bool get_force_quit ( void ) + { + return NOMAD::Evaluator::_force_quit; + } + + /// Access to the multi-objective flag. + /** + \return The multi-objective flag. + */ + bool is_multi_obj ( void ) const + { + return _is_multi_obj; + } - public: - - /// Constructor. - /** - \param p Parameters -- \b IN. - */ - Evaluator ( const NOMAD::Parameters & p ); - - /// Destructor. - virtual ~Evaluator ( void ) {} - - /// Force quit (called by pressing ctrl-c). - static void force_quit ( void ) { NOMAD::Evaluator::_force_quit = true; } - - /// Access to the \c force_quit flag. - /** - \return The \c force_quit flag. - */ - static bool get_force_quit ( void ) { return NOMAD::Evaluator::_force_quit; } - - /// Access to the multi-objective flag. - /** - \return The multi-objective flag. - */ - bool is_multi_obj ( void ) const { return _is_multi_obj; } - - /// User pre-processing of a list of points. - /** - - This virtual method is called before the evaluation of a list + /// Access to the model evaluator flag. + /** + \return The model evaluator flag. + */ + virtual bool is_model_evaluator ( void ) const + { + return _is_model_evaluator; + } + + /// User pre-processing of a list of points. + /** + - This virtual method is called before the evaluation of a list of points. - - It allows the user to pre-process the points to be evaluated. - \param pts The list of points -- \b IN/OUT. - */ - virtual void list_of_points_preprocessing - ( std::set<Priority_Eval_Point> & pts ) const {} - - /// User updates after a success. - /** - This virtual method is called every time a new (full) success is made. - \param stats Stats -- \b IN. - \param x Last successful point -- \b IN. - */ - virtual void update_success ( const NOMAD::Stats & stats , - const NOMAD::Eval_Point & x ) {} - - /// User updates after an iteration. - /** - This virtual method is called every time a MADS iteration is terminated. - \param success Success of the iteration -- \b IN. - \param stats Stats -- \b IN. - \param ev_control The NOMAD::Evaluator_Control object -- \b IN. - \param true_barrier Barrier for true evaluations -- \b IN. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN. - \param pareto_front Pareto front -- \b IN. - \param stop Allows the user to stop the algorithm -- \b OUT. - */ - virtual void update_iteration ( NOMAD::success_type success , - const NOMAD::Stats & stats , - const NOMAD::Evaluator_Control & ev_control , - const NOMAD::Barrier & true_barrier , - const NOMAD::Barrier & sgte_barrier , - const NOMAD::Pareto_Front & pareto_front , - bool & stop ) {} - - /// Evaluate the blackbox functions at a given trial point (#1). - /** - - Const version. - - May be user-defined. - - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). - \param x The trial point -- \b IN/OUT. - \param h_max Maximal feasibility value \c h_max -- \b IN. - \param count_eval Flag indicating if the evaluation has to be counted - or not -- \b OUT. - \return A boolean equal to \c false if the evaluation failed. - */ - virtual bool eval_x ( NOMAD::Eval_Point & x , - const NOMAD::Double & h_max , - bool & count_eval ) const; - - /// Evaluate the blackbox functions at a given trial point (#2). - /** - - Non-const version. - - Calls the const version by default. - - May be user-defined. - - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). - \param x The trial point -- \b IN/OUT. - \param h_max Maximal feasibility value \c h_max -- \b IN. - \param count_eval Flag indicating if the evaluation has to be counted - or not -- \b OUT. - \return A boolean equal to \c false if the evaluation failed. - */ - virtual bool eval_x ( NOMAD::Eval_Point & x , - const NOMAD::Double & h_max , - bool & count_eval ) { - return static_cast<const Evaluator *>(this)->eval_x ( x , h_max , count_eval ); - } + - It allows the user to pre-process the points to be evaluated. + \param pts The list of points -- \b IN/OUT. + */ + virtual void list_of_points_preprocessing + ( std::set<Priority_Eval_Point> & pts ) const {} + + /// User updates after a success. + /** + This virtual method is called every time a new (full) success is made. + \param stats Stats -- \b IN. + \param x Last successful point -- \b IN. + */ + virtual void update_success ( const NOMAD::Stats & stats , + const NOMAD::Eval_Point & x ) {} + + /// User updates after an iteration. + /** + This virtual method is called every time a MADS iteration is terminated. + \param success Success of the iteration -- \b IN. + \param stats Stats -- \b IN. + \param ev_control The NOMAD::Evaluator_Control object -- \b IN. + \param true_barrier Barrier for true evaluations -- \b IN. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN. + \param pareto_front Pareto front -- \b IN. + \param stop Allows the user to stop the algorithm -- \b OUT. + */ + virtual void update_iteration ( NOMAD::success_type success , + const NOMAD::Stats & stats , + const NOMAD::Evaluator_Control & ev_control , + const NOMAD::Barrier & true_barrier , + const NOMAD::Barrier & sgte_barrier , + const NOMAD::Pareto_Front & pareto_front , + bool & stop ) {} + + /// Evaluate the blackbox functions at a given trial point (#1). + /** + - Const version. + - May be user-defined. + - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). + \param x The trial point -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) const; + + /// Evaluate the blackbox functions at a given trial point (#2). + /** + - Non-const version. + - Calls the const version by default. + - May be user-defined. + - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). + \param x The trial point -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) + { + return static_cast<const Evaluator *>(this)->eval_x ( x , h_max , count_eval ); + } + + + + /// Evaluate the blackbox functions at a given list of trial points (#1). + /** + - Const version. + - May be user-defined. + - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). + \param x The list of trial points -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Number of evaluations that are counted -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( std::list<NOMAD::Eval_Point *> &x , + const NOMAD::Double & h_max, + std::list<bool> & count_eval ) const; + + + /// Evaluate the blackbox functions at a given list of trial points (#2). + /** + - Non-Const version. + - May be user-defined. + - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). + \param x The list of trial points -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Number of evaluations that are counted -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( std::list<NOMAD::Eval_Point *> &x , + const NOMAD::Double & h_max, + std::list<bool> & count_eval ) + { + return static_cast<const Evaluator *>(this)->eval_x ( x , h_max , count_eval ); + } - /// Compute the objective value \c f(x) from the blackbox outputs of a point. - /** - \param x The point -- \b IN/OUT. - */ - virtual void compute_f ( NOMAD::Eval_Point & x ) const; - - /// Compute the feasibility value \c h(x) from the blackbox outputs of a point. - /** - \param x The point -- \b IN/OUT. - */ - void compute_h ( NOMAD::Eval_Point & x ) const; - }; + + + /// Compute the objective value \c f(x) from the blackbox outputs of a point. + /** + \param x The point -- \b IN/OUT. + */ + virtual void compute_f ( NOMAD::Eval_Point & x ) const; + + /// Compute the feasibility value \c h(x) from the blackbox outputs of a point. + /** + \param x The point -- \b IN/OUT. + */ + void compute_h ( NOMAD::Eval_Point & x ) const; + }; } #endif diff --git a/src/Evaluator_Control.cpp b/src/Evaluator_Control.cpp index 56f33022c2a9f26dce737a3bbd09403fff63b8de..77b5c10cdb0a56e7c04500d473ca288a0813e75a 100644 --- a/src/Evaluator_Control.cpp +++ b/src/Evaluator_Control.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -48,6 +48,7 @@ /* static members initialization */ /*-----------------------------------*/ bool NOMAD::Evaluator_Control::_force_quit = false; +bool NOMAD::Evaluator_Control::_force_evaluation_failure = false; /*---------------------------------------------------------*/ @@ -255,16 +256,18 @@ void NOMAD::Evaluator_Control::process_eval_point // insertion of the Eval_Point in the barriers: barrier.insert(x); - if ( x.get_eval_type() == NOMAD::TRUTH || _p.get_opt_only_sgte() ) { + if ( x.get_eval_type() == NOMAD::TRUTH || _p.get_opt_only_sgte() ) + { // multi-objective: - if ( pareto_front ) { + if ( pareto_front ) + { // insertion of the Eval_Point in the Pareto front: if ( x.is_feasible ( _p.get_h_min() ) && - pareto_front->insert ( x ) && - _p.get_user_calls_enabled() ) - _ev->update_success ( _stats , x ); + pareto_front->insert ( x ) && + _p.get_user_calls_enabled() ) + _ev->update_success ( _stats , x ); } @@ -286,55 +289,47 @@ NOMAD::success_type NOMAD::Evaluator_Control::process_barrier_points NOMAD::dd_type display_degree , NOMAD::search_type search ) const { - b1.reset_success(); - - NOMAD::Eval_Point * modifiable_x; - NOMAD::success_type one_eval_succ; - bool opt_only_sgte = _p.get_opt_only_sgte(); - const std::string & his_file = _p.get_history_file(); - const NOMAD::Eval_Point * last_success = NULL; - const std::list<const NOMAD::Eval_Point *> - & all_inserted = b2.get_all_inserted(); - std::list<const NOMAD::Eval_Point *>::const_iterator - it , end = all_inserted.end(); - for ( it = all_inserted.begin() ; it != end ; ++it ) { - - // insertion in barrier: - modifiable_x = &NOMAD::Cache::get_modifiable_point ( **it ); - - modifiable_x->set_direction ( NULL ); - modifiable_x->set_mesh_index ( NULL ); - modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); - modifiable_x->set_user_eval_priority ( NOMAD::Double() ); - modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); - - // process evaluation point: - process_eval_point ( **it , b1 , pareto_front ); - - one_eval_succ = b1.get_one_eval_succ(); - if ( one_eval_succ != NOMAD::UNSUCCESSFUL && one_eval_succ >= b1.get_success() ) - last_success = *it; - - // update the history file: - if ( !his_file.empty() && ( opt_only_sgte || - (*it)->get_eval_type() == NOMAD::TRUTH ) ) - write_sol_or_his_file ( _p.get_problem_dir() + his_file , **it , false ); - } - - NOMAD::success_type success = b1.get_success(); - - // display and save only the last success: - if ( last_success ) - display_eval_result ( *last_success , - display_degree , - search , - success , - success ); - - // barrier update: - b1.update_and_reset_success(); + b1.reset_success(); + + NOMAD::Eval_Point * modifiable_x; + NOMAD::success_type one_eval_succ; + const NOMAD::Eval_Point * last_success = NULL; + const std::list<const NOMAD::Eval_Point *> & all_inserted = b2.get_all_inserted(); + std::list<const NOMAD::Eval_Point *>::const_iterator it , end = all_inserted.end(); + for ( it = all_inserted.begin() ; it != end ; ++it ) + { + + // insertion in barrier: + modifiable_x = &NOMAD::Cache::get_modifiable_point ( **it ); + + modifiable_x->set_direction ( NULL ); + modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); + modifiable_x->set_user_eval_priority ( NOMAD::Double() ); + modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); + + // process evaluation point: + process_eval_point ( **it , b1 , pareto_front ); + + one_eval_succ = b1.get_one_eval_succ(); + if ( one_eval_succ != NOMAD::UNSUCCESSFUL && one_eval_succ >= b1.get_success() ) + last_success = *it; - return success; + } + + NOMAD::success_type success = b1.get_success(); + + // display and save only the last success: + if ( last_success && display_degree == NOMAD::FULL_DISPLAY) + display_eval_result ( *last_success , + display_degree , + search , + success , + success ); + + // barrier update: + b1.update_and_reset_success(); + + return success; } /*---------------------------------------------------------*/ @@ -367,12 +362,14 @@ void NOMAD::Evaluator_Control::stats_file ( const std::string & file_name std::string fn = _p.get_problem_dir() + file_name; std::ofstream fout ( fn.c_str() , std::ios::app ); - if ( !fout.fail() ) { + if ( !fout.fail() ) + { fout.setf ( std::ios::fixed ); fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); display_stats ( false , fout , _p.get_stats_file() , x , feasible , multi_obj ); } - else { + else + { const NOMAD::Display & out = _p.out(); if ( out.get_gen_dd() != NOMAD::NO_DISPLAY && out.get_gen_dd() != NOMAD::MINIMAL_DISPLAY) out << std::endl @@ -394,207 +391,236 @@ void NOMAD::Evaluator_Control::display_stats bool feasible , const NOMAD::Point * multi_obj ) const { - if ( stats.empty() ) { + if ( stats.empty() ) + { #ifndef R_VERSION - out << std::endl; + out << std::endl; #endif - return; - } - - if ( header ) { + return; + } + + if ( header ) + { #ifndef R_VERSION - out << std::endl; + out << std::endl; #endif - } - - NOMAD::Double f; - const NOMAD::Point * sol = NULL; - const NOMAD::Point * bbo = NULL; - const NOMAD::Signature * signature = NULL; - int bbe = _stats.get_bb_eval(); - int real_time = _stats.get_real_time(); - int i; - - // this integer is used for the default width display - // of the various stats on the number of evaluations: - int max_bbe = _p.get_max_bb_eval(); - if ( _p.get_max_sgte_eval() > max_bbe ) - max_bbe = _p.get_max_sgte_eval(); - if ( _p.get_max_sim_bb_eval() > max_bbe ) - max_bbe = _p.get_max_sim_bb_eval(); - if ( _p.get_max_eval() > max_bbe ) - max_bbe = _p.get_max_eval(); - - if ( x ) - { - signature = x->get_signature(); - f = (feasible) ? x->get_f() : NOMAD::INF; - sol = x; - bbo = &(x->get_bb_outputs()); - _last_stats_tag = x->get_tag(); - _last_stats_bbe = bbe; - } + } + + NOMAD::Double f; + const NOMAD::Point * sol = NULL; + const NOMAD::Point * bbo = NULL; + const NOMAD::Signature * signature = NULL; + int bbe = _stats.get_bb_eval(); + int real_time = _stats.get_real_time(); + int blk_bbe = _stats.get_block_eval(); + int i; + + // this integer is used for the default width display + // of the various stats on the number of evaluations: + int max_bbe = _p.get_max_bb_eval(); + if ( _p.get_max_sgte_eval() > max_bbe ) + max_bbe = _p.get_max_sgte_eval(); + if ( _p.get_max_sim_bb_eval() > max_bbe ) + max_bbe = _p.get_max_sim_bb_eval(); + if ( _p.get_max_eval() > max_bbe ) + max_bbe = _p.get_max_eval(); + + if ( x ) + { + signature = x->get_signature(); + f = (feasible) ? x->get_f() : NOMAD::INF; + sol = x; + bbo = &(x->get_bb_outputs()); + + if (bbe < _last_stats_bbe && ! multi_obj) + return; - std::string s1 , format; - std::list<std::string>::const_iterator it , end = stats.end(); - for ( it = stats.begin() ; it != end ; ++it ) { + _last_stats_tag = x->get_tag(); + _last_stats_bbe = bbe; + } + - if ( it->empty() ) { + + std::string s1 , format; + std::list<std::string>::const_iterator it , end = stats.end(); + for ( it = stats.begin() ; it != end ; ++it ) + { + + if ( it->empty() ) + { #ifndef R_VERSION - out << "\t"; + out << "\t"; #endif - } - else { - - if ( header ) { + } + else { + + if ( header ) + { #ifndef R_VERSION - s1 = *it; - NOMAD::Display::extract_display_format ( s1 , format ); - out << s1; + s1 = *it; + NOMAD::Display::extract_display_format ( s1 , format ); + out << s1; #endif - } - - else { - - // get the stats type: - NOMAD::display_stats_type dst - = NOMAD::Display::get_display_stats_type ( *it ); - - // some stats types are disables in the multi-objective case: - if ( multi_obj && - ( dst == NOMAD::DS_SIM_BBE || - dst == NOMAD::DS_BBE || - dst == NOMAD::DS_SGTE || - dst == NOMAD::DS_EVAL || - dst == NOMAD::DS_TIME || - dst == NOMAD::DS_STAT_SUM || - dst == NOMAD::DS_STAT_AVG ) ) - dst = NOMAD::DS_UNDEFINED; - - // display the stats: - switch ( dst ) { - case NOMAD::DS_UNDEFINED: - s1 = *it; - NOMAD::Display::extract_display_format ( s1 , format ); - out << s1; - break; - case NOMAD::DS_OBJ: - if ( multi_obj ) - display_stats_point ( out , stats , it , multi_obj ); - else { + } + + else + { + + // get the stats type: + NOMAD::display_stats_type dst + = NOMAD::Display::get_display_stats_type ( *it ); + + // some stats types are disables in the multi-objective case: + if ( multi_obj && + ( dst == NOMAD::DS_SIM_BBE || + dst == NOMAD::DS_BBE || + dst == NOMAD::DS_SGTE || + dst == NOMAD::DS_EVAL || + dst == NOMAD::DS_TIME || + dst == NOMAD::DS_STAT_SUM || + dst == NOMAD::DS_STAT_AVG ) ) + dst = NOMAD::DS_UNDEFINED; + + // display the stats: + switch ( dst ) + { + case NOMAD::DS_UNDEFINED: + s1 = *it; + NOMAD::Display::extract_display_format ( s1 , format ); + out << s1; + break; + case NOMAD::DS_OBJ: + if ( multi_obj ) + display_stats_point ( out , stats , it , multi_obj ); + else + { #ifdef R_VERSION - { - std::ostringstream oss; - display_stats_real ( oss , f , format ); - Rprintf ( "%s" , oss.str().c_str() ); - } + { + std::ostringstream oss; + display_stats_real ( oss , f , format ); + Rprintf ( "%s" , oss.str().c_str() ); + } #else - display_stats_real ( out , f , format ); + display_stats_real ( out , f , format ); #endif - format.clear(); - } - break; - case NOMAD::DS_MESH_INDEX: - display_stats_int ( out , - NOMAD::Mesh::get_mesh_index() , - 10*L_LIMITS , - format ); - format.clear(); - break; - case NOMAD::DS_DELTA_M: - case NOMAD::DS_MESH_SIZE: - { - if ( signature ) { - NOMAD::Point delta_m; - signature->get_mesh().get_delta_m ( delta_m , - NOMAD::Mesh::get_mesh_index() ); - display_stats_point ( out , stats , it , &delta_m ); - } - else - out << "-"; - } - break; - case NOMAD::DS_DELTA_P: - case NOMAD::DS_POLL_SIZE: - { - if ( signature ) { - NOMAD::Point delta_p; - signature->get_mesh().get_delta_p ( delta_p , - NOMAD::Mesh::get_mesh_index() ); - display_stats_point ( out , stats , it , &delta_p ); - } - else - out << "-"; - } - break; - case NOMAD::DS_SIM_BBE: - display_stats_int ( out , _stats.get_sim_bb_eval() , max_bbe , format ); - format.clear(); - break; - case NOMAD::DS_BBE: - + format.clear(); + } + break; + case NOMAD::DS_MESH_INDEX: + { + if ( signature ) + { + NOMAD::Point mesh_indices=signature->get_mesh()->get_mesh_indices(); + display_stats_point ( out , stats , it , &mesh_indices ); + } + else + out << "-"; + + + break; + } + case NOMAD::DS_DELTA_M: + case NOMAD::DS_MESH_SIZE: + { + if ( signature ) + { + NOMAD::Point delta; + signature->get_mesh()->get_delta ( delta ); + display_stats_point ( out , stats , it , &delta ); + } + else + out << "-"; + } + break; + case NOMAD::DS_DELTA_P: + case NOMAD::DS_POLL_SIZE: + { + if ( signature ) + { + NOMAD::Point Delta; + signature->get_mesh()->get_Delta ( Delta ); + display_stats_point ( out , stats , it , &Delta ); + + } + else + out << "-"; + } + break; + case NOMAD::DS_SIM_BBE: + display_stats_int ( out , _stats.get_sim_bb_eval() , max_bbe , format ); + format.clear(); + break; + case NOMAD::DS_BBE: + #ifdef R_VERSION - { - std::ostringstream oss; - display_stats_int ( oss , bbe , max_bbe , format ); - Rprintf ( "\t%s " , oss.str().c_str() ); - } + { + std::ostringstream oss; + display_stats_int ( oss , bbe , max_bbe , format ); + Rprintf ( "\t%s " , oss.str().c_str() ); + } #else - { - - display_stats_int ( out , bbe , max_bbe , format ); - } + { + display_stats_int ( out , bbe , max_bbe , format ); + } #endif - format.clear(); - break; - case NOMAD::DS_SGTE: - display_stats_int ( out , _stats.get_sgte_eval() , max_bbe , format ); - format.clear(); - break; - case NOMAD::DS_EVAL: - display_stats_int ( out , _stats.get_eval() , max_bbe , format ); - format.clear(); - break; - case NOMAD::DS_TIME: - display_stats_int ( out , real_time , 3600 , format ); - format.clear(); - break; - case NOMAD::DS_STAT_SUM: - display_stats_real ( out , _stats.get_stat_sum() , format ); - format.clear(); - break; - case NOMAD::DS_STAT_AVG: - display_stats_real ( out , _stats.get_stat_avg() , format ); - format.clear(); - break; - case NOMAD::DS_BBO: - display_stats_point ( out , stats , it , bbo ); - break; - case NOMAD::DS_SOL: - display_stats_point ( out , stats , it , sol , signature->get_input_type() ); - break; - case NOMAD::DS_VAR: - ++it; - NOMAD::atoi ( *it , i ); - if ( sol ) - if (format.empty()) - display_stats_type ( out , (*sol)[i] , (signature->get_input_type())[i] ); - else - display_stats_real ( out , (*sol)[i] , format ); - else - out << "-"; - format.clear(); - break; + format.clear(); + break; + case NOMAD::DS_BLK_EVA: + { + display_stats_int ( out , blk_bbe , max_bbe , format ); + } + format.clear(); + break; + + case NOMAD::DS_SGTE: + //display_stats_int ( out , sgte_bbe , max_bbe , format ); + display_stats_int ( out , _stats.get_sgte_eval() , max_bbe , format ); + format.clear(); + break; + case NOMAD::DS_EVAL: + display_stats_int ( out , _stats.get_eval() , max_bbe , format ); + format.clear(); + break; + case NOMAD::DS_TIME: + display_stats_int ( out , real_time , 3600 , format ); + format.clear(); + break; + case NOMAD::DS_STAT_SUM: + display_stats_real ( out , _stats.get_stat_sum() , format ); + format.clear(); + break; + case NOMAD::DS_STAT_AVG: + display_stats_real ( out , _stats.get_stat_avg() , format ); + format.clear(); + break; + case NOMAD::DS_BBO: + display_stats_point ( out , stats , it , bbo ); + break; + case NOMAD::DS_SOL: + display_stats_point ( out , stats , it , sol , signature->get_input_type() ); + break; + case NOMAD::DS_VAR: + ++it; + NOMAD::atoi ( *it , i ); + if ( sol ) + if (format.empty()) + display_stats_type ( out , (*sol)[i] , (signature->get_input_type())[i] ); + else + display_stats_real ( out , (*sol)[i] , format ); + else + out << "-"; + format.clear(); + break; + } + } + } } - } - } - } - - if ( !header ) + + if ( !header ) #ifdef R_VERSION - Rprintf("\n"); + Rprintf("\n"); #else - out << std::endl; + out << std::endl; #endif } @@ -713,11 +739,11 @@ void NOMAD::Evaluator_Control::display_stats_point if ( !s1.empty() ) out << s1; - if ( !s2.empty() && i < n-1 && s2.find("(VNS)")==std::string::npos && s2.find("(PhaseOne)")==std::string::npos && s2.find("(LH)")==std::string::npos && s2.find("(ExtendedPoll)")==std::string::npos ) + if ( !s2.empty() && i < n-1 && s2.find("(VNS)")==std::string::npos && s2.find("(PhaseOne)")==std::string::npos && s2.find("(LH)")==std::string::npos && s2.find("(ExtendedPoll)")==std::string::npos ) out << " " << s2; out << " "; } - if ( !s2.empty() && (s2.find("(VNS)")!=std::string::npos || s2.find("(PhaseOne)")!=std::string::npos || s2.find("(LH)")!=std::string::npos || s2.find("(ExtendedPoll)")!=std::string::npos)) + if ( !s2.empty() && (s2.find("(VNS)")!=std::string::npos || s2.find("(PhaseOne)")!=std::string::npos || s2.find("(LH)")!=std::string::npos || s2.find("(ExtendedPoll)")!=std::string::npos)) out << s2; } } @@ -798,15 +824,16 @@ void NOMAD::Evaluator_Control::write_sol_or_his_file << file_name << "\'" << std::endl << std::endl; } + /*---------------------------------------------------------*/ /* display evaluation result (private) */ /*---------------------------------------------------------*/ void NOMAD::Evaluator_Control::display_eval_result ( const NOMAD::Eval_Point & x , - NOMAD::dd_type display_degree , - NOMAD::search_type search , - NOMAD::success_type one_eval_success , - NOMAD::success_type success ) const + NOMAD::dd_type display_degree , + NOMAD::search_type search , + NOMAD::success_type one_eval_success , + NOMAD::success_type success ) const { const NOMAD::Display & out = _p.out(); int cur_bbe; @@ -833,10 +860,10 @@ void NOMAD::Evaluator_Control::display_eval_result if ( !_p.get_opt_only_sgte() ) return; - cur_bbe = _sgte_cache->size(); + cur_bbe = _stats.get_sgte_eval(); } else - cur_bbe = _cache->size(); + cur_bbe = _stats.get_eval(); const std::string & stats_file_name = _p.get_stats_file_name(); bool feas_x = x.is_feasible ( _p.get_h_min() ); @@ -844,7 +871,7 @@ void NOMAD::Evaluator_Control::display_eval_result // update the history file: // (contains surrogate evaluations if opt_only_sgte==true) const std::string & his_file = _p.get_history_file(); - if ( !his_file.empty() && cur_bbe > _last_history_bbe ) + if ( !his_file.empty() && cur_bbe > _last_history_bbe) { write_sol_or_his_file ( _p.get_problem_dir() + his_file , x , false ); _last_history_bbe = cur_bbe; @@ -858,12 +885,12 @@ void NOMAD::Evaluator_Control::display_eval_result // save the current solution in file: write_solution_file ( x ); - bool ds_ok = ( cur_bbe > _last_stats_bbe ) && - ( _p.get_display_all_eval() || - ( one_eval_success == NOMAD::FULL_SUCCESS && feas_x ) ); + bool ds_ok = ( cur_bbe > _last_stats_bbe) && + ( _p.get_display_all_eval() || + ( one_eval_success == NOMAD::FULL_SUCCESS && feas_x ) ); // normal display and minimal: - if ( (display_degree == NOMAD::NORMAL_DISPLAY || display_degree == NOMAD::MINIMAL_DISPLAY )&& ds_ok ) + if ( (display_degree == NOMAD::NORMAL_DISPLAY || display_degree == NOMAD::MINIMAL_DISPLAY ) && ds_ok ) display_stats ( false , out , _p.get_display_stats() , &x , feas_x , NULL ); // detailed display: else if ( display_degree == NOMAD::FULL_DISPLAY ) @@ -885,11 +912,13 @@ void NOMAD::Evaluator_Control::display_eval_result if ( x.is_eval_ok() ) out << " [ h=" << x.get_h() << " f=" << x.get_f() << " ]" << std::endl; + else if (x.check_rejected()) + out << ": evaluation rejected by user (this may alter convergence properties!)" << std::endl; else - out << ": evaluation failed" << std::endl; + out << ": evaluation failed (you may need to check the source of the problem)." << std::endl; } - if ( _p.get_display_all_eval() && cur_bbe > _last_stats_bbe ) + if ( _p.get_display_all_eval() && cur_bbe > _last_stats_bbe ) { if ( display_degree == NOMAD::NORMAL_DISPLAY || display_degree == NOMAD::MINIMAL_DISPLAY ) @@ -901,6 +930,7 @@ void NOMAD::Evaluator_Control::display_eval_result } } + /*-------------------------------------------*/ /* search a point in the cache */ /*-------------------------------------------*/ @@ -916,98 +946,100 @@ bool NOMAD::Evaluator_Control::cache_check const NOMAD::Double & h_max , NOMAD::dd_type display_degree ) const { - NOMAD::eval_type x_eval_type = x->get_eval_type(); - const NOMAD::Eval_Point * cache_x = NULL; - - // first cache check: - if ( x->is_in_cache() ) - cache_x = x; - - // second cache check: - else - cache_x = ( ( x->get_eval_type() == NOMAD::TRUTH ) ? - _cache : _sgte_cache )->find ( *x ); - - // cache hit: transfer some data from x to cache_x: - if ( cache_x ) { - - if ( x_eval_type != cache_x->get_eval_type() ) - throw NOMAD::Exception ( "Evaluator_Control.cpp" , __LINE__ , - "Evaluator_Control::cache_check(): eval and cache pts have different eval_type" ); - - if ( cache_x->is_eval_ok() ) { - - NOMAD::Eval_Point * modifiable_cache_x - = &NOMAD::Cache::get_modifiable_point ( *cache_x ); - - // if wrong number of outputs, reset cache_x._bb_outputs: - { - int m = _p.get_bb_nb_outputs(); - if ( cache_x->get_bb_outputs().size() != m ) - modifiable_cache_x->set_bb_output ( NOMAD::Point ( m ) ); - } - - modifiable_cache_x->set_signature ( x->get_signature () ); - modifiable_cache_x->set_direction ( x->get_direction () ); - modifiable_cache_x->set_mesh_index ( x->get_mesh_index () ); - // The point in cache is updated for the poll center to correspond to the new poll center of x (important for poll reduction) - modifiable_cache_x->set_poll_center ( x->get_poll_center () ); - modifiable_cache_x->set_poll_center_type ( x->get_poll_center_type () ); - modifiable_cache_x->set_user_eval_priority ( x->get_user_eval_priority() ); - modifiable_cache_x->set_rand_eval_priority ( x->get_rand_eval_priority() ); - + NOMAD::eval_type x_eval_type = x->get_eval_type(); + const NOMAD::Eval_Point * cache_x = NULL; + + // first cache check: + if ( x->is_in_cache() ) + cache_x = x; + // second cache check: + else + cache_x = ( ( x->get_eval_type() == NOMAD::TRUTH ) ? + _cache : _sgte_cache )->find ( *x ); + + // cache hit: transfer some data from x to cache_x: + if ( cache_x ) + { + + if ( x_eval_type != cache_x->get_eval_type() ) + throw NOMAD::Exception ( "Evaluator_Control.cpp" , __LINE__ , + "Evaluator_Control::cache_check(): eval and cache pts have different eval_type" ); + + if ( cache_x->is_eval_ok() ) + { + + NOMAD::Eval_Point * modifiable_cache_x + = &NOMAD::Cache::get_modifiable_point ( *cache_x ); + + // if wrong number of outputs, reset cache_x._bb_outputs: + { + int m = _p.get_bb_nb_outputs(); + if ( cache_x->get_bb_outputs().size() != m ) + modifiable_cache_x->set_bb_output ( NOMAD::Point ( m ) ); + } + + modifiable_cache_x->set_signature ( x->get_signature () ); + modifiable_cache_x->set_direction ( x->get_direction () ); + modifiable_cache_x->set_poll_center ( x->get_poll_center () ); + modifiable_cache_x->set_poll_center_type ( x->get_poll_center_type () ); + modifiable_cache_x->set_user_eval_priority ( x->get_user_eval_priority() ); + modifiable_cache_x->set_rand_eval_priority ( x->get_rand_eval_priority() ); + #ifdef MODEL_STATS - modifiable_cache_x->set_model_data ( *x ); + modifiable_cache_x->set_model_data ( *x ); #endif - - // set_f, set_h, and set_EB_ok: - _ev->compute_f ( *modifiable_cache_x ); - _ev->compute_h ( *modifiable_cache_x ); + + // set_f, set_h, and set_EB_ok: + _ev->compute_f ( *modifiable_cache_x ); + _ev->compute_h ( *modifiable_cache_x ); + } } - } - - // point in cache but evaluation is to be made again: - if ( cache_x && cache_x->is_eval_ok() && - ( !cache_x->get_f().is_defined() || - ( cache_x->is_EB_ok() && - !cache_x->get_bb_outputs().is_complete() && - cache_x->get_h().is_defined() && - cache_x->get_h() < h_max ) ) ) { - x = cache_x; - cache_x = NULL; - } - - // point in cache: - if ( cache_x ) { - - _stats.add_cache_hit(); - - // displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - const NOMAD::Display & out = _p.out(); - if ( cache_x->get_eval_type() == NOMAD::SGTE ) - out << "surrogate "; - out << "cache hit: #" << x->get_tag() - << " --> #" << cache_x->get_tag() << std::endl; + + // point in cache but evaluation is to be made again: + if ( cache_x && cache_x->is_eval_ok() && + ( !cache_x->get_f().is_defined() || + ( cache_x->is_EB_ok() && + !cache_x->get_bb_outputs().is_complete() && + cache_x->get_h().is_defined() && + cache_x->get_h() < h_max ) ) ) + { + x = cache_x; + cache_x = NULL; + } + + // point in cache: + if ( cache_x ) + { + + _stats.add_cache_hit(); + + // displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + const NOMAD::Display & out = _p.out(); + if ( cache_x->get_eval_type() == NOMAD::SGTE ) + out << "surrogate "; + out << "cache hit: #" << x->get_tag() + << " --> #" << cache_x->get_tag() << std::endl; + } + + // process the Eval_Point taken in cache: + process_eval_point ( *cache_x , + ( cache_x->get_eval_type() == NOMAD::TRUTH ) ? + true_barrier : sgte_barrier , + pareto_front ); + + // count the (simulated) bb eval ? + int index_cnt_eval = _p.get_index_cnt_eval(); + if ( index_cnt_eval >= 0 && cache_x->get_bb_outputs()[index_cnt_eval] == 0.0 ) + count_eval = false; + + x = cache_x; + + return true; } - - // process the Eval_Point taken in cache: - process_eval_point ( *cache_x , - ( cache_x->get_eval_type() == NOMAD::TRUTH ) ? - true_barrier : sgte_barrier , - pareto_front ); - - // count the (simulated) bb eval ? - int index_cnt_eval = _p.get_index_cnt_eval(); - if ( index_cnt_eval >= 0 && cache_x->get_bb_outputs()[index_cnt_eval] == 0.0 ) - count_eval = false; - - x = cache_x; - - return true; - } - - return false; + + return false; } /*----------------------------------------------------*/ @@ -1041,6 +1073,8 @@ void NOMAD::Evaluator_Control::eval_point ( NOMAD::Eval_Point & x // evaluation of the point: // ------------------------ bool eval_ok = true; + + NOMAD::Evaluator_Control::_force_evaluation_failure=false; { // 1. scaling: @@ -1049,23 +1083,31 @@ void NOMAD::Evaluator_Control::eval_point ( NOMAD::Eval_Point & x eval_x->scale(); // 2.1. evaluation: - try { + try + { eval_ok = _ev->eval_x ( *eval_x , h_max , count_eval ); + } - catch ( ... ) { - eval_ok = false; - } + catch ( exception & e ) + { + throw NOMAD::Exception ( "Evaluator_control.cpp" , __LINE__ , e.what() ); + } + // 2.2. check the nan's: if ( eval_ok && eval_x->check_nan() ) eval_ok = false; + + if ( _force_evaluation_failure ) + eval_ok = false; // 3. unscaling: if ( do_scaling ) eval_x->unscale(); } - if ( eval_ok ) { + if ( eval_ok ) + { eval_x->set_eval_status ( NOMAD::EVAL_OK ); @@ -1074,7 +1116,8 @@ void NOMAD::Evaluator_Control::eval_point ( NOMAD::Eval_Point & x _ev->compute_h ( *eval_x ); } - else { + else + { eval_x->set_eval_status ( NOMAD::EVAL_FAIL ); _stats.add_failed_eval(); } @@ -1100,57 +1143,142 @@ void NOMAD::Evaluator_Control::eval_point ( NOMAD::Eval_Point & x x.set_in_cache ( false ); } - // process the evaluated point: - if ( eval_ok && x.is_in_cache() ) - process_eval_point ( *eval_x , - ( eval_x->get_eval_type() == NOMAD::TRUTH ) ? - true_barrier : sgte_barrier , - pareto_front ); + } + +} + + +/*----------------------------------------------------*/ +/* eval points in a list (private) */ +/*----------------------------------------------------*/ +void NOMAD::Evaluator_Control::eval_points ( std::list<NOMAD::Eval_Point *> & list_eval , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + std::list<bool> & count_list_eval, + bool & stop , + NOMAD::stop_type & stop_reason , + const NOMAD::Double & h_max ) +{ + int max_bb_eval = _p.get_max_bb_eval(); + int max_sgte_eval = _p.get_max_sgte_eval(); + + std::list<NOMAD::Eval_Point*>::iterator it_begin=list_eval.begin(); + + if ( ( (*it_begin)->get_eval_type() == NOMAD::TRUTH && max_bb_eval != 0 ) || + ( (*it_begin)->get_eval_type() == NOMAD::SGTE && max_sgte_eval != 0 ) ) + { + + // 1. Pre-evaluation tests and scaling + for ( std::list<NOMAD::Eval_Point*>::iterator it=it_begin;it!=list_eval.end();++it) + { + // get the signature: + NOMAD::Signature * signature = (*it)->get_signature(); + if ( !signature ) + throw NOMAD::Exception ( "Evaluator_Control.cpp" , __LINE__ , + "Evaluator_Control::eval_points(): the point has no signature" ); + + // Scaling before evaluation of the points: + bool do_scaling = signature->get_scaling().is_defined(); + if ( do_scaling ) + (*it)->scale(); + + } - // count the bb evaluation: - if ( count_eval ) + // 2. list evaluation: + bool eval_list_ok = true; + NOMAD::Evaluator_Control::_force_evaluation_failure=false; + + try { - if ( x.get_eval_type() == NOMAD::SGTE ) - _stats.add_sgte_eval(); - else - { - // current mads bbe evaluation - _stats.add_bb_eval(); - - } + eval_list_ok=_ev->eval_x ( list_eval , h_max,count_list_eval ); } + catch ( exception & e ) + { + throw NOMAD::Exception ( "Evaluator_control.cpp" , __LINE__ , e.what() ); + } + + if ( _force_evaluation_failure ) + eval_list_ok = false; + + + // One block of evaluations is counted + if ( eval_list_ok ) + _stats.add_one_block_eval(); + + - // count the output stats (STAT_SUM and STAT_AVG): - if ( _p.check_stat_sum() || _p.check_stat_avg() ) + // 3. Post list evaluation checks and operation + std::list<bool>::iterator it_count=count_list_eval.begin(); + for ( std::list<NOMAD::Eval_Point*>::iterator it=it_begin;it!=list_eval.end();++it,++it_count) { + bool eval_ok=true; + bool eval_rejected=false; - count_output_stats(x); + // 3.1. check the nan's and list evaluation failure: + if ( !eval_list_ok || (*it)->check_nan() ) + eval_ok = false; - // check STAT_SUM_TARGET: - NOMAD::Double sum_target = _p.get_stat_sum_target(); - if ( sum_target.is_defined() ) { - NOMAD::Double sum = _stats.get_stat_sum(); - if ( !stop && sum.is_defined() && sum >= sum_target ) { - stop = true; - stop_reason = NOMAD::STAT_SUM_TARGET_REACHED; + if ((*it)->check_rejected()) + { + eval_rejected=true; + eval_ok=false; + } + + // 3.2 unscaling: + if ( (*it)->get_signature()->get_scaling().is_defined() ) + (*it)->unscale(); + + + if ( eval_ok && (*it)->get_eval_status()!=NOMAD::EVAL_FAIL ) + { + (*it)->set_eval_status ( NOMAD::EVAL_OK ); + + // set_f, set_h and set_EB_ok: + _ev->compute_f ( *(*it) ); + _ev->compute_h ( *(*it)); + + } + else if (!eval_rejected) + { + (*it)->set_eval_status ( NOMAD::EVAL_FAIL ); + _stats.add_failed_eval(); + } // Do nothing if eval has been rejected + + // insertion in cache even if is_eval_ok == false. Exception: a point that has been rejected by user is not put in the cache. + if ( !(*it)->is_in_cache() && !eval_rejected ) + { + + int size_before , size_after; + + if ( (*it)->get_eval_type() == NOMAD::SGTE ) + { + size_before = _sgte_cache->size(); + _sgte_cache->insert(*(*it)); + size_after = _sgte_cache->size(); + } + else + { + size_before = _cache->size(); + _cache->insert(*(*it)); + size_after = _cache->size(); } + + if ( size_after == size_before ) + (*it)->set_in_cache ( false ); } + + + // count the output stats (STAT_SUM and STAT_AVG): + if ( (_p.check_stat_sum() || _p.check_stat_avg()) && !eval_rejected) + count_output_stats(*(*it)); + } } - - // check the number of blackbox evaluations: - if ( !stop ) { - if ( max_bb_eval > 0 && _stats.get_bb_eval() >= max_bb_eval ) { - stop = true; - stop_reason = NOMAD::MAX_BB_EVAL_REACHED; - } - if ( max_sgte_eval > 0 && _stats.get_sgte_eval() >= max_sgte_eval ) { - stop = true; - stop_reason = NOMAD::MAX_SGTE_EVAL_REACHED; - } - } } + + /*-------------------------------------------*/ /* check stopping criteria (private) */ /*-------------------------------------------*/ @@ -1161,86 +1289,132 @@ void NOMAD::Evaluator_Control::check_stopping_criteria bool & stop , NOMAD::stop_type & stop_reason ) const { - // check the time: - if ( !stop && - _p.get_max_time() > 0 && - _stats.get_real_time() >= _p.get_max_time() ) { - stop = true; - stop_reason = NOMAD::MAX_TIME_REACHED; - } - - // count an evaluation or a simulated blackbox evaluation: - if ( x.get_eval_type() == NOMAD::TRUTH ) { - _stats.add_eval(); - if ( count_eval && !x.get_current_run() ) - _stats.add_sim_bb_eval(); - } + // check the time: + if ( !stop && + _p.get_max_time() > 0 && + _stats.get_real_time() >= _p.get_max_time() ) + { + stop = true; + stop_reason = NOMAD::MAX_TIME_REACHED; + } + + // count an evaluation or a simulated blackbox evaluation: + if ( x.get_eval_type() == NOMAD::TRUTH ) + { + _stats.add_eval(); + if ( count_eval && !x.get_current_run() ) + _stats.add_sim_bb_eval(); + } + + + // check STAT_SUM_TARGET: + if ( !stop && + (_p.check_stat_sum() || _p.check_stat_avg())) + { + + NOMAD::Double sum_target = _p.get_stat_sum_target(); + if ( sum_target.is_defined() ) + { + NOMAD::Double sum = _stats.get_stat_sum(); + if ( sum.is_defined() && sum >= sum_target ) + { + stop = true; + stop_reason = NOMAD::STAT_SUM_TARGET_REACHED; + } + } + } + + // check the number of blackbox evaluations: + if ( !stop ) + { + int max_bb_eval = _p.get_max_bb_eval(); + int max_sgte_eval = _p.get_max_sgte_eval(); + if ( max_bb_eval > 0 && _stats.get_bb_eval() >= max_bb_eval ) + { + stop = true; + stop_reason = NOMAD::MAX_BB_EVAL_REACHED; + } + if ( max_sgte_eval > 0 && _stats.get_sgte_eval() >= max_sgte_eval ) + { + stop = true; + stop_reason = NOMAD::MAX_SGTE_EVAL_REACHED; + } + } - // check the stopping condition MAX_EVAL: - if ( !stop && - _p.get_max_eval() > 0 && - _stats.get_eval() >= _p.get_max_eval() ) { - stop = true; - stop_reason = NOMAD::MAX_EVAL_REACHED; - } - - // check the stopping condition MAX_SIM_BB_EVAL: - if ( !stop && - _p.get_max_sim_bb_eval() > 0 && - _stats.get_sim_bb_eval() >= _p.get_max_sim_bb_eval() ) { - stop = true; - stop_reason = NOMAD::MAX_SIM_BB_EVAL_REACHED; - } - - // check the stopping conditions F_TARGET and FEAS_REACHED - // (for phase one: the evaluations must stop if all EB - // constraints are satisfied, but some PB constraints can - // be violated) - if ( !stop && - x.is_eval_ok() && - ( _p.get_opt_only_sgte() || - x.get_eval_type() == NOMAD::TRUTH ) ) { - - bool feasible = x.is_feasible ( _p.get_h_min() ); - - // check FEAS_REACHED: - if ( feasible && _p.get_stop_if_feasible() ) { - stop = true; - stop_reason = NOMAD::FEAS_REACHED; - } - - // check F_TARGET: - { - const NOMAD::Point & f_target = _p.get_f_target(); - const std::list<int> & index_obj = _p.get_index_obj(); - std::list<int>::const_iterator index_obj_end = index_obj.end(); - bool check_f_target = f_target.is_defined(); - int nb_to_check = (check_f_target) ? - f_target.nb_defined() : 0; - - if ( check_f_target && ( feasible || search == NOMAD::LH_SEARCH_P1 ) ) { - const NOMAD::Point & bbo = x.get_bb_outputs(); - bool chk = true; - int k = 0; - int cnt = 0; - for ( std::list<int>::const_iterator it = index_obj.begin(); - it != index_obj_end ; ++it , ++k ) { - if ( bbo[*it].is_defined() && f_target[k].is_defined() ) { - if ( f_target[k] < bbo[*it] ) { - chk = false; - break; - } - cnt++; - } + // check the stopping condition MAX_EVAL: + if ( !stop && + _p.get_max_eval() > 0 && + _stats.get_eval() >= _p.get_max_eval() ) + { + stop = true; + stop_reason = NOMAD::MAX_EVAL_REACHED; } - if ( chk && cnt == nb_to_check ) { - stop = true; - stop_reason = NOMAD::F_TARGET_REACHED; + // check the stopping condition MAX_SIM_BB_EVAL: + if ( !stop && + _p.get_max_sim_bb_eval() > 0 && + _stats.get_sim_bb_eval() >= _p.get_max_sim_bb_eval() ) + { + stop = true; + stop_reason = NOMAD::MAX_SIM_BB_EVAL_REACHED; + } + + // check the stopping conditions F_TARGET and FEAS_REACHED + // (for phase one: the evaluations must stop if all EB + // constraints are satisfied, but some PB constraints can + // be violated) + if ( !stop && + x.is_eval_ok() && + ( _p.get_opt_only_sgte() || + x.get_eval_type() == NOMAD::TRUTH ) ) + { + + bool feasible = x.is_feasible ( _p.get_h_min() ); + + // check FEAS_REACHED: + if ( feasible && _p.get_stop_if_feasible() ) + { + stop = true; + stop_reason = NOMAD::FEAS_REACHED; + } + + // check F_TARGET: + { + const NOMAD::Point & f_target = _p.get_f_target(); + const std::list<int> & index_obj = _p.get_index_obj(); + std::list<int>::const_iterator index_obj_end = index_obj.end(); + bool check_f_target = f_target.is_defined(); + int nb_to_check = (check_f_target) ? + f_target.nb_defined() : 0; + + if ( check_f_target && ( feasible || search == NOMAD::LH_SEARCH_P1 ) ) + { + const NOMAD::Point & bbo = x.get_bb_outputs(); + bool chk = true; + int k = 0; + int cnt = 0; + for ( std::list<int>::const_iterator it = index_obj.begin(); + it != index_obj_end ; ++it , ++k ) + { + if ( bbo[*it].is_defined() && f_target[k].is_defined() ) + { + if ( f_target[k] < bbo[*it] ) + { + chk = false; + break; + } + cnt++; + } + } + + if ( chk && cnt == nb_to_check ) + { + stop = true; + stop_reason = NOMAD::F_TARGET_REACHED; + } + } + } } - } - } - } } /*-------------------------------------------------------*/ @@ -1342,87 +1516,90 @@ void NOMAD::Evaluator_Control::wait_for_evaluations NOMAD::success_type & success , std::list<const NOMAD::Eval_Point *> & evaluated_pts ) { - if ( _nb_in_progress == 0 ) - return; - - // display degree: - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_display_degree ( search ); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << NOMAD::open_block ( "wait for evaluations" ); - - NOMAD::Barrier & barrier = ( _p.get_opt_only_sgte() ) ? - sgte_barrier : true_barrier; - char signal; - int source; - NOMAD::Eval_Point * eval_x; - NOMAD::success_type one_eval_success; - - while ( _nb_in_progress > 0 ) { - - source = NOMAD::Slave::receive_signal ( signal ); - eval_x = _eval_in_progress[source]; - - if ( eval_x ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << "receive eval point #" << eval_x->get_tag() - << " from slave " << source << std::endl << std::endl; - - receive_eval_result ( search , - eval_x , - true_barrier , - sgte_barrier , - pareto_front , - source , - stop , - stop_reason ); - - // list of processed points: - if ( eval_x->is_in_cache() ) - evaluated_pts.push_back ( eval_x ); - - // success: - one_eval_success = barrier.get_one_eval_succ(); - success = barrier.get_success(); - - // asynchronous success count: - if ( success == NOMAD::FULL_SUCCESS && - _elop_tag != _slaves_elop_tags[source] ) - _stats.add_asynchronous_success(); - - // displays: - display_eval_result ( *eval_x , - display_degree , - search , - one_eval_success , - success ); - - if ( !_eval_in_progress[source]->is_in_cache() ) - delete _eval_in_progress[source]; - _eval_in_progress[source] = NULL; - _slaves_elop_tags[source] = -1; - --_nb_in_progress; - - // force quit (by pressing ctrl-c): - if ( !stop && NOMAD::Evaluator_Control::_force_quit ) { - stop = true; - stop_reason = NOMAD::CTRL_C; - break; - } - - if ( stop && ( stop_reason==NOMAD::ERROR || - stop_reason==NOMAD::UNKNOWN_STOP_REASON ) ) - break; - } - else - NOMAD::Slave::send_signal ( NOMAD::WAIT_SIGNAL , source ); - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block(); + if ( _nb_in_progress == 0 ) + return; + + // display degree: + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_display_degree ( search ); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << NOMAD::open_block ( "wait for evaluations" ); + + NOMAD::Barrier & barrier = ( _p.get_opt_only_sgte() ) ? + sgte_barrier : true_barrier; + char signal; + int source; + NOMAD::Eval_Point * eval_x; + NOMAD::success_type one_eval_success; + + while ( _nb_in_progress > 0 ) + { + + source = NOMAD::Slave::receive_signal ( signal ); + eval_x = _eval_in_progress[source]; + + if ( eval_x ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << "receive eval point #" << eval_x->get_tag() + << " from slave " << source << std::endl << std::endl; + + receive_eval_result ( search , + eval_x , + true_barrier , + sgte_barrier , + pareto_front , + source , + stop , + stop_reason ); + + // list of processed points: + if ( eval_x->is_in_cache() ) + evaluated_pts.push_back ( eval_x ); + + // success: + one_eval_success = barrier.get_one_eval_succ(); + success = barrier.get_success(); + + // asynchronous success count: + if ( success == NOMAD::FULL_SUCCESS && + _elop_tag != _slaves_elop_tags[source] ) + _stats.add_asynchronous_success(); + + // displays: + display_eval_result ( *eval_x , + display_degree , + search , + one_eval_success , + success ); + + if ( !_eval_in_progress[source]->is_in_cache() ) + delete _eval_in_progress[source]; + _eval_in_progress[source] = NULL; + _slaves_elop_tags[source] = -1; + --_nb_in_progress; + + // force quit (by pressing ctrl-c): + if ( !stop && ( NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit() ) ) + { + stop = true; + stop_reason = NOMAD::CTRL_C; + break; + } + + if ( stop && ( stop_reason==NOMAD::ERROR || + stop_reason==NOMAD::UNKNOWN_STOP_REASON ) ) + break; + } + else + NOMAD::Slave::send_signal ( NOMAD::WAIT_SIGNAL , source ); + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block(); } #endif @@ -1467,7 +1644,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points std::list<const NOMAD::Eval_Point *> & evaluated_pts ) // OUT : list of processed pts { - if ( stop || _eval_lop.empty() ) { + if ( stop || _eval_lop.empty() ) + { stop_reason = NOMAD::UNKNOWN_STOP_REASON; ++_elop_tag; return; @@ -1480,7 +1658,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points const NOMAD::Display & out = _p.out(); NOMAD::dd_type display_degree = out.get_display_degree ( search ); - if ( display_degree == NOMAD::FULL_DISPLAY ) { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { std::ostringstream msg; msg << "list of points evaluation (" << search << ")"; out << std::endl << NOMAD::open_block ( msg.str() ); @@ -1529,14 +1708,16 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points std::set<NOMAD::Priority_Eval_Point>::iterator it = _eval_lop.begin() , end = _eval_lop.end(); - while ( !stop && !opp_stop && it != end ) { + while ( !stop && !opp_stop && it != end ) + { x = it->get_point(); x->set_current_run ( true ); // displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { // open the evaluation block: { @@ -1547,20 +1728,31 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points out << std::endl << NOMAD::open_block ( oss.str() ); } - out << std::endl << "point #" << x->get_tag() << " ( "; - x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - if ( x->get_direction() ) - out << "direction : " << *x->get_direction() << std::endl; - if ( x->get_mesh_index() ) - out << "mesh index : " << *x->get_mesh_index() << std::endl; + out << std::endl << "point #" << x->get_tag() << " ( "; + x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + if ( x->get_direction() ) + { + out << "direction : " << *x->get_direction() << std::endl; + NOMAD::Point delta; + x->get_signature()->get_mesh()->get_delta(delta); + out << "direction d : ( " << *x->get_direction()/delta << " )" << std::endl; + } + if ( x->get_signature() ) + out << "mesh indices: ( " << x->get_signature()->get_mesh()->get_mesh_indices() << " )" << std::endl; + out << std::endl; + + + } // check if the evaluation at this point is already in progress: - if ( !already_in_progress ( *x ) ) { + if ( !already_in_progress ( *x ) ) + { // current point check (# of bb outputs, bounds, integer values, fixed-vars): - if ( x->check ( _p.get_bb_nb_outputs() , check_failed_reason ) ) { + if ( x->check ( _p.get_bb_nb_outputs() , check_failed_reason ) ) + { count_eval = true; @@ -1571,7 +1763,9 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points pareto_front , count_eval , barrier.get_h_max() , - display_degree ) ) { + display_degree ) ) + + { // list of processed points: evaluated_pts.push_back ( x ); @@ -1603,7 +1797,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points f0 , barrier , nb_success , - one_for_luck ) ) { + one_for_luck ) ) + { _stats.add_interrupted_eval(); opp_stop = true; // will break loop #1 } @@ -1614,7 +1809,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // point not in cache (the point is saved for loop #2): - else { + else + { // blackbox or surrogate evaluations are allowed: if ( ( x->get_eval_type() == NOMAD::TRUTH && max_bb_eval != 0 ) || @@ -1628,7 +1824,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // points[k]->check() failed (close the evaluation block): - else if ( display_degree == NOMAD::FULL_DISPLAY ) { + else if ( display_degree == NOMAD::FULL_DISPLAY ) + { std::ostringstream oss; oss << "check failed (" << check_failed_reason << ")"; out.close_block ( oss.str() ); @@ -1636,7 +1833,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // evaluation already in progress (close the evaluation block): - else if ( display_degree == NOMAD::FULL_DISPLAY ) { + else if ( display_degree == NOMAD::FULL_DISPLAY ) + { std::ostringstream oss; oss << "evaluation of point #" << x->get_tag() << " already in progress"; @@ -1647,7 +1845,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points ++k; // force quit (by pressing ctrl-c): - if ( !stop && NOMAD::Evaluator_Control::_force_quit ) { + if ( !stop && (NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit()) ) + { stop = true; stop_reason = NOMAD::CTRL_C; } @@ -1664,14 +1863,16 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points char signal; NOMAD::Eval_Point * eval_x; - while ( !stop && !opp_stop && nb_evaluated < nb_to_evaluate ) { + while ( !stop && !opp_stop && nb_evaluated < nb_to_evaluate ) + { source = NOMAD::Slave::receive_signal ( signal ); // 2.1: send the RESULT signal, receive and process the evaluation result: // ----------------------------------------------------------------------- eval_x = _eval_in_progress[source]; - if ( eval_x ) { + if ( eval_x ) + { if ( display_degree == NOMAD::FULL_DISPLAY ) out << std::endl << "receive eval point #" << eval_x->get_tag() @@ -1720,7 +1921,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points f0 , barrier , nb_success , - one_for_luck ) ) { + one_for_luck ) ) + { _stats.add_interrupted_eval(); opp_stop = true; // will break loop #2 } @@ -1733,7 +1935,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points // 2.2: send the EVAL signal and launch a new evaluation: // ------------------------------------------------------ - else { + else + { // do not launch a new evaluation if... @@ -1744,19 +1947,22 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points // or if bbe+_nb_in_progress >= max_bb_eval: else if ( to_be_evaluated[cur]->get_eval_type() == NOMAD::TRUTH && max_bb_eval > 0 && - _stats.get_bb_eval() + _nb_in_progress >= max_bb_eval ) { + _stats.get_bb_eval() + _nb_in_progress >= max_bb_eval ) + { stop = true; stop_reason = NOMAD::MAX_BB_EVAL_REACHED; NOMAD::Slave::send_signal ( NOMAD::WAIT_SIGNAL , source ); } - else { + else + { // get the signature: NOMAD::Signature * signature = to_be_evaluated[cur]->get_signature(); // there is no signature (error): - if ( !signature ) { + if ( !signature ) + { stop = true; stop_reason = NOMAD::ERROR; if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) @@ -1767,7 +1973,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points NOMAD::Slave::send_signal ( NOMAD::WAIT_SIGNAL , source ); } - else { + else + { NOMAD::Slave::send_signal ( NOMAD::EVAL_SIGNAL , source ); @@ -1800,7 +2007,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // force quit (by pressing ctrl-c): - if ( !stop && NOMAD::Evaluator_Control::_force_quit ) { + if ( !stop && ( NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit() )) + { stop = true; stop_reason = NOMAD::CTRL_C; } @@ -1827,7 +2035,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points evaluated_pts ); // barriers update: - if ( !stop ) { + if ( !stop ) + { true_barrier.update_and_reset_success(); sgte_barrier.update_and_reset_success(); } @@ -1851,6 +2060,7 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // end of eval_lop() parallel version +// C. Tribes may 28, 2014 --- method for points block evaluation of a given max size /*----------------------------------------------------------------*/ /* eval_list_of_points, private version (scalar version) */ /*----------------------------------------------------------------*/ @@ -1881,6 +2091,7 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points const NOMAD::Display & out = _p.out(); NOMAD::dd_type display_degree = out.get_display_degree ( search ); + if ( display_degree == NOMAD::FULL_DISPLAY ) { std::ostringstream oss; @@ -1913,79 +2124,207 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points const NOMAD::Eval_Point * x; NOMAD::check_failed_type check_failed_reason; - bool count_eval; bool one_for_luck = false; bool stop_evals = false; int init_nb_eval = _stats.get_eval(); int nb_success = 0; int k = 0; + int k_block = 0; int nb_points = get_nb_eval_points(); + int block_size = _p.get_bb_max_block_size(); + int block_nb = 1; // main loop (on the list of points): // ---------------------------------- std::set<NOMAD::Priority_Eval_Point>::iterator it = _eval_lop.begin() , end = _eval_lop.end(); + std::list<NOMAD::Eval_Point *> list_x,list_eval; + std::list<bool> count_list_eval; while ( !stop_evals && !stop && it != end ) { - x = it->get_point(); - x->set_current_run ( true ); + if ( block_size > 1 && display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "Block of evaluations (" << block_nb <<")"; + out << std::endl << NOMAD::open_block ( oss.str() ); + } - // displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) + // Creation of a block of evaluations from the list + //---------------------- + k_block=k; + bool opportunistic_success_from_cache_point=false; + while (list_eval.size()!=static_cast<size_t>(block_size) && it != end && ! stop_evals) { + + x = it->get_point(); + x->set_current_run ( true ); + + // displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) { - // open the evaluation block: - std::ostringstream oss; - if ( x->get_eval_type() == NOMAD::SGTE ) - oss << "surrogate "; - oss << "evaluation " << k+1 << "/" << nb_points; - out << std::endl << NOMAD::open_block ( oss.str() ); + { + // open the evaluation block: + std::ostringstream oss; + oss << "submitted "; + if ( x->get_eval_type() == NOMAD::SGTE ) + oss << "surrogate "; + oss << "evaluation " << k+1 << "/" << nb_points; + out << std::endl << NOMAD::open_block ( oss.str() ); + } + + out << std::endl << "point #" << x->get_tag() << " ( "; + x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + if ( x->get_direction() ) + { + out << "direction : " << *x->get_direction() << std::endl; + NOMAD::Point delta; + x->get_signature()->get_mesh()->get_delta(delta); + out << "direction d : ( " << *x->get_direction()/delta << " )" << std::endl; + } + if ( x->get_signature() ) + out << "mesh indices: ( " << x->get_signature()->get_mesh()->get_mesh_indices() << " )" << std::endl; + out << std::endl; + } - out << std::endl << "point #" << x->get_tag() << " ( "; - x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - if ( x->get_direction() ) - out << "direction : " << *x->get_direction() << std::endl; - if ( x->get_mesh_index() ) - out << "mesh index : " << *x->get_mesh_index() << std::endl; - out << std::endl; + // current point check (# of bb outputs, bounds, integer values, fixed-vars): + if ( x->check ( _p.get_bb_nb_outputs() , check_failed_reason ) ) + { + bool count_eval = true; + bool has_been_in_cache=cache_check ( x , + true_barrier , + sgte_barrier , + pareto_front , + count_eval , + barrier.get_h_max() , + display_degree ); + + + // put the point in a block list for evaluation: + if ( !has_been_in_cache ) + list_eval.push_back(&NOMAD::Cache::get_modifiable_point ( *x )); + else + { + // check stopping criteria for points in cache + check_stopping_criteria ( search , count_eval , *x , stop , stop_reason ); + + // process the evaluated point: + process_eval_point ( *x , + ( x->get_eval_type() == NOMAD::TRUTH ) ? true_barrier : sgte_barrier , + pareto_front ); + + + // success: + NOMAD::success_type one_eval_success = barrier.get_one_eval_succ(); + success = barrier.get_success(); + + + opportunistic_success_from_cache_point = stop_evaluations ( *x , + search , + k , + nb_points , + stop , + display_degree , + one_eval_success , + success , + init_nb_eval , + f0 , + barrier , + nb_success , + one_for_luck ); + + + } + + if (!stop) + list_x.push_back(&NOMAD::Cache::get_modifiable_point ( *x )); + + if ( opportunistic_success_from_cache_point ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block(); + + if ( block_size > 1 && display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block (); + + stop_evals = true; + break; + } + + } + // points[k]->check() failed: + else if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "check failed (" << check_failed_reason << ")" << std::endl; + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block(); + + + ++it; + ++k; } - - // current point check (# of bb outputs, bounds, integer values, fixed-vars): - if ( x->check ( _p.get_bb_nb_outputs() , check_failed_reason ) ) + if (list_eval.size()!=0) { - count_eval = true; - - bool has_been_in_cache=cache_check ( x , - true_barrier , - sgte_barrier , - pareto_front , - count_eval , - barrier.get_h_max() , - display_degree ); + count_list_eval.assign(list_eval.size(), false); - // search in cache or eval the point: - if ( !has_been_in_cache ) + if (_p.eval_points_as_block()) { - eval_point ( NOMAD::Cache::get_modifiable_point ( *x ) , - true_barrier , - sgte_barrier , - pareto_front , - count_eval , - stop , - stop_reason , - barrier.get_h_max() ); + eval_points ( list_eval , + true_barrier , + sgte_barrier , + pareto_front , + count_list_eval , + stop , + stop_reason , + barrier.get_h_max() ); + // check stopping criteria for points NOT in cache + std::list<NOMAD::Eval_Point *>::iterator it_eval; + } + else + { + // bool count_eval=false; + x=*(list_eval.begin()); + eval_point ( NOMAD::Cache::get_modifiable_point ( *x ) , + true_barrier , + sgte_barrier , + pareto_front , + count_list_eval.front() , + stop , + stop_reason , + barrier.get_h_max() ); } - // check stopping criteria: - check_stopping_criteria ( search , count_eval , *x , stop , stop_reason ); + } + + // Stop evals and exit the loop + if ( stop_evals ) + break; + + // Check all the points in the evaluation block + std::list<NOMAD::Eval_Point *>::iterator it_x,it_eval; + k=k_block; + it_eval=list_eval.begin(); + for(it_x=list_x.begin();it_x!=list_x.end();++it_x) + { + + x=(*it_x); + + // process the evaluated point: + if ( x->is_eval_ok() && x->is_in_cache() ) + process_eval_point ( *x , + ( x->get_eval_type() == NOMAD::TRUTH ) ? + true_barrier : sgte_barrier , + pareto_front ); + + + // success: NOMAD::success_type one_eval_success = barrier.get_one_eval_succ(); success = barrier.get_success(); @@ -2002,50 +2341,95 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points } // displays: - if ( ! has_been_in_cache || display_degree!=NOMAD::MINIMAL_DISPLAY) - display_eval_result ( *x, display_degree, search, one_eval_success, success ); + if ( block_size > 0 && display_degree == NOMAD::FULL_DISPLAY ) + { + // open the evaluation block: + std::ostringstream oss; + if ( x->get_eval_type() == NOMAD::SGTE ) + oss << "surrogate "; + oss << "evaluation " << k+1 << "/" << nb_points; + out << std::endl << NOMAD::open_block ( oss.str() ); + out << std::endl << "point #" << x->get_tag() << std::endl; + } + + std::list<bool>::iterator it_count=count_list_eval.begin(); + for(it_eval=list_eval.begin();it_eval!=list_eval.end();++it_eval,++it_count) + { + if ((*it_eval)==x) + { + + // count the bb evaluation: + if ( *it_count ) + { + if ( (*it_eval)->get_eval_type() == NOMAD::SGTE ) + _stats.add_sgte_eval(); + else + { + // current mads bbe evaluation + _stats.add_bb_eval(); + } + + // count the output stats (STAT_SUM and STAT_AVG): + if ( _p.check_stat_sum() || _p.check_stat_avg() ) + count_output_stats(*(*it_eval)); + } + + check_stopping_criteria ( search , *it_count ,*(*it_eval) , stop , stop_reason ); + + if ( *it_count ) + display_eval_result ( *x, display_degree, search, one_eval_success, success ); + + break; + } + } + + // close the evaluation block: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block (); + // stop the evaluations (opportunistic strategy) ? - if ( stop_evaluations ( *x , - search , - k , - nb_points , - stop , - display_degree , - one_eval_success , - success , - init_nb_eval , - f0 , - barrier , - nb_success , - one_for_luck ) ) + if ( !stop_evals && stop_evaluations ( *x , + search , + k , + nb_points , + stop , + display_degree , + one_eval_success , + success , + init_nb_eval , + f0 , + barrier , + nb_success , + one_for_luck ) ) { _stats.add_interrupted_eval(); stop_evals = true; } + + + ++k; + } - // points[k]->check() failed: - else if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "check failed (" << check_failed_reason << ")" << std::endl; - - // close the evaluation block: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << NOMAD::close_block(); - - ++it; - ++k; + if ( block_size > 1 && display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block (); + // force quit (by pressing ctrl-c): - if ( !stop && NOMAD::Evaluator_Control::_force_quit ) + if ( !stop && ( NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit()) ) { stop = true; stop_reason = NOMAD::CTRL_C; } - } // end of main loop - // ---------------- + list_x.clear(); + list_eval.clear(); + + ++block_nb; + + }// end of test for list evaluation // barriers update: if ( !stop ) @@ -2070,6 +2454,8 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points clear_eval_lop(); } // end of eval_lop() scalar version + + #endif /*-------------------------------------------------*/ @@ -2077,21 +2463,21 @@ void NOMAD::Evaluator_Control::private_eval_list_of_points /*-------------------------------------------------*/ void NOMAD::Evaluator_Control::reduce_eval_lop ( int n ) { - int nb_eval_pts = get_nb_eval_points(); - - if ( n < 0 || n >= nb_eval_pts ) - return; - - const NOMAD::Eval_Point * x; - std::set<NOMAD::Priority_Eval_Point>::iterator it = _eval_lop.end(); - --it; - - while ( get_nb_eval_points() > n ) { - x = it->get_point(); - if ( x && !x->is_in_cache() && x->get_eval_status() != NOMAD::EVAL_IN_PROGRESS ) - delete x; - _eval_lop.erase ( it-- ); - } + int nb_eval_pts = get_nb_eval_points(); + + if ( n < 0 || n >= nb_eval_pts ) + return; + + const NOMAD::Eval_Point * x; + std::set<NOMAD::Priority_Eval_Point>::iterator it = _eval_lop.end(); + for( int i=0;i<nb_eval_pts-n;i++) + { + --it; + x = it->get_point(); + if ( x && !x->is_in_cache() && x->get_eval_status() != NOMAD::EVAL_IN_PROGRESS ) + delete x; + } + _eval_lop.erase( it,_eval_lop.end()); } /*-------------------------------------------------*/ @@ -2844,7 +3230,6 @@ void NOMAD::Evaluator_Control::eval_list_of_points x->set ( (*it2)->size() , _p.get_bb_nb_outputs() ); x->set_signature ( (*it2)->get_signature () ); x->set_direction ( (*it2)->get_direction () ); - x->set_mesh_index ( (*it2)->get_mesh_index() ); x->Point::operator = ( **it2 ); modified_list = true; @@ -2868,11 +3253,13 @@ void NOMAD::Evaluator_Control::eval_list_of_points // model ordering: // --------------- - if ( !modified_list && _model_eval_sort && _eval_lop.size() > 1 ) { + if ( !modified_list && _model_eval_sort && _eval_lop.size() > 1 ) + { switch ( _p.get_model_eval_sort() ) { case NOMAD::TGP_MODEL: TGP_model_ordering ( display_degree , modified_list ); - if ( NOMAD::Evaluator_Control::_force_quit ) { + if ( NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit() ) + { stop = true; stop_reason = NOMAD::CTRL_C; } @@ -2940,12 +3327,14 @@ void NOMAD::Evaluator_Control::eval_list_of_points /*------------------------------------------------------------------------------------*/ /* ordering of a list of points based on surrogate (1st) or model (2nd) evaluations */ /*------------------------------------------------------------------------------------*/ + void NOMAD::Evaluator_Control::ordering_lop ( NOMAD::search_type search , // IN : search type bool & stop , // IN/OUT: stopping criterion NOMAD::stop_type & stop_reason , // OUT : stopping reason NOMAD::Barrier & true_barrier , // IN/OUT: truth barrier NOMAD::Barrier & sgte_barrier // IN/OUT: surrogate barrier ) + { std::list<const NOMAD::Eval_Point *> * evaluated_pts = new std::list<const NOMAD::Eval_Point *>; @@ -3008,7 +3397,6 @@ void NOMAD::Evaluator_Control::ordering_lop ( NOMAD::search_type sea x->set_direction ( (*it2)->get_direction () ); x->set_poll_center( (*it2)->get_poll_center () ); // Poll center is needed for further testing (not needed when evaluating points) x->set_poll_center_type ( (*it2)->get_poll_center_type () ); - x->set_mesh_index ( (*it2)->get_mesh_index() ); x->Point::operator = ( **it2 ); modified_list = true; @@ -3038,7 +3426,7 @@ void NOMAD::Evaluator_Control::ordering_lop ( NOMAD::search_type sea } } - if ( NOMAD::Evaluator_Control::_force_quit ) + if ( NOMAD::Evaluator_Control::_force_quit || NOMAD::Evaluator::get_force_quit() ) { stop = true; stop_reason = NOMAD::CTRL_C; @@ -3089,37 +3477,39 @@ bool NOMAD::Evaluator_Control::stop_evaluations int & nb_success , bool & one_for_luck ) const { - // opportunistic evaluation ? - bool opportunistic = is_opportunistic ( search ); - - if ( k < nb_points - 1 ) { + // opportunistic evaluation ? + bool opportunistic = is_opportunistic ( search ); - if ( stop ) - return true; - - if ( opportunistic && - ( x.get_eval_type() == NOMAD::TRUTH || _p.get_opt_only_sgte() ) ) { - - if ( one_for_luck && one_eval_success != NOMAD::FULL_SUCCESS ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - _p.out() << std::endl - << "opportunistic termination of evaluations (lucky eval)" - << std::endl; - return true; - } - - if ( success == NOMAD::FULL_SUCCESS && - check_opportunistic_criterion ( display_degree , - one_eval_success , - init_nb_eval , - f0 , - barrier , - nb_success , - one_for_luck ) ) - return true; - } - } - return false; + if ( k < nb_points - 1 ) { + + if ( stop ) + return true; + + if ( opportunistic && + ( x.get_eval_type() == NOMAD::TRUTH || _p.get_opt_only_sgte() ) ) + { + + if ( one_for_luck && one_eval_success != NOMAD::FULL_SUCCESS ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + _p.out() << std::endl + << "opportunistic termination of evaluations (lucky eval)" + << std::endl; + return true; + } + + if ( success == NOMAD::FULL_SUCCESS && + check_opportunistic_criterion ( display_degree , + one_eval_success , + init_nb_eval , + f0 , + barrier , + nb_success , + one_for_luck ) ) + return true; + } + } + return false; } /*-----------------------------------------------------------------*/ @@ -3136,91 +3526,105 @@ bool NOMAD::Evaluator_Control::check_opportunistic_criterion int & nb_success , bool & one_for_luck ) const { - int min_nb_success = _p.get_opportunistic_min_nb_success(); - int min_eval = _p.get_opportunistic_min_eval(); - NOMAD::Double min_f_imprvmt = _p.get_opportunistic_min_f_imprvmt(); - bool lucky_eval = _p.get_opportunistic_lucky_eval(); - const NOMAD::Display & out = _p.out(); - - // min_nb_success: - if ( min_nb_success > 0 ) { - - if ( one_eval_success == NOMAD::FULL_SUCCESS ) - ++nb_success; - - if ( nb_success < min_nb_success ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << "opport. strategy (nb_success=" << nb_success - << " < min_nb_success=" << min_nb_success - << "): continue evaluations" - << std::endl; - - return false; - } - } - - // min_eval: - if ( min_eval > 0 ) { - - int eval = _stats.get_eval() - init_nb_eval; - - if ( eval < min_eval ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << "opport. strategy (eval=" << eval - << " < min_eval=" << min_eval - << "): continue evaluations" << std::endl; - return false; - } - } - - // min_f_imprvmt: - if ( min_f_imprvmt.is_defined() ) { - - const NOMAD::Eval_Point * bf = barrier.get_best_feasible(); - - if ( f0.is_defined() && bf ) { - - NOMAD::Double f = bf->get_f(); - - if ( f.is_defined() ) { - - NOMAD::Double f_imprvmt = f0.rel_err(f) * 100.0; - if ( f_imprvmt < min_f_imprvmt ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << "opport. strategy (f_improvement=" - << f_imprvmt << " < min_f_imprvmt=" << min_f_imprvmt - << "): continue evaluations" << std::endl; - - return false; + int min_nb_success = _p.get_opportunistic_min_nb_success(); + int min_eval = _p.get_opportunistic_min_eval(); + NOMAD::Double min_f_imprvmt = _p.get_opportunistic_min_f_imprvmt(); + bool lucky_eval = _p.get_opportunistic_lucky_eval(); + const NOMAD::Display & out = _p.out(); + + // min_nb_success: + if ( min_nb_success > 0 ) + { + + if ( one_eval_success == NOMAD::FULL_SUCCESS ) + ++nb_success; + + if ( nb_success < min_nb_success ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << "opport. strategy (nb_success=" << nb_success + << " < min_nb_success=" << min_nb_success + << "): continue evaluations" + << std::endl; + + return false; + } } - } - } - } - - // lucky_eval: - if ( lucky_eval && one_eval_success == NOMAD::FULL_SUCCESS ) { - one_for_luck = true; - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << "opport. strategy: one more evaluation for luck" - << std::endl; - - return false; - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << "opport. strategy: stop evaluations" - << std::endl; - - return true; + + // min_eval: + if ( min_eval > 0 ) + { + + int eval = _stats.get_eval() - init_nb_eval; + + if ( eval < min_eval ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << "opport. strategy (eval=" << eval + << " < min_eval=" << min_eval + << "): continue evaluations" << std::endl; + return false; + } + } + + // min_f_imprvmt: + if ( min_f_imprvmt.is_defined() ) + { + + const NOMAD::Eval_Point * bf = barrier.get_best_feasible(); + + if ( f0.is_defined() && bf ) + { + + NOMAD::Double f = bf->get_f(); + + if ( f.is_defined() ) + { + + NOMAD::Double f_imprvmt = f0.rel_err(f) * 100.0; + + if ( f_imprvmt < min_f_imprvmt ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << "opport. strategy (f_improvement=" + << f_imprvmt << " < min_f_imprvmt=" << min_f_imprvmt + << "): continue evaluations" << std::endl; + + return false; + } + } + } + } + + // lucky_eval: + if ( lucky_eval && one_eval_success == NOMAD::FULL_SUCCESS ) + { + one_for_luck = true; + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << "opport. strategy: one more evaluation for luck" + << std::endl; + + return false; + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << std::endl << "opport. strategy: stop evaluations" ; + if (_p.get_bb_max_block_size() > 1) + out << " at the end of the block evaluation"; + out << std::endl; + } + + return true; } /*---------------------------------------------------------------*/ @@ -3287,9 +3691,11 @@ void NOMAD::Evaluator_Control::add_eval_point( NOMAD::Eval_Point *& x NOMAD::Direction * new_dir = NULL; if ( _p.has_periodic_variables() && - x->treat_periodic_variables ( new_dir ) ) { + x->treat_periodic_variables ( new_dir ) ) + { - if ( new_dir && new_dir->norm() == 0.0 ) { + if ( new_dir && new_dir->norm() == 0.0 ) + { if ( display_degree == NOMAD::FULL_DISPLAY ) out << "point #" << x->get_tag() @@ -3306,16 +3712,19 @@ void NOMAD::Evaluator_Control::add_eval_point( NOMAD::Eval_Point *& x } delete new_dir; - if ( snap_to_bounds && x->snap_to_bounds() ) { + if ( snap_to_bounds && x->snap_to_bounds() ) + { - if ( display_degree == NOMAD::FULL_DISPLAY ) { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { out << std::endl << "point #" << x->get_tag() << " "; if ( x->get_direction() && x->get_direction()->get_index() >= 0 ) out << "(dir " << x->get_direction()->get_index() << ") "; out << "has been snapped to bounds" << std::endl; } - if ( x->get_direction() && x->get_direction()->norm() == 0.0 ) { + if ( x->get_direction() && x->get_direction()->norm() == 0.0 ) + { if ( display_degree == NOMAD::FULL_DISPLAY ) out << "point #" << x->get_tag() @@ -3350,7 +3759,7 @@ void NOMAD::Evaluator_Control::add_eval_point( NOMAD::Eval_Point *& x if ( !signature ) throw NOMAD::Exception ( "Evaluator_Control.cpp" , __LINE__ , "Evaluator_Control::add_eval_point(): the point has no signature" ); - + // angle with last successful directions (feasible) const NOMAD::Direction & feas_success_dir = signature->get_feas_success_dir(); if ( feas_success_dir.is_defined() && @@ -3362,7 +3771,7 @@ void NOMAD::Evaluator_Control::add_eval_point( NOMAD::Eval_Point *& x if ( infeas_success_dir.is_defined() && x->get_poll_center_type() == NOMAD::INFEASIBLE ) pep.set_angle_success_dir ( infeas_success_dir.get_angle ( *x->get_direction() ) ); - + } diff --git a/src/Evaluator_Control.hpp b/src/Evaluator_Control.hpp index 09ab63bfb5563d888f23c5de098e993803d7cfdd..d0bfb6f123a7b83222563505cd8cbe8ce622baa5 100644 --- a/src/Evaluator_Control.hpp +++ b/src/Evaluator_Control.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Evaluator_Control.hpp - \brief Control of the blackbox evaluations (headers) - \author Sebastien Le Digabel - \date 2010-04-15 - \see Evaluator_Control.cpp -*/ + \file Evaluator_Control.hpp + \brief Control of the blackbox evaluations (headers) + \author Sebastien Le Digabel + \date 2010-04-15 + \see Evaluator_Control.cpp + */ #ifndef __EVALUATOR_CONTROL__ #define __EVALUATOR_CONTROL__ @@ -54,682 +54,720 @@ #ifdef R_VERSION extern "C" { - #include <Rinternals.h> +#include <Rinternals.h> } #endif namespace NOMAD { - - /// Control of the blackbox evaluations. - /** + + /// Control of the blackbox evaluations. + /** This class allows the evaluation of a list of trial point. - */ - class Evaluator_Control : private NOMAD::Uncopyable { - - private: - - static bool _force_quit; ///< Forces NOMAD to terminate if Ctrl-C is pressed. - const NOMAD::Parameters & _p; ///< Parameters. - NOMAD::Evaluator * _ev; ///< The evaluator. - - NOMAD::Cache * _cache; ///< Cache for true function evaluations. - NOMAD::Cache * _sgte_cache; ///< Cache for surrogate evaluations. - - /// List of points to be evaluated. - std::set<NOMAD::Priority_Eval_Point> _eval_lop; - - /// Flag to enable or disable the model ordering. - bool _model_eval_sort; - - /// Flag equal to \c true if the destructor has to delete \c this->_ev. - bool _del_ev; - - /// Flag equal to \c true if the destructor has to erase the cache. - bool _del_cache; - - /// Flag equal to \c true if the destructor has to erase the cache for surrogates. - bool _del_sgte_cache; - + */ + class Evaluator_Control : private NOMAD::Uncopyable { + + private: + + static bool _force_quit; ///< Forces NOMAD to terminate if Ctrl-C is pressed. + static bool _force_evaluation_failure; ///< Forces an evaluation failure. + + const NOMAD::Parameters & _p; ///< Parameters. + NOMAD::Evaluator * _ev; ///< The evaluator. + + NOMAD::Cache * _cache; ///< Cache for true function evaluations. + NOMAD::Cache * _sgte_cache; ///< Cache for surrogate evaluations. + + /// List of points to be evaluated. + std::set<NOMAD::Priority_Eval_Point> _eval_lop; + + /// Flag to enable or disable the model ordering. + bool _model_eval_sort; + + /// Flag equal to \c true if the destructor has to delete \c this->_ev. + bool _del_ev; + + /// Flag equal to \c true if the destructor has to erase the cache. + bool _del_cache; + + /// Flag equal to \c true if the destructor has to erase the cache for surrogates. + bool _del_sgte_cache; + #ifdef USE_MPI - NOMAD::Eval_Point ** _eval_in_progress; ///< List of evaluations in progress. - int _nb_in_progress; ///< Number of evaluations in progress. - - /// Elop tag. - /** - Unique tag associated to \c this->eval_lop(). - */ - int _elop_tag; - - /// Elop tag for each slave. - /** - _slaves_elop_tags[k] corresponds to the Elop tag for slave \c k. - */ - int * _slaves_elop_tags; - - NOMAD::Slave * _slave; // Slave object for master process + NOMAD::Eval_Point ** _eval_in_progress; ///< List of evaluations in progress. + int _nb_in_progress; ///< Number of evaluations in progress. + + /// Elop tag. + /** + Unique tag associated to \c this->eval_lop(). + */ + int _elop_tag; + + /// Elop tag for each slave. + /** + _slaves_elop_tags[k] corresponds to the Elop tag for slave \c k. + */ + int * _slaves_elop_tags; + + NOMAD::Slave * _slave; // Slave object for master process #endif - + #ifdef USE_TGP - NOMAD::TGP_Model * _last_TGP_model; ///< Last TGP model from the model search. + NOMAD::TGP_Model * _last_TGP_model; ///< Last TGP model from the model search. #endif - - NOMAD::Model_Stats _model_ordering_stats; ///< Model ordering stats. - NOMAD::Stats & _stats; ///< Algorithm stats. - - /** - - Lattest tag of a point that has been written for \c display_stats + + NOMAD::Model_Stats _model_ordering_stats; ///< Model ordering stats. + NOMAD::Stats & _stats; ///< Algorithm stats. + + /** + - Lattest tag of a point that has been written for \c display_stats or \c stats_file. - - It is used to avoid any double display at the end of a run. - */ - mutable int _last_stats_tag; - - /// Same as \c this->_last_stats_bbe for the number of blackbox evaluations. - mutable int _last_stats_bbe; - - /// Last entry in the history file to avoid cache hits. - mutable int _last_history_bbe; - - /// Process an already evaluated Eval_Point. - /** - \param x The point -- \b IN. - \param barrier The barrier -- \b IN/OUT. - \param pareto_front The Pareto front -- \b IN/OUT - (may be NULL). - */ - void process_eval_point ( const NOMAD::Eval_Point & x , - NOMAD::Barrier & barrier , - NOMAD::Pareto_Front * pareto_front ) const; - - /// Save the solution file or update the history file. - /** - \param file_name Name of the file -- \b IN. - \param x Lattest solution -- \b IN. - \param is_sol Flag equal to \c true if the file is - a solution file; otherwise it is a history file. -- \b IN. - \param display_bimv Display best infeasible (min. viol.) if \c true -- \b IN. - */ - void write_sol_or_his_file ( const std::string & file_name , - const NOMAD::Eval_Point & x , - bool is_sol , - bool display_bimv=false) const; - - /// Display evaluation result. - /** - \param x Lattest evaluation -- \b IN. - \param display_degree Display degree -- \b IN. - \param search Search type -- \b IN. - \param one_eval_success Success for one evaluation -- \b IN. - \param success Success for a series of evaluations -- \b IN. - */ - void display_eval_result ( const NOMAD::Eval_Point & x , - NOMAD::dd_type display_degree , - NOMAD::search_type search , - NOMAD::success_type one_eval_success , - NOMAD::success_type success ) const; - - /// Check if evaluations have to be stopped. - /** - Checks the opportunistic strategy stopping criterion. - \param x The lattest evaluation -- \b IN. - \param search Search type -- \b IN. - \param k Evaluation index -- \b IN. - \param nb_points Number of points to evaluate -- \b IN. - \param stop \c true if the algorithm has to be stopped -- \b IN. - \param display_degree Display degree -- \b IN. - \param one_eval_success Success for one evaluation -- \b IN. - \param success Success for a series of evaluations -- \b IN. - \param init_nb_eval Initial number of evaluations -- \b IN. - \param f0 Initial value of the objective function -- \b IN - (may be undefined). - \param barrier Barrier -- \b IN. - \param nb_success Number of successes -- \b IN/OUT. - \param one_for_luck \c true if one additional evaluation is made - according to parameter \c OPPORTUNISTIC_LUCKY_EVAL - -- \b IN/OUT. - */ - bool stop_evaluations ( const NOMAD::Eval_Point & x , - NOMAD::search_type search , - int k , - int nb_points , - bool stop , - NOMAD::dd_type display_degree , - NOMAD::success_type one_eval_success , - NOMAD::success_type success , - int init_nb_eval , - const NOMAD::Double & f0 , - const NOMAD::Barrier & barrier , - int & nb_success , - bool & one_for_luck ) const; - - /// Check the opportunistic strategy stopping criterion. - /** - \param display_degree Display degree -- \b IN. - \param one_eval_success Success for one evaluation -- \b IN. - \param init_nb_eval Initial number of evaluations -- \b IN. - \param f0 Initial value of the objective function -- \b IN - (may be undefined). - \param barrier Barrier -- \b IN. - \param nb_success Number of successes -- \b IN/OUT. - \param one_for_luck \c true if one additional evaluation is made - according to parameter OPPORTUNISTIC_LUCKY_EVAL - -- \b IN/OUT. - \return A boolean equal to \c true to stop the evaluations; - Otherwise, continue the evaluations. - */ - bool check_opportunistic_criterion ( NOMAD::dd_type display_degree , - NOMAD::success_type one_eval_success , - int init_nb_eval , - const NOMAD::Double & f0 , - const NOMAD::Barrier & barrier , - int & nb_success , - bool & one_for_luck ) const; - - /// Quadratic model ordering (parameter \c MODEL_EVAL_SORT). - /** - \param display_degree Display degree -- \b IN. - \param modified_list To indicate a change in the evaluation list -- \b OUT. - */ - void quad_model_ordering ( NOMAD::dd_type display_degree , - bool & modified_list ); - - /// TGP model ordering (parameter \c MODEL_EVAL_SORT). - /** - \param display_degree Display degree -- \b IN. - \param modified_list To indicate a change in the evaluation list -- \b OUT. - */ - void TGP_model_ordering ( NOMAD::dd_type display_degree , - bool & modified_list ); - - /// Count the output stats (STAT_SUM and STAT_AVG). - /** - \param x Lattest evaluation -- \b IN. - */ - void count_output_stats ( const NOMAD::Eval_Point & x ); - - /// Search a point in the cache. - /** - \param x The point -- \b IN/OUT. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param count_eval Count or not a simulated evaluation -- \b OUT. - \param h_max Maximal feasibility value -- \b IN. - \param display_degree Display degree -- \b IN. - \return A boolean equal to \c true if the point is in cache. - */ - bool cache_check ( const NOMAD::Eval_Point *& x , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - bool & count_eval , - const NOMAD::Double & h_max , - NOMAD::dd_type display_degree ) const; - - /// Evaluate a point. - /* - \param x The point -- \b IN/OUT. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param count_eval Count or not the evaluation -- \b OUT. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param h_max Maximal feasibility value -- \b IN. - */ - void eval_point ( NOMAD::Eval_Point & x , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - bool & count_eval , - bool & stop , - NOMAD::stop_type & stop_reason , - const NOMAD::Double & h_max ); - - /// Check if a search is opportunistic or not. - /** - \param t Search type -- \b IN. - \return A boolean equal to \c true if the search is opportunistic. - */ - bool is_opportunistic ( NOMAD::search_type t ) const; - - /// Check stopping criteria. - /** - \param search Search type -- \b IN. - \param count_eval Count or not the evaluation -- \b IN. - \param x Lattest evaluation -- \b IN/OUT. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - */ - void check_stopping_criteria ( NOMAD::search_type search , - bool count_eval , - const NOMAD::Eval_Point & x , - bool & stop , - NOMAD::stop_type & stop_reason ) const; - + - It is used to avoid any double display at the end of a run. + */ + mutable int _last_stats_tag; + + /// Same as \c this->_last_stats_bbe for the number of blackbox evaluations. + mutable int _last_stats_bbe; + + /// Last entry in the history file to avoid cache hits. + mutable int _last_history_bbe; + + /// Process an already evaluated Eval_Point. + /** + \param x The point -- \b IN. + \param barrier The barrier -- \b IN/OUT. + \param pareto_front The Pareto front -- \b IN/OUT + (may be NULL). + */ + void process_eval_point ( const NOMAD::Eval_Point & x , + NOMAD::Barrier & barrier , + NOMAD::Pareto_Front * pareto_front ) const; + + /// Save the solution file or update the history file. + /** + \param file_name Name of the file -- \b IN. + \param x Lattest solution -- \b IN. + \param is_sol Flag equal to \c true if the file is + a solution file; otherwise it is a history file. + \param display_bimv Display best infeasible (min. viol.) if \c true + */ + void write_sol_or_his_file ( const std::string & file_name , + const NOMAD::Eval_Point & x , + bool is_sol , + bool display_bimv=false) const; + + /// Display evaluation result. + /** + \param x Lattest evaluation -- \b IN. + \param display_degree Display degree -- \b IN. + \param search Search type -- \b IN. + \param one_eval_success Success for one evaluation -- \b IN. + \param success Success for a series of evaluations -- \b IN. + */ + void display_eval_result ( const NOMAD::Eval_Point & x , + NOMAD::dd_type display_degree , + NOMAD::search_type search , + NOMAD::success_type one_eval_success , + NOMAD::success_type success ) const; + + /// Check if evaluations have to be stopped. + /** + Checks the opportunistic strategy stopping criterion. + \param x The lattest evaluation -- \b IN. + \param search Search type -- \b IN. + \param k Evaluation index -- \b IN. + \param nb_points Number of points to evaluate -- \b IN. + \param stop \c true if the algorithm has to be stopped -- \b IN. + \param display_degree Display degree -- \b IN. + \param one_eval_success Success for one evaluation -- \b IN. + \param success Success for a series of evaluations -- \b IN. + \param init_nb_eval Initial number of evaluations -- \b IN. + \param f0 Initial value of the objective function -- \b IN + (may be undefined). + \param barrier Barrier -- \b IN. + \param nb_success Number of successes -- \b IN/OUT. + \param one_for_luck \c true if one additional evaluation is made + according to parameter \c OPPORTUNISTIC_LUCKY_EVAL + -- \b IN/OUT. + */ + bool stop_evaluations ( const NOMAD::Eval_Point & x , + NOMAD::search_type search , + int k , + int nb_points , + bool stop , + NOMAD::dd_type display_degree , + NOMAD::success_type one_eval_success , + NOMAD::success_type success , + int init_nb_eval , + const NOMAD::Double & f0 , + const NOMAD::Barrier & barrier , + int & nb_success , + bool & one_for_luck ) const; + + /// Check the opportunistic strategy stopping criterion. + /** + \param display_degree Display degree -- \b IN. + \param one_eval_success Success for one evaluation -- \b IN. + \param init_nb_eval Initial number of evaluations -- \b IN. + \param f0 Initial value of the objective function -- \b IN + (may be undefined). + \param barrier Barrier -- \b IN. + \param nb_success Number of successes -- \b IN/OUT. + \param one_for_luck \c true if one additional evaluation is made + according to parameter OPPORTUNISTIC_LUCKY_EVAL + -- \b IN/OUT. + \return A boolean equal to \c true to stop the evaluations; + Otherwise, continue the evaluations. + */ + bool check_opportunistic_criterion ( NOMAD::dd_type display_degree , + NOMAD::success_type one_eval_success , + int init_nb_eval , + const NOMAD::Double & f0 , + const NOMAD::Barrier & barrier , + int & nb_success , + bool & one_for_luck ) const; + + /// Quadratic model ordering (parameter \c MODEL_EVAL_SORT). + /** + \param display_degree Display degree -- \b IN. + \param modified_list To indicate a change in the evaluation list -- \b OUT. + */ + void quad_model_ordering ( NOMAD::dd_type display_degree , + bool & modified_list ); + + /// TGP model ordering (parameter \c MODEL_EVAL_SORT). + /** + \param display_degree Display degree -- \b IN. + \param modified_list To indicate a change in the evaluation list -- \b OUT. + */ + void TGP_model_ordering ( NOMAD::dd_type display_degree , + bool & modified_list ); + + /// Count the output stats (STAT_SUM and STAT_AVG). + /** + \param x Lattest evaluation -- \b IN. + */ + void count_output_stats ( const NOMAD::Eval_Point & x ); + + /// Search a point in the cache. + /** + \param x The point -- \b IN/OUT. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param count_eval Count or not a simulated evaluation -- \b OUT. + \param h_max Maximal feasibility value -- \b IN. + \param display_degree Display degree -- \b IN. + \return A boolean equal to \c true if the point is in cache. + */ + bool cache_check ( const NOMAD::Eval_Point *& x , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + bool & count_eval , + const NOMAD::Double & h_max , + NOMAD::dd_type display_degree ) const; + + /// Evaluate a point. + /* + \param x The point -- \b IN/OUT. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param count_eval Count or not the evaluation -- \b OUT. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param h_max Maximal feasibility value -- \b IN. + */ + void eval_point ( NOMAD::Eval_Point & x , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + bool & count_eval , + bool & stop , + NOMAD::stop_type & stop_reason , + const NOMAD::Double & h_max ); + + + + /// Evaluate points. + /* + \param list_x The list of points -- \b IN/OUT. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param list_count_eval A list of bool for counted evaluations -- \b OUT. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param h_max Maximal feasibility value -- \b IN. + */ + void eval_points ( std::list<NOMAD::Eval_Point *> & list_x , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + std::list<bool> & list_count_eval , + bool & stop , + NOMAD::stop_type & stop_reason , + const NOMAD::Double & h_max ); + + + + + /// Check if a search is opportunistic or not. + /** + \param t Search type -- \b IN. + \return A boolean equal to \c true if the search is opportunistic. + */ + bool is_opportunistic ( NOMAD::search_type t ) const; + + /// Check stopping criteria. + /** + \param search Search type -- \b IN. + \param count_eval Count or not the evaluation -- \b IN. + \param x Lattest evaluation -- \b IN/OUT. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void check_stopping_criteria ( NOMAD::search_type search , + bool count_eval , + const NOMAD::Eval_Point & x , + bool & stop , + NOMAD::stop_type & stop_reason ) const; + #ifdef USE_MPI - - /// Receive an evaluation result from a slave. - /** - \param search Search type -- \b IN. - \param x A pointer to the evaluation -- \b OUT. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param slave_rank Slave rank -- \b IN. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - */ - void receive_eval_result ( NOMAD::search_type search , - NOMAD::Eval_Point * x , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - int slave_rank , - bool & stop , - NOMAD::stop_type & stop_reason ); - - /// Check if the evaluation of a point is already in progress. - /** - \param x The point -- \b IN. - \return A boolean equal to \c true if the evaluation - of the point is already in progress. - */ - bool already_in_progress ( const NOMAD::Eval_Point & x ) const; - + + /// Receive an evaluation result from a slave. + /** + \param search Search type -- \b IN. + \param x A pointer to the evaluation -- \b OUT. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param slave_rank Slave rank -- \b IN. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void receive_eval_result ( NOMAD::search_type search , + NOMAD::Eval_Point * x , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + int slave_rank , + bool & stop , + NOMAD::stop_type & stop_reason ); + + /// Check if the evaluation of a point is already in progress. + /** + \param x The point -- \b IN. + \return A boolean equal to \c true if the evaluation + of the point is already in progress. + */ + bool already_in_progress ( const NOMAD::Eval_Point & x ) const; + #endif - - /// Evaluate a list of points. - /** - - "Evaluate a list of points" is abbreviated with "eval_lop". - - This method is private and is called by the public eval_lop method. - - This method is defined twice in the .cpp for scalar and parallel versions. - - The method clears the list of points \c this->_eval_lop. - \param search Search type -- \b IN. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. - \param success Success for these evaluations -- \b OUT. - \param evaluated_pts List of processed points -- \b OUT. - */ - void private_eval_list_of_points - ( NOMAD::search_type search , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - bool & stop , - NOMAD::stop_type & stop_reason , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc , - NOMAD::success_type & success , - std::list<const NOMAD::Eval_Point *> & evaluated_pts ); - + + /// Evaluate a list of points. + /** + - "Evaluate a list of points" is abbreviated with "eval_lop". + - This method is private and is called by the public eval_lop method. + - This method is defined twice in the .cpp for scalar and parallel versions. + - The method clears the list of points \c this->_eval_lop. + \param search Search type -- \b IN. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. + \param success Success for these evaluations -- \b OUT. + \param evaluated_pts List of processed points -- \b OUT. + */ + void private_eval_list_of_points + ( NOMAD::search_type search , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + bool & stop , + NOMAD::stop_type & stop_reason , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc , + NOMAD::success_type & success , + std::list<const NOMAD::Eval_Point *> & evaluated_pts ); + + #ifdef MODEL_STATS - /// Display stats on an evaluation for which a model has been used. - /** - \param evaluated_pts List of evaluated points -- \b IN. - */ - void display_model_stats - ( const std::list<const NOMAD::Eval_Point *> & evaluated_pts ) const; + /// Display stats on an evaluation for which a model has been used. + /** + \param evaluated_pts List of evaluated points -- \b IN. + */ + void display_model_stats + ( const std::list<const NOMAD::Eval_Point *> & evaluated_pts ) const; #endif - - public: - - /// Constructor. - /** - \param p Parameters -- \b IN. - \param stats Stats -- \b IN/OUT. - \param ev Pointer to the Evaluator -- \b IN (may be \c NULL). - \param cache Pointer to the cache -- \b IN/OUT (may be \c NULL). - \param sgte_cache Pointer to the surrogate cache -- \b IN/OUT (may be \c NULL). - */ - Evaluator_Control ( const NOMAD::Parameters & p , - NOMAD::Stats & stats , - NOMAD::Evaluator * ev , - NOMAD::Cache * cache , - NOMAD::Cache * sgte_cache ); - - /// Destructor. - virtual ~Evaluator_Control ( void ); - - /// Force quit (called by pressing Ctrl-C). - static void force_quit ( void ) { Evaluator_Control::_force_quit = true; } - - - /// Display in stats file according to parameter \c STATS_FILE. - /** - \param file_name Name of the output file -- \b IN. - \param x Pointer to the lattest evaluation -- \b IN (may be \c NULL). - \param feasible Equal to \c true if \c x is feasible -- \b IN. - \param multi_obj Pointer to several objective values -- \b IN (may be \c NULL). - */ - void stats_file ( const std::string & file_name , - const NOMAD::Eval_Point * x , - bool feasible , - const NOMAD::Point * multi_obj ) const; - - /// Display stats during NOMAD::Mads::run() for minimal and normal display. - /** - \param header Boolean equal to \c true if a header has to be displayed - -- \b IN. - \param out Display -- \b IN. - \param stats List of stats to display -- \b IN. - \param x Pointer to the lattest evaluation -- \b IN (may be \c NULL). - \param feasible Equal to \c true if \c x is feasible -- \b IN. - \param multi_obj Pointer to several objective values -- \b IN (may be \c NULL). - */ - void display_stats ( bool header , - const NOMAD::Display & out , - const std::list<std::string> & stats , - const NOMAD::Eval_Point * x , - bool feasible , - const NOMAD::Point * multi_obj ) const; - - /// Display a real according to parameter \c DISPLAY_STATS. - /** - \param out Display -- \b IN. - \param d The real to display -- \b IN. - \param format The format - -- \b IN -- \b optional (default = empty string). - */ - void display_stats_real ( const NOMAD::Display & out , - const NOMAD::Double & d , - const std::string & format = "" ) const; - - /// Display a number according to its type \c DISPLAY_STATS. - /** - \param out Display -- \b IN. - \param d The number to display -- \b IN. - \param bbType The type to display -- \b IN. - */ - void display_stats_type ( const NOMAD::Display & out , - const NOMAD::Double & d , - const NOMAD::bb_input_type & bbType ) const; - - /// Display an integer according to parameter \c DISPLAY_STATS. - /** - \param out Display -- \b IN. - \param i The integer to display -- \b IN. - \param max_i Maximal value of \c i used to determine the display width - -- \b IN -- \b optional (default = \c -1). - \param format The format - -- \b IN -- \b optional (default = empty string). - */ - void display_stats_int ( const NOMAD::Display & out , - int i , - int max_i = -1 , - const std::string & format = "" ) const; - - /// Display a point according to parameter \c DISPLAY_STATS. - /** - \param out Display -- \b IN. - \param display_stats List of stats to display -- \b IN. - \param it Iterator for the list \c stats -- \b IN/OUT. - \param x Pointer to the point -- \b IN (may be \c NULL). - \param bbType Vector of input type -- \b IN -- \b optional (default = \c empty vector). - */ - void display_stats_point ( const NOMAD::Display & out , - const std::list<std::string> & display_stats , - std::list<std::string>::const_iterator & it , - const NOMAD::Point * x , - const std::vector<NOMAD::bb_input_type> & bbType = std::vector<NOMAD::bb_input_type> (0) ) const; - - /// Display model ordering stats ( parameter \c MODEL_EVAL_SORT ). - /** - \param out Display -- \b IN. - */ - void display_model_ordering_stats ( const NOMAD::Display & out ) const - { - out << _model_ordering_stats << std::endl; - } - - /// Save the caches. - /** - \param overwrite A boolean equal to \c true if the cache files - may be overwritten -- \b IN. - \return A boolean equal to \c true if the caches could be saved. - */ - bool save_caches ( bool overwrite ); - - /// Update the solution file. - /** - \param x The lattest solution -- \b IN. - \param display_bimv Required to display least infeasible (default=false) -- \b IN - */ - void write_solution_file ( const NOMAD::Eval_Point & x , bool display_bimv=false) const; - - /// Update a barrier from another barrier. - /** - Update barrier \c b1 from points in barrier \c b2 and treat - these points as evaluations (used in VNS search). - \param b1 First barrier -- \b IN/OUT. - \param b2 Second barrier -- \b IN. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param display_degree Display degree -- \b IN. - \param search Search type -- \b IN. - \return Success for these simulated evaluations. - */ - NOMAD::success_type process_barrier_points ( NOMAD::Barrier & b1 , - const NOMAD::Barrier & b2 , - NOMAD::Pareto_Front * pareto_front , - NOMAD::dd_type display_degree , - NOMAD::search_type search ) const; - /// Access to the cache (#1). - /** - Non-const version. - \return The cache. - */ - NOMAD::Cache & get_cache ( void ) { return *_cache; } - - /// Access to the cache (#2). - /** - Const version. - \return The cache. - */ - const NOMAD::Cache & get_cache ( void ) const { return *_cache; } - - /// Access to the surrogate cache (#1). - /** - Non-const version. - \return The surrogate cache. - */ - NOMAD::Cache & get_sgte_cache ( void ) { return *_sgte_cache; } - - /// Access to the surrogate cache (#2). - /** - Const version. - \return The surrogate cache. - */ - const NOMAD::Cache & get_sgte_cache ( void ) const { return *_sgte_cache; } - - /// Access to the evaluator. - /** - \return The evaluator. - */ - NOMAD::Evaluator * get_evaluator ( void ) const { return _ev; } - - /// Access to \c _last_stats_tag. - /** - \return \c _last_stats_tag. - */ - int get_last_stats_tag ( void ) const { return _last_stats_tag; } - - /// Access to _last_stats_bbe. - /** - \return _last_stats_bbe. - */ - int get_last_stats_bbe ( void ) const { return _last_stats_bbe; } - - /// Set the evaluator. - /** - \param e A pointer to the evaluator -- \b IN. - */ - void set_evaluator ( NOMAD::Evaluator * e ) { _ev = e; } - -#ifdef USE_TGP - /// Set the last TGP model from the model search. - /** - \param m The last TGP model -- \b IN. - */ - void set_last_TGP_model ( NOMAD::TGP_Model * m ) { _last_TGP_model = m; } + + public: + + /// Constructor. + /** + \param p Parameters -- \b IN. + \param stats Stats -- \b IN/OUT. + \param ev Pointer to the Evaluator -- \b IN (may be \c NULL). + \param cache Pointer to the cache -- \b IN/OUT (may be \c NULL). + \param sgte_cache Pointer to the surrogate cache -- \b IN/OUT (may be \c NULL). + */ + Evaluator_Control ( const NOMAD::Parameters & p , + NOMAD::Stats & stats , + NOMAD::Evaluator * ev , + NOMAD::Cache * cache , + NOMAD::Cache * sgte_cache ); + + /// Destructor. + virtual ~Evaluator_Control ( void ); + + /// Force quit (called by pressing Ctrl-C). + static void force_quit ( void ) + { + Evaluator_Control::_force_quit = true; + } + + /// Force evaluation failure. + static void force_evaluation_failure ( void ) + { + Evaluator_Control::_force_evaluation_failure = true; + } + + + /// Display in stats file according to parameter \c STATS_FILE. + /** + \param file_name Name of the output file -- \b IN. + \param x Pointer to the lattest evaluation -- \b IN (may be \c NULL). + \param feasible Equal to \c true if \c x is feasible -- \b IN. + \param multi_obj Pointer to several objective values -- \b IN (may be \c NULL). + */ + void stats_file ( const std::string & file_name , + const NOMAD::Eval_Point * x , + bool feasible , + const NOMAD::Point * multi_obj ) const; + + /// Display stats during NOMAD::Mads::run() for minimal and normal display. + /** + \param header Boolean equal to \c true if a header has to be displayed + -- \b IN. + \param out Display -- \b IN. + \param stats List of stats to display -- \b IN. + \param x Pointer to the lattest evaluation -- \b IN (may be \c NULL). + \param feasible Equal to \c true if \c x is feasible -- \b IN. + \param multi_obj Pointer to several objective values -- \b IN (may be \c NULL). + */ + void display_stats ( bool header , + const NOMAD::Display & out , + const std::list<std::string> & stats , + const NOMAD::Eval_Point * x , + bool feasible , + const NOMAD::Point * multi_obj ) const; + + /// Display a real according to parameter \c DISPLAY_STATS. + /** + \param out Display -- \b IN. + \param d The real to display -- \b IN. + \param format The format + -- \b IN -- \b optional (default = empty string). + */ + void display_stats_real ( const NOMAD::Display & out , + const NOMAD::Double & d , + const std::string & format = "" ) const; + + /// Display a number according to its type \c DISPLAY_STATS. + /** + \param out Display -- \b IN. + \param d The number to display -- \b IN. + \param bbType The type to display -- \b IN. + */ + void display_stats_type ( const NOMAD::Display & out , + const NOMAD::Double & d , + const NOMAD::bb_input_type & bbType ) const; + + /// Display an integer according to parameter \c DISPLAY_STATS. + /** + \param out Display -- \b IN. + \param i The integer to display -- \b IN. + \param max_i Maximal value of \c i used to determine the display width + -- \b IN -- \b optional (default = \c -1). + \param format The format + -- \b IN -- \b optional (default = empty string). + */ + void display_stats_int ( const NOMAD::Display & out , + int i , + int max_i = -1 , + const std::string & format = "" ) const; + + /// Display a point according to parameter \c DISPLAY_STATS. + /** + \param out Display -- \b IN. + \param display_stats List of stats to display -- \b IN. + \param it Iterator for the list \c stats -- \b IN/OUT. + \param x Pointer to the point -- \b IN (may be \c NULL). + \param bbType Vector of input type -- \b IN -- \b optional (default = \c empty vector). + */ + void display_stats_point ( const NOMAD::Display & out , + const std::list<std::string> & display_stats , + std::list<std::string>::const_iterator & it , + const NOMAD::Point * x , + const std::vector<NOMAD::bb_input_type> & bbType = std::vector<NOMAD::bb_input_type> (0) ) const; + + /// Display model ordering stats ( parameter \c MODEL_EVAL_SORT ). + /** + \param out Display -- \b IN. + */ + void display_model_ordering_stats ( const NOMAD::Display & out ) const + { + out << _model_ordering_stats << std::endl; + } + + /// Save the caches. + /** + \param overwrite A boolean equal to \c true if the cache files + may be overwritten -- \b IN. + \return A boolean equal to \c true if the caches could be saved. + */ + bool save_caches ( bool overwrite ); + + /// Update the solution file. + /** + \param x The lattest solution -- \b IN. + \param display_bimv Required to display least infeasible (default=false) -- \b IN + */ + void write_solution_file ( const NOMAD::Eval_Point & x , bool display_bimv=false) const; + + /// Update a barrier from another barrier. + /** + Update barrier \c b1 from points in barrier \c b2 and treat + these points as evaluations (used in VNS search). + \param b1 First barrier -- \b IN/OUT. + \param b2 Second barrier -- \b IN. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param display_degree Display degree -- \b IN. + \param search Search type -- \b IN. + \return Success for these simulated evaluations. + */ + NOMAD::success_type process_barrier_points ( NOMAD::Barrier & b1 , + const NOMAD::Barrier & b2 , + NOMAD::Pareto_Front * pareto_front , + NOMAD::dd_type display_degree , + NOMAD::search_type search ) const; + /// Access to the cache (#1). + /** + Non-const version. + \return The cache. + */ + NOMAD::Cache & get_cache ( void ) { return *_cache; } + + /// Access to the cache (#2). + /** + Const version. + \return The cache. + */ + const NOMAD::Cache & get_cache ( void ) const { return *_cache; } + + /// Access to the surrogate cache (#1). + /** + Non-const version. + \return The surrogate cache. + */ + NOMAD::Cache & get_sgte_cache ( void ) { return *_sgte_cache; } + + /// Access to the surrogate cache (#2). + /** + Const version. + \return The surrogate cache. + */ + const NOMAD::Cache & get_sgte_cache ( void ) const { return *_sgte_cache; } + + /// Access to the evaluator. + /** + \return The evaluator. + */ + NOMAD::Evaluator * get_evaluator ( void ) const { return _ev; } + + /// Access to \c _last_stats_tag. + /** + \return \c _last_stats_tag. + */ + int get_last_stats_tag ( void ) const { return _last_stats_tag; } + + /// Access to _last_stats_bbe. + /** + \return _last_stats_bbe. + */ + int get_last_stats_bbe ( void ) const { return _last_stats_bbe; } + + /// Set the evaluator. + /** + \param e A pointer to the evaluator -- \b IN. + */ + void set_evaluator ( NOMAD::Evaluator * e ) { _ev = e; } + +#ifdef USE_TGP + /// Set the last TGP model from the model search. + /** + \param m The last TGP model -- \b IN. + */ + void set_last_TGP_model ( NOMAD::TGP_Model * m ) { _last_TGP_model = m; } #endif - - /// Reset. - void reset ( void ); - - - /// Order eval list of points based on surrogate (1st) or model (2nd) - /** - \param search Search type -- \b IN. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - */ - void ordering_lop - ( NOMAD::search_type search , // IN : search type - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::Barrier & true_barrier , // IN/OUT: truth barrier - NOMAD::Barrier & sgte_barrier // IN/OUT: surrogate barrier - ); - - - - - /// Evaluation of a list of points (public version that calls the private version). - /** - \param search Search type -- \b IN. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. - \param success Success for this series of evaluations -- \b OUT. - \param evaluated_pts List of processed points -- \b OUT. - */ - void eval_list_of_points - ( NOMAD::search_type search , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - bool & stop , - NOMAD::stop_type & stop_reason , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc , - NOMAD::success_type & success , - std::list<const NOMAD::Eval_Point *> * evaluated_pts = NULL ); - - /// Add a point to the list of points to be evaluated. - /** - - The point has to be a dynamic object. - - It can be deleted into the method and be \c NULL after that. - - The point is also snapped to bounds. - - Periodic variables are checked. - \param x The point -- \b IN/OUT. - \param display_degree Display degree -- \b IN. - \param snap_to_bounds Boolean equal to \c true if the - point has to be snapped to bounds -- \b IN. - \param f_sgte Objective value for the surrogate -- \b IN - (may be undefined). - \param h_sgte Feasibility value for the surrogate -- \b IN - (may be undefined). - \param f_model Objective value for the model -- \b IN - (may be undefined). - \param h_model Feasibility value for the model -- \b IN - (may be undefined). - - */ - void add_eval_point ( NOMAD::Eval_Point *& x , - NOMAD::dd_type display_degree , - bool snap_to_bounds , - const NOMAD::Double & f_sgte , - const NOMAD::Double & h_sgte , - const NOMAD::Double & f_model , - const NOMAD::Double & h_model ); - - /// Display the list of evaluation points \c _eval_lop. - /** - \param t Search type -- \b IN - -- \b optional (default = NOMAD::UNDEFINED_SEARCH ). - */ - void display_eval_lop ( NOMAD::search_type t = NOMAD::UNDEFINED_SEARCH ) const; - - /// Access to the number of evaluation points. - /** - \return The number of evaluation points. - */ - int get_nb_eval_points ( void ) const - { - return static_cast<int> ( _eval_lop.size() ); - } - - /// Access to the list of evaluation points. - /** - \return The list of evaluation points. - */ - const std::set<NOMAD::Priority_Eval_Point> & get_eval_lop ( void ) const - { - return _eval_lop; - } - - /// Clear the list of evaluation points. - void clear_eval_lop ( void ) { reduce_eval_lop(0); } - - /// Reduce the list of evaluation points. - /** - \param n New size of the list -- \b IN. - */ - void reduce_eval_lop ( int n ); - - /// Enable the model ordering. - void enable_model_eval_sort ( void ) { _model_eval_sort = true; } - - /// Disable the model ordering. - void disable_model_eval_sort ( void ) { _model_eval_sort = false; } - + + /// Reset. + void reset ( void ); + + + /// Order eval list of points based on surrogate (1st) or model (2nd) + /** + \param search Search type -- \b IN. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + */ + void ordering_lop + ( NOMAD::search_type search , // IN : search type + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::Barrier & true_barrier , // IN/OUT: truth barrier + NOMAD::Barrier & sgte_barrier // IN/OUT: surrogate barrier + ); + + + + + /// Evaluation of a list of points (public version that calls the private version). + /** + \param search Search type -- \b IN. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. + \param success Success for this series of evaluations -- \b OUT. + \param evaluated_pts List of processed points -- \b OUT. + */ + void eval_list_of_points + ( NOMAD::search_type search , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + bool & stop , + NOMAD::stop_type & stop_reason , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc , + NOMAD::success_type & success , + std::list<const NOMAD::Eval_Point *> * evaluated_pts = NULL ); + + /// Add a point to the list of points to be evaluated. + /** + - The point has to be a dynamic object. + - It can be deleted into the method and be \c NULL after that. + - The point is also snapped to bounds. + - Periodic variables are checked. + \param x The point -- \b IN/OUT. + \param display_degree Display degree -- \b IN. + \param snap_to_bounds Boolean equal to \c true if the + point has to be snapped to bounds -- \b IN. + \param f_sgte Objective value for the surrogate -- \b IN + (may be undefined). + \param h_sgte Feasibility value for the surrogate -- \b IN + (may be undefined). + \param f_model Objective value for the model -- \b IN + (may be undefined). + \param h_model Feasibility value for the model -- \b IN + (may be undefined). + + */ + void add_eval_point ( NOMAD::Eval_Point *& x , + NOMAD::dd_type display_degree , + bool snap_to_bounds , + const NOMAD::Double & f_sgte , + const NOMAD::Double & h_sgte , + const NOMAD::Double & f_model , + const NOMAD::Double & h_model ); + + /// Display the list of evaluation points \c _eval_lop. + /** + \param t Search type -- \b IN + -- \b optional (default = NOMAD::UNDEFINED_SEARCH ). + */ + void display_eval_lop ( NOMAD::search_type t = NOMAD::UNDEFINED_SEARCH ) const; + + /// Access to the number of evaluation points. + /** + \return The number of evaluation points. + */ + int get_nb_eval_points ( void ) const + { + return static_cast<int> ( _eval_lop.size() ); + } + + /// Access to the list of evaluation points. + /** + \return The list of evaluation points. + */ + const std::set<NOMAD::Priority_Eval_Point> & get_eval_lop ( void ) const + { + return _eval_lop; + } + + /// Clear the list of evaluation points. + void clear_eval_lop ( void ) { reduce_eval_lop(0); } + + /// Reduce the list of evaluation points. + /** + \param n New size of the list -- \b IN. + */ + void reduce_eval_lop ( int n ); + + /// Enable the model ordering. + void enable_model_eval_sort ( void ) { _model_eval_sort = true; } + + /// Disable the model ordering. + void disable_model_eval_sort ( void ) { _model_eval_sort = false; } + #ifdef USE_MPI - - /// Access to the number of evaluations in progress. - /** - \return the number of evaluations in progress. - */ - int get_nb_eval_in_progress ( void ) const { return _nb_in_progress; } - - /// Wait for evaluations in progress. - /** - \param search Search type -- \b IN. - \param true_barrier Barrier for true evaluations -- \b IN/OUT. - \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. - \param pareto_front A pointer to the Pareto front -- \b IN/OUT - (may be \c NULL). - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param success Success for these evaluations -- \b OUT. - \param evaluated_pts List of processed points -- \b OUT. - */ - void wait_for_evaluations ( NOMAD::search_type search , - NOMAD::Barrier & true_barrier , - NOMAD::Barrier & sgte_barrier , - NOMAD::Pareto_Front * pareto_front , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - std::list<const NOMAD::Eval_Point *> - & evaluated_pts ); + + /// Access to the number of evaluations in progress. + /** + \return the number of evaluations in progress. + */ + int get_nb_eval_in_progress ( void ) const { return _nb_in_progress; } + + /// Wait for evaluations in progress. + /** + \param search Search type -- \b IN. + \param true_barrier Barrier for true evaluations -- \b IN/OUT. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN/OUT. + \param pareto_front A pointer to the Pareto front -- \b IN/OUT + (may be \c NULL). + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param success Success for these evaluations -- \b OUT. + \param evaluated_pts List of processed points -- \b OUT. + */ + void wait_for_evaluations ( NOMAD::search_type search , + NOMAD::Barrier & true_barrier , + NOMAD::Barrier & sgte_barrier , + NOMAD::Pareto_Front * pareto_front , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + std::list<const NOMAD::Eval_Point *> + & evaluated_pts ); #endif - }; + }; } #endif diff --git a/src/Exception.cpp b/src/Exception.cpp index b600dda0f8cc756fe365296b3c714adeb748a53a..cd72299d1872cabf5f7d67bead6ebe28225f54fd 100644 --- a/src/Exception.cpp +++ b/src/Exception.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Exception.hpp b/src/Exception.hpp index e318c49bfcba02eb334801c5fcc1162a25fea1e5..5e32917a133ade0f9a9de0f41d41e9ccce4784ab 100644 --- a/src/Exception.hpp +++ b/src/Exception.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Extended_Poll.cpp b/src/Extended_Poll.cpp index 85d008cc6a5d88d767051a5d7b2ee743e73010a2..4344e92f9641779caf9acb06a7a8e8191193a6df 100644 --- a/src/Extended_Poll.cpp +++ b/src/Extended_Poll.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -47,10 +47,10 @@ /*----------------------------------------------------------------*/ NOMAD::Extended_Poll::~Extended_Poll ( void ) { - std::set<NOMAD::Signature_Element>::const_iterator it , end = _signatures.end(); - for ( it = _signatures.begin() ; it != end ; ++it ) - delete (*it).get_signature(); - poll_reset(); + std::set<NOMAD::Signature_Element>::const_iterator it , end = _signatures.end(); + for ( it = _signatures.begin() ; it != end ; ++it ) + delete (*it).get_signature(); + poll_reset(); } /*----------------------------------------------------------------*/ @@ -58,16 +58,16 @@ NOMAD::Extended_Poll::~Extended_Poll ( void ) /*----------------------------------------------------------------*/ void NOMAD::Extended_Poll::reset ( void ) { - // successful directions: - std::set<NOMAD::Signature_Element>::const_iterator it , end = _signatures.end(); - for ( it = _signatures.begin() ; it != end ; ++it ) - { - (*it).get_signature()->reset_feas_success_dir(); - (*it).get_signature()->reset_infeas_success_dir(); - } - - // poll_reset: - poll_reset(); + // successful directions: + std::set<NOMAD::Signature_Element>::const_iterator it , end = _signatures.end(); + for ( it = _signatures.begin() ; it != end ; ++it ) + { + (*it).get_signature()->reset_feas_success_dir(); + (*it).get_signature()->reset_infeas_success_dir(); + } + + // poll_reset: + poll_reset(); } /*----------------------------------------------------------------*/ @@ -75,13 +75,13 @@ void NOMAD::Extended_Poll::reset ( void ) /*----------------------------------------------------------------*/ void NOMAD::Extended_Poll::poll_reset ( void ) { - _poll_signatures.clear(); - std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); - for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; - it != end ; ++it ) - if ( !(*it)->is_in_cache() ) - delete *it; - _extended_points.clear(); + _poll_signatures.clear(); + std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); + for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; + it != end ; ++it ) + if ( !(*it)->is_in_cache() ) + delete *it; + _extended_points.clear(); } /*----------------------------------------------------------------*/ @@ -89,49 +89,56 @@ void NOMAD::Extended_Poll::poll_reset ( void ) /* created by the user in construct_extended_points() */ /*----------------------------------------------------------------*/ void NOMAD::Extended_Poll::add_extended_poll_point ( NOMAD::Point & ep , - NOMAD::Signature & s ) + NOMAD::Signature & s ) { - // new signature: - // -------------- - NOMAD::Signature * new_s = new NOMAD::Signature (s); - - // . 's' can be standard, but its copy 'new_s' is not - - // . a standard signature will never be inserted into _signatures, - // since standard signatures are handled and deleted by the Parameters class - - { - // signature already registered ? - NOMAD::Signature_Element se ( new_s ); - std::set<NOMAD::Signature_Element>::const_iterator it = _signatures.find ( se ); - - // signature already registered: - if ( it != _signatures.end() ) - { - - // success directions eventually included in new_s are not considered - // since new_s is the copy of s, which is user provided - - delete new_s; - new_s = it->get_signature(); - } - - // new signature to register: - else - _signatures.insert ( se ); - - _poll_signatures.insert ( NOMAD::Signature_Element ( new_s ) ); - } - - // new eval point: - // --------------- - int ell = NOMAD::Mesh::get_mesh_index(); - NOMAD::Eval_Point * pt = new NOMAD::Eval_Point; - pt->set ( ep , _p.get_bb_nb_outputs() ); - pt->set_signature ( new_s ); - pt->set_mesh_index ( &ell ); - - _extended_points.push_back ( pt ); + // new signature: + // -------------- + NOMAD::Signature * new_s = new NOMAD::Signature (s); + + // . 's' can be standard, but its copy 'new_s' is not + + // . a standard signature will never be inserted into _signatures, + // since standard signatures are handled and deleted by the Parameters class + + { + // signature already registered ? + NOMAD::Signature_Element se ( new_s ); + std::set<NOMAD::Signature_Element>::const_iterator it = _signatures.find ( se ); + + // signature already registered: + if ( it != _signatures.end() ) + { + + // success directions eventually included in new_s are not considered + // since new_s is the copy of s, which is user provided + + delete new_s; + new_s = it->get_signature(); + } + + // new signature to register: + else + _signatures.insert ( se ); + + _poll_signatures.insert ( NOMAD::Signature_Element ( new_s ) ); + } + + // new eval point: + // --------------- + NOMAD::Eval_Point * pt = new NOMAD::Eval_Point; + pt->set ( ep , _p.get_bb_nb_outputs() ); + pt->set_signature ( new_s ); + + for ( int i = 0 ; i < pt->get_n() ; ++i ) + { + if ( (pt->get_signature()->get_input_type())[i] != NOMAD::CONTINUOUS && ! (*pt)[i].is_integer() ) + + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , + "NOMAD::Extended_Poll::add_extended_points(): the categorical variables of the added point must be an integer." ); + } + + + _extended_points.push_back ( pt ); } /*----------------------------------------------------------------*/ @@ -141,333 +148,361 @@ void NOMAD::Extended_Poll::add_extended_poll_point ( NOMAD::Point & ep , /* . private method */ /*----------------------------------------------------------------*/ bool NOMAD::Extended_Poll::check_trigger ( const NOMAD::Eval_Point * old_bf , - const NOMAD::Eval_Point * old_bi , - const NOMAD::Eval_Point * y ) const + const NOMAD::Eval_Point * old_bi , + const NOMAD::Eval_Point * y ) const { - if ( !y->is_in_cache() || - !y->is_eval_ok() || - !y->get_f().is_defined() || - !y->get_h().is_defined() ) - return false; - - // y is feasible: - // -------------- - if ( y->is_feasible ( _p.get_h_min() ) ) - { - - if ( !old_bf ) - return true; - - return check_trigger_on_f ( old_bf->get_f() , y->get_f() ); - } - - // y is infeasible: - // ---------------- - if ( !old_bf && !old_bi ) - return true; - - if ( !old_bf ) - return ( y->get_h() < old_bi->get_h() ); - - if ( !old_bi ) - return check_trigger_on_f ( old_bf->get_f() , y->get_f() ); - - if ( y->get_h() >= old_bi->get_h() ) - return false; - - // y is infeasible, and old best feasible and best infeasible solutions are - // available: the extended poll will be performed if the y point in the - // (h,f) space is below the line joining [ h(old_bf) , f(old_bf)+trigger ] - // to [ h(old_bi) , f(old_bi)+trigger ] : - const NOMAD::Double & hA = old_bf->get_h(); - NOMAD::Double fA = old_bf->get_f(); - - const NOMAD::Double & hB = old_bi->get_h(); - NOMAD::Double fB = old_bi->get_f(); - - const NOMAD::Double & hy = y->get_h(); - const NOMAD::Double & fy = y->get_f(); - - const NOMAD::Double & ept = _p.get_extended_poll_trigger(); - - if ( _p.get_relative_ept() && fA != 0.0 && fB != 0.0 && fy != 0.0 ) - { - fA = fA + fA.abs() * ept; - fB = fB + fB.abs() * ept; - } - else - { - fA = fA + ept; - fB = fB + ept; - } - - // line joining [h(A),f(A)] to [h(B),f(B)]: f=a*h+b : - NOMAD::Double a = (fA-fB) / (hA-hB); - NOMAD::Double b = fA - a * hA; - - return fy < a*hy + b; + if ( !y->is_in_cache() || + !y->is_eval_ok() || + !y->get_f().is_defined() || + !y->get_h().is_defined() ) + return false; + + // y is feasible: + // -------------- + if ( y->is_feasible ( _p.get_h_min() ) ) + { + + if ( !old_bf ) + return true; + + return check_trigger_on_f ( old_bf->get_f() , y->get_f() ); + } + + // y is infeasible: + // ---------------- + if ( !old_bf && !old_bi ) + return true; + + if ( !old_bf ) + return ( y->get_h() < old_bi->get_h() ); + + if ( !old_bi ) + return check_trigger_on_f ( old_bf->get_f() , y->get_f() ); + + if ( y->get_h() >= old_bi->get_h() ) + return false; + + // y is infeasible, and old best feasible and best infeasible solutions are + // available: the extended poll will be performed if the y point in the + // (h,f) space is below the line joining [ h(old_bf) , f(old_bf)+trigger ] + // to [ h(old_bi) , f(old_bi)+trigger ] : + const NOMAD::Double & hA = old_bf->get_h(); + NOMAD::Double fA = old_bf->get_f(); + + const NOMAD::Double & hB = old_bi->get_h(); + NOMAD::Double fB = old_bi->get_f(); + + const NOMAD::Double & hy = y->get_h(); + const NOMAD::Double & fy = y->get_f(); + + const NOMAD::Double & ept = _p.get_extended_poll_trigger(); + + if ( _p.get_relative_ept() && fA != 0.0 && fB != 0.0 && fy != 0.0 ) + { + fA = fA + fA.abs() * ept; + fB = fB + fB.abs() * ept; + } + else + { + fA = fA + ept; + fB = fB + ept; + } + + // line joining [h(A),f(A)] to [h(B),f(B)]: f=a*h+b : + NOMAD::Double a = (fA-fB) / (hA-hB); + NOMAD::Double b = fA - a * hA; + + return fy < a*hy + b; } /*-------------------------------------------------------------------*/ /* check only the f values for the extended poll trigger (private) */ /*-------------------------------------------------------------------*/ bool NOMAD::Extended_Poll::check_trigger_on_f ( const NOMAD::Double & old_f , - const NOMAD::Double & new_f ) const + const NOMAD::Double & new_f ) const { - if ( new_f <= old_f ) - return true; - - // relative comparison (both values are != 0): - if ( _p.get_relative_ept() && old_f != 0.0 && new_f != 0.0 ) - return ( new_f < old_f + old_f.abs() * _p.get_extended_poll_trigger() ); - - // absolute comparison: - return ( new_f < old_f + _p.get_extended_poll_trigger() ); + if ( new_f <= old_f ) + return true; + + // relative comparison (both values are != 0): + if ( _p.get_relative_ept() && old_f != 0.0 && new_f != 0.0 ) + return ( new_f < old_f + old_f.abs() * _p.get_extended_poll_trigger() ); + + // absolute comparison: + return ( new_f < old_f + _p.get_extended_poll_trigger() ); } /*----------------------------------------------------------------*/ /* descent from the extended poll center (private) */ /*----------------------------------------------------------------*/ void NOMAD::Extended_Poll::descent ( const NOMAD::Eval_Point * y , - Mads & mads , - int & nb_ext_poll_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + Mads & mads , + int & nb_ext_poll_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - int mesh_index = NOMAD::Mesh::get_mesh_index(); - NOMAD::Stats & stats = mads.get_stats(); - bool has_sgte = _p.has_sgte(); - bool opt_only_sgte = _p.get_opt_only_sgte(); - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_poll_dd(); - - // displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - - std::ostringstream oss; - oss << NOMAD::EXTENDED_POLL << " descent"; - if ( has_sgte ) - oss << " (on surrogates)"; - - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - - out << " iteration = " << stats.get_iterations() << std::endl - << " blackbox eval. = " << stats.get_bb_eval() << std::endl; - if ( has_sgte ) - out << " sgte eval. = " << stats.get_sgte_eval() << std::endl; - out << " mesh index = " << mesh_index << std::endl - << "ext. poll center = ( "; - y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " ) f=" << y->get_f() << " h=" << y->get_h() << std::endl << std::endl; - } - - // get the signature: - NOMAD::Signature * signature = y->get_signature(); - - - // create the descent parameters: - NOMAD::Parameters descent_p ( signature , _p.out() ); - set_descent_parameters ( y , stats , descent_p ); - - // Evaluator_Control object: - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // descent: run MADS: - // ------------------ - NOMAD::Mads EP_mads ( descent_p , - ev_control.get_evaluator () , - NULL , - &ev_control.get_cache () , - &ev_control.get_sgte_cache() ); + + + NOMAD::Stats & stats = mads.get_stats(); + bool has_sgte = _p.has_sgte(); + bool opt_only_sgte = _p.get_opt_only_sgte(); + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_poll_dd(); + + // get the signature: + NOMAD::Signature * signature = y->get_signature(); + + + // displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + + std::ostringstream oss; + oss << NOMAD::EXTENDED_POLL << " descent"; + if ( has_sgte ) + oss << " (on surrogates)"; + + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + + out << " iteration = " << stats.get_iterations() << std::endl + << " blackbox eval. = " << stats.get_bb_eval() << std::endl; + if ( has_sgte ) + out << " sgte eval. = " << stats.get_sgte_eval() << std::endl; + out << " mesh indices = (" << signature->get_mesh()->get_mesh_indices() << " )" << std::endl + << "ext. poll center = ( "; + y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " ) f=" << y->get_f() << " h=" << y->get_h() << std::endl << std::endl; + } + + + + // create the descent parameters: + NOMAD::Parameters descent_p ( signature , _p.out() ); + set_descent_parameters ( y , stats , descent_p ); + + + // mesh indices before the descent --> restore after descent + NOMAD::Point mesh_indices = signature->get_mesh()->get_mesh_indices(); + + // limit mesh index before the descent --> restore after descent + int limit_mesh_index = signature->get_mesh()->get_limit_mesh_index(); + + + // Set mesh indices to 0 + NOMAD::Point delta( signature->get_n(), 0 ); + descent_p.get_signature()->get_mesh()->set_mesh_indices( delta ); + + // Use best_feasible or best_infeasible limit mesh index as a termination criterion for descent + const NOMAD::Eval_Point * old_bf = mads.get_best_feasible(); + const NOMAD::Eval_Point * old_bi = mads.get_best_infeasible(); + int l1=0,l2=0; + if ( old_bf ) + l1 = static_cast<int>((old_bf->get_signature()->get_mesh()->get_min_mesh_indices())[0].value()); // index same for all variables when using categorical variable + else if ( old_bi ) + l2 = static_cast<int>((old_bi->get_signature()->get_mesh()->get_min_mesh_indices())[0].value()); + descent_p.get_signature()->get_mesh()->set_limit_mesh_index( min( l1, l2) ); + + + + // Evaluator_Control object: + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // descent: run MADS: + // ------------------ + NOMAD::Mads EP_mads ( descent_p , + ev_control.get_evaluator () , + NULL , + &ev_control.get_cache () , + &ev_control.get_sgte_cache() ); #ifdef DEBUG out << std::endl << NOMAD::open_block ( "MADS run (ext. poll)" ) << std::endl; #endif - - NOMAD::Mads::set_flag_reset_barriers ( true ); - NOMAD::Mads::set_flag_reset_mesh ( false ); - - NOMAD::stop_type st = EP_mads.run(); - - NOMAD::Mads::set_flag_reset_mesh ( true ); - + + NOMAD::Mads::set_flag_reset_barriers ( true ); + NOMAD::Mads::set_flag_reset_mesh ( false ); + + NOMAD::stop_type st = EP_mads.run(); + + NOMAD::Mads::set_flag_reset_mesh ( true ); + #ifdef DEBUG out << std::endl << NOMAD::close_block ( "end of run (ext. poll)" ) << std::endl; #endif - - // restore mesh index: - NOMAD::Mesh::set_mesh_index ( mesh_index ); - - // update stats: - const NOMAD::Stats & EP_stats = EP_mads.get_stats(); - stats.update ( EP_stats , true ); // for_search = true - stats.add_ext_poll_bb_eval ( EP_stats.get_bb_eval() ); - stats.add_ext_poll_descent (); - - // check MADS stopping criteria: - if ( st == NOMAD::CTRL_C || - st == NOMAD::ERROR || - st == NOMAD::UNKNOWN_STOP_REASON || - st == NOMAD::FEAS_REACHED || - st == NOMAD::MAX_CACHE_MEMORY_REACHED || - st == NOMAD::STAT_SUM_TARGET_REACHED || - st == NOMAD::MAX_SGTE_EVAL_REACHED || - st == NOMAD::F_TARGET_REACHED || - st == NOMAD::MAX_SIM_BB_EVAL_REACHED || - st == NOMAD::MAX_TIME_REACHED || - st == NOMAD::MAX_BB_EVAL_REACHED ) - { - stop_reason = st; - stop = true; - } - - // Pareto front: - NOMAD::Pareto_Front * pareto_front = mads.get_pareto_front(); - - // the barriers: - NOMAD::Barrier & true_barrier = mads.get_true_barrier(); - NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); - - // surrogate evaluations: perform at most one true evaluation: - if ( has_sgte && !opt_only_sgte ) - { - - if ( !stop ) - { - - // remember old best surrogates incumbents: - const NOMAD::Eval_Point * old_sgte_bf = sgte_barrier.get_best_feasible (); - const NOMAD::Eval_Point * old_sgte_bi = sgte_barrier.get_best_infeasible(); - - // update the surrogate barrier - // (no need to invoke Evaluator_Control::process_barrier_points() here - // since only surrogate evaluations have been made): - sgte_barrier.insert ( EP_mads.get_sgte_barrier() ); - NOMAD::success_type sgte_succ = sgte_barrier.get_success(); - sgte_barrier.update_and_reset_success(); - - // we generate only a true trial point if the - // surrogates improved the surrogate barrier: - if ( sgte_succ != NOMAD::UNSUCCESSFUL ) - { - - // choose the best surrogate point(s) where to evaluate the true function: - const NOMAD::Eval_Point * sgte_bf = sgte_barrier.get_best_feasible (); - const NOMAD::Eval_Point * sgte_bi = sgte_barrier.get_best_infeasible(); - - std::list<const NOMAD::Eval_Point *> candidates; - - if ( sgte_bf && ( !y->is_feasible(_p.get_h_min()) || sgte_bf != old_sgte_bf ) ) - candidates.push_back ( sgte_bf ); - - if ( sgte_bi && sgte_bi != old_sgte_bi ) - candidates.push_back ( sgte_bi ); - - // generate the new trial points: - NOMAD::Eval_Point * sk; - std::list<const NOMAD::Eval_Point *>::const_iterator it , end = candidates.end(); - for ( it = candidates.begin() ; it != end ; ++it ) - { - - // display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << "ext. poll surrogate candidate: " << **it << std::endl; - - sk = new NOMAD::Eval_Point; - sk->set ( signature->get_n() , _p.get_bb_nb_outputs() ); - sk->set_signature ( signature ); - sk->set_mesh_index ( &mesh_index ); - sk->Point::operator = ( **it ); - - // add the new point to the list of trial points: - ev_control.add_eval_point ( sk , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } - - // eval_list_of_points: - // -------------------- - success = NOMAD::UNSUCCESSFUL; - new_feas_inc = new_infeas_inc = NULL; - - ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , - true_barrier , - sgte_barrier , - pareto_front , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - - // number of search points (0 or 1 or 2): - nb_ext_poll_pts += static_cast<int> ( candidates.size() ); - } - } - } - - // true evaluations (or surrogate evaluations if opt_only_sgte==true): - else - { - - const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); - - // for the update of new_feas_inc and new_infeas_inc (1/2): - const NOMAD::Eval_Point * old_feasible_incumbent - = active_barrier.get_best_feasible(); - const NOMAD::Eval_Point * old_infeasible_incumbent - = active_barrier.get_best_infeasible(); - - // update barriers and process extended poll points: - NOMAD::success_type sgte_succ - = ev_control.process_barrier_points ( sgte_barrier , - EP_mads.get_sgte_barrier() , - pareto_front , - display_degree , - NOMAD::EXTENDED_POLL ); - - NOMAD::success_type true_succ - = ev_control.process_barrier_points ( true_barrier , - EP_mads.get_true_barrier() , - pareto_front , - display_degree , - NOMAD::EXTENDED_POLL ); - - // update of new_feas_inc and new_infeas_inc (2/2): - const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); - const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); - if ( bf && bf != old_feasible_incumbent ) - new_feas_inc = bf; - if ( bi && bi != old_infeasible_incumbent ) - new_infeas_inc = bi; - - // number of extended poll points and success: - if ( opt_only_sgte ) - { - nb_ext_poll_pts += EP_mads.get_stats().get_sgte_eval(); - success = sgte_succ; - } - else - { - nb_ext_poll_pts += EP_mads.get_stats().get_eval(); - success = true_succ; - } - } - - // final display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << "end of " << NOMAD::EXTENDED_POLL << " descent (" << success << ")"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } + + // Restore mesh indices and limit mesh index (termination criterion) + signature->get_mesh()->set_mesh_indices( mesh_indices ); + signature->get_mesh()->set_limit_mesh_index( limit_mesh_index ); + + + // update stats: + const NOMAD::Stats & EP_stats = EP_mads.get_stats(); + stats.update ( EP_stats , true ); // for_search = true + stats.add_ext_poll_bb_eval ( EP_stats.get_bb_eval() ); + stats.add_ext_poll_descent (); + + // check MADS stopping criteria: + if ( st == NOMAD::CTRL_C || + st == NOMAD::ERROR || + st == NOMAD::UNKNOWN_STOP_REASON || + st == NOMAD::FEAS_REACHED || + st == NOMAD::MAX_CACHE_MEMORY_REACHED || + st == NOMAD::STAT_SUM_TARGET_REACHED || + st == NOMAD::MAX_SGTE_EVAL_REACHED || + st == NOMAD::F_TARGET_REACHED || + st == NOMAD::MAX_SIM_BB_EVAL_REACHED || + st == NOMAD::MAX_TIME_REACHED || + st == NOMAD::MAX_BB_EVAL_REACHED ) + { + stop_reason = st; + stop = true; + } + + // Pareto front: + NOMAD::Pareto_Front * pareto_front = mads.get_pareto_front(); + + // the barriers: + NOMAD::Barrier & true_barrier = mads.get_true_barrier(); + NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); + + // surrogate evaluations: perform at most one true evaluation: + if ( has_sgte && !opt_only_sgte ) + { + + if ( !stop ) + { + + // remember old best surrogates incumbents: + const NOMAD::Eval_Point * old_sgte_bf = sgte_barrier.get_best_feasible (); + const NOMAD::Eval_Point * old_sgte_bi = sgte_barrier.get_best_infeasible(); + + // update the surrogate barrier + // (no need to invoke Evaluator_Control::process_barrier_points() here + // since only surrogate evaluations have been made): + sgte_barrier.insert ( EP_mads.get_sgte_barrier() ); + NOMAD::success_type sgte_succ = sgte_barrier.get_success(); + sgte_barrier.update_and_reset_success(); + + // we generate only a true trial point if the + // surrogates improved the surrogate barrier: + if ( sgte_succ != NOMAD::UNSUCCESSFUL ) + { + + // choose the best surrogate point(s) where to evaluate the true function: + const NOMAD::Eval_Point * sgte_bf = sgte_barrier.get_best_feasible (); + const NOMAD::Eval_Point * sgte_bi = sgte_barrier.get_best_infeasible(); + + std::list<const NOMAD::Eval_Point *> candidates; + + if ( sgte_bf && ( !y->is_feasible(_p.get_h_min()) || sgte_bf != old_sgte_bf ) ) + candidates.push_back ( sgte_bf ); + + if ( sgte_bi && sgte_bi != old_sgte_bi ) + candidates.push_back ( sgte_bi ); + + // generate the new trial points: + NOMAD::Eval_Point * sk; + std::list<const NOMAD::Eval_Point *>::const_iterator it , end = candidates.end(); + for ( it = candidates.begin() ; it != end ; ++it ) + { + + // display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << "ext. poll surrogate candidate: " << **it << std::endl; + + sk = new NOMAD::Eval_Point; + sk->set ( signature->get_n() , _p.get_bb_nb_outputs() ); + sk->set_signature ( signature ); + sk->Point::operator = ( **it ); + + // add the new point to the list of trial points: + ev_control.add_eval_point ( sk , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + } + + // eval_list_of_points: + // -------------------- + success = NOMAD::UNSUCCESSFUL; + new_feas_inc = new_infeas_inc = NULL; + + ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , + true_barrier , + sgte_barrier , + pareto_front , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + + // number of search points (0 or 1 or 2): + nb_ext_poll_pts += static_cast<int> ( candidates.size() ); + } + } + } + + // true evaluations (or surrogate evaluations if opt_only_sgte==true): + else + { + + const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); + + // for the update of new_feas_inc and new_infeas_inc (1/2): + const NOMAD::Eval_Point * old_feasible_incumbent + = active_barrier.get_best_feasible(); + const NOMAD::Eval_Point * old_infeasible_incumbent + = active_barrier.get_best_infeasible(); + + // update barriers and process extended poll points: + NOMAD::success_type sgte_succ + = ev_control.process_barrier_points ( sgte_barrier , + EP_mads.get_sgte_barrier() , + pareto_front , + display_degree , + NOMAD::EXTENDED_POLL ); + + NOMAD::success_type true_succ + = ev_control.process_barrier_points ( true_barrier , + EP_mads.get_true_barrier() , + pareto_front , + display_degree , + NOMAD::EXTENDED_POLL ); + + // update of new_feas_inc and new_infeas_inc (2/2): + const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); + const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); + if ( bf && bf != old_feasible_incumbent ) + new_feas_inc = bf; + if ( bi && bi != old_infeasible_incumbent ) + new_infeas_inc = bi; + + // number of extended poll points and success: + if ( opt_only_sgte ) + { + nb_ext_poll_pts += EP_mads.get_stats().get_sgte_eval(); + success = sgte_succ; + } + else + { + nb_ext_poll_pts += EP_mads.get_stats().get_eval(); + success = true_succ; + } + } + + // final display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of " << NOMAD::EXTENDED_POLL << " descent (" << success << ")"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } } /*----------------------------------------------------------------*/ @@ -478,191 +513,191 @@ void NOMAD::Extended_Poll::set_descent_parameters const NOMAD::Stats & stats , NOMAD::Parameters & descent_p ) const { - - // extended poll center signature - // (will be the temporary standard signature): - NOMAD::Signature * epc_signature = y->get_signature(); - if ( !epc_signature ) - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , - "Extended_Poll::set_descent_parameters(): ext. poll center has no signature" ); - - // we set all the parameters: - descent_p.set_DIMENSION ( epc_signature->get_n() ); - descent_p.set_BB_INPUT_TYPE ( epc_signature->get_input_types() ); - descent_p.set_LOWER_BOUND ( epc_signature->get_lb() ); - descent_p.set_UPPER_BOUND ( epc_signature->get_ub() ); - descent_p.set_FIXED_VARIABLE ( epc_signature->get_fixed_variables() ); - descent_p.set_PERIODIC_VARIABLE ( epc_signature->get_periodic_variables() ); - descent_p.set_VARIABLE_GROUP ( epc_signature->get_var_groups() ); - descent_p.set_BB_OUTPUT_TYPE ( _p.get_bb_output_type() ); - descent_p.set_DIRECTION_TYPE ( _p.get_direction_types() ); - - - { - const std::list<std::string> & bb_exe = _p.get_bb_exe(); - descent_p.set_BB_EXE ( bb_exe ); - std::list<std::string>::const_iterator it , end = bb_exe.end(); - for ( it = bb_exe.begin() ; it != end ; ++it ) - descent_p.set_SGTE_EXE ( *it , _p.get_sgte_exe ( *it ) ); - } - - descent_p.set_PROBLEM_DIR ( _p.get_problem_dir() ); - descent_p.set_TMP_DIR ( _p.get_tmp_dir() ); - descent_p.set_SGTE_COST ( _p.get_sgte_cost() ); - descent_p.set_SGTE_EVAL_SORT ( _p.get_sgte_eval_sort() ); - descent_p.set_X0 ( *y ); - - bool has_sgte = _p.has_sgte(); - if ( has_sgte ) - { - descent_p.reset_f_target(); - descent_p.set_HAS_SGTE ( true ); - descent_p.set_OPT_ONLY_SGTE ( true ); - descent_p.set_STOP_IF_FEASIBLE ( false ); - descent_p.set_MODEL_SEARCH ( false ); - descent_p.set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); - } - else - { - descent_p.set_F_TARGET ( _p.get_f_target() ); - descent_p.set_STOP_IF_FEASIBLE ( _p.get_stop_if_feasible() ); - descent_p.set_MODEL_EVAL_SORT ( _p.get_model_eval_sort()); - descent_p.set_MODEL_SEARCH (_p.has_model_search()); - } - - descent_p.set_DIRECTION_TYPE ( _p.get_direction_types() ); - descent_p.set_SEC_POLL_DIR_TYPE ( _p.get_sec_poll_dir_types() ); - descent_p.set_HALTON_SEED ( _p.get_halton_seed() ); - descent_p.set_SEED ( _p.get_seed() ); - - descent_p.set_LH_SEARCH ( 0 , 0 ); - - int bbe = stats.get_bb_eval(); - int sgte_eval = stats.get_sgte_eval(); - - { - int p_max_bbe = _p.get_max_bb_eval(); - if ( p_max_bbe > 0 ) - descent_p.set_MAX_BB_EVAL ( p_max_bbe - bbe ); - - int p_max_sgte_eval = _p.get_max_sgte_eval(); - if ( p_max_sgte_eval > 0 ) - descent_p.set_MAX_SGTE_EVAL ( p_max_sgte_eval - sgte_eval ); - - int p_max_eval = _p.get_max_eval(); - if ( p_max_eval > 0 ) - descent_p.set_MAX_EVAL ( p_max_eval - stats.get_eval() ); - - int p_max_sbe = _p.get_max_sim_bb_eval(); - if ( p_max_sbe > 0 ) - descent_p.set_MAX_SIM_BB_EVAL ( p_max_sbe - stats.get_sim_bb_eval() ); - - int p_max_time = _p.get_max_time(); - if ( p_max_time > 0 ) - descent_p.set_MAX_TIME ( p_max_time - stats.get_real_time() ); - - NOMAD::Double p_sst = _p.get_stat_sum_target(); - if ( p_sst.is_defined() ) - descent_p.set_STAT_SUM_TARGET ( p_sst - stats.get_stat_sum() ); - } - - descent_p.set_OPPORTUNISTIC_EVAL ( _p.get_opportunistic_eval() ); - descent_p.set_BB_INPUT_INCLUDE_SEED ( _p.get_bb_input_include_seed() ); - descent_p.set_BB_INPUT_INCLUDE_TAG ( _p.get_bb_input_include_tag() ); - descent_p.set_BB_REDIRECTION ( _p.get_bb_redirection() ); - - descent_p.set_EXTENDED_POLL_ENABLED ( false ); - descent_p.set_USER_CALLS_ENABLED ( false ); - - descent_p.set_H_MAX_0 ( _p.get_h_max_0() ); - descent_p.set_H_MIN ( _p.get_h_min() ); - descent_p.set_H_NORM ( _p.get_h_norm() ); - descent_p.set_RHO ( _p.get_rho() ); - descent_p.set_SNAP_TO_BOUNDS ( _p.get_snap_to_bounds() ); - descent_p.set_MAX_CACHE_MEMORY ( _p.get_max_cache_memory() ); - descent_p.set_SPECULATIVE_SEARCH ( _p.get_speculative_search() ); - descent_p.set_OPPORTUNISTIC_LUCKY_EVAL ( _p.get_opportunistic_lucky_eval() ); - descent_p.set_OPPORTUNISTIC_MIN_EVAL ( _p.get_opportunistic_min_eval() ); - descent_p.set_OPPORTUNISTIC_MIN_F_IMPRVMT ( _p.get_opportunistic_min_f_imprvmt() ); - descent_p.set_OPPORTUNISTIC_MIN_NB_SUCCESS ( _p.get_opportunistic_min_nb_success() ); - - descent_p.set_CACHE_FILE ( _p.get_cache_file() ); - descent_p.set_SGTE_CACHE_FILE ( _p.get_sgte_cache_file() ); - descent_p.set_CACHE_SAVE_PERIOD ( _p.get_cache_save_period() ); - - descent_p.set_ADD_SEED_TO_FILE_NAMES ( _p.get_add_seed_to_file_names() ); - - descent_p.set_DISPLAY_ALL_EVAL(_p.get_display_all_eval()); - if ( _p.out().get_poll_dd() == NOMAD::FULL_DISPLAY ) - descent_p.set_DISPLAY_DEGREE ( NOMAD::NORMAL_DISPLAY ); - else if (_p.out().get_poll_dd() == NOMAD::NORMAL_DISPLAY ) - descent_p.set_DISPLAY_DEGREE ( NOMAD::MINIMAL_DISPLAY ); - else - descent_p.set_DISPLAY_DEGREE ( _p.out().get_poll_dd()); - - if ( has_sgte ) - descent_p.set_DISPLAY_STATS ( NOMAD::itos(sgte_eval) + "+SGTE OBJ (ExtendedPoll---surrogate)" ); - else - { - std::list<std::string> ds = _p.get_display_stats(); - std::list<std::string>::iterator it = ds.begin(); - std::list<std::string>::const_iterator end = ds.end(); - std::string s_bbe = NOMAD::itos(bbe) + "+"; - while ( it != end ) - { - if (*it == "BBE") - ds.insert ( it , s_bbe ); - ++it; - } - ds.push_back ( " (ExtendedPoll)" ); - descent_p.set_DISPLAY_STATS ( ds ); - } - - // STATS_FILE: - if ( has_sgte ) - descent_p.set_STATS_FILE ( _p.get_stats_file_name() , NOMAD::itos(sgte_eval) + "+SGTE OBJ (ExtendedPoll---surrogate)" ); - else - { - std::list<std::string> sf = _p.get_stats_file(); - std::list<std::string>::iterator it = sf.begin(); - std::list<std::string>::const_iterator end = sf.end(); - std::string s_bbe = NOMAD::itos(bbe) + "+"; - while ( it != end ) - { - if ( *it == "BBE" ) - sf.insert ( it , s_bbe ); - ++it; - } - sf.push_back ( " (ExtendedPoll)" ); - descent_p.set_STATS_FILE ( _p.get_stats_file_name() , sf ); - } - - // Mesh: - { - const Mesh & mesh = epc_signature->get_mesh(); - descent_p.set_MIN_MESH_SIZE ( mesh.get_min_mesh_size() ); - descent_p.set_MIN_POLL_SIZE ( mesh.get_min_poll_size() ); - int ell = NOMAD::Mesh::get_mesh_index(); - descent_p.set_INITIAL_MESH_INDEX ( ell ); - descent_p.set_MAX_MESH_INDEX ( ell ); - descent_p.set_INITIAL_MESH_SIZE ( mesh.get_initial_mesh_size() , false ); - - - } - - // check the parameters: - try - { - descent_p.check ( false , // remove_history_file = false - false , // remove_solution_file = false - false ); // remove_stats_file = false - } - catch ( NOMAD::Exception & e ) - { - std::ostringstream err; - err << "-- " << e.what(); - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err.str() ); - } + + // extended poll center signature + // (will be the temporary standard signature): + NOMAD::Signature * epc_signature = y->get_signature(); + if ( !epc_signature ) + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , + "Extended_Poll::set_descent_parameters(): ext. poll center has no signature" ); + + // we set all the parameters: + descent_p.set_DIMENSION ( epc_signature->get_n() ); + descent_p.set_BB_INPUT_TYPE ( epc_signature->get_input_types() ); + descent_p.set_LOWER_BOUND ( epc_signature->get_lb() ); + descent_p.set_UPPER_BOUND ( epc_signature->get_ub() ); + descent_p.set_FIXED_VARIABLE ( epc_signature->get_fixed_variables() ); + descent_p.set_PERIODIC_VARIABLE ( epc_signature->get_periodic_variables() ); + descent_p.set_VARIABLE_GROUP ( epc_signature->get_var_groups() ); + descent_p.set_BB_OUTPUT_TYPE ( _p.get_bb_output_type() ); + descent_p.set_DIRECTION_TYPE ( _p.get_direction_types() ); + descent_p.set_SEC_POLL_DIR_TYPE ( _p.get_sec_poll_dir_types() ); + + + { + const std::list<std::string> & bb_exe = _p.get_bb_exe(); + descent_p.set_BB_EXE ( bb_exe ); + std::list<std::string>::const_iterator it , end = bb_exe.end(); + for ( it = bb_exe.begin() ; it != end ; ++it ) + descent_p.set_SGTE_EXE ( *it , _p.get_sgte_exe ( *it ) ); + } + + descent_p.set_PROBLEM_DIR ( _p.get_problem_dir() ); + descent_p.set_TMP_DIR ( _p.get_tmp_dir() ); + descent_p.set_SGTE_COST ( _p.get_sgte_cost() ); + descent_p.set_SGTE_EVAL_SORT ( _p.get_sgte_eval_sort() ); + descent_p.set_X0 ( *y ); + + bool has_sgte = _p.has_sgte(); + if ( has_sgte ) + { + descent_p.reset_f_target(); + descent_p.set_HAS_SGTE ( true ); + descent_p.set_OPT_ONLY_SGTE ( true ); + descent_p.set_STOP_IF_FEASIBLE ( false ); + descent_p.set_MODEL_SEARCH ( false ); + descent_p.set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); + } + else + { + descent_p.set_F_TARGET ( _p.get_f_target() ); + descent_p.set_STOP_IF_FEASIBLE ( _p.get_stop_if_feasible() ); + descent_p.set_MODEL_EVAL_SORT ( _p.get_model_eval_sort()); + descent_p.set_MODEL_SEARCH (_p.has_model_search()); + + + } + + descent_p.set_LH_SEARCH ( 0 , 0 ); + + int bbe = stats.get_bb_eval(); + int sgte_eval = stats.get_sgte_eval(); + + { + int p_max_bbe = _p.get_max_bb_eval(); + if ( p_max_bbe > 0 ) + descent_p.set_MAX_BB_EVAL ( p_max_bbe - bbe ); + + int p_max_sgte_eval = _p.get_max_sgte_eval(); + if ( p_max_sgte_eval > 0 ) + descent_p.set_MAX_SGTE_EVAL ( p_max_sgte_eval - sgte_eval ); + + int p_max_eval = _p.get_max_eval(); + if ( p_max_eval > 0 ) + descent_p.set_MAX_EVAL ( p_max_eval - stats.get_eval() ); + + int p_max_sbe = _p.get_max_sim_bb_eval(); + if ( p_max_sbe > 0 ) + descent_p.set_MAX_SIM_BB_EVAL ( p_max_sbe - stats.get_sim_bb_eval() ); + + int p_max_time = _p.get_max_time(); + if ( p_max_time > 0 ) + descent_p.set_MAX_TIME ( p_max_time - stats.get_real_time() ); + + NOMAD::Double p_sst = _p.get_stat_sum_target(); + if ( p_sst.is_defined() ) + descent_p.set_STAT_SUM_TARGET ( p_sst - stats.get_stat_sum() ); + } + + descent_p.set_OPPORTUNISTIC_EVAL ( _p.get_opportunistic_eval() ); + descent_p.set_BB_INPUT_INCLUDE_SEED ( _p.get_bb_input_include_seed() ); + descent_p.set_BB_INPUT_INCLUDE_TAG ( _p.get_bb_input_include_tag() ); + descent_p.set_BB_REDIRECTION ( _p.get_bb_redirection() ); + + descent_p.set_EXTENDED_POLL_ENABLED ( false ); + descent_p.set_USER_CALLS_ENABLED ( false ); + + descent_p.set_H_MAX_0 ( _p.get_h_max_0() ); + descent_p.set_H_MIN ( _p.get_h_min() ); + descent_p.set_H_NORM ( _p.get_h_norm() ); + descent_p.set_RHO ( _p.get_rho() ); + descent_p.set_SNAP_TO_BOUNDS ( _p.get_snap_to_bounds() ); + descent_p.set_MAX_CACHE_MEMORY ( _p.get_max_cache_memory() ); + descent_p.set_SPECULATIVE_SEARCH ( _p.get_speculative_search() ); + descent_p.set_OPPORTUNISTIC_LUCKY_EVAL ( _p.get_opportunistic_lucky_eval() ); + descent_p.set_OPPORTUNISTIC_MIN_EVAL ( _p.get_opportunistic_min_eval() ); + descent_p.set_OPPORTUNISTIC_MIN_F_IMPRVMT ( _p.get_opportunistic_min_f_imprvmt() ); + descent_p.set_OPPORTUNISTIC_MIN_NB_SUCCESS ( _p.get_opportunistic_min_nb_success() ); + + if (_p.eval_points_as_block()) + descent_p.set_BB_MAX_BLOCK_SIZE( _p.get_bb_max_block_size() ); + + + descent_p.set_CACHE_FILE ( _p.get_cache_file() ); + descent_p.set_SGTE_CACHE_FILE ( _p.get_sgte_cache_file() ); + descent_p.set_CACHE_SAVE_PERIOD ( _p.get_cache_save_period() ); + + descent_p.set_ADD_SEED_TO_FILE_NAMES ( _p.get_add_seed_to_file_names() ); + + descent_p.set_DISPLAY_ALL_EVAL(_p.get_display_all_eval()); + if ( _p.out().get_poll_dd() == NOMAD::FULL_DISPLAY ) + descent_p.set_DISPLAY_DEGREE ( NOMAD::NORMAL_DISPLAY ); + else if (_p.out().get_poll_dd() == NOMAD::NORMAL_DISPLAY ) + descent_p.set_DISPLAY_DEGREE ( NOMAD::MINIMAL_DISPLAY ); + else + descent_p.set_DISPLAY_DEGREE ( _p.out().get_poll_dd()); + + // Stats style modified + if ( has_sgte ) + descent_p.set_DISPLAY_STATS ( NOMAD::itos(sgte_eval) + "+SGTE OBJ (ExtendedPoll---surrogate)" ); + else + { + std::list<std::string> ds = _p.get_display_stats(); + std::list<std::string>::iterator it = ds.begin(); + std::list<std::string>::const_iterator end = ds.end(); + std::string s_bbe = NOMAD::itos(bbe) + "+"; + while ( it != end ) + { + if (*it == "BBE") + ds.insert ( it , s_bbe ); + ++it; + } + ds.push_back ( " (ExtendedPoll)" ); + descent_p.set_DISPLAY_STATS ( ds ); + } + + // STATS_FILE: + if ( has_sgte ) + descent_p.set_STATS_FILE ( _p.get_stats_file_name() , NOMAD::itos(sgte_eval) + "+SGTE OBJ (ExtendedPoll---surrogate)" ); + else + { + std::list<std::string> sf = _p.get_stats_file(); + std::list<std::string>::iterator it = sf.begin(); + std::list<std::string>::const_iterator end = sf.end(); + std::string s_bbe = NOMAD::itos(bbe) + "+"; + while ( it != end ) + { + if ( *it == "BBE" ) + sf.insert ( it , s_bbe ); + ++it; + } + sf.push_back ( " (ExtendedPoll)" ); + descent_p.set_STATS_FILE ( _p.get_stats_file_name() , sf ); + } + + // Mesh: + { + const OrthogonalMesh * mesh = epc_signature->get_mesh(); + descent_p.set_MIN_MESH_SIZE ( mesh->get_min_mesh_size() ); + descent_p.set_MIN_POLL_SIZE ( mesh->get_min_poll_size() ); + descent_p.set_INITIAL_POLL_SIZE ( mesh->get_initial_poll_size() , false ); + + } + + // check the parameters: + try + { + descent_p.check ( false , // remove_history_file = false + false , // remove_solution_file = false + false ); // remove_stats_file = false + } + catch ( NOMAD::Exception & e ) + { + std::ostringstream err; + err << "-- " << e.what(); + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err.str() ); + } + } /*----------------------------------------------------------------*/ @@ -677,270 +712,270 @@ const NOMAD::Eval_Point * NOMAD::Extended_Poll::eval_epp const NOMAD::Eval_Point *& new_feas_inc , const NOMAD::Eval_Point *& new_infeas_inc ) const { - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_poll_dd(); - - // initial display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - out << std::endl << NOMAD::open_block ( "extended poll point eval" ) << std::endl - << "extended poll point = ( "; - y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " )" << std::endl; - } - - // add the eval point to the evaluator control: - ev_control.add_eval_point ( y , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - - // get the stats: - NOMAD::Stats & stats = mads.get_stats(); - int old_bbe = stats.get_bb_eval(); - - // eval list of points: - new_feas_inc = new_infeas_inc = NULL; - std::list<const NOMAD::Eval_Point *> evaluated_pts; - - ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , - mads.get_true_barrier() , - mads.get_sgte_barrier() , - mads.get_pareto_front() , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success , - &evaluated_pts ); - - // update the number of extended poll blackbox evaluations: - stats.add_ext_poll_bb_eval ( stats.get_bb_eval() - old_bbe ); - - // final display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::close_block() << std::endl; - - // return the evaluated point: - return ( evaluated_pts.size() != 1 ) ? NULL : *evaluated_pts.begin(); + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_poll_dd(); + + // initial display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << std::endl << NOMAD::open_block ( "extended poll point eval" ) << std::endl + << "extended poll point = ( "; + y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " )" << std::endl; + } + + // add the eval point to the evaluator control: + ev_control.add_eval_point ( y , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + + // get the stats: + NOMAD::Stats & stats = mads.get_stats(); + int old_bbe = stats.get_bb_eval(); + + // eval list of points: + new_feas_inc = new_infeas_inc = NULL; + std::list<const NOMAD::Eval_Point *> evaluated_pts; + + ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , + mads.get_true_barrier() , + mads.get_sgte_barrier() , + mads.get_pareto_front() , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success , + &evaluated_pts ); + + // update the number of extended poll blackbox evaluations: + stats.add_ext_poll_bb_eval ( stats.get_bb_eval() - old_bbe ); + + // final display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::close_block() << std::endl; + + // return the evaluated point: + return ( evaluated_pts.size() != 1 ) ? NULL : *evaluated_pts.begin(); } /*-----------------------------------------*/ /* run the extended poll */ /*-----------------------------------------*/ void NOMAD::Extended_Poll::run ( Mads & mads , - int & nb_ext_poll_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_ext_poll_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - nb_ext_poll_pts = 0; - success = NOMAD::UNSUCCESSFUL; - new_feas_inc = new_infeas_inc = NULL; - - if ( stop || _extended_points.empty() ) - return; - - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_poll_dd(); - NOMAD::Eval_Point * cur; - - // phase 1: evaluate the extended poll points in order to sort them - // -------- (based on the surrogates or on the true function): - if ( _extended_points.size() > 1 ) - { - - bool has_sgte = _p.has_sgte(); - bool old_sgte_eval_sort = _p.get_sgte_eval_sort(); - - // phase 1 initial display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << "extended poll pts sorting"; - if ( has_sgte ) - oss << " (on surrogates)"; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - if ( has_sgte ) { - _p.set_SGTE_EVAL_SORT ( false ); // this ensures that only surrogate - _p.force_check_flag(); // evaluations are performed - } - - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // loop on the extended poll points: - std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); - for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; - it != end ; ++it ) - { - cur = *it; - - if ( has_sgte ) - cur->set_eval_type ( NOMAD::SGTE ); - - ev_control.add_eval_point ( cur , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } - - _extended_points.clear(); - - // get the stats: - NOMAD::Stats & stats = mads.get_stats(); - int old_bbe = stats.get_bb_eval(); - - // number of eval points: - nb_ext_poll_pts = ev_control.get_nb_eval_points(); - - // eval list of points: - new_feas_inc = new_infeas_inc = NULL; - std::list<const NOMAD::Eval_Point *> evaluated_pts; - - ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , - mads.get_true_barrier() , - mads.get_sgte_barrier() , - mads.get_pareto_front() , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success , - &evaluated_pts ); - if ( has_sgte ) - { - if ( !_p.get_opt_only_sgte() ) { - success = NOMAD::UNSUCCESSFUL; - new_feas_inc = new_infeas_inc = NULL; - } - _p.set_SGTE_EVAL_SORT ( old_sgte_eval_sort ); - _p.force_check_flag(); - } - - // update the number of extended poll blackbox evaluations: - stats.add_ext_poll_bb_eval ( stats.get_bb_eval() - old_bbe ); - - // sort the evaluated extended poll points: - if ( success != NOMAD::FULL_SUCCESS ) - sort_epp ( evaluated_pts ); - - // the extended poll is terminated in case of success: - if ( stop || success == NOMAD::FULL_SUCCESS || new_feas_inc || new_infeas_inc ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl - << NOMAD::close_block ( "end of ext poll pts sorting (success)" ) - << std::endl; - return; - } - - // phase 1 final display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << "end of ext poll pts sorting"; - if ( has_sgte ) - oss << " (on surrogates)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - - } // end of phase 1 + nb_ext_poll_pts = 0; + success = NOMAD::UNSUCCESSFUL; + new_feas_inc = new_infeas_inc = NULL; + + if ( stop || _extended_points.empty() ) + return; + + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_poll_dd(); + NOMAD::Eval_Point * cur; + + // phase 1: evaluate the extended poll points in order to sort them + // -------- (based on the surrogates or on the true function): + if ( _extended_points.size() > 1 ) + { + + bool has_sgte = _p.has_sgte(); + bool old_sgte_eval_sort = _p.get_sgte_eval_sort(); + + // phase 1 initial display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "extended poll pts sorting"; + if ( has_sgte ) + oss << " (on surrogates)"; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + if ( has_sgte ) { + _p.set_SGTE_EVAL_SORT ( false ); // this ensures that only surrogate + _p.force_check_flag(); // evaluations are performed + } + + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // loop on the extended poll points: + std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); + for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; + it != end ; ++it ) + { + cur = *it; + + if ( has_sgte ) + cur->set_eval_type ( NOMAD::SGTE ); + + ev_control.add_eval_point ( cur , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + } + + _extended_points.clear(); + + // get the stats: + NOMAD::Stats & stats = mads.get_stats(); + int old_bbe = stats.get_bb_eval(); + + // number of eval points: + nb_ext_poll_pts = ev_control.get_nb_eval_points(); + + // eval list of points: + new_feas_inc = new_infeas_inc = NULL; + std::list<const NOMAD::Eval_Point *> evaluated_pts; + + ev_control.eval_list_of_points ( NOMAD::EXTENDED_POLL , + mads.get_true_barrier() , + mads.get_sgte_barrier() , + mads.get_pareto_front() , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success , + &evaluated_pts ); + if ( has_sgte ) + { + if ( !_p.get_opt_only_sgte() ) { + success = NOMAD::UNSUCCESSFUL; + new_feas_inc = new_infeas_inc = NULL; + } + _p.set_SGTE_EVAL_SORT ( old_sgte_eval_sort ); + _p.force_check_flag(); + } + + // update the number of extended poll blackbox evaluations: + stats.add_ext_poll_bb_eval ( stats.get_bb_eval() - old_bbe ); + + // sort the evaluated extended poll points: + if ( success != NOMAD::FULL_SUCCESS ) + sort_epp ( evaluated_pts ); + + // the extended poll is terminated in case of success: + if ( stop || success == NOMAD::FULL_SUCCESS || new_feas_inc || new_infeas_inc ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl + << NOMAD::close_block ( "end of ext poll pts sorting (success)" ) + << std::endl; + return; + } + + // phase 1 final display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of ext poll pts sorting"; + if ( has_sgte ) + oss << " (on surrogates)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + + } // end of phase 1 + // -------------- + + /*--------------------------------------------------------------*/ + + // phase 2: execute the extended poll for each extended point: + // -------- + { + const NOMAD::Eval_Point * old_bf = mads.get_best_feasible(); + const NOMAD::Eval_Point * old_bi = mads.get_best_infeasible(); + const NOMAD::Eval_Point * y; + + while ( !_extended_points.empty() ) + { + + cur = *_extended_points.begin(); + + // the point has already been evaluated during + // the extended poll points sorting: + if ( cur->is_in_cache() && cur->get_eval_type() == NOMAD::TRUTH ) + y = cur; + + // the point has to be evaluated: + else + { + + y = eval_epp ( cur , + mads , + stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc ); + + ++nb_ext_poll_pts; + + // the extended poll is terminated in case of success: + if ( !y || + stop || + success == NOMAD::FULL_SUCCESS || + new_feas_inc || + new_infeas_inc ) + break; + } + + _extended_points.pop_front(); + + // perform the extended poll descent ? + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << std::endl + << "extended poll center: ( "; + y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " )" << std::endl << std::endl + << "perform extended poll descent ..."; + } + if ( check_trigger ( old_bf , old_bi , y ) ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "... yes" << std::endl; + descent ( y , + mads , + nb_ext_poll_pts , + stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc ); + + // the extended poll is terminated in case of success: + if ( stop || success == NOMAD::FULL_SUCCESS || new_feas_inc || new_infeas_inc ) + break; + } + else if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "... no" << std::endl; + } + } // end of phase 2 // -------------- - - /*--------------------------------------------------------------*/ - - // phase 2: execute the extended poll for each extended point: - // -------- - { - const NOMAD::Eval_Point * old_bf = mads.get_best_feasible(); - const NOMAD::Eval_Point * old_bi = mads.get_best_infeasible(); - const NOMAD::Eval_Point * y; - - while ( !_extended_points.empty() ) - { - - cur = *_extended_points.begin(); - - // the point has already been evaluated during - // the extended poll points sorting: - if ( cur->is_in_cache() && cur->get_eval_type() == NOMAD::TRUTH ) - y = cur; - - // the point has to be evaluated: - else - { - - y = eval_epp ( cur , - mads , - stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc ); - - ++nb_ext_poll_pts; - - // the extended poll is terminated in case of success: - if ( !y || - stop || - success == NOMAD::FULL_SUCCESS || - new_feas_inc || - new_infeas_inc ) - break; - } - - _extended_points.pop_front(); - - // perform the extended poll descent ? - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - out << std::endl - << "extended poll center: ( "; - y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " )" << std::endl << std::endl - << "perform extended poll descent ..."; - } - if ( check_trigger ( old_bf , old_bi , y ) ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "... yes" << std::endl; - descent ( y , - mads , - nb_ext_poll_pts , - stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc ); - - // the extended poll is terminated in case of success: - if ( stop || success == NOMAD::FULL_SUCCESS || new_feas_inc || new_infeas_inc ) - break; - } - else if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "... no" << std::endl; - } - } // end of phase 2 - // -------------- - - // clean the extended points that have not been considered: - std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); - for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; - it != end ; ++it ) - if ( !(*it)->is_in_cache() ) - delete *it; - _extended_points.clear(); + + // clean the extended points that have not been considered: + std::list<NOMAD::Eval_Point *>::const_iterator end = _extended_points.end(); + for ( std::list<NOMAD::Eval_Point *>::iterator it = _extended_points.begin() ; + it != end ; ++it ) + if ( !(*it)->is_in_cache() ) + delete *it; + _extended_points.clear(); } /*----------------------------------------------------------------*/ @@ -950,71 +985,70 @@ void NOMAD::Extended_Poll::run ( Mads & mads , void NOMAD::Extended_Poll::sort_epp ( const std::list<const NOMAD::Eval_Point *> & evaluated_pts ) { - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_poll_dd(); - const NOMAD::Double & h_min = _p.get_h_min(); - std::set<NOMAD::Priority_Eval_Point> sorted_pts; - - // 1. loop on the evaluated points: - std::list<const NOMAD::Eval_Point *>::const_iterator it1 , end1 = evaluated_pts.end(); - for ( it1 = evaluated_pts.begin() ; it1 != end1 ; ++it1 ) - { - - // creation of a Priority_Eval_Point: - NOMAD::Priority_Eval_Point pep ( *it1 , h_min ); - - // surrogate values for f and h: - if ( (*it1)->get_eval_type() == NOMAD::SGTE ) - { - pep.set_f_sgte ( (*it1)->get_f() ); - pep.set_h_sgte ( (*it1)->get_h() ); - } - - // insertion in the sorted list of points: - sorted_pts.insert ( pep ); - } - - // 2. loop on the sorted points: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "sorted ext poll pts" ) << std::endl; - - const NOMAD::Eval_Point * cur; - NOMAD::Eval_Point * y; - int i = 0 , nb_pts = static_cast<int> ( sorted_pts.size() ); - std::set<NOMAD::Priority_Eval_Point>::const_iterator + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_poll_dd(); + const NOMAD::Double & h_min = _p.get_h_min(); + std::set<NOMAD::Priority_Eval_Point> sorted_pts; + + // 1. loop on the evaluated points: + std::list<const NOMAD::Eval_Point *>::const_iterator it1 , end1 = evaluated_pts.end(); + for ( it1 = evaluated_pts.begin() ; it1 != end1 ; ++it1 ) + { + + // creation of a Priority_Eval_Point: + NOMAD::Priority_Eval_Point pep ( *it1 , h_min ); + + // surrogate values for f and h: + if ( (*it1)->get_eval_type() == NOMAD::SGTE ) + { + pep.set_f_sgte ( (*it1)->get_f() ); + pep.set_h_sgte ( (*it1)->get_h() ); + } + + // insertion in the sorted list of points: + sorted_pts.insert ( pep ); + } + + // 2. loop on the sorted points: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::open_block ( "sorted ext poll pts" ) << std::endl; + + const NOMAD::Eval_Point * cur; + NOMAD::Eval_Point * y; + int i = 0 , nb_pts = static_cast<int> ( sorted_pts.size() ); + std::set<NOMAD::Priority_Eval_Point>::const_iterator it2 , end2 = sorted_pts.end(); - - for ( it2 = sorted_pts.begin() ; it2 != end2 ; ++it2 ) - { - - // we copy y=cur an create a new Eval_Point because cur can be a surrogate - // point already in the surrogate cache - - cur = (*it2).get_point(); - - y = new NOMAD::Eval_Point; - y->set ( cur->size() , _p.get_bb_nb_outputs() ); - y->set_signature ( cur->get_signature () ); - y->set_direction ( cur->get_direction () ); - y->set_mesh_index ( cur->get_mesh_index() ); - y->Point::operator = ( *cur ); - - // display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - out << "point #"; - out.display_int_w ( ++i , nb_pts ); - out << "/" << nb_pts << " : ( "; - y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " )" << std::endl; - } - - // insertion in _extended_points: - _extended_points.push_back ( y ); - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::close_block() << std::endl; + + for ( it2 = sorted_pts.begin() ; it2 != end2 ; ++it2 ) + { + + // we copy y=cur an create a new Eval_Point because cur can be a surrogate + // point already in the surrogate cache + + cur = (*it2).get_point(); + + y = new NOMAD::Eval_Point; + y->set ( cur->size() , _p.get_bb_nb_outputs() ); + y->set_signature ( cur->get_signature () ); + y->set_direction ( cur->get_direction () ); + y->Point::operator = ( *cur ); + + // display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << "point #"; + out.display_int_w ( ++i , nb_pts ); + out << "/" << nb_pts << " : ( "; + y->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " )" << std::endl; + } + + // insertion in _extended_points: + _extended_points.push_back ( y ); + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::close_block() << std::endl; } /*--------------------------------------------------------------------*/ @@ -1022,67 +1056,67 @@ void NOMAD::Extended_Poll::sort_epp /*--------------------------------------------------------------------*/ bool NOMAD::Extended_Poll::set_neighbors_exe ( std::string & error_str ) { - error_str.clear(); - - _neighbors_exe = _p.get_neighbors_exe(); - - if ( _neighbors_exe.empty() ) { - error_str = "categorical variables: parameter NEIGHBORS_EXE is undefined"; - return false; - } - - const std::string problem_dir = _p.get_problem_dir(); - - std::list<std::string> neighbors_exe_words; - NOMAD::get_words ( _neighbors_exe , neighbors_exe_words ); - - // _neighbors_exe is composed of several words (it is a command): - if ( neighbors_exe_words.size() > 1 ) - { - - _neighbors_exe.clear(); - - std::list<std::string>::const_iterator it = neighbors_exe_words.begin() , - end = neighbors_exe_words.end(); - while (true) { - - if ( (*it)[0] != '$' ) { - _neighbors_exe += "\"" + problem_dir; - _neighbors_exe += *it + "\""; - } - else - _neighbors_exe += it->substr ( 1 , it->size()-1 ); - - ++it; - - if ( it == end ) - break; - - _neighbors_exe += " "; - } - } - - // _neighbors_exe is just composed of one name (it is an executable): - else - { - - if ( _neighbors_exe[0] != '$' ) - _neighbors_exe = problem_dir + _neighbors_exe; - else - _neighbors_exe = _neighbors_exe.substr ( 1 , _neighbors_exe.size()-1 ); - - if ( !NOMAD::check_exe_file ( _neighbors_exe ) ) - { - error_str = "categorical variables: \'" + _neighbors_exe - + "\' is not a valid executable file"; - return false; - } - - if ( _neighbors_exe[0] != '$' ) - _neighbors_exe = "\"" + _neighbors_exe + "\""; - } - - return true; + error_str.clear(); + + _neighbors_exe = _p.get_neighbors_exe(); + + if ( _neighbors_exe.empty() ) { + error_str = "categorical variables: parameter NEIGHBORS_EXE is undefined"; + return false; + } + + const std::string problem_dir = _p.get_problem_dir(); + + std::list<std::string> neighbors_exe_words; + NOMAD::get_words ( _neighbors_exe , neighbors_exe_words ); + + // _neighbors_exe is composed of several words (it is a command): + if ( neighbors_exe_words.size() > 1 ) + { + + _neighbors_exe.clear(); + + std::list<std::string>::const_iterator it = neighbors_exe_words.begin() , + end = neighbors_exe_words.end(); + while (true) { + + if ( (*it)[0] != '$' ) { + _neighbors_exe += "\"" + problem_dir; + _neighbors_exe += *it + "\""; + } + else + _neighbors_exe += it->substr ( 1 , it->size()-1 ); + + ++it; + + if ( it == end ) + break; + + _neighbors_exe += " "; + } + } + + // _neighbors_exe is just composed of one name (it is an executable): + else + { + + if ( _neighbors_exe[0] != '$' ) + _neighbors_exe = problem_dir + _neighbors_exe; + else + _neighbors_exe = _neighbors_exe.substr ( 1 , _neighbors_exe.size()-1 ); + + if ( !NOMAD::check_exe_file ( _neighbors_exe ) ) + { + error_str = "categorical variables: \'" + _neighbors_exe + + "\' is not a valid executable file"; + return false; + } + + if ( _neighbors_exe[0] != '$' ) + _neighbors_exe = "\"" + _neighbors_exe + "\""; + } + + return true; } /*----------------------------------------------------------------------*/ @@ -1092,130 +1126,130 @@ bool NOMAD::Extended_Poll::set_neighbors_exe ( std::string & error_str ) /*----------------------------------------------------------------------*/ void NOMAD::Extended_Poll::construct_extended_points ( const NOMAD::Eval_Point & xk ) { - if ( _neighbors_exe.empty() ) - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , - "NOMAD::Extended_Poll::construct_extended_points(): no NEIGHBORS_EXE executable (batch mode) or no subclass implementation of the method (library mode)" ); - - if ( !xk.is_complete() ) - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , - "NOMAD::Extended_Poll::construct_extended_points(): bad extended poll center"); - - NOMAD::Signature * signature = _p.get_signature(); - if ( !signature ) - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , - "NOMAD::Extended_Poll::construct_extended_points(): no signature" ); - - std::string tmp_dir = _p.get_tmp_dir(); - - std::ostringstream oss; - oss << "." << _p.get_seed() << "." << xk.get_tag() << ".neighbors."; - const std::string & sint = oss.str(); - - // input file writing: - // ------------------- - std::string input_file_name = + if ( _neighbors_exe.empty() ) + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , + "NOMAD::Extended_Poll::construct_extended_points(): no NEIGHBORS_EXE executable (batch mode) or no subclass implementation of the method (library mode)" ); + + if ( !xk.is_complete() ) + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , + "NOMAD::Extended_Poll::construct_extended_points(): bad extended poll center"); + + NOMAD::Signature * signature = _p.get_signature(); + if ( !signature ) + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , + "NOMAD::Extended_Poll::construct_extended_points(): no signature" ); + + std::string tmp_dir = _p.get_tmp_dir(); + + std::ostringstream oss; + oss << "." << _p.get_seed() << "." << xk.get_tag() << ".neighbors."; + const std::string & sint = oss.str(); + + // input file writing: + // ------------------- + std::string input_file_name = tmp_dir + NOMAD::BLACKBOX_INPUT_FILE_PREFIX + sint + NOMAD::BLACKBOX_INPUT_FILE_EXT; - - std::string output_file_name = + + std::string output_file_name = tmp_dir + NOMAD::BLACKBOX_OUTPUT_FILE_PREFIX + sint + NOMAD::BLACKBOX_OUTPUT_FILE_EXT; - - std::ofstream fout ( input_file_name.c_str() ); - if ( fout.fail() ) - { - remove ( input_file_name.c_str () ); - std::string err = "could not open file neighbors input file " + input_file_name; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - - fout.setf ( std::ios::fixed ); - fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); - xk.Point::display ( fout , " " , -1 , -1 ); - fout << std::endl; - - fout.close(); - - if ( fout.fail() ) - { - remove ( input_file_name.c_str () ); - std::string err = "could not write file neighbors input file " + input_file_name; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - - // system call to get the neighbors: - // --------------------------------- - - std::string cmd = _neighbors_exe + " " + input_file_name + " > " + output_file_name; - + + std::ofstream fout ( input_file_name.c_str() ); + if ( fout.fail() ) + { + remove ( input_file_name.c_str () ); + std::string err = "could not open file neighbors input file " + input_file_name; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + + fout.setf ( std::ios::fixed ); + fout.precision ( NOMAD::DISPLAY_PRECISION_BB ); + xk.Point::display ( fout , " " , -1 , -1 ); + fout << std::endl; + + fout.close(); + + if ( fout.fail() ) + { + remove ( input_file_name.c_str () ); + std::string err = "could not write file neighbors input file " + input_file_name; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + + // system call to get the neighbors: + // --------------------------------- + + std::string cmd = _neighbors_exe + " " + input_file_name + " > " + output_file_name; + #ifdef DEBUG #ifdef USE_MPI - int rank; - MPI_Comm_rank ( MPI_COMM_WORLD, &rank); - _p.out() << "command(rank=" << rank - << ") = \'" << cmd << "\'" << std::endl; + int rank; + MPI_Comm_rank ( MPI_COMM_WORLD, &rank); + _p.out() << "command(rank=" << rank + << ") = \'" << cmd << "\'" << std::endl; #else - _p.out() << "command=\'" << cmd << "\'" << std::endl; + _p.out() << "command=\'" << cmd << "\'" << std::endl; #endif #endif - - // the call: - if ( ( system ( cmd.c_str() ) ) != 0 ) - { - remove ( input_file_name.c_str () ); - remove ( output_file_name.c_str() ); - std::string err = "error with command " + cmd; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - - // reading of the output file: - // --------------------------- - - std::ifstream fin ( output_file_name.c_str() ); - - if ( fin.fail() ) - { - remove ( input_file_name.c_str () ); - remove ( output_file_name.c_str() ); - std::string err = "could not open neighbors output file " + output_file_name; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - - int n = xk.size(); - - while ( true ) - { - NOMAD::Point y(n); - try - { - fin >> y; - } - catch ( NOMAD::Point::Bad_Input & ) - { - if ( y.is_defined() ) { - remove ( input_file_name.c_str () ); - remove ( output_file_name.c_str() ); - std::string err = "error with neighbor in file " + output_file_name; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - break; - } - - if ( !y.is_complete() ) - { - remove ( input_file_name.c_str () ); - remove ( output_file_name.c_str() ); - std::string err = "error with neighbor in file " + output_file_name; - throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); - } - - add_extended_poll_point ( y , *signature ); - } - - fin.close(); - - // delete the input and output files: - // ---------------------------------- - remove ( input_file_name.c_str () ); - remove ( output_file_name.c_str() ); + + // the call: + if ( ( system ( cmd.c_str() ) ) != 0 ) + { + remove ( input_file_name.c_str () ); + remove ( output_file_name.c_str() ); + std::string err = "error with command " + cmd; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + + // reading of the output file: + // --------------------------- + + std::ifstream fin ( output_file_name.c_str() ); + + if ( fin.fail() ) + { + remove ( input_file_name.c_str () ); + remove ( output_file_name.c_str() ); + std::string err = "could not open neighbors output file " + output_file_name; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + + int n = xk.size(); + + while ( true ) + { + NOMAD::Point y(n); + try + { + fin >> y; + } + catch ( NOMAD::Point::Bad_Input & ) + { + if ( y.is_defined() ) { + remove ( input_file_name.c_str () ); + remove ( output_file_name.c_str() ); + std::string err = "error with neighbor in file " + output_file_name; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + break; + } + + if ( !y.is_complete() ) + { + remove ( input_file_name.c_str () ); + remove ( output_file_name.c_str() ); + std::string err = "error with neighbor in file " + output_file_name; + throw NOMAD::Exception ( "Extended_Poll.cpp" , __LINE__ , err ); + } + + add_extended_poll_point ( y , *signature ); + } + + fin.close(); + + // delete the input and output files: + // ---------------------------------- + remove ( input_file_name.c_str () ); + remove ( output_file_name.c_str() ); } diff --git a/src/Extended_Poll.hpp b/src/Extended_Poll.hpp index 5f39f1e5bd041f52defcff310d91379c3190723b..55cdae4c83a92656acc2c6527081b9cfbaf8128c 100644 --- a/src/Extended_Poll.hpp +++ b/src/Extended_Poll.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Filter_Point.hpp b/src/Filter_Point.hpp index 81d9858349c26507aa3af7aebe2fc160bbf5b64d..3e74cc433c55df5cf8be3ba9a5dc1df7604859a6 100644 --- a/src/Filter_Point.hpp +++ b/src/Filter_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/LH_Search.cpp b/src/LH_Search.cpp index d9ec06b2060c0a50d5d8324b79e5c70ddcd71d44..43d76d1240a81ece985a8f4de60ec3520f07d18d 100644 --- a/src/LH_Search.cpp +++ b/src/LH_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,221 +34,227 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file LH_Search.cpp - \brief Latin-Hypercube search (implementation) - \author Sebastien Le Digabel - \date 2010-04-09 - \see LH_Search.hpp -*/ + \file LH_Search.cpp + \brief Latin-Hypercube search (implementation) + \author Sebastien Le Digabel + \date 2010-04-09 + \see LH_Search.hpp + */ #include "LH_Search.hpp" /*-----------------------------------------------------------*/ /* MADS Latin-Hypercube (LH) search */ /*-----------------------------------------------------------*/ void NOMAD::LH_Search::search ( NOMAD::Mads & mads , - int & nb_search_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - bool & count_search , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_search_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + bool & count_search , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - new_feas_inc = new_infeas_inc = NULL; - nb_search_pts = 0; - success = NOMAD::UNSUCCESSFUL; - count_search = !stop; - - if ( stop ) - return; - - // initial display: - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << NOMAD::LH_SEARCH; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - // active barrier: - const NOMAD::Barrier & barrier = mads.get_active_barrier(); - - // Evaluator_Control: - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // current incumbents: - const NOMAD::Eval_Point * feas_inc = barrier.get_best_feasible (); - const NOMAD::Eval_Point * infeas_inc = barrier.get_best_infeasible(); - - // get a reference point and a signature: - const NOMAD::Eval_Point * ref = (feas_inc) ? feas_inc : infeas_inc; - NOMAD::Signature * signature = _p.get_signature(); - - // check the number of points: - int p = _initial_search ? _p.get_LH_search_p0() : _p.get_LH_search_pi(); - if ( p <= 0 ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of LH " << ( _initial_search ? "initial " : "") - << "search (number of points <= 0)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + new_feas_inc = new_infeas_inc = NULL; + nb_search_pts = 0; + success = NOMAD::UNSUCCESSFUL; + count_search = !stop; + + if ( stop ) + return; + + // initial display: + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << NOMAD::LH_SEARCH; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; } - return; - } - - // no reference point is available (we consider the standard signature): - if ( !ref ) - { - - // it is not sufficient with categorical variables: - if ( signature->has_categorical() ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << "end of LH " << ( _initial_search ? "initial " : "") - << "search (no available reference point)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - return; + + // active barrier: + const NOMAD::Barrier & barrier = mads.get_active_barrier(); + + // Evaluator_Control: + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // current incumbents: + const NOMAD::Eval_Point * feas_inc = barrier.get_best_feasible (); + const NOMAD::Eval_Point * infeas_inc = barrier.get_best_infeasible(); + + // get a reference point and a signature: + const NOMAD::Eval_Point * ref = (feas_inc) ? feas_inc : infeas_inc; + NOMAD::Signature * signature = _p.get_signature(); + + // check the number of points: + int p = _initial_search ? _p.get_LH_search_p0() : _p.get_LH_search_pi(); + if ( p <= 0 ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of LH " << ( _initial_search ? "initial " : "") + << "search (number of points <= 0)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + return; } - } - else - signature = ref->get_signature(); - - // Change Display stats style - const std::list<std::string> old_ds = _p.get_display_stats(); - std::list<std::string> ds = old_ds; - ds.push_back ( " (LH)" ); - _p.set_DISPLAY_STATS ( ds ); - - // check the parameters: - _p.check ( false , // remove_history_file = false - false , // remove_solution_file = false - false ); // remove_stats_file = false - - int i; - NOMAD::Eval_Point * x; - int n = signature->get_n(); - int m = _p.get_bb_nb_outputs(); - int mesh_index = NOMAD::Mesh::get_mesh_index(); - int pm1 = p-1; - - // mesh sizes: - NOMAD::Point delta_m_max ( n ); - signature->get_mesh().get_delta_m ( delta_m_max , NOMAD::Mesh::get_min_mesh_index() ); - - NOMAD::Double delta_m_i; - NOMAD::Point delta_m; - if ( !_initial_search ) - signature->get_mesh().get_delta_m ( delta_m , mesh_index ); - - // fixed variables: - const NOMAD::Point & fixed_variables = signature->get_fixed_variables(); - - // bb input types: - const std::vector<NOMAD::bb_input_type> & bbit = signature->get_input_types(); - - // bounds: - const NOMAD::Point & lb = signature->get_lb(); - const NOMAD::Point & ub = signature->get_ub(); - - // pts contains n points of dimension p: each of these points contains - // p different values for each variable: - NOMAD::Point ** pts = new NOMAD::Point * [n]; - - // creation of p search points: - for ( int k = 0 ; k < p ; ++k ) { - - x = new NOMAD::Eval_Point ( n , m ); - x->set_signature ( signature ); - x->set_mesh_index ( &mesh_index ); - - for ( i = 0 ; i < n ; ++i ) { - - if ( k==0 ) { - if ( fixed_variables[i].is_defined() ) - pts[i] = new NOMAD::Point ( p , fixed_variables[i] ); - else if ( bbit[i] == NOMAD::CATEGORICAL ) { - pts[i] = new NOMAD::Point ( p , (*ref)[i] ); - } - else { - pts[i] = new NOMAD::Point ( p ); - - // for the initial mesh: delta_m is not used and there will - // be no projection on mesh: - if ( !_initial_search ) - delta_m_i = delta_m[i]; - - values_for_var_i ( p , - delta_m_i , - delta_m_max[i] , - bbit [i] , - lb [i] , - ub [i] , - *pts [i] ); - } - } - - (*x)[i] = (*pts[i])[k]; - - if ( k == pm1 ) - delete pts[i]; + + // no reference point is available (we consider the standard signature): + if ( !ref ) + { + + // it is not sufficient with categorical variables: + if ( signature->has_categorical() ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of LH " << ( _initial_search ? "initial " : "") + << "search (no available reference point)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + return; + } } + else + signature = ref->get_signature(); + + // Change Display stats style + const std::list<std::string> old_ds = _p.get_display_stats(); + std::list<std::string> ds = old_ds; + ds.push_back ( " (LH)" ); + _p.set_DISPLAY_STATS ( ds ); + + // check the parameters: + _p.check ( false , // remove_history_file = false + false , // remove_solution_file = false + false ); // remove_stats_file = false + + int i; + NOMAD::Eval_Point * x; + int n = signature->get_n(); + int m = _p.get_bb_nb_outputs(); + int pm1 = p-1; - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << "LH point #" << x->get_tag() - << ": ( "; - x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; + // mesh sizes: + NOMAD::Point delta_max = signature->get_mesh()->get_delta_max (); + NOMAD::Double delta_i; + NOMAD::Point delta; + if ( !_initial_search ) + signature->get_mesh()->get_delta ( delta ); + + // fixed variables: + const NOMAD::Point & fixed_variables = signature->get_fixed_variables(); + + // bb input types: + const std::vector<NOMAD::bb_input_type> & bbit = signature->get_input_types(); + + // bounds: + const NOMAD::Point & lb = signature->get_lb(); + const NOMAD::Point & ub = signature->get_ub(); + + // pts contains n points of dimension p: each of these points contains + // p different values for each variable: + NOMAD::Point ** pts = new NOMAD::Point * [n]; + + // creation of p search points: + for ( int k = 0 ; k < p ; ++k ) + { + + x = new NOMAD::Eval_Point ( n , m ); + x->set_signature ( signature ); + + for ( i = 0 ; i < n ; ++i ) + { + + if ( k==0 ) + { + if ( fixed_variables[i].is_defined() ) + pts[i] = new NOMAD::Point ( p , fixed_variables[i] ); + else if ( bbit[i] == NOMAD::CATEGORICAL ) + { + pts[i] = new NOMAD::Point ( p , (*ref)[i] ); + } + else + { + pts[i] = new NOMAD::Point ( p ); + + // for the initial mesh: delta is not used and there will + // be no projection on mesh: + if ( !_initial_search ) + delta_i = delta[i]; + + values_for_var_i ( p , + delta_i , + delta_max[i] , + bbit [i] , + lb [i] , + ub [i] , + *pts [i] ); + } + } + + (*x)[i] = (*pts[i])[k]; + + if ( k == pm1 ) + delete pts[i]; + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << "LH point #" << x->get_tag() + << ": ( "; + x->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // add the new point to the ordered list of search trial points: + ev_control.add_eval_point ( x , + display_degree , + false , // snap_to_bounds = false + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); } - - // add the new point to the ordered list of search trial points: - ev_control.add_eval_point ( x , - display_degree , - false , // snap_to_bounds = false - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } - - delete [] pts; - - nb_search_pts = ev_control.get_nb_eval_points(); - - // eval_list_of_points: - // -------------------- - new_feas_inc = new_infeas_inc = NULL; - ev_control.eval_list_of_points ( _type , - mads.get_true_barrier() , - mads.get_sgte_barrier() , - mads.get_pareto_front() , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - - - _p.get_display_stats(); - - // restore stats style - _p.set_DISPLAY_STATS ( old_ds ); - _p.check ( false , // remove_history_file = false - false , // remove_solution_file = false - false ); // remove_stats_file = false - - - - // final displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of LH search (" << success << ")"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - + + delete [] pts; + + nb_search_pts = ev_control.get_nb_eval_points(); + + // eval_list_of_points: + // -------------------- + new_feas_inc = new_infeas_inc = NULL; + ev_control.eval_list_of_points ( _type , + mads.get_true_barrier() , + mads.get_sgte_barrier() , + mads.get_pareto_front() , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + + + _p.get_display_stats(); + + // restore stats style + _p.set_DISPLAY_STATS ( old_ds ); + _p.check ( false , // remove_history_file = false + false , // remove_solution_file = false + false ); // remove_stats_file = false + + + + // final displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of LH search (" << success << ")"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + } /*-----------------------------------------------------------*/ @@ -259,67 +265,69 @@ void NOMAD::LH_Search::search ( NOMAD::Mads & mads , /* . private method */ /*-----------------------------------------------------------*/ void NOMAD::LH_Search::values_for_var_i ( int p , - const NOMAD::Double & delta_m , - const NOMAD::Double & delta_m_max , - const NOMAD::bb_input_type & bbit , - const NOMAD::Double & lb , - const NOMAD::Double & ub , - NOMAD::Point & x ) const + const NOMAD::Double & delta_m , + const NOMAD::Double & delta_m_max , + const NOMAD::bb_input_type & bbit , + const NOMAD::Double & lb , + const NOMAD::Double & ub , + NOMAD::Point & x ) const { - // categorical variables have already been treated as fixed variables: - if ( bbit == NOMAD::CATEGORICAL ) - return; - - int i; - NOMAD::Double v; - NOMAD::Random_Pickup rp (p); - bool rounding = ( bbit != NOMAD::CONTINUOUS ); - bool lb_def = lb.is_defined(); - bool ub_def = ub.is_defined(); - double w = ( ( lb_def && ub_def ) ? - ub.value()-lb.value() : 1.0 ) / p; - // main loop: - for ( i = 0 ; i < p ; ++i ) { - - // both bounds exist: - if ( lb_def && ub_def ) - v = lb + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w; - - // one of the bounds does not exist: - else { - - // lb exists, and ub not: mapping [0;1] --> [lb;+INF[ - if ( lb_def ) - v = lb + 10 * delta_m_max * sqrt ( - log ( NOMAD::DEFAULT_EPSILON + - ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); - - // lb does not exist: - else { - - // ub exists, and lb not: mapping [0;1] --> ]-INF;ub] - if ( ub_def ) - v = ub - delta_m_max * 10 * - sqrt ( -log ( NOMAD::DEFAULT_EPSILON + - ( i +NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); - - // there are no bounds: mapping [0;1] --> ]-INF;+INF[ - else - v = (NOMAD::RNG::rand()%2 ? -1.0 : 1.0) * delta_m_max * 10 * - sqrt ( - log ( NOMAD::DEFAULT_EPSILON + - ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); - } + // categorical variables have already been treated as fixed variables: + if ( bbit == NOMAD::CATEGORICAL ) + return; + + int i; + NOMAD::Double v; + NOMAD::Random_Pickup rp (p); + bool rounding = ( bbit != NOMAD::CONTINUOUS ); + bool lb_def = lb.is_defined(); + bool ub_def = ub.is_defined(); + double w = ( ( lb_def && ub_def ) ? + ub.value()-lb.value() : 1.0 ) / p; + // main loop: + for ( i = 0 ; i < p ; ++i ) + { + + // both bounds exist: + if ( lb_def && ub_def ) + v = lb + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w; + // one of the bounds does not exist: + else + { + + // lb exists, and ub not: mapping [0;1] --> [lb;+INF[ + if ( lb_def ) + v = lb + 10 * delta_m_max * sqrt ( - log ( NOMAD::DEFAULT_EPSILON + + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); + + // lb does not exist: + else + { + + // ub exists, and lb not: mapping [0;1] --> ]-INF;ub] + if ( ub_def ) + v = ub - delta_m_max * 10 * + sqrt ( -log ( NOMAD::DEFAULT_EPSILON + + ( i +NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); + + // there are no bounds: mapping [0;1] --> ]-INF;+INF[ + else + v = (NOMAD::RNG::rand()%2 ? -1.0 : 1.0) * delta_m_max * 10 * + sqrt ( - log ( NOMAD::DEFAULT_EPSILON + + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) ); + } + } + + // rounding: + if ( rounding ) + v = v.round(); + + // projection to mesh (with ref=0): + v.project_to_mesh ( 0.0 , delta_m , lb , ub ); + + // affectation + permutation: + x[rp.pickup()] = v; } - - // rounding: - if ( rounding ) - v = v.round(); - - // projection to mesh (with ref=0): - v.project_to_mesh ( 0.0 , delta_m , lb , ub ); - - // affectation + permutation: - x[rp.pickup()] = v; - } } /*---------------------------------------------------------*/ @@ -328,43 +336,46 @@ void NOMAD::LH_Search::values_for_var_i ( int p /* (static) */ /*---------------------------------------------------------*/ bool NOMAD::LH_Search::LH_points ( int n , - int m , - int p , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - std::vector<NOMAD::Eval_Point *> & pts ) { - if ( n <= 0 || - p <= 0 || - !lb.is_defined() || - !ub.is_defined() || - lb.size() != n || - ub.size() != n ) - return false; - - for ( size_t j = 0 ; j < pts.size() ; ++j ) - delete pts[j]; - pts.clear(); - - NOMAD::Eval_Point * x; - int i; - int pm1 = p-1; - NOMAD::Random_Pickup ** rps = new NOMAD::Random_Pickup *[n]; - - for ( int k = 0 ; k < p ; ++k ) { - x = new NOMAD::Eval_Point ( n , m ); - for ( i = 0 ; i < n ; ++i ) { - if ( k==0 ) - rps[i] = new NOMAD::Random_Pickup(p); - (*x)[i] = lb[i] + - (ub[i]-lb[i]) * - ( rps[i]->pickup() + NOMAD::RNG::rand()/(1.0+NOMAD::D_INT_MAX)) / p; - if ( k==pm1 ) - delete rps[i]; + int m , + int p , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + std::vector<NOMAD::Eval_Point *> & pts ) +{ + if ( n <= 0 || + p <= 0 || + !lb.is_defined() || + !ub.is_defined() || + lb.size() != n || + ub.size() != n ) + return false; + + for ( size_t j = 0 ; j < pts.size() ; ++j ) + delete pts[j]; + pts.clear(); + + NOMAD::Eval_Point * x; + int i; + int pm1 = p-1; + NOMAD::Random_Pickup ** rps = new NOMAD::Random_Pickup *[n]; + + for ( int k = 0 ; k < p ; ++k ) + { + x = new NOMAD::Eval_Point ( n , m ); + for ( i = 0 ; i < n ; ++i ) + { + if ( k==0 ) + rps[i] = new NOMAD::Random_Pickup(p); + (*x)[i] = lb[i] + + (ub[i]-lb[i]) * + ( rps[i]->pickup() + NOMAD::RNG::rand()/(1.0+NOMAD::D_INT_MAX)) / p; + if ( k==pm1 ) + delete rps[i]; + } + pts.push_back(x); } - pts.push_back(x); - } - - delete [] rps; - - return true; + + delete [] rps; + + return true; } diff --git a/src/LH_Search.hpp b/src/LH_Search.hpp index c80ff2c4c7fa944d8f1f8f67d90df09eba28b1ab..685141a60f535323f055a492bc40299bb9caee1e 100644 --- a/src/LH_Search.hpp +++ b/src/LH_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/L_Curve.cpp b/src/L_Curve.cpp index b712db18b82d098fbcf3cdb61edad65cdf7f2de5..0050f90742f09dcfac9ff2f2f8259e51052ba911 100644 --- a/src/L_Curve.cpp +++ b/src/L_Curve.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/L_Curve.hpp b/src/L_Curve.hpp index feac036459a6bac79a76bd1b3e7b98afb7aedacc..83305807241acc891a8a09d53ef7cad1925368e9 100644 --- a/src/L_Curve.hpp +++ b/src/L_Curve.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Mads.cpp b/src/Mads.cpp index 3788e3faa0bb4aa9b893d8bde47468ccb48577a0..5232644104a4dcd7b92779c29d0cfc1a5ad0bcda 100644 --- a/src/Mads.cpp +++ b/src/Mads.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Mads.cpp - \brief MADS algorithm (implementation) - \author Sebastien Le Digabel - \date 2010-04-20 - \see Mads.hpp -*/ + \file Mads.cpp + \brief MADS algorithm (implementation) + \author Sebastien Le Digabel + \date 2010-04-20 + \see Mads.hpp + */ #include "Mads.hpp" /*-----------------------------------*/ @@ -51,17 +51,18 @@ bool NOMAD::Mads::_flag_reset_mesh = true; bool NOMAD::Mads::_flag_reset_barriers = true; bool NOMAD::Mads::_flag_p1_active = false; + /*---------------------------------------------------------*/ /* force quit (static, called by pressing ctrl-c) */ /*---------------------------------------------------------*/ void NOMAD::Mads::force_quit ( int signalValue ) { - NOMAD::Mads::_force_quit = true; - NOMAD::Evaluator_Control::force_quit(); - NOMAD::Evaluator::force_quit(); - + NOMAD::Mads::_force_quit = true; + NOMAD::Evaluator_Control::force_quit(); + NOMAD::Evaluator::force_quit(); + #ifdef USE_TGP - NOMAD::TGP_Output_Model::force_quit(); + NOMAD::TGP_Output_Model::force_quit(); #endif } @@ -69,14 +70,14 @@ void NOMAD::Mads::force_quit ( int signalValue ) /* access to the flags (static) */ /*---------------------------------------------------------*/ void NOMAD::Mads::get_flags ( bool & flag_check_bimads , - bool & flag_reset_mesh , - bool & flag_reset_barriers , - bool & flag_p1_active ) + bool & flag_reset_mesh , + bool & flag_reset_barriers , + bool & flag_p1_active ) { - flag_check_bimads = _flag_check_bimads; - flag_reset_mesh = _flag_reset_mesh; - flag_reset_barriers = _flag_reset_barriers; - flag_p1_active = _flag_p1_active; + flag_check_bimads = _flag_check_bimads; + flag_reset_mesh = _flag_reset_mesh; + flag_reset_barriers = _flag_reset_barriers; + flag_p1_active = _flag_p1_active; } /*---------------------------------------------------------*/ @@ -87,53 +88,53 @@ void NOMAD::Mads::get_flags ( bool & flag_check_bimads , /*---------------------------------------------------------*/ void NOMAD::Mads::init ( void ) { - - NOMAD::Mads::_force_quit = false; - - if ( !NOMAD::Slave::is_master() ) - return; - - // Mads::force_quit() will be called if ctrl-c is pressed: - signal ( SIGINT , NOMAD::Mads::force_quit ); + + NOMAD::Mads::_force_quit = false; + + if ( !NOMAD::Slave::is_master() ) + return; + + // Mads::force_quit() will be called if ctrl-c is pressed: + signal ( SIGINT , NOMAD::Mads::force_quit ); #ifndef WINDOWS - signal ( SIGPIPE , NOMAD::Mads::force_quit ); // (ctrl-c during a "| more") + signal ( SIGPIPE , NOMAD::Mads::force_quit ); // (ctrl-c during a "| more") #endif #ifdef USE_MPI - signal ( SIGTERM , NOMAD::Mads::force_quit ); + signal ( SIGTERM , NOMAD::Mads::force_quit ); #endif - - // random number generator seed initialization: - bool valid_seed=NOMAD::RNG::set_seed(_p.get_seed()); - if ( !valid_seed ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ ,"seed for random number generator not initialized properly!" ); - - // model searches initialization: + + // model searches initialization: if ( _p.has_model_search() ) { #ifdef USE_TGP - if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) - _model_search1 = new TGP_Model_Search ( _p ); + if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) + _model_search1 = new TGP_Model_Search ( _p ); #endif - if ( _p.get_model_search(1) == NOMAD::QUADRATIC_MODEL ) - _model_search1 = new Quad_Model_Search ( _p ); + if ( _p.get_model_search(1) == NOMAD::QUADRATIC_MODEL ) + _model_search1 = new Quad_Model_Search ( _p ); #ifdef USE_TGP - if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) - _model_search2 = new TGP_Model_Search ( _p ); + if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) + _model_search2 = new TGP_Model_Search ( _p ); #endif - if ( _p.get_model_search(2) == NOMAD::QUADRATIC_MODEL ) - _model_search2 = new Quad_Model_Search ( _p ); - } - + if ( _p.get_model_search(2) == NOMAD::QUADRATIC_MODEL ) + _model_search2 = new Quad_Model_Search ( _p ); + } + #ifdef USE_TGP - _ev_control.set_last_TGP_model ( NULL ); + _ev_control.set_last_TGP_model ( NULL ); #endif - - // VNS search initialization: - if ( _p.get_VNS_search() ) - _VNS_search = new VNS_Search ( _p ); - - // cache search initialization: - if ( _p.get_cache_search() ) - _cache_search = new Cache_Search ( _p ); + + // VNS search initialization: + if ( _p.get_VNS_search() ) + _VNS_search = new VNS_Search ( _p ); + + // cache search initialization: + if ( _p.get_cache_search() ) + _cache_search = new Cache_Search ( _p ); + + // Orthogonal mesh initialization + _mesh->reset(); + + } /*---------------------------------------------------------*/ @@ -141,634 +142,133 @@ void NOMAD::Mads::init ( void ) /*---------------------------------------------------------*/ NOMAD::Mads::~Mads ( void ) { - delete _pareto_front; - delete _model_search1; - delete _model_search2; - delete _VNS_search; - delete _cache_search; - delete _L_curve; - - if ( _extended_poll && !_user_ext_poll) - delete _extended_poll; + delete _pareto_front; + delete _model_search1; + delete _model_search2; + delete _VNS_search; + delete _cache_search; + delete _L_curve; + + if ( _extended_poll && !_user_ext_poll) + delete _extended_poll; } -/*---------------------------------------------------------*/ -/* reset */ -/*---------------------------------------------------------*/ -/* default values for parameters: keep_barriers = false */ -/* keep_stats = false */ -/*---------------------------------------------------------*/ +/*-------------------------------------------------------------*/ +/* reset */ +/*-------------------------------------------------------------*/ +/* default values for parameters: keep_barriers = false */ +/* keep_stats = false */ +/*-------------------------------------------------------------*/ void NOMAD::Mads::reset ( bool keep_barriers , bool keep_stats ) { - // evaluator control: + // evaluator control: #ifdef USE_TGP - _ev_control.set_last_TGP_model ( NULL ); + _ev_control.set_last_TGP_model ( NULL ); #endif - - // user search: - _user_search = NULL; - - // model search #1: - if ( _p.get_model_search(1) != NOMAD::NO_MODEL ) { - if ( _model_search1 ) - _model_search1->reset(); - else { - if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) { + + // user search: + _user_search = NULL; + + // model search #1: + if ( _p.get_model_search(1) != NOMAD::NO_MODEL ) + { + if ( _model_search1 ) + _model_search1->reset(); + else { + if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) + { #ifdef USE_TGP - _model_search1 = new TGP_Model_Search ( _p ) ; + _model_search1 = new TGP_Model_Search ( _p ) ; #endif - } - else - _model_search1 = new Quad_Model_Search ( _p ); - } - } - else { - delete _model_search1; - _model_search1 = NULL; - } - - // model search #2: - if ( _p.get_model_search(2) != NOMAD::NO_MODEL ) { - if ( _model_search2 ) - _model_search2->reset(); - else { - if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) { + } + else + _model_search1 = new Quad_Model_Search ( _p ); + } + } + else + { + delete _model_search1; + _model_search1 = NULL; + } + + // model search #2: + if ( _p.get_model_search(2) != NOMAD::NO_MODEL ) + { + if ( _model_search2 ) + _model_search2->reset(); + else + { + if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) + { #ifdef USE_TGP - _model_search2 = new TGP_Model_Search ( _p ) ; + _model_search2 = new TGP_Model_Search ( _p ) ; #endif - } - else - _model_search2 = new Quad_Model_Search ( _p ); - } - } - else { - delete _model_search2; - _model_search2 = NULL; - } - - // VNS search: - if ( _p.get_VNS_search() ) { - if ( _VNS_search ) - _VNS_search->reset(); - else - _VNS_search = new VNS_Search ( _p ); - } - else { - delete _VNS_search; - _VNS_search = NULL; - } - - // cache search: - if ( _p.get_cache_search() ) { - if ( _cache_search ) - _cache_search->reset(); - else - _cache_search = new Cache_Search ( _p ); - } - else { - delete _cache_search; - _cache_search = NULL; - } - - // barriers: - _flag_reset_barriers = !keep_barriers; - if ( _flag_reset_barriers ) { - _true_barrier.reset(); - _sgte_barrier.reset(); - } - - // stats: - if ( !keep_stats ) - _stats.reset(); - - // mesh: - NOMAD::Mesh::init ( _p.get_mesh_update_basis().value() , - _p.get_mesh_coarsening_exponent () , - _p.get_mesh_refining_exponent () , - _p.get_initial_mesh_index () );/*---------------------------------------------------------*/ - -} - -/* algorithm execution (single-objective) */ -/*---------------------------------------------------------*/ -NOMAD::stop_type NOMAD::Mads::run ( void ) -{ - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_gen_dd(); - NOMAD::stop_type stop_reason = NOMAD::UNKNOWN_STOP_REASON; - -#ifdef USE_MPI - - if ( NOMAD::Slave::get_nb_processes() < 2 ) - { - out << NOMAD::open_block("ERROR:") << "Incorrect command to run with MPI." << std::endl - << "Usage: mpirun -np p exeName" << std::endl ; - out << NOMAD::close_block(); - return stop_reason; - } + } + else + _model_search2 = new Quad_Model_Search ( _p ); + } + } + else + { + delete _model_search2; + _model_search2 = NULL; + } + // VNS search: + if ( _p.get_VNS_search() ) + { + if ( _VNS_search ) + _VNS_search->reset(); + else + _VNS_search = new VNS_Search ( _p ); + } + else { + delete _VNS_search; + _VNS_search = NULL; + } - // init the slaves: - bool stop_slaves_here = false; - - if ( NOMAD::Slave::is_master() ) { - if ( !NOMAD::Slave::are_running() ) { - NOMAD::Slave::init_slaves ( out ); - stop_slaves_here = true; - } - } - else { - NOMAD::Slave s ( _p , _ev_control.get_evaluator() ); - s.run(); - return stop_reason; - } - -#endif - - try { - - // check an extended poll if there are categorical - // variables and disable extended poll otherwise: - if ( _p.get_signature()->has_categorical() ) - { - - if ( _user_ext_poll && !_extended_poll ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "categorical variables: user extended poll object is NULL" ); - - if ( _p.get_extended_poll_enabled() && !_user_ext_poll ) - { - - if (!_extended_poll) - _extended_poll = new NOMAD::Extended_Poll ( _p ); // extended poll created only once with the signatures of _p - - std::string error_str; - if ( !_extended_poll->set_neighbors_exe ( error_str ) ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , error_str ); - } - } - else if ( _extended_poll ) - { - if ( !_user_ext_poll ) - delete _extended_poll; - _extended_poll = NULL; - } - - // check if Mads::run() has been called for multi-objective: - if ( NOMAD::Mads::_flag_check_bimads && _p.get_nb_obj() > 1 ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::run() called for multi-objective instead of Mads::multi_run()" ); - -#ifndef R_VERSION - if ( display_degree == NOMAD::NORMAL_DISPLAY || display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "MADS run" ); - - if ( display_degree == NOMAD::NORMAL_DISPLAY ) { - _ev_control.display_stats ( true , - out , - _p.get_display_stats() , - NULL , - false , - NULL ); - out << std::endl << std::endl; - } -#endif - - // barriers init: - if ( _flag_reset_barriers ) - { - _true_barrier.reset(); - _sgte_barrier.reset(); - } - - // evaluator control init: - _ev_control.reset(); - - // reset the extended poll: - if ( _extended_poll && _p.get_extended_poll_enabled() ) - _extended_poll->reset(); - - // mesh init/reset: - if ( _flag_reset_mesh ) - NOMAD::Mesh::init ( _p.get_mesh_update_basis().value() , - _p.get_mesh_coarsening_exponent () , - _p.get_mesh_refining_exponent () , - _p.get_initial_mesh_index () ); - - NOMAD::success_type success , last_success; - int nb_search_pts; - bool count_search; - bool stop = false; - const NOMAD::Eval_Point * new_feas_inc = NULL; - const NOMAD::Eval_Point * new_infeas_inc = NULL; - - stop_reason = NOMAD::NO_STOP; - - // x0 eval: - eval_x0 ( stop , stop_reason ); - - // phase one: if no feasible starting point: - bool phase_one_done = false; - if (stop && - stop_reason == NOMAD::X0_FAIL && - _p.has_EB_constraints() && - ( _stats.get_eval() > 0 || ( _p.get_opt_only_sgte() && _stats.get_sgte_eval() > 0 ) ) ) - { - - phase_one_done = true; - Phase_One_Search p1s ( _p ); - p1s.search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - } - - // initial Latin-Hypercube (LH) search: - if ( !stop && !phase_one_done && _p.get_LH_search_p0() > 0 ) { - - LH_Search lh ( _p , true , _flag_p1_active ); - int nb_search_pts; - - lh.search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_LH_success(); - - if ( count_search ) - _stats.add_nb_LH_searches(); - - _stats.add_LH_pts ( nb_search_pts ); - } - - // no iterations allowed: - if ( !stop && _p.get_max_iterations() == 0 ) { - stop = true; - stop_reason = NOMAD::MAX_ITER_REACHED; - } - - // L_curve initialization: - delete _L_curve; - _L_curve = NULL; - const NOMAD::Double L_curve_target = _p.get_L_curve_target(); - if ( L_curve_target.is_defined() ) - { - _L_curve = new NOMAD::L_Curve ( L_curve_target ); - const NOMAD::Eval_Point * best_feasible = get_best_feasible(); - if ( best_feasible ) - _L_curve->insert ( _stats.get_bb_eval() , best_feasible->get_f() ); - } - - int max_cfi = _p.get_max_consecutive_failed_iterations(); - int nb_cfi = 0; - - success = last_success = NOMAD::UNSUCCESSFUL; - - // MADS iterations: - while ( !stop ) - { - - iteration ( stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc ); - - if ( success == NOMAD::UNSUCCESSFUL && last_success == NOMAD::UNSUCCESSFUL ) - ++nb_cfi; - else - nb_cfi = (success == NOMAD::UNSUCCESSFUL) ? 1 : 0; - - last_success = success; - - // check the consecutive number of failed iterations: - if ( max_cfi > 0 && nb_cfi > max_cfi ) - { - stop = true; - stop_reason = NOMAD::MAX_CONS_FAILED_ITER; - } - - } - - // parallel version: -#ifdef USE_MPI - - // asynchronous mode: wait for the evaluations in progress: - if ( _p.get_asynchronous() ) - { - std::list<const NOMAD::Eval_Point *> evaluated_pts; - _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - success , - evaluated_pts ); - } - - // update stats: - _stats.set_MPI_data_size ( NOMAD::Slave::get_data_sent() + - NOMAD::Slave::get_data_rcvd() ); - -#endif - - // final cache save (overwrite=true): - _ev_control.save_caches ( true ); - - // final displays: - const NOMAD::Eval_Point * bf = get_best_feasible(); - bool write_stats = bf && - ( bf->get_tag() != _ev_control.get_last_stats_tag() || - _stats.get_bb_eval() != _ev_control.get_last_stats_bbe() ); - - const std::string & stats_file_name = _p.get_stats_file_name(); - - if ( !stats_file_name.empty() ) - { - if ( write_stats && !_p.get_display_all_eval() ) - { - _ev_control.stats_file ( stats_file_name , bf , true , NULL ); - } - if ( !bf ) - { - std::ofstream fout ( (_p.get_problem_dir() + stats_file_name).c_str() ); - if ( fout.fail() ) - { - if ( out.get_gen_dd() != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY ) - out << std::endl - << "Warning (" << "Mads.cpp" << ", " << __LINE__ - << "): could not save information in stats file \'" - << stats_file_name << "\'" << std::endl << std::endl; - } - else - fout << "no feasible solution has been found in " - << _stats.get_bb_eval() << " evaluations" - << std::endl; - fout.close(); - } - } - - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + // cache search: + if ( _p.get_cache_search() ) + { + if ( _cache_search ) + _cache_search->reset(); + else + _cache_search = new Cache_Search ( _p ); + } + else + { + delete _cache_search; + _cache_search = NULL; + } + + // barriers: + _flag_reset_barriers = !keep_barriers; + if ( _flag_reset_barriers ) { - - // final stats: - if ( display_degree == NOMAD::NORMAL_DISPLAY && bf && write_stats && !_p.get_display_all_eval() ) - _ev_control.display_stats ( false, - out, - _p.get_display_stats() , - bf , - true , - NULL ); -#ifndef R_VERSION - std::ostringstream msg; - msg << "end of run (" << stop_reason << ")"; - out << std::endl << NOMAD::close_block ( msg.str() ); -#endif - } - - // mono-objective final displays: - if ( _p.get_nb_obj() == 1 ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "NOMAD final display" ); - -#ifndef R_VERSION - display(); -#endif - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block(); - } - - } // end of the try block - - catch ( std::exception & e ) { - -#ifdef USE_MPI - if ( NOMAD::Slave::are_running() ) - NOMAD::Slave::stop_slaves ( out ); -#endif - - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , e.what() ); - } - - // stop the slaves: -#ifdef USE_MPI - if ( NOMAD::Slave::are_running() && stop_slaves_here ) - NOMAD::Slave::stop_slaves ( out ); -#endif - - return stop_reason; -} - -/*----------------------------------------------------------------------*/ -/* launch a single optimization for multi-objective optimization */ -/*----------------------------------------------------------------------*/ -/* . the display_degree is given as a parameter since it corresponds */ -/* to the original iterative display degree before all degrees have */ -/* been set to zero */ -/* . private method */ -/*----------------------------------------------------------------------*/ -void NOMAD::Mads::multi_launch_single_opt -( NOMAD::dd_type display_degree , - int mads_runs , - int overall_bbe , - NOMAD::Multi_Obj_Evaluator & ev , - int & stagnation_cnt , - NOMAD::Stats & multi_stats , - bool & stop , - NOMAD::stop_type & stop_reason ) -{ - // max number of bb evaluations for one MADS run: - int max_bbe = _p.get_max_bb_eval(); - - // size of the Pareto front before the MADS run: - int tmp = _pareto_front->size(); - - // current MADS run: - int cur_mads_run = multi_stats.get_mads_runs(); - - // displays: - const NOMAD::Display & out = _p.out(); - - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) { - out << "MADS run " << std::setw(2) << cur_mads_run + 1; - if ( mads_runs > 0 ) - out << "/" << mads_runs; - out << " ..."; - } - - // run single-objective MADS (it also updates the Pareto front): - NOMAD::Mads::set_flag_check_bimads ( false ); - NOMAD::stop_type single_run_stop_reason = run(); - NOMAD::Mads::set_flag_check_bimads ( true ); - - if ( single_run_stop_reason == NOMAD::CTRL_C || - single_run_stop_reason == NOMAD::ERROR || - single_run_stop_reason == NOMAD::UNKNOWN_STOP_REASON || - single_run_stop_reason == NOMAD::X0_FAIL || - single_run_stop_reason == NOMAD::F_TARGET_REACHED || - single_run_stop_reason == NOMAD::P1_FAIL ) { - stop = true; - stop_reason = single_run_stop_reason; - } - - // update MULTI-MADS stats from MADS stats: - multi_stats.update ( _stats , false ); // for_search = false - multi_stats.add_mads_run(); - - int nb_new_pts = _pareto_front->size() - tmp; - int global_bbe = multi_stats.get_bb_eval(); - - // displays: - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) { - - // display basic stats on the terminated run: - out << "... OK [bb eval=" << std::setw(3) << _stats.get_bb_eval() - << "] [overall bb eval=" << std::setw(5) << global_bbe - << "] [# dominant pts=" << std::setw(4) << _pareto_front->size() - << "] [# new pts=" << std::setw(4) << nb_new_pts << "]"; - - // display f1, f2, and f: - const NOMAD::Eval_Point * bf = get_best_feasible(); - if ( bf ) { - - const NOMAD::Point & bbo = bf->get_bb_outputs(); - - out << " [f1=" << bbo[ev.get_i1()] - << " f2=" << bbo[ev.get_i2()]; - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << " f=" << bf->get_f(); - out << "]"; - } - out << std::endl; - } - - if ( _stats.get_bb_eval() == 0 && nb_new_pts == 0 ) - ++stagnation_cnt; - else - stagnation_cnt = 0; - - // stop ? - if ( !stop ) - { - - // test the number of MADS runs: - if ( mads_runs > 0 ) - { - if ( multi_stats.get_mads_runs() >= mads_runs ) - { - stop = true; - stop_reason = NOMAD::MULTI_NB_MADS_RUNS_REACHED; - } - } - - // test if no new Pareto point has been generated for 50*n MADS runs: - else - { - if ( stagnation_cnt > 50 * _p.get_nb_free_variables() ) - { - stop = true; - stop_reason = NOMAD::MULTI_STAGNATION; - } - } - } - - if ( overall_bbe >= 0 && global_bbe >= overall_bbe ) { - stop = true; - stop_reason = NOMAD::MULTI_MAX_BB_REACHED; - } - - bool user_calls_enabled = _p.get_user_calls_enabled(); - - if ( !stop ) - { - - // ell is the mesh index on which the last run terminated: - // int ell = NOMAD::Mesh::get_mesh_index(); - - // reset MADS: - reset(); - - // this strategy deciding the initial mesh size - // was used with versions < 3.4 - // if ( cur_mads_run > 1 ) - // _p.set_INITIAL_MESH_INDEX ( (ell > 5) ? 5 : ell ); - - // modify MAX_BB_EVAL for single runs (in order to have - // less than overall_bbe blackbox evaluations): - if ( overall_bbe >= 0 && global_bbe + max_bbe > overall_bbe ) - _p.set_MAX_BB_EVAL ( overall_bbe - global_bbe ); - } - - // set the number of MADS runs for the general Stats object: - _stats.set_mads_runs ( multi_stats.get_mads_runs() ); - - // call the user-defined function Multi_Obj_Evaluator::update_mads_run(): - if ( user_calls_enabled ) - ev.update_mads_run ( _stats , - _ev_control , - _true_barrier , - _sgte_barrier , - *_pareto_front ); + _true_barrier.reset(); + _sgte_barrier.reset(); + } + + // stats: + if ( !keep_stats ) + _stats.reset(); + + + _mesh->reset(); + } -/*--------------------------------------------------------------------------*/ -/* compute and set the minimal poll size for multi-objective optimization */ -/* (private) */ -/*--------------------------------------------------------------------------*/ -void NOMAD::Mads::multi_set_min_poll_size ( const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & delta_p_0 , - NOMAD::Double delta_j ) -{ - delta_j /= sqrt ( NOMAD::Mesh::get_mesh_update_basis() ); - - int n = delta_p_0.size(); - NOMAD::Point delta_p_min (n); - for ( int i = 0 ; i < n ; ++i ) { - - // set a relative value: - if ( lb[i].is_defined() && ub[i].is_defined() ) - delta_p_min[i] = delta_j * ( ub[i] - lb[i] ); - - // set an absolute value: - else - delta_p_min[i] = delta_j; - - // compare to delta_p_0: - if ( delta_p_min[i] > delta_p_0[i] ) - delta_p_min[i] = delta_p_0[i]; - } - - _p.set_MIN_POLL_SIZE ( delta_p_min ); -} - -/*---------------------------------------------------------*/ -/* algorithm execution (multi) */ +/* algorithm execution (single-objective) */ /*---------------------------------------------------------*/ -NOMAD::stop_type NOMAD::Mads::multi_run ( void ) +NOMAD::stop_type NOMAD::Mads::run ( void ) { - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_gen_dd(); - NOMAD::stop_type stop_reason = NOMAD::UNKNOWN_STOP_REASON; - - // init the slaves: - + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_gen_dd(); + NOMAD::stop_type stop_reason = NOMAD::UNKNOWN_STOP_REASON; + #ifdef USE_MPI - + if ( NOMAD::Slave::get_nb_processes() < 2 ) { out << NOMAD::open_block("ERROR:") << "Incorrect command to run with MPI." << std::endl @@ -777,427 +277,983 @@ NOMAD::stop_type NOMAD::Mads::multi_run ( void ) return stop_reason; } - bool stop_slaves_here = false; - - if ( NOMAD::Slave::is_master() ) { - if ( !NOMAD::Slave::are_running() ) { - NOMAD::Slave::init_slaves ( out ); - stop_slaves_here = true; - } - } - else { - NOMAD::Slave s ( _p , _ev_control.get_evaluator() ); - s.run(); - return stop_reason; - } - + + // init the slaves: + bool stop_slaves_here = false; + + if ( NOMAD::Slave::is_master() ) + { + if ( !NOMAD::Slave::are_running() ) + { + NOMAD::Slave::init_slaves ( out ); + stop_slaves_here = true; + } + } + else + { + NOMAD::Slave s ( _p , _ev_control.get_evaluator() ); + s.run(); + return stop_reason; + } + #endif - - try { - - // objective indexes: - NOMAD::Multi_Obj_Evaluator::set_obj_indexes ( _p.get_index_obj() ); - - // bounds: - const NOMAD::Point & lb = _p.get_lb(); - const NOMAD::Point & ub = _p.get_ub(); - - // MULTI-MADS stopping criteria: - int mads_runs = _p.get_multi_nb_mads_runs(); // max number of MADS runs - int overall_bbe = _p.get_multi_overall_bb_eval(); // max number of total bb eval. - bool use_delta_crit = _p.get_multi_use_delta_crit(); // use the delta term. crit. - int stagnation_cnt = 0; - - if ( mads_runs == 0 ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::multi_run(): parameter MULTI_NB_MADS_RUNS is not positive" ); - - if ( _p.get_nb_obj() != 2 ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::multi_run(): NOMAD current version handles a maximum of two objectives" ); - - // remember cache save period: - int old_csp = _p.get_cache_save_period(); - - // remember L_CURVE_TARGET: - NOMAD::Double old_lct = _p.get_L_curve_target(); - - // remember solution file: - std::string old_sol_file = _p.get_solution_file(); - - // remember the original LH search parameters: - int lh_p0 = _p.get_LH_search_p0(); - int lh_pi = _p.get_LH_search_pi(); - - // remember the original minimal poll size: - const NOMAD::Point original_min_poll_size = _p.get_min_poll_size(); - - // remember display degrees: - NOMAD::dd_type iter_dd = out.get_iter_dd(); - std::string old_dd; - out.get_display_degree ( old_dd ); - - // save list of starting points: - std::string x0_cache_file = _p.get_x0_cache_file(); - std::vector<NOMAD::Point *> x0s; + + try { - const std::vector<NOMAD::Point *> & x0s_tmp = _p.get_x0s(); - size_t nx0 = x0s_tmp.size() , k; - for ( k = 0 ; k < nx0 ; ++k ) - x0s.push_back ( new Point ( *x0s_tmp[k] ) ); - } - - // compute delta_p_0: - NOMAD::Point delta_p_0 ( _p.get_dimension() ); - _p.get_signature()->get_mesh().get_delta_p ( delta_p_0 , - _p.get_initial_mesh_index() ); - - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << std::endl << NOMAD::open_block ( "multi-MADS run" ) << std::endl; - - bool stop = false; - stop_reason = NOMAD::NO_STOP; - - // MULTI-MADS stats: - NOMAD::Stats multi_stats ( _stats ); - - // access to the evaluator (downcast to a Multi_Obj_Evaluator): - NOMAD::Multi_Obj_Evaluator * ev = - static_cast<NOMAD::Multi_Obj_Evaluator*> ( _ev_control.get_evaluator() ); - if ( !ev->is_multi_obj() ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::multi_run(): associated Evaluator object is not a Multi_Obj_Evaluator" ); - - // parameters modifications: - // ------------------------- - - // STATS_FILE: - const std::string old_stats_file_name = _p.get_stats_file_name(); - const std::list<std::string> old_stats_file = _p.get_stats_file(); - _p.reset_stats_file(); - - // MAX_BB_EVAL: - int max_bbe = _p.get_max_bb_eval(); - if ( overall_bbe >= 0 && ( max_bbe < 0 || overall_bbe < max_bbe ) ) - _p.set_MAX_BB_EVAL ( overall_bbe ); - - // disable display: - _p.set_DISPLAY_DEGREE ( NOMAD::NO_DISPLAY ); - - // disable solution file: - _p.set_SOLUTION_FILE ( "" ); - - // disable CACHE_SAVE_PERIOD: - _p.set_CACHE_SAVE_PERIOD ( -1 ); - - // disable L_CURVE_TARGET: - _p.set_L_CURVE_TARGET ( NOMAD::Double() ); - - // LH_SEARCH and MAX_BB_EVAL adjustment: - if ( lh_p0 > 0 ) { - _p.set_LH_SEARCH ( lh_p0 , 0 ); - if ( max_bbe >= 0 ) { - int bbe = max_bbe + lh_p0; - if ( overall_bbe >= 0 && bbe > overall_bbe ) - bbe = overall_bbe; - _p.set_MAX_BB_EVAL ( bbe ); - } - } - - // parameters validation: - _p.check ( true , // remove_history_file = true - true , // remove_solution_file = true - true ); // remove_stats_file = true - - // Pareto front initialization: - delete _pareto_front; - _pareto_front = new NOMAD::Pareto_Front; - - // initial optimizations ( minimize f1(x) or f2(x) ): - // -------------------------------------------------- - const NOMAD::Eval_Point * best_f2; - int i; - - for ( i = 0 ; i < 2 ; ++i ) - { - if ( stop ) - break; + // check an extended poll if there are categorical + // variables and disable extended poll otherwise: + if ( _p.get_signature()->has_categorical() ) + { + + if ( _user_ext_poll && !_extended_poll ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "categorical variables: user extended poll object is NULL" ); + + if ( _p.get_extended_poll_enabled() && !_user_ext_poll ) + { + if (!_extended_poll) + _extended_poll = new NOMAD::Extended_Poll ( _p ); // extended poll created only once with the signatures of _p + + std::string error_str; + if ( !_extended_poll->set_neighbors_exe ( error_str ) ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , error_str ); + } + } + else if ( _extended_poll ) + { + if ( !_user_ext_poll ) + delete _extended_poll; + _extended_poll = NULL; + } + + // check if Mads::run() has been called for multi-objective: + if ( NOMAD::Mads::_flag_check_bimads && _p.get_nb_obj() > 1 ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::run() called for multi-objective instead of Mads::multi_run()" ); - // minimize f2: - if ( i == 1 ) +#ifndef R_VERSION + if ( display_degree == NOMAD::NORMAL_DISPLAY || display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::open_block ( "MADS run" ); + + if ( display_degree == NOMAD::NORMAL_DISPLAY ) { + _ev_control.display_stats ( true , + out , + _p.get_display_stats() , + NULL , + false , + NULL ); + out << std::endl << std::endl; + } +#endif + + // barriers init: + if ( _flag_reset_barriers ) { + _true_barrier.reset(); + _sgte_barrier.reset(); + } - // new starting point: - best_f2 = _pareto_front->get_best_f2(); - if ( best_f2 ) - { - _p.set_EXTERN_SIGNATURE ( best_f2->get_signature() ); - _p.reset_X0(); - _p.set_X0 ( *best_f2 ); + // evaluator control init: + _ev_control.reset(); + + // reset the extended poll: + if ( _extended_poll && _p.get_extended_poll_enabled() ) + _extended_poll->reset(); + + // mesh init/reset: + if ( _flag_reset_mesh ) + _mesh->reset(); + + NOMAD::success_type success , last_success; + int nb_search_pts; + bool count_search; + bool stop = false; + const NOMAD::Eval_Point * new_feas_inc = NULL; + const NOMAD::Eval_Point * new_infeas_inc = NULL; + + stop_reason = NOMAD::NO_STOP; + + // x0 eval: + eval_x0 ( stop , stop_reason ); + + // phase one: if no feasible starting point: + bool phase_one_done = false; + if (stop && + stop_reason == NOMAD::X0_FAIL && + _p.has_EB_constraints() && + ( _stats.get_eval() > 0 || ( _p.get_opt_only_sgte() && _stats.get_sgte_eval() > 0 ) ) ) + { + + phase_one_done = true; + Phase_One_Search p1s ( _p ); + p1s.search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + _mesh->reset(); + + } + + // initial Latin-Hypercube (LH) search: + if ( !stop && !phase_one_done && _p.get_LH_search_p0() > 0 ) + { + + LH_Search lh ( _p , true , _flag_p1_active ); + int nb_search_pts; + + lh.search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_LH_success(); + + if ( count_search ) + _stats.add_nb_LH_searches(); + + _stats.add_LH_pts ( nb_search_pts ); + } + + // no iterations allowed: + if ( !stop && _p.get_max_iterations() == 0 ) + { + stop = true; + stop_reason = NOMAD::MAX_ITER_REACHED; + } + + // L_curve initialization: + delete _L_curve; + _L_curve = NULL; + const NOMAD::Double L_curve_target = _p.get_L_curve_target(); + if ( L_curve_target.is_defined() ) + { + _L_curve = new NOMAD::L_Curve ( L_curve_target ); + const NOMAD::Eval_Point * best_feasible = get_best_feasible(); + if ( best_feasible ) + _L_curve->insert ( _stats.get_bb_eval() , best_feasible->get_f() ); + } + + int max_cfi = _p.get_max_consecutive_failed_iterations(); + int nb_cfi = 0; + + success = last_success = NOMAD::UNSUCCESSFUL; + + // MADS iterations: + while ( !stop ) + { + + iteration ( stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc ); + + if ( success == NOMAD::UNSUCCESSFUL && last_success == NOMAD::UNSUCCESSFUL ) + ++nb_cfi; + else + nb_cfi = (success == NOMAD::UNSUCCESSFUL) ? 1 : 0; + + last_success = success; + + // check the consecutive number of failed iterations: + if ( max_cfi > 0 && nb_cfi > max_cfi ) + { + stop = true; + stop_reason = NOMAD::MAX_CONS_FAILED_ITER; } - // LH_SEARCH: - if ( lh_pi > 0 ) - _p.set_LH_SEARCH ( lh_pi , 0 ); - else if ( lh_p0 > 0 ) - _p.set_LH_SEARCH ( 0 , 0 ); - - // MAX_BB_EVAL: - if ( max_bbe >= 0 ) { - int bbe = max_bbe + ( (lh_pi > 0 ) ? lh_pi : 0 ); - if ( overall_bbe >= 0 ) { - if ( bbe > overall_bbe ) - bbe = overall_bbe; - int global_bbe = multi_stats.get_bb_eval(); - if ( global_bbe + bbe > overall_bbe ) - bbe = overall_bbe - global_bbe; + } + + // parallel version: +#ifdef USE_MPI + + // asynchronous mode: wait for the evaluations in progress: + if ( _p.get_asynchronous() ) + { + std::list<const NOMAD::Eval_Point *> evaluated_pts; + _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + success , + evaluated_pts ); + } + + // update stats: + _stats.set_MPI_data_size ( NOMAD::Slave::get_data_sent() + + NOMAD::Slave::get_data_rcvd() ); + +#endif + + // final cache save (overwrite=true): + _ev_control.save_caches ( true ); + + // final displays: + const NOMAD::Eval_Point * bf = get_best_feasible(); + bool write_stats = bf && + ( bf->get_tag() != _ev_control.get_last_stats_tag() || + _stats.get_bb_eval() != _ev_control.get_last_stats_bbe() ); + + const std::string & stats_file_name = _p.get_stats_file_name(); + + if ( !stats_file_name.empty() ) + { + if ( write_stats && !_p.get_display_all_eval() ) + { + _ev_control.stats_file ( stats_file_name , bf , true , NULL ); + } + if ( !bf && display_degree > NOMAD::MINIMAL_DISPLAY ) + { + std::ofstream fout ( (_p.get_problem_dir() + stats_file_name).c_str() ); + if ( fout.fail() ) + { + out << std::endl + << "Warning (" << "Mads.cpp" << ", " << __LINE__ + << "): could not save information in stats file \'" + << stats_file_name << "\'" << std::endl << std::endl; } - _p.set_MAX_BB_EVAL ( bbe ); + else + fout << "no feasible solution has been found after " + << _stats.get_bb_eval() << " evaluations" + << std::endl; + fout.close(); } + + } + + if ( display_degree > NOMAD::MINIMAL_DISPLAY) + { + + // final stats: + if ( display_degree == NOMAD::NORMAL_DISPLAY && bf && write_stats && !_p.get_display_all_eval() ) + _ev_control.display_stats ( false, + out, + _p.get_display_stats() , + bf , + true , + NULL ); +#ifndef R_VERSION + std::ostringstream msg; + msg << "end of run (" << stop_reason << ")"; + out << std::endl << NOMAD::close_block ( msg.str() ); +#endif + } + + // mono-objective final displays: + if ( _p.get_nb_obj() == 1 ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::open_block ( "NOMAD final display" ); + +#ifndef R_VERSION + display(); +#endif + + - if ( _p.to_be_checked() ) - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - true ); // remove_stats_file = true + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block(); } - // set weights/reference: - ev->set_weights ( 1-i , i ); - ev->set_ref ( NULL ); + } // end of the try block + + catch ( std::exception & e ) + { - // launch the single optimization: - multi_launch_single_opt ( iter_dd , - mads_runs , - overall_bbe , - *ev , - stagnation_cnt , - multi_stats , - stop , - stop_reason ); - } - - const NOMAD::Point * ref; - const NOMAD::Pareto_Point * xj; - NOMAD::Double delta_j; - - // the LH search is disabled: - _p.set_LH_SEARCH ( 0 , 0 ); - - // MAX_BB_EVAL reset: - if ( max_bbe > 0 && ( lh_p0 > 0 || lh_pi > 0 ) ) +#ifdef USE_MPI + if ( NOMAD::Slave::are_running() ) + NOMAD::Slave::stop_slaves ( out ); +#endif + + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , e.what() ); + } + + // stop the slaves: +#ifdef USE_MPI + if ( NOMAD::Slave::are_running() && stop_slaves_here ) + NOMAD::Slave::stop_slaves ( out ); +#endif + + return stop_reason; +} + +/*----------------------------------------------------------------------*/ +/* launch a single optimization for multi-objective optimization */ +/*----------------------------------------------------------------------*/ +/* . the display_degree is given as a parameter since it corresponds */ +/* to the original iterative display degree before all degrees have */ +/* been set to zero */ +/* . private method */ +/*----------------------------------------------------------------------*/ +void NOMAD::Mads::multi_launch_single_opt +( NOMAD::dd_type display_degree , + int mads_runs , + int overall_bbe , + NOMAD::Multi_Obj_Evaluator & ev , + int & stagnation_cnt , + NOMAD::Stats & multi_stats , + bool & stop , + NOMAD::stop_type & stop_reason ) +{ + // max number of bb evaluations for one MADS run: + int max_bbe = _p.get_max_bb_eval(); + + // size of the Pareto front before the MADS run: + int tmp = _pareto_front->size(); + + // current MADS run: + int cur_mads_run = multi_stats.get_mads_runs(); + + // displays: + const NOMAD::Display & out = _p.out(); + + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + { + out << "MADS run " << std::setw(2) << cur_mads_run + 1; + if ( mads_runs > 0 ) + out << "/" << mads_runs; + out << " ..."; + } + + // run single-objective MADS (it also updates the Pareto front): + NOMAD::Mads::set_flag_check_bimads ( false ); + NOMAD::stop_type single_run_stop_reason = run(); + NOMAD::Mads::set_flag_check_bimads ( true ); + + if ( single_run_stop_reason == NOMAD::CTRL_C || + single_run_stop_reason == NOMAD::ERROR || + single_run_stop_reason == NOMAD::UNKNOWN_STOP_REASON || + single_run_stop_reason == NOMAD::X0_FAIL || + single_run_stop_reason == NOMAD::F_TARGET_REACHED || + single_run_stop_reason == NOMAD::P1_FAIL ) { - int bbe = max_bbe; - if ( overall_bbe >= 0 ) + stop = true; + stop_reason = single_run_stop_reason; + } + + // update MULTI-MADS stats from MADS stats: + multi_stats.update ( _stats , false ); // for_search = false + multi_stats.add_mads_run(); + + int nb_new_pts = _pareto_front->size() - tmp; + int global_bbe = multi_stats.get_bb_eval(); + + // displays: + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + { + + // display basic stats on the terminated run: + out << "... OK [bb eval=" << std::setw(3) << _stats.get_bb_eval() + << "] [overall bb eval=" << std::setw(5) << global_bbe + << "] [# dominant pts=" << std::setw(4) << _pareto_front->size() + << "] [# new pts=" << std::setw(4) << nb_new_pts << "]"; + + // display f1, f2, and f: + const NOMAD::Eval_Point * bf = get_best_feasible(); + if ( bf ) { - if ( bbe > overall_bbe ) - bbe = overall_bbe; - int global_bbe = multi_stats.get_bb_eval(); - if ( global_bbe + bbe > overall_bbe ) - bbe = overall_bbe - global_bbe; + const NOMAD::Point & bbo = bf->get_bb_outputs(); + + out << " [f1=" << bbo[ev.get_i1()] + << " f2=" << bbo[ev.get_i2()]; + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << " f=" << bf->get_f(); + out << "]"; } - _p.set_MAX_BB_EVAL ( bbe ); - } - - // MULTI-MADS main loop: - // --------------------- - const NOMAD::Eval_Point * x0_tmp; - - while ( !stop ) - { - - // get the reference point from the Pareto front: - ref = _pareto_front->get_ref ( xj , delta_j ); - - if ( !xj ) { - stop = true; - stop_reason = NOMAD::MULTI_NO_PARETO_PTS; - break; - } - - // use delta as stopping criterion: - if ( use_delta_crit ) { - if ( delta_j.is_defined() && delta_j > 0.0 ) - multi_set_min_poll_size ( lb , ub , delta_p_0 , delta_j ); - else - _p.set_MIN_POLL_SIZE ( original_min_poll_size ); - } - - // new starting point: - x0_tmp = xj->get_element(); - _p.set_EXTERN_SIGNATURE ( x0_tmp->get_signature() ); - _p.reset_X0(); - _p.set_X0 ( *x0_tmp ); - - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - true ); // remove_stats_file = true - - // a reference point has been found: optimization - // with reference-based function: - if ( ref ) { - - // set reference: - ev->set_ref ( ref ); - - // launch the single optimization: - multi_launch_single_opt ( iter_dd , - mads_runs , - overall_bbe , - *ev , - stagnation_cnt , - multi_stats , - stop , - stop_reason ); - - delete ref; - ev->set_ref ( NULL ); - } - - // no reference available: two optimizations ( f1(x) and f2(x) ): - else { - - // for the stagnation check: - const NOMAD::Eval_Point * pp_before; - int stagnation_cnt_before , overall_bbe_before; - bool check_1 = false; - - // loop on f1 and f2: - for ( i = 0 ; i < 2 ; ++i ) { - - if ( stop ) - break; - - // minimize f2: - if ( i == 1 ) { - - // new starting point: - best_f2 = _pareto_front->get_best_f2(); - if ( best_f2 ) { - _p.set_EXTERN_SIGNATURE ( best_f2->get_signature() ); - _p.reset_X0(); - _p.set_X0 ( *best_f2 ); - } - else - _p.set_X0 ( *x0_tmp ); - - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - true ); // remove_stats_file = true - } - - // set weights/reference: - ev->set_weights ( 1-i , i ); - ev->set_ref ( NULL ); - - stagnation_cnt_before = stagnation_cnt; - overall_bbe_before = overall_bbe; - pp_before = ( _pareto_front->size() == 1 ) ? - _pareto_front->begin() : NULL; - - // launch the single optimization: - multi_launch_single_opt ( iter_dd , - mads_runs , - overall_bbe , - *ev , - stagnation_cnt , - multi_stats , - stop , - stop_reason ); - - // stagnation check: - if ( stagnation_cnt > stagnation_cnt_before && - overall_bbe == overall_bbe_before && - _pareto_front->size() == 1 && - _pareto_front->begin() == pp_before ) { - - if ( i == 0 ) - check_1 = true; - else if ( check_1 ) { - stop = true; - stop_reason = NOMAD::MULTI_STAGNATION; - } - } - } - } - - } // end of MULTI-MADS main loop - // --------------------------- + out << std::endl; + } + + if ( _stats.get_bb_eval() == 0 && nb_new_pts == 0 ) + ++stagnation_cnt; + else + stagnation_cnt = 0; + + // stop ? + if ( !stop ) + { + + // test the number of MADS runs: + if ( mads_runs > 0 ) + { + if ( multi_stats.get_mads_runs() >= mads_runs ) + { + stop = true; + stop_reason = NOMAD::MULTI_NB_MADS_RUNS_REACHED; + } + } + + // test if no new Pareto point has been generated for 50*n MADS runs: + else + { + if ( stagnation_cnt > 50 * _p.get_nb_free_variables() ) + { + stop = true; + stop_reason = NOMAD::MULTI_STAGNATION; + } + } + } + + if ( overall_bbe >= 0 && global_bbe >= overall_bbe ) + { + stop = true; + stop_reason = NOMAD::MULTI_MAX_BB_REACHED; + } + + bool user_calls_enabled = _p.get_user_calls_enabled(); + + if ( !stop ) + { + + // ell is the mesh index on which the last run terminated: + // int ell = NOMAD::Mesh::get_mesh_index(); + + // reset MADS: + reset(); + + // this strategy deciding the initial mesh size + // was used with versions < 3.4 + // if ( cur_mads_run > 1 ) + // _p.set_INITIAL_MESH_INDEX ( (ell > 5) ? 5 : ell ); + + // modify MAX_BB_EVAL for single runs (in order to have + // less than overall_bbe blackbox evaluations): + if ( overall_bbe >= 0 && global_bbe + max_bbe > overall_bbe ) + _p.set_MAX_BB_EVAL ( overall_bbe - global_bbe ); + } + + // set the number of MADS runs for the general Stats object: + _stats.set_mads_runs ( multi_stats.get_mads_runs() ); + + // call the user-defined function Multi_Obj_Evaluator::update_mads_run(): + if ( user_calls_enabled ) + ev.update_mads_run ( _stats , + _ev_control , + _true_barrier , + _sgte_barrier , + *_pareto_front ); +} - // parameters re-initialization and final displays: - { - _p.reset_X0(); - size_t nx0 = x0s.size(); - if ( nx0 > 0 ) { - for ( size_t k = 0 ; k < nx0 ; ++k ) { - _p.set_X0 ( *x0s[k] ); - delete x0s[k]; - } - } - else if ( !x0_cache_file.empty() ) - _p.set_X0 ( x0_cache_file ); - } - _p.set_MAX_BB_EVAL ( max_bbe ); - _p.set_DISPLAY_DEGREE ( old_dd ); - _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); - _p.set_SOLUTION_FILE ( old_sol_file ); - _p.set_LH_SEARCH ( lh_p0 , lh_pi ); - _p.set_CACHE_SAVE_PERIOD ( old_csp ); - _p.set_L_CURVE_TARGET ( old_lct ); - - if ( use_delta_crit ) - _p.set_MIN_POLL_SIZE ( original_min_poll_size ); +/*--------------------------------------------------------------------------*/ +/* compute and set the minimal poll size for multi-objective optimization */ +/* (private) */ +/*--------------------------------------------------------------------------*/ +void NOMAD::Mads::multi_set_min_poll_size ( const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & Delta_0 , + NOMAD::Double delta_j ) +{ - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - true ); // remove_stats_file = true + delta_j /= sqrt ( _mesh->get_update_basis() ); + + int n = Delta_0.size(); + NOMAD::Point Delta_min (n); + + for ( int i = 0 ; i < n ; ++i ) + { + + // set a relative value: + if ( lb[i].is_defined() && ub[i].is_defined() ) + Delta_min[i] = delta_j * ( ub[i] - lb[i] ); + + // set an absolute value: + else + Delta_min[i] = delta_j; + + // compare to Delta_0: + if ( Delta_min[i] > Delta_0[i] ) + Delta_min[i] = Delta_0[i]; + } + + _p.set_MIN_POLL_SIZE ( Delta_min ); +} - // reset MADS stats from MULTI-MADS stats: - _stats = multi_stats; - - // final cache save (overwrite=true): - _ev_control.save_caches ( true ); +/*---------------------------------------------------------*/ +/* algorithm execution (multi) */ +/*---------------------------------------------------------*/ +NOMAD::stop_type NOMAD::Mads::multi_run ( void ) +{ + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_gen_dd(); + NOMAD::stop_type stop_reason = NOMAD::UNKNOWN_STOP_REASON; + + // init the slaves: -#ifndef R_VERSION - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) { - std::ostringstream msg; - msg << "end of run (" << stop_reason << ")"; - out << std::endl << NOMAD::close_block ( msg.str() ) << std::endl; - } +#ifdef USE_MPI + + if ( NOMAD::Slave::get_nb_processes() < 2 ) + { + out << NOMAD::open_block("ERROR:") << "Incorrect command to run with MPI." << std::endl + << "Usage: mpirun -np p exeName" << std::endl ; + out << NOMAD::close_block(); + return stop_reason; + } + + bool stop_slaves_here = false; + + if ( NOMAD::Slave::is_master() ) + { + if ( !NOMAD::Slave::are_running() ) + { + NOMAD::Slave::init_slaves ( out ); + stop_slaves_here = true; + } + } + else + { + NOMAD::Slave s ( _p , _ev_control.get_evaluator() ); + s.run(); + return stop_reason; + } + #endif + + try { + + // objective indexes: + NOMAD::Multi_Obj_Evaluator::set_obj_indexes ( _p.get_index_obj() ); + + // bounds: + const NOMAD::Point & lb = _p.get_lb(); + const NOMAD::Point & ub = _p.get_ub(); + + // MULTI-MADS stopping criteria: + int mads_runs = _p.get_multi_nb_mads_runs(); // max number of MADS runs + int overall_bbe = _p.get_multi_overall_bb_eval(); // max number of total bb eval. + bool use_delta_crit = _p.get_multi_use_delta_crit(); // use the delta term. crit. + int stagnation_cnt = 0; + + if ( mads_runs == 0 ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::multi_run(): parameter MULTI_NB_MADS_RUNS is not positive" ); + + if ( _p.get_nb_obj() != 2 ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::multi_run(): NOMAD current version handles a maximum of two objectives" ); + + // remember cache save period: + int old_csp = _p.get_cache_save_period(); + + // remember L_CURVE_TARGET: + NOMAD::Double old_lct = _p.get_L_curve_target(); + + // remember solution file: + std::string old_sol_file = _p.get_solution_file(); + + // remember the original LH search parameters: + int lh_p0 = _p.get_LH_search_p0(); + int lh_pi = _p.get_LH_search_pi(); + + // remember the original minimal poll size: + const NOMAD::Point original_min_poll_size = _p.get_min_poll_size(); + + // remember display degrees: + NOMAD::dd_type iter_dd = out.get_iter_dd(); + std::string old_dd; + out.get_display_degree ( old_dd ); + + // save list of starting points: + std::string x0_cache_file = _p.get_x0_cache_file(); + std::vector<NOMAD::Point *> x0s; + { + const std::vector<NOMAD::Point *> & x0s_tmp = _p.get_x0s(); + size_t nx0 = x0s_tmp.size() , k; + for ( k = 0 ; k < nx0 ; ++k ) + x0s.push_back ( new Point ( *x0s_tmp[k] ) ); + } + + NOMAD::Point Delta_0 = _mesh->get_initial_poll_size (); + + + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << std::endl << NOMAD::open_block ( "multi-MADS run" ) << std::endl; + + bool stop = false; + stop_reason = NOMAD::NO_STOP; + + // MULTI-MADS stats: + NOMAD::Stats multi_stats ( _stats ); + + // access to the evaluator (downcast to a Multi_Obj_Evaluator): + NOMAD::Multi_Obj_Evaluator * ev = + static_cast<NOMAD::Multi_Obj_Evaluator*> ( _ev_control.get_evaluator() ); + if ( !ev->is_multi_obj() ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::multi_run(): associated Evaluator object is not a Multi_Obj_Evaluator" ); + + // parameters modifications: + // ------------------------- + + // STATS_FILE: + const std::string old_stats_file_name = _p.get_stats_file_name(); + const std::list<std::string> old_stats_file = _p.get_stats_file(); + _p.reset_stats_file(); + + // MAX_BB_EVAL: + int max_bbe = _p.get_max_bb_eval(); + if ( overall_bbe >= 0 && ( max_bbe < 0 || overall_bbe < max_bbe ) ) + _p.set_MAX_BB_EVAL ( overall_bbe ); + + // disable display: + _p.set_DISPLAY_DEGREE ( NOMAD::NO_DISPLAY ); + + // disable solution file: + _p.set_SOLUTION_FILE ( "" ); + + // disable CACHE_SAVE_PERIOD: + _p.set_CACHE_SAVE_PERIOD ( -1 ); + + // disable L_CURVE_TARGET: + _p.set_L_CURVE_TARGET ( NOMAD::Double() ); + + // LH_SEARCH and MAX_BB_EVAL adjustment: + if ( lh_p0 > 0 ) + { + _p.set_LH_SEARCH ( lh_p0 , 0 ); + if ( max_bbe >= 0 ) + { + int bbe = max_bbe + lh_p0; + if ( overall_bbe >= 0 && bbe > overall_bbe ) + bbe = overall_bbe; + _p.set_MAX_BB_EVAL ( bbe ); + } + } + + // parameters validation: + _p.check ( true , // remove_history_file = true + true , // remove_solution_file = true + true ); // remove_stats_file = true + + // Pareto front initialization: + delete _pareto_front; + _pareto_front = new NOMAD::Pareto_Front; + + // Problem has categorical variables ? (Si why this flag is needed below) + bool hasCategoricalVar=_p.get_signature()->has_categorical(); + + // initial optimizations ( minimize f1(x) or f2(x) ): + // -------------------------------------------------- + const NOMAD::Eval_Point * best_f2; + int i; + + for ( i = 0 ; i < 2 ; ++i ) + { + + if ( stop ) + break; + + // minimize f2: + if ( i == 1 ) + { + + // new starting point: + best_f2 = _pareto_front->get_best_f2(); + if ( best_f2 ) + { + _p.set_EXTERN_SIGNATURE ( best_f2->get_signature() ); + _p.reset_X0(); + _p.set_X0 ( *best_f2 ); + } + + // LH_SEARCH: + if ( lh_pi > 0 ) + _p.set_LH_SEARCH ( lh_pi , 0 ); + else if ( lh_p0 > 0 ) + _p.set_LH_SEARCH ( 0 , 0 ); + + // MAX_BB_EVAL: + if ( max_bbe >= 0 ) + { + int bbe = max_bbe + ( (lh_pi > 0 ) ? lh_pi : 0 ); + if ( overall_bbe >= 0 ) + { + if ( bbe > overall_bbe ) + bbe = overall_bbe; + int global_bbe = multi_stats.get_bb_eval(); + if ( global_bbe + bbe > overall_bbe ) + bbe = overall_bbe - global_bbe; + } + _p.set_MAX_BB_EVAL ( bbe ); + } + + if ( _p.to_be_checked() ) + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + true ); // remove_stats_file = true + + _mesh=_p.get_signature()->get_mesh(); + + } + + // set weights/reference: + ev->set_weights ( 1-i , i ); + ev->set_ref ( NULL ); + + // launch the single optimization: + multi_launch_single_opt ( iter_dd , + mads_runs , + overall_bbe , + *ev , + stagnation_cnt , + multi_stats , + stop , + stop_reason ); + } + + const NOMAD::Point * ref; + const NOMAD::Pareto_Point * xj; + NOMAD::Double delta_j; + + // the LH search is disabled: + _p.set_LH_SEARCH ( 0 , 0 ); + + // MAX_BB_EVAL reset: + if ( max_bbe > 0 && ( lh_p0 > 0 || lh_pi > 0 ) ) + { + int bbe = max_bbe; + if ( overall_bbe >= 0 ) + { + if ( bbe > overall_bbe ) + bbe = overall_bbe; + + int global_bbe = multi_stats.get_bb_eval(); + if ( global_bbe + bbe > overall_bbe ) + bbe = overall_bbe - global_bbe; + } + _p.set_MAX_BB_EVAL ( bbe ); + } + + // MULTI-MADS main loop: + // --------------------- + const NOMAD::Eval_Point * x0_tmp; + + while ( !stop ) + { + + // get the reference point from the Pareto front: + ref = _pareto_front->get_ref ( xj , delta_j ); + + if ( !xj ) + { + stop = true; + stop_reason = NOMAD::MULTI_NO_PARETO_PTS; + break; + } + + // use delta as stopping criterion: + if ( use_delta_crit ) + { + if ( delta_j.is_defined() && delta_j > 0.0 ) + multi_set_min_poll_size ( lb , ub , Delta_0 , delta_j ); + else + _p.set_MIN_POLL_SIZE ( original_min_poll_size ); + } + + // new starting point: + x0_tmp = xj->get_element(); + _p.set_EXTERN_SIGNATURE ( x0_tmp->get_signature() ); + _p.reset_X0(); + _p.set_X0 ( *x0_tmp ); + + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + true ); // remove_stats_file = true + + // a reference point has been found: optimization + // with reference-based function: + if ( ref ) + { + + // set reference: + ev->set_ref ( ref ); + + // launch the single optimization: + multi_launch_single_opt ( iter_dd , + mads_runs , + overall_bbe , + *ev , + stagnation_cnt , + multi_stats , + stop , + stop_reason ); + + delete ref; + ev->set_ref ( NULL ); + } + + // no reference available: two optimizations ( f1(x) and f2(x) ): + else + { + + // for the stagnation check: + const NOMAD::Eval_Point * pp_before; + int stagnation_cnt_before , overall_bbe_before; + bool check_1 = false; + + // loop on f1 and f2: + for ( i = 0 ; i < 2 ; ++i ) + { + + if ( stop ) + break; + + // minimize f2: + if ( i == 1 ) + { + + // new starting point: + best_f2 = _pareto_front->get_best_f2(); + if ( best_f2 ) + { + _p.set_EXTERN_SIGNATURE ( best_f2->get_signature() ); + _p.reset_X0(); + _p.set_X0 ( *best_f2 ); + } + else + _p.set_X0 ( *x0_tmp ); + + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + true ); // remove_stats_file = true + } + + // set weights/reference: + ev->set_weights ( 1-i , i ); + ev->set_ref ( NULL ); + + stagnation_cnt_before = stagnation_cnt; + overall_bbe_before = overall_bbe; + pp_before = ( _pareto_front->size() == 1 ) ? + _pareto_front->begin() : NULL; + + // launch the single optimization: + multi_launch_single_opt ( iter_dd , + mads_runs , + overall_bbe , + *ev , + stagnation_cnt , + multi_stats , + stop , + stop_reason ); + + // stagnation check: + if ( stagnation_cnt > stagnation_cnt_before && + overall_bbe == overall_bbe_before && + _pareto_front->size() == 1 && + _pareto_front->begin() == pp_before ) + { + + if ( i == 0 ) + check_1 = true; + else if ( check_1 ) + { + stop = true; + stop_reason = NOMAD::MULTI_STAGNATION; + } + } + } + } + + } // end of MULTI-MADS main loop + // --------------------------- + + + // parameters re-initialization and final displays: + if ( ! hasCategoricalVar ) // Dimension may change when categorical variables are present. This may pose problem for the check. Hence we add a test -> when categorical variables are present, the parameters are not set back to their initial state at the end of the multi-objective optimization. + { + _p.reset_X0(); + size_t nx0 = x0s.size(); + if ( nx0 > 0 ) + { + for ( size_t k = 0 ; k < nx0 ; ++k ) + { + _p.set_X0 ( *x0s[k] ); + delete x0s[k]; + } + } + else if ( !x0_cache_file.empty() ) + _p.set_X0 ( x0_cache_file ); + + if ( use_delta_crit ) + _p.set_MIN_POLL_SIZE ( original_min_poll_size ); - // multi-objective final displays: - if ( _p.get_nb_obj() > 1 ) { - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.open_block ( "NOMAD final display" ); - - display(); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block(); - } + } + _p.set_MAX_BB_EVAL ( max_bbe ); + _p.set_DISPLAY_DEGREE ( old_dd ); + _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); + _p.set_SOLUTION_FILE ( old_sol_file ); + _p.set_LH_SEARCH ( lh_p0 , lh_pi ); + _p.set_CACHE_SAVE_PERIOD ( old_csp ); + _p.set_L_CURVE_TARGET ( old_lct ); - } // end of the try block - - catch ( std::exception & e ) { - + + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + true ); // remove_stats_file = true + + // reset MADS stats from MULTI-MADS stats: + _stats = multi_stats; + + // final cache save (overwrite=true): + _ev_control.save_caches ( true ); + +#ifndef R_VERSION + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + { + std::ostringstream msg; + msg << "end of run (" << stop_reason << ")"; + out << std::endl << NOMAD::close_block ( msg.str() ) << std::endl; + } +#endif + + + // multi-objective final displays: + if ( _p.get_nb_obj() > 1 ) + { + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.open_block ( "NOMAD final display" ); + + display(); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block(); + } + + } // end of the try block + + catch ( std::exception & e ) + { + #ifdef USE_MPI - if ( NOMAD::Slave::are_running() ) - NOMAD::Slave::stop_slaves ( out ); + if ( NOMAD::Slave::are_running() ) + NOMAD::Slave::stop_slaves ( out ); #endif - - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , e.what() ); - } - - // stop the slaves: + + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , e.what() ); + } + + // stop the slaves: #ifdef USE_MPI - if ( NOMAD::Slave::are_running() && stop_slaves_here ) - NOMAD::Slave::stop_slaves ( out ); + if ( NOMAD::Slave::are_running() && stop_slaves_here ) + NOMAD::Slave::stop_slaves ( out ); #endif - - return stop_reason; + + return stop_reason; } /*---------------------------------------------------------*/ @@ -1209,152 +1265,172 @@ void NOMAD::Mads::iteration ( bool & stop , const NOMAD::Eval_Point *& new_feas_inc , const NOMAD::Eval_Point *& new_infeas_inc ) { - - bool forbid_poll_size_stop = false; - - // force quit (by pressing ctrl-c): - if ( !stop && NOMAD::Mads::_force_quit ) - { - stop = true; - stop_reason = NOMAD::CTRL_C; - return; - } - - // poll center selection: - ( ( _p.get_opt_only_sgte() ) ? - _sgte_barrier : _true_barrier ).select_poll_center ( success ); - - // displays: - const NOMAD::Display & out = _p.out(); - if ( out.get_iter_dd() == NOMAD::FULL_DISPLAY ) - out << std::endl - << NOMAD::open_block ( "MADS iteration " - + NOMAD::itos ( _stats.get_iterations() ) ) - << std::endl; - display_iteration_begin(); - - // SEARCH: - // ------- + + bool forbid_poll_size_stop = false; + + // force quit (by pressing ctrl-c): + if ( !stop && NOMAD::Mads::_force_quit ) + { + stop = true; + stop_reason = NOMAD::CTRL_C; + return; + } + + // poll center selection: + ( ( _p.get_opt_only_sgte() ) ? + _sgte_barrier : _true_barrier ).select_poll_center ( success ); + + // displays: + const NOMAD::Display & out = _p.out(); + if ( out.get_iter_dd() == NOMAD::FULL_DISPLAY ) + out << std::endl + << NOMAD::open_block ( "MADS iteration " + + NOMAD::itos ( _stats.get_iterations() ) ) + << std::endl; + display_iteration_begin(); + + // SEARCH: + // ------- search ( stop , stop_reason , success , new_feas_inc , new_infeas_inc ); - // POLL: - // ----- - if ( success != NOMAD::FULL_SUCCESS ) - poll ( stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc , - forbid_poll_size_stop ); - - // UPDATES: - // -------- - int old_ell = NOMAD::Mesh::get_mesh_index(); - - if ( !stop ) - { - - // mesh update: - NOMAD::Mesh::update ( success ); - - // check the min mesh/poll sizes stopping criteria: - _p.get_signature()->get_mesh().check_min_mesh_sizes ( _p.get_max_mesh_index() , - NOMAD::Mesh::get_mesh_index(), - stop , - stop_reason ); - - // if the Delta_k^p stopping criterion is met with integer variables, - // the last set of directions must have a minimal coordinate of 1; - // otherwise the stopping criterion is disabled at this iteration: - if ( forbid_poll_size_stop && stop && stop_reason == NOMAD::DELTA_P_MIN_REACHED ) + // POLL: + // ----- + if ( success != NOMAD::FULL_SUCCESS ) + poll ( stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc , + forbid_poll_size_stop ); + + // UPDATES: + // -------- + + NOMAD::Point old_r=_mesh->get_mesh_indices(); + + if ( !stop ) { - stop = false; - stop_reason = NOMAD::NO_STOP; - } - - // display: - if ( _p.out().get_iter_dd() == NOMAD::FULL_DISPLAY ) - _p.out() << std::endl << NOMAD::open_block ( "Mesh update" ) - << "previous mesh index: " << old_ell << std::endl - << "new mesh index : " << NOMAD::Mesh::get_mesh_index() << std::endl - << NOMAD::close_block() << std::endl; - - // periodic cache save (overwrite=false): - if ( _p.get_cache_save_period() > 0 && - _stats.get_iterations()%_p.get_cache_save_period() == - _p.get_cache_save_period() - 1 ) - _ev_control.save_caches ( false ); - } - - // number of iterations: - _stats.add_iteration(); - if ( !stop && - _p.get_max_iterations() > 0 && - _stats.get_iterations() >= _p.get_max_iterations() ) - { - stop = true; - stop_reason = NOMAD::MAX_ITER_REACHED; - } - - // max cache memory: - if ( !stop && - _p.get_max_cache_memory() > 0.0 && - _ev_control.get_cache().size_of() > 1048576*_p.get_max_cache_memory() ) - { - stop = true; - stop_reason = NOMAD::MAX_CACHE_MEMORY_REACHED; - } - - // L_CURVE_TARGET stopping criterion: - if ( _L_curve && !stop ) - { - int bbe = _stats.get_bb_eval(); - if ( success == NOMAD::FULL_SUCCESS ) + // OrthogonalMesh update using success status and direction of success (when present) + if ( new_feas_inc ) + { + _mesh=new_feas_inc->get_signature()->get_mesh(); + _mesh->update ( success, new_feas_inc->get_direction() ); + } + else if ( new_infeas_inc ) + { + _mesh=new_infeas_inc->get_signature()->get_mesh(); + _mesh->update ( success, new_infeas_inc->get_direction()); + } + else + _mesh->update ( success ); + + + _mesh->check_min_mesh_sizes( stop , stop_reason ); + + // if the Delta_k^p stopping criterion is met with integer variables, + // the last set of directions must have a minimal coordinate of 1; + // otherwise the stopping criterion is disabled at this iteration: + if ( forbid_poll_size_stop && stop && stop_reason == NOMAD::DELTA_P_MIN_REACHED ) + { + stop = false; + stop_reason = NOMAD::NO_STOP; + } + + // display: + if ( _p.out().get_iter_dd() == NOMAD::FULL_DISPLAY ) + { + _p.out() << std::endl << NOMAD::open_block ( "Orthogonal mesh update" ) + << "previous mesh indices: ( " << old_r << " )" << std::endl + << "new mesh indices : ( " << _mesh->get_mesh_indices() << " )" << std::endl + << NOMAD::close_block() << std::endl; + } + + // periodic cache save (overwrite=false): + if ( _p.get_cache_save_period() > 0 && + _stats.get_iterations()%_p.get_cache_save_period() == + _p.get_cache_save_period() - 1 ) + _ev_control.save_caches ( false ); + } + + // number of iterations: + _stats.add_iteration(); + if ( !stop && + _p.get_max_iterations() > 0 && + _stats.get_iterations() >= _p.get_max_iterations() ) { - if ( new_feas_inc ) - _L_curve->insert ( bbe , new_feas_inc->get_f() ); - } - else if ( success == NOMAD::UNSUCCESSFUL && _L_curve->check_stop ( bbe ) ) + stop = true; + stop_reason = NOMAD::MAX_ITER_REACHED; + } + + // max cache memory: + if ( !stop && + _p.get_max_cache_memory() > 0.0 && + _ev_control.get_cache().size_of() > 1048576*_p.get_max_cache_memory() ) { - stop = true; - stop_reason = NOMAD::L_CURVE_TARGET_REACHED; - } - } - - // call the user-defined function Evaluator::update_iteration(): - if ( _p.get_user_calls_enabled() ) - { - bool stop_before = stop; - _ev_control.get_evaluator()->update_iteration ( success , - _stats , - _ev_control , - _true_barrier , - _sgte_barrier , - *_pareto_front , - stop ); - if ( !stop_before && stop ) - stop_reason = NOMAD::USER_STOPPED; - } - - // if the algorithms stops, we set the mesh index to the value - // it had before the mesh update: - if ( stop ) - Mesh::set_mesh_index ( old_ell ); - - // displays at the end of an iteration: - display_iteration_end ( stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc ); + stop = true; + stop_reason = NOMAD::MAX_CACHE_MEMORY_REACHED; + } + + // L_CURVE_TARGET stopping criterion: + if ( _L_curve && !stop ) + { + int bbe = _stats.get_bb_eval(); + if ( success == NOMAD::FULL_SUCCESS ) + { + if ( new_feas_inc ) + _L_curve->insert ( bbe , new_feas_inc->get_f() ); + } + else if ( success == NOMAD::UNSUCCESSFUL && _L_curve->check_stop ( bbe ) ) + { + stop = true; + stop_reason = NOMAD::L_CURVE_TARGET_REACHED; + } + } + + // call the user-defined function Evaluator::update_iteration(): + if ( _p.get_user_calls_enabled() ) + { + bool stop_before = stop; + + NOMAD::Pareto_Front * pf = ( ( _pareto_front ) ? _pareto_front:(new NOMAD::Pareto_Front) ); + + _ev_control.get_evaluator()->update_iteration ( success , + _stats , + _ev_control , + _true_barrier , + _sgte_barrier , + *pf , + stop ); + + if ( ! _pareto_front ) + delete pf; + + + if ( !stop_before && stop ) + stop_reason = NOMAD::USER_STOPPED; + } + + // if the algorithms stops, we set the mesh index to the value + // it had before the mesh update: + if ( stop ) + { + _mesh->set_mesh_indices( old_r ); + } + + // displays at the end of an iteration: + display_iteration_end ( stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc ); - // displays: - if ( out.get_iter_dd() == NOMAD::FULL_DISPLAY ) - out << std::endl - << NOMAD::close_block ( "end of iteration " - + NOMAD::itos ( _stats.get_iterations()-1 ) ); + // displays: + if ( out.get_iter_dd() == NOMAD::FULL_DISPLAY ) + out << std::endl + << NOMAD::close_block ( "end of iteration " + + NOMAD::itos ( _stats.get_iterations()-1 ) ); } /*---------------------------------------------------------*/ @@ -1384,8 +1460,7 @@ void NOMAD::Mads::poll ( bool & stop , const NOMAD::Eval_Point * x; - int k; - int offset = 0; + size_t offset = 0; std::vector<NOMAD::Signature *> signatures; @@ -1423,17 +1498,14 @@ void NOMAD::Mads::poll ( bool & stop , { // add the poll center signature signatures.push_back(poll_center->get_signature()); - + // Creation of the poll directions set_poll_directions ( dirs[i_pc] , i_pc , offset , *poll_center , stop , stop_reason ); // Reduction is applied only to achieve ortho n+1 - reducePollToNDir=dirs_have_orthomads_np1(dirs[i_pc]); - - + reducePollToNDir=dirs_have_orthomads_np1(dirs[i_pc]); + // creation of the poll trial points in the evaluator control: - k = 0; - if (reducePollToNDir) { @@ -1443,46 +1515,46 @@ void NOMAD::Mads::poll ( bool & stop , _ev_control_for_sorting.clear_eval_lop(); - // Sort the directions only if mesh is not max - if (NOMAD::Mesh::mesh_index_is_not_max() ) - { - - // 1st sorting of points based on feas. or infeas. success direction. IMPORTANT removes out of bounds -> this justifies to proceede in two steps - set_poll_trial_points(dirs[i_pc],offset,*poll_center,stop,stop_reason,true); - if (stop) - { - delete[] dirs; - delete[] reducedPollDirs; - return; - } - + // Sort the directions only if mesh is not finest + if ( ! _mesh->is_finest() ) + { + + // 1st sorting of points based on feas. or infeas. success direction. IMPORTANT removes out of bounds -> this justifies to proceede in two steps + set_poll_trial_points(dirs[i_pc],offset,*poll_center,stop,stop_reason,true); + if (stop) + { + delete[] dirs; + delete[] reducedPollDirs; + return; + } + #ifdef USE_MPI - // asynchronous mode: wait for truth evaluations in progress: - if ( _p.get_asynchronous() ) - { - std::list<const NOMAD::Eval_Point *> eval_pts; - _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - success , - eval_pts ); - } + // asynchronous mode: wait for truth evaluations in progress: + if ( _p.get_asynchronous() ) + { + std::list<const NOMAD::Eval_Point *> eval_pts; + _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + success , + eval_pts ); + } #endif - - // 2nd sorting of points based on model and surrogate if available - _ev_control_for_sorting.ordering_lop( NOMAD::POLL,stop,stop_reason,_true_barrier,_sgte_barrier ); - if (stop) - { - delete[] dirs; - delete[] reducedPollDirs; - return; - } - } + + // 2nd sorting of points based on model and surrogate if available + _ev_control_for_sorting.ordering_lop( NOMAD::POLL,stop,stop_reason,_true_barrier,_sgte_barrier ); + if (stop) + { + delete[] dirs; + delete[] reducedPollDirs; + return; + } + } + - // reduce the number of poll direction using dir indices from ev_control_for_sorting and original poll directions (reducedPollDirs) bool hasBeenReduced=set_reduced_poll_to_n_directions(reducedPollDirs[i_pc],*poll_center); @@ -1498,6 +1570,13 @@ void NOMAD::Mads::poll ( bool & stop , set_poll_trial_points(dirs[i_pc],offset,*poll_center,stop,stop_reason,false); offset = dirs[i_pc].size(); + if (!reducePollToNDir) + { + // 2nd sorting of points based on model and surrogate if available + _ev_control.ordering_lop( NOMAD::POLL,stop,stop_reason,_true_barrier,_sgte_barrier ); + } + + } if (stop) @@ -1527,7 +1606,7 @@ void NOMAD::Mads::poll ( bool & stop , + NOMAD::itos ( poll_pts.size() ) + " poll trial points." ); else - out << std::endl << NOMAD::open_block ( "re-ordered and reduced (dynamic directions maybe added after evaluations) list of " + out << std::endl << NOMAD::open_block ( "re-ordered and reduced (dynamic directions may be added after evaluations) list of " + NOMAD::itos ( poll_pts.size() ) + " poll trial points" ); @@ -1580,7 +1659,7 @@ void NOMAD::Mads::poll ( bool & stop , offset=0; while ( true ) { - if ( poll_center && dirs_have_orthomads_np1(reducedPollDirs[i_pc])) + if ( poll_center && NOMAD::Mads::dirs_have_orthomads_np1(reducedPollDirs[i_pc])) { std::list<NOMAD::Direction> dyn_dirs; @@ -1598,10 +1677,10 @@ void NOMAD::Mads::poll ( bool & stop , *evaluated_pts ); } #endif - + bool hasNewDynDir=get_dynamic_directions (reducedPollDirs[i_pc], - dyn_dirs, - *poll_center); + dyn_dirs, + *poll_center); // Set new poll points obtained dynamically @@ -1622,7 +1701,7 @@ void NOMAD::Mads::poll ( bool & stop , return; } } - offset = static_cast<int>(dyn_dirs.size()); + offset = dyn_dirs.size(); } // loop increment: if ( i_pc == NOMAD::PRIMARY ) @@ -1780,36 +1859,41 @@ void NOMAD::Mads::poll ( bool & stop , bool NOMAD::Mads::set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & dirs, const NOMAD::Eval_Point & poll_center) { - NOMAD::Signature * cur_signature=poll_center.get_signature(); - int n = cur_signature->get_n(); - int n_cat=cur_signature->get_n_categorical(); + NOMAD::Signature * cur_signature = poll_center.get_signature(); + size_t n = cur_signature->get_n()-cur_signature->get_nb_fixed_variables() ; + + // No direction for categorical variables + size_t n_cat = cur_signature->get_n_categorical(); // Verify that enough directions for reduction are provided - if (static_cast<int>(dirs.size())<n-n_cat) + if ( dirs.size()<n-n_cat ) return false; // Maximum number of direction groups std::list<NOMAD::Direction>::iterator itDirs; - int maxDirGroupIndex=0; - int dgi; + size_t maxDirGroupIndex=0; + size_t dgi; for (itDirs=dirs.begin();itDirs!=dirs.end() ; ++itDirs) { dgi=(*itDirs).get_dir_group_index(); if (dgi>maxDirGroupIndex) maxDirGroupIndex=dgi; } - + + std::list<NOMAD::Direction> TmpDirs(dirs); + dirs.clear(); + // Loop on each direction group for (dgi=0;dgi<=maxDirGroupIndex;++dgi) { - + // Get all poll directions with a given direction group index + Get a vector of unique indices for those directions std::vector<NOMAD::Direction> pollDirs; std::vector<int> pollDirIndices; bool containsOrthoMads=false; - for (itDirs=dirs.begin();itDirs!=dirs.end() ; ++itDirs) + for (itDirs=TmpDirs.begin();itDirs!=TmpDirs.end() ; ++itDirs) { - if ((*itDirs).get_dir_group_index()==dgi) + if ( static_cast<size_t>((*itDirs).get_dir_group_index()) == dgi ) { pollDirs.push_back(*itDirs); pollDirIndices.push_back((*itDirs).get_index()); @@ -1819,9 +1903,10 @@ bool NOMAD::Mads::set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & } - // Sorted directions only if mesh_index_is_not_max - std::vector<NOMAD::Direction> sortedDirs(pollDirs); - if ( NOMAD::Mesh::mesh_index_is_not_max()) + std::list<NOMAD::Direction> sortedDirs; + std::list<NOMAD::Direction>::iterator itSortedDirs; + // Sort the directions only if mesh is not finest + if ( !_mesh->is_finest() ) { const std::set<NOMAD::Priority_Eval_Point> & LOP=_ev_control_for_sorting.get_eval_lop(); @@ -1830,20 +1915,26 @@ bool NOMAD::Mads::set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , "Mads::set_reduced_poll_to_n_directions(): the _ev_control_for_sorting does not have a list of evaluation points." ); - + // Get all directions from ev_control ordered lop (list of evaluation points) with a given direction group index and given poll center - // Get a vector of unique indices for those directions - std::vector<int> sortedDirIndices; + // Get a set of unique indices of those directions + std::list<int> sortedDirIndices; + std::set<int> indices; + std::list<int>::iterator itSortedDirIndices; std::set<NOMAD::Priority_Eval_Point>::const_iterator citLOP; for (citLOP=LOP.begin();citLOP!=LOP.end();++citLOP) { const NOMAD::Eval_Point *eval_point=(*citLOP).get_point(); - if (eval_point->get_direction()->get_dir_group_index()==dgi && - *(eval_point->get_poll_center())==poll_center) - { - sortedDirIndices.push_back(eval_point->get_direction()->get_index()); - } - + if ( static_cast<size_t>(eval_point->get_direction()->get_dir_group_index()) == dgi && + *(eval_point->get_poll_center())==poll_center) + { + int index=eval_point->get_direction()->get_index(); + if ( indices.size() == 0 || indices.find(index) == indices.end() ) // if the index is already in indices no need to add it in sortedDirIndices to avoid duplicate. + sortedDirIndices.push_back(index); + indices.insert(index); // If the index is already in the set IT IS NOT INSERTED --> set of unique sort integers + + } + } if ( sortedDirIndices.size()==0 ) @@ -1854,57 +1945,69 @@ bool NOMAD::Mads::set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & // --> complete sorted direction with remaining directions in poll dirs // // 2 - Add poll directions (from tmpDirs) in the same order as sorted direction indices (from ev_control) - std::vector<int>::iterator itSortedDirIndices,itPollDirIndices; + std::vector<int>::iterator itPollDirIndices; std::vector<NOMAD::Direction>::iterator itPollDirs=pollDirs.begin(); - int pos,maxPos=0; - for (itPollDirIndices=pollDirIndices.begin();itPollDirIndices!=pollDirIndices.end();++itPollDirIndices,++itPollDirs) + size_t pos; + for ( itSortedDirIndices = sortedDirIndices.begin() ; itSortedDirIndices != sortedDirIndices.end() ; ++itSortedDirIndices) { - itSortedDirIndices=std::find(sortedDirIndices.begin(),sortedDirIndices.end(),(*itPollDirIndices)); - if (itSortedDirIndices!=sortedDirIndices.end()) + itPollDirIndices=find(pollDirIndices.begin(),pollDirIndices.end(),*itSortedDirIndices); + if ( itPollDirIndices!=pollDirIndices.end() ) { - pos=distance(sortedDirIndices.begin(),itSortedDirIndices); - sortedDirs[pos]=*itPollDirs; - if (pos > maxPos) maxPos=pos; + pos=distance(pollDirIndices.begin(),itPollDirIndices); + itPollDirs=pollDirs.begin(); + std::advance(itPollDirs,pos); + sortedDirs.push_back(*itPollDirs); } - else // Handle the case where poll direction not in sorted directions - sortedDirs[maxPos+1]=*itPollDirs; - } + } + // 3 - complete with remaining pollDirs directions + if ( sortedDirs.size() != pollDirs.size() ) + { + itPollDirs=pollDirs.begin(); + for ( itPollDirIndices = pollDirIndices.begin() ; itPollDirIndices != pollDirIndices.end() ; ++itPollDirIndices,++itPollDirs) + { + itSortedDirIndices=find(sortedDirIndices.begin(),sortedDirIndices.end(),*itPollDirIndices); + if ( itSortedDirIndices == sortedDirIndices.end() ) + // Handle the case where poll direction not in sorted directions --> put it at the end + sortedDirs.push_back(*itPollDirs); + } + } + } + else + sortedDirs.assign(pollDirs.begin(),pollDirs.end()); - // Make a spanning set of directions + // Make a spanning set of directions (this is slightly different Ortho n+1 paper but still we have the garantee that Dk grows asymptotically dense because D^o_k has not been sorted if mesh_index_is_max) // Sequentially add sorted directions that increase the rank in two situations: - // - If mesh_index_is_not_max -> consider all directions for adding -> n directions - // - If mesh index_is_max but some ORTHO MADS directions are present -> only consider ortho mads dir for adding -> n directions + // - If mesh is not finest -> consider all directions for adding -> n directions + // - If mesh is finest but some ORTHO MADS directions are present -> only consider ortho mads dir for adding -> n directions // - Else, all directions are considered -> more than n directions // See paper Ortho n+1 paper for details - std::vector<NOMAD::Direction>::iterator itSortedDirs; - dirs.clear(); - int currentRank=0; + + + size_t currentRank=get_rank_from_dirs(dirs); for (itSortedDirs=sortedDirs.begin();itSortedDirs!=sortedDirs.end();++itSortedDirs) { dirs.push_back(*itSortedDirs); - - if (NOMAD::Mesh::mesh_index_is_not_max() || (!NOMAD::Mesh::mesh_index_is_not_max() && containsOrthoMads)) + if ( !_mesh->is_finest() || ( _mesh->is_finest() && containsOrthoMads)) { - int rank=get_rank_from_dirs(dirs); + size_t rank=get_rank_from_dirs(dirs); if (rank>currentRank && rank<=n-n_cat && NOMAD::dir_is_orthomads((*itSortedDirs).get_type())) currentRank++; else dirs.pop_back(); } } - + } const NOMAD::Display & out = _p.out(); NOMAD::dd_type display_degree = out.get_poll_dd(); - - if ( static_cast<int>(dirs.size())!=n-n_cat ) + if ( dirs.size()!=n-n_cat ) { if (display_degree == NOMAD::FULL_DISPLAY ) { out << std::endl << NOMAD::open_block ( "The number of reduced directions is lower than n-n_categorical: "); - out << dirs.size() << std::endl; + out << dirs.size() << ". No reduction is performed." << std::endl; out << NOMAD::close_block(); } return false; @@ -1921,25 +2024,28 @@ int NOMAD::Mads::get_rank_from_dirs(const std::list<NOMAD::Direction> & dirs) return 0; std::list<NOMAD::Direction>::const_iterator it=dirs.begin(); - int m=(*it).size(); - int n=dirs.size(); + size_t m=(*it).size(); + size_t n=dirs.size(); double ** M = new double *[m]; - for (int i=0 ; i<m ; ++i ) { + for (size_t i=0 ; i<m ; ++i ) + { it=dirs.begin(); M[i] = new double[n]; - for (int j = 0 ; j < n ; ++j ){ - M[i][j] = (*it)[i].value() ; + for (size_t j = 0 ; j < n ; ++j ) + { + M[i][j] = (*it)[static_cast<int>(i)].value() ; ++it; } } int rank=NOMAD::get_rank(M,m,n); - for (int i = 0 ; i < m ; ++i ) { - delete M[i]; + for (size_t i = 0 ; i < m ; ++i ) + { + delete[] M[i]; } - delete M; + delete[] M; return rank; } @@ -1949,8 +2055,8 @@ int NOMAD::Mads::get_rank_from_dirs(const std::list<NOMAD::Direction> & dirs) /* (private) */ /*---------------------------------------------------------------------------------------*/ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll_center , - const std::list<NOMAD::Direction> & dirs , - NOMAD::Point & prospect_point ) + const std::list<NOMAD::Direction> & dirs , + NOMAD::Point & prospect_point ) { const NOMAD::Display & out = _p.out(); @@ -1961,18 +2067,17 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll // active cache: const NOMAD::Cache & cache = get_cache(); - // mesh index and poll size: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - NOMAD::Point delta_p,delta_m; + NOMAD::Point delta,Delta; NOMAD::Signature * signature=poll_center.get_signature(); - signature->get_mesh().get_delta_p ( delta_p , mesh_index ); - signature->get_mesh().get_delta_m ( delta_m , mesh_index ); + _mesh->get_delta ( delta ); + _mesh->get_Delta ( Delta ); // compute the interpolation radius: points in Y must be at - // a max distance of ms_radius_factor times Delta^p_k: - NOMAD::Point interpolation_radius = delta_p; + // a max distance of ms_radius_factor times Delta^k: + NOMAD::Point interpolation_radius = Delta; interpolation_radius *= _p.get_model_quad_radius_factor(); + // Epsilon for quad model hypercube scaling NOMAD::Double epsilon = _p.get_model_np1_quad_epsilon(); @@ -1980,9 +2085,9 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll out << std::endl << NOMAD::open_block ( "Quadratic model for (n+1)th prospect point") << std::endl << "model construction for " << ev_type << std::endl << "nbr of cache pts: " << cache.size() << std::endl - << "mesh index : " << mesh_index << std::endl + << "mesh indices : ( " << _mesh->get_mesh_indices () << " )" << std::endl << "poll center : ( " << poll_center << " )" << std::endl - << "poll size : ( " << delta_p << " )" << std::endl + << "poll size : ( " << Delta << " )" << std::endl << "interpol. radius: ( " << interpolation_radius << " )" << std::endl << "epsilon hypercube: ( " << epsilon << " )" << std::endl;; #endif @@ -2022,7 +2127,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll #endif // define scaling with rotation: obtain an hypercube [0,1]^n formed by truncated directions - model.define_scaling_by_directions ( dirs, delta_m,epsilon); + model.define_scaling_by_directions ( dirs, delta ,epsilon); #ifdef DEBUG out << std::endl; @@ -2032,7 +2137,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll // error check: if ( model.get_error_flag() ) tmp_stats.add_construction_error(); - + // no model error: else { @@ -2049,7 +2154,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll model.display_Y_error ( out ); #endif - + // count model: if ( ev_type == NOMAD::TRUTH ) tmp_stats.add_nb_truth(); @@ -2099,9 +2204,6 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll // parameters creation: NOMAD::Parameters model_param ( out ); - // random seed: - model_param.set_SEED ( _p.get_seed() + 10 ); - // number of variables: model_param.set_DIMENSION ( n ); @@ -2114,7 +2216,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll // starting points: model_param.set_X0 ( NOMAD::Point ( n , 500.0 ) ); - + // fixed variables: for ( i = 0 ; i < n ; ++i ) if ( model.variable_is_fixed(i) || _p.variable_is_fixed(i) ) @@ -2128,14 +2230,12 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll // display: model_param.set_DISPLAY_DEGREE ( NOMAD::NO_DISPLAY ); - // mesh: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - int min_mesh_index = NOMAD::Mesh::get_min_mesh_index(); - int max_mesh_index = NOMAD::Mesh::get_max_mesh_index(); - int max_halton_index = NOMAD::Mesh::get_max_halton_index(); - - NOMAD::Mesh::init ( 4.0 , 1 , -1 , 0 ); - + // mesh: use isotropic mesh + model_param.set_ANISOTROPIC_MESH ( false ); + model_param.set_MESH_UPDATE_BASIS ( 4.0 ); + model_param.set_MESH_COARSENING_EXPONENT ( 1 ); + model_param.set_MESH_REFINING_EXPONENT ( -1 ); + model_param.set_INITIAL_MESH_INDEX ( 0 ); model_param.set_INITIAL_MESH_SIZE ( NOMAD::Point ( n , 100.0 ) ); // maximum number of evaluations: @@ -2164,7 +2264,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll NOMAD::Point ub ( n , 1000.0 ); model_param.set_LOWER_BOUND ( lb ); model_param.set_UPPER_BOUND ( ub ); - + try { @@ -2176,33 +2276,30 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll if (model_param.get_nb_obj()==2) ev =new NOMAD::Multi_Obj_Quad_Model_Evaluator( model_param , model ); else - ev=new NOMAD::Single_Obj_Quad_Model_Evaluator(model_param, model); + ev=new NOMAD::Single_Obj_Quad_Model_Evaluator( model_param , model ); // algorithm creation and execution: NOMAD::Mads mads ( model_param , ev ); + + NOMAD::Phase_One_Evaluator * p1ev=NULL; + if ( model_param.get_nb_obj() >= 2 && ! flag_check_bimads ) + { + p1ev = new NOMAD::Phase_One_Evaluator ( model_param , *ev ); + mads.get_evaluator_control().set_evaluator ( p1ev ); + } NOMAD::stop_type st = mads.run(); delete ev; - + if (p1ev) + delete p1ev; + // reset flags: NOMAD::Mads::set_flag_check_bimads ( flag_check_bimads ); NOMAD::Mads::set_flag_reset_mesh ( flag_reset_mesh ); NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); - // reset mesh to what it was before: - NOMAD::Mesh::init ( _p.get_mesh_update_basis().value() , - _p.get_mesh_coarsening_exponent() , - _p.get_mesh_refining_exponent() , - _p.get_initial_mesh_index() ); - - NOMAD::Mesh::set_max_halton_index ( max_halton_index ); - NOMAD::Mesh::set_mesh_index ( mesh_index ); - NOMAD::Mesh::set_min_mesh_index ( min_mesh_index ); - NOMAD::Mesh::set_max_mesh_index ( max_mesh_index ); - - // check the stopping criterion: if ( st == NOMAD::CTRL_C || st == NOMAD::MAX_CACHE_MEMORY_REACHED ) { std::ostringstream oss; @@ -2216,6 +2313,7 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll { NOMAD::Display out_tmp = out; out_tmp.set_degrees ( NOMAD::NORMAL_DISPLAY ); + out_tmp.open_block("Optimization results"); mads.display ( out_tmp ); } @@ -2288,13 +2386,14 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll out << "( " << prospect_point << " )" << std::endl; else out << "failure" << std::endl; - } - - if ( _p.get_display_degree() == NOMAD::FULL_DISPLAY ) - { + out << NOMAD::close_block() << std::endl; } +#ifdef DEBUG + out << NOMAD::close_block() << std::endl; +#endif + return !error; } @@ -2303,62 +2402,65 @@ bool NOMAD::Mads::optimize_quad_model ( const NOMAD::Eval_Point & poll /* set the poll directions based on signatures (private) */ /*----------------------------------------------------------------*/ void NOMAD::Mads::set_poll_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type i_pc , - int offset , - const NOMAD::Eval_Point & poll_center , - bool & stop , - NOMAD::stop_type & stop_reason ) + NOMAD::poll_type i_pc , + size_t offset , + const NOMAD::Eval_Point & poll_center , + bool & stop , + NOMAD::stop_type & stop_reason ) { - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_poll_dd(); - - std::list<NOMAD::Direction>::const_iterator it , end; - - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - if ( i_pc == NOMAD::SECONDARY ) - out << "secondary "; - out << "poll center: ( "; - poll_center.Point::display ( out, " ", 2, NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // get the poll center's signature: - NOMAD::Signature * cur_signature = poll_center.get_signature(); - - if ( !cur_signature ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::poll(): could not get the poll center's signature" ); - - int n = cur_signature->get_n(); - - if ( n != poll_center.size() ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::poll(): the poll center has an incompatible signature" ); + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_poll_dd(); + + std::list<NOMAD::Direction>::const_iterator it , end; + + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + if ( i_pc == NOMAD::SECONDARY ) + out << "secondary "; + out << "poll center: ( "; + poll_center.Point::display ( out, " ", 2, NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // get the poll center's signature: + NOMAD::Signature * cur_signature = poll_center.get_signature(); + + if ( !cur_signature ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::poll(): could not get the poll center's signature" ); + + int n = cur_signature->get_n(); + + if ( n != poll_center.size() ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::poll(): the poll center has an incompatible signature" ); + + // get directions from the signature: + cur_signature->get_directions ( dirs , + i_pc , + poll_center ); + - // get directions from the signature: - cur_signature->get_directions ( dirs , - i_pc , - poll_center , - NOMAD::Mesh::get_mesh_index() ); - - int k = 0; - for ( it = dirs.begin() ; it != dirs.end() ; ++it, k++ ) - it->set_index ( offset + k ); - - if ( !stop && dirs.empty() ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "Mads::poll(): could not get directions: stop" - << std::endl << NOMAD::close_block() << std::endl; - stop = true; - stop_reason = NOMAD::MESH_PREC_REACHED; - return; + + size_t k = 0; + for ( it = dirs.begin() ; it != dirs.end() ; ++it, ++k ) + it->set_index ( static_cast<int>(offset + k) ); + - } - - // displays: + if ( !stop && dirs.empty() ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "Mads::poll(): could not get directions: stop" + << std::endl << NOMAD::close_block() << std::endl; + stop = true; + stop_reason = NOMAD::MESH_PREC_REACHED; + return; + + } + + + // displays: if ( display_degree == NOMAD::FULL_DISPLAY ) { end = dirs.end(); @@ -2386,7 +2488,7 @@ bool NOMAD::Mads::dirs_have_orthomads_np1( const std::list<NOMAD::Direction> & d { std::list<NOMAD::Direction>::const_iterator it , end = dirs.end(); for ( it = dirs.begin() ; it != end ; ++it ) - if ( (*it).get_type()==NOMAD::ORTHO_NP1_QUAD || + if ( (*it).get_type()==NOMAD::ORTHO_NP1_QUAD || (*it).get_type()==NOMAD::ORTHO_NP1_NEG) return true; return false; @@ -2412,13 +2514,12 @@ bool NOMAD::Mads::dir_from_model_opt( const std::list<NOMAD::Direction> & dirs) /* set the poll trial points based on poll directions (private) */ /*----------------------------------------------------------------*/ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, - int offset, + size_t offset, const NOMAD::Eval_Point & poll_center, bool & stop, NOMAD::stop_type &stop_reason, bool sorting) { - int mesh_index = NOMAD::Mesh::get_mesh_index(); NOMAD::Signature * cur_signature=poll_center.get_signature(); NOMAD::poll_center_type pc_type=( poll_center.is_feasible ( _p.get_h_min() ) ) ? NOMAD::FEASIBLE : NOMAD::INFEASIBLE; @@ -2434,7 +2535,6 @@ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, const NOMAD::Display & out = _p.out(); NOMAD::dd_type display_degree = out.get_poll_dd(); - int k=0; for ( it = dirs.begin() ; it != dirs.end() ; ++it ) { @@ -2445,23 +2545,14 @@ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, // equal to 1 with dir=1: the variables are set to 0 (1+1=0 in binary): for (int i = 0 ; i < n ; ++i ) (*pt)[i] = ( bbit[i]==NOMAD::BINARY && (*dir)[i]==1.0 && (poll_center)[i]==1.0 ) ? 0.0 : (*pt)[i] = (poll_center)[i] + (*dir)[i]; + - // we check that the new poll trial point is different than the poll center - // (this happens when the mesh size becomes too small): - if ( !stop && pt->Point::operator == ( poll_center ) ) - { + if ( pt->Point::operator == ( poll_center ) ) delete pt; - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "Mads::poll(): could not generate poll trial points: stop" - << std::endl << NOMAD::close_block() << std::endl; - stop = true; - stop_reason = NOMAD::MESH_PREC_REACHED; - return; - } - + else + { pt->set_signature ( cur_signature ); pt->set_direction ( dir ); - pt->set_mesh_index ( &mesh_index ); pt->set_poll_center_type ( pc_type ); pt->set_poll_center ( &poll_center ); @@ -2472,7 +2563,7 @@ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, NOMAD::Random_Pickup rp ( nb_dirs ); pt->set_rand_eval_priority ( rp.pickup() ); } - + if (!sorting) _ev_control.add_eval_point ( pt , display_degree , @@ -2491,10 +2582,21 @@ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, NOMAD::Double() , NOMAD::Double() ); } - + ++k; + } } + if ( k==0 ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "Mads::poll(): could not generate poll trial points: stop" + << std::endl << NOMAD::close_block() << std::endl; + stop = true; + stop_reason = NOMAD::MESH_PREC_REACHED; + } + + return; } @@ -2503,36 +2605,38 @@ void NOMAD::Mads::set_poll_trial_points (std::list<NOMAD::Direction> &dirs, /* compute the poll directions dynamically (private) */ /*-------------------------------------------------------------*/ bool NOMAD::Mads::get_dynamic_directions (const std::list<NOMAD::Direction> & dirs, - std::list<NOMAD::Direction> & newDirs, - const NOMAD::Eval_Point & poll_center ) + std::list<NOMAD::Direction> & newDirs, + const NOMAD::Eval_Point & poll_center ) { const NOMAD::Signature * cur_signature=poll_center.get_signature(); - int n=cur_signature->get_n(); - int n_cat=cur_signature->get_n_categorical(); + size_t n = cur_signature->get_n()-cur_signature->get_nb_fixed_variables(); + size_t n_cat = cur_signature->get_n_categorical(); const NOMAD::Display & out = _p.out(); NOMAD::dd_type display_degree = out.get_poll_dd(); // Dynamic completion only if sufficient directions provided: (n-n_cat)->(n-n_cat)+1 - if (static_cast<int>(dirs.size())<n-n_cat) + if ( dirs.size() < n-n_cat ) return false; - + // Get the maximum number of direction groups std::list<NOMAD::Direction>::const_iterator itDir; int maxDirGroupIndex=0; int dgi; - for (itDir=dirs.begin();itDir!=dirs.end() ; ++itDir) { + for (itDir=dirs.begin();itDir!=dirs.end() ; ++itDir) + { dgi=(*itDir).get_dir_group_index(); - if (dgi>maxDirGroupIndex) maxDirGroupIndex=dgi; + if (dgi>maxDirGroupIndex) + maxDirGroupIndex=dgi; } // Loop on each direction group to obtain a new direction for (dgi=0;dgi<=maxDirGroupIndex;++dgi) { int maxIndex=0; - + // 1 - Search directions having the same direction group index std::list<NOMAD::Direction> rDirs; std::list<NOMAD::Double>::iterator it_fv; @@ -2541,7 +2645,7 @@ bool NOMAD::Mads::get_dynamic_directions (const std::list<NOMAD::Direction> & di if ((*itDir).get_index()>maxIndex) maxIndex=(*itDir).get_index(); if ((*itDir).get_dir_group_index()==dgi) - rDirs.push_back(*itDir); + rDirs.push_back(*itDir); } // 2 - add a dynamic direction from a quad model optimization or sum of direction negatives @@ -2553,18 +2657,27 @@ bool NOMAD::Mads::get_dynamic_directions (const std::list<NOMAD::Direction> & di } } - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << std::endl - << NOMAD::open_block ( "Added (n+1)th poll direction(s) (include mesh size parameter)" ); - for ( itDir = newDirs.begin() ; itDir != newDirs.end() ; ++itDir ) { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << std::endl; + if ( newDirs.size()!= 0 ) + out << NOMAD::open_block ( "Added (n+1)th poll direction(s) (include mesh size parameter)" ); + else + out << NOMAD::open_block ( "Cannot generate a (n+1)th poll direction" ); + + for ( itDir = newDirs.begin() ; itDir != newDirs.end() ; ++itDir ) + { out << "dir "; - out.display_int_w ( (*itDir).get_index() , newDirs.size() ); + out.display_int_w ( (*itDir).get_index() , static_cast<int>(newDirs.size()) ); out << " : " << *itDir << std::endl; } out.close_block(); out << std::endl; } + + if ( newDirs.size()==0 ) + return false; return true; @@ -2581,13 +2694,13 @@ bool NOMAD::Mads::get_dynamic_directions (const std::list<NOMAD::Direction> & di /* function evaluations in Mesh Adaptive Direct Search Algorithms*/ /*----------------------------------------------------------------*/ NOMAD::Direction NOMAD::Mads::get_single_dynamic_direction (const std::list<NOMAD::Direction> & dirs, - const NOMAD::Eval_Point & poll_center) + const NOMAD::Eval_Point & poll_center) { const NOMAD::Signature * cur_signature=poll_center.get_signature(); int n=cur_signature->get_n(); NOMAD::Direction Vb1( n , 0.0 ,NOMAD::UNDEFINED_DIRECTION); - + std::vector<NOMAD::Double> alpha; NOMAD::Double f_pc=(poll_center.is_feasible(_p.get_h_min())) ? poll_center.get_f():poll_center.get_h(); @@ -2622,15 +2735,15 @@ NOMAD::Direction NOMAD::Mads::get_single_dynamic_direction (const std::list<NOMA // Update the new directions depending on the input_types const std::vector<NOMAD::bb_input_type> & input_types=cur_signature->get_input_types(); - int mesh_index = NOMAD::Mesh::get_mesh_index(); - NOMAD::Point delta_p; - cur_signature->get_mesh().get_delta_p ( delta_p , mesh_index ); - NOMAD::Point delta_m; - cur_signature->get_mesh().get_delta_m ( delta_m , mesh_index ); + + NOMAD::Point delta,Delta; + _mesh->get_delta ( delta ); + _mesh->get_Delta ( Delta ); bool isZero=true; for (int i=0; i<n; ++i) { - NOMAD::Double v=V[i].value(),vb1=Vb1[i].value(),dm=delta_m[i].value(),dp=delta_p[i].value(); + NOMAD::Double v=V[i].value(),vb1=Vb1[i].value(),dm=delta[i].value(),dp=Delta[i].value(); + // Continous variables ---> rounding towards mesh node. if (input_types[i]==NOMAD::CONTINUOUS) { @@ -2680,48 +2793,55 @@ NOMAD::Direction NOMAD::Mads::get_single_dynamic_direction (const std::list<NOMA /*----------------------------------------------------------------*/ void NOMAD::Mads::check_directions ( bool & forbid_poll_size_stop ) { - if ( !_p.get_min_poll_size_defined() ) { - - NOMAD::Double v , min; - const NOMAD::Point * dir; - int i , n; - - const NOMAD::Signature * signature; - - const std::set<NOMAD::Priority_Eval_Point> & poll_pts = _ev_control.get_eval_lop(); - std::set<NOMAD::Priority_Eval_Point>::const_iterator end = poll_pts.end() , it; - for ( it = poll_pts.begin() ; it != end ; ++it ) { - - signature = it->get_point()->get_signature(); - - if ( signature ) { - - dir = it->get_point()->get_direction(); - - if ( dir ) { - - n = dir->size(); - - if ( n == signature->get_n() ) { - - const std::vector<NOMAD::bb_input_type> & bbit - = signature->get_input_types(); - - for ( i = 0 ; i < n ; ++i ) { - if ( bbit[i] == NOMAD::INTEGER ) { - v = (*dir)[i].abs(); - if ( v.is_defined() && v > 0.0 && ( !min.is_defined() || v < min ) ) - min = v; - } - } - } - } - } - } - - if ( min.is_defined() && min > 1.0 ) - forbid_poll_size_stop = true; - } + if ( !_p.get_min_poll_size_defined() ) + { + + NOMAD::Double v , min; + const NOMAD::Point * dir; + int i , n; + + const NOMAD::Signature * signature; + + const std::set<NOMAD::Priority_Eval_Point> & poll_pts = _ev_control.get_eval_lop(); + std::set<NOMAD::Priority_Eval_Point>::const_iterator end = poll_pts.end() , it; + for ( it = poll_pts.begin() ; it != end ; ++it ) + { + + signature = it->get_point()->get_signature(); + + if ( signature ) + { + + dir = it->get_point()->get_direction(); + + if ( dir ) + { + + n = dir->size(); + + if ( n == signature->get_n() ) + { + + const std::vector<NOMAD::bb_input_type> & bbit + = signature->get_input_types(); + + for ( i = 0 ; i < n ; ++i ) + { + if ( bbit[i] == NOMAD::INTEGER ) + { + v = (*dir)[i].abs(); + if ( v.is_defined() && v > 0.0 && ( !min.is_defined() || v < min ) ) + min = v; + } + } + } + } + } + } + + if ( min.is_defined() && min > 1.0 ) + forbid_poll_size_stop = true; + } } /*---------------------------------------------------------*/ @@ -2731,23 +2851,23 @@ void NOMAD::Mads::check_directions ( bool & forbid_poll_size_stop ) void NOMAD::Mads::update_success_directions ( const NOMAD::Eval_Point * new_inc , bool feasible ) const { - if ( new_inc && new_inc->get_direction() ) + if ( new_inc && new_inc->get_direction() ) { - - const NOMAD::Direction * dir = new_inc->get_direction(); - NOMAD::Signature * signature = new_inc->get_signature(); + const NOMAD::Direction * dir = new_inc->get_direction(); + NOMAD::Signature * signature = new_inc->get_signature(); - if ( !signature ) - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , - "Mads::update_success_directions(): new incumbent has no signature" ); - - if ( feasible ) - new_inc->get_signature()->set_feas_success_dir ( *dir ); - else - new_inc->get_signature()->set_infeas_success_dir ( *dir ); - - } + + if ( !signature ) + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , + "Mads::update_success_directions(): new incumbent has no signature" ); + + if ( feasible ) + new_inc->get_signature()->set_feas_success_dir ( *dir ); + else + new_inc->get_signature()->set_infeas_success_dir ( *dir ); + + } } @@ -2760,240 +2880,259 @@ void NOMAD::Mads::search ( bool & stop , const NOMAD::Eval_Point *& new_feas_inc , const NOMAD::Eval_Point *& new_infeas_inc ) { - int nb_search_pts; - bool count_search; - int mads_iteration = _stats.get_iterations(); - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - NOMAD::success_type last_it_success = success; - success = NOMAD::UNSUCCESSFUL; - - // first display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "MADS search" ); - - // 1. speculative search: - if ( _p.get_speculative_search() ) - { - if ( new_feas_inc || new_infeas_inc ) + int nb_search_pts; + bool count_search; + int mads_iteration = _stats.get_iterations(); + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + NOMAD::success_type last_it_success = success; + success = NOMAD::UNSUCCESSFUL; + + // first display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::open_block ( "MADS search" ); + + // 1. speculative search: + if ( _p.get_speculative_search() ) { - Speculative_Search ss ( _p ); - - ss.search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_spec_success(); - if ( count_search ) - _stats.add_nb_spec_searches(); - _stats.add_spec_pts ( nb_search_pts ); - } - } - - // 2. user search: - if ( success != NOMAD::FULL_SUCCESS && _user_search ) { - - // initial user search display: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << NOMAD::USER_SEARCH; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - // the search: - _user_search->search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - // update stats: - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_usr_srch_success(); - if ( count_search ) - _stats.add_nb_usr_searches(); - _stats.add_usr_srch_pts ( nb_search_pts ); - - // final user search display: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::USER_SEARCH << " (" << success << ")"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - } - - // 3. cache search: - if ( success != NOMAD::FULL_SUCCESS && _p.get_cache_search() ) { - - // the search: - _cache_search->search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - // update stats: - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_CS_success(); - if ( count_search ) - _stats.add_nb_cache_searches(); - _stats.add_CS_pts ( nb_search_pts ); - } - - // 4. Model Searches (stats are updated inside the searches): - if ( success != NOMAD::FULL_SUCCESS && _p.has_model_search() ) { - + if ( new_feas_inc || new_infeas_inc ) + { + Speculative_Search ss ( _p ); + + ss.search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_spec_success(); + if ( count_search ) + _stats.add_nb_spec_searches(); + _stats.add_spec_pts ( nb_search_pts ); + } + } + + // 2. user search: + if ( success != NOMAD::FULL_SUCCESS && _user_search ) + { + + // initial user search display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << NOMAD::USER_SEARCH; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + // the search: + _user_search->search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + // update stats: + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_usr_srch_success(); + if ( count_search ) + _stats.add_nb_usr_searches(); + _stats.add_usr_srch_pts ( nb_search_pts ); + + // final user search display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of " << NOMAD::USER_SEARCH << " (" << success << ")"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + } + + // 3. cache search: + if ( success != NOMAD::FULL_SUCCESS && _p.get_cache_search() ) + { + + // the search: + _cache_search->search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + // update stats: + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_CS_success(); + if ( count_search ) + _stats.add_nb_cache_searches(); + _stats.add_CS_pts ( nb_search_pts ); + } + + // 4. Model Searches (stats are updated inside the searches): + if ( success != NOMAD::FULL_SUCCESS && _p.has_model_search() ) + { + #ifdef USE_MPI - // asynchronous mode: wait for the evaluations in progress: - if ( _p.get_asynchronous() ) { - std::list<const NOMAD::Eval_Point *> evaluated_pts; - _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - success , - evaluated_pts ); - } + // asynchronous mode: wait for the evaluations in progress: + if ( _p.get_asynchronous() ) + { + std::list<const NOMAD::Eval_Point *> evaluated_pts; + _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + success , + evaluated_pts ); + } #endif - - // model search #1: - _model_search1->search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - // save the TGP model for the model ordering: - if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) { + + // model search #1: + _model_search1->search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + // save the TGP model for the model ordering: + if ( _p.get_model_search(1) == NOMAD::TGP_MODEL ) + { #ifdef USE_TGP - _ev_control.set_last_TGP_model - ( static_cast<NOMAD::TGP_Model_Search *>(_model_search1)->get_model() ); + _ev_control.set_last_TGP_model + ( static_cast<NOMAD::TGP_Model_Search *>(_model_search1)->get_model() ); #endif - } - // model search #2: - if ( success != NOMAD::FULL_SUCCESS && _model_search2 ) { - + } + // model search #2: + if ( success != NOMAD::FULL_SUCCESS && _model_search2 ) + { + #ifdef USE_MPI - // asynchronous mode: wait for the evaluations in progress: - if ( _p.get_asynchronous() ) { - std::list<const NOMAD::Eval_Point *> evaluated_pts; - _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - success , - evaluated_pts ); - } + // asynchronous mode: wait for the evaluations in progress: + if ( _p.get_asynchronous() ) + { + std::list<const NOMAD::Eval_Point *> evaluated_pts; + _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + success , + evaluated_pts ); + } #endif - _model_search2->search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - // save the TGP model for the model ordering: - if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) { + _model_search2->search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + // save the TGP model for the model ordering: + if ( _p.get_model_search(2) == NOMAD::TGP_MODEL ) + { #ifdef USE_TGP - _ev_control.set_last_TGP_model - ( static_cast<NOMAD::TGP_Model_Search *>(_model_search2)->get_model() ); + _ev_control.set_last_TGP_model + ( static_cast<NOMAD::TGP_Model_Search *>(_model_search2)->get_model() ); #endif - } - } - } - - // 5. VNS search: - if ( _p.get_VNS_search() && - success != NOMAD::FULL_SUCCESS && - last_it_success == NOMAD::UNSUCCESSFUL && - NOMAD::Mesh::get_mesh_index() >= 0 && - _stats.get_iterations() > 0 ) { - - // check the VNS_trigger criterion: - int bbe = _stats.get_bb_eval(); - if ( bbe==0 || - _stats.get_VNS_bb_eval() / static_cast<float>(bbe) < _p.get_VNS_trigger() ) { - + } + } + } + + // 5. VNS search: + if ( _p.get_VNS_search() && + success != NOMAD::FULL_SUCCESS && + last_it_success == NOMAD::UNSUCCESSFUL && + _mesh->is_finer_than_initial() && + _stats.get_iterations() > 0 ) + { + + // check the VNS_trigger criterion: + int bbe = _stats.get_bb_eval(); + if ( bbe==0 || + _stats.get_VNS_bb_eval() / static_cast<float>(bbe) < _p.get_VNS_trigger() ) + { + #ifdef USE_MPI - // asynchronous mode: wait for the evaluations in progress: - if ( _p.get_asynchronous() ) { - std::list<const NOMAD::Eval_Point *> evaluated_pts; - _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - success , - evaluated_pts ); - } + // asynchronous mode: wait for the evaluations in progress: + if ( _p.get_asynchronous() ) + { + std::list<const NOMAD::Eval_Point *> evaluated_pts; + _ev_control.wait_for_evaluations ( NOMAD::ASYNCHRONOUS , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + success , + evaluated_pts ); + } #endif - - _VNS_search->search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_VNS_success(); - if ( count_search ) - _stats.add_nb_VNS_searches(); - _stats.add_VNS_pts ( nb_search_pts ); - } - } - - // 6. Latin-Hypercube (LH) search: - if ( success != NOMAD::FULL_SUCCESS && _p.get_LH_search_pi() > 0 ) { - - // for the first iteration: do not perform the - // search if there was an initial LH search: - if ( mads_iteration > 0 || _p.get_LH_search_p0() <= 0 ) { - - LH_Search lh ( _p , false , _flag_p1_active ); - - lh.search ( *this , - nb_search_pts , - stop , - stop_reason , - success , - count_search , - new_feas_inc , - new_infeas_inc ); - if ( success == NOMAD::FULL_SUCCESS ) - _stats.add_LH_success(); - if ( count_search ) - _stats.add_nb_LH_searches(); - _stats.add_LH_pts ( nb_search_pts ); - } - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << NOMAD::close_block ( "end of search" ); + + _VNS_search->search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_VNS_success(); + + if ( count_search ) + _stats.add_nb_VNS_searches(); + + _stats.add_VNS_pts ( nb_search_pts ); + } + } + + // 6. Latin-Hypercube (LH) search: + if ( success != NOMAD::FULL_SUCCESS && _p.get_LH_search_pi() > 0 ) + { + + // for the first iteration: do not perform the + // search if there was an initial LH search: + if ( mads_iteration > 0 || _p.get_LH_search_p0() <= 0 ) { + + LH_Search lh ( _p , false , _flag_p1_active ); + + lh.search ( *this , + nb_search_pts , + stop , + stop_reason , + success , + count_search , + new_feas_inc , + new_infeas_inc ); + + if ( success == NOMAD::FULL_SUCCESS ) + _stats.add_LH_success(); + + if ( count_search ) + _stats.add_nb_LH_searches(); + + _stats.add_LH_pts ( nb_search_pts ); + } + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block ( "end of search" ); } /*---------------------------------------------------------*/ @@ -3002,195 +3141,201 @@ void NOMAD::Mads::search ( bool & stop , void NOMAD::Mads::eval_x0 ( bool & stop , NOMAD::stop_type & stop_reason ) { - const std::vector<NOMAD::Point *> & x0s = _p.get_x0s(); - const std::string & x0_cache_file = _p.get_x0_cache_file(); - if ( x0s.empty() && x0_cache_file.empty() ) - return; - - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_gen_dd(); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "starting point evaluation" ); - - NOMAD::Eval_Point * pt; - size_t k; - int m = _p.get_bb_nb_outputs(); - int n = _p.get_dimension(); - std::ostringstream err; - - // x0s from vector Parameters::_x0s: - // --------------------------------- - size_t x0s_size = x0s.size(); - for ( k = 0 ; k < x0s_size ; ++k ) { - - // the current starting point has to be in dimension n: - if ( x0s[k]->size() != n ) { - err << "starting point ( " << *x0s[k] << " ) is not of dimension " << n; - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , err.str() ); - } - - // creation of the Eval_Point: - pt = new NOMAD::Eval_Point; - pt->set ( *x0s[k] , m ); - pt->set_signature ( _p.get_signature() ); - - _ev_control.add_eval_point ( pt , - display_degree , - false , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } - - // x0 from a cache file: - // --------------------- - if ( !x0_cache_file.empty() ) { - - NOMAD::Cache & cache = _ev_control.get_cache(); - const NOMAD::Eval_Point * x; - - // another cache file (this file won't be modified): - if ( x0_cache_file != _p.get_cache_file() ) { - - NOMAD::Cache x0_cache ( out , ( _p.get_opt_only_sgte() ) ? NOMAD::SGTE : - NOMAD::TRUTH ); - std::string file_name = _p.get_problem_dir() + x0_cache_file; - - if ( !x0_cache.load ( file_name , NULL , display_degree==NOMAD::FULL_DISPLAY ) ) { - err << "could not load (or create) the cache file " << file_name; - throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , err.str() ); - } - - // we copy all the temporary cache points - // into the list of points to be evaluated: - x = x0_cache.begin(); - while ( x ) { - - pt = new NOMAD::Eval_Point; - pt->set ( *x , m ); - - if ( x->get_signature() ) - pt->set_signature ( x->get_signature() ); - else if ( x->size() == n ) - pt->set_signature ( _p.get_signature() ); - - if ( pt->get_signature() ) - _ev_control.add_eval_point ( pt , - display_degree , - false , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - else { - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << std::endl << "Warning (" << "Mads.cpp" << ", " << __LINE__ - << "): could not use the starting point " << *pt - << " (no signature)" << std::endl << std::endl; - delete pt; + const std::vector<NOMAD::Point *> & x0s = _p.get_x0s(); + const std::string & x0_cache_file = _p.get_x0_cache_file(); + if ( x0s.empty() && x0_cache_file.empty() ) + return; + + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_gen_dd(); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::open_block ( "starting point evaluation" ); + + NOMAD::Eval_Point * pt; + size_t k; + int m = _p.get_bb_nb_outputs(); + int n = _p.get_dimension(); + std::ostringstream err; + + // x0s from vector Parameters::_x0s: + // --------------------------------- + size_t x0s_size = x0s.size(); + for ( k = 0 ; k < x0s_size ; ++k ) + { + + // the current starting point has to be in dimension n: + if ( x0s[k]->size() != n ) + { + err << "starting point ( " << *x0s[k] << " ) is not of dimension " << n; + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , err.str() ); + } + + // creation of the Eval_Point: + pt = new NOMAD::Eval_Point; + pt->set ( *x0s[k] , m ); + pt->set_signature ( _p.get_signature() ); + + _ev_control.add_eval_point ( pt , + display_degree , + false , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); } - - x = x0_cache.next(); - } - - // insertion of this temporary cache in the algorithm's cache: - cache.insert ( x0_cache ); - } - - // x0 cache file and the algorithm's cache file are the same: - else { - - x = cache.begin(); - while ( x ) { - pt = &NOMAD::Cache::get_modifiable_point ( *x ); - - if ( x->get_signature() ) - pt->set_signature ( x->get_signature() ); - else if ( x->size() == n ) - pt->set_signature ( _p.get_signature() ); - - if ( pt->get_signature() ) - _ev_control.add_eval_point ( pt , - display_degree , - false , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - else { - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << std::endl << "Warning (" << "Mads.cpp" << ", " << __LINE__ - << "): could not use the starting point " << *pt - << "(no signature)" << std::endl; + + // x0 from a cache file: + // --------------------- + if ( !x0_cache_file.empty() ) + { + + NOMAD::Cache & cache = _ev_control.get_cache(); + const NOMAD::Eval_Point * x; + + // another cache file (this file won't be modified): + if ( x0_cache_file != _p.get_cache_file() ) + { + + NOMAD::Cache x0_cache ( out , ( _p.get_opt_only_sgte() ) ? NOMAD::SGTE : NOMAD::TRUTH ); + std::string file_name = _p.get_problem_dir() + x0_cache_file; + + if ( !x0_cache.load ( file_name , NULL , display_degree==NOMAD::FULL_DISPLAY ) ) + { + err << "could not load (or create) the cache file " << file_name; + throw NOMAD::Exception ( "Mads.cpp" , __LINE__ , err.str() ); + } + + // we copy all the temporary cache points + // into the list of points to be evaluated: + x = x0_cache.begin(); + while ( x ) + { + + pt = new NOMAD::Eval_Point; + pt->set ( *x , m ); + + if ( x->get_signature() ) + pt->set_signature ( x->get_signature() ); + else if ( x->size() == n ) + pt->set_signature ( _p.get_signature() ); + + if ( pt->get_signature() ) + _ev_control.add_eval_point ( pt , + display_degree , + false , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + else + { + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << std::endl << "Warning (" << "Mads.cpp" << ", " << __LINE__ + << "): could not use the starting point " << *pt + << " (no signature)" << std::endl << std::endl; + delete pt; + } + + x = x0_cache.next(); + } + + // insertion of this temporary cache in the algorithm's cache: + cache.insert ( x0_cache ); + } + + // x0 cache file and the algorithm's cache file are the same: + else { + + x = cache.begin(); + while ( x ) { + pt = &NOMAD::Cache::get_modifiable_point ( *x ); + + if ( x->get_signature() ) + pt->set_signature ( x->get_signature() ); + else if ( x->size() == n ) + pt->set_signature ( _p.get_signature() ); + + if ( pt->get_signature() ) + _ev_control.add_eval_point ( pt , + display_degree , + false , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + else { + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << std::endl << "Warning (" << "Mads.cpp" << ", " << __LINE__ + << "): could not use the starting point " << *pt + << "(no signature)" << std::endl; + } + x = cache.next(); + } + } } - x = cache.next(); - } - } - } - - // display of all starting points: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - - const std::set<NOMAD::Priority_Eval_Point> & pts = _ev_control.get_eval_lop(); - - // one starting point: - if ( pts.size() == 1 ) { - out << std::endl << "x0 eval point: ( "; - pts.begin()->get_point()->Point::display ( out , - " " , - 2 , - NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // several starting points: - else - _ev_control.display_eval_lop ( NOMAD::X0_EVAL ); - } - - NOMAD::success_type success; - const NOMAD::Eval_Point * new_feas_inc = NULL; - const NOMAD::Eval_Point * new_infeas_inc = NULL; - - // eval_list_of_points (x0): - // ------------------------- - _ev_control.eval_list_of_points ( NOMAD::X0_EVAL , - _true_barrier , - _sgte_barrier , - _pareto_front , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - if ( !stop && - ( success == NOMAD::UNSUCCESSFUL || - (!new_feas_inc && !new_infeas_inc ) || - ( _p.get_barrier_type() == NOMAD::EB && - !get_active_barrier().get_best_feasible() ) ) ) { - stop = true; - stop_reason = NOMAD::X0_FAIL; - } - - - // displays: - display_iteration_end ( stop , - stop_reason , - success , - new_feas_inc , - new_infeas_inc ); - - // stop the algorithm if no iterations are allowed: - if ( !stop && _p.get_max_iterations() == 0 ) - { - stop = true; - stop_reason = NOMAD::MAX_ITER_REACHED; - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::close_block ( "end of starting point evaluation" ); + + // display of all starting points: + if ( display_degree == NOMAD::FULL_DISPLAY ) { + + const std::set<NOMAD::Priority_Eval_Point> & pts = _ev_control.get_eval_lop(); + + // one starting point: + if ( pts.size() == 1 ) { + out << std::endl << "x0 eval point: ( "; + pts.begin()->get_point()->Point::display ( out , + " " , + 2 , + NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // several starting points: + else + _ev_control.display_eval_lop ( NOMAD::X0_EVAL ); + } + + NOMAD::success_type success; + const NOMAD::Eval_Point * new_feas_inc = NULL; + const NOMAD::Eval_Point * new_infeas_inc = NULL; + + // eval_list_of_points (x0): + // ------------------------- + _ev_control.eval_list_of_points ( NOMAD::X0_EVAL , + _true_barrier , + _sgte_barrier , + _pareto_front , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + if ( !stop && + ( success == NOMAD::UNSUCCESSFUL || + (!new_feas_inc && !new_infeas_inc ) || + ( _p.get_barrier_type() == NOMAD::EB && + !get_active_barrier().get_best_feasible() ) ) ) { + stop = true; + stop_reason = NOMAD::X0_FAIL; + } + + + // displays: + display_iteration_end ( stop , + stop_reason , + success , + new_feas_inc , + new_infeas_inc ); + + // stop the algorithm if no iterations are allowed: + if ( !stop && _p.get_max_iterations() == 0 ) + { + stop = true; + stop_reason = NOMAD::MAX_ITER_REACHED; + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::close_block ( "end of starting point evaluation" ); } /*---------------------------------------------------------*/ @@ -3198,69 +3343,72 @@ void NOMAD::Mads::eval_x0 ( bool & stop , /*---------------------------------------------------------*/ void NOMAD::Mads::display_pareto_front ( void ) const { - if ( !_pareto_front ) - return; - - const std::string & stats_file_name = _p.get_stats_file_name(); - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_gen_dd(); - - // loop on the Pareto points: - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << std::endl << NOMAD::open_block ( "Pareto front" ) << std::endl; - - const NOMAD::Eval_Point * cur = _pareto_front->begin(); - while ( cur ) { - - if ( cur->is_eval_ok() && cur->is_feasible ( _p.get_h_min() ) ) { - - const std::list<int> & index_obj = _p.get_index_obj(); - std::list<int>::const_iterator it , end = index_obj.end(); - const NOMAD::Point & bbo = cur->get_bb_outputs(); - int i = 0; - NOMAD::Point multi_obj ( static_cast<int>(index_obj.size()) ); - - for ( it = index_obj.begin() ; it != end ; ++it ) - multi_obj[i++] = bbo[*it]; - - if ( !stats_file_name.empty() ) - _ev_control.stats_file ( stats_file_name , cur , true , &multi_obj ); - - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY && !_p.get_display_stats().empty() ) - _ev_control.display_stats ( false , - out , - _p.get_display_stats() , - cur , - true , - &multi_obj ); - } - cur = _pareto_front->next(); - } - - if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << NOMAD::close_block(); - - // other stats: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - - out << std::endl << "number of pts : " << _pareto_front->size() << std::endl; - - NOMAD::Double delta , surf; - _pareto_front->get_delta_surf ( delta , surf , - _p.get_multi_f_bounds() ); // f1_min, f1_max, - // f2_min, f2_max - out << "delta_j : " << delta << std::endl - << "surf : "; - if ( surf.is_defined() ) - out << 100*surf << "%" << std::endl; - else - out << NOMAD::Double() - << " (define valid MULTI_F_BOUNDS values to access this output)" - << std::endl; - } - else if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) - out << std::endl << "number of Pareto points: " << _pareto_front->size() - << std::endl; + if ( !_pareto_front ) + return; + + const std::string & stats_file_name = _p.get_stats_file_name(); + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_gen_dd(); + + // loop on the Pareto points: + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << std::endl << NOMAD::open_block ( "Pareto front" ) << std::endl; + + const NOMAD::Eval_Point * cur = _pareto_front->begin(); + while ( cur ) + { + + if ( cur->is_eval_ok() && cur->is_feasible ( _p.get_h_min() ) ) + { + + const std::list<int> & index_obj = _p.get_index_obj(); + std::list<int>::const_iterator it , end = index_obj.end(); + const NOMAD::Point & bbo = cur->get_bb_outputs(); + int i = 0; + NOMAD::Point multi_obj ( static_cast<int>(index_obj.size()) ); + + for ( it = index_obj.begin() ; it != end ; ++it ) + multi_obj[i++] = bbo[*it]; + + if ( !stats_file_name.empty() ) + _ev_control.stats_file ( stats_file_name , cur , true , &multi_obj ); + + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY && !_p.get_display_stats().empty() ) + _ev_control.display_stats ( false , + out , + _p.get_display_stats() , + cur , + true , + &multi_obj ); + } + cur = _pareto_front->next(); + } + + if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << NOMAD::close_block(); + + // other stats: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + + out << std::endl << "number of pts : " << _pareto_front->size() << std::endl; + + NOMAD::Double delta , surf; + _pareto_front->get_delta_surf ( delta , surf , + _p.get_multi_f_bounds() ); // f1_min, f1_max, + // f2_min, f2_max + out << "delta_j : " << delta << std::endl + << "surf : "; + if ( surf.is_defined() ) + out << 100*surf << "%" << std::endl; + else + out << NOMAD::Double() + << " (define valid MULTI_F_BOUNDS values to access this output)" + << std::endl; + } + else if ( display_degree != NOMAD::NO_DISPLAY && display_degree != NOMAD::MINIMAL_DISPLAY) + out << std::endl << "number of Pareto points: " << _pareto_front->size() + << std::endl; } /*---------------------------------------------------------*/ @@ -3275,7 +3423,8 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const // 0. no display: // -------------- - if ( display_degree == NOMAD::NO_DISPLAY || display_degree == NOMAD::MINIMAL_DISPLAY) { + if ( display_degree == NOMAD::NO_DISPLAY || display_degree == NOMAD::MINIMAL_DISPLAY) + { // there may be a pareto front to write as a stats file: if ( _pareto_front && @@ -3342,11 +3491,11 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const { out << std::endl << NOMAD::open_block ( "miscellaneous" ) - << "mesh index : min=" - << NOMAD::Mesh::get_min_mesh_index() << ", max=" - << NOMAD::Mesh::get_max_mesh_index() << ", last=" - << NOMAD::Mesh::get_mesh_index() << std::endl; - + << "mesh indices : min= (" + << _mesh->get_min_mesh_indices() << " ), max = (" + << _mesh->get_max_mesh_indices() << " ), last= ( " + << _mesh->get_mesh_indices() << " ) " << std::endl; + if ( bimv ) { out << "best infeasible solution (min. violation): ( "; @@ -3388,7 +3537,8 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const out << "stat avg : " << _stats.get_stat_avg() << std::endl; // Pareto front (multi-objective optimization): - if ( _pareto_front ) { + if ( _pareto_front ) + { out << "number of MADS runs : " << _stats.get_mads_runs() << std::endl; if ( _pareto_front->empty() ) out << "Pareto front : empty" << std::endl; @@ -3412,7 +3562,7 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const << " f=" << bimv->get_f() << std::endl; } - out << "best feasible solution : "; + out << "best feasible solution : "; if ( bf ) { @@ -3423,7 +3573,7 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const } else out << "no feasible solution has been found" << std::endl; - + } } out.close_block(); @@ -3435,17 +3585,17 @@ void NOMAD::Mads::display ( const NOMAD::Display & out ) const /*---------------------------------------------------------*/ void NOMAD::Mads::display_model_stats ( const NOMAD::Display & out ) const { - if ( _model_search1 ) - out << std::endl << NOMAD::open_block ( "model search #1 stats" ) - << *_model_search1 << NOMAD::close_block(); - if ( _model_search2 ) - out << std::endl << NOMAD::open_block ( "model search #2 stats" ) - << *_model_search2 << NOMAD::close_block(); - if ( _p.get_model_eval_sort() != NOMAD::NO_MODEL ) { - out << std::endl << NOMAD::open_block ( "model ordering stats" ); - _ev_control.display_model_ordering_stats ( out ); - out << NOMAD::close_block(); - } + if ( _model_search1 ) + out << std::endl << NOMAD::open_block ( "model search #1 stats" ) + << *_model_search1 << NOMAD::close_block(); + if ( _model_search2 ) + out << std::endl << NOMAD::open_block ( "model search #2 stats" ) + << *_model_search2 << NOMAD::close_block(); + if ( _p.get_model_eval_sort() != NOMAD::NO_MODEL ) { + out << std::endl << NOMAD::open_block ( "model ordering stats" ); + _ev_control.display_model_ordering_stats ( out ); + out << NOMAD::close_block(); + } } /*---------------------------------------------------------*/ @@ -3454,12 +3604,16 @@ void NOMAD::Mads::display_model_stats ( const NOMAD::Display & out ) const /*---------------------------------------------------------*/ void NOMAD::Mads::display_deltas ( const NOMAD::Signature & s ) const { - NOMAD::Point delta_m , delta_p; - s.get_mesh().get_delta_m ( delta_m , NOMAD::Mesh::get_mesh_index() ); - s.get_mesh().get_delta_p ( delta_p , NOMAD::Mesh::get_mesh_index() ); - _p.out() << "mesh size : ( " << delta_m << " )" << std::endl - << "poll size : ( " << delta_p << " )" - << std::endl; + + NOMAD::Point delta,Delta; + + _mesh->get_delta(delta); + _mesh->get_Delta(Delta); + if (delta.is_defined() && Delta.is_defined()) + _p.out() << "mesh size : ( " << delta << " )" << std::endl + << "poll size : ( " << Delta << " )" << std::endl + << "mesh indices : ( " << _mesh->get_mesh_indices() << " )" << std::endl; + } /*-------------------------------------------------------*/ @@ -3467,74 +3621,72 @@ void NOMAD::Mads::display_deltas ( const NOMAD::Signature & s ) const /*-------------------------------------------------------*/ void NOMAD::Mads::display_iteration_begin ( void ) const { - const NOMAD::Display & out = _p.out(); - if ( out.get_iter_dd() != NOMAD::FULL_DISPLAY ) - return; - - // incumbents: - const NOMAD::Eval_Point * bf = get_best_feasible(); - const NOMAD::Eval_Point * bi = get_best_infeasible(); - const NOMAD::Signature * s1 = NULL; - - out << "blackbox evaluations : " << _stats.get_bb_eval() << std::endl; + const NOMAD::Display & out = _p.out(); + if ( out.get_iter_dd() != NOMAD::FULL_DISPLAY ) + return; + + // incumbents: + const NOMAD::Eval_Point * bf = get_best_feasible(); + const NOMAD::Eval_Point * bi = get_best_infeasible(); + const NOMAD::Signature * s1 = NULL; + + out << "blackbox evaluations : " << _stats.get_bb_eval() << std::endl; #ifdef USE_MPI - if ( _p.get_asynchronous() ) - out << "eval. in progress : " << _ev_control.get_nb_eval_in_progress() - << std::endl; + if ( _p.get_asynchronous() ) + out << "eval. in progress : " << _ev_control.get_nb_eval_in_progress() + << std::endl; #endif - out << "best feas. solution : "; - if ( bf ) { - out << "( "; - bf->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " ) h=" << bf->get_h() - << " f=" << bf->get_f() - << std::endl; - } - else - out << "none" << std::endl; - out << "best infeas. solution: "; - if ( bi ) { - out << "( "; - bi->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " ) h=" << bi->get_h() - << " f=" << bi->get_f() - << std::endl; - } - else - out << "none" << std::endl; - - out << "poll center : "; - const NOMAD::Eval_Point * poll_center = get_active_barrier().get_poll_center(); - if ( poll_center ) { - out << "( "; - poll_center->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - - s1 = poll_center->get_signature(); - if (s1) - display_deltas ( *s1 ); - } - else - out << "none" << std::endl; - - const NOMAD::Eval_Point * sec_poll_center + out << "best feas. solution : "; + if ( bf ) { + out << "( "; + bf->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " ) h=" << bf->get_h() + << " f=" << bf->get_f() + << std::endl; + } + else + out << "none" << std::endl; + out << "best infeas. solution: "; + if ( bi ) { + out << "( "; + bi->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " ) h=" << bi->get_h() + << " f=" << bi->get_f() + << std::endl; + } + else + out << "none" << std::endl; + + out << "poll center : "; + const NOMAD::Eval_Point * poll_center = get_active_barrier().get_poll_center(); + if ( poll_center ) { + out << "( "; + poll_center->Point::display ( out , " " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + + s1 = poll_center->get_signature(); + if (s1) + display_deltas ( *s1 ); + } + else + out << "none" << std::endl; + + const NOMAD::Eval_Point * sec_poll_center = get_active_barrier().get_sec_poll_center(); - - if ( sec_poll_center ) { - out << "sec. poll center : ( "; - sec_poll_center->Point::display ( out , - " " , - 2 , - NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - const NOMAD::Signature * s2 = sec_poll_center->get_signature(); - if ( s2 && (!s1 || s1 != s2) ) - display_deltas ( *s2 ); - } - - out << "mesh index : " << NOMAD::Mesh::get_mesh_index() << std::endl - << "h_max : " - << get_active_barrier().get_h_max() << std::endl; + + if ( sec_poll_center ) { + out << "sec. poll center : ( "; + sec_poll_center->Point::display ( out , + " " , + 2 , + NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + const NOMAD::Signature * s2 = sec_poll_center->get_signature(); + if ( s2 && (!s1 || s1 != s2) ) + display_deltas ( *s2 ); + } + out << "h_max : " + << get_active_barrier().get_h_max() << std::endl; } /*---------------------------------------------------------*/ @@ -3542,37 +3694,37 @@ void NOMAD::Mads::display_iteration_begin ( void ) const /*---------------------------------------------------------*/ void NOMAD::Mads::display_iteration_end ( bool stop , - NOMAD::stop_type stop_reason , - NOMAD::success_type success , - const NOMAD::Eval_Point * new_feas_inc , - const NOMAD::Eval_Point * new_infeas_inc ) const + NOMAD::stop_type stop_reason , + NOMAD::success_type success , + const NOMAD::Eval_Point * new_feas_inc , + const NOMAD::Eval_Point * new_infeas_inc ) const { - const NOMAD::Display & out = _p.out(); - - if ( out.get_iter_dd() != NOMAD::FULL_DISPLAY ) - return; - - out << std::endl - << "terminate MADS : "; - out.display_yes_or_no ( stop ); - out << std::endl; - if ( stop ) { - out << "termination cause : " << stop_reason; - if ( stop_reason==NOMAD::X0_FAIL && - !_flag_p1_active && - _p.has_EB_constraints() ) - out << " (phase one will be performed)"; - out << std::endl; - } - out << "iteration status : " << success << std::endl; - out << "new feas. incumbent : "; - if ( new_feas_inc ) - out << *new_feas_inc; - else - out << "none" << std::endl; - out << "new infeas. incumbent: "; - if ( new_infeas_inc ) - out << *new_infeas_inc; - else - out << "none" << std::endl; + const NOMAD::Display & out = _p.out(); + + if ( out.get_iter_dd() != NOMAD::FULL_DISPLAY ) + return; + + out << std::endl + << "terminate MADS : "; + out.display_yes_or_no ( stop ); + out << std::endl; + if ( stop ) { + out << "termination cause : " << stop_reason; + if ( stop_reason==NOMAD::X0_FAIL && + !_flag_p1_active && + _p.has_EB_constraints() ) + out << " (phase one will be performed)"; + out << std::endl; + } + out << "iteration status : " << success << std::endl; + out << "new feas. incumbent : "; + if ( new_feas_inc ) + out << *new_feas_inc; + else + out << "none" << std::endl; + out << "new infeas. incumbent: "; + if ( new_infeas_inc ) + out << *new_infeas_inc; + else + out << "none" << std::endl; } diff --git a/src/Mads.hpp b/src/Mads.hpp index 750061da68e4bb6e9f2869421f74a2e45ad4b907..c44819e34c6efc22fb22b7f4ab87aca9e8042bfa 100644 --- a/src/Mads.hpp +++ b/src/Mads.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -52,551 +52,559 @@ #include "L_Curve.hpp" #include "Extended_Poll.hpp" +#include "XMesh.hpp" +#include "SMesh.hpp" + #ifdef USE_TGP #include "TGP_Model_Search.hpp" #endif namespace NOMAD { - - // forward declaration of Extended_Poll: - class Extended_Poll; - - /// The MADS algorithm. - class Mads : private NOMAD::Uncopyable { - - private: - - static bool _force_quit; ///< Forces NOMAD to terminate if Ctrl-C is pressed. - - NOMAD::Parameters & _p; ///< Parameters. - NOMAD::Stats _stats; ///< Statistics. - NOMAD::Evaluator_Control _ev_control; ///< Evaluator control. - NOMAD::Evaluator_Control _ev_control_for_sorting; ///< Evaluator control. - NOMAD::Barrier _true_barrier; ///< Barrier for true function evaluations. - NOMAD::Barrier _sgte_barrier; ///< Barrier for surrogate evaluations. - - /// Pareto front for multi-objective optimization. - NOMAD::Pareto_Front * _pareto_front; - - /// User search defined with NOMAD::Mads::set_user_search(). - NOMAD::Search * _user_search; - - NOMAD::Search * _model_search1; ///< Model search #1. - NOMAD::Search * _model_search2; ///< Model search #2. - - NOMAD::Search * _VNS_search; ///< VNS search. - NOMAD::Search * _cache_search; ///< Cache search. - NOMAD::L_Curve * _L_curve; ///< L-curve target. - NOMAD::Extended_Poll * _extended_poll; ///< Extended poll for categorical variables. - bool _user_ext_poll; ///< Flag for user-defined extended poll. - - // MADS flags (these are not parameters as users do not modify them): - - static bool _flag_check_bimads; ///< Flag for the multi-objective test in \c run(). - static bool _flag_reset_mesh; ///< Reset or not the mesh before a MADS run. - static bool _flag_reset_barriers; ///< Reset or not the barriers before a MADS run. - static bool _flag_p1_active; ///< Flag equal to \c true if phase one is active. - - /*-----------------------------------------------------------------------------*/ - - /// Initializations. - void init ( void ); - - /// Starting point evaluation. - /** - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - */ - void eval_x0 ( bool & stop , NOMAD::stop_type & stop_reason ); - - /// One MADS iteration. - /** - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param success Success for this iteration -- \b OUT. - \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. - */ - void iteration ( bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ); - - /// The search step. - /** - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param success Success for this step -- \b OUT. - \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. - */ - void search ( bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ); - - /// The poll step. - /** - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param success Success for this step -- \b OUT. - \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. - \param forbid_poll_size_stop Boolean used to check if the min poll - size stopping criterion has to be - disabled for integer variables -- \b OUT. - */ - void poll ( bool & stop, - NOMAD::stop_type & stop_reason, - NOMAD::success_type & success, - const NOMAD::Eval_Point *& new_feas_inc, - const NOMAD::Eval_Point *& new_infeas_inc, - bool & forbid_poll_size_stop ); - - /// Sets the poll trial points from poll direction, poll center and mesh size - /** - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - \param dirs List of directions for the poll -- \b IN. - \param poll_center the poll center (can be null) -- \b IN. - \param offset Dir index offset for primary and sec. poll center -- \b IN. - \param sorting If true than the points are for sorting -- \b IN. - */ - void set_poll_trial_points ( std::list<NOMAD::Direction> & dirs, - int offset, - const NOMAD::Eval_Point & poll_center, - bool & stop, - NOMAD::stop_type &stop_reason, - bool sorting); - - - /// Compute a prospect point by optimization on quadratic models. - /** - \param poll_center The poll center -- \b IN. - \param dirs The directions that delimit the hypercube for optimization -- \b IN. - \param prospect_point The prospect point -- \b OUT. - \return A flag equal to \c true if the prospect direction has been computed. - */ - bool optimize_quad_model ( const NOMAD::Eval_Point & poll_center , - const std::list<NOMAD::Direction> & dirs , - NOMAD::Point & prospect_point ) ; - - /// Sets the poll directions from signature, poll center and mesh size - /** - \param dirs List of directions for the poll -- \b OUT. - \param i_pc Poll type -- \b IN. - \param offset Dir index offset for primary and sec. poll center -- \b IN. - \param poll_center The poll center -- \b IN. - \param stop Stop flag, true if cannot get direction -- \b IN/OUT. - \param stop_reason Stop type -- \b OUT. - */ - void set_poll_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type i_pc , - int offset , - const NOMAD::Eval_Point & poll_center , - bool & stop , - NOMAD::stop_type & stop_reason ); - - /// Reduce the number of poll directions -> n - /** - \param dirs List of directions for the poll -- \b IN/OUT. - \param poll_center the poll center -- \b IN. - \return success for this step. - */ - bool set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & dirs, - const NOMAD::Eval_Point & poll_center); - - /// Compute the rank of a list of directions - /** - \param dirs List of directions for the poll -- \b IN/OUT. - \return rank>0 of the dirs if successfull or 0 if rank cannot be evaluated - */ - int get_rank_from_dirs(const std::list<NOMAD::Direction> & dirs); - - - /// Check the directions after the poll step. - /** - \param forbid_poll_size_stop Boolean equal to \c true if - the \c MIN_POLL_SIZE parameter is valid for - the last set of poll directions -- \b OUT. - */ - void check_directions ( bool & forbid_poll_size_stop ); - - /// Update of the success directions. - /** - - Occurs after the poll. - \param new_inc Pointer to the new incumbent -- \b IN (may be \c NULL). - \param feasible Flag equal to \c true if the incumbent is feasible -- \b IN. - */ - void update_success_directions ( const NOMAD::Eval_Point * new_inc , - bool feasible ) const; - - /// Launch a single-objective MADS run for multi-objective optimization. - /** - \param display_degree Display degree -- \b IN. - \param mads_runs Total number of MADS runs to execute -- \b IN. - \param overall_bbe Global maximum number of blackbox evaluations -- \b IN. - \param ev Evaluator for multi-objective -- \b IN/OUT. - \param stagnation_cnt Counter to detect a stagnation -- \b IN/OUT. - \param multi_stats Stats for multi-objective -- \b IN/OUT. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - */ - void multi_launch_single_opt ( NOMAD::dd_type display_degree , - int mads_runs , - int overall_bbe , - NOMAD::Multi_Obj_Evaluator & ev , - int & stagnation_cnt , - NOMAD::Stats & multi_stats , - bool & stop , - NOMAD::stop_type & stop_reason ); - - /// Compute and set the minimal poll size for multi-objective optimization. - /** - \param lb Lower bounds -- \b IN. - \param ub Upper bounds -- \b IN. - \param delta_p_0 Initial poll size -- \b IN. - \param delta_j Delta criterion for multi-objective -- \b IN/OUT. - */ - void multi_set_min_poll_size ( const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & delta_p_0 , - NOMAD::Double delta_j ); - - // Display mesh and poll sizes for a given signature. - /** - \param s The signature -- \b IN. - */ - void display_deltas ( const NOMAD::Signature & s ) const; - - /// Displays at the beginning of an iteration. - void display_iteration_begin ( void ) const; - - /// Displays at the end of an iteration. - /** - \param stop Stop flag -- \b IN. - \param stop_reason Stop reason -- \b IN. - \param success Iteration success -- \b IN. - \param new_feas_inc Pointer to the new feasible incumbent -- \b IN. - \param new_infeas_inc Pointer to the new infeasible incumbent -- \b IN. - */ - void display_iteration_end ( bool stop , - NOMAD::stop_type stop_reason , - NOMAD::success_type success , - const NOMAD::Eval_Point * new_feas_inc , - const NOMAD::Eval_Point * new_infeas_inc ) const; - - - /// Determine dynamic directions from a set of directions. - /** - - The computed opposite directions already include Delta^k_m. - \param dirs List of existing directions (no snap to bounds) -- \b IN. - \param newDirs New dynamic directions -- \b OUT. - \param poll_center Poll center -- \b IN. - \return true if new dynamic direction generated false otherwise - */ - bool get_dynamic_directions (const std::list<NOMAD::Direction> & dirs, - std::list<NOMAD::Direction> & newDirs, - const NOMAD::Eval_Point & poll_center) ; - - - - /// Check if a set of directions include Ortho-MADS N+1 direction. - /** - \param dirs List of directions -- \b IN. - \return A boolean equal to \c true if at - least one direction in the set is - of type Ortho-MADS N+1. - */ - bool dirs_have_orthomads_np1 ( const std::list<NOMAD::Direction> & dirs ); - - - /// Check if a dir needs to be obtained from model optimization - /** - \param dirs List of directions -- \b IN. - \return A boolean equal to \c true if all directions are of type Ortho-MADS N+1 QUAD. - */ - bool dir_from_model_opt( const std::list<NOMAD::Direction> & dirs); - - - /// get a single direction using quad model optimization or sum of negatives - /** - \param dirs Reduced poll directions (no snap to bounds) -- \b IN. - \param poll_center Poll center -- \b IN. - \return new direction - */ - NOMAD::Direction get_single_dynamic_direction (const std::list<NOMAD::Direction> & dirs, - const NOMAD::Eval_Point & poll_center) ; - - - /*-----------------------------------------------------------------------------*/ - - public: - - /// Constructor #1. - /** - - Basic version. - \param p Parameters -- \b IN. - \param ev A pointer to the evaluator -- \b IN - -- \b optional (default = \c NULL). - */ - Mads ( NOMAD::Parameters & p , NOMAD::Evaluator * ev = NULL ) - : _p ( p ) , - _stats ( p.get_sgte_cost() ) , - _ev_control ( p , _stats , ev , NULL , NULL ) , - _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , &(_ev_control.get_cache()) , &(_ev_control.get_sgte_cache()) ) , - _true_barrier ( p , NOMAD::TRUTH ) , - _sgte_barrier ( p , NOMAD::SGTE ) , - _pareto_front ( NULL ) , - _user_search ( NULL ) , - _model_search1 ( NULL ) , - _model_search2 ( NULL ) , - _VNS_search ( NULL ) , - _cache_search ( NULL ) , - _L_curve ( NULL ) , - _extended_poll ( NULL ) , - _user_ext_poll ( false ) { init(); } - - /// Constructor #2. - /** - - Advanced version. - \param p Parameters -- \b IN. - \param ev A pointer to the evaluator -- \b IN (may be \c NULL). - \param extended_poll A pointer to a NOMAD::Extended_Poll object - -- \b IN (may be \c NULL). - \param cache A pointer to a cache -- \b IN (may be \c NULL). - \param sgte_cache A pointer to a cache for surrogates - -- \b IN (may be \c NULL). - */ - Mads ( NOMAD::Parameters & p , - NOMAD::Evaluator * ev , // may be NULL - NOMAD::Extended_Poll * extended_poll , // may be NULL - NOMAD::Cache * cache , // may be NULL - NOMAD::Cache * sgte_cache ) // may be NULL - : _p ( p ) , - _stats ( p.get_sgte_cost() ) , - _ev_control ( p , _stats , ev , cache , sgte_cache ) , - _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , cache , sgte_cache ) , - _true_barrier ( p , NOMAD::TRUTH ) , - _sgte_barrier ( p , NOMAD::SGTE ) , - _pareto_front ( NULL ) , - _user_search ( NULL ) , - _model_search1 ( NULL ) , - _model_search2 ( NULL ) , - _VNS_search ( NULL ) , - _cache_search ( NULL ) , - _L_curve ( NULL ) , - _extended_poll ( extended_poll ) , - _user_ext_poll ( (extended_poll!=NULL) ) { init(); } - - /// Destructor. - virtual ~Mads ( void ); - - /// Algorithm execution for single-objective. - /** - \return Stop reason. - */ - NOMAD::stop_type run ( void ); - - /// Algorithm execution for multi-objective. - /** - \return Stop reason. - */ - NOMAD::stop_type multi_run ( void ); - - /// Force quit. - /** - Called by pressing Ctrl-C. - \param signalValue Signal value -- \b IN. - */ - static void force_quit ( int signalValue ); - - /// Reset. - /** - - Also resets the user search. - \param keep_barriers A boolean equal to \c true if NOMAD::Barrier objects - have to be reseted - -- \b IN -- \b optional (default = \c false). - \param keep_stats A boolean equal to \c true if the stats object - has to be reseted - -- \b IN -- \b optional (default = \c false). - */ - void reset ( bool keep_barriers = false , bool keep_stats = false ); - - /// Set user search. - /** - \param us A pointer to the user search -- \b IN. - */ - void set_user_search ( NOMAD::Search * us ) { _user_search = us; } - - /// Set an extern Pareto front. - /** - \param pf A pointer to a Pareto front -- \b IN. - */ - void set_pareto_front ( NOMAD::Pareto_Front * pf ) { _pareto_front = pf; } - - /// Set the flag for the multi-objective test. - /** - \param fcb The flag for the multi-objective test -- \b IN. - */ - static void set_flag_check_bimads ( bool fcb ) { _flag_check_bimads = fcb; } - - /// Set the flag \c _flag_reset_mesh. - /** - \param frm The flag -- \b IN. - */ - static void set_flag_reset_mesh ( bool frm ) { _flag_reset_mesh = frm; } - - /// Set the flag \c _flag_reset_barriers. - /** - \param frb The flag -- \b IN. - */ - static void set_flag_reset_barriers ( bool frb ) { _flag_reset_barriers = frb; } - - /// Set the flag \c _flag_p1_active -- \b IN. - /** - \param fpa The flag. - */ - static void set_flag_p1_active ( bool fpa ) { _flag_p1_active = fpa; } - - /// Access to the flags. - /** - \param flag_check_bimads Multi-objective flag -- \b OUT. - \param flag_reset_mesh Mesh reset flag -- \b OUT. - \param flag_reset_barriers Reset barriers flag -- \b OUT. - \param flag_p1_active Phase one flag -- \b OUT. - */ - static void get_flags ( bool & flag_check_bimads , - bool & flag_reset_mesh , - bool & flag_reset_barriers , - bool & flag_p1_active ); - - /// Access to the stats. - /** - \return The stats. - */ - NOMAD::Stats & get_stats ( void ) { return _stats; } - - /// Access to the evaluator control. - /** - \return The evaluator control. - */ - NOMAD::Evaluator_Control & get_evaluator_control ( void ) { return _ev_control; } - - /// Access to the barrier for true function evaluations. - /** - \return The barrier for the true function evaluations. - */ - NOMAD::Barrier & get_true_barrier ( void ) { return _true_barrier; } - - /// Access to the barrier for surrogate evaluations. - /** - \return The barrier for the surrogates. - */ - NOMAD::Barrier & get_sgte_barrier ( void ) { return _sgte_barrier; } - - /// Access to the NOMAD::Extended_Poll object. - /** - \return A pointer to \c _extended_poll. - */ - NOMAD::Extended_Poll * get_extended_poll ( void ) const { return _extended_poll; } - - - - /// Access to the Pareto front. - /** - \return A pointer to the Pareto front. - */ - NOMAD::Pareto_Front * get_pareto_front ( void ) const { return _pareto_front; } - - /// Access to the active cache (truth or surrogate). - /** - \return The active cache. - */ - const NOMAD::Cache & get_cache ( void ) const - { - return ( _p.get_opt_only_sgte() ) ? - _ev_control.get_sgte_cache() : _ev_control.get_cache(); - } - - /// Access to the active barrier (truth or surrogate). - /** - \return The active barrier. - */ - const NOMAD::Barrier & get_active_barrier ( void ) const - { - return ( _p.get_opt_only_sgte() ) ? _sgte_barrier : _true_barrier; - } - - /// Access to the best feasible point. - /** - \return A pointer to the best feasible point; - \return \c NULL if there is no feasible point. - */ - const NOMAD::Eval_Point * get_best_feasible ( void ) const - { - return get_active_barrier().get_best_feasible(); - } - - /// Access to the best infeasible point. - /** - \return A pointer to the best infeasible point; - \return \c NULL if there is no infeasible point. - */ - const NOMAD::Eval_Point * get_best_infeasible( void ) const - { - return get_active_barrier().get_best_infeasible(); - } - - /// Access to the best infeasible point with minimun constraint violation. - /** - \return A pointer to the best infeasible point with min. viol.; - \return \c NULL if there is no infeasible point. - */ - const NOMAD::Eval_Point * get_best_infeasible_min_viol ( void ) const - { - return get_active_barrier().get_best_infeasible_min_viol(); - } - - /// Display model stats. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display_model_stats ( const NOMAD::Display & out ) const; - - /// Display the Pareto front. - /** - Displays the front at the standard output or in a stats file. - */ - void display_pareto_front ( void ) const; - - /// Display. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - - /// Display. - /** - Uses the NOMAD::Display object of the NOMAD::Parameters class. - */ - void display ( void ) const { display ( _p.out() ); } - }; - - /// Display a NOMAD::Mads object. - /** + + // forward declaration of Extended_Poll: + class Extended_Poll; + + /// The MADS algorithm. + class Mads : private NOMAD::Uncopyable { + + private: + + static bool _force_quit; ///< Forces NOMAD to terminate if Ctrl-C is pressed. + + NOMAD::Parameters & _p; ///< Parameters. + NOMAD::Stats _stats; ///< Statistics. + NOMAD::Evaluator_Control _ev_control; ///< Evaluator control. + NOMAD::Evaluator_Control _ev_control_for_sorting; ///< Evaluator control. + NOMAD::Barrier _true_barrier; ///< Barrier for true function evaluations. + NOMAD::Barrier _sgte_barrier; ///< Barrier for surrogate evaluations. + + NOMAD::OrthogonalMesh * _mesh; ///< Access to the OrthogonalMesh + + /// Pareto front for multi-objective optimization. + NOMAD::Pareto_Front * _pareto_front; + + /// User search defined with NOMAD::Mads::set_user_search(). + NOMAD::Search * _user_search; + + NOMAD::Search * _model_search1; ///< Model search #1. + NOMAD::Search * _model_search2; ///< Model search #2. + + NOMAD::Search * _VNS_search; ///< VNS search. + NOMAD::Search * _cache_search; ///< Cache search. + NOMAD::L_Curve * _L_curve; ///< L-curve target. + NOMAD::Extended_Poll * _extended_poll; ///< Extended poll for categorical variables. + bool _user_ext_poll; ///< Flag for user-defined extended poll. + + // MADS flags (these are not parameters as users do not modify them): + + static bool _flag_check_bimads; ///< Flag for the multi-objective test in \c run(). + static bool _flag_reset_mesh; ///< Reset or not the mesh before a MADS run. + static bool _flag_reset_barriers; ///< Reset or not the barriers before a MADS run. + static bool _flag_p1_active; ///< Flag equal to \c true if phase one is active. + + /*-----------------------------------------------------------------------------*/ + + /// Initializations. + void init ( void ); + + /// Starting point evaluation. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void eval_x0 ( bool & stop , NOMAD::stop_type & stop_reason ); + + /// One MADS iteration. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param success Success for this iteration -- \b OUT. + \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. + */ + void iteration ( bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ); + + /// The search step. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param success Success for this step -- \b OUT. + \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. + */ + void search ( bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ); + + /// The poll step. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param success Success for this step -- \b OUT. + \param new_feas_inc Pointer to the new feasible incumbent -- \b OUT. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b OUT. + \param forbid_poll_size_stop Boolean used to check if the min poll + size stopping criterion has to be + disabled for integer variables -- \b OUT. + */ + void poll ( bool & stop, + NOMAD::stop_type & stop_reason, + NOMAD::success_type & success, + const NOMAD::Eval_Point *& new_feas_inc, + const NOMAD::Eval_Point *& new_infeas_inc, + bool & forbid_poll_size_stop ); + + /// Sets the poll trial points from poll direction, poll center and mesh size + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + \param dirs List of directions for the poll -- \b IN. + \param poll_center the poll center (can be null) -- \b IN. + \param offset Dir index offset for primary and sec. poll center -- \b IN. + \param sorting If true than the points are for sorting -- \b IN. + */ + void set_poll_trial_points ( std::list<NOMAD::Direction> & dirs, + size_t offset, + const NOMAD::Eval_Point & poll_center, + bool & stop, + NOMAD::stop_type &stop_reason, + bool sorting); + + + /// Compute a prospect point by optimization on quadratic models. + /** + \param poll_center The poll center -- \b IN. + \param dirs The directions that delimit the hypercube for optimization -- \b IN. + \param prospect_point The prospect point -- \b OUT. + \return A flag equal to \c true if the prospect direction has been computed. + */ + bool optimize_quad_model ( const NOMAD::Eval_Point & poll_center , + const std::list<NOMAD::Direction> & dirs , + NOMAD::Point & prospect_point ) ; + + + /// Sets the poll directions from signature, poll center and mesh size + /** + \param dirs List of directions for the poll -- \b OUT. + \param i_pc Poll type -- \b IN. + \param offset Dir index offset for primary and sec. poll center -- \b IN. + \param poll_center The poll center -- \b IN. + \param stop Stop flag, true if cannot get direction -- \b IN/OUT. + \param stop_reason Stop type -- \b OUT. + */ + void set_poll_directions ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type i_pc , + size_t offset , + const NOMAD::Eval_Point & poll_center , + bool & stop , + NOMAD::stop_type & stop_reason ); + + /// Reduce the number of poll directions -> n + /** + \param dirs List of directions for the poll -- \b IN/OUT. + \param poll_center the poll center -- \b IN. + \return success for this step. + */ + bool set_reduced_poll_to_n_directions(std::list<NOMAD::Direction> & dirs, + const NOMAD::Eval_Point & poll_center); + + /// Compute the rank of a list of directions + /** + \param dirs List of directions for the poll -- \b IN/OUT. + \return rank>0 of the dirs if successfull or 0 if rank cannot be evaluated + */ + int get_rank_from_dirs(const std::list<NOMAD::Direction> & dirs); + + + /// Check the directions after the poll step. + /** + \param forbid_poll_size_stop Boolean equal to \c true if + the \c MIN_POLL_SIZE parameter is valid for + the last set of poll directions -- \b OUT. + */ + void check_directions ( bool & forbid_poll_size_stop ); + + /// Update of the success directions. + /** + - Occurs after the poll. + \param new_inc Pointer to the new incumbent -- \b IN (may be \c NULL). + \param feasible Flag equal to \c true if the incumbent is feasible -- \b IN. + */ + void update_success_directions ( const NOMAD::Eval_Point * new_inc , + bool feasible ) const; + + /// Launch a single-objective MADS run for multi-objective optimization. + /** + \param display_degree Display degree -- \b IN. + \param mads_runs Total number of MADS runs to execute -- \b IN. + \param overall_bbe Global maximum number of blackbox evaluations -- \b IN. + \param ev Evaluator for multi-objective -- \b IN/OUT. + \param stagnation_cnt Counter to detect a stagnation -- \b IN/OUT. + \param multi_stats Stats for multi-objective -- \b IN/OUT. + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void multi_launch_single_opt ( NOMAD::dd_type display_degree , + int mads_runs , + int overall_bbe , + NOMAD::Multi_Obj_Evaluator & ev , + int & stagnation_cnt , + NOMAD::Stats & multi_stats , + bool & stop , + NOMAD::stop_type & stop_reason ); + + /// Compute and set the minimal poll size for multi-objective optimization. + /** + \param lb Lower bounds -- \b IN. + \param ub Upper bounds -- \b IN. + \param delta_p_0 Initial poll size -- \b IN. + \param delta_j Delta criterion for multi-objective -- \b IN/OUT. + */ + void multi_set_min_poll_size ( const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & delta_p_0 , + NOMAD::Double delta_j ); + + // Display mesh and poll sizes for a given signature. + /** + \param s The signature -- \b IN. + */ + void display_deltas ( const NOMAD::Signature & s ) const; + + /// Displays at the beginning of an iteration. + void display_iteration_begin ( void ) const; + + /// Displays at the end of an iteration. + /** + \param stop Stop flag -- \b IN. + \param stop_reason Stop reason -- \b IN. + \param success Iteration success -- \b IN. + \param new_feas_inc Pointer to the new feasible incumbent -- \b IN. + \param new_infeas_inc Pointer to the new infeasible incumbent -- \b IN. + */ + void display_iteration_end ( bool stop , + NOMAD::stop_type stop_reason , + NOMAD::success_type success , + const NOMAD::Eval_Point * new_feas_inc , + const NOMAD::Eval_Point * new_infeas_inc ) const; + + + /// Determine dynamic directions from a set of directions. + /** + - The computed opposite directions already include Delta^k_m. + \param dirs List of existing directions (no snap to bounds) -- \b IN. + \param newDirs New dynamic directions -- \b OUT. + \param poll_center Poll center -- \b IN. + \return true if new dynamic direction generated false otherwise + */ + bool get_dynamic_directions (const std::list<NOMAD::Direction> & dirs, + std::list<NOMAD::Direction> & newDirs, + const NOMAD::Eval_Point & poll_center) ; + + + + /// Check if a set of directions include Ortho-MADS N+1 direction. + /** + \param dirs List of directions -- \b IN. + \return A boolean equal to \c true if at + least one direction in the set is + of type Ortho-MADS N+1. + */ + bool dirs_have_orthomads_np1 ( const std::list<NOMAD::Direction> & dirs ); + + + /// Check if a dir needs to be obtained from model optimization + /** + \param dirs List of directions -- \b IN. + \return A boolean equal to \c true if all directions are of type Ortho-MADS N+1 QUAD. + */ + bool dir_from_model_opt( const std::list<NOMAD::Direction> & dirs); + + + /// get a single direction using quad model optimization or sum of negatives + /** + \param dirs Reduced poll directions (no snap to bounds) -- \b IN. + \param poll_center Poll center -- \b IN. + \return new direction + */ + NOMAD::Direction get_single_dynamic_direction (const std::list<NOMAD::Direction> & dirs, + const NOMAD::Eval_Point & poll_center) ; + + + /*-----------------------------------------------------------------------------*/ + + public: + + /// Constructor #1. + /** + - Basic version. + \param p Parameters -- \b IN. + \param ev A pointer to the evaluator -- \b IN + -- \b optional (default = \c NULL). + */ + Mads ( NOMAD::Parameters & p , NOMAD::Evaluator * ev = NULL ) + : _p ( p ) , + _stats ( p.get_sgte_cost() ) , + _ev_control ( p , _stats , ev , NULL , NULL ) , + _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , &(_ev_control.get_cache()) , &(_ev_control.get_sgte_cache()) ) , + _true_barrier ( p , NOMAD::TRUTH ) , + _sgte_barrier ( p , NOMAD::SGTE ) , + _mesh ( p.get_signature()->get_mesh() ) , + _pareto_front ( NULL ) , + _user_search ( NULL ) , + _model_search1 ( NULL ) , + _model_search2 ( NULL ) , + _VNS_search ( NULL ) , + _cache_search ( NULL ) , + _L_curve ( NULL ) , + _extended_poll ( NULL ) , + _user_ext_poll ( false ) { init(); } + + /// Constructor #2. + /** + - Advanced version. + \param p Parameters -- \b IN. + \param ev A pointer to the evaluator -- \b IN (may be \c NULL). + \param extended_poll A pointer to a NOMAD::Extended_Poll object + -- \b IN (may be \c NULL). + \param cache A pointer to a cache -- \b IN (may be \c NULL). + \param sgte_cache A pointer to a cache for surrogates + -- \b IN (may be \c NULL). + */ + Mads ( NOMAD::Parameters & p , + NOMAD::Evaluator * ev , // may be NULL + NOMAD::Extended_Poll * extended_poll , // may be NULL + NOMAD::Cache * cache , // may be NULL + NOMAD::Cache * sgte_cache ) // may be NULL + : _p ( p ) , + _stats ( p.get_sgte_cost() ) , + _ev_control ( p , _stats , ev , cache , sgte_cache ) , + _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , cache , sgte_cache ) , + _true_barrier ( p , NOMAD::TRUTH ) , + _sgte_barrier ( p , NOMAD::SGTE ) , + _mesh ( p.get_signature()->get_mesh() ) , + _pareto_front ( NULL ) , + _user_search ( NULL ) , + _model_search1 ( NULL ) , + _model_search2 ( NULL ) , + _VNS_search ( NULL ) , + _cache_search ( NULL ) , + _L_curve ( NULL ) , + _extended_poll ( extended_poll ) , + _user_ext_poll ( (extended_poll!=NULL) ) { init(); } + + /// Destructor. + virtual ~Mads ( void ); + + /// Algorithm execution for single-objective. + /** + \return Stop reason. + */ + NOMAD::stop_type run ( void ); + + /// Algorithm execution for multi-objective. + /** + \return Stop reason. + */ + NOMAD::stop_type multi_run ( void ); + + /// Force quit. + /** + Called by pressing Ctrl-C. + \param signalValue Signal value -- \b IN. + */ + static void force_quit ( int signalValue ); + + /// Reset. + /** + - Also resets the user search. + \param keep_barriers A boolean equal to \c true if NOMAD::Barrier objects + have to be reseted + -- \b IN -- \b optional (default = \c false). + \param keep_stats A boolean equal to \c true if the stats object + has to be reseted + -- \b IN -- \b optional (default = \c false). + */ + void reset ( bool keep_barriers = false , bool keep_stats = false ); + + /// Set user search. + /** + \param us A pointer to the user search -- \b IN. + */ + void set_user_search ( NOMAD::Search * us ) { _user_search = us; } + + /// Set an extern Pareto front. + /** + \param pf A pointer to a Pareto front -- \b IN. + */ + void set_pareto_front ( NOMAD::Pareto_Front * pf ) { _pareto_front = pf; } + + /// Set the flag for the multi-objective test. + /** + \param fcb The flag for the multi-objective test -- \b IN. + */ + static void set_flag_check_bimads ( bool fcb ) { _flag_check_bimads = fcb; } + + /// Set the flag \c _flag_reset_mesh. + /** + \param frm The flag -- \b IN. + */ + static void set_flag_reset_mesh ( bool frm ) { _flag_reset_mesh = frm; } + + /// Set the flag \c _flag_reset_barriers. + /** + \param frb The flag -- \b IN. + */ + static void set_flag_reset_barriers ( bool frb ) { _flag_reset_barriers = frb; } + + /// Set the flag \c _flag_p1_active -- \b IN. + /** + \param fpa The flag. + */ + static void set_flag_p1_active ( bool fpa ) { _flag_p1_active = fpa; } + + /// Access to the flags. + /** + \param flag_check_bimads Multi-objective flag -- \b OUT. + \param flag_reset_mesh Mesh reset flag -- \b OUT. + \param flag_reset_barriers Reset barriers flag -- \b OUT. + \param flag_p1_active Phase one flag -- \b OUT. + */ + static void get_flags ( bool & flag_check_bimads , + bool & flag_reset_mesh , + bool & flag_reset_barriers , + bool & flag_p1_active ); + + /// Access to the stats. + /** + \return The stats. + */ + NOMAD::Stats & get_stats ( void ) { return _stats; } + + /// Access to the evaluator control. + /** + \return The evaluator control. + */ + NOMAD::Evaluator_Control & get_evaluator_control ( void ) { return _ev_control; } + + /// Access to the barrier for true function evaluations. + /** + \return The barrier for the true function evaluations. + */ + NOMAD::Barrier & get_true_barrier ( void ) { return _true_barrier; } + + /// Access to the barrier for surrogate evaluations. + /** + \return The barrier for the surrogates. + */ + NOMAD::Barrier & get_sgte_barrier ( void ) { return _sgte_barrier; } + + /// Access to the NOMAD::Extended_Poll object. + /** + \return A pointer to \c _extended_poll. + */ + NOMAD::Extended_Poll * get_extended_poll ( void ) const { return _extended_poll; } + + + + /// Access to the Pareto front. + /** + \return A pointer to the Pareto front. + */ + NOMAD::Pareto_Front * get_pareto_front ( void ) const { return _pareto_front; } + + /// Access to the active cache (truth or surrogate). + /** + \return The active cache. + */ + const NOMAD::Cache & get_cache ( void ) const + { + return ( _p.get_opt_only_sgte() ) ? + _ev_control.get_sgte_cache() : _ev_control.get_cache(); + } + + /// Access to the active barrier (truth or surrogate). + /** + \return The active barrier. + */ + const NOMAD::Barrier & get_active_barrier ( void ) const + { + return ( _p.get_opt_only_sgte() ) ? _sgte_barrier : _true_barrier; + } + + /// Access to the best feasible point. + /** + \return A pointer to the best feasible point; + \return \c NULL if there is no feasible point. + */ + const NOMAD::Eval_Point * get_best_feasible ( void ) const + { + return get_active_barrier().get_best_feasible(); + } + + /// Access to the best infeasible point. + /** + \return A pointer to the best infeasible point; + \return \c NULL if there is no infeasible point. + */ + const NOMAD::Eval_Point * get_best_infeasible( void ) const + { + return get_active_barrier().get_best_infeasible(); + } + + /// Access to the best infeasible point with minimun constraint violation. + /** + \return A pointer to the best infeasible point with min. viol.; + \return \c NULL if there is no infeasible point. + */ + const NOMAD::Eval_Point * get_best_infeasible_min_viol ( void ) const + { + return get_active_barrier().get_best_infeasible_min_viol(); + } + + /// Display model stats. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display_model_stats ( const NOMAD::Display & out ) const; + + /// Display the Pareto front. + /** + Displays the front at the standard output or in a stats file. + */ + void display_pareto_front ( void ) const; + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + /// Display. + /** + Uses the NOMAD::Display object of the NOMAD::Parameters class. + */ + void display ( void ) const { display ( _p.out() ); } + }; + + /// Display a NOMAD::Mads object. + /** \param out The NOMAD::Display object -- \b IN. \param m The NOMAD::Mads object to be displayed -- \b IN. \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Mads & m ) - { - m.display ( out ); - return out; - } + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Mads & m ) + { + m.display ( out ); + return out; + } } #endif diff --git a/src/Makefile.am b/src/Makefile.am index 10468220d3699b4f1ac66e189675fb57a334f3da..2ffa64126077fafc59eb022c46f2530e24f38ea7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,33 +3,35 @@ libnomad_a_SOURCES = Barrier.cpp Cache.cpp Cache_File_Point.cpp Cache_Point.cpp\ Cache_Search.cpp Clock.cpp Direction.cpp Directions.cpp Display.cpp\ Double.cpp Eval_Point.cpp Evaluator_Control.cpp Evaluator.cpp\ Exception.cpp Extended_Poll.cpp L_Curve.cpp LH_Search.cpp Mads.cpp\ - Mesh.cpp Model_Sorted_Point.cpp Model_Stats.cpp Multi_Obj_Evaluator.cpp\ + SMesh.cpp XMesh.cpp Model_Sorted_Point.cpp Model_Stats.cpp Multi_Obj_Evaluator.cpp\ Parameter_Entries.cpp Parameter_Entry.cpp Parameters.cpp\ Pareto_Front.cpp Pareto_Point.cpp Phase_One_Evaluator.cpp\ Phase_One_Search.cpp Point.cpp Priority_Eval_Point.cpp Quad_Model.cpp\ Quad_Model_Evaluator.cpp Quad_Model_Search.cpp Random_Pickup.cpp\ RNG.cpp Signature.cpp Slave.cpp Speculative_Search.cpp Stats.cpp\ TGP_Model.cpp TGP_Model_Evaluator.cpp TGP_Model_Search.cpp\ - TGP_Output_Model.cpp utils.cpp Variable_Group.cpp VNS_Search.cpp + TGP_Output_Model.cpp utils.cpp Variable_Group.cpp VNS_Search.cpp\ + OrthogonalMesh.cpp libnomadmpi_a_SOURCES = Barrier.cpp Cache.cpp Cache_File_Point.cpp Cache_Point.cpp\ Cache_Search.cpp Clock.cpp Direction.cpp Directions.cpp Display.cpp\ Double.cpp Eval_Point.cpp Evaluator_Control.cpp Evaluator.cpp\ Exception.cpp Extended_Poll.cpp L_Curve.cpp LH_Search.cpp Mads.cpp\ - Mesh.cpp Model_Sorted_Point.cpp Model_Stats.cpp Multi_Obj_Evaluator.cpp\ + SMesh.cpp XMesh.cpp Model_Sorted_Point.cpp Model_Stats.cpp Multi_Obj_Evaluator.cpp\ Parameter_Entries.cpp Parameter_Entry.cpp Parameters.cpp\ Pareto_Front.cpp Pareto_Point.cpp Phase_One_Evaluator.cpp\ Phase_One_Search.cpp Point.cpp Priority_Eval_Point.cpp Quad_Model.cpp\ Quad_Model_Evaluator.cpp Quad_Model_Search.cpp Random_Pickup.cpp\ RNG.cpp Signature.cpp Slave.cpp Speculative_Search.cpp Stats.cpp\ TGP_Model.cpp TGP_Model_Evaluator.cpp TGP_Model_Search.cpp\ - TGP_Output_Model.cpp utils.cpp Variable_Group.cpp VNS_Search.cpp + TGP_Output_Model.cpp utils.cpp Variable_Group.cpp VNS_Search.cpp\ + OrthogonalMesh.cpp pkginclude_HEADERS = Cache_File_Point.hpp Cache.hpp Cache_Point.hpp\ Cache_Search.hpp Clock.hpp defines.hpp Direction.hpp Directions.hpp\ Display.hpp Double.hpp Eval_Point.hpp Evaluator_Control.hpp\ Evaluator.hpp Exception.hpp Extended_Poll.hpp Filter_Point.hpp\ - L_Curve.hpp LH_Search.hpp Mads.hpp Mesh.hpp Model_Sorted_Point.hpp\ + L_Curve.hpp LH_Search.hpp Mads.hpp SMesh.hpp XMesh.hpp Model_Sorted_Point.hpp\ Model_Stats.hpp Multi_Obj_Evaluator.hpp\ Multi_Obj_Quad_Model_Evaluator.hpp nomad.hpp Parameter_Entries.hpp\ Parameter_Entry.hpp Parameters.hpp Pareto_Front.hpp Pareto_Point.hpp\ @@ -40,7 +42,7 @@ pkginclude_HEADERS = Cache_File_Point.hpp Cache.hpp Cache_Point.hpp\ Single_Obj_Quad_Model_Evaluator.hpp Slave.hpp Speculative_Search.hpp\ Stats.hpp TGP_Model_Evaluator.hpp TGP_Model.hpp TGP_Model_Search.hpp\ TGP_Output_Model.hpp Uncopyable.hpp utils.hpp Variable_Group.hpp\ - VNS_Search.hpp Barrier.hpp + VNS_Search.hpp Barrier.hpp OrthogonalMesh.hpp bin_PROGRAMS = nomad nomad_SOURCES = nomad.cpp diff --git a/src/Mesh.cpp b/src/Mesh.cpp deleted file mode 100644 index cd3bc7c495f042b7b0a68e7c8820f7d290cde35f..0000000000000000000000000000000000000000 --- a/src/Mesh.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ -/* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ -/* Charles Audet - Ecole Polytechnique, Montreal */ -/* Gilles Couture - Ecole Polytechnique, Montreal */ -/* John Dennis - Rice University, Houston */ -/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ -/* Christophe Tribes - Ecole Polytechnique, Montreal */ -/* */ -/* funded in part by AFOSR and Exxon Mobil */ -/* */ -/* Author: Sebastien Le Digabel */ -/* */ -/* Contact information: */ -/* Ecole Polytechnique de Montreal - GERAD */ -/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ -/* e-mail: nomad@gerad.ca */ -/* phone : 1-514-340-6053 #6928 */ -/* fax : 1-514-340-5665 */ -/* */ -/* This program is free software: you can redistribute it and/or modify it under the */ -/* terms of 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. */ -/* */ -/* This program 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 Lesser General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU Lesser General Public License along */ -/* with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* */ -/* You can find information on the NOMAD software at www.gerad.ca/nomad */ -/*-------------------------------------------------------------------------------------*/ -/** - \file Mesh.cpp - \brief Class for the MADS mesh (implementation) - \author Sebastien Le Digabel - \date 2010-04-06 - \see Mesh.hpp -*/ -#include "Mesh.hpp" - -/*-----------------------------------*/ -/* static members initialization */ -/*-----------------------------------*/ -double NOMAD::Mesh::_mesh_update_basis = 4.0; -int NOMAD::Mesh::_mesh_coarsening_exponent = 1; -int NOMAD::Mesh::_mesh_refining_exponent = -1; -int NOMAD::Mesh::_initial_mesh_index = 0; -int NOMAD::Mesh::_mesh_index = 0; -int NOMAD::Mesh::_min_mesh_index = 0; -int NOMAD::Mesh::_max_mesh_index = 0; -int NOMAD::Mesh::_max_halton_index = -1; - -/*-----------------------------------------------------------*/ -/* constructor */ -/*-----------------------------------------------------------*/ -NOMAD::Mesh::Mesh ( const NOMAD::Point & delta_m_0 , - const NOMAD::Point & delta_m_min , - const NOMAD::Point & delta_p_min ) - : _initial_mesh_size ( delta_m_0 ) , - _min_mesh_size ( delta_m_min ) , - _min_poll_size ( delta_p_min ) -{ - bool chkp = delta_p_min.is_defined(); - bool chkm = delta_m_min.is_defined(); - int k , n = delta_m_0.size(); - - if ( !delta_m_0.is_complete() ) - throw NOMAD::Exception ( "Mesh.cpp" , __LINE__ , - "NOMAD::Mesh::Mesh(): delta_m_0 has undefined values" ); - - if ( chkp && delta_p_min.size() != n ) - throw NOMAD::Exception ( "Mesh.cpp" , __LINE__ , - "NOMAD::Mesh::Mesh(): delta_m_0 and delta_p_min have different sizes" ); - - if ( chkm && delta_m_min.size() != n ) - throw NOMAD::Exception ( "Mesh.cpp" , __LINE__ , - "NOMAD::Mesh::Mesh(): delta_m_0 and delta_m_min have different sizes" ); - - // we check that delta_p_min <= delta_p_0 and that delta_m_min <= delta_m_0: - if ( chkp || chkm ) { - - NOMAD::Point * dp0 = NULL , * dm0 = NULL; - - if ( chkp ) { - dp0 = new NOMAD::Point ( n ); - get_delta_p ( *dp0 , NOMAD::Mesh::_initial_mesh_index ); - } - - if ( chkm ) { - dm0 = new NOMAD::Point ( n ); - get_delta_m ( *dm0 , NOMAD::Mesh::_initial_mesh_index ); - } - - std::string error; - - for ( k = 0 ; k < n ; ++k ) { - - if ( dp0 && - _min_poll_size[k].is_defined() && - (*dp0)[k] < _min_poll_size[k] ) { - error = "NOMAD::Mesh::Mesh(): delta_p_0 < delta_p_min"; - break; - } - - if ( dm0 && - _min_mesh_size[k].is_defined() && - (*dm0)[k] < _min_mesh_size[k] ) { - error = "NOMAD::Mesh::Mesh(): delta_m_0 < delta_m_min"; - break; - } - - } - - delete dp0; - delete dm0; - - if ( !error.empty() ) - throw NOMAD::Exception ( "Mesh.cpp" , __LINE__ , error ); - } -} - -/*-----------------------------------------------------------*/ -/* Mesh static members initialization (static) */ -/*-----------------------------------------------------------*/ -void NOMAD::Mesh::init ( double mesh_update_basis , - int mesh_coarsening_exponent , - int mesh_refining_exponent , - int initial_mesh_index ) -{ - NOMAD::Mesh::_mesh_update_basis = mesh_update_basis; - NOMAD::Mesh::_mesh_coarsening_exponent = mesh_coarsening_exponent; - NOMAD::Mesh::_mesh_refining_exponent = mesh_refining_exponent; - NOMAD::Mesh::_mesh_index = - NOMAD::Mesh::_initial_mesh_index = - NOMAD::Mesh::_min_mesh_index = - NOMAD::Mesh::_max_mesh_index = initial_mesh_index; - NOMAD::Mesh::_max_halton_index = -1; -} - -/*-----------------------------------------------------------*/ -/* update the mesh (static) */ -/*-----------------------------------------------------------*/ -void NOMAD::Mesh::update ( NOMAD::success_type success , int & mesh_index ) -{ - // defaults: - // full success: lk = lk - 1 - // failure : lk = lk + 1 - - if ( success == NOMAD::FULL_SUCCESS ) { - mesh_index -= NOMAD::Mesh::_mesh_coarsening_exponent; - if ( mesh_index < -NOMAD::L_LIMITS ) - mesh_index = -NOMAD::L_LIMITS; - } - else if ( success == NOMAD::UNSUCCESSFUL ) - mesh_index -= NOMAD::Mesh::_mesh_refining_exponent; - - if ( mesh_index > _max_mesh_index ) - _max_mesh_index = mesh_index; - - - if ( mesh_index < _min_mesh_index ) - _min_mesh_index = mesh_index; -} - -/*-----------------------------------------------------------*/ -/* manually set the mesh index (static) */ -/*-----------------------------------------------------------*/ -void NOMAD::Mesh::set_mesh_index ( int mesh_index ) -{ - NOMAD::Mesh::_mesh_index = mesh_index; - if ( mesh_index > _max_mesh_index ) - _max_mesh_index = mesh_index; - if ( mesh_index < _min_mesh_index ) - _min_mesh_index = mesh_index; -} - -/*-----------------------------------------------------------*/ -/* display */ -/*-----------------------------------------------------------*/ -void NOMAD::Mesh::display ( const NOMAD::Display & out ) const -{ - out << "n : " << get_n() << std::endl - << "mesh update basis : " << _mesh_update_basis << std::endl - << "mesh coarsening exponent: " << _mesh_coarsening_exponent << std::endl - << "mesh refining exponent : " << _mesh_refining_exponent << std::endl - << "initial mesh index : " << _initial_mesh_index << std::endl - << "initial mesh size : " - << "(" << _initial_mesh_size << " )" << std::endl; - out << "minimal mesh size : "; - if ( _min_mesh_size.is_defined() ) - out << "(" << _min_mesh_size << " )" << std::endl; - else - out << "none"; - out << std::endl - << "minimal poll size : "; - if ( _min_poll_size.is_defined() ) - out << "(" << _min_poll_size << " )" << std::endl; - else - out << "none"; - out << std::endl; -} - -/*----------------------------------------------------------*/ -/* check the stopping conditions on the minimal poll size */ -/* and on the minimal mesh size */ -/*----------------------------------------------------------*/ -void NOMAD::Mesh::check_min_mesh_sizes ( int max_mesh_index , - int mesh_index , - bool & stop , - NOMAD::stop_type & stop_reason ) const -{ - if ( stop ) - return; - - // 1. mesh index tests: - if ( abs ( mesh_index ) > NOMAD::L_LIMITS ) { - stop = true; - stop_reason = NOMAD::L_LIMITS_REACHED; - } - if ( max_mesh_index != NOMAD::UNDEFINED_L && mesh_index > max_mesh_index ) { - stop = true; - stop_reason = NOMAD::L_MAX_REACHED; - } - - // 2. delta_k^p (poll size) tests: - if ( check_min_poll_size_criterion ( mesh_index ) ) { - stop = true; - stop_reason = NOMAD::DELTA_P_MIN_REACHED; - } - - // 3. delta_k^m (mesh size) tests: - if ( check_min_mesh_size_criterion ( mesh_index ) ) { - stop = true; - stop_reason = NOMAD::DELTA_M_MIN_REACHED; - } -} - -/*-----------------------------------------------------------*/ -/* check the minimal poll size (private) */ -/*-----------------------------------------------------------*/ -bool NOMAD::Mesh::check_min_poll_size_criterion ( int mesh_index ) const -{ - if ( !_min_poll_size.is_defined() ) - return false; - NOMAD::Point delta_p; - return get_delta_p ( delta_p , mesh_index ); -} - -/*-----------------------------------------------------------*/ -/* check the minimal mesh size (private) */ -/*-----------------------------------------------------------*/ -bool NOMAD::Mesh::check_min_mesh_size_criterion ( int mesh_index ) const -{ - if ( !_min_mesh_size.is_defined() ) - return false; - NOMAD::Point delta_m; - return get_delta_m ( delta_m , mesh_index ); -} - -/*----------------------------------------------------------------*/ -/* get delta_m (mesh size parameter) */ -/* Delta^m_k = Delta^m_0 \tau^{ell_0^+ - ell_k^+} */ -/*----------------------------------------------------------------*/ -/* the function also returns true if one value is < delta_m_min */ -/* (stopping criterion MIN_MESH_SIZE) */ -/*----------------------------------------------------------------*/ -bool NOMAD::Mesh::get_delta_m ( NOMAD::Point & delta_m , int mesh_index ) const -{ - int n = get_n(); - delta_m.reset ( n ); - - // power_of_tau = tau^{ max{0,l0} - max{0,lk} }: - NOMAD::Double power_of_tau - = pow ( _mesh_update_basis , - ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - - ( (mesh_index > 0) ? mesh_index : 0) ); - - bool stop = false; - bool mms_def = _min_mesh_size.is_defined(); - - // Delta^m_k = power_of_tau * Delta^m_0: - for ( int i = 0 ; i < n ; ++i ) - { - delta_m[i] = _initial_mesh_size[i] * power_of_tau; - if ( mms_def && !stop && _min_mesh_size[i].is_defined() && delta_m[i] < _min_mesh_size[i] ) - stop = true; - } - - return stop; -} - -/*----------------------------------------------------------------*/ -/* get delta_m (mesh size parameter) */ -/* Delta^m_k = Delta^m_0 \tau^{ell_0^+ - ell_k^+} */ -/*----------------------------------------------------------------*/ -/* static version */ -/*----------------------------------------------------------------*/ -void NOMAD::Mesh::get_delta_m ( NOMAD::Point & delta_m , - const NOMAD::Point & initial_mesh_size , - double mesh_update_basis , - int initial_mesh_index , - int mesh_index ) -{ - - int n = initial_mesh_size.size(); - delta_m.reset ( n ); - - // power_of_tau = tau^{ max{0,l0} - max{0,lk} }: - NOMAD::Double power_of_tau - = pow ( mesh_update_basis , - ( (initial_mesh_index > 0) ? initial_mesh_index : 0) - - ( (mesh_index > 0) ? mesh_index : 0) ); - - // Delta^m_k = power_of_tau * Delta^m_0: - for ( int i = 0 ; i < n ; ++i ) - delta_m[i] = initial_mesh_size[i] * power_of_tau; -} - -/*-------------------------------------------------------------------*/ -/* get delta_p (poll size parameter) */ -/* Delta^p_k = Delta^m_k \tau^{ |ell_k|/2 } */ -/* = Delta^m_0 \tau^{ell_0^+ - ell_k^+ + |ell_k|/2} */ -/*-------------------------------------------------------------------*/ -/* the function also returns true if all values are < delta_p_ */ -/* (stopping criterion MIN_POLL_SIZE) */ -/*-------------------------------------------------------------------*/ -bool NOMAD::Mesh::get_delta_p ( NOMAD::Point & delta_p , int mesh_index ) const -{ - int n = get_n(); - delta_p.reset ( n ); - - // power_of_tau = tau^{ max{0,l0} - max{0,lk} + |lk|/2}: - NOMAD::Double power_of_tau - = pow ( _mesh_update_basis , abs(mesh_index) / 2.0 + - ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - - ( (mesh_index > 0) ? mesh_index : 0) ); - - bool stop = true; - - bool mps_def = _min_poll_size.is_defined(); - - // Delta^p_k = power_of_tau * Delta^m_0: - for ( int i = 0 ; i < n ; ++i ) - { - delta_p[i] = _initial_mesh_size[i] * power_of_tau; - if ( !mps_def || !_min_poll_size[i].is_defined() || delta_p[i] >= _min_poll_size[i] ) - stop = false; - } - - return stop; -} - -/*-------------------------------------------------------------------*/ -/* get delta_p (poll size parameter) */ -/* Delta^p_k = Delta^m_k \tau^{ |ell_k|/2 } */ -/* = Delta^m_0 \tau^{ell_0^+ - ell_k^+ + |ell_k|/2} */ -/*-------------------------------------------------------------------*/ -/* static version */ -/*-------------------------------------------------------------------*/ -void NOMAD::Mesh::get_delta_p ( NOMAD::Point & delta_p , - const NOMAD::Point & initial_mesh_size , - double mesh_update_basis , - int initial_mesh_index , - int mesh_index ) { - - int n = initial_mesh_size.size(); - delta_p.reset ( n ); - - // power_of_tau = tau^{ max{0,l0} - max{0,lk} + |lk|/2}: - NOMAD::Double power_of_tau - = pow ( mesh_update_basis , abs(mesh_index) / 2.0 + - ( (initial_mesh_index > 0) ? initial_mesh_index : 0) - - ( (mesh_index > 0) ? mesh_index : 0) ); - - // Delta^p_k = power_of_tau * Delta^m_0: - for ( int i = 0 ; i < n ; ++i ) - delta_p[i] = initial_mesh_size[i] * power_of_tau; -} diff --git a/src/Mesh.hpp b/src/Mesh.hpp deleted file mode 100644 index bd00a52f7eef3691c5471b85e1ccb967fbe4efe9..0000000000000000000000000000000000000000 --- a/src/Mesh.hpp +++ /dev/null @@ -1,361 +0,0 @@ -/*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ -/* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ -/* Charles Audet - Ecole Polytechnique, Montreal */ -/* Gilles Couture - Ecole Polytechnique, Montreal */ -/* John Dennis - Rice University, Houston */ -/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ -/* Christophe Tribes - Ecole Polytechnique, Montreal */ -/* */ -/* funded in part by AFOSR and Exxon Mobil */ -/* */ -/* Author: Sebastien Le Digabel */ -/* */ -/* Contact information: */ -/* Ecole Polytechnique de Montreal - GERAD */ -/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ -/* e-mail: nomad@gerad.ca */ -/* phone : 1-514-340-6053 #6928 */ -/* fax : 1-514-340-5665 */ -/* */ -/* This program is free software: you can redistribute it and/or modify it under the */ -/* terms of 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. */ -/* */ -/* This program 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 Lesser General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU Lesser General Public License along */ -/* with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* */ -/* You can find information on the NOMAD software at www.gerad.ca/nomad */ -/*-------------------------------------------------------------------------------------*/ -/** - \file Mesh.hpp - \brief Class for the MADS mesh (headers) - \author Sebastien Le Digabel - \date 2010-04-06 - \see Mesh.cpp -*/ -#ifndef __MESH__ -#define __MESH__ - -#include "Point.hpp" - -namespace NOMAD { - - /// Class for the MADS mesh. - /** - - The mesh in NOMAD is defined with the basic directions and the - mesh size parameter Delta^m_k. - - The mesh size parameter is defined with the mesh index (the integer ell_k). - - Use the static function \c NOMAD::Mesh::get_mesh_index() to access the value - of the mesh index ell_k. - - The poll size parameter Delta^p_k is not used to define the mesh but - to define the poll trial points. - - At each MADS iteration the mesh is updated with - Delta^m_k+1 = tau^w+ Delta^m_k and w+ >= 0 (dominating iteration) - or with - Delta^m_k+1 = tau^w- Delta^m_k and w- < 0 (iteration failure). - The mesh is not changed after improving iterations. - - Mesh and poll size parameters are stored as NOMAD::Point objects - (one value for each variable) in order to ensure automatic scaling. - - See the MADS papers for more details on the mesh. - */ - class Mesh { - - private: - - static double _mesh_update_basis; ///< Mesh update basis (tau) - static int _mesh_coarsening_exponent; ///< Mesh coarsening exponent (w+) - static int _mesh_refining_exponent; ///< Mesh refining exponent (w-) - static int _initial_mesh_index; ///< Initial mesh index (ell_0) - static int _mesh_index; ///< Mesh index (ell_k) - - static int _min_mesh_index; ///< Minimal value reached by the mesh index - static int _max_mesh_index; ///< Maximal value reached by the mesh index - - static int _max_halton_index; ///< Maximal Halton index for Ortho-MADS - - NOMAD::Point _initial_mesh_size; ///< Delta^m_0 (abs values; one delta/var) - - /// Equivalent of \c _min_poll_size for the mesh size parameter Delta^m_k. - NOMAD::Point _min_mesh_size; - - /// Delta^p_min (abs. values, one delta/var.); Can be undefined or incomplete. - NOMAD::Point _min_poll_size; - - /*--------------------------------------------------------------*/ - - /// Private affectation operator. - /** - \param m The right-hand side object -- \b IN. - */ - const Mesh & operator = ( const Mesh & m ); - - /// Check the minimal poll size criterion. - bool check_min_poll_size_criterion ( int mesh_index = Mesh::_mesh_index ) const; - - /// Check the minimal mesh size criterion. - bool check_min_mesh_size_criterion ( int mesh_index = Mesh::_mesh_index ) const; - - /*--------------------------------------------------------------*/ - - public: - - /// Constructor. - /** - \param delta_m_0 Initial mesh size Delta^m_0 -- \b IN. - \param delta_p_min Minimal poll size Delta^p_min (may be undefined) -- \b IN. - \param delta_m_min Minimal mesh size Delta^m_min (may be undefined) -- \b IN. - */ - Mesh ( const NOMAD::Point & delta_m_0 , - const NOMAD::Point & delta_p_min , - const NOMAD::Point & delta_m_min ); - - /// Copy constructor. - /** - \param m The copied object -- \b IN. - */ - Mesh ( const Mesh & m ) - : _initial_mesh_size ( m._initial_mesh_size ) , - _min_mesh_size ( m._min_mesh_size ) , - _min_poll_size ( m._min_poll_size ) {} - - /// Destructor. - virtual ~Mesh ( void ) {} - - /// Static members initialization. - /** - \param mesh_update_basis Mesh update basis (tau) -- \b IN. - \param mesh_coarsening_exponent Mesh coarsening exponent (w+) -- \b IN. - \param mesh_refining_exponent Mesh refining exponent (w-) -- \b IN. - \param initial_mesh_index Initial mesh index ell_0 -- \b IN. - */ - static void init ( double mesh_update_basis , - int mesh_coarsening_exponent , - int mesh_refining_exponent , - int initial_mesh_index ); - - /// Access to the initial mesh size. - /** - \return A NOMAD::Point for the initial mesh size. - */ - const NOMAD::Point & get_initial_mesh_size ( void ) const - { - return _initial_mesh_size; - } - - /// Access to the minimal mesh size. - /** - \return A NOMAD::Point for the minimal mesh size. - */ - const NOMAD::Point & get_min_mesh_size ( void ) const { return _min_mesh_size; } - - /// Access to the minimal poll size. - /** - \return A NOMAD::Point for the minimal poll size. - */ - const NOMAD::Point & get_min_poll_size ( void ) const { return _min_poll_size; } - - /// Access to the mesh index. - /** - \return An integer with the mesh index. - */ - static int get_mesh_index ( void ) { return Mesh::_mesh_index; } - - /// Manually set the mesh index. - /** - \param mesh_index The mesh index ell_k -- \b IN. - */ - static void set_mesh_index ( int mesh_index ); - - /// Access to the maximal mesh index. - /** - This corresponds to the maximal value of ell_k reached so far. - \return An integer with the maximal mesh index. - */ - static int get_max_mesh_index ( void ) { return Mesh::_max_mesh_index; } - - - /// Manually set the maximum mesh index. - /** - This corresponds to the maximum value of ell_k reached so far. - \param h The maximum mesh index -- \b IN. - */ - static void set_max_mesh_index ( int h ) { _max_mesh_index = h; } - - /// Access to the minimal mesh index. - /** - This corresponds to the minimal value of ell_k reached so far. - \return An integer with the minimal mesh index. - */ - static int get_min_mesh_index ( void ) { return Mesh::_min_mesh_index; } - - /// Manually set the minimum mesh index. - /** - This corresponds to the minimum value of ell_k reached so far. - \param h The minimum mesh index -- \b IN. - */ - static void set_min_mesh_index ( int h ) { _min_mesh_index = h; } - - /// Test if mesh index<max_mesh_index so far. - /** - \return True if mesh index lower than maximal mesh index False otherwise. - */ - // Use 1- Apply dynamic reduction of poll dir only if true - // use 2- Ortho n+1. Apply selection n directions out of 2n based on target dir only if true. Otherwise the selection alternates +/-. - static bool mesh_index_is_not_max(void){return Mesh::_mesh_index<Mesh::_max_mesh_index; /*true*/ } - - /// Access to the mesh update basis tau. - /** - \return A double with the mesh update basis tau. - */ - static double get_mesh_update_basis ( void ) { return Mesh::_mesh_update_basis; } - - /// Access to the maximal Halton index. - /** - This corresponds to the maximal value of the Halton index reached so far. - \return An integer with the maximal Halton index. - */ - static int get_max_halton_index ( void ) { return _max_halton_index; } - - /// Manually set the maximal Halton index. - /** - This corresponds to the maximal value of the Halton index reached so far. - \param h The maximal Halton index -- \b IN. - */ - static void set_max_halton_index ( int h ) { _max_halton_index = h; } - - /// Update the mesh (#1). - /** - \param success Type of success of the iteration -- \b IN. - \param mesh_index The mesh index before and after the update -- \b IN/OUT. - */ - static void update ( NOMAD::success_type success , int & mesh_index ); - - /// Update the mesh (#2). - /** - \param success Type of success of the iteration -- \b IN. - */ - static void update ( NOMAD::success_type success ) - { - Mesh::update ( success , Mesh::_mesh_index ); - } - - /// Access to the number of variables. - /** - This number of variables corresponds to the one used for the construction - of the current NOMAD::Mesh object. - \return An integer with the number of variables. - */ - int get_n ( void ) const { return _initial_mesh_size.size(); } - - /// Access to the mesh size parameter Delta^m_k. - /** - - The mesh size parameter is computed with - Delta^m_k = Delta^m_0 tau^{ell_0^+ - ell_k^+}. - - It is a NOMAD::Point of size \c nc the number of free variables. - \param delta_m The mesh size parameter Delta^m_k -- \b OUT. - \param mesh_index A mesh index ell_k -- \b IN - -- \b optional (default = the current mesh index ell_k.) - \return A boolean equal to \c true if all values are - strictly inferior than the associated minimal - mesh size Delta^m_min - (stopping criterion MIN_MESH_SIZE). - */ - bool get_delta_m ( NOMAD::Point & delta_m , - int mesh_index = Mesh::_mesh_index ) const; - - /// Access to the mesh size parameter Delta^m_k. - /** - - The mesh size parameter is computed with - Delta^m_k = Delta^m_0 tau^{ell_0^+ - ell_k^+}. - - It is a NOMAD::Point of size \c nc the number of free variables. - - This method is static and allows to compute mesh sizes - without a NOMAD::Mesh object. - \param delta_m Mesh size parameter Delta^m_k (size \c nc) -- \b OUT. - \param initial_mesh_size Initial mesh size Delta^m_0 (size \c nc) -- \b IN. - \param mesh_update_basis Mesh update basis tau -- \b IN. - \param initial_mesh_index Initial mesh index ell_0 -- \b IN. - \param mesh_index Mesh index ell_k -- \b IN. - */ - static void get_delta_m ( NOMAD::Point & delta_m , - const NOMAD::Point & initial_mesh_size , - double mesh_update_basis , - int initial_mesh_index , - int mesh_index ); - - /// Access to the poll size parameter Delta^p_k. - /** - - The poll size parameter is computed with - Delta^p_k = Delta^m_k tau^{ |ell_k|/2 } - = Delta^m_0 tau^{ell_0^+ - ell_k^+ + |ell_k|/2} - - It is a NOMAD::Point of size \c nc the number of free variables. - \param delta_p The poll size parameter Delta^p_k -- \b OUT. - \param mesh_index A mesh index -- \b IN - -- \b optional (default = the current mesh index ell_k.) - \return A boolean equal to \c true if all values are - strictly inferior than the associated minimal - poll size Delta^p_min - (stopping criterion MIN_POLL_SIZE). - */ - bool get_delta_p ( NOMAD::Point & delta_p , - int mesh_index = Mesh::_mesh_index ) const; - - /// Access to the poll size parameter Delta^p_k. - /** - - The poll size parameter is computed with - Delta^p_k = Delta^m_k tau^{ |ell_k|/2 } - = Delta^m_0 tau^{ell_0^+ - ell_k^+ + |ell_k|/2} - - It is a NOMAD::Point of size \c nc the number of free variables. - - This method is static and allows to compute poll sizes - without a NOMAD::Mesh object. - \param delta_p Poll size parameter Delta^p_k (size \c nc) -- \b OUT. - \param initial_mesh_size Initial mesh size Delta^m_0 (size \c nc) -- \b IN. - \param mesh_update_basis Mesh update basis tau -- \b IN. - \param initial_mesh_index Initial mesh index ell_0 -- \b IN. - \param mesh_index Mesh index ell_k -- \b IN. - */ - static void get_delta_p ( NOMAD::Point & delta_p , - const NOMAD::Point & initial_mesh_size , - double mesh_update_basis , - int initial_mesh_index , - int mesh_index ); - - /// Check the stopping conditions on the minimal poll and mesh sizes. - /** - \param max_mesh_index Maximal mesh index ell_max -- \b IN. - \param mesh_index Current mesh index ell_k -- \b IN. - \param stop Stop flag -- \b IN/OUT. - \param stop_reason Stop reason -- \b OUT. - */ - void check_min_mesh_sizes ( int max_mesh_index , - int mesh_index , - bool & stop , - NOMAD::stop_type & stop_reason ) const; - /// Display. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - }; - - /// Display a NOMAD::Mesh object. - /** - \param out The NOMAD::Display object -- \b IN. - \param m The NOMAD::Mesh object to be displayed -- \b IN. - \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Mesh & m ) - { - m.display ( out ); - return out; - } -} - -#endif diff --git a/src/Model_Sorted_Point.cpp b/src/Model_Sorted_Point.cpp index 0eaabf651aa827169054ab6ff0c7b68401186606..1afbbdbb421929bbc9d8b08f172cf4afbe973b51 100644 --- a/src/Model_Sorted_Point.cpp +++ b/src/Model_Sorted_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Model_Sorted_Point.hpp b/src/Model_Sorted_Point.hpp index 195a47dafc47b5e4dfc9d5186f314037d34183f0..c1e1a7c64d06439f014083d26ce7143e8c43d7b6 100644 --- a/src/Model_Sorted_Point.hpp +++ b/src/Model_Sorted_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Model_Stats.cpp b/src/Model_Stats.cpp index 60b4201577a5933fe5caab7359604925251814b1..bc18f4da6f89dd6b0aeef3f3f1c01d22349bf001 100644 --- a/src/Model_Stats.cpp +++ b/src/Model_Stats.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Model_Stats.hpp b/src/Model_Stats.hpp index 345fedd3848bd4c0becb7b8492f4aadc9555a2c5..1351a304cbf8237b2907dd1c6c0a6217fd59e590 100644 --- a/src/Model_Stats.hpp +++ b/src/Model_Stats.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Multi_Obj_Evaluator.cpp b/src/Multi_Obj_Evaluator.cpp index 4cf8b81b31823014f1addb5dd104e01bb9298701..89c5bfe23b45ebcbbb4dcfb081e1ef0b365e19fd 100644 --- a/src/Multi_Obj_Evaluator.cpp +++ b/src/Multi_Obj_Evaluator.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Multi_Obj_Evaluator.hpp b/src/Multi_Obj_Evaluator.hpp index e525c04ea69f7d54d60f4db7c11e391c5d32b3ba..522cb4f8780707249730e230cc6ddc4ed27decfc 100644 --- a/src/Multi_Obj_Evaluator.hpp +++ b/src/Multi_Obj_Evaluator.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Multi_Obj_Quad_Model_Evaluator.hpp b/src/Multi_Obj_Quad_Model_Evaluator.hpp index 36cb9db74f32228e0740a1ffc238f703ebd2d882..932fa5abe6a3905c4b4737eca156e805978b23d9 100644 --- a/src/Multi_Obj_Quad_Model_Evaluator.hpp +++ b/src/Multi_Obj_Quad_Model_Evaluator.hpp @@ -1,8 +1,7 @@ - /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version (3.5.1).7.2 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -38,7 +37,7 @@ \file Multi_Obj_Quad_Model_Evaluator.hpp \brief NOMAD::Mulit_Obj_Evaluator subclass for quadratic model optimization (headers) \author Christophe Tribes - \date 2012-06-19 + \date 2014-06-19 \see Multi_Obj_Quad_Model_Evaluator.cpp */ #ifndef __MULTI_OBJ_QUAD_MODEL_EVALUATOR__ @@ -59,11 +58,12 @@ namespace NOMAD { \param model Model -- \b IN. */ Multi_Obj_Quad_Model_Evaluator ( const NOMAD::Parameters & p , - const NOMAD::Quad_Model & model ) : NOMAD::Quad_Model_Evaluator(p,model),NOMAD::Multi_Obj_Evaluator(p) {;} + const NOMAD::Quad_Model & model ) : NOMAD::Quad_Model_Evaluator(p,model),NOMAD::Multi_Obj_Evaluator(p) {_is_model_evaluator=true;} /// Destructor. virtual ~Multi_Obj_Quad_Model_Evaluator ( void ){;} + /// Evaluate the blackboxes quad model at a given trial point /** \param x point to evaluate -- \b IN/OUT. diff --git a/src/OrthogonalMesh.cpp b/src/OrthogonalMesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c7331aea1444bbe891c17b523d05cb7967acc3d --- /dev/null +++ b/src/OrthogonalMesh.cpp @@ -0,0 +1,205 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Sebastien Le Digabel */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file OrthogonalMesh.hpp + \brief implementation + \author Christophe Tribes + \date 2014-06-19 + \see SMesh.cpp XMesh.cpp + */ + +#include "OrthogonalMesh.hpp" + +/// Constructor (called only by derived objects). +NOMAD::OrthogonalMesh::OrthogonalMesh (const NOMAD::Point & Delta_0 , + const NOMAD::Point & Delta_min , + const NOMAD::Point & delta_min , + const NOMAD::Point & fixed_variables , + NOMAD::Double update_basis, + int coarsening_step, + int refining_step, + int limit_mesh_index ) : +_delta_0 ( Delta_0 ), +_Delta_0 ( Delta_0 ), +_Delta_min ( Delta_min ), +_delta_min ( delta_min ), +_update_basis ( update_basis ), +_coarsening_step ( coarsening_step ), +_refining_step ( refining_step ), +_limit_mesh_index ( limit_mesh_index ) +{ + + _Delta_min_is_defined=_Delta_min.is_defined(); + _Delta_min_is_complete=_Delta_min.is_complete(); + + bool chkMesh = delta_min.is_defined(); + bool chkPoll = _Delta_min_is_defined; + _n = Delta_0.size(); + + + _n_free_variables = _n - fixed_variables.nb_defined(); + + // The delta_0 are decreased + _delta_0*=pow(_n_free_variables,-0.5); + + if ( !_Delta_0.is_complete() ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , + "NOMAD::OrthogonalMesh::OrthogonalMesh(): delta_0 has undefined values" ); + + if ( chkMesh && delta_min.size() != _n ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , + "NOMAD::OrthogonalMesh::OrthogonalMesh(): delta_0 and delta_min have different sizes" ); + + if ( chkPoll && Delta_min.size() != _n ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , + "NOMAD::OrthogonalMesh::OrthogonalMesh(): Delta_0 and Delta_min have different sizes" ); + + + std::string error; + for ( int k = 0 ; k < _n ; ++k ) + { + // we check that Delta_min <= Delta_0 and that delta_min <= delta_0: + if ( chkMesh && + _delta_min[k].is_defined() && + _delta_0[k] < _delta_min[k] ) + { + error = "NOMAD::OrthogonalMesh::OrthogonalMesh(): delta_0 < delta_min"; + break; + } + if ( chkPoll && + _Delta_min[k].is_defined() && + _Delta_0[k] < _Delta_min[k] ) + { + error = "NOMAD::OrthogonalMesh::OrthogonalMesh(): Delta_0 < Delta_min"; + break; + } + + } + + if ( !error.empty() ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , error ); +} + + + +bool NOMAD::OrthogonalMesh::is_finer_than_initial (void) const +{ + NOMAD::Point delta; + get_delta(delta); + + for (int i =0; i < _n ; ++i ) + if ( delta[i] >= _delta_0[i] ) + return false; + + return true; +} + + + +/// Manually set the min mesh size per coordinate. +void NOMAD::OrthogonalMesh::set_min_mesh_sizes ( const NOMAD::Point & delta_min ) +{ + + // If delta_min undefined than _delta_min->undefined + if ( ! delta_min.is_defined() ) + { + _delta_min.clear(); + return; + } + + // If delta_min defined test that everything is consistent + if ( delta_min.size() != _n ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::OrthogonalMesh::set_min_mesh_sizes() delta_min has dimension different than mesh dimension" ); + + if ( !delta_min.is_complete() ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , + "NOMAD::OrthogonalMesh::set_min_mesh_sizes(): delta_min has some defined and undefined values" ); + + std::string error; + for ( int k = 0 ; k < _n ; ++k ) + { + + // we check that Delta_min <= Delta_0 and that delta_min <= delta_0: + if ( delta_min[k].is_defined() && + _delta_0[k] < delta_min[k] ) + { + error = "NOMAD::OrthogonalMesh::set_delta_min(): delta_0 < delta_min"; + break; + } + if ( delta_min[k].is_defined() && + _Delta_0[k] < delta_min[k] ) + { + error = "NOMAD::OrthogonalMesh::set_delta_min(): Delta_0 < delta_min"; + break; + } + + } + + if ( !error.empty() ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , error ); + + _delta_min=delta_min; + +} + + + +/*-----------------------------------------------------------*/ +/* set delta_0 */ +/*-----------------------------------------------------------*/ +void NOMAD::OrthogonalMesh::set_delta_0 ( const NOMAD::Point & d ) +{ + + if ( d.size() != _delta_0.size() ) + throw NOMAD::Exception ( "OrthogonalMesh.hpp" , __LINE__ , + "NOMAD::OrthogonalMesh::set_delta_0(): dimension of provided delta_0 must be consistent with their previous dimension" ); + + _delta_0=d; +} + +/*-----------------------------------------------------------*/ +/* set Delta_0 */ +/*-----------------------------------------------------------*/ +void NOMAD::OrthogonalMesh::set_Delta_0 ( const NOMAD::Point & d ) +{ + + if ( d.size() != _Delta_0.size() ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::set_Delta_0(): dimension of provided Delta_0 must be consistent with their previous dimension" ); + + _Delta_0=d; +} diff --git a/src/OrthogonalMesh.hpp b/src/OrthogonalMesh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5971ae5ea03e931d42fce8e58c5f1cbda63e8943 --- /dev/null +++ b/src/OrthogonalMesh.hpp @@ -0,0 +1,384 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Sebastien Le Digabel */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file OrthogonalMesh.hpp + \brief Virtual class for the MADS orthogonal meshes (headers) + \author Christophe Tribes + \date 2010-04-06 + \see Mesh.cpp XMesh.cpp +*/ +#ifndef __ORTHOGONALMESH__ +#define __ORTHOGONALMESH__ + +#include "Point.hpp" +#include "Direction.hpp" + +namespace NOMAD { + + /// Virtual class for the MADS orthogonal meshes. + /** + - An orthogonal mesh in NOMAD is defined with the basic orthogonal directions the + mesh size parameter delta^k. + - The poll size parameter Delta^k is not used to define the mesh but + to define the poll trial points. + - At each MADS iteration the mesh is updated. + - Mesh and poll size parameters are stored as NOMAD::Point objects. + */ + class OrthogonalMesh { + + /*--------------------------------------------------------------*/ + private: + + + /*--------------------------------------------------------------*/ + + /// Private affectation operator. + /** + \param m The right-hand side object -- \b IN. + */ + const OrthogonalMesh & operator = ( const OrthogonalMesh & m ); + + + /*--------------------------------------------------------------*/ + protected: + + + NOMAD::Point _delta_0; + NOMAD::Point _Delta_0; + NOMAD::Point _Delta_min; + NOMAD::Point _delta_min; + + + NOMAD::Double _update_basis; + int _coarsening_step; + int _refining_step ; + + int _n; + + bool _Delta_min_is_defined; + bool _Delta_min_is_complete; + + int _n_free_variables; + + int _limit_mesh_index; // Limit max or min of the mesh index for fine mesh (SMesh->max, XMesh->min) + + /// Constructor (called only by derived objects). + /** + \param Delta_0 Initial poll size Delta_0 -- \b IN. + \param Delta_min Minimal poll size Delta_min (may be undefined) -- \b IN. + \param delta_min Minimal mesh size delta_min (may be undefined) -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + \param update_basis Mesh/poll update basis (tau) -- \b IN. + \param coarsening_step Mesh/poll coarsening exponent (w+) -- \b IN. + \param refining_step Mesh/poll refining exponent (w-) -- \b IN. + \param limit_mesh_index Limit mesh index to trigger stopping criterion -- \b IN. + */ + OrthogonalMesh (const NOMAD::Point & Delta_0 , + const NOMAD::Point & Delta_min , + const NOMAD::Point & delta_min , + const NOMAD::Point & fixed_variables , + NOMAD::Double update_basis, + int coarsening_step, + int refining_step, + int limit_mesh_index ) ; + + + /// Copy constructor (called only by derived objects). + /** + \param m The copied object -- \b IN. + */ + OrthogonalMesh ( const OrthogonalMesh & m ) + : _delta_0 ( m._delta_0 ), + _Delta_0 ( m._Delta_0 ), + _Delta_min ( m._Delta_min ), + _delta_min ( m._delta_min ), + _update_basis ( m._update_basis ), + _coarsening_step ( m._coarsening_step ), + _refining_step ( m._refining_step ), + _n ( m._n ), + _Delta_min_is_defined ( m._Delta_min_is_defined ), + _Delta_min_is_complete ( m._Delta_min_is_complete ), + _n_free_variables ( m._n_free_variables ), + _limit_mesh_index ( m._limit_mesh_index){} + + + /*--------------------------------------------------------------*/ + public: + + + /// Destructor. + virtual ~OrthogonalMesh ( void ){;} + + + /// Update the Mesh (poll and mesh sizes). + /** + \param success Type of success of the iteration -- \b IN. + \param dir Direction of the iteration (optional) -- \b IN. + */ + virtual void update ( NOMAD::success_type success, const NOMAD::Direction * dir=NULL) = 0; + + + /// Update the provided mesh indices (the Mesh is unchanged). + /** + \param success Type of success of the iteration -- \b IN. + \param mesh_indices Provided mesh indices for update -- \b IN/OUT. + \param dir Direction of the iteration (optional) -- \b IN. + */ + virtual void update ( NOMAD::success_type success, NOMAD::Point & mesh_indices, const NOMAD::Direction * dir=NULL ) const = 0; + + + + /// Reset the Mesh to its original sizes (poll and mesh sizes). + virtual void reset ( void ) = 0; + + + /// Access to the initial mesh size. + /** + \return A NOMAD::Point for the initial mesh size. + */ + const NOMAD::Point & get_initial_mesh_size ( void ) const { return _delta_0; } + + /// Access to the initial poll size. + /** + \return A NOMAD::Point for the initial poll size. + */ + const NOMAD::Point & get_initial_poll_size ( void ) const { return _Delta_0; } + + + /// Access to the minimal mesh size. + /** + \return A NOMAD::Point for the minimal mesh size. + */ + const NOMAD::Point & get_min_mesh_size ( void ) const { return _delta_min; } + + + /// Access to the minimal poll size. + /** + \return A NOMAD::Point for the minimal poll size. + */ + const NOMAD::Point & get_min_poll_size ( void ) const { return _Delta_min; } + + + /// Test if mesh is finest so far. + /** + \return True if mesh is the finest so far, False otherwise. + */ + virtual bool is_finest(void) const = 0; + + + /// Test if current mesh is finer than initial mesh (used by VNS search). + /** + \return True if mesh size is smaller than initial mesh size for all components. + */ + bool is_finer_than_initial (void) const; + + + /// Access to the mesh/poll update basis tau. + /** + \return A double with the update basis tau. + */ + double get_update_basis ( void ) const { return _update_basis.value(); } + + + /// Access to the mesh ratio after a success + /** + \return A point with the ratio for each coordinate + */ + virtual NOMAD::Point get_mesh_ratio_if_success( void ) const = 0; + + + /// Access to the number of variables. + /** + \return An integer with the number of variables. + */ + int get_n ( void ) const { return _n; } + + + /// Access to the number of free variables. + /** + \return An integer with the number of free variables. + */ + int get_n_free_variables ( void ) const { return _n_free_variables; } + + + /// Access to the mesh size parameter delta^k. + /** + \return delta The mesh size parameter delta^k -- \b OUT. + */ + NOMAD::Point get_delta ( void ) const + { + NOMAD::Point delta; + get_delta(delta); + return delta; + } + + /// Access to the mesh size parameter delta^k. + /** + \param delta The mesh size parameter delta^k -- \b OUT. + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + mesh size delta_min + (stopping criterion MIN_MESH_SIZE). + */ + virtual bool get_delta ( NOMAD::Point & delta ) const = 0; + + /// Access to the largest mesh size. + /** + \return The largest mesh size -- \b OUT. + */ + virtual NOMAD::Point get_delta_max ( void ) const = 0; + + + /// Access to the poll size parameter Delta^k. + /** + \return Delta The poll size parameter Delta^k -- \b OUT. + */ + NOMAD::Point get_Delta ( void ) + { + NOMAD::Point Delta; + get_Delta(Delta); + return Delta; + } + + /// Access to the poll size parameter Delta^k. + /** + \param Delta The poll size parameter Delta^k -- \b OUT. + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + mesh size delta_min + (stopping criterion MIN_POLL_SIZE). + */ + virtual bool get_Delta ( NOMAD::Point & Delta ) const = 0 ; + + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + virtual void display ( const NOMAD::Display & out ) const = 0; + + /// Check the stopping conditions on the minimal poll and mesh sizes. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + virtual void check_min_mesh_sizes ( bool & stop , + NOMAD::stop_type & stop_reason ) const = 0; + + /// Access to the mesh indices per coordinate. + /** + \return A point with the mesh index for each coordinate. + */ + virtual const NOMAD::Point get_mesh_indices ( void ) const = 0; + + /// Manually set the mesh indices per coordinate (virtual). + /** + \param r The mesh index per coordinate -- \b IN. + */ + virtual void set_mesh_indices ( const NOMAD::Point & r ) =0 ; + + /// Manually set the min mesh size per coordinate. + /** + \param delta_min The min mesh sizes per coordinate (can be undefined) -- \b IN. + */ + void set_min_mesh_sizes ( const NOMAD::Point & delta_min ); + + /// Manually set intial mesh size per coordinate. + /** + \param d The initial mesh sizes per coordinate -- \b IN. + */ + void set_delta_0 ( const NOMAD::Point & d ); + + /// Manually set intial poll size per coordinate. + /** + \param d The initial poll sizes per coordinate -- \b IN. + */ + void set_Delta_0 ( const NOMAD::Point & d ); + + + /// Access to the min mesh indices reached so far. + /** + \return A point with the mesh index for each coordinate. + */ + virtual const NOMAD::Point get_min_mesh_indices ( void ) const = 0; + + /// Access to the max mesh indices reached so far. + /** + \return A point with the mesh index for each coordinate. + */ + virtual const NOMAD::Point get_max_mesh_indices ( void ) const = 0; + + + /// Access to the limit mesh index. + /** + \return An integer with the limit mesh index. + */ + int get_limit_mesh_index ( void ) const { return _limit_mesh_index;} + + + /// Manually set the limit mesh index. + /** + \param limit_mesh_index The limit mesh index. + */ + virtual void set_limit_mesh_index ( int limit_mesh_index ) = 0; + + + /// Scale and project the ith component of a vector on the mesh + /** + \param i The vector component number -- \b IN. + \param l The vector component value -- \b IN. + \return The ith component of a vector after mesh scaling and projection + */ + virtual NOMAD::Double scale_and_project(int i, const NOMAD::Double & l) const = 0 ; + + + }; + + /// Display a NOMAD::OrthogonalMesh object. + /** + \param out The NOMAD::Display object -- \b IN. + \param m The NOMAD::OrthogonalMesh object to be displayed -- \b IN. + \return The NOMAD::Display object. + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::OrthogonalMesh & m ) + { + m.display ( out ); + return out; + } +} + +#endif diff --git a/src/Parameter_Entries.cpp b/src/Parameter_Entries.cpp index 5b30143a0a6dfa585d2384205cc61f28af1adb27..6a7392c8cb4fa578d24065d9029ae0460b62d7c4 100644 --- a/src/Parameter_Entries.cpp +++ b/src/Parameter_Entries.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Parameter_Entries.hpp b/src/Parameter_Entries.hpp index 7c1d9e1f3030f841f7c40d09b3dce68a3c7cbec6..aff4d011b277bc8e987de16c2dc924bc7af28671 100644 --- a/src/Parameter_Entries.hpp +++ b/src/Parameter_Entries.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Parameter_Entry.cpp b/src/Parameter_Entry.cpp index 069e559ace332855c656aa4f7fcbdf93d9e94b9e..de60272d0c1a7822d0901232fab6ef8840bf77d2 100644 --- a/src/Parameter_Entry.cpp +++ b/src/Parameter_Entry.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -57,6 +57,10 @@ NOMAD::Parameter_Entry::Parameter_Entry ( const std::string & entry , std::string s; std::istringstream in ( entry ); in >> _name; + + if (_name.size()==0) + return; + if ( remove_comments && _name[0] == '#' ) _name.clear(); else { diff --git a/src/Parameter_Entry.hpp b/src/Parameter_Entry.hpp index 5333af52ae819a7dd6a133d3b371b3567b53051e..7c1e0b96bd7b491f38d6381aceba961f6a324911 100644 --- a/src/Parameter_Entry.hpp +++ b/src/Parameter_Entry.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Parameters.cpp b/src/Parameters.cpp index 3d22e53936ceba7b905e6141fa45d7a618c0d5ca..cf218fe94a114a0ed88a836aac507b71f7678e29 100644 --- a/src/Parameters.cpp +++ b/src/Parameters.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -42,6 +42,8 @@ */ #include "Parameters.hpp" #include "Slave.hpp" +#include "XMesh.hpp" +#include "SMesh.hpp" bool NOMAD::Parameters::_warning_has_been_displayed=false; @@ -50,9 +52,9 @@ bool NOMAD::Parameters::_warning_has_been_displayed=false; /*----------------------------------------*/ NOMAD::Parameters::~Parameters ( void ) { - delete _std_signature; - delete_x0s(); - reset_variable_groups(); + delete _std_signature; + delete_x0s(); + reset_variable_groups(); } /*----------------------------------------*/ @@ -60,174 +62,183 @@ NOMAD::Parameters::~Parameters ( void ) /*----------------------------------------*/ void NOMAD::Parameters::init ( void ) { - // miscellaneous and algorithm parameters: - _to_be_checked = true; - _seed = NOMAD::get_pid(); - _max_eval = -1; - _max_sim_bb_eval = -1; - _max_bb_eval = -1; - _max_bbe_decided = false; - _max_time = -1; - _max_iterations = -1; - _max_cons_failed_it = -1; - _max_cache_memory = 2000; - _cache_save_period = 25; - _snap_to_bounds = true; - _stop_if_feasible = false; - _user_calls_enabled = true; - _asynchronous = true; - _stat_sum_target.clear(); - _L_curve_target.clear(); - _cache_file.clear(); - _problem_dir.clear(); - _tmp_dir.clear(); - - // F_TARGET: - reset_f_target(); - - // output files: - _add_seed_to_file_names = true; - _solution_file.clear(); - _history_file.clear(); - - // NOMAD::Double static members: - set_EPSILON ( NOMAD::DEFAULT_EPSILON ); - set_UNDEF_STR ( NOMAD::DEFAULT_UNDEF_STR ); - set_INF_STR ( NOMAD::DEFAULT_INF_STR ); - - // Mesh: - _mesh_update_basis.clear(); - _mesh_coarsening_exponent = 1; - _mesh_refining_exponent =-1; - _initial_mesh_index = 0; - _max_mesh_index = NOMAD::UNDEFINED_L; - _min_poll_size_defined = false; - _initial_mesh_size.clear(); - _min_mesh_size.clear(); - _min_poll_size.clear(); - - // Directions: - reset_directions ( -1 ); - - // X0: - reset_X0(); - - // signature: - delete _std_signature; - _std_signature = NULL; - - // variables: - _dimension = -1; - _nb_free_variables = -1; - _extended_poll_trigger = 0.1; - _relative_ept = true; - _extended_poll_enabled = true; - _bb_input_include_tag = false; - _bb_input_include_seed = false; - _bb_redirection = true; - _bb_input_type.clear(); - _neighbors_exe.clear(); - reset_bounds(); - reset_scaling(); - reset_fixed_variables(); - reset_periodic_variables(); - reset_variable_groups(); - - // Barrier: - _rho = 0.1; - _h_min = 0.0; - _h_max_0 = NOMAD::INF; - _h_norm = NOMAD::L2; - _has_constraints = false; - _has_EB_constraints = false; - _has_filter_constraints = false; - _barrier_type = NOMAD::EB; - - // outputs: - _index_obj.clear(); - _bb_exe.clear(); - _bb_output_type.clear(); - _index_cnt_eval = -1; - _index_stat_sum = -1; - _index_stat_avg = -1; - - // surrogate: - _sgte_exe.clear(); - _sgte_cache_file.clear(); - _sgte_eval_sort = true; - _has_sgte = false; - _opt_only_sgte = false; - _sgte_cost = -1; - _sgte_max_eval = -1; - - // MULTI-MADS: - _multi_nb_mads_runs = -1; - _multi_overall_bb_eval = -1; - _multi_use_delta_crit = false; - _multi_formulation = NOMAD::UNDEFINED_FORMULATION; - _multi_f_bounds.reset(); - - // model disabled - _disable_models=false; - - - // model search parameters: - _model_params.search1 = NOMAD::QUADRATIC_MODEL; - _model_params.search2 = NOMAD::NO_MODEL; - - _model_params.search_proj_to_mesh = true; - _model_params.search_optimistic = true; - _model_params.search_max_trial_pts = 10; - - // model ordering parameters: - _model_params.eval_sort = NOMAD::QUADRATIC_MODEL; - _model_params.eval_sort_cautious = true; - - // quadratic model parameters: - _model_params.quad_radius_factor = 2.0; - _model_params.quad_use_WP = false; - _model_params.quad_min_Y_size = -1; - _model_params.quad_max_Y_size = 500; - _model_params.model_np1_quad_epsilon =0.01; - - // TGP model parameters: - _model_params.tgp_mode = NOMAD::TGP_FAST; - _model_params.tgp_reuse_model = true; - - // other searches: - _VNS_trigger.clear(); - _speculative_search = true; - _VNS_search = false; - _LH_search_p0 = -1; - _LH_search_pi = -1; - _opportunistic_LH = true; - _opp_LH_is_defined = false; - _cache_search = false; - _opportunistic_cache_search = false; - _opp_CS_is_defined = false; - - // opportunistic strategy: - _opportunistic_eval = true; - _opportunistic_min_nb_success = -1; - _opportunistic_min_eval = -1; - _opportunistic_lucky_eval = false; - _opportunistic_min_f_imprvmt.clear(); - - // display: - _out.set_degrees ( NOMAD::NORMAL_DISPLAY ); + // miscellaneous and algorithm parameters: + _to_be_checked = true; + _seed = 0; + // _seed = NOMAD::get_pid(); + _max_eval = -1; + _max_sim_bb_eval = -1; + _max_bb_eval = -1; + _max_bbe_decided = false; + _max_time = -1; + _max_iterations = -1; + _max_cons_failed_it = -1; + _max_cache_memory = 2000; + _cache_save_period = 25; + _snap_to_bounds = true; + _stop_if_feasible = false; + _user_calls_enabled = true; + _asynchronous = true; + _stat_sum_target.clear(); + _L_curve_target.clear(); + _cache_file.clear(); + _problem_dir.clear(); + _tmp_dir.clear(); + + // F_TARGET: + reset_f_target(); + + // output files: + _add_seed_to_file_names = true; + _solution_file.clear(); + _history_file.clear(); + + // NOMAD::Double static members: + set_EPSILON ( NOMAD::DEFAULT_EPSILON ); + set_UNDEF_STR ( NOMAD::DEFAULT_UNDEF_STR ); + set_INF_STR ( NOMAD::DEFAULT_INF_STR ); + + // Mesh: + _anisotropic_mesh = true; + _use_smesh = false; + _mesh_update_basis = 4; + _poll_update_basis = 2; + _mesh_coarsening_exponent = 1; + _mesh_refining_exponent =-1; + _initial_mesh_index = 0; + _min_poll_size_defined = false; + _initial_mesh_size.clear(); + _initial_poll_size.clear(); + _min_mesh_size.clear(); + _min_poll_size.clear(); + + // Directions: + reset_directions ( ); + + // X0: + reset_X0(); + + // signature: + delete _std_signature; + _std_signature = NULL; + + // variables: + _dimension = -1; + _nb_free_variables = -1; + _extended_poll_trigger = 0.1; + _relative_ept = true; + _extended_poll_enabled = true; + _bb_input_include_tag = false; + _bb_input_include_seed = false; + _bb_redirection = true; + _bb_input_type.clear(); + _neighbors_exe.clear(); + reset_bounds(); + reset_scaling(); + reset_fixed_variables(); + reset_periodic_variables(); + reset_variable_groups(); + + // Barrier: + _rho = 0.1; + _h_min = 0.0; + _h_max_0 = NOMAD::INF; + _h_norm = NOMAD::L2; + _has_constraints = false; + _has_EB_constraints = false; + _has_filter_constraints = false; + _barrier_type = NOMAD::EB; + + // outputs: + _index_obj.clear(); + _bb_exe.clear(); + _bb_output_type.clear(); + _index_cnt_eval = -1; + _index_stat_sum = -1; + _index_stat_avg = -1; + + // surrogate: + _sgte_exe.clear(); + _sgte_cache_file.clear(); + _sgte_eval_sort = true; + _has_sgte = false; + _opt_only_sgte = false; + _sgte_cost = -1; + _sgte_max_eval = -1; + + // MULTI-MADS: + _multi_nb_mads_runs = -1; + _multi_overall_bb_eval = -1; + _multi_use_delta_crit = false; + _multi_formulation = NOMAD::UNDEFINED_FORMULATION; + _multi_f_bounds.reset(); + + // model is not disabled + _disable_models=false; + + // sort is not disabled + _disable_eval_sort=false; + + + // model search parameters: + _model_params.search1 = NOMAD::QUADRATIC_MODEL; + _model_params.search2 = NOMAD::NO_MODEL; + + _model_params.search_proj_to_mesh = true; + _model_params.search_optimistic = true; + _model_params.search_max_trial_pts = 10; + + // model ordering parameters: + _model_params.eval_sort = NOMAD::QUADRATIC_MODEL; + _model_params.eval_sort_cautious = false; + + // quadratic model parameters: + _model_params.quad_radius_factor = 2.0; + _model_params.quad_use_WP = false; + _model_params.quad_min_Y_size = -1; + _model_params.quad_max_Y_size = 500; + _model_params.model_np1_quad_epsilon =0.01; + + // TGP model parameters: + _model_params.tgp_mode = NOMAD::TGP_FAST; + _model_params.tgp_reuse_model = true; + + // other searches: + _VNS_trigger.clear(); + _speculative_search = true; + _VNS_search = false; + _LH_search_p0 = -1; + _LH_search_pi = -1; + _opportunistic_LH = true; + _opp_LH_is_defined = false; + _cache_search = false; + _opportunistic_cache_search = false; + _opp_CS_is_defined = false; + + // opportunistic strategy: + _bb_max_block_size = 1; + _eval_points_as_block = false; + _opportunistic_eval = true; + _opportunistic_min_nb_success = -1; + _opportunistic_min_eval = -1; + _opportunistic_lucky_eval = false; + _opportunistic_min_f_imprvmt.clear(); + + // display: + _out.set_degrees ( NOMAD::NORMAL_DISPLAY ); #ifdef DEBUG - set_POINT_DISPLAY_LIMIT ( -1 ); + set_POINT_DISPLAY_LIMIT ( -1 ); #else - set_POINT_DISPLAY_LIMIT ( NOMAD::DEFAULT_POINT_DISPLAY_LIMIT ); + set_POINT_DISPLAY_LIMIT ( NOMAD::DEFAULT_POINT_DISPLAY_LIMIT ); #endif - - _out.set_open_brace ( "{" ); - _out.set_closed_brace ( "}" ); - - _display_stats.clear(); - reset_stats_file(); - - _display_all_eval = false; + + _out.set_open_brace ( "{" ); + _out.set_closed_brace ( "}" ); + + _display_stats.clear(); + reset_stats_file(); + + _display_all_eval = false; } /*------------------------------------------------------------------*/ @@ -236,10 +247,10 @@ void NOMAD::Parameters::init ( void ) /*------------------------------------------------------------------*/ void NOMAD::Parameters::delete_x0s ( void ) { - size_t x0n = _x0s.size(); - for ( size_t i = 0 ; i < x0n ; ++i ) - delete _x0s[i]; - _x0s.clear(); + size_t x0n = _x0s.size(); + for ( size_t i = 0 ; i < x0n ; ++i ) + delete _x0s[i]; + _x0s.clear(); } /*----------------------------------------*/ @@ -247,20 +258,19 @@ void NOMAD::Parameters::delete_x0s ( void ) /*----------------------------------------*/ void NOMAD::Parameters::reset_X0 ( void ) { - _to_be_checked = true; - delete_x0s(); - _x0_cache_file.clear(); + _to_be_checked = true; + delete_x0s(); + _x0_cache_file.clear(); } /*----------------------------------------*/ /* reset the directions */ /*----------------------------------------*/ -void NOMAD::Parameters::reset_directions ( int halton_seed ) +void NOMAD::Parameters::reset_directions ( void ) { - _to_be_checked = true; - _direction_types.clear(); - _sec_poll_dir_types.clear(); - _halton_seed = halton_seed; + _to_be_checked = true; + _direction_types.clear(); + _sec_poll_dir_types.clear(); } /*--------------------------------------------*/ @@ -269,20 +279,20 @@ void NOMAD::Parameters::reset_directions ( int halton_seed ) bool NOMAD::Parameters::check_display_stats ( const std::list<std::string> & stats ) const { - int var_index; - std::list<std::string>::const_iterator it , end = stats.end(); - for ( it = stats.begin() ; it != end ; ++it ) { - if ( !it->empty() && - NOMAD::Display::get_display_stats_type(*it) == NOMAD::DS_VAR ) { - ++it; - if ( !NOMAD::atoi ( *it , var_index ) || - var_index < 0 || - var_index >= _dimension ) { - return false; - } - } - } - return true; + int var_index; + std::list<std::string>::const_iterator it , end = stats.end(); + for ( it = stats.begin() ; it != end ; ++it ) { + if ( !it->empty() && + NOMAD::Display::get_display_stats_type(*it) == NOMAD::DS_VAR ) { + ++it; + if ( !NOMAD::atoi ( *it , var_index ) || + var_index < 0 || + var_index >= _dimension ) { + return false; + } + } + } + return true; } /*--------------------------------------------*/ @@ -290,38 +300,38 @@ bool NOMAD::Parameters::check_display_stats /*--------------------------------------------*/ bool NOMAD::Parameters::check_directory ( std::string & s ) { - // step 1: remove spaces at the begining: - size_t i = 0 , ns = s.size(); - while ( i < ns && s[i] == ' ' ) - ++i; - std::string ss; - while ( i < ns ) - ss.push_back(s[i++]); - if ( ss.empty() ) - return false; - s = ss; - - // step 2: replace '/' or '\' with DIR_SEP: - i = 0; - ns = s.size(); - while ( i < ns ) { - if ( s[i] == '/' || s[i] == '\\' ) - s[i] = NOMAD::DIR_SEP; - ++i; - } - - // step 3: add DIR_SEP at the end: - if ( i >= 1 ) { - if (s[i-1] != NOMAD::DIR_SEP) { - s += NOMAD::DIR_SEP; - } - } - else { - s = "."; - s.push_back ( NOMAD::DIR_SEP ); - } - - return true; + // step 1: remove spaces at the begining: + size_t i = 0 , ns = s.size(); + while ( i < ns && s[i] == ' ' ) + ++i; + std::string ss; + while ( i < ns ) + ss.push_back(s[i++]); + if ( ss.empty() ) + return false; + s = ss; + + // step 2: replace '/' or '\' with DIR_SEP: + i = 0; + ns = s.size(); + while ( i < ns ) { + if ( s[i] == '/' || s[i] == '\\' ) + s[i] = NOMAD::DIR_SEP; + ++i; + } + + // step 3: add DIR_SEP at the end: + if ( i >= 1 ) { + if (s[i-1] != NOMAD::DIR_SEP) { + s += NOMAD::DIR_SEP; + } + } + else { + s = "."; + s.push_back ( NOMAD::DIR_SEP ); + } + + return true; } /*---------------------------------------------------------------*/ @@ -331,38 +341,38 @@ bool NOMAD::Parameters::check_directory ( std::string & s ) void NOMAD::Parameters::interpret_periodic_var ( const NOMAD::Parameter_Entries & entries ) { - int i , j , k; - std::list<std::string>::const_iterator it , end; - NOMAD::Parameter_Entry * pe = entries.find ( "PERIODIC_VARIABLE" ); - - while ( pe ) { - - // just one variable index (can be '*' or a range of indexes 'i-j'): - if ( pe->get_nb_values() == 1 ) { - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE" ); - - for ( k = i ; k <= j ; ++k ) - set_PERIODIC_VARIABLE (k); - } - - // list of variable indexes: - else { - end = pe->get_values().end(); - for ( it = pe->get_values().begin() ; it != end ; ++it ) { - if ( !NOMAD::atoi ( *it , i ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE" ); - set_PERIODIC_VARIABLE (i); - } - } - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + int i , j , k; + std::list<std::string>::const_iterator it , end; + NOMAD::Parameter_Entry * pe = entries.find ( "PERIODIC_VARIABLE" ); + + while ( pe ) { + + // just one variable index (can be '*' or a range of indexes 'i-j'): + if ( pe->get_nb_values() == 1 ) { + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE" ); + + for ( k = i ; k <= j ; ++k ) + set_PERIODIC_VARIABLE (k); + } + + // list of variable indexes: + else { + end = pe->get_values().end(); + for ( it = pe->get_values().begin() ; it != end ; ++it ) { + if ( !NOMAD::atoi ( *it , i ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE" ); + set_PERIODIC_VARIABLE (i); + } + } + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*------------------------------------------------------------*/ @@ -371,46 +381,45 @@ void NOMAD::Parameters::interpret_periodic_var /*------------------------------------------------------------*/ void NOMAD::Parameters::interpret_var_groups ( const NOMAD::Parameter_Entries & entries ) { - int i , j , k; - std::set<int> var_indexes; - std::list<std::string>::const_iterator it , end; - NOMAD::Parameter_Entry * pe = entries.find ( "VARIABLE_GROUP" ); - - while ( pe ) { - - // just one variable index (can be '*' or a range of indexes 'i-j'): - if ( pe->get_nb_values() == 1 ) { - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP" ); - - for ( k = j ; k >= i ; --k ) - var_indexes.insert(k); - } - - // list of variable indexes: - else { - end = pe->get_values().end(); - for ( it = pe->get_values().begin() ; it != end ; ++it ) { - if ( !NOMAD::atoi ( *it , i ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP" ); - var_indexes.insert(i); - } - } - - set_VARIABLE_GROUP ( var_indexes , - _direction_types , - _sec_poll_dir_types , - -1 ); - - var_indexes.clear(); - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + int i , j , k; + std::set<int> var_indexes; + std::list<std::string>::const_iterator it , end; + NOMAD::Parameter_Entry * pe = entries.find ( "VARIABLE_GROUP" ); + + while ( pe ) { + + // just one variable index (can be '*' or a range of indexes 'i-j'): + if ( pe->get_nb_values() == 1 ) { + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP" ); + + for ( k = j ; k >= i ; --k ) + var_indexes.insert(k); + } + + // list of variable indexes: + else { + end = pe->get_values().end(); + for ( it = pe->get_values().begin() ; it != end ; ++it ) { + if ( !NOMAD::atoi ( *it , i ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP" ); + var_indexes.insert(i); + } + } + + set_VARIABLE_GROUP ( var_indexes , + _direction_types , + _sec_poll_dir_types ); + + var_indexes.clear(); + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*------------------------------------------------------*/ @@ -421,180 +430,180 @@ void NOMAD::Parameters::interpret_var_groups ( const NOMAD::Parameter_Entries & /* (private) */ /*------------------------------------------------------*/ void NOMAD::Parameters::interpret_BFVS ( const NOMAD::Parameter_Entries & entries , - const std::string & param_name ) -{ - // param_name == LOWER_BOUND or UPPER_BOUND or FIXED_VARIABLE: - if ( param_name != "LOWER_BOUND" && - param_name != "UPPER_BOUND" && - param_name != "FIXED_VARIABLE" && - param_name != "SCALING" ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "wrong use of Parameters::interpret_BFVS()" ); - - NOMAD::Parameter_Entry * pe = entries.find ( param_name ); - std::list<std::string>::const_iterator it; - int i, j, k; - NOMAD::Double v; - std::string err; - std::string file_name; - std::ifstream fin; - - while ( pe ) - { - - // file name or just one index: - if ( pe->get_nb_values() == 1 ) - { - - // special case for FIXED_VARIABLE without value - // (the value will be taken from x0, if unique): - if ( isdigit ( (*pe->get_values().begin())[0] ) || - *pe->get_values().begin() == "*" ) - { - - if ( param_name[0] != 'F' ) - { - err = "invalid parameter: " + param_name - + " - only one argument, which is not a file name"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - if ( _x0s.size() != 1 || !_x0_cache_file.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "FIXED_VARIABLE with only a variable index and no unique x0" ); - - if ( !NOMAD::string_to_index_range ( *pe->get_values().begin() , - i , - j , - &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE" ); - - for ( k = i ; k <= j ; ++k ) - set_FIXED_VARIABLE ( k , (*_x0s[0])[k] ); - } - - - // file name: - else { - - file_name = _problem_dir + *pe->get_values().begin(); - - fin.open ( file_name.c_str() ); - - if ( fin.fail() ) - { - err = "invalid parameter: " + param_name + - " - could not open file \'" + file_name + "\'"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - try { - switch ( param_name[0] ) { - case 'L': - _lb.reset ( _dimension ); - fin >> _lb; - break; - case 'U': - _ub.reset ( _dimension ); - fin >> _ub; - break; - case 'F': - _fixed_variables.reset ( _dimension ); - fin >> _fixed_variables; - break; - case 'S': - _scaling.reset ( _dimension ); - fin >> _scaling; - } - } - catch ( NOMAD::Point::Bad_Input & ) { - err = "invalid parameter: " + param_name + - " - could not read file \'" + file_name + "\'"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - fin.close(); - } - } - - // vector form: all values on one row: - else if ( pe->get_nb_values() == _dimension + 2 ) { - - if ( !pe->is_unique() ) { - err = "invalid parameter: " + param_name + - " - has been given in vector form with [] or () and is not unique"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - it = pe->get_values().begin(); - - if ( *it != "[" && *it != "(" ) { - err = "invalid parameter: " + param_name + - " - error in vector form with () or []"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - ++it; - for ( k = 0 ; k < _dimension ; ++k ) { - if ( !v.atof(*it) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - ++it; - switch ( param_name[0] ) { - case 'L': set_LOWER_BOUND ( k , v ); - break; - case 'U': set_UPPER_BOUND ( k , v ); - break; - case 'F': set_FIXED_VARIABLE ( k , v ); - break; - case 'S': set_SCALING ( k , v ); - } - } - - if ( *it != "]" && *it != ")" ) { - err = "invalid parameter: " + param_name + - " - error in vector form with () or []"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - } - - // indexed values: - else { - - if ( pe->get_nb_values() != 2 ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - ++it; - if ( !v.atof(*it) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - for ( k = j ; k >= i ; --k ) - switch (param_name[0]) { - case 'L': set_LOWER_BOUND ( k, v ); - break; - case 'U': set_UPPER_BOUND ( k, v ); - break; - case 'F': set_FIXED_VARIABLE ( k, v ); - break; - case 'S': set_SCALING ( k, v ); - } - } - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + const std::string & param_name ) +{ + // param_name == LOWER_BOUND or UPPER_BOUND or FIXED_VARIABLE: + if ( param_name != "LOWER_BOUND" && + param_name != "UPPER_BOUND" && + param_name != "FIXED_VARIABLE" && + param_name != "SCALING" ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "wrong use of Parameters::interpret_BFVS()" ); + + NOMAD::Parameter_Entry * pe = entries.find ( param_name ); + std::list<std::string>::const_iterator it; + int i, j, k; + NOMAD::Double v; + std::string err; + std::string file_name; + std::ifstream fin; + + while ( pe ) + { + + // file name or just one index: + if ( pe->get_nb_values() == 1 ) + { + + // special case for FIXED_VARIABLE without value + // (the value will be taken from x0, if unique): + if ( isdigit ( (*pe->get_values().begin())[0] ) || + *pe->get_values().begin() == "*" ) + { + + if ( param_name[0] != 'F' ) + { + err = "invalid parameter: " + param_name + + " - only one argument, which is not a file name"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + if ( _x0s.size() != 1 || !_x0_cache_file.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "FIXED_VARIABLE with only a variable index and no unique x0" ); + + if ( !NOMAD::string_to_index_range ( *pe->get_values().begin() , + i , + j , + &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE" ); + + for ( k = i ; k <= j ; ++k ) + set_FIXED_VARIABLE ( k , (*_x0s[0])[k] ); + } + + + // file name: + else { + + file_name = _problem_dir + *pe->get_values().begin(); + + fin.open ( file_name.c_str() ); + + if ( fin.fail() ) + { + err = "invalid parameter: " + param_name + + " - could not open file \'" + file_name + "\'"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + try { + switch ( param_name[0] ) { + case 'L': + _lb.reset ( _dimension ); + fin >> _lb; + break; + case 'U': + _ub.reset ( _dimension ); + fin >> _ub; + break; + case 'F': + _fixed_variables.reset ( _dimension ); + fin >> _fixed_variables; + break; + case 'S': + _scaling.reset ( _dimension ); + fin >> _scaling; + } + } + catch ( NOMAD::Point::Bad_Input & ) { + err = "invalid parameter: " + param_name + + " - could not read file \'" + file_name + "\'"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + fin.close(); + } + } + + // vector form: all values on one row: + else if ( pe->get_nb_values() == _dimension + 2 ) { + + if ( !pe->is_unique() ) { + err = "invalid parameter: " + param_name + + " - has been given in vector form with [] or () and is not unique"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + it = pe->get_values().begin(); + + if ( *it != "[" && *it != "(" ) { + err = "invalid parameter: " + param_name + + " - error in vector form with () or []"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + ++it; + for ( k = 0 ; k < _dimension ; ++k ) { + if ( !v.atof(*it) ) { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + ++it; + switch ( param_name[0] ) { + case 'L': set_LOWER_BOUND ( k , v ); + break; + case 'U': set_UPPER_BOUND ( k , v ); + break; + case 'F': set_FIXED_VARIABLE ( k , v ); + break; + case 'S': set_SCALING ( k , v ); + } + } + + if ( *it != "]" && *it != ")" ) { + err = "invalid parameter: " + param_name + + " - error in vector form with () or []"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + } + + // indexed values: + else { + + if ( pe->get_nb_values() != 2 ) { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + ++it; + if ( !v.atof(*it) ) { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + for ( k = j ; k >= i ; --k ) + switch (param_name[0]) { + case 'L': set_LOWER_BOUND ( k, v ); + break; + case 'U': set_UPPER_BOUND ( k, v ); + break; + case 'F': set_FIXED_VARIABLE ( k, v ); + break; + case 'S': set_SCALING ( k, v ); + } + } + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*----------------------------------------------------------------*/ @@ -602,64 +611,64 @@ void NOMAD::Parameters::interpret_BFVS ( const NOMAD::Parameter_Entries & entrie /*----------------------------------------------------------------*/ void NOMAD::Parameters::interpret_f_target ( const NOMAD::Parameter_Entries & entries ) { - NOMAD::Double d; - std::list<std::string>::const_iterator it; - NOMAD::Parameter_Entry * pe = entries.find ( "F_TARGET" ); - - if ( pe ) - { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET not unique" ); - - it = pe->get_values().begin(); - - int nb_values = pe->get_nb_values(); - - // just one value: single-objective optimization: - if ( nb_values == 1 ) - { - - if ( !d.atof ( *it ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET" ); - set_F_TARGET (d); - } - - // vector form: multi-objective optimization: - else - { - - nb_values -= 2; - - NOMAD::Point f_target ( nb_values ); - - if ( *it != "[" && *it != "(" ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET - error in vector form with () or []" ); - - ++it; - - for ( int k = 0 ; k < nb_values ; ++k ) - { - - if ( !d.atof ( *it ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET" ); - ++it; - - f_target[k] = d; - } - - if ( *it != "]" && *it != ")" ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET - error in vector form with () or []" ); - - set_F_TARGET ( f_target ); - } - pe->set_has_been_interpreted(); - } + NOMAD::Double d; + std::list<std::string>::const_iterator it; + NOMAD::Parameter_Entry * pe = entries.find ( "F_TARGET" ); + + if ( pe ) + { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET not unique" ); + + it = pe->get_values().begin(); + + int nb_values = pe->get_nb_values(); + + // just one value: single-objective optimization: + if ( nb_values == 1 ) + { + + if ( !d.atof ( *it ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET" ); + set_F_TARGET (d); + } + + // vector form: multi-objective optimization: + else + { + + nb_values -= 2; + + NOMAD::Point f_target ( nb_values ); + + if ( *it != "[" && *it != "(" ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET - error in vector form with () or []" ); + + ++it; + + for ( int k = 0 ; k < nb_values ; ++k ) + { + + if ( !d.atof ( *it ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET" ); + ++it; + + f_target[k] = d; + } + + if ( *it != "]" && *it != ")" ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET - error in vector form with () or []" ); + + set_F_TARGET ( f_target ); + } + pe->set_has_been_interpreted(); + } } /*-------------------------------------------------------------*/ @@ -670,116 +679,137 @@ void NOMAD::Parameters::interpret_mesh_sizes ( const NOMAD::Parameter_Entries & entries , const std::string & param_name ) { - // param_name == "INITIAL_MESH_SIZE" or "MIN_MESH_SIZE" or "MIN_POLL_SIZE": - if ( param_name != "INITIAL_MESH_SIZE" && - param_name != "MIN_MESH_SIZE" && - param_name != "MIN_POLL_SIZE" ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "wrong use of Parameters::interpret_mesh_sizes()" ); - - int i , j , k; - NOMAD::Double v; - bool relative; - std::string err; - std::list<std::string>::const_iterator it; - NOMAD::Parameter_Entry * pe = entries.find ( param_name ); - - while ( pe ) { - - // just one value: - if ( pe->get_nb_values() == 1 ) { - - if ( !pe->is_unique() ) { - err = "invalid parameter: " + param_name - + " - has been given with just one value and is not unique"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - if ( !v.relative_atof ( *pe->get_values().begin() , relative ) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - if ( param_name[0] == 'I' ) - set_INITIAL_MESH_SIZE ( v , relative ); - else if ( param_name[4] == 'M' ) - set_MIN_MESH_SIZE ( v , relative ); - else - set_MIN_POLL_SIZE ( v , relative ); - } - - // indexed form: - else if ( pe->get_nb_values() == 2 ) { - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - ++it; - - if ( !v.relative_atof( *it , relative ) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - for ( k = i ; k <= j ; ++k ) { - if ( param_name[0] == 'I' ) - set_INITIAL_MESH_SIZE ( k , v , relative ); - else if ( param_name[4] == 'M' ) - set_MIN_MESH_SIZE ( k , v , relative ); - else - set_MIN_POLL_SIZE ( k , v , relative ); - } - } - - // vector form: all values on one row: - else if ( pe->get_nb_values() == _dimension + 2 ) { - - if ( !pe->is_unique() ) { - err = "invalid parameter: " + param_name - + " - has been given in vector form with [] or () and is not unique"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - it = pe->get_values().begin(); - - if ( *it != "[" && *it != "(" ) { - err = "invalid parameter: " + param_name + - " - error in vector form with () or []"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - ++it; - for ( k = 0 ; k < _dimension ; ++k ) { - if ( !v.relative_atof ( *it , relative ) ) { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - ++it; - if ( param_name[0] == 'I' ) - set_INITIAL_MESH_SIZE ( k , v , relative ); - else if ( param_name[4] == 'M' ) - set_MIN_MESH_SIZE ( k , v , relative ); - else - set_MIN_POLL_SIZE ( k , v , relative ); - } - - if ( *it != "]" && *it != ")" ) { - err = "invalid parameter: " + param_name + - " - error in vector form with () or []"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - } - - else { - err = "invalid parameter: " + param_name; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + // param_name == "INITIAL_MESH_SIZE" or "INITIAL_MESH_SIZE" or "MIN_MESH_SIZE" or "MIN_POLL_SIZE": + if ( param_name != "INITIAL_POLL_SIZE" && + param_name != "INITIAL_MESH_SIZE" && + param_name != "MIN_MESH_SIZE" && + param_name != "MIN_POLL_SIZE" ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "wrong use of Parameters::interpret_mesh_sizes()" ); + + int i , j , k; + NOMAD::Double v; + bool relative; + std::string err; + std::list<std::string>::const_iterator it; + NOMAD::Parameter_Entry * pe = entries.find ( param_name ); + + while ( pe ) + { + + // just one value: + if ( pe->get_nb_values() == 1 ) + { + + if ( !pe->is_unique() ) + { + err = "invalid parameter: " + param_name + + " - has been given with just one value and is not unique"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + if ( !v.relative_atof ( *pe->get_values().begin() , relative ) ) + { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + if ( param_name[0] == 'I' && param_name[8] =='M') + set_INITIAL_MESH_SIZE ( v , relative ); + else if ( param_name[0] == 'I' && param_name[8] =='P') + set_INITIAL_POLL_SIZE ( v , relative ); + else if ( param_name[4] == 'M' ) + set_MIN_MESH_SIZE ( v , relative ); + else + set_MIN_POLL_SIZE ( v , relative ); + } + + // indexed form: + else if ( pe->get_nb_values() == 2 ) + { + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + ++it; + + if ( !v.relative_atof( *it , relative ) ) + { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + for ( k = i ; k <= j ; ++k ) + { + if ( param_name[0] == 'I' && param_name[8] =='M') + set_INITIAL_MESH_SIZE ( k , v , relative ); + else if ( param_name[0] == 'I' && param_name[8] =='P') + set_INITIAL_POLL_SIZE ( k , v , relative ); + else if ( param_name[4] == 'M' ) + set_MIN_MESH_SIZE ( k , v , relative ); + else + set_MIN_POLL_SIZE ( k , v , relative ); + } + } + + // vector form: all values on one row: + else if ( pe->get_nb_values() == _dimension + 2 ) + { + + if ( !pe->is_unique() ) { + err = "invalid parameter: " + param_name + + " - has been given in vector form with [] or () and is not unique"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + it = pe->get_values().begin(); + + if ( *it != "[" && *it != "(" ) + { + err = "invalid parameter: " + param_name + + " - error in vector form with () or []"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + ++it; + for ( k = 0 ; k < _dimension ; ++k ) + { + if ( !v.relative_atof ( *it , relative ) ) + { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + ++it; + if ( param_name[0] == 'I' && param_name[8] =='M' ) + set_INITIAL_MESH_SIZE ( k , v , relative ); + if ( param_name[0] == 'I' && param_name[8] =='P' ) + set_INITIAL_POLL_SIZE ( k , v , relative ); + else if ( param_name[4] == 'M' ) + set_MIN_MESH_SIZE ( k , v , relative ); + else + set_MIN_POLL_SIZE ( k , v , relative ); + } + + if ( *it != "]" && *it != ")" ) + { + err = "invalid parameter: " + param_name + + " - error in vector form with () or []"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + } + + else + { + err = "invalid parameter: " + param_name; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*---------------------------------------------------------------------------------*/ @@ -793,64 +823,64 @@ void NOMAD::Parameters::interpret_mesh_sizes void NOMAD::Parameters::interpret_bb_input_type ( const NOMAD::Parameter_Entries & entries ) { - int i , j , k; - NOMAD::bb_input_type bbit; - std::list<std::string>::const_iterator it; - NOMAD::Parameter_Entry * pe = entries.find ( "BB_INPUT_TYPE" ); - - while ( pe ) { - - // indexed form: - if ( pe->get_nb_values() == 2 ) { - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - ++it; - if ( !NOMAD::string_to_bb_input_type ( *it , bbit ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - - for ( k = i ; k <= j ; ++k ) - set_BB_INPUT_TYPE ( k , bbit ); - } - - // vector form: all values on one row: - else if ( pe->get_nb_values() == _dimension + 2 ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - std::string ( "invalid parameter: BB_INPUT_TYPE " ) - + " - has been given in vector form with [] or () and is not unique" ); - - it = pe->get_values().begin(); - - if ( *it != "[" && *it != "(" ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE - error in vector form with () or []" ); - - ++it; - for ( k = 0 ; k < _dimension ; ++k ) { - if ( !NOMAD::string_to_bb_input_type ( *it , bbit ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - ++it; - set_BB_INPUT_TYPE ( k , bbit ); - } - - if ( *it != "]" && *it != ")" ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE - error in vector form with () ot []" ); - } - - else - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + int i , j , k; + NOMAD::bb_input_type bbit; + std::list<std::string>::const_iterator it; + NOMAD::Parameter_Entry * pe = entries.find ( "BB_INPUT_TYPE" ); + + while ( pe ) { + + // indexed form: + if ( pe->get_nb_values() == 2 ) { + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + ++it; + if ( !NOMAD::string_to_bb_input_type ( *it , bbit ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + + for ( k = i ; k <= j ; ++k ) + set_BB_INPUT_TYPE ( k , bbit ); + } + + // vector form: all values on one row: + else if ( pe->get_nb_values() == _dimension + 2 ) { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + std::string ( "invalid parameter: BB_INPUT_TYPE " ) + + " - has been given in vector form with [] or () and is not unique" ); + + it = pe->get_values().begin(); + + if ( *it != "[" && *it != "(" ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE - error in vector form with () or []" ); + + ++it; + for ( k = 0 ; k < _dimension ; ++k ) { + if ( !NOMAD::string_to_bb_input_type ( *it , bbit ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + ++it; + set_BB_INPUT_TYPE ( k , bbit ); + } + + if ( *it != "]" && *it != ")" ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE - error in vector form with () ot []" ); + } + + else + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*------------------------------------------------*/ @@ -859,153 +889,153 @@ void NOMAD::Parameters::interpret_bb_input_type /*------------------------------------------------*/ void NOMAD::Parameters::interpret_x0 ( const NOMAD::Parameter_Entries & entries ) { - NOMAD::Parameter_Entry * pe = entries.find ( "X0" ); - std::list<std::string>::const_iterator it; - int i , j , k , l; - NOMAD::Double v; - NOMAD::Point tmp_x0; - std::vector<int> indexes; - - while ( pe ) { - - tmp_x0.reset ( _dimension ); - - // File name: - if ( pe->get_nb_values() == 1 ) - set_X0 ( *pe->get_values().begin() ); - - // Vector form: all values on one row: - else if ( pe->get_nb_values() == _dimension + 2 ) { - - it = pe->get_values().begin(); - - if ( *it != "[" && *it != "(" ) { - - // particular case with n=1 and 3 entry values: - // example: X0 1 0 4.0 (first coordinate of the 2nd x0 point put to 4.0) - if ( _dimension == 1 ) { - - it = pe->get_values().begin(); - - if ( !NOMAD::atoi ( *it , l ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - - i = static_cast<int> ( indexes.size() ); - if ( l > i ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - else if ( l == i ) { - l = static_cast<int> ( _x0s.size() ); - indexes.push_back ( l ); - set_X0 ( tmp_x0 ); - } - else - l = indexes[l]; - - ++it; - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - - if ( i != 0 && j != 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - - ++it; - if ( !v.atof(*it) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - - (*_x0s[l])[0] = v; - } - - else - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0 - error in vector form with () or []" ); - } - - else { - - ++it; - for ( k = 0 ; k < _dimension ; ++k ) { - if ( !v.atof(*it) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0" ); - ++it; - tmp_x0[k] = v; - } - - if ( *it != "]" && *it != ")" ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: X0 - error in vector form with () or []" ); - - set_X0 ( tmp_x0 ); - } - } - - // indexed values without x0 index (must be unique) - // (example: X0 0-5 1.0): - else if ( pe->get_nb_values() == 2 ) { - - it = pe->get_values().begin(); - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - ++it; - if ( !v.atof(*it) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - - if ( indexes.empty() ) { - l = static_cast<int> ( _x0s.size() ); - indexes.push_back ( l ); - set_X0 ( tmp_x0 ); - } - else - l = indexes[0]; - - for ( k = j ; k >= i ; --k ) - (*_x0s[l])[k] = v; - } - - // indexed values with x0 index - // example: X0 0 0-5 1.0 --> first x0 point - // X0 1 0-5 2.0 --> 2nd x0 point - else { - - if ( pe->get_nb_values() != 3 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - - it = pe->get_values().begin(); - - if ( !NOMAD::atoi ( *it , l ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - - i = static_cast<int> ( indexes.size() ); - if ( l > i ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - else if ( l == i ) { - l = static_cast<int> ( _x0s.size() ); - indexes.push_back ( l ); - set_X0 ( tmp_x0 ); - } - else - l = indexes[l]; - - ++it; - if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - - ++it; - if ( !v.atof(*it) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); - - for ( k = j ; k >= i ; --k ) - (*_x0s[l])[k] = v; - - } - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } + NOMAD::Parameter_Entry * pe = entries.find ( "X0" ); + std::list<std::string>::const_iterator it; + int i , j , k , l; + NOMAD::Double v; + NOMAD::Point tmp_x0; + std::vector<int> indexes; + + while ( pe ) { + + tmp_x0.reset ( _dimension ); + + // File name: + if ( pe->get_nb_values() == 1 ) + set_X0 ( *pe->get_values().begin() ); + + // Vector form: all values on one row: + else if ( pe->get_nb_values() == _dimension + 2 ) { + + it = pe->get_values().begin(); + + if ( *it != "[" && *it != "(" ) { + + // particular case with n=1 and 3 entry values: + // example: X0 1 0 4.0 (first coordinate of the 2nd x0 point put to 4.0) + if ( _dimension == 1 ) { + + it = pe->get_values().begin(); + + if ( !NOMAD::atoi ( *it , l ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + + i = static_cast<int> ( indexes.size() ); + if ( l > i ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + else if ( l == i ) { + l = static_cast<int> ( _x0s.size() ); + indexes.push_back ( l ); + set_X0 ( tmp_x0 ); + } + else + l = indexes[l]; + + ++it; + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + + if ( i != 0 && j != 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + + ++it; + if ( !v.atof(*it) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + + (*_x0s[l])[0] = v; + } + + else + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0 - error in vector form with () or []" ); + } + + else { + + ++it; + for ( k = 0 ; k < _dimension ; ++k ) { + if ( !v.atof(*it) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0" ); + ++it; + tmp_x0[k] = v; + } + + if ( *it != "]" && *it != ")" ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: X0 - error in vector form with () or []" ); + + set_X0 ( tmp_x0 ); + } + } + + // indexed values without x0 index (must be unique) + // (example: X0 0-5 1.0): + else if ( pe->get_nb_values() == 2 ) { + + it = pe->get_values().begin(); + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + ++it; + if ( !v.atof(*it) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + + if ( indexes.empty() ) { + l = static_cast<int> ( _x0s.size() ); + indexes.push_back ( l ); + set_X0 ( tmp_x0 ); + } + else + l = indexes[0]; + + for ( k = j ; k >= i ; --k ) + (*_x0s[l])[k] = v; + } + + // indexed values with x0 index + // example: X0 0 0-5 1.0 --> first x0 point + // X0 1 0-5 2.0 --> 2nd x0 point + else { + + if ( pe->get_nb_values() != 3 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + + it = pe->get_values().begin(); + + if ( !NOMAD::atoi ( *it , l ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + + i = static_cast<int> ( indexes.size() ); + if ( l > i ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + else if ( l == i ) { + l = static_cast<int> ( _x0s.size() ); + indexes.push_back ( l ); + set_X0 ( tmp_x0 ); + } + else + l = indexes[l]; + + ++it; + if ( !NOMAD::string_to_index_range ( *it , i , j , &_dimension ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + + ++it; + if ( !v.atof(*it) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: X0" ); + + for ( k = j ; k >= i ; --k ) + (*_x0s[l])[k] = v; + + } + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } } /*----------------------------------------*/ @@ -1013,77 +1043,77 @@ void NOMAD::Parameters::interpret_x0 ( const NOMAD::Parameter_Entries & entries /*----------------------------------------*/ void NOMAD::Parameters::read ( const std::string & param_file ) { - // parameters will have to be checked: - _to_be_checked = true; - - // PROBLEM_DIR: - // ------------ - _problem_dir.clear(); - size_t k = param_file.find_last_of ( NOMAD::DIR_SEP ); - if ( k >= 0 && k < param_file.size() ) - _problem_dir = param_file.substr (0,k) + NOMAD::DIR_SEP; - else - _problem_dir = std::string(".") + NOMAD::DIR_SEP; - - // open the parameters file: - std::string err = "could not open parameters file \'" + param_file + "\'"; - std::ifstream fin; - if ( NOMAD::check_read_file ( param_file ) ) { - fin.open ( param_file.c_str() ); - if ( !fin.fail() ) - err.clear(); - } - if ( !err.empty() ) { - fin.close(); - throw NOMAD::Exception ( "Parameters.cpp" , __LINE__ , err ); - } - - // the set of entries: - NOMAD::Parameter_Entries entries; - - // the file is read: fill the set 'entries' of Parameter_Entry: - NOMAD::Parameter_Entry * pe; - std::string s; - - while ( fin.good() && !fin.eof() ) - { - - s.clear(); - - getline ( fin , s ); - - if ( !fin.fail() && !s.empty() ) - { - pe = new NOMAD::Parameter_Entry ( s ); - if ( pe->is_ok() ) - entries.insert ( pe ); // pe will be deleted by ~Parameter_Entries() - else - { - if ( ( pe->get_name() != "" && pe->get_nb_values() == 0 ) || - pe->get_name() == "STATS_FILE" ) - { - err = "invalid parameter: " + pe->get_name(); - delete pe; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - delete pe; - } - } - } - - // the file is closed: - fin.close(); - - // entries display: + // parameters will have to be checked: + _to_be_checked = true; + + // PROBLEM_DIR: + // ------------ + _problem_dir.clear(); + size_t k = param_file.find_last_of ( NOMAD::DIR_SEP ); + if ( k < param_file.size() ) + _problem_dir = param_file.substr (0,k) + NOMAD::DIR_SEP; + else + _problem_dir = std::string(".") + NOMAD::DIR_SEP; + + // open the parameters file: + std::string err = "could not open parameters file \'" + param_file + "\'"; + std::ifstream fin; + if ( NOMAD::check_read_file ( param_file ) ) { + fin.open ( param_file.c_str() ); + if ( !fin.fail() ) + err.clear(); + } + if ( !err.empty() ) { + fin.close(); + throw NOMAD::Exception ( "Parameters.cpp" , __LINE__ , err ); + } + + // the set of entries: + NOMAD::Parameter_Entries entries; + + // the file is read: fill the set 'entries' of Parameter_Entry: + NOMAD::Parameter_Entry * pe; + std::string s; + + while ( fin.good() && !fin.eof() ) + { + + s.clear(); + + getline ( fin , s ); + + if ( !fin.fail() && !s.empty() ) + { + pe = new NOMAD::Parameter_Entry ( s ); + if ( pe->is_ok() ) + entries.insert ( pe ); // pe will be deleted by ~Parameter_Entries() + else + { + if ( ( pe->get_name() != "" && pe->get_nb_values() == 0 ) || + pe->get_name() == "STATS_FILE" ) + { + err = "invalid parameter: " + pe->get_name(); + delete pe; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + delete pe; + } + } + } + + // the file is closed: + fin.close(); + + // entries display: #ifdef DEBUG - if ( NOMAD::Slave::is_master() ) - _out << std::endl - << NOMAD::open_block ( "parsing of \'" + param_file + "\'" ) - << entries - << NOMAD::close_block(); + if ( NOMAD::Slave::is_master() ) + _out << std::endl + << NOMAD::open_block ( "parsing of \'" + param_file + "\'" ) + << entries + << NOMAD::close_block(); #endif - - read(entries); + + read(entries); } /*----------------------------------------*/ @@ -1091,1705 +1121,1760 @@ void NOMAD::Parameters::read ( const std::string & param_file ) /*----------------------------------------*/ void NOMAD::Parameters::read ( const NOMAD::Parameter_Entries & entries ) { - - // interpret and set the entries using SET methods: - std::list<std::string>::const_iterator it , end; - int i , j , m; - NOMAD::Double d; - NOMAD::Parameter_Entry * pe; - std::string s; - std::string err ; - - /*----------------------------------------------*/ - - // EPSILON: - // -------- - { - pe = entries.find ( "EPSILON" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EPSILON not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EPSILON" ); - set_EPSILON (d); - pe->set_has_been_interpreted(); - } - } - - // UNDEF_STR: - // ---------- - pe = entries.find ( "UNDEF_STR" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: UNDEF_STR not unique" ); - set_UNDEF_STR ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - - // INF_STR: - // -------- - pe = entries.find ( "INF_STR" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INF_STR not unique" ); - set_INF_STR ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - - // MESH_UPDATE_BASIS: - // ------------------ - { - pe = entries.find ( "MESH_UPDATE_BASIS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_UPDATE_BASIS not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_UPDATE_BASIS" ); - set_MESH_UPDATE_BASIS (d); - pe->set_has_been_interpreted(); - } - } - - // INITIAL_MESH_INDEX: - // ------------------- - { - pe = entries.find ( "INITIAL_MESH_INDEX" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_INDEX not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_INDEX" ); - pe->set_has_been_interpreted(); - set_INITIAL_MESH_INDEX (i); - } - } - - // MESH_REFINING_EXPONENT: - // ----------------------- - { - pe = entries.find ( "MESH_REFINING_EXPONENT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_REFINING_EXPONENT not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_REFINING_EXPONENT" ); - pe->set_has_been_interpreted(); - set_MESH_REFINING_EXPONENT (i); - } - } - - // MESH_COARSENING_EXPONENT: - // ------------------------- - { - pe = entries.find ( "MESH_COARSENING_EXPONENT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_COARSENING_EXPONENT not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_COARSENING_EXPONENT" ); - pe->set_has_been_interpreted(); - set_MESH_COARSENING_EXPONENT (i); - } - } - - // MAX_MESH_INDEX: - // --------------- - { - pe = entries.find ( "MAX_MESH_INDEX" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_MESH_INDEX not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_MESH_INDEX" ); - pe->set_has_been_interpreted(); - set_MAX_MESH_INDEX (i); - } - } - - // HALTON_SEED: - // ------------ - { - pe = entries.find ( "HALTON_SEED" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HALTON_SEED not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HALTON_SEED" ); - pe->set_has_been_interpreted(); - set_HALTON_SEED (i); - } - } - - // POINT_DISPLAY_LIMIT: - // -------------------- - { - pe = entries.find ( "POINT_DISPLAY_LIMIT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: POINT_DISPLAY_LIMIT not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: POINT_DISPLAY_LIMIT" ); - set_POINT_DISPLAY_LIMIT (i); - pe->set_has_been_interpreted(); - } - } - - // DIMENSION: - // ---------- - { - pe = entries.find ( "DIMENSION" ); - - if ( !pe ) { - if ( !pe && _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION not defined" ); - } - else { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION not unique" ); - - int dim; - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), dim) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION" ); - - pe->set_has_been_interpreted(); - - set_DIMENSION ( dim ); - } - } - - // SNAP_TO_BOUNDS: - // --------------- - { - pe = entries.find ( "SNAP_TO_BOUNDS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SNAP_TO_BOUNDS not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SNAP_TO_BOUNDS" ); - set_SNAP_TO_BOUNDS ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // MULTI-MADS: - // ----------- - { - // MULTI_OVERALL_BB_EVAL: - pe = entries.find ( "MULTI_OVERALL_BB_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_OVERALL_BB_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_OVERALL_BB_EVAL" ); - pe->set_has_been_interpreted(); - set_MULTI_OVERALL_BB_EVAL (i); - } - - // MULTI_NB_MADS_RUNS: - pe = entries.find ( "MULTI_NB_MADS_RUNS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_NB_MADS_RUNS not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_NB_MADS_RUNS" ); - pe->set_has_been_interpreted(); - set_MULTI_NB_MADS_RUNS (i); - } - - // MULTI_USE_DELTA_CRIT: - pe = entries.find ( "MULTI_USE_DELTA_CRIT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_USE_DELTA_CRIT not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_USE_DELTA_CRIT" ); - pe->set_has_been_interpreted(); - set_MULTI_USE_DELTA_CRIT ( i == 1 ); - } - - // MULTI_F_BOUNDS (f1_min, f2_min, f2_min, f2_max): - pe = entries.find ( "MULTI_F_BOUNDS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_F_BOUNDS not unique" ); - if ( pe->get_nb_values() != 4 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_F_BOUNDS" ); - NOMAD::Point mfb ( 4 ); - it = pe->get_values().begin(); - for ( i = 0 ; i < 4 ; ++i ) { - if ( !d.atof ( *it ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_F_BOUNDS" ); - mfb[i] = d; - ++it; - } - pe->set_has_been_interpreted(); - set_MULTI_F_BOUNDS ( mfb ); - } - - // MULTI_FORMULATION: - // ------------------ - { - pe = entries.find ( "MULTI_FORMULATION" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_FORMULATION not unique" ); - NOMAD::multi_formulation_type mft; - if ( pe->get_nb_values() != 1 || - !NOMAD::string_to_multi_formulation_type - ( *(pe->get_values().begin()) , mft ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Invalid parameter: MULTI_FORMULATION_TYPE" ); - pe->set_has_been_interpreted(); - set_MULTI_FORMULATION ( mft ); - } - } - } - - // Models - // -------------- - { - - - // Disable models when explicitely requested - pe = entries.find ( "DISABLE" ); - while ( pe ) - { - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISABLE" ); - - std::string smt = *(pe->get_values().begin()); - NOMAD::toupper(smt); - if ( smt == "MODELS" ) - { - set_DISABLE_MODELS(); - } - else { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Invalid parameter: DISABLE MODELS. Only MODELS argument is accepted!" ); - - } - - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } - - - - // MODEL_SEARCH (can be entered one time or twice): - int i_model_search = 1; - bool b_model_search = false; - pe = entries.find ( "MODEL_SEARCH" ); - - while ( pe ) { - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH" ); - if ( i_model_search == 3 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH (cannot be entered more than twice" ); - - NOMAD::model_type mt; - std::string smt = *(pe->get_values().begin()); - int imt = NOMAD::string_to_bool ( smt ); - - // entered as a boolean: - if ( imt == 0 || imt == 1 ) { - if ( b_model_search || i_model_search == 2 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH (boolean argument can only be used once)" ); - b_model_search = true; - set_MODEL_SEARCH ( imt == 1 ); - } - - // entered as a model type: - else { - - if ( !NOMAD::string_to_model_type ( smt , mt ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT" ); - - set_MODEL_SEARCH ( i_model_search , mt ); - } - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - ++i_model_search; - } - - // MODEL_SEARCH_OPTIMISTIC: - { - pe = entries.find ( "MODEL_SEARCH_OPTIMISTIC" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_OPTIMISTIC not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_OPTIMISTIC" ); - set_MODEL_SEARCH_OPTIMISTIC ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // MODEL_SEARCH_PROJ_TO_MESH: - { - pe = entries.find ( "MODEL_SEARCH_PROJ_TO_MESH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_PROJ_TO_MESH not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_PROJ_TO_MESH" ); - set_MODEL_SEARCH_PROJ_TO_MESH ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // MODEL_QUAD_RADIUS_FACTOR: - { - pe = entries.find ( "MODEL_QUAD_RADIUS_FACTOR" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_RADIUS_FACTOR not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_RADIUS_FACTOR" ); - pe->set_has_been_interpreted(); - set_MODEL_QUAD_RADIUS_FACTOR ( d ); - } - } - - // MODEL_QUAD_USE_WP: - { - pe = entries.find ( "MODEL_QUAD_USE_WP" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_USE_WP not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_USE_WP" ); - set_MODEL_QUAD_USE_WP ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // MODEL_QUAD_MAX_Y_SIZE: - { - pe = entries.find ( "MODEL_QUAD_MAX_Y_SIZE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MAX_Y_SIZE not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MAX_Y_SIZE" ); - pe->set_has_been_interpreted(); - set_MODEL_QUAD_MAX_Y_SIZE (i); - } - } - - // MODEL_QUAD_MIN_Y_SIZE: - { - pe = entries.find ( "MODEL_QUAD_MIN_Y_SIZE" ); - if ( pe ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MIN_Y_SIZE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MIN_Y_SIZE" ); - - s = *(pe->get_values().begin()); - NOMAD::toupper(s); - - if ( s == "N+1" ) - i = -1; - else if ( !NOMAD::atoi ( s , i ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MIN_Y_SIZE" ); - - pe->set_has_been_interpreted(); - set_MODEL_QUAD_MIN_Y_SIZE (i); - } - } - - - // MODEL_QUAD_HYPERCUBE_LOWER_LIM: - { - pe = entries.find ( "MODEL_NP1_QUAD_EPSILON" ); - if ( pe ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_NP1_QUAD_EPSILON not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_NP1_QUAD_EPSILON" ); - - s = *(pe->get_values().begin()); - NOMAD::toupper(s); - NOMAD::Double d; - if ( !d.atof ( s) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_NP1_QUAD_EPSILON" ); - - pe->set_has_been_interpreted(); - set_MODEL_NP1_QUAD_EPSILON (d); - } - } - - // MODEL_TGP_MODE: - { - pe = entries.find ( "MODEL_TGP_MODE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_TGP_MODE not unique" ); - - NOMAD::TGP_mode_type m; - if ( pe->get_nb_values() != 1 || - !NOMAD::string_to_TGP_mode_type ( *(pe->get_values().begin()) , m ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Invalid parameter: MODEL_TGP_MODE" ); - pe->set_has_been_interpreted(); - set_MODEL_TGP_MODE ( m ); - } - } - - // MODEL_TGP_REUSE_MODEL: - { - pe = entries.find ( "MODEL_TGP_REUSE_MODEL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_TGP_REUSE_MODEL not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_TGP_REUSE_MODEL" ); - set_MODEL_TGP_REUSE_MODEL ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // MODEL_SEARCH_MAX_TRIAL_PTS: - { - pe = entries.find ( "MODEL_SEARCH_MAX_TRIAL_PTS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS" ); - pe->set_has_been_interpreted(); - set_MODEL_SEARCH_MAX_TRIAL_PTS (i); - } - } - - // MODEL_EVAL_SORT: - { - pe = entries.find ( "MODEL_EVAL_SORT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT not unique" ); - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT" ); - - NOMAD::model_type mt; - std::string smt = *(pe->get_values().begin()); - int imt = NOMAD::string_to_bool ( smt ); - - // entered as a boolean: - if ( imt == 0 || imt == 1 ) - set_MODEL_EVAL_SORT ( imt == 1 ); - - // entered as a model type: - else { - - if ( !NOMAD::string_to_model_type ( smt , mt ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT" ); - set_MODEL_EVAL_SORT ( mt ); - } - - pe->set_has_been_interpreted(); - } - } - - // MODEL_EVAL_SORT_CAUTIOUS: - { - pe = entries.find ( "MODEL_EVAL_SORT_CAUTIOUS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT_CAUTIOUS not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT_CAUTIOUS" ); - set_MODEL_EVAL_SORT_CAUTIOUS ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - } - - // SPECULATIVE_SEARCH: - // ------------------- - { - pe = entries.find ( "SPECULATIVE_SEARCH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SPECULATIVE_SEARCH not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SPECULATIVE_SEARCH" ); - set_SPECULATIVE_SEARCH ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // VNS_SEARCH: - // ----------- - { - pe = entries.find ( "VNS_SEARCH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VNS_SEARCH not unique" ); - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VNS_SEARCH" ); - - s = *(pe->get_values().begin()); - i = NOMAD::string_to_bool ( s ); - - // entered as a real: - if ( i == -1 || s == "1" ) { - if ( !d.atof ( s ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VNS_SEARCH" ); - set_VNS_SEARCH ( d ); - } - // entered as a boolean: - else - set_VNS_SEARCH ( i == 1 ); - - pe->set_has_been_interpreted(); - } - } - - // CACHE_SEARCH: - // ------------- - { - pe = entries.find ( "CACHE_SEARCH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_SEARCH not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_SEARCH" ); - set_CACHE_SEARCH ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // LH_SEARCH: - // ---------- - { - pe = entries.find ( "LH_SEARCH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LH_SEARCH not unique" ); - if ( pe->get_nb_values() != 2 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LH_SEARCH" ); - it = pe->get_values().begin(); - - if ( !NOMAD::atoi (*it++ , i) || i < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LH_SEARCH" ); - - if ( !NOMAD::atoi (*it , j) || j < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LH_SEARCH" ); - - set_LH_SEARCH ( i , j ); - pe->set_has_been_interpreted(); - } - - // OPPORTUNISTIC_LH: - // ----------------- - { - pe = entries.find ( "OPPORTUNISTIC_LH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_LH not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_LH" ); - set_OPPORTUNISTIC_LH ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - } - - // OPPORTUNISTIC_CACHE_SEARCH: - // --------------------------- - { - pe = entries.find ( "OPPORTUNISTIC_CACHE_SEARCH" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_CACHE_SEARCH not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_CACHE_SEARCH" ); - set_OPPORTUNISTIC_CACHE_SEARCH ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // opportunistic strategy: - // ----------------------- - { - // OPPORTUNISTIC_EVAL: - pe = entries.find ( "OPPORTUNISTIC_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_EVAL not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_EVAL" ); - set_OPPORTUNISTIC_EVAL ( i == 1 ); - pe->set_has_been_interpreted(); - } - - // OPPORTUNISTIC_MIN_NB_SUCCESS: - pe = entries.find ( "OPPORTUNISTIC_MIN_NB_SUCCESS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_NB_SUCCESS not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_NB_SUCCESS" ); - pe->set_has_been_interpreted(); - set_OPPORTUNISTIC_MIN_NB_SUCCESS (i); - } - - // OPPORTUNISTIC_MIN_EVAL: - pe = entries.find ( "OPPORTUNISTIC_MIN_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_EVAL" ); - pe->set_has_been_interpreted(); - set_OPPORTUNISTIC_MIN_EVAL (i); - } - - // OPPORTUNISTIC_MIN_F_IMPRVMT: - pe = entries.find ( "OPPORTUNISTIC_MIN_F_IMPRVMT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_F_IMPRVMT not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_MIN_F_IMPRVMT" ); - pe->set_has_been_interpreted(); - set_OPPORTUNISTIC_MIN_F_IMPRVMT ( d ); - } - - // OPPORTUNISTIC_LUCKY_EVAL: - pe = entries.find ( "OPPORTUNISTIC_LUCKY_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_LUCKY_EVAL not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPPORTUNISTIC_LUCKY_EVAL" ); - set_OPPORTUNISTIC_LUCKY_EVAL ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // Directions (DIRECTION_TYPE and SEC_POLL_DIR_TYPE): - // -------------------------------------------------- - { - NOMAD::direction_type dt; - - - pe = entries.find ( "DIRECTION_TYPE" ); - while ( pe ) { - - if ( !NOMAD::strings_to_direction_type ( pe->get_values() , dt ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIRECTION_TYPE" ); - set_DIRECTION_TYPE ( dt ); - - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } - - pe = entries.find ( "SEC_POLL_DIR_TYPE" ); - while ( pe ) { - if ( !NOMAD::strings_to_direction_type ( pe->get_values() , dt ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SEC_POLL_DIR_TYPE" ); - set_SEC_POLL_DIR_TYPE ( dt ); - - pe->set_has_been_interpreted(); - pe = pe->get_next(); - } - } - - - // MAX_ITERATIONS: - // --------------- - { - pe = entries.find ( "MAX_ITERATIONS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_ITERATIONS not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_ITERATIONS" ); - pe->set_has_been_interpreted(); - set_MAX_ITERATIONS (i); - } - } - - // MAX_CONSECUTIVE_FAILED_ITERATIONS: - // ---------------------------------- - { - pe = entries.find ( "MAX_CONSECUTIVE_FAILED_ITERATIONS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_CONSECUTIVE_FAILED_ITERATIONS not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_CONSECUTIVE_FAILED_ITERATIONS" ); - pe->set_has_been_interpreted(); - set_MAX_CONSECUTIVE_FAILED_ITERATIONS (static_cast<int>(d.value())); - } - } - - // MAX_CACHE_MEMORY: - // ----------------- - { - pe = entries.find ( "MAX_CACHE_MEMORY" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_CACHE_MEMORY not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_CACHE_MEMORY" ); - pe->set_has_been_interpreted(); - set_MAX_CACHE_MEMORY (static_cast<float>(d.value())); - } - } - - // MAX_EVAL: - // --------- - { - pe = entries.find ( "MAX_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_EVAL" ); - pe->set_has_been_interpreted(); - set_MAX_EVAL (i); - } - } - - // MAX_BB_EVAL: - // ------------ - { - pe = entries.find ( "MAX_BB_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_BB_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_BB_EVAL" ); - pe->set_has_been_interpreted(); - set_MAX_BB_EVAL (i); - } - } - - // MAX_SIM_BB_EVAL: - // ---------------- - { - pe = entries.find ( "MAX_SIM_BB_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_SIM_BB_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_SIM_BB_EVAL" ); - pe->set_has_been_interpreted(); - set_MAX_SIM_BB_EVAL (i); - } - } - - // MAX_SGTE_EVAL: - // -------------- - { - pe = entries.find ( "MAX_SGTE_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_SGTE_EVAL not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_SGTE_EVAL" ); - pe->set_has_been_interpreted(); - set_MAX_SGTE_EVAL (i); - } - } - - // MAX_TIME: - // --------- - { - pe = entries.find ( "MAX_TIME" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_TIME not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MAX_TIME" ); - - pe->set_has_been_interpreted(); - set_MAX_TIME (i); - } - } - - // STAT_SUM_TARGET: - // ---------------- - { - pe = entries.find ( "STAT_SUM_TARGET" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STAT_SUM_TARGET not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STAT_SUM_TARGET" ); - pe->set_has_been_interpreted(); - set_STAT_SUM_TARGET ( d ); - } - } - - // L_CURVE_TARGET: - // --------------- - { - pe = entries.find ( "L_CURVE_TARGET" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: L_CURVE_TARGET not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: L_CURVE_TARGET" ); - pe->set_has_been_interpreted(); - set_L_CURVE_TARGET ( d ); - } - } - - // EXTENDED_POLL_TRIGGER: - // ---------------------- - { - pe = entries.find ( "EXTENDED_POLL_TRIGGER" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_TRIGGER not unique" ); - - bool rel; - - if ( pe->get_nb_values() != 1 || - !d.relative_atof ( *(pe->get_values().begin()) , rel ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_TRIGGER" ); - - pe->set_has_been_interpreted(); - set_EXTENDED_POLL_TRIGGER ( d , rel ); - } - } - - // EXTENDED_POLL_ENABLED: - // ---------------------- - { - pe = entries.find ( "EXTENDED_POLL_ENABLED" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_ENABLED not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_ENABLED" ); - set_EXTENDED_POLL_ENABLED ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // USER_CALLS_ENABLED: - // ------------------- - { - pe = entries.find ( "USER_CALLS_ENABLED" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: USER_CALLS_ENABLED not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: USER_CALLS_ENABLED" ); - set_USER_CALLS_ENABLED ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // ASYNCHRONOUS: - // ------------- - { - pe = entries.find ( "ASYNCHRONOUS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: ASYNCHRONOUS not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: ASYNCHRONOUS" ); - set_ASYNCHRONOUS ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // RHO: - // ---- - { - pe = entries.find ( "RHO" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: RHO not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: RHO" ); - pe->set_has_been_interpreted(); - set_RHO(d); - } - } - - // H_MIN: - // ------ - { - pe = entries.find ( "H_MIN" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: H_MIN not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: H_MIN" ); - pe->set_has_been_interpreted(); - set_H_MIN(d); - } - } - - // H_MAX_0: - // -------- - { - pe = entries.find ( "H_MAX_0" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: H_MAX_0 not unique" ); - if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Invalid parameter: H_MAX_0" ); - pe->set_has_been_interpreted(); - set_H_MAX_0(d); - } - } - - // H_NORM: - // ------- - { - pe = entries.find ( "H_NORM" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: H_NORM not unique" ); - NOMAD::hnorm_type hn = NOMAD::L2; - if ( pe->get_nb_values() != 1 || - !NOMAD::string_to_hnorm_type ( *(pe->get_values().begin()) , hn ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Invalid parameter: H_NORM" ); - pe->set_has_been_interpreted(); - set_H_NORM ( hn ); - } - } - - // TMP_DIR: - // -------- - { - _tmp_dir.clear(); - pe = entries.find ( "TMP_DIR" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: TMP_DIR not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: TMP_DIR" ); - - set_TMP_DIR ( *(pe->get_values().begin()) ); - - pe->set_has_been_interpreted(); - } - } - - // ADD_SEED_TO_FILE_NAMES: - // ----------------------- - { - pe = entries.find ( "ADD_SEED_TO_FILE_NAMES" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: ADD_SEED_TO_FILE_NAMES not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: ADD_SEED_TO_FILE_NAMES" ); - - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: ADD_SEED_TO_FILE_NAMES" ); - set_ADD_SEED_TO_FILE_NAMES ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // SOLUTION_FILE: - // -------------- - { - _solution_file.clear(); - pe = entries.find ( "SOLUTION_FILE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SOLUTION_FILE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SOLUTION_FILE" ); - set_SOLUTION_FILE ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - } - - // HISTORY_FILE: - // ------------- - { - _history_file.clear(); - pe = entries.find ( "HISTORY_FILE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HISTORY_FILE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HISTORY_FILE" ); - set_HISTORY_FILE ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - } - - // STATS_FILE: - // ----------- - { - pe = entries.find ( "STATS_FILE" ); - if ( pe ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STATS_FILE not unique" ); - - end = pe->get_values().end(); - it = pe->get_values().begin(); - std::string file_name = *it; - ++it; - - std::list<std::string> ls; - if (it!=end) - { - while ( it != end ) { - ls.push_back(*it); - ++it; - } - ls.resize(ls.size()-1); - } - - set_STATS_FILE ( file_name , ls ); - pe->set_has_been_interpreted(); - } - } - - // CACHE FILE: - // ----------- - { - _cache_file.clear(); - pe = entries.find ( "CACHE_FILE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_FILE not unique" ); - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_FILE" ); - set_CACHE_FILE ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - } - - // SGTE_CACHE FILE: - // ---------------- - { - _sgte_cache_file.clear(); - pe = entries.find ( "SGTE_CACHE_FILE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_CACHE_FILE not unique" ); - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_CACHE_FILE" ); - set_SGTE_CACHE_FILE ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - } - - - // CACHE_SAVE_PERIOD: - // ------------------ - { - pe = entries.find ( "CACHE_SAVE_PERIOD" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_SAVE_PERIOD not unique" ); - if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_SAVE_PERIOD" ); - set_CACHE_SAVE_PERIOD (i); - pe->set_has_been_interpreted(); - } - } - - // SGTE_COST: - // ---------- - { - pe = entries.find ( "SGTE_COST" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_COST not unique" ); - if ( pe->get_nb_values() != 1 || - !NOMAD::atoi (*(pe->get_values().begin()) , i) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_COST" ); - set_SGTE_COST (i); - pe->set_has_been_interpreted(); - } - } - - // X0: - // --- - interpret_x0 ( entries ); - - // FIXED_VARIABLE: - // --------------- - interpret_BFVS ( entries , "FIXED_VARIABLE"); - - // LOWER_BOUND: - // ------------ - interpret_BFVS ( entries , "LOWER_BOUND"); - - // UPPER_BOUND: - // ------------ - interpret_BFVS ( entries , "UPPER_BOUND"); - - // SCALING: - // -------- - interpret_BFVS ( entries , "SCALING" ); - - // BB_INPUT_TYPE: - // -------------- - interpret_bb_input_type ( entries ); - - // F_TARGET: - // --------- - interpret_f_target ( entries ); - - // STOP_IF_FEASIBLE: - // ----------------- - pe = entries.find ( "STOP_IF_FEASIBLE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STOP_IF_FEASIBLE not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STOP_IF_FEASIBLE" ); - pe->set_has_been_interpreted(); - set_STOP_IF_FEASIBLE ( i == 1 ); - } - - // BB_INPUT_INCLUDE_TAG: - // --------------------- - { - pe = entries.find ( "BB_INPUT_INCLUDE_TAG" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_INCLUDE_TAG not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_INCLUDE_TAG" ); - set_BB_INPUT_INCLUDE_TAG ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // BB_INPUT_INCLUDE_SEED: - // ---------------------- - { - pe = entries.find ( "BB_INPUT_INCLUDE_SEED" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_INCLUDE_SEED not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_INCLUDE_SEED" ); - set_BB_INPUT_INCLUDE_SEED ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - // BB_REDIRECTION: - // --------------- - { - pe = entries.find ( "BB_REDIRECTION" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_REDIRECTION not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_REDIRECTION" ); - set_BB_REDIRECTION ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // INITIAL_MESH_SIZE, MIN_MESH_SIZE, and MIN_POLL_SIZE: - // ---------------------------------------------------- - interpret_mesh_sizes ( entries , "INITIAL_MESH_SIZE" ); - interpret_mesh_sizes ( entries , "MIN_MESH_SIZE" ); - interpret_mesh_sizes ( entries , "MIN_POLL_SIZE" ); - - // BB_OUTPUT_TYPE: - // --------------- - { - pe = entries.find ( "BB_OUTPUT_TYPE" ); - - if ( !pe ) { - if ( _bb_output_type.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE not defined" ); - } - else { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE not unique" ); - - m = pe->get_nb_values(); - - if ( m <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE" ); - - NOMAD::bb_output_type cur; - std::list<NOMAD::bb_output_type> bbot; - i = 0; - end = pe->get_values().end(); - for ( it = pe->get_values().begin() ; it != end ; ++it ) { - if ( !NOMAD::string_to_bb_output_type ( *it , cur ) ) { - err = "invalid parameter: BB_OUTPUT_TYPE (" + pe->get_name(); - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - bbot.push_back (cur); - } - - set_BB_OUTPUT_TYPE ( bbot ); - - pe->set_has_been_interpreted(); - } - } - - // NEIGHBORS_EXE: - // -------------- - { - _neighbors_exe.clear(); - pe = entries.find ( "NEIGHBORS_EXE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: NEIGHBORS_EXE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: NEIGHBORS_EXE" ); - set_NEIGHBORS_EXE ( *(pe->get_values().begin()) ); - pe->set_has_been_interpreted(); - } - } - - // BB_EXE: - // ------- - { - pe = entries.find ( "BB_EXE" ); - if ( pe ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE not unique" ); - - m = pe->get_nb_values(); - - if ( m == 1 ) - set_BB_EXE ( *pe->get_values().begin() ); - - else { - - if ( m != static_cast<int>(_bb_output_type.size()) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: number of BB_EXE (>1) and corresponding BB_OUTPUT_TYPE must be the same." ); - - std::list<std::string> bbexe; - end = pe->get_values().end(); - for ( it = pe->get_values().begin() ; it != end ; ++it ) - bbexe.push_back (*it); - - set_BB_EXE ( bbexe ); - } - - pe->set_has_been_interpreted(); - } - } - - // SGTE_EXE: - // --------- - { - pe = entries.find ( "SGTE_EXE" ); - if ( pe ) { - - std::string bb_exe_name , sgte_name; - - if ( pe->get_nb_values() == 1 ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EXE (with one arguement) not unique" ); - sgte_name = *pe->get_values().begin(); - } - - else if ( pe->get_nb_values() == 2 ) { - bb_exe_name = *pe->get_values().begin(); - sgte_name = *(++pe->get_values().begin()); - } - - else - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EXE" ); - - set_SGTE_EXE ( bb_exe_name , sgte_name ); - pe->set_has_been_interpreted(); - } - } - - // SGTE_EVAL_SORT: - // --------------- - { - pe = entries.find ( "SGTE_EVAL_SORT" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EVAL_SORT not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EVAL_SORT" ); - set_SGTE_EVAL_SORT ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // HAS_SGTE: - // --------- - { - pe = entries.find ( "HAS_SGTE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HAS_SGTE not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HAS_SGTE" ); - set_HAS_SGTE ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // OPT_ONLY_SGTE: - // -------------- - { - pe = entries.find ( "OPT_ONLY_SGTE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPT_ONLY_SGTE not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPT_ONLY_SGTE" ); - set_OPT_ONLY_SGTE ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // DISPLAY_DEGREE: - // --------------- - { - pe = entries.find ( "DISPLAY_DEGREE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_DEGREE not unique" ); - if ( pe->get_nb_values() != 1 || - !set_DISPLAY_DEGREE ( *(pe->get_values().begin()) ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_DEGREE" ); - pe->set_has_been_interpreted(); - } - } - - // OPEN_BRACE: - // ----------- - { - pe = entries.find ( "OPEN_BRACE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPEN_BRACE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPEN_BRACE" ); - - set_OPEN_BRACE ( *(pe->get_values().begin()) ); - - pe->set_has_been_interpreted(); - } - } - - // CLOSED_BRACE: - // ------------- - { - pe = entries.find ( "CLOSED_BRACE" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CLOSED_BRACE not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CLOSED_BRACE" ); - - set_CLOSED_BRACE ( *(pe->get_values().begin()) ); - - pe->set_has_been_interpreted(); - } - } - - // DISPLAY_STATS: - { - pe = entries.find ( "DISPLAY_STATS" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_STATS not unique" ); - std::list<std::string> ls; - end = pe->get_values().end(); - for ( it = pe->get_values().begin() ; it != end ; ++it ) - ls.push_back ( *it ); - ls.resize ( ls.size()-1 ); - set_DISPLAY_STATS ( ls ); - pe->set_has_been_interpreted(); - } - } - - // DISPLAY_ALL_EVAL: - // ----------------- - { - pe = entries.find ( "DISPLAY_ALL_EVAL" ); - if ( pe ) { - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_ALL_EVAL not unique" ); - i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); - if ( pe->get_nb_values() != 1 || i == -1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_ALL_EVAL" ); - set_DISPLAY_ALL_EVAL ( i == 1 ); - pe->set_has_been_interpreted(); - } - } - - // SEED: - // ----- - { - pe = entries.find ( "SEED" ); - - if ( pe ) { - - if ( !pe->is_unique() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SEED not unique" ); - - if ( pe->get_nb_values() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SEED" ); - - s = *(pe->get_values().begin()); - NOMAD::toupper(s); - - if ( s == "NONE" || s == "DIFF" ) - i = -1; - else if ( !NOMAD::atoi ( s , i ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SEED" ); - set_SEED(i); - pe->set_has_been_interpreted(); - } - } - - // VARIABLE_GROUP: - // --------------- - interpret_var_groups ( entries ); - - // PERIODIC_VARIABLE: - // ------------------ - interpret_periodic_var ( entries ); - - /*----------------------------------------------*/ - - // check the non-interpreted parameters: - pe = entries.find_non_interpreted(); - if ( pe ) { - err = "invalid parameter: " + pe->get_name() + " - unknown"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - // user must check the parameters with Parameters::check() + + // interpret and set the entries using SET methods: + std::list<std::string>::const_iterator it , end; + int i , j , m; + NOMAD::Double d; + NOMAD::Parameter_Entry * pe; + std::string s; + std::string err ; + + /*----------------------------------------------*/ + + // EPSILON: + // -------- + { + pe = entries.find ( "EPSILON" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EPSILON not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EPSILON" ); + set_EPSILON (d); + pe->set_has_been_interpreted(); + } + } + + // UNDEF_STR: + // ---------- + pe = entries.find ( "UNDEF_STR" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: UNDEF_STR not unique" ); + set_UNDEF_STR ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + + // INF_STR: + // -------- + pe = entries.find ( "INF_STR" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INF_STR not unique" ); + set_INF_STR ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + + // ANISOTROPIC_MESH + //------------------- + { + pe = entries.find ( "ANISOTROPIC_MESH" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ANISOTROPIC_MESH not unique" ); + + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ANISOTROPIC_MESH" ); + set_ANISOTROPIC_MESH ( i == 1 ); + pe->set_has_been_interpreted(); + + } + } + + // POLL_UPDATE_BASIS: + // ------------------ + { + pe = entries.find ( "POLL_UPDATE_BASIS" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: POLL_UPDATE_BASIS not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: POLL_UPDATE_BASIS" ); + set_POLL_UPDATE_BASIS (d); + pe->set_has_been_interpreted(); + } + } + + + + // MESH_UPDATE_BASIS: + // ------------------ + { + pe = entries.find ( "MESH_UPDATE_BASIS" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_UPDATE_BASIS not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_UPDATE_BASIS" ); + set_MESH_UPDATE_BASIS (d); + pe->set_has_been_interpreted(); + } + } + + // INITIAL_MESH_INDEX: + // ------------------- + { + pe = entries.find ( "INITIAL_MESH_INDEX" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_INDEX not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_INDEX" ); + pe->set_has_been_interpreted(); + set_INITIAL_MESH_INDEX (i); + } + } + + // MESH_REFINING_EXPONENT: + // ----------------------- + { + pe = entries.find ( "MESH_REFINING_EXPONENT" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_REFINING_EXPONENT not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_REFINING_EXPONENT" ); + pe->set_has_been_interpreted(); + set_MESH_REFINING_EXPONENT (i); + } + } + + // MESH_COARSENING_EXPONENT: + // ------------------------- + { + pe = entries.find ( "MESH_COARSENING_EXPONENT" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_COARSENING_EXPONENT not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_COARSENING_EXPONENT" ); + pe->set_has_been_interpreted(); + set_MESH_COARSENING_EXPONENT (i); + } + } + + // USE_SMESH: + // --------------- + { + pe = entries.find ( "USE_SMESH" ); + if ( pe ) + { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: USE_SMESH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: USE_SMESH" ); + set_USE_SMESH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + + // POINT_DISPLAY_LIMIT: + // -------------------- + { + pe = entries.find ( "POINT_DISPLAY_LIMIT" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: POINT_DISPLAY_LIMIT not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: POINT_DISPLAY_LIMIT" ); + set_POINT_DISPLAY_LIMIT (i); + pe->set_has_been_interpreted(); + } + } + + // DIMENSION: + // ---------- + { + pe = entries.find ( "DIMENSION" ); + + if ( !pe ) { + if ( !pe && _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION not defined" ); + } + else { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION not unique" ); + + int dim; + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), dim) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION" ); + + pe->set_has_been_interpreted(); + + set_DIMENSION ( dim ); + } + } + + // SNAP_TO_BOUNDS: + // --------------- + { + pe = entries.find ( "SNAP_TO_BOUNDS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SNAP_TO_BOUNDS not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SNAP_TO_BOUNDS" ); + set_SNAP_TO_BOUNDS ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // MULTI-MADS: + // ----------- + { + // MULTI_OVERALL_BB_EVAL: + pe = entries.find ( "MULTI_OVERALL_BB_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_OVERALL_BB_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_OVERALL_BB_EVAL" ); + pe->set_has_been_interpreted(); + set_MULTI_OVERALL_BB_EVAL (i); + } + + // MULTI_NB_MADS_RUNS: + pe = entries.find ( "MULTI_NB_MADS_RUNS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_NB_MADS_RUNS not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_NB_MADS_RUNS" ); + pe->set_has_been_interpreted(); + set_MULTI_NB_MADS_RUNS (i); + } + + // MULTI_USE_DELTA_CRIT: + pe = entries.find ( "MULTI_USE_DELTA_CRIT" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_USE_DELTA_CRIT not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_USE_DELTA_CRIT" ); + pe->set_has_been_interpreted(); + set_MULTI_USE_DELTA_CRIT ( i == 1 ); + } + + // MULTI_F_BOUNDS (f1_min, f2_min, f2_min, f2_max): + pe = entries.find ( "MULTI_F_BOUNDS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_F_BOUNDS not unique" ); + if ( pe->get_nb_values() != 4 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_F_BOUNDS" ); + NOMAD::Point mfb ( 4 ); + it = pe->get_values().begin(); + for ( i = 0 ; i < 4 ; ++i ) { + if ( !d.atof ( *it ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_F_BOUNDS" ); + mfb[i] = d; + ++it; + } + pe->set_has_been_interpreted(); + set_MULTI_F_BOUNDS ( mfb ); + } + + // MULTI_FORMULATION: + // ------------------ + { + pe = entries.find ( "MULTI_FORMULATION" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_FORMULATION not unique" ); + NOMAD::multi_formulation_type mft; + if ( pe->get_nb_values() != 1 || + !NOMAD::string_to_multi_formulation_type + ( *(pe->get_values().begin()) , mft ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Invalid parameter: MULTI_FORMULATION_TYPE" ); + pe->set_has_been_interpreted(); + set_MULTI_FORMULATION ( mft ); + } + } + } + + // Models + // -------------- + { + + + // Disable models when explicitely requested + pe = entries.find ( "DISABLE" ); + while ( pe ) + { + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISABLE" ); + + std::string smt = *(pe->get_values().begin()); + NOMAD::toupper(smt); + if ( smt == "MODELS" ) + set_DISABLE_MODELS(); + else if ( smt == "EVAL_SORT" ) + set_DISABLE_EVAL_SORT(); + else + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Invalid parameter: DISABLE MODELS. Only MODELS argument is accepted!" ); + + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } + + + + // MODEL_SEARCH (can be entered one time or twice): + int i_model_search = 1; + bool b_model_search = false; + pe = entries.find ( "MODEL_SEARCH" ); + + while ( pe ) { + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH" ); + if ( i_model_search == 3 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH (cannot be entered more than twice" ); + + NOMAD::model_type mt; + std::string smt = *(pe->get_values().begin()); + int imt = NOMAD::string_to_bool ( smt ); + + // entered as a boolean: + if ( imt == 0 || imt == 1 ) { + if ( b_model_search || i_model_search == 2 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH (boolean argument can only be used once)" ); + b_model_search = true; + set_MODEL_SEARCH ( imt == 1 ); + } + + // entered as a model type: + else { + + if ( !NOMAD::string_to_model_type ( smt , mt ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH" ); + + set_MODEL_SEARCH ( i_model_search , mt ); + } + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + ++i_model_search; + } + + // MODEL_SEARCH_OPTIMISTIC: + { + pe = entries.find ( "MODEL_SEARCH_OPTIMISTIC" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_OPTIMISTIC not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_OPTIMISTIC" ); + set_MODEL_SEARCH_OPTIMISTIC ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // MODEL_SEARCH_PROJ_TO_MESH: + { + pe = entries.find ( "MODEL_SEARCH_PROJ_TO_MESH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_PROJ_TO_MESH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_PROJ_TO_MESH" ); + set_MODEL_SEARCH_PROJ_TO_MESH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // MODEL_QUAD_RADIUS_FACTOR: + { + pe = entries.find ( "MODEL_QUAD_RADIUS_FACTOR" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_RADIUS_FACTOR not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_RADIUS_FACTOR" ); + pe->set_has_been_interpreted(); + set_MODEL_QUAD_RADIUS_FACTOR ( d ); + } + } + + // MODEL_QUAD_USE_WP: + { + pe = entries.find ( "MODEL_QUAD_USE_WP" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_USE_WP not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_USE_WP" ); + set_MODEL_QUAD_USE_WP ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // MODEL_QUAD_MAX_Y_SIZE: + { + pe = entries.find ( "MODEL_QUAD_MAX_Y_SIZE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MAX_Y_SIZE not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MAX_Y_SIZE" ); + pe->set_has_been_interpreted(); + set_MODEL_QUAD_MAX_Y_SIZE (i); + } + } + + // MODEL_QUAD_MIN_Y_SIZE: + { + pe = entries.find ( "MODEL_QUAD_MIN_Y_SIZE" ); + if ( pe ) { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MIN_Y_SIZE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MIN_Y_SIZE" ); + + s = *(pe->get_values().begin()); + NOMAD::toupper(s); + + if ( s == "N+1" ) + i = -1; + else if ( !NOMAD::atoi ( s , i ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MIN_Y_SIZE" ); + + pe->set_has_been_interpreted(); + set_MODEL_QUAD_MIN_Y_SIZE (i); + } + } + + + // MODEL_QUAD_HYPERCUBE_LOWER_LIM: + { + pe = entries.find ( "MODEL_NP1_QUAD_EPSILON" ); + if ( pe ) { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_NP1_QUAD_EPSILON not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_NP1_QUAD_EPSILON" ); + + s = *(pe->get_values().begin()); + NOMAD::toupper(s); + NOMAD::Double d; + if ( !d.atof ( s) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_NP1_QUAD_EPSILON" ); + + pe->set_has_been_interpreted(); + set_MODEL_NP1_QUAD_EPSILON (d); + } + } + + // MODEL_TGP_MODE: + { + pe = entries.find ( "MODEL_TGP_MODE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_TGP_MODE not unique" ); + + NOMAD::TGP_mode_type m; + if ( pe->get_nb_values() != 1 || + !NOMAD::string_to_TGP_mode_type ( *(pe->get_values().begin()) , m ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Invalid parameter: MODEL_TGP_MODE" ); + pe->set_has_been_interpreted(); + set_MODEL_TGP_MODE ( m ); + } + } + + // MODEL_TGP_REUSE_MODEL: + { + pe = entries.find ( "MODEL_TGP_REUSE_MODEL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_TGP_REUSE_MODEL not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_TGP_REUSE_MODEL" ); + set_MODEL_TGP_REUSE_MODEL ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // MODEL_SEARCH_MAX_TRIAL_PTS: + { + pe = entries.find ( "MODEL_SEARCH_MAX_TRIAL_PTS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS" ); + pe->set_has_been_interpreted(); + set_MODEL_SEARCH_MAX_TRIAL_PTS (i); + } + } + + // MODEL_EVAL_SORT: + { + pe = entries.find ( "MODEL_EVAL_SORT" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT not unique" ); + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT" ); + + NOMAD::model_type mt; + std::string smt = *(pe->get_values().begin()); + int imt = NOMAD::string_to_bool ( smt ); + + // entered as a boolean: + if ( imt == 0 || imt == 1 ) + set_MODEL_EVAL_SORT ( imt == 1 ); + + // entered as a model type: + else { + + if ( !NOMAD::string_to_model_type ( smt , mt ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT" ); + set_MODEL_EVAL_SORT ( mt ); + } + + pe->set_has_been_interpreted(); + } + } + + // MODEL_EVAL_SORT_CAUTIOUS: + { + pe = entries.find ( "MODEL_EVAL_SORT_CAUTIOUS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT_CAUTIOUS not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT_CAUTIOUS" ); + set_MODEL_EVAL_SORT_CAUTIOUS ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + } + + // SPECULATIVE_SEARCH: + // ------------------- + { + pe = entries.find ( "SPECULATIVE_SEARCH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SPECULATIVE_SEARCH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SPECULATIVE_SEARCH" ); + set_SPECULATIVE_SEARCH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // VNS_SEARCH: + // ----------- + { + pe = entries.find ( "VNS_SEARCH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VNS_SEARCH not unique" ); + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VNS_SEARCH" ); + + s = *(pe->get_values().begin()); + i = NOMAD::string_to_bool ( s ); + + // entered as a real: + if ( i == -1 || s == "1" ) { + if ( !d.atof ( s ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VNS_SEARCH" ); + set_VNS_SEARCH ( d ); + } + // entered as a boolean: + else + set_VNS_SEARCH ( i == 1 ); + + pe->set_has_been_interpreted(); + } + } + + // CACHE_SEARCH: + // ------------- + { + pe = entries.find ( "CACHE_SEARCH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_SEARCH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_SEARCH" ); + set_CACHE_SEARCH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // LH_SEARCH: + // ---------- + { + pe = entries.find ( "LH_SEARCH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LH_SEARCH not unique" ); + if ( pe->get_nb_values() != 2 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LH_SEARCH" ); + it = pe->get_values().begin(); + + if ( !NOMAD::atoi (*it++ , i) || i < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LH_SEARCH" ); + + if ( !NOMAD::atoi (*it , j) || j < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LH_SEARCH" ); + + set_LH_SEARCH ( i , j ); + pe->set_has_been_interpreted(); + } + + // OPPORTUNISTIC_LH: + // ----------------- + { + pe = entries.find ( "OPPORTUNISTIC_LH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_LH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_LH" ); + set_OPPORTUNISTIC_LH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + } + + // OPPORTUNISTIC_CACHE_SEARCH: + // --------------------------- + { + pe = entries.find ( "OPPORTUNISTIC_CACHE_SEARCH" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_CACHE_SEARCH not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_CACHE_SEARCH" ); + set_OPPORTUNISTIC_CACHE_SEARCH ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // opportunistic strategy: + // ----------------------- + { + + // BB_MAX_BLOCK_SIZE + pe = entries.find ( "BB_MAX_BLOCK_SIZE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_MAX_BLOCK_SIZE not unique" ); + + it = pe->get_values().begin(); + + if ( !NOMAD::atoi (*it++ , i) || i <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_MAX_BLOCK_SIZE" ); + set_BB_MAX_BLOCK_SIZE (i); + + pe->set_has_been_interpreted(); + } + + + // OPPORTUNISTIC_EVAL: + pe = entries.find ( "OPPORTUNISTIC_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_EVAL not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_EVAL" ); + set_OPPORTUNISTIC_EVAL ( i == 1 ); + pe->set_has_been_interpreted(); + } + + // OPPORTUNISTIC_MIN_NB_SUCCESS: + pe = entries.find ( "OPPORTUNISTIC_MIN_NB_SUCCESS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_NB_SUCCESS not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_NB_SUCCESS" ); + pe->set_has_been_interpreted(); + set_OPPORTUNISTIC_MIN_NB_SUCCESS (i); + } + + // OPPORTUNISTIC_MIN_EVAL: + pe = entries.find ( "OPPORTUNISTIC_MIN_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_EVAL" ); + pe->set_has_been_interpreted(); + set_OPPORTUNISTIC_MIN_EVAL (i); + } + + // OPPORTUNISTIC_MIN_F_IMPRVMT: + pe = entries.find ( "OPPORTUNISTIC_MIN_F_IMPRVMT" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_F_IMPRVMT not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_MIN_F_IMPRVMT" ); + pe->set_has_been_interpreted(); + set_OPPORTUNISTIC_MIN_F_IMPRVMT ( d ); + } + + // OPPORTUNISTIC_LUCKY_EVAL: + pe = entries.find ( "OPPORTUNISTIC_LUCKY_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_LUCKY_EVAL not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPPORTUNISTIC_LUCKY_EVAL" ); + set_OPPORTUNISTIC_LUCKY_EVAL ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // Directions (DIRECTION_TYPE and SEC_POLL_DIR_TYPE): + // -------------------------------------------------- + { + NOMAD::direction_type dt; + + + pe = entries.find ( "DIRECTION_TYPE" ); + while ( pe ) { + + if ( !NOMAD::strings_to_direction_type ( pe->get_values() , dt ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIRECTION_TYPE" ); + set_DIRECTION_TYPE ( dt ); + + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } + + pe = entries.find ( "SEC_POLL_DIR_TYPE" ); + while ( pe ) { + if ( !NOMAD::strings_to_direction_type ( pe->get_values() , dt ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SEC_POLL_DIR_TYPE" ); + set_SEC_POLL_DIR_TYPE ( dt ); + + pe->set_has_been_interpreted(); + pe = pe->get_next(); + } + } + + + // MAX_ITERATIONS: + // --------------- + { + pe = entries.find ( "MAX_ITERATIONS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_ITERATIONS not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_ITERATIONS" ); + pe->set_has_been_interpreted(); + set_MAX_ITERATIONS (i); + } + } + + // MAX_CONSECUTIVE_FAILED_ITERATIONS: + // ---------------------------------- + { + pe = entries.find ( "MAX_CONSECUTIVE_FAILED_ITERATIONS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_CONSECUTIVE_FAILED_ITERATIONS not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_CONSECUTIVE_FAILED_ITERATIONS" ); + pe->set_has_been_interpreted(); + set_MAX_CONSECUTIVE_FAILED_ITERATIONS (static_cast<int>(d.value())); + } + } + + // MAX_CACHE_MEMORY: + // ----------------- + { + pe = entries.find ( "MAX_CACHE_MEMORY" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_CACHE_MEMORY not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_CACHE_MEMORY" ); + pe->set_has_been_interpreted(); + set_MAX_CACHE_MEMORY (static_cast<float>(d.value())); + } + } + + // MAX_EVAL: + // --------- + { + pe = entries.find ( "MAX_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_EVAL" ); + pe->set_has_been_interpreted(); + set_MAX_EVAL (i); + } + } + + // MAX_BB_EVAL: + // ------------ + { + pe = entries.find ( "MAX_BB_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_BB_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_BB_EVAL" ); + pe->set_has_been_interpreted(); + set_MAX_BB_EVAL (i); + } + } + + // MAX_SIM_BB_EVAL: + // ---------------- + { + pe = entries.find ( "MAX_SIM_BB_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_SIM_BB_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_SIM_BB_EVAL" ); + pe->set_has_been_interpreted(); + set_MAX_SIM_BB_EVAL (i); + } + } + + // MAX_SGTE_EVAL: + // -------------- + { + pe = entries.find ( "MAX_SGTE_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_SGTE_EVAL not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_SGTE_EVAL" ); + pe->set_has_been_interpreted(); + set_MAX_SGTE_EVAL (i); + } + } + + // MAX_TIME: + // --------- + { + pe = entries.find ( "MAX_TIME" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_TIME not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()), i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MAX_TIME" ); + + pe->set_has_been_interpreted(); + set_MAX_TIME (i); + } + } + + // STAT_SUM_TARGET: + // ---------------- + { + pe = entries.find ( "STAT_SUM_TARGET" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STAT_SUM_TARGET not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STAT_SUM_TARGET" ); + pe->set_has_been_interpreted(); + set_STAT_SUM_TARGET ( d ); + } + } + + // L_CURVE_TARGET: + // --------------- + { + pe = entries.find ( "L_CURVE_TARGET" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: L_CURVE_TARGET not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: L_CURVE_TARGET" ); + pe->set_has_been_interpreted(); + set_L_CURVE_TARGET ( d ); + } + } + + // EXTENDED_POLL_TRIGGER: + // ---------------------- + { + pe = entries.find ( "EXTENDED_POLL_TRIGGER" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_TRIGGER not unique" ); + + bool rel; + + if ( pe->get_nb_values() != 1 || + !d.relative_atof ( *(pe->get_values().begin()) , rel ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_TRIGGER" ); + + pe->set_has_been_interpreted(); + set_EXTENDED_POLL_TRIGGER ( d , rel ); + } + } + + // EXTENDED_POLL_ENABLED: + // ---------------------- + { + pe = entries.find ( "EXTENDED_POLL_ENABLED" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_ENABLED not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_ENABLED" ); + set_EXTENDED_POLL_ENABLED ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // USER_CALLS_ENABLED: + // ------------------- + { + pe = entries.find ( "USER_CALLS_ENABLED" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: USER_CALLS_ENABLED not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: USER_CALLS_ENABLED" ); + set_USER_CALLS_ENABLED ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // ASYNCHRONOUS: + // ------------- + { + pe = entries.find ( "ASYNCHRONOUS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ASYNCHRONOUS not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ASYNCHRONOUS" ); + set_ASYNCHRONOUS ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // RHO: + // ---- + { + pe = entries.find ( "RHO" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: RHO not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: RHO" ); + pe->set_has_been_interpreted(); + set_RHO(d); + } + } + + // H_MIN: + // ------ + { + pe = entries.find ( "H_MIN" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: H_MIN not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: H_MIN" ); + pe->set_has_been_interpreted(); + set_H_MIN(d); + } + } + + // H_MAX_0: + // -------- + { + pe = entries.find ( "H_MAX_0" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: H_MAX_0 not unique" ); + if ( pe->get_nb_values() != 1 || !d.atof ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Invalid parameter: H_MAX_0" ); + pe->set_has_been_interpreted(); + set_H_MAX_0(d); + } + } + + // H_NORM: + // ------- + { + pe = entries.find ( "H_NORM" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: H_NORM not unique" ); + NOMAD::hnorm_type hn = NOMAD::L2; + if ( pe->get_nb_values() != 1 || + !NOMAD::string_to_hnorm_type ( *(pe->get_values().begin()) , hn ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Invalid parameter: H_NORM" ); + pe->set_has_been_interpreted(); + set_H_NORM ( hn ); + } + } + + // TMP_DIR: + // -------- + { + _tmp_dir.clear(); + pe = entries.find ( "TMP_DIR" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: TMP_DIR not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: TMP_DIR" ); + + set_TMP_DIR ( *(pe->get_values().begin()) ); + + pe->set_has_been_interpreted(); + } + } + + // ADD_SEED_TO_FILE_NAMES: + // ----------------------- + { + pe = entries.find ( "ADD_SEED_TO_FILE_NAMES" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ADD_SEED_TO_FILE_NAMES not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ADD_SEED_TO_FILE_NAMES" ); + + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: ADD_SEED_TO_FILE_NAMES" ); + set_ADD_SEED_TO_FILE_NAMES ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // SOLUTION_FILE: + // -------------- + { + _solution_file.clear(); + pe = entries.find ( "SOLUTION_FILE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SOLUTION_FILE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SOLUTION_FILE" ); + set_SOLUTION_FILE ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + } + + // HISTORY_FILE: + // ------------- + { + _history_file.clear(); + pe = entries.find ( "HISTORY_FILE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: HISTORY_FILE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: HISTORY_FILE" ); + set_HISTORY_FILE ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + } + + // STATS_FILE: + // ----------- + { + pe = entries.find ( "STATS_FILE" ); + if ( pe ) { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STATS_FILE not unique" ); + + end = pe->get_values().end(); + it = pe->get_values().begin(); + std::string file_name = *it; + ++it; + + std::list<std::string> ls; + if (it!=end) + { + while ( it != end ) { + ls.push_back(*it); + ++it; + } + ls.resize(ls.size()-1); + } + + set_STATS_FILE ( file_name , ls ); + pe->set_has_been_interpreted(); + } + } + + // CACHE FILE: + // ----------- + { + _cache_file.clear(); + pe = entries.find ( "CACHE_FILE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_FILE not unique" ); + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_FILE" ); + set_CACHE_FILE ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + } + + // SGTE_CACHE FILE: + // ---------------- + { + _sgte_cache_file.clear(); + pe = entries.find ( "SGTE_CACHE_FILE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_CACHE_FILE not unique" ); + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_CACHE_FILE" ); + set_SGTE_CACHE_FILE ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + } + + + // CACHE_SAVE_PERIOD: + // ------------------ + { + pe = entries.find ( "CACHE_SAVE_PERIOD" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_SAVE_PERIOD not unique" ); + if ( pe->get_nb_values() != 1 || !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_SAVE_PERIOD" ); + set_CACHE_SAVE_PERIOD (i); + pe->set_has_been_interpreted(); + } + } + + // SGTE_COST: + // ---------- + { + pe = entries.find ( "SGTE_COST" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_COST not unique" ); + if ( pe->get_nb_values() != 1 || + !NOMAD::atoi (*(pe->get_values().begin()) , i) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_COST" ); + set_SGTE_COST (i); + pe->set_has_been_interpreted(); + } + } + + // X0: + // --- + interpret_x0 ( entries ); + + // FIXED_VARIABLE: + // --------------- + interpret_BFVS ( entries , "FIXED_VARIABLE"); + + // LOWER_BOUND: + // ------------ + interpret_BFVS ( entries , "LOWER_BOUND"); + + // UPPER_BOUND: + // ------------ + interpret_BFVS ( entries , "UPPER_BOUND"); + + // SCALING: + // -------- + interpret_BFVS ( entries , "SCALING" ); + + // BB_INPUT_TYPE: + // -------------- + interpret_bb_input_type ( entries ); + + // F_TARGET: + // --------- + interpret_f_target ( entries ); + + // STOP_IF_FEASIBLE: + // ----------------- + pe = entries.find ( "STOP_IF_FEASIBLE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STOP_IF_FEASIBLE not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STOP_IF_FEASIBLE" ); + pe->set_has_been_interpreted(); + set_STOP_IF_FEASIBLE ( i == 1 ); + } + + // BB_INPUT_INCLUDE_TAG: + // --------------------- + { + pe = entries.find ( "BB_INPUT_INCLUDE_TAG" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_INCLUDE_TAG not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_INCLUDE_TAG" ); + set_BB_INPUT_INCLUDE_TAG ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // BB_INPUT_INCLUDE_SEED: + // ---------------------- + { + pe = entries.find ( "BB_INPUT_INCLUDE_SEED" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_INCLUDE_SEED not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_INCLUDE_SEED" ); + set_BB_INPUT_INCLUDE_SEED ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + // BB_REDIRECTION: + // --------------- + { + pe = entries.find ( "BB_REDIRECTION" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_REDIRECTION not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_REDIRECTION" ); + set_BB_REDIRECTION ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // INITIAL_POLL_SIZE, INITIAL_MESH_SIZE, MIN_MESH_SIZE, and MIN_POLL_SIZE: + // ---------------------------------------------------- + interpret_mesh_sizes ( entries , "INITIAL_MESH_SIZE" ); + interpret_mesh_sizes ( entries , "INITIAL_POLL_SIZE" ); + interpret_mesh_sizes ( entries , "MIN_MESH_SIZE" ); + interpret_mesh_sizes ( entries , "MIN_POLL_SIZE" ); + + // BB_OUTPUT_TYPE: + // --------------- + { + pe = entries.find ( "BB_OUTPUT_TYPE" ); + + if ( !pe ) { + if ( _bb_output_type.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE not defined" ); + } + else { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE not unique" ); + + m = pe->get_nb_values(); + + if ( m <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE" ); + + NOMAD::bb_output_type cur; + std::list<NOMAD::bb_output_type> bbot; + i = 0; + end = pe->get_values().end(); + for ( it = pe->get_values().begin() ; it != end ; ++it ) { + if ( !NOMAD::string_to_bb_output_type ( *it , cur ) ) { + err = "invalid parameter: BB_OUTPUT_TYPE (" + pe->get_name(); + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + bbot.push_back (cur); + } + + set_BB_OUTPUT_TYPE ( bbot ); + + pe->set_has_been_interpreted(); + } + } + + // NEIGHBORS_EXE: + // -------------- + { + _neighbors_exe.clear(); + pe = entries.find ( "NEIGHBORS_EXE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: NEIGHBORS_EXE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: NEIGHBORS_EXE" ); + set_NEIGHBORS_EXE ( *(pe->get_values().begin()) ); + pe->set_has_been_interpreted(); + } + } + + // BB_EXE: + // ------- + { + pe = entries.find ( "BB_EXE" ); + if ( pe ) { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE not unique" ); + + m = pe->get_nb_values(); + + if ( m == 1 ) + set_BB_EXE ( *pe->get_values().begin() ); + + else { + + if ( m != static_cast<int>(_bb_output_type.size()) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: number of BB_EXE (>1) and corresponding BB_OUTPUT_TYPE must be the same." ); + + std::list<std::string> bbexe; + end = pe->get_values().end(); + for ( it = pe->get_values().begin() ; it != end ; ++it ) + bbexe.push_back (*it); + + set_BB_EXE ( bbexe ); + } + + pe->set_has_been_interpreted(); + } + } + + // SGTE_EXE: + // --------- + { + pe = entries.find ( "SGTE_EXE" ); + if ( pe ) { + + std::string bb_exe_name , sgte_name; + + if ( pe->get_nb_values() == 1 ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EXE (with one arguement) not unique" ); + sgte_name = *pe->get_values().begin(); + } + + else if ( pe->get_nb_values() == 2 ) { + bb_exe_name = *pe->get_values().begin(); + sgte_name = *(++pe->get_values().begin()); + } + + else + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EXE" ); + + set_SGTE_EXE ( bb_exe_name , sgte_name ); + pe->set_has_been_interpreted(); + } + } + + // SGTE_EVAL_SORT: + // --------------- + { + pe = entries.find ( "SGTE_EVAL_SORT" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EVAL_SORT not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EVAL_SORT" ); + set_SGTE_EVAL_SORT ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // HAS_SGTE: + // --------- + { + pe = entries.find ( "HAS_SGTE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: HAS_SGTE not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: HAS_SGTE" ); + set_HAS_SGTE ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // OPT_ONLY_SGTE: + // -------------- + { + pe = entries.find ( "OPT_ONLY_SGTE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPT_ONLY_SGTE not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPT_ONLY_SGTE" ); + set_OPT_ONLY_SGTE ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // DISPLAY_DEGREE: + // --------------- + { + pe = entries.find ( "DISPLAY_DEGREE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_DEGREE not unique" ); + if ( pe->get_nb_values() != 1 || + !set_DISPLAY_DEGREE ( *(pe->get_values().begin()) ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_DEGREE" ); + pe->set_has_been_interpreted(); + } + } + + // OPEN_BRACE: + // ----------- + { + pe = entries.find ( "OPEN_BRACE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPEN_BRACE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPEN_BRACE" ); + + set_OPEN_BRACE ( *(pe->get_values().begin()) ); + + pe->set_has_been_interpreted(); + } + } + + // CLOSED_BRACE: + // ------------- + { + pe = entries.find ( "CLOSED_BRACE" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CLOSED_BRACE not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CLOSED_BRACE" ); + + set_CLOSED_BRACE ( *(pe->get_values().begin()) ); + + pe->set_has_been_interpreted(); + } + } + + // DISPLAY_STATS: + { + pe = entries.find ( "DISPLAY_STATS" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_STATS not unique" ); + std::list<std::string> ls; + end = pe->get_values().end(); + for ( it = pe->get_values().begin() ; it != end ; ++it ) + ls.push_back ( *it ); + ls.resize ( ls.size()-1 ); + set_DISPLAY_STATS ( ls ); + pe->set_has_been_interpreted(); + } + } + + // DISPLAY_ALL_EVAL: + // ----------------- + { + pe = entries.find ( "DISPLAY_ALL_EVAL" ); + if ( pe ) { + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_ALL_EVAL not unique" ); + i = NOMAD::string_to_bool ( *(pe->get_values().begin() ) ); + if ( pe->get_nb_values() != 1 || i == -1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_ALL_EVAL" ); + set_DISPLAY_ALL_EVAL ( i == 1 ); + pe->set_has_been_interpreted(); + } + } + + // SEED: + // ----- + { + pe = entries.find ( "SEED" ); + + if ( pe ) + { + + if ( !pe->is_unique() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SEED not unique" ); + + if ( pe->get_nb_values() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SEED" ); + + s = *(pe->get_values().begin()); + NOMAD::toupper(s); + + + if ( s == "DIFF" ) + i = -1; + else if ( !NOMAD::atoi ( s , i ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SEED" ); + set_SEED(i); + pe->set_has_been_interpreted(); + + + } + } + + // VARIABLE_GROUP: + // --------------- + interpret_var_groups ( entries ); + + // PERIODIC_VARIABLE: + // ------------------ + interpret_periodic_var ( entries ); + + /*----------------------------------------------*/ + + // check the non-interpreted parameters: + pe = entries.find_non_interpreted(); + if ( pe ) { + err = "invalid parameter: " + pe->get_name() + " - unknown"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + // user must check the parameters with Parameters::check() } /*---------------------------------------*/ @@ -2797,644 +2882,654 @@ void NOMAD::Parameters::read ( const NOMAD::Parameter_Entries & entries ) /*---------------------------------------*/ void NOMAD::Parameters::display ( const NOMAD::Display & out ) const { - std::list<std::string>::const_iterator it; - - if ( _to_be_checked ) { - out << "parameters not checked" << std::endl; - return; - } - - // problem directory: - if ( !_problem_dir.empty() ) { - out << "problem directory : " << _problem_dir << std::endl; - if ( _tmp_dir != _problem_dir ) - out << "tmp directory : " << _tmp_dir << std::endl; - } - - // dimension: - out << "dimension : n=" << _dimension << std::endl; - - // bounds: - if ( _lb.is_defined() ) { - out << "lower bounds : ( "; - _lb.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - if ( _ub.is_defined() ) { - out << "upper bounds : ( "; - _ub.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // scaling: - if ( _scaling.is_defined() ) { - out << "scaling : ( "; - _scaling.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // fixed variables: - if ( _fixed_variables.is_defined() ) { - out << "fixed variables : ( "; - _fixed_variables.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // back-box input types: - if ( _bb_input_include_tag ) - out << "blackbox input files : include tag" << std::endl; - if ( _bb_input_include_seed ) - out << "blackbox input files : include seed" << std::endl; - - out << "blackbox input types : "; - if ( get_signature()->all_continuous() ) - out << "all variables are continuous (R)" << std::endl; - else - out << "( " << _bb_input_type << " )" << std::endl; - - // extended poll trigger: - if ( get_signature()->has_categorical() ) { - if ( _extended_poll_enabled ) { - out << "extended poll trigger: " << _extended_poll_trigger; - if ( _relative_ept ) - out << " (relative)"; - if ( !_neighbors_exe.empty() ) - out << std::endl << "neighbors executable : " << _neighbors_exe; - } - else - out << "extended poll is disabled"; - out << std::endl; - } - - // periodic variables: - if ( !_periodic_variables.empty() ) { - out << "periodic variables : { "; - for ( size_t k = 0 ; k < _periodic_variables.size() ; ++k ) - if ( _periodic_variables[k] ) - out << k << " "; - out << "}" << std::endl; - } - - // variable groups: - if ( _var_groups.size() > 1 ) { - int i = 0; - out.open_block ( "variable groups" ); - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator - it2 , end2 = _var_groups.end(); - for ( it2 = _var_groups.begin() ; it2 != end2 ; ++it2 ) - out << NOMAD::open_block ( "group #" + NOMAD::itos ( i++ ) ) - << **it2 << NOMAD::close_block(); - out.close_block(); - } - - // blackbox outputs: - { - bool display_bb_exe = !_bb_exe.empty(); - bool display_sgte_exe = !_sgte_exe.empty(); - int m = static_cast<int>(_bb_output_type.size()); - int w = 1+int(log(static_cast<double>(m))/NOMAD::LOG10); - it = _bb_exe.begin(); - - out.open_block ( "blackbox outputs (m=" + NOMAD::itos ( m ) + ")" ); - for ( int i = 0 ; i < m ; ++i ) { - out << "#" << std::setw(w) << i << " " << std::setw(12) << _bb_output_type[i]; - if ( display_bb_exe ) { - out << "\t" << *it; - if ( display_sgte_exe ) - out << "\t" << get_sgte_exe(*it); - ++it; - } - out << std::endl; - } - out.close_block(); - } - - // signature (standard or extern): - out << "signature : " - << ( (_std_signature) ? "standard" : "extern" ) << std::endl; - - // BB_REDIRECTION: - if ( !_bb_redirection ) { - out << "blackbox output redirection : "; - out.display_yes_or_no ( _bb_redirection ); - out << std::endl; - } - - // surrogate: - { - out << "has surrogate : "; - out.display_yes_or_no ( _has_sgte ); - out << std::endl; - if ( _has_sgte ) { - - // OPT_ONLY_SGTE: - if ( _opt_only_sgte ) { - out << "minimize only with surrogate : "; - out.display_yes_or_no ( _opt_only_sgte ); - out << std::endl; - } - - // SGTE_EVAL_SORT: - out << "sort trial points with surrogate: "; - out.display_yes_or_no ( _sgte_eval_sort ); - out << std::endl; - - // SGTE_COST: - out << "surrogate cost : "; - if ( _sgte_cost > 0 ) - out << _sgte_cost - << " surrogate evaluations count as one bb evaluation" << std::endl; - else - out << "none" << std::endl; - } - } - - // MULTI-MADS: - if ( get_nb_obj() > 1 ) { - out << "multi-MADS : [overall bb eval="; - if ( _multi_overall_bb_eval >= 0 ) - out << _multi_overall_bb_eval; - else - out << "-"; - out << "] [nb MADS runs="; - if ( _multi_nb_mads_runs >= 0 ) - out << _multi_nb_mads_runs; - else - out << "-"; - out << "] [use delta crit="; - out.display_yes_or_no ( _multi_use_delta_crit ); - out << "]" << std::endl - << " [formulation=" - << _multi_formulation << "]"; - if ( _multi_f_bounds.is_defined() ) { - out << " [f_bounds="; - _multi_f_bounds.display ( out , "," , -1 , -1 ); - out << "]"; - } - out << std::endl; - } - - // barrier: - if ( _has_constraints ) { - - out << "barrier type : "; - switch ( _barrier_type ) { - case NOMAD::EB: - out << "extreme" << std::endl; - break; - case NOMAD::PEB_P: - case NOMAD::PB: - out << "progressive" << std::endl; - out << "prog. barrier trigger : " << _rho << std::endl; - break; - default: - out << "filter" << std::endl; - } - out << "barrier h_min : " << _h_min << std::endl - << "barrier initial h_max : " << _h_max_0 << std::endl; - } - if ( _has_filter_constraints ) - out << "barrier h_norm : " << _h_norm << std::endl; - - // ADD_SEED_TO_FILE_NAMES: - out << "add seed to output file names : "; - out.display_yes_or_no ( _add_seed_to_file_names ); - out << std::endl; - - // SOLUTION_FILE: - out << "solution file : "; - if ( !_solution_file.empty() ) - out << _solution_file << std::endl; - else - out << "none" << std::endl; - - // HISTORY_FILE: - out << "history file : "; - if ( !_history_file.empty() ) - out << _history_file << std::endl; - else - out << "none" << std::endl; - - // STATS_FILE: - out << "stats file : "; - if ( !_stats_file_name.empty() ) { - out << "(" << _stats_file_name << ") "; - std::list<std::string>::const_iterator end = _stats_file.end(); - for ( it = _stats_file.begin() ; it != end ; ++it ) { - if ( it->empty() ) - out << " "; - else - out << *it; - } - out << std::endl; - } - else - out << "none" << std::endl; - - // CACHE_FILE: - out << "cache file : "; - if ( !_cache_file.empty() ) { - out << _cache_file << std::endl; - out << "cache save period : "; - if ( _cache_save_period <= 0 ) - out << "never"; - else if ( _cache_save_period == 1 ) - out << "every iteration"; - else - out << "every " << _cache_save_period << " iterations"; - out << std::endl; - } - else - out << "none" << std::endl; - - // surrogate cache file: - if ( !_sgte_cache_file.empty() ) - out << "surrogate cache file : " - << _sgte_cache_file << std::endl; - - // X0: - if ( _x0s.empty() && _x0_cache_file.empty() ) - out << "x0 : points in \'" - << _cache_file << "\'" << std::endl; - else { - bool first = true; - if ( !_x0_cache_file.empty() ) { - if ( first ) { - out << "x0 : "; - first = false; - } - else - out << " : "; - out << _x0_cache_file; - if ( _x0_cache_file != _cache_file ) - out << " (read only)"; - out << std::endl; - } - if ( !_x0s.empty() ) { - size_t x0n = _x0s.size(); - for ( size_t k = 0 ; k < x0n ; ++k ) { - if ( first ) { - out << "x0 : "; - first = false; - } - else - out << " : "; - out << "( "; - _x0s[k]->display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - } - } - - // directions: - { - std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); - if ( _direction_types.size() == 1 ) - out << "directions : " - << *_direction_types.begin() << std::endl; - else { - out << NOMAD::open_block ( "directions" ); - for ( it = _direction_types.begin() ; it != end ; ++it ) - out << *it << std::endl; - out.close_block(); - } - if ( _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P ) { - if ( _sec_poll_dir_types.empty() ) - out << "sec. poll dir. type: no secondary poll" << std::endl; - else { - if ( _sec_poll_dir_types.size() == 1 ) - out << "sec. poll dir. type: " - << *_sec_poll_dir_types.begin() << std::endl; - else { - end = _sec_poll_dir_types.end(); - out << NOMAD::open_block ( "sec. poll dir. types" ); - for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) - out << *it << std::endl; - out.close_block(); - } - } - } - if ( _halton_seed >= 0 ) - out << "user halton seed : " << _halton_seed << std::endl; - - } - - // mesh: - { - out << NOMAD::open_block ( "mesh" ) - << "update basis : " << std::setw(3) << _mesh_update_basis << std::endl - << "coarsening exponent: " << std::setw(3) << _mesh_coarsening_exponent - << std::endl - << "refining exponent : " << std::setw(3) << _mesh_refining_exponent - << std::endl - << "initial mesh index : " << std::setw(3) << _initial_mesh_index << std::endl; - if ( _max_mesh_index != NOMAD::UNDEFINED_L ) - out << "max mesh index : " << std::setw(3) << _max_mesh_index << std::endl; - out << "initial mesh size : ( "; - _initial_mesh_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - if ( _min_mesh_size.is_defined() ) { - out << "min mesh size : ( "; - _min_mesh_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - if ( _min_poll_size.is_defined() ) { - out << "min poll size : ( "; - _min_poll_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - out.close_block(); - } - - // ASYNCHRONOUS: + std::list<std::string>::const_iterator it; + + if ( _to_be_checked ) { + out << "parameters not checked" << std::endl; + return; + } + + // problem directory: + if ( !_problem_dir.empty() ) { + out << "problem directory : " << _problem_dir << std::endl; + if ( _tmp_dir != _problem_dir ) + out << "tmp directory : " << _tmp_dir << std::endl; + } + + // dimension: + out << "dimension : n=" << _dimension << std::endl; + + // bounds: + if ( _lb.is_defined() ) { + out << "lower bounds : ( "; + _lb.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + if ( _ub.is_defined() ) { + out << "upper bounds : ( "; + _ub.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // scaling: + if ( _scaling.is_defined() ) { + out << "scaling : ( "; + _scaling.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // fixed variables: + if ( _fixed_variables.is_defined() ) { + out << "fixed variables : ( "; + _fixed_variables.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // back-box input types: + if ( _bb_input_include_tag ) + out << "blackbox input files : include tag" << std::endl; + if ( _bb_input_include_seed ) + out << "blackbox input files : include seed" << std::endl; + + out << "blackbox input types : "; + if ( get_signature()->all_continuous() ) + out << "all variables are continuous (R)" << std::endl; + else + out << "( " << _bb_input_type << " )" << std::endl; + + // extended poll trigger: + if ( get_signature()->has_categorical() ) { + if ( _extended_poll_enabled ) { + out << "extended poll trigger: " << _extended_poll_trigger; + if ( _relative_ept ) + out << " (relative)"; + if ( !_neighbors_exe.empty() ) + out << std::endl << "neighbors executable : " << _neighbors_exe; + } + else + out << "extended poll is disabled"; + out << std::endl; + } + + // periodic variables: + if ( !_periodic_variables.empty() ) { + out << "periodic variables : { "; + for ( size_t k = 0 ; k < _periodic_variables.size() ; ++k ) + if ( _periodic_variables[k] ) + out << k << " "; + out << "}" << std::endl; + } + + // variable groups: + if ( _var_groups.size() > 1 ) { + int i = 0; + out.open_block ( "variable groups" ); + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator + it2 , end2 = _var_groups.end(); + for ( it2 = _var_groups.begin() ; it2 != end2 ; ++it2 ) + out << NOMAD::open_block ( "group #" + NOMAD::itos ( i++ ) ) + << **it2 << NOMAD::close_block(); + out.close_block(); + } + + // blackbox outputs: + { + bool display_bb_exe = !_bb_exe.empty(); + bool display_sgte_exe = !_sgte_exe.empty(); + int m = static_cast<int>(_bb_output_type.size()); + int w = 1+int(log(static_cast<double>(m))/NOMAD::LOG10); + it = _bb_exe.begin(); + + out.open_block ( "blackbox outputs (m=" + NOMAD::itos ( m ) + ")" ); + for ( int i = 0 ; i < m ; ++i ) { + out << "#" << std::setw(w) << i << " " << std::setw(12) << _bb_output_type[i]; + if ( display_bb_exe ) { + out << "\t" << *it; + if ( display_sgte_exe ) + out << "\t" << get_sgte_exe(*it); + ++it; + } + out << std::endl; + } + out.close_block(); + } + + // signature (standard or extern): + out << "signature : " + << ( (_std_signature) ? "standard" : "extern" ) << std::endl; + + // BB_REDIRECTION: + if ( !_bb_redirection ) { + out << "blackbox output redirection : "; + out.display_yes_or_no ( _bb_redirection ); + out << std::endl; + } + + // surrogate: + { + out << "has surrogate : "; + out.display_yes_or_no ( _has_sgte ); + out << std::endl; + if ( _has_sgte ) { + + // OPT_ONLY_SGTE: + if ( _opt_only_sgte ) { + out << "minimize only with surrogate : "; + out.display_yes_or_no ( _opt_only_sgte ); + out << std::endl; + } + + // SGTE_EVAL_SORT: + out << "sort trial points with surrogate: "; + out.display_yes_or_no ( _sgte_eval_sort ); + out << std::endl; + + // SGTE_COST: + out << "surrogate cost : "; + if ( _sgte_cost > 0 ) + out << _sgte_cost + << " surrogate evaluations count as one bb evaluation" << std::endl; + else + out << "none" << std::endl; + } + } + + // MULTI-MADS: + if ( get_nb_obj() > 1 ) { + out << "multi-MADS : [overall bb eval="; + if ( _multi_overall_bb_eval >= 0 ) + out << _multi_overall_bb_eval; + else + out << "-"; + out << "] [nb MADS runs="; + if ( _multi_nb_mads_runs >= 0 ) + out << _multi_nb_mads_runs; + else + out << "-"; + out << "] [use delta crit="; + out.display_yes_or_no ( _multi_use_delta_crit ); + out << "]" << std::endl + << " [formulation=" + << _multi_formulation << "]"; + if ( _multi_f_bounds.is_defined() ) { + out << " [f_bounds="; + _multi_f_bounds.display ( out , "," , -1 , -1 ); + out << "]"; + } + out << std::endl; + } + + // barrier: + if ( _has_constraints ) { + + out << "barrier type : "; + switch ( _barrier_type ) { + case NOMAD::EB: + out << "extreme" << std::endl; + break; + case NOMAD::PEB_P: + case NOMAD::PB: + out << "progressive" << std::endl; + out << "prog. barrier trigger : " << _rho << std::endl; + break; + default: + out << "filter" << std::endl; + } + out << "barrier h_min : " << _h_min << std::endl + << "barrier initial h_max : " << _h_max_0 << std::endl; + } + if ( _has_filter_constraints ) + out << "barrier h_norm : " << _h_norm << std::endl; + + // ADD_SEED_TO_FILE_NAMES: + out << "add seed to output file names : "; + out.display_yes_or_no ( _add_seed_to_file_names ); + out << std::endl; + + // SOLUTION_FILE: + out << "solution file : "; + if ( !_solution_file.empty() ) + out << _solution_file << std::endl; + else + out << "none" << std::endl; + + // HISTORY_FILE: + out << "history file : "; + if ( !_history_file.empty() ) + out << _history_file << std::endl; + else + out << "none" << std::endl; + + // STATS_FILE: + out << "stats file : "; + if ( !_stats_file_name.empty() ) { + out << "(" << _stats_file_name << ") "; + std::list<std::string>::const_iterator end = _stats_file.end(); + for ( it = _stats_file.begin() ; it != end ; ++it ) { + if ( it->empty() ) + out << " "; + else + out << *it; + } + out << std::endl; + } + else + out << "none" << std::endl; + + // CACHE_FILE: + out << "cache file : "; + if ( !_cache_file.empty() ) { + out << _cache_file << std::endl; + out << "cache save period : "; + if ( _cache_save_period <= 0 ) + out << "never"; + else if ( _cache_save_period == 1 ) + out << "every iteration"; + else + out << "every " << _cache_save_period << " iterations"; + out << std::endl; + } + else + out << "none" << std::endl; + + // surrogate cache file: + if ( !_sgte_cache_file.empty() ) + out << "surrogate cache file : " + << _sgte_cache_file << std::endl; + + // X0: + if ( _x0s.empty() && _x0_cache_file.empty() ) + out << "x0 : points in \'" + << _cache_file << "\'" << std::endl; + else { + bool first = true; + if ( !_x0_cache_file.empty() ) { + if ( first ) { + out << "x0 : "; + first = false; + } + else + out << " : "; + out << _x0_cache_file; + if ( _x0_cache_file != _cache_file ) + out << " (read only)"; + out << std::endl; + } + if ( !_x0s.empty() ) { + size_t x0n = _x0s.size(); + for ( size_t k = 0 ; k < x0n ; ++k ) { + if ( first ) { + out << "x0 : "; + first = false; + } + else + out << " : "; + out << "( "; + _x0s[k]->display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + } + } + + // directions: + { + std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); + if ( _direction_types.size() == 1 ) + out << "directions : " + << *_direction_types.begin() << std::endl; + else { + out << NOMAD::open_block ( "directions" ); + for ( it = _direction_types.begin() ; it != end ; ++it ) + out << *it << std::endl; + out.close_block(); + } + if ( _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P ) { + if ( _sec_poll_dir_types.empty() ) + out << "sec. poll dir. type: no secondary poll" << std::endl; + else { + if ( _sec_poll_dir_types.size() == 1 ) + out << "sec. poll dir. type: " + << *_sec_poll_dir_types.begin() << std::endl; + else { + end = _sec_poll_dir_types.end(); + out << NOMAD::open_block ( "sec. poll dir. types" ); + for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) + out << *it << std::endl; + out.close_block(); + } + } + } + + } + + // mesh: + { + if ( get_use_smesh() ) + { + out << NOMAD::open_block ( "smesh (isotropic)" ); + out << "mesh update basis : " << std::setw(3) << _mesh_update_basis << std::endl; + } + else + { + if ( get_anisotropic_mesh() ) + out << NOMAD::open_block ( "xmesh (anisotropic)" ); + else + out << NOMAD::open_block ( "xmesh (isotropic)" ); + out << "poll update basis : " << std::setw(3) << _poll_update_basis << std::endl; + } + out << "coarsening exponent : " << std::setw(3) << _mesh_coarsening_exponent + << std::endl + << "refining exponent : " << std::setw(3) << _mesh_refining_exponent + << std::endl + << "initial mesh index : " << std::setw(3) << _initial_mesh_index << std::endl; + out << "initial mesh size : ( "; + _initial_mesh_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + out << "initial poll size : ( "; + _initial_poll_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + if ( _min_mesh_size.is_defined() ) { + out << "min mesh size : ( "; + _min_mesh_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + if ( _min_poll_size.is_defined() ) { + out << "min poll size : ( "; + _min_poll_size.display ( out , " " , 4 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + out.close_block(); + } + + // ASYNCHRONOUS: #ifdef USE_MPI - out << "asynchronous : "; - out.display_yes_or_no ( _asynchronous ); - out << std::endl; + out << "asynchronous : "; + out.display_yes_or_no ( _asynchronous ); + out << std::endl; #endif - - // USER_CALLS_ENABLED: - if ( !_user_calls_enabled ) - out << "user calls : disabled" << std::endl; - - // SNAP_TO_BOUNDS: - out << "snap to bounds : "; - out.display_yes_or_no ( _snap_to_bounds ); - out << std::endl; - - // opportunistic strategy: - { - out << "opportunistic evaluations : "; - out.display_yes_or_no ( _opportunistic_eval ); - out << std::endl; - if ( _opportunistic_eval ) { - if ( _opportunistic_min_nb_success > 0 ) - out << "opportunistic min nb success : " - << _opportunistic_min_nb_success << std::endl; - if ( _opportunistic_min_eval > 0 ) - out << "opportunistic min nb eval : " - << _opportunistic_min_eval << std::endl; - if ( _opportunistic_min_f_imprvmt.is_defined() ) - out << "opportunistic min obj improvement: " - << _opportunistic_min_f_imprvmt << "%" - << std::endl; - if ( _opportunistic_lucky_eval ) - out << "opportunistic lucky eval : " - << _opportunistic_lucky_eval << std::endl; - } - } - - // models: - if (_disable_models) - { - out << NOMAD::open_block ( "models" ); - out << "models usage has been forcefully disabled: " - << std::endl << NOMAD::close_block(); - } - else - { - if ( _model_params.search1 != NOMAD::NO_MODEL || - _model_params.eval_sort != NOMAD::NO_MODEL ) - { - out << NOMAD::open_block ( "models" ); - if ( _model_params.search1 != NOMAD::NO_MODEL ) - { - out << NOMAD::open_block ( "model search" ); - if ( _model_params.search2 == NOMAD::NO_MODEL ) - out << "models type : " << _model_params.search1 << std::endl; - else - out << "models types : " - << _model_params.search1 << " and " - << _model_params.search2 << std::endl; - out << "project to mesh: "; - out.display_yes_or_no ( _model_params.search_proj_to_mesh ); - out << std::endl - << "optimistic : "; - out.display_yes_or_no ( _model_params.search_optimistic ); - out << std::endl - << "max trial pts : " << _model_params.search_max_trial_pts - << std::endl << NOMAD::close_block(); - } - else - out << "no model search" << std::endl; - - // model ordering: - if ( _model_params.eval_sort != NOMAD::NO_MODEL ) { - if ( _model_params.eval_sort == NOMAD::QUADRATIC_MODEL ) { - out << NOMAD::open_block ( "model ordering" ) - << "models type : " << _model_params.eval_sort - << std::endl << "cautious model ordering: "; - out.display_yes_or_no ( _model_params.eval_sort_cautious ); - out << std::endl << NOMAD::close_block(); - } - else - out << "model ordering: " << _model_params.eval_sort << std::endl; - } - else - out << "no model ordering" << std::endl; - - - if ( has_direction_type(NOMAD::ORTHO_NP1_QUAD) ) - { - out << NOMAD::open_block ( "Quad model (n+1)th dynamic direction for Ortho N+1" ) - << "models type : QUADRATIC " - << std::endl << "cautious model ordering: "; - out.display_yes_or_no ( _model_params.eval_sort_cautious ); - out << std::endl << "quad model epsilon for ortho n+1: " - << _model_params.model_np1_quad_epsilon << std::endl; - out << std::endl << NOMAD::close_block(); - } - - // quadratic model parameters: - if ( _model_params.eval_sort == NOMAD::QUADRATIC_MODEL || - _model_params.search1 == NOMAD::QUADRATIC_MODEL || - _model_params.search2 == NOMAD::QUADRATIC_MODEL ) { - out << NOMAD::open_block ( "quadratic model parameters" ) - << "radius factor: " << _model_params.quad_radius_factor << std::endl - << "use WP : "; - out.display_yes_or_no ( _model_params.quad_use_WP ); - out << std::endl << "min Y size : "; - if ( _model_params.quad_min_Y_size < 0 ) - out << "n+1"; - else - out << _model_params.quad_min_Y_size; - out << std::endl - << "max Y size : " << _model_params.quad_max_Y_size - << std::endl << NOMAD::close_block(); - } - - // TGP model parameters: - if ( _model_params.eval_sort == NOMAD::TGP_MODEL || - _model_params.search1 == NOMAD::TGP_MODEL || - _model_params.search2 == NOMAD::TGP_MODEL ) { - out << NOMAD::open_block ( "TGP model parameters" ) - << "mode : " << _model_params.tgp_mode << std::endl - << "reuse model: " << _model_params.tgp_reuse_model << std::endl - << NOMAD::close_block(); - } - out.close_block(); - } - else { - out << "use models : "; - out.display_yes_or_no ( false ); - out << std::endl; - } - } - - // SPECULATIVE_SEARCH: - out << "speculative search : "; - out.display_yes_or_no ( _speculative_search ); - out << std::endl; - - // VNS_SEARCH: - out << "VNS search : "; - out.display_yes_or_no ( _VNS_search ); - if ( _VNS_search ) - out << " [trigger=" << _VNS_trigger << "]"; - out << std::endl; - - // LH_SEARCH: - out << "Latin-Hypercube (LH) search : "; - if ( _LH_search_p0 > 0 || _LH_search_pi > 0 ) { - out << "#init:" << _LH_search_p0 - << ", #iter:" << _LH_search_pi - << ", opport:"; - out.display_yes_or_no ( _opportunistic_LH ); - } - else - out.display_yes_or_no ( false ); - out << std::endl; - - // CACHE_SEARCH: - out << "cache search : "; - if ( _cache_search ) { - out.display_yes_or_no ( true ); - out << ", opport:"; - out.display_yes_or_no ( _opportunistic_cache_search ); - } - else - out.display_yes_or_no ( false ); - out << std::endl; - - // random seed / unique tag / run id: - out << "random seed / run id : " << _seed << std::endl; - - // EPSILON: - out << "epsilon : " - << NOMAD::Double::get_epsilon() << std::endl; - - // UNDEF_STR: - out << "undefined string : " - << NOMAD::Double::get_undef_str() << std::endl; - - // INF_STR: - out << "infinity string : " - << NOMAD::Double::get_inf_str() << std::endl; - - // DISPLAY_DEGREEs: - out << NOMAD::open_block ( "display degrees" ) - << "general : " << _out.get_gen_dd() << std::endl - << "search : " << _out.get_search_dd() << std::endl - << "poll : " << _out.get_poll_dd() << std::endl - << "iterative: " << _out.get_iter_dd() << std::endl - << NOMAD::close_block(); - - // DISPLAY_STATS: - out << "display stats : "; - std::list<std::string>::const_iterator end = _display_stats.end(); - for ( it = _display_stats.begin() ; it != end ; ++it ) { - if ( it->empty() ) - out << " "; - else - out << *it; - } - out << std::endl; - - // DISPLAY_ALL_EVAL: - out << "display all evaluations : "; - out.display_yes_or_no ( _display_all_eval ); - out << std::endl; - - // POINT_DISPLAY_LIMIT: - out << "point display limit : "; - if ( NOMAD::Point::get_display_limit() > 0 ) - out << NOMAD::Point::get_display_limit() << std::endl; - else - out << "no limit" << std::endl; - - // MAX_EVAL: - if ( _max_eval > 0 ) - out << "max eval. (bb+cache) : " << _max_eval << std::endl; - - // MAX_BB_EVAL: - if ( _max_bb_eval >= 0 ) { - out << "max number of blackbox eval. : " << _max_bb_eval; - if ( _max_bb_eval == 0 ) - out << " (no blackbox eval. allowed)"; - out << std::endl; - } - - // MAX_SIM_BB_EVAL: - if ( _max_sim_bb_eval >= 0 ) - out << "max simulated blackbox eval. : " << _max_sim_bb_eval << std::endl; - - // MAX_SGTE_EVAL: - if ( _sgte_max_eval >= 0 ) { - out << "max surrogate eval. : " << _sgte_max_eval; - if ( _sgte_max_eval == 0 ) - out << " (no surrogate eval. allowed)"; - out << std::endl; - } - - // MAX_ITERATIONS: - if ( _max_iterations >= 0 ) { - out << "max iterations : " << _max_iterations; - if ( _max_iterations == 0 ) - out << " (no iterations allowed)"; - out << std::endl; - } - - // MAX_CONSECUTIVE_FAILED_ITERATIONS: - if ( _max_cons_failed_it > 0 ) - out << "max consecutive failed it. : " << _max_cons_failed_it << std::endl; - - // MAX_CACHE_MEMORY: - if ( _max_cache_memory > 0 ) - out << "max cache memory : " << _max_cache_memory - << " MB" << std::endl; - - // MAX_TIME: - if ( _max_time > 0 ) - out << "max wall-clock time : " << _max_time << "s" << std::endl; - - // F_TARGET: - if ( _f_target.is_defined() ) { - out << "objective target : "; - if ( _f_target.size() > 1 ) { - out << "( "; - _f_target.display ( out , " " , 4 , -1 ); - out << " )" << std::endl; - } - else - out << _f_target[0] << std::endl; - } - - // STAT_SUM_TARGET: - if ( _stat_sum_target.is_defined() ) - out << "stat sum target : " - << _stat_sum_target << std::endl; - - // L_CURVE_TARGET: - if ( _L_curve_target.is_defined() ) - out << "L-curve target : " - << _L_curve_target << std::endl; - - // STOP_IF_FEASIBLE: - if ( _stop_if_feasible ) { - out << "stop if feasible : "; - out.display_yes_or_no ( _stop_if_feasible ); - out << std::endl; - } + + // USER_CALLS_ENABLED: + if ( !_user_calls_enabled ) + out << "user calls : disabled" << std::endl; + + // SNAP_TO_BOUNDS: + out << "snap to bounds : "; + out.display_yes_or_no ( _snap_to_bounds ); + out << std::endl; + + // opportunistic strategy: + { + out << "opportunistic evaluations : "; + out.display_yes_or_no ( _opportunistic_eval ); + out << std::endl; + if ( _opportunistic_eval ) { + if ( _opportunistic_min_nb_success > 0 ) + out << "opportunistic min nb success : " + << _opportunistic_min_nb_success << std::endl; + if ( _opportunistic_min_eval > 0 ) + out << "opportunistic min nb eval : " + << _opportunistic_min_eval << std::endl; + if ( _opportunistic_min_f_imprvmt.is_defined() ) + out << "opportunistic min obj improvement: " + << _opportunistic_min_f_imprvmt << "%" + << std::endl; + if ( _opportunistic_lucky_eval ) + out << "opportunistic lucky eval : " + << _opportunistic_lucky_eval << std::endl; + } + } + + // models: + if (_disable_models) + { + out << NOMAD::open_block ( "models" ); + out << "models usage has been forcefully disabled: " + << std::endl << NOMAD::close_block(); + } + else + { + if ( _model_params.search1 != NOMAD::NO_MODEL || + _model_params.eval_sort != NOMAD::NO_MODEL ) + { + out << NOMAD::open_block ( "models" ); + if ( _model_params.search1 != NOMAD::NO_MODEL ) + { + out << NOMAD::open_block ( "model search" ); + if ( _model_params.search2 == NOMAD::NO_MODEL ) + out << "models type : " << _model_params.search1 << std::endl; + else + out << "models types : " + << _model_params.search1 << " and " + << _model_params.search2 << std::endl; + out << "project to mesh: "; + out.display_yes_or_no ( _model_params.search_proj_to_mesh ); + out << std::endl + << "optimistic : "; + out.display_yes_or_no ( _model_params.search_optimistic ); + out << std::endl + << "max trial pts : " << _model_params.search_max_trial_pts + << std::endl << NOMAD::close_block(); + } + else + out << "no model search" << std::endl; + + // model ordering: + if ( _model_params.eval_sort != NOMAD::NO_MODEL ) { + if ( _model_params.eval_sort == NOMAD::QUADRATIC_MODEL ) { + out << NOMAD::open_block ( "model ordering" ) + << "models type : " << _model_params.eval_sort + << std::endl << "cautious model ordering: "; + out.display_yes_or_no ( _model_params.eval_sort_cautious ); + out << std::endl << NOMAD::close_block(); + } + else + out << "model ordering: " << _model_params.eval_sort << std::endl; + } + else + out << "no model ordering" << std::endl; + + + if ( has_direction_type(NOMAD::ORTHO_NP1_QUAD) ) + { + out << NOMAD::open_block ( "Quad model (n+1)th dynamic direction for Ortho N+1" ) + << "models type : QUADRATIC " + << std::endl << "cautious model ordering: "; + out.display_yes_or_no ( _model_params.eval_sort_cautious ); + out << std::endl << "quad model epsilon for ortho n+1: " + << _model_params.model_np1_quad_epsilon << std::endl; + out << std::endl << NOMAD::close_block(); + } + + // quadratic model parameters: + if ( _model_params.eval_sort == NOMAD::QUADRATIC_MODEL || + _model_params.search1 == NOMAD::QUADRATIC_MODEL || + _model_params.search2 == NOMAD::QUADRATIC_MODEL ) { + out << NOMAD::open_block ( "quadratic model parameters" ) + << "radius factor: " << _model_params.quad_radius_factor << std::endl + << "use WP : "; + out.display_yes_or_no ( _model_params.quad_use_WP ); + out << std::endl << "min Y size : "; + if ( _model_params.quad_min_Y_size < 0 ) + out << "n+1"; + else + out << _model_params.quad_min_Y_size; + out << std::endl + << "max Y size : " << _model_params.quad_max_Y_size + << std::endl << NOMAD::close_block(); + } + + // TGP model parameters: + if ( _model_params.eval_sort == NOMAD::TGP_MODEL || + _model_params.search1 == NOMAD::TGP_MODEL || + _model_params.search2 == NOMAD::TGP_MODEL ) { + out << NOMAD::open_block ( "TGP model parameters" ) + << "mode : " << _model_params.tgp_mode << std::endl + << "reuse model: " << _model_params.tgp_reuse_model << std::endl + << NOMAD::close_block(); + } + out.close_block(); + } + else { + out << "use models : "; + out.display_yes_or_no ( false ); + out << std::endl; + } + } + + // SPECULATIVE_SEARCH: + out << "speculative search : "; + out.display_yes_or_no ( _speculative_search ); + out << std::endl; + + // VNS_SEARCH: + out << "VNS search : "; + out.display_yes_or_no ( _VNS_search ); + if ( _VNS_search ) + out << " [trigger=" << _VNS_trigger << "]"; + out << std::endl; + + // LH_SEARCH: + out << "Latin-Hypercube (LH) search : "; + if ( _LH_search_p0 > 0 || _LH_search_pi > 0 ) { + out << "#init:" << _LH_search_p0 + << ", #iter:" << _LH_search_pi + << ", opport:"; + out.display_yes_or_no ( _opportunistic_LH ); + } + else + out.display_yes_or_no ( false ); + out << std::endl; + + // CACHE_SEARCH: + out << "cache search : "; + if ( _cache_search ) { + out.display_yes_or_no ( true ); + out << ", opport:"; + out.display_yes_or_no ( _opportunistic_cache_search ); + } + else + out.display_yes_or_no ( false ); + out << std::endl; + + // random seed / unique tag / run id: + out << "random seed / run id : " << _seed << std::endl; + + // EPSILON: + out << "epsilon : " + << NOMAD::Double::get_epsilon() << std::endl; + + // UNDEF_STR: + out << "undefined string : " + << NOMAD::Double::get_undef_str() << std::endl; + + // INF_STR: + out << "infinity string : " + << NOMAD::Double::get_inf_str() << std::endl; + + // DISPLAY_DEGREEs: + out << NOMAD::open_block ( "display degrees" ) + << "general : " << _out.get_gen_dd() << std::endl + << "search : " << _out.get_search_dd() << std::endl + << "poll : " << _out.get_poll_dd() << std::endl + << "iterative: " << _out.get_iter_dd() << std::endl + << NOMAD::close_block(); + + // DISPLAY_STATS: + out << "display stats : "; + std::list<std::string>::const_iterator end = _display_stats.end(); + for ( it = _display_stats.begin() ; it != end ; ++it ) { + if ( it->empty() ) + out << " "; + else + out << *it; + } + out << std::endl; + + // DISPLAY_ALL_EVAL: + out << "display all evaluations : "; + out.display_yes_or_no ( _display_all_eval ); + out << std::endl; + + // POINT_DISPLAY_LIMIT: + out << "point display limit : "; + if ( NOMAD::Point::get_display_limit() > 0 ) + out << NOMAD::Point::get_display_limit() << std::endl; + else + out << "no limit" << std::endl; + + // MAX_EVAL: + if ( _max_eval > 0 ) + out << "max eval. (bb+cache) : " << _max_eval << std::endl; + + // MAX_BB_EVAL: + if ( _max_bb_eval >= 0 ) { + out << "max number of blackbox eval. : " << _max_bb_eval; + if ( _max_bb_eval == 0 ) + out << " (no blackbox eval. allowed)"; + out << std::endl; + } + + // MAX_SIM_BB_EVAL: + if ( _max_sim_bb_eval >= 0 ) + out << "max simulated blackbox eval. : " << _max_sim_bb_eval << std::endl; + + // MAX_SGTE_EVAL: + if ( _sgte_max_eval >= 0 ) { + out << "max surrogate eval. : " << _sgte_max_eval; + if ( _sgte_max_eval == 0 ) + out << " (no surrogate eval. allowed)"; + out << std::endl; + } + + // MAX_ITERATIONS: + if ( _max_iterations >= 0 ) { + out << "max iterations : " << _max_iterations; + if ( _max_iterations == 0 ) + out << " (no iterations allowed)"; + out << std::endl; + } + + // MAX_CONSECUTIVE_FAILED_ITERATIONS: + if ( _max_cons_failed_it > 0 ) + out << "max consecutive failed it. : " << _max_cons_failed_it << std::endl; + + // MAX_CACHE_MEMORY: + if ( _max_cache_memory > 0 ) + out << "max cache memory : " << _max_cache_memory + << " MB" << std::endl; + + // MAX_TIME: + if ( _max_time > 0 ) + out << "max wall-clock time : " << _max_time << "s" << std::endl; + + // F_TARGET: + if ( _f_target.is_defined() ) { + out << "objective target : "; + if ( _f_target.size() > 1 ) { + out << "( "; + _f_target.display ( out , " " , 4 , -1 ); + out << " )" << std::endl; + } + else + out << _f_target[0] << std::endl; + } + + // STAT_SUM_TARGET: + if ( _stat_sum_target.is_defined() ) + out << "stat sum target : " + << _stat_sum_target << std::endl; + + // L_CURVE_TARGET: + if ( _L_curve_target.is_defined() ) + out << "L-curve target : " + << _L_curve_target << std::endl; + + // STOP_IF_FEASIBLE: + if ( _stop_if_feasible ) { + out << "stop if feasible : "; + out.display_yes_or_no ( _stop_if_feasible ); + out << std::endl; + } } /*---------------------------------------*/ @@ -3442,8 +3537,8 @@ void NOMAD::Parameters::display ( const NOMAD::Display & out ) const /*---------------------------------------*/ void NOMAD::Parameters::reset_stats_file ( void ) { - _stats_file.clear(); - _stats_file_name.clear(); + _stats_file.clear(); + _stats_file_name.clear(); } /*---------------------------------------*/ @@ -3454,18 +3549,18 @@ void NOMAD::Parameters::reset_stats_file ( void ) void NOMAD::Parameters::reset_variable_groups ( std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & vg ) const { - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator end = vg.end() , it; - for ( it = vg.begin() ; it != end ; ++it ) - delete *it; - vg.clear(); + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator end = vg.end() , it; + for ( it = vg.begin() ; it != end ; ++it ) + delete *it; + vg.clear(); } // 2/2 (public): void NOMAD::Parameters::reset_variable_groups ( void ) { - _to_be_checked = true; - reset_variable_groups ( _var_groups ); - reset_variable_groups ( _user_var_groups ); + _to_be_checked = true; + reset_variable_groups ( _var_groups ); + reset_variable_groups ( _user_var_groups ); } /*---------------------------------------*/ @@ -3473,8 +3568,8 @@ void NOMAD::Parameters::reset_variable_groups ( void ) /*---------------------------------------*/ void NOMAD::Parameters::reset_fixed_variables ( void ) { - _to_be_checked = true; - _fixed_variables.clear(); + _to_be_checked = true; + _fixed_variables.clear(); } /*---------------------------------------*/ @@ -3482,8 +3577,8 @@ void NOMAD::Parameters::reset_fixed_variables ( void ) /*---------------------------------------*/ void NOMAD::Parameters::reset_periodic_variables ( void ) { - _to_be_checked = true; - _periodic_variables.clear(); + _to_be_checked = true; + _periodic_variables.clear(); } /*---------------------------------------*/ @@ -3491,9 +3586,9 @@ void NOMAD::Parameters::reset_periodic_variables ( void ) /*---------------------------------------*/ void NOMAD::Parameters::reset_bounds ( void ) { - _to_be_checked = true; - _lb.clear(); - _ub.clear(); + _to_be_checked = true; + _lb.clear(); + _ub.clear(); } /*---------------------------------------*/ @@ -3501,1028 +3596,1150 @@ void NOMAD::Parameters::reset_bounds ( void ) /*---------------------------------------*/ void NOMAD::Parameters::reset_scaling ( void ) { - _to_be_checked = true; - _scaling.clear(); + _to_be_checked = true; + _scaling.clear(); } /*----------------------------------------*/ /* check the parameters */ /*----------------------------------------*/ void NOMAD::Parameters::check ( bool remove_history_file , - bool remove_solution_file , - bool remove_stats_file ) -{ - if ( !_to_be_checked ) - return; - - int i; - - /*--------------------------------------------------*/ - /* display degree and NOMAD::Point::display_limit */ - /*--------------------------------------------------*/ - { - + bool remove_solution_file , + bool remove_stats_file ) +{ + if ( !_to_be_checked ) + return; + + int i; + + /*--------------------------------------------------*/ + /* display degree and NOMAD::Point::display_limit */ + /*--------------------------------------------------*/ + { + #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - _out.set_degrees ( NOMAD::NO_DISPLAY ); + if ( !NOMAD::Slave::is_master() ) + _out.set_degrees ( NOMAD::NO_DISPLAY ); #endif - + #ifdef DEBUG #ifdef USE_MPI - if ( NOMAD::Slave::is_master() ) + if ( NOMAD::Slave::is_master() ) +#endif + _out.set_degrees ( NOMAD::FULL_DISPLAY ); #endif - _out.set_degrees ( NOMAD::FULL_DISPLAY ); + + if ( _out.get_gen_dd() == NOMAD::FULL_DISPLAY ) + set_POINT_DISPLAY_LIMIT ( -1 ); + } + + /*----------------------------*/ + /* DIMENSION */ + /*----------------------------*/ + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION" ); + if ( _dimension > NOMAD::MAX_DIMENSION ) + { + std::ostringstream oss; + oss << "invalid parameter: DIMENSION (must be <= " + << NOMAD::MAX_DIMENSION << ")"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , oss.str() ); + } + + /*----------------------------*/ + /* BB_INPUT_TYPE */ + /*----------------------------*/ + if ( static_cast<int>(_bb_input_type.size()) != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + + + /*----------------------------*/ + /* BOUNDS */ + /*----------------------------*/ + { + if ( _lb.size() > _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LOWER_BOUND" ); + if ( _lb.size() < _dimension ) + _lb.resize ( _dimension ); + + if ( _ub.size() > _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: UPPER_BOUND" ); + if ( _ub.size() < _dimension ) + _ub.resize ( _dimension ); + + for ( i = 0 ; i < _dimension ; ++i ) + { + if ( _lb[i].is_defined() && _ub[i].is_defined() ) + { + if ( _lb[i] > _ub[i] ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LOWER_BOUND or UPPER_BOUND" ); + if ( _lb[i] == _ub[i] ) + set_FIXED_VARIABLE ( i , _lb[i] ); + + } + // Check that x0s are within bounds when defined + if(_lb[i].is_defined()) + { + std::vector<NOMAD::Point *>::iterator it; + for(it=_x0s.begin();it<_x0s.end();it++) + { + // Compare values only if dimension is the same + if ( (*it)->size()==_lb.size() && (**it)[i] < _lb[i] ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: x0 < LOWER_BOUND " ); + } + } + if(_ub[i].is_defined()) + { + std::vector<NOMAD::Point *>::iterator it; + for(it=_x0s.begin();it<_x0s.end();it++) + { + // Compare values only if dimension is the same + if ( (*it)->size()==_ub.size() && (**it)[i] > _ub[i] ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: x0 > UPPER_BOUND " ); + } + } + // integer, binary, and categorical variables: + if ( _bb_input_type[i] != NOMAD::CONTINUOUS ) + { + + // binary variables: + if ( _bb_input_type[i] == NOMAD::BINARY ) + { + _lb[i] = 0.0; + _ub[i] = 1.0; + } + // integer and categorical variables: + else + { + if ( _lb[i].is_defined() ) + _lb[i] = ceil(_lb[i].value()); + if ( _ub[i].is_defined() ) + _ub[i] = floor(_ub[i].value()); + } + } + } + } + + + /*----------------------------*/ + /* FIXED_VARIABLES */ + /*----------------------------*/ + if ( _fixed_variables.size() > _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE" ); + + if ( _fixed_variables.size() < _dimension ) + _fixed_variables.resize ( _dimension ); + + int nb_fixed = 0; + for ( i = 0; i < _dimension; ++i ) + if ( _fixed_variables[i].is_defined() ) + { + ++nb_fixed; + if ( (_lb[i].is_defined() && _fixed_variables[i] < _lb[i]) || + (_ub[i].is_defined() && _fixed_variables[i] > _ub[i]) || + ( (_bb_input_type[i] == NOMAD::INTEGER || + _bb_input_type[i] == NOMAD::CATEGORICAL ) + && !_fixed_variables[i].is_integer() ) || + ( _bb_input_type[i] == NOMAD::BINARY && !_fixed_variables[i].is_binary() ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE" ); + } + + if ( nb_fixed == _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE - all variables are fixed" ); + + _nb_free_variables = _dimension - nb_fixed; + + /*----------------------------*/ + /* Poll and Mesh */ + /*----------------------------*/ + { + + if ( _use_smesh && _anisotropic_mesh ) + { + _anisotropic_mesh=false; + if ( !_warning_has_been_displayed ) + _out << NOMAD::open_block("Warning:") + << "Anisotropic mesh is disabled when using smesh." << std::endl + << NOMAD::close_block(); + } + + + // mesh sizes: + if ( _initial_mesh_size.size() != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE must have same dimension as problem" ); + + // poll sizes + if ( _initial_poll_size.size() != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_POLL_SIZE must have same dimension as problem" ); + + if ( _initial_mesh_size.is_defined() && _initial_poll_size.is_defined() ) + { + if ( !_warning_has_been_displayed ) + _out << NOMAD::open_block("Warning:") + << "Initial mesh size and initial poll size are provided. Only the initial poll size will be considered." << std::endl + << NOMAD::close_block(); + _initial_mesh_size.clear(); + _initial_mesh_size.reset ( _dimension ); + } + + + // initial mesh size or poll size: + // -------------------------------- + bool use_x0 = !_x0s.empty() && _x0s[0]->size() == _dimension; + for ( i = 0 ; i < _dimension ; ++i ) + { + + // continuous variables: + // --------------------- + if ( _bb_input_type[i] == NOMAD::CONTINUOUS ) + { + + // Determine _initial_mesh_size from _initial_poll_size (this will disappear in future version) + if ( _initial_mesh_size[i].is_defined() ) + _initial_poll_size[i]=_initial_mesh_size[i]*pow(_dimension,0.5); + + // default value for initial mesh size + if ( !_initial_poll_size[i].is_defined() ) + { + + if (_lb[i].is_defined() && _ub[i].is_defined()) + { + set_INITIAL_POLL_SIZE ( i , 0.1 , true ); + if ( _lb[i] == _ub[i] ) + set_INITIAL_POLL_SIZE (i, 1 ,false); + + } + else if ( _lb[i].is_defined() && use_x0 && (*_x0s[0])[i].is_defined() && _lb[i]!=(*_x0s[0])[i]) + { + _initial_poll_size[i] = ((*_x0s[0])[i]-_lb[i])/10.0; // Case x0 < lb tested elsewhere + } + else if ( _ub[i].is_defined()&& use_x0 && (*_x0s[0])[i].is_defined() && _ub[i]!=(*_x0s[0])[i]) + { + _initial_poll_size[i] = (_ub[i]-(*_x0s[0])[i])/10.0; // Case x0 > ub tested elsewhere + } + else + { + if ( use_x0 && (*_x0s[0])[i].is_defined() && (*_x0s[0])[i].abs() > NOMAD::Double::get_epsilon()*10.0 ) + _initial_poll_size[i] = (*_x0s[0])[i].abs()/10.0; + else + { + _initial_poll_size[i] = 1.0; + + if (_out.get_gen_dd()>=NOMAD::NORMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Initial mesh size for variable " << i << " has been arbitrarily fixed to 1." << std::endl + << " In the absence of bounds and initial values different than zero," << std::endl + << " it is recommended to explicitely provide this parameter." << std::endl + << NOMAD::close_block(); + } + } + } + else if ( !_fixed_variables[i].is_defined() && + ( _initial_poll_size[i].value() < NOMAD::Double::get_epsilon() || + _initial_poll_size[i].value() <= 0.0 ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE" ); + } + // binary/categorical variables: + // ----------------------------- + else if ( _bb_input_type[i] == NOMAD::BINARY || + _bb_input_type[i] == NOMAD::CATEGORICAL ) + { + // mesh and poll sizes not used for binary and categorical + // but set to prevent warning when creating signature + _initial_mesh_size[i] = 1.0; + _initial_poll_size[i] = 1.0; + } + // integer variables: + // ------------------ + else + { + // Determine mesh size from poll size + if ( _initial_poll_size[i].is_defined() ) + _initial_mesh_size[i]=_initial_poll_size[i]*pow(_dimension,-0.5); + + + if ( _initial_mesh_size[i].is_defined() ) + { + _initial_mesh_size[i]=_initial_mesh_size[i].round(); + if ( _initial_mesh_size[i] < 1.0 ) + _initial_mesh_size[i] = 1.0; + + } + else // that is no initial_mesh_size and no initial_poll_size + { + + // default value for initial mesh size + // (r0.1 if there are bounds + rounding to nearest integer not zero, 1.0 otherwise): + if ( !_lb[i].is_defined() || !_ub[i].is_defined() ) + _initial_mesh_size[i] = 1.0; + else + { + set_INITIAL_POLL_SIZE ( i , 0.1 , true ); + _initial_mesh_size[i]=_initial_poll_size[i]*pow(_dimension,-0.5); + _initial_mesh_size[i]=_initial_mesh_size[i].round(); + if ( _initial_mesh_size[i] < 1.0 ) + _initial_mesh_size[i] = 1.0; + + } + } + _initial_poll_size[i]=_initial_mesh_size[i]*pow(_dimension,0.5); + + } + // Determine _initial_mesh_size from _initial_poll_size (this will disappear in future version) + if ( !_initial_mesh_size[i].is_defined() ) + _initial_mesh_size[i]=_initial_poll_size[i]*pow(_dimension,-0.5); + + } + + // min mesh size \delta_min: + if ( _min_mesh_size.is_defined() ) + { + + if ( _min_mesh_size.size() != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE" ); + + for ( i = 0 ; i < _dimension ; ++i ) + if ( _min_mesh_size[i].is_defined() && + (_min_mesh_size[i].value() < NOMAD::Double::get_epsilon() || + _min_mesh_size[i].value() <= 0.0 ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameters: MIN_MESH_SIZE" ); + } + + // min poll size \Delta^p_min: + if ( _min_poll_size.is_defined() ) + { + + _min_poll_size_defined = true; + + if ( _min_poll_size.size() != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_POLL_SIZE" ); + + for ( i = 0 ; i < _dimension ; ++i ) + { + // continuous variables: + if ( _bb_input_type[i] == NOMAD::CONTINUOUS ) + { + if ( _min_poll_size[i].is_defined() && + (_min_poll_size[i].value() < NOMAD::Double::get_epsilon() || + _min_poll_size[i].value() <= 0.0 ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameters: MIN_POLL_SIZE" ); + } + + // integer and binary variables: + else if ( _bb_input_type[i] != NOMAD::CATEGORICAL ) + { + if ( _min_poll_size[i].is_defined() ) + { + if ( _min_poll_size[i] < 1.0 ) + _min_poll_size[i] = 1.0; + } + else + _min_poll_size[i] = 1.0; + } + } + } + + // default min poll size for non-continuous variables: + else + { + + _min_poll_size_defined = false; + + _min_poll_size = NOMAD::Point ( _dimension ); + for ( i = 0 ; i < _dimension ; ++i ) + if ( _bb_input_type[i] == NOMAD::INTEGER ) + _min_poll_size[i] = 1.0; + } + + // default value for _mesh_update_basis (tau): + if ( _mesh_update_basis <= 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameters: MESH_UPDATE_BASIS (must be >1)" ); + + if ( _poll_update_basis <= 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameters: POLL_UPDATE_BASIS (must be >1)" ); + } + + + int nb_obj = static_cast<int>(_index_obj.size()); + + /*----------------------------*/ + /* DISPLAY_STATS */ + /*----------------------------*/ + if ( _display_stats.empty() ) + { + std::list<std::string> ls; + if ( nb_obj == 1 ) + { + ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_BBE ) ); + ls.push_back ( std::string() ); + } + ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_OBJ ) ); + set_DISPLAY_STATS ( ls ); + } + + else if ( !check_display_stats ( _display_stats ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DISPLAY_STATS" ); + + /*----------------------------*/ + /* STATS_FILE */ + /*----------------------------*/ + if ( !_stats_file_name.empty() ) + { + if ( _stats_file.empty() ) + { + std::list<std::string> ls; + ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_BBE ) ); + ls.push_back ( std::string() ); + ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_OBJ ) ); + set_STATS_FILE ( _stats_file_name , ls ); + } + else if ( !check_display_stats ( _stats_file ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STATS_FILE" ); + } + + /*----------------------------*/ + /* SCALING */ + /*----------------------------*/ + if ( _scaling.size() > _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SCALING" ); + + if ( _scaling.size() < _dimension ) + _scaling.resize ( _dimension ); + + for ( i = 0; i < _dimension; ++i ) + if ( _scaling[i].is_defined() && _scaling[i] == 0.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SCALING (zero value)" ); + + /*---------------------------*/ + /* blackbox outputs */ + /*---------------------------*/ + if ( _bb_output_type.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE" ); + if ( _bb_output_type.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE - undefined" ); + + size_t m = _bb_output_type.size(); + + if ( !_bb_exe.empty() && m != _bb_exe.size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE: wrong number of blackbox executable names" ); + + // surrogate: + if ( !_sgte_exe.empty() ) + { + + _has_sgte = true; + + if ( _bb_exe.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EXE - no BB_EXE is defined" ); + + std::map<std::string,std::string>::const_iterator it; + std::map<std::string,std::string>::const_iterator end = _sgte_exe.end(); + std::list<std::string>::const_iterator bb_exe_begin = _bb_exe.begin(); + std::list<std::string>::const_iterator bb_exe_end = _bb_exe.end(); + + // an empty string in _sgte_exe means that there is a unique + // blackbox with the associated surrogate + // (SGTE_EXE parameter with only one argument): + it = _sgte_exe.find(""); + if ( it != end ) { + if ( _sgte_exe.size() != 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EXE - impossible to interpret with one argument" ); + + std::string bb_exe_name = *bb_exe_begin; + std::list<std::string>::const_iterator it2 = ++bb_exe_begin; + while ( it2 != bb_exe_end ) { + if ( *it2 != bb_exe_name ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: unique SGTE_EXE without unique blackbox executable" ); + ++it2; + } + + std::string sgte_name = it->second; + + _sgte_exe.clear(); + _sgte_exe[bb_exe_name] = sgte_name; + } + else + for ( it = _sgte_exe.begin() ; it != end ; ++it ) + if ( find ( bb_exe_begin , bb_exe_end , it->first ) == bb_exe_end ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_EXE" ); + } + else if ( !_has_sgte ) + { + _sgte_eval_sort = false; + _sgte_cost = -1; + + if ( _opt_only_sgte ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: OPT_ONLY_SGTE" ); + } + + if ( _opt_only_sgte ) + _sgte_eval_sort = false; + + size_t k; + + // CNT_EVAL, _STAT_SUM_ and _STAT_AVG_ checks (each one have to be unique): + _index_cnt_eval = _index_stat_sum = _index_stat_avg = -1; + for ( k = 0 ; k < m ; ++k ) + { + if ( _bb_output_type[k] == NOMAD::STAT_SUM ) + { + if ( _index_stat_sum >= 0 ) + { + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE: more than one STAT_SUM output" ); + } + _index_stat_sum = static_cast<int>(k); + } + else if ( _bb_output_type[k] == NOMAD::STAT_AVG ) + { + if ( _index_stat_avg >= 0 ) + { + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE: more than one STAT_AVG output" ); + } + _index_stat_avg = static_cast<int>(k); + } + else if ( _bb_output_type[k] == NOMAD::CNT_EVAL ) + { + if ( _index_cnt_eval >= 0 ) + { + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE: more than one CNT_EVAL output" ); + } + _index_cnt_eval = static_cast<int>(k); + } + } + + // F_TARGET: + if ( _f_target.is_defined() && nb_obj != _f_target.size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: F_TARGET of bad dimension" ); + + /*----------------------------*/ + /* directions */ + /*----------------------------*/ + bool use_ortho_mads = false; + + { + bool use_mads = false; + bool use_ortho_mads_only = true; + std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); + + // default value for primary poll directions: + if ( _direction_types.empty() ) + { + set_DIRECTION_TYPE ( NOMAD::ORTHO_NP1_QUAD ); // Default setting that maybe changed if models are disabled + use_mads = true; + use_ortho_mads = true; + use_ortho_mads_only = true; // OrthoMads (2n or n+1) not mixed with LT or GPS + } + else + for ( it = _direction_types.begin() ; it != end ; ++it ) + { + if ( NOMAD::dir_is_mads ( *it ) ) + use_mads = true; + if ( NOMAD::dir_is_orthomads ( *it ) ) + use_ortho_mads = true; + if ( ! NOMAD::dir_is_orthomads ( *it ) ) + use_ortho_mads_only = false; + + } + + if ( ! use_ortho_mads_only && _anisotropic_mesh ) + { + _anisotropic_mesh=false; + if ( !_warning_has_been_displayed ) + _out << NOMAD::open_block("Warning:") + << "Anisotropic mesh is disabled for direction types other than OrthoMads." << std::endl + << NOMAD::close_block(); + } + + + + + // default value for secondary poll directions: + if ( _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P ) + { + + if ( _sec_poll_dir_types.empty() ) + { + if ( use_mads ) + { + if ( _direction_types.size() == 1 ) + { + NOMAD::direction_type dt = *(_direction_types.begin()); + if ( dt == NOMAD::ORTHO_1 || dt == NOMAD::ORTHO_2 ) + set_SEC_POLL_DIR_TYPE ( NOMAD::ORTHO_1 ); + else if ( dt == NOMAD::LT_1 || dt == NOMAD::LT_2 ) + set_SEC_POLL_DIR_TYPE ( NOMAD::LT_1 ); + else + set_SEC_POLL_DIR_TYPE ( (use_ortho_mads) ? NOMAD::ORTHO_2 : NOMAD::LT_2 ); + } + else + set_SEC_POLL_DIR_TYPE ( (use_ortho_mads) ? NOMAD::ORTHO_2 : NOMAD::LT_2 ); + } + else + set_SEC_POLL_DIR_TYPE ( NOMAD::GPS_NP1_STATIC ); + } + + else + { + bool old_uom = use_ortho_mads; + bool old_um = use_mads; + end = _sec_poll_dir_types.end(); + for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) + { + if ( *it == NOMAD::NO_DIRECTION ) + { + _sec_poll_dir_types.clear(); + use_ortho_mads = old_uom; + use_mads = old_um; + break; + } + if ( NOMAD::dir_is_orthomads (*it) ) + use_ortho_mads = true; + if ( NOMAD::dir_is_mads ( *it ) ) + use_mads = true; + } + } + } + else + _sec_poll_dir_types.clear(); + + /*----------------------------*/ + /* SPECULATIVE_SEARCH */ + /*----------------------------*/ + if ( !use_mads ) + _speculative_search = false; + } + + /*----------------------------*/ + /* periodic variables */ + /*----------------------------*/ + if ( !_periodic_variables.empty() ) { + + // check the size: + if ( _dimension != static_cast<int>(_periodic_variables.size()) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE - bad size" ); + + // check the bounds: + for ( int k = 0 ; k < _dimension ; ++k ) + if ( _periodic_variables[k] ) { + if ( !_lb[k].is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE - lower bound not defined" ); + if ( !_ub[k].is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE - upper bound not defined" ); + } + } + + + /*---------------------------*/ + /* model parameters */ + /*---------------------------*/ + { + + // disable models upon request + if ( _disable_models) + { + _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + { + _out << NOMAD::open_block("Warning:") + << "Model use is forcefully disabled." << std::endl + << NOMAD::close_block(); + + if (has_direction_type(NOMAD::ORTHO_NP1_QUAD)) + { + _out << NOMAD::open_block("Warning:") + << "Model use is disabled for direction type. Direction types ORTHO N+1 QUAD are changed to ORTHO N+1 NEG." << std::endl + << NOMAD::close_block(); + } + } + set_DIRECTION_TYPE_NO_MODEL(); + + } + + // disable models when requested or for more than 50 variables, + // for categorical variables and for surrogate optimization: + bool has_categorical=false; + bool has_binary=false; + for ( i = 0 ; i < _dimension ; ++i ) + { + if ( !_fixed_variables[i].is_defined() && _bb_input_type[i] == NOMAD::CATEGORICAL ) + { + has_categorical=true; + } + if ( !_fixed_variables[i].is_defined() && _bb_input_type[i] == NOMAD::BINARY ) + { + has_binary=true; + } + } + + if ( _nb_free_variables >= 50 || has_categorical || _opt_only_sgte ) + { + _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; + set_DIRECTION_TYPE_NO_MODEL(); + + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + { + if ( _opt_only_sgte) + _out << NOMAD::open_block("Warning:") + << "Model use is disabled when setting the option OPT_ONLY_SGTE to yes." << std::endl; + if ( has_categorical) + _out << NOMAD::open_block("Warning:") + << "Model use is disabled for problem with categorical variables." << std::endl + << NOMAD::close_block(); + if ( _nb_free_variables >= 50) + _out << NOMAD::open_block("Warning:") + << "Model use is disabled for problem with dimension greater than 50." << std::endl + << NOMAD::close_block(); + } + } + + + // disable PEB constraints when categorical variables are present + if ( has_categorical && _barrier_type == NOMAD::PEB_P) + { + + change_PEB_to_PB(); + + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "PEB constraints are disabled when using categorical variables. To continue, PEB constraints have been replaced by PB constraints." << std::endl + << NOMAD::close_block(); + + } + + if ( ( has_categorical || has_binary ) && _anisotropic_mesh ) + { + _anisotropic_mesh=false; + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Default anisotropic mesh is disabled with categorical and binary variables." << std::endl + << NOMAD::close_block(); + + } + + // disable model use in parallel mode: +#ifdef USE_MPI + _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; + set_DIRECTION_TYPE_NO_MODEL(); + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Model use is disabled in parallel mode (MPI)." << std::endl + << NOMAD::close_block(); + + + if ((has_direction_type(NOMAD::ORTHO_NP1_QUAD) || has_direction_type(NOMAD::ORTHO_NP1_NEG)) && _asynchronous) + { + set_ASYNCHRONOUS(false); + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Asynchronous mode is disabled in parallel mode (MPI) when dynamic directions (ortho n+1) are used." << std::endl + << NOMAD::close_block(); + } #endif - - if ( _out.get_gen_dd() == NOMAD::FULL_DISPLAY ) - set_POINT_DISPLAY_LIMIT ( -1 ); - } - - /*----------------------------*/ - /* DIMENSION */ - /*----------------------------*/ - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION" ); - if ( _dimension > NOMAD::MAX_DIMENSION ) - { - std::ostringstream oss; - oss << "invalid parameter: DIMENSION (must be <= " - << NOMAD::MAX_DIMENSION << ")"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , oss.str() ); - } - - /*----------------------------*/ - /* BB_INPUT_TYPE */ - /*----------------------------*/ - if ( static_cast<int>(_bb_input_type.size()) != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - - /*----------------------------*/ - /* BOUNDS */ - /*----------------------------*/ - { - if ( _lb.size() > _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LOWER_BOUND" ); - if ( _lb.size() < _dimension ) - _lb.resize ( _dimension ); - - if ( _ub.size() > _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: UPPER_BOUND" ); - if ( _ub.size() < _dimension ) - _ub.resize ( _dimension ); - - for ( i = 0 ; i < _dimension ; ++i ) - { - if ( _lb[i].is_defined() && _ub[i].is_defined() ) - { - if ( _lb[i] > _ub[i] ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LOWER_BOUND or UPPER_BOUND" ); - if ( _lb[i] == _ub[i] ) - set_FIXED_VARIABLE ( i , _lb[i] ); - - } - // Check that x0s are within bounds when defined - if(_lb[i].is_defined()) - { - std::vector<NOMAD::Point *>::iterator it; - for(it=_x0s.begin();it<_x0s.end();it++) - { - // Compare values only if dimension is the same - if ( (*it)->size()==_lb.size() && (**it)[i] < _lb[i] ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: x0 < LOWER_BOUND " ); - } - } - if(_ub[i].is_defined()) - { - std::vector<NOMAD::Point *>::iterator it; - for(it=_x0s.begin();it<_x0s.end();it++) - { - // Compare values only if dimension is the same - if ( (*it)->size()==_ub.size() && (**it)[i] > _ub[i] ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: x0 > UPPER_BOUND " ); - } - } - // integer, binary, and categorical variables: - if ( _bb_input_type[i] != NOMAD::CONTINUOUS ) - { - - // binary variables: - if ( _bb_input_type[i] == NOMAD::BINARY ) - { - _lb[i] = 0.0; - _ub[i] = 1.0; - } - // integer and categorical variables: - else - { - if ( _lb[i].is_defined() ) - _lb[i] = ceil(_lb[i].value()); - if ( _ub[i].is_defined() ) - _ub[i] = floor(_ub[i].value()); - } - } - } - } - - - - /*----------------------------*/ - /* FIXED_VARIABLES */ - /*----------------------------*/ - if ( _fixed_variables.size() > _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE" ); - - if ( _fixed_variables.size() < _dimension ) - _fixed_variables.resize ( _dimension ); - - int nb_fixed = 0; - for ( i = 0; i < _dimension; ++i ) - if ( _fixed_variables[i].is_defined() ) { - ++nb_fixed; - if ( (_lb[i].is_defined() && _fixed_variables[i] < _lb[i]) || - (_ub[i].is_defined() && _fixed_variables[i] > _ub[i]) || - ( (_bb_input_type[i] == NOMAD::INTEGER || - _bb_input_type[i] == NOMAD::CATEGORICAL ) - && !_fixed_variables[i].is_integer() ) || - ( _bb_input_type[i] == NOMAD::BINARY && !_fixed_variables[i].is_binary() ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE" ); - } - - if ( nb_fixed == _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE - all variables are fixed" ); - - _nb_free_variables = _dimension - nb_fixed; - - /*----------------------------*/ - /* Mesh */ - /*----------------------------*/ - { - // mesh sizes: - - - if ( _initial_mesh_size.size() != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE must have same dimension as problem" ); - - // initial mesh size: - // ------------------ - bool use_x0 = !_x0s.empty() && _x0s[0]->size() == _dimension; - - for ( i = 0 ; i < _dimension ; ++i ) - { - - // continuous variables: - // --------------------- - if ( _bb_input_type[i] == NOMAD::CONTINUOUS ) - { - // default value for initial mesh size - if ( !_initial_mesh_size[i].is_defined() ) - { - - if (_lb[i].is_defined() && _ub[i].is_defined()) - set_INITIAL_MESH_SIZE ( i , 0.1 , true ); - else if ( _lb[i].is_defined() && use_x0 && (*_x0s[0])[i].is_defined() && _lb[i]!=(*_x0s[0])[i]) - { - _initial_mesh_size[i] = (*_x0s[0])[i]-_lb[i]; // Case x0 < lb tested elsewhere - } - else if ( _ub[i].is_defined()&& use_x0 && (*_x0s[0])[i].is_defined() && _ub[i]!=(*_x0s[0])[i]) - { - _initial_mesh_size[i] = _ub[i]-(*_x0s[0])[i]; // Case x0 > ub tested elsewhere - } - else - { - if ( use_x0 && (*_x0s[0])[i].is_defined() && (*_x0s[0])[i].abs() > 1.0 ) - _initial_mesh_size[i] = (*_x0s[0])[i].abs(); - else - _initial_mesh_size[i] = 1.0; - - if (_initial_mesh_size[i] == 1.0 && _out.get_gen_dd()>=NOMAD::NORMAL_DISPLAY && !_warning_has_been_displayed) - _out << NOMAD::open_block("Warning:") - << "Initial mesh size for variable " << i << " has been arbitrarily fixed to 1." << std::endl - << " In the absence of bounds and initial values different than zero," << std::endl - << " it is recommended to explicitely provide this parameter." << std::endl - << NOMAD::close_block(); - } - } - - else if ( !_fixed_variables[i].is_defined() && - ( _initial_mesh_size[i].value() < NOMAD::Double::get_epsilon() || - _initial_mesh_size[i].value() <= 0.0 ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE" ); - } - - // binary/categorical variables: - // ----------------------------- - else if ( _bb_input_type[i] == NOMAD::BINARY || - _bb_input_type[i] == NOMAD::CATEGORICAL ) - { - _initial_mesh_size[i] = 1.0; - } - - // integer variables: - // ------------------ - else - { - - if ( _initial_mesh_size[i].is_defined() ) - { - _initial_mesh_size[i]=_initial_mesh_size[i].round(); - if ( _initial_mesh_size[i] < 1.0 ) - _initial_mesh_size[i] = 1.0; - } - else - { - - // default value for initial mesh size - // (r0.1 if there are bounds + rounding to nearest integer not zero, 1.0 otherwise): - if ( !_lb[i].is_defined() || !_ub[i].is_defined() ) - _initial_mesh_size[i] = 1.0; - else - { - set_INITIAL_MESH_SIZE ( i , 0.1 , true ); - _initial_mesh_size[i]=_initial_mesh_size[i].round(); - if ( _initial_mesh_size[i] < 1.0 ) - _initial_mesh_size[i] = 1.0; - } - } - } - } - - // min mesh size \Delta^m_min: - if ( _min_mesh_size.is_defined() ) - { - - if ( _min_mesh_size.size() != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE" ); - - for ( i = 0 ; i < _dimension ; ++i ) - if ( _min_mesh_size[i].is_defined() && - (_min_mesh_size[i].value() < NOMAD::Double::get_epsilon() || - _min_mesh_size[i].value() <= 0.0 ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameters: MIN_MESH_SIZE" ); - } - - // min poll size \Delta^p_min: - if ( _min_poll_size.is_defined() ) - { - - _min_poll_size_defined = true; - - if ( _min_poll_size.size() != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_POLL_SIZE" ); - - for ( i = 0 ; i < _dimension ; ++i ) - { - // continuous variables: - if ( _bb_input_type[i] == NOMAD::CONTINUOUS ) - { - if ( _min_poll_size[i].is_defined() && - (_min_poll_size[i].value() < NOMAD::Double::get_epsilon() || - _min_poll_size[i].value() <= 0.0 ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameters: MIN_POLL_SIZE" ); - } - - // integer and binary variables: - else if ( _bb_input_type[i] != NOMAD::CATEGORICAL ) - { - if ( _min_poll_size[i].is_defined() ) - { - if ( _min_poll_size[i] < 1.0 ) - _min_poll_size[i] = 1.0; - } - else - _min_poll_size[i] = 1.0; - } - } - } - - // default min poll size for non-continuous variables: - else - { - - _min_poll_size_defined = false; - - _min_poll_size = NOMAD::Point ( _dimension ); - for ( i = 0 ; i < _dimension ; ++i ) - if ( _bb_input_type[i] != NOMAD::CONTINUOUS && - _bb_input_type[i] != NOMAD::CATEGORICAL ) - _min_poll_size[i] = 1.0; - } - - // default value for _mesh_update_basis (tau): - if ( !_mesh_update_basis.is_defined() ) - _mesh_update_basis = 4.0; - else if ( _mesh_update_basis <= 0.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameters: MESH_UPDATE_BASIS" ); - - // compare l0 and lmax: - if ( _max_mesh_index != NOMAD::UNDEFINED_L && _initial_mesh_index > _max_mesh_index ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameters: MAX_MESH_INDEX or INITIAL_MESH_INDEX" ); - } - - int nb_obj = static_cast<int>(_index_obj.size()); - - /*----------------------------*/ - /* DISPLAY_STATS */ - /*----------------------------*/ - if ( _display_stats.empty() ) { - std::list<std::string> ls; - if ( nb_obj == 1 ) { - ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_BBE ) ); - ls.push_back ( std::string() ); - } - ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_OBJ ) ); - set_DISPLAY_STATS ( ls ); - } - - else if ( !check_display_stats ( _display_stats ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DISPLAY_STATS" ); - - /*----------------------------*/ - /* STATS_FILE */ - /*----------------------------*/ - if ( !_stats_file_name.empty() ) { - if ( _stats_file.empty() ) { - std::list<std::string> ls; - ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_BBE ) ); - ls.push_back ( std::string() ); - ls.push_back ( NOMAD::Display::get_display_stats_keyword ( NOMAD::DS_OBJ ) ); - set_STATS_FILE ( _stats_file_name , ls ); - } - else if ( !check_display_stats ( _stats_file ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STATS_FILE" ); - } - - /*----------------------------*/ - /* SCALING */ - /*----------------------------*/ - if ( _scaling.size() > _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SCALING" ); - - if ( _scaling.size() < _dimension ) - _scaling.resize ( _dimension ); - - for ( i = 0; i < _dimension; ++i ) - if ( _scaling[i].is_defined() && _scaling[i] == 0.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SCALING (zero value)" ); - - /*---------------------------*/ - /* blackbox outputs */ - /*---------------------------*/ - if ( _bb_output_type.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE" ); - if ( _bb_output_type.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE - undefined" ); - - size_t m = _bb_output_type.size(); - - if ( !_bb_exe.empty() && m != _bb_exe.size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE: wrong number of blackbox executable names" ); - - // surrogate: - if ( !_sgte_exe.empty() ) - { - - _has_sgte = true; - - if ( _bb_exe.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EXE - no BB_EXE is defined" ); - - std::map<std::string,std::string>::const_iterator it; - std::map<std::string,std::string>::const_iterator end = _sgte_exe.end(); - std::list<std::string>::const_iterator bb_exe_begin = _bb_exe.begin(); - std::list<std::string>::const_iterator bb_exe_end = _bb_exe.end(); - - // an empty string in _sgte_exe means that there is a unique - // blackbox with the associated surrogate - // (SGTE_EXE parameter with only one argument): - it = _sgte_exe.find(""); - if ( it != end ) { - if ( _sgte_exe.size() != 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EXE - impossible to interpret with one argument" ); - - std::string bb_exe_name = *bb_exe_begin; - std::list<std::string>::const_iterator it2 = ++bb_exe_begin; - while ( it2 != bb_exe_end ) { - if ( *it2 != bb_exe_name ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: unique SGTE_EXE without unique blackbox executable" ); - ++it2; - } - - std::string sgte_name = it->second; - - _sgte_exe.clear(); - _sgte_exe[bb_exe_name] = sgte_name; - } - else - for ( it = _sgte_exe.begin() ; it != end ; ++it ) - if ( find ( bb_exe_begin , bb_exe_end , it->first ) == bb_exe_end ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_EXE" ); - } - else if ( !_has_sgte ) - { - _sgte_eval_sort = false; - _sgte_cost = -1; - - if ( _opt_only_sgte ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: OPT_ONLY_SGTE" ); - } - - if ( _opt_only_sgte ) - _sgte_eval_sort = false; - - size_t k; - - // _STAT_SUM_ and _STAT_AVG_ checks (each one have to be unique): - _index_stat_sum = _index_stat_avg = -1; - for ( k = 0 ; k < m ; ++k ) { - if ( _bb_output_type[k] == NOMAD::STAT_SUM ) { - if ( _index_stat_sum >= 0 ) { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE: more than one STAT_SUM output" ); - } - _index_stat_sum = static_cast<int>(k); - } - else if ( _bb_output_type[k] == NOMAD::STAT_AVG ) { - if ( _index_stat_avg >= 0 ) { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE: more than one STAT_AVG output" ); - } - _index_stat_avg = static_cast<int>(k); - } - else if ( _bb_output_type[k] == NOMAD::CNT_EVAL ) { - if ( _index_cnt_eval >= 0 ) { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE: more than one CNT_EVAL output" ); - } - _index_cnt_eval = static_cast<int>(k); - } - } - - // F_TARGET: - if ( _f_target.is_defined() && nb_obj != _f_target.size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: F_TARGET of bad dimension" ); - - /*----------------------------*/ - /* directions */ - /*----------------------------*/ - bool use_ortho_mads = false; - - { - bool use_mads = false; - std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); - - // default value for primary poll directions: - if ( _direction_types.empty() ) - { - set_DIRECTION_TYPE ( NOMAD::ORTHO_NP1_QUAD ); // Default setting that maybe changed if models are disabled - use_mads = true; - use_ortho_mads = true; - } - else - for ( it = _direction_types.begin() ; it != end ; ++it ) - { - if ( NOMAD::dir_is_mads ( *it ) ) - use_mads = true; - if ( NOMAD::dir_is_orthomads ( *it ) ) - use_ortho_mads = true; - } - - // default value for secondary poll directions: - if ( _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P ) - { - - if ( _sec_poll_dir_types.empty() ) - { - if ( use_mads ) { - if ( _direction_types.size() == 1 ) - { - NOMAD::direction_type dt = *(_direction_types.begin()); - if ( dt == NOMAD::ORTHO_1 || dt == NOMAD::ORTHO_2 ) - set_SEC_POLL_DIR_TYPE ( NOMAD::ORTHO_1 ); - else if ( dt == NOMAD::LT_1 || dt == NOMAD::LT_2 ) - set_SEC_POLL_DIR_TYPE ( NOMAD::LT_1 ); - else - set_SEC_POLL_DIR_TYPE ( (use_ortho_mads) ? NOMAD::ORTHO_2 : NOMAD::LT_2 ); - } - else - set_SEC_POLL_DIR_TYPE ( (use_ortho_mads) ? NOMAD::ORTHO_2 : NOMAD::LT_2 ); - } - else - set_SEC_POLL_DIR_TYPE ( NOMAD::GPS_NP1_STATIC ); - } - - else { - bool old_uom = use_ortho_mads; - bool old_um = use_mads; - end = _sec_poll_dir_types.end(); - for ( it = _sec_poll_dir_types.begin() ; it != end ; ++it ) { - if ( *it == NOMAD::NO_DIRECTION ) { - _sec_poll_dir_types.clear(); - use_ortho_mads = old_uom; - use_mads = old_um; - break; - } - if ( NOMAD::dir_is_orthomads (*it) ) - use_ortho_mads = true; - if ( NOMAD::dir_is_mads ( *it ) ) - use_mads = true; - } - } - } - else - _sec_poll_dir_types.clear(); - - /*----------------------------*/ - /* SPECULATIVE_SEARCH */ - /*----------------------------*/ - if ( !use_mads ) - _speculative_search = false; - } - - /*----------------------------*/ - /* periodic variables */ - /*----------------------------*/ - if ( !_periodic_variables.empty() ) { - - // check the size: - if ( _dimension != static_cast<int>(_periodic_variables.size()) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE - bad size" ); - - // check the bounds: - for ( int k = 0 ; k < _dimension ; ++k ) - if ( _periodic_variables[k] ) { - if ( !_lb[k].is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE - lower bound not defined" ); - if ( !_ub[k].is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE - upper bound not defined" ); - } - } - - - /*---------------------------*/ - /* model parameters */ - /*---------------------------*/ - { - - // disable models upon request - if ( _disable_models) - { - _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; - if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) - { - _out << NOMAD::open_block("Warning:") - << "Model use is forcefully disabled." << std::endl - << NOMAD::close_block(); - - if (has_direction_type(NOMAD::ORTHO_NP1_QUAD)) - { - _out << NOMAD::open_block("Warning:") - << "Model use is disabled for direction type. Direction types ORTHO N+1 QUAD are changed to ORTHO N+1 NEG." << std::endl - << NOMAD::close_block(); - } - } - set_DIRECTION_TYPE_NO_MODEL(); - - } - - // disable models when requested or for more than 50 variables, - // for categorical variables and for surrogate optimization: - bool has_categorical=false; - for ( i = 0 ; i < _dimension ; ++i ) - { - if ( !_fixed_variables[i].is_defined() && _bb_input_type[i] == NOMAD::CATEGORICAL ) - { - has_categorical=true; - break; - } - } - - if ( _nb_free_variables >= 50 || has_categorical || _opt_only_sgte ) - { - _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; - set_DIRECTION_TYPE_NO_MODEL(); - - if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) - { - if ( _opt_only_sgte) - _out << NOMAD::open_block("Warning:") - << "Model use is disabled when setting the option OPT_ONLY_SGTE to yes." << std::endl; - if ( has_categorical) - _out << NOMAD::open_block("Warning:") - << "Model use is disabled for problem with categorical variables." << std::endl - << NOMAD::close_block(); - if ( _nb_free_variables >= 50) - _out << NOMAD::open_block("Warning:") - << "Model use is disabled for problem with dimension greater than 50." << std::endl - << NOMAD::close_block(); - } - } - - // disable PEB constraints when categorical variables are present - if ( has_categorical && _barrier_type == NOMAD::PEB_P) - { - - change_PEB_to_PB(); - - if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) - _out << NOMAD::open_block("Warning:") - << "PEB constraints are disabled when using categorical variables. PEB constraints have been replaced by PB constraints." << std::endl - << NOMAD::close_block(); - - } - - - // disable model use in parallel mode: + + // other checks: + if ( ( _model_params.search1 == NOMAD::NO_MODEL && + _model_params.search2 != NOMAD::NO_MODEL ) || + ( _model_params.search1 != NOMAD::NO_MODEL && + _model_params.search1 == _model_params.search2 ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH (conflict with the two types of search)" ); + + if ( _model_params.quad_radius_factor <= 0.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_RADIUS_FACTOR (must be > 0)" ); + + if ( _model_params.quad_min_Y_size < 0 ) + _model_params.quad_min_Y_size = -1; + else if ( _model_params.quad_min_Y_size < 2 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_QUAD_MIN_Y_SIZE (must be in {'N+1',-1,2,3,...})" ); + + if ( _model_params.model_np1_quad_epsilon <= 0.0 || _model_params.model_np1_quad_epsilon >= 1.0) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_NP1_QUAD_EPSILON (must be > 0 and < 1)" ); + + if ( _model_params.quad_max_Y_size <= _nb_free_variables ) + _model_params.quad_max_Y_size = _nb_free_variables + 1; + + if ( _model_params.search_max_trial_pts < 1 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS (must be >= 1)" ); + } + + /*----------------------------*/ + /* EVAL SORT */ + /*----------------------------*/ + if (_disable_eval_sort) + { + + _model_params.eval_sort = NOMAD::NO_MODEL; + _sgte_eval_sort = false; + NOMAD::Priority_Eval_Point::set_lexicographic_order(true); + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Eval sort is forcefully disabled (using models, surrogates, user eval priority, etc.). Only lexicographic order is used." << std::endl + << NOMAD::close_block(); + + } + else + NOMAD::Priority_Eval_Point::set_lexicographic_order(false); + + + /*----------------------------*/ + /* variable groups */ + /*----------------------------*/ + { + + // reset variable groups: + reset_variable_groups ( _var_groups ); + + std::vector<bool> in_group ( _dimension ); + for ( i = 0 ; i < _dimension ; ++i ) + in_group[i] = false; + + NOMAD::Variable_Group * vg; + std::set<NOMAD::direction_type> direction_types , sec_poll_dir_types; + + // 1. user groups: + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator + end = _user_var_groups.end() , it; + + bool mod; + for ( it = _user_var_groups.begin() ; it != end ; ++it ) + { + + if ( !(*it)->check ( _fixed_variables , _bb_input_type , &in_group, mod ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP" ); + + direction_types = (*it)->get_direction_types(); + sec_poll_dir_types = (*it)->get_sec_poll_dir_types(); + + if ( direction_types.empty() ) + direction_types = _direction_types; + + if ( sec_poll_dir_types.empty() ) + sec_poll_dir_types = _sec_poll_dir_types; + + vg = new NOMAD::Variable_Group ( (*it)->get_var_indexes() , + direction_types , + sec_poll_dir_types , + _out ); + + _var_groups.insert ( vg ); + } + + + // 2. 'automatic' groups for other variables: + std::set<int> vi_cbi; // list of cont./bin./int. variables + std::set<int> vi_cat; // list of categorical variables + + for ( i = 0 ; i < _dimension ; ++i ) + { + if ( !in_group[i] && !_fixed_variables[i].is_defined() ) { + if ( _bb_input_type[i] != NOMAD::CATEGORICAL ) + vi_cbi.insert(i); + else + vi_cat.insert(i); + } + } + + // creation of a group for cont./bin./int. variables: + if ( !vi_cbi.empty() ) + { + vg = new NOMAD::Variable_Group ( vi_cbi , + _direction_types , + _sec_poll_dir_types , + _out ); + + _var_groups.insert ( vg ); + } + + // creation of a group for categorical variables: + if ( !vi_cat.empty() ) + { + vg = new NOMAD::Variable_Group ( vi_cat , + _direction_types , + _sec_poll_dir_types , + _out ); + _var_groups.insert ( vg ); + } + } + + /*----------------------------*/ + /* TMP_DIR */ + /*----------------------------*/ + { + if ( _tmp_dir.empty() ) + _tmp_dir = _problem_dir; + + // check the directory: + if ( !_tmp_dir.empty() && !NOMAD::check_read_file ( _tmp_dir ) ) + { + std::string err = "invalid parameter: TMP_DIR: cannot access \'" + _tmp_dir + "\'"; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + } + + /*------------------------------------------------------*/ + /* SOLUTION_FILE, HISTORY_FILE and STATS_FILE */ + /* (depending on the value of ADD_SEED_TO_FILE_NAMES, */ + /* the seed is added the file names) */ + /*------------------------------------------------------*/ + if ( _add_seed_to_file_names ) + { + + std::string s_seed = NOMAD::itos(_seed); + int n_seed = static_cast<int>(s_seed.size()); + + add_seed_to_file_name ( n_seed , s_seed , _solution_file ); + add_seed_to_file_name ( n_seed , s_seed , _history_file ); + add_seed_to_file_name ( n_seed , s_seed , _stats_file_name ); + } + + // remove old history, solution, and stats files: + std::string old_file; + if ( remove_history_file && !_history_file.empty() ) + { + old_file = _problem_dir + _history_file; + remove ( old_file.c_str() ); + } + if ( remove_stats_file && !_stats_file_name.empty() ) + { + old_file = _problem_dir + _stats_file_name; + remove ( old_file.c_str() ); + } + if ( remove_solution_file && !_solution_file.empty() ) + { + old_file = _problem_dir + _solution_file; + remove ( old_file.c_str() ); + } + + /*----------------------------*/ + /* opportunistic strategy */ + /*----------------------------*/ + if ( !_opportunistic_eval ) + { + _model_params.eval_sort = NOMAD::NO_MODEL; + _sgte_eval_sort = false; + _opportunistic_lucky_eval = false; + _opportunistic_min_nb_success = -1; + _opportunistic_min_eval = -1; + _opportunistic_min_f_imprvmt.clear(); + } + + // opportunistic default strategy for LH search: + // single-objective: the default is taken the same as OPPORTUNISTIC_EVAL + // multi-objective : the default is 'no' + if ( !_opp_LH_is_defined ) + _opportunistic_LH = ( nb_obj > 1 ) ? false : _opportunistic_eval; + + // opportunistic default strategy for cache search + // (the same as OPPORTUNISTIC_EVAL): + if ( !_opp_CS_is_defined ) + _opportunistic_cache_search = false; + + if (_bb_max_block_size<=0) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::check(): invalid block size for list evaluation (>0)" ); + + if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed && _bb_max_block_size > 1 && (_max_bb_eval>0 || _max_sim_bb_eval>0 || _max_eval>0)) + _out << NOMAD::open_block("Warning:") + << "The maximum number of evaluations may be exceeded when BB_MAX_BLOCK_SIZE>1." << std::endl + << NOMAD::close_block(); + + #ifdef USE_MPI - _model_params.search1 = _model_params.search2 = _model_params.eval_sort = NOMAD::NO_MODEL; - set_DIRECTION_TYPE_NO_MODEL(); - if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) - _out << NOMAD::open_block("Warning:") - << "Model use is disabled in parallel mode." << std::endl - << NOMAD::close_block(); - - - if ((has_direction_type(NOMAD::ORTHO_NP1_QUAD) || has_direction_type(NOMAD::ORTHO_NP1_NEG)) && _asynchronous) - { - set_ASYNCHRONOUS(false); - if (_out.get_gen_dd()>NOMAD::MINIMAL_DISPLAY && !_warning_has_been_displayed) - _out << NOMAD::open_block("Warning:") - << "Asynchronous mode is disabled in parallel mode when dynamic directions (ortho n+1) are used." << std::endl - << NOMAD::close_block(); - } + if (_bb_max_block_size >1) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::check(): List evaluation by block of size > 1 are not allowed when using MPI." ); #endif - - // other checks: - if ( ( _model_params.search1 == NOMAD::NO_MODEL && - _model_params.search2 != NOMAD::NO_MODEL ) || - ( _model_params.search1 != NOMAD::NO_MODEL && - _model_params.search1 == _model_params.search2 ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH (conflict with the two types of search)" ); - - if ( _model_params.quad_radius_factor <= 0.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_RADIUS_FACTOR (must be > 0)" ); - - if ( _model_params.quad_min_Y_size < 0 ) - _model_params.quad_min_Y_size = -1; - else if ( _model_params.quad_min_Y_size < 2 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_QUAD_MIN_Y_SIZE (must be in {'N+1',-1,2,3,...})" ); - - if ( _model_params.model_np1_quad_epsilon <= 0.0 || _model_params.model_np1_quad_epsilon >= 1.0) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_NP1_QUAD_EPSILON (must be > 0 and < 1)" ); - - if ( _model_params.quad_max_Y_size <= _nb_free_variables ) - _model_params.quad_max_Y_size = _nb_free_variables + 1; - - if ( _model_params.search_max_trial_pts < 1 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH_MAX_TRIAL_PTS (must be >= 1)" ); - } - - - /*----------------------------*/ - /* variable groups */ - /* (and Halton seed) */ - /*----------------------------*/ - { - - // reset variable groups: - reset_variable_groups ( _var_groups ); - - // Halton seed: - if ( _halton_seed < 0 ) { - int * primes = new int [_dimension]; - NOMAD::construct_primes ( _dimension , primes ); - _halton_seed = primes[_dimension-1]; - delete [] primes; - } - - int def_halton_seed = _halton_seed , halton_seed; - - std::vector<bool> in_group ( _dimension ); - for ( i = 0 ; i < _dimension ; ++i ) - in_group[i] = false; - - NOMAD::Variable_Group * vg; - std::set<NOMAD::direction_type> direction_types , sec_poll_dir_types; - - // 1. user groups: - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::const_iterator - end = _user_var_groups.end() , it; - - bool mod; - for ( it = _user_var_groups.begin() ; it != end ; ++it ) - { - - if ( !(*it)->check ( _fixed_variables , _bb_input_type , &in_group, mod ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP" ); - - halton_seed = (*it)->get_halton_seed(); - if ( use_ortho_mads && halton_seed < 0 ) - halton_seed = def_halton_seed++; - - direction_types = (*it)->get_direction_types(); - sec_poll_dir_types = (*it)->get_sec_poll_dir_types(); - - if ( direction_types.empty() ) - direction_types = _direction_types; - - if ( sec_poll_dir_types.empty() ) - sec_poll_dir_types = _sec_poll_dir_types; - - vg = new NOMAD::Variable_Group ( (*it)->get_var_indexes() , - direction_types , - sec_poll_dir_types , - halton_seed , - _out ); - - _var_groups.insert ( vg ); - } - - - // 2. 'automatic' groups for other variables: - std::set<int> vi_cbi; // list of cont./bin./int. variables - std::set<int> vi_cat; // list of categorical variables - - for ( i = 0 ; i < _dimension ; ++i ) - { - if ( !in_group[i] && !_fixed_variables[i].is_defined() ) { - if ( _bb_input_type[i] != NOMAD::CATEGORICAL ) - vi_cbi.insert(i); - else - vi_cat.insert(i); - } - } - - // creation of a group for cont./bin./int. variables: - if ( !vi_cbi.empty() ) - { - - halton_seed = -1; - if ( use_ortho_mads ) - halton_seed = def_halton_seed++; - - vg = new NOMAD::Variable_Group ( vi_cbi , - _direction_types , - _sec_poll_dir_types , - halton_seed , - _out ); - - _var_groups.insert ( vg ); - } - - // creation of a group for categorical variables: - if ( !vi_cat.empty() ) - { - vg = new NOMAD::Variable_Group ( vi_cat , - _direction_types , - _sec_poll_dir_types , - -1 , // no use of Halton seed - _out ); - _var_groups.insert ( vg ); - } - } - - /*----------------------------*/ - /* TMP_DIR */ - /*----------------------------*/ - { - if ( _tmp_dir.empty() ) - _tmp_dir = _problem_dir; - - // check the directory: - if ( !_tmp_dir.empty() && !NOMAD::check_read_file ( _tmp_dir ) ) - { - std::string err = "invalid parameter: TMP_DIR: cannot access \'" + _tmp_dir + "\'"; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - } - - /*------------------------------------------------------*/ - /* SOLUTION_FILE, HISTORY_FILE and STATS_FILE */ - /* (depending on the value of ADD_SEED_TO_FILE_NAMES, */ - /* the seed is added the file names) */ - /*------------------------------------------------------*/ - if ( _add_seed_to_file_names ) - { - - std::string s_seed = NOMAD::itos(_seed); - int n_seed = static_cast<int>(s_seed.size()); - - add_seed_to_file_name ( n_seed , s_seed , _solution_file ); - add_seed_to_file_name ( n_seed , s_seed , _history_file ); - add_seed_to_file_name ( n_seed , s_seed , _stats_file_name ); - } - - // remove old history, solution, and stats files: - std::string old_file; - if ( remove_history_file && !_history_file.empty() ) - { - old_file = _problem_dir + _history_file; - remove ( old_file.c_str() ); - } - if ( remove_stats_file && !_stats_file_name.empty() ) - { - old_file = _problem_dir + _stats_file_name; - remove ( old_file.c_str() ); - } - if ( remove_solution_file && !_solution_file.empty() ) - { - old_file = _problem_dir + _solution_file; - remove ( old_file.c_str() ); - } - - /*----------------------------*/ - /* opportunistic strategy */ - /*----------------------------*/ - if ( !_opportunistic_eval ) - { - _model_params.eval_sort = NOMAD::NO_MODEL; - _sgte_eval_sort = false; - _opportunistic_lucky_eval = false; - _opportunistic_min_nb_success = -1; - _opportunistic_min_eval = -1; - _opportunistic_min_f_imprvmt.clear(); - } - - // opportunistic default strategy for LH search: - // single-objective: the default is taken the same as OPPORTUNISTIC_EVAL - // multi-objective : the default is 'no' - if ( !_opp_LH_is_defined ) - _opportunistic_LH = ( nb_obj > 1 ) ? false : _opportunistic_eval; - - // opportunistic default strategy for cache search - // (the same as OPPORTUNISTIC_EVAL): - if ( !_opp_CS_is_defined ) - _opportunistic_cache_search = false; - - /*----------------------------*/ - /* MULTI-MADS */ - /*----------------------------*/ - if ( nb_obj > 1 ) - { - - if ( _multi_formulation == NOMAD::UNDEFINED_FORMULATION ) - _multi_formulation = ( _VNS_search ) ? NOMAD::DIST_L2 : NOMAD::PRODUCT; - - if ( _multi_nb_mads_runs < 0 ) - { - - if ( _multi_overall_bb_eval < 0 ) - { - _multi_nb_mads_runs = 30; - if ( !_max_bbe_decided ) - { - _max_bb_eval = 25 * _nb_free_variables; - - if ( _LH_search_p0 < 0 ) - _LH_search_p0 = _max_bb_eval; - } - } - else if ( !_max_bbe_decided ) - { - _max_bb_eval = static_cast<int> - ( ceil ( sqrt ( 1.0 * _nb_free_variables * _multi_overall_bb_eval ) ) ); - - if ( _LH_search_p0 < 0 ) - _LH_search_p0 = _max_bb_eval; - } - } - else if ( _multi_overall_bb_eval > 0 && !_max_bbe_decided ) - { - _max_bb_eval = _multi_overall_bb_eval / _multi_nb_mads_runs; - if ( _multi_nb_mads_runs * _max_bb_eval < _multi_overall_bb_eval ) - ++_max_bb_eval; - } - } - - /*----------------------------------*/ - /* signature (standard or extern) */ - /*----------------------------------*/ - NOMAD::Signature * new_s = new NOMAD::Signature ( _dimension , - _bb_input_type , - _initial_mesh_size , - _min_mesh_size , - _min_poll_size , - _lb , - _ub , - _scaling , - _fixed_variables , - _periodic_variables , - _var_groups ); - // extern signature: - if ( _extern_signature ) - { - - bool fail = ( *new_s != *_extern_signature ); - delete new_s; - if ( fail ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Parameters::check(): incompatible extern signature" ); - } - - // standard signature: - else - { - - if ( _std_signature ) - { - delete new_s; - - _std_signature->reset ( _dimension , - _bb_input_type , - _initial_mesh_size , - _min_mesh_size , - _min_poll_size , - _lb , - _ub , - _scaling , - _fixed_variables , - _periodic_variables , - _var_groups ); - } - else - { - _std_signature = new_s; - _std_signature->set_std(); - } - } - - bool has_categorical - = ( (_std_signature) ? _std_signature : _extern_signature )->has_categorical(); - - - /*----------------------------*/ - /* X0 */ - /*----------------------------*/ - { - if ( _x0s.empty() && _x0_cache_file.empty() ) { - if ( _LH_search_p0 <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Parameters::check(): no starting point" ); - else if ( has_categorical ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Parameters::check(): no starting point with categorical variables" ); - } - - size_t x0n = _x0s.size(); - for ( size_t k = 0 ; k < x0n ; ++k ) - if ( !_x0s[k]->is_complete() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: x0 with missing coordinates" ); - - // avoid _x0_cache_file == _sgte_cache_file : - if ( !_opt_only_sgte && - !_x0_cache_file.empty() && - !_sgte_cache_file.empty() && - _x0_cache_file == _sgte_cache_file ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: x0 and sgte cache file are the same" ); - } - - - /*----------------------*/ - - _to_be_checked = false; - _warning_has_been_displayed=true; + + /*----------------------------*/ + /* MULTI-MADS */ + /*----------------------------*/ + if ( nb_obj > 1 ) + { + + if ( _multi_formulation == NOMAD::UNDEFINED_FORMULATION ) + _multi_formulation = ( _VNS_search ) ? NOMAD::DIST_L2 : NOMAD::PRODUCT; + + if ( _multi_nb_mads_runs < 0 ) + { + + if ( _multi_overall_bb_eval < 0 ) + { + _multi_nb_mads_runs = 30; + if ( !_max_bbe_decided ) + { + _max_bb_eval = 25 * _nb_free_variables; + + if ( _LH_search_p0 < 0 ) + _LH_search_p0 = _max_bb_eval; + } + } + else if ( !_max_bbe_decided ) + { + _max_bb_eval = static_cast<int> + ( ceil ( sqrt ( 1.0 * _nb_free_variables * _multi_overall_bb_eval ) ) ); + + if ( _LH_search_p0 < 0 ) + _LH_search_p0 = _max_bb_eval; + } + } + else if ( _multi_overall_bb_eval > 0 && !_max_bbe_decided ) + { + _max_bb_eval = _multi_overall_bb_eval / _multi_nb_mads_runs; + if ( _multi_nb_mads_runs * _max_bb_eval < _multi_overall_bb_eval ) + ++_max_bb_eval; + } + } + + /*----------------------------------*/ + /* signature (standard or extern) */ + /*----------------------------------*/ + NOMAD::Signature * new_s = new NOMAD::Signature ( _dimension , + _bb_input_type , + _lb , + _ub , + _use_smesh , + _anisotropic_mesh , + _initial_poll_size, + _min_poll_size, + _min_mesh_size, + _mesh_update_basis, + _poll_update_basis, + _mesh_coarsening_exponent, + _mesh_refining_exponent, + _initial_mesh_index, + _scaling , + _fixed_variables , + _periodic_variables , + _var_groups ); + + // extern signature: + if ( _extern_signature ) + { + + bool fail = ( *new_s != *_extern_signature ); + delete new_s; + if ( fail ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::check(): incompatible extern signature" ); + } + + // standard signature: + else + { + if ( _std_signature ) + { + delete new_s; + + _std_signature->reset ( _dimension , + _bb_input_type , + _lb , + _ub , + _scaling , + _fixed_variables , + _periodic_variables , + _var_groups ); + } + else + { + _std_signature = new_s; + _std_signature->set_std(); + } + } + + bool has_categorical + = ( (_std_signature) ? _std_signature : _extern_signature )->has_categorical(); + + + /*----------------------------*/ + /* X0 */ + /*----------------------------*/ + { + if ( _x0s.empty() && _x0_cache_file.empty() ) { + if ( _LH_search_p0 <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::check(): no starting point" ); + else if ( has_categorical ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::check(): no starting point with categorical variables" ); + } + + size_t x0n = _x0s.size(); + for ( size_t k = 0 ; k < x0n ; ++k ) + { + if ( !_x0s[k]->is_complete() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: x0 with missing coordinates" ); + + // check that x0 is consistent with input type + for ( i = 0 ; i < _dimension ; ++i ) + { + const NOMAD::Double xi = (*_x0s[k])[i]; + if ( _bb_input_type[i] != NOMAD::CONTINUOUS && ! xi.is_integer() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: x0 with variables values inconistent with their type (integer, binary, categorical." ); + + } + + } + + + // avoid _x0_cache_file == _sgte_cache_file : + if ( !_opt_only_sgte && + !_x0_cache_file.empty() && + !_sgte_cache_file.empty() && + _x0_cache_file == _sgte_cache_file ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: x0 and sgte cache file are the same" ); + } + + + /*----------------------*/ + + _to_be_checked = false; + _warning_has_been_displayed=true; } /*-----------------------------------------------------------------*/ @@ -4530,27 +4747,27 @@ void NOMAD::Parameters::check ( bool remove_history_file , /* (static, private) */ /*-----------------------------------------------------------------*/ void NOMAD::Parameters::add_seed_to_file_name ( int n_seed , - const std::string & s_seed , - std::string & file_name ) -{ - int n_pn = static_cast<int>(file_name.size()); - - if ( n_pn == 0 ) - return; - - int k = static_cast<int>(file_name.find_last_of(".")); - std::string ext = ""; - std::string fic = file_name; - - if ( k >= 0 && k < n_pn ) { - fic = file_name.substr ( 0 , k ); - ext = file_name.substr ( k , n_pn-k ); - n_pn = k; - } - - if ( n_pn <= n_seed+1 || - fic.substr ( n_pn-n_seed , n_pn-1 ) != s_seed ) - file_name = fic + "." + s_seed + ext; + const std::string & s_seed , + std::string & file_name ) +{ + int n_pn = static_cast<int>(file_name.size()); + + if ( n_pn == 0 ) + return; + + int k = static_cast<int>(file_name.find_last_of(".")); + std::string ext = ""; + std::string fic = file_name; + + if ( k >= 0 && k < n_pn ) { + fic = file_name.substr ( 0 , k ); + ext = file_name.substr ( k , n_pn-k ); + n_pn = k; + } + + if ( n_pn <= n_seed+1 || + fic.substr ( n_pn-n_seed , n_pn-1 ) != s_seed ) + file_name = fic + "." + s_seed + ext; } /*----------------------------------------*/ @@ -4560,208 +4777,199 @@ void NOMAD::Parameters::add_seed_to_file_name ( int n_seed , // get_signature: NOMAD::Signature * NOMAD::Parameters::get_signature ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_signature(), Parameters::check() must be invoked" ); - if ( !_std_signature && !_extern_signature ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_signature(), no signature is set" ); - return (_std_signature) ? _std_signature : _extern_signature; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_signature(), Parameters::check() must be invoked" ); + if ( !_std_signature && !_extern_signature ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_signature(), no signature is set" ); + return (_std_signature) ? _std_signature : _extern_signature; } // get_dimension: int NOMAD::Parameters::get_dimension ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_dimension(), Parameters::check() must be invoked" ); - return _dimension; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_dimension(), Parameters::check() must be invoked" ); + return _dimension; } // get_nb_free_variables: int NOMAD::Parameters::get_nb_free_variables ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_nb_free_variables(), Parameters::check() must be invoked" ); - return _nb_free_variables; -} - -// get_halton_seed: -int NOMAD::Parameters::get_halton_seed ( void ) const -{ - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_halton_seed(), Parameters::check() must be invoked" ); - return _halton_seed; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_nb_free_variables(), Parameters::check() must be invoked" ); + return _nb_free_variables; } // get_add_seed_to_file_names: bool NOMAD::Parameters::get_add_seed_to_file_names ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_add_seed_to_file_names(), Parameters::check() must be invoked" ); - return _add_seed_to_file_names; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_add_seed_to_file_names(), Parameters::check() must be invoked" ); + return _add_seed_to_file_names; } // get_snap_to_bounds: bool NOMAD::Parameters::get_snap_to_bounds ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_snap_to_bounds(), Parameters::check() must be invoked" ); - return _snap_to_bounds; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_snap_to_bounds(), Parameters::check() must be invoked" ); + return _snap_to_bounds; } // get_speculative_search: bool NOMAD::Parameters::get_speculative_search ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_speculative_search(), Parameters::check() must be invoked" ); - return _speculative_search; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_speculative_search(), Parameters::check() must be invoked" ); + return _speculative_search; } // get_cache_search: bool NOMAD::Parameters::get_cache_search ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_cache_search(), Parameters::check() must be invoked" ); - return _cache_search; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_cache_search(), Parameters::check() must be invoked" ); + return _cache_search; } // access to all the models parameters: void NOMAD::Parameters::get_model_parameters ( NOMAD::model_params_type & mp ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_parameters(), Parameters::check() must be invoked" ); - mp = _model_params; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_parameters(), Parameters::check() must be invoked" ); + mp = _model_params; } // get_model_search: NOMAD::model_type NOMAD::Parameters::get_model_search ( int i ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_search(), Parameters::check() must be invoked" ); - - if ( i != 1 && i != 2 ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_search(i), i must be 1 or 2" ); - - return ( i == 1 ) ? _model_params.search1 : _model_params.search2; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_search(), Parameters::check() must be invoked" ); + + if ( i != 1 && i != 2 ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_search(i), i must be 1 or 2" ); + + return ( i == 1 ) ? _model_params.search1 : _model_params.search2; } // has_model_search: bool NOMAD::Parameters::has_model_search ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_model_search(), Parameters::check() must be invoked" ); - return _model_params.search1 != NOMAD::NO_MODEL; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_model_search(), Parameters::check() must be invoked" ); + return _model_params.search1 != NOMAD::NO_MODEL; } // get_model_search_optimistic: bool NOMAD::Parameters::get_model_search_optimistic ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_search_optimistic(), Parameters::check() must be invoked" ); - return _model_params.search_optimistic; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_search_optimistic(), Parameters::check() must be invoked" ); + return _model_params.search_optimistic; } // get_model_search_proj_to_mesh: bool NOMAD::Parameters::get_model_search_proj_to_mesh ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_search_proj_to_mesh(), Parameters::check() must be invoked" ); - return _model_params.search_proj_to_mesh; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_search_proj_to_mesh(), Parameters::check() must be invoked" ); + return _model_params.search_proj_to_mesh; } // get_model_quad_radius_factor: const NOMAD::Double & NOMAD::Parameters::get_model_quad_radius_factor ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_quad_radius_factor(), Parameters::check() must be invoked" ); - return _model_params.quad_radius_factor; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_quad_radius_factor(), Parameters::check() must be invoked" ); + return _model_params.quad_radius_factor; } // get_model_quad_use_WP: bool NOMAD::Parameters::get_model_quad_use_WP ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_quad_use_WP(), Parameters::check() must be invoked" ); - return _model_params.quad_use_WP; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_quad_use_WP(), Parameters::check() must be invoked" ); + return _model_params.quad_use_WP; } // get_model_quad_max_Y_size: int NOMAD::Parameters::get_model_quad_max_Y_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_quad_max_Y_size(), Parameters::check() must be invoked" ); - return _model_params.quad_max_Y_size; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_quad_max_Y_size(), Parameters::check() must be invoked" ); + return _model_params.quad_max_Y_size; } // get_model_np1_quad_epsilon: const NOMAD::Double & NOMAD::Parameters::get_model_np1_quad_epsilon ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_np1_quad_epsilon(), Parameters::check() must be invoked" ); - return _model_params.model_np1_quad_epsilon; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_np1_quad_epsilon(), Parameters::check() must be invoked" ); + return _model_params.model_np1_quad_epsilon; } // get_model_quad_min_Y_size: int NOMAD::Parameters::get_model_quad_min_Y_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_quad_min_Y_size(), Parameters::check() must be invoked" ); - return _model_params.quad_min_Y_size; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_quad_min_Y_size(), Parameters::check() must be invoked" ); + return _model_params.quad_min_Y_size; } // get_model_tgp_mode: NOMAD::TGP_mode_type NOMAD::Parameters::get_model_tgp_mode ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_tgp_mode(), Parameters::check() must be invoked" ); - return _model_params.tgp_mode; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_tgp_mode(), Parameters::check() must be invoked" ); + return _model_params.tgp_mode; } // get_model_tgp_reuse_model: bool NOMAD::Parameters::get_model_tgp_reuse_model ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_tgp_reuse_model(), Parameters::check() must be invoked" ); - return _model_params.tgp_reuse_model; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_tgp_reuse_model(), Parameters::check() must be invoked" ); + return _model_params.tgp_reuse_model; } // get_model_search_max_trial_pts: int NOMAD::Parameters::get_model_search_max_trial_pts ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_search_max_trial_pts(), Parameters::check() must be invoked" ); - return _model_params.search_max_trial_pts; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_search_max_trial_pts(), Parameters::check() must be invoked" ); + return _model_params.search_max_trial_pts; } // get_model_eval_sort: NOMAD::model_type NOMAD::Parameters::get_model_eval_sort ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_eval_sort(), Parameters::check() must be invoked" ); - return _model_params.eval_sort; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_eval_sort(), Parameters::check() must be invoked" ); + return _model_params.eval_sort; } @@ -4769,939 +4977,977 @@ NOMAD::model_type NOMAD::Parameters::get_model_eval_sort ( void ) const // get_model_eval_sort_cautious: bool NOMAD::Parameters::get_model_eval_sort_cautious ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_model_eval_sort_cautious(), Parameters::check() must be invoked" ); - return _model_params.eval_sort_cautious; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_model_eval_sort_cautious(), Parameters::check() must be invoked" ); + return _model_params.eval_sort_cautious; } // get_VNS_search: bool NOMAD::Parameters::get_VNS_search ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_VNS_search(), Parameters::check() must be invoked" ); - return _VNS_search; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_VNS_search(), Parameters::check() must be invoked" ); + return _VNS_search; } // get_VNS_trigger: const NOMAD::Double & NOMAD::Parameters::get_VNS_trigger ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_VNS_trigger(), Parameters::check() must be invoked" ); - return _VNS_trigger; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_VNS_trigger(), Parameters::check() must be invoked" ); + return _VNS_trigger; } // get_LH_search_p0: int NOMAD::Parameters::get_LH_search_p0 ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_LH_search_p0(), Parameters::check() must be invoked" ); - return _LH_search_p0; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_LH_search_p0(), Parameters::check() must be invoked" ); + return _LH_search_p0; } // get_LH_search_p0: int NOMAD::Parameters::get_LH_search_pi ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_LH_search_pi(), Parameters::check() must be invoked" ); - return _LH_search_pi; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_LH_search_pi(), Parameters::check() must be invoked" ); + return _LH_search_pi; } // get_direction_types: const std::set<NOMAD::direction_type> & NOMAD::Parameters::get_direction_types ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_direction_types(), Parameters::check() must be invoked" ); - return _direction_types; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_direction_types(), Parameters::check() must be invoked" ); + return _direction_types; } // get_sec_poll_dir_types: const std::set<NOMAD::direction_type> & NOMAD::Parameters::get_sec_poll_dir_types ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_sec_poll_dir_types(), Parameters::check() must be invoked" ); - return _sec_poll_dir_types; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_sec_poll_dir_types(), Parameters::check() must be invoked" ); + return _sec_poll_dir_types; } // check if there are Ortho-MADS directions: bool NOMAD::Parameters::has_orthomads_directions ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_orthomads_directions(), Parameters::check() must be invoked" ); - bool use_ortho_mads = NOMAD::dirs_have_orthomads ( _direction_types ); - if ( !use_ortho_mads ) - use_ortho_mads = NOMAD::dirs_have_orthomads ( _sec_poll_dir_types ); - return use_ortho_mads; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_orthomads_directions(), Parameters::check() must be invoked" ); + bool use_ortho_mads = NOMAD::dirs_have_orthomads ( _direction_types ); + if ( !use_ortho_mads ) + use_ortho_mads = NOMAD::dirs_have_orthomads ( _sec_poll_dir_types ); + return use_ortho_mads; } // check if there are dynamic directions to complete the (n+1)th direction: bool NOMAD::Parameters::has_dynamic_direction ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_dynamic_direction(), Parameters::check() must be invoked" ); - - return (has_direction_type(NOMAD::ORTHO_NP1_QUAD) || has_direction_type(NOMAD::ORTHO_NP1_NEG)); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_dynamic_direction(), Parameters::check() must be invoked" ); + + return (has_direction_type(NOMAD::ORTHO_NP1_QUAD) || has_direction_type(NOMAD::ORTHO_NP1_NEG)); } // check that a given direction type is present (private) -bool NOMAD::Parameters::has_direction_type ( NOMAD::direction_type dt ) const +bool NOMAD::Parameters::has_direction_type ( NOMAD::direction_type dt ) const +{ + std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); + for ( it = _direction_types.begin() ; it != end ; ++it ) + if ( (*it)==dt) + return true; + return false; +} + + +// anisotropic mesh : +bool NOMAD::Parameters::get_anisotropic_mesh ( void ) const { - std::set<NOMAD::direction_type>::const_iterator it , end = _direction_types.end(); - for ( it = _direction_types.begin() ; it != end ; ++it ) - if ( (*it)==dt) - return true; - return false; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_anisotropic_mesh, Parameters::check() must be invoked" ); + return _anisotropic_mesh; } +// smesh: +bool NOMAD::Parameters::get_use_smesh ( void ) const +{ + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_use_smesh, Parameters::check() must be invoked" ); + return _use_smesh; +} + // get_mesh_update_basis: const NOMAD::Double & NOMAD::Parameters::get_mesh_update_basis ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_mesh_update_basis(), Parameters::check() must be invoked" ); - return _mesh_update_basis; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_mesh_update_basis(), Parameters::check() must be invoked" ); + return _mesh_update_basis; +} + +// get_poll_update_basis: +const NOMAD::Double & NOMAD::Parameters::get_poll_update_basis ( void ) const +{ + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_poll_update_basis(), Parameters::check() must be invoked" ); + return _poll_update_basis; } // get_mesh_coarsening_exponent: int NOMAD::Parameters::get_mesh_coarsening_exponent ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_mesh_coarsening_exponent(), Parameters::check() must be invoked" ); - return _mesh_coarsening_exponent; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_mesh_coarsening_exponent(), Parameters::check() must be invoked" ); + return _mesh_coarsening_exponent; } // get_mesh_refining_exponent: int NOMAD::Parameters::get_mesh_refining_exponent ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_mesh_refining_exponent(), Parameters::check() must be invoked" ); - return _mesh_refining_exponent; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_mesh_refining_exponent(), Parameters::check() must be invoked" ); + return _mesh_refining_exponent; } // get_initial_mesh_index: int NOMAD::Parameters::get_initial_mesh_index ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_initial_mesh_index(), Parameters::check() must be invoked" ); - return _initial_mesh_index; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_initial_mesh_index(), Parameters::check() must be invoked" ); + return _initial_mesh_index; } -// get_max_mesh_index: -int NOMAD::Parameters::get_max_mesh_index ( void ) const +// get_initial_mesh_size: +const NOMAD::Point & NOMAD::Parameters::get_initial_mesh_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_mesh_index(), Parameters::check() must be invoked" ); - return _max_mesh_index; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_initial_mesh_size(), Parameters::check() must be invoked" ); + return _initial_mesh_size; } -// get_initial_mesh_size: -const NOMAD::Point & NOMAD::Parameters::get_initial_mesh_size ( void ) const +// get_initial_poll_size: +const NOMAD::Point & NOMAD::Parameters::get_initial_poll_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_initial_mesh_size(), Parameters::check() must be invoked" ); - return _initial_mesh_size; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_initial_poll_size(), Parameters::check() must be invoked" ); + return _initial_poll_size; } // get_min_mesh_size: const NOMAD::Point & NOMAD::Parameters::get_min_mesh_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_min_mesh_size(), Parameters::check() must be invoked" ); - return _min_mesh_size; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_min_mesh_size(), Parameters::check() must be invoked" ); + return _min_mesh_size; } // get_min_poll_size: const NOMAD::Point & NOMAD::Parameters::get_min_poll_size ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_min_poll_size(), Parameters::check() must be invoked" ); - return _min_poll_size; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_min_poll_size(), Parameters::check() must be invoked" ); + return _min_poll_size; } // get_min_poll_size_defined: bool NOMAD::Parameters::get_min_poll_size_defined ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_min_poll_size_defined(), Parameters::check() must be invoked" ); - return _min_poll_size_defined; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_min_poll_size_defined(), Parameters::check() must be invoked" ); + return _min_poll_size_defined; } // get_neighbors_exe: const std::string & NOMAD::Parameters::get_neighbors_exe ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_neighbors_exe(), Parameters::check() must be invoked" ); - return _neighbors_exe; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_neighbors_exe(), Parameters::check() must be invoked" ); + return _neighbors_exe; } // get_extended_poll_trigger: const NOMAD::Double & NOMAD::Parameters::get_extended_poll_trigger ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_extended_poll_trigger(), Parameters::check() must be invoked" ); - return _extended_poll_trigger; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_extended_poll_trigger(), Parameters::check() must be invoked" ); + return _extended_poll_trigger; } // get_relative_ept: bool NOMAD::Parameters::get_relative_ept ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_relative_ept(), Parameters::check() must be invoked" ); - return _relative_ept; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_relative_ept(), Parameters::check() must be invoked" ); + return _relative_ept; } // get_extended_poll_enabled: bool NOMAD::Parameters::get_extended_poll_enabled ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_extended_poll_enabled(), Parameters::check() must be invoked" ); - return _extended_poll_enabled; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_extended_poll_enabled(), Parameters::check() must be invoked" ); + return _extended_poll_enabled; } // get_user_calls_enabled: bool NOMAD::Parameters::get_user_calls_enabled ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_user_calls_enabled(), Parameters::check() must be invoked" ); - return _user_calls_enabled; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_user_calls_enabled(), Parameters::check() must be invoked" ); + return _user_calls_enabled; } // get_asynchronous: bool NOMAD::Parameters::get_asynchronous ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_asynchronous(), Parameters::check() must be invoked" ); - return _asynchronous; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_asynchronous(), Parameters::check() must be invoked" ); + return _asynchronous; } // get_x0s: const std::vector<NOMAD::Point *> & NOMAD::Parameters::get_x0s ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_x0s(), Parameters::check() must be invoked" ); - return _x0s; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_x0s(), Parameters::check() must be invoked" ); + return _x0s; } // get_x0_cache_file: const std::string & NOMAD::Parameters::get_x0_cache_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_x0_cache_file(), Parameters::check() must be invoked" ); - return _x0_cache_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_x0_cache_file(), Parameters::check() must be invoked" ); + return _x0_cache_file; } // get_lb: const NOMAD::Point & NOMAD::Parameters::get_lb ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_lb(), Parameters::check() must be invoked" ); - return _lb; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_lb(), Parameters::check() must be invoked" ); + return _lb; } // get_ub: const NOMAD::Point & NOMAD::Parameters::get_ub ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_ub(), Parameters::check() must be invoked" ); - return _ub; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_ub(), Parameters::check() must be invoked" ); + return _ub; } // get_scaling: const NOMAD::Point & NOMAD::Parameters::get_scaling ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_scaling(), Parameters::check() must be invoked" ); - return _scaling; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_scaling(), Parameters::check() must be invoked" ); + return _scaling; } // get_fixed_variables: const NOMAD::Point & NOMAD::Parameters::get_fixed_variables ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_fixed_variables(), Parameters::check() must be invoked" ); - return _fixed_variables; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_fixed_variables(), Parameters::check() must be invoked" ); + return _fixed_variables; } // variable_is_fixed: bool NOMAD::Parameters::variable_is_fixed ( int index ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::variable_is_fixed(), Parameters::check() must be invoked" ); - if ( index < 0 || index >= _fixed_variables.size() ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::variable_is_fixed(), bad variable index" ); - return _fixed_variables[index].is_defined(); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::variable_is_fixed(), Parameters::check() must be invoked" ); + if ( index < 0 || index >= _fixed_variables.size() ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::variable_is_fixed(), bad variable index" ); + return _fixed_variables[index].is_defined(); } // get_bb_nb_outputs: int NOMAD::Parameters::get_bb_nb_outputs ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_nb_outputs(), Parameters::check() must be invoked" ); - return static_cast<int>(_bb_output_type.size()); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_nb_outputs(), Parameters::check() must be invoked" ); + return static_cast<int>(_bb_output_type.size()); } // get_bb_exe: const std::list<std::string> & NOMAD::Parameters::get_bb_exe ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_exe(), Parameters::check() must be invoked" ); - return _bb_exe; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_exe(), Parameters::check() must be invoked" ); + return _bb_exe; } // get_sgte_eval_sort: bool NOMAD::Parameters::get_sgte_eval_sort ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_sgte_eval_sort(), Parameters::check() must be invoked" ); - return _sgte_eval_sort; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_sgte_eval_sort(), Parameters::check() must be invoked" ); + return _sgte_eval_sort; } // has_sgte: bool NOMAD::Parameters::has_sgte ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_sgte(), Parameters::check() must be invoked" ); - return _has_sgte; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_sgte(), Parameters::check() must be invoked" ); + return _has_sgte; } // get_opt_only_sgte: bool NOMAD::Parameters::get_opt_only_sgte ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opt_only_sgte(), Parameters::check() must be invoked" ); - return _opt_only_sgte; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opt_only_sgte(), Parameters::check() must be invoked" ); + return _opt_only_sgte; } // has_sgte_exe: bool NOMAD::Parameters::has_sgte_exe ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_sgte_exe(), Parameters::check() must be invoked" ); - return !_sgte_exe.empty(); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_sgte_exe(), Parameters::check() must be invoked" ); + return !_sgte_exe.empty(); } // get_sgte_cost: int NOMAD::Parameters::get_sgte_cost ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_sgte_cost(), Parameters::check() must be invoked" ); - return _sgte_cost; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_sgte_cost(), Parameters::check() must be invoked" ); + return _sgte_cost; } // get_sgte_exe (returns an empty string if bb_exe has no surrogate): std::string NOMAD::Parameters::get_sgte_exe ( const std::string & bb_exe ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_sgte_exe(), Parameters::check() must be invoked" ); - std::map<std::string,std::string>::const_iterator it = _sgte_exe.find(bb_exe); - std::string s; - if ( it != _sgte_exe.end() ) - s = it->second; - return s; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_sgte_exe(), Parameters::check() must be invoked" ); + std::map<std::string,std::string>::const_iterator it = _sgte_exe.find(bb_exe); + std::string s; + if ( it != _sgte_exe.end() ) + s = it->second; + return s; } // get_index_obj: const std::list<int> & NOMAD::Parameters::get_index_obj ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_index_obj(), Parameters::check() must be invoked" ); - return _index_obj; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_index_obj(), Parameters::check() must be invoked" ); + return _index_obj; } // get_nb_obj: int NOMAD::Parameters::get_nb_obj ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_nb_obj(), Parameters::check() must be invoked" ); - return static_cast<int>(_index_obj.size()); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_nb_obj(), Parameters::check() must be invoked" ); + return static_cast<int>(_index_obj.size()); } // get_bb_input_include_tag: bool NOMAD::Parameters::get_bb_input_include_tag ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_input_include_tag(), Parameters::check() must be invoked" ); - return _bb_input_include_tag; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_input_include_tag(), Parameters::check() must be invoked" ); + return _bb_input_include_tag; } // get_bb_input_include_seed: bool NOMAD::Parameters::get_bb_input_include_seed ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_input_include_seed(), Parameters::check() must be invoked" ); - return _bb_input_include_seed; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_input_include_seed(), Parameters::check() must be invoked" ); + return _bb_input_include_seed; } // get_bb_redirection: bool NOMAD::Parameters::get_bb_redirection ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_redirection(), Parameters::check() must be invoked" ); - return _bb_redirection; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_redirection(), Parameters::check() must be invoked" ); + return _bb_redirection; } // get_bb_input_type: const std::vector<NOMAD::bb_input_type> & NOMAD::Parameters::get_bb_input_type ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_input_type(), Parameters::check() must be invoked" ); - return _bb_input_type; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_input_type(), Parameters::check() must be invoked" ); + return _bb_input_type; } // get_bb_output_type: const std::vector<NOMAD::bb_output_type> & NOMAD::Parameters::get_bb_output_type ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_bb_output_type(), Parameters::check() must be invoked" ); - return _bb_output_type; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_output_type(), Parameters::check() must be invoked" ); + return _bb_output_type; } // get_seed: int NOMAD::Parameters::get_seed ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_seed(), Parameters::check() must be invoked" ); - return _seed; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_seed(), Parameters::check() must be invoked" ); + return _seed; } // get_display_all_eval: bool NOMAD::Parameters::get_display_all_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_display_all_eval(), Parameters::check() must be invoked" ); - return _display_all_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_display_all_eval(), Parameters::check() must be invoked" ); + return _display_all_eval; } // get_display_stats: const std::list<std::string> & NOMAD::Parameters::get_display_stats ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_display_stats(), Parameters::check() must be invoked" ); - return _display_stats; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_display_stats(), Parameters::check() must be invoked" ); + return _display_stats; } // get_stats_file_name: const std::string & NOMAD::Parameters::get_stats_file_name ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_stats_file_name(), Parameters::check() must be invoked" ); - return _stats_file_name; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_stats_file_name(), Parameters::check() must be invoked" ); + return _stats_file_name; } // get_stats_file: const std::list<std::string> & NOMAD::Parameters::get_stats_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_stats_file(), Parameters::check() must be invoked" ); - return _stats_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_stats_file(), Parameters::check() must be invoked" ); + return _stats_file; } // get_point_display_limit: int NOMAD::Parameters::get_point_display_limit ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_point_display_limit(), Parameters::check() must be invoked" ); - return NOMAD::Point::get_display_limit(); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_point_display_limit(), Parameters::check() must be invoked" ); + return NOMAD::Point::get_display_limit(); } // out (ex get_display()): const NOMAD::Display & NOMAD::Parameters::out ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::out(), Parameters::check() must be invoked" ); - return _out; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::out(), Parameters::check() must be invoked" ); + return _out; } // get_display_degree 1/2: void NOMAD::Parameters::get_display_degree ( std::string & d ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_display_degree(), Parameters::check() must be invoked" ); - _out.get_display_degree ( d ); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_display_degree(), Parameters::check() must be invoked" ); + _out.get_display_degree ( d ); } // get_display_degree 2/2: int NOMAD::Parameters::get_display_degree ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_display_degree(), Parameters::check() must be invoked" ); - return _out.get_gen_dd(); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_display_degree(), Parameters::check() must be invoked" ); + return _out.get_gen_dd(); } // get_max_eval: int NOMAD::Parameters::get_max_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_eval(), Parameters::check() must be invoked" ); - return _max_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_eval(), Parameters::check() must be invoked" ); + return _max_eval; } // get_max_bb_eval: int NOMAD::Parameters::get_max_bb_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_bb_eval(), Parameters::check() must be invoked" ); - return _max_bb_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_bb_eval(), Parameters::check() must be invoked" ); + return _max_bb_eval; } // get_max_sim_bb_eval: int NOMAD::Parameters::get_max_sim_bb_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_sim_bb_eval(), Parameters::check() must be invoked" ); - return _max_sim_bb_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_sim_bb_eval(), Parameters::check() must be invoked" ); + return _max_sim_bb_eval; } // get_max_sgte_eval: int NOMAD::Parameters::get_max_sgte_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_sgte_eval(), Parameters::check() must be invoked" ); - return _sgte_max_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_sgte_eval(), Parameters::check() must be invoked" ); + return _sgte_max_eval; } // get_max_time: int NOMAD::Parameters::get_max_time ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_time(), Parameters::check() must be invoked" ); - return _max_time; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_time(), Parameters::check() must be invoked" ); + return _max_time; } // get_max_iterations: int NOMAD::Parameters::get_max_iterations ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_iterations(), Parameters::check() must be invoked" ); - return _max_iterations; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_iterations(), Parameters::check() must be invoked" ); + return _max_iterations; } // get_max_consecutive_failed_iterations: int NOMAD::Parameters::get_max_consecutive_failed_iterations ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_consecutive_failed_iterations(), Parameters::check() must be invoked" ); - return _max_cons_failed_it; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_consecutive_failed_iterations(), Parameters::check() must be invoked" ); + return _max_cons_failed_it; } // get_max_cache_memory: float NOMAD::Parameters::get_max_cache_memory ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_max_cache_memory(), Parameters::check() must be invoked" ); - return _max_cache_memory; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_max_cache_memory(), Parameters::check() must be invoked" ); + return _max_cache_memory; } // get_cache_save_period: int NOMAD::Parameters::get_cache_save_period ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_cache_save_period(), Parameters::check() must be invoked" ); - return _cache_save_period; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_cache_save_period(), Parameters::check() must be invoked" ); + return _cache_save_period; } // get_stop_if_feasible: bool NOMAD::Parameters::get_stop_if_feasible ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_stop_if_feasible(), Parameters::check() must be invoked" ); - return _stop_if_feasible; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_stop_if_feasible(), Parameters::check() must be invoked" ); + return _stop_if_feasible; } // get_f_target: const NOMAD::Point & NOMAD::Parameters::get_f_target ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_f_target(), Parameters::check() must be invoked" ); - return _f_target; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_f_target(), Parameters::check() must be invoked" ); + return _f_target; } // get_stat_sum_target: const NOMAD::Double & NOMAD::Parameters::get_stat_sum_target ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_stat_sum_target(), Parameters::check() must be invoked" ); - return _stat_sum_target; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_stat_sum_target(), Parameters::check() must be invoked" ); + return _stat_sum_target; } // get_L_curve_target: const NOMAD::Double & NOMAD::Parameters::get_L_curve_target ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_L_curve_target(), Parameters::check() must be invoked" ); - return _L_curve_target; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_L_curve_target(), Parameters::check() must be invoked" ); + return _L_curve_target; } // get_problem_dir: const std::string & NOMAD::Parameters::get_problem_dir ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_problem_dir(), Parameters::check() must be invoked" ); - return _problem_dir; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_problem_dir(), Parameters::check() must be invoked" ); + return _problem_dir; } // get_tmp_dir: const std::string & NOMAD::Parameters::get_tmp_dir ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_tmp_dir(), Parameters::check() must be invoked" ); - return _tmp_dir; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_tmp_dir(), Parameters::check() must be invoked" ); + return _tmp_dir; } // get_solution_file: const std::string & NOMAD::Parameters::get_solution_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_solution_file(), Parameters::check() must be invoked" ); - return _solution_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_solution_file(), Parameters::check() must be invoked" ); + return _solution_file; } // get_history_file: const std::string & NOMAD::Parameters::get_history_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_history_file(), Parameters::check() must be invoked" ); - return _history_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_history_file(), Parameters::check() must be invoked" ); + return _history_file; } // get_cache_file: const std::string & NOMAD::Parameters::get_cache_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_cache_file(), Parameters::check() must be invoked" ); - return _cache_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_cache_file(), Parameters::check() must be invoked" ); + return _cache_file; } // get_sgte_cache_file: const std::string & NOMAD::Parameters::get_sgte_cache_file ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_sgte_cache_file(), Parameters::check() must be invoked" ); - return _sgte_cache_file; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_sgte_cache_file(), Parameters::check() must be invoked" ); + return _sgte_cache_file; } // get_rho: const NOMAD::Double & NOMAD::Parameters::get_rho ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_rho(), Parameters::check() must be invoked" ); - return _rho; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_rho(), Parameters::check() must be invoked" ); + return _rho; } // get_h_min: const NOMAD::Double & NOMAD::Parameters::get_h_min ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_h_min(), Parameters::check() must be invoked" ); - return _h_min; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_h_min(), Parameters::check() must be invoked" ); + return _h_min; } // get_h_max_0: const NOMAD::Double & NOMAD::Parameters::get_h_max_0 ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_h_max_0(), Parameters::check() must be invoked" ); - return _h_max_0; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_h_max_0(), Parameters::check() must be invoked" ); + return _h_max_0; } // get_h_norm: NOMAD::hnorm_type NOMAD::Parameters::get_h_norm ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_h_norm(), Parameters::check() must be invoked" ); - return _h_norm; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_h_norm(), Parameters::check() must be invoked" ); + return _h_norm; } // use_sec_poll_center: bool NOMAD::Parameters::use_sec_poll_center ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::use_second_poll_center(), Parameters::check() must be invoked" ); - return _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::use_second_poll_center(), Parameters::check() must be invoked" ); + return _barrier_type == NOMAD::PB || _barrier_type == NOMAD::PEB_P; } // get_barrier_type: NOMAD::bb_output_type NOMAD::Parameters::get_barrier_type ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_filter_type(), Parameters::check() must be invoked" ); - return _barrier_type; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_filter_type(), Parameters::check() must be invoked" ); + return _barrier_type; } // has_constraints: bool NOMAD::Parameters::has_constraints ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_constraints(), Parameters::check() must be invoked" ); - return _has_constraints; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_constraints(), Parameters::check() must be invoked" ); + return _has_constraints; } // has_EB_constraints: bool NOMAD::Parameters::has_EB_constraints ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::has_EB_constraints(), Parameters::check() must be invoked" ); - return _has_EB_constraints; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::has_EB_constraints(), Parameters::check() must be invoked" ); + return _has_EB_constraints; } // get_multi_nb_mads_runs: int NOMAD::Parameters::get_multi_nb_mads_runs ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_multi_nb_mads_runs(), Parameters::check() must be invoked" ); - return _multi_nb_mads_runs; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_multi_nb_mads_runs(), Parameters::check() must be invoked" ); + return _multi_nb_mads_runs; } // get_multi_overall_bb_eval: int NOMAD::Parameters::get_multi_overall_bb_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_multi_overall_bb_eval(), Parameters::check() must be invoked" ); - return _multi_overall_bb_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_multi_overall_bb_eval(), Parameters::check() must be invoked" ); + return _multi_overall_bb_eval; } // get_multi_use_delta_crit: bool NOMAD::Parameters::get_multi_use_delta_crit ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_multi_use_delta_crit(), Parameters::check() must be invoked" ); - return _multi_use_delta_crit; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_multi_use_delta_crit(), Parameters::check() must be invoked" ); + return _multi_use_delta_crit; } // get_multi_f_bounds: const NOMAD::Point & NOMAD::Parameters::get_multi_f_bounds ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_multi_f_bounds(), Parameters::check() must be invoked" ); - return _multi_f_bounds; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_multi_f_bounds(), Parameters::check() must be invoked" ); + return _multi_f_bounds; } // get_multi_formulation: NOMAD::multi_formulation_type NOMAD::Parameters::get_multi_formulation ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_multi_formulation(), Parameters::check() must be invoked" ); - return _multi_formulation; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_multi_formulation(), Parameters::check() must be invoked" ); + return _multi_formulation; } // get_opportunistic_cache_search: bool NOMAD::Parameters::get_opportunistic_cache_search ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_cache_search(), Parameters::check() must be invoked" ); - return _opportunistic_cache_search; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_cache_search(), Parameters::check() must be invoked" ); + return _opportunistic_cache_search; } // get_opportunistic_LH: bool NOMAD::Parameters::get_opportunistic_LH ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_LH(), Parameters::check() must be invoked" ); - return _opportunistic_LH; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_LH(), Parameters::check() must be invoked" ); + return _opportunistic_LH; } // get_opportunistic_eval: bool NOMAD::Parameters::get_opportunistic_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_eval(), Parameters::check() must be invoked" ); - return _opportunistic_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_eval(), Parameters::check() must be invoked" ); + return _opportunistic_eval; } // get_opportunistic_min_nb_success int NOMAD::Parameters::get_opportunistic_min_nb_success ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_min_nb_success(), Parameters::check() must be invoked"); - return _opportunistic_min_nb_success; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_min_nb_success(), Parameters::check() must be invoked"); + return _opportunistic_min_nb_success; } // get_opportunistic_min_eval int NOMAD::Parameters::get_opportunistic_min_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_min_eval(), Parameters::check() must be invoked" ); - return _opportunistic_min_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_min_eval(), Parameters::check() must be invoked" ); + return _opportunistic_min_eval; +} + +// get_bb_max_block_size +int NOMAD::Parameters::get_bb_max_block_size ( void ) const +{ + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_bb_max_block_size(), Parameters::check() must be invoked" ); + return _bb_max_block_size; } + // get_opportunistic_min_f_imprvmt const NOMAD::Double & NOMAD::Parameters::get_opportunistic_min_f_imprvmt ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_min_f_imprvmt(), Parameters::check() must be invoked" ); - return _opportunistic_min_f_imprvmt; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_min_f_imprvmt(), Parameters::check() must be invoked" ); + return _opportunistic_min_f_imprvmt; } // get_opportunistic_lucky_eval: bool NOMAD::Parameters::get_opportunistic_lucky_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_opportunistic_lucky_eval(), Parameters::check() must be invoked" ); - return _opportunistic_lucky_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_opportunistic_lucky_eval(), Parameters::check() must be invoked" ); + return _opportunistic_lucky_eval; } // check_stat_sum: bool NOMAD::Parameters::check_stat_sum ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::check_stat_sum(), Parameters::check() must be invoked" ); - return ( _index_stat_sum >= 0 ); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::check_stat_sum(), Parameters::check() must be invoked" ); + return ( _index_stat_sum >= 0 ); } // check_stat_avg: bool NOMAD::Parameters::check_stat_avg ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::check_stat_avg(), Parameters::check() must be invoked" ); - return ( _index_stat_avg >= 0 ); + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::check_stat_avg(), Parameters::check() must be invoked" ); + return ( _index_stat_avg >= 0 ); } // get_index_stat_sum: int NOMAD::Parameters::get_index_stat_sum ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_index_stat_sum(), Parameters::check() must be invoked" ); - return _index_stat_sum; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_index_stat_sum(), Parameters::check() must be invoked" ); + return _index_stat_sum; } // get_index_stat_avg: int NOMAD::Parameters::get_index_stat_avg ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_index_stat_avg(), Parameters::check() must be invoked" ); - return _index_stat_avg; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_index_stat_avg(), Parameters::check() must be invoked" ); + return _index_stat_avg; } // get_index_cnt_eval: int NOMAD::Parameters::get_index_cnt_eval ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_index_cnt_eval(), Parameters::check() must be invoked" ); - return _index_cnt_eval; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_index_cnt_eval(), Parameters::check() must be invoked" ); + return _index_cnt_eval; } // get_periodic_variables: const std::vector<bool> & NOMAD::Parameters::get_periodic_variables ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_periodic_variables(), Parameters::check() must be invoked" ); - return _periodic_variables; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_periodic_variables(), Parameters::check() must be invoked" ); + return _periodic_variables; } // get_variable_groups: const std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & NOMAD::Parameters::get_variable_groups ( void ) const { - if ( _to_be_checked ) - throw Bad_Access ( "Parameters.cpp" , __LINE__ , - "Parameters::get_variable_groups(), Parameters::check() must be invoked" ); - return _var_groups; + if ( _to_be_checked ) + throw Bad_Access ( "Parameters.cpp" , __LINE__ , + "Parameters::get_variable_groups(), Parameters::check() must be invoked" ); + return _var_groups; } /*----------------------------------------*/ @@ -5711,185 +5957,185 @@ NOMAD::Parameters::get_variable_groups ( void ) const // set_POINT_DISPLAY_LIMIT: void NOMAD::Parameters::set_POINT_DISPLAY_LIMIT ( int dl ) { - NOMAD::Point::set_display_limit ( dl ); + NOMAD::Point::set_display_limit ( dl ); } // set_DIMENSION: bool NOMAD::Parameters::set_DIMENSION ( int dim ) { - if ( _dimension > 0 ) { - _dimension = -1; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION - defined twice" ); - return false; - } - - _to_be_checked = true; - _dimension = dim; - if ( _dimension <= 0 ) { - _dimension = -1; - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIMENSION" ); - return false; - } - - // all variables are initially considered continuous: - _bb_input_type.resize ( _dimension ); - for ( int i = 0 ; i < _dimension ; ++i ) - _bb_input_type[i] = NOMAD::CONTINUOUS; - - // resize of _initial_mesh_size: - _initial_mesh_size.reset ( _dimension ); - - return true; + if ( _dimension > 0 ) { + _dimension = -1; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION - defined twice" ); + return false; + } + + _to_be_checked = true; + _dimension = dim; + if ( _dimension <= 0 ) { + _dimension = -1; + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIMENSION" ); + return false; + } + + // all variables are initially considered continuous: + _bb_input_type.resize ( _dimension ); + for ( int i = 0 ; i < _dimension ; ++i ) + _bb_input_type[i] = NOMAD::CONTINUOUS; + + // resize of _initial_mesh_size: + _initial_mesh_size.reset ( _dimension ); + _initial_poll_size.reset ( _dimension ); + + return true; } // set_EXTERN_SIGNATURE (set a new extern signature and // delete the standard signature): void NOMAD::Parameters::set_EXTERN_SIGNATURE ( NOMAD::Signature * s ) { - if ( _std_signature && s == _std_signature ) - return; - - // standard signature: - delete _std_signature; - _std_signature = NULL; - _extern_signature = s; - - // dimension: - _dimension = -1; - set_DIMENSION ( s->get_n() ); - - // input types: - set_BB_INPUT_TYPE ( s->get_input_types() ); - - // bounds: - set_LOWER_BOUND ( s->get_lb() ); - set_UPPER_BOUND ( s->get_ub() ); - - // scaling: - set_SCALING ( s->get_scaling() ); - - // fixed variables: - set_FIXED_VARIABLE ( s->get_fixed_variables() ); - - // periodic variables: - set_PERIODIC_VARIABLE ( s->get_periodic_variables() ); - - // variable groups: - reset_variable_groups(); - set_VARIABLE_GROUP ( s->get_var_groups() ); - - _to_be_checked = true; -} - -// set_HALTON_SEED: -void NOMAD::Parameters::set_HALTON_SEED ( int hs ) -{ - _to_be_checked = true; - _halton_seed = ( hs < 0 ) ? -1 : hs; + if ( _std_signature && s == _std_signature ) + return; + + // standard signature: + delete _std_signature; + _std_signature = NULL; + _extern_signature = s; + + // dimension: + _dimension = -1; + set_DIMENSION ( s->get_n() ); + + // input types: + set_BB_INPUT_TYPE ( s->get_input_types() ); + + // bounds: + set_LOWER_BOUND ( s->get_lb() ); + set_UPPER_BOUND ( s->get_ub() ); + + // scaling: + set_SCALING ( s->get_scaling() ); + + // fixed variables: + set_FIXED_VARIABLE ( s->get_fixed_variables() ); + + // periodic variables: + set_PERIODIC_VARIABLE ( s->get_periodic_variables() ); + + // variable groups: + reset_variable_groups(); + set_VARIABLE_GROUP ( s->get_var_groups() ); + + _to_be_checked = true; } // set_SNAP_TO_BOUNDS: void NOMAD::Parameters::set_SNAP_TO_BOUNDS ( bool stb ) { - _to_be_checked = true; - _snap_to_bounds = stb; + _to_be_checked = true; + _snap_to_bounds = stb; } // set_SPECULATIVE_SEARCH: void NOMAD::Parameters::set_SPECULATIVE_SEARCH ( bool ss ) { - _to_be_checked = true; - _speculative_search = ss; + _to_be_checked = true; + _speculative_search = ss; } // set_CACHE_SEARCH: void NOMAD::Parameters::set_CACHE_SEARCH ( bool s ) { - _to_be_checked = true; - _cache_search = s; + _to_be_checked = true; + _cache_search = s; } // Disable use of models void NOMAD::Parameters::set_DISABLE_MODELS ( void ) { - _disable_models=true; + _disable_models=true; +} + +// Disable use of models +void NOMAD::Parameters::set_DISABLE_EVAL_SORT ( void ) +{ + _disable_eval_sort=true; } // set all the models parameters: void NOMAD::Parameters::set_model_parameters ( const NOMAD::model_params_type & mp ) { - _to_be_checked = true; - set_MODEL_SEARCH ( 1 , mp.search1 ); - set_MODEL_SEARCH ( 2 , mp.search2 ); - set_MODEL_EVAL_SORT ( mp.eval_sort ); - set_MODEL_SEARCH_OPTIMISTIC ( mp.search_optimistic ); - set_MODEL_SEARCH_PROJ_TO_MESH ( mp.search_proj_to_mesh ); - set_MODEL_SEARCH_MAX_TRIAL_PTS ( mp.search_max_trial_pts ); - set_MODEL_EVAL_SORT_CAUTIOUS ( mp.eval_sort_cautious ); - set_MODEL_QUAD_RADIUS_FACTOR ( mp.quad_radius_factor ); - set_MODEL_QUAD_USE_WP ( mp.quad_use_WP ); - set_MODEL_QUAD_MIN_Y_SIZE ( mp.quad_min_Y_size ); - set_MODEL_QUAD_MAX_Y_SIZE ( mp.quad_max_Y_size ); - set_MODEL_TGP_MODE ( mp.tgp_mode ); - set_MODEL_TGP_REUSE_MODEL ( mp.tgp_reuse_model ); + _to_be_checked = true; + set_MODEL_SEARCH ( 1 , mp.search1 ); + set_MODEL_SEARCH ( 2 , mp.search2 ); + set_MODEL_EVAL_SORT ( mp.eval_sort ); + set_MODEL_SEARCH_OPTIMISTIC ( mp.search_optimistic ); + set_MODEL_SEARCH_PROJ_TO_MESH ( mp.search_proj_to_mesh ); + set_MODEL_SEARCH_MAX_TRIAL_PTS ( mp.search_max_trial_pts ); + set_MODEL_EVAL_SORT_CAUTIOUS ( mp.eval_sort_cautious ); + set_MODEL_QUAD_RADIUS_FACTOR ( mp.quad_radius_factor ); + set_MODEL_QUAD_USE_WP ( mp.quad_use_WP ); + set_MODEL_QUAD_MIN_Y_SIZE ( mp.quad_min_Y_size ); + set_MODEL_QUAD_MAX_Y_SIZE ( mp.quad_max_Y_size ); + set_MODEL_TGP_MODE ( mp.tgp_mode ); + set_MODEL_TGP_REUSE_MODEL ( mp.tgp_reuse_model ); } // set_MODEL_SEARCH (1/3): void NOMAD::Parameters::set_MODEL_SEARCH ( int i , NOMAD::model_type ms ) { - _to_be_checked = true; - + _to_be_checked = true; + #ifndef USE_TGP - if ( ms == NOMAD::TGP_MODEL ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_SEARCH: this version has not been compiled for TGP" ); + if ( ms == NOMAD::TGP_MODEL ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_SEARCH: this version has not been compiled for TGP" ); #endif - - if ( i != 1 && i != 2 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "NOMAD::Parameters::set_MODEL_SEARCH(i,m): bad value for argument i (must be 1 or 2)" ); - - if ( i == 1 ) { - if ( _model_params.search2 != NOMAD::NO_MODEL ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "NOMAD::Parameters::set_MODEL_SEARCH(1,m): already a second model search" ); - - _model_params.search1 = ms; - } - else { - - if ( _model_params.search1 == NOMAD::NO_MODEL && ms != NOMAD::NO_MODEL ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "NOMAD::Parameters::set_MODEL_SEARCH(2,m): no first model search" ); - - if ( _model_params.search1 != NOMAD::NO_MODEL && _model_params.search1 == ms ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "NOMAD::Parameters::set_MODEL_SEARCH(2,m): second model search of the same type" ); - - _model_params.search2 = ms; - } + + if ( i != 1 && i != 2 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "NOMAD::Parameters::set_MODEL_SEARCH(i,m): bad value for argument i (must be 1 or 2)" ); + + if ( i == 1 ) { + if ( _model_params.search2 != NOMAD::NO_MODEL ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "NOMAD::Parameters::set_MODEL_SEARCH(1,m): already a second model search" ); + + _model_params.search1 = ms; + } + else { + + if ( _model_params.search1 == NOMAD::NO_MODEL && ms != NOMAD::NO_MODEL ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "NOMAD::Parameters::set_MODEL_SEARCH(2,m): no first model search" ); + + if ( _model_params.search1 != NOMAD::NO_MODEL && _model_params.search1 == ms ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "NOMAD::Parameters::set_MODEL_SEARCH(2,m): second model search of the same type" ); + + _model_params.search2 = ms; + } } // set_MODEL_SEARCH (2/3): void NOMAD::Parameters::set_MODEL_SEARCH ( bool ms ) { - if ( ms ) { - set_MODEL_SEARCH ( 1 , NOMAD::QUADRATIC_MODEL ); - set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); - } - else { - set_MODEL_SEARCH ( 1 , NOMAD::NO_MODEL ); - set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); - } + if ( ms ) { + set_MODEL_SEARCH ( 1 , NOMAD::QUADRATIC_MODEL ); + set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); + } + else { + set_MODEL_SEARCH ( 1 , NOMAD::NO_MODEL ); + set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); + } } // set_MODEL_SEARCH (3/3): void NOMAD::Parameters::set_MODEL_SEARCH ( NOMAD::model_type ms ) { - set_MODEL_SEARCH ( 1 , ms ); - set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); + set_MODEL_SEARCH ( 1 , ms ); + set_MODEL_SEARCH ( 2 , NOMAD::NO_MODEL ); } @@ -5897,71 +6143,71 @@ void NOMAD::Parameters::set_MODEL_SEARCH ( NOMAD::model_type ms ) void NOMAD::Parameters::set_MODEL_EVAL_SORT ( NOMAD::model_type mes ) { #ifndef USE_TGP - if ( mes == NOMAD::TGP_MODEL ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_EVAL_SORT: this version has not been compiled for TGP" ); + if ( mes == NOMAD::TGP_MODEL ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_EVAL_SORT: this version has not been compiled for TGP" ); #endif - _to_be_checked = true; - _model_params.eval_sort = mes; + _to_be_checked = true; + _model_params.eval_sort = mes; } // set_MODEL_EVAL_SORT (2/2): void NOMAD::Parameters::set_MODEL_EVAL_SORT ( bool mes ) { - if ( mes ) - set_MODEL_EVAL_SORT ( NOMAD::QUADRATIC_MODEL ); - else - set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); + if ( mes ) + set_MODEL_EVAL_SORT ( NOMAD::QUADRATIC_MODEL ); + else + set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); } // set_MODEL_SEARCH_OPTIMISTIC: void NOMAD::Parameters::set_MODEL_SEARCH_OPTIMISTIC ( bool mso ) { - _to_be_checked = true; - _model_params.search_optimistic = mso; + _to_be_checked = true; + _model_params.search_optimistic = mso; } // set_MODEL_SEARCH_PROJ_TO_MESH: void NOMAD::Parameters::set_MODEL_SEARCH_PROJ_TO_MESH ( bool ptm ) { - _to_be_checked = true; - _model_params.search_proj_to_mesh = ptm; + _to_be_checked = true; + _model_params.search_proj_to_mesh = ptm; } // set_MODEL_QUAD_RADIUS_FACTOR: void NOMAD::Parameters::set_MODEL_QUAD_RADIUS_FACTOR ( const NOMAD::Double & r ) { - _to_be_checked = true; - _model_params.quad_radius_factor = r; + _to_be_checked = true; + _model_params.quad_radius_factor = r; } // set_MODEL_QUAD_USE_WP: void NOMAD::Parameters::set_MODEL_QUAD_USE_WP ( bool uwp ) { - _to_be_checked = true; - _model_params.quad_use_WP = uwp; + _to_be_checked = true; + _model_params.quad_use_WP = uwp; } // set_MODEL_QUAD_MAX_Y_SIZE: void NOMAD::Parameters::set_MODEL_QUAD_MAX_Y_SIZE ( int s ) { - _to_be_checked = true; - _model_params.quad_max_Y_size = s; + _to_be_checked = true; + _model_params.quad_max_Y_size = s; } // set_MODEL_QUAD_MIN_Y_SIZE: void NOMAD::Parameters::set_MODEL_QUAD_MIN_Y_SIZE ( int s ) { - _to_be_checked = true; - _model_params.quad_min_Y_size = (s < 0) ? -1 : s; + _to_be_checked = true; + _model_params.quad_min_Y_size = (s < 0) ? -1 : s; } // set_MODEL_QUAD_HYPERCUBE_LOWER_LIM: void NOMAD::Parameters::set_MODEL_NP1_QUAD_EPSILON ( const NOMAD::Double & d ) { - _to_be_checked = true; - _model_params.model_np1_quad_epsilon = d; + _to_be_checked = true; + _model_params.model_np1_quad_epsilon = d; } @@ -5969,402 +6215,401 @@ void NOMAD::Parameters::set_MODEL_NP1_QUAD_EPSILON ( const NOMAD::Double & d ) // set_MODEL_TGP_MODE: void NOMAD::Parameters::set_MODEL_TGP_MODE ( NOMAD::TGP_mode_type m ) { - if ( m == NOMAD::TGP_USER ) { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MODEL_TGP_MODE: the TGP user mode is only a debugging option" ); - } - - _to_be_checked = true; - _model_params.tgp_mode = m; + if ( m == NOMAD::TGP_USER ) { + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MODEL_TGP_MODE: the TGP user mode is only a debugging option" ); + } + + _to_be_checked = true; + _model_params.tgp_mode = m; } // set_MODEL_TGP_REUSE_MODEL: void NOMAD::Parameters::set_MODEL_TGP_REUSE_MODEL ( bool rm ) { - _to_be_checked = true; - _model_params.tgp_reuse_model = rm; + _to_be_checked = true; + _model_params.tgp_reuse_model = rm; } // set_MODEL_SEARCH_MAX_TRIAL_PTS: void NOMAD::Parameters::set_MODEL_SEARCH_MAX_TRIAL_PTS ( int s ) { - _to_be_checked = true; - _model_params.search_max_trial_pts = s; + _to_be_checked = true; + _model_params.search_max_trial_pts = s; } // set_MODEL_EVAL_SORT_CAUTIOUS: void NOMAD::Parameters::set_MODEL_EVAL_SORT_CAUTIOUS ( bool mesc ) { - _to_be_checked = true; - _model_params.eval_sort_cautious = mesc; + _to_be_checked = true; + _model_params.eval_sort_cautious = mesc; } // set_VNS_SEARCH (1/2): void NOMAD::Parameters::set_VNS_SEARCH ( bool s ) { - _to_be_checked = true; - _VNS_search = s; - _VNS_trigger = ( s ) ? 0.75 : NOMAD::Double(); + _to_be_checked = true; + _VNS_search = s; + _VNS_trigger = ( s ) ? 0.75 : NOMAD::Double(); } // set_VNS_SEARCH (2/2): void NOMAD::Parameters::set_VNS_SEARCH ( const NOMAD::Double & trigger ) { - _to_be_checked = true; - if ( !trigger.is_defined() ) { - _VNS_search = false; - return; - } - - if ( trigger < 0.0 || trigger > 1.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VNS_SEARCH: must be in [0;1]" ); - - _VNS_search = ( trigger > 0.0 ); - _VNS_trigger = trigger; + _to_be_checked = true; + if ( !trigger.is_defined() ) { + _VNS_search = false; + return; + } + + if ( trigger < 0.0 || trigger > 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VNS_SEARCH: must be in [0;1]" ); + + _VNS_search = ( trigger > 0.0 ); + _VNS_trigger = trigger; } // set_LH_SEARCH: void NOMAD::Parameters::set_LH_SEARCH ( int p0 , int pi ) { - _to_be_checked = true; - _LH_search_p0 = (p0 <= 0 ) ? 0 : p0; - _LH_search_pi = (pi <= 0 ) ? 0 : pi; + _to_be_checked = true; + _LH_search_p0 = (p0 <= 0 ) ? 0 : p0; + _LH_search_pi = (pi <= 0 ) ? 0 : pi; } // set_DIRECTION_TYPE (1/2): void NOMAD::Parameters::set_DIRECTION_TYPE ( NOMAD::direction_type dt ) { - _to_be_checked = true; - if ( dt == NOMAD::UNDEFINED_DIRECTION || - dt == NOMAD::NO_DIRECTION || - dt == NOMAD::MODEL_SEARCH_DIR ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: DIRECTION_TYPE" ); - _direction_types.insert ( dt ); + _to_be_checked = true; + if ( dt == NOMAD::UNDEFINED_DIRECTION || + dt == NOMAD::NO_DIRECTION || + dt == NOMAD::MODEL_SEARCH_DIR ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: DIRECTION_TYPE" ); + _direction_types.insert ( dt ); } // set_DIRECTION_TYPE (2/2): void NOMAD::Parameters::set_DIRECTION_TYPE ( const std::set<NOMAD::direction_type> & dt ) { - std::set<NOMAD::direction_type>::const_iterator it , end = dt.end(); - for ( it = dt.begin() ; it != end ; ++it ) - set_DIRECTION_TYPE ( *it ); + std::set<NOMAD::direction_type>::const_iterator it , end = dt.end(); + for ( it = dt.begin() ; it != end ; ++it ) + set_DIRECTION_TYPE ( *it ); } void NOMAD::Parameters::set_DIRECTION_TYPE_NO_MODEL ( void ) { - std::set<NOMAD::direction_type>::iterator it=_direction_types.find(NOMAD::ORTHO_NP1_QUAD); - std::set<NOMAD::direction_type>::iterator end = _direction_types.end(); - while (it != end) - { - _direction_types.erase(it); - _direction_types.insert(NOMAD::ORTHO_NP1_NEG); - it=_direction_types.find(NOMAD::ORTHO_NP1_QUAD); - } + std::set<NOMAD::direction_type>::iterator it=_direction_types.find(NOMAD::ORTHO_NP1_QUAD); + std::set<NOMAD::direction_type>::iterator end = _direction_types.end(); + while (it != end) + { + _direction_types.erase(it); + _direction_types.insert(NOMAD::ORTHO_NP1_NEG); + it=_direction_types.find(NOMAD::ORTHO_NP1_QUAD); + } } // set_SEC_POLL_DIR_TYPE (1/2): void NOMAD::Parameters::set_SEC_POLL_DIR_TYPE ( NOMAD::direction_type dt ) { - _to_be_checked = true; - if ( dt == NOMAD::UNDEFINED_DIRECTION || dt == NOMAD::MODEL_SEARCH_DIR ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SEC_POLL_DIR_TYPE" ); - _sec_poll_dir_types.insert ( dt ); + _to_be_checked = true; + if ( dt == NOMAD::UNDEFINED_DIRECTION || dt == NOMAD::MODEL_SEARCH_DIR ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SEC_POLL_DIR_TYPE" ); + _sec_poll_dir_types.insert ( dt ); } // set_SEC_POLL_DIR_TYPE (2/2): void NOMAD::Parameters::set_SEC_POLL_DIR_TYPE ( const std::set<NOMAD::direction_type> & dt ) { - std::set<NOMAD::direction_type>::const_iterator it , end = dt.end(); - for ( it = dt.begin() ; it != end ; ++it ) - set_SEC_POLL_DIR_TYPE ( *it ); + std::set<NOMAD::direction_type>::const_iterator it , end = dt.end(); + for ( it = dt.begin() ; it != end ; ++it ) + set_SEC_POLL_DIR_TYPE ( *it ); } // set_RHO: void NOMAD::Parameters::set_RHO ( const NOMAD::Double & rho ) { - if ( !rho.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: RHO" ); - _to_be_checked = true; - _rho = rho; + if ( !rho.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: RHO" ); + _to_be_checked = true; + _rho = rho; } // set_H_MIN: void NOMAD::Parameters::set_H_MIN ( const NOMAD::Double & h_min ) { - if ( !h_min.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: H_MIN" ); - _to_be_checked = true; - _h_min = h_min; + if ( !h_min.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , "invalid parameter: H_MIN" ); + _to_be_checked = true; + _h_min = h_min; } // set_H_MAX_0: void NOMAD::Parameters::set_H_MAX_0 ( const NOMAD::Double & h_max ) { - _to_be_checked = true; - _h_max_0 = ( h_max.is_defined() ) ? h_max : NOMAD::INF; + _to_be_checked = true; + _h_max_0 = ( h_max.is_defined() ) ? h_max : NOMAD::INF; } // set_H_NORM: void NOMAD::Parameters::set_H_NORM ( NOMAD::hnorm_type h_norm ) { - _to_be_checked = true; - _h_norm = h_norm; + _to_be_checked = true; + _h_norm = h_norm; } // set_SCALING (1/2): void NOMAD::Parameters::set_SCALING ( int index , const NOMAD::Double & value ) { - _to_be_checked = true; - if ( index < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SCALING" ); - if ( index >= _scaling.size() ) - _scaling.resize ( index + 1 ); - - _scaling[index] = value; + _to_be_checked = true; + if ( index < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SCALING" ); + if ( index >= _scaling.size() ) + _scaling.resize ( index + 1 ); + + _scaling[index] = value; } // set_SCALING (2/2): void NOMAD::Parameters::set_SCALING ( const NOMAD::Point & s ) { - _to_be_checked = true; - _scaling = s; + _to_be_checked = true; + _scaling = s; } // set_FIXED_VARIABLE (1/3): void NOMAD::Parameters::set_FIXED_VARIABLE ( int index , const NOMAD::Double & value ) { - _to_be_checked = true; - if ( index < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE" ); - if ( index >= _fixed_variables.size() ) - _fixed_variables.resize ( index + 1 ); - - _fixed_variables[index] = value; + _to_be_checked = true; + if ( index < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE" ); + if ( index >= _fixed_variables.size() ) + _fixed_variables.resize ( index + 1 ); + + _fixed_variables[index] = value; } // set_FIXED_VARIABLE (2/3): void NOMAD::Parameters::set_FIXED_VARIABLE ( int index ) { - _to_be_checked = true; - if ( index < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE (index < 0)" ); - if ( _x0s.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE (no starting point defined)" ); - - if ( index >= _x0s[0]->size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: FIXED_VARIABLE (incompatible starting point)" ); - - if ( index >= _fixed_variables.size() ) - _fixed_variables.resize ( index + 1 ); - - _fixed_variables[index] = (*_x0s[0])[index]; + _to_be_checked = true; + if ( index < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE (index < 0)" ); + if ( _x0s.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE (no starting point defined)" ); + + if ( index >= _x0s[0]->size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: FIXED_VARIABLE (incompatible starting point)" ); + + if ( index >= _fixed_variables.size() ) + _fixed_variables.resize ( index + 1 ); + + _fixed_variables[index] = (*_x0s[0])[index]; } // set_FIXED_VARIABLE (2/3): void NOMAD::Parameters::set_FIXED_VARIABLE ( const NOMAD::Point & fv ) { - _to_be_checked = true; - _fixed_variables = fv; + _to_be_checked = true; + _fixed_variables = fv; } // set_LOWER_BOUND (1/2): void NOMAD::Parameters::set_LOWER_BOUND ( int index, const NOMAD::Double & value ) { - _to_be_checked = true; - if (index < 0) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: LOWER_BOUND" ); - if ( index >= _lb.size() ) - _lb.resize(index+1); - if ( !_lb[index].is_defined() || value > _lb[index] ) - _lb[index] = value; + _to_be_checked = true; + if (index < 0) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: LOWER_BOUND" ); + if ( index >= _lb.size() ) + _lb.resize(index+1); + if ( !_lb[index].is_defined() || value > _lb[index] ) + _lb[index] = value; } // set_LOWER_BOUND (2/2): void NOMAD::Parameters::set_LOWER_BOUND ( const NOMAD::Point & lb ) { - _to_be_checked = true; - _lb = lb; + _to_be_checked = true; + _lb = lb; } // set_UPPER_BOUND (1/2): void NOMAD::Parameters::set_UPPER_BOUND ( int index, const NOMAD::Double & value ) { - _to_be_checked = true; - if (index < 0) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: UPPER_BOUND" ); - if ( index >= _ub.size() ) - _ub.resize (index + 1); - if ( !_ub[index].is_defined() || value < _ub[index] ) - _ub[index] = value; + _to_be_checked = true; + if (index < 0) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: UPPER_BOUND" ); + if ( index >= _ub.size() ) + _ub.resize (index + 1); + if ( !_ub[index].is_defined() || value < _ub[index] ) + _ub[index] = value; } // set_UPPER_BOUND (2/2): void NOMAD::Parameters::set_UPPER_BOUND ( const NOMAD::Point & ub ) { - _to_be_checked = true; - _ub = ub; + _to_be_checked = true; + _ub = ub; } // set_SGTE_COST: void NOMAD::Parameters::set_SGTE_COST ( int c ) { - _to_be_checked = true; - _sgte_cost = ( c > 0 ) ? c : -1; + _to_be_checked = true; + _sgte_cost = ( c > 0 ) ? c : -1; } // set_SGTE_EVAL_SORT: void NOMAD::Parameters::set_SGTE_EVAL_SORT ( bool ses ) { - _to_be_checked = true; - _sgte_eval_sort = ses; + _to_be_checked = true; + _sgte_eval_sort = ses; } // set_HAS_SGTET: void NOMAD::Parameters::set_HAS_SGTE ( bool hs ) { - _to_be_checked = true; - _has_sgte = hs; + _to_be_checked = true; + _has_sgte = hs; } // set_OPT_ONLY_SGTE: void NOMAD::Parameters::set_OPT_ONLY_SGTE ( bool oos ) { - _to_be_checked = true; - _opt_only_sgte = oos; + _to_be_checked = true; + _opt_only_sgte = oos; } // set_SGTE_EXE: void NOMAD::Parameters::set_SGTE_EXE ( const std::string & bb_exe , - const std::string & sgte_exe ) + const std::string & sgte_exe ) { - _to_be_checked = true; - _sgte_exe[bb_exe] = sgte_exe; + _to_be_checked = true; + _sgte_exe[bb_exe] = sgte_exe; } // set_BB_EXE (1/3): void NOMAD::Parameters::set_BB_EXE ( const std::string & bbexe ) { - _to_be_checked = true; - if ( _bb_output_type.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE - BB_OUTPUT_TYPE must be defined first" ); - _bb_exe.clear(); - size_t nk = _bb_output_type.size(); - for ( size_t k = 0 ; k < nk ; ++k ) - _bb_exe.push_back ( bbexe ); + _to_be_checked = true; + if ( _bb_output_type.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE - BB_OUTPUT_TYPE must be defined first" ); + _bb_exe.clear(); + size_t nk = _bb_output_type.size(); + for ( size_t k = 0 ; k < nk ; ++k ) + _bb_exe.push_back ( bbexe ); } // set_BB_EXE (2/3): void NOMAD::Parameters::set_BB_EXE ( int m , const std::string * bbexe ) { - _to_be_checked = true; - - if ( m <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE" ); - - if ( m != static_cast<int>(_bb_output_type.size()) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE - number of names or BB_OUTPUT_TYPE undefined" ); - - size_t nk = _bb_output_type.size(); - for ( size_t k = 0 ; k < nk ; ++k ) - _bb_exe.push_back ( bbexe[k] ); + _to_be_checked = true; + + if ( m <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE" ); + + if ( m != static_cast<int>(_bb_output_type.size()) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE - number of names or BB_OUTPUT_TYPE undefined" ); + + size_t nk = _bb_output_type.size(); + for ( size_t k = 0 ; k < nk ; ++k ) + _bb_exe.push_back ( bbexe[k] ); } // set_BB_EXE (3/3): void NOMAD::Parameters::set_BB_EXE ( const std::list<std::string> & bbexe ) { - _to_be_checked = true; - if ( !bbexe.empty() && bbexe.size() != _bb_output_type.size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_EXE - number of names or BB_OUTPUT_TYPE undefined" ); - _bb_exe = bbexe; + _to_be_checked = true; + if ( !bbexe.empty() && bbexe.size() != _bb_output_type.size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_EXE - number of names or BB_OUTPUT_TYPE undefined" ); + _bb_exe = bbexe; } // set_BB_INPUT_INCLUDE_TAG: void NOMAD::Parameters::set_BB_INPUT_INCLUDE_TAG ( bool bbiit ) { - _to_be_checked = true; - _bb_input_include_tag = bbiit; + _to_be_checked = true; + _bb_input_include_tag = bbiit; } // set_BB_INPUT_INCLUDE_SEED: void NOMAD::Parameters::set_BB_INPUT_INCLUDE_SEED ( bool bbiis ) { - _to_be_checked = true; - _bb_input_include_seed = bbiis; + _to_be_checked = true; + _bb_input_include_seed = bbiis; } // set_BB_REDIRECTION: void NOMAD::Parameters::set_BB_REDIRECTION ( bool bbr ) { - _to_be_checked = true; - _bb_redirection = bbr; + _to_be_checked = true; + _bb_redirection = bbr; } // set_BB_INPUT_TYPE (1/3): void NOMAD::Parameters::set_BB_INPUT_TYPE ( int index , NOMAD::bb_input_type bbit ) { - _to_be_checked = true; - if ( index < 0 || index >= _dimension || - static_cast<int>(_bb_input_type.size()) != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_INPUT_TYPE" ); - _bb_input_type[index] = bbit; + _to_be_checked = true; + if ( index < 0 || index >= _dimension || + static_cast<int>(_bb_input_type.size()) != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_INPUT_TYPE" ); + _bb_input_type[index] = bbit; } // set_BB_INPUT_TYPE (2/3): void NOMAD::Parameters::set_BB_INPUT_TYPE ( const std::vector<NOMAD::bb_input_type > & bbit ) { - int n = static_cast<int>(bbit.size()); - for ( int i = 0 ; i < n ; ++i ) - set_BB_INPUT_TYPE ( i , bbit[i] ); + int n = static_cast<int>(bbit.size()); + for ( int i = 0 ; i < n ; ++i ) + set_BB_INPUT_TYPE ( i , bbit[i] ); } // set_BB_INPUT_TYPE (3/3): void NOMAD::Parameters::set_BB_INPUT_TYPE ( const std::list<NOMAD::bb_input_type > & bbit ) { - int i = 0; - std::list<NOMAD::bb_input_type>::const_iterator it , end = bbit.end(); - for ( it = bbit.begin() ; it != end ; ++it , ++i ) - set_BB_INPUT_TYPE ( i , *it ); + int i = 0; + std::list<NOMAD::bb_input_type>::const_iterator it , end = bbit.end(); + for ( it = bbit.begin() ; it != end ; ++it , ++i ) + set_BB_INPUT_TYPE ( i , *it ); } // reset_PEB_changes: void NOMAD::Parameters::reset_PEB_changes ( void ) const { - size_t nk = _bb_output_type.size(); - for ( size_t k = 0 ; k < nk ; ++k ) - if ( _bb_output_type[k] == NOMAD::PEB_E ) - _bb_output_type[k] = NOMAD::PEB_P; + size_t nk = _bb_output_type.size(); + for ( size_t k = 0 ; k < nk ; ++k ) + if ( _bb_output_type[k] == NOMAD::PEB_E ) + _bb_output_type[k] = NOMAD::PEB_P; } - // change PEB to PB constraints void NOMAD::Parameters::change_PEB_to_PB ( void ) { - size_t nk = _bb_output_type.size(); - for ( size_t k = 0 ; k < nk ; ++k ) - if ( _bb_output_type[k] == NOMAD::PEB_P || _bb_output_type[k] == NOMAD::PEB_E ) - { - _bb_output_type[k] = NOMAD::PB; - _barrier_type = NOMAD::PB; - } + size_t nk = _bb_output_type.size(); + for ( size_t k = 0 ; k < nk ; ++k ) + if ( _bb_output_type[k] == NOMAD::PEB_P || _bb_output_type[k] == NOMAD::PEB_E ) + { + _bb_output_type[k] = NOMAD::PB; + _barrier_type = NOMAD::PB; + } } @@ -6372,998 +6617,1100 @@ void NOMAD::Parameters::change_PEB_to_PB ( void ) // change_PEB_constraint_status: void NOMAD::Parameters::change_PEB_constraint_status ( int index ) const { - if ( index < 0 || - index >= static_cast<int>(_bb_output_type.size()) || - _bb_output_type[index] != NOMAD::PEB_P ) - throw NOMAD::Exception ( "Parameters.cpp" , __LINE__ , - "error in Parameters::change_PEB_constraint_status(i): bad i" ); - _bb_output_type[index] = NOMAD::PEB_E; + if ( index < 0 || + index >= static_cast<int>(_bb_output_type.size()) || + _bb_output_type[index] != NOMAD::PEB_P ) + throw NOMAD::Exception ( "Parameters.cpp" , __LINE__ , + "error in Parameters::change_PEB_constraint_status(i): bad i" ); + _bb_output_type[index] = NOMAD::PEB_E; } // set_BB_OUTPUT_TYPE (1/2): void NOMAD::Parameters::set_BB_OUTPUT_TYPE ( const std::list<NOMAD::bb_output_type> & bbot ) { - int i = 0; - std::vector<NOMAD::bb_output_type> bbot_vector ( bbot.size() ); - std::list<NOMAD::bb_output_type>::const_iterator end = bbot.end() , it; - for ( it = bbot.begin() ; it != end ; ++it ) - bbot_vector[i++] = *it; - set_BB_OUTPUT_TYPE ( bbot_vector ); + int i = 0; + std::vector<NOMAD::bb_output_type> bbot_vector ( bbot.size() ); + std::list<NOMAD::bb_output_type>::const_iterator end = bbot.end() , it; + for ( it = bbot.begin() ; it != end ; ++it ) + bbot_vector[i++] = *it; + set_BB_OUTPUT_TYPE ( bbot_vector ); } // set_BB_OUTPUT_TYPE (2/2): void NOMAD::Parameters::set_BB_OUTPUT_TYPE ( const std::vector<NOMAD::bb_output_type> & bbot ) { - _to_be_checked = true; - - _barrier_type = NOMAD::EB; - _has_constraints = false; - _has_EB_constraints = false; - _has_filter_constraints = false; - - _bb_output_type.clear(); - - int m = static_cast<int>(bbot.size()); - - if ( m <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE" ); - if ( !_bb_output_type.empty() && - m != static_cast<int>(_bb_output_type.size()) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE - number of types" ); - - _bb_output_type.resize (m); - - bool filter_used = false; - bool pb_used = false; - bool peb_used = false; - - _index_obj.clear(); - - for ( int i = 0 ; i < m ; ++i ) - { - - _bb_output_type[i] = bbot[i]; - - switch ( bbot[i] ) - { - - case NOMAD::OBJ: - _index_obj.push_back(i); - break; - - case NOMAD::EB: - _has_constraints = true; - _has_EB_constraints = true; - break; - - case NOMAD::FILTER: - _has_constraints = true; - _has_filter_constraints = true; - filter_used = true; - break; - - case NOMAD::PB: - _has_constraints = true; - _has_filter_constraints = true; - pb_used = true; - break; - - case NOMAD::PEB_P: - case NOMAD::PEB_E: - _has_constraints = true; - _has_filter_constraints = true; - pb_used = true; - peb_used = true; - _bb_output_type[i] = NOMAD::PEB_P; - break; - default: - break; - } - } - - if ( _index_obj.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE - OBJ not given" ); - if ( filter_used && pb_used ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: BB_OUTPUT_TYPE - F and PB/PEB used together" ); - - if ( filter_used ) - _barrier_type = NOMAD::FILTER; - else if ( pb_used ) - _barrier_type = (peb_used) ? NOMAD::PEB_P : NOMAD::PB; + _to_be_checked = true; + + _barrier_type = NOMAD::EB; + _has_constraints = false; + _has_EB_constraints = false; + _has_filter_constraints = false; + + _bb_output_type.clear(); + + int m = static_cast<int>(bbot.size()); + + if ( m <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE" ); + if ( !_bb_output_type.empty() && + m != static_cast<int>(_bb_output_type.size()) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE - number of types" ); + + _bb_output_type.resize (m); + + bool filter_used = false; + bool pb_used = false; + bool peb_used = false; + + _index_obj.clear(); + + for ( int i = 0 ; i < m ; ++i ) + { + + _bb_output_type[i] = bbot[i]; + + switch ( bbot[i] ) + { + + case NOMAD::OBJ: + _index_obj.push_back(i); + break; + + case NOMAD::EB: + _has_constraints = true; + _has_EB_constraints = true; + break; + + case NOMAD::FILTER: + _has_constraints = true; + _has_filter_constraints = true; + filter_used = true; + break; + + case NOMAD::PB: + _has_constraints = true; + _has_filter_constraints = true; + pb_used = true; + break; + + case NOMAD::PEB_P: + case NOMAD::PEB_E: + _has_constraints = true; + _has_filter_constraints = true; + pb_used = true; + peb_used = true; + _bb_output_type[i] = NOMAD::PEB_P; + break; + default: + break; + } + } + + if ( _index_obj.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE - OBJ not given" ); + if ( filter_used && pb_used ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: BB_OUTPUT_TYPE - F and PB/PEB used together" ); + + if ( filter_used ) + _barrier_type = NOMAD::FILTER; + else if ( pb_used ) + _barrier_type = (peb_used) ? NOMAD::PEB_P : NOMAD::PB; } // set_PROBLEM_DIR: void NOMAD::Parameters::set_PROBLEM_DIR ( const std::string & dir ) { - _to_be_checked = true; - _problem_dir = dir; - if ( !_problem_dir.empty() && !NOMAD::Parameters::check_directory ( _problem_dir ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PROBLEM_DIR" ); + _to_be_checked = true; + _problem_dir = dir; + if ( !_problem_dir.empty() && !NOMAD::Parameters::check_directory ( _problem_dir ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PROBLEM_DIR" ); } // set_TMP_DIR: void NOMAD::Parameters::set_TMP_DIR ( const std::string & dir ) { - _to_be_checked = true; - _tmp_dir = dir; - if ( !_tmp_dir.empty() && !NOMAD::Parameters::check_directory ( _tmp_dir ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: TMP_DIR" ); + _to_be_checked = true; + _tmp_dir = dir; + if ( !_tmp_dir.empty() && !NOMAD::Parameters::check_directory ( _tmp_dir ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: TMP_DIR" ); } // set_ADD_SEED_TO_FILE_NAMES: void NOMAD::Parameters::set_ADD_SEED_TO_FILE_NAMES ( bool astfn ) { - _to_be_checked = true; - _add_seed_to_file_names = astfn; + _to_be_checked = true; + _add_seed_to_file_names = astfn; } // set_SOLUTION_FILE: void NOMAD::Parameters::set_SOLUTION_FILE ( const std::string & sf ) { - _to_be_checked = true; - _solution_file = sf; - if ( sf.empty() ) - return; - if ( !NOMAD::Parameters::check_directory ( _solution_file ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SOLUTION_FILE" ); - _solution_file.resize ( _solution_file.size()-1 ); + _to_be_checked = true; + _solution_file = sf; + if ( sf.empty() ) + return; + if ( !NOMAD::Parameters::check_directory ( _solution_file ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SOLUTION_FILE" ); + _solution_file.resize ( _solution_file.size()-1 ); } // set_HISTORY_FILE: void NOMAD::Parameters::set_HISTORY_FILE ( const std::string & hf ) { - _to_be_checked = true; - _history_file = hf; - if ( hf.empty() ) - return; - if ( !NOMAD::Parameters::check_directory ( _history_file ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: HISTORY_FILE" ); - _history_file.resize ( _history_file.size()-1 ); + _to_be_checked = true; + _history_file = hf; + if ( hf.empty() ) + return; + if ( !NOMAD::Parameters::check_directory ( _history_file ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: HISTORY_FILE" ); + _history_file.resize ( _history_file.size()-1 ); } // set_CACHE_FILE: void NOMAD::Parameters::set_CACHE_FILE ( const std::string & cf ) { - _to_be_checked = true; - _cache_file = cf; - if ( cf.empty() ) - return; - if ( !NOMAD::Parameters::check_directory ( _cache_file ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: CACHE_FILE" ); - _cache_file.resize ( _cache_file.size()-1 ); + _to_be_checked = true; + _cache_file = cf; + if ( cf.empty() ) + return; + if ( !NOMAD::Parameters::check_directory ( _cache_file ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: CACHE_FILE" ); + _cache_file.resize ( _cache_file.size()-1 ); } // set_SGTE_CACHE_FILE: void NOMAD::Parameters::set_SGTE_CACHE_FILE ( const std::string & cf ) { - _to_be_checked = true; - _sgte_cache_file = cf; - if ( cf.empty() ) - return; - if ( !NOMAD::Parameters::check_directory ( _sgte_cache_file ) ) { - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: SGTE_CACHE_FILE"); - } - _sgte_cache_file.resize ( _sgte_cache_file.size()-1 ); + _to_be_checked = true; + _sgte_cache_file = cf; + if ( cf.empty() ) + return; + if ( !NOMAD::Parameters::check_directory ( _sgte_cache_file ) ) { + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: SGTE_CACHE_FILE"); + } + _sgte_cache_file.resize ( _sgte_cache_file.size()-1 ); } // set_X0: // add a new point in the list of starting points: void NOMAD::Parameters::set_X0 ( const NOMAD::Point & x0 ) { - _to_be_checked = true; - _x0s.push_back ( new NOMAD::Point ( x0 ) ); + _to_be_checked = true; + _x0s.push_back ( new NOMAD::Point ( x0 ) ); } // indicate a x0 file or a cache file containing starting points: void NOMAD::Parameters::set_X0 ( const std::string & file_name ) { - _to_be_checked = true; - - if ( file_name.empty() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Parameters::set_X0(file_name): file_name is empty" ); - - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "Parameters::set_X0() has been used before setting DIMENSION" ); - - NOMAD::Point tmp_x0 ( _dimension ); - std::string complete_file_name = _problem_dir + file_name; - std::ifstream fin ( complete_file_name.c_str() ); - - if ( fin.fail() ) { - std::string err = "invalid parameter: X0 - could not open file \'" - + complete_file_name + "\'"; - fin.close(); - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); - } - - bool flag = true; - try { - fin >> tmp_x0; - } - catch ( NOMAD::Point::Bad_Input & ) { - flag = false; - - // we suppose that the file name corresponds to a cache file: - _x0_cache_file = file_name; - } - - while ( flag ) { - - set_X0 ( tmp_x0 ); - - // other starting points in the file ? - flag = true; - try { - fin >> tmp_x0; - } - catch ( NOMAD::Point::Bad_Input & ) { - flag = false; - } - } - - fin.close(); + _to_be_checked = true; + + if ( file_name.empty() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::set_X0(file_name): file_name is empty" ); + + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "Parameters::set_X0() has been used before setting DIMENSION" ); + + NOMAD::Point tmp_x0 ( _dimension ); + std::string complete_file_name = _problem_dir + file_name; + std::ifstream fin ( complete_file_name.c_str() ); + + if ( fin.fail() ) { + std::string err = "invalid parameter: X0 - could not open file \'" + + complete_file_name + "\'"; + fin.close(); + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , err ); + } + + bool flag = true; + try { + fin >> tmp_x0; + } + catch ( NOMAD::Point::Bad_Input & ) { + flag = false; + + // we suppose that the file name corresponds to a cache file: + _x0_cache_file = file_name; + } + + while ( flag ) { + + set_X0 ( tmp_x0 ); + + // other starting points in the file ? + flag = true; + try { + fin >> tmp_x0; + } + catch ( NOMAD::Point::Bad_Input & ) { + flag = false; + } + } + + fin.close(); } // set_DISPLAY_ALL_EVAL: void NOMAD::Parameters::set_DISPLAY_ALL_EVAL ( bool dae ) { - _to_be_checked = true; - _display_all_eval = dae; + _to_be_checked = true; + _display_all_eval = dae; } // set_DISPLAY_STATS (1/2): void NOMAD::Parameters::set_DISPLAY_STATS ( const std::list<std::string> & ls ) { - _display_stats.clear(); - _display_stats = ls; + _display_stats.clear(); + _display_stats = ls; } // set_DISPLAY_STATS (2/2): void NOMAD::Parameters::set_DISPLAY_STATS ( const std::string & stats ) { - if ( stats.empty() ) { - _display_stats.clear(); - return; - } - - NOMAD::Parameter_Entry pe ( "DISPLAY_STATS " + stats , false ); - - std::list<std::string>::const_iterator end = pe.get_values().end() , - it = pe.get_values().begin(); - std::list<std::string> ls; - - while ( it != end ) { - ls.push_back ( *it ); - ++it; - } - - ls.resize ( ls.size()-1 ); - - set_DISPLAY_STATS ( ls ); + if ( stats.empty() ) { + _display_stats.clear(); + return; + } + + NOMAD::Parameter_Entry pe ( "DISPLAY_STATS " + stats , false ); + + std::list<std::string>::const_iterator end = pe.get_values().end() , + it = pe.get_values().begin(); + std::list<std::string> ls; + + while ( it != end ) { + ls.push_back ( *it ); + ++it; + } + + ls.resize ( ls.size()-1 ); + + set_DISPLAY_STATS ( ls ); } // set_STATS_FILE (1/2): void NOMAD::Parameters::set_STATS_FILE ( const std::string & file_name , - const std::list<std::string> & ls ) -{ - if ( file_name.empty() ) { - reset_stats_file(); - return; - } - - _to_be_checked = true; - _stats_file = ls; - _stats_file_name = file_name; - - if ( !NOMAD::Parameters::check_directory ( _stats_file_name ) ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: STATS_FILE" ); - - _stats_file_name.resize ( _stats_file_name.size()-1 ); + const std::list<std::string> & ls ) +{ + if ( file_name.empty() ) { + reset_stats_file(); + return; + } + + _to_be_checked = true; + _stats_file = ls; + _stats_file_name = file_name; + + if ( !NOMAD::Parameters::check_directory ( _stats_file_name ) ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: STATS_FILE" ); + + _stats_file_name.resize ( _stats_file_name.size()-1 ); } // set_STATS_FILE (2/2): void NOMAD::Parameters::set_STATS_FILE ( const std::string & file_name , - const std::string & stats ) -{ - NOMAD::Parameter_Entry pe ( "STATS_FILE " + file_name + " " + stats , false ); - std::list<std::string>::const_iterator end = pe.get_values().end() , - it = pe.get_values().begin(); - std::list<std::string> ls; - ++it; - while ( it != end ) { - ls.push_back(*it); - ++it; - } - - ls.resize ( ls.size()-1 ); - - set_STATS_FILE ( file_name , ls ); + const std::string & stats ) +{ + NOMAD::Parameter_Entry pe ( "STATS_FILE " + file_name + " " + stats , false ); + std::list<std::string>::const_iterator end = pe.get_values().end() , + it = pe.get_values().begin(); + std::list<std::string> ls; + ++it; + while ( it != end ) { + ls.push_back(*it); + ++it; + } + + ls.resize ( ls.size()-1 ); + + set_STATS_FILE ( file_name , ls ); } // set_DISPLAY_DEGREE (1/3) - (accepts also dd_type arguments): bool NOMAD::Parameters::set_DISPLAY_DEGREE ( int dd ) { #ifndef DEBUG - return set_DISPLAY_DEGREE ( NOMAD::itos(dd) ); + return set_DISPLAY_DEGREE ( NOMAD::itos(dd) ); #endif - return true; + return true; } // set_DISPLAY_DEGREE (2/3): bool NOMAD::Parameters::set_DISPLAY_DEGREE ( const std::string & dd ) { #ifndef DEBUG - { - std::string ddu = dd; - NOMAD::toupper ( ddu ); - - if ( ddu == "NO" || ddu == "NO_DISPLAY" ) { - set_DISPLAY_DEGREE ( 0 , 0 , 0 , 0 ); - return true; - } - else if ( ddu == "MIN" || ddu == "MINIMAL" || ddu == "MINIMAL_DISPLAY" ) { - set_DISPLAY_DEGREE ( 1 , 1 , 1 , 1 ); - return true; - } - - else if ( ddu == "NORMAL" || ddu == "NORMAL_DISPLAY" ) { - set_DISPLAY_DEGREE ( 2 , 2 , 2 , 2 ); - return true; - } - - else if ( ddu == "FULL" || ddu == "FULL_DISPLAY" ) { - set_DISPLAY_DEGREE ( 3 , 3 , 3 , 3 ); - return true; - } - } - - if ( dd.size() == 1 ) { - int i; - if ( !NOMAD::atoi ( dd[0] , i ) ) - return false; - _out.set_degrees ( NOMAD::Display::int_to_dd(i) ); - return true; - } - - if ( dd.size() != 4 ) - return false; - - // 1. general display: - int gdd; - if ( !NOMAD::atoi ( dd[0] , gdd ) ) - return false; - - // 2. search display: - int sdd; - if ( !NOMAD::atoi ( dd[1] , sdd ) ) - return false; - - // 3. poll display: - int pdd; - if ( !NOMAD::atoi ( dd[2] , pdd ) ) - return false; - - // 4. iterative display: - int idd; - if ( !NOMAD::atoi ( dd[3] , idd ) ) - return false; - - set_DISPLAY_DEGREE ( gdd , sdd , pdd , idd ); - + { + std::string ddu = dd; + NOMAD::toupper ( ddu ); + + if ( ddu == "NO" || ddu == "NO_DISPLAY" ) { + set_DISPLAY_DEGREE ( 0 , 0 , 0 , 0 ); + return true; + } + else if ( ddu == "MIN" || ddu == "MINIMAL" || ddu == "MINIMAL_DISPLAY" ) { + set_DISPLAY_DEGREE ( 1 , 1 , 1 , 1 ); + return true; + } + + else if ( ddu == "NORMAL" || ddu == "NORMAL_DISPLAY" ) { + set_DISPLAY_DEGREE ( 2 , 2 , 2 , 2 ); + return true; + } + + else if ( ddu == "FULL" || ddu == "FULL_DISPLAY" ) { + set_DISPLAY_DEGREE ( 3 , 3 , 3 , 3 ); + return true; + } + } + + if ( dd.size() == 1 ) { + int i; + if ( !NOMAD::atoi ( dd[0] , i ) ) + return false; + _out.set_degrees ( NOMAD::Display::int_to_dd(i) ); + return true; + } + + if ( dd.size() != 4 ) + return false; + + // 1. general display: + int gdd; + if ( !NOMAD::atoi ( dd[0] , gdd ) ) + return false; + + // 2. search display: + int sdd; + if ( !NOMAD::atoi ( dd[1] , sdd ) ) + return false; + + // 3. poll display: + int pdd; + if ( !NOMAD::atoi ( dd[2] , pdd ) ) + return false; + + // 4. iterative display: + int idd; + if ( !NOMAD::atoi ( dd[3] , idd ) ) + return false; + + set_DISPLAY_DEGREE ( gdd , sdd , pdd , idd ); + #endif - return true; + return true; } // set_DISPLAY_DEGREE (3/3): void NOMAD::Parameters::set_DISPLAY_DEGREE ( int gen_dd , - int search_dd , - int poll_dd , - int iter_dd ) + int search_dd , + int poll_dd , + int iter_dd ) { #ifndef DEBUG - _out.set_degrees ( NOMAD::Display::int_to_dd ( gen_dd ) , - NOMAD::Display::int_to_dd ( search_dd ) , - NOMAD::Display::int_to_dd ( poll_dd ) , - NOMAD::Display::int_to_dd ( iter_dd ) ); + _out.set_degrees ( NOMAD::Display::int_to_dd ( gen_dd ) , + NOMAD::Display::int_to_dd ( search_dd ) , + NOMAD::Display::int_to_dd ( poll_dd ) , + NOMAD::Display::int_to_dd ( iter_dd ) ); #endif } // set_OPEN_BRACE: void NOMAD::Parameters::set_OPEN_BRACE ( const std::string & ob ) { - _to_be_checked = true; - _out.set_open_brace ( ob ); + _to_be_checked = true; + _out.set_open_brace ( ob ); } // set_CLOSED_BRACE: void NOMAD::Parameters::set_CLOSED_BRACE ( const std::string & cb ) { - _to_be_checked = true; - _out.set_closed_brace ( cb ); + _to_be_checked = true; + _out.set_closed_brace ( cb ); } // set_SEED: void NOMAD::Parameters::set_SEED ( int t ) { - _to_be_checked = true; - _seed = ( t < 0 ) ? NOMAD::get_pid() : t; + _to_be_checked = true; + _seed = ( t < 0 ) ? NOMAD::get_pid() : t; + + if ( t < 0 && t!=-1 && _out.get_gen_dd()>=NOMAD::NORMAL_DISPLAY && !_warning_has_been_displayed) + _out << NOMAD::open_block("Warning:") + << "Seed should be in the interval [0;INT_MAX] U {-1}. The seed is set to the process id!" << std::endl + << NOMAD::close_block(); + + // The RNG seed is set here when explicit set is required otherwise default RNG seed is used + NOMAD::RNG::set_seed(_seed); + } // set_MAX_EVAL: void NOMAD::Parameters::set_MAX_EVAL ( int e ) { - _to_be_checked = true; - _max_eval = ( e <= 0 ) ? -1 : e; + _to_be_checked = true; + _max_eval = ( e <= 0 ) ? -1 : e; } // set_MAX_BB_EVAL: void NOMAD::Parameters::set_MAX_BB_EVAL ( int bbe ) { - _to_be_checked = true; - _max_bbe_decided = true; - _max_bb_eval = ( bbe < 0 ) ? -1 : bbe; + _to_be_checked = true; + _max_bbe_decided = true; + _max_bb_eval = ( bbe < 0 ) ? -1 : bbe; } // set_MAX_SIM_BB_EVAL: void NOMAD::Parameters::set_MAX_SIM_BB_EVAL ( int bbe ) { - _to_be_checked = true; - _max_sim_bb_eval = ( bbe <= 0 ) ? -1 : bbe; + _to_be_checked = true; + _max_sim_bb_eval = ( bbe <= 0 ) ? -1 : bbe; } // set_MAX_SGTE_EVAL: void NOMAD::Parameters::set_MAX_SGTE_EVAL ( int bbe ) { - _to_be_checked = true; - _sgte_max_eval = ( bbe < 0 ) ? -1 : bbe; + _to_be_checked = true; + _sgte_max_eval = ( bbe < 0 ) ? -1 : bbe; } // set_MAX_TIME: void NOMAD::Parameters::set_MAX_TIME ( int t ) { - _to_be_checked = true; - _max_time = ( t <= 0 ) ? -1 : t; + _to_be_checked = true; + _max_time = ( t <= 0 ) ? -1 : t; } // set_MAX_ITERATIONS: void NOMAD::Parameters::set_MAX_ITERATIONS ( int it ) { - _to_be_checked = true; - _max_iterations = ( it < 0 ) ? -1 : it; + _to_be_checked = true; + _max_iterations = ( it < 0 ) ? -1 : it; } // set_MAX_CONSECUTIVE_FAILED_ITERATIONS: void NOMAD::Parameters::set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( int it ) { - _to_be_checked = true; - _max_cons_failed_it = ( it <= 0 ) ? -1 : it; + _to_be_checked = true; + _max_cons_failed_it = ( it <= 0 ) ? -1 : it; } // set_MAX_CACHE_MEMORY:: void NOMAD::Parameters::set_MAX_CACHE_MEMORY ( float mcm ) { - _to_be_checked = true; - _max_cache_memory = ( mcm < 0.0 ) ? -1 : mcm; + _to_be_checked = true; + _max_cache_memory = ( mcm < 0.0 ) ? -1 : mcm; } // set_CACHE_SAVE_PERIOD: void NOMAD::Parameters::set_CACHE_SAVE_PERIOD ( int csp ) { - _to_be_checked = true; - _cache_save_period = ( csp <= 0 ) ? -1 : csp; + _to_be_checked = true; + _cache_save_period = ( csp <= 0 ) ? -1 : csp; } // set_STOP_IF_FEASIBLE: void NOMAD::Parameters::set_STOP_IF_FEASIBLE ( bool sif ) { - _to_be_checked = true; - _stop_if_feasible = sif; + _to_be_checked = true; + _stop_if_feasible = sif; } // set_F_TARGET (1/2): void NOMAD::Parameters::set_F_TARGET ( const NOMAD::Double & f_target ) { - _to_be_checked = true; - _f_target = NOMAD::Point ( 1 , f_target ); + _to_be_checked = true; + _f_target = NOMAD::Point ( 1 , f_target ); } // set_F_TARGET (2/2): void NOMAD::Parameters::set_F_TARGET ( const NOMAD::Point & f_target ) { - _to_be_checked = true; - _f_target = f_target; + _to_be_checked = true; + _f_target = f_target; } // set_STAT_SUM_TARGET: void NOMAD::Parameters::set_STAT_SUM_TARGET ( const NOMAD::Double & sst ) { - _to_be_checked = true; - _stat_sum_target = sst; + _to_be_checked = true; + _stat_sum_target = sst; } // set_L_CURVE_TARGET: void NOMAD::Parameters::set_L_CURVE_TARGET ( const NOMAD::Double & lct ) { - _to_be_checked = true; - _L_curve_target = lct; + _to_be_checked = true; + _L_curve_target = lct; +} + +// set_ANISOTROPIC_MESH: +void NOMAD::Parameters::set_ANISOTROPIC_MESH ( bool anis ) +{ + _to_be_checked = true; + _anisotropic_mesh = anis; } + +// set_USE_SMESH: +void NOMAD::Parameters::set_USE_SMESH ( bool use_smesh ) +{ + _to_be_checked = true; + _use_smesh = use_smesh; +} + + + // set_MESH_UPDATE_BASIS: void NOMAD::Parameters::set_MESH_UPDATE_BASIS ( const NOMAD::Double & mub ) { - if ( !mub.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_UPDATE_BASIS" ); - _to_be_checked = true; - _mesh_update_basis = mub; + if ( !mub.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_UPDATE_BASIS" ); + _to_be_checked = true; + _mesh_update_basis = mub; +} + +// set_POLL_UPDATE_BASIS: +void NOMAD::Parameters::set_POLL_UPDATE_BASIS ( const NOMAD::Double & pub ) +{ + if ( !pub.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: POLL_UPDATE_BASIS" ); + _to_be_checked = true; + _poll_update_basis = pub; } + // set_INITIAL_MESH_INDEX: void NOMAD::Parameters::set_INITIAL_MESH_INDEX ( int ell_0 ) { - _to_be_checked = true; - if ( ell_0 > NOMAD::L_LIMITS ) - ell_0 = NOMAD::L_LIMITS; - else if ( ell_0 < - NOMAD::L_LIMITS ) - ell_0 = -NOMAD::L_LIMITS; - _initial_mesh_index = ell_0; + _to_be_checked = true; + if ( ell_0 > NOMAD::L_LIMITS ) + ell_0 = NOMAD::L_LIMITS; + else if ( ell_0 < - NOMAD::L_LIMITS ) + ell_0 = -NOMAD::L_LIMITS; + _initial_mesh_index = ell_0; } // set_MESH_COARSENING_EXPONENT: void NOMAD::Parameters::set_MESH_COARSENING_EXPONENT ( int mce ) { - _to_be_checked = true; - if ( mce < 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_COARSENING_EXPONENT"); - _mesh_coarsening_exponent = mce; + _to_be_checked = true; + if ( mce < 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_COARSENING_EXPONENT"); + _mesh_coarsening_exponent = mce; } // set_MESH_REFINING_EXPONENT: void NOMAD::Parameters::set_MESH_REFINING_EXPONENT ( int mre ) { - _to_be_checked = true; - if ( mre >= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MESH_REFINING_EXPONENT"); - _mesh_refining_exponent = mre; -} - -// set_MAX_MESH_INDEX: -void NOMAD::Parameters::set_MAX_MESH_INDEX ( int lmax ) -{ - _to_be_checked = true; - if ( lmax > NOMAD::L_LIMITS ) - lmax = NOMAD::L_LIMITS; - _max_mesh_index = lmax; + _to_be_checked = true; + if ( mre >= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MESH_REFINING_EXPONENT"); + _mesh_refining_exponent = mre; } // set_INITIAL_MESH_SIZE (1/3): void NOMAD::Parameters::set_INITIAL_MESH_SIZE ( int index , - const NOMAD::Double & d , - bool relative ) -{ - if ( index < 0 || index >= _initial_mesh_size.size() || !d.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE" ); - _to_be_checked = true; - - if ( relative ) { - - if ( !_lb.is_defined() || !_ub.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE - bounds not defined" ); - - if ( !_lb[index].is_defined() || !_ub[index].is_defined() || - d <= 0.0 || d > 1.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE - relative value" ); - - NOMAD::Double d2 = d; - d2 *= _ub[index] - _lb[index]; - _initial_mesh_size[index] = d2; - } - else - _initial_mesh_size[index] = d; + const NOMAD::Double & d , + bool relative ) +{ + if ( index < 0 || index >= _initial_mesh_size.size() || !d.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE" ); + _to_be_checked = true; + + if ( relative ) + { + + if ( !_lb.is_defined() || !_ub.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE - bounds not defined" ); + + if ( !_lb[index].is_defined() || !_ub[index].is_defined() || + d <= 0.0 || d > 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE - relative value" ); + + NOMAD::Double d2 = d; + d2 *= _ub[index] - _lb[index]; + _initial_mesh_size[index] = d2; + } + else + _initial_mesh_size[index] = d; } // set_INITIAL_MESH_SIZE (2/3): void NOMAD::Parameters::set_INITIAL_MESH_SIZE ( const NOMAD::Point & delta_m_0 , - bool relative ) + bool relative ) { - _to_be_checked = true; - if ( relative ) { - int nd = delta_m_0.size(); - for ( int i = 0 ; i < nd ; ++i ) - set_INITIAL_MESH_SIZE ( i , delta_m_0[i] , true ); - } - else - _initial_mesh_size = delta_m_0; + _to_be_checked = true; + if ( relative ) + { + int nd = delta_m_0.size(); + for ( int i = 0 ; i < nd ; ++i ) + set_INITIAL_MESH_SIZE ( i , delta_m_0[i] , true ); + } + else + _initial_mesh_size = delta_m_0; } // set_INITIAL_MESH_SIZE (3/3): void NOMAD::Parameters::set_INITIAL_MESH_SIZE ( const NOMAD::Double & d , bool relative ) { - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: INITIAL_MESH_SIZE - undefined dimension" ); - _to_be_checked = true; - if ( relative ) - for ( int i = 0 ; i < _dimension ; ++i ) - set_INITIAL_MESH_SIZE ( i , d , true ); - else - _initial_mesh_size = NOMAD::Point ( _dimension , d ); + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_MESH_SIZE - undefined dimension" ); + _to_be_checked = true; + if ( relative ) + for ( int i = 0 ; i < _dimension ; ++i ) + set_INITIAL_MESH_SIZE ( i , d , true ); + else + _initial_mesh_size = NOMAD::Point ( _dimension , d ); +} + +// set_INITIAL_POLL_SIZE (1/3): +void NOMAD::Parameters::set_INITIAL_POLL_SIZE ( int index , + const NOMAD::Double & d , + bool relative ) +{ + if ( index < 0 || index >= _initial_poll_size.size() || !d.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_POLL_SIZE" ); + _to_be_checked = true; + + if ( relative ) + { + + if ( !_lb.is_defined() || !_ub.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_POLL_SIZE - bounds not defined" ); + + if ( !_lb[index].is_defined() || !_ub[index].is_defined() || + d <= 0.0 || d > 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_POLL_SIZE - relative value" ); + + NOMAD::Double d2 = d; + d2 *= _ub[index] - _lb[index]; + _initial_poll_size[index] = d2; + } + else + _initial_poll_size[index] = d; +} + +// set_INITIAL_POLL_SIZE (2/3): +void NOMAD::Parameters::set_INITIAL_POLL_SIZE ( const NOMAD::Point & delta_m_0 , + bool relative ) +{ + _to_be_checked = true; + if ( relative ) + { + int nd = delta_m_0.size(); + for ( int i = 0 ; i < nd ; ++i ) + set_INITIAL_POLL_SIZE ( i , delta_m_0[i] , true ); + } + else + _initial_poll_size = delta_m_0; +} + +// set_INITIAL_POLL_SIZE (3/3): +void NOMAD::Parameters::set_INITIAL_POLL_SIZE ( const NOMAD::Double & d , bool relative ) +{ + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: INITIAL_POLL_SIZE - undefined dimension" ); + _to_be_checked = true; + if ( relative ) + for ( int i = 0 ; i < _dimension ; ++i ) + set_INITIAL_POLL_SIZE ( i , d , true ); + else + _initial_poll_size = NOMAD::Point ( _dimension , d ); } + + // set_MIN_MESH_SIZE (1/3): void NOMAD::Parameters::set_MIN_MESH_SIZE ( int index , - const NOMAD::Double & d , - bool relative ) -{ - if (_dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE - undefined dimension" ); - - if ( !_min_mesh_size.is_defined() ) - _min_mesh_size = NOMAD::Point ( _dimension ); - - if ( index < 0 || index >= _min_mesh_size.size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE" ); - _to_be_checked = true; - if ( relative ) { - - if ( !_lb.is_defined() || !_ub.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE - bounds not defined" ); - - if ( !_lb[index].is_defined() || !_ub[index].is_defined() || - !d.is_defined() || d <= 0.0 || d > 1.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE - relative value" ); - NOMAD::Double d2 = d; - d2 *= _ub[index] - _lb[index]; - _min_mesh_size[index] = d2; - } - else - _min_mesh_size[index] = d; + const NOMAD::Double & d , + bool relative ) +{ + if (_dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE - undefined dimension" ); + + if ( !_min_mesh_size.is_defined() ) + _min_mesh_size = NOMAD::Point ( _dimension ); + + if ( index < 0 || index >= _min_mesh_size.size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE" ); + _to_be_checked = true; + if ( relative ) + { + + if ( !_lb.is_defined() || !_ub.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE - bounds not defined" ); + + if ( !_lb[index].is_defined() || !_ub[index].is_defined() || + !d.is_defined() || d <= 0.0 || d > 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE - relative value" ); + NOMAD::Double d2 = d; + d2 *= _ub[index] - _lb[index]; + _min_mesh_size[index] = d2; + } + else + _min_mesh_size[index] = d; } // set_MIN_MESH_SIZE (2/3): void NOMAD::Parameters::set_MIN_MESH_SIZE ( const NOMAD::Point & delta_p_min , - bool relative ) + bool relative ) { - _to_be_checked = true; - if ( relative ) { - int nd = delta_p_min.size(); - for ( int i = 0 ; i < nd ; ++i ) - set_MIN_MESH_SIZE ( i , delta_p_min[i] , true ); - } - else - _min_mesh_size = delta_p_min; + _to_be_checked = true; + if ( relative ) + { + int nd = delta_p_min.size(); + for ( int i = 0 ; i < nd ; ++i ) + set_MIN_MESH_SIZE ( i , delta_p_min[i] , true ); + } + else + _min_mesh_size = delta_p_min; } // set_MIN_MESH_SIZE (3/3): void NOMAD::Parameters::set_MIN_MESH_SIZE ( const NOMAD::Double & d , bool relative ) { - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_MESH_SIZE - undefined dimension" ); - _to_be_checked = true; - if ( relative ) - for ( int i = 0 ; i < _dimension ; ++i ) - set_MIN_MESH_SIZE ( i , d , true ); - else - _min_mesh_size = NOMAD::Point ( _dimension , d ); + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_MESH_SIZE - undefined dimension" ); + _to_be_checked = true; + if ( relative ) + for ( int i = 0 ; i < _dimension ; ++i ) + set_MIN_MESH_SIZE ( i , d , true ); + else + _min_mesh_size = NOMAD::Point ( _dimension , d ); } // set_MIN_POLL_SIZE (1/3): void NOMAD::Parameters::set_MIN_POLL_SIZE ( int index , - const NOMAD::Double & d , - bool relative ) -{ - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_POLL_SIZE - undefined dimension" ); - - if ( !_min_poll_size.is_defined() ) - _min_poll_size = NOMAD::Point ( _dimension ); - - if ( index < 0 || index >= _min_poll_size.size() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_POLL_SIZE" ); - _to_be_checked = true; - if ( relative ) { - if ( !_lb[index].is_defined() || !_ub[index].is_defined() || - !d.is_defined() || d <= 0.0 || d > 1.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_POLL_SIZE - relative value" ); - _min_poll_size[index] = d * ( _ub[index] - _lb[index] ); - } - else - _min_poll_size[index] = d; + const NOMAD::Double & d , + bool relative ) +{ + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_POLL_SIZE - undefined dimension" ); + + if ( !_min_poll_size.is_defined() ) + _min_poll_size = NOMAD::Point ( _dimension ); + + if ( index < 0 || index >= _min_poll_size.size() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_POLL_SIZE" ); + _to_be_checked = true; + if ( relative ) { + if ( !_lb[index].is_defined() || !_ub[index].is_defined() || + !d.is_defined() || d <= 0.0 || d > 1.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_POLL_SIZE - relative value" ); + _min_poll_size[index] = d * ( _ub[index] - _lb[index] ); + } + else + _min_poll_size[index] = d; } // set_MIN_POLL_SIZE (2/3): void NOMAD::Parameters::set_MIN_POLL_SIZE ( const NOMAD::Point & delta_p_min , - bool relative ) + bool relative ) { - _to_be_checked = true; - if ( relative ) { - int nd = delta_p_min.size(); - for ( int i = 0 ; i < nd ; ++i ) - set_MIN_POLL_SIZE ( i , delta_p_min[i] , true ); - } - else - _min_poll_size = delta_p_min; + _to_be_checked = true; + if ( relative ) { + int nd = delta_p_min.size(); + for ( int i = 0 ; i < nd ; ++i ) + set_MIN_POLL_SIZE ( i , delta_p_min[i] , true ); + } + else + _min_poll_size = delta_p_min; } // set_MIN_POLL_SIZE (3/3): void NOMAD::Parameters::set_MIN_POLL_SIZE ( const NOMAD::Double & d , bool relative ) { - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MIN_POLL_SIZE - undefined dimension" ); - _to_be_checked = true; - if ( relative ) - for ( int i = 0 ; i < _dimension ; ++i ) - set_MIN_POLL_SIZE ( i , d , true ); - else - _min_poll_size = NOMAD::Point ( _dimension , d ); + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MIN_POLL_SIZE - undefined dimension" ); + _to_be_checked = true; + if ( relative ) + for ( int i = 0 ; i < _dimension ; ++i ) + set_MIN_POLL_SIZE ( i , d , true ); + else + _min_poll_size = NOMAD::Point ( _dimension , d ); } // set_NEIGHBORS_EXE: void NOMAD::Parameters::set_NEIGHBORS_EXE ( const std::string & ne ) { - _to_be_checked = true; - _neighbors_exe = ne; + _to_be_checked = true; + _neighbors_exe = ne; } // set_EXTENDED_POLL_TRIGGER: void NOMAD::Parameters::set_EXTENDED_POLL_TRIGGER ( const NOMAD::Double & ept , - bool relative ) + bool relative ) { - _to_be_checked = true; - - if ( !ept.is_defined() ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_TRIGGER (undefined)" ); - - if ( ept <= 0.0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: EXTENDED_POLL_TRIGGER: must be strictly positive" ); + _to_be_checked = true; - _extended_poll_trigger = ept; - _relative_ept = relative; + if ( !ept.is_defined() ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_TRIGGER (undefined)" ); + + if ( ept <= 0.0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: EXTENDED_POLL_TRIGGER: must be strictly positive" ); + + _extended_poll_trigger = ept; + _relative_ept = relative; } // set_EXTENDED_POLL_ENABLED: void NOMAD::Parameters::set_EXTENDED_POLL_ENABLED ( bool epe ) { - _to_be_checked = true; - _extended_poll_enabled = epe; + _to_be_checked = true; + _extended_poll_enabled = epe; } // set_USER_CALLS_ENABLED: void NOMAD::Parameters::set_USER_CALLS_ENABLED ( bool uce ) { - _to_be_checked = true; - _user_calls_enabled = uce; + _to_be_checked = true; + _user_calls_enabled = uce; } // set_ASYNCHRONOUS: void NOMAD::Parameters::set_ASYNCHRONOUS ( bool a ) { - _to_be_checked = true; - _asynchronous = a; + _to_be_checked = true; + _asynchronous = a; } // set_MULTI_NB_MADS_RUNS: void NOMAD::Parameters::set_MULTI_NB_MADS_RUNS ( int i ) -{ - if ( i == 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_NB_MADS_RUNS - has been set to zero" ); - - _to_be_checked = true; - _multi_nb_mads_runs = ( i < 0 ) ? -1 : i; +{ + if ( i == 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_NB_MADS_RUNS - has been set to zero" ); + + _to_be_checked = true; + _multi_nb_mads_runs = ( i < 0 ) ? -1 : i; } // set_MULTI_OVERALL_BB_EVAL: void NOMAD::Parameters::set_MULTI_OVERALL_BB_EVAL ( int i ) { - _to_be_checked = true; - _multi_overall_bb_eval = ( i < 0 ) ? -1 : i; -} + _to_be_checked = true; + _multi_overall_bb_eval = ( i < 0 ) ? -1 : i; +} // set_MULTI_USE_DELTA_CRIT: void NOMAD::Parameters::set_MULTI_USE_DELTA_CRIT ( bool b ) { - _to_be_checked = true; - _multi_use_delta_crit = b; + _to_be_checked = true; + _multi_use_delta_crit = b; } // set_MULTI_F_BOUNDS: void NOMAD::Parameters::set_MULTI_F_BOUNDS ( const NOMAD::Point & p ) { - _to_be_checked = true; - if ( p.size() != 4 || p[0] >= p[1] || p[2] >= p[3] ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: MULTI_F_BOUNDS" ); - _multi_f_bounds = p; + _to_be_checked = true; + if ( p.size() != 4 || p[0] >= p[1] || p[2] >= p[3] ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: MULTI_F_BOUNDS" ); + _multi_f_bounds = p; } // set_MULTI_FORMULATION: void NOMAD::Parameters::set_MULTI_FORMULATION ( NOMAD::multi_formulation_type mft ) { - _to_be_checked = true; - _multi_formulation = mft; + _to_be_checked = true; + _multi_formulation = mft; +} + +void NOMAD::Parameters::set_BB_MAX_BLOCK_SIZE ( int max_block_size ) +{ + _to_be_checked = true; + _bb_max_block_size = max_block_size; + + if ( _bb_max_block_size > 1 ) + _eval_points_as_block=true; + + } + + // set_OPPORTUNISTIC_LH: void NOMAD::Parameters::set_OPPORTUNISTIC_LH ( bool opp ) { - _to_be_checked = true; - _opportunistic_LH = opp; - _opp_LH_is_defined = true; + _to_be_checked = true; + _opportunistic_LH = opp; + _opp_LH_is_defined = true; } // set_OPPORTUNISTIC_CACHE_SEARCH: void NOMAD::Parameters::set_OPPORTUNISTIC_CACHE_SEARCH ( bool opp ) { - _to_be_checked = true; - _opportunistic_cache_search = opp; - _opp_CS_is_defined = true; + _to_be_checked = true; + _opportunistic_cache_search = opp; + _opp_CS_is_defined = true; } // set_OPPORTUNISTIC_EVAL: void NOMAD::Parameters::set_OPPORTUNISTIC_EVAL ( bool oe ) { - _to_be_checked = true; - _opportunistic_eval = oe; + _to_be_checked = true; + _opportunistic_eval = oe; } // set_OPPORTUNISTIC_MIN_NB_SUCCESS: void NOMAD::Parameters::set_OPPORTUNISTIC_MIN_NB_SUCCESS ( int mns ) { - _to_be_checked = true; - if ( mns <= 0 ) - mns = -1; - _opportunistic_min_nb_success = mns; + _to_be_checked = true; + if ( mns <= 0 ) + mns = -1; + _opportunistic_min_nb_success = mns; } // set_OPPORTUNISTIC_MIN_EVAL: void NOMAD::Parameters::set_OPPORTUNISTIC_MIN_EVAL ( int me ) { - _to_be_checked = true; - if ( me <= 0 ) - me = -1; - _opportunistic_min_eval = me; + _to_be_checked = true; + if ( me <= 0 ) + me = -1; + _opportunistic_min_eval = me; } // set_OPPORTUNISTIC_MIN_F_IMPRVMT: void NOMAD::Parameters::set_OPPORTUNISTIC_MIN_F_IMPRVMT ( const NOMAD::Double & mfi ) { - _to_be_checked = true; - if ( !mfi.is_defined() || mfi <= 0.0 ) - _opportunistic_min_f_imprvmt.clear(); - else - _opportunistic_min_f_imprvmt = mfi; + _to_be_checked = true; + if ( !mfi.is_defined() || mfi <= 0.0 ) + _opportunistic_min_f_imprvmt.clear(); + else + _opportunistic_min_f_imprvmt = mfi; } // set_OPPORTUNISTIC_LUCKY_EVAL: void NOMAD::Parameters::set_OPPORTUNISTIC_LUCKY_EVAL ( bool le ) { - _to_be_checked = true; - _opportunistic_lucky_eval = le; + _to_be_checked = true; + _opportunistic_lucky_eval = le; } // set_PERIODIC_VARIABLE (1/2): void NOMAD::Parameters::set_PERIODIC_VARIABLE ( int index ) { - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE - undefined dimension" ); - - if ( index < 0 || index >= _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: PERIODIC_VARIABLE - bad variable index" ); - - if ( _periodic_variables.empty() ) - for ( int i = 0 ; i < _dimension ; ++i ) - _periodic_variables.push_back ( false ); - - _periodic_variables[index] = true; - _to_be_checked = true; + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE - undefined dimension" ); + + if ( index < 0 || index >= _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: PERIODIC_VARIABLE - bad variable index" ); + + if ( _periodic_variables.empty() ) + for ( int i = 0 ; i < _dimension ; ++i ) + _periodic_variables.push_back ( false ); + + _periodic_variables[index] = true; + _to_be_checked = true; } // set_PERIODIC_VARIABLE (2/2): void NOMAD::Parameters::set_PERIODIC_VARIABLE ( const std::vector<bool> & pv ) { - _to_be_checked = true; - _periodic_variables = pv; + _to_be_checked = true; + _periodic_variables = pv; } // set_VARIABLE_GROUP (1/3): -void NOMAD::Parameters::set_VARIABLE_GROUP ( const std::set<int> & var_indexes , - int halton_seed ) -{ - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP - undefined dimension" ); - - if ( _bb_input_type.empty() || - static_cast<int>(_bb_input_type.size()) != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP - undefined blackbox input types" ); - - _to_be_checked = true; - - std::set<NOMAD::direction_type> empty; - - _user_var_groups.insert ( new NOMAD::Variable_Group ( var_indexes , - empty , - empty , - halton_seed , - _out ) ); +void NOMAD::Parameters::set_VARIABLE_GROUP ( const std::set<int> & var_indexes ) +{ + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP - undefined dimension" ); + + if ( _bb_input_type.empty() || + static_cast<int>(_bb_input_type.size()) != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP - undefined blackbox input types" ); + + _to_be_checked = true; + + std::set<NOMAD::direction_type> empty; + + _user_var_groups.insert ( new NOMAD::Variable_Group ( var_indexes , + empty , + empty , + _out ) ); } // set_VARIABLE_GROUP (2/3): void NOMAD::Parameters::set_VARIABLE_GROUP ( const std::set<int> & var_indexes , const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed ) -{ - if ( _dimension <= 0 ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP - undefined dimension" ); - - if ( _bb_input_type.empty() || - static_cast<int>(_bb_input_type.size()) != _dimension ) - throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , - "invalid parameter: VARIABLE_GROUP - undefined blackbox input types" ); - - _to_be_checked = true; - - std::set<NOMAD::direction_type> dt = direction_types; - if ( dt.empty() ) - dt.insert ( NOMAD::ORTHO_NP1_QUAD ); - - _user_var_groups.insert ( new NOMAD::Variable_Group ( var_indexes , - dt , - sec_poll_dir_types , - halton_seed , - _out ) ); + const std::set<NOMAD::direction_type> & sec_poll_dir_types ) +{ + if ( _dimension <= 0 ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP - undefined dimension" ); + + if ( _bb_input_type.empty() || + static_cast<int>(_bb_input_type.size()) != _dimension ) + throw Invalid_Parameter ( "Parameters.cpp" , __LINE__ , + "invalid parameter: VARIABLE_GROUP - undefined blackbox input types" ); + + _to_be_checked = true; + + std::set<NOMAD::direction_type> dt = direction_types; + if ( dt.empty() ) + dt.insert ( NOMAD::ORTHO_NP1_QUAD ); + + _user_var_groups.insert ( new NOMAD::Variable_Group ( var_indexes , + dt , + sec_poll_dir_types , + _out ) ); } // set_VARIABLE_GROUP (3/3): void NOMAD::Parameters::set_VARIABLE_GROUP ( const std::list<NOMAD::Variable_Group*> & vg ) { - - std::list<NOMAD::Variable_Group*>::const_iterator it , end = vg.end(); - for ( it = vg.begin() ; it != end ; ++it ) - set_VARIABLE_GROUP ( (*it)->get_var_indexes () , - (*it)->get_direction_types () , - (*it)->get_sec_poll_dir_types() , - (*it)->get_halton_seed () ); - + + std::list<NOMAD::Variable_Group*>::const_iterator it , end = vg.end(); + for ( it = vg.begin() ; it != end ; ++it ) + set_VARIABLE_GROUP ( (*it)->get_var_indexes () , + (*it)->get_direction_types () , + (*it)->get_sec_poll_dir_types() + ); + } /*-----------------------------------------------*/ @@ -7371,9 +7718,9 @@ void NOMAD::Parameters::set_VARIABLE_GROUP /*-----------------------------------------------*/ void NOMAD::Parameters::help ( const std::string & param_name,bool developer ) const { - std::list<std::string> ls; - ls.push_back ( param_name ); - help ( ls,developer); + std::list<std::string> ls; + ls.push_back ( param_name ); + help ( ls,developer); } /*-----------------------------------------------*/ @@ -7381,13 +7728,13 @@ void NOMAD::Parameters::help ( const std::string & param_name,bool developer ) c /*-----------------------------------------------*/ void NOMAD::Parameters::help ( int argc , char ** argv , bool developer ) const { - std::list<std::string> ls; - if ( argc <= 2 ) - ls.push_back ( "ALL" ); - else - for ( int i = 2 ; i < argc ; ++i ) - ls.push_back ( argv[i] ); - help(ls,developer); + std::list<std::string> ls; + if ( argc <= 2 ) + ls.push_back ( "ALL" ); + else + for ( int i = 2 ; i < argc ; ++i ) + ls.push_back ( argv[i] ); + help(ls,developer); } /*-----------------------------------------------*/ @@ -7396,125 +7743,125 @@ void NOMAD::Parameters::help ( int argc , char ** argv , bool developer ) const void NOMAD::Parameters::help ( const std::list<std::string> & pnames,bool developer ) const { #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - return; + if ( !NOMAD::Slave::is_master() ) + return; #endif - - // initial display: - _out << std::endl - << NOMAD::open_block ( "NOMAD - help on parameters - see more details in " - + NOMAD::USER_GUIDE_FILE ); - - std::list<std::string> param_names = pnames; - NOMAD::toupper ( param_names ); - - bool chk = false; - bool display_all = false; - - // if ( NOMAD::string_find ( "ALL PARAMS PARAMETERS EVERYTHING NOMAD" , param_names ) ) - if ( NOMAD::string_match ( "ALL", param_names) || NOMAD::string_match( "PARAMS", param_names ) || - NOMAD::string_match ( "PARAMETER", param_names) || NOMAD::string_match ( "PARAM", param_names) || - NOMAD::string_match ( "NOMAD" , param_names ) || NOMAD::string_match ( "EVERYTHING", param_names) ) - display_all = true; - - const char registered_key_basic[]="2N ANGLES AVG BARRIER BASIC BASIC BB_EXE BB_INPUT_TYPE BB_OUTPUT_TYPE BI-MADS BI-OBJECTIVES BIMADS \ - BINARY BIOBJECTIVES BLACK-BOXES BLACKBOXES BOUNDS CACHE BBEVAL CACHE_FILE CNT_EVAL CONSTRAINTS CONTINUOUS COUNT DEBUG DELTA_0 DIMENSION \ - DIRECTION_TYPE DIRECTION_TYPES DIRECTIONS DIRECTIONS_TYPES DIRECTORY DISPLAY_ALL_EVAL DISPLAY_DEGREES DISPLAY_STATS EVALUATIONS \ - EXECUTABLE F_TARGET FILES FILTER FORMAT GPS h(x) HISTORY_FILE INITIAL_MESH_SIZE INTEGER LATEX LATIN-HYPERCUBE LB LH_SEARCH LOWER_BOUND \ - LT LT-MADS LTMADS MADS MAX_BB_EVAL MAX_TIME MAXIMUM MINIMIZE MODEL MODELS MULTI-OBJECTIVE MULTIOBJECTIVES N+1 NUMBER OPTIMIZE ORTHO \ - ORTHO-MADS ORTHOMADS OUTPUTS PATH PB PEB POINT POLL PROGRESSIVE-BARRIER RANDOM SAMPLING SCREEN SCREEN SOLUTION_FILE STARTING STATIC \ - STATS STATS_FILE STOPPING SUM TEMPORARY TERMINATES TERMINATION TMP_DIR UB UNIFORM UPPER_BOUNDS VARIABLES X0"; - - const char registered_key_advanced[]="ADD_SEED_TO_FILE_NAMES ADVANCED ASYNCHRONOUS BB_INPUT_INCLUDE_SEED BB_INPUT_INCLUDE_TAG \ - BB_REDIRECTION BBEVAL BI-MADS BI-OBJECTIVES BIMADS BIOBJECTIVES BLACK-BOXES BLACKBOXES BLOCKS BOUNDS CACHE CACHE_FILE CACHE_SAVE_PERIOD \ - CACHE_SEARCH CATEGORICAL CLOSED_BRACES CONSTRAINTS CYCLIC DELTA DELTA^P DETERMINISTIC DIRECTIONS DISABLE DISABLE_MODEL DISABLE_MODELS \ - DISPLAY ELL ELL_0 EVALUATIONS EXECUTABLE EXTENDED_POLL EXTENDED_POLL_DISABLED EXTENDED_POLL_ENABLED EXTENDED_POLL_TRIGGER FEASIBILITY \ - FILES FILTER FIXED_VARIABLE FROBENIUS GLOBAL GROUPS H_MAX_0 H_MIN H_NORM HALTON_SEED HAS_SGTE HMAX HMAX_0 HMIN INDENTATION INF_STR \ - INFINITY INITIAL_MESH_INDEX INTERPOLATION ITERATIONS L_0 L_INF L0 L1 L2 LATIN-HYPERCUBE LB LIBRARY LINF LT-MADS LTMADS MADS \ - MAX_CACHE_MEMORY MAX_CONSECUTIVE_FAILED_ITERATIONS MAX_EVAL MAX_ITERATIONS MAX_MESH_INDEX MAX_SGTE_EVAL MAX_SIM_BB_EVAL MAXIMUM \ - MB MEGA-BYTES MEGABYTES MESH MESH_COARSENING_EXPONENT MESH_REFINING_EXPONENT MESH_UPDATE_BASIS META-HEURISTICS METAHEURISTICS MFN \ - MIN_MESH_SIZE MIN_POLL_SIZE MINIMUM MIXED MODEL MODEL_EVAL_SORT MODEL_ORDERING MODEL_SEARCH MODEL_SEARCH_OPTIMISTIC MODELS MPI \ - MULTI_F_BOUNDS MULTI_NB_MADS_RUNS MULTI_OVERALL_BB_EVAL MULTI-OBJECTIVES MULTIOBJECTIVES MVP N+1 NEIGHBORHOOD NEIGHBORHOODS NEIGHBORS_EXE \ - NEIGHBOURHOODS NEIGHBOURS NUMBER OPEN_BRACES OPPORTUNISTIC_CACHE_SEARCH OPPORTUNISTIC_EVAL OPPORTUNISTIC_LH OPPORTUNISTIC_MIN_EVAL \ - OPTIMISTIC ORTHO ORTHO-MADS ORTHOGONAL ORTHOMADS OUTPUT OUTPUTS PARALLELISM PARETO PB PEB PERIODIC_VARIABLE PMADS POINT_DISPLAY_LIMIT \ - POLL PRECISION PROGRESSIVE-BARRIER PROJECTION PSD-MADS PSDMADS QUAD QUADRATIC RAM RANDOM REALS REGRESSION RHO SAMPLING SCALE SCALING \ - SEARCH SEED SGTE_CACHE_FILE SGTE_COST SGTE_EVAL_SORT SGTE_EXE SGTE_ORDERING SGTES SIMULATED SNAP_TO_BOUNDS SPECULATIVE_SEARCH \ - STAT_SUM_TARGET STATS STOP_IF_FEASIBLE SUCCESSES SURF SURROGATES TABULATIONS TAU TERMINATES TERMINATION TGP TGPMODEL_SEARCH TRIGGER \ - UB UNDEF_STR UNDEFINED USER_CALLS_DISABLED USER_CALLS_ENABLED VARIABLE_GROUP VARIABLES VNS_SEARCH W- W+"; - - const char registered_key_developer[]="BI-MADS BI-OBJECTIVES BIMADS BIOBJECTIVES BLACK-BOXES BLACK-BOXES COMPARISONS DEVELOPER \ - DIRECTIONS EPSILON EVALUATIONS FROBENIUS IMPROVEMENT INTERPOLATION L_CURVE_TARGET MADS MFN MODEL MODEL_EVAL_SORT_CAUTIOUS MODEL_ORDERING \ - MODEL_QUAD_MAX_Y_SIZE MODEL_QUAD_MIN_Y_SIZE MODEL_QUAD_RADIUS_FACTOR MODEL_QUAD_USE_WP MODEL_SEARCH MODEL_SEARCH_MAX_TRIAL_PTS \ - MODEL_SEARCH_PROJ_TO_MESH MODEL_TGP_MODE MODEL_TGP_REUSE_MODEL MODELS MULTI_FORMULATION MULTI_USE_DELTA_CRITERION MULTI-OBJECTIVES \ - MULTIOBJECTIVES N+1 NP1 OBJECTIVE OPPORTUNISTIC_LUCKY_EVAL OPPORTUNISTIC_MIN_F_IMPRVMT OPPORTUNISTIC_MIN_NB_SUCCESSES OPT_ONLY_SGTES \ - ORTHO PARETO PB PEB POLL PRECISION PROGRESSIVE-BARRIER PROJECTION QUAD QUADRATIC REALS REGRESSION SEC_POLL_DIR_TYPES SGTES STOPPING \ - SUCCESSES SURROGATES TERMINATES TERMINATION TGP WELL-POISEDNESS"; - - - if ( display_all || NOMAD::string_find ( registered_key_basic, param_names ) ) - { - _out << "--------------------------------------------------------------" << endl; - _out << "-----------------------BASIC PARAMETERS-----------------------" << endl; - _out << "--------------------------------------------------------------" << endl; - } - - - // BB_EXE: - // ------- - if ( display_all || NOMAD::string_find ( "BB_EXE BASIC BLACK-BOXES BLACKBOXES \ + + // initial display: + _out << std::endl + << NOMAD::open_block ( "NOMAD - help on parameters - see more details in " + + NOMAD::USER_GUIDE_FILE ); + + std::list<std::string> param_names = pnames; + NOMAD::toupper ( param_names ); + + bool chk = false; + bool display_all = false; + + if ( NOMAD::string_match ( "ALL", param_names) || NOMAD::string_match( "PARAMS", param_names ) || + NOMAD::string_match ( "PARAMETER", param_names) || NOMAD::string_match ( "PARAM", param_names) || + NOMAD::string_match ( "NOMAD" , param_names ) || NOMAD::string_match ( "EVERYTHING", param_names) ) + display_all = true; + + + const char registered_key_basic[]="2N ANGLES AVG BARRIER BASIC BASIC BB_EXE BB_INPUT_TYPE BB_OUTPUT_TYPE BI-MADS BI-OBJECTIVES BIMADS \ + BINARY BIOBJECTIVES BLACK-BOXES BLACKBOXES BOUNDS CACHE BBEVAL CACHE_FILE CNT_EVAL CONSTRAINTS CONTINUOUS COUNT DEBUG DELTA_0 DIMENSION \ + DIRECTION_TYPE DIRECTION_TYPES DIRECTIONS DIRECTIONS_TYPES DIRECTORY DISPLAY_ALL_EVAL DISPLAY_DEGREES DISPLAY_STATS EVALUATIONS \ + EXECUTABLE F_TARGET FILES FILTER FORMAT GPS h(x) HISTORY_FILE INITIAL_MESH_SIZE INTEGER LATEX LATIN-HYPERCUBE LB LH_SEARCH LOWER_BOUND \ + LT LT-MADS LTMADS MADS MAX_BB_EVAL MAX_TIME MAXIMUM MINIMIZE MODEL MODELS MULTI-OBJECTIVE MULTIOBJECTIVES N+1 NUMBER OPTIMIZE ORTHO \ + ORTHO-MADS ORTHOMADS OUTPUTS PATH PB PEB POINT POLL PROGRESSIVE-BARRIER RANDOM SAMPLING SCREEN SCREEN SOLUTION_FILE STARTING STATIC \ + STATS STATS_FILE STOPPING SUM TEMPORARY TERMINATES TERMINATION TMP_DIR UB UNIFORM UPPER_BOUNDS VARIABLES X0"; + + const char registered_key_advanced[]="ADD_SEED_TO_FILE_NAMES ADVANCED ANISOTROPIC_MESH ASYNCHRONOUS BB_INPUT_INCLUDE_SEED BB_INPUT_INCLUDE_TAG \ + BB_REDIRECTION BBEVAL BI-MADS BI-OBJECTIVES BIMADS BIOBJECTIVES BLACK-BOXES BLACKBOXES BLOCKS BOUNDS CACHE CACHE_FILE CACHE_SAVE_PERIOD \ + CACHE_SEARCH CATEGORICAL CLOSED_BRACES CONSTRAINTS CYCLIC DELTA DETERMINISTIC DIRECTIONS DISABLE DISABLE_EVAL_SORT DISABLE_MODEL DISABLE_MODELS \ + DISPLAY ELL ELL_0 BB_MAX_BLOCK_SIZE EVALUATIONS EXECUTABLE EXTENDED_POLL EXTENDED_POLL_DISABLED EXTENDED_POLL_ENABLED EXTENDED_POLL_TRIGGER FEASIBILITY \ + FILES FILTER FIXED_VARIABLE FROBENIUS GLOBAL GROUPS H_MAX_0 H_MIN H_NORM HAS_SGTE HMAX HMAX_0 HMIN INDENTATION INF_STR \ + INFINITY INTERPOLATION ITERATIONS L_0 L_INF L0 L1 L2 LATIN-HYPERCUBE LB LIBRARY LINF LT-MADS LTMADS MADS \ + MAX_CACHE_MEMORY MAX_CONSECUTIVE_FAILED_ITERATIONS MAX_EVAL MAX_ITERATIONS MAX_SGTE_EVAL MAX_SIM_BB_EVAL MAXIMUM \ + MB MEGA-BYTES MEGABYTES MESH MESH_COARSENING_EXPONENT MESH_REFINING_EXPONENT MESH_UPDATE_BASIS META-HEURISTICS METAHEURISTICS MFN \ + MIN_MESH_SIZE MIN_POLL_SIZE MINIMUM MIXED MODEL MODEL_EVAL_SORT MODEL_ORDERING MODEL_SEARCH MODEL_SEARCH_OPTIMISTIC MODELS MPI \ + MULTI_F_BOUNDS MULTI_NB_MADS_RUNS MULTI_OVERALL_BB_EVAL MULTI-OBJECTIVES MULTIOBJECTIVES MVP N+1 NEIGHBORHOOD NEIGHBORHOODS NEIGHBORS_EXE \ + NEIGHBOURHOODS NEIGHBOURS NUMBER OPEN_BRACES OPPORTUNISTIC_CACHE_SEARCH OPPORTUNISTIC_EVAL OPPORTUNISTIC_LH OPPORTUNISTIC_MIN_EVAL \ + OPTIMISTIC ORTHO ORTHO-MADS ORTHOGONAL ORTHOMADS OUTPUT OUTPUTS PARALLELISM PARETO PB PEB PERIODIC_VARIABLE PMADS POINT_DISPLAY_LIMIT \ + POLL POLL_UPDATE_BASIS PRECISION PROGRESSIVE-BARRIER PROJECTION PSD-MADS PSDMADS QUAD QUADRATIC RAM RANDOM REALS REGRESSION RHO SAMPLING SCALE SCALING \ + SEARCH SEED SGTE_CACHE_FILE SGTE_COST SGTE_EVAL_SORT SGTE_EXE SGTE_ORDERING SGTES SIMULATED SNAP_TO_BOUNDS SPECULATIVE_SEARCH \ + STAT_SUM_TARGET STATS STOP_IF_FEASIBLE SUCCESSES SURF SURROGATES TABULATIONS TAU TERMINATES TERMINATION TGP TGPMODEL_SEARCH TRIGGER \ + UB UNDEF_STR UNDEFINED USER_CALLS_DISABLED USER_CALLS_ENABLED VARIABLE_GROUP VARIABLES VNS_SEARCH W- W+"; + + const char registered_key_developer[]="BI-MADS BI-OBJECTIVES BIMADS BIOBJECTIVES BLACK-BOXES BLACK-BOXES COMPARISONS DEVELOPER \ + DIRECTIONS EPSILON EVALUATIONS FROBENIUS INITIAL_MESH_INDEX IMPROVEMENT INTERPOLATION L_CURVE_TARGET MADS MFN MODEL MODEL_EVAL_SORT_CAUTIOUS MODEL_ORDERING \ + MODEL_QUAD_MAX_Y_SIZE MODEL_QUAD_MIN_Y_SIZE MODEL_QUAD_RADIUS_FACTOR MODEL_QUAD_USE_WP MODEL_SEARCH MODEL_SEARCH_MAX_TRIAL_PTS \ + MODEL_SEARCH_PROJ_TO_MESH MODEL_TGP_MODE MODEL_TGP_REUSE_MODEL MODELS MULTI_FORMULATION MULTI_USE_DELTA_CRITERION MULTI-OBJECTIVES \ + MULTIOBJECTIVES N+1 NP1 OBJECTIVE OPPORTUNISTIC_LUCKY_EVAL OPPORTUNISTIC_MIN_F_IMPRVMT OPPORTUNISTIC_MIN_NB_SUCCESSES OPT_ONLY_SGTES \ + ORTHO PARETO PB PEB POLL PRECISION PROGRESSIVE-BARRIER PROJECTION QUAD QUADRATIC REALS REGRESSION SEC_POLL_DIR_TYPES SGTES STOPPING \ + SUCCESSES SURROGATES TERMINATES TERMINATION TGP USE_SMESH WELL-POISEDNESS"; + + + if ( display_all || NOMAD::string_find ( registered_key_basic, param_names ) ) + { + _out << "--------------------------------------------------------------" << endl; + _out << "-----------------------BASIC PARAMETERS-----------------------" << endl; + _out << "--------------------------------------------------------------" << endl; + } + + + // BB_EXE: + // ------- + if ( display_all || NOMAD::string_find ( "BB_EXE BASIC BLACK-BOXES BLACKBOXES \ EXECUTABLE FILES BI-OBJECTIVES \ BIOBJECTIVES MULTIOBJECTIVES \ BIMADS BI-MADS \ MULTI-OBJECTIVES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_EXE (basic)" ) << std::endl - << ". blackbox executable names" << std::endl - << ". list of strings" << std::endl - << ". no default, required (except in library mode)" << std::endl - << ". several executables can be used" << std::endl - << ". one executable can give several outputs" << std::endl - << ". use \' or \", and \'$\', to specify names or" << std::endl - << " commands with spaces" << std::endl - << ". when the \'$\' character is put in first" << std::endl - << " position of a string, it is considered" << std::endl - << " as global and no path will be added" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "BB_EXE bb.exe" << std::endl - << "BB_EXE bb1.exe bb2.exe" << std::endl - << "BB_EXE \'$nice bb.exe\'" << std::endl - << "BB_EXE \'$python bb.py\'" << std::endl - << NOMAD::close_block() - << NOMAD::close_block(); - chk = true; - } - - // BB_INPUT_TYPE: - // -------------- - if ( display_all || NOMAD::string_find ( "BB_INPUT_TYPE BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "BB_EXE (basic)" ) << std::endl + << ". blackbox executable names" << std::endl + << ". list of strings" << std::endl + << ". no default, required (except in library mode)" << std::endl + << ". several executables can be used" << std::endl + << ". one executable can give several outputs" << std::endl + << ". use \' or \", and \'$\', to specify names or" << std::endl + << " commands with spaces" << std::endl + << ". when the \'$\' character is put in first" << std::endl + << " position of a string, it is considered" << std::endl + << " as global and no path will be added" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "BB_EXE bb.exe" << std::endl + << "BB_EXE bb1.exe bb2.exe" << std::endl + << "BB_EXE \'$nice bb.exe\'" << std::endl + << "BB_EXE \'$python bb.py\'" << std::endl + << NOMAD::close_block() + << NOMAD::close_block(); + chk = true; + } + + // BB_INPUT_TYPE: + // -------------- + if ( display_all || NOMAD::string_find ( "BB_INPUT_TYPE BLACK-BOXES BLACKBOXES \ BASIC VARIABLES CONTINUOUS \ INTEGER BINARY" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_INPUT_TYPE (basic)" ) << std::endl - << ". blackbox input types" << std::endl - << ". list of types for each variable" << std::endl - << ". " << NOMAD::open_block ( "available types" ) - << "B: binary" << std::endl - << "C: categorical" << std::endl - << "I: integer" << std::endl - << "R: continuous" << std::endl - << NOMAD::close_block() - << ". default: * R (all continuous)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "BB_INPUT_TYPE ( R I B ) # for all 3 variables" << std::endl - << "BB_INPUT_TYPE 1-3 B # variables 1 to 3 are binary" << std::endl - << "BB_INPUT_TYPE 0 I # first variable is integer" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // BB_OUTPUT_TYPE: - // --------------- - if ( display_all || NOMAD::string_find ( "BB_OUTPUT_TYPE BASIC CONSTRAINTS \ + _out << std::endl + << NOMAD::open_block ( "BB_INPUT_TYPE (basic)" ) << std::endl + << ". blackbox input types" << std::endl + << ". list of types for each variable" << std::endl + << ". " << NOMAD::open_block ( "available types" ) + << "B: binary" << std::endl + << "C: categorical" << std::endl + << "I: integer" << std::endl + << "R: continuous" << std::endl + << NOMAD::close_block() + << ". default: * R (all continuous)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "BB_INPUT_TYPE ( R I B ) # for all 3 variables" << std::endl + << "BB_INPUT_TYPE 1-3 B # variables 1 to 3 are binary" << std::endl + << "BB_INPUT_TYPE 0 I # first variable is integer" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // BB_OUTPUT_TYPE: + // --------------- + if ( display_all || NOMAD::string_find ( "BB_OUTPUT_TYPE BASIC CONSTRAINTS \ BLACK-BOXES BLACKBOXES \ BARRIER STATS BI-OBJECTIVES h(x) \ PB PEB FILTER STATS SUM AVG CNT_EVAL \ @@ -7523,1991 +7870,2069 @@ void NOMAD::Parameters::help ( const std::list<std::string> & pnames,bool develo BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS \ OPTIMIZE" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_OUTPUT_TYPE (basic)" ) << std::endl - << ". blackbox output types" << std::endl - << ". list of types for each blackbox output" << std::endl - << ". " << NOMAD::open_block ( "available types" ) << std::endl - << "OBJ : objective value to minimize" << std::endl - << " (define twice for bi-objective)" << std::endl - << "CSTR or PB: constraint <= 0 treated with" << std::endl - << " Progressive Barrier (PB)" << std::endl - << "EB : constraint <= 0 treated with" << std::endl - << " Extreme Barrier (EB)" << std::endl - << "PEB : constraint <= 0 treated with" << std::endl - << " hybrid PB/EB" << std::endl - << "F : constraint <= 0 treated with Filter" << std::endl - << "CNT_EVAL : 0 or 1 output: count or not the" << std::endl - << " evaluation" << std::endl - << "STAT_AVG : NOMAD will compute the average" << std::endl - << " value for this output" << std::endl - << "STAT_SUM : the same for the sum" << std::endl - << "NOTHING : the output is ignored" << std::endl - << "- : same as \'NOTHING\'" << std::endl - << NOMAD::close_block() - << ". STAT_SUM and STAT_AVG outputs have to be unique;" << std::endl - << " they are updated at every new blackbox evaluation" << std::endl - << ". no default, required" << std::endl - << ". see user guide for blackbox output formats" << std::endl - << ". equality constraints are not natively supported" << std::endl - << ". see parameters LOWER_BOUND and UPPER_BOUND for" << std::endl - << " bound constraints" << std::endl - << ". " << NOMAD::open_block ( "examples" ) << std::endl - << "BB_EXE bb.exe # these two lines define" << std::endl - << "BB_OUTPUT_TYPE OBJ EB EB # that bb.exe outputs" << std::endl - << " # three values" << std::endl - << std::endl - << "BB_EXE bb1.exe bb2.exe bb2.exe # bb1.exe outputs the" << std::endl - << "BB_OUTPUT_TYPE OBJ EB EB # objective and bb2.exe" << std::endl - << " # two constraints" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - - // CACHE_FILE: - // ----------- - if ( display_all || NOMAD::string_find ( "CACHE_FILE BASIC \ + _out << std::endl + << NOMAD::open_block ( "BB_OUTPUT_TYPE (basic)" ) << std::endl + << ". blackbox output types" << std::endl + << ". list of types for each blackbox output" << std::endl + << ". " << NOMAD::open_block ( "available types" ) << std::endl + << "OBJ : objective value to minimize" << std::endl + << " (define twice for bi-objective)" << std::endl + << "CSTR or PB: constraint <= 0 treated with" << std::endl + << " Progressive Barrier (PB)" << std::endl + << "EB : constraint <= 0 treated with" << std::endl + << " Extreme Barrier (EB)" << std::endl + << "PEB : constraint <= 0 treated with" << std::endl + << " hybrid PB/EB" << std::endl + << "F : constraint <= 0 treated with Filter" << std::endl + << "CNT_EVAL : 0 or 1 output: count or not the" << std::endl + << " evaluation" << std::endl + << "STAT_AVG : NOMAD will compute the average" << std::endl + << " value for this output" << std::endl + << "STAT_SUM : the same for the sum" << std::endl + << "NOTHING : the output is ignored" << std::endl + << "- : same as \'NOTHING\'" << std::endl + << NOMAD::close_block() + << ". STAT_SUM and STAT_AVG outputs have to be unique;" << std::endl + << " they are updated at every new blackbox evaluation" << std::endl + << ". no default, required" << std::endl + << ". see user guide for blackbox output formats" << std::endl + << ". equality constraints are not natively supported" << std::endl + << ". see parameters LOWER_BOUND and UPPER_BOUND for" << std::endl + << " bound constraints" << std::endl + << ". " << NOMAD::open_block ( "examples" ) << std::endl + << "BB_EXE bb.exe # these two lines define" << std::endl + << "BB_OUTPUT_TYPE OBJ EB EB # that bb.exe outputs" << std::endl + << " # three values" << std::endl + << std::endl + << "BB_EXE bb1.exe bb2.exe bb2.exe # bb1.exe outputs the" << std::endl + << "BB_OUTPUT_TYPE OBJ EB EB # objective and bb2.exe" << std::endl + << " # two constraints" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + + // CACHE_FILE: + // ----------- + if ( display_all || NOMAD::string_find ( "CACHE_FILE BASIC \ FILES OUTPUTS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "CACHE_FILE (basic)" ) << std::endl - << ". cache file; if the specified file" << std::endl - << " does not exist, it will be created" << std::endl - << ". argument: one string" << std::endl - << ". no default" << std::endl - << ". points already in the file will be" << std::endl - << " tagged as true evaluations" << std::endl - << ". example: CACHE_FILE cache.bin" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // DIMENSION: - // ---------- - if ( display_all || NOMAD::string_find ( "DIMENSION BASIC VARIABLES" , - param_names ) ) + _out << std::endl + << NOMAD::open_block ( "CACHE_FILE (basic)" ) << std::endl + << ". cache file; if the specified file" << std::endl + << " does not exist, it will be created" << std::endl + << ". argument: one string" << std::endl + << ". no default" << std::endl + << ". points already in the file will be" << std::endl + << " tagged as true evaluations" << std::endl + << ". example: CACHE_FILE cache.bin" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // DIMENSION: + // ---------- + if ( display_all || NOMAD::string_find ( "DIMENSION BASIC VARIABLES" , + param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DIMENSION (basic)" ) << std::endl - << ". number of variables" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default, required" << std::endl - << ". example: DIMENSION 3" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // DIRECTION_TYPE: - // --------------- - if ( display_all || NOMAD::string_find ( "DIRECTION_TYPES BASIC DIRECTION_TYPE DIRECTIONS_TYPES \ + _out << std::endl + << NOMAD::open_block ( "DIMENSION (basic)" ) << std::endl + << ". number of variables" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default, required" << std::endl + << ". example: DIMENSION 3" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // DIRECTION_TYPE: + // --------------- + if ( display_all || NOMAD::string_find ( "DIRECTION_TYPES BASIC DIRECTION_TYPE DIRECTIONS_TYPES \ BASIC ORTHO LT GPS \ MADS DIRECTIONS 2N N+1 POLL MODEL MODELS \ ORTHOMADS ORTHO-MADS LTMADS LT-MADS \ RANDOM STATIC UNIFORM ANGLES" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DIRECTION_TYPE (basic)" ) << std::endl - << ". types of directions used in the poll step" << std::endl - << ". arguments: direction types (see user" << std::endl - << " guide for available types)" << std::endl - << ". default: ORTHO (OrthoMADS n+1 (QUAD model used for " << std::endl - << " (n+1)th dir)." << std::endl - << ". several direction types can be defined" << std::endl - << " at the same time (one direction per line)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) << std::endl - << "DIRECTION_TYPE ORTHO 1 # OrthoMADS, 1" << std::endl - << "DIRECTION_TYPE ORTHO 2 # OrthoMADS, 2" << std::endl - << "DIRECTION_TYPE ORTHO N+1 # OrthoMADS, n+1" << std::endl - << " # (QUAD model used"<< std::endl - << " # for (n+1)th dir)"<< std::endl - << "DIRECTION_TYPE ORTHO N+1 QUAD # OrthoMADS, n+1" << std::endl - << " # (QUAD model used"<< std::endl - << " # for (n+1)th dir)"<< std::endl - << "DIRECTION_TYPE ORTHO N+1 NEG # OrthoMADS, n+1" << std::endl - << " # ((n+1)th dir = " << std::endl - << " # negative sum of" << std::endl - << " # n first dirs)" << std::endl - << "DIRECTION_TYPE ORTHO # OrthoMADS, n+1 QUAD " << std::endl - << "DIRECTION_TYPE ORTHO 2N # OrthoMADS, 2n" << std::endl - << "DIRECTION_TYPE LT 1 # LT-MADS, 1" << std::endl - << "DIRECTION_TYPE LT 2 # LT-MADS, 2" << std::endl - << "DIRECTION_TYPE LT N+1 # LT-MADS, n+1" << std::endl - << "DIRECTION_TYPE LT # LT-MADS, 2n" << std::endl - << "DIRECTION_TYPE LT 2N # LT-MADS, 2n" << std::endl - << "DIRECTION_TYPE GPS BINARY or BIN # GPS, bin var" << std::endl - << "DIRECTION_TYPE GPS N+1 # GPS, n+1," << std::endl - << " # static" << std::endl - << "DIRECTION_TYPE GPS N+1 STATIC # GPS, n+1," << std::endl - << " # static" << std::endl - << "DIRECTION_TYPE GPS N+1 STATIC UNIFORM # GPS, n+1," << std::endl - << " # static, unif" << std::endl - << "DIRECTION_TYPE GPS N+1 RAND # GPS, n+1," << std::endl - << " # rand" << std::endl - << "DIRECTION_TYPE GPS N+1 RAND UNIFORM # GPS, n+1," << std::endl - << " # rand, unif" << std::endl - << "DIRECTION_TYPE GPS # GPS, 2n," << std::endl - << " # static" << std::endl - << "DIRECTION_TYPE GPS 2N # GPS, 2n," << std::endl - << " # static" << std::endl - << "DIRECTION_TYPE GPS 2N STATIC # GPS, 2n," << std::endl - << " # static" << std::endl - << "DIRECTION_TYPE GPS 2N RAND # GPS, 2n," << std::endl - << " # rand" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // DISPLAY_ALL_EVAL: - // ----------------- - if ( display_all || NOMAD::string_find ( "DISPLAY_ALL_EVAL DISPLAY_STATS \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "DIRECTION_TYPE (basic)" ) << std::endl + << ". types of directions used in the poll step" << std::endl + << ". arguments: direction types (see user" << std::endl + << " guide for available types)" << std::endl + << ". default: ORTHO (OrthoMADS n+1 (QUAD model used for " << std::endl + << " (n+1)th dir)." << std::endl + << ". several direction types can be defined" << std::endl + << " at the same time (one direction per line)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) << std::endl + << "DIRECTION_TYPE ORTHO 1 # OrthoMADS, 1" << std::endl + << "DIRECTION_TYPE ORTHO 2 # OrthoMADS, 2" << std::endl + << "DIRECTION_TYPE ORTHO N+1 # OrthoMADS, n+1" << std::endl + << " # (QUAD model used"<< std::endl + << " # for (n+1)th dir)"<< std::endl + << "DIRECTION_TYPE ORTHO N+1 QUAD # OrthoMADS, n+1" << std::endl + << " # (QUAD model used"<< std::endl + << " # for (n+1)th dir)"<< std::endl + << "DIRECTION_TYPE ORTHO N+1 NEG # OrthoMADS, n+1" << std::endl + << " # ((n+1)th dir = " << std::endl + << " # negative sum of" << std::endl + << " # n first dirs)" << std::endl + << "DIRECTION_TYPE ORTHO # OrthoMADS, n+1 QUAD " << std::endl + << "DIRECTION_TYPE ORTHO 2N # OrthoMADS, 2n" << std::endl + << "DIRECTION_TYPE LT 1 # LT-MADS, 1" << std::endl + << "DIRECTION_TYPE LT 2 # LT-MADS, 2" << std::endl + << "DIRECTION_TYPE LT N+1 # LT-MADS, n+1" << std::endl + << "DIRECTION_TYPE LT # LT-MADS, 2n" << std::endl + << "DIRECTION_TYPE LT 2N # LT-MADS, 2n" << std::endl + << "DIRECTION_TYPE GPS BINARY or BIN # GPS, bin var" << std::endl + << "DIRECTION_TYPE GPS N+1 # GPS, n+1," << std::endl + << " # static" << std::endl + << "DIRECTION_TYPE GPS N+1 STATIC # GPS, n+1," << std::endl + << " # static" << std::endl + << "DIRECTION_TYPE GPS N+1 STATIC UNIFORM # GPS, n+1," << std::endl + << " # static, unif" << std::endl + << "DIRECTION_TYPE GPS N+1 RAND # GPS, n+1," << std::endl + << " # rand" << std::endl + << "DIRECTION_TYPE GPS N+1 RAND UNIFORM # GPS, n+1," << std::endl + << " # rand, unif" << std::endl + << "DIRECTION_TYPE GPS # GPS, 2n," << std::endl + << " # static" << std::endl + << "DIRECTION_TYPE GPS 2N # GPS, 2n," << std::endl + << " # static" << std::endl + << "DIRECTION_TYPE GPS 2N STATIC # GPS, 2n," << std::endl + << " # static" << std::endl + << "DIRECTION_TYPE GPS 2N RAND # GPS, 2n," << std::endl + << " # rand" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // DISPLAY_ALL_EVAL: + // ----------------- + if ( display_all || NOMAD::string_find ( "DISPLAY_ALL_EVAL DISPLAY_STATS \ STATS_FILE BASIC" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DISPLAY_ALL_EVAL (basic)" ) << std::endl - << ". if \'yes\', more points are displayed with" << std::endl - << " parameters DISPLAY_STATS and STATS_FILE" << std::endl - << ". points of the phase one with EB constraints" << std::endl - << " are not displayed" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: DISPLAY_ALL_EVAL yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // DISPLAY_DEGREE: - // --------------- - if ( display_all || NOMAD::string_find ( "DISPLAY_DEGREES OUTPUTS \ + _out << std::endl + << NOMAD::open_block ( "DISPLAY_ALL_EVAL (basic)" ) << std::endl + << ". if \'yes\', more points are displayed with" << std::endl + << " parameters DISPLAY_STATS and STATS_FILE" << std::endl + << ". points of the phase one with EB constraints" << std::endl + << " are not displayed" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: DISPLAY_ALL_EVAL yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // DISPLAY_DEGREE: + // --------------- + if ( display_all || NOMAD::string_find ( "DISPLAY_DEGREES OUTPUTS \ SCREEN DEBUG BASIC" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DISPLAY_DEGREE (basic)" ) << std::endl - << ". " << NOMAD::open_block ( "display degree" ) - << "0: no display" << std::endl - << "1: minimal display" << std::endl - << "2: normal display" << std::endl - << "3: full display" << std::endl - << NOMAD::close_block() - << ". argument: one integer in {0, 1, 2, 3} (basic)" << std::endl - << " or one string in {\'NO\', \'NO_DISPLAY\', \'MIN\'," << std::endl - << " \'MINIMAL\', \'MINIMAL_DISPLAY\' ,\'NORMAL\'," - << std::endl - << " \'NORMAL_DISPLAY\', \'FULL\'," << std::endl - << " \'FULL_DISPLAY\'}" << std::endl - << " or one string composed of 4 integers each in" << std::endl - << " { 0, 1, 2 ,3} (advanced)" << std::endl - << ". default: 2" << std::endl - << ". " - << NOMAD::open_block("advanced use with 4 digits (see user guide for details)") - << "#1 general display degree (before and after" << std::endl - << " all iterations)" << std::endl - << "#2 search display degree (during searches)" << std::endl - << "#3 poll display degree (during polls)" << std::endl - << "#4 iterative display degree (other displays at" << std::endl - << " each iteration)" << std::endl - << NOMAD::close_block() << ". " << NOMAD::open_block ( "examples" ) - << "DISPLAY_DEGREE 2 # basic : normal display" << std::endl - << "DISPLAY_DEGREE 0030 # advanced: display only" << std::endl - << " # poll info" << std::endl - << NOMAD::close_block() - << NOMAD::close_block(); - chk = true; - } - - // DISPLAY_STATS: - // --------------- - if ( display_all || NOMAD::string_find ( "DISPLAY_STATS OUTPUTS LATEX FORMAT \ + _out << std::endl + << NOMAD::open_block ( "DISPLAY_DEGREE (basic)" ) << std::endl + << ". " << NOMAD::open_block ( "display degree" ) + << "0: no display" << std::endl + << "1: minimal display" << std::endl + << "2: normal display" << std::endl + << "3: full display" << std::endl + << NOMAD::close_block() + << ". argument: one integer in {0, 1, 2, 3} (basic)" << std::endl + << " or one string in {\'NO\', \'NO_DISPLAY\', \'MIN\'," << std::endl + << " \'MINIMAL\', \'MINIMAL_DISPLAY\' ,\'NORMAL\'," + << std::endl + << " \'NORMAL_DISPLAY\', \'FULL\'," << std::endl + << " \'FULL_DISPLAY\'}" << std::endl + << " or one string composed of 4 integers each in" << std::endl + << " { 0, 1, 2 ,3} (advanced)" << std::endl + << ". default: 2" << std::endl + << ". " + << NOMAD::open_block("advanced use with 4 digits (see user guide for details)") + << "#1 general display degree (before and after" << std::endl + << " all iterations)" << std::endl + << "#2 search display degree (during searches)" << std::endl + << "#3 poll display degree (during polls)" << std::endl + << "#4 iterative display degree (other displays at" << std::endl + << " each iteration)" << std::endl + << NOMAD::close_block() << ". " << NOMAD::open_block ( "examples" ) + << "DISPLAY_DEGREE 2 # basic : normal display" << std::endl + << "DISPLAY_DEGREE 0030 # advanced: display only" << std::endl + << " # poll info" << std::endl + << NOMAD::close_block() + << NOMAD::close_block(); + chk = true; + } + + // DISPLAY_STATS: + // --------------- + if ( display_all || NOMAD::string_find ( "DISPLAY_STATS OUTPUTS LATEX FORMAT \ SCREEN DEBUG BASIC" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DISPLAY_STATS (basic)" ) << std::endl - << ". format of the outputs displayed at each success" << std::endl - << " (single-objective)" << std::endl - << ". format of the final Pareto front" << std::endl - << " (multi-objective)" << std::endl - << ". displays more points with DISPLAY_ALL_EVAL=true" << std::endl - << ". arguments: list of strings possibly including" << std::endl - << " the following keywords:" << std::endl - << " BBE : blackbox evaluations" << std::endl - << " BBO : blackbox outputs" << std::endl - << " EVAL : evaluations (includes cache hits)" << std::endl - << " MESH_INDEX: mesh index" << std::endl - << " MESH_SIZE : mesh size delta_k^m" << std::endl - << " OBJ : objective function value" << std::endl - << " POLL_SIZE : poll size delta_k^p" << std::endl - << " SIM_BBE : simulated blackbox evaluations" << std::endl - << " SGTE : surrogate evaluations" << std::endl - << " SOL : current feasible iterate" << std::endl - << " STAT_SUM : value of stat SUM" << std::endl - << " STAT_AVG : value of stat AVG" << std::endl - << " TIME : real time in seconds" << std::endl - << " VARi : value of variable i" << std::endl - << " (0 for the first variable)" << std::endl - << ". all outputs may be formatted using C style" << std::endl - << " (%f, %e, %E, %g, %G, %i, %d with the possibility" << std::endl - << " to specify the display width and the precision)" << std::endl - << " example: %5.2Ef displays f in 5 columns and 2 decimals" << std::endl - << " in scientific notation" << std::endl - << ". do not use quotes" << std::endl - << ". the \'%\' character may be explicitely indicated with \'\\%\'" - << std::endl - << ". see details in user guide" << std::endl - << ". defaults: BBE OBJ (single-objective)" << std::endl - << " OBJ (multi-objective)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "DISPLAY_STATS TIME f=OBJ" << std::endl - << "DISPLAY_STATS %5.2obj" << std::endl - << "# for LaTeX tables:" << std::endl - << "DISPLAY_STATS $BBE$ & ( $%12.5SOL, ) & $OBJ$ \\\\" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // F_TARGET: - // --------- - if ( display_all || NOMAD::string_find ( "F_TARGET BASIC BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "DISPLAY_STATS (basic)" ) << std::endl + << ". format of the outputs displayed at each success" << std::endl + << " (single-objective)" << std::endl + << ". format of the final Pareto front" << std::endl + << " (multi-objective)" << std::endl + << ". displays more points with DISPLAY_ALL_EVAL=true" << std::endl + << ". arguments: list of strings possibly including" << std::endl + << " the following keywords:" << std::endl + << " BBE : blackbox evaluations" << std::endl + << " BBO : blackbox outputs" << std::endl + << " BLK_EVA : number of blocks of evaluations" << std::endl + << " EVAL : evaluations (includes cache hits)" << std::endl + << " MESH_INDEX: mesh index" << std::endl + << " MESH_SIZE : mesh size delta_k^m" << std::endl + << " OBJ : objective function value" << std::endl + << " POLL_SIZE : poll size delta_k^p" << std::endl + << " SIM_BBE : simulated blackbox evaluations" << std::endl + << " SGTE : surrogate evaluations" << std::endl + << " SOL : current feasible iterate" << std::endl + << " STAT_SUM : value of stat SUM" << std::endl + << " STAT_AVG : value of stat AVG" << std::endl + << " TIME : real time in seconds" << std::endl + << " VARi : value of variable i" << std::endl + << " (0 for the first variable)" << std::endl + << ". all outputs may be formatted using C style" << std::endl + << " (%f, %e, %E, %g, %G, %i, %d with the possibility" << std::endl + << " to specify the display width and the precision)" << std::endl + << " example: %5.2Ef displays f in 5 columns and 2 decimals" << std::endl + << " in scientific notation" << std::endl + << ". do not use quotes" << std::endl + << ". the \'%\' character may be explicitely indicated with \'\\%\'" + << std::endl + << ". see details in user guide" << std::endl + << ". defaults: BBE OBJ (single-objective)" << std::endl + << " OBJ (multi-objective)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "DISPLAY_STATS TIME f=OBJ" << std::endl + << "DISPLAY_STATS %5.2obj" << std::endl + << "# for LaTeX tables:" << std::endl + << "DISPLAY_STATS $BBE$ & ( $%12.5SOL, ) & $OBJ$ \\\\" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // F_TARGET: + // --------- + if ( display_all || NOMAD::string_find ( "F_TARGET BASIC BLACK-BOXES BLACKBOXES \ BI-OBJECTIVES STOPPING \ MULTI-OBJECTIVES \ BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "F_TARGET (basic)" ) << std::endl - << ". NOMAD terminates if fi <= F_TARGET[i] for" << std::endl - << " all objectives i" << std::endl - << ". arguments: one or two reals (single or bi-obj.)" << std::endl - << ". no default" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "F_TARGET 0.0 # single-objective" << std::endl - << "F_TARGET ( 0.0 0.0 ) # bi-objective" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - - // HISTORY_FILE: - // ------------- - if ( display_all || NOMAD::string_find ( "HISTORY_FILE BASIC \ + _out << std::endl + << NOMAD::open_block ( "F_TARGET (basic)" ) << std::endl + << ". NOMAD terminates if fi <= F_TARGET[i] for" << std::endl + << " all objectives i" << std::endl + << ". arguments: one or two reals (single or bi-obj.)" << std::endl + << ". no default" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "F_TARGET 0.0 # single-objective" << std::endl + << "F_TARGET ( 0.0 0.0 ) # bi-objective" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + + // HISTORY_FILE: + // ------------- + if ( display_all || NOMAD::string_find ( "HISTORY_FILE BASIC \ FILES OUTPUTS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "HISTORY_FILE (basic)" ) << std::endl - << ". history file: contains all trial points" << std::endl - << ". does not include multiple evaluations" << std::endl - << ". argument: one string" << std::endl - << ". no default" << std::endl - << ". the seed is added to the file name" << std::endl - << " if ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl - << ". example: HISTORY_FILE his.txt" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // INITIAL_MESH_SIZE: - // ------------------ - if ( display_all || NOMAD::string_find ( "INITIAL_MESH_SIZE BASIC MADS \ - DELTA_0 " , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "INITIAL_MESH_SIZE (basic)" ) << std::endl - << ". initial mesh size" << std::endl - << ". arguments: one or DIMENSION positive real(s)" << std::endl - << ". defaults: r0.1 if bounds are defined (10% of the range)," << std::endl - << " max{|x0|,1.0} otherwise" << std::endl - << ". NOMAD uses one mesh size per variable to achieve scaling" << std::endl - << ". values can be given with \'r\' to indicate a proportion of" << std::endl - << " the bounds range (bounds have to be defined for the" << std::endl - << " corresponding variables)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "INITIAL_MESH_SIZE 1.0 # for all variables" << std::endl - << "INITIAL_MESH_SIZE ( 3 - r0.1 ) # for all variables" << std::endl - << " # (default considered" << std::endl - << " # for 2nd variable)" << std::endl - << "INITIAL_MESH_SIZE 1 0.5 # for var. 1 only" << std::endl - << "INITIAL_MESH_SIZE 2-4 r0.25 # for var. 2 to 4" << std::endl - << NOMAD::close_block() - << NOMAD::close_block(); - chk = true; - } - - // LH_SEARCH: - // ---------- - if ( display_all || NOMAD::string_find ( "LH_SEARCH LATIN-HYPERCUBE \ + _out << std::endl + << NOMAD::open_block ( "HISTORY_FILE (basic)" ) << std::endl + << ". history file: contains all trial points" << std::endl + << ". does not include multiple evaluations" << std::endl + << ". argument: one string" << std::endl + << ". no default" << std::endl + << ". the seed is added to the file name" << std::endl + << " if ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl + << ". example: HISTORY_FILE his.txt" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // INITIAL_MESH_SIZE: + // ------------------ + if ( display_all || NOMAD::string_find ( "INITIAL_MESH_SIZE BASIC MADS \ + DELTA_0 " , param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "INITIAL_MESH_SIZE (basic)" ) << std::endl + << ". initial mesh size" << std::endl + << ". arguments: one or DIMENSION positive real(s)" << std::endl + << ". no default" << std::endl + << ". NOMAD uses one mesh size per variable." << std::endl + << ". values can be given with \'r\' to indicate a proportion of" << std::endl + << " the bounds range (bounds have to be defined for the" << std::endl + << " corresponding variables)" << std::endl + << ". initial poll size is determined from initial mesh size" << std::endl + << " when provided, but providing both is not allowed. " << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "INITIAL_MESH_SIZE 1.0 # for all variables" << std::endl + << "INITIAL_MESH_SIZE ( 3 - r0.1 ) # for all variables" << std::endl + << " # (default considered" << std::endl + << " # for 2nd variable)" << std::endl + << "INITIAL_MESH_SIZE 1 0.5 # for var. 1 only" << std::endl + << "INITIAL_MESH_SIZE 2-4 r0.25 # for var. 2 to 4" << std::endl + << NOMAD::close_block() + << NOMAD::close_block(); + chk = true; + } + + + // INITIAL_POLL_SIZE: + // ------------------ + if ( display_all || NOMAD::string_find ( "INITIAL_POLL_SIZE BASIC MADS \ + DELTA_0 " , param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "INITIAL_POLL_SIZE (basic)" ) << std::endl + << ". initial poll size" << std::endl + << ". arguments: one or DIMENSION positive real(s)" << std::endl + << ". defaults: r0.1 if bounds are defined (10% of the range)," << std::endl + << " |x0|/10 otherwise (if x0!=0)" << std::endl + << ". NOMAD uses one poll size per variable to achieve scaling" << std::endl + << ". values can be given with \'r\' to indicate a proportion of" << std::endl + << " the bounds range (bounds have to be defined for the" << std::endl + << " corresponding variables)." << std::endl + << ". the initial mesh size is determined from initial poll size" << std::endl + << " when provided, but providing both is not allowed. " << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "INITIAL_POLL_SIZE 1.0 # for all variables" << std::endl + << "INITIAL_POLL_SIZE ( 3 - r0.1 ) # for all variables" << std::endl + << " # (default considered" << std::endl + << " # for 2nd variable)" << std::endl + << "INITIAL_POLL_SIZE 1 0.5 # for var. 1 only" << std::endl + << "INITIAL_POLL_SIZE 2-4 r0.25 # for var. 2 to 4" << std::endl + << NOMAD::close_block() + << NOMAD::close_block(); + chk = true; + } + + + // LH_SEARCH: + // ---------- + if ( display_all || NOMAD::string_find ( "LH_SEARCH LATIN-HYPERCUBE \ SAMPLING BASIC" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "LH_SEARCH (basic)" ) << std::endl - << ". Latin-Hypercube sampling (search)" << std::endl - << ". arguments: two nonnegative integers p0 and pi" << std::endl - << ". defaults: no search for single-objective" << std::endl - << " or one initial search for bi-objective" << std::endl - << " (see user guide)" << std::endl - << ". p0: number of initial LH search points" << std::endl - << " (or in first MADS run for bi-obj.)" << std::endl - << ". pi: LH search points at each iteration" << std::endl - << " (or in 2nd MADS run for bi-obj.)" << std::endl - << ". the search can be opportunistic or not" << std::endl - << " (see parameter OPPORTUNISTIC_LH)" << std::endl - << ". example: LH_SEARCH 100 0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // LOWER_BOUND: - // ------------ - if ( display_all || NOMAD::string_find ( "LOWER_BOUND BASIC LB BOUNDS FILES" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "LOWER_BOUND (basic)" ) << std::endl - << ". lower bounds for each variable" << std::endl - << ". no default" << std::endl - << ". can be defined by various methods (see user guide)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "LOWER_BOUND * 0.0 # all variables are nonnegative" << std::endl - << "LOWER_BOUND 0-2 0.0 # the 3 first var. are nonnegative" << std::endl - << "LOWER_BOUND 0 0.0 # the first var. is nonnegative" << std::endl - << "LOWER_BOUND lb.txt # bounds are defined in \'lb.txt\'" << std::endl - << " # containing DIMENSION values" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // MAX_BB_EVAL: - // ------------ - if ( display_all || NOMAD::string_find ( "MAX_BB_EVAL BASIC BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "LH_SEARCH (basic)" ) << std::endl + << ". Latin-Hypercube sampling (search)" << std::endl + << ". arguments: two nonnegative integers p0 and pi" << std::endl + << ". defaults: no search for single-objective" << std::endl + << " or one initial search for bi-objective" << std::endl + << " (see user guide)" << std::endl + << ". p0: number of initial LH search points" << std::endl + << " (or in first MADS run for bi-obj.)" << std::endl + << ". pi: LH search points at each iteration" << std::endl + << " (or in 2nd MADS run for bi-obj.)" << std::endl + << ". the search can be opportunistic or not" << std::endl + << " (see parameter OPPORTUNISTIC_LH)" << std::endl + << ". example: LH_SEARCH 100 0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // LOWER_BOUND: + // ------------ + if ( display_all || NOMAD::string_find ( "LOWER_BOUND BASIC LB BOUNDS FILES" , + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "LOWER_BOUND (basic)" ) << std::endl + << ". lower bounds for each variable" << std::endl + << ". no default" << std::endl + << ". can be defined by various methods (see user guide)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "LOWER_BOUND * 0.0 # all variables are nonnegative" << std::endl + << "LOWER_BOUND 0-2 0.0 # the 3 first var. are nonnegative" << std::endl + << "LOWER_BOUND 0 0.0 # the first var. is nonnegative" << std::endl + << "LOWER_BOUND lb.txt # bounds are defined in \'lb.txt\'" << std::endl + << " # containing DIMENSION values" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // MAX_BB_EVAL: + // ------------ + if ( display_all || NOMAD::string_find ( "MAX_BB_EVAL BASIC BLACK-BOXES BLACKBOXES \ MAXIMUM CACHE BBEVAL \ NUMBER EVALUATIONS STOPPING \ BI-0BJECTIVE MULTI-OBJECTIVE \ BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_BB_EVAL (basic)" ) << std::endl - << ". maximum number of blackbox evaluations" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". doesn\'t consider evaluations taken in the" << std::endl - << " cache (cache hits)" << std::endl - << ". in bi-objective mode: max number of blackbox" << std::endl - << " evaluations for each MADS run" << std::endl - << ". example: MAX_BB_EVAL 1000" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_TIME: - // --------- - if ( display_all || NOMAD::string_find ( "MAX_TIME BASIC BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "MAX_BB_EVAL (basic)" ) << std::endl + << ". maximum number of blackbox evaluations" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". doesn\'t consider evaluations taken in the" << std::endl + << " cache (cache hits)" << std::endl + << ". in bi-objective mode: max number of blackbox" << std::endl + << " evaluations for each MADS run" << std::endl + << ". example: MAX_BB_EVAL 1000" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_TIME: + // --------- + if ( display_all || NOMAD::string_find ( "MAX_TIME BASIC BLACK-BOXES BLACKBOXES \ MAXIMUM WALL-CLOCK REAL \ STOPPING TERMINATION \ TERMINATES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_TIME (basic)" ) << std::endl - << ". maximum wall-clock time in seconds" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". example: MAX_TIME 3600 # one hour max" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // SOLUTION_FILE: - // -------------- - if ( display_all || NOMAD::string_find ( "SOLUTION_FILE BASIC \ + _out << std::endl + << NOMAD::open_block ( "MAX_TIME (basic)" ) << std::endl + << ". maximum wall-clock time in seconds" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". example: MAX_TIME 3600 # one hour max" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // SOLUTION_FILE: + // -------------- + if ( display_all || NOMAD::string_find ( "SOLUTION_FILE BASIC \ FILES OUTPUTS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SOLUTION_FILE (basic)" ) << std::endl - << ". file containing the solution" << std::endl - << ". argument: one string" << std::endl - << ". no default" << std::endl - << ". the seed is added to the file name if" << std::endl - << " ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl - << ". example: SOLUTION_FILE sol.txt" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // STATS_FILE: - // ----------- - if ( display_all || NOMAD::string_find ( "STATS_FILE BASIC \ + _out << std::endl + << NOMAD::open_block ( "SOLUTION_FILE (basic)" ) << std::endl + << ". file containing the solution" << std::endl + << ". argument: one string" << std::endl + << ". no default" << std::endl + << ". the seed is added to the file name if" << std::endl + << " ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl + << ". example: SOLUTION_FILE sol.txt" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // STATS_FILE: + // ----------- + if ( display_all || NOMAD::string_find ( "STATS_FILE BASIC \ FILES OUTPUTS DISPLAY_STATS" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "STATS_FILE (basic)" ) << std::endl - << ". file containing all successes with the same format" << std::endl - << " than DISPLAY_STATS" << std::endl - << ". displays more points with DISPLAY_ALL_EVAL=true" << std::endl - << ". arguments: one string (file name) and one" << std::endl - << " list of strings (stats)" << std::endl - << ". no default" << std::endl - << ". the seed is added to the file name if" << std::endl - << " ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl - << ". example: STATS_FILE log.txt BBE SOL f=%.2EOBJ" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // TMP_DIR: - // -------- - if ( display_all || NOMAD::string_find ( "TMP_DIR BASIC PATH TEMPORARY \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "STATS_FILE (basic)" ) << std::endl + << ". file containing all successes with the same format" << std::endl + << " than DISPLAY_STATS" << std::endl + << ". displays more points with DISPLAY_ALL_EVAL=true" << std::endl + << ". arguments: one string (file name) and one" << std::endl + << " list of strings (stats)" << std::endl + << ". no default" << std::endl + << ". the seed is added to the file name if" << std::endl + << " ADD_SEED_TO_FILE_NAMES=\'yes\'" << std::endl + << ". example: STATS_FILE log.txt BBE SOL f=%.2EOBJ" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // TMP_DIR: + // -------- + if ( display_all || NOMAD::string_find ( "TMP_DIR BASIC PATH TEMPORARY \ DIRECTORY FILES \ BLACK-BOXES BLACKBOXES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "TMP_DIR (basic)" ) << std::endl - << ". temporary directory for blackbox input/output files" << std::endl - << ". argument: one string indicating a directory" << std::endl - << ". default: problem directory" << std::endl - << ". improved performance with a local temporary directory" << std::endl - << ". example: TMP_DIR /tmp" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // UPPER_BOUND: - // ------------ - if ( display_all || NOMAD::string_find ( "UPPER_BOUND BASIC UB BOUNDS" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "UPPER_BOUND (basic)" ) << std::endl - << ". upper bounds for each variable" << std::endl - << ". same logic as parameter LOWER_BOUND" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // X0: - // --- - if ( display_all || NOMAD::string_find ( "X0 STARTING POINT BASIC \ + _out << std::endl + << NOMAD::open_block ( "TMP_DIR (basic)" ) << std::endl + << ". temporary directory for blackbox input/output files" << std::endl + << ". argument: one string indicating a directory" << std::endl + << ". default: problem directory" << std::endl + << ". improved performance with a local temporary directory" << std::endl + << ". example: TMP_DIR /tmp" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // UPPER_BOUND: + // ------------ + if ( display_all || NOMAD::string_find ( "UPPER_BOUND BASIC UB BOUNDS" , + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "UPPER_BOUND (basic)" ) << std::endl + << ". upper bounds for each variable" << std::endl + << ". same logic as parameter LOWER_BOUND" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // X0: + // --- + if ( display_all || NOMAD::string_find ( "X0 STARTING POINT BASIC \ VARIABLES \ LH LATIN-HYPERCUBE \ CACHE FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "X0 (basic)" ) << std::endl - << ". starting point(s)" << std::endl - << ". arguments: text file name," << std::endl - << " or cache file name," << std::endl - << " or DIMENSION reals," << std::endl - << " or indexed values" << std::endl - << ". default: best point from a cache file or from" << std::endl - << " an initial LH search" << std::endl - << ". do not use a surrogate cache file" << std::endl - << " (even if OPT_ONLY_SGTE=\'yes\')" << std::endl - << ". more than one starting point can be defined (all points" << std::endl - << " are evaluated: x0 evaluations are not opportunistic)" << std:: endl - << ". a text file can describe more than one point" << std::endl - << ". may be infeasible, but can only violate PB, F, or PEB" << std::endl - << " constraints" << std::endl - << ". cannot be outside bounds" << std::endl - << ". must respect fixed variables (param. FIXED_VARIABLE)" << std::endl - << ". " << NOMAD::open_block ("examples") << std::endl - << "X0 x0.txt # text file with a multiple" << std::endl - << " # of DIMENSION values" << std::endl << std::endl - << "X0 * 0.0 # first starting point" << std::endl - << "X0 1 * 1.0 # second starting point" << std::endl << std::endl - << "X0 ( 0 1 2 ) # if DIMENSION=3" << std::endl << std::endl - << "see other examples in user guide" << std::endl - << NOMAD::close_block() - << NOMAD::close_block(); - chk = true; - } - - - if ( display_all || NOMAD::string_find ( registered_key_advanced , param_names ) ) - { - _out << "--------------------------------------------------------------" << endl; - _out << "---------------------ADVANCED PARAMETERS----------------------" << endl; - _out << "--------------------------------------------------------------" << endl; - } - - // ADD_SEED_TO_FILE_NAMES: - // ----------------------- - if ( display_all || NOMAD::string_find ( "ADD_SEED_TO_FILE_NAMES OUTPUTS \ + _out << std::endl + << NOMAD::open_block ( "X0 (basic)" ) << std::endl + << ". starting point(s)" << std::endl + << ". arguments: text file name," << std::endl + << " or cache file name," << std::endl + << " or DIMENSION reals," << std::endl + << " or indexed values" << std::endl + << ". default: best point from a cache file or from" << std::endl + << " an initial LH search" << std::endl + << ". do not use a surrogate cache file" << std::endl + << " (even if OPT_ONLY_SGTE=\'yes\')" << std::endl + << ". more than one starting point can be defined (all points" << std::endl + << " are evaluated: x0 evaluations are not opportunistic)" << std:: endl + << ". a text file can describe more than one point" << std::endl + << ". may be infeasible, but can only violate PB, F, or PEB" << std::endl + << " constraints" << std::endl + << ". cannot be outside bounds" << std::endl + << ". must respect fixed variables (param. FIXED_VARIABLE)" << std::endl + << ". " << NOMAD::open_block ("examples") << std::endl + << "X0 x0.txt # text file with a multiple" << std::endl + << " # of DIMENSION values" << std::endl << std::endl + << "X0 * 0.0 # first starting point" << std::endl + << "X0 1 * 1.0 # second starting point" << std::endl << std::endl + << "X0 ( 0 1 2 ) # if DIMENSION=3" << std::endl << std::endl + << "see other examples in user guide" << std::endl + << NOMAD::close_block() + << NOMAD::close_block(); + chk = true; + } + + + if ( display_all || NOMAD::string_find ( registered_key_advanced , param_names ) ) + { + _out << "--------------------------------------------------------------" << endl; + _out << "---------------------ADVANCED PARAMETERS----------------------" << endl; + _out << "--------------------------------------------------------------" << endl; + } + + // ADD_SEED_TO_FILE_NAMES: + // ----------------------- + if ( display_all || NOMAD::string_find ( "ADD_SEED_TO_FILE_NAMES OUTPUTS \ ADVANCED FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "ADD_SEED_TO_FILE_NAMES (advanced)" ) << std::endl - << ". if \'yes\', the seed is added to the name of" << std::endl - << " output files (HISTORY_FILE, SOLUTION_FILE," << std::endl - << " and STATS_FILE)" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: ADD_SEED_TO_FILE_NAMES no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // ASYNCHRONOUS: - // ------------- - if ( display_all || NOMAD::string_find ( "ASYNCHRONOUS PARALLELISM MPI \ + _out << std::endl + << NOMAD::open_block ( "ADD_SEED_TO_FILE_NAMES (advanced)" ) << std::endl + << ". if \'yes\', the seed is added to the name of" << std::endl + << " output files (HISTORY_FILE, SOLUTION_FILE," << std::endl + << " and STATS_FILE)" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: ADD_SEED_TO_FILE_NAMES no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // ANISOTROPIC_MESH: + // ------------- + if ( display_all || NOMAD::string_find ( "ANISOTROPIC MESH SCALING" , param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "ANISOTROPIC_MESH (advanced)" ) << std::endl + << ". use anisotropic mesh for generating directions" << std::endl + << ". if \'yes\', the mesh size is scaled dynamically" << std::endl + << ". based on direction of success." << std::endl + << ". This option is compatible with Ortho Mads " << std::endl + << ". directions only " << std::endl + << ". default: \'yes\'" << std::endl + << ". example: ANISOTROPIC_MESH no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // ASYNCHRONOUS: + // ------------- + if ( display_all || NOMAD::string_find ( "ASYNCHRONOUS PARALLELISM MPI \ ADVANCED PMADS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "ASYNCHRONOUS (advanced)" ) << std::endl - << ". asynchronous strategy for the parallel version" << std::endl - << ". if \'yes\', there can be evaluations in progress" << std::endl - << " after an iteration has ended" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: ASYNCHRONOUS no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // BB_INPUT_INCLUDE_SEED: - // ---------------------- - if ( display_all || NOMAD::string_find ( "BB_INPUT_INCLUDE_SEED BLACK-BOXES \ + _out << std::endl + << NOMAD::open_block ( "ASYNCHRONOUS (advanced)" ) << std::endl + << ". asynchronous strategy for the parallel version" << std::endl + << ". if \'yes\', there can be evaluations in progress" << std::endl + << " after an iteration has ended" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: ASYNCHRONOUS no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // BB_INPUT_INCLUDE_SEED: + // ---------------------- + if ( display_all || NOMAD::string_find ( "BB_INPUT_INCLUDE_SEED BLACK-BOXES \ BLACKBOXES \ ADVANCED FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_INPUT_INCLUDE_SEED (advanced)" ) << std::endl - << ". if \'yes\', the seed (\'SEED\') of the current" << std::endl - << " execution is put as the first entry in" << std::endl - << " all blackbox input files" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: BB_INPUT_INCLUDE_SEED yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // BB_INPUT_INCLUDE_TAG: - // --------------------- - if ( display_all || NOMAD::string_find ( "BB_INPUT_INCLUDE_TAG \ + _out << std::endl + << NOMAD::open_block ( "BB_INPUT_INCLUDE_SEED (advanced)" ) << std::endl + << ". if \'yes\', the seed (\'SEED\') of the current" << std::endl + << " execution is put as the first entry in" << std::endl + << " all blackbox input files" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: BB_INPUT_INCLUDE_SEED yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // BB_INPUT_INCLUDE_TAG: + // --------------------- + if ( display_all || NOMAD::string_find ( "BB_INPUT_INCLUDE_TAG \ BLACK-BOXES BLACKBOXES \ ADVANCED FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_INPUT_INCLUDE_TAG (advanced)" ) << std::endl - << ". if \'yes\', the tag of a point is put as the first" << std::endl - << " entry in all blackbox input files (second" << std::endl - << " entry if BB_INPUT_INCLUDE_SEED=\'yes\')" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: BB_INPUT_INCLUDE_TAG yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // BB_REDIRECTION: - // --------------- - if ( display_all || NOMAD::string_find ( "BB_REDIRECTION BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "BB_INPUT_INCLUDE_TAG (advanced)" ) << std::endl + << ". if \'yes\', the tag of a point is put as the first" << std::endl + << " entry in all blackbox input files (second" << std::endl + << " entry if BB_INPUT_INCLUDE_SEED=\'yes\')" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: BB_INPUT_INCLUDE_TAG yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // BB_REDIRECTION: + // --------------- + if ( display_all || NOMAD::string_find ( "BB_REDIRECTION BLACK-BOXES BLACKBOXES \ ADVANCED OUTPUT FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "BB_REDIRECTION (advanced)" ) << std::endl - << ". if NOMAD uses a redirection (\'>\') to" << std::endl - << " create blackbox output files" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". if \'no\', the blackbox has to manage its" << std::endl - << " own output files (see user guide)" << std::endl - << ". example: BB_INPUT_INCLUDE_TAG yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // CACHE_SAVE_PERIOD: - // ------------------ - if ( display_all || NOMAD::string_find ( "CACHE_SAVE_PERIOD OUTPUTS \ + _out << std::endl + << NOMAD::open_block ( "BB_REDIRECTION (advanced)" ) << std::endl + << ". if NOMAD uses a redirection (\'>\') to" << std::endl + << " create blackbox output files" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". if \'no\', the blackbox has to manage its" << std::endl + << " own output files (see user guide)" << std::endl + << ". example: BB_INPUT_INCLUDE_TAG yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // CACHE_SAVE_PERIOD: + // ------------------ + if ( display_all || NOMAD::string_find ( "CACHE_SAVE_PERIOD OUTPUTS \ ITERATIONS ADVANCED FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "CACHE_SAVE_PERIOD (advanced)" ) << std::endl - << ". period (iterations) at which the cache file is saved" << std::endl - << " (if CACHE_FILE is defined; disabled for bi-objective)" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". default: 25" << std::endl - << ". example: CACHE_SAVE_PERIOD 10" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // CACHE_SEARCH: - // ------------- - if ( display_all || NOMAD::string_find ( "CACHE_SEARCH ADVANCED\ + _out << std::endl + << NOMAD::open_block ( "CACHE_SAVE_PERIOD (advanced)" ) << std::endl + << ". period (iterations) at which the cache file is saved" << std::endl + << " (if CACHE_FILE is defined; disabled for bi-objective)" << std::endl + << ". argument: one nonnegative integer" << std::endl + << ". default: 25" << std::endl + << ". example: CACHE_SAVE_PERIOD 10" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // CACHE_SEARCH: + // ------------- + if ( display_all || NOMAD::string_find ( "CACHE_SEARCH ADVANCED\ CACHE_FILE SGTE_CACHE_FILE" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "CACHE_SEARCH (advanced)" ) << std::endl - << ". enable or disable the cache search" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". the search looks in the cache between iterations" << std::endl - << ". this can be useful when a non-empty initial cache" << std::endl - << " file is provided or with an extern cache that" << std::endl - << " the user updates independently" << std::endl - << ". example: CACHE_SEARCH yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // CLOSED_BRACE: - // ------------- - if ( display_all || NOMAD::string_find ( "CLOSED_BRACES INDENTATION TABULATIONS \ + _out << std::endl + << NOMAD::open_block ( "CACHE_SEARCH (advanced)" ) << std::endl + << ". enable or disable the cache search" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". the search looks in the cache between iterations" << std::endl + << ". this can be useful when a non-empty initial cache" << std::endl + << " file is provided or with an extern cache that" << std::endl + << " the user updates independently" << std::endl + << ". example: CACHE_SEARCH yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // CLOSED_BRACE: + // ------------- + if ( display_all || NOMAD::string_find ( "CLOSED_BRACES INDENTATION TABULATIONS \ BLOCKS ADVANCED DISPLAY" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "CLOSED_BRACE (advanced)" ) << std::endl - << ". string displayed at the end of indented" << std::endl - << " blocks in full display mode" << std::endl - << ". argument: one string" << std::endl - << ". default: \'}\'" << std::endl - << ". example: CLOSED_BRACE End" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // DISABLE MODELS - //----------- - if ( display_all || NOMAD::string_find ( "MODEL DISABLE MODELS DISABLE_MODELS \ - MODEL_EVAL_SORT ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "CLOSED_BRACE (advanced)" ) << std::endl + << ". string displayed at the end of indented" << std::endl + << " blocks in full display mode" << std::endl + << ". argument: one string" << std::endl + << ". default: \'}\'" << std::endl + << ". example: CLOSED_BRACE End" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // DISABLE MODELS / EVAL_SORT + //----------- + if ( display_all || NOMAD::string_find ( "MODEL DISABLE MODELS DISABLE_MODELS \ + MODEL_EVAL_SORT ADVANCED \ + EVAL_SORT \ ORTHO N+1 QUAD QUADRATIC MODEL_SEARCH TGP " , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "DISABLE (advanced)" ) << std::endl - << ". this parameter is used to forcefully disable a feature." << std::endl - << ". argument: MODELS" << std::endl - << ". # DISABLE MODELS is equivalent to set: " << std::endl - << " MODEL_EVAL_SORT no " << std::endl - << " MODEL_SEARCH no " << std::endl - << " DIRECTION_TYPE ORTHO N+1 NEG " << std::endl - << " # WARNING: extra settings of MODEL_EVAL_SORT," << std::endl - << " MODEL_SEARCH and DIRECTION_TYPE ORTHO N+1 QUAD" << std::endl - << " will be ignored " << std::endl - << ". default: no default" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // EXTENDED_POLL_ENABLED: - // ---------------------- - if ( display_all || NOMAD::string_find ( "EXTENDED_POLL_ENABLED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "DISABLE (advanced)" ) << std::endl + << ". this parameter is used to forcefully disable a feature." << std::endl + << ". argument: MODELS or EVAL_SORT" << std::endl + << ". # DISABLE MODELS is equivalent to set: " << std::endl + << " MODEL_EVAL_SORT no " << std::endl + << " MODEL_SEARCH no " << std::endl + << " DIRECTION_TYPE ORTHO N+1 NEG " << std::endl + << " # WARNING: extra settings of MODEL_EVAL_SORT," << std::endl + << " MODEL_SEARCH and DIRECTION_TYPE ORTHO N+1 QUAD" << std::endl + << " will be ignored " << std::endl + << ". # DISABLE EVAL_SORT: ordering by lexicographic order only. " << std::endl + << " # WARNING: setting of MODEL_EVAL_SORT," << std::endl + << " SURROGATE_EVAL_SORT and user priority " << std::endl + << " will be ignored" << std::endl + << ". default: no default" << std::endl + + << NOMAD::close_block(); + chk = true; + } + + // BB_MAX_BLOCK_SIZE + //----------- + if ( display_all || NOMAD::string_find ( "EVAL LIST MAX BLOCK SIZE BB BLACKBOX \ + BLACK-BOX OPPORTUNIST OPPORTUNISTIC PARALLEL", + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "BB_MAX_BLOCK_SIZE (advanced)" ) << std::endl + << ". maximum size of a block of evaluations send to the blackbox" << std::endl + << " executable at once. Blackbox executable can manage parallel" << std::endl + << " evaluations on its own. Opportunistic strategies may apply after" << std::endl + << " each block of evaluations." << std::endl + << " Depending on the algorithm phase, the blackbox executable will" << std::endl + << " receive at most BB_MAX_BLOCK_SIZE points to evaluate." << std::endl + << " When this parameter is greater than one, the number of evaluations"<< std::endl + << " may exceed the MAX_BB_EVAL stopping criterion." << std::endl + << ". argument: integer > 0" << std::endl + << ". example: BB_MAX_BLOCK_SIZE 3," << std::endl + << " The blackbox executable receives blocks of" << std::endl + << " at most 3 points for evaluation." << std::endl + << ". default: 1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // EXTENDED_POLL_ENABLED: + // ---------------------- + if ( display_all || NOMAD::string_find ( "EXTENDED_POLL_ENABLED \ EXTENDED_POLL_DISABLED \ MIXED MVP CATEGORICAL \ ADVANCED" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "EXTENDED_POLL_ENABLED (advanced)" ) << std::endl - << ". if \'no\', the extended poll for categorical" << std::endl - << " variables is disabled" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". the extended poll uses the surrogate" << std::endl - << " if HAS_SGTE or SGTE_EXE is defined" << std::endl - << ". example: EXTENDED_POLL_ENABLED yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // EXTENDED_POLL_TRIGGER: - // ---------------------- - if ( display_all || NOMAD::string_find ( "EXTENDED_POLL_TRIGGER ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "EXTENDED_POLL_ENABLED (advanced)" ) << std::endl + << ". if \'no\', the extended poll for categorical" << std::endl + << " variables is disabled" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". the extended poll uses the surrogate" << std::endl + << " if HAS_SGTE or SGTE_EXE is defined" << std::endl + << ". example: EXTENDED_POLL_ENABLED yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // EXTENDED_POLL_TRIGGER: + // ---------------------- + if ( display_all || NOMAD::string_find ( "EXTENDED_POLL_TRIGGER ADVANCED \ MIXED MVP CATEGORICAL" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "EXTENDED_POLL_TRIGGER (advanced)" ) << std::endl - << ". extended poll trigger for categorical variables" << std::endl - << ". argument: one positive real (can be relative)" << std::endl - << ". an extended poll around the extended poll point y" << std::endl - << " constructed from an iterate xk is performed if" << std::endl - << " f(y) < f(xk)+trigger or f(y) < f(xk)+|f(x_k)|*trigger" << std::endl - << " (relative value)" << std::endl - << ". see details in user guide" << std::endl - << ". default: r0.1" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "EXTENDED_POLL_TRIGGER 10.0 # ext poll trigger of 10" << std::endl - << "EXTENDED_POLL_TRIGGER r0.2 # ext poll trigger of 20%" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - - // FIXED_VARIABLE: - // --------------- - if ( display_all || NOMAD::string_find ( "FIXED_VARIABLE VARIABLES ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "EXTENDED_POLL_TRIGGER (advanced)" ) << std::endl + << ". extended poll trigger for categorical variables" << std::endl + << ". argument: one positive real (can be relative)" << std::endl + << ". an extended poll around the extended poll point y" << std::endl + << " constructed from an iterate xk is performed if" << std::endl + << " f(y) < f(xk)+trigger or f(y) < f(xk)+|f(x_k)|*trigger" << std::endl + << " (relative value)" << std::endl + << ". see details in user guide" << std::endl + << ". default: r0.1" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "EXTENDED_POLL_TRIGGER 10.0 # ext poll trigger of 10" << std::endl + << "EXTENDED_POLL_TRIGGER r0.2 # ext poll trigger of 20%" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + + // FIXED_VARIABLE: + // --------------- + if ( display_all || NOMAD::string_find ( "FIXED_VARIABLE VARIABLES ADVANCED \ FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "FIXED_VARIABLE (advanced)" ) << std::endl - << ". fix some variables to some specific values" << std::endl - << ". arguments: variable indexes and values" << std::endl - << ". no default" << std::endl - << ". values are optional if at least one starting point" << std::endl - << " is defined" << std::endl - << ". can be given by a text file containing DIMENSION" << std::endl - << " entrie (use \'-\' for free variables)" << std::endl - << ". variables inside groups defined by VARIABLE_GROUP" << std::endl - << " cannot be fixed" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "FIXED_VARIABLE ( 0.0 - 0.0 ) # variables 0 and 2 are fixed" << std::endl - << "FIXED_VARIABLE fixed.txt # with a file" << std::endl - << "FIXED_VARIABLE 0-1 3.14 # 2 first variables fixed" << std::endl - << " # to 3.14" << std::endl - << "FIXED_VARIABLE 0 # first variable fixed to" << std::endl - << " # its X0 value" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // HALTON_SEED: - // ------------ - if ( display_all || NOMAD::string_find ( "HALTON_SEED ADVANCED ORTHO-MADS ORTHOMADS \ - RANDOM \ - DETERMINISTIC ORTHOGONAL DIRECTIONS \ - POLL" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "HALTON_SEED (advanced)" ) << std::endl - << ". Halton seed to get different runs with OrthoMADS" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". default: the DIMENSION^th prime number" << std::endl - << ". choose values greater than or equal to this default" << std::endl - << ". see also parameter SEED for different LT-MADS runs" << std::endl - << ". example: HALTON_SEED 10" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // H_MAX_0: - // -------- - if ( display_all || NOMAD::string_find ( "H_MAX_0 HMAX_0 HMAX ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "FIXED_VARIABLE (advanced)" ) << std::endl + << ". fix some variables to some specific values" << std::endl + << ". arguments: variable indexes and values" << std::endl + << ". no default" << std::endl + << ". values are optional if at least one starting point" << std::endl + << " is defined" << std::endl + << ". can be given by a text file containing DIMENSION" << std::endl + << " entrie (use \'-\' for free variables)" << std::endl + << ". variables inside groups defined by VARIABLE_GROUP" << std::endl + << " cannot be fixed" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "FIXED_VARIABLE ( 0.0 - 0.0 ) # variables 0 and 2 are fixed" << std::endl + << "FIXED_VARIABLE fixed.txt # with a file" << std::endl + << "FIXED_VARIABLE 0-1 3.14 # 2 first variables fixed" << std::endl + << " # to 3.14" << std::endl + << "FIXED_VARIABLE 0 # first variable fixed to" << std::endl + << " # its X0 value" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // H_MAX_0: + // -------- + if ( display_all || NOMAD::string_find ( "H_MAX_0 HMAX_0 HMAX ADVANCED \ CONSTRAINTS PB FILTER PEB \ L1 L2 LINF L_INF \ FEASIBILITY \ PROGRESSIVE-BARRIER" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "H_MAX_0 (advanced)" ) << std::endl - << ". initial value of h_max (for PB and" << std::endl - << " F constraints handling strategies)" << std::endl - << ". argument: one positive real" << std::endl - << ". default: 1E+20" << std::endl - << ". points x such that h(x) > h_max are" << std::endl - << " rejected (h measures the feasibility)" << std::endl - << ". example: H_MAX_0 100.0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // H_MIN: - // ------ - if ( display_all || NOMAD::string_find ( "H_MIN HMIN ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "H_MAX_0 (advanced)" ) << std::endl + << ". initial value of h_max (for PB and" << std::endl + << " F constraints handling strategies)" << std::endl + << ". argument: one positive real" << std::endl + << ". default: 1E+20" << std::endl + << ". points x such that h(x) > h_max are" << std::endl + << " rejected (h measures the feasibility)" << std::endl + << ". example: H_MAX_0 100.0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // H_MIN: + // ------ + if ( display_all || NOMAD::string_find ( "H_MIN HMIN ADVANCED \ CONSTRAINTS PB FILTER PEB \ L1 L2 LINF L_INF \ FEASIBILITY \ PROGRESSIVE-BARRIER" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "H_MIN (advanced)" ) << std::endl - << ". value of h_min; x is feasible if h(x) <= h_min" << std::endl - << " (h measures the feasibility)" << std::endl - << ". argument: one positive real" << std::endl - << ". default: 0.0" << std::endl - << ". example: H_MIN 1E-5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // H_NORM: - // ------- - if ( display_all || NOMAD::string_find ( "H_NORM ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "H_MIN (advanced)" ) << std::endl + << ". value of h_min; x is feasible if h(x) <= h_min" << std::endl + << " (h measures the feasibility)" << std::endl + << ". argument: one positive real" << std::endl + << ". default: 0.0" << std::endl + << ". example: H_MIN 1E-5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // H_NORM: + // ------- + if ( display_all || NOMAD::string_find ( "H_NORM ADVANCED \ CONSTRAINTS PB FILTER PEB \ L1 L2 LINF L_INF \ FEASIBILITY \ PROGRESSIVE-BARRIER" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "H_NORM (advanced)" ) << std::endl - << ". norm used by the F and PB constraints handling" << std::endl - << " strategies to compute h(x) (h measures the" << std::endl - << " feasibility)" << std::endl - << ". argument: one string in {\'L1\', \'L2\', \'Linf\'}" << std::endl - << ". default: \'L2\'" << std::endl - << ". example: H_NORM Linf" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // HAS_SGTE: - // --------- - if ( display_all || NOMAD::string_find ( "HAS_SGTE SGTE_EXE ADVANCED SURROGATES \ + _out << std::endl + << NOMAD::open_block ( "H_NORM (advanced)" ) << std::endl + << ". norm used by the F and PB constraints handling" << std::endl + << " strategies to compute h(x) (h measures the" << std::endl + << " feasibility)" << std::endl + << ". argument: one string in {\'L1\', \'L2\', \'Linf\'}" << std::endl + << ". default: \'L2\'" << std::endl + << ". example: H_NORM Linf" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // HAS_SGTE: + // --------- + if ( display_all || NOMAD::string_find ( "HAS_SGTE SGTE_EXE ADVANCED SURROGATES \ BLACK-BOXES BLACKBOXES \ SGTES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "HAS_SGTE (advanced)" ) << std::endl - << ". to indicate that the problem has a surrogate" << std::endl - << ". argument: one boolean (\'yes\' or \'no\') " << std::endl - << ". default: \'no\' if parameter SGTE_EXE is undefined," << std::endl - << " \'yes\' otherwise" << std::endl - << ". this parameter is not necessary in batch" << std::endl - << " mode, but essential in library mode when" << std::endl - << " no surrogate executable is provided" << std::endl - << ". example: HAS_SGTE yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // INF_STR: - // -------- - if ( display_all || NOMAD::string_find ( "INF_STR ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "HAS_SGTE (advanced)" ) << std::endl + << ". to indicate that the problem has a surrogate" << std::endl + << ". argument: one boolean (\'yes\' or \'no\') " << std::endl + << ". default: \'no\' if parameter SGTE_EXE is undefined," << std::endl + << " \'yes\' otherwise" << std::endl + << ". this parameter is not necessary in batch" << std::endl + << " mode, but essential in library mode when" << std::endl + << " no surrogate executable is provided" << std::endl + << ". example: HAS_SGTE yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // INF_STR: + // -------- + if ( display_all || NOMAD::string_find ( "INF_STR ADVANCED \ INFINITY DISPLAY REALS" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "INF_STR (advanced)" ) << std::endl - << ". string used to display infinity" << std::endl - << ". argument: one string" << std::endl - << ". default: \"inf\"" << std::endl - << ". example: INF_STR Infinity" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // INITIAL_MESH_INDEX: - // ------------------- - if ( display_all || NOMAD::string_find ( "INITIAL_MESH_INDEX ADVANCED \\DELTA \ - MADS L0 L_0 \\ELL_0" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "INITIAL_MESH_INDEX (advanced)" ) << std::endl - << ". initial mesh index \\ell_0" << std::endl - << ". argument: one integer (can be negative)" << std::endl - << ". default: 0" << std::endl - << ". example: INITIAL_MESH_INDEX -1" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MAX_CACHE_MEMORY: - // ----------------- - if ( display_all || NOMAD::string_find ( "MAX_CACHE_MEMORY ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "INF_STR (advanced)" ) << std::endl + << ". string used to display infinity" << std::endl + << ". argument: one string" << std::endl + << ". default: \"inf\"" << std::endl + << ". example: INF_STR Infinity" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_CACHE_MEMORY: + // ----------------- + if ( display_all || NOMAD::string_find ( "MAX_CACHE_MEMORY ADVANCED \ MAXIMUM RAM STOPPING \ MB MEGA-BYTES MEGABYTES \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_CACHE_MEMORY (advanced)" ) << std::endl - << ". the program terminates as soon as the cache" << std::endl - << " reaches this memory limit" << std::endl - << ". argument: one positive integer (expressed in MB)" << std::endl - << ". default: 2000" << std::endl - << ". example: MAX_CACHE_MEMORY 1024 # limit of 1GB cache" << std::endl - << " # occupation" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_CONSECUTIVE_FAILED_ITERATIONS: - // ---------------------------------- - if ( display_all || NOMAD::string_find ( "MAX_CONSECUTIVE_FAILED_ITERATIONS ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MAX_CACHE_MEMORY (advanced)" ) << std::endl + << ". the program terminates as soon as the cache" << std::endl + << " reaches this memory limit" << std::endl + << ". argument: one positive integer (expressed in MB)" << std::endl + << ". default: 2000" << std::endl + << ". example: MAX_CACHE_MEMORY 1024 # limit of 1GB cache" << std::endl + << " # occupation" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_CONSECUTIVE_FAILED_ITERATIONS: + // ---------------------------------- + if ( display_all || NOMAD::string_find ( "MAX_CONSECUTIVE_FAILED_ITERATIONS ADVANCED \ TERMINATION STOPPING TERMINATES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_CONSECUTIVE_FAILED_ITERATIONS (advanced)" ) << std::endl - << ". maximum number of consecutive failed iterations" << std::endl - << ". arguments: one positive integer" << std::endl - << ". no default" << std::endl - << ". example: MAX_CONSECUTIVE_FAILED_ITERATIONS 5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_EVAL: - // --------- - if ( display_all || NOMAD::string_find ( "MAX_EVAL ADVANCED BLACK-BOXES BLACKBOXES \ + _out << std::endl + << NOMAD::open_block ( "MAX_CONSECUTIVE_FAILED_ITERATIONS (advanced)" ) << std::endl + << ". maximum number of consecutive failed iterations" << std::endl + << ". arguments: one positive integer" << std::endl + << ". no default" << std::endl + << ". example: MAX_CONSECUTIVE_FAILED_ITERATIONS 5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_EVAL: + // --------- + if ( display_all || NOMAD::string_find ( "MAX_EVAL ADVANCED BLACK-BOXES BLACKBOXES \ MAXIMUM CACHE BBEVAL \ NUMBER EVALUATIONS STOPPING \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_EVAL (advanced)" ) << std::endl - << ". maximum number of evaluations" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". includes evaluations taken in" << std::endl - << " the cache (cache hits)" << std::endl - << ". example: MAX_EVAL 1000" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_ITERATIONS: - // --------------- - if ( display_all || NOMAD::string_find ( "MAX_ITERATIONS ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MAX_EVAL (advanced)" ) << std::endl + << ". maximum number of evaluations" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". includes evaluations taken in" << std::endl + << " the cache (cache hits)" << std::endl + << ". example: MAX_EVAL 1000" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_ITERATIONS: + // --------------- + if ( display_all || NOMAD::string_find ( "MAX_ITERATIONS ADVANCED \ MAXIMUM MADS \ NUMBER STOPPING \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_ITERATIONS (advanced)" ) << std::endl - << ". maximum number of MADS iterations" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". example: MAX_ITERATIONS 20" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_MESH_INDEX: - // --------------- - if ( display_all || NOMAD::string_find ( "MAX_MESH_INDEX ADVANCED MAXIMUM \ - \\DELTA TERMINATION \ - STOPPING TERMINATES \\ELL" , param_names ) ) - { - _out << std::endl - << NOMAD::open_block ( "MAX_MESH_INDEX (advanced)" ) << std::endl - << ". maximum mesh index" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". no default" << std::endl - << ". example: MAX_MESH_INDEX 5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_SGTE_EVAL: - // -------------- - if ( display_all || NOMAD::string_find ( "MAX_SGTE_EVAL ADVANCED BLACK-BOXES \ + _out << std::endl + << NOMAD::open_block ( "MAX_ITERATIONS (advanced)" ) << std::endl + << ". maximum number of MADS iterations" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". example: MAX_ITERATIONS 20" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MAX_SGTE_EVAL: + // -------------- + if ( display_all || NOMAD::string_find ( "MAX_SGTE_EVAL ADVANCED BLACK-BOXES \ BLACKBOXES \ MAXIMUM SURROGATES BBEVAL SGTES \ NUMBER EVALUATIONS STOPPING \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_SGTE_EVAL (advanced)" ) << std::endl - << ". maximum number of surrogate evaluations" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". example: MAX_SGTE_EVAL 10000" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MAX_SIM_BB_EVAL: - // ---------------- - if ( display_all || NOMAD::string_find ( "MAX_SIM_BB_EVAL ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MAX_SGTE_EVAL (advanced)" ) << std::endl + << ". maximum number of surrogate evaluations" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". example: MAX_SGTE_EVAL 10000" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MAX_SIM_BB_EVAL: + // ---------------- + if ( display_all || NOMAD::string_find ( "MAX_SIM_BB_EVAL ADVANCED \ BLACK-BOXES BLACKBOXES BBEVAL \ MAXIMUM CACHE SIMULATED \ NUMBER EVALUATIONS STOPPING \ TERMINATES TERMINATION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MAX_SIM_BB_EVAL (advanced)" ) << std::endl - << ". maximum number of simulated blackbox evaluations" << std::endl - << ". argument: one positive integer" << std::endl - << ". no default" << std::endl - << ". the same as MAX_BB_EVAL except that it considers" << std::endl - << " initial cache hits (cache points that come from" << std::endl - << " a cache file)" << std::endl - << ". simulates the number of blackbox evaluations" << std::endl - << " when no cache file is used" << std::endl - << ". example: MAX_SIM_BB_EVAL 1000" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MESH_COARSENING_EXPONENT: - // ------------------------- - if ( display_all || NOMAD::string_find ( "MESH_COARSENING_EXPONENT ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MAX_SIM_BB_EVAL (advanced)" ) << std::endl + << ". maximum number of simulated blackbox evaluations" << std::endl + << ". argument: one positive integer" << std::endl + << ". no default" << std::endl + << ". the same as MAX_BB_EVAL except that it considers" << std::endl + << " initial cache hits (cache points that come from" << std::endl + << " a cache file)" << std::endl + << ". simulates the number of blackbox evaluations" << std::endl + << " when no cache file is used" << std::endl + << ". example: MAX_SIM_BB_EVAL 1000" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MESH_COARSENING_EXPONENT: + // ------------------------- + if ( display_all || NOMAD::string_find ( "MESH_COARSENING_EXPONENT ADVANCED \ MADS W+ \\DELTA" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MESH_COARSENING_EXPONENT (advanced)" ) << std::endl - << ". mesh coarsening exponent w^+ used to update the mesh" << std::endl - << " after successes (\\Delta^m_{k+1}=\\tau^{w^+}\\Delta^m_k)" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". default: 1" << std::endl - << ". example: MESH_COARSENING_EXPONENT 0 # the mesh size is" << std::endl - << " # not increased" << std::endl - << " # after successes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MESH_REFINING_EXPONENT: - // ----------------------- - if ( display_all || NOMAD::string_find ( "MESH_REFINING_EXPONENT ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MESH_COARSENING_EXPONENT (advanced)" ) << std::endl + << ". mesh coarsening exponent w^+ used to update the mesh" << std::endl + << " after successes (\\Delta^m_{k+1}=\\tau^{w^+}\\Delta^m_k)" << std::endl + << ". argument: one nonnegative integer" << std::endl + << ". default: 1" << std::endl + << ". example: MESH_COARSENING_EXPONENT 0 # the mesh size is" << std::endl + << " # not increased" << std::endl + << " # after successes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MESH_REFINING_EXPONENT: + // ----------------------- + if ( display_all || NOMAD::string_find ( "MESH_REFINING_EXPONENT ADVANCED \ MADS W- \\DELTA" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MESH_REFINING_EXPONENT (advanced)" ) << std::endl - << ". mesh refining exponent w^- used to update the mesh" << std::endl - << " after failures (\\Delta^m_{k+1} = \\tau^{w^-}\\Delta^m_k)" << std::endl - << ". argument: one negative" << std::endl - << ". default: -1" << std::endl - << ". example: MESH_REFINING_EXPONENT -2" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MESH_UPDATE_BASIS: - // ------------------ - if ( display_all || NOMAD::string_find ( "MESH_UPDATE_BASIS ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MESH_REFINING_EXPONENT (advanced)" ) << std::endl + << ". mesh refining exponent w^- used to update the mesh" << std::endl + << " after failures (\\Delta^m_{k+1} = \\tau^{w^-}\\Delta^m_k)" << std::endl + << ". argument: one negative" << std::endl + << ". default: -1" << std::endl + << ". example: MESH_REFINING_EXPONENT -2" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MESH_UPDATE_BASIS: + // ------------------ + if ( display_all || NOMAD::string_find ( "MESH_UPDATE_BASIS ADVANCED \ MADS \\TAU \\DELTA" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MESH_UPDATE_BASIS (advanced)" ) << std::endl - << ". mesh update basis \\tau used to update the" << std::endl - << " mesh (\\Delta^m_{k+1} = \\tau^w\\Delta^m_k)" << std::endl - << ". argument: one positive real" << std::endl - << ". default: 4.0" << std::endl - << ". example: MESH_UPDATE_BASIS 2.0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MIN_MESH_SIZE: - // -------------- - if ( display_all || NOMAD::string_find ( "MIN_MESH_SIZE ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MESH_UPDATE_BASIS (advanced)" ) << std::endl + << ". mesh update basis \\tau used to update the" << std::endl + << " mesh (\\Delta^m_{k+1} = \\tau^w\\Delta^m_k)" << std::endl + << ". argument: one positive real > 1" << std::endl + << ". default: 4.0" << std::endl + << ". example: MESH_UPDATE_BASIS 2.0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MIN_MESH_SIZE: + // -------------- + if ( display_all || NOMAD::string_find ( "MIN_MESH_SIZE ADVANCED \ \\DELTA MINIMUM TERMINATION \ STOPPING TERMINATES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MIN_MESH_SIZE (advanced)" ) << std::endl - << ". minimum mesh size" << std::endl - << ". arguments: same logic as INITIAL_MESH_SIZE" << std::endl - << " (\'r\' can be used)" << std::endl - << ". no default" << std::endl - << ". example: MIN_MESH_SIZE r1E-5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MIN_POLL_SIZE: - // -------------- - if ( display_all || NOMAD::string_find ( "MIN_POLL_SIZE MESH ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MIN_MESH_SIZE (advanced)" ) << std::endl + << ". minimum mesh size" << std::endl + << ". arguments: same logic as INITIAL_MESH_SIZE" << std::endl + << " (\'r\' can be used)" << std::endl + << ". no default" << std::endl + << ". example: MIN_MESH_SIZE r1E-5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MIN_POLL_SIZE: + // -------------- + if ( display_all || NOMAD::string_find ( "MIN_POLL_SIZE MESH ADVANCED \ \\DELTA^P MINIMUM TERMINATION \ STOPPING TERMINATES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MIN_POLL_SIZE (advanced)" ) << std::endl - << ". minimum poll size" << std::endl - << ". arguments: same logic as INITIAL_MESH_SIZE" << std::endl - << " (\'r\' can be used)" << std::endl - << ". default: 1.0 for integer or binary variables, no default otherwise" - << std::endl - << ". example: MIN_POLL_SIZE r1E-5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MODEL_EVAL_SORT: - // ---------------- - if ( display_all || NOMAD::string_find ( "MODEL_ORDERING MODEL_EVAL_SORT ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MIN_POLL_SIZE (advanced)" ) << std::endl + << ". minimum poll size" << std::endl + << ". arguments: same logic as INITIAL_MESH_SIZE" << std::endl + << " (\'r\' can be used)" << std::endl + << ". default: 1.0 for integer or binary variables, no default otherwise" + << std::endl + << ". example: MIN_POLL_SIZE r1E-5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MODEL_EVAL_SORT: + // ---------------- + if ( display_all || NOMAD::string_find ( "MODEL_ORDERING MODEL_EVAL_SORT ADVANCED \ MODELS INTERPOLATION REGRESSION \ MFN FROBENIUS QUADRATIC \ TGP" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_EVAL_SORT (advanced)" ) << std::endl - << ". if models are used to sort the trial points" << std::endl - << ". disabled for more than 50 variables" << std::endl - << ". disabled with categorical variables" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << " or one string in {\'QUADRATIC\', \'TGP\'}" << std::endl - << ". default: \'QUADRATIC\'" << std::endl - << ". examples: MODEL_EVAL_SORT quadratic" << std::endl - << " MODEL_EVAL_SORT yes # quadratic is used" << std::endl - << " MODEL_EVAL_SORT no # no MES" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MODEL_SEARCH: - // ------------- - if ( display_all || NOMAD::string_find ( "MODEL_SEARCH ADVANCED CATEGORICAL \ + _out << std::endl + << NOMAD::open_block ( "MODEL_EVAL_SORT (advanced)" ) << std::endl + << ". if models are used to sort the trial points" << std::endl + << ". disabled for more than 50 variables" << std::endl + << ". disabled with categorical variables" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << " or one string in {\'QUADRATIC\', \'TGP\'}" << std::endl + << ". default: \'QUADRATIC\'" << std::endl + << ". examples: MODEL_EVAL_SORT quadratic" << std::endl + << " MODEL_EVAL_SORT yes # quadratic is used" << std::endl + << " MODEL_EVAL_SORT no # no MES" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MODEL_SEARCH: + // ------------- + if ( display_all || NOMAD::string_find ( "MODEL_SEARCH ADVANCED CATEGORICAL \ MODELS INTERPOLATION REGRESSION \ MFN FROBENIUS QUADRATIC PARALLEL \ TGP" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_SEARCH (advanced)" ) << std::endl - << ". model search (MS)" << std::endl - << ". can be entered twice in order to define two searches" << std::endl - << ". disabled for more than 50 variables" << std::endl - << ". disabled with categorical variables" << std::endl - << ". disabled in parallel mode" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << " or one string in {\'QUADRATIC\', \'TGP\'}" << std::endl - << ". default: \'QUADRATIC\'" << std::endl - << ". example: MODEL_SEARCH QUADRATIC" << std::endl - << " MODEL_SEARCH TGP" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // MODEL_SEARCH_OPTIMISTIC: - // ------------------------ - if ( display_all || NOMAD::string_find ( "MODEL_SEARCH_OPTIMISTIC ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MODEL_SEARCH (advanced)" ) << std::endl + << ". model search (MS)" << std::endl + << ". can be entered twice in order to define two searches" << std::endl + << ". disabled for more than 50 variables" << std::endl + << ". disabled with categorical variables" << std::endl + << ". disabled in parallel mode" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << " or one string in {\'QUADRATIC\', \'TGP\'}" << std::endl + << ". default: \'QUADRATIC\'" << std::endl + << ". example: MODEL_SEARCH QUADRATIC" << std::endl + << " MODEL_SEARCH TGP" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // MODEL_SEARCH_OPTIMISTIC: + // ------------------------ + if ( display_all || NOMAD::string_find ( "MODEL_SEARCH_OPTIMISTIC ADVANCED \ MODELS INTERPOLATION REGRESSION \ MFN FROBENIUS QUADRATIC \ TGP" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_SEARCH_OPTIMISTIC (advanced)" ) << std::endl - << ". model search (MS) is optimistic or not" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: MODEL_SEARCH_OPTIMISTIC no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MULTI_F_BOUNDS: - // --------------- - if ( display_all || NOMAD::string_find ( "MULTI_F_BOUNDS ADVANCED PARETO \ + _out << std::endl + << NOMAD::open_block ( "MODEL_SEARCH_OPTIMISTIC (advanced)" ) << std::endl + << ". model search (MS) is optimistic or not" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: MODEL_SEARCH_OPTIMISTIC no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MULTI_F_BOUNDS: + // --------------- + if ( display_all || NOMAD::string_find ( "MULTI_F_BOUNDS ADVANCED PARETO \ BI-OBJECTIVES MULTI-OBJECTIVES \ BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS SURF" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MULTI_F_BOUNDS (advanced)" ) << std::endl - << ". multi-objective optimization: bounds on the two" << std::endl - << " objective functions" << std::endl - << ". arguments: 4 reals: f1_min f1_max f2_min f2_max" << std::endl - << ". default: none" << std::endl - << ". these values are used to display the \'surf\' statistics" << std::endl - << " on Pareto fronts (useful to compare different Pareto" << std::endl - << " fronts)" << std::endl - << ". \'surf\' will not be displayed with invalid values (for example" - << std::endl - << " if a dominant point has a f2 value greater than f2_max)" << std::endl - << ". example: MULTI_F_BOUNDS 0 10 0 10" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MULTI_NB_MADS_RUNS: - // ------------------- - if ( display_all || NOMAD::string_find ( "MULTI_NB_MADS_RUNS ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "MULTI_F_BOUNDS (advanced)" ) << std::endl + << ". multi-objective optimization: bounds on the two" << std::endl + << " objective functions" << std::endl + << ". arguments: 4 reals: f1_min f1_max f2_min f2_max" << std::endl + << ". default: none" << std::endl + << ". these values are used to display the \'surf\' statistics" << std::endl + << " on Pareto fronts (useful to compare different Pareto" << std::endl + << " fronts)" << std::endl + << ". \'surf\' will not be displayed with invalid values (for example" + << std::endl + << " if a dominant point has a f2 value greater than f2_max)" << std::endl + << ". example: MULTI_F_BOUNDS 0 10 0 10" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MULTI_NB_MADS_RUNS: + // ------------------- + if ( display_all || NOMAD::string_find ( "MULTI_NB_MADS_RUNS ADVANCED \ BI-OBJECTIVES MULTI-OBJECTIVES \ BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS \ NUMBER" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MULTI_NB_MADS_RUNS (advanced)" ) << std::endl - << ". multi-objective optimization:" << std::endl - << " number of MADS runs" << std::endl - << ". argument: one positive integer" << std::endl - << ". default: see user guide" << std::endl - << ". example: MULTI_NB_MADS_RUNS 30" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MULTI_OVERALL_BB_EVAL: - // --------------------- - if ( display_all || NOMAD::string_find ( "MULTI_OVERALL_BB_EVAL ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "MULTI_NB_MADS_RUNS (advanced)" ) << std::endl + << ". multi-objective optimization:" << std::endl + << " number of MADS runs" << std::endl + << ". argument: one positive integer" << std::endl + << ". default: see user guide" << std::endl + << ". example: MULTI_NB_MADS_RUNS 30" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MULTI_OVERALL_BB_EVAL: + // --------------------- + if ( display_all || NOMAD::string_find ( "MULTI_OVERALL_BB_EVAL ADVANCED \ BI-OBJECTIVES MULTI-OBJECTIVES \ BIOBJECTIVES MULTIOBJECTIVES \ BI-MADS BIMADS \ NUMBER BLACK-BOXES BLACKBOXES BBEVAL \ EVALUATIONS TERMINATION \ STOPPING TERMINATES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "MULTI_OVERALL_BB_EVAL (advanced)" ) << std::endl - << ". multi-objective optimization: maximum" << std::endl - << " number of blackbox evaluations" << std::endl - << ". argument: one positive integer" << std::endl - << ". default: see user guide" << std::endl - << ". example: MULTI_OVERALL_BB_EVAL 1000" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // NEIGHBORS_EXE: - // -------------- - if ( display_all || NOMAD::string_find ( "NEIGHBORS_EXE NEIGHBOURS \ + _out << std::endl + << NOMAD::open_block ( "MULTI_OVERALL_BB_EVAL (advanced)" ) << std::endl + << ". multi-objective optimization: maximum" << std::endl + << " number of blackbox evaluations" << std::endl + << ". argument: one positive integer" << std::endl + << ". default: see user guide" << std::endl + << ". example: MULTI_OVERALL_BB_EVAL 1000" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // NEIGHBORS_EXE: + // -------------- + if ( display_all || NOMAD::string_find ( "NEIGHBORS_EXE NEIGHBOURS \ NEIGHBORHOODS NEIGHBOURHOODS \ EXTENDED_POLL \ MIXED MVP CATEGORICAL \ ADVANCED" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "NEIGHBORS_EXE (advanced)" ) << std::endl - << ". to indicate a neighborhood executable for categorical" << std::endl - << " variables in batch mode" << std::endl - << ". arguments: one string" << std::endl - << ". no default" << std::endl - << ". the executable must take a file with the coordinates of" << std::endl - << " a point as argument and displays a list of neighbors" << std::endl - << ". the number of variables must be the same" << std::endl - << ". when the \'$\' character is put in first position of a" << std::endl - << " string, it is considered as global and no path is added" << std::endl - << ". see user guide for details" << std::endl - << ". example: NEIGHBORS_EXE neighbors.exe" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPEN_BRACE: - // ----------- - if ( display_all || NOMAD::string_find ( "OPEN_BRACES INDENTATION TABULATIONS \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "NEIGHBORS_EXE (advanced)" ) << std::endl + << ". to indicate a neighborhood executable for categorical" << std::endl + << " variables in batch mode" << std::endl + << ". arguments: one string" << std::endl + << ". no default" << std::endl + << ". the executable must take a file with the coordinates of" << std::endl + << " a point as argument and displays a list of neighbors" << std::endl + << ". the number of variables must be the same" << std::endl + << ". when the \'$\' character is put in first position of a" << std::endl + << " string, it is considered as global and no path is added" << std::endl + << ". see user guide for details" << std::endl + << ". example: NEIGHBORS_EXE neighbors.exe" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPEN_BRACE: + // ----------- + if ( display_all || NOMAD::string_find ( "OPEN_BRACES INDENTATION TABULATIONS \ BLOCKS ADVANCED DISPLAY" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "OPEN_BRACE (advanced)" ) << std::endl - << ". string displayed at the beginning of indented" << std::endl - << " blocks in full display mode" << std::endl - << ". argument: one string" << std::endl - << ". default: \'{\'" << std::endl - << ". example: OPEN_BRACE Begin" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPPORTUNISTIC_CACHE_SEARCH: - // --------------------------- - if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_CACHE_SEARCH ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "OPEN_BRACE (advanced)" ) << std::endl + << ". string displayed at the beginning of indented" << std::endl + << " blocks in full display mode" << std::endl + << ". argument: one string" << std::endl + << ". default: \'{\'" << std::endl + << ". example: OPEN_BRACE Begin" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPPORTUNISTIC_CACHE_SEARCH: + // --------------------------- + if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_CACHE_SEARCH ADVANCED \ BLACK-BOXES BLACKBOXES EVALUATIONS \ SUCCESSES CACHE SEARCH" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_CACHE_SEARCH (advanced)" ) << std::endl - << ". opportunistic strategy for cache search" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: OPPORTUNISTIC_CACHE_SEARCH yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPPORTUNISTIC_EVAL: - // ------------------- - if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_EVAL ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_CACHE_SEARCH (advanced)" ) << std::endl + << ". opportunistic strategy for cache search" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: OPPORTUNISTIC_CACHE_SEARCH yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPPORTUNISTIC_EVAL: + // ------------------- + if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_EVAL ADVANCED \ BLACK-BOXES BLACKBOXES EVALUATIONS \ SUCCESSES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_EVAL (advanced)" ) << std::endl - << ". opportunistic strategy (terminate a list of" << std::endl - << " evaluations after successes)" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". type \'nomad -h opportunistic\' to see advanced options" << std::endl - << ". example: OPPORTUNISTIC_EVAL no # complete evaluations" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // OPPORTUNISTIC_LH: - // ----------------- - if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_LH ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_EVAL (advanced)" ) << std::endl + << ". opportunistic strategy (terminate a list of" << std::endl + << " evaluations after successes)" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". type \'nomad -h opportunistic\' to see advanced options" << std::endl + << ". example: OPPORTUNISTIC_EVAL no # complete evaluations" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // OPPORTUNISTIC_LH: + // ----------------- + if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_LH ADVANCED \ BLACK-BOXES BLACKBOXES EVALUATIONS \ SUCCESSES LATIN-HYPERCUBE SEARCH" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_LH (advanced)" ) << std::endl - << ". opportunistic strategy for Latin-Hypercube search" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: same value as OPPORTUNISTIC_EVAL" << std::endl - << ". example: OPPORTUNISTIC_LH no # complete evaluations" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // OPPORTUNISTIC_MIN_EVAL: - // ----------------------- - if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_EVAL ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_LH (advanced)" ) << std::endl + << ". opportunistic strategy for Latin-Hypercube search" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: same value as OPPORTUNISTIC_EVAL" << std::endl + << ". example: OPPORTUNISTIC_LH no # complete evaluations" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // OPPORTUNISTIC_MIN_EVAL: + // ----------------------- + if ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_EVAL ADVANCED \ BLACK-BOXES BLACKBOXES EVALUATIONS \ SUCCESSES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_MIN_EVAL (advanced)" ) << std::endl - << ". advanced parameter for the opportunistic" << std::endl - << " strategy (see user guide)" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". no default" << std::endl - << ". example: OPPORTUNISTIC_MIN_EVAL 3" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // PERIODIC_VARIABLE: - // ------------------ - if ( display_all || NOMAD::string_find ( "PERIODIC_VARIABLE VARIABLES ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_MIN_EVAL (advanced)" ) << std::endl + << ". advanced parameter for the opportunistic" << std::endl + << " strategy (see user guide)" << std::endl + << ". argument: one nonnegative integer" << std::endl + << ". no default" << std::endl + << ". example: OPPORTUNISTIC_MIN_EVAL 3" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // PERIODIC_VARIABLE: + // ------------------ + if ( display_all || NOMAD::string_find ( "PERIODIC_VARIABLE VARIABLES ADVANCED \ BOUNDS LB UB CYCLIC MADS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "PERIODIC_VARIABLE (advanced)" ) << std::endl - << ". specify that some variables are periodic" << std::endl - << ". arguments: variable indexes" << std::endl - << ". no default" << std::endl - << ". bounds must be defined for these variables" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "PERIODIC_VARIABLE * # all variables are periodic" << std::endl - << "PERIODIC_VARIABLE 0-1 # 2 first var. are periodic" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // POINT_DISPLAY_LIMIT: - // -------------------- - if ( display_all || NOMAD::string_find ( "POINT_DISPLAY_LIMIT OUTPUTS \ + _out << std::endl + << NOMAD::open_block ( "PERIODIC_VARIABLE (advanced)" ) << std::endl + << ". specify that some variables are periodic" << std::endl + << ". arguments: variable indexes" << std::endl + << ". no default" << std::endl + << ". bounds must be defined for these variables" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "PERIODIC_VARIABLE * # all variables are periodic" << std::endl + << "PERIODIC_VARIABLE 0-1 # 2 first var. are periodic" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // POINT_DISPLAY_LIMIT: + // -------------------- + if ( display_all || NOMAD::string_find ( "POINT_DISPLAY_LIMIT OUTPUTS \ ADVANCED PRECISION" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "POINT_DISPLAY_LIMIT (advanced)" ) << std::endl - << ". maximum number of point coordinates" << std::endl - << " that are displayed" << std::endl - << ". argument: one positive integer" << std::endl - << ". default: 20" << std::endl - << ". example: POINT_DISPLAY_LIMIT 10" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // RHO: - // ---- - if ( display_all || NOMAD::string_find ( "RHO ADVANCED MADS CONSTRAINTS \ + _out << std::endl + << NOMAD::open_block ( "POINT_DISPLAY_LIMIT (advanced)" ) << std::endl + << ". maximum number of point coordinates" << std::endl + << " that are displayed" << std::endl + << ". argument: one positive integer" << std::endl + << ". default: 20" << std::endl + << ". example: POINT_DISPLAY_LIMIT 10" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // POLL_UPDATE_BASIS: + // ------------------ + if ( display_all || NOMAD::string_find ( "POLL_UPDATE_BASIS ADVANCED \ + MADS ANISOTROPIC MESH \\TAU \\DELTA" , param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "POLL_UPDATE_BASIS (advanced)" ) << std::endl + << ". poll update basis \\tau used to update the" << std::endl + << " poll (\\Delta^{k+1} = \\tau^w\\Delta^k)" << std::endl + << ". argument: one positive real > 1" << std::endl + << ". default: 2.0" << std::endl + << ". example: POLL_UPDATE_BASIS 1.5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // RHO: + // ---- + if ( display_all || NOMAD::string_find ( "RHO ADVANCED MADS CONSTRAINTS \ PROGRESSIVE-BARRIER PB PEB \ FILTER TRIGGER" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "RHO (advanced)" ) << std::endl - << ". rho parameter of the progressive barrier" << std::endl - << ". argument: one nonnegative real" << std::endl - << ". default: 0.1" << std::endl - << ". example: RHO 0.5" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // SCALING: - // -------- - if ( display_all || NOMAD::string_find ( "SCALING SCALE ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "RHO (advanced)" ) << std::endl + << ". rho parameter of the progressive barrier" << std::endl + << ". argument: one nonnegative real" << std::endl + << ". default: 0.1" << std::endl + << ". example: RHO 0.5" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // SCALING: + // -------- + if ( display_all || NOMAD::string_find ( "SCALING SCALE ADVANCED \ FILES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SCALING (advanced)" ) << std::endl - << ". variable scaling" << std::endl - << ". arguments: variable indexes and values" << std::endl - << ". no default" << std::endl - << ". variables are multiplied by these values: they are scaled" << std::endl - << " before an evaluation and the call to Evaluator::eval_x()," << std::endl - << " and unscaled after the evaluation" << std::endl - << ". all NOMAD outputs (including files) display unscaled values" << std::endl - << ". all variable-related parameters (bounds, starting points," << std::endl - << " fixed variables) must be specified without scaling" << std::endl - << ". can be given by a text file containing DIMENSION entries" << std::endl - << " (use \'-\' for unscaled variables)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "SCALING ( 0.1 - 100 ) # variables 0 and 2 are scaled" << std::endl - << "SCALING scaling.txt # with a file" << std::endl - << "SCALING 0-1 10.0 # 2 first variables scaled" << std::endl - << " # by factor 10" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - - // SEED: - // ----- - if ( display_all || NOMAD::string_find ( "SEED ADVANCED \ - RANDOM FILES LT-MADS LTMADS \ + _out << std::endl + << NOMAD::open_block ( "SCALING (advanced)" ) << std::endl + << ". variable scaling" << std::endl + << ". arguments: variable indexes and values" << std::endl + << ". no default" << std::endl + << ". variables are multiplied by these values: they are scaled" << std::endl + << " before an evaluation and the call to Evaluator::eval_x()," << std::endl + << " and unscaled after the evaluation" << std::endl + << ". all NOMAD outputs (including files) display unscaled values" << std::endl + << ". all variable-related parameters (bounds, starting points," << std::endl + << " fixed variables) must be specified without scaling" << std::endl + << ". can be given by a text file containing DIMENSION entries" << std::endl + << " (use \'-\' for unscaled variables)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "SCALING ( 0.1 - 100 ) # variables 0 and 2 are scaled" << std::endl + << "SCALING scaling.txt # with a file" << std::endl + << "SCALING 0-1 10.0 # 2 first variables scaled" << std::endl + << " # by factor 10" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + + // SEED: + // ----- + if ( display_all || NOMAD::string_find ( "SEED ADVANCED \ + RANDOM FILES ORTHOMADS LT-MADS LTMADS \ LATIN-HYPERCUBE LH TGP \ SAMPLING SEARCH" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SEED (advanced)" ) << std::endl - << ". random seed" << std::endl - << ". argument: one integer or the string \'NONE\'" << std::endl - << ". default: \'NONE\'" << std::endl - << ". the random seed is different at each run if" << std::endl - << " \'NONE\' or a negative integer is entered" << std::endl - << ". the seed is used in the output file names" << std::endl - << ". randomness is used for LT-MADS directions," << std::endl - << " Latin-Hypercube search, and TGP search." << std::endl - << ". example: SEED 100" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // SGTE_CACHE_FILE: - // ---------------- - if ( display_all || NOMAD::string_find ( "SGTE_CACHE_FILE ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "SEED (advanced)" ) << std::endl + << ". random seed" << std::endl + << ". argument: one integer in [0," << UINT32_MAX << "] U {-1} or the string \'DIFF\'" << std::endl + << ". default: \'" << NOMAD::RNG::get_seed() << "\'" << std::endl + << ". the default value is used for each run if" << std::endl + << " the parameter is not provided. " << std::endl + << ". if '-1' or \'DIFF\' is entered " << std::endl + << " the seed is different for each run (PID is used)." << std::endl + << ". the seed is used in the output file names" << std::endl + << ". the seed affects the randomness of " << std::endl + << " Ortho-MADS and LT-MADS directions," << std::endl + << " Latin-Hypercube search, and TGP search." << std::endl + << ". example: SEED 123456" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // SGTE_CACHE_FILE: + // ---------------- + if ( display_all || NOMAD::string_find ( "SGTE_CACHE_FILE ADVANCED \ SURROGATES SGTES \ FILES OUTPUTS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SGTE_CACHE_FILE (advanced)" ) << std::endl - << ". surrogate cache file; cannot be the same" << std::endl - << " as CACHE_FILE" << std::endl - << ". argument: one string" << std::endl - << ". no default" << std::endl - << ". points already in the file will be tagged" << std::endl - << " as surrogate evaluations" << std::endl - << ". example: SGTE_CACHE_FILE sgte_cache.bin" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // SGTE_COST: - // ---------- - if ( display_all || NOMAD::string_find ( "SGTE_COST SURROGATES SGTES ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "SGTE_CACHE_FILE (advanced)" ) << std::endl + << ". surrogate cache file; cannot be the same" << std::endl + << " as CACHE_FILE" << std::endl + << ". argument: one string" << std::endl + << ". no default" << std::endl + << ". points already in the file will be tagged" << std::endl + << " as surrogate evaluations" << std::endl + << ". example: SGTE_CACHE_FILE sgte_cache.bin" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // SGTE_COST: + // ---------- + if ( display_all || NOMAD::string_find ( "SGTE_COST SURROGATES SGTES ADVANCED \ BLACK-BOXES BLACKBOXES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SGTE_COST (advanced)" ) << std::endl - << ". cost of the surrogate function relatively" << std::endl - << " to the true function" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". default: infinity (no surrogate cost)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "SGTE_COST 3 # three surrogate evaluations" << std::endl - << " # count as one blackbox" << std::endl - << " # evaluation (the surrogate" << std::endl - << " # is three times faster)" << std::endl - << "SGTE_COST -1 # set to infinity" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // SGTE_EVAL_SORT: - // --------------- - if ( display_all || NOMAD::string_find ( "SGTE_EVAL_SORT ADVANCED SURROGATES \ + _out << std::endl + << NOMAD::open_block ( "SGTE_COST (advanced)" ) << std::endl + << ". cost of the surrogate function relatively" << std::endl + << " to the true function" << std::endl + << ". argument: one nonnegative integer" << std::endl + << ". default: infinity (no surrogate cost)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "SGTE_COST 3 # three surrogate evaluations" << std::endl + << " # count as one blackbox" << std::endl + << " # evaluation (the surrogate" << std::endl + << " # is three times faster)" << std::endl + << "SGTE_COST -1 # set to infinity" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // SGTE_EVAL_SORT: + // --------------- + if ( display_all || NOMAD::string_find ( "SGTE_EVAL_SORT ADVANCED SURROGATES \ SGTE_ORDERING SGTES BLACK-BOXES \ BLACKBOXES" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SGTE_EVAL_SORT (advanced)" ) << std::endl - << ". if surrogate is used to sort the trial points" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: SGTE_EVAL_SORT NO" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // SGTE_EXE: - // ---------- - if ( display_all || NOMAD::string_find ( "SGTE_EXE HAS_SGTE ADVANCED SURROGATES \ + _out << std::endl + << NOMAD::open_block ( "SGTE_EVAL_SORT (advanced)" ) << std::endl + << ". if surrogate is used to sort the trial points" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: SGTE_EVAL_SORT NO" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // SGTE_EXE: + // ---------- + if ( display_all || NOMAD::string_find ( "SGTE_EXE HAS_SGTE ADVANCED SURROGATES \ SGTES BLACK-BOXES BLACKBOXES \ FILES EXECUTABLE" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SGTE_EXE (advanced)" ) << std::endl - << ". to indicate a surrogate executable" << std::endl - << ". arguments: one or two strings" << std::endl - << ". no default" << std::endl - << ". surrogate(s) and blackbox(es) must have the same" << std::endl - << " number of outputs" << std::endl - << ". if surrogates are used, every blackbox executable" << std::endl - << " must have a surrogate" - << std::endl - << ". automatically sets HAS_SGTE to \'yes\'" << std::endl - << ". " << NOMAD::open_block ( "examples" ) << std::endl - << "SGTE_EXE b1.exe s1.exe # \'s1.exe\' is a surrogate" << std::endl - << " # for \'b1.exe\'" << std::endl << std::endl - << "SGTE_EXE sgte.exe # only if one blackbox" << std::endl - << " # executable is used" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // SNAP_TO_BOUNDS: - // --------------- - if ( display_all || NOMAD::string_find ( "SNAP_TO_BOUNDS PROJECTION \ + _out << std::endl + << NOMAD::open_block ( "SGTE_EXE (advanced)" ) << std::endl + << ". to indicate a surrogate executable" << std::endl + << ". arguments: one or two strings" << std::endl + << ". no default" << std::endl + << ". surrogate(s) and blackbox(es) must have the same" << std::endl + << " number of outputs" << std::endl + << ". if surrogates are used, every blackbox executable" << std::endl + << " must have a surrogate" + << std::endl + << ". automatically sets HAS_SGTE to \'yes\'" << std::endl + << ". " << NOMAD::open_block ( "examples" ) << std::endl + << "SGTE_EXE b1.exe s1.exe # \'s1.exe\' is a surrogate" << std::endl + << " # for \'b1.exe\'" << std::endl << std::endl + << "SGTE_EXE sgte.exe # only if one blackbox" << std::endl + << " # executable is used" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // SNAP_TO_BOUNDS: + // --------------- + if ( display_all || NOMAD::string_find ( "SNAP_TO_BOUNDS PROJECTION \ ADVANCED" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SNAP_TO_BOUNDS (advanced)" ) << std::endl - << ". if \'yes\', snap to bounds points generated" << std::endl - << " outside boundaries" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: SNAP_TO_BOUNDS no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // SPECULATIVE_SEARCH: - // ------------------- - if ( display_all || NOMAD::string_find ( "SPECULATIVE_SEARCH MADS OPTIMISTIC \ + _out << std::endl + << NOMAD::open_block ( "SNAP_TO_BOUNDS (advanced)" ) << std::endl + << ". if \'yes\', snap to bounds points generated" << std::endl + << " outside boundaries" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: SNAP_TO_BOUNDS no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // SPECULATIVE_SEARCH: + // ------------------- + if ( display_all || NOMAD::string_find ( "SPECULATIVE_SEARCH MADS OPTIMISTIC \ ADVANCED" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "SPECULATIVE_SEARCH (advanced)" ) << std::endl - << ". MADS speculative_search (optimistic strategy)" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: SPECULATIVE_SEARCH no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // STAT_SUM_TARGET: - // ---------------- - if ( display_all || NOMAD::string_find ( "STAT_SUM_TARGET ADVANCED TERMINATION \ + _out << std::endl + << NOMAD::open_block ( "SPECULATIVE_SEARCH (advanced)" ) << std::endl + << ". MADS speculative_search (optimistic strategy)" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: SPECULATIVE_SEARCH no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // STAT_SUM_TARGET: + // ---------------- + if ( display_all || NOMAD::string_find ( "STAT_SUM_TARGET ADVANCED TERMINATION \ STOPPING TERMINATES STATS" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "STAT_SUM_TARGET (advanced)" ) << std::endl - << ". MADS terminates if STAT_SUM reaches the value of this" << std::endl - << " parameter (STAT_SUM is one of the possible outputs" << std::endl - << " defined in BB_OUTPUT_TYPE)" << std::endl - << ". argument: one real" << std::endl - << ". no default" << std::endl - << ". example: STAT_SUM_TARGET 100.0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // STOP_IF_FEASIBLE: - // ----------------- - if ( display_all || NOMAD::string_find ( "STOP_IF_FEASIBLE ADVANCED \ + _out << std::endl + << NOMAD::open_block ( "STAT_SUM_TARGET (advanced)" ) << std::endl + << ". MADS terminates if STAT_SUM reaches the value of this" << std::endl + << " parameter (STAT_SUM is one of the possible outputs" << std::endl + << " defined in BB_OUTPUT_TYPE)" << std::endl + << ". argument: one real" << std::endl + << ". no default" << std::endl + << ". example: STAT_SUM_TARGET 100.0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // STOP_IF_FEASIBLE: + // ----------------- + if ( display_all || NOMAD::string_find ( "STOP_IF_FEASIBLE ADVANCED \ TERMINATES TERMINATION STOPPING" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "STOP_IF_FEASIBLE (advanced)" ) << std::endl - << ". the algorithm terminates if it generates" << std::endl - << " a feasible solution" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: STOP_IF_FEASIBLE yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // UNDEF_STR: - // ---------- - if ( display_all || NOMAD::string_find ( "UNDEF_STR ADVANCED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "STOP_IF_FEASIBLE (advanced)" ) << std::endl + << ". the algorithm terminates if it generates" << std::endl + << " a feasible solution" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: STOP_IF_FEASIBLE yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // UNDEF_STR: + // ---------- + if ( display_all || NOMAD::string_find ( "UNDEF_STR ADVANCED \ UNDEFINED DISPLAY REALS" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "UNDEF_STR (advanced)" ) << std::endl - << ". string used to display undefined real values" << std::endl - << ". argument: one string" << std::endl - << ". default: \"-\"" << std::endl - << ". example: UNDEF_STR Undefined" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // USER_CALLS_ENABLED: - // ------------------- - if ( display_all || NOMAD::string_find ( "USER_CALLS_ENABLED USER_CALLS_DISABLED \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "UNDEF_STR (advanced)" ) << std::endl + << ". string used to display undefined real values" << std::endl + << ". argument: one string" << std::endl + << ". default: \"-\"" << std::endl + << ". example: UNDEF_STR Undefined" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // USER_CALLS_ENABLED: + // ------------------- + if ( display_all || NOMAD::string_find ( "USER_CALLS_ENABLED USER_CALLS_DISABLED \ ADVANCED LIBRARY" , - param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "USER_CALLS_ENABLED (advanced)" ) << std::endl - << ". if \'no\', the automatic calls to user" << std::endl - << " functions are disabled" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: USER_CALLS_ENABLED yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // VARIABLE_GROUP: - // -------------- - if ( display_all || NOMAD::string_find ( "VARIABLE_GROUP GROUPS PSD-MADS PSDMADS \ + param_names ) ) { + _out << std::endl + << NOMAD::open_block ( "USER_CALLS_ENABLED (advanced)" ) << std::endl + << ". if \'no\', the automatic calls to user" << std::endl + << " functions are disabled" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: USER_CALLS_ENABLED yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // VARIABLE_GROUP: + // -------------- + if ( display_all || NOMAD::string_find ( "VARIABLE_GROUP GROUPS PSD-MADS PSDMADS \ VARIABLES ADVANCED" , param_names ) ) { - _out << std::endl - << NOMAD::open_block ( "VARIABLE_GROUP (advanced)" ) << std::endl - << ". defines groups of variables" << std::endl - << ". MADS directions are applied separately for" << std::endl - << " each group" << std::endl - << ". also used by PSD-MADS (not yet implemented)" << std::endl - << ". groups cannot include fixed variables" << std::endl - << ". arguments: variable indexes" << std::endl - << ". default groups are created for different types" << std::endl - << " of variables" << std::endl - << ". no other default" << std::endl - << ". advanced options only available in library mode" << std::endl - << " (see user guide)" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "VARIABLE_GROUP 2-5" << std::endl - << "VARIABLE_GROUP 0 1 3" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - - // VNS_SEARCH: - // ----------- - if ( display_all || NOMAD::string_find ( "VNS_SEARCH NEIGHBORHOOD \ + _out << std::endl + << NOMAD::open_block ( "VARIABLE_GROUP (advanced)" ) << std::endl + << ". defines groups of variables" << std::endl + << ". MADS directions are applied separately for" << std::endl + << " each group" << std::endl + << ". also used by PSD-MADS (not yet implemented)" << std::endl + << ". groups cannot include fixed variables" << std::endl + << ". arguments: variable indexes" << std::endl + << ". default groups are created for different types" << std::endl + << " of variables" << std::endl + << ". no other default" << std::endl + << ". advanced options only available in library mode" << std::endl + << " (see user guide)" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "VARIABLE_GROUP 2-5" << std::endl + << "VARIABLE_GROUP 0 1 3" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + + // VNS_SEARCH: + // ----------- + if ( display_all || NOMAD::string_find ( "VNS_SEARCH NEIGHBORHOOD \ METAHEURISTICS META-HEURISTICS \ GLOBAL ADVANCED \ TRIGGER" , - param_names ) ) { - - if ( !NOMAD::string_find ( "RHO" , param_names ) ) { - - _out << std::endl - << NOMAD::open_block ( "VNS_SEARCH (advanced)" ) << std::endl - << ". Variable Neighborhood Search (VNS) search" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << " or one real in [0;1] for the VNS trigger" << std::endl - << ". default: \'no\' (same as 0.0)" << std::endl - << ". the VNS trigger is the maximum desired ratio of" << std::endl - << " VNS blackbox evaluations over the total number" << std::endl - << " of blackbox evaluations" << std::endl - << ". the VNS search is never executed with a null trigger" << std::endl - << " while a value of 1 allows the search at every" << std::endl - << " iteration" << std::endl - << ". if VNS_SEARCH=\'yes\', the default value of 0.75 is" << std::endl - << " taken for the trigger" << std::endl - << ". VNS search uses the surrogate if HAS_SGTE or" << std::endl - << " SGTE_EXE is defined" << std::endl - << ". " << NOMAD::open_block ( "examples" ) - << "VNS_SEARCH yes # VNS trigger of 75%" << std::endl - << "VNS_SEARCH 0.5 # VNS trigger of 50%" << std::endl - << NOMAD::close_block() << NOMAD::close_block(); - chk = true; - } - } - - - - // last display: - if ( !chk && !developer) { - - std::string pname = ( pnames.size() == 1 ) ? - ("\'" + *pnames.begin() + "\'") : - "the specified list of parameter names"; - - _out << std::endl << "no help available for " << pname << std::endl - << "help example: \'nomad -h mesh\' displays help on the mesh parameters" - << std::endl; - } - - if (developer && NOMAD::string_find(registered_key_developer,param_names)) - { - _out << "--------------------------------------------------------------" << endl; - _out << "---------------------DEVELOPER PARAMETERS---------------------" << endl; - _out << "--------------------------------------------------------------" << endl; - } - - // EPSILON: - // -------- - if ( developer && (display_all || NOMAD::string_find ( "EPSILON DEVELOPPER \ - PRECISION REALS COMPARISONS" , - param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "EPSILON (developer)" ) << std::endl - << ". precision on reals" << std::endl - << ". argument: one positive real" << std::endl - << ". default: 1E-13" << std::endl - << ". example: EPSILON 1E-8" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // L_CURVE_TARGET: - // --------------- - if ( developer && ( display_all || NOMAD::string_find ( "L_CURVE_TARGET DEVELOPER TERMINATION \ - STOPPING TERMINATES" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "L_CURVE_TARGET (developer)" ) << std::endl - << ". MADS terminates if it detects that the objective will" << std::endl - << " not reach this value (based on an approximation" << std::endl - << " of the L-shaped curve obj_value v.s. bb_eval)" << std::endl - << ". argument: one real" << std::endl - << ". no default" << std::endl - << ". example: L_CURVE_TARGET 10.0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MODEL_EVAL_SORT_CAUTIOUS: - // ------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_ORDERING MODEL_EVAL_SORT_CAUTIOUS \ - MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS DEVELOPER \ - QUADRATIC TGP" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_EVAL_SORT_CAUTIOUS (developer)" ) << std::endl - << ". if the model ordering strategy is cautious, meaning" << std::endl - << " that models are evaluated only within a trust radius" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: MODEL_EVAL_SORT_CAUTIOUS no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_QUAD_MAX_Y_SIZE: - // ---------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_MAX_Y_SIZE MODEL_SEARCH DEVELOPER \ - MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_QUAD_MAX_Y_SIZE (developer)" ) << std::endl - << ". Sup. limit on the size of interp. set Y for quadr. models" << std::endl - << ". arguments: one integer greater than the number of variables" << std::endl - << ". default: 500" << std::endl - << ". example: MODEL_QUAD_MAX_Y_SIZE 10" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_QUAD_MIN_Y_SIZE: - // ---------------------- - if ( developer && (display_all || NOMAD::string_find ( "MODEL_QUAD_MIN_Y_SIZE MODEL_SEARCH DEVELOPER \ - MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_QUAD_MIN_Y_SIZE (developer)" ) << std::endl - << ". Inf. limit on the size of interp. set Y for quadr. models" << std::endl - << ". arguments: one integer > 1 or the string \'N+1\'" << std::endl - << ". default: N+1" << std::endl - << ". examples: MODEL_QUAD_MIN_Y_SIZE N+1" << std::endl - << " MODEL_QUAD_MIN_Y_SIZE -1 # same as N+1" << std::endl - << " MODEL_QUAD_MIN_Y_SIZE 2" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_QUAD_RADIUS_FACTOR: - // ------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_RADIUS_FACTOR MODEL_SEARCH \ - DEVELOPER MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_QUAD_RADIUS_FACTOR (developer)" ) << std::endl - << ". quadratic model search radius factor (see user guide)" << std::endl - << ". arguments: one strictly positive real" << std::endl - << ". default: 2.0" << std::endl - << ". example: MODEL_QUAD_RADIUS_FACTOR 1.0" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_SEARCH_MAX_TRIAL_PTS: - // --------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_SEARCH_MAX_TRIAL_PTS \ - DEVELOPER MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC \ - TGP" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_SEARCH_MAX_TRIAL_PTS (developer)" ) << std::endl - << ". limit on the number of trial points for one model search" << std::endl - << ". arguments: one integer greater than or equal to 1" << std::endl - << ". the quadratic model search will not generate more than 4 points" << std::endl - << ". default: 10" << std::endl - << ". example: MODEL_SEARCH_MAX_TRIAL_PTS 1" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_SEARCH_PROJ_TO_MESH: - // -------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_SEARCH_PROJ_TO_MESH DEVELOPER \ - MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC PROJECTION \ - TGP" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_SEARCH_PROJ_TO_MESH (developer)" ) << std::endl - << ". if model search trial points are projected to the mesh" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: MODEL_SEARCH_PROJ_TO_MESH no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_QUAD_USE_WP: - // ------------------ - if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_USE_WP DEVELOPER \ - WELL-POISEDNESS \ - MODELS INTERPOLATION REGRESSION \ - MFN FROBENIUS QUADRATIC" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "MODEL_QUAD_USE_WP (developer)" ) << std::endl - << ". enable the strategy to maintain WP with quadr. models" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: MODEL_QUAD_USE_WP yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MODEL_NP1_QUAD_EPSILON : - // --------------- - if ( developer && (display_all || NOMAD::string_find ( "MODEL MODELS NP1 QUAD EPSILON \ - ORTHO N+1 QUAD DEVELOPER" , - param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "MODEL_NP1_QUAD_EPSILON (developer)" ) << std::endl - << ". with the direction type ORTHO N+1 QUAD selected the" << std::endl - << " (n+1)-th direction is determined within a truncated " << std::endl - << " unit hypercube ]epsilon;1[^n defined by the first " << std::endl - << " n-th directions. The truncation is on lower limit " << std::endl - << " and is defined with a single argument (epsilon)." << std::endl - << ". argument: real in ]0;1[" << std::endl - << ". default: 0.01" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MODEL_TGP_MODE: - // --------------- - if ( developer && (display_all || NOMAD::string_find ( "MODEL_TGP_MODE MODEL_SEARCH DEVELOPER \ - MODELS INTERPOLATION REGRESSION \ - TGP" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MODEL_TGP_MODE (developer)" ) << std::endl - << ". TGP mode (fast or precise)" << std::endl - << ". arguments: one string in {\'FAST\', \'PRECISE\'}" << std::endl - << ". default: \'FAST\'" << std::endl - << ". example: MODEL_TGP_MODE PRECISE" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MODEL_TGP_REUSE_MODEL: - // ---------------------- - if (developer && ( display_all || NOMAD::string_find ( "MODEL_TGP_REUSE_MODEL DEVELOPER \ - MODELS INTERPOLATION REGRESSION \ - TGP" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "MODEL_TGP_REUSE_MODEL (developer)" ) << std::endl - << ". enable to use the last model from the TGP search for" << std::endl - << " the TGP model eval sort strategy." << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'yes\'" << std::endl - << ". example: MODEL_TGP_REUSE_MODEL no" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // MULTI_FORMULATION: - // ----------------- - if ( developer && (display_all || NOMAD::string_find ( "MULTI_FORMULATION DEVELOPER PARETO \ - BI-OBJECTIVES MULTI-OBJECTIVES\ - BIOBJECTIVES MULTIOBJECTIVES \ - BI-MADS BIMADS" , - param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "MULTI_FORMULATION (developer)" ) << std::endl - << ". multi-objective optimization: single-objective reformulation" - << std::endl - << ". argument: one string in {\'NORMALIZED\', \'PRODUCT\', \'DIST_L1\'," - << std::endl - << " \'DIST_L2\', \'DIST_LINF\'}" << std::endl - << " (\'NORMALIZED\' and \'DIST_LINF\' are equivalent)" << std::endl - << ". default: \'PRODUCT\' or \'DIST_L2\' if VNS_SEARCH is set to \'yes\'" - << std::endl - << ". example: MULTI_FORMULATION DIST_L1" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - // MULTI_USE_DELTA_CRIT: - // --------------------- - if ( developer && ( display_all || NOMAD::string_find ( "MULTI_USE_DELTA_CRITERION DEVELOPER PARETO \ - BIOBJECTIVES MULTIOBJECTIVES \ - BI-MADS BIMADS \ - BI-OBJECTIVES MULTI-OBJECTIVES" , - param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "MULTI_USE_DELTA_CRIT (developer)" ) << std::endl - << ". multi-objective optimization: use the delta criterion" << std::endl - << " (can result in a better distributed Pareto front)" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: MULTI_USE_DELTA_CRIT yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPPORTUNISTIC_LUCKY_EVAL: - // ------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_LUCKY_EVAL DEVELOPER \ - BLACK-BOXES BLACKBOXES EVALUATIONS \ - SUCCESSES" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_LUCKY_EVAL (developer)" ) << std::endl - << ". developer parameter for the opportunistic" << std::endl - << " strategy" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". default: \'no\'" << std::endl - << ". example: OPPORTUNISTIC_LUCKY_EVAL yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPPORTUNISTIC_MIN_F_IMPRVMT: - // ---------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_F_IMPRVMT DEVELOPER \ - OBJECTIVE \ - BLACK-BOXES BLACKBOXES EVALUATIONS \ - SUCCESSES IMPROVEMENT" , param_names ) ) ) { - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_MIN_F_IMPRVMT (developer)" ) << std::endl - << ". advanced parameter for the opportunistic" << std::endl - << " strategy (see user guide)" << std::endl - << ". argument: one real" << std::endl - << ". no default" << std::endl - << ". example: OPPORTUNISTIC_MIN_F_IMPRVMT 0.1" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPPORTUNISTIC_MIN_NB_SUCCESS: - // ----------------------------- - if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_NB_SUCCESSES DEVELOPER \ - BLACK-BOXES BLACKBOXES \ - EVALUATIONS" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "OPPORTUNISTIC_MIN_NB_SUCCESS (developer)" ) << std::endl - << ". advanced parameter for the opportunistic" << std::endl - << " strategy (see user guide)" << std::endl - << ". argument: one nonnegative integer" << std::endl - << ". no default" << std::endl - << ". example: OPPORTUNISTIC_MIN_NB_SUCCESS 2" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // OPT_ONLY_SGTE: - // -------------- - if (developer && ( display_all || NOMAD::string_find ( "OPT_ONLY_SGTES DEVELOPER SURROGATES \ - BLACK-BOXES BLACKBOXES \ - SGTES" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "OPT_ONLY_SGTE (developer)" ) << std::endl - << ". NOMAD will only minimize the surrogate" << std::endl - << ". argument: one boolean (\'yes\' or \'no\')" << std::endl - << ". SGTE_EXE or HAS_SGTE must be defined" << std::endl - << ". default: \'no\'" << std::endl - << ". example: OPT_ONLY_SGTE yes" << std::endl - << NOMAD::close_block(); - chk = true; - } - - // SEC_POLL_DIR_TYPES: - // ------------------- - if ( developer && ( display_all || NOMAD::string_find ( "SEC_POLL_DIR_TYPES DEVELOPER MADS \ - POLL DIRECTIONS PB PEB \ - PROGRESSIVE-BARRIER" , param_names ) ) ){ - _out << std::endl - << NOMAD::open_block ( "SEC_POLL_DIR_TYPES (developer)" ) << std::endl - << ". types of directions for the secondary poll" << std::endl - << ". arguments: same logic as DIRECTION_TYPE" << std::endl - << ". default: see user guide" << std::endl - << ". example: SEC_POLL_DIR_TYPES ORTHO 1" << std::endl - << NOMAD::close_block(); - chk = true; - } - - - - // last display: - if ( !chk && developer) { - - std::string pname = ( pnames.size() == 1 ) ? - ("\'" + *pnames.begin() + "\'") : - "the specified list of parameter names"; - - _out << std::endl << "no help available for " << pname << std::endl - << "Developer help example: \'nomad -d mesh\' displays developer " << std::endl - << " help on the mesh parameters." << std::endl - << std::endl; - } - - - _out.close_block(); + param_names ) ) { + + if ( !NOMAD::string_find ( "RHO" , param_names ) ) { + + _out << std::endl + << NOMAD::open_block ( "VNS_SEARCH (advanced)" ) << std::endl + << ". Variable Neighborhood Search (VNS) search" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << " or one real in [0;1] for the VNS trigger" << std::endl + << ". default: \'no\' (same as 0.0)" << std::endl + << ". the VNS trigger is the maximum desired ratio of" << std::endl + << " VNS blackbox evaluations over the total number" << std::endl + << " of blackbox evaluations" << std::endl + << ". the VNS search is never executed with a null trigger" << std::endl + << " while a value of 1 allows the search at every" << std::endl + << " iteration" << std::endl + << ". if VNS_SEARCH=\'yes\', the default value of 0.75 is" << std::endl + << " taken for the trigger" << std::endl + << ". VNS search uses the surrogate if HAS_SGTE or" << std::endl + << " SGTE_EXE is defined" << std::endl + << ". " << NOMAD::open_block ( "examples" ) + << "VNS_SEARCH yes # VNS trigger of 75%" << std::endl + << "VNS_SEARCH 0.5 # VNS trigger of 50%" << std::endl + << NOMAD::close_block() << NOMAD::close_block(); + chk = true; + } + } + + + + // last display: + if ( !chk && !developer) { + + std::string pname = ( pnames.size() == 1 ) ? + ("\'" + *pnames.begin() + "\'") : + "the specified list of parameter names"; + + _out << std::endl << "no help available for " << pname << std::endl + << "help example: \'nomad -h mesh\' displays help on the mesh parameters" + << std::endl; + } + + if (developer && NOMAD::string_find(registered_key_developer,param_names)) + { + _out << "--------------------------------------------------------------" << endl; + _out << "---------------------DEVELOPER PARAMETERS---------------------" << endl; + _out << "--------------------------------------------------------------" << endl; + } + + // EPSILON: + // -------- + if ( developer && (display_all || NOMAD::string_find ( "EPSILON DEVELOPPER \ + PRECISION REALS COMPARISONS" , + param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "EPSILON (developer)" ) << std::endl + << ". precision on reals" << std::endl + << ". argument: one positive real" << std::endl + << ". default: 1E-13" << std::endl + << ". example: EPSILON 1E-8" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // INITIAL_MESH_INDEX: + // ------------------- + if ( developer && ( display_all || NOMAD::string_find ( "INITIAL_MESH_INDEX DEVELOPER SMESH \ + \\DELTA MADS L0 L_0 \\ELL_0" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "INITIAL_MESH_INDEX (developer)" ) << std::endl + << ". initial mesh index for SMesh \\ell_0" << std::endl + << ". argument: one integer (can be negative)" << std::endl + << ". default: 0" << std::endl + << ". example: INITIAL_MESH_INDEX -1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // L_CURVE_TARGET: + // --------------- + if ( developer && ( display_all || NOMAD::string_find ( "L_CURVE_TARGET DEVELOPER TERMINATION \ + STOPPING TERMINATES" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "L_CURVE_TARGET (developer)" ) << std::endl + << ". MADS terminates if it detects that the objective will" << std::endl + << " not reach this value (based on an approximation" << std::endl + << " of the L-shaped curve obj_value v.s. bb_eval)" << std::endl + << ". argument: one real" << std::endl + << ". no default" << std::endl + << ". example: L_CURVE_TARGET 10.0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + + // MODEL_EVAL_SORT_CAUTIOUS: + // ------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_ORDERING MODEL_EVAL_SORT_CAUTIOUS \ + MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS DEVELOPER \ + QUADRATIC TGP" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_EVAL_SORT_CAUTIOUS (developer)" ) << std::endl + << ". if the model ordering strategy is cautious, meaning" << std::endl + << " that models are evaluated only within a trust radius" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: MODEL_EVAL_SORT_CAUTIOUS no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_QUAD_MAX_Y_SIZE: + // ---------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_MAX_Y_SIZE MODEL_SEARCH DEVELOPER \ + MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_QUAD_MAX_Y_SIZE (developer)" ) << std::endl + << ". Sup. limit on the size of interp. set Y for quadr. models" << std::endl + << ". arguments: one integer greater than the number of variables" << std::endl + << ". default: 500" << std::endl + << ". example: MODEL_QUAD_MAX_Y_SIZE 10" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_QUAD_MIN_Y_SIZE: + // ---------------------- + if ( developer && (display_all || NOMAD::string_find ( "MODEL_QUAD_MIN_Y_SIZE MODEL_SEARCH DEVELOPER \ + MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_QUAD_MIN_Y_SIZE (developer)" ) << std::endl + << ". Inf. limit on the size of interp. set Y for quadr. models" << std::endl + << ". arguments: one integer > 1 or the string \'N+1\'" << std::endl + << ". default: N+1" << std::endl + << ". examples: MODEL_QUAD_MIN_Y_SIZE N+1" << std::endl + << " MODEL_QUAD_MIN_Y_SIZE -1 # same as N+1" << std::endl + << " MODEL_QUAD_MIN_Y_SIZE 2" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_QUAD_RADIUS_FACTOR: + // ------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_RADIUS_FACTOR MODEL_SEARCH \ + DEVELOPER MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_QUAD_RADIUS_FACTOR (developer)" ) << std::endl + << ". quadratic model search radius factor (see user guide)" << std::endl + << ". arguments: one strictly positive real" << std::endl + << ". default: 2.0" << std::endl + << ". example: MODEL_QUAD_RADIUS_FACTOR 1.0" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_SEARCH_MAX_TRIAL_PTS: + // --------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_SEARCH_MAX_TRIAL_PTS \ + DEVELOPER MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC \ + TGP" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_SEARCH_MAX_TRIAL_PTS (developer)" ) << std::endl + << ". limit on the number of trial points for one model search" << std::endl + << ". arguments: one integer greater than or equal to 1" << std::endl + << ". the quadratic model search will not generate more than 4 points" << std::endl + << ". default: 10" << std::endl + << ". example: MODEL_SEARCH_MAX_TRIAL_PTS 1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_SEARCH_PROJ_TO_MESH: + // -------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_SEARCH_PROJ_TO_MESH DEVELOPER \ + MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC PROJECTION \ + TGP" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_SEARCH_PROJ_TO_MESH (developer)" ) << std::endl + << ". if model search trial points are projected to the mesh" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: MODEL_SEARCH_PROJ_TO_MESH no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_QUAD_USE_WP: + // ------------------ + if ( developer && ( display_all || NOMAD::string_find ( "MODEL_QUAD_USE_WP DEVELOPER \ + WELL-POISEDNESS \ + MODELS INTERPOLATION REGRESSION \ + MFN FROBENIUS QUADRATIC" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "MODEL_QUAD_USE_WP (developer)" ) << std::endl + << ". enable the strategy to maintain WP with quadr. models" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: MODEL_QUAD_USE_WP yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MODEL_NP1_QUAD_EPSILON : + // --------------- + if ( developer && (display_all || NOMAD::string_find ( "MODEL MODELS NP1 QUAD EPSILON \ + ORTHO N+1 QUAD DEVELOPER" , + param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "MODEL_NP1_QUAD_EPSILON (developer)" ) << std::endl + << ". with the direction type ORTHO N+1 QUAD selected the" << std::endl + << " (n+1)-th direction is determined within a truncated " << std::endl + << " unit hypercube ]epsilon;1[^n defined by the first " << std::endl + << " n-th directions. The truncation is on lower limit " << std::endl + << " and is defined with a single argument (epsilon)." << std::endl + << ". argument: real in ]0;1[" << std::endl + << ". default: 0.01" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MODEL_TGP_MODE: + // --------------- + if ( developer && (display_all || NOMAD::string_find ( "MODEL_TGP_MODE MODEL_SEARCH DEVELOPER \ + MODELS INTERPOLATION REGRESSION \ + TGP" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MODEL_TGP_MODE (developer)" ) << std::endl + << ". TGP mode (fast or precise)" << std::endl + << ". arguments: one string in {\'FAST\', \'PRECISE\'}" << std::endl + << ". default: \'FAST\'" << std::endl + << ". example: MODEL_TGP_MODE PRECISE" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MODEL_TGP_REUSE_MODEL: + // ---------------------- + if (developer && ( display_all || NOMAD::string_find ( "MODEL_TGP_REUSE_MODEL DEVELOPER \ + MODELS INTERPOLATION REGRESSION \ + TGP" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "MODEL_TGP_REUSE_MODEL (developer)" ) << std::endl + << ". enable to use the last model from the TGP search for" << std::endl + << " the TGP model eval sort strategy." << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'yes\'" << std::endl + << ". example: MODEL_TGP_REUSE_MODEL no" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // MULTI_FORMULATION: + // ----------------- + if ( developer && (display_all || NOMAD::string_find ( "MULTI_FORMULATION DEVELOPER PARETO \ + BI-OBJECTIVES MULTI-OBJECTIVES\ + BIOBJECTIVES MULTIOBJECTIVES \ + BI-MADS BIMADS" , + param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "MULTI_FORMULATION (developer)" ) << std::endl + << ". multi-objective optimization: single-objective reformulation" + << std::endl + << ". argument: one string in {\'NORMALIZED\', \'PRODUCT\', \'DIST_L1\'," + << std::endl + << " \'DIST_L2\', \'DIST_LINF\'}" << std::endl + << " (\'NORMALIZED\' and \'DIST_LINF\' are equivalent)" << std::endl + << ". default: \'PRODUCT\' or \'DIST_L2\' if VNS_SEARCH is set to \'yes\'" + << std::endl + << ". example: MULTI_FORMULATION DIST_L1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // MULTI_USE_DELTA_CRIT: + // --------------------- + if ( developer && ( display_all || NOMAD::string_find ( "MULTI_USE_DELTA_CRITERION DEVELOPER PARETO \ + BIOBJECTIVES MULTIOBJECTIVES \ + BI-MADS BIMADS \ + BI-OBJECTIVES MULTI-OBJECTIVES" , + param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "MULTI_USE_DELTA_CRIT (developer)" ) << std::endl + << ". multi-objective optimization: use the delta criterion" << std::endl + << " (can result in a better distributed Pareto front)" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: MULTI_USE_DELTA_CRIT yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPPORTUNISTIC_LUCKY_EVAL: + // ------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_LUCKY_EVAL DEVELOPER \ + BLACK-BOXES BLACKBOXES EVALUATIONS \ + SUCCESSES" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_LUCKY_EVAL (developer)" ) << std::endl + << ". developer parameter for the opportunistic" << std::endl + << " strategy" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". default: \'no\'" << std::endl + << ". example: OPPORTUNISTIC_LUCKY_EVAL yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPPORTUNISTIC_MIN_F_IMPRVMT: + // ---------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_F_IMPRVMT DEVELOPER \ + OBJECTIVE \ + BLACK-BOXES BLACKBOXES EVALUATIONS \ + SUCCESSES IMPROVEMENT" , param_names ) ) ) { + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_MIN_F_IMPRVMT (developer)" ) << std::endl + << ". advanced parameter for the opportunistic" << std::endl + << " strategy (see user guide)" << std::endl + << ". argument: one real" << std::endl + << ". no default" << std::endl + << ". example: OPPORTUNISTIC_MIN_F_IMPRVMT 0.1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPPORTUNISTIC_MIN_NB_SUCCESS: + // ----------------------------- + if ( developer && ( display_all || NOMAD::string_find ( "OPPORTUNISTIC_MIN_NB_SUCCESSES DEVELOPER \ + BLACK-BOXES BLACKBOXES \ + EVALUATIONS" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "OPPORTUNISTIC_MIN_NB_SUCCESS (developer)" ) << std::endl + << ". advanced parameter for the opportunistic" << std::endl + << " strategy (see user guide)" << std::endl + << ". argument: one nonnegative integer" << std::endl + << ". no default" << std::endl + << ". example: OPPORTUNISTIC_MIN_NB_SUCCESS 2" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // OPT_ONLY_SGTE: + // -------------- + if (developer && ( display_all || NOMAD::string_find ( "OPT_ONLY_SGTES DEVELOPER SURROGATES \ + BLACK-BOXES BLACKBOXES \ + SGTES" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "OPT_ONLY_SGTE (developer)" ) << std::endl + << ". NOMAD will only minimize the surrogate" << std::endl + << ". argument: one boolean (\'yes\' or \'no\')" << std::endl + << ". SGTE_EXE or HAS_SGTE must be defined" << std::endl + << ". default: \'no\'" << std::endl + << ". example: OPT_ONLY_SGTE yes" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // SEC_POLL_DIR_TYPES: + // ------------------- + if ( developer && ( display_all || NOMAD::string_find ( "SEC_POLL_DIR_TYPES DEVELOPER MADS \ + POLL DIRECTIONS PB PEB \ + PROGRESSIVE-BARRIER" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "SEC_POLL_DIR_TYPES (developer)" ) << std::endl + << ". types of directions for the secondary poll" << std::endl + << ". arguments: same logic as DIRECTION_TYPE" << std::endl + << ". default: see user guide" << std::endl + << ". example: SEC_POLL_DIR_TYPES ORTHO 1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + // USE_SMESH: + // ------------------- + if ( developer && ( display_all || NOMAD::string_find ( "USE_SMESH SMESH MESH \ + ANISO" , param_names ) ) ){ + _out << std::endl + << NOMAD::open_block ( "USE_SMESH (developer)" ) << std::endl + << ". forces the use of the standard mesh (older version of mesh)" << std::endl + << ". default: no" << std::endl + << ". example: USE_SMESH 1" << std::endl + << NOMAD::close_block(); + chk = true; + } + + + // last display: + if ( !chk && developer) { + + std::string pname = ( pnames.size() == 1 ) ? + ("\'" + *pnames.begin() + "\'") : + "the specified list of parameter names"; + + _out << std::endl << "no help available for " << pname << std::endl + << "Developer help example: \'nomad -d mesh\' displays developer " << std::endl + << " help on the mesh parameters." << std::endl + << std::endl; + } + + + _out.close_block(); } diff --git a/src/Parameters.hpp b/src/Parameters.hpp index 67f976e9a32f834499c72a10c89d57659ebbe879..5a8d6c8e701ebd7c4f3234a55db81a080f1848dc 100644 --- a/src/Parameters.hpp +++ b/src/Parameters.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Parameters.hpp - \brief NOMAD Parameters (headers) - \author Sebastien Le Digabel - \date 2010-04-21 - \see Parameters.cpp -*/ + \file Parameters.hpp + \brief NOMAD Parameters (headers) + \author Sebastien Le Digabel + \date 2010-04-21 + \see Parameters.cpp + */ #ifndef __PARAMETERS__ #define __PARAMETERS__ @@ -51,2471 +51,2551 @@ #include "Signature.hpp" namespace NOMAD { - - /// Structure to represent the models parameters. - struct model_params_type { - - NOMAD::model_type search1; ///< First model search (MS) type. - NOMAD::model_type search2; ///< Second model search (MS) type. - - NOMAD::model_type eval_sort; ///< Use models to sort trial pts (MES). - - bool search_optimistic; ///< If the MS is optimistic or not. - bool search_proj_to_mesh; ///< Model solution projected or not to mesh. - int search_max_trial_pts; ///< Limit on the number of MS trial pts. - bool eval_sort_cautious; ///< Cautious strategy for MES. - - NOMAD::Double quad_radius_factor; ///< Quadratic model radius factor \c r. - bool quad_use_WP; ///< Use or not a well-poisedness strategy. - int quad_min_Y_size; ///< Limit inf on the size of \c Y. - int quad_max_Y_size; ///< Limit sup on the size of \c Y. - NOMAD::Double model_np1_quad_epsilon;///< Ortho n+1 quadratic model epsilon (scaling used for (n+1)th dynamic direction with Ortho n+1) - - NOMAD::TGP_mode_type tgp_mode; ///< TGP mode (fast or precise). - bool tgp_reuse_model; ///< Use the model from MS for the MES. - }; - - /// Class for the NOMAD parameters. - class Parameters : private NOMAD::Uncopyable { - - private: - - bool _to_be_checked; ///< Access control to the parameters. - static bool _warning_has_been_displayed; - NOMAD::Display _out; ///< Display. - - /*----------------------------------------------------------------------*/ - - /// Initializations. - void init ( void ); - - /// Interpretation of the entries for the starting point. - /** - \param entries Parameter entries -- \b IN. - */ - void interpret_x0 ( const NOMAD::Parameter_Entries & entries ); - - /// Interpretation of the entries for mesh and poll sizes. - /** - \param entries Parameter entries -- \b IN. - \param param_name Parameter name -- \b IN. - */ - void interpret_mesh_sizes ( const NOMAD::Parameter_Entries & entries , - const std::string & param_name ); - - /// Interpretation of the entries for bounds and fixed variables. - /** - \c BFVS stands for "Bounds and Fixed VariableS". - \param entries Parameter entries -- \b IN. - \param param_name Parameter name -- \b IN. - */ - void interpret_BFVS ( const NOMAD::Parameter_Entries & entries , - const std::string & param_name ); - /// Interpretation of the entries for parameter \c BB_INPUT_TYPE. - /** - \param entries Parameter entries -- \b IN. - */ - void interpret_bb_input_type ( const NOMAD::Parameter_Entries & entries ); - - /// Interpretation of the entries for parameter \c PERIODIC_VARIABLE. - /** - \param entries Parameter entries -- \b IN. - */ - void interpret_periodic_var ( const NOMAD::Parameter_Entries & entries ); - - /// Interpretation of the entries for parameter \c VARIABLE_GROUP. - /** - \param entries Parameter entries -- \b IN. - */ - void interpret_var_groups ( const NOMAD::Parameter_Entries & entries ); - - // Interpretation of the entries for parameter \c F_TARGET. - /** - \param entries Parameter entries -- \b IN. - */ - void interpret_f_target ( const NOMAD::Parameter_Entries & entries ); - - /// Delete the list of starting points. - void delete_x0s ( void ); - - /// Check a directory name. - /** - \param dir Directory name -- \b IN. - \return A boolean equal to \c true if the directory is valid. - */ - static bool check_directory ( std::string & dir ); - - /// Add a seed to a file name. - /** - - Transforms \c file_name.ext into \c file_name.seed.ext. - \param n_seed Length of the seed \c s_seed -- \b IN. - \param s_seed A string representating the seed -- \b IN. - \param file_name File name -- \b IN/OUT. - */ - static void add_seed_to_file_name ( int n_seed , - const std::string & s_seed , - std::string & file_name ); - - - - /// Check if a specified direction type is set. - /** - \param dt The specified direction type -- \b IN. - \return true if the specified direction type is used. - */ - bool has_direction_type(NOMAD::direction_type dt) const; - - - /*----------------------------------------------------------------------*/ - - public: - - /// Exception class for an invalid parameter. - class Invalid_Parameter : public NOMAD::Exception { - public: - /// Constructor. - Invalid_Parameter ( const std::string & file , - int line , - const std::string & msg ) - : NOMAD::Exception ( file , line , msg ) {} + /// Structure to represent the models parameters. + struct model_params_type { + + NOMAD::model_type search1; ///< First model search (MS) type. + NOMAD::model_type search2; ///< Second model search (MS) type. + + NOMAD::model_type eval_sort; ///< Use models to sort trial pts (MES). + + bool search_optimistic; ///< If the MS is optimistic or not. + bool search_proj_to_mesh; ///< Model solution projected or not to mesh. + int search_max_trial_pts; ///< Limit on the number of MS trial pts. + bool eval_sort_cautious; ///< Cautious strategy for MES. + + NOMAD::Double quad_radius_factor; ///< Quadratic model radius factor \c r. + bool quad_use_WP; ///< Use or not a well-poisedness strategy. + int quad_min_Y_size; ///< Limit inf on the size of \c Y. + int quad_max_Y_size; ///< Limit sup on the size of \c Y. + NOMAD::Double model_np1_quad_epsilon;///< Ortho n+1 quadratic model epsilon (scaling used for (n+1)th dynamic direction with Ortho n+1) + + NOMAD::TGP_mode_type tgp_mode; ///< TGP mode (fast or precise). + bool tgp_reuse_model; ///< Use the model from MS for the MES. }; - /// Exception class for a bad access. - class Bad_Access : public NOMAD::Exception { + /// Class for the NOMAD parameters. + class Parameters : private NOMAD::Uncopyable { + + private: + + bool _to_be_checked; ///< Access control to the parameters. + static bool _warning_has_been_displayed; + NOMAD::Display _out; ///< Display. + + /*----------------------------------------------------------------------*/ + + /// Initializations. + void init ( void ); + + /// Interpretation of the entries for the starting point. + /** + \param entries Parameter entries -- \b IN. + */ + void interpret_x0 ( const NOMAD::Parameter_Entries & entries ); + + /// Interpretation of the entries for mesh and poll sizes. + /** + \param entries Parameter entries -- \b IN. + \param param_name Parameter name -- \b IN. + */ + void interpret_mesh_sizes ( const NOMAD::Parameter_Entries & entries , + const std::string & param_name ); + + /// Interpretation of the entries for bounds and fixed variables. + /** + \c BFVS stands for "Bounds and Fixed VariableS". + \param entries Parameter entries -- \b IN. + \param param_name Parameter name -- \b IN. + */ + void interpret_BFVS ( const NOMAD::Parameter_Entries & entries , + const std::string & param_name ); + + /// Interpretation of the entries for parameter \c BB_INPUT_TYPE. + /** + \param entries Parameter entries -- \b IN. + */ + void interpret_bb_input_type ( const NOMAD::Parameter_Entries & entries ); + + /// Interpretation of the entries for parameter \c PERIODIC_VARIABLE. + /** + \param entries Parameter entries -- \b IN. + */ + void interpret_periodic_var ( const NOMAD::Parameter_Entries & entries ); + + /// Interpretation of the entries for parameter \c VARIABLE_GROUP. + /** + \param entries Parameter entries -- \b IN. + */ + void interpret_var_groups ( const NOMAD::Parameter_Entries & entries ); + + // Interpretation of the entries for parameter \c F_TARGET. + /** + \param entries Parameter entries -- \b IN. + */ + void interpret_f_target ( const NOMAD::Parameter_Entries & entries ); + + /// Delete the list of starting points. + void delete_x0s ( void ); + + /// Check a directory name. + /** + \param dir Directory name -- \b IN. + \return A boolean equal to \c true if the directory is valid. + */ + static bool check_directory ( std::string & dir ); + + /// Add a seed to a file name. + /** + - Transforms \c file_name.ext into \c file_name.seed.ext. + \param n_seed Length of the seed \c s_seed -- \b IN. + \param s_seed A string representating the seed -- \b IN. + \param file_name File name -- \b IN/OUT. + */ + static void add_seed_to_file_name ( int n_seed , + const std::string & s_seed , + std::string & file_name ); + + + + /// Check if a specified direction type is set. + /** + \param dt The specified direction type -- \b IN. + \return true if the specified direction type is used. + */ + bool has_direction_type(NOMAD::direction_type dt) const; + + + /*----------------------------------------------------------------------*/ + public: - /// Constructor. - Bad_Access ( const std::string & file , - int line , - const std::string & msg ) - : NOMAD::Exception ( file , line , msg ) {} + + /// Exception class for an invalid parameter. + class Invalid_Parameter : public NOMAD::Exception { + public: + /// Constructor. + Invalid_Parameter ( const std::string & file , + int line , + const std::string & msg ) + : NOMAD::Exception ( file , line , msg ) {} + }; + + /// Exception class for a bad access. + class Bad_Access : public NOMAD::Exception { + public: + /// Constructor. + Bad_Access ( const std::string & file , + int line , + const std::string & msg ) + : NOMAD::Exception ( file , line , msg ) {} + }; + + /*----------------------------------------------------------------------*/ + + /// Constructor #1. + /** + \param out Display -- \b IN. + */ + explicit Parameters ( const NOMAD::Display & out ) + : _out ( out ) , + _std_signature ( NULL ) , + _extern_signature ( NULL ) { init(); } + + /// Constructor #2. + /** + From an extern signature. + \param extern_signature A pointer to the extern signature -- \b IN. + \param out Display -- \b IN. + */ + explicit Parameters ( NOMAD::Signature * extern_signature , + const NOMAD::Display & out ) + : _out ( out ) , + _std_signature ( NULL ) , + _extern_signature ( extern_signature ) { init(); } + + /// Destructor. + virtual ~Parameters ( void ); + + /// Display parameter help. + /** + - Help option obtained with command \c nomad \c -h. + - A list of parameters is given as the program arguments. + \param argc Number of command line arguments -- \b IN. + \param argv The command line arguments -- \b IN. + \param developer Bool to request developer help (defaut=false) -- \b IN. + */ + void help ( int argc , char ** argv , bool developer=false) const; + + /// Display parameter help. + /** + For a specific parameter. + \param param_name Name of the parameter -- \b IN. + \param developer Bool to request developer help (defaut=false) -- \b IN. + */ + void help ( const std::string & param_name, bool developer=false ) const; + + /// Display parameter help. + /** + For a list of parameters. + \param param_names_list List of parameter names -- \b IN. + \param developer Bool to request developer help (defaut=false) -- \b IN. + */ + void help ( const std::list<std::string> & param_names_list , bool developer=false) const; + + /// Reset. + void reset ( void ) { init(); } + + /// Read parameters from a file. 1/2 + /** + \param param_file Name of the parameters file -- \b IN. + */ + void read ( const std::string & param_file ); + + /// Read parameters from a Parameter_Entries 2/2 + /** + \param entries -- \b IN. + */ + void read ( const NOMAD::Parameter_Entries & entries ); + + + /// Check the parameters. + /** + \param remove_history_file A boolean equal to \c true if the history file + has to be deleted + -- \b IN -- \b optional (default = \c true). + \param remove_solution_file A boolean equal to \c true if the solution file + has to be deleted + -- \b IN -- \b optional (default = \c true). + \param remove_stats_file A boolean equal to \c true if the stats file + has to be deleted + -- \b IN -- \b optional (default = \c true). + */ + void check ( bool remove_history_file = true , + bool remove_solution_file = true , + bool remove_stats_file = true ); + + /// Force the check flag to be satisfied. + /** + This advanced function should be used with care. + */ + void force_check_flag ( void ) { _to_be_checked = false; } + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + /// Display. + /** + Uses \c this->_out as NOMAD::Display object. + */ + void display ( void ) const { display ( _out ); } + + /*--------------------------------------------------------------*/ + /* Attributes and methods listed by categories */ + /*--------------------------------------------------------------*/ + + // Algorithm and miscellaneous parameters: + // --------------------------------------- + private: + std::string _problem_dir; ///< Problem directory. + std::string _tmp_dir; ///< Temporary directory. + int _seed; ///< Seed. + int _max_eval; ///< Maximum number of evaluations. + int _max_bb_eval; ///< Maximum number of blackbox evaluations. + + std::list<std::string> _display_stats; ///< Stats keywords for \c DISPLAY_STATS. + bool _display_all_eval; ///< Parameter \c DISPLAY_ALL_EVAL + + /// Equal to \c true if \c _max_bb_eval has been entered. + bool _max_bbe_decided; + + /// Maximum number of simulated evaluations. + int _max_sim_bb_eval; + + int _max_time; ///< Maximum time. + int _max_iterations; ///< Maximum number of iterations. + int _max_cons_failed_it; ///< Maximum number of consecutive failed iterations. + float _max_cache_memory; ///< Maximum cache memory. + bool _stop_if_feasible; ///< Stop if a feasible solution is found. + NOMAD::Point _f_target; ///< Target for the objective function. + NOMAD::Double _stat_sum_target; ///< Target for the STAT_SUM stat. + NOMAD::Double _L_curve_target; ///< Target for the L_CURVE criterion. + bool _snap_to_bounds; ///< Snap or not the points to the bounds. + bool _user_calls_enabled; ///< Enable calls to user functions. + bool _asynchronous; ///< Asynchronous version for parallelism. + + public: + + /// Test to know if parameters have to be checked. + /** + \return A boolean equal to \c true if parameters have + to be checked with function NOMAD::Parameters::check(). + */ + bool to_be_checked ( void ) const { return _to_be_checked; } + + /// Access to the display degrees. + /** + - Use NOMAD::Parameters::out().get_X_dd() + to access other specific display degrees. + - \see Display.hpp. + \param d The 4 display degrees as a string -- \b OUT. + */ + void get_display_degree ( std::string & d ) const; + + /// Access to the display degree. + /** + \return General display degree. + */ + int get_display_degree ( void ) const; + + /// Access to display. + /** + \return The NOMAD::Display object. + */ + const NOMAD::Display & out ( void ) const; + + /// Access to the \c DISPLAY_STATS parameter. + /** + \return The \c DISPLAY_STATS parameter. + */ + const std::list<std::string> & get_display_stats ( void ) const; + + /// Access to the \c DISPLAY_ALL_EVAL parameter. + /** + \return The \c DISPLAY_ALL_EVAL parameter. + */ + bool get_display_all_eval ( void ) const; + + /// Access to the \c POINT_DISPLAY_LIMIT parameter. + /** + \return The \c POINT_DISPLAY_LIMIT parameter. + */ + int get_point_display_limit ( void ) const; + + /// Access to the seed. + /** + \return The seed. + */ + int get_seed ( void ) const; + + /// Access to the maximum number of evaluations. + /** + \return The maximum number of evaluations. + */ + int get_max_eval ( void ) const; + + /// Access to the \c MAX_SIM_BB_EVAL parameter. + /** + \return The \c MAX_SIM_BB_EVAL parameter. + */ + int get_max_sim_bb_eval ( void ) const; + + /// Access to the \c MAX_BB_EVAL parameter. + /** + \return The \c MAX_BB_EVAL parameter. + */ + int get_max_bb_eval ( void ) const; + + /// Access to the \c MAX_TIME parameter. + /** + \return The \c MAX_TIME parameter. + */ + int get_max_time ( void ) const; + + /// Access to the maximum number of iterations. + /** + \return The maximum number of iterations. + */ + int get_max_iterations ( void ) const; + + /// Access to the maximum number of consecutive failed iterations. + /** + \return The maximum number of consecutive failed iterations. + */ + int get_max_consecutive_failed_iterations ( void ) const; + + /// Access to the maximum cache memory. + /** + \return The maximum cache memory. + */ + float get_max_cache_memory ( void ) const; + + /// Access to the \c STOP_IF_FEASIBLE parameter. + /** + \return The \c STOP_IF_FEASIBLE parameter. + */ + bool get_stop_if_feasible ( void ) const; + + /// Access to the \c F_TARGET parameter. + /** + \return The \c F_TARGET parameter. + */ + const NOMAD::Point & get_f_target ( void ) const; + + /// Access to the \c STAT_SUM_TARGET parameter. + /** + \return The \c STAT_SUM_TARGET parameter. + */ + const NOMAD::Double & get_stat_sum_target ( void ) const; + + /// Access to the \c L_CURVE_TARGET parameter. + /** + \return The \c L_CURVE_TARGET parameter. + */ + const NOMAD::Double & get_L_curve_target ( void ) const; + + /// Access to the problem directory. + /** + \return The problem directory. + */ + const std::string & get_problem_dir ( void ) const; + + /// Access to the temporary directory. + /** + \return The temporary directory. + */ + const std::string & get_tmp_dir ( void ) const; + + /// Access to the \c SNAP_TO_BOUNDS parameter. + /** + \return The \c SNAP_TO_BOUNDS parameter. + */ + bool get_snap_to_bounds ( void ) const; + + /// Access to the \c USER_CALLS_ENABLED parameter. + /** + \return The \c USER_CALLS_ENABLED parameter. + */ + bool get_user_calls_enabled ( void ) const; + + /// Access to the \c ASYNCHRONOUS parameter. + /** + \return The \c ASYNCHRONOUS parameter. + */ + bool get_asynchronous ( void ) const; + + /// Set the \c POINT_DISPLAY_LIMIT parameter. + /** + \param dl The \c POINT_DISPLAY_LIMIT parameter -- \b IN. + */ + void set_POINT_DISPLAY_LIMIT ( int dl ); + + /// Set the \c DISPLAY_STATS parameter. + /** + - From a list of strings. + \param ds The \c DISPLAY_STATS parameter -- \b IN. + */ + void set_DISPLAY_STATS ( const std::list<std::string> & ds ); + + /// Set the \c DISPLAY_STATS parameter. + /** + - From a string. + \param ds The \c DISPLAY_STATS parameter -- \b IN. + */ + void set_DISPLAY_STATS ( const std::string & ds ); + + /// Set the \c DISPLAY_ALL_EVAL parameter. + /** + \param dae The \c DISPLAY_ALL_EVAL parameter -- \b IN. + */ + void set_DISPLAY_ALL_EVAL ( bool dae ); + + /// Set the display degree. + /** + - Accepts also NOMAD::dd_type arguments. + \param dd Display degree -- \b IN. + \return \c true if the operation succeeded. + */ + bool set_DISPLAY_DEGREE ( int dd ); + + /// Set the display degrees. + /** + - From a string with the 4 degrees. + \param dd Display degree -- \b IN. + \return \c true if the operation succeeded. + */ + bool set_DISPLAY_DEGREE ( const std::string & dd ); + + /// Set the display degrees. + /* + \param gen_dd General display degree -- \b IN. + \param search_dd Search display degree -- \b IN. + \param poll_dd Poll display degree -- \b IN. + \param iter_dd Iterative display degree -- \b IN. + */ + void set_DISPLAY_DEGREE ( int gen_dd , + int search_dd , + int poll_dd , + int iter_dd ); + + /// Set the \c OPEN_BRACE parameter. + /** + \param s The \c OPEN_BRACE parameter -- \b IN. + */ + void set_OPEN_BRACE ( const std::string & s ); + + /// Set the \c CLOSED_BRACE parameter. + /** + \param s The \c CLOSED_BRACE parameter -- \b IN. + */ + void set_CLOSED_BRACE ( const std::string & s ); + + /// Set the seed. + /** + \param seed The seed -- \b IN. + */ + void set_SEED ( int seed ); + + /// Set the \c MAX_EVAL parameter. + /** + \param me The \c MAX_EVAL parameter -- \b IN. + */ + void set_MAX_EVAL ( int me ); + + /// Set the \c MAX_SIM_BB_EVAL parameter. + /** + \param msbe The \c MAX_SIM_BB_EVAL parameter -- \b IN. + */ + void set_MAX_SIM_BB_EVAL ( int msbe ); + + /// Set the \c MAX_BB_EVAL parameter. + /** + \param bbe The \c MAX_BB_EVAL parameter -- \b IN. + */ + void set_MAX_BB_EVAL ( int bbe ); + + /// Set the \c MAX_TIME parameter. + /** + \param mt The \c MAX_TIME parameter -- \b IN. + */ + void set_MAX_TIME ( int mt ); + + /// Set the \c MAX_ITERATIONS parameter. + /** + \param mi The \c MAX_ITERATIONS parameter -- \b IN. + */ + void set_MAX_ITERATIONS ( int mi ); + + /// Set the \c MAX_CONSECUTIVE_FAILED_ITERATIONS parameter. + /** + \param mcsi The \c MAX_CONSECUTIVE_FAILED_ITERATIONS parameter -- \b IN. + */ + void set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( int mcsi ); + + /// Set the \c MAX_CACHE_MEMORY parameter. + /** + \param mcm The \c MAX_CACHE_MEMORY parameter -- \b IN. + */ + void set_MAX_CACHE_MEMORY ( float mcm ); + + /// Set the \c STOP_IF_FEASIBLE parameter. + /** + \param sif The \c STOP_IF_FEASIBLE parameter -- \b IN. + */ + void set_STOP_IF_FEASIBLE ( bool sif ); + + /// Set the \c STAT_SUM_TARGET parameter. + /** + \param target The \c STAT_SUM_TARGET parameter -- \b IN. + */ + void set_STAT_SUM_TARGET ( const NOMAD::Double & target ); + + /// Set the \c L_CURVE_TARGET parameter. + /** + \param target The \c L_CURVE_TARGET parameter -- \b IN. + */ + void set_L_CURVE_TARGET ( const NOMAD::Double & target ); + + /// Set the \c PROBLEM_DIR parameter. + /** + \param dir The \c PROBLEM_DIR parameter -- \b IN. + */ + void set_PROBLEM_DIR ( const std::string & dir ); + + /// Set the \c TMP_DIR parameter. + /** + \param dir The \c TMP_DIR parameter -- \b IN. + */ + void set_TMP_DIR ( const std::string & dir ); + + /// Set the \c SNAP_TO_BOUNDS parameter. + /** + \param stb The \c SNAP_TO_BOUNDS parameter -- \b IN. + */ + void set_SNAP_TO_BOUNDS ( bool stb ); + + /// Set the \c USER_CALLS_ENABLED parameter. + /** + \param uce The \c USER_CALLS_ENABLED parameter -- \b IN. + */ + void set_USER_CALLS_ENABLED ( bool uce ); + + /// Set the \c ASYNCHRONOUS parameter. + /** + \param as The \c ASYNCHRONOUS parameter -- \b IN. + */ + void set_ASYNCHRONOUS ( bool as ); + + /// Set the \c F_TARGET parameter. + /** + - Multi-objective version. + \param target The \c F_TARGET parameter -- \b IN. + */ + void set_F_TARGET ( const NOMAD::Point & target ); + + /// Set the F_TARGET \c parameter. + /** + - Single-objective version. + \param target The \c F_TARGET parameter -- \b IN. + */ + void set_F_TARGET ( const NOMAD::Double & target ); + + /// Reset the \c F_TARGET parameter. + void reset_f_target ( void ) { _f_target.clear(); } + + /// Set the \c EPSILON parameter. + /** + \param eps The \c EPSILON parameter -- \b IN. + */ + void set_EPSILON ( const NOMAD::Double & eps ) + { + NOMAD::Double::set_epsilon ( eps.value() ); + } + + /// Set the \c UNDEF_STR parameter. + /** + \param undef_str The \c UNDEF_STR parameter -- \b IN. + */ + void set_UNDEF_STR ( const std::string & undef_str ) + { + NOMAD::Double::set_undef_str ( undef_str ); + } + + /// Set the \c INF_STR parameter. + /** + \param inf_str The \c INF_STR parameter -- \b IN. + */ + void set_INF_STR ( const std::string & inf_str ) + { + NOMAD::Double::set_inf_str ( inf_str ); + } + + /// Access to the \c EPSILON parameter. + /** + \return The \c EPSILON parameter. + */ + const NOMAD::Double get_epsilon ( void ) const + { + return NOMAD::Double::get_epsilon(); + } + + /// Access to the \c UNDEF_STR parameter. + /** + \return The \c UNDEF_STR parameter. + */ + const std::string get_undef_str ( void ) const + { + return NOMAD::Double::get_undef_str(); + } + + /// Access to the \c INF_STR parameter. + /** + \return The \c INF_STR parameter. + */ + const std::string get_inf_str ( void ) const + { + return NOMAD::Double::get_inf_str(); + } + + // Output files: + // ------------- + private: + + /// List of stats for parameter \c STATS_FILE. + std::list<std::string> _stats_file; + + /// Name of the stats file. + std::string _stats_file_name; + + /// Parameter \c ADD_SEED_TO_FILE_NAME. + bool _add_seed_to_file_names; + + std::string _solution_file; ///< Parameter \c SOLUTION_FILE. + std::string _history_file; ///< Parameter \c HISTORY_FILE. + std::string _cache_file; ///< Parameter \c CACHE_FILE. + int _cache_save_period; ///< Parameter \c CACHE_SAVE_PERIOD. + + public: + + /// Access to the list of stats for the \c STATS_FILE parameter. + /** + \return The list of stats. + */ + const std::list<std::string> & get_stats_file ( void ) const; + + /// Access to the name of the stats file. + /** + \return The name of the stats file. + */ + const std::string & get_stats_file_name ( void ) const; + + /// Access to the \c SOLUTION_FILE parameter. + /** + \return The \c SOLUTION_FILE parameter. + */ + const std::string & get_solution_file ( void ) const; + + /// Access to the \c HISTORY_FILE parameter. + /** + \return The \c HISTORY_FILE parameter. + */ + const std::string & get_history_file ( void ) const; + + /// Access to the \c CACHE_FILE parameter. + /** + \return The \c CACHE_FILE parameter. + */ + const std::string & get_cache_file ( void ) const; + + /// Access to the \c CACHE_SAVE_PERIOD parameter. + /** + \return The \c CACHE_SAVE_PERIOD parameter. + */ + int get_cache_save_period ( void ) const; + + /// Access to the \c ADD_SEED_TO_FILE_NAME parameter. + /** + \return The \c ADD_SEED_TO_FILE_NAME parameter. + */ + bool get_add_seed_to_file_names ( void ) const; + + /// Reset the \c STATS_FILE parameter. + void reset_stats_file ( void ); + + /// Set the \c STATS_FILE parameter. + /** + \param file_name Name of the stats file -- \b IN. + \param stats List of stats -- \b IN. + */ + void set_STATS_FILE ( const std::string & file_name , + const std::list<std::string> & stats ); + + /// Set the \c STATS_FILE parameter. + /** + \param file_name Name of the stats file -- \b IN. + \param stats The stats -- \b IN. + */ + void set_STATS_FILE ( const std::string & file_name , + const std::string & stats ); + + /// Set the \c ADD_SEED_TO_FILE_NAME parameter. + /** + \param astfn The \c ADD_SEED_TO_FILE_NAME parameter -- \b IN. + */ + void set_ADD_SEED_TO_FILE_NAMES ( bool astfn ); + + /// Set the \c SOLUTION_FILE parameter. + /** + \param sf The \c SOLUTION_FILE parameter -- \b IN. + */ + void set_SOLUTION_FILE ( const std::string & sf ); + + /// Set the \c HISTORY_FILE parameter. + /** + \param hf The \c HISTORY_FILE parameter -- \b IN. + */ + void set_HISTORY_FILE ( const std::string & hf ); + + /// Set the \c CACHE_FILE parameter. + /** + \param cf The \c CACHE_FILE parameter -- \b IN. + */ + void set_CACHE_FILE ( const std::string & cf ); + + /// Set the \c CACHE_SAVE_PERIOD parameter. + /** + \param csp The \c CACHE_SAVE_PERIOD parameter -- \b IN. + */ + void set_CACHE_SAVE_PERIOD ( int csp ); + + // Searches: + // --------- + private: + + /// Speculative search (MADS search). + bool _speculative_search; + + bool _disable_models; ///< Models disablement + + NOMAD::model_params_type _model_params; ///< Models parameters. + + // VNS search parameters: + bool _VNS_search; ///< Flag for the VNS search. + NOMAD::Double _VNS_trigger; ///< VNS trigger. + + // Latin-Hypercube (LH) search: + int _LH_search_p0; ///< Number of initial LH search points. + int _LH_search_pi; ///< LH search points at each iteration. + bool _opportunistic_LH; ///< Parameter \c OPPORTUNISTIC_LH. + bool _opp_LH_is_defined; ///< A boolean equal to \c true if a LH has been defined. + + bool _cache_search; ///< Cache search. + bool _opportunistic_cache_search; ///< Parameter \c OPPORTUNISTIC_CACHE_SEARCH. + + /// A boolean equal to \c true if \c OPPORTUNISTIC_CACHE_SEARCH has been defined. + bool _opp_CS_is_defined; + + public: + + /// Access to the \c SPECULATIVE_SEARCH parameter. + /** + \return The \c SPECULATIVE_SEARCH parameter. + */ + bool get_speculative_search ( void ) const; + + /// Check if a model search is specified. + /** + \return A boolean equal to \c true if a model search is defined. + */ + bool has_model_search ( void ) const; + + /// Access to the \c MODEL_SEARCH parameter. + /** + \param i Index of the model search (1 or 2) -- \b IN. + \return The \c MODEL_SEARCH parameter. + */ + NOMAD::model_type get_model_search ( int i ) const; + + /// Access to the \c MODEL_SEARCH_OPTIMISTIC parameter. + /** + \return The \c MODEL_SEARCH_OPTIMISTIC parameter. + */ + bool get_model_search_optimistic ( void ) const; + + /// Access to the \c MODEL_SEARCH_PROJ_TO_MESH parameter. + /** + \return The \c MODEL_SEARCH_PROJ_TO_MESH parameter. + */ + bool get_model_search_proj_to_mesh ( void ) const; + + /// Access to the \c MODEL_QUAD_RADIUS_FACTOR parameter. + /** + \return The \c MODEL_QUAD_RADIUS_FACTOR parameter. + */ + const NOMAD::Double & get_model_quad_radius_factor ( void ) const; + + /// Access to the \c MODEL_NP1_QUAD_EPSILON parameter. + /** + \return The \c MODEL_NP1_QUAD_EPSILON parameter. + */ + const NOMAD::Double & get_model_np1_quad_epsilon ( void ) const; + + + /// Access to the \c MODEL_QUAD_USE_WP parameter. + /** + \return The \c MODEL_QUAD_USE_WP parameter. + */ + bool get_model_quad_use_WP ( void ) const; + + /// Access to the \c MODEL_QUAD_MAX_Y_SIZE parameter. + /** + \return The \c MODEL_QUAD_MAX_Y_SIZE parameter. + */ + int get_model_quad_max_Y_size ( void ) const; + + /// Access to the \c MODEL_QUAD_MIN_Y_SIZE parameter. + /** + \return The \c MODEL_QUAD_MIN_Y_SIZE parameter. + */ + int get_model_quad_min_Y_size ( void ) const; + + /// Access to the \c MODEL_TGP_MODE parameter. + /** + \return The \c MODEL_TGP_MODE parameter. + */ + NOMAD::TGP_mode_type get_model_tgp_mode ( void ) const; + + /// Access to the \c MODEL_TGP_REUSE_MODEL parameter. + /** + \return The \c MODEL_TGP_REUSE_MODEL parameter. + */ + bool get_model_tgp_reuse_model ( void ) const; + + /// Access to the \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. + /** + \return The \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. + */ + int get_model_search_max_trial_pts ( void ) const; + + /// Access to the \c MODEL_EVAL_SORT parameter. + /** + \return The \c MODEL_EVAL_SORT parameter. + */ + NOMAD::model_type get_model_eval_sort ( void ) const; + + /// Access to the \c MODEL_EVAL_SORT_CAUTIOUS parameter. + /** + \return The \c MODEL_EVAL_SORT_CAUTIOUS parameter. + */ + bool get_model_eval_sort_cautious ( void ) const; + + + /// Access to all the models parameters. + /** + \param mp The models parameters -- \b OUT. + */ + void get_model_parameters ( NOMAD::model_params_type & mp ) const; + + /// Access to the \c VNS_SEARCH parameter. + /** + \return The \c VNS_SEARCH parameter. + */ + bool get_VNS_search ( void ) const; + + /// Access to the VNS trigger. + /** + \return The VNS trigger. + */ + const NOMAD::Double & get_VNS_trigger ( void ) const; + + /// Access to the number of initial LH search points. + /** + \return The number of initial LH search points. + */ + int get_LH_search_p0 ( void ) const; + + /// Access to the number of LH search points at each iteration. + /** + \return The number of LH search points at each iteration. + */ + int get_LH_search_pi ( void ) const; + + /// Access to the \c OPPORTUNISTIC_LH parameter. + /** + \return The \c OPPORTUNISTIC_LH parameter. + */ + bool get_opportunistic_LH ( void ) const; + + /// Access to the \c CACHE_SEARCH parameter. + /** + \return The \c CACHE_SEARCH parameter. + */ + bool get_cache_search ( void ) const; + + /// Access to the \c OPPORTUNISTIC_CACHE_SEARCH parameter. + /** + \return The \c OPPORTUNISTIC_CACHE_SEARCH parameter. + */ + bool get_opportunistic_cache_search ( void ) const; + + /// Set the \c SPECULATIVE_SEARCH parameter. + /** + \param ss The \c SPECULATIVE_SEARCH parameter -- \b IN. + */ + void set_SPECULATIVE_SEARCH ( bool ss ); + + /// Disable use of models. + /** + */ + void set_DISABLE_MODELS ( void ); + + /// Disable use of sort (lexicographic order used). + /** + */ + void set_DISABLE_EVAL_SORT ( void ); + + /// Set all the models parameters. + /** + \param mp The models parameters -- \b IN. + */ + void set_model_parameters ( const NOMAD::model_params_type & mp ); + + /// Set the \c MODEL_SEARCH parameter (1/3). + /** + \param i Index of the model search (1 or 2) -- \b IN. + \param ms The \c MODEL_SEARCH parameter -- \b IN. + */ + void set_MODEL_SEARCH ( int i , NOMAD::model_type ms ); + + /// Set the \c MODEL_SEARCH parameter (2/3). + /** + \param ms The \c MODEL_SEARCH parameter -- \b IN. + */ + void set_MODEL_SEARCH ( bool ms ); + + /// Set the \c MODEL_SEARCH parameter (3/3). + /** + \param mod_type The \c MODEL_SEARCH parameter -- \b IN. + */ + void set_MODEL_SEARCH ( NOMAD::model_type mod_type ); + + /// Set the \c MODEL_SEARCH_OPTIMISTIC parameter. + /** + \param mso The \c MODEL_SEARCH_OPTIMISTIC parameter -- \b IN. + */ + void set_MODEL_SEARCH_OPTIMISTIC ( bool mso ); + + /// Set the \c MODEL_SEARCH_PROJ_TO_MESH parameter. + /** + \param ptm The \c MODEL_SEARCH_PROJ_TO_MESH parameter -- \b IN. + */ + void set_MODEL_SEARCH_PROJ_TO_MESH ( bool ptm ); + + /// Set the \c MODEL_QUAD_RADIUS_FACTOR parameter. + /** + \param r The \c MODEL_QUAD_RADIUS_FACTOR parameter -- \b IN. + */ + void set_MODEL_QUAD_RADIUS_FACTOR ( const NOMAD::Double & r ); + + /// Set the \c MODEL_QUAD_USE_WP parameter. + /** + \param uwp The \c MODEL_QUAD_USE_WP parameter -- \b IN. + */ + void set_MODEL_QUAD_USE_WP ( bool uwp ); + + /// Set the \c MODEL_QUAD_MAX_Y_SIZE parameter. + /** + \param s The \c MODEL_QUAD_MAX_Y_SIZE parameter -- \b IN. + */ + void set_MODEL_QUAD_MAX_Y_SIZE ( int s ); + + /// Set the \c MODEL_QUAD_MIN_Y_SIZE parameter. + /** + \param s The \c MODEL_QUAD_MIN_Y_SIZE parameter -- \b IN. + */ + void set_MODEL_QUAD_MIN_Y_SIZE ( int s ); + + /// Set the \c MODEL_NP1_QUAD_EPSILON parameter. + /** + \param r The \c MODEL_NP1_QUAD_EPSILON parameter -- \b IN. + */ + void set_MODEL_NP1_QUAD_EPSILON ( const NOMAD::Double & r ); + + /// Set the \c MODEL_TGP_MODE parameter. + /** + \param m The \c MODEL_TGP_MODE parameter -- \b IN. + */ + void set_MODEL_TGP_MODE ( NOMAD::TGP_mode_type m ); + + /// Set the \c MODEL_TGP_REUSE_MODEL parameter. + /** + \param rm The \c MODEL_TGP_REUSE_MODEL parameter -- \b IN. + */ + void set_MODEL_TGP_REUSE_MODEL ( bool rm ); + + /// Set the \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. + /** + \param s The \c MODEL_SEARCH_MAX_TRIAL_PTS parameter -- \b IN. + */ + void set_MODEL_SEARCH_MAX_TRIAL_PTS ( int s ); + + /// Set the \c MODEL_EVAL_SORT parameter (1/2). + /** + \param mes The \c MODEL_EVAL_SORT parameter -- \b IN. + */ + void set_MODEL_EVAL_SORT ( NOMAD::model_type mes ); + + /// Set the \c MODEL_EVAL_SORT parameter (2/2). + /** + \param mes The \c MODEL_EVAL_SORT parameter -- \b IN. + */ + void set_MODEL_EVAL_SORT ( bool mes ); + + + /// Set the \c MODEL_EVAL_SORT_CAUTIOUS parameter. + /** + \param mesc The \c MODEL_EVAL_SORT_CAUTIOUS parameter -- \b IN. + */ + void set_MODEL_EVAL_SORT_CAUTIOUS ( bool mesc ); + + /// Set the \c VNS_SEARCH parameter. + /** + \param vns The \c VNS_SEARCH parameter -- \b IN. + */ + void set_VNS_SEARCH ( bool vns ); + + /// Set the \c VNS_SEARCH parameter. + /** + \param trigger The VNS trigger -- \b IN. + */ + void set_VNS_SEARCH ( const NOMAD::Double & trigger ); + + /// Set the \c LH_SEARCH parameter. + /** + \param p0 Number of initial LH search points -- \b IN. + \param pi LH search points at each iteration -- \b IN. + */ + void set_LH_SEARCH ( int p0 , int pi ); + + /// Set the \c OPPORTUNISTIC_LH parameter. + /** + \param olh The \c OPPORTUNISTIC_LH parameter -- \b IN. + */ + void set_OPPORTUNISTIC_LH ( bool olh ); + + /// Set the \c CACHE_SEARCH parameter. + /** + \param cs The \c CACHE_SEARCH parameter -- \b IN. + */ + void set_CACHE_SEARCH ( bool cs ); + + /// Set the \c OPPORTUNISTIC_CACHE_SEARCH parameter. + /** + \param ocs The \c OPPORTUNISTIC_CACHE_SEARCH parameter -- \b IN. + */ + void set_OPPORTUNISTIC_CACHE_SEARCH ( bool ocs ); + + // Mesh: + // ----- + private: + + bool _use_smesh; ///< Use smesh (default xmesh) + bool _anisotropic_mesh; ///< Anisotropic mesh (xmesh only, i.e. _use_smesh=false) + NOMAD::Double _mesh_update_basis; ///< Mesh update basis (tau). + NOMAD::Double _poll_update_basis; ///< Poll update basis (beta). + int _mesh_coarsening_exponent; ///< Mesh coarsening exponent. + int _mesh_refining_exponent; ///< Mesh refining exponent. + int _initial_mesh_index; ///< Initial mesh index (ell_0). + NOMAD::Point _initial_mesh_size; ///< Initial (absolute) mesh size (delta^0). + NOMAD::Point _min_mesh_size; ///< Minimal (absolute) mesh size (delta_min). + NOMAD::Point _initial_poll_size; ///< Initial (absolute) poll size (delta^0). + NOMAD::Point _min_poll_size; ///< Minimal (absolute) poll size (Delta_min). + + bool _min_poll_size_defined; ///< \c true if _min_poll_size is user-defined. + + public: + + /// Access to the \c ANISOTROPIC_MESH parameter. + /** + \return The \c ANISOTROPIC_MESH parameter -- \b IN. + */ + bool get_anisotropic_mesh ( void ) const; + + /// Access to the \c USE_SMESH parameter. + /** + \return The \c USE_SMESH parameter -- \b IN. + */ + bool get_use_smesh ( void ) const; + + + + /// Access to the \c POLL_UPDATE_BASIS parameter. + /** + \return The \c POLL_UPDATE_BASIS parameter. + */ + const NOMAD::Double & get_poll_update_basis ( void ) const; + + + /// Access to the \c MESH_UPDATE_BASIS parameter. + /** + \return The \c MESH_UPDATE_BASIS parameter. + */ + const NOMAD::Double & get_mesh_update_basis ( void ) const; + + /// Access to the \c MESH_COARSENING_EXPONENT parameter. + /** + \return The \c MESH_COARSENING_EXPONENT parameter. + */ + int get_mesh_coarsening_exponent ( void ) const; + + /// Access to the \c MESH_REFINING_EXPONENT parameter. + /** + \return The \c MESH_REFINING_EXPONENT parameter. + */ + int get_mesh_refining_exponent ( void ) const; + + /// Access to the \c INITIAL_MESH_INDEX parameter. + /** + \return The \c INITIAL_MESH_INDEX parameter. + */ + int get_initial_mesh_index ( void ) const; + + + /// Access to the \c INITIAL_MESH_SIZE parameter. + /** + \return The \c INITIAL_MESH_SIZE parameter. + */ + const NOMAD::Point & get_initial_mesh_size ( void ) const; + + /// Access to the \c INITIAL_POLL_SIZE parameter. + /** + \return The \c INITIAL_POLL_SIZE parameter. + */ + const NOMAD::Point & get_initial_poll_size ( void ) const; + + /// Access to the \c MIN_MESH_SIZE parameter. + /** + \return The \c MIN_MESH_SIZE parameter. + */ + const NOMAD::Point & get_min_mesh_size ( void ) const; + + /// Access to the \c MIN_POLL_SIZE parameter. + /** + \return The \c MIN_POLL_SIZE parameter. + */ + const NOMAD::Point & get_min_poll_size ( void ) const; + + /// Access to \c _min_poll_size_defined. + /** + \return A boolean equal to \c true if the \c MIN_POLL_SIZE parameter + has been user-defined. + */ + bool get_min_poll_size_defined ( void ) const; + + /// Set the \c ANISOTROPIC_MESH parameter. + /** + \param anis The \c ANISOTROPIC_MESH parameter -- \b IN. + */ + void set_ANISOTROPIC_MESH ( bool anis ); + + /// Set the \c USE_SMESH parameter. + /** + \param use_smesh The \c USE_SMESH parameter -- \b IN. + */ + void set_USE_SMESH ( bool use_smesh ); + + + /// Set the \c MESH_UPDATE_BASIS parameter. + /** + \param tau The \c MESH_UPDATE_BASIS parameter -- \b IN. + */ + void set_MESH_UPDATE_BASIS ( const NOMAD::Double & tau ); + + /// Set the \c POLL_UPDATE_BASIS parameter. + /** + \param r The \c POLL_UPDATE_BASIS parameter -- \b IN. + */ + void set_POLL_UPDATE_BASIS ( const NOMAD::Double & r ); + + + /// Set the \c INITIAL_MESH_INDEX parameter. + /** + \param ell_0 The \c INITIAL_MESH_INDEX parameter -- \b IN. + */ + void set_INITIAL_MESH_INDEX ( int ell_0 ); + + /// Set the \c MESH_REFINING_EXPONENT parameter. + /** + \param mre The \c MESH_REFINING_EXPONENT parameter -- \b IN. + */ + void set_MESH_REFINING_EXPONENT ( int mre ); + + /// Set the \c MESH_COARSENING_EXPONENT parameter. + /** + \param mce The \c MESH_COARSENING_EXPONENT parameter -- \b IN. + */ + void set_MESH_COARSENING_EXPONENT ( int mce ); + + /// Set the \c MIN_MESH_SIZE parameter. + /** + \param mms Minimum mesh size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_MESH_SIZE ( const NOMAD::Double & mms , bool relative = false ); + + /// Set the \c MIN_MESH_SIZE parameter. + /** + \param index Index of a variable -- \b IN. + \param mms Minimum mesh size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_MESH_SIZE ( int index , + const NOMAD::Double & mms , + bool relative = false ); + + /// Set the \c MIN_MESH_SIZE parameter. + /** + \param mms Minimum mesh size -- \b IN. + \param relative Indicated as relative values + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_MESH_SIZE ( const NOMAD::Point & mms , bool relative = false ); + + /// Set the \c MIN_POLL_SIZE parameter. + /** + \param mps Minimum poll size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_POLL_SIZE ( const NOMAD::Double & mps , bool relative = false ); + + /// Set the \c MIN_POLL_SIZE parameter. + /** + \param index Index of a variable -- \b IN. + \param mps Minimum poll size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_POLL_SIZE ( int index , + const NOMAD::Double & mps , + bool relative = false ); + + /// Set the \c MIN_POLL_SIZE parameter. + /** + \param mps Minimum poll size -- \b IN. + \param relative Indicated as relative values + -- \b IN -- \b optional (default = \c false). + */ + void set_MIN_POLL_SIZE ( const NOMAD::Point & mps , bool relative = false ); + + /// Set the \c INITIAL_MESH_SIZE parameter. + /** + \param ims Initial mesh size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_MESH_SIZE ( const NOMAD::Double & ims , bool relative = false ); + + /// Set the \c INITIAL_MESH_SIZE parameter. + /** + \param index Index of a variable -- \b IN. + \param ims Initial mesh size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_MESH_SIZE ( int index , + const NOMAD::Double & ims , + bool relative = false ); + + /// Set the \c INITIAL_MESH_SIZE parameter. + /** + \param ims Initial mesh size -- \b IN. + \param relative Indicated as relative values + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_MESH_SIZE ( const NOMAD::Point & ims , bool relative = false ); + + + /// Set the \c INITIAL_POLL_SIZE parameter. + /** + \param ims Initial poll size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_POLL_SIZE ( const NOMAD::Double & ims , bool relative = false ); + + /// Set the \c INITIAL_POLL_SIZE parameter. + /** + \param index Index of a variable -- \b IN. + \param ims Initial poll size -- \b IN. + \param relative Indicated as a relative value + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_POLL_SIZE ( int index , + const NOMAD::Double & ims , + bool relative = false ); + + /// Set the \c INITIAL_POLL_SIZE parameter. + /** + \param ims Initial poll size -- \b IN. + \param relative Indicated as relative values + -- \b IN -- \b optional (default = \c false). + */ + void set_INITIAL_POLL_SIZE ( const NOMAD::Point & ims , bool relative = false ); + + + + // Directions: + // ----------- + private: + + /// Types of poll directions. + std::set<NOMAD::direction_type> _direction_types; + + /// Types of directions for the secondary poll. + std::set<NOMAD::direction_type> _sec_poll_dir_types; + + /// Change direction types to prevent using models for finding the (n+1)th direction + /// Apply if ORTHO N+1 QUAD -> ORTHO N+1 NEG. + void set_DIRECTION_TYPE_NO_MODEL ( void ); + + + public: + + /// Access to the list of poll direction types. + /** + \return The list of poll direction types. + */ + const std::set<NOMAD::direction_type> & get_direction_types ( void ) const; + + /// Access to the list of secondary poll direction types. + /** + \return The list of secondary poll direction types. + */ + const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const; + + + /// Check if there are Ortho-MADS directions. + /** + \return A boolean equal to \c true if there is at least one + Ortho-MADS direction in the list of poll directions + or in the list of secondary poll directions. + */ + bool has_orthomads_directions ( void ) const; + + + /// Check if a direction type that required dynamic completion for the (n+1)th direction. + /** + \return true if a dynamic completion is required. + */ + bool has_dynamic_direction(void) const; + + + /// Reset the directions. + void reset_directions ( void ); + + + /// Add a new direction type. + /** + \param dt The new direction type -- \b IN. + */ + void set_DIRECTION_TYPE ( NOMAD::direction_type dt ); + + /// Add a set of new direction types. + /** + \param dt The set of new direction types -- \b IN. + */ + void set_DIRECTION_TYPE ( const std::set<NOMAD::direction_type> & dt ); + + + /// Add a new direction type for the secondary poll. + /** + \param dt The new direction type -- \b IN. + */ + void set_SEC_POLL_DIR_TYPE ( NOMAD::direction_type dt ); + + /// Add a set of new direction types for the secondary poll. + /** + \param dt The set of new direction types -- \b IN. + */ + void set_SEC_POLL_DIR_TYPE ( const std::set<NOMAD::direction_type> & dt ); + + /// Enables use of quad model to determine prospect direction + /// for Ortho n+1 direction type + /** + \param qmpd boolean -- \b IN. + */ + void set_QUAD_MODEL_PROSPECT_DIR ( bool qmpd ) ; + + // Starting point(s): + // ------------------ + private: + + std::vector<NOMAD::Point *> _x0s; ///< List of starting points. + std::string _x0_cache_file; ///< Cache file containing starting points. + + public: + + /// Add a new point in the list of starting points. + /** + \param x0 The new point -- \b IN. + */ + void set_X0 ( const NOMAD::Point & x0 ); + + /// Indicate a cache file containing starting points. + /** + \param file_name Name of the cache file -- \b IN. + */ + void set_X0 ( const std::string & file_name ); + + /// Reset all string points. + void reset_X0 ( void ); + + /// Access to the list of starting points. + /** + \return The list of starting points. + */ + const std::vector<NOMAD::Point *> & get_x0s ( void ) const; + + /// Access to the name of a cache file containing starting points. + /** + \return The file name. + */ + const std::string & get_x0_cache_file ( void ) const; + + // Signature: standard or extern (only one is != NULL): + // ---------------------------------------------------- + private: + + /// Standard signature. + /** + Created and deleted by the Parameters class. + */ + NOMAD::Signature * _std_signature; + + /// Extern signature. + /** + Created and deleted outside the class. + */ + NOMAD::Signature * _extern_signature; + + public: + + /// Access to the signature. + /** + \return The one non-NULL signature. + */ + NOMAD::Signature * get_signature ( void ) const; + + /// Set a new extern signature. + /** + Deletes the standard signature. + \param s A pointer to the extern signature -- \b IN. + */ + void set_EXTERN_SIGNATURE ( NOMAD::Signature * s ); + + // Dimension: + // ---------- + private: + + /// Dimension. + /** + - Number of variables. + - Parameter \c DIMENSION. + */ + int _dimension; + + public: + + /// Access to the dimension. + /** + \return The dimension. + */ + int get_dimension ( void ) const; + + /// Set the dimension. + /** + \param n The dimension -- \b IN. + \return \c true if the operation succeeded. + */ + bool set_DIMENSION ( int n ); + + // Fixed variables: + // ---------------- + private: + + /// Fixed variables. + /** + - This point is of dimension \c n (parameter \c DIMENSION). + - Undefined values correspond to free variables. + */ + NOMAD::Point _fixed_variables; + + /// Number of free variables. + int _nb_free_variables; + + public: + + /// Access to the number of free variables. + /** + \return The number of free variables. + */ + int get_nb_free_variables ( void ) const; + + /// Access to the fixed variables. + /** + \return The fixed variables. + */ + const NOMAD::Point & get_fixed_variable ( void ) const + { + return get_fixed_variables(); + } + + /// Access to the fixed variables. + /** + \return The fixed variables. + */ + const NOMAD::Point & get_fixed_variables ( void ) const; + + /// Test if a variable is fixed. + /** + \param i Index of the variable -- \b IN. + \return A boolean equal to \c true if the variable \c i is fixed. + */ + bool variable_is_fixed ( int i ) const; + + /// Reset the fixed variables. + /** + This frees all the variables. + */ + void reset_fixed_variables ( void ); + + /// Fix one variable. + /** + \param i Index of the variable -- \b IN. + \param value Value of the fixed variable -- \b IN. + */ + void set_FIXED_VARIABLE ( int i , const NOMAD::Double & value ); + + /// Fix one variable. + /** + The value of the variable is based on the starting point. + \param i Index of the variable -- \b IN. + */ + void set_FIXED_VARIABLE ( int i ); + + /// Fix a series of variables. + /** + \param fv The fixed variables; This point is of dimension \c n; + free variables correspond to undefined values -- \b IN. + */ + void set_FIXED_VARIABLE ( const NOMAD::Point & fv ); + + /// Free a variable. + /** + \param i Index of the variable -- \b IN. + */ + void set_FREE_VARIABLE ( int i ) { set_FIXED_VARIABLE ( i , NOMAD::Double() ); } + + // Periodic variables: + // ------------------- + + /// Periodic variables. + /** + - This vector is of size \c n. + - \c _periodic_variables[i] is equal to \c true if + the variable \c i is periodic. + */ + std::vector<bool> _periodic_variables; + + /// Access to the periodic variables. + /** + \return The periodic variables + */ + const std::vector<bool> & get_periodic_variable ( void ) const + { + return get_periodic_variables(); + } + + /// Access to the periodic variables. + /** + \return The periodic variables + */ + const std::vector<bool> & get_periodic_variables ( void ) const; + + /// Check if there is periodic variables. + /** + \return A boolean equal to \c true if there is periodic variables. + */ + bool has_periodic_variables ( void ) const + { + return !_periodic_variables.empty(); + } + + /// Reset periodic variables. + void reset_periodic_variables ( void ); + + /// Set one variable to be periodic. + /** + \param i Index of the variable -- \b IN. + */ + void set_PERIODIC_VARIABLE ( int i ); + + /// Set a series of variables to be periodic. + /** + \param pv Vector of size \c n indicating the + periodic variables -- \b IN. + */ + void set_PERIODIC_VARIABLE ( const std::vector<bool> & pv ); + + // Categorical variables: + // ---------------------- + private: + + /// Extended poll trigger. + /** + - Must be strictly positive. + - May be relative. + */ + NOMAD::Double _extended_poll_trigger; + + /// Equal to \c true if the extended poll trigger is relative. + bool _relative_ept; + + /// Equal to \c true if the extended poll is enabled. + bool _extended_poll_enabled; + + /// Neighborhood executable for using batch mode with categorical variables. + std::string _neighbors_exe; + + public: + + /// Access to the extended poll trigger. + /** + \return The extended poll trigger. + */ + const NOMAD::Double & get_extended_poll_trigger ( void ) const; + + /// Check if the extended poll trigger is relative. + /** + \return A boolean equal to \c true if the extended poll trigger is relative. + */ + bool get_relative_ept ( void ) const; + + /// Check if the extended poll is enabled. + /** + \return A boolean equal to \c true if the extended poll is enabled. + */ + bool get_extended_poll_enabled ( void ) const; + + /// Access to the neighborhood executable. + /** + \return The neighborhood executable. + */ + const std::string & get_neighbors_exe ( void ) const; + + /// Set the extended poll trigger. + /** + \param ept The extended poll trigger -- \b IN. + \param rel A boolean equal to \c true if the extended poll + trigger is relative -- \b IN. + */ + void set_EXTENDED_POLL_TRIGGER ( const NOMAD::Double & ept , bool rel ); + + /// Enable or disable the extended poll. + /** + \param epe A boolean equal to \c true if the extended poll is enabled -- \b IN. + */ + void set_EXTENDED_POLL_ENABLED ( bool epe ); + + /// Set the neighborhood executable. + /** + \param ne The neighborhood executable. + */ + void set_NEIGHBORS_EXE ( const std::string & ne ); + + // Groups of variables: + // -------------------- + private: + + /// Groups of variables. + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> _var_groups; + + /// User groups of variables. + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> _user_var_groups; + + /// Reset a group of variables. + /** + \param g Group to reset; may be \c _var_groups or \c _user_var_groups + -- \b IN/OUT. + */ + void reset_variable_groups + ( std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & g ) const; + + public: + + /// Reset groups of variables. + void reset_variable_groups ( void ); + + /// Access to the groups of variables. + /** + \return The groups of variables. + */ + const std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & + get_variable_groups ( void ) const; + + /// Set one group of variables. + /** + Basic version. + \param var_indexes Indexes of the variables of the group -- \b IN. + */ + void set_VARIABLE_GROUP ( const std::set<int> & var_indexes ); + + /// Set one group of variables. + /** + Advanced version. + \param var_indexes Indexes of the variables of the group -- \b IN. + \param prim_poll_dir_types Types of the poll directions -- \b IN. + \param sec_poll_dir_types Types of the secondary poll directions -- \b IN. + */ + void set_VARIABLE_GROUP + ( const std::set<int> & var_indexes , + const std::set<NOMAD::direction_type> & prim_poll_dir_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types ); + + /// Set several groups of variables. + /** + \param vg A list of groups of variables -- \b IN. + */ + void set_VARIABLE_GROUP ( const std::list<NOMAD::Variable_Group*> & vg ); + + // Bounds and scaling: + // ------------------- + private: + + NOMAD::Point _lb; ///< Lower bounds. + NOMAD::Point _ub; ///< Upper bounds. + NOMAD::Point _scaling; ///< Scaling. + + public: + + /// Access to the lower bounds. + /** + \return The lower bounds. + */ + const NOMAD::Point & get_lb ( void ) const; + + /// Access to the upper bounds. + /** + \return The upper bounds. + */ + const NOMAD::Point & get_ub ( void ) const; + + /// Access to the lower bounds. + /** + \return The lower bounds. + */ + const NOMAD::Point & get_lower_bound ( void ) const { return get_lb(); } + + /// Access to the upper bounds. + /** + \return The upper bounds. + */ + const NOMAD::Point & get_upper_bound ( void ) const { return get_ub(); } + + /// Access to the scaling. + /** + \return The scaling. + */ + const NOMAD::Point & get_scaling ( void ) const; + + /// Reset the bounds. + void reset_bounds ( void ); + + /// Reset the scaling. + void reset_scaling ( void ); + + /// Set one lower bound. + /** + \param i Index of the variable -- \b IN. + \param lb Lower bound -- \b IN. + */ + void set_LOWER_BOUND ( int i , const NOMAD::Double & lb ); + + /// Set all lower bounds. + /** + Use undefined values for variables without bounds. + \param lb Lower bounds -- \b IN. + */ + void set_LOWER_BOUND ( const NOMAD::Point & lb ); + + /// Set one upper bound. + /** + \param i Index of the variable -- \b IN. + \param ub Upper bound -- \b IN. + */ + void set_UPPER_BOUND ( int i , const NOMAD::Double & ub ); + + /// Set all upper bounds. + /** + Use undefined values for variables without bounds. + \param ub Upper bounds -- \b IN. + */ + void set_UPPER_BOUND ( const NOMAD::Point & ub ); + + /// Set the scaling of one variable. + /** + \param i Index of the variable -- \b IN. + \param s Scaling -- \b IN. + */ + void set_SCALING ( int i , const NOMAD::Double & s ); + + /// Set the scaling for all variables. + /** + Use undefined values for variables scaling. + \param s Scaling -- \b IN. + */ + void set_SCALING ( const NOMAD::Point & s ); + + // Blackboxes (inputs and outputs): + // -------------------------------- + private: + + /// Blackbox input types. + std::vector<NOMAD::bb_input_type> _bb_input_type; + + /// Parameter \c BB_INPUT_INCLUDE_TAG. + bool _bb_input_include_tag; + + /// Parameter \c BB_INPUT_INCLUDE_SEED. + bool _bb_input_include_seed; + + /// Blackbox output types. + /** + May be modified during the algorithm (PEB constraints). + */ + mutable std::vector<NOMAD::bb_output_type> _bb_output_type; + + /// List of blackbox executables. + std::list<std::string> _bb_exe; + + /// List of objective indexes. + std::list<int> _index_obj; + + /// Index for the output \c STAT_SUM. + int _index_stat_sum; + + /// Index for the output \c STAT_AVG. + int _index_stat_avg; + + /// Index for the output \c CNT_EVAL. + /** + - \c 0 or \c 1. + - \c CNT_EVAL indicates if a blackbox evaluation has to be counted. + */ + int _index_cnt_eval; + + /// Parameter \c BB_REDIRECTION. + bool _bb_redirection; + + public: + + /// Access to the number of blackbox outputs. + /** + \return The number of blackbox outputs. + */ + int get_bb_nb_outputs ( void ) const; + + /// Access to the \c BB_INPUT_INCLUDE_TAG parameter. + /** + \return The \c BB_INPUT_INCLUDE_TAG parameter. + */ + bool get_bb_input_include_tag ( void ) const; + + /// Access to the \c BB_INPUT_INCLUDE_SEED parameter. + /** + \return The \c BB_INPUT_INCLUDE_SEED parameter. + */ + bool get_bb_input_include_seed ( void ) const; + + /// Access to the blackbox input types. + /** + \return The blackbox input types. + */ + const std::vector<NOMAD::bb_input_type> & get_bb_input_type ( void ) const; + + /// Access to the blackbox output types. + /** + \return The blackbox output types. + */ + const std::vector<NOMAD::bb_output_type> & get_bb_output_type ( void ) const; + + /// Access to the objective indexes. + /** + \return The list of objective indexes. + */ + const std::list<int> & get_index_obj ( void ) const; + + /// Access to the number of objective functions. + /** + \return The number of objective functions. + */ + int get_nb_obj ( void ) const; + + /// Check the display and file stats. + /** + \param stats The stats -- \b IN. + \return A booleam equal to \c true if the stats are valid. + */ + bool check_display_stats ( const std::list<std::string> & stats ) const; + + /// Check if there is a \c STAT_SUM output. + /** + \return A boolean equal to \c true if there a \c STAT_SUM output. + */ + bool check_stat_sum ( void ) const; + + /// Check if there is a \c STAT_AVG output. + /** + \return A boolean equal to \c true if there is a \c STAT_AVG output. + */ + bool check_stat_avg ( void ) const; + + /// Access the index of output \c CNT_EVAL output. + /** + \return Index of the \c CNT_EVAL output. + \return \c -1 if there is no \c CNT_EVAL output. + */ + int get_index_cnt_eval ( void ) const; + + /// Access the index of output \c STAT_SUM output. + /** + \return Index of the \c STAT_SUM output. + \return \c -1 if there is no \c STAT_SUM output. + */ + int get_index_stat_sum ( void ) const; + + /// Access the index of output \c STAT_AVG output. + /** + \return Index of the \c STAT_AVG output. + \return \c -1 if there is no \c STAT_AVG output. + */ + int get_index_stat_avg ( void ) const; + + /// Access to the list of blackbox executables. + /** + \return The list of blackbox executables. + */ + const std::list<std::string> & get_bb_exe ( void ) const; + + /// Access to the \c BB_REDIRECTION parameter. + /** + \return The \c BB_REDIRECTION parameter. + */ + bool get_bb_redirection ( void ) const; + + /// Set the \c BB_INPUT_INCLUDE_TAG parameter. + /** + \param bbiit The \c BB_INPUT_INCLUDE_TAG parameter -- \b IN. + */ + void set_BB_INPUT_INCLUDE_TAG ( bool bbiit ); + + /// Set the \c BB_INPUT_INCLUDE_SEED parameter. + /** + \param bbiis The \c BB_INPUT_INCLUDE_SEED parameter -- \b IN. + */ + void set_BB_INPUT_INCLUDE_SEED ( bool bbiis ); + + /// Set the blackbox input type of one variable. + /** + \param index Index of the variable -- \b IN. + \param bbit Type of the variable -- \b IN. + */ + void set_BB_INPUT_TYPE ( int index , NOMAD::bb_input_type bbit ); + + /// Set the blackbox input types of all variables. + /** + \param bbit Types of the variables -- \b IN. + */ + void set_BB_INPUT_TYPE ( const std::vector<NOMAD::bb_input_type> & bbit ); + + /// Set the blackbox input types of all variables. + /** + \param bbit Types of the variables -- \b IN. + */ + void set_BB_INPUT_TYPE ( const std::list<NOMAD::bb_input_type> & bbit ); + + /// Set the blackbox output types. + /** + \param bbot Blackbox output types -- \b IN. + */ + void set_BB_OUTPUT_TYPE ( const std::list<NOMAD::bb_output_type> & bbot ); + + /// Set the blackbox output types. + /** + \param bbot Blackbox output types -- \b IN. + */ + void set_BB_OUTPUT_TYPE ( const std::vector<NOMAD::bb_output_type> & bbot ); + + /// Set a list of blackbox executable names. + /** + Must correspond to the blackbox output types. + \param bbexe The list of blackbox executable names -- \b IN. + */ + void set_BB_EXE ( const std::list<std::string> & bbexe ); + + /// Set a list of blackbox executable names. + /** + \param m Number of blackbox outputs and size of \c bbexe -- \b IN. + \param bbexe The list of blackbox executable names -- \b IN. + */ + void set_BB_EXE ( int m , const std::string * bbexe ); + + /// Set a unique blackbox executable name. + /** + \param bbexe The blackbox executable name -- \b IN. + */ + void set_BB_EXE ( const std::string & bbexe ); + + /// Set the \c BB_REDIRECTION parameter. + /** + \param bbr The \c BB_REDIRECTION parameter -- \b IN. + */ + void set_BB_REDIRECTION ( bool bbr ); + + /// Reset the PEB statuses. + /** + Set all outputs at NOMAD::PEB_E (PEB constraint in "extreme" status) + to NOMAD::PEB_P (PEB constraint in "progressive" status). + */ + void reset_PEB_changes ( void ) const; + + /// Change constraints from PEB to PB. + /** + Set all outputs at NOMAD::PEB to NOMAD::PB + */ + void change_PEB_to_PB ( void ); + + /// Change the status of one PEB constraint. + /** + The status is changed from + NOMAD::PEB_P (PEB constraint in "progressive" status) + to NOMAD::PEB_E (PEB constraint in "extreme" status). + \param index Index of the PEB constraint. + */ + void change_PEB_constraint_status ( int index ) const; + + // Surrogates: + // ----------- + private: + + /// Surrogate executables. + /** + \c _sgte_exe[bb_exe] corresponds to the surrogate associated + with the blackbox true executable \c bb_exe. + */ + std::map<std::string,std::string> _sgte_exe; + + bool _disable_eval_sort; ///< Sort disablement + + /// Flag equal to \c true if surrogates are used to sort evaluation points. + bool _sgte_eval_sort; + + /// Flag equal to \c true if the problem has a surrogate. + bool _has_sgte; + + /// Flag equal to \c true if NOMAD considers only surrogates. + bool _opt_only_sgte; + + /// Surrogate cost. + /** + Number of surrogate evaluations counting as one blackbox evaluation. + */ + int _sgte_cost; + + /// Maximum number of surrogate evaluations. + int _sgte_max_eval; + + /// Surrogate cache file. + std::string _sgte_cache_file; + + public: + + /// Access to the surrogate associated with a truth executable. + /** + \param bb_exe The truth executable -- \b IN. + \return The surrogate executable name. + \return An empty string if \c bb_exe has no surrogate. + */ + std::string get_sgte_exe ( const std::string & bb_exe ) const; + + /// Access to the \c SGTE_EVAL_SORT parameter. + /** + \return The \c SGTE_EVAL_SORT parameter. + */ + bool get_sgte_eval_sort ( void ) const; + + /// Access to the \c SGTE_COST parameter. + /** + \return The \c SGTE_COST parameter. + */ + int get_sgte_cost ( void ) const; + + /// Access to the \c MAX_SGTE_EVAL parameter. + /** + \return The \c MAX_SGTE_EVAL parameter. + */ + int get_max_sgte_eval ( void ) const; + + /// Access to the \c SGTE_CACHE_FILE parameter. + /** + \return The \c SGTE_CACHE_FILE parameter. + */ + const std::string & get_sgte_cache_file ( void ) const; + + /// Access to the \c HAS_SGTEparameter. + /** + \return The \c HAS_SGTEparameter. + */ + bool has_sgte ( void ) const; + + /// Access to the \c OPT_ONLY_SGTE parameter. + /** + \return The \c OPT_ONLY_SGTE parameter. + */ + bool get_opt_only_sgte ( void ) const; + + /// Check if a surrogate executable has been defined. + /** + \return A boolean equal to \c true if + a surrogate executable has been defined. + */ + bool has_sgte_exe ( void ) const; + + /// Set the \c SGTE_EXE parameter. + /** + \param bb_exe Truth executable -- \b IN. + \param sgte_exe Associated surrogate executable -- \b IN. + */ + void set_SGTE_EXE ( const std::string & bb_exe , const std::string & sgte_exe ); + + /// Set the \c SGTE_EVAL_SORT parameter. + /** + \param ses The \c SGTE_EVAL_SORT parameter -- \b IN. + */ + void set_SGTE_EVAL_SORT ( bool ses ); + + /// Set the \c HAS_SGTE parameter. + /** + \param hs The \c HAS_SGTE parameter -- \b IN. + */ + void set_HAS_SGTE ( bool hs ); + + /// Set the \c OPT_ONLY_SGTE parameter. + /** + \param oos The \c OPT_ONLY_SGTE parameter -- \b IN. + */ + void set_OPT_ONLY_SGTE ( bool oos ); + + /// Set the \c SGTE_COST parameter. + /** + \param sc The \c SGTE_COST parameter -- \b IN. + */ + void set_SGTE_COST ( int sc ); + + /// Set the \c MAX_SGTE_EVAL parameter. + /** + \param mse The \c MAX_SGTE_EVAL parameter -- \b IN. + */ + void set_MAX_SGTE_EVAL ( int mse ); + + /// Set the \c SGTE_CACHE_FILE parameter. + /** + \param scf The \c SGTE_CACHE_FILE parameter -- \b IN. + */ + void set_SGTE_CACHE_FILE ( const std::string & scf ); + + // Barrier: + // -------- + private: + NOMAD::Double _h_min; ///< Value of \c h_min. + NOMAD::Double _h_max_0; ///< Initial value of \c h_max. + NOMAD::Double _rho; ///< Rho parameter of the progressive barrier. + NOMAD::hnorm_type _h_norm; ///< Norm used to compute the feasibility function \c h. + + /// Flag equal to \c true if there are constraints. + bool _has_constraints; + + /// Flag equal to \c true if there are filter or progressive barrier constraints. + bool _has_filter_constraints; + + /// Flag equal to \c true if there are extreme barrier constraints. + bool _has_EB_constraints; + + /// Type of the barrier. + /** + May be NOMAD::FILTER, NOMAD::PB, NOMAD::PEB_P, or NOMAD::EB. + */ + NOMAD::bb_output_type _barrier_type; + + public: + + /// Access to the \c H_MIN parameter. + /** + \return The \c H_MIN parameter. + */ + const NOMAD::Double & get_h_min ( void ) const; + + /// Access to the \c H_MAX_0 parameter. + /** + \return The \c H_MAX_0 parameter. + */ + const NOMAD::Double & get_h_max_0 ( void ) const; + + /// Access to the \c RHO parameter. + /** + \return The \c RHO parameter. + */ + const NOMAD::Double & get_rho ( void ) const; + + /// Access to the \c H_NORM parameter. + /** + \return The \c H_NORM parameter. + */ + NOMAD::hnorm_type get_h_norm ( void ) const; + + /// Access to the type of barrier. + /** + \return The type of barrier. + */ + NOMAD::bb_output_type get_barrier_type ( void ) const; + + /// Check if there are constraints. + /** + \return A boolean equal to \c true if there are constraints. + */ + bool has_constraints ( void ) const; + + /// Check if there are extreme barrier constraints. + /** + \return A boolean equal to \c true if there are extreme barrier constraints. + */ + bool has_EB_constraints ( void ) const; + + /// Check if the progressive barrier (PB) is used. + /** + \return A boolean equal to \c true if the PB is used. + */ + bool use_sec_poll_center ( void ) const; + + /// Set the \c H_MIN parameter. + /** + \param h_min The \c H_MIN parameter -- \b IN. + */ + void set_H_MIN ( const NOMAD::Double & h_min ); + + /// Set the \c H_MAX_0 parameter. + /** + \param h_max The \c H_MAX_0 parameter -- \b IN. + */ + void set_H_MAX_0 ( const NOMAD::Double & h_max ); + + /// Set the \c RHO parameter. + /** + \param rho The \c RHO parameter -- \b IN. + */ + void set_RHO ( const NOMAD::Double & rho ); + + /// Set the \c H_NORM parameter. + /** + \param h_norm The \c H_NORM parameter -- \b IN. + */ + void set_H_NORM ( NOMAD::hnorm_type h_norm ); + + // MULTI-MADS parameters: + // ---------------------- + private: + + /// Number of MADS runs in Multi-MADS. + int _multi_nb_mads_runs; + + /// Maximum number of blackbox evaluations in Multi-MADS. + int _multi_overall_bb_eval; + + /// Flag equal to \c true if the delta criterion is used in Multi-MADS. + bool _multi_use_delta_crit; + + /// Bounds on the objective necessary for the display of the \c surf stat. + NOMAD::Point _multi_f_bounds; + + /// Multi-MADS reformulation. + /** + May be NOMAD::NORMALIZED, NOMAD::PRODUCT, + NOMAD::DIST_L1, NOMAD::DIST_L2, or NOMAD::DIST_LINF. + */ + NOMAD::multi_formulation_type _multi_formulation; + + public: + + /// Access to the \c MULTI_NB_MADS_RUNS parameter. + /** + \return The \c MULTI_NB_MADS_RUNS parameter. + */ + int get_multi_nb_mads_runs ( void ) const; + + /// Access to the \c MULTI_OVERALL_BB_EVAL parameter. + /** + \return The \c MULTI_OVERALL_BB_EVAL parameter. + */ + int get_multi_overall_bb_eval ( void ) const; + + /// Access to the \c MULTI_USE_DELTA_CRIT parameter. + /** + \return The \c MULTI_USE_DELTA_CRIT parameter. + */ + bool get_multi_use_delta_crit ( void ) const; + + /// Access to the \c MULTI_F_BOUNDS parameter. + /** + \return The \c MULTI_F_BOUNDS parameter. + */ + const NOMAD::Point & get_multi_f_bounds ( void ) const; + + /// Access to the \c MULTI_FORMULATION parameter. + /** + \return The \c MULTI_FORMULATION parameter. + */ + NOMAD::multi_formulation_type get_multi_formulation ( void ) const; + + /// Set the \c MULTI_NB_MADS_RUNS parameter. + /** + \param mads_runs The \c MULTI_NB_MADS_RUNS parameter -- \b IN. + */ + void set_MULTI_NB_MADS_RUNS ( int mads_runs ); + + /// Set the \c MULTI_OVERALL_BB_EVAL parameter. + /** + \param bbe The \c MULTI_OVERALL_BB_EVAL parameter -- \b IN. + */ + void set_MULTI_OVERALL_BB_EVAL ( int bbe ); + + /// Set the \c MULTI_USE_DELTA_CRIT parameter. + /** + \param udc The \c MULTI_USE_DELTA_CRIT parameter -- \b IN. + */ + void set_MULTI_USE_DELTA_CRIT ( bool udc ); + + /// Set the \c MULTI_F_BOUNDS parameter. + /** + \param mfb The \c MULTI_F_BOUNDS parameter -- \b IN. + */ + void set_MULTI_F_BOUNDS ( const NOMAD::Point & mfb ); + + /// Set the \c MULTI_FORMULATION parameter. + /** + \param mf The \c MULTI_FORMULATION parameter -- \b IN. + */ + void set_MULTI_FORMULATION ( NOMAD::multi_formulation_type mf ); + + // Opportunistic strategy parameters: + // ---------------------------------- + private: + + /// Flag equal to \c true if the opportunistic strategy is enabled. + bool _opportunistic_eval; + + /// Minimum number of successes. + /** + Parameter \c OPPORTUNISTIC_MIN_NB_SUCCESS. + */ + int _opportunistic_min_nb_success; + + /// Minimum number of evaluations. + /** + Parameter \c OPPORTUNISTIC_MIN_EVAL. + */ + int _opportunistic_min_eval; + + /// Minimum (relative) percentage of feasible objective improvement. + /** + Parameter \c OPPORTUNISTIC_MIN_F_IMPRVMT. + */ + NOMAD::Double _opportunistic_min_f_imprvmt; + + /// Flag equal to \c true if the lucky evaluation is enabled. + /** + Do one more eval "for luck". + */ + bool _opportunistic_lucky_eval; + + + /// Max block size for list evaluation + /** + Parameter \c BB_MAX_BLOCK_SIZE. + */ + int _bb_max_block_size; + + /// Block of points evaluation + /** + Parameter \c EVAL_POINTS_AS_BLOCK. + */ + bool _eval_points_as_block; + + public: + + /// Access to the \c OPPORTUNISTIC_EVAL parameter. + /** + \return The \c OPPORTUNISTIC_EVAL parameter + */ + bool get_opportunistic_eval ( void ) const; + + /// Access to the \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. + /** + \return The \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. + */ + int get_opportunistic_min_nb_success ( void ) const; + + /// Access to the \c OPPORTUNISTIC_MIN_EVAL parameter. + /** + \return The \c OPPORTUNISTIC_MIN_EVAL parameter. + */ + int get_opportunistic_min_eval ( void ) const; + + /// Access to the \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. + /** + \return The \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. + */ + const NOMAD::Double & get_opportunistic_min_f_imprvmt ( void ) const; + + /// Access to the \c OPPORTUNISTIC_LUCKY_EVAL parameter. + /** + \return The \c OPPORTUNISTIC_LUCKY_EVAL parameter. + */ + bool get_opportunistic_lucky_eval ( void ) const; + + /// Access to the \c BB_MAX_BLOCK_SIZE parameter + /** + \return the \c BB_MAX_BLOCK_SIZE parameter + */ + int get_bb_max_block_size ( void ) const ; + + /// Set the \c BB_MAX_BLOCK_SIZE parameter. + /** + \param bb_block_size The \c BB_MAX_BLOCK_SIZE parameter -- \b IN. + */ + void set_BB_MAX_BLOCK_SIZE ( int bb_block_size ); + + /// Access to the \c EVAL_POINTS_AS_BLOCK parameter + /** + \return true if points are evaluated as a block (number of elements >=1) + */ + bool eval_points_as_block() const {return _eval_points_as_block;} + + + /// Set the \c OPPORTUNISTIC_EVAL parameter. + /** + \param opp_eval The \c OPPORTUNISTIC_EVAL parameter -- \b IN. + */ + void set_OPPORTUNISTIC_EVAL ( bool opp_eval ); + + /// Set the \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. + /** + \param opp_min_nb_succ The \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter -- \b IN. + */ + void set_OPPORTUNISTIC_MIN_NB_SUCCESS ( int opp_min_nb_succ ); + + /// Set the \c OPPORTUNISTIC_MIN_EVAL parameter. + /** + \param opp_min_eval The \c OPPORTUNISTIC_MIN_EVAL parameter -- \b IN. + */ + void set_OPPORTUNISTIC_MIN_EVAL ( int opp_min_eval ); + + /// Set the \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. + /** + \param opp_min_f_imprvt The \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter -- \b IN. + */ + void set_OPPORTUNISTIC_MIN_F_IMPRVMT ( const NOMAD::Double & opp_min_f_imprvt ); + + /// Set the \c OPPORTUNISTIC_LUCKY_EVAL parameter. + /** + \param opp_lucky_eval The \c OPPORTUNISTIC_LUCKY_EVAL parameter -- \b IN. + */ + void set_OPPORTUNISTIC_LUCKY_EVAL ( bool opp_lucky_eval ); + + + + }; /*----------------------------------------------------------------------*/ - /// Constructor #1. - /** - \param out Display -- \b IN. - */ - explicit Parameters ( const NOMAD::Display & out ) - : _out ( out ) , - _std_signature ( NULL ) , - _extern_signature ( NULL ) { init(); } - - /// Constructor #2. - /** - From an extern signature. - \param extern_signature A pointer to the extern signature -- \b IN. - \param out Display -- \b IN. - */ - explicit Parameters ( NOMAD::Signature * extern_signature , - const NOMAD::Display & out ) - : _out ( out ) , - _std_signature ( NULL ) , - _extern_signature ( extern_signature ) { init(); } - - /// Destructor. - virtual ~Parameters ( void ); - - /// Display parameter help. - /** - - Help option obtained with command \c nomad \c -h. - - A list of parameters is given as the program arguments. - \param argc Number of command line arguments -- \b IN. - \param argv The command line arguments -- \b IN. - \param developer Bool to request developer help (defaut=false) -- \b IN. - */ - void help ( int argc , char ** argv , bool developer=false) const; - - /// Display parameter help. - /** - For a specific parameter. - \param param_name Name of the parameter -- \b IN. - \param developer Bool to request developer help (defaut=false) -- \b IN. - */ - void help ( const std::string & param_name, bool developer=false ) const; - - /// Display parameter help. - /** - For a list of parameters. - \param param_names_list List of parameter names -- \b IN. - \param developer Bool to request developer help (defaut=false) -- \b IN. - */ - void help ( const std::list<std::string> & param_names_list , bool developer=false) const; - - /// Reset. - void reset ( void ) { init(); } - - /// Read parameters from a file. 1/2 - /** - \param param_file Name of the parameters file -- \b IN. - */ - void read ( const std::string & param_file ); - - /// Read parameters from a Parameter_Entries 2/2 - /** - \param entries -- \b IN. - */ - void read ( const NOMAD::Parameter_Entries & entries ); - - - /// Check the parameters. - /** - \param remove_history_file A boolean equal to \c true if the history file - has to be deleted - -- \b IN -- \b optional (default = \c true). - \param remove_solution_file A boolean equal to \c true if the solution file - has to be deleted - -- \b IN -- \b optional (default = \c true). - \param remove_stats_file A boolean equal to \c true if the stats file - has to be deleted - -- \b IN -- \b optional (default = \c true). - */ - void check ( bool remove_history_file = true , - bool remove_solution_file = true , - bool remove_stats_file = true ); - - /// Force the check flag to be satisfied. - /** - This advanced function should be used with care. - */ - void force_check_flag ( void ) { _to_be_checked = false; } - - /// Display. - /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - - /// Display. - /** - Uses \c this->_out as NOMAD::Display object. - */ - void display ( void ) const { display ( _out ); } - - /*--------------------------------------------------------------*/ - /* Attributes and methods listed by categories */ - /*--------------------------------------------------------------*/ - - // Algorithm and miscellaneous parameters: - // --------------------------------------- - private: - std::string _problem_dir; ///< Problem directory. - std::string _tmp_dir; ///< Temporary directory. - int _seed; ///< Seed. - int _max_eval; ///< Maximum number of evaluations. - int _max_bb_eval; ///< Maximum number of blackbox evaluations. - - std::list<std::string> _display_stats; ///< Stats keywords for \c DISPLAY_STATS. - bool _display_all_eval; ///< Parameter \c DISPLAY_ALL_EVAL - - /// Equal to \c true if \c _max_bb_eval has been entered. - bool _max_bbe_decided; - - /// Maximum number of simulated evaluations. - int _max_sim_bb_eval; - - int _max_time; ///< Maximum time. - int _max_iterations; ///< Maximum number of iterations. - int _max_cons_failed_it; ///< Maximum number of consecutive failed iterations. - float _max_cache_memory; ///< Maximum cache memory. - bool _stop_if_feasible; ///< Stop if a feasible solution is found. - NOMAD::Point _f_target; ///< Target for the objective function. - NOMAD::Double _stat_sum_target; ///< Target for the STAT_SUM stat. - NOMAD::Double _L_curve_target; ///< Target for the L_CURVE criterion. - bool _snap_to_bounds; ///< Snap or not the points to the bounds. - bool _user_calls_enabled; ///< Enable calls to user functions. - bool _asynchronous; ///< Asynchronous version for parallelism. - - public: - - /// Test to know if parameters have to be checked. - /** - \return A boolean equal to \c true if parameters have - to be checked with function NOMAD::Parameters::check(). - */ - bool to_be_checked ( void ) const { return _to_be_checked; } - - /// Access to the display degrees. - /** - - Use NOMAD::Parameters::out().get_X_dd() - to access other specific display degrees. - - \see Display.hpp. - \param d The 4 display degrees as a string -- \b OUT. - */ - void get_display_degree ( std::string & d ) const; - - /// Access to the display degree. - /** - \return General display degree. - */ - int get_display_degree ( void ) const; - - /// Access to display. - /** - \return The NOMAD::Display object. - */ - const NOMAD::Display & out ( void ) const; - - /// Access to the \c DISPLAY_STATS parameter. - /** - \return The \c DISPLAY_STATS parameter. - */ - const std::list<std::string> & get_display_stats ( void ) const; - - /// Access to the \c DISPLAY_ALL_EVAL parameter. - /** - \return The \c DISPLAY_ALL_EVAL parameter. - */ - bool get_display_all_eval ( void ) const; - - /// Access to the \c POINT_DISPLAY_LIMIT parameter. - /** - \return The \c POINT_DISPLAY_LIMIT parameter. - */ - int get_point_display_limit ( void ) const; - - /// Access to the seed. - /** - \return The seed. - */ - int get_seed ( void ) const; - - /// Access to the maximum number of evaluations. - /** - \return The maximum number of evaluations. - */ - int get_max_eval ( void ) const; - - /// Access to the \c MAX_SIM_BB_EVAL parameter. - /** - \return The \c MAX_SIM_BB_EVAL parameter. - */ - int get_max_sim_bb_eval ( void ) const; - - /// Access to the \c MAX_BB_EVAL parameter. - /** - \return The \c MAX_BB_EVAL parameter. - */ - int get_max_bb_eval ( void ) const; - - /// Access to the \c MAX_TIME parameter. - /** - \return The \c MAX_TIME parameter. - */ - int get_max_time ( void ) const; - - /// Access to the maximum number of iterations. - /** - \return The maximum number of iterations. - */ - int get_max_iterations ( void ) const; - - /// Access to the maximum number of consecutive failed iterations. - /** - \return The maximum number of consecutive failed iterations. - */ - int get_max_consecutive_failed_iterations ( void ) const; - - /// Access to the maximum cache memory. - /** - \return The maximum cache memory. - */ - float get_max_cache_memory ( void ) const; - - /// Access to the \c STOP_IF_FEASIBLE parameter. - /** - \return The \c STOP_IF_FEASIBLE parameter. - */ - bool get_stop_if_feasible ( void ) const; - - /// Access to the \c F_TARGET parameter. - /** - \return The \c F_TARGET parameter. - */ - const NOMAD::Point & get_f_target ( void ) const; - - /// Access to the \c STAT_SUM_TARGET parameter. - /** - \return The \c STAT_SUM_TARGET parameter. - */ - const NOMAD::Double & get_stat_sum_target ( void ) const; - - /// Access to the \c L_CURVE_TARGET parameter. - /** - \return The \c L_CURVE_TARGET parameter. - */ - const NOMAD::Double & get_L_curve_target ( void ) const; - - /// Access to the problem directory. - /** - \return The problem directory. - */ - const std::string & get_problem_dir ( void ) const; - - /// Access to the temporary directory. - /** - \return The temporary directory. - */ - const std::string & get_tmp_dir ( void ) const; - - /// Access to the \c SNAP_TO_BOUNDS parameter. - /** - \return The \c SNAP_TO_BOUNDS parameter. - */ - bool get_snap_to_bounds ( void ) const; - - /// Access to the \c USER_CALLS_ENABLED parameter. - /** - \return The \c USER_CALLS_ENABLED parameter. - */ - bool get_user_calls_enabled ( void ) const; - - /// Access to the \c ASYNCHRONOUS parameter. - /** - \return The \c ASYNCHRONOUS parameter. - */ - bool get_asynchronous ( void ) const; - - /// Set the \c POINT_DISPLAY_LIMIT parameter. - /** - \param dl The \c POINT_DISPLAY_LIMIT parameter -- \b IN. - */ - void set_POINT_DISPLAY_LIMIT ( int dl ); - - /// Set the \c DISPLAY_STATS parameter. - /** - - From a list of strings. - \param ds The \c DISPLAY_STATS parameter -- \b IN. - */ - void set_DISPLAY_STATS ( const std::list<std::string> & ds ); - - /// Set the \c DISPLAY_STATS parameter. - /** - - From a string. - \param ds The \c DISPLAY_STATS parameter -- \b IN. - */ - void set_DISPLAY_STATS ( const std::string & ds ); - - /// Set the \c DISPLAY_ALL_EVAL parameter. - /** - \param dae The \c DISPLAY_ALL_EVAL parameter -- \b IN. - */ - void set_DISPLAY_ALL_EVAL ( bool dae ); - - /// Set the display degree. - /** - - Accepts also NOMAD::dd_type arguments. - \param dd Display degree -- \b IN. - \return \c true if the operation succeeded. - */ - bool set_DISPLAY_DEGREE ( int dd ); - - /// Set the display degrees. - /** - - From a string with the 4 degrees. - \param dd Display degree -- \b IN. - \return \c true if the operation succeeded. - */ - bool set_DISPLAY_DEGREE ( const std::string & dd ); - - /// Set the display degrees. - /* - \param gen_dd General display degree -- \b IN. - \param search_dd Search display degree -- \b IN. - \param poll_dd Poll display degree -- \b IN. - \param iter_dd Iterative display degree -- \b IN. - */ - void set_DISPLAY_DEGREE ( int gen_dd , - int search_dd , - int poll_dd , - int iter_dd ); - - /// Set the \c OPEN_BRACE parameter. - /** - \param s The \c OPEN_BRACE parameter -- \b IN. - */ - void set_OPEN_BRACE ( const std::string & s ); - - /// Set the \c CLOSED_BRACE parameter. - /** - \param s The \c CLOSED_BRACE parameter -- \b IN. - */ - void set_CLOSED_BRACE ( const std::string & s ); - - /// Set the seed. - /** - \param seed The seed -- \b IN. - */ - void set_SEED ( int seed ); - - /// Set the \c MAX_EVAL parameter. - /** - \param me The \c MAX_EVAL parameter -- \b IN. - */ - void set_MAX_EVAL ( int me ); - - /// Set the \c MAX_SIM_BB_EVAL parameter. - /** - \param msbe The \c MAX_SIM_BB_EVAL parameter -- \b IN. - */ - void set_MAX_SIM_BB_EVAL ( int msbe ); - - /// Set the \c MAX_BB_EVAL parameter. - /** - \param bbe The \c MAX_BB_EVAL parameter -- \b IN. - */ - void set_MAX_BB_EVAL ( int bbe ); - - /// Set the \c MAX_TIME parameter. - /** - \param mt The \c MAX_TIME parameter -- \b IN. - */ - void set_MAX_TIME ( int mt ); - - /// Set the \c MAX_ITERATIONS parameter. - /** - \param mi The \c MAX_ITERATIONS parameter -- \b IN. - */ - void set_MAX_ITERATIONS ( int mi ); - - /// Set the \c MAX_CONSECUTIVE_FAILED_ITERATIONS parameter. - /** - \param mcsi The \c MAX_CONSECUTIVE_FAILED_ITERATIONS parameter -- \b IN. - */ - void set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( int mcsi ); - - /// Set the \c MAX_CACHE_MEMORY parameter. - /** - \param mcm The \c MAX_CACHE_MEMORY parameter -- \b IN. - */ - void set_MAX_CACHE_MEMORY ( float mcm ); - - /// Set the \c STOP_IF_FEASIBLE parameter. - /** - \param sif The \c STOP_IF_FEASIBLE parameter -- \b IN. - */ - void set_STOP_IF_FEASIBLE ( bool sif ); - - /// Set the \c STAT_SUM_TARGET parameter. - /** - \param target The \c STAT_SUM_TARGET parameter -- \b IN. - */ - void set_STAT_SUM_TARGET ( const NOMAD::Double & target ); - - /// Set the \c L_CURVE_TARGET parameter. - /** - \param target The \c L_CURVE_TARGET parameter -- \b IN. - */ - void set_L_CURVE_TARGET ( const NOMAD::Double & target ); - - /// Set the \c PROBLEM_DIR parameter. - /** - \param dir The \c PROBLEM_DIR parameter -- \b IN. - */ - void set_PROBLEM_DIR ( const std::string & dir ); - - /// Set the \c TMP_DIR parameter. - /** - \param dir The \c TMP_DIR parameter -- \b IN. - */ - void set_TMP_DIR ( const std::string & dir ); - - /// Set the \c SNAP_TO_BOUNDS parameter. - /** - \param stb The \c SNAP_TO_BOUNDS parameter -- \b IN. - */ - void set_SNAP_TO_BOUNDS ( bool stb ); - - /// Set the \c USER_CALLS_ENABLED parameter. - /** - \param uce The \c USER_CALLS_ENABLED parameter -- \b IN. - */ - void set_USER_CALLS_ENABLED ( bool uce ); - - /// Set the \c ASYNCHRONOUS parameter. - /** - \param as The \c ASYNCHRONOUS parameter -- \b IN. - */ - void set_ASYNCHRONOUS ( bool as ); - - /// Set the \c F_TARGET parameter. - /** - - Multi-objective version. - \param target The \c F_TARGET parameter -- \b IN. - */ - void set_F_TARGET ( const NOMAD::Point & target ); - - /// Set the F_TARGET \c parameter. - /** - - Single-objective version. - \param target The \c F_TARGET parameter -- \b IN. - */ - void set_F_TARGET ( const NOMAD::Double & target ); - - /// Reset the \c F_TARGET parameter. - void reset_f_target ( void ) { _f_target.clear(); } - - /// Set the \c EPSILON parameter. - /** - \param eps The \c EPSILON parameter -- \b IN. - */ - void set_EPSILON ( const NOMAD::Double & eps ) - { - NOMAD::Double::set_epsilon ( eps.value() ); - } - - /// Set the \c UNDEF_STR parameter. - /** - \param undef_str The \c UNDEF_STR parameter -- \b IN. - */ - void set_UNDEF_STR ( const std::string & undef_str ) - { - NOMAD::Double::set_undef_str ( undef_str ); - } - - /// Set the \c INF_STR parameter. + /// Display a NOMAD::Parameters object. /** - \param inf_str The \c INF_STR parameter -- \b IN. - */ - void set_INF_STR ( const std::string & inf_str ) - { - NOMAD::Double::set_inf_str ( inf_str ); - } - - /// Access to the \c EPSILON parameter. - /** - \return The \c EPSILON parameter. - */ - const NOMAD::Double get_epsilon ( void ) const - { - return NOMAD::Double::get_epsilon(); - } - - /// Access to the \c UNDEF_STR parameter. - /** - \return The \c UNDEF_STR parameter. - */ - const std::string get_undef_str ( void ) const - { - return NOMAD::Double::get_undef_str(); - } - - /// Access to the \c INF_STR parameter. - /** - \return The \c INF_STR parameter. - */ - const std::string get_inf_str ( void ) const + \param out The NOMAD::Display object -- \b IN. + \param p The NOMAD::Parameters object to be displayed -- \b IN. + \return The NOMAD::Display object. + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Parameters & p ) { - return NOMAD::Double::get_inf_str(); + p.display ( out ); + return out; } - - // Output files: - // ------------- - private: - - /// List of stats for parameter \c STATS_FILE. - std::list<std::string> _stats_file; - - /// Name of the stats file. - std::string _stats_file_name; - - /// Parameter \c ADD_SEED_TO_FILE_NAME. - bool _add_seed_to_file_names; - - std::string _solution_file; ///< Parameter \c SOLUTION_FILE. - std::string _history_file; ///< Parameter \c HISTORY_FILE. - std::string _cache_file; ///< Parameter \c CACHE_FILE. - int _cache_save_period; ///< Parameter \c CACHE_SAVE_PERIOD. - - public: - - /// Access to the list of stats for the \c STATS_FILE parameter. - /** - \return The list of stats. - */ - const std::list<std::string> & get_stats_file ( void ) const; - - /// Access to the name of the stats file. - /** - \return The name of the stats file. - */ - const std::string & get_stats_file_name ( void ) const; - - /// Access to the \c SOLUTION_FILE parameter. - /** - \return The \c SOLUTION_FILE parameter. - */ - const std::string & get_solution_file ( void ) const; - - /// Access to the \c HISTORY_FILE parameter. - /** - \return The \c HISTORY_FILE parameter. - */ - const std::string & get_history_file ( void ) const; - - /// Access to the \c CACHE_FILE parameter. - /** - \return The \c CACHE_FILE parameter. - */ - const std::string & get_cache_file ( void ) const; - - /// Access to the \c CACHE_SAVE_PERIOD parameter. - /** - \return The \c CACHE_SAVE_PERIOD parameter. - */ - int get_cache_save_period ( void ) const; - - /// Access to the \c ADD_SEED_TO_FILE_NAME parameter. - /** - \return The \c ADD_SEED_TO_FILE_NAME parameter. - */ - bool get_add_seed_to_file_names ( void ) const; - - /// Reset the \c STATS_FILE parameter. - void reset_stats_file ( void ); - - /// Set the \c STATS_FILE parameter. - /** - \param file_name Name of the stats file -- \b IN. - \param stats List of stats -- \b IN. - */ - void set_STATS_FILE ( const std::string & file_name , - const std::list<std::string> & stats ); - - /// Set the \c STATS_FILE parameter. - /** - \param file_name Name of the stats file -- \b IN. - \param stats The stats -- \b IN. - */ - void set_STATS_FILE ( const std::string & file_name , - const std::string & stats ); - - /// Set the \c ADD_SEED_TO_FILE_NAME parameter. - /** - \param astfn The \c ADD_SEED_TO_FILE_NAME parameter -- \b IN. - */ - void set_ADD_SEED_TO_FILE_NAMES ( bool astfn ); - - /// Set the \c SOLUTION_FILE parameter. - /** - \param sf The \c SOLUTION_FILE parameter -- \b IN. - */ - void set_SOLUTION_FILE ( const std::string & sf ); - - /// Set the \c HISTORY_FILE parameter. - /** - \param hf The \c HISTORY_FILE parameter -- \b IN. - */ - void set_HISTORY_FILE ( const std::string & hf ); - - /// Set the \c CACHE_FILE parameter. - /** - \param cf The \c CACHE_FILE parameter -- \b IN. - */ - void set_CACHE_FILE ( const std::string & cf ); - - /// Set the \c CACHE_SAVE_PERIOD parameter. - /** - \param csp The \c CACHE_SAVE_PERIOD parameter -- \b IN. - */ - void set_CACHE_SAVE_PERIOD ( int csp ); - - // Searches: - // --------- - private: - - /// Speculative search (MADS search). - bool _speculative_search; - - bool _disable_models; ///< Models disablement - - NOMAD::model_params_type _model_params; ///< Models parameters. - - // VNS search parameters: - bool _VNS_search; ///< Flag for the VNS search. - NOMAD::Double _VNS_trigger; ///< VNS trigger. - - // Latin-Hypercube (LH) search: - int _LH_search_p0; ///< Number of initial LH search points. - int _LH_search_pi; ///< LH search points at each iteration. - bool _opportunistic_LH; ///< Parameter \c OPPORTUNISTIC_LH. - bool _opp_LH_is_defined; ///< A boolean equal to \c true if a LH has been defined. - - bool _cache_search; ///< Cache search. - bool _opportunistic_cache_search; ///< Parameter \c OPPORTUNISTIC_CACHE_SEARCH. - - /// A boolean equal to \c true if \c OPPORTUNISTIC_CACHE_SEARCH has been defined. - bool _opp_CS_is_defined; - - public: - - /// Access to the \c SPECULATIVE_SEARCH parameter. - /** - \return The \c SPECULATIVE_SEARCH parameter. - */ - bool get_speculative_search ( void ) const; - - /// Check if a model search is specified. - /** - \return A boolean equal to \c true if a model search is defined. - */ - bool has_model_search ( void ) const; - - /// Access to the \c MODEL_SEARCH parameter. - /** - \param i Index of the model search (1 or 2) -- \b IN. - \return The \c MODEL_SEARCH parameter. - */ - NOMAD::model_type get_model_search ( int i ) const; - - /// Access to the \c MODEL_SEARCH_OPTIMISTIC parameter. - /** - \return The \c MODEL_SEARCH_OPTIMISTIC parameter. - */ - bool get_model_search_optimistic ( void ) const; - - /// Access to the \c MODEL_SEARCH_PROJ_TO_MESH parameter. - /** - \return The \c MODEL_SEARCH_PROJ_TO_MESH parameter. - */ - bool get_model_search_proj_to_mesh ( void ) const; - - /// Access to the \c MODEL_QUAD_RADIUS_FACTOR parameter. - /** - \return The \c MODEL_QUAD_RADIUS_FACTOR parameter. - */ - const NOMAD::Double & get_model_quad_radius_factor ( void ) const; - - /// Access to the \c MODEL_NP1_QUAD_EPSILON parameter. - /** - \return The \c MODEL_NP1_QUAD_EPSILON parameter. - */ - const NOMAD::Double & get_model_np1_quad_epsilon ( void ) const; - - - /// Access to the \c MODEL_QUAD_USE_WP parameter. - /** - \return The \c MODEL_QUAD_USE_WP parameter. - */ - bool get_model_quad_use_WP ( void ) const; - - /// Access to the \c MODEL_QUAD_MAX_Y_SIZE parameter. - /** - \return The \c MODEL_QUAD_MAX_Y_SIZE parameter. - */ - int get_model_quad_max_Y_size ( void ) const; - - /// Access to the \c MODEL_QUAD_MIN_Y_SIZE parameter. - /** - \return The \c MODEL_QUAD_MIN_Y_SIZE parameter. - */ - int get_model_quad_min_Y_size ( void ) const; - - /// Access to the \c MODEL_TGP_MODE parameter. - /** - \return The \c MODEL_TGP_MODE parameter. - */ - NOMAD::TGP_mode_type get_model_tgp_mode ( void ) const; - - /// Access to the \c MODEL_TGP_REUSE_MODEL parameter. - /** - \return The \c MODEL_TGP_REUSE_MODEL parameter. - */ - bool get_model_tgp_reuse_model ( void ) const; - - /// Access to the \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. - /** - \return The \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. - */ - int get_model_search_max_trial_pts ( void ) const; - - /// Access to the \c MODEL_EVAL_SORT parameter. - /** - \return The \c MODEL_EVAL_SORT parameter. - */ - NOMAD::model_type get_model_eval_sort ( void ) const; - - /// Access to the \c MODEL_EVAL_SORT_CAUTIOUS parameter. - /** - \return The \c MODEL_EVAL_SORT_CAUTIOUS parameter. - */ - bool get_model_eval_sort_cautious ( void ) const; - - - /// Access to all the models parameters. - /** - \param mp The models parameters -- \b OUT. - */ - void get_model_parameters ( NOMAD::model_params_type & mp ) const; - - /// Access to the \c VNS_SEARCH parameter. - /** - \return The \c VNS_SEARCH parameter. - */ - bool get_VNS_search ( void ) const; - - /// Access to the VNS trigger. - /** - \return The VNS trigger. - */ - const NOMAD::Double & get_VNS_trigger ( void ) const; - - /// Access to the number of initial LH search points. - /** - \return The number of initial LH search points. - */ - int get_LH_search_p0 ( void ) const; - - /// Access to the number of LH search points at each iteration. - /** - \return The number of LH search points at each iteration. - */ - int get_LH_search_pi ( void ) const; - - /// Access to the \c OPPORTUNISTIC_LH parameter. - /** - \return The \c OPPORTUNISTIC_LH parameter. - */ - bool get_opportunistic_LH ( void ) const; - - /// Access to the \c CACHE_SEARCH parameter. - /** - \return The \c CACHE_SEARCH parameter. - */ - bool get_cache_search ( void ) const; - - /// Access to the \c OPPORTUNISTIC_CACHE_SEARCH parameter. - /** - \return The \c OPPORTUNISTIC_CACHE_SEARCH parameter. - */ - bool get_opportunistic_cache_search ( void ) const; - - /// Set the \c SPECULATIVE_SEARCH parameter. - /** - \param ss The \c SPECULATIVE_SEARCH parameter -- \b IN. - */ - void set_SPECULATIVE_SEARCH ( bool ss ); - - - /// Disable use of models. - /** - */ - void set_DISABLE_MODELS ( void ); - - - /// Set all the models parameters. - /** - \param mp The models parameters -- \b IN. - */ - void set_model_parameters ( const NOMAD::model_params_type & mp ); - - /// Set the \c MODEL_SEARCH parameter (1/3). - /** - \param i Index of the model search (1 or 2) -- \b IN. - \param ms The \c MODEL_SEARCH parameter -- \b IN. - */ - void set_MODEL_SEARCH ( int i , NOMAD::model_type ms ); - - /// Set the \c MODEL_SEARCH parameter (2/3). - /** - \param ms The \c MODEL_SEARCH parameter -- \b IN. - */ - void set_MODEL_SEARCH ( bool ms ); - - /// Set the \c MODEL_SEARCH parameter (3/3). - /** - \param mod_type The \c MODEL_SEARCH parameter -- \b IN. - */ - void set_MODEL_SEARCH ( NOMAD::model_type mod_type ); - - /// Set the \c MODEL_SEARCH_OPTIMISTIC parameter. - /** - \param mso The \c MODEL_SEARCH_OPTIMISTIC parameter -- \b IN. - */ - void set_MODEL_SEARCH_OPTIMISTIC ( bool mso ); - - /// Set the \c MODEL_SEARCH_PROJ_TO_MESH parameter. - /** - \param ptm The \c MODEL_SEARCH_PROJ_TO_MESH parameter -- \b IN. - */ - void set_MODEL_SEARCH_PROJ_TO_MESH ( bool ptm ); - - /// Set the \c MODEL_QUAD_RADIUS_FACTOR parameter. - /** - \param r The \c MODEL_QUAD_RADIUS_FACTOR parameter -- \b IN. - */ - void set_MODEL_QUAD_RADIUS_FACTOR ( const NOMAD::Double & r ); - - /// Set the \c MODEL_QUAD_USE_WP parameter. - /** - \param uwp The \c MODEL_QUAD_USE_WP parameter -- \b IN. - */ - void set_MODEL_QUAD_USE_WP ( bool uwp ); - - /// Set the \c MODEL_QUAD_MAX_Y_SIZE parameter. - /** - \param s The \c MODEL_QUAD_MAX_Y_SIZE parameter -- \b IN. - */ - void set_MODEL_QUAD_MAX_Y_SIZE ( int s ); - - /// Set the \c MODEL_QUAD_MIN_Y_SIZE parameter. - /** - \param s The \c MODEL_QUAD_MIN_Y_SIZE parameter -- \b IN. - */ - void set_MODEL_QUAD_MIN_Y_SIZE ( int s ); - - /// Set the \c MODEL_NP1_QUAD_EPSILON parameter. - /** - \param r The \c MODEL_NP1_QUAD_EPSILON parameter -- \b IN. - */ - void set_MODEL_NP1_QUAD_EPSILON ( const NOMAD::Double & r ); - - /// Set the \c MODEL_TGP_MODE parameter. - /** - \param m The \c MODEL_TGP_MODE parameter -- \b IN. - */ - void set_MODEL_TGP_MODE ( NOMAD::TGP_mode_type m ); - - /// Set the \c MODEL_TGP_REUSE_MODEL parameter. - /** - \param rm The \c MODEL_TGP_REUSE_MODEL parameter -- \b IN. - */ - void set_MODEL_TGP_REUSE_MODEL ( bool rm ); - - /// Set the \c MODEL_SEARCH_MAX_TRIAL_PTS parameter. - /** - \param s The \c MODEL_SEARCH_MAX_TRIAL_PTS parameter -- \b IN. - */ - void set_MODEL_SEARCH_MAX_TRIAL_PTS ( int s ); - - /// Set the \c MODEL_EVAL_SORT parameter (1/2). - /** - \param mes The \c MODEL_EVAL_SORT parameter -- \b IN. - */ - void set_MODEL_EVAL_SORT ( NOMAD::model_type mes ); - - /// Set the \c MODEL_EVAL_SORT parameter (2/2). - /** - \param mes The \c MODEL_EVAL_SORT parameter -- \b IN. - */ - void set_MODEL_EVAL_SORT ( bool mes ); - - - /// Set the \c MODEL_EVAL_SORT_CAUTIOUS parameter. - /** - \param mesc The \c MODEL_EVAL_SORT_CAUTIOUS parameter -- \b IN. - */ - void set_MODEL_EVAL_SORT_CAUTIOUS ( bool mesc ); - - /// Set the \c VNS_SEARCH parameter. - /** - \param vns The \c VNS_SEARCH parameter -- \b IN. - */ - void set_VNS_SEARCH ( bool vns ); - - /// Set the \c VNS_SEARCH parameter. - /** - \param trigger The VNS trigger -- \b IN. - */ - void set_VNS_SEARCH ( const NOMAD::Double & trigger ); - - /// Set the \c LH_SEARCH parameter. - /** - \param p0 Number of initial LH search points -- \b IN. - \param pi LH search points at each iteration -- \b IN. - */ - void set_LH_SEARCH ( int p0 , int pi ); - - /// Set the \c OPPORTUNISTIC_LH parameter. - /** - \param olh The \c OPPORTUNISTIC_LH parameter -- \b IN. - */ - void set_OPPORTUNISTIC_LH ( bool olh ); - - /// Set the \c CACHE_SEARCH parameter. - /** - \param cs The \c CACHE_SEARCH parameter -- \b IN. - */ - void set_CACHE_SEARCH ( bool cs ); - - /// Set the \c OPPORTUNISTIC_CACHE_SEARCH parameter. - /** - \param ocs The \c OPPORTUNISTIC_CACHE_SEARCH parameter -- \b IN. - */ - void set_OPPORTUNISTIC_CACHE_SEARCH ( bool ocs ); - - // Mesh: - // ----- - private: - - NOMAD::Double _mesh_update_basis; ///< Mesh update basis (tau). - int _mesh_coarsening_exponent; ///< Mesh coarsening exponent. - int _mesh_refining_exponent; ///< Mesh refining exponent. - int _initial_mesh_index; ///< Initial mesh index (ell_0). - int _max_mesh_index; ///< Final mesh index (ell_max). - - NOMAD::Point _initial_mesh_size; ///< Initial (absolute) mesh size (Delta^m_0). - NOMAD::Point _min_mesh_size; ///< Minimal (absolute) mesh size (Delta^m_min). - NOMAD::Point _min_poll_size; ///< Minimal (absolute) poll size (Delta^p_min). - - bool _min_poll_size_defined; ///< \c true if _min_poll_size is user-defined. - - public: - - /// Access to the \c MESH_UPDATE_BASIS parameter. - /** - \return The \c MESH_UPDATE_BASIS parameter. - */ - const NOMAD::Double & get_mesh_update_basis ( void ) const; - - /// Access to the \c MESH_COARSENING_EXPONENT parameter. - /** - \return The \c MESH_COARSENING_EXPONENT parameter. - */ - int get_mesh_coarsening_exponent ( void ) const; - - /// Access to the \c MESH_REFINING_EXPONENT parameter. - /** - \return The \c MESH_REFINING_EXPONENT parameter. - */ - int get_mesh_refining_exponent ( void ) const; - - /// Access to the \c INITIAL_MESH_INDEX parameter. - /** - \return The \c INITIAL_MESH_INDEX parameter. - */ - int get_initial_mesh_index ( void ) const; - - /// Access to the \c MAX_MESH_INDEX parameter. - /** - \return The \c MAX_MESH_INDEX parameter. - */ - int get_max_mesh_index ( void ) const; - - /// Access to the \c INITIAL_MESH_SIZE parameter. - /** - \return The \c INITIAL_MESH_SIZE parameter. - */ - const NOMAD::Point & get_initial_mesh_size ( void ) const; - - /// Access to the \c MIN_MESH_SIZE parameter. - /** - \return The \c MIN_MESH_SIZE parameter. - */ - const NOMAD::Point & get_min_mesh_size ( void ) const; - - /// Access to the \c MIN_POLL_SIZE parameter. - /** - \return The \c MIN_POLL_SIZE parameter. - */ - const NOMAD::Point & get_min_poll_size ( void ) const; - - /// Access to \c _min_poll_size_defined. - /** - \return A boolean equal to \c true if the \c MIN_POLL_SIZE parameter - has been user-defined. - */ - bool get_min_poll_size_defined ( void ) const; - - /// Set the \c MAX_MESH_INDEX parameter. - /** - \param lmax The \c MAX_MESH_INDEX parameter -- \b IN. - */ - void set_MAX_MESH_INDEX ( int lmax ); - - /// Set the \c MESH_UPDATE_BASIS parameter. - /** - \param tau The \c MESH_UPDATE_BASIS parameter -- \b IN. - */ - void set_MESH_UPDATE_BASIS ( const NOMAD::Double & tau ); - - /// Set the \c INITIAL_MESH_INDEX parameter. - /** - \param ell_0 The \c INITIAL_MESH_INDEX parameter -- \b IN. - */ - void set_INITIAL_MESH_INDEX ( int ell_0 ); - - /// Set the \c MESH_REFINING_EXPONENT parameter. - /** - \param mre The \c MESH_REFINING_EXPONENT parameter -- \b IN. - */ - void set_MESH_REFINING_EXPONENT ( int mre ); - - /// Set the \c MESH_COARSENING_EXPONENT parameter. - /** - \param mce The \c MESH_COARSENING_EXPONENT parameter -- \b IN. - */ - void set_MESH_COARSENING_EXPONENT ( int mce ); - - /// Set the \c MIN_MESH_SIZE parameter. - /** - \param mms Minimum mesh size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_MESH_SIZE ( const NOMAD::Double & mms , bool relative = false ); - - /// Set the \c MIN_MESH_SIZE parameter. - /** - \param index Index of a variable -- \b IN. - \param mms Minimum mesh size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_MESH_SIZE ( int index , - const NOMAD::Double & mms , - bool relative = false ); - - /// Set the \c MIN_MESH_SIZE parameter. - /** - \param mms Minimum mesh size -- \b IN. - \param relative Indicated as relative values - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_MESH_SIZE ( const NOMAD::Point & mms , bool relative = false ); - - /// Set the \c MIN_POLL_SIZE parameter. - /** - \param mps Minimum poll size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_POLL_SIZE ( const NOMAD::Double & mps , bool relative = false ); - - /// Set the \c MIN_POLL_SIZE parameter. - /** - \param index Index of a variable -- \b IN. - \param mps Minimum poll size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_POLL_SIZE ( int index , - const NOMAD::Double & mps , - bool relative = false ); - - /// Set the \c MIN_POLL_SIZE parameter. - /** - \param mps Minimum poll size -- \b IN. - \param relative Indicated as relative values - -- \b IN -- \b optional (default = \c false). - */ - void set_MIN_POLL_SIZE ( const NOMAD::Point & mps , bool relative = false ); - - /// Set the \c INITIAL_MESH_SIZE parameter. - /** - \param ims Initial mesh size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_INITIAL_MESH_SIZE ( const NOMAD::Double & ims , bool relative = false ); - - /// Set the \c INITIAL_MESH_SIZE parameter. - /** - \param index Index of a variable -- \b IN. - \param ims Initial mesh size -- \b IN. - \param relative Indicated as a relative value - -- \b IN -- \b optional (default = \c false). - */ - void set_INITIAL_MESH_SIZE ( int index , - const NOMAD::Double & ims , - bool relative = false ); - - /// Set the \c INITIAL_MESH_SIZE parameter. - /** - \param ims Initial mesh size -- \b IN. - \param relative Indicated as relative values - -- \b IN -- \b optional (default = \c false). - */ - void set_INITIAL_MESH_SIZE ( const NOMAD::Point & ims , bool relative = false ); - - // Directions: - // ----------- - private: - - /// Types of poll directions. - std::set<NOMAD::direction_type> _direction_types; - - /// Types of directions for the secondary poll. - std::set<NOMAD::direction_type> _sec_poll_dir_types; - - - /// Halton seed for Ortho-MADS directions. - /** - If the default value of \c -1 is left, - the Halton seed is decided by NOMAD::Directions. - */ - int _halton_seed; - - /// Change direction types to prevent using models for finding the (n+1)th direction - /// Apply if ORTHO N+1 QUAD -> ORTHO N+1 NEG. - void set_DIRECTION_TYPE_NO_MODEL ( void ); - - - public: - - /// Access to the list of poll direction types. - /** - \return The list of poll direction types. - */ - const std::set<NOMAD::direction_type> & get_direction_types ( void ) const; - - /// Access to the list of secondary poll direction types. - /** - \return The list of secondary poll direction types. - */ - const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const; - - - /// Check if there are Ortho-MADS directions. - /** - \return A boolean equal to \c true if there is at least one - Ortho-MADS direction in the list of poll directions - or in the list of secondary poll directions. - */ - bool has_orthomads_directions ( void ) const; - - - /// Check if a direction type that required dynamic completion for the (n+1)th direction. - /** - \return true if a dynamic completion is required. - */ - bool has_dynamic_direction(void) const; - - - - /// Access to the Halton seed. - /** - \return The Halton seed. - */ - int get_halton_seed ( void ) const; - - /// Reset the directions. - /** - \param halton_seed Halton seed -- \b IN. - */ - void reset_directions ( int halton_seed ); - - /// Add a new direction type. - /** - \param dt The new direction type -- \b IN. - */ - void set_DIRECTION_TYPE ( NOMAD::direction_type dt ); - - /// Add a set of new direction types. - /** - \param dt The set of new direction types -- \b IN. - */ - void set_DIRECTION_TYPE ( const std::set<NOMAD::direction_type> & dt ); - - - /// Add a new direction type for the secondary poll. - /** - \param dt The new direction type -- \b IN. - */ - void set_SEC_POLL_DIR_TYPE ( NOMAD::direction_type dt ); - - /// Add a set of new direction types for the secondary poll. - /** - \param dt The set of new direction types -- \b IN. - */ - void set_SEC_POLL_DIR_TYPE ( const std::set<NOMAD::direction_type> & dt ); - - /// Set the Halton seed. - /** - \param hs The Halton seed -- \b IN. - */ - void set_HALTON_SEED ( int hs ); - - - /// Enables use of quad model to determine prospect direction - /// for Ortho n+1 direction type - /** - \param qmpd boolean -- \b IN. - */ - void set_QUAD_MODEL_PROSPECT_DIR ( bool qmpd ) ; - - // Starting point(s): - // ------------------ - private: - - std::vector<NOMAD::Point *> _x0s; ///< List of starting points. - std::string _x0_cache_file; ///< Cache file containing starting points. - - public: - - /// Add a new point in the list of starting points. - /** - \param x0 The new point -- \b IN. - */ - void set_X0 ( const NOMAD::Point & x0 ); - - /// Indicate a cache file containing starting points. - /** - \param file_name Name of the cache file -- \b IN. - */ - void set_X0 ( const std::string & file_name ); - - /// Reset all string points. - void reset_X0 ( void ); - - /// Access to the list of starting points. - /** - \return The list of starting points. - */ - const std::vector<NOMAD::Point *> & get_x0s ( void ) const; - - /// Access to the name of a cache file containing starting points. - /** - \return The file name. - */ - const std::string & get_x0_cache_file ( void ) const; - - // Signature: standard or extern (only one is != NULL): - // ---------------------------------------------------- - private: - - /// Standard signature. - /** - Created and deleted by the Parameters class. - */ - NOMAD::Signature * _std_signature; - - /// Extern signature. - /** - Created and deleted outside the class. - */ - NOMAD::Signature * _extern_signature; - - public: - - /// Access to the signature. - /** - \return The one non-NULL signature. - */ - NOMAD::Signature * get_signature ( void ) const; - - /// Set a new extern signature. - /** - Deletes the standard signature. - \param s A pointer to the extern signature -- \b IN. - */ - void set_EXTERN_SIGNATURE ( NOMAD::Signature * s ); - - // Dimension: - // ---------- - private: - - /// Dimension. - /** - - Number of variables. - - Parameter \c DIMENSION. - */ - int _dimension; - - public: - - /// Access to the dimension. - /** - \return The dimension. - */ - int get_dimension ( void ) const; - - /// Set the dimension. - /** - \param n The dimension -- \b IN. - \return \c true if the operation succeeded. - */ - bool set_DIMENSION ( int n ); - - // Fixed variables: - // ---------------- - private: - - /// Fixed variables. - /** - - This point is of dimension \c n (parameter \c DIMENSION). - - Undefined values correspond to free variables. - */ - NOMAD::Point _fixed_variables; - - /// Number of free variables. - int _nb_free_variables; - - public: - - /// Access to the number of free variables. - /** - \return The number of free variables. - */ - int get_nb_free_variables ( void ) const; - - /// Access to the fixed variables. - /** - \return The fixed variables. - */ - const NOMAD::Point & get_fixed_variable ( void ) const - { - return get_fixed_variables(); - } - - /// Access to the fixed variables. - /** - \return The fixed variables. - */ - const NOMAD::Point & get_fixed_variables ( void ) const; - - /// Test if a variable is fixed. - /** - \param i Index of the variable -- \b IN. - \return A boolean equal to \c true if the variable \c i is fixed. - */ - bool variable_is_fixed ( int i ) const; - - /// Reset the fixed variables. - /** - This frees all the variables. - */ - void reset_fixed_variables ( void ); - - /// Fix one variable. - /** - \param i Index of the variable -- \b IN. - \param value Value of the fixed variable -- \b IN. - */ - void set_FIXED_VARIABLE ( int i , const NOMAD::Double & value ); - - /// Fix one variable. - /** - The value of the variable is based on the starting point. - \param i Index of the variable -- \b IN. - */ - void set_FIXED_VARIABLE ( int i ); - - /// Fix a series of variables. - /** - \param fv The fixed variables; This point is of dimension \c n; - free variables correspond to undefined values -- \b IN. - */ - void set_FIXED_VARIABLE ( const NOMAD::Point & fv ); - - /// Free a variable. - /** - \param i Index of the variable -- \b IN. - */ - void set_FREE_VARIABLE ( int i ) { set_FIXED_VARIABLE ( i , NOMAD::Double() ); } - - // Periodic variables: - // ------------------- - - /// Periodic variables. - /** - - This vector is of size \c n. - - \c _periodic_variables[i] is equal to \c true if - the variable \c i is periodic. - */ - std::vector<bool> _periodic_variables; - - /// Access to the periodic variables. - /** - \return The periodic variables - */ - const std::vector<bool> & get_periodic_variable ( void ) const - { - return get_periodic_variables(); - } - - /// Access to the periodic variables. - /** - \return The periodic variables - */ - const std::vector<bool> & get_periodic_variables ( void ) const; - - /// Check if there is periodic variables. - /** - \return A boolean equal to \c true if there is periodic variables. - */ - bool has_periodic_variables ( void ) const - { - return !_periodic_variables.empty(); - } - - /// Reset periodic variables. - void reset_periodic_variables ( void ); - - /// Set one variable to be periodic. - /** - \param i Index of the variable -- \b IN. - */ - void set_PERIODIC_VARIABLE ( int i ); - - /// Set a series of variables to be periodic. - /** - \param pv Vector of size \c n indicating the - periodic variables -- \b IN. - */ - void set_PERIODIC_VARIABLE ( const std::vector<bool> & pv ); - - // Categorical variables: - // ---------------------- - private: - - /// Extended poll trigger. - /** - - Must be strictly positive. - - May be relative. - */ - NOMAD::Double _extended_poll_trigger; - - /// Equal to \c true if the extended poll trigger is relative. - bool _relative_ept; - - /// Equal to \c true if the extended poll is enabled. - bool _extended_poll_enabled; - - /// Neighborhood executable for using batch mode with categorical variables. - std::string _neighbors_exe; - - public: - - /// Access to the extended poll trigger. - /** - \return The extended poll trigger. - */ - const NOMAD::Double & get_extended_poll_trigger ( void ) const; - - /// Check if the extended poll trigger is relative. - /** - \return A boolean equal to \c true if the extended poll trigger is relative. - */ - bool get_relative_ept ( void ) const; - - /// Check if the extended poll is enabled. - /** - \return A boolean equal to \c true if the extended poll is enabled. - */ - bool get_extended_poll_enabled ( void ) const; - - /// Access to the neighborhood executable. - /** - \return The neighborhood executable. - */ - const std::string & get_neighbors_exe ( void ) const; - - /// Set the extended poll trigger. - /** - \param ept The extended poll trigger -- \b IN. - \param rel A boolean equal to \c true if the extended poll - trigger is relative -- \b IN. - */ - void set_EXTENDED_POLL_TRIGGER ( const NOMAD::Double & ept , bool rel ); - - /// Enable or disable the extended poll. - /** - \param epe A boolean equal to \c true if the extended poll is enabled -- \b IN. - */ - void set_EXTENDED_POLL_ENABLED ( bool epe ); - - /// Set the neighborhood executable. - /** - \param ne The neighborhood executable. - */ - void set_NEIGHBORS_EXE ( const std::string & ne ); - - // Groups of variables: - // -------------------- - private: - - /// Groups of variables. - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> _var_groups; - - /// User groups of variables. - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> _user_var_groups; - - /// Reset a group of variables. - /** - \param g Group to reset; may be \c _var_groups or \c _user_var_groups - -- \b IN/OUT. - */ - void reset_variable_groups - ( std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & g ) const; - - public: - - /// Reset groups of variables. - void reset_variable_groups ( void ); - - /// Access to the groups of variables. - /** - \return The groups of variables. - */ - const std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & - get_variable_groups ( void ) const; - - /// Set one group of variables. - /** - Basic version. - \param var_indexes Indexes of the variables of the group -- \b IN. - \param halton_seed Halton seed - -- \b IN -- \b optional (default = \c -1). - */ - void set_VARIABLE_GROUP ( const std::set<int> & var_indexes , - int halton_seed = -1 ); - - /// Set one group of variables. - /** - Advanced version. - \param var_indexes Indexes of the variables of the group -- \b IN. - \param prim_poll_dir_types Types of the poll directions -- \b IN. - \param sec_poll_dir_types Types of the secondary poll directions -- \b IN. - \param halton_seed Halton seed -- \b IN. - */ - void set_VARIABLE_GROUP - ( const std::set<int> & var_indexes , - const std::set<NOMAD::direction_type> & prim_poll_dir_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed ); - - /// Set several groups of variables. - /** - \param vg A list of groups of variables -- \b IN. - */ - void set_VARIABLE_GROUP ( const std::list<NOMAD::Variable_Group*> & vg ); - - // Bounds and scaling: - // ------------------- - private: - - NOMAD::Point _lb; ///< Lower bounds. - NOMAD::Point _ub; ///< Upper bounds. - NOMAD::Point _scaling; ///< Scaling. - - public: - - /// Access to the lower bounds. - /** - \return The lower bounds. - */ - const NOMAD::Point & get_lb ( void ) const; - - /// Access to the upper bounds. - /** - \return The upper bounds. - */ - const NOMAD::Point & get_ub ( void ) const; - - /// Access to the lower bounds. - /** - \return The lower bounds. - */ - const NOMAD::Point & get_lower_bound ( void ) const { return get_lb(); } - - /// Access to the upper bounds. - /** - \return The upper bounds. - */ - const NOMAD::Point & get_upper_bound ( void ) const { return get_ub(); } - - /// Access to the scaling. - /** - \return The scaling. - */ - const NOMAD::Point & get_scaling ( void ) const; - - /// Reset the bounds. - void reset_bounds ( void ); - - /// Reset the scaling. - void reset_scaling ( void ); - - /// Set one lower bound. - /** - \param i Index of the variable -- \b IN. - \param lb Lower bound -- \b IN. - */ - void set_LOWER_BOUND ( int i , const NOMAD::Double & lb ); - - /// Set all lower bounds. - /** - Use undefined values for variables without bounds. - \param lb Lower bounds -- \b IN. - */ - void set_LOWER_BOUND ( const NOMAD::Point & lb ); - - /// Set one upper bound. - /** - \param i Index of the variable -- \b IN. - \param ub Upper bound -- \b IN. - */ - void set_UPPER_BOUND ( int i , const NOMAD::Double & ub ); - - /// Set all upper bounds. - /** - Use undefined values for variables without bounds. - \param ub Upper bounds -- \b IN. - */ - void set_UPPER_BOUND ( const NOMAD::Point & ub ); - - /// Set the scaling of one variable. - /** - \param i Index of the variable -- \b IN. - \param s Scaling -- \b IN. - */ - void set_SCALING ( int i , const NOMAD::Double & s ); - - /// Set the scaling for all variables. - /** - Use undefined values for variables scaling. - \param s Scaling -- \b IN. - */ - void set_SCALING ( const NOMAD::Point & s ); - - // Blackboxes (inputs and outputs): - // -------------------------------- - private: - - /// Blackbox input types. - std::vector<NOMAD::bb_input_type> _bb_input_type; - - /// Parameter \c BB_INPUT_INCLUDE_TAG. - bool _bb_input_include_tag; - - /// Parameter \c BB_INPUT_INCLUDE_SEED. - bool _bb_input_include_seed; - - /// Blackbox output types. - /** - May be modified during the algorithm (PEB constraints). - */ - mutable std::vector<NOMAD::bb_output_type> _bb_output_type; - - /// List of blackbox executables. - std::list<std::string> _bb_exe; - - /// List of objective indexes. - std::list<int> _index_obj; - - /// Index for the output \c STAT_SUM. - int _index_stat_sum; - - /// Index for the output \c STAT_AVG. - int _index_stat_avg; - - /// Index for the output \c CNT_EVAL. - /** - - \c 0 or \c 1. - - \c CNT_EVAL indicates if a blackbox evaluation has to be counted. - */ - int _index_cnt_eval; - - /// Parameter \c BB_REDIRECTION. - bool _bb_redirection; - - public: - - /// Access to the number of blackbox outputs. - /** - \return The number of blackbox outputs. - */ - int get_bb_nb_outputs ( void ) const; - - /// Access to the \c BB_INPUT_INCLUDE_TAG parameter. - /** - \return The \c BB_INPUT_INCLUDE_TAG parameter. - */ - bool get_bb_input_include_tag ( void ) const; - - /// Access to the \c BB_INPUT_INCLUDE_SEED parameter. - /** - \return The \c BB_INPUT_INCLUDE_SEED parameter. - */ - bool get_bb_input_include_seed ( void ) const; - - /// Access to the blackbox input types. - /** - \return The blackbox input types. - */ - const std::vector<NOMAD::bb_input_type> & get_bb_input_type ( void ) const; - - /// Access to the blackbox output types. - /** - \return The blackbox output types. - */ - const std::vector<NOMAD::bb_output_type> & get_bb_output_type ( void ) const; - - /// Access to the objective indexes. - /** - \return The list of objective indexes. - */ - const std::list<int> & get_index_obj ( void ) const; - - /// Access to the number of objective functions. - /** - \return The number of objective functions. - */ - int get_nb_obj ( void ) const; - - /// Check the display and file stats. - /** - \param stats The stats -- \b IN. - \return A booleam equal to \c true if the stats are valid. - */ - bool check_display_stats ( const std::list<std::string> & stats ) const; - - /// Check if there is a \c STAT_SUM output. - /** - \return A boolean equal to \c true if there a \c STAT_SUM output. - */ - bool check_stat_sum ( void ) const; - - /// Check if there is a \c STAT_AVG output. - /** - \return A boolean equal to \c true if there is a \c STAT_AVG output. - */ - bool check_stat_avg ( void ) const; - - /// Access the index of output \c CNT_EVAL output. - /** - \return Index of the \c CNT_EVAL output. - \return \c -1 if there is no \c CNT_EVAL output. - */ - int get_index_cnt_eval ( void ) const; - - /// Access the index of output \c STAT_SUM output. - /** - \return Index of the \c STAT_SUM output. - \return \c -1 if there is no \c STAT_SUM output. - */ - int get_index_stat_sum ( void ) const; - - /// Access the index of output \c STAT_AVG output. - /** - \return Index of the \c STAT_AVG output. - \return \c -1 if there is no \c STAT_AVG output. - */ - int get_index_stat_avg ( void ) const; - - /// Access to the list of blackbox executables. - /** - \return The list of blackbox executables. - */ - const std::list<std::string> & get_bb_exe ( void ) const; - - /// Access to the \c BB_REDIRECTION parameter. - /** - \return The \c BB_REDIRECTION parameter. - */ - bool get_bb_redirection ( void ) const; - - /// Set the \c BB_INPUT_INCLUDE_TAG parameter. - /** - \param bbiit The \c BB_INPUT_INCLUDE_TAG parameter -- \b IN. - */ - void set_BB_INPUT_INCLUDE_TAG ( bool bbiit ); - - /// Set the \c BB_INPUT_INCLUDE_SEED parameter. - /** - \param bbiis The \c BB_INPUT_INCLUDE_SEED parameter -- \b IN. - */ - void set_BB_INPUT_INCLUDE_SEED ( bool bbiis ); - - /// Set the blackbox input type of one variable. - /** - \param index Index of the variable -- \b IN. - \param bbit Type of the variable -- \b IN. - */ - void set_BB_INPUT_TYPE ( int index , NOMAD::bb_input_type bbit ); - - /// Set the blackbox input types of all variables. - /** - \param bbit Types of the variables -- \b IN. - */ - void set_BB_INPUT_TYPE ( const std::vector<NOMAD::bb_input_type> & bbit ); - - /// Set the blackbox input types of all variables. - /** - \param bbit Types of the variables -- \b IN. - */ - void set_BB_INPUT_TYPE ( const std::list<NOMAD::bb_input_type> & bbit ); - - /// Set the blackbox output types. - /** - \param bbot Blackbox output types -- \b IN. - */ - void set_BB_OUTPUT_TYPE ( const std::list<NOMAD::bb_output_type> & bbot ); - - /// Set the blackbox output types. - /** - \param bbot Blackbox output types -- \b IN. - */ - void set_BB_OUTPUT_TYPE ( const std::vector<NOMAD::bb_output_type> & bbot ); - - /// Set a list of blackbox executable names. - /** - Must correspond to the blackbox output types. - \param bbexe The list of blackbox executable names -- \b IN. - */ - void set_BB_EXE ( const std::list<std::string> & bbexe ); - - /// Set a list of blackbox executable names. - /** - \param m Number of blackbox outputs and size of \c bbexe -- \b IN. - \param bbexe The list of blackbox executable names -- \b IN. - */ - void set_BB_EXE ( int m , const std::string * bbexe ); - - /// Set a unique blackbox executable name. - /** - \param bbexe The blackbox executable name -- \b IN. - */ - void set_BB_EXE ( const std::string & bbexe ); - - /// Set the \c BB_REDIRECTION parameter. - /** - \param bbr The \c BB_REDIRECTION parameter -- \b IN. - */ - void set_BB_REDIRECTION ( bool bbr ); - - /// Reset the PEB statuses. - /** - Set all outputs at NOMAD::PEB_E (PEB constraint in "extreme" status) - to NOMAD::PEB_P (PEB constraint in "progressive" status). - */ - void reset_PEB_changes ( void ) const; - - /// Change constraints from PEB to PB. - /** - Set all outputs at NOMAD::PEB to NOMAD::PB - */ - void change_PEB_to_PB ( void ); - - /// Change the status of one PEB constraint. - /** - The status is changed from - NOMAD::PEB_P (PEB constraint in "progressive" status) - to NOMAD::PEB_E (PEB constraint in "extreme" status). - \param index Index of the PEB constraint. - */ - void change_PEB_constraint_status ( int index ) const; - - // Surrogates: - // ----------- - private: - - /// Surrogate executables. - /** - \c _sgte_exe[bb_exe] corresponds to the surrogate associated - with the blackbox true executable \c bb_exe. - */ - std::map<std::string,std::string> _sgte_exe; - - /// Flag equal to \c true if surrogates are used to sort evaluation points. - bool _sgte_eval_sort; - - /// Flag equal to \c true if the problem has a surrogate. - bool _has_sgte; - - /// Flag equal to \c true if NOMAD considers only surrogates. - bool _opt_only_sgte; - - /// Surrogate cost. - /** - Number of surrogate evaluations counting as one blackbox evaluation. - */ - int _sgte_cost; - - /// Maximum number of surrogate evaluations. - int _sgte_max_eval; - - /// Surrogate cache file. - std::string _sgte_cache_file; - - public: - - /// Access to the surrogate associated with a truth executable. - /** - \param bb_exe The truth executable -- \b IN. - \return The surrogate executable name. - \return An empty string if \c bb_exe has no surrogate. - */ - std::string get_sgte_exe ( const std::string & bb_exe ) const; - - /// Access to the \c SGTE_EVAL_SORT parameter. - /** - \return The \c SGTE_EVAL_SORT parameter. - */ - bool get_sgte_eval_sort ( void ) const; - - /// Access to the \c SGTE_COST parameter. - /** - \return The \c SGTE_COST parameter. - */ - int get_sgte_cost ( void ) const; - - /// Access to the \c MAX_SGTE_EVAL parameter. - /** - \return The \c MAX_SGTE_EVAL parameter. - */ - int get_max_sgte_eval ( void ) const; - - /// Access to the \c SGTE_CACHE_FILE parameter. - /** - \return The \c SGTE_CACHE_FILE parameter. - */ - const std::string & get_sgte_cache_file ( void ) const; - - /// Access to the \c HAS_SGTEparameter. - /** - \return The \c HAS_SGTEparameter. - */ - bool has_sgte ( void ) const; - - /// Access to the \c OPT_ONLY_SGTE parameter. - /** - \return The \c OPT_ONLY_SGTE parameter. - */ - bool get_opt_only_sgte ( void ) const; - - /// Check if a surrogate executable has been defined. - /** - \return A boolean equal to \c true if - a surrogate executable has been defined. - */ - bool has_sgte_exe ( void ) const; - - /// Set the \c SGTE_EXE parameter. - /** - \param bb_exe Truth executable -- \b IN. - \param sgte_exe Associated surrogate executable -- \b IN. - */ - void set_SGTE_EXE ( const std::string & bb_exe , const std::string & sgte_exe ); - - /// Set the \c SGTE_EVAL_SORT parameter. - /** - \param ses The \c SGTE_EVAL_SORT parameter -- \b IN. - */ - void set_SGTE_EVAL_SORT ( bool ses ); - - /// Set the \c HAS_SGTE parameter. - /** - \param hs The \c HAS_SGTE parameter -- \b IN. - */ - void set_HAS_SGTE ( bool hs ); - - /// Set the \c OPT_ONLY_SGTE parameter. - /** - \param oos The \c OPT_ONLY_SGTE parameter -- \b IN. - */ - void set_OPT_ONLY_SGTE ( bool oos ); - - /// Set the \c SGTE_COST parameter. - /** - \param sc The \c SGTE_COST parameter -- \b IN. - */ - void set_SGTE_COST ( int sc ); - - /// Set the \c MAX_SGTE_EVAL parameter. - /** - \param mse The \c MAX_SGTE_EVAL parameter -- \b IN. - */ - void set_MAX_SGTE_EVAL ( int mse ); - - /// Set the \c SGTE_CACHE_FILE parameter. - /** - \param scf The \c SGTE_CACHE_FILE parameter -- \b IN. - */ - void set_SGTE_CACHE_FILE ( const std::string & scf ); - - // Barrier: - // -------- - private: - NOMAD::Double _h_min; ///< Value of \c h_min. - NOMAD::Double _h_max_0; ///< Initial value of \c h_max. - NOMAD::Double _rho; ///< Rho parameter of the progressive barrier. - NOMAD::hnorm_type _h_norm; ///< Norm used to compute the feasibility function \c h. - - /// Flag equal to \c true if there are constraints. - bool _has_constraints; - - /// Flag equal to \c true if there are filter or progressive barrier constraints. - bool _has_filter_constraints; - - /// Flag equal to \c true if there are extreme barrier constraints. - bool _has_EB_constraints; - - /// Type of the barrier. - /** - May be NOMAD::FILTER, NOMAD::PB, NOMAD::PEB_P, or NOMAD::EB. - */ - NOMAD::bb_output_type _barrier_type; - - public: - - /// Access to the \c H_MIN parameter. - /** - \return The \c H_MIN parameter. - */ - const NOMAD::Double & get_h_min ( void ) const; - - /// Access to the \c H_MAX_0 parameter. - /** - \return The \c H_MAX_0 parameter. - */ - const NOMAD::Double & get_h_max_0 ( void ) const; - - /// Access to the \c RHO parameter. - /** - \return The \c RHO parameter. - */ - const NOMAD::Double & get_rho ( void ) const; - - /// Access to the \c H_NORM parameter. - /** - \return The \c H_NORM parameter. - */ - NOMAD::hnorm_type get_h_norm ( void ) const; - - /// Access to the type of barrier. - /** - \return The type of barrier. - */ - NOMAD::bb_output_type get_barrier_type ( void ) const; - - /// Check if there are constraints. - /** - \return A boolean equal to \c true if there are constraints. - */ - bool has_constraints ( void ) const; - - /// Check if there are extreme barrier constraints. - /** - \return A boolean equal to \c true if there are extreme barrier constraints. - */ - bool has_EB_constraints ( void ) const; - - /// Check if the progressive barrier (PB) is used. - /** - \return A boolean equal to \c true if the PB is used. - */ - bool use_sec_poll_center ( void ) const; - - /// Set the \c H_MIN parameter. - /** - \param h_min The \c H_MIN parameter -- \b IN. - */ - void set_H_MIN ( const NOMAD::Double & h_min ); - - /// Set the \c H_MAX_0 parameter. - /** - \param h_max The \c H_MAX_0 parameter -- \b IN. - */ - void set_H_MAX_0 ( const NOMAD::Double & h_max ); - - /// Set the \c RHO parameter. - /** - \param rho The \c RHO parameter -- \b IN. - */ - void set_RHO ( const NOMAD::Double & rho ); - - /// Set the \c H_NORM parameter. - /** - \param h_norm The \c H_NORM parameter -- \b IN. - */ - void set_H_NORM ( NOMAD::hnorm_type h_norm ); - - // MULTI-MADS parameters: - // ---------------------- - private: - - /// Number of MADS runs in Multi-MADS. - int _multi_nb_mads_runs; - - /// Maximum number of blackbox evaluations in Multi-MADS. - int _multi_overall_bb_eval; - - /// Flag equal to \c true if the delta criterion is used in Multi-MADS. - bool _multi_use_delta_crit; - - /// Bounds on the objective necessary for the display of the \c surf stat. - NOMAD::Point _multi_f_bounds; - - /// Multi-MADS reformulation. - /** - May be NOMAD::NORMALIZED, NOMAD::PRODUCT, - NOMAD::DIST_L1, NOMAD::DIST_L2, or NOMAD::DIST_LINF. - */ - NOMAD::multi_formulation_type _multi_formulation; - - public: - - /// Access to the \c MULTI_NB_MADS_RUNS parameter. - /** - \return The \c MULTI_NB_MADS_RUNS parameter. - */ - int get_multi_nb_mads_runs ( void ) const; - - /// Access to the \c MULTI_OVERALL_BB_EVAL parameter. - /** - \return The \c MULTI_OVERALL_BB_EVAL parameter. - */ - int get_multi_overall_bb_eval ( void ) const; - - /// Access to the \c MULTI_USE_DELTA_CRIT parameter. - /** - \return The \c MULTI_USE_DELTA_CRIT parameter. - */ - bool get_multi_use_delta_crit ( void ) const; - - /// Access to the \c MULTI_F_BOUNDS parameter. - /** - \return The \c MULTI_F_BOUNDS parameter. - */ - const NOMAD::Point & get_multi_f_bounds ( void ) const; - - /// Access to the \c MULTI_FORMULATION parameter. - /** - \return The \c MULTI_FORMULATION parameter. - */ - NOMAD::multi_formulation_type get_multi_formulation ( void ) const; - - /// Set the \c MULTI_NB_MADS_RUNS parameter. - /** - \param mads_runs The \c MULTI_NB_MADS_RUNS parameter -- \b IN. - */ - void set_MULTI_NB_MADS_RUNS ( int mads_runs ); - - /// Set the \c MULTI_OVERALL_BB_EVAL parameter. - /** - \param bbe The \c MULTI_OVERALL_BB_EVAL parameter -- \b IN. - */ - void set_MULTI_OVERALL_BB_EVAL ( int bbe ); - - /// Set the \c MULTI_USE_DELTA_CRIT parameter. - /** - \param udc The \c MULTI_USE_DELTA_CRIT parameter -- \b IN. - */ - void set_MULTI_USE_DELTA_CRIT ( bool udc ); - - /// Set the \c MULTI_F_BOUNDS parameter. - /** - \param mfb The \c MULTI_F_BOUNDS parameter -- \b IN. - */ - void set_MULTI_F_BOUNDS ( const NOMAD::Point & mfb ); - - /// Set the \c MULTI_FORMULATION parameter. - /** - \param mf The \c MULTI_FORMULATION parameter -- \b IN. - */ - void set_MULTI_FORMULATION ( NOMAD::multi_formulation_type mf ); - - // Opportunistic strategy parameters: - // ---------------------------------- - private: - - /// Flag equal to \c true if the opportunistic strategy is enabled. - bool _opportunistic_eval; - - /// Minimum number of successes. - /** - Parameter \c OPPORTUNISTIC_MIN_NB_SUCCESS. - */ - int _opportunistic_min_nb_success; - - /// Minimum number of evaluations. - /** - Parameter \c OPPORTUNISTIC_MIN_EVAL. - */ - int _opportunistic_min_eval; - - /// Minimum (relative) percentage of feasible objective improvement. - /** - Parameter \c OPPORTUNISTIC_MIN_F_IMPRVMT. - */ - NOMAD::Double _opportunistic_min_f_imprvmt; - - /// Flag equal to \c true if the lucky evaluation is enabled. - /** - Do one more eval "for luck". - */ - bool _opportunistic_lucky_eval; - - public: - - /// Access to the \c OPPORTUNISTIC_EVAL parameter. - /** - \return The \c OPPORTUNISTIC_EVAL parameter - */ - bool get_opportunistic_eval ( void ) const; - - /// Access to the \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. - /** - \return The \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. - */ - int get_opportunistic_min_nb_success ( void ) const; - - /// Access to the \c OPPORTUNISTIC_MIN_EVAL parameter. - /** - \return The \c OPPORTUNISTIC_MIN_EVAL parameter. - */ - int get_opportunistic_min_eval ( void ) const; - - /// Access to the \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. - /** - \return The \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. - */ - const NOMAD::Double & get_opportunistic_min_f_imprvmt ( void ) const; - - /// Access to the \c OPPORTUNISTIC_LUCKY_EVAL parameter. - /** - \return The \c OPPORTUNISTIC_LUCKY_EVAL parameter. - */ - bool get_opportunistic_lucky_eval ( void ) const; - - /// Set the \c OPPORTUNISTIC_EVAL parameter. - /** - \param opp_eval The \c OPPORTUNISTIC_EVAL parameter -- \b IN. - */ - void set_OPPORTUNISTIC_EVAL ( bool opp_eval ); - - /// Set the \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter. - /** - \param opp_min_nb_succ The \c OPPORTUNISTIC_MIN_NB_SUCCESS parameter -- \b IN. - */ - void set_OPPORTUNISTIC_MIN_NB_SUCCESS ( int opp_min_nb_succ ); - - /// Set the \c OPPORTUNISTIC_MIN_EVAL parameter. - /** - \param opp_min_eval The \c OPPORTUNISTIC_MIN_EVAL parameter -- \b IN. - */ - void set_OPPORTUNISTIC_MIN_EVAL ( int opp_min_eval ); - - /// Set the \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter. - /** - \param opp_min_f_imprvt The \c OPPORTUNISTIC_MIN_F_IMPRVMT parameter -- \b IN. - */ - void set_OPPORTUNISTIC_MIN_F_IMPRVMT ( const NOMAD::Double & opp_min_f_imprvt ); - - /// Set the \c OPPORTUNISTIC_LUCKY_EVAL parameter. - /** - \param opp_lucky_eval The \c OPPORTUNISTIC_LUCKY_EVAL parameter -- \b IN. - */ - void set_OPPORTUNISTIC_LUCKY_EVAL ( bool opp_lucky_eval ); - }; - - /*----------------------------------------------------------------------*/ - - /// Display a NOMAD::Parameters object. - /** - \param out The NOMAD::Display object -- \b IN. - \param p The NOMAD::Parameters object to be displayed -- \b IN. - \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Parameters & p ) - { - p.display ( out ); - return out; - } } #endif diff --git a/src/Pareto_Front.cpp b/src/Pareto_Front.cpp index 0369f4884384f2e9558a68d6c87d16b4f420153c..0abcee593ad4602007a667adc201f9ee3823fd81 100644 --- a/src/Pareto_Front.cpp +++ b/src/Pareto_Front.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Pareto_Front.hpp b/src/Pareto_Front.hpp index 1b2c2be5168ff4303992fa5235d97a2015d94713..c7d251f5a2c9f0543d2ddc7d5460b9c5a27935c5 100644 --- a/src/Pareto_Front.hpp +++ b/src/Pareto_Front.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Pareto_Point.cpp b/src/Pareto_Point.cpp index 318289ee0263d09a47be01ba530f6523781c14ed..75ad0ae1cb7dcf608c9e4d66369d973bea23e1b8 100644 --- a/src/Pareto_Point.cpp +++ b/src/Pareto_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Pareto_Point.hpp b/src/Pareto_Point.hpp index ccfe632ab5d0a8a24eff4cd1afef1016a990f2bd..1d981f646c51333094190b8c99e886a850136a6c 100644 --- a/src/Pareto_Point.hpp +++ b/src/Pareto_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Phase_One_Evaluator.cpp b/src/Phase_One_Evaluator.cpp index e9697d4177368d7d81a5ec233c53fde73a5c6846..27d57ef89f42ad2b4f2220cdf9c9ca31ea516d76 100644 --- a/src/Phase_One_Evaluator.cpp +++ b/src/Phase_One_Evaluator.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Phase_One_Evaluator.cpp - \brief NOMAD::Evaluator subclass for the phase one (implementation) - \author Sebastien Le Digabel - \date 2010-04-09 - \see Phase_One_Evaluator.hpp -*/ + \file Phase_One_Evaluator.cpp + \brief NOMAD::Evaluator subclass for the phase one (implementation) + \author Sebastien Le Digabel + \date 2010-04-09 + \see Phase_One_Evaluator.hpp + */ #include "Phase_One_Evaluator.hpp" /*------------------------------------------------------------------*/ @@ -48,28 +48,30 @@ /*------------------------------------------------------------------*/ void NOMAD::Phase_One_Evaluator::compute_f ( NOMAD::Eval_Point & x ) const { - if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) { - std::ostringstream err; - err << "Phase_One_Evaluator::compute_f(x): " - << "x has a wrong number of blackbox outputs (" - << x.get_bb_outputs().size() << " != " << _p.get_bb_nb_outputs() << ")"; - throw NOMAD::Exception ( "Phase_One_Evaluator.cpp" , __LINE__ , err.str() ); - } - - // objective value for MADS phase 1: the squared sum of all EB constraint violations - // (each EB constraint has been previously transformed into OBJ values): - const std::list<int> & index_obj = _p.get_index_obj(); - const std::list<int>::const_iterator end = index_obj.end(); - const NOMAD::Point & bbo = x.get_bb_outputs(); - NOMAD::Double h_min = _p.get_h_min(); - NOMAD::Double sum = 0.0; - NOMAD::Double v; - - for ( std::list<int>::const_iterator it = index_obj.begin() ; it != end ; ++it ) { - v = bbo[*it]; - if ( v > h_min ) - sum += v.pow2(); - } - - x.set_f ( sum ); + if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) + { + std::ostringstream err; + err << "Phase_One_Evaluator::compute_f(x): " + << "x has a wrong number of blackbox outputs (" + << x.get_bb_outputs().size() << " != " << _p.get_bb_nb_outputs() << ")"; + throw NOMAD::Exception ( "Phase_One_Evaluator.cpp" , __LINE__ , err.str() ); + } + + // objective value for MADS phase 1: the squared sum of all EB constraint violations + // (each EB constraint has been previously transformed into OBJ values): + const std::list<int> & index_obj = _p.get_index_obj(); + const std::list<int>::const_iterator end = index_obj.end(); + const NOMAD::Point & bbo = x.get_bb_outputs(); + NOMAD::Double h_min = _p.get_h_min(); + NOMAD::Double sum = 0.0; + NOMAD::Double v; + + for ( std::list<int>::const_iterator it = index_obj.begin() ; it != end ; ++it ) + { + v = bbo[*it]; + if ( v > h_min ) + sum += v.pow2(); + } + + x.set_f ( sum ); } diff --git a/src/Phase_One_Evaluator.hpp b/src/Phase_One_Evaluator.hpp index 88d1bcc17973dbfe88d93c7ddcc003f7c7d0ea6a..a22ca4e274ee10f58f813677512889f362d33aea 100644 --- a/src/Phase_One_Evaluator.hpp +++ b/src/Phase_One_Evaluator.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,85 +34,133 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Phase_One_Evaluator.hpp - \brief NOMAD::Evaluator subclass for the phase one (headers) - \author Sebastien Le Digabel - \date 2010-04-22 - \see Phase_One_Evaluator.cpp -*/ + \file Phase_One_Evaluator.hpp + \brief NOMAD::Evaluator subclass for the phase one (headers) + \author Sebastien Le Digabel + \date 2010-04-22 + \see Phase_One_Evaluator.cpp + */ #ifndef __PHASE_ONE_EVALUATOR__ #define __PHASE_ONE_EVALUATOR__ #include "Evaluator.hpp" namespace NOMAD { - - /// NOMAD::Evaluator subclass for the phase one. - class Phase_One_Evaluator : public NOMAD::Evaluator { - - private: - - NOMAD::Evaluator & _basic_ev; ///< The original evaluator. - - public: - - /// Constructor. - /** - \param p Parameters -- \b IN. - \param ev Original evaluator -- \b IN. - */ - Phase_One_Evaluator ( const NOMAD::Parameters & p , NOMAD::Evaluator & ev ) - : NOMAD::Evaluator ( p ) , - _basic_ev ( ev ) {} - - /// Destructor. - virtual ~Phase_One_Evaluator ( void ) {} - - /// User updates after a success. - /** - This virtual method is called every time a new (full) success is made. - \param s Stats -- \b IN. - \param x Successful point -- \b IN. - */ - virtual void update_success ( const NOMAD::Stats & s , const NOMAD::Eval_Point & x ) - { - _basic_ev.update_success ( s , x ); - } - - /// Evaluate the blackboxes at a given trial point. - /** - \param x The trial point -- \b IN/OUT. - \param h_max Maximal feasibility value \c h_max -- \b IN. - \param count_eval Flag indicating if the evaluation has to be counted - or not -- \b OUT. - \return A boolean equal to \c false if the evaluation failed. - */ - virtual bool eval_x ( NOMAD::Eval_Point & x , - const NOMAD::Double & h_max , - bool & count_eval ) const - { - return _basic_ev.eval_x ( x , h_max , count_eval ); - } - - /// User preprocessing of points before evaluations. - /** - This method is called before the evaluation of a list of points. - \param pts List of points to preprocess -- \b IN/OUT. - */ - virtual void list_of_points_preprocessing - ( std::set<NOMAD::Priority_Eval_Point> & pts ) const - { - _basic_ev.list_of_points_preprocessing ( pts ); - } - /// Objective computation. - /** - - Compute \c f(x) from the blackbox outputs of a point. - - Special objective for MADS phase one. - \param x The trial point -- \b IN/OUT. - */ - virtual void compute_f ( NOMAD::Eval_Point & x ) const; - }; + /// NOMAD::Evaluator subclass for the phase one. + class Phase_One_Evaluator : public NOMAD::Evaluator { + + private: + + NOMAD::Evaluator & _basic_ev; ///< The original evaluator. + + public: + + /// Constructor. + /** + \param p Parameters -- \b IN. + \param ev Original evaluator -- \b IN. + */ + Phase_One_Evaluator ( const NOMAD::Parameters & p , NOMAD::Evaluator & ev ) + : NOMAD::Evaluator ( p ) , + _basic_ev ( ev ) {} + + /// Destructor. + virtual ~Phase_One_Evaluator ( void ) {} + + /// User updates after a success. + /** + This virtual method is called every time a new (full) success is made. + \param s Stats -- \b IN. + \param x Successful point -- \b IN. + */ + virtual void update_success ( const NOMAD::Stats & s , const NOMAD::Eval_Point & x ) + { + _basic_ev.update_success ( s , x ); + } + + /// Evaluate the blackboxes at a given trial point. + /** + \param x The trial point -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) const + { + return _basic_ev.eval_x ( x , h_max , count_eval ); + } + + + /// Evaluate the blackboxes at a given list of trial points. + /** + \param list_x The list of trial points -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param list_count_eval Flags indicating if the evaluations have to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( std::list<NOMAD::Eval_Point *> & list_x , + const NOMAD::Double & h_max , + std::list<bool> & list_count_eval ) const + { + return _basic_ev.eval_x ( list_x , h_max , list_count_eval ); + } + + + /// User preprocessing of points before evaluations. + /** + This method is called before the evaluation of a list of points. + \param pts List of points to preprocess -- \b IN/OUT. + */ + virtual void list_of_points_preprocessing + ( std::set<NOMAD::Priority_Eval_Point> & pts ) const + { + _basic_ev.list_of_points_preprocessing ( pts ); + } + + + /// Access to the model evaluator flag. + /** + \return The model evaluator flag. + */ + virtual bool is_model_evaluator ( void ) const + { + return _basic_ev.is_model_evaluator(); + } + + /// User updates after an iteration. + /** + This virtual method is called every time a MADS iteration is terminated. + \param success Success of the iteration -- \b IN. + \param stats Stats -- \b IN. + \param ev_control The NOMAD::Evaluator_Control object -- \b IN. + \param true_barrier Barrier for true evaluations -- \b IN. + \param sgte_barrier Barrier for surrogate evaluations -- \b IN. + \param pareto_front Pareto front -- \b IN. + \param stop Allows the user to stop the algorithm -- \b OUT. + */ + virtual void update_iteration ( NOMAD::success_type success , + const NOMAD::Stats & stats , + const NOMAD::Evaluator_Control & ev_control , + const NOMAD::Barrier & true_barrier , + const NOMAD::Barrier & sgte_barrier , + const NOMAD::Pareto_Front & pareto_front , + bool & stop ) {} + + + + /// Objective computation. + /** + - Compute \c f(x) from the blackbox outputs of a point. + - Special objective for MADS phase one. + \param x The trial point -- \b IN/OUT. + */ + virtual void compute_f ( NOMAD::Eval_Point & x ) const; + }; } #endif diff --git a/src/Phase_One_Search.cpp b/src/Phase_One_Search.cpp index 1a9ed3e22f873e6d8a6aa99ca7549d7a2f61c488..d058fe2288534de79f11985d9945efc631c5d192 100644 --- a/src/Phase_One_Search.cpp +++ b/src/Phase_One_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Phase_One_Search.cpp - \brief NOMAD::Search subclass for the phase one (implementation) - \author Sebastien Le Digabel - \date 2010-04-09 - \see Phase_One_Search.hpp -*/ + \file Phase_One_Search.cpp + \brief NOMAD::Search subclass for the phase one (implementation) + \author Sebastien Le Digabel + \date 2010-04-09 + \see Phase_One_Search.hpp + */ #include "Phase_One_Search.hpp" /*-------------------------------------------------------------*/ @@ -47,279 +47,283 @@ /* (try to satisfy EB constraints) */ /*-------------------------------------------------------------*/ void NOMAD::Phase_One_Search::search ( NOMAD::Mads & mads , - int & nb_search_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - bool & count_search , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_search_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + bool & count_search , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - new_feas_inc = new_infeas_inc = NULL; - nb_search_pts = 0; - success = NOMAD::UNSUCCESSFUL; - stop = false; - count_search = true; - - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - - // initial display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << NOMAD::P1_SEARCH; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - // stats: - NOMAD::Stats & stats = mads.get_stats(); - - // counters: - int old_bbe = stats.get_bb_eval(); - int old_it = stats.get_iterations(); - - // Evaluator_Control: - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // save and modify parameters: - std::string old_display_degree; - _p.out().get_display_degree ( old_display_degree ); - const std::list<std::string> old_ds = _p.get_display_stats(); - NOMAD::Double old_VNS_trigger = _p.get_VNS_trigger(); - const std::string old_stats_file_name = _p.get_stats_file_name(); - const std::string old_sol_file = _p.get_solution_file(); - const std::list<std::string> old_stats_file = _p.get_stats_file(); - const NOMAD::Point old_f_target = _p.get_f_target(); - NOMAD::Double old_lct = _p.get_L_curve_target(); - bool old_sif = _p.get_stop_if_feasible(); - const std::vector<NOMAD::bb_output_type> old_bbot = _p.get_bb_output_type(); - std::vector<NOMAD::bb_output_type> p1_bbot = old_bbot; - - - if ( display_degree == NOMAD::NORMAL_DISPLAY) // Normal display -> minimal display for Phase one - _p.set_DISPLAY_DEGREE( NOMAD::MINIMAL_DISPLAY); - else if (display_degree == NOMAD::FULL_DISPLAY) - _p.set_DISPLAY_DEGREE( NOMAD::FULL_DISPLAY);// Full display -> full display for Phase one - - - - int m = static_cast<int> ( old_bbot.size() ); - int cnt = 0; - for ( int i = 0 ; i < m ; ++i ) { - if ( old_bbot[i] == NOMAD::EB ) { - p1_bbot[i] = NOMAD::OBJ; - ++cnt; - } - else if ( old_bbot[i] == NOMAD::OBJ ) - p1_bbot[i] = NOMAD::UNDEFINED_BBO; - } - - if ( cnt == 0 ) { - stop = true; - stop_reason = NOMAD::P1_FAIL; - return; - } - - _p.set_F_TARGET ( NOMAD::Point ( cnt , 0.0 ) ); - _p.set_L_CURVE_TARGET ( NOMAD::Double() ); - _p.set_STOP_IF_FEASIBLE ( false ); - _p.set_VNS_SEARCH ( false ); - _p.set_BB_OUTPUT_TYPE ( p1_bbot ); - _p.set_SOLUTION_FILE ( "" ); - _p.reset_stats_file(); - - // DISPLAY_STATS and STATS_FILE - { - std::list<std::string> ds = old_ds; - std::list<std::string> sf = old_stats_file; - ds.push_back ( " (PhaseOne)" ); - _p.set_DISPLAY_STATS ( ds ); - sf.push_back ( " (PhaseOne)" ); - _p.set_STATS_FILE ( old_stats_file_name , sf ); - - } - - - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - false ); // remove_stats_file = false - - // modify evaluator: - NOMAD::Evaluator * old_ev = ev_control.get_evaluator(); - NOMAD::Phase_One_Evaluator * p1ev = new NOMAD::Phase_One_Evaluator ( _p , *old_ev ); - ev_control.set_evaluator ( p1ev ); - - // disable the Pareto front: - NOMAD::Pareto_Front * old_pareto_front = mads.get_pareto_front(); - mads.set_pareto_front ( NULL ); - - int old_eval = stats.get_eval(); - - // run MADS with modified parameters: - // ---------------------------------- - - // C. Tribes march 2013 ---- these flags are mads static and must be put back to their original value after running mads (see below) - // get flags: - bool flag_check_bimads , flag_reset_mesh , flag_reset_barriers , flag_p1_active; - NOMAD::Mads::get_flags ( flag_check_bimads , - flag_reset_mesh , - flag_reset_barriers , - flag_p1_active ); - - - // set flags: - NOMAD::Mads::set_flag_check_bimads ( false ); - NOMAD::Mads::set_flag_reset_mesh ( false ); - NOMAD::Mads::set_flag_p1_active ( true ); - NOMAD::Mads::set_flag_reset_barriers ( true ); - - // run: - stop_reason = mads.run(); - - // reset stopping condition: - if ( stop_reason == NOMAD::F_TARGET_REACHED ) { - - // stop if feasible: - if ( old_sif ) { - stop = true; - stop_reason = NOMAD::FEAS_REACHED; - } - - // continue: - else { - stop = false; - stop_reason = NOMAD::NO_STOP; - } - } - else - stop = true; - - // reset flags to there previous state : - // C. Tribes march 2013 ---- these flags are mads static and must be put back to their original value after running mads - NOMAD::Mads::set_flag_check_bimads ( flag_check_bimads ); - NOMAD::Mads::set_flag_reset_mesh ( flag_reset_mesh ); - NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); - NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); - -// NOMAD::Mads::set_flag_check_bimads ( true ); -// NOMAD::Mads::set_flag_reset_mesh ( true ); -// NOMAD::Mads::set_flag_p1_active ( false ); - - // number of search points: - nb_search_pts = stats.get_eval() - old_eval; - - // restore evaluator: - ev_control.set_evaluator ( old_ev ); - delete p1ev; - - // restore the Pareto front: - mads.set_pareto_front ( old_pareto_front ); - - // restore parameters: - _p.set_VNS_SEARCH ( old_VNS_trigger ); - _p.set_F_TARGET ( old_f_target ); - _p.set_L_CURVE_TARGET ( old_lct ); - _p.set_BB_OUTPUT_TYPE ( old_bbot ); - _p.set_DISPLAY_DEGREE ( old_display_degree ); - _p.set_SOLUTION_FILE ( old_sol_file ); - _p.reset_stats_file(); - _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); - _p.set_DISPLAY_STATS (old_ds); - - _p.check ( false , // remove_history_file = false - true , // remove_solution_file = true - false ); // remove_stats_file = true - - // reset mesh index: - NOMAD::Mesh::set_mesh_index ( _p.get_initial_mesh_index() ); - - // counters: - stats.add_p1_iterations ( stats.get_iterations() - old_it ); - stats.add_p1_bbe ( stats.get_bb_eval () - old_bbe ); - - // for the update of new_feas_inc and new_infeas_inc (1/2): - const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); - const NOMAD::Eval_Point * old_feasible_incumbent = NULL; - const NOMAD::Eval_Point * old_infeasible_incumbent = NULL; - old_feasible_incumbent = active_barrier.get_best_feasible(); - old_infeasible_incumbent = active_barrier.get_best_infeasible(); - - // update the barriers and compute the true values - // of f and h for all evaluated points: - NOMAD::Barrier & true_barrier = mads.get_true_barrier(); - NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); - - true_barrier.reset(); - sgte_barrier.reset(); - - // scan the active cache: - const NOMAD::Cache & active_cache = mads.get_cache(); - if ( active_cache.empty() ) { - stop = true; - stop_reason = NOMAD::P1_FAIL; - return; - } - - const NOMAD::Eval_Point * cur = active_cache.begin(); - while ( cur ) { - - if ( cur->get_current_run() && cur->is_eval_ok() ) { - - NOMAD::Eval_Point * modifiable_x = &NOMAD::Cache::get_modifiable_point ( *cur ); - - modifiable_x->set_direction ( NULL ); - modifiable_x->set_mesh_index ( NULL ); - modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); - modifiable_x->set_user_eval_priority ( NOMAD::Double() ); - modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); - - old_ev->compute_f ( *modifiable_x ); - old_ev->compute_h ( *modifiable_x ); - - // insertion in barrier: - (( cur->get_eval_type() == NOMAD::TRUTH ) ? - true_barrier : sgte_barrier).insert (*cur); - } - cur = active_cache.next(); - } - - success = active_barrier.get_success(); - - if ( !stop && success == NOMAD::UNSUCCESSFUL ) { - stop = true; - stop_reason = NOMAD::P1_FAIL; - return; - } - - true_barrier.update_and_reset_success(); - sgte_barrier.update_and_reset_success(); - - // update of new_feas_inc and new_infeas_inc (2/2): - const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); - const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); - if ( bf && bf != old_feasible_incumbent ) - new_feas_inc = bf; - if ( bi && bi != old_infeasible_incumbent ) - new_infeas_inc = bi; - - // final displays: - if ( bf ) - { - - // solution file: - ev_control.write_solution_file ( *bf ); - - // stats_file: - const std::string & stats_file_name = _p.get_stats_file_name(); - if ( !stats_file_name.empty() && display_degree > NOMAD::NO_DISPLAY) - ev_control.stats_file ( stats_file_name , bf , true , NULL ); - - // display_stats - if (display_degree > NOMAD::NO_DISPLAY) - ev_control.display_stats(false, out, old_ds , bf , true , NULL ); - } - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::close_block ( "end of phase one" ); + new_feas_inc = new_infeas_inc = NULL; + nb_search_pts = 0; + success = NOMAD::UNSUCCESSFUL; + stop = false; + count_search = true; + + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + + // initial display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << NOMAD::P1_SEARCH; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + // stats: + NOMAD::Stats & stats = mads.get_stats(); + + // counters: + int old_bbe = stats.get_bb_eval(); + int old_it = stats.get_iterations(); + + // Evaluator_Control: + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // save and modify parameters: + std::string old_display_degree; + _p.out().get_display_degree ( old_display_degree ); + const std::list<std::string> old_ds = _p.get_display_stats(); + NOMAD::Double old_VNS_trigger = _p.get_VNS_trigger(); + const std::string old_stats_file_name = _p.get_stats_file_name(); + const std::string old_sol_file = _p.get_solution_file(); + const std::list<std::string> old_stats_file = _p.get_stats_file(); + const NOMAD::Point old_f_target = _p.get_f_target(); + NOMAD::Double old_lct = _p.get_L_curve_target(); + bool old_sif = _p.get_stop_if_feasible(); + const std::vector<NOMAD::bb_output_type> old_bbot = _p.get_bb_output_type(); + std::vector<NOMAD::bb_output_type> p1_bbot = old_bbot; + + + if ( display_degree == NOMAD::NORMAL_DISPLAY) // Normal display -> minimal display for Phase one + _p.set_DISPLAY_DEGREE( NOMAD::MINIMAL_DISPLAY); + else if (display_degree == NOMAD::FULL_DISPLAY) + _p.set_DISPLAY_DEGREE( NOMAD::FULL_DISPLAY);// Full display -> full display for Phase one + + + + int m = static_cast<int> ( old_bbot.size() ); + int cnt = 0; + for ( int i = 0 ; i < m ; ++i ) + { + if ( old_bbot[i] == NOMAD::EB ) + { + p1_bbot[i] = NOMAD::OBJ; + ++cnt; + } + else if ( old_bbot[i] == NOMAD::OBJ ) + p1_bbot[i] = NOMAD::UNDEFINED_BBO; + } + + if ( cnt == 0 ) { + stop = true; + stop_reason = NOMAD::P1_FAIL; + return; + } + + _p.set_F_TARGET ( NOMAD::Point ( cnt , 0.0 ) ); + _p.set_L_CURVE_TARGET ( NOMAD::Double() ); + _p.set_STOP_IF_FEASIBLE ( false ); + _p.set_VNS_SEARCH ( false ); + _p.set_BB_OUTPUT_TYPE ( p1_bbot ); + _p.set_SOLUTION_FILE ( "" ); + _p.reset_stats_file(); + + // DISPLAY_STATS and STATS_FILE + { + std::list<std::string> ds = old_ds; + std::list<std::string> sf = old_stats_file; + ds.push_back ( " (PhaseOne)" ); + _p.set_DISPLAY_STATS ( ds ); + sf.push_back ( " (PhaseOne)" ); + _p.set_STATS_FILE ( old_stats_file_name , sf ); + + } + + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + false ); // remove_stats_file = false + + // modify evaluator: + NOMAD::Evaluator * old_ev = ev_control.get_evaluator(); + NOMAD::Phase_One_Evaluator * p1ev = new NOMAD::Phase_One_Evaluator ( _p , *old_ev ); + ev_control.set_evaluator ( p1ev ); + + // disable the Pareto front: + NOMAD::Pareto_Front * old_pareto_front = mads.get_pareto_front(); + mads.set_pareto_front ( NULL ); + + int old_eval = stats.get_eval(); + + // run MADS with modified parameters: + // ---------------------------------- + + // C. Tribes march 2014 ---- these flags are mads static and must be put back to their original value after running mads (see below) + // get flags: + bool flag_check_bimads , flag_reset_mesh , flag_reset_barriers , flag_p1_active; + NOMAD::Mads::get_flags ( flag_check_bimads , + flag_reset_mesh , + flag_reset_barriers , + flag_p1_active ); + + + // set flags: + NOMAD::Mads::set_flag_check_bimads ( false ); + NOMAD::Mads::set_flag_reset_mesh ( false ); + NOMAD::Mads::set_flag_p1_active ( true ); + NOMAD::Mads::set_flag_reset_barriers ( true ); + + // run: + stop_reason = mads.run(); + + // reset stopping condition: + if ( stop_reason == NOMAD::F_TARGET_REACHED ) + { + + // stop if feasible: + if ( old_sif ) + { + stop = true; + stop_reason = NOMAD::FEAS_REACHED; + } + + // continue: + else { + stop = false; + stop_reason = NOMAD::NO_STOP; + } + } + else + stop = true; + + // reset flags to there previous state : + // C. Tribes march 2014 ---- these flags are mads static and must be put back to their original value after running mads + NOMAD::Mads::set_flag_check_bimads ( flag_check_bimads ); + NOMAD::Mads::set_flag_reset_mesh ( flag_reset_mesh ); + NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); + NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); + + // NOMAD::Mads::set_flag_check_bimads ( true ); + // NOMAD::Mads::set_flag_reset_mesh ( true ); + // NOMAD::Mads::set_flag_p1_active ( false ); + + // number of search points: + nb_search_pts = stats.get_eval() - old_eval; + + // restore evaluator: + ev_control.set_evaluator ( old_ev ); + delete p1ev; + + // restore the Pareto front: + mads.set_pareto_front ( old_pareto_front ); + + // restore parameters: + _p.set_VNS_SEARCH ( old_VNS_trigger ); + _p.set_F_TARGET ( old_f_target ); + _p.set_L_CURVE_TARGET ( old_lct ); + _p.set_BB_OUTPUT_TYPE ( old_bbot ); + _p.set_DISPLAY_DEGREE ( old_display_degree ); + _p.set_SOLUTION_FILE ( old_sol_file ); + _p.reset_stats_file(); + _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); + _p.set_DISPLAY_STATS (old_ds); + + _p.check ( false , // remove_history_file = false + true , // remove_solution_file = true + false ); // remove_stats_file = true + + + // counters: + stats.add_p1_iterations ( stats.get_iterations() - old_it ); + stats.add_p1_bbe ( stats.get_bb_eval () - old_bbe ); + + // for the update of new_feas_inc and new_infeas_inc (1/2): + const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); + const NOMAD::Eval_Point * old_feasible_incumbent = NULL; + const NOMAD::Eval_Point * old_infeasible_incumbent = NULL; + old_feasible_incumbent = active_barrier.get_best_feasible(); + old_infeasible_incumbent = active_barrier.get_best_infeasible(); + + // update the barriers and compute the true values + // of f and h for all evaluated points: + NOMAD::Barrier & true_barrier = mads.get_true_barrier(); + NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); + + true_barrier.reset(); + sgte_barrier.reset(); + + // scan the active cache: + const NOMAD::Cache & active_cache = mads.get_cache(); + if ( active_cache.empty() ) + { + stop = true; + stop_reason = NOMAD::P1_FAIL; + return; + } + + const NOMAD::Eval_Point * cur = active_cache.begin(); + while ( cur ) + { + + if ( cur->is_eval_ok() && cur->get_signature() ) + { + + NOMAD::Eval_Point * modifiable_x = &NOMAD::Cache::get_modifiable_point ( *cur ); + + modifiable_x->set_direction ( NULL ); + modifiable_x->set_poll_center_type ( NOMAD::UNDEFINED_POLL_CENTER_TYPE ); + modifiable_x->set_user_eval_priority ( NOMAD::Double() ); + modifiable_x->set_rand_eval_priority ( NOMAD::Double() ); + + old_ev->compute_f ( *modifiable_x ); + old_ev->compute_h ( *modifiable_x ); + + // insertion in barrier: + (( cur->get_eval_type() == NOMAD::TRUTH ) ? true_barrier : sgte_barrier).insert (*cur); + } + + cur = active_cache.next(); + } + + success = active_barrier.get_success(); + + if ( !stop && success == NOMAD::UNSUCCESSFUL ) + { + stop = true; + stop_reason = NOMAD::P1_FAIL; + return; + } + + true_barrier.update_and_reset_success(); + sgte_barrier.update_and_reset_success(); + + // update of new_feas_inc and new_infeas_inc (2/2): + const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); + const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); + if ( bf && bf != old_feasible_incumbent ) + new_feas_inc = bf; + if ( bi && bi != old_infeasible_incumbent ) + new_infeas_inc = bi; + + // final displays: + if ( bf && bf->get_current_run() ) + { + + // solution file: + ev_control.write_solution_file ( *bf ); + + // stats_file: + const std::string & stats_file_name = _p.get_stats_file_name(); + if ( !stats_file_name.empty() && display_degree > NOMAD::NO_DISPLAY) + ev_control.stats_file ( stats_file_name , bf , true , NULL ); + + // display_stats + if (display_degree > NOMAD::NO_DISPLAY) + ev_control.display_stats(false, out, old_ds , bf , true , NULL ); + } + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << NOMAD::close_block ( "end of phase one" ); } diff --git a/src/Phase_One_Search.hpp b/src/Phase_One_Search.hpp index 299166659e4955db2dca94fb4e5d60e3eed04d60..46b57d6b2357ab10ad6795352ac2c87270cafeba 100644 --- a/src/Phase_One_Search.hpp +++ b/src/Phase_One_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Point.cpp b/src/Point.cpp index 57f10c882eb345a8c719d45d6447b7669f1bd146..fe27123b57e9ce9aee2cee6661edad621ecc890d 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -62,7 +62,8 @@ NOMAD::Point::Point ( int n , const NOMAD::Double & d ) : _n (n) , _coords (NULL if ( NOMAD::Point::_cardinality > NOMAD::Point::_max_cardinality ) ++NOMAD::Point::_max_cardinality; #endif - if (_n > 0) { + if (_n > 0) + { _coords = new NOMAD::Double [_n]; if ( d.is_defined() ) std::fill ( _coords , _coords+_n , d ); @@ -81,7 +82,8 @@ NOMAD::Point::Point ( const NOMAD::Point & p ) : _n (p._n) , _coords (NULL) if ( NOMAD::Point::_cardinality >= NOMAD::Point::_max_cardinality ) ++NOMAD::Point::_max_cardinality; #endif - if ( _n > 0 ) { + if ( _n > 0 ) + { NOMAD::Double * p1 = _coords = new NOMAD::Double [_n]; const NOMAD::Double * p2 = p._coords; for ( int k = 0 ; k < _n ; ++k , ++p1 , ++p2 ) @@ -106,13 +108,16 @@ NOMAD::Point::~Point ( void ) /*-----------------------------------------------*/ void NOMAD::Point::reset ( int n , const NOMAD::Double & d ) { - if ( n <= 0 ) { + if ( n <= 0 ) + { _n = 0; delete [] _coords; _coords = NULL; } - else { - if ( _n != n ) { + else + { + if ( _n != n ) + { delete [] _coords; _n = n; _coords = new NOMAD::Double [_n]; @@ -129,15 +134,17 @@ void NOMAD::Point::resize ( int n ) { if ( n == _n ) return; - if ( n <= 0 ) { + + if ( n <= 0 ) + { _n = 0; delete [] _coords; _coords = NULL; return; } NOMAD::Double * new_coords = new NOMAD::Double [n]; - if ( _coords ) { - + if ( _coords ) + { int min = ( n < _n ) ? n : _n; NOMAD::Double * p1 = new_coords; @@ -188,7 +195,8 @@ const NOMAD::Point & NOMAD::Point::operator = ( const NOMAD::Point & p ) if ( this == &p ) return *this; - if ( _n != p._n ) { + if ( _n != p._n ) + { delete [] _coords; _n = p._n; if (_n > 0) @@ -306,7 +314,8 @@ void NOMAD::Point::set ( int n , const NOMAD::Double * a ) if ( n <= 0 || !a ) return; - if ( _n != n ) { + if ( _n != n ) + { delete [] _coords; _n = n; _coords = new NOMAD::Double [_n]; @@ -475,7 +484,8 @@ bool NOMAD::Point::operator < ( const NOMAD::Point & p ) const const NOMAD::Double * p1 = _coords; const NOMAD::Double * p2 = p._coords; - for ( int k = 0 ; k < _n ; ++k , ++p1 , ++p2 ) { + for ( int k = 0 ; k < _n ; ++k , ++p1 , ++p2 ) + { if ( *p1 < *p2 ) return true; @@ -505,8 +515,8 @@ bool NOMAD::Point::comp_with_undef ( const NOMAD::Point & p ) const bool p1d , p2d; - for ( int k = 0 ; k < _n ; ++k , ++p1 , ++p2 ) { - + for ( int k = 0 ; k < _n ; ++k , ++p1 , ++p2 ) + { p1d = p1->is_defined(); p2d = p2->is_defined(); @@ -560,7 +570,8 @@ const NOMAD::Double NOMAD::Point::get_angle ( const NOMAD::Point & x ) const const NOMAD::Double * p1 = _coords; const NOMAD::Double * p2 = x._coords; - for ( int i = 0 ; i < _n ; ++i , ++p1 , ++p2 ) { + for ( int i = 0 ; i < _n ; ++i , ++p1 , ++p2 ) + { norm_1 += *p1 * *p1; norm_2 += *p2 * *p2; inner_product += *p1 * *p2; diff --git a/src/Point.hpp b/src/Point.hpp index f88991035bcb467da72a88d3ce004332977909f4..344ade6534eacdb3cfd0a8808c6344549bd8abb0 100644 --- a/src/Point.hpp +++ b/src/Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -43,9 +43,6 @@ #ifndef __POINT__ #define __POINT__ -/// Avoids warnings on std::inner_product with visual C++. -#define _SCL_SECURE_NO_WARNINGS - #include <numeric> #include <functional> #include "Double.hpp" diff --git a/src/Priority_Eval_Point.cpp b/src/Priority_Eval_Point.cpp index af60cb18c2bffb4744d8d91a1aa7907c8d1e0ec1..f5059e46854dfc75687aac0ee1d4fdf88d1e608a 100644 --- a/src/Priority_Eval_Point.cpp +++ b/src/Priority_Eval_Point.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -42,6 +42,8 @@ */ #include "Priority_Eval_Point.hpp" +bool NOMAD::Priority_Eval_Point::_lexicographic_order=false; + /*------------------------------------------------*/ /* comparison operator */ /*------------------------------------------------*/ @@ -54,10 +56,14 @@ bool NOMAD::Priority_Eval_Point::dominates { if ( this == &x ) return false; - - const NOMAD::Eval_Point * x1 = get_element(); + const NOMAD::Eval_Point * x1 = get_element(); const NOMAD::Eval_Point * x2 = x.get_element(); + // criterion 0: lexicographic order + if (_lexicographic_order) + return NOMAD::Point(*x1) < NOMAD::Point(*x2); + + // criterion 1: user criterion: // ------------ const NOMAD::Double uep1 = x1->get_user_eval_priority(); @@ -115,7 +121,7 @@ bool NOMAD::Priority_Eval_Point::dominates // ------------ flag = compare_hf_values ( _h_sgte , _f_sgte , x_h_sgte , x_f_sgte ); if ( flag ) - return ( flag > 0 ); + return ( flag > 0 ); // criterion 6: model f and h values: // ------------ @@ -135,22 +141,8 @@ bool NOMAD::Priority_Eval_Point::dominates return false; } - // !not used! - // criterion 8: check the angle with the simplex gradient: - // ------------ - if ( _angle_simplex_grad.is_defined() && x_angle_simplex_grad.is_defined() ) - { - - if ( _angle_simplex_grad < x_angle_simplex_grad ) - return true; - - if ( x_angle_simplex_grad < _angle_simplex_grad ) - return false; - } - - - // criterion 9: take the point with the best h value: + // criterion 8: take the point with the best h value: // ------------ flag = compare_h_values ( x1->get_h() , x2->get_h() ); if ( flag ) @@ -164,12 +156,14 @@ bool NOMAD::Priority_Eval_Point::dominates if ( flag ) return ( flag > 0 ); - // criterion 10: random criterion for randomly generated directions: + // criterion 9: random criterion for randomly generated directions: // ------------- const NOMAD::Double rep1 = x1->get_rand_eval_priority(); - if ( rep1.is_defined() ) { + if ( rep1.is_defined() ) + { const NOMAD::Double rep2 = x2->get_rand_eval_priority(); - if ( rep2.is_defined() ) { + if ( rep2.is_defined() ) + { if ( rep1 < rep2 ) return true; if ( rep2 < rep1 ) @@ -177,9 +171,10 @@ bool NOMAD::Priority_Eval_Point::dominates } } - // criterion 11: compare the tags: + // criterion 10: compare the tags: // ------------- return x1->get_tag() < x2->get_tag(); + } /*-----------------------------------------------*/ @@ -194,7 +189,8 @@ bool NOMAD::Priority_Eval_Point::dominates int NOMAD::Priority_Eval_Point::compare_h_values ( const NOMAD::Double & hx1 , const NOMAD::Double & hx2 ) const { - if ( hx1.is_defined() && hx2.is_defined() ) { + if ( hx1.is_defined() && hx2.is_defined() ) + { if ( hx1 < hx2 ) return 1; if ( hx2 < hx1 ) @@ -218,53 +214,56 @@ int NOMAD::Priority_Eval_Point::compare_hf_values ( const NOMAD::Double & hx1 , const NOMAD::Double & hx2 , const NOMAD::Double & fx2 ) const { - if ( fx1.is_defined() && fx2.is_defined() ) { - - if ( hx1.is_defined() && hx2.is_defined() ) { - - // x1 is feasible: - if ( hx1 <= _h_min ) { - - // both points are feasible: - if ( hx2 <= _h_min ) { - if ( fx1 < fx2 ) - return 1; - if ( fx2 < fx1 ) - return -1; + if ( fx1.is_defined() && fx2.is_defined() ) + { + + if ( hx1.is_defined() && hx2.is_defined() ) + { + // x1 is feasible: + if ( hx1 <= _h_min ) + { + // both points are feasible: + if ( hx2 <= _h_min ) + { + if ( fx1 < fx2 ) + return 1; + if ( fx2 < fx1 ) + return -1; + } + + // x1 feasible and x2 infeasible: + else + return 1; + } + + // x1 is infeasible: + else + { + // x2 is feasible: + if ( hx2 <= _h_min ) + return -1; + + // both points are infeasible: + if ( ( hx1 < hx2 && fx1 < fx2 ) || + ( hx1 == hx2 && fx1 < fx2 ) || + ( hx1 < hx2 && fx1 == fx2 ) ) + return 1; + + if ( ( hx2 < hx1 && fx2 < fx1 ) || + ( hx2 == hx1 && fx2 < fx1 ) || + ( hx2 < hx1 && fx2 == fx1 ) ) + return -1; + } + } + + // we only have f values: + else + { + if ( fx1 < fx2 ) + return 1; + if ( fx2 < fx1 ) + return -1; + } } - - // x1 feasible and x2 infeasible: - else - return 1; - } - - // x1 is infeasible: - else { - - // x2 is feasible: - if ( hx2 <= _h_min ) - return -1; - - // both points are infeasible: - if ( ( hx1 < hx2 && fx1 < fx2 ) || - ( hx1 == hx2 && fx1 < fx2 ) || - ( hx1 < hx2 && fx1 == fx2 ) ) - return 1; - - if ( ( hx2 < hx1 && fx2 < fx1 ) || - ( hx2 == hx1 && fx2 < fx1 ) || - ( hx2 < hx1 && fx2 == fx1 ) ) - return -1; - } - } - - // we only have f values: - else { - if ( fx1 < fx2 ) - return 1; - if ( fx2 < fx1 ) - return -1; - } - } - return 0; + return 0; } diff --git a/src/Priority_Eval_Point.hpp b/src/Priority_Eval_Point.hpp index 24939ca67ebd04a3babe28b308153e47bf1313c3..e74885d63ede09dc581e901802f3e55c3e72c1dd 100644 --- a/src/Priority_Eval_Point.hpp +++ b/src/Priority_Eval_Point.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -60,6 +60,7 @@ namespace NOMAD { NOMAD::Double _h_model; ///< Feasibility model value. NOMAD::Double _angle_success_dir; ///< Angle with last successful direction. NOMAD::Double _angle_simplex_grad; ///< Angle with simplex gradient. + static bool _lexicographic_order; ///< Use lexicographic order for comparison /// Affectation operator. /** @@ -214,6 +215,12 @@ namespace NOMAD { */ void set_h_model ( const NOMAD::Double & h ) { _h_model = h; } + /// Set the lexicographic order for sorting. + /** + */ + static void set_lexicographic_order ( bool order ) { _lexicographic_order = order; } + + }; } diff --git a/src/Quad_Model.cpp b/src/Quad_Model.cpp index 668d5259d07359960ba333e856183db8db7068dd..0bb28ef25bea86e82bf6117398d0adc9335945ff 100644 --- a/src/Quad_Model.cpp +++ b/src/Quad_Model.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Quad_Model.cpp - \brief Quadratic regression or MFN interpolation model (implementation) - \author Sebastien Le Digabel - \date 2010-08-31 - \see Quad_Model.hpp -*/ + \file Quad_Model.cpp + \brief Quadratic regression or MFN interpolation model (implementation) + \author Sebastien Le Digabel + \date 2010-08-31 + \see Quad_Model.hpp + */ #include "Quad_Model.hpp" /*-----------------------------------------------------------*/ @@ -47,24 +47,24 @@ /*-----------------------------------------------------------*/ NOMAD::Quad_Model::Quad_Model ( const NOMAD::Display & out , - const std::vector<NOMAD::bb_output_type> & bbot , - const NOMAD::Cache & cache , - const NOMAD::Signature & signature ) - : _out ( out ) , - _bbot ( bbot ) , - _interpolation_type ( NOMAD::UNDEFINED_INTERPOLATION_TYPE ) , - _n ( signature.get_n() ) , - _nfree ( _n ) , - _fixed_vars ( new bool [_n] ) , - _index ( NULL ) , - _alpha ( NULL ) , - _cache ( cache ) , - _signature ( signature ) , - _error_flag ( true ) + const std::vector<NOMAD::bb_output_type> & bbot , + const NOMAD::Cache & cache , + const NOMAD::Signature & signature ) +: _out ( out ) , +_bbot ( bbot ) , +_interpolation_type ( NOMAD::UNDEFINED_INTERPOLATION_TYPE ) , +_n ( signature.get_n() ) , +_nfree ( _n ) , +_fixed_vars ( new bool [_n] ) , +_index ( NULL ) , +_alpha ( NULL ) , +_cache ( cache ) , +_signature ( signature ) , +_error_flag ( true ) { - for ( int i = 0 ; i < _n ; ++i ) - _fixed_vars[i] = false; - init_alpha(); + for ( int i = 0 ; i < _n ; ++i ) + _fixed_vars[i] = false; + init_alpha(); } /*-----------------------------------------------------------*/ @@ -72,16 +72,16 @@ NOMAD::Quad_Model::Quad_Model /*-----------------------------------------------------------*/ NOMAD::Quad_Model::~Quad_Model ( void ) { - int m = static_cast<int> ( _bbot.size() ); - for ( int i = 0 ; i < m ; ++i ) - delete _alpha[i]; - delete [] _alpha; - delete [] _fixed_vars; - delete [] _index; - - // clear the interpolation set Y: - for ( size_t k = 0 ; k < _Y.size() ; ++k ) - delete _Y[k]; + int m = static_cast<int> ( _bbot.size() ); + for ( int i = 0 ; i < m ; ++i ) + delete _alpha[i]; + delete [] _alpha; + delete [] _fixed_vars; + delete [] _index; + + // clear the interpolation set Y: + for ( size_t k = 0 ; k < _Y.size() ; ++k ) + delete _Y[k]; } /*-----------------------------------------------------------*/ @@ -89,72 +89,76 @@ NOMAD::Quad_Model::~Quad_Model ( void ) /*-----------------------------------------------------------*/ void NOMAD::Quad_Model::init_alpha ( void ) { - _n_alpha = ( _nfree + 1 ) * ( _nfree + 2 ) / 2; - - int i , m = static_cast<int> ( _bbot.size() ); - - // initialize _alpha: - // ------------------ - if ( _alpha ) { + _n_alpha = ( _nfree + 1 ) * ( _nfree + 2 ) / 2; + + int i , m = static_cast<int> ( _bbot.size() ); + + // initialize _alpha: + // ------------------ + if ( _alpha ) + { + for ( i = 0 ; i < m ; ++i ) + delete _alpha[i]; + delete [] _alpha; + } + + _alpha = new NOMAD::Point * [m]; + for ( i = 0 ; i < m ; ++i ) - delete _alpha[i]; - delete [] _alpha; - } - - _alpha = new NOMAD::Point * [m]; - - for ( i = 0 ; i < m ; ++i ) - _alpha[i] = ( _bbot[i] == NOMAD::OBJ || NOMAD::bbot_is_constraint(_bbot[i]) ) ? - new NOMAD::Point ( _n_alpha ) : NULL; - - // initialize _index: - // ------------------ - - // example: with 3 variables (X,Y,Z) with Y fixed. - // -------- - // the problem is reduced to the two variables x=X and y=Z, - // and _index is corresponds to: - // - // 0 1 0 1 : index[0] = 0 - // 1 X 1 x : index[1] = 1 - // 2 Y 2 y : index[2] = 3 - // 3 Z 3 .5 x^2 : index[3] = 4 - // 4 .5 X^2 4 .5 y^2 : index[4] = 6 - // 5 .5 Y^2 5 xy : index[5] = 8 - // 6 .5 Z^2 - // 7 XY - // 8 XZ - // 9 YZ - // - // If there are no fixed variables, index is of size (n+1)(n+2)/2 - // with index[i] = i. - - delete [] _index; - - _index = new int [_n_alpha]; - - int nm1 = _n - 1; - int c1 = 2*_n + 1; - int c2 = 1; - int k1 , k2; - - _index[0] = 0; - for ( i = 0 ; i < _n ; ++i ) { - if ( !_fixed_vars[i] ) { - _index[c2 ] = i+1; - _index[c2+_nfree] = i+1+_n; - ++c2; - } - } - - c2 += _nfree; - - for ( k1 = 0 ; k1 < nm1 ; ++k1 ) - for ( k2 = k1+1 ; k2 < _n ; ++k2 ) { - if ( !_fixed_vars[k1] && !_fixed_vars[k2] ) - _index[c2++] = c1; - ++c1; + _alpha[i] = ( _bbot[i] == NOMAD::OBJ || NOMAD::bbot_is_constraint(_bbot[i]) ) ? + new NOMAD::Point ( _n_alpha ) : NULL; + + // initialize _index: + // ------------------ + + // example: with 3 variables (X,Y,Z) with Y fixed. + // -------- + // the problem is reduced to the two variables x=X and y=Z, + // and _index is corresponds to: + // + // 0 1 0 1 : index[0] = 0 + // 1 X 1 x : index[1] = 1 + // 2 Y 2 y : index[2] = 3 + // 3 Z 3 .5 x^2 : index[3] = 4 + // 4 .5 X^2 4 .5 y^2 : index[4] = 6 + // 5 .5 Y^2 5 xy : index[5] = 8 + // 6 .5 Z^2 + // 7 XY + // 8 XZ + // 9 YZ + // + // If there are no fixed variables, index is of size (n+1)(n+2)/2 + // with index[i] = i. + + delete [] _index; + + _index = new int [_n_alpha]; + + int nm1 = _n - 1; + int c1 = 2*_n + 1; + int c2 = 1; + int k1 , k2; + + _index[0] = 0; + for ( i = 0 ; i < _n ; ++i ) + { + if ( !_fixed_vars[i] ) + { + _index[c2 ] = i+1; + _index[c2+_nfree] = i+1+_n; + ++c2; + } } + + c2 += _nfree; + + for ( k1 = 0 ; k1 < nm1 ; ++k1 ) + for ( k2 = k1+1 ; k2 < _n ; ++k2 ) + { + if ( !_fixed_vars[k1] && !_fixed_vars[k2] ) + _index[c2++] = c1; + ++c1; + } } /*---------------------------------------------------------*/ @@ -162,119 +166,125 @@ void NOMAD::Quad_Model::init_alpha ( void ) /* into an interpolation set (private) */ /*---------------------------------------------------------*/ bool NOMAD::Quad_Model::check_outputs ( const NOMAD::Point & bbo , int m ) const { - - if ( bbo.size() != m ) - return false; - - for ( int i = 0 ; i < m ; ++i ) - if ( !bbo[i].is_defined() || bbo[i].value() > NOMAD::MODEL_MAX_OUTPUT ) - return false; - - return true; + + if ( bbo.size() != m ) + return false; + + for ( int i = 0 ; i < m ; ++i ) + if ( !bbo[i].is_defined() || bbo[i].value() > NOMAD::MODEL_MAX_OUTPUT ) + return false; + + return true; } /*-----------------------------------------------------------*/ /* construct the interpolation set Y */ /*-----------------------------------------------------------*/ void NOMAD::Quad_Model::construct_Y ( const NOMAD::Point & center , - const NOMAD::Point & interpolation_radius , - int max_Y_size ) + const NOMAD::Point & interpolation_radius , + int max_Y_size ) { - _error_flag = true; - - if ( center.size() != _n || - interpolation_radius.size() != _n || - !center.is_complete() || - !interpolation_radius.is_complete() ) - return; - - _error_flag = false; - _center = center; - - int m = static_cast<int> ( _bbot.size() ); - - // browse the cache: - const NOMAD::Eval_Point * cur = _cache.begin(); - while ( cur ) - { - - if ( cur->get_eval_status() == NOMAD::EVAL_OK && - cur->get_n () == _n && - _signature.is_compatible (*cur) ) - { - - const NOMAD::Point & bbo = cur->get_bb_outputs(); - - if ( check_outputs ( bbo , m ) ) { - - // the center point has been found - // (it is put in first position): - if ( _center == *cur ) { - _Y.push_back ( new NOMAD::Eval_Point ( *cur ) ); - int nYm1 = get_nY() - 1; - if ( nYm1 > 0 ) { - NOMAD::Eval_Point * tmp = _Y[0]; - _Y[0 ] = _Y[nYm1]; - _Y[nYm1] = tmp; - } - } - - // other points must within the interpolation radius: - else if ( is_within_radius ( *cur , interpolation_radius ) ) - _Y.push_back ( new NOMAD::Eval_Point ( *cur ) ); - } + _error_flag = true; + + if ( center.size() != _n || + interpolation_radius.size() != _n || + !center.is_complete() || + !interpolation_radius.is_complete() ) + return; + + _error_flag = false; + _center = center; + + int m = static_cast<int> ( _bbot.size() ); + + // browse the cache: + const NOMAD::Eval_Point * cur = _cache.begin(); + while ( cur ) + { + + if ( cur->get_eval_status() == NOMAD::EVAL_OK && + cur->get_n () == _n && + _signature.is_compatible (*cur) ) + { + + const NOMAD::Point & bbo = cur->get_bb_outputs(); + + if ( check_outputs ( bbo , m ) ) + { + + // the center point has been found + // (it is put in first position): + if ( _center == *cur ) + { + _Y.push_back ( new NOMAD::Eval_Point ( *cur ) ); + int nYm1 = get_nY() - 1; + if ( nYm1 > 0 ) + { + NOMAD::Eval_Point * tmp = _Y[0]; + _Y[0 ] = _Y[nYm1]; + _Y[nYm1] = tmp; + } + } + + // other points must within the interpolation radius: + else if ( is_within_radius ( *cur , interpolation_radius ) ) + { + _Y.push_back ( new NOMAD::Eval_Point ( *cur ) ); + } + } + } + cur = _cache.next(); } - cur = _cache.next(); - } - - // respect the limit on the number of points: - if ( get_nY() > max_Y_size ) - reduce_Y ( center , max_Y_size ); + + // respect the limit on the number of points: + if ( get_nY() > max_Y_size ) + reduce_Y ( center , max_Y_size ); } /*-----------------------------------------------------------------*/ /* reduce the number of interpolation points */ /*-----------------------------------------------------------------*/ void NOMAD::Quad_Model::reduce_Y ( const NOMAD::Point & center , - int max_Y_size ) + int max_Y_size ) { - int nY = get_nY(); - - if ( nY <= max_Y_size ) - return; - - std::multiset<NOMAD::Model_Sorted_Point> Ys; - for ( int k = 0 ; k < nY ; ++k ) - Ys.insert ( NOMAD::Model_Sorted_Point ( _Y[k] , center ) ); - - _Y.clear(); - - std::multiset<NOMAD::Model_Sorted_Point>::const_iterator it , end = Ys.end(); - for ( it = Ys.begin() ; it != end ; ++it ) { - if ( get_nY() < max_Y_size ) - _Y.push_back ( static_cast<NOMAD::Eval_Point *> ( it->get_point() ) ); - else - delete it->get_point(); - } + int nY = get_nY(); + + if ( nY <= max_Y_size ) + return; + + std::multiset<NOMAD::Model_Sorted_Point> Ys; + for ( int k = 0 ; k < nY ; ++k ) + Ys.insert ( NOMAD::Model_Sorted_Point ( _Y[k] , center ) ); + + _Y.clear(); + + std::multiset<NOMAD::Model_Sorted_Point>::const_iterator it , end = Ys.end(); + for ( it = Ys.begin() ; it != end ; ++it ) { + if ( get_nY() < max_Y_size ) + _Y.push_back ( static_cast<NOMAD::Eval_Point *> ( it->get_point() ) ); + else + delete it->get_point(); + } } /*-----------------------------------------------------------*/ /* check if an unscaled point is in B(center,radius) for a */ /* given radius (private) */ /*-----------------------------------------------------------*/ -bool NOMAD::Quad_Model::is_within_radius ( const NOMAD::Point & x , - const NOMAD::Point & radius ) const +bool NOMAD::Quad_Model::is_within_radius ( const NOMAD::Point & x , + const NOMAD::Point & radius ) const { - if ( x.size() != _n || radius.size() != _n ) - return false; - - for ( int i = 0 ; i < _n ; ++i ) - if ( !x[i].is_defined() || - !radius[i].is_defined() || - radius[i] < ( x[i] - _center[i]).abs() ) - return false; - - return true; + if ( x.size() != _n || radius.size() != _n ) + return false; + + for ( int i = 0 ; i < _n ; ++i ) + { + if ( !x[i].is_defined() || + !radius[i].is_defined() || + radius[i] < ( x[i] - _center[i]).abs() ) + return false; + } + return true; } /*------------------------------------------------------*/ @@ -282,16 +292,16 @@ bool NOMAD::Quad_Model::is_within_radius ( const NOMAD::Point & x , /*------------------------------------------------------*/ bool NOMAD::Quad_Model::is_within_trust_radius ( const NOMAD::Point & x ) const { - // check that all scaled coordinates are in [-1;1] and - // that fixed variables are equal to zero: - for ( int i = 0 ; i < _n ; ++i ) - if ( !_ref [i].is_defined() || - !_scaling[i].is_defined() || - ! x[i].is_defined() || - x[i].abs() > 1.0 || - ( _fixed_vars[i] && x[i] != 0.0 ) ) - return false; - return true; + // check that all scaled coordinates are in [-1;1] and + // that fixed variables are equal to zero: + for ( int i = 0 ; i < _n ; ++i ) + if ( !_ref [i].is_defined() || + !_scaling[i].is_defined() || + ! x[i].is_defined() || + x[i].abs() > 1.0 || + ( _fixed_vars[i] && x[i] != 0.0 ) ) + return false; + return true; } /*--------------------------------------------------------------*/ @@ -300,253 +310,253 @@ bool NOMAD::Quad_Model::is_within_trust_radius ( const NOMAD::Point & x ) const /*--------------------------------------------------------------*/ void NOMAD::Quad_Model::define_scaling ( const NOMAD::Double & r ) { - if ( _error_flag || _Y.empty() ) { - _error_flag = true; - return; - } - - int i , k; - int nY = get_nY(); - NOMAD::Point min(_n) , max(_n); - NOMAD::Double tmp; - - // The parameters defining the scaling with rotation (see define_scaling_by_direction) are cleared. - // Only the parameters for the basic scaling are set - _dirP.clear(); - _epsilon.clear(); - _delta_m.clear(); - - - _scaling.clear(); - _ref.clear (); - _ref.reset ( _n ); - _scaling.reset ( _n ); - - // compute the reference (center of Y): - for ( k = 0 ; k < nY ; ++k ) - { - - if ( !_Y[k] || _n != _Y[k]->size() ) - { - _error_flag = true; - return; - } - - for ( i = 0 ; i < _n ; ++i ) - { - tmp = (*_Y[k])[i]; - if ( !min[i].is_defined() || tmp < min[i] ) - min[i] = tmp; - if ( !max[i].is_defined() || tmp > max[i] ) - max[i] = tmp; - } - } - - for ( i = 0 ; i < _n ; ++i ) - _ref[i] = ( min[i] + max[i] ) / 2.0; - + if ( _error_flag || _Y.empty() ) { + _error_flag = true; + return; + } + + int i , k; + int nY = get_nY(); + NOMAD::Point min(_n) , max(_n); + NOMAD::Double tmp; + + // The parameters defining the scaling with rotation (see define_scaling_by_direction) are cleared. + // Only the parameters for the basic scaling are set + _dirP.clear(); + _epsilon.clear(); + _delta_m.clear(); + + + _scaling.clear(); + _ref.clear (); + _ref.reset ( _n ); + _scaling.reset ( _n ); + + // compute the reference (center of Y): + for ( k = 0 ; k < nY ; ++k ) + { + + if ( !_Y[k] || _n != _Y[k]->size() ) + { + _error_flag = true; + return; + } + + for ( i = 0 ; i < _n ; ++i ) + { + tmp = (*_Y[k])[i]; + if ( !min[i].is_defined() || tmp < min[i] ) + min[i] = tmp; + if ( !max[i].is_defined() || tmp > max[i] ) + max[i] = tmp; + } + } + + for ( i = 0 ; i < _n ; ++i ) + _ref[i] = ( min[i] + max[i] ) / 2.0; + #ifdef MODEL_STATS - _Yw = NOMAD::Double(); - for ( i = 0 ; i < _n ; ++i ) - { - tmp = max[i]-min[i]; - if ( !_Yw.is_defined() || tmp > _Yw ) - _Yw = tmp; - } + _Yw = NOMAD::Double(); + for ( i = 0 ; i < _n ; ++i ) + { + tmp = max[i]-min[i]; + if ( !_Yw.is_defined() || tmp > _Yw ) + _Yw = tmp; + } #endif - + #ifdef DEBUG - _out << std::endl - << "define_scaling(): reference = ( " << _ref << " )" << std::endl; + _out << std::endl + << "define_scaling(): reference = ( " << _ref << " )" << std::endl; #endif - - // compute the scaling (and detect fixed variables): - for ( k = 0 ; k < nY ; ++k ) { - - for ( i = 0 ; i < _n ; ++i ) { - tmp = ( (*_Y[k])[i] - _ref[i] ).abs(); - if ( !_scaling[i].is_defined() || _scaling[i] < tmp ) - _scaling[i] = tmp; + + // compute the scaling (and detect fixed variables): + for ( k = 0 ; k < nY ; ++k ) { + + for ( i = 0 ; i < _n ; ++i ) { + tmp = ( (*_Y[k])[i] - _ref[i] ).abs(); + if ( !_scaling[i].is_defined() || _scaling[i] < tmp ) + _scaling[i] = tmp; + } } - } - - _nfree = _n; - - for ( i = 0 ; i < _n ; ++i ) - { - if ( _scaling[i] == 0.0 ) - { - _scaling [i] = 0.0; - _fixed_vars[i] = true; - --_nfree; - if ( _nfree == 0 ) - { - _scaling.clear(); - _ref.clear(); - _error_flag = true; - return; - } - } - else - _scaling[i] *= 1.0/r; // all coordinates in [-r;r] - } - - if ( _nfree < _n ) - init_alpha(); - - for ( k = 0 ; k < nY ; ++k ) - { - if ( !scale ( *_Y[k] ) ) - { - _scaling.clear(); - _error_flag = true; - return; - } - } - + + _nfree = _n; + + for ( i = 0 ; i < _n ; ++i ) + { + if ( _scaling[i] == 0.0 ) + { + _scaling [i] = 0.0; + _fixed_vars[i] = true; + --_nfree; + if ( _nfree == 0 ) + { + _scaling.clear(); + _ref.clear(); + _error_flag = true; + return; + } + } + else + _scaling[i] *= 1.0/r; // all coordinates in [-r;r] + } + + if ( _nfree < _n ) + init_alpha(); + + for ( k = 0 ; k < nY ; ++k ) + { + if ( !scale ( *_Y[k] ) ) + { + _scaling.clear(); + _error_flag = true; + return; + } + } + #ifdef DEBUG - _out << "define_scaling(): scaling = ( " << _scaling << " )" << std::endl; + _out << "define_scaling(): scaling = ( " << _scaling << " )" << std::endl; #endif - - _error_flag = false; + + _error_flag = false; } - + /*-------------------------------------------------------------------*/ /* . Scaling with rotation based on a set of directions. */ /* See paper: */ /* Reducing the number of function evaluations in */ /* Mesh Adaptive Direct Search algorithms, Audet, Ianni, */ -/* LeDigabel, Tribes, 2012 */ +/* LeDigabel, Tribes, 2014 */ /* . looks also for fixed variables */ /*-------------------------------------------------------------------*/ void NOMAD::Quad_Model::define_scaling_by_directions ( const std::list<NOMAD::Direction> & dirs, const NOMAD::Point & delta_m, const NOMAD::Double & epsilon ) { - if ( _error_flag || _Y.empty() ) { - _error_flag = true; - return; - } - - int i , k; - int nY = get_nY(); - NOMAD::Point min(_n) , max(_n); - NOMAD::Double tmp; - - - // The parameters defining the basic scaling (see define_scaling) are cleared. - // Only the parameters for the direction scaling are set - _scaling.clear(); - _ref.clear (); - - // For direction scaling - if (static_cast<int> (dirs.size())!=_n || static_cast<int>(delta_m.size()) != _n || epsilon<=0.0 || epsilon>=1) - { - _error_flag = true; - return; - } - _delta_m=delta_m; - // Get D' from dirs (scaling with delta_m - std::list<NOMAD::Direction>::const_iterator itDir; - for (itDir=dirs.begin(); itDir != dirs.end(); itDir++) - { - NOMAD::Direction dir_i(_n,0.0,itDir->get_type()); - dir_i.set_index(itDir->get_index()); - for ( int i = 0 ; i < _n ; ++i ) - { - if (_delta_m[i]<=0.0) - { - _error_flag=true; - return; - } - dir_i[i]=(*itDir)[i]/_delta_m[i]; - } - _dirP.push_back(dir_i); - } - - _epsilon=epsilon; - - - // compute the min and the max: - for ( k = 0 ; k < nY ; ++k ) - { - - if ( !_Y[k] || _n != _Y[k]->size() ) - { - _error_flag = true; - return; - } - - for ( i = 0 ; i < _n ; ++i ) - { - tmp = (*_Y[k])[i]; - if ( !min[i].is_defined() || tmp < min[i] ) - min[i] = tmp; - if ( !max[i].is_defined() || tmp > max[i] ) - max[i] = tmp; - } - } - + if ( _error_flag || _Y.empty() ) { + _error_flag = true; + return; + } + + int i , k; + int nY = get_nY(); + NOMAD::Point min(_n) , max(_n); + NOMAD::Double tmp; + + + // The parameters defining the basic scaling (see define_scaling) are cleared. + // Only the parameters for the direction scaling are set + _scaling.clear(); + _ref.clear (); + + // For direction scaling + if (static_cast<int> (dirs.size())!=_n || static_cast<int>(delta_m.size()) != _n || epsilon<=0.0 || epsilon>=1) + { + _error_flag = true; + return; + } + _delta_m=delta_m; + // Get D' from dirs (scaling with delta_m + std::list<NOMAD::Direction>::const_iterator itDir; + for (itDir=dirs.begin(); itDir != dirs.end(); itDir++) + { + NOMAD::Direction dir_i(_n,0.0,itDir->get_type()); + dir_i.set_index(itDir->get_index()); + for ( int i = 0 ; i < _n ; ++i ) + { + if (_delta_m[i]<=0.0) + { + _error_flag=true; + return; + } + dir_i[i]=(*itDir)[i]/_delta_m[i]; + } + _dirP.push_back(dir_i); + } + + _epsilon=epsilon; + + + // compute the min and the max: + for ( k = 0 ; k < nY ; ++k ) + { + + if ( !_Y[k] || _n != _Y[k]->size() ) + { + _error_flag = true; + return; + } + + for ( i = 0 ; i < _n ; ++i ) + { + tmp = (*_Y[k])[i]; + if ( !min[i].is_defined() || tmp < min[i] ) + min[i] = tmp; + if ( !max[i].is_defined() || tmp > max[i] ) + max[i] = tmp; + } + } + #ifdef MODEL_STATS - _Yw = NOMAD::Double(); - for ( i = 0 ; i < _n ; ++i ) - { - tmp = max[i]-min[i]; - if ( !_Yw.is_defined() || tmp > _Yw ) - _Yw = tmp; - } + _Yw = NOMAD::Double(); + for ( i = 0 ; i < _n ; ++i ) + { + tmp = max[i]-min[i]; + if ( !_Yw.is_defined() || tmp > _Yw ) + _Yw = tmp; + } #endif - - // Detect fixed variables: - _nfree = _n; - for ( i = 0 ; i < _n ; ++i ) - { - bool fixed_var_i=true; - for ( k = 0 ; k < nY ; ++k ) - { - if ( ( (*_Y[k])[i] - _center[i] ).abs() > 0.0 ) - { - fixed_var_i=false; - break; - } - } - _fixed_vars[i]=fixed_var_i; - if (fixed_var_i) - --_nfree; - - if ( _nfree == 0 ) - { - _scaling.clear(); - _ref.clear(); - _dirP.clear(); - _error_flag = true; - return; - } - } - if ( _nfree < _n ) - init_alpha(); - - // Perform scaling of Y - for ( k = 0 ; k < nY ; ++k ) - { - if ( !scale ( *_Y[k] ) ) - { - _scaling.clear(); - _dirP.clear(); - _error_flag = true; - return; - } - } - + + // Detect fixed variables: + _nfree = _n; + for ( i = 0 ; i < _n ; ++i ) + { + bool fixed_var_i=true; + for ( k = 0 ; k < nY ; ++k ) + { + if ( ( (*_Y[k])[i] - _center[i] ).abs() > 0.0 ) + { + fixed_var_i=false; + break; + } + } + _fixed_vars[i]=fixed_var_i; + if (fixed_var_i) + --_nfree; + + if ( _nfree == 0 ) + { + _scaling.clear(); + _ref.clear(); + _dirP.clear(); + _error_flag = true; + return; + } + } + if ( _nfree < _n ) + init_alpha(); + + // Perform scaling of Y + for ( k = 0 ; k < nY ; ++k ) + { + if ( !scale ( *_Y[k] ) ) + { + _scaling.clear(); + _dirP.clear(); + _error_flag = true; + return; + } + } + #ifdef DEBUG - _out << "define_scaling_by_direction(): " << std::endl; - for ( itDir = _dirP.begin() ; itDir != _dirP.end() ; ++itDir ) - { - _out << "dirPrime "; - _out.display_int_w ( (*itDir).get_index() , _dirP.size() ); - _out << " : " << *itDir << std::endl; - } + _out << "define_scaling_by_direction(): " << std::endl; + for ( itDir = _dirP.begin() ; itDir != _dirP.end() ; ++itDir ) + { + _out << "dirPrime "; + _out.display_int_w ( (*itDir).get_index() , static_cast<int>(_dirP.size()) ); + _out << " : " << *itDir << std::endl; + } #endif - - _error_flag = false; + + _error_flag = false; } @@ -555,55 +565,55 @@ void NOMAD::Quad_Model::define_scaling_by_directions ( const std::list<NOMAD::Di /*--------------------------------------------------------------*/ bool NOMAD::Quad_Model::scale ( NOMAD::Point & x ) const { - if ( _error_flag || _n != x.size() ) - return false; - - if (_dirP.size()==0) - { - // Scale without rotation - for ( int i = 0 ; i < _n ; ++i ) - { - if ( !_ref [i].is_defined() || - !_scaling[i].is_defined() || - ! x[i].is_defined() ) - return false; - x[i] -= _ref[i]; - if ( _scaling[i] != 0 ) - x[i] /= _scaling[i]; - } - } - else - { - if (! _epsilon.is_defined() || !_delta_m.is_complete()) - return false; - // Scale with rotation based on direction and center (see paper Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2012 - // T(y)=(D')^-1*(center-x)/delta_m/(1-epsilon) - epsilon*1/(1-epsilon) - // (D')^-1=(D')^T/normCol^2 - NOMAD::Point temp(_n,0.0); - double normCol2=0.0; - std::list<NOMAD::Direction>::const_iterator itDir=_dirP.begin(); - for ( int i = 0 ; i < _n ; ++i ) - { - normCol2+=pow((*itDir)[i].value(),2); - - if (_delta_m[i] !=0.0) - temp[i]=(_center[i]-x[i])/_delta_m[i]/(1-_epsilon); - else - return false; - x[i]=0.0; - } - int j=0; - for (itDir=_dirP.begin(); itDir != _dirP.end(); itDir++,j++) - { - for ( int i = 0 ; i < _n ; ++i ) - { - x[j]+=temp[i]*(*itDir)[i]/normCol2; - } - x[j]-=_epsilon/(1.0-_epsilon); - } - } - - return true; + if ( _error_flag || _n != x.size() ) + return false; + + if (_dirP.size()==0) + { + // Scale without rotation + for ( int i = 0 ; i < _n ; ++i ) + { + if ( !_ref [i].is_defined() || + !_scaling[i].is_defined() || + ! x[i].is_defined() ) + return false; + x[i] -= _ref[i]; + if ( _scaling[i] != 0 ) + x[i] /= _scaling[i]; + } + } + else + { + if (! _epsilon.is_defined() || !_delta_m.is_complete()) + return false; + // Scale with rotation based on direction and center (see paper Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2014 + // T(y)=(D')^-1*(center-x)/delta_m/(1-epsilon) - epsilon*1/(1-epsilon) + // (D')^-1=(D')^T/normCol^2 + NOMAD::Point temp(_n,0.0); + NOMAD::Double normCol2=0.0; + std::list<NOMAD::Direction>::const_iterator itDir=_dirP.begin(); + for ( int i = 0 ; i < _n ; ++i ) + { + normCol2+=pow((*itDir)[i].value(),2.0); + + if (_delta_m[i] !=0.0) + temp[i]=(_center[i].value()-x[i].value())/_delta_m[i].value()/(1.0-_epsilon.value()); + else + return false; + x[i]=0.0; + } + int j=0; + for (itDir=_dirP.begin(); itDir != _dirP.end(); itDir++,j++) + { + for ( int i = 0 ; i < _n ; ++i ) + { + x[j]+=temp[i].value()*(*itDir)[i].value()/normCol2.value(); + } + x[j]-=_epsilon.value()/(1.0-_epsilon.value()); + } + } + + return true; } /*-----------------------------------------------------------*/ @@ -611,53 +621,53 @@ bool NOMAD::Quad_Model::scale ( NOMAD::Point & x ) const /*-----------------------------------------------------------*/ bool NOMAD::Quad_Model::unscale ( NOMAD::Point & x ) const { - if ( _error_flag || _n != x.size() ) - return false; - - if (_dirP.size()==0) - { - // Scale without rotation - for ( int i = 0 ; i < _n ; ++i ) - { - if ( !_ref [i].is_defined() || - !_scaling[i].is_defined() || - ! x[i].is_defined() ) - return false; - - x[i] *= _scaling[i]; - x[i] += _ref [i]; - } - } - else - { - - if (! _epsilon.is_defined() || !_delta_m.is_complete()) - return false; - - // UnScale with rotation see paper Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2012 - //T^−1(x) = center+ _delta_m Dp ((ε−1)x−ε1) - NOMAD::Point temp(_n,0.0); - for ( int i = 0 ; i < _n ; ++i ) - { - temp[i]=(x[i]*(_epsilon-1.0)-_epsilon)*_delta_m[i]; - x[i]=0.0; - } - std::list<NOMAD::Direction>::const_iterator itDir; - int j=0; - for (itDir=_dirP.begin(); itDir != _dirP.end(); itDir++,j++) - { - for (int i=0 ; i< _n ; i++) - { - x[i]+=temp[j]*(*itDir)[i]; - } - } - for ( int i = 0 ; i < _n ; ++i ) - { - x[i]+=_center[i]; - } - } - - return true; + if ( _error_flag || _n != x.size() ) + return false; + + if (_dirP.size()==0) + { + // Scale without rotation + for ( int i = 0 ; i < _n ; ++i ) + { + if ( !_ref [i].is_defined() || + !_scaling[i].is_defined() || + ! x[i].is_defined() ) + return false; + + x[i] *= _scaling[i]; + x[i] += _ref [i]; + } + } + else + { + + if (! _epsilon.is_defined() || !_delta_m.is_complete()) + return false; + + // UnScale with rotation see paper Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2014 + //T^−1(x) = center+ _delta_m Dp ((ε−1)x−ε1) + NOMAD::Point temp(_n,0.0); + for ( int i = 0 ; i < _n ; ++i ) + { + temp[i]=(x[i]*(_epsilon-1.0)-_epsilon)*_delta_m[i]; + x[i]=0.0; + } + std::list<NOMAD::Direction>::const_iterator itDir; + int j=0; + for (itDir=_dirP.begin(); itDir != _dirP.end(); itDir++,j++) + { + for (int i=0 ; i< _n ; i++) + { + x[i]+=temp[j]*(*itDir)[i]; + } + } + for ( int i = 0 ; i < _n ; ++i ) + { + x[i]+=_center[i]; + } + } + + return true; } /*-----------------------------------------------------------*/ @@ -665,19 +675,19 @@ bool NOMAD::Quad_Model::unscale ( NOMAD::Point & x ) const /*-----------------------------------------------------------*/ bool NOMAD::Quad_Model::unscale_grad ( NOMAD::Point & x ) const { - if ( _error_flag || _n != x.size() ) - return false; - - for ( int i = 0 ; i < _n ; ++i ) - { - - if (!_scaling[i].is_defined() || !x[i].is_defined() ) - return false; - - x[i] *= _scaling[i]; - } - - return true; + if ( _error_flag || _n != x.size() ) + return false; + + for ( int i = 0 ; i < _n ; ++i ) + { + + if (!_scaling[i].is_defined() || !x[i].is_defined() ) + return false; + + x[i] *= _scaling[i]; + } + + return true; } /*------------------------------------------------------------------*/ @@ -685,73 +695,73 @@ bool NOMAD::Quad_Model::unscale_grad ( NOMAD::Point & x ) const /* (private) */ /*------------------------------------------------------------------*/ double NOMAD::Quad_Model::compute_M ( int i , int j ) const { - - if ( _error_flag ) - return 0.0; - - if ( j == 0 ) - return 1.0; - - if ( j <= _nfree ) - return (*_Y[i])[_index[j]-1].value(); - - if ( j <= 2 * _nfree ) - return 0.5 * pow ( (*_Y[i])[_index[j-_nfree]-1].value() , 2.0 ); - - int nm1 = _nfree - 1; - int jm2n , dec , r , i1 , i2; - - jm2n = j - 2 * _nfree; - dec = nm1; - r = jm2n; - i1 = -1; - - while ( r > 0 ) { - r -= dec; - ++i1; - --dec; - } - - i2 = r + nm1; - - return (*_Y[i])[_index[i1+1]-1].value() * (*_Y[i])[_index[i2+1]-1].value(); + + if ( _error_flag ) + return 0.0; + + if ( j == 0 ) + return 1.0; + + if ( j <= _nfree ) + return (*_Y[i])[_index[j]-1].value(); + + if ( j <= 2 * _nfree ) + return 0.5 * pow ( (*_Y[i])[_index[j-_nfree]-1].value() , 2.0 ); + + int nm1 = _nfree - 1; + int jm2n , dec , r , i1 , i2; + + jm2n = j - 2 * _nfree; + dec = nm1; + r = jm2n; + i1 = -1; + + while ( r > 0 ) { + r -= dec; + ++i1; + --dec; + } + + i2 = r + nm1; + + return (*_Y[i])[_index[i1+1]-1].value() * (*_Y[i])[_index[i2+1]-1].value(); } /*-----------------------------------------------------------*/ /* construct m models (one by output) */ /*-----------------------------------------------------------*/ void NOMAD::Quad_Model::construct ( bool use_WP , - double eps , - int max_mpn , - int max_Y_size ) + double eps , + int max_mpn , + int max_Y_size ) { - if ( _error_flag ) - return; - - int p1 = get_nY(); - - - // MFN interpolation: - if ( p1 < _n_alpha ) { - _interpolation_type = NOMAD::MFN; - _error_flag = !construct_MFN_model ( eps , max_mpn , max_Y_size ); - } - else { - - _error_flag = true; - - // well-poised regression: - if ( use_WP && p1 > _n_alpha ) { - _interpolation_type = NOMAD::WP_REGRESSION; - _error_flag = !construct_WP_model ( max_Y_size ); + if ( _error_flag ) + return; + + int p1 = get_nY(); + + + // MFN interpolation: + if ( p1 < _n_alpha ) { + _interpolation_type = NOMAD::MFN; + _error_flag = !construct_MFN_model ( eps , max_mpn , max_Y_size ); } - - // regression: - if ( _error_flag ) { - _interpolation_type = NOMAD::REGRESSION; - _error_flag = !construct_regression_model ( eps , max_mpn , max_Y_size ); + else { + + _error_flag = true; + + // well-poised regression: + if ( use_WP && p1 > _n_alpha ) { + _interpolation_type = NOMAD::WP_REGRESSION; + _error_flag = !construct_WP_model ( max_Y_size ); + } + + // regression: + if ( _error_flag ) { + _interpolation_type = NOMAD::REGRESSION; + _error_flag = !construct_regression_model ( eps , max_mpn , max_Y_size ); + } } - } } /*---------------------------------------------------------------*/ @@ -763,27 +773,27 @@ void NOMAD::Quad_Model::construct ( bool use_WP , /*---------------------------------------------------------------*/ int NOMAD::Quad_Model::find_max_lix ( const NOMAD::Point & li , - const std::vector<NOMAD::Eval_Point *> & Y , - int i1 , - int i2 , - NOMAD::Double & max_lix ) const + const std::vector<NOMAD::Eval_Point *> & Y , + int i1 , + int i2 , + NOMAD::Double & max_lix ) const { - max_lix = -1.0; - int ji = -1; - NOMAD::Double tmp; - for ( int j = i1 ; j <= i2 ; ++j ) { - tmp = eval ( *Y[j] , li ); - if ( tmp.is_defined() ) { - tmp = tmp.abs(); - if ( tmp > max_lix ) { - max_lix = tmp; - ji = j; - } - } - } - if ( ji < 0 ) - max_lix.clear(); - return ji; + max_lix = -1.0; + int ji = -1; + NOMAD::Double tmp; + for ( int j = i1 ; j <= i2 ; ++j ) { + tmp = eval ( *Y[j] , li ); + if ( tmp.is_defined() ) { + tmp = tmp.abs(); + if ( tmp > max_lix ) { + max_lix = tmp; + ji = j; + } + } + } + if ( ji < 0 ) + max_lix.clear(); + return ji; } /*-----------------------------------------------------------*/ @@ -791,378 +801,378 @@ int NOMAD::Quad_Model::find_max_lix /*-----------------------------------------------------------*/ bool NOMAD::Quad_Model::construct_WP_model ( int max_Y_size ) { - -#ifdef DEBUG - _out << std::endl - << NOMAD::open_block ( "NOMAD::Quad_Model::construct_WP_model()" ); -#endif - - // check the set Y: - if ( !check_Y() ) - return false; - - int i , j , k , p1 = get_nY(); - - // the number of points (p+1) must be in [1+(n+1)(n+2)/2;MS_MAX_Y_SIZE]: - if ( p1 <= _n_alpha || p1 > max_Y_size ) { + #ifdef DEBUG _out << std::endl - << "NOMAD::Quad_Model::construct_WP_model(): " - << "(p+1) not in [1+(n+1)(n+2)/2;" << max_Y_size << "]" - << std::endl << NOMAD::close_block() << std::endl; + << NOMAD::open_block ( "NOMAD::Quad_Model::construct_WP_model()" ); #endif - return false; - } - - // Lagrange polynomials: - std::vector<NOMAD::Point *> l; - for ( i = 0 ; i < _n_alpha ; ++i ) { - l.push_back ( new NOMAD::Point ( _n_alpha ) ); - for ( j = 0 ; j < _n_alpha ; ++j ) - (*l[i])[j] = (i==j) ? 1.0 : 0.0; - } - - // creation of sets Y1 and Y2; Y2 contains all available points - // of _Y and Y1 will be the 'well-poised' set with n_alpha points: - std::vector<NOMAD::Eval_Point *> Y1 , Y2 = _Y; - int iy2 , ny2m1 = p1-1; - NOMAD::Double max_lix , liyi , ljyi; - - // we init Y1 with the first point of Y: - Y1.push_back ( Y2[0] ); - Y2[0] = Y2[ny2m1]; - Y2.resize ( ny2m1 ); - - // use algo 6.2 p.95 of the DFO book in order to construct Lagrange polynomials: - // ----------------------------------------------------------------------------- - for ( i = 0 ; i < _n_alpha ; ++i ) { - - // 1. point selection (select a point in Y2: Y2[iy2]): - // ------------------- - if ( i > 0 ) { - - ny2m1 = static_cast<int>(Y2.size())-1; - iy2 = find_max_lix ( *l[i] , Y2 , 0 , ny2m1 , max_lix ); - - if ( iy2 < 0 ) { + + // check the set Y: + if ( !check_Y() ) + return false; + + int i , j , k , p1 = get_nY(); + + // the number of points (p+1) must be in [1+(n+1)(n+2)/2;MS_MAX_Y_SIZE]: + if ( p1 <= _n_alpha || p1 > max_Y_size ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::construct_WP_model(): " - << "cannot find candidate in Y" - << std::endl << NOMAD::close_block() << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::construct_WP_model(): " + << "(p+1) not in [1+(n+1)(n+2)/2;" << max_Y_size << "]" + << std::endl << NOMAD::close_block() << std::endl; #endif - for ( i = 0 ; i < _n_alpha ; ++i ) - delete l[i]; - return false; - } - - // add Y2[iy2] in Y1: - Y1.push_back ( Y2[iy2] ); - Y2[iy2] = Y2[ny2m1]; - Y2.resize (ny2m1); + return false; } - - // 2. normalization: - // ----------------- - liyi = eval ( *Y1[i] , *l[i] ); - - if ( liyi.abs().value() < 1e-15 ) { + + // Lagrange polynomials: + std::vector<NOMAD::Point *> l; + for ( i = 0 ; i < _n_alpha ; ++i ) { + l.push_back ( new NOMAD::Point ( _n_alpha ) ); + for ( j = 0 ; j < _n_alpha ; ++j ) + (*l[i])[j] = (i==j) ? 1.0 : 0.0; + } + + // creation of sets Y1 and Y2; Y2 contains all available points + // of _Y and Y1 will be the 'well-poised' set with n_alpha points: + std::vector<NOMAD::Eval_Point *> Y1 , Y2 = _Y; + int iy2 , ny2m1 = p1-1; + NOMAD::Double max_lix , liyi , ljyi; + + // we init Y1 with the first point of Y: + Y1.push_back ( Y2[0] ); + Y2[0] = Y2[ny2m1]; + Y2.resize ( ny2m1 ); + + // use algo 6.2 p.95 of the DFO book in order to construct Lagrange polynomials: + // ----------------------------------------------------------------------------- + for ( i = 0 ; i < _n_alpha ; ++i ) { + + // 1. point selection (select a point in Y2: Y2[iy2]): + // ------------------- + if ( i > 0 ) { + + ny2m1 = static_cast<int>(Y2.size())-1; + iy2 = find_max_lix ( *l[i] , Y2 , 0 , ny2m1 , max_lix ); + + if ( iy2 < 0 ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::construct_WP_model(): set Y is not poised" - << std::endl << NOMAD::close_block() << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::construct_WP_model(): " + << "cannot find candidate in Y" + << std::endl << NOMAD::close_block() << std::endl; #endif - for ( i = 0 ; i < _n_alpha ; ++i ) - delete l[i]; - return false; - } - - for ( k = 0 ; k < _n_alpha ; ++k ) { - (*l[i])[k] /= liyi; - if ( (*l[i])[k].abs().value() < 1e-15 ) - (*l[i])[k] = 0.0; - } - - // 3. orthogonalization: - // --------------------- - for ( j = 0 ; j < _n_alpha ; ++j ) - if ( j != i ) { - ljyi = eval ( *Y1[i] , *l[j] ); - for ( k = 0 ; k < _n_alpha ; ++k ) { - (*l[j])[k] = (*l[j])[k] - ljyi * (*l[i])[k]; - if ( (*l[j])[k].abs().value() < 1e-15 ) - (*l[j])[k] = 0.0; - } - } - } - + for ( i = 0 ; i < _n_alpha ; ++i ) + delete l[i]; + return false; + } + + // add Y2[iy2] in Y1: + Y1.push_back ( Y2[iy2] ); + Y2[iy2] = Y2[ny2m1]; + Y2.resize (ny2m1); + } + + // 2. normalization: + // ----------------- + liyi = eval ( *Y1[i] , *l[i] ); + + if ( liyi.abs().value() < 1e-15 ) { #ifdef DEBUG - display_lagrange_polynomials ( l , Y1 ); + _out << std::endl + << "NOMAD::Quad_Model::construct_WP_model(): set Y is not poised" + << std::endl << NOMAD::close_block() << std::endl; #endif - - // compute alpha: - // -------------- - int m = static_cast<int> ( _bbot.size() ); - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) { - for ( j = 0 ; j < _n_alpha ; ++j ) { - (*_alpha[i])[j] = 0.0; - for ( k = 0 ; k < _n_alpha ; ++k ) - (*_alpha[i])[j] += Y1[k]->get_bb_outputs()[i] * (*l[k])[j]; - } + for ( i = 0 ; i < _n_alpha ; ++i ) + delete l[i]; + return false; + } + + for ( k = 0 ; k < _n_alpha ; ++k ) { + (*l[i])[k] /= liyi; + if ( (*l[i])[k].abs().value() < 1e-15 ) + (*l[i])[k] = 0.0; + } + + // 3. orthogonalization: + // --------------------- + for ( j = 0 ; j < _n_alpha ; ++j ) + if ( j != i ) { + ljyi = eval ( *Y1[i] , *l[j] ); + for ( k = 0 ; k < _n_alpha ; ++k ) { + (*l[j])[k] = (*l[j])[k] - ljyi * (*l[i])[k]; + if ( (*l[j])[k].abs().value() < 1e-15 ) + (*l[j])[k] = 0.0; + } + } } - - // poisedness improvement using algorithm 6.3 page 95: - // --------------------------------------------------- - - // old alpha: - NOMAD::Point ** old_alpha = new NOMAD::Point * [m] , ** tmp_alpha; - for ( i = 0 ; i < m ; ++i ) - old_alpha[i] = ( _alpha[i] ) ? - new NOMAD::Point ( _n_alpha ) : NULL; - - int ik; - NOMAD::Double ljyk , lkyk , lix , new_rel_err , - cur_rel_err = compute_max_rel_err(); - - if ( cur_rel_err.is_defined() && cur_rel_err.value() > 1e-15 ) { - - for ( int niter = 0 ; niter < 10 ; ++niter ) { - - ny2m1 = static_cast<int>(Y2.size())-1; - - if ( ny2m1 < 0 ) - break; - - max_lix = -1.0; - iy2 = -1; - ik = -1; - - for ( i = 0 ; i < _n_alpha ; ++i ) { - - j = find_max_lix ( *l[i] , Y2 , 0 , ny2m1 , lix ); - if ( j >= 0 && lix > max_lix ) { - max_lix = lix; - iy2 = j; - ik = i; - } - } - - if ( ik < 0 ) - break; - - // set Y1[ik] = Y2[iy2]: - Y1[ik ] = Y2[iy2]; - Y2[iy2] = Y2[ny2m1]; - Y2.resize ( ny2m1 ); - - lkyk = eval ( *Y1[ik] , *l[ik] ); - - if ( lkyk.abs() <= 1e-15 ) - break; - - // update Lagrange polynomials: - // ---------------------------- - - // normalization and orthogonalization: - for ( i = 0 ; i < _n_alpha ; ++i ) - (*l[ik])[i] /= lkyk; - - for ( j = 0 ; j < _n_alpha ; ++j ) { - if ( j != ik ) { - ljyk = eval ( *Y1[ik] , *l[j] ); - for ( i = 0 ; i < _n_alpha ; ++i ) - (*l[j])[i] = (*l[j])[i] - ljyk * (*l[ik])[i]; - } - } - - // save old alpha and compute new one: - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) { - *(old_alpha[i]) = *(_alpha[i]); - for ( j = 0 ; j < _n_alpha ; ++j ) { - (*_alpha[i])[j] = 0.0; - for ( k = 0 ; k < _n_alpha ; ++k ) - (*_alpha[i])[j] += Y1[k]->get_bb_outputs()[i] * (*l[k])[j]; - } - } - - // compute new error: - new_rel_err = compute_max_rel_err(); - - // if no better error, restore old alpha and exit loop: - if ( !new_rel_err.is_defined() || new_rel_err >= cur_rel_err ) { - tmp_alpha = _alpha; - _alpha = old_alpha; - old_alpha = tmp_alpha; - break; - } - - cur_rel_err = new_rel_err; + +#ifdef DEBUG + display_lagrange_polynomials ( l , Y1 ); +#endif + + // compute alpha: + // -------------- + int m = static_cast<int> ( _bbot.size() ); + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) { + for ( j = 0 ; j < _n_alpha ; ++j ) { + (*_alpha[i])[j] = 0.0; + for ( k = 0 ; k < _n_alpha ; ++k ) + (*_alpha[i])[j] += Y1[k]->get_bb_outputs()[i] * (*l[k])[j]; + } + } + + // poisedness improvement using algorithm 6.3 page 95: + // --------------------------------------------------- + + // old alpha: + NOMAD::Point ** old_alpha = new NOMAD::Point * [m] , ** tmp_alpha; + for ( i = 0 ; i < m ; ++i ) + old_alpha[i] = ( _alpha[i] ) ? + new NOMAD::Point ( _n_alpha ) : NULL; + + int ik; + NOMAD::Double ljyk , lkyk , lix , new_rel_err , + cur_rel_err = compute_max_rel_err(); + + if ( cur_rel_err.is_defined() && cur_rel_err.value() > 1e-15 ) { + + for ( int niter = 0 ; niter < 10 ; ++niter ) { + + ny2m1 = static_cast<int>(Y2.size())-1; + + if ( ny2m1 < 0 ) + break; + + max_lix = -1.0; + iy2 = -1; + ik = -1; + + for ( i = 0 ; i < _n_alpha ; ++i ) { + + j = find_max_lix ( *l[i] , Y2 , 0 , ny2m1 , lix ); + if ( j >= 0 && lix > max_lix ) { + max_lix = lix; + iy2 = j; + ik = i; + } + } + + if ( ik < 0 ) + break; + + // set Y1[ik] = Y2[iy2]: + Y1[ik ] = Y2[iy2]; + Y2[iy2] = Y2[ny2m1]; + Y2.resize ( ny2m1 ); + + lkyk = eval ( *Y1[ik] , *l[ik] ); + + if ( lkyk.abs() <= 1e-15 ) + break; + + // update Lagrange polynomials: + // ---------------------------- + + // normalization and orthogonalization: + for ( i = 0 ; i < _n_alpha ; ++i ) + (*l[ik])[i] /= lkyk; + + for ( j = 0 ; j < _n_alpha ; ++j ) { + if ( j != ik ) { + ljyk = eval ( *Y1[ik] , *l[j] ); + for ( i = 0 ; i < _n_alpha ; ++i ) + (*l[j])[i] = (*l[j])[i] - ljyk * (*l[ik])[i]; + } + } + + // save old alpha and compute new one: + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) { + *(old_alpha[i]) = *(_alpha[i]); + for ( j = 0 ; j < _n_alpha ; ++j ) { + (*_alpha[i])[j] = 0.0; + for ( k = 0 ; k < _n_alpha ; ++k ) + (*_alpha[i])[j] += Y1[k]->get_bb_outputs()[i] * (*l[k])[j]; + } + } + + // compute new error: + new_rel_err = compute_max_rel_err(); + + // if no better error, restore old alpha and exit loop: + if ( !new_rel_err.is_defined() || new_rel_err >= cur_rel_err ) { + tmp_alpha = _alpha; + _alpha = old_alpha; + old_alpha = tmp_alpha; + break; + } + + cur_rel_err = new_rel_err; + } } - } - - for ( i = 0 ; i < m ; ++i ) - delete old_alpha[i]; - delete [] old_alpha; - for ( i = 0 ; i < _n_alpha ; ++i ) - delete l[i]; - + + for ( i = 0 ; i < m ; ++i ) + delete old_alpha[i]; + delete [] old_alpha; + for ( i = 0 ; i < _n_alpha ; ++i ) + delete l[i]; + #ifdef DEBUG - _out.close_block(); + _out.close_block(); #endif - - return true; + + return true; } /*-----------------------------------------------------------*/ /* construct regression model (private) */ /*-----------------------------------------------------------*/ bool NOMAD::Quad_Model::construct_regression_model ( double eps , - int max_mpn , - int max_Y_size ) + int max_mpn , + int max_Y_size ) { #ifdef DEBUG - _out << std::endl - << NOMAD::open_block ( "NOMAD::Quad_Model::construct_regression_model()" ); -#endif - - _error_flag = false; - - // check the set Y: - if ( !check_Y() ) - return false; - - int p1 = get_nY(); - - // the number of points (p+1) must be in [(n+1)(n+2)/2;MS_MAX_Y_SIZE]: - if ( p1 < _n_alpha || p1 > max_Y_size ) { -#ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::construct_regression_model(): " - << "(p+1) not in [(n+1)(n+2)/2;" - << max_Y_size << "]" - << std::endl << NOMAD::close_block() << std::endl; -#endif - return false; - } - - // for this procedure, the number of points is limited to 500 - // (because of the SVD decomposition): - if ( p1 > 500 ) { - reduce_Y ( NOMAD::Point ( _n , 0.0 ) , 500 ); - p1 = 500; - } - - // construct the matrix F=M'M (_n_alpha,_n_alpha): - // ----------------------------------------------- - int i , j , k; - double ** F = new double *[_n_alpha]; - double ** M = new double *[p1]; - for ( i = 0 ; i < p1 ; ++i ) { - M[i] = new double[_n_alpha]; - for ( j = 0 ; j < _n_alpha ; ++j ) - M[i][j] = compute_M ( i , j ); - } - - for ( i = 0 ; i < _n_alpha ; ++i ) { - F[i] = new double[_n_alpha]; - for ( j = 0 ; j <= i ; ++j ) { - F[i][j] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - F[i][j] += M[k][i] * M[k][j]; - if ( i != j ) - F[j][i] = F[i][j]; - } - } - -#ifdef DEBUG - _out << std::endl << "F="; - for ( i = 0 ; i < _n_alpha ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < _n_alpha ; ++j ) - _out << std::setw(12) << F[i][j] << " "; - _out << std::endl; - } + _out << std::endl + << NOMAD::open_block ( "NOMAD::Quad_Model::construct_regression_model()" ); #endif - - bool error = false; - - // SVD decomposition of the F matrix (F=U.W.V'): - // --------------------------------------------- - // (F will be transformed in U) - - double * W = new double [_n_alpha]; - double ** V = new double *[_n_alpha]; - for ( i = 0 ; i < _n_alpha ; ++i ) - V[i] = new double[_n_alpha]; - - std::string error_msg; - if ( NOMAD::SVD_decomposition ( error_msg , F , W , V , _n_alpha , _n_alpha , max_mpn ) ) { - - // compute condition number: - compute_cond ( W , _n_alpha , eps ); - + + _error_flag = false; + + // check the set Y: + if ( !check_Y() ) + return false; + + int p1 = get_nY(); + + // the number of points (p+1) must be in [(n+1)(n+2)/2;MS_MAX_Y_SIZE]: + if ( p1 < _n_alpha || p1 > max_Y_size ) { #ifdef DEBUG - _out << std::endl << "F="; + _out << std::endl + << "NOMAD::Quad_Model::construct_regression_model(): " + << "(p+1) not in [(n+1)(n+2)/2;" + << max_Y_size << "]" + << std::endl << NOMAD::close_block() << std::endl; +#endif + return false; + } + + // for this procedure, the number of points is limited to 500 + // (because of the SVD decomposition): + if ( p1 > 500 ) { + reduce_Y ( NOMAD::Point ( _n , 0.0 ) , 500 ); + p1 = 500; + } + + // construct the matrix F=M'M (_n_alpha,_n_alpha): + // ----------------------------------------------- + int i , j , k; + double ** F = new double *[_n_alpha]; + double ** M = new double *[p1]; + for ( i = 0 ; i < p1 ; ++i ) { + M[i] = new double[_n_alpha]; + for ( j = 0 ; j < _n_alpha ; ++j ) + M[i][j] = compute_M ( i , j ); + } + for ( i = 0 ; i < _n_alpha ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < _n_alpha ; ++j ) - _out << std::setw(12) << F[i][j] << " "; - _out << std::endl; + F[i] = new double[_n_alpha]; + for ( j = 0 ; j <= i ; ++j ) { + F[i][j] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + F[i][j] += M[k][i] * M[k][j]; + if ( i != j ) + F[j][i] = F[i][j]; + } } - - _out << std::endl << "W=\t"; - for ( i = 0 ; i < _n_alpha ; ++i ) - _out << std::setw(12) << W[i] << " "; - _out << std::endl << std::endl << "cond=" << _cond << std::endl; - _out << std::endl << "V="; +#ifdef DEBUG + _out << std::endl << "F="; for ( i = 0 ; i < _n_alpha ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < _n_alpha ; ++j ) - _out << std::setw(12) << V[i][j] << " "; - _out << std::endl; + _out << "\t"; + for ( j = 0 ; j < _n_alpha ; ++j ) + _out << std::setw(12) << F[i][j] << " "; + _out << std::endl; } #endif - - } - else { + + bool error = false; + + // SVD decomposition of the F matrix (F=U.W.V'): + // --------------------------------------------- + // (F will be transformed in U) + + double * W = new double [_n_alpha]; + double ** V = new double *[_n_alpha]; + for ( i = 0 ; i < _n_alpha ; ++i ) + V[i] = new double[_n_alpha]; + + std::string error_msg; + if ( NOMAD::SVD_decomposition ( error_msg , F , W , V , _n_alpha , _n_alpha , max_mpn ) ) { + + // compute condition number: + compute_cond ( W , _n_alpha , eps ); + #ifdef DEBUG - _out << std::endl << "NOMAD::Quad_Model::construct_regression_model(): " - << "SVD decomposition (" << error_msg << ")" - << std::endl << NOMAD::close_block() << std::endl; + _out << std::endl << "F="; + for ( i = 0 ; i < _n_alpha ; ++i ) { + _out << "\t"; + for ( j = 0 ; j < _n_alpha ; ++j ) + _out << std::setw(12) << F[i][j] << " "; + _out << std::endl; + } + + _out << std::endl << "W=\t"; + for ( i = 0 ; i < _n_alpha ; ++i ) + _out << std::setw(12) << W[i] << " "; + _out << std::endl << std::endl << "cond=" << _cond << std::endl; + + _out << std::endl << "V="; + for ( i = 0 ; i < _n_alpha ; ++i ) { + _out << "\t"; + for ( j = 0 ; j < _n_alpha ; ++j ) + _out << std::setw(12) << V[i][j] << " "; + _out << std::endl; + } #endif - error = true; - _cond.clear(); - } - - // resolution of system F.alpha = M'.f(Y): - // --------------------------------------- - if ( !error ) { - int m = static_cast<int> ( _bbot.size() ); - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) - solve_regression_system ( M , F , W , V , i , *_alpha[i] , eps ); - } - - // free memory: - for ( i = 0 ; i < _n_alpha ; ++i ) { - delete [] F[i]; - delete [] V[i]; - } - for ( i = 0 ; i < p1 ; ++i ) - delete [] M[i]; - delete [] M; - delete [] F; - delete [] V; - delete [] W; - + + } + else { #ifdef DEBUG - _out.close_block(); + _out << std::endl << "NOMAD::Quad_Model::construct_regression_model(): " + << "SVD decomposition (" << error_msg << ")" + << std::endl << NOMAD::close_block() << std::endl; #endif - - return !error; + error = true; + _cond.clear(); + } + + // resolution of system F.alpha = M'.f(Y): + // --------------------------------------- + if ( !error ) { + int m = static_cast<int> ( _bbot.size() ); + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) + solve_regression_system ( M , F , W , V , i , *_alpha[i] , eps ); + } + + // free memory: + for ( i = 0 ; i < _n_alpha ; ++i ) { + delete [] F[i]; + delete [] V[i]; + } + for ( i = 0 ; i < p1 ; ++i ) + delete [] M[i]; + delete [] M; + delete [] F; + delete [] V; + delete [] W; + +#ifdef DEBUG + _out.close_block(); +#endif + + return !error; } /*-------------------------------------------------------------*/ @@ -1170,17 +1180,17 @@ bool NOMAD::Quad_Model::construct_regression_model ( double eps , /*-------------------------------------------------------------*/ void NOMAD::Quad_Model::compute_cond ( const double * W , int n , double eps ) { - double min = NOMAD::INF; - double max = -min; - for ( int i = 0 ; i < n ; ++i ) { - if ( W[i] < min ) - min = W[i]; - if ( W[i] > max ) - max = W[i]; - } - if ( min < eps ) - min = eps; - _cond = max / min; + double min = NOMAD::INF; + double max = -min; + for ( int i = 0 ; i < n ; ++i ) { + if ( W[i] < min ) + min = W[i]; + if ( W[i] > max ) + max = W[i]; + } + if ( min < eps ) + min = eps; + _cond = max / min; } /*-------------------------------------------------------------*/ @@ -1188,224 +1198,235 @@ void NOMAD::Quad_Model::compute_cond ( const double * W , int n , double eps ) /* (private) */ /*-------------------------------------------------------------*/ void NOMAD::Quad_Model::solve_regression_system ( double ** M , - double ** F , - double * W , - double ** V , - int bbo_index , - NOMAD::Point & alpha , - double eps ) const + double ** F , + double * W , + double ** V , + int bbo_index , + NOMAD::Point & alpha , + double eps ) const { - // resize the alpha vector: - if ( alpha.size() != _n_alpha ) - alpha.reset ( _n_alpha , 0.0 ); - - double * alpha_tmp = new double [_n_alpha]; - int i , k , p1 = get_nY(); - - // solve the system: - for ( i = 0 ; i < _n_alpha ; ++i ) { - alpha_tmp[i] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - alpha_tmp[i] += M[k][i] * ( _Y[k]->get_bb_outputs()[bbo_index].value() ); - } - - double * alpha_tmp2 = new double [_n_alpha]; - - // some W values will be zero (or near zero); - // each value that is smaller than eps is ignored - - for ( i = 0 ; i < _n_alpha ; ++i ) { - alpha_tmp2[i] = 0.0; - for ( k = 0 ; k < _n_alpha ; ++k ) - if ( W[i] > eps ) - alpha_tmp2[i] += F[k][i] * alpha_tmp[k] / W[i]; - } - - delete [] alpha_tmp; - - for ( i = 0 ; i < _n_alpha ; ++i ) { - alpha[i] = 0.0; - for ( k = 0 ; k < _n_alpha ; ++k ) - alpha[i] += V[i][k] * alpha_tmp2[k]; - } - - delete [] alpha_tmp2; + // resize the alpha vector: + if ( alpha.size() != _n_alpha ) + alpha.reset ( _n_alpha , 0.0 ); + + double * alpha_tmp = new double [_n_alpha]; + int i , k , p1 = get_nY(); + + // solve the system: + for ( i = 0 ; i < _n_alpha ; ++i ) { + alpha_tmp[i] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + alpha_tmp[i] += M[k][i] * ( _Y[k]->get_bb_outputs()[bbo_index].value() ); + } + + double * alpha_tmp2 = new double [_n_alpha]; + + // some W values will be zero (or near zero); + // each value that is smaller than eps is ignored + + for ( i = 0 ; i < _n_alpha ; ++i ) { + alpha_tmp2[i] = 0.0; + for ( k = 0 ; k < _n_alpha ; ++k ) + if ( W[i] > eps ) + alpha_tmp2[i] += F[k][i] * alpha_tmp[k] / W[i]; + } + + delete [] alpha_tmp; + + for ( i = 0 ; i < _n_alpha ; ++i ) { + alpha[i] = 0.0; + for ( k = 0 ; k < _n_alpha ; ++k ) + alpha[i] += V[i][k] * alpha_tmp2[k]; + } + + delete [] alpha_tmp2; } /*----------------------------------------------------------*/ /* construct Minimum Frobenius Norm (MFN) model (private) */ /*----------------------------------------------------------*/ bool NOMAD::Quad_Model::construct_MFN_model ( double eps , - int max_mpn , - int max_Y_size ) + int max_mpn , + int max_Y_size ) { -#ifdef DEBUG - _out << std::endl - << NOMAD::open_block ( "NOMAD::Quad_Model::construct_MFN_model()" ); -#endif - - // check the set Y: - if ( !check_Y() ) - return false; - - int p1 = get_nY(); - - // the number of points (p+1) must be in [n+1;(n+1)(n+2)/2-1]: - if ( p1 <= _nfree || p1 >= _n_alpha ) { #ifdef DEBUG _out << std::endl - << "NOMAD::Quad_Model::construct_MFN_model(): " - << "(p+1) not in [n+1;(n+1)(n+2)/2-1]" - << std::endl << NOMAD::close_block() << std::endl; + << NOMAD::open_block ( "NOMAD::Quad_Model::construct_MFN_model()" ); #endif - return false; - } - - // for this procedure, the number of points is limited to 250 - // (because of the SVD decomposition): - if ( p1 > 250 ) { - reduce_Y ( NOMAD::Point ( _n , 0.0 ) , 250 ); - p1 = 250; - } - - // construct the matrix F (4 parts): - // --------------------------------- - // [ 1 | 2 ] - // [ --+-- ] - // [ 3 | 4 ] - - int i , j , k; - int np1 = _nfree + 1; - int nF = np1 + p1; - double ** F = new double *[nF]; - double ** M = new double *[p1]; - for ( i = 0 ; i < nF ; ++i ) - F[i] = new double[nF]; - - // 1/4: MQ.MQ' (p+1,p+1): - { - for ( i = 0 ; i < p1 ; ++i ) { - M[i] = new double[_n_alpha]; - for ( j = 0 ; j < _n_alpha ; ++j ) - M[i][j] = compute_M ( i , j ); - for ( j = 0 ; j <= i ; ++j ) { - F[i][j] = 0.0; - for ( k = np1 ; k < _n_alpha ; ++k ) - F[i][j] += M[i][k] * M[j][k]; - if ( i != j ) - F[j][i] = F[i][j]; - } - } - } - - // 2/4: ML (p+1,n+1): - for ( i = 0 ; i < p1 ; ++i ) { - F[i][p1] = 1.0; - for ( j = p1+1 ; j < nF ; ++j ) - F[i][j] = M[i][j-p1]; - } - - // 3/4: ML' (n+1,p+1): - for ( j = 0 ; j < p1 ; ++j ) { - F[p1][j] = 1.0; - for ( i = p1+1 ; i < nF ; ++i ) - F[i][j] = M[j][i-p1]; - } - - // 4/4: 0 (n+1,n+1): - for ( i = p1 ; i < nF ; ++i ) - for ( j = p1 ; j < nF ; ++j ) - F[i][j] = 0.0; - + + // check the set Y: + if ( !check_Y() ) + return false; + + int p1 = get_nY(); + + // the number of points (p+1) must be in [n+1;(n+1)(n+2)/2-1]: + if ( p1 <= _nfree || p1 >= _n_alpha ) { #ifdef DEBUG - _out << std::endl << "F="; - for ( i = 0 ; i < nF ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < nF ; ++j ) - _out << std::setw(12) << F[i][j] << " "; - _out << std::endl; - } + _out << std::endl + << "NOMAD::Quad_Model::construct_MFN_model(): " + << "(p+1) not in [n+1;(n+1)(n+2)/2-1]" + << std::endl << NOMAD::close_block() << std::endl; #endif - - for ( i = 0 ; i < p1 ; ++i ) - delete [] M[i]; - delete [] M; - - bool error = false; - - // SVD decomposition of the F matrix (F = U.W.V'): - // ----------------------------------------------- - // (F will be transformed in U) - - double * W = new double [nF]; - double ** V = new double *[nF]; - for ( i = 0 ; i < nF ; ++i ) - V[i] = new double[nF]; - - std::string error_msg; - - if ( NOMAD::SVD_decomposition ( error_msg , F , W , V , nF , nF , max_mpn ) ) { - - // compute condition number: - compute_cond ( W , nF , eps ); - + return false; + } + + // for this procedure, the number of points is limited to 250 + // (because of the SVD decomposition): + if ( p1 > 250 ) { + reduce_Y ( NOMAD::Point ( _n , 0.0 ) , 250 ); + p1 = 250; + } + + // construct the matrix F (4 parts): + // --------------------------------- + // [ 1 | 2 ] + // [ --+-- ] + // [ 3 | 4 ] + + int i , j , k; + int np1 = _nfree + 1; + int nF = np1 + p1; + double ** F = new double *[nF]; + double ** M = new double *[p1]; + for ( i = 0 ; i < nF ; ++i ) + F[i] = new double[nF]; + + // 1/4: MQ.MQ' (p+1,p+1): + { + for ( i = 0 ; i < p1 ; ++i ) + { + M[i] = new double[_n_alpha]; + for ( j = 0 ; j < _n_alpha ; ++j ) + M[i][j] = compute_M ( i , j ); + for ( j = 0 ; j <= i ; ++j ) + { + F[i][j] = 0.0; + for ( k = np1 ; k < _n_alpha ; ++k ) + F[i][j] += M[i][k] * M[j][k]; + if ( i != j ) + F[j][i] = F[i][j]; + } + } + } + + // 2/4: ML (p+1,n+1): + for ( i = 0 ; i < p1 ; ++i ) + { + F[i][p1] = 1.0; + for ( j = p1+1 ; j < nF ; ++j ) + F[i][j] = M[i][j-p1]; + } + + // 3/4: ML' (n+1,p+1): + for ( j = 0 ; j < p1 ; ++j ) + { + F[p1][j] = 1.0; + for ( i = p1+1 ; i < nF ; ++i ) + F[i][j] = M[j][i-p1]; + } + + // 4/4: 0 (n+1,n+1): + for ( i = p1 ; i < nF ; ++i ) + for ( j = p1 ; j < nF ; ++j ) + F[i][j] = 0.0; + + #ifdef DEBUG _out << std::endl << "F="; - for ( i = 0 ; i < nF ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < nF ; ++j ) - _out << std::setw(12) << F[i][j] << " "; - _out << std::endl; + for ( i = 0 ; i < nF ; ++i ) + { + _out << "\t"; + for ( j = 0 ; j < nF ; ++j ) + _out << std::setw(12) << F[i][j] << " "; + _out << std::endl; } +#endif + + for ( i = 0 ; i < p1 ; ++i ) + delete [] M[i]; + delete [] M; + + bool error = false; + + // SVD decomposition of the F matrix (F = U.W.V'): + // ----------------------------------------------- + // (F will be transformed in U) - _out << std::endl << "W=\t"; + double * W = new double [nF]; + double ** V = new double *[nF]; for ( i = 0 ; i < nF ; ++i ) - _out << std::setw(12) << W[i] << " "; - _out << std::endl << std::endl << "cond=" << _cond << std::endl; + V[i] = new double[nF]; - _out << std::endl << "V="; - for ( i = 0 ; i < nF ; ++i ) { - _out << "\t"; - for ( j = 0 ; j < nF ; ++j ) - _out << std::setw(12) << V[i][j] << " "; - _out << std::endl; - } + std::string error_msg; + + if ( NOMAD::SVD_decomposition ( error_msg , F , W , V , nF , nF , max_mpn ) ) { + + // compute condition number: + compute_cond ( W , nF , eps ); + +#ifdef DEBUG + _out << std::endl << "F="; + for ( i = 0 ; i < nF ; ++i ) + { + _out << "\t"; + for ( j = 0 ; j < nF ; ++j ) + _out << std::setw(12) << F[i][j] << " "; + _out << std::endl; + } + + _out << std::endl << "W=\t"; + for ( i = 0 ; i < nF ; ++i ) + _out << std::setw(12) << W[i] << " "; + _out << std::endl << std::endl << "cond=" << _cond << std::endl; + + _out << std::endl << "V="; + for ( i = 0 ; i < nF ; ++i ) + { + _out << "\t"; + for ( j = 0 ; j < nF ; ++j ) + _out << std::setw(12) << V[i][j] << " "; + _out << std::endl; + } #endif - - } - else { + + } + else + { #ifdef DEBUG - _out << std::endl << "NOMAD::Quad_Model::construct_MFN_model(): " - << "SVD decomposition (" << error_msg << ")" - << std::endl << std::endl; + _out << std::endl << "NOMAD::Quad_Model::construct_MFN_model(): " + << "SVD decomposition (" << error_msg << ")" + << std::endl << std::endl; #endif - error = true; - _cond.clear(); - } - - // resolution of system F.[mu alpha_L]'=[f(Y) 0]' : - // ------------------------------------------------ - if ( !error ) { - int m = static_cast<int> ( _bbot.size() ); - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) - solve_MFN_system ( F , W , V , i , *_alpha[i] , eps ); - } - - // free memory: - for ( i = 0 ; i < nF ; ++i ) { - delete [] F[i]; - delete [] V[i]; - } - delete [] F; - delete [] V; - delete [] W; - + error = true; + _cond.clear(); + } + + // resolution of system F.[mu alpha_L]'=[f(Y) 0]' : + // ------------------------------------------------ + if ( !error ) + { + int m = static_cast<int> ( _bbot.size() ); + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) + solve_MFN_system ( F , W , V , i , *_alpha[i] , eps ); + } + + // free memory: + for ( i = 0 ; i < nF ; ++i ) + { + delete [] F[i]; + delete [] V[i]; + } + delete [] F; + delete [] V; + delete [] W; + #ifdef DEBUG - _out.close_block(); + _out.close_block(); #endif - - return !error; + + return !error; } /*--------------------------------------------------*/ @@ -1413,89 +1434,101 @@ bool NOMAD::Quad_Model::construct_MFN_model ( double eps , /* for MFN interpolation (private) */ /*--------------------------------------------------*/ void NOMAD::Quad_Model::solve_MFN_system ( double ** F , - double * W , - double ** V , - int bbo_index , - NOMAD::Point & alpha , - double eps ) const + double * W , + double ** V , + int bbo_index , + NOMAD::Point & alpha , + double eps ) const { - // resize the alpha vector: - if ( alpha.size() != _n_alpha ) - alpha.reset ( _n_alpha , 0.0 ); - - int i , k , k1 , k2 , + // resize the alpha vector: + if ( alpha.size() != _n_alpha ) + alpha.reset ( _n_alpha , 0.0 ); + + int i , k , k1 , k2 , np1 = _nfree + 1 , nm1 = _nfree - 1 , p1 = get_nY() , nF = np1 + p1; - - // step 1/2: find alpha_L and mu: - // --------- - double * alpha_tmp = new double [np1]; - double * mu_tmp = new double [ p1]; - double * mu = new double [ p1]; - - // if F is singular, some W values will be zero (or near zero); - // each value that is smaller than eps is ignored: - for ( i = 0 ; i < p1 ; ++i ) { - mu_tmp[i] = 0.0; - if ( W[i] > eps ) - for ( k = 0 ; k < p1 ; ++k ) - mu_tmp[i] += F[k][i] * - ( _Y[k]->get_bb_outputs()[bbo_index].value() ) / W[i]; - } - - for ( i = p1 ; i < nF ; ++i ) { - alpha_tmp[i-p1] = 0.0; - if ( W[i] > eps ) - for ( k = 0 ; k < p1 ; ++k ) - alpha_tmp[i-p1] += F[k][i] * - ( _Y[k]->get_bb_outputs()[bbo_index].value() ) / W[i]; - } - - for ( i = 0 ; i < p1 ; ++i ) { - mu[i] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - mu[i] += V[i][k] * mu_tmp[k]; - for ( k = p1 ; k < nF ; ++k ) - mu[i] += V[i][k] * alpha_tmp[k-p1]; - } - - for ( i = p1 ; i < nF ; ++i ) { - alpha[i-p1] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - alpha[i-p1] += V[i][k] * mu_tmp[k]; - for ( k = p1 ; k < nF ; ++k ) - alpha[i-p1] += V[i][k] * alpha_tmp[k-p1]; - } - - delete [] alpha_tmp; - delete [] mu_tmp; - + + // step 1/2: find alpha_L and mu: + // --------- + double * alpha_tmp = new double [np1]; + double * mu_tmp = new double [ p1]; + double * mu = new double [ p1]; + + // if F is singular, some W values will be zero (or near zero); + // each value that is smaller than eps is ignored: + for ( i = 0 ; i < p1 ; ++i ) + { + mu_tmp[i] = 0.0; + if ( W[i] > eps ) + for ( k = 0 ; k < p1 ; ++k ) + mu_tmp[i] += F[k][i] * + ( _Y[k]->get_bb_outputs()[bbo_index].value() ) / W[i]; + } + + for ( i = p1 ; i < nF ; ++i ) + { + alpha_tmp[i-p1] = 0.0; + if ( W[i] > eps ) + for ( k = 0 ; k < p1 ; ++k ) + alpha_tmp[i-p1] += F[k][i] * + ( _Y[k]->get_bb_outputs()[bbo_index].value() ) / W[i]; + } + + for ( i = 0 ; i < p1 ; ++i ) + { + mu[i] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + mu[i] += V[i][k] * mu_tmp[k]; + for ( k = p1 ; k < nF ; ++k ) + mu[i] += V[i][k] * alpha_tmp[k-p1]; + } + + for ( i = p1 ; i < nF ; ++i ) + { + alpha[i-p1] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + alpha[i-p1] += V[i][k] * mu_tmp[k]; + for ( k = p1 ; k < nF ; ++k ) + alpha[i-p1] += V[i][k] * alpha_tmp[k-p1]; + } + + delete [] alpha_tmp; + delete [] mu_tmp; + #ifdef DEBUG - _out << std::endl << "output #" << bbo_index << ": mu=\t"; - for ( i = 0 ; i < p1 ; ++i ) - _out << std::setw(12) << mu[i] << " "; - _out << std::endl; + _out << std::endl << "output #" << bbo_index << ": mu=\t"; + for ( i = 0 ; i < p1 ; ++i ) + _out << std::setw(12) << mu[i] << " "; + _out << std::endl; + + _out << std::endl << "output #" << bbo_index << ": alpha_intermediate=\t"; + for ( i = 0 ; i < alpha.size() ; ++i ) + _out << std::setw(12) << alpha[i] << " "; + _out << std::endl; + #endif - - // step 2/2: find alpha_Q: - // --------- - for ( i = 0 ; i < _nfree ; ++i ) { - alpha[i+np1] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - alpha[i+np1] += mu[k] * pow ( (*_Y[k])[i].value() , 2.0 ) / 2.0; - } - - for ( k1 = 0 ; k1 < nm1 ; ++k1 ) - for ( k2 = k1+1 ; k2 < _nfree ; ++k2 ) { - alpha[i+np1] = 0.0; - for ( k = 0 ; k < p1 ; ++k ) - alpha[i+np1] += mu[k] * (*_Y[k])[k1].value() * (*_Y[k])[k2].value(); - ++i; + + // step 2/2: find alpha_Q: + // --------- + for ( i = 0 ; i < _nfree ; ++i ) + { + alpha[i+np1] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + alpha[i+np1] += mu[k] * pow ( (*_Y[k])[_index[i+1]-1].value() , 2.0 ) / 2.0; } - - delete [] mu; + + for ( k1 = 0 ; k1 < nm1 ; ++k1 ) + for ( k2 = k1+1 ; k2 < _nfree ; ++k2 ) + { + alpha[i+np1] = 0.0; + for ( k = 0 ; k < p1 ; ++k ) + alpha[i+np1] += mu[k] * (*_Y[k])[_index[k1+1]-1].value() * (*_Y[k])[_index[k2+1]-1].value(); + ++i; + } + + delete [] mu; } /*-----------------------------------------------------------*/ @@ -1503,69 +1536,69 @@ void NOMAD::Quad_Model::solve_MFN_system ( double ** F , /*-----------------------------------------------------------*/ bool NOMAD::Quad_Model::check_Y ( void ) const { - if ( _Y.empty() ) { + if ( _Y.empty() ) { #ifdef DEBUG - _out << std::endl << "NOMAD::Quad_Model::check_Y(): set Y is empty" - << std::endl << std::endl; + _out << std::endl << "NOMAD::Quad_Model::check_Y(): set Y is empty" + << std::endl << std::endl; #endif - return false; - } - - int nY = get_nY(); - int m = static_cast<int> ( _bbot.size() ); - - for ( int k = 0 ; k < nY ; ++k ) { - - if ( _Y[k] == NULL ) { + return false; + } + + int nY = get_nY(); + int m = static_cast<int> ( _bbot.size() ); + + for ( int k = 0 ; k < nY ; ++k ) { + + if ( _Y[k] == NULL ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::check_Y(): NULL pointer in the set Y" - << std::endl << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::check_Y(): NULL pointer in the set Y" + << std::endl << std::endl; #endif - return false; - } - - if ( _Y[k]->get_eval_status() != NOMAD::EVAL_OK ) { + return false; + } + + if ( _Y[k]->get_eval_status() != NOMAD::EVAL_OK ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::check_Y(): a point in Y failed to evaluate" - << std::endl << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::check_Y(): a point in Y failed to evaluate" + << std::endl << std::endl; #endif - return false; - } - - const NOMAD::Point & bbo = _Y[k]->get_bb_outputs(); - - if ( !bbo.is_complete() ) { + return false; + } + + const NOMAD::Point & bbo = _Y[k]->get_bb_outputs(); + + if ( !bbo.is_complete() ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::check_Y(): some bb outputs in Y are not defined" - << std::endl << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::check_Y(): some bb outputs in Y are not defined" + << std::endl << std::endl; #endif - return false; - } - - if ( bbo.size() != m ) { + return false; + } + + if ( bbo.size() != m ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::check_Y(): " - << "bb outputs in Y do not have the same dimension" - << std::endl << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::check_Y(): " + << "bb outputs in Y do not have the same dimension" + << std::endl << std::endl; #endif - return false; - } - - if ( _Y[k]->size() != _n ) { + return false; + } + + if ( _Y[k]->size() != _n ) { #ifdef DEBUG - _out << std::endl - << "NOMAD::Quad_Model::check_Y(): " - << "points in Y do not have the same dimension" - << std::endl << std::endl; + _out << std::endl + << "NOMAD::Quad_Model::check_Y(): " + << "points in Y do not have the same dimension" + << std::endl << std::endl; #endif - return false; + return false; + } } - } - return true; + return true; } /*----------------------------------------------------*/ @@ -1573,26 +1606,28 @@ bool NOMAD::Quad_Model::check_Y ( void ) const /*----------------------------------------------------*/ bool NOMAD::Quad_Model::check ( void ) const { - if ( !_alpha ) - return false; - - int nalpha = (_nfree+1)*(_nfree+2)/2; - int i , m = static_cast<int> ( _bbot.size() ); - - for ( int bbo_index = 0 ; bbo_index < m ; ++bbo_index ) { - - if ( _alpha[bbo_index] ) { - - if ( _alpha[bbo_index]->size() != nalpha ) - return false; - - for ( i = 0 ; i < nalpha ; ++i ) - if ( !(*_alpha[bbo_index])[i].is_defined() ) - return false; + if ( !_alpha ) + return false; + + int nalpha = (_nfree+1)*(_nfree+2)/2; + int i , m = static_cast<int> ( _bbot.size() ); + + for ( int bbo_index = 0 ; bbo_index < m ; ++bbo_index ) + { + + if ( _alpha[bbo_index] ) + { + + if ( _alpha[bbo_index]->size() != nalpha ) + return false; + + for ( i = 0 ; i < nalpha ; ++i ) + if ( !(*_alpha[bbo_index])[i].is_defined() ) + return false; + } } - } - - return true; + + return true; } @@ -1604,27 +1639,29 @@ bool NOMAD::Quad_Model::check ( void ) const /* . a more efficient version is used in Quad_Model_Evaluator::eval_x() ) */ /*--------------------------------------------------------------------------*/ NOMAD::Double NOMAD::Quad_Model::eval ( const NOMAD::Point & x , - const NOMAD::Point & alpha ) const + const NOMAD::Point & alpha ) const { - int i , j , k = 1 , nm1 = _n-1; - NOMAD::Double z = alpha[0]; - - for ( i = 0 ; i < _n ; ++i ) { - if ( !_fixed_vars[i] ) { - z += x[i] * ( alpha[k] + 0.5 * alpha[k+_nfree] * x[i] ); - ++k; + int i , j , k = 1 , nm1 = _n-1; + NOMAD::Double z = alpha[0]; + + for ( i = 0 ; i < _n ; ++i ) + { + if ( !_fixed_vars[i] ) + { + z += x[i] * ( alpha[k] + 0.5 * alpha[k+_nfree] * x[i] ); + ++k; + } } - } - - k += _nfree; - - for ( i = 0 ; i < nm1 ; ++i ) - if ( !_fixed_vars[i] ) - for ( j = i+1 ; j < _n ; ++j ) - if ( !_fixed_vars[j] ) - z += alpha[k++] * x[i] * x[j]; - - return z; + + k += _nfree; + + for ( i = 0 ; i < nm1 ; ++i ) + if ( !_fixed_vars[i] ) + for ( j = i+1 ; j < _n ; ++j ) + if ( !_fixed_vars[j] ) + z += alpha[k++] * x[i] * x[j]; + + return z; } @@ -1632,60 +1669,60 @@ NOMAD::Double NOMAD::Quad_Model::eval ( const NOMAD::Point & x , /* compute model h and f values at a point */ /*----------------------------------------------------------------*/ void NOMAD::Quad_Model::eval_hf ( const NOMAD::Point & x , - const NOMAD::Double & h_min , - NOMAD::hnorm_type h_norm , - NOMAD::Double & h , - NOMAD::Double & f ) const + const NOMAD::Double & h_min , + NOMAD::hnorm_type h_norm , + NOMAD::Double & h , + NOMAD::Double & f ) const { - f.clear(); - h = 0.0; - - int m = static_cast<int>(_bbot.size()); - NOMAD::Double bboi; - - for ( int i = 0 ; i < m ; ++i ) { + f.clear(); + h = 0.0; - if ( _alpha[i] ) { - - bboi = eval ( x , *_alpha[i] ); - - if ( bboi.is_defined() ) { - - if ( _bbot[i] == NOMAD::EB || _bbot[i] == NOMAD::PEB_E ) { - - if ( bboi > h_min ) { - h.clear(); - return; - } - } - - else if ( ( _bbot[i] == NOMAD::FILTER || - _bbot[i] == NOMAD::PB || - _bbot[i] == NOMAD::PEB_P ) ) { - if ( bboi > h_min ) { - switch ( h_norm ) { - case NOMAD::L1: - h += bboi; - break; - case NOMAD::L2: - h += bboi * bboi; - break; - case NOMAD::LINF: - if ( bboi > h ) - h = bboi; - break; - } - } - } - - else if ( _bbot[i] == NOMAD::OBJ ) - f = bboi; - } - } - } - - if ( h_norm == NOMAD::L2 ) - h = h.sqrt(); + int m = static_cast<int>(_bbot.size()); + NOMAD::Double bboi; + + for ( int i = 0 ; i < m ; ++i ) { + + if ( _alpha[i] ) { + + bboi = eval ( x , *_alpha[i] ); + + if ( bboi.is_defined() ) { + + if ( _bbot[i] == NOMAD::EB || _bbot[i] == NOMAD::PEB_E ) { + + if ( bboi > h_min ) { + h.clear(); + return; + } + } + + else if ( ( _bbot[i] == NOMAD::FILTER || + _bbot[i] == NOMAD::PB || + _bbot[i] == NOMAD::PEB_P ) ) { + if ( bboi > h_min ) { + switch ( h_norm ) { + case NOMAD::L1: + h += bboi; + break; + case NOMAD::L2: + h += bboi * bboi; + break; + case NOMAD::LINF: + if ( bboi > h ) + h = bboi; + break; + } + } + } + + else if ( _bbot[i] == NOMAD::OBJ ) + f = bboi; + } + } + } + + if ( h_norm == NOMAD::L2 ) + h = h.sqrt(); } @@ -1697,29 +1734,29 @@ void NOMAD::Quad_Model::eval_hf ( const NOMAD::Point & x , /*-----------------------------------------------------*/ NOMAD::Double NOMAD::Quad_Model::compute_max_rel_err ( void ) const { - NOMAD::Double truth_value , model_value , rel_err , max_rel_err; - int k , nY = get_nY() , m = static_cast<int> ( _bbot.size() ); - - for ( int bbo_index = 0 ; bbo_index < m ; ++bbo_index ) { - if ( _alpha[bbo_index] ) { - for ( k = 0 ; k < nY ; ++k ) { - if ( _Y[k] && _Y[k]->get_eval_status() == NOMAD::EVAL_OK ) { - truth_value = _Y[k]->get_bb_outputs()[bbo_index]; - if ( truth_value.is_defined() ) { - model_value = eval ( *_Y[k] , *_alpha[bbo_index] ); - if ( model_value.is_defined() ) { - if ( truth_value.abs() != 0.0 ) { - rel_err = (truth_value-model_value).abs() / truth_value.abs(); - if ( !max_rel_err.is_defined() || rel_err > max_rel_err ) - max_rel_err = rel_err; - } - } - } - } - } - } - } - return max_rel_err; + NOMAD::Double truth_value , model_value , rel_err , max_rel_err; + int k , nY = get_nY() , m = static_cast<int> ( _bbot.size() ); + + for ( int bbo_index = 0 ; bbo_index < m ; ++bbo_index ) { + if ( _alpha[bbo_index] ) { + for ( k = 0 ; k < nY ; ++k ) { + if ( _Y[k] && _Y[k]->get_eval_status() == NOMAD::EVAL_OK ) { + truth_value = _Y[k]->get_bb_outputs()[bbo_index]; + if ( truth_value.is_defined() ) { + model_value = eval ( *_Y[k] , *_alpha[bbo_index] ); + if ( model_value.is_defined() ) { + if ( truth_value.abs() != 0.0 ) { + rel_err = (truth_value-model_value).abs() / truth_value.abs(); + if ( !max_rel_err.is_defined() || rel_err > max_rel_err ) + max_rel_err = rel_err; + } + } + } + } + } + } + } + return max_rel_err; } /*---------------------------------------------*/ @@ -1729,91 +1766,91 @@ NOMAD::Double NOMAD::Quad_Model::compute_max_rel_err ( void ) const /* (private) */ /*---------------------------------------------*/ void NOMAD::Quad_Model::compute_model_error ( int bbo_index , - NOMAD::Double & error , - NOMAD::Double & min_rel_err , - NOMAD::Double & max_rel_err , - NOMAD::Double & avg_rel_err ) const + NOMAD::Double & error , + NOMAD::Double & min_rel_err , + NOMAD::Double & max_rel_err , + NOMAD::Double & avg_rel_err ) const { - NOMAD::Double truth_value , model_value , rel_err; - int nY = get_nY() , cnt = 0; - bool chk = true; - - max_rel_err.clear(); - min_rel_err.clear(); - avg_rel_err = error = 0.0; - + NOMAD::Double truth_value , model_value , rel_err; + int nY = get_nY() , cnt = 0; + bool chk = true; + + max_rel_err.clear(); + min_rel_err.clear(); + avg_rel_err = error = 0.0; + #ifdef DEBUG - std::ostringstream msg; - msg << "output #" << bbo_index; - _out.open_block ( msg.str() ); + std::ostringstream msg; + msg << "output #" << bbo_index; + _out.open_block ( msg.str() ); #endif - - for ( int k = 0 ; k < nY ; ++k ) - if ( _Y[k] && _Y[k]->get_eval_status() == NOMAD::EVAL_OK ) - { - truth_value = _Y[k]->get_bb_outputs()[bbo_index]; - - if ( truth_value.is_defined() ) - { - model_value = eval ( *_Y[k] , *_alpha[bbo_index] ); - if ( model_value.is_defined() ) - { - rel_err.clear(); - if ( truth_value.abs() != 0.0 ) - rel_err = (truth_value-model_value).abs() / truth_value.abs(); - else - { - if (truth_value.abs()==model_value.abs()) - rel_err=0.0; - else - rel_err=NOMAD::INF; - } - if ( !max_rel_err.is_defined() || rel_err > max_rel_err ) - max_rel_err = rel_err; - if ( !min_rel_err.is_defined() || rel_err < min_rel_err ) - min_rel_err = rel_err; - avg_rel_err += rel_err; - ++cnt; - + + for ( int k = 0 ; k < nY ; ++k ) + if ( _Y[k] && _Y[k]->get_eval_status() == NOMAD::EVAL_OK ) + { + truth_value = _Y[k]->get_bb_outputs()[bbo_index]; + + if ( truth_value.is_defined() ) + { + model_value = eval ( *_Y[k] , *_alpha[bbo_index] ); + if ( model_value.is_defined() ) + { + rel_err.clear(); + if ( truth_value.abs() != 0.0 ) + rel_err = (truth_value-model_value).abs() / truth_value.abs(); + else + { + if (truth_value.abs()==model_value.abs()) + rel_err=0.0; + else + rel_err=NOMAD::INF; + } + if ( !max_rel_err.is_defined() || rel_err > max_rel_err ) + max_rel_err = rel_err; + if ( !min_rel_err.is_defined() || rel_err < min_rel_err ) + min_rel_err = rel_err; + avg_rel_err += rel_err; + ++cnt; + #ifdef DEBUG - _out << "Y[" << k << "]= ( "; - _Y[k]->NOMAD::Point::display ( _out ); - _out << " )" << " f=" << truth_value - << " m=" << model_value << " error^2=" - << ( model_value - truth_value ).pow2() - << " rel_err=" << rel_err - << std::endl; + _out << "Y[" << k << "]= ( "; + _Y[k]->NOMAD::Point::display ( _out ); + _out << " )" << " f=" << truth_value + << " m=" << model_value << " error^2=" + << ( model_value - truth_value ).pow2() + << " rel_err=" << rel_err + << std::endl; #endif - error += ( model_value - truth_value ).pow2(); - } - else - { - chk = false; - break; - } - } - else - { - chk = false; - break; - } - } - + error += ( model_value - truth_value ).pow2(); + } + else + { + chk = false; + break; + } + } + else + { + chk = false; + break; + } + } + #ifdef DEBUG - _out.close_block(); + _out.close_block(); #endif - - if ( chk) + + if ( chk) { // Case where chk is true (at least one model_value and the corresponding thruth value were defined => cnt != 0) - error = error.sqrt(); - avg_rel_err = avg_rel_err / cnt; + error = error.sqrt(); + avg_rel_err = avg_rel_err / cnt; } - else + else { - error.clear(); - min_rel_err.clear(); - max_rel_err.clear(); - avg_rel_err.clear(); + error.clear(); + min_rel_err.clear(); + max_rel_err.clear(); + avg_rel_err.clear(); } } @@ -1822,54 +1859,54 @@ void NOMAD::Quad_Model::compute_model_error ( int bbo_index , /*-----------------------------------------------------------*/ void NOMAD::Quad_Model::display_model_coeffs ( const NOMAD::Display & out ) const { - if ( _error_flag ) { - out << "model coefficients: could not be constructed" << std::endl; - return; - } - - int m = static_cast<int> ( _bbot.size() ); - - out << NOMAD::open_block ( "model coefficients" ); - for ( int i = 0 ; i < m ; ++i ) { - out << "output #"; - out.display_int_w ( i , m ); - out << ": "; - if ( _alpha[i] ) { - out<< "[ "; - _alpha[i]->display ( out , " " , 6 ); - out << " ]"; + if ( _error_flag ) { + out << "model coefficients: could not be constructed" << std::endl; + return; } - else - out << "NULL"; - out << std::endl; - } - out.close_block(); + + int m = static_cast<int> ( _bbot.size() ); + + out << NOMAD::open_block ( "model coefficients" ); + for ( int i = 0 ; i < m ; ++i ) { + out << "output #"; + out.display_int_w ( i , m ); + out << ": "; + if ( _alpha[i] ) { + out<< "[ "; + _alpha[i]->display ( out , " " , 6 ); + out << " ]"; + } + else + out << "NULL"; + out << std::endl; + } + out.close_block(); } /*-----------------------------------------------------------*/ /* display the interpolation set Y */ /*-----------------------------------------------------------*/ void NOMAD::Quad_Model::display_Y ( const NOMAD::Display & out , - const std::string & title ) const + const std::string & title ) const { - out << NOMAD::open_block ( title ); - int nY = get_nY(); - for ( int k = 0 ; k < nY ; ++k ) { - out << "#"; - out.display_int_w ( k , nY ); - out << ": "; - if ( _Y[k] ) { - out << "( "; - _Y[k]->NOMAD::Point::display ( out , " " , 12 ); - out << " ) bbo=[ "; - _Y[k]->get_bb_outputs().display ( out , " " , 12 ); - out << " ]"; + out << NOMAD::open_block ( title ); + int nY = get_nY(); + for ( int k = 0 ; k < nY ; ++k ) { + out << "#"; + out.display_int_w ( k , nY ); + out << ": "; + if ( _Y[k] ) { + out << "( "; + _Y[k]->NOMAD::Point::display ( out , " " , 12 ); + out << " ) bbo=[ "; + _Y[k]->get_bb_outputs().display ( out , " " , 12 ); + out << " ]"; + } + else + out << "NULL"; + out << std::endl; } - else - out << "NULL"; - out << std::endl; - } - out.close_block(); + out.close_block(); } /*-------------------------------------------------------*/ @@ -1877,86 +1914,81 @@ void NOMAD::Quad_Model::display_Y ( const NOMAD::Display & out , /*-------------------------------------------------------*/ void NOMAD::Quad_Model::display_Y_error ( const NOMAD::Display & out ) const { - if ( _error_flag ) - { - out << "model error on the interpolation set: cannot be computed" - << std::endl; - return; - } - - int i ; - int index = -1; - int m = static_cast<int> ( _bbot.size() ); - - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) - { - if ( index >= 0 ) - { - index = -1; - break; - } - else - index = i; - } - - NOMAD::Double error , min_rel_err , max_rel_err , avg_rel_err; - - // only one output: - if ( index >= 0 ) - { - compute_model_error ( index , error , min_rel_err , max_rel_err , avg_rel_err ); - out << "model errors on the interpolation set: error=" - << error << " min_rel_err=" << min_rel_err - << " max_rel_err=" << max_rel_err << " avg_rel_err=" << avg_rel_err - << std::endl; - } - - // several outputs: - else { - - out.open_block ( "model error on the interpolation set" ); - - NOMAD::Double error_i , min_rel_err_i , max_rel_err_i , avg_rel_err_i; - - error = avg_rel_err = 0.0; - min_rel_err.clear(); - max_rel_err.clear(); - - int cnt = 0; - - for ( i = 0 ; i < m ; ++i ) - if ( _alpha[i] ) - { - - ++cnt; - - compute_model_error ( i , - error_i , - min_rel_err_i , - max_rel_err_i , - avg_rel_err_i ); - - if (error_i.is_defined()) - error += error_i; - if (avg_rel_err_i.is_defined()) - avg_rel_err += avg_rel_err_i; - if ( !min_rel_err.is_defined() || min_rel_err_i < min_rel_err ) - min_rel_err = min_rel_err_i; - if ( !max_rel_err.is_defined() || max_rel_err_i > max_rel_err ) - max_rel_err = max_rel_err_i; - - out << "output #" << i << ": error=" << error_i - << " min_rel_err=" << min_rel_err_i << " max_rel_err=" - << max_rel_err_i << " avg_rel_err=" << avg_rel_err_i << std::endl; - } - - out << std::endl << "global: error=" << error - << " min_rel_err=" << min_rel_err - << " max_rel_err=" << max_rel_err - << " avg_rel_err=" << avg_rel_err / cnt - << std::endl << NOMAD::close_block(); - } + if ( _error_flag ) { + out << "model error on the interpolation set: cannot be computed" + << std::endl; + return; + } + + int i ; + int index = -1; + int m = static_cast<int> ( _bbot.size() ); + + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) { + if ( index >= 0 ) { + index = -1; + break; + } + else + index = i; + } + + NOMAD::Double error , min_rel_err , max_rel_err , avg_rel_err; + + // only one output: + if ( index >= 0 ) { + compute_model_error ( index , error , min_rel_err , max_rel_err , avg_rel_err ); + out << "model errors on the interpolation set: error=" + << error << " min_rel_err=" << min_rel_err + << " max_rel_err=" << max_rel_err << " avg_rel_err=" << avg_rel_err + << std::endl; + } + + // several outputs: + else { + + out.open_block ( "model error on the interpolation set" ); + + NOMAD::Double error_i , min_rel_err_i , max_rel_err_i , avg_rel_err_i; + + error = avg_rel_err = 0.0; + min_rel_err.clear(); + max_rel_err.clear(); + + int cnt = 0; + + for ( i = 0 ; i < m ; ++i ) + if ( _alpha[i] ) { + + ++cnt; + + compute_model_error ( i , + error_i , + min_rel_err_i , + max_rel_err_i , + avg_rel_err_i ); + + if (error_i.is_defined()) + error += error_i; + if (avg_rel_err_i.is_defined()) + avg_rel_err += avg_rel_err_i; + if ( !min_rel_err.is_defined() || min_rel_err_i < min_rel_err ) + min_rel_err = min_rel_err_i; + if ( !max_rel_err.is_defined() || max_rel_err_i > max_rel_err ) + max_rel_err = max_rel_err_i; + + out << "output #" << i << ": error=" << error_i + << " min_rel_err=" << min_rel_err_i << " max_rel_err=" + << max_rel_err_i << " avg_rel_err=" << avg_rel_err_i << std::endl; + } + + out << std::endl << "global: error=" << error + << " min_rel_err=" << min_rel_err + << " max_rel_err=" << max_rel_err + << " avg_rel_err=" << avg_rel_err / cnt + << std::endl << NOMAD::close_block(); + } } /*-----------------------------------------------*/ @@ -1964,57 +1996,57 @@ void NOMAD::Quad_Model::display_Y_error ( const NOMAD::Display & out ) const /*-----------------------------------------------*/ void NOMAD::Quad_Model::display_lagrange_polynomials ( const std::vector<NOMAD::Point *> & l , - const std::vector<NOMAD::Eval_Point *> & Y ) const + const std::vector<NOMAD::Eval_Point *> & Y ) const { - int i , j , nY = static_cast<int> ( Y.size() ); - - // display Lagrange polynomials: - _out << std::endl << NOMAD::open_block ( "Lagrange polynomials" ); - for ( i = 0 ; i < _n_alpha ; ++i ) { - _out << "l["; - _out.display_int_w ( i , _n_alpha ); - _out << "] = [ "; - l[i]->NOMAD::Point::display ( _out , " " , 14 , -1 ); - _out << "]" << std::endl; - } - _out.close_block(); - - // display current set Y: - _out << std::endl << NOMAD::open_block ( "current set Y" ); - for ( i = 0 ; i < nY ; ++i ) { - _out << "Y["; - _out.display_int_w ( i , nY ); - _out << "] = "; - if ( Y[i] ) { - _out << "( "; - Y[i]->NOMAD::Point::display ( _out , " " , 6 , -1 ); - _out << " )"; + int i , j , nY = static_cast<int> ( Y.size() ); + + // display Lagrange polynomials: + _out << std::endl << NOMAD::open_block ( "Lagrange polynomials" ); + for ( i = 0 ; i < _n_alpha ; ++i ) { + _out << "l["; + _out.display_int_w ( i , _n_alpha ); + _out << "] = [ "; + l[i]->NOMAD::Point::display ( _out , " " , 14 , -1 ); + _out << "]" << std::endl; } - else - _out << "NULL"; - _out << std::endl; + _out.close_block(); + + // display current set Y: + _out << std::endl << NOMAD::open_block ( "current set Y" ); + for ( i = 0 ; i < nY ; ++i ) { + _out << "Y["; + _out.display_int_w ( i , nY ); + _out << "] = "; + if ( Y[i] ) { + _out << "( "; + Y[i]->NOMAD::Point::display ( _out , " " , 6 , -1 ); + _out << " )"; + } + else + _out << "NULL"; + _out << std::endl; } - - _out.close_block(); - - // display l(Y): should be the identity matrix: - NOMAD::Double tmp , err = 0.0; - _out << std::endl << NOMAD::open_block ( "l(Y)" ); - for ( i = 0 ; i < _n_alpha ; ++i ) { - _out << "l["; - _out.display_int_w ( i , _n_alpha ); - _out << "]: "; - for ( j = 0 ; j < _n_alpha ; ++j ) { - tmp.clear(); - if ( j < nY && Y[j] ) { - tmp = eval ( *Y[j] , *l[i] ); - err += (i==j) ? (tmp-1.0).abs() : tmp.abs(); - } - tmp.display ( _out , "%6.3f" ); - _out << " "; + + _out.close_block(); + + // display l(Y): should be the identity matrix: + NOMAD::Double tmp , err = 0.0; + _out << std::endl << NOMAD::open_block ( "l(Y)" ); + for ( i = 0 ; i < _n_alpha ; ++i ) { + _out << "l["; + _out.display_int_w ( i , _n_alpha ); + _out << "]: "; + for ( j = 0 ; j < _n_alpha ; ++j ) { + tmp.clear(); + if ( j < nY && Y[j] ) { + tmp = eval ( *Y[j] , *l[i] ); + err += (i==j) ? (tmp-1.0).abs() : tmp.abs(); + } + tmp.display ( _out , "%6.3f" ); + _out << " "; + } + _out << std::endl; } - _out << std::endl; - } - _out << std::endl << "error (with identity) = " - << err << std::endl << NOMAD::close_block() << std::endl; + _out << std::endl << "error (with identity) = " + << err << std::endl << NOMAD::close_block() << std::endl; } diff --git a/src/Quad_Model.hpp b/src/Quad_Model.hpp index 9197ea5cd0667f39e917a5fb427815b21b1d8d5b..b9320c7014bf04cd405894fd942ba57177b67c36 100644 --- a/src/Quad_Model.hpp +++ b/src/Quad_Model.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -387,7 +387,7 @@ namespace NOMAD { */ void define_scaling ( const NOMAD::Double & r ); - /// Define scaling based on directions. See paper: Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2012 + /// Define scaling based on directions. See paper: Reducing the number of function evaluations in Mesh Adaptive Direct Search algorithms, Audet, Ianni, LeDigabel, Tribes, 2014 /** - Looks also for fixed variables. \param dirP The \c dirP parameter corresponds to set of directions formin a hyper-cube centered on poll center -- \b IN. diff --git a/src/Quad_Model_Evaluator.cpp b/src/Quad_Model_Evaluator.cpp index 717ad9ecffc1da4a66e22579b5cf703fcc0d51e4..7a6d9f804eba12fd970afae49d669583dc64d403 100644 --- a/src/Quad_Model_Evaluator.cpp +++ b/src/Quad_Model_Evaluator.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version (3.5.1).7.2 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -49,12 +49,12 @@ NOMAD::Quad_Model_Evaluator::Quad_Model_Evaluator ( const NOMAD::Parameters & p , const NOMAD::Quad_Model & model ) : - _n ( model.get_n() ) , - _nm1 ( _n-1 ) , - _m ( p.get_bb_nb_outputs() ) , - _x ( NULL ) , - _alpha ( NULL ) , - _model_ready ( model.check() ) + _n ( model.get_n() ) , + _nm1 ( _n-1 ) , + _m ( p.get_bb_nb_outputs() ) , + _x ( NULL ) , + _alpha ( NULL ) , + _model_ready ( model.check() ) { if ( _model_ready ) { @@ -116,7 +116,8 @@ NOMAD::Quad_Model_Evaluator::Quad_Model_Evaluator /*-----------------------------*/ NOMAD::Quad_Model_Evaluator::~Quad_Model_Evaluator ( void ) { - if ( _model_ready ) { + if ( _model_ready ) + { for ( int i = 0 ; i < _m ; ++i ) if ( _alpha[i] ) delete [] _alpha[i]; @@ -148,11 +149,13 @@ bool NOMAD::Quad_Model_Evaluator::eval_x for ( i = 0 ; i < _n ; ++i ) _x[i] = x[i].value() / 1000.0; - for ( int oi = 0 ; oi < _m ; ++oi ) { + for ( int oi = 0 ; oi < _m ; ++oi ) + { alpha = _alpha[oi]; - if ( alpha ) { + if ( alpha ) + { z = alpha[0]; p = _x; diff --git a/src/Quad_Model_Evaluator.hpp b/src/Quad_Model_Evaluator.hpp index b0d2f2273360c4e6b3231add1692be28ae6a3784..f3780a5e8db66d689ab42d2ed19212aec3757c89 100644 --- a/src/Quad_Model_Evaluator.hpp +++ b/src/Quad_Model_Evaluator.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Quad_Model_Evaluator.hpp - \brief NOMAD::Evaluator subclass for quadratic model optimization (headers) - \author Sebastien Le Digabel - \date 2010-08-31 - \see Quad_Model_Evaluator.cpp -*/ + \file Quad_Model_Evaluator.hpp + \brief NOMAD::Evaluator subclass for quadratic model optimization (headers) + \author Sebastien Le Digabel + \date 2010-08-31 + \see Quad_Model_Evaluator.cpp + */ #ifndef __QUAD_MODEL_EVALUATOR__ #define __QUAD_MODEL_EVALUATOR__ @@ -47,60 +47,82 @@ namespace NOMAD { - - /// NOMAD::Evaluator subclass for quadratic model optimization. - class Quad_Model_Evaluator { - - private: - - int _n; ///< Number of variables. - int _nm1; ///< Number of variables minus one. - int _m; ///< Number of blackbox outputs. - double * _x; ///< An evaluation point. - double ** _alpha; ///< Model parameters. - bool _model_ready; ///< \c true if model ready to evaluate. - - public: - - /// Constructor. - /** - \param p Parameters -- \b IN. - \param model Model -- \b IN. - */ - Quad_Model_Evaluator ( const NOMAD::Parameters & p , - const NOMAD::Quad_Model & model ); - - /// Destructor. - virtual ~Quad_Model_Evaluator ( void ); - - /// Evaluate the blackboxes at a given trial point. - /** - \param x The trial point -- \b IN/OUT. - \param h_max Maximal feasibility value \c h_max -- \b IN. - \param count_eval Flag indicating if the evaluation has to be counted - or not -- \b OUT. - \return A boolean equal to \c false if the evaluation failed. - */ - virtual bool eval_x ( NOMAD::Eval_Point & x , - const NOMAD::Double & h_max , - bool & count_eval ) const; - - /// Evaluate the gradient of a blackboxe at a given trial point. - /** - \param x The trial point -- \b IN/OUT. - \param g The gradient of a bb model at the trial point \c x -- \b OUT. - \param output_index The index of the black box. -- \b IN. - \param count_eval Flag indicating if the evaluation has to be counted - or not -- \b OUT. - \return A boolean equal to \c false if the evaluation failed. - */ - - virtual bool evalGrad_x (const NOMAD::Point & x , - NOMAD::Point & g , - const int & output_index , - bool & count_eval ) const; - - }; + + /// NOMAD::Evaluator subclass for quadratic model optimization. + class Quad_Model_Evaluator { + + private: + + int _n; ///< Number of variables. + int _nm1; ///< Number of variables minus one. + int _m; ///< Number of blackbox outputs. + double * _x; ///< An evaluation point. + double ** _alpha; ///< Model parameters. + bool _model_ready; ///< \c true if model ready to evaluate. + + public: + + /// Constructor. + /** + \param p Parameters -- \b IN. + \param model Model -- \b IN. + */ + Quad_Model_Evaluator ( const NOMAD::Parameters & p , + const NOMAD::Quad_Model & model ); + + /// Destructor. + virtual ~Quad_Model_Evaluator ( void ); + + /// Evaluate the blackboxes at a given trial point. + /** + \param x The trial point -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) const; + + /// Evaluate the blackbox functions at a given trial point (#2). + /** + - Non-const version. + - Calls the const version by default. + - May be user-defined. + - Surrogate or true evaluation depending on the value of \c x.is_surrogate(). + \param x The trial point -- \b IN/OUT. + \param h_max Maximal feasibility value \c h_max -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + virtual bool eval_x ( NOMAD::Eval_Point & x , + const NOMAD::Double & h_max , + bool & count_eval ) + { + return static_cast<const NOMAD::Quad_Model_Evaluator *>(this)->eval_x ( x , h_max, count_eval ); + } + + + + + /// Evaluate the gradient of a blackboxe at a given trial point. + /** + \param x The trial point -- \b IN/OUT. + \param g The gradient of a bb model at the trial point \c x -- \b OUT. + \param output_index The index of the black box. -- \b IN. + \param count_eval Flag indicating if the evaluation has to be counted + or not -- \b OUT. + \return A boolean equal to \c false if the evaluation failed. + */ + + virtual bool evalGrad_x (const NOMAD::Point & x , + NOMAD::Point & g , + const int & output_index , + bool & count_eval ) const; + + }; } #endif diff --git a/src/Quad_Model_Search.cpp b/src/Quad_Model_Search.cpp index 5219d1d7abb37df70b7001d9a1710192f187b289..ef61c01f882c22f8a15bd2213f0c6a8fed1e2d83 100644 --- a/src/Quad_Model_Search.cpp +++ b/src/Quad_Model_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -92,412 +92,426 @@ /* */ /*----------------------------------------------------------------*/ void NOMAD::Quad_Model_Search::search ( NOMAD::Mads & mads , - int & nb_search_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - bool & count_search , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_search_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + bool & count_search , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - new_feas_inc = new_infeas_inc = NULL; - nb_search_pts = 0; - success = NOMAD::UNSUCCESSFUL; - count_search = false; - - _one_search_stats.reset(); - - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - - if ( stop ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "Quad_Model_Search::search(): not performed (stop flag is active)" - << std::endl; - return; - } - - // black-box output types: - const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); - const std::list<int> & index_obj_list = _p.get_index_obj(); - - if ( index_obj_list.empty() ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "Quad_Model_Search::search(): not performed with no objective function" - << std::endl; - return; - } - - - // initial displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << NOMAD::MODEL_SEARCH << " #" - << _all_searches_stats.get_MS_nb_searches(); - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - // surrogate or truth model evaluations: - NOMAD::eval_type ev_type = + new_feas_inc = new_infeas_inc = NULL; + nb_search_pts = 0; + success = NOMAD::UNSUCCESSFUL; + count_search = false; + + _one_search_stats.reset(); + + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + + if ( stop ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "Quad_Model_Search::search(): not performed (stop flag is active)" + << std::endl; + return; + } + + // black-box output types: + const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type(); + const std::list<int> & index_obj_list = _p.get_index_obj(); + + if ( index_obj_list.empty() ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "Quad_Model_Search::search(): not performed with no objective function" + << std::endl; + return; + } + + + // initial displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << NOMAD::MODEL_SEARCH << " #" + << _all_searches_stats.get_MS_nb_searches(); + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + // surrogate or truth model evaluations: + NOMAD::eval_type ev_type = ( _p.get_opt_only_sgte() ) ? NOMAD::SGTE : NOMAD::TRUTH; - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "model construction for " << ev_type << std::endl; - - // active cache: - const NOMAD::Cache & cache = mads.get_cache(); - - // active barrier: - const NOMAD::Barrier & barrier = + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "model construction for " << ev_type << std::endl; + + // active cache: + const NOMAD::Cache & cache = mads.get_cache(); + + // active barrier: + const NOMAD::Barrier & barrier = ( ev_type == NOMAD::SGTE ) ? mads.get_sgte_barrier() : mads.get_true_barrier(); - - // current incumbents: xk[0]=best_feas and xk[1]=best_infeas: - const NOMAD::Eval_Point * xk[2]; - xk[0] = barrier.get_best_feasible (); - xk[1] = barrier.get_best_infeasible(); - - if ( !xk[0] && !xk[1] ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH << " (no incumbent)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - return; - } - - // from this point the search is counted: - count_search = true; - _one_search_stats.add_MS_nb_searches(); - - // display the number of cache points: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << "number of points in cache: " - << cache.size() << std::endl; - - // stats: - NOMAD::Stats & stats = mads.get_stats(); - - // current mesh index: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - - // number of interpolation points: - int nY[2]; - nY[0] = nY[1] = -1; - - int min_Y_size = _p.get_model_quad_min_Y_size(); - int max_Y_size = _p.get_model_quad_max_Y_size(); - - // use or not well-poisedness: - bool use_WP = _p.get_model_quad_use_WP(); - - // flag to detect model errors: - bool model_ok = false; - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // main loop on the two incumbents (feasible and infeasible): - // --------- - for ( int i_inc = 0 ; i_inc < 2 ; ++i_inc ) - { - - if ( xk[i_inc] ) - { - - // display the model center: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << std::endl << "model center"; - if ( xk[0] && xk[1] ) - out << " (" << i_inc+1 << "/2)"; - out << ": " << *xk[i_inc] << std::endl; - } - - // get and check the signature: - NOMAD::Signature * signature = xk[i_inc]->get_signature(); - if ( !signature ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH << " (no signature)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - stats.update_model_stats ( _one_search_stats ); - _all_searches_stats.update ( _one_search_stats ); - return; - } - - int n = signature->get_n(); - if ( n != xk[i_inc]->size() ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH << " (incompatible signature)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - stats.update_model_stats ( _one_search_stats ); - _all_searches_stats.update ( _one_search_stats ); - return; - } - - // compute the interpolation radius: points in Y must be at - // a max distance of ms_radius_factor times Delta^p_k: - NOMAD::Point delta_p , delta_m; - signature->get_mesh().get_delta_p ( delta_p , mesh_index ); - signature->get_mesh().get_delta_m ( delta_m , mesh_index ); - - NOMAD::Point interpolation_radius = delta_p; - interpolation_radius *= _p.get_model_quad_radius_factor(); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "mesh index : " << mesh_index << std::endl - << "mesh size parameter : ( " << delta_m << " )" << std::endl - << "poll size parameter : ( " << delta_p << " )" << std::endl - << "interpolation radius : ( " << interpolation_radius - << " )" << std::endl; - - // creation of the model: - NOMAD::Quad_Model model ( out , bbot , cache , *signature ); - NOMAD::Clock clock; - - // construct interpolation set Y: - // ------------------------------ - model.construct_Y ( *xk[i_inc] , - interpolation_radius , - max_Y_size ); - - nY[i_inc] = model.get_nY(); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - out << "number of points in Y: " << nY[i_inc] - << " (p=" << nY[i_inc]-1; - if ( nY[i_inc] < 2 ) - out << ", not enough"; - out << ")" << std::endl; - } - - if ( nY[i_inc] < 2 ) - _one_search_stats.add_not_enough_pts(); - else - { - + + // current incumbents: xk[0]=best_feas and xk[1]=best_infeas: + const NOMAD::Eval_Point * xk[2]; + xk[0] = barrier.get_best_feasible (); + xk[1] = barrier.get_best_infeasible(); + + if ( !xk[0] && !xk[1] ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH << " (no incumbent)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + return; + } + + // from this point the search is counted: + count_search = true; + _one_search_stats.add_MS_nb_searches(); + + // display the number of cache points: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << "number of points in cache: " + << cache.size() << std::endl; + + // stats: + NOMAD::Stats & stats = mads.get_stats(); + + // number of interpolation points: + int nY[2]; + nY[0] = nY[1] = -1; + + int min_Y_size = _p.get_model_quad_min_Y_size(); + int max_Y_size = _p.get_model_quad_max_Y_size(); + + // use or not well-poisedness: + bool use_WP = _p.get_model_quad_use_WP(); + + // flag to detect model errors: + bool model_ok = false; + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // main loop on the two incumbents (feasible and infeasible): + // --------- + for ( int i_inc = 0 ; i_inc < 2 ; ++i_inc ) + { + + if ( xk[i_inc] ) + { + + // display the model center: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << std::endl << "model center"; + if ( xk[0] && xk[1] ) + out << " (" << i_inc+1 << "/2)"; + out << ": " << *xk[i_inc] << std::endl; + } + + // get and check the signature: + NOMAD::Signature * signature = xk[i_inc]->get_signature(); + if ( !signature ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH << " (no signature)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + stats.update_model_stats ( _one_search_stats ); + _all_searches_stats.update ( _one_search_stats ); + return; + } + + // current mesh index: + NOMAD::Point mesh_indices = signature->get_mesh()->get_mesh_indices(); + + + int n = signature->get_n(); + if ( n != xk[i_inc]->size() ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH << " (incompatible signature)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + stats.update_model_stats ( _one_search_stats ); + _all_searches_stats.update ( _one_search_stats ); + return; + } + + // compute the interpolation radius: points in Y must be at + // a max distance of ms_radius_factor times Delta^k: + NOMAD::Point Delta , delta; + signature->get_mesh()->get_Delta ( Delta ); + signature->get_mesh()->get_delta ( delta ); + + + NOMAD::Point interpolation_radius = Delta; + interpolation_radius *= _p.get_model_quad_radius_factor(); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "mesh indices : (" << mesh_indices << ")" << std::endl + << "mesh size parameter : ( " << delta << " )" << std::endl + << "poll size parameter : ( " << Delta << " )" << std::endl + << "interpolation radius : ( " << interpolation_radius + << " )" << std::endl; + + // creation of the model: + NOMAD::Quad_Model model ( out , bbot , cache , *signature ); + + + + NOMAD::Clock clock; + + // construct interpolation set Y: + // ------------------------------ + model.construct_Y ( *xk[i_inc] , + interpolation_radius , + max_Y_size ); + + nY[i_inc] = model.get_nY(); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << "number of points in Y: " << nY[i_inc] + << " (p=" << nY[i_inc]-1; + if ( nY[i_inc] < 2 ) + out << ", not enough"; + out << ")" << std::endl; + } + + if ( nY[i_inc] < 2 ) + _one_search_stats.add_not_enough_pts(); + else + { + #ifdef DEBUG - out << std::endl; - model.display_Y ( out , "unscaled interpolation set Y" ); + out << std::endl; + model.display_Y ( out , "unscaled interpolation set Y" ); #endif - - // define scaling: - // --------------- - // The min box around the interpolation set Y - // is scaled to [-r;r] with r=MODEL_RADIUS_FACTOR. - model.define_scaling ( _p.get_model_quad_radius_factor() ); - + + // define scaling: + // --------------- + // The min box around the interpolation set Y + // is scaled to [-r;r] with r=MODEL_RADIUS_FACTOR. + model.define_scaling ( _p.get_model_quad_radius_factor() ); + #ifdef DEBUG - out << std::endl; - model.display_Y ( out , "scaled interpolation set Ys" ); + out << std::endl; + model.display_Y ( out , "scaled interpolation set Ys" ); #endif - - // error check: - if ( model.get_error_flag() ) - _one_search_stats.add_construction_error(); - - // not enough points (this is not counted as an error): - else if ( nY[i_inc] < 2 || - ( min_Y_size < 0 && nY[i_inc] <= model.get_nfree() ) ) - _one_search_stats.add_not_enough_pts(); - - // no error and enough points in Y: - else - { - - // construct model: - // ---------------- - model.construct ( use_WP , NOMAD::SVD_EPS , NOMAD::SVD_MAX_MPN , max_Y_size ); - _one_search_stats.add_construction_time ( clock.get_CPU_time() ); - _one_search_stats.update_nY ( model.get_nY() ); - - // display model characteristics: + + // error check: + if ( model.get_error_flag() ) + _one_search_stats.add_construction_error(); + + // not enough points (this is not counted as an error): + else if ( nY[i_inc] < 2 || + ( min_Y_size < 0 && nY[i_inc] <= model.get_nfree() ) ) + _one_search_stats.add_not_enough_pts(); + + // no error and enough points in Y: + else + { + + // construct model: + // ---------------- + model.construct ( use_WP , NOMAD::SVD_EPS , NOMAD::SVD_MAX_MPN , max_Y_size ); + _one_search_stats.add_construction_time ( clock.get_CPU_time() ); + _one_search_stats.update_nY ( model.get_nY() ); + + // display model characteristics: #ifdef DEBUG - out << std::endl; - model.display_model_coeffs ( out ); - out << std::endl; - model.display_Y_error ( out ); -#endif - // count model: - if ( ev_type == NOMAD::TRUTH ) - _one_search_stats.add_nb_truth(); - else - _one_search_stats.add_nb_sgte(); - - switch ( model.get_interpolation_type() ) - { - case NOMAD::MFN: - _one_search_stats.add_nb_MFN(); - break; - case NOMAD::WP_REGRESSION: - _one_search_stats.add_nb_WP_regression(); - break; - case NOMAD::REGRESSION: - _one_search_stats.add_nb_regression(); - break; - default: - break; - } - - // check model error flag: - const NOMAD::Double & cond = model.get_cond(); - if ( model.get_error_flag() || - !cond.is_defined() || - cond > NOMAD::SVD_MAX_COND ) - { - if ( model.get_error_flag() ) - _one_search_stats.add_construction_error(); - else - _one_search_stats.add_bad_cond(); - } - else - { - - model_ok = true; - - // optimize model: - // --------------- - NOMAD::Point xf , xi; - - clock.reset(); - - bool optimization_ok = optimize_model ( model , - xk , - i_inc , - display_degree , - out , - xf , - xi , - stop , - stop_reason ); - - _one_search_stats.add_optimization_time ( clock.get_CPU_time() ); - - if ( optimization_ok ) - { - - // get solution(s), project to mesh (+round for integers), and create trial points: - // ---------------------------------------------------------- - if ( xf.is_defined() ) - create_trial_point ( ev_control , - xf , - model , - *signature , - mesh_index , - delta_m , - display_degree , - out ); - - if ( xi.is_defined() ) - create_trial_point ( ev_control , - xi , - model , - *signature , - mesh_index , - delta_m , - display_degree , - out ); - } - else - _one_search_stats.add_MS_opt_error(); - } - } - } - } - } // end of main loop - - // check the number of times that not enough points could be considered: - if ( nY[0] <= 1 && nY[1] <= 1 ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH - << " (not enough points)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - stats.update_model_stats ( _one_search_stats ); - _all_searches_stats.update ( _one_search_stats ); - return; - } - - // check if no model has been computed: - if ( !model_ok ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH - << " (model computation or optimization error)"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } - stats.update_model_stats ( _one_search_stats ); - _all_searches_stats.update ( _one_search_stats ); - return; - } - - nb_search_pts = ev_control.get_nb_eval_points(); - - // reduce the list of trial points from a maximum - // of 4 points to MODEL_SEARCH_MAX_TRIAL_PTS points: - int max_trial_pts = _p.get_model_search_max_trial_pts(); - if ( max_trial_pts > 4 ) - max_trial_pts = 4; - if ( nb_search_pts > max_trial_pts ) - { - ev_control.reduce_eval_lop ( max_trial_pts ); - nb_search_pts = ev_control.get_nb_eval_points(); - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - out << "the list of trial points is reduced to " - << nb_search_pts << " point"; - if ( nb_search_pts > 1 ) - out << "s"; - out << std::endl; - } - } - - _one_search_stats.update_MS_max_search_pts ( nb_search_pts ); - - // evaluate the trial points: - // -------------------------- - int bbe = stats.get_bb_eval(); - int sgte_eval = stats.get_sgte_eval (); - int cache_hits = stats.get_cache_hits(); - - new_feas_inc = new_infeas_inc = NULL; - - ev_control.disable_model_eval_sort(); - - ev_control.eval_list_of_points ( _type , - mads.get_true_barrier() , - mads.get_sgte_barrier() , - mads.get_pareto_front() , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - - ev_control.enable_model_eval_sort(); - - // update stats: - _one_search_stats.add_MS_bb_eval ( stats.get_bb_eval () - bbe ); - _one_search_stats.add_MS_sgte_eval ( stats.get_sgte_eval () - sgte_eval ); - _one_search_stats.add_MS_cache_hits ( stats.get_cache_hits() - cache_hits ); - - if ( success == NOMAD::FULL_SUCCESS ) - _one_search_stats.add_MS_success(); - - _one_search_stats.add_MS_pts ( nb_search_pts ); - - stats.update_model_stats ( _one_search_stats ); - _all_searches_stats.update ( _one_search_stats ); - - // final display: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of " << NOMAD::MODEL_SEARCH << " (" << success << ")"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } + out << std::endl; + model.display_model_coeffs ( out ); + out << std::endl; + model.display_Y_error ( out ); +#endif + // count model: + if ( ev_type == NOMAD::TRUTH ) + _one_search_stats.add_nb_truth(); + else + _one_search_stats.add_nb_sgte(); + + switch ( model.get_interpolation_type() ) + { + case NOMAD::MFN: + _one_search_stats.add_nb_MFN(); + break; + case NOMAD::WP_REGRESSION: + _one_search_stats.add_nb_WP_regression(); + break; + case NOMAD::REGRESSION: + _one_search_stats.add_nb_regression(); + break; + default: + break; + } + + // check model error flag: + const NOMAD::Double & cond = model.get_cond(); + if ( model.get_error_flag() || + !cond.is_defined() || + cond > NOMAD::SVD_MAX_COND ) + { + if ( model.get_error_flag() ) + _one_search_stats.add_construction_error(); + else + _one_search_stats.add_bad_cond(); + } + else + { + + model_ok = true; + + // optimize model: + // --------------- + NOMAD::Point xf , xi; + + clock.reset(); + + bool optimization_ok = optimize_model ( model , + xk , + i_inc , + display_degree , + out , + xf , + xi , + stop , + stop_reason ); + + _one_search_stats.add_optimization_time ( clock.get_CPU_time() ); + + if ( optimization_ok ) + { + + // get solution(s), project to mesh (+round for integers), and create trial points: + // ---------------------------------------------------------- + if ( xf.is_defined() ) + create_trial_point ( ev_control , + xf , + model , + *signature , + mesh_indices , + delta , + display_degree , + out ); + + if ( xi.is_defined() ) + create_trial_point ( ev_control , + xi , + model , + *signature , + mesh_indices , + delta , + display_degree , + out ); + } + else + _one_search_stats.add_MS_opt_error(); + } + } + } + } + } // end of main loop + + // check the number of times that not enough points could be considered: + if ( nY[0] <= 1 && nY[1] <= 1 ) { + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH + << " (not enough points)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + stats.update_model_stats ( _one_search_stats ); + _all_searches_stats.update ( _one_search_stats ); + return; + } + + // check if no model has been computed: + if ( !model_ok ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH + << " (model computation or optimization error)"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } + stats.update_model_stats ( _one_search_stats ); + _all_searches_stats.update ( _one_search_stats ); + return; + } + + nb_search_pts = ev_control.get_nb_eval_points(); + + // reduce the list of trial points from a maximum + // of 4 points to MODEL_SEARCH_MAX_TRIAL_PTS points: + int max_trial_pts = _p.get_model_search_max_trial_pts(); + if ( max_trial_pts > 4 ) + max_trial_pts = 4; + if ( nb_search_pts > max_trial_pts ) + { + ev_control.reduce_eval_lop ( max_trial_pts ); + nb_search_pts = ev_control.get_nb_eval_points(); + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << "the list of trial points is reduced to " + << nb_search_pts << " point"; + if ( nb_search_pts > 1 ) + out << "s"; + out << std::endl; + } + } + + _one_search_stats.update_MS_max_search_pts ( nb_search_pts ); + + // evaluate the trial points: + // -------------------------- + int bbe = stats.get_bb_eval(); + int sgte_eval = stats.get_sgte_eval (); + int cache_hits = stats.get_cache_hits(); + + new_feas_inc = new_infeas_inc = NULL; + + ev_control.disable_model_eval_sort(); + + ev_control.eval_list_of_points ( _type , + mads.get_true_barrier() , + mads.get_sgte_barrier() , + mads.get_pareto_front() , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + + ev_control.enable_model_eval_sort(); + + // update stats: + _one_search_stats.add_MS_bb_eval ( stats.get_bb_eval () - bbe ); + _one_search_stats.add_MS_sgte_eval ( stats.get_sgte_eval () - sgte_eval ); + _one_search_stats.add_MS_cache_hits ( stats.get_cache_hits() - cache_hits ); + + if ( success == NOMAD::FULL_SUCCESS ) + _one_search_stats.add_MS_success(); + + _one_search_stats.add_MS_pts ( nb_search_pts ); + + stats.update_model_stats ( _one_search_stats ); + _all_searches_stats.update ( _one_search_stats ); + + // final display: + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "end of " << NOMAD::MODEL_SEARCH << " (" << success << ")"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } } /*---------------------------------------------------------------*/ @@ -508,167 +522,168 @@ void NOMAD::Quad_Model_Search::create_trial_point NOMAD::Point x , const NOMAD::Quad_Model & model , NOMAD::Signature & signature , - int mesh_index , - const NOMAD::Point & delta_m , + const NOMAD::Point & mesh_indices , + const NOMAD::Point & delta , NOMAD::dd_type display_degree , const NOMAD::Display & out ) { - - bool proj_to_mesh = _p.get_model_search_proj_to_mesh(); - - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << "candidate"; - if ( proj_to_mesh ) - out << " (before projection)"; - out << ": ( " << x << " )" << std::endl; - } - - // model center: - NOMAD::Point center = model.get_center(); - - // model search point: - int n = x.size(); - - // projection to mesh: - if ( proj_to_mesh ) - { - x.project_to_mesh ( center , delta_m , _p.get_lb() , _p.get_ub() ); - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "candidate (after projection) : ( " - << x << " )" << std::endl; - } - - - // Round for integer and binary variables: - for (int i=0;i<n;i++) - { - if ( _p.get_bb_input_type()[i] == NOMAD::INTEGER ) - { - if ( x[i] >= 0.0 ) - x[i] = x[i].NOMAD::Double::ceil(); - else - x[i] = x[i].NOMAD::Double::floor(); - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "candidate (after rounding integer) : ( " - << x << " )" << std::endl; - } - // binary variables: - else if ( _p.get_bb_input_type()[i] == NOMAD::BINARY ) - { - if ( x[i]!= 0.0 ) - x[i] = 1.0; - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "candidate (after rounding binary) : ( " - << x << " )" << std::endl; - } - } - - - - // compare x and center: - if ( x == center ) - { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "candidate rejected (candidate==model center)" << std::endl; - return; - } - - - - NOMAD::Eval_Point * tk = new NOMAD::Eval_Point; - - // if the search is optimistic, a direction is computed (this - // will be used in case of success in the speculative search): - if ( _p.get_model_search_optimistic() ) - { - NOMAD::Direction dir ( n , 0.0 , NOMAD::MODEL_SEARCH_DIR ); - dir.Point::operator = ( x - center ); - tk->set_direction ( &dir ); - } - - tk->set ( n , _p.get_bb_nb_outputs() ); - tk->set_signature ( &signature ); - tk->set_mesh_index ( &mesh_index ); - - tk->Point::operator = ( x ); - - // compute model f and h in order to accept or reject the trial point: - - NOMAD::Double h0 , f0; // model values of f and h at the center - NOMAD::Double h1 , f1; // model values of f and h at the trial point - - const NOMAD::Double & h_min = _p.get_h_min(); - NOMAD::hnorm_type h_norm = _p.get_h_norm(); - - model.scale ( x ); - - model.eval_hf ( NOMAD::Point (n,0) , h_min , h_norm , h0 , f0 ); - model.eval_hf ( x , h_min , h_norm , h1 , f1 ); - - if ( display_degree == NOMAD::FULL_DISPLAY ) - { + + bool proj_to_mesh = _p.get_model_search_proj_to_mesh(); + + if ( display_degree == NOMAD::FULL_DISPLAY ) { + out << "candidate"; + if ( proj_to_mesh ) + out << " (before projection)"; + out << ": ( " << x << " )" << std::endl; + } + + // model center: + NOMAD::Point center = model.get_center(); + + // model search point: + int n = x.size(); + + // projection to mesh: + if ( proj_to_mesh ) + { + x.project_to_mesh ( center , delta , _p.get_lb() , _p.get_ub() ); + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "candidate (after projection) : ( " + << x << " )" << std::endl; + } + + + // Round for integer and binary variables: + bool has_integer=false; + bool has_binary=false; + for (int i=0;i<n;i++) + { + if ( _p.get_bb_input_type()[i] == NOMAD::INTEGER ) + { + has_integer=true; + if ( x[i] >= 0.0 ) + x[i] = x[i].NOMAD::Double::ceil(); + else + x[i] = x[i].NOMAD::Double::floor(); + } + // binary variables: + else if ( _p.get_bb_input_type()[i] == NOMAD::BINARY ) + { + has_binary=true; + if ( x[i]!= 0.0 ) + x[i] = 1.0; + } + } + if ( has_integer && display_degree == NOMAD::FULL_DISPLAY ) + out << "candidate (after rounding integer) : ( " + << x << " )" << std::endl; + + if ( has_binary && display_degree == NOMAD::FULL_DISPLAY ) + out << "candidate (after rounding binary) : ( " + << x << " )" << std::endl; + + + // compare x and center: + if ( x == center ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "candidate rejected (candidate==model center)" << std::endl; + return; + } + + + + NOMAD::Eval_Point * tk = new NOMAD::Eval_Point; + + // if the search is optimistic, a direction is computed (this + // will be used in case of success in the speculative search): + if ( _p.get_model_search_optimistic() ) + { + NOMAD::Direction dir ( n , 0.0 , NOMAD::MODEL_SEARCH_DIR ); + dir.Point::operator = ( x - center ); + tk->set_direction ( &dir ); + } + + tk->set ( n , _p.get_bb_nb_outputs() ); + tk->set_signature ( &signature ); + tk->Point::operator = ( x ); + + // compute model f and h in order to accept or reject the trial point: + NOMAD::Double h0 , f0; // model values of f and h at the center + NOMAD::Double h1 , f1; // model values of f and h at the trial point + + const NOMAD::Double & h_min = _p.get_h_min(); + NOMAD::hnorm_type h_norm = _p.get_h_norm(); + + model.scale ( x ); + + model.eval_hf ( NOMAD::Point (n,0) , h_min , h_norm , h0 , f0 ); + model.eval_hf ( x , h_min , h_norm , h1 , f1 ); + + if ( display_degree == NOMAD::FULL_DISPLAY ) + { #ifdef DEBUG - out << "model at center : h=" << h0 << " f=" << f0 << std::endl; + out << "model at center : h=" << h0 << " f=" << f0 << std::endl; #endif - out << "model at candidate: h=" << h1 << " f=" << f1 - << std::endl << std::endl; - } - - bool accept_point = true; - - if ( !f1.is_defined() || !h1.is_defined() ) - accept_point = false; - else - { - if ( !f0.is_defined() || !h0.is_defined() ) - accept_point = true; - else - accept_point = (f1 <= f0) || (h1 <= h0); - } - - // we check that the candidate does not correspond to another candidate: - if ( accept_point ) - { - const std::set<NOMAD::Priority_Eval_Point> & eval_lop - = ev_control.get_eval_lop(); - - std::set<NOMAD::Priority_Eval_Point>::const_iterator it , end = eval_lop.end(); - - for ( it = eval_lop.begin() ; it != end ; ++it ) - if ( it->get_point()->NOMAD::Point::operator == ( *tk ) ) - { - accept_point = false; - break; - } - } - - // add the new point to the list of search trial points: - if ( accept_point ) { - ev_control.add_eval_point ( tk , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - f1 , - h1 ); + out << "model at candidate: h=" << h1 << " f=" << f1 + << std::endl << std::endl; + } + + bool accept_point = true; + + if ( !f1.is_defined() || !h1.is_defined() ) + accept_point = false; + else + { + if ( !f0.is_defined() || !h0.is_defined() ) + accept_point = true; + else + accept_point = (f1 <= f0) || (h1 <= h0); + } + + // we check that the candidate does not correspond to another candidate: + if ( accept_point ) + { + const std::set<NOMAD::Priority_Eval_Point> & eval_lop + = ev_control.get_eval_lop(); + + std::set<NOMAD::Priority_Eval_Point>::const_iterator it , end = eval_lop.end(); + + for ( it = eval_lop.begin() ; it != end ; ++it ) + if ( it->get_point()->NOMAD::Point::operator == ( *tk ) ) + { + accept_point = false; + break; + } + } + + // add the new point to the list of search trial points: + if ( accept_point ) { + ev_control.add_eval_point ( tk , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + f1 , + h1 ); #ifdef MODEL_STATS - if ( tk ) { - tk->set_mod_use ( 1 ); // 1 for model search - tk->set_cond ( model.get_cond() ); - tk->set_Yw ( model.get_Yw () ); - tk->set_nY ( model.get_nY () ); - tk->set_mh ( h1 ); - tk->set_mf ( f1 ); - } + if ( tk ) { + tk->set_mod_use ( 1 ); // 1 for model search + tk->set_cond ( model.get_cond() ); + tk->set_Yw ( model.get_Yw () ); + tk->set_nY ( model.get_nY () ); + tk->set_mh ( h1 ); + tk->set_mf ( f1 ); + } #endif - - } - else { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "candidate rejected" << std::endl; - _one_search_stats.add_MS_rejected(); - delete tk; - } + + } + else { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "candidate rejected" << std::endl; + _one_search_stats.add_MS_rejected(); + delete tk; + } } /*---------------------------------------------------------------*/ @@ -690,302 +705,287 @@ bool NOMAD::Quad_Model_Search::optimize_model bool & stop , NOMAD::stop_type & stop_reason ) { - xf.clear(); - xi.clear(); - - int n = model.get_n(); - bool error = false; - std::string error_str; - int i; - - // initial displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "model optimization"; - if ( xk[0] && xk[1] ) - oss << " (" << i_inc+1 << "/2)"; - out << std::endl << NOMAD::open_block ( oss.str() ); - } - - // parameters creation: - NOMAD::Parameters model_param ( out ); - - // random seed: - model_param.set_SEED ( _p.get_seed() + 10*_all_searches_stats.get_MS_nb_searches() ); - - // number of variables: - model_param.set_DIMENSION ( n ); - - // blackbox outputs: - model_param.set_BB_OUTPUT_TYPE ( _p.get_bb_output_type() ); - - // blackbox inputs: - // Use defaults: all variables are treated as continuous (integer and binary. Categoricals disable models anyway). - - // barrier parameters: - model_param.set_H_MIN ( _p.get_h_min () ); - model_param.set_H_NORM ( _p.get_h_norm() ); - - // starting points: - { - // 1/2: point (0,...,0): - model_param.set_X0 ( NOMAD::Point ( n , 0.0 ) ); - - // 2/2: model center if different than (0,..,0) and if in [-1;1]: - NOMAD::Point x1 = model.get_center(); - - if ( x1.size() == n && x1.is_complete() ) { - - model.scale ( x1 ); - - bool diff = false; - bool bnd_ok = true; - - for ( i = 0 ; i < n ; ++i ) { - - if ( x1[i] != 0 ) - diff = true; - - if ( x1[i].abs() > 1.0 ) { - bnd_ok = false; - break; - } - - x1[i] *= 1000.0; - } - - if ( diff && bnd_ok ) - model_param.set_X0 ( x1 ); - } - } - - // fixed variables: - for ( i = 0 ; i < n ; ++i ) - if ( model.variable_is_fixed(i) || _p.variable_is_fixed(i) ) - model_param.set_FIXED_VARIABLE(i); - - // no model search and no model ordering: - model_param.set_MODEL_SEARCH ( false ); - model_param.set_MODEL_EVAL_SORT ( false ); - model_param.set_DIRECTION_TYPE(NOMAD::ORTHO_2N); - - - // display: - model_param.set_DISPLAY_DEGREE ( NOMAD::NO_DISPLAY ); - - - // mesh: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - int min_mesh_index = NOMAD::Mesh::get_min_mesh_index(); - int max_mesh_index = NOMAD::Mesh::get_max_mesh_index(); - int max_halton_index = NOMAD::Mesh::get_max_halton_index(); - - NOMAD::Mesh::init ( 4.0 , 1 , -1 , 0 ); - - model_param.set_INITIAL_MESH_SIZE ( NOMAD::Point ( n , 100.0 ) ); - - // maximum number of evaluations: - if (_p.get_bb_nb_outputs()==2) - model_param.set_MULTI_OVERALL_BB_EVAL ( 50000 ); - else - model_param.set_MAX_BB_EVAL ( 50000 ); - - // min mesh size: - // model_param.set_MAX_MESH_INDEX ( 30 ); - // model_param.set_MIN_MESH_SIZE ( NOMAD::Double ( 1e-8 ) , false ); - - model_param.set_SNAP_TO_BOUNDS ( true ); - // model_param.set_SNAP_TO_BOUNDS ( false ); - // model_param.set_LH_SEARCH ( n*100 , n*10 ); - // model_param.set_OPPORTUNISTIC_LH ( true ); - - // disable user calls: - model_param.set_USER_CALLS_ENABLED ( false ); - - // set flags: - bool flag_check_bimads , flag_reset_mesh , flag_reset_barriers , flag_p1_active; - NOMAD::Mads::get_flags ( flag_check_bimads , - flag_reset_mesh , - flag_reset_barriers , - flag_p1_active ); - - NOMAD::Mads::set_flag_check_bimads (false ); - NOMAD::Mads::set_flag_reset_mesh ( true ); - NOMAD::Mads::set_flag_reset_barriers ( true ); - NOMAD::Mads::set_flag_p1_active ( false ); - - // bounds: - { - NOMAD::Point lb ( n , -1.0 ); - NOMAD::Point ub ( n , 1.0 ); - - const NOMAD::Point & LB = _p.get_lb(); - const NOMAD::Point & UB = _p.get_ub(); - - if ( LB.is_defined() || UB.is_defined() ) - { - - model.unscale ( lb ); - model.unscale ( ub ); - - for ( i = 0 ; i < n ; ++i ) - { - - if ( LB[i].is_defined() && LB[i] > lb[i] ) - lb[i] = LB[i]; - - if ( UB[i].is_defined() && UB[i] < ub[i] ) - ub[i] = UB[i]; - } - - model.scale ( lb ); - model.scale ( ub ); - - for ( i = 0 ; i < n ; ++i ) - { - if ( ub[i] < lb[i] || lb[i] > 0.0 || ub[i] < 0.0 ) - { - error = true; - error_str = "optimization error: problem with bounds"; - break; - } - lb[i] *= 1000.0; - ub[i] *= 1000.0; - } - } - else - { - lb *= 1000.0; - ub *= 1000.0; - } - - model_param.set_LOWER_BOUND ( lb ); - model_param.set_UPPER_BOUND ( ub ); - } - - if ( !error ) - { - - try - { - - // parameters validation: - model_param.check(); - - // model evaluator creation: - NOMAD::Evaluator *ev; - if (model_param.get_bb_nb_outputs()==2) - ev =new NOMAD::Multi_Obj_Quad_Model_Evaluator( model_param , model ); - else - ev=new NOMAD::Single_Obj_Quad_Model_Evaluator(model_param, model); - - // algorithm creation and execution: - NOMAD::Mads mads ( model_param , ev ); - NOMAD::stop_type st = mads.run(); - - delete ev; - - // check the stopping criterion: - if ( st == NOMAD::CTRL_C || st == NOMAD::MAX_CACHE_MEMORY_REACHED ) { - std::ostringstream oss; - oss << "model optimization: " << st; - error_str = oss.str(); - error = true; - stop = true; - stop_reason = st; - } - - else if ( st == NOMAD::MAX_BB_EVAL_REACHED ) - _one_search_stats.add_MS_max_bbe(); - - // display solution: + xf.clear(); + xi.clear(); + + int n = model.get_n(); + bool error = false; + std::string error_str; + int i; + + // initial displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "model optimization"; + if ( xk[0] && xk[1] ) + oss << " (" << i_inc+1 << "/2)"; + out << std::endl << NOMAD::open_block ( oss.str() ); + } + + // parameters creation: + NOMAD::Parameters model_param ( out ); + + // number of variables: + model_param.set_DIMENSION ( n ); + + // blackbox outputs: + model_param.set_BB_OUTPUT_TYPE ( _p.get_bb_output_type() ); + + // barrier parameters: + model_param.set_H_MIN ( _p.get_h_min () ); + model_param.set_H_NORM ( _p.get_h_norm() ); + + // starting points: + { + // 1/2: point (0,...,0): + model_param.set_X0 ( NOMAD::Point ( n , 0.0 ) ); + + // 2/2: model center if different than (0,..,0) and if in [-1;1]: + NOMAD::Point x1 = model.get_center(); + + if ( x1.size() == n && x1.is_complete() ) + { + + model.scale ( x1 ); + + bool diff = false; + bool bnd_ok = true; + + for ( i = 0 ; i < n ; ++i ) + { + + if ( x1[i] != 0 ) + diff = true; + + if ( x1[i].abs() > 1.0 ) + { + bnd_ok = false; + break; + } + + x1[i] *= 1000.0; + } + + if ( diff && bnd_ok ) + model_param.set_X0 ( x1 ); + } + } + + // fixed variables: + for ( i = 0 ; i < n ; ++i ) + if ( model.variable_is_fixed(i) || _p.variable_is_fixed(i) ) + model_param.set_FIXED_VARIABLE(i); + + // no model search and no model ordering: + model_param.set_MODEL_SEARCH ( false ); + model_param.set_MODEL_EVAL_SORT ( false ); + model_param.set_DIRECTION_TYPE(NOMAD::ORTHO_2N); + + + // display: + model_param.set_DISPLAY_DEGREE ( NOMAD::NO_DISPLAY ); + + // mesh: use isotropic mesh + model_param.set_ANISOTROPIC_MESH ( false ); + model_param.set_MESH_UPDATE_BASIS ( 4.0 ); + model_param.set_MESH_COARSENING_EXPONENT ( 1 ); + model_param.set_MESH_REFINING_EXPONENT ( -1 ); + model_param.set_INITIAL_MESH_INDEX ( 0 ); + model_param.set_INITIAL_MESH_SIZE ( NOMAD::Point ( n , 100.0 ) ); + + // maximum number of evaluations: + if (_p.get_nb_obj()==2) + model_param.set_MULTI_OVERALL_BB_EVAL ( 50000 ); + else + model_param.set_MAX_BB_EVAL ( 50000 ); + + + model_param.set_SNAP_TO_BOUNDS ( true ); + + // disable user calls: + model_param.set_USER_CALLS_ENABLED ( false ); + + // set flags: + bool flag_check_bimads , flag_reset_mesh , flag_reset_barriers , flag_p1_active; + NOMAD::Mads::get_flags ( flag_check_bimads , + flag_reset_mesh , + flag_reset_barriers , + flag_p1_active ); + + NOMAD::Mads::set_flag_check_bimads (false ); + NOMAD::Mads::set_flag_reset_mesh ( true ); + NOMAD::Mads::set_flag_reset_barriers ( true ); + NOMAD::Mads::set_flag_p1_active ( false ); + + // bounds: + { + NOMAD::Point lb ( n , -1.0 ); + NOMAD::Point ub ( n , 1.0 ); + + const NOMAD::Point & LB = _p.get_lb(); + const NOMAD::Point & UB = _p.get_ub(); + + if ( LB.is_defined() || UB.is_defined() ) + { + + model.unscale ( lb ); + model.unscale ( ub ); + + for ( i = 0 ; i < n ; ++i ) + { + + if ( LB[i].is_defined() && LB[i] > lb[i] ) + lb[i] = LB[i]; + + if ( UB[i].is_defined() && UB[i] < ub[i] ) + ub[i] = UB[i]; + } + + model.scale ( lb ); + model.scale ( ub ); + + for ( i = 0 ; i < n ; ++i ) + { + if ( ub[i] < lb[i] || lb[i] > 0.0 || ub[i] < 0.0 ) + { + error = true; + error_str = "optimization error: problem with bounds"; + break; + } + lb[i] *= 1000.0; + ub[i] *= 1000.0; + } + } + else + { + lb *= 1000.0; + ub *= 1000.0; + } + + model_param.set_LOWER_BOUND ( lb ); + model_param.set_UPPER_BOUND ( ub ); + } + + if ( !error ) + { + + try + { + + // parameters validation: + model_param.check(); + + // model evaluator creation: + NOMAD::Evaluator *ev; + if (model_param.get_nb_obj()==2) + ev =new NOMAD::Multi_Obj_Quad_Model_Evaluator( model_param , model ); + else + ev=new NOMAD::Single_Obj_Quad_Model_Evaluator(model_param, model); + + // algorithm creation and execution: + NOMAD::Mads mads ( model_param , ev ); + + // Handle the case where nb_bb_obj>=2 but no-bimads (case of PhaseOneSearch) ---> need Phase_One_Evaluator for compute_f + NOMAD::Phase_One_Evaluator * p1ev=NULL; + if ( model_param.get_nb_obj() >= 2 && ! flag_check_bimads ) + { + p1ev = new NOMAD::Phase_One_Evaluator ( model_param , *ev ); + mads.get_evaluator_control().set_evaluator ( p1ev ); + } + + NOMAD::stop_type st = mads.run(); + + delete ev; + if (p1ev) + delete p1ev; + + // check the stopping criterion: + if ( st == NOMAD::CTRL_C || st == NOMAD::MAX_CACHE_MEMORY_REACHED ) { + std::ostringstream oss; + oss << "model optimization: " << st; + error_str = oss.str(); + error = true; + stop = true; + stop_reason = st; + } + + else if ( st == NOMAD::MAX_BB_EVAL_REACHED ) + _one_search_stats.add_MS_max_bbe(); + + // display solution: #ifdef DEBUG - NOMAD::Display out_tmp = out; - out_tmp.set_degrees ( NOMAD::NORMAL_DISPLAY ); - mads.display ( out_tmp ); + NOMAD::Display out_tmp = out; + out_tmp.set_degrees ( NOMAD::NORMAL_DISPLAY ); + mads.display ( out_tmp ); #endif - - // update the stats on the number of model evaluations: - _one_search_stats.update_MS_model_opt ( mads.get_stats().get_bb_eval() ); - - // get the solution(s): - const NOMAD::Eval_Point * best_feas = mads.get_best_feasible (); - const NOMAD::Eval_Point * best_infeas = mads.get_best_infeasible(); - - if ( best_feas ) { - xf = *best_feas; - xf *= 0.001; - - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << "best feasible point after unscaling : ( "; - xf.NOMAD::Point::display ( out ); - out << " )" << std::endl; - } - - model.unscale ( xf ); - } - else if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "no feasible solution" << std::endl; - - if ( best_infeas ) { - xi = *best_infeas; - xi *= 0.001; - - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << "best infeasible point before unscaling: ( "; - xi.NOMAD::Point::display ( out ); - out << " )" << std::endl; - } - - model.unscale ( xi ); - } - else if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "no infeasible solution" << std::endl; - - if ( !xf.is_defined() && !xi.is_defined() ) { - error = true; - error_str = "optimization error: no solution"; - } - } - catch ( std::exception & e ) { - error = true; - error_str = std::string ( "optimization error: " ) + e.what(); - } - } - - // error before run: - else if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "error before run" << std::endl; - - // reset flags: - NOMAD::Mads::set_flag_check_bimads ( flag_check_bimads ); - NOMAD::Mads::set_flag_reset_mesh ( flag_reset_mesh ); - NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); - NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); - - // reset mesh to what it was before: - NOMAD::Mesh::init ( _p.get_mesh_update_basis().value() , - _p.get_mesh_coarsening_exponent() , - _p.get_mesh_refining_exponent() , - _p.get_initial_mesh_index() ); - - NOMAD::Mesh::set_max_halton_index ( max_halton_index ); - - NOMAD::Mesh::set_mesh_index ( mesh_index ); - NOMAD::Mesh::set_min_mesh_index ( min_mesh_index ); - NOMAD::Mesh::set_max_mesh_index ( max_mesh_index ); - - - - - // close display block: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - if ( error ) - out.close_block ( error_str ); - else - out.close_block(); - out << std::endl; - } - - return !error; + + // update the stats on the number of model evaluations: + _one_search_stats.update_MS_model_opt ( mads.get_stats().get_bb_eval() ); + + // get the solution(s): + const NOMAD::Eval_Point * best_feas = mads.get_best_feasible (); + const NOMAD::Eval_Point * best_infeas = mads.get_best_infeasible(); + + if ( best_feas ) { + xf = *best_feas; + xf *= 0.001; + + if ( display_degree == NOMAD::FULL_DISPLAY ) { + out << "best feasible point after unscaling : ( "; + xf.NOMAD::Point::display ( out ); + out << " )" << std::endl; + } + + model.unscale ( xf ); + } + else if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "no feasible solution" << std::endl; + + if ( best_infeas ) { + xi = *best_infeas; + xi *= 0.001; + + if ( display_degree == NOMAD::FULL_DISPLAY ) { + out << "best infeasible point before unscaling: ( "; + xi.NOMAD::Point::display ( out ); + out << " )" << std::endl; + } + + model.unscale ( xi ); + } + else if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "no infeasible solution" << std::endl; + + if ( !xf.is_defined() && !xi.is_defined() ) { + error = true; + error_str = "optimization error: no solution"; + } + } + catch ( std::exception & e ) { + error = true; + error_str = std::string ( "optimization error: " ) + e.what(); + } + } + + // error before run: + else if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "error before run" << std::endl; + + // reset flags: + NOMAD::Mads::set_flag_check_bimads ( flag_check_bimads ); + NOMAD::Mads::set_flag_reset_mesh ( flag_reset_mesh ); + NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); + NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); + + + // close display block: + if ( display_degree == NOMAD::FULL_DISPLAY ) { + if ( error ) + out.close_block ( error_str ); + else + out.close_block(); + out << std::endl; + } + + return !error; } diff --git a/src/Quad_Model_Search.hpp b/src/Quad_Model_Search.hpp index 92ec2e22407682e25611abdad6186d91975eaca8..1f2d19e49f4b1981189fafe42a54c75f6b1f8d8d 100644 --- a/src/Quad_Model_Search.hpp +++ b/src/Quad_Model_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -85,8 +85,8 @@ namespace NOMAD { \param x The point coordinates -- \b IN. \param model The model -- \b IN. \param signature Signature -- \b IN. - \param mesh_index Mesh index -- \b IN. - \param delta_m Mesh size parameter -- \b IN. + \param mesh_indices Mesh indic -- \b IN. + \param delta Mesh size parameter -- \b IN. \param display_degree Display degree -- \b IN. \param out The NOMAD::Display object -- \b IN. */ @@ -95,11 +95,11 @@ namespace NOMAD { NOMAD::Point x , const NOMAD::Quad_Model & model , NOMAD::Signature & signature , - int mesh_index , - const NOMAD::Point & delta_m , + const NOMAD::Point & mesh_indices , + const NOMAD::Point & delta , NOMAD::dd_type display_degree , const NOMAD::Display & out ); - + /*----------------------------------------------------------------------*/ public: diff --git a/src/RNG.cpp b/src/RNG.cpp index 42e70a600550b0356cadb026625809ca55473788..c37391f209ef2921e906a38914081e68aff524dc 100644 --- a/src/RNG.cpp +++ b/src/RNG.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2010 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -39,38 +39,79 @@ */ #include "RNG.hpp" +#include <math.h> +//** Default values for the provided number seed */ +int NOMAD::RNG::_s = 0; -//** Default values for the random number seed */ -uint32_t NOMAD::RNG::x = 123456789; -uint32_t NOMAD::RNG::y = 362436069; -uint32_t NOMAD::RNG::z = 521288629; +uint32_t NOMAD::RNG::x_def = 123456789; +uint32_t NOMAD::RNG::y_def = 362436069; +uint32_t NOMAD::RNG::z_def = 521288629; +uint32_t NOMAD::RNG::_x = x_def; +uint32_t NOMAD::RNG::_y = y_def; +uint32_t NOMAD::RNG::_z = z_def; -bool NOMAD::RNG::set_seed(unsigned long s) + +void NOMAD::RNG::set_seed(int s) { - if(s<=UINT32_MAX) - { - x=s; - return true; - } - else - return false; + + if( s<=INT_MAX && s>=0 ) + _s=s; + else + throw NOMAD::Exception ( "RNG.cpp" , __LINE__ , + "NOMAD::RNG::set_seed(): invalid seed. Seed should be in [0,INT_MAX]" ); + + reset_seed_to_default(); + for ( int i=0 ; i<_s ; i++) + NOMAD::RNG::rand(); + + } uint32_t NOMAD::RNG::rand ( void ) -{ //period 2^96-1 +{ + // http://madrabbit.org/~ray/code/xorshf96.c //period 2^96-1 uint32_t t; - x ^= x << 16; - x ^= x >> 5; - x ^= x << 1; + _x ^= _x << 16; + _x ^= _x >> 5; + _x ^= _x << 1; - t = x; - x = y; - y = z; - z = t ^ x ^ y; + t = _x; + _x = _y; + _y = _z; + _z = t ^ _x ^ _y; - return z; + return _z; } + +/*----------------------------------------*/ +/* normal random generators */ +/*----------------------------------------*/ +double NOMAD::RNG::normal_rand( double mean , double var ) +{ + // Box-Muller transformation~\cite{BoMu58} + + double x1 , x2 , w; + + do + { + x1 = NOMAD::RNG::rand(-1.0,1.0); + x2 = NOMAD::RNG::rand(-1.0,1.0); + w = x1 * x1 + x2 * x2; + } while ( w >= 1.0 ); + + w = sqrt( (-2.0 * log( w ) ) / w ); + + return pow ( var,0.5) * x1 * w + mean; +} +double NOMAD::RNG::normal_rand_mean_0 ( double Var , int Nsample ) +{ + double sum = 0.0; + double a=pow( 3.0*Var,0.5 ); + for ( int i=0 ; i<Nsample ; i++ ) + sum+=NOMAD::RNG::rand(-a,a); + return sum / pow( Nsample,0.5 ); +} diff --git a/src/RNG.hpp b/src/RNG.hpp index e7e1ee4e30f047571ea352b95d248069f8d1de89..c0f8714b860976d11ad9be36bd2f5828a87bca93 100644 --- a/src/RNG.hpp +++ b/src/RNG.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2010 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -43,45 +43,90 @@ #define __RNG__ #include "defines.hpp" +#include "Exception.hpp" using namespace std; namespace NOMAD { - - /// Class for random number generator + + /// Class for random number generator /** - This class is used to set a seed for the random number generator and - get a random integer or a random double between two values. + This class is used to set a seed for the random number generator and + get a random integer or a random double between two values. */ class RNG { public: - + + /// Get current seed + /* + /return An integer in [0,UINT32_MAX]. + */ + static int get_seed ( void ) + { + return static_cast<int>(_s); + } + + /// Reset seed to its default value + static void reset_seed_to_default ( void ) + { + _x=x_def; + _y=y_def; + _z=z_def; + } + /// Set seed /* /param s The seed -- \b IN. - /return A boolean if the seed is acceptable, that is in [0,UINT32_MAX]. */ - static bool set_seed(unsigned long s); + static void set_seed(int s); + /// Get a random integer as uint32 - /** This function serves to obtain a random number \c + /** This function serves to obtain a random number \c /return An integer in the interval [0,UINT32_MAX]. */ static uint32_t rand(); + + + /// Get a random number having a normal distribution as double + /* + /param a Lower bound -- \b IN. + /param b Upper bound -- \b IN. + /return A double in the interval [a,b]. + */ + static double rand(double a, double b) + { + return a+((b-a)*NOMAD::RNG::rand())/UINT32_MAX; + } - /// Get a random number as double + /// Get a random number approaching a normal distribution (N(0,Var)) as double + // A series of Nsample random numbers Xi in the interval [-sqrt(3*Var);+sqrt(3*Var)] is used -> E[Xi]=0, Var(Xi)=var + // see http://en.wikipedia.org/wiki/Central_limit_theorem + /* + /param Nsample Number of samples for averaging -- \b IN. + /param Var Variance of the target normal distribution -- \b IN. + /return A double in the interval [-sqrt(3*Var);+sqrt(3*Var)]. + */ + static double normal_rand_mean_0( double Var=1 , int Nsample=12 ) ; + + + /// Get a random number approaching a normal distribution ( N(Mean,Var) ) as double /* - /param a Lower bound -- \b IN. - /param b Upper bound -- \b IN. - /return A double in the interval [a,b]. - */ - static double rand(double a, double b){return a+((b-a)*NOMAD::RNG::rand())/UINT32_MAX;} + /param Mean Mean of the target normal distribution -- \b IN. + /param Var Variance of the target normal distribution -- \b IN. + /return A random number. + */ + static double normal_rand( double Mean=0 , double Var=1 ) ; + private: - static uint32_t x,y,z; ///< Default parameter value for the random seed generator. + + static uint32_t x_def,y_def,z_def,_x,_y,_z; ///< Default parameter value for the random number generator (_s used as the seed). + static int _s; }; } + #endif diff --git a/src/Random_Pickup.cpp b/src/Random_Pickup.cpp index e0208df6bb0ec6d3a0ef45dd7f1ebe8a20ca77f4..1770499863776a85ed70c98b18fc05406ffcf7e8 100644 --- a/src/Random_Pickup.cpp +++ b/src/Random_Pickup.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -71,7 +71,7 @@ int NOMAD::Random_Pickup::pickup ( void ) { if ( _n == 0 ) return 0; - int ind = NOMAD::RNG::rand()%_n; + int ind = NOMAD::RNG::rand()%_n; int tmp = _elts[ind]; if ( ind < _n - 1 ) { _elts[ind ] = _elts[_n-1]; diff --git a/src/Random_Pickup.hpp b/src/Random_Pickup.hpp index e17bc2ae23c54a65055fc27094efee1d735b3d2a..b111a8672b8dcee5e5f5a44089066bbe0d01f063 100644 --- a/src/Random_Pickup.hpp +++ b/src/Random_Pickup.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/SMesh.cpp b/src/SMesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08746148847e5d58da5e3a2765aedf20b2210d7b --- /dev/null +++ b/src/SMesh.cpp @@ -0,0 +1,382 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Sebastien Le Digabel */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file SMesh.cpp + \brief Class for the MADS mesh (implementation) + \author Sebastien Le Digabel + \date 2010-04-06 + \see SMesh.hpp +*/ +#include "SMesh.hpp" + + + +/*-----------------------------------------------------------*/ +/* update the mesh */ +/*-----------------------------------------------------------*/ +void NOMAD::SMesh::update ( NOMAD::success_type success , const NOMAD::Direction *dir) // , const NOMAD::OrthogonalMesh * mesh ) +{ + // defaults: + // full success: lk = lk - 1 + // failure : lk = lk + 1 + + + if ( success == NOMAD::FULL_SUCCESS ) + { + _mesh_index -= _coarsening_step; + if ( _mesh_index < -NOMAD::L_LIMITS ) + _mesh_index = -NOMAD::L_LIMITS; + } + else if ( success == NOMAD::UNSUCCESSFUL ) + _mesh_index -= _refining_step; + + if ( _mesh_index > _max_mesh_index ) + _max_mesh_index = _mesh_index; + + + if ( _mesh_index < _min_mesh_index ) + _min_mesh_index = _mesh_index; +} + +/*-----------------------------------------------------------*/ +/* Update the provided mesh indices (the Mesh is unchanged). */ +/*-----------------------------------------------------------*/ +void NOMAD::SMesh::update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir ) const +{ + + if ( mesh_indices.is_defined() ) + { + for (int i=0; i < mesh_indices.size() ; i++) + { + if ( success == NOMAD::FULL_SUCCESS ) + { + mesh_indices[i] -= _coarsening_step; + if ( mesh_indices[i] < -NOMAD::L_LIMITS ) + mesh_indices[i] = -NOMAD::L_LIMITS; + } + else if ( success == NOMAD::UNSUCCESSFUL ) + mesh_indices[i] -= _refining_step; + } + } +} + + +/*-----------------------------------------------------------*/ +/* manually set the mesh index */ +/*-----------------------------------------------------------*/ +void NOMAD::SMesh::set_mesh_indices ( const NOMAD::Point & r ) +{ + if (!r.is_defined()) + _mesh_index=0; + else + _mesh_index=r[0].NOMAD::Double::round(); + + if ( _mesh_index > _max_mesh_index ) + _max_mesh_index = _mesh_index; + if ( _mesh_index < _min_mesh_index ) + _min_mesh_index = _mesh_index; +} + + + +/*-----------------------------------------------------------*/ +/* set the limit mesh index (max value) */ +/*-----------------------------------------------------------*/ +void NOMAD::SMesh::set_limit_mesh_index ( int l ) +{ + _limit_mesh_index=l; +} + + + +/*-----------------------------------------------------------*/ +/* display */ +/*-----------------------------------------------------------*/ +void NOMAD::SMesh::display ( const NOMAD::Display & out ) const +{ + out << "n : " << get_n() << std::endl + << "mesh update basis : " << _update_basis << std::endl + << "mesh coarsening step: " << _coarsening_step << std::endl + << "mesh refining step : " << _refining_step << std::endl + << "initial mesh size : " + << "(" << _delta_0 << " )" << std::endl; + out << "minimal mesh size : "; + if ( _delta_min.is_defined() ) + out << "(" << _delta_min << " )" << std::endl; + else + out << "none"; + out << std::endl + << "minimal poll size : "; + if ( _Delta_min_is_defined ) + out << "(" << _Delta_min << " )" << std::endl; + else + out << "none"; + out << std::endl; +} + +/*----------------------------------------------------------*/ +/* check the stopping conditions on the minimal poll size */ +/* and on the minimal mesh size */ +/*----------------------------------------------------------*/ +void NOMAD::SMesh::check_min_mesh_sizes ( bool & stop , + NOMAD::stop_type & stop_reason ) const +{ + if ( stop ) + return; + + // 1. mesh index tests: + if ( abs ( _mesh_index ) > NOMAD::L_LIMITS ) + { + stop = true; + stop_reason = NOMAD::L_LIMITS_REACHED; + } + + // 2. delta_k^p (poll size) tests: + if ( check_min_poll_size_criterion ( ) ) + { + stop = true; + stop_reason = NOMAD::DELTA_P_MIN_REACHED; + } + + // 3. delta_k^m (mesh size) tests: + if ( check_min_mesh_size_criterion ( ) ) + { + stop = true; + stop_reason = NOMAD::DELTA_M_MIN_REACHED; + } +} + +/*-----------------------------------------------------------*/ +/* check the minimal poll size (private) */ +/*-----------------------------------------------------------*/ +bool NOMAD::SMesh::check_min_poll_size_criterion ( ) const +{ + if ( !_Delta_min_is_defined ) + return false; + NOMAD::Point Delta; + return get_Delta ( Delta ); +} + +/*-----------------------------------------------------------*/ +/* check the minimal mesh size (private) */ +/*-----------------------------------------------------------*/ +bool NOMAD::SMesh::check_min_mesh_size_criterion ( ) const +{ + if ( !_delta_min.is_defined() ) + return false; + NOMAD::Point delta; + return get_delta ( delta ); +} + +/*----------------------------------------------------------------*/ +/* get delta (mesh size parameter) */ +/* delta^k = delta^0 \tau^{ell_0^+ - ell_k^+} */ +/*----------------------------------------------------------------*/ +/* the function also returns true if one value is < delta_min */ +/* (stopping criterion MIN_MESH_SIZE) */ +/*----------------------------------------------------------------*/ +bool NOMAD::SMesh::get_delta ( NOMAD::Point & delta ) const +{ + delta.reset ( _n ); + + bool delta_min_is_defined=_delta_min.is_defined(); + + + // power_of_tau = tau^{ max{0,l0} - max{0,lk} }: + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index > 0) ? _mesh_index : 0) ); + + bool stop = false; + + // delta^k = power_of_tau * delta^0: + for ( int i = 0 ; i < _n ; ++i ) + { + delta[i] = _delta_0[i] * power_of_tau; + if ( !stop && delta_min_is_defined && delta[i] < _delta_min[i] ) + stop = true; + + } + + return stop; +} + +/*----------------------------------------------------------------*/ +/* get delta (mesh size parameter) */ +/* delta^k = delta^0 \tau^{ell_0^+ - ell_k^+} */ +/*----------------------------------------------------------------*/ +NOMAD::Double NOMAD::SMesh::get_delta ( int i ) const +{ + + + // power_of_tau = tau^{ max{0,l0} - max{0,lk} }: + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index > 0) ? _mesh_index : 0) ); + + + NOMAD::Double delta = _delta_0[i] * power_of_tau; + + return delta; +} + + +/*----------------------------------------------------------------*/ +/* get delta_max (the larget mesh size) */ +/*----------------------------------------------------------------*/ +NOMAD::Point NOMAD::SMesh::get_delta_max ( ) const +{ + + NOMAD::Point delta_max ( _n ); + + // power_of_tau = tau^{ max{0,l0} - max{0,lk} }: + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_min_mesh_index > 0) ? _min_mesh_index : 0) ); + + // delta^k = power_of_tau * delta^0: + for ( int i = 0 ; i < _n ; ++i ) + delta_max[i] = _delta_0[i] * power_of_tau; + + return delta_max; +} + + +/*-------------------------------------------------------------------*/ +/* get Delta (poll size parameter) */ +/* Delta^k = Delta^m_k \tau^{ |ell_k|/2 } */ +/* = delta^0 \tau^{ell_0^+ - ell_k^+ + |ell_k|/2} */ +/*-------------------------------------------------------------------*/ +/* the function also returns true if all values are < Delta_min */ +/*-------------------------------------------------------------------*/ +bool NOMAD::SMesh::get_Delta ( NOMAD::Point & Delta ) const +{ + + Delta.reset ( _n ); + + // power_of_tau = tau^{ max{0,l0} - max{0,lk} + |lk|/2}: + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , abs(_mesh_index) / 2.0 + + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index > 0) ? _mesh_index : 0) ); + + bool stop = true; + + // Delta^k = power_of_tau * Delta^0: + for ( int i = 0 ; i < _n ; ++i ) + { + Delta[i] = _Delta_0[i] * power_of_tau; + if ( !_Delta_min_is_complete || Delta[i] >= _Delta_min[i] ) + stop = false; + + if ( _Delta_min_is_defined && _Delta_min[i].is_defined() && Delta[i] < _Delta_min[i] ) + Delta[i]=_Delta_min[i]; + } + + return stop; +} + +/*-------------------------------------------------------------------*/ +/* get Delta (poll size parameter) */ +/* Delta^k = Delta^m_k \tau^{ |ell_k|/2 } */ +/* = delta^0 \tau^{ell_0^+ - ell_k^+ + |ell_k|/2} */ +/*--------------------------------------------------------------*/ +/* the function returns Delta >= Delta_min */ +/*--------------------------------------------------------------*/ +NOMAD::Double NOMAD::SMesh::get_Delta ( int i ) const +{ + + // power_of_tau = tau^{ max{0,l0} - max{0,lk} + |lk|/2}: + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , abs(_mesh_index) / 2.0 + + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index > 0) ? _mesh_index : 0) ); + + NOMAD::Double Delta = _Delta_0[i] * power_of_tau; + + if ( _Delta_min_is_defined && _Delta_min[i].is_defined() && Delta < _Delta_min[i] ) + Delta=_Delta_min[i]; + + return Delta; +} + + +NOMAD::Double NOMAD::SMesh::scale_and_project(int i, const NOMAD::Double & l) const +{ + NOMAD::Double delta = get_delta ( i ); + NOMAD::Double Delta = get_Delta ( i ); + + + if ( delta.is_defined() && Delta.is_defined() && i <= _n) + { + NOMAD::Double d= Delta / delta * l; + return d.NOMAD::Double::round()*delta; + } + else + throw NOMAD::Exception ( "SMesh.cpp" , __LINE__ , + "Mesh scaling and projection cannot be performed!" ); + +} + + + + +NOMAD::Point NOMAD::SMesh::get_mesh_ratio_if_success ( void ) const +{ + + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index > 0) ? _mesh_index : 0) ); + + NOMAD::Double power_of_tau_if_success + = pow ( _update_basis.value() , + ( (_initial_mesh_index > 0) ? _initial_mesh_index : 0) - + ( (_mesh_index - _coarsening_step > 0) ? _mesh_index - _coarsening_step : 0) ); + + try + { + NOMAD::Double ratio_scalaire = power_of_tau_if_success/power_of_tau; + return NOMAD::Point( _n , ratio_scalaire ); + } + catch ( NOMAD::Double::Invalid_Value & ) + { + return NOMAD::Point( _n,-1 ); + } +} diff --git a/src/SMesh.hpp b/src/SMesh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..00f02118efc2cfcd8a155aac6b0d040029b826c2 --- /dev/null +++ b/src/SMesh.hpp @@ -0,0 +1,309 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Sebastien Le Digabel */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file SMesh.hpp + \brief Class for the static orthogonal MADS mesh (headers) + \author Christophe Tribes + \date 2010-04-06 + \see OrthogonalMesh.cpp SMesh.cpp + */ +#ifndef __SMESH__ +#define __SMESH__ + +#include "Point.hpp" +#include "OrthogonalMesh.hpp" + +namespace NOMAD { + + /// Class for the MADS orthogonal static mesh. + /** + - The static mesh is defined with the basic directions and a + mesh size parameter delta^k. + - The mesh size parameter is defined with a single mesh index (the integer r^k) + and the initial mesh size delta^0 for all coordinates. + - The poll size parameter Delta^k (single value for all coordinates) is not + used to define the mesh but to define the poll trial points. + - At each MADS iteration the mesh is updated with + delta^k+1 = tau^w+ delta^k and w+ >= 0 (dominating iteration) + or with + delta^k+1 = tau^w- delta^k and w- < 0 (iteration failure). + The mesh is not changed after improving iterations. + - Mesh and poll size parameters are stored as NOMAD::Point objects + (one value for each variable). The scaling is done once based on initial mesh size. + - See the MADS papers for more details on the mesh. + */ + + class SMesh : public NOMAD::OrthogonalMesh { + + private: + + int _initial_mesh_index; + int _mesh_index; + int _min_mesh_index; ///< Minimal value reached by the mesh index + int _max_mesh_index; ///< Maximal value reached by the mesh index + + /*--------------------------------------------------------------*/ + + /// Private affectation operator. + /** + \param m The right-hand side object -- \b IN. + */ + const SMesh & operator = ( const SMesh & m ); + + /// Check the minimal poll size criterion. + bool check_min_poll_size_criterion ( ) const; + + /// Check the minimal mesh size criterion. + bool check_min_mesh_size_criterion ( ) const; + + /// Access to the mesh size parameter delta^k. + /** + \return delta The mesh size parameter delta^k -- \b OUT. + \param i The index of the mesh size + */ + NOMAD::Double get_delta ( int i ) const ; + + + /// Access to the poll size parameter Delta^k. + /** + \return Delta The poll size parameter Delta^k -- \b OUT. + \param i The index of the poll size + */ + NOMAD::Double get_Delta ( int i ) const ; + + + + /*--------------------------------------------------------------*/ + + public: + + /// Constructor. + /** + \param delta_0 Initial mesh size delta_0 -- \b IN. + \param Delta_min Minimal poll size Delta_min (may be undefined) -- \b IN. + \param delta_min Minimal mesh size delta_min (may be undefined) -- \b IN. + \param mesh_update_basis Mesh update basis (tau), default=4 -- \b IN. + \param mesh_coarsening_step Mesh coarsening step (w+), default=1 -- \b IN. + \param mesh_refining_step Mesh refining step (w-), default=-1 -- \b IN. + \param initial_mesh_index Initial mesh index ell_0, default=0 -- \b IN. + \param limit_max_mesh_index Limit max of the mesh index, default=L_LIMITS -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + */ + SMesh ( const NOMAD::Point & delta_0 , + const NOMAD::Point & Delta_min , + const NOMAD::Point & delta_min , + const NOMAD::Point & fixed_variables , + NOMAD::Double mesh_update_basis=4.0, + int mesh_coarsening_step=1, + int mesh_refining_step=-1, + int initial_mesh_index=0, + int limit_max_mesh_index=NOMAD::L_LIMITS) + : NOMAD::OrthogonalMesh ( delta_0, + Delta_min, + delta_min, + fixed_variables, + mesh_update_basis, + mesh_coarsening_step, + mesh_refining_step , + limit_max_mesh_index ), + _initial_mesh_index ( initial_mesh_index ), + _mesh_index ( _initial_mesh_index ), + _min_mesh_index ( initial_mesh_index ), + _max_mesh_index ( initial_mesh_index ) {} + + + /// Copy constructor. + /** + \param m The copied object -- \b IN. + */ + SMesh ( const SMesh & m ) + : OrthogonalMesh(m) , + _initial_mesh_index ( m._initial_mesh_index ), + _mesh_index ( m._initial_mesh_index ), + _min_mesh_index( m._initial_mesh_index ), + _max_mesh_index ( m._initial_mesh_index ) {} + + /// Destructor. + virtual ~SMesh ( void ) + { + _delta_0.clear(); + _Delta_0.clear(); + _delta_min.clear(); + _Delta_min.clear(); + } + + + /// Access to the mesh index. + /** + \return A Point with the mesh index. + */ + const NOMAD::Point get_mesh_indices ( void ) const + { + return NOMAD::Point( 1 , NOMAD::Double(_mesh_index) ); + } + + /// Access to the min mesh index reached so far. + /** + \return A Point with the mesh index. + */ + const NOMAD::Point get_min_mesh_indices ( void ) const + { + return NOMAD::Point( 1 , NOMAD::Double(_min_mesh_index) ); + } + + + /// Access to the max mesh index reached so far. + /** + \return A Point with the mesh index. + */ + const NOMAD::Point get_max_mesh_indices ( void ) const + { + return NOMAD::Point( 1 , NOMAD::Double(_max_mesh_index) ); + } + + + /// Manually set the mesh index using a point. (set_mesh_indices for consistency with XMesh) + /** + \param r The mesh index provided as a point -- \b IN. + */ + void set_mesh_indices ( const NOMAD::Point & r ); + + + + /// Manually set the limit mesh index used for termination criterion (max value for SMesh). + /** + \param l The limit mesh index for all coordinates -- \b IN. + */ + void set_limit_mesh_index ( int l ); + + + + /// Test if finest mesh so far. + /** + \return True if mesh index greater or equal to the maximal mesh index; False otherwise. + */ + bool is_finest(void) const {return _mesh_index >= _max_mesh_index; } + + + /// Access to the mesh ratios after a success + /** + \return A point with the ratio for each coordinate + */ + NOMAD::Point get_mesh_ratio_if_success( void ) const; + + + /// Update the provided mesh indices (the Mesh is unchanged). + /** + \param success Type of success of the iteration -- \b IN. + \param mesh_indices The mesh indices before and after the update -- \b IN/OUT. + \param dir The direction that is considered (opt) -- \b IN. + */ + void update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir=NULL ) const ; + + + /// Update the Mesh. + /** + \param success Type of success of the iteration -- \b IN. + \param dir The direction that is considered (opt) -- \b IN. + */ + void update ( NOMAD::success_type success , const NOMAD::Direction *dir=NULL); + + + /// Reset the mesh to its original size (mesh indices). + void reset ( void ) + { + set_mesh_indices( NOMAD::Point(1,NOMAD::Double(_initial_mesh_index))) ; + _min_mesh_index=_initial_mesh_index ; + _max_mesh_index=_initial_mesh_index; + } + + /// Access to the mesh size parameter delta^k. + /** + \param delta The mesh size parameter delta^k -- \b OUT. + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + mesh size delta_min + (stopping criterion MIN_MESH_SIZE). + */ + virtual bool get_delta ( NOMAD::Point & delta ) const ; + + + + + /// Access to the larget mesh size so far. + /** + \return delta_max The largest mesh size reached so far -- \b OUT. + */ + NOMAD::Point get_delta_max ( void ) const ; + + /// Access to the poll size parameter Delta^k. + /** + \param Delta The poll size parameter Delta^k -- \b OUT. + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + mesh size Delta_min + (stopping criterion MIN_POLL_SIZE). + */ + virtual bool get_Delta ( NOMAD::Point & Delta ) const ; + + + /// Check the stopping conditions on the minimal poll and mesh sizes. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void check_min_mesh_sizes ( bool & stop , + NOMAD::stop_type & stop_reason ) const; + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + + /// Scale and project the ith component of a vector on the mesh + /** + \param i The vector component number -- \b IN. + \param l The vector component value -- \b IN. + \return The ith component of a vector after mesh scaling and projection + */ + NOMAD::Double scale_and_project(int i, const NOMAD::Double & l) const ; + + + }; +} + +#endif diff --git a/src/Search.hpp b/src/Search.hpp index 07ed31aeebe9c0203fda7394021a7a99ae820063..a7b6b2e87e0c7f94a7cb46e2d83bd701dacc4c76 100644 --- a/src/Search.hpp +++ b/src/Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Set_Element.hpp b/src/Set_Element.hpp index def08a79bbdbd6618ce73ec0eaabb654fcfc7f0d..092346af4f3f178807b2992029ad738b01b8199c 100644 --- a/src/Set_Element.hpp +++ b/src/Set_Element.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Signature.cpp b/src/Signature.cpp index ee7fa007580eef5fe8f3ad6f7256d9649fc71ca1..cba5d264adf08725b8f026a83a3288323d235e1a 100644 --- a/src/Signature.cpp +++ b/src/Signature.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,13 +34,15 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Signature.cpp - \brief Evaluation point signature (implementation) - \author Sebastien Le Digabel - \date 2010-04-22 - \see Signature.hpp -*/ + \file Signature.cpp + \brief Evaluation point signature (implementation) + \author Sebastien Le Digabel + \date 2010-04-22 + \see Signature.hpp + */ #include "Signature.hpp" +#include "SMesh.hpp" +#include "XMesh.hpp" /*-----------------------------------*/ /* static members initialization */ @@ -56,38 +58,62 @@ bool NOMAD::Signature::_warning_has_been_displayed=false; /* constructor 1 */ /*--------------------------------------------------*/ NOMAD::Signature::Signature -( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups , - const NOMAD::Display & out ) - : _mesh ( NULL ) , - _std ( false ) , - _out (out) +( int n , + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + bool use_smesh , + bool anisotropic_mesh , + const NOMAD::Point & initial_poll_size , + const NOMAD::Point & min_poll_size , + const NOMAD::Point & min_mesh_size , + NOMAD::Double & mesh_update_basis , + NOMAD::Double & poll_update_basis , + int & mesh_coarsening_exponent, + int & mesh_refining_exponent, + int initial_mesh_index , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables, + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups , + const NOMAD::Display & out ) +: _std ( false ) , +_out ( out ) { - init ( n , - input_types , - initial_mesh_size , - min_mesh_size , - min_poll_size , - lb , - ub , - scaling , - fixed_variables , - periodic_variables , - var_groups ); - + // Mesh index starts at 0 for an xmesh and decreases as the mesh size decreases + // The mesh index is reset to 0 as the mesh is reset. + if ( ! use_smesh ) + _mesh=new NOMAD::XMesh(anisotropic_mesh, + initial_poll_size, + min_poll_size, + min_mesh_size, + fixed_variables, + poll_update_basis, // XMesh set poll update basis (default 2) + mesh_coarsening_exponent, + mesh_refining_exponent); + else // Mesh index can be provided for isotropic smesh and increases as the mesh size decreases + _mesh=new NOMAD::SMesh(initial_poll_size, // new initial_poll_size ~ old initial mesh size + min_poll_size, + min_mesh_size, + fixed_variables, + mesh_update_basis, // SMesh set mesh update basis (default 4) + mesh_coarsening_exponent, + mesh_refining_exponent, + initial_mesh_index ); + + init ( n , + input_types , + lb , + ub , + scaling , + fixed_variables , + periodic_variables , + var_groups ); + #ifdef MEMORY_DEBUG - ++NOMAD::Signature::_cardinality; - if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) - ++NOMAD::Signature::_max_cardinality; + ++NOMAD::Signature::_cardinality; + if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) + ++NOMAD::Signature::_max_cardinality; #endif } @@ -96,79 +122,81 @@ NOMAD::Signature::Signature /*--------------------------------------------------*/ NOMAD::Signature::Signature ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed , - const NOMAD::Display & out ) - : _mesh ( NULL ) , - _std ( false ) , - _out ( out ) + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & initial_poll_size , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const std::set<NOMAD::direction_type> & direction_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types , + const NOMAD::Display & out ) +: _std ( false ) , +_out ( out ) { - if ( static_cast<int> ( input_types.size() ) != n ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::Signature(): bad argument: input_types" ); - - // automatic creation of groups of variables: - // ------------------------------------------ - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> var_groups; - - { - std::set<int> vi_cbi; // list of cont./bin./int. variables - std::set<int> vi_cat; // list of categorical variables - - for ( int i = 0 ; i < n ; ++i ) - if ( input_types[i] != NOMAD::CATEGORICAL ) - vi_cbi.insert(i); - else - vi_cat.insert(i); - - // creation of a group for cont./bin./int. variables: - if ( !vi_cbi.empty() ) - var_groups.insert ( new NOMAD::Variable_Group ( vi_cbi , - direction_types , - sec_poll_dir_types , - halton_seed++ , - out ) ); - - // creation of a group for categorical variables: - if ( !vi_cat.empty() ) - var_groups.insert ( new NOMAD::Variable_Group ( vi_cat , - direction_types , - sec_poll_dir_types, - -1 , // no Halton seed - out ) ); - - } - - // init: - // ----- - init ( n , - input_types , - initial_mesh_size , - NOMAD::Point() , - NOMAD::Point() , - lb , - ub , - NOMAD::Point() , - NOMAD::Point() , - std::vector<bool>() , - var_groups ); - - // delete the temporary groups of variables: - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::iterator + if ( static_cast<int> ( input_types.size() ) != n ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::Signature(): bad argument: input_types" ); + + // Default mesh is isotropic xmesh + //------------------------------------------ + _mesh=new NOMAD::XMesh (false, + initial_poll_size, + NOMAD::Point(), + NOMAD::Point(), + NOMAD::Point()); + + + // automatic creation of groups of variables: + // ------------------------------------------ + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> var_groups; + + { + std::set<int> vi_cbi; // list of cont./bin./int. variables + std::set<int> vi_cat; // list of categorical variables + + for ( int i = 0 ; i < n ; ++i ) + if ( input_types[i] != NOMAD::CATEGORICAL ) + vi_cbi.insert(i); + else + vi_cat.insert(i); + + // creation of a group for cont./bin./int. variables: + if ( !vi_cbi.empty() ) + var_groups.insert ( new NOMAD::Variable_Group ( vi_cbi , + direction_types , + sec_poll_dir_types , + out ) ); + + // creation of a group for categorical variables: + if ( !vi_cat.empty() ) + var_groups.insert ( new NOMAD::Variable_Group ( vi_cat , + direction_types , + sec_poll_dir_types, + out ) ); + + } + + // init: + // ----- + init ( n , + input_types , + lb , + ub , + NOMAD::Point() , + NOMAD::Point() , + std::vector<bool>() , + var_groups ); + + // delete the temporary groups of variables: + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::iterator it , end = var_groups.end(); - - for ( it = var_groups.begin() ; it != end ; ++it ) - delete *it; - + + for ( it = var_groups.begin() ; it != end ; ++it ) + delete *it; + #ifdef MEMORY_DEBUG - ++NOMAD::Signature::_cardinality; - if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) - ++NOMAD::Signature::_max_cardinality; + ++NOMAD::Signature::_cardinality; + if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) + ++NOMAD::Signature::_max_cardinality; #endif } @@ -176,29 +204,35 @@ NOMAD::Signature::Signature /* copy constructor */ /*--------------------------------------------------*/ NOMAD::Signature::Signature ( const NOMAD::Signature & s ) - : _lb ( s._lb ) , - _ub ( s._ub ) , - _scaling ( s._scaling ) , - _fixed_variables ( s._fixed_variables ) , - _input_types ( s._input_types ) , - _all_continuous ( s._all_continuous ) , - _has_categorical ( s._has_categorical ) , - _periodic_variables ( s._periodic_variables ) , - _mesh ( new NOMAD::Mesh(*s._mesh) ) , - _std ( false ) , - _feas_success_dir ( s._feas_success_dir ) , - _infeas_success_dir ( s._infeas_success_dir ) , - _out (s._out) +: _lb ( s._lb ) , +_ub ( s._ub ) , +_scaling ( s._scaling ) , +_fixed_variables ( s._fixed_variables ) , +_input_types ( s._input_types ) , +_all_continuous ( s._all_continuous ) , +_has_categorical ( s._has_categorical ) , +_periodic_variables ( s._periodic_variables ) , +_std ( false ) , +_feas_success_dir ( s._feas_success_dir ) , +_infeas_success_dir ( s._infeas_success_dir ) , +_out (s._out) { - std::list<NOMAD::Variable_Group *>::const_iterator it , end = s._var_groups.end(); - for ( it = s._var_groups.begin() ; it != end ; ++it ) - _var_groups.push_back ( new NOMAD::Variable_Group(**it) ); - + + + if (dynamic_cast<NOMAD::SMesh*> (s._mesh)) + _mesh = new NOMAD::SMesh (*(static_cast<NOMAD::SMesh*>(s._mesh))); + else + _mesh = new NOMAD::XMesh (*(static_cast<NOMAD::XMesh*>(s._mesh))); + + std::list<NOMAD::Variable_Group *>::const_iterator it , end = s._var_groups.end(); + for ( it = s._var_groups.begin() ; it != end ; ++it ) + _var_groups.push_back ( new NOMAD::Variable_Group(**it) ); + #ifdef MEMORY_DEBUG - ++NOMAD::Signature::_cardinality; - if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) - ++NOMAD::Signature::_max_cardinality; -#endif + ++NOMAD::Signature::_cardinality; + if ( NOMAD::Signature::_cardinality > NOMAD::Signature::_max_cardinality ) + ++NOMAD::Signature::_max_cardinality; +#endif } /*--------------------------------------------------*/ @@ -206,9 +240,9 @@ NOMAD::Signature::Signature ( const NOMAD::Signature & s ) /*--------------------------------------------------*/ NOMAD::Signature::~Signature ( void ) { - clear(); + clear(); #ifdef MEMORY_DEBUG - --NOMAD::Signature::_cardinality; + --NOMAD::Signature::_cardinality; #endif } @@ -217,20 +251,20 @@ NOMAD::Signature::~Signature ( void ) /*--------------------------------------------------------------------------------*/ void NOMAD::Signature::clear ( void ) { - delete _mesh; - _mesh = NULL; - _all_continuous = true; - _has_categorical = false; - _std = false; - reset_var_groups(); - _feas_success_dir.clear(); - _infeas_success_dir.clear(); - _lb.clear(); - _ub.clear(); - _scaling.clear(); - _fixed_variables.clear(); - _input_types.clear(); - _periodic_variables.clear(); + _all_continuous = true; + _has_categorical = false; + _std = false; + reset_var_groups(); + _feas_success_dir.clear(); + _infeas_success_dir.clear(); + _lb.clear(); + _ub.clear(); + _scaling.clear(); + _fixed_variables.clear(); + _input_types.clear(); + _periodic_variables.clear(); + delete _mesh; + } /*--------------------------------------------------*/ @@ -238,10 +272,10 @@ void NOMAD::Signature::clear ( void ) /*--------------------------------------------------*/ void NOMAD::Signature::set_feas_success_dir ( const NOMAD::Direction & d ) { - if ( d.size() != static_cast<int>(_input_types.size()) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::set_feas_success_dir(): bad direction" ); - _feas_success_dir = d; + if ( d.size() != static_cast<int>(_input_types.size()) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::set_feas_success_dir(): bad direction" ); + _feas_success_dir = d; } /*--------------------------------------------------*/ @@ -249,10 +283,10 @@ void NOMAD::Signature::set_feas_success_dir ( const NOMAD::Direction & d ) /*--------------------------------------------------*/ void NOMAD::Signature::set_infeas_success_dir ( const NOMAD::Direction & d ) { - if ( d.size() != static_cast<int>(_input_types.size()) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::set_infeas_success_dir(): bad direction" ); - _infeas_success_dir = d; + if ( d.size() != static_cast<int>(_input_types.size()) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::set_infeas_success_dir(): bad direction" ); + _infeas_success_dir = d; } @@ -261,198 +295,201 @@ void NOMAD::Signature::set_infeas_success_dir ( const NOMAD::Direction & d ) /*--------------------------------------------------*/ void NOMAD::Signature::init ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ) + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables , + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ) { - // reset directions: - _feas_success_dir.clear(); - _infeas_success_dir.clear(); - - // check the dimension (n): - if ( n <= 0 ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: n" ); - - // bounds: - if ( lb.empty() ) - _lb.reset ( n ); - else if ( lb.size() == n ) - _lb = lb; - else - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: lb" ); - if ( ub.empty() ) - _ub.reset ( n ); - else if ( ub.size() == n ) - _ub = ub; - else - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: ub" ); - - // scaling: - if ( scaling.empty() ) - _scaling.reset ( n ); - else if ( scaling.size() == n ) - _scaling = scaling; - else - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: scaling" ); - int i; - for ( i = 0 ; i < n ; ++i ) - if ( _scaling[i].is_defined() && _scaling[i] == 0.0 ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: scaling (zero value)" ); - - // fixed variables: - if ( fixed_variables.empty() ) - _fixed_variables.reset ( n ); - else if ( fixed_variables.size() == n ) - _fixed_variables = fixed_variables; - else - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: fixed_variables" ); - - // periodic variables: - _periodic_variables = periodic_variables; - if ( !_periodic_variables.empty() ) { - - if ( static_cast<int>(periodic_variables.size()) != n ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: periodic_variables" ); - - for ( i = 0 ; i < n ; ++i ) - if ( _periodic_variables[i] && ( !_lb[i].is_defined() || !_ub[i].is_defined() ) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): incompatible periodic variables" ); - } - - // input types: - if ( static_cast<int>(input_types.size()) != n ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: input_types" ); - _input_types = input_types; - _all_continuous = true; - _has_categorical = false; - - for ( i = 0 ; i < n ; ++i ) - { - - if ( (_lb[i].is_defined() || _ub[i].is_defined() ) && _input_types[i] == NOMAD::CATEGORICAL && _out.get_gen_dd()>=NOMAD::NORMAL_DISPLAY && !_warning_has_been_displayed ) - { - _out << NOMAD::open_block("Warning:") - << "NOMAD::Signature::init(): Providing bounds for categorical variables is not recommended!" << std::endl - << NOMAD::close_block(); - _warning_has_been_displayed=true; - } - - if ( _fixed_variables[i].is_defined() && ((_lb[i].is_defined() && _fixed_variables[i] < _lb[i]) || (_ub[i].is_defined() && _fixed_variables[i] > _ub[i]) || - ( (_input_types[i] == NOMAD::INTEGER || _input_types[i] == NOMAD::CATEGORICAL ) - && !_fixed_variables[i].is_integer() ) || - ( _input_types[i] == NOMAD::BINARY && !_fixed_variables[i].is_binary() ) ) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: fixed variable inconsistent with bounds or input types" ); - - if ( _lb[i].is_defined() && _ub[i].is_defined() ) - { - if ( _lb[i].is_defined() && _ub[i].is_defined() && _lb[i].value()> ub[i].value() ) - { - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): bad argument: lower bound must be lower than upper bound!" ); - } - if ( _lb[i] == _ub[i] ) - _fixed_variables[i]=_lb[i]; - } - } - for ( i = 0 ; i < n ; ++i ) - { - if ( _input_types[i] == NOMAD::CATEGORICAL ) - { - _has_categorical = true; - _all_continuous = false; - break; - } - if ( _input_types[i] != NOMAD::CONTINUOUS ) - { - _all_continuous = false; - if ( _has_categorical ) - break; - } - - - } - - // variable groups: - reset_var_groups(); - - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::iterator + // reset directions: + _feas_success_dir.clear(); + _infeas_success_dir.clear(); + + // check the dimension (n): + if ( n <= 0 ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: n" ); + + // bounds: + if ( lb.empty() ) + _lb.reset ( n ); + else if ( lb.size() == n ) + _lb = lb; + else + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: lb" ); + if ( ub.empty() ) + _ub.reset ( n ); + else if ( ub.size() == n ) + _ub = ub; + else + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: ub" ); + + // scaling: + if ( scaling.empty() ) + _scaling.reset ( n ); + else if ( scaling.size() == n ) + _scaling = scaling; + else + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: scaling" ); + int i; + for ( i = 0 ; i < n ; ++i ) + if ( _scaling[i].is_defined() && _scaling[i] == 0.0 ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: scaling (zero value)" ); + + // fixed variables: + if ( fixed_variables.empty() ) + _fixed_variables.reset ( n ); + else if ( fixed_variables.size() == n ) + _fixed_variables = fixed_variables; + else + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: fixed_variables" ); + + // periodic variables: + _periodic_variables = periodic_variables; + if ( !_periodic_variables.empty() ) + { + + if ( static_cast<int>(periodic_variables.size()) != n ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: periodic_variables" ); + + for ( i = 0 ; i < n ; ++i ) + if ( _periodic_variables[i] && ( !_lb[i].is_defined() || !_ub[i].is_defined() ) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): incompatible periodic variables" ); + } + + // input types: + if ( static_cast<int>(input_types.size()) != n ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: input_types" ); + _input_types = input_types; + _all_continuous = true; + _has_categorical = false; + + for ( i = 0 ; i < n ; ++i ) + { + + if ( (_lb[i].is_defined() || _ub[i].is_defined() ) && _input_types[i] == NOMAD::CATEGORICAL && _out.get_gen_dd()>=NOMAD::NORMAL_DISPLAY && !_warning_has_been_displayed ) + { + _out << NOMAD::open_block("Warning:") + << "NOMAD::Signature::init(): Providing explicit bounds for categorical variables is irrelevant. Bounds are provided implicitely by the neighbors function." << std::endl + << NOMAD::close_block(); + _warning_has_been_displayed=true; + } + + if ( _fixed_variables[i].is_defined() && ((_lb[i].is_defined() && _fixed_variables[i] < _lb[i]) || (_ub[i].is_defined() && _fixed_variables[i] > _ub[i]) || + ( (_input_types[i] == NOMAD::INTEGER || _input_types[i] == NOMAD::CATEGORICAL ) + && !_fixed_variables[i].is_integer() ) || + ( _input_types[i] == NOMAD::BINARY && !_fixed_variables[i].is_binary() ) ) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: fixed variable inconsistent with bounds or input types" ); + + if ( _lb[i].is_defined() && _ub[i].is_defined() ) + { + if ( _lb[i].is_defined() && _ub[i].is_defined() && _lb[i].value()> ub[i].value() ) + { + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): bad argument: lower bound must be lower than upper bound!" ); + } + if ( _lb[i] == _ub[i] ) + _fixed_variables[i]=_lb[i]; + } + } + for ( i = 0 ; i < n ; ++i ) + { + if ( _input_types[i] == NOMAD::CATEGORICAL ) + { + _has_categorical = true; + _all_continuous = false; + break; + } + if ( _input_types[i] != NOMAD::CONTINUOUS ) + { + _all_continuous = false; + if ( _has_categorical ) + break; + } + + + } + + // variable groups: + reset_var_groups(); + + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp>::iterator end = var_groups.end() , it; - bool mod=false; - for ( it = var_groups.begin() ; it != end ; ++it ) - { - - if ( !(*it)->check ( _fixed_variables , input_types , NULL, mod ) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): incompatible variable group" ); - } - - if (mod) - { - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> tmp_var_groups; - for ( it = var_groups.begin() ; it != end ; ++it ) - { - tmp_var_groups.insert(*it); - } - var_groups.clear(); - var_groups=tmp_var_groups; - tmp_var_groups.clear(); - - } - - for ( it = var_groups.begin() ; it != end ; ++it ) - _var_groups.push_back( new NOMAD::Variable_Group (**it) ); - - - // mesh: - if ( initial_mesh_size.size() != n || - (min_mesh_size.is_defined() && min_mesh_size.size() != n) || - (min_poll_size.is_defined() && min_poll_size.size() != n) ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::init(): mesh arguments with different sizes" ); - delete _mesh; - - try { - _mesh = new NOMAD::Mesh ( initial_mesh_size , min_mesh_size , min_poll_size ); - } - catch ( NOMAD::Exception & e ) - { - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , - *this , e.what() ); - } - + bool mod=false; + for ( it = var_groups.begin() ; it != end ; ++it ) + { + + + if ( !(*it)->check ( _fixed_variables , input_types , NULL, mod ) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): incompatible variable group" ); + + } + + // if the indices in var_groups have been modified than var_groups is reconstructed to ensure proper ordering + if ( mod ) + { + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> tmp_var_groups; + for ( it = var_groups.begin() ; it != end ; ++it ) + { + tmp_var_groups.insert(*it); + } + var_groups.clear(); + var_groups=tmp_var_groups; + tmp_var_groups.clear(); + + } + + for ( it = var_groups.begin() ; it != end ; ++it ) + _var_groups.push_back( new NOMAD::Variable_Group (**it) ); + + // mesh: + if ( _mesh->get_initial_poll_size().size() != n || + ( _mesh->get_min_mesh_size().is_defined() && _mesh->get_min_mesh_size().size() != n) || + ( _mesh->get_min_poll_size().is_defined() && _mesh->get_min_poll_size().size() != n) ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::init(): mesh arguments with different sizes" ); + + + } /*--------------------------------------------------*/ /* Access to the number of categorical variables */ /*--------------------------------------------------*/ int NOMAD::Signature::get_n_categorical ( void ) const -{ - int n_cat=0; - for (int i = 0 ; i < get_n() ; ++i ) { - if ( _input_types[i] == NOMAD::CATEGORICAL ) - n_cat++; - } - - return n_cat; +{ + int n_cat=0; + for (int i = 0 ; i < get_n() ; ++i ) + if ( _input_types[i] == NOMAD::CATEGORICAL ) + n_cat++; + + return n_cat; +} + +/*--------------------------------------------------*/ +/* Access to the number of categorical variables */ +/*--------------------------------------------------*/ +int NOMAD::Signature::get_nb_fixed_variables ( void ) const +{ + int n_fixed=0; + for (int i = 0 ; i < get_n() ; ++i ) + if ( _fixed_variables[i].is_defined() ) + n_fixed++; + + return n_fixed; } - @@ -461,29 +498,24 @@ int NOMAD::Signature::get_n_categorical ( void ) const /*--------------------------------------------------*/ void NOMAD::Signature::reset ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ) + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables , + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ) { - reset_var_groups(); - init ( n , - input_types , - initial_mesh_size , - min_mesh_size , - min_poll_size , - lb , - ub , - scaling , - fixed_variables , - periodic_variables , - var_groups ); + reset_mesh(); + reset_var_groups(); + init ( n , + input_types , + lb , + ub , + scaling , + fixed_variables , + periodic_variables , + var_groups ); } /*--------------------------------------------------*/ @@ -491,11 +523,11 @@ void NOMAD::Signature::reset /*--------------------------------------------------*/ void NOMAD::Signature::reset_var_groups ( void ) { - std::list<NOMAD::Variable_Group *>::const_iterator + std::list<NOMAD::Variable_Group *>::const_iterator end = _var_groups.end() , it; - for ( it = _var_groups.begin() ; it != end ; ++it ) - delete *it; - _var_groups.clear(); + for ( it = _var_groups.begin() ; it != end ; ++it ) + delete *it; + _var_groups.clear(); } /*----------------------------------------------------------*/ @@ -506,160 +538,167 @@ void NOMAD::Signature::reset_var_groups ( void ) /*----------------------------------------------------------*/ bool NOMAD::Signature::is_compatible ( const NOMAD::Point & x ) const { - if ( get_n() != x.size() || !_mesh || _var_groups.empty() ) - return false; - return true; + if ( get_n() != x.size() || _var_groups.empty() ) + return false; + return true; } /*-----------------------------------------------------*/ -/* compute the directions (they include delta_m) */ +/* compute the directions */ /*-----------------------------------------------------*/ -void NOMAD::Signature::get_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index ) +void NOMAD::Signature::get_directions ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::Point & poll_center ) { - - - NOMAD::Direction * pd; - int i; - std::list<NOMAD::Direction>::const_iterator it_dir , end_dir; - std::set<int>::const_iterator it_vi , end_vi; - - // get delta_m (mesh size parameter): - int n = get_n(); - NOMAD::Point delta_m (n); - NOMAD::Point delta_p (n); - _mesh->get_delta_m ( delta_m , mesh_index ); - _mesh->get_delta_p ( delta_p , mesh_index ); - - - // Reset dir_group_index. - // For each signature, a variable_group has a unique set of directions generated and a unique dir_group_index starting by zero (-1 if no dirs) - _dir_group_index=-1; - - // loop on variable groups: - std::list<NOMAD::Variable_Group*>::const_iterator end_vg = _var_groups.end() , it_vg; - for ( it_vg = _var_groups.begin() ; it_vg != end_vg ; ++it_vg ) - { - - const std::set<int> & var_indexes = (*it_vg)->get_var_indexes(); - - // get the directions for the current group of variables: - std::list<NOMAD::Direction> dirs_nc; - (*it_vg)->get_directions ( dirs_nc, - poll , - poll_center , - mesh_index , - _feas_success_dir , - _infeas_success_dir ); - - // scale with delta_m and resize the directions to size n; - // also round integer and binary variables: - end_dir = dirs_nc.end(); - if (static_cast<int>(dirs_nc.size())!=0) - ++_dir_group_index; - for ( it_dir = dirs_nc.begin() ; it_dir != end_dir ; ++it_dir ) - { - - dirs.push_back ( NOMAD::Direction ( n , 0.0 , it_dir->get_type(),_dir_group_index) ); - - pd = &(*(--dirs.end())); - - end_vi = var_indexes.end(); - i = 0; - for ( it_vi = var_indexes.begin() ; it_vi != end_vi ; ++it_vi ) { - - (*pd)[*it_vi] = delta_m[*it_vi] * (*it_dir)[i++]; - - // integer variables: - if ( _input_types[*it_vi] == NOMAD::INTEGER ) - { - if ( (*pd)[*it_vi] >= delta_p[*it_vi]/3.0 ) - (*pd)[*it_vi] = (*pd)[*it_vi].ceil(); - else if ( (*pd)[*it_vi] <= -delta_p[*it_vi]/3.0 ) - (*pd)[*it_vi] = (*pd)[*it_vi].floor(); - else - (*pd)[*it_vi] = (*pd)[*it_vi].round(); - } - - // binary variables: - else if ( _input_types[*it_vi] == NOMAD::BINARY ) { - if ( (*pd)[*it_vi] != 0.0 ) - (*pd)[*it_vi] = 1.0; - } - - // categorical variables: set direction=0: - else if ( _input_types[*it_vi] == NOMAD::CATEGORICAL ) - (*pd)[*it_vi] = 0.0; - } - } - } + + NOMAD::Direction * pd; + int i; + std::list<NOMAD::Direction>::const_iterator it_dir , end_dir; + std::set<int>::const_iterator it_vi , end_vi; + + int n = get_n(); + NOMAD::Point delta=_mesh->get_delta ( ); + NOMAD::Point Delta=_mesh->get_Delta ( ); + + + // Reset dir_group_index. + // For each signature, a variable_group has a unique set of directions generated and a unique dir_group_index starting by zero (-1 if no dirs) + _dir_group_index=-1; + + // loop on variable groups: + std::list<NOMAD::Variable_Group*>::const_iterator end_vg = _var_groups.end() , it_vg; + for ( it_vg = _var_groups.begin() ; it_vg != end_vg ; ++it_vg ) + { + + const std::set<int> & var_indexes = (*it_vg)->get_var_indexes(); + + // get the directions on a unit nc-sphere for the current group of variables: + std::list<NOMAD::Direction> dirs_nc; + (*it_vg)->get_directions ( dirs_nc , poll , *_mesh ); // _mesh of all directions + + + // scale with delta and resize the directions to size n; + // also round integer and binary variables: + end_dir = dirs_nc.end(); + if (static_cast<int>(dirs_nc.size())!=0) + ++_dir_group_index; + for ( it_dir = dirs_nc.begin() ; it_dir != end_dir ; ++it_dir ) + { + + dirs.push_back ( NOMAD::Direction ( n , 0.0 , it_dir->get_type(),_dir_group_index) ); + + pd = &(*(--dirs.end())); + + end_vi = var_indexes.end(); + i = 0; + + + for ( it_vi = var_indexes.begin() ; it_vi != end_vi ; ++it_vi ,++i) + { + // Scaling and projection on the mesh + (*pd)[*it_vi] = _mesh->scale_and_project(*it_vi,(*it_dir)[i]); + + // integer variables: + if ( _input_types[*it_vi] == NOMAD::INTEGER ) + { + if ( (*pd)[*it_vi] >= Delta[*it_vi]/3.0 ) + (*pd)[*it_vi] = (*pd)[*it_vi].ceil(); + else if ( (*pd)[*it_vi] <= -Delta[*it_vi]/3.0 ) + (*pd)[*it_vi] = (*pd)[*it_vi].floor(); + else + (*pd)[*it_vi] = (*pd)[*it_vi].round(); + } + + // binary variables: + else if ( _input_types[*it_vi] == NOMAD::BINARY ) + { + if ( (*pd)[*it_vi] != 0.0 ) + (*pd)[*it_vi] = 1.0; + } + + // categorical variables: set direction=0: + else if ( _input_types[*it_vi] == NOMAD::CATEGORICAL ) + (*pd)[*it_vi] = 0.0; + } + + } + } } /*----------------------------------------------------------------*/ /* get just one direction for a given mesh (used by VNS search) */ /*----------------------------------------------------------------*/ -void NOMAD::Signature::get_one_direction ( NOMAD::Direction & dir, - int mesh_index, - int halton_index ) const +void NOMAD::Signature::get_one_direction ( NOMAD::Direction & dir , int ell) const { - int i; - std::set<int>::const_iterator it_vi , end_vi; - - // get delta_m (mesh size parameter): - int n = get_n(); - NOMAD::Point delta_m (n); - _mesh->get_delta_m ( delta_m , mesh_index ); - NOMAD::Point delta_p (n); - _mesh->get_delta_p( delta_p , mesh_index ); - - dir.reset ( n , 0.0 ); - dir.set_type ( NOMAD::UNDEFINED_DIRECTION ); - - // loop on variable groups: - std::list<NOMAD::Variable_Group*>::const_iterator end_vg = _var_groups.end() , it_vg; - for ( it_vg = _var_groups.begin() ; it_vg != end_vg ; ++it_vg ) { - - const std::set<int> & var_indexes = (*it_vg)->get_var_indexes(); - - // get the direction for the current group of variables: - NOMAD::Direction dir_nc; - - if ( (*it_vg)->get_one_direction ( dir_nc , mesh_index , halton_index++ ) ) { - - // scale with delta_m and round integer and binary variables: - end_vi = var_indexes.end(); - i = 0; - for ( it_vi = var_indexes.begin() ; it_vi != end_vi ; ++it_vi ) { - - dir[*it_vi] = delta_m[*it_vi] * dir_nc[i++]; - - // integer variables: - if ( _input_types[*it_vi] == NOMAD::INTEGER ) { - if ( dir[*it_vi] >= delta_p[*it_vi]/3.0 ) - dir[*it_vi] = ceil ( dir[*it_vi].value() ); - else if ( dir [*it_vi] <= -delta_p[*it_vi]/3.0 ) - dir[*it_vi] = floor ( dir[*it_vi].value() ); - else - { - double x=dir[*it_vi].value(); - dir[*it_vi] = (x>0)? floor(x+0.5): ceil(x-0.5); - } - } - - // binary variables: - else if ( _input_types[*it_vi] == NOMAD::BINARY ) { - if ( dir[*it_vi] != 0.0 ) - dir[*it_vi] = 1.0; - } - - // categorical variables: set direction=0: - else if ( _input_types[*it_vi] == NOMAD::CATEGORICAL ) - dir[*it_vi] = 0.0; - } - } - } + int i; + std::set<int>::const_iterator it_vi , end_vi; + + // get delta_m (mesh size parameter): + int n = get_n(); + NOMAD::Point delta=_mesh->get_delta ( ); + NOMAD::Point Delta=_mesh->get_Delta ( ); + + dir.reset ( n , 0.0 ); + dir.set_type ( NOMAD::UNDEFINED_DIRECTION ); + + // The mesh indices are modified and must be reset properly once the one direction is obtained + const NOMAD::Point old_mesh_indices=_mesh->get_mesh_indices(); + NOMAD::Point modified_mesh_indices(n,NOMAD::Double(ell)); + _mesh->set_mesh_indices(modified_mesh_indices); + + // loop on variable groups: + std::list<NOMAD::Variable_Group*>::const_iterator end_vg = _var_groups.end() , it_vg; + for ( it_vg = _var_groups.begin() ; it_vg != end_vg ; ++it_vg ) + { + + const std::set<int> & var_indexes = (*it_vg)->get_var_indexes(); + + // get the direction for the current group of variables: + NOMAD::Direction dir_nc ( static_cast<int>(var_indexes.size()) , 0.0 , NOMAD::UNDEFINED_DIRECTION ); + + // get a direction on a unit nc-sphere + if ( (*it_vg)->get_one_direction ( dir_nc ) ) + { + + // scale with delta_m and round integer and binary variables: + end_vi = var_indexes.end(); + i = 0; + for ( it_vi = var_indexes.begin() ; it_vi != end_vi ; ++it_vi ) + { + + dir[*it_vi]=_mesh->scale_and_project(*it_vi,dir_nc[i++]); + + + // integer variables: + if ( _input_types[*it_vi] == NOMAD::INTEGER ) + { + if ( dir[*it_vi] >= Delta[*it_vi]/3.0 ) + dir[*it_vi] = ceil ( dir[*it_vi].value() ); + else if ( dir [*it_vi] <= -Delta[*it_vi]/3.0 ) + dir[*it_vi] = floor ( dir[*it_vi].value() ); + else + { + double x=dir[*it_vi].value(); + dir[*it_vi] = (x>0)? floor(x+0.5): ceil(x-0.5); + } + } + + // binary variables: + else if ( _input_types[*it_vi] == NOMAD::BINARY ) + { + if ( dir[*it_vi] != 0.0 ) + dir[*it_vi] = 1.0; + } + + // categorical variables: set direction=0: + else if ( _input_types[*it_vi] == NOMAD::CATEGORICAL ) + dir[*it_vi] = 0.0; + } + } + } + + // Reset the mesh indices to their previous values + _mesh->set_mesh_indices(old_mesh_indices); } /*----------------------------------*/ @@ -668,16 +707,17 @@ void NOMAD::Signature::get_one_direction ( NOMAD::Direction & dir, /*----------------------------------*/ void NOMAD::Signature::scale ( NOMAD::Point & x ) { - int n = get_n(); - if ( n != x.size() ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::scale(x): x.size() != signature.size()" ); - NOMAD::Double sci; - for ( int i = 0 ; i < n ; ++i ) { - sci = _scaling[i]; - if ( sci.is_defined() ) - x[i] *= sci; - } + int n = get_n(); + if ( n != x.size() ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::scale(x): x.size() != signature.size()" ); + NOMAD::Double sci; + for ( int i = 0 ; i < n ; ++i ) + { + sci = _scaling[i]; + if ( sci.is_defined() ) + x[i] *= sci; + } } /*----------------------------------*/ @@ -686,16 +726,17 @@ void NOMAD::Signature::scale ( NOMAD::Point & x ) /*----------------------------------*/ void NOMAD::Signature::unscale ( NOMAD::Point & x ) { - int n = get_n(); - if ( n != x.size() ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::unscale(x): x.size() != signature.size()" ); - NOMAD::Double sci; - for ( int i = 0 ; i < n ; ++i ) { - sci = _scaling[i]; - if ( sci.is_defined() ) - x[i] /= sci; - } + int n = get_n(); + if ( n != x.size() ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::unscale(x): x.size() != signature.size()" ); + NOMAD::Double sci; + for ( int i = 0 ; i < n ; ++i ) + { + sci = _scaling[i]; + if ( sci.is_defined() ) + x[i] /= sci; + } } /*-----------------------------------------------------------------------*/ @@ -708,36 +749,39 @@ void NOMAD::Signature::unscale ( NOMAD::Point & x ) /*-----------------------------------------------------------------------*/ bool NOMAD::Signature::snap_to_bounds ( NOMAD::Point & x , NOMAD::Direction * direction ) { - int n = get_n(); - if ( n != x.size() ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::snap_to_bounds(x): x.size() != signature.size()" ); - - bool modified = false; - bool no_periodic_var = _periodic_variables.empty(); - - for ( int i = 0 ; i < n ; ++i ) + int n = get_n(); + if ( n != x.size() ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::snap_to_bounds(x): x.size() != signature.size()" ); - if ( no_periodic_var || !_periodic_variables[i] ) { - - const NOMAD::Double & ubi = _ub[i]; - NOMAD::Double & xi = x[i]; - if ( ubi.is_defined() && xi > ubi ) { - if (direction) - (*direction)[i] += ubi - xi; - xi = ubi; - modified = true; - } - const NOMAD::Double & lbi = _lb[i]; - if ( lbi.is_defined() && xi < lbi ) { - if (direction) - (*direction)[i] += (lbi - xi); - xi = lbi; - modified = true; - } - } - - return modified; + bool modified = false; + bool no_periodic_var = _periodic_variables.empty(); + + for ( int i = 0 ; i < n ; ++i ) + + if ( no_periodic_var || !_periodic_variables[i] ) + { + + const NOMAD::Double & ubi = _ub[i]; + NOMAD::Double & xi = x[i]; + if ( ubi.is_defined() && xi > ubi ) + { + if (direction) + (*direction)[i] += ubi - xi; + xi = ubi; + modified = true; + } + const NOMAD::Double & lbi = _lb[i]; + if ( lbi.is_defined() && xi < lbi ) + { + if (direction) + (*direction)[i] += (lbi - xi); + xi = lbi; + modified = true; + } + } + + return modified; } /*--------------------------------------------------*/ @@ -745,62 +789,69 @@ bool NOMAD::Signature::snap_to_bounds ( NOMAD::Point & x , NOMAD::Direction * di /* returns true if x has been modified */ /*--------------------------------------------------*/ bool NOMAD::Signature::treat_periodic_variables ( NOMAD::Point & x , - const NOMAD::Direction * old_dir , - NOMAD::Direction *& new_dir ) + const NOMAD::Direction * old_dir , + NOMAD::Direction *& new_dir ) { - if ( _periodic_variables.empty() ) - return false; - - int n = get_n(); - if ( n != x.size() ) - throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , - "NOMAD::Signature::treat_periodic_variables(x): x.size() != signature.size()" ); - - new_dir = ( old_dir ) ? new NOMAD::Direction (*old_dir) : NULL; - - bool modified = false; - - for ( int i = 0 ; i < n ; ++i ) { - - NOMAD::bb_input_type bbit = _input_types[i]; + if ( _periodic_variables.empty() ) + return false; - if ( _periodic_variables[i] && !_fixed_variables[i].is_defined() && - ( bbit == NOMAD::CONTINUOUS || bbit == NOMAD::INTEGER ) ) { - - const NOMAD::Double & ubi = _ub[i]; - const NOMAD::Double & lbi = _lb[i]; - NOMAD::Double & xi = x[i]; - - bool chk = false; - - NOMAD::Double new_x = xi; - while ( new_x > ubi ) { - new_x += lbi - ubi; - chk = true; - } - - if ( !chk ) { - while ( new_x < lbi ) { - new_x += ubi - lbi; - chk = true; - } - } - - if ( chk ) { - - if ( bbit == NOMAD::INTEGER ) - new_x.round(); - - if (new_dir) - (*new_dir)[i] += new_x - xi; - - x[i] = new_x; - modified = true; - } + int n = get_n(); + if ( n != x.size() ) + throw NOMAD::Signature::Signature_Error ( "Signature.cpp" , __LINE__ , *this , + "NOMAD::Signature::treat_periodic_variables(x): x.size() != signature.size()" ); + + new_dir = ( old_dir ) ? new NOMAD::Direction (*old_dir) : NULL; + + bool modified = false; + + for ( int i = 0 ; i < n ; ++i ) + { + + NOMAD::bb_input_type bbit = _input_types[i]; + + + if ( _periodic_variables[i] && !_fixed_variables[i].is_defined() && + ( bbit == NOMAD::CONTINUOUS || bbit == NOMAD::INTEGER ) ) + { + + const NOMAD::Double & ubi = _ub[i]; + const NOMAD::Double & lbi = _lb[i]; + NOMAD::Double & xi = x[i]; + + bool chk = false; + + NOMAD::Double new_x = xi; + while ( new_x > ubi ) + { + new_x += lbi - ubi; + chk = true; + } + + if ( !chk ) + { + while ( new_x < lbi ) + { + new_x += ubi - lbi; + chk = true; + } + } + + if ( chk ) + { + + if ( bbit == NOMAD::INTEGER ) + new_x.round(); + + if (new_dir) + (*new_dir)[i] += new_x - xi; + + x[i] = new_x; + modified = true; + } + } } - } - - return modified; + + return modified; } /*--------------------------------------------------*/ @@ -808,84 +859,90 @@ bool NOMAD::Signature::treat_periodic_variables ( NOMAD::Point & x /*--------------------------------------------------*/ void NOMAD::Signature::display ( const NOMAD::Display & out ) const { - if ( _std ) - out << "(standard signature)" << std::endl; - - // dimension: - out << "n : " << get_n() << std::endl; - - // bounds: - out << "lb : "; - if ( _lb.is_defined() ) - out << "( " << _lb << ")"; - else - out << "none"; - out << std::endl; - out << "ub : "; - if ( _ub.is_defined() ) - out << "( " << _ub << ")"; - else - out << "none"; - out << std::endl; - - // scaling: - out << "scaling : "; - if ( _scaling.is_defined() ) - out << "( " << _scaling << ")"; - else - out << "none"; - out << std::endl; - - // fixed variables: - out << "fixed variables : "; - if ( _fixed_variables.is_defined() ) - out << "( " << _fixed_variables << ")"; - else - out << "none"; - out << std::endl; - - // input types: - out << "input types : (" << _input_types << " )" << std::endl; - - // periodic variables: - out << "periodic variables: "; - if ( _periodic_variables.empty() ) - out << "none" << std::endl; - else { - size_t pvs = _periodic_variables.size(); - out << "{"; - for ( size_t k = 0 ; k < pvs ; ++k ) - out << _periodic_variables[k] << " "; - out << "}" << std::endl; - } - - // success directions: - out << "feas. succ. dir. : "; - if ( _feas_success_dir.is_defined() ) - out << _feas_success_dir << std::endl; - else - out << "none"; - out << std::endl - << "infeas. succ. dir.: "; - if ( _infeas_success_dir.is_defined() ) - out << _infeas_success_dir; - else - out << "none"; - out << std::endl; - - // variable groups: - out << NOMAD::open_block ( "variable groups" ); - int i = 0; - std::list<NOMAD::Variable_Group *>::const_iterator end = _var_groups.end() , it; - for ( it = _var_groups.begin() ; it != end ; ++it ) { - out << NOMAD::open_block ( "group #" + NOMAD::itos(i++) ) - << **it << NOMAD::close_block(); - } - out.close_block(); - - // mesh: - out << NOMAD::open_block ( "mesh" ) << *_mesh - << NOMAD::close_block(); + if ( _std ) + out << "(standard signature)" << std::endl; + + // dimension: + out << "n : " << get_n() << std::endl; + + // bounds: + out << "lb : "; + if ( _lb.is_defined() ) + out << "( " << _lb << ")"; + else + out << "none"; + out << std::endl; + out << "ub : "; + if ( _ub.is_defined() ) + out << "( " << _ub << ")"; + else + out << "none"; + out << std::endl; + + // scaling: + out << "scaling : "; + if ( _scaling.is_defined() ) + out << "( " << _scaling << ")"; + else + out << "none"; + out << std::endl; + + // fixed variables: + out << "fixed variables : "; + if ( _fixed_variables.is_defined() ) + out << "( " << _fixed_variables << ")"; + else + out << "none"; + out << std::endl; + + // input types: + out << "input types : (" << _input_types << " )" << std::endl; + + // periodic variables: + out << "periodic variables: "; + if ( _periodic_variables.empty() ) + out << "none" << std::endl; + else + { + size_t pvs = _periodic_variables.size(); + out << "{"; + for ( size_t k = 0 ; k < pvs ; ++k ) + out << _periodic_variables[k] << " "; + out << "}" << std::endl; + } + + // success directions: + out << "feas. succ. dir. : "; + if ( _feas_success_dir.is_defined() ) + out << _feas_success_dir << std::endl; + else + out << "none"; + out << std::endl + << "infeas. succ. dir.: "; + if ( _infeas_success_dir.is_defined() ) + out << _infeas_success_dir; + else + out << "none"; + out << std::endl; + + // variable groups: + out << NOMAD::open_block ( "variable groups" ); + int i = 0; + std::list<NOMAD::Variable_Group *>::const_iterator end = _var_groups.end() , it; + for ( it = _var_groups.begin() ; it != end ; ++it ) + { + out << NOMAD::open_block ( "group #" + NOMAD::itos(i++) ) + << **it << NOMAD::close_block(); + } + out.close_block(); + + // mesh: + out << NOMAD::open_block ( "mesh" ) ; + out << "initial poll size: ( " << _mesh->get_initial_poll_size() << " )" << std::endl; + out << "initial mesh size: ( " << _mesh->get_initial_mesh_size() << " )" << std::endl; + out << "minimum mesh size: ( " << _mesh->get_min_mesh_size() << " )" << std::endl; + out << "minimum poll size: ( " << _mesh->get_min_poll_size() << " )" << std::endl; + out << NOMAD::close_block(); } /*-------------------------------------------*/ @@ -895,138 +952,141 @@ void NOMAD::Signature::display ( const NOMAD::Display & out ) const /*-------------------------------------------*/ bool NOMAD::Signature::operator < ( const NOMAD::Signature & s ) const { - if ( this == &s ) - return false; - - // standard signature: not checked: standard and non-standard signatures can be == - // ( this is tested in Parameters::check() ) - - // dimension: - // ---------- - int n = _lb.size(); - int sn = s._lb.size(); - - if ( n < sn ) - return true; - if ( sn < n ) - return false; - - // variable groups: - // ---------------- - int nvg1 = _var_groups.size(); - int nvg2 = s._var_groups.size(); - if ( nvg1 != nvg2 ) - return (nvg1 < nvg2); - - std::list<NOMAD::Variable_Group*>::const_iterator + if ( this == &s ) + return false; + + // standard signature: not checked: standard and non-standard signatures can be == + // ( this is tested in Parameters::check() ) + + // dimension: + // ---------- + int n = static_cast<int>(_lb.size()); + int sn = static_cast<int>(s._lb.size()); + + if ( n < sn ) + return true; + if ( sn < n ) + return false; + + // variable groups: + // ---------------- + size_t nvg1 = _var_groups.size(); + size_t nvg2 = s._var_groups.size(); + if ( nvg1 != nvg2 ) + return (nvg1 < nvg2); + + std::list<NOMAD::Variable_Group*>::const_iterator it1 = _var_groups.begin() , it2 = s._var_groups.begin() , end = _var_groups.end(); - - while ( it1 != end ) { - if ( **it1 < **it2 ) - return true; - if ( **it2 < **it1 ) - return false; - ++it1; - ++it2; - } - - // first check on the periodic variables: - // -------------------------------------- - bool p1_empty = _periodic_variables.empty(); - bool p2_empty = s._periodic_variables.empty(); - if ( p1_empty != p2_empty ) - return p1_empty; - - // first check on the mesh: - // ------------------------ - const NOMAD::Point & delta_m_0 = _mesh->get_initial_mesh_size(); - const NOMAD::Point & delta_m_min = _mesh->get_min_mesh_size(); - const NOMAD::Point & delta_p_min = _mesh->get_min_poll_size(); - bool chkm = delta_m_min.is_defined(); - bool chkp = delta_p_min.is_defined(); - - const NOMAD::Point & s_delta_m_0 = s._mesh->get_initial_mesh_size(); - const NOMAD::Point & s_delta_m_min = s._mesh->get_min_mesh_size(); - const NOMAD::Point & s_delta_p_min = s._mesh->get_min_poll_size(); - bool s_chkm = s_delta_m_min.is_defined(); - bool s_chkp = s_delta_p_min.is_defined(); - - if ( _mesh != s._mesh ) { - if ( chkm != s_chkm ) - return !chkm; - if ( chkp != s_chkp ) - return !chkp; - } - - /*---------------------------*/ - /* loop on all coordinates */ - /*---------------------------*/ - for ( int i = 0 ; i < n ; ++i ) { - // input types: - // ------------ - if ( _input_types[i] < s._input_types[i] ) - return true; - if ( s._input_types[i] < _input_types[i] ) - return false; + while ( it1 != end ) + { + if ( **it1 < **it2 ) + return true; + if ( **it2 < **it1 ) + return false; + ++it1; + ++it2; + } - // bounds: - // ------- - if ( _lb[i].comp_with_undef ( s._lb[i] ) ) - return true; - if ( s._lb[i].comp_with_undef ( _lb[i] ) ) - return false; - if ( _ub[i].comp_with_undef ( s._ub[i] ) ) - return true; - if ( s._ub[i].comp_with_undef ( _ub[i] ) ) - return false; - - // scaling: - // -------- - if ( _scaling[i].comp_with_undef ( s._scaling[i] ) ) - return true; - if ( s._scaling[i].comp_with_undef ( _scaling[i] ) ) - return false; - - // fixed variables: - // ---------------- - if ( _fixed_variables[i].comp_with_undef ( s._fixed_variables[i] ) ) - return true; - if ( s._fixed_variables[i].comp_with_undef ( _fixed_variables[i] ) ) - return false; - - // periodic variables: - // ------------------- - if ( !p1_empty && _periodic_variables[i] != s._periodic_variables[i] ) - return _periodic_variables[i]; - - // mesh: - // ----- - if ( _mesh != s._mesh ) - { - if ( delta_m_0[i].comp_with_undef ( s_delta_m_0[i] ) ) - return true; - if ( s_delta_m_0[i].comp_with_undef ( delta_m_0[i] ) ) - return false; - if ( chkm ) - { - if ( delta_m_min[i].comp_with_undef ( s_delta_m_min[i] ) ) - return true; - if ( s_delta_m_min[i].comp_with_undef ( delta_m_min[i] ) ) - return false; - } - if ( chkp ) - { - if ( delta_p_min[i].comp_with_undef ( s_delta_p_min[i] ) ) - return true; - if ( s_delta_p_min[i].comp_with_undef ( delta_p_min[i] ) ) - return false; - } + // first check on the periodic variables: + // -------------------------------------- + bool p1_empty = _periodic_variables.empty(); + bool p2_empty = s._periodic_variables.empty(); + if ( p1_empty != p2_empty ) + return p1_empty; + + // first check on the mesh: + // ------------------------ + bool chkm = _mesh->get_min_mesh_size().is_defined(); + bool chkp = _mesh->get_min_poll_size().is_defined(); + + bool s_chkm = s._mesh->get_min_mesh_size().is_defined(); + bool s_chkp = s._mesh->get_min_poll_size().is_defined(); + + if ( _mesh->get_initial_mesh_size() != s._mesh->get_initial_mesh_size() && + _mesh->get_min_mesh_size() != s._mesh->get_min_mesh_size() && + _mesh->get_min_poll_size() != s._mesh->get_min_poll_size() ) + { + if ( chkm != s_chkm ) + return !chkm; + if ( chkp != s_chkp ) + return !chkp; } - } - - // both signatures are equal: - return false; + + /*---------------------------*/ + /* loop on all coordinates */ + /*---------------------------*/ + for ( int i = 0 ; i < n ; ++i ) + { + + // input types: + // ------------ + if ( _input_types[i] < s._input_types[i] ) + return true; + if ( s._input_types[i] < _input_types[i] ) + return false; + + // bounds: + // ------- + if ( _lb[i].comp_with_undef ( s._lb[i] ) ) + return true; + if ( s._lb[i].comp_with_undef ( _lb[i] ) ) + return false; + if ( _ub[i].comp_with_undef ( s._ub[i] ) ) + return true; + if ( s._ub[i].comp_with_undef ( _ub[i] ) ) + return false; + + // scaling: + // -------- + if ( _scaling[i].comp_with_undef ( s._scaling[i] ) ) + return true; + if ( s._scaling[i].comp_with_undef ( _scaling[i] ) ) + return false; + + // fixed variables: + // ---------------- + if ( _fixed_variables[i].comp_with_undef ( s._fixed_variables[i] ) ) + return true; + if ( s._fixed_variables[i].comp_with_undef ( _fixed_variables[i] ) ) + return false; + + // periodic variables: + // ------------------- + if ( !p1_empty && _periodic_variables[i] != s._periodic_variables[i] ) + return _periodic_variables[i]; + + // mesh: + // ----- + if ( _mesh->get_initial_mesh_size() != s._mesh->get_initial_mesh_size() && + _mesh->get_min_mesh_size() != s._mesh->get_min_mesh_size() && + _mesh->get_min_poll_size() != s._mesh->get_min_poll_size() ) + { + if ( _mesh->get_initial_mesh_size()[i].comp_with_undef ( s._mesh->get_initial_mesh_size()[i] ) ) + return true; + if ( s._mesh->get_initial_mesh_size()[i].comp_with_undef ( _mesh->get_initial_mesh_size()[i] ) ) + return false; + + + if ( chkm ) + { + if ( _mesh->get_min_mesh_size()[i].comp_with_undef ( s._mesh->get_min_mesh_size()[i] ) ) + return true; + if ( s._mesh->get_min_mesh_size()[i].comp_with_undef ( _mesh->get_min_mesh_size()[i] ) ) + return false; + } + if ( chkp ) + { + if ( _mesh->get_min_poll_size()[i].comp_with_undef ( s._mesh->get_min_poll_size()[i] ) ) + return true; + if ( s._mesh->get_min_poll_size()[i].comp_with_undef ( _mesh->get_min_poll_size()[i] ) ) + return false; + } + } + } + + // both signatures are equal: + return false; } diff --git a/src/Signature.hpp b/src/Signature.hpp index 3eb9f9514d0b81b7f6334f2e7ffc8e0cfd78cef3..44dcd320b3df51769aad0f7459535c9d4f751f13 100644 --- a/src/Signature.hpp +++ b/src/Signature.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,489 +34,519 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Signature.hpp - \brief Evaluation point signature (headers) - \author Sebastien Le Digabel - \date 2010-04-22 - \see Signature.cpp -*/ + \file Signature.hpp + \brief Evaluation point signature (headers) + \author Sebastien Le Digabel + \date 2010-04-22 + \see Signature.cpp + */ #ifndef __SIGNATURE__ #define __SIGNATURE__ #include "Variable_Group.hpp" namespace NOMAD { - - /// Evaluation point signature. - class Signature { - - private: + /// Evaluation point signature. + class Signature { + + private: + #ifdef MEMORY_DEBUG - static int _cardinality; ///< Number of NOMAD::Signature objects in memory. - static int _max_cardinality; ///< Max number of NOMAD::Signature objects in memory. + static int _cardinality; ///< Number of NOMAD::Signature objects in memory. + static int _max_cardinality; ///< Max number of NOMAD::Signature objects in memory. #endif - - NOMAD::Point _lb; ///< Lower bounds. - NOMAD::Point _ub; ///< Upper bounds. - NOMAD::Point _scaling; ///< Scaling. - NOMAD::Point _fixed_variables; ///< Fixed variables. - - std::vector<NOMAD::bb_input_type> _input_types; ///< Input types. - - bool _all_continuous; ///< Flag equal to \c true if all variables are continuous. - bool _has_categorical; ///< Flag equal to \c true if there are categorical variables. - - static bool _warning_has_been_displayed; ///< Flag equal to \c true if the warning has already been displayed - - std::vector<bool> _periodic_variables; ///< Periodic variables. - - /// Groups of variables. - /** - Include the directions/ - */ - std::list<NOMAD::Variable_Group*> _var_groups; - - /// Mesh associated to this signature. - NOMAD::Mesh * _mesh; - - /** - Flag equal to \c true if the signature is standard - (i.e created in Parameters class). - */ - bool _std; - - // Feasible successful direction. - /** - Mutable since it is not used in - \c operator \c < and have to be often changed. - */ - mutable NOMAD::Direction _feas_success_dir; - - // Infeasible successful direction. - /** - Mutable since it is not used in - \c operator \c < and have to be often changed. - */ - mutable NOMAD::Direction _infeas_success_dir; - - // Direction group index - int _dir_group_index; - - // Display - NOMAD::Display _out; - - /*---------------------------------------------------------------------------*/ - - /// Initializations. - /** - \param n Number of variables -- \b IN. - \param input_types Types of the variables -- \b IN. - \param initial_mesh_size Initial mesh size -- \b IN. - \param min_mesh_size Minimum mesh size -- \b IN. - \param min_poll_size Minimum poll size -- \b IN. - \param lb Lower bounds -- \b IN. - \param ub Upper bounds -- \b IN. - \param scaling Scaling -- \b IN. - \param fixed_variables Fixed variables -- \b IN. - \param periodic_variables Periodic variables -- \b IN. - \param var_groups Groups of variables -- \b IN. - */ - void init - ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ); - - /// Reset groups of variables. - void reset_var_groups ( void ); - - /// Clear. - /** - Private method called by the destructor and after an exception is thrown. - */ - void clear ( void ); - - /// Affectation operator. - /** - \param s The right-hand side object. - */ - const Signature & operator = ( const Signature & s ); - - public: - - /*---------------------------------------------------------------------------*/ - - /// Exception class for an invalid signature. - class Signature_Error : public NOMAD::Exception { + + NOMAD::Point _lb; ///< Lower bounds. + NOMAD::Point _ub; ///< Upper bounds. + NOMAD::Point _scaling; ///< Scaling. + NOMAD::Point _fixed_variables; ///< Fixed variables. + + std::vector<NOMAD::bb_input_type> _input_types; ///< Input types. + + bool _all_continuous; ///< Flag equal to \c true if all variables are continuous. + bool _has_categorical; ///< Flag equal to \c true if there are categorical variables. + + static bool _warning_has_been_displayed; ///< Flag equal to \c true if the warning has already been displayed + + std::vector<bool> _periodic_variables; ///< Periodic variables. + + /// Groups of variables. + /** + Include the directions/ + */ + std::list<NOMAD::Variable_Group*> _var_groups; + + /// Mesh associated to this signature. + NOMAD::OrthogonalMesh *_mesh; ///< Orthogonal mesh + + /** + Flag equal to \c true if the signature is standard + (i.e created in Parameters class). + */ + bool _std; + + // Feasible successful direction. + /** + Mutable since it is not used in + \c operator \c < and have to be often changed. + */ + mutable NOMAD::Direction _feas_success_dir; + + // Infeasible successful direction. + /** + Mutable since it is not used in + \c operator \c < and have to be often changed. + */ + mutable NOMAD::Direction _infeas_success_dir; + + + // Direction group index + int _dir_group_index; + + // Display + NOMAD::Display _out; + + /*---------------------------------------------------------------------------*/ + + /// Initializations. + /** + \param n Number of variables -- \b IN. + \param input_types Types of the variables -- \b IN. + \param lb Lower bounds -- \b IN. + \param ub Upper bounds -- \b IN. + \param scaling Scaling -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + \param periodic_variables Periodic variables -- \b IN. + \param var_groups Groups of variables -- \b IN. + */ + void init + ( int n , + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables , + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ); + + /// Reset groups of variables. + void reset_var_groups ( void ); + + /// Clear. + /** + Private method called by the destructor and after an exception is thrown. + */ + void clear ( void ); + + /// Affectation operator. + /** + \param s The right-hand side object. + */ + const Signature & operator = ( const Signature & s ); + public: - /// Constructor. - Signature_Error ( const std::string & file , - int line , - Signature & s , - const std::string & msg ) - : NOMAD::Exception ( file , line , msg ) { s.clear(); } - }; - - /*---------------------------------------------------------------------------*/ - - /// Constructor #1. - /** - Advanced version. - \param n Number of variables -- \b IN. - \param input_types Types of the variables -- \b IN. - \param initial_mesh_size Initial mesh size -- \b IN. - \param min_mesh_size Minimum mesh size -- \b IN. - \param min_poll_size Minimum poll size -- \b IN. - \param lb Lower bounds -- \b IN. - \param ub Upper bounds -- \b IN. - \param scaling Scaling -- \b IN. - \param fixed_variables Fixed variables -- \b IN. - \param periodic_variables Periodic variables -- \b IN. - \param var_groups Groups of variables -- \b IN. - \param out Display -- \b IN. - */ - Signature - ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups , - const NOMAD::Display & out=NOMAD::Display() - ); - - /// Constructor #2. - /** - Basic version that will automatically construct groups of variables. - \param n Number of variables -- \b IN. - \param input_types Types of the variables -- \b IN. - \param initial_mesh_size Initial mesh size -- \b IN. - \param lb Lower bounds -- \b IN. - \param ub Upper bounds -- \b IN. - \param direction_types Types of directions -- \b IN. - \param sec_poll_dir_types Types of directions for secondary poll -- \b IN. - \param halton_seed Halton seed -- \b IN. - \param out Display -- \b IN. - */ - Signature ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed , - const NOMAD::Display & out = NOMAD::Display() - ); - - /// Copy constructor. - /** - \param s The copied object. - */ - Signature ( const Signature & s ); - - /// Destructor. - virtual ~Signature ( void ); - - /// Reset. - /** - \param n Number of variables -- \b IN. - \param input_types Types of the variables -- \b IN. - \param initial_mesh_size Initial mesh size -- \b IN. - \param min_mesh_size Minimum mesh size -- \b IN. - \param min_poll_size Minimum poll size -- \b IN. - \param lb Lower bounds -- \b IN. - \param ub Upper bounds -- \b IN. - \param scaling Scaling -- \b IN. - \param fixed_variables Fixed variables -- \b IN. - \param periodic_variables Periodic variables -- \b IN. - \param var_groups Groups of variables -- \b IN. - */ - void reset - ( int n , - const std::vector<NOMAD::bb_input_type> & input_types , - const NOMAD::Point & initial_mesh_size , - const NOMAD::Point & min_mesh_size , - const NOMAD::Point & min_poll_size , - const NOMAD::Point & lb , - const NOMAD::Point & ub , - const NOMAD::Point & scaling , - const NOMAD::Point & fixed_variables , - const std::vector<bool> & periodic_variables , - std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ); - - /// Define a signature to be standard. - void set_std ( void ) { _std = true; } - - /// Set a feasible successful direction. - /** - \param dir The direction -- \b IN. - */ - void set_feas_success_dir ( const NOMAD::Direction & dir ); - - /// Set an infeasible successful direction. - /** - \param dir The direction -- \b IN. - */ - void set_infeas_success_dir ( const NOMAD::Direction & dir ); - - /// Reset the feasible successful direction. - void reset_feas_success_dir ( void ) const { _feas_success_dir.clear(); } - - /// Reset the infeasible successful direction. - void reset_infeas_success_dir ( void ) const { _infeas_success_dir.clear(); } - - /// Scaling. - /** - Performed before an evaluation. - \param x The scaled point -- \b IN/OUT. - */ - void scale ( NOMAD::Point & x ); - - /// Unscaling. - /** - Performed after an evaluation. - \param x The unscaled point -- \b IN/OUT. - */ - void unscale ( NOMAD::Point & x ); - - /// Snap to bounds. - /** - - Supposes that \c this->treat_periodic_variables() has already been invoked. - - If periodic variables have been treated, then bounds are + + /*---------------------------------------------------------------------------*/ + + /// Exception class for an invalid signature. + class Signature_Error : public NOMAD::Exception { + public: + /// Constructor. + Signature_Error ( const std::string & file , + int line , + Signature & s , + const std::string & msg ) + : NOMAD::Exception ( file , line , msg ) { s.clear(); } + }; + + /*---------------------------------------------------------------------------*/ + + /// Constructor #1. + /** + Advanced version. + \param n Number of variables -- \b IN. + \param input_types Types of the variables -- \b IN. + \param use_smesh Type of mesh (SMesh, XMesh) -- \b IN. + \param anisotropic_mesh Anisotropy of mesh (XMesh) -- \b IN. + \param initial_poll_size Initial poll size -- \b IN. + \param min_poll_size Minimum poll size -- \b IN. + \param min_mesh_size Minimim mesh size -- \b IN. + \param mesh_update_basis Mesh update basis -- \b IN. + \param poll_update_basis Poll update basis -- \b IN. + \param mesh_coarsening_exponent Mesh coarsening exponent -- \b IN. + \param mesh_refining_exponent Mesh refining exponent -- \b IN. + \param initial_mesh_index Initial mesh index -- \b IN. + \param lb Lower bounds -- \b IN. + \param ub Upper bounds -- \b IN. + \param scaling Scaling -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + \param periodic_variables Periodic variables -- \b IN. + \param var_groups Groups of variables -- \b IN. + \param out Display -- \b IN. + */ + Signature + ( int n , + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + bool use_smesh , + bool anisotropic_mesh , + const NOMAD::Point & initial_poll_size , + const NOMAD::Point & min_poll_size , + const NOMAD::Point & min_mesh_size , + NOMAD::Double & mesh_update_basis , + NOMAD::Double & poll_update_basis , + int & mesh_coarsening_exponent, + int & mesh_refining_exponent, + int initial_mesh_index , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables, + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups , + const NOMAD::Display & out=NOMAD::Display() + ); + + /// Constructor #2. + /** + Basic version that will automatically construct groups of variables. + \param n Number of variables -- \b IN. + \param input_types Types of the variables -- \b IN. + \param initial_poll_size Initial poll size -- \b IN. + \param lb Lower bounds -- \b IN. + \param ub Upper bounds -- \b IN. + \param direction_types Types of directions -- \b IN. + \param sec_poll_dir_types Types of directions for secondary poll -- \b IN. + \param out Display -- \b IN. + */ + Signature ( int n , + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & initial_poll_size , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const std::set<NOMAD::direction_type> & direction_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types , + const NOMAD::Display & out = NOMAD::Display() + ); + + /// Copy constructor. + /** + \param s The copied object. + */ + Signature ( const Signature & s ); + + /// Destructor. + virtual ~Signature ( void ); + + /// Reset. + /** + \param n Number of variables -- \b IN. + \param input_types Types of the variables -- \b IN. + \param lb Lower bounds -- \b IN. + \param ub Upper bounds -- \b IN. + \param scaling Scaling -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + \param periodic_variables Periodic variables -- \b IN. + \param var_groups Groups of variables -- \b IN. + */ + void reset + ( int n , + const std::vector<NOMAD::bb_input_type> & input_types , + const NOMAD::Point & lb , + const NOMAD::Point & ub , + const NOMAD::Point & scaling , + const NOMAD::Point & fixed_variables , + const std::vector<bool> & periodic_variables , + std::set<NOMAD::Variable_Group*,NOMAD::VG_Comp> & var_groups ); + + /// Define a signature to be standard. + void set_std ( void ) { _std = true; } + + /// Set a feasible successful direction. + /** + \param dir The direction -- \b IN. + */ + void set_feas_success_dir ( const NOMAD::Direction & dir ); + + /// Set an infeasible successful direction. + /** + \param dir The direction -- \b IN. + */ + void set_infeas_success_dir ( const NOMAD::Direction & dir ); + + /// Reset the feasible successful direction. + void reset_feas_success_dir ( void ) const { _feas_success_dir.clear(); } + + /// Reset the infeasible successful direction. + void reset_infeas_success_dir ( void ) const { _infeas_success_dir.clear(); } + + /// Scaling. + /** + Performed before an evaluation. + \param x The scaled point -- \b IN/OUT. + */ + void scale ( NOMAD::Point & x ); + + /// Unscaling. + /** + Performed after an evaluation. + \param x The unscaled point -- \b IN/OUT. + */ + void unscale ( NOMAD::Point & x ); + + /// Snap to bounds. + /** + - Supposes that \c this->treat_periodic_variables() has already been invoked. + - If periodic variables have been treated, then bounds are satisfied and there is no need to snap anymore. - \param x The point to snap -- \b IN/OUT. - \param direction A pointer to the direction associated to this point - (may be \c NULL) -- \b IN/OUT. - \return A Boolean equal to \c true if \c x has been modified. - */ - bool snap_to_bounds ( NOMAD::Point & x , NOMAD::Direction * direction ); - - /// Treat the periodic variables. - /** - \param x The point to treat -- \b IN/OUT. - \param old_dir A pointer to the direction associated to this point - (before the treatment; may be \c NULL) -- \b IN. - \param new_dir A pointer to the direction associated to this point - (after the treatment; may be \c NULL) -- \b OUT. - \return A boolean equal to \c true if \c x has been modified. - */ - bool treat_periodic_variables ( NOMAD::Point & x , - const NOMAD::Direction * old_dir , - NOMAD::Direction *& new_dir ); - - /// Access to the lower bounds. - /** - \return The lower bounds. - */ - const NOMAD::Point & get_lb ( void ) const { return _lb; } - - /// Access to the upper bounds. - /** - \return The upper bounds. - */ - const NOMAD::Point & get_ub ( void ) const { return _ub; } - - /// Access to the scaling. - /** - \return The scaling. - */ - const NOMAD::Point & get_scaling ( void ) const { return _scaling; } - - /// Access to the fixed variables. - /** - \return The fixed variables. - */ - const NOMAD::Point & get_fixed_variables ( void ) const { return _fixed_variables; } - - /// Access to the feasible successful direction. - /** - \return The feasible successful direction - (may be undefined). - */ - const NOMAD::Direction & get_feas_success_dir ( void ) const - { - return _feas_success_dir; - } - - /// Access to the infeasible successful direction. - /** - \return The infeasible successful direction - (may be undefined). - */ - const NOMAD::Direction & get_infeas_success_dir ( void ) const - { - return _infeas_success_dir; - } - - /// Access to the periodic variables. - /** - \return The periodic variables. - */ - const std::vector<bool> & get_periodic_variables ( void ) const - { - return _periodic_variables; - } - - /// Check if all variables are continuous. - /** - \return A boolean equal to \c true if all variables are continuous. - */ - bool all_continuous ( void ) const { return _all_continuous; } - - /// Check if there are categorical variables. - /** - \return A boolean equal to \c true if there are categorical variables. - */ - bool has_categorical ( void ) const { return _has_categorical; } - - /// Access to the number of categorical variables. - /** - \return Integer equal to the number of categorical variables. - */ - int get_n_categorical ( void ) const ; - - /// Access to the number of variables. - /** - \return The number of variables. - */ - int get_n ( void ) const { return static_cast<int> ( _input_types.size() ); } - - /// Access to the input types. - /** - \return The input types. - */ - const std::vector<NOMAD::bb_input_type> & get_input_types ( void ) const - { - return _input_types; - } - - /// Access to the input types. - /** - \return The input types. - */ - const std::vector<NOMAD::bb_input_type> & get_input_type ( void ) const - { - return _input_types; - } - - /// Access to the groups of variables. - /** - \return The groups of variables. - */ - const std::list<NOMAD::Variable_Group*> & get_var_groups ( void ) const - { - return _var_groups; - } - - /// Access to the mesh. - /** - \return A pointer to the mesh. - */ - const NOMAD::Mesh & get_mesh ( void ) const { return *_mesh; } - - /// Check the compatibility of a point. - /** - - Only the number of variables is checked. - - Other criteria (fixed variables, binary variables,...) + \param x The point to snap -- \b IN/OUT. + \param direction A pointer to the direction associated to this point + (may be \c NULL) -- \b IN/OUT. + \return A Boolean equal to \c true if \c x has been modified. + */ + bool snap_to_bounds ( NOMAD::Point & x , NOMAD::Direction * direction ); + + /// Treat the periodic variables. + /** + \param x The point to treat -- \b IN/OUT. + \param old_dir A pointer to the direction associated to this point + (before the treatment; may be \c NULL) -- \b IN. + \param new_dir A pointer to the direction associated to this point + (after the treatment; may be \c NULL) -- \b OUT. + \return A boolean equal to \c true if \c x has been modified. + */ + bool treat_periodic_variables ( NOMAD::Point & x , + const NOMAD::Direction * old_dir , + NOMAD::Direction *& new_dir ); + + /// Access to the lower bounds. + /** + \return The lower bounds. + */ + const NOMAD::Point & get_lb ( void ) const { return _lb; } + + /// Access to the upper bounds. + /** + \return The upper bounds. + */ + const NOMAD::Point & get_ub ( void ) const { return _ub; } + + /// Access to the mesh. + /** + \return The orthogonal mesh. + */ + NOMAD::OrthogonalMesh * get_mesh ( void ) const { return _mesh; } + + + /// Update the Mesh (poll and mesh sizes). + /** + \param success Type of success of the iteration -- \b IN. + \param dir Direction of the iteration (optional) -- \b IN. + */ + void update_mesh ( NOMAD::success_type success, const NOMAD::Direction * dir=NULL ) + { + _mesh->update ( success, dir ); + } + + /// Complete reset of the mesh. + /** + */ + void reset_mesh ( void ) { _mesh->reset(); } + + /// Reset of the mesh indices. + /** + /param mesh_indices + */ + void reset_mesh ( NOMAD::Point & mesh_indices ) { _mesh->set_mesh_indices( mesh_indices); } + + + /// Access to the scaling. + /** + \return The scaling. + */ + const NOMAD::Point & get_scaling ( void ) const { return _scaling; } + + /// Access to the fixed variables. + /** + \return The fixed variables. + */ + const NOMAD::Point & get_fixed_variables ( void ) const { return _fixed_variables; } + + + /// Access to the number of fixed variables. + /** + \return The number of fixed variables. + */ + int get_nb_fixed_variables ( void ) const; + + + + /// Access to the feasible successful direction. + /** + \return The feasible successful direction + (may be undefined). + */ + const NOMAD::Direction & get_feas_success_dir ( void ) const + { + return _feas_success_dir; + } + + /// Access to the infeasible successful direction. + /** + \return The infeasible successful direction + (may be undefined). + */ + const NOMAD::Direction & get_infeas_success_dir ( void ) const + { + return _infeas_success_dir; + } + + /// Access to the periodic variables. + /** + \return The periodic variables. + */ + const std::vector<bool> & get_periodic_variables ( void ) const + { + return _periodic_variables; + } + + /// Check if all variables are continuous. + /** + \return A boolean equal to \c true if all variables are continuous. + */ + bool all_continuous ( void ) const { return _all_continuous; } + + /// Check if there are categorical variables. + /** + \return A boolean equal to \c true if there are categorical variables. + */ + bool has_categorical ( void ) const { return _has_categorical; } + + /// Access to the number of categorical variables. + /** + \return Integer equal to the number of categorical variables. + */ + int get_n_categorical ( void ) const ; + + /// Access to the number of variables. + /** + \return The number of variables. + */ + int get_n ( void ) const { return static_cast<int> ( _input_types.size() ); } + + /// Access to the input types. + /** + \return The input types. + */ + const std::vector<NOMAD::bb_input_type> & get_input_types ( void ) const + { + return _input_types; + } + + /// Access to the input types. + /** + \return The input types. + */ + const std::vector<NOMAD::bb_input_type> & get_input_type ( void ) const + { + return _input_types; + } + + /// Access to the groups of variables. + /** + \return The groups of variables. + */ + const std::list<NOMAD::Variable_Group*> & get_var_groups ( void ) const + { + return _var_groups; + } + + + /// Check the compatibility of a point. + /** + - Only the number of variables is checked. + - Other criteria (fixed variables, binary variables,...) are checked by NOMAD::Eval_Point::check(). - \param x The point to check -- \b IN. - \return A boolean equal to \c true if the point is compatible - with the signature. - */ - bool is_compatible ( const NOMAD::Point & x ) const; - - /// Access to the directions. - /** - - The computed directions already include Delta^k_m. - \param dirs List of directions -- \b OUT. - \param poll Type of poll (primary or secondary) -- \b IN. - \param poll_center Poll center -- \b IN. - \param mesh_index Mesh index ell -- \b IN. - */ - void get_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index ); - - - /// Access to one direction for a given mesh. - /** - Used for example in the VNS search. - \param dir The direction -- \b OUT. - \param mesh_index Mesh index ell -- \b IN. - \param halton_index Halton index -- \b IN. - */ - void get_one_direction ( NOMAD::Direction & dir , - int mesh_index , - int halton_index ) const; - - - /// Comparison operator \c < . - /** - Successful directions are not considered. - \param s The right-hand side object -- \b IN. - \return A boolean equal to \c true if \c *this \c < \c s. - */ - bool operator < ( const Signature & s ) const; - - /// Comparison operator \c != . - /** - \param s The right-hand side object -- \b IN. - \return A boolean equal to \c true if \c *this \c != \c s. - */ - bool operator != ( const Signature & s ) const - { - return ( (*this < s) || (s < *this) ); - } - + \param x The point to check -- \b IN. + \return A boolean equal to \c true if the point is compatible + with the signature. + */ + bool is_compatible ( const NOMAD::Point & x ) const; + + /// Access to the directions. + /** + - The computed directions already include Delta^k_m. + \param dirs List of directions -- \b OUT. + \param poll Type of poll (primary or secondary) -- \b IN. + \param poll_center Poll center -- \b IN. + */ + void get_directions ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::Point & poll_center ); + + + /// Access to one direction for a given mesh. + /** + Used for example in the VNS search. + \param dir The direction -- \b OUT. + \param mesh_index Mesh index ell -- \b IN. + */ + void get_one_direction ( NOMAD::Direction & dir , + int mesh_index ) const; + + + /// Comparison operator \c < . + /** + Successful directions are not considered. + \param s The right-hand side object -- \b IN. + \return A boolean equal to \c true if \c *this \c < \c s. + */ + bool operator < ( const Signature & s ) const; + + /// Comparison operator \c != . + /** + \param s The right-hand side object -- \b IN. + \return A boolean equal to \c true if \c *this \c != \c s. + */ + bool operator != ( const Signature & s ) const + { + return ( (*this < s) || (s < *this) ); + } + #ifdef MEMORY_DEBUG - - /// Access to the number of NOMAD::Signature objects in memory. - /** - \return Number of NOMAD::Signature objects in memory. - */ - static int get_cardinality ( void ) { return Signature::_cardinality; } - - /// Access to the max number of NOMAD::Signature objects in memory. - /** - \return Max number of NOMAD::Signature objects in memory. - */ - static int get_max_cardinality ( void ) { return Signature::_max_cardinality; } + + /// Access to the number of NOMAD::Signature objects in memory. + /** + \return Number of NOMAD::Signature objects in memory. + */ + static int get_cardinality ( void ) { return Signature::_cardinality; } + + /// Access to the max number of NOMAD::Signature objects in memory. + /** + \return Max number of NOMAD::Signature objects in memory. + */ + static int get_max_cardinality ( void ) { return Signature::_max_cardinality; } #endif - - /// Display. + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + }; + + /// Display a NOMAD::Signature object. /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - - }; - - /// Display a NOMAD::Signature object. - /** \param out The NOMAD::Display object -- \b IN. \param s The NOMAD::Signature object to be displayed -- \b IN. \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Signature & s ) { - s.display ( out ); - return out; - } + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Signature & s ) { + s.display ( out ); + return out; + } } #endif diff --git a/src/Signature_Element.hpp b/src/Signature_Element.hpp index e9f0a5f4fd3d993b4f3147aaa3e664263648e6a2..fa0357d8b9709213ed1fc7c3c6ae83ae3928eee8 100644 --- a/src/Signature_Element.hpp +++ b/src/Signature_Element.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Single_Obj_Quad_Model_Evaluator.hpp b/src/Single_Obj_Quad_Model_Evaluator.hpp index e6c67822d5dd3033761061587b45fd68ad3bd439..7580717ad9f593d9449858103a180ee54c021757 100644 --- a/src/Single_Obj_Quad_Model_Evaluator.hpp +++ b/src/Single_Obj_Quad_Model_Evaluator.hpp @@ -1,8 +1,8 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version (3.5.1).7.2 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -38,7 +38,7 @@ \file Single_Obj_Quad_Model_Evaluator.hpp \brief NOMAD::Evaluator subclass for quadratic model optimization (headers) \author Christophe Tribes - \date 2012-06-19 + \date 2014-06-19 \see Single_Obj_Quad_Model_Evaluator.cpp */ #ifndef __SINGLE_OBJ_QUAD_MODEL_EVALUATOR__ @@ -60,11 +60,12 @@ namespace NOMAD { \param model Model -- \b IN. */ Single_Obj_Quad_Model_Evaluator ( const NOMAD::Parameters & p , - const NOMAD::Quad_Model & model ) : NOMAD::Quad_Model_Evaluator(p,model),NOMAD::Evaluator(p){;} + const NOMAD::Quad_Model & model ) : NOMAD::Quad_Model_Evaluator(p,model),NOMAD::Evaluator(p){_is_model_evaluator=true;} /// Destructor. virtual ~Single_Obj_Quad_Model_Evaluator ( void ){;} + /// Evaluate the blackboxes quad model at a given trial point /** \param x point to evaluate -- \b IN/OUT. @@ -75,6 +76,7 @@ namespace NOMAD { const NOMAD::Double & h_max , bool & count_eval ) const {return Quad_Model_Evaluator::eval_x(x,h_max,count_eval);} + }; } diff --git a/src/Slave.cpp b/src/Slave.cpp index 1986ce58d59bd12519ae5a406105ac8fa742e011..cb73ff58c1ed109158ef7d25385864e6bad6073b 100644 --- a/src/Slave.cpp +++ b/src/Slave.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Slave.cpp - \brief Slave process (implementation) - \author Sebastien Le Digabel - \date 2010-04-22 - \see Slave.hpp -*/ + \file Slave.cpp + \brief Slave process (implementation) + \author Sebastien Le Digabel + \date 2010-04-22 + \see Slave.hpp + */ #include "Slave.hpp" /*-----------------------------------*/ @@ -58,24 +58,24 @@ bool NOMAD::Slave::_stop_ok = false; void NOMAD::Slave::init ( void ) const { #ifdef USE_MPI - MPI_Comm_rank ( MPI_COMM_WORLD, &NOMAD::Slave::_rank ); - MPI_Comm_size ( MPI_COMM_WORLD, &NOMAD::Slave::_np ); + MPI_Comm_rank ( MPI_COMM_WORLD, &NOMAD::Slave::_rank ); + MPI_Comm_size ( MPI_COMM_WORLD, &NOMAD::Slave::_np ); #else - NOMAD::Slave::_rank = 0; - NOMAD::Slave::_np = 1; + NOMAD::Slave::_rank = 0; + NOMAD::Slave::_np = 1; #endif - - // Slave::force_quit() will be called if ctrl-c is pressed: - if ( !NOMAD::Slave::is_master() ) { - - NOMAD::Evaluator::force_quit(); - - signal ( SIGTERM , NOMAD::Slave::force_quit ); - signal ( SIGINT , NOMAD::Slave::force_quit ); + + // Slave::force_quit() will be called if ctrl-c is pressed: + if ( !NOMAD::Slave::is_master() ) { + + NOMAD::Evaluator::force_quit(); + + signal ( SIGTERM , NOMAD::Slave::force_quit ); + signal ( SIGINT , NOMAD::Slave::force_quit ); #ifndef WINDOWS - signal ( SIGPIPE , NOMAD::Slave::force_quit ); // (ctrl-c during a "| more") + signal ( SIGPIPE , NOMAD::Slave::force_quit ); // (ctrl-c during a "| more") #endif - } + } } /*----------------------------------------*/ @@ -84,14 +84,14 @@ void NOMAD::Slave::init ( void ) const /*----------------------------------------*/ int NOMAD::Slave::get_rank ( void ) { - if ( NOMAD::Slave::_rank < 0 ) { + if ( NOMAD::Slave::_rank < 0 ) { #ifdef USE_MPI - MPI_Comm_rank ( MPI_COMM_WORLD, &NOMAD::Slave::_rank ); + MPI_Comm_rank ( MPI_COMM_WORLD, &NOMAD::Slave::_rank ); #else - NOMAD::Slave::_rank = 0; + NOMAD::Slave::_rank = 0; #endif - } - return NOMAD::Slave::_rank; + } + return NOMAD::Slave::_rank; } /*----------------------------------------*/ @@ -100,14 +100,14 @@ int NOMAD::Slave::get_rank ( void ) /*----------------------------------------*/ int NOMAD::Slave::get_nb_processes ( void ) { - if ( NOMAD::Slave::_np < 0 ) { + if ( NOMAD::Slave::_np < 0 ) { #ifdef USE_MPI - MPI_Comm_size ( MPI_COMM_WORLD, &NOMAD::Slave::_np ); + MPI_Comm_size ( MPI_COMM_WORLD, &NOMAD::Slave::_np ); #else - NOMAD::Slave::_np = 1; + NOMAD::Slave::_np = 1; #endif - } - return NOMAD::Slave::_np; + } + return NOMAD::Slave::_np; } /*----------------------*/ @@ -116,58 +116,58 @@ int NOMAD::Slave::get_nb_processes ( void ) void NOMAD::Slave::run ( void ) const { #ifdef USE_MPI - - MPI_Request req; - char signal = 0; - NOMAD::Eval_Point * x = NULL; - bool count_eval = false; - - while ( true ) { - - // receive signal from master: - // --------------------------- - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , 0 , &req ); - - // slave is ready or not initialized: - NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); - - NOMAD::Slave::wait_request ( req ); - // EVAL signal: - // ------------ - if ( signal == NOMAD::EVAL_SIGNAL ) { - - // receive and evaluate the point: - x = eval_point ( count_eval ); - - } - - // RESULT signal: - // -------------- - else if ( signal == NOMAD::RESULT_SIGNAL ) - { - - // send the evaluation result to the master: - send_eval_result ( x , count_eval ); - - delete x; - x = NULL; + MPI_Request req; + char signal = 0; + NOMAD::Eval_Point * x = NULL; + bool count_eval = false; + + while ( true ) { + + // receive signal from master: + // --------------------------- + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , 0 , &req ); + + // slave is ready or not initialized: + NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); + + NOMAD::Slave::wait_request ( req ); + + // EVAL signal: + // ------------ + if ( signal == NOMAD::EVAL_SIGNAL ) { + + // receive and evaluate the point: + x = eval_point ( count_eval ); + + } + + // RESULT signal: + // -------------- + else if ( signal == NOMAD::RESULT_SIGNAL ) + { + + // send the evaluation result to the master: + send_eval_result ( x , count_eval ); + + delete x; + x = NULL; + } + + // STOP signal: + // ------------ + else if ( signal == NOMAD::STOP_SIGNAL ) + break; + + // WAIT signal: + // ------------ + // else if ( signal == NOMAD::WAIT_SIGNAL ) { + // } } - - // STOP signal: - // ------------ - else if ( signal == NOMAD::STOP_SIGNAL ) - break; - - // WAIT signal: - // ------------ - // else if ( signal == NOMAD::WAIT_SIGNAL ) { - // } - } - - if ( x ) - delete x; - + + if ( x ) + delete x; + #endif } @@ -178,93 +178,101 @@ void NOMAD::Slave::run ( void ) const void NOMAD::Slave::init_slaves ( const NOMAD::Display & out ) { #ifdef USE_MPI - - if ( !NOMAD::Slave::is_master() || NOMAD::Slave::_are_running ) - return; - - NOMAD::dd_type display_degree = out.get_gen_dd(); - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "initializing slaves" ); - - MPI_Status status; - MPI_Request ** req = new MPI_Request * [ NOMAD::Slave::_np ]; - int nb_initialized = 0; - int nb_slaves = NOMAD::Slave::_np - 1; - int source; - char signal; - NOMAD::Clock clk; - - // 1. launch requests: - for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { - req[source] = new MPI_Request; - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , source , req[source] ); + + if ( !NOMAD::Slave::is_master() || NOMAD::Slave::_are_running ) + return; + + NOMAD::dd_type display_degree = out.get_gen_dd(); if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "." << std::endl; - } - - // 2. test requests (with a maximal delay of MAX_REQ_WAIT): - int cnt = 0 , flag; - while ( nb_initialized < nb_slaves && clk.get_real_time() < NOMAD::MAX_REQ_WAIT ) { - + out << std::endl << NOMAD::open_block ( "initializing slaves" ); + + MPI_Status status; + MPI_Request ** req = new MPI_Request * [ NOMAD::Slave::_np ]; + int nb_initialized = 0; + int nb_slaves = NOMAD::Slave::_np - 1; + int source; + char signal; + NOMAD::Clock clk; + + // 1. launch requests: for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { + req[source] = new MPI_Request; + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , source , req[source] ); + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "." << std::endl; + } - if ( req[source] ) { - - MPI_Test ( req[source] , &flag , &status ); - - if ( flag ) { - - MPI_Wait ( req[source] , &status ); - - // send the WAIT signal: - NOMAD::Slave::send_data ( &NOMAD::WAIT_SIGNAL , 1 , MPI_CHAR , source , true ); - - delete req[source]; - req[source] = NULL; - ++nb_initialized; - } - } + // 2. test requests (with a maximal delay of MAX_REQ_WAIT): + int cnt = 0 , flag; + while ( nb_initialized < nb_slaves && clk.get_real_time() < NOMAD::MAX_REQ_WAIT ) + { + + for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) + { + + if ( req[source] ) + { + + MPI_Test ( req[source] , &flag , &status ); + + if ( flag ) + { + + MPI_Wait ( req[source] , &status ); + + // send the WAIT signal: + NOMAD::Slave::send_data ( &NOMAD::WAIT_SIGNAL , 1 , MPI_CHAR , source , true ); + + delete req[source]; + req[source] = NULL; + ++nb_initialized; + } + } + } + // a constant is used in order to display only a few '.' : + if ( display_degree == NOMAD::FULL_DISPLAY && cnt%1000000==0 ) + out << "." << std::endl; + + ++cnt; } - // a constant is used in order to display only a few '.' : - if ( display_degree == NOMAD::FULL_DISPLAY && cnt%1000000==0 ) - out << "." << std::endl; - - ++cnt; - } - - // 3. delete requests: - std::list<int> err_list; - for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { - if ( req[source] ) { - err_list.push_back ( source ); - MPI_Cancel ( req[source] ); - delete req[source]; + + // 3. delete requests: + std::list<int> err_list; + for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) + { + if ( req[source] ) + { + err_list.push_back ( source ); + MPI_Cancel ( req[source] ); + delete req[source]; + } } - } - delete [] req; - - NOMAD::Slave::_are_running = true; - NOMAD::Slave::_stop_ok = false; - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << NOMAD::close_block() << std::endl; - - if ( !err_list.empty() ) { - - std::ostringstream oss; - oss << "could not initialize slave"; - if ( err_list.size() > 1 ) { - oss << "s"; - std::list<int>::const_iterator it , end = err_list.end(); - for ( it = err_list.begin() ; it != end ; ++it ) - oss << " #" << *it; + delete [] req; + + NOMAD::Slave::_are_running = true; + NOMAD::Slave::_stop_ok = false; + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block() << std::endl; + + if ( !err_list.empty() ) + { + + std::ostringstream oss; + oss << "could not initialize slave"; + if ( err_list.size() > 1 ) + { + oss << "s"; + std::list<int>::const_iterator it , end = err_list.end(); + for ( it = err_list.begin() ; it != end ; ++it ) + oss << " #" << *it; + } + else + oss << " #" << *err_list.begin(); + + throw NOMAD::Exception ( "Slave.cpp" , __LINE__ , oss.str() ); } - else - oss << " #" << *err_list.begin(); - - throw NOMAD::Exception ( "Slave.cpp" , __LINE__ , oss.str() ); - } - + #endif } @@ -275,78 +283,78 @@ void NOMAD::Slave::init_slaves ( const NOMAD::Display & out ) void NOMAD::Slave::stop_slaves ( const NOMAD::Display & out ) { #ifdef USE_MPI - - if ( !NOMAD::Slave::is_master() || NOMAD::Slave::_stop_ok ) - return; - - NOMAD::dd_type display_degree = out.get_gen_dd(); - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << NOMAD::open_block ( "stopping slaves" ); - - int nb_stopped = 0; - int nb_slaves = NOMAD::Slave::_np - 1; - int source; - char signal; - - NOMAD::Clock clk; - - MPI_Status status; - MPI_Request ** req = new MPI_Request * [ NOMAD::Slave::_np ]; - - // 1. launch requests: - for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { - req[source] = new MPI_Request; - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , source , req[source] ); + + if ( !NOMAD::Slave::is_master() || NOMAD::Slave::_stop_ok ) + return; + + NOMAD::dd_type display_degree = out.get_gen_dd(); if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "." << std::endl; - } - - // 2. test requests (with a maximal delay of MAX_REQ_WAIT): - int cnt = 0 , flag; - while ( nb_stopped < nb_slaves && clk.get_real_time() < NOMAD::MAX_REQ_WAIT ) { - + out << std::endl << NOMAD::open_block ( "stopping slaves" ); + + int nb_stopped = 0; + int nb_slaves = NOMAD::Slave::_np - 1; + int source; + char signal; + + NOMAD::Clock clk; + + MPI_Status status; + MPI_Request ** req = new MPI_Request * [ NOMAD::Slave::_np ]; + + // 1. launch requests: for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { + req[source] = new MPI_Request; + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , source , req[source] ); + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "." << std::endl; + } - if ( req[source] ) { - - MPI_Test ( req[source] , &flag , &status ); - - if ( flag ) { - - MPI_Wait ( req[source] , &status ); - - // send the STOP signal: - NOMAD::Slave::send_data ( &NOMAD::STOP_SIGNAL , 1 , MPI_CHAR , source , true ); - - delete req[source]; - req[source] = NULL; - ++nb_stopped; - } - } + // 2. test requests (with a maximal delay of MAX_REQ_WAIT): + int cnt = 0 , flag; + while ( nb_stopped < nb_slaves && clk.get_real_time() < NOMAD::MAX_REQ_WAIT ) { + + for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { + + if ( req[source] ) { + + MPI_Test ( req[source] , &flag , &status ); + + if ( flag ) { + + MPI_Wait ( req[source] , &status ); + + // send the STOP signal: + NOMAD::Slave::send_data ( &NOMAD::STOP_SIGNAL , 1 , MPI_CHAR , source , true ); + + delete req[source]; + req[source] = NULL; + ++nb_stopped; + } + } + } + // a constant is used in order to display only a few '.' : + if ( display_degree == NOMAD::FULL_DISPLAY && cnt%1000000==0 ) + out << "." << std::endl; + ++cnt; } - // a constant is used in order to display only a few '.' : - if ( display_degree == NOMAD::FULL_DISPLAY && cnt%1000000==0 ) - out << "." << std::endl; - ++cnt; - } - - NOMAD::Slave::_are_running = false; - NOMAD::Slave::_stop_ok = true; - - // 3. delete requests: - for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { - if ( req[source] ) { - MPI_Cancel ( req[source] ); - delete req[source]; - NOMAD::Slave::_stop_ok = false; + + NOMAD::Slave::_are_running = false; + NOMAD::Slave::_stop_ok = true; + + // 3. delete requests: + for ( source = 1 ; source < NOMAD::Slave::_np ; ++source ) { + if ( req[source] ) { + MPI_Cancel ( req[source] ); + delete req[source]; + NOMAD::Slave::_stop_ok = false; + } } - } - delete [] req; - - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << NOMAD::close_block() << std::endl; - - #endif + delete [] req; + + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << NOMAD::close_block() << std::endl; + +#endif } #ifdef USE_MPI @@ -355,63 +363,63 @@ void NOMAD::Slave::stop_slaves ( const NOMAD::Display & out ) /* receive data (static, private) */ /*------------------------------------------------------*/ int NOMAD::Slave::receive_data ( void * buf , - int count , - MPI_Datatype datatype , - int source , // may be MPI_ANY_SOURCE - MPI_Request * req ) + int count , + MPI_Datatype datatype , + int source , // may be MPI_ANY_SOURCE + MPI_Request * req ) { - int tag = ( NOMAD::Slave::is_master() ) ? source : NOMAD::Slave::get_rank(); - - // immediate receive: - if ( req ) { - if ( source == MPI_ANY_SOURCE ) - throw NOMAD::Exception ( "Slave.cpp" , __LINE__ , - "Slave::receive_data(): immediate receive with no source" ); - MPI_Irecv ( buf , count , datatype , source , tag , MPI_COMM_WORLD , req ); - } - - // normal receive: - else { - MPI_Status status; - if ( source == MPI_ANY_SOURCE ) - tag = MPI_ANY_TAG; - MPI_Recv ( buf , count , datatype , source , tag , MPI_COMM_WORLD , &status ); - source = status.MPI_SOURCE; - } - - // stats: - int size; - MPI_Type_size ( datatype , &size ); - NOMAD::Slave::_data_rcvd += count * size; - - return source; + int tag = ( NOMAD::Slave::is_master() ) ? source : NOMAD::Slave::get_rank(); + + // immediate receive: + if ( req ) { + if ( source == MPI_ANY_SOURCE ) + throw NOMAD::Exception ( "Slave.cpp" , __LINE__ , + "Slave::receive_data(): immediate receive with no source" ); + MPI_Irecv ( buf , count , datatype , source , tag , MPI_COMM_WORLD , req ); + } + + // normal receive: + else { + MPI_Status status; + if ( source == MPI_ANY_SOURCE ) + tag = MPI_ANY_TAG; + MPI_Recv ( buf , count , datatype , source , tag , MPI_COMM_WORLD , &status ); + source = status.MPI_SOURCE; + } + + // stats: + int size; + MPI_Type_size ( datatype , &size ); + NOMAD::Slave::_data_rcvd += count * size; + + return source; } /*------------------------------------------------------*/ /* send data (static, private) */ /*------------------------------------------------------*/ void NOMAD::Slave::send_data ( const void * buf , - int count , - MPI_Datatype datatype , - int dest , - bool ready_send ) + int count , + MPI_Datatype datatype , + int dest , + bool ready_send ) { - int tag = ( NOMAD::Slave::is_master() ) ? dest : NOMAD::Slave::get_rank(); - - // ready send: - if ( ready_send ) - MPI_Rsend ( const_cast<void*>(buf) , count , datatype , - dest , tag , MPI_COMM_WORLD ); - - // normal send: - else - MPI_Send ( const_cast<void*>(buf) , count , datatype , - dest , tag , MPI_COMM_WORLD ); - - // stats: - int size; - MPI_Type_size ( datatype , &size ); - NOMAD::Slave::_data_sent += count * size; + int tag = ( NOMAD::Slave::is_master() ) ? dest : NOMAD::Slave::get_rank(); + + // ready send: + if ( ready_send ) + MPI_Rsend ( const_cast<void*>(buf) , count , datatype , + dest , tag , MPI_COMM_WORLD ); + + // normal send: + else + MPI_Send ( const_cast<void*>(buf) , count , datatype , + dest , tag , MPI_COMM_WORLD ); + + // stats: + int size; + MPI_Type_size ( datatype , &size ); + NOMAD::Slave::_data_sent += count * size; } /*------------------------------------------------------*/ @@ -420,158 +428,159 @@ void NOMAD::Slave::send_data ( const void * buf , /*------------------------------------------------------*/ NOMAD::Eval_Point * NOMAD::Slave::eval_point ( bool & count_eval ) const { - // 1. receive the point: - int itab[3]; - MPI_Request req; - NOMAD::Slave::receive_data ( itab , 3 , MPI_INT , 0 , &req ); - NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); - NOMAD::Slave::wait_request ( req ); - - int n = itab[0]; - double * dtab = new double[n+1]; - - NOMAD::Slave::receive_data ( dtab , n+1 , MPI_DOUBLE , 0 , &req ); - NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); - NOMAD::Slave::wait_request ( req ); - - // 2. create the Eval_Point: - NOMAD::Eval_Point * x = new NOMAD::Eval_Point ( n , _p->get_bb_nb_outputs() ); - for ( int i = 0 ; i < n ; ++i ) - (*x)[i] = dtab[i]; - NOMAD::Double h_max = dtab[n]; - - x->set_tag ( itab[2] ); - x->set_eval_type ( ( itab[1] > 0 ) ? NOMAD::SGTE : NOMAD::TRUTH ); - - delete [] dtab; - - // 3. evaluate the point: - bool eval_ok; - try { - eval_ok = _ev->eval_x ( *x , h_max , count_eval ); - } - catch ( ... ) { - eval_ok = false; - } - - x->set_eval_status ( ( eval_ok ) ? NOMAD::EVAL_OK : NOMAD::EVAL_FAIL ); - - return x; + // 1. receive the point: + int itab[3]; + MPI_Request req; + NOMAD::Slave::receive_data ( itab , 3 , MPI_INT , 0 , &req ); + NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); + NOMAD::Slave::wait_request ( req ); + + int n = itab[0]; + double * dtab = new double[n+1]; + + NOMAD::Slave::receive_data ( dtab , n+1 , MPI_DOUBLE , 0 , &req ); + NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , 0 , false ); + NOMAD::Slave::wait_request ( req ); + + // 2. create the Eval_Point: + int bb_nb_outputs=_p->get_bb_nb_outputs(); + NOMAD::Eval_Point * x = new NOMAD::Eval_Point ( n , bb_nb_outputs ); + for ( int i = 0 ; i < n ; ++i ) + (*x)[i] = dtab[i]; + NOMAD::Double h_max = dtab[n]; + + x->set_tag ( itab[2] ); + x->set_eval_type ( ( itab[1] > 0 ) ? NOMAD::SGTE : NOMAD::TRUTH ); + + delete [] dtab; + + // 3. evaluate the point: + bool eval_ok; + try { + eval_ok = _ev->eval_x ( *x , h_max , count_eval ); + } + catch ( ... ) { + eval_ok = false; + } + + x->set_eval_status ( ( eval_ok ) ? NOMAD::EVAL_OK : NOMAD::EVAL_FAIL ); + + return x; } /*-----------------------------------------------------*/ /* send an evaluation result to the master (private) */ /*-----------------------------------------------------*/ void NOMAD::Slave::send_eval_result ( const NOMAD::Eval_Point * x , - bool count_eval ) const + bool count_eval ) const { - // receive a signal from the master: - char signal; - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , 0 , NULL ); - - // send the evaluation result: - int m = _p->get_bb_nb_outputs(); - int s = 2*m+2; - double * dtab = new double [s]; - const NOMAD::Point & bbo = x->get_bb_outputs(); - - // bb_outputs (m values): - for ( int i = 0 ; i < m ; ++i ) { - if ( bbo[i].is_defined() ) { - dtab[i ] = bbo[i].value(); - dtab[i+m] = 1.0; - } - else { - dtab[i ] = NOMAD::INF; - dtab[i+m] = -1.0; + // receive a signal from the master: + char signal; + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , 0 , NULL ); + + // send the evaluation result: + int m = _p->get_bb_nb_outputs(); + int s = 2*m+2; + double * dtab = new double [s]; + const NOMAD::Point & bbo = x->get_bb_outputs(); + + // bb_outputs (m values): + for ( int i = 0 ; i < m ; ++i ) { + if ( bbo[i].is_defined() ) { + dtab[i ] = bbo[i].value(); + dtab[i+m] = 1.0; + } + else { + dtab[i ] = NOMAD::INF; + dtab[i+m] = -1.0; + } } - } - - // evaluation status: - dtab[2*m] = ( x->get_eval_status() == NOMAD::EVAL_OK ) ? 1.0 : -1.0; - - // count_eval: - dtab[s-1] = ( count_eval ) ? 1.0 : -1.0; - - // send the array: - NOMAD::Slave::send_data ( dtab , s , MPI_DOUBLE , 0 , true ); - - delete [] dtab; + + // evaluation status: + dtab[2*m] = ( x->get_eval_status() == NOMAD::EVAL_OK ) ? 1.0 : -1.0; + + // count_eval: + dtab[s-1] = ( count_eval ) ? 1.0 : -1.0; + + // send the array: + NOMAD::Slave::send_data ( dtab , s , MPI_DOUBLE , 0 , true ); + + delete [] dtab; } /*---------------------------------------------*/ /* receive an evaluation result from a slave */ /*---------------------------------------------*/ void NOMAD::Slave::receive_eval_result ( int slave_rank , - NOMAD::Eval_Point * x , - bool & eval_ok , - bool & count_eval ) const + NOMAD::Eval_Point * x , + bool & eval_ok , + bool & count_eval ) const { - // send the RESULT signal to the slave: - NOMAD::Slave::send_data ( &NOMAD::RESULT_SIGNAL , 1 , MPI_CHAR , slave_rank , true ); - - // receive the evaluation result as a double array: - int m = _p->get_bb_nb_outputs(); - int s = 2*m+2; - double * dtab = new double [s]; - - MPI_Request req; - NOMAD::Slave::receive_data ( dtab , s , MPI_DOUBLE , slave_rank , &req ); - NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , slave_rank , false ); - NOMAD::Slave::wait_request ( req ); - - // interpret the array: - for ( int i = 0 ; i < m ; ++i ) - x->set_bb_output ( i , ( dtab[i+m] > 0.0 ) ? dtab[i] : NOMAD::Double() ); - - eval_ok = ( dtab[2*m] > 0.0 ); - - x->set_eval_status ( eval_ok ? NOMAD::EVAL_OK : NOMAD::EVAL_FAIL ); - - count_eval = ( dtab[s-1] > 0.0 ); - - delete [] dtab; + // send the RESULT signal to the slave: + NOMAD::Slave::send_data ( &NOMAD::RESULT_SIGNAL , 1 , MPI_CHAR , slave_rank , true ); + + // receive the evaluation result as a double array: + int m = _p->get_bb_nb_outputs(); + int s = 2*m+2; + double * dtab = new double [s]; + + MPI_Request req; + NOMAD::Slave::receive_data ( dtab , s , MPI_DOUBLE , slave_rank , &req ); + NOMAD::Slave::send_data ( &NOMAD::READY_SIGNAL , 1 , MPI_CHAR , slave_rank , false ); + NOMAD::Slave::wait_request ( req ); + + // interpret the array: + for ( int i = 0 ; i < m ; ++i ) + x->set_bb_output ( i , ( dtab[i+m] > 0.0 ) ? dtab[i] : NOMAD::Double() ); + + eval_ok = ( dtab[2*m] > 0.0 ); + + x->set_eval_status ( eval_ok ? NOMAD::EVAL_OK : NOMAD::EVAL_FAIL ); + + count_eval = ( dtab[s-1] > 0.0 ); + + delete [] dtab; } /*-----------------------------------------------------*/ /* send an Eval_Point to a slave */ /*-----------------------------------------------------*/ void NOMAD::Slave::send_eval_point ( const NOMAD::Eval_Point * x , - int slave_rank , - const NOMAD::Double & h_max ) const + int slave_rank , + const NOMAD::Double & h_max ) const { - char signal; - int itab[3]; - int n = x->size(); + char signal; + int itab[3]; + int n = x->size(); - // n: - itab[0] = n; - - // evaluation type (+1: sgte eval; -1: true eval): - itab[1] = ( x->get_eval_type() == NOMAD::SGTE ) ? 1 : -1; - - // tag of the point: - itab[2] = x->get_tag(); - - // point coordinates: - double * dtab = new double[n+1]; - for ( int i = 0 ; i < n ; ++i ) - dtab[i] = (*x)[i].value(); - dtab[n] = h_max.value(); - - // wait for the slave signal: - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , slave_rank , NULL ); - - // send n and evaluation type: - NOMAD::Slave::send_data ( itab , 3 , MPI_INT , slave_rank , true ); - - // wait for the slave signal: - NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , slave_rank , NULL ); - - // send the point coordinates: - NOMAD::Slave::send_data ( dtab , n+1 , MPI_DOUBLE , slave_rank , true ); - - delete [] dtab; + // n: + itab[0] = n; + + // evaluation type (+1: sgte eval; -1: true eval): + itab[1] = ( x->get_eval_type() == NOMAD::SGTE ) ? 1 : -1; + + // tag of the point: + itab[2] = x->get_tag(); + + // point coordinates: + double * dtab = new double[n+1]; + for ( int i = 0 ; i < n ; ++i ) + dtab[i] = (*x)[i].value(); + dtab[n] = h_max.value(); + + // wait for the slave signal: + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , slave_rank , NULL ); + + // send n and evaluation type: + NOMAD::Slave::send_data ( itab , 3 , MPI_INT , slave_rank , true ); + + // wait for the slave signal: + NOMAD::Slave::receive_data ( &signal , 1 , MPI_CHAR , slave_rank , NULL ); + + // send the point coordinates: + NOMAD::Slave::send_data ( dtab , n+1 , MPI_DOUBLE , slave_rank , true ); + + delete [] dtab; } /*-----------------------------------------*/ @@ -580,8 +589,8 @@ void NOMAD::Slave::send_eval_point ( const NOMAD::Eval_Point * x , /*-----------------------------------------*/ void NOMAD::Slave::wait_request ( MPI_Request & req ) { - MPI_Status status; - MPI_Wait ( &req , &status ); + MPI_Status status; + MPI_Wait ( &req , &status ); } #endif diff --git a/src/Slave.hpp b/src/Slave.hpp index a460c43c7551c3fe05c3215f97b99715225833ba..03ae58a9f7cf9d50a6d850051f9f50d92b3f0d4b 100644 --- a/src/Slave.hpp +++ b/src/Slave.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -82,10 +82,8 @@ namespace NOMAD { \param p Parameters -- \b IN. \param ev A pointer to an evaluator -- \b IN. */ - Slave ( const NOMAD::Parameters & p , - NOMAD::Evaluator * ev ) - : _p ( &p ) , - _ev ( ev ) { init(); } + Slave ( const NOMAD::Parameters & p , NOMAD::Evaluator * ev ) + { _p=&p; _ev=ev; init(); } /// Destructor. virtual ~Slave ( void ) {} diff --git a/src/Speculative_Search.cpp b/src/Speculative_Search.cpp index c4bb03c1189e52fa759e0253bc39d8260d251e23..468e97d1114e2e415f0dfcdf92a2582e3e12b0cb 100644 --- a/src/Speculative_Search.cpp +++ b/src/Speculative_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,12 +34,12 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Speculative_Search.cpp - \brief Speculative search (implementation) - \author Sebastien Le Digabel - \date 2010-04-12 - \see Speculative.hpp -*/ + \file Speculative_Search.cpp + \brief Speculative search (implementation) + \author Sebastien Le Digabel + \date 2010-04-12 + \see Speculative.hpp + */ #include "Speculative_Search.hpp" /*-------------------------------------------------------------*/ @@ -56,148 +56,146 @@ /* and has already been made in Mads.cpp */ /*-------------------------------------------------------------*/ void NOMAD::Speculative_Search::search ( NOMAD::Mads & mads , - int & nb_search_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - bool & count_search , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_search_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + bool & count_search , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - // new_feas_inc and new_infeas_inc are used as inputs, - // so do not initialize them to NULL here - - nb_search_pts = 0; - success = NOMAD::UNSUCCESSFUL; - count_search = !stop; - - if ( stop ) - return; - - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << NOMAD::SPEC_SEARCH; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - int lkm1; // l_{k-1} - int lk; // l_k - int n; - NOMAD::Signature * signature; - NOMAD::Point delta_m_k; - NOMAD::Point delta_m_km1; - NOMAD::Point factor; - NOMAD::Point xkm1; - NOMAD::Eval_Point * sk; - const NOMAD::Eval_Point * x[2]; - x[0] = new_feas_inc; - x[1] = new_infeas_inc; - - // Evaluator_Control: - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - for ( int i = 0 ; i < 2 ; ++i ) { - if ( x[i] && x[i]->get_mesh_index() ) { - - const NOMAD::Direction * dir = x[i]->get_direction(); - if ( dir && ( dir->is_mads() || dir->get_type()==NOMAD::MODEL_SEARCH_DIR ) ) { - - // get the x_k's signature: - signature = x[i]->get_signature(); - if ( !signature ) - throw NOMAD::Exception ( "Speculative_Search.cpp" , __LINE__ , - "Speculative_Search::search(): could not get the signature" ); - - xkm1 = *x[i] - *dir; - - lk = lkm1 = *x[i]->get_mesh_index(); - NOMAD::Mesh::update ( NOMAD::FULL_SUCCESS , lk ); - - n = signature->get_n(); - delta_m_k = NOMAD::Point ( n ); - delta_m_km1 = NOMAD::Point ( n ); - factor = NOMAD::Point ( n ); - - signature->get_mesh().get_delta_m ( delta_m_k , lk ); - signature->get_mesh().get_delta_m ( delta_m_km1 , lkm1 ); - - // multiplicative factor: takes into account the fact that - // the direction contains \Delta^m_k: - try { - - // factor = delta_m_k / delta_m_km1 : - for ( int k = 0 ; k < n ; ++k ) { - if ( delta_m_k[k].is_defined() && delta_m_km1[k].is_defined() && - delta_m_k[k].value() != 0.0 && delta_m_km1[k].value() != 0.0 ) - factor[k] = delta_m_k[k] / delta_m_km1[k]; - else - factor[k] = 0.0; - } - } - catch ( NOMAD::Double::Invalid_Value & ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << "could not compute " << _type << " point: stop" << std::endl - << NOMAD::close_block ( "end of speculative search" ); - stop = true; - stop_reason = NOMAD::MESH_PREC_REACHED; - return; - } - - if ( lkm1 <= 0 ) - factor *= NOMAD::Mesh::get_mesh_update_basis(); - - // speculative search point: - NOMAD::Direction new_dir ( n , 0.0 , dir->get_type() ); - new_dir.Point::operator = ( factor * *dir ); - - sk = new NOMAD::Eval_Point; - sk->set ( n , _p.get_bb_nb_outputs() ); - sk->set_signature ( signature ); - sk->set_direction ( &new_dir ); - sk->set_mesh_index ( &lk ); - - sk->Point::operator = ( xkm1 + new_dir ); - - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << "trial point #" << sk->get_tag() - << ": ( "; - sk->Point::display ( out ," " , 2 , NOMAD::Point::get_display_limit() ); - out << " )" << std::endl; - } - - // add the new point to the list of search trial points: - ev_control.add_eval_point ( sk , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } + // new_feas_inc and new_infeas_inc are used as inputs, + // so do not initialize them to NULL here + + nb_search_pts = 0; + success = NOMAD::UNSUCCESSFUL; + count_search = !stop; + + if ( stop ) + return; + + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << NOMAD::SPEC_SEARCH; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + //int lkm1; // l_{k-1} + // int lk; // l_k + int n; + NOMAD::Signature * signature; + NOMAD::Point delta_m_k; + NOMAD::Point delta_m_km1; + NOMAD::Point factor; + NOMAD::Point xkm1; + NOMAD::Eval_Point * sk; + const NOMAD::Eval_Point * x[2]; + x[0] = new_feas_inc; + x[1] = new_infeas_inc; + + // Evaluator_Control: + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + for ( int i = 0 ; i < 2 ; ++i ) + { + if ( x[i] && x[i]->get_signature() ) + { + + const NOMAD::Direction * dir = x[i]->get_direction(); + if ( dir && ( dir->is_mads() || dir->get_type()==NOMAD::MODEL_SEARCH_DIR ) ) { + + // get the x_k's signature: + signature = x[i]->get_signature(); + if ( !signature ) + throw NOMAD::Exception ( "Speculative_Search.cpp" , __LINE__ , + "Speculative_Search::search(): could not get the signature" ); + + xkm1 = *x[i] - *dir; + + factor = signature->get_mesh()->get_mesh_ratio_if_success(); + n=signature->get_n(); + for ( int k = 0 ; k < n ; ++k ) + { + if ( factor[k].is_defined() ) + { + if ( factor[k] == 1 ) + { + // factor determined based on mesh type ( default is 4 = mesh_update_basis = 2* poll_update_basis ) + if ( dynamic_cast<NOMAD::XMesh *> (signature->get_mesh()) ) + factor[k] = signature->get_mesh()->get_update_basis()*2.0; + else + factor[k] = signature->get_mesh()->get_update_basis(); + + } + else if ( factor[k] == 0 ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << "could not compute " << _type << " point: stop" << std::endl + << NOMAD::close_block ( "end of speculative search" ); + stop = true; + stop_reason = NOMAD::MESH_PREC_REACHED; + return; + } + + } + else + factor[k]=0; + + } + NOMAD::Point mesh_indices_k( x[i]->get_signature()->get_mesh()->get_mesh_indices() ); + signature->get_mesh()->update( NOMAD::FULL_SUCCESS, mesh_indices_k , dir ); + + // speculative search point: + NOMAD::Direction new_dir ( n , 0.0 , dir->get_type() ); + new_dir.Point::operator = ( factor * *dir ); + + sk = new NOMAD::Eval_Point; + sk->set ( n , _p.get_bb_nb_outputs() ); + sk->set_signature ( signature ); + sk->set_direction ( &new_dir ); + + sk->Point::operator = ( xkm1 + new_dir ); + + if ( display_degree == NOMAD::FULL_DISPLAY ) { + out << "trial point #" << sk->get_tag() + << ": ( "; + sk->Point::display ( out ," " , 2 , NOMAD::Point::get_display_limit() ); + out << " )" << std::endl; + } + + // add the new point to the list of search trial points: + ev_control.add_eval_point ( sk , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + } + } + } + + nb_search_pts = ev_control.get_nb_eval_points(); + + // eval_list_of_points:s + // -------------------- + new_feas_inc = new_infeas_inc = NULL; + + ev_control.eval_list_of_points ( _type , + mads.get_true_barrier() , + mads.get_sgte_barrier() , + mads.get_pareto_front() , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + + if ( display_degree == NOMAD::FULL_DISPLAY ) { + std::ostringstream oss; + oss << "end of speculative search (" << success << ")"; + out << NOMAD::close_block ( oss.str() ) << std::endl; } - } - - nb_search_pts = ev_control.get_nb_eval_points(); - - // eval_list_of_points: - // -------------------- - new_feas_inc = new_infeas_inc = NULL; - - ev_control.eval_list_of_points ( _type , - mads.get_true_barrier() , - mads.get_sgte_barrier() , - mads.get_pareto_front() , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << "end of speculative search (" << success << ")"; - out << NOMAD::close_block ( oss.str() ) << std::endl; - } } diff --git a/src/Speculative_Search.hpp b/src/Speculative_Search.hpp index 8ba14c2be68711932fc5d93550bd7611a983154e..e0db82d82e1325caf3f0904e8de6f26d14bab508 100644 --- a/src/Speculative_Search.hpp +++ b/src/Speculative_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/Stats.cpp b/src/Stats.cpp index b65011b857c6c94f555d157d8161e91c7f82a5d0..15479e00858d44f90f8c4c8a45d08af68857052d 100644 --- a/src/Stats.cpp +++ b/src/Stats.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -51,6 +51,7 @@ NOMAD::Stats & NOMAD::Stats::operator = ( const NOMAD::Stats & s ) _sim_bb_eval = s._sim_bb_eval; _sgte_eval = s._sgte_eval; _bb_eval = s._bb_eval; + _block_eval = s._block_eval; _failed_eval = s._failed_eval; _cache_hits = s._cache_hits; _interrupted_eval = s._interrupted_eval; @@ -107,6 +108,7 @@ void NOMAD::Stats::reset ( void ) _sim_bb_eval = _sgte_eval = _bb_eval = + _block_eval = _failed_eval = _cache_hits = _interrupted_eval = @@ -167,6 +169,7 @@ void NOMAD::Stats::update ( const NOMAD::Stats & s , bool for_search ) _sim_bb_eval += s._sim_bb_eval; _sgte_eval += s._sgte_eval; _bb_eval += s._bb_eval; + _block_eval += s._block_eval; _failed_eval += s._failed_eval; _cache_hits += s._cache_hits; _interrupted_eval += s._interrupted_eval; @@ -256,6 +259,9 @@ void NOMAD::Stats::display ( const NOMAD::Display & out ) const out << "bb evaluations (with sgte cost) : " << get_bb_eval(); else out << "blackbox evaluations : " << _bb_eval; + out << std::endl; + if ( _block_eval > 0) + out << "Block of evaluations : " << _block_eval; if ( _p1_bbe > 0 ) out << " (phase one: " << _p1_bbe << ")"; out << std::endl; diff --git a/src/Stats.hpp b/src/Stats.hpp index 5e02b11cc1ee26727e9e82f85b5c46099430be42..db9cf2aa71343293d028beef3fd2827b0c7f6b83 100644 --- a/src/Stats.hpp +++ b/src/Stats.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -69,6 +69,7 @@ namespace NOMAD { int _sgte_eval; ///< Number of surrogate evaluations. int _sgte_cost; ///< Surrogate cost. int _bb_eval; ///< Number of blackbox evaluations. + int _block_eval; ///< Number of block of evaluations. int _failed_eval; ///< Number of failed evaluations. int _cache_hits; ///< Number of cache hits. int _interrupted_eval; ///< Number of interrupted sequence of evaluations. @@ -150,6 +151,7 @@ public: _sgte_eval ( s._sgte_eval ) , _sgte_cost ( s._sgte_cost ) , _bb_eval ( s._bb_eval ) , + _block_eval ( s._block_eval ) , _failed_eval ( s._failed_eval ) , _cache_hits ( s._cache_hits ) , _interrupted_eval ( s._interrupted_eval ) , @@ -239,10 +241,19 @@ public: /// Add \c 1 to stat \c _sgte_eval. void add_sgte_eval ( void ) { ++_sgte_eval; } - + + /// Add \c count_eval to stat \c _sgte_eval. + void add_sgte_eval ( int count_eval ) { _sgte_eval+=count_eval; } + /// Add \c 1 to stat \c _bb_eval. void add_bb_eval ( void ) { ++_bb_eval; } + /// Add \c 1 to stat \c _block_eval. + void add_one_block_eval ( void ) { ++_block_eval; } + + /// Add \c count_eval to stat \c _bb_eval. + void add_bb_eval ( int count_eval ) { _bb_eval+=count_eval; } + /// Add \c 1 to stat \c _failed_eval. void add_failed_eval ( void ) { ++_failed_eval; } @@ -475,6 +486,16 @@ public: return ( _sgte_cost > 0 ) ? _bb_eval + _sgte_eval / _sgte_cost : _bb_eval; } + + /// Access to the number of block of evaluations (includes bb and surrogates). + /** + \return The number of blackbox evaluations. + */ + int get_block_eval ( void ) const + { + return _block_eval; + } + /// Access to the \c sum stat. /** \return The \c sum stat. diff --git a/src/TGP_Model.cpp b/src/TGP_Model.cpp index 900d6ea6e10631e4299b5c14314a0bc1f1ae8451..b5005f6055e2ac439798e019ba89e2fc028aec08 100644 --- a/src/TGP_Model.cpp +++ b/src/TGP_Model.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/TGP_Model.hpp b/src/TGP_Model.hpp index 22e0a10aa9c114922a51f40787bda8c92a835f9f..78cf20ceeb4b0b6bf5d84eeaef61654abd83977b 100644 --- a/src/TGP_Model.hpp +++ b/src/TGP_Model.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/TGP_Model_Evaluator.cpp b/src/TGP_Model_Evaluator.cpp index 58538e8cae7250a334c0af2d4ca5b4118acc4231..3edc7c6587e4d318e6a239f15666be2ea3d3703a 100644 --- a/src/TGP_Model_Evaluator.cpp +++ b/src/TGP_Model_Evaluator.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/TGP_Model_Evaluator.hpp b/src/TGP_Model_Evaluator.hpp index 5358b8443d8294be5f106e66f490feee412c10fe..2a378f243deaac6a0c4683ffb00ed3085bfda72c 100644 --- a/src/TGP_Model_Evaluator.hpp +++ b/src/TGP_Model_Evaluator.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/TGP_Model_Search.cpp b/src/TGP_Model_Search.cpp index 4c1c3738c83f9f489273d1f546e544477c85178a..bf5b6bc80e670f0e13055f065f3b2979f836c41b 100644 --- a/src/TGP_Model_Search.cpp +++ b/src/TGP_Model_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -202,10 +202,8 @@ void NOMAD::TGP_Model_Search::search ( NOMAD::Mads & mads count_search = true; _one_search_stats.add_MS_nb_searches(); - // mesh: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - NOMAD::Point delta_m; - signature->get_mesh().get_delta_m ( delta_m , mesh_index ); + NOMAD::Point delta_m; + signature->get_mesh()->get_delta(delta_m); // initial displays: if ( display_degree == NOMAD::FULL_DISPLAY ) { @@ -214,7 +212,6 @@ void NOMAD::TGP_Model_Search::search ( NOMAD::Mads & mads << _p.get_seed() << std::endl; #endif out << "number of cache points: " << cache.size() << std::endl - << "mesh index : " << mesh_index << std::endl << "mesh size parameter : ( " << delta_m << " )" << std::endl << "incumbent : ( "; incumbent->NOMAD::Point::display @@ -320,7 +317,6 @@ void NOMAD::TGP_Model_Search::search ( NOMAD::Mads & mads register_point ( *trial_pts[i] , *signature , *incumbent , - mesh_index , display_degree , ev_control ); @@ -1203,7 +1199,6 @@ void NOMAD::TGP_Model_Search::register_point ( NOMAD::Point x , NOMAD::Signature & signature , const NOMAD::Point & incumbent , - int mesh_index , NOMAD::dd_type display_degree , NOMAD::Evaluator_Control & ev_control ) const { @@ -1220,8 +1215,7 @@ void NOMAD::TGP_Model_Search::register_point } tk->set_signature ( &signature ); - tk->set_mesh_index ( &mesh_index ); - tk->Point::operator = ( x ); + tk->Point::operator = ( x ); // add the new point to the list of search trial points: ev_control.add_eval_point ( tk , @@ -1457,8 +1451,6 @@ bool NOMAD::TGP_Model_Search::optimize_model // parameters creation: NOMAD::Parameters model_param ( out ); - // random seed: - model_param.set_SEED ( _p.get_seed() + 10 * _all_searches_stats.get_MS_nb_searches() ); // number of variables: model_param.set_DIMENSION ( n ); @@ -1466,9 +1458,6 @@ bool NOMAD::TGP_Model_Search::optimize_model // blackbox outputs: model_param.set_BB_OUTPUT_TYPE ( _p.get_bb_output_type() ); - // blackbox inputs: - model_param.set_BB_INPUT_TYPE ( _p.get_bb_input_type() ); - // barrier parameters: model_param.set_H_MIN ( _p.get_h_min () ); model_param.set_H_NORM ( _p.get_h_norm() ); @@ -1501,30 +1490,19 @@ bool NOMAD::TGP_Model_Search::optimize_model else model_param.set_DISPLAY_STATS ( "bbe obj" ); } - - // mesh: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - int min_mesh_index = NOMAD::Mesh::get_min_mesh_index(); - int max_mesh_index = NOMAD::Mesh::get_max_mesh_index(); - int max_halton_index = NOMAD::Mesh::get_max_halton_index(); - - NOMAD::Mesh::init ( 4.0 , 1 , -1 , 0 ); - - // searches: - // model_param.set_LH_SEARCH ( 1000 , 100 ); - // model_param.set_OPPORTUNISTIC_LH ( true ); - // model_param.set_VNS_SEARCH ( true ); + // mesh: use isotropic mesh + model_param.set_ANISOTROPIC_MESH ( false ); + model_param.set_MESH_UPDATE_BASIS ( 4.0 ); + model_param.set_MESH_COARSENING_EXPONENT ( 1 ); + model_param.set_MESH_REFINING_EXPONENT ( -1 ); + model_param.set_INITIAL_MESH_INDEX ( 0 ); + // maximum number of evaluations (2000 or 10000): model_param.set_MAX_BB_EVAL ( ( _p.get_model_tgp_mode() == NOMAD::TGP_PRECISE ) ? 10000 : 2000 ); - // min mesh size: - // model_param.set_MAX_MESH_INDEX ( 30 ); - // model_param.set_MIN_MESH_SIZE ( NOMAD::Double ( 1e-8 ) , false ); - model_param.set_SNAP_TO_BOUNDS ( true ); - // model_param.set_SNAP_TO_BOUNDS ( false ); // disable user calls: model_param.set_USER_CALLS_ENABLED ( false ); @@ -1600,18 +1578,6 @@ bool NOMAD::TGP_Model_Search::optimize_model NOMAD::Mads::set_flag_reset_barriers ( flag_reset_barriers ); NOMAD::Mads::set_flag_p1_active ( flag_p1_active ); - // reset mesh to what it was before: - NOMAD::Mesh::init ( _p.get_mesh_update_basis().value() , - _p.get_mesh_coarsening_exponent() , - _p.get_mesh_refining_exponent() , - _p.get_initial_mesh_index() ); - - NOMAD::Mesh::set_max_halton_index ( max_halton_index ); - - NOMAD::Mesh::set_mesh_index ( min_mesh_index ); - NOMAD::Mesh::set_mesh_index ( max_mesh_index ); - NOMAD::Mesh::set_mesh_index ( mesh_index ); - // close display block: if ( display_degree == NOMAD::FULL_DISPLAY ) { if ( error ) diff --git a/src/TGP_Model_Search.hpp b/src/TGP_Model_Search.hpp index fe614ca746981d4ecd60096c9f0f33b9ae5dae0b..c31faf1ed2d83be410b2d997b428b500834677c2 100644 --- a/src/TGP_Model_Search.hpp +++ b/src/TGP_Model_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -205,14 +205,12 @@ namespace NOMAD { \param x The point coordinates -- \b IN. \param signature Signature -- \b IN. \param incumbent The incumbent -- \b IN. - \param mesh_index Mesh index -- \b IN. \param display_degree Display degree -- \b IN. \param ev_control The NOMAD::Evaluator_Control object -- \b IN/OUT. */ void register_point ( NOMAD::Point x , NOMAD::Signature & signature , - const NOMAD::Point & incumbent , - int mesh_index , + const NOMAD::Point & incumbent ,, NOMAD::dd_type display_degree , NOMAD::Evaluator_Control & ev_control ) const; diff --git a/src/TGP_Output_Model.cpp b/src/TGP_Output_Model.cpp index 569c1b57c0202a9fdec7f03031cfc1e474be286e..55152a1d6ea0194252f2b706ab4a69f9c6f3be1d 100644 --- a/src/TGP_Output_Model.cpp +++ b/src/TGP_Output_Model.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -52,7 +52,7 @@ int TGP_OUTPUT_MODEL_DUMMY; // avoids that TGP_Output_Model.o has no symbols wit /*---------------------------------------------------------*/ /* NOMAD-TGP callback function (called regularly by TGP) */ /*---------------------------------------------------------*/ -// SLD -- 2012-09-04 +// SLD -- 2014-09-04 // void NOMAD::TGP_callback ( bool & TGP_interrupt ) // { // if ( NOMAD::TGP_Output_Model::get_force_quit() ) @@ -225,7 +225,7 @@ void NOMAD::TGP_Output_Model::compute ( double ** X , NULL ); // dhier=NULL // set the NOMAD-TGP callback function: - // _tgp_model->set_callback ( NOMAD::TGP_callback ); // SLD -- 2012-09-04 + // _tgp_model->set_callback ( NOMAD::TGP_callback ); // SLD -- 2014-09-04 // TGP verbim (display): #ifdef TGP_DEBUG diff --git a/src/TGP_Output_Model.hpp b/src/TGP_Output_Model.hpp index ea892752732b47361b2935f4a12d94ea9b394e62..eaae843cd4fad3d4d14e4c6546e7ea17bdfa32a7 100644 --- a/src/TGP_Output_Model.hpp +++ b/src/TGP_Output_Model.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -62,7 +62,7 @@ extern "C" namespace NOMAD { // NOMAD-TGP callback function (called regularly by TGP). - // void TGP_callback ( bool & TGP_interrupt ); // SLD -- 2012-09-04 + // void TGP_callback ( bool & TGP_interrupt ); // SLD -- 2014-09-04 /// TGP models for one output. class TGP_Output_Model : private NOMAD::Uncopyable { diff --git a/src/Uncopyable.hpp b/src/Uncopyable.hpp index d14e567c5782aaabb2afc612d772637ce067ee65..64065a3b9a4927d4f17a24f8b753fb7a19c5ff1a 100644 --- a/src/Uncopyable.hpp +++ b/src/Uncopyable.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/VNS_Search.cpp b/src/VNS_Search.cpp index 343a4b1662b7435603c970d486ac7f1de0523c73..508057a6d60c40b6ce0f9e0eb5bce2e630aca079 100644 --- a/src/VNS_Search.cpp +++ b/src/VNS_Search.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -47,11 +47,9 @@ /*---------------------------------------------------------*/ void NOMAD::VNS_Search::reset ( void ) { - _k = _k_max = 1; - _halton_index = NOMAD::VNS_HALTON_INDEX_0; - _old_x = NULL; - for ( int ell = 0 ; ell <= NOMAD::L_LIMITS ; ++ell ) - _nb_performed[ell] = 0; + _k = _k_max = 1; + _old_x = NULL; + } /*---------------------------------------------------------*/ @@ -59,574 +57,580 @@ void NOMAD::VNS_Search::reset ( void ) /* VNS: x --[shaking(k)]--> x' --[descent]--> x" */ /*---------------------------------------------------------*/ void NOMAD::VNS_Search::search ( NOMAD::Mads & mads , - int & nb_search_pts , - bool & stop , - NOMAD::stop_type & stop_reason , - NOMAD::success_type & success , - bool & count_search , - const NOMAD::Eval_Point *& new_feas_inc , - const NOMAD::Eval_Point *& new_infeas_inc ) + int & nb_search_pts , + bool & stop , + NOMAD::stop_type & stop_reason , + NOMAD::success_type & success , + bool & count_search , + const NOMAD::Eval_Point *& new_feas_inc , + const NOMAD::Eval_Point *& new_infeas_inc ) { - new_feas_inc = new_infeas_inc = NULL; - nb_search_pts = 0; - success = NOMAD::UNSUCCESSFUL; - count_search = !stop; - - if ( stop ) - return; - - // initial display: - const NOMAD::Display & out = _p.out(); - NOMAD::dd_type display_degree = out.get_search_dd(); - if ( display_degree == NOMAD::FULL_DISPLAY ) { - std::ostringstream oss; - oss << NOMAD::VNS_SEARCH; - out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; - } - - bool opt_only_sgte = _p.get_opt_only_sgte(); - - // the barriers: - NOMAD::Barrier & true_barrier = mads.get_true_barrier(); - NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); - const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); - - // point x: - NOMAD::Double best_f; - bool x_feas = true; - const NOMAD::Eval_Point * x = active_barrier.get_best_feasible(); - if ( x ) - best_f = x->get_f(); - else { - x = active_barrier.get_best_infeasible(); - x_feas = false; - } - - if ( !x ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block ( "end of VNS search (no incumbent)" ); - return; - } - - // update _k and _old_x: - if ( x == _old_x ) { - ++_k; - if ( _k > _k_max ) - _k_max = _k; - } - else - _k = 1; - - _old_x = x; - - // get the signature: - NOMAD::Signature * signature = x->get_signature(); - if ( !signature ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block ( "end of VNS search (no signature)" ); - return; - } - - int n = signature->get_n(); - if ( n != x->size() ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block ( "end of VNS search (incompatible signature)" ); - return; - } - - // shaking: get ONE direction from the signature: - NOMAD::Direction dir; - signature->get_one_direction ( dir , - 1 - _k , // mesh_index = 1-k - _halton_index ); - - _halton_index += NOMAD::VNS_HALTON_INCR; - - // shaking: construct x': - NOMAD::Point xp = *x + dir; - - // shaking: the perturbation is tried twice with dir and -dir - // (in case x == x + dir after snapping) - for ( int nbt = 0 ; nbt < 2 ; ++nbt ) { - - // treat xp: periodic variables or bounds: - if ( _p.has_periodic_variables() ) { - NOMAD::Direction * tmp_dir = NULL; - signature->treat_periodic_variables ( xp , NULL , tmp_dir ); - } - else - signature->snap_to_bounds ( xp , NULL ); - - // if xp == x : - if ( xp == *x ) { - - // no third try: the search fails - if ( nbt == 1 ) { - if ( display_degree == NOMAD::FULL_DISPLAY ) - out.close_block ( "end of VNS search (shaking failed)" ); - return; - } - - // 2nd try (-dir instead of dir): - xp = *x - dir; - } - } - - // current mesh index: - int mesh_index = NOMAD::Mesh::get_mesh_index(); - - // reset mesh index: - int initial_mesh_index = _p.get_initial_mesh_index(); - NOMAD::Mesh::set_mesh_index ( initial_mesh_index ); - - // stats: - NOMAD::Stats & stats = mads.get_stats(); - - // current number of blackbox evaluations: - int bbe = stats.get_bb_eval(); - int sgte_eval = stats.get_sgte_eval(); - int mads_iterations = stats.get_iterations(); - bool has_sgte = _p.has_sgte(); - - // displays: - if ( display_degree == NOMAD::FULL_DISPLAY ) { - out << " it = " << mads_iterations << std::endl - << " bbe = " << bbe << std::endl; - if ( has_sgte ) - out << " sgte_eval = " << sgte_eval << std::endl; - out << "mesh_index = " << mesh_index << std::endl - << " k = " << _k << std::endl - << " kmax = " << _k_max << std::endl - << " x = ( "; - x->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " ) f=" << x->get_f() << " h=" << x->get_h() << std::endl - << " dir = ( "; - dir.Point::display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " ) |dir|="; - NOMAD::Double norm = dir.norm(); - out << norm << std::endl; - out << " xp = ( "; - xp.display ( out , " " , 5 , _p.get_point_display_limit() ); - out << " )" << std::endl << std::endl; - out << "bb_eval (before+VNS only) objective_value" - << std::endl << std::endl; - } - - // save parameters that are going to be modified: - // ---------------------------------------------- - std::string old_display_degree; - _p.out().get_display_degree ( old_display_degree ); - - NOMAD::model_params_type old_mp; - _p.get_model_parameters ( old_mp ); - - bool old_ses = _p.get_sgte_eval_sort(); - bool old_sif = _p.get_stop_if_feasible(); - int old_hs = _p.get_halton_seed(); - int old_max_time = _p.get_max_time(); - int old_max_mesh_index = _p.get_max_mesh_index(); - int old_max_bbe = _p.get_max_bb_eval(); - int old_max_eval = _p.get_max_eval(); - int old_max_sgte_eval = _p.get_max_sgte_eval(); - int old_max_it = _p.get_max_iterations(); - int old_max_cfi = _p.get_max_consecutive_failed_iterations(); - int old_LH_p0 = _p.get_LH_search_p0(); - int old_LH_pi = _p.get_LH_search_pi(); - bool old_opp_LH = _p.get_opportunistic_LH(); - bool old_CS = _p.get_cache_search(); - bool old_opp_CS = _p.get_opportunistic_cache_search(); - int old_max_sbe = _p.get_max_sim_bb_eval(); - NOMAD::Double old_sst = _p.get_stat_sum_target(); - NOMAD::Double old_lct = _p.get_L_curve_target(); - NOMAD::Double old_trigger = _p.get_VNS_trigger(); - NOMAD::Point old_ft = _p.get_f_target(); - const std::list<std::string> old_ds = _p.get_display_stats(); - const std::list<std::string> old_stats_file = _p.get_stats_file(); - const std::string old_stats_file_name = _p.get_stats_file_name(); - const std::string old_sol_file = _p.get_solution_file(); - const std::string old_his_file = _p.get_history_file(); - bool old_uce = _p.get_user_calls_enabled(); - bool old_epe = _p.get_extended_poll_enabled(); - const std::vector<NOMAD::bb_output_type> old_bbot = _p.get_bb_output_type(); - - - - // save list of starting points: - std::string x0_cache_file = _p.get_x0_cache_file(); - std::vector<NOMAD::Point *> x0s; - { - const std::vector<NOMAD::Point *> & x0s_tmp = _p.get_x0s(); - size_t nx0 = x0s_tmp.size() , k; - for ( k = 0 ; k < nx0 ; ++k ) - x0s.push_back ( new Point ( *x0s_tmp[k] ) ); - } - - // modify parameters: - // ------------------ - if (display_degree == NOMAD::FULL_DISPLAY) - _p.set_DISPLAY_DEGREE(NOMAD::NORMAL_DISPLAY); - else if (display_degree == NOMAD::NORMAL_DISPLAY) - _p.set_DISPLAY_DEGREE(NOMAD::MINIMAL_DISPLAY); - else - _p.set_DISPLAY_DEGREE(display_degree); - - - _p.set_HALTON_SEED ( NOMAD::Mesh::get_max_halton_index() ); - _p.set_SOLUTION_FILE ( "" ); - _p.set_LH_SEARCH ( 0 , 0 ); - _p.set_VNS_SEARCH ( false ); - _p.set_CACHE_SEARCH ( false ); - _p.set_MAX_ITERATIONS ( -1 ); - _p.set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( -1 ); - _p.reset_X0(); - _p.reset_stats_file(); - - - if ( has_sgte ) { - _p.set_OPT_ONLY_SGTE ( true ); - _p.set_MODEL_SEARCH ( NOMAD::NO_MODEL ); - _p.set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); - } - - _p.set_USER_CALLS_ENABLED ( false ); - _p.set_EXTENDED_POLL_ENABLED ( false ); - - // DISPLAY_STATS: - { - if ( has_sgte ) - _p.set_DISPLAY_STATS ( NOMAD::itos(sgte_eval) + "+SGTE OBJ (VNS--surrogate)" ); - else - { - std::list<std::string> ds = old_ds; - std::list<std::string>::iterator it = ds.begin(); - std::list<std::string>::const_iterator end = ds.end(); - std::string s_bbe = NOMAD::itos(bbe) + "+"; - while ( it != end ) - { - if ( *it == "BBE" ) - ds.insert ( it , s_bbe ); - ++it; - } - ds.push_back ( " (VNS)" ); - _p.set_DISPLAY_STATS ( ds ); - } - } - - // STATS_FILE: - { - std::list<std::string> sf = old_stats_file; - std::list<std::string>::iterator it = sf.begin(); - std::list<std::string>::const_iterator end = sf.end(); - std::string s_bbe = NOMAD::itos(bbe) + "+"; - while ( it != end ) - { - if ( *it == "BBE" ) - sf.insert ( it , s_bbe ); - ++it; - } - sf.push_back ( " (VNS)" ); - _p.set_STATS_FILE ( old_stats_file_name , sf ); - } - - - // mesh: - _p.set_MAX_MESH_INDEX ( (mesh_index > initial_mesh_index) ? - mesh_index : initial_mesh_index); - - // X0: - _p.set_EXTERN_SIGNATURE ( signature ); - _p.set_X0 ( xp ); - - // MAX_BB_EVAL: - if ( old_max_bbe < 0 ) - _p.set_MAX_BB_EVAL ( 100 * n ); - else - _p.set_MAX_BB_EVAL ( old_max_bbe - bbe ); - - // MAX_SGTE_EVAL: - if ( old_max_sgte_eval > 0 ) - _p.set_MAX_SGTE_EVAL ( old_max_sgte_eval - sgte_eval ); - - // MAX_EVAL: - if ( old_max_eval > 0 ) - _p.set_MAX_EVAL ( old_max_eval - stats.get_eval() ); - - // MAX_SIM_BB_EVAL: - if ( old_max_sbe > 0 ) - _p.set_MAX_SIM_BB_EVAL ( old_max_sbe - stats.get_sim_bb_eval() ); - - // STAT_SUM_TARGET: - if ( old_sst.is_defined() ) - _p.set_STAT_SUM_TARGET ( old_sst - stats.get_stat_sum() ); - - // MAX_TIME: - if ( old_max_time > 0 ) - _p.set_MAX_TIME ( old_max_time - stats.get_real_time() ); - - // L_CURVE_TARGET: - if ( !has_sgte ) - _p.set_L_CURVE_TARGET ( best_f ); - - // F_TARGET and STOP_IF_FEASIBLE: - if ( has_sgte ) { - _p.reset_f_target(); - _p.set_STOP_IF_FEASIBLE ( false ); - } - - // check the parameters: - _p.check ( false , // remove_history_file = false - false , // remove_solution_file = false - false ); // remove_stats_file = false - - // Evaluator_Control: - NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); - - // descent: run MADS: - // ------------------ - NOMAD::Mads VNS_mads ( _p , - ev_control.get_evaluator () , - mads.get_extended_poll () , - &ev_control.get_cache () , - &ev_control.get_sgte_cache() ); - - NOMAD::Mads::set_flag_reset_mesh ( false ); - NOMAD::Mads::set_flag_reset_barriers ( true ); - - NOMAD::stop_type st = VNS_mads.run(); - - NOMAD::Mads::set_flag_reset_mesh ( true ); - - // update stats: - { - const NOMAD::Stats & VNS_stats = VNS_mads.get_stats(); - stats.update ( VNS_stats , true ); // for_search = true - stats.add_VNS_bb_eval ( VNS_stats.get_bb_eval () ); - stats.add_VNS_sgte_eval ( VNS_stats.get_sgte_eval() ); - } - - // check MADS stopping criteria: - if ( st == NOMAD::CTRL_C || - st == NOMAD::ERROR || - st == NOMAD::UNKNOWN_STOP_REASON || - st == NOMAD::FEAS_REACHED || - st == NOMAD::MAX_CACHE_MEMORY_REACHED || - st == NOMAD::STAT_SUM_TARGET_REACHED || - st == NOMAD::MAX_SGTE_EVAL_REACHED || - st == NOMAD::F_TARGET_REACHED || - st == NOMAD::MAX_SIM_BB_EVAL_REACHED || - st == NOMAD::MAX_TIME_REACHED || - (st == NOMAD::MAX_BB_EVAL_REACHED && old_max_bbe > 0 ) ) { - stop_reason = st; - stop = true; - } - - // Pareto front: - NOMAD::Pareto_Front * pareto_front = mads.get_pareto_front(); - - // restore starting points: - { - _p.reset_X0(); - size_t nx0 = x0s.size(); - - if ( nx0 > 0 ) { - for ( size_t k = 0 ; k < nx0 ; ++k ) { - _p.set_X0 ( *x0s[k] ); - delete x0s[k]; - } - } - else if ( !x0_cache_file.empty() ) - _p.set_X0 ( x0_cache_file ); - } - - // restore other saved parameters: - _p.set_model_parameters ( old_mp ); - _p.set_USER_CALLS_ENABLED ( old_uce ); - _p.set_EXTENDED_POLL_ENABLED ( old_epe ); - _p.set_VNS_SEARCH ( old_trigger ); - _p.set_F_TARGET ( old_ft ); - _p.set_STOP_IF_FEASIBLE ( old_sif ); - _p.set_L_CURVE_TARGET ( old_lct ); - _p.set_DISPLAY_DEGREE ( old_display_degree ); - _p.set_DISPLAY_STATS ( old_ds ); - _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); - _p.set_SOLUTION_FILE ( old_sol_file ); - _p.set_MAX_BB_EVAL ( old_max_bbe ); - _p.set_MAX_EVAL ( old_max_eval ); - _p.set_MAX_SGTE_EVAL ( old_max_sgte_eval ); - _p.set_MAX_ITERATIONS ( old_max_it ); - _p.set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( old_max_cfi ); - _p.set_STAT_SUM_TARGET ( old_sst ); - _p.set_LH_SEARCH ( old_LH_p0 , old_LH_pi ); - _p.set_OPPORTUNISTIC_LH ( old_opp_LH ); - _p.set_CACHE_SEARCH ( old_CS ); - _p.set_OPPORTUNISTIC_CACHE_SEARCH ( old_opp_CS ); - _p.set_MAX_SIM_BB_EVAL ( old_max_sbe ); - _p.set_MAX_MESH_INDEX ( old_max_mesh_index ); - _p.set_HALTON_SEED ( old_hs ); - _p.set_MAX_TIME ( old_max_time ); - _p.set_SGTE_EVAL_SORT ( old_ses ); - _p.set_OPT_ONLY_SGTE ( opt_only_sgte ); - _p.set_BB_OUTPUT_TYPE ( old_bbot ); - - - - _p.check ( false , // remove_history_file = false - false , // remove_solution_file = false - false ); // remove_stats_file = false - - // restore mesh index: - NOMAD::Mesh::set_mesh_index ( mesh_index ); - - // surrogate evaluations: perform only one true evaluation: - if ( has_sgte && !opt_only_sgte ) - { - - if ( !stop ) - { - - // remember old best surrogates incumbents: - const NOMAD::Eval_Point * old_sgte_bf = sgte_barrier.get_best_feasible (); - const NOMAD::Eval_Point * old_sgte_bi = sgte_barrier.get_best_infeasible(); - - // update the surrogate barrier - // (no need to invoke Evaluator_Control::process_barrier_points() here - // since only surrogate evaluations have been made): - sgte_barrier.insert ( VNS_mads.get_sgte_barrier() ); - NOMAD::success_type sgte_succ = sgte_barrier.get_success(); - sgte_barrier.update_and_reset_success(); - - // we generate only a true trial point if the - // surrogates improved the surrogate barrier: - if ( sgte_succ != NOMAD::UNSUCCESSFUL ) - { - - // choose the best surrogate point(s) where to evaluate the true function: - const NOMAD::Eval_Point * sgte_bf = sgte_barrier.get_best_feasible (); - const NOMAD::Eval_Point * sgte_bi = sgte_barrier.get_best_infeasible(); - - std::list<const NOMAD::Eval_Point *> candidates; - - if ( sgte_bf && ( !x_feas || sgte_bf != old_sgte_bf ) ) - candidates.push_back ( sgte_bf ); - - if ( sgte_bi && sgte_bi != old_sgte_bi ) - candidates.push_back ( sgte_bi ); - - // generate the new trial points: - NOMAD::Eval_Point * sk; - std::list<const NOMAD::Eval_Point *>::const_iterator - it , end = candidates.end(); - for ( it = candidates.begin() ; it != end ; ++it ) - { - - // display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - out << std::endl << "VNS surrogate candidate: " - << **it << std::endl; - - sk = new NOMAD::Eval_Point; - sk->set ( n , _p.get_bb_nb_outputs() ); - sk->set_signature ( signature ); - sk->set_mesh_index ( &mesh_index ); - sk->Point::operator = ( **it ); - - // add the new point to the list of search trial points: - ev_control.add_eval_point ( sk , - display_degree , - _p.get_snap_to_bounds() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() , - NOMAD::Double() ); - } - - // eval_list_of_points: - // -------------------- - success = NOMAD::UNSUCCESSFUL; - new_feas_inc = new_infeas_inc = NULL; - - ev_control.eval_list_of_points ( _type , - true_barrier , - sgte_barrier , - pareto_front , - stop , - stop_reason , - new_feas_inc , - new_infeas_inc , - success ); - - // number of search points (0 or 1 or 2): - nb_search_pts = static_cast<int> ( candidates.size() ); - } - } - } - - // true evaluations (or surrogate evaluations if opt_only_sgte==true): - else - { - - // for the update of new_feas_inc and new_infeas_inc (1/2): - const NOMAD::Eval_Point * old_feasible_incumbent = - active_barrier.get_best_feasible(); - const NOMAD::Eval_Point * old_infeasible_incumbent = - active_barrier.get_best_infeasible(); - - // update barriers and process VNS search points: - NOMAD::success_type sgte_succ - = ev_control.process_barrier_points ( sgte_barrier , - VNS_mads.get_sgte_barrier() , - pareto_front , - display_degree , - NOMAD::VNS_SEARCH ); - NOMAD::success_type true_succ - = ev_control.process_barrier_points ( true_barrier , - VNS_mads.get_true_barrier() , - pareto_front , - display_degree , - NOMAD::VNS_SEARCH ); - - // update of new_feas_inc and new_infeas_inc (2/2): - const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); - const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); - if ( bf && bf != old_feasible_incumbent ) - new_feas_inc = bf; - - if ( bi && bi != old_infeasible_incumbent ) - { - new_infeas_inc = bi; - // check the PEB constraints: if we have a new best infeasible - // incumbent from another infeasible incumbent - if ( _p.get_barrier_type() == NOMAD::PEB_P ) - ( ( _p.get_opt_only_sgte() ) ? sgte_barrier : true_barrier ).check_PEB_constraints ( *new_infeas_inc , display_degree==NOMAD::FULL_DISPLAY ); - } - - // number of search points and success: - if ( opt_only_sgte ) - { - nb_search_pts = VNS_mads.get_stats().get_sgte_eval(); - success = sgte_succ; - } - else - { - nb_search_pts = VNS_mads.get_stats().get_eval(); - success = true_succ; - } - - // solution file: - if ( bf ) - ev_control.write_solution_file ( *bf ); - - } - - // update _nb_performed: - if ( mesh_index > 0 ) - ++_nb_performed [ mesh_index ]; - - // final display: - if ( display_degree == NOMAD::FULL_DISPLAY ) - { - std::ostringstream oss; - oss << "end of VNS search (" << success << ")"; - out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; - } + new_feas_inc = new_infeas_inc = NULL; + nb_search_pts = 0; + success = NOMAD::UNSUCCESSFUL; + count_search = !stop; + + if ( stop ) + return; + + // initial display: + const NOMAD::Display & out = _p.out(); + NOMAD::dd_type display_degree = out.get_search_dd(); + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << NOMAD::VNS_SEARCH; + out << std::endl << NOMAD::open_block ( oss.str() ) << std::endl; + } + + bool opt_only_sgte = _p.get_opt_only_sgte(); + + // the barriers: + NOMAD::Barrier & true_barrier = mads.get_true_barrier(); + NOMAD::Barrier & sgte_barrier = mads.get_sgte_barrier(); + const NOMAD::Barrier & active_barrier = mads.get_active_barrier(); + + // point x: + NOMAD::Double best_f; + bool x_feas = true; + const NOMAD::Eval_Point * x = active_barrier.get_best_feasible(); + if ( x ) + best_f = x->get_f(); + else + { + x = active_barrier.get_best_infeasible(); + x_feas = false; + } + + if ( !x ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block ( "end of VNS search (no incumbent)" ); + return; + } + + // update _k and _old_x: + if ( x == _old_x ) + { + ++_k; + if ( _k > _k_max ) + _k_max = _k; + } + else + _k = 1; + + _old_x = x; + + // get the signature: + NOMAD::Signature * signature = x->get_signature(); + if ( !signature ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block ( "end of VNS search (no signature)" ); + return; + } + + int n = signature->get_n(); + if ( n != x->size() ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block ( "end of VNS search (incompatible signature)" ); + return; + } + + // shaking: get ONE direction from the signature: + NOMAD::Direction dir; + + signature->get_one_direction ( dir , _k - 1); + + + // shaking: construct x': + NOMAD::Point xp = *x + dir; + + // shaking: the perturbation is tried twice with dir and -dir + // (in case x == x + dir after snapping) + for ( int nbt = 0 ; nbt < 2 ; ++nbt ) + { + + // treat xp: periodic variables or bounds: + if ( _p.has_periodic_variables() ) + { + NOMAD::Direction * tmp_dir = NULL; + signature->treat_periodic_variables ( xp , NULL , tmp_dir ); + } + else + signature->snap_to_bounds ( xp , NULL ); + + if ( xp == *x ) + { + + // no third try: the search fails + if ( nbt == 1 ) + { + if ( display_degree == NOMAD::FULL_DISPLAY ) + out.close_block ( "end of VNS search (shaking failed)" ); + return; + } + + // 2nd try (-dir instead of dir): + xp = *x - dir; + } + } + + // Current mesh indices + const NOMAD::Point old_mesh_indices = signature->get_mesh()->get_mesh_indices ( ); + const NOMAD::Point old_delta_min = signature->get_mesh()->get_min_mesh_size(); + + + // stats: + NOMAD::Stats & stats = mads.get_stats(); + + // current number of blackbox evaluations: + int bbe = stats.get_bb_eval(); + int blk_eva = stats.get_block_eval(); + int sgte_eval = stats.get_sgte_eval(); + int mads_iterations = stats.get_iterations(); + bool has_sgte = _p.has_sgte(); + + // displays: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + out << " it = " << mads_iterations << std::endl + << " bbe = " << bbe << std::endl + << " blk_eva = " << blk_eva << std::endl; + if ( has_sgte ) + out << " sgte_eval = " << sgte_eval << std::endl; + out << "mesh_indices = ( " << old_mesh_indices << " ) " << std::endl + << " k = " << _k << std::endl + << " kmax = " << _k_max << std::endl + << " x = ( "; + x->Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " ) f=" << x->get_f() << " h=" << x->get_h() << std::endl + << " dir = ( "; + dir.Point::display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " ) |dir|="; + NOMAD::Double norm = dir.norm(); + out << norm << std::endl; + out << " xp = ( "; + xp.display ( out , " " , 5 , _p.get_point_display_limit() ); + out << " )" << std::endl << std::endl; + out << "bb_eval (before+VNS only) objective_value" + << std::endl << std::endl; + } + + // save parameters that are going to be modified: + // ---------------------------------------------- + std::string old_display_degree; + _p.out().get_display_degree ( old_display_degree ); + + NOMAD::model_params_type old_mp; + _p.get_model_parameters ( old_mp ); + + bool old_ses = _p.get_sgte_eval_sort(); + bool old_sif = _p.get_stop_if_feasible(); + int old_max_time = _p.get_max_time(); + int old_max_bbe = _p.get_max_bb_eval(); + int old_max_eval = _p.get_max_eval(); + int old_max_sgte_eval = _p.get_max_sgte_eval(); + int old_max_it = _p.get_max_iterations(); + int old_max_cfi = _p.get_max_consecutive_failed_iterations(); + int old_LH_p0 = _p.get_LH_search_p0(); + int old_LH_pi = _p.get_LH_search_pi(); + bool old_opp_LH = _p.get_opportunistic_LH(); + bool old_CS = _p.get_cache_search(); + bool old_opp_CS = _p.get_opportunistic_cache_search(); + int old_max_sbe = _p.get_max_sim_bb_eval(); + NOMAD::Double old_sst = _p.get_stat_sum_target(); + NOMAD::Double old_lct = _p.get_L_curve_target(); + NOMAD::Double old_trigger = _p.get_VNS_trigger(); + NOMAD::Point old_ft = _p.get_f_target(); + const std::list<std::string> old_ds = _p.get_display_stats(); + const std::list<std::string> old_stats_file = _p.get_stats_file(); + const std::string old_stats_file_name = _p.get_stats_file_name(); + const std::string old_sol_file = _p.get_solution_file(); + const std::string old_his_file = _p.get_history_file(); + bool old_uce = _p.get_user_calls_enabled(); + bool old_epe = _p.get_extended_poll_enabled(); + const std::vector<NOMAD::bb_output_type> old_bbot = _p.get_bb_output_type(); + + // save list of starting points: + std::string x0_cache_file = _p.get_x0_cache_file(); + std::vector<NOMAD::Point *> x0s; + { + const std::vector<NOMAD::Point *> & x0s_tmp = _p.get_x0s(); + size_t nx0 = x0s_tmp.size() , k; + for ( k = 0 ; k < nx0 ; ++k ) + x0s.push_back ( new Point ( *x0s_tmp[k] ) ); + } + + // modify parameters: + // ------------------ + _p.set_DISPLAY_DEGREE(NOMAD::NO_DISPLAY); + + _p.set_SOLUTION_FILE ( "" ); + _p.set_LH_SEARCH ( 0 , 0 ); + _p.set_VNS_SEARCH ( false ); + _p.set_CACHE_SEARCH ( false ); + _p.set_MAX_ITERATIONS ( -1 ); + _p.set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( -1 ); + _p.reset_X0(); + _p.reset_stats_file(); + + + if ( has_sgte ) + { + _p.set_OPT_ONLY_SGTE ( true ); + _p.set_MODEL_SEARCH ( NOMAD::NO_MODEL ); + _p.set_MODEL_EVAL_SORT ( NOMAD::NO_MODEL ); + } + + _p.set_USER_CALLS_ENABLED ( false ); + _p.set_EXTENDED_POLL_ENABLED ( false ); + + // DISPLAY_STATS: + { + if ( has_sgte ) + _p.set_DISPLAY_STATS ( NOMAD::itos(sgte_eval) + "+SGTE OBJ (VNS--surrogate)" ); + else + { + std::list<std::string> ds = old_ds; + std::list<std::string>::iterator it = ds.begin(); + std::list<std::string>::const_iterator end = ds.end(); + std::string s_bbe = NOMAD::itos(bbe) + "+"; + std::string s_blk = NOMAD::itos(blk_eva) + "+"; + while ( it != end ) + { + if ( *it == "BBE" ) + ds.insert ( it , s_bbe ); + if ( *it == "BLK_EVA" ) + ds.insert ( it , s_blk ); + ++it; + } + ds.push_back ( " (VNS)" ); + _p.set_DISPLAY_STATS ( ds ); + } + } + + // STATS_FILE: + { + std::list<std::string> sf = old_stats_file; + std::list<std::string>::iterator it = sf.begin(); + std::list<std::string>::const_iterator end = sf.end(); + std::string s_bbe = NOMAD::itos(bbe) + "+"; + std::string s_blk = NOMAD::itos(blk_eva) + "+"; + while ( it != end ) + { + if ( *it == "BBE" ) + sf.insert ( it , s_bbe ); + if ( *it == "BLK_EVA" ) + sf.insert ( it , s_blk ); + ++it; + } + sf.push_back ( " (VNS)" ); + + _p.set_STATS_FILE( old_stats_file_name, sf); + } + + + // Mesh size at current mads iterate can be used as termination criterion for vns search. + // Mesh indices are reinitialized during p.check() + NOMAD::Point delta=signature->get_mesh()->get_delta ( ); + signature->get_mesh()->set_min_mesh_sizes( delta ); + + + // X0: + _p.set_EXTERN_SIGNATURE ( signature ); + _p.set_X0 ( xp ); + + // MAX_BB_EVAL: + if ( old_max_bbe < 0 ) + _p.set_MAX_BB_EVAL ( 100 * n ); + else + _p.set_MAX_BB_EVAL ( old_max_bbe - bbe ); + + // MAX_SGTE_EVAL: + if ( old_max_sgte_eval > 0 ) + _p.set_MAX_SGTE_EVAL ( old_max_sgte_eval - sgte_eval ); + + // MAX_EVAL: + if ( old_max_eval > 0 ) + _p.set_MAX_EVAL ( old_max_eval - stats.get_eval() ); + + // MAX_SIM_BB_EVAL: + if ( old_max_sbe > 0 ) + _p.set_MAX_SIM_BB_EVAL ( old_max_sbe - stats.get_sim_bb_eval() ); + + // STAT_SUM_TARGET: + if ( old_sst.is_defined() ) + _p.set_STAT_SUM_TARGET ( old_sst - stats.get_stat_sum() ); + + // MAX_TIME: + if ( old_max_time > 0 ) + _p.set_MAX_TIME ( old_max_time - stats.get_real_time() ); + + // L_CURVE_TARGET: + if ( !has_sgte ) + _p.set_L_CURVE_TARGET ( best_f ); + + // F_TARGET and STOP_IF_FEASIBLE: + if ( has_sgte ) + { + _p.reset_f_target(); + _p.set_STOP_IF_FEASIBLE ( false ); + } + + // check the parameters: + _p.check ( false , // remove_history_file = false + false , // remove_solution_file = false + false ); // remove_stats_file = false + + // Evaluator_Control: + NOMAD::Evaluator_Control & ev_control = mads.get_evaluator_control(); + + // descent: run MADS: + // ------------------ + NOMAD::Mads VNS_mads ( _p , + ev_control.get_evaluator () , + mads.get_extended_poll () , + &ev_control.get_cache () , + &ev_control.get_sgte_cache() ); + NOMAD::Mads::set_flag_reset_mesh ( false ); + NOMAD::Mads::set_flag_reset_barriers ( true ); + + NOMAD::stop_type st = VNS_mads.run(); + + NOMAD::Mads::set_flag_reset_mesh ( true ); + + // update stats: + { + const NOMAD::Stats & VNS_stats = VNS_mads.get_stats(); + stats.update ( VNS_stats , true ); // for_search = true + stats.add_VNS_bb_eval ( VNS_stats.get_bb_eval () ); + stats.add_VNS_sgte_eval ( VNS_stats.get_sgte_eval() ); + } + + // check MADS stopping criteria: + if ( st == NOMAD::CTRL_C || + st == NOMAD::ERROR || + st == NOMAD::UNKNOWN_STOP_REASON || + st == NOMAD::FEAS_REACHED || + st == NOMAD::MAX_CACHE_MEMORY_REACHED || + st == NOMAD::STAT_SUM_TARGET_REACHED || + st == NOMAD::MAX_SGTE_EVAL_REACHED || + st == NOMAD::F_TARGET_REACHED || + st == NOMAD::MAX_SIM_BB_EVAL_REACHED || + st == NOMAD::MAX_TIME_REACHED || + (st == NOMAD::MAX_BB_EVAL_REACHED && old_max_bbe > 0 ) ) + { + stop_reason = st; + stop = true; + } + + // Pareto front: + NOMAD::Pareto_Front * pareto_front = mads.get_pareto_front(); + + // restore starting points: + { + _p.reset_X0(); + size_t nx0 = x0s.size(); + + if ( nx0 > 0 ) + { + + for ( size_t k = 0 ; k < nx0 ; ++k ) + { + _p.set_X0 ( *x0s[k] ); + delete x0s[k]; + } + } + else if ( !x0_cache_file.empty() ) + _p.set_X0 ( x0_cache_file ); + } + + // restore other saved parameters: + _p.set_model_parameters ( old_mp ); + _p.set_USER_CALLS_ENABLED ( old_uce ); + _p.set_EXTENDED_POLL_ENABLED ( old_epe ); + _p.set_VNS_SEARCH ( old_trigger ); + _p.set_F_TARGET ( old_ft ); + _p.set_STOP_IF_FEASIBLE ( old_sif ); + _p.set_L_CURVE_TARGET ( old_lct ); + _p.set_DISPLAY_DEGREE ( old_display_degree ); + _p.set_DISPLAY_STATS ( old_ds ); + _p.set_STATS_FILE ( old_stats_file_name , old_stats_file ); + _p.set_SOLUTION_FILE ( old_sol_file ); + _p.set_MAX_BB_EVAL ( old_max_bbe ); + _p.set_MAX_EVAL ( old_max_eval ); + _p.set_MAX_SGTE_EVAL ( old_max_sgte_eval ); + _p.set_MAX_ITERATIONS ( old_max_it ); + _p.set_MAX_CONSECUTIVE_FAILED_ITERATIONS ( old_max_cfi ); + _p.set_STAT_SUM_TARGET ( old_sst ); + _p.set_LH_SEARCH ( old_LH_p0 , old_LH_pi ); + _p.set_OPPORTUNISTIC_LH ( old_opp_LH ); + _p.set_CACHE_SEARCH ( old_CS ); + _p.set_OPPORTUNISTIC_CACHE_SEARCH ( old_opp_CS ); + _p.set_MAX_SIM_BB_EVAL ( old_max_sbe ); + _p.set_MAX_TIME ( old_max_time ); + _p.set_SGTE_EVAL_SORT ( old_ses ); + _p.set_OPT_ONLY_SGTE ( opt_only_sgte ); + _p.set_BB_OUTPUT_TYPE ( old_bbot ); + + + _p.check ( false , // remove_history_file = false + false , // remove_solution_file = false + false ); // remove_stats_file = false + + // restore min mesh sizes and mesh indices + signature->get_mesh()->set_min_mesh_sizes( old_delta_min ); + signature->get_mesh()->set_mesh_indices( old_mesh_indices ); // Needed because mesh indices reinitialized during p.check() + + + // surrogate evaluations: perform only one true evaluation: + if ( has_sgte && !opt_only_sgte ) + { + + if ( !stop ) + { + + // remember old best surrogates incumbents: + const NOMAD::Eval_Point * old_sgte_bf = sgte_barrier.get_best_feasible (); + const NOMAD::Eval_Point * old_sgte_bi = sgte_barrier.get_best_infeasible(); + + // update the surrogate barrier + // (no need to invoke Evaluator_Control::process_barrier_points() here + // since only surrogate evaluations have been made): + sgte_barrier.insert ( VNS_mads.get_sgte_barrier() ); + NOMAD::success_type sgte_succ = sgte_barrier.get_success(); + sgte_barrier.update_and_reset_success(); + + // we generate only a true trial point if the + // surrogates improved the surrogate barrier: + if ( sgte_succ != NOMAD::UNSUCCESSFUL ) + { + + // choose the best surrogate point(s) where to evaluate the true function: + const NOMAD::Eval_Point * sgte_bf = sgte_barrier.get_best_feasible (); + const NOMAD::Eval_Point * sgte_bi = sgte_barrier.get_best_infeasible(); + + std::list<const NOMAD::Eval_Point *> candidates; + + if ( sgte_bf && ( !x_feas || sgte_bf != old_sgte_bf ) ) + candidates.push_back ( sgte_bf ); + + if ( sgte_bi && sgte_bi != old_sgte_bi ) + candidates.push_back ( sgte_bi ); + + // generate the new trial points: + NOMAD::Eval_Point * sk; + std::list<const NOMAD::Eval_Point *>::const_iterator + it , end = candidates.end(); + for ( it = candidates.begin() ; it != end ; ++it ) + { + + // display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + out << std::endl << "VNS surrogate candidate: " + << **it << std::endl; + + sk = new NOMAD::Eval_Point; + sk->set ( n , _p.get_bb_nb_outputs() ); + sk->set_signature ( signature ); + sk->Point::operator = ( **it ); + + // add the new point to the list of search trial points: + ev_control.add_eval_point ( sk , + display_degree , + _p.get_snap_to_bounds() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() , + NOMAD::Double() ); + } + + // eval_list_of_points: + // -------------------- + success = NOMAD::UNSUCCESSFUL; + new_feas_inc = new_infeas_inc = NULL; + + ev_control.eval_list_of_points ( _type , + true_barrier , + sgte_barrier , + pareto_front , + stop , + stop_reason , + new_feas_inc , + new_infeas_inc , + success ); + + // number of search points (0 or 1 or 2): + nb_search_pts = static_cast<int> ( candidates.size() ); + } + } + } + + // true evaluations (or surrogate evaluations if opt_only_sgte==true): + else + { + + // for the update of new_feas_inc and new_infeas_inc (1/2): + const NOMAD::Eval_Point * old_feasible_incumbent = + active_barrier.get_best_feasible(); + const NOMAD::Eval_Point * old_infeasible_incumbent = + active_barrier.get_best_infeasible(); + + // update barriers and process VNS search points: + NOMAD::success_type sgte_succ + = ev_control.process_barrier_points ( sgte_barrier , + VNS_mads.get_sgte_barrier() , + pareto_front , + display_degree , + NOMAD::VNS_SEARCH ); + NOMAD::success_type true_succ + = ev_control.process_barrier_points ( true_barrier , + VNS_mads.get_true_barrier() , + pareto_front , + display_degree , + NOMAD::VNS_SEARCH ); + + // update of new_feas_inc and new_infeas_inc (2/2): + const NOMAD::Eval_Point * bf = active_barrier.get_best_feasible (); + const NOMAD::Eval_Point * bi = active_barrier.get_best_infeasible(); + if ( bf && bf != old_feasible_incumbent ) + new_feas_inc = bf; + + if ( bi && bi != old_infeasible_incumbent ) + { + new_infeas_inc = bi; + // check the PEB constraints: if we have a new best infeasible + // incumbent from another infeasible incumbent + // ( active_barrier.check_PEB_constraints() ): + if ( _p.get_barrier_type() == NOMAD::PEB_P ) + ( ( _p.get_opt_only_sgte() ) ? sgte_barrier : true_barrier ).check_PEB_constraints ( *new_infeas_inc , display_degree==NOMAD::FULL_DISPLAY ); + } + + // number of search points and success: + if ( opt_only_sgte ) + { + nb_search_pts = VNS_mads.get_stats().get_sgte_eval(); + success = sgte_succ; + } + else + { + nb_search_pts = VNS_mads.get_stats().get_eval(); + success = true_succ; + } + + // solution file: + if ( bf ) + ev_control.write_solution_file ( *bf ); + + } + + // final display: + if ( display_degree == NOMAD::FULL_DISPLAY ) + { + std::ostringstream oss; + oss << "end of VNS search (" << success << ")"; + out << std::endl << NOMAD::close_block ( oss.str() ) << std::endl; + } } diff --git a/src/VNS_Search.hpp b/src/VNS_Search.hpp index 26cead63acb7fa21947ddb809224d705bd50de14..f74a3fe859c20ad61f25e7e99e03470c13a109fc 100644 --- a/src/VNS_Search.hpp +++ b/src/VNS_Search.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -55,15 +55,8 @@ namespace NOMAD { int _k; ///< VNS neighborhood parameter. int _k_max; ///< Maximum value of \c _k. - int _halton_index; ///< Halton index used for shaking directions. const NOMAD::Eval_Point * _old_x; ///< Previous reference point (updates \c _k). - /// Search frequency. - /** - \c _nb_performed[ell] corresponds to the number of times that - the VNS search has been performed on a mesh of a size \c ell. - */ - int _nb_performed [NOMAD::L_LIMITS+1]; public: @@ -75,7 +68,6 @@ namespace NOMAD { : NOMAD::Search ( p , NOMAD::VNS_SEARCH ) , _k ( 1 ) , _k_max ( 1 ) , - _halton_index ( NOMAD::VNS_HALTON_INDEX_0 ) , _old_x ( NULL ) {} /// Destructor. @@ -104,16 +96,7 @@ namespace NOMAD { bool & count_search , const NOMAD::Eval_Point *& new_feas_inc , const NOMAD::Eval_Point *& new_infeas_inc ); - - /// Access to the search frequency. - /** - \param ell The mesh index -- \b IN. - \return Number of times that the VNS search has been performed on a given mesh. - */ - int get_nb_performed ( int ell ) const - { - return ( ell < 0 ) ? 0 : _nb_performed[ell]; - } + }; } diff --git a/src/Variable_Group.cpp b/src/Variable_Group.cpp index f00a7d66e289b70afe52aadae035f8c81a3c07db..c177fec114bb511a039f08b356dd2e893432a3de 100644 --- a/src/Variable_Group.cpp +++ b/src/Variable_Group.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -51,160 +51,105 @@ bool NOMAD::Variable_Group::check std::vector<bool> * in_group , bool & mod ) { - - // initial checks: - if ( _var_indexes.empty() ) - return false; - bool binary = true; - bool categorical = false; - bool reset_dirs = false; - - // other checks + filling of vector in_group: - int n = static_cast<int>(bbit.size()); - std::set<int>::const_iterator end = _var_indexes.end() , - it = _var_indexes.begin(); - - while ( it != end ) - { - - if ( *it < 0 || *it >= n ) - return false; - - // check if the variable is fixed: - if ( fixed_vars[*it].is_defined() ) - { - reset_dirs = true; - _var_indexes.erase ( it++ ); - mod=true; - continue; - } - - if ( bbit[*it] == NOMAD::CATEGORICAL ) - { - categorical = true; - binary = false; - } - else - { - if ( categorical ) - return false; - if ( bbit[*it] != NOMAD::BINARY ) - binary = false; - } - - if ( in_group ) - (*in_group)[*it] = true; - - ++it; - } - - // modify the directions if a fixed variable has been removed: - if ( reset_dirs ) - { - - int halton_seed = _directions->get_halton_seed(); - std::set<NOMAD::direction_type> direction_types - = _directions->get_direction_types(); - std::set<NOMAD::direction_type> sec_poll_dir_types - = _directions->get_sec_poll_dir_types(); - - delete _directions; - - _directions = new Directions ( static_cast<int>(_var_indexes.size()) , - direction_types , - sec_poll_dir_types , - halton_seed , - _out ); - } - - if ( binary ) - _directions->set_binary(); - - else - { - - // we check here that NOMAD::GPS_BINARY is not in - // dir_types nor in sec_poll_dir_types: - const std::set<NOMAD::direction_type> & direction_types - = _directions->get_direction_types(); - const std::set<NOMAD::direction_type> & sec_poll_dir_types - = _directions->get_sec_poll_dir_types(); - - if ( direction_types.find ( NOMAD::GPS_BINARY ) != direction_types.end () || - sec_poll_dir_types.find ( NOMAD::GPS_BINARY ) != sec_poll_dir_types.end() ) - return false; - - if ( categorical ) - _directions->set_categorical(); - } - - return true; + // initial checks: + if ( _var_indexes.empty() ) + return false; + + bool binary = true; + bool categorical = false; + bool reset_dirs = false; + + // other checks + filling of vector in_group: + int n = static_cast<int>(bbit.size()); + std::set<int>::const_iterator end = _var_indexes.end() , + it = _var_indexes.begin(); + + while ( it != end ) + { + + if ( *it < 0 || *it >= n ) + return false; + + // check if the variable is fixed: + if ( fixed_vars[*it].is_defined() ) + { + reset_dirs = true; + _var_indexes.erase ( it++ ); + mod=true; + continue; + } + + if ( bbit[*it] == NOMAD::CATEGORICAL ) + { + categorical = true; + binary = false; + } + else + { + if ( categorical ) + return false; + if ( bbit[*it] != NOMAD::BINARY ) + binary = false; + } + + if ( in_group ) + (*in_group)[*it] = true; + + ++it; + } + + // modify the directions if a fixed variable has been removed: + if ( reset_dirs ) + { + + std::set<NOMAD::direction_type> direction_types = _directions->get_direction_types(); + std::set<NOMAD::direction_type> sec_poll_dir_types = _directions->get_sec_poll_dir_types(); + + delete _directions; + + _directions = new Directions ( static_cast<int>(_var_indexes.size()) , + direction_types , + sec_poll_dir_types , + _out ); + } + + if ( binary ) + _directions->set_binary(); + + else + { + + // we check here that NOMAD::GPS_BINARY is not in + // dir_types nor in sec_poll_dir_types: + const std::set<NOMAD::direction_type> & direction_types + = _directions->get_direction_types(); + const std::set<NOMAD::direction_type> & sec_poll_dir_types + = _directions->get_sec_poll_dir_types(); + + if ( direction_types.find ( NOMAD::GPS_BINARY ) != direction_types.end () || + sec_poll_dir_types.find ( NOMAD::GPS_BINARY ) != sec_poll_dir_types.end() ) + return false; + + if ( categorical ) + _directions->set_categorical(); + } + + return true; } /*---------------------------------------------------------*/ /* compute the directions */ /*---------------------------------------------------------*/ -void NOMAD::Variable_Group::get_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index , - const NOMAD::Direction & feas_success_dir , - const NOMAD::Direction & infeas_success_dir ) +void NOMAD::Variable_Group::get_directions ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::OrthogonalMesh & mesh ) { - - int nc = static_cast<int>(_var_indexes.size()); - - // vectors are of size nc : - // ------------------------ - if ( nc == poll_center.size() ) { - - _directions->compute ( dirs , - poll , - poll_center , - mesh_index , - -1 , - feas_success_dir , - infeas_success_dir ); - return; - } - - // construct vectors of size nc from vectors of size < nc : - // -------------------------------------------------------- - std::set<int>::const_iterator it ; - int i = 0; - - NOMAD::Point new_poll_center ( nc ); - NOMAD::Direction new_fsd , new_isd; - - if ( feas_success_dir.is_defined() ) - new_fsd = NOMAD::Direction ( nc , 0.0 , feas_success_dir.get_type() ); - - if ( infeas_success_dir.is_defined() ) - new_isd = NOMAD::Direction ( nc , 0.0 , infeas_success_dir.get_type() ); - - for ( it = _var_indexes.begin() ; it != _var_indexes.end() ; ++it ) - { - - new_poll_center[i] = poll_center[*it]; - - if ( feas_success_dir.is_defined() ) - new_fsd[i] = feas_success_dir [*it]; - - if ( infeas_success_dir.is_defined() ) - new_isd[i] = infeas_success_dir[*it]; - - ++i; - } - - _directions->compute ( dirs , - poll , - new_poll_center , - mesh_index , - -1 , - new_fsd , - new_isd ); - + + _directions->compute ( dirs , + poll , + mesh ); + return; } /*---------------------------------------------------------*/ @@ -212,24 +157,24 @@ void NOMAD::Variable_Group::get_directions ( std::list<NOMAD::Direction> & dirs /*---------------------------------------------------------*/ bool NOMAD::Variable_Group::operator < ( const NOMAD::Variable_Group & vg ) const { - // variable indexes: - if ( _var_indexes.size() < vg._var_indexes.size() ) - return true; - if ( _var_indexes.size() > vg._var_indexes.size() ) - return false; - - std::set<int>::const_iterator it1 , - it2 = vg._var_indexes.begin() , - end = _var_indexes.end(); - for ( it1 = _var_indexes.begin() ; it1 != end ; ++it1 , ++it2 ) { - if ( *it1 < *it2 ) - return true; - if ( *it1 > *it2 ) - return false; - } - - // directions: - return ( *_directions < *vg._directions ); + // variable indexes: + if ( _var_indexes.size() < vg._var_indexes.size() ) + return true; + if ( _var_indexes.size() > vg._var_indexes.size() ) + return false; + + std::set<int>::const_iterator it1 , + it2 = vg._var_indexes.begin() , + end = _var_indexes.end(); + for ( it1 = _var_indexes.begin() ; it1 != end ; ++it1 , ++it2 ) { + if ( *it1 < *it2 ) + return true; + if ( *it1 > *it2 ) + return false; + } + + // directions: + return ( *_directions < *vg._directions ); } /*---------------------------------------------------------*/ @@ -237,15 +182,15 @@ bool NOMAD::Variable_Group::operator < ( const NOMAD::Variable_Group & vg ) cons /*---------------------------------------------------------*/ void NOMAD::Variable_Group::display ( const NOMAD::Display & out ) const { - out << "indexes: { "; - std::set<int>::const_iterator end = _var_indexes.end(); - for ( std::set<int>::const_iterator it = _var_indexes.begin() ; it != end ; ++it ) - out << *it << " "; - out << "}" << std::endl; - if ( _directions->is_categorical() ) - out << "no directions (categorical variables)" << std::endl; - else - out << NOMAD::open_block ( "directions" ) - << *_directions - << NOMAD::close_block(); + out << "indexes: { "; + std::set<int>::const_iterator end = _var_indexes.end(); + for ( std::set<int>::const_iterator it = _var_indexes.begin() ; it != end ; ++it ) + out << *it << " "; + out << "}" << std::endl; + if ( _directions->is_categorical() ) + out << "no directions (categorical variables)" << std::endl; + else + out << NOMAD::open_block ( "directions" ) + << *_directions + << NOMAD::close_block(); } diff --git a/src/Variable_Group.hpp b/src/Variable_Group.hpp index 4e9725c4eb03ba018eeada87f5df50f5cabe32b2..70f60544af43e840948cc06375097c49c3e5de9d 100644 --- a/src/Variable_Group.hpp +++ b/src/Variable_Group.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,198 +34,180 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file Variable_Group.hpp - \brief Group of variables (headers) - \author Sebastien Le Digabel - \date 2010-04-XX - \see Variable_Group.cpp -*/ + \file Variable_Group.hpp + \brief Group of variables (headers) + \author Sebastien Le Digabel + \date 2010-04-XX + \see Variable_Group.cpp + */ #ifndef __VARIABLE_GROUP__ #define __VARIABLE_GROUP__ #include "Directions.hpp" namespace NOMAD { - - /// Group of variables. - /** - A group can be composed of integer / continous / binary variables - or only categorical variables. - */ - class Variable_Group { - - private: - - std::set<int> _var_indexes; ///< The variable indexes. - NOMAD::Directions * _directions; ///< The directions. - const NOMAD::Display & _out; ///< Display. - - /// Affectation operator. - /** - \param vg The right-hand side object -- \b IN. - */ - Variable_Group & operator = ( const Variable_Group & vg ); - - public: - - /// Constructor. - /** - \param var_indexes Variable indexes -- \b IN. - \param direction_types Direction types -- \b IN. - \param sec_poll_dir_types Direction types for secondary poll -- \b IN. - \param halton_seed Halton seed -- \b IN. - \param out Display -- \b IN. - */ - Variable_Group ( const std::set<int> & var_indexes , - const std::set<NOMAD::direction_type> & direction_types , - const std::set<NOMAD::direction_type> & sec_poll_dir_types , - int halton_seed , - const NOMAD::Display & out ) - : _var_indexes ( var_indexes ) , - _directions ( new Directions ( static_cast<int>(var_indexes.size()) , - direction_types , - sec_poll_dir_types , - halton_seed , - out ) ) , - _out ( out ) {} - - /// Copy constructor. - /** - \param vg The copied object -- \b IN. - */ - Variable_Group ( const Variable_Group & vg ) - : _var_indexes ( vg._var_indexes ) , - _directions ( new Directions ( *vg._directions ) ) , - _out ( vg._out ) {} - - /// Destructor. - virtual ~Variable_Group ( void ) { delete _directions; } - - /// Comparison operator. - /** - \param vg The right-hand side object -- \b IN. - \return A boolean equal to \c true if \c *this \c < \c vg. - */ - bool operator < ( const Variable_Group & vg ) const; - - /// Check the group. - /** - Also removes fixed variables from the group. - \param fixed_vars Fixed variables -- \b IN. - \param bbit Input types -- \b IN. - \param in_group A pointer to a vector indicating if variables - belong to a group (may be \c NULL) -- \b OUT. - \param mod True if the variable group has been modified -- \b out - \return A boolean equal to \c true if the verification is valid. - */ - bool check ( const NOMAD::Point & fixed_vars , - const std::vector<NOMAD::bb_input_type> & bbit , - std::vector<bool> * in_group , - bool & mod ); - /// Check if the directions are Ortho-MADS directions. + /// Group of variables. /** - \return A boolean equal to \c true if the directions are Ortho-MADS directions. - */ - bool is_orthomads ( void ) const { return _directions->is_orthomads(); } - - /// Access to the Halton seed. - /** - \return The Halton seed. - */ - int get_halton_seed ( void ) const { return _directions->get_halton_seed(); } - - /// Access to the variable indexes. - /** - \return The variable indexes. - */ - const std::set<int> & get_var_indexes ( void ) const { return _var_indexes; } - - /// Access to the direction types. - /** - \return The direction types. - */ - const std::set<NOMAD::direction_type> & get_direction_types ( void ) const - { - return _directions->get_direction_types(); - } - - /// Access to the direction types for the secondary poll. - /** - \return The direction types for the secondary poll. - */ - const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const - { - return _directions->get_sec_poll_dir_types(); - } - - /// Access to the directions. - /** - - The computed directions already include Delta^k_m. - \param dirs List of directions -- \b OUT. - \param poll Type of poll (primary or secondary) -- \b IN. - \param poll_center Poll center -- \b IN. - \param mesh_index Mesh index ell -- \b IN. - \param feas_success_dir Feasible success direction -- \b IN. - \param infeas_success_dir Infeasible success direction -- \b IN. - */ - void get_directions ( std::list<NOMAD::Direction> & dirs , - NOMAD::poll_type poll , - const NOMAD::Point & poll_center , - int mesh_index , - const NOMAD::Direction & feas_success_dir , - const NOMAD::Direction & infeas_success_dir ); - - - /// Access to one direction for a given mesh. - /** - Used for example in the VNS search. - \param dir The direction -- \b OUT. - \param mesh_index Mesh index ell -- \b IN. - \param halton_index Halton index; must be > 0 -- \b IN. - */ - bool get_one_direction ( NOMAD::Direction & dir , - int mesh_index , - int halton_index ) - { - return _directions->compute_one_direction ( dir , mesh_index , halton_index ); - } + A group can be composed of integer / continous / binary variables + or only categorical variables. + */ + class Variable_Group { + + private: + + std::set<int> _var_indexes; ///< The variable indexes. + NOMAD::Directions * _directions; ///< The directions. + const NOMAD::Display & _out; ///< Display. + + /// Affectation operator. + /** + \param vg The right-hand side object -- \b IN. + */ + Variable_Group & operator = ( const Variable_Group & vg ); + + public: + + /// Constructor. + /** + \param var_indexes Variable indexes -- \b IN. + \param direction_types Direction types -- \b IN. + \param sec_poll_dir_types Direction types for secondary poll -- \b IN. + \param out Display -- \b IN. + */ + Variable_Group ( const std::set<int> & var_indexes , + const std::set<NOMAD::direction_type> & direction_types , + const std::set<NOMAD::direction_type> & sec_poll_dir_types , + const NOMAD::Display & out ) + : _var_indexes ( var_indexes ), + _directions ( new Directions ( static_cast<int>(var_indexes.size()) , + direction_types , + sec_poll_dir_types , + out ) ) , + _out ( out ) {} + + /// Copy constructor. + /** + \param vg The copied object -- \b IN. + */ + Variable_Group ( const Variable_Group & vg ) + : _var_indexes ( vg._var_indexes ) , + _directions ( new Directions ( *vg._directions ) ) , + _out ( vg._out ) {} + + /// Destructor. + virtual ~Variable_Group ( void ) { delete _directions; } + + /// Comparison operator. + /** + \param vg The right-hand side object -- \b IN. + \return A boolean equal to \c true if \c *this \c < \c vg. + */ + bool operator < ( const Variable_Group & vg ) const; + + /// Check the group. + /** + Also removes fixed variables from the group. + \param fixed_vars Fixed variables -- \b IN. + \param bbit Input types -- \b IN. + \param in_group A pointer to a vector indicating if variables + belong to a group (may be \c NULL) -- \b OUT. + \param mod True if the variable group has been modified -- \b out + \return A boolean equal to \c true if the verification is valid. + */ + bool check ( const NOMAD::Point & fixed_vars , + const std::vector<NOMAD::bb_input_type> & bbit , + std::vector<bool> * in_group , + bool & mod ); + + /// Check if the directions are Ortho-MADS directions. + /** + \return A boolean equal to \c true if the directions are Ortho-MADS directions. + */ + bool is_orthomads ( void ) const { return _directions->is_orthomads(); } + + + /// Access to the variable indexes. + /** + \return The variable indexes. + */ + const std::set<int> & get_var_indexes ( void ) const { return _var_indexes; } + + /// Access to the direction types. + /** + \return The direction types. + */ + const std::set<NOMAD::direction_type> & get_direction_types ( void ) const + { + return _directions->get_direction_types(); + } + + /// Access to the direction types for the secondary poll. + /** + \return The direction types for the secondary poll. + */ + const std::set<NOMAD::direction_type> & get_sec_poll_dir_types ( void ) const + { + return _directions->get_sec_poll_dir_types(); + } + + /// Access to the directions. + /** + \param dirs List of directions -- \b OUT. + \param poll Type of poll (primary or secondary) -- \b IN. + \param mesh Mesh -- \b IN. + */ + void get_directions ( std::list<NOMAD::Direction> & dirs , + NOMAD::poll_type poll , + const NOMAD::OrthogonalMesh & mesh ); + + + /// Access to one direction for a given mesh. + /** + Used for example in the VNS search. + \param dir The direction -- \b OUT. + */ + bool get_one_direction ( NOMAD::Direction & dir ) + { + return _directions->compute_dir_on_unit_sphere( dir ); + } + + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + /// Display. + /** + Uses the \c this->_out member as NOMAD::Display object. + */ + void display ( void ) const { display ( _out ); } + }; - /// Display. + /// Display a NOMAD::Variable_Group object. /** - \param out The NOMAD::Display object -- \b IN. - */ - void display ( const NOMAD::Display & out ) const; - - /// Display. - /** - Uses the \c this->_out member as NOMAD::Display object. - */ - void display ( void ) const { display ( _out ); } - }; - - /// Display a NOMAD::Variable_Group object. - /** \param out The NOMAD::Display object -- \b IN. \param vg The NOMAD::Variable_Group object to be displayed -- \b IN. \return The NOMAD::Display object. - */ - inline const NOMAD::Display & operator << ( const NOMAD::Display & out , - const NOMAD::Variable_Group & vg ) { - vg.display ( out ); - return out; - } - - /// Allow the comparison between two pointers to NOMAD::Variable_Group objects. - /** - Used with \c set<Variable_Group*,VG_Comp> in class NOMAD::Parameters. - */ - struct VG_Comp { - /// Comparison between two NOMAD::Variable_Group objects. - bool operator() ( const Variable_Group * vg1 , const Variable_Group * vg2 ) const { - return (*vg1 < *vg2); + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::Variable_Group & vg ) { + vg.display ( out ); + return out; } - }; + + /// Allow the comparison between two pointers to NOMAD::Variable_Group objects. + /** + Used with \c set<Variable_Group*,VG_Comp> in class NOMAD::Parameters. + */ + struct VG_Comp { + /// Comparison between two NOMAD::Variable_Group objects. + bool operator() ( const Variable_Group * vg1 , const Variable_Group * vg2 ) const { + return (*vg1 < *vg2); + } + }; } #endif diff --git a/src/XMesh.cpp b/src/XMesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..926ddac8f88c68c40524df03a8e63a1cbb19a1cd --- /dev/null +++ b/src/XMesh.cpp @@ -0,0 +1,511 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Sebastien Le Digabel */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file XMesh.cpp + \brief Class for the MADS xmesh (implementation) + \author Christophe Tribes + \date 2014-07 + \see XMesh.hpp + */ +#include "XMesh.hpp" +#include <math.h> + + +/*-----------------------------------------------------------*/ +/* init the XMesh */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::init ( ) +{ + bool chkMesh = _delta_min.is_defined(); + bool chkPoll = _Delta_min_is_defined; + _n = _delta_0.size(); + + + if ( !_Delta_0.is_complete() ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::init(): Delta_0 has undefined values" ); + if ( _delta_0.size() != _Delta_0.size() ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::init(): delta_0 and Delta_0 have different sizes" ); + + if ( !_delta_0.is_complete() ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::init(): delta_0 has undefined values" ); + + if ( chkMesh && _delta_min.size() != _n ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::init(): delta_0 and delta_min have different sizes" ); + + if ( chkPoll && _Delta_min.size() != _n ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::init(): delta_0 and Delta_min have different sizes" ); + + if ( _limit_mesh_index >0 ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::XMesh(): limit mesh index must be <=0 " ); + + + _r.resize( _n ); + _r_max.resize( _n ); + _r_min.resize( _n ); + + for ( int k = 0 ; k < _n ; ++k ) + { + _r[k]=0; + _r_max[k]=0; + _r_min[k]=0; + } + + +} + + +/*-----------------------------------------------------------*/ +/* Update the provided mesh indices (the Mesh is unchanged). */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir ) const +{ + + if ( mesh_indices.is_defined() ) + { + + if ( dir && dir->size() != mesh_indices.size() ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::update(): mesh_indices and dir have different sizes" ); + + for (int i=0; i < mesh_indices.size() ; i++) + { + if ( success == NOMAD::FULL_SUCCESS ) + { + + if ( (*dir)[i] !=0.0) + mesh_indices[i] += _coarsening_step; + + if ( mesh_indices[i] > -NOMAD::XL_LIMITS ) + mesh_indices[i] = -NOMAD::XL_LIMITS; + } + else if ( success == NOMAD::UNSUCCESSFUL ) + mesh_indices[i] += _refining_step; + } + } +} + + + +/*-----------------------------------------------------------*/ +/* update the XMesh */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::update ( NOMAD::success_type success , const NOMAD::Direction * dir) +{ + // defaults: + // full success: r^k_j = r^k_j + 1 if (dir_k != 0 and anistropic_mesh) and r^k_j remains the same if dir_k=0 + // failure : r^k_j = r^k_j - 1 + + + if ( dir && dir->size() != _n ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::update(): delta_0 and dir have different sizes" ); + + + if ( success == NOMAD::FULL_SUCCESS ) + { + // Evaluate ||d||_inf + NOMAD::Double norm_inf=0; + NOMAD::Point delta=NOMAD::OrthogonalMesh::get_delta(); + + if ( _anisotropic_mesh ) + { + for (int i=0; i < _n; i++) + { + if ( dir && (*dir)[i].abs()/delta[i] > norm_inf ) + norm_inf=(*dir)[i].abs()/delta[i]; + } + } + else + norm_inf=-1; + + // Determine current max mesh index + NOMAD::Double max_index=NOMAD::XL_LIMITS; + for (int j=0; j < _n; j++) + if ( _r[j] > max_index ) + max_index=_r[j]; + + + // Update mesh indices for coordinates with |dir_j|>1/n_free_variables ||dir||_inf or mesh index >=-2 + for (int i=0; i < _n; i++) + { + if ( ! dir || (*dir)[i].abs()/delta[i] > norm_inf/_n_free_variables || _r[i] >=-2 ) + { + _r[i] += _coarsening_step; + + if (_r[i] > -NOMAD::XL_LIMITS ) + _r[i] = -NOMAD::XL_LIMITS; + + if ( _r[i] > _r_max[i] ) + _r_max[i] = _r[i]; + + } + } + + + // Udate mesh indices for coordinates with |dir_l| < 1/n_free_variables ||dir||_inf and mesh index < 2*max_mesh_index + for (int l=0; l < _n; l++) + { + if ( dir && _r[l] < -2 && (*dir)[l].abs()/delta[l] <= norm_inf/_n_free_variables && _r[l] < 2*max_index ) + _r[l]+= _coarsening_step; + } + + } + else if ( success == NOMAD::UNSUCCESSFUL ) + for (int i=0; i< _n; i++) + { + _r[i] += _refining_step; + + if ( _r[i] < _r_min[i] ) + _r_min[i] = _r[i]; + + } +} + + +/*-----------------------------------------------------------*/ +/* display */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::display ( const NOMAD::Display & out ) const +{ + out << "n : " << _n << std::endl + << "tau : " << _update_basis << std::endl + << "poll coarsening exponent: " << _coarsening_step << std::endl + << "poll refining exponent : " << _refining_step << std::endl; + out << "minimal mesh size : "; + if ( _delta_min.is_defined() ) + out << "(" << _delta_min << " )" << std::endl; + else + out << "none"; + out << std::endl + << "minimal poll size : "; + if ( _Delta_min_is_defined ) + out << "( " << _Delta_min << " )" << std::endl; + else + out << "none"; + + out << std::endl << "initial poll size : "; + if (_Delta_0.is_defined()) + out <<"( " << _Delta_0 << " )" << std::endl; + else + out <<"( none )" << std::endl; + + out << std::endl << "initial mesh size : "; + + if ( _delta_0.is_defined() ) + out <<"( " << _delta_0 << " )" << std::endl; + else + out <<"( none )" << std::endl; + + out << std::endl; +} + + +/*----------------------------------------------------------*/ +/* check the stopping conditions on the minimal poll size */ +/* and on the minimal mesh size */ +/*----------------------------------------------------------*/ +void NOMAD::XMesh::check_min_mesh_sizes ( bool & stop , + NOMAD::stop_type & stop_reason ) const +{ + if ( stop ) + return; + + // Coarse mesh stopping criterion + stop=false; + + for (int i=0;i<_n;i++) + if ( _r[i] > -NOMAD::XL_LIMITS ) + { + stop = true; + break; + } + + if (stop) + { + stop_reason = NOMAD::XL_LIMITS_REACHED; + return; + } + + stop=true; + + // Fine mesh stopping criterion + // All mesh indices must < _limit_mesh_index to trigger this stopping criterion + for (int i=0;i<_n;i++) + { + if ( _r[i] >= _limit_mesh_index ) + { + stop = false; + break; + } + } + if (stop) + { + stop_reason = NOMAD::XL_LIMITS_REACHED; + return; + } + + // 2. Delta^k (poll size) tests: + if ( check_min_poll_size_criterion ( ) ) + { + stop = true; + stop_reason = NOMAD::DELTA_P_MIN_REACHED; + } + + // 3. delta^k (mesh size) tests: + if ( check_min_mesh_size_criterion ( ) ) + { + stop = true; + stop_reason = NOMAD::DELTA_M_MIN_REACHED; + } +} + +/*-----------------------------------------------------------*/ +/* check the minimal poll size (private) */ +/*-----------------------------------------------------------*/ +bool NOMAD::XMesh::check_min_poll_size_criterion ( ) const +{ + if ( !_Delta_min_is_defined ) + return false; + + NOMAD::Point Delta; + return get_Delta ( Delta ); +} + +/*-----------------------------------------------------------*/ +/* check the minimal mesh size (private) */ +/*-----------------------------------------------------------*/ +bool NOMAD::XMesh::check_min_mesh_size_criterion ( ) const +{ + if ( !_delta_min.is_defined() ) + return false; + + NOMAD::Point delta; + return get_delta ( delta ); +} + + +/*--------------------------------------------------------------*/ +/* get delta (mesh size parameter) */ +/* delta^k = delta^0 \tau ^min{0,2*r^k} */ +/*--------------------------------------------------------------*/ +/* the function also returns true if ALL delta[i] < delta_min */ +/*----------------------------------------------------------------*/ +bool NOMAD::XMesh::get_delta ( NOMAD::Point & delta ) const +{ + + delta.resize(_n); + + bool delta_min_is_defined=_delta_min.is_defined(); + + bool stop = true; + + // delta^k = power_of_beta * delta^0: + for ( int i = 0 ; i < _n ; ++i ) + { + NOMAD::Double power_of_beta + = pow ( _update_basis.value() , ( (_r[i] >= 0) ? 0 : 2*_r[i].value() ) ); + + delta[i] = _delta_0[i] * power_of_beta; + + if ( delta_min_is_defined && _delta_min[i].is_defined() && delta[i] >= _delta_min[i] ) + stop = false; + } + + return stop; +} + + +/*--------------------------------------------------------------*/ +/* get delta (mesh size parameter) */ +/* delta^k = delta^0 \tau ^min{0,2*r^k} */ +/*--------------------------------------------------------------*/ +NOMAD::Double NOMAD::XMesh::get_delta ( int i ) const +{ + + // delta^k = power_of_beta * delta^0: + NOMAD::Double power_of_beta = pow ( _update_basis.value() , ( (_r[i] >= 0) ? 0 : 2*_r[i].value() ) ); + + return _delta_0[i] * power_of_beta; + +} + + + +/*--------------------------------------------------------------*/ +/* get Delta (poll size parameter) */ +/* Delta^k = Delta^0 \tau ^{r^k} */ +/*--------------------------------------------------------------*/ +/* the function also returns true if all values are < Delta_min */ +/*----------------------------------------------------------------*/ +bool NOMAD::XMesh::get_Delta ( NOMAD::Point & Delta ) const +{ + + bool stop = true; + + Delta.resize(_n); + + // delta^k = power_of_tau * delta^0: + for ( int i = 0 ; i < _n ; ++i ) + { + Delta[i] = _Delta_0[i] * pow( _update_basis.value() , _r[i].value() ); + + if ( !_Delta_min_is_complete || Delta[i] >= _Delta_min[i] ) + stop = false; + + if ( _Delta_min_is_defined && _Delta_min[i].is_defined() && Delta[i] < _Delta_min[i] ) + Delta[i]=_Delta_min[i]; + + } + + return stop; +} + +/*--------------------------------------------------------------*/ +/* get Delta_i (poll size parameter) */ +/* Delta^k = Delta^0 \tau ^{r^k} */ +/*--------------------------------------------------------------*/ +/* the function returns Delta >= Delta_min */ +/*--------------------------------------------------------------*/ +NOMAD::Double NOMAD::XMesh::get_Delta ( int i ) const +{ + + NOMAD::Double Delta = _Delta_0[i] * pow( _update_basis.value() , _r[i].value() ); + + if ( _Delta_min_is_defined && _Delta_min[i].is_defined() && Delta < _Delta_min[i] ) + Delta=_Delta_min[i]; + + + return Delta; +} + + +bool NOMAD::XMesh::is_finest ( ) const +{ + + for ( int i = 0 ; i < _n ; ++i ) + { + if ( _r[i] > _r_min[i] ) + return false; + } + return true; +} + + +/*-----------------------------------------------------------*/ +/* set the mesh indices */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::set_mesh_indices ( const NOMAD::Point & r ) +{ + + if ( r.size() != _n ) + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "NOMAD::XMesh::set_mesh_indices(): dimension of provided mesh indices must be consistent with their previous dimension" ); + + _r=r; + for ( int i = 0 ; i < _n ; ++i ) + { + if ( r[i] > _r_max[i] ) + _r_max[i] = r[i]; + if ( r[i] < _r_min[i] ) + _r_min[i] = r[i]; + } +} + + +/*-----------------------------------------------------------*/ +/* set the limit mesh index (min value for XMesh) */ +/*-----------------------------------------------------------*/ +void NOMAD::XMesh::set_limit_mesh_index ( int l ) +{ + _limit_mesh_index=l; +} + + + + +/*-----------------------------------------------------------*/ +/* scale and project on the mesh */ +/*-----------------------------------------------------------*/ +NOMAD::Double NOMAD::XMesh::scale_and_project(int i, const NOMAD::Double & l) const +{ + NOMAD::Double delta = get_delta( i ); + NOMAD::Double Delta = get_Delta( i ); + + + if ( i<=_n && delta.is_defined() && Delta.is_defined() ) + { + NOMAD::Double d = Delta / delta * l; + return d.NOMAD::Double::round()*delta; + } + else + throw NOMAD::Exception ( "XMesh.cpp" , __LINE__ , + "Mesh scaling and projection cannot be performed!" ); + + +} + + +NOMAD::Point NOMAD::XMesh::get_mesh_ratio_if_success ( void ) const +{ + + try + { + NOMAD::Point ratio( _n ); + for (int i=0 ; i < _n ; i++) + { + NOMAD::Double power_of_tau + = pow ( _update_basis.value() , ( (_r[i] >= 0) ? 0 : 2*_r[i].value() ) ); + + NOMAD::Double power_of_tau_if_success + = pow ( _update_basis.value() , ( (_r[i] + _coarsening_step >= 0) ? 0 : 2*(_r[i].value() + _coarsening_step) ) ); + + ratio[i] = power_of_tau_if_success/power_of_tau; + + } + + return ratio; + } + catch ( NOMAD::Double::Invalid_Value & ) + { + return NOMAD::Point( _n,-1 ); + } +} diff --git a/src/XMesh.hpp b/src/XMesh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e29262cd6d15a4b969ea6deeaa38ea2ec28fbe38 --- /dev/null +++ b/src/XMesh.hpp @@ -0,0 +1,307 @@ +/*-------------------------------------------------------------------------------------*/ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ +/* */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ +/* Charles Audet - Ecole Polytechnique, Montreal */ +/* Gilles Couture - Ecole Polytechnique, Montreal */ +/* John Dennis - Rice University, Houston */ +/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */ +/* Christophe Tribes - Ecole Polytechnique, Montreal */ +/* */ +/* funded in part by AFOSR and Exxon Mobil */ +/* */ +/* Author: Christophe Tribes */ +/* */ +/* Contact information: */ +/* Ecole Polytechnique de Montreal - GERAD */ +/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */ +/* e-mail: nomad@gerad.ca */ +/* phone : 1-514-340-6053 #6928 */ +/* fax : 1-514-340-5665 */ +/* */ +/* This program is free software: you can redistribute it and/or modify it under the */ +/* terms of 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. */ +/* */ +/* This program 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 Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License along */ +/* with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* */ +/* You can find information on the NOMAD software at www.gerad.ca/nomad */ +/*-------------------------------------------------------------------------------------*/ +/** + \file XMesh.hpp + \brief Class for the xmesh (extensible mesh) (headers) + \author Christophe Tribes + \date 2014-07 + \see XMesh.cpp + */ +#ifndef __XMESH__ +#define __XMESH__ + +#include "OrthogonalMesh.hpp" + +namespace NOMAD { + + /// Class for the MADS Xmesh. + /** + - The Xmesh in NOMAD is defined with the basic directions and the + mesh size parameter delta^k for each coordinate. + */ + + class XMesh : public NOMAD::OrthogonalMesh { + + /*--------------------------------------------------------------*/ + private: + + NOMAD::Point _r; // Mesh index per coordinate. + NOMAD::Point _r_min; + NOMAD::Point _r_max; + bool _anisotropic_mesh; + + + + /*--------------------------------------------------------------*/ + + /// Private affectation operator. + /** + \param m The right-hand side object -- \b IN. + */ + const XMesh & operator = ( const XMesh & m ); + + /// Check the minimal poll size criterion. + bool check_min_poll_size_criterion ( ) const; + + /// Check the minimal mesh size criterion. + bool check_min_mesh_size_criterion ( ) const; + + + /// Access to the mesh size parameter delta^k. + /** + \return delta The mesh size parameter delta^k -- \b OUT. + \param i The index of the mesh size + */ + NOMAD::Double get_delta ( int i ) const ; + + + /// Access to the poll size parameter Delta^k. + /** + \return Delta The poll size parameter Delta^k -- \b OUT. + \param i The index of the poll size + */ + NOMAD::Double get_Delta ( int i ) const ; + + void init ( ); + + public: + + /// Constructor. + /** + \param anistropic_mesh Use anisotropic mesh or not -- \b IN. + \param Delta_0 Initial poll size Delta^0 -- \b IN. + \param Delta_min Minimal poll size Delta^min (may be undefined) -- \b IN. + \param delta_min Minimal mesh size delta^min (may be undefined) -- \b IN. + \param poll_update_basis Poll update basis (b); default=2 -- \b IN. + \param poll_coarsening_step Poll coarsening step (w+); default=1 -- \b IN. + \param poll_refining_step Poll refining step (w-); default=-1 -- \b IN. + \param fixed_variables Fixed variables -- \b IN. + \param limit_min_mesh_index Limit mesh index (<0) -- \b IN. + */ + XMesh (bool anisotropic_mesh, + const NOMAD::Point & Delta_0 , + const NOMAD::Point & Delta_min , + const NOMAD::Point & delta_min , + const NOMAD::Point & fixed_variables, + NOMAD::Double poll_update_basis=2.0, + int poll_coarsening_step=1, + int poll_refining_step=-1 , + int limit_min_mesh_index=NOMAD::XL_LIMITS ) + : NOMAD::OrthogonalMesh ( Delta_0, + Delta_min, + delta_min, + fixed_variables, + poll_update_basis, + poll_coarsening_step, + poll_refining_step , + limit_min_mesh_index ), + _anisotropic_mesh ( anisotropic_mesh ){ init();} + + + + + /// Copy constructor. + /** + \param m The copied object -- \b IN. + */ + XMesh ( const XMesh & m ) + : OrthogonalMesh ( m ) , + _r ( m._r ), + _r_min ( m._r_min ), + _r_max ( m._r_max ), + _anisotropic_mesh ( m._anisotropic_mesh ){} + + /// Destructor. + ~XMesh ( void ) + { + _delta_0.clear(); + _Delta_0.clear(); + _delta_min.clear(); + _Delta_min.clear(); + } + + + /// Access to the mesh size parameter delta^k for earch coordinate. + /** + - It is a NOMAD::Point of size \c nc the number of free variables. + \param delta The mesh size parameter delta^k -- \b OUT. + -- \b optional (default = the current mesh index ell_k.) + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + mesh size delta_min (stopping criterion MIN_MESH_SIZE). + */ + bool get_delta ( NOMAD::Point & delta ) const ; + + + /// Access to the largest mesh size for earch coordinate. + /** + \return delta_max + */ + NOMAD::Point get_delta_max ( void ) const { return _delta_0;} + + + /// Access to the poll size Delta^k for each coordinate. + /** + - It is a NOMAD::Point of size \c nc the number of free variables. + \param Delta The poll size parameter Delta^k -- \b OUT. + \return A boolean equal to \c true if all values are + strictly inferior than the associated minimal + poll size Delta_min + (stopping criterion MIN_POLL_SIZE). + */ + bool get_Delta ( NOMAD::Point & Delta) const ; + + + /// Update the provided mesh indices (the Mesh is unchanged). + /** + \param success Type of success of the iteration -- \b IN. + \param mesh_indices The mesh indices before and after the update -- \b IN/OUT. + \param dir The direction that is considered (opt) -- \b IN. + */ + void update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir=NULL ) const ; + + + /// Test if mesh finer than initial. + /** + \return True if mesh size is smaller than initial mesh size for all components; False otherwise. + */ + bool is_finer_than_initial (void) const {return true;} + + + + /// Update the XMesh (poll and mesh sizes). + /** + \param success Type of success of the iteration -- \b IN. + \param dir Direction of the iteration -- \b IN. + */ + void update ( NOMAD::success_type success, const NOMAD::Direction * dir=NULL); + + /// Reset the mesh to its original size (mesh indices). + void reset ( void ) { init() ;} + + + /// Display. + /** + \param out The NOMAD::Display object -- \b IN. + */ + void display ( const NOMAD::Display & out ) const; + + /// Test if r < r_min so far for all coordinates. + /** + \return True if mesh is the finest so far, False otherwise. + */ + bool is_finest ( void ) const; + + + /// Scale and project the ith component of a vector on the mesh + /** + \param i The vector component number -- \b IN. + \param l The vector component value -- \b IN. + \return The ith component of a vector after mesh scaling and projection + */ + NOMAD::Double scale_and_project(int i, const NOMAD::Double & l) const ; + + + /// Check the stopping conditions on the minimal poll and mesh sizes. + /** + \param stop Stop flag -- \b IN/OUT. + \param stop_reason Stop reason -- \b OUT. + */ + void check_min_mesh_sizes ( bool & stop , + NOMAD::stop_type & stop_reason ) const; + + /// Access to the mesh indices per coordinate. + /** + \return A point with the mesh index for each coordinate. + */ + const NOMAD::Point get_mesh_indices ( void ) const { return _r; } + + /// Access to the min mesh indices reached so far. + /** + \return A point with the mesh index for each coordinate. + */ + const NOMAD::Point get_min_mesh_indices ( void ) const { return _r_min; } + + + /// Access to the max mesh indices reached so far. + /** + \return A point with the mesh index for each coordinate. + */ + const NOMAD::Point get_max_mesh_indices ( void ) const { return _r_max; } + + + /// Manually set the mesh index. + /** + \param r The mesh index provided as a point -- \b IN. + */ + void set_mesh_indices ( const NOMAD::Point & r ); + + + + /// Manually set the limit mesh index (termination criterion). + /** + \param l The limit mesh index for all coordinates -- \b IN. + */ + void set_limit_mesh_index ( int l ); + + + + /// Access to the mesh ratios after a success + /** + \return A point with the ratio for each coordinate + */ + NOMAD::Point get_mesh_ratio_if_success ( void ) const; + + + + }; + + /// Display a NOMAD::XMesh object. + /** + \param out The NOMAD::Display object -- \b IN. + \param m The NOMAD::XMesh object to be displayed -- \b IN. + \return The NOMAD::Display object. + */ + inline const NOMAD::Display & operator << ( const NOMAD::Display & out , + const NOMAD::XMesh & m ) + { + m.display ( out ); + return out; + } + +} + +#endif diff --git a/src/defines.hpp b/src/defines.hpp index 5593c1c85cedbbaa3e2b9128e103223e51ad2812..511f75e36db545a2bc277e5cbbbf0d0f9ae09382 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -9,7 +9,7 @@ /* Christophe Tribes - Ecole Polytechnique, Montreal */ /* */ /* funded in part by AFOSR and Exxon Mobil */ -/* */ +/* */ /* Author: Sebastien Le Digabel */ /* */ /* Contact information: */ @@ -34,11 +34,11 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file defines.hpp - \brief Definitions - \author Sebastien Le Digabel - \date 2010-03-23 -*/ + \file defines.hpp + \brief Definitions + \author Sebastien Le Digabel + \date 2010-03-23 + */ #ifndef __DEFINES__ #define __DEFINES__ @@ -53,10 +53,10 @@ // #define R_VERSION // defined for the R version only // Matlab version OPTI style (if not defined than GERAD style) -// #define OPTI_VERSION +// #define OPTI_VERSION // Define in order to display debug information -// #define DEBUG +//#define DEBUG // define in order to display memory debug information: //#define MEMORY_DEBUG @@ -76,12 +76,12 @@ #endif -// CASE Linux using gnu compiler +// CASE Linux using gnu compiler #ifdef __gnu_linux__ #define GCC_X #endif -// CASE OSX using gnu compiler +// CASE OSX using gnu compiler #ifdef __APPLE__ #ifdef __GNUC__ #define GCC_X @@ -99,9 +99,10 @@ // CASE Visual Studio C++ compiler #ifdef _MSC_VER #define WINDOWS +#pragma warning(disable:4996) #endif -// For NOMAD random number generator +// For NOMAD random number generator #if !defined(UINT32_MAX) typedef unsigned int uint32_t; #define UINT32_MAX 0xffffffff @@ -122,384 +123,389 @@ typedef unsigned int uint32_t; // #define MODEL_STATS namespace NOMAD { - - /// Current version: - const std::string BASE_VERSION = "3.6.1"; - + + /// Current version: + const std::string BASE_VERSION = "3.7.2"; + #ifdef R_VERSION - const std::string VERSION = BASE_VERSION + ".R"; + const std::string VERSION = BASE_VERSION + ".R"; #else #ifdef USE_MPI #ifdef USE_TGP - const std::string VERSION = BASE_VERSION + ".TGP" + ".MPI"; + const std::string VERSION = BASE_VERSION + ".TGP" + ".MPI"; #else - const std::string VERSION = BASE_VERSION + ".MPI"; + const std::string VERSION = BASE_VERSION + ".MPI"; #endif #else #ifdef USE_TGP - const std::string VERSION = BASE_VERSION + ".TGP"; + const std::string VERSION = BASE_VERSION + ".TGP"; #else - const std::string VERSION = BASE_VERSION; + const std::string VERSION = BASE_VERSION; #endif #endif #endif - - // Directory separator, plus LGPL and user guide files + + // Directory separator, plus LGPL and user guide files #ifdef WINDOWS - const char DIR_SEP = '\\'; ///< Directory separator - const std::string HOME = "%NOMAD_HOME%"; ///< Home directory + const char DIR_SEP = '\\'; ///< Directory separator + const std::string HOME = "%NOMAD_HOME%"; ///< Home directory #else - const char DIR_SEP = '/'; ///< Directory separator - const std::string HOME = "$NOMAD_HOME"; ///< Home directory + const char DIR_SEP = '/'; ///< Directory separator + const std::string HOME = "$NOMAD_HOME"; ///< Home directory #endif - - /// Licence file - const std::string LGPL_FILE = HOME+DIR_SEP+"src"+DIR_SEP+"lgpl.txt"; - - /// User guide file - const std::string USER_GUIDE_FILE = HOME+DIR_SEP+"doc"+DIR_SEP+"user_guide.pdf"; - - /// Examples directory - const std::string EXAMPLES_DIR = HOME+DIR_SEP+"examples"; - - /// Tools directory - const std::string TOOLS_DIR = HOME+DIR_SEP+"tools"; - - /// Tag for valid cache files + + /// Licence file + const std::string LGPL_FILE = HOME+DIR_SEP+"src"+DIR_SEP+"lgpl.txt"; + + /// User guide file + const std::string USER_GUIDE_FILE = HOME+DIR_SEP+"doc"+DIR_SEP+"user_guide.pdf"; + + /// Examples directory + const std::string EXAMPLES_DIR = HOME+DIR_SEP+"examples"; + + /// Tools directory + const std::string TOOLS_DIR = HOME+DIR_SEP+"tools"; + + /// Tag for valid cache files #ifdef GCC_X - const int CACHE_FILE_ID = 77041301; + const int CACHE_FILE_ID = 77041301; #else #ifdef GCC_WINDOWS - const int CACHE_FILE_ID = 77041302; + const int CACHE_FILE_ID = 77041302; #else #ifdef _MSC_VER - const int CACHE_FILE_ID = 77041303; + const int CACHE_FILE_ID = 77041303; #else - const int CACHE_FILE_ID = 77041304; + const int CACHE_FILE_ID = 77041304; #endif #endif #endif - + #ifdef USE_MPI - // MPI constants - const int MAX_REQ_WAIT = 3 ; ///< Maximum time to wait for a request - const char STOP_SIGNAL = 'S'; ///< Stop signal - const char EVAL_SIGNAL = 'X'; ///< Evaluation signal - const char READY_SIGNAL = 'R'; ///< Ready signal - const char RESULT_SIGNAL = 'O'; ///< Result signal - const char WAIT_SIGNAL = 'W'; ///< Wait signal + // MPI constants + const int MAX_REQ_WAIT = 3 ; ///< Maximum time to wait for a request + const char STOP_SIGNAL = 'S'; ///< Stop signal + const char EVAL_SIGNAL = 'X'; ///< Evaluation signal + const char READY_SIGNAL = 'R'; ///< Ready signal + const char RESULT_SIGNAL = 'O'; ///< Result signal + const char WAIT_SIGNAL = 'W'; ///< Wait signal #endif - - /// Maximum number of variables. - const int MAX_DIMENSION = 1000; - - // Mesh index constants - const int L_LIMITS = 50; ///< Limits for the mesh index values - const int UNDEFINED_L = L_LIMITS+1; ///< Undefined value for the mesh index - - /// Default epsilon used by NOMAD::Double - /** Use Parameters::set_EPSILON(), or parameter EPSILON, - or NOMAD::Double::set_epsilon() to change it - */ - const double DEFAULT_EPSILON = 1e-13; - - /// Maximal output value for points used for models. - const double MODEL_MAX_OUTPUT = 1e10; - - /// Default infinity string used by NOMAD::Double - /** Use Parameters::set_INF_STR(), or parameter INF_STR, - or NOMAD::Double::set_inf_str() to change it - */ - const std::string DEFAULT_INF_STR = "inf"; - - /// Default undefined value string used by NOMAD::Double - /** Use Parameters::set_UNDEF_STR(), or parameter UNDEF_STR, - or NOMAD::Double::set_undef_str() to change it - */ - const std::string DEFAULT_UNDEF_STR = "NaN"; - - // VNS constants - const int VNS_HALTON_INDEX_0 = 997; ///< Initial Halton index for the VNS - const int VNS_HALTON_INCR = 17; ///< VNS Halton index increment - - /// log(10) (for display widths.) - const double LOG10 = 2.30258509299; - - const double INF = std::numeric_limits<double>::max(); ///< Infinity - - const double D_INT_MAX = UINT32_MAX; ///< The UINT32_MAX constant as a \c double - - // Singular Value Decomposition (SVD) constants: - const double SVD_EPS = 1e-13; ///< Epsilon for SVD - const int SVD_MAX_MPN = 1500; ///< Matrix maximal size (\c m+n ) - const double SVD_MAX_COND = NOMAD::INF; ///< Max. acceptable cond. number - - /// Default value for parameter POINT_DISPLAY_LIMIT - /** Use Parameters::set_POINT_DISPLAY_LIMIT() or parameter POINT_DISPLAY_LIMIT - or Point::set_display_limit() to change it */ - const int DEFAULT_POINT_DISPLAY_LIMIT = 20; - - // Display precisions. - const int DISPLAY_PRECISION_STD = 10; ///< Standard display precision - const int DISPLAY_PRECISION_BB = 15; ///< Display precision for blackboxes - - /// Constant for blackbox files #1. - const std::string BLACKBOX_INPUT_FILE_PREFIX = "nomad"; - - /// Constant for blackbox files #2. - const std::string BLACKBOX_INPUT_FILE_EXT = "input"; - - /// Constant for blackbox files #3. - const std::string BLACKBOX_OUTPUT_FILE_PREFIX = "nomad"; - - /// Constant for blackbox files #4. - const std::string BLACKBOX_OUTPUT_FILE_EXT = "output"; - - /// Display degree type. - enum dd_type + + /// Maximum number of variables. + const int MAX_DIMENSION = 1000; + + // Old static Mesh index constants + const int L_LIMITS = 50; ///< Limits for the smesh index values + const int UNDEFINED_L = L_LIMITS+1; ///< Undefined value for the smesh index + + // xmesh index constants + const int XL_LIMITS = -50; ///< Limits for the xmesh index values + const int UNDEFINED_XL = XL_LIMITS-1; ///< Undefined value for the xmesh index + + + /// Default epsilon used by NOMAD::Double + /** Use Parameters::set_EPSILON(), or parameter EPSILON, + or NOMAD::Double::set_epsilon() to change it + */ + const double DEFAULT_EPSILON = 1e-13; + + /// Maximal output value for points used for models. + const double MODEL_MAX_OUTPUT = 1e10; + + /// Default infinity string used by NOMAD::Double + /** Use Parameters::set_INF_STR(), or parameter INF_STR, + or NOMAD::Double::set_inf_str() to change it + */ + const std::string DEFAULT_INF_STR = "inf"; + + /// Default undefined value string used by NOMAD::Double + /** Use Parameters::set_UNDEF_STR(), or parameter UNDEF_STR, + or NOMAD::Double::set_undef_str() to change it + */ + const std::string DEFAULT_UNDEF_STR = "NaN"; + + /// log(10) (for display widths.) + const double LOG10 = 2.30258509299; + + const double INF = std::numeric_limits<double>::max(); ///< Infinity + + const double D_INT_MAX = UINT32_MAX; ///< The UINT32_MAX constant as a \c double + + // Singular Value Decomposition (SVD) constants: + const double SVD_EPS = 1e-13; ///< Epsilon for SVD + const int SVD_MAX_MPN = 1500; ///< Matrix maximal size (\c m+n ) + const double SVD_MAX_COND = NOMAD::INF; ///< Max. acceptable cond. number + + /// Default value for parameter POINT_DISPLAY_LIMIT + /** Use Parameters::set_POINT_DISPLAY_LIMIT() or parameter POINT_DISPLAY_LIMIT + or Point::set_display_limit() to change it */ + const int DEFAULT_POINT_DISPLAY_LIMIT = 20; + + // Display precisions. + const int DISPLAY_PRECISION_STD = 10; ///< Standard display precision + const int DISPLAY_PRECISION_BB = 15; ///< Display precision for blackboxes + + /// Constant for blackbox files #1. + const std::string BLACKBOX_INPUT_FILE_PREFIX = "nomad"; + + /// Constant for blackbox files #2. + const std::string BLACKBOX_INPUT_FILE_EXT = "input"; + + /// Constant for blackbox files #3. + const std::string BLACKBOX_OUTPUT_FILE_PREFIX = "nomad"; + + /// Constant for blackbox files #4. + const std::string BLACKBOX_OUTPUT_FILE_EXT = "output"; + + /// Display degree type. + enum dd_type { - NO_DISPLAY , ///< No display - MINIMAL_DISPLAY, ///< Minimal dispay - NORMAL_DISPLAY , ///< Normal display - FULL_DISPLAY ///< Full display + NO_DISPLAY , ///< No display + MINIMAL_DISPLAY, ///< Minimal dispay + NORMAL_DISPLAY , ///< Normal display + FULL_DISPLAY ///< Full display }; - - /// Types of the variables - // (do not modify this order) - enum bb_input_type + + /// Types of the variables + // (do not modify this order) + enum bb_input_type { - CONTINUOUS , ///< Continuous variable (default) (R) - INTEGER , ///< Integer variable (I) - CATEGORICAL , ///< Categorical variable (C) - BINARY ///< Binary variable (B) + CONTINUOUS , ///< Continuous variable (default) (R) + INTEGER , ///< Integer variable (I) + CATEGORICAL , ///< Categorical variable (C) + BINARY ///< Binary variable (B) }; - - /// Blackbox outputs type - enum bb_output_type + + /// Blackbox outputs type + enum bb_output_type { - OBJ , ///< Objective value - EB , ///< Extreme barrier constraint - PB , ///< progressive barrier constraint - // PEB ///< PB constraint that becomes EB once satisfied - PEB_P , ///< PEB constraint, state P (PB) - PEB_E , ///< PEB constraint, state E (EB) - FILTER , ///< Filter constraint - CNT_EVAL , ///< Output set to 0 or 1 to specify to count or not the - ///< blackbox evaluation - STAT_AVG , ///< Stat (average) - STAT_SUM , ///< Stat (sum) - UNDEFINED_BBO ///< Ignored output + OBJ , ///< Objective value + EB , ///< Extreme barrier constraint + PB , ///< progressive barrier constraint + // PEB ///< PB constraint that becomes EB once satisfied + PEB_P , ///< PEB constraint, state P (PB) + PEB_E , ///< PEB constraint, state E (EB) + FILTER , ///< Filter constraint + CNT_EVAL , ///< Output set to 0 or 1 to specify to count or not the + ///< blackbox evaluation + STAT_AVG , ///< Stat (average) + STAT_SUM , ///< Stat (sum) + UNDEFINED_BBO ///< Ignored output }; - - /// Formulation for multi-objective optimization - enum multi_formulation_type + + /// Formulation for multi-objective optimization + enum multi_formulation_type { - NORMALIZED , ///< Normalized formulation - PRODUCT , ///< Product formulation - DIST_L1 , ///< Distance formulation with norm L1 - DIST_L2 , ///< Distance formulation with norm L2 - DIST_LINF , ///< Distance formulation with norm Linf - UNDEFINED_FORMULATION ///< Undefined formulation + NORMALIZED , ///< Normalized formulation + PRODUCT , ///< Product formulation + DIST_L1 , ///< Distance formulation with norm L1 + DIST_L2 , ///< Distance formulation with norm L2 + DIST_LINF , ///< Distance formulation with norm Linf + UNDEFINED_FORMULATION ///< Undefined formulation }; - - /// Poll type - enum poll_type + + /// Poll type + enum poll_type { - PRIMARY , ///< Primary poll - SECONDARY ///< Secondary poll + PRIMARY , ///< Primary poll + SECONDARY ///< Secondary poll }; - - /// Poll center feasibility type - enum poll_center_type + + /// Poll center feasibility type + enum poll_center_type { - FEASIBLE , ///< Feasible poll center type - INFEASIBLE , ///< Infeasible poll center type - UNDEFINED_POLL_CENTER_TYPE ///< Undefined poll center type + FEASIBLE , ///< Feasible poll center type + INFEASIBLE , ///< Infeasible poll center type + UNDEFINED_POLL_CENTER_TYPE ///< Undefined poll center type }; - - /// Search type - enum search_type + + /// Search type + enum search_type { - X0_EVAL , ///< Starting point evaluation - POLL , ///< Poll - EXTENDED_POLL , ///< Extended poll - SEARCH , ///< Generic search - CACHE_SEARCH , ///< Cache search (does not require evals) - SPEC_SEARCH , ///< MADS speculative search (dynamic order in GPS) - LH_SEARCH , ///< Latin Hypercube (LH) search - LH_SEARCH_P1 , ///< Latin Hypercube (LH) search during phase one - MODEL_SEARCH , ///< Model search - VNS_SEARCH , ///< VNS search - P1_SEARCH , ///< Phase one search - ASYNCHRONOUS , ///< Parallel asynchronous final evaluations - USER_SEARCH , ///< User search - UNDEFINED_SEARCH ///< Undefined search + X0_EVAL , ///< Starting point evaluation + POLL , ///< Poll + EXTENDED_POLL , ///< Extended poll + SEARCH , ///< Generic search + CACHE_SEARCH , ///< Cache search (does not require evals) + SPEC_SEARCH , ///< MADS speculative search (dynamic order in GPS) + LH_SEARCH , ///< Latin Hypercube (LH) search + LH_SEARCH_P1 , ///< Latin Hypercube (LH) search during phase one + MODEL_SEARCH , ///< Model search + VNS_SEARCH , ///< VNS search + P1_SEARCH , ///< Phase one search + ASYNCHRONOUS , ///< Parallel asynchronous final evaluations + USER_SEARCH , ///< User search + UNDEFINED_SEARCH ///< Undefined search }; - - /// Model type - enum model_type + + /// Model type + enum model_type { - QUADRATIC_MODEL , ///< Quadratic model - TGP_MODEL , ///< TGP model - NO_MODEL ///< No models + QUADRATIC_MODEL , ///< Quadratic model + TGP_MODEL , ///< TGP model + NO_MODEL ///< No models }; - - /// TGP mode - enum TGP_mode_type + + /// TGP mode + enum TGP_mode_type { - TGP_FAST , ///< TGP fast mode. - TGP_PRECISE , ///< TGP precise mode. - TGP_USER ///< TGP user mode. + TGP_FAST , ///< TGP fast mode. + TGP_PRECISE , ///< TGP precise mode. + TGP_USER ///< TGP user mode. }; - - /// Success type of an iteration - // (do not modify this order) - enum success_type + + /// Success type of an iteration + // (do not modify this order) + enum success_type { - UNSUCCESSFUL , ///< Failure - PARTIAL_SUCCESS , ///< Partial success (improving) - FULL_SUCCESS ///< Full success (dominating) + UNSUCCESSFUL , ///< Failure + PARTIAL_SUCCESS , ///< Partial success (improving) + FULL_SUCCESS ///< Full success (dominating) }; - - /// Quadratic interpolation type - enum interpolation_type + + /// Quadratic interpolation type + enum interpolation_type { - MFN , ///< Minimum Frobenius Norm interpolation. - REGRESSION , ///< Regression. - WP_REGRESSION , ///< Well-poised regression. - UNDEFINED_INTERPOLATION_TYPE ///< Undefined. + MFN , ///< Minimum Frobenius Norm interpolation. + REGRESSION , ///< Regression. + WP_REGRESSION , ///< Well-poised regression. + UNDEFINED_INTERPOLATION_TYPE ///< Undefined. }; - - /// Stopping criteria - enum stop_type + + /// Stopping criteria + enum stop_type { - NO_STOP , ///< No stop - ERROR , ///< Error - UNKNOWN_STOP_REASON , ///< Unknown - CTRL_C , ///< Ctrl-C - USER_STOPPED , ///< User-stopped in Evaluator::update_iteration() - MESH_PREC_REACHED , ///< Mesh minimum precision reached - X0_FAIL , ///< Problem with starting point evaluation - P1_FAIL , ///< Problem with phase one - DELTA_M_MIN_REACHED , ///< Min mesh size - DELTA_P_MIN_REACHED , ///< Min poll size - L_MAX_REACHED , ///< Max mesh index - L_LIMITS_REACHED , ///< Mesh index limits - MAX_TIME_REACHED , ///< Max time - MAX_BB_EVAL_REACHED , ///< Max number of blackbox evaluations - MAX_SGTE_EVAL_REACHED , ///< Max number of surrogate evaluations - MAX_EVAL_REACHED , ///< Max number of evaluations - MAX_SIM_BB_EVAL_REACHED , ///< Max number of sim bb evaluations - MAX_ITER_REACHED , ///< Max number of iterations - MAX_CONS_FAILED_ITER , ///< Max number of consecutive failed iterations - FEAS_REACHED , ///< Feasibility - F_TARGET_REACHED , ///< F_TARGET - STAT_SUM_TARGET_REACHED , ///< STAT_SUM_TARGET - L_CURVE_TARGET_REACHED , ///< L_CURVE_TARGET - MULTI_MAX_BB_REACHED , ///< Max number of blackbox evaluations (multi obj.) - MULTI_NB_MADS_RUNS_REACHED , ///< Max number of MADS runs (multi obj.) - MULTI_STAGNATION , ///< Stagnation criterion (multi obj.) - MULTI_NO_PARETO_PTS , ///< No Pareto points (multi obj.) - MAX_CACHE_MEMORY_REACHED ///< Max cache memory + NO_STOP , ///< No stop + ERROR , ///< Error + UNKNOWN_STOP_REASON , ///< Unknown + CTRL_C , ///< Ctrl-C + USER_STOPPED , ///< User-stopped in Evaluator::update_iteration() + MESH_PREC_REACHED , ///< Mesh minimum precision reached + X0_FAIL , ///< Problem with starting point evaluation + P1_FAIL , ///< Problem with phase one + DELTA_M_MIN_REACHED , ///< Min mesh size + DELTA_P_MIN_REACHED , ///< Min poll size + L_MAX_REACHED , ///< Max mesh index + L_MIN_REACHED , ///< Min mesh index + L_LIMITS_REACHED , ///< Mesh index limits + XL_LIMITS_REACHED , ///< Mesh index limits + MAX_TIME_REACHED , ///< Max time + MAX_BB_EVAL_REACHED , ///< Max number of blackbox evaluations + MAX_SGTE_EVAL_REACHED , ///< Max number of surrogate evaluations + MAX_EVAL_REACHED , ///< Max number of evaluations + MAX_SIM_BB_EVAL_REACHED , ///< Max number of sim bb evaluations + MAX_ITER_REACHED , ///< Max number of iterations + MAX_CONS_FAILED_ITER , ///< Max number of consecutive failed iterations + FEAS_REACHED , ///< Feasibility + F_TARGET_REACHED , ///< F_TARGET + STAT_SUM_TARGET_REACHED , ///< STAT_SUM_TARGET + L_CURVE_TARGET_REACHED , ///< L_CURVE_TARGET + MULTI_MAX_BB_REACHED , ///< Max number of blackbox evaluations (multi obj.) + MULTI_NB_MADS_RUNS_REACHED , ///< Max number of MADS runs (multi obj.) + MULTI_STAGNATION , ///< Stagnation criterion (multi obj.) + MULTI_NO_PARETO_PTS , ///< No Pareto points (multi obj.) + MAX_CACHE_MEMORY_REACHED ///< Max cache memory }; - - /// Type of norm used for the computation of h - enum hnorm_type + + /// Type of norm used for the computation of h + enum hnorm_type { - L1 , ///< norm L1 - L2 , ///< norm L2 - LINF ///< norm Linf + L1 , ///< norm L1 + L2 , ///< norm L2 + LINF ///< norm Linf }; - - /// Types of directions - // (do not modify this order) - enum direction_type + + /// Types of directions + // (do not modify this order) + enum direction_type { - UNDEFINED_DIRECTION , ///< Undefined direction - MODEL_SEARCH_DIR , ///< Model search direction - NO_DIRECTION , ///< No direction - ORTHO_1 , ///< OrthoMADS 1 - ORTHO_2 , ///< OrthoMADS 2 - ORTHO_NP1_QUAD , ///< OrthoMADS n+1 use Quad model to determine n+1-th direction - ORTHO_NP1_NEG , ///< OrthoMADS n+1 use negative sum of n first directions to determine n+1-th direction - DYN_ADDED , ///< Dynamic addition (n+1-th direction added for ORTHO n+1) - ORTHO_2N , ///< OrthoMADS 2n - LT_1 , ///< LT-MADS 1 - LT_2 , ///< LT-MADS 2 - LT_2N , ///< LT-MADS 2n - LT_NP1 , ///< LT-MADS n+1 - GPS_BINARY , ///< GPS for binary variables - GPS_2N_STATIC , ///< GPS 2n static (classic coordinate search) - GPS_2N_RAND , ///< GPS 2n random - GPS_NP1_STATIC_UNIFORM , ///< GPS n+1 static uniform - GPS_NP1_STATIC , ///< GPS n+1 static - GPS_NP1_RAND_UNIFORM , ///< GPS n+1 random uniform - GPS_NP1_RAND , ///< GPS n+1 - PROSPECT_DIR ///< Prospect direction + UNDEFINED_DIRECTION , ///< Undefined direction + MODEL_SEARCH_DIR , ///< Model search direction + NO_DIRECTION , ///< No direction + ORTHO_1 , ///< OrthoMADS 1 + ORTHO_2 , ///< OrthoMADS 2 + ORTHO_NP1_QUAD , ///< OrthoMADS n+1 use Quad model to determine n+1-th direction + ORTHO_NP1_NEG , ///< OrthoMADS n+1 use negative sum of n first directions to determine n+1-th direction + DYN_ADDED , ///< Dynamic addition (n+1-th direction added for ORTHO n+1) + ORTHO_2N , ///< OrthoMADS 2n + LT_1 , ///< LT-MADS 1 + LT_2 , ///< LT-MADS 2 + LT_2N , ///< LT-MADS 2n + LT_NP1 , ///< LT-MADS n+1 + GPS_BINARY , ///< GPS for binary variables + GPS_2N_STATIC , ///< GPS 2n static (classic coordinate search) + GPS_2N_RAND , ///< GPS 2n random + GPS_NP1_STATIC_UNIFORM , ///< GPS n+1 static uniform + GPS_NP1_STATIC , ///< GPS n+1 static + GPS_NP1_RAND_UNIFORM , ///< GPS n+1 random uniform + GPS_NP1_RAND , ///< GPS n+1 + PROSPECT_DIR ///< Prospect direction }; - - /// Type for Eval_Point::check() failures - enum check_failed_type + + /// Type for Eval_Point::check() failures + enum check_failed_type { - CHECK_OK , ///< Correct check - LB_FAIL , ///< LB failure - UB_FAIL , ///< UB failure - FIX_VAR_FAIL , ///< Fixed variables failure - BIN_FAIL , ///< Binary failure - CAT_FAIL , ///< Categorical failure - INT_FAIL ///< Integer failure + CHECK_OK , ///< Correct check + LB_FAIL , ///< LB failure + UB_FAIL , ///< UB failure + FIX_VAR_FAIL , ///< Fixed variables failure + BIN_FAIL , ///< Binary failure + CAT_FAIL , ///< Categorical failure + INT_FAIL ///< Integer failure }; - - /// Type for cache indexes in Cache: - enum cache_index_type + + /// Type for cache indexes in Cache: + enum cache_index_type { - CACHE_1 , ///< Cache index #1 - CACHE_2 , ///< Cache index #2 - CACHE_3 , ///< Cache index #3 - UNDEFINED_CACHE ///< Undefined cache index + CACHE_1 , ///< Cache index #1 + CACHE_2 , ///< Cache index #2 + CACHE_3 , ///< Cache index #3 + UNDEFINED_CACHE ///< Undefined cache index }; - - /// Type for DISPLAY_STATS parameter - // (do not modify this order): - enum display_stats_type + + /// Type for DISPLAY_STATS parameter + // (do not modify this order): + enum display_stats_type { - DS_OBJ , ///< Objective (f) value - // (keep in first position) - DS_SIM_BBE , ///< Number of simulated bb evaluations - DS_BBE , ///< Number of bb evaluations - DS_SGTE , ///< Number of surrogate evaluations - DS_BBO , ///< All blackbox outputs - DS_EVAL , ///< Number of evaluations - DS_TIME , ///< Wall-clock time - DS_MESH_INDEX , ///< Mesh index - DS_MESH_SIZE , ///< Mesh size parameter Delta^m_k - DS_DELTA_M , ///< Same as \c DS_MESH_SIZE - DS_POLL_SIZE , ///< Poll size parameter Delta^p_k - DS_DELTA_P , ///< Same as \c DS_POLL_SIZE - DS_SOL , ///< Solution vector - DS_VAR , ///< One variable - DS_STAT_SUM , ///< Stat sum - DS_STAT_AVG , ///< Stat avg - DS_UNDEFINED ///< Undefined value - // (keep in last position) + DS_OBJ , ///< Objective (f) value + // (keep in first position) + DS_SIM_BBE , ///< Number of simulated bb evaluations + DS_BBE , ///< Number of bb evaluations + DS_BLK_EVA , ///< Number of block evaluation calls + DS_SGTE , ///< Number of surrogate evaluations + DS_BBO , ///< All blackbox outputs + DS_EVAL , ///< Number of evaluations + DS_TIME , ///< Wall-clock time + DS_MESH_INDEX , ///< Mesh index + DS_MESH_SIZE , ///< Mesh size parameter Delta^m_k + DS_DELTA_M , ///< Same as \c DS_MESH_SIZE + DS_POLL_SIZE , ///< Poll size parameter Delta^p_k + DS_DELTA_P , ///< Same as \c DS_POLL_SIZE + DS_SOL , ///< Solution vector + DS_VAR , ///< One variable + DS_STAT_SUM , ///< Stat sum + DS_STAT_AVG , ///< Stat avg + DS_UNDEFINED ///< Undefined value + // (keep in last position) }; - - /// Type for evaluation - enum eval_type + + /// Type for evaluation + enum eval_type { - TRUTH , ///< Truth - SGTE ///< Surrogate + TRUTH , ///< Truth + SGTE ///< Surrogate }; - - /// Type for an evaluation status - enum eval_status_type + + /// Type for an evaluation status + enum eval_status_type { - EVAL_FAIL , ///< Evaluation failure - EVAL_OK , ///< Correct evaluation - EVAL_IN_PROGRESS , ///< Evaluation in progress - UNDEFINED_STATUS ///< Undefined evaluation status + EVAL_FAIL , ///< Evaluation failure + EVAL_USER_REJECT , ///< Evaluation was rejected by user (not failure -> may submitted again) + EVAL_OK , ///< Correct evaluation + EVAL_IN_PROGRESS , ///< Evaluation in progress + UNDEFINED_STATUS ///< Undefined evaluation status }; - + } #endif diff --git a/src/nomad.cpp b/src/nomad.cpp index 88e49b48dd335498845d4e89bdecd45ec6d4fa3c..250c2a3d743175f4ceb0ee2409ebe888d49927db 100644 --- a/src/nomad.cpp +++ b/src/nomad.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -34,11 +34,11 @@ /* You can find information on the NOMAD software at www.gerad.ca/nomad */ /*-------------------------------------------------------------------------------------*/ /** - \file nomad.cpp - \brief NOMAD main file - \author Sebastien Le Digabel - \date 2010-04-12 -*/ + \file nomad.cpp + \brief NOMAD main file + \author Sebastien Le Digabel + \date 2010-04-12 + */ #include "nomad.hpp" /*------------------------------------------*/ @@ -46,128 +46,138 @@ /*------------------------------------------*/ int main ( int argc , char ** argv ) { - - // display: - NOMAD::Display out ( std::cout ); - out.precision ( NOMAD::DISPLAY_PRECISION_STD ); - - std::string error; - { - // NOMAD initializations: - NOMAD::begin ( argc , argv ); - - // usage: - if ( argc < 2 ) { - NOMAD::display_usage ( argv[0],std::cerr ); - NOMAD::end(); - return EXIT_FAILURE; - } - - // parameters file: - std::string param_file_name = argv[1]; - std::string opt = param_file_name; - NOMAD::toupper ( opt ); - - // display version if option '-v' has been specified: - if ( opt == "-U" ) { - NOMAD::display_usage ( argv[0], out ); - NOMAD::end(); - return EXIT_SUCCESS; - } - - - // display version if option '-v' has been specified: - if ( opt == "-V" || opt =="-VERSION") { - NOMAD::display_version ( out ); - NOMAD::end(); - return EXIT_SUCCESS; - } - - // display info if option '-i' has been specified: - if ( opt == "-I" || opt == "-INFO" ) { - NOMAD::display_info ( out ); - NOMAD::display_usage ( argv[0], out ); - NOMAD::end(); - return EXIT_SUCCESS; - } - - // parameters creation: - NOMAD::Parameters p ( out ); - - // display help on parameters if option '-h' has been specified: - if ( opt == "-H" || opt == "-HELP" ) { - p.help ( argc , argv ); - NOMAD::end(); - return EXIT_SUCCESS; - } - - // display developer help on parameters if option '-d' has been specified: - if ( opt == "-D" ) { - p.help ( argc , argv,true ); - NOMAD::end(); - return EXIT_SUCCESS; - } - - - // check the number of processess: + + // display: + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + + std::string error; + { + // NOMAD initializations: + NOMAD::begin ( argc , argv ); + + // usage: + if ( argc < 2 ) + { + NOMAD::display_usage ( argv[0],std::cerr ); + NOMAD::end(); + return EXIT_FAILURE; + } + + // parameters file: + std::string param_file_name = argv[1]; + std::string opt = param_file_name; + NOMAD::toupper ( opt ); + + // display version if option '-v' has been specified: + if ( opt == "-U" ) + { + NOMAD::display_usage ( argv[0], out ); + NOMAD::end(); + return EXIT_SUCCESS; + } + + + // display version if option '-v' has been specified: + if ( opt == "-V" || opt =="-VERSION") + { + NOMAD::display_version ( out ); + NOMAD::end(); + return EXIT_SUCCESS; + } + + // display info if option '-i' has been specified: + if ( opt == "-I" || opt == "-INFO" ) + { + NOMAD::display_info ( out ); + NOMAD::display_usage ( argv[0], out ); + NOMAD::end(); + return EXIT_SUCCESS; + } + + // parameters creation: + NOMAD::Parameters p ( out ); + + // display help on parameters if option '-h' has been specified: + if ( opt == "-H" || opt == "-HELP" ) + { + p.help ( argc , argv ); + NOMAD::end(); + return EXIT_SUCCESS; + } + + // display developer help on parameters if option '-d' has been specified: + if ( opt == "-D" ) + { + p.help ( argc , argv,true ); + NOMAD::end(); + return EXIT_SUCCESS; + } + + + // check the number of processess: #ifdef USE_MPI - if ( NOMAD::Slave::get_nb_processes() < 2 ) { - std::cerr << "ERROR: Incorrect command to run with MPI." << std::endl; - NOMAD::display_usage ( argv[0], std::cerr ); - NOMAD::end(); - return EXIT_FAILURE; - } + if ( NOMAD::Slave::get_nb_processes() < 2 ) + { + std::cerr << "ERROR: Incorrect command to run with MPI." << std::endl; + NOMAD::display_usage ( argv[0], std::cerr ); + NOMAD::end(); + return EXIT_FAILURE; + } #endif - - try { - - - // read parameters file: - p.read ( param_file_name ); - - // parameters check: - p.check(); - - // display NOMAD info: - if ( p.get_display_degree() > NOMAD::MINIMAL_DISPLAY) - NOMAD::display_info ( out ); - - // parameters display: - if ( NOMAD::Slave::is_master() && - p.get_display_degree() == NOMAD::FULL_DISPLAY ) - out << std::endl - << NOMAD::open_block ( "parameters" ) << std::endl - << p - << NOMAD::close_block(); - - // algorithm creation and execution: - NOMAD::Mads mads ( p , NULL ); - if ( p.get_nb_obj() == 1 ) - mads.run(); - else - mads.multi_run(); - + + try { + + + // read parameters file: + p.read ( param_file_name ); + + // parameters check: + p.check(); + + // display NOMAD info: + if ( p.get_display_degree() > NOMAD::MINIMAL_DISPLAY) + NOMAD::display_info ( out ); + + // parameters display: + if ( NOMAD::Slave::is_master() && + p.get_display_degree() == NOMAD::FULL_DISPLAY ) + out << std::endl + << NOMAD::open_block ( "parameters" ) << std::endl + << p + << NOMAD::close_block(); + + // algorithm creation and execution: + NOMAD::Mads mads ( p , NULL ); + if ( p.get_nb_obj() == 1 ) + mads.run(); + else + mads.multi_run(); + #ifdef MODEL_STATS - mads.display_model_stats ( out ); + mads.display_model_stats ( out ); #endif - - } - catch ( std::exception & e ) { - if ( NOMAD::Slave::is_master() ) { - error = std::string ( "NOMAD has been interrupted: " ) + e.what(); - std::cerr << std::endl << error << std::endl << std::endl; - } + + } + catch ( std::exception & e ) + { + if ( NOMAD::Slave::is_master() ) + { + error = std::string ( "NOMAD has been interrupted: " ) + e.what(); + std::cerr << std::endl << error << std::endl << std::endl; + } + } + + NOMAD::Slave::stop_slaves ( out ); + NOMAD::end(); } - NOMAD::Slave::stop_slaves ( out ); - NOMAD::end(); - } - #ifdef MEMORY_DEBUG - NOMAD::display_cardinalities ( out ); + NOMAD::display_cardinalities ( out ); #endif - - return ( error.empty() ) ? EXIT_SUCCESS : EXIT_FAILURE; + + return ( error.empty() ) ? EXIT_SUCCESS : EXIT_FAILURE; } /*-----------------------------------------------------*/ @@ -176,79 +186,79 @@ int main ( int argc , char ** argv ) #ifdef MEMORY_DEBUG void NOMAD::display_cardinalities ( const NOMAD::Display & out ) { - + #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - return; + if ( !NOMAD::Slave::is_master() ) + return; #endif - - // compute the biggest int value for appropriate display width: - int max = (NOMAD::Double::get_max_cardinality() > NOMAD::Point::get_max_cardinality()) + + // compute the biggest int value for appropriate display width: + int max = (NOMAD::Double::get_max_cardinality() > NOMAD::Point::get_max_cardinality()) ? NOMAD::Double::get_max_cardinality() : NOMAD::Point::get_max_cardinality(); - if ( NOMAD::Direction::get_max_cardinality() > max ) - max = NOMAD::Direction::get_max_cardinality(); - if ( NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality() > max ) - max = NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality(); - if ( NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality() > max ) - max = NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality(); - if ( NOMAD::Cache_File_Point::get_max_cardinality() > max ) - max = NOMAD::Cache_File_Point::get_max_cardinality(); - - // cardinalities display: - // ---------------------- - out << std::endl - << NOMAD::open_block ( "important objects in memory" ); - - // NOMAD::Signature: - out << "Signature : "; - out.display_int_w ( NOMAD::Signature::get_cardinality() , max ); - out << " (max="; - out.display_int_w ( NOMAD::Signature::get_max_cardinality() , max ); - out << ")" << std::endl; - - // NOMAD::Double: - out << "Double : "; - out.display_int_w ( NOMAD::Double::get_cardinality() , max ); - out << " (max="; - out.display_int_w ( NOMAD::Double::get_max_cardinality() , max ); - out << ")" << std::endl; - - // NOMAD::Point: - out << "Point : "; - out.display_int_w ( NOMAD::Point::get_cardinality() , max ); - out << " (max="; - out.display_int_w ( NOMAD::Point::get_max_cardinality() , max ); - out << ")" << std::endl; - - // NOMAD::Direction: - out << "Direction : "; - out.display_int_w ( NOMAD::Direction::get_cardinality() , max ); - out << " (max="; - out.display_int_w ( NOMAD::Direction::get_max_cardinality() , max ); - out << ")" << std::endl; - - // Set_Element<Eval_Point>: - out << "Set_Element<Eval_Point>: "; - out.display_int_w (NOMAD::Set_Element<NOMAD::Eval_Point>::get_cardinality(), max); - out << " (max="; - out.display_int_w (NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality(), max); - out << ")" << std::endl; - - // Set_Element<NOMAD::Signature>: - out << "Set_Element<Signature> : "; - out.display_int_w (NOMAD::Set_Element<NOMAD::Signature>::get_cardinality(), max); - out << " (max="; - out.display_int_w (NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality(), max); - out << ")" << std::endl; - - // NOMAD::Cache_File_Point: - out << "Cache_File_Point : "; - out.display_int_w ( NOMAD::Cache_File_Point::get_cardinality() , max ); - out << " (max="; - out.display_int_w ( NOMAD::Cache_File_Point::get_max_cardinality() , max ); - out << ")" << std::endl; - - out << NOMAD::close_block(); + if ( NOMAD::Direction::get_max_cardinality() > max ) + max = NOMAD::Direction::get_max_cardinality(); + if ( NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality() > max ) + max = NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality(); + if ( NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality() > max ) + max = NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality(); + if ( NOMAD::Cache_File_Point::get_max_cardinality() > max ) + max = NOMAD::Cache_File_Point::get_max_cardinality(); + + // cardinalities display: + // ---------------------- + out << std::endl + << NOMAD::open_block ( "important objects in memory" ); + + // NOMAD::Signature: + out << "Signature : "; + out.display_int_w ( NOMAD::Signature::get_cardinality() , max ); + out << " (max="; + out.display_int_w ( NOMAD::Signature::get_max_cardinality() , max ); + out << ")" << std::endl; + + // NOMAD::Double: + out << "Double : "; + out.display_int_w ( NOMAD::Double::get_cardinality() , max ); + out << " (max="; + out.display_int_w ( NOMAD::Double::get_max_cardinality() , max ); + out << ")" << std::endl; + + // NOMAD::Point: + out << "Point : "; + out.display_int_w ( NOMAD::Point::get_cardinality() , max ); + out << " (max="; + out.display_int_w ( NOMAD::Point::get_max_cardinality() , max ); + out << ")" << std::endl; + + // NOMAD::Direction: + out << "Direction : "; + out.display_int_w ( NOMAD::Direction::get_cardinality() , max ); + out << " (max="; + out.display_int_w ( NOMAD::Direction::get_max_cardinality() , max ); + out << ")" << std::endl; + + // Set_Element<Eval_Point>: + out << "Set_Element<Eval_Point>: "; + out.display_int_w (NOMAD::Set_Element<NOMAD::Eval_Point>::get_cardinality(), max); + out << " (max="; + out.display_int_w (NOMAD::Set_Element<NOMAD::Eval_Point>::get_max_cardinality(), max); + out << ")" << std::endl; + + // Set_Element<NOMAD::Signature>: + out << "Set_Element<Signature> : "; + out.display_int_w (NOMAD::Set_Element<NOMAD::Signature>::get_cardinality(), max); + out << " (max="; + out.display_int_w (NOMAD::Set_Element<NOMAD::Signature>::get_max_cardinality(), max); + out << ")" << std::endl; + + // NOMAD::Cache_File_Point: + out << "Cache_File_Point : "; + out.display_int_w ( NOMAD::Cache_File_Point::get_cardinality() , max ); + out << " (max="; + out.display_int_w ( NOMAD::Cache_File_Point::get_max_cardinality() , max ); + out << ")" << std::endl; + + out << NOMAD::close_block(); } #endif @@ -258,12 +268,12 @@ void NOMAD::display_cardinalities ( const NOMAD::Display & out ) void NOMAD::display_version ( const NOMAD::Display & out ) { #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - return; + if ( !NOMAD::Slave::is_master() ) + return; #endif - out << std::endl << "NOMAD - version " - << NOMAD::VERSION << " - www.gerad.ca/nomad" - << std::endl << std::endl; + out << std::endl << "NOMAD - version " + << NOMAD::VERSION << " - www.gerad.ca/nomad" + << std::endl << std::endl; } /*------------------------------------------*/ @@ -272,28 +282,28 @@ void NOMAD::display_version ( const NOMAD::Display & out ) void NOMAD::display_info ( const NOMAD::Display & out ) { #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - return; + if ( !NOMAD::Slave::is_master() ) + return; #endif - NOMAD::display_version ( out ); - out << NOMAD::open_block ( "Copyright (C) 2001-2013" ) - << "Mark A. Abramson - The Boeing Company" << std::endl - << "Charles Audet - Ecole Polytechnique de Montreal" << std::endl - << "Gilles Couture - Ecole Polytechnique de Montreal" << std::endl - << "John E. Dennis, Jr. - Rice University" << std::endl - << "Sebastien Le Digabel - Ecole Polytechnique de Montreal" << std::endl - << "Christophe Tribes - Ecole Polytechnique de Montreal" << std::endl - << NOMAD::close_block() - << std::endl - << "Funded in part by AFOSR and Exxon Mobil." << std::endl - << std::endl - << "License : \'" << NOMAD::LGPL_FILE << "\'" << std::endl - << "User guide: \'" << NOMAD::USER_GUIDE_FILE << "\'" << std::endl - << "Examples : \'" << NOMAD::EXAMPLES_DIR << "\'" << std::endl - << "Tools : \'" << NOMAD::TOOLS_DIR << "\'" << std::endl - << std::endl - << "Please report bugs to nomad@gerad.ca" - << std::endl; + NOMAD::display_version ( out ); + out << NOMAD::open_block ( "Copyright (C) 2001-2015" ) + << "Mark A. Abramson - The Boeing Company" << std::endl + << "Charles Audet - Ecole Polytechnique de Montreal" << std::endl + << "Gilles Couture - Ecole Polytechnique de Montreal" << std::endl + << "John E. Dennis, Jr. - Rice University" << std::endl + << "Sebastien Le Digabel - Ecole Polytechnique de Montreal" << std::endl + << "Christophe Tribes - Ecole Polytechnique de Montreal" << std::endl + << NOMAD::close_block() + << std::endl + << "Funded in part by AFOSR and Exxon Mobil." << std::endl + << std::endl + << "License : \'" << NOMAD::LGPL_FILE << "\'" << std::endl + << "User guide: \'" << NOMAD::USER_GUIDE_FILE << "\'" << std::endl + << "Examples : \'" << NOMAD::EXAMPLES_DIR << "\'" << std::endl + << "Tools : \'" << NOMAD::TOOLS_DIR << "\'" << std::endl + << std::endl + << "Please report bugs to nomad@gerad.ca" + << std::endl; } /*------------------------------------------*/ @@ -302,24 +312,24 @@ void NOMAD::display_info ( const NOMAD::Display & out ) void NOMAD::display_usage ( char* exeName, const NOMAD::Display & out ) { #ifdef USE_MPI - if ( !NOMAD::Slave::is_master() ) - return; - out << std::endl - << "Run NOMAD.MPI : mpirun -np p " << exeName << " parameters_file" << std::endl - << "Info : " << exeName << " -i" << std::endl - << "Help : " << exeName << " -h keyword(s) (or 'all')" << std::endl - << "Developer help : " << exeName << " -d keyword(s) (or 'all')" << std::endl - << "Version : " << exeName << " -v" << std::endl - << "Usage : " << exeName << " -u" << std::endl - << std::endl; + if ( !NOMAD::Slave::is_master() ) + return; + out << std::endl + << "Run NOMAD.MPI : mpirun -np p " << exeName << " parameters_file" << std::endl + << "Info : " << exeName << " -i" << std::endl + << "Help : " << exeName << " -h keyword(s) (or 'all')" << std::endl + << "Developer help : " << exeName << " -d keyword(s) (or 'all')" << std::endl + << "Version : " << exeName << " -v" << std::endl + << "Usage : " << exeName << " -u" << std::endl + << std::endl; #else - out << std::endl - << "Run NOMAD : " << exeName << " parameters_file" << std::endl - << "Info : " << exeName << " -i" << std::endl - << "Help : " << exeName << " -h keyword(s) (or 'all')" << std::endl - << "Developer help : " << exeName << " -d keyword(s) (or 'all')" << std::endl - << "Version : " << exeName << " -v" << std::endl - << "Usage : " << exeName << " -u" << std::endl - << std::endl; + out << std::endl + << "Run NOMAD : " << exeName << " parameters_file" << std::endl + << "Info : " << exeName << " -i" << std::endl + << "Help : " << exeName << " -h keyword(s) (or 'all')" << std::endl + << "Developer help : " << exeName << " -d keyword(s) (or 'all')" << std::endl + << "Version : " << exeName << " -v" << std::endl + << "Usage : " << exeName << " -u" << std::endl + << std::endl; #endif } diff --git a/src/nomad.hpp b/src/nomad.hpp index a035a3771ed5d8c283877738eb7335417382d4fa..580117703c945c1e9fe73ec345473d384a48b9b6 100644 --- a/src/nomad.hpp +++ b/src/nomad.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ diff --git a/src/utils.cpp b/src/utils.cpp index e6a593d91f29e0fd218a0fcfc09b0ffa1fded087..199400fa5e4f6a8341424377e4be09911385017c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -149,6 +149,17 @@ std::string NOMAD::itos ( int i ) return oss.str(); } +/*-----------------------------------------------------------------*/ +/* NOMAD::itos */ +/*-----------------------------------------------------------------*/ +std::string NOMAD::itos ( size_t i ) +{ + std::ostringstream oss; + oss << i; + return oss.str(); +} + + /*-----------------------------------------------------------------*/ /* NOMAD::toupper - 1/2 */ /*-----------------------------------------------------------------*/ @@ -801,20 +812,20 @@ bool NOMAD::string_to_index_range ( const std::string & s , int NOMAD::get_rank(double ** M, - int m, - int n) + size_t m, + size_t n) { double * W = new double [n]; double ** V = new double *[n]; - for (int i = 0 ; i < n ; ++i ) + for (size_t i = 0 ; i < n ; ++i ) { V[i]=new double [n]; } std::string error_msg; - NOMAD::SVD_decomposition ( error_msg , M , W , V , m , n ); + NOMAD::SVD_decomposition ( error_msg , M , W , V , static_cast<int>(m) , static_cast<int>(n) ); - for (int i=0;i<n;++i) + for (size_t i=0;i<n;++i) delete [] V[i]; delete [] V; @@ -826,7 +837,7 @@ int NOMAD::get_rank(double ** M, } int rank=0; - for (int i=0;i<n;i++) + for (size_t i=0;i<n;i++) { if (fabs(W[i])>NOMAD::SVD_EPS) rank++; diff --git a/src/utils.hpp b/src/utils.hpp index 9dceb88a086ec892f8a2d500ad0cbaee0fe096df..0fd19d580d5305ef5a1b9fcb7b85c5a0861dc674 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------------------------*/ -/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.6.1 */ +/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */ /* */ -/* Copyright (C) 2001-2012 Mark Abramson - the Boeing Company, Seattle */ +/* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */ /* Charles Audet - Ecole Polytechnique, Montreal */ /* Gilles Couture - Ecole Polytechnique, Montreal */ /* John Dennis - Rice University, Houston */ @@ -196,6 +196,13 @@ namespace NOMAD { */ bool dir_is_orthomads ( NOMAD::direction_type dt ); + /// If a NOMAD::direction_type variable corresponds to a Ortho-MADS direction using XMesh. + /** + \param dt The NOMAD::direction_type -- \b IN. + \return A boolean equal to \c true if \c dt corresponds to a Ortho-MADS direction using XMesh. + */ + bool dir_is_orthomads_xmesh ( NOMAD::direction_type dt ); + /// Check if a set of directions include Ortho-MADS direction. /** \param dir_types Set of direction types -- \b IN. @@ -205,7 +212,17 @@ namespace NOMAD { */ bool dirs_have_orthomads ( const std::set<NOMAD::direction_type> & dir_types ); - /// Check if a set of directions include Ortho-MADS N+1 direction. + /// Check if a set of directions include Ortho-MADS direction using XMesh. + /** + \param dir_types Set of direction types -- \b IN. + \return A boolean equal to \c true if at + least one direction in the set is + of type Ortho-MADS+XMesh. + */ + bool dirs_have_orthomads_xmesh ( const std::set<NOMAD::direction_type> & dir_types ); + + + /// Check if a set of direction types include Ortho-MADS N+1 direction. /** \param dir_types Set of direction types -- \b IN. \return A boolean equal to \c true if at @@ -213,8 +230,7 @@ namespace NOMAD { of type Ortho-MADS N+1. */ bool dirs_have_orthomads_np1 ( const std::set<NOMAD::direction_type> & dir_types ); - - + /// Construct the n first prime numbers. /** @@ -269,6 +285,15 @@ namespace NOMAD { */ std::string itos ( int i ); + + /// Transform a unsigned long (size_t) into a string. + /** + \param i The unsigned long -- \b IN. + \return The string. + */ + std::string itos ( size_t i ); + + /// Put a string into upper cases. /** \param s The string -- \b IN/OUT. @@ -353,8 +378,8 @@ namespace NOMAD { \return The rank>0 if the decomposition worked else 0. */ int get_rank(double **M, - int m, - int n); + size_t m, + size_t n); } diff --git a/tools/COOP-MADS/Cache_Server.cpp b/tools/COOP-MADS/Cache_Server.cpp index dd1df4aa7e279f269a748584e90ee6dbf116bd78..2b0d701d770f2793a12ea518853dba0b0fccc9f0 100644 --- a/tools/COOP-MADS/Cache_Server.cpp +++ b/tools/COOP-MADS/Cache_Server.cpp @@ -27,796 +27,823 @@ char Cache_Server::EP_SIGNAL = 'E'; /* constructor */ /*-----------------------------------*/ Cache_Server::Cache_Server ( const Display & out , - int rank , - int np , - const Double & h_min , - int max_bbe , - bool allow_multiple_evals ) - : Cache ( out , TRUTH ) , - _rank ( rank ) , - _np ( np ) , - _h_min ( h_min ) , - _max_bbe ( max_bbe ) , - _bf ( NULL ) , - _bi1 ( NULL ) , - _bi2 ( NULL ) , - _multiple_evals ( 0 ) , - _cache_hits ( 0 ) , - _cache_search_pts ( 0 ) , - _waited_pts ( NULL ) , - _clients_ext_pts ( NULL ) { - - // cache server: - if ( _rank == _np - 1 ) { - - _clients_ext_pts = new list<const Eval_Point*> [_np]; - - if ( !allow_multiple_evals ) { - _waited_pts = new Point * [_np]; - for ( int i = 0 ; i < _np ; ++i ) - _waited_pts[i] = NULL; + int rank , + int np , + const Double & h_min , + int max_bbe , + bool allow_multiple_evals ) +: Cache ( out , TRUTH ) , +_rank ( rank ) , +_np ( np ) , +_h_min ( h_min ) , +_max_bbe ( max_bbe ) , +_bf ( NULL ) , +_bi1 ( NULL ) , +_bi2 ( NULL ) , +_multiple_evals ( 0 ) , +_cache_hits ( 0 ) , +_cache_search_pts ( 0 ) , +_waited_pts ( NULL ) , +_clients_ext_pts ( NULL ) { + + // cache server: + if ( _rank == _np - 1 ) { + + _clients_ext_pts = new list<const Eval_Point*> [_np]; + + if ( !allow_multiple_evals ) { + _waited_pts = new Point * [_np]; + for ( int i = 0 ; i < _np ; ++i ) + _waited_pts[i] = NULL; + } } - } } /*-----------------------------------*/ /* destructor */ /*-----------------------------------*/ Cache_Server::~Cache_Server ( void ) { - if ( _waited_pts ) { - for ( int i = 0 ; i < _np ; ++i ) - if ( _waited_pts[i] ) - delete _waited_pts; - delete [] _waited_pts; - } - - if ( _clients_ext_pts ) - delete [] _clients_ext_pts; + if ( _waited_pts ) { + for ( int i = 0 ; i < _np ; ++i ) + if ( _waited_pts[i] ) + delete _waited_pts; + delete [] _waited_pts; + } + + if ( _clients_ext_pts ) + delete [] _clients_ext_pts; } /*-----------------------------------*/ /* start the server (process np-1) */ /*-----------------------------------*/ void Cache_Server::start ( void ) { - - int npm1 = _np-1; - - if ( _rank != npm1 ) - return; - - MPI_Status status; - int nb_stops = 0; - int source; - char signal; - - /*-------------*/ - /* main loop */ - /*-------------*/ - while ( nb_stops != npm1 ) { - - MPI_Recv ( &signal , 1 , MPI_CHAR , MPI_ANY_SOURCE , - Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD , &status ); - source = status.MPI_SOURCE; - - // stop signal: - // ------------ - if ( signal == Cache_Server::STOP_SIGNAL ) { - // cout << "STOP SIGNAL FROM RANK " << source << endl; - ++nb_stops; - } - - // find signal: - // ------------ - else if ( signal == Cache_Server::FIND_SIGNAL ) { - // cout << "FIND SIGNAL FROM RANK " << source << endl; - process_find_signal ( source ); - } - - // insert signal: - // -------------- - else if ( signal == Cache_Server::INSERT_SIGNAL ) { - // cout << "INSERT SIGNAL FROM RANK " << source << endl; - process_insert_signal ( source ); - } - - // number of extern points signal: - // ------------------------------- - else if ( signal == Cache_Server::NB_EP_SIGNAL ) { - // cout << "NB EXTERN POINTS SIGNAL FROM RANK " << source << endl; - int nb_client_extern_pts = _clients_ext_pts[source].size(); - MPI_Rsend ( &nb_client_extern_pts , 1 , MPI_INT , source , - Cache_Server::TAG_NB_EP , MPI_COMM_WORLD ); - } - - // extern point signal: - // -------------------- - else if ( signal == Cache_Server::EP_SIGNAL ) { - // cout << "EXTERN POINT SIGNAL FROM RANK " << source << endl; - process_ep_signal ( source ); + + int npm1 = _np-1; + + if ( _rank != npm1 ) + return; + + MPI_Status status; + int nb_stops = 0; + int source; + char signal; + + /*-------------*/ + /* main loop */ + /*-------------*/ + while ( nb_stops != npm1 ) { + + MPI_Recv ( &signal , 1 , MPI_CHAR , MPI_ANY_SOURCE , + Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD , &status ); + source = status.MPI_SOURCE; + + // stop signal: + // ------------ + if ( signal == Cache_Server::STOP_SIGNAL ) { + //cout << "STOP SIGNAL FROM RANK " << source << endl; + ++nb_stops; + } + + // find signal: + // ------------ + else if ( signal == Cache_Server::FIND_SIGNAL ) { + //cout << "FIND SIGNAL FROM RANK " << source << endl; + process_find_signal ( source ); + } + + // insert signal: + // -------------- + else if ( signal == Cache_Server::INSERT_SIGNAL ) { + //cout << "INSERT SIGNAL FROM RANK " << source << endl; + process_insert_signal ( source ); + } + + // number of extern points signal: + // ------------------------------- + else if ( signal == Cache_Server::NB_EP_SIGNAL ) { + //cout << "NB EXTERN POINTS SIGNAL FROM RANK " << source << endl; + int nb_client_extern_pts = _clients_ext_pts[source].size(); + MPI_Rsend ( &nb_client_extern_pts , 1 , MPI_INT , source , + Cache_Server::TAG_NB_EP , MPI_COMM_WORLD ); + } + + // extern point signal: + // -------------------- + else if ( signal == Cache_Server::EP_SIGNAL ) { + //cout << "EXTERN POINT SIGNAL FROM RANK " << source << endl; + process_ep_signal ( source ); + } } - } } /*---------------------------------*/ /* stop the server (clients) */ /*---------------------------------*/ void Cache_Server::stop ( void ) const { - int npm1 = _np-1; - if ( _rank == npm1 ) - return; - MPI_Send ( &Cache_Server::STOP_SIGNAL , 1 , MPI_CHAR , npm1 , - Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + int npm1 = _np-1; + if ( _rank == npm1 ) + return; + MPI_Send ( &Cache_Server::STOP_SIGNAL , 1 , MPI_CHAR , npm1 , + Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); } /*---------------------------------------*/ /* process the extern point signal */ /*---------------------------------------*/ void Cache_Server::process_ep_signal ( int source ) const { - - int nb_pt = ( _clients_ext_pts[source].size() > 0 ) ? 1 : 0; - - MPI_Rsend ( &nb_pt , 1 , MPI_INT , source , - Cache_Server::TAG_EP , MPI_COMM_WORLD ); - - // send and remove the extern point: - if ( nb_pt > 0 ) { - - const Eval_Point * x = *(_clients_ext_pts[source].begin()); - - ++_cache_search_pts; - - // send the point : - int i , n = x->size() , m = x->get_m(); - int itab[5]; - itab[0] = n; - itab[1] = m; - itab[2] = ( x->is_eval_ok() ) ? 1 : 0; - const int * ell = x->get_mesh_index(); - if ( ell ) { - itab[3] = 1; - itab[4] = *ell; + + int nb_pt = ( _clients_ext_pts[source].size() > 0 ) ? 1 : 0; + + MPI_Rsend ( &nb_pt , 1 , MPI_INT , source , + Cache_Server::TAG_EP , MPI_COMM_WORLD ); + + // send and remove the extern point: + if ( nb_pt > 0 ) { + + const Eval_Point * x = *(_clients_ext_pts[source].begin()); + + ++_cache_search_pts; + + // send the point : + int i , n = x->size() , m = x->get_m(); + int itab[5]; + itab[0] = n; + itab[1] = m; + itab[2] = ( x->is_eval_ok() ) ? 1 : 0; + + if ( x->get_signature() && ((x->get_signature()->get_mesh()->get_mesh_indices())[0]).is_defined() ) + { + itab[3] = 1; + itab[4] = static_cast<int>((x->get_signature()->get_mesh()->get_mesh_indices())[0].value()); + } + else + itab[3] = itab[4] = 0; + + double * rtab = new double[n+2*m]; + for ( i = 0 ; i < n ; ++i ) + rtab[i] = (*x)[i].value(); + + const Point & bbo = x->get_bb_outputs(); + + for ( i = 0 ; i < m ; ++i ) + if ( bbo[i].is_defined() ) { + rtab[2*i+n ] = 1.0; + rtab[2*i+n+1] = bbo[i].value(); + } + else + rtab[2*i+n] = rtab[2*i+n+1] = -1.0; + + MPI_Send ( itab , 5 , MPI_INT , source , + Cache_Server::TAG_X5 , MPI_COMM_WORLD ); + + MPI_Send ( rtab , n+2*m , MPI_DOUBLE , source , + Cache_Server::TAG_X6 , MPI_COMM_WORLD ); + + // remove the point: + _clients_ext_pts[source].pop_front(); } - else - itab[3] = itab[4] = 0; - - double * rtab = new double[n+2*m]; - for ( i = 0 ; i < n ; ++i ) - rtab[i] = (*x)[i].value(); - - const Point & bbo = x->get_bb_outputs(); - - for ( i = 0 ; i < m ; ++i ) - if ( bbo[i].is_defined() ) { - rtab[2*i+n ] = 1.0; - rtab[2*i+n+1] = bbo[i].value(); - } - else - rtab[2*i+n] = rtab[2*i+n+1] = -1.0; - - MPI_Send ( itab , 5 , MPI_INT , source , - Cache_Server::TAG_X5 , MPI_COMM_WORLD ); - - MPI_Send ( rtab , n+2*m , MPI_DOUBLE , source , - Cache_Server::TAG_X6 , MPI_COMM_WORLD ); - - // remove the point: - _clients_ext_pts[source].pop_front(); - } } /*-------------------------------*/ /* process the find signal */ /*-------------------------------*/ void Cache_Server::process_find_signal ( int source ) const { - - MPI_Status status; - int i; - - // receive the point coordinates: - int itab[2]; - MPI_Recv ( itab , 2 , MPI_INT , source , - Cache_Server::TAG_X1 , MPI_COMM_WORLD , &status ); - - int n = itab[0]; - int m = itab[1]; - - double * rtab = new double[n]; - - MPI_Recv ( rtab , n , MPI_DOUBLE , source , - Cache_Server::TAG_X2 , MPI_COMM_WORLD , &status ); - - // create the Eval_Point to search: - Eval_Point * x = new Eval_Point ( n , m ); - - for ( i = 0 ; i < n ; ++i ) - (*x)[i] = rtab[i]; - - delete [] rtab; - - // search in cache, or stop the algorithm: - const Eval_Point * cache_x; - - if ( _max_bbe > 0 && size() >= _max_bbe ) { - Eval_Point * stop_point = new Eval_Point ( n , m ); + + + MPI_Status status; + int i; + + // receive the point coordinates: + int itab[2]; + MPI_Recv ( itab , 2 , MPI_INT , source , + Cache_Server::TAG_X1 , MPI_COMM_WORLD , &status ); + + int n = itab[0]; + int m = itab[1]; + + double * rtab = new double[n]; + + MPI_Recv ( rtab , n , MPI_DOUBLE , source , + Cache_Server::TAG_X2 , MPI_COMM_WORLD , &status ); + + + + // create the Eval_Point to search: + Eval_Point * x = new Eval_Point ( n , m ); + for ( i = 0 ; i < n ; ++i ) - (*stop_point)[i] = (*x)[i]; - stop_point->set_eval_status ( EVAL_FAIL ); - cache_x = stop_point; - } - else - cache_x = Cache::find ( *x ); - - // cache hit signal : - int cache_hit; - - // point in cache : - if ( cache_x ) { - - delete x; - - cache_hit = 1; - - ++_cache_hits; - - MPI_Rsend ( &cache_hit , 1 , MPI_INT , source , - Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD ); - - // bb output values, defined values and eval_ok flag: - rtab = new double[m]; - char * ctab = new char [m+1]; - const Point & bbo = cache_x->get_bb_outputs(); - - for ( i = 0 ; i < m ; ++i ) { - if ( bbo[i].is_defined() ) { - rtab[i] = bbo[i].value(); - ctab[i] = '1'; - } - else { - rtab[i] = INF; - ctab[i] = '0'; - } - } - - ctab[m] = ( cache_x->is_eval_ok() ) ? '1' : '0'; - - MPI_Send ( rtab , m , MPI_DOUBLE , source , - Cache_Server::TAG_BBOR, MPI_COMM_WORLD ); + (*x)[i] = rtab[i]; - MPI_Send ( ctab , m+1 , MPI_CHAR , source , - Cache_Server::TAG_BBOC , MPI_COMM_WORLD ); - delete [] rtab; - delete [] ctab; - - // remove this point from _clients_ext_pts: - { - list<const Eval_Point *>::iterator - it = _clients_ext_pts[source].begin() , - end = _clients_ext_pts[source].end (); - while ( it != end ) { - if ( *it == cache_x ) { - _clients_ext_pts[source].erase(it); - break; - } - ++it; - } - } - } - - // point not in cache : - else { - - cache_hit = 0; - - // evaluation in progress ? - if ( _waited_pts ) { - - for ( i = 0 ; i < _np ; ++i ) - if ( _waited_pts[i] && *_waited_pts[i] == *x ) { - cache_hit = -1; - break; - } - - if ( cache_hit == 0 ) - _waited_pts[source] = x; - else - delete x; + + // search in cache, or stop the algorithm: + const Eval_Point * cache_x; + + + + + if ( _max_bbe > 0 && size() >= _max_bbe ) { + Eval_Point * stop_point = new Eval_Point ( n , m ); + for ( i = 0 ; i < n ; ++i ) + (*stop_point)[i] = (*x)[i]; + stop_point->set_eval_status ( EVAL_FAIL ); + cache_x = stop_point; } else - delete x; - - MPI_Rsend ( &cache_hit , 1 , MPI_INT , source , - Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD ); - } + cache_x = Cache::find ( *x ); + + + + // cache hit signal : + int cache_hit; + + // point in cache : + if ( cache_x ) { + + delete x; + + cache_hit = 1; + + ++_cache_hits; + + MPI_Rsend ( &cache_hit , 1 , MPI_INT , source , + Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD ); + + // bb output values, defined values and eval_ok flag: + rtab = new double[m]; + char * ctab = new char [m+1]; + const Point & bbo = cache_x->get_bb_outputs(); + + for ( i = 0 ; i < m ; ++i ) { + if ( bbo[i].is_defined() ) { + rtab[i] = bbo[i].value(); + ctab[i] = '1'; + } + else { + rtab[i] = INF; + ctab[i] = '0'; + } + } + + ctab[m] = ( cache_x->is_eval_ok() ) ? '1' : '0'; + + MPI_Send ( rtab , m , MPI_DOUBLE , source , + Cache_Server::TAG_BBOR, MPI_COMM_WORLD ); + + MPI_Send ( ctab , m+1 , MPI_CHAR , source , + Cache_Server::TAG_BBOC , MPI_COMM_WORLD ); + + delete [] rtab; + delete [] ctab; + + // remove this point from _clients_ext_pts: + { + list<const Eval_Point *>::iterator + it = _clients_ext_pts[source].begin() , + end = _clients_ext_pts[source].end (); + while ( it != end ) { + if ( *it == cache_x ) { + _clients_ext_pts[source].erase(it); + break; + } + ++it; + } + } + } + + // point not in cache : + else { + + + + cache_hit = 0; + + // evaluation in progress ? + if ( _waited_pts ) { + + for ( i = 0 ; i < _np ; ++i ) + if ( _waited_pts[i] && *_waited_pts[i] == *x ) { + cache_hit = -1; + break; + } + + if ( cache_hit == 0 ) + _waited_pts[source] = x; + else + delete x; + } + else + delete x; + + + MPI_Rsend ( &cache_hit , 1 , MPI_INT , source , + Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD ); + + } } /*--------------------*/ /* find a point */ /*--------------------*/ const Eval_Point * Cache_Server::find ( const Eval_Point & x ) const { - - MPI_Status status; - int npm1 = _np-1; - - // server: - if ( _rank == npm1 ) - return Cache::find ( x ); - - // A. search in local cache: - const Eval_Point * cache_x = Cache::find ( x ); - if ( cache_x ) - return cache_x; - - // B. ask the server. - int i , n = x.size() , m = x.get_m(); - int itab[2]; - itab[0] = n; - itab[1] = m; - double * rtab = new double[n]; - for ( i = 0 ; i < n ; ++i ) - rtab[i] = x[i].value(); - - int cache_hit = -1; - MPI_Request req = MPI_REQUEST_NULL; - - while ( cache_hit < 0 ) { - - // B1. send a request for cache_hit: - MPI_Irecv ( &cache_hit , 1 , MPI_INT , npm1 , - Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD , &req ); - - // B2. send the find signal: - MPI_Send ( &Cache_Server::FIND_SIGNAL , 1 , MPI_CHAR , - npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); - // B3. send the point coordinates: - MPI_Send ( itab , 2 , MPI_INT , npm1 , - Cache_Server::TAG_X1 , MPI_COMM_WORLD ); - - MPI_Send ( rtab , n , MPI_DOUBLE , npm1 , - Cache_Server::TAG_X2 , MPI_COMM_WORLD ); - - // B4. wait for the cache_hit request: - MPI_Wait ( &req , &status ); - - // cache hit possible values: - // - // -1: point is being evaluated by another process (wait) - // 0: point not in cache server - // 1: point in cache server - } - - delete [] rtab; - - // C. cache hit: receive the point outputs: - if ( cache_hit == 1 ) { - - // C.1. bb output values and eval status: - rtab = new double[m]; - MPI_Recv ( rtab , m , MPI_DOUBLE , npm1 , - Cache_Server::TAG_BBOR , MPI_COMM_WORLD , &status ); - - char * ctab = new char[m+1]; - MPI_Recv ( ctab , m+1 , MPI_CHAR , npm1 , - Cache_Server::TAG_BBOC , MPI_COMM_WORLD , &status ); - - Point bbo(m); - for ( i = 0 ; i < m ; ++i ) - if ( ctab[i]=='1' ) - bbo[i] = rtab[i]; - - delete [] rtab; - - // C.2. eval point construction: - Eval_Point * y = new Eval_Point ( n , m ); - y->set_bb_output ( bbo ); + MPI_Status status; + int npm1 = _np-1; + + // server: + if ( _rank == npm1 ) + return Cache::find ( x ); + + // A. search in local cache: + const Eval_Point * cache_x = Cache::find ( x ); + if ( cache_x ) + return cache_x; + + // B. ask the server. + int i , n = x.size() , m = x.get_m(); + int itab[2]; + itab[0] = n; + itab[1] = m; + double * rtab = new double[n]; for ( i = 0 ; i < n ; ++i ) - (*y)[i] = x[i]; - - y->set_eval_status ( (ctab[m]=='1') ? EVAL_OK : EVAL_FAIL ); - - y->set_current_run ( x.get_current_run() ); - - delete [] ctab; - - cache_x = y; - - // C.3. insertion in local cache: - const_cast<Cache_Server*>(this)->Cache::insert ( *cache_x ); - } - - return cache_x; + rtab[i] = x[i].value(); + + int cache_hit = -1; + MPI_Request req = MPI_REQUEST_NULL; + + while ( cache_hit < 0 ) { + + // B1. send a request for cache_hit: + MPI_Irecv ( &cache_hit , 1 , MPI_INT , npm1 , + Cache_Server::TAG_CACHE_HIT , MPI_COMM_WORLD , &req ); + + // B2. send the find signal: + MPI_Send ( &Cache_Server::FIND_SIGNAL , 1 , MPI_CHAR , + npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + + // B3. send the point coordinates: + MPI_Send ( itab , 2 , MPI_INT , npm1 , + Cache_Server::TAG_X1 , MPI_COMM_WORLD ); + + MPI_Send ( rtab , n , MPI_DOUBLE , npm1 , + Cache_Server::TAG_X2 , MPI_COMM_WORLD ); + + // B4. wait for the cache_hit request: + MPI_Wait ( &req , &status ); + + // cache hit possible values: + // + // -1: point is being evaluated by another process (wait) + // 0: point not in cache server + // 1: point in cache server + } + + delete [] rtab; + + // C. cache hit: receive the point outputs: + if ( cache_hit == 1 ) { + + // C.1. bb output values and eval status: + rtab = new double[m]; + MPI_Recv ( rtab , m , MPI_DOUBLE , npm1 , + Cache_Server::TAG_BBOR , MPI_COMM_WORLD , &status ); + + char * ctab = new char[m+1]; + MPI_Recv ( ctab , m+1 , MPI_CHAR , npm1 , + Cache_Server::TAG_BBOC , MPI_COMM_WORLD , &status ); + + Point bbo(m); + for ( i = 0 ; i < m ; ++i ) + if ( ctab[i]=='1' ) + bbo[i] = rtab[i]; + + delete [] rtab; + + // C.2. eval point construction: + Eval_Point * y = new Eval_Point ( n , m ); + y->set_bb_output ( bbo ); + for ( i = 0 ; i < n ; ++i ) + (*y)[i] = x[i]; + + y->set_eval_status ( (ctab[m]=='1') ? EVAL_OK : EVAL_FAIL ); + + y->set_current_run ( x.get_current_run() ); + + delete [] ctab; + + cache_x = y; + + // C.3. insertion in local cache: + const_cast<Cache_Server*>(this)->Cache::insert ( *cache_x ); + } + + return cache_x; } /*------------------------------------*/ /* process the insertion signal */ /*------------------------------------*/ void Cache_Server::process_insert_signal ( int source ) { + + + if ( _waited_pts && _waited_pts[source] ) { + delete _waited_pts[source]; + _waited_pts[source] = NULL; + } + + // receive the evaluation point: + MPI_Status status; + int itab[7]; + MPI_Recv ( itab , 7 , MPI_INT , source , + Cache_Server::TAG_X3 , MPI_COMM_WORLD , &status ); + + + int n = itab[0]; + int m = itab[1]; + + double * rtab = new double[n+2*m+2]; + + MPI_Recv ( rtab , n+2*m+2 , MPI_DOUBLE , source , + Cache_Server::TAG_X4 , MPI_COMM_WORLD , &status ); + + + + // create the Eval_Point to insert: + Eval_Point * x = new Eval_Point ( n , m ); + + int i; + for ( i = 0 ; i < n ; ++i ) + (*x)[i] = rtab[i]; + + for ( i = 0 ; i < m ; ++i ) + if ( rtab[2*i+n] > 0 ) + x->set_bb_output ( i , rtab[2*i+n+1] ); + + if ( itab[5] == 1 ) + x->set_f ( rtab[n+2*m ] ); + + if ( itab[6] == 1 ) + x->set_h ( rtab[n+2*m+1] ); + + delete [] rtab; + + x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); + + + if ( itab[3] == 1 && x->get_signature() ) + { + NOMAD::Point mesh_indices(n,NOMAD::Double(itab[4])); + cout << x->get_signature() << endl; - if ( _waited_pts && _waited_pts[source] ) { - delete _waited_pts[source]; - _waited_pts[source] = NULL; - } - - // receive the evaluation point: - MPI_Status status; - int itab[7]; - MPI_Recv ( itab , 7 , MPI_INT , source , - Cache_Server::TAG_X3 , MPI_COMM_WORLD , &status ); - - int n = itab[0]; - int m = itab[1]; - - double * rtab = new double[n+2*m+2]; - - MPI_Recv ( rtab , n+2*m+2 , MPI_DOUBLE , source , - Cache_Server::TAG_X4 , MPI_COMM_WORLD , &status ); - - // create the Eval_Point to insert: - Eval_Point * x = new Eval_Point ( n , m ); - - int i; - for ( i = 0 ; i < n ; ++i ) - (*x)[i] = rtab[i]; - - for ( i = 0 ; i < m ; ++i ) - if ( rtab[2*i+n] > 0 ) - x->set_bb_output ( i , rtab[2*i+n+1] ); - - if ( itab[5] == 1 ) - x->set_f ( rtab[n+2*m ] ); - - if ( itab[6] == 1 ) - x->set_h ( rtab[n+2*m+1] ); - - delete [] rtab; - - x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); - - if ( itab[3] == 1 ) - x->set_mesh_index ( &itab[4] ); - - // Eval_Point insertion in cache and multiple_evals detection: - const Eval_Point * cache_x = Cache::find ( *x ); - if ( cache_x ) { - ++_multiple_evals; - delete x; - x = const_cast<Eval_Point *>(cache_x); - } - else - Cache::insert ( *x ); + x->get_signature()->get_mesh()->set_mesh_indices ( mesh_indices); + } - // update the best points: - update_best_points ( *x , source ); + // Eval_Point insertion in cache and multiple_evals detection: + const Eval_Point * cache_x = Cache::find ( *x ); + if ( cache_x ) { + ++_multiple_evals; + delete x; + x = const_cast<Eval_Point *>(cache_x); + } + else + Cache::insert ( *x ); + + // update the best points: + update_best_points ( *x , source ); } /*--------------------*/ /* insert a point */ /*--------------------*/ void Cache_Server::insert ( const NOMAD::Eval_Point & x ) { - - // insertion in local cache : - Cache::insert ( x ); - - int npm1 = _np-1; - if ( _rank == npm1 ) - return; - - // insert signal : - MPI_Send ( &Cache_Server::INSERT_SIGNAL , 1 , MPI_CHAR , - npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); - - // send the point : - int i , n = x.size() , m = x.get_m(); - int itab[7]; - itab[0] = n; - itab[1] = m; - itab[2] = ( x.is_eval_ok() ) ? 1 : 0; - const int * ell = x.get_mesh_index(); - if ( ell ) { - itab[3] = 1; - itab[4] = *ell; - } - else - itab[3] = itab[4] = 0; - - double * rtab = new double[n+2*m+2]; - for ( i = 0 ; i < n ; ++i ) - rtab[i] = x[i].value(); - - const Point & bbo = x.get_bb_outputs(); - - for ( i = 0 ; i < m ; ++i ) - if ( bbo[i].is_defined() ) { - rtab[2*i+n ] = 1.0; - rtab[2*i+n+1] = bbo[i].value(); + + // insertion in local cache : + Cache::insert ( x ); + + int npm1 = _np-1; + if ( _rank == npm1 ) + return; + + // insert signal : + MPI_Send ( &Cache_Server::INSERT_SIGNAL , 1 , MPI_CHAR , + npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + + // send the point : + int i , n = x.size() , m = x.get_m(); + int itab[7]; + itab[0] = n; + itab[1] = m; + itab[2] = ( x.is_eval_ok() ) ? 1 : 0; + + if ( x.get_signature() && ((x.get_signature()->get_mesh()->get_mesh_indices())[0]).is_defined() ) + { + itab[3] = 1; + itab[4] = static_cast<int>((x.get_signature()->get_mesh()->get_mesh_indices())[0].value()); } else - rtab[2*i+n] = rtab[2*i+n+1] = -1.0; - - // f and h values: - if ( x.get_f().is_defined() ) { - itab[5 ] = 1; - rtab[n+2*m] = x.get_f().value(); - } - else { - itab[5 ] = 0; - rtab[n+2*m] = INF; - } - if ( x.get_h().is_defined() ) { - itab[6 ] = 1; - rtab[n+2*m+1] = x.get_h().value(); - } - else { - itab[6 ] = 0; - rtab[n+2*m+1] = INF; - } - - MPI_Send ( itab , 7 , MPI_INT , npm1 , - Cache_Server::TAG_X3 , MPI_COMM_WORLD ); - - MPI_Send ( rtab , n+2*m+2 , MPI_DOUBLE , npm1 , - Cache_Server::TAG_X4 , MPI_COMM_WORLD ); - - delete [] rtab; + itab[3] = itab[4] = 0; + + double * rtab = new double[n+2*m+2]; + for ( i = 0 ; i < n ; ++i ) + rtab[i] = x[i].value(); + + const Point & bbo = x.get_bb_outputs(); + + for ( i = 0 ; i < m ; ++i ) + if ( bbo[i].is_defined() ) { + rtab[2*i+n ] = 1.0; + rtab[2*i+n+1] = bbo[i].value(); + } + else + rtab[2*i+n] = rtab[2*i+n+1] = -1.0; + + // f and h values: + if ( x.get_f().is_defined() ) { + itab[5 ] = 1; + rtab[n+2*m] = x.get_f().value(); + } + else { + itab[5 ] = 0; + rtab[n+2*m] = INF; + } + if ( x.get_h().is_defined() ) { + itab[6 ] = 1; + rtab[n+2*m+1] = x.get_h().value(); + } + else { + itab[6 ] = 0; + rtab[n+2*m+1] = INF; + } + + MPI_Send ( itab , 7 , MPI_INT , npm1 , + Cache_Server::TAG_X3 , MPI_COMM_WORLD ); + + MPI_Send ( rtab , n+2*m+2 , MPI_DOUBLE , npm1 , + Cache_Server::TAG_X4 , MPI_COMM_WORLD ); + + delete [] rtab; } /*--------------------------------------*/ /* get and remove an extern point */ /*--------------------------------------*/ const Eval_Point * Cache_Server::get_and_remove_extern_point ( void ) const { - - int npm1 = _np-1; - - if ( _rank == npm1 ) - return NULL; - - // extern point from the client: - // ----------------------------- - if ( Cache::get_nb_extern_points() > 0 ) - return Cache::get_and_remove_extern_point(); - - // extern point from the server: - // ----------------------------- - int nb_pt; - - // send a request for an extern point: - MPI_Request req; - MPI_Irecv ( &nb_pt , 1 , MPI_INT , npm1 , - Cache_Server::TAG_EP , MPI_COMM_WORLD , &req ); - - // extern points signal : - MPI_Send ( &Cache_Server::EP_SIGNAL , 1 , MPI_CHAR , - npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); - - // wait for the request: - MPI_Status status; - MPI_Wait ( &req , &status ); - - if ( nb_pt == 0 ) - return NULL; - - // receive the extern point: - int itab[5]; - MPI_Recv ( itab , 5 , MPI_INT , npm1 , - Cache_Server::TAG_X5 , MPI_COMM_WORLD , &status ); - - int n = itab[0]; - int m = itab[1]; - - double * rtab = new double[n+2*m]; - - MPI_Recv ( rtab , n+2*m , MPI_DOUBLE , npm1 , - Cache_Server::TAG_X6 , MPI_COMM_WORLD , &status ); - - // create the Eval_Point: - Eval_Point * x = new Eval_Point ( n , m ); - - int i; - for ( i = 0 ; i < n ; ++i ) - (*x)[i] = rtab[i]; - - for ( i = 0 ; i < m ; ++i ) - if ( rtab[2*i+n] > 0 ) - x->set_bb_output ( i , rtab[2*i+n+1] ); - - delete [] rtab; - - x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); - - if ( itab[3] == 1 ) - x->set_mesh_index ( &itab[4] ); - - // insert the point in local cache: - const Eval_Point * cache_x = Cache::find ( *x ); - if ( cache_x ) { - delete x; - return cache_x; - } - - x->set_current_run ( true ); - const_cast<Cache_Server*>(this)->Cache::insert ( *x ); - x->set_current_run ( false ); - - return x; + + int npm1 = _np-1; + + if ( _rank == npm1 ) + return NULL; + + // extern point from the client: + // ----------------------------- + if ( Cache::get_nb_extern_points() > 0 ) + return Cache::get_and_remove_extern_point(); + + // extern point from the server: + // ----------------------------- + int nb_pt; + + // send a request for an extern point: + MPI_Request req; + MPI_Irecv ( &nb_pt , 1 , MPI_INT , npm1 , + Cache_Server::TAG_EP , MPI_COMM_WORLD , &req ); + + // extern points signal : + MPI_Send ( &Cache_Server::EP_SIGNAL , 1 , MPI_CHAR , + npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + + // wait for the request: + MPI_Status status; + MPI_Wait ( &req , &status ); + + if ( nb_pt == 0 ) + return NULL; + + // receive the extern point: + int itab[5]; + MPI_Recv ( itab , 5 , MPI_INT , npm1 , + Cache_Server::TAG_X5 , MPI_COMM_WORLD , &status ); + + int n = itab[0]; + int m = itab[1]; + + double * rtab = new double[n+2*m]; + + MPI_Recv ( rtab , n+2*m , MPI_DOUBLE , npm1 , + Cache_Server::TAG_X6 , MPI_COMM_WORLD , &status ); + + // create the Eval_Point: + Eval_Point * x = new Eval_Point ( n , m ); + + int i; + for ( i = 0 ; i < n ; ++i ) + (*x)[i] = rtab[i]; + + for ( i = 0 ; i < m ; ++i ) + if ( rtab[2*i+n] > 0 ) + x->set_bb_output ( i , rtab[2*i+n+1] ); + + delete [] rtab; + + x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); + + if ( itab[3] == 1 && x->get_signature() ) + { + x->get_signature()->get_mesh()->set_mesh_indices ( NOMAD::Point(n,NOMAD::Double(itab[4])) ); + } + + + // insert the point in local cache: + const Eval_Point * cache_x = Cache::find ( *x ); + if ( cache_x ) { + delete x; + return cache_x; + } + + x->set_current_run ( true ); + const_cast<Cache_Server*>(this)->Cache::insert ( *x ); + x->set_current_run ( false ); + + return x; } /*---------------------------------------*/ /* get the number of extern points */ /*---------------------------------------*/ int Cache_Server::get_nb_extern_points ( void ) const { - - int nb_client_extern_pts = Cache::get_nb_extern_points(); - int nb_server_extern_pts = 0; - int npm1 = _np-1; - - if ( _rank != npm1 ) { - - // send a request for the number of extern points: - MPI_Request req; - MPI_Irecv ( &nb_server_extern_pts , 1 , MPI_INT , npm1 , - Cache_Server::TAG_NB_EP , MPI_COMM_WORLD , &req ); - - // number of extern points signal : - MPI_Send ( &Cache_Server::NB_EP_SIGNAL , 1 , MPI_CHAR , - npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); - - // wait for the request: - MPI_Status status; - MPI_Wait ( &req , &status ); - } - - return nb_client_extern_pts + nb_server_extern_pts; + + int nb_client_extern_pts = Cache::get_nb_extern_points(); + int nb_server_extern_pts = 0; + int npm1 = _np-1; + + if ( _rank != npm1 ) { + + // send a request for the number of extern points: + MPI_Request req; + MPI_Irecv ( &nb_server_extern_pts , 1 , MPI_INT , npm1 , + Cache_Server::TAG_NB_EP , MPI_COMM_WORLD , &req ); + + // number of extern points signal : + MPI_Send ( &Cache_Server::NB_EP_SIGNAL , 1 , MPI_CHAR , + npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + + // wait for the request: + MPI_Status status; + MPI_Wait ( &req , &status ); + } + + return nb_client_extern_pts + nb_server_extern_pts; } /*---------------------------------*/ /* display the extern points */ /*---------------------------------*/ void Cache_Server::display_extern_pts ( const Display & out ) const { - - int npm1 = _np-1; - - // server: - // ------- - if ( _rank == npm1 ) { - - list<const Eval_Point*>::const_iterator it; - out << endl << open_block ("Clients extern points"); - - for ( int i = 0 ; i < npm1 ; ++i ) { - out.open_block ( "client #"+itos(i) ); - for ( it = _clients_ext_pts[i].begin() ; - it != _clients_ext_pts[i].end () ; - ++it ) { - out << "#" << (*it)->get_tag() << " ( "; - (*it)->Point::display ( out ); - out << " ) " << " [" - << (*it)->get_bb_outputs() << " ] f=" - << (*it)->get_f() << " h=" - << (*it)->get_h() << endl; - } - out.close_block(); + + int npm1 = _np-1; + + // server: + // ------- + if ( _rank == npm1 ) { + + list<const Eval_Point*>::const_iterator it; + out << endl << open_block ("Clients extern points"); + + for ( int i = 0 ; i < npm1 ; ++i ) { + out.open_block ( "client #"+itos(i) ); + for ( it = _clients_ext_pts[i].begin() ; + it != _clients_ext_pts[i].end () ; + ++it ) { + out << "#" << (*it)->get_tag() << " ( "; + (*it)->Point::display ( out ); + out << " ) " << " [" + << (*it)->get_bb_outputs() << " ] f=" + << (*it)->get_f() << " h=" + << (*it)->get_h() << endl; + } + out.close_block(); + } } - } - - // clients: - else { - - out << endl - << open_block ( "Process #" + itos(_rank) + ": extern points" ); - - out << "number of points = " - << get_nb_extern_points() << endl; - - const Eval_Point * extern_pt = get_and_remove_extern_point(); - - while ( extern_pt ) { - - out << "#" << extern_pt->get_tag() << " ( "; - extern_pt->Point::display ( out ); - out << " ) " << " [" - << extern_pt->get_bb_outputs() << " ] f=" - << extern_pt->get_f() << " h=" - << extern_pt->get_h() << endl; - - extern_pt = get_and_remove_extern_point(); + + // clients: + else { + + out << endl + << open_block ( "Process #" + itos(_rank) + ": extern points" ); + + out << "number of points = " + << get_nb_extern_points() << endl; + + const Eval_Point * extern_pt = get_and_remove_extern_point(); + + while ( extern_pt ) { + + out << "#" << extern_pt->get_tag() << " ( "; + extern_pt->Point::display ( out ); + out << " ) " << " [" + << extern_pt->get_bb_outputs() << " ] f=" + << extern_pt->get_f() << " h=" + << extern_pt->get_h() << endl; + + extern_pt = get_and_remove_extern_point(); + } } - } - out << close_block() << endl; + out << close_block() << endl; } /*--------------------------------------*/ /* update and display the best points */ /*--------------------------------------*/ void Cache_Server::update_best_points ( const Eval_Point & x , - int source ) { - const Double & f = x.get_f(); - const Double & h = x.get_h(); - - if ( !f.is_defined() || !h.is_defined() ) - return; - - int i; - bool add_x = false; - - // feasible: - if ( h <= _h_min ) { - - // new best feasible point: - if ( !_bf || f < _bf->get_f() ) { - _bf = &x; - add_x = true; - display_current_solution(); - } - } - - // infeasible: - else { - if ( !_bi1 || h < _bi1->get_h() ) { - _bi1 = &x; - add_x = true; + int source ) { + const Double & f = x.get_f(); + const Double & h = x.get_h(); + + if ( !f.is_defined() || !h.is_defined() ) + return; + + int i; + bool add_x = false; + + // feasible: + if ( h <= _h_min ) { + + // new best feasible point: + if ( !_bf || f < _bf->get_f() ) { + _bf = &x; + add_x = true; + display_current_solution(); + } } - if ( !_bi2 || f < _bi2->get_f() ) { - _bi2 = &x; - add_x = true; + + // infeasible: + else { + if ( !_bi1 || h < _bi1->get_h() ) { + _bi1 = &x; + add_x = true; + } + if ( !_bi2 || f < _bi2->get_f() ) { + _bi2 = &x; + add_x = true; + } } - } - - if ( add_x ) - for ( i = 0 ; i < _np-1 ; ++i ) - if ( i != source ) - _clients_ext_pts[i].push_front ( &x ); + + if ( add_x ) + for ( i = 0 ; i < _np-1 ; ++i ) + if ( i != source ) + _clients_ext_pts[i].push_front ( &x ); } /*-----------------------------------------*/ /* display the current best solution */ /*-----------------------------------------*/ void Cache_Server::display_current_solution ( void ) const { - if ( _rank != _np-1 || !_bf ) - return; - _out << _clock.get_real_time() << "\t" - << size() << "\t" << _bf->get_f() << endl; + if ( _rank != _np-1 || !_bf ) + return; + _out << _clock.get_real_time() << "\t" + << size() << "\t" << _bf->get_f() << endl; } /*-------------------------------*/ /* display the best points */ /*-------------------------------*/ void Cache_Server::display_best_points ( const Display & out ) const { - if ( _rank != _np-1 ) - return; - - // stats: - out << "evaluations : " << size() << endl - << "multiple evaluations : " << _multiple_evals << endl - << "cache hits : " << _cache_hits << endl - << "cache search points : " << _cache_search_pts << endl; - - // best feasible solution: - out << "best feasible solution: "; - if ( _bf ) { - out << "x=( "; - _bf->Point::display(out); - out << " )" - << " F(x)=[ " << _bf->get_bb_outputs() << " ] h=" - << _bf->get_h() << " f=" << _bf->get_f() << endl; - } - else - out << "NULL" << endl; - - // best infeasible solutions: - if ( _bi1 ) { - out << "best infeas. sol. #1 : x=( "; - _bi1->Point::display(out); - out << " )" - << " F(x)=[ " << _bi1->get_bb_outputs() << " ] h=" - << _bi1->get_h() << " f=" << _bi1->get_f() << endl; - } - - if ( _bi2 && _bi2 != _bi1 ) { - out << "best infeas. sol. #2 : x=( "; - _bi2->Point::display(out); - out << " )" - << " F(x)=[ " << _bi2->get_bb_outputs() << " ] h=" - << _bi2->get_h() << " f=" << _bi2->get_f() << endl; - } + if ( _rank != _np-1 ) + return; + + // stats: + out << "evaluations : " << size() << endl + << "multiple evaluations : " << _multiple_evals << endl + << "cache hits : " << _cache_hits << endl + << "cache search points : " << _cache_search_pts << endl; + + // best feasible solution: + out << "best feasible solution: "; + if ( _bf ) { + out << "x=( "; + _bf->Point::display(out); + out << " )" + << " F(x)=[ " << _bf->get_bb_outputs() << " ] h=" + << _bf->get_h() << " f=" << _bf->get_f() << endl; + } + else + out << "NULL" << endl; + + // best infeasible solutions: + if ( _bi1 ) { + out << "best infeas. sol. #1 : x=( "; + _bi1->Point::display(out); + out << " )" + << " F(x)=[ " << _bi1->get_bb_outputs() << " ] h=" + << _bi1->get_h() << " f=" << _bi1->get_f() << endl; + } + + if ( _bi2 && _bi2 != _bi1 ) { + out << "best infeas. sol. #2 : x=( "; + _bi2->Point::display(out); + out << " )" + << " F(x)=[ " << _bi2->get_bb_outputs() << " ] h=" + << _bi2->get_h() << " f=" << _bi2->get_f() << endl; + } } diff --git a/tools/COOP-MADS/main.cpp b/tools/COOP-MADS/main.cpp index 83457489c3cc8a700e22d0742d8313c1fb3e089e..2b698d030684ce6ec1f9025225a9318e262c2e56 100644 --- a/tools/COOP-MADS/main.cpp +++ b/tools/COOP-MADS/main.cpp @@ -47,10 +47,8 @@ int main ( int argc , char ** argv ) { p.set_DISPLAY_DEGREE ( NO_DISPLAY ); p.set_DISPLAY_STATS ( "process #" + itos(rank) + " BBE OBJ" ); p.set_SEED ( get_pid() ); - - // these Halton seeds are valid for up to 1000 variables: - if ( rank != 0 ) - p.set_HALTON_SEED ( 7999 + 99*rank ); + + p.set_ANISOTROPIC_MESH(false); // cache search: p.set_CACHE_SEARCH ( USE_CACHE_SEARCH ); diff --git a/tools/COOP-MADS/problems/G2_10/runExample.log b/tools/COOP-MADS/problems/G2_10/runExample.log index 3546193bb728cb2a64990bc0fecca57b130459c7..133b63da0c5310eabc004c8305250b10c0580d87 100644 --- a/tools/COOP-MADS/problems/G2_10/runExample.log +++ b/tools/COOP-MADS/problems/G2_10/runExample.log @@ -2,28 +2,22 @@ TIME BBE OBJ 0 1 -0.001746040966254643 -0 2 -0.01019466859856645 -0 3 -0.01262929088633488 -0 4 -0.02737222459485665 -0 6 -0.03633168612260773 -0 8 -0.03649432351615038 -0 10 -0.06795149962330944 -0 13 -0.07360536752310878 -0 14 -0.09066696872825573 -0 25 -0.106549342247164 -0 32 -0.1145527897987842 -1 43 -0.1219426591809022 -1 44 -0.134377704552527 -1 48 -0.1582591392910043 -1 57 -0.1794716687140574 -2 68 -0.1954582060851584 -2 92 -0.1967787148730447 -2 100 -0.2074681592385568 -2 101 -0.2081555540466212 -6 101 -0.2081555540466212 +0 2 -0.08743509125381764 +0 3 -0.09502614738887308 +0 12 -0.1241414508378795 +0 13 -0.1243880456661476 +0 14 -0.1282392319163835 +0 17 -0.1473005317907833 +0 35 -0.150183285112481 +0 46 -0.1572895785336448 +0 65 -0.194312112152985 +1 99 -0.215523726538665 +2 100 -0.215523726538665 -evaluations : 101 +evaluations : 100 multiple evaluations : 0 -cache hits : 1507 -cache search points : 33 -best feasible solution: x=( 3 3 3 7 7 3 3 3 3 7 ) F(x)=[ -750140.25 -33 -0.2081555540466212 ] h=0 f=-0.2081555540466212 +cache hits : 1374 +cache search points : 26 +best feasible solution: x=( 9 8 6 3 6 3.5 3 3 5 3 ) F(x)=[ -3674159.25 -25.5 -0.215523726538665 ] h=0 f=-0.215523726538665 +best infeas. sol. #1 : x=( 6 10 8.5 8.5 7.5 0 5.5 0.5 6.5 3.5 ) F(x)=[ 0.75 -18.5 -0.1232423970453351 ] h=0.75 f=-0.1232423970453351 +best infeas. sol. #2 : x=( 5.5 9 9.5 2.5 6.5 1 0 2 5.5 5 ) F(x)=[ 0.75 -28.5 -0.1303069434264795 ] h=0.75 f=-0.1303069434264795 diff --git a/tools/COOP-MADS/problems/RHEOLOGY/runExample.log b/tools/COOP-MADS/problems/RHEOLOGY/runExample.log index ae57c2b69c698961a1208d5914a9c1d6592e48b1..3342d27408b5917f424fdd31ab4f7ab1b6fe1015 100644 --- a/tools/COOP-MADS/problems/RHEOLOGY/runExample.log +++ b/tools/COOP-MADS/problems/RHEOLOGY/runExample.log @@ -2,125 +2,121 @@ TIME BBE OBJ 0 1 409.067422156616 -0 30 313.290666411087 -0 33 309.645062177308 -0 61 305.603554188662 -0 73 274.349745457906 -1 99 272.250128417616 -1 103 268.037284648273 -1 162 262.043368378846 -1 163 260.97381694916 -1 186 256.09850445141 -1 221 256.020492150343 -1 233 254.953534545783 -1 267 254.8720087317 -1 270 254.656322775826 -1 305 254.543645584072 -2 330 254.400682410755 -2 389 254.388049251401 -2 391 254.353067924927 -2 405 254.242240065196 -2 410 254.176238806978 -2 415 254.152120602604 -2 429 254.149410983437 -2 431 253.918898261246 -2 441 253.639818573328 -2 443 253.55474416257 -2 457 251.141461891318 -2 491 250.248064868682 -2 524 250.244171560004 -2 527 249.849164247345 -2 547 249.567222954085 -2 548 249.366239271189 -3 580 249.155498293568 -3 589 249.047280135277 -3 591 248.252066657473 -3 595 246.518827325057 -3 617 245.800965359953 -3 620 243.882335163937 -3 628 242.422501962147 -3 634 242.276927272015 -3 671 241.954108810511 -3 675 241.010585095445 -3 682 240.459307984963 -3 710 238.836934740093 -3 712 236.774345707808 -3 742 234.62986725466 -3 759 233.935408736368 -3 761 231.87366973145 -3 763 229.965932283635 -3 767 219.750264964398 -3 789 218.765266185861 -3 807 218.764685351186 -4 815 216.792767347362 -4 849 216.495270200364 -4 851 216.10267122674 -4 863 213.554832966872 -4 910 211.268885538006 -4 913 209.197077094276 -4 935 208.431462438035 -4 946 206.720752330144 -4 992 206.548275350849 -4 1013 206.178168852652 -4 1014 206.072252871052 -4 1015 205.053416198016 -4 1021 204.42785503742 -4 1023 202.520104744871 -4 1026 195.391180273313 -4 1029 177.49001293616 -4 1039 160.826983870132 -5 1062 160.272301645993 -5 1072 132.497730491384 -5 1095 132.211409945968 -5 1125 115.126136735852 -5 1142 103.410900663377 -5 1146 85.2425026449348 -5 1199 83.74223201807099 -5 1204 83.598074475476 -5 1230 71.84331120065551 -5 1237 70.29089492791761 -5 1260 66.3415584718624 -6 1309 65.7246434832216 -6 1313 60.1426677896144 -6 1350 58.9447055060385 -6 1351 55.614847308125 -6 1360 53.0178794687419 -6 1388 48.3232738347114 -6 1422 47.6627115940218 -6 1432 42.8248958769611 -6 1443 37.0265396215478 -6 1465 36.6923042836351 -6 1467 35.8124722457898 -7 1515 34.8258600812852 -7 1543 34.2676414158401 -7 1562 34.0364811732794 -7 1563 33.3484189173833 -7 1586 33.0532004059883 -7 1658 33.0035616836186 -7 1664 32.9776044737094 -7 1666 32.9093509482159 -8 1747 32.9056660232471 -8 1750 32.9049205755534 -8 1765 32.9003950798501 -8 1783 32.8983814142292 -8 1784 32.8884427141221 -8 1788 32.8680789470553 -8 1817 32.8557333071788 -8 1819 32.8409646841575 -8 1820 32.8187524114084 -8 1823 32.7593360339631 -8 1883 32.7588840107007 -8 1885 32.7575288245444 -8 1888 32.7521213326056 -8 1937 32.7512802945923 -8 1943 32.7503235466136 -8 1987 32.7498744681357 -8 1989 32.748528115889 -8 2000 32.7481266130554 -9 2001 32.7481266130554 +0 2 407.173143113625 +0 7 326.103515990633 +0 42 325.623426986692 +0 59 295.895440816156 +0 72 293.4555631559 +0 90 279.968263515696 +0 139 275.288266367226 +0 187 275.132352128014 +0 209 275.075795191333 +0 210 274.976333696773 +0 241 274.933105934363 +0 250 274.790628310616 +0 270 274.36972472876 +0 289 274.275563955637 +0 326 274.268484588901 +0 338 274.064933108817 +1 386 274.062269914507 +1 387 274.054281384837 +1 391 274.049026282641 +1 401 273.920837770762 +1 404 273.508720307709 +1 424 273.331822600277 +1 428 273.234004939865 +1 445 272.832477208338 +1 467 272.636358518916 +1 485 272.016936191517 +1 522 271.675223302068 +1 528 271.458245294985 +1 563 271.409843575617 +1 566 271.294040864725 +1 575 271.203751307945 +1 580 270.867285707472 +1 582 270.135910598837 +1 584 268.624704712738 +1 586 264.655640417888 +1 626 264.547329099114 +1 629 264.369411744322 +1 636 259.186132611454 +1 670 259.111109366001 +1 694 258.526885252145 +1 737 258.461782617644 +1 741 258.254128487816 +2 743 257.637827815885 +2 751 257.487467885692 +2 763 256.062079426438 +2 784 255.55667512634 +2 822 255.301356122905 +2 827 255.062123107245 +2 852 254.969793840294 +2 872 254.961280633716 +2 874 254.872629390701 +2 892 254.11730737943 +2 901 252.429482703112 +2 913 247.734161777393 +2 943 246.281383367226 +2 950 244.871940734504 +2 955 243.687522298512 +2 968 240.313783391124 +2 994 225.924186834258 +2 1027 225.375287811551 +2 1030 223.59959141347 +2 1033 214.372939666438 +2 1075 212.392129645385 +2 1079 202.458511181126 +3 1118 201.385729843192 +3 1121 200.414479846749 +3 1122 197.265532908615 +3 1130 196.484237748458 +3 1143 195.363761230687 +3 1150 194.180926892312 +3 1164 186.886694594438 +3 1229 186.775564288857 +3 1235 185.543088875516 +3 1247 184.315879020582 +3 1250 183.591281538454 +3 1251 180.585581615803 +3 1252 176.910717859633 +3 1256 151.835774047001 +3 1288 151.049164181499 +3 1289 143.621877654316 +3 1298 138.52428369358 +3 1300 130.977242901418 +3 1304 100.267474292617 +3 1325 99.71006688112919 +3 1363 94.56656135601661 +3 1379 79.3308117287512 +3 1411 62.8192798819504 +4 1413 57.1236275580665 +4 1433 45.5493739549428 +4 1482 44.5241434513005 +4 1485 42.8758586335358 +4 1494 40.173767108364 +4 1520 35.9160626502317 +4 1541 35.4706065363053 +4 1625 35.3985432229957 +4 1626 34.7705213812039 +4 1648 33.7365638550162 +4 1654 33.2736870837588 +4 1721 33.1821599854517 +4 1756 33.1640101150454 +4 1759 33.1094860838809 +5 1772 33.0242678796706 +5 1817 32.9941537610489 +5 1827 32.993685905707 +5 1860 32.9805924282463 +5 1912 32.9797736631138 +5 1936 32.979572485373 +5 1941 32.9794989828924 +5 1943 32.978674947399 +5 1980 32.9781395291375 +5 1983 32.9779413611568 +5 2001 32.9779413611568 evaluations : 2001 multiple evaluations : 0 -cache hits : 386 -cache search points : 230 -best feasible solution: x=( 5.176711478052312 3.06427162795444 9.47699431007095 ) F(x)=[ 32.7481266130554 ] h=0 f=32.7481266130554 +cache hits : 258 +cache search points : 221 +best feasible solution: x=( 5.167878504178415 3.051154465074881 9.460783454109679 ) F(x)=[ 32.9779413611568 ] h=0 f=32.9779413611568 diff --git a/tools/COOP-MADS/problems/RHEOLOGY/x0.txt b/tools/COOP-MADS/problems/RHEOLOGY/x0.txt index 6597ade3532c5a50bbb32088540316296a7b8cf4..51fdf048b8ac6b09906d589e385475f2ceae18bf 100644 --- a/tools/COOP-MADS/problems/RHEOLOGY/x0.txt +++ b/tools/COOP-MADS/problems/RHEOLOGY/x0.txt @@ -1,3 +1,3 @@ -10 -10 -10 +10 +10 +10 diff --git a/tools/PSD-MADS/Cache_Server.cpp b/tools/PSD-MADS/Cache_Server.cpp index a9568ce381883dfd81370e0f4065a64aafbea7bb..96d4ff9e826984fbc61d93ff03bb776c9be39488 100644 --- a/tools/PSD-MADS/Cache_Server.cpp +++ b/tools/PSD-MADS/Cache_Server.cpp @@ -237,10 +237,11 @@ void Cache_Server::process_ep_signal ( int source ) const { itab[0] = n; itab[1] = m; itab[2] = ( x->is_eval_ok() ) ? 1 : 0; - const int * ell = x->get_mesh_index(); - if ( ell ) { - itab[3] = 1; - itab[4] = *ell; + + if ( x->get_signature() && (x->get_signature()->get_mesh()->get_mesh_indices())[0].is_defined() ) + { + itab[3]=1; + itab[4]=static_cast<int>((x->get_signature()->get_mesh()->get_mesh_indices())[0].value()); } else itab[3] = itab[4] = 0; @@ -540,9 +541,6 @@ void Cache_Server::process_insert_signal ( int source ) { x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); - if ( itab[3] == 1 ) - x->set_mesh_index ( &itab[4] ); - // Eval_Point insertion in cache and multiple_evals detection: const Eval_Point * cache_x = Cache::find ( *x ); if ( cache_x ) { @@ -579,11 +577,12 @@ void Cache_Server::insert ( const NOMAD::Eval_Point & x ) { itab[0] = n; itab[1] = m; itab[2] = ( x.is_eval_ok() ) ? 1 : 0; - const int * ell = x.get_mesh_index(); - if ( ell ) { - itab[3] = 1; - itab[4] = *ell; - } + + if ( x.get_signature() && (x.get_signature()->get_mesh()->get_mesh_indices())[0].is_defined() ) + { + itab[3]=1; + itab[4]=static_cast<int>((x.get_signature()->get_mesh()->get_mesh_indices())[0].value()); + } else itab[3] = itab[4] = 0; @@ -692,9 +691,6 @@ const Eval_Point * Cache_Server::get_and_remove_extern_point ( void ) const { x->set_eval_status ( ( itab[2] == 1 ) ? EVAL_OK : EVAL_FAIL ); - if ( itab[3] == 1 ) - x->set_mesh_index ( &itab[4] ); - // insert the point in local cache: const Eval_Point * cache_x = Cache::find ( *x ); if ( cache_x ) { diff --git a/tools/PSD-MADS/Master_Slaves.cpp b/tools/PSD-MADS/Master_Slaves.cpp index b5229e993f77ce9d5a2db44503dbe2f554d2f5f8..52c5901c64b641f0d230b497955ebd7d58d610cc 100644 --- a/tools/PSD-MADS/Master_Slaves.cpp +++ b/tools/PSD-MADS/Master_Slaves.cpp @@ -19,377 +19,381 @@ char Master_Slaves::OPTI_DATA_SIGNAL = 'D'; /* start the master (process 0) */ /*--------------------------------*/ void Master_Slaves::start ( void ) const { - - if ( _rank != 0 ) - return; - - MPI_Status status; - int source; - char signal; - int n = _p.get_dimension(); - int nb_stops = 0; - int pollster_mesh_index = 0; - bool stop_algo = false; - double * best_feasible = NULL; - - // the first best infeasible point is initialized with x0: - double * best_infeasible = new double [n+2]; - const Point * x0 = (_p.get_x0s())[0]; - for ( int i = 0 ; i < n ; ++i ) - best_infeasible[i] = (*x0)[i].value(); - best_infeasible[n ] = INF; - best_infeasible[n+1] = INF; - - /*-------------*/ - /* main loop */ - /*-------------*/ - while ( nb_stops != _np-2 ) { - - MPI_Recv ( &signal , 1 , MPI_CHAR , MPI_ANY_SOURCE , - Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD , &status ); - source = status.MPI_SOURCE; - - // stop signal: - // ------------ - if ( signal == Master_Slaves::STOP_SIGNAL ) { - if ( _debug ) { - _p.out() << "MASTER: STOP SIGNAL FROM RANK " << source; - if ( source == 1 ) - _p.out() << " (POLLSTER)"; - _p.out() << endl; - } - ++nb_stops; - } - - // optimization data signal: - // ------------------------- - else if ( signal == Master_Slaves::OPTI_DATA_SIGNAL ) { - if ( _debug ) { - _p.out() << "MASTER: receive optimization data request from slave " - << source; - if ( source == 1 ) - _p.out() << " (POLLSTER)"; - _p.out() << endl; - } - - send_optimization_data ( pollster_mesh_index , - stop_algo , - best_feasible , - best_infeasible , - source ); - } - - // optimization result signal: - // --------------------------- - else if ( signal == Master_Slaves::OPTI_RES_SIGNAL ) { - if ( _debug ) { - _p.out() << "MASTER: receive optimization result from slave " - << source; - if ( source == 1 ) - _p.out() << " (POLLSTER)"; - _p.out() << endl; - } - - // pollster: - if ( source == 1 ) - receive_optimization_result ( pollster_mesh_index , - stop_algo , - best_feasible , - best_infeasible , - source ); - - // other slaves: - else { - int tmp1; - bool tmp2; - receive_optimization_result ( tmp1 , - tmp2 , - best_feasible , - best_infeasible , - source ); - } + if ( _rank != 0 ) + return; + + MPI_Status status; + int source; + char signal; + int n = _p.get_dimension(); + int nb_stops = 0; + int pollster_mesh_index = 0; + bool stop_algo = false; + double * best_feasible = NULL; + + // the first best infeasible point is initialized with x0: + double * best_infeasible = new double [n+2]; + const Point * x0 = (_p.get_x0s())[0]; + for ( int i = 0 ; i < n ; ++i ) + best_infeasible[i] = (*x0)[i].value(); + best_infeasible[n ] = INF; + best_infeasible[n+1] = INF; + + /*-------------*/ + /* main loop */ + /*-------------*/ + while ( nb_stops != _np-2 ) { + + MPI_Recv ( &signal , 1 , MPI_CHAR , MPI_ANY_SOURCE , + Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD , &status ); + + source = status.MPI_SOURCE; + + // stop signal: + // ------------ + if ( signal == Master_Slaves::STOP_SIGNAL ) { + if ( _debug ) { + _p.out() << "MASTER: STOP SIGNAL FROM RANK " << source; + if ( source == 1 ) + _p.out() << " (POLLSTER)"; + _p.out() << endl; + } + ++nb_stops; + } + + // optimization data signal: + // ------------------------- + else if ( signal == Master_Slaves::OPTI_DATA_SIGNAL ) { + if ( _debug ) { + _p.out() << "MASTER: receive optimization data request from slave " + << source; + if ( source == 1 ) + _p.out() << " (POLLSTER)"; + _p.out() << endl; + } + + send_optimization_data ( pollster_mesh_index , + stop_algo , + best_feasible , + best_infeasible , + source ); + } + + // optimization result signal: + // --------------------------- + else if ( signal == Master_Slaves::OPTI_RES_SIGNAL ) { + if ( _debug ) { + _p.out() << "MASTER: receive optimization result from slave " + << source; + if ( source == 1 ) + _p.out() << " (POLLSTER)"; + _p.out() << endl; + } + + // pollster: + if ( source == 1 ) + receive_optimization_result ( pollster_mesh_index , + stop_algo , + best_feasible , + best_infeasible , + source ); + + // other slaves: + else { + int tmp1; + bool tmp2; + receive_optimization_result ( tmp1 , + tmp2 , + best_feasible , + best_infeasible , + source ); + } + } } - } - - if ( best_feasible ) - delete [] best_feasible; - if ( best_infeasible ) - delete [] best_infeasible; + + if ( best_feasible ) + delete [] best_feasible; + if ( best_infeasible ) + delete [] best_infeasible; } /*------------------------------------------*/ /* stop the master (processes 1 to _np-2) */ /*------------------------------------------*/ - void Master_Slaves::stop ( void ) const { - if ( _rank == 0 || _rank == _np-1 ) - return; - - MPI_Send ( &Master_Slaves::STOP_SIGNAL , 1 , MPI_CHAR , - 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); +void Master_Slaves::stop ( void ) const { + if ( _rank == 0 || _rank == _np-1 ) + return; + + MPI_Send ( &Master_Slaves::STOP_SIGNAL , 1 , MPI_CHAR , + 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); } /*----------------------------------------*/ /* MADS run */ /*----------------------------------------*/ void Master_Slaves::mads_run ( Cache & cache ) { - - const Eval_Point * best_feasible = NULL; - const Eval_Point * best_infeasible = NULL; - Double old_f = INF; - bool stop_algo = false; - int run_index = 0; - int mesh_index = 0; - double default_eps = Double::get_epsilon(); - int n = _p.get_dimension(); - int * free_vars = new int [_ns]; - Point x0 ( n ) , delta_0 , delta_min; - - /*---------------------*/ - /* main loop */ - /*---------------------*/ - while ( !stop_algo ) { - best_feasible = NULL; - best_infeasible = NULL; - - // random SEED: - _p.set_SEED ( get_pid() + run_index ); - - // Halton seed: - _p.set_HALTON_SEED ( 7999 + 99 * _rank + 20 * run_index ); + const Eval_Point * best_feasible = NULL; + const Eval_Point * best_infeasible = NULL; + Double old_f = INF; + bool stop_algo = false; + int run_index = 0; + int mesh_index = 0; + double default_eps = Double::get_epsilon(); + int n = _p.get_dimension(); + int * free_vars = new int [_ns]; + Point x0 ( n ) , delta_0 , delta_min; - // first run: - if ( run_index == 0 ) { - - // max number of evaluations for regular slaves: - if ( _rank != 1 ) - _p.set_MAX_BB_EVAL ( _bbe ); - - // display: - // p.set_DISPLAY_STATS ( "process #" + itos(_rank) + " BBE OBJ" ); - // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); - _p.set_DISPLAY_DEGREE ( NO_DISPLAY ); - } - - // force the parameters check: - _p.force_check_flag(); - - /*------------------*/ - /* pollster slave */ - /*------------------*/ - if ( _rank == 1 ) { - - stop_type stop_reason = UNKNOWN_STOP_REASON; - - Mesh::get_delta_m ( delta_0 , - _initial_mesh_size , - _mesh_update_basis , - _initial_mesh_index , - mesh_index ); - - // we set a very small epsilon in order to accept - // very small initial mesh sizes: - Double::set_epsilon ( 1e-16 ); - - if ( !check_delta ( delta_0 ) ) - stop_algo = true; - - else { - - // first run: - if ( run_index == 0 ) { - - // directions: - { - int halton_seed = _p.get_halton_seed(); - bool use_orthomads = _p.has_orthomads_directions(); - _p.reset_directions ( halton_seed ); - _p.set_DIRECTION_TYPE ( (use_orthomads) ? ORTHO_1 : LT_1 ); - } - - // cache search: - _p.set_CACHE_SEARCH ( true ); - _p.set_OPPORTUNISTIC_CACHE_SEARCH ( false ); - } - - // other runs: - else { - - // stop_algo may be set to 'false' here: - receive_optimization_data ( stop_algo , x0 , old_f ); - - // starting point: - _p.reset_X0(); - _p.set_X0 ( x0 ); - } - - if ( !stop_algo ) { - - // pollster mesh: - _p.set_INITIAL_MESH_INDEX ( mesh_index ); - _p.set_MAX_MESH_INDEX ( mesh_index ); - _p.set_INITIAL_MESH_SIZE ( delta_0 ); - _p.set_MIN_MESH_SIZE ( delta_0 ); - - // check the parameters: - _p.check(); - Double::set_epsilon ( default_eps ); - - Mads mads ( _p , NULL , NULL , &cache , NULL ); - stop_reason = mads.run(); - best_feasible = mads.get_best_feasible(); - best_infeasible = mads.get_best_infeasible(); - - bool success = false; - - if ( best_feasible ) { - - success = (best_feasible->get_f() < old_f); - - if ( _debug ) - _p.out() << "POLLSTER: ELL=" - << mesh_index << " BBE=" - << mads.get_stats().get_bb_eval() - << " OLD_F=" << old_f << " NEW_F=" - << best_feasible->get_f() - << " SUCCESS=" << success << endl; - } - - // pollster mesh update: - if ( success ) - --mesh_index; - else - ++mesh_index; - } - } - - send_optimization_result ( mesh_index , - stop_algo , - best_feasible , - best_infeasible , - stop_reason ); + /*---------------------*/ + /* main loop */ + /*---------------------*/ + while ( !stop_algo ) { + + best_feasible = NULL; + best_infeasible = NULL; + + // Seed: + _p.set_SEED ( 99 * _rank + 20 * run_index ); + + // first run: + if ( run_index == 0 ) { + + // max number of evaluations for regular slaves: + if ( _rank != 1 ) + _p.set_MAX_BB_EVAL ( _bbe ); + + // display: + // p.set_DISPLAY_STATS ( "process #" + itos(_rank) + " BBE OBJ" ); + // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); + _p.set_DISPLAY_DEGREE ( NO_DISPLAY ); + } + + // force the parameters check: + _p.force_check_flag(); + + /*------------------*/ + /* pollster slave */ + /*------------------*/ + if ( _rank == 1 ) { + + stop_type stop_reason = UNKNOWN_STOP_REASON; + + _p.check(); // must do check to get a valid signature + _p.get_signature()->get_mesh()->set_mesh_indices( NOMAD::Point( n,mesh_index ) ); + delta_0=_p.get_signature()->get_mesh()->get_delta ( ); + + + + // we set a very small epsilon in order to accept + // very small initial mesh sizes: + Double::set_epsilon ( 1e-16 ); + + if ( !check_delta ( delta_0 ) ) + stop_algo = true; + + else { + + // first run: + if ( run_index == 0 ) { + + // directions: + { + bool use_orthomads = _p.has_orthomads_directions(); + _p.reset_directions ( ); + _p.set_DIRECTION_TYPE ( (use_orthomads) ? ORTHO_1 : LT_1 ); + } + + // cache search: + _p.set_CACHE_SEARCH ( true ); + _p.set_OPPORTUNISTIC_CACHE_SEARCH ( false ); + } + + // other runs: + else { + + // stop_algo may be set to 'false' here: + receive_optimization_data ( stop_algo , x0 , old_f ); + + // starting point: + _p.reset_X0(); + _p.set_X0 ( x0 ); + } + + if ( !stop_algo ) { + + // check the parameters: + _p.check(); + + _p.get_signature()->get_mesh()->set_min_mesh_sizes( delta_0 ); + + if ( mesh_index <= 0 ) + _p.get_signature()->get_mesh()->set_limit_mesh_index ( mesh_index ); + else + _p.get_signature()->get_mesh()->set_limit_mesh_index ( 0 ); + + Double::set_epsilon ( default_eps ); + + Mads mads ( _p , NULL , NULL , &cache , NULL ); + stop_reason = mads.run(); + best_feasible = mads.get_best_feasible(); + best_infeasible = mads.get_best_infeasible(); + + bool success = false; + + if ( best_feasible ) { + + success = (best_feasible->get_f() < old_f); + + if ( _debug ) + _p.out() << "POLLSTER: ELL=" + << mesh_index << " BBE=" + << mads.get_stats().get_bb_eval() + << " OLD_F=" << old_f << " NEW_F=" + << best_feasible->get_f() + << " SUCCESS=" << success << endl; + } + + // pollster mesh update: + if ( success ) + ++mesh_index; + else + --mesh_index; + + } + } + + send_optimization_result ( mesh_index , + stop_algo , + best_feasible , + best_infeasible , + stop_reason ); + } + + /*------------------*/ + /* regular slaves */ + /*------------------*/ + else { + + int i , j , pollster_mesh_index; + + receive_optimization_data ( stop_algo , + x0 , + old_f , + pollster_mesh_index , + free_vars ); + + if ( _debug ) { + _p.out() << "SLAVE #" << _rank + << ": OPTIM. DATA: [STOP=" << stop_algo + << "] [POLLSTER_MESH_INDEX=" << pollster_mesh_index + << "] [X0=" << x0 << " ] [f(X0)=" + << old_f << "] [FREE VARS= "; + for ( i = 0 ; i < _ns ; ++i ) + _p.out() << free_vars[i] << " "; + _p.out() << " ]" << endl; + } + + if ( !stop_algo ) { + + // starting point: + _p.reset_X0(); + _p.set_X0 ( x0 ); + + // mesh of the regular slave: + int ell_0 = 0; + if ( pollster_mesh_index > ell_0 ) + ell_0 = pollster_mesh_index; + + _p.check(); // Must do check to access signature + _p.get_signature()->get_mesh()->set_mesh_indices( NOMAD::Point( n,ell_0 ) ); + delta_0=_p.get_signature()->get_mesh()->get_delta(); + + _p.get_signature()->get_mesh()->set_mesh_indices( NOMAD::Point( n ,pollster_mesh_index ) ); + delta_min=_p.get_signature()->get_mesh()->get_delta(); + + + + Double::set_epsilon ( 1e-16 ); + if ( !check_delta ( delta_0 ) || !check_delta ( delta_min ) ) + stop_algo = true; + + else { + + + + // free variables: + { + _p.reset_fixed_variables(); + bool fix_var; + for ( i = 0 ; i < n ; ++i ) { + fix_var = true; + for ( j = 0 ; j < _ns ; ++j ) + if ( free_vars[j] == i ) { + fix_var = false; + break; + } + if ( fix_var ) + _p.set_FIXED_VARIABLE ( i ); + } + } + + // check the parameters: + _p.check(); + + // modify mesh termination criterions + _p.get_signature()->get_mesh()->set_mesh_indices( NOMAD::Point( n,ell_0 ) ); + + if ( pollster_mesh_index <=0 ) + _p.get_signature()->get_mesh()->set_limit_mesh_index( pollster_mesh_index ); + else + _p.get_signature()->get_mesh()->set_limit_mesh_index( 0 ); + + _p.get_signature()->get_mesh()->set_min_mesh_sizes( delta_min ); + _p.get_signature()->get_mesh()->set_delta_0 ( delta_0 ); + + + + Double::set_epsilon ( default_eps ); + + // MADS run: + Mads mads ( _p , NULL , NULL , &cache , NULL ); + mads.run(); + best_feasible = mads.get_best_feasible(); + best_infeasible = mads.get_best_infeasible(); + + if ( _debug && best_feasible ) { + _p.out() << "RANK #" << _rank << ": POLLSTER_ELL=" + << pollster_mesh_index << " VARS = ["; + for ( i = 0 ; i < _ns ; ++i ) + _p.out() << free_vars[i] << " "; + _p.out() << " ] BBE=" << mads.get_stats().get_bb_eval() + << " OLD_F=" << old_f << " NEW_F=" + << best_feasible->get_f() + << " SUCCESS=" + << (best_feasible->get_f() < old_f) + << endl; + } + } + } + + { + int tmp1 = -1; + bool tmp2 = false; + stop_type tmp3 = UNKNOWN_STOP_REASON; + send_optimization_result ( tmp1 , + tmp2 , + best_feasible , + best_infeasible , + tmp3 ); + } + } + + // loop increment: + ++run_index; } - /*------------------*/ - /* regular slaves */ - /*------------------*/ - else { - - int i , j , pollster_mesh_index; - - receive_optimization_data ( stop_algo , - x0 , - old_f , - pollster_mesh_index , - free_vars ); - - if ( _debug ) { - _p.out() << "SLAVE #" << _rank - << ": OPTIM. DATA: [STOP=" << stop_algo - << "] [POLLSTER_MESH_INDEX=" << pollster_mesh_index - << "] [X0=" << x0 << " ] [f(X0)=" - << old_f << "] [FREE VARS= "; - for ( i = 0 ; i < _ns ; ++i ) - _p.out() << free_vars[i] << " "; - _p.out() << " ]" << endl; - } - - if ( !stop_algo ) { - - // starting point: - _p.reset_X0(); - _p.set_X0 ( x0 ); - - // mesh of the regular slave: - int ell_0 = 0; - if ( pollster_mesh_index < ell_0 ) - ell_0 = pollster_mesh_index; - - - Mesh::get_delta_m ( delta_0 , - _initial_mesh_size , - _mesh_update_basis , - _initial_mesh_index , - ell_0 ); - - Mesh::get_delta_m ( delta_min , - _initial_mesh_size , - _mesh_update_basis , - _initial_mesh_index , - pollster_mesh_index ); - - - Double::set_epsilon ( 1e-16 ); - if ( !check_delta ( delta_0 ) || !check_delta ( delta_min ) ) - stop_algo = true; - - else { - - // mesh of the regular slave: - _p.set_INITIAL_MESH_INDEX ( ell_0 ); - _p.set_MAX_MESH_INDEX ( pollster_mesh_index ); - _p.set_INITIAL_MESH_SIZE ( delta_0 ); - _p.set_MIN_MESH_SIZE ( delta_min ); - - // free variables: - { - _p.reset_fixed_variables(); - bool fix_var; - for ( i = 0 ; i < n ; ++i ) { - fix_var = true; - for ( j = 0 ; j < _ns ; ++j ) - if ( free_vars[j] == i ) { - fix_var = false; - break; - } - if ( fix_var ) - _p.set_FIXED_VARIABLE ( i ); - } - } - - // check the parameters: - _p.check(); - Double::set_epsilon ( default_eps ); - - // MADS run: - Mads mads ( _p , NULL , NULL , &cache , NULL ); - mads.run(); - best_feasible = mads.get_best_feasible(); - best_infeasible = mads.get_best_infeasible(); - - if ( _debug && best_feasible ) { - _p.out() << "RANK #" << _rank << ": POLLSTER_ELL=" - << pollster_mesh_index << " VARS = ["; - for ( i = 0 ; i < _ns ; ++i ) - _p.out() << free_vars[i] << " "; - _p.out() << " ] BBE=" << mads.get_stats().get_bb_eval() - << " OLD_F=" << old_f << " NEW_F=" - << best_feasible->get_f() - << " SUCCESS=" - << (best_feasible->get_f() < old_f) - << endl; - } - } - } - - { - int tmp1 = -1; - bool tmp2 = false; - stop_type tmp3 = UNKNOWN_STOP_REASON; - send_optimization_result ( tmp1 , - tmp2 , - best_feasible , - best_infeasible , - tmp3 ); - } - } - - // loop increment: - ++run_index; - } - - delete [] free_vars; + delete [] free_vars; } /*----------------------------------------------------*/ @@ -397,155 +401,155 @@ void Master_Slaves::mads_run ( Cache & cache ) { /* POLLSTER --> MASTER */ /*----------------------------------------------------*/ void Master_Slaves::receive_optimization_result - ( int & pollster_mesh_index , - bool & stop_algo , - double *& best_feasible , - double *& best_infeasible , - int source ) const { - - int itab[5]; - MPI_Status status; - - MPI_Recv ( itab , 5 , MPI_INT , source , - Master_Slaves::TAG_I1 , MPI_COMM_WORLD , &status ); - - pollster_mesh_index = itab[0]; - - // stop the algorithm ? - stop_algo = ( itab[4] == 1 ); - - if ( !stop_algo ) { - - stop_type stop_reason = static_cast<stop_type>(itab[1]); - - switch ( stop_reason ) { - case ERROR: - case UNKNOWN_STOP_REASON: - case CTRL_C: - case MESH_PREC_REACHED: - case X0_FAIL: - case P1_FAIL: - case L_MAX_REACHED: - case L_LIMITS_REACHED: - case MAX_TIME_REACHED: - case MAX_BB_EVAL_REACHED: - case MAX_SGTE_EVAL_REACHED: - case MAX_EVAL_REACHED: - case MAX_SIM_BB_EVAL_REACHED: - case MAX_ITER_REACHED: - case FEAS_REACHED: - case F_TARGET_REACHED: - case STAT_SUM_TARGET_REACHED: - case L_CURVE_TARGET_REACHED: - case MULTI_MAX_BB_REACHED: - case MULTI_NB_MADS_RUNS_REACHED: - case MULTI_STAGNATION: - case MULTI_NO_PARETO_PTS: - case MAX_CACHE_MEMORY_REACHED: - stop_algo = true; - default: - stop_algo = false; - } - } - - int i , nb_pts = 0; - if ( itab[2] == 1 ) - ++nb_pts; - if ( itab[3] == 1 ) - ++nb_pts; - - // itab[2] == 1 --> bf != NULL - // itab[3] == 1 --> bi != NULL - - if ( nb_pts > 0 ) { - - int n = _p.get_dimension(); - double * rtab = new double [(n+2)*nb_pts]; - - MPI_Recv ( rtab , (n+2)*nb_pts , MPI_DOUBLE , source , - Master_Slaves::TAG_R1 , MPI_COMM_WORLD , &status ); - - if ( nb_pts == 2 ) { - - // best feasible and infeasible updates: - bool update = false; - - if ( best_feasible ) { - Double old_f = best_feasible[n+1]; - Double new_f = rtab [n+1]; - if ( new_f < old_f ) - update = true; - } - else { - best_feasible = new double[n+2]; - update = true; - } - - if ( update ) { - for ( i = 0 ; i < n ; ++i ) - best_feasible[i] = rtab[i]; - best_feasible[n ] = rtab[n]; - best_feasible[n+1] = rtab[n+1]; - } - - update = false; - - if ( best_infeasible ) { - - Double old_h = best_infeasible[n]; - Double new_h = rtab [2*n+2]; - if ( new_h < old_h ) - update = true; - } - else { - best_infeasible = new double[n+2]; - update = true; - } - - if ( update ) { - int cur = n+2; - for ( i = 0 ; i < n ; ++i ) - best_infeasible[i] = rtab[cur++]; - best_infeasible[n ] = rtab[cur++]; - best_infeasible[n+1] = rtab[cur]; - } - delete [] rtab; +( int & pollster_mesh_index , + bool & stop_algo , + double *& best_feasible , + double *& best_infeasible , + int source ) const { + + int itab[5]; + MPI_Status status; + + MPI_Recv ( itab , 5 , MPI_INT , source , + Master_Slaves::TAG_I1 , MPI_COMM_WORLD , &status ); + + pollster_mesh_index = itab[0]; + + // stop the algorithm ? + stop_algo = ( itab[4] == 1 ); + + if ( !stop_algo ) { + + stop_type stop_reason = static_cast<stop_type>(itab[1]); + + switch ( stop_reason ) { + case ERROR: + case UNKNOWN_STOP_REASON: + case CTRL_C: + case MESH_PREC_REACHED: + case X0_FAIL: + case P1_FAIL: + case L_MAX_REACHED: + case L_LIMITS_REACHED: + case MAX_TIME_REACHED: + case MAX_BB_EVAL_REACHED: + case MAX_SGTE_EVAL_REACHED: + case MAX_EVAL_REACHED: + case MAX_SIM_BB_EVAL_REACHED: + case MAX_ITER_REACHED: + case FEAS_REACHED: + case F_TARGET_REACHED: + case STAT_SUM_TARGET_REACHED: + case L_CURVE_TARGET_REACHED: + case MULTI_MAX_BB_REACHED: + case MULTI_NB_MADS_RUNS_REACHED: + case MULTI_STAGNATION: + case MULTI_NO_PARETO_PTS: + case MAX_CACHE_MEMORY_REACHED: + stop_algo = true; + default: + stop_algo = false; + } } - else { - - // best feasible update: - if ( itab[2] == 1 ) { - if ( best_feasible ) { - Double old_f = best_feasible[n+1]; - Double new_f = rtab [n+1]; - if ( new_f < old_f ) { - delete [] best_feasible; - best_feasible = rtab; - } - else - delete [] rtab; - } - else - best_feasible = rtab; - } - - // best infeasible update: - else { - if ( best_infeasible ) { - Double old_h = best_infeasible[n]; - Double new_h = rtab [n]; - if ( new_h < old_h ) { - delete [] best_infeasible; - best_infeasible = rtab; - } - else - delete [] rtab; - } - else - best_infeasible = rtab; - } + + int i , nb_pts = 0; + if ( itab[2] == 1 ) + ++nb_pts; + if ( itab[3] == 1 ) + ++nb_pts; + + // itab[2] == 1 --> bf != NULL + // itab[3] == 1 --> bi != NULL + + if ( nb_pts > 0 ) { + + int n = _p.get_dimension(); + double * rtab = new double [(n+2)*nb_pts]; + + MPI_Recv ( rtab , (n+2)*nb_pts , MPI_DOUBLE , source , + Master_Slaves::TAG_R1 , MPI_COMM_WORLD , &status ); + + if ( nb_pts == 2 ) { + + // best feasible and infeasible updates: + bool update = false; + + if ( best_feasible ) { + Double old_f = best_feasible[n+1]; + Double new_f = rtab [n+1]; + if ( new_f < old_f ) + update = true; + } + else { + best_feasible = new double[n+2]; + update = true; + } + + if ( update ) { + for ( i = 0 ; i < n ; ++i ) + best_feasible[i] = rtab[i]; + best_feasible[n ] = rtab[n]; + best_feasible[n+1] = rtab[n+1]; + } + + update = false; + + if ( best_infeasible ) { + + Double old_h = best_infeasible[n]; + Double new_h = rtab [2*n+2]; + if ( new_h < old_h ) + update = true; + } + else { + best_infeasible = new double[n+2]; + update = true; + } + + if ( update ) { + int cur = n+2; + for ( i = 0 ; i < n ; ++i ) + best_infeasible[i] = rtab[cur++]; + best_infeasible[n ] = rtab[cur++]; + best_infeasible[n+1] = rtab[cur]; + } + delete [] rtab; + } + else { + + // best feasible update: + if ( itab[2] == 1 ) { + if ( best_feasible ) { + Double old_f = best_feasible[n+1]; + Double new_f = rtab [n+1]; + if ( new_f < old_f ) { + delete [] best_feasible; + best_feasible = rtab; + } + else + delete [] rtab; + } + else + best_feasible = rtab; + } + + // best infeasible update: + else { + if ( best_infeasible ) { + Double old_h = best_infeasible[n]; + Double new_h = rtab [n]; + if ( new_h < old_h ) { + delete [] best_infeasible; + best_infeasible = rtab; + } + else + delete [] rtab; + } + else + best_infeasible = rtab; + } + } } - } } /*---------------------------------------------*/ @@ -553,67 +557,67 @@ void Master_Slaves::receive_optimization_result /* POLLSTER --> MASTER */ /*---------------------------------------------*/ void Master_Slaves::send_optimization_result - ( int pollster_mesh_index , - bool stop_algo , - const Eval_Point * bf , - const Eval_Point * bi , - stop_type st ) const { - - // send a signal to the master: - MPI_Send ( &Master_Slaves::OPTI_RES_SIGNAL , 1 , MPI_CHAR , - 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); - - // send the data: - int itab[5]; - - itab[0] = pollster_mesh_index; - itab[1] = static_cast<int>(st); - - int nb_pts = 0; - if ( bf ) { - ++nb_pts; - itab[2] = 1; - } - else - itab[2] = 0; - - if ( bi ) { - ++nb_pts; - itab[3] = 1; - } - else - itab[3] = 0; - - itab[4] = (stop_algo) ? 1 : 0; - - MPI_Send ( itab , 5 , MPI_INT , 0 , - Master_Slaves::TAG_I1 , MPI_COMM_WORLD ); - - if ( nb_pts > 0 ) { - - int n = _p.get_dimension(); - double * rtab = new double [(n+2)*nb_pts]; - - int i , cur = 0; +( int pollster_mesh_index , + bool stop_algo , + const Eval_Point * bf , + const Eval_Point * bi , + stop_type st ) const { + + // send a signal to the master: + MPI_Send ( &Master_Slaves::OPTI_RES_SIGNAL , 1 , MPI_CHAR , + 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); + + // send the data: + int itab[5]; + + itab[0] = pollster_mesh_index; + itab[1] = static_cast<int>(st); + + int nb_pts = 0; if ( bf ) { - for ( i = 0 ; i < n ; ++i ) - rtab[cur++] = (*bf)[i].value(); - rtab[cur++] = bf->get_h().value(); - rtab[cur++] = bf->get_f().value(); + ++nb_pts; + itab[2] = 1; } - + else + itab[2] = 0; + if ( bi ) { - for ( i = 0 ; i < n ; ++i ) - rtab[cur++] = (*bi)[i].value(); - rtab[cur++] = bi->get_h().value(); - rtab[cur ] = bi->get_f().value(); + ++nb_pts; + itab[3] = 1; + } + else + itab[3] = 0; + + itab[4] = (stop_algo) ? 1 : 0; + + MPI_Send ( itab , 5 , MPI_INT , 0 , + Master_Slaves::TAG_I1 , MPI_COMM_WORLD ); + + if ( nb_pts > 0 ) { + + int n = _p.get_dimension(); + double * rtab = new double [(n+2)*nb_pts]; + + int i , cur = 0; + if ( bf ) { + for ( i = 0 ; i < n ; ++i ) + rtab[cur++] = (*bf)[i].value(); + rtab[cur++] = bf->get_h().value(); + rtab[cur++] = bf->get_f().value(); + } + + if ( bi ) { + for ( i = 0 ; i < n ; ++i ) + rtab[cur++] = (*bi)[i].value(); + rtab[cur++] = bi->get_h().value(); + rtab[cur ] = bi->get_f().value(); + } + + MPI_Send ( rtab , cur , MPI_DOUBLE , 0 , + Master_Slaves::TAG_R1 , MPI_COMM_WORLD ); + + delete [] rtab; } - - MPI_Send ( rtab , cur , MPI_DOUBLE , 0 , - Master_Slaves::TAG_R1 , MPI_COMM_WORLD ); - - delete [] rtab; - } } /*---------------------------------------------*/ @@ -622,37 +626,37 @@ void Master_Slaves::send_optimization_result /*---------------------------------------------*/ void Master_Slaves::receive_optimization_data ( bool & stop_algo , - Point & x0 , - Double & fx0 , - int & pollster_mesh_index , - int * free_vars ) const { - - // step 1/2: receive common pollster data: - receive_optimization_data ( stop_algo , x0 , fx0 ); - - int i; - - // step 2/2: receive additional data for regular slaves: - if ( !stop_algo ) { - - int * itab = new int [_ns+1]; - MPI_Status status; - - MPI_Recv ( itab , _ns+1 , MPI_INT , 0 , - Master_Slaves::TAG_I2 , MPI_COMM_WORLD , &status ); - - for ( i = 0 ; i < _ns ; ++i ) - free_vars[i] = itab[i]; - - pollster_mesh_index = itab[_ns]; - - delete [] itab; - } - else { - pollster_mesh_index = -1; - for ( i = 0 ; i < _ns ; ++i ) - free_vars[i] = -1; - } + Point & x0 , + Double & fx0 , + int & pollster_mesh_index , + int * free_vars ) const { + + // step 1/2: receive common pollster data: + receive_optimization_data ( stop_algo , x0 , fx0 ); + + int i; + + // step 2/2: receive additional data for regular slaves: + if ( !stop_algo ) { + + int * itab = new int [_ns+1]; + MPI_Status status; + + MPI_Recv ( itab , _ns+1 , MPI_INT , 0 , + Master_Slaves::TAG_I2 , MPI_COMM_WORLD , &status ); + + for ( i = 0 ; i < _ns ; ++i ) + free_vars[i] = itab[i]; + + pollster_mesh_index = itab[_ns]; + + delete [] itab; + } + else { + pollster_mesh_index = 1; + for ( i = 0 ; i < _ns ; ++i ) + free_vars[i] = -1; + } } /*---------------------------------------------*/ @@ -660,82 +664,82 @@ void Master_Slaves::receive_optimization_data /* MASTER --> POLLSTER */ /*---------------------------------------------*/ void Master_Slaves::receive_optimization_data ( bool & stop_algo , - Point & x0 , - Double & fx0 ) const { - char c_stop; - MPI_Status status; - MPI_Request req = MPI_REQUEST_NULL; - int i , n = _p.get_dimension(); - - // send a request for c_stop: - MPI_Irecv ( &c_stop , 1 , MPI_CHAR , 0 , - Master_Slaves::TAG_CSTOP , MPI_COMM_WORLD , &req ); - - // send a signal to the master: - MPI_Send ( &Master_Slaves::OPTI_DATA_SIGNAL , 1 , MPI_CHAR , - 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); - - MPI_Wait ( &req , &status ); - - // stop: - if ( c_stop == '1' ) { - stop_algo = true; - x0.reset(); - } - - // continue: - else { - - stop_algo = false; - double * rtab = new double [n+2]; + Point & x0 , + Double & fx0 ) const { + char c_stop; + MPI_Status status; + MPI_Request req = MPI_REQUEST_NULL; + int i , n = _p.get_dimension(); - MPI_Recv ( rtab , n+2 , MPI_DOUBLE , 0 , - Master_Slaves::TAG_D1 , MPI_COMM_WORLD , &status ); - - for ( i = 0 ; i < n ; ++i ) - x0[i] = rtab[i]; + // send a request for c_stop: + MPI_Irecv ( &c_stop , 1 , MPI_CHAR , 0 , + Master_Slaves::TAG_CSTOP , MPI_COMM_WORLD , &req ); - Double h = rtab[n]; - fx0 = ( h <= _p.get_h_min() ) ? rtab[n+1] : INF; - - // get the best feasible point from the cache server: - { - char pt_flag; - int npm1 = _np-1; - MPI_Irecv ( &pt_flag , 1 , MPI_CHAR , npm1 , - Cache_Server::TAG_BF , MPI_COMM_WORLD , &req ); - - MPI_Send ( &Cache_Server::BF_SIGNAL , 1 , MPI_CHAR , - npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); - - MPI_Wait ( &req , &status ); - - if ( pt_flag == '1' ) { - - MPI_Recv ( rtab , n+2 , MPI_DOUBLE , npm1 , - Cache_Server::TAG_X7 , MPI_COMM_WORLD , &status ); - - for ( i = 0 ; i < n ; ++i ) - x0[i] = rtab[i]; - - Double h = rtab[n]; - fx0 = ( h <= _p.get_h_min() ) ? rtab[n+1] : INF; - - } + // send a signal to the master: + MPI_Send ( &Master_Slaves::OPTI_DATA_SIGNAL , 1 , MPI_CHAR , + 0 , Master_Slaves::TAG_SIGNAL , MPI_COMM_WORLD ); + + MPI_Wait ( &req , &status ); + + // stop: + if ( c_stop == '1' ) { + stop_algo = true; + x0.reset(); } - delete [] rtab; - - // check the bounds: - const Point & lb = _p.get_lb(); - const Point & ub = _p.get_ub(); - - for ( i = 0 ; i < n ; ++i ) { - if ( lb[i].is_defined() && x0[i].value() < lb[i].value() ) - x0[i] = lb[i]; - if ( ub[i].is_defined() && x0[i].value() > ub[i].value() ) - x0[i] = ub[i]; + + // continue: + else { + + stop_algo = false; + double * rtab = new double [n+2]; + + MPI_Recv ( rtab , n+2 , MPI_DOUBLE , 0 , + Master_Slaves::TAG_D1 , MPI_COMM_WORLD , &status ); + + for ( i = 0 ; i < n ; ++i ) + x0[i] = rtab[i]; + + Double h = rtab[n]; + fx0 = ( h <= _p.get_h_min() ) ? rtab[n+1] : INF; + + // get the best feasible point from the cache server: + { + char pt_flag; + int npm1 = _np-1; + MPI_Irecv ( &pt_flag , 1 , MPI_CHAR , npm1 , + Cache_Server::TAG_BF , MPI_COMM_WORLD , &req ); + + MPI_Send ( &Cache_Server::BF_SIGNAL , 1 , MPI_CHAR , + npm1 , Cache_Server::TAG_SIGNAL , MPI_COMM_WORLD ); + + MPI_Wait ( &req , &status ); + + if ( pt_flag == '1' ) { + + MPI_Recv ( rtab , n+2 , MPI_DOUBLE , npm1 , + Cache_Server::TAG_X7 , MPI_COMM_WORLD , &status ); + + for ( i = 0 ; i < n ; ++i ) + x0[i] = rtab[i]; + + Double h = rtab[n]; + fx0 = ( h <= _p.get_h_min() ) ? rtab[n+1] : INF; + + } + } + delete [] rtab; + + // check the bounds: + const Point & lb = _p.get_lb(); + const Point & ub = _p.get_ub(); + + for ( i = 0 ; i < n ; ++i ) { + if ( lb[i].is_defined() && x0[i].value() < lb[i].value() ) + x0[i] = lb[i]; + if ( ub[i].is_defined() && x0[i].value() > ub[i].value() ) + x0[i] = ub[i]; + } } - } } /*-----------------------------------------------------*/ @@ -744,61 +748,61 @@ void Master_Slaves::receive_optimization_data ( bool & stop_algo , /*-----------------------------------------------------*/ void Master_Slaves::send_optimization_data ( int pollster_mesh_index , - bool stop_algo , - const double * best_feasible , - const double * best_infeasible , - int source ) const { - - char c_stop = (stop_algo) ? '1' : '0'; - - MPI_Rsend ( &c_stop , 1 , MPI_CHAR , source , - Master_Slaves::TAG_CSTOP , MPI_COMM_WORLD ); - - // continue: - if ( !stop_algo ) { + bool stop_algo , + const double * best_feasible , + const double * best_infeasible , + int source ) const { - int n = _p.get_dimension(); - - // data for pollster and regular slaves: - if ( best_feasible ) - MPI_Send ( const_cast<double*>(best_feasible) , n+2 , MPI_DOUBLE , - source , Master_Slaves::TAG_D1 , MPI_COMM_WORLD ); - else - MPI_Send ( const_cast<double*>(best_infeasible) , n+2 , MPI_DOUBLE , - source , Master_Slaves::TAG_D1 , MPI_COMM_WORLD ); - - // additional data for regular slaves: - if ( source != 1 ) { - - int * itab = new int [_ns+1]; - - // choose the free varables: - { - Random_Pickup rp ( n ); - - for ( int i = 0 ; i < _ns ; ++i ) - itab[i] = rp.pickup(); // index of the ith free variable - } - - itab[_ns] = pollster_mesh_index; - - MPI_Send ( itab , _ns+1 , MPI_INT , source , - Master_Slaves::TAG_I2 , MPI_COMM_WORLD ); - - delete [] itab; + char c_stop = (stop_algo) ? '1' : '0'; + + MPI_Rsend ( &c_stop , 1 , MPI_CHAR , source , + Master_Slaves::TAG_CSTOP , MPI_COMM_WORLD ); + + // continue: + if ( !stop_algo ) { + + int n = _p.get_dimension(); + + // data for pollster and regular slaves: + if ( best_feasible ) + MPI_Send ( const_cast<double*>(best_feasible) , n+2 , MPI_DOUBLE , + source , Master_Slaves::TAG_D1 , MPI_COMM_WORLD ); + else + MPI_Send ( const_cast<double*>(best_infeasible) , n+2 , MPI_DOUBLE , + source , Master_Slaves::TAG_D1 , MPI_COMM_WORLD ); + + // additional data for regular slaves: + if ( source != 1 ) { + + int * itab = new int [_ns+1]; + + // choose the free varables: + { + Random_Pickup rp ( n ); + + for ( int i = 0 ; i < _ns ; ++i ) + itab[i] = rp.pickup(); // index of the ith free variable + } + + itab[_ns] = pollster_mesh_index; + + MPI_Send ( itab , _ns+1 , MPI_INT , source , + Master_Slaves::TAG_I2 , MPI_COMM_WORLD ); + + delete [] itab; + } } - } } /*-----------------------------------------------*/ /* check the initial mesh size values */ /*-----------------------------------------------*/ bool Master_Slaves::check_delta ( const Point & delta ) { - int n = delta.size(); - for ( int i = 0 ; i < n ; ++i ) - if ( delta[i].value() < Double::get_epsilon() || - delta[i].value() <= 0.0 ) - return false; - return true; + int n = delta.size(); + for ( int i = 0 ; i < n ; ++i ) + if ( delta[i].value() < Double::get_epsilon() || + delta[i].value() <= 0.0 ) + return false; + return true; } - + diff --git a/tools/PSD-MADS/Master_Slaves.hpp b/tools/PSD-MADS/Master_Slaves.hpp index ef298ed4fcfeb6de187873d852f7b1db64af23d2..33eb386b212f33aa3161b668da57cdfddd51e517 100644 --- a/tools/PSD-MADS/Master_Slaves.hpp +++ b/tools/PSD-MADS/Master_Slaves.hpp @@ -20,10 +20,6 @@ private: Parameters & _p; // parameters bool _debug; // debug display flag - Point _initial_mesh_size; // used for mesh sizes computations - double _mesh_update_basis; - int _initial_mesh_index; - static const int TAG_SIGNAL; static const int TAG_I1; static const int TAG_I2; @@ -83,10 +79,7 @@ public: _bbe ( bbe ) , _ns ( ns ) , _p ( p ) , - _debug ( debug ) , - _initial_mesh_size ( p.get_initial_mesh_size() ) , - _mesh_update_basis ( p.get_mesh_update_basis().value() ) , - _initial_mesh_index ( p.get_initial_mesh_index() ) {} + _debug ( debug ) {} // Destructor: virtual ~Master_Slaves ( void ) {} diff --git a/tools/PSD-MADS/main.cpp b/tools/PSD-MADS/main.cpp index 516c8f67f3de0eb01c99d9574a7125e30347c451..5d9122bc8599c4af058fcde376097626c5a926c8 100644 --- a/tools/PSD-MADS/main.cpp +++ b/tools/PSD-MADS/main.cpp @@ -65,6 +65,11 @@ int main ( int argc , char ** argv ) { // read the parameters file: p.read ( argv[1] ); + + + // Force anisotropy(false) to have a single mesh_index (XMesh) + p.set_ANISOTROPIC_MESH ( false ); + // check the parameters: p.check(); diff --git a/tools/PSD-MADS/problems/G2_10/runExample.log b/tools/PSD-MADS/problems/G2_10/runExample.log index d19b8d8086d739a233d0169920be2ce98757366e..77b68db660e5c30ebd7a26f52105769fccedf6ac 100644 --- a/tools/PSD-MADS/problems/G2_10/runExample.log +++ b/tools/PSD-MADS/problems/G2_10/runExample.log @@ -1,107 +1,34 @@ - mpirun -np 4 ../../psdmads.exe param.txt 2 3 TIME BBE OBJ 0 1 -0.001746040966254643 -0 2 -0.02813866582027356 -0 4 -0.03246494243742246 -0 5 -0.03500916329442131 -0 6 -0.03979188572323358 -0 7 -0.04911024464431659 -0 8 -0.0624744264055816 -0 15 -0.07048573066714986 -0 17 -0.07913640207892171 -0 18 -0.2767691552979534 -0 32 -0.2840652234097061 -1 37 -0.3467264619146415 -1 47 -0.3616531939153783 -1 51 -0.3629746044080329 -1 53 -0.3784626616521393 -1 67 -0.4007959643190014 -1 76 -0.4011229010993316 -1 84 -0.4032331127256472 -1 87 -0.403470848334701 -1 90 -0.4037279807054211 -1 95 -0.4041302132836239 -1 100 -0.4048613086583342 -1 107 -0.4053884600639073 -1 120 -0.4069087605072449 -1 131 -0.4072285704612035 -2 151 -0.4077863530293669 -2 152 -0.4086685803184945 -2 158 -0.4130919348061188 -2 170 -0.4137304728713846 -2 172 -0.4148496666566134 -2 176 -0.4191250251192655 -2 182 -0.4200033998088014 -2 205 -0.4208641998228952 -3 206 -0.4225719140558536 -3 215 -0.4228472348980148 -3 217 -0.424356641202593 -3 218 -0.4257196697168721 -3 224 -0.4353114259472481 -3 235 -0.4384297542906666 -3 249 -0.4428448864268232 -3 259 -0.4452338309063813 -3 268 -0.4454447130476139 -3 274 -0.4463397444771921 -3 276 -0.44789418940056 -3 284 -0.4480311333354084 -3 294 -0.4518803988674263 -3 310 -0.4541110520311777 -4 338 -0.4554487138353737 -4 349 -0.4555011463355874 -4 371 -0.4671811067309874 -4 376 -0.4681242182210517 -4 379 -0.4682305982863977 -4 385 -0.470523423605836 -4 397 -0.4736991861621658 -5 407 -0.4795311288186103 -5 408 -0.4831426791267522 -5 422 -0.4858641762962093 -5 424 -0.4879898135606146 -5 432 -0.4887503548786935 -5 433 -0.4890297740218854 -5 437 -0.4940686510588005 -5 441 -0.4994879542195462 -5 453 -0.4996398710974662 -5 467 -0.5120558920079147 -5 486 -0.5156106481361489 -5 494 -0.5184315095785024 -5 496 -0.5226683626664205 -6 509 -0.5280449547858778 -6 512 -0.5383933309117888 -6 523 -0.5429439408280063 -6 533 -0.5543908904333605 -6 537 -0.5632007867272643 -6 541 -0.5671878178220834 -7 583 -0.5761420295747868 -7 604 -0.6084769206498875 -8 610 -0.6113445698633692 -8 639 -0.6144597698235708 -8 645 -0.629444227845865 -8 647 -0.6313958500255352 -8 648 -0.6360620644111428 -8 651 -0.6422846491448985 -8 654 -0.6459778341618972 -8 663 -0.6460135265779767 -8 674 -0.6465276784852958 -8 680 -0.6505834588791414 -8 690 -0.659017324207901 -9 716 -0.6629043685717967 -10 758 -0.6846542316250898 -11 799 -0.6848344023953686 -11 800 -0.6853069561564632 -11 801 -0.6861970681378093 -11 804 -0.6878053210464737 -11 805 -0.6916807972008618 -11 810 -0.6993985430379386 -14 872 -0.7015922046101486 -18 964 -0.7038488494934669 -18 968 -0.7044602723295867 -18 969 -0.7058578026145313 -20 1000 -0.7058578026145313 -evaluations: 1000 -cache hits : 323 -best feasible solution: x=( 3.0462646484375 3.1387939453125 3.0379638671875 2.962646484375 0.6630859375 1.3421630859375 0.35400390625 0.1610107421875 0.398193359375 0.4324951171875 ) F(x)=[ -0.001806557213181849 -59.46337890625 -0.7058578026145313 ] h=0 f=-0.7058578026145313 - +0 2 -0.1020265638285207 +0 6 -0.1441632798005752 +0 15 -0.1542510749518172 +0 22 -0.1577316768630335 +0 37 -0.183989373943974 +0 38 -0.2020008666180557 +0 39 -0.2129271506181529 +0 40 -0.2361644054928127 +1 75 -0.2374148796747058 +1 94 -0.2603035160235741 +1 116 -0.2684048733308141 +2 174 -0.2821001936977113 +3 212 -0.2866228068210581 +4 298 -0.2898075435824587 +4 322 -0.316703796586124 +5 350 -0.338651875099582 +6 412 -0.3480692693344858 +7 506 -0.4056438193796689 +8 550 -0.4404750660164174 +9 598 -0.4453605848005951 +11 758 -0.4502266934808508 +12 780 -0.4606308402126712 +12 794 -0.4678396551609023 +12 804 -0.4864410201396533 +13 836 -0.5028952047514585 +15 961 -0.513267791679749 +29 1001 -0.513267791679749 +evaluations: 1001 +cache hits : 14460 +best feasible solution: x=( 3.125 3.125 3.25 1.5 2.375 0.25 2.625 0.125 0.5 0.875 ) F(x)=[ -3.307846963405609 -57.25 -0.513267791679749 ] h=0 f=-0.513267791679749 diff --git a/tools/SENSITIVITY/detailed_analysis/detailed_analysis.cpp b/tools/SENSITIVITY/detailed_analysis/detailed_analysis.cpp index c2d03c76f1bb6021969f3b41fc050459cccf5ca2..b8db6f5aed07b6a7a9586347f493cc3d18f54301 100644 --- a/tools/SENSITIVITY/detailed_analysis/detailed_analysis.cpp +++ b/tools/SENSITIVITY/detailed_analysis/detailed_analysis.cpp @@ -332,7 +332,6 @@ void create_new_parameters ( const NOMAD::Parameters & p0 , p.set_ADD_SEED_TO_FILE_NAMES ( p0.get_add_seed_to_file_names() ); p.set_DIRECTION_TYPE ( p0.get_direction_types() ); p.set_SEC_POLL_DIR_TYPE ( p0.get_sec_poll_dir_types() ); - p.set_HALTON_SEED ( p0.get_halton_seed() ); p.set_OPPORTUNISTIC_EVAL ( p0.get_opportunistic_eval() ); p.set_OPPORTUNISTIC_MIN_NB_SUCCESS ( p0.get_opportunistic_min_nb_success() ); p.set_OPPORTUNISTIC_MIN_EVAL ( p0.get_opportunistic_min_eval() ); diff --git a/tools/SENSITIVITY/problems/cube/detailed/param.txt b/tools/SENSITIVITY/problems/cube/detailed/param.txt index 8939c254e9abcc545ae3f3ee150d2663373e1ad9..849595d95bbfa27158cd348e03c1ec9d19a2b064 100644 --- a/tools/SENSITIVITY/problems/cube/detailed/param.txt +++ b/tools/SENSITIVITY/problems/cube/detailed/param.txt @@ -6,5 +6,5 @@ LOWER_BOUND [0 0 0] UPPER_BOUND [2 2 2] # tmp_dir /tmp #max_bb_eval 500 -#multi_overall_bb_eval 500 +multi_overall_bb_eval 500 #multi_nb_mads_runs 5 diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.cpp index e9112bd383cc8f19e2d76ae272c24ef8887def36..53236ea0bb9c3c23ad0a8c0d8f0881519f55445b 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.cpp @@ -1,80 +1,80 @@ -#include "RungeKutta.hpp" - -#include <iomanip> - -using namespace std; - -template <class E> -RungeKutta<E>::RungeKutta(int dim) -{ - m = dim; - k1 = new double[m]; - k2 = new double[m]; - k3 = new double[m]; - k4 = new double[m]; - y = new double[m]; - y_tmp = new double[m]; -} - -template <class E> -RungeKutta<E>::~RungeKutta() -{ - delete [] k1; - delete [] k2; - delete [] k3; - delete [] k4; - delete [] y; - delete [] y_tmp; -} - -template <class E> -void RungeKutta<E>::set ( E * tmp , double * y0 , double beg , double end ) -{ - unit=tmp; - x0=beg; xn=end; - x=x0; - h=double(xn-x0)/double(N_INTER); - for (i=0;i<m;i++) {y[i]=y0[i];} - success=true; -} - -template <class E> -bool RungeKutta<E>::run() { - for(j=0;j<MAX_ITER_RK;j++) { - //Avoid going out of x interval - if (x+h >xn) { - h = xn-x; - j = MAX_ITER_RK; - } - - //Compute k1, k2, k3, k4 - for(i=0;i<m;i++) - k1[i] = h*unit->f(i, x, y); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k1[i]/2.0; - for(i=0;i<m;i++) - k2[i] = h*unit->f(i, x+h/2.0, y_tmp); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k2[i]/2.0; - for(i=0;i<m;i++) - k3[i] = h*unit->f(i, x+h/2.0, y_tmp); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k3[i]; - for ( i = 0 ; i < m ; i++ ) - k4[i] = h*unit->f ( i , x+h , y_tmp ); - //Compute the new y - for(i=0;i<m;i++) - y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0; - x += h; - } - - if ( x < xn-EPS ) {// MODIF SEB (le EPS) - success=false; - - // cout.setf(ios::fixed); - // cout << setprecision(12); - // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl; - } - - return success; -} +#include "RungeKutta.hpp" + +#include <iomanip> + +using namespace std; + +template <class E> +RungeKutta<E>::RungeKutta(int dim) +{ + m = dim; + k1 = new double[m]; + k2 = new double[m]; + k3 = new double[m]; + k4 = new double[m]; + y = new double[m]; + y_tmp = new double[m]; +} + +template <class E> +RungeKutta<E>::~RungeKutta() +{ + delete [] k1; + delete [] k2; + delete [] k3; + delete [] k4; + delete [] y; + delete [] y_tmp; +} + +template <class E> +void RungeKutta<E>::set ( E * tmp , double * y0 , double beg , double end ) +{ + unit=tmp; + x0=beg; xn=end; + x=x0; + h=double(xn-x0)/double(N_INTER); + for (i=0;i<m;i++) {y[i]=y0[i];} + success=true; +} + +template <class E> +bool RungeKutta<E>::run() { + for(j=0;j<MAX_ITER_RK;j++) { + //Avoid going out of x interval + if (x+h >xn) { + h = xn-x; + j = MAX_ITER_RK; + } + + //Compute k1, k2, k3, k4 + for(i=0;i<m;i++) + k1[i] = h*unit->f(i, x, y); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k1[i]/2.0; + for(i=0;i<m;i++) + k2[i] = h*unit->f(i, x+h/2.0, y_tmp); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k2[i]/2.0; + for(i=0;i<m;i++) + k3[i] = h*unit->f(i, x+h/2.0, y_tmp); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k3[i]; + for ( i = 0 ; i < m ; i++ ) + k4[i] = h*unit->f ( i , x+h , y_tmp ); + //Compute the new y + for(i=0;i<m;i++) + y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0; + x += h; + } + + if ( x < xn-EPS ) {// MODIF SEB (le EPS) + success=false; + + // cout.setf(ios::fixed); + // cout << setprecision(12); + // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl; + } + + return success; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.hpp index db2b3c22d5b1c897238f65d8a961be5d6fadfaf7..240075371d9f76c61faa9f0865ace58c090acd41 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/RungeKutta.hpp @@ -1,37 +1,37 @@ -/* -To use the Runge-Kutta solver for systems of first order differential equations, - (the parametric object E must have public function such as E->f(i,x,y), - where i is the index of the function to evaluate, x is the time and - y is a point such as y(x), returns values of differential equation i) - - 1- construct the solver : solver = new RungeKutta<objet>(int); //the integer is the dimension of x - 2- set the solver : solver->set(unit, y0, x0, xn); //unit is usually the pointer *this, y0 are the initial conditions, and x0 and xn is the time interval - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed???????????????????????????? - 4- delete the solver : delete solver; -(ref :Fortin) -*/ -#ifndef RUNGEKUTTA_H -#define RUNGEKUTTA_H - -#include "defines.hpp" -using namespace std; - -template <class E> -class RungeKutta -{ -private: - double *k1, *k2, *k3, *k4, *y_tmp, *y; - // double k1[MAX_DIM], k2[MAX_DIM], k3[MAX_DIM], k4[MAX_DIM], y_tmp[MAX_DIM], y[MAX_DIM]; - double h, x0, xn, x; - int i, j, m; - bool success; - E *unit; - -public: - RungeKutta(int); - ~RungeKutta(); - void set(E*, double*, double, double); - double dx(){return h;} - bool run(); -}; -#endif +/* +To use the Runge-Kutta solver for systems of first order differential equations, + (the parametric object E must have public function such as E->f(i,x,y), + where i is the index of the function to evaluate, x is the time and + y is a point such as y(x), returns values of differential equation i) + + 1- construct the solver : solver = new RungeKutta<objet>(int); //the integer is the dimension of x + 2- set the solver : solver->set(unit, y0, x0, xn); //unit is usually the pointer *this, y0 are the initial conditions, and x0 and xn is the time interval + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed???????????????????????????? + 4- delete the solver : delete solver; +(ref :Fortin) +*/ +#ifndef RUNGEKUTTA_H +#define RUNGEKUTTA_H + +#include "defines.hpp" +using namespace std; + +template <class E> +class RungeKutta +{ +private: + double *k1, *k2, *k3, *k4, *y_tmp, *y; + // double k1[MAX_DIM], k2[MAX_DIM], k3[MAX_DIM], k4[MAX_DIM], y_tmp[MAX_DIM], y[MAX_DIM]; + double h, x0, xn, x; + int i, j, m; + bool success; + E *unit; + +public: + RungeKutta(int); + ~RungeKutta(); + void set(E*, double*, double, double); + double dx(){return h;} + bool run(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.cpp index 60e3d3883204076214d950171deff58a7ccc7809..d23a93996575be1c12c1d6a882367d2444a7fd60 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.cpp @@ -1,27 +1,27 @@ -#include "bissection.hpp" -using namespace std; - -template <class E> -bool bissection<E>::run() -{ - for (i=1; i<MAX_ITER_BISSECTION; i++) - { - xm=(x1+x2)/2; - // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; - if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) - { - i=MAX_ITER_BISSECTION; - OK=true; - } - else - { - f1 = unit->f(x1); - fm = unit->f(xm); - f2 = unit->f(x2); - if (f1*fm < 0.0) x2 = xm; - if (fm*f2 < 0.0) x1 = xm; - } - } - // if (DEBUG) system("pause"); - return OK; -} +#include "bissection.hpp" +using namespace std; + +template <class E> +bool bissection<E>::run() +{ + for (i=1; i<MAX_ITER_BISSECTION; i++) + { + xm=(x1+x2)/2; + // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; + if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) + { + i=MAX_ITER_BISSECTION; + OK=true; + } + else + { + f1 = unit->f(x1); + fm = unit->f(xm); + f2 = unit->f(x2); + if (f1*fm < 0.0) x2 = xm; + if (fm*f2 < 0.0) x1 = xm; + } + } + // if (DEBUG) system("pause"); + return OK; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.hpp index c277e299792392a6a4331b44dfd49b60a7f53e16..18d4ee6b1cd2949f7b3e8206a5c88629006bca25 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/bissection.hpp @@ -1,31 +1,31 @@ -/* -To use the bissection solver to find the root of a scalar function -when the secant solver fails. - (the parametric object E must have public function such as E->f(x), - where x is the point at which evaluate f.) - 1- construct the solver : solver = new bissect<E>(); - 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are the interval's bounds - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed -*/ -#ifndef BISSECTION_H -#define BISSECTION_H - -#include "defines.hpp" -using namespace std; - -template <class E> -class bissection { -private: - double x1, xm, x2; - double f1, fm, f2; - int i; - bool OK; - E *unit; - -public: - bissection(){x1=xm=x2=f1=fm=f2=0; OK=false;} - void set(E* tmp, double xx1, double xx2) {unit=tmp; x1=xx1; x2=xx2;} - bool run(); - ~bissection(){} -}; -#endif +/* +To use the bissection solver to find the root of a scalar function +when the secant solver fails. + (the parametric object E must have public function such as E->f(x), + where x is the point at which evaluate f.) + 1- construct the solver : solver = new bissect<E>(); + 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are the interval's bounds + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed +*/ +#ifndef BISSECTION_H +#define BISSECTION_H + +#include "defines.hpp" +using namespace std; + +template <class E> +class bissection { +private: + double x1, xm, x2; + double f1, fm, f2; + int i; + bool OK; + E *unit; + +public: + bissection(){x1=xm=x2=f1=fm=f2=0; OK=false;} + void set(E* tmp, double xx1, double xx2) {unit=tmp; x1=xx1; x2=xx2;} + bool run(); + ~bissection(){} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.cpp index eb8a223bf429389fe9ad4b3d8b59b914331d7cc6..1b6f36b09550b2585fa78071983f0f77fc9d4576 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.cpp @@ -1,287 +1,287 @@ -#include "burner.hpp" -using namespace std; - -/*----------------------------------------------------------*/ -/* arrondi pour ne conserver que n chiffres significatifs */ -/*----------------------------------------------------------*/ -double arrondi ( double x , int n ) { - if (fabs(x) < EPS) - return 0.0; - double m = pow ( 10 , ceil(-log10(x)) + n - 1 ); - return round(m*x)/m; -} - -/*---------------------------------------------------------------*/ -burner::burner ( int nb , chemical ** chem ) { - - rem_nb = nb; - - NO=NO2=N2O=CO=0.0; - m = new double[nb]; - can_burn = new bool[nb]; - - // combustion.prop : - // ----------------- - // 64-17-5 3 2 3 - // 74-82-8 2 1 2 - // 1333-74-0 0.5 0 1 - // 100-42-5 10 8 4 - // 74-85-1 3 2 2 - // 108-88-3 9 7 4 - // 100-41-4 10.5 8 5 - // 71-43-2 7.5 6 3 - - for ( i = 0 ; i < nb ; i++ ) { - - can_burn[i] = false; - - if ( chem[i]->CAS == "64-17-5" || - chem[i]->CAS == "74-82-8" || - chem[i]->CAS == "1333-74-0" || - chem[i]->CAS == "100-42-5" || - chem[i]->CAS == "74-85-1" || - chem[i]->CAS == "108-88-3" || - chem[i]->CAS == "100-41-4" || - chem[i]->CAS == "71-43-2" ) - can_burn[i] = true; - } - - O2 = new chemical ("7782-44-7"); - N2 = new chemical ("7727-37-9"); - CO2 = new chemical ("124-38-9"); - H2O = new chemical ("7732-18-5"); - - // Construct the rx array; - rx = new combrx * [nb]; - for ( i = 0 ; i < nb ; i++ ) { - if ( can_burn[i] ) - rx[i] = new combrx ( chem[i]->CAS ); - else - rx[i] = NULL; - } -} - -/*---------------------------------------------------------------*/ -burner::~burner ( void ) { - - delete [] m; - delete [] can_burn; - - for ( i = 0 ; i < rem_nb ; i++ ) - if (rx[i]) - delete rx[i]; - delete [] rx; - - delete O2; - delete N2; - delete CO2; - delete H2O; -} - -/*---------------------------------------------------------------*/ -bool burner::solve(double * y) -{ - OK=true; - //perform mass balance (neglect pollutants flows) - out->m = 0.0; - for(i=0;i<in->nb;i++) - { - if (!can_burn[i]) { - out->chem[i]->m = in->chem[i]->m; - out->m+=out->chem[i]->m; - } - else { - out->chem[i]->m=0.0; - O2->m+=rx[i]->O2_flow()*in->chem[i]->n(); - N2->m+=rx[i]->N2_flow()*in->chem[i]->n(); - CO2->m+=rx[i]->CO2_flow()*in->chem[i]->n(); - H2O->m+=rx[i]->H2O_flow()*in->chem[i]->n(); - } - } - N2->m*=(1.0+eta); - O2->m*=(1.0+eta); - //perform energy balance to find Tout - T = in->T; - - step=10; - Q=1; - // find temperature - while (fabs(step)>TOL_BURN && fabs(Q)>TOL_BURN && T<MAX_TEMP) - { - T+=step; - - if(T>MAX_TEMP) - T=MAX_TEMP; - Q = 0.0; - for ( i = 0 ; i < in->nb ; i++ ) - Q += in->chem[i]->dH ( in->T , T , in->P ) * in->chem[i]->n(); - - for ( i = 0 ; i < in->nb ; i++ ) - if ( can_burn[i] ) - Q += rx[i]->Hcomb(T) * in->chem[i]->n(); - - Q += O2->dH ( 293 , T , in->P ) * O2->n(); - Q += N2->dH ( 293 , T , in->P ) * N2->n(); - - - if (step/fabs(step)*Q >0) - step*= -0.1; - else if (fabs(Q)<10) - step*=0.25; - - } - - - - out->set_thermo(in->thermo); - // out->thermo = in->thermo; - - out->set(in->P, T); - O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); - N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); - CO2->P=in->P; CO2->T=T; CO2->state=1; CO2->find_v(); - H2O->P=in->P; H2O->T=T; H2O->state=1; H2O->find_v(); - //check if mixture can burn - m_can_burn = 0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) m_can_burn+=in->chem[i]->n(); - LFLmix=0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) LFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->LFL(in->P,T); - UFLmix=0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) UFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->UFL(in->P,T); - num = 0.0; - buff=in->T; in->set(in->P, T); - for(i=0;i<in->nb;i++) if(can_burn[i]) num+=in->chem[i]->n()/in->n()*in->v; - in->set(in->P, buff); - den = O2->v+N2->v+out->v; - composition = num/den; - if(!(LFLmix<=composition && composition<=UFLmix) || T==MAX_TEMP) - { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Mixture in "<<name<<" can't burn (LFL="<<LFLmix -// <<" UFL="<<UFLmix<<" x="<<composition<<").\n"; -// logf.close(); - T=in->T; - filename = out->name; - *out=*in; - out->set(filename); - // out->write(); // WRITE TOTO - OK=false; - } - else - { - O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); - N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); - // out->write(); // WRITE TOTO - } - if(OK) //compute the pollutants production - { - fill_K_array(); - NO = 1e6*sqrt(K[0]*(N2->n()/den)*(O2->n()/den))*den*0.03/(O2->m+N2->m+out->m+H2O->m+CO2->m); - N2O = 1e6*K[1]*(N2->n()/den)*sqrt(O2->n()/den)*den*0.044/(O2->m+N2->m+out->m+H2O->m+CO2->m); - NO2 = 1e6*K[2]*sqrt(N2->n()/den)*(O2->n()/den)*den*0.046/(O2->m+N2->m+out->m+H2O->m+CO2->m); - CO = 1e6*K[3]*(CO2->n()/den)*den/sqrt(O2->n()/den)*0.028/(O2->m+N2->m+out->m+H2O->m+CO2->m); - } -// logf.open(MESSAGES,ios::app); - if (NO>EPS && NO2>EPS && N2O>EPS) { - // logf<<" --> Warning <-- Presence of NOx: "<<(NO+NO2+N2O)<<" ppm in "<<name<<".\n"; - y[7] = NO+NO2+N2O; - - if (ARRONDI) - y[7] = arrondi ( y[7] , 6 ); - - } - if (CO>EPS) { - // logf<<" --> Warning <-- Presence of CO: "<<CO<<" ppm in "<<name<<".\n"; - y[8] = CO; - if (ARRONDI) - y[8] = arrondi ( y[8] , 6 ); - - } -// logf.close(); - return OK; -} - -void burner::fill_K_array() -{ - a[0]=1.0; a[1]=1.0; a[2]=0.5; a[3]=1.0; - b[0]=1.0; b[1]=0.5; b[2]=1.0; b[3]=-0.5; - c[0]=2.0; c[1]=1.0; c[2]=1.0; c[3]=1.0; - K[0] = exp(-120.27*(173.38-T*0.012)/T); - K[1] = exp(-120.27*(103.64+T*0.074)/T); - K[2] = exp(-120.27*(51.96+T*0.061)/T); - K[3] = exp(-120.27*(283.84-T*0.087)/T); - for(i=0;i<4;i++) - K[i]*=pow(1000, c[i]-a[i]-b[i]); -} - -void burner::write() { - - cout << setprecision(6); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in : " << in->name; - cout << endl << "\t>> streams out : " << out->name; - cout << endl << "\t>> P = " << in->P << " atm, T(in) = " << in->T - << " T(out) = " << T << " K"; - O2->P = 1; - O2->T = 293; - O2->state = 1; - O2->find_v(); - N2->P=1; - N2->T=293; - N2->state=1; - N2->find_v(); - cout << endl << "\t>> Required air flow = " - << (O2->m+N2->m) << " kg/s (" << (O2->v+N2->v) << " m3/s)"; - O2->P=in->P; - O2->T=T; - O2->state=1; - O2->find_v(); - N2->P=in->P; - N2->T=T; - N2->state=1; - N2->find_v(); - step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); - cout << endl << "\t>> Total flue gases = " - << (out->m+CO2->m+H2O->m+N2->m+eta*O2->m/(1+eta)) - <<" kg/s (" << step << " m3/s)"; - cout << "\n\tEND\n\n"; - cost(); -} - - -double burner::get_cost ( void ) { - - - O2->P = 1; - O2->T = 293; - O2->state = 1; - O2->find_v(); - N2->P=1; - N2->T=293; - N2->state=1; - N2->find_v(); - O2->P=in->P; - O2->T=T; - O2->state=1; - O2->find_v(); - N2->P=in->P; - N2->T=T; - N2->state=1; - N2->find_v(); - step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); - - buff = 3.1761-0.1373*log10(step) + 0.3414*pow(log10(step),2); - buff = 2.7*pow(10, buff); - buff = buff*MS_YEAR/MS_2001; - - return buff; -} - - -void burner::cost ( void ) { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} +#include "burner.hpp" +using namespace std; + +/*----------------------------------------------------------*/ +/* arrondi pour ne conserver que n chiffres significatifs */ +/*----------------------------------------------------------*/ +double arrondi ( double x , int n ) { + if (fabs(x) < EPS) + return 0.0; + double m = pow ( 10 , ceil(-log10(x)) + n - 1 ); + return round(m*x)/m; +} + +/*---------------------------------------------------------------*/ +burner::burner ( int nb , chemical ** chem ) { + + rem_nb = nb; + + NO=NO2=N2O=CO=0.0; + m = new double[nb]; + can_burn = new bool[nb]; + + // combustion.prop : + // ----------------- + // 64-17-5 3 2 3 + // 74-82-8 2 1 2 + // 1333-74-0 0.5 0 1 + // 100-42-5 10 8 4 + // 74-85-1 3 2 2 + // 108-88-3 9 7 4 + // 100-41-4 10.5 8 5 + // 71-43-2 7.5 6 3 + + for ( i = 0 ; i < nb ; i++ ) { + + can_burn[i] = false; + + if ( chem[i]->CAS == "64-17-5" || + chem[i]->CAS == "74-82-8" || + chem[i]->CAS == "1333-74-0" || + chem[i]->CAS == "100-42-5" || + chem[i]->CAS == "74-85-1" || + chem[i]->CAS == "108-88-3" || + chem[i]->CAS == "100-41-4" || + chem[i]->CAS == "71-43-2" ) + can_burn[i] = true; + } + + O2 = new chemical ("7782-44-7"); + N2 = new chemical ("7727-37-9"); + CO2 = new chemical ("124-38-9"); + H2O = new chemical ("7732-18-5"); + + // Construct the rx array; + rx = new combrx * [nb]; + for ( i = 0 ; i < nb ; i++ ) { + if ( can_burn[i] ) + rx[i] = new combrx ( chem[i]->CAS ); + else + rx[i] = NULL; + } +} + +/*---------------------------------------------------------------*/ +burner::~burner ( void ) { + + delete [] m; + delete [] can_burn; + + for ( i = 0 ; i < rem_nb ; i++ ) + if (rx[i]) + delete rx[i]; + delete [] rx; + + delete O2; + delete N2; + delete CO2; + delete H2O; +} + +/*---------------------------------------------------------------*/ +bool burner::solve(double * y) +{ + OK=true; + //perform mass balance (neglect pollutants flows) + out->m = 0.0; + for(i=0;i<in->nb;i++) + { + if (!can_burn[i]) { + out->chem[i]->m = in->chem[i]->m; + out->m+=out->chem[i]->m; + } + else { + out->chem[i]->m=0.0; + O2->m+=rx[i]->O2_flow()*in->chem[i]->n(); + N2->m+=rx[i]->N2_flow()*in->chem[i]->n(); + CO2->m+=rx[i]->CO2_flow()*in->chem[i]->n(); + H2O->m+=rx[i]->H2O_flow()*in->chem[i]->n(); + } + } + N2->m*=(1.0+eta); + O2->m*=(1.0+eta); + //perform energy balance to find Tout + T = in->T; + + step=10; + Q=1; + // find temperature + while (fabs(step)>TOL_BURN && fabs(Q)>TOL_BURN && T<MAX_TEMP) + { + T+=step; + + if(T>MAX_TEMP) + T=MAX_TEMP; + Q = 0.0; + for ( i = 0 ; i < in->nb ; i++ ) + Q += in->chem[i]->dH ( in->T , T , in->P ) * in->chem[i]->n(); + + for ( i = 0 ; i < in->nb ; i++ ) + if ( can_burn[i] ) + Q += rx[i]->Hcomb(T) * in->chem[i]->n(); + + Q += O2->dH ( 293 , T , in->P ) * O2->n(); + Q += N2->dH ( 293 , T , in->P ) * N2->n(); + + + if (step/fabs(step)*Q >0) + step*= -0.1; + else if (fabs(Q)<10) + step*=0.25; + + } + + + + out->set_thermo(in->thermo); + // out->thermo = in->thermo; + + out->set(in->P, T); + O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); + N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); + CO2->P=in->P; CO2->T=T; CO2->state=1; CO2->find_v(); + H2O->P=in->P; H2O->T=T; H2O->state=1; H2O->find_v(); + //check if mixture can burn + m_can_burn = 0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) m_can_burn+=in->chem[i]->n(); + LFLmix=0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) LFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->LFL(in->P,T); + UFLmix=0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) UFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->UFL(in->P,T); + num = 0.0; + buff=in->T; in->set(in->P, T); + for(i=0;i<in->nb;i++) if(can_burn[i]) num+=in->chem[i]->n()/in->n()*in->v; + in->set(in->P, buff); + den = O2->v+N2->v+out->v; + composition = num/den; + if(!(LFLmix<=composition && composition<=UFLmix) || T==MAX_TEMP) + { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Mixture in "<<name<<" can't burn (LFL="<<LFLmix +// <<" UFL="<<UFLmix<<" x="<<composition<<").\n"; +// logf.close(); + T=in->T; + filename = out->name; + *out=*in; + out->set(filename); + // out->write(); // WRITE TOTO + OK=false; + } + else + { + O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); + N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); + // out->write(); // WRITE TOTO + } + if(OK) //compute the pollutants production + { + fill_K_array(); + NO = 1e6*sqrt(K[0]*(N2->n()/den)*(O2->n()/den))*den*0.03/(O2->m+N2->m+out->m+H2O->m+CO2->m); + N2O = 1e6*K[1]*(N2->n()/den)*sqrt(O2->n()/den)*den*0.044/(O2->m+N2->m+out->m+H2O->m+CO2->m); + NO2 = 1e6*K[2]*sqrt(N2->n()/den)*(O2->n()/den)*den*0.046/(O2->m+N2->m+out->m+H2O->m+CO2->m); + CO = 1e6*K[3]*(CO2->n()/den)*den/sqrt(O2->n()/den)*0.028/(O2->m+N2->m+out->m+H2O->m+CO2->m); + } +// logf.open(MESSAGES,ios::app); + if (NO>EPS && NO2>EPS && N2O>EPS) { + // logf<<" --> Warning <-- Presence of NOx: "<<(NO+NO2+N2O)<<" ppm in "<<name<<".\n"; + y[7] = NO+NO2+N2O; + + if (ARRONDI) + y[7] = arrondi ( y[7] , 6 ); + + } + if (CO>EPS) { + // logf<<" --> Warning <-- Presence of CO: "<<CO<<" ppm in "<<name<<".\n"; + y[8] = CO; + if (ARRONDI) + y[8] = arrondi ( y[8] , 6 ); + + } +// logf.close(); + return OK; +} + +void burner::fill_K_array() +{ + a[0]=1.0; a[1]=1.0; a[2]=0.5; a[3]=1.0; + b[0]=1.0; b[1]=0.5; b[2]=1.0; b[3]=-0.5; + c[0]=2.0; c[1]=1.0; c[2]=1.0; c[3]=1.0; + K[0] = exp(-120.27*(173.38-T*0.012)/T); + K[1] = exp(-120.27*(103.64+T*0.074)/T); + K[2] = exp(-120.27*(51.96+T*0.061)/T); + K[3] = exp(-120.27*(283.84-T*0.087)/T); + for(i=0;i<4;i++) + K[i]*=pow(1000, c[i]-a[i]-b[i]); +} + +void burner::write() { + + cout << setprecision(6); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in : " << in->name; + cout << endl << "\t>> streams out : " << out->name; + cout << endl << "\t>> P = " << in->P << " atm, T(in) = " << in->T + << " T(out) = " << T << " K"; + O2->P = 1; + O2->T = 293; + O2->state = 1; + O2->find_v(); + N2->P=1; + N2->T=293; + N2->state=1; + N2->find_v(); + cout << endl << "\t>> Required air flow = " + << (O2->m+N2->m) << " kg/s (" << (O2->v+N2->v) << " m3/s)"; + O2->P=in->P; + O2->T=T; + O2->state=1; + O2->find_v(); + N2->P=in->P; + N2->T=T; + N2->state=1; + N2->find_v(); + step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); + cout << endl << "\t>> Total flue gases = " + << (out->m+CO2->m+H2O->m+N2->m+eta*O2->m/(1+eta)) + <<" kg/s (" << step << " m3/s)"; + cout << "\n\tEND\n\n"; + cost(); +} + + +double burner::get_cost ( void ) { + + + O2->P = 1; + O2->T = 293; + O2->state = 1; + O2->find_v(); + N2->P=1; + N2->T=293; + N2->state=1; + N2->find_v(); + O2->P=in->P; + O2->T=T; + O2->state=1; + O2->find_v(); + N2->P=in->P; + N2->T=T; + N2->state=1; + N2->find_v(); + step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); + + buff = 3.1761-0.1373*log10(step) + 0.3414*pow(log10(step),2); + buff = 2.7*pow(10, buff); + buff = buff*MS_YEAR/MS_2001; + + return buff; +} + + +void burner::cost ( void ) { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.hpp index 3d834032e5fc8480aa17f95b94b71a9d9fc9cf98..310df0d78663669e1536c1f38750c21102828ee6 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/burner.hpp @@ -1,59 +1,59 @@ -/* -This unit simulates a burner. The user must provide the air excess -and all combustion data as defined in data\\combustion.prop : - CAS nb_moles_O2 nb_moles_CO2 nb_moles_H2O -Then, mass and energy balances are performed and flows of common -combustion pollutants are estimated. -(reference : Crowl & Louvar) - -Structure in the .process file: -burner {name} {index of input stream} {index of output stream} {air excess >0 (ex.: 1.2 is a 120% excess)} - -How to use: - 1- Call the constructor: burn = new burner(in, out); burner(nb_in, chem_list) - ->set(in, out) - 2- Set the air excess : burn->set(excess); - 3- Set the name of the unit: burn->set(name); - 4- Solve: bool=burn->solve(); -*/ -#ifndef BURNER_H -#define BURNER_H -#include "stream.hpp" -#include "combrx.hpp" -using namespace std; - -class burner -{ -private: - - string filename; - int rem_nb; - stream *in, *out; - chemical *O2, *N2, *CO2, *H2O; - combrx **rx; - bool *can_burn, stop, OK; - double eta, NO, NO2, N2O, CO; - double T, LFLmix, UFLmix, composition; - string name; - double * m; - double a[4], b[4], c[4], K[4]; - int i; - double buff, Q, m_can_burn, step, num, den; - ifstream data; - // ofstream logf, results; - // terminator *end; - void fill_K_array(); - -public: - // burner(){}; - burner ( int , chemical ** ); - void set ( stream * s1 , stream * s2 ) { in=s1; out=s2; for(i=0;i<in->nb;i++) m[i] = in->chem[i]->m;} - void set ( const string & n ) { name = n; } - void set(double e) {eta = e;} - bool solve(double * y); - void write(); - void cost(); - double get_cost ( void ); - ~burner(); -}; -#endif +/* +This unit simulates a burner. The user must provide the air excess +and all combustion data as defined in data\\combustion.prop : + CAS nb_moles_O2 nb_moles_CO2 nb_moles_H2O +Then, mass and energy balances are performed and flows of common +combustion pollutants are estimated. +(reference : Crowl & Louvar) + +Structure in the .process file: +burner {name} {index of input stream} {index of output stream} {air excess >0 (ex.: 1.2 is a 120% excess)} + +How to use: + 1- Call the constructor: burn = new burner(in, out); burner(nb_in, chem_list) + ->set(in, out) + 2- Set the air excess : burn->set(excess); + 3- Set the name of the unit: burn->set(name); + 4- Solve: bool=burn->solve(); +*/ +#ifndef BURNER_H +#define BURNER_H +#include "stream.hpp" +#include "combrx.hpp" +using namespace std; + +class burner +{ +private: + + string filename; + int rem_nb; + stream *in, *out; + chemical *O2, *N2, *CO2, *H2O; + combrx **rx; + bool *can_burn, stop, OK; + double eta, NO, NO2, N2O, CO; + double T, LFLmix, UFLmix, composition; + string name; + double * m; + double a[4], b[4], c[4], K[4]; + int i; + double buff, Q, m_can_burn, step, num, den; + ifstream data; + // ofstream logf, results; + // terminator *end; + void fill_K_array(); + +public: + // burner(){}; + burner ( int , chemical ** ); + void set ( stream * s1 , stream * s2 ) { in=s1; out=s2; for(i=0;i<in->nb;i++) m[i] = in->chem[i]->m;} + void set ( const string & n ) { name = n; } + void set(double e) {eta = e;} + bool solve(double * y); + void write(); + void cost(); + double get_cost ( void ); + ~burner(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.cpp index c7174f643dda84b2d8082bb6f4ba55135f405d52..a35a767865f7f1761450f84acf60c65e996d8311 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.cpp @@ -1,114 +1,114 @@ -#include "cashflow.hpp" -using namespace std; - -cashflow::cashflow(int n) -{ - N=n+1; - Inv = new double[N]; - Coper = new double[N]; - Amort = new double[N]; - Rev = new double[N]; - Flow = new double[N]; - Flowact = new double[N]; - Itot=Ctot=Rtot=i_rate=a_rate=0.0; - - - yield_tab[ 0] = 0.515; - yield_tab[ 1] = 0.778; - yield_tab[ 2] = 0.812; - yield_tab[ 3] = 0.893; - yield_tab[ 4] = 0.985; - yield_tab[ 5] = 0.837; - yield_tab[ 6] = 0.849; - yield_tab[ 7] = 0.746; - yield_tab[ 8] = 0.812; - yield_tab[ 9] = 0.954; - yield_tab[10] = 0.999; - yield_tab[11] = 0.961; - yield_tab[12] = 0.815; - yield_tab[13] = 0.886; - yield_tab[14] = 0.922; - -} - -cashflow::~cashflow ( void ) { - delete [] Inv; - delete [] Coper; - delete [] Amort; - delete [] Rev; - delete [] Flow; - delete [] Flowact; -} - -bool cashflow::run() -{ - if(Itot<EPS || Ctot<EPS || Rtot<EPS || i_rate<EPS || a_rate<EPS) - OK=false; - else - { - //if(!MUTE)cout<<endl<<" investments flow... OK"; - set_Inv(); - //if(!MUTE)cout<<endl<<" depreciation flow... OK"; - set_Amort(); - set_C_R(); - //if(!MUTE)cout<<endl<<" costs flow... OK"; - //if(!MUTE)cout<<endl<<" revenus flow... OK"; - for(i=0;i<N;i++) - { - Flow[i] = (Rev[i]-Coper[i])*(1.0-a_rate)-(Inv[i]-a_rate*Amort[i]); - Flowact[i] = Flow[i]/pow(1.0+i_rate, i); - } - //if(!MUTE)cout<<endl<<" cash flow... OK"; - //if(!MUTE)cout<<endl<<" actualizing cash flow... OK"; - OK=true; - -// cout<<endl<<endl<<" CASH FLOW DETAILS"<<endl; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; -// cout<<endl<<" "<<" i "<<" Investment "<<" Deprec. " -// <<" Expenses "<<" Revenus "<<" Cash flow "<<" Act. flow "; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; -// cout<<setfill(' ')<<setiosflags(ios::fixed)<<setprecision(0); -// for(i=0;i<N;i++) -// cout<<endl -// <<" "<<setw(2)<<i<<" "<<setw(11) -// <<Inv[i]<<" "<<setw(11)<<Amort[i]<<" " -// <<setw(11)<<Coper[i]<<" "<<setw(11)<<Rev[i]<<" "<<setw(11)<<Flow[i]<<" "<<setw(11)<<Flowact[i]; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; - } - return OK; -} - -void cashflow::set_Amort() -{ - Amort[0] = 0.0; - temp=Itot; - for(i=1;i<N-1;i++) - { - temp+=Inv[i]; - Amort[i] = temp/double(N-i); - temp-=Amort[i]; - } - Amort[N-1]=Amort[N-2]; -} - -void cashflow::set_Inv() -{ - Inv[0] = Itot; - for(i=1;i<N-1;i++) - { - if((i)%5==0) Inv[i]=0.1*Itot; - else Inv[i]=0.0; - } - Inv[N-1]=0.0; - for(i=0;i<N-1;i++) Inv[N-1]-=0.1*Inv[i]; -} - -void cashflow::set_C_R() -{ - Coper[0] = Rev[0] = 0.0; - for(i=1;i<N;i++) - { - Coper[i] = yield(i)*Ctot; - Rev[i] = yield(i)*Rtot; - } -} +#include "cashflow.hpp" +using namespace std; + +cashflow::cashflow(int n) +{ + N=n+1; + Inv = new double[N]; + Coper = new double[N]; + Amort = new double[N]; + Rev = new double[N]; + Flow = new double[N]; + Flowact = new double[N]; + Itot=Ctot=Rtot=i_rate=a_rate=0.0; + + + yield_tab[ 0] = 0.515; + yield_tab[ 1] = 0.778; + yield_tab[ 2] = 0.812; + yield_tab[ 3] = 0.893; + yield_tab[ 4] = 0.985; + yield_tab[ 5] = 0.837; + yield_tab[ 6] = 0.849; + yield_tab[ 7] = 0.746; + yield_tab[ 8] = 0.812; + yield_tab[ 9] = 0.954; + yield_tab[10] = 0.999; + yield_tab[11] = 0.961; + yield_tab[12] = 0.815; + yield_tab[13] = 0.886; + yield_tab[14] = 0.922; + +} + +cashflow::~cashflow ( void ) { + delete [] Inv; + delete [] Coper; + delete [] Amort; + delete [] Rev; + delete [] Flow; + delete [] Flowact; +} + +bool cashflow::run() +{ + if(Itot<EPS || Ctot<EPS || Rtot<EPS || i_rate<EPS || a_rate<EPS) + OK=false; + else + { + //if(!MUTE)cout<<endl<<" investments flow... OK"; + set_Inv(); + //if(!MUTE)cout<<endl<<" depreciation flow... OK"; + set_Amort(); + set_C_R(); + //if(!MUTE)cout<<endl<<" costs flow... OK"; + //if(!MUTE)cout<<endl<<" revenus flow... OK"; + for(i=0;i<N;i++) + { + Flow[i] = (Rev[i]-Coper[i])*(1.0-a_rate)-(Inv[i]-a_rate*Amort[i]); + Flowact[i] = Flow[i]/pow(1.0+i_rate, i); + } + //if(!MUTE)cout<<endl<<" cash flow... OK"; + //if(!MUTE)cout<<endl<<" actualizing cash flow... OK"; + OK=true; + +// cout<<endl<<endl<<" CASH FLOW DETAILS"<<endl; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; +// cout<<endl<<" "<<" i "<<" Investment "<<" Deprec. " +// <<" Expenses "<<" Revenus "<<" Cash flow "<<" Act. flow "; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; +// cout<<setfill(' ')<<setiosflags(ios::fixed)<<setprecision(0); +// for(i=0;i<N;i++) +// cout<<endl +// <<" "<<setw(2)<<i<<" "<<setw(11) +// <<Inv[i]<<" "<<setw(11)<<Amort[i]<<" " +// <<setw(11)<<Coper[i]<<" "<<setw(11)<<Rev[i]<<" "<<setw(11)<<Flow[i]<<" "<<setw(11)<<Flowact[i]; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; + } + return OK; +} + +void cashflow::set_Amort() +{ + Amort[0] = 0.0; + temp=Itot; + for(i=1;i<N-1;i++) + { + temp+=Inv[i]; + Amort[i] = temp/double(N-i); + temp-=Amort[i]; + } + Amort[N-1]=Amort[N-2]; +} + +void cashflow::set_Inv() +{ + Inv[0] = Itot; + for(i=1;i<N-1;i++) + { + if((i)%5==0) Inv[i]=0.1*Itot; + else Inv[i]=0.0; + } + Inv[N-1]=0.0; + for(i=0;i<N-1;i++) Inv[N-1]-=0.1*Inv[i]; +} + +void cashflow::set_C_R() +{ + Coper[0] = Rev[0] = 0.0; + for(i=1;i<N;i++) + { + Coper[i] = yield(i)*Ctot; + Rev[i] = yield(i)*Rtot; + } +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.hpp index a71b7abf72e7322f1ed2c25256e1bedcd5a610f9..5aa5f70ead6aa4bf754d8175e1dbe9358b458352 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/cashflow.hpp @@ -1,33 +1,33 @@ -#ifndef CASHFLOW_H -#define CASHFLOW_H -#include "defines.hpp" -// #include <iomanip> -using namespace std; - -class cashflow -{ - private: - // char name[31], filename[41]; - // ifstream in; - // ofstream out; - double Itot, Ctot, Rtot; - void set_Inv(), set_Amort(), set_C_R(); - double temp; - int i, j, counter; - bool OK; - double yield_tab[15]; - - double yield ( int k ) const { return yield_tab[(k==15) ? 14 : k%15]; } - -public: - double *Inv, *Coper, *Amort, *Rev, *Flow, *Flowact; - double i_rate, a_rate; - int N; - cashflow(int); - ~cashflow(); - // void set(char n[31]) {strcpy(name, n);} - void set_rates(double d1, double d2){i_rate=d1; a_rate=d2;} - void set_basics(double d1, double d2, double d3){Itot=d1; Ctot=d2; Rtot=d3;} - bool run(); -}; -#endif +#ifndef CASHFLOW_H +#define CASHFLOW_H +#include "defines.hpp" +// #include <iomanip> +using namespace std; + +class cashflow +{ + private: + // char name[31], filename[41]; + // ifstream in; + // ofstream out; + double Itot, Ctot, Rtot; + void set_Inv(), set_Amort(), set_C_R(); + double temp; + int i, j, counter; + bool OK; + double yield_tab[15]; + + double yield ( int k ) const { return yield_tab[(k==15) ? 14 : k%15]; } + +public: + double *Inv, *Coper, *Amort, *Rev, *Flow, *Flowact; + double i_rate, a_rate; + int N; + cashflow(int); + ~cashflow(); + // void set(char n[31]) {strcpy(name, n);} + void set_rates(double d1, double d2){i_rate=d1; a_rate=d2;} + void set_basics(double d1, double d2, double d3){Itot=d1; Ctot=d2; Rtot=d3;} + bool run(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.cpp index 3c155a15a133f26f879eb326abe88654bf9f89d1..ad29297014d461b8355574e2129aa39760f4f545 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.cpp @@ -1,529 +1,529 @@ -#include "chemical.hpp" -using namespace std; - -void chemical::check_error ( void ) { - if (error>MAX_ERROR) { - cout << "ERROR 2\n\n"; - exit(0); - } - if (warning>MAX_WARNING) { - cout << "ERROR 3\n\n"; - exit(0); - } -} - -// copy-constr. : -chemical::chemical ( const chemical & chem ) { - - CAS = chem.CAS; - name = chem.name; - M = chem.M; - - state = chem.state; - Tm = chem.Tm; - Tb = chem.Tb; - Tc = chem.Tc; - Pc = chem.Pc; - Ho = chem.Ho; - rho_liq = chem.rho_liq; - dHvap = chem.dHvap; - - mu_param[0] = chem.mu_param[0]; - mu_param[1] = chem.mu_param[1]; - Cp_param[0] = chem.Cp_param[0]; - Cp_param[1] = chem.Cp_param[1]; - Cp_param[2] = chem.Cp_param[2]; - Cp_param[3] = chem.Cp_param[3]; - Cp_liq = chem.Cp_liq; - Psat_param[0] = chem.Psat_param[0]; - Psat_param[1] = chem.Psat_param[1]; - Psat_param[2] = chem.Psat_param[2]; - - thermo = new thermolib(); - thermo->send(Pc,Tc, omega()); - - P = chem.P; - T = chem.T; - m = chem.m; - v = chem.v; - - warning = chem.warning; - error = chem.error; - tmp = chem.tmp; -} - -chemical::chemical ( const string & chem_name ) { - - CAS = chem_name; - - // C. Tribes add initialization for more robustness (variables may be initialized uncorrectly dependent on the execution) - P=T=m=v=0.0; - - // 1/12 : - if (CAS=="100-41-4") { - name = "ethylbenzene"; - M = 106.17; - state = 0; - Tm = 178.2; - Tb = 409.3; - Tc = 617.1; - Pc = 35.6; - Ho = 29.79; - rho_liq = 867.0; - dHvap = 35.56; - mu_param[0] = 472.82; - mu_param[1] = 264.22; - Cp_param[0] = -43.069; - Cp_param[1] = 7.067e-01; - Cp_param[2] = -4.807e-04; - Cp_param[3] = 1.30e-07; - Cp_liq = 190.23; - Psat_param[0] = 16.0195; - Psat_param[1] = 3279.47; - Psat_param[2] = -59.95; - } - - // 2/12 : - else if (CAS=="1333-74-0") { - name = "hydrogen"; - M = 2.02; - state = 1; - Tm = 14.0; - Tb = 20.4; - Tc = 33.2; - Pc = 12.8; - Ho = 0.0; - rho_liq = 71.0; - dHvap = 0.9; - mu_param[0] = 13.82; - mu_param[1] = 5.39; - Cp_param[0] = 27.124; - Cp_param[1] = 9.267e-03; - Cp_param[2] = -1.380e-05; - Cp_param[3] = 7.64e-09; - Cp_liq = 0.0; - Psat_param[0] = 13.6333; - Psat_param[1] = 164.90; - Psat_param[2] = 3.19; - } - - // 3/12 : - else if (CAS=="108-88-3") { - name = "toluene"; - M =92.14; - state = 0; - Tm = 178.0; - Tb = 383.8; - Tc = 591.7; - Pc = 40.6; - Ho = 50.0; - rho_liq = 867; - dHvap = 33.18; - mu_param[0] = 467.33; - mu_param[1] = 255.24; - Cp_param[0] = -24.338; - Cp_param[1] = 5.121e-1; - Cp_param[2] = -2.763e-4; - Cp_param[3] = 4.91e-8; - Cp_liq = 159.85; - Psat_param[0] = 16.0137; - Psat_param[1] = 3096.52; - Psat_param[2] = -53.67; - } - - // 4/12 : - else if (CAS=="74-82-8") { - name = "methane"; - M =16.04; - state =1; - Tm = 90.7; - Tb = 111.7; - Tc = 190.6; - Pc = 45.4; - Ho = -74.85; - rho_liq = 425; - dHvap = 8.18; - mu_param[0] = 114.14; - mu_param[1] = 57.60; - Cp_param[0] = 19.238; - Cp_param[1] = 5.209e-02; - Cp_param[2] = 1.197e-05; - Cp_param[3] = -1.13e-08; - Cp_liq = 0.0; - Psat_param[0] = 15.2243; - Psat_param[1] = 897.84; - Psat_param[2] = -7.16; - } - - // 5/12 : - else if (CAS=="71-43-2") { - name = "benzene"; - M = 78.11; - state = 0; - Tm = 278.7; - Tb = 353.3; - Tc = 562.1; - Pc = 48.3; - Ho = 82.93; - rho_liq = 885; - dHvap = 30.76; - mu_param[0] = 545.64; - mu_param[1] = 265.24; - Cp_param[0] = 33.894; - Cp_param[1] = 4.74e-1; - Cp_param[2] = -3.015e-4; - Cp_param[3] = 7.13e-8; - Cp_liq = 116.03; - Psat_param[0] = 15.9008; - Psat_param[1] = 2788.51; - Psat_param[2] = -52.36; - } - - // 6/12 : - else if (CAS=="74-85-1") { - name = "ethylene"; - M = 28.05; - state =1; - Tm = 104.0; - Tb = 169.4; - Tc = 282.4; - Pc = 49.7; - Ho =52.3; - rho_liq = 577.0; - dHvap = 13.54; - mu_param[0] = 168.98; - mu_param[1] = 93.94; - Cp_param[0] = 3.803; - Cp_param[1] = 1.565e-01; - Cp_param[2] = -8.343e-05; - Cp_param[3] = 1.75e-08; - Cp_liq = 0.0; - Psat_param[0] =15.5368; - Psat_param[1] = 1347.01; - Psat_param[2] = -18.15; - } - - // 7/12 : - else if (CAS=="100-42-5") { - name = "styrene"; - M =104.15; - state = 0; - Tm = 242.5; - Tb = 418.3; - Tc =647.0; - Pc =39.4; - Ho =147.36; - rho_liq =906.0; - dHvap = 36.82; - mu_param[0] = 528.64; - mu_param[1] = 276.71; - Cp_param[0] =-28.229; - Cp_param[1] =6.155e-01; - Cp_param[2] = -4.020e-04; - Cp_param[3] = 9.93e-08; - Cp_liq =166.13; - Psat_param[0] = 16.0193; - Psat_param[1] = 3328.57; - Psat_param[2] =-63.72; - } - - // 8/12 : - else if (CAS=="7782-44-7") { - name = "oxygen"; - M = 32.00; - state = 1; - Tm = 54.4; - Tb = 90.2; - Tc = 154.6; - Pc = 49.8; - Ho =0.0 ; - rho_liq =1149.1 ; - dHvap =6.82 ; - mu_param[0] = 85.68; - mu_param[1] = 51.50; - Cp_param[0] = 28.087; - Cp_param[1] = -3.678e-06 ; - Cp_param[2] = 1.745e-05; - Cp_param[3] = -1.06e-08; - Cp_liq =0.0 ; - Psat_param[0] = 15.4075; - Psat_param[1] = 734.55 ; - Psat_param[2] =-6.45 ; - } - - // 9/12 : - else if (CAS=="7727-37-9") { - name = "nitrogen"; - M = 28.01; - state = 1; - Tm = 63.3; - Tb = 77.4; - Tc = 126.2; - Pc = 33.5; - Ho = 0.0; - rho_liq = 804.0; - dHvap = 5.58; - mu_param[0] = 90.30; - mu_param[1] = 46.41; - Cp_param[0] = 31.128; - Cp_param[1] = -1.356e-02 ; - Cp_param[2] = 2.678e-05; - Cp_param[3] =-1.17e-08 ; - Cp_liq = 0.0; - Psat_param[0] = 14.9342; - Psat_param[1] = 588.72; - Psat_param[2] = -6.60; - } - - // 10/12 : - else if (CAS=="124-38-9") { - name = "carbon-dioxide"; - M =44.01; - state = 1; - Tm = 216.6; - Tb = 194.4; - Tc = 304.2; - Pc = 72.8; - Ho = -393.41; - rho_liq = 777.0; - dHvap = 17.15; - mu_param[0] = 578.08; - mu_param[1] = 185.24 ; - Cp_param[0] = 19.782; - Cp_param[1] = 7.339e-02; - Cp_param[2] = -5.598e-05; - Cp_param[3] = 1.71e-08; - Cp_liq = 0.0; - Psat_param[0] = 22.5898; - Psat_param[1] =3103.39 ; - Psat_param[2] = -0.16; - } - - // 11/12 : - else if (CAS=="7732-18-5") { - name = "water"; - M =18.02; - state = 0; - Tm = 273.15; - Tb = 373.15; - Tc = 647.4; - Pc = 217.6; - Ho = -241.83; - rho_liq = 998 ; - dHvap = 40.66; - mu_param[0] = 658.25; - mu_param[1] = 283.16; - Cp_param[0] = 32.220; - Cp_param[1] = 1.923e-03 ; - Cp_param[2] = 1.055e-05; - Cp_param[3] = -3.59e-09; - Cp_liq = 75.24; - Psat_param[0] = 18.3036; - Psat_param[1] = 3816.44; - Psat_param[2] = -46.13; - } - - // 12/12 : - else if (CAS=="64-17-5") { - name = "ethanol"; - M =46.07; - state =0 ; - Tm =159.1 ; - Tb = 351.5; - Tc = 516.2; - Pc =63.0 ; - Ho = -234.8; - rho_liq = 789.0; - dHvap =38.74 ; - mu_param[0] = 686.64; - mu_param[1] = 300.88; - Cp_param[0] = 9.008; - Cp_param[1] = 2.139e-01; - Cp_param[2] = -8.385e-05 ; - Cp_param[3] = 1.37e-09; - Cp_liq = 2.22; - Psat_param[0] = 18.9119; - Psat_param[1] = 3803.98; - Psat_param[2] = -41.68; - } - - else { - cout << "ERROR 1\n\n"; - exit(0); - } - - thermo = new thermolib(); - thermo->send(Pc,Tc, omega()); - - -} - -double chemical::K() -{ - thermo->set(P,T,v,n()); - return thermo->K(); -} - -double chemical::mu() -{ - // Returns the fluid's viscosity in Pa.s - if (Tm<=T && T<=Tboil(P)) - return pow(10,(mu_param[0]*(1.0/T-1.0/mu_param[1])-3)); - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot compute viscosity of "<<name<<".\n"; - logf.close(); - warning++; - check_error(); - return 1.0; - } -} - -double chemical::rho() -{ - // Returns the fluid's density in kg/m3, wether it's liquid or gas - if(state==0) tmp= rho_liq; - if(state==1) - { - find_v(); - if (v>EPS) tmp= m/v; - else tmp= 0.0; - } - return tmp; -} - -double chemical::Cp() { - // cout<<endl<<"Cp de "<<name<<" a "<<T; - // Returns the fluid's Cp in J/mol.K - if(state==0) { - - // tmp = Cp_liq; // BUG : boucle infinie !!! - return Cp_liq; // SEB - - } - if(state==1 || T>Tboil(P)) { - tmp=0; - for (int i=0;i<4;i++) - tmp+=Cp_param[i]*pow(T,i); - } - else { - T=Tb; - - tmp = Cp(); // ici boucle infinie si state==0 !!! - - } - return tmp; -} - -double chemical::Cp(bool q) -{ - // Returns the fluid's Cp in J/mol.K - if(q==0) tmp=Cp_liq; - if(q==1) - { - tmp=0; - for (int i=0;i<4;i++) tmp+=Cp_param[i]*pow(T,i); - } - return tmp; -} - -double chemical::Psat() -{ - // Returns the fluid's vapor pressure in atm, using Antoine's equation - if(Tm<=T && T<=Tc) - return (exp(Psat_param[0]-Psat_param[1]/(T+Psat_param[2]))/760.01); - else - { - - return Psat(Tb); - } -} -double chemical::Psat(double t) -{ - // Returns the fluid's vapor pressure in atm, using Antoine's equation - return (exp(Psat_param[0]-Psat_param[1]/(t+Psat_param[2]))/760.01); -} - -double chemical::dH(double T1,double T2, double pres) -{ - //Enthalpy variation in kJ/mol. Does not affect any attributes of current object. - double energy=0, TT=Tboil(pres), vap=Hvap(TT); - int sign=1, i; - if (T2<T1) {sign = -1; energy=T1; T1=T2; T2=energy; energy=0;} - if (T1==T2) energy = 0.0; - if (T2<TT) energy = Cp_liq*(T2-T1)/1000; - if (TT<T1) for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(T1,i))/i/1000; - if(T1<=TT && TT<=T2) - { - energy=Cp_liq*(TT-T1)/1000; - energy+=vap; - for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(TT,i))/i/1000; - } - return energy*sign; -} - -void chemical::find_T() -{ - if(n()>EPS && P>EPS) - { - thermo->set(P,T,v,n()); - T=thermo->T(); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot find T of "<<name<<".\n"; - logf.close(); - warning++; - } - check_error(); -} - -void chemical::find_P() -{ - if(n()>EPS && T>EPS) - { - thermo->set(P,T,v,n()); - P=thermo->P(); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot find P of "<<name<<".\n"; - logf.close(); - warning++; - } - check_error(); -} - -void chemical::find_v() -{ - - if(state==0) v=m/rho_liq; - if(state==1 && P>EPS && T>EPS && m>EPS) - { - thermo->set(P,T,v,n()); - v=thermo->v(); - } -} - -void chemical::find_state() -{ - ofstream logf; - if (T>Tc || P>Pc) state = 1; //T or P is bigger than Tc or Pc - if (T<=Tm) //T is smaller than melting point - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- The chemical "<<name<<" is solid.\n"; - logf.close(); - warning++; - } - check_error(); - if (T<Tboil(P)) state=0; - else state=1; -} +#include "chemical.hpp" +using namespace std; + +void chemical::check_error ( void ) { + if (error>MAX_ERROR) { + cout << "ERROR 2\n\n"; + exit(0); + } + if (warning>MAX_WARNING) { + cout << "ERROR 3\n\n"; + exit(0); + } +} + +// copy-constr. : +chemical::chemical ( const chemical & chem ) { + + CAS = chem.CAS; + name = chem.name; + M = chem.M; + + state = chem.state; + Tm = chem.Tm; + Tb = chem.Tb; + Tc = chem.Tc; + Pc = chem.Pc; + Ho = chem.Ho; + rho_liq = chem.rho_liq; + dHvap = chem.dHvap; + + mu_param[0] = chem.mu_param[0]; + mu_param[1] = chem.mu_param[1]; + Cp_param[0] = chem.Cp_param[0]; + Cp_param[1] = chem.Cp_param[1]; + Cp_param[2] = chem.Cp_param[2]; + Cp_param[3] = chem.Cp_param[3]; + Cp_liq = chem.Cp_liq; + Psat_param[0] = chem.Psat_param[0]; + Psat_param[1] = chem.Psat_param[1]; + Psat_param[2] = chem.Psat_param[2]; + + thermo = new thermolib(); + thermo->send(Pc,Tc, omega()); + + P = chem.P; + T = chem.T; + m = chem.m; + v = chem.v; + + warning = chem.warning; + error = chem.error; + tmp = chem.tmp; +} + +chemical::chemical ( const string & chem_name ) { + + CAS = chem_name; + + // C. Tribes add initialization for more robustness (variables may be initialized uncorrectly dependent on the execution) + P=T=m=v=0.0; + + // 1/12 : + if (CAS=="100-41-4") { + name = "ethylbenzene"; + M = 106.17; + state = 0; + Tm = 178.2; + Tb = 409.3; + Tc = 617.1; + Pc = 35.6; + Ho = 29.79; + rho_liq = 867.0; + dHvap = 35.56; + mu_param[0] = 472.82; + mu_param[1] = 264.22; + Cp_param[0] = -43.069; + Cp_param[1] = 7.067e-01; + Cp_param[2] = -4.807e-04; + Cp_param[3] = 1.30e-07; + Cp_liq = 190.23; + Psat_param[0] = 16.0195; + Psat_param[1] = 3279.47; + Psat_param[2] = -59.95; + } + + // 2/12 : + else if (CAS=="1333-74-0") { + name = "hydrogen"; + M = 2.02; + state = 1; + Tm = 14.0; + Tb = 20.4; + Tc = 33.2; + Pc = 12.8; + Ho = 0.0; + rho_liq = 71.0; + dHvap = 0.9; + mu_param[0] = 13.82; + mu_param[1] = 5.39; + Cp_param[0] = 27.124; + Cp_param[1] = 9.267e-03; + Cp_param[2] = -1.380e-05; + Cp_param[3] = 7.64e-09; + Cp_liq = 0.0; + Psat_param[0] = 13.6333; + Psat_param[1] = 164.90; + Psat_param[2] = 3.19; + } + + // 3/12 : + else if (CAS=="108-88-3") { + name = "toluene"; + M =92.14; + state = 0; + Tm = 178.0; + Tb = 383.8; + Tc = 591.7; + Pc = 40.6; + Ho = 50.0; + rho_liq = 867; + dHvap = 33.18; + mu_param[0] = 467.33; + mu_param[1] = 255.24; + Cp_param[0] = -24.338; + Cp_param[1] = 5.121e-1; + Cp_param[2] = -2.763e-4; + Cp_param[3] = 4.91e-8; + Cp_liq = 159.85; + Psat_param[0] = 16.0137; + Psat_param[1] = 3096.52; + Psat_param[2] = -53.67; + } + + // 4/12 : + else if (CAS=="74-82-8") { + name = "methane"; + M =16.04; + state =1; + Tm = 90.7; + Tb = 111.7; + Tc = 190.6; + Pc = 45.4; + Ho = -74.85; + rho_liq = 425; + dHvap = 8.18; + mu_param[0] = 114.14; + mu_param[1] = 57.60; + Cp_param[0] = 19.238; + Cp_param[1] = 5.209e-02; + Cp_param[2] = 1.197e-05; + Cp_param[3] = -1.13e-08; + Cp_liq = 0.0; + Psat_param[0] = 15.2243; + Psat_param[1] = 897.84; + Psat_param[2] = -7.16; + } + + // 5/12 : + else if (CAS=="71-43-2") { + name = "benzene"; + M = 78.11; + state = 0; + Tm = 278.7; + Tb = 353.3; + Tc = 562.1; + Pc = 48.3; + Ho = 82.93; + rho_liq = 885; + dHvap = 30.76; + mu_param[0] = 545.64; + mu_param[1] = 265.24; + Cp_param[0] = 33.894; + Cp_param[1] = 4.74e-1; + Cp_param[2] = -3.015e-4; + Cp_param[3] = 7.13e-8; + Cp_liq = 116.03; + Psat_param[0] = 15.9008; + Psat_param[1] = 2788.51; + Psat_param[2] = -52.36; + } + + // 6/12 : + else if (CAS=="74-85-1") { + name = "ethylene"; + M = 28.05; + state =1; + Tm = 104.0; + Tb = 169.4; + Tc = 282.4; + Pc = 49.7; + Ho =52.3; + rho_liq = 577.0; + dHvap = 13.54; + mu_param[0] = 168.98; + mu_param[1] = 93.94; + Cp_param[0] = 3.803; + Cp_param[1] = 1.565e-01; + Cp_param[2] = -8.343e-05; + Cp_param[3] = 1.75e-08; + Cp_liq = 0.0; + Psat_param[0] =15.5368; + Psat_param[1] = 1347.01; + Psat_param[2] = -18.15; + } + + // 7/12 : + else if (CAS=="100-42-5") { + name = "styrene"; + M =104.15; + state = 0; + Tm = 242.5; + Tb = 418.3; + Tc =647.0; + Pc =39.4; + Ho =147.36; + rho_liq =906.0; + dHvap = 36.82; + mu_param[0] = 528.64; + mu_param[1] = 276.71; + Cp_param[0] =-28.229; + Cp_param[1] =6.155e-01; + Cp_param[2] = -4.020e-04; + Cp_param[3] = 9.93e-08; + Cp_liq =166.13; + Psat_param[0] = 16.0193; + Psat_param[1] = 3328.57; + Psat_param[2] =-63.72; + } + + // 8/12 : + else if (CAS=="7782-44-7") { + name = "oxygen"; + M = 32.00; + state = 1; + Tm = 54.4; + Tb = 90.2; + Tc = 154.6; + Pc = 49.8; + Ho =0.0 ; + rho_liq =1149.1 ; + dHvap =6.82 ; + mu_param[0] = 85.68; + mu_param[1] = 51.50; + Cp_param[0] = 28.087; + Cp_param[1] = -3.678e-06 ; + Cp_param[2] = 1.745e-05; + Cp_param[3] = -1.06e-08; + Cp_liq =0.0 ; + Psat_param[0] = 15.4075; + Psat_param[1] = 734.55 ; + Psat_param[2] =-6.45 ; + } + + // 9/12 : + else if (CAS=="7727-37-9") { + name = "nitrogen"; + M = 28.01; + state = 1; + Tm = 63.3; + Tb = 77.4; + Tc = 126.2; + Pc = 33.5; + Ho = 0.0; + rho_liq = 804.0; + dHvap = 5.58; + mu_param[0] = 90.30; + mu_param[1] = 46.41; + Cp_param[0] = 31.128; + Cp_param[1] = -1.356e-02 ; + Cp_param[2] = 2.678e-05; + Cp_param[3] =-1.17e-08 ; + Cp_liq = 0.0; + Psat_param[0] = 14.9342; + Psat_param[1] = 588.72; + Psat_param[2] = -6.60; + } + + // 10/12 : + else if (CAS=="124-38-9") { + name = "carbon-dioxide"; + M =44.01; + state = 1; + Tm = 216.6; + Tb = 194.4; + Tc = 304.2; + Pc = 72.8; + Ho = -393.41; + rho_liq = 777.0; + dHvap = 17.15; + mu_param[0] = 578.08; + mu_param[1] = 185.24 ; + Cp_param[0] = 19.782; + Cp_param[1] = 7.339e-02; + Cp_param[2] = -5.598e-05; + Cp_param[3] = 1.71e-08; + Cp_liq = 0.0; + Psat_param[0] = 22.5898; + Psat_param[1] =3103.39 ; + Psat_param[2] = -0.16; + } + + // 11/12 : + else if (CAS=="7732-18-5") { + name = "water"; + M =18.02; + state = 0; + Tm = 273.15; + Tb = 373.15; + Tc = 647.4; + Pc = 217.6; + Ho = -241.83; + rho_liq = 998 ; + dHvap = 40.66; + mu_param[0] = 658.25; + mu_param[1] = 283.16; + Cp_param[0] = 32.220; + Cp_param[1] = 1.923e-03 ; + Cp_param[2] = 1.055e-05; + Cp_param[3] = -3.59e-09; + Cp_liq = 75.24; + Psat_param[0] = 18.3036; + Psat_param[1] = 3816.44; + Psat_param[2] = -46.13; + } + + // 12/12 : + else if (CAS=="64-17-5") { + name = "ethanol"; + M =46.07; + state =0 ; + Tm =159.1 ; + Tb = 351.5; + Tc = 516.2; + Pc =63.0 ; + Ho = -234.8; + rho_liq = 789.0; + dHvap =38.74 ; + mu_param[0] = 686.64; + mu_param[1] = 300.88; + Cp_param[0] = 9.008; + Cp_param[1] = 2.139e-01; + Cp_param[2] = -8.385e-05 ; + Cp_param[3] = 1.37e-09; + Cp_liq = 2.22; + Psat_param[0] = 18.9119; + Psat_param[1] = 3803.98; + Psat_param[2] = -41.68; + } + + else { + cout << "ERROR 1\n\n"; + exit(0); + } + + thermo = new thermolib(); + thermo->send(Pc,Tc, omega()); + + +} + +double chemical::K() +{ + thermo->set(P,T,v,n()); + return thermo->K(); +} + +double chemical::mu() +{ + // Returns the fluid's viscosity in Pa.s + if (Tm<=T && T<=Tboil(P)) + return pow(10,(mu_param[0]*(1.0/T-1.0/mu_param[1])-3)); + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot compute viscosity of "<<name<<".\n"; + logf.close(); + warning++; + check_error(); + return 1.0; + } +} + +double chemical::rho() +{ + // Returns the fluid's density in kg/m3, wether it's liquid or gas + if(state==0) tmp= rho_liq; + if(state==1) + { + find_v(); + if (v>EPS) tmp= m/v; + else tmp= 0.0; + } + return tmp; +} + +double chemical::Cp() { + // cout<<endl<<"Cp de "<<name<<" a "<<T; + // Returns the fluid's Cp in J/mol.K + if(state==0) { + + // tmp = Cp_liq; // BUG : boucle infinie !!! + return Cp_liq; // SEB + + } + if(state==1 || T>Tboil(P)) { + tmp=0; + for (int i=0;i<4;i++) + tmp+=Cp_param[i]*pow(T,i); + } + else { + T=Tb; + + tmp = Cp(); // ici boucle infinie si state==0 !!! + + } + return tmp; +} + +double chemical::Cp(bool q) +{ + // Returns the fluid's Cp in J/mol.K + if(q==0) tmp=Cp_liq; + if(q==1) + { + tmp=0; + for (int i=0;i<4;i++) tmp+=Cp_param[i]*pow(T,i); + } + return tmp; +} + +double chemical::Psat() +{ + // Returns the fluid's vapor pressure in atm, using Antoine's equation + if(Tm<=T && T<=Tc) + return (exp(Psat_param[0]-Psat_param[1]/(T+Psat_param[2]))/760.01); + else + { + + return Psat(Tb); + } +} +double chemical::Psat(double t) +{ + // Returns the fluid's vapor pressure in atm, using Antoine's equation + return (exp(Psat_param[0]-Psat_param[1]/(t+Psat_param[2]))/760.01); +} + +double chemical::dH(double T1,double T2, double pres) +{ + //Enthalpy variation in kJ/mol. Does not affect any attributes of current object. + double energy=0, TT=Tboil(pres), vap=Hvap(TT); + int sign=1, i; + if (T2<T1) {sign = -1; energy=T1; T1=T2; T2=energy; energy=0;} + if (T1==T2) energy = 0.0; + if (T2<TT) energy = Cp_liq*(T2-T1)/1000; + if (TT<T1) for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(T1,i))/i/1000; + if(T1<=TT && TT<=T2) + { + energy=Cp_liq*(TT-T1)/1000; + energy+=vap; + for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(TT,i))/i/1000; + } + return energy*sign; +} + +void chemical::find_T() +{ + if(n()>EPS && P>EPS) + { + thermo->set(P,T,v,n()); + T=thermo->T(); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot find T of "<<name<<".\n"; + logf.close(); + warning++; + } + check_error(); +} + +void chemical::find_P() +{ + if(n()>EPS && T>EPS) + { + thermo->set(P,T,v,n()); + P=thermo->P(); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot find P of "<<name<<".\n"; + logf.close(); + warning++; + } + check_error(); +} + +void chemical::find_v() +{ + + if(state==0) v=m/rho_liq; + if(state==1 && P>EPS && T>EPS && m>EPS) + { + thermo->set(P,T,v,n()); + v=thermo->v(); + } +} + +void chemical::find_state() +{ + ofstream logf; + if (T>Tc || P>Pc) state = 1; //T or P is bigger than Tc or Pc + if (T<=Tm) //T is smaller than melting point + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- The chemical "<<name<<" is solid.\n"; + logf.close(); + warning++; + } + check_error(); + if (T<Tboil(P)) state=0; + else state=1; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.hpp index 71b28a956e9a81d399e78c777bb896601170e64c..344bd010651aa1f3e1229bc32e714752c22b628a 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/chemical.hpp @@ -1,48 +1,48 @@ -#ifndef CHEMICAL_H -#define CHEMICAL_H - -#include "thermolib.hpp" -#include <string> -using namespace std; - -class chemical -{ - public: - string name; - string CAS; - double M; //molar weight, in g/mol - bool state; //current state : 0=liquid 1=gas - double P, T, m, v; //current values : P in atm, T in K, m in kg/s, v in m3/s - - double n() {return 1000.0*m/M;} //mole flow in mol/s - double Hvap(double t) {return dHvap*pow((Tc-t)/(Tc-Tb),0.38);} //vaporization heat at specific T (Watson correlation) - double omega() {return ((-1.0)*log10(Psat(0.7*Tc)/Pc) -1.0);} //Pitzer acentric factor - double Tboil(double p) {return (Psat_param[1]/(Psat_param[0]-log(760.01*p))-Psat_param[2]);} //boiling tempararure at specific P - double mu(), rho(), Cp(), Cp(bool), Psat(), Psat(double); //T-dependant properties - double K(); //liquid-vapor equilibrium constant - double gamma(){return Cp(true)/(Cp(true)-8.3144);}//compressibility ratio =Cp/Cv - double dH(double, double, double); //enthalpy variation kJ/mol - void find_T(), find_P(), find_v(), find_state(); //for gases only - double Tm, Tb, Tc, Pc; //melting, boiling and critical temp. (K); critical pressure (atm) - double Ho;//standard formation heat in kJ/mol - - //private: - int warning, error; - void check_error(); - double dHvap, tmp; //vaporization heat (kJ/mol) - double mu_param[2], Cp_param[4], Cp_liq, Psat_param[3], rho_liq; //correlations parameters - thermolib *thermo; - - // public: - // chemical() {}; - - // copy-constr. : - chemical ( const chemical & chem ); - - chemical ( const string & chem_name ); //Contructor : initializes fields and reads CAS in the data file - void purge() {P=T=m=v=0.0; state=false;} - ~chemical(){delete thermo;}; -}; - -#endif - +#ifndef CHEMICAL_H +#define CHEMICAL_H + +#include "thermolib.hpp" +#include <string> +using namespace std; + +class chemical +{ + public: + string name; + string CAS; + double M; //molar weight, in g/mol + bool state; //current state : 0=liquid 1=gas + double P, T, m, v; //current values : P in atm, T in K, m in kg/s, v in m3/s + + double n() {return 1000.0*m/M;} //mole flow in mol/s + double Hvap(double t) {return dHvap*pow((Tc-t)/(Tc-Tb),0.38);} //vaporization heat at specific T (Watson correlation) + double omega() {return ((-1.0)*log10(Psat(0.7*Tc)/Pc) -1.0);} //Pitzer acentric factor + double Tboil(double p) {return (Psat_param[1]/(Psat_param[0]-log(760.01*p))-Psat_param[2]);} //boiling tempararure at specific P + double mu(), rho(), Cp(), Cp(bool), Psat(), Psat(double); //T-dependant properties + double K(); //liquid-vapor equilibrium constant + double gamma(){return Cp(true)/(Cp(true)-8.3144);}//compressibility ratio =Cp/Cv + double dH(double, double, double); //enthalpy variation kJ/mol + void find_T(), find_P(), find_v(), find_state(); //for gases only + double Tm, Tb, Tc, Pc; //melting, boiling and critical temp. (K); critical pressure (atm) + double Ho;//standard formation heat in kJ/mol + + //private: + int warning, error; + void check_error(); + double dHvap, tmp; //vaporization heat (kJ/mol) + double mu_param[2], Cp_param[4], Cp_liq, Psat_param[3], rho_liq; //correlations parameters + thermolib *thermo; + + // public: + // chemical() {}; + + // copy-constr. : + chemical ( const chemical & chem ); + + chemical ( const string & chem_name ); //Contructor : initializes fields and reads CAS in the data file + void purge() {P=T=m=v=0.0; state=false;} + ~chemical(){delete thermo;}; +}; + +#endif + diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.cpp index 85ab3e0b27bf8f9ab868d5792401fe63d4e0bbbd..f4a35c181e862b1a9b1eafdaf1190ff41abe19d8 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.cpp @@ -1,290 +1,290 @@ -#include "column.hpp" -using namespace std; - -column::column(stream* in, stream* out_B, stream* out_D) -{ - F = in; - B = out_B; - D = out_D; - L=new stream("columnL", F->nb, F->chem); - V=new stream("columnV", F->nb, F->chem); - flasher = new flash(F, L, V); - alpha_1 = new double[F->nb]; - alpha_f = new double[F->nb]; - alpha_N = new double[F->nb]; - alpha_m = new double[F->nb]; - T_d=0; T_b=0; T_f=F->T; -// for(i=0;i<F->nb;i++) -// if(F->chem[i]->Tc<F->T && F->chem[i]->m>EPS) -// { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Presence of gas in column.\n"; -// logf.close(); -// i=F->nb; -// } -} - -column::~column() -{ - delete L; delete V; delete flasher; - delete [] alpha_1; - delete [] alpha_f; - delete [] alpha_N; - delete [] alpha_m; -} - -void column::set(double p, int lk, double xd, int hk, double xb) -{ - P=p; - HK=hk-1; x_B=xb; - LK=lk-1; x_D=xd; - //logf.open(MESSAGES, ios::app); - // F->write(); system("pause"); - // if (F->chem[LK]->m<EPS) logf<<" ==> Error <== Flow of light key in column "<<name<<" is zero.\n"; -// if (F->chem[HK]->m<EPS) logf<<" ==> Error <== Flow of heavy key in column "<<name<<" is zero.\n"; - //logf.close(); -} - -bool column::solve() -{ - - OK=true; - // B->thermo=F->thermo; D->thermo=F->thermo; - //flash once the feed stream - - - - flasher->set(P,F->T); - - flasher->adiabatic(); - - - T_f=flasher->T; - L->set(P, T_f); V->set(P, T_f); - // L->write(); V->write(); TOTO - //check if a column is needed; if not, bypass block - if(F->chem[LK]->n()/F->n()<0.001) OK=false; - if(F->chem[HK]->n()/F->n()<0.001) OK=false; - if(!OK) - return false; -// { -// strcpy(filename, B->name); *B=*L; B->set(filename); B->write(); -// strcpy(filename, D->name); *D=*V; D->set(filename); D->write(); -// } - else - { - - - - - - //apply the FUG method - first_split(); - Nmin = Fenske(); - N=Nmin+1; - while (fabs(N-Nmin)>0.1) - { - N=Nmin; - D->set(P, T_f); T_d=D->bp; - B->set(P, T_f); T_b=B->bp; - set_alpha(); - distribute(); - Nmin = Fenske(); - if (Nmin<1) Nmin=1; - } - D->set(P, T_d); - B->set(P, T_b); - if(fabs(Nmin)<=MIN_PLATES || fabs(Nmin)>MAX_PLATES) OK=false; - else - { - Rmin = Underwood(); - if(Rmin>100) Rmin=100; - if(L->chem[HK]->m+L->chem[LK]->m<EPS) Rmin=10.0; - if (Nmin<5) Ract = 1.5*Rmin; - if (5<Nmin && Nmin<15) Ract = 1.3*Rmin; - if (15<=Nmin) Ract = 1.1*Rmin; - N = Gilliland(); - feed = Kirkbride(); - condense(); - reboil(); - } - // B->write(); TOTO - // D->write(); TOTO - } - return OK; -} - -void column::first_split() -{ - B->purge(); D->purge(); - set_alpha(); - //Check if LK is really lighter than HK - if (alpha_m[LK]<1) - { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Swapping keys in column "<<name<<".\n"; -// logf.close(); - feed=LK; LK=HK; HK=feed; set_alpha(); - } - for(i=0;i<F->nb;i++) - { - if (i!=LK && i!=HK && F->chem[i]->m>EPS) - { - if(alpha_f[i] > alpha_f[LK]) //volatile - { - D->chem[i]->m = (alpha_f[i]-alpha_f[LK])/alpha_f[i]*F->chem[i]->m; - D->m += D->chem[i]->m; - B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; - B->m+=B->chem[i]->m; - } - if(alpha_f[i] < 1) //not volatile - { - B->chem[i]->m = (alpha_f[HK]-alpha_f[i])/alpha_f[i]*F->chem[i]->m; - B->m += B->chem[i]->m; - D->chem[i]->m = F->chem[i]->m-B->chem[i]->m; - D->m+=D->chem[i]->m; - } - if(1 <= alpha_f[i] && alpha_f[i]<=alpha_f[LK]) //ambiguous volatility - { - D->chem[i]->m = (alpha_f[i]-1)/(alpha_f[LK]-1)*F->chem[i]->m; - B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; - D->m+=D->chem[i]->m; - B->m+=B->chem[i]->m; - } - } - } - D->chem[HK]->m = D->n()*x_D/(1-x_D)*D->chem[HK]->M/1000.0; - if(D->chem[HK]->m<EPS) D->chem[HK]->m=0.01*F->chem[HK]->m; - B->chem[LK]->m = B->n()*x_B/(1-x_B)*B->chem[LK]->M/1000.0; - if(B->chem[LK]->m<EPS) B->chem[LK]->m=0.01*F->chem[LK]->m; - B->chem[HK]->m = F->chem[HK]->m - D->chem[HK]->m; - D->chem[LK]->m = F->chem[LK]->m - B->chem[LK]->m; - D->m += (D->chem[LK]->m + D->chem[HK]->m); - B->m += (B->chem[LK]->m + B->chem[HK]->m); -} -void column::distribute() -{ - D->m=0; B->m=0; - for(i=0;i<F->nb;i++) - { - if (i!=LK && i!=HK && F->chem[i]->m>EPS) - { - if(alpha_m[i] > 1) //volatile and ambiguous - { - B->chem[i]->m = F->chem[i]->m/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); - D->chem[i]->m = F->chem[i]->m - B->chem[i]->m; - } - if(alpha_m[i] <= 1) //not volatile - { - D->chem[i]->m = F->chem[i]->m*(D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin))/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); - B->chem[i]->m = F->chem[i]->m - D->chem[i]->m; - } - D->m+=D->chem[i]->m; - B->m+=B->chem[i]->m; - } - } - D->m += (D->chem[LK]->m + D->chem[HK]->m); - B->m += (B->chem[LK]->m + B->chem[HK]->m); -} - -void column::set_alpha() -{ - for(i=0;i<F->nb; i++) - { - if (T_b>EPS && F->chem[i]->m>EPS) alpha_1[i] = F->chem[i]->Psat(T_b)/F->chem[HK]->Psat(T_b); - else alpha_1[i]=0; - if (T_d>EPS&& F->chem[i]->m>EPS) alpha_N[i] = F->chem[i]->Psat(T_d)/F->chem[HK]->Psat(T_d); - else alpha_N[i]=0; - if (T_f>EPS&& F->chem[i]->m>EPS) alpha_f[i] = F->chem[i]->Psat(T_f)/F->chem[HK]->Psat(T_f); - else alpha_f[i]=0; - alpha_m[i] = pow(alpha_1[i]*alpha_f[i]*alpha_N[i], 1.0/3.0); - } - for(i=0;i<F->nb;i++) if(alpha_m[i]<EPS&& F->chem[i]->m>EPS) alpha_m[i] = alpha_f[i]; -} - -void column::reboil() -{ - Q_reboil = 0.0; - for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) - { - Q_reboil += B->chem[i]->Cp(false)*(T_b-T_f)*B->chem[i]->n()/1000.0; //energy to go from input to bottoms T - Q_reboil += D->chem[i]->Cp(false)*(T_f-T_d)*D->chem[i]->n()/1000.0; //energy to go from input to tops T - } - Q_reboil += Q_condens; -} - -void column::condense() -{ - Q_condens = 0.0; - for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) - { - Q_condens += D->chem[i]->Hvap(T_d)*(1+Ract)*D->chem[i]->n(); - } -} - -void column::write() -{ - cout << setprecision(11); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout <<"\t>> "<<name; - cout <<endl<<"\t>> stream in: "<<F->name; - cout <<endl<<"\t>> streams out: "<<B->name<<" (bot.) "<<D->name<<" (top.)"; - cout <<endl<<"\t>> P = "<<P<<" atm, T(0) = "<<T_b<<", T("<<feed<<") = "<<T_f<<", T("<<int(N)<<") = "<<T_d<<" K"; - cout <<endl<<"\t>> Number of stages: "<<int(N)<<" (feeding at stage "<<feed<<")"; - cout <<endl<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(5)<<"\t>> LK purity = "<<D->chem[LK]->n()/D->n()<<" HK purity = "<<B->chem[HK]->n()/B->n(); - cout <<endl<<"\t>> Reboiler duty: "<<Q_reboil<<" kW Condenser duty: "<<(-1)*Q_condens<<" kW"; - cout << "\n\tEND\n\n"; - cost(); water(); power(); -} - -double column::get_cost() -{ - //cost of vessel - vol=(0.45*N)*(pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); - if(vol<0.3) vol=0.3; if(vol>520)vol=520; - money = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); - money = pow(10, money); - P= (P-1)*101.325/100; - diam=sqrt(4.0*vol/pi/N/0.45); - vol=(P+1)*diam/(317.46*(850-0.6*(P+1)))+0.0315; - money *=(2.25+ 1.82*vol*2.2); - //cost of trays - vol = (pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); - diam = 2.9949+0.4465*log10(vol)+0.3961*pow(log10(vol),2); - money+=1.5*pow(10, diam); - //cost of reboiler U=5250W/m2.K - vol=fabs(Q_reboil)/0.85/5.25/15.0; - if(vol<10) vol=10; if(vol>100) vol=100; - vol = 4.4646-0.5277*log10(vol)+0.3955*pow(log10(vol),2); - money += (1.63+1.66*2.5)*pow(10, vol); - //cost of condenser U=1850W/m2.K - vol=fabs(Q_condens)/0.85/1.85/(0.5*(T_d-298)); - if(vol<1) vol=1; if(vol>100) vol=100; - vol = 3.9912+0.0668*log10(vol)+0.243*pow(log10(vol),2); - money += (1.74+1.55*2.5)*pow(10, vol); - money = money*MS_YEAR/MS_2001; - return money; -} - - -void column::cost() -{ - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} -void column::power() -{ - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - money =(Q_reboil/0.85-Q_condens); - cout << "\t>>" << money; - cout << "\n\tEND\n\n"; -} -void column::water() -{ - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - money = (fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298))); - cout << "\t>>" << money; - cout << "\n\tEND\n\n"; -} +#include "column.hpp" +using namespace std; + +column::column(stream* in, stream* out_B, stream* out_D) +{ + F = in; + B = out_B; + D = out_D; + L=new stream("columnL", F->nb, F->chem); + V=new stream("columnV", F->nb, F->chem); + flasher = new flash(F, L, V); + alpha_1 = new double[F->nb]; + alpha_f = new double[F->nb]; + alpha_N = new double[F->nb]; + alpha_m = new double[F->nb]; + T_d=0; T_b=0; T_f=F->T; +// for(i=0;i<F->nb;i++) +// if(F->chem[i]->Tc<F->T && F->chem[i]->m>EPS) +// { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Presence of gas in column.\n"; +// logf.close(); +// i=F->nb; +// } +} + +column::~column() +{ + delete L; delete V; delete flasher; + delete [] alpha_1; + delete [] alpha_f; + delete [] alpha_N; + delete [] alpha_m; +} + +void column::set(double p, int lk, double xd, int hk, double xb) +{ + P=p; + HK=hk-1; x_B=xb; + LK=lk-1; x_D=xd; + //logf.open(MESSAGES, ios::app); + // F->write(); system("pause"); + // if (F->chem[LK]->m<EPS) logf<<" ==> Error <== Flow of light key in column "<<name<<" is zero.\n"; +// if (F->chem[HK]->m<EPS) logf<<" ==> Error <== Flow of heavy key in column "<<name<<" is zero.\n"; + //logf.close(); +} + +bool column::solve() +{ + + OK=true; + // B->thermo=F->thermo; D->thermo=F->thermo; + //flash once the feed stream + + + + flasher->set(P,F->T); + + flasher->adiabatic(); + + + T_f=flasher->T; + L->set(P, T_f); V->set(P, T_f); + // L->write(); V->write(); TOTO + //check if a column is needed; if not, bypass block + if(F->chem[LK]->n()/F->n()<0.001) OK=false; + if(F->chem[HK]->n()/F->n()<0.001) OK=false; + if(!OK) + return false; +// { +// strcpy(filename, B->name); *B=*L; B->set(filename); B->write(); +// strcpy(filename, D->name); *D=*V; D->set(filename); D->write(); +// } + else + { + + + + + + //apply the FUG method + first_split(); + Nmin = Fenske(); + N=Nmin+1; + while (fabs(N-Nmin)>0.1) + { + N=Nmin; + D->set(P, T_f); T_d=D->bp; + B->set(P, T_f); T_b=B->bp; + set_alpha(); + distribute(); + Nmin = Fenske(); + if (Nmin<1) Nmin=1; + } + D->set(P, T_d); + B->set(P, T_b); + if(fabs(Nmin)<=MIN_PLATES || fabs(Nmin)>MAX_PLATES) OK=false; + else + { + Rmin = Underwood(); + if(Rmin>100) Rmin=100; + if(L->chem[HK]->m+L->chem[LK]->m<EPS) Rmin=10.0; + if (Nmin<5) Ract = 1.5*Rmin; + if (5<Nmin && Nmin<15) Ract = 1.3*Rmin; + if (15<=Nmin) Ract = 1.1*Rmin; + N = Gilliland(); + feed = Kirkbride(); + condense(); + reboil(); + } + // B->write(); TOTO + // D->write(); TOTO + } + return OK; +} + +void column::first_split() +{ + B->purge(); D->purge(); + set_alpha(); + //Check if LK is really lighter than HK + if (alpha_m[LK]<1) + { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Swapping keys in column "<<name<<".\n"; +// logf.close(); + feed=LK; LK=HK; HK=feed; set_alpha(); + } + for(i=0;i<F->nb;i++) + { + if (i!=LK && i!=HK && F->chem[i]->m>EPS) + { + if(alpha_f[i] > alpha_f[LK]) //volatile + { + D->chem[i]->m = (alpha_f[i]-alpha_f[LK])/alpha_f[i]*F->chem[i]->m; + D->m += D->chem[i]->m; + B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; + B->m+=B->chem[i]->m; + } + if(alpha_f[i] < 1) //not volatile + { + B->chem[i]->m = (alpha_f[HK]-alpha_f[i])/alpha_f[i]*F->chem[i]->m; + B->m += B->chem[i]->m; + D->chem[i]->m = F->chem[i]->m-B->chem[i]->m; + D->m+=D->chem[i]->m; + } + if(1 <= alpha_f[i] && alpha_f[i]<=alpha_f[LK]) //ambiguous volatility + { + D->chem[i]->m = (alpha_f[i]-1)/(alpha_f[LK]-1)*F->chem[i]->m; + B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; + D->m+=D->chem[i]->m; + B->m+=B->chem[i]->m; + } + } + } + D->chem[HK]->m = D->n()*x_D/(1-x_D)*D->chem[HK]->M/1000.0; + if(D->chem[HK]->m<EPS) D->chem[HK]->m=0.01*F->chem[HK]->m; + B->chem[LK]->m = B->n()*x_B/(1-x_B)*B->chem[LK]->M/1000.0; + if(B->chem[LK]->m<EPS) B->chem[LK]->m=0.01*F->chem[LK]->m; + B->chem[HK]->m = F->chem[HK]->m - D->chem[HK]->m; + D->chem[LK]->m = F->chem[LK]->m - B->chem[LK]->m; + D->m += (D->chem[LK]->m + D->chem[HK]->m); + B->m += (B->chem[LK]->m + B->chem[HK]->m); +} +void column::distribute() +{ + D->m=0; B->m=0; + for(i=0;i<F->nb;i++) + { + if (i!=LK && i!=HK && F->chem[i]->m>EPS) + { + if(alpha_m[i] > 1) //volatile and ambiguous + { + B->chem[i]->m = F->chem[i]->m/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); + D->chem[i]->m = F->chem[i]->m - B->chem[i]->m; + } + if(alpha_m[i] <= 1) //not volatile + { + D->chem[i]->m = F->chem[i]->m*(D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin))/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); + B->chem[i]->m = F->chem[i]->m - D->chem[i]->m; + } + D->m+=D->chem[i]->m; + B->m+=B->chem[i]->m; + } + } + D->m += (D->chem[LK]->m + D->chem[HK]->m); + B->m += (B->chem[LK]->m + B->chem[HK]->m); +} + +void column::set_alpha() +{ + for(i=0;i<F->nb; i++) + { + if (T_b>EPS && F->chem[i]->m>EPS) alpha_1[i] = F->chem[i]->Psat(T_b)/F->chem[HK]->Psat(T_b); + else alpha_1[i]=0; + if (T_d>EPS&& F->chem[i]->m>EPS) alpha_N[i] = F->chem[i]->Psat(T_d)/F->chem[HK]->Psat(T_d); + else alpha_N[i]=0; + if (T_f>EPS&& F->chem[i]->m>EPS) alpha_f[i] = F->chem[i]->Psat(T_f)/F->chem[HK]->Psat(T_f); + else alpha_f[i]=0; + alpha_m[i] = pow(alpha_1[i]*alpha_f[i]*alpha_N[i], 1.0/3.0); + } + for(i=0;i<F->nb;i++) if(alpha_m[i]<EPS&& F->chem[i]->m>EPS) alpha_m[i] = alpha_f[i]; +} + +void column::reboil() +{ + Q_reboil = 0.0; + for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) + { + Q_reboil += B->chem[i]->Cp(false)*(T_b-T_f)*B->chem[i]->n()/1000.0; //energy to go from input to bottoms T + Q_reboil += D->chem[i]->Cp(false)*(T_f-T_d)*D->chem[i]->n()/1000.0; //energy to go from input to tops T + } + Q_reboil += Q_condens; +} + +void column::condense() +{ + Q_condens = 0.0; + for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) + { + Q_condens += D->chem[i]->Hvap(T_d)*(1+Ract)*D->chem[i]->n(); + } +} + +void column::write() +{ + cout << setprecision(11); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout <<"\t>> "<<name; + cout <<endl<<"\t>> stream in: "<<F->name; + cout <<endl<<"\t>> streams out: "<<B->name<<" (bot.) "<<D->name<<" (top.)"; + cout <<endl<<"\t>> P = "<<P<<" atm, T(0) = "<<T_b<<", T("<<feed<<") = "<<T_f<<", T("<<int(N)<<") = "<<T_d<<" K"; + cout <<endl<<"\t>> Number of stages: "<<int(N)<<" (feeding at stage "<<feed<<")"; + cout <<endl<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(5)<<"\t>> LK purity = "<<D->chem[LK]->n()/D->n()<<" HK purity = "<<B->chem[HK]->n()/B->n(); + cout <<endl<<"\t>> Reboiler duty: "<<Q_reboil<<" kW Condenser duty: "<<(-1)*Q_condens<<" kW"; + cout << "\n\tEND\n\n"; + cost(); water(); power(); +} + +double column::get_cost() +{ + //cost of vessel + vol=(0.45*N)*(pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); + if(vol<0.3) vol=0.3; if(vol>520)vol=520; + money = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); + money = pow(10, money); + P= (P-1)*101.325/100; + diam=sqrt(4.0*vol/pi/N/0.45); + vol=(P+1)*diam/(317.46*(850-0.6*(P+1)))+0.0315; + money *=(2.25+ 1.82*vol*2.2); + //cost of trays + vol = (pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); + diam = 2.9949+0.4465*log10(vol)+0.3961*pow(log10(vol),2); + money+=1.5*pow(10, diam); + //cost of reboiler U=5250W/m2.K + vol=fabs(Q_reboil)/0.85/5.25/15.0; + if(vol<10) vol=10; if(vol>100) vol=100; + vol = 4.4646-0.5277*log10(vol)+0.3955*pow(log10(vol),2); + money += (1.63+1.66*2.5)*pow(10, vol); + //cost of condenser U=1850W/m2.K + vol=fabs(Q_condens)/0.85/1.85/(0.5*(T_d-298)); + if(vol<1) vol=1; if(vol>100) vol=100; + vol = 3.9912+0.0668*log10(vol)+0.243*pow(log10(vol),2); + money += (1.74+1.55*2.5)*pow(10, vol); + money = money*MS_YEAR/MS_2001; + return money; +} + + +void column::cost() +{ + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} +void column::power() +{ + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + money =(Q_reboil/0.85-Q_condens); + cout << "\t>>" << money; + cout << "\n\tEND\n\n"; +} +void column::water() +{ + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + money = (fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298))); + cout << "\t>>" << money; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.hpp index cfd1daf16270b9ae30ba6500da2b75d7a576eb41..8dedb5a82bd85f4c6cf6b5d6a0dde55c8d56f299 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/column.hpp @@ -1,61 +1,61 @@ -/* -This unit simulates a distillation column, using -the FUG method. -(ref : Seader & Henley). - -Structure in the .process file: -column {name} {pressure} {index of input stream} {index of bottoms and heads} {indexes of light key and heavy key} {x_LK and x_HK} - -How to use: - 1- Call the constructor : col = new column(in, out_B, out_D); //in is F, out_B is B, out_D is D column(nb, chem_list) - set(in, out_B, out_D) - 2- Set operating conditions : col->set(pressure, LK, x_LK, HK, x_HK); // LK and HK and integer indexes, x_LK is the undesired mole fraction of LK in B, x_HK... - 3- Set the name : col->set(name); - 4- Run the model: col->solve(); -*/ -#ifndef COLUMN_H -#define COLUMN_H - -#include "flash.hpp" -using namespace std; - -class column -{ -private: - // ofstream results, logf; - bool OK; - string name; - stream *F, *B, *D, *L, *V ; - int LK, HK, feed, i; - double x_B, x_D, T_b, T_d, T_f, vol, money, diam; - double Nmin, N, Rmin, Ract, tmp, Q_condens, Q_reboil; - double *alpha_1, *alpha_f, *alpha_N, *alpha_m; - flash *flasher; - void set_alpha(), first_split(), distribute(), condense(), reboil(); - double Fenske() { return log10(D->chem[LK]->n()*B->chem[HK]->n()/D->chem[HK]->n()/B->chem[LK]->n())/log10(alpha_m[LK]);} - double Underwood() {return L->n()*(D->chem[LK]->n()/L->chem[LK]->n()-alpha_m[LK]*D->chem[HK]->n()/L->chem[HK]->n())/(D->n()*(alpha_m[LK]-1));} - double Gilliland(){N=(Ract-Rmin)/(Ract+1); tmp=1-exp((1+54.4*N)*(N-1)/(11+117.2*N)/pow(N, 0.5)); return (tmp+Nmin)/(1-tmp);} - int Kirkbride() {tmp=pow(B->n()*F->chem[HK]->n()*pow(x_B/x_D,2)/F->chem[LK]->n()/D->n(), 0.206); return int(N/(tmp+1));} - -public: - // column(){P=0.0;} - // column(int, chemical*); - // void set(stream*&, stream*&, stream*&); - column(stream*, stream*, stream*); - ~column(); - double P; - void set(double, int, double, int, double); - void set( const string & n ) { name = n; } - bool solve(); - void write(); - void cost(), water(), power(); - - double get_cost ( void ); - double get_power ( void ) const { return Q_reboil/0.85-Q_condens; } - - double get_water ( void ) const { return fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298)); } - - int get_N ( void ) const { return (int) N; } - -}; -#endif +/* +This unit simulates a distillation column, using +the FUG method. +(ref : Seader & Henley). + +Structure in the .process file: +column {name} {pressure} {index of input stream} {index of bottoms and heads} {indexes of light key and heavy key} {x_LK and x_HK} + +How to use: + 1- Call the constructor : col = new column(in, out_B, out_D); //in is F, out_B is B, out_D is D column(nb, chem_list) + set(in, out_B, out_D) + 2- Set operating conditions : col->set(pressure, LK, x_LK, HK, x_HK); // LK and HK and integer indexes, x_LK is the undesired mole fraction of LK in B, x_HK... + 3- Set the name : col->set(name); + 4- Run the model: col->solve(); +*/ +#ifndef COLUMN_H +#define COLUMN_H + +#include "flash.hpp" +using namespace std; + +class column +{ +private: + // ofstream results, logf; + bool OK; + string name; + stream *F, *B, *D, *L, *V ; + int LK, HK, feed, i; + double x_B, x_D, T_b, T_d, T_f, vol, money, diam; + double Nmin, N, Rmin, Ract, tmp, Q_condens, Q_reboil; + double *alpha_1, *alpha_f, *alpha_N, *alpha_m; + flash *flasher; + void set_alpha(), first_split(), distribute(), condense(), reboil(); + double Fenske() { return log10(D->chem[LK]->n()*B->chem[HK]->n()/D->chem[HK]->n()/B->chem[LK]->n())/log10(alpha_m[LK]);} + double Underwood() {return L->n()*(D->chem[LK]->n()/L->chem[LK]->n()-alpha_m[LK]*D->chem[HK]->n()/L->chem[HK]->n())/(D->n()*(alpha_m[LK]-1));} + double Gilliland(){N=(Ract-Rmin)/(Ract+1); tmp=1-exp((1+54.4*N)*(N-1)/(11+117.2*N)/pow(N, 0.5)); return (tmp+Nmin)/(1-tmp);} + int Kirkbride() {tmp=pow(B->n()*F->chem[HK]->n()*pow(x_B/x_D,2)/F->chem[LK]->n()/D->n(), 0.206); return int(N/(tmp+1));} + +public: + // column(){P=0.0;} + // column(int, chemical*); + // void set(stream*&, stream*&, stream*&); + column(stream*, stream*, stream*); + ~column(); + double P; + void set(double, int, double, int, double); + void set( const string & n ) { name = n; } + bool solve(); + void write(); + void cost(), water(), power(); + + double get_cost ( void ); + double get_power ( void ) const { return Q_reboil/0.85-Q_condens; } + + double get_water ( void ) const { return fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298)); } + + int get_N ( void ) const { return (int) N; } + +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.cpp index 83ad673825887cc0696981505fa884bb9c1a9c5d..0f30f1af32b99e3b5521dede45a6bde5aa7cbe57 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.cpp @@ -1,66 +1,66 @@ -#include "combrx.hpp" -using namespace std; - -combrx::combrx ( const string & cas ) { - - // combustion.prop : - // ----------------- - CAS = cas; - - if (CAS=="64-17-5") { - nO2 = 3; - nCO2 = 2; - nH2O = 3; - } - else if (CAS=="74-82-8") { - nO2 = 2; - nCO2 = 1; - nH2O = 2; - } - else if (CAS=="1333-74-0") { - nO2 = 0.5; - nCO2 = 0; - nH2O = 1; - } - else if (CAS=="100-42-5") { - nO2 = 10; - nCO2 = 8; - nH2O = 4; - } - else if (CAS=="74-85-1") { - nO2 = 3; - nCO2 = 2; - nH2O = 2; - } - else if (CAS=="108-88-3") { - nO2 = 9; - nCO2 = 7; - nH2O = 4; - } - else if (CAS=="100-41-4") { - nO2 = 10.5; - nCO2 = 8; - nH2O = 5; - } - else if (CAS=="71-43-2") { - nO2 = 7.5; - nCO2 = 6; - nH2O = 3; - } - else { - cout << "ERROR 21" << endl; - exit(0); - } - - COMB = new chemical(CAS); - O2 = new chemical("7782-44-7"); - N2 = new chemical("7727-37-9"); - CO2 = new chemical("124-38-9"); - H2O = new chemical("7732-18-5"); - Hro = CO2->Ho*nCO2 + nH2O*(H2O->Ho - H2O->dHvap) - COMB->Ho; - LFLo = -3420.0/Hro + 0.569e-3*Hro + 0.0538e-6*pow(Hro,2) + 1.8; - LFLo = LFLo/100.0; - UFLo = 0.0063*Hro + 0.567e-6*pow(Hro, 2) + 23.5; - UFLo = UFLo/100.0; - -} +#include "combrx.hpp" +using namespace std; + +combrx::combrx ( const string & cas ) { + + // combustion.prop : + // ----------------- + CAS = cas; + + if (CAS=="64-17-5") { + nO2 = 3; + nCO2 = 2; + nH2O = 3; + } + else if (CAS=="74-82-8") { + nO2 = 2; + nCO2 = 1; + nH2O = 2; + } + else if (CAS=="1333-74-0") { + nO2 = 0.5; + nCO2 = 0; + nH2O = 1; + } + else if (CAS=="100-42-5") { + nO2 = 10; + nCO2 = 8; + nH2O = 4; + } + else if (CAS=="74-85-1") { + nO2 = 3; + nCO2 = 2; + nH2O = 2; + } + else if (CAS=="108-88-3") { + nO2 = 9; + nCO2 = 7; + nH2O = 4; + } + else if (CAS=="100-41-4") { + nO2 = 10.5; + nCO2 = 8; + nH2O = 5; + } + else if (CAS=="71-43-2") { + nO2 = 7.5; + nCO2 = 6; + nH2O = 3; + } + else { + cout << "ERROR 21" << endl; + exit(0); + } + + COMB = new chemical(CAS); + O2 = new chemical("7782-44-7"); + N2 = new chemical("7727-37-9"); + CO2 = new chemical("124-38-9"); + H2O = new chemical("7732-18-5"); + Hro = CO2->Ho*nCO2 + nH2O*(H2O->Ho - H2O->dHvap) - COMB->Ho; + LFLo = -3420.0/Hro + 0.569e-3*Hro + 0.0538e-6*pow(Hro,2) + 1.8; + LFLo = LFLo/100.0; + UFLo = 0.0063*Hro + 0.567e-6*pow(Hro, 2) + 23.5; + UFLo = UFLo/100.0; + +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.hpp index b57e643762d2dbcc59dfdf040e503d580416b4ca..02e098bb96d4fbd6ece10fb1ef45e50803768425 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/combrx.hpp @@ -1,29 +1,29 @@ -#ifndef COMBRX_H -#define COMBRX_H -#include "chemical.hpp" -#include "defines.hpp" -using namespace std; - -class combrx { - -private : - ifstream data; - bool stop; - double nO2, nCO2, nH2O; - char tmp[41]; - string CAS; - chemical *H2O, *N2, *O2, *CO2, *COMB; - double LFLo, UFLo, Hro, sum; - -public: - combrx( const string & cas ); - double O2_flow() { return (O2->M*nO2/1000.0); } //theoritical O2 flow, in kg/mol of COMB - double N2_flow(){return (0.79*O2_flow()/0.21);} //theoritical N2 flow, in kg/mol of COMB - double CO2_flow() {return (nCO2*CO2->M/1000.0);} //theoritical CO2 flow, in kg/mol of COMB - double H2O_flow() {return (nH2O*H2O->M/1000.0);} //theoritical H2O flow, in kg/mol of COMB - double LFL(double P, double T) {sum=LFLo + 0.03139/Hro*(T-298); if(sum<EPS) return EPS; else return sum;} //in %vol - double UFL(double P, double T) {sum=UFLo - 0.03139/Hro*(T-298) + 0.206*(log10(0.101325*P)+1); if(sum>1) return (1-EPS); else return sum;} //in %vol - double Hcomb(double T) {return (nCO2*CO2->dH(298,T,1)+ nH2O*H2O->dH(298,T,1)-nO2*O2->dH(298,T,1)-COMB->dH(298,T,1)+Hro);} //in kJ/mol - ~combrx(){delete H2O; delete N2; delete O2; delete CO2; delete COMB;} -}; -#endif +#ifndef COMBRX_H +#define COMBRX_H +#include "chemical.hpp" +#include "defines.hpp" +using namespace std; + +class combrx { + +private : + ifstream data; + bool stop; + double nO2, nCO2, nH2O; + char tmp[41]; + string CAS; + chemical *H2O, *N2, *O2, *CO2, *COMB; + double LFLo, UFLo, Hro, sum; + +public: + combrx( const string & cas ); + double O2_flow() { return (O2->M*nO2/1000.0); } //theoritical O2 flow, in kg/mol of COMB + double N2_flow(){return (0.79*O2_flow()/0.21);} //theoritical N2 flow, in kg/mol of COMB + double CO2_flow() {return (nCO2*CO2->M/1000.0);} //theoritical CO2 flow, in kg/mol of COMB + double H2O_flow() {return (nH2O*H2O->M/1000.0);} //theoritical H2O flow, in kg/mol of COMB + double LFL(double P, double T) {sum=LFLo + 0.03139/Hro*(T-298); if(sum<EPS) return EPS; else return sum;} //in %vol + double UFL(double P, double T) {sum=UFLo - 0.03139/Hro*(T-298) + 0.206*(log10(0.101325*P)+1); if(sum>1) return (1-EPS); else return sum;} //in %vol + double Hcomb(double T) {return (nCO2*CO2->dH(298,T,1)+ nH2O*H2O->dH(298,T,1)-nO2*O2->dH(298,T,1)-COMB->dH(298,T,1)+Hro);} //in kJ/mol + ~combrx(){delete H2O; delete N2; delete O2; delete CO2; delete COMB;} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.cpp index 930ea8f58ac00b78b1aea1b6933d286eafb9bae0..027ad0e7dd937f8f0eb8a52d9401d2d00d78f2c2 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.cpp @@ -1,220 +1,220 @@ -#include "flash.hpp" -#include "bissection.cpp" -using namespace std; - -flash::flash ( stream * in , stream * out_L , stream * out_V ) { - F = in; - Fcopy = new stream("Fcopy", F->nb, F->chem); - Tin = F->T; - z = new double[F->nb]; - for ( i = 0 ; i < F->nb ; i++ ) - z[i] = F->chem[i]->n()/F->n(); - - L = out_L; - V = out_V; - success = true; - K = new double[F->nb]; - task=0; - solver = new bissection<flash>(); -} - -void flash::set(double p, double t) -{ - P=p; - T=t; - for (i=0;i<F->nb;i++) - { - if(F->chem[i]->Tc<T) K[i] = F->chem[i]->Psat(T)/P; - else K[i]=1; - } - F->set(P,T); -} - -bool flash::solve() -{ - L->purge(); - V->purge(); - f_x=F->quality(); - - if( 0.0 < f_x && f_x < 1.0) - { - - // TOTO - for ( i = 0 ; i < F->nb ; i++ ) { - if ( F->chem[i]->Tc < T ) { - F->m -= F->chem[i]->m; - F->chem[i]->m = 0; - } - } - - for ( i = 0 ; i < F->nb ; i++ ) - z[i] = F->chem[i]->n()/F->n(); - - solver->set(this, 0.0, 1.0); - - success=solver->run(); - - if (!success) - { -// if(task==0){ -// log.open(MESSAGES, ios::app); -// log<<" --> Warning <-- Solver of FLASH "<<name<<" did not converge.\n"; -// log.close();} - for (i=0;i<F->nb;i++) - { - if (T<F->chem[i]->Tc && T>F->chem[i]->Tboil(P)) {V->chem[i]->m=F->chem[i]->m; V->m+=V->chem[i]->m;} - if (T<F->chem[i]->Tc && T<=F->chem[i]->Tboil(P)) {L->chem[i]->m=F->chem[i]->m; L->m+=L->chem[i]->m;} - } - } - else - { - - V->m = x*F->n(); - L->m = F->n() - V->m; - //Distribute liquid components - for (i=0;i<L->nb;i++) - { - L->chem[i]->m = (L->m*z[i])/(1+x*(K[i]-1))*L->chem[i]->M/1000.0; - L->chem[i]->state=0; - } - - - L->m=0.0; for(i=0;i<L->nb;i++) L->m+=L->chem[i]->m; - //Distribute vapor components - for (i=0;i<V->nb;i++) - { - V->chem[i]->m = V->m*L->chem[i]->n()*K[i]/L->n()*V->chem[i]->M/1000.0; - V->chem[i]->state=1; - } - V->m=0.0; for(i=0;i<V->nb;i++) V->m+=V->chem[i]->m; - } - for(i=0;i<F->nb;i++) - if(F->chem[i]->Tc<T){V->chem[i]->m=Fcopy->chem[i]->m; V->m+=Fcopy->chem[i]->m;} - - } - else - { - /* if(task==0) - { - log.open("runtime\\messages.r", ios::app); - if (T<F->dp) log<<" --> Warning <-- Mixture in "<<name<<" can't be flashed (bp="<<F->bp<<" dp="<<F->dp<<").\n"; - log.close(); - } */ - for (i=0;i<F->nb;i++) - { - if (F->chem[i]->Tc<T || f_x>=1) {V->chem[i]->m=Fcopy->chem[i]->m; V->m+=V->chem[i]->m; } - else {L->chem[i]->m=Fcopy->chem[i]->m; L->m+=L->chem[i]->m;} - - } - success = true; - } - L->set(P,T); - V->set(P,T); - Q = 0.0; - for (i=0;i<F->nb;i++) - { - Q += L->chem[i]->dH(Tin, T, P)*L->chem[i]->n(); - Q += V->chem[i]->dH(Tin, T, P)*V->chem[i]->n(); - } - F->m=0; - for(i=0;i<Fcopy->nb;i++) {F->chem[i]->m = Fcopy->chem[i]->m; F->m+=F->chem[i]->m;} - F->set(F->P,Tin); -// if(fabs(V->m+L->m-F->m)>sqrt(EPS)) -// { -// log.open(MESSAGES, ios::app); -// log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(V->m+L->m-F->m)/F->m<<").\n"; -// log.close(); -// } -// V->write();// TOTO - // L->write(); // TOTO - - return success; -} - -double flash::f(double psy) -{ - x=psy; - f_x=0.0; - for(i=0;i<F->nb;i++) f_x += (z[i]*(1-K[i]))/(1+psy*(K[i]-1)); - return f_x; -} - -bool flash::adiabatic() -{ - task=1; - F->set(P,T); T=F->dp; - step=-5; - Q=1; - - - while (fabs(step)>0.01 && fabs(Q)>0.1) - { - T+=step; - F->set(P,T); - - for (i=0;i<F->nb;i++) - K[i] = F->chem[i]->Psat(T)/P; - - success=solve(); - - - if (Q<0 && step<0) step*=-0.5; - if (Q>0 && step>0) step*=-0.5; - } - if (fabs(Q)<0.1) return true; - else return false; -} - -void flash::write() { - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> "<<name; - cout << endl << "\t>> stream in : "<<F->name; - cout <<endl<<"\t>> streams out : "<<L->name<<" (liq.) "<<V->name<<" (vap.)"; - cout <<endl<<"\t>> P = "<<P<<" atm, T = "<<T<<" K"; - cout <<endl<<"\t>> Heat duty = "<<Q; - if (success==true) cout <<" kW (converge normally)"; - cout << "\n\tEND\n\n"; - cost(); - power(); - water(); -} - - -double flash::get_cost ( void ) { - vol=15.0*(L->v+V->v); - if(vol<0.3) vol=0.3; if(vol>520)vol=520; - step = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); - step = pow(10, step); - P= (P-1)*101.325/100; - f_x=pow(2.0*vol/pi, 1.0/3.0); - vol=(P+1)*f_x/(317.46*(850-0.6*(P+1)))+0.0315; - step *=(2.25+ 1.82*vol*2.2); - step = step*MS_YEAR/MS_2001; - return step; -} - -void flash::cost() { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} -void flash::power() { - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - cout << "\t>>" << Q; - cout << "\n\tEND\n\n"; -} - -double flash::get_water ( void ) { - step = (Q<0.0) ? fabs(Q)/(4.185*0.10*(Tin-298)) : 0.0; - return step; -} - -void flash::water() { - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - if(Q<0.0) - step= (fabs(Q)/(4.185*0.10*(Tin-298))); - else - step= 0.0; - cout << "\t>>" << step; - cout << "\n\tEND\n\n"; -} +#include "flash.hpp" +#include "bissection.cpp" +using namespace std; + +flash::flash ( stream * in , stream * out_L , stream * out_V ) { + F = in; + Fcopy = new stream("Fcopy", F->nb, F->chem); + Tin = F->T; + z = new double[F->nb]; + for ( i = 0 ; i < F->nb ; i++ ) + z[i] = F->chem[i]->n()/F->n(); + + L = out_L; + V = out_V; + success = true; + K = new double[F->nb]; + task=0; + solver = new bissection<flash>(); +} + +void flash::set(double p, double t) +{ + P=p; + T=t; + for (i=0;i<F->nb;i++) + { + if(F->chem[i]->Tc<T) K[i] = F->chem[i]->Psat(T)/P; + else K[i]=1; + } + F->set(P,T); +} + +bool flash::solve() +{ + L->purge(); + V->purge(); + f_x=F->quality(); + + if( 0.0 < f_x && f_x < 1.0) + { + + // TOTO + for ( i = 0 ; i < F->nb ; i++ ) { + if ( F->chem[i]->Tc < T ) { + F->m -= F->chem[i]->m; + F->chem[i]->m = 0; + } + } + + for ( i = 0 ; i < F->nb ; i++ ) + z[i] = F->chem[i]->n()/F->n(); + + solver->set(this, 0.0, 1.0); + + success=solver->run(); + + if (!success) + { +// if(task==0){ +// log.open(MESSAGES, ios::app); +// log<<" --> Warning <-- Solver of FLASH "<<name<<" did not converge.\n"; +// log.close();} + for (i=0;i<F->nb;i++) + { + if (T<F->chem[i]->Tc && T>F->chem[i]->Tboil(P)) {V->chem[i]->m=F->chem[i]->m; V->m+=V->chem[i]->m;} + if (T<F->chem[i]->Tc && T<=F->chem[i]->Tboil(P)) {L->chem[i]->m=F->chem[i]->m; L->m+=L->chem[i]->m;} + } + } + else + { + + V->m = x*F->n(); + L->m = F->n() - V->m; + //Distribute liquid components + for (i=0;i<L->nb;i++) + { + L->chem[i]->m = (L->m*z[i])/(1+x*(K[i]-1))*L->chem[i]->M/1000.0; + L->chem[i]->state=0; + } + + + L->m=0.0; for(i=0;i<L->nb;i++) L->m+=L->chem[i]->m; + //Distribute vapor components + for (i=0;i<V->nb;i++) + { + V->chem[i]->m = V->m*L->chem[i]->n()*K[i]/L->n()*V->chem[i]->M/1000.0; + V->chem[i]->state=1; + } + V->m=0.0; for(i=0;i<V->nb;i++) V->m+=V->chem[i]->m; + } + for(i=0;i<F->nb;i++) + if(F->chem[i]->Tc<T){V->chem[i]->m=Fcopy->chem[i]->m; V->m+=Fcopy->chem[i]->m;} + + } + else + { + /* if(task==0) + { + log.open("runtime\\messages.r", ios::app); + if (T<F->dp) log<<" --> Warning <-- Mixture in "<<name<<" can't be flashed (bp="<<F->bp<<" dp="<<F->dp<<").\n"; + log.close(); + } */ + for (i=0;i<F->nb;i++) + { + if (F->chem[i]->Tc<T || f_x>=1) {V->chem[i]->m=Fcopy->chem[i]->m; V->m+=V->chem[i]->m; } + else {L->chem[i]->m=Fcopy->chem[i]->m; L->m+=L->chem[i]->m;} + + } + success = true; + } + L->set(P,T); + V->set(P,T); + Q = 0.0; + for (i=0;i<F->nb;i++) + { + Q += L->chem[i]->dH(Tin, T, P)*L->chem[i]->n(); + Q += V->chem[i]->dH(Tin, T, P)*V->chem[i]->n(); + } + F->m=0; + for(i=0;i<Fcopy->nb;i++) {F->chem[i]->m = Fcopy->chem[i]->m; F->m+=F->chem[i]->m;} + F->set(F->P,Tin); +// if(fabs(V->m+L->m-F->m)>sqrt(EPS)) +// { +// log.open(MESSAGES, ios::app); +// log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(V->m+L->m-F->m)/F->m<<").\n"; +// log.close(); +// } +// V->write();// TOTO + // L->write(); // TOTO + + return success; +} + +double flash::f(double psy) +{ + x=psy; + f_x=0.0; + for(i=0;i<F->nb;i++) f_x += (z[i]*(1-K[i]))/(1+psy*(K[i]-1)); + return f_x; +} + +bool flash::adiabatic() +{ + task=1; + F->set(P,T); T=F->dp; + step=-5; + Q=1; + + + while (fabs(step)>0.01 && fabs(Q)>0.1) + { + T+=step; + F->set(P,T); + + for (i=0;i<F->nb;i++) + K[i] = F->chem[i]->Psat(T)/P; + + success=solve(); + + + if (Q<0 && step<0) step*=-0.5; + if (Q>0 && step>0) step*=-0.5; + } + if (fabs(Q)<0.1) return true; + else return false; +} + +void flash::write() { + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> "<<name; + cout << endl << "\t>> stream in : "<<F->name; + cout <<endl<<"\t>> streams out : "<<L->name<<" (liq.) "<<V->name<<" (vap.)"; + cout <<endl<<"\t>> P = "<<P<<" atm, T = "<<T<<" K"; + cout <<endl<<"\t>> Heat duty = "<<Q; + if (success==true) cout <<" kW (converge normally)"; + cout << "\n\tEND\n\n"; + cost(); + power(); + water(); +} + + +double flash::get_cost ( void ) { + vol=15.0*(L->v+V->v); + if(vol<0.3) vol=0.3; if(vol>520)vol=520; + step = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); + step = pow(10, step); + P= (P-1)*101.325/100; + f_x=pow(2.0*vol/pi, 1.0/3.0); + vol=(P+1)*f_x/(317.46*(850-0.6*(P+1)))+0.0315; + step *=(2.25+ 1.82*vol*2.2); + step = step*MS_YEAR/MS_2001; + return step; +} + +void flash::cost() { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} +void flash::power() { + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + cout << "\t>>" << Q; + cout << "\n\tEND\n\n"; +} + +double flash::get_water ( void ) { + step = (Q<0.0) ? fabs(Q)/(4.185*0.10*(Tin-298)) : 0.0; + return step; +} + +void flash::water() { + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + if(Q<0.0) + step= (fabs(Q)/(4.185*0.10*(Tin-298))); + else + step= 0.0; + cout << "\t>>" << step; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.hpp index 29bc250c316f150c5f2880ab5696b5601867009d..b6cdb41b3b5c556d848c01ec23b40b0ba0f4356e 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/flash.hpp @@ -1,55 +1,55 @@ -/* -This unit takes operating P and T, and indexes of streams. It applies -the Rachford-Rice procedure to solve the isothermal flash problem -(ref : Seader & Henley). - -Structure in the .process file: -flash {name} {pressure} {temperature} {index of input stream} {index of output liquid and output vapor} - -How to use: - 1- Call the constructor : flash1 = new flash(in, out_L, out_V); //in is the feed, out_L is the liquid output and out_V is the vapor output - 2- Set P and T: flash1->set(P,T); - 3- Set the name: flash1->set(name); - 4a- Perform an isothermal flash : flash1->solve(); - 4b- Perform an adiabatic flash: flash1->adiabatic(); -*/ -#ifndef FLASH_H -#define FLASH_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class flash { -private: - bool success; - bissection<flash> *solver; - // ofstream log, results; -// char name[31], filename[41]; //name of the unit - - string name; - - int i, task; //task=0: isothermal flash; task=1:adiabatic flash - stream *F, *Fcopy; //pointer to the input stream - stream *L, *V; //pointers to liquid and vapor output streams - double f_x, x, *K, *z; //pressure (given) and temperature (given) - double Q, Tin, step, vol; //required power, in kW - -public: - flash(){P=0.0; T=0.0;} - flash(stream*, stream*, stream*); //defines the connectivities of this unit - ~flash(){delete Fcopy; delete [] K; delete [] z; delete solver;} - double P ,T; - void set(double, double); - void set( const string & n ) { name = n; } - bool solve(); //applies the Rachford-Rice procedure - bool adiabatic(); //adiabatic isobaric flash - double f(double); //returns the function to the solver - void write(); - double get_water ( void ); - double get_cost ( void ); - - double get_power ( void ) const { return Q; } - void cost(), water(), power(); -}; -#endif +/* +This unit takes operating P and T, and indexes of streams. It applies +the Rachford-Rice procedure to solve the isothermal flash problem +(ref : Seader & Henley). + +Structure in the .process file: +flash {name} {pressure} {temperature} {index of input stream} {index of output liquid and output vapor} + +How to use: + 1- Call the constructor : flash1 = new flash(in, out_L, out_V); //in is the feed, out_L is the liquid output and out_V is the vapor output + 2- Set P and T: flash1->set(P,T); + 3- Set the name: flash1->set(name); + 4a- Perform an isothermal flash : flash1->solve(); + 4b- Perform an adiabatic flash: flash1->adiabatic(); +*/ +#ifndef FLASH_H +#define FLASH_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class flash { +private: + bool success; + bissection<flash> *solver; + // ofstream log, results; +// char name[31], filename[41]; //name of the unit + + string name; + + int i, task; //task=0: isothermal flash; task=1:adiabatic flash + stream *F, *Fcopy; //pointer to the input stream + stream *L, *V; //pointers to liquid and vapor output streams + double f_x, x, *K, *z; //pressure (given) and temperature (given) + double Q, Tin, step, vol; //required power, in kW + +public: + flash(){P=0.0; T=0.0;} + flash(stream*, stream*, stream*); //defines the connectivities of this unit + ~flash(){delete Fcopy; delete [] K; delete [] z; delete solver;} + double P ,T; + void set(double, double); + void set( const string & n ) { name = n; } + bool solve(); //applies the Rachford-Rice procedure + bool adiabatic(); //adiabatic isobaric flash + double f(double); //returns the function to the solver + void write(); + double get_water ( void ); + double get_cost ( void ); + + double get_power ( void ) const { return Q; } + void cost(), water(), power(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.cpp index fd8942e30cbea0202a6a60ed31b1a3f0b03974a4..3c23822ae8f89a1971ec24d0d35b218e13ebbf40 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.cpp @@ -1,146 +1,146 @@ -#include "heatx.hpp" -#include "bissection.cpp" - -heatx::heatx(bool m, stream* s1, stream* s2) -{ - in = s1; - out = s2; - out->m=0; - for(i=0;i<in->nb;i++) - { - out->chem[i]->m=in->chem[i]->m; - out->m+=out->chem[i]->m; - } - solver = new bissection<heatx>(); - mode = m; - success = true; -} - -void heatx::set(double d1, double d2) -{ - if(mode==0) T=d1; - if(mode==1) Q=d1; - eta = d2; -} - -bool heatx::solve() -{ - if(mode==0) - { - Q = 0.0; - out->set(in->P, T); - // out->write(); // WRITE TOTO - for(i=0;i<in->nb;i++) - Q+=out->chem[i]->dH(in->T, out->T, in->P)*out->chem[i]->n(); - if(eta>EPS) - Qreal = Q/eta; - else { - Qreal=Q; - success=false; - } - } - if(mode==1) - { - Qreal = eta*Q; - min = in->T; - max = 2000; - solver->set(this, min, max); - success = solver->run(); - out->set(in->P, T); - //out->write(); // WRITE TOTO - } - return success; -} - - -double heatx::f(double x) -{ - T=x; - max = Qreal; - for(i=0;i<in->nb;i++) - max -= out->chem[i]->dH(in->T, T, in->P)*out->chem[i]->n(); - return max; -} - -void heatx::write() -{ - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in: " << in->name << " T = " << in->T <<" K"; - cout << endl << "\t>> stream out: " << out->name << " T = " << out->T <<" K"; - if (mode==0) - cout<<endl<<"\t>> Heat duty : "<<Qreal<<" kW"; - if (mode==1) - cout<<endl<<"\t>> Heat duty : "<<Q<<" kW"; - if (success) - cout<<endl<<"\t>> Heat losses "<<fabs(Qreal-Q)<<" kW (converged normally)"; - cout << "\n\tEND\n\n"; - - cost(); - power(); - water(); -} - - - -double heatx::get_cost ( void ) { - if(mode==1) min=fabs(Q)/0.225/(eta)/fabs(out->T-in->T); - if(mode==0) min=fabs(Qreal)/0.25/(eta)/fabs(out->T-in->T); - if(min<10) min=10; if(min>1000) min=1000; - max = 4.3247-0.303*log10(min)+0.1634*pow(log10(min),2); - T=in->P; - T = (T-1)*1.01325; - if (fabs(T)<EPS) T=0.1; if(T>100) T=100; - min=0.03881-0.11272*log10(T)+0.08183*pow(log10(T),2); - min=pow(10, min); - max = (1.63+1.66*2.5*min)*pow(10, max); - max = max*MS_YEAR/MS_2001; - return max; -} - - -void heatx::cost() -{ - cout << setprecision(5); - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - - - -double heatx::get_water ( void ) -{ - max = (Q<0.0) ? fabs(Q)/(4.185*0.10*(out->T-298)) : 0.0; - return max; -} - - -void heatx::water() -{ - if(Q<0.0) max = fabs(Q)/(4.185*0.10*(out->T-298)); - else max = 0.0; - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - cout << "\t>>" << max; - cout << "\n\tEND\n\n"; - -} - -double heatx::get_power ( void ) { - max = (mode) ? Q : Qreal; - if (max>EPS) - return max; - return 0.0; -} - -void heatx::power() -{ - if(mode==0) max = Qreal; - if(mode==1) max = Q; - - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - if(max>EPS) cout<< "\t>>" << max; - else cout<< "\t>>" << 0; - cout << "\n\tEND\n\n"; -} +#include "heatx.hpp" +#include "bissection.cpp" + +heatx::heatx(bool m, stream* s1, stream* s2) +{ + in = s1; + out = s2; + out->m=0; + for(i=0;i<in->nb;i++) + { + out->chem[i]->m=in->chem[i]->m; + out->m+=out->chem[i]->m; + } + solver = new bissection<heatx>(); + mode = m; + success = true; +} + +void heatx::set(double d1, double d2) +{ + if(mode==0) T=d1; + if(mode==1) Q=d1; + eta = d2; +} + +bool heatx::solve() +{ + if(mode==0) + { + Q = 0.0; + out->set(in->P, T); + // out->write(); // WRITE TOTO + for(i=0;i<in->nb;i++) + Q+=out->chem[i]->dH(in->T, out->T, in->P)*out->chem[i]->n(); + if(eta>EPS) + Qreal = Q/eta; + else { + Qreal=Q; + success=false; + } + } + if(mode==1) + { + Qreal = eta*Q; + min = in->T; + max = 2000; + solver->set(this, min, max); + success = solver->run(); + out->set(in->P, T); + //out->write(); // WRITE TOTO + } + return success; +} + + +double heatx::f(double x) +{ + T=x; + max = Qreal; + for(i=0;i<in->nb;i++) + max -= out->chem[i]->dH(in->T, T, in->P)*out->chem[i]->n(); + return max; +} + +void heatx::write() +{ + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in: " << in->name << " T = " << in->T <<" K"; + cout << endl << "\t>> stream out: " << out->name << " T = " << out->T <<" K"; + if (mode==0) + cout<<endl<<"\t>> Heat duty : "<<Qreal<<" kW"; + if (mode==1) + cout<<endl<<"\t>> Heat duty : "<<Q<<" kW"; + if (success) + cout<<endl<<"\t>> Heat losses "<<fabs(Qreal-Q)<<" kW (converged normally)"; + cout << "\n\tEND\n\n"; + + cost(); + power(); + water(); +} + + + +double heatx::get_cost ( void ) { + if(mode==1) min=fabs(Q)/0.225/(eta)/fabs(out->T-in->T); + if(mode==0) min=fabs(Qreal)/0.25/(eta)/fabs(out->T-in->T); + if(min<10) min=10; if(min>1000) min=1000; + max = 4.3247-0.303*log10(min)+0.1634*pow(log10(min),2); + T=in->P; + T = (T-1)*1.01325; + if (fabs(T)<EPS) T=0.1; if(T>100) T=100; + min=0.03881-0.11272*log10(T)+0.08183*pow(log10(T),2); + min=pow(10, min); + max = (1.63+1.66*2.5*min)*pow(10, max); + max = max*MS_YEAR/MS_2001; + return max; +} + + +void heatx::cost() +{ + cout << setprecision(5); + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + + + +double heatx::get_water ( void ) +{ + max = (Q<0.0) ? fabs(Q)/(4.185*0.10*(out->T-298)) : 0.0; + return max; +} + + +void heatx::water() +{ + if(Q<0.0) max = fabs(Q)/(4.185*0.10*(out->T-298)); + else max = 0.0; + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + cout << "\t>>" << max; + cout << "\n\tEND\n\n"; + +} + +double heatx::get_power ( void ) { + max = (mode) ? Q : Qreal; + if (max>EPS) + return max; + return 0.0; +} + +void heatx::power() +{ + if(mode==0) max = Qreal; + if(mode==1) max = Q; + + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + if(max>EPS) cout<< "\t>>" << max; + else cout<< "\t>>" << 0; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.hpp index d3b7dffa4dd8771694a77c52ad38a6aba478e821..f9854adf318b541dcac49e2466d35cc69683cd2d 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/heatx.hpp @@ -1,49 +1,49 @@ -/* -This unit performs the heating of a stream (mode 0) or the heat -exchange to a stream (mode 1). -(ref : McCabe, Smith & Harriott) - -Structure in the .process file: -mode 0 : heatx {name} 0 {index of input stream} {index of output stream} {T out} {efficiency} //efficiency is a fraction between 0 and 1 -mode 1 : heatx {name} 1 {index of input stream} {index of output stream} {Q} {efficiency} //Q is the heat flow in kW -How to use: - 1- Call the constructor: heat = new heatx(mode, in, out); - 2- Set the operating conditions : heat->set(T_out, eta); //mode 0 - or : heat->set(Q, eta); //mode 1 - 3- Set the name of the unit: heat->set(name); - 4- Solve: bool=heat->solve(); -*/ -#ifndef HEATX_H -#define HEATX_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class heatx -{ -private: - int i; - bool success, mode; - bissection<heatx> *solver; - // ofstream logf, results; - double min, max; - string name; - stream *in, *out; //streams of the unit - double eta, Q, Qreal, T; - -public: - heatx(){} - heatx(bool, stream*, stream*); //defines the connectivities of this unit - ~heatx(){delete solver;} - void set(double, double); - void set(const string & n) { name = n; } - double f(double); - bool solve(); - void write(); - void power(), water(), cost(); - double get_cost(); - double get_power(); - double get_water(); -}; -#endif +/* +This unit performs the heating of a stream (mode 0) or the heat +exchange to a stream (mode 1). +(ref : McCabe, Smith & Harriott) + +Structure in the .process file: +mode 0 : heatx {name} 0 {index of input stream} {index of output stream} {T out} {efficiency} //efficiency is a fraction between 0 and 1 +mode 1 : heatx {name} 1 {index of input stream} {index of output stream} {Q} {efficiency} //Q is the heat flow in kW +How to use: + 1- Call the constructor: heat = new heatx(mode, in, out); + 2- Set the operating conditions : heat->set(T_out, eta); //mode 0 + or : heat->set(Q, eta); //mode 1 + 3- Set the name of the unit: heat->set(name); + 4- Solve: bool=heat->solve(); +*/ +#ifndef HEATX_H +#define HEATX_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class heatx +{ +private: + int i; + bool success, mode; + bissection<heatx> *solver; + // ofstream logf, results; + double min, max; + string name; + stream *in, *out; //streams of the unit + double eta, Q, Qreal, T; + +public: + heatx(){} + heatx(bool, stream*, stream*); //defines the connectivities of this unit + ~heatx(){delete solver;} + void set(double, double); + void set(const string & n) { name = n; } + double f(double); + bool solve(); + void write(); + void power(), water(), cost(); + double get_cost(); + double get_power(); + double get_water(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.cpp index dc02dc7e4b82f42e8631fadcb4d4b2d8500fec32..00202a2af2f1ce299966b7b44e1fe85c060950d0 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.cpp @@ -1,80 +1,80 @@ -#include "mix.hpp" -#include "bissection.cpp" -using namespace std; - -mix::mix ( int n , stream ** s1 , stream * s2 ) { - nb_in=n; - in = s1; - out= s2; - success = true; - solver = new bissection<mix>(); -} - -bool mix::solve() -{ - //Mass balance - out->m=0; - out->purge(); - for (j=0; j<out->nb;j++) - for (i=0;i<nb_in;i++) if(in[i]->chem[j]->m>EPS) - { - out->chem[j]->m+=in[i]->chem[j]->m; - out->m+=in[i]->chem[j]->m; - } - //Find the temperature - double max=0.0; double min=1e6; - for(i=0;i<nb_in;i++) - for(j=0;j<out->nb;j++) - { - if(in[i]->chem[j]->T>max && in[i]->chem[j]->m>EPS) max=in[i]->chem[j]->T; - if(in[i]->chem[j]->T<min && in[i]->chem[j]->m>EPS) min=in[i]->chem[j]->T; - } - if(fabs(max-min)<EPS) T=max; - else - { - solver->set(this, min, max); - success = solver->run(); - } - out->set(P,T); - // if (success==false) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Solver of "<<name<<" did not converge.\n"; - // log.close(); - // } - // min = 0; - // for(i=0;i<nb_in;i++) - // min+=in[i]->m; - // if(fabs(min-out->m)>sqrt(EPS)) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(min-out->m)/min<<").\n"; - // log.close(); - // } - - // out->write(); // WRITE TOTO - return success; -} - -double mix::f(double x) -{ - T=x; - double energy=0.0; //in kW - for (j=0; j<out->nb;j++) - for (i=0;i<nb_in;i++) - energy += in[i]->chem[j]->dH(in[i]->T, T, P)*in[i]->chem[j]->n()/1000; - return energy; -} - -void mix::write() { - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name - << endl << "\t>> streams in: "; - for ( int i = 0 ; i < nb_in ; i++ ) - cout << in[i]->name << " "; - cout << endl << "\t>> stream out: " << out->name; - cout <<endl << "\t>> P = " << P << " atm, T = " << T; - if (success) - cout << " K (converged normally)"; - cout << "\n\tEND\n\n"; -} +#include "mix.hpp" +#include "bissection.cpp" +using namespace std; + +mix::mix ( int n , stream ** s1 , stream * s2 ) { + nb_in=n; + in = s1; + out= s2; + success = true; + solver = new bissection<mix>(); +} + +bool mix::solve() +{ + //Mass balance + out->m=0; + out->purge(); + for (j=0; j<out->nb;j++) + for (i=0;i<nb_in;i++) if(in[i]->chem[j]->m>EPS) + { + out->chem[j]->m+=in[i]->chem[j]->m; + out->m+=in[i]->chem[j]->m; + } + //Find the temperature + double max=0.0; double min=1e6; + for(i=0;i<nb_in;i++) + for(j=0;j<out->nb;j++) + { + if(in[i]->chem[j]->T>max && in[i]->chem[j]->m>EPS) max=in[i]->chem[j]->T; + if(in[i]->chem[j]->T<min && in[i]->chem[j]->m>EPS) min=in[i]->chem[j]->T; + } + if(fabs(max-min)<EPS) T=max; + else + { + solver->set(this, min, max); + success = solver->run(); + } + out->set(P,T); + // if (success==false) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Solver of "<<name<<" did not converge.\n"; + // log.close(); + // } + // min = 0; + // for(i=0;i<nb_in;i++) + // min+=in[i]->m; + // if(fabs(min-out->m)>sqrt(EPS)) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(min-out->m)/min<<").\n"; + // log.close(); + // } + + // out->write(); // WRITE TOTO + return success; +} + +double mix::f(double x) +{ + T=x; + double energy=0.0; //in kW + for (j=0; j<out->nb;j++) + for (i=0;i<nb_in;i++) + energy += in[i]->chem[j]->dH(in[i]->T, T, P)*in[i]->chem[j]->n()/1000; + return energy; +} + +void mix::write() { + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name + << endl << "\t>> streams in: "; + for ( int i = 0 ; i < nb_in ; i++ ) + cout << in[i]->name << " "; + cout << endl << "\t>> stream out: " << out->name; + cout <<endl << "\t>> P = " << P << " atm, T = " << T; + if (success) + cout << " K (converged normally)"; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.hpp index 6d4ee0f28d6696616e803fdfe89e6689b3001d69..85b8d771f173ba66deb363e2586bb42d7cd74854 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/mix.hpp @@ -1,44 +1,44 @@ -/* -This unit takes more than two input streams and merge them in one -output stream. The pressure must be specified by the user, and the -temperature of the output stream is computed. - -Structure in the .process file: -mix {name} {pressure} {nb_in} {indexes of input streams} {index of output stream} - -How to use: - 1- Call the constructor: mix1 = new mix(nb_in, list1_in, out); - 2- Set the operating pressure : mix1->set(P); - 3- Set the name of the unit: mix1->set(name); - 4- Solve: bool=mix1->solve(); -*/ -#ifndef MIX_H -#define MIX_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class mix { - private: - int i, j; - bool success; - bissection<mix> *solver; - string name; - int nb_in; //number of input streams - stream **in; //list pointers to input streams - stream *out; //pointer to output stream - // double min, max; - - public: - double P, T; //pressure (given) and temperature (unknown) - mix(){P=0.0;} - mix(int, stream**, stream*); //defines the connectivities of this unit - ~mix(){delete solver;} - void set(double p) {P=p;} - void set ( const string & n ) { name = n; } - double f(double); //returns the function to the solver - bool solve(); //finds the temperature and computes mass balance - void write(); -}; -#endif +/* +This unit takes more than two input streams and merge them in one +output stream. The pressure must be specified by the user, and the +temperature of the output stream is computed. + +Structure in the .process file: +mix {name} {pressure} {nb_in} {indexes of input streams} {index of output stream} + +How to use: + 1- Call the constructor: mix1 = new mix(nb_in, list1_in, out); + 2- Set the operating pressure : mix1->set(P); + 3- Set the name of the unit: mix1->set(name); + 4- Solve: bool=mix1->solve(); +*/ +#ifndef MIX_H +#define MIX_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class mix { + private: + int i, j; + bool success; + bissection<mix> *solver; + string name; + int nb_in; //number of input streams + stream **in; //list pointers to input streams + stream *out; //pointer to output stream + // double min, max; + + public: + double P, T; //pressure (given) and temperature (unknown) + mix(){P=0.0;} + mix(int, stream**, stream*); //defines the connectivities of this unit + ~mix(){delete solver;} + void set(double p) {P=p;} + void set ( const string & n ) { name = n; } + double f(double); //returns the function to the solver + bool solve(); //finds the temperature and computes mass balance + void write(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.cpp index bcb7ccff69f72da99964d64e56481b4db3c2ece4..54694511705078ad9e5954a1610d97e22f00169f 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.cpp @@ -1,174 +1,174 @@ -#include "pfr.hpp" -#include "RungeKutta.cpp" -using namespace std; - -pfr::pfr ( stream * s1 , stream * s2 , double ** t , int nb_r , reaction ** rr , double u , double ta ) { - - F = s2; - F->m=0; - P=s1->P; - for ( i = 0 ; i < s1->nb ; i++ ) { - F->chem[i]->m = s1->chem[i]->m; - F->m+=F->chem[i]->m; - } - F->set(s1->P, s1->T); - m_in=F->m; - a = t; - rx = rr; - n=nb_r; - m= F->nb; - U=u; - Ta=ta; - T = F->T; - C = new double[m]; - y = new double[m+1]; - r=new double[n]; - OK=true; - explode=true; - solver = new RungeKutta<pfr>(m+1); -} - -pfr::~pfr() { - delete [] r; - delete [] C; - delete [] y; - delete solver; -} - -bool pfr::run() { - - for ( i = 0 ; i < m ; i++ ) - y[i]=F->chem[i]->n(); - - y[m]=T; - - solver->set ( this , y , 0.0 , L ); - - dL=solver->dx(); - - OK=solver->run(); - - sum = F->m; - F->m = 0; - - for ( i = 0 ; i < m ; i++ ) - F->m+=F->chem[i]->m; - for ( i = 0 ; i < m ; i++ ) - F->chem[i]->m *= sum/F->m; - // if (OK) - //mass balance! - if ( fabs(m_in-F->m) > EPS || !explode ) - OK=false; - - return OK; -} - -double pfr::f ( int eq , double l , double * y ) { - - - sum=F->m; - F->m=0; - for(i=0; i<m;i++) - { - if(y[i]<0) y[i]=0; - F->chem[i]->m = y[i]*F->chem[i]->M/1000.0; - F->m+=F->chem[i]->m; - } - - - for(i=0; i<m;i++) - F->chem[i]->m *= sum/F->m; - - - F->m=sum; - T=y[m]; - if(T>MAX_TEMP) - { - cout << "ERROR 11\n\n"; - exit(0); - } - - - for(i=0; i<m;i++) - C[i]=F->chem[i]->n()/F->v; - - for(j=0;j<n;j++) - r[j] = rx[j]->rate(T,C); - - if(0<=eq && eq<m) //return dFi/dL - { - tmp=0.0; - for(j=0;j<n;j++) tmp+=a[eq][j]*r[j]; - tmp *= (pi*D*D/4.0); - } - - - - if(eq==m) //return dT/dL - { - - - F->set(F->P,T); - - tmp=0.0; - for(j=0;j<n;j++) - tmp -= r[j]*rx[j]->dHr(T); - - - tmp *= (pi*D*D/4.0); - - - tmp += (pi*D)*U*(Ta-T); - - - tmp1=0.0; - for(i=0;i<m;i++) - tmp1+= y[i]*F->chem[i]->Cp()*0.001; - tmp /= tmp1; - - - if(fabs(tmp*dL)>500.0) - { - cout << "ERROR 13\n\n"; - exit(0); - } - } - - - - - return tmp; -} - - - -double pfr::get_cost ( void ) { - dL=L*pi*pow(D,2)/4.0; - if(dL<0.3) dL=0.3; if(dL>520) dL=520; - sum = 3.4974+0.4485*log10(dL)+0.1074*pow(log10(dL),2); - sum = pow(10, sum); - P= (P-1)*101.325/100; - dL=(P+1)*D/(317.46*(850-0.6*(P+1)))+0.0315; - sum *=(2.25+ 1.82*dL*4.2); - sum = sum*MS_YEAR/MS_2001; - return sum; -} - -double pfr::get_water() { - sum = (U>EPS && T>Ta) ? U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0 : 0.0; - return sum; -} - -void pfr::cost() { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - -void pfr::water() { - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - if (U>EPS && T>Ta) sum = (U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0); - else sum = 0.0; - cout << "\t>>" << sum; - cout << "\n\tEND\n\n"; -} +#include "pfr.hpp" +#include "RungeKutta.cpp" +using namespace std; + +pfr::pfr ( stream * s1 , stream * s2 , double ** t , int nb_r , reaction ** rr , double u , double ta ) { + + F = s2; + F->m=0; + P=s1->P; + for ( i = 0 ; i < s1->nb ; i++ ) { + F->chem[i]->m = s1->chem[i]->m; + F->m+=F->chem[i]->m; + } + F->set(s1->P, s1->T); + m_in=F->m; + a = t; + rx = rr; + n=nb_r; + m= F->nb; + U=u; + Ta=ta; + T = F->T; + C = new double[m]; + y = new double[m+1]; + r=new double[n]; + OK=true; + explode=true; + solver = new RungeKutta<pfr>(m+1); +} + +pfr::~pfr() { + delete [] r; + delete [] C; + delete [] y; + delete solver; +} + +bool pfr::run() { + + for ( i = 0 ; i < m ; i++ ) + y[i]=F->chem[i]->n(); + + y[m]=T; + + solver->set ( this , y , 0.0 , L ); + + dL=solver->dx(); + + OK=solver->run(); + + sum = F->m; + F->m = 0; + + for ( i = 0 ; i < m ; i++ ) + F->m+=F->chem[i]->m; + for ( i = 0 ; i < m ; i++ ) + F->chem[i]->m *= sum/F->m; + // if (OK) + //mass balance! + if ( fabs(m_in-F->m) > EPS || !explode ) + OK=false; + + return OK; +} + +double pfr::f ( int eq , double l , double * y ) { + + + sum=F->m; + F->m=0; + for(i=0; i<m;i++) + { + if(y[i]<0) y[i]=0; + F->chem[i]->m = y[i]*F->chem[i]->M/1000.0; + F->m+=F->chem[i]->m; + } + + + for(i=0; i<m;i++) + F->chem[i]->m *= sum/F->m; + + + F->m=sum; + T=y[m]; + if(T>MAX_TEMP) + { + cout << "ERROR 11\n\n"; + exit(0); + } + + + for(i=0; i<m;i++) + C[i]=F->chem[i]->n()/F->v; + + for(j=0;j<n;j++) + r[j] = rx[j]->rate(T,C); + + if(0<=eq && eq<m) //return dFi/dL + { + tmp=0.0; + for(j=0;j<n;j++) tmp+=a[eq][j]*r[j]; + tmp *= (pi*D*D/4.0); + } + + + + if(eq==m) //return dT/dL + { + + + F->set(F->P,T); + + tmp=0.0; + for(j=0;j<n;j++) + tmp -= r[j]*rx[j]->dHr(T); + + + tmp *= (pi*D*D/4.0); + + + tmp += (pi*D)*U*(Ta-T); + + + tmp1=0.0; + for(i=0;i<m;i++) + tmp1+= y[i]*F->chem[i]->Cp()*0.001; + tmp /= tmp1; + + + if(fabs(tmp*dL)>500.0) + { + cout << "ERROR 13\n\n"; + exit(0); + } + } + + + + + return tmp; +} + + + +double pfr::get_cost ( void ) { + dL=L*pi*pow(D,2)/4.0; + if(dL<0.3) dL=0.3; if(dL>520) dL=520; + sum = 3.4974+0.4485*log10(dL)+0.1074*pow(log10(dL),2); + sum = pow(10, sum); + P= (P-1)*101.325/100; + dL=(P+1)*D/(317.46*(850-0.6*(P+1)))+0.0315; + sum *=(2.25+ 1.82*dL*4.2); + sum = sum*MS_YEAR/MS_2001; + return sum; +} + +double pfr::get_water() { + sum = (U>EPS && T>Ta) ? U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0 : 0.0; + return sum; +} + +void pfr::cost() { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + +void pfr::water() { + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + if (U>EPS && T>Ta) sum = (U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0); + else sum = 0.0; + cout << "\t>>" << sum; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.hpp index 9746a504839af042f2f0584c37708be715bbbbb4..a8f49a71415ecc208c6ed692e7a4c6b99351ce49 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pfr.hpp @@ -1,36 +1,36 @@ -#ifndef PFR_H -#define PFR_H - -#include "reaction.hpp" -#include "RungeKutta.hpp" -#include "stream.hpp" -using namespace std; - -class pfr { -private: - // terminator *term; - // ofstream results; - string name; - bool OK, explode; - int i ,j, n, m; - double L,D,dL, U, Ta, m_in, sum, P; - stream *F; - double **a, *C, T, *y, *r, tmp, tmp1; - reaction **rx; - RungeKutta<pfr> *solver; - -public: - // pfr(){}; - pfr ( stream * , stream * , double ** , int , reaction ** , double , double ); - void set ( const string & n ) { name = n; } - void set(double l, double d) {L=l; D=d;} - bool run(); - void water(); - void cost(); - double get_cost ( void ); - double get_water ( void ); - - double f(int, double, double*); - ~pfr(); -}; -#endif +#ifndef PFR_H +#define PFR_H + +#include "reaction.hpp" +#include "RungeKutta.hpp" +#include "stream.hpp" +using namespace std; + +class pfr { +private: + // terminator *term; + // ofstream results; + string name; + bool OK, explode; + int i ,j, n, m; + double L,D,dL, U, Ta, m_in, sum, P; + stream *F; + double **a, *C, T, *y, *r, tmp, tmp1; + reaction **rx; + RungeKutta<pfr> *solver; + +public: + // pfr(){}; + pfr ( stream * , stream * , double ** , int , reaction ** , double , double ); + void set ( const string & n ) { name = n; } + void set(double l, double d) {L=l; D=d;} + bool run(); + void water(); + void cost(); + double get_cost ( void ); + double get_water ( void ); + + double f(int, double, double*); + ~pfr(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.cpp index 902f30dcfd2091ddbd5395997e010cb446546243..3617b30317dac940d299770d5afe8f8ec4a67c31 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.cpp @@ -1,138 +1,138 @@ -#include "profitability.hpp" -#include "secant.cpp" -using namespace std; - -bool profitability::run ( double * y ) -{ - OK=true; - - // cout<<setiosflags(ios::fixed); - // cout<<endl<<endl<<" PROFITABILITY ANALYSIS"<<endl; - // cout<<endl<<setprecision(1)<<" Return on investment (%)= "<<ROI()*100.0; - // cout<<endl<<" Rate of return (%)= "<<RR()*100.0; // y[10] - - y[10] = RR()*100.0; // y[10] - - ROI(); - RR(); - - // cout<<endl<<" Discounted flow rate (%)= "<<DFR()*100.0; - - DFR(); - - // cout<<endl<<endl<<" Payout time (y)= "<<PT(); // y[ 9] - y[9] = PT(); - - // cout<<endl<<setprecision(0)<<" Annual equivalent cost ($)= "<<AEC(); // y[12] - y[12] = AEC(); - - // cout<<endl<<" Net present value ($)= "<<NPV()<<endl; // y[13] - y[13] = NPV(); - - return OK; -} - -double profitability::ROI() -{ - // if(!MUTE)cout<<endl<<" return on investment..."; - num=den=0.0; - for(i=0;i<C->N;i++) - { - if(C->Inv[i]>EPS) den+=C->Inv[i]; - num+=(C->Rev[i]-C->Coper[i]-C->Amort[i]); - } - if (num>EPS && den>EPS && C->N>0) { - // if(!MUTE)cout<<" OK"; - return num/C->N/den; - } - else return 0.0; -} - -double profitability::RR() -{ - // if(!MUTE)cout<<endl<<" rate of return..."; - num=den=0.0; - for(i=0;i<C->N;i++) - { - num+=(C->Rev[i]-C->Coper[i])/pow(1.0+C->i_rate, i); - den+=C->Inv[i]/pow(1.0+C->i_rate, i); - } - if(num>EPS && den>EPS) { - // if(!MUTE)cout<<" OK"; - return num/den; - } - else return 0.0; -} - -double profitability::DFR() -{ - //if(!MUTE)cout<<endl<<" discounted cash flow rate..."; - solver = new secant<profitability>(); - solver->set(this, 0.0, 0.01); - OK = solver->run(); - - if ( OK && num>EPS && num < 1e20 ) { - // if(!MUTE)cout<<" OK"; - return num; - } - else return 0.0; -} - -double profitability::f(double x) -{ - num=x; - sum=0.0; - for(i=0;i<C->N;i++) - sum += C->Flow[i]/pow(1.0+x, i); - return sum; -} - -double profitability::PT() -{ - // if(!MUTE)cout<<endl<<" payout time..."; - sum=0.0; - for(i=0;i<C->N;i++) - { - if((sum+C->Flow[i])>0.0) - { - den=0.0; - while(sum+den*C->Flow[i]<=0.0) den+=0.001; - den+=double(i-1); - i=C->N; - } - else sum+=C->Flow[i]; - } - - if(den>EPS) { - // if(!MUTE)cout<<" OK"; - return den; - } - else return 0.0; -} - -double profitability::AEC() -{ - //if(!MUTE)cout<<endl<<" annual equivalent cost..."; - sum=0.0; - for(i=0;i<C->N;i++) sum+=(C->Coper[i]+C->Inv[i])/pow(1.0+C->i_rate, i); - if (sum>EPS) { -// if(!MUTE) -// cout<<" OK"; - return sum*(C->i_rate*pow(1.0+C->i_rate,C->N))/(pow(1.0+C->i_rate,C->N)-1.0); - } - else return 0.0; -} - -double profitability::NPV() -{ - // if(!MUTE)cout<<endl<<" net present value..."; - sum=0.0; - for ( i = 0 ; i < C->N ; i++ ) - sum += C->Flowact[i]; - if ( sum > EPS ) { -// if(!MUTE) -// cout<<" OK"; - return sum; - } - return 0.0; -} +#include "profitability.hpp" +#include "secant.cpp" +using namespace std; + +bool profitability::run ( double * y ) +{ + OK=true; + + // cout<<setiosflags(ios::fixed); + // cout<<endl<<endl<<" PROFITABILITY ANALYSIS"<<endl; + // cout<<endl<<setprecision(1)<<" Return on investment (%)= "<<ROI()*100.0; + // cout<<endl<<" Rate of return (%)= "<<RR()*100.0; // y[10] + + y[10] = RR()*100.0; // y[10] + + ROI(); + RR(); + + // cout<<endl<<" Discounted flow rate (%)= "<<DFR()*100.0; + + DFR(); + + // cout<<endl<<endl<<" Payout time (y)= "<<PT(); // y[ 9] + y[9] = PT(); + + // cout<<endl<<setprecision(0)<<" Annual equivalent cost ($)= "<<AEC(); // y[12] + y[12] = AEC(); + + // cout<<endl<<" Net present value ($)= "<<NPV()<<endl; // y[13] + y[13] = NPV(); + + return OK; +} + +double profitability::ROI() +{ + // if(!MUTE)cout<<endl<<" return on investment..."; + num=den=0.0; + for(i=0;i<C->N;i++) + { + if(C->Inv[i]>EPS) den+=C->Inv[i]; + num+=(C->Rev[i]-C->Coper[i]-C->Amort[i]); + } + if (num>EPS && den>EPS && C->N>0) { + // if(!MUTE)cout<<" OK"; + return num/C->N/den; + } + else return 0.0; +} + +double profitability::RR() +{ + // if(!MUTE)cout<<endl<<" rate of return..."; + num=den=0.0; + for(i=0;i<C->N;i++) + { + num+=(C->Rev[i]-C->Coper[i])/pow(1.0+C->i_rate, i); + den+=C->Inv[i]/pow(1.0+C->i_rate, i); + } + if(num>EPS && den>EPS) { + // if(!MUTE)cout<<" OK"; + return num/den; + } + else return 0.0; +} + +double profitability::DFR() +{ + //if(!MUTE)cout<<endl<<" discounted cash flow rate..."; + solver = new secant<profitability>(); + solver->set(this, 0.0, 0.01); + OK = solver->run(); + + if ( OK && num>EPS && num < 1e20 ) { + // if(!MUTE)cout<<" OK"; + return num; + } + else return 0.0; +} + +double profitability::f(double x) +{ + num=x; + sum=0.0; + for(i=0;i<C->N;i++) + sum += C->Flow[i]/pow(1.0+x, i); + return sum; +} + +double profitability::PT() +{ + // if(!MUTE)cout<<endl<<" payout time..."; + sum=0.0; + for(i=0;i<C->N;i++) + { + if((sum+C->Flow[i])>0.0) + { + den=0.0; + while(sum+den*C->Flow[i]<=0.0) den+=0.001; + den+=double(i-1); + i=C->N; + } + else sum+=C->Flow[i]; + } + + if(den>EPS) { + // if(!MUTE)cout<<" OK"; + return den; + } + else return 0.0; +} + +double profitability::AEC() +{ + //if(!MUTE)cout<<endl<<" annual equivalent cost..."; + sum=0.0; + for(i=0;i<C->N;i++) sum+=(C->Coper[i]+C->Inv[i])/pow(1.0+C->i_rate, i); + if (sum>EPS) { +// if(!MUTE) +// cout<<" OK"; + return sum*(C->i_rate*pow(1.0+C->i_rate,C->N))/(pow(1.0+C->i_rate,C->N)-1.0); + } + else return 0.0; +} + +double profitability::NPV() +{ + // if(!MUTE)cout<<endl<<" net present value..."; + sum=0.0; + for ( i = 0 ; i < C->N ; i++ ) + sum += C->Flowact[i]; + if ( sum > EPS ) { +// if(!MUTE) +// cout<<" OK"; + return sum; + } + return 0.0; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.hpp index 03f85c57c5454c84d5be1f6d6d35a42a45839c1f..194102c797e5dc33436d923e0b2b883da4a85979 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/profitability.hpp @@ -1,30 +1,30 @@ -#ifndef PROFITABILITY_H -#define PROFITABILITY_H -#include "cashflow.hpp" -#include "secant.hpp" - -#include <iomanip> - -using namespace std; - -class profitability -{ -private: - cashflow *C; -// ofstream out; -// char name[41]; - bool OK; - double ROI(), RR(), DFR(); - double PT(), AEC(), NPV(); - int i; - double den, num, sum; - secant<profitability> *solver; - -public: - profitability(cashflow* c){C=c;} - ~profitability(){delete solver;}; - // void set(char n[31]) {strcpy(name, n); strcat(name, ".econo");} - bool run ( double * y ); - double f(double); -}; -#endif +#ifndef PROFITABILITY_H +#define PROFITABILITY_H +#include "cashflow.hpp" +#include "secant.hpp" + +#include <iomanip> + +using namespace std; + +class profitability +{ +private: + cashflow *C; +// ofstream out; +// char name[41]; + bool OK; + double ROI(), RR(), DFR(); + double PT(), AEC(), NPV(); + int i; + double den, num, sum; + secant<profitability> *solver; + +public: + profitability(cashflow* c){C=c;} + ~profitability(){delete solver;}; + // void set(char n[31]) {strcpy(name, n); strcat(name, ".econo");} + bool run ( double * y ); + double f(double); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.cpp index 166123fcc5c2a010b33059419d072a6a5b28882c..685a0bef39991b6383b7ec874dbe9d695504bf08 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.cpp @@ -1,94 +1,94 @@ -#include "pump.hpp" -using namespace std; - -bool pump::solve() { - - // out->chem = in->chem; - out->set ( in->nb , in->chem ); - out->m = in->m; - - - in->set(in->P,in->T); - for ( i = 0 ; i < in->nb ; i++ ) - if(in->chem[i]->m>EPS) { - in->chem[i]->find_v(); - if(in->chem[i]->state==1) { - W+=in->chem[i]->gamma()*in->T*0.0083144*in->chem[i]->n()/ - (in->chem[i]->gamma()-1.0)*(pow(P/in->P, 1.0-1.0/in->chem[i]->gamma())-1.0); - tmp += in->chem[i]->gamma(); - n++; - } - if(in->chem[i]->state==0) - W+=in->chem[i]->v*(P-in->P)*101.325; - } - if (fabs(state-1)<EPS) //compressing gases - out->T = in->T*pow(P/in->P, 1.0-1.0/(tmp/n)); - else //compressing liquids - out->T=in->T; - out->set(P, out->T); - if(eta>EPS) - W /= eta; - else - success=false; - // out->write(); // WRITE TOTO - return success; -} - -void pump::write() { - - cout << setprecision(6); - - string file_name = RUNTIME + name + ".unit"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout <<"\t>> " << name; - cout << endl << "\t>> stream in: "<<in->name<<" out: "<<out->name; - cout << endl << "\t>> P(in) = "<<in->P<<" P(out) = "<<out->P<<" atm"; - cout << endl << "\t>> T(in) = "<<in->T<<" T(out) = "<<out->T<<" K"; - cout << endl << "\t>> Shaft work = "<<W; - if (success) - cout <<" kW (converge normally)"; - cout << "\n\tEND\n\n"; - - power(); - cost(); -} - - -double pump::get_cost ( void ) { - - if ( fabs(state-1) < EPS ) { - if(W<450) W=450; if(W>3000)W=3000; - tmp=2.2891+1.3604*log10(W)-0.1027*pow(log10(W),2); - tmp=3.2*pow(10.0, tmp); - tmp1=2.4604+1.4191*log10(W)-0.1798*pow(log10(W),2); - tmp1=1.5*pow(10.0, tmp1); - tmp+=tmp1; - } - else { - if(W<1) W=1; if(W>300)W=300; - tmp=3.3892+0.0536*log10(W)+0.1538*pow(log10(W),2); - tmp=pow(10.0, tmp); - P=(P-1.0)*101.325/100.0; - if (P<EPS) P=1; if(P>100) P=100; - W = -0.3925+0.3957*log10(P)-0.00226*pow(log10(P),2); - W=pow(10.0, W); if(W<1) W=1; - tmp*=(1.89+1.35*W*1.8); - } - tmp = tmp*MS_YEAR/MS_2001; - return tmp; -} - - -void pump::cost() { - string file_name = RUNTIME + name + ".cost"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - -void pump::power() { - string file_name = RUNTIME + name + ".power"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout << "\t>>" << W; - cout << "\n\tEND\n\n"; -} +#include "pump.hpp" +using namespace std; + +bool pump::solve() { + + // out->chem = in->chem; + out->set ( in->nb , in->chem ); + out->m = in->m; + + + in->set(in->P,in->T); + for ( i = 0 ; i < in->nb ; i++ ) + if(in->chem[i]->m>EPS) { + in->chem[i]->find_v(); + if(in->chem[i]->state==1) { + W+=in->chem[i]->gamma()*in->T*0.0083144*in->chem[i]->n()/ + (in->chem[i]->gamma()-1.0)*(pow(P/in->P, 1.0-1.0/in->chem[i]->gamma())-1.0); + tmp += in->chem[i]->gamma(); + n++; + } + if(in->chem[i]->state==0) + W+=in->chem[i]->v*(P-in->P)*101.325; + } + if (fabs(state-1)<EPS) //compressing gases + out->T = in->T*pow(P/in->P, 1.0-1.0/(tmp/n)); + else //compressing liquids + out->T=in->T; + out->set(P, out->T); + if(eta>EPS) + W /= eta; + else + success=false; + // out->write(); // WRITE TOTO + return success; +} + +void pump::write() { + + cout << setprecision(6); + + string file_name = RUNTIME + name + ".unit"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout <<"\t>> " << name; + cout << endl << "\t>> stream in: "<<in->name<<" out: "<<out->name; + cout << endl << "\t>> P(in) = "<<in->P<<" P(out) = "<<out->P<<" atm"; + cout << endl << "\t>> T(in) = "<<in->T<<" T(out) = "<<out->T<<" K"; + cout << endl << "\t>> Shaft work = "<<W; + if (success) + cout <<" kW (converge normally)"; + cout << "\n\tEND\n\n"; + + power(); + cost(); +} + + +double pump::get_cost ( void ) { + + if ( fabs(state-1) < EPS ) { + if(W<450) W=450; if(W>3000)W=3000; + tmp=2.2891+1.3604*log10(W)-0.1027*pow(log10(W),2); + tmp=3.2*pow(10.0, tmp); + tmp1=2.4604+1.4191*log10(W)-0.1798*pow(log10(W),2); + tmp1=1.5*pow(10.0, tmp1); + tmp+=tmp1; + } + else { + if(W<1) W=1; if(W>300)W=300; + tmp=3.3892+0.0536*log10(W)+0.1538*pow(log10(W),2); + tmp=pow(10.0, tmp); + P=(P-1.0)*101.325/100.0; + if (P<EPS) P=1; if(P>100) P=100; + W = -0.3925+0.3957*log10(P)-0.00226*pow(log10(P),2); + W=pow(10.0, W); if(W<1) W=1; + tmp*=(1.89+1.35*W*1.8); + } + tmp = tmp*MS_YEAR/MS_2001; + return tmp; +} + + +void pump::cost() { + string file_name = RUNTIME + name + ".cost"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + +void pump::power() { + string file_name = RUNTIME + name + ".power"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout << "\t>>" << W; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.hpp index dbcacfd5005ca04ff4cc2f45b02d8ef3bd55af37..aac9e6bea209a0cf9177dcdcc7f3bdd63d9030e6 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/pump.hpp @@ -1,46 +1,46 @@ -/* -This unit takes one input stream and divides in two or more -output streams. The pressure and temparature of output streams -are the same as the input's. -(ref : McCabe, Smith & Harriott) - -Structure in the .process file: -pump {name} {index of input stream} {index of output stream} {output pressure in atm} {efficiency, between 0 and 1} - -How to use: - 1- Call the constructor: pump1 = new pump(in, out); - 2- Set conditions: pump1->set(P_output, efficiency); - 3- Set the name: pump1->set(name); - 4- Solve: pump1->solve(); -*/ -#ifndef PUMP_H -#define PUMP_H - -#include "stream.hpp" -using namespace std; - -class pump -{ -private: - int i, j, n; - double state, tmp, tmp1; - bool success; - string name; - stream *in; //pointer to input stream - stream *out; //pointer to output stream - -public: - double P, W, eta; //output presure in atm, work in kW and efficiency - pump(stream* s1, stream* s2) {in=s1; out=s2; success=true; W=0.0; n=0; tmp=0.0;} - ~pump(){} - void set(double p, double e){P = p; eta = e; state=in->quality();} - void set(const string & n) { name = n; } - bool solve(); //finds the temperature and computes mass balance - void write(); - void cost(); - double get_cost(); // calcule W aussi - double get_power() const { return W; } - - void power(); -}; -#endif +/* +This unit takes one input stream and divides in two or more +output streams. The pressure and temparature of output streams +are the same as the input's. +(ref : McCabe, Smith & Harriott) + +Structure in the .process file: +pump {name} {index of input stream} {index of output stream} {output pressure in atm} {efficiency, between 0 and 1} + +How to use: + 1- Call the constructor: pump1 = new pump(in, out); + 2- Set conditions: pump1->set(P_output, efficiency); + 3- Set the name: pump1->set(name); + 4- Solve: pump1->solve(); +*/ +#ifndef PUMP_H +#define PUMP_H + +#include "stream.hpp" +using namespace std; + +class pump +{ +private: + int i, j, n; + double state, tmp, tmp1; + bool success; + string name; + stream *in; //pointer to input stream + stream *out; //pointer to output stream + +public: + double P, W, eta; //output presure in atm, work in kW and efficiency + pump(stream* s1, stream* s2) {in=s1; out=s2; success=true; W=0.0; n=0; tmp=0.0;} + ~pump(){} + void set(double p, double e){P = p; eta = e; state=in->quality();} + void set(const string & n) { name = n; } + bool solve(); //finds the temperature and computes mass balance + void write(); + void cost(); + double get_cost(); // calcule W aussi + double get_power() const { return W; } + + void power(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.cpp index ee658e5b654b82ee3560805b5a519f44cbc97a14..9eaafc1a52eb29cacd9e13768a770b8b28d8465c 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.cpp @@ -1,204 +1,204 @@ -#include "reaction.hpp" -using namespace std; - - -int reaction::find_chemical ( const string & chem_name ) const { - for ( int i = 0 ; i < m ; i++ ) - if ( list[i]->CAS == chem_name ) - return i; - return -1; -} - -// donnees hardcodees -reaction::reaction ( const string & in1 , int dim , chemical ** in2 ) { - - m = dim; // nbre de chemicals - list = in2; // liste des chemicals - - n = new double[m]; - safe_n = new double[m]; - safe_a = new double[m]; - a = new double[m]; - - int i , j; - for ( i = 0 ; i < m ; i++ ) { - a[i]=0.0; - n[i]=0.0; - } - - // 1/5 : - if ( in1 == "eb2sty" ) { - k0 = 3.525e5; - E = 90.85; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10a\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10b\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("100-42-5")) < 0 ) { - cout << "ERROR 10c\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 2/5 : - else if ( in1 == "sty2eb" ) { - k0 = 2.754e-4; - E = -18.653; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10d\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10e\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("100-42-5")) < 0 ) { - cout << "ERROR 10f\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - } - - // 3/5 : - else if ( in1 == "eb2bz" ) { - k0 = 9.577e4; - E = 111.375; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10g\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("71-43-2")) < 0 ) { - cout << "ERROR 10h\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-85-1")) < 0 ) { - cout << "ERROR 10i\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 4/5 : - else if ( in1 == "eb2tol" ) { - k0 = 6.077e8; - E = 207.850; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10j\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10k\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("108-88-3")) < 0 ) { - cout << "ERROR 10l\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-82-8")) < 0 ) { - cout << "ERROR 10m\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 5/5 : - else if ( in1 == "tol2bz" ) { - k0 = 1; - E = 19.038; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10n\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 0.5; - if ( (j = find_chemical ("108-88-3")) < 0 ) { - cout << "ERROR 10o\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("71-43-2")) < 0 ) { - cout << "ERROR 10p\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-82-8")) < 0 ) { - cout << "ERROR 10q\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - else { - cout << "ERROR 12\n\n"; - exit(0); - } - - for ( i = 0 ; i < m ; i++ ) { - safe_n[i]=n[i]; - safe_a[i]=a[i]; - } -} - -reaction::~reaction() { - delete [] a; - delete [] n; - delete [] safe_n; - delete [] safe_a; -} - -double reaction::dHr(double T) -{ - int i , j; - for (i=0;i<m;i++) - if(safe_a[i]!=a[i]) - { - if(a[i]>safe_a[i]) a[i]=safe_a[i]; - else safe_a[i]=a[i]; - } - double tmp=0.0; - for (i=0;i<m;i++) tmp += a[i]*list[i]->Ho; - if(fabs(T-298)>EPS) - for (i=0;i<m;i++) - for (j=1;j<=4;j++) tmp += a[i]*list[i]->Cp_param[j-1]*(pow(T,j)-pow(298.0,j))/j/1000.0; - return tmp; -} - -double reaction::rate(double T, double* C) -{ - double tmp = k0*exp(-1000*E/8.3144/T); - for ( int i=0;i<m;i++) - { - if(safe_n[i]!=n[i]) n[i]=safe_n[i]; - if(C[i]>EPS && fabs(n[i])>EPS) tmp *= pow(C[i], n[i]); - } - return tmp; -} +#include "reaction.hpp" +using namespace std; + + +int reaction::find_chemical ( const string & chem_name ) const { + for ( int i = 0 ; i < m ; i++ ) + if ( list[i]->CAS == chem_name ) + return i; + return -1; +} + +// donnees hardcodees +reaction::reaction ( const string & in1 , int dim , chemical ** in2 ) { + + m = dim; // nbre de chemicals + list = in2; // liste des chemicals + + n = new double[m]; + safe_n = new double[m]; + safe_a = new double[m]; + a = new double[m]; + + int i , j; + for ( i = 0 ; i < m ; i++ ) { + a[i]=0.0; + n[i]=0.0; + } + + // 1/5 : + if ( in1 == "eb2sty" ) { + k0 = 3.525e5; + E = 90.85; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10a\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10b\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("100-42-5")) < 0 ) { + cout << "ERROR 10c\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 2/5 : + else if ( in1 == "sty2eb" ) { + k0 = 2.754e-4; + E = -18.653; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10d\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10e\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("100-42-5")) < 0 ) { + cout << "ERROR 10f\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + } + + // 3/5 : + else if ( in1 == "eb2bz" ) { + k0 = 9.577e4; + E = 111.375; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10g\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("71-43-2")) < 0 ) { + cout << "ERROR 10h\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-85-1")) < 0 ) { + cout << "ERROR 10i\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 4/5 : + else if ( in1 == "eb2tol" ) { + k0 = 6.077e8; + E = 207.850; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10j\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10k\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("108-88-3")) < 0 ) { + cout << "ERROR 10l\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-82-8")) < 0 ) { + cout << "ERROR 10m\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 5/5 : + else if ( in1 == "tol2bz" ) { + k0 = 1; + E = 19.038; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10n\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 0.5; + if ( (j = find_chemical ("108-88-3")) < 0 ) { + cout << "ERROR 10o\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("71-43-2")) < 0 ) { + cout << "ERROR 10p\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-82-8")) < 0 ) { + cout << "ERROR 10q\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + else { + cout << "ERROR 12\n\n"; + exit(0); + } + + for ( i = 0 ; i < m ; i++ ) { + safe_n[i]=n[i]; + safe_a[i]=a[i]; + } +} + +reaction::~reaction() { + delete [] a; + delete [] n; + delete [] safe_n; + delete [] safe_a; +} + +double reaction::dHr(double T) +{ + int i , j; + for (i=0;i<m;i++) + if(safe_a[i]!=a[i]) + { + if(a[i]>safe_a[i]) a[i]=safe_a[i]; + else safe_a[i]=a[i]; + } + double tmp=0.0; + for (i=0;i<m;i++) tmp += a[i]*list[i]->Ho; + if(fabs(T-298)>EPS) + for (i=0;i<m;i++) + for (j=1;j<=4;j++) tmp += a[i]*list[i]->Cp_param[j-1]*(pow(T,j)-pow(298.0,j))/j/1000.0; + return tmp; +} + +double reaction::rate(double T, double* C) +{ + double tmp = k0*exp(-1000*E/8.3144/T); + for ( int i=0;i<m;i++) + { + if(safe_n[i]!=n[i]) n[i]=safe_n[i]; + if(C[i]>EPS && fabs(n[i])>EPS) tmp *= pow(C[i], n[i]); + } + return tmp; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.hpp index f05b27e4589a1e0443a3911532d8f8b4e7f6caeb..1456e0d2bf24b59b66a76788fd8fdfa7ed5d6672 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reaction.hpp @@ -1,32 +1,32 @@ -#ifndef REACTION_H -#define REACTION_H - -#include "chemical.hpp" -using namespace std; - -class reaction { -private: - - int m; - double *n, k0, E, Hr, *safe_n, *safe_a; - // double tmp; -// char file[41], line[31]; - chemical ** list; -// ifstream in; - // ofstream logf; - // terminator *end; - - int find_chemical ( const string & chem_name ) const; - -public: - // reaction(){}; - reaction ( const string & , int , chemical ** ); - ~reaction(); - double *a; //contains the molar coefficients - double dHr(double); //returns heat of rection at T, in kJ/mol - double rate(double, double*); //returns rate of reaction aT and C[], in mol/s.m3 - -// void show_name(){cout<<name;} -}; - -#endif +#ifndef REACTION_H +#define REACTION_H + +#include "chemical.hpp" +using namespace std; + +class reaction { +private: + + int m; + double *n, k0, E, Hr, *safe_n, *safe_a; + // double tmp; +// char file[41], line[31]; + chemical ** list; +// ifstream in; + // ofstream logf; + // terminator *end; + + int find_chemical ( const string & chem_name ) const; + +public: + // reaction(){}; + reaction ( const string & , int , chemical ** ); + ~reaction(); + double *a; //contains the molar coefficients + double dHr(double); //returns heat of rection at T, in kJ/mol + double rate(double, double*); //returns rate of reaction aT and C[], in mol/s.m3 + +// void show_name(){cout<<name;} +}; + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.cpp index 0f0ddae03673fe3ccd6ad46ef92158393d835e32..7f6e3a9455b13cecce0397ef8540e84a8a3d46f7 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.cpp @@ -1,100 +1,100 @@ -#include "reactor.hpp" -using namespace std; - -template<class TYPE> -reactor<TYPE>::reactor(stream* s1, stream* s2) -{ - in = s1; - out = s2; - - model = NULL; -} - -template<class TYPE> -reactor<TYPE>::~reactor() { - for ( i = 0 ; i < n ; i++ ) - delete rx[i]; - delete [] rx; - for ( i = 0 ; i < m ; i++ ) - delete table[i]; - delete [] table; - - if (model) - delete model; -} - -template<class TYPE> -void reactor<TYPE>::set ( double l , double d , int nb , const string * list_rx ) { - m = in->nb; - n = nb; - L = l; - D = d; - V = pi*pow(D/2.0, 2)*L; - - double * yields = new double [n]; - - rx = new reaction * [n]; - for ( j = 0 ; j < n ; j++ ) - rx[j] = new reaction ( list_rx[j] , m , in->chem ); - - table = new double * [m]; - for ( i = 0 ; i < m ; i++ ) - table[i] = new double[n]; - for ( j = 0 ; j < n ; j++ ) - for ( i = 0 ; i < m ; i++ ) - table[i][j] = rx[j]->a[i]; - for ( j = 0 ; j < n ; j++ ) { - yields[j]=0.0; - for ( i = 0 ; i < m ; i++ ) - if ( table[i][j] < 0 ) { - yields[j]=in->chem[i]->n(); - i=m; - } - } - - delete [] yields; - -} - -template<class TYPE> -bool reactor<TYPE>::solve() { - - if (model) - delete model; - model = new TYPE(in, out, table, n, rx, U, Ta); - model->set(name); - model->set(L,D); - - success = model->run(); - - // if(fabs(in->m-out->m)>sqrt(EPS)) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(in->m-out->m)/in->m<<").\n"; - // log.close(); - // } - - - // out->write(); // WRITE TOTO - - return success; -} - -template<class TYPE> -void reactor<TYPE>::write ( void ) { - - cout << setprecision(6); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in : " << in->name; - cout << endl << "\t>> stream out : " << out->name; - cout << endl << "\t>> P = " << in->P - << " atm, T(in) = " << in->T << ", T(out) = " << out->T << " K"; - cout << endl << "\t>> L = " << L << ", D = " << D << " m"; - if (success) - cout << " (converge normally)"; - cout << "\n\tEND\n\n"; - model->cost(); - model->water(); -} +#include "reactor.hpp" +using namespace std; + +template<class TYPE> +reactor<TYPE>::reactor(stream* s1, stream* s2) +{ + in = s1; + out = s2; + + model = NULL; +} + +template<class TYPE> +reactor<TYPE>::~reactor() { + for ( i = 0 ; i < n ; i++ ) + delete rx[i]; + delete [] rx; + for ( i = 0 ; i < m ; i++ ) + delete table[i]; + delete [] table; + + if (model) + delete model; +} + +template<class TYPE> +void reactor<TYPE>::set ( double l , double d , int nb , const string * list_rx ) { + m = in->nb; + n = nb; + L = l; + D = d; + V = pi*pow(D/2.0, 2)*L; + + double * yields = new double [n]; + + rx = new reaction * [n]; + for ( j = 0 ; j < n ; j++ ) + rx[j] = new reaction ( list_rx[j] , m , in->chem ); + + table = new double * [m]; + for ( i = 0 ; i < m ; i++ ) + table[i] = new double[n]; + for ( j = 0 ; j < n ; j++ ) + for ( i = 0 ; i < m ; i++ ) + table[i][j] = rx[j]->a[i]; + for ( j = 0 ; j < n ; j++ ) { + yields[j]=0.0; + for ( i = 0 ; i < m ; i++ ) + if ( table[i][j] < 0 ) { + yields[j]=in->chem[i]->n(); + i=m; + } + } + + delete [] yields; + +} + +template<class TYPE> +bool reactor<TYPE>::solve() { + + if (model) + delete model; + model = new TYPE(in, out, table, n, rx, U, Ta); + model->set(name); + model->set(L,D); + + success = model->run(); + + // if(fabs(in->m-out->m)>sqrt(EPS)) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(in->m-out->m)/in->m<<").\n"; + // log.close(); + // } + + + // out->write(); // WRITE TOTO + + return success; +} + +template<class TYPE> +void reactor<TYPE>::write ( void ) { + + cout << setprecision(6); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in : " << in->name; + cout << endl << "\t>> stream out : " << out->name; + cout << endl << "\t>> P = " << in->P + << " atm, T(in) = " << in->T << ", T(out) = " << out->T << " K"; + cout << endl << "\t>> L = " << L << ", D = " << D << " m"; + if (success) + cout << " (converge normally)"; + cout << "\n\tEND\n\n"; + model->cost(); + model->water(); +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.hpp index 78f936fe00e0bf1fd35f0487f3e8eb8e295a84a5..af0d2810711e78ab8b2a3dcee4cde090396f2c58 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/reactor.hpp @@ -1,48 +1,48 @@ -/* -This unit simulates a chemical reactor. Actually, only the pfr can be used. -(ref : Fogler). - -Structure in the .process file: -reactor {name} {pfr or cstr} {index of input stream} {index of output stream} {length in m} {diameter in m} {nb_react, list of reactions occuring} {U in kW/m2.K}{Ta in K} - -How to use: - 1- Call the constructor : react = new reactor<pfr or cstr>(in, out); - 2- Set dimensions and reactions : react->set(length, diameter, nb_react, list_react); //list_react is the list of reactions names - 3- Set cooling parameters : react->set(U, Ta); - 4- Set the name : react->set(name); - 5- Run the model: react->solve(); -*/ -#ifndef REACTOR_H -#define REACTOR_H - -#include "pfr.hpp" -using namespace std; - -template<class TYPE> -class reactor { -private: - // ofstream log; - bool success; - string name; - int i ,j, m, n; - double V, L, D, U, Ta; - stream *in, *out; - TYPE *model; - reaction ** rx; - double ** table; - -public: - // reactor(){}; - reactor(stream*, stream*); - void set( const string & n) { name = n; } - void set(double, double, int, const string * ); - void set(double u, double ta) {U=u;Ta=ta;} - bool solve(); - void write(); - - double get_cost ( void ) const { return model->get_cost() ; } - double get_water ( void ) const { return model->get_water(); } - - ~reactor(); -}; -#endif +/* +This unit simulates a chemical reactor. Actually, only the pfr can be used. +(ref : Fogler). + +Structure in the .process file: +reactor {name} {pfr or cstr} {index of input stream} {index of output stream} {length in m} {diameter in m} {nb_react, list of reactions occuring} {U in kW/m2.K}{Ta in K} + +How to use: + 1- Call the constructor : react = new reactor<pfr or cstr>(in, out); + 2- Set dimensions and reactions : react->set(length, diameter, nb_react, list_react); //list_react is the list of reactions names + 3- Set cooling parameters : react->set(U, Ta); + 4- Set the name : react->set(name); + 5- Run the model: react->solve(); +*/ +#ifndef REACTOR_H +#define REACTOR_H + +#include "pfr.hpp" +using namespace std; + +template<class TYPE> +class reactor { +private: + // ofstream log; + bool success; + string name; + int i ,j, m, n; + double V, L, D, U, Ta; + stream *in, *out; + TYPE *model; + reaction ** rx; + double ** table; + +public: + // reactor(){}; + reactor(stream*, stream*); + void set( const string & n) { name = n; } + void set(double, double, int, const string * ); + void set(double u, double ta) {U=u;Ta=ta;} + bool solve(); + void write(); + + double get_cost ( void ) const { return model->get_cost() ; } + double get_water ( void ) const { return model->get_water(); } + + ~reactor(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.cpp index 79e5d049cd839cf672a3eb71e48c6d976119c25f..e8582e03da28e148ba43074dbff9b4e4a5ad4069 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.cpp @@ -1,47 +1,47 @@ -#include "secant.hpp" -using namespace std; - -template <class E> -secant<E>::secant() -{ - x_last=0; - x_now=0; - x_next=0; - f_last=0; - f_now=0; - OK=false; -} - -template <class E> -void secant<E>::set(E* tmp, double x1, double x2) -{ - unit=tmp; - x_last=x1; - x_now=x2; - OK=false; -} - -template <class E> -bool secant<E>::run() -{ - // if(DEBUG) cout<<endl<<"begin solve secant"; - f_last = unit->f(x_last); - for (i=1; i<MAX_ITER_SECANT; i++) - { - f_now = unit->f(x_now); - // if(DEBUG) cout<<endl<<" x = "<<x_now<<" f(x) = "<<f_now; - x_next = x_now - (f_now*(x_now-x_last)/(f_now-f_last)); - if (fabs((x_next-x_now)/x_now)<=TOL_SECANT) - { - i=MAX_ITER_SECANT; - OK=true; - } - else - { - x_last=x_now; - f_last=f_now; - x_now=x_next; - } - } - return OK; -} +#include "secant.hpp" +using namespace std; + +template <class E> +secant<E>::secant() +{ + x_last=0; + x_now=0; + x_next=0; + f_last=0; + f_now=0; + OK=false; +} + +template <class E> +void secant<E>::set(E* tmp, double x1, double x2) +{ + unit=tmp; + x_last=x1; + x_now=x2; + OK=false; +} + +template <class E> +bool secant<E>::run() +{ + // if(DEBUG) cout<<endl<<"begin solve secant"; + f_last = unit->f(x_last); + for (i=1; i<MAX_ITER_SECANT; i++) + { + f_now = unit->f(x_now); + // if(DEBUG) cout<<endl<<" x = "<<x_now<<" f(x) = "<<f_now; + x_next = x_now - (f_now*(x_now-x_last)/(f_now-f_last)); + if (fabs((x_next-x_now)/x_now)<=TOL_SECANT) + { + i=MAX_ITER_SECANT; + OK=true; + } + else + { + x_last=x_now; + f_last=f_now; + x_now=x_next; + } + } + return OK; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.hpp index d1bb096e5c0267e24add5f95f58caa6523caa3ee..a04cbc542af177484e56bbaa924df887a2c2cdc4 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/secant.hpp @@ -1,31 +1,31 @@ -/* -To use the secant solver to find the root of a scalar function: - (the parametric object E must have public function such as E->f(x), - where x is the point at which evaluate f.) - 1- construct the solver : solver = new secant<E>(); - 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are two required initial points - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed -*/ -#ifndef SECANT_H -#define SECANT_H - -#include "defines.hpp" -using namespace std; - - -template <class E> -class secant { -private: - double x_last, x_now, x_next; - double f_last, f_now, error; - int i; - bool OK; - E *unit; - -public: - secant(); - void set(E*, double, double); - bool run(); - ~secant(){} -}; -#endif +/* +To use the secant solver to find the root of a scalar function: + (the parametric object E must have public function such as E->f(x), + where x is the point at which evaluate f.) + 1- construct the solver : solver = new secant<E>(); + 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are two required initial points + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed +*/ +#ifndef SECANT_H +#define SECANT_H + +#include "defines.hpp" +using namespace std; + + +template <class E> +class secant { +private: + double x_last, x_now, x_next; + double f_last, f_now, error; + int i; + bool OK; + E *unit; + +public: + secant(); + void set(E*, double, double); + bool run(); + ~secant(){} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.cpp index 0b2df2008515f202bf61bc495dc205e53d345e4d..75216ae65c7d270cc5ec7d40495dd7eac8e31163 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.cpp @@ -1,538 +1,538 @@ -#include "servor.hpp" -#include "reactor.cpp" -using namespace std; - -/*---------------------------------------------------------------------*/ -servor::servor ( int nb_u , int n2 , stream ** streams ) { - nb = nb_u; - nb_s = n2; - type = new string[nb]; - name = new string[nb]; - s = streams; - - -// for (int i=0; i<nb; i++) -// { -// type[i]=new char[31]; -// name[i]=new char[31]; -// } -// cursor=0; -// s = s_list; -// // end = new terminator("\0"); -// mix1=NULL; -// split1=NULL; -// flash1=NULL; -// pump1=NULL; -// col=NULL; -// react_pfr=NULL; -// react_cstr=NULL; -// heat=NULL; - - burn = new burner ( s[0]->nb , s[0]->chem ); -} - -/*---------------------------------------------------------------------*/ -servor::~servor() { - delete [] type; - delete [] name; - delete burn; -} - -/*---------------------------------------------------------------------*/ -bool servor::solve_process ( const double * x , double * y ) { - - - for ( i = 0 ; i < 8 ; i++ ) - costs[i] = 0.0; - - k = 0; - norm = 1.0 / TOL_WEGSTEIN; - - for ( cursor = 0 ; cursor < nb ; cursor++ ) { - - if (type[cursor] == "mix" ) { - do_mix_process(x); - } - else if ( type[cursor] == "split" ) { - do_split_process(x); - } - else if ( type[cursor] == "flash" ) { - do_flash_process(x); - } - else if ( type[cursor] == "pump" ) { - do_pump_process(x); - } - else if ( type[cursor] == "heatx") { - do_heatx_process(x); - } - else if ( type[cursor] == "burner" ) { - do_burner_process(x,y); - } - else if ( type[cursor] == "column" ) { - do_column_process(x,y); - } - else if ( type[cursor] == "reactor" ) { - do_reactor_process(x); - } - else if ( type[cursor] == "loop" ) { - - recycle = 10; - end_recycle = 0; - do_loop_process(x); - } - else { - cout << "ERROR 18\n\n"; - exit(0); - } - - } - - return true; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_loop_process ( const double * x ) { - - // structure in the input file : - // loop - // name : "looping" - // index of recycle stream : 11 - // index of stream's beginning block : 7 - // index of stream's end block : 1 - - // TOTO -// if (k==0) -// cout << endl << " -> Wegstein iterations "; -// else if ( k <= 2 ) -// cout << endl << " -> loop " << setw(3) << k; -// else -// cout << endl << " -> loop " << setw(3) << k << " > error " << norm; - - // Get the two fisrst points - if ( k==0 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) - x_last[i] = s[recycle]->chem[i]->m; - end_loop = false; - } - - if ( k==1 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) { - x_now [i] = s[recycle]->chem[i]->m; - g_last[i] = s[recycle]->chem[i]->m; - } - - end_loop = false; - } - - if ( k == 2 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) - g_now[i] = s[recycle]->chem[i]->m; - end_loop=false; - } - k++; - - - // run the Wegstein algorithm - if ( k > 2 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) { - g_now[i] = s[recycle]->chem[i]->m; - - if ( fabs (x_now[i]-x_last[i]) > EPS ) - slope[i] = ( g_now[i] - g_last[i] ) / ( x_now[i] - x_last[i] ); - else - slope[i] = 0; - - theta[i] = 1.0 / (1.0-slope[i]); - if ( theta[i] < MIN_THETA ) - theta[i] = MIN_THETA; - if ( theta[i] > MAX_THETA ) - theta[i] = MAX_THETA; - x_next[i] = (1.0-theta[i])*x_now[i] + theta[i]*g_now[i]; - } - norm = 0.0; - for ( i = 0 ; i < s[0]->nb ; i++ ) - if ( fabs(x_now[i]) > EPS ) - norm += fabs (x_next[i]-x_now[i]) / fabs(x_now[i]); - - if ( norm > TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) { - s[recycle]->m = 0.0; - for ( i = 0 ; i < s[0]->nb ; i++ ) { - s[recycle]->chem[i]->m = x_next[i]; - s[recycle]->m += x_next[i]; - x_last[i] = x_now[i]; - g_last[i] = g_now[i]; - x_now[i] = x_next[i]; - } - end_loop=false; - } - if ( norm <= TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) - end_loop = true; - - } - - - if ( end_loop ) { - if ( k < MAX_ITER_WEGSTEIN && k > 3 ) { - // cout<<" OK"; // TOTO - // s[recycle]->write(); // WRITE TOTO - -// // WRITE TOTO : -// cout << "WRITE FILE " << RUNTIME << name[cursor] << ".unit" << " :\n\tBEGIN\n"; -// cout << "\t>> " << name[cursor]; -// cout << endl << "\t>> from block " << cursor+1 << " to block " << end_recycle+1; -// cout << endl << "\t>> Wegstein converged in " -// << k << " iterations (rel. err. " << norm << ")."; -// cout << "\n\tEND\n\n"; - - k = 0; - norm = 1.0/TOL_WEGSTEIN; - } -// else { -// log.open(MESSAGES, ios::app); -// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; -// log.close(); -// } - } - - - if ( !end_loop && k < MAX_ITER_WEGSTEIN ) - cursor = end_recycle-1; - if ( !end_loop && k==MAX_ITER_WEGSTEIN ) { -// log.open(MESSAGES, ios::app); -// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; -// log.close(); - k=0; - norm = 1.0/TOL_WEGSTEIN; - cursor=nb; - } - -} - -/*---------------------------------------------------------------------*/ -void servor::do_burner_process ( const double * x , double * y ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - // read parameters : - int i1 = 8; - int i2 = 13; - double f = x[6]; - - burn->set ( s[i1-1] , s[i2-1] ); - burn->set(f); - burn->set(name[cursor]); - - if ( burn->solve(y) ) { - // cout << "OK"; // TOTO - // burn->write(); // WRITE TOTO - costs[7] = burn->get_cost(); - } - else { - cout << "ERROR 20\n\n"; - exit(0); - } -} - -/*---------------------------------------------------------------------*/ -void servor::do_split_process ( const double * x ) -{ - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - int i1 = 9; - int i2 = 2; - int i_tab[2] = { 10 , 11 }; - double f_tab[2]; - f_tab[0] = x[5]; - f_tab[1] = 1-x[5]; - - stream * list1[2]; - list1[0] = s[i_tab[0]-1]; - list1[1] = s[i_tab[1]-1]; - - split * split1 = new split ( i2 , s[i1-1] , list1 ); - - split1->set(f_tab); - split1->set(name[cursor]); - if ( split1->solve() ) { - // cout<<"OK"; // TOTO - // split1->write(); // WRITE TOTO - } - else { - cout << "ERROR 19\n\n"; - exit(0); - } - delete split1; -} - -/*---------------------------------------------------------------------*/ -void servor::do_column_process ( const double * x , double * y ) { - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - double f1 , f2; - int i , i1 , i2; - int i_tab[2]; - double f = 1.0; - - if (name[cursor]=="sep-sty") { - i = 7; - i1 = 15; - i2 = 9; - i_tab[0] = 1; - i_tab[1] = 7; - f1 = f2 = x[2]; - } - else if (name[cursor]=="sep-bz") { - i = 10; - i1 = 12; - i2 = 14; - i_tab[0] = 5; - i_tab[1] = 1; - f1 = f2 = x[3]; - } - else { - cout << "ERROR 17\n\n"; - exit(0); - } - - column * col = new column ( s[i-1] , s[i1-1] , s[i2-1] ); - col->set ( f , i_tab[0] , f1 , i_tab[1] , f2 ); - col->set(name[cursor]); - if ( col->solve() ) { - //cout<<"OK"; // TOTO - //col->write(); // WRITE TOTO - - if (name[cursor]=="sep-sty") { - y[4] = col->get_N(); - costs[5] = col->get_cost(); - power[5] = col->get_power(); - water[5] = col->get_water(); - } - else { - y[5] = col->get_N(); - costs[6] = col->get_cost(); - power[4] = col->get_power(); - water[4] = col->get_water(); - } - } - else { - cout << "ERROR 15\n\n"; - exit(0); - } - delete col; -} - -/*---------------------------------------------------------------------*/ -void servor::do_flash_process ( const double * x ) { - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - double f1 = 1.0; - double f2 = x[7]; - // int i_tab [3] = { 6 , 7 , 8 }; - // flash * flash1 = new flash ( s[i_tab[0]-1] , s[i_tab[1]-1] , s[i_tab[2]-1] ); - flash * flash1 = new flash ( s[5] , s[6] , s[7] ); - - flash1->set(f1, f2); - flash1->set(name[cursor]); - if ( flash1->solve() ) { - // cout<<"OK"; // TOTO - // flash1->write(); // WRITE TOTO - costs[4] = flash1->get_cost(); - power[2] = flash1->get_power(); - water[1] = flash1->get_water(); - } - else { - cout << "ERROR 14\n\n"; - exit(0); - } - delete flash1; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_mix_process ( const double * x ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - // Read parameters (hardcode avec eb2sty.process) : - double f1 = 1.0; - int i1 = 3; - int i_tab[3] = { 1 , 12 , 11 }; - int i2 = 2; - - // We can solve the unit - stream * list2 = s[i2-1] , ** list1 = new stream * [i1]; - for ( int i = 0 ; i < i1 ; i++ ) - list1[i] = s[i_tab[i]-1]; - mix * mix1 = new mix ( i1 , list1 , list2 ); - mix1->set(f1); - mix1->set(name[cursor]); - if (mix1->solve()) { - // cout<<"OK"; // TOTO - // mix1->write(); // WRITE TOTO - } - else { - cout << "ERROR 6\n\n"; - exit(0); - } - delete mix1; - delete [] list1; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_pump_process ( const double * x ) { - - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters (hardcode avec eb2sty.process) : - int i1 = 2; - int i2 = 3; - double f1 = x[4]; - double f2 = 0.75; - - pump * pump1 = new pump ( s[i1-1] , s[i2-1] ); - pump1->set(f1,f2); - pump1->set(name[cursor]); - - - - // solve : - if ( pump1->solve() ) { - // cout<<"OK"; // TOTO - // pump1->write(); // WRITE TOTO - - power[0] = pump1->get_power(); - costs[0] = pump1->get_cost(); - } - else { - cout << "ERROR 7\n\n"; - exit(0); - } - - delete pump1; -} - -/*---------------------------------------------------------------------*/ -void servor::do_heatx_process ( const double * x ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - //Read parameters (idem) : - - bool b = false; - - // heater : - int i1; - int i2; - double f1; - - // heater : - if (name[cursor]=="heater") { - i1 = 3; - i2 = 4; - f1 = x[0]; - } - - // cooler : - else if (name[cursor]=="cooler") { - i1 = 5; - i2 = 6; - f1 = x[7]; - } - else { - cout << "ERROR 16\n\n"; - exit(0); - } - - double f2 = 0.85; - - // solve : - heatx * heat = new heatx ( b , s[i1-1] , s[i2-1] ); - heat->set(f1,f2); - heat->set(name[cursor]); - if (heat->solve()) { - // cout<<"OK"; // TOTO - // heat->write(); // WRITE TOTO - if (name[cursor]=="heater") { - costs[1] = heat->get_cost(); - power[3] = heat->get_power(); - water[2] = heat->get_water(); - } - else { - costs[3] = heat->get_cost(); - power[1] = heat->get_power(); - water[0] = heat->get_water(); - } - } - else { - cout << "ERROR 8\n\n"; - exit(0); - } - delete heat; -} - -/*---------------------------------------------------------------------*/ -void servor::do_reactor_process ( const double * x ) { - - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - // Read parameters (idem) : - int i1 = 4; - int i2 = 5; - - reactor<pfr> * react_pfr = new reactor<pfr> ( s[i1-1] , s[i2-1] ); - - react_pfr->set(name[cursor]); - - double f1 = x[1]; - double f2 = 0.5; - - string list[5] = { "eb2sty" , "sty2eb" , "eb2bz" , "eb2tol" , "tol2bz" }; - - i1 = 5; - - react_pfr->set(f1,f2,i1,list); - - f1 = 0.0; - f2 = 300.0; - - react_pfr->set(f1,f2); - - if ( react_pfr->solve() ) { - // cout<<"OK"; // TOTO - // react_pfr->write(); // WRITE TOTO - costs[2] = react_pfr->get_cost(); - water[3] = react_pfr->get_water(); - } - else { - cout << "ERROR 9\n\n"; - exit(0); - } - delete react_pfr; -} - - -double servor::get_costs_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 8 ; i++ ) - sum += ( (ARRONDI) ? arrondi(costs[i],6) : costs[i] ); - return sum; -} - -double servor::get_power_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 6 ; i++ ) - sum += ( (ARRONDI) ? arrondi(power[i],6) : power[i] ); - return sum; -} - -double servor::get_water_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 6 ; i++ ) - sum += ( (ARRONDI) ? arrondi(water[i],6) : water[i] ); - return sum; -} +#include "servor.hpp" +#include "reactor.cpp" +using namespace std; + +/*---------------------------------------------------------------------*/ +servor::servor ( int nb_u , int n2 , stream ** streams ) { + nb = nb_u; + nb_s = n2; + type = new string[nb]; + name = new string[nb]; + s = streams; + + +// for (int i=0; i<nb; i++) +// { +// type[i]=new char[31]; +// name[i]=new char[31]; +// } +// cursor=0; +// s = s_list; +// // end = new terminator("\0"); +// mix1=NULL; +// split1=NULL; +// flash1=NULL; +// pump1=NULL; +// col=NULL; +// react_pfr=NULL; +// react_cstr=NULL; +// heat=NULL; + + burn = new burner ( s[0]->nb , s[0]->chem ); +} + +/*---------------------------------------------------------------------*/ +servor::~servor() { + delete [] type; + delete [] name; + delete burn; +} + +/*---------------------------------------------------------------------*/ +bool servor::solve_process ( const double * x , double * y ) { + + + for ( i = 0 ; i < 8 ; i++ ) + costs[i] = 0.0; + + k = 0; + norm = 1.0 / TOL_WEGSTEIN; + + for ( cursor = 0 ; cursor < nb ; cursor++ ) { + + if (type[cursor] == "mix" ) { + do_mix_process(x); + } + else if ( type[cursor] == "split" ) { + do_split_process(x); + } + else if ( type[cursor] == "flash" ) { + do_flash_process(x); + } + else if ( type[cursor] == "pump" ) { + do_pump_process(x); + } + else if ( type[cursor] == "heatx") { + do_heatx_process(x); + } + else if ( type[cursor] == "burner" ) { + do_burner_process(x,y); + } + else if ( type[cursor] == "column" ) { + do_column_process(x,y); + } + else if ( type[cursor] == "reactor" ) { + do_reactor_process(x); + } + else if ( type[cursor] == "loop" ) { + + recycle = 10; + end_recycle = 0; + do_loop_process(x); + } + else { + cout << "ERROR 18\n\n"; + exit(0); + } + + } + + return true; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_loop_process ( const double * x ) { + + // structure in the input file : + // loop + // name : "looping" + // index of recycle stream : 11 + // index of stream's beginning block : 7 + // index of stream's end block : 1 + + // TOTO +// if (k==0) +// cout << endl << " -> Wegstein iterations "; +// else if ( k <= 2 ) +// cout << endl << " -> loop " << setw(3) << k; +// else +// cout << endl << " -> loop " << setw(3) << k << " > error " << norm; + + // Get the two fisrst points + if ( k==0 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) + x_last[i] = s[recycle]->chem[i]->m; + end_loop = false; + } + + if ( k==1 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) { + x_now [i] = s[recycle]->chem[i]->m; + g_last[i] = s[recycle]->chem[i]->m; + } + + end_loop = false; + } + + if ( k == 2 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) + g_now[i] = s[recycle]->chem[i]->m; + end_loop=false; + } + k++; + + + // run the Wegstein algorithm + if ( k > 2 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) { + g_now[i] = s[recycle]->chem[i]->m; + + if ( fabs (x_now[i]-x_last[i]) > EPS ) + slope[i] = ( g_now[i] - g_last[i] ) / ( x_now[i] - x_last[i] ); + else + slope[i] = 0; + + theta[i] = 1.0 / (1.0-slope[i]); + if ( theta[i] < MIN_THETA ) + theta[i] = MIN_THETA; + if ( theta[i] > MAX_THETA ) + theta[i] = MAX_THETA; + x_next[i] = (1.0-theta[i])*x_now[i] + theta[i]*g_now[i]; + } + norm = 0.0; + for ( i = 0 ; i < s[0]->nb ; i++ ) + if ( fabs(x_now[i]) > EPS ) + norm += fabs (x_next[i]-x_now[i]) / fabs(x_now[i]); + + if ( norm > TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) { + s[recycle]->m = 0.0; + for ( i = 0 ; i < s[0]->nb ; i++ ) { + s[recycle]->chem[i]->m = x_next[i]; + s[recycle]->m += x_next[i]; + x_last[i] = x_now[i]; + g_last[i] = g_now[i]; + x_now[i] = x_next[i]; + } + end_loop=false; + } + if ( norm <= TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) + end_loop = true; + + } + + + if ( end_loop ) { + if ( k < MAX_ITER_WEGSTEIN && k > 3 ) { + // cout<<" OK"; // TOTO + // s[recycle]->write(); // WRITE TOTO + +// // WRITE TOTO : +// cout << "WRITE FILE " << RUNTIME << name[cursor] << ".unit" << " :\n\tBEGIN\n"; +// cout << "\t>> " << name[cursor]; +// cout << endl << "\t>> from block " << cursor+1 << " to block " << end_recycle+1; +// cout << endl << "\t>> Wegstein converged in " +// << k << " iterations (rel. err. " << norm << ")."; +// cout << "\n\tEND\n\n"; + + k = 0; + norm = 1.0/TOL_WEGSTEIN; + } +// else { +// log.open(MESSAGES, ios::app); +// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; +// log.close(); +// } + } + + + if ( !end_loop && k < MAX_ITER_WEGSTEIN ) + cursor = end_recycle-1; + if ( !end_loop && k==MAX_ITER_WEGSTEIN ) { +// log.open(MESSAGES, ios::app); +// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; +// log.close(); + k=0; + norm = 1.0/TOL_WEGSTEIN; + cursor=nb; + } + +} + +/*---------------------------------------------------------------------*/ +void servor::do_burner_process ( const double * x , double * y ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + // read parameters : + int i1 = 8; + int i2 = 13; + double f = x[6]; + + burn->set ( s[i1-1] , s[i2-1] ); + burn->set(f); + burn->set(name[cursor]); + + if ( burn->solve(y) ) { + // cout << "OK"; // TOTO + // burn->write(); // WRITE TOTO + costs[7] = burn->get_cost(); + } + else { + cout << "ERROR 20\n\n"; + exit(0); + } +} + +/*---------------------------------------------------------------------*/ +void servor::do_split_process ( const double * x ) +{ + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + int i1 = 9; + int i2 = 2; + int i_tab[2] = { 10 , 11 }; + double f_tab[2]; + f_tab[0] = x[5]; + f_tab[1] = 1-x[5]; + + stream * list1[2]; + list1[0] = s[i_tab[0]-1]; + list1[1] = s[i_tab[1]-1]; + + split * split1 = new split ( i2 , s[i1-1] , list1 ); + + split1->set(f_tab); + split1->set(name[cursor]); + if ( split1->solve() ) { + // cout<<"OK"; // TOTO + // split1->write(); // WRITE TOTO + } + else { + cout << "ERROR 19\n\n"; + exit(0); + } + delete split1; +} + +/*---------------------------------------------------------------------*/ +void servor::do_column_process ( const double * x , double * y ) { + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + double f1 , f2; + int i , i1 , i2; + int i_tab[2]; + double f = 1.0; + + if (name[cursor]=="sep-sty") { + i = 7; + i1 = 15; + i2 = 9; + i_tab[0] = 1; + i_tab[1] = 7; + f1 = f2 = x[2]; + } + else if (name[cursor]=="sep-bz") { + i = 10; + i1 = 12; + i2 = 14; + i_tab[0] = 5; + i_tab[1] = 1; + f1 = f2 = x[3]; + } + else { + cout << "ERROR 17\n\n"; + exit(0); + } + + column * col = new column ( s[i-1] , s[i1-1] , s[i2-1] ); + col->set ( f , i_tab[0] , f1 , i_tab[1] , f2 ); + col->set(name[cursor]); + if ( col->solve() ) { + //cout<<"OK"; // TOTO + //col->write(); // WRITE TOTO + + if (name[cursor]=="sep-sty") { + y[4] = col->get_N(); + costs[5] = col->get_cost(); + power[5] = col->get_power(); + water[5] = col->get_water(); + } + else { + y[5] = col->get_N(); + costs[6] = col->get_cost(); + power[4] = col->get_power(); + water[4] = col->get_water(); + } + } + else { + cout << "ERROR 15\n\n"; + exit(0); + } + delete col; +} + +/*---------------------------------------------------------------------*/ +void servor::do_flash_process ( const double * x ) { + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + double f1 = 1.0; + double f2 = x[7]; + // int i_tab [3] = { 6 , 7 , 8 }; + // flash * flash1 = new flash ( s[i_tab[0]-1] , s[i_tab[1]-1] , s[i_tab[2]-1] ); + flash * flash1 = new flash ( s[5] , s[6] , s[7] ); + + flash1->set(f1, f2); + flash1->set(name[cursor]); + if ( flash1->solve() ) { + // cout<<"OK"; // TOTO + // flash1->write(); // WRITE TOTO + costs[4] = flash1->get_cost(); + power[2] = flash1->get_power(); + water[1] = flash1->get_water(); + } + else { + cout << "ERROR 14\n\n"; + exit(0); + } + delete flash1; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_mix_process ( const double * x ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + // Read parameters (hardcode avec eb2sty.process) : + double f1 = 1.0; + int i1 = 3; + int i_tab[3] = { 1 , 12 , 11 }; + int i2 = 2; + + // We can solve the unit + stream * list2 = s[i2-1] , ** list1 = new stream * [i1]; + for ( int i = 0 ; i < i1 ; i++ ) + list1[i] = s[i_tab[i]-1]; + mix * mix1 = new mix ( i1 , list1 , list2 ); + mix1->set(f1); + mix1->set(name[cursor]); + if (mix1->solve()) { + // cout<<"OK"; // TOTO + // mix1->write(); // WRITE TOTO + } + else { + cout << "ERROR 6\n\n"; + exit(0); + } + delete mix1; + delete [] list1; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_pump_process ( const double * x ) { + + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters (hardcode avec eb2sty.process) : + int i1 = 2; + int i2 = 3; + double f1 = x[4]; + double f2 = 0.75; + + pump * pump1 = new pump ( s[i1-1] , s[i2-1] ); + pump1->set(f1,f2); + pump1->set(name[cursor]); + + + + // solve : + if ( pump1->solve() ) { + // cout<<"OK"; // TOTO + // pump1->write(); // WRITE TOTO + + power[0] = pump1->get_power(); + costs[0] = pump1->get_cost(); + } + else { + cout << "ERROR 7\n\n"; + exit(0); + } + + delete pump1; +} + +/*---------------------------------------------------------------------*/ +void servor::do_heatx_process ( const double * x ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + //Read parameters (idem) : + + bool b = false; + + // heater : + int i1; + int i2; + double f1; + + // heater : + if (name[cursor]=="heater") { + i1 = 3; + i2 = 4; + f1 = x[0]; + } + + // cooler : + else if (name[cursor]=="cooler") { + i1 = 5; + i2 = 6; + f1 = x[7]; + } + else { + cout << "ERROR 16\n\n"; + exit(0); + } + + double f2 = 0.85; + + // solve : + heatx * heat = new heatx ( b , s[i1-1] , s[i2-1] ); + heat->set(f1,f2); + heat->set(name[cursor]); + if (heat->solve()) { + // cout<<"OK"; // TOTO + // heat->write(); // WRITE TOTO + if (name[cursor]=="heater") { + costs[1] = heat->get_cost(); + power[3] = heat->get_power(); + water[2] = heat->get_water(); + } + else { + costs[3] = heat->get_cost(); + power[1] = heat->get_power(); + water[0] = heat->get_water(); + } + } + else { + cout << "ERROR 8\n\n"; + exit(0); + } + delete heat; +} + +/*---------------------------------------------------------------------*/ +void servor::do_reactor_process ( const double * x ) { + + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + // Read parameters (idem) : + int i1 = 4; + int i2 = 5; + + reactor<pfr> * react_pfr = new reactor<pfr> ( s[i1-1] , s[i2-1] ); + + react_pfr->set(name[cursor]); + + double f1 = x[1]; + double f2 = 0.5; + + string list[5] = { "eb2sty" , "sty2eb" , "eb2bz" , "eb2tol" , "tol2bz" }; + + i1 = 5; + + react_pfr->set(f1,f2,i1,list); + + f1 = 0.0; + f2 = 300.0; + + react_pfr->set(f1,f2); + + if ( react_pfr->solve() ) { + // cout<<"OK"; // TOTO + // react_pfr->write(); // WRITE TOTO + costs[2] = react_pfr->get_cost(); + water[3] = react_pfr->get_water(); + } + else { + cout << "ERROR 9\n\n"; + exit(0); + } + delete react_pfr; +} + + +double servor::get_costs_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 8 ; i++ ) + sum += ( (ARRONDI) ? arrondi(costs[i],6) : costs[i] ); + return sum; +} + +double servor::get_power_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 6 ; i++ ) + sum += ( (ARRONDI) ? arrondi(power[i],6) : power[i] ); + return sum; +} + +double servor::get_water_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 6 ; i++ ) + sum += ( (ARRONDI) ? arrondi(water[i],6) : water[i] ); + return sum; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.hpp index e048542375b8df2942bfd10dd2117cfe6622b53c..73b1cd2ef8efb77cae3833eff494a03b00db71d8 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/servor.hpp @@ -1,101 +1,101 @@ -#ifndef SERVOR_H -#define SERVOR_H - -//Possible units -#include "mix.hpp" -#include "split.hpp" -#include "pump.hpp" -#include "column.hpp" -#include "reactor.hpp" -#include "heatx.hpp" -#include "burner.hpp" - -using namespace std; - -class servor { - -public: - - double norm; - int k; - int nb; - int nb_s; - string * type; - string * name; - int cursor; - stream ** s; - - int recycle; - int end_recycle; - int i; - bool end_loop; - - double x_last[MAX_DIM]; - double x_now [MAX_DIM]; - double x_next[MAX_DIM]; - double g_last[MAX_DIM]; - double g_now [MAX_DIM]; - double slope [MAX_DIM]; - double theta [MAX_DIM]; - - double costs[8]; - double power[6]; - double water[6]; - - - // clock_t beg_time, end_time; - // bool OK, b, solve_OK; - // char filename[31], kind[10], **list, process_name[31]; - // double f, f1, f2, f_tab[10], t; - // int i, i1, i2, i_tab[10], time; - // stream *list2; - -// double theta[MAX_DIM], slope[MAX_DIM], norm; -// bool end_loop; -// int k, recycle, end_recycle; -// char loop_name[31]; - -// mix *mix1; void do_mix(); -// split *split1; -// flash *flash1; void do_flash(); -// pump *pump1; void do_pump(); -// column *col; void do_column(); -// reactor<pfr> *react_pfr; void do_reactor(); -// reactor<cstr> *react_cstr; -// heatx *heat; void do_heatx(); - burner * burn; - -// stream *s; //list of streams -// friend void out_of_memory(void){exit(0);} - - - // constructeur : - servor ( int , int , stream ** ); - - // destructeur : - ~servor(); - - -// void set(int t) {time=t;} -// void set(char n[31]) {strcpy(process_name, n);} - void do_split_process ( const double * x ); - void do_column_process ( const double * x , double * y ); - void do_flash_process ( const double * x ); - void do_mix_process ( const double * x ); - void do_pump_process ( const double * x ); - void do_heatx_process ( const double * x ); - void do_reactor_process ( const double * x ); - void do_burner_process ( const double * x , double * y ); - void do_loop_process ( const double * x ); - - bool solve_process ( const double * x , double * y ); //main solver of the software. - - double get_costs_sum ( void ) const; - - double get_power_sum ( void ) const; - - double get_water_sum ( void ) const; - - -}; -#endif +#ifndef SERVOR_H +#define SERVOR_H + +//Possible units +#include "mix.hpp" +#include "split.hpp" +#include "pump.hpp" +#include "column.hpp" +#include "reactor.hpp" +#include "heatx.hpp" +#include "burner.hpp" + +using namespace std; + +class servor { + +public: + + double norm; + int k; + int nb; + int nb_s; + string * type; + string * name; + int cursor; + stream ** s; + + int recycle; + int end_recycle; + int i; + bool end_loop; + + double x_last[MAX_DIM]; + double x_now [MAX_DIM]; + double x_next[MAX_DIM]; + double g_last[MAX_DIM]; + double g_now [MAX_DIM]; + double slope [MAX_DIM]; + double theta [MAX_DIM]; + + double costs[8]; + double power[6]; + double water[6]; + + + // clock_t beg_time, end_time; + // bool OK, b, solve_OK; + // char filename[31], kind[10], **list, process_name[31]; + // double f, f1, f2, f_tab[10], t; + // int i, i1, i2, i_tab[10], time; + // stream *list2; + +// double theta[MAX_DIM], slope[MAX_DIM], norm; +// bool end_loop; +// int k, recycle, end_recycle; +// char loop_name[31]; + +// mix *mix1; void do_mix(); +// split *split1; +// flash *flash1; void do_flash(); +// pump *pump1; void do_pump(); +// column *col; void do_column(); +// reactor<pfr> *react_pfr; void do_reactor(); +// reactor<cstr> *react_cstr; +// heatx *heat; void do_heatx(); + burner * burn; + +// stream *s; //list of streams +// friend void out_of_memory(void){exit(0);} + + + // constructeur : + servor ( int , int , stream ** ); + + // destructeur : + ~servor(); + + +// void set(int t) {time=t;} +// void set(char n[31]) {strcpy(process_name, n);} + void do_split_process ( const double * x ); + void do_column_process ( const double * x , double * y ); + void do_flash_process ( const double * x ); + void do_mix_process ( const double * x ); + void do_pump_process ( const double * x ); + void do_heatx_process ( const double * x ); + void do_reactor_process ( const double * x ); + void do_burner_process ( const double * x , double * y ); + void do_loop_process ( const double * x ); + + bool solve_process ( const double * x , double * y ); //main solver of the software. + + double get_costs_sum ( void ) const; + + double get_power_sum ( void ) const; + + double get_water_sum ( void ) const; + + +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.cpp index d3f48c90fb149e1ebdd627f3fa28b56c0f331bff..d14c519c6794b52ae69162e2455e248636ce0adc 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.cpp @@ -1,53 +1,53 @@ -#include "split.hpp" -using namespace std; - -split::split(int n, stream* s1, stream** s2) -{ - nb_out=n; - in = s1; - out= s2; - success = true; -} - -bool split::solve() -{ - tmp=0; - for (i=0;i<nb_out; i++) tmp+=frac[i]; - if(fabs(1-tmp)<=EPS) - { - success = true; - for (i=0; i<nb_out;i++) - { - out[i]->m=0; - for (j=0;j<in->nb;j++) - { - - out[i]->chem[j]->m = frac[i]*in->chem[j]->m; - out[i]->m += out[i]->chem[j]->m; - } - out[i]->set(in->P, in->T); - // out[i]->write(); // TOTO - } - } - tmp=0; for(i=0;i<nb_out;i++) tmp+=out[i]->m; - if(fabs(tmp-in->m)>EPS) - { -// logf.open(MESSAGES, ios::app); -// logf<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(tmp-in->m)/tmp<<").\n"; -// logf.close(); - success = false; - } - else success = true; - return success; -} - -void split::write() -{ - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout <<"\t>> "<<name; - cout << endl<<"\t>> stream in: "<<in->name;; - cout<<endl<<"\t>> streams out: "<<setprecision(3); - for ( i = 0 ; i < nb_out ; i++ ) - cout << out[i]->name<<" ("<<frac[i]<<") "; - cout << "\n\tEND\n\n"; -} +#include "split.hpp" +using namespace std; + +split::split(int n, stream* s1, stream** s2) +{ + nb_out=n; + in = s1; + out= s2; + success = true; +} + +bool split::solve() +{ + tmp=0; + for (i=0;i<nb_out; i++) tmp+=frac[i]; + if(fabs(1-tmp)<=EPS) + { + success = true; + for (i=0; i<nb_out;i++) + { + out[i]->m=0; + for (j=0;j<in->nb;j++) + { + + out[i]->chem[j]->m = frac[i]*in->chem[j]->m; + out[i]->m += out[i]->chem[j]->m; + } + out[i]->set(in->P, in->T); + // out[i]->write(); // TOTO + } + } + tmp=0; for(i=0;i<nb_out;i++) tmp+=out[i]->m; + if(fabs(tmp-in->m)>EPS) + { +// logf.open(MESSAGES, ios::app); +// logf<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(tmp-in->m)/tmp<<").\n"; +// logf.close(); + success = false; + } + else success = true; + return success; +} + +void split::write() +{ + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout <<"\t>> "<<name; + cout << endl<<"\t>> stream in: "<<in->name;; + cout<<endl<<"\t>> streams out: "<<setprecision(3); + for ( i = 0 ; i < nb_out ; i++ ) + cout << out[i]->name<<" ("<<frac[i]<<") "; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.hpp index 2c75638072d6ed52d32f8d48d0c4970069655230..7634f470e968c8cda76ed0f9642e7bce2ff1a195 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/split.hpp @@ -1,43 +1,43 @@ -/* -This unit takes one input stream and divides in two or more -output streams. The pressure and temparature of output streams -are the same as the input's. - -Structure in the .process file: -split {name} {index of input stream} {nb_out} {indexes of output streams and fractions of input} - -How to use: - 1- Call the constructor: split1 = new split(nb_out, in, list_out); - 2- Set split fractions: split1->set(fractions); - 3- Set the name: split1->set(name); - 4- Solve: split1->solve(); -*/ -#ifndef SPLIT_H -#define SPLIT_H - -#include "stream.hpp" -using namespace std; - -class split -{ -private: - - int i, j; - bool success; - double tmp; - string name; - int nb_out; //number of input streams - stream *in; //pointer to input stream - stream **out; //list of pointers to output streams - double *frac; //list of split fractions - -public: - split(int, stream*, stream**); //defines the connectivities of this unit - ~split(){} - void set(double* f) {frac=f;} - void set(const string & n) { name = n;} - bool solve(); //finds the temperature and computes mass balance - void write(); -}; - -#endif +/* +This unit takes one input stream and divides in two or more +output streams. The pressure and temparature of output streams +are the same as the input's. + +Structure in the .process file: +split {name} {index of input stream} {nb_out} {indexes of output streams and fractions of input} + +How to use: + 1- Call the constructor: split1 = new split(nb_out, in, list_out); + 2- Set split fractions: split1->set(fractions); + 3- Set the name: split1->set(name); + 4- Solve: split1->solve(); +*/ +#ifndef SPLIT_H +#define SPLIT_H + +#include "stream.hpp" +using namespace std; + +class split +{ +private: + + int i, j; + bool success; + double tmp; + string name; + int nb_out; //number of input streams + stream *in; //pointer to input stream + stream **out; //list of pointers to output streams + double *frac; //list of split fractions + +public: + split(int, stream*, stream**); //defines the connectivities of this unit + ~split(){} + void set(double* f) {frac=f;} + void set(const string & n) { name = n;} + bool solve(); //finds the temperature and computes mass balance + void write(); +}; + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.cpp index 8854441ea39a4a547414299b8725c623b9042192..408c1cb21e949286b9cb58cc2e25801db61a1480 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.cpp @@ -1,265 +1,265 @@ -#include "stream.hpp" -using namespace std; - -// destructor : -stream::~stream ( void ) { - delete thermo; - delete [] tab1; - delete [] tab2; - delete [] tab3; - delete [] tab4; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; -} - -void stream::check_error() -{ - - if (error>MAX_ERROR) { - cout << "ERROR 4\n\n"; - exit(0); - } - if (warning>MAX_WARNING) { - cout << "ERROR 5\n\n"; - exit(0); - } -} - -void stream::set ( int _nb , chemical ** _chem) { - int i; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; - nb = _nb; - chem = new chemical * [nb]; - for ( i = 0 ; i < nb ; i++ ) - chem[i] = new chemical(*_chem[i]); -} - -void stream::set(double pres, double temp) //set P, T, find state and resulting v -{ - if(thermo->get_dim()!=nb) - { - delete thermo; - thermo = new thermolib(nb); - } - P=pres; - T=temp; - for (i=0;i<nb;i++) {chem[i]->P=pres; chem[i]->T=temp;} - if(n()>EPS) - { - v=quality(); - tmp1=0; - for (i=0;i<nb;i++) - { - if (T>chem[i]->Tc || v==1) chem[i]->state=1; - else chem[i]->state=0; - } - v=0; - for (i=0;i<nb;i++) - { - if (chem[i]->state==0) {if (chem[i]->m>EPS) v+= chem[i]->m/chem[i]->rho(); tab4[i]=0;} - if (chem[i]->state==1) {tab4[i] = chem[i]->n(); tmp1+=tab4[i];} - } - if (tmp1>EPS) - { - for (i=0;i<nb;i++) - { - tab1[i] = chem[i]->Pc; //cout<<endl<<tab1[i]; - tab2[i] = chem[i]->Tc; // cout<<" "<<tab2[i]; - tab3[i] = chem[i]->omega(); //cout<<" "<<tab3[i]; - tab4[i]/=tmp1; // cout<<" "<<tab4[i]; - } - thermo->send(tab1,tab2,tab3, tab4); - thermo->set(P,T,0.0,tmp1); - v+=thermo->v(); - } - } - else v= 0.0; -} - -void stream::set(double *list) -{ - m=0; - for (i=0; i<nb; i++) - { - chem[i]->m=list[i]; - m+=list[i]; - } -} - -void stream::bubble() -{ - bp=1.1e6; - for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)<bp && chem[i]->m>EPS) bp=chem[i]->Tboil(P); - if (bp==1.1e6) bp=0.0; - else - { - step=2; - while (fabs(step)>TOL_BP && fabs(tmp1-1)>TOL_BP) - { - //if(DEBUG) cout<<endl<<bp; - bp+=step; - tmp1=tmp2=0; - for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()*chem[i]->Psat(bp)/P;} - tmp1/=tmp2; - step=10*(1.0-tmp1); - } - } -} - -void stream::dew() -{ - dp=0.0; - tmp1=10; - for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)>dp && chem[i]->m>EPS) dp=chem[i]->Tboil(P); - if (dp>EPS) - { - dp=bp; - step=1; - while (fabs(step)>TOL_DP && fabs(tmp1/tmp2-1)>TOL_DP) - { - dp+=step; - if(dp<bp) dp=bp; - //if(DEBUG) cout<<endl<<dp; - tmp1=tmp2=0; - for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()/chem[i]->Psat(dp)*P; } - if (step/fabs(step)*tmp2/tmp1 >1 || step/fabs(step)*tmp1/tmp2 <-1) step*= -0.1; - } - } -} - -double stream::quality() -{ - if(T>EPS) - { - bubble(); - dew(); - //if(DEBUG) cout<<endl<<name<<" bp="<<bp<<" dp="<<dp<<" T="<<T; system("pause"); - if (bp < dp) - { - if (bp < T && T< dp) tmp= (T-bp)/(dp-bp); - if (T<= bp) tmp= 0.0; - if (T >= dp) tmp= 1.0; - } - } - else tmp= 0.0; - return tmp; -} - -double stream::K(int i) -{ - for (j=0;j<nb;j++) - tab4[j] = chem[j]->n()/n(); - thermo->send(tab1,tab2,tab3, tab4); - if (T>EPS && P>EPS) - { - thermo->set(P,T,v,n()); - return thermo->K(i); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot compute K of "<<chem[i]->name<<" in stream "<<name<<".\n"; - logf.close(); - warning++; - check_error(); - return 1.0; - } -} - -double stream::n() -{ - tmp=0.0; - for ( k = 0 ; k < nb ; k++ ) - tmp+=chem[k]->n(); - return tmp; -} - - -// affectation : -stream & stream::operator = ( const stream & s ) { - - (*thermo) = *(s.thermo); - - delete [] tab1; - delete [] tab2; - delete [] tab3; - delete [] tab4; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; - - P = s.P; - T = s.T; - m = s.m; - v = s.v; - i = s.i; - j = s.j; - k = s.k; - error = s.error; - warning = s.warning; - name = s.name; - nb = s.nb; - chem = new chemical *[nb]; - - tab1 = new double[nb]; - tab2 = new double[nb]; - tab3 = new double[nb]; - tab4 = new double[nb]; - - step = s.step; - - for ( i = 0 ; i < nb ; i++ ) { - chem[i] = new chemical(*s.chem[i]); - tab1[i] = s.tab1[i]; - tab2[i] = s.tab2[i]; - tab3[i] = s.tab3[i]; - tab4[i] = s.tab4[i]; - } - - tmp = s.tmp; - tmp1 = s.tmp1; - tmp2 = s.tmp2; - - return *this; -} - - -void stream::write() { - - string file_name = RUNTIME + name + ".stream"; - - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - - cout.unsetf(ios::scientific); - cout << setiosflags(ios::showpoint | ios::fixed)<<setprecision(1); - - cout << "\t>>" << setw(8) << P << " " << setw(9) << T <<" "; - - cout << resetiosflags(ios::fixed) << setiosflags(ios::scientific) << setprecision(3); - - if (m>EPS) - cout << setw(11) << m << setw(11) << v; - else - cout << " x x "; - for ( i = 0 ; i < nb ; i++ ) { - if ( chem[i]->m <= EPS ) - cout << " x "; - else - cout << setw(11) << chem[i]->m; - } - cout << "\n\tEND\n\n"; - - cout.setf(ios::scientific); - -} - -void stream::purge() -{ - P=T=m=v=0.0; - for(i=0;i<nb;i++) - chem[i]->purge(); -} +#include "stream.hpp" +using namespace std; + +// destructor : +stream::~stream ( void ) { + delete thermo; + delete [] tab1; + delete [] tab2; + delete [] tab3; + delete [] tab4; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; +} + +void stream::check_error() +{ + + if (error>MAX_ERROR) { + cout << "ERROR 4\n\n"; + exit(0); + } + if (warning>MAX_WARNING) { + cout << "ERROR 5\n\n"; + exit(0); + } +} + +void stream::set ( int _nb , chemical ** _chem) { + int i; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; + nb = _nb; + chem = new chemical * [nb]; + for ( i = 0 ; i < nb ; i++ ) + chem[i] = new chemical(*_chem[i]); +} + +void stream::set(double pres, double temp) //set P, T, find state and resulting v +{ + if(thermo->get_dim()!=nb) + { + delete thermo; + thermo = new thermolib(nb); + } + P=pres; + T=temp; + for (i=0;i<nb;i++) {chem[i]->P=pres; chem[i]->T=temp;} + if(n()>EPS) + { + v=quality(); + tmp1=0; + for (i=0;i<nb;i++) + { + if (T>chem[i]->Tc || v==1) chem[i]->state=1; + else chem[i]->state=0; + } + v=0; + for (i=0;i<nb;i++) + { + if (chem[i]->state==0) {if (chem[i]->m>EPS) v+= chem[i]->m/chem[i]->rho(); tab4[i]=0;} + if (chem[i]->state==1) {tab4[i] = chem[i]->n(); tmp1+=tab4[i];} + } + if (tmp1>EPS) + { + for (i=0;i<nb;i++) + { + tab1[i] = chem[i]->Pc; //cout<<endl<<tab1[i]; + tab2[i] = chem[i]->Tc; // cout<<" "<<tab2[i]; + tab3[i] = chem[i]->omega(); //cout<<" "<<tab3[i]; + tab4[i]/=tmp1; // cout<<" "<<tab4[i]; + } + thermo->send(tab1,tab2,tab3, tab4); + thermo->set(P,T,0.0,tmp1); + v+=thermo->v(); + } + } + else v= 0.0; +} + +void stream::set(double *list) +{ + m=0; + for (i=0; i<nb; i++) + { + chem[i]->m=list[i]; + m+=list[i]; + } +} + +void stream::bubble() +{ + bp=1.1e6; + for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)<bp && chem[i]->m>EPS) bp=chem[i]->Tboil(P); + if (bp==1.1e6) bp=0.0; + else + { + step=2; + while (fabs(step)>TOL_BP && fabs(tmp1-1)>TOL_BP) + { + //if(DEBUG) cout<<endl<<bp; + bp+=step; + tmp1=tmp2=0; + for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()*chem[i]->Psat(bp)/P;} + tmp1/=tmp2; + step=10*(1.0-tmp1); + } + } +} + +void stream::dew() +{ + dp=0.0; + tmp1=10; + for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)>dp && chem[i]->m>EPS) dp=chem[i]->Tboil(P); + if (dp>EPS) + { + dp=bp; + step=1; + while (fabs(step)>TOL_DP && fabs(tmp1/tmp2-1)>TOL_DP) + { + dp+=step; + if(dp<bp) dp=bp; + //if(DEBUG) cout<<endl<<dp; + tmp1=tmp2=0; + for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()/chem[i]->Psat(dp)*P; } + if (step/fabs(step)*tmp2/tmp1 >1 || step/fabs(step)*tmp1/tmp2 <-1) step*= -0.1; + } + } +} + +double stream::quality() +{ + if(T>EPS) + { + bubble(); + dew(); + //if(DEBUG) cout<<endl<<name<<" bp="<<bp<<" dp="<<dp<<" T="<<T; system("pause"); + if (bp < dp) + { + if (bp < T && T< dp) tmp= (T-bp)/(dp-bp); + if (T<= bp) tmp= 0.0; + if (T >= dp) tmp= 1.0; + } + } + else tmp= 0.0; + return tmp; +} + +double stream::K(int i) +{ + for (j=0;j<nb;j++) + tab4[j] = chem[j]->n()/n(); + thermo->send(tab1,tab2,tab3, tab4); + if (T>EPS && P>EPS) + { + thermo->set(P,T,v,n()); + return thermo->K(i); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot compute K of "<<chem[i]->name<<" in stream "<<name<<".\n"; + logf.close(); + warning++; + check_error(); + return 1.0; + } +} + +double stream::n() +{ + tmp=0.0; + for ( k = 0 ; k < nb ; k++ ) + tmp+=chem[k]->n(); + return tmp; +} + + +// affectation : +stream & stream::operator = ( const stream & s ) { + + (*thermo) = *(s.thermo); + + delete [] tab1; + delete [] tab2; + delete [] tab3; + delete [] tab4; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; + + P = s.P; + T = s.T; + m = s.m; + v = s.v; + i = s.i; + j = s.j; + k = s.k; + error = s.error; + warning = s.warning; + name = s.name; + nb = s.nb; + chem = new chemical *[nb]; + + tab1 = new double[nb]; + tab2 = new double[nb]; + tab3 = new double[nb]; + tab4 = new double[nb]; + + step = s.step; + + for ( i = 0 ; i < nb ; i++ ) { + chem[i] = new chemical(*s.chem[i]); + tab1[i] = s.tab1[i]; + tab2[i] = s.tab2[i]; + tab3[i] = s.tab3[i]; + tab4[i] = s.tab4[i]; + } + + tmp = s.tmp; + tmp1 = s.tmp1; + tmp2 = s.tmp2; + + return *this; +} + + +void stream::write() { + + string file_name = RUNTIME + name + ".stream"; + + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + + cout.unsetf(ios::scientific); + cout << setiosflags(ios::showpoint | ios::fixed)<<setprecision(1); + + cout << "\t>>" << setw(8) << P << " " << setw(9) << T <<" "; + + cout << resetiosflags(ios::fixed) << setiosflags(ios::scientific) << setprecision(3); + + if (m>EPS) + cout << setw(11) << m << setw(11) << v; + else + cout << " x x "; + for ( i = 0 ; i < nb ; i++ ) { + if ( chem[i]->m <= EPS ) + cout << " x "; + else + cout << setw(11) << chem[i]->m; + } + cout << "\n\tEND\n\n"; + + cout.setf(ios::scientific); + +} + +void stream::purge() +{ + P=T=m=v=0.0; + for(i=0;i<nb;i++) + chem[i]->purge(); +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.hpp index 94b21025cc190e1bc0783d172737cd72bef2e889..895ef3d6b8fcd99dee13564f66d71932a2c009c5 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/stream.hpp @@ -1,86 +1,86 @@ -#ifndef STREAM_H -#define STREAM_H -#include "chemical.hpp" -#include <iomanip> -using namespace std; - -class stream { - -private: - - stream ( void ) {} - stream ( const stream & s ) {} - -public: - void check_error(); - - double P, T, m, v; // Pressure in atm, temperature in K, - // total mass flow in kg/s, total volume flow in m3/s - - int i, j, k, error, warning; - - string name; - - int nb; // number of chemicals to store; - - chemical ** chem; // list of stored chemicals - - thermolib *thermo; - - double tmp, tmp1,tmp2, *tab1, *tab2, *tab3, *tab4; - double step; - void bubble(), dew(); - -public: - - - - - - double dp, bp; - double rho() {if(v!=0) return m/v; else exit(0);} // Apparent density in kg/m3 - double n(); // total mole flow (mol/s) - double quality(); // returns the vapor fraction of stream (1=all vapor, 0 = all liquid) - double K(int); // returns the vapor-liquid equilibrium constant of compound i - - // constructor : - stream ( const string _name , int n , chemical ** list ) : P (0 ) , - T (0 ) , - m (0 ) , - v (0 ) , - error (0 ) , - warning(0 ) , - name (_name ) , - nb (n ) , - chem (new chemical *[nb]) , - thermo (new thermolib (nb)) , - tab1 (new double [nb]) , - tab2 (new double [nb]) , - tab3 (new double [nb]) , - tab4 (new double [nb]) { - for ( i = 0 ; i < nb ; i++ ) - chem[i] = new chemical(*list[i]); - } - - - // affectation : - stream & operator = ( const stream & s ); - - void set_thermo ( thermolib * t ) { (*thermo) = *t; } - - - void set(double, double); // Sets P and T - void set(double*); // Sets mass flows - void set( const string & n ) { name = n;} - void set ( int _nb , chemical ** _chem); - - - // destructor : - ~stream ( void ); - - void write(); - void purge(); -}; - - -#endif +#ifndef STREAM_H +#define STREAM_H +#include "chemical.hpp" +#include <iomanip> +using namespace std; + +class stream { + +private: + + stream ( void ) {} + stream ( const stream & s ) {} + +public: + void check_error(); + + double P, T, m, v; // Pressure in atm, temperature in K, + // total mass flow in kg/s, total volume flow in m3/s + + int i, j, k, error, warning; + + string name; + + int nb; // number of chemicals to store; + + chemical ** chem; // list of stored chemicals + + thermolib *thermo; + + double tmp, tmp1,tmp2, *tab1, *tab2, *tab3, *tab4; + double step; + void bubble(), dew(); + +public: + + + + + + double dp, bp; + double rho() {if(v!=0) return m/v; else exit(0);} // Apparent density in kg/m3 + double n(); // total mole flow (mol/s) + double quality(); // returns the vapor fraction of stream (1=all vapor, 0 = all liquid) + double K(int); // returns the vapor-liquid equilibrium constant of compound i + + // constructor : + stream ( const string _name , int n , chemical ** list ) : P (0 ) , + T (0 ) , + m (0 ) , + v (0 ) , + error (0 ) , + warning(0 ) , + name (_name ) , + nb (n ) , + chem (new chemical *[nb]) , + thermo (new thermolib (nb)) , + tab1 (new double [nb]) , + tab2 (new double [nb]) , + tab3 (new double [nb]) , + tab4 (new double [nb]) { + for ( i = 0 ; i < nb ; i++ ) + chem[i] = new chemical(*list[i]); + } + + + // affectation : + stream & operator = ( const stream & s ); + + void set_thermo ( thermolib * t ) { (*thermo) = *t; } + + + void set(double, double); // Sets P and T + void set(double*); // Sets mass flows + void set( const string & n ) { name = n;} + void set ( int _nb , chemical ** _chem); + + + // destructor : + ~stream ( void ); + + void write(); + void purge(); +}; + + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.cpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.cpp index 51e3fbb903cd0b64921ea3f0e84cc9e8826bd101..5113bca59ee704135d5d363d31d39243ef145601 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.cpp @@ -1,175 +1,175 @@ -#include "thermolib.hpp" -#include "defines.hpp" -#include "secant.cpp" -using namespace std; - - - - -// affectation : -thermolib & thermolib::operator = ( const thermolib & t ) { - - if (dim!=t.dim) - reset(t.dim); - - for ( i = 0 ; i < dim ; i++ ) { - Pc[i] = t.Pc[i]; - Tc[i] = t.Tc[i]; - omega[i] = t.omega[i]; - molefrac[i] = t.molefrac[i]; - } - - return *this; -} - -thermolib::~thermolib() { - delete solver; - delete [] Pc; - delete [] Tc; - delete [] omega; - delete [] molefrac; -} - -void thermolib::construct ( void ) { - molefrac = new double[dim]; - Pc = new double[dim]; - Tc = new double[dim]; - omega = new double[dim]; - - // C. Tribes add this for more robustness (variables may be initialized uncorrectly dependent on the execution) - for ( i = 0 ; i < dim ; i++ ) - { - Pc[i] = 0.0; - Tc[i] = 0.0; - omega[i] = 0.0; - molefrac[i] = 0.0; - } - - - solver = new secant<thermolib>(); -} - -void thermolib::reset(int b) -{ - delete [] molefrac; - delete [] Pc; - delete [] Tc; - delete [] omega; - delete solver; - dim = b; - construct(); -} - -double thermolib::a_mix() -{ - if (dim>1) - { - tmp=0; - for (i=0;i<dim;i++) - for (j=0;j<dim;j++) - tmp += molefrac[i]*molefrac[j]*sqrt(a(i)*a(j)); - return tmp; - } - else return a(0); -} - -double thermolib::b_mix() -{ - if (dim>1) - { - tmp=0; - for (i=0;i<dim;i++) - tmp += molefrac[i]*b(i); - return tmp; - } - else return b(0); -} - -void thermolib::send(double* pc, double* tc, double* w, double* y) -{ - for (i=0;i<dim;i++) - { - Pc[i] = pc[i]*101.325; - Tc[i] = tc[i]; - omega[i] = w[i]; - molefrac[i] = y[i]; - } -} - -double thermolib::P() -{ - task=0; - pressure = 8.3144*temperature/molevolume; - solver->set(this, pressure, 1.001*pressure); - success=solver->run(); - return pressure/101.325; -} - -double thermolib::T() -{ - task=1; - temperature = pressure*molevolume/8.144; - solver->set(this, temperature, 1.001*temperature); - success=solver->run(); - return temperature; -} - -double thermolib::v() -{ - if (mole>EPS) - { - task=2; - molevolume = 8.3144*temperature/pressure; - solver->set(this, molevolume, 1.001*molevolume); - success=solver->run(); - return 0.001*mole*molevolume; - } - else return 0.0; -} - -double thermolib::Zv() -{ - task=4; - solver->set(this, 1.0, 0.99); - success=solver->run(); - return Z; -} - -double thermolib::phiV(int i) -{ - return exp((Z-1)*B(i)/B() - log(Z-B()) - A()/B()*(2*sqrt(A(i)/A())-B(i)/B())*log(1+B()/Z)); -} - -double thermolib::phiL(int i) -{ - Pr = pressure/Pc[i]; - Tr = temperature/Tc[i]; - tmp = 2.05135 - 2.10899/Tr - 0.19396*pow(Tr,2) + 0.02282*pow(Tr,3) + (0.08852 - 0.00872*pow(Tr,2))*Pr + (-0.00353 - 0.00203*Tr)*pow(Pr,2) - log10(Pr); - tmp += omega[i]*(-4.23893 + 8.65808*Tr - 1.2206/Tr - 3.15224*pow(Tr,3) - 0.025*(Pr-0.6)); - return pow(10, tmp); -} - -double thermolib::f(double x) -{ - if (task==0) - { - pressure=x; - x= 8.3144*temperature/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - x; - } - if (task==1) - { - temperature=x; - x= 8.3144*x/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - pressure; - } - if (task==2) - { - molevolume=x; - x= 8.3144*temperature/(x-b_mix()) - a_mix()/(pow(x,2)+b_mix()*x) - pressure; - } - if(task==4) - { - Z=x; - x= (pow(x,3)-pow(x,2)+(A()-B()-pow(B(),2))*x-A()*B()); - } - return x; -} +#include "thermolib.hpp" +#include "defines.hpp" +#include "secant.cpp" +using namespace std; + + + + +// affectation : +thermolib & thermolib::operator = ( const thermolib & t ) { + + if (dim!=t.dim) + reset(t.dim); + + for ( i = 0 ; i < dim ; i++ ) { + Pc[i] = t.Pc[i]; + Tc[i] = t.Tc[i]; + omega[i] = t.omega[i]; + molefrac[i] = t.molefrac[i]; + } + + return *this; +} + +thermolib::~thermolib() { + delete solver; + delete [] Pc; + delete [] Tc; + delete [] omega; + delete [] molefrac; +} + +void thermolib::construct ( void ) { + molefrac = new double[dim]; + Pc = new double[dim]; + Tc = new double[dim]; + omega = new double[dim]; + + // C. Tribes add this for more robustness (variables may be initialized uncorrectly dependent on the execution) + for ( i = 0 ; i < dim ; i++ ) + { + Pc[i] = 0.0; + Tc[i] = 0.0; + omega[i] = 0.0; + molefrac[i] = 0.0; + } + + + solver = new secant<thermolib>(); +} + +void thermolib::reset(int b) +{ + delete [] molefrac; + delete [] Pc; + delete [] Tc; + delete [] omega; + delete solver; + dim = b; + construct(); +} + +double thermolib::a_mix() +{ + if (dim>1) + { + tmp=0; + for (i=0;i<dim;i++) + for (j=0;j<dim;j++) + tmp += molefrac[i]*molefrac[j]*sqrt(a(i)*a(j)); + return tmp; + } + else return a(0); +} + +double thermolib::b_mix() +{ + if (dim>1) + { + tmp=0; + for (i=0;i<dim;i++) + tmp += molefrac[i]*b(i); + return tmp; + } + else return b(0); +} + +void thermolib::send(double* pc, double* tc, double* w, double* y) +{ + for (i=0;i<dim;i++) + { + Pc[i] = pc[i]*101.325; + Tc[i] = tc[i]; + omega[i] = w[i]; + molefrac[i] = y[i]; + } +} + +double thermolib::P() +{ + task=0; + pressure = 8.3144*temperature/molevolume; + solver->set(this, pressure, 1.001*pressure); + success=solver->run(); + return pressure/101.325; +} + +double thermolib::T() +{ + task=1; + temperature = pressure*molevolume/8.144; + solver->set(this, temperature, 1.001*temperature); + success=solver->run(); + return temperature; +} + +double thermolib::v() +{ + if (mole>EPS) + { + task=2; + molevolume = 8.3144*temperature/pressure; + solver->set(this, molevolume, 1.001*molevolume); + success=solver->run(); + return 0.001*mole*molevolume; + } + else return 0.0; +} + +double thermolib::Zv() +{ + task=4; + solver->set(this, 1.0, 0.99); + success=solver->run(); + return Z; +} + +double thermolib::phiV(int i) +{ + return exp((Z-1)*B(i)/B() - log(Z-B()) - A()/B()*(2*sqrt(A(i)/A())-B(i)/B())*log(1+B()/Z)); +} + +double thermolib::phiL(int i) +{ + Pr = pressure/Pc[i]; + Tr = temperature/Tc[i]; + tmp = 2.05135 - 2.10899/Tr - 0.19396*pow(Tr,2) + 0.02282*pow(Tr,3) + (0.08852 - 0.00872*pow(Tr,2))*Pr + (-0.00353 - 0.00203*Tr)*pow(Pr,2) - log10(Pr); + tmp += omega[i]*(-4.23893 + 8.65808*Tr - 1.2206/Tr - 3.15224*pow(Tr,3) - 0.025*(Pr-0.6)); + return pow(10, tmp); +} + +double thermolib::f(double x) +{ + if (task==0) + { + pressure=x; + x= 8.3144*temperature/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - x; + } + if (task==1) + { + temperature=x; + x= 8.3144*x/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - pressure; + } + if (task==2) + { + molevolume=x; + x= 8.3144*temperature/(x-b_mix()) - a_mix()/(pow(x,2)+b_mix()*x) - pressure; + } + if(task==4) + { + Z=x; + x= (pow(x,3)-pow(x,2)+(A()-B()-pow(B(),2))*x-A()*B()); + } + return x; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.hpp b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.hpp index 3440270ab02d6575023747971b89e9725da31061..3d39c8c7664d3be918c45978344f86a89d681550 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/surrogate/thermolib.hpp @@ -1,50 +1,50 @@ -#ifndef THERMOLIB_H -#define THERMOLIB_H -#include "secant.hpp" -using namespace std; - -class thermolib -{ - private: - bool success; - int dim, i, j; - double pressure, temperature, molevolume, mole,*molefrac; - double *Pc, *Tc, *omega, Z, tmp, Tr, Pr; - void construct(); - double a(int i) {return (0.42748*pow(8.8144,2)*pow(Tc[i],2)*pow(1.0+f_omega(i)*(1.0-sqrt(temperature/Tc[i])), 2)/Pc[i]);} - double a_mix(); - double b(int i) {return (0.08664*8.3144*Tc[i]/Pc[i]);} - double b_mix(); - double A(int i) {return (a(i)*pressure/pow(8.3144, 2)/pow(temperature, 2));} - double A() {return (a_mix()*pressure/pow(8.3144, 2)/pow(temperature, 2));} - double B(int i) {return (b(i)*pressure/8.3144/temperature);} - double B(){return (b_mix()*pressure/8.3144/temperature);} - double Zv(), phiV(int), phiL(int); - double f_omega(int i) {return (0.48 + 1.574*omega[i] - 0.176*pow(omega[i], 2));} - int task; //0=find P 1=find T 2=find v 3= find K 4=find Zv - secant<thermolib> *solver; - - public: - double P(); //retruns pressure at T and v, in atm - double T(); //returns temperature at P and v, in K - double v(); //returns volume flow at P, T, n(), in m3/s - double K() {Z = Zv(); return phiL(0)/phiV(0);} //returns the vapor-liquid equilibirum constant - double K(int i) {return phiL(i)/phiV(i);} - double compres_coeff(){return 1.0;}; - - -// affectation : - thermolib & operator = ( const thermolib & t ); - - thermolib ( int d = 1 ) { dim=d; construct();} - - void send(double pc, double tc, double w) { Pc[0] = pc*101.325; Tc[0] = tc; omega[0]=w;} - void send(double*, double*, double*, double*); - void set(double p, double t, double v, double n) {pressure=p*101.325; temperature=t; molevolume=0.001*n/v; mole=n;} - double f(double); - int get_dim() {return dim;} - ~thermolib(); - void reset(int); -}; -#endif - +#ifndef THERMOLIB_H +#define THERMOLIB_H +#include "secant.hpp" +using namespace std; + +class thermolib +{ + private: + bool success; + int dim, i, j; + double pressure, temperature, molevolume, mole,*molefrac; + double *Pc, *Tc, *omega, Z, tmp, Tr, Pr; + void construct(); + double a(int i) {return (0.42748*pow(8.8144,2)*pow(Tc[i],2)*pow(1.0+f_omega(i)*(1.0-sqrt(temperature/Tc[i])), 2)/Pc[i]);} + double a_mix(); + double b(int i) {return (0.08664*8.3144*Tc[i]/Pc[i]);} + double b_mix(); + double A(int i) {return (a(i)*pressure/pow(8.3144, 2)/pow(temperature, 2));} + double A() {return (a_mix()*pressure/pow(8.3144, 2)/pow(temperature, 2));} + double B(int i) {return (b(i)*pressure/8.3144/temperature);} + double B(){return (b_mix()*pressure/8.3144/temperature);} + double Zv(), phiV(int), phiL(int); + double f_omega(int i) {return (0.48 + 1.574*omega[i] - 0.176*pow(omega[i], 2));} + int task; //0=find P 1=find T 2=find v 3= find K 4=find Zv + secant<thermolib> *solver; + + public: + double P(); //retruns pressure at T and v, in atm + double T(); //returns temperature at P and v, in K + double v(); //returns volume flow at P, T, n(), in m3/s + double K() {Z = Zv(); return phiL(0)/phiV(0);} //returns the vapor-liquid equilibirum constant + double K(int i) {return phiL(i)/phiV(i);} + double compres_coeff(){return 1.0;}; + + +// affectation : + thermolib & operator = ( const thermolib & t ); + + thermolib ( int d = 1 ) { dim=d; construct();} + + void send(double pc, double tc, double w) { Pc[0] = pc*101.325; Tc[0] = tc; omega[0]=w;} + void send(double*, double*, double*, double*); + void set(double p, double t, double v, double n) {pressure=p*101.325; temperature=t; molevolume=0.001*n/v; mole=n;} + double f(double); + int get_dim() {return dim;} + ~thermolib(); + void reset(int); +}; +#endif + diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.cpp index 175e64bb507e1c6dfe6a5956a0d5be4f8e09bfec..dbc37f4c7eb11d8439b38c4ca1c0ebcad406603d 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.cpp @@ -1,80 +1,80 @@ -#include "RungeKutta.hpp" - -#include <iomanip> - -using namespace std; - -template <class E> -RungeKutta<E>::RungeKutta(int dim) -{ - m = dim; - k1 = new double[m]; - k2 = new double[m]; - k3 = new double[m]; - k4 = new double[m]; - y = new double[m]; - y_tmp = new double[m]; -} - -template <class E> -RungeKutta<E>::~RungeKutta() -{ - delete [] k1; - delete [] k2; - delete [] k3; - delete [] k4; - delete [] y; - delete [] y_tmp; -} - -template <class E> -void RungeKutta<E>::set ( E * tmp , double * y0 , double beg , double end ) -{ - unit=tmp; - x0=beg; xn=end; - x=x0; - h=double(xn-x0)/double(N_INTER); - for (i=0;i<m;i++) {y[i]=y0[i];} - success=true; -} - -template <class E> -bool RungeKutta<E>::run() { - for(j=0;j<MAX_ITER_RK;j++) { - //Avoid going out of x interval - if (x+h >xn) { - h = xn-x; - j = MAX_ITER_RK; - } - - //Compute k1, k2, k3, k4 - for(i=0;i<m;i++) - k1[i] = h*unit->f(i, x, y); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k1[i]/2.0; - for(i=0;i<m;i++) - k2[i] = h*unit->f(i, x+h/2.0, y_tmp); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k2[i]/2.0; - for(i=0;i<m;i++) - k3[i] = h*unit->f(i, x+h/2.0, y_tmp); - for(i=0;i<m;i++) - y_tmp[i] = y[i]+k3[i]; - for ( i = 0 ; i < m ; i++ ) - k4[i] = h*unit->f ( i , x+h , y_tmp ); - //Compute the new y - for(i=0;i<m;i++) - y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0; - x += h; - } - - if ( x < xn-EPS ) {// MODIF SEB (le EPS) - success=false; - - // cout.setf(ios::fixed); - // cout << setprecision(12); - // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl; - } - - return success; -} +#include "RungeKutta.hpp" + +#include <iomanip> + +using namespace std; + +template <class E> +RungeKutta<E>::RungeKutta(int dim) +{ + m = dim; + k1 = new double[m]; + k2 = new double[m]; + k3 = new double[m]; + k4 = new double[m]; + y = new double[m]; + y_tmp = new double[m]; +} + +template <class E> +RungeKutta<E>::~RungeKutta() +{ + delete [] k1; + delete [] k2; + delete [] k3; + delete [] k4; + delete [] y; + delete [] y_tmp; +} + +template <class E> +void RungeKutta<E>::set ( E * tmp , double * y0 , double beg , double end ) +{ + unit=tmp; + x0=beg; xn=end; + x=x0; + h=double(xn-x0)/double(N_INTER); + for (i=0;i<m;i++) {y[i]=y0[i];} + success=true; +} + +template <class E> +bool RungeKutta<E>::run() { + for(j=0;j<MAX_ITER_RK;j++) { + //Avoid going out of x interval + if (x+h >xn) { + h = xn-x; + j = MAX_ITER_RK; + } + + //Compute k1, k2, k3, k4 + for(i=0;i<m;i++) + k1[i] = h*unit->f(i, x, y); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k1[i]/2.0; + for(i=0;i<m;i++) + k2[i] = h*unit->f(i, x+h/2.0, y_tmp); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k2[i]/2.0; + for(i=0;i<m;i++) + k3[i] = h*unit->f(i, x+h/2.0, y_tmp); + for(i=0;i<m;i++) + y_tmp[i] = y[i]+k3[i]; + for ( i = 0 ; i < m ; i++ ) + k4[i] = h*unit->f ( i , x+h , y_tmp ); + //Compute the new y + for(i=0;i<m;i++) + y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0; + x += h; + } + + if ( x < xn-EPS ) {// MODIF SEB (le EPS) + success=false; + + // cout.setf(ios::fixed); + // cout << setprecision(12); + // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl; + } + + return success; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.hpp index db2b3c22d5b1c897238f65d8a961be5d6fadfaf7..240075371d9f76c61faa9f0865ace58c090acd41 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/RungeKutta.hpp @@ -1,37 +1,37 @@ -/* -To use the Runge-Kutta solver for systems of first order differential equations, - (the parametric object E must have public function such as E->f(i,x,y), - where i is the index of the function to evaluate, x is the time and - y is a point such as y(x), returns values of differential equation i) - - 1- construct the solver : solver = new RungeKutta<objet>(int); //the integer is the dimension of x - 2- set the solver : solver->set(unit, y0, x0, xn); //unit is usually the pointer *this, y0 are the initial conditions, and x0 and xn is the time interval - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed???????????????????????????? - 4- delete the solver : delete solver; -(ref :Fortin) -*/ -#ifndef RUNGEKUTTA_H -#define RUNGEKUTTA_H - -#include "defines.hpp" -using namespace std; - -template <class E> -class RungeKutta -{ -private: - double *k1, *k2, *k3, *k4, *y_tmp, *y; - // double k1[MAX_DIM], k2[MAX_DIM], k3[MAX_DIM], k4[MAX_DIM], y_tmp[MAX_DIM], y[MAX_DIM]; - double h, x0, xn, x; - int i, j, m; - bool success; - E *unit; - -public: - RungeKutta(int); - ~RungeKutta(); - void set(E*, double*, double, double); - double dx(){return h;} - bool run(); -}; -#endif +/* +To use the Runge-Kutta solver for systems of first order differential equations, + (the parametric object E must have public function such as E->f(i,x,y), + where i is the index of the function to evaluate, x is the time and + y is a point such as y(x), returns values of differential equation i) + + 1- construct the solver : solver = new RungeKutta<objet>(int); //the integer is the dimension of x + 2- set the solver : solver->set(unit, y0, x0, xn); //unit is usually the pointer *this, y0 are the initial conditions, and x0 and xn is the time interval + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed???????????????????????????? + 4- delete the solver : delete solver; +(ref :Fortin) +*/ +#ifndef RUNGEKUTTA_H +#define RUNGEKUTTA_H + +#include "defines.hpp" +using namespace std; + +template <class E> +class RungeKutta +{ +private: + double *k1, *k2, *k3, *k4, *y_tmp, *y; + // double k1[MAX_DIM], k2[MAX_DIM], k3[MAX_DIM], k4[MAX_DIM], y_tmp[MAX_DIM], y[MAX_DIM]; + double h, x0, xn, x; + int i, j, m; + bool success; + E *unit; + +public: + RungeKutta(int); + ~RungeKutta(); + void set(E*, double*, double, double); + double dx(){return h;} + bool run(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/bb.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/bb.cpp index 151727d5c5e3129f1c289e10a40185b8e9de1bfd..4e348d76434f0668bd0b1fece84123a0ac35190a 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/bb.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/bb.cpp @@ -1,361 +1,361 @@ -#include "servor.hpp" -#include "profitability.hpp" -using namespace std; - -/*------------------------------------------------------------------------*/ -/* fonction principale */ -/*------------------------------------------------------------------------*/ -int main ( int argc , char ** argv ) { - - double g0 = 1e+20; - double g1 = 1e+20; - double g2 = 1e+20; - double g3 = 1e+20; - double g4 = 1e+20; - double g5 = 1e+20; - double g6 = 1e+20; - double g7 = 1e+20; - double g8 = 1e+20; - double g9 = 1e+20; - double g10 = 1e+20; - double f = 1e+20; - - bool OK; - ifstream in; - double d; - int i; - int i_stream , i_chem; - double x [8]; - long double tmp[8]; - double raw_cost; - double util_cost; - double Itot; - double Coper; - double Rtot; - double max; - double mtot; - double m; - double purity; - int nb_chem = 7; - int nb_s = 15; - int nb_u = 11; - int n = 8; - double l [8] = { 600 , 2 , 0.0001 , 0.0001 , 2 , 0.01 , 0.1 , 300 }; - double u [8] = { 1100 , 20 , 0.1 , 0.1 , 20 , 0.5 , 5 , 500 }; - double list [7] = { 0.5 , 0 , 0 , 0 , 0 , 0 , 0 }; - double price[7] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 }; - profitability * P = NULL; - cashflow * F = NULL; - chemical ** chem = NULL; - stream ** s = NULL; - servor * units = NULL; - string * safe = NULL; - - // verif. du nombre d'arguments : - if (argc!=2) { - // cout << "\nargc != 2\n\n"; - goto TERMINATE; - } - - // lecture et scaling de x : - // ------------------------- - in.open (argv[1]); - - for ( i = 0 ; i < n ; i++ ) - in >> tmp[i]; - - in.close(); - - if (in.fail()) { - // cout << "\nin.fail (1)\n\n"; - goto TERMINATE; - } - - //for ( i = 0 ; i < n ; i++ ) - // cout << "tmp[" << i << "] = " << tmp[i] << endl; - // cout << endl; - - for ( i = 0 ; i < n ; i++ ) - x[i] = (u[i]-l[i])*((double)tmp[i]/100.0) + l[i]; - - //for ( i = 0 ; i < n ; i++ ) - // cout << "x[" << i << "] = " << x[i] << endl; - - // verifs de x (j'ai pris ca dans checkup et c'est tout ce dont - // ca a besoin de checker ici) : - if ( x[6] < EPS || x[2] < 0 || x[2] > 1 || x[3] < 0 || x[3] > 1 ) - goto TERMINATE; - - // chemicals : - // ----------- - chem = new chemical * [nb_chem]; - chem[0] = new chemical ("100-41-4" ); - chem[1] = new chemical ("1333-74-0"); - chem[2] = new chemical ("108-88-3" ); - chem[3] = new chemical ("74-82-8" ); - chem[4] = new chemical ("71-43-2" ); - chem[5] = new chemical ("74-85-1" ); - chem[6] = new chemical ("100-42-5" ); - - price[6] = 1.39; - price[2] = 0.64; - price[0] = 0.11; - price[4] = 1.19; - - // streams : - // --------- - s = new stream * [nb_s]; - s[ 0] = new stream ( "feed" , nb_chem , chem ); - s[ 1] = new stream ( "2" , nb_chem , chem ); - s[ 2] = new stream ( "3" , nb_chem , chem ); - s[ 3] = new stream ( "4" , nb_chem , chem ); - s[ 4] = new stream ( "5" , nb_chem , chem ); - s[ 5] = new stream ( "6" , nb_chem , chem ); - s[ 6] = new stream ( "7" , nb_chem , chem ); - s[ 7] = new stream ( "8" , nb_chem , chem ); - s[ 8] = new stream ( "9" , nb_chem , chem ); - s[ 9] = new stream ( "10" , nb_chem , chem ); - s[10] = new stream ( "back" , nb_chem , chem ); - s[11] = new stream ( "12" , nb_chem , chem ); - s[12] = new stream ( "stack" , nb_chem , chem ); - s[13] = new stream ( "out-bz" , nb_chem , chem ); - s[14] = new stream ( "out-sty" , nb_chem , chem ); - - // initial conditions on streams : - // ------------------------------- - s[0]->P = 1.0; - s[0]->T = 298; - s[0]->set(list); - - // units settings and calculation sequence : - // ----------------------------------------- - units = new servor ( nb_u , nb_s , s ); - safe = new string[nb_u]; - - units->type[ 0] = "mix"; - units->name[ 0] = safe[ 0] = "mixfeed"; - units->type[ 1] = "pump"; - units->name[ 1] = safe[ 1] = "pump"; - units->type[ 2] = "heatx"; - units->name[ 2] = safe[ 2] = "heater"; - units->type[ 3] = "reactor"; - units->name[ 3] = safe[ 3] = "pfr"; - units->type[ 4] = "heatx"; - units->name[ 4] = safe[ 4] = "cooler"; - units->type[ 5] = "flash"; - units->name[ 5] = safe[ 5] = "degasor"; - units->type[ 6] = "column"; - units->name[ 6] = safe[ 6] = "sep-sty"; - units->type[ 7] = "split"; - units->name[ 7] = safe[ 7] = "spliter"; - units->type[ 8] = "column"; - units->name[ 8] = safe[ 8] = "sep-bz"; - units->type[ 9] = "loop"; - units->name[ 9] = safe[ 9] = "looping"; - units->type[10] = "burner"; - units->name[10] = safe[10] = "fire"; - - - // executing the calculation sequence : - //------------------------------------- - double y[14]; - y[7] = y[8] = 1000.0; - - if (!units->solve_process(x,y)) - goto TERMINATE; - - // on recupere les resultats : - // --------------------------- - y[6] = s[0]->m; - y[3] = s[13]->m; - y[2] = s[13]->chem[4]->m; - y[1] = s[14]->m; - y[0] = s[14]->chem[6]->m; - - y[9 ] = 1e20; - y[10] = 1e20; - y[11] = units->get_costs_sum() * 6.192; - y[12] = 1e20; - y[13] = 1e20; - - // arrondis : - if (ARRONDI) { - y[ 6] = arrondi ( y[ 6] , 4 ); - y[ 3] = arrondi ( y[ 3] , 4 ); - y[ 2] = arrondi ( y[ 2] , 4 ); - y[ 1] = arrondi ( y[ 1] , 4 ); - y[ 0] = arrondi ( y[ 0] , 4 ); - y[11] = arrondi ( y[11] , 6 ); - } - - g0 = ( y[0] > 0 && y[0] < 1e+20 ) ? 0.0 : 1e20; - g1 = ( y[4] <= 80 ) ? 0.0 : 1.0; - g2 = ( y[5] <= 80 ) ? 0.0 : 1.0; - g3 = ( y[7] <= 200 && y[8] <= 8 ) ? 0.0 : 1.0; - g4 = ( y[1] > 0 && y[1] < 1e20 ) ? (0.99-y[0]/y[1])/0.99 : 1e20; - g5 = ( y[3] > 0 && y[3] < 1e20 ) ? (0.99-y[2]/y[3])/0.99 : 1e20; - g6 = ( y[6] > 0 && y[6] < 1e20 ) ? (0.6-y[0]/y[6])/0.6 : 1e20; - - - // bloc econo : - // ------------ - - // raw_cost : - raw_cost = 0.0; - if ( s[0]->m > EPS ) { - if ( s[0]->chem[6]->m > EPS ) { - d = (ARRONDI) ? arrondi ( s[0]->chem[6]->m , 4 ) : s[0]->chem[6]->m; - raw_cost += d * 1.39; - } - if ( s[0]->chem[2]->m > EPS ) { - d = (ARRONDI) ? arrondi ( s[0]->chem[2]->m , 4 ) : s[0]->chem[2]->m; - raw_cost += d * 0.64; - } - if ( s[0]->chem[0]->m > EPS ) { - d = (ARRONDI) ? arrondi ( s[0]->chem[0]->m , 4 ) : s[0]->chem[0]->m; - raw_cost += d * 0.11; - } - if ( s[0]->chem[4]->m > EPS ) { - d = (ARRONDI) ? arrondi ( s[0]->chem[4]->m , 4 ) : s[0]->chem[4]->m; - raw_cost += d * 1.19; - } - } - // raw_cost = raw_cost*3600.0*nb_h*nb_d : - raw_cost *= 25920000; - - // util_cost : - util_cost = (units->get_power_sum() * 0.000125 + units->get_water_sum() * 0.00008) * 25920000; - - // Coper : - Itot = y[11]; - Coper = 0.16 * Itot + 2.26 * raw_cost + util_cost; - - - // Rtot : - Rtot = 0.0; - for ( i_stream = 13 ; i_stream < 15 ; i_stream++ ) { - i_chem = 0; - max = 0.0; - mtot = 0.0; - for ( i = 0 ; i < nb_chem ; i++ ) { - m = (ARRONDI) ? arrondi ( s[i_stream]->chem[i]->m , 4 ) : s[i_stream]->chem[i]->m; - - if ( m > EPS ) { - mtot += m; - if ( m > max ) { - max = m; - i_chem = i; - } - } - } - if (mtot > EPS ) { - purity = max/mtot; - d = price[i_chem] * max; - if ( purity < 0.5 ) - d = 0.0; - else if ( purity < 0.6 ) - d *= 0.05; - else if ( purity < 0.7 ) - d *= 0.1; - else if ( purity < 0.8 ) - d *= 0.15; - else if ( purity < 0.9 ) - d *= 0.3; - else if ( purity < 0.95 ) - d *= 0.5; - else if ( purity < 0.98 ) - d *= 0.6; - else if ( purity < 0.99 ) - d *= 0.8; - else if ( purity > 0.995 ) - d *= 1.1; - Rtot += d*25920000; - } - } - - // cash flows : - F = new cashflow(15); - F->set_rates(0.1,0.4); - F->set_basics(Itot, Coper, Rtot); - OK = F->run(); - - // calculating profitability indicators : - if(OK) { - P = new profitability(F); - OK = P->run(y); - delete P; - } - - delete F; - - // arrondis : - if (ARRONDI) { - y[12] = round(y[12]); - y[13] = round(y[13]); - y[ 9] = round(y[ 9]*10)/10.0; - y[10] = round(y[10]*10)/10.0; - } - - g7 = ( y[ 9] < 1e20 ) ? ( y[9] - 4.0 ) / 4.0 : 1e20; - g8 = ( y[10] < 1e20 ) ? (0.2-y[10])/0.2 : 1e20; - g9 = ( y[11] < 1e20 ) ? (y[11]-10e6)/10e6 : 1e20; - g10 = ( y[12] > 0 && y[12] < 1e20 ) ? (y[12]-15e6) / 15e6 : 1e20; - - f = ( y[13] > 0 && y[13] < 1e20 ) ? -y[13] : 1e20; - -// cout << setprecision(10); -// cout << "\n\n"; -// for ( int i = 0 ; i < 14 ; i++ ) -// cout << "y[" << i << "] = " << y[i] << endl; - - - // menage et affichage du resultat de la boite noire : - TERMINATE: - - // cout << "\n\n"; - // cout << " g0 = " << g0 << endl - // << " g1 = " << g1 << endl - // << " g2 = " << g2 << endl - // << " g3 = " << g3 << endl - // << " g4 = " << g4 << endl - // << " g5 = " << g5 << endl - // << " g6 = " << g6 << endl - // << " g7 = " << g7 << endl - // << " g8 = " << g8 << endl - // << " g9 = " << g9 << endl - // << "g10 = " << g10 << endl - // << " f = " << f << endl; - - - cout << g0 << " " - << g1 << " " - << g2 << " " - << g3 << " " - << g4 << " " - << g5 << " " - << g6 << " " - << g7 << " " - << g8 << " " - << g9 << " " - << g10 << " " - << f << endl; - - if (units) - delete units; - if (safe) - delete [] safe; - - if (chem) { - for ( i = 0 ; i < nb_chem ; i++ ) - delete chem[i]; - delete [] chem; - } - - if (s) { - for ( i = 0 ; i < nb_s ; i++ ) - delete s[i]; - delete [] s; - } - - return 0; -} +#include "servor.hpp" +#include "profitability.hpp" +using namespace std; + +/*------------------------------------------------------------------------*/ +/* fonction principale */ +/*------------------------------------------------------------------------*/ +int main ( int argc , char ** argv ) { + + double g0 = 1e+20; + double g1 = 1e+20; + double g2 = 1e+20; + double g3 = 1e+20; + double g4 = 1e+20; + double g5 = 1e+20; + double g6 = 1e+20; + double g7 = 1e+20; + double g8 = 1e+20; + double g9 = 1e+20; + double g10 = 1e+20; + double f = 1e+20; + + bool OK; + ifstream in; + double d; + int i; + int i_stream , i_chem; + double x [8]; + long double tmp[8]; + double raw_cost; + double util_cost; + double Itot; + double Coper; + double Rtot; + double max; + double mtot; + double m; + double purity; + int nb_chem = 7; + int nb_s = 15; + int nb_u = 11; + int n = 8; + double l [8] = { 600 , 2 , 0.0001 , 0.0001 , 2 , 0.01 , 0.1 , 300 }; + double u [8] = { 1100 , 20 , 0.1 , 0.1 , 20 , 0.5 , 5 , 500 }; + double list [7] = { 0.5 , 0 , 0 , 0 , 0 , 0 , 0 }; + double price[7] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 }; + profitability * P = NULL; + cashflow * F = NULL; + chemical ** chem = NULL; + stream ** s = NULL; + servor * units = NULL; + string * safe = NULL; + + // verif. du nombre d'arguments : + if (argc!=2) { + // cout << "\nargc != 2\n\n"; + goto TERMINATE; + } + + // lecture et scaling de x : + // ------------------------- + in.open (argv[1]); + + for ( i = 0 ; i < n ; i++ ) + in >> tmp[i]; + + in.close(); + + if (in.fail()) { + // cout << "\nin.fail (1)\n\n"; + goto TERMINATE; + } + + //for ( i = 0 ; i < n ; i++ ) + // cout << "tmp[" << i << "] = " << tmp[i] << endl; + // cout << endl; + + for ( i = 0 ; i < n ; i++ ) + x[i] = (u[i]-l[i])*((double)tmp[i]/100.0) + l[i]; + + //for ( i = 0 ; i < n ; i++ ) + // cout << "x[" << i << "] = " << x[i] << endl; + + // verifs de x (j'ai pris ca dans checkup et c'est tout ce dont + // ca a besoin de checker ici) : + if ( x[6] < EPS || x[2] < 0 || x[2] > 1 || x[3] < 0 || x[3] > 1 ) + goto TERMINATE; + + // chemicals : + // ----------- + chem = new chemical * [nb_chem]; + chem[0] = new chemical ("100-41-4" ); + chem[1] = new chemical ("1333-74-0"); + chem[2] = new chemical ("108-88-3" ); + chem[3] = new chemical ("74-82-8" ); + chem[4] = new chemical ("71-43-2" ); + chem[5] = new chemical ("74-85-1" ); + chem[6] = new chemical ("100-42-5" ); + + price[6] = 1.39; + price[2] = 0.64; + price[0] = 0.11; + price[4] = 1.19; + + // streams : + // --------- + s = new stream * [nb_s]; + s[ 0] = new stream ( "feed" , nb_chem , chem ); + s[ 1] = new stream ( "2" , nb_chem , chem ); + s[ 2] = new stream ( "3" , nb_chem , chem ); + s[ 3] = new stream ( "4" , nb_chem , chem ); + s[ 4] = new stream ( "5" , nb_chem , chem ); + s[ 5] = new stream ( "6" , nb_chem , chem ); + s[ 6] = new stream ( "7" , nb_chem , chem ); + s[ 7] = new stream ( "8" , nb_chem , chem ); + s[ 8] = new stream ( "9" , nb_chem , chem ); + s[ 9] = new stream ( "10" , nb_chem , chem ); + s[10] = new stream ( "back" , nb_chem , chem ); + s[11] = new stream ( "12" , nb_chem , chem ); + s[12] = new stream ( "stack" , nb_chem , chem ); + s[13] = new stream ( "out-bz" , nb_chem , chem ); + s[14] = new stream ( "out-sty" , nb_chem , chem ); + + // initial conditions on streams : + // ------------------------------- + s[0]->P = 1.0; + s[0]->T = 298; + s[0]->set(list); + + // units settings and calculation sequence : + // ----------------------------------------- + units = new servor ( nb_u , nb_s , s ); + safe = new string[nb_u]; + + units->type[ 0] = "mix"; + units->name[ 0] = safe[ 0] = "mixfeed"; + units->type[ 1] = "pump"; + units->name[ 1] = safe[ 1] = "pump"; + units->type[ 2] = "heatx"; + units->name[ 2] = safe[ 2] = "heater"; + units->type[ 3] = "reactor"; + units->name[ 3] = safe[ 3] = "pfr"; + units->type[ 4] = "heatx"; + units->name[ 4] = safe[ 4] = "cooler"; + units->type[ 5] = "flash"; + units->name[ 5] = safe[ 5] = "degasor"; + units->type[ 6] = "column"; + units->name[ 6] = safe[ 6] = "sep-sty"; + units->type[ 7] = "split"; + units->name[ 7] = safe[ 7] = "spliter"; + units->type[ 8] = "column"; + units->name[ 8] = safe[ 8] = "sep-bz"; + units->type[ 9] = "loop"; + units->name[ 9] = safe[ 9] = "looping"; + units->type[10] = "burner"; + units->name[10] = safe[10] = "fire"; + + + // executing the calculation sequence : + //------------------------------------- + double y[14]; + y[7] = y[8] = 1000.0; + + if (!units->solve_process(x,y)) + goto TERMINATE; + + // on recupere les resultats : + // --------------------------- + y[6] = s[0]->m; + y[3] = s[13]->m; + y[2] = s[13]->chem[4]->m; + y[1] = s[14]->m; + y[0] = s[14]->chem[6]->m; + + y[9 ] = 1e20; + y[10] = 1e20; + y[11] = units->get_costs_sum() * 6.192; + y[12] = 1e20; + y[13] = 1e20; + + // arrondis : + if (ARRONDI) { + y[ 6] = arrondi ( y[ 6] , 4 ); + y[ 3] = arrondi ( y[ 3] , 4 ); + y[ 2] = arrondi ( y[ 2] , 4 ); + y[ 1] = arrondi ( y[ 1] , 4 ); + y[ 0] = arrondi ( y[ 0] , 4 ); + y[11] = arrondi ( y[11] , 6 ); + } + + g0 = ( y[0] > 0 && y[0] < 1e+20 ) ? 0.0 : 1e20; + g1 = ( y[4] <= 80 ) ? 0.0 : 1.0; + g2 = ( y[5] <= 80 ) ? 0.0 : 1.0; + g3 = ( y[7] <= 200 && y[8] <= 8 ) ? 0.0 : 1.0; + g4 = ( y[1] > 0 && y[1] < 1e20 ) ? (0.99-y[0]/y[1])/0.99 : 1e20; + g5 = ( y[3] > 0 && y[3] < 1e20 ) ? (0.99-y[2]/y[3])/0.99 : 1e20; + g6 = ( y[6] > 0 && y[6] < 1e20 ) ? (0.6-y[0]/y[6])/0.6 : 1e20; + + + // bloc econo : + // ------------ + + // raw_cost : + raw_cost = 0.0; + if ( s[0]->m > EPS ) { + if ( s[0]->chem[6]->m > EPS ) { + d = (ARRONDI) ? arrondi ( s[0]->chem[6]->m , 4 ) : s[0]->chem[6]->m; + raw_cost += d * 1.39; + } + if ( s[0]->chem[2]->m > EPS ) { + d = (ARRONDI) ? arrondi ( s[0]->chem[2]->m , 4 ) : s[0]->chem[2]->m; + raw_cost += d * 0.64; + } + if ( s[0]->chem[0]->m > EPS ) { + d = (ARRONDI) ? arrondi ( s[0]->chem[0]->m , 4 ) : s[0]->chem[0]->m; + raw_cost += d * 0.11; + } + if ( s[0]->chem[4]->m > EPS ) { + d = (ARRONDI) ? arrondi ( s[0]->chem[4]->m , 4 ) : s[0]->chem[4]->m; + raw_cost += d * 1.19; + } + } + // raw_cost = raw_cost*3600.0*nb_h*nb_d : + raw_cost *= 25920000; + + // util_cost : + util_cost = (units->get_power_sum() * 0.000125 + units->get_water_sum() * 0.00008) * 25920000; + + // Coper : + Itot = y[11]; + Coper = 0.16 * Itot + 2.26 * raw_cost + util_cost; + + + // Rtot : + Rtot = 0.0; + for ( i_stream = 13 ; i_stream < 15 ; i_stream++ ) { + i_chem = 0; + max = 0.0; + mtot = 0.0; + for ( i = 0 ; i < nb_chem ; i++ ) { + m = (ARRONDI) ? arrondi ( s[i_stream]->chem[i]->m , 4 ) : s[i_stream]->chem[i]->m; + + if ( m > EPS ) { + mtot += m; + if ( m > max ) { + max = m; + i_chem = i; + } + } + } + if (mtot > EPS ) { + purity = max/mtot; + d = price[i_chem] * max; + if ( purity < 0.5 ) + d = 0.0; + else if ( purity < 0.6 ) + d *= 0.05; + else if ( purity < 0.7 ) + d *= 0.1; + else if ( purity < 0.8 ) + d *= 0.15; + else if ( purity < 0.9 ) + d *= 0.3; + else if ( purity < 0.95 ) + d *= 0.5; + else if ( purity < 0.98 ) + d *= 0.6; + else if ( purity < 0.99 ) + d *= 0.8; + else if ( purity > 0.995 ) + d *= 1.1; + Rtot += d*25920000; + } + } + + // cash flows : + F = new cashflow(15); + F->set_rates(0.1,0.4); + F->set_basics(Itot, Coper, Rtot); + OK = F->run(); + + // calculating profitability indicators : + if(OK) { + P = new profitability(F); + OK = P->run(y); + delete P; + } + + delete F; + + // arrondis : + if (ARRONDI) { + y[12] = round(y[12]); + y[13] = round(y[13]); + y[ 9] = round(y[ 9]*10)/10.0; + y[10] = round(y[10]*10)/10.0; + } + + g7 = ( y[ 9] < 1e20 ) ? ( y[9] - 4.0 ) / 4.0 : 1e20; + g8 = ( y[10] < 1e20 ) ? (0.2-y[10])/0.2 : 1e20; + g9 = ( y[11] < 1e20 ) ? (y[11]-10e6)/10e6 : 1e20; + g10 = ( y[12] > 0 && y[12] < 1e20 ) ? (y[12]-15e6) / 15e6 : 1e20; + + f = ( y[13] > 0 && y[13] < 1e20 ) ? -y[13] : 1e20; + +// cout << setprecision(10); +// cout << "\n\n"; +// for ( int i = 0 ; i < 14 ; i++ ) +// cout << "y[" << i << "] = " << y[i] << endl; + + + // menage et affichage du resultat de la boite noire : + TERMINATE: + + // cout << "\n\n"; + // cout << " g0 = " << g0 << endl + // << " g1 = " << g1 << endl + // << " g2 = " << g2 << endl + // << " g3 = " << g3 << endl + // << " g4 = " << g4 << endl + // << " g5 = " << g5 << endl + // << " g6 = " << g6 << endl + // << " g7 = " << g7 << endl + // << " g8 = " << g8 << endl + // << " g9 = " << g9 << endl + // << "g10 = " << g10 << endl + // << " f = " << f << endl; + + + cout << g0 << " " + << g1 << " " + << g2 << " " + << g3 << " " + << g4 << " " + << g5 << " " + << g6 << " " + << g7 << " " + << g8 << " " + << g9 << " " + << g10 << " " + << f << endl; + + if (units) + delete units; + if (safe) + delete [] safe; + + if (chem) { + for ( i = 0 ; i < nb_chem ; i++ ) + delete chem[i]; + delete [] chem; + } + + if (s) { + for ( i = 0 ; i < nb_s ; i++ ) + delete s[i]; + delete [] s; + } + + return 0; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.cpp index 60e3d3883204076214d950171deff58a7ccc7809..d23a93996575be1c12c1d6a882367d2444a7fd60 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.cpp @@ -1,27 +1,27 @@ -#include "bissection.hpp" -using namespace std; - -template <class E> -bool bissection<E>::run() -{ - for (i=1; i<MAX_ITER_BISSECTION; i++) - { - xm=(x1+x2)/2; - // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; - if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) - { - i=MAX_ITER_BISSECTION; - OK=true; - } - else - { - f1 = unit->f(x1); - fm = unit->f(xm); - f2 = unit->f(x2); - if (f1*fm < 0.0) x2 = xm; - if (fm*f2 < 0.0) x1 = xm; - } - } - // if (DEBUG) system("pause"); - return OK; -} +#include "bissection.hpp" +using namespace std; + +template <class E> +bool bissection<E>::run() +{ + for (i=1; i<MAX_ITER_BISSECTION; i++) + { + xm=(x1+x2)/2; + // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; + if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) + { + i=MAX_ITER_BISSECTION; + OK=true; + } + else + { + f1 = unit->f(x1); + fm = unit->f(xm); + f2 = unit->f(x2); + if (f1*fm < 0.0) x2 = xm; + if (fm*f2 < 0.0) x1 = xm; + } + } + // if (DEBUG) system("pause"); + return OK; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.hpp index c277e299792392a6a4331b44dfd49b60a7f53e16..18d4ee6b1cd2949f7b3e8206a5c88629006bca25 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/bissection.hpp @@ -1,31 +1,31 @@ -/* -To use the bissection solver to find the root of a scalar function -when the secant solver fails. - (the parametric object E must have public function such as E->f(x), - where x is the point at which evaluate f.) - 1- construct the solver : solver = new bissect<E>(); - 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are the interval's bounds - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed -*/ -#ifndef BISSECTION_H -#define BISSECTION_H - -#include "defines.hpp" -using namespace std; - -template <class E> -class bissection { -private: - double x1, xm, x2; - double f1, fm, f2; - int i; - bool OK; - E *unit; - -public: - bissection(){x1=xm=x2=f1=fm=f2=0; OK=false;} - void set(E* tmp, double xx1, double xx2) {unit=tmp; x1=xx1; x2=xx2;} - bool run(); - ~bissection(){} -}; -#endif +/* +To use the bissection solver to find the root of a scalar function +when the secant solver fails. + (the parametric object E must have public function such as E->f(x), + where x is the point at which evaluate f.) + 1- construct the solver : solver = new bissect<E>(); + 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are the interval's bounds + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed +*/ +#ifndef BISSECTION_H +#define BISSECTION_H + +#include "defines.hpp" +using namespace std; + +template <class E> +class bissection { +private: + double x1, xm, x2; + double f1, fm, f2; + int i; + bool OK; + E *unit; + +public: + bissection(){x1=xm=x2=f1=fm=f2=0; OK=false;} + void set(E* tmp, double xx1, double xx2) {unit=tmp; x1=xx1; x2=xx2;} + bool run(); + ~bissection(){} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.cpp index eb8a223bf429389fe9ad4b3d8b59b914331d7cc6..1b6f36b09550b2585fa78071983f0f77fc9d4576 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.cpp @@ -1,287 +1,287 @@ -#include "burner.hpp" -using namespace std; - -/*----------------------------------------------------------*/ -/* arrondi pour ne conserver que n chiffres significatifs */ -/*----------------------------------------------------------*/ -double arrondi ( double x , int n ) { - if (fabs(x) < EPS) - return 0.0; - double m = pow ( 10 , ceil(-log10(x)) + n - 1 ); - return round(m*x)/m; -} - -/*---------------------------------------------------------------*/ -burner::burner ( int nb , chemical ** chem ) { - - rem_nb = nb; - - NO=NO2=N2O=CO=0.0; - m = new double[nb]; - can_burn = new bool[nb]; - - // combustion.prop : - // ----------------- - // 64-17-5 3 2 3 - // 74-82-8 2 1 2 - // 1333-74-0 0.5 0 1 - // 100-42-5 10 8 4 - // 74-85-1 3 2 2 - // 108-88-3 9 7 4 - // 100-41-4 10.5 8 5 - // 71-43-2 7.5 6 3 - - for ( i = 0 ; i < nb ; i++ ) { - - can_burn[i] = false; - - if ( chem[i]->CAS == "64-17-5" || - chem[i]->CAS == "74-82-8" || - chem[i]->CAS == "1333-74-0" || - chem[i]->CAS == "100-42-5" || - chem[i]->CAS == "74-85-1" || - chem[i]->CAS == "108-88-3" || - chem[i]->CAS == "100-41-4" || - chem[i]->CAS == "71-43-2" ) - can_burn[i] = true; - } - - O2 = new chemical ("7782-44-7"); - N2 = new chemical ("7727-37-9"); - CO2 = new chemical ("124-38-9"); - H2O = new chemical ("7732-18-5"); - - // Construct the rx array; - rx = new combrx * [nb]; - for ( i = 0 ; i < nb ; i++ ) { - if ( can_burn[i] ) - rx[i] = new combrx ( chem[i]->CAS ); - else - rx[i] = NULL; - } -} - -/*---------------------------------------------------------------*/ -burner::~burner ( void ) { - - delete [] m; - delete [] can_burn; - - for ( i = 0 ; i < rem_nb ; i++ ) - if (rx[i]) - delete rx[i]; - delete [] rx; - - delete O2; - delete N2; - delete CO2; - delete H2O; -} - -/*---------------------------------------------------------------*/ -bool burner::solve(double * y) -{ - OK=true; - //perform mass balance (neglect pollutants flows) - out->m = 0.0; - for(i=0;i<in->nb;i++) - { - if (!can_burn[i]) { - out->chem[i]->m = in->chem[i]->m; - out->m+=out->chem[i]->m; - } - else { - out->chem[i]->m=0.0; - O2->m+=rx[i]->O2_flow()*in->chem[i]->n(); - N2->m+=rx[i]->N2_flow()*in->chem[i]->n(); - CO2->m+=rx[i]->CO2_flow()*in->chem[i]->n(); - H2O->m+=rx[i]->H2O_flow()*in->chem[i]->n(); - } - } - N2->m*=(1.0+eta); - O2->m*=(1.0+eta); - //perform energy balance to find Tout - T = in->T; - - step=10; - Q=1; - // find temperature - while (fabs(step)>TOL_BURN && fabs(Q)>TOL_BURN && T<MAX_TEMP) - { - T+=step; - - if(T>MAX_TEMP) - T=MAX_TEMP; - Q = 0.0; - for ( i = 0 ; i < in->nb ; i++ ) - Q += in->chem[i]->dH ( in->T , T , in->P ) * in->chem[i]->n(); - - for ( i = 0 ; i < in->nb ; i++ ) - if ( can_burn[i] ) - Q += rx[i]->Hcomb(T) * in->chem[i]->n(); - - Q += O2->dH ( 293 , T , in->P ) * O2->n(); - Q += N2->dH ( 293 , T , in->P ) * N2->n(); - - - if (step/fabs(step)*Q >0) - step*= -0.1; - else if (fabs(Q)<10) - step*=0.25; - - } - - - - out->set_thermo(in->thermo); - // out->thermo = in->thermo; - - out->set(in->P, T); - O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); - N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); - CO2->P=in->P; CO2->T=T; CO2->state=1; CO2->find_v(); - H2O->P=in->P; H2O->T=T; H2O->state=1; H2O->find_v(); - //check if mixture can burn - m_can_burn = 0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) m_can_burn+=in->chem[i]->n(); - LFLmix=0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) LFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->LFL(in->P,T); - UFLmix=0.0; - for(i=0;i<in->nb;i++) if(can_burn[i]) UFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->UFL(in->P,T); - num = 0.0; - buff=in->T; in->set(in->P, T); - for(i=0;i<in->nb;i++) if(can_burn[i]) num+=in->chem[i]->n()/in->n()*in->v; - in->set(in->P, buff); - den = O2->v+N2->v+out->v; - composition = num/den; - if(!(LFLmix<=composition && composition<=UFLmix) || T==MAX_TEMP) - { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Mixture in "<<name<<" can't burn (LFL="<<LFLmix -// <<" UFL="<<UFLmix<<" x="<<composition<<").\n"; -// logf.close(); - T=in->T; - filename = out->name; - *out=*in; - out->set(filename); - // out->write(); // WRITE TOTO - OK=false; - } - else - { - O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); - N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); - // out->write(); // WRITE TOTO - } - if(OK) //compute the pollutants production - { - fill_K_array(); - NO = 1e6*sqrt(K[0]*(N2->n()/den)*(O2->n()/den))*den*0.03/(O2->m+N2->m+out->m+H2O->m+CO2->m); - N2O = 1e6*K[1]*(N2->n()/den)*sqrt(O2->n()/den)*den*0.044/(O2->m+N2->m+out->m+H2O->m+CO2->m); - NO2 = 1e6*K[2]*sqrt(N2->n()/den)*(O2->n()/den)*den*0.046/(O2->m+N2->m+out->m+H2O->m+CO2->m); - CO = 1e6*K[3]*(CO2->n()/den)*den/sqrt(O2->n()/den)*0.028/(O2->m+N2->m+out->m+H2O->m+CO2->m); - } -// logf.open(MESSAGES,ios::app); - if (NO>EPS && NO2>EPS && N2O>EPS) { - // logf<<" --> Warning <-- Presence of NOx: "<<(NO+NO2+N2O)<<" ppm in "<<name<<".\n"; - y[7] = NO+NO2+N2O; - - if (ARRONDI) - y[7] = arrondi ( y[7] , 6 ); - - } - if (CO>EPS) { - // logf<<" --> Warning <-- Presence of CO: "<<CO<<" ppm in "<<name<<".\n"; - y[8] = CO; - if (ARRONDI) - y[8] = arrondi ( y[8] , 6 ); - - } -// logf.close(); - return OK; -} - -void burner::fill_K_array() -{ - a[0]=1.0; a[1]=1.0; a[2]=0.5; a[3]=1.0; - b[0]=1.0; b[1]=0.5; b[2]=1.0; b[3]=-0.5; - c[0]=2.0; c[1]=1.0; c[2]=1.0; c[3]=1.0; - K[0] = exp(-120.27*(173.38-T*0.012)/T); - K[1] = exp(-120.27*(103.64+T*0.074)/T); - K[2] = exp(-120.27*(51.96+T*0.061)/T); - K[3] = exp(-120.27*(283.84-T*0.087)/T); - for(i=0;i<4;i++) - K[i]*=pow(1000, c[i]-a[i]-b[i]); -} - -void burner::write() { - - cout << setprecision(6); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in : " << in->name; - cout << endl << "\t>> streams out : " << out->name; - cout << endl << "\t>> P = " << in->P << " atm, T(in) = " << in->T - << " T(out) = " << T << " K"; - O2->P = 1; - O2->T = 293; - O2->state = 1; - O2->find_v(); - N2->P=1; - N2->T=293; - N2->state=1; - N2->find_v(); - cout << endl << "\t>> Required air flow = " - << (O2->m+N2->m) << " kg/s (" << (O2->v+N2->v) << " m3/s)"; - O2->P=in->P; - O2->T=T; - O2->state=1; - O2->find_v(); - N2->P=in->P; - N2->T=T; - N2->state=1; - N2->find_v(); - step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); - cout << endl << "\t>> Total flue gases = " - << (out->m+CO2->m+H2O->m+N2->m+eta*O2->m/(1+eta)) - <<" kg/s (" << step << " m3/s)"; - cout << "\n\tEND\n\n"; - cost(); -} - - -double burner::get_cost ( void ) { - - - O2->P = 1; - O2->T = 293; - O2->state = 1; - O2->find_v(); - N2->P=1; - N2->T=293; - N2->state=1; - N2->find_v(); - O2->P=in->P; - O2->T=T; - O2->state=1; - O2->find_v(); - N2->P=in->P; - N2->T=T; - N2->state=1; - N2->find_v(); - step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); - - buff = 3.1761-0.1373*log10(step) + 0.3414*pow(log10(step),2); - buff = 2.7*pow(10, buff); - buff = buff*MS_YEAR/MS_2001; - - return buff; -} - - -void burner::cost ( void ) { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} +#include "burner.hpp" +using namespace std; + +/*----------------------------------------------------------*/ +/* arrondi pour ne conserver que n chiffres significatifs */ +/*----------------------------------------------------------*/ +double arrondi ( double x , int n ) { + if (fabs(x) < EPS) + return 0.0; + double m = pow ( 10 , ceil(-log10(x)) + n - 1 ); + return round(m*x)/m; +} + +/*---------------------------------------------------------------*/ +burner::burner ( int nb , chemical ** chem ) { + + rem_nb = nb; + + NO=NO2=N2O=CO=0.0; + m = new double[nb]; + can_burn = new bool[nb]; + + // combustion.prop : + // ----------------- + // 64-17-5 3 2 3 + // 74-82-8 2 1 2 + // 1333-74-0 0.5 0 1 + // 100-42-5 10 8 4 + // 74-85-1 3 2 2 + // 108-88-3 9 7 4 + // 100-41-4 10.5 8 5 + // 71-43-2 7.5 6 3 + + for ( i = 0 ; i < nb ; i++ ) { + + can_burn[i] = false; + + if ( chem[i]->CAS == "64-17-5" || + chem[i]->CAS == "74-82-8" || + chem[i]->CAS == "1333-74-0" || + chem[i]->CAS == "100-42-5" || + chem[i]->CAS == "74-85-1" || + chem[i]->CAS == "108-88-3" || + chem[i]->CAS == "100-41-4" || + chem[i]->CAS == "71-43-2" ) + can_burn[i] = true; + } + + O2 = new chemical ("7782-44-7"); + N2 = new chemical ("7727-37-9"); + CO2 = new chemical ("124-38-9"); + H2O = new chemical ("7732-18-5"); + + // Construct the rx array; + rx = new combrx * [nb]; + for ( i = 0 ; i < nb ; i++ ) { + if ( can_burn[i] ) + rx[i] = new combrx ( chem[i]->CAS ); + else + rx[i] = NULL; + } +} + +/*---------------------------------------------------------------*/ +burner::~burner ( void ) { + + delete [] m; + delete [] can_burn; + + for ( i = 0 ; i < rem_nb ; i++ ) + if (rx[i]) + delete rx[i]; + delete [] rx; + + delete O2; + delete N2; + delete CO2; + delete H2O; +} + +/*---------------------------------------------------------------*/ +bool burner::solve(double * y) +{ + OK=true; + //perform mass balance (neglect pollutants flows) + out->m = 0.0; + for(i=0;i<in->nb;i++) + { + if (!can_burn[i]) { + out->chem[i]->m = in->chem[i]->m; + out->m+=out->chem[i]->m; + } + else { + out->chem[i]->m=0.0; + O2->m+=rx[i]->O2_flow()*in->chem[i]->n(); + N2->m+=rx[i]->N2_flow()*in->chem[i]->n(); + CO2->m+=rx[i]->CO2_flow()*in->chem[i]->n(); + H2O->m+=rx[i]->H2O_flow()*in->chem[i]->n(); + } + } + N2->m*=(1.0+eta); + O2->m*=(1.0+eta); + //perform energy balance to find Tout + T = in->T; + + step=10; + Q=1; + // find temperature + while (fabs(step)>TOL_BURN && fabs(Q)>TOL_BURN && T<MAX_TEMP) + { + T+=step; + + if(T>MAX_TEMP) + T=MAX_TEMP; + Q = 0.0; + for ( i = 0 ; i < in->nb ; i++ ) + Q += in->chem[i]->dH ( in->T , T , in->P ) * in->chem[i]->n(); + + for ( i = 0 ; i < in->nb ; i++ ) + if ( can_burn[i] ) + Q += rx[i]->Hcomb(T) * in->chem[i]->n(); + + Q += O2->dH ( 293 , T , in->P ) * O2->n(); + Q += N2->dH ( 293 , T , in->P ) * N2->n(); + + + if (step/fabs(step)*Q >0) + step*= -0.1; + else if (fabs(Q)<10) + step*=0.25; + + } + + + + out->set_thermo(in->thermo); + // out->thermo = in->thermo; + + out->set(in->P, T); + O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); + N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); + CO2->P=in->P; CO2->T=T; CO2->state=1; CO2->find_v(); + H2O->P=in->P; H2O->T=T; H2O->state=1; H2O->find_v(); + //check if mixture can burn + m_can_burn = 0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) m_can_burn+=in->chem[i]->n(); + LFLmix=0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) LFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->LFL(in->P,T); + UFLmix=0.0; + for(i=0;i<in->nb;i++) if(can_burn[i]) UFLmix+=in->chem[i]->n()/m_can_burn*rx[i]->UFL(in->P,T); + num = 0.0; + buff=in->T; in->set(in->P, T); + for(i=0;i<in->nb;i++) if(can_burn[i]) num+=in->chem[i]->n()/in->n()*in->v; + in->set(in->P, buff); + den = O2->v+N2->v+out->v; + composition = num/den; + if(!(LFLmix<=composition && composition<=UFLmix) || T==MAX_TEMP) + { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Mixture in "<<name<<" can't burn (LFL="<<LFLmix +// <<" UFL="<<UFLmix<<" x="<<composition<<").\n"; +// logf.close(); + T=in->T; + filename = out->name; + *out=*in; + out->set(filename); + // out->write(); // WRITE TOTO + OK=false; + } + else + { + O2->P=in->P; O2->T=T; O2->state=1; O2->find_v(); + N2->P=in->P; N2->T=T; N2->state=1; N2->find_v(); + // out->write(); // WRITE TOTO + } + if(OK) //compute the pollutants production + { + fill_K_array(); + NO = 1e6*sqrt(K[0]*(N2->n()/den)*(O2->n()/den))*den*0.03/(O2->m+N2->m+out->m+H2O->m+CO2->m); + N2O = 1e6*K[1]*(N2->n()/den)*sqrt(O2->n()/den)*den*0.044/(O2->m+N2->m+out->m+H2O->m+CO2->m); + NO2 = 1e6*K[2]*sqrt(N2->n()/den)*(O2->n()/den)*den*0.046/(O2->m+N2->m+out->m+H2O->m+CO2->m); + CO = 1e6*K[3]*(CO2->n()/den)*den/sqrt(O2->n()/den)*0.028/(O2->m+N2->m+out->m+H2O->m+CO2->m); + } +// logf.open(MESSAGES,ios::app); + if (NO>EPS && NO2>EPS && N2O>EPS) { + // logf<<" --> Warning <-- Presence of NOx: "<<(NO+NO2+N2O)<<" ppm in "<<name<<".\n"; + y[7] = NO+NO2+N2O; + + if (ARRONDI) + y[7] = arrondi ( y[7] , 6 ); + + } + if (CO>EPS) { + // logf<<" --> Warning <-- Presence of CO: "<<CO<<" ppm in "<<name<<".\n"; + y[8] = CO; + if (ARRONDI) + y[8] = arrondi ( y[8] , 6 ); + + } +// logf.close(); + return OK; +} + +void burner::fill_K_array() +{ + a[0]=1.0; a[1]=1.0; a[2]=0.5; a[3]=1.0; + b[0]=1.0; b[1]=0.5; b[2]=1.0; b[3]=-0.5; + c[0]=2.0; c[1]=1.0; c[2]=1.0; c[3]=1.0; + K[0] = exp(-120.27*(173.38-T*0.012)/T); + K[1] = exp(-120.27*(103.64+T*0.074)/T); + K[2] = exp(-120.27*(51.96+T*0.061)/T); + K[3] = exp(-120.27*(283.84-T*0.087)/T); + for(i=0;i<4;i++) + K[i]*=pow(1000, c[i]-a[i]-b[i]); +} + +void burner::write() { + + cout << setprecision(6); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in : " << in->name; + cout << endl << "\t>> streams out : " << out->name; + cout << endl << "\t>> P = " << in->P << " atm, T(in) = " << in->T + << " T(out) = " << T << " K"; + O2->P = 1; + O2->T = 293; + O2->state = 1; + O2->find_v(); + N2->P=1; + N2->T=293; + N2->state=1; + N2->find_v(); + cout << endl << "\t>> Required air flow = " + << (O2->m+N2->m) << " kg/s (" << (O2->v+N2->v) << " m3/s)"; + O2->P=in->P; + O2->T=T; + O2->state=1; + O2->find_v(); + N2->P=in->P; + N2->T=T; + N2->state=1; + N2->find_v(); + step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); + cout << endl << "\t>> Total flue gases = " + << (out->m+CO2->m+H2O->m+N2->m+eta*O2->m/(1+eta)) + <<" kg/s (" << step << " m3/s)"; + cout << "\n\tEND\n\n"; + cost(); +} + + +double burner::get_cost ( void ) { + + + O2->P = 1; + O2->T = 293; + O2->state = 1; + O2->find_v(); + N2->P=1; + N2->T=293; + N2->state=1; + N2->find_v(); + O2->P=in->P; + O2->T=T; + O2->state=1; + O2->find_v(); + N2->P=in->P; + N2->T=T; + N2->state=1; + N2->find_v(); + step=(eta*O2->v/(1+eta)+N2->v+H2O->v+CO2->v+out->v); + + buff = 3.1761-0.1373*log10(step) + 0.3414*pow(log10(step),2); + buff = 2.7*pow(10, buff); + buff = buff*MS_YEAR/MS_2001; + + return buff; +} + + +void burner::cost ( void ) { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.hpp index 3d834032e5fc8480aa17f95b94b71a9d9fc9cf98..310df0d78663669e1536c1f38750c21102828ee6 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/burner.hpp @@ -1,59 +1,59 @@ -/* -This unit simulates a burner. The user must provide the air excess -and all combustion data as defined in data\\combustion.prop : - CAS nb_moles_O2 nb_moles_CO2 nb_moles_H2O -Then, mass and energy balances are performed and flows of common -combustion pollutants are estimated. -(reference : Crowl & Louvar) - -Structure in the .process file: -burner {name} {index of input stream} {index of output stream} {air excess >0 (ex.: 1.2 is a 120% excess)} - -How to use: - 1- Call the constructor: burn = new burner(in, out); burner(nb_in, chem_list) - ->set(in, out) - 2- Set the air excess : burn->set(excess); - 3- Set the name of the unit: burn->set(name); - 4- Solve: bool=burn->solve(); -*/ -#ifndef BURNER_H -#define BURNER_H -#include "stream.hpp" -#include "combrx.hpp" -using namespace std; - -class burner -{ -private: - - string filename; - int rem_nb; - stream *in, *out; - chemical *O2, *N2, *CO2, *H2O; - combrx **rx; - bool *can_burn, stop, OK; - double eta, NO, NO2, N2O, CO; - double T, LFLmix, UFLmix, composition; - string name; - double * m; - double a[4], b[4], c[4], K[4]; - int i; - double buff, Q, m_can_burn, step, num, den; - ifstream data; - // ofstream logf, results; - // terminator *end; - void fill_K_array(); - -public: - // burner(){}; - burner ( int , chemical ** ); - void set ( stream * s1 , stream * s2 ) { in=s1; out=s2; for(i=0;i<in->nb;i++) m[i] = in->chem[i]->m;} - void set ( const string & n ) { name = n; } - void set(double e) {eta = e;} - bool solve(double * y); - void write(); - void cost(); - double get_cost ( void ); - ~burner(); -}; -#endif +/* +This unit simulates a burner. The user must provide the air excess +and all combustion data as defined in data\\combustion.prop : + CAS nb_moles_O2 nb_moles_CO2 nb_moles_H2O +Then, mass and energy balances are performed and flows of common +combustion pollutants are estimated. +(reference : Crowl & Louvar) + +Structure in the .process file: +burner {name} {index of input stream} {index of output stream} {air excess >0 (ex.: 1.2 is a 120% excess)} + +How to use: + 1- Call the constructor: burn = new burner(in, out); burner(nb_in, chem_list) + ->set(in, out) + 2- Set the air excess : burn->set(excess); + 3- Set the name of the unit: burn->set(name); + 4- Solve: bool=burn->solve(); +*/ +#ifndef BURNER_H +#define BURNER_H +#include "stream.hpp" +#include "combrx.hpp" +using namespace std; + +class burner +{ +private: + + string filename; + int rem_nb; + stream *in, *out; + chemical *O2, *N2, *CO2, *H2O; + combrx **rx; + bool *can_burn, stop, OK; + double eta, NO, NO2, N2O, CO; + double T, LFLmix, UFLmix, composition; + string name; + double * m; + double a[4], b[4], c[4], K[4]; + int i; + double buff, Q, m_can_burn, step, num, den; + ifstream data; + // ofstream logf, results; + // terminator *end; + void fill_K_array(); + +public: + // burner(){}; + burner ( int , chemical ** ); + void set ( stream * s1 , stream * s2 ) { in=s1; out=s2; for(i=0;i<in->nb;i++) m[i] = in->chem[i]->m;} + void set ( const string & n ) { name = n; } + void set(double e) {eta = e;} + bool solve(double * y); + void write(); + void cost(); + double get_cost ( void ); + ~burner(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.cpp index c7174f643dda84b2d8082bb6f4ba55135f405d52..a35a767865f7f1761450f84acf60c65e996d8311 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.cpp @@ -1,114 +1,114 @@ -#include "cashflow.hpp" -using namespace std; - -cashflow::cashflow(int n) -{ - N=n+1; - Inv = new double[N]; - Coper = new double[N]; - Amort = new double[N]; - Rev = new double[N]; - Flow = new double[N]; - Flowact = new double[N]; - Itot=Ctot=Rtot=i_rate=a_rate=0.0; - - - yield_tab[ 0] = 0.515; - yield_tab[ 1] = 0.778; - yield_tab[ 2] = 0.812; - yield_tab[ 3] = 0.893; - yield_tab[ 4] = 0.985; - yield_tab[ 5] = 0.837; - yield_tab[ 6] = 0.849; - yield_tab[ 7] = 0.746; - yield_tab[ 8] = 0.812; - yield_tab[ 9] = 0.954; - yield_tab[10] = 0.999; - yield_tab[11] = 0.961; - yield_tab[12] = 0.815; - yield_tab[13] = 0.886; - yield_tab[14] = 0.922; - -} - -cashflow::~cashflow ( void ) { - delete [] Inv; - delete [] Coper; - delete [] Amort; - delete [] Rev; - delete [] Flow; - delete [] Flowact; -} - -bool cashflow::run() -{ - if(Itot<EPS || Ctot<EPS || Rtot<EPS || i_rate<EPS || a_rate<EPS) - OK=false; - else - { - //if(!MUTE)cout<<endl<<" investments flow... OK"; - set_Inv(); - //if(!MUTE)cout<<endl<<" depreciation flow... OK"; - set_Amort(); - set_C_R(); - //if(!MUTE)cout<<endl<<" costs flow... OK"; - //if(!MUTE)cout<<endl<<" revenus flow... OK"; - for(i=0;i<N;i++) - { - Flow[i] = (Rev[i]-Coper[i])*(1.0-a_rate)-(Inv[i]-a_rate*Amort[i]); - Flowact[i] = Flow[i]/pow(1.0+i_rate, i); - } - //if(!MUTE)cout<<endl<<" cash flow... OK"; - //if(!MUTE)cout<<endl<<" actualizing cash flow... OK"; - OK=true; - -// cout<<endl<<endl<<" CASH FLOW DETAILS"<<endl; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; -// cout<<endl<<" "<<" i "<<" Investment "<<" Deprec. " -// <<" Expenses "<<" Revenus "<<" Cash flow "<<" Act. flow "; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; -// cout<<setfill(' ')<<setiosflags(ios::fixed)<<setprecision(0); -// for(i=0;i<N;i++) -// cout<<endl -// <<" "<<setw(2)<<i<<" "<<setw(11) -// <<Inv[i]<<" "<<setw(11)<<Amort[i]<<" " -// <<setw(11)<<Coper[i]<<" "<<setw(11)<<Rev[i]<<" "<<setw(11)<<Flow[i]<<" "<<setw(11)<<Flowact[i]; -// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; - } - return OK; -} - -void cashflow::set_Amort() -{ - Amort[0] = 0.0; - temp=Itot; - for(i=1;i<N-1;i++) - { - temp+=Inv[i]; - Amort[i] = temp/double(N-i); - temp-=Amort[i]; - } - Amort[N-1]=Amort[N-2]; -} - -void cashflow::set_Inv() -{ - Inv[0] = Itot; - for(i=1;i<N-1;i++) - { - if((i)%5==0) Inv[i]=0.1*Itot; - else Inv[i]=0.0; - } - Inv[N-1]=0.0; - for(i=0;i<N-1;i++) Inv[N-1]-=0.1*Inv[i]; -} - -void cashflow::set_C_R() -{ - Coper[0] = Rev[0] = 0.0; - for(i=1;i<N;i++) - { - Coper[i] = yield(i)*Ctot; - Rev[i] = yield(i)*Rtot; - } -} +#include "cashflow.hpp" +using namespace std; + +cashflow::cashflow(int n) +{ + N=n+1; + Inv = new double[N]; + Coper = new double[N]; + Amort = new double[N]; + Rev = new double[N]; + Flow = new double[N]; + Flowact = new double[N]; + Itot=Ctot=Rtot=i_rate=a_rate=0.0; + + + yield_tab[ 0] = 0.515; + yield_tab[ 1] = 0.778; + yield_tab[ 2] = 0.812; + yield_tab[ 3] = 0.893; + yield_tab[ 4] = 0.985; + yield_tab[ 5] = 0.837; + yield_tab[ 6] = 0.849; + yield_tab[ 7] = 0.746; + yield_tab[ 8] = 0.812; + yield_tab[ 9] = 0.954; + yield_tab[10] = 0.999; + yield_tab[11] = 0.961; + yield_tab[12] = 0.815; + yield_tab[13] = 0.886; + yield_tab[14] = 0.922; + +} + +cashflow::~cashflow ( void ) { + delete [] Inv; + delete [] Coper; + delete [] Amort; + delete [] Rev; + delete [] Flow; + delete [] Flowact; +} + +bool cashflow::run() +{ + if(Itot<EPS || Ctot<EPS || Rtot<EPS || i_rate<EPS || a_rate<EPS) + OK=false; + else + { + //if(!MUTE)cout<<endl<<" investments flow... OK"; + set_Inv(); + //if(!MUTE)cout<<endl<<" depreciation flow... OK"; + set_Amort(); + set_C_R(); + //if(!MUTE)cout<<endl<<" costs flow... OK"; + //if(!MUTE)cout<<endl<<" revenus flow... OK"; + for(i=0;i<N;i++) + { + Flow[i] = (Rev[i]-Coper[i])*(1.0-a_rate)-(Inv[i]-a_rate*Amort[i]); + Flowact[i] = Flow[i]/pow(1.0+i_rate, i); + } + //if(!MUTE)cout<<endl<<" cash flow... OK"; + //if(!MUTE)cout<<endl<<" actualizing cash flow... OK"; + OK=true; + +// cout<<endl<<endl<<" CASH FLOW DETAILS"<<endl; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; +// cout<<endl<<" "<<" i "<<" Investment "<<" Deprec. " +// <<" Expenses "<<" Revenus "<<" Cash flow "<<" Act. flow "; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; +// cout<<setfill(' ')<<setiosflags(ios::fixed)<<setprecision(0); +// for(i=0;i<N;i++) +// cout<<endl +// <<" "<<setw(2)<<i<<" "<<setw(11) +// <<Inv[i]<<" "<<setw(11)<<Amort[i]<<" " +// <<setw(11)<<Coper[i]<<" "<<setw(11)<<Rev[i]<<" "<<setw(11)<<Flow[i]<<" "<<setw(11)<<Flowact[i]; +// cout<<endl<<" "<<setfill('-')<<setw(76)<<" "; + } + return OK; +} + +void cashflow::set_Amort() +{ + Amort[0] = 0.0; + temp=Itot; + for(i=1;i<N-1;i++) + { + temp+=Inv[i]; + Amort[i] = temp/double(N-i); + temp-=Amort[i]; + } + Amort[N-1]=Amort[N-2]; +} + +void cashflow::set_Inv() +{ + Inv[0] = Itot; + for(i=1;i<N-1;i++) + { + if((i)%5==0) Inv[i]=0.1*Itot; + else Inv[i]=0.0; + } + Inv[N-1]=0.0; + for(i=0;i<N-1;i++) Inv[N-1]-=0.1*Inv[i]; +} + +void cashflow::set_C_R() +{ + Coper[0] = Rev[0] = 0.0; + for(i=1;i<N;i++) + { + Coper[i] = yield(i)*Ctot; + Rev[i] = yield(i)*Rtot; + } +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.hpp index a71b7abf72e7322f1ed2c25256e1bedcd5a610f9..5aa5f70ead6aa4bf754d8175e1dbe9358b458352 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/cashflow.hpp @@ -1,33 +1,33 @@ -#ifndef CASHFLOW_H -#define CASHFLOW_H -#include "defines.hpp" -// #include <iomanip> -using namespace std; - -class cashflow -{ - private: - // char name[31], filename[41]; - // ifstream in; - // ofstream out; - double Itot, Ctot, Rtot; - void set_Inv(), set_Amort(), set_C_R(); - double temp; - int i, j, counter; - bool OK; - double yield_tab[15]; - - double yield ( int k ) const { return yield_tab[(k==15) ? 14 : k%15]; } - -public: - double *Inv, *Coper, *Amort, *Rev, *Flow, *Flowact; - double i_rate, a_rate; - int N; - cashflow(int); - ~cashflow(); - // void set(char n[31]) {strcpy(name, n);} - void set_rates(double d1, double d2){i_rate=d1; a_rate=d2;} - void set_basics(double d1, double d2, double d3){Itot=d1; Ctot=d2; Rtot=d3;} - bool run(); -}; -#endif +#ifndef CASHFLOW_H +#define CASHFLOW_H +#include "defines.hpp" +// #include <iomanip> +using namespace std; + +class cashflow +{ + private: + // char name[31], filename[41]; + // ifstream in; + // ofstream out; + double Itot, Ctot, Rtot; + void set_Inv(), set_Amort(), set_C_R(); + double temp; + int i, j, counter; + bool OK; + double yield_tab[15]; + + double yield ( int k ) const { return yield_tab[(k==15) ? 14 : k%15]; } + +public: + double *Inv, *Coper, *Amort, *Rev, *Flow, *Flowact; + double i_rate, a_rate; + int N; + cashflow(int); + ~cashflow(); + // void set(char n[31]) {strcpy(name, n);} + void set_rates(double d1, double d2){i_rate=d1; a_rate=d2;} + void set_basics(double d1, double d2, double d3){Itot=d1; Ctot=d2; Rtot=d3;} + bool run(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.cpp index af4d12aa7ee6ff9924b960263d7296fa9451abef..2fb1052a36b84c7e0fa6b83e1db77a60086018cb 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.cpp @@ -1,529 +1,529 @@ -#include "chemical.hpp" -using namespace std; - -void chemical::check_error ( void ) { - if (error>MAX_ERROR) { - cout << "ERROR 2\n\n"; - exit(0); - } - if (warning>MAX_WARNING) { - cout << "ERROR 3\n\n"; - exit(0); - } -} - -// copy-constr. : -chemical::chemical ( const chemical & chem ) { - - CAS = chem.CAS; - name = chem.name; - M = chem.M; - - state = chem.state; - Tm = chem.Tm; - Tb = chem.Tb; - Tc = chem.Tc; - Pc = chem.Pc; - Ho = chem.Ho; - rho_liq = chem.rho_liq; - dHvap = chem.dHvap; - - mu_param[0] = chem.mu_param[0]; - mu_param[1] = chem.mu_param[1]; - Cp_param[0] = chem.Cp_param[0]; - Cp_param[1] = chem.Cp_param[1]; - Cp_param[2] = chem.Cp_param[2]; - Cp_param[3] = chem.Cp_param[3]; - Cp_liq = chem.Cp_liq; - Psat_param[0] = chem.Psat_param[0]; - Psat_param[1] = chem.Psat_param[1]; - Psat_param[2] = chem.Psat_param[2]; - - thermo = new thermolib(); - thermo->send(Pc,Tc, omega()); - - P = chem.P; - T = chem.T; - m = chem.m; - v = chem.v; - - warning = chem.warning; - error = chem.error; - tmp = chem.tmp; -} - -chemical::chemical ( const string & chem_name ) { - - CAS = chem_name; - - // C. Tribes add initialization for more robustness (variables may be initialized uncorrectly dependent on the execution) - P=T=m=v=0.0; - - // 1/12 : - if (CAS=="100-41-4") { - name = "ethylbenzene"; - M = 106.17; - state = 0; - Tm = 178.2; - Tb = 409.3; - Tc = 617.1; - Pc = 35.6; - Ho = 29.79; - rho_liq = 867.0; - dHvap = 35.56; - mu_param[0] = 472.82; - mu_param[1] = 264.22; - Cp_param[0] = -43.069; - Cp_param[1] = 7.067e-01; - Cp_param[2] = -4.807e-04; - Cp_param[3] = 1.30e-07; - Cp_liq = 190.23; - Psat_param[0] = 16.0195; - Psat_param[1] = 3279.47; - Psat_param[2] = -59.95; - } - - // 2/12 : - else if (CAS=="1333-74-0") { - name = "hydrogen"; - M = 2.02; - state = 1; - Tm = 14.0; - Tb = 20.4; - Tc = 33.2; - Pc = 12.8; - Ho = 0.0; - rho_liq = 71.0; - dHvap = 0.9; - mu_param[0] = 13.82; - mu_param[1] = 5.39; - Cp_param[0] = 27.124; - Cp_param[1] = 9.267e-03; - Cp_param[2] = -1.380e-05; - Cp_param[3] = 7.64e-09; - Cp_liq = 0.0; - Psat_param[0] = 13.6333; - Psat_param[1] = 164.90; - Psat_param[2] = 3.19; - } - - // 3/12 : - else if (CAS=="108-88-3") { - name = "toluene"; - M =92.14; - state = 0; - Tm = 178.0; - Tb = 383.8; - Tc = 591.7; - Pc = 40.6; - Ho = 50.0; - rho_liq = 867; - dHvap = 33.18; - mu_param[0] = 467.33; - mu_param[1] = 255.24; - Cp_param[0] = -24.338; - Cp_param[1] = 5.121e-1; - Cp_param[2] = -2.763e-4; - Cp_param[3] = 4.91e-8; - Cp_liq = 159.85; - Psat_param[0] = 16.0137; - Psat_param[1] = 3096.52; - Psat_param[2] = -53.67; - } - - // 4/12 : - else if (CAS=="74-82-8") { - name = "methane"; - M =16.04; - state =1; - Tm = 90.7; - Tb = 111.7; - Tc = 190.6; - Pc = 45.4; - Ho = -74.85; - rho_liq = 425; - dHvap = 8.18; - mu_param[0] = 114.14; - mu_param[1] = 57.60; - Cp_param[0] = 19.238; - Cp_param[1] = 5.209e-02; - Cp_param[2] = 1.197e-05; - Cp_param[3] = -1.13e-08; - Cp_liq = 0.0; - Psat_param[0] = 15.2243; - Psat_param[1] = 897.84; - Psat_param[2] = -7.16; - } - - // 5/12 : - else if (CAS=="71-43-2") { - name = "benzene"; - M = 78.11; - state = 0; - Tm = 278.7; - Tb = 353.3; - Tc = 562.1; - Pc = 48.3; - Ho = 82.93; - rho_liq = 885; - dHvap = 30.76; - mu_param[0] = 545.64; - mu_param[1] = 265.24; - Cp_param[0] = 33.894; - Cp_param[1] = 4.74e-1; - Cp_param[2] = -3.015e-4; - Cp_param[3] = 7.13e-8; - Cp_liq = 116.03; - Psat_param[0] = 15.9008; - Psat_param[1] = 2788.51; - Psat_param[2] = -52.36; - } - - // 6/12 : - else if (CAS=="74-85-1") { - name = "ethylene"; - M = 28.05; - state =1; - Tm = 104.0; - Tb = 169.4; - Tc = 282.4; - Pc = 49.7; - Ho =52.3; - rho_liq = 577.0; - dHvap = 13.54; - mu_param[0] = 168.98; - mu_param[1] = 93.94; - Cp_param[0] = 3.803; - Cp_param[1] = 1.565e-01; - Cp_param[2] = -8.343e-05; - Cp_param[3] = 1.75e-08; - Cp_liq = 0.0; - Psat_param[0] =15.5368; - Psat_param[1] = 1347.01; - Psat_param[2] = -18.15; - } - - // 7/12 : - else if (CAS=="100-42-5") { - name = "styrene"; - M =104.15; - state = 0; - Tm = 242.5; - Tb = 418.3; - Tc =647.0; - Pc =39.4; - Ho =147.36; - rho_liq =906.0; - dHvap = 36.82; - mu_param[0] = 528.64; - mu_param[1] = 276.71; - Cp_param[0] =-28.229; - Cp_param[1] =6.155e-01; - Cp_param[2] = -4.020e-04; - Cp_param[3] = 9.93e-08; - Cp_liq =166.13; - Psat_param[0] = 16.0193; - Psat_param[1] = 3328.57; - Psat_param[2] =-63.72; - } - - // 8/12 : - else if (CAS=="7782-44-7") { - name = "oxygen"; - M = 32.00; - state = 1; - Tm = 54.4; - Tb = 90.2; - Tc = 154.6; - Pc = 49.8; - Ho =0.0 ; - rho_liq =1149.1 ; - dHvap =6.82 ; - mu_param[0] = 85.68; - mu_param[1] = 51.50; - Cp_param[0] = 28.087; - Cp_param[1] = -3.678e-06 ; - Cp_param[2] = 1.745e-05; - Cp_param[3] = -1.06e-08; - Cp_liq =0.0 ; - Psat_param[0] = 15.4075; - Psat_param[1] = 734.55 ; - Psat_param[2] =-6.45 ; - } - - // 9/12 : - else if (CAS=="7727-37-9") { - name = "nitrogen"; - M = 28.01; - state = 1; - Tm = 63.3; - Tb = 77.4; - Tc = 126.2; - Pc = 33.5; - Ho = 0.0; - rho_liq = 804.0; - dHvap = 5.58; - mu_param[0] = 90.30; - mu_param[1] = 46.41; - Cp_param[0] = 31.128; - Cp_param[1] = -1.356e-02 ; - Cp_param[2] = 2.678e-05; - Cp_param[3] =-1.17e-08 ; - Cp_liq = 0.0; - Psat_param[0] = 14.9342; - Psat_param[1] = 588.72; - Psat_param[2] = -6.60; - } - - // 10/12 : - else if (CAS=="124-38-9") { - name = "carbon-dioxide"; - M =44.01; - state = 1; - Tm = 216.6; - Tb = 194.4; - Tc = 304.2; - Pc = 72.8; - Ho = -393.41; - rho_liq = 777.0; - dHvap = 17.15; - mu_param[0] = 578.08; - mu_param[1] = 185.24 ; - Cp_param[0] = 19.782; - Cp_param[1] = 7.339e-02; - Cp_param[2] = -5.598e-05; - Cp_param[3] = 1.71e-08; - Cp_liq = 0.0; - Psat_param[0] = 22.5898; - Psat_param[1] =3103.39 ; - Psat_param[2] = -0.16; - } - - // 11/12 : - else if (CAS=="7732-18-5") { - name = "water"; - M =18.02; - state = 0; - Tm = 273.15; - Tb = 373.15; - Tc = 647.4; - Pc = 217.6; - Ho = -241.83; - rho_liq = 998 ; - dHvap = 40.66; - mu_param[0] = 658.25; - mu_param[1] = 283.16; - Cp_param[0] = 32.220; - Cp_param[1] = 1.923e-03 ; - Cp_param[2] = 1.055e-05; - Cp_param[3] = -3.59e-09; - Cp_liq = 75.24; - Psat_param[0] = 18.3036; - Psat_param[1] = 3816.44; - Psat_param[2] = -46.13; - } - - // 12/12 : - else if (CAS=="64-17-5") { - name = "ethanol"; - M =46.07; - state =0 ; - Tm =159.1 ; - Tb = 351.5; - Tc = 516.2; - Pc =63.0 ; - Ho = -234.8; - rho_liq = 789.0; - dHvap =38.74 ; - mu_param[0] = 686.64; - mu_param[1] = 300.88; - Cp_param[0] = 9.008; - Cp_param[1] = 2.139e-01; - Cp_param[2] = -8.385e-05 ; - Cp_param[3] = 1.37e-09; - Cp_liq = 2.22; - Psat_param[0] = 18.9119; - Psat_param[1] = 3803.98; - Psat_param[2] = -41.68; - } - - else { - cout << "ERROR 1\n\n"; - exit(0); - } - - thermo = new thermolib(); - thermo->send(Pc,Tc, omega()); - - -} - -double chemical::K() -{ - thermo->set(P,T,v,n()); - return thermo->K(); -} - -double chemical::mu() -{ - // Returns the fluid's viscosity in Pa.s - if (Tm<=T && T<=Tboil(P)) - return pow(10,(mu_param[0]*(1.0/T-1.0/mu_param[1])-3)); - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot compute viscosity of "<<name<<".\n"; - logf.close(); - warning++; - check_error(); - return 1.0; - } -} - -double chemical::rho() -{ - // Returns the fluid's density in kg/m3, wether it's liquid or gas - if(state==0) tmp= rho_liq; - if(state==1) - { - find_v(); - if (v>EPS) tmp= m/v; - else tmp= 0.0; - } - return tmp; -} - -double chemical::Cp() { - // cout<<endl<<"Cp de "<<name<<" a "<<T; - // Returns the fluid's Cp in J/mol.K - if(state==0) { - - // tmp = Cp_liq; // BUG : boucle infinie !!! - return Cp_liq; // SEB - - } - if(state==1 || T>Tboil(P)) { - tmp=0; - for (int i=0;i<4;i++) - tmp+=Cp_param[i]*pow(T,i); - } - else { - T=Tb; - - tmp = Cp(); // ici boucle infinie si state==0 !!! - - } - return tmp; -} - -double chemical::Cp(bool q) -{ - // Returns the fluid's Cp in J/mol.K - if(q==0) tmp=Cp_liq; - if(q==1) - { - tmp=0; - for (int i=0;i<4;i++) tmp+=Cp_param[i]*pow(T,i); - } - return tmp; -} - -double chemical::Psat() -{ - // Returns the fluid's vapor pressure in atm, using Antoine's equation - if(Tm<=T && T<=Tc) - return (exp(Psat_param[0]-Psat_param[1]/(T+Psat_param[2]))/760.01); - else - { - - return Psat(Tb); - } -} -double chemical::Psat(double t) -{ - // Returns the fluid's vapor pressure in atm, using Antoine's equation - return (exp(Psat_param[0]-Psat_param[1]/(t+Psat_param[2]))/760.01); -} - -double chemical::dH(double T1,double T2, double pres) -{ - //Enthalpy variation in kJ/mol. Does not affect any attributes of current object. - double energy=0, TT=Tboil(pres), vap=Hvap(TT); - int sign=1, i; - if (T2<T1) {sign = -1; energy=T1; T1=T2; T2=energy; energy=0;} - if (T1==T2) energy = 0.0; - if (T2<TT) energy = Cp_liq*(T2-T1)/1000; - if (TT<T1) for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(T1,i))/i/1000; - if(T1<=TT && TT<=T2) - { - energy=Cp_liq*(TT-T1)/1000; - energy+=vap; - for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(TT,i))/i/1000; - } - return energy*sign; -} - -void chemical::find_T() -{ - if(n()>EPS && P>EPS) - { - thermo->set(P,T,v,n()); - T=thermo->T(); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot find T of "<<name<<".\n"; - logf.close(); - warning++; - } - check_error(); -} - -void chemical::find_P() -{ - if(n()>EPS && T>EPS) - { - thermo->set(P,T,v,n()); - P=thermo->P(); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot find P of "<<name<<".\n"; - logf.close(); - warning++; - } - check_error(); -} - -void chemical::find_v() -{ - - if(state==0) v=m/rho_liq; - if(state==1 && P>EPS && T>EPS && m>EPS) - { - thermo->set(P,T,v,n()); - v=thermo->v(); - } -} - -void chemical::find_state() -{ - ofstream logf; - if (T>Tc || P>Pc) state = 1; //T or P is bigger than Tc or Pc - if (T<=Tm) //T is smaller than melting point - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- The chemical "<<name<<" is solid.\n"; - logf.close(); - warning++; - } - check_error(); - if (T<Tboil(P)) state=0; - else state=1; -} +#include "chemical.hpp" +using namespace std; + +void chemical::check_error ( void ) { + if (error>MAX_ERROR) { + cout << "ERROR 2\n\n"; + exit(0); + } + if (warning>MAX_WARNING) { + cout << "ERROR 3\n\n"; + exit(0); + } +} + +// copy-constr. : +chemical::chemical ( const chemical & chem ) { + + CAS = chem.CAS; + name = chem.name; + M = chem.M; + + state = chem.state; + Tm = chem.Tm; + Tb = chem.Tb; + Tc = chem.Tc; + Pc = chem.Pc; + Ho = chem.Ho; + rho_liq = chem.rho_liq; + dHvap = chem.dHvap; + + mu_param[0] = chem.mu_param[0]; + mu_param[1] = chem.mu_param[1]; + Cp_param[0] = chem.Cp_param[0]; + Cp_param[1] = chem.Cp_param[1]; + Cp_param[2] = chem.Cp_param[2]; + Cp_param[3] = chem.Cp_param[3]; + Cp_liq = chem.Cp_liq; + Psat_param[0] = chem.Psat_param[0]; + Psat_param[1] = chem.Psat_param[1]; + Psat_param[2] = chem.Psat_param[2]; + + thermo = new thermolib(); + thermo->send(Pc,Tc, omega()); + + P = chem.P; + T = chem.T; + m = chem.m; + v = chem.v; + + warning = chem.warning; + error = chem.error; + tmp = chem.tmp; +} + +chemical::chemical ( const string & chem_name ) { + + CAS = chem_name; + + // C. Tribes add initialization for more robustness (variables may be initialized uncorrectly dependent on the execution) + P=T=m=v=0.0; + + // 1/12 : + if (CAS=="100-41-4") { + name = "ethylbenzene"; + M = 106.17; + state = 0; + Tm = 178.2; + Tb = 409.3; + Tc = 617.1; + Pc = 35.6; + Ho = 29.79; + rho_liq = 867.0; + dHvap = 35.56; + mu_param[0] = 472.82; + mu_param[1] = 264.22; + Cp_param[0] = -43.069; + Cp_param[1] = 7.067e-01; + Cp_param[2] = -4.807e-04; + Cp_param[3] = 1.30e-07; + Cp_liq = 190.23; + Psat_param[0] = 16.0195; + Psat_param[1] = 3279.47; + Psat_param[2] = -59.95; + } + + // 2/12 : + else if (CAS=="1333-74-0") { + name = "hydrogen"; + M = 2.02; + state = 1; + Tm = 14.0; + Tb = 20.4; + Tc = 33.2; + Pc = 12.8; + Ho = 0.0; + rho_liq = 71.0; + dHvap = 0.9; + mu_param[0] = 13.82; + mu_param[1] = 5.39; + Cp_param[0] = 27.124; + Cp_param[1] = 9.267e-03; + Cp_param[2] = -1.380e-05; + Cp_param[3] = 7.64e-09; + Cp_liq = 0.0; + Psat_param[0] = 13.6333; + Psat_param[1] = 164.90; + Psat_param[2] = 3.19; + } + + // 3/12 : + else if (CAS=="108-88-3") { + name = "toluene"; + M =92.14; + state = 0; + Tm = 178.0; + Tb = 383.8; + Tc = 591.7; + Pc = 40.6; + Ho = 50.0; + rho_liq = 867; + dHvap = 33.18; + mu_param[0] = 467.33; + mu_param[1] = 255.24; + Cp_param[0] = -24.338; + Cp_param[1] = 5.121e-1; + Cp_param[2] = -2.763e-4; + Cp_param[3] = 4.91e-8; + Cp_liq = 159.85; + Psat_param[0] = 16.0137; + Psat_param[1] = 3096.52; + Psat_param[2] = -53.67; + } + + // 4/12 : + else if (CAS=="74-82-8") { + name = "methane"; + M =16.04; + state =1; + Tm = 90.7; + Tb = 111.7; + Tc = 190.6; + Pc = 45.4; + Ho = -74.85; + rho_liq = 425; + dHvap = 8.18; + mu_param[0] = 114.14; + mu_param[1] = 57.60; + Cp_param[0] = 19.238; + Cp_param[1] = 5.209e-02; + Cp_param[2] = 1.197e-05; + Cp_param[3] = -1.13e-08; + Cp_liq = 0.0; + Psat_param[0] = 15.2243; + Psat_param[1] = 897.84; + Psat_param[2] = -7.16; + } + + // 5/12 : + else if (CAS=="71-43-2") { + name = "benzene"; + M = 78.11; + state = 0; + Tm = 278.7; + Tb = 353.3; + Tc = 562.1; + Pc = 48.3; + Ho = 82.93; + rho_liq = 885; + dHvap = 30.76; + mu_param[0] = 545.64; + mu_param[1] = 265.24; + Cp_param[0] = 33.894; + Cp_param[1] = 4.74e-1; + Cp_param[2] = -3.015e-4; + Cp_param[3] = 7.13e-8; + Cp_liq = 116.03; + Psat_param[0] = 15.9008; + Psat_param[1] = 2788.51; + Psat_param[2] = -52.36; + } + + // 6/12 : + else if (CAS=="74-85-1") { + name = "ethylene"; + M = 28.05; + state =1; + Tm = 104.0; + Tb = 169.4; + Tc = 282.4; + Pc = 49.7; + Ho =52.3; + rho_liq = 577.0; + dHvap = 13.54; + mu_param[0] = 168.98; + mu_param[1] = 93.94; + Cp_param[0] = 3.803; + Cp_param[1] = 1.565e-01; + Cp_param[2] = -8.343e-05; + Cp_param[3] = 1.75e-08; + Cp_liq = 0.0; + Psat_param[0] =15.5368; + Psat_param[1] = 1347.01; + Psat_param[2] = -18.15; + } + + // 7/12 : + else if (CAS=="100-42-5") { + name = "styrene"; + M =104.15; + state = 0; + Tm = 242.5; + Tb = 418.3; + Tc =647.0; + Pc =39.4; + Ho =147.36; + rho_liq =906.0; + dHvap = 36.82; + mu_param[0] = 528.64; + mu_param[1] = 276.71; + Cp_param[0] =-28.229; + Cp_param[1] =6.155e-01; + Cp_param[2] = -4.020e-04; + Cp_param[3] = 9.93e-08; + Cp_liq =166.13; + Psat_param[0] = 16.0193; + Psat_param[1] = 3328.57; + Psat_param[2] =-63.72; + } + + // 8/12 : + else if (CAS=="7782-44-7") { + name = "oxygen"; + M = 32.00; + state = 1; + Tm = 54.4; + Tb = 90.2; + Tc = 154.6; + Pc = 49.8; + Ho =0.0 ; + rho_liq =1149.1 ; + dHvap =6.82 ; + mu_param[0] = 85.68; + mu_param[1] = 51.50; + Cp_param[0] = 28.087; + Cp_param[1] = -3.678e-06 ; + Cp_param[2] = 1.745e-05; + Cp_param[3] = -1.06e-08; + Cp_liq =0.0 ; + Psat_param[0] = 15.4075; + Psat_param[1] = 734.55 ; + Psat_param[2] =-6.45 ; + } + + // 9/12 : + else if (CAS=="7727-37-9") { + name = "nitrogen"; + M = 28.01; + state = 1; + Tm = 63.3; + Tb = 77.4; + Tc = 126.2; + Pc = 33.5; + Ho = 0.0; + rho_liq = 804.0; + dHvap = 5.58; + mu_param[0] = 90.30; + mu_param[1] = 46.41; + Cp_param[0] = 31.128; + Cp_param[1] = -1.356e-02 ; + Cp_param[2] = 2.678e-05; + Cp_param[3] =-1.17e-08 ; + Cp_liq = 0.0; + Psat_param[0] = 14.9342; + Psat_param[1] = 588.72; + Psat_param[2] = -6.60; + } + + // 10/12 : + else if (CAS=="124-38-9") { + name = "carbon-dioxide"; + M =44.01; + state = 1; + Tm = 216.6; + Tb = 194.4; + Tc = 304.2; + Pc = 72.8; + Ho = -393.41; + rho_liq = 777.0; + dHvap = 17.15; + mu_param[0] = 578.08; + mu_param[1] = 185.24 ; + Cp_param[0] = 19.782; + Cp_param[1] = 7.339e-02; + Cp_param[2] = -5.598e-05; + Cp_param[3] = 1.71e-08; + Cp_liq = 0.0; + Psat_param[0] = 22.5898; + Psat_param[1] =3103.39 ; + Psat_param[2] = -0.16; + } + + // 11/12 : + else if (CAS=="7732-18-5") { + name = "water"; + M =18.02; + state = 0; + Tm = 273.15; + Tb = 373.15; + Tc = 647.4; + Pc = 217.6; + Ho = -241.83; + rho_liq = 998 ; + dHvap = 40.66; + mu_param[0] = 658.25; + mu_param[1] = 283.16; + Cp_param[0] = 32.220; + Cp_param[1] = 1.923e-03 ; + Cp_param[2] = 1.055e-05; + Cp_param[3] = -3.59e-09; + Cp_liq = 75.24; + Psat_param[0] = 18.3036; + Psat_param[1] = 3816.44; + Psat_param[2] = -46.13; + } + + // 12/12 : + else if (CAS=="64-17-5") { + name = "ethanol"; + M =46.07; + state =0 ; + Tm =159.1 ; + Tb = 351.5; + Tc = 516.2; + Pc =63.0 ; + Ho = -234.8; + rho_liq = 789.0; + dHvap =38.74 ; + mu_param[0] = 686.64; + mu_param[1] = 300.88; + Cp_param[0] = 9.008; + Cp_param[1] = 2.139e-01; + Cp_param[2] = -8.385e-05 ; + Cp_param[3] = 1.37e-09; + Cp_liq = 2.22; + Psat_param[0] = 18.9119; + Psat_param[1] = 3803.98; + Psat_param[2] = -41.68; + } + + else { + cout << "ERROR 1\n\n"; + exit(0); + } + + thermo = new thermolib(); + thermo->send(Pc,Tc, omega()); + + +} + +double chemical::K() +{ + thermo->set(P,T,v,n()); + return thermo->K(); +} + +double chemical::mu() +{ + // Returns the fluid's viscosity in Pa.s + if (Tm<=T && T<=Tboil(P)) + return pow(10,(mu_param[0]*(1.0/T-1.0/mu_param[1])-3)); + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot compute viscosity of "<<name<<".\n"; + logf.close(); + warning++; + check_error(); + return 1.0; + } +} + +double chemical::rho() +{ + // Returns the fluid's density in kg/m3, wether it's liquid or gas + if(state==0) tmp= rho_liq; + if(state==1) + { + find_v(); + if (v>EPS) tmp= m/v; + else tmp= 0.0; + } + return tmp; +} + +double chemical::Cp() { + // cout<<endl<<"Cp de "<<name<<" a "<<T; + // Returns the fluid's Cp in J/mol.K + if(state==0) { + + // tmp = Cp_liq; // BUG : boucle infinie !!! + return Cp_liq; // SEB + + } + if(state==1 || T>Tboil(P)) { + tmp=0; + for (int i=0;i<4;i++) + tmp+=Cp_param[i]*pow(T,i); + } + else { + T=Tb; + + tmp = Cp(); // ici boucle infinie si state==0 !!! + + } + return tmp; +} + +double chemical::Cp(bool q) +{ + // Returns the fluid's Cp in J/mol.K + if(q==0) tmp=Cp_liq; + if(q==1) + { + tmp=0; + for (int i=0;i<4;i++) tmp+=Cp_param[i]*pow(T,i); + } + return tmp; +} + +double chemical::Psat() +{ + // Returns the fluid's vapor pressure in atm, using Antoine's equation + if(Tm<=T && T<=Tc) + return (exp(Psat_param[0]-Psat_param[1]/(T+Psat_param[2]))/760.01); + else + { + + return Psat(Tb); + } +} +double chemical::Psat(double t) +{ + // Returns the fluid's vapor pressure in atm, using Antoine's equation + return (exp(Psat_param[0]-Psat_param[1]/(t+Psat_param[2]))/760.01); +} + +double chemical::dH(double T1,double T2, double pres) +{ + //Enthalpy variation in kJ/mol. Does not affect any attributes of current object. + double energy=0, TT=Tboil(pres), vap=Hvap(TT); + int sign=1, i; + if (T2<T1) {sign = -1; energy=T1; T1=T2; T2=energy; energy=0;} + if (T1==T2) energy = 0.0; + if (T2<TT) energy = Cp_liq*(T2-T1)/1000; + if (TT<T1) for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(T1,i))/i/1000; + if(T1<=TT && TT<=T2) + { + energy=Cp_liq*(TT-T1)/1000; + energy+=vap; + for (i=1;i<=4;i++) energy+=Cp_param[i-1]*(pow(T2,i)-pow(TT,i))/i/1000; + } + return energy*sign; +} + +void chemical::find_T() +{ + if(n()>EPS && P>EPS) + { + thermo->set(P,T,v,n()); + T=thermo->T(); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot find T of "<<name<<".\n"; + logf.close(); + warning++; + } + check_error(); +} + +void chemical::find_P() +{ + if(n()>EPS && T>EPS) + { + thermo->set(P,T,v,n()); + P=thermo->P(); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot find P of "<<name<<".\n"; + logf.close(); + warning++; + } + check_error(); +} + +void chemical::find_v() +{ + + if(state==0) v=m/rho_liq; + if(state==1 && P>EPS && T>EPS && m>EPS) + { + thermo->set(P,T,v,n()); + v=thermo->v(); + } +} + +void chemical::find_state() +{ + ofstream logf; + if (T>Tc || P>Pc) state = 1; //T or P is bigger than Tc or Pc + if (T<=Tm) //T is smaller than melting point + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- The chemical "<<name<<" is solid.\n"; + logf.close(); + warning++; + } + check_error(); + if (T<Tboil(P)) state=0; + else state=1; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.hpp index 71b28a956e9a81d399e78c777bb896601170e64c..344bd010651aa1f3e1229bc32e714752c22b628a 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/chemical.hpp @@ -1,48 +1,48 @@ -#ifndef CHEMICAL_H -#define CHEMICAL_H - -#include "thermolib.hpp" -#include <string> -using namespace std; - -class chemical -{ - public: - string name; - string CAS; - double M; //molar weight, in g/mol - bool state; //current state : 0=liquid 1=gas - double P, T, m, v; //current values : P in atm, T in K, m in kg/s, v in m3/s - - double n() {return 1000.0*m/M;} //mole flow in mol/s - double Hvap(double t) {return dHvap*pow((Tc-t)/(Tc-Tb),0.38);} //vaporization heat at specific T (Watson correlation) - double omega() {return ((-1.0)*log10(Psat(0.7*Tc)/Pc) -1.0);} //Pitzer acentric factor - double Tboil(double p) {return (Psat_param[1]/(Psat_param[0]-log(760.01*p))-Psat_param[2]);} //boiling tempararure at specific P - double mu(), rho(), Cp(), Cp(bool), Psat(), Psat(double); //T-dependant properties - double K(); //liquid-vapor equilibrium constant - double gamma(){return Cp(true)/(Cp(true)-8.3144);}//compressibility ratio =Cp/Cv - double dH(double, double, double); //enthalpy variation kJ/mol - void find_T(), find_P(), find_v(), find_state(); //for gases only - double Tm, Tb, Tc, Pc; //melting, boiling and critical temp. (K); critical pressure (atm) - double Ho;//standard formation heat in kJ/mol - - //private: - int warning, error; - void check_error(); - double dHvap, tmp; //vaporization heat (kJ/mol) - double mu_param[2], Cp_param[4], Cp_liq, Psat_param[3], rho_liq; //correlations parameters - thermolib *thermo; - - // public: - // chemical() {}; - - // copy-constr. : - chemical ( const chemical & chem ); - - chemical ( const string & chem_name ); //Contructor : initializes fields and reads CAS in the data file - void purge() {P=T=m=v=0.0; state=false;} - ~chemical(){delete thermo;}; -}; - -#endif - +#ifndef CHEMICAL_H +#define CHEMICAL_H + +#include "thermolib.hpp" +#include <string> +using namespace std; + +class chemical +{ + public: + string name; + string CAS; + double M; //molar weight, in g/mol + bool state; //current state : 0=liquid 1=gas + double P, T, m, v; //current values : P in atm, T in K, m in kg/s, v in m3/s + + double n() {return 1000.0*m/M;} //mole flow in mol/s + double Hvap(double t) {return dHvap*pow((Tc-t)/(Tc-Tb),0.38);} //vaporization heat at specific T (Watson correlation) + double omega() {return ((-1.0)*log10(Psat(0.7*Tc)/Pc) -1.0);} //Pitzer acentric factor + double Tboil(double p) {return (Psat_param[1]/(Psat_param[0]-log(760.01*p))-Psat_param[2]);} //boiling tempararure at specific P + double mu(), rho(), Cp(), Cp(bool), Psat(), Psat(double); //T-dependant properties + double K(); //liquid-vapor equilibrium constant + double gamma(){return Cp(true)/(Cp(true)-8.3144);}//compressibility ratio =Cp/Cv + double dH(double, double, double); //enthalpy variation kJ/mol + void find_T(), find_P(), find_v(), find_state(); //for gases only + double Tm, Tb, Tc, Pc; //melting, boiling and critical temp. (K); critical pressure (atm) + double Ho;//standard formation heat in kJ/mol + + //private: + int warning, error; + void check_error(); + double dHvap, tmp; //vaporization heat (kJ/mol) + double mu_param[2], Cp_param[4], Cp_liq, Psat_param[3], rho_liq; //correlations parameters + thermolib *thermo; + + // public: + // chemical() {}; + + // copy-constr. : + chemical ( const chemical & chem ); + + chemical ( const string & chem_name ); //Contructor : initializes fields and reads CAS in the data file + void purge() {P=T=m=v=0.0; state=false;} + ~chemical(){delete thermo;}; +}; + +#endif + diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/column.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/column.cpp index 85ab3e0b27bf8f9ab868d5792401fe63d4e0bbbd..f4a35c181e862b1a9b1eafdaf1190ff41abe19d8 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/column.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/column.cpp @@ -1,290 +1,290 @@ -#include "column.hpp" -using namespace std; - -column::column(stream* in, stream* out_B, stream* out_D) -{ - F = in; - B = out_B; - D = out_D; - L=new stream("columnL", F->nb, F->chem); - V=new stream("columnV", F->nb, F->chem); - flasher = new flash(F, L, V); - alpha_1 = new double[F->nb]; - alpha_f = new double[F->nb]; - alpha_N = new double[F->nb]; - alpha_m = new double[F->nb]; - T_d=0; T_b=0; T_f=F->T; -// for(i=0;i<F->nb;i++) -// if(F->chem[i]->Tc<F->T && F->chem[i]->m>EPS) -// { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Presence of gas in column.\n"; -// logf.close(); -// i=F->nb; -// } -} - -column::~column() -{ - delete L; delete V; delete flasher; - delete [] alpha_1; - delete [] alpha_f; - delete [] alpha_N; - delete [] alpha_m; -} - -void column::set(double p, int lk, double xd, int hk, double xb) -{ - P=p; - HK=hk-1; x_B=xb; - LK=lk-1; x_D=xd; - //logf.open(MESSAGES, ios::app); - // F->write(); system("pause"); - // if (F->chem[LK]->m<EPS) logf<<" ==> Error <== Flow of light key in column "<<name<<" is zero.\n"; -// if (F->chem[HK]->m<EPS) logf<<" ==> Error <== Flow of heavy key in column "<<name<<" is zero.\n"; - //logf.close(); -} - -bool column::solve() -{ - - OK=true; - // B->thermo=F->thermo; D->thermo=F->thermo; - //flash once the feed stream - - - - flasher->set(P,F->T); - - flasher->adiabatic(); - - - T_f=flasher->T; - L->set(P, T_f); V->set(P, T_f); - // L->write(); V->write(); TOTO - //check if a column is needed; if not, bypass block - if(F->chem[LK]->n()/F->n()<0.001) OK=false; - if(F->chem[HK]->n()/F->n()<0.001) OK=false; - if(!OK) - return false; -// { -// strcpy(filename, B->name); *B=*L; B->set(filename); B->write(); -// strcpy(filename, D->name); *D=*V; D->set(filename); D->write(); -// } - else - { - - - - - - //apply the FUG method - first_split(); - Nmin = Fenske(); - N=Nmin+1; - while (fabs(N-Nmin)>0.1) - { - N=Nmin; - D->set(P, T_f); T_d=D->bp; - B->set(P, T_f); T_b=B->bp; - set_alpha(); - distribute(); - Nmin = Fenske(); - if (Nmin<1) Nmin=1; - } - D->set(P, T_d); - B->set(P, T_b); - if(fabs(Nmin)<=MIN_PLATES || fabs(Nmin)>MAX_PLATES) OK=false; - else - { - Rmin = Underwood(); - if(Rmin>100) Rmin=100; - if(L->chem[HK]->m+L->chem[LK]->m<EPS) Rmin=10.0; - if (Nmin<5) Ract = 1.5*Rmin; - if (5<Nmin && Nmin<15) Ract = 1.3*Rmin; - if (15<=Nmin) Ract = 1.1*Rmin; - N = Gilliland(); - feed = Kirkbride(); - condense(); - reboil(); - } - // B->write(); TOTO - // D->write(); TOTO - } - return OK; -} - -void column::first_split() -{ - B->purge(); D->purge(); - set_alpha(); - //Check if LK is really lighter than HK - if (alpha_m[LK]<1) - { -// logf.open(MESSAGES,ios::app); -// logf<<" --> Warning <-- Swapping keys in column "<<name<<".\n"; -// logf.close(); - feed=LK; LK=HK; HK=feed; set_alpha(); - } - for(i=0;i<F->nb;i++) - { - if (i!=LK && i!=HK && F->chem[i]->m>EPS) - { - if(alpha_f[i] > alpha_f[LK]) //volatile - { - D->chem[i]->m = (alpha_f[i]-alpha_f[LK])/alpha_f[i]*F->chem[i]->m; - D->m += D->chem[i]->m; - B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; - B->m+=B->chem[i]->m; - } - if(alpha_f[i] < 1) //not volatile - { - B->chem[i]->m = (alpha_f[HK]-alpha_f[i])/alpha_f[i]*F->chem[i]->m; - B->m += B->chem[i]->m; - D->chem[i]->m = F->chem[i]->m-B->chem[i]->m; - D->m+=D->chem[i]->m; - } - if(1 <= alpha_f[i] && alpha_f[i]<=alpha_f[LK]) //ambiguous volatility - { - D->chem[i]->m = (alpha_f[i]-1)/(alpha_f[LK]-1)*F->chem[i]->m; - B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; - D->m+=D->chem[i]->m; - B->m+=B->chem[i]->m; - } - } - } - D->chem[HK]->m = D->n()*x_D/(1-x_D)*D->chem[HK]->M/1000.0; - if(D->chem[HK]->m<EPS) D->chem[HK]->m=0.01*F->chem[HK]->m; - B->chem[LK]->m = B->n()*x_B/(1-x_B)*B->chem[LK]->M/1000.0; - if(B->chem[LK]->m<EPS) B->chem[LK]->m=0.01*F->chem[LK]->m; - B->chem[HK]->m = F->chem[HK]->m - D->chem[HK]->m; - D->chem[LK]->m = F->chem[LK]->m - B->chem[LK]->m; - D->m += (D->chem[LK]->m + D->chem[HK]->m); - B->m += (B->chem[LK]->m + B->chem[HK]->m); -} -void column::distribute() -{ - D->m=0; B->m=0; - for(i=0;i<F->nb;i++) - { - if (i!=LK && i!=HK && F->chem[i]->m>EPS) - { - if(alpha_m[i] > 1) //volatile and ambiguous - { - B->chem[i]->m = F->chem[i]->m/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); - D->chem[i]->m = F->chem[i]->m - B->chem[i]->m; - } - if(alpha_m[i] <= 1) //not volatile - { - D->chem[i]->m = F->chem[i]->m*(D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin))/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); - B->chem[i]->m = F->chem[i]->m - D->chem[i]->m; - } - D->m+=D->chem[i]->m; - B->m+=B->chem[i]->m; - } - } - D->m += (D->chem[LK]->m + D->chem[HK]->m); - B->m += (B->chem[LK]->m + B->chem[HK]->m); -} - -void column::set_alpha() -{ - for(i=0;i<F->nb; i++) - { - if (T_b>EPS && F->chem[i]->m>EPS) alpha_1[i] = F->chem[i]->Psat(T_b)/F->chem[HK]->Psat(T_b); - else alpha_1[i]=0; - if (T_d>EPS&& F->chem[i]->m>EPS) alpha_N[i] = F->chem[i]->Psat(T_d)/F->chem[HK]->Psat(T_d); - else alpha_N[i]=0; - if (T_f>EPS&& F->chem[i]->m>EPS) alpha_f[i] = F->chem[i]->Psat(T_f)/F->chem[HK]->Psat(T_f); - else alpha_f[i]=0; - alpha_m[i] = pow(alpha_1[i]*alpha_f[i]*alpha_N[i], 1.0/3.0); - } - for(i=0;i<F->nb;i++) if(alpha_m[i]<EPS&& F->chem[i]->m>EPS) alpha_m[i] = alpha_f[i]; -} - -void column::reboil() -{ - Q_reboil = 0.0; - for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) - { - Q_reboil += B->chem[i]->Cp(false)*(T_b-T_f)*B->chem[i]->n()/1000.0; //energy to go from input to bottoms T - Q_reboil += D->chem[i]->Cp(false)*(T_f-T_d)*D->chem[i]->n()/1000.0; //energy to go from input to tops T - } - Q_reboil += Q_condens; -} - -void column::condense() -{ - Q_condens = 0.0; - for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) - { - Q_condens += D->chem[i]->Hvap(T_d)*(1+Ract)*D->chem[i]->n(); - } -} - -void column::write() -{ - cout << setprecision(11); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout <<"\t>> "<<name; - cout <<endl<<"\t>> stream in: "<<F->name; - cout <<endl<<"\t>> streams out: "<<B->name<<" (bot.) "<<D->name<<" (top.)"; - cout <<endl<<"\t>> P = "<<P<<" atm, T(0) = "<<T_b<<", T("<<feed<<") = "<<T_f<<", T("<<int(N)<<") = "<<T_d<<" K"; - cout <<endl<<"\t>> Number of stages: "<<int(N)<<" (feeding at stage "<<feed<<")"; - cout <<endl<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(5)<<"\t>> LK purity = "<<D->chem[LK]->n()/D->n()<<" HK purity = "<<B->chem[HK]->n()/B->n(); - cout <<endl<<"\t>> Reboiler duty: "<<Q_reboil<<" kW Condenser duty: "<<(-1)*Q_condens<<" kW"; - cout << "\n\tEND\n\n"; - cost(); water(); power(); -} - -double column::get_cost() -{ - //cost of vessel - vol=(0.45*N)*(pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); - if(vol<0.3) vol=0.3; if(vol>520)vol=520; - money = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); - money = pow(10, money); - P= (P-1)*101.325/100; - diam=sqrt(4.0*vol/pi/N/0.45); - vol=(P+1)*diam/(317.46*(850-0.6*(P+1)))+0.0315; - money *=(2.25+ 1.82*vol*2.2); - //cost of trays - vol = (pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); - diam = 2.9949+0.4465*log10(vol)+0.3961*pow(log10(vol),2); - money+=1.5*pow(10, diam); - //cost of reboiler U=5250W/m2.K - vol=fabs(Q_reboil)/0.85/5.25/15.0; - if(vol<10) vol=10; if(vol>100) vol=100; - vol = 4.4646-0.5277*log10(vol)+0.3955*pow(log10(vol),2); - money += (1.63+1.66*2.5)*pow(10, vol); - //cost of condenser U=1850W/m2.K - vol=fabs(Q_condens)/0.85/1.85/(0.5*(T_d-298)); - if(vol<1) vol=1; if(vol>100) vol=100; - vol = 3.9912+0.0668*log10(vol)+0.243*pow(log10(vol),2); - money += (1.74+1.55*2.5)*pow(10, vol); - money = money*MS_YEAR/MS_2001; - return money; -} - - -void column::cost() -{ - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} -void column::power() -{ - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - money =(Q_reboil/0.85-Q_condens); - cout << "\t>>" << money; - cout << "\n\tEND\n\n"; -} -void column::water() -{ - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - money = (fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298))); - cout << "\t>>" << money; - cout << "\n\tEND\n\n"; -} +#include "column.hpp" +using namespace std; + +column::column(stream* in, stream* out_B, stream* out_D) +{ + F = in; + B = out_B; + D = out_D; + L=new stream("columnL", F->nb, F->chem); + V=new stream("columnV", F->nb, F->chem); + flasher = new flash(F, L, V); + alpha_1 = new double[F->nb]; + alpha_f = new double[F->nb]; + alpha_N = new double[F->nb]; + alpha_m = new double[F->nb]; + T_d=0; T_b=0; T_f=F->T; +// for(i=0;i<F->nb;i++) +// if(F->chem[i]->Tc<F->T && F->chem[i]->m>EPS) +// { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Presence of gas in column.\n"; +// logf.close(); +// i=F->nb; +// } +} + +column::~column() +{ + delete L; delete V; delete flasher; + delete [] alpha_1; + delete [] alpha_f; + delete [] alpha_N; + delete [] alpha_m; +} + +void column::set(double p, int lk, double xd, int hk, double xb) +{ + P=p; + HK=hk-1; x_B=xb; + LK=lk-1; x_D=xd; + //logf.open(MESSAGES, ios::app); + // F->write(); system("pause"); + // if (F->chem[LK]->m<EPS) logf<<" ==> Error <== Flow of light key in column "<<name<<" is zero.\n"; +// if (F->chem[HK]->m<EPS) logf<<" ==> Error <== Flow of heavy key in column "<<name<<" is zero.\n"; + //logf.close(); +} + +bool column::solve() +{ + + OK=true; + // B->thermo=F->thermo; D->thermo=F->thermo; + //flash once the feed stream + + + + flasher->set(P,F->T); + + flasher->adiabatic(); + + + T_f=flasher->T; + L->set(P, T_f); V->set(P, T_f); + // L->write(); V->write(); TOTO + //check if a column is needed; if not, bypass block + if(F->chem[LK]->n()/F->n()<0.001) OK=false; + if(F->chem[HK]->n()/F->n()<0.001) OK=false; + if(!OK) + return false; +// { +// strcpy(filename, B->name); *B=*L; B->set(filename); B->write(); +// strcpy(filename, D->name); *D=*V; D->set(filename); D->write(); +// } + else + { + + + + + + //apply the FUG method + first_split(); + Nmin = Fenske(); + N=Nmin+1; + while (fabs(N-Nmin)>0.1) + { + N=Nmin; + D->set(P, T_f); T_d=D->bp; + B->set(P, T_f); T_b=B->bp; + set_alpha(); + distribute(); + Nmin = Fenske(); + if (Nmin<1) Nmin=1; + } + D->set(P, T_d); + B->set(P, T_b); + if(fabs(Nmin)<=MIN_PLATES || fabs(Nmin)>MAX_PLATES) OK=false; + else + { + Rmin = Underwood(); + if(Rmin>100) Rmin=100; + if(L->chem[HK]->m+L->chem[LK]->m<EPS) Rmin=10.0; + if (Nmin<5) Ract = 1.5*Rmin; + if (5<Nmin && Nmin<15) Ract = 1.3*Rmin; + if (15<=Nmin) Ract = 1.1*Rmin; + N = Gilliland(); + feed = Kirkbride(); + condense(); + reboil(); + } + // B->write(); TOTO + // D->write(); TOTO + } + return OK; +} + +void column::first_split() +{ + B->purge(); D->purge(); + set_alpha(); + //Check if LK is really lighter than HK + if (alpha_m[LK]<1) + { +// logf.open(MESSAGES,ios::app); +// logf<<" --> Warning <-- Swapping keys in column "<<name<<".\n"; +// logf.close(); + feed=LK; LK=HK; HK=feed; set_alpha(); + } + for(i=0;i<F->nb;i++) + { + if (i!=LK && i!=HK && F->chem[i]->m>EPS) + { + if(alpha_f[i] > alpha_f[LK]) //volatile + { + D->chem[i]->m = (alpha_f[i]-alpha_f[LK])/alpha_f[i]*F->chem[i]->m; + D->m += D->chem[i]->m; + B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; + B->m+=B->chem[i]->m; + } + if(alpha_f[i] < 1) //not volatile + { + B->chem[i]->m = (alpha_f[HK]-alpha_f[i])/alpha_f[i]*F->chem[i]->m; + B->m += B->chem[i]->m; + D->chem[i]->m = F->chem[i]->m-B->chem[i]->m; + D->m+=D->chem[i]->m; + } + if(1 <= alpha_f[i] && alpha_f[i]<=alpha_f[LK]) //ambiguous volatility + { + D->chem[i]->m = (alpha_f[i]-1)/(alpha_f[LK]-1)*F->chem[i]->m; + B->chem[i]->m = F->chem[i]->m-D->chem[i]->m; + D->m+=D->chem[i]->m; + B->m+=B->chem[i]->m; + } + } + } + D->chem[HK]->m = D->n()*x_D/(1-x_D)*D->chem[HK]->M/1000.0; + if(D->chem[HK]->m<EPS) D->chem[HK]->m=0.01*F->chem[HK]->m; + B->chem[LK]->m = B->n()*x_B/(1-x_B)*B->chem[LK]->M/1000.0; + if(B->chem[LK]->m<EPS) B->chem[LK]->m=0.01*F->chem[LK]->m; + B->chem[HK]->m = F->chem[HK]->m - D->chem[HK]->m; + D->chem[LK]->m = F->chem[LK]->m - B->chem[LK]->m; + D->m += (D->chem[LK]->m + D->chem[HK]->m); + B->m += (B->chem[LK]->m + B->chem[HK]->m); +} +void column::distribute() +{ + D->m=0; B->m=0; + for(i=0;i<F->nb;i++) + { + if (i!=LK && i!=HK && F->chem[i]->m>EPS) + { + if(alpha_m[i] > 1) //volatile and ambiguous + { + B->chem[i]->m = F->chem[i]->m/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); + D->chem[i]->m = F->chem[i]->m - B->chem[i]->m; + } + if(alpha_m[i] <= 1) //not volatile + { + D->chem[i]->m = F->chem[i]->m*(D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin))/(1+D->chem[HK]->n()/B->chem[HK]->n()*pow(alpha_m[i], Nmin)); + B->chem[i]->m = F->chem[i]->m - D->chem[i]->m; + } + D->m+=D->chem[i]->m; + B->m+=B->chem[i]->m; + } + } + D->m += (D->chem[LK]->m + D->chem[HK]->m); + B->m += (B->chem[LK]->m + B->chem[HK]->m); +} + +void column::set_alpha() +{ + for(i=0;i<F->nb; i++) + { + if (T_b>EPS && F->chem[i]->m>EPS) alpha_1[i] = F->chem[i]->Psat(T_b)/F->chem[HK]->Psat(T_b); + else alpha_1[i]=0; + if (T_d>EPS&& F->chem[i]->m>EPS) alpha_N[i] = F->chem[i]->Psat(T_d)/F->chem[HK]->Psat(T_d); + else alpha_N[i]=0; + if (T_f>EPS&& F->chem[i]->m>EPS) alpha_f[i] = F->chem[i]->Psat(T_f)/F->chem[HK]->Psat(T_f); + else alpha_f[i]=0; + alpha_m[i] = pow(alpha_1[i]*alpha_f[i]*alpha_N[i], 1.0/3.0); + } + for(i=0;i<F->nb;i++) if(alpha_m[i]<EPS&& F->chem[i]->m>EPS) alpha_m[i] = alpha_f[i]; +} + +void column::reboil() +{ + Q_reboil = 0.0; + for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) + { + Q_reboil += B->chem[i]->Cp(false)*(T_b-T_f)*B->chem[i]->n()/1000.0; //energy to go from input to bottoms T + Q_reboil += D->chem[i]->Cp(false)*(T_f-T_d)*D->chem[i]->n()/1000.0; //energy to go from input to tops T + } + Q_reboil += Q_condens; +} + +void column::condense() +{ + Q_condens = 0.0; + for (i=0;i<F->nb;i++) if(F->chem[i]->m>EPS) + { + Q_condens += D->chem[i]->Hvap(T_d)*(1+Ract)*D->chem[i]->n(); + } +} + +void column::write() +{ + cout << setprecision(11); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout <<"\t>> "<<name; + cout <<endl<<"\t>> stream in: "<<F->name; + cout <<endl<<"\t>> streams out: "<<B->name<<" (bot.) "<<D->name<<" (top.)"; + cout <<endl<<"\t>> P = "<<P<<" atm, T(0) = "<<T_b<<", T("<<feed<<") = "<<T_f<<", T("<<int(N)<<") = "<<T_d<<" K"; + cout <<endl<<"\t>> Number of stages: "<<int(N)<<" (feeding at stage "<<feed<<")"; + cout <<endl<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(5)<<"\t>> LK purity = "<<D->chem[LK]->n()/D->n()<<" HK purity = "<<B->chem[HK]->n()/B->n(); + cout <<endl<<"\t>> Reboiler duty: "<<Q_reboil<<" kW Condenser duty: "<<(-1)*Q_condens<<" kW"; + cout << "\n\tEND\n\n"; + cost(); water(); power(); +} + +double column::get_cost() +{ + //cost of vessel + vol=(0.45*N)*(pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); + if(vol<0.3) vol=0.3; if(vol>520)vol=520; + money = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); + money = pow(10, money); + P= (P-1)*101.325/100; + diam=sqrt(4.0*vol/pi/N/0.45); + vol=(P+1)*diam/(317.46*(850-0.6*(P+1)))+0.0315; + money *=(2.25+ 1.82*vol*2.2); + //cost of trays + vol = (pow(300*D->v, 1.5)/2.4/sqrt(B->v))*sqrt(D->m/B->m); + diam = 2.9949+0.4465*log10(vol)+0.3961*pow(log10(vol),2); + money+=1.5*pow(10, diam); + //cost of reboiler U=5250W/m2.K + vol=fabs(Q_reboil)/0.85/5.25/15.0; + if(vol<10) vol=10; if(vol>100) vol=100; + vol = 4.4646-0.5277*log10(vol)+0.3955*pow(log10(vol),2); + money += (1.63+1.66*2.5)*pow(10, vol); + //cost of condenser U=1850W/m2.K + vol=fabs(Q_condens)/0.85/1.85/(0.5*(T_d-298)); + if(vol<1) vol=1; if(vol>100) vol=100; + vol = 3.9912+0.0668*log10(vol)+0.243*pow(log10(vol),2); + money += (1.74+1.55*2.5)*pow(10, vol); + money = money*MS_YEAR/MS_2001; + return money; +} + + +void column::cost() +{ + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} +void column::power() +{ + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + money =(Q_reboil/0.85-Q_condens); + cout << "\t>>" << money; + cout << "\n\tEND\n\n"; +} +void column::water() +{ + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + money = (fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298))); + cout << "\t>>" << money; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/column.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/column.hpp index cfd1daf16270b9ae30ba6500da2b75d7a576eb41..8dedb5a82bd85f4c6cf6b5d6a0dde55c8d56f299 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/column.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/column.hpp @@ -1,61 +1,61 @@ -/* -This unit simulates a distillation column, using -the FUG method. -(ref : Seader & Henley). - -Structure in the .process file: -column {name} {pressure} {index of input stream} {index of bottoms and heads} {indexes of light key and heavy key} {x_LK and x_HK} - -How to use: - 1- Call the constructor : col = new column(in, out_B, out_D); //in is F, out_B is B, out_D is D column(nb, chem_list) - set(in, out_B, out_D) - 2- Set operating conditions : col->set(pressure, LK, x_LK, HK, x_HK); // LK and HK and integer indexes, x_LK is the undesired mole fraction of LK in B, x_HK... - 3- Set the name : col->set(name); - 4- Run the model: col->solve(); -*/ -#ifndef COLUMN_H -#define COLUMN_H - -#include "flash.hpp" -using namespace std; - -class column -{ -private: - // ofstream results, logf; - bool OK; - string name; - stream *F, *B, *D, *L, *V ; - int LK, HK, feed, i; - double x_B, x_D, T_b, T_d, T_f, vol, money, diam; - double Nmin, N, Rmin, Ract, tmp, Q_condens, Q_reboil; - double *alpha_1, *alpha_f, *alpha_N, *alpha_m; - flash *flasher; - void set_alpha(), first_split(), distribute(), condense(), reboil(); - double Fenske() { return log10(D->chem[LK]->n()*B->chem[HK]->n()/D->chem[HK]->n()/B->chem[LK]->n())/log10(alpha_m[LK]);} - double Underwood() {return L->n()*(D->chem[LK]->n()/L->chem[LK]->n()-alpha_m[LK]*D->chem[HK]->n()/L->chem[HK]->n())/(D->n()*(alpha_m[LK]-1));} - double Gilliland(){N=(Ract-Rmin)/(Ract+1); tmp=1-exp((1+54.4*N)*(N-1)/(11+117.2*N)/pow(N, 0.5)); return (tmp+Nmin)/(1-tmp);} - int Kirkbride() {tmp=pow(B->n()*F->chem[HK]->n()*pow(x_B/x_D,2)/F->chem[LK]->n()/D->n(), 0.206); return int(N/(tmp+1));} - -public: - // column(){P=0.0;} - // column(int, chemical*); - // void set(stream*&, stream*&, stream*&); - column(stream*, stream*, stream*); - ~column(); - double P; - void set(double, int, double, int, double); - void set( const string & n ) { name = n; } - bool solve(); - void write(); - void cost(), water(), power(); - - double get_cost ( void ); - double get_power ( void ) const { return Q_reboil/0.85-Q_condens; } - - double get_water ( void ) const { return fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298)); } - - int get_N ( void ) const { return (int) N; } - -}; -#endif +/* +This unit simulates a distillation column, using +the FUG method. +(ref : Seader & Henley). + +Structure in the .process file: +column {name} {pressure} {index of input stream} {index of bottoms and heads} {indexes of light key and heavy key} {x_LK and x_HK} + +How to use: + 1- Call the constructor : col = new column(in, out_B, out_D); //in is F, out_B is B, out_D is D column(nb, chem_list) + set(in, out_B, out_D) + 2- Set operating conditions : col->set(pressure, LK, x_LK, HK, x_HK); // LK and HK and integer indexes, x_LK is the undesired mole fraction of LK in B, x_HK... + 3- Set the name : col->set(name); + 4- Run the model: col->solve(); +*/ +#ifndef COLUMN_H +#define COLUMN_H + +#include "flash.hpp" +using namespace std; + +class column +{ +private: + // ofstream results, logf; + bool OK; + string name; + stream *F, *B, *D, *L, *V ; + int LK, HK, feed, i; + double x_B, x_D, T_b, T_d, T_f, vol, money, diam; + double Nmin, N, Rmin, Ract, tmp, Q_condens, Q_reboil; + double *alpha_1, *alpha_f, *alpha_N, *alpha_m; + flash *flasher; + void set_alpha(), first_split(), distribute(), condense(), reboil(); + double Fenske() { return log10(D->chem[LK]->n()*B->chem[HK]->n()/D->chem[HK]->n()/B->chem[LK]->n())/log10(alpha_m[LK]);} + double Underwood() {return L->n()*(D->chem[LK]->n()/L->chem[LK]->n()-alpha_m[LK]*D->chem[HK]->n()/L->chem[HK]->n())/(D->n()*(alpha_m[LK]-1));} + double Gilliland(){N=(Ract-Rmin)/(Ract+1); tmp=1-exp((1+54.4*N)*(N-1)/(11+117.2*N)/pow(N, 0.5)); return (tmp+Nmin)/(1-tmp);} + int Kirkbride() {tmp=pow(B->n()*F->chem[HK]->n()*pow(x_B/x_D,2)/F->chem[LK]->n()/D->n(), 0.206); return int(N/(tmp+1));} + +public: + // column(){P=0.0;} + // column(int, chemical*); + // void set(stream*&, stream*&, stream*&); + column(stream*, stream*, stream*); + ~column(); + double P; + void set(double, int, double, int, double); + void set( const string & n ) { name = n; } + bool solve(); + void write(); + void cost(), water(), power(); + + double get_cost ( void ); + double get_power ( void ) const { return Q_reboil/0.85-Q_condens; } + + double get_water ( void ) const { return fabs(Q_condens)/(4.185*0.85*0.25*fabs(T_d-298)); } + + int get_N ( void ) const { return (int) N; } + +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.cpp index 83ad673825887cc0696981505fa884bb9c1a9c5d..0f30f1af32b99e3b5521dede45a6bde5aa7cbe57 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.cpp @@ -1,66 +1,66 @@ -#include "combrx.hpp" -using namespace std; - -combrx::combrx ( const string & cas ) { - - // combustion.prop : - // ----------------- - CAS = cas; - - if (CAS=="64-17-5") { - nO2 = 3; - nCO2 = 2; - nH2O = 3; - } - else if (CAS=="74-82-8") { - nO2 = 2; - nCO2 = 1; - nH2O = 2; - } - else if (CAS=="1333-74-0") { - nO2 = 0.5; - nCO2 = 0; - nH2O = 1; - } - else if (CAS=="100-42-5") { - nO2 = 10; - nCO2 = 8; - nH2O = 4; - } - else if (CAS=="74-85-1") { - nO2 = 3; - nCO2 = 2; - nH2O = 2; - } - else if (CAS=="108-88-3") { - nO2 = 9; - nCO2 = 7; - nH2O = 4; - } - else if (CAS=="100-41-4") { - nO2 = 10.5; - nCO2 = 8; - nH2O = 5; - } - else if (CAS=="71-43-2") { - nO2 = 7.5; - nCO2 = 6; - nH2O = 3; - } - else { - cout << "ERROR 21" << endl; - exit(0); - } - - COMB = new chemical(CAS); - O2 = new chemical("7782-44-7"); - N2 = new chemical("7727-37-9"); - CO2 = new chemical("124-38-9"); - H2O = new chemical("7732-18-5"); - Hro = CO2->Ho*nCO2 + nH2O*(H2O->Ho - H2O->dHvap) - COMB->Ho; - LFLo = -3420.0/Hro + 0.569e-3*Hro + 0.0538e-6*pow(Hro,2) + 1.8; - LFLo = LFLo/100.0; - UFLo = 0.0063*Hro + 0.567e-6*pow(Hro, 2) + 23.5; - UFLo = UFLo/100.0; - -} +#include "combrx.hpp" +using namespace std; + +combrx::combrx ( const string & cas ) { + + // combustion.prop : + // ----------------- + CAS = cas; + + if (CAS=="64-17-5") { + nO2 = 3; + nCO2 = 2; + nH2O = 3; + } + else if (CAS=="74-82-8") { + nO2 = 2; + nCO2 = 1; + nH2O = 2; + } + else if (CAS=="1333-74-0") { + nO2 = 0.5; + nCO2 = 0; + nH2O = 1; + } + else if (CAS=="100-42-5") { + nO2 = 10; + nCO2 = 8; + nH2O = 4; + } + else if (CAS=="74-85-1") { + nO2 = 3; + nCO2 = 2; + nH2O = 2; + } + else if (CAS=="108-88-3") { + nO2 = 9; + nCO2 = 7; + nH2O = 4; + } + else if (CAS=="100-41-4") { + nO2 = 10.5; + nCO2 = 8; + nH2O = 5; + } + else if (CAS=="71-43-2") { + nO2 = 7.5; + nCO2 = 6; + nH2O = 3; + } + else { + cout << "ERROR 21" << endl; + exit(0); + } + + COMB = new chemical(CAS); + O2 = new chemical("7782-44-7"); + N2 = new chemical("7727-37-9"); + CO2 = new chemical("124-38-9"); + H2O = new chemical("7732-18-5"); + Hro = CO2->Ho*nCO2 + nH2O*(H2O->Ho - H2O->dHvap) - COMB->Ho; + LFLo = -3420.0/Hro + 0.569e-3*Hro + 0.0538e-6*pow(Hro,2) + 1.8; + LFLo = LFLo/100.0; + UFLo = 0.0063*Hro + 0.567e-6*pow(Hro, 2) + 23.5; + UFLo = UFLo/100.0; + +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.hpp index b57e643762d2dbcc59dfdf040e503d580416b4ca..02e098bb96d4fbd6ece10fb1ef45e50803768425 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/combrx.hpp @@ -1,29 +1,29 @@ -#ifndef COMBRX_H -#define COMBRX_H -#include "chemical.hpp" -#include "defines.hpp" -using namespace std; - -class combrx { - -private : - ifstream data; - bool stop; - double nO2, nCO2, nH2O; - char tmp[41]; - string CAS; - chemical *H2O, *N2, *O2, *CO2, *COMB; - double LFLo, UFLo, Hro, sum; - -public: - combrx( const string & cas ); - double O2_flow() { return (O2->M*nO2/1000.0); } //theoritical O2 flow, in kg/mol of COMB - double N2_flow(){return (0.79*O2_flow()/0.21);} //theoritical N2 flow, in kg/mol of COMB - double CO2_flow() {return (nCO2*CO2->M/1000.0);} //theoritical CO2 flow, in kg/mol of COMB - double H2O_flow() {return (nH2O*H2O->M/1000.0);} //theoritical H2O flow, in kg/mol of COMB - double LFL(double P, double T) {sum=LFLo + 0.03139/Hro*(T-298); if(sum<EPS) return EPS; else return sum;} //in %vol - double UFL(double P, double T) {sum=UFLo - 0.03139/Hro*(T-298) + 0.206*(log10(0.101325*P)+1); if(sum>1) return (1-EPS); else return sum;} //in %vol - double Hcomb(double T) {return (nCO2*CO2->dH(298,T,1)+ nH2O*H2O->dH(298,T,1)-nO2*O2->dH(298,T,1)-COMB->dH(298,T,1)+Hro);} //in kJ/mol - ~combrx(){delete H2O; delete N2; delete O2; delete CO2; delete COMB;} -}; -#endif +#ifndef COMBRX_H +#define COMBRX_H +#include "chemical.hpp" +#include "defines.hpp" +using namespace std; + +class combrx { + +private : + ifstream data; + bool stop; + double nO2, nCO2, nH2O; + char tmp[41]; + string CAS; + chemical *H2O, *N2, *O2, *CO2, *COMB; + double LFLo, UFLo, Hro, sum; + +public: + combrx( const string & cas ); + double O2_flow() { return (O2->M*nO2/1000.0); } //theoritical O2 flow, in kg/mol of COMB + double N2_flow(){return (0.79*O2_flow()/0.21);} //theoritical N2 flow, in kg/mol of COMB + double CO2_flow() {return (nCO2*CO2->M/1000.0);} //theoritical CO2 flow, in kg/mol of COMB + double H2O_flow() {return (nH2O*H2O->M/1000.0);} //theoritical H2O flow, in kg/mol of COMB + double LFL(double P, double T) {sum=LFLo + 0.03139/Hro*(T-298); if(sum<EPS) return EPS; else return sum;} //in %vol + double UFL(double P, double T) {sum=UFLo - 0.03139/Hro*(T-298) + 0.206*(log10(0.101325*P)+1); if(sum>1) return (1-EPS); else return sum;} //in %vol + double Hcomb(double T) {return (nCO2*CO2->dH(298,T,1)+ nH2O*H2O->dH(298,T,1)-nO2*O2->dH(298,T,1)-COMB->dH(298,T,1)+Hro);} //in kJ/mol + ~combrx(){delete H2O; delete N2; delete O2; delete CO2; delete COMB;} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/defines.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/defines.hpp index 76a08babf8c7f46e0e043d78f0ae084fb8a5a617..5f6ad7e229d36d09449792bc7b4e73ab82251154 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/defines.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/defines.hpp @@ -1,89 +1,89 @@ -/***************************************************************************/ -/* CONFIGURATION OF THE OPERATING SYSTEM */ -/* */ -/* If Windows platform, put a "0" */ -/* If Linux, Unix or Mac platform, put a "1" */ -/* */ -#define PLATFORM 1 /* */ -/***************************************************************************/ - -#include <iostream> -#include <fstream> -#include <cmath> - -// #include <iomanip> -// #include <cstring> -// #include <cctype> -#include <cstdlib> -// #include <ctime> -using namespace std; - - -double arrondi ( double x , int n ); - - -#define ARRONDI 1 // arrondir ou pas - -#define DEBUG 0 //choose the debug (1) or normal (0) mode -#define MUTE 0 //choose 1 to avoid all screen output, 0 to have the normal display -#define EPS 1e-10 //the software "0" - -// Platform-dependant declarations -#define WIN 0 /* all versions */ -#define OTHER 1 /* Unix, Linux, SunOS, MacIntosh */ -#define MESSAGES "runtime/messages.r" -#define RUNTIME "runtime/" -#define DATA "data/" - -//useful constants -#define R 0.0821 //ideal gas constant in atm.l/mol.K -#define MAX_TEMP 3000.0 //Maximal temperature in the process -#define pi 3.14159265358979323846 //the pi number -#define MAX_DIM 30 -#define MAX_STREAM 30 -#define MAX_UNIT 30 - -//For the chemical class -#define MAX_ERROR 0 -#define MAX_WARNING 10 - -//For the secant solver -#define TOL_SECANT 1e-8 -#define MAX_ITER_SECANT 250 - -//For the bissection solver -#define TOL_BISSECTION 1e-8 -#define MAX_ITER_BISSECTION 250 - -//For the Newton solver -#define TOL_NEWTON 1e-6 -#define MAX_ITER_NEWTON 250 -#define STEP_NEWTON 1e-3 - -//For the Runge-Kutta solver -#define N_INTER 250 -#define MAX_ITER_RK N_INTER+1 - -//For the Wegstein solver -#define MIN_THETA -3.0 -#define MAX_THETA 1.0 -#define TOL_WEGSTEIN 1e-3 -#define MAX_ITER_WEGSTEIN 50 - -//For the stream flashing -#define TOL_BP 1e-3 -#define TOL_DP 1e-3 - -//For the burner -#define TOL_BURN 1e-4 - -//For the column -#define MAX_PLATES 500 -#define MIN_PLATES 1 - -//For the flash -#define TOL_FLASH 1e-2 - -//For the cost estimtiors -#define MS_2001 1094.0 -#define MS_YEAR 1139.0 +/***************************************************************************/ +/* CONFIGURATION OF THE OPERATING SYSTEM */ +/* */ +/* If Windows platform, put a "0" */ +/* If Linux, Unix or Mac platform, put a "1" */ +/* */ +#define PLATFORM 1 /* */ +/***************************************************************************/ + +#include <iostream> +#include <fstream> +#include <cmath> + +// #include <iomanip> +// #include <cstring> +// #include <cctype> +#include <cstdlib> +// #include <ctime> +using namespace std; + + +double arrondi ( double x , int n ); + + +#define ARRONDI 1 // arrondir ou pas + +#define DEBUG 0 //choose the debug (1) or normal (0) mode +#define MUTE 0 //choose 1 to avoid all screen output, 0 to have the normal display +#define EPS 1e-10 //the software "0" + +// Platform-dependant declarations +#define WIN 0 /* all versions */ +#define OTHER 1 /* Unix, Linux, SunOS, MacIntosh */ +#define MESSAGES "runtime/messages.r" +#define RUNTIME "runtime/" +#define DATA "data/" + +//useful constants +#define R 0.0821 //ideal gas constant in atm.l/mol.K +#define MAX_TEMP 3000.0 //Maximal temperature in the process +#define pi 3.14159265358979323846 //the pi number +#define MAX_DIM 30 +#define MAX_STREAM 30 +#define MAX_UNIT 30 + +//For the chemical class +#define MAX_ERROR 0 +#define MAX_WARNING 10 + +//For the secant solver +#define TOL_SECANT 1e-8 +#define MAX_ITER_SECANT 250 + +//For the bissection solver +#define TOL_BISSECTION 1e-8 +#define MAX_ITER_BISSECTION 250 + +//For the Newton solver +#define TOL_NEWTON 1e-6 +#define MAX_ITER_NEWTON 250 +#define STEP_NEWTON 1e-3 + +//For the Runge-Kutta solver +#define N_INTER 250 +#define MAX_ITER_RK N_INTER+1 + +//For the Wegstein solver +#define MIN_THETA -3.0 +#define MAX_THETA 1.0 +#define TOL_WEGSTEIN 1e-3 +#define MAX_ITER_WEGSTEIN 50 + +//For the stream flashing +#define TOL_BP 1e-3 +#define TOL_DP 1e-3 + +//For the burner +#define TOL_BURN 1e-4 + +//For the column +#define MAX_PLATES 500 +#define MIN_PLATES 1 + +//For the flash +#define TOL_FLASH 1e-2 + +//For the cost estimtiors +#define MS_2001 1094.0 +#define MS_YEAR 1139.0 diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.cpp index 930ea8f58ac00b78b1aea1b6933d286eafb9bae0..027ad0e7dd937f8f0eb8a52d9401d2d00d78f2c2 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.cpp @@ -1,220 +1,220 @@ -#include "flash.hpp" -#include "bissection.cpp" -using namespace std; - -flash::flash ( stream * in , stream * out_L , stream * out_V ) { - F = in; - Fcopy = new stream("Fcopy", F->nb, F->chem); - Tin = F->T; - z = new double[F->nb]; - for ( i = 0 ; i < F->nb ; i++ ) - z[i] = F->chem[i]->n()/F->n(); - - L = out_L; - V = out_V; - success = true; - K = new double[F->nb]; - task=0; - solver = new bissection<flash>(); -} - -void flash::set(double p, double t) -{ - P=p; - T=t; - for (i=0;i<F->nb;i++) - { - if(F->chem[i]->Tc<T) K[i] = F->chem[i]->Psat(T)/P; - else K[i]=1; - } - F->set(P,T); -} - -bool flash::solve() -{ - L->purge(); - V->purge(); - f_x=F->quality(); - - if( 0.0 < f_x && f_x < 1.0) - { - - // TOTO - for ( i = 0 ; i < F->nb ; i++ ) { - if ( F->chem[i]->Tc < T ) { - F->m -= F->chem[i]->m; - F->chem[i]->m = 0; - } - } - - for ( i = 0 ; i < F->nb ; i++ ) - z[i] = F->chem[i]->n()/F->n(); - - solver->set(this, 0.0, 1.0); - - success=solver->run(); - - if (!success) - { -// if(task==0){ -// log.open(MESSAGES, ios::app); -// log<<" --> Warning <-- Solver of FLASH "<<name<<" did not converge.\n"; -// log.close();} - for (i=0;i<F->nb;i++) - { - if (T<F->chem[i]->Tc && T>F->chem[i]->Tboil(P)) {V->chem[i]->m=F->chem[i]->m; V->m+=V->chem[i]->m;} - if (T<F->chem[i]->Tc && T<=F->chem[i]->Tboil(P)) {L->chem[i]->m=F->chem[i]->m; L->m+=L->chem[i]->m;} - } - } - else - { - - V->m = x*F->n(); - L->m = F->n() - V->m; - //Distribute liquid components - for (i=0;i<L->nb;i++) - { - L->chem[i]->m = (L->m*z[i])/(1+x*(K[i]-1))*L->chem[i]->M/1000.0; - L->chem[i]->state=0; - } - - - L->m=0.0; for(i=0;i<L->nb;i++) L->m+=L->chem[i]->m; - //Distribute vapor components - for (i=0;i<V->nb;i++) - { - V->chem[i]->m = V->m*L->chem[i]->n()*K[i]/L->n()*V->chem[i]->M/1000.0; - V->chem[i]->state=1; - } - V->m=0.0; for(i=0;i<V->nb;i++) V->m+=V->chem[i]->m; - } - for(i=0;i<F->nb;i++) - if(F->chem[i]->Tc<T){V->chem[i]->m=Fcopy->chem[i]->m; V->m+=Fcopy->chem[i]->m;} - - } - else - { - /* if(task==0) - { - log.open("runtime\\messages.r", ios::app); - if (T<F->dp) log<<" --> Warning <-- Mixture in "<<name<<" can't be flashed (bp="<<F->bp<<" dp="<<F->dp<<").\n"; - log.close(); - } */ - for (i=0;i<F->nb;i++) - { - if (F->chem[i]->Tc<T || f_x>=1) {V->chem[i]->m=Fcopy->chem[i]->m; V->m+=V->chem[i]->m; } - else {L->chem[i]->m=Fcopy->chem[i]->m; L->m+=L->chem[i]->m;} - - } - success = true; - } - L->set(P,T); - V->set(P,T); - Q = 0.0; - for (i=0;i<F->nb;i++) - { - Q += L->chem[i]->dH(Tin, T, P)*L->chem[i]->n(); - Q += V->chem[i]->dH(Tin, T, P)*V->chem[i]->n(); - } - F->m=0; - for(i=0;i<Fcopy->nb;i++) {F->chem[i]->m = Fcopy->chem[i]->m; F->m+=F->chem[i]->m;} - F->set(F->P,Tin); -// if(fabs(V->m+L->m-F->m)>sqrt(EPS)) -// { -// log.open(MESSAGES, ios::app); -// log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(V->m+L->m-F->m)/F->m<<").\n"; -// log.close(); -// } -// V->write();// TOTO - // L->write(); // TOTO - - return success; -} - -double flash::f(double psy) -{ - x=psy; - f_x=0.0; - for(i=0;i<F->nb;i++) f_x += (z[i]*(1-K[i]))/(1+psy*(K[i]-1)); - return f_x; -} - -bool flash::adiabatic() -{ - task=1; - F->set(P,T); T=F->dp; - step=-5; - Q=1; - - - while (fabs(step)>0.01 && fabs(Q)>0.1) - { - T+=step; - F->set(P,T); - - for (i=0;i<F->nb;i++) - K[i] = F->chem[i]->Psat(T)/P; - - success=solve(); - - - if (Q<0 && step<0) step*=-0.5; - if (Q>0 && step>0) step*=-0.5; - } - if (fabs(Q)<0.1) return true; - else return false; -} - -void flash::write() { - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> "<<name; - cout << endl << "\t>> stream in : "<<F->name; - cout <<endl<<"\t>> streams out : "<<L->name<<" (liq.) "<<V->name<<" (vap.)"; - cout <<endl<<"\t>> P = "<<P<<" atm, T = "<<T<<" K"; - cout <<endl<<"\t>> Heat duty = "<<Q; - if (success==true) cout <<" kW (converge normally)"; - cout << "\n\tEND\n\n"; - cost(); - power(); - water(); -} - - -double flash::get_cost ( void ) { - vol=15.0*(L->v+V->v); - if(vol<0.3) vol=0.3; if(vol>520)vol=520; - step = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); - step = pow(10, step); - P= (P-1)*101.325/100; - f_x=pow(2.0*vol/pi, 1.0/3.0); - vol=(P+1)*f_x/(317.46*(850-0.6*(P+1)))+0.0315; - step *=(2.25+ 1.82*vol*2.2); - step = step*MS_YEAR/MS_2001; - return step; -} - -void flash::cost() { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} -void flash::power() { - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - cout << "\t>>" << Q; - cout << "\n\tEND\n\n"; -} - -double flash::get_water ( void ) { - step = (Q<0.0) ? fabs(Q)/(4.185*0.10*(Tin-298)) : 0.0; - return step; -} - -void flash::water() { - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - if(Q<0.0) - step= (fabs(Q)/(4.185*0.10*(Tin-298))); - else - step= 0.0; - cout << "\t>>" << step; - cout << "\n\tEND\n\n"; -} +#include "flash.hpp" +#include "bissection.cpp" +using namespace std; + +flash::flash ( stream * in , stream * out_L , stream * out_V ) { + F = in; + Fcopy = new stream("Fcopy", F->nb, F->chem); + Tin = F->T; + z = new double[F->nb]; + for ( i = 0 ; i < F->nb ; i++ ) + z[i] = F->chem[i]->n()/F->n(); + + L = out_L; + V = out_V; + success = true; + K = new double[F->nb]; + task=0; + solver = new bissection<flash>(); +} + +void flash::set(double p, double t) +{ + P=p; + T=t; + for (i=0;i<F->nb;i++) + { + if(F->chem[i]->Tc<T) K[i] = F->chem[i]->Psat(T)/P; + else K[i]=1; + } + F->set(P,T); +} + +bool flash::solve() +{ + L->purge(); + V->purge(); + f_x=F->quality(); + + if( 0.0 < f_x && f_x < 1.0) + { + + // TOTO + for ( i = 0 ; i < F->nb ; i++ ) { + if ( F->chem[i]->Tc < T ) { + F->m -= F->chem[i]->m; + F->chem[i]->m = 0; + } + } + + for ( i = 0 ; i < F->nb ; i++ ) + z[i] = F->chem[i]->n()/F->n(); + + solver->set(this, 0.0, 1.0); + + success=solver->run(); + + if (!success) + { +// if(task==0){ +// log.open(MESSAGES, ios::app); +// log<<" --> Warning <-- Solver of FLASH "<<name<<" did not converge.\n"; +// log.close();} + for (i=0;i<F->nb;i++) + { + if (T<F->chem[i]->Tc && T>F->chem[i]->Tboil(P)) {V->chem[i]->m=F->chem[i]->m; V->m+=V->chem[i]->m;} + if (T<F->chem[i]->Tc && T<=F->chem[i]->Tboil(P)) {L->chem[i]->m=F->chem[i]->m; L->m+=L->chem[i]->m;} + } + } + else + { + + V->m = x*F->n(); + L->m = F->n() - V->m; + //Distribute liquid components + for (i=0;i<L->nb;i++) + { + L->chem[i]->m = (L->m*z[i])/(1+x*(K[i]-1))*L->chem[i]->M/1000.0; + L->chem[i]->state=0; + } + + + L->m=0.0; for(i=0;i<L->nb;i++) L->m+=L->chem[i]->m; + //Distribute vapor components + for (i=0;i<V->nb;i++) + { + V->chem[i]->m = V->m*L->chem[i]->n()*K[i]/L->n()*V->chem[i]->M/1000.0; + V->chem[i]->state=1; + } + V->m=0.0; for(i=0;i<V->nb;i++) V->m+=V->chem[i]->m; + } + for(i=0;i<F->nb;i++) + if(F->chem[i]->Tc<T){V->chem[i]->m=Fcopy->chem[i]->m; V->m+=Fcopy->chem[i]->m;} + + } + else + { + /* if(task==0) + { + log.open("runtime\\messages.r", ios::app); + if (T<F->dp) log<<" --> Warning <-- Mixture in "<<name<<" can't be flashed (bp="<<F->bp<<" dp="<<F->dp<<").\n"; + log.close(); + } */ + for (i=0;i<F->nb;i++) + { + if (F->chem[i]->Tc<T || f_x>=1) {V->chem[i]->m=Fcopy->chem[i]->m; V->m+=V->chem[i]->m; } + else {L->chem[i]->m=Fcopy->chem[i]->m; L->m+=L->chem[i]->m;} + + } + success = true; + } + L->set(P,T); + V->set(P,T); + Q = 0.0; + for (i=0;i<F->nb;i++) + { + Q += L->chem[i]->dH(Tin, T, P)*L->chem[i]->n(); + Q += V->chem[i]->dH(Tin, T, P)*V->chem[i]->n(); + } + F->m=0; + for(i=0;i<Fcopy->nb;i++) {F->chem[i]->m = Fcopy->chem[i]->m; F->m+=F->chem[i]->m;} + F->set(F->P,Tin); +// if(fabs(V->m+L->m-F->m)>sqrt(EPS)) +// { +// log.open(MESSAGES, ios::app); +// log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(V->m+L->m-F->m)/F->m<<").\n"; +// log.close(); +// } +// V->write();// TOTO + // L->write(); // TOTO + + return success; +} + +double flash::f(double psy) +{ + x=psy; + f_x=0.0; + for(i=0;i<F->nb;i++) f_x += (z[i]*(1-K[i]))/(1+psy*(K[i]-1)); + return f_x; +} + +bool flash::adiabatic() +{ + task=1; + F->set(P,T); T=F->dp; + step=-5; + Q=1; + + + while (fabs(step)>0.01 && fabs(Q)>0.1) + { + T+=step; + F->set(P,T); + + for (i=0;i<F->nb;i++) + K[i] = F->chem[i]->Psat(T)/P; + + success=solve(); + + + if (Q<0 && step<0) step*=-0.5; + if (Q>0 && step>0) step*=-0.5; + } + if (fabs(Q)<0.1) return true; + else return false; +} + +void flash::write() { + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> "<<name; + cout << endl << "\t>> stream in : "<<F->name; + cout <<endl<<"\t>> streams out : "<<L->name<<" (liq.) "<<V->name<<" (vap.)"; + cout <<endl<<"\t>> P = "<<P<<" atm, T = "<<T<<" K"; + cout <<endl<<"\t>> Heat duty = "<<Q; + if (success==true) cout <<" kW (converge normally)"; + cout << "\n\tEND\n\n"; + cost(); + power(); + water(); +} + + +double flash::get_cost ( void ) { + vol=15.0*(L->v+V->v); + if(vol<0.3) vol=0.3; if(vol>520)vol=520; + step = 3.4974+0.4485*log10(vol)+0.1074*pow(log10(vol),2); + step = pow(10, step); + P= (P-1)*101.325/100; + f_x=pow(2.0*vol/pi, 1.0/3.0); + vol=(P+1)*f_x/(317.46*(850-0.6*(P+1)))+0.0315; + step *=(2.25+ 1.82*vol*2.2); + step = step*MS_YEAR/MS_2001; + return step; +} + +void flash::cost() { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} +void flash::power() { + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + cout << "\t>>" << Q; + cout << "\n\tEND\n\n"; +} + +double flash::get_water ( void ) { + step = (Q<0.0) ? fabs(Q)/(4.185*0.10*(Tin-298)) : 0.0; + return step; +} + +void flash::water() { + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + if(Q<0.0) + step= (fabs(Q)/(4.185*0.10*(Tin-298))); + else + step= 0.0; + cout << "\t>>" << step; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.hpp index 29bc250c316f150c5f2880ab5696b5601867009d..b6cdb41b3b5c556d848c01ec23b40b0ba0f4356e 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/flash.hpp @@ -1,55 +1,55 @@ -/* -This unit takes operating P and T, and indexes of streams. It applies -the Rachford-Rice procedure to solve the isothermal flash problem -(ref : Seader & Henley). - -Structure in the .process file: -flash {name} {pressure} {temperature} {index of input stream} {index of output liquid and output vapor} - -How to use: - 1- Call the constructor : flash1 = new flash(in, out_L, out_V); //in is the feed, out_L is the liquid output and out_V is the vapor output - 2- Set P and T: flash1->set(P,T); - 3- Set the name: flash1->set(name); - 4a- Perform an isothermal flash : flash1->solve(); - 4b- Perform an adiabatic flash: flash1->adiabatic(); -*/ -#ifndef FLASH_H -#define FLASH_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class flash { -private: - bool success; - bissection<flash> *solver; - // ofstream log, results; -// char name[31], filename[41]; //name of the unit - - string name; - - int i, task; //task=0: isothermal flash; task=1:adiabatic flash - stream *F, *Fcopy; //pointer to the input stream - stream *L, *V; //pointers to liquid and vapor output streams - double f_x, x, *K, *z; //pressure (given) and temperature (given) - double Q, Tin, step, vol; //required power, in kW - -public: - flash(){P=0.0; T=0.0;} - flash(stream*, stream*, stream*); //defines the connectivities of this unit - ~flash(){delete Fcopy; delete [] K; delete [] z; delete solver;} - double P ,T; - void set(double, double); - void set( const string & n ) { name = n; } - bool solve(); //applies the Rachford-Rice procedure - bool adiabatic(); //adiabatic isobaric flash - double f(double); //returns the function to the solver - void write(); - double get_water ( void ); - double get_cost ( void ); - - double get_power ( void ) const { return Q; } - void cost(), water(), power(); -}; -#endif +/* +This unit takes operating P and T, and indexes of streams. It applies +the Rachford-Rice procedure to solve the isothermal flash problem +(ref : Seader & Henley). + +Structure in the .process file: +flash {name} {pressure} {temperature} {index of input stream} {index of output liquid and output vapor} + +How to use: + 1- Call the constructor : flash1 = new flash(in, out_L, out_V); //in is the feed, out_L is the liquid output and out_V is the vapor output + 2- Set P and T: flash1->set(P,T); + 3- Set the name: flash1->set(name); + 4a- Perform an isothermal flash : flash1->solve(); + 4b- Perform an adiabatic flash: flash1->adiabatic(); +*/ +#ifndef FLASH_H +#define FLASH_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class flash { +private: + bool success; + bissection<flash> *solver; + // ofstream log, results; +// char name[31], filename[41]; //name of the unit + + string name; + + int i, task; //task=0: isothermal flash; task=1:adiabatic flash + stream *F, *Fcopy; //pointer to the input stream + stream *L, *V; //pointers to liquid and vapor output streams + double f_x, x, *K, *z; //pressure (given) and temperature (given) + double Q, Tin, step, vol; //required power, in kW + +public: + flash(){P=0.0; T=0.0;} + flash(stream*, stream*, stream*); //defines the connectivities of this unit + ~flash(){delete Fcopy; delete [] K; delete [] z; delete solver;} + double P ,T; + void set(double, double); + void set( const string & n ) { name = n; } + bool solve(); //applies the Rachford-Rice procedure + bool adiabatic(); //adiabatic isobaric flash + double f(double); //returns the function to the solver + void write(); + double get_water ( void ); + double get_cost ( void ); + + double get_power ( void ) const { return Q; } + void cost(), water(), power(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.cpp index fd8942e30cbea0202a6a60ed31b1a3f0b03974a4..3c23822ae8f89a1971ec24d0d35b218e13ebbf40 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.cpp @@ -1,146 +1,146 @@ -#include "heatx.hpp" -#include "bissection.cpp" - -heatx::heatx(bool m, stream* s1, stream* s2) -{ - in = s1; - out = s2; - out->m=0; - for(i=0;i<in->nb;i++) - { - out->chem[i]->m=in->chem[i]->m; - out->m+=out->chem[i]->m; - } - solver = new bissection<heatx>(); - mode = m; - success = true; -} - -void heatx::set(double d1, double d2) -{ - if(mode==0) T=d1; - if(mode==1) Q=d1; - eta = d2; -} - -bool heatx::solve() -{ - if(mode==0) - { - Q = 0.0; - out->set(in->P, T); - // out->write(); // WRITE TOTO - for(i=0;i<in->nb;i++) - Q+=out->chem[i]->dH(in->T, out->T, in->P)*out->chem[i]->n(); - if(eta>EPS) - Qreal = Q/eta; - else { - Qreal=Q; - success=false; - } - } - if(mode==1) - { - Qreal = eta*Q; - min = in->T; - max = 2000; - solver->set(this, min, max); - success = solver->run(); - out->set(in->P, T); - //out->write(); // WRITE TOTO - } - return success; -} - - -double heatx::f(double x) -{ - T=x; - max = Qreal; - for(i=0;i<in->nb;i++) - max -= out->chem[i]->dH(in->T, T, in->P)*out->chem[i]->n(); - return max; -} - -void heatx::write() -{ - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in: " << in->name << " T = " << in->T <<" K"; - cout << endl << "\t>> stream out: " << out->name << " T = " << out->T <<" K"; - if (mode==0) - cout<<endl<<"\t>> Heat duty : "<<Qreal<<" kW"; - if (mode==1) - cout<<endl<<"\t>> Heat duty : "<<Q<<" kW"; - if (success) - cout<<endl<<"\t>> Heat losses "<<fabs(Qreal-Q)<<" kW (converged normally)"; - cout << "\n\tEND\n\n"; - - cost(); - power(); - water(); -} - - - -double heatx::get_cost ( void ) { - if(mode==1) min=fabs(Q)/0.225/(eta)/fabs(out->T-in->T); - if(mode==0) min=fabs(Qreal)/0.25/(eta)/fabs(out->T-in->T); - if(min<10) min=10; if(min>1000) min=1000; - max = 4.3247-0.303*log10(min)+0.1634*pow(log10(min),2); - T=in->P; - T = (T-1)*1.01325; - if (fabs(T)<EPS) T=0.1; if(T>100) T=100; - min=0.03881-0.11272*log10(T)+0.08183*pow(log10(T),2); - min=pow(10, min); - max = (1.63+1.66*2.5*min)*pow(10, max); - max = max*MS_YEAR/MS_2001; - return max; -} - - -void heatx::cost() -{ - cout << setprecision(5); - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - - - -double heatx::get_water ( void ) -{ - max = (Q<0.0) ? fabs(Q)/(4.185*0.10*(out->T-298)) : 0.0; - return max; -} - - -void heatx::water() -{ - if(Q<0.0) max = fabs(Q)/(4.185*0.10*(out->T-298)); - else max = 0.0; - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - cout << "\t>>" << max; - cout << "\n\tEND\n\n"; - -} - -double heatx::get_power ( void ) { - max = (mode) ? Q : Qreal; - if (max>EPS) - return max; - return 0.0; -} - -void heatx::power() -{ - if(mode==0) max = Qreal; - if(mode==1) max = Q; - - cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; - if(max>EPS) cout<< "\t>>" << max; - else cout<< "\t>>" << 0; - cout << "\n\tEND\n\n"; -} +#include "heatx.hpp" +#include "bissection.cpp" + +heatx::heatx(bool m, stream* s1, stream* s2) +{ + in = s1; + out = s2; + out->m=0; + for(i=0;i<in->nb;i++) + { + out->chem[i]->m=in->chem[i]->m; + out->m+=out->chem[i]->m; + } + solver = new bissection<heatx>(); + mode = m; + success = true; +} + +void heatx::set(double d1, double d2) +{ + if(mode==0) T=d1; + if(mode==1) Q=d1; + eta = d2; +} + +bool heatx::solve() +{ + if(mode==0) + { + Q = 0.0; + out->set(in->P, T); + // out->write(); // WRITE TOTO + for(i=0;i<in->nb;i++) + Q+=out->chem[i]->dH(in->T, out->T, in->P)*out->chem[i]->n(); + if(eta>EPS) + Qreal = Q/eta; + else { + Qreal=Q; + success=false; + } + } + if(mode==1) + { + Qreal = eta*Q; + min = in->T; + max = 2000; + solver->set(this, min, max); + success = solver->run(); + out->set(in->P, T); + //out->write(); // WRITE TOTO + } + return success; +} + + +double heatx::f(double x) +{ + T=x; + max = Qreal; + for(i=0;i<in->nb;i++) + max -= out->chem[i]->dH(in->T, T, in->P)*out->chem[i]->n(); + return max; +} + +void heatx::write() +{ + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in: " << in->name << " T = " << in->T <<" K"; + cout << endl << "\t>> stream out: " << out->name << " T = " << out->T <<" K"; + if (mode==0) + cout<<endl<<"\t>> Heat duty : "<<Qreal<<" kW"; + if (mode==1) + cout<<endl<<"\t>> Heat duty : "<<Q<<" kW"; + if (success) + cout<<endl<<"\t>> Heat losses "<<fabs(Qreal-Q)<<" kW (converged normally)"; + cout << "\n\tEND\n\n"; + + cost(); + power(); + water(); +} + + + +double heatx::get_cost ( void ) { + if(mode==1) min=fabs(Q)/0.225/(eta)/fabs(out->T-in->T); + if(mode==0) min=fabs(Qreal)/0.25/(eta)/fabs(out->T-in->T); + if(min<10) min=10; if(min>1000) min=1000; + max = 4.3247-0.303*log10(min)+0.1634*pow(log10(min),2); + T=in->P; + T = (T-1)*1.01325; + if (fabs(T)<EPS) T=0.1; if(T>100) T=100; + min=0.03881-0.11272*log10(T)+0.08183*pow(log10(T),2); + min=pow(10, min); + max = (1.63+1.66*2.5*min)*pow(10, max); + max = max*MS_YEAR/MS_2001; + return max; +} + + +void heatx::cost() +{ + cout << setprecision(5); + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + + + +double heatx::get_water ( void ) +{ + max = (Q<0.0) ? fabs(Q)/(4.185*0.10*(out->T-298)) : 0.0; + return max; +} + + +void heatx::water() +{ + if(Q<0.0) max = fabs(Q)/(4.185*0.10*(out->T-298)); + else max = 0.0; + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + cout << "\t>>" << max; + cout << "\n\tEND\n\n"; + +} + +double heatx::get_power ( void ) { + max = (mode) ? Q : Qreal; + if (max>EPS) + return max; + return 0.0; +} + +void heatx::power() +{ + if(mode==0) max = Qreal; + if(mode==1) max = Q; + + cout << "WRITE FILE " << RUNTIME << name << ".power" << " :\n\tBEGIN\n"; + if(max>EPS) cout<< "\t>>" << max; + else cout<< "\t>>" << 0; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.hpp index d3b7dffa4dd8771694a77c52ad38a6aba478e821..f9854adf318b541dcac49e2466d35cc69683cd2d 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/heatx.hpp @@ -1,49 +1,49 @@ -/* -This unit performs the heating of a stream (mode 0) or the heat -exchange to a stream (mode 1). -(ref : McCabe, Smith & Harriott) - -Structure in the .process file: -mode 0 : heatx {name} 0 {index of input stream} {index of output stream} {T out} {efficiency} //efficiency is a fraction between 0 and 1 -mode 1 : heatx {name} 1 {index of input stream} {index of output stream} {Q} {efficiency} //Q is the heat flow in kW -How to use: - 1- Call the constructor: heat = new heatx(mode, in, out); - 2- Set the operating conditions : heat->set(T_out, eta); //mode 0 - or : heat->set(Q, eta); //mode 1 - 3- Set the name of the unit: heat->set(name); - 4- Solve: bool=heat->solve(); -*/ -#ifndef HEATX_H -#define HEATX_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class heatx -{ -private: - int i; - bool success, mode; - bissection<heatx> *solver; - // ofstream logf, results; - double min, max; - string name; - stream *in, *out; //streams of the unit - double eta, Q, Qreal, T; - -public: - heatx(){} - heatx(bool, stream*, stream*); //defines the connectivities of this unit - ~heatx(){delete solver;} - void set(double, double); - void set(const string & n) { name = n; } - double f(double); - bool solve(); - void write(); - void power(), water(), cost(); - double get_cost(); - double get_power(); - double get_water(); -}; -#endif +/* +This unit performs the heating of a stream (mode 0) or the heat +exchange to a stream (mode 1). +(ref : McCabe, Smith & Harriott) + +Structure in the .process file: +mode 0 : heatx {name} 0 {index of input stream} {index of output stream} {T out} {efficiency} //efficiency is a fraction between 0 and 1 +mode 1 : heatx {name} 1 {index of input stream} {index of output stream} {Q} {efficiency} //Q is the heat flow in kW +How to use: + 1- Call the constructor: heat = new heatx(mode, in, out); + 2- Set the operating conditions : heat->set(T_out, eta); //mode 0 + or : heat->set(Q, eta); //mode 1 + 3- Set the name of the unit: heat->set(name); + 4- Solve: bool=heat->solve(); +*/ +#ifndef HEATX_H +#define HEATX_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class heatx +{ +private: + int i; + bool success, mode; + bissection<heatx> *solver; + // ofstream logf, results; + double min, max; + string name; + stream *in, *out; //streams of the unit + double eta, Q, Qreal, T; + +public: + heatx(){} + heatx(bool, stream*, stream*); //defines the connectivities of this unit + ~heatx(){delete solver;} + void set(double, double); + void set(const string & n) { name = n; } + double f(double); + bool solve(); + void write(); + void power(), water(), cost(); + double get_cost(); + double get_power(); + double get_water(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.cpp index dc02dc7e4b82f42e8631fadcb4d4b2d8500fec32..00202a2af2f1ce299966b7b44e1fe85c060950d0 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.cpp @@ -1,80 +1,80 @@ -#include "mix.hpp" -#include "bissection.cpp" -using namespace std; - -mix::mix ( int n , stream ** s1 , stream * s2 ) { - nb_in=n; - in = s1; - out= s2; - success = true; - solver = new bissection<mix>(); -} - -bool mix::solve() -{ - //Mass balance - out->m=0; - out->purge(); - for (j=0; j<out->nb;j++) - for (i=0;i<nb_in;i++) if(in[i]->chem[j]->m>EPS) - { - out->chem[j]->m+=in[i]->chem[j]->m; - out->m+=in[i]->chem[j]->m; - } - //Find the temperature - double max=0.0; double min=1e6; - for(i=0;i<nb_in;i++) - for(j=0;j<out->nb;j++) - { - if(in[i]->chem[j]->T>max && in[i]->chem[j]->m>EPS) max=in[i]->chem[j]->T; - if(in[i]->chem[j]->T<min && in[i]->chem[j]->m>EPS) min=in[i]->chem[j]->T; - } - if(fabs(max-min)<EPS) T=max; - else - { - solver->set(this, min, max); - success = solver->run(); - } - out->set(P,T); - // if (success==false) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Solver of "<<name<<" did not converge.\n"; - // log.close(); - // } - // min = 0; - // for(i=0;i<nb_in;i++) - // min+=in[i]->m; - // if(fabs(min-out->m)>sqrt(EPS)) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(min-out->m)/min<<").\n"; - // log.close(); - // } - - // out->write(); // WRITE TOTO - return success; -} - -double mix::f(double x) -{ - T=x; - double energy=0.0; //in kW - for (j=0; j<out->nb;j++) - for (i=0;i<nb_in;i++) - energy += in[i]->chem[j]->dH(in[i]->T, T, P)*in[i]->chem[j]->n()/1000; - return energy; -} - -void mix::write() { - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name - << endl << "\t>> streams in: "; - for ( int i = 0 ; i < nb_in ; i++ ) - cout << in[i]->name << " "; - cout << endl << "\t>> stream out: " << out->name; - cout <<endl << "\t>> P = " << P << " atm, T = " << T; - if (success) - cout << " K (converged normally)"; - cout << "\n\tEND\n\n"; -} +#include "mix.hpp" +#include "bissection.cpp" +using namespace std; + +mix::mix ( int n , stream ** s1 , stream * s2 ) { + nb_in=n; + in = s1; + out= s2; + success = true; + solver = new bissection<mix>(); +} + +bool mix::solve() +{ + //Mass balance + out->m=0; + out->purge(); + for (j=0; j<out->nb;j++) + for (i=0;i<nb_in;i++) if(in[i]->chem[j]->m>EPS) + { + out->chem[j]->m+=in[i]->chem[j]->m; + out->m+=in[i]->chem[j]->m; + } + //Find the temperature + double max=0.0; double min=1e6; + for(i=0;i<nb_in;i++) + for(j=0;j<out->nb;j++) + { + if(in[i]->chem[j]->T>max && in[i]->chem[j]->m>EPS) max=in[i]->chem[j]->T; + if(in[i]->chem[j]->T<min && in[i]->chem[j]->m>EPS) min=in[i]->chem[j]->T; + } + if(fabs(max-min)<EPS) T=max; + else + { + solver->set(this, min, max); + success = solver->run(); + } + out->set(P,T); + // if (success==false) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Solver of "<<name<<" did not converge.\n"; + // log.close(); + // } + // min = 0; + // for(i=0;i<nb_in;i++) + // min+=in[i]->m; + // if(fabs(min-out->m)>sqrt(EPS)) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(min-out->m)/min<<").\n"; + // log.close(); + // } + + // out->write(); // WRITE TOTO + return success; +} + +double mix::f(double x) +{ + T=x; + double energy=0.0; //in kW + for (j=0; j<out->nb;j++) + for (i=0;i<nb_in;i++) + energy += in[i]->chem[j]->dH(in[i]->T, T, P)*in[i]->chem[j]->n()/1000; + return energy; +} + +void mix::write() { + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name + << endl << "\t>> streams in: "; + for ( int i = 0 ; i < nb_in ; i++ ) + cout << in[i]->name << " "; + cout << endl << "\t>> stream out: " << out->name; + cout <<endl << "\t>> P = " << P << " atm, T = " << T; + if (success) + cout << " K (converged normally)"; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.hpp index 6d4ee0f28d6696616e803fdfe89e6689b3001d69..85b8d771f173ba66deb363e2586bb42d7cd74854 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/mix.hpp @@ -1,44 +1,44 @@ -/* -This unit takes more than two input streams and merge them in one -output stream. The pressure must be specified by the user, and the -temperature of the output stream is computed. - -Structure in the .process file: -mix {name} {pressure} {nb_in} {indexes of input streams} {index of output stream} - -How to use: - 1- Call the constructor: mix1 = new mix(nb_in, list1_in, out); - 2- Set the operating pressure : mix1->set(P); - 3- Set the name of the unit: mix1->set(name); - 4- Solve: bool=mix1->solve(); -*/ -#ifndef MIX_H -#define MIX_H - -#include "stream.hpp" -#include "bissection.hpp" -using namespace std; - -class mix { - private: - int i, j; - bool success; - bissection<mix> *solver; - string name; - int nb_in; //number of input streams - stream **in; //list pointers to input streams - stream *out; //pointer to output stream - // double min, max; - - public: - double P, T; //pressure (given) and temperature (unknown) - mix(){P=0.0;} - mix(int, stream**, stream*); //defines the connectivities of this unit - ~mix(){delete solver;} - void set(double p) {P=p;} - void set ( const string & n ) { name = n; } - double f(double); //returns the function to the solver - bool solve(); //finds the temperature and computes mass balance - void write(); -}; -#endif +/* +This unit takes more than two input streams and merge them in one +output stream. The pressure must be specified by the user, and the +temperature of the output stream is computed. + +Structure in the .process file: +mix {name} {pressure} {nb_in} {indexes of input streams} {index of output stream} + +How to use: + 1- Call the constructor: mix1 = new mix(nb_in, list1_in, out); + 2- Set the operating pressure : mix1->set(P); + 3- Set the name of the unit: mix1->set(name); + 4- Solve: bool=mix1->solve(); +*/ +#ifndef MIX_H +#define MIX_H + +#include "stream.hpp" +#include "bissection.hpp" +using namespace std; + +class mix { + private: + int i, j; + bool success; + bissection<mix> *solver; + string name; + int nb_in; //number of input streams + stream **in; //list pointers to input streams + stream *out; //pointer to output stream + // double min, max; + + public: + double P, T; //pressure (given) and temperature (unknown) + mix(){P=0.0;} + mix(int, stream**, stream*); //defines the connectivities of this unit + ~mix(){delete solver;} + void set(double p) {P=p;} + void set ( const string & n ) { name = n; } + double f(double); //returns the function to the solver + bool solve(); //finds the temperature and computes mass balance + void write(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.cpp index aa12b2fdd9edb49a3f61ee5e3a39ab278491f60d..10583ce4da9356087bcc65adc54e99937dc0187c 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.cpp @@ -1,172 +1,172 @@ -#include "pfr.hpp" -#include "RungeKutta.cpp" -using namespace std; - -pfr::pfr ( stream * s1 , stream * s2 , double ** t , int nb_r , reaction ** rr , double u , double ta ) { - - F = s2; - F->m=0; - P=s1->P; - for ( i = 0 ; i < s1->nb ; i++ ) { - F->chem[i]->m = s1->chem[i]->m; - F->m+=F->chem[i]->m; - } - F->set(s1->P, s1->T); - m_in=F->m; - a = t; - rx = rr; - n=nb_r; - m= F->nb; - U=u; - Ta=ta; - T = F->T; - C = new double[m]; - y = new double[m+1]; - r=new double[n]; - OK=true; - explode=true; - solver = new RungeKutta<pfr>(m+1); -} - -pfr::~pfr() { - delete [] r; - delete [] C; - delete [] y; - delete solver; -} - -bool pfr::run() { - - for ( i = 0 ; i < m ; i++ ) - y[i]=F->chem[i]->n(); - - y[m]=T; - - solver->set ( this , y , 0.0 , L ); - - dL=solver->dx(); - - OK=solver->run(); - - sum = F->m; - F->m = 0; - - for ( i = 0 ; i < m ; i++ ) - F->m+=F->chem[i]->m; - for ( i = 0 ; i < m ; i++ ) - F->chem[i]->m *= sum/F->m; - // if (OK) - //mass balance! - if ( fabs(m_in-F->m) > EPS || !explode ) - OK=false; - - return OK; -} - -double pfr::f ( int eq , double l , double * y ) { - - - sum=F->m; - F->m=0; - for(i=0; i<m;i++) - { - if(y[i]<0) y[i]=0; - F->chem[i]->m = y[i]*F->chem[i]->M/1000.0; - F->m+=F->chem[i]->m; - } - - - for(i=0; i<m;i++) - F->chem[i]->m *= sum/F->m; - - - - F->m=sum; - T=y[m]; - if(T>MAX_TEMP) - { - cout << "ERROR 11\n\n"; - exit(0); - } - - - for(i=0; i<m;i++) - C[i]=F->chem[i]->n()/F->v; - - for(j=0;j<n;j++) - r[j] = rx[j]->rate(T,C); - - if(0<=eq && eq<m) //return dFi/dL - { - tmp=0.0; - for(j=0;j<n;j++) tmp+=a[eq][j]*r[j]; - tmp *= (pi*D*D/4.0); - } - - - - if(eq==m) //return dT/dL - { - - - F->set(F->P,T); - - tmp=0.0; - for(j=0;j<n;j++) - tmp -= r[j]*rx[j]->dHr(T); - - - tmp *= (pi*D*D/4.0); - - - tmp += (pi*D)*U*(Ta-T); - - - tmp1=0.0; - for(i=0;i<m;i++) { - tmp1+= y[i]*F->chem[i]->Cp()*0.001; - } - tmp /= tmp1; - - if(fabs(tmp*dL)>500.0) - { - cout << "ERROR 13\n\n"; - exit(0); - } - } - - return tmp; -} - - - -double pfr::get_cost ( void ) { - dL=L*pi*pow(D,2)/4.0; - if(dL<0.3) dL=0.3; if(dL>520) dL=520; - sum = 3.4974+0.4485*log10(dL)+0.1074*pow(log10(dL),2); - sum = pow(10, sum); - P= (P-1)*101.325/100; - dL=(P+1)*D/(317.46*(850-0.6*(P+1)))+0.0315; - sum *=(2.25+ 1.82*dL*4.2); - sum = sum*MS_YEAR/MS_2001; - return sum; -} - -double pfr::get_water() { - sum = (U>EPS && T>Ta) ? U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0 : 0.0; - return sum; -} - -void pfr::cost() { - cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - -void pfr::water() { - cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; - if (U>EPS && T>Ta) sum = (U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0); - else sum = 0.0; - cout << "\t>>" << sum; - cout << "\n\tEND\n\n"; -} +#include "pfr.hpp" +#include "RungeKutta.cpp" +using namespace std; + +pfr::pfr ( stream * s1 , stream * s2 , double ** t , int nb_r , reaction ** rr , double u , double ta ) { + + F = s2; + F->m=0; + P=s1->P; + for ( i = 0 ; i < s1->nb ; i++ ) { + F->chem[i]->m = s1->chem[i]->m; + F->m+=F->chem[i]->m; + } + F->set(s1->P, s1->T); + m_in=F->m; + a = t; + rx = rr; + n=nb_r; + m= F->nb; + U=u; + Ta=ta; + T = F->T; + C = new double[m]; + y = new double[m+1]; + r=new double[n]; + OK=true; + explode=true; + solver = new RungeKutta<pfr>(m+1); +} + +pfr::~pfr() { + delete [] r; + delete [] C; + delete [] y; + delete solver; +} + +bool pfr::run() { + + for ( i = 0 ; i < m ; i++ ) + y[i]=F->chem[i]->n(); + + y[m]=T; + + solver->set ( this , y , 0.0 , L ); + + dL=solver->dx(); + + OK=solver->run(); + + sum = F->m; + F->m = 0; + + for ( i = 0 ; i < m ; i++ ) + F->m+=F->chem[i]->m; + for ( i = 0 ; i < m ; i++ ) + F->chem[i]->m *= sum/F->m; + // if (OK) + //mass balance! + if ( fabs(m_in-F->m) > EPS || !explode ) + OK=false; + + return OK; +} + +double pfr::f ( int eq , double l , double * y ) { + + + sum=F->m; + F->m=0; + for(i=0; i<m;i++) + { + if(y[i]<0) y[i]=0; + F->chem[i]->m = y[i]*F->chem[i]->M/1000.0; + F->m+=F->chem[i]->m; + } + + + for(i=0; i<m;i++) + F->chem[i]->m *= sum/F->m; + + + + F->m=sum; + T=y[m]; + if(T>MAX_TEMP) + { + cout << "ERROR 11\n\n"; + exit(0); + } + + + for(i=0; i<m;i++) + C[i]=F->chem[i]->n()/F->v; + + for(j=0;j<n;j++) + r[j] = rx[j]->rate(T,C); + + if(0<=eq && eq<m) //return dFi/dL + { + tmp=0.0; + for(j=0;j<n;j++) tmp+=a[eq][j]*r[j]; + tmp *= (pi*D*D/4.0); + } + + + + if(eq==m) //return dT/dL + { + + + F->set(F->P,T); + + tmp=0.0; + for(j=0;j<n;j++) + tmp -= r[j]*rx[j]->dHr(T); + + + tmp *= (pi*D*D/4.0); + + + tmp += (pi*D)*U*(Ta-T); + + + tmp1=0.0; + for(i=0;i<m;i++) { + tmp1+= y[i]*F->chem[i]->Cp()*0.001; + } + tmp /= tmp1; + + if(fabs(tmp*dL)>500.0) + { + cout << "ERROR 13\n\n"; + exit(0); + } + } + + return tmp; +} + + + +double pfr::get_cost ( void ) { + dL=L*pi*pow(D,2)/4.0; + if(dL<0.3) dL=0.3; if(dL>520) dL=520; + sum = 3.4974+0.4485*log10(dL)+0.1074*pow(log10(dL),2); + sum = pow(10, sum); + P= (P-1)*101.325/100; + dL=(P+1)*D/(317.46*(850-0.6*(P+1)))+0.0315; + sum *=(2.25+ 1.82*dL*4.2); + sum = sum*MS_YEAR/MS_2001; + return sum; +} + +double pfr::get_water() { + sum = (U>EPS && T>Ta) ? U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0 : 0.0; + return sum; +} + +void pfr::cost() { + cout << "WRITE FILE " << RUNTIME << name << ".cost" << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + +void pfr::water() { + cout << "WRITE FILE " << RUNTIME << name << ".water" << " :\n\tBEGIN\n"; + if (U>EPS && T>Ta) sum = (U*L*pi*pow(D,2)/4*(T-Ta)/4.185/25.0); + else sum = 0.0; + cout << "\t>>" << sum; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.hpp index 9746a504839af042f2f0584c37708be715bbbbb4..a8f49a71415ecc208c6ed692e7a4c6b99351ce49 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/pfr.hpp @@ -1,36 +1,36 @@ -#ifndef PFR_H -#define PFR_H - -#include "reaction.hpp" -#include "RungeKutta.hpp" -#include "stream.hpp" -using namespace std; - -class pfr { -private: - // terminator *term; - // ofstream results; - string name; - bool OK, explode; - int i ,j, n, m; - double L,D,dL, U, Ta, m_in, sum, P; - stream *F; - double **a, *C, T, *y, *r, tmp, tmp1; - reaction **rx; - RungeKutta<pfr> *solver; - -public: - // pfr(){}; - pfr ( stream * , stream * , double ** , int , reaction ** , double , double ); - void set ( const string & n ) { name = n; } - void set(double l, double d) {L=l; D=d;} - bool run(); - void water(); - void cost(); - double get_cost ( void ); - double get_water ( void ); - - double f(int, double, double*); - ~pfr(); -}; -#endif +#ifndef PFR_H +#define PFR_H + +#include "reaction.hpp" +#include "RungeKutta.hpp" +#include "stream.hpp" +using namespace std; + +class pfr { +private: + // terminator *term; + // ofstream results; + string name; + bool OK, explode; + int i ,j, n, m; + double L,D,dL, U, Ta, m_in, sum, P; + stream *F; + double **a, *C, T, *y, *r, tmp, tmp1; + reaction **rx; + RungeKutta<pfr> *solver; + +public: + // pfr(){}; + pfr ( stream * , stream * , double ** , int , reaction ** , double , double ); + void set ( const string & n ) { name = n; } + void set(double l, double d) {L=l; D=d;} + bool run(); + void water(); + void cost(); + double get_cost ( void ); + double get_water ( void ); + + double f(int, double, double*); + ~pfr(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.cpp index 902f30dcfd2091ddbd5395997e010cb446546243..3617b30317dac940d299770d5afe8f8ec4a67c31 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.cpp @@ -1,138 +1,138 @@ -#include "profitability.hpp" -#include "secant.cpp" -using namespace std; - -bool profitability::run ( double * y ) -{ - OK=true; - - // cout<<setiosflags(ios::fixed); - // cout<<endl<<endl<<" PROFITABILITY ANALYSIS"<<endl; - // cout<<endl<<setprecision(1)<<" Return on investment (%)= "<<ROI()*100.0; - // cout<<endl<<" Rate of return (%)= "<<RR()*100.0; // y[10] - - y[10] = RR()*100.0; // y[10] - - ROI(); - RR(); - - // cout<<endl<<" Discounted flow rate (%)= "<<DFR()*100.0; - - DFR(); - - // cout<<endl<<endl<<" Payout time (y)= "<<PT(); // y[ 9] - y[9] = PT(); - - // cout<<endl<<setprecision(0)<<" Annual equivalent cost ($)= "<<AEC(); // y[12] - y[12] = AEC(); - - // cout<<endl<<" Net present value ($)= "<<NPV()<<endl; // y[13] - y[13] = NPV(); - - return OK; -} - -double profitability::ROI() -{ - // if(!MUTE)cout<<endl<<" return on investment..."; - num=den=0.0; - for(i=0;i<C->N;i++) - { - if(C->Inv[i]>EPS) den+=C->Inv[i]; - num+=(C->Rev[i]-C->Coper[i]-C->Amort[i]); - } - if (num>EPS && den>EPS && C->N>0) { - // if(!MUTE)cout<<" OK"; - return num/C->N/den; - } - else return 0.0; -} - -double profitability::RR() -{ - // if(!MUTE)cout<<endl<<" rate of return..."; - num=den=0.0; - for(i=0;i<C->N;i++) - { - num+=(C->Rev[i]-C->Coper[i])/pow(1.0+C->i_rate, i); - den+=C->Inv[i]/pow(1.0+C->i_rate, i); - } - if(num>EPS && den>EPS) { - // if(!MUTE)cout<<" OK"; - return num/den; - } - else return 0.0; -} - -double profitability::DFR() -{ - //if(!MUTE)cout<<endl<<" discounted cash flow rate..."; - solver = new secant<profitability>(); - solver->set(this, 0.0, 0.01); - OK = solver->run(); - - if ( OK && num>EPS && num < 1e20 ) { - // if(!MUTE)cout<<" OK"; - return num; - } - else return 0.0; -} - -double profitability::f(double x) -{ - num=x; - sum=0.0; - for(i=0;i<C->N;i++) - sum += C->Flow[i]/pow(1.0+x, i); - return sum; -} - -double profitability::PT() -{ - // if(!MUTE)cout<<endl<<" payout time..."; - sum=0.0; - for(i=0;i<C->N;i++) - { - if((sum+C->Flow[i])>0.0) - { - den=0.0; - while(sum+den*C->Flow[i]<=0.0) den+=0.001; - den+=double(i-1); - i=C->N; - } - else sum+=C->Flow[i]; - } - - if(den>EPS) { - // if(!MUTE)cout<<" OK"; - return den; - } - else return 0.0; -} - -double profitability::AEC() -{ - //if(!MUTE)cout<<endl<<" annual equivalent cost..."; - sum=0.0; - for(i=0;i<C->N;i++) sum+=(C->Coper[i]+C->Inv[i])/pow(1.0+C->i_rate, i); - if (sum>EPS) { -// if(!MUTE) -// cout<<" OK"; - return sum*(C->i_rate*pow(1.0+C->i_rate,C->N))/(pow(1.0+C->i_rate,C->N)-1.0); - } - else return 0.0; -} - -double profitability::NPV() -{ - // if(!MUTE)cout<<endl<<" net present value..."; - sum=0.0; - for ( i = 0 ; i < C->N ; i++ ) - sum += C->Flowact[i]; - if ( sum > EPS ) { -// if(!MUTE) -// cout<<" OK"; - return sum; - } - return 0.0; -} +#include "profitability.hpp" +#include "secant.cpp" +using namespace std; + +bool profitability::run ( double * y ) +{ + OK=true; + + // cout<<setiosflags(ios::fixed); + // cout<<endl<<endl<<" PROFITABILITY ANALYSIS"<<endl; + // cout<<endl<<setprecision(1)<<" Return on investment (%)= "<<ROI()*100.0; + // cout<<endl<<" Rate of return (%)= "<<RR()*100.0; // y[10] + + y[10] = RR()*100.0; // y[10] + + ROI(); + RR(); + + // cout<<endl<<" Discounted flow rate (%)= "<<DFR()*100.0; + + DFR(); + + // cout<<endl<<endl<<" Payout time (y)= "<<PT(); // y[ 9] + y[9] = PT(); + + // cout<<endl<<setprecision(0)<<" Annual equivalent cost ($)= "<<AEC(); // y[12] + y[12] = AEC(); + + // cout<<endl<<" Net present value ($)= "<<NPV()<<endl; // y[13] + y[13] = NPV(); + + return OK; +} + +double profitability::ROI() +{ + // if(!MUTE)cout<<endl<<" return on investment..."; + num=den=0.0; + for(i=0;i<C->N;i++) + { + if(C->Inv[i]>EPS) den+=C->Inv[i]; + num+=(C->Rev[i]-C->Coper[i]-C->Amort[i]); + } + if (num>EPS && den>EPS && C->N>0) { + // if(!MUTE)cout<<" OK"; + return num/C->N/den; + } + else return 0.0; +} + +double profitability::RR() +{ + // if(!MUTE)cout<<endl<<" rate of return..."; + num=den=0.0; + for(i=0;i<C->N;i++) + { + num+=(C->Rev[i]-C->Coper[i])/pow(1.0+C->i_rate, i); + den+=C->Inv[i]/pow(1.0+C->i_rate, i); + } + if(num>EPS && den>EPS) { + // if(!MUTE)cout<<" OK"; + return num/den; + } + else return 0.0; +} + +double profitability::DFR() +{ + //if(!MUTE)cout<<endl<<" discounted cash flow rate..."; + solver = new secant<profitability>(); + solver->set(this, 0.0, 0.01); + OK = solver->run(); + + if ( OK && num>EPS && num < 1e20 ) { + // if(!MUTE)cout<<" OK"; + return num; + } + else return 0.0; +} + +double profitability::f(double x) +{ + num=x; + sum=0.0; + for(i=0;i<C->N;i++) + sum += C->Flow[i]/pow(1.0+x, i); + return sum; +} + +double profitability::PT() +{ + // if(!MUTE)cout<<endl<<" payout time..."; + sum=0.0; + for(i=0;i<C->N;i++) + { + if((sum+C->Flow[i])>0.0) + { + den=0.0; + while(sum+den*C->Flow[i]<=0.0) den+=0.001; + den+=double(i-1); + i=C->N; + } + else sum+=C->Flow[i]; + } + + if(den>EPS) { + // if(!MUTE)cout<<" OK"; + return den; + } + else return 0.0; +} + +double profitability::AEC() +{ + //if(!MUTE)cout<<endl<<" annual equivalent cost..."; + sum=0.0; + for(i=0;i<C->N;i++) sum+=(C->Coper[i]+C->Inv[i])/pow(1.0+C->i_rate, i); + if (sum>EPS) { +// if(!MUTE) +// cout<<" OK"; + return sum*(C->i_rate*pow(1.0+C->i_rate,C->N))/(pow(1.0+C->i_rate,C->N)-1.0); + } + else return 0.0; +} + +double profitability::NPV() +{ + // if(!MUTE)cout<<endl<<" net present value..."; + sum=0.0; + for ( i = 0 ; i < C->N ; i++ ) + sum += C->Flowact[i]; + if ( sum > EPS ) { +// if(!MUTE) +// cout<<" OK"; + return sum; + } + return 0.0; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.hpp index 03f85c57c5454c84d5be1f6d6d35a42a45839c1f..194102c797e5dc33436d923e0b2b883da4a85979 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/profitability.hpp @@ -1,30 +1,30 @@ -#ifndef PROFITABILITY_H -#define PROFITABILITY_H -#include "cashflow.hpp" -#include "secant.hpp" - -#include <iomanip> - -using namespace std; - -class profitability -{ -private: - cashflow *C; -// ofstream out; -// char name[41]; - bool OK; - double ROI(), RR(), DFR(); - double PT(), AEC(), NPV(); - int i; - double den, num, sum; - secant<profitability> *solver; - -public: - profitability(cashflow* c){C=c;} - ~profitability(){delete solver;}; - // void set(char n[31]) {strcpy(name, n); strcat(name, ".econo");} - bool run ( double * y ); - double f(double); -}; -#endif +#ifndef PROFITABILITY_H +#define PROFITABILITY_H +#include "cashflow.hpp" +#include "secant.hpp" + +#include <iomanip> + +using namespace std; + +class profitability +{ +private: + cashflow *C; +// ofstream out; +// char name[41]; + bool OK; + double ROI(), RR(), DFR(); + double PT(), AEC(), NPV(); + int i; + double den, num, sum; + secant<profitability> *solver; + +public: + profitability(cashflow* c){C=c;} + ~profitability(){delete solver;}; + // void set(char n[31]) {strcpy(name, n); strcat(name, ".econo");} + bool run ( double * y ); + double f(double); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.cpp index 166123fcc5c2a010b33059419d072a6a5b28882c..685a0bef39991b6383b7ec874dbe9d695504bf08 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.cpp @@ -1,94 +1,94 @@ -#include "pump.hpp" -using namespace std; - -bool pump::solve() { - - // out->chem = in->chem; - out->set ( in->nb , in->chem ); - out->m = in->m; - - - in->set(in->P,in->T); - for ( i = 0 ; i < in->nb ; i++ ) - if(in->chem[i]->m>EPS) { - in->chem[i]->find_v(); - if(in->chem[i]->state==1) { - W+=in->chem[i]->gamma()*in->T*0.0083144*in->chem[i]->n()/ - (in->chem[i]->gamma()-1.0)*(pow(P/in->P, 1.0-1.0/in->chem[i]->gamma())-1.0); - tmp += in->chem[i]->gamma(); - n++; - } - if(in->chem[i]->state==0) - W+=in->chem[i]->v*(P-in->P)*101.325; - } - if (fabs(state-1)<EPS) //compressing gases - out->T = in->T*pow(P/in->P, 1.0-1.0/(tmp/n)); - else //compressing liquids - out->T=in->T; - out->set(P, out->T); - if(eta>EPS) - W /= eta; - else - success=false; - // out->write(); // WRITE TOTO - return success; -} - -void pump::write() { - - cout << setprecision(6); - - string file_name = RUNTIME + name + ".unit"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout <<"\t>> " << name; - cout << endl << "\t>> stream in: "<<in->name<<" out: "<<out->name; - cout << endl << "\t>> P(in) = "<<in->P<<" P(out) = "<<out->P<<" atm"; - cout << endl << "\t>> T(in) = "<<in->T<<" T(out) = "<<out->T<<" K"; - cout << endl << "\t>> Shaft work = "<<W; - if (success) - cout <<" kW (converge normally)"; - cout << "\n\tEND\n\n"; - - power(); - cost(); -} - - -double pump::get_cost ( void ) { - - if ( fabs(state-1) < EPS ) { - if(W<450) W=450; if(W>3000)W=3000; - tmp=2.2891+1.3604*log10(W)-0.1027*pow(log10(W),2); - tmp=3.2*pow(10.0, tmp); - tmp1=2.4604+1.4191*log10(W)-0.1798*pow(log10(W),2); - tmp1=1.5*pow(10.0, tmp1); - tmp+=tmp1; - } - else { - if(W<1) W=1; if(W>300)W=300; - tmp=3.3892+0.0536*log10(W)+0.1538*pow(log10(W),2); - tmp=pow(10.0, tmp); - P=(P-1.0)*101.325/100.0; - if (P<EPS) P=1; if(P>100) P=100; - W = -0.3925+0.3957*log10(P)-0.00226*pow(log10(P),2); - W=pow(10.0, W); if(W<1) W=1; - tmp*=(1.89+1.35*W*1.8); - } - tmp = tmp*MS_YEAR/MS_2001; - return tmp; -} - - -void pump::cost() { - string file_name = RUNTIME + name + ".cost"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout << "\t>>" << get_cost(); - cout << "\n\tEND\n\n"; -} - -void pump::power() { - string file_name = RUNTIME + name + ".power"; - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - cout << "\t>>" << W; - cout << "\n\tEND\n\n"; -} +#include "pump.hpp" +using namespace std; + +bool pump::solve() { + + // out->chem = in->chem; + out->set ( in->nb , in->chem ); + out->m = in->m; + + + in->set(in->P,in->T); + for ( i = 0 ; i < in->nb ; i++ ) + if(in->chem[i]->m>EPS) { + in->chem[i]->find_v(); + if(in->chem[i]->state==1) { + W+=in->chem[i]->gamma()*in->T*0.0083144*in->chem[i]->n()/ + (in->chem[i]->gamma()-1.0)*(pow(P/in->P, 1.0-1.0/in->chem[i]->gamma())-1.0); + tmp += in->chem[i]->gamma(); + n++; + } + if(in->chem[i]->state==0) + W+=in->chem[i]->v*(P-in->P)*101.325; + } + if (fabs(state-1)<EPS) //compressing gases + out->T = in->T*pow(P/in->P, 1.0-1.0/(tmp/n)); + else //compressing liquids + out->T=in->T; + out->set(P, out->T); + if(eta>EPS) + W /= eta; + else + success=false; + // out->write(); // WRITE TOTO + return success; +} + +void pump::write() { + + cout << setprecision(6); + + string file_name = RUNTIME + name + ".unit"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout <<"\t>> " << name; + cout << endl << "\t>> stream in: "<<in->name<<" out: "<<out->name; + cout << endl << "\t>> P(in) = "<<in->P<<" P(out) = "<<out->P<<" atm"; + cout << endl << "\t>> T(in) = "<<in->T<<" T(out) = "<<out->T<<" K"; + cout << endl << "\t>> Shaft work = "<<W; + if (success) + cout <<" kW (converge normally)"; + cout << "\n\tEND\n\n"; + + power(); + cost(); +} + + +double pump::get_cost ( void ) { + + if ( fabs(state-1) < EPS ) { + if(W<450) W=450; if(W>3000)W=3000; + tmp=2.2891+1.3604*log10(W)-0.1027*pow(log10(W),2); + tmp=3.2*pow(10.0, tmp); + tmp1=2.4604+1.4191*log10(W)-0.1798*pow(log10(W),2); + tmp1=1.5*pow(10.0, tmp1); + tmp+=tmp1; + } + else { + if(W<1) W=1; if(W>300)W=300; + tmp=3.3892+0.0536*log10(W)+0.1538*pow(log10(W),2); + tmp=pow(10.0, tmp); + P=(P-1.0)*101.325/100.0; + if (P<EPS) P=1; if(P>100) P=100; + W = -0.3925+0.3957*log10(P)-0.00226*pow(log10(P),2); + W=pow(10.0, W); if(W<1) W=1; + tmp*=(1.89+1.35*W*1.8); + } + tmp = tmp*MS_YEAR/MS_2001; + return tmp; +} + + +void pump::cost() { + string file_name = RUNTIME + name + ".cost"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout << "\t>>" << get_cost(); + cout << "\n\tEND\n\n"; +} + +void pump::power() { + string file_name = RUNTIME + name + ".power"; + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + cout << "\t>>" << W; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.hpp index dbcacfd5005ca04ff4cc2f45b02d8ef3bd55af37..aac9e6bea209a0cf9177dcdcc7f3bdd63d9030e6 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/pump.hpp @@ -1,46 +1,46 @@ -/* -This unit takes one input stream and divides in two or more -output streams. The pressure and temparature of output streams -are the same as the input's. -(ref : McCabe, Smith & Harriott) - -Structure in the .process file: -pump {name} {index of input stream} {index of output stream} {output pressure in atm} {efficiency, between 0 and 1} - -How to use: - 1- Call the constructor: pump1 = new pump(in, out); - 2- Set conditions: pump1->set(P_output, efficiency); - 3- Set the name: pump1->set(name); - 4- Solve: pump1->solve(); -*/ -#ifndef PUMP_H -#define PUMP_H - -#include "stream.hpp" -using namespace std; - -class pump -{ -private: - int i, j, n; - double state, tmp, tmp1; - bool success; - string name; - stream *in; //pointer to input stream - stream *out; //pointer to output stream - -public: - double P, W, eta; //output presure in atm, work in kW and efficiency - pump(stream* s1, stream* s2) {in=s1; out=s2; success=true; W=0.0; n=0; tmp=0.0;} - ~pump(){} - void set(double p, double e){P = p; eta = e; state=in->quality();} - void set(const string & n) { name = n; } - bool solve(); //finds the temperature and computes mass balance - void write(); - void cost(); - double get_cost(); // calcule W aussi - double get_power() const { return W; } - - void power(); -}; -#endif +/* +This unit takes one input stream and divides in two or more +output streams. The pressure and temparature of output streams +are the same as the input's. +(ref : McCabe, Smith & Harriott) + +Structure in the .process file: +pump {name} {index of input stream} {index of output stream} {output pressure in atm} {efficiency, between 0 and 1} + +How to use: + 1- Call the constructor: pump1 = new pump(in, out); + 2- Set conditions: pump1->set(P_output, efficiency); + 3- Set the name: pump1->set(name); + 4- Solve: pump1->solve(); +*/ +#ifndef PUMP_H +#define PUMP_H + +#include "stream.hpp" +using namespace std; + +class pump +{ +private: + int i, j, n; + double state, tmp, tmp1; + bool success; + string name; + stream *in; //pointer to input stream + stream *out; //pointer to output stream + +public: + double P, W, eta; //output presure in atm, work in kW and efficiency + pump(stream* s1, stream* s2) {in=s1; out=s2; success=true; W=0.0; n=0; tmp=0.0;} + ~pump(){} + void set(double p, double e){P = p; eta = e; state=in->quality();} + void set(const string & n) { name = n; } + bool solve(); //finds the temperature and computes mass balance + void write(); + void cost(); + double get_cost(); // calcule W aussi + double get_power() const { return W; } + + void power(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.cpp index ee658e5b654b82ee3560805b5a519f44cbc97a14..9eaafc1a52eb29cacd9e13768a770b8b28d8465c 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.cpp @@ -1,204 +1,204 @@ -#include "reaction.hpp" -using namespace std; - - -int reaction::find_chemical ( const string & chem_name ) const { - for ( int i = 0 ; i < m ; i++ ) - if ( list[i]->CAS == chem_name ) - return i; - return -1; -} - -// donnees hardcodees -reaction::reaction ( const string & in1 , int dim , chemical ** in2 ) { - - m = dim; // nbre de chemicals - list = in2; // liste des chemicals - - n = new double[m]; - safe_n = new double[m]; - safe_a = new double[m]; - a = new double[m]; - - int i , j; - for ( i = 0 ; i < m ; i++ ) { - a[i]=0.0; - n[i]=0.0; - } - - // 1/5 : - if ( in1 == "eb2sty" ) { - k0 = 3.525e5; - E = 90.85; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10a\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10b\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("100-42-5")) < 0 ) { - cout << "ERROR 10c\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 2/5 : - else if ( in1 == "sty2eb" ) { - k0 = 2.754e-4; - E = -18.653; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10d\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10e\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("100-42-5")) < 0 ) { - cout << "ERROR 10f\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - } - - // 3/5 : - else if ( in1 == "eb2bz" ) { - k0 = 9.577e4; - E = 111.375; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10g\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("71-43-2")) < 0 ) { - cout << "ERROR 10h\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-85-1")) < 0 ) { - cout << "ERROR 10i\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 4/5 : - else if ( in1 == "eb2tol" ) { - k0 = 6.077e8; - E = 207.850; - if ( (j = find_chemical ("100-41-4")) < 0 ) { - cout << "ERROR 10j\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10k\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("108-88-3")) < 0 ) { - cout << "ERROR 10l\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-82-8")) < 0 ) { - cout << "ERROR 10m\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - - // 5/5 : - else if ( in1 == "tol2bz" ) { - k0 = 1; - E = 19.038; - if ( (j = find_chemical ("1333-74-0")) < 0 ) { - cout << "ERROR 10n\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 0.5; - if ( (j = find_chemical ("108-88-3")) < 0 ) { - cout << "ERROR 10o\n\n"; - exit(0); - } - a[j] = -1; - n[j] = 1; - if ( (j = find_chemical ("71-43-2")) < 0 ) { - cout << "ERROR 10p\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - if ( (j = find_chemical ("74-82-8")) < 0 ) { - cout << "ERROR 10q\n\n"; - exit(0); - } - a[j] = 1; - n[j] = 0; - } - else { - cout << "ERROR 12\n\n"; - exit(0); - } - - for ( i = 0 ; i < m ; i++ ) { - safe_n[i]=n[i]; - safe_a[i]=a[i]; - } -} - -reaction::~reaction() { - delete [] a; - delete [] n; - delete [] safe_n; - delete [] safe_a; -} - -double reaction::dHr(double T) -{ - int i , j; - for (i=0;i<m;i++) - if(safe_a[i]!=a[i]) - { - if(a[i]>safe_a[i]) a[i]=safe_a[i]; - else safe_a[i]=a[i]; - } - double tmp=0.0; - for (i=0;i<m;i++) tmp += a[i]*list[i]->Ho; - if(fabs(T-298)>EPS) - for (i=0;i<m;i++) - for (j=1;j<=4;j++) tmp += a[i]*list[i]->Cp_param[j-1]*(pow(T,j)-pow(298.0,j))/j/1000.0; - return tmp; -} - -double reaction::rate(double T, double* C) -{ - double tmp = k0*exp(-1000*E/8.3144/T); - for ( int i=0;i<m;i++) - { - if(safe_n[i]!=n[i]) n[i]=safe_n[i]; - if(C[i]>EPS && fabs(n[i])>EPS) tmp *= pow(C[i], n[i]); - } - return tmp; -} +#include "reaction.hpp" +using namespace std; + + +int reaction::find_chemical ( const string & chem_name ) const { + for ( int i = 0 ; i < m ; i++ ) + if ( list[i]->CAS == chem_name ) + return i; + return -1; +} + +// donnees hardcodees +reaction::reaction ( const string & in1 , int dim , chemical ** in2 ) { + + m = dim; // nbre de chemicals + list = in2; // liste des chemicals + + n = new double[m]; + safe_n = new double[m]; + safe_a = new double[m]; + a = new double[m]; + + int i , j; + for ( i = 0 ; i < m ; i++ ) { + a[i]=0.0; + n[i]=0.0; + } + + // 1/5 : + if ( in1 == "eb2sty" ) { + k0 = 3.525e5; + E = 90.85; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10a\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10b\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("100-42-5")) < 0 ) { + cout << "ERROR 10c\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 2/5 : + else if ( in1 == "sty2eb" ) { + k0 = 2.754e-4; + E = -18.653; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10d\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10e\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("100-42-5")) < 0 ) { + cout << "ERROR 10f\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + } + + // 3/5 : + else if ( in1 == "eb2bz" ) { + k0 = 9.577e4; + E = 111.375; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10g\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("71-43-2")) < 0 ) { + cout << "ERROR 10h\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-85-1")) < 0 ) { + cout << "ERROR 10i\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 4/5 : + else if ( in1 == "eb2tol" ) { + k0 = 6.077e8; + E = 207.850; + if ( (j = find_chemical ("100-41-4")) < 0 ) { + cout << "ERROR 10j\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10k\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("108-88-3")) < 0 ) { + cout << "ERROR 10l\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-82-8")) < 0 ) { + cout << "ERROR 10m\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + + // 5/5 : + else if ( in1 == "tol2bz" ) { + k0 = 1; + E = 19.038; + if ( (j = find_chemical ("1333-74-0")) < 0 ) { + cout << "ERROR 10n\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 0.5; + if ( (j = find_chemical ("108-88-3")) < 0 ) { + cout << "ERROR 10o\n\n"; + exit(0); + } + a[j] = -1; + n[j] = 1; + if ( (j = find_chemical ("71-43-2")) < 0 ) { + cout << "ERROR 10p\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + if ( (j = find_chemical ("74-82-8")) < 0 ) { + cout << "ERROR 10q\n\n"; + exit(0); + } + a[j] = 1; + n[j] = 0; + } + else { + cout << "ERROR 12\n\n"; + exit(0); + } + + for ( i = 0 ; i < m ; i++ ) { + safe_n[i]=n[i]; + safe_a[i]=a[i]; + } +} + +reaction::~reaction() { + delete [] a; + delete [] n; + delete [] safe_n; + delete [] safe_a; +} + +double reaction::dHr(double T) +{ + int i , j; + for (i=0;i<m;i++) + if(safe_a[i]!=a[i]) + { + if(a[i]>safe_a[i]) a[i]=safe_a[i]; + else safe_a[i]=a[i]; + } + double tmp=0.0; + for (i=0;i<m;i++) tmp += a[i]*list[i]->Ho; + if(fabs(T-298)>EPS) + for (i=0;i<m;i++) + for (j=1;j<=4;j++) tmp += a[i]*list[i]->Cp_param[j-1]*(pow(T,j)-pow(298.0,j))/j/1000.0; + return tmp; +} + +double reaction::rate(double T, double* C) +{ + double tmp = k0*exp(-1000*E/8.3144/T); + for ( int i=0;i<m;i++) + { + if(safe_n[i]!=n[i]) n[i]=safe_n[i]; + if(C[i]>EPS && fabs(n[i])>EPS) tmp *= pow(C[i], n[i]); + } + return tmp; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.hpp index f05b27e4589a1e0443a3911532d8f8b4e7f6caeb..1456e0d2bf24b59b66a76788fd8fdfa7ed5d6672 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/reaction.hpp @@ -1,32 +1,32 @@ -#ifndef REACTION_H -#define REACTION_H - -#include "chemical.hpp" -using namespace std; - -class reaction { -private: - - int m; - double *n, k0, E, Hr, *safe_n, *safe_a; - // double tmp; -// char file[41], line[31]; - chemical ** list; -// ifstream in; - // ofstream logf; - // terminator *end; - - int find_chemical ( const string & chem_name ) const; - -public: - // reaction(){}; - reaction ( const string & , int , chemical ** ); - ~reaction(); - double *a; //contains the molar coefficients - double dHr(double); //returns heat of rection at T, in kJ/mol - double rate(double, double*); //returns rate of reaction aT and C[], in mol/s.m3 - -// void show_name(){cout<<name;} -}; - -#endif +#ifndef REACTION_H +#define REACTION_H + +#include "chemical.hpp" +using namespace std; + +class reaction { +private: + + int m; + double *n, k0, E, Hr, *safe_n, *safe_a; + // double tmp; +// char file[41], line[31]; + chemical ** list; +// ifstream in; + // ofstream logf; + // terminator *end; + + int find_chemical ( const string & chem_name ) const; + +public: + // reaction(){}; + reaction ( const string & , int , chemical ** ); + ~reaction(); + double *a; //contains the molar coefficients + double dHr(double); //returns heat of rection at T, in kJ/mol + double rate(double, double*); //returns rate of reaction aT and C[], in mol/s.m3 + +// void show_name(){cout<<name;} +}; + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.cpp index 0f0ddae03673fe3ccd6ad46ef92158393d835e32..7f6e3a9455b13cecce0397ef8540e84a8a3d46f7 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.cpp @@ -1,100 +1,100 @@ -#include "reactor.hpp" -using namespace std; - -template<class TYPE> -reactor<TYPE>::reactor(stream* s1, stream* s2) -{ - in = s1; - out = s2; - - model = NULL; -} - -template<class TYPE> -reactor<TYPE>::~reactor() { - for ( i = 0 ; i < n ; i++ ) - delete rx[i]; - delete [] rx; - for ( i = 0 ; i < m ; i++ ) - delete table[i]; - delete [] table; - - if (model) - delete model; -} - -template<class TYPE> -void reactor<TYPE>::set ( double l , double d , int nb , const string * list_rx ) { - m = in->nb; - n = nb; - L = l; - D = d; - V = pi*pow(D/2.0, 2)*L; - - double * yields = new double [n]; - - rx = new reaction * [n]; - for ( j = 0 ; j < n ; j++ ) - rx[j] = new reaction ( list_rx[j] , m , in->chem ); - - table = new double * [m]; - for ( i = 0 ; i < m ; i++ ) - table[i] = new double[n]; - for ( j = 0 ; j < n ; j++ ) - for ( i = 0 ; i < m ; i++ ) - table[i][j] = rx[j]->a[i]; - for ( j = 0 ; j < n ; j++ ) { - yields[j]=0.0; - for ( i = 0 ; i < m ; i++ ) - if ( table[i][j] < 0 ) { - yields[j]=in->chem[i]->n(); - i=m; - } - } - - delete [] yields; - -} - -template<class TYPE> -bool reactor<TYPE>::solve() { - - if (model) - delete model; - model = new TYPE(in, out, table, n, rx, U, Ta); - model->set(name); - model->set(L,D); - - success = model->run(); - - // if(fabs(in->m-out->m)>sqrt(EPS)) - // { - // log.open(MESSAGES, ios::app); - // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(in->m-out->m)/in->m<<").\n"; - // log.close(); - // } - - - // out->write(); // WRITE TOTO - - return success; -} - -template<class TYPE> -void reactor<TYPE>::write ( void ) { - - cout << setprecision(6); - - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout << "\t>> " << name; - cout << endl << "\t>> stream in : " << in->name; - cout << endl << "\t>> stream out : " << out->name; - cout << endl << "\t>> P = " << in->P - << " atm, T(in) = " << in->T << ", T(out) = " << out->T << " K"; - cout << endl << "\t>> L = " << L << ", D = " << D << " m"; - if (success) - cout << " (converge normally)"; - cout << "\n\tEND\n\n"; - model->cost(); - model->water(); -} +#include "reactor.hpp" +using namespace std; + +template<class TYPE> +reactor<TYPE>::reactor(stream* s1, stream* s2) +{ + in = s1; + out = s2; + + model = NULL; +} + +template<class TYPE> +reactor<TYPE>::~reactor() { + for ( i = 0 ; i < n ; i++ ) + delete rx[i]; + delete [] rx; + for ( i = 0 ; i < m ; i++ ) + delete table[i]; + delete [] table; + + if (model) + delete model; +} + +template<class TYPE> +void reactor<TYPE>::set ( double l , double d , int nb , const string * list_rx ) { + m = in->nb; + n = nb; + L = l; + D = d; + V = pi*pow(D/2.0, 2)*L; + + double * yields = new double [n]; + + rx = new reaction * [n]; + for ( j = 0 ; j < n ; j++ ) + rx[j] = new reaction ( list_rx[j] , m , in->chem ); + + table = new double * [m]; + for ( i = 0 ; i < m ; i++ ) + table[i] = new double[n]; + for ( j = 0 ; j < n ; j++ ) + for ( i = 0 ; i < m ; i++ ) + table[i][j] = rx[j]->a[i]; + for ( j = 0 ; j < n ; j++ ) { + yields[j]=0.0; + for ( i = 0 ; i < m ; i++ ) + if ( table[i][j] < 0 ) { + yields[j]=in->chem[i]->n(); + i=m; + } + } + + delete [] yields; + +} + +template<class TYPE> +bool reactor<TYPE>::solve() { + + if (model) + delete model; + model = new TYPE(in, out, table, n, rx, U, Ta); + model->set(name); + model->set(L,D); + + success = model->run(); + + // if(fabs(in->m-out->m)>sqrt(EPS)) + // { + // log.open(MESSAGES, ios::app); + // log<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(in->m-out->m)/in->m<<").\n"; + // log.close(); + // } + + + // out->write(); // WRITE TOTO + + return success; +} + +template<class TYPE> +void reactor<TYPE>::write ( void ) { + + cout << setprecision(6); + + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout << "\t>> " << name; + cout << endl << "\t>> stream in : " << in->name; + cout << endl << "\t>> stream out : " << out->name; + cout << endl << "\t>> P = " << in->P + << " atm, T(in) = " << in->T << ", T(out) = " << out->T << " K"; + cout << endl << "\t>> L = " << L << ", D = " << D << " m"; + if (success) + cout << " (converge normally)"; + cout << "\n\tEND\n\n"; + model->cost(); + model->water(); +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.hpp index 78f936fe00e0bf1fd35f0487f3e8eb8e295a84a5..af0d2810711e78ab8b2a3dcee4cde090396f2c58 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/reactor.hpp @@ -1,48 +1,48 @@ -/* -This unit simulates a chemical reactor. Actually, only the pfr can be used. -(ref : Fogler). - -Structure in the .process file: -reactor {name} {pfr or cstr} {index of input stream} {index of output stream} {length in m} {diameter in m} {nb_react, list of reactions occuring} {U in kW/m2.K}{Ta in K} - -How to use: - 1- Call the constructor : react = new reactor<pfr or cstr>(in, out); - 2- Set dimensions and reactions : react->set(length, diameter, nb_react, list_react); //list_react is the list of reactions names - 3- Set cooling parameters : react->set(U, Ta); - 4- Set the name : react->set(name); - 5- Run the model: react->solve(); -*/ -#ifndef REACTOR_H -#define REACTOR_H - -#include "pfr.hpp" -using namespace std; - -template<class TYPE> -class reactor { -private: - // ofstream log; - bool success; - string name; - int i ,j, m, n; - double V, L, D, U, Ta; - stream *in, *out; - TYPE *model; - reaction ** rx; - double ** table; - -public: - // reactor(){}; - reactor(stream*, stream*); - void set( const string & n) { name = n; } - void set(double, double, int, const string * ); - void set(double u, double ta) {U=u;Ta=ta;} - bool solve(); - void write(); - - double get_cost ( void ) const { return model->get_cost() ; } - double get_water ( void ) const { return model->get_water(); } - - ~reactor(); -}; -#endif +/* +This unit simulates a chemical reactor. Actually, only the pfr can be used. +(ref : Fogler). + +Structure in the .process file: +reactor {name} {pfr or cstr} {index of input stream} {index of output stream} {length in m} {diameter in m} {nb_react, list of reactions occuring} {U in kW/m2.K}{Ta in K} + +How to use: + 1- Call the constructor : react = new reactor<pfr or cstr>(in, out); + 2- Set dimensions and reactions : react->set(length, diameter, nb_react, list_react); //list_react is the list of reactions names + 3- Set cooling parameters : react->set(U, Ta); + 4- Set the name : react->set(name); + 5- Run the model: react->solve(); +*/ +#ifndef REACTOR_H +#define REACTOR_H + +#include "pfr.hpp" +using namespace std; + +template<class TYPE> +class reactor { +private: + // ofstream log; + bool success; + string name; + int i ,j, m, n; + double V, L, D, U, Ta; + stream *in, *out; + TYPE *model; + reaction ** rx; + double ** table; + +public: + // reactor(){}; + reactor(stream*, stream*); + void set( const string & n) { name = n; } + void set(double, double, int, const string * ); + void set(double u, double ta) {U=u;Ta=ta;} + bool solve(); + void write(); + + double get_cost ( void ) const { return model->get_cost() ; } + double get_water ( void ) const { return model->get_water(); } + + ~reactor(); +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.cpp index 79e5d049cd839cf672a3eb71e48c6d976119c25f..e8582e03da28e148ba43074dbff9b4e4a5ad4069 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.cpp @@ -1,47 +1,47 @@ -#include "secant.hpp" -using namespace std; - -template <class E> -secant<E>::secant() -{ - x_last=0; - x_now=0; - x_next=0; - f_last=0; - f_now=0; - OK=false; -} - -template <class E> -void secant<E>::set(E* tmp, double x1, double x2) -{ - unit=tmp; - x_last=x1; - x_now=x2; - OK=false; -} - -template <class E> -bool secant<E>::run() -{ - // if(DEBUG) cout<<endl<<"begin solve secant"; - f_last = unit->f(x_last); - for (i=1; i<MAX_ITER_SECANT; i++) - { - f_now = unit->f(x_now); - // if(DEBUG) cout<<endl<<" x = "<<x_now<<" f(x) = "<<f_now; - x_next = x_now - (f_now*(x_now-x_last)/(f_now-f_last)); - if (fabs((x_next-x_now)/x_now)<=TOL_SECANT) - { - i=MAX_ITER_SECANT; - OK=true; - } - else - { - x_last=x_now; - f_last=f_now; - x_now=x_next; - } - } - return OK; -} +#include "secant.hpp" +using namespace std; + +template <class E> +secant<E>::secant() +{ + x_last=0; + x_now=0; + x_next=0; + f_last=0; + f_now=0; + OK=false; +} + +template <class E> +void secant<E>::set(E* tmp, double x1, double x2) +{ + unit=tmp; + x_last=x1; + x_now=x2; + OK=false; +} + +template <class E> +bool secant<E>::run() +{ + // if(DEBUG) cout<<endl<<"begin solve secant"; + f_last = unit->f(x_last); + for (i=1; i<MAX_ITER_SECANT; i++) + { + f_now = unit->f(x_now); + // if(DEBUG) cout<<endl<<" x = "<<x_now<<" f(x) = "<<f_now; + x_next = x_now - (f_now*(x_now-x_last)/(f_now-f_last)); + if (fabs((x_next-x_now)/x_now)<=TOL_SECANT) + { + i=MAX_ITER_SECANT; + OK=true; + } + else + { + x_last=x_now; + f_last=f_now; + x_now=x_next; + } + } + return OK; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.hpp index d1bb096e5c0267e24add5f95f58caa6523caa3ee..a04cbc542af177484e56bbaa924df887a2c2cdc4 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/secant.hpp @@ -1,31 +1,31 @@ -/* -To use the secant solver to find the root of a scalar function: - (the parametric object E must have public function such as E->f(x), - where x is the point at which evaluate f.) - 1- construct the solver : solver = new secant<E>(); - 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are two required initial points - 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed -*/ -#ifndef SECANT_H -#define SECANT_H - -#include "defines.hpp" -using namespace std; - - -template <class E> -class secant { -private: - double x_last, x_now, x_next; - double f_last, f_now, error; - int i; - bool OK; - E *unit; - -public: - secant(); - void set(E*, double, double); - bool run(); - ~secant(){} -}; -#endif +/* +To use the secant solver to find the root of a scalar function: + (the parametric object E must have public function such as E->f(x), + where x is the point at which evaluate f.) + 1- construct the solver : solver = new secant<E>(); + 2- set the solver : solver->set(unit, x0, x1); //unit is usually the pointer *this, and x0 and x1 are two required initial points + 3- launch the solver : bool = solver->run(); //will return true is success, false if the solver failed +*/ +#ifndef SECANT_H +#define SECANT_H + +#include "defines.hpp" +using namespace std; + + +template <class E> +class secant { +private: + double x_last, x_now, x_next; + double f_last, f_now, error; + int i; + bool OK; + E *unit; + +public: + secant(); + void set(E*, double, double); + bool run(); + ~secant(){} +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.cpp index 0b2df2008515f202bf61bc495dc205e53d345e4d..75216ae65c7d270cc5ec7d40495dd7eac8e31163 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.cpp @@ -1,538 +1,538 @@ -#include "servor.hpp" -#include "reactor.cpp" -using namespace std; - -/*---------------------------------------------------------------------*/ -servor::servor ( int nb_u , int n2 , stream ** streams ) { - nb = nb_u; - nb_s = n2; - type = new string[nb]; - name = new string[nb]; - s = streams; - - -// for (int i=0; i<nb; i++) -// { -// type[i]=new char[31]; -// name[i]=new char[31]; -// } -// cursor=0; -// s = s_list; -// // end = new terminator("\0"); -// mix1=NULL; -// split1=NULL; -// flash1=NULL; -// pump1=NULL; -// col=NULL; -// react_pfr=NULL; -// react_cstr=NULL; -// heat=NULL; - - burn = new burner ( s[0]->nb , s[0]->chem ); -} - -/*---------------------------------------------------------------------*/ -servor::~servor() { - delete [] type; - delete [] name; - delete burn; -} - -/*---------------------------------------------------------------------*/ -bool servor::solve_process ( const double * x , double * y ) { - - - for ( i = 0 ; i < 8 ; i++ ) - costs[i] = 0.0; - - k = 0; - norm = 1.0 / TOL_WEGSTEIN; - - for ( cursor = 0 ; cursor < nb ; cursor++ ) { - - if (type[cursor] == "mix" ) { - do_mix_process(x); - } - else if ( type[cursor] == "split" ) { - do_split_process(x); - } - else if ( type[cursor] == "flash" ) { - do_flash_process(x); - } - else if ( type[cursor] == "pump" ) { - do_pump_process(x); - } - else if ( type[cursor] == "heatx") { - do_heatx_process(x); - } - else if ( type[cursor] == "burner" ) { - do_burner_process(x,y); - } - else if ( type[cursor] == "column" ) { - do_column_process(x,y); - } - else if ( type[cursor] == "reactor" ) { - do_reactor_process(x); - } - else if ( type[cursor] == "loop" ) { - - recycle = 10; - end_recycle = 0; - do_loop_process(x); - } - else { - cout << "ERROR 18\n\n"; - exit(0); - } - - } - - return true; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_loop_process ( const double * x ) { - - // structure in the input file : - // loop - // name : "looping" - // index of recycle stream : 11 - // index of stream's beginning block : 7 - // index of stream's end block : 1 - - // TOTO -// if (k==0) -// cout << endl << " -> Wegstein iterations "; -// else if ( k <= 2 ) -// cout << endl << " -> loop " << setw(3) << k; -// else -// cout << endl << " -> loop " << setw(3) << k << " > error " << norm; - - // Get the two fisrst points - if ( k==0 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) - x_last[i] = s[recycle]->chem[i]->m; - end_loop = false; - } - - if ( k==1 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) { - x_now [i] = s[recycle]->chem[i]->m; - g_last[i] = s[recycle]->chem[i]->m; - } - - end_loop = false; - } - - if ( k == 2 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) - g_now[i] = s[recycle]->chem[i]->m; - end_loop=false; - } - k++; - - - // run the Wegstein algorithm - if ( k > 2 ) { - for ( i = 0 ; i < s[0]->nb ; i++ ) { - g_now[i] = s[recycle]->chem[i]->m; - - if ( fabs (x_now[i]-x_last[i]) > EPS ) - slope[i] = ( g_now[i] - g_last[i] ) / ( x_now[i] - x_last[i] ); - else - slope[i] = 0; - - theta[i] = 1.0 / (1.0-slope[i]); - if ( theta[i] < MIN_THETA ) - theta[i] = MIN_THETA; - if ( theta[i] > MAX_THETA ) - theta[i] = MAX_THETA; - x_next[i] = (1.0-theta[i])*x_now[i] + theta[i]*g_now[i]; - } - norm = 0.0; - for ( i = 0 ; i < s[0]->nb ; i++ ) - if ( fabs(x_now[i]) > EPS ) - norm += fabs (x_next[i]-x_now[i]) / fabs(x_now[i]); - - if ( norm > TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) { - s[recycle]->m = 0.0; - for ( i = 0 ; i < s[0]->nb ; i++ ) { - s[recycle]->chem[i]->m = x_next[i]; - s[recycle]->m += x_next[i]; - x_last[i] = x_now[i]; - g_last[i] = g_now[i]; - x_now[i] = x_next[i]; - } - end_loop=false; - } - if ( norm <= TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) - end_loop = true; - - } - - - if ( end_loop ) { - if ( k < MAX_ITER_WEGSTEIN && k > 3 ) { - // cout<<" OK"; // TOTO - // s[recycle]->write(); // WRITE TOTO - -// // WRITE TOTO : -// cout << "WRITE FILE " << RUNTIME << name[cursor] << ".unit" << " :\n\tBEGIN\n"; -// cout << "\t>> " << name[cursor]; -// cout << endl << "\t>> from block " << cursor+1 << " to block " << end_recycle+1; -// cout << endl << "\t>> Wegstein converged in " -// << k << " iterations (rel. err. " << norm << ")."; -// cout << "\n\tEND\n\n"; - - k = 0; - norm = 1.0/TOL_WEGSTEIN; - } -// else { -// log.open(MESSAGES, ios::app); -// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; -// log.close(); -// } - } - - - if ( !end_loop && k < MAX_ITER_WEGSTEIN ) - cursor = end_recycle-1; - if ( !end_loop && k==MAX_ITER_WEGSTEIN ) { -// log.open(MESSAGES, ios::app); -// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; -// log.close(); - k=0; - norm = 1.0/TOL_WEGSTEIN; - cursor=nb; - } - -} - -/*---------------------------------------------------------------------*/ -void servor::do_burner_process ( const double * x , double * y ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - // read parameters : - int i1 = 8; - int i2 = 13; - double f = x[6]; - - burn->set ( s[i1-1] , s[i2-1] ); - burn->set(f); - burn->set(name[cursor]); - - if ( burn->solve(y) ) { - // cout << "OK"; // TOTO - // burn->write(); // WRITE TOTO - costs[7] = burn->get_cost(); - } - else { - cout << "ERROR 20\n\n"; - exit(0); - } -} - -/*---------------------------------------------------------------------*/ -void servor::do_split_process ( const double * x ) -{ - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - int i1 = 9; - int i2 = 2; - int i_tab[2] = { 10 , 11 }; - double f_tab[2]; - f_tab[0] = x[5]; - f_tab[1] = 1-x[5]; - - stream * list1[2]; - list1[0] = s[i_tab[0]-1]; - list1[1] = s[i_tab[1]-1]; - - split * split1 = new split ( i2 , s[i1-1] , list1 ); - - split1->set(f_tab); - split1->set(name[cursor]); - if ( split1->solve() ) { - // cout<<"OK"; // TOTO - // split1->write(); // WRITE TOTO - } - else { - cout << "ERROR 19\n\n"; - exit(0); - } - delete split1; -} - -/*---------------------------------------------------------------------*/ -void servor::do_column_process ( const double * x , double * y ) { - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - double f1 , f2; - int i , i1 , i2; - int i_tab[2]; - double f = 1.0; - - if (name[cursor]=="sep-sty") { - i = 7; - i1 = 15; - i2 = 9; - i_tab[0] = 1; - i_tab[1] = 7; - f1 = f2 = x[2]; - } - else if (name[cursor]=="sep-bz") { - i = 10; - i1 = 12; - i2 = 14; - i_tab[0] = 5; - i_tab[1] = 1; - f1 = f2 = x[3]; - } - else { - cout << "ERROR 17\n\n"; - exit(0); - } - - column * col = new column ( s[i-1] , s[i1-1] , s[i2-1] ); - col->set ( f , i_tab[0] , f1 , i_tab[1] , f2 ); - col->set(name[cursor]); - if ( col->solve() ) { - //cout<<"OK"; // TOTO - //col->write(); // WRITE TOTO - - if (name[cursor]=="sep-sty") { - y[4] = col->get_N(); - costs[5] = col->get_cost(); - power[5] = col->get_power(); - water[5] = col->get_water(); - } - else { - y[5] = col->get_N(); - costs[6] = col->get_cost(); - power[4] = col->get_power(); - water[4] = col->get_water(); - } - } - else { - cout << "ERROR 15\n\n"; - exit(0); - } - delete col; -} - -/*---------------------------------------------------------------------*/ -void servor::do_flash_process ( const double * x ) { - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters - double f1 = 1.0; - double f2 = x[7]; - // int i_tab [3] = { 6 , 7 , 8 }; - // flash * flash1 = new flash ( s[i_tab[0]-1] , s[i_tab[1]-1] , s[i_tab[2]-1] ); - flash * flash1 = new flash ( s[5] , s[6] , s[7] ); - - flash1->set(f1, f2); - flash1->set(name[cursor]); - if ( flash1->solve() ) { - // cout<<"OK"; // TOTO - // flash1->write(); // WRITE TOTO - costs[4] = flash1->get_cost(); - power[2] = flash1->get_power(); - water[1] = flash1->get_water(); - } - else { - cout << "ERROR 14\n\n"; - exit(0); - } - delete flash1; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_mix_process ( const double * x ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - // Read parameters (hardcode avec eb2sty.process) : - double f1 = 1.0; - int i1 = 3; - int i_tab[3] = { 1 , 12 , 11 }; - int i2 = 2; - - // We can solve the unit - stream * list2 = s[i2-1] , ** list1 = new stream * [i1]; - for ( int i = 0 ; i < i1 ; i++ ) - list1[i] = s[i_tab[i]-1]; - mix * mix1 = new mix ( i1 , list1 , list2 ); - mix1->set(f1); - mix1->set(name[cursor]); - if (mix1->solve()) { - // cout<<"OK"; // TOTO - // mix1->write(); // WRITE TOTO - } - else { - cout << "ERROR 6\n\n"; - exit(0); - } - delete mix1; - delete [] list1; -} - - -/*---------------------------------------------------------------------*/ -void servor::do_pump_process ( const double * x ) { - - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - //Read parameters (hardcode avec eb2sty.process) : - int i1 = 2; - int i2 = 3; - double f1 = x[4]; - double f2 = 0.75; - - pump * pump1 = new pump ( s[i1-1] , s[i2-1] ); - pump1->set(f1,f2); - pump1->set(name[cursor]); - - - - // solve : - if ( pump1->solve() ) { - // cout<<"OK"; // TOTO - // pump1->write(); // WRITE TOTO - - power[0] = pump1->get_power(); - costs[0] = pump1->get_cost(); - } - else { - cout << "ERROR 7\n\n"; - exit(0); - } - - delete pump1; -} - -/*---------------------------------------------------------------------*/ -void servor::do_heatx_process ( const double * x ) { - - // cout << endl << " -- " << name[cursor] << "... "; // TOTO - - //Read parameters (idem) : - - bool b = false; - - // heater : - int i1; - int i2; - double f1; - - // heater : - if (name[cursor]=="heater") { - i1 = 3; - i2 = 4; - f1 = x[0]; - } - - // cooler : - else if (name[cursor]=="cooler") { - i1 = 5; - i2 = 6; - f1 = x[7]; - } - else { - cout << "ERROR 16\n\n"; - exit(0); - } - - double f2 = 0.85; - - // solve : - heatx * heat = new heatx ( b , s[i1-1] , s[i2-1] ); - heat->set(f1,f2); - heat->set(name[cursor]); - if (heat->solve()) { - // cout<<"OK"; // TOTO - // heat->write(); // WRITE TOTO - if (name[cursor]=="heater") { - costs[1] = heat->get_cost(); - power[3] = heat->get_power(); - water[2] = heat->get_water(); - } - else { - costs[3] = heat->get_cost(); - power[1] = heat->get_power(); - water[0] = heat->get_water(); - } - } - else { - cout << "ERROR 8\n\n"; - exit(0); - } - delete heat; -} - -/*---------------------------------------------------------------------*/ -void servor::do_reactor_process ( const double * x ) { - - // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO - - // Read parameters (idem) : - int i1 = 4; - int i2 = 5; - - reactor<pfr> * react_pfr = new reactor<pfr> ( s[i1-1] , s[i2-1] ); - - react_pfr->set(name[cursor]); - - double f1 = x[1]; - double f2 = 0.5; - - string list[5] = { "eb2sty" , "sty2eb" , "eb2bz" , "eb2tol" , "tol2bz" }; - - i1 = 5; - - react_pfr->set(f1,f2,i1,list); - - f1 = 0.0; - f2 = 300.0; - - react_pfr->set(f1,f2); - - if ( react_pfr->solve() ) { - // cout<<"OK"; // TOTO - // react_pfr->write(); // WRITE TOTO - costs[2] = react_pfr->get_cost(); - water[3] = react_pfr->get_water(); - } - else { - cout << "ERROR 9\n\n"; - exit(0); - } - delete react_pfr; -} - - -double servor::get_costs_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 8 ; i++ ) - sum += ( (ARRONDI) ? arrondi(costs[i],6) : costs[i] ); - return sum; -} - -double servor::get_power_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 6 ; i++ ) - sum += ( (ARRONDI) ? arrondi(power[i],6) : power[i] ); - return sum; -} - -double servor::get_water_sum ( void ) const { - double sum = 0.0; - for ( int i = 0 ; i < 6 ; i++ ) - sum += ( (ARRONDI) ? arrondi(water[i],6) : water[i] ); - return sum; -} +#include "servor.hpp" +#include "reactor.cpp" +using namespace std; + +/*---------------------------------------------------------------------*/ +servor::servor ( int nb_u , int n2 , stream ** streams ) { + nb = nb_u; + nb_s = n2; + type = new string[nb]; + name = new string[nb]; + s = streams; + + +// for (int i=0; i<nb; i++) +// { +// type[i]=new char[31]; +// name[i]=new char[31]; +// } +// cursor=0; +// s = s_list; +// // end = new terminator("\0"); +// mix1=NULL; +// split1=NULL; +// flash1=NULL; +// pump1=NULL; +// col=NULL; +// react_pfr=NULL; +// react_cstr=NULL; +// heat=NULL; + + burn = new burner ( s[0]->nb , s[0]->chem ); +} + +/*---------------------------------------------------------------------*/ +servor::~servor() { + delete [] type; + delete [] name; + delete burn; +} + +/*---------------------------------------------------------------------*/ +bool servor::solve_process ( const double * x , double * y ) { + + + for ( i = 0 ; i < 8 ; i++ ) + costs[i] = 0.0; + + k = 0; + norm = 1.0 / TOL_WEGSTEIN; + + for ( cursor = 0 ; cursor < nb ; cursor++ ) { + + if (type[cursor] == "mix" ) { + do_mix_process(x); + } + else if ( type[cursor] == "split" ) { + do_split_process(x); + } + else if ( type[cursor] == "flash" ) { + do_flash_process(x); + } + else if ( type[cursor] == "pump" ) { + do_pump_process(x); + } + else if ( type[cursor] == "heatx") { + do_heatx_process(x); + } + else if ( type[cursor] == "burner" ) { + do_burner_process(x,y); + } + else if ( type[cursor] == "column" ) { + do_column_process(x,y); + } + else if ( type[cursor] == "reactor" ) { + do_reactor_process(x); + } + else if ( type[cursor] == "loop" ) { + + recycle = 10; + end_recycle = 0; + do_loop_process(x); + } + else { + cout << "ERROR 18\n\n"; + exit(0); + } + + } + + return true; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_loop_process ( const double * x ) { + + // structure in the input file : + // loop + // name : "looping" + // index of recycle stream : 11 + // index of stream's beginning block : 7 + // index of stream's end block : 1 + + // TOTO +// if (k==0) +// cout << endl << " -> Wegstein iterations "; +// else if ( k <= 2 ) +// cout << endl << " -> loop " << setw(3) << k; +// else +// cout << endl << " -> loop " << setw(3) << k << " > error " << norm; + + // Get the two fisrst points + if ( k==0 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) + x_last[i] = s[recycle]->chem[i]->m; + end_loop = false; + } + + if ( k==1 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) { + x_now [i] = s[recycle]->chem[i]->m; + g_last[i] = s[recycle]->chem[i]->m; + } + + end_loop = false; + } + + if ( k == 2 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) + g_now[i] = s[recycle]->chem[i]->m; + end_loop=false; + } + k++; + + + // run the Wegstein algorithm + if ( k > 2 ) { + for ( i = 0 ; i < s[0]->nb ; i++ ) { + g_now[i] = s[recycle]->chem[i]->m; + + if ( fabs (x_now[i]-x_last[i]) > EPS ) + slope[i] = ( g_now[i] - g_last[i] ) / ( x_now[i] - x_last[i] ); + else + slope[i] = 0; + + theta[i] = 1.0 / (1.0-slope[i]); + if ( theta[i] < MIN_THETA ) + theta[i] = MIN_THETA; + if ( theta[i] > MAX_THETA ) + theta[i] = MAX_THETA; + x_next[i] = (1.0-theta[i])*x_now[i] + theta[i]*g_now[i]; + } + norm = 0.0; + for ( i = 0 ; i < s[0]->nb ; i++ ) + if ( fabs(x_now[i]) > EPS ) + norm += fabs (x_next[i]-x_now[i]) / fabs(x_now[i]); + + if ( norm > TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) { + s[recycle]->m = 0.0; + for ( i = 0 ; i < s[0]->nb ; i++ ) { + s[recycle]->chem[i]->m = x_next[i]; + s[recycle]->m += x_next[i]; + x_last[i] = x_now[i]; + g_last[i] = g_now[i]; + x_now[i] = x_next[i]; + } + end_loop=false; + } + if ( norm <= TOL_WEGSTEIN && k < MAX_ITER_WEGSTEIN ) + end_loop = true; + + } + + + if ( end_loop ) { + if ( k < MAX_ITER_WEGSTEIN && k > 3 ) { + // cout<<" OK"; // TOTO + // s[recycle]->write(); // WRITE TOTO + +// // WRITE TOTO : +// cout << "WRITE FILE " << RUNTIME << name[cursor] << ".unit" << " :\n\tBEGIN\n"; +// cout << "\t>> " << name[cursor]; +// cout << endl << "\t>> from block " << cursor+1 << " to block " << end_recycle+1; +// cout << endl << "\t>> Wegstein converged in " +// << k << " iterations (rel. err. " << norm << ")."; +// cout << "\n\tEND\n\n"; + + k = 0; + norm = 1.0/TOL_WEGSTEIN; + } +// else { +// log.open(MESSAGES, ios::app); +// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; +// log.close(); +// } + } + + + if ( !end_loop && k < MAX_ITER_WEGSTEIN ) + cursor = end_recycle-1; + if ( !end_loop && k==MAX_ITER_WEGSTEIN ) { +// log.open(MESSAGES, ios::app); +// log<<" ==> Error <== Wegstein algorithm did not converge.\n"; +// log.close(); + k=0; + norm = 1.0/TOL_WEGSTEIN; + cursor=nb; + } + +} + +/*---------------------------------------------------------------------*/ +void servor::do_burner_process ( const double * x , double * y ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + // read parameters : + int i1 = 8; + int i2 = 13; + double f = x[6]; + + burn->set ( s[i1-1] , s[i2-1] ); + burn->set(f); + burn->set(name[cursor]); + + if ( burn->solve(y) ) { + // cout << "OK"; // TOTO + // burn->write(); // WRITE TOTO + costs[7] = burn->get_cost(); + } + else { + cout << "ERROR 20\n\n"; + exit(0); + } +} + +/*---------------------------------------------------------------------*/ +void servor::do_split_process ( const double * x ) +{ + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + int i1 = 9; + int i2 = 2; + int i_tab[2] = { 10 , 11 }; + double f_tab[2]; + f_tab[0] = x[5]; + f_tab[1] = 1-x[5]; + + stream * list1[2]; + list1[0] = s[i_tab[0]-1]; + list1[1] = s[i_tab[1]-1]; + + split * split1 = new split ( i2 , s[i1-1] , list1 ); + + split1->set(f_tab); + split1->set(name[cursor]); + if ( split1->solve() ) { + // cout<<"OK"; // TOTO + // split1->write(); // WRITE TOTO + } + else { + cout << "ERROR 19\n\n"; + exit(0); + } + delete split1; +} + +/*---------------------------------------------------------------------*/ +void servor::do_column_process ( const double * x , double * y ) { + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + double f1 , f2; + int i , i1 , i2; + int i_tab[2]; + double f = 1.0; + + if (name[cursor]=="sep-sty") { + i = 7; + i1 = 15; + i2 = 9; + i_tab[0] = 1; + i_tab[1] = 7; + f1 = f2 = x[2]; + } + else if (name[cursor]=="sep-bz") { + i = 10; + i1 = 12; + i2 = 14; + i_tab[0] = 5; + i_tab[1] = 1; + f1 = f2 = x[3]; + } + else { + cout << "ERROR 17\n\n"; + exit(0); + } + + column * col = new column ( s[i-1] , s[i1-1] , s[i2-1] ); + col->set ( f , i_tab[0] , f1 , i_tab[1] , f2 ); + col->set(name[cursor]); + if ( col->solve() ) { + //cout<<"OK"; // TOTO + //col->write(); // WRITE TOTO + + if (name[cursor]=="sep-sty") { + y[4] = col->get_N(); + costs[5] = col->get_cost(); + power[5] = col->get_power(); + water[5] = col->get_water(); + } + else { + y[5] = col->get_N(); + costs[6] = col->get_cost(); + power[4] = col->get_power(); + water[4] = col->get_water(); + } + } + else { + cout << "ERROR 15\n\n"; + exit(0); + } + delete col; +} + +/*---------------------------------------------------------------------*/ +void servor::do_flash_process ( const double * x ) { + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters + double f1 = 1.0; + double f2 = x[7]; + // int i_tab [3] = { 6 , 7 , 8 }; + // flash * flash1 = new flash ( s[i_tab[0]-1] , s[i_tab[1]-1] , s[i_tab[2]-1] ); + flash * flash1 = new flash ( s[5] , s[6] , s[7] ); + + flash1->set(f1, f2); + flash1->set(name[cursor]); + if ( flash1->solve() ) { + // cout<<"OK"; // TOTO + // flash1->write(); // WRITE TOTO + costs[4] = flash1->get_cost(); + power[2] = flash1->get_power(); + water[1] = flash1->get_water(); + } + else { + cout << "ERROR 14\n\n"; + exit(0); + } + delete flash1; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_mix_process ( const double * x ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + // Read parameters (hardcode avec eb2sty.process) : + double f1 = 1.0; + int i1 = 3; + int i_tab[3] = { 1 , 12 , 11 }; + int i2 = 2; + + // We can solve the unit + stream * list2 = s[i2-1] , ** list1 = new stream * [i1]; + for ( int i = 0 ; i < i1 ; i++ ) + list1[i] = s[i_tab[i]-1]; + mix * mix1 = new mix ( i1 , list1 , list2 ); + mix1->set(f1); + mix1->set(name[cursor]); + if (mix1->solve()) { + // cout<<"OK"; // TOTO + // mix1->write(); // WRITE TOTO + } + else { + cout << "ERROR 6\n\n"; + exit(0); + } + delete mix1; + delete [] list1; +} + + +/*---------------------------------------------------------------------*/ +void servor::do_pump_process ( const double * x ) { + + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + //Read parameters (hardcode avec eb2sty.process) : + int i1 = 2; + int i2 = 3; + double f1 = x[4]; + double f2 = 0.75; + + pump * pump1 = new pump ( s[i1-1] , s[i2-1] ); + pump1->set(f1,f2); + pump1->set(name[cursor]); + + + + // solve : + if ( pump1->solve() ) { + // cout<<"OK"; // TOTO + // pump1->write(); // WRITE TOTO + + power[0] = pump1->get_power(); + costs[0] = pump1->get_cost(); + } + else { + cout << "ERROR 7\n\n"; + exit(0); + } + + delete pump1; +} + +/*---------------------------------------------------------------------*/ +void servor::do_heatx_process ( const double * x ) { + + // cout << endl << " -- " << name[cursor] << "... "; // TOTO + + //Read parameters (idem) : + + bool b = false; + + // heater : + int i1; + int i2; + double f1; + + // heater : + if (name[cursor]=="heater") { + i1 = 3; + i2 = 4; + f1 = x[0]; + } + + // cooler : + else if (name[cursor]=="cooler") { + i1 = 5; + i2 = 6; + f1 = x[7]; + } + else { + cout << "ERROR 16\n\n"; + exit(0); + } + + double f2 = 0.85; + + // solve : + heatx * heat = new heatx ( b , s[i1-1] , s[i2-1] ); + heat->set(f1,f2); + heat->set(name[cursor]); + if (heat->solve()) { + // cout<<"OK"; // TOTO + // heat->write(); // WRITE TOTO + if (name[cursor]=="heater") { + costs[1] = heat->get_cost(); + power[3] = heat->get_power(); + water[2] = heat->get_water(); + } + else { + costs[3] = heat->get_cost(); + power[1] = heat->get_power(); + water[0] = heat->get_water(); + } + } + else { + cout << "ERROR 8\n\n"; + exit(0); + } + delete heat; +} + +/*---------------------------------------------------------------------*/ +void servor::do_reactor_process ( const double * x ) { + + // cout<<endl<<" -- "<<name[cursor]<<"... "; // TOTO + + // Read parameters (idem) : + int i1 = 4; + int i2 = 5; + + reactor<pfr> * react_pfr = new reactor<pfr> ( s[i1-1] , s[i2-1] ); + + react_pfr->set(name[cursor]); + + double f1 = x[1]; + double f2 = 0.5; + + string list[5] = { "eb2sty" , "sty2eb" , "eb2bz" , "eb2tol" , "tol2bz" }; + + i1 = 5; + + react_pfr->set(f1,f2,i1,list); + + f1 = 0.0; + f2 = 300.0; + + react_pfr->set(f1,f2); + + if ( react_pfr->solve() ) { + // cout<<"OK"; // TOTO + // react_pfr->write(); // WRITE TOTO + costs[2] = react_pfr->get_cost(); + water[3] = react_pfr->get_water(); + } + else { + cout << "ERROR 9\n\n"; + exit(0); + } + delete react_pfr; +} + + +double servor::get_costs_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 8 ; i++ ) + sum += ( (ARRONDI) ? arrondi(costs[i],6) : costs[i] ); + return sum; +} + +double servor::get_power_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 6 ; i++ ) + sum += ( (ARRONDI) ? arrondi(power[i],6) : power[i] ); + return sum; +} + +double servor::get_water_sum ( void ) const { + double sum = 0.0; + for ( int i = 0 ; i < 6 ; i++ ) + sum += ( (ARRONDI) ? arrondi(water[i],6) : water[i] ); + return sum; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.hpp index e048542375b8df2942bfd10dd2117cfe6622b53c..73b1cd2ef8efb77cae3833eff494a03b00db71d8 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/servor.hpp @@ -1,101 +1,101 @@ -#ifndef SERVOR_H -#define SERVOR_H - -//Possible units -#include "mix.hpp" -#include "split.hpp" -#include "pump.hpp" -#include "column.hpp" -#include "reactor.hpp" -#include "heatx.hpp" -#include "burner.hpp" - -using namespace std; - -class servor { - -public: - - double norm; - int k; - int nb; - int nb_s; - string * type; - string * name; - int cursor; - stream ** s; - - int recycle; - int end_recycle; - int i; - bool end_loop; - - double x_last[MAX_DIM]; - double x_now [MAX_DIM]; - double x_next[MAX_DIM]; - double g_last[MAX_DIM]; - double g_now [MAX_DIM]; - double slope [MAX_DIM]; - double theta [MAX_DIM]; - - double costs[8]; - double power[6]; - double water[6]; - - - // clock_t beg_time, end_time; - // bool OK, b, solve_OK; - // char filename[31], kind[10], **list, process_name[31]; - // double f, f1, f2, f_tab[10], t; - // int i, i1, i2, i_tab[10], time; - // stream *list2; - -// double theta[MAX_DIM], slope[MAX_DIM], norm; -// bool end_loop; -// int k, recycle, end_recycle; -// char loop_name[31]; - -// mix *mix1; void do_mix(); -// split *split1; -// flash *flash1; void do_flash(); -// pump *pump1; void do_pump(); -// column *col; void do_column(); -// reactor<pfr> *react_pfr; void do_reactor(); -// reactor<cstr> *react_cstr; -// heatx *heat; void do_heatx(); - burner * burn; - -// stream *s; //list of streams -// friend void out_of_memory(void){exit(0);} - - - // constructeur : - servor ( int , int , stream ** ); - - // destructeur : - ~servor(); - - -// void set(int t) {time=t;} -// void set(char n[31]) {strcpy(process_name, n);} - void do_split_process ( const double * x ); - void do_column_process ( const double * x , double * y ); - void do_flash_process ( const double * x ); - void do_mix_process ( const double * x ); - void do_pump_process ( const double * x ); - void do_heatx_process ( const double * x ); - void do_reactor_process ( const double * x ); - void do_burner_process ( const double * x , double * y ); - void do_loop_process ( const double * x ); - - bool solve_process ( const double * x , double * y ); //main solver of the software. - - double get_costs_sum ( void ) const; - - double get_power_sum ( void ) const; - - double get_water_sum ( void ) const; - - -}; -#endif +#ifndef SERVOR_H +#define SERVOR_H + +//Possible units +#include "mix.hpp" +#include "split.hpp" +#include "pump.hpp" +#include "column.hpp" +#include "reactor.hpp" +#include "heatx.hpp" +#include "burner.hpp" + +using namespace std; + +class servor { + +public: + + double norm; + int k; + int nb; + int nb_s; + string * type; + string * name; + int cursor; + stream ** s; + + int recycle; + int end_recycle; + int i; + bool end_loop; + + double x_last[MAX_DIM]; + double x_now [MAX_DIM]; + double x_next[MAX_DIM]; + double g_last[MAX_DIM]; + double g_now [MAX_DIM]; + double slope [MAX_DIM]; + double theta [MAX_DIM]; + + double costs[8]; + double power[6]; + double water[6]; + + + // clock_t beg_time, end_time; + // bool OK, b, solve_OK; + // char filename[31], kind[10], **list, process_name[31]; + // double f, f1, f2, f_tab[10], t; + // int i, i1, i2, i_tab[10], time; + // stream *list2; + +// double theta[MAX_DIM], slope[MAX_DIM], norm; +// bool end_loop; +// int k, recycle, end_recycle; +// char loop_name[31]; + +// mix *mix1; void do_mix(); +// split *split1; +// flash *flash1; void do_flash(); +// pump *pump1; void do_pump(); +// column *col; void do_column(); +// reactor<pfr> *react_pfr; void do_reactor(); +// reactor<cstr> *react_cstr; +// heatx *heat; void do_heatx(); + burner * burn; + +// stream *s; //list of streams +// friend void out_of_memory(void){exit(0);} + + + // constructeur : + servor ( int , int , stream ** ); + + // destructeur : + ~servor(); + + +// void set(int t) {time=t;} +// void set(char n[31]) {strcpy(process_name, n);} + void do_split_process ( const double * x ); + void do_column_process ( const double * x , double * y ); + void do_flash_process ( const double * x ); + void do_mix_process ( const double * x ); + void do_pump_process ( const double * x ); + void do_heatx_process ( const double * x ); + void do_reactor_process ( const double * x ); + void do_burner_process ( const double * x , double * y ); + void do_loop_process ( const double * x ); + + bool solve_process ( const double * x , double * y ); //main solver of the software. + + double get_costs_sum ( void ) const; + + double get_power_sum ( void ) const; + + double get_water_sum ( void ) const; + + +}; +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/split.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/split.cpp index d3f48c90fb149e1ebdd627f3fa28b56c0f331bff..d14c519c6794b52ae69162e2455e248636ce0adc 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/split.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/split.cpp @@ -1,53 +1,53 @@ -#include "split.hpp" -using namespace std; - -split::split(int n, stream* s1, stream** s2) -{ - nb_out=n; - in = s1; - out= s2; - success = true; -} - -bool split::solve() -{ - tmp=0; - for (i=0;i<nb_out; i++) tmp+=frac[i]; - if(fabs(1-tmp)<=EPS) - { - success = true; - for (i=0; i<nb_out;i++) - { - out[i]->m=0; - for (j=0;j<in->nb;j++) - { - - out[i]->chem[j]->m = frac[i]*in->chem[j]->m; - out[i]->m += out[i]->chem[j]->m; - } - out[i]->set(in->P, in->T); - // out[i]->write(); // TOTO - } - } - tmp=0; for(i=0;i<nb_out;i++) tmp+=out[i]->m; - if(fabs(tmp-in->m)>EPS) - { -// logf.open(MESSAGES, ios::app); -// logf<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(tmp-in->m)/tmp<<").\n"; -// logf.close(); - success = false; - } - else success = true; - return success; -} - -void split::write() -{ - cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; - cout <<"\t>> "<<name; - cout << endl<<"\t>> stream in: "<<in->name;; - cout<<endl<<"\t>> streams out: "<<setprecision(3); - for ( i = 0 ; i < nb_out ; i++ ) - cout << out[i]->name<<" ("<<frac[i]<<") "; - cout << "\n\tEND\n\n"; -} +#include "split.hpp" +using namespace std; + +split::split(int n, stream* s1, stream** s2) +{ + nb_out=n; + in = s1; + out= s2; + success = true; +} + +bool split::solve() +{ + tmp=0; + for (i=0;i<nb_out; i++) tmp+=frac[i]; + if(fabs(1-tmp)<=EPS) + { + success = true; + for (i=0; i<nb_out;i++) + { + out[i]->m=0; + for (j=0;j<in->nb;j++) + { + + out[i]->chem[j]->m = frac[i]*in->chem[j]->m; + out[i]->m += out[i]->chem[j]->m; + } + out[i]->set(in->P, in->T); + // out[i]->write(); // TOTO + } + } + tmp=0; for(i=0;i<nb_out;i++) tmp+=out[i]->m; + if(fabs(tmp-in->m)>EPS) + { +// logf.open(MESSAGES, ios::app); +// logf<<" --> Warning <-- Block "<<name<<" is not in mass balance ("<<fabs(tmp-in->m)/tmp<<").\n"; +// logf.close(); + success = false; + } + else success = true; + return success; +} + +void split::write() +{ + cout << "WRITE FILE " << RUNTIME << name << ".unit" << " :\n\tBEGIN\n"; + cout <<"\t>> "<<name; + cout << endl<<"\t>> stream in: "<<in->name;; + cout<<endl<<"\t>> streams out: "<<setprecision(3); + for ( i = 0 ; i < nb_out ; i++ ) + cout << out[i]->name<<" ("<<frac[i]<<") "; + cout << "\n\tEND\n\n"; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/split.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/split.hpp index 2c75638072d6ed52d32f8d48d0c4970069655230..7634f470e968c8cda76ed0f9642e7bce2ff1a195 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/split.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/split.hpp @@ -1,43 +1,43 @@ -/* -This unit takes one input stream and divides in two or more -output streams. The pressure and temparature of output streams -are the same as the input's. - -Structure in the .process file: -split {name} {index of input stream} {nb_out} {indexes of output streams and fractions of input} - -How to use: - 1- Call the constructor: split1 = new split(nb_out, in, list_out); - 2- Set split fractions: split1->set(fractions); - 3- Set the name: split1->set(name); - 4- Solve: split1->solve(); -*/ -#ifndef SPLIT_H -#define SPLIT_H - -#include "stream.hpp" -using namespace std; - -class split -{ -private: - - int i, j; - bool success; - double tmp; - string name; - int nb_out; //number of input streams - stream *in; //pointer to input stream - stream **out; //list of pointers to output streams - double *frac; //list of split fractions - -public: - split(int, stream*, stream**); //defines the connectivities of this unit - ~split(){} - void set(double* f) {frac=f;} - void set(const string & n) { name = n;} - bool solve(); //finds the temperature and computes mass balance - void write(); -}; - -#endif +/* +This unit takes one input stream and divides in two or more +output streams. The pressure and temparature of output streams +are the same as the input's. + +Structure in the .process file: +split {name} {index of input stream} {nb_out} {indexes of output streams and fractions of input} + +How to use: + 1- Call the constructor: split1 = new split(nb_out, in, list_out); + 2- Set split fractions: split1->set(fractions); + 3- Set the name: split1->set(name); + 4- Solve: split1->solve(); +*/ +#ifndef SPLIT_H +#define SPLIT_H + +#include "stream.hpp" +using namespace std; + +class split +{ +private: + + int i, j; + bool success; + double tmp; + string name; + int nb_out; //number of input streams + stream *in; //pointer to input stream + stream **out; //list of pointers to output streams + double *frac; //list of split fractions + +public: + split(int, stream*, stream**); //defines the connectivities of this unit + ~split(){} + void set(double* f) {frac=f;} + void set(const string & n) { name = n;} + bool solve(); //finds the temperature and computes mass balance + void write(); +}; + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.cpp index 8854441ea39a4a547414299b8725c623b9042192..408c1cb21e949286b9cb58cc2e25801db61a1480 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.cpp @@ -1,265 +1,265 @@ -#include "stream.hpp" -using namespace std; - -// destructor : -stream::~stream ( void ) { - delete thermo; - delete [] tab1; - delete [] tab2; - delete [] tab3; - delete [] tab4; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; -} - -void stream::check_error() -{ - - if (error>MAX_ERROR) { - cout << "ERROR 4\n\n"; - exit(0); - } - if (warning>MAX_WARNING) { - cout << "ERROR 5\n\n"; - exit(0); - } -} - -void stream::set ( int _nb , chemical ** _chem) { - int i; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; - nb = _nb; - chem = new chemical * [nb]; - for ( i = 0 ; i < nb ; i++ ) - chem[i] = new chemical(*_chem[i]); -} - -void stream::set(double pres, double temp) //set P, T, find state and resulting v -{ - if(thermo->get_dim()!=nb) - { - delete thermo; - thermo = new thermolib(nb); - } - P=pres; - T=temp; - for (i=0;i<nb;i++) {chem[i]->P=pres; chem[i]->T=temp;} - if(n()>EPS) - { - v=quality(); - tmp1=0; - for (i=0;i<nb;i++) - { - if (T>chem[i]->Tc || v==1) chem[i]->state=1; - else chem[i]->state=0; - } - v=0; - for (i=0;i<nb;i++) - { - if (chem[i]->state==0) {if (chem[i]->m>EPS) v+= chem[i]->m/chem[i]->rho(); tab4[i]=0;} - if (chem[i]->state==1) {tab4[i] = chem[i]->n(); tmp1+=tab4[i];} - } - if (tmp1>EPS) - { - for (i=0;i<nb;i++) - { - tab1[i] = chem[i]->Pc; //cout<<endl<<tab1[i]; - tab2[i] = chem[i]->Tc; // cout<<" "<<tab2[i]; - tab3[i] = chem[i]->omega(); //cout<<" "<<tab3[i]; - tab4[i]/=tmp1; // cout<<" "<<tab4[i]; - } - thermo->send(tab1,tab2,tab3, tab4); - thermo->set(P,T,0.0,tmp1); - v+=thermo->v(); - } - } - else v= 0.0; -} - -void stream::set(double *list) -{ - m=0; - for (i=0; i<nb; i++) - { - chem[i]->m=list[i]; - m+=list[i]; - } -} - -void stream::bubble() -{ - bp=1.1e6; - for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)<bp && chem[i]->m>EPS) bp=chem[i]->Tboil(P); - if (bp==1.1e6) bp=0.0; - else - { - step=2; - while (fabs(step)>TOL_BP && fabs(tmp1-1)>TOL_BP) - { - //if(DEBUG) cout<<endl<<bp; - bp+=step; - tmp1=tmp2=0; - for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()*chem[i]->Psat(bp)/P;} - tmp1/=tmp2; - step=10*(1.0-tmp1); - } - } -} - -void stream::dew() -{ - dp=0.0; - tmp1=10; - for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)>dp && chem[i]->m>EPS) dp=chem[i]->Tboil(P); - if (dp>EPS) - { - dp=bp; - step=1; - while (fabs(step)>TOL_DP && fabs(tmp1/tmp2-1)>TOL_DP) - { - dp+=step; - if(dp<bp) dp=bp; - //if(DEBUG) cout<<endl<<dp; - tmp1=tmp2=0; - for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()/chem[i]->Psat(dp)*P; } - if (step/fabs(step)*tmp2/tmp1 >1 || step/fabs(step)*tmp1/tmp2 <-1) step*= -0.1; - } - } -} - -double stream::quality() -{ - if(T>EPS) - { - bubble(); - dew(); - //if(DEBUG) cout<<endl<<name<<" bp="<<bp<<" dp="<<dp<<" T="<<T; system("pause"); - if (bp < dp) - { - if (bp < T && T< dp) tmp= (T-bp)/(dp-bp); - if (T<= bp) tmp= 0.0; - if (T >= dp) tmp= 1.0; - } - } - else tmp= 0.0; - return tmp; -} - -double stream::K(int i) -{ - for (j=0;j<nb;j++) - tab4[j] = chem[j]->n()/n(); - thermo->send(tab1,tab2,tab3, tab4); - if (T>EPS && P>EPS) - { - thermo->set(P,T,v,n()); - return thermo->K(i); - } - else - { - ofstream logf; - logf.open(MESSAGES, ios::app); - logf<<" --> Warning <-- Cannot compute K of "<<chem[i]->name<<" in stream "<<name<<".\n"; - logf.close(); - warning++; - check_error(); - return 1.0; - } -} - -double stream::n() -{ - tmp=0.0; - for ( k = 0 ; k < nb ; k++ ) - tmp+=chem[k]->n(); - return tmp; -} - - -// affectation : -stream & stream::operator = ( const stream & s ) { - - (*thermo) = *(s.thermo); - - delete [] tab1; - delete [] tab2; - delete [] tab3; - delete [] tab4; - for ( i = 0 ; i < nb ; i++ ) - delete chem[i]; - delete [] chem; - - P = s.P; - T = s.T; - m = s.m; - v = s.v; - i = s.i; - j = s.j; - k = s.k; - error = s.error; - warning = s.warning; - name = s.name; - nb = s.nb; - chem = new chemical *[nb]; - - tab1 = new double[nb]; - tab2 = new double[nb]; - tab3 = new double[nb]; - tab4 = new double[nb]; - - step = s.step; - - for ( i = 0 ; i < nb ; i++ ) { - chem[i] = new chemical(*s.chem[i]); - tab1[i] = s.tab1[i]; - tab2[i] = s.tab2[i]; - tab3[i] = s.tab3[i]; - tab4[i] = s.tab4[i]; - } - - tmp = s.tmp; - tmp1 = s.tmp1; - tmp2 = s.tmp2; - - return *this; -} - - -void stream::write() { - - string file_name = RUNTIME + name + ".stream"; - - cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; - - cout.unsetf(ios::scientific); - cout << setiosflags(ios::showpoint | ios::fixed)<<setprecision(1); - - cout << "\t>>" << setw(8) << P << " " << setw(9) << T <<" "; - - cout << resetiosflags(ios::fixed) << setiosflags(ios::scientific) << setprecision(3); - - if (m>EPS) - cout << setw(11) << m << setw(11) << v; - else - cout << " x x "; - for ( i = 0 ; i < nb ; i++ ) { - if ( chem[i]->m <= EPS ) - cout << " x "; - else - cout << setw(11) << chem[i]->m; - } - cout << "\n\tEND\n\n"; - - cout.setf(ios::scientific); - -} - -void stream::purge() -{ - P=T=m=v=0.0; - for(i=0;i<nb;i++) - chem[i]->purge(); -} +#include "stream.hpp" +using namespace std; + +// destructor : +stream::~stream ( void ) { + delete thermo; + delete [] tab1; + delete [] tab2; + delete [] tab3; + delete [] tab4; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; +} + +void stream::check_error() +{ + + if (error>MAX_ERROR) { + cout << "ERROR 4\n\n"; + exit(0); + } + if (warning>MAX_WARNING) { + cout << "ERROR 5\n\n"; + exit(0); + } +} + +void stream::set ( int _nb , chemical ** _chem) { + int i; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; + nb = _nb; + chem = new chemical * [nb]; + for ( i = 0 ; i < nb ; i++ ) + chem[i] = new chemical(*_chem[i]); +} + +void stream::set(double pres, double temp) //set P, T, find state and resulting v +{ + if(thermo->get_dim()!=nb) + { + delete thermo; + thermo = new thermolib(nb); + } + P=pres; + T=temp; + for (i=0;i<nb;i++) {chem[i]->P=pres; chem[i]->T=temp;} + if(n()>EPS) + { + v=quality(); + tmp1=0; + for (i=0;i<nb;i++) + { + if (T>chem[i]->Tc || v==1) chem[i]->state=1; + else chem[i]->state=0; + } + v=0; + for (i=0;i<nb;i++) + { + if (chem[i]->state==0) {if (chem[i]->m>EPS) v+= chem[i]->m/chem[i]->rho(); tab4[i]=0;} + if (chem[i]->state==1) {tab4[i] = chem[i]->n(); tmp1+=tab4[i];} + } + if (tmp1>EPS) + { + for (i=0;i<nb;i++) + { + tab1[i] = chem[i]->Pc; //cout<<endl<<tab1[i]; + tab2[i] = chem[i]->Tc; // cout<<" "<<tab2[i]; + tab3[i] = chem[i]->omega(); //cout<<" "<<tab3[i]; + tab4[i]/=tmp1; // cout<<" "<<tab4[i]; + } + thermo->send(tab1,tab2,tab3, tab4); + thermo->set(P,T,0.0,tmp1); + v+=thermo->v(); + } + } + else v= 0.0; +} + +void stream::set(double *list) +{ + m=0; + for (i=0; i<nb; i++) + { + chem[i]->m=list[i]; + m+=list[i]; + } +} + +void stream::bubble() +{ + bp=1.1e6; + for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)<bp && chem[i]->m>EPS) bp=chem[i]->Tboil(P); + if (bp==1.1e6) bp=0.0; + else + { + step=2; + while (fabs(step)>TOL_BP && fabs(tmp1-1)>TOL_BP) + { + //if(DEBUG) cout<<endl<<bp; + bp+=step; + tmp1=tmp2=0; + for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()*chem[i]->Psat(bp)/P;} + tmp1/=tmp2; + step=10*(1.0-tmp1); + } + } +} + +void stream::dew() +{ + dp=0.0; + tmp1=10; + for(i=0;i<nb;i++) if(T<chem[i]->Tc && chem[i]->Tboil(P)>dp && chem[i]->m>EPS) dp=chem[i]->Tboil(P); + if (dp>EPS) + { + dp=bp; + step=1; + while (fabs(step)>TOL_DP && fabs(tmp1/tmp2-1)>TOL_DP) + { + dp+=step; + if(dp<bp) dp=bp; + //if(DEBUG) cout<<endl<<dp; + tmp1=tmp2=0; + for (i=0;i<nb;i++) if(T<chem[i]->Tc) {tmp2+=chem[i]->n(); tmp1+=chem[i]->n()/chem[i]->Psat(dp)*P; } + if (step/fabs(step)*tmp2/tmp1 >1 || step/fabs(step)*tmp1/tmp2 <-1) step*= -0.1; + } + } +} + +double stream::quality() +{ + if(T>EPS) + { + bubble(); + dew(); + //if(DEBUG) cout<<endl<<name<<" bp="<<bp<<" dp="<<dp<<" T="<<T; system("pause"); + if (bp < dp) + { + if (bp < T && T< dp) tmp= (T-bp)/(dp-bp); + if (T<= bp) tmp= 0.0; + if (T >= dp) tmp= 1.0; + } + } + else tmp= 0.0; + return tmp; +} + +double stream::K(int i) +{ + for (j=0;j<nb;j++) + tab4[j] = chem[j]->n()/n(); + thermo->send(tab1,tab2,tab3, tab4); + if (T>EPS && P>EPS) + { + thermo->set(P,T,v,n()); + return thermo->K(i); + } + else + { + ofstream logf; + logf.open(MESSAGES, ios::app); + logf<<" --> Warning <-- Cannot compute K of "<<chem[i]->name<<" in stream "<<name<<".\n"; + logf.close(); + warning++; + check_error(); + return 1.0; + } +} + +double stream::n() +{ + tmp=0.0; + for ( k = 0 ; k < nb ; k++ ) + tmp+=chem[k]->n(); + return tmp; +} + + +// affectation : +stream & stream::operator = ( const stream & s ) { + + (*thermo) = *(s.thermo); + + delete [] tab1; + delete [] tab2; + delete [] tab3; + delete [] tab4; + for ( i = 0 ; i < nb ; i++ ) + delete chem[i]; + delete [] chem; + + P = s.P; + T = s.T; + m = s.m; + v = s.v; + i = s.i; + j = s.j; + k = s.k; + error = s.error; + warning = s.warning; + name = s.name; + nb = s.nb; + chem = new chemical *[nb]; + + tab1 = new double[nb]; + tab2 = new double[nb]; + tab3 = new double[nb]; + tab4 = new double[nb]; + + step = s.step; + + for ( i = 0 ; i < nb ; i++ ) { + chem[i] = new chemical(*s.chem[i]); + tab1[i] = s.tab1[i]; + tab2[i] = s.tab2[i]; + tab3[i] = s.tab3[i]; + tab4[i] = s.tab4[i]; + } + + tmp = s.tmp; + tmp1 = s.tmp1; + tmp2 = s.tmp2; + + return *this; +} + + +void stream::write() { + + string file_name = RUNTIME + name + ".stream"; + + cout << "WRITE FILE " << file_name << " :\n\tBEGIN\n"; + + cout.unsetf(ios::scientific); + cout << setiosflags(ios::showpoint | ios::fixed)<<setprecision(1); + + cout << "\t>>" << setw(8) << P << " " << setw(9) << T <<" "; + + cout << resetiosflags(ios::fixed) << setiosflags(ios::scientific) << setprecision(3); + + if (m>EPS) + cout << setw(11) << m << setw(11) << v; + else + cout << " x x "; + for ( i = 0 ; i < nb ; i++ ) { + if ( chem[i]->m <= EPS ) + cout << " x "; + else + cout << setw(11) << chem[i]->m; + } + cout << "\n\tEND\n\n"; + + cout.setf(ios::scientific); + +} + +void stream::purge() +{ + P=T=m=v=0.0; + for(i=0;i<nb;i++) + chem[i]->purge(); +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.hpp index 94b21025cc190e1bc0783d172737cd72bef2e889..895ef3d6b8fcd99dee13564f66d71932a2c009c5 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/stream.hpp @@ -1,86 +1,86 @@ -#ifndef STREAM_H -#define STREAM_H -#include "chemical.hpp" -#include <iomanip> -using namespace std; - -class stream { - -private: - - stream ( void ) {} - stream ( const stream & s ) {} - -public: - void check_error(); - - double P, T, m, v; // Pressure in atm, temperature in K, - // total mass flow in kg/s, total volume flow in m3/s - - int i, j, k, error, warning; - - string name; - - int nb; // number of chemicals to store; - - chemical ** chem; // list of stored chemicals - - thermolib *thermo; - - double tmp, tmp1,tmp2, *tab1, *tab2, *tab3, *tab4; - double step; - void bubble(), dew(); - -public: - - - - - - double dp, bp; - double rho() {if(v!=0) return m/v; else exit(0);} // Apparent density in kg/m3 - double n(); // total mole flow (mol/s) - double quality(); // returns the vapor fraction of stream (1=all vapor, 0 = all liquid) - double K(int); // returns the vapor-liquid equilibrium constant of compound i - - // constructor : - stream ( const string _name , int n , chemical ** list ) : P (0 ) , - T (0 ) , - m (0 ) , - v (0 ) , - error (0 ) , - warning(0 ) , - name (_name ) , - nb (n ) , - chem (new chemical *[nb]) , - thermo (new thermolib (nb)) , - tab1 (new double [nb]) , - tab2 (new double [nb]) , - tab3 (new double [nb]) , - tab4 (new double [nb]) { - for ( i = 0 ; i < nb ; i++ ) - chem[i] = new chemical(*list[i]); - } - - - // affectation : - stream & operator = ( const stream & s ); - - void set_thermo ( thermolib * t ) { (*thermo) = *t; } - - - void set(double, double); // Sets P and T - void set(double*); // Sets mass flows - void set( const string & n ) { name = n;} - void set ( int _nb , chemical ** _chem); - - - // destructor : - ~stream ( void ); - - void write(); - void purge(); -}; - - -#endif +#ifndef STREAM_H +#define STREAM_H +#include "chemical.hpp" +#include <iomanip> +using namespace std; + +class stream { + +private: + + stream ( void ) {} + stream ( const stream & s ) {} + +public: + void check_error(); + + double P, T, m, v; // Pressure in atm, temperature in K, + // total mass flow in kg/s, total volume flow in m3/s + + int i, j, k, error, warning; + + string name; + + int nb; // number of chemicals to store; + + chemical ** chem; // list of stored chemicals + + thermolib *thermo; + + double tmp, tmp1,tmp2, *tab1, *tab2, *tab3, *tab4; + double step; + void bubble(), dew(); + +public: + + + + + + double dp, bp; + double rho() {if(v!=0) return m/v; else exit(0);} // Apparent density in kg/m3 + double n(); // total mole flow (mol/s) + double quality(); // returns the vapor fraction of stream (1=all vapor, 0 = all liquid) + double K(int); // returns the vapor-liquid equilibrium constant of compound i + + // constructor : + stream ( const string _name , int n , chemical ** list ) : P (0 ) , + T (0 ) , + m (0 ) , + v (0 ) , + error (0 ) , + warning(0 ) , + name (_name ) , + nb (n ) , + chem (new chemical *[nb]) , + thermo (new thermolib (nb)) , + tab1 (new double [nb]) , + tab2 (new double [nb]) , + tab3 (new double [nb]) , + tab4 (new double [nb]) { + for ( i = 0 ; i < nb ; i++ ) + chem[i] = new chemical(*list[i]); + } + + + // affectation : + stream & operator = ( const stream & s ); + + void set_thermo ( thermolib * t ) { (*thermo) = *t; } + + + void set(double, double); // Sets P and T + void set(double*); // Sets mass flows + void set( const string & n ) { name = n;} + void set ( int _nb , chemical ** _chem); + + + // destructor : + ~stream ( void ); + + void write(); + void purge(); +}; + + +#endif diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.cpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.cpp index 13a3b35f8f8bccf272bb39053902421df53d1f91..f6bf0a15792f059ba7e2c086395e348223ea5094 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.cpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.cpp @@ -1,174 +1,174 @@ -#include "thermolib.hpp" -#include "defines.hpp" -#include "secant.cpp" -using namespace std; - - - - -// affectation : -thermolib & thermolib::operator = ( const thermolib & t ) { - - if (dim!=t.dim) - reset(t.dim); - - for ( i = 0 ; i < dim ; i++ ) { - Pc[i] = t.Pc[i]; - Tc[i] = t.Tc[i]; - omega[i] = t.omega[i]; - molefrac[i] = t.molefrac[i]; - } - - return *this; -} - -thermolib::~thermolib() { - delete solver; - delete [] Pc; - delete [] Tc; - delete [] omega; - delete [] molefrac; -} - -void thermolib::construct ( void ) { - molefrac = new double[dim]; - Pc = new double[dim]; - Tc = new double[dim]; - omega = new double[dim]; - - // C. Tribes add this for more robustness (variables may be initialized uncorrectly dependent on the execution) - for ( i = 0 ; i < dim ; i++ ) - { - Pc[i] = 0.0; - Tc[i] = 0.0; - omega[i] = 0.0; - molefrac[i] = 0.0; - } - - solver = new secant<thermolib>(); -} - -void thermolib::reset(int b) -{ - delete [] molefrac; - delete [] Pc; - delete [] Tc; - delete [] omega; - delete solver; - dim = b; - construct(); -} - -double thermolib::a_mix() -{ - if (dim>1) - { - tmp=0; - for (i=0;i<dim;i++) - for (j=0;j<dim;j++) - tmp += molefrac[i]*molefrac[j]*sqrt(a(i)*a(j)); - return tmp; - } - else return a(0); -} - -double thermolib::b_mix() -{ - if (dim>1) - { - tmp=0; - for (i=0;i<dim;i++) - tmp += molefrac[i]*b(i); - return tmp; - } - else return b(0); -} - -void thermolib::send(double* pc, double* tc, double* w, double* y) -{ - for (i=0;i<dim;i++) - { - Pc[i] = pc[i]*101.325; - Tc[i] = tc[i]; - omega[i] = w[i]; - molefrac[i] = y[i]; - } -} - -double thermolib::P() -{ - task=0; - pressure = 8.3144*temperature/molevolume; - solver->set(this, pressure, 1.001*pressure); - success=solver->run(); - return pressure/101.325; -} - -double thermolib::T() -{ - task=1; - temperature = pressure*molevolume/8.144; - solver->set(this, temperature, 1.001*temperature); - success=solver->run(); - return temperature; -} - -double thermolib::v() -{ - if (mole>EPS) - { - task=2; - molevolume = 8.3144*temperature/pressure; - solver->set(this, molevolume, 1.001*molevolume); - success=solver->run(); - return 0.001*mole*molevolume; - } - else return 0.0; -} - -double thermolib::Zv() -{ - task=4; - solver->set(this, 1.0, 0.99); - success=solver->run(); - return Z; -} - -double thermolib::phiV(int i) -{ - return exp((Z-1)*B(i)/B() - log(Z-B()) - A()/B()*(2*sqrt(A(i)/A())-B(i)/B())*log(1+B()/Z)); -} - -double thermolib::phiL(int i) -{ - Pr = pressure/Pc[i]; - Tr = temperature/Tc[i]; - tmp = 2.05135 - 2.10899/Tr - 0.19396*pow(Tr,2) + 0.02282*pow(Tr,3) + (0.08852 - 0.00872*pow(Tr,2))*Pr + (-0.00353 - 0.00203*Tr)*pow(Pr,2) - log10(Pr); - tmp += omega[i]*(-4.23893 + 8.65808*Tr - 1.2206/Tr - 3.15224*pow(Tr,3) - 0.025*(Pr-0.6)); - return pow(10, tmp); -} - -double thermolib::f(double x) -{ - if (task==0) - { - pressure=x; - x= 8.3144*temperature/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - x; - } - if (task==1) - { - temperature=x; - x= 8.3144*x/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - pressure; - } - if (task==2) - { - molevolume=x; - x= 8.3144*temperature/(x-b_mix()) - a_mix()/(pow(x,2)+b_mix()*x) - pressure; - } - if(task==4) - { - Z=x; - x= (pow(x,3)-pow(x,2)+(A()-B()-pow(B(),2))*x-A()*B()); - } - return x; -} +#include "thermolib.hpp" +#include "defines.hpp" +#include "secant.cpp" +using namespace std; + + + + +// affectation : +thermolib & thermolib::operator = ( const thermolib & t ) { + + if (dim!=t.dim) + reset(t.dim); + + for ( i = 0 ; i < dim ; i++ ) { + Pc[i] = t.Pc[i]; + Tc[i] = t.Tc[i]; + omega[i] = t.omega[i]; + molefrac[i] = t.molefrac[i]; + } + + return *this; +} + +thermolib::~thermolib() { + delete solver; + delete [] Pc; + delete [] Tc; + delete [] omega; + delete [] molefrac; +} + +void thermolib::construct ( void ) { + molefrac = new double[dim]; + Pc = new double[dim]; + Tc = new double[dim]; + omega = new double[dim]; + + // C. Tribes add this for more robustness (variables may be initialized uncorrectly dependent on the execution) + for ( i = 0 ; i < dim ; i++ ) + { + Pc[i] = 0.0; + Tc[i] = 0.0; + omega[i] = 0.0; + molefrac[i] = 0.0; + } + + solver = new secant<thermolib>(); +} + +void thermolib::reset(int b) +{ + delete [] molefrac; + delete [] Pc; + delete [] Tc; + delete [] omega; + delete solver; + dim = b; + construct(); +} + +double thermolib::a_mix() +{ + if (dim>1) + { + tmp=0; + for (i=0;i<dim;i++) + for (j=0;j<dim;j++) + tmp += molefrac[i]*molefrac[j]*sqrt(a(i)*a(j)); + return tmp; + } + else return a(0); +} + +double thermolib::b_mix() +{ + if (dim>1) + { + tmp=0; + for (i=0;i<dim;i++) + tmp += molefrac[i]*b(i); + return tmp; + } + else return b(0); +} + +void thermolib::send(double* pc, double* tc, double* w, double* y) +{ + for (i=0;i<dim;i++) + { + Pc[i] = pc[i]*101.325; + Tc[i] = tc[i]; + omega[i] = w[i]; + molefrac[i] = y[i]; + } +} + +double thermolib::P() +{ + task=0; + pressure = 8.3144*temperature/molevolume; + solver->set(this, pressure, 1.001*pressure); + success=solver->run(); + return pressure/101.325; +} + +double thermolib::T() +{ + task=1; + temperature = pressure*molevolume/8.144; + solver->set(this, temperature, 1.001*temperature); + success=solver->run(); + return temperature; +} + +double thermolib::v() +{ + if (mole>EPS) + { + task=2; + molevolume = 8.3144*temperature/pressure; + solver->set(this, molevolume, 1.001*molevolume); + success=solver->run(); + return 0.001*mole*molevolume; + } + else return 0.0; +} + +double thermolib::Zv() +{ + task=4; + solver->set(this, 1.0, 0.99); + success=solver->run(); + return Z; +} + +double thermolib::phiV(int i) +{ + return exp((Z-1)*B(i)/B() - log(Z-B()) - A()/B()*(2*sqrt(A(i)/A())-B(i)/B())*log(1+B()/Z)); +} + +double thermolib::phiL(int i) +{ + Pr = pressure/Pc[i]; + Tr = temperature/Tc[i]; + tmp = 2.05135 - 2.10899/Tr - 0.19396*pow(Tr,2) + 0.02282*pow(Tr,3) + (0.08852 - 0.00872*pow(Tr,2))*Pr + (-0.00353 - 0.00203*Tr)*pow(Pr,2) - log10(Pr); + tmp += omega[i]*(-4.23893 + 8.65808*Tr - 1.2206/Tr - 3.15224*pow(Tr,3) - 0.025*(Pr-0.6)); + return pow(10, tmp); +} + +double thermolib::f(double x) +{ + if (task==0) + { + pressure=x; + x= 8.3144*temperature/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - x; + } + if (task==1) + { + temperature=x; + x= 8.3144*x/(molevolume-b_mix()) - a_mix()/(pow(molevolume,2)+b_mix()*molevolume) - pressure; + } + if (task==2) + { + molevolume=x; + x= 8.3144*temperature/(x-b_mix()) - a_mix()/(pow(x,2)+b_mix()*x) - pressure; + } + if(task==4) + { + Z=x; + x= (pow(x,3)-pow(x,2)+(A()-B()-pow(B(),2))*x-A()*B()); + } + return x; +} diff --git a/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.hpp b/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.hpp index 3440270ab02d6575023747971b89e9725da31061..3d39c8c7664d3be918c45978344f86a89d681550 100644 --- a/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.hpp +++ b/tools/SENSITIVITY/problems/styrene/black-box/truth/thermolib.hpp @@ -1,50 +1,50 @@ -#ifndef THERMOLIB_H -#define THERMOLIB_H -#include "secant.hpp" -using namespace std; - -class thermolib -{ - private: - bool success; - int dim, i, j; - double pressure, temperature, molevolume, mole,*molefrac; - double *Pc, *Tc, *omega, Z, tmp, Tr, Pr; - void construct(); - double a(int i) {return (0.42748*pow(8.8144,2)*pow(Tc[i],2)*pow(1.0+f_omega(i)*(1.0-sqrt(temperature/Tc[i])), 2)/Pc[i]);} - double a_mix(); - double b(int i) {return (0.08664*8.3144*Tc[i]/Pc[i]);} - double b_mix(); - double A(int i) {return (a(i)*pressure/pow(8.3144, 2)/pow(temperature, 2));} - double A() {return (a_mix()*pressure/pow(8.3144, 2)/pow(temperature, 2));} - double B(int i) {return (b(i)*pressure/8.3144/temperature);} - double B(){return (b_mix()*pressure/8.3144/temperature);} - double Zv(), phiV(int), phiL(int); - double f_omega(int i) {return (0.48 + 1.574*omega[i] - 0.176*pow(omega[i], 2));} - int task; //0=find P 1=find T 2=find v 3= find K 4=find Zv - secant<thermolib> *solver; - - public: - double P(); //retruns pressure at T and v, in atm - double T(); //returns temperature at P and v, in K - double v(); //returns volume flow at P, T, n(), in m3/s - double K() {Z = Zv(); return phiL(0)/phiV(0);} //returns the vapor-liquid equilibirum constant - double K(int i) {return phiL(i)/phiV(i);} - double compres_coeff(){return 1.0;}; - - -// affectation : - thermolib & operator = ( const thermolib & t ); - - thermolib ( int d = 1 ) { dim=d; construct();} - - void send(double pc, double tc, double w) { Pc[0] = pc*101.325; Tc[0] = tc; omega[0]=w;} - void send(double*, double*, double*, double*); - void set(double p, double t, double v, double n) {pressure=p*101.325; temperature=t; molevolume=0.001*n/v; mole=n;} - double f(double); - int get_dim() {return dim;} - ~thermolib(); - void reset(int); -}; -#endif - +#ifndef THERMOLIB_H +#define THERMOLIB_H +#include "secant.hpp" +using namespace std; + +class thermolib +{ + private: + bool success; + int dim, i, j; + double pressure, temperature, molevolume, mole,*molefrac; + double *Pc, *Tc, *omega, Z, tmp, Tr, Pr; + void construct(); + double a(int i) {return (0.42748*pow(8.8144,2)*pow(Tc[i],2)*pow(1.0+f_omega(i)*(1.0-sqrt(temperature/Tc[i])), 2)/Pc[i]);} + double a_mix(); + double b(int i) {return (0.08664*8.3144*Tc[i]/Pc[i]);} + double b_mix(); + double A(int i) {return (a(i)*pressure/pow(8.3144, 2)/pow(temperature, 2));} + double A() {return (a_mix()*pressure/pow(8.3144, 2)/pow(temperature, 2));} + double B(int i) {return (b(i)*pressure/8.3144/temperature);} + double B(){return (b_mix()*pressure/8.3144/temperature);} + double Zv(), phiV(int), phiL(int); + double f_omega(int i) {return (0.48 + 1.574*omega[i] - 0.176*pow(omega[i], 2));} + int task; //0=find P 1=find T 2=find v 3= find K 4=find Zv + secant<thermolib> *solver; + + public: + double P(); //retruns pressure at T and v, in atm + double T(); //returns temperature at P and v, in K + double v(); //returns volume flow at P, T, n(), in m3/s + double K() {Z = Zv(); return phiL(0)/phiV(0);} //returns the vapor-liquid equilibirum constant + double K(int i) {return phiL(i)/phiV(i);} + double compres_coeff(){return 1.0;}; + + +// affectation : + thermolib & operator = ( const thermolib & t ); + + thermolib ( int d = 1 ) { dim=d; construct();} + + void send(double pc, double tc, double w) { Pc[0] = pc*101.325; Tc[0] = tc; omega[0]=w;} + void send(double*, double*, double*, double*); + void set(double p, double t, double v, double n) {pressure=p*101.325; temperature=t; molevolume=0.001*n/v; mole=n;} + double f(double); + int get_dim() {return dim;} + ~thermolib(); + void reset(int); +}; +#endif + diff --git a/utils/MergeCacheFiles/Readme.txt b/utils/MergeCacheFiles/Readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..20d4ad5d9caa1408c038617543ba9b60727e0b32 --- /dev/null +++ b/utils/MergeCacheFiles/Readme.txt @@ -0,0 +1,21 @@ +Cache files from different runs of the same problem can be merged and reused in a later optimization. + +Please note that binary cache files must be from the same OS. Please note that the provided cacheX.bin files have been created under OSX. + +1- Using the OS (linux and OSX) command line + +- The following sources codes allow to merge two binary files (cache1.bin and cache2.bin) into a new cache file called cache3.bin. + +- On the command line execute the make command + +- Execute ./merge.exe + +2- Using Matlab environment + +- If not already done, setup the mex Matlab External Interface with the command mex -setup at the command prompt. Please refer to Matlab documentation for details. + +- Change the Current Folder to %NOMAD_HOME%/utils/MergeCacheFiles + +- Run the command build.m + +- Run the command mergeM(‘cache1.bin’,’cache2.bin’,’cache3.bin’) diff --git a/utils/MergeCacheFiles/build.m b/utils/MergeCacheFiles/build.m new file mode 100644 index 0000000000000000000000000000000000000000..5017f5c810df31eeffe0b8e35cafc806a2a55aa6 --- /dev/null +++ b/utils/MergeCacheFiles/build.m @@ -0,0 +1,72 @@ +%% GERAD NOMAD Build for Matlab + +% This file will help you compile NOMAD for use with MATLAB. + +% To recompile you will need to get / do the following: + +% 1) Get NOMAD +% NOMAD is available from http://www.gerad.ca/NOMAD/PHP_Forms/Download.php. +% Complete the download form then download the latest version. Define the +% $NOMAD_HOME environment variable. + +% 2) NOMAD MEX Interface +% The NOMAD MEX Interface is a simple MEX interface written to use NOMAD. + +% 3) Compile the MEX File +% The code below will build the NOMAD MEX file. Once you have completed all the +% above steps, simply run this file to compile NOMAD! You MUST BE in the +% base directory of OPTI! + +clear nomad + +switch(computer) +case 'PCWIN' +libdir = ' -Lwin32\'; +case 'PCWIN64' +libdir = ' -Lwin64\'; +case 'GLNX86' +libdir = 'glnx86/'; +case 'GLNXA64' +libdir = 'glnxa64/'; +case 'MACI64' +libdir = 'maci64/'; +end + +clear nomad_home nomad_src; + + +fprintf('\n------------------------------------------------\n'); +fprintf('NOMAD CACHE MERGE BUILD \n\n'); + +nomad_home = getenv('NOMAD_HOME'); +if (length(nomad_home)<1) + error('opti:nomad','Please set NOMAD_HOME variables properly with the command setenv(''NOMAD_HOME'',ARG1)!'); +end +nomad_src=[nomad_home filesep 'src' filesep]; + + +%Get NOMAD Libraries +post = [' -I. -I' nomad_src ' -lm -lut -output mergeM']; + +%Compile & Move +pre = ['mex -v -largeArrayDims mergeM.cpp ' nomad_src 'Parameters.cpp ' nomad_src 'Barrier.cpp ' nomad_src 'Cache.cpp '... +nomad_src 'Cache_File_Point.cpp ' nomad_src 'Cache_Point.cpp ' nomad_src 'Cache_Search.cpp ' nomad_src 'Clock.cpp '... +nomad_src 'Direction.cpp ' nomad_src 'Directions.cpp ' nomad_src 'Display.cpp '... +nomad_src 'Double.cpp ' nomad_src 'Eval_Point.cpp ' nomad_src 'Evaluator.cpp ' nomad_src 'Evaluator_Control.cpp ' nomad_src 'Exception.cpp '... +nomad_src 'Extended_Poll.cpp ' nomad_src 'L_Curve.cpp ' nomad_src 'LH_Search.cpp ' nomad_src 'OrthogonalMesh.cpp ' nomad_src 'Mads.cpp ' nomad_src 'Model_Sorted_Point.cpp '... +nomad_src 'Model_Stats.cpp ' nomad_src 'Multi_Obj_Evaluator.cpp ' nomad_src 'Parameter_Entries.cpp '... +nomad_src 'Parameter_Entry.cpp ' nomad_src 'Pareto_Front.cpp ' nomad_src 'Pareto_Point.cpp ' nomad_src 'Phase_One_Evaluator.cpp '... +nomad_src 'Phase_One_Search.cpp ' nomad_src 'Point.cpp ' nomad_src 'Priority_Eval_Point.cpp ' nomad_src 'Quad_Model.cpp '... +nomad_src 'Quad_Model_Evaluator.cpp ' nomad_src 'Quad_Model_Search.cpp ' nomad_src 'Random_Pickup.cpp ' nomad_src 'RNG.cpp '... +nomad_src 'Signature.cpp ' nomad_src 'Slave.cpp ' nomad_src 'SMesh.cpp ' nomad_src 'Speculative_Search.cpp ' nomad_src 'Stats.cpp ' nomad_src 'utils.cpp '... +nomad_src 'Variable_Group.cpp ' nomad_src 'VNS_Search.cpp ' nomad_src 'XMesh.cpp']; + +try + eval([pre post]) + clear nomad_home nomad_src cdir post pre libdir; + fprintf('Done!\n'); +catch ME + clear nomad_home nomad_src cdir post pre libdir; + error('opti:nomad','Error Compiling NOMAD!\n%s',ME.message); +end +fprintf('------------------------------------------------\n'); diff --git a/utils/MergeCacheFiles/cache1.bin b/utils/MergeCacheFiles/cache1.bin new file mode 100644 index 0000000000000000000000000000000000000000..d3c04eef56120311a637e5e4c6c4560975b47e03 Binary files /dev/null and b/utils/MergeCacheFiles/cache1.bin differ diff --git a/utils/MergeCacheFiles/cache2.bin b/utils/MergeCacheFiles/cache2.bin new file mode 100644 index 0000000000000000000000000000000000000000..c87363aa13552d0ff62f19332c1a5212459207a7 Binary files /dev/null and b/utils/MergeCacheFiles/cache2.bin differ diff --git a/utils/MergeCacheFiles/cache3.bin b/utils/MergeCacheFiles/cache3.bin new file mode 100644 index 0000000000000000000000000000000000000000..d2bc763560c37723713a363869fd2c1189d04184 Binary files /dev/null and b/utils/MergeCacheFiles/cache3.bin differ diff --git a/utils/MergeCacheFiles/makefile b/utils/MergeCacheFiles/makefile new file mode 100644 index 0000000000000000000000000000000000000000..965ba8105a4bf8fc936f37c522be06d3a831d0de --- /dev/null +++ b/utils/MergeCacheFiles/makefile @@ -0,0 +1,50 @@ +EXE = merge.exe + +COMPILATOR = g++ + +COMPILATOR_OPTIONS = -O2 -ansi +L1 = $(NOMAD_HOME)/lib/nomad.a +LIBS = $(L1) -lm +INCLUDE = -I$(NOMAD_HOME)/src -I. +COMPILE = $(COMPILATOR) $(COMPILATOR_OPTIONS) $(INCLUDE) -c +OBJS = merge.o + + +ifndef NOMAD_HOME +define ECHO_NOMAD + @echo Please set NOMAD_HOME environment variable! + @false +endef +endif + + +$(EXE): $(L1) $(OBJS) + $(ECHO_NOMAD) + @echo " building the scalar version ..." + @echo " exe file : "$(EXE) + @$(COMPILATOR) -o $(EXE) $(OBJS) $(LIBS) $(COMPILATOR_OPTIONS) + @strip $(EXE) + + +merge.o: merge.cpp + $(ECHO_NOMAD) + @$(COMPILE) merge.cpp + +$(L1) $(L1_MPI): ; + $(ECHO_NOMAD) + +all: $(EXE) $(EXE_MPI) + +clean: ; + @echo " cleaning obj files" + @rm -f $(OBJS) $(OBJS_MPI) + +del: ; + @echo " cleaning trash files" + @rm -f core *~ + @echo " cleaning obj files" + @rm -f $(OBJS) $(OBJS_MPI) + @echo " cleaning exe file" + @rm -f $(EXE) $(EXE_MPI) + + diff --git a/utils/MergeCacheFiles/merge.cpp b/utils/MergeCacheFiles/merge.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e4264ef9eb703e233bde52c6a5d138bf4577185d --- /dev/null +++ b/utils/MergeCacheFiles/merge.cpp @@ -0,0 +1,56 @@ +/*-----------------------------------------------------*/ +/* how to use the NOMAD library with a user function */ +/*-----------------------------------------------------*/ +#include "nomad.hpp" +using namespace std; +// using namespace NOMAD; avoids putting NOMAD:: everywhere + + +/*------------------------------------------*/ +/* NOMAD main function */ +/*------------------------------------------*/ +int main ( int argc , char ** argv ) +{ + + // display: + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + try + { + + // NOMAD initializations: + NOMAD::begin ( argc , argv ); + + // parameters creation: + NOMAD::Cache cache1 ( out ); + NOMAD::Cache cache2 ( out ); + NOMAD::Cache cache3 ( out ); + + cache1.load("cache1.bin"); + out << "Before merging \n cache1.bin contains " << cache1.size() << " points" << endl; + + cache2.load("cache2.bin"); + out << " cache2.bin contains " << cache2.size() << " points" << endl; + + cache3.load("cache3.bin"); + out << " cache3.bin contains " << cache3.size() << " points" << endl; + + + + cache3.insert(cache1); + cache3.insert(cache2); + + cache3.save(true); + + out << "After merging \n cache3.bin contains " << cache3.size() << " points" << endl; + + + } + catch ( exception & e ) + { + cerr << "\n Merge triggered an exception (" << e.what() << ")\n\n"; + } + + return EXIT_SUCCESS; +} diff --git a/utils/MergeCacheFiles/mergeM.cpp b/utils/MergeCacheFiles/mergeM.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fde710c448b22027ed8a10821ea53a9ca884e64d --- /dev/null +++ b/utils/MergeCacheFiles/mergeM.cpp @@ -0,0 +1,90 @@ +/*-----------------------------------------------------*/ +/* Merge cache files from NOMAD */ +/*-----------------------------------------------------*/ +#include "mex.h" +#include "nomad.hpp" + +using namespace std; +// using namespace NOMAD; avoids putting NOMAD:: everywhere + + +struct printfbuf : std::streambuf { +public: + //Constructor + printfbuf() + { + setp(m_buffer, m_buffer + s_size - 2); + } +private: + enum { s_size = 1024 }; //not sure on this size + char m_buffer[s_size]; + int_type overflow(int_type c) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) { + *pptr() = traits_type::to_char_type(c); + pbump(1); + } + return sync() != -1 ? traits_type::not_eof(c) : traits_type::eof(); + } + + int sync() { + *pptr() = 0; + mexPrintf(pbase()); + mexEvalString("drawnow;"); + setp(m_buffer, m_buffer + s_size - 2); + return 0; + } + }; + +// Main Entry Function +// ----------------------------------------------------------------- +void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + // display: + + + try + { + + if(nrhs != 3 || !mxIsChar(prhs[0]) || !mxIsChar(prhs[1]) || !mxIsChar(prhs[2]) ) + mexErrMsgTxt("You must supply the name of 3 cache files for merging. 2 for input and 1 for output \n"); + + + char *cache_file_name_1 = NULL; + char *cache_file_name_2 = NULL; + char *cache_file_name_3 = NULL; + cache_file_name_1 = mxArrayToString(prhs[0]); + cache_file_name_2 = mxArrayToString(prhs[1]); + cache_file_name_3 = mxArrayToString(prhs[2]); + + printfbuf buf; + std::streambuf *cout_sbuf = std::cout.rdbuf(); //keep existing buffer + std::cout.rdbuf(&buf); //redirect buffer + + NOMAD::Display out ( std::cout ); + out.precision ( NOMAD::DISPLAY_PRECISION_STD ); + + // parameters creation: + NOMAD::Cache cache1 ( out ); + NOMAD::Cache cache2 ( out ); + NOMAD::Cache cache3 ( out ); + + cache1.load(cache_file_name_1); + cache2.load(cache_file_name_2); + cache3.load(cache_file_name_3); + + + cache3.insert(cache1); + cache3.insert(cache2); + cache3.save(true); + + out << "After merging \n " << cache_file_name_3 << " contains " << cache3.size() << " points" << endl; + + + } + catch ( exception & e ) + { + cerr << "\n Merge triggered an exception (" << e.what() << ")\n\n"; + } + +} diff --git a/utils/Run_TestSuite/readme.txt b/utils/Run_TestSuite/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..b99438f0531bd5743ceaed6c656580637fa88d84 --- /dev/null +++ b/utils/Run_TestSuite/readme.txt @@ -0,0 +1,3 @@ +1- Set the NOMAD_HOME environment variable +2- Execute the perl script (perl ./runNomadAll_parallel.pl 4) +3- Check the execution logs if necessary \ No newline at end of file diff --git a/utils/Run_TestSuite/runNomadAll_parallel.pl b/utils/Run_TestSuite/runNomadAll_parallel.pl new file mode 100755 index 0000000000000000000000000000000000000000..f7be08fd0492c1c81cc8b1367a1081405220cb9c --- /dev/null +++ b/utils/Run_TestSuite/runNomadAll_parallel.pl @@ -0,0 +1,309 @@ +#!/usr/bin/perl +# use strict; +use warnings; + +use Data::Dumper; + +use threads; +use threads::shared; +use Thread::Semaphore; + + +if (! exists $ENV{NOMAD_HOME}) { + print "Please provide an environment variable NOMAD_HOME. \n"; + exit 1; +} + +print "NOMAD_HOME = $ENV{NOMAD_HOME} \n"; + +#if (! exists $ENV{LIBAMPLDIR}) { +# print "!!!!!!!!!!!!!!!! The LIBAMPLDIR environment variable is not set -> ampl example may not work! \n"; +#} + +#if (! exists $ENV{CUTER} | ! exists $ENV{MYCUTER} | ! exists $ENV{SIFDEC} | ! exists $ENV{MYSIFDEC} ) { +# print "!!!!!!!!!!!!!!!! The environment variables for CUTEr are not set -> CUTEr example may not work! \n"; +#} + + +my $MPIcommand:shared; +open(aComRes,"uname |") or die "Can't run command: $!\n"; +if ( grep(/MINGW/,<aComRes>) ){ + $MPIcommand="mpiexec -localonly"; # version mingw +} else +{ + $MPIcommand="mpirun -n"; # version OSX and linux +} + +my $keySearch=" Error | error | error: | Exception | NOMAD::Exception | Failed | Arrêt | Stop"; + +my $nombre_de_jobs_en_parallele:shared; +if ( ! exists $ARGV[0]) { +$nombre_de_jobs_en_parallele = 1; # 1 but still 3 processes minimun required for mpi +} else { +$nombre_de_jobs_en_parallele = $ARGV[0]; +} + + +my $nomadEXE="nomad"; +my $nomadMPI_EXE="nomad.MPI"; + +my $maxLinesForLogProblem:shared; +$maxLinesForLogProblem = 20; + +my @list = ( + ["cd $ENV{NOMAD_HOME}/examples/basic/batch/single_obj ; if [ ! -e bb.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; fi ; $ENV{NOMAD_HOME}/bin/$nomadEXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/batch/single_obj_parallel ; if [ ! -e bb.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; fi ; $ENV{NOMAD_HOME}/bin/$nomadEXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/batch/bi_obj ; if [ ! -e bb.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; fi ; $ENV{NOMAD_HOME}/bin/$nomadEXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/batch/single_obj ; if [ ! -e bb.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; fi ; $MPIcommand 3 $ENV{NOMAD_HOME}/bin/$nomadMPI_EXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/batch/bi_obj ; if [ ! -e bb.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; fi ; $MPIcommand 3 $ENV{NOMAD_HOME}/bin/$nomadMPI_EXE param.txt 2>&1"] , + ["cd $ENV{NOMAD_HOME}/examples/basic/library/single_obj ; if [ -e basic_lib.exe ] ; then rm -f basic_lib.exe ; fi ; make clean 2>&1 ; make 2>&1; ./basic_lib.exe 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/library/bi_obj ; if [ -e basic_lib.exe ] ; then rm -f basic_lib.exe ; fi ; make clean 2>&1 ; make 2>&1 ; ./basic_lib.exe 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/library/single_obj ; if [ -e basic_lib_MPI.exe ] ; then rm -f basic_lib_MPI.exe ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./basic_lib_MPI.exe 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/library/bi_obj ; if [ -e basic_lib_MPI.exe ] ; then rm -f basic_lib_MPI.exe ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./basic_lib_MPI.exe 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/basic/library/single_obj_parallel ; if [ -e basic_lib.exe ] ; then rm -f basic_lib.exe ; fi ; make clean 2>&1 ; make 2>&1; ./basic_lib.exe 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/batch ; if [ ! -e bb.exe -o ! -e neighbors.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; g++ -o neighbors.exe neighbors.cpp ; fi ; echo ; $ENV{NOMAD_HOME}/bin/$nomadEXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/batch ; if [ ! -e bb.exe -o ! -e neighbors.exe ] ; then g++ -o bb.exe bb.cpp 2>&1 ; g++ -o neighbors.exe neighbors.cpp ; fi ; echo ; $MPIcommand 3 $ENV{NOMAD_HOME}/bin/$nomadMPI_EXE param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/single_obj ; if [ -e categorical.exe ] ; then rm -f categorical.exe ; echo ; fi ; make clean 2>&1 ; make 2>&1; ./categorical.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/single_obj ; if [ -e categorical_MPI.exe ] ; then rm -f categorical_MPI.exe ; echo ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./categorical_MPI.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/bi_obj ; if [ -e categorical.exe ] ; then rm -f categorical.exe ; echo ; fi ; make clean 2>&1 ; make 2>&1; ./categorical.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/categorical/bi_obj ; if [ -e categorical_MPI.exe ] ; then rm -f categorical_MPI.exe ; echo ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./categorical_MPI.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/restart ; if [ -e restart.exe ] ; then rm -f restart.exe ; echo ; fi ; make clean 2>&1 ; make 2>&1; ./restart.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/restart ; if [ -e restart_MPI.exe ] ; then rm -f restart_MPI.exe ; echo ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./restart_MPI.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/multi_start ; if [ -e multi.exe ] ; then rm -f multi.exe ; echo ; fi ; make clean 2>&1 ; make 2>&1; ./multi.exe param.txt 4 5 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/user_search ; if [ -e user_search.exe ] ; then rm -f user_search.exe ; echo ; fi ; make clean 2>&1 ; make 2>&1; ./user_search.exe 2>&1 "], + ["cd $ENV{NOMAD_HOME}/examples/advanced/user_search ; if [ -e user_search_MPI.exe ] ; then rm -f user_search_MPI.exe ; echo ; fi ; make clean 2>&1 ; make mpi 2>&1; $MPIcommand 3 ./user_search_MPI.exe 2>&1 "], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/AMPL ; if [ ! -e bb.exe ] ; then make 2>&1 ; echo ; fi ; $ENV{NOMAD_HOME}/bin/$nomadEXE param.txt 2>&1 "], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/AMPL ; if [ ! -e bb.exe ] ; then make 2>&1 ; echo ; fi ; $MPIcommand 3 $ENV{NOMAD_HOME}/bin/$nomadMPI_EXE param.txt 2>&1 "], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/CUTEr ; if [ ! -e bb ] ; then $ENV{MYSIFDEC}/bin/sifdecode PROBLEM.SIF ; ./compile 2>&1 ; fi ; $ENV{NOMAD_HOME}/bin/$nomadEXE parameters.txt 2>&1 "], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/CUTEr ; sleep 10 ; if [ ! -e bb ] ; then ./compile 2>&1 ; fi ; $MPIcommand 3 $ENV{NOMAD_HOME}/bin/$nomadMPI_EXE parameters.txt 2>&1 "], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/DLL/single_obj ; if [ -e nomad_for_dll ] ; then rm -f nomad_for_dll ; fi ; echo ; make 2>&1; ./nomad_for_dll parameters.txt 2>&1"], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/DLL/bi_obj ; if [ -e nomad_for_dll ] ; then rm -f nomad_for_dll ; fi ; echo ; make clean 2>&1 ; make 2>&1; ./nomad_for_dll parameters.txt 2>&1"], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/FORTRAN/example1 ; if [ -e test ] ; then rm -f test ; fi ; make clean 2>&1 ; make 2>&1; ./test 2>&1"], +# ["cd $ENV{NOMAD_HOME}/examples/interfaces/FORTRAN/example2 ; if [ -e test ] ; then rm -f test ; fi ; make clean 2>&1 ; make 2>&1; ./test 2>&1"], + ["cd $ENV{NOMAD_HOME}/tools/COOP-MADS ; if [ -e coopmads.exe ] ; then rm -f *.exe *.o ; fi ; make 2>&1 ; cd problems/G2_10 ; g++ -o bb.exe bb.cpp 2>&1; $MPIcommand 3 ../../coopmads.exe param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/tools/COOP-MADS ; sleep 10 ; if [ ! -e coopmads.exe ] ; then make 2>&1 ; fi ; cd problems/RHEOLOGY ; g++ -o bb.exe bb.cpp 2>&1; $MPIcommand 3 ../../coopmads.exe param.txt 2>&1"], + ["cd $ENV{NOMAD_HOME}/tools/PSD-MADS ; if [ -e psdmads.exe ] ; then rm -f *.exe *.o ; fi ; make 2>&1 ; cd problems/G2_20 ; g++ -o bb.exe bb.cpp 2>&1; $MPIcommand 6 ../../psdmads.exe param.txt 50 5 2>&1"] + ); + +my @NOMADcompilations = ( + ["cd $ENV{NOMAD_HOME}/src ; make clean ; make all -j $nombre_de_jobs_en_parallele 2>&1"], + ["cd $ENV{NOMAD_HOME}/src ; make clean ; make mpi -j $nombre_de_jobs_en_parallele 2>&1"] + ); + + +# le sémaphore permet de réguler le nombre de jobs en simultané, bloquant le processus principal tant qu'il n'y a pas de place de libre +my $semaphoreProblems = Thread::Semaphore->new($nombre_de_jobs_en_parallele); + + +# quelques variables partagées +my $cpt:shared; +my $failed:shared; + +# Initialisation de compteur et de tests +$cpt = 0; +$failed = 0; + +my $started = 0; + +################################################################ +# Sub pour résoudre les problèmes en parallèle +################################################################ +sub RunProblem($$$$$){ + my $aRef = shift; + my $index = shift; + my $cpt_ref = shift; + my $failed_ref = shift; + my $sema_ref = shift; + + open(WRITE_LOG,"> log$index.txt"); + for my $command (@{$aRef}){ + + my $fail=1; + + my @Problem=split(/;/,$command); + my $nmax=$#Problem; + my @Path=split(/\s+/,$Problem[0]); + + print WRITE_LOG "Path to problem: $Path[1] \n Command: $Problem[$nmax] ; Managed as process $index \n"; + open(LOG,"$command |") or die "Can't run program: $!\n"; + if ($? != 0) { + print "Echec d'exécution de la commande $! du process $index \n"; + $$failed_ref++; + $fail=0; + } + else { + @lines = <LOG>; + foreach $line (@lines){ + if (my @foo = grep(/$keySearch/, $line) ) { + print "????????? Probleme a l'execution de la commande du process $index :\n -----> @foo\n"; + print WRITE_LOG " !!!!!!!!!!!!!!! @foo \n "; + $$failed_ref++; + $fail=0; + last; + } + } + my $nL=$maxLinesForLogProblem; + if ( $#lines < $maxLinesForLogProblem){ + $nL=$#lines; + } + for ($i = $#lines - $nL ; $i != $#lines+1; $i++) { + print WRITE_LOG " -----> $lines[$i] "; + } + } + if ($fail==1){ + print WRITE_LOG "++++++++++++ OK! \n"; + } + close (LOG); + } + close (WRITE_LOG); + + # incrémente le nombre de jobs finis + $$cpt_ref++; + + # on a une place de libre. Ne pas oublier de libérer le sémaphore même en cas d'erreur + $$sema_ref->up(); + + return; +} + +############################# +# Sub pour les compilations +############################# +sub CompileNOMAD($$$){ + my $aRef = shift; + my $index = shift; + my $failed = shift; + + open(WRITE_LOG,"> logNOMADCompile$index.txt"); + for my $command (@{$aRef}){ + + my @Problem=split(/;/,$command); + my @Path=split(/\s+/,$Problem[0]); + + print WRITE_LOG "Path: $Path[1] \n Command: $Problem[1] ; Managed as process $index \n"; + open(LOG,"$command |") or die "Can't run program: $!\n"; + if ($? != 0) { + print "Echec d'exécution de la compilation de NOMAD par la commande $! process $index \n"; + $$failed=0; + } + else { + while (<LOG>){ + if (my @foo = grep(/error/, $_) ) { + print "??????? Probleme a la compilation de NOMAD dans le process $index:\n -----> @foo\n"; + print WRITE_LOG " -----> @foo \n "; + $$failed=0; + last; + } + if (my @foo = grep(/warning/, $_) ) { + print WRITE_LOG " -----> @foo \n "; + } + } + } + if ($$failed==1){ + print WRITE_LOG "++++++++++ OK! \n"; + } + close (LOG); + } + close (WRITE_LOG); + return; +} + +##################################### +##### Debut du programme principal +##################################### +# nettoie les fichiers de log +print "########################################################\n"; +print "On nettoie les anciens fichiers de log \n"; +system ("rm -f log*.txt"); + + +# démarre la compilation de nomad +my $failedCompileNOMAD=1; +my $thrNOMAD = threads->create("CompileNOMAD",($NOMADcompilations[0],1,\$failedCompileNOMAD)); ### Version parallele +#CompileNOMAD($NOMADcompilations[0],1,\$failedCompileNOMAD); ### Version scalaire +print "########################################################\n"; +print "La compilation de NOMAD (non mpi) vient de commencer \n"; + + +# démarre la compilation de nomad_mpi +my $failedCompileNOMAD_MPI=1; +my $thrNOMAD_MPI = threads->create("CompileNOMAD",($NOMADcompilations[1],2,\$failedCompileNOMAD_MPI)); ### Version parallele +#CompileNOMAD($NOMADcompilations[1],2,\$failedCompileNOMAD_MPI); ### Version scalaire +print "La compilation de NOMAD (mpi) vient de commencer \n"; + +$thrNOMAD->join(); +$thrNOMAD_MPI->join(); + +if ($failedCompileNOMAD==0){ + print "La compilation de NOMAD (non mpi) a echoue. On s'arrete la! \n"; +} + +if ($failedCompileNOMAD_MPI==0){ + print "La compilation de NOMAD (mpi) a echoue. On s'arrete la! \n"; +} + +if ($failedCompileNOMAD==0 or $failedCompileNOMAD_MPI==0){ + exit 0; +} + +print "Les compilations de nomad ont réussi \n"; +print "########################################################\n\n"; + +print "########################################################\n"; +print "Démarrage des executions en parallele pour les problemes \n"; +print "########################################################\n"; + + +# démarre tous les jobs +while ($started < scalar @list ){ + my $aRefToAListOfCommands = $list[$started]; + + # incrémente le compteur + $started++; + + # avons nous une place de libre ? + $semaphoreProblems->down(); + + # si le sémaphore est a 0, le processus principal va se bloquer en attendant une nouvelle place + print "Creation du job $started\n"; + my $thr = threads->create("RunProblem", ( + $aRefToAListOfCommands, + $started, + \$cpt, + \$failed, + \$semaphoreProblems + ) + ); + # détache le job du thread principal, rend la main au thread principal + $thr->detach(); + + # si on veut attendre la fin du job pour redonner la main, on utilise + # $thr->join(); +} + +# attend les derniers jobs +while ($cpt < $started){ + print "Seul $cpt jobs finis sur $started, on patiente!\n"; + sleep(3); +} +print "$cpt jobs lances, $failed échoués, sur les ".scalar @list." prévus\n"; + +if ($failed !=0) { + print "-----> Check the readme file for the failed problem(s)!!! \n"; +} + +print "On combine tous les logs en un seul\n"; +my $i=0; +open (LOGALL, '>', "logAll.txt") or die("impossible d'ecrire dans le fichier logAll.txt, $!"); +while ($i < scalar @list ){ + # incrémente le compteur + $i++; + open (LOGI, '<', "log$i.txt") or die("Impossible de lire log$i.txt, $!\n"); + print LOGALL "*********************************************************\n"; + while (my $Ligne = <LOGI> ) { + print LOGALL $Ligne; + } + close(LOGI); +} + +print "The End.\n";