diff --git a/.cirrus.yml b/.cirrus.yml
index 24876407..7a29b030 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -2,13 +2,13 @@ task:
matrix:
- name: FreeBSD -- gcc | g++
freebsd_instance:
- image: freebsd-13-1-release-amd64
+ image: freebsd-14-1-release-amd64
env:
- cc: gcc12
- cxx: g++12
+ cc: gcc14
+ cxx: g++14
- name: FreeBSD -- clang | clang++
freebsd_instance:
- image: freebsd-13-1-release-amd64
+ image: freebsd-14-1-release-amd64
env:
cc: clang
cxx: clang++
@@ -16,8 +16,8 @@ task:
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-base:latest
env:
- cc: gcc-12
- cxx: g++-12
+ cc: gcc-14
+ cxx: g++-14
- name: MacOS M1 -- clang | clang++
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-base:latest
@@ -40,7 +40,6 @@ task:
-DCMAKE_CXX_COMPILER=$cxx \
-DTEST_OPENMP=OFF \
-DBUILD_INTERFACE_C=ON \
- -DBUILD_TESTS=ON \
-DCMAKE_INSTALL_PREFIX=../instdir \
..
build_script: |
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8e64260b..ce1d7728 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -22,11 +22,6 @@ jobs:
build_type: "Release", cc: "cl", cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
}
-# - {
-# name: "Windows -- MinGW", artifact: "Windows-MinGW.tar.xz",
-# os: windows-latest,
-# build_type: "Release", cc: "x86_64-w64-mingw32-gcc", cxx: "x86_64-w64-mingw32-g++"
-# }
- {
name: "Ubuntu", artifact: "Linux.tar.xz",
os: ubuntu-latest,
@@ -48,7 +43,7 @@ jobs:
- name: Prepare Python environment
run: >-
- pip install setuptools wheel cython pytest
+ pip install setuptools wheel cython==0.29.* pytest
- name: Install dependencies on Windows
if: startsWith(matrix.config.name, 'Windows')
@@ -80,7 +75,6 @@ jobs:
cmake \
-DCMAKE_CC_COMPILER=${{matrix.config.cc}} \
-DCMAKE_CXX_COMPILER=${{matrix.config.cxx}} \
- -DBUILD_TESTS=ON \
-DBUILD_INTERFACE_C=ON \
-DBUILD_INTERFACE_PYTHON=ON \
-DTEST_OPENMP=OFF \
@@ -94,17 +88,8 @@ jobs:
mkdir instdir
mkdir build
cd build
- if [[ "${{matrix.config.name}}" == "Windows -- MinGW" ]]; then
- cmake -G "MinGW Makefiles" \
- -DTEST_OPENMP=OFF \
- -DBUILD_INTERFACE_C=ON \
- -DBUILD_EXAMPLES=OFF \
- -DCMAKE_INSTALL_PREFIX=../instdir \
- ..
- else
- cmake .. -DTEST_OPENMP=OFF -DBUILD_INTERFACE_C=ON -DBUILD_INTERFACE_PYTHON=ON -DBUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=../instdir
- fi
-
+ cmake .. -DTEST_OPENMP=OFF -DBUILD_INTERFACE_C=ON -DBUILD_INTERFACE_PYTHON=ON -DBUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=../instdir
+
- name: Build
shell: bash
run: |
@@ -130,16 +115,8 @@ jobs:
pip install --force-reinstall dist/*.whl
pytest
- - name: Prepare upload
- shell: bash
- run: |
- mv README.txt instdir/.
- mv LICENSE instdir/.
- cd instdir
- tar -cf NOMAD4.tar *
-
- - name: Upload
- uses: actions/upload-artifact@v3
- with:
- name: ${{ matrix.config.os }}
- path: instdir/NOMAD4.tar
+# - name: Upload
+# uses: actions/upload-artifact@v2
+# with:
+# name: ${{ matrix.config.os }}
+# path: build
diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml
index b25fb607..b9c4ccbe 100644
--- a/.github/workflows/pypi.yml
+++ b/.github/workflows/pypi.yml
@@ -1,4 +1,4 @@
-name: Build and publish binary wheels onto PyPi
+name: Build and publish binary wheels onto TestPyPi
on:
workflow_dispatch:
@@ -19,9 +19,15 @@ jobs:
os: ubuntu-latest
archs: x86_64
- - name: macOS
+ - name: macOS_X86
os: macos-latest
archs: x86_64
+ extra_option: -DCMAKE_OSX_ARCHITECTURES=x86_64
+
+ - name: macOS_ARM
+ os: macos-latest
+ archs: arm64
+ extra_option: -DCMAKE_OSX_ARCHITECTURES=arm64
name: Wheels for ${{ matrix.target.name }}
runs-on: ${{ matrix.target.os }}
@@ -32,6 +38,10 @@ jobs:
with:
python-version: '3.8'
+ - name: Prepare Python environment
+ run: >-
+ pip install setuptools wheel cython==0.29.* pytest
+
- name: Install dependencies on Windows
if: startsWith(matrix.config.name, 'Windows')
run: |
@@ -53,12 +63,12 @@ jobs:
cmake --version
- name: Build binary wheels
- uses: pypa/cibuildwheel@v2.20.0
+ uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS: >-
${{ matrix.target.archs }}
CIBW_BEFORE_ALL: >-
- cmake -DBUILD_INTERFACE_PYTHON=ON -DTEST_OPENMP=OFF -DBUILD_EXAMPLES=OFF -S . -B build &&
+ cmake -DBUILD_INTERFACE_PYTHON=ON -DTEST_OPENMP=OFF -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release ${{ matrix.target.extra_option }} -S . -B build &&
cmake --build build --config Release --clean-first --target nomadStatic --parallel 2
CIBW_ENVIRONMENT: >-
NOMAD_SRC=../../src
@@ -70,7 +80,9 @@ jobs:
CIBW_BUILD_FRONTEND: >-
build
CIBW_BUILD_VERBOSITY: >-
- 3
+ 2
+ CIBW_SKIP: >-
+ pp*
with:
output-dir: wheelhouse
package-dir: interfaces/PyNomad
@@ -78,16 +90,17 @@ jobs:
- name: Collect wheels for processing
uses: actions/upload-artifact@v4
with:
+ name: binary-${{ matrix.target.name }}
path: wheelhouse/*.whl
# We use pypa/gh-action-pypi-publish to upload the binary wheels onto PyPi.
pypi-publish:
- name: Publish to PyPi
+ name: Publish to TestPyPi (testing)
runs-on: ubuntu-latest
needs: build
# Specifying a GitHub environment is optional, but strongly encouraged
- environment: master
+ environment: develop
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
@@ -96,8 +109,11 @@ jobs:
- name: Collect wheels for publication
uses: actions/download-artifact@v4
with:
- name: artifact
+ pattern: binary-*
+ merge-multiple: true
path: dist
- - name: Publish wheels to PyPi
+ - name: Publish wheels to TestPyPi
uses: pypa/gh-action-pypi-publish@release/v1
+ with:
+ repository_url: https://test.pypi.org/legacy/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 005e7a34..c66c54ca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,10 +7,10 @@ cmake_minimum_required(VERSION 3.15...3.15)
# Warning. This must be consistent with src/nomad_version.hpp
set(NOMAD_VERSION_MAJOR 4)
-set(NOMAD_VERSION_MINOR 4)
-set(NOMAD_VERSION_PATCH 0)
-set(NOMAD_VERSION ${NOMAD_VERSION_MAJOR}.${NOMAD_VERSION_MINOR}.${NOMAD_VERSION_PATCH})
+set(NOMAD_VERSION_MINOR 5)
+set(NOMAD_VERSION_PATCH beta1) # The beta version betaX is for develop branch of the public repo.
+set(NOMAD_VERSION ${NOMAD_VERSION_MAJOR}.${NOMAD_VERSION_MINOR}.${NOMAD_VERSION_PATCH})
# name of the project
# Need to update when version changes
@@ -29,8 +29,8 @@ endif()
# Need to update when version changes
set(NOMAD_SRC_TEMPLATE NOMAD_${NOMAD_VERSION_MAJOR}_${NOMAD_VERSION_MINOR})
-# use standard compilers parameters for c++14
-SET(CMAKE_CXX_STANDARD 14 )
+# use standard compilers parameters for c++17
+SET(CMAKE_CXX_STANDARD 17 )
SET(CMAKE_CXX_STANDARD_REQUIRED ON )
# Disable in-source builds to prevent source tree corruption.
@@ -42,7 +42,7 @@ endif()
#check compiler version
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- # require at least gcc 4
+ # require at least gcc 8
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
message(FATAL_ERROR "GCC version < 8 has not been tested for Nomad")
endif()
@@ -53,7 +53,7 @@ elseif (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message(FATAL_ERROR "Clang version has not been tested for Nomad")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
- # require at least 15.0 (MSVC 2017) for C++14 support
+ # require at least 15.8 (MSVC 2017) for C++17 support
if (MSVC_TOOLSET_VERSION VERSION_LESS 141)
message(FATAL_ERROR "MSVC version ${CMAKE_CXX_COMPILER_VERSION} has not been tested for Nomad")
endif()
@@ -72,9 +72,25 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#
# Message for starting configuration
#
-message(CHECK_START " Configuring custom options")
+message(CHECK_START "Configuring custom options")
list(APPEND CMAKE_MESSAGE_INDENT " ")
+#
+# Modify the build type if not specified on the command
+#
+if (CMAKE_CONFIGURATION_TYPES)
+ message(STATUS " Multi-configuration generator detected. Use the --config option during build to specify the build type (Release, Debug, ...).")
+else()
+ if (NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Release" CACHE PATH "..." FORCE)
+ message(STATUS " Build type not set explicitly. Default is set to Release. To force build type selection, use --DCMAKE_BUILD_TYPE=xxx, options are Debug Release RelWithDebInfo MinSizeRel.")
+ else()
+ message(STATUS " Build type is ${CMAKE_BUILD_TYPE}")
+ endif()
+endif()
+
+
+
#
# Modify the install prefix if not specified on the command
#
@@ -83,6 +99,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
message(STATUS " Installation prefix set to ${CMAKE_INSTALL_PREFIX}")
+
#
# Choose to build with time stats enabled
#
@@ -123,6 +140,7 @@ else()
message(STATUS " Examples NOT built")
endif()
+
#
# Choose to build the C interface
#
@@ -140,15 +158,11 @@ endif()
#
option(BUILD_INTERFACE_PYTHON "Option to build Python interface to Nomad" OFF)
if(BUILD_INTERFACE_PYTHON MATCHES ON)
- if(OpenMP_FOUND)
- message(STATUS " Warning: Cannot build Python interface with OpenMP enabled")
- else()
- set(Python3_FIND_VIRTUALENV "First")
- find_package(Python 3.6 QUIET REQUIRED)
+ set(Python3_FIND_VIRTUALENV "First") # Using virtualenv to have cython and wheel is easy
+ find_package(Python 3.8 QUIET REQUIRED)
message(CHECK_START " Configuring build for Python interface (Python ${Python_VERSION})")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/interfaces/PyNomad)
message(CHECK_PASS " done")
- endif()
else()
message(STATUS " Python interface to Nomad NOT built")
endif()
@@ -240,14 +254,13 @@ else()
message(STATUS " Sgtelib library will NOT be used\n")
endif()
-
-
#
# Custom options final message
#
list(REMOVE_ITEM CMAKE_MESSAGE_INDENT " ")
message(CHECK_PASS " done")
+
#
# Add nomad app directory for building
#
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index c0178b2a..2508e00f 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -13,3 +13,4 @@ Ludovic Salomon
Renaud Saltet
Jan Provaznik
Tangi Migot
+Edward Hallé-Hannan
diff --git a/README.txt b/README.txt
index 32b9c306..852725b4 100644
--- a/README.txt
+++ b/README.txt
@@ -126,13 +126,11 @@ cmake -S . -B build/release
addpath(strcat(getenv('NOMAD_HOME'),'/build/release/bin'))
To enable *Python* interface (PyNomad) building:
- cmake -DBUILD_INTERFACE_PYTHON=ON -DTEST_OPENMP=OFF -S . -B build/release
+ cmake -DBUILD_INTERFACE_PYTHON=ON -S . -B build/release
! Before proceeding, have a look into
$NOMAD_HOME/interfaces/PyNomad/readme.txt
- ! The Python interface will not be built if OpenMP is enabled.
-
! More details are provided in $NOMAD_HOME/interfaces/PyNomad/readme.txt
! Building requires to have Cython. Cython can be obtained with
@@ -151,8 +149,10 @@ cmake --build build/release (for *OSX* and *Linux*)
Option --parallel xx can be added for faster build.
- The option --config Release should be used on *Windows* to build only
+ The option --config Release should be used on *Windows*
+ multi-configuration build environment (VisualStudio) to build only
Release configuration. The default configuration is Debug.
+ The same option should be used for *OSX* when using a *Xcode* project.
cmake --install build/release --config Release (for *Windows*)
or
diff --git a/ROADMAP.md b/ROADMAP.md
index acb8704a..782ec1ad 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -1,11 +1,9 @@
## Next release
-### v4.5 - Not before July 2024
+### v4.6 - Not before July 2025
-These are the features we consider for 4.5:
+These are the features we consider for 4.6:
-* Periodic variables
-
-* COOP-Mads for parallel Mads optimization
+* Paralel run of multiple algorithms
* Suggest and Observe paradigm without control on the evaluations
diff --git a/doc/doxygen/Doxyfile b/doc/doxygen/Doxyfile
index a0d3b5d6..dd73ab7f 100644
--- a/doc/doxygen/Doxyfile
+++ b/doc/doxygen/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = "NOMAD Source"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = "Version 4.2"
+PROJECT_NUMBER = "Version 4.5"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/doc/user_guide/source/AdvancedFunctionalities.rst b/doc/user_guide/source/AdvancedFunctionalities.rst
index 618ed676..e53dc90e 100644
--- a/doc/user_guide/source/AdvancedFunctionalities.rst
+++ b/doc/user_guide/source/AdvancedFunctionalities.rst
@@ -277,6 +277,47 @@ only for point evaluation.
An example of usage of PSD-MADS in library mode is in
``$NOMAD_HOME/examples/advanced/library/PSDMads``.
+.. _multiobjective_optimization:
+
+Multiobjective optimization
+---------------------------
+
+NOMAD can solve multiobjective optimization problems in search of a Pareto front. An example of a multiobjective problem solved by
+NOMAD in library mode can be found at ``$NOMAD_HOME/examples/basic/library/multi_obj``. Two examples are also proposed in batch mode at
+``$NOMAD_HOME/examples/basic/batch/multi_obj`` and ``$NOMAD_HOME/examples/basic/batch/multi_obj2``.
+
+NOMAD performs multiobjective optimization through the DMulti-MADS algorithm proposed in [BiLedSa2020]_ and [BiLedSa2024]_. The
+DMulti-MADS algorithm solves multiobjective optimization problems of the form
+
+.. math::
+
+ \min_{x \in \Omega} f(x) = (f_1(x), f_2(x), \ldots, f_m(x))^\top
+
+where :math:`4 \geq m \geq 2` is the number of objectives.
+
+DMulti-MADS extends the MADS algorithm with progressive barrier approach [AuDe09a]_ to multiobjective optimization and improves
+along the iterations a current set of non-dominated solutions. It can be used for unconstrained/constrained/mixed-integer
+blackbox multiobjective optimization.
+
+To activate the DMulti-MADS algorithm, at least two arguments of the parameter ``BB_OUTPUT_TYPE`` must be set to OBJ and the flag
+``DMULTIMADS_OPTIMIZATION`` set to ``true``. DMulti-MADS does not perform well with ``openMP`` and cannot use the ``ORTHO N+1 QUAD``
+strategy. Additional parameters are:
+
+ `*` `DMULTIMADS_NM_STRATEGY`` decides which single-objective strategy to use for the Nelder-Mead search step. It can be set at ``DOM`` or ``MULTI``.
+
+ `*` `DMULTIMADS_QUAD_MODEL_STRATEGY`` decides which single-objective strategy to use for the quadratic model search step. It can be set at ``DMS``, ``DOM`` or ``MULTI``.
+
+These searches bring a significant performance boost in most of the applications solved, but can considerably slow the resolution in terms of computational time (up to x10).
+If one wants faster resolution (at the detriment of solution quality), one can deactivate first the ``QUAD_MODEL_SEARCH`` and if not sufficient enough the
+``NM_SEARCH``.
+
+Multiobjective optimization problems are generally more difficult to solve than their single-objective counterparts. The more objectives, the more expensive and
+difficult to interpret. For this reason, NOMAD cannot tackle problems with more than 4 objectives.
+
+Multiobjective optimization is also available for other programming languages: see ``${NOMAD_HOME}/examples/advanced/library/c_api/example3`` for an example in ``c``
+and ``${NOMAD_HOME}/examples/advanced/library/PyNomad/simpleExample_PbMultiObj.py`` to solve multiobjective blackbox problems from ``Python``.
+
+
.. _disco_mads:
DISCO-Mads
@@ -378,6 +419,14 @@ NOMAD will start where it was, with evaluation 101.
Parallel space decomposition of the mesh adaptive direct search algorithm.
*SIAM Journal on Optimization*, 19(3):1150–1170, 2008.
+ .. [BiLedSa2020] J. Bigeon, S. Le Digabel, and L. Salomon.
+ DMulti-MADS: Mesh adaptive direct multisearch for bound-constrained blackbox multiobjective optimization.
+ *Computational Optimization and Applications*, 79(2):301–338, 2021.
+
+ .. [BiLedSa2024] J. Bigeon, S. Le Digabel, and L. Salomon.
+ Handling of constraints in multiobjective blackbox optimization.
+ *Computational Optimization and Applications*, 9(1):69–113, 2024.
+
.. [BoDeFrSeToTr99a] A.J. Booker, J.E. Dennis, Jr., P.D. Frank, D.B. Serafini, V. Torczon, and M.W. Trosset.
A Rigorous Framework for Optimization of Expensive Functions by Surrogates.
*Structural and Multidisciplinary Optimization*, 17(1):1–13, 1999.
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 5735faa9..9c107011 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,37 +1,40 @@
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/example1)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/example2)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/example3)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/example4)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/multi_obj)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/single_obj_parallel)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/StopOnFTarget)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/library/CustomSurrogateOrdering)
+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/FixedVariable)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/NMonly)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/Restart)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/Restart_VNS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/exampleSuggestAndObserve)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/CustomOpportunistic)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/CustomPollMethod)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/CustomSearchMethod)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/DiscoMads/EscapeDiscontinuities)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/DiscoMads/EscapeHiddenConstraints)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/HandlingHiddenConstraints)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/StopIfBBFails)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/NestedOptim)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/StopOnConsecutiveFails)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/CustomCompForOrdering)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/CustomStatSum)
if(OpenMP_CXX_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/PSDMads)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/COOPMads)
endif()
if (BUILD_INTERFACE_C MATCHES ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/c_api/example1)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/c_api/example2)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/library/c_api/example3)
endif()
# For running the tests on the batch examples we need to build the blackbox
# AND install
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/example1)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/single_obj)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/multi_obj)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/multi_obj2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/surrogate_sort)
@@ -40,12 +43,13 @@ if(OpenMP_CXX_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/single_obj_parallel)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/basic/batch/single_obj_MPIparallel)
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/BBOutputRedirection)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/LHonly)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/CountEval)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/FixedVariable)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/SuggestAndObserve)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/DiscoMads)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/UseCacheFileForRerun)
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/advanced/batch/BBOutputRedirection)
# The script for running library examples is created in a temp directory
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/runExampleTest.sh
diff --git a/examples/advanced/batch/BBOutputRedirection/CMakeLists.txt b/examples/advanced/batch/BBOutputRedirection/CMakeLists.txt
index ef27350c..2dece6c1 100644
--- a/examples/advanced/batch/BBOutputRedirection/CMakeLists.txt
+++ b/examples/advanced/batch/BBOutputRedirection/CMakeLists.txt
@@ -1,15 +1,15 @@
set(CMAKE_EXECUTABLE_SUFFIX .exe)
-add_executable(bb5.exe bb5.cpp )
-set_target_properties(bb5.exe PROPERTIES SUFFIX "")
+add_executable(bb_redirect.exe bb_redirect.cpp )
+set_target_properties(bb_redirect.exe PROPERTIES SUFFIX "")
# installing executables and libraries
-install(TARGETS bb5.exe
+install(TARGETS bb_redirect.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
# Add a test for this example
-message(STATUS " Add example batch #5")
+message(STATUS " Add example advanced batch BB redirection")
-# Test run in working directory AFTER install of bb5.exe executable
-add_test(NAME Example5BasicBatch
+# Test run in working directory AFTER install of bb_redirect.exe executable
+add_test(NAME ExampleAdvancedBatchRedirect
COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
diff --git a/examples/advanced/batch/BBOutputRedirection/bb_redirect.cpp b/examples/advanced/batch/BBOutputRedirection/bb_redirect.cpp
new file mode 100644
index 00000000..1e9b9fad
--- /dev/null
+++ b/examples/advanced/batch/BBOutputRedirection/bb_redirect.cpp
@@ -0,0 +1,158 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+//
+// BB_5
+//
+// Created by Christophe Tribes
+//
+#include
+#include
+#include
+#include
+using namespace std;
+
+
+// Blackbox manages sending the results in the nomad output file.
+// The name of the output MUST be inputfilename.output.
+// INPUT and OUTPUT files have a fixed name during optimization.
+// Some verbose can be displayed on the standard output or standard error and will not be considered by Nomad
+// The verbose is stored in a log file.
+int main(int argc, const char ** argv)
+{
+
+ double f = 1e20;
+ double x[2];
+ if (argc >=2)
+ {
+ // Output filename MUST be input file name + ".output"
+ std::string outputfilename = std::string(argv[1]) + ".output";
+
+ ifstream in (argv[1]);
+ for ( int i = 0 ; i < 2 ; i++ )
+ {
+ in >> x[i];
+ }
+ if ( in.fail() )
+ {
+ // std::cout << "Reading input file " << argv[1] << " fails. Nothing to output. Return execution status 1." << std::endl;
+ return 1;
+ }
+ std::cout << "Input vector x ( " << x[0] << " " << x[1] << " )" << std::endl;
+
+ f = pow (5 * x[0]-2 , 4) + pow (5 * x[0]-2, 2) * pow( x[1] , 2) +pow ( 3 * x[1] + 1 , 2);
+
+ std::cout << "Objective computed successfully. F(x)=" << f << std::endl;
+
+ ofstream outfile;
+ outfile.open(outputfilename.c_str(), std::ofstream::trunc);
+ if (outfile.fail())
+ {
+ std::cout << "Cannot open output file " << outputfilename.c_str() << std::endl;
+ }
+ else
+ {
+ std::cout << "Output objective value in file "<< outputfilename.c_str() << std::endl;
+ }
+ outfile << f << std::endl;
+ outfile.close();
+
+ return 0;
+ }
+ else
+ {
+ std::cout << "Input file name is not provided to the blackbox" << std::endl;
+ return 1;
+ }
+
+ }
+
diff --git a/examples/advanced/batch/BBOutputRedirection/param.txt b/examples/advanced/batch/BBOutputRedirection/param.txt
index ffece1c2..cb53b4e8 100644
--- a/examples/advanced/batch/BBOutputRedirection/param.txt
+++ b/examples/advanced/batch/BBOutputRedirection/param.txt
@@ -3,21 +3,21 @@
DIMENSION 2 # number of variables
-BB_EXE bb5.exe # 'bb5.exe' is a program that
- # takes in argument the name of
- # a text file ('input filename')
- # containing 2
- # values, and that write 1
- # values that correspond to the
- # objective function value (OBJ)
- # in a file inputfilename.output
- # IN THAT CASE WE MUST HAVE THE OPTION
- # BB_REDIRECTION no
- # To have log file use BB_EXE "bb5.exe $>> $log.txt"
+BB_EXE bb_redirect.exe # 'bb_redirect.exe' is a program that
+ # takes in argument the name of
+ # a text file ('input filename')
+ # containing 2
+ # values, and that write 1
+ # values that correspond to the
+ # objective function value (OBJ)
+ # in a file inputfilename.output
+ # IN THAT CASE WE MUST HAVE THE OPTION
+ # BB_REDIRECTION no
+ # To have log file use BB_EXE "bb_redirect.exe $>> $log.txt"
BB_OUTPUT_TYPE OBJ
-BB_REDIRECTION no # For a blackbox that manages the output file (default
- # is redirection), NOMAD expect an output file with a name
+BB_REDIRECTION no # For a blackbox that manages the output file
+ # NOMAD expect an output file with a name
# of the input file + ".output'
# INPUT and OUTPUT files have a fixed name
# during optimization.
diff --git a/examples/advanced/batch/CountEval/CMakeLists.txt b/examples/advanced/batch/CountEval/CMakeLists.txt
new file mode 100644
index 00000000..51db91c5
--- /dev/null
+++ b/examples/advanced/batch/CountEval/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(CMAKE_EXECUTABLE_SUFFIX .exe)
+add_executable(bb_cnt_eval.exe bb_cnt_eval.cpp )
+set_target_properties(bb_cnt_eval.exe PROPERTIES SUFFIX "")
+
+# installing executables and libraries
+install(TARGETS bb_cnt_eval.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+# Add a test for this example
+message(STATUS " Add example advanced batch count eval")
+
+# Test run in working directory AFTER install of bb_cnt_eval.exe executable
+add_test(NAME CountEvalAdvancedBatch
+ COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
diff --git a/examples/advanced/batch/BBOutputRedirection/bb5.cpp b/examples/advanced/batch/CountEval/bb_cnt_eval.cpp
similarity index 64%
rename from examples/advanced/batch/BBOutputRedirection/bb5.cpp
rename to examples/advanced/batch/CountEval/bb_cnt_eval.cpp
index 84085e28..563f8386 100644
--- a/examples/advanced/batch/BBOutputRedirection/bb5.cpp
+++ b/examples/advanced/batch/CountEval/bb_cnt_eval.cpp
@@ -44,69 +44,102 @@
/* */
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
-//
-// BB_5
-//
-// Created by CT
-//
-#include
+#include // For sqrt
+#include // For ifstream
#include
-#include
-#include
-using namespace std;
+#include // For logic_error
+#include
+const int n = 10;
-// Blackbox manages sending the results in the nomad output file.
-// The name of the output MUST be inputfilename.output.
-// INPUT and OUTPUT files have a fixed name during optimization.
-// Some verbose can be displayed on the standard output or standard error and will not be considered by Nomad
-// The verbose can be send to a log file (see param.txt file).
-int main(int argc, const char ** argv)
+int main (int argc, char **argv)
{
-
- double f = 1e20;
- double x[2];
- if (argc >=2)
+ bool eval_ok = false;
+
+ // Remotely based on G2.
+ double f = 1e+20, g1 = 1e+20, g2 = 1e+20, g3 = 1e+20;
+ double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, prod1 = 1.0, prod2 = 1.0;
+ double x[n];
+
+ bool x0read = false;
+ if (argc >= 2)
{
- // Output filename MUST be input file name + ".output"
- std::string outputfilename = std::string(argv[1]) + ".output";
-
- ifstream in (argv[1]);
- for ( int i = 0 ; i < 2 ; i++ )
+ std::string x0file = argv[1];
+ std::ifstream in (argv[1]);
+ for (int i = 0; i < n; i++)
{
- in >> x[i];
+ if (in.fail())
+ {
+ std::cerr << "Error reading file " << x0file << " for x0." << std::endl;
+ x0read = false;
+ break;
+ }
+ in >> x[i];
+ x0read = true;
}
- if ( in.fail() )
- {
- // std::cout << "Reading input file " << argv[1] << " fails. Nothing to output. Return execution status 1." << std::endl;
- return 1;
- }
- std::cout << "Input vector x ( " << x[0] << " " << x[1] << " )" << std::endl;
-
- f = pow (5 * x[0]-2 , 4) + pow (5 * x[0]-2, 2) * pow( x[1] , 2) +pow ( 3 * x[1] + 1 , 2);
+ in.close();
+ }
- std::cout << "Objective computed successfully. F(x)=" << f << std::endl;
-
- ofstream outfile;
- outfile.open(outputfilename.c_str(), std::ofstream::trunc);
- if (outfile.fail())
+ if (x0read)
+ {
+ try
{
- std::cout << "Cannot open output file " << outputfilename.c_str() << std::endl;
+ for (int i = 0; i < n ; i++)
+ {
+ sum1 += pow(cos(x[i]), 4);
+ sum2 += x[i];
+ sum3 += (i+1)*x[i]*x[i];
+ prod1 *= pow(cos(x[i]), 2);
+ if (prod2 != 0.0)
+ {
+ if (x[i] == 0.0)
+ {
+ prod2 = 0.0;
+ }
+ else
+ {
+ prod2 *= x[i];
+ }
+ }
+ }
+
+ g1 = -prod2 + 0.75;
+
+ // Let's say g1 is a hidden constraint. We don't want to count when it is not verified
+ if (g1>0)
+ {
+ std::cout << 0 << " Inf" << std::endl;
+ return 1;
+ }
+
+ g2 = sum2 -7.5 * n;
+
+ f = 10*g1 + 10*g2;
+ if (0.0 != sum3)
+ {
+ f -= (sum1 -2*prod1) / std::abs(sqrt(sum3));
+ }
+ // Scale
+ if (!std::isnan(f))
+ {
+ f *= 1e-5;
+ }
+
+ eval_ok = !std::isnan(f);
+
+ g3 = - (f + 2000);
}
- else
+ catch (std::exception &e)
{
- std::cout << "Output objective value in file "<< outputfilename.c_str() << std::endl;
+ std::string err("Exception: ");
+ err += e.what();
+ throw std::logic_error(err);
}
- outfile << f << std::endl;
- outfile.close();
-
- return 0;
}
- else
- {
- std::cout << "Input file name is not provided to the blackbox" << std::endl;
- return 1;
- }
-
- }
-
+
+
+ std::cout << 1 << " " << f << " " << g2 << " " << g3 << std::endl;
+
+ // Return 0 if eval_ok.
+ return !eval_ok;
+}
diff --git a/examples/advanced/batch/CountEval/param.txt b/examples/advanced/batch/CountEval/param.txt
new file mode 100644
index 00000000..6b8ccc60
--- /dev/null
+++ b/examples/advanced/batch/CountEval/param.txt
@@ -0,0 +1,38 @@
+#
+# Example: count eval flag is provided by the blackbox
+# If a hidden constraint is not verified, the remaining constraints are not computed,
+# the objective is set to infinity and the evaluation is not counted.
+# NOTE: For library mode, the countEval flag is an output argument of the eval_x function.
+
+
+# PROBLEM PARAMETERS
+####################
+
+# Number of variables
+DIMENSION 10
+
+# Black box
+BB_EXE bb_cnt_eval.exe
+BB_OUTPUT_TYPE CNT_EVAL OBJ PB PB # CNT_EVAL is for the flag passed from the bb to Nomad
+
+# Starting point
+X0 ( 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 )
+
+# Bounds are useful to avoid extreme values
+LOWER_BOUND * -20.0
+UPPER_BOUND * 20.0
+
+
+# ALGORITHM PARAMETERS
+######################
+
+# The algorithm terminates after that number black-box evaluations
+MAX_BB_EVAL 100
+
+# Formatted stats into a file
+STATS_FILE stats.txt BBE SOL BBO
+
+DISPLAY_ALL_EVAL yes
+
+
+
diff --git a/examples/advanced/batch/DiscoMads/CMakeLists.txt b/examples/advanced/batch/DiscoMads/CMakeLists.txt
index 41c65320..31c8f640 100644
--- a/examples/advanced/batch/DiscoMads/CMakeLists.txt
+++ b/examples/advanced/batch/DiscoMads/CMakeLists.txt
@@ -6,11 +6,4 @@ set_target_properties(bb_disco.exe PROPERTIES SUFFIX "")
install(TARGETS bb_disco.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example batch DiscoMads")
- # Test run in working directory AFTER install of bb executable
- add_test(NAME ExampleAdvancedBatchDiscoMadsDiscont
- COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad paramEscapeDiscont.txt
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-endif()
+# No test for this example
diff --git a/examples/advanced/batch/DiscoMads/paramEscapeDiscont.txt b/examples/advanced/batch/DiscoMads/paramEscapeDiscont.txt
index 31e43889..f8e6bff2 100644
--- a/examples/advanced/batch/DiscoMads/paramEscapeDiscont.txt
+++ b/examples/advanced/batch/DiscoMads/paramEscapeDiscont.txt
@@ -66,7 +66,6 @@ DISCO_MADS_REVEALING_POLL_NB_POINTS 2 # defaut= problem dimension
# RECOMMENDED PARAMETERS FOR DISCOMADS
######################
-NB_THREADS_OPENMP 1 # DiscoMads works with OpenMP but has not been extensively tested
# Quadratic model: desactivated as they may be slow with DiscoMads
QUAD_MODEL_SEARCH false
diff --git a/examples/advanced/batch/DiscoMads/paramEscapeHiddenConstraints.txt b/examples/advanced/batch/DiscoMads/paramEscapeHiddenConstraints.txt
new file mode 100644
index 00000000..b81502a9
--- /dev/null
+++ b/examples/advanced/batch/DiscoMads/paramEscapeHiddenConstraints.txt
@@ -0,0 +1,85 @@
+## Run DiscoMads to reveal and escape hidden constraints regions
+
+
+# The problem is described sec. 5.3 "5.3. Design of a styrene production process." of [1] and more detailled
+# in section 2.5.4, p.61 of [2].
+
+# IMPORTANT : The blackbox used is Styrene, run in hybrid library/batch mode.
+# The styrene standalone executable is registered with "BB_EXE truth.exe"
+# To run this optimization, this file must be executed in a path where styrene truth.exe executable is available.
+# Styrene sources are available at https://github.com/bbopt/styrene and must be compiled prior to run this optimization.
+
+# [1] Escaping Unknown Discontinuous Regions in Blackbox Optimization
+# Charles Audet, Alain Batailly, and Solène Kojtych, SIAM Journal on Optimization, 2022
+# doi/10.1137/21M1420915
+# [2] Contributions à l'optimisation de systèmes mécaniques non réguliers : reconception
+# d'aubes de compresseur
+# Solène Kojtych, Ph.D. thesis 2022
+# doi/10.1137/21M1420915
+####################
+
+
+# PROBLEM PARAMETERS
+####################
+
+# Number of variables
+DIMENSION 8
+
+# Black box
+BB_EXE truth.exe
+
+# BB output (-R indicates a revealing output)
+BB_OUTPUT_TYPE EB EB EB EB PB PB PB PB PB PB PB OBJ-R
+# Only revealing output are considered to reveal hidden constraints with DiscoMads
+
+# Starting point
+X0 ( 100 87.82280202 95.36797348 0 0 49.04338841 42.41599794 41.01732603 )
+
+LOWER_BOUND * 0
+UPPER_BOUND * 100
+
+# GENERAL ALGORITHM PARAMETERS
+######################
+
+# The algorithm terminates after that number black-box evaluations
+# or when min mesh size is reached
+MAX_BB_EVAL 1000
+MIN_MESH_SIZE * 1E-7
+
+# Parameters for display degree
+DISPLAY_DEGREE 2
+DISPLAY_ALL_EVAL true
+DISPLAY_STATS BBE OBJ
+
+
+# DISCOMADS PARAMETERS
+######################
+DISCO_MADS_OPTIMIZATION true
+DISCO_MADS_HID_CONST true # escape hidden constraints instead of discontinuities
+
+# Remoteness to hidden constraints wished
+DISCO_MADS_EXCLUSION_RADIUS 15
+
+# Revealing poll
+DISCO_MADS_REVEALING_POLL_RADIUS 20
+DISCO_MADS_REVEALING_POLL_NB_POINTS 8 # default= problem dimension
+
+
+# RECOMMENDED PARAMETERS FOR DISCOMADS
+######################
+
+# Quadratic model: desactivated as they may be slow with DiscoMads
+QUAD_MODEL_SEARCH false
+EVAL_QUEUE_SORT DIR_LAST_SUCCESS
+DIRECTION_TYPE ORTHO 2N
+
+#INITIAL_FRAME_SIZE * 5.05
+
+# SPECIFIC THESIS PARAMETERS USED IN [2]
+######################
+## Uncomment the following parameters to reproduce the thesis parameters
+#DIRECTION_TYPE ORTHO N+1 NEG # comment previous "DIRECTION_TYPE" command
+#SEED 3698370
+#ANISOTROPIC_MESH false
+#NM_SEARCH false
+#SPECULATIVE_SEARCH true
\ No newline at end of file
diff --git a/examples/advanced/batch/FixedVariable/CMakeLists.txt b/examples/advanced/batch/FixedVariable/CMakeLists.txt
index cbc42840..5c1d7145 100644
--- a/examples/advanced/batch/FixedVariable/CMakeLists.txt
+++ b/examples/advanced/batch/FixedVariable/CMakeLists.txt
@@ -6,20 +6,4 @@ set_target_properties(uu.exe PROPERTIES SUFFIX "")
install(TARGETS uu.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
-
- message(STATUS " Add example batch fixed variables")
- # Test run in working directory AFTER install of bb executable
-
- if (WIN32)
- add_test(NAME ExampleAdvancedBatchFixedVariables
- COMMAND bash.exe runFixedWin.sh ${CMAKE_INSTALL_PREFIX}
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- # Temp comment
- #else()
- # add_test(NAME ExampleAdvancedBatchFixedVariables
- # COMMAND ./runFixed.sh ${CMAKE_INSTALL_PREFIX}
- # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- endif()
-endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/batch/FixedVariable/param.txt b/examples/advanced/batch/FixedVariable/param.txt
index a755b5b7..e3103b78 100644
--- a/examples/advanced/batch/FixedVariable/param.txt
+++ b/examples/advanced/batch/FixedVariable/param.txt
@@ -23,8 +23,6 @@ MAX_BB_EVAL 1000
# Parameters for display degree
DISPLAY_DEGREE 2
DISPLAY_ALL_EVAL true
-DISPLAY_INFEASIBLE true
-DISPLAY_UNSUCCESSFUL false
GRANULARITY * 0.01
@@ -35,6 +33,8 @@ DISPLAY_STATS BBE ( SOL ) OBJ
BB_OUTPUT_TYPE PB OBJ
ADD_SEED_TO_FILE_NAMES false
+EVAL_OPPORTUNISTIC true
+H_MAX_0 200000
FIXED_VARIABLE 0-2
CACHE_FILE cache.txt
diff --git a/examples/advanced/batch/FixedVariable/param1.txt b/examples/advanced/batch/FixedVariable/param1.txt
index c722b308..3cd8cee7 100644
--- a/examples/advanced/batch/FixedVariable/param1.txt
+++ b/examples/advanced/batch/FixedVariable/param1.txt
@@ -21,11 +21,8 @@ UPPER_BOUND * 31.0
MAX_BB_EVAL 1000
# Parameters for display degree
-#DISPLAY_HEADER 0
DISPLAY_DEGREE 2
DISPLAY_ALL_EVAL false
-DISPLAY_INFEASIBLE false
-DISPLAY_UNSUCCESSFUL false
GRANULARITY * 0.01
@@ -39,10 +36,4 @@ EVAL_OPPORTUNISTIC true
H_MAX_0 200000
FIXED_VARIABLE 0-2
-#NB_THREADS_OPENMP 8
-
-HOT_RESTART_ON_USER_INTERRUPT false
-HOT_RESTART_READ_FILES false
-HOT_RESTART_WRITE_FILES false
CACHE_FILE cache.txt
-REJECT_UNKNOWN_PARAMETERS false
diff --git a/examples/advanced/batch/FixedVariable/param10.txt b/examples/advanced/batch/FixedVariable/param10.txt
index a9b5cada..56504b8b 100644
--- a/examples/advanced/batch/FixedVariable/param10.txt
+++ b/examples/advanced/batch/FixedVariable/param10.txt
@@ -22,11 +22,8 @@ UPPER_BOUND * 31.0
MAX_BB_EVAL 1000
# Parameters for display degree
-#DISPLAY_HEADER 0
DISPLAY_DEGREE 2
DISPLAY_ALL_EVAL true
-DISPLAY_INFEASIBLE true
-DISPLAY_UNSUCCESSFUL true
GRANULARITY * 0.01
@@ -36,4 +33,7 @@ DISPLAY_STATS BBE ( MESH_SIZE ) ( POLL_SIZE ) ( SOL ) OBJ CONS_H
BB_OUTPUT_TYPE PB OBJ
ADD_SEED_TO_FILE_NAMES false
+EVAL_OPPORTUNISTIC true
+H_MAX_0 200000
+
CACHE_FILE cache.txt
diff --git a/examples/advanced/batch/FixedVariable/param2.txt b/examples/advanced/batch/FixedVariable/param2.txt
index 782df556..ef21c4fd 100644
--- a/examples/advanced/batch/FixedVariable/param2.txt
+++ b/examples/advanced/batch/FixedVariable/param2.txt
@@ -22,11 +22,7 @@ UPPER_BOUND * 31.0
MAX_BB_EVAL 1000
# Parameters for display degree
-#DISPLAY_HEADER 0
DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL false
-DISPLAY_INFEASIBLE false
-DISPLAY_UNSUCCESSFUL false
GRANULARITY * 0.01
@@ -36,6 +32,8 @@ DISPLAY_STATS BBE ( MESH_SIZE ) ( POLL_SIZE ) ( SOL ) OBJ
BB_OUTPUT_TYPE PB OBJ
ADD_SEED_TO_FILE_NAMES false
+EVAL_OPPORTUNISTIC true
+H_MAX_0 200000
FIXED_VARIABLE 2-3
CACHE_FILE cache.txt
diff --git a/examples/advanced/batch/FixedVariable/param3.txt b/examples/advanced/batch/FixedVariable/param3.txt
index 83f066f0..610a96b7 100644
--- a/examples/advanced/batch/FixedVariable/param3.txt
+++ b/examples/advanced/batch/FixedVariable/param3.txt
@@ -22,11 +22,7 @@ UPPER_BOUND * 31.0
MAX_BB_EVAL 1000
# Parameters for display degree
-#DISPLAY_HEADER 0
DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL false
-DISPLAY_INFEASIBLE false
-DISPLAY_UNSUCCESSFUL false
GRANULARITY * 0.01
@@ -36,6 +32,8 @@ DISPLAY_STATS BBE ( MESH_SIZE ) ( POLL_SIZE ) ( SOL ) OBJ
BB_OUTPUT_TYPE PB OBJ
ADD_SEED_TO_FILE_NAMES false
+EVAL_OPPORTUNISTIC true
+H_MAX_0 200000
FIXED_VARIABLE 3-4
CACHE_FILE cache.txt
diff --git a/examples/advanced/batch/FixedVariable/runFixed.sh b/examples/advanced/batch/FixedVariable/runFixed.sh
index 8aa88a81..039ff3cf 100755
--- a/examples/advanced/batch/FixedVariable/runFixed.sh
+++ b/examples/advanced/batch/FixedVariable/runFixed.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
#Batch executable to run a problem using a series of fixed values.
# Argument #1: path to Nomad install dir
diff --git a/examples/advanced/batch/FixedVariable/runFixedWin.sh b/examples/advanced/batch/FixedVariable/runFixedWin.sh
index 5abd30b5..ac27a4e2 100644
--- a/examples/advanced/batch/FixedVariable/runFixedWin.sh
+++ b/examples/advanced/batch/FixedVariable/runFixedWin.sh
@@ -1,21 +1,21 @@
#Batch executable to run a problem using a series of fixed values.
-# Argument #1: path to Nomad install dir
+nomad_exe=$1
rm -f cache.txt
# Fix 0-2
echo "Fix 0-2"
-%1\bin\nomad.exe param1.txt
+$nomad_exe param1.txt
echo "Cache size: "; wc -l cache.txt
# Fix 2-3
echo "Fix 2-3"
-%1\bin\nomad.exe param2.txt
+$nomad_exe param2.txt
echo "Cache size: "; wc -l cache.txt
# Fix 3-4
echo "Fix 3-4"
-%1\bin\nomad.exe param3.txt
+$nomad_exe param3.txt
echo "Cache size: "; wc -l cache.txt
# Fix nothing
echo "Fix nothing"
-%1\bin\nomad.exe param10.txt
+$nomad_exe param10.txt
echo "Cache size: "; wc -l cache.txt
diff --git a/examples/advanced/batch/IBEX/README.txt b/examples/advanced/batch/IBEX/README.txt
index 8a691f4d..03602a47 100644
--- a/examples/advanced/batch/IBEX/README.txt
+++ b/examples/advanced/batch/IBEX/README.txt
@@ -6,6 +6,4 @@ Then, you have to use the files "create_set" or "create_set_with_volume" to crea
However, if you don't want to create the Set, you can only provide the system file name thanks to the attribute SYSTEM_FILE_NAME and the Set will be created automatically in NOMAD. The argument SET_FILE (bool) defines if you already created the Set or if you only want to pass the system file.
-Two different use of NOMAD with IBEX are available. You can either call the Set in the BB file and project directly in the this file (see bb.cpp) or you can project the point in NOMAD, and in this case you give the informations needed thanks to the param.txt file, such as explained above.
-
-IMPORTANT: Modify the path to IBEX in bb.cpp before building the example
+Two differents use of NOMAD with IBEX are available. You can either call the Set in the BB file and project directly in the this file (see bb.cpp) or you can project the point in NOMAD, and in this case you give the informations needed thanks to the param.txt file, such as explained above.
diff --git a/examples/advanced/batch/IBEX/bb.cpp b/examples/advanced/batch/IBEX/bb.cpp
index ae39bc4f..f2a66e75 100644
--- a/examples/advanced/batch/IBEX/bb.cpp
+++ b/examples/advanced/batch/IBEX/bb.cpp
@@ -44,13 +44,58 @@
/* */
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
-
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
#include
#include
#include
#include
#include
-#include "/home/User/MyName/ibex-2.8.9/__build__/ibex.h" // IMPORTANT: Modify the path before building
+#include "/home/expert/Bureau/ibex-2.8.9/__build__/ibex.h"
using namespace std;
using namespace ibex;
diff --git a/examples/advanced/batch/LHonly/CMakeLists.txt b/examples/advanced/batch/LHonly/CMakeLists.txt
index 0fee1089..252f96f0 100644
--- a/examples/advanced/batch/LHonly/CMakeLists.txt
+++ b/examples/advanced/batch/LHonly/CMakeLists.txt
@@ -6,13 +6,4 @@ set_target_properties(u.exe PROPERTIES SUFFIX "")
install(TARGETS u.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example batch LHOnly")
-
- # Test run in working directory AFTER install of bb executable
- add_test(NAME ExampleAdvancedBatchLHOnly
- COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- )
-endif()
+# No test for this example
diff --git a/examples/advanced/batch/PSDMadsWithPythonBB/param.txt b/examples/advanced/batch/PSDMadsWithPythonBB/param.txt
index a82b5096..fc00b761 100755
--- a/examples/advanced/batch/PSDMadsWithPythonBB/param.txt
+++ b/examples/advanced/batch/PSDMadsWithPythonBB/param.txt
@@ -1,7 +1,3 @@
-# NOTE: Nomad executable needs openMP support
-# for this example to work
-
-
DIMENSION 50
BB_EXE '$python3 bb.py '
@@ -13,10 +9,10 @@ LOWER_BOUND * -10
UPPER_BOUND * 10
-MAX_BB_EVAL 10000
+MAX_BB_EVAL 1000
PSD_MADS_OPTIMIZATION yes
-NB_THREADS_OPENMP 4
+PSD_MADS_NB_SUBPROBLEM 4
DISPLAY_DEGREE 2
DISPLAY_STATS BBE ( SOL ) OBJ
diff --git a/examples/advanced/batch/SuggestAndObserve/CMakeLists.txt b/examples/advanced/batch/SuggestAndObserve/CMakeLists.txt
index 063df455..016caae5 100644
--- a/examples/advanced/batch/SuggestAndObserve/CMakeLists.txt
+++ b/examples/advanced/batch/SuggestAndObserve/CMakeLists.txt
@@ -23,19 +23,4 @@ endif()
install(TARGETS suggest.exe observe.exe bbr.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
-
- message(STATUS " Add example batch suggest and observe")
- # Test run in working directory AFTER install of bb executable
-
- if (WIN32)
- add_test(NAME ExampleAdvancedBatchSuggestAndObserve
- COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./loopSuggestAndObserve.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- else()
- add_test(NAME ExampleAdvancedBatchSuggestAndObserve
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./loopSuggestAndObserve.sh
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- endif()
-endif()
+# No test for this example
diff --git a/examples/advanced/batch/SuggestAndObserve/README.txt b/examples/advanced/batch/SuggestAndObserve/README.txt
new file mode 100644
index 00000000..7cebcd1e
--- /dev/null
+++ b/examples/advanced/batch/SuggestAndObserve/README.txt
@@ -0,0 +1,31 @@
+# Loop Suggest and Observe
+
+This project runs a loop of suggestion and observation using the executables `suggest.exe`, `bbr.exe`, and `observe.exe`.
+
+## Description
+
+The `loopSuggestAndObserve.sh` script executes a series of iterations where points are suggested, evaluated, and observed. The process continues until no new points are suggested or the maximum number of iterations is reached.
+
+## Usage
+
+To run the script, ensure that the executables `suggest.exe`, `bbr.exe`, and `observe.exe` are present in the same directory as the script. Then, execute the script with the following command:
+
+./loopSuggestAndObserve.sh
+
+## Generated Files
+
+. cache.txt, cache[1-9]*.txt: Cache files used and updated in each iteration.
+
+. x*.txt: Files containing the suggested points for each iteration.
+
+. f*.txt: Files containing the evaluation results for each iteration.
+
+. param[1-9]*.txt: Parameter files updated in each iteration.
+
+## Notes
+
+Ensure that the executables suggest.exe, bbr.exe, and observe.exe are properly compiled and accessible by using the CMake build procedure.
+
+The script is configured for a maximum of 10 iterations, but this number can be adjusted by modifying the condition in the until loop.
+
+
diff --git a/examples/advanced/batch/SuggestAndObserve/bbr.cpp b/examples/advanced/batch/SuggestAndObserve/bbr.cpp
index b759a51f..8d991b28 100644
--- a/examples/advanced/batch/SuggestAndObserve/bbr.cpp
+++ b/examples/advanced/batch/SuggestAndObserve/bbr.cpp
@@ -54,7 +54,7 @@
#define DIMENSION 2
-bool eval_xs(const std::vector> &xs, std::vector& fxs)
+bool eval_xs(const std::vector > &xs, std::vector& fxs)
{
bool eval_ok = false;
@@ -90,13 +90,13 @@ bool eval_xs(const std::vector> &xs, std::vector& fx
}
-std::vector> readXFile(const std::string& xFileName)
+std::vector > readXFile(const std::string& xFileName)
{
- std::vector> xs;
+ std::vector > xs;
std::ifstream in(xFileName);
// Get the input points
- while (!in.eof())
+ while (!in.eof() && in.good())
{
std::vector x(DIMENSION);
for (size_t i = 0; i < DIMENSION; i++)
@@ -106,6 +106,7 @@ std::vector> readXFile(const std::string& xFileName)
xs.push_back(x);
}
in.close();
+
xs.pop_back();
return xs;
diff --git a/examples/advanced/batch/SuggestAndObserve/utils.cpp b/examples/advanced/batch/SuggestAndObserve/utils.cpp
index a22bfd2c..49d6530f 100644
--- a/examples/advanced/batch/SuggestAndObserve/utils.cpp
+++ b/examples/advanced/batch/SuggestAndObserve/utils.cpp
@@ -77,9 +77,9 @@ void readXFile(const std::string& xFileName, NOMAD::ArrayOfPoint &aop)
readXFile(xFileName, xs);
aop.clear();
- for (auto x : xs)
+ for (const auto& x : xs)
{
- aop.push_back(NOMAD::Point(x));
+ aop.emplace_back(x);
}
}
@@ -94,19 +94,18 @@ void initParams(std::shared_ptr& params,
params->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(DIMENSION, 10.0));
NOMAD::BBOutputTypeList bbot; // Definition of output types
- bbot.push_back(NOMAD::BBOutputType::OBJ);
+ bbot.emplace_back(NOMAD::BBOutputType::OBJ);
params->setAttributeValue("BB_OUTPUT_TYPE", bbot);
-
params->setAttributeValue("CACHE_FILE", cacheFileName);
- for (auto paramAsString : additionalParams)
+ for (const auto& paramAsString : additionalParams)
{
params->readParamLine(paramAsString);
}
// Display parameters
- params->setAttributeValue("DISPLAY_DEGREE", 0);
+ //params->setAttributeValue("DISPLAY_DEGREE", 4);
// parameters validation
params->getPbParams()->doNotShowWarnings();
diff --git a/examples/advanced/batch/UseCacheFileForRerun/CMakeLists.txt b/examples/advanced/batch/UseCacheFileForRerun/CMakeLists.txt
index b8ec4a2e..3bc4fc3a 100644
--- a/examples/advanced/batch/UseCacheFileForRerun/CMakeLists.txt
+++ b/examples/advanced/batch/UseCacheFileForRerun/CMakeLists.txt
@@ -6,10 +6,4 @@ set_target_properties(bb_cache.exe PROPERTIES SUFFIX "")
install(TARGETS bb_cache.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-# message(STATUS " Add example batch for using cache file for rerun")
-
-# Test run in working directory AFTER install of bb_cache.exe executable
-# add_test(NAME ExampleAdvancedBatchCacheFileForRerun
-# COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
+# No test for this example
diff --git a/examples/advanced/batch/UseCacheFileForRerun/README.txt b/examples/advanced/batch/UseCacheFileForRerun/README.txt
new file mode 100644
index 00000000..33f355ac
--- /dev/null
+++ b/examples/advanced/batch/UseCacheFileForRerun/README.txt
@@ -0,0 +1,42 @@
+# Utilization of a cache file for a hot restart
+
+This project illustrates how a first optimization run can be continued with
+a second run with more evaluations.
+
+The example uses a cache file to resume an optimization if the initial attempt
+is prematurely stopped. To simulate this situation we have two parameter files
+that can be ran in sequence.
+
+This functionality is only possible if the problem definition is not changed
+between the runs.
+
+## Usage
+
+To run the first optimization execute the following command:
+
+$NOMAD_HOME/bin/nomad param_firstRun.txt
+
+This creates a cache file `cache.txt` containing 100 evaluated points.
+
+To continue this optimization with 50 more points, execute the following command:
+
+$NOMAD_HOME/bin/nomad param_secondRun.txt
+
+In the second run, the `MAX_BB_EVAL` parameter is increased to 150, and the
+`USE_CACHE_FILE_FOR_RERUN` option is enabled. This means that the first 100
+evaluations of the second run will be loaded from the cache file instead of
+being re-evaluated by the blackbox function. The optimization algorithm will
+then proceed with new evaluations until it reaches the maximum number of
+evaluations specified.
+
+
+
+## Notes
+
+Running two times using `param_firstRun.txt` will produce different results
+because the cache file is used. We can note that the cache hits increase between
+two runs.
+
+For using the best point obtained after a first run and stored in a cache,
+the user can remove initial point provide in `X0`.
+
\ No newline at end of file
diff --git a/examples/advanced/batch/UseCacheFileForRerun/param.txt b/examples/advanced/batch/UseCacheFileForRerun/param_firstRun.txt
similarity index 64%
rename from examples/advanced/batch/UseCacheFileForRerun/param.txt
rename to examples/advanced/batch/UseCacheFileForRerun/param_firstRun.txt
index 79aff37b..fe40e5fd 100644
--- a/examples/advanced/batch/UseCacheFileForRerun/param.txt
+++ b/examples/advanced/batch/UseCacheFileForRerun/param_firstRun.txt
@@ -23,13 +23,6 @@ UPPER_BOUND * 20.0
# The algorithm terminates after that number black-box evaluations
MAX_BB_EVAL 100
-
-# If cache.txt exits it will be used.
-# Possible Use Case:
-# - first run (no cache file) with max_bb_eval 100. Cache file is created
-# - increase max_bb_eval to 150.
-# - second run uses the first 100 in the cache file and continues with real bb evals to reach 150
-USE_CACHE_FILE_FOR_RERUN true
CACHE_FILE cache.txt
# Parameters for display
diff --git a/examples/advanced/batch/UseCacheFileForRerun/paramNextStep.txt b/examples/advanced/batch/UseCacheFileForRerun/param_secondRun.txt
similarity index 100%
rename from examples/advanced/batch/UseCacheFileForRerun/paramNextStep.txt
rename to examples/advanced/batch/UseCacheFileForRerun/param_secondRun.txt
diff --git a/examples/advanced/library/COOPMads/CMakeLists.txt b/examples/advanced/library/COOPMads/CMakeLists.txt
new file mode 100644
index 00000000..2fcc98c7
--- /dev/null
+++ b/examples/advanced/library/COOPMads/CMakeLists.txt
@@ -0,0 +1,31 @@
+# Example only for OPENMP build
+
+add_executable(rosenbrockCoop.exe rosenbrockCoop.cpp )
+
+target_include_directories(rosenbrockCoop.exe PRIVATE
+ ${CMAKE_SOURCE_DIR}/src)
+
+set_target_properties(rosenbrockCoop.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
+
+target_link_libraries(rosenbrockCoop.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
+
+# installing executables and libraries
+install(TARGETS rosenbrockCoop.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+
+# Add a test for this example
+message(STATUS " Add example test for COOPMads")
+
+if (WIN32)
+ add_test(NAME ExampleAdvancedCOOPMads
+ COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./rosenbrockCoop.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+else()
+ add_test(NAME ExampleAdvancedCOOPMads
+ COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./rosenbrockCoop.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+endif()
+
diff --git a/examples/advanced/library/COOPMads/rosenbrockCoop.cpp b/examples/advanced/library/COOPMads/rosenbrockCoop.cpp
new file mode 100644
index 00000000..0b50c00b
--- /dev/null
+++ b/examples/advanced/library/COOPMads/rosenbrockCoop.cpp
@@ -0,0 +1,164 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+/*--------------------------------------------*/
+/* Rosenbrock with dimension greater than 2 */
+/*--------------------------------------------*/
+#include "Nomad/nomad.hpp"
+#include "Type/DirectionType.hpp"
+#include "Type/EvalSortType.hpp"
+
+const size_t N = 20;
+
+/*----------------------------------------*/
+/* The problem */
+/*----------------------------------------*/
+class My_Evaluator : public NOMAD::Evaluator
+{
+private:
+
+public:
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
+ {}
+
+ ~My_Evaluator() override = default;
+
+ bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
+};
+
+
+/*----------------------------------------*/
+/* user-defined eval_x */
+/*----------------------------------------*/
+bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
+ const NOMAD::Double &hMax,
+ bool &countEval) const
+{
+
+ if (N%2 != 0)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
+ }
+
+ double f=0;
+ for ( size_t i = 1 ; i <= N/2 ; ++i ) {
+ f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
+ f += pow ( 1 - x[2*i-2].todouble() , 2 );
+ }
+ x.setBBO(std::to_string(f));
+
+ countEval = true; // count a black-box evaluation
+
+ return true; // the evaluation succeeded
+}
+
+
+void initAllParams(std::shared_ptr allParams)
+{
+ // Parameters creation
+ allParams->setAttributeValue("DIMENSION", N);
+ // 100 black-box evaluations
+ allParams->setAttributeValue("MAX_BB_EVAL", 400*N);
+
+
+ // Starting point
+ allParams->setAttributeValue("X0", NOMAD::Point(N, 0.5) );
+
+ // Bounds
+ allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(N, -10.0 ));
+ allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(N, 10.0 ));
+
+ allParams->setAttributeValue("COOP_MADS_OPTIMIZATION",true);
+ allParams->setAttributeValue("COOP_MADS_NB_PROBLEM", 5);
+ allParams->setAttributeValue("COOP_MADS_OPTIMIZATION_CACHE_SEARCH",true);
+
+ allParams->setAttributeValue("DIRECTION_TYPE",NOMAD::DirectionType::ORTHO_2N);
+
+ // Constraints and objective
+ NOMAD::BBOutputTypeList bbOutputTypes = {NOMAD::BBOutputType::OBJ};
+ allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
+
+ allParams->setAttributeValue("DISPLAY_DEGREE", 2);
+
+ NOMAD::ArrayOfString ds("BBE ( SOL ) OBJ");
+ allParams->setAttributeValue("DISPLAY_STATS", ds);
+
+ // Parameters validation
+ allParams->checkAndComply();
+
+}
+
+
+/*------------------------------------------*/
+/* NOMAD main function */
+/*------------------------------------------*/
+int main()
+{
+ NOMAD::MainStep TheMainStep;
+
+ auto params = std::make_shared();
+ initAllParams(params);
+ TheMainStep.setAllParameters(params);
+
+ // Custom Evaluator
+ auto ev = std::make_unique(params->getEvalParams());
+ TheMainStep.addEvaluator(std::move(ev));
+
+ try
+ {
+ TheMainStep.start();
+ TheMainStep.run();
+ TheMainStep.end();
+ }
+
+ catch(std::exception &e)
+ {
+ std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
+ }
+
+ return 0;
+}
diff --git a/examples/advanced/library/CustomCompForOrdering/CMakeLists.txt b/examples/advanced/library/CustomCompForOrdering/CMakeLists.txt
index 908d4935..004724aa 100644
--- a/examples/advanced/library/CustomCompForOrdering/CMakeLists.txt
+++ b/examples/advanced/library/CustomCompForOrdering/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS customCompForOrdering.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for custom ordering of points before evaluation")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedcustomCompForOrdering
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customCompForOrdering.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedcustomCompForOrdering
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customCompForOrdering.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/CustomCompForOrdering/customCompForOrdering.cpp b/examples/advanced/library/CustomCompForOrdering/customCompForOrdering.cpp
index 898602e7..35effc23 100644
--- a/examples/advanced/library/CustomCompForOrdering/customCompForOrdering.cpp
+++ b/examples/advanced/library/CustomCompForOrdering/customCompForOrdering.cpp
@@ -46,7 +46,9 @@
/*---------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* Example of a program that uses a custom comparison (2 elements) for */
-/* ordering trial points before evaluation */
+/* ordering trial points before evaluation. */
+/* The rank of points is established in the completeTrialPointsInformation */
+/* and comp functions. */
/*--------------------------------------------------------------------------*/
#include "Nomad/nomad.hpp"
#include "Algos/EvcInterface.hpp"
@@ -63,11 +65,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -99,11 +101,11 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
return true; // the evaluation succeeded
}
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
// Parameters creation
allParams->setAttributeValue("DIMENSION", n);
-
+
// Starting point
allParams->setAttributeValue("X0", NOMAD::Point(n, 0.0) );
@@ -117,15 +119,19 @@ void initAllParams(std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
+ allParams->setAttributeValue("MAX_BB_EVAL", 200);
+
+ allParams->setAttributeValue("QUAD_MODEL_SEARCH", false);
+
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
-
+
// Parameters validation requested to have access to their value.
allParams->checkAndComply();
@@ -136,52 +142,73 @@ void initAllParams(std::shared_ptr allParams)
// The closer to 0, the lower the priority.
class CustomOrder : public NOMAD::ComparePriorityMethod
{
+ // The evaluation point tags are unique. Let's use
+ // them as map key. The value for ordering is the
+ // second element of the map, the distance to P0.
+ std::map _valByTags;
public:
bool comp(NOMAD::EvalQueuePointPtr& p1, NOMAD::EvalQueuePointPtr& p2) const override
{
bool lowerPriority = false;
+ auto itP1 = _valByTags.find(p1->getTag());
+ auto itP2 = _valByTags.find(p2->getTag());
+ if (itP1 != _valByTags.end() && itP2 != _valByTags.end())
+ {
+ lowerPriority = (itP1->second < itP2->second);
+ }
+
+ return lowerPriority;
+
+ }
+
+
+ void completeTrialPointsInformation(const NOMAD::Step *step, NOMAD::EvalPointSet & trialPoints) override
+ {
NOMAD::Point P0(n, 0);
- NOMAD::Double d1 = NOMAD::Point::dist(P0, *(p1.get()));
- NOMAD::Double d2 = NOMAD::Point::dist(P0, *(p2.get()));
- if (d1 < d2)
+ _valByTags.clear();
+
+ // We could std::copy_if but it is not worth it. Clarity is better.
+ for ( const auto & evalQueuePoint : trialPoints)
{
- lowerPriority = true;
+ // Let use a reference point to compute a distance.
+ // The distance is used in comp function to order the points.
+ auto tag = evalQueuePoint.getTag();
+ NOMAD::Double d1 = NOMAD::Point::dist(P0, evalQueuePoint);
+ _valByTags.insert(std::pair(tag,d1));
}
- return lowerPriority;
}
};
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
-
+
// Set parameters
auto params = std::make_shared();
initAllParams(params);
TheMainStep.setAllParameters(params);
-
+
// Custom Evaluator creation
auto ev = std::make_unique(params->getEvalParams());
TheMainStep.addEvaluator(std::move(ev));
-
+
+ // The run
+ TheMainStep.start();
+
// Define new sort function and sort according to that function
+ // Must be done after main step start.
auto customOrder = std::make_shared();
NOMAD::EvcInterface::getEvaluatorControl()->setUserCompMethod(customOrder);
- // The run
- TheMainStep.start();
TheMainStep.run();
TheMainStep.end();
-
- return 1;
+
+ return 0;
}
diff --git a/examples/advanced/library/CustomOpportunistic/CMakeLists.txt b/examples/advanced/library/CustomOpportunistic/CMakeLists.txt
index e2dd2eba..904e719d 100644
--- a/examples/advanced/library/CustomOpportunistic/CMakeLists.txt
+++ b/examples/advanced/library/CustomOpportunistic/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS customOpport.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for custom opportunism")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedCustomOpport
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customOpport.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedCustomOpport
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customOpport.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/CustomOpportunistic/customOpport.cpp b/examples/advanced/library/CustomOpportunistic/customOpport.cpp
index 4160dedf..03d9409e 100644
--- a/examples/advanced/library/CustomOpportunistic/customOpport.cpp
+++ b/examples/advanced/library/CustomOpportunistic/customOpport.cpp
@@ -45,7 +45,6 @@
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
-
/*--------------------------------------------------------------------------*/
/* Example of a program that makes NOMAD do a local opportunistic stop */
/* of queued evaluations from a Poll step when a user criterion is met */
@@ -64,6 +63,9 @@
// for custom opportunistic stop of step
NOMAD::Double currentBestFeasF;
+// Default F and H compute type used for custom oppportunistic stop
+NOMAD::FHComputeType computeType = NOMAD::defaultFHComputeType;
+
/*----------------------------------------*/
/* The problem */
/*----------------------------------------*/
@@ -74,11 +76,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -91,7 +93,6 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
const NOMAD::Double &hMax,
bool &countEval) const
{
-
if (N%2 != 0)
{
throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
@@ -102,16 +103,16 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
f += pow ( 1 - x[2*i-2].todouble() , 2 );
}
- x.setBBO(std::to_string(f));
+ NOMAD::Double F(f);
+ x.setBBO(F.tostring());
countEval = true;
return true; // the evaluation succeeded
}
-void initAllParams( std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
-
// Parameters creation
allParams->setAttributeValue("DIMENSION", N);
// 100 black-box evaluations
@@ -125,14 +126,14 @@ void initAllParams( std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::OBJ);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DISPLAY_DEGREE", 3);
allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
- // Opportunistic eval must be activated (rem: activated by default!). Let us sort with a poor sorting strategy (quadratic model is much better). Default criterion for opportunism is disabled and replaced by a custom opportunistic criterion provided by a user callback (see below).
+ // Opportunistic eval must be activated (rem: activated by default!). Let us sort with a poor sorting strategy (quadratic model is much better than lexicographical). Default criterion for opportunism is disabled and replaced by a custom opportunistic criterion provided by a user callback (see below).
allParams->setAttributeValue("EVAL_OPPORTUNISTIC", true);
allParams->setAttributeValue("EVAL_QUEUE_SORT",NOMAD::EvalSortType::LEXICOGRAPHICAL);
@@ -144,7 +145,6 @@ void initAllParams( std::shared_ptr allParams)
// Parameters validation
allParams->checkAndComply();
-
}
@@ -158,39 +158,38 @@ void customEvalCB(NOMAD::EvalQueuePointPtr & evalQueuePoint, bool &opportunistic
if (NOMAD::EvalType::BB == evalQueuePoint->getEvalType() )
{
// Consider only feasible points
- if (evalQueuePoint->isFeasible(NOMAD::EvalType::BB))
+ if (evalQueuePoint->isFeasible(computeType))
{
// Update my current best feasible point
if (!currentBestFeasF.isDefined())
{
- currentBestFeasF = evalQueuePoint->getF(NOMAD::EvalType::BB);
+ currentBestFeasF = evalQueuePoint->getF(computeType);
return;
}
auto mystep = evalQueuePoint->getGenStep();
// Opportunism only if enough reduction is obtained (optim f is 0)
- auto FMinOpport = currentBestFeasF - 0.01*currentBestFeasF.abs();
+ auto FMinOpport = currentBestFeasF - 0.1*currentBestFeasF.abs();
if (NOMAD::stepTypeToString(mystep).find("Poll") != string::npos &&
- evalQueuePoint->getF(NOMAD::EvalType::BB) < FMinOpport)
+ evalQueuePoint->getF(computeType) < FMinOpport)
{
opportunisticEvalStop=true;
std::cout<<"*****************************************************"<< std::endl;
std::cout<<"Opportunistic stop in Poll on f sufficient decrease. "<< std::endl;
std::cout<<"*****************************************************"<< std::endl;
- currentBestFeasF = evalQueuePoint->getF(NOMAD::EvalType::BB);
+ currentBestFeasF = evalQueuePoint->getF(computeType);
}
}
}
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
NOMAD::MainStep TheMainStep;
@@ -213,5 +212,5 @@ int main ( int argc , char ** argv )
TheMainStep.run();
TheMainStep.end();
- return 1;
+ return 0;
}
diff --git a/examples/advanced/library/CustomPollMethod/CMakeLists.txt b/examples/advanced/library/CustomPollMethod/CMakeLists.txt
new file mode 100644
index 00000000..aa9373e0
--- /dev/null
+++ b/examples/advanced/library/CustomPollMethod/CMakeLists.txt
@@ -0,0 +1,20 @@
+add_executable(customPollMethod.exe customPollMethod.cpp )
+
+target_include_directories(customPollMethod.exe PRIVATE
+ ${CMAKE_SOURCE_DIR}/src)
+
+set_target_properties(customPollMethod.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
+
+
+if(OpenMP_CXX_FOUND)
+ target_link_libraries(customPollMethod.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
+else()
+ target_link_libraries(customPollMethod.exe PUBLIC nomadAlgos nomadUtils nomadEval)
+endif()
+
+# installing executables and libraries
+install(TARGETS customPollMethod.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+
+# No test for this example
diff --git a/examples/advanced/library/CustomPollMethod/customPollMethod.cpp b/examples/advanced/library/CustomPollMethod/customPollMethod.cpp
new file mode 100644
index 00000000..fbdaf3c1
--- /dev/null
+++ b/examples/advanced/library/CustomPollMethod/customPollMethod.cpp
@@ -0,0 +1,293 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+/* Example of a program that makes NOMAD do a Mads custom/user poll in */
+/* addition to the Ortho 2n poll method. */
+/*--------------------------------------------------------------------------*/
+#include "Nomad/nomad.hpp"
+#include "Algos/EvcInterface.hpp"
+#include "Algos/Mads/Mads.hpp"
+#include "Algos/Mads/MadsMegaIteration.hpp"
+#include "Algos/Mads/SearchMethodAlgo.hpp"
+#include "Algos/SubproblemManager.hpp"
+#include "Cache/CacheBase.hpp"
+#include "Type/EvalSortType.hpp"
+#include "Algos/AlgoStopReasons.hpp"
+#include "Util/AllStopReasons.hpp"
+#include "Math/MatrixUtils.hpp"
+
+/*----------------------------------------*/
+/* The problem */
+/*----------------------------------------*/
+const int N=6;
+
+class My_Evaluator : public NOMAD::Evaluator
+{
+private:
+
+public:
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
+ {}
+
+ ~My_Evaluator() override = default;
+
+ bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
+};
+
+
+/*----------------------------------------*/
+/* user-defined eval_x */
+/*----------------------------------------*/
+bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
+ const NOMAD::Double &hMax,
+ bool &countEval) const
+{
+ if (N%2 != 0)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
+ }
+ double f=0;
+ for ( size_t i = 1 ; i <= N/2 ; ++i ) {
+ f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
+ f += pow ( 1 - x[2*i-2].todouble() , 2 );
+ }
+ NOMAD::Double F(f);
+ x.setBBO(F.tostring());
+ countEval = true;
+
+ return true; // the evaluation succeeded
+}
+
+
+void initAllParams(const std::shared_ptr& allParams)
+{
+ // Parameters creation
+ allParams->setAttributeValue("DIMENSION", N);
+
+ // black-box evaluations
+ allParams->setAttributeValue("MAX_BB_EVAL", 400*N);
+
+ // Starting point
+ allParams->setAttributeValue("X0", NOMAD::Point(N, 0.0) );
+
+ // Bounds
+ allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(N, -10.0));
+ allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(N, 10.0));
+
+ // Constraints and objective
+ NOMAD::BBOutputTypeList bbOutputTypes;
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::OBJ);
+ allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes);
+
+ // NOTE: USER_POLL directions can be combined with other direction type or not.
+ NOMAD::DirectionTypeList dtList = {NOMAD::DirectionType::USER_POLL, NOMAD::DirectionType::ORTHO_2N};
+
+ allParams->setAttributeValue("DIRECTION_TYPE",dtList);
+
+ allParams->setAttributeValue("QUAD_MODEL_SEARCH", false); // Disable QMS and NM for clarity of the display
+ allParams->setAttributeValue("NM_SEARCH", false);
+
+ // Display
+ allParams->setAttributeValue("DISPLAY_DEGREE", 3);
+ allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
+
+ // Parameters validation
+ allParams->checkAndComply();
+
+}
+
+// The function to generate QRMads user poll directions. This is registered as a callback below.
+bool userQRPollMethodCallback(const NOMAD::Step& step, std::list & dirs, const size_t n)
+{
+ // Important: by default USER_CALLS are disabled when doing quad model optimization
+ // -> NO call to this function when doing quad model search.
+
+ auto mads = dynamic_cast(step.getRootAlgorithm());
+ if (nullptr == mads)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No Mads available.");
+ }
+ // Access to the current poll method frame center
+ auto callingPoll = dynamic_cast(&step);
+ if (nullptr == callingPoll)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No poll method available.");
+ }
+ auto frameCenter = callingPoll->getFrameCenter();
+
+ // Let's work on the Mads pb. Remark: Mads does not see the fixed variables.
+ auto pbParams = mads->getPbParams();
+
+ // Pb parameters
+ auto nPb = pbParams->getAttributeValue("DIMENSION");
+ if (nPb != n)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Dimension pb.");
+ }
+
+ // Mesh delta frame size is used to scale the proposed search direction
+ auto mesh = step.getIterationMesh();
+ if (nullptr == mesh)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No mesh available.");
+ }
+ // Box size has the dimension of the Mads problem.
+ NOMAD::ArrayOfDouble boxSize = mesh->getDeltaFrameSize();
+
+ dirs.clear();
+ NOMAD::Direction dirUnit(n, 0.0);
+ NOMAD::Direction::computeDirOnUnitSphere(dirUnit);
+
+ while (dirUnit[0] == 0)
+ {
+ NOMAD::Direction::computeDirOnUnitSphere(dirUnit);
+ }
+
+ // Matrix M
+ auto ** M = new double*[n];
+ for (size_t i = 0; i < n; ++i)
+ {
+ M[i] = new double [n];
+ M[i][0] = dirUnit[i].todouble();
+ for (size_t j = 1; j < n; ++j)
+ {
+ M[i][j] = (i == j)? 1.0:0.0;
+ }
+ }
+
+ // std::cout << "M matrix for QR:" <(n),static_cast(n));
+
+ if ( !success || !error_msg.empty())
+ {
+ std::cerr << "QR decomposition for QR 2N poll method has failed" << std::endl;
+ return false;
+ }
+
+ // std::cout << "Direction after QR decomposition: " << std::endl;
+ // Ordering D_k alternates Qk and -Qk instead of [Q_k -Q_k]
+ NOMAD::Direction dir(n);
+ for (size_t i = 0; i < n; ++i)
+ {
+ for (size_t j = 0; j < n; ++j)
+ {
+ dir[j] = Q[j][i];
+ }
+
+ dirs.push_back(dir);
+ dirs.push_back(-dir);
+ }
+
+ // Delete M, Q and R:
+ for ( size_t i = 0 ; i < n ; ++i )
+ {
+ delete [] M[i];
+ delete [] Q[i];
+ delete [] R[i];
+ }
+ delete [] Q;
+ delete [] R;
+ delete [] M;
+
+ return true;
+}
+
+/*------------------------------------------*/
+/* NOMAD main function */
+/*------------------------------------------*/
+int main()
+{
+ NOMAD::MainStep TheMainStep;
+
+ // Set parameters
+ auto params = std::make_shared();
+ initAllParams(params);
+ TheMainStep.setAllParameters(params);
+
+ // Custom Evaluator
+ std::unique_ptr ev(new My_Evaluator(params->getEvalParams()));
+ TheMainStep.setEvaluator(std::move(ev));
+
+ // Main step start initializes Mads (default algorithm)
+ TheMainStep.start();
+
+ // Registering the callback function to generate Mads user poll trial points via poll directions.
+ // The user poll also requires to set DIRECTION_TYPE USER_POLL (see above)
+ auto mads = std::dynamic_pointer_cast(TheMainStep.getAlgo(NOMAD::StepType::ALGORITHM_MADS));
+ if (nullptr == mads)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Cannot access to Mads algorithm");
+ }
+ mads->addCallback(NOMAD::CallbackType::USER_METHOD_POLL, userQRPollMethodCallback);
+
+ TheMainStep.run();
+ TheMainStep.end();
+
+ return 0;
+}
diff --git a/examples/advanced/library/CustomSearchMethod/CMakeLists.txt b/examples/advanced/library/CustomSearchMethod/CMakeLists.txt
new file mode 100644
index 00000000..e20ed203
--- /dev/null
+++ b/examples/advanced/library/CustomSearchMethod/CMakeLists.txt
@@ -0,0 +1,20 @@
+add_executable(customSearchMethod.exe customSearchMethod.cpp )
+
+target_include_directories(customSearchMethod.exe PRIVATE
+ ${CMAKE_SOURCE_DIR}/src)
+
+set_target_properties(customSearchMethod.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
+
+
+if(OpenMP_CXX_FOUND)
+ target_link_libraries(customSearchMethod.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
+else()
+ target_link_libraries(customSearchMethod.exe PUBLIC nomadAlgos nomadUtils nomadEval)
+endif()
+
+# installing executables and libraries
+install(TARGETS customSearchMethod.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+
+# No test for this example
diff --git a/examples/advanced/library/CustomSearchMethod/customSearchMethod.cpp b/examples/advanced/library/CustomSearchMethod/customSearchMethod.cpp
new file mode 100644
index 00000000..e2b6b693
--- /dev/null
+++ b/examples/advanced/library/CustomSearchMethod/customSearchMethod.cpp
@@ -0,0 +1,233 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+/* Example of a program that makes NOMAD do a Mads custom user search in */
+/* addition to the default search. */
+/*--------------------------------------------------------------------------*/
+#include "Nomad/nomad.hpp"
+#include "Algos/EvcInterface.hpp"
+#include "Algos/Mads/Mads.hpp"
+#include "Algos/Mads/MadsMegaIteration.hpp"
+#include "Algos/Mads/SearchMethodAlgo.hpp"
+#include "Algos/SubproblemManager.hpp"
+#include "Cache/CacheBase.hpp"
+#include "Type/EvalSortType.hpp"
+#include "Algos/AlgoStopReasons.hpp"
+#include "Util/AllStopReasons.hpp"
+
+/*----------------------------------------*/
+/* The problem */
+/*----------------------------------------*/
+const int N=6;
+
+class My_Evaluator : public NOMAD::Evaluator
+{
+private:
+
+public:
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
+ {}
+
+ ~My_Evaluator() override = default;
+
+ bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
+};
+
+
+/*----------------------------------------*/
+/* user-defined eval_x */
+/*----------------------------------------*/
+bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
+ const NOMAD::Double &hMax,
+ bool &countEval) const
+{
+
+ if (N%2 != 0)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
+ }
+
+ double f=0;
+ for ( size_t i = 1 ; i <= N/2 ; ++i ) {
+ f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
+ f += pow ( 1 - x[2*i-2].todouble() , 2 );
+ }
+ NOMAD::Double F(f);
+ x.setBBO(F.tostring());
+ countEval = true;
+
+ return true; // the evaluation succeeded
+}
+
+
+void initAllParams(const std::shared_ptr& allParams)
+{
+ // Parameters creation
+ allParams->setAttributeValue("DIMENSION", N);
+ // 100 black-box evaluations
+ allParams->setAttributeValue("MAX_BB_EVAL", 50*N);
+ // Starting point
+ allParams->setAttributeValue("X0", NOMAD::Point(N, 0.0) );
+
+ // Bounds
+ allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(N, -10.0));
+ allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(N, 10.0));
+
+ // Constraints and objective
+ NOMAD::BBOutputTypeList bbOutputTypes;
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::OBJ);
+ allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
+
+ // Algo
+ allParams->setAttributeValue("DIRECTION_TYPE",NOMAD::DirectionType::ORTHO_2N);
+ allParams->setAttributeValue("QUAD_MODEL_SEARCH", false);
+ allParams->setAttributeValue("NM_SEARCH", false);
+
+ // Enable the user search method. See below for registering the callback function
+ // to generate the search directions. Both are required.
+ allParams->setAttributeValue("USER_SEARCH", true);
+
+ // Display
+ allParams->setAttributeValue("DISPLAY_DEGREE", 3);
+ allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
+ allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
+
+ // Parameters validation
+ allParams->checkAndComply();
+}
+
+// The function to generate user search directions. This is registered as a callback below.
+bool userSearchMethodCallback(const NOMAD::Step& step, NOMAD::EvalPointSet & trialPoints)
+{
+ // Important: by default USER_CALLS are disabled when doing quad model optimization
+ // -> NO call to this function when doing quad model search.
+
+ auto mads = dynamic_cast(step.getRootAlgorithm());
+ if (nullptr == mads)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No Mads available.");
+ }
+ auto barrier = mads->getMegaIterationBarrier();
+ if (nullptr == barrier)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No barrier available.");
+ }
+ auto frameCenter = barrier->getFirstPoint();
+
+ // Let's work on the Mads pb.
+ auto pbParams = mads->getPbParams();
+
+ // Pb parameters
+ auto n = pbParams->getAttributeValue("DIMENSION");
+
+ // Mesh delta frame size is used to scale the proposed search direction
+ auto mesh = step.getIterationMesh();
+ if (nullptr == mesh)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"No mesh available.");
+ }
+ // Frame size of the mesh
+ NOMAD::ArrayOfDouble frameSize = mesh->getDeltaFrameSize();
+
+ // Let's try a random direction larger than the mesh frame size.
+ NOMAD::Direction dir(n,0.0);
+
+ // Compute unit sphere direction
+ NOMAD::Direction::computeDirOnUnitSphere(dir);
+
+ for (size_t i = 0 ; i < n ; i++)
+ {
+ // Let's explore beyond the frame size
+ dir[i] *= frameSize[i]*2.0; // Note: resulting pt is projected on the bounds and on the mesh if required.
+ }
+
+ trialPoints.clear();
+
+ // insert the trial point in the trial point set
+ NOMAD::EvalPoint ep(*frameCenter->getX() + dir);
+ ep.setPointFrom(frameCenter, NOMAD::SubproblemManager::getInstance()->getSubFixedVariable(&step));
+ trialPoints.insert(ep);
+
+ return true;
+}
+
+
+/*------------------------------------------*/
+/* NOMAD main function */
+/*------------------------------------------*/
+int main()
+{
+ NOMAD::MainStep TheMainStep;
+
+ // Set parameters
+ auto params = std::make_shared();
+ initAllParams(params);
+ TheMainStep.setAllParameters(params);
+
+ // Custom Evaluator
+ std::unique_ptr ev(new My_Evaluator(params->getEvalParams()));
+ TheMainStep.setEvaluator(std::move(ev));
+
+ // Main step start initializes Mads (default algorithm)
+ TheMainStep.start();
+
+ // Registering the callback function to generate Mads user search trial points
+ // Setting USER_SEARCH yes is also required (see above)
+ auto mads = std::dynamic_pointer_cast(TheMainStep.getAlgo(NOMAD::StepType::ALGORITHM_MADS));
+ if (nullptr == mads)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Cannot access to Mads algorithm");
+ }
+ mads->addCallback(NOMAD::CallbackType::USER_METHOD_SEARCH, userSearchMethodCallback);
+
+ TheMainStep.run();
+ TheMainStep.end();
+
+ return 0;
+}
diff --git a/examples/advanced/library/CustomStatSum/CMakeLists.txt b/examples/advanced/library/CustomStatSum/CMakeLists.txt
index 135af970..7d9bebbc 100644
--- a/examples/advanced/library/CustomStatSum/CMakeLists.txt
+++ b/examples/advanced/library/CustomStatSum/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS customStatSum.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for stop on stat sum criterion")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedcustomStatSum
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customStatSum.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedcustomStatSum
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customStatSum.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/CustomStatSum/customStatSum.cpp b/examples/advanced/library/CustomStatSum/customStatSum.cpp
index 4aada090..880c5a95 100644
--- a/examples/advanced/library/CustomStatSum/customStatSum.cpp
+++ b/examples/advanced/library/CustomStatSum/customStatSum.cpp
@@ -59,7 +59,7 @@
#include "Util/AllStopReasons.hpp"
-// User stats used for stoping optimization
+// User stats used for stopping optimization
/* This feature is implemented in Nomad 3 as STAT_SUM and STAT_SUM_TARGET
Nomad 4 has more flexibility by using user evaluation callbacks
*/
@@ -76,11 +76,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -120,9 +120,8 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
return true; // the evaluation succeeded
}
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
-
const size_t n = 5;
// Parameters creation
@@ -140,11 +139,11 @@ void initAllParams(std::shared_ptr allParams)
allParams->setAttributeValue("UPPER_BOUND", ub);
// Constraints and objective
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::BBO_UNDEFINED);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::BBO_UNDEFINED);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::BBO_UNDEFINED);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::BBO_UNDEFINED);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
@@ -155,7 +154,6 @@ void initAllParams(std::shared_ptr allParams)
// Parameters validation requested to have access to their value.
allParams->checkAndComply();
-
}
@@ -163,7 +161,7 @@ void initAllParams(std::shared_ptr allParams)
/* After each evaluation compute user stats on extra outputs and check on */
/* user stat stopping criterion */
/*------------------------------------------------------------------------*/
-void customEvalStopCB( NOMAD::EvalQueuePointPtr & evalQueuePoint, bool & globalStop)
+void customEvalStopCB(NOMAD::EvalQueuePointPtr& evalQueuePoint, bool& globalStop)
{
globalStop = false;
if (nullptr != evalQueuePoint)
@@ -187,14 +185,11 @@ void customEvalStopCB( NOMAD::EvalQueuePointPtr & evalQueuePoint, bool & globalS
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -212,11 +207,10 @@ int main ( int argc , char ** argv )
// Add callback function for eval check and stop management.
NOMAD::EvcInterface::getEvaluatorControl()->addEvalCallback(cbFailCheck);
-
// The run
TheMainStep.start();
TheMainStep.run();
TheMainStep.end();
- return 1;
+ return 0;
}
diff --git a/examples/advanced/library/DiscoMads/EscapeDiscontinuities/CMakeLists.txt b/examples/advanced/library/DiscoMads/EscapeDiscontinuities/CMakeLists.txt
index ec33b151..b5a9adcd 100644
--- a/examples/advanced/library/DiscoMads/EscapeDiscontinuities/CMakeLists.txt
+++ b/examples/advanced/library/DiscoMads/EscapeDiscontinuities/CMakeLists.txt
@@ -16,18 +16,4 @@ endif()
install(TARGETS DiscoMadsEscapeDiscont.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example DiscoMadsEscapeDiscont library #1")
-
-# Can run this test after install
- if (WIN32)
- add_test(NAME ExampleDiscoMadsEscapeDiscontLib
- COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./DiscoMadsEscapeDiscont.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- else()
- add_test(NAME ExampleDiscoMadsEscapeDiscontLib
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./DiscoMadsEscapeDiscont.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
- endif()
-endif()
+# No test for this example
diff --git a/examples/advanced/library/DiscoMads/EscapeDiscontinuities/DiscoMadsEscapeDiscont.cpp b/examples/advanced/library/DiscoMads/EscapeDiscontinuities/DiscoMadsEscapeDiscont.cpp
index a2c20cb2..5c05f10b 100644
--- a/examples/advanced/library/DiscoMads/EscapeDiscontinuities/DiscoMadsEscapeDiscont.cpp
+++ b/examples/advanced/library/DiscoMads/EscapeDiscontinuities/DiscoMadsEscapeDiscont.cpp
@@ -54,7 +54,7 @@
/*----------------------------------------*/
/* The problem */
/*----------------------------------------*/
-// The problem is described sec. 5.1 "Results of a typical run" of [1] and more detailled
+// The problem is described sec. 5.1 "Results of a typical run" of [1] and more detailed
// following eq. 2.52, p.53 in [2].
// [1] Escaping Unknown Discontinuous Regions in Blackbox Optimization
@@ -65,21 +65,19 @@
// Solène Kojtych, Ph.D. thesis 2022
// doi/10.1137/21M1420915
-
class My_Evaluator : public NOMAD::Evaluator
{
public:
- My_Evaluator(const std::shared_ptr& evalParams, NOMAD::EvalType evalType)
+ explicit My_Evaluator(const std::shared_ptr& evalParams, NOMAD::EvalType evalType)
: NOMAD::Evaluator(evalParams, evalType)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double& hMax, bool &countEval) const override
{
- bool eval_ok = false;
- NOMAD::Double f = 1e+20, c1 = 1e+20;
- size_t n = x.size();
+ bool eval_ok = false;
+ NOMAD::Double f = 1e+20, c1 = 1e+20;
try
{
@@ -124,8 +122,6 @@ class My_Evaluator : public NOMAD::Evaluator
};
-
-
void initParams(NOMAD::AllParameters &p)
{
// parameters creation
@@ -166,15 +162,12 @@ void initParams(NOMAD::AllParameters &p)
p.setAttributeValue("DISCO_MADS_REVEALING_POLL_NB_POINTS", n);
// ------- Recommended parameters for DiscoMads
- // no parallelism
- p.setAttributeValue("NB_THREADS_OPENMP",1); // DiscoMads works with OpenMP but has not been extensively tested
- // quad models are desactivated as they may be slow with DiscoMads
+ // quad models are deactivated as they may be slow with DiscoMads
p.getRunParams()->setAttributeValue("QUAD_MODEL_SEARCH", false);
p.getRunParams()->setAttributeValue("DIRECTION_TYPE", NOMAD::DirectionType::ORTHO_2N);
p.getEvaluatorControlParams()->setAttributeValue("EVAL_QUEUE_SORT",NOMAD::EvalSortType::DIR_LAST_SUCCESS);
-
// ------- Specific thesis parameters
// Uncomment the following parameters to reproduce the thesis parameters
//p.set_SEED(3698370);
@@ -183,7 +176,6 @@ void initParams(NOMAD::AllParameters &p)
//p.getRunParams()->setAttributeValue("NM_SEARCH", false);
//p.setAttributeValue("SPECULATIVE_SEARCH", true);
-
// parameters validation
p.checkAndComply();
}
@@ -191,7 +183,7 @@ void initParams(NOMAD::AllParameters &p)
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main (int argc, char **argv)
+int main()
{
auto TheMainStep = std::make_unique();
diff --git a/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/CMakeLists.txt b/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/CMakeLists.txt
index 4154a909..ca3d2303 100644
--- a/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/CMakeLists.txt
+++ b/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/CMakeLists.txt
@@ -16,18 +16,4 @@ endif()
install(TARGETS DiscoMadsEscapeHiddenConstraints.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# # Add a test for this example
-# if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example DiscoMads library #1")
-
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleDiscoMadsLib
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./DiscoMadsEscapeHiddenConstraints.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-# else()
-# add_test(NAME ExampleDiscoMadsLib
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./DiscoMadsEscapeHiddenConstraints.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-# endif()
-# endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/DiscoMadsEscapeHiddenConstraints.cpp b/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/DiscoMadsEscapeHiddenConstraints.cpp
index 356e3078..af48a7cd 100644
--- a/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/DiscoMadsEscapeHiddenConstraints.cpp
+++ b/examples/advanced/library/DiscoMads/EscapeHiddenConstraints/DiscoMadsEscapeHiddenConstraints.cpp
@@ -58,7 +58,7 @@
#include "Util/AllStopReasons.hpp"
// # The problem is described sec. 5.3 "5.3. Design of a styrene production process."
-// of [1] and more detailled in section 2.5.4, p.61 of [2].
+// of [1] and more detailed in section 2.5.4, p.61 of [2].
//
// IMPORTANT
//
@@ -76,7 +76,7 @@
// Solène Kojtych, Ph.D. thesis 2022
// doi/10.1137/21M1420915
-void initAllParams( std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
const int n = 8;
@@ -120,8 +120,6 @@ void initAllParams( std::shared_ptr allParams)
allParams->setAttributeValue("DISCO_MADS_REVEALING_POLL_NB_POINTS", n);
// ------- Recommended parameters for DiscoMads
- // no parallelism
- allParams->setAttributeValue("NB_THREADS_OPENMP",1); // DiscoMads works with OpenMP but has not been extensively tested
// quad models are desactivated as they may be slow with DiscoMads
allParams->getRunParams()->setAttributeValue("QUAD_MODEL_SEARCH", false);
@@ -143,14 +141,11 @@ void initAllParams( std::shared_ptr allParams)
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -171,5 +166,5 @@ int main ( int argc , char ** argv )
std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
}
- return 1;
+ return 0;
}
diff --git a/examples/advanced/library/FixedVariable/.gitignore b/examples/advanced/library/FixedVariable/.gitignore
index b9bdc5aa..ef60df2b 100644
--- a/examples/advanced/library/FixedVariable/.gitignore
+++ b/examples/advanced/library/FixedVariable/.gitignore
@@ -1,3 +1,4 @@
+nomadtmp.*
*.o
*.exe
cache.txt
diff --git a/examples/advanced/library/FixedVariable/CMakeLists.txt b/examples/advanced/library/FixedVariable/CMakeLists.txt
index 1b1cadc7..afb29e1b 100644
--- a/examples/advanced/library/FixedVariable/CMakeLists.txt
+++ b/examples/advanced/library/FixedVariable/CMakeLists.txt
@@ -19,19 +19,16 @@ install(TARGETS fixedVariable.exe ufl.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example test for fixed variables")
- # Can run this test after install
+message(STATUS " Add example for fixed variables")
- if (WIN32)
- add_test(NAME ExampleAdvancedFixedVariables
+if (WIN32)
+ add_test(NAME ExampleAdvancedFixedVariables
COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./fixedVariable.exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
- else()
- add_test(NAME ExampleAdvancedFixedVariables
+else()
+ add_test(NAME ExampleAdvancedFixedVariables
COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./fixedVariable.exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
- endif()
endif()
diff --git a/examples/advanced/library/FixedVariable/fixedVariable.cpp b/examples/advanced/library/FixedVariable/fixedVariable.cpp
index ea9073fe..63213930 100644
--- a/examples/advanced/library/FixedVariable/fixedVariable.cpp
+++ b/examples/advanced/library/FixedVariable/fixedVariable.cpp
@@ -51,8 +51,6 @@
#include "Eval/Evaluator.hpp"
#include "Param/AllParameters.hpp"
-
-
void initParams1(NOMAD::AllParameters &p)
{
// parameters creation
@@ -165,7 +163,7 @@ void initParamsFinal(NOMAD::AllParameters &p, const NOMAD::Point& x0)
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main (int argc, char **argv)
+int main()
{
auto TheMainStep = std::make_unique();
@@ -174,6 +172,11 @@ int main (int argc, char **argv)
auto params = std::make_shared();
initParams1(*params);
TheMainStep->setAllParameters(params);
+
+ auto computeTypeS = NOMAD::ComputeType::STANDARD;
+ auto hNormType = params->getAttributeValue("H_NORM");
+ auto evalType = NOMAD::EvalType::BB;
+ NOMAD::FHComputeType computeType = {evalType, {computeTypeS, hNormType}};
try
{
@@ -195,8 +198,9 @@ int main (int argc, char **argv)
NOMAD::CacheBase::getInstance()->resetNbCacheHits();
NOMAD::EvcInterface::getEvaluatorControl()->setNbEval(0);
std::vector bestFeasList;
- NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(),
- NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
+
+
+ NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(), computeType);
// NB. Assuming the list is non-empty.
NOMAD::Point x02 = *(bestFeasList[0].getX());
initParams2(*params, x02);
@@ -214,8 +218,7 @@ int main (int argc, char **argv)
// Part 3: FIXED_VARIABLE 3-4
NOMAD::CacheBase::getInstance()->resetNbCacheHits();
NOMAD::EvcInterface::getEvaluatorControl()->setNbEval(0);
- NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(),
- NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
+ NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(), computeType);
NOMAD::Point x03 = *(bestFeasList[0].getX());
initParams3(*params , x03);
try
@@ -230,8 +233,7 @@ int main (int argc, char **argv)
}
// Final part: No fixed variable
- NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(),
- NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
+ NOMAD::CacheBase::getInstance()->findBestFeas(bestFeasList, NOMAD::Point(), computeType);
NOMAD::Point x0final = *(bestFeasList[0].getX());
initParamsFinal(*params,x0final);
try
@@ -245,6 +247,5 @@ int main (int argc, char **argv)
std::cerr << "\nFinal run has been interrupted (" << e.what() << ")\n\n";
}
-
return 0;
}
diff --git a/examples/advanced/library/HandlingHiddenConstraints/CMakeLists.txt b/examples/advanced/library/HandlingHiddenConstraints/CMakeLists.txt
index 05d30486..72886fbe 100644
--- a/examples/advanced/library/HandlingHiddenConstraints/CMakeLists.txt
+++ b/examples/advanced/library/HandlingHiddenConstraints/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS handlingHiddenCons.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for handling hidden constraints")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedhandlingHiddenCons
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./handlingHiddenCons.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedhandlingHiddenCons
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./handlingHiddenCons.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/HandlingHiddenConstraints/handlingHiddenCons.cpp b/examples/advanced/library/HandlingHiddenConstraints/handlingHiddenCons.cpp
index 83c16540..19bde71d 100644
--- a/examples/advanced/library/HandlingHiddenConstraints/handlingHiddenCons.cpp
+++ b/examples/advanced/library/HandlingHiddenConstraints/handlingHiddenCons.cpp
@@ -45,8 +45,8 @@
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
-/* example of a program that makes NOMAD do a local step stop (search) */
-/* after a user criterion */
+/* example of a program that makes NOMAD call a user call back function to */
+/* manage failed evaluations. */
/*--------------------------------------------------------------------------*/
#include "Nomad/nomad.hpp"
#include "Algos/EvcInterface.hpp"
@@ -65,8 +65,7 @@
// setAttributeValue("BB_EXE",xxxx)
// To run this optimization, the program must be executed in a path where styrene truth executable is available.
// Styrene sources are available at https://github.com/bbopt/styrene and must be compiled prior to run this optimization.
-
-void initAllParams( std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
const int n = 8;
@@ -78,7 +77,6 @@ void initAllParams( std::shared_ptr allParams)
std::vector x0 = { 54, 66, 86, 8, 29, 51, 32, 15};
allParams->setAttributeValue("X0", NOMAD::Point(x0) );
allParams->setAttributeValue("BB_EXE", std::string("./truth.exe"));
-
// Bounds
allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, 0.0 ));
@@ -91,11 +89,8 @@ void initAllParams( std::shared_ptr allParams)
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
-
// Parameters validation
allParams->checkAndComply();
-
-
}
@@ -112,21 +107,18 @@ void customFailEvalCB( NOMAD::EvalQueuePointPtr & evalQueuePoint)
if (! eval->isBBOutputComplete())
{
eval->setBBO(std::string("1 1 1 1 1 1 1 1 1 1 1 1"), eval->getBBOutputTypeList(), true);
- std::cout<<"BBoutput was incomplete. BBO is reset to be complete."<& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override
{
bool eval_ok = false;
// Based on G2.
NOMAD::Double f, c1 = 0, c2 = 0;
- size_t n = x.size();
try
{
@@ -125,13 +124,13 @@ void initParams1(NOMAD::AllParameters &p)
p.getDispParams()->setAttributeValue("DISPLAY_UNSUCCESSFUL", false);
p.getDispParams()->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("BBE ( SOL ) OBJ"));
-
p.getEvalParams()->setAttributeValue("BB_OUTPUT_TYPE", NOMAD::stringToBBOutputTypeList("OBJ PB PB"));
p.getEvaluatorControlParams()->setAttributeValue("EVAL_OPPORTUNISTIC", false);
+
+ // Activating NM optimization deactivates the default Mads optimization (default)
p.getRunParams()->setAttributeValue("NM_OPTIMIZATION",true);
-
// parameters validation
p.checkAndComply();
}
@@ -140,7 +139,7 @@ void initParams1(NOMAD::AllParameters &p)
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main (int argc, char **argv)
+int main()
{
auto TheMainStep = std::make_unique();
diff --git a/examples/advanced/library/NestedOptim/CMakeLists.txt b/examples/advanced/library/NestedOptim/CMakeLists.txt
new file mode 100644
index 00000000..0c1ef393
--- /dev/null
+++ b/examples/advanced/library/NestedOptim/CMakeLists.txt
@@ -0,0 +1,29 @@
+
+add_executable(nestedOptim.exe nestedOptim.cpp)
+
+target_include_directories(nestedOptim.exe PRIVATE
+ ${CMAKE_SOURCE_DIR}/src)
+
+set_target_properties(nestedOptim.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
+
+target_link_libraries(nestedOptim.exe PUBLIC nomadAlgos nomadUtils nomadEval)
+
+# installing executables and libraries
+install(TARGETS nestedOptim.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+
+# Add a test for this example
+message(STATUS " Add example for nested optimization")
+
+if (WIN32)
+ add_test(NAME ExampleAdvancedNestedMads
+ COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./nestedOptim.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+else()
+ add_test(NAME ExampleAdvancedNestedMads
+ COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./nestedOptim.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+endif()
diff --git a/examples/advanced/library/NestedOptim/nestedOptim.cpp b/examples/advanced/library/NestedOptim/nestedOptim.cpp
new file mode 100644
index 00000000..364dbfea
--- /dev/null
+++ b/examples/advanced/library/NestedOptim/nestedOptim.cpp
@@ -0,0 +1,224 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+/*--------------------------------------------*/
+/* Rosenbrock with dimension greater than 2 */
+/* Inner problem has dimension 2 */
+/* Inner problem is solved with SimpleMads */
+/* Outer problem is solved with regular Mads*/
+/*--------------------------------------------*/
+#include "Nomad/nomad.hpp"
+#include "Algos/SimpleMads/SimpleMads.hpp"
+#include "Type/DirectionType.hpp"
+#include "Type/EvalSortType.hpp"
+
+const size_t Nout = 10; // 10 variables outer problem, 2 additional (hidden) variables are used in the problem
+
+/*----------------------------------------*/
+/* The problem */
+/*----------------------------------------*/
+class My_EvaluatorOut : public NOMAD::Evaluator
+{
+private:
+ const NOMAD::Step * _genStep;
+
+public:
+ explicit My_EvaluatorOut(const std::shared_ptr& evalParams, const NOMAD::Step * genStep )
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB),
+ _genStep(genStep)
+ {}
+
+ ~My_EvaluatorOut() override = default;
+
+ bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
+};
+
+
+/*----------------------------------------*/
+/* user-defined eval_x */
+/*----------------------------------------*/
+bool My_EvaluatorOut::eval_x(NOMAD::EvalPoint &x,
+ const NOMAD::Double &hMax,
+ bool &countEval) const
+{
+ if (Nout%2 != 0)
+ {
+ throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
+ }
+
+ //
+ // Suboptimization on 2 variables. x (dim=10) is passed as a fixed variables to inner evaluation function
+ //
+
+ // The function to evaluate an eval point.
+ // Outer variables ->x
+ std::function&)> eval_x = [&x](std::vector& allXIn) -> bool
+ {
+ for (auto & xIn: allXIn)
+ {
+ double f=0;
+ // outer variables (dim 10) contribution to f
+ for ( size_t i = 1 ; i <= Nout/2 ; ++i ) {
+ f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
+ f += pow ( 1 - x[2*i-2].todouble() , 2 );
+ }
+ // inner variables (dim 2) contribution to f
+ f += pow ( 10 * (xIn[1].todouble() - pow(xIn[0].todouble(),2) ) , 2 );
+ f += pow ( 1 - xIn[0].todouble() , 2 );
+
+ xIn.setF(f);
+ xIn.setH(0);
+ }
+ return true;
+ };
+
+ // Inner Sub-Pb parameters
+ auto pbParams = std::make_shared();
+ pbParams->setAttributeValue("DIMENSION",2);
+ pbParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(2,-5)); // lb = (-5,-5)
+ pbParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(2,5)); // ub = (5,5)
+ NOMAD::ArrayOfPoint x0s{NOMAD::ArrayOfDouble(2,0)}; // A single X0 = (0,0)
+ pbParams->setAttributeValue("X0", x0s);
+ pbParams->checkAndComply();
+
+ // Run parameters (use default)
+ auto runParams = std::make_shared();
+ runParams->setAttributeValue("ANISOTROPIC_MESH",false);
+ auto evcParams = NOMAD::EvcInterface::getEvaluatorControl()->getEvaluatorControlGlobalParams();
+ runParams->checkAndComply(evcParams, pbParams);
+
+ NOMAD::BBOutputTypeList bbot = {NOMAD::BBOutputType::Type::OBJ};
+
+ auto madsStopReasons = std::make_shared>();
+
+ // Create a simple mads to solve the inner problem on 2 dimension.
+ // Outer variables -> x are available as fixed parameters in the evaluation.
+ // Simple Mads is not opportunistic. All poll points are passed at once into eval_x.
+ NOMAD::SimpleMads mads(_genStep, madsStopReasons, runParams, pbParams, bbot, eval_x /* eval_x for a block of points */, 1600 /* maxEval */);
+
+ // No need to display something at the end of the sub-optimization
+ mads.setEndDisplay(false);
+
+ mads.start();
+ bool runOk = mads.run();
+ mads.end();
+
+ double f = 0;
+ if (!runOk)
+ {
+ std::cout << "Pb with inner mads. Let's continue. f=0." << std::endl;
+ }
+ else
+ {
+ // Get the best feas solution
+ f = mads.getBestSimpleSolution(true).getF().todouble();
+ }
+
+ x.setBBO(std::to_string(f));
+
+ countEval = true; // count a black-box evaluation
+
+ return true; // the evaluation succeeded
+}
+
+
+void initAllParams(const std::shared_ptr& allParams)
+{
+ // Parameters creation
+ allParams->setAttributeValue("DIMENSION", Nout);
+ // 100 black-box evaluations
+ allParams->setAttributeValue("MAX_BB_EVAL", 400*Nout);
+
+ // Starting point
+ allParams->setAttributeValue("X0", NOMAD::Point(Nout, 0.5) );
+
+ // Bounds
+ allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(Nout, -10.0 ));
+ allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(Nout, 10.0 ));
+
+ // Constraints and objective
+ NOMAD::BBOutputTypeList bbOutputTypes = {NOMAD::BBOutputType::OBJ};
+ allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
+
+ allParams->setAttributeValue("DISPLAY_DEGREE", 2);
+
+ NOMAD::ArrayOfString ds("BBE ( SOL ) OBJ");
+ allParams->setAttributeValue("DISPLAY_STATS", ds);
+
+ // Parameters validation
+ allParams->checkAndComply();
+}
+
+
+/*------------------------------------------*/
+/* NOMAD main function */
+/*------------------------------------------*/
+int main()
+{
+ NOMAD::MainStep TheMainStep;
+
+ auto params = std::make_shared();
+ initAllParams(params);
+ TheMainStep.setAllParameters(params);
+
+ // Custom Evaluator
+ auto ev = std::make_unique(params->getEvalParams(), &TheMainStep);
+ TheMainStep.addEvaluator(std::move(ev));
+
+ try
+ {
+ TheMainStep.start();
+ TheMainStep.run();
+ TheMainStep.end();
+ }
+
+ catch(std::exception &e)
+ {
+ std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
+ }
+
+ return 0;
+}
diff --git a/examples/advanced/library/PSDMads/CMakeLists.txt b/examples/advanced/library/PSDMads/CMakeLists.txt
index 60b326ab..37e90b5a 100644
--- a/examples/advanced/library/PSDMads/CMakeLists.txt
+++ b/examples/advanced/library/PSDMads/CMakeLists.txt
@@ -15,19 +15,17 @@ install(TARGETS rosenbrock.exe
# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example test for PSDMads")
- # Can run this test after install
+message(STATUS " Add example test for PSDMads")
- if (WIN32)
- add_test(NAME ExampleAdvancedPSDMads
+if (WIN32)
+ add_test(NAME ExampleAdvancedPSDMads
COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./rosenbrock.exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
- else()
- add_test(NAME ExampleAdvancedPSDMads
+else()
+ add_test(NAME ExampleAdvancedPSDMads
COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./rosenbrock.exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
- endif()
endif()
+
diff --git a/examples/advanced/library/PSDMads/rosenbrock.cpp b/examples/advanced/library/PSDMads/rosenbrock.cpp
index 470b9e95..1a35a68f 100644
--- a/examples/advanced/library/PSDMads/rosenbrock.cpp
+++ b/examples/advanced/library/PSDMads/rosenbrock.cpp
@@ -61,11 +61,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -78,12 +78,11 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
const NOMAD::Double &hMax,
bool &countEval) const
{
-
if (N%2 != 0)
{
throw NOMAD::Exception(__FILE__,__LINE__,"Dimension N should be an even number");
}
-
+
double f=0;
for ( size_t i = 1 ; i <= N/2 ; ++i ) {
f += pow ( 10 * (x[2*i-1].todouble() - pow(x[2*i-2].todouble(),2) ) , 2 );
@@ -97,47 +96,55 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
}
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
// Parameters creation
allParams->setAttributeValue("DIMENSION", N);
// 100 black-box evaluations
allParams->setAttributeValue("MAX_BB_EVAL", 100*N);
-
-
+
// Starting point
allParams->setAttributeValue("X0", NOMAD::Point(N, 0.5) );
// Bounds
allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(N, -10.0 ));
allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(N, 10.0 ));
-
+
allParams->setAttributeValue("PSD_MADS_OPTIMIZATION",true);
allParams->setAttributeValue("PSD_MADS_NB_VAR_IN_SUBPROBLEM",2);
allParams->setAttributeValue("PSD_MADS_SUBPROBLEM_PERCENT_COVERAGE",NOMAD::Double(0.0));
allParams->setAttributeValue("PSD_MADS_SUBPROBLEM_MAX_BB_EVAL",10);
- allParams->setAttributeValue("NB_THREADS_OPENMP",4);
+
+ allParams->setAttributeValue("PSD_MADS_NB_SUBPROBLEM",4);
+
+ // ChT Temp for debugging
+ allParams->setAttributeValue("NM_SEARCH",false);
+ allParams->setAttributeValue("QUAD_MODEL_SEARCH",false);
+ allParams->setAttributeValue("DIRECTION_TYPE",NOMAD::DirectionType::ORTHO_2N);
+ allParams->setAttributeValue("EVAL_QUEUE_SORT",NOMAD::EvalSortType::DIR_LAST_SUCCESS);
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes = {NOMAD::BBOutputType::OBJ};
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
- allParams->setAttributeValue("DISPLAY_UNSUCCESSFUL",false);
+
+ NOMAD::ArrayOfString ds("BBE ( SOL ) OBJ");
+ allParams->setAttributeValue("DISPLAY_STATS", ds);
+ // allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
+ // allParams->setAttributeValue("DISPLAY_UNSUCCESSFUL",false);
// allParams->setAttributeValue("STATS_FILE", NOMAD::ArrayOfString("stats.txt bbe obj"));
// Parameters validation
allParams->checkAndComply();
-
}
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
NOMAD::MainStep TheMainStep;
auto params = std::make_shared();
diff --git a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/.gitignore b/examples/advanced/library/PyNomad/LoopSuggestAndObserve/.gitignore
deleted file mode 100644
index 6575205d..00000000
--- a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-cache.txt
diff --git a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/cache0.txt b/examples/advanced/library/PyNomad/LoopSuggestAndObserve/cache0.txt
deleted file mode 100644
index 91cfb6b4..00000000
--- a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/cache0.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-BB_OUTPUT_TYPE OBJ
-( -0.5 -1 1 ) EVAL_OK ( -0.5 )
-( -0.5 1 0.5 ) EVAL_OK ( 1 )
-( 0 0 1 ) EVAL_OK ( 3 )
diff --git a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/runTestLoopSuggestAndObserve.py b/examples/advanced/library/PyNomad/LoopSuggestAndObserve/runTestLoopSuggestAndObserve.py
deleted file mode 100644
index f0e88780..00000000
--- a/examples/advanced/library/PyNomad/LoopSuggestAndObserve/runTestLoopSuggestAndObserve.py
+++ /dev/null
@@ -1,85 +0,0 @@
-import PyNomad
-import shutil
-
-def bb(x):
- out =[]
- for i in range(len(x)):
- f =[]
- f.append(sum( [ x[i][j] for j in range(len(x[i])) ] ))
- # print(f)
- out.append(f)
- return out
-
-
-# copy cache file
-shutil.copyfile("cache0.txt","cache.txt")
-
-params = ["DISPLAY_DEGREE 2", "DIMENSION 3", "LOWER_BOUND ( -1 -1 -1 )", "UPPER_BOUND * 1", "BB_OUTPUT_TYPE OBJ", "CACHE_FILE cache.txt","INITIAL_FRAME_SIZE ( 1.0 1.0 1.0 )","MEGA_SEARCH_POLL yes" ]
-
-# Stopping criterions on bb eval and on frame size
-MAX_BB_EVAL= 100
-MIN_FRAME_SIZE= 1E-4
-MAX_ITERATIONS= 10
-
-nbEval= 0
-frameSize=100000
-
-iteration= 0
-
-for iteration in range(MAX_ITERATIONS):
-
- # Increment iteration counter
- iteration = iteration + 1
-
- if nbEval > MAX_BB_EVAL :
- print("Reached max bb eval")
- break
-
- if frameSize update parameters and cache
- updatedParams = PyNomad.observe(params,candidates,evals,"cache.txt")
-
- # Decode bytes into string
- for i in range(len(updatedParams)):
- updatedParams[i] = updatedParams[i].decode('utf-8')
- for i in range(len(params)):
- if type(params[i]) is bytes:
- params[i] = params[i].decode('utf-8')
-
- print("Updated parameters by observe:\n",updatedParams)
- print("---------------------")
-
- # Replace updated params in params OR add if not present
- for i in range(len(updatedParams)):
- split1 = updatedParams[i].split()
- found = False
- for j in range(len(params)):
- split2 = params[j].split()
- if ( split2[0].upper() == split1[0].upper() ):
- params[j] = updatedParams[i]
- found = True
- break;
- if not found:
- params.append(updatedParams[i])
-
- print("Parameters for next iteration:\n",params)
- print("\n")
diff --git a/examples/advanced/library/PyNomad/OnlyObserve/.gitignore b/examples/advanced/library/PyNomad/OnlyObserve/.gitignore
deleted file mode 100644
index 837b3093..00000000
--- a/examples/advanced/library/PyNomad/OnlyObserve/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-cache.txt
-cache*.txt
-!cache0.txt
diff --git a/examples/advanced/library/PyNomad/OnlyObserve/cache0.txt b/examples/advanced/library/PyNomad/OnlyObserve/cache0.txt
deleted file mode 100644
index 91cfb6b4..00000000
--- a/examples/advanced/library/PyNomad/OnlyObserve/cache0.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-BB_OUTPUT_TYPE OBJ
-( -0.5 -1 1 ) EVAL_OK ( -0.5 )
-( -0.5 1 0.5 ) EVAL_OK ( 1 )
-( 0 0 1 ) EVAL_OK ( 3 )
diff --git a/examples/advanced/library/PyNomad/OnlyObserve/runTestObserve.py b/examples/advanced/library/PyNomad/OnlyObserve/runTestObserve.py
deleted file mode 100644
index 3a3d08cc..00000000
--- a/examples/advanced/library/PyNomad/OnlyObserve/runTestObserve.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import PyNomad
-
-import shutil
-
-# Copy cache file
-shutil.copyfile("cache0.txt","cache.txt")
-
-params = ["DISPLAY_DEGREE 2", "DIMENSION 3", "LOWER_BOUND ( -1 -1 -1 )", "UPPER_BOUND * 1", "MAX_BB_EVAL 100", "BB_OUTPUT_TYPE OBJ", "CACHE_FILE cache.txt","MEGA_SEARCH_POLL yes" ]
-
-
-points=[[0.5,0,0.5]]
-evals=[[-1]]
-
-print("Initial parameters:\n",params)
-
-# Observe evaluated points and update cache and parameters
-updatedParams = PyNomad.observe(params,points,evals,"cache1.txt")
-
-# Decode bytes into string
-for i in range(len(updatedParams)):
- updatedParams[i] = updatedParams[i].decode('utf-8')
-
-print("Modified parameters:\n",updatedParams)
diff --git a/examples/advanced/library/PyNomad/OnlySuggest/runTestSuggest.py b/examples/advanced/library/PyNomad/OnlySuggest/runTestSuggest.py
deleted file mode 100644
index 59a1f0a9..00000000
--- a/examples/advanced/library/PyNomad/OnlySuggest/runTestSuggest.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# import PyNomad
-from PyNomad import PyNomadMainStep
-
-#params = ["DISPLAY_DEGREE 2", "DIMENSION 3", "LOWER_BOUND ( -1 -1 -1 )", "UPPER_BOUND * 1", "BB_OUTPUT_TYPE OBJ", "CACHE_FILE cache.txt", "MEGA_SEARCH_POLL yes" , "SEED 0"]
-params = ["DISPLAY_DEGREE 2", "DIMENSION 3", "LOWER_BOUND ( -1 -1 -1 )", "UPPER_BOUND * 1", "BB_OUTPUT_TYPE OBJ", "CACHE_FILE cache.txt", "LH_EVAL 5" , "SEED 0"]
-
-#candidates = PyNomad.suggest(params)
-mainstep = PyNomadMainStep(params)
-
-candidates = mainstep.suggest()
-
-print(candidates)
-
-# To obtain the same candidates the Random Number Generator (static) must be reset
-# Otherwise, each suggest call will most likely propose different candidates
-# PyNomad.resetRandomNumberGenerator()
-
-#candidates2 = PyNomad.suggest(params)
-candidates2 = mainstep.suggest()
-
-print(candidates2)
-
-#print(PyNomad.getRNGState())
diff --git a/examples/advanced/library/PyNomad/OptimizeWithMainStep/bb.py b/examples/advanced/library/PyNomad/OptimizeWithMainStep/bb.py
deleted file mode 100644
index 358c667c..00000000
--- a/examples/advanced/library/PyNomad/OptimizeWithMainStep/bb.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/python
-import sys
-
-def bb():
- filename = sys.argv[1]
- file = open(filename, 'r')
- x = file.read().split()
- file.close()
-
- dim = len(x)
- x = [float(x[i]) for i in range(dim)]
-
- f = sum([x[i]**2 for i in range(dim)])
- print(f)
-
-bb()
diff --git a/examples/advanced/library/PyNomad/OptimizeWithMainStep/param.txt b/examples/advanced/library/PyNomad/OptimizeWithMainStep/param.txt
deleted file mode 100644
index 5e605fb7..00000000
--- a/examples/advanced/library/PyNomad/OptimizeWithMainStep/param.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-
-DISPLAY_DEGREE 2
-
-DIMENSION 3
-X0 (0.71 0.51 0.51)
-LOWER_BOUND ( -1 -1 -1 )
-UPPER_BOUND * 1
-MAX_BB_EVAL 100
-
-
-BB_EXE "$python bb.py"
-BB_OUTPUT_TYPE OBJ
diff --git a/examples/advanced/library/PyNomad/OptimizeWithMainStep/runTestOptimizeWithMainStep.py b/examples/advanced/library/PyNomad/OptimizeWithMainStep/runTestOptimizeWithMainStep.py
deleted file mode 100644
index 2a3297d9..00000000
--- a/examples/advanced/library/PyNomad/OptimizeWithMainStep/runTestOptimizeWithMainStep.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import PyNomad
-
-
-params = ["DISPLAY_DEGREE 2", "DIMENSION 3", "X0 (0.71 0.51 0.51)", "LOWER_BOUND ( -1 -1 -1 )", "UPPER_BOUND * 1", "MAX_BB_EVAL 100", "BB_EXE \"$python bb.py\"" , "BB_OUTPUT_TYPE OBJ"]
-# params = ["DISPLAY_DEGREE 2"]
-
-
-PyNomad.optimizeWithMainStep(params)
diff --git a/examples/advanced/library/PyNomad/OptimizeWithMainStep/x0.txt b/examples/advanced/library/PyNomad/OptimizeWithMainStep/x0.txt
deleted file mode 100644
index bedc6e16..00000000
--- a/examples/advanced/library/PyNomad/OptimizeWithMainStep/x0.txt
+++ /dev/null
@@ -1 +0,0 @@
-0.71 0.51 0.51
diff --git a/examples/advanced/library/PyNomad/simpleExample_BlockEvalParallel.py b/examples/advanced/library/PyNomad/simpleExample_BlockEvalParallel.py
new file mode 100644
index 00000000..400058bd
--- /dev/null
+++ b/examples/advanced/library/PyNomad/simpleExample_BlockEvalParallel.py
@@ -0,0 +1,57 @@
+import PyNomad
+import sys
+
+from asyncio import gather, run
+
+
+# This example is for a block, i.e., a vector of EvalPoints, evaluated asynchronously.
+
+# Evaluation of a single point.
+async def bb_single(x):
+ try:
+ dim = x.size()
+ f = sum([x.get_coord(i)**2 for i in range(dim)])
+ except Exception as e:
+ print("Unexpected error in bb_single()", str(e))
+ return "Inf"
+ return str(f)
+
+# The blackbox output must be put in each EvalPoint passed as argument (x.setBBO()).
+async def async_bb_block(block):
+ nbPoints = block.size()
+ evals = []
+ evalOk = []
+ for i in range(nbPoints):
+ evalOk.append(False)
+ xs = block.get_x(i)
+ evals.append(bb_single(xs))
+
+ try:
+ results = await gather(*evals)
+ for k in range(nbPoints):
+ x = block.get_x(k)
+ x.setBBO(results[k].encode("UTF-8"))
+ evalOk[k] = True
+ except Exception as e:
+ print("Unexpected error in async_bb_block()", str(e))
+ return 0
+ return evalOk # list where 1 is success, 0 is a failed evaluation
+
+def sync_bb_block(block):
+ result = run(async_bb_block(block))
+ return result
+
+
+x0 = [0.71, 0.51, 0.51]
+lb = [-1, -1, -1]
+ub=[]
+
+params = ["BB_OUTPUT_TYPE OBJ", "MAX_BB_EVAL 100", "UPPER_BOUND * 1", "DIRECTION_TYPE ORTHO N+1 NEG"]
+params += ["DISPLAY_DEGREE 2", "DISPLAY_STATS BBE BLK_SIZE OBJ", "DISPLAY_ALL_EVAL true"]
+params += ["MEGA_SEARCH_POLL yes", "BB_MAX_BLOCK_SIZE 4"]
+
+result = PyNomad.optimize(sync_bb_block, x0, lb, ub, params)
+
+fmt = ["{} = {}".format(n,v) for (n,v) in result.items()]
+output = "\n".join(fmt)
+print("\nNOMAD results \n" + output + " \n")
diff --git a/examples/advanced/library/PyNomad/simpleExample_NMOptimization.py b/examples/advanced/library/PyNomad/simpleExample_NMOptimization.py
new file mode 100644
index 00000000..5a85d528
--- /dev/null
+++ b/examples/advanced/library/PyNomad/simpleExample_NMOptimization.py
@@ -0,0 +1,21 @@
+import PyNomad
+
+# This example of blackbox function is for a single process
+# The blackbox output must be put in the EvalPoint passed as argument
+def bb(x):
+ dim = x.size()
+ f = sum([x.get_coord(i)**2 for i in range(dim)])
+ x.setBBO(str(f).encode("UTF-8"))
+ return 1 # 1: success 0: failed evaluation
+
+x0 = [0.71, 0.51, 0.51]
+lb = [-1, -1, -1]
+ub=[]
+
+params = ["BB_OUTPUT_TYPE OBJ", "MAX_BB_EVAL 100","NM_OPTIMIZATION yes", "UPPER_BOUND * 1", "DISPLAY_DEGREE 2", "DISPLAY_ALL_EVAL false", "DISPLAY_STATS BBE OBJ"]
+
+result = PyNomad.optimize(bb, x0, lb, ub, params)
+
+fmt = ["{} = {}".format(n,v) for (n,v) in result.items()]
+output = "\n".join(fmt)
+print("\nNOMAD results \n" + output + " \n")
diff --git a/examples/advanced/library/PyNomad/simpleExample_basic_parallelEval.py b/examples/advanced/library/PyNomad/simpleExample_basic_parallelEval.py
new file mode 100644
index 00000000..bd57bced
--- /dev/null
+++ b/examples/advanced/library/PyNomad/simpleExample_basic_parallelEval.py
@@ -0,0 +1,25 @@
+import PyNomad
+
+# This example of blackbox function is for a single process
+# The blackbox output must be put in the EvalPoint passed as argument
+
+# Nomad parallel bb evaluations
+
+def bb(x):
+ dim = x.size()
+ f = sum([x.get_coord(i)**2 for i in range(dim)])
+ x.setBBO(str(f).encode("UTF-8"))
+
+ return 1 # 1: success 0: failed evaluation
+
+x0 = [0.71, 0.51, 0.51]
+lb = [-1, -1, -1]
+ub=[]
+
+params = ["BB_OUTPUT_TYPE OBJ", "MAX_BB_EVAL 100", "UPPER_BOUND * 1","DIRECTION_TYPE ORTHO 2n", "DISPLAY_DEGREE 2", "DISPLAY_ALL_EVAL true", "DISPLAY_STATS THREAD_NUM BBE OBJ","NB_THREADS_PARALLEL_EVAL 4"]
+
+result = PyNomad.optimize(bb, x0, lb, ub, params)
+
+fmt = ["{} = {}".format(n,v) for (n,v) in result.items()]
+output = "\n".join(fmt)
+print("\nNOMAD results \n" + output + " \n")
diff --git a/examples/advanced/library/Restart/CMakeLists.txt b/examples/advanced/library/Restart/CMakeLists.txt
index f1781e8f..9da03f29 100644
--- a/examples/advanced/library/Restart/CMakeLists.txt
+++ b/examples/advanced/library/Restart/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS restart.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_TESTS MATCHES ON)
- message(STATUS " Add example test for restart")
- # Can run this test after install
- if (WIN32)
- add_test(NAME ExampleAdvancedRestart
- COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./restart.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- )
- else()
- add_test(NAME ExampleAdvancedRestart
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./restart.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- )
- endif()
-endif()
+# No test for this example
diff --git a/examples/advanced/library/Restart/restart.cpp b/examples/advanced/library/Restart/restart.cpp
index 551891fb..2adba033 100644
--- a/examples/advanced/library/Restart/restart.cpp
+++ b/examples/advanced/library/Restart/restart.cpp
@@ -45,7 +45,7 @@
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
-/* example of a program that makes NOMAD restarts after failed iterations */
+/* example of a program that makes NOMAD restart after failed iterations */
/*--------------------------------------------------------------------------*/
#include "Nomad/nomad.hpp"
#include "Algos/EvcInterface.hpp"
@@ -64,11 +64,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams, NOMAD::EvalType evalType)
+ explicit My_Evaluator(const std::shared_ptr& evalParams, NOMAD::EvalType evalType)
: NOMAD::Evaluator(evalParams, evalType)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -102,7 +102,7 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
}
-void initAllParams(std::shared_ptr allParams, const size_t n)
+void initAllParams(const std::shared_ptr& allParams, const size_t n)
{
// Parameters creation
allParams->setAttributeValue("DIMENSION", n);
@@ -121,9 +121,9 @@ void initAllParams(std::shared_ptr allParams, const size_t
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB); // Note: pb solves easier with PB constraint. This choice is made to illustrate the custom stop and restart.
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB); // Note: pb solves easier with PB constraint. This choice is made to illustrate the custom stop and restart.
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
@@ -166,7 +166,7 @@ void userMegaIterationEnd(const NOMAD::Step& step,
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
// Dimension (Number of variables)
size_t n = 5;
@@ -186,7 +186,7 @@ int main ( int argc , char ** argv )
std::vector bf;
std::vector bi;
-
+
// Main run
try
{
@@ -203,11 +203,11 @@ int main ( int argc , char ** argv )
// New starting points
NOMAD::ArrayOfPoint x0s;
- if (bf.size() > 0)
+ if (!bf.empty())
{
x0s.push_back(bf[0]);
}
- if (bi.size() > 0)
+ if (!bi.empty())
{
x0s.push_back(bi[0]);
}
@@ -231,8 +231,8 @@ int main ( int argc , char ** argv )
bf.clear();
bi.clear();
- NOMAD::CacheBase::getInstance()->findBestFeas(bf, NOMAD::Point(n), NOMAD::EvalType::BB,NOMAD::ComputeType::STANDARD);
- NOMAD::CacheBase::getInstance()->findBestInf(bi, NOMAD::INF, NOMAD::Point(n), NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
+ NOMAD::CacheBase::getInstance()->findBestFeas(bf);
+ NOMAD::CacheBase::getInstance()->findBestInf(bi);
}
}
diff --git a/examples/advanced/library/Restart_VNS/CMakeLists.txt b/examples/advanced/library/Restart_VNS/CMakeLists.txt
deleted file mode 100644
index e9a2a86b..00000000
--- a/examples/advanced/library/Restart_VNS/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-add_executable(restart_vns.exe restart_vns.cpp )
-
-target_include_directories(restart_vns.exe PRIVATE
- ${CMAKE_SOURCE_DIR}/src)
-
-set_target_properties(restart_vns.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
-
-
-if(OpenMP_CXX_FOUND)
- target_link_libraries(restart_vns.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
-else()
- target_link_libraries(restart_vns.exe PUBLIC nomadAlgos nomadUtils nomadEval)
-endif()
-
-# installing executables and libraries
-install(TARGETS restart_vns.exe
- RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-
-
-# Add a test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for restart VNS")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedRestart
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./restart_vns.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedRestart
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./restart_vns.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
diff --git a/examples/advanced/library/Restart_VNS/problems/7_WILD3/bb.cpp b/examples/advanced/library/Restart_VNS/problems/7_WILD3/bb.cpp
deleted file mode 100644
index b8c538ee..00000000
--- a/examples/advanced/library/Restart_VNS/problems/7_WILD3/bb.cpp
+++ /dev/null
@@ -1,791 +0,0 @@
-/*---------------------------------------------------------------------------------*/
-/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
-/* */
-/* NOMAD - Version 4 has been created and developed by */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* The copyright of NOMAD - version 4 is owned by */
-/* Charles Audet - Polytechnique Montreal */
-/* Sebastien Le Digabel - Polytechnique Montreal */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
-/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
-/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
-/* for Data Valorization) */
-/* */
-/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
-/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
-/* and Exxon Mobil. */
-/* */
-/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
-/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
-/* Exxon Mobil. */
-/* */
-/* Contact information: */
-/* Polytechnique Montreal - GERAD */
-/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
-/* e-mail: nomad@gerad.ca */
-/* */
-/* 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 . */
-/* */
-/* You can find information on the NOMAD software at www.gerad.ca/nomad */
-/*---------------------------------------------------------------------------------*/
-#include
-#include
-#include
-#include
-#include
-using namespace std;
-
-/*-------------*/
-/* constants */
-/*-------------*/
-const double PI = 3.141592653589793;
-const double SQRT5 = sqrt(5.0);
-const double SQRT10 = sqrt(10.0);
-const double C13 = 13.0;
-const double C14 = 14.0;
-const double C29 = 29.0;
-const double C45 = 45.0;
-const double DINT_MAX = INT_MAX;
-
-const double Y1[] = { 0.14 , 0.18 , 0.22 , 0.25 , 0.29 ,
- 0.32 , 0.35 , 0.39 , 0.37 , 0.58 ,
- 0.73 , 0.96 , 1.34 , 2.10 , 4.39 };
-
-const double Y2[] = { 0.1957 , 0.1947 , 0.1735 , 0.1600 ,
- 0.0844 , 0.0627 , 0.0456 , 0.0342 ,
- 0.0323 , 0.0235 , 0.0246 };
-
-const double Y3[] = { 34780 , 28610 , 23650 , 19630 ,
- 16370 , 13720 , 11540 , 9744 ,
- 8261 , 7030 , 6005 , 5147 ,
- 4427 , 3820 , 3307 , 2872 };
-
-const double Y4[] = { 0.844 , 0.908 , 0.932 , 0.936 , 0.925 ,
- 0.908 , 0.881 , 0.850 , 0.818 , 0.784 ,
- 0.751 , 0.718 , 0.685 , 0.658 , 0.628 ,
- 0.603 , 0.580 , 0.558 , 0.538 , 0.522 ,
- 0.506 , 0.490 , 0.478 , 0.467 , 0.457 ,
- 0.448 , 0.438 , 0.431 , 0.424 , 0.420 ,
- 0.414 , 0.411 , 0.406 };
-
-const double Y5[] = { 1.366 , 1.191 , 1.112 , 1.013 , 0.991 ,
- 0.885 , 0.831 , 0.847 , 0.786 , 0.725 ,
- 0.746 , 0.679 , 0.608 , 0.655 , 0.616 ,
- 0.606 , 0.602 , 0.626 , 0.651 , 0.724 ,
- 0.649 , 0.649 , 0.694 , 0.644 , 0.624 ,
- 0.661 , 0.612 , 0.558 , 0.533 , 0.495 ,
- 0.500 , 0.423 , 0.395 , 0.375 , 0.372 ,
- 0.391 , 0.396 , 0.405 , 0.428 , 0.429 ,
- 0.523 , 0.562 , 0.607 , 0.653 , 0.672 ,
- 0.708 , 0.633 , 0.668 , 0.645 , 0.632 ,
- 0.591 , 0.559 , 0.597 , 0.625 , 0.739 ,
- 0.710 , 0.729 , 0.720 , 0.636 , 0.581 ,
- 0.428 , 0.292 , 0.162 , 0.098 , 0.054 };
-
-const double V[] = { 4 , 2 , 1 , 0.5 , 0.25 , 0.167 , 0.125 ,
- 0.1 , 0.0833 , 0.0714 , 0.0625 };
-
-/*-----------------------------------------*/
-/* enumeration type for the problem type */
-/*-----------------------------------------*/
-enum problem_type {
- SMOOTH , // smooth
- NONDIFF, // nonsmooth
- WILD3 , // deterministic noise
- NOISY3 // random noise
-};
-
-problem_type get_pb_type ( int pb_type ) {
- switch ( pb_type ) {
- case 1: return SMOOTH;
- case 2: return NONDIFF;
- case 3: return WILD3;
- case 4: return NOISY3;
- }
- return SMOOTH;
-}
-
-void display_pb_type ( problem_type pb_type , ostream & out ) {
- switch ( pb_type ) {
- case SMOOTH : out << "SMOOTH" ; break;
- case NONDIFF: out << "NONDIFF"; break;
- case WILD3 : out << "WILD3" ; break;
- case NOISY3 : out << "NOISY3" ; break;
- }
-}
-
-/*----------------------*/
-/* get problem name */
-/*----------------------*/
-string get_problem_name ( int nprob ) {
- switch ( nprob ) {
- case 1: return "LINEAR_FULL";
- case 2: return "LINEAR_R1";
- case 3: return "LINEAR_R1Z";
- case 4: return "ROSENBROCK";
- case 5: return "HELICAL";
- case 6: return "POWELLSG";
- case 7: return "FREUDENSTEIN_ROTH";
- case 8: return "BARD";
- case 9: return "KOWALIK_OSBORNE";
- case 10: return "MEYER";
- case 11: return "WATSON";
- case 12: return "BOX3";
- case 13: return "JENNRICH_SAMPSON";
- case 14: return "BROWN_DENNIS";
- case 15: return "CHEBYQUAD";
- case 16: return "BROWN";
- case 17: return "OSBORNE1";
- case 18: return "OSBORNE2";
- case 19: return "BDQRTIC";
- case 20: return "CUBE";
- case 21: return "MANCINO";
- case 22: return "HEART8";
- }
- return "";
-}
-
-/*-----------------------*/
-/* get instance data */
-/*-----------------------*/
-void get_instance_data ( int ninstance , // IN: in {1,2,...,53}
- problem_type pbtype , // IN
- int & nprob , // OUT
- int & n , // OUT
- int & m , // OUT
- bool & ns ) { // OUT
- switch ( ninstance ) {
- case 1: nprob = 1; n = 9; m = 45; ns = 0; break; // LINEAR_FULL
- case 2: nprob = 1; n = 9; m = 45; ns = 1; break; // LINEAR_FULL
- case 3: nprob = 2; n = 7; m = 35; ns = 0; break; // LINEAR_R1
- case 4: nprob = 2; n = 7; m = 35; ns = 1; break; // LINEAR_R1
- case 5: nprob = 3; n = 7; m = 35; ns = 0; break; // LINEAR_R1Z
- case 6: nprob = 3; n = 7; m = 35; ns = 1; break; // LINEAR_R1Z
- case 7: nprob = 4; n = 2; m = 2; ns = 0; break; // ROSENBROCK
- case 8: nprob = 4; n = 2; m = 2; ns = 1; break; // ROSENBROCK
- case 9: nprob = 5; n = 3; m = 3; ns = 0; break; // HELICAL
- case 10: nprob = 5; n = 3; m = 3; ns = 1; break; // HELICAL
- case 11: nprob = 6; n = 4; m = 4; ns = 0; break; // POWELLSG
- case 12: nprob = 6; n = 4; m = 4; ns = 1; break; // POWELLSG
- case 13: nprob = 7; n = 2; m = 2; ns = 0; break; // FREUDENSTEIN_ROTH
- case 14: nprob = 7; n = 2; m = 2; ns = 1; break; // FREUDENSTEIN_ROTH
- case 15: nprob = 8; n = 3; m = 15; ns = 0; break; // BARD
- case 16: nprob = 8; n = 3; m = 15; ns = 1; break; // BARD
- case 17: nprob = 9; n = 4; m = 11; ns = 0; break; // KOWALIK_OSBORNE
- case 18: nprob = 10; n = 3; m = 16; ns = 0; break; // MEYER
- case 19: nprob = 11; n = 6; m = 31; ns = 0; break; // WATSON
- case 20: nprob = 11; n = 6; m = 31; ns = 1; break; // WATSON
- case 21: nprob = 11; n = 9; m = 31; ns = 0; break; // WATSON
- case 22: nprob = 11; n = 9; m = 31; ns = 1; break; // WATSON
- case 23: nprob = 11; n = 12; m = 31; ns = 0; break; // WATSON
- case 24: nprob = 11; n = 12; m = 31; ns = 1; break; // WATSON
- case 25: nprob = 12; n = 3; m = 10; ns = 0; break; // BOX3
- case 26: nprob = 13; n = 2; m = 10; ns = 0; break; // JENNRICH_SAMPSON
- case 27: nprob = 14; n = 4; m = 20; ns = 0; break; // BROWN_DENNIS
- case 28: nprob = 14; n = 4; m = 20; ns = 1; break; // BROWN_DENNIS
- case 29: nprob = 15; n = 6; m = 6; ns = 0; break; // CHEBYQUAD
- case 30: nprob = 15; n = 7; m = 7; ns = 0; break; // CHEBYQUAD
- case 31: nprob = 15; n = 8; m = 8; ns = 0; break; // CHEBYQUAD
- case 32: nprob = 15; n = 9; m = 9; ns = 0; break; // CHEBYQUAD
- case 33: nprob = 15; n = 10; m = 10; ns = 0; break; // CHEBYQUAD
- case 34: nprob = 15; n = 11; m = 11; ns = 0; break; // CHEBYQUAD
- case 35: nprob = 16; n = 10; m = 10; ns = 0; break; // BROWN
- case 36: nprob = 17; n = 5; m = 33; ns = 0; break; // OSBORNE1
- case 37: nprob = 18; n = 11; m = 65; ns = 0; break; // OSBORNE2
- case 38: nprob = 18; n = 11; m = 65; ns = 1; break; // OSBORNE2
- case 39: nprob = 19; n = 8; m = 8; ns = 0; break; // BDQRTIC
- case 40: nprob = 19; n = 10; m = 12; ns = 0; break; // BDQRTIC
- case 41: nprob = 19; n = 11; m = 14; ns = 0; break; // BDQRTIC
- case 42: nprob = 19; n = 12; m = 16; ns = 0; break; // BDQRTIC
- case 43: nprob = 20; n = 5; m = 5; ns = 0; break; // CUBE
- case 44: nprob = 20; n = 6; m = 6; ns = 0; break; // CUBE
- case 45: nprob = 20; n = 8; m = 8; ns = 0; break; // CUBE
- case 46: nprob = 21; n = 5; m = 5; ns = 0; break; // MANCINO
- case 47: nprob = 21; n = 5; m = 5; ns = 1; break; // MANCINO
- case 48: nprob = 21; n = 8; m = 8; ns = 0; break; // MANCINO
- case 49: nprob = 21; n = 10; m = 10; ns = 0; break; // MANCINO
- case 50: nprob = 21; n = 12; m = 12; ns = 0; break; // MANCINO
- case 51: nprob = 21; n = 12; m = 12; ns = 1; break; // MANCINO
- case 52: nprob = 22; n = 8; m = 8; ns = 0; break; // HEART8
- case 53: nprob = 22; n = 8; m = 8; ns = 1; break; // HEART8
- }
-}
-
-/*--------------------------------------------------*/
-/* dfoxs function */
-/*--------------------------------------------------*/
-/* transcripted in C++ from the matlab version */
-/* dfoxs.m of S. Wild */
-/* http://www.mcs.anl.gov/~more/dfo/matlab/dfoxs.m */
-/*--------------------------------------------------*/
-void dfoxs ( int n , // IN : dimension of problem
- int nprob , // IN : problem index in {1,2,...,22}
- double factor , // IN : std pt is multiplied by factor
- double * x ) { // OUT: array of size n
-
- int i , j;
- double sum , tmp;
-
- switch ( nprob ) {
- case 1: // Linear function - full rank or rank 1
- case 2: // Linear function - full rank or rank 1
- case 3: // Linear function - full rank or rank 1
- case 8: // Bard function
- case 19: // Bdqrtic
- for ( i = 0 ; i < n ; ++i )
- x[i] = 1.0;
- break;
- case 4: // Rosenbrock function
- x[0] = -1.2;
- x[1] = 1.0;
- break;
- case 5: // Helical valley function
- x[0] = -1;
- for ( i = 1 ; i < n ; ++i )
- x[i] = 0.0;
- break;
- case 6: // Powell singular function
- x[0] = 3;
- x[1] = -1;
- x[2] = 0;
- x[3] = 1;
- break;
- case 7: // Freudenstein and Roth function
- x[0] = 0.5;
- x[1] = -2.0;
- break;
- case 9: // Kowalik and Osborne function
- x[0] = 0.250;
- x[1] = 0.390;
- x[2] = 0.415;
- x[3] = 0.390;
- break;
- case 10: // Meyer function
- x[0] = .02;
- x[1] = 4000;
- x[2] = 250;
- break;
- case 11: // Watson function
- case 16: // Brown almost-linear function
- case 20: // Cube
- for ( i = 0 ; i < n ; ++i )
- x[i] = 0.5;
- break;
- case 12: // Box 3-dimensional function
- x[0] = 0;
- x[1] = 10;
- x[2] = 20;
- break;
- case 13: // Jennrich and Sampson function
- x[0] = 0.3;
- x[1] = 0.4;
- break;
- case 14: // Brown and Dennis function
- x[0] = 25;
- x[1] = 5;
- x[2] = -5;
- x[3] = -1;
- break;
- case 15: // Chebyquad function
- for ( i = 1 ; i <= n ; ++i )
- x[i-1] = i/(n+1.0);
- break;
- case 17: // Osborne 1 function
- x[0] = 0.5;
- x[1] = 1.5;
- x[2] = 1.0;
- x[3] = 0.01;
- x[4] = 0.02;
- break;
- case 18: // Osborne 2 function
- x[ 0] = 1.3;
- x[ 1] = 0.65;
- x[ 2] = 0.65;
- x[ 3] = 0.7;
- x[ 4] = 0.6;
- x[ 5] = 3.0;
- x[ 6] = 5.0;
- x[ 7] = 7.0;
- x[ 8] = 2.0;
- x[ 9] = 4.5;
- x[10] = 5.5;
- break;
- case 21: // Mancino
- for ( i = 1 ; i <= n ; ++i ) {
- sum = 0;
- for ( j = 1 ; j <= n ; ++j ) {
- tmp = i;
- tmp = sqrt(tmp/j);
- sum += (tmp*( pow(sin(log(tmp)),5.0)+ pow(cos(log(tmp)),5.0)));
- }
- x[i-1] = -0.0008710996 * (pow(i-50,3.0) + sum);
- }
- break;
- case 22: // Heart8
- x[0] = -0.300;
- x[1] = -0.390;
- x[2] = 0.300;
- x[3] = -0.344;
- x[4] = -1.200;
- x[5] = 2.690;
- x[6] = 1.590;
- x[7] = -1.500;
- break;
- }
-
- for ( i = 0 ; i < n ; ++i )
- x[i] *= factor;
-}
-
-/*---------------------------------------------------*/
-/* dfovec function */
-/*---------------------------------------------------*/
-/* transcripted in C++ from the matlab version */
-/* dfovec.m of S. Wild */
-/* http://www.mcs.anl.gov/~more/dfo/matlab/dfovec.m */
-/*---------------------------------------------------*/
-bool dfovec ( int m , // IN : number of outputs
- int n , // IN : dimension of problem
- const double * x , // IN : array of size n
- int nprob , // IN : problem index in {1,2,...,22}
- double * fvec ) { // OUT: array of size m
-
- int i , j;
- double tmp , tmp1 , tmp2 , tmp3 , tmp4 , den , sum = 0;
-
- // 1. Linear function - full rank:
- if ( nprob == 1 ) {
- for ( j = 0 ; j < n ; ++j )
- sum += x[j];
- tmp = 2*sum/m + 1;
- for ( i = 0 ; i < m ; ++i ) {
- fvec[i] = -tmp;
- if ( i < n )
- fvec[i] += x[i];
- }
- }
-
- // 2. Linear function - rank 1:
- else if ( nprob == 2 ) {
- for ( j = 1 ; j <= n ; ++j )
- sum += j*x[j-1];
- for ( i = 1 ; i <= m ; ++i )
- fvec[i-1] = i*sum - 1;
- }
-
- // 3. Linear function - rank 1 with zero columns and rows:
- else if ( nprob == 3 ) {
- for ( j = 2 ; j < n ; ++j )
- sum += j*x[j-1];
- for ( i = 0 ; i < m-1 ; ++i )
- fvec[i] = i*sum - 1;
- fvec[m-1] = -1;
- }
-
- // 4. Rosenbrock function:
- else if ( nprob == 4 ) {
- fvec[0] = 10*(x[1] - x[0]*x[0]);
- fvec[1] = 1 - x[0];
- }
-
- // 5. Helical valley function:
- else if ( nprob == 5 ) {
- if ( x[0] > 0 )
- tmp = atan ( x[1]/x[0] ) / (2*PI);
- else if ( x[0] < 0 )
- tmp = atan ( x[1]/x[0] ) / (2*PI) + .5;
- else
- tmp = .25;
- fvec[0] = 10*(x[2] - 10*tmp);
- fvec[1] = 10*(sqrt(x[0]*x[0]+x[1]*x[1])-1);
- fvec[2] = x[2];
- }
-
- // 6. Powell singular function:
- else if ( nprob == 6 ) {
- fvec[0] = x[0] + 10*x[1];
- fvec[1] = SQRT5*(x[2] - x[3]);
- fvec[2] = pow(x[1] - 2*x[2],2.0);
- fvec[3] = SQRT10*pow(x[0] - x[3],2.0);
- }
-
- // 7. Freudenstein and Roth function:
- else if ( nprob == 7 ) {
- fvec[0] = -C13 + x[0] + ((5 - x[1])*x[1] - 2)*x[1];
- fvec[1] = -C29 + x[0] + ((1 + x[1])*x[1] - C14)*x[1];
- }
-
- // 8. Bard function:
- else if ( nprob == 8 ) {
- for ( i = 1 ; i <= 15 ; ++i ) {
- tmp1 = i;
- tmp2 = 16-i;
- tmp3 = tmp1;
- if ( i > 8 )
- tmp3 = tmp2;
-
- den = x[1]*tmp2 + x[2]*tmp3;
-
- if ( den == 0 )
- return false;
-
- fvec[i-1] = Y1[i-1] - (x[0] + tmp1/den);
- }
- }
-
- // 9. Kowalik and Osborne function:
- else if ( nprob == 9 ) {
- for ( i = 0 ; i < 11 ; ++i ) {
- tmp1 = V[i]*(V[i] + x[1]);
- tmp2 = V[i]*(V[i] + x[2]) + x[3];
- if ( tmp2 == 0.0 )
- return false;
- fvec[i] = Y2[i] - x[0]*tmp1/tmp2;
- }
- }
-
- // 10. Meyer function:
- else if ( nprob == 10 ) {
- for ( i = 0 ; i < 16 ; ++i ) {
- den = 5*(i+1) + C45 + x[2];
- if ( den == 0 )
- return false;
- fvec[i] = x[0]*exp(x[1]/den) - Y3[i];
- }
- }
-
- // 11. Watson function:
- else if ( nprob == 11 ) {
- for ( i = 1 ; i <= 29 ; ++i ) {
- tmp = i/C29;
- tmp1 = 0;
- tmp3 = 1;
- for ( j = 2 ; j <= n ; ++j ) {
- tmp1 += (j-1)*tmp3*x[j-1];
- tmp3 *= tmp;
- }
- tmp2 = 0;
- tmp3 = 1;
- for ( j = 1 ; j <= n ; ++j ) {
- tmp2 += tmp3*x[j-1];
- tmp3 *= tmp;
- }
- fvec[i-1] = tmp1 - tmp2*tmp2 - 1;
- }
- fvec[29] = x[0];
- fvec[30] = x[1] - x[0]*x[0] - 1;
- }
-
- // 12. Box 3-dimensional function:
- else if ( nprob == 12 ) {
- for ( i = 1 ; i <= m ; ++i ) {
- tmp = i;
- tmp1 = tmp/10.0;
- fvec[i-1] = exp(-tmp1*x[0]) - exp(-tmp1*x[1]) +
- (exp(-tmp) - exp(-tmp1))*x[2];
- }
- }
-
- // 13. Jennrich and Sampson function:
- else if ( nprob == 13 ) {
- for ( i = 1 ; i <= m ; ++i )
- fvec[i-1] = 2 + 2*i - exp(i*x[0]) - exp(i*x[1]);
- }
-
- // 14. Brown and Dennis function:
- else if ( nprob == 14 ) {
- for ( i = 1 ; i <= m ; ++i ) {
- tmp = i/5.0;
- tmp1 = x[0] + tmp*x[1] - exp(tmp);
- tmp2 = x[2] + sin(tmp)*x[3] - cos(tmp);
- fvec[i-1] = tmp1*tmp1 + tmp2*tmp2;
- }
- }
-
- // 15. Chebyquad function:
- else if ( nprob == 15 ) {
- for ( i = 0 ; i < m ; ++i )
- fvec[i] = 0.0;
- for ( j = 0 ; j < n ; ++j ) {
- tmp1 = 1;
- tmp2 = 2*x[j] - 1;
- tmp3 = 2*tmp2;
- for ( i = 0 ; i < m ; ++i ) {
- fvec[i] += tmp2;
- tmp = tmp3*tmp2 - tmp1;
- tmp1 = tmp2;
- tmp2 = tmp;
- }
- }
- tmp = -1;
- for ( i = 1 ; i <= m ; ++i ) {
- fvec[i-1] /= n;
- if ( tmp > 0 )
- fvec[i-1] += 1.0 / (i*i - 1);
- tmp = -tmp;
- }
- }
-
- // 16. Brown almost-linear function:
- else if ( nprob == 16 ) {
- sum = -n-1;
- tmp = 1;
- for ( j = 0 ; j < n ; ++j ) {
- sum += x[j];
- tmp *= x[j];
- }
- for ( i = 0 ; i < n-1 ; ++i )
- fvec[i] = x[i] + sum;
- fvec[n-1] = tmp - 1;
- }
-
- // 17. Osborne 1 function:
- else if ( nprob == 17 ) {
- for ( i = 1 ; i <= 33 ; ++i ) {
- tmp = 10*(i-1);
- tmp1 = exp(-x[3]*tmp);
- tmp2 = exp(-x[4]*tmp);
- fvec[i-1] = Y4[i-1] - (x[0] + x[1]*tmp1 + x[2]*tmp2);
- }
- }
-
- // 18. Osborne 2 function:
- else if ( nprob == 18 ) {
- for ( i = 0 ; i < 65 ; ++i ) {
- tmp = i/10.0;
- tmp1 = exp(-x[4]*tmp);
- tmp2 = exp(-x[5]*pow(tmp-x[8],2.0));
- tmp3 = exp(-x[6]*pow(tmp-x[9],2.0));
- tmp4 = exp(-x[7]*pow(tmp-x[10],2.0));
- fvec[i] = Y5[i] - (x[0]*tmp1 + x[1]*tmp2 +
- x[2]*tmp3 + x[3]*tmp4);
- }
- }
-
- // 19. Bdqrtic:
- else if ( nprob == 19 ) {
- for ( i = 1 ; i <= n-4 ; ++i ) {
- fvec[i-1 ] = (-4*x[i-1]+3.0);
- fvec[n-5+i] = (x[i-1]*x[i-1]+2*x[i]*x[i]+3*x[i+1]*x[i+1]
- +4*x[i+2]*x[i+2]+5*x[n-1]*x[n-1]);
- }
- }
-
- // 20. Cube:
- else if ( nprob == 20 ) {
- fvec[0] = (x[0]-1.0);
- for ( i = 1 ; i < n ; ++i )
- fvec[i] = 10*(x[i]-pow(x[i-1],3.0));
- }
-
- // 21. Mancino:
- else if ( nprob == 21 ) {
- for ( i = 1 ; i <= n ; ++i ) {
- tmp1 = 0;
- for ( j = 1 ; j <= n ; ++j ) {
- tmp3 = i;
- tmp2 = sqrt ( x[i-1]*x[i-1] + tmp3/j) ;
- tmp1 += tmp2*( pow(sin(log(tmp2)),5.0) + pow(cos(log(tmp2)),5.0) );
- }
- fvec[i-1]=1400*x[i-1] + pow(i-50,3.0) + tmp1;
- }
- }
-
- // 22. Heart8:
- else if ( nprob == 22 ) {
- fvec[0] = x[0] + x[1] + 0.69;
- fvec[1] = x[2] + x[3] + 0.044;
- fvec[2] = x[4]*x[0] + x[5]*x[1] - x[6]*x[2] - x[7]*x[3] + 1.57;
- fvec[3] = x[6]*x[0] + x[7]*x[1] + x[4]*x[2] + x[5]*x[3] + 1.31;
- fvec[4] = x[0]*(x[4]*x[4]-x[6]*x[6]) - 2.0*x[2]*x[4]*x[6] +
- x[1]*(x[5]*x[5]-x[7]*x[7]) - 2.0*x[3]*x[5]*x[7] + 2.65;
- fvec[5] = x[2]*(x[4]*x[4]-x[6]*x[6]) + 2.0*x[0]*x[4]*x[6] +
- x[3]*(x[5]*x[5]-x[7]*x[7]) + 2.0*x[1]*x[5]*x[7] - 2.0;
- fvec[6] = x[0]*x[4]*(x[4]*x[4]-3.0*x[6]*x[6]) +
- x[2]*x[6]*(x[6]*x[6]-3.0*x[4]*x[4]) +
- x[1]*x[5]*(x[5]*x[5]-3.0*x[7]*x[7]) +
- x[3]*x[7]*(x[7]*x[7]-3.0*x[5]*x[5]) + 12.6;
- fvec[7] = x[2]*x[4]*(x[4]*x[4]-3.0*x[6]*x[6]) -
- x[0]*x[6]*(x[6]*x[6]-3.0*x[4]*x[4]) +
- x[3]*x[5]*(x[5]*x[5]-3.0*x[7]*x[7]) -
- x[1]*x[7]*(x[7]*x[7]-3.0*x[5]*x[5]) - 9.48;
- }
-
- return true;
-}
-
-/*---------------------------------------------------*/
-/* calfun function */
-/*---------------------------------------------------*/
-/* transcripted in C++ from the matlab version */
-/* calfun.m of S. Wild */
-/* http://www.mcs.anl.gov/~more/dfo/matlab/calfun.m */
-/*---------------------------------------------------*/
-double calfun ( int m , // IN : number of outputs.
- int n , // IN : dimension of problem
- int nprob , // IN : problem index in {1,...,22}
- problem_type probtype , // IN : problem type
- const double * x , // IN : array of size n
- bool & error ) { // OUT: error flag
-
- error = false;
-
- int i;
- double tmp , f = 0.0 , n1 = 0.0 , n2 = 0.0 , ninf = 0.0 ,
- * fvec = new double[m] , * xc = new double[n];
-
- // restrict domain for some nondiff problems:
- if ( probtype == NONDIFF &&
- ( nprob == 8 ||
- nprob == 9 ||
- nprob == 13 ||
- nprob == 16 ||
- nprob == 17 ||
- nprob == 18 ) )
- for ( i = 0 ; i < n ; ++i )
- xc[i] = ( x[i] < 0.0 ) ? 0.0 : x[i];
- else if ( probtype == WILD3 ) {
- for ( i = 0 ; i < n ; ++i ) {
- xc[i] = x[i];
- tmp = fabs ( x[i] );
- n1 += tmp;
- n2 += x[i]*x[i];
- if ( tmp > ninf )
- ninf = tmp;
- }
- n2 = sqrt(n2);
- }
- else
- for ( i = 0 ; i < n ; ++i )
- xc[i] = x[i];
-
- // generate the vector:
- if ( !dfovec ( m , n , xc , nprob , fvec ) ) {
- error = true;
- delete [] xc;
- delete [] fvec;
- return 1e100;
- }
-
- delete [] xc;
-
- // calculate the function value:
- switch ( probtype ) {
-
- case SMOOTH: // smooth
- for ( i = 0 ; i < m ; ++i )
- f += fvec[i]*fvec[i];
- break;
-
- case NONDIFF: // nonsmooth
- for ( i = 0 ; i < m ; ++i )
- f += fabs ( fvec[i] );
- break;
-
- case WILD3: // deterministic noise
- tmp = 0.9*sin(100*n1)*cos(100*ninf) + 0.1*cos(n2);
- tmp *= 4.0*tmp*tmp - 3.0;
- for ( i = 0 ; i < m ; ++i )
- f += fvec[i]*fvec[i];
- f *= 1.0 + 0.001*tmp;
- break;
-
- case NOISY3: // random noise
- for ( i = 0 ; i < m ; ++i ) {
- tmp = rand() / DINT_MAX;
- tmp = 1.0 + 0.001 * ( tmp * 2.0 - 1.0 );
- tmp *= fvec[i];
- f += tmp*tmp;
- }
- break;
- }
-
- delete [] fvec;
-
- return f;
-}
-
-/*--------------------------------------*/
-/* main function */
-/*--------------------------------------*/
-int main ( int argc , char ** argv ) {
-
- if ( argc != 2 ) {
- cout << "error (no input file)" << endl;
- return 1;
- }
-
- // problem 7777777_WILD3:
- const int ninstance = 7;
- const problem_type pbtype = WILD3;
-
- int nprob;
- int n ;
- int m ;
- bool ns;
- get_instance_data ( ninstance , pbtype , nprob , n , m , ns );
-
- // bool ns;
- // get_instance_data ( ninstance , pbtype , nprob , n , m , ns );
- // {
- // cout << endl << "MORE_WILD_" << ninstance
- // << "_" << get_problem_name ( nprob ) << "_";
- // display_pb_type ( pbtype , cout );
- // cout << " (nprob=" << nprob << ",n="
- // << n << ",m=" << m << ",ns=" << ns << ")"
- // << endl;
- // }
-
- int i;
- double * x = new double[n];
-
- // read the point:
- ifstream in ( argv[1] );
-
- for ( i = 0 ; i < n ; ++i )
- in >> x[i];
-
- in.close();
-
- if ( in.fail() ) {
- cerr << endl << "could not read input file " << argv[1]
- << endl << endl;
- delete [] x;
- return 1;
- }
-
-// cout << "x = ( ";
-// for ( i = 0 ; i < n ; ++i )
-// cout << x[i] << " ";
-// cout << ")" << endl;
-
- bool error;
- double f = calfun ( m , n , nprob , pbtype , x , error );
-
- if ( error )
- cout << "error";
- else
- cout << f;
-
- cout << endl;
-
- delete [] x;
-
- return 0;
-}
diff --git a/examples/advanced/library/Restart_VNS/problems/7_WILD3/param.txt b/examples/advanced/library/Restart_VNS/problems/7_WILD3/param.txt
deleted file mode 100644
index 5997ac55..00000000
--- a/examples/advanced/library/Restart_VNS/problems/7_WILD3/param.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-BB_OUTPUT_TYPE OBJ
-TMP_DIR /tmp
-x0 * 0.0 #x0.txt
-
-HOT_RESTART_READ_FILES false
-HOT_RESTART_WRITE_FILES false
-
-#VNS_MADS_SEARCH true
-
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./STATS/stats.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats.txt
-
-# MAX_BB_EVAL 420 #100
-
-# initial_mesh_size * 5.0
-
-
-# model_search no
-# model_eval_sort no
diff --git a/examples/advanced/library/Restart_VNS/problems/7_WILD3/param_VNSmartAlgo.txt b/examples/advanced/library/Restart_VNS/problems/7_WILD3/param_VNSmartAlgo.txt
deleted file mode 100644
index 42242f23..00000000
--- a/examples/advanced/library/Restart_VNS/problems/7_WILD3/param_VNSmartAlgo.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-TMP_DIR /tmp
-BB_OUTPUT_TYPE OBJ
-x0 * 0.0 #x0.txt
-
-# MAX_BB_EVAL 100
-
-VNSMART_SEARCH yes
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./VNSmartAlgoSearch/stats_vnsmart.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./VNSmartAlgoSearch/detailedStats_vnsmart.txt
-HISTORY_FILE ./VNSmartAlgoSearch/historyFile_vnsmart.txt
diff --git a/examples/advanced/library/Restart_VNS/problems/7_WILD3/paramvns.txt b/examples/advanced/library/Restart_VNS/problems/7_WILD3/paramvns.txt
deleted file mode 100644
index 99e4906e..00000000
--- a/examples/advanced/library/Restart_VNS/problems/7_WILD3/paramvns.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-BB_OUTPUT_TYPE OBJ
-TMP_DIR /tmp
-x0 * 0.0 #x0.txt
-
-HOT_RESTART_READ_FILES false
-HOT_RESTART_WRITE_FILES false
-
-VNS_MADS_SEARCH true
-
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./STATS/stats_vns.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats_vns.txt
-
-# MAX_BB_EVAL 420 #100
-
-# initial_mesh_size * 5.0
-
-
-# model_search no
-# model_eval_sort no
diff --git a/examples/advanced/library/Restart_VNS/problems/7_WILD3/x0.txt b/examples/advanced/library/Restart_VNS/problems/7_WILD3/x0.txt
deleted file mode 100644
index c680d593..00000000
--- a/examples/advanced/library/Restart_VNS/problems/7_WILD3/x0.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-5 -20
-
diff --git a/examples/advanced/library/Restart_VNS/problems/COCO/Readme.txt b/examples/advanced/library/Restart_VNS/problems/COCO/Readme.txt
deleted file mode 100644
index e7e0e524..00000000
--- a/examples/advanced/library/Restart_VNS/problems/COCO/Readme.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-Follow the Getting started instructions from the Readme of https://github.com/numbbo/coco
-For the step 4, copy coco.h and coco.c into this subdirectory.
-Once available run the cmake configuration, build and install steps.
-An executable single_bbob-constrained.exe must be available in this subdirectory.
-
-Three (3) hardocoded attributes can be changed in the source code. Instances to be run, dimensions to include and functions considered.
-The parameter file must be modified accordingly. X0 and the number of constraints are different for each function and instance. Lower and upper bounds are the same.
diff --git a/examples/advanced/library/Restart_VNS/problems/COCO/param.txt b/examples/advanced/library/Restart_VNS/problems/COCO/param.txt
deleted file mode 100644
index dd16bb96..00000000
--- a/examples/advanced/library/Restart_VNS/problems/COCO/param.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-
-# PROBLEM PARAMETERS
-####################
-
-# Number of variables
-DIMENSION 10
-
-# Black box
-BB_EXE single_bbob-constrained.exe
-BB_OUTPUT_TYPE OBJ PB PB PB PB PB PB PB PB PB
-
-# Starting point
-X0 ( -4.426533 4.238298 1.037814 -3.581491 -4.835488 1.023338 2.797704 -2.753894 -2.859614 -4.790012 ) # Given by coco for instance 1, dim 10, f51
-
-# Bounds are useful to avoid extreme values
-LOWER_BOUND * -5.0
-UPPER_BOUND * 5.0
-
-
-# ALGORITHM PARAMETERS
-######################
-
-# The algorithm terminates after that number black-box evaluations
-# MAX_BB_EVAL 600
-
-# Parameters for display
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL 1
-DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
-STATS_FILE ./STATS/stats.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats.txt
-HISTORY_FILE ./STATS/historyFile.txt
-
diff --git a/examples/advanced/library/Restart_VNS/problems/COCO/param_VNSmartAlgo.txt b/examples/advanced/library/Restart_VNS/problems/COCO/param_VNSmartAlgo.txt
deleted file mode 100644
index 6029e107..00000000
--- a/examples/advanced/library/Restart_VNS/problems/COCO/param_VNSmartAlgo.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-# Number of variables
-DIMENSION 10
-
-# Black box
-BB_EXE single_bbob-constrained.exe
-BB_OUTPUT_TYPE OBJ PB PB PB PB PB PB PB PB PB
-
-# Starting point
-X0 ( -4.426533 4.238298 1.037814 -3.581491 -4.835488 1.023338 2.797704 -2.753894 -2.859614 -4.790012 ) # Given by coco for instance 1, dim 10, f51
-
-# Bounds are useful to avoid extreme values
-LOWER_BOUND * -5.0
-UPPER_BOUND * 5.0
-
-MAX_BB_EVAL 2000
-
-VNSMART_ALGO_SEARCH yes
-
-DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./VNSmartAlgoSearch/stats_vnsmart.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./VNSmartAlgoSearch/detailedStats_vnsmart.txt
-HISTORY_FILE ./VNSmartAlgoSearch/historyFile_vnsmart.txt
diff --git a/examples/advanced/library/Restart_VNS/problems/COCO/paramvns.txt b/examples/advanced/library/Restart_VNS/problems/COCO/paramvns.txt
deleted file mode 100644
index cebdae4e..00000000
--- a/examples/advanced/library/Restart_VNS/problems/COCO/paramvns.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-
-# PROBLEM PARAMETERS
-####################
-
-# Number of variables
-DIMENSION 10
-
-# Black box
-BB_EXE single_bbob-constrained.exe
-BB_OUTPUT_TYPE OBJ PB PB PB PB PB PB PB PB PB
-
-# Starting point
-X0 ( -4.426533 4.238298 1.037814 -3.581491 -4.835488 1.023338 2.797704 -2.753894 -2.859614 -4.790012 ) # Given by coco for instance 1, dim 10, f51
-
-# Bounds are useful to avoid extreme values
-LOWER_BOUND * -5.0
-UPPER_BOUND * 5.0
-
-
-# ALGORITHM PARAMETERS
-######################
-
-# The algorithm terminates after that number black-box evaluations
-# MAX_BB_EVAL 600
-
-# VNS search
-VNS_MADS_SEARCH true
-VNS_MADS_SEARCH_TRIGGER 0.75
-
-
-# Parameters for display
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL 1
-DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
-STATS_FILE ./STATS/stats_vns.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats_vns.txt
-HISTORY_FILE ./STATS/historyFile_vns.txt
-
diff --git a/examples/advanced/library/Restart_VNS/problems/COCO/x0.txt b/examples/advanced/library/Restart_VNS/problems/COCO/x0.txt
deleted file mode 100644
index 5e4a6a73..00000000
--- a/examples/advanced/library/Restart_VNS/problems/COCO/x0.txt
+++ /dev/null
@@ -1 +0,0 @@
--4.426533 4.238298 1.037814 -3.581491 -4.835488 1.023338 2.797704 -2.753894 -2.859614 -4.790012
diff --git a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param.txt b/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param.txt
deleted file mode 100644
index dfeb3b69..00000000
--- a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-TMP_DIR /tmp
-BB_OUTPUT_TYPE OBJ
-X0 * -5.12
-
-# LOWER_BOUND * -5.12
-# UPPER_BOUND * 5.12
-
-# MAX_BB_EVAL 500
-
-#VNS_MADS_SEARCH true
-#VNS_MADS_SEARCH_TRIGGER 0.75
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./STATS/stats.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats.txt
-HISTORY_FILE ./STATS/historyFile.txt
diff --git a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param_VNSmartAlgo.txt b/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param_VNSmartAlgo.txt
deleted file mode 100644
index ba0c4fde..00000000
--- a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/param_VNSmartAlgo.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-TMP_DIR /tmp
-BB_OUTPUT_TYPE OBJ
-X0 * -5.12
-
-# LOWER_BOUND * -5.12
-# UPPER_BOUND * 5.12
-
-MAX_BB_EVAL 100
-
-VNSMART_SEARCH yes
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./VNSmartAlgoSearch/stats_vnsmart.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./VNSmartAlgoSearch/detailedStats_vnsmart.txt
-HISTORY_FILE ./VNSmartAlgoSearch/historyFile_vnsmart.txt
diff --git a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/paramvns.txt b/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/paramvns.txt
deleted file mode 100644
index 9a214201..00000000
--- a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/paramvns.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-DIMENSION 12
-BB_EXE bb.exe
-TMP_DIR /tmp
-BB_OUTPUT_TYPE OBJ
-X0 * -5.12
-
-# LOWER_BOUND * -5.12
-# UPPER_BOUND * 5.12
-
-# MAX_BB_EVAL 500
-
-VNS_MADS_SEARCH true
-VNS_MADS_SEARCH_TRIGGER 0.75
-
-DISPLAY_STATS bbe ( sol ) obj
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL true
-STATS_FILE ./STATS/stats_vns.txt bbe ( sol ) obj
-EVAL_STATS_FILE ./STATS/detailedStats_vns.txt
-HISTORY_FILE ./STATS/historyFile_vns.txt
diff --git a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/x0.txt b/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/x0.txt
deleted file mode 100644
index ed7b51cb..00000000
--- a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/x0.txt
+++ /dev/null
@@ -1 +0,0 @@
--5.12 -5.12
diff --git a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/xe.txt b/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/xe.txt
deleted file mode 100644
index 8cc9589b..00000000
--- a/examples/advanced/library/Restart_VNS/problems/RASTRIGIN/xe.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-0 0
-
-0
\ No newline at end of file
diff --git a/examples/advanced/library/Restart_VNS/restart_vns.cpp b/examples/advanced/library/Restart_VNS/restart_vns.cpp
deleted file mode 100644
index 55e63281..00000000
--- a/examples/advanced/library/Restart_VNS/restart_vns.cpp
+++ /dev/null
@@ -1,481 +0,0 @@
-/*---------------------------------------------------------------------------------*/
-/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
-/* */
-/* NOMAD - Version 4 has been created and developed by */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* The copyright of NOMAD - version 4 is owned by */
-/* Charles Audet - Polytechnique Montreal */
-/* Sebastien Le Digabel - Polytechnique Montreal */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
-/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
-/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
-/* for Data Valorization) */
-/* */
-/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
-/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
-/* and Exxon Mobil. */
-/* */
-/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
-/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
-/* Exxon Mobil. */
-/* */
-/* Contact information: */
-/* Polytechnique Montreal - GERAD */
-/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
-/* e-mail: nomad@gerad.ca */
-/* */
-/* 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 . */
-/* */
-/* You can find information on the NOMAD software at www.gerad.ca/nomad */
-/*---------------------------------------------------------------------------------*/
-/*------------------------------------------------------------------------------------*/
-/* example of a program that makes NOMAD restarts after a chosen stopping condition */
-/* enables to restart from current state with different parameter settings (here VNS) */
-/*------------------------------------------------------------------------------------*/
-
-#include "Nomad/nomad.hpp"
-#include "Algos/EvcInterface.hpp"
-#include "Algos/Mads/MadsMegaIteration.hpp"
-#include "Algos/AlgoStopReasons.hpp"
-#include "Cache/CacheBase.hpp"
-#include "Type/LHSearchType.hpp"
-#include "Eval/SuccessStats.hpp"
-#include
-#include
-
-
-std::shared_ptr mesh;
-auto params = std::make_shared();
-auto madsStopReasons = std::make_shared>();
-
-// Problem given to the solver
-std::string problembName = "./problems/RASTRIGIN";
-std::string bbexe = "./problems/RASTRIGIN/bb.exe";
-
-// Counter for the number of successive failure
-int compteur = 0;
-
-// Thresholds
-int stopConsFailures = 3; // Threshold for the number of successive failure
-int stopMeshIndex = -2; // Threshold for the mesh index
-
-// Stopping conditions initialization
-bool stopCondition = false;
-
-// Nombre d'entrée dans la méga itération
-int nbEnterMegaIter = 0;
-
-// Number of bbeval with VNS activated
-int nbBbeBeforeVNS = 0;
-int nbBbeWithVNS = 0;
-
-// Run number
-int i = 0;
-
-// Number and state of the iteration
-int nbIteration = 0;
-bool iterationSucess = false;
-bool VNS = false;
-
-
-void initAllParams(std::shared_ptr allParams, const size_t n)
-{
- // Parameters creation
- allParams->setAttributeValue("DIMENSION", n);
- // Blackbox to evaluate
- allParams->setAttributeValue("BB_EXE", bbexe);
- // 100 black-box evaluations
- // allParams->setAttributeValue("MAX_BB_EVAL", 200);
- // Starting point
- // RASTRIGIN
- allParams->setAttributeValue("X0", NOMAD::Point(n, -5.12) );
- /*
- // COCO
- NOMAD::Point x0(n);
- x0[0] = -4.426533;
- x0[1] = 4.238298;
- x0[2] = 1.037814;
- x0[3] = -3.581491;
- x0[4] = -4.835488;
- x0[5] = 1.023338;
- x0[6] = 2.797704;
- x0[7] = -2.753894;
- x0[8] = -2.859614;
- x0[9] = -4.790012;
- allParams->setAttributeValue("X0", x0);
- */
- // Bounds
- // RASTRIGIN
- //allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, -5.12));
- //allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(n, 5.12));
- // COCO
- //allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, -5.0));
- //allParams->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(n, 5.0));
-
- // Constraints and objective
- NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::OBJ);
- // RASTRIGIN
- allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
- allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
-
-
- // COCO
- /*
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB);
- allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
- allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj cons_h"));
- */
-
- allParams->setAttributeValue("DISPLAY_DEGREE", 2);
- allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
-
- // Parameters validation
- allParams->checkAndComply();
-
-}
-
-
-/*--------------------------------------*/
-/* Before each MegaIteration, verify if */
-/* the algorithm should stop. */
-/*--------------------------------------*/
-void userMegaIterationStart(const NOMAD::Step& step,
- bool &stop)
-{
- auto megaIter = dynamic_cast(&step);
- auto bbe = NOMAD::EvcInterface::getEvaluatorControl()->getBbEval(); // Number of blackbox evaluation
-
- //std::cout << "CallBack START no VNS" << std::endl;
-
- stop = false;
-
-
- if (nullptr != megaIter)
- {
- // std::cout << std::endl << "Start mega itération!" << std::endl;
- ++nbIteration;
- // We use the success of the previous megaIteration. The success is reset to UNDEFINED at the defaultStart before this callback function is called.
- auto success = megaIter->getSuccessType(); //NOT_TRIALS, UNSUCCESSFUL, PARTIAL_SUCCESS, FULL_SUCCESS ou UNDEFINED
-
- // The counter is updated regarding the reuslt of the previous iteration
- if (NOMAD::SuccessType::FULL_SUCCESS == success || NOMAD::SuccessType::PARTIAL_SUCCESS == success) // counter reset for success or partial success
- {
- //std::cout << "SUCCESS OR PARTIAL SUCCESS" << std::endl;
- compteur = 0;
- iterationSucess = true;
- }
- else if (NOMAD::SuccessType::UNDEFINED == success) // no event case
- {
- //std::cout << "Default type set at start" << std::endl;
- }
- else // update if unsuccessful or no trial points
- {
- //std::cout << "UNSUCCESSFUL OR NO_TRIALS" << std::endl;
- ++compteur;
- }
- // std::cout << "Nb consecutive fails:" << compteur << std::endl;
-
- // We can also have access to this information through nomad statistics
- // auto nbConsecutiveFail = megaIter->getConstSuccessStats().getStatsNbConsecutiveFail();
- // std::cout << "Compteur NOMAD : " << nbConsecutiveFail << std::endl;
-
- if (i > 0) {
- // Keep information about the value of mesh index from the previous run
- NOMAD::ArrayOfDouble oldMeshIndices = mesh->getMeshIndex();
- //std::cout << "old mesh indices : " << oldMeshIndices << std::endl;
-
- // Let's pass the mesh
- //std::cout << std::endl << "Mesh :" << std::endl;
- mesh = megaIter->getMesh();
- //std::cout << *mesh << std::endl;
-
- // Set the mesh index value
- mesh->setMeshIndex(oldMeshIndices);
- }
- else {
- // Let's pass the mesh
- //std::cout << std::endl << Mesh :" << std::endl;
- mesh = megaIter->getMesh();
- //std::cout << *mesh << std::endl;
- }
-
- // Let's print a parameter on MAX_BB_EVAL
- // int maxBbEval;
- // maxBbEval = params->getAttributeValue("MAX_BB_EVAL");
- // std::cout << "MAX_BB_EVAL : " << maxBbEval << std::endl;
-
- // Collect mesh index information
- NOMAD::ArrayOfDouble meshIndices = mesh->getMeshIndex();
- NOMAD::ArrayOfDouble meshIndexStop(meshIndices.size(), stopMeshIndex);
- //std::cout << "mesh indices: " << meshIndices << std::endl;
- // std::cout << "mesh stop indices: " << meshIndexStop << std::endl;
-
- // Reinitialize the iteration state
- iterationSucess = false;
-
- // Stopping conditions:
- stopCondition = (compteur >= stopConsFailures);
- //std::cout << std::endl << "Stopping condition: " << stopCondition << std::endl;
-
- if (stopCondition) // Stop motivated by user conditions
- {
- stop = true;
- }
- }
-}
-
-/*--------------------------------------------*/
-/* Before each MegaIteration after using VNS, */
-/* the algorithm should stop. */
-/*--------------------------------------------*/
-void userMegaIterationStartForVNS(const NOMAD::Step& step,
- bool &stop)
-{
- auto megaIter = dynamic_cast(&step);
- auto bbe = NOMAD::EvcInterface::getEvaluatorControl()->getBbEval(); // Récupère le nombre de blackbox evaluations
-
-
- stop = false;
-
- if (nullptr != megaIter)
- {
-
- ++nbEnterMegaIter;
- ++nbIteration;
- // std::cout << std::endl << "Nb mega iter: " << nbEnterMegaIter << std::endl;
- // We use the success of the previous megaIteration. The success is reset to UNDEFINED at the defaultStart before this callback function is called.
- auto success = megaIter->getSuccessType(); //NO_TRIALS, UNSUCCESSFUL, PARTIAL_SUCCESS, FULL_SUCCESS ou UNDEFINED
-
- // The counter is updated regarding the reuslt of the previous iteration
- if (NOMAD::SuccessType::FULL_SUCCESS == success || NOMAD::SuccessType::PARTIAL_SUCCESS == success) // counter reset for success or partial success
- {
- compteur = 0;
- iterationSucess = true;
- }
- else if (NOMAD::SuccessType::UNDEFINED == success) // no event case
- {
- std::cout << "Default type set at start" << std::endl;
- }
- else // update if unsuccessful or no trial points
- {
- ++compteur;
- }
- //std::cout << "Number of successive fails: " << compteur << std::endl;
-
-
- // Keep information about the value of mesh index from the previous run
- NOMAD::ArrayOfDouble oldMeshIndices = mesh->getMeshIndex();
- // std::cout << "old mesh indices: " << oldMeshIndices << std::endl;
-
- // Let's pass the mesh
- //std::cout << std::endl << "Mesh :" << std::endl;
- mesh = megaIter->getMesh();
- //std::cout << *mesh << std::endl;
-
- // Set the mesh index value
- mesh->setMeshIndex(oldMeshIndices);
-
- // Collect mesh index information
- NOMAD::ArrayOfDouble meshIndices = mesh->getMeshIndex();
- NOMAD::ArrayOfDouble meshIndexStop(meshIndices.size(), stopMeshIndex);
- //std::cout << "mesh indices : " << meshIndices << std::endl;
- //std::cout << "mesh stop indices : " << meshIndexStop << std::endl;
-
- iterationSucess = false;
-
- // Stopping conditions:
- stopCondition = (compteur >= stopConsFailures);
- // std::cout << std::endl << "Stopping condition: " << stopCondition << std::endl;
-
- // Stop motivated by user conditions : after one megaiteration
- if (NOMAD::SuccessType::UNDEFINED != success && nbEnterMegaIter > 1)
- {
- stop = true;
- nbEnterMegaIter = 0;
- nbBbeWithVNS += (bbe - nbBbeBeforeVNS);
- }
- }
-}
-
-
-/*------------------------------------------*/
-/* NOMAD main function */
-/*------------------------------------------*/
-int main ( int argc , char ** argv )
-{
- // Dimension (Number of variables)
- size_t n = 12;
-
- NOMAD::MainStep TheMainStep;
-
- initAllParams(params, n);
- TheMainStep.setAllParameters(params);
-
- // Custom batch Evaluator
- auto ev = std::make_unique(params->getEvalParams(),NOMAD::EvalType::BB);
- TheMainStep.addEvaluator(std::move(ev));
-
- std::vector bf;
- std::vector bi;
- bool stopLoop = false;
- bool stopReasonIsCallback = false;
-
- // Main run
- try
- {
- i = 0;
- // successive runs:
- do
- {
- std::cout << std::endl << "MADS run #" + NOMAD::itos(i) << std::endl;
-
- // Stats files
- std::string statsFile = problembName;
- statsFile += "/STATS/stats";
- statsFile += std::to_string(i);
- statsFile += ".txt bbe ( sol ) obj";
- params->setAttributeValue("STATS_FILE", NOMAD::ArrayOfString(statsFile));
-
- std::string detailedStatsFile = problembName;
- detailedStatsFile += "/STATS/detailedStats";
- detailedStatsFile += std::to_string(i);
- detailedStatsFile += ".txt";
- params->setAttributeValue("EVAL_STATS_FILE", std::string(detailedStatsFile));
-
- std::string historyFile = problembName;
- historyFile += "/STATS/history";
- historyFile += std::to_string(i);
- historyFile += ".txt";
- params->setAttributeValue("HISTORY_FILE", std::string(historyFile));
-
- // Set callbacks
-
- if (!stopCondition) // MADS default without VNS
- {
- std::cout << "MADS default no VNS" << std::endl;
- TheMainStep.addCallback(NOMAD::CallbackType::MEGA_ITERATION_START, userMegaIterationStart);
-
- if ( i > 0 )
- {
- // Seuil compteur dynamique
- stopConsFailures = static_cast(3*std::ceil(i/5.0));
-
- // Desactivate VNS MADS search
- params->getRunParams()->setAttributeValue("VNS_MADS_SEARCH", false);
-
-
- // New starting points
- NOMAD::ArrayOfPoint x0s;
- if (bf.size() > 0)
- {
- x0s.push_back(bf[0]);
- }
- if (bi.size() > 0)
- {
- x0s.push_back(bi[0]);
- }
- params->getPbParams()->setAttributeValue("X0", x0s);
-
- //std::cout << mesh->getDeltaFrameSize() << std::endl;
- params->getPbParams()->setAttributeValue("INITIAL_FRAME_SIZE", mesh->getDeltaFrameSize());
-
- // at least one evaluation is conducted if points bf and bi are null
- std::string lhSearchStr = (bf.empty() && bi.empty()) ? " 1 0" : "0 0";
- params->getRunParams()->setAttributeValue("LH_SEARCH", NOMAD::LHSearchType(lhSearchStr));
-
- // Parameters validation
- params->checkAndComply();
- }
-
- }
- else // MADS default + VNS for 1 mega iteration only
- {
- // Update thresholds for the stopping criterion
- stopConsFailures = static_cast(3*std::ceil(i/5.0));
-
- TheMainStep.addCallback(NOMAD::CallbackType::MEGA_ITERATION_START, userMegaIterationStartForVNS);
- nbBbeBeforeVNS = NOMAD::EvcInterface::getEvaluatorControl()->getBbEval(); // Keeps the number of blackbox evaluations before using VNS
-
- // Activate VNS MADS serach
- params->getRunParams()->setAttributeValue("VNS_MADS_SEARCH", true);
- params->getRunParams()->setAttributeValue("VNS_MADS_SEARCH_TRIGGER", NOMAD::Double(1));
-
- // New starting points
- NOMAD::ArrayOfPoint x0s;
- if (bf.size() > 0)
- {
- x0s.push_back(bf[0]);
- }
- if (bi.size() > 0)
- {
- x0s.push_back(bi[0]);
- }
- params->getPbParams()->setAttributeValue("X0", x0s);
-
- //std::cout << mesh->getDeltaFrameSize() << std::endl;
- params->getPbParams()->setAttributeValue("INITIAL_FRAME_SIZE", mesh->getDeltaFrameSize());
-
- // at least one evaluation is conducted if points bf and bi are null
- std::string lhSearchStr = (bf.empty() && bi.empty()) ? " 1 0" : "0 0";
- params->getRunParams()->setAttributeValue("LH_SEARCH", NOMAD::LHSearchType(lhSearchStr));
-
- // Parameters validation
- params->checkAndComply();
-
- }
-
- // The run
- TheMainStep.start();
- TheMainStep.run();
- TheMainStep.end();
-
- auto algoStopReason = NOMAD::AlgoStopReasons::get(TheMainStep.getAllStopReasons()); // Récupère le stop reason de mads
- stopLoop = algoStopReason->testIf(NOMAD::MadsStopType::MESH_PREC_REACHED) || algoStopReason->testIf(NOMAD::MadsStopType::MIN_MESH_INDEX_REACHED) ; // Test si le stop reason correspond MESH_PREC_REACHED
- std::cout << algoStopReason->getStopReasonAsString() << std::endl; // Juste affiche le stop reason.
-
- stopReasonIsCallback = (algoStopReason->getStopReasonAsString() == "User-stopped in a callback function (Base)");
-
-
- bf.clear();
- bi.clear();
- NOMAD::CacheBase::getInstance()->findBestFeas(bf, NOMAD::Point(n), NOMAD::EvalType::BB,NOMAD::ComputeType::STANDARD);
- NOMAD::CacheBase::getInstance()->findBestInf(bi, NOMAD::INF, NOMAD::Point(n), NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
-
- ++i;
-
- } while (!stopLoop); // run until one NOMAD termination criterion is met
-
-}
-
- catch(std::exception &e)
- {
- std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/examples/advanced/library/StopIfBBFails/CMakeLists.txt b/examples/advanced/library/StopIfBBFails/CMakeLists.txt
index 33dbeb27..e4c0da87 100644
--- a/examples/advanced/library/StopIfBBFails/CMakeLists.txt
+++ b/examples/advanced/library/StopIfBBFails/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS stopIfBBFails.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for handling bb fail")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedstopIfBBFails
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopIfBBFails.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedstopIfBBFails
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopIfBBFails.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/StopIfBBFails/stopIfBBFails.cpp b/examples/advanced/library/StopIfBBFails/stopIfBBFails.cpp
index 5e5d4729..9f8f3ec9 100644
--- a/examples/advanced/library/StopIfBBFails/stopIfBBFails.cpp
+++ b/examples/advanced/library/StopIfBBFails/stopIfBBFails.cpp
@@ -66,7 +66,7 @@
// To run this optimization, the program must be executed in a path where styrene truth executable is available.
// Styrene sources are available at https://github.com/bbopt/styrene and must be compiled prior to run this optimization.
-void initAllParams( std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
const int n = 8;
@@ -78,7 +78,6 @@ void initAllParams( std::shared_ptr allParams)
std::vector x0 = { 54, 66, 86, 8, 29, 51, 32, 15};
allParams->setAttributeValue("X0", NOMAD::Point(x0) );
allParams->setAttributeValue("BB_EXE", std::string("./truth.exe")); // IMPORTANT: May require some change
-
// Bounds
allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, 0.0 ));
@@ -91,11 +90,8 @@ void initAllParams( std::shared_ptr allParams)
allParams->setAttributeValue("DISPLAY_DEGREE", 4);
allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
-
// Parameters validation
allParams->checkAndComply();
-
-
}
@@ -120,14 +116,11 @@ void customEvalStopCB( NOMAD::EvalQueuePointPtr & evalQueuePoint, bool & globalS
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -147,5 +140,5 @@ int main ( int argc , char ** argv )
TheMainStep.run();
TheMainStep.end();
- return 1;
+ return 0;
}
diff --git a/examples/advanced/library/StopOnConsecutiveFails/CMakeLists.txt b/examples/advanced/library/StopOnConsecutiveFails/CMakeLists.txt
index 98bfc846..4e561260 100644
--- a/examples/advanced/library/StopOnConsecutiveFails/CMakeLists.txt
+++ b/examples/advanced/library/StopOnConsecutiveFails/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS stopOnConsecutiveFails.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for handling stop after consecutive fails")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedstopOnConsecutiveFails
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopOnConsecutiveFails.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedstopOnConsecutiveFails
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopOnConsecutiveFails.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/StopOnConsecutiveFails/stopOnConsecutiveFails.cpp b/examples/advanced/library/StopOnConsecutiveFails/stopOnConsecutiveFails.cpp
index b3c1182d..0fc779c1 100644
--- a/examples/advanced/library/StopOnConsecutiveFails/stopOnConsecutiveFails.cpp
+++ b/examples/advanced/library/StopOnConsecutiveFails/stopOnConsecutiveFails.cpp
@@ -62,11 +62,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -98,9 +98,8 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
return true; // the evaluation succeeded
}
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
-
const size_t n = 5;
// Parameters creation
@@ -119,9 +118,9 @@ void initAllParams(std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
@@ -130,7 +129,6 @@ void initAllParams(std::shared_ptr allParams)
// Parameters validation requested to have access to their value.
allParams->checkAndComply();
-
}
@@ -165,14 +163,11 @@ void userIterationCallback(const NOMAD::Step& step,
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -186,12 +181,11 @@ int main ( int argc , char ** argv )
// Set main step callback
TheMainStep.addCallback(NOMAD::CallbackType::MEGA_ITERATION_END, userIterationCallback);
-
-
+
// The run
TheMainStep.start();
TheMainStep.run();
TheMainStep.end();
- return 1;
+ return 0;
}
diff --git a/examples/advanced/library/c_api/example1/CMakeLists.txt b/examples/advanced/library/c_api/example1/CMakeLists.txt
index 58ed2ab4..ddc099d5 100644
--- a/examples/advanced/library/c_api/example1/CMakeLists.txt
+++ b/examples/advanced/library/c_api/example1/CMakeLists.txt
@@ -41,20 +41,19 @@ install(TARGETS example1_c_api.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
# Add a test for this example
-if(BUILD_EXAMPLES MATCHES ON)
- message(STATUS " Add example test for c-api 1")
- # Can run this test after install
+message(STATUS " Add example test for c-api 1")
+
+# Can run this test after install
- if (WIN32)
+if (WIN32)
# MAYBE ENABLE the test when script is adapted to windows
# add_test(NAME ExampleAdvancedC-API1
# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example1_c_api.exe
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# )
- else()
- add_test(NAME ExampleAdvancedC-API1
+else()
+ add_test(NAME ExampleAdvancedC-API1
COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example1_c_api.exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
- endif()
endif()
diff --git a/examples/advanced/library/c_api/example1/example1_c_api.c b/examples/advanced/library/c_api/example1/example1_c_api.c
index 2144be78..eea107d6 100644
--- a/examples/advanced/library/c_api/example1/example1_c_api.c
+++ b/examples/advanced/library/c_api/example1/example1_c_api.c
@@ -13,7 +13,6 @@ bool example1_bb(int nb_inputs, double *x, int nb_outputs, double *bb_outputs, b
bool eval_ok = true;
// based on G2
- double f = 1e+20, g1 = 1e+20, g2 = 1e+20;
double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, prod1 = 1.0, prod2 = 1.0;
for (int i = 0; i < nb_inputs; ++i)
@@ -35,10 +34,10 @@ bool example1_bb(int nb_inputs, double *x, int nb_outputs, double *bb_outputs, b
}
}
- g1 = -prod2 + 0.75;
- g2 = sum2 - 7.5 * nb_inputs;
+ const double g1 = -prod2 + 0.75;
+ const double g2 = sum2 - 7.5 * nb_inputs;
- f = 10 * g1 + 10 * g2;
+ double f = 10 * g1 + 10 * g2;
if (0.0 != sum3)
{
f -= fabs(((sum1 - 2 * prod1) / sqrt(sum3)));
@@ -71,6 +70,7 @@ int main(int argc, char **argv)
// create Nomad problem
NomadProblem nomad_pb = createNomadProblem(example1_bb,
+ NULL,
nb_inputs,
nb_outputs);
@@ -90,9 +90,6 @@ int main(int argc, char **argv)
addNomadParam(nomad_pb, "DISPLAY_ALL_EVAL true");
addNomadParam(nomad_pb, "DISPLAY_UNSUCCESSFUL false");
- // for reproducibility
- addNomadValParam(nomad_pb, "NB_THREADS_OPENMP", 1);
-
// and the number of blackbox allowed
addNomadParam(nomad_pb, "MAX_BB_EVAL 1000");
@@ -100,24 +97,22 @@ int main(int argc, char **argv)
double x0[10] = {7.0, 7.0, 7.0, 7.0, 7.0,
7.0, 7.0, 7.0, 7.0, 7.0}; // starting point
- double x_feas_sol[10] = {0.0, 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0, 0.0}; // feasible solution
-
- double x_inf_sol[10] = {0.0, 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0, 0.0}; // infeasible solution
+ NomadResult nomad_result = createNomadResult();
- double outputs_feas_sol[10] = {0.0, 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0, 0.0}; // feasible solution outputs
+ int run_flag = solveNomadProblem(nomad_result, nomad_pb, 1, x0, NULL);
+ printf("Run status: %d\n", run_flag);
- double outputs_inf_sol[10] = {0.0, 0.0, 0.0, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0, 0.0}; // infeasible solution outputs
+ int nb_solutions = nbSolutionsNomadResult(nomad_result);
+ printf("The algorithm has found %d solutions\n", nb_solutions);
- bool exists_feas, exists_infeas = false; // flag which indicates if the solution exists or not
+ // Get a solution
+ double x_sol[10];
+ double outputs_sol[4];
- solveNomadProblem(nomad_pb, 1, x0,
- &exists_feas, x_feas_sol, outputs_feas_sol,
- &exists_infeas, x_inf_sol, outputs_inf_sol,
- NULL);
+ bool exists_feas = feasibleSolutionsFoundNomadResult(nomad_result) &&
+ nb_solutions > 0;
+ loadInputSolutionsNomadResult(x_sol, 1, nomad_result);
+ loadOutputSolutionsNomadResult(outputs_sol, 1, nomad_result);
// display found solutions
if (exists_feas)
@@ -126,24 +121,27 @@ int main(int argc, char **argv)
printf("x_feas = [ ");
for (int i = 0; i < nb_inputs; ++i)
{
- printf("%f ", x_feas_sol[i]);
+ printf("%f ", x_sol[i]);
}
printf(" ]\n");
printf("f_feas = ");
- printf("%f \n", outputs_feas_sol[2]);
+ printf("%f \n", outputs_sol[2]);
+ printf("Constraints = [ %f %f %f ]\n",
+ outputs_sol[0], outputs_sol[1], outputs_sol[3]);
}
-
- if (exists_infeas) // as a feasible solution has been found, no infeasible solution is given
+ else
{
printf("Best infeasible solution found (least infeasible with lowest f): \n");
printf("x_infeas = [ ");
for (int i = 0; i < nb_inputs; ++i)
{
- printf("%f ", x_inf_sol[i]);
+ printf("%f ", x_sol[i]);
}
printf(" ]\n");
printf("f_infeas = ");
- printf("%f \n", outputs_inf_sol[2]);
+ printf("%f \n", outputs_sol[2]);
+ printf("Constraints = [ %f %f %f ]\n",
+ outputs_sol[0], outputs_sol[1], outputs_sol[3]);
}
// NB: relaunch the problem will restart from the beginning
@@ -152,13 +150,19 @@ int main(int argc, char **argv)
printf("\n");
addNomadBoolParam(nomad_pb, "DISPLAY_ALL_EVAL", false);
+ // Set the dependant parameters to their default value
+ // Needed because they have been set in the previous run and are not reset by default
+ addNomadBoolParam(nomad_pb, "DISPLAY_INFEASIBLE", true);
+ addNomadBoolParam(nomad_pb, "DISPLAY_UNSUCCESSFUL", false);
- exists_feas = false;
- exists_infeas = false;
- solveNomadProblem(nomad_pb, 1, x0,
- &exists_feas, x_feas_sol, outputs_feas_sol,
- &exists_infeas, x_inf_sol, outputs_inf_sol,
- NULL);
+ run_flag = solveNomadProblem(nomad_result, nomad_pb, 1, x0, NULL);
+ printf("Run status: %d\n", run_flag);
+
+ nb_solutions = nbSolutionsNomadResult(nomad_result);
+ exists_feas = feasibleSolutionsFoundNomadResult(nomad_result) &&
+ nb_solutions > 1;
+ loadInputSolutionsNomadResult(x_sol, 1, nomad_result);
+ loadOutputSolutionsNomadResult(outputs_sol, 1, nomad_result);
// display found solutions
if (exists_feas)
@@ -167,27 +171,31 @@ int main(int argc, char **argv)
printf("x_feas = [ ");
for (int i = 0; i < nb_inputs; ++i)
{
- printf("%f ", x_feas_sol[i]);
+ printf("%f ", x_sol[i]);
}
printf(" ]\n");
printf("f_feas = ");
- printf("%f \n", outputs_feas_sol[2]);
+ printf("%f \n", outputs_sol[2]);
+ printf("c(x) = [ %f %f %f ]\n",
+ outputs_sol[0], outputs_sol[1], outputs_sol[3]);
}
-
- if (exists_infeas) // as a feasible solution has been found, no infeasible solution is given
+ else
{
printf("Best infeasible solution found: \n");
printf("x_infeas = [ ");
for (int i = 0; i < nb_inputs; ++i)
{
- printf("%f ", x_inf_sol[i]);
+ printf("%f ", x_sol[i]);
}
printf(" ]\n");
printf("f_infeas = ");
- printf("%f \n", outputs_inf_sol[2]);
+ printf("%f \n", outputs_sol[2]);
+ printf("c(x) = [ %f %f %f ]\n",
+ outputs_sol[0], outputs_sol[1], outputs_sol[3]);
}
freeNomadProblem(nomad_pb);
+ freeNomadResult(nomad_result);
return EXIT_SUCCESS;
}
diff --git a/examples/advanced/library/c_api/example2/CMakeLists.txt b/examples/advanced/library/c_api/example2/CMakeLists.txt
index 1748f9d0..1d06831d 100644
--- a/examples/advanced/library/c_api/example2/CMakeLists.txt
+++ b/examples/advanced/library/c_api/example2/CMakeLists.txt
@@ -42,21 +42,4 @@ install(TARGETS example2_c_api.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-if(BUILD_EXAMPLES MATCHES ON)
- message(STATUS " Add example test for c-api 2")
- # Can run this test after install
-
- if (WIN32)
-# MAYBE enable when script works for windows
-# add_test(NAME ExampleAdvancedC-API2
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example2_c_api.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
- else()
- add_test(NAME ExampleAdvancedC-API2
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example2_c_api.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- )
- endif()
-endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/advanced/library/c_api/example2/example2_c_api.c b/examples/advanced/library/c_api/example2/example2_c_api.c
index 57cc6845..4f26c332 100644
--- a/examples/advanced/library/c_api/example2/example2_c_api.c
+++ b/examples/advanced/library/c_api/example2/example2_c_api.c
@@ -39,6 +39,7 @@ int solve_moustache_pb()
// create Nomad problem
NomadProblem nomad_pb = createNomadProblem(moustache_bb,
+ NULL,
nb_inputs,
nb_outputs);
@@ -59,20 +60,23 @@ int solve_moustache_pb()
// run problem
double x0[2] = {0, 2.0}; // starting point
- double x_feas_sol[2] = {0.0, 0.0}; // feasible solution
-
- double x_inf_sol[2] = {0.0, 0.0}; // infeasible solution
-
- double outputs_feas_sol[3] = {0.0, 0.0, 0.0}; // feasible solution outputs
-
- double outputs_inf_sol[3] = {0.0, 0.0, 0.0}; // infeasible solution outputs
-
- bool exists_feas, exists_infeas = false; // flag which indicates if the solution exists or not
-
- solveNomadProblem(nomad_pb, 1, x0,
- &exists_feas, x_feas_sol, outputs_feas_sol,
- &exists_infeas, x_inf_sol, outputs_inf_sol,
- NULL);
+ NomadResult nomad_result = createNomadResult();
+ int run_flag = solveNomadProblem(nomad_result, nomad_pb, 1, x0, NULL);
+ printf("Run status: %d\n", run_flag);
+ const int nb_solutions = nbSolutionsNomadResult(nomad_result);
+ const bool exists_feas = feasibleSolutionsFoundNomadResult(nomad_result);
+ printf("The solver has found %d solutions ", nb_solutions);
+ if (exists_feas)
+ {
+ printf("and they are feasible\n");
+ }
+ else
+ {
+ printf("and they are infeasible\n");
+ }
+
+ freeNomadProblem(nomad_pb);
+ freeNomadResult(nomad_result);
return 0;
}
@@ -127,6 +131,33 @@ bool speedreducer_bb(int nb_inputs, double *x, int nb_outputs, double *bb_output
return true;
}
+void speedreducer_bb_block(int block_size, int nb_inputs, double *x,
+ int nb_outputs, double *bb_outputs,
+ bool *count_eval, bool *eval_ok, NomadUserDataPtr data)
+{
+ double *inputs = malloc(nb_inputs * sizeof(double));
+ double *outputs = malloc(nb_outputs * sizeof(double));
+ for (int index = 0; index < block_size; ++index)
+ {
+ for (int i = 0; i < nb_inputs; ++i)
+ {
+ inputs[i] = x[index * nb_inputs + i];
+ }
+ // Call the blackbox on each element of the block
+ // There could be some applications where it is faster
+ // to parallelize the blocks
+ eval_ok[index] = speedreducer_bb(nb_inputs, inputs,
+ nb_outputs, outputs,
+ &count_eval[index], data);
+ for (int i = 0; i < nb_outputs; ++i)
+ {
+ bb_outputs[index * nb_outputs + i] = outputs[i];
+ }
+ }
+ free(inputs);
+ free(outputs);
+}
+
int solve_speedreducer_pb()
{
// fix essential parameters of the blackbox
@@ -143,6 +174,7 @@ int solve_speedreducer_pb()
// create Nomad problem
NomadProblem nomad_pb = createNomadProblem(speedreducer_bb,
+ speedreducer_bb_block,
dim,
nb_outputs);
@@ -163,6 +195,9 @@ int solve_speedreducer_pb()
// set non opportunistic eval
addNomadBoolParam(nomad_pb, "EVAL_OPPORTUNISTIC", false);
+ // Activate evaluation per block
+ addNomadValParam(nomad_pb, "BB_MAX_BLOCK_SIZE", 4);
+
// run problem
double x0[7] = {3.000000000000000e+00,
7.500000000000000e-01,
@@ -172,25 +207,30 @@ int solve_speedreducer_pb()
3.400000000000000e+00,
5.250000000000000e+00};
- double x_feas_sol[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // feasible solution
-
- double x_inf_sol[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // infeasible solution
-
- double outputs_feas_sol[12] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // feasible solution outputs
-
- double outputs_inf_sol[12] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // infeasible solution outputs
-
- bool exists_feas, exists_infeas = false; // flag which indicates if the solution exists or not
-
- solveNomadProblem(nomad_pb, 1, x0,
- &exists_feas, x_feas_sol, outputs_feas_sol,
- &exists_infeas, x_inf_sol, outputs_inf_sol,
- NULL);
+ NomadResult nomad_result = createNomadResult();
+ int run_flag = solveNomadProblem(nomad_result,
+ nomad_pb, 1, x0,
+ NULL);
+ printf("Run status: %d\n", run_flag);
+ const int nb_solutions = nbSolutionsNomadResult(nomad_result);
+ const bool exists_feas = feasibleSolutionsFoundNomadResult(nomad_result);
+ printf("The solver has found %d solutions ", nb_solutions);
+ if (exists_feas)
+ {
+ printf("and they are feasible\n\n");
+ }
+ else
+ {
+ printf("and they are infeasible\n\n");
+ }
+
+ freeNomadProblem(nomad_pb);
+ freeNomadResult(nomad_result);
return 0;
}
-int main(int argc, char **argv)
+int main()
{
solve_moustache_pb();
solve_speedreducer_pb();
diff --git a/examples/advanced/library/c_api/example3/CMakeLists.txt b/examples/advanced/library/c_api/example3/CMakeLists.txt
new file mode 100644
index 00000000..79089c08
--- /dev/null
+++ b/examples/advanced/library/c_api/example3/CMakeLists.txt
@@ -0,0 +1,45 @@
+add_executable(example3_c_api.exe example3_c_api.c)
+
+target_include_directories(
+ example3_c_api.exe
+ PRIVATE
+ ${CMAKE_SOURCE_DIR}/src
+ ${CMAKE_SOURCE_DIR}/interfaces/CInterface
+)
+
+set_target_properties(
+ example3_c_api.exe
+ PROPERTIES
+ INSTALL_RPATH
+ "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
+ SUFFIX ""
+)
+
+
+if(OpenMP_CXX_FOUND)
+ target_link_libraries(
+ example3_c_api.exe
+ PUBLIC
+ nomadCInterface
+ OpenMP::OpenMP_CXX
+ )
+else()
+ target_link_libraries(
+ example3_c_api.exe
+ PUBLIC nomadCInterface
+ )
+endif()
+
+if (NOT WIN32)
+ target_link_libraries(
+ example3_c_api.exe
+ PUBLIC m
+ )
+endif()
+
+# installing executables and libraries
+install(TARGETS example3_c_api.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+
+# No test for this example
diff --git a/examples/advanced/library/c_api/example3/example3_c_api.c b/examples/advanced/library/c_api/example3/example3_c_api.c
new file mode 100644
index 00000000..8fe7a312
--- /dev/null
+++ b/examples/advanced/library/c_api/example3/example3_c_api.c
@@ -0,0 +1,212 @@
+#include
+#include
+#include
+#include
+
+#include "NomadStdCInterface.h"
+
+// A conceptual marine design problem
+// See "An Easy-To-use Real-world Multi-objective Optimization Suite problem"
+// by R. Tanabe and H. Ishibuchi
+bool marine_design_bb(int nb_inputs, double *x, int nb_outputs, double *bb_outputs, bool *count_eval, NomadUserDataPtr data)
+{
+ bool eval_ok = true;
+
+ // Variables
+ const double L = x[0];
+ const double B = x[1];
+ const double D = x[2];
+ const double T = x[3];
+ const double Vk = x[4];
+ const double Cb = x[5];
+
+ // Parameters
+ const double handlingRate = 8000;
+ const double roundTripMiles = 5000;
+ const double fuelPrice = 100;
+ const double g = 9.8065;
+
+ // Equations
+ const double verticalCenterOfBuoyancy = 0.53 * T;
+ const double metacentricRadius = (0.085 * Cb - 0.002) * B * B / (T * Cb);
+ const double verticalCenterOfGravity = 1 + 0.52 * D;
+
+ const double displacement = 1.025 * L * B * T * Cb;
+ const double a = 4977.06 * Cb * Cb - 8105.61 * Cb + 4456.51;
+ const double b = -10847.2 * Cb * Cb + 12817 * Cb - 6960.32;
+ const double V = 0.5144 * Vk;
+ const double froudenumber = V / pow(g * L, 0.5);
+ const double P = pow(displacement, 2.0/3) * pow(Vk, 3) / (a + b * froudenumber);
+
+ const double steelWeight = 0.034 * pow(L, 1.7) * pow(B, 0.7) *
+ pow(D, 0.4) * pow(Cb, 0.5);
+ const double outfitWeight = 1.0 * pow(L, 0.8) * pow(B, 0.6) *
+ pow(D, 0.3) * pow(Cb, 0.1);
+ const double machineryWeight = 0.17 * pow(P, 0.9);
+ const double lightShipWeight = steelWeight + outfitWeight + machineryWeight;
+
+ const double deadweight = displacement - lightShipWeight;
+
+ const double dailyConsumption = (0.19 * P * 24) / 1000 + 0.2;
+ const double seaDays = (roundTripMiles * Vk) / 24;
+ const double fuelCarried = dailyConsumption * (seaDays + 5);
+ const double portCost = 6.3 * pow(deadweight, 0.8);
+
+ const double cargoDeadweight = deadweight - fuelCarried - 2 * pow(deadweight, 0.5);
+ const double portDays = 2 * (cargoDeadweight / handlingRate + 0.5);
+ const double roundTripsPerYear = 350.0 / (seaDays + portDays);
+
+ const double fuelCost = 1.05 * dailyConsumption * seaDays * fuelPrice;
+ const double runningCosts = 40000 * pow(deadweight, 0.8);
+ const double voyageCosts = (fuelCost + portCost) * roundTripsPerYear;
+ const double shipCosts = 1.3 * (2000 * pow(steelWeight, 0.85) +
+ 3500 * outfitWeight + 2400 * pow(P, 0.8));
+ const double capitalCosts = 0.2 * shipCosts;
+ const double annualCosts = capitalCosts + runningCosts + voyageCosts;
+
+ const double annualCargo = - cargoDeadweight * roundTripsPerYear;
+
+ // Objectives
+ const double f1 = annualCosts / annualCargo;
+ const double f2 = lightShipWeight;
+ const double f3 = annualCargo;
+
+ // Constraints
+ const double g1 = L / B - 6.0; // >= 0
+ const double g2 = 15.0 - L / D; // >= 0
+ const double g3 = 19.0 - L / T; // >= 0
+ const double g4 = 0.45 * pow(deadweight, 0.31) - T; // >= 0
+ const double g5 = 0.7 * D + 0.7 - T; // >= 0
+ const double g6 = deadweight - 3000; // >= 0
+ const double g7 = 500000 - deadweight; // >= 0
+ const double g8 = 0.32 - froudenumber; // >= 0
+ const double g9 = verticalCenterOfBuoyancy + metacentricRadius -
+ verticalCenterOfGravity - 0.07 * B; // >= 0
+
+ // fix bb_outputs
+ bb_outputs[0] = f1;
+ bb_outputs[1] = f2;
+ bb_outputs[2] = f3;
+ bb_outputs[3] = -g1;
+ bb_outputs[4] = -g2;
+ bb_outputs[5] = -g3;
+ bb_outputs[6] = -g4;
+ bb_outputs[7] = -g5;
+ bb_outputs[8] = -g6;
+ bb_outputs[9] = -g7;
+ bb_outputs[10] = -g8;
+ bb_outputs[11] = -g9;
+
+ *count_eval = true;
+
+ return eval_ok;
+}
+
+int solve_marine_design_pb()
+{
+ // fix essential parameters of the blackbox
+ int nb_inputs = 6;
+ int nb_outputs = 12;
+ char type_bb_outputs[] = "OBJ OBJ OBJ PB PB PB PB PB PB PB PB PB";
+
+ // the problem will terminate after 1500 evaluations
+ int max_bb_eval = 1500;
+
+ // fix lower and upper bounds.
+ double lb[] = {150, 20, 13, 10, 14, 0.63};
+ double ub[] = {274.32, 32.31, 25, 11.71, 18, 0.75};
+
+ // create Nomad problem
+ NomadProblem nomad_pb = createNomadProblem(marine_design_bb,
+ NULL,
+ nb_inputs,
+ nb_outputs);
+
+ // Fix parameters without the NOMAD terminology
+
+ // Main parameters
+ addNomadArrayOfDoubleParam(nomad_pb, "LOWER_BOUND", lb);
+ addNomadArrayOfDoubleParam(nomad_pb, "UPPER_BOUND", ub);
+ addNomadStringParam(nomad_pb, "BB_OUTPUT_TYPE", type_bb_outputs);
+
+ addNomadValParam(nomad_pb, "MAX_BB_EVAL", max_bb_eval);
+
+ // Display options
+ addNomadValParam(nomad_pb, "DISPLAY_DEGREE", 2);
+ addNomadBoolParam(nomad_pb, "DISPLAY_ALL_EVAL", false);
+ addNomadBoolParam(nomad_pb, "DISPLAY_UNSUCCESSFUL", false);
+
+ // As we are in a multiobjective context, we need to explicitly
+ // set the choice of the algorithm used
+ addNomadBoolParam(nomad_pb, "DMULTIMADS_OPTIMIZATION", true);
+
+ // For the multiobjective case, we cannot use ORTHO N+1 QUAD
+ addNomadParam(nomad_pb, "DIRECTION_TYPE ORTHO N+1 NEG");
+
+ // Here, deactivate QUAD_MODEL_SEARCH
+ addNomadBoolParam(nomad_pb, "QUAD_MODEL_SEARCH", false);
+
+ // Change options for NM strategy
+ addNomadStringParam(nomad_pb, "DMULTIMADS_NM_STRATEGY", "MULTI");
+
+ // A line initialization is practically more efficient than giving a single point for
+ // multiobjective optimization.
+ // The interesting reader can report to the following reference for more information.
+ // Direct Multisearch for multiobjective optimization
+ // by A.L. Custodio, J.F.A. Madeira, A.I.F. Vaz and L.N. Vicente, 2011.
+ double x0s[6 * 6]; // starting points
+ for (size_t j = 0; j < nb_inputs; ++j)
+ {
+ for (size_t i = 0; i < nb_inputs; ++i)
+ {
+ x0s[j * nb_inputs + i] = lb[i] + (double) j * (ub[i] - lb[i]) / (nb_inputs - 1);
+ }
+ }
+
+ // Run problem
+ NomadResult nomad_result = createNomadResult();
+ int run_flag = solveNomadProblem(nomad_result, nomad_pb,
+ nb_inputs, x0s, NULL);
+ printf("Run status: %d\n", run_flag);
+ const int nb_solutions = nbSolutionsNomadResult(nomad_result);
+ const bool exists_feas = feasibleSolutionsFoundNomadResult(nomad_result);
+ printf("The solver has found %d solutions ", nb_solutions);
+ if (exists_feas)
+ {
+ printf("and they are feasible\n");
+ }
+ else
+ {
+ printf("and they are infeasible\n");
+ }
+
+ double* x_solutions = malloc(nb_inputs * nb_solutions * sizeof(double));
+ double* output_solutions = malloc(nb_outputs * nb_solutions * sizeof(double));
+ loadInputSolutionsNomadResult(x_solutions, nb_solutions, nomad_result);
+ loadOutputSolutionsNomadResult(output_solutions, nb_solutions, nomad_result);
+ printf("Solutions:\n");
+ for (int index = 0; index < nb_solutions; ++index)
+ {
+ printf("sol %d: x = [", index+1);
+ for (int i = 0; i < nb_inputs; ++i)
+ {
+ printf(" %f", x_solutions[index * nb_inputs + i]);
+ }
+ printf("]; f = [%f %f %f]\n",
+ output_solutions[index * nb_outputs],
+ output_solutions[index * nb_outputs + 1],
+ output_solutions[index * nb_outputs + 2]);
+ }
+
+ free(x_solutions);
+ free(output_solutions);
+ freeNomadProblem(nomad_pb);
+ freeNomadResult(nomad_result);
+ return 0;
+}
+
+int main()
+{
+ solve_marine_design_pb();
+ return EXIT_SUCCESS;
+}
diff --git a/examples/advanced/library/exampleSuggestAndObserve/loopSuggestAndObserve.cpp b/examples/advanced/library/exampleSuggestAndObserve/loopSuggestAndObserve.cpp
index bf9dbd01..8d10af91 100644
--- a/examples/advanced/library/exampleSuggestAndObserve/loopSuggestAndObserve.cpp
+++ b/examples/advanced/library/exampleSuggestAndObserve/loopSuggestAndObserve.cpp
@@ -88,7 +88,11 @@ bool eval_xs(const NOMAD::ArrayOfPoint &xs, std::vector& f
return eval_ok;
}
-void initParams(std::shared_ptr& params, const std::string & cacheFileName, const std::string & initialFrameSizeAsString, const std::string & hmax0AsString, bool useCacheAndMegaSearchPoll )
+void initParams(const std::shared_ptr& params,
+ const std::string& cacheFileName,
+ const std::string& initialFrameSizeAsString,
+ const std::string& hmax0AsString,
+ bool useCacheAndMegaSearchPoll)
{
// Problem parameters
params->setAttributeValue("DIMENSION", 2); // number of variables
@@ -96,7 +100,7 @@ void initParams(std::shared_ptr& params, const std::string
params->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(2, 10.0));
NOMAD::BBOutputTypeList bbot; // Definition of output types
- bbot.push_back(NOMAD::BBOutputType::Type::OBJ);
+ bbot.emplace_back(NOMAD::BBOutputType::Type::OBJ);
params->setAttributeValue("BB_OUTPUT_TYPE", bbot);
if (! useCacheAndMegaSearchPoll)
@@ -128,12 +132,10 @@ void initParams(std::shared_ptr& params, const std::string
}
-
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main(int argc, char ** argv)
+int main()
{
try
{
@@ -168,7 +170,7 @@ int main(int argc, char ** argv)
// MainStep runs suggest
auto xs = SuggestMainStep->suggest();
- if (0 == xs.size())
+ if (xs.empty())
{
std::cout << "No more points to suggest at iteration " << iterationCount << "." << std::endl;
// Could not suggest any more points. Break.
@@ -184,7 +186,6 @@ int main(int argc, char ** argv)
//THIS IS IMPORTANT (see comments in function)
NOMAD::MainStep::resetCache();
-
// Parameters creation (important to create a fresh one because Suggest modifies its params (X0 from cache))
auto paramsForObservePtr = std::make_shared();
@@ -214,7 +215,7 @@ int main(int argc, char ** argv)
paramsForObservePtr.reset();
std::cout << "Updated parameters: " << std::endl;
- for (auto p : updatedParams)
+ for (const auto& p : updatedParams)
{
std::cout << p << std::endl;
NOMAD::ParameterEntry pe(p);
diff --git a/examples/advanced/library/exampleSuggestAndObserve/suggestAndObserve.cpp b/examples/advanced/library/exampleSuggestAndObserve/suggestAndObserve.cpp
index 3a7bca1e..9da5d9f2 100644
--- a/examples/advanced/library/exampleSuggestAndObserve/suggestAndObserve.cpp
+++ b/examples/advanced/library/exampleSuggestAndObserve/suggestAndObserve.cpp
@@ -96,7 +96,7 @@ void initParams(std::shared_ptr& params, const std::string
params->setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(2, 10.0));
NOMAD::BBOutputTypeList bbot; // Definition of output types
- bbot.push_back(NOMAD::BBOutputType::Type::OBJ);
+ bbot.emplace_back(NOMAD::BBOutputType::Type::OBJ);
params->setAttributeValue("BB_OUTPUT_TYPE", bbot);
@@ -114,12 +114,10 @@ void initParams(std::shared_ptr& params, const std::string
}
-
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main(int argc, char ** argv)
+int main()
{
try
{
@@ -154,7 +152,7 @@ int main(int argc, char ** argv)
std::cout << paramName << " ( " << paramsForObserve->getAttributeValue(paramName) << " )" << std::endl;
auto updateParams = ObserveMainStep->observe(xs,fxs,"cache1.txt");
std::cout << "Updated parameters: " << std::endl;
- for (auto p : updateParams)
+ for (const auto& p : updateParams)
{
std::cout << p << std::endl;
}
diff --git a/examples/basic/batch/MatlabBB/paramNomad.txt b/examples/basic/batch/MatlabBB/paramNomad.txt
index 12f01bc0..83c1e39d 100644
--- a/examples/basic/batch/MatlabBB/paramNomad.txt
+++ b/examples/basic/batch/MatlabBB/paramNomad.txt
@@ -1,21 +1,21 @@
dimension 5
-# WARNING: The command to run matlab in batch mode may vary with Matlab version and OS.
-# The given bat (bb.bat) command has been tested with Matlab 2021b on Windows.
-# - To make sure the command works properly with your Matlab version, start a Windows shell command terminal.
-# - Go into the directory of this example
-# - Test the following command: bb.bat X0.txt
-# - Matlab should start in background and run the 'fun.m' function.
-# - The command should display '4 -10 -30', that is the objective and constraints values for X0.
-# - When the blackbox Matlab command is working you can run Nomad on it.
-#
-# The given shell script command (bb.sh) has been tested with Matlab 2022a on OSX and Linux
-# - To test the command, go into the directory of this example
-# - Run the command: ./bb.sh X0.txt
-# - The command should display '4 -10 -30', that is the objective and constraints values for X0.
+% WARNING: The command to run matlab in batch mode may vary with Matlab version and OS.
+% The given bat (bb.bat) command has been tested with Matlab 2021b on Windows.
+% - To make sure the command works properly with your Matlab version, start a Windows shell command terminal.
+% - Go into the directory of this example
+% - Test the following command: bb.bat X0.txt
+% - Matlab should start in background and run the 'fun.m' function.
+% - The command should display '4 -10 -30', that is the objective and constraints values for X0.
+% - When the blackbox Matlab command is working you can run Nomad on it.
+%
+% The given shell script command (bb.sh) has been tested with Matlab 2022a on OSX and Linux
+% - To test the command, go into the directory of this example
+% - Run the command: ./bb.sh X0.txt
+%. - The command should display '4 -10 -30', that is the objective and constraints values for X0.
-bb_exe bb.sh # for linux/osx
-# bb_exe bb.bat # for windows is a cmd prompt windows
+# bb_exe bb.sh # for linux/osx
+bb_exe bb.bat # for windows is a cmd prompt windows
@@ -27,6 +27,6 @@ display_degree 2
display_stats BBE ( SOL ) BBO
display_all_eval yes
-max_bb_eval 50
+max_bb_eval 5
bb_output_type OBJ PB PB
diff --git a/examples/basic/batch/PythonBB/param.txt b/examples/basic/batch/PythonBB/param.txt
index 33dc7c4b..88f834b0 100755
--- a/examples/basic/batch/PythonBB/param.txt
+++ b/examples/basic/batch/PythonBB/param.txt
@@ -1,6 +1,6 @@
DIMENSION 5
-BB_EXE '$python bb.py ' # '$python3 bb.py '
+BB_EXE '$python3 bb.py '
BB_OUTPUT_TYPE OBJ PB EB
X0 ( 0 0 0 0 0 )
diff --git a/examples/basic/batch/example1/CMakeLists.txt b/examples/basic/batch/example1/CMakeLists.txt
index 14cbcbfc..1445f8c9 100644
--- a/examples/basic/batch/example1/CMakeLists.txt
+++ b/examples/basic/batch/example1/CMakeLists.txt
@@ -6,6 +6,7 @@ set_target_properties(bb1.exe PROPERTIES SUFFIX "")
install(TARGETS bb1.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
# Add a test for this example
message(STATUS " Add example batch #1")
diff --git a/examples/basic/batch/example1/param.txt b/examples/basic/batch/example1/param.txt
index bb23c412..5a91ec33 100644
--- a/examples/basic/batch/example1/param.txt
+++ b/examples/basic/batch/example1/param.txt
@@ -30,11 +30,6 @@ MAX_BB_EVAL 1000
# including cache hits
MAX_EVAL 200
-# Parameters for display
-DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL 1
-DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
-
# Formatted stats into a file
#STATS_FILE stats.txt BBE SOL OBJ
@@ -44,4 +39,3 @@ DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
# Solution file (just best inputs found)
#SOLUTION_FILE sol.txt
-
diff --git a/examples/basic/batch/example1/param_LH.txt b/examples/basic/batch/example1/param_LH.txt
new file mode 100644
index 00000000..87da9e4f
--- /dev/null
+++ b/examples/basic/batch/example1/param_LH.txt
@@ -0,0 +1,45 @@
+
+# PROBLEM PARAMETERS
+####################
+
+# Number of variables
+DIMENSION 10
+
+# Black box
+BB_EXE bb1.exe
+BB_OUTPUT_TYPE OBJ PB PB PB
+
+# Starting point
+# X0 ( 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 )
+
+# Bounds for variables
+LOWER_BOUND * -10
+UPPER_BOUND * 20
+
+# All variables must be multiple of 0.0001
+GRANULARITY * 0.0001
+
+
+# ALGORITHM PARAMETERS
+######################
+
+# The algorithm terminates after that number black-box evaluations
+MAX_BB_EVAL 1000
+
+# The algorithm terminates after that total number of evaluations,
+# including cache hits
+MAX_EVAL 1100
+
+# Latin Hypercube Search parameters
+LH_SEARCH 100 10
+
+
+# DISPLAY PARAMETERS
+####################
+DISPLAY_DEGREE 2
+DISPLAY_INFEASIBLE true
+DISPLAY_STATS BBE EVAL ( SOL ) OBJ CONS_H H_MAX
+#STATS_FILE stats.txt BBE SOL OBJ
+
+
+
diff --git a/examples/basic/batch/example1/param_LH_ONLY.txt b/examples/basic/batch/example1/param_LH_ONLY.txt
new file mode 100644
index 00000000..4979577a
--- /dev/null
+++ b/examples/basic/batch/example1/param_LH_ONLY.txt
@@ -0,0 +1,27 @@
+
+# PROBLEM PARAMETERS
+####################
+
+# Number of variables
+DIMENSION 10
+
+# Black box
+BB_EXE bb1.exe
+BB_OUTPUT_TYPE OBJ PB PB EB
+
+# Starting point
+X0 ( 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 )
+
+LOWER_BOUND * 0.0
+UPPER_BOUND * 10.0
+
+
+# ALGORITHM PARAMETERS
+######################
+
+LH_EVAL 10 # Enabling LH eval disables default Mads optimization
+
+# Parameters for display
+DISPLAY_DEGREE 3
+DISPLAY_STATS BBE ( SOL ) OBJ
+
diff --git a/examples/basic/batch/example2/param_NM.txt b/examples/basic/batch/example1/param_NM.txt
similarity index 57%
rename from examples/basic/batch/example2/param_NM.txt
rename to examples/basic/batch/example1/param_NM.txt
index b215562a..70b59812 100644
--- a/examples/basic/batch/example2/param_NM.txt
+++ b/examples/basic/batch/example1/param_NM.txt
@@ -3,18 +3,15 @@
####################
# Number of variables
-DIMENSION 5
+DIMENSION 10
# Black box
-BB_EXE bb2.exe
-BB_OUTPUT_TYPE OBJ PB PB
+BB_EXE bb1.exe
+BB_OUTPUT_TYPE OBJ PB PB PB
# Starting point
-X0 ( 0 0 0 0 0 )
+X0 ( 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 )
-LOWER_BOUND * -6 # 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
# ALGORITHM PARAMETERS
######################
@@ -23,11 +20,12 @@ UPPER_BOUND ( 5 6 7 - - ) # x_1 <= 5, x_2 <= 6, x_3 <= 7
NM_OPTIMIZATION true
# The algorithm terminates after that number black-box evaluations
-MAX_BB_EVAL 400
+MAX_BB_EVAL 1000
+
# DISPLAY PARAMETERS
####################
# Show more info - display degree = 3
-DISPLAY_DEGREE 3
-DISPLAY_MAX_STEP_LEVEL 10
+DISPLAY_STATS BBE ( SOL ) OBJ CONS_H
#STATS_FILE stats.txt BBE SOL OBJ
+
diff --git a/examples/basic/batch/example1/x0.txt b/examples/basic/batch/example1/x0.txt
new file mode 100644
index 00000000..06af1ce9
--- /dev/null
+++ b/examples/basic/batch/example1/x0.txt
@@ -0,0 +1 @@
+5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0
diff --git a/examples/basic/batch/example2/param.txt b/examples/basic/batch/example2/param.txt
index 457c150b..7278d648 100644
--- a/examples/basic/batch/example2/param.txt
+++ b/examples/basic/batch/example2/param.txt
@@ -24,21 +24,18 @@ MAX_BB_EVAL 1000
MEGA_SEARCH_POLL true # Generate search and poll steps trial points before starting evaluation
-NB_THREADS_OPENMP 4 # Number of threads to perform blackbox evaluation
- # This requires to have Nomad built with OpenMP (see $NOMAD_HOME/README.txt)
- # With this parameter, the default thread number (1) is replaced.
+NB_THREADS_PARALLEL_EVAL 4 # Number of threads to perform blackbox evaluation
+ # This requires to have Nomad built with OpenMP (see $NOMAD_HOME/README.txt)
+ # With this parameter, the default thread number (1) is replaced.
# The algorithm terminates after that total number of evaluations,
# including cache hits
MAX_EVAL 200
-QUAD_MODEL_SEARCH no
-DIRECTION_TYPE ORTHO 2N
-
# DISPLAY PARAMETERS
####################
DISPLAY_DEGREE 2
DISPLAY_ALL_EVAL 1
-DISPLAY_STATS BBE ( SOL ) OBJ
+DISPLAY_STATS BBE THREAD_NUM ( SOL ) OBJ
#STATS_FILE stats.txt BBE SOL OBJ
diff --git a/examples/basic/batch/multi_obj/param.txt b/examples/basic/batch/multi_obj/param.txt
index 5d374817..749f6d03 100644
--- a/examples/basic/batch/multi_obj/param.txt
+++ b/examples/basic/batch/multi_obj/param.txt
@@ -23,12 +23,12 @@ DMULTIMADS_OPTIMIZATION yes
# For multiobjctive, sort should not use the default quad model info
EVAL_QUEUE_SORT DIR_LAST_SUCCESS
-# Let's deactivate all default search methods
+# Let's deactivate all default search methods except NM (prototype)
# and do ORTHO 2n for more intense poll (default is n+1)
DIRECTION_TYPE ORTHO 2n
QUAD_MODEL_SEARCH no
-NM_SEARCH no
SPECULATIVE_SEARCH no
+DMULTIMADS_NM_STRATEGY MULTI
DISPLAY_DEGREE 2
DISPLAY_ALL_EVAL yes
diff --git a/examples/basic/batch/multi_obj/x.txt b/examples/basic/batch/multi_obj/x.txt
new file mode 100644
index 00000000..0b3eef12
--- /dev/null
+++ b/examples/basic/batch/multi_obj/x.txt
@@ -0,0 +1 @@
+2.0 2.0
diff --git a/examples/basic/batch/multi_obj2/CMakeLists.txt b/examples/basic/batch/multi_obj2/CMakeLists.txt
index 2814ea58..5c15976c 100644
--- a/examples/basic/batch/multi_obj2/CMakeLists.txt
+++ b/examples/basic/batch/multi_obj2/CMakeLists.txt
@@ -7,10 +7,4 @@ set_target_properties(bbMO2.exe PROPERTIES SUFFIX "")
install(TARGETS bbMO2.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-message(STATUS " Add example batch multi_obj 2")
-
-# Test run in working directory AFTER install of bb.exe executable
-add_test(NAME ExampleMultiObj2BasicBatch
- COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
+# No test for this example
\ No newline at end of file
diff --git a/examples/basic/batch/multi_obj2/param.txt b/examples/basic/batch/multi_obj2/param.txt
index 3af84d82..9424656a 100644
--- a/examples/basic/batch/multi_obj2/param.txt
+++ b/examples/basic/batch/multi_obj2/param.txt
@@ -25,7 +25,6 @@ NM_SEARCH no
SPECULATIVE_SEARCH no
DISPLAY_DEGREE 2
-DISPLAY_ALL_EVAL yes
DISPLAY_STATS BBE ( SOL ) BBO # Display the number of evaluation (BBE),
# the current solution ( SOL ) and the objectives
diff --git a/examples/basic/batch/multi_obj2/param_testQMS.txt b/examples/basic/batch/multi_obj2/param_testQMS.txt
new file mode 100644
index 00000000..07ca4ec7
--- /dev/null
+++ b/examples/basic/batch/multi_obj2/param_testQMS.txt
@@ -0,0 +1,41 @@
+DIMENSION 3 # number of variables
+
+
+BB_EXE bbMO2.exe
+BB_OUTPUT_TYPE OBJ OBJ
+
+X0 ( 0 0 0 ) # starting point
+
+LOWER_BOUND * -5
+UPPER_BOUND * 5
+
+MAX_BB_EVAL 1000
+
+# DMultiMads is enabled (default Mads is disabled)
+DMULTIMADS_OPTIMIZATION yes
+
+# Quad model search using DMS strategy
+QUAD_MODEL_SEARCH yes
+DMULTIMADS_QUAD_MODEL_STRATEGY DMS
+
+# For multiobjctive, sort should not use the default quad model info
+EVAL_QUEUE_SORT DIR_LAST_SUCCESS
+
+# Let's deactivate all default search methods
+# and do ORTHO n+1 Neg (Neg is for disabling quad model (n+1)th direction)
+DIRECTION_TYPE ORTHO n+1 neg
+NM_SEARCH no
+SPECULATIVE_SEARCH no
+
+DISPLAY_DEGREE 2
+DISPLAY_UNSUCCESSFUL yes
+DISPLAY_STATS BBE ( SOL ) BBO # Display the number of evaluation (BBE),
+ # the current solution ( SOL ) and the objectives
+
+
+SOLUTION_FILE sol.txt # Write the approximated Pareto points
+SOLUTION_FILE_FINAL yes # in a file at the end of the run
+
+
+
+
diff --git a/examples/basic/batch/multi_obj2/x.txt b/examples/basic/batch/multi_obj2/x.txt
new file mode 100644
index 00000000..0b3eef12
--- /dev/null
+++ b/examples/basic/batch/multi_obj2/x.txt
@@ -0,0 +1 @@
+2.0 2.0
diff --git a/examples/basic/batch/single_obj/CMakeLists.txt b/examples/basic/batch/single_obj/CMakeLists.txt
deleted file mode 100644
index af96eefc..00000000
--- a/examples/basic/batch/single_obj/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-set(CMAKE_EXECUTABLE_SUFFIX .exe)
-add_executable(bb.exe bb.cpp )
-set_target_properties(bb.exe PROPERTIES SUFFIX "")
-
-
-# installing executables and libraries
-install(TARGETS bb.exe
- RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-
-# Add a test for this example
-message(STATUS " Add example batch single_obj")
-
-# Test run in working directory AFTER install of bb.exe executable
-add_test(NAME ExampleSingleObjBasicBatch
- COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
diff --git a/examples/basic/batch/single_obj/param.txt b/examples/basic/batch/single_obj/param.txt
deleted file mode 100644
index f3a60f61..00000000
--- a/examples/basic/batch/single_obj/param.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-DIMENSION 5 # number of variables
-
-
-BB_EXE bb.exe # 'bb.exe' is a program that
-BB_OUTPUT_TYPE OBJ PB EB # takes in argument the name of
- # a text file containing 5
- # values, and that displays 3
- # values that correspond to the
- # objective function value (OBJ),
- # and two constraints values g1
- # and g2 with g1 <= 0 and
- # g2 <= 0; 'PB' and 'EB'
- # correspond to constraints that
- # are treated by the Progressive
- # and Extreme Barrier approaches
- # (all constraint-handling
- # options are described in the
- # detailed parameters list)
-
-X0 ( 0 0 0 0 0 ) # starting point
-
-LOWER_BOUND * -6 # 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 # indicates a directory where
- # temporary files are put
- # (increases performance by ~100%
- # if you're working on a network
- # account and if TMP_DIR is on a
- # local disk)
-
-DISPLAY_DEGREE 2
-DISPLAY_STATS BBE ( SOL ) OBJ CONS_H # Display the number of evaluation (BBE),
- # the current solution ( SOL ) and the objective
-DISPLAY_INFEASIBLE yes # Allow to display infeasible solution during PhaseOne
diff --git a/examples/basic/batch/single_obj/x.txt b/examples/basic/batch/single_obj/x.txt
deleted file mode 100644
index 88b14b24..00000000
--- a/examples/basic/batch/single_obj/x.txt
+++ /dev/null
@@ -1 +0,0 @@
-0 0 0 0 0
diff --git a/examples/basic/batch/single_obj_MPIparallel/bb.cpp b/examples/basic/batch/single_obj_MPIparallel/bb.cpp
index 4d03dc99..216e31a5 100644
--- a/examples/basic/batch/single_obj_MPIparallel/bb.cpp
+++ b/examples/basic/batch/single_obj_MPIparallel/bb.cpp
@@ -180,7 +180,7 @@ void evalServerStart(const char* input_file_name)
// Get the input vectors
std::string str;
- std::vector> X;
+ std::vector > X;
while (std::getline(in, str))
{
@@ -206,7 +206,7 @@ void evalServerStart(const char* input_file_name)
char signal;
MPI_Status status;
int evaluator;
- std::vector> all_outputs(X.size(),std::vector(m,0));
+ std::vector > all_outputs(X.size(),std::vector(m,0));
size_t eval_counter_sent = 0, eval_counter_received = 0, nb_points = X.size() ;
int index;
while (eval_counter_received != nb_points)
diff --git a/examples/basic/batch/single_obj_MPIparallel/param.txt b/examples/basic/batch/single_obj_MPIparallel/param.txt
index 8c20a406..44ed1023 100644
--- a/examples/basic/batch/single_obj_MPIparallel/param.txt
+++ b/examples/basic/batch/single_obj_MPIparallel/param.txt
@@ -1,16 +1,17 @@
DIMENSION 5 # number of variables
BB_EXE '$mpirun $-np $4 bb4.exe' # WARNING Adjust the path to mpirun
- # or mpiexec according to your setup.
+ # or mpiexec according to your setup.
-BB_MAX_BLOCK_SIZE 20 # At most, 20 points are put in a block for evaluation
+BB_MAX_BLOCK_SIZE 20
MEGA_SEARCH_POLL yes # Generate search and poll trial points before evaluation
- # Max points put in box. Without this option, single point
+ # Max points put in block. Without this option, single point
# can be passed in a block for evaluation creating a bottleneck.
DIRECTION_TYPE ORTHO 2N # Single pass for generating poll trial points
# Better to have more points in blocks
+
BB_OUTPUT_TYPE OBJ PB PB
X0 ( 0 0 0 0 0 ) # starting point
diff --git a/examples/basic/batch/single_obj_parallel/CMakeLists.txt b/examples/basic/batch/single_obj_parallel/CMakeLists.txt
index 742e2226..13f6becf 100644
--- a/examples/basic/batch/single_obj_parallel/CMakeLists.txt
+++ b/examples/basic/batch/single_obj_parallel/CMakeLists.txt
@@ -1,11 +1,11 @@
set(CMAKE_EXECUTABLE_SUFFIX .exe)
-add_executable(bb3.exe bb.cpp )
-set_target_properties(bb3.exe PROPERTIES SUFFIX "")
+add_executable(bb_s.exe bb.cpp )
+set_target_properties(bb_s.exe PROPERTIES SUFFIX "")
-target_link_libraries(bb3.exe PUBLIC OpenMP::OpenMP_CXX)
+target_link_libraries(bb_s.exe PUBLIC OpenMP::OpenMP_CXX)
# installing executables and libraries
-install(TARGETS bb3.exe
+install(TARGETS bb_s.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
# Add a test for this example
diff --git a/examples/basic/batch/single_obj_parallel/param.txt b/examples/basic/batch/single_obj_parallel/param.txt
index 5368fcdf..0d710d40 100644
--- a/examples/basic/batch/single_obj_parallel/param.txt
+++ b/examples/basic/batch/single_obj_parallel/param.txt
@@ -1,7 +1,12 @@
DIMENSION 5 # number of variables
-BB_EXE bb3.exe
+BB_EXE bb_s.exe
+# Blocks of points are provided to the BB.
+# BB evaluate points in parallel.
+# Nomad queue for parallel evaluations is not
+# used in this example. Look into example 2 for
+# using this feature.
BB_MAX_BLOCK_SIZE 4
BB_OUTPUT_TYPE OBJ PB EB
diff --git a/examples/basic/batch/surrogate_sort/CMakeLists.txt b/examples/basic/batch/surrogate_sort/CMakeLists.txt
index 1cacbec9..6e91fee3 100644
--- a/examples/basic/batch/surrogate_sort/CMakeLists.txt
+++ b/examples/basic/batch/surrogate_sort/CMakeLists.txt
@@ -7,10 +7,4 @@ set_target_properties(ss_sgte.exe PROPERTIES SUFFIX "")
install(TARGETS ss_bb.exe ss_sgte.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add a test for this example
-message(STATUS " Add example batch surrogate sort")
-
-# Test run in working directory AFTER install of bb executable
-add_test(NAME ExampleSurrogateSortBasicBatch
- COMMAND ${CMAKE_INSTALL_PREFIX}/bin/nomad param.txt
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
+# No test for this example
diff --git a/examples/basic/batch/surrogate_sort/param.txt b/examples/basic/batch/surrogate_sort/param.txt
index 5a33a8db..1c17a49c 100644
--- a/examples/basic/batch/surrogate_sort/param.txt
+++ b/examples/basic/batch/surrogate_sort/param.txt
@@ -28,9 +28,6 @@ MAX_BB_EVAL 100
# Use surrogate executable to sort points before evaluating them with the blackbox
EVAL_QUEUE_SORT SURROGATE
-# Using only one thread for clarity and reproducibility
-NB_THREADS_OPENMP 1
-
# Display parameters
####################
DISPLAY_DEGREE 2
diff --git a/examples/basic/batch/surrogate_sort/param_surrogateOptim.txt b/examples/basic/batch/surrogate_sort/param_surrogateOptim.txt
index 1bf29a09..f07fb5c5 100644
--- a/examples/basic/batch/surrogate_sort/param_surrogateOptim.txt
+++ b/examples/basic/batch/surrogate_sort/param_surrogateOptim.txt
@@ -23,10 +23,9 @@ UPPER_BOUND * 20.0
# The algorithm terminates after that number surrogate evaluations
MAX_SURROGATE_EVAL_OPTIMIZATION 100
-# Use surrogate evaluation for optimization
+# Use surrogate evaluation for optimization
EVAL_SURROGATE_OPTIMIZATION yes
-
# Display parameters
####################
DISPLAY_ALL_EVAL true
diff --git a/examples/basic/library/CustomSurrogateOrdering/CMakeLists.txt b/examples/basic/library/CustomSurrogateOrdering/CMakeLists.txt
index 24c9d7d9..177f7546 100644
--- a/examples/basic/library/CustomSurrogateOrdering/CMakeLists.txt
+++ b/examples/basic/library/CustomSurrogateOrdering/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS customSurrogateOrdering.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for custom ordering of points before evaluation")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedcustomSurrogateOrdering
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customSurrogateOrdering.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedcustomSurrogateOrdering
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./customSurrogateOrdering.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/basic/library/CustomSurrogateOrdering/customSurrogateOrdering.cpp b/examples/basic/library/CustomSurrogateOrdering/customSurrogateOrdering.cpp
index f17e2eac..19b785ce 100644
--- a/examples/basic/library/CustomSurrogateOrdering/customSurrogateOrdering.cpp
+++ b/examples/basic/library/CustomSurrogateOrdering/customSurrogateOrdering.cpp
@@ -64,11 +64,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -105,11 +105,11 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
class My_Surrogate_Evaluator : public NOMAD::Evaluator
{
public:
- My_Surrogate_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Surrogate_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::SURROGATE)
{}
- ~My_Surrogate_Evaluator() {}
+ ~My_Surrogate_Evaluator() override = default;
std::vector eval_block(NOMAD::Block &block,
const NOMAD::Double &hMax,
@@ -127,22 +127,20 @@ std::vector My_Surrogate_Evaluator::eval_block(NOMAD::Block &block,
NOMAD::Point P0(n, 0);
// Start evaluation
- for (auto it = block.begin(); it != block.end(); it++)
+ for (auto & it : block)
{
// Use distance to P0 for objective
- NOMAD::Double d = NOMAD::Point::dist(P0, *(*it)->getX());
+ NOMAD::Double d = NOMAD::Point::dist(P0, *it->getX());
std::string bbo = d.tostring();
bbo += " 0.0 0.0"; // Both constraints are feasible
- (*it)->setBBO(bbo);
+ it->setBBO(bbo);
}
return success;
}
-
-
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
// Parameters creation
allParams->setAttributeValue("DIMENSION", n);
@@ -150,7 +148,7 @@ void initAllParams(std::shared_ptr allParams)
// Starting point
allParams->setAttributeValue("X0", NOMAD::Point(n, 0.0) );
- // Bounds
+ // Set bounds
allParams->setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, -6.0 )); // all var. >= -6
NOMAD::ArrayOfDouble ub(n);
ub[0] = 5.0; // x_1 <= 5
@@ -160,9 +158,9 @@ void initAllParams(std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::PB);
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
// Use surrogate for sorting
@@ -175,25 +173,21 @@ void initAllParams(std::shared_ptr allParams)
allParams->setAttributeValue("NM_SEARCH", false);
allParams->setAttributeValue("DIRECTION_TYPE", NOMAD::DirectionType::ORTHO_NP1_NEG);
-
+ // Set display parameters
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
allParams->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("bbe ( sol ) obj"));
allParams->setAttributeValue("DISPLAY_ALL_EVAL", true);
// Parameters validation requested to have access to their value.
allParams->checkAndComply();
-
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -208,7 +202,7 @@ int main ( int argc , char ** argv )
// Custom SURROGATE evaluator creation
auto evSurrogate = std::make_unique(params->getEvalParams());
TheMainStep.addEvaluator(std::move(evSurrogate));
- // Warning: Need to set ordering with surrogate to use the surrogate. See EVAL_QUEUE_SORT parameter set above.
+ // Warning: Need to set ordering with surrogate to use the surrogate. See EVAL_QUEUE_SORT parameter set above
// The run
TheMainStep.start();
diff --git a/examples/basic/library/StopOnFTarget/CMakeLists.txt b/examples/basic/library/StopOnFTarget/CMakeLists.txt
index 4b74e770..4063438f 100644
--- a/examples/basic/library/StopOnFTarget/CMakeLists.txt
+++ b/examples/basic/library/StopOnFTarget/CMakeLists.txt
@@ -17,19 +17,4 @@ install(TARGETS stopOnFTarget.exe
RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-# Add test for this example
-#if(BUILD_TESTS MATCHES ON)
-# message(STATUS " Add example test for handling stop if F hit target")
-# # Can run this test after install
-# if (WIN32)
-# add_test(NAME ExampleAdvancedstopOnFTarget
-# COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopOnFTarget.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# else()
-# add_test(NAME ExampleAdvancedstopOnFTarget
-# COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./stopOnFTarget.exe
-# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-# )
-# endif()
-#endif()
+# No test for this example
\ No newline at end of file
diff --git a/examples/basic/library/StopOnFTarget/stopOnFTarget.cpp b/examples/basic/library/StopOnFTarget/stopOnFTarget.cpp
index 5bd299cd..ea2c29da 100644
--- a/examples/basic/library/StopOnFTarget/stopOnFTarget.cpp
+++ b/examples/basic/library/StopOnFTarget/stopOnFTarget.cpp
@@ -62,11 +62,11 @@ class My_Evaluator : public NOMAD::Evaluator
private:
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override;
};
@@ -98,9 +98,8 @@ bool My_Evaluator::eval_x(NOMAD::EvalPoint &x,
return true; // the evaluation succeeded
}
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
-
const size_t n = 5;
// Parameters creation
@@ -119,10 +118,10 @@ void initAllParams(std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::OBJ);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB);
- bbOutputTypes.push_back(NOMAD::BBOutputType::Type::EB);
- allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::OBJ);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB);
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::Type::EB);
+ allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes);
// Algo for search
allParams->setAttributeValue("NM_SEARCH", false);
@@ -133,7 +132,7 @@ void initAllParams(std::shared_ptr allParams)
// Parameters validation requested to have access to their value.
allParams->checkAndComply();
-
+
}
@@ -142,7 +141,7 @@ void initAllParams(std::shared_ptr allParams)
/* the algorithm should stop. */
/*----------------------------------------*/
void userIterationCallback(const NOMAD::Step& step,
- bool &stop)
+ bool &stop)
{
// Several NOMAD::Algorithm are used by NOMAD.
// We are interested only on the main Mads (Mega) Iteration.
@@ -155,11 +154,10 @@ void userIterationCallback(const NOMAD::Step& step,
{
// Fetch the best feasible point in the cache
std::vector bestFeas;
- NOMAD::CacheBase::getInstance()->findBestFeas(bestFeas, NOMAD::Point() /* no fixed variables */,
- NOMAD::EvalType::BB, NOMAD::ComputeType::STANDARD);
+ NOMAD::CacheBase::getInstance()->findBestFeas(bestFeas);
for (const auto & evalP: bestFeas)
{
- if ( evalP.getF() <= FTarget)
+ if ( evalP.getF(NOMAD::defaultFHComputeType) <= FTarget)
{
// Stop motivated by user conditions
stop = true;
@@ -174,14 +172,11 @@ void userIterationCallback(const NOMAD::Step& step,
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main ( int argc , char ** argv )
+int main()
{
-
-
NOMAD::MainStep TheMainStep;
// Set parameters
@@ -196,11 +191,10 @@ int main ( int argc , char ** argv )
// Set main step callback
TheMainStep.addCallback(NOMAD::CallbackType::MEGA_ITERATION_END, userIterationCallback);
-
// The run
TheMainStep.start();
TheMainStep.run();
TheMainStep.end();
return 1;
-}
+}
diff --git a/examples/basic/library/example1/example1_lib.cpp b/examples/basic/library/example1/example1_lib.cpp
index 8d7f0e2a..4ff58422 100644
--- a/examples/basic/library/example1/example1_lib.cpp
+++ b/examples/basic/library/example1/example1_lib.cpp
@@ -59,11 +59,11 @@
class My_Evaluator : public NOMAD::Evaluator
{
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB) // Evaluator for true blackbox evaluations only
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override
{
@@ -95,7 +95,7 @@ class My_Evaluator : public NOMAD::Evaluator
}
g1 = -prod2 + 0.75;
- g2 = sum2 -7.5 * n;
+ g2 = sum2 -7.5 * (double)n;
f = 10*g1 + 10*g2;
if (0.0 != sum3)
@@ -109,6 +109,7 @@ class My_Evaluator : public NOMAD::Evaluator
}
NOMAD::Double c2000 = -f-2000;
+ // Double::tostring function uses FULL precision
std::string bbo = g1.tostring();
bbo += " " + g2.tostring();
bbo += " " + f.tostring();
@@ -141,7 +142,7 @@ class My_Evaluator : public NOMAD::Evaluator
};
-void initAllParams(std::shared_ptr allParams)
+void initAllParams(const std::shared_ptr& allParams)
{
// Parameters creation
// Number of variables
@@ -157,10 +158,10 @@ void initAllParams(std::shared_ptr allParams)
// Constraints and objective
NOMAD::BBOutputTypeList bbOutputTypes;
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB); // g1
- bbOutputTypes.push_back(NOMAD::BBOutputType::PB); // g2
- bbOutputTypes.push_back(NOMAD::BBOutputType::OBJ); // f
- bbOutputTypes.push_back(NOMAD::BBOutputType::EB); // c2000
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::PB); // g1
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::PB); // g2
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::OBJ); // f
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::EB); // c2000
allParams->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes );
allParams->setAttributeValue("DIRECTION_TYPE", NOMAD::DirectionType::ORTHO_2N);
allParams->setAttributeValue("DISPLAY_DEGREE", 2);
@@ -181,21 +182,22 @@ void initAllParams(std::shared_ptr allParams)
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main (int argc, char **argv)
+int main()
{
-
NOMAD::MainStep TheMainStep;
try
{
+ // Set parameters
auto params = std::make_shared();
initAllParams(params);
TheMainStep.setAllParameters(params);
-
+
+ // Set evaluator
auto ev = std::make_unique(params->getEvalParams());
TheMainStep.addEvaluator(std::move(ev));
-
-
+
+ // Run optimization
TheMainStep.start();
TheMainStep.run();
TheMainStep.end();
diff --git a/examples/basic/library/example2/example2_lib.cpp b/examples/basic/library/example2/example2_lib.cpp
index ce912d9d..e15cbcab 100644
--- a/examples/basic/library/example2/example2_lib.cpp
+++ b/examples/basic/library/example2/example2_lib.cpp
@@ -57,13 +57,12 @@
/* equality constraint. */
/* */
/* Modified problem: */
-/* Geometric constraint x1+...+x4+d=10 */
/* Pb dimension is set to n=4 */
/* Set an inequality constraint: */
/* x1+...+x4<=10 */
/* If constraint is verified */
/* - Pick up d = 10-(x1+...+x4) */
-/* - Compute f=-(x1^2+...+x^4^2+d^2) */
+/* - Compute f=-(x1^2+...+x4^2+d^2) */
/* - Count eval */
/* If constraint is not verified */
/* - f=Inf */
@@ -74,11 +73,11 @@
class My_Evaluator : public NOMAD::Evaluator
{
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double& hMax, bool &countEval) const override
{
@@ -98,7 +97,7 @@ class My_Evaluator : public NOMAD::Evaluator
if (s1 > 10)
{
c1 = s1;
- std::string bbo = f.tostring() + " " + c1.tostring(); // f is not really computed. But the point is infeasible and we handle the constraint with EB, so it does not matter. The point is simply discarded.
+ std::string bbo = f.tostring() + " " + c1.tostring(); // f is not really computed. But the point is infeasible, and we handle the constraint with EB, so it does not matter. The point is simply discarded.
x.setBBO(bbo);
countEval = false; // DO NOT count as a blackbox evaluation when geometric constraint is not verified
@@ -143,14 +142,14 @@ void initParams(NOMAD::AllParameters &p)
// parameters creation
size_t n = 4; // Number of variables of the modified problem
p.setAttributeValue("DIMENSION", n);
- p.setAttributeValue("BB_OUTPUT_TYPE", NOMAD::stringToBBOutputTypeList("OBJ EB")); // EB constraint: If a point is infeasible it is simply discarded. F (costly part) is not computed.
+ p.setAttributeValue("BB_OUTPUT_TYPE", NOMAD::stringToBBOutputTypeList("OBJ EB")); // EB constraint: If a point is infeasible it is simply discarded. F (costly part) is not computed.
p.setAttributeValue("X0", NOMAD::Point(n,5.0)); // starting point (0.0 0.0 0.0 0.0 0.0)
p.setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, 0.0)); // all var. >= 0
p.setAttributeValue("UPPER_BOUND", NOMAD::ArrayOfDouble(n, 5.0)); // all var. >= 0);
// the algorithm terminates after 100 black-box evaluations,
- // or 10000 total evaluations, including cache hits and evalutions for
+ // or 10000 total evaluations, including cache hits and evaluations for
// which countEval was false.
p.setAttributeValue("MAX_BB_EVAL", 200);
p.setAttributeValue("MAX_EVAL", 10000);
@@ -166,7 +165,7 @@ void initParams(NOMAD::AllParameters &p)
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
-int main (int argc, char **argv)
+int main()
{
auto TheMainStep = std::make_unique();
diff --git a/examples/basic/library/example3/CMakeLists.txt b/examples/basic/library/example3/CMakeLists.txt
deleted file mode 100644
index 3d4d7791..00000000
--- a/examples/basic/library/example3/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-add_executable(example3_lib.exe example3_lib.cpp )
-
-target_include_directories(example3_lib.exe PRIVATE
- ${CMAKE_SOURCE_DIR}/src)
-
-set_target_properties(example3_lib.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
-
-
-if(OpenMP_CXX_FOUND)
- target_link_libraries(example3_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
-else()
- target_link_libraries(example3_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval)
-endif()
-
-# installing executables and libraries
-install(TARGETS example3_lib.exe
- RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-
-
-# Add a test for this example
-message(STATUS " Add example library #3")
-
-# Can run this test after install
-if (WIN32)
- add_test(NAME Example3BasicLib
- COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example3_lib.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-else()
- add_test(NAME Example3BasicLib
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example3_lib.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-endif()
diff --git a/examples/basic/library/example3/example3_lib.cpp b/examples/basic/library/example3/example3_lib.cpp
deleted file mode 100644
index a8781bf9..00000000
--- a/examples/basic/library/example3/example3_lib.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/*---------------------------------------------------------------------------------*/
-/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
-/* */
-/* NOMAD - Version 4 has been created and developed by */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* The copyright of NOMAD - version 4 is owned by */
-/* Charles Audet - Polytechnique Montreal */
-/* Sebastien Le Digabel - Polytechnique Montreal */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
-/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
-/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
-/* for Data Valorization) */
-/* */
-/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
-/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
-/* and Exxon Mobil. */
-/* */
-/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
-/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
-/* Exxon Mobil. */
-/* */
-/* Contact information: */
-/* Polytechnique Montreal - GERAD */
-/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
-/* e-mail: nomad@gerad.ca */
-/* */
-/* 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 . */
-/* */
-/* You can find information on the NOMAD software at www.gerad.ca/nomad */
-/*---------------------------------------------------------------------------------*/
-
-#include "Nomad/nomad.hpp"
-
-/*----------------------------------------*/
-/* The problem */
-/*----------------------------------------*/
-class My_Evaluator : public NOMAD::Evaluator
-{
-public:
-
- // Create a EvalType::BB evaluator.
- My_Evaluator(const std::shared_ptr& evalParams)
- : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
- {}
-
- ~My_Evaluator() {}
-
- bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double& hMax, bool &countEval) const override
- {
- bool eval_ok = false;
- size_t n = x.size();
-
- NOMAD::Double f = 0.0; // Objective value
- NOMAD::Double c1 = 0.0; // Constraint 1
- NOMAD::Double c2 = 0.0; // Constraint 2
-
- try
- {
- for (size_t i = 0; i < n; i++)
- {
- NOMAD::Double xi = x[i];
- c1 += (xi-1).pow2();
- c2 += (xi+1).pow2();
- }
- c1 = c1-25;
- c2 = 25-c2;
-
- f = x[n-1];
- std::string bbo = f.tostring() + " " + c1.tostring() + " " + c2.tostring();
- x.setBBO(bbo);
- eval_ok = true;
- }
- catch (std::exception &e)
- {
- std::string err("Exception: ");
- err += e.what();
- throw std::logic_error(err);
- }
-
-
- countEval = true; // count a black-box evaluation
-
- return eval_ok; // the evaluation succeeded
- }
-
- // Wrapper around eval_x
- // If eval_block is not defined here, eval_x is called sequentially
- // for each point in the block, and a warning is shown.
- // The user may redefine eval_block to optimize parallelism management.
- std::vector eval_block(std::vector> &block,
- const NOMAD::Double& hMax,
- std::vector &countEval) const override
- {
- std::vector evalOk(block.size(), false);
- countEval.resize(block.size(), false);
-
- for (size_t index = 0; index < block.size(); index++)
- {
- bool countEval1 = false;
- evalOk[index] = eval_x(*block[index], hMax, countEval1);
- countEval[index] = countEval1;
- }
-
- return evalOk;
- }
-};
-
-
-
-
-void initParams(NOMAD::AllParameters &p)
-{
- // parameters creation
- size_t n = 6; // Number of variables
- p.setAttributeValue("DIMENSION", n);
- p.setAttributeValue("BB_OUTPUT_TYPE", NOMAD::stringToBBOutputTypeList("OBJ PB PB"));
-
- NOMAD::Point X0(n, 0.0);
- X0[n-1] = -4.0; // starting point (0.0 0.0 0.0 0.0 0.0 -4.0)
- p.setAttributeValue("X0", X0);
- p.setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, -6.0)); // all var. >= -6
- NOMAD::ArrayOfDouble ub(n); // 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
- ub[n-1] = 6.0; // x_6 <= 6
- p.setAttributeValue("UPPER_BOUND", ub);
-
- // the algorithm terminates after MAX_BB_EVAL black-box evaluations, or MAX_EVAL total evaluations (including cache hits).
- p.setAttributeValue("MAX_BB_EVAL", 1000);
- p.setAttributeValue("MAX_EVAL", 1000);
- p.setAttributeValue("BB_MAX_BLOCK_SIZE", (size_t)8);
- p.setAttributeValue("NB_THREADS_OPENMP",1); // Using a single thread is recommanded with block eval
-
- NOMAD::ArrayOfDouble minMeshSize(n, 0.1);
- minMeshSize[4] = 0.2;
- p.setAttributeValue("MIN_MESH_SIZE", minMeshSize);
-
- NOMAD::Point fixedVariable(n);
- fixedVariable[5] = X0[5];
- p.setAttributeValue("FIXED_VARIABLE", fixedVariable);
-
- p.setAttributeValue("DISPLAY_DEGREE", 2);
- p.setAttributeValue("DISPLAY_ALL_EVAL", true);
- p.setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString("EVAL BLK_EVA ( SOL ) OBJ CONS_H H_MAX"));
-
- // parameters validation
- p.checkAndComply();
-}
-
-/*------------------------------------------*/
-/* NOMAD main function */
-/*------------------------------------------*/
-int main (int argc, char **argv)
-{
- auto TheMainStep = std::make_unique();
-
- // Initialize all parameters
- auto params = std::make_shared();
- initParams(*params);
- TheMainStep->setAllParameters(params);
-
- // Custom Evaluator creation
- auto ev = std::make_unique(params->getEvalParams());
- TheMainStep->addEvaluator(std::move(ev));
-
- try
- {
- // Algorithm creation and execution
- TheMainStep->start();
- TheMainStep->run();
- TheMainStep->end();
- }
-
- catch(std::exception &e)
- {
- std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
- }
-
- return 0;
-}
diff --git a/examples/basic/library/example4/CMakeLists.txt b/examples/basic/library/example4/CMakeLists.txt
deleted file mode 100644
index dbcc9296..00000000
--- a/examples/basic/library/example4/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-add_executable(example4_lib.exe example4_lib.cpp )
-
-target_include_directories(example4_lib.exe PRIVATE
- ${CMAKE_SOURCE_DIR}/src)
-
-set_target_properties(example4_lib.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
-
-
-if(OpenMP_CXX_FOUND)
- target_link_libraries(example4_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
-else()
- target_link_libraries(example4_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval)
-endif()
-
-# installing executables and libraries
-install(TARGETS example4_lib.exe
- RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
-
-
-# Add a test for this example
-message(STATUS " Add example library #4")
-
-# Can run this test after install
-if (WIN32)
- add_test(NAME example4BasicLib
- COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example4_lib.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-else()
- add_test(NAME example4BasicLib
- COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./example4_lib.exe
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
-endif()
diff --git a/examples/basic/library/example4/example4_lib.cpp b/examples/basic/library/example4/example4_lib.cpp
deleted file mode 100644
index 1086f836..00000000
--- a/examples/basic/library/example4/example4_lib.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/*---------------------------------------------------------------------------------*/
-/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
-/* */
-/* NOMAD - Version 4 has been created and developed by */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* The copyright of NOMAD - version 4 is owned by */
-/* Charles Audet - Polytechnique Montreal */
-/* Sebastien Le Digabel - Polytechnique Montreal */
-/* Viviane Rochon Montplaisir - Polytechnique Montreal */
-/* Christophe Tribes - Polytechnique Montreal */
-/* */
-/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
-/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
-/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
-/* for Data Valorization) */
-/* */
-/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
-/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
-/* and Exxon Mobil. */
-/* */
-/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
-/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
-/* Exxon Mobil. */
-/* */
-/* Contact information: */
-/* Polytechnique Montreal - GERAD */
-/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
-/* e-mail: nomad@gerad.ca */
-/* */
-/* 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 . */
-/* */
-/* You can find information on the NOMAD software at www.gerad.ca/nomad */
-/*---------------------------------------------------------------------------------*/
-
-#include "Nomad/nomad.hpp"
-
-/*----------------------------------------*/
-/* The problem */
-/*----------------------------------------*/
-class My_Evaluator : public NOMAD::Evaluator
-{
-public:
- My_Evaluator(const std::shared_ptr& evalParams, NOMAD::EvalType evalType)
- : NOMAD::Evaluator(evalParams, evalType)
- {}
-
- ~My_Evaluator() {}
-
- bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double& hMax, bool &countEval) const override
- {
- bool eval_ok = false;
- size_t n = x.size();
-
- NOMAD::Double f = 0.0; // Objective value
- NOMAD::Double c1 = 0.0; // Constraint 1
- NOMAD::Double c2 = 0.0; // Constraint 2
-
- try
- {
- if (NOMAD::EvalType::BB == _evalType)
- {
- for (size_t i = 0; i < n; i++)
- {
- NOMAD::Double xi = x[i];
- c1 += (xi-1).pow2();
- c2 += (xi+1).pow2();
- }
- c1 = c1-25;
- c2 = 25-c2;
-
- }
- else
- {
- c1 = x[0]*x[0]-5;
- c2 = 5-x[1]*x[1];
- }
-
- f = x[n-1];
- std::string bbo = f.tostring() + " " + c1.tostring() + " " + c2.tostring();
- x.setBBO(bbo); // Eval type and Bb output types are determined automatically
- eval_ok = true;
- }
- catch (std::exception &e)
- {
- std::string err("Exception: ");
- err += e.what();
- throw std::logic_error(err);
- }
-
-
- countEval = true; // count a black-box evaluation
-
- return eval_ok; // the evaluation succeeded
- }
-
- // Wrapper around eval_x
- // If eval_block is not defined here, eval_x is called sequentially
- // for each point in the block, and a warning is shown.
- // The user may redefine eval_block to optimize parallelism management.
- std::vector eval_block(std::vector> &block,
- const NOMAD::Double& hMax,
- std::vector &countEval) const override
- {
- std::vector evalOk(block.size(), false);
- countEval.resize(block.size(), false);
-
- for (size_t index = 0; index < block.size(); index++)
- {
- bool countEval1 = false;
- evalOk[index] = eval_x(*block[index], hMax, countEval1);
- countEval[index] = countEval1;
- }
-
- return evalOk;
- }
-};
-
-
-
-
-void initParams(NOMAD::AllParameters &p)
-{
- // parameters creation
- size_t n = 6; // Number of variables
- p.setAttributeValue("DIMENSION", n);
- p.setAttributeValue("BB_OUTPUT_TYPE", NOMAD::stringToBBOutputTypeList("OBJ EB EB"));
-
-
- NOMAD::Point X0(n, 0.0);
- // X0[n-1] = -4.0; // starting point (0.0 0.0 0.0 0.0 0.0 -4.0)
- p.setAttributeValue("X0", X0);
- p.setAttributeValue("LOWER_BOUND", NOMAD::ArrayOfDouble(n, -6.0)); // all var. >= -6
- NOMAD::ArrayOfDouble ub(n); // 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
- ub[n-1] = 6.0; // x_6 <= 6
- p.setAttributeValue("UPPER_BOUND", ub);
-
- // the algorithm terminates after MAX_BB_EVAL black-box evaluations.
- p.setAttributeValue("MAX_BB_EVAL", 1000);
- p.setAttributeValue("EVAL_SURROGATE_COST", 10);
- p.setAttributeValue("EVAL_QUEUE_SORT",NOMAD::EvalSortType::SURROGATE);
-
-
- // Using surrogate for sort and the options below => no quad model is used.
- p.setAttributeValue("QUAD_MODEL_SEARCH", false);
- p.setAttributeValue("NM_SEARCH", false);
- p.setAttributeValue("DIRECTION_TYPE", NOMAD::DirectionType::ORTHO_2N);
-
- p.setAttributeValue("DISPLAY_DEGREE", 2);
-
-
- // parameters validation
- p.checkAndComply();
-}
-
-/*------------------------------------------*/
-/* NOMAD main function */
-/*------------------------------------------*/
-int main (int argc, char **argv)
-{
- auto TheMainStep = std::make_unique();
-
- // Initialize all parameters
- auto params = std::make_shared();
- initParams(*params);
- TheMainStep->setAllParameters(params);
-
- // Custom BB evaluator creation
- auto evBB = std::make_unique(params->getEvalParams(),NOMAD::EvalType::BB);
- TheMainStep->addEvaluator(std::move(evBB));
-
- // Custom SURROGATE evaluator creation
- auto evSurrogate = std::make_unique(params->getEvalParams(),NOMAD::EvalType::SURROGATE);
- TheMainStep->addEvaluator(std::move(evSurrogate));
- try
- {
- // Algorithm creation and execution
- TheMainStep->start();
- TheMainStep->run();
- TheMainStep->end();
- }
-
- catch(std::exception &e)
- {
- std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
- }
-
- return 0;
-}
diff --git a/examples/basic/library/multi_obj/CMakeLists.txt b/examples/basic/library/multi_obj/CMakeLists.txt
new file mode 100644
index 00000000..11615c0c
--- /dev/null
+++ b/examples/basic/library/multi_obj/CMakeLists.txt
@@ -0,0 +1,29 @@
+add_executable(multi_obj_lib.exe multi_obj_lib.cpp)
+
+target_include_directories(multi_obj_lib.exe PRIVATE ${CMAKE_SOURCE_DIR}/src)
+
+set_target_properties(multi_obj_lib.exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" SUFFIX "")
+
+if(OpenMP_CXX_FOUND)
+ target_link_libraries(multi_obj_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval OpenMP::OpenMP_CXX)
+else()
+ target_link_libraries(multi_obj_lib.exe PUBLIC nomadAlgos nomadUtils nomadEval)
+endif()
+
+# installing executables and libraries
+install(TARGETS multi_obj_lib.exe
+ RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} )
+
+# Add a test for this example
+message(STATUS " Add multi obj library example")
+
+# Can run this test after install
+if (WIN32)
+ add_test(NAME MultiObjBasicLib
+ COMMAND bash.exe ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./multi_obj_lib.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+else()
+ add_test(NAME MultiObjBasicLib
+ COMMAND ${CMAKE_BINARY_DIR}/examples/runExampleTest.sh ./multi_obj_lib.exe
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+endif()
diff --git a/examples/basic/library/multi_obj/multi_obj_lib.cpp b/examples/basic/library/multi_obj/multi_obj_lib.cpp
new file mode 100644
index 00000000..03f47ffa
--- /dev/null
+++ b/examples/basic/library/multi_obj/multi_obj_lib.cpp
@@ -0,0 +1,280 @@
+/*---------------------------------------------------------------------------------*/
+/* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
+/* */
+/* NOMAD - Version 4 has been created and developed by */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* The copyright of NOMAD - version 4 is owned by */
+/* Charles Audet - Polytechnique Montreal */
+/* Sebastien Le Digabel - Polytechnique Montreal */
+/* Viviane Rochon Montplaisir - Polytechnique Montreal */
+/* Christophe Tribes - Polytechnique Montreal */
+/* */
+/* NOMAD 4 has been funded by Rio Tinto, Hydro-Québec, Huawei-Canada, */
+/* NSERC (Natural Sciences and Engineering Research Council of Canada), */
+/* InnovÉÉ (Innovation en Énergie Électrique) and IVADO (The Institute */
+/* for Data Valorization) */
+/* */
+/* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
+/* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
+/* and Exxon Mobil. */
+/* */
+/* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
+/* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
+/* Exxon Mobil. */
+/* */
+/* Contact information: */
+/* Polytechnique Montreal - GERAD */
+/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
+/* e-mail: nomad@gerad.ca */
+/* */
+/* 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 . */
+/* */
+/* You can find information on the NOMAD software at www.gerad.ca/nomad */
+/*---------------------------------------------------------------------------------*/
+/**
+ \file multi_obj_lib.cpp
+ \brief Library example for nomad (DMulti-MADS algorithm)
+ \author Ludovic Salomon
+ \date 2024
+ */
+
+#include "Nomad/nomad.hpp"
+#include "Type/DMultiMadsSearchStrategyType.hpp"
+
+// A conceptual marine design problem
+// See "An Easy-To-use Real-world Multi-objective Optimization Suite problem"
+// by R. Tanabe and H. Ishibuchi
+class MarineDesignProblem : public NOMAD::Evaluator
+{
+public:
+ explicit MarineDesignProblem(const std::shared_ptr& evalParams)
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
+ {}
+
+ ~MarineDesignProblem() override = default;
+
+ bool eval_x(NOMAD::EvalPoint& x, const NOMAD::Double& hMax, bool& countEval) const override
+ {
+ bool eval_ok = false;
+
+ NOMAD::Double f1 = 1e20, f2 = 1e20, f3 = 1e20;
+
+ try
+ {
+ // Variables
+ const double L = x[0].todouble();
+ const double B = x[1].todouble();
+ const double D = x[2].todouble();
+ const double T = x[3].todouble();
+ const double Vk = x[4].todouble();
+ const double Cb = x[5].todouble();
+
+ // Parameters
+ const double handlingRate = 8000;
+ const double roundTripMiles = 5000;
+ const double fuelPrice = 100;
+ const double g = 9.8065;
+
+ // Equations
+ const double verticalCenterOfBuoyancy = 0.53 * T;
+ const double metacentricRadius = (0.085 * Cb - 0.002) * B * B / (T * Cb);
+ const double verticalCenterOfGravity = 1 + 0.52 * D;
+
+ const double displacement = 1.025 * L * B * T * Cb;
+ const double a = 4977.06 * Cb * Cb - 8105.61 * Cb + 4456.51;
+ const double b = -10847.2 * Cb * Cb + 12817 * Cb - 6960.32;
+ const double V = 0.5144 * Vk;
+ const double froudenumber = V / std::pow(g * L, 0.5);
+ const double P = std::pow(displacement, 2.0/3) * std::pow(Vk, 3) / (a + b * froudenumber);
+
+ const double steelWeight = 0.034 * std::pow(L, 1.7) * std::pow(B, 0.7) *
+ std::pow(D, 0.4) * std::pow(Cb, 0.5);
+ const double outfitWeight = 1.0 * std::pow(L, 0.8) * std::pow(B, 0.6) *
+ std::pow(D, 0.3) * std::pow(Cb, 0.1);
+ const double machineryWeight = 0.17 * std::pow(P, 0.9);
+ const double lightShipWeight = steelWeight + outfitWeight + machineryWeight;
+
+ const double deadweight = displacement - lightShipWeight;
+
+ const double dailyConsumption = (0.19 * P * 24) / 1000 + 0.2;
+ const double seaDays = (roundTripMiles * Vk) / 24;
+ const double fuelCarried = dailyConsumption * (seaDays + 5);
+ const double portCost = 6.3 * std::pow(deadweight, 0.8);
+
+ const double cargoDeadweight = deadweight - fuelCarried - 2 * std::pow(deadweight, 0.5);
+ const double portDays = 2 * (cargoDeadweight / handlingRate + 0.5);
+ const double roundTripsPerYear = 350.0 / (seaDays + portDays);
+
+ const double fuelCost = 1.05 * dailyConsumption * seaDays * fuelPrice;
+ const double runningCosts = 40000 * std::pow(deadweight, 0.8);
+ const double voyageCosts = (fuelCost + portCost) * roundTripsPerYear;
+ const double shipCosts = 1.3 * (2000 * std::pow(steelWeight, 0.85) +
+ 3500 * outfitWeight + 2400 * std::pow(P, 0.8));
+ const double capitalCosts = 0.2 * shipCosts;
+ const double annualCosts = capitalCosts + runningCosts + voyageCosts;
+
+ const double annualCargo = - cargoDeadweight * roundTripsPerYear;
+
+ // Objectives
+ f1 = annualCosts / annualCargo;
+ f2 = lightShipWeight;
+ f3 = annualCargo;
+
+ // Constraints
+ const NOMAD::Double g1 = L / B - 6.0; // >= 0
+ const NOMAD::Double g2 = 15.0 - L / D; // >= 0
+ const NOMAD::Double g3 = 19.0 - L / T; // >= 0
+ const NOMAD::Double g4 = 0.45 * std::pow(deadweight, 0.31) - T; // >= 0
+ const NOMAD::Double g5 = 0.7 * D + 0.7 - T; // >= 0
+ const NOMAD::Double g6 = deadweight - 3000; // >= 0
+ const NOMAD::Double g7 = 500000 - deadweight; // >= 0
+ const NOMAD::Double g8 = 0.32 - froudenumber; // >= 0
+ const NOMAD::Double g9 = verticalCenterOfBuoyancy + metacentricRadius -
+ verticalCenterOfGravity - 0.07 * B; // >= 0
+
+ std::string bbo = f1.tostring() + " " + f2.tostring() + " " + f3.tostring();
+ bbo += " " + (-g1).tostring();
+ bbo += " " + (-g2).tostring();
+ bbo += " " + (-g3).tostring();
+ bbo += " " + (-g4).tostring();
+ bbo += " " + (-g5).tostring();
+ bbo += " " + (-g6).tostring();
+ bbo += " " + (-g7).tostring();
+ bbo += " " + (-g8).tostring();
+ bbo += " " + (-g9).tostring();
+
+ x.setBBO(bbo);
+
+ eval_ok = true;
+ }
+ catch (std::exception& e)
+ {
+ std::string err("Exception: ");
+ err += e.what();
+ throw std::logic_error(err);
+ }
+ countEval = true;
+ return eval_ok;
+ }
+};
+
+// Main function
+int main()
+{
+ NOMAD::MainStep TheMainStep;
+
+ try
+ {
+ // Parameters creation
+ auto params = std::make_shared();
+
+ // Dimensions of the blackbox, inputs and outputs
+ const size_t n = 6;
+ params->setAttributeValue("DIMENSION", n);
+
+ NOMAD::ArrayOfDouble lb(n, 0);
+ lb[0] = 150;
+ lb[1] = 20;
+ lb[2] = 13;
+ lb[3] = 10;
+ lb[4] = 14;
+ lb[5] = 0.63;
+ params->setAttributeValue("LOWER_BOUND", lb);
+
+ NOMAD::ArrayOfDouble ub(n, 0);
+ ub[0] = 274.32;
+ ub[1] = 32.31;
+ ub[2] = 25;
+ ub[3] = 11.71;
+ ub[4] = 18;
+ ub[5] = 0.75;
+ params->setAttributeValue("UPPER_BOUND", ub);
+
+ // Outputs, constraints and objectives
+ NOMAD::BBOutputTypeList bbOutputTypes;
+ for (size_t i = 0; i < 3; ++i)
+ {
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::OBJ);
+ }
+ for (size_t i = 0; i < 9; ++i)
+ {
+ bbOutputTypes.emplace_back(NOMAD::BBOutputType::EB); // We want a two-phase approach
+ }
+ params->setAttributeValue("BB_OUTPUT_TYPE", bbOutputTypes);
+
+ // A line initialization is practically more efficient than giving a single point for
+ // multiobjective optimization.
+ // The interesting reader can report to the following reference for more information.
+ // Direct Multisearch for multiobjective optimization
+ // by A.L. Custodio, J.F.A. Madeira, A.I.F. Vaz and L.N. Vicente, 2011.
+ NOMAD::ArrayOfPoint x0s;
+ for (size_t j = 0; j < n; ++j)
+ {
+ NOMAD::Point x0(n, 0);
+ for (size_t i = 0; i < n; ++i)
+ {
+ x0[i] = lb[i] + (double) j * (ub[i] - lb[i]) / (n - 1);
+ }
+ x0s.push_back(x0);
+ }
+ // Starting point
+ params->setAttributeValue("X0", x0s);
+
+ // Algorithm parameters
+ // 1- Terminate after this number of maximum blackbox evaluations.
+ params->setAttributeValue("MAX_BB_EVAL", 3000);
+
+ // 2- Use n+1 directions
+ params->setAttributeValue("DIRECTION_TYPE", NOMAD::DirectionType::ORTHO_NP1_NEG);
+
+ // 3- For multiobjective optimization, these parameters are required.
+ params->setAttributeValue("DMULTIMADS_OPTIMIZATION", true);
+ // For multiobjective optimization, sort cannot use the default quad model info.
+ params->setAttributeValue("EVAL_QUEUE_SORT", NOMAD::EvalSortType::DIR_LAST_SUCCESS);
+ params->setAttributeValue("NM_SEARCH", false); // Deactivate Nelder-Mead search
+ // NB: by default, QUAD_MODEL_SEARCH is activated; to deactivate it, uncomment
+ // params->setAttributeValue("QUAD_MODEL_SEARCH", true); // Deactivate Quad Model search
+ // Change Quad Model search strategy for DMultiMads
+ params->setAttributeValue("DMULTIMADS_QUAD_MODEL_STRATEGY", NOMAD::DMultiMadsQuadSearchType::DMS);
+
+ // Advanced attributes for DMultiMads
+ params->setAttributeValue("DMULTIMADS_SELECT_INCUMBENT_THRESHOLD", 2);
+
+ // 4- Other useful parameters
+ params->setAttributeValue("DISPLAY_DEGREE", 2);
+ params->setAttributeValue("DISPLAY_ALL_EVAL",true);
+ params->setAttributeValue("SOLUTION_FILE", std::string("sol.txt")); // Save the Pareto front approximation
+ // params->setAttributeValue("HISTORY_FILE", std::string("history.txt")); // Save history. To uncomment if you want it.
+
+ // Validate
+ params->checkAndComply();
+
+ // Run the solver
+ TheMainStep.setAllParameters(params);
+ auto ev = std::make_unique(params->getEvalParams());
+ TheMainStep.addEvaluator(std::move(ev));
+
+ TheMainStep.start();
+ TheMainStep.run();
+ TheMainStep.end();
+ }
+
+ catch(std::exception &e)
+ {
+ std::cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
+ }
+ return 0;
+}
diff --git a/examples/basic/library/single_obj_parallel/basic_lib.cpp b/examples/basic/library/single_obj_parallel/basic_lib.cpp
index 73ed7875..c6f95610 100644
--- a/examples/basic/library/single_obj_parallel/basic_lib.cpp
+++ b/examples/basic/library/single_obj_parallel/basic_lib.cpp
@@ -44,58 +44,56 @@
/* */
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
-/*-----------------------------------------------------*/
-/* how to use the NOMAD library with a user function */
-/*-----------------------------------------------------*/
+/*----------------------------------------------------------*/
+/* How to use the NOMAD library with a user eval function */
+/* that take a block of points and evaluate them in */
+/* parallel (OpenMP). */
+/*------------------------------------- ----------------*/
#include "Nomad/nomad.hpp"
#ifdef _OPENMP
#include
#endif
-// Number of threads to be used in parallel
-#define NUM_THREADS 6
-
-// A structure to pass arguments to the evaluation wrapper function
-class My_Evaluator;
-typedef struct Arg_Eval_tag {
- std::shared_ptr x;
- NOMAD::Double hMax;
- bool countEval;
-} Arg_Eval_t;
+// Number of threads to be used for evaluation of a block of points in parallel.
+// NOMAD queue for parallel evaluation is not used in this example. To
+// perform parallel evaluations using NOMAD queue, the user must set
+// the Nomad parameter NB_THREADS_EVAL to a value greater than 1.
+#define THREADS_EVAL_X 6
// Wrapper of eval_x used for parallel evaluation.
-bool wrapper_eval_x(Arg_Eval_t& eval_arg)
+bool wrapper_eval_x(std::shared_ptr & x, const NOMAD::Double& hmax, bool & countEval)
{
+
+ // std::cout << "Thread #" << omp_get_thread_num() << std::endl;
+
NOMAD::Double c1 = 0.0, c2 = 0.0;
- NOMAD::EvalPoint& x = *(eval_arg.x);
for (int i = 0; i < 5; i++)
{
- c1 += (x[i]-1).pow2();
- c2 += (x[i]+1).pow2();
+ c1 += ((*x)[i]-1).pow2();
+ c2 += ((*x)[i]+1).pow2();
}
- NOMAD::Double f = x[4]; // objective value
+ NOMAD::Double f = (*x)[4]; // objective value
c1 = c1-25; // constraint 1
c2 = 25-c2; // constraint 2
std::string bbo = f.tostring() + " " + c1.tostring() + " " + c2.tostring();
- eval_arg.x->setBBO(bbo);
+ x->setBBO(bbo);
- eval_arg.countEval = true; // count a black-box evaluation
+ countEval = true; // count a black-box evaluation
return true; // Eval ok
}
-
class My_Evaluator : public NOMAD::Evaluator
{
public:
- My_Evaluator(const std::shared_ptr& evalParams)
+ explicit My_Evaluator(const std::shared_ptr& evalParams)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB)
{}
- ~My_Evaluator() {}
+ ~My_Evaluator() override = default;
// Implementation
std::vector eval_block(std::vector> &block,
@@ -105,40 +103,31 @@ class My_Evaluator : public NOMAD::Evaluator
{
std::vector evalOk(block.size(), false);
listCountEval.resize(block.size(), false); // Evaluations are not counted until eval_x is called and sets countEval
-
- // Arguments passed to the evaluation wrapper
- Arg_Eval_t* eval_arg = new Arg_Eval_t[block.size()];
-
- std::vector>::iterator it_x = block.begin(), end_x = block.end();
- size_t i = 0;
+
+ int i;
#ifdef _OPENMP
- #pragma omp parallel
+ #pragma omp parallel for num_threads(THREADS_EVAL_X) shared(block,evalOk,listCountEval, hMax) private(i)
#endif
- for (it_x = block.begin(); it_x != end_x; ++it_x, ++i)
+ for(i = 0; i < (int)block.size(); i++)
{
- // A thread is created for each x in the block.
- eval_arg[i].x = (*it_x);
- eval_arg[i].hMax = hMax.todouble();
- evalOk[i] = wrapper_eval_x(eval_arg[i]);
- listCountEval[i] = eval_arg[i].countEval;
+ bool countEval = false;
+ evalOk[i] = wrapper_eval_x(block[i],hMax, countEval);
+ listCountEval[i] = countEval;
}
- // End of parallel block
-
- delete[] eval_arg;
return evalOk;
}
};
-void initParams(std::shared_ptr& params)
+void initParams(const std::shared_ptr& params)
{
params->setAttributeValue("DIMENSION", 5); // number of variables
NOMAD::BBOutputTypeList bbot; // Definition of output types
- bbot.push_back(NOMAD::BBOutputType::OBJ);
- bbot.push_back(NOMAD::BBOutputType::PB);
- bbot.push_back(NOMAD::BBOutputType::EB);
+ bbot.emplace_back(NOMAD::BBOutputType::OBJ);
+ bbot.emplace_back(NOMAD::BBOutputType::PB);
+ bbot.emplace_back(NOMAD::BBOutputType::EB);
params->setAttributeValue("BB_OUTPUT_TYPE", bbot);
// params->setAttributeValue("DISPLAY_ALL_EVAL", true); // displays all evaluations.
@@ -149,7 +138,7 @@ void initParams(std::shared_ptr& params)
params->setAttributeValue("SPECULATIVE_SEARCH", false);
params->setAttributeValue("NM_SEARCH", false);
params->setAttributeValue("QUAD_MODEL_SEARCH", false);
- // Use single pass poll method with n+1 points -> 6 trial points in a block per poll
+ // Use poll method n+1 uni -> 6 trial points per poll on a single pass
params->setAttributeValue("DIRECTION_TYPE",NOMAD::DirectionType::NP1_UNI);
params->setAttributeValue("X0", NOMAD::Point(5,0.0)); // starting point
@@ -165,18 +154,16 @@ void initParams(std::shared_ptr& params)
// 100 black-box evaluations
// Max number of points to be given as a block for evaluation
- // This option is required to perform parallel evaluations in eval_block
- // function above
- params->setAttributeValue("BB_MAX_BLOCK_SIZE", NUM_THREADS);
+ // This option is required to perform parallel evaluations
+ // All points in a block will be evaluated in parallel
+ params->setAttributeValue("BB_MAX_BLOCK_SIZE", THREADS_EVAL_X);
- // A single thread is used for Nomad "parallel" evaluation queue.
- params->setAttributeValue("NB_THREADS_OPENMP", 1);
+ // NOTE: A single thread is used for Nomad "parallel" evaluation queue.
// parameters validation:
params->checkAndComply();
}
-
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
@@ -184,13 +171,21 @@ int main(int argc, char ** argv)
{
try
{
+
+#ifdef _OPENMP
+ // This is important for nested parallel regions. Nomad parallel region
+ // for evaluation queue and a parallel region for block evaluation.
+ omp_set_nested(true);
+ omp_set_dynamic(false);
+#endif
+
auto TheMainStep = std::make_unique();
// Parameters creation
auto params = std::make_shared();
initParams(params);
TheMainStep->setAllParameters(params);
-
+
// Custom Evaluator
auto ev = std::make_unique(params->getEvalParams());
TheMainStep->addEvaluator(std::move(ev));
diff --git a/ext/sgtelib/CMakeLists.txt b/ext/sgtelib/CMakeLists.txt
index 1d5d8263..5412552e 100644
--- a/ext/sgtelib/CMakeLists.txt
+++ b/ext/sgtelib/CMakeLists.txt
@@ -24,27 +24,27 @@ endif()
# check compiler version
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- # require at least gcc 4
- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4)
- message(FATAL_ERROR "GCC version < 4 has not been tested for Nomad")
+ # require at least gcc 8
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
+ message(FATAL_ERROR "GCC version < 8 has not been tested for sgtelib")
endif()
elseif (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
# require at least clang 5
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
- message(FATAL_ERROR "Clang version has not been tested for Nomad")
+ message(FATAL_ERROR "Clang version has not been tested for sgtelib")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
- # require at least 15.0 (MSVC 2017) for C++14 support
+ # require at least 15.8 (MSVC 2017) for C++17 support
if (MSVC_TOOLSET_VERSION VERSION_LESS 141)
- message(FATAL_ERROR "MSVC version ${CMAKE_CXX_COMPILER_VERSION} has not been tested for Nomad")
+ message(FATAL_ERROR "MSVC version ${CMAKE_CXX_COMPILER_VERSION} has not been tested for sgtelib")
endif()
else()
message(WARNING "You are using an unsupported compiler. Compilation has only been tested with Clang, GCC, and MSVC.")
endif()
-# require c++14
-set(CXX_STANDARD_REQUIRED 14)
+# require c++17
+set(CXX_STANDARD_REQUIRED 17)
# header files
@@ -113,6 +113,7 @@ if(BUILD_INTERFACE_PYTHON MATCHES ON)
endif()
+
# install header files
install(
FILES ${SGTELIB_HEADERS}
diff --git a/ext/sgtelib/CMakeListsLibs.txt b/ext/sgtelib/CMakeListsLibs.txt
index b84eeb6c..259f2d29 100644
--- a/ext/sgtelib/CMakeListsLibs.txt
+++ b/ext/sgtelib/CMakeListsLibs.txt
@@ -32,6 +32,7 @@ endif()
# installing library
install(
TARGETS sgtelib
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)
diff --git a/ext/sgtelib/CMakeListsLibsStatic.txt b/ext/sgtelib/CMakeListsLibsStatic.txt
index 52aac569..0e4b134a 100644
--- a/ext/sgtelib/CMakeListsLibsStatic.txt
+++ b/ext/sgtelib/CMakeListsLibsStatic.txt
@@ -32,6 +32,7 @@ endif()
# installing library
install(
TARGETS sgtelibStatic
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sgtelib
)
diff --git a/ext/sgtelib/src/Matrix.cpp b/ext/sgtelib/src/Matrix.cpp
index 373cf022..40cf7afe 100644
--- a/ext/sgtelib/src/Matrix.cpp
+++ b/ext/sgtelib/src/Matrix.cpp
@@ -1672,7 +1672,8 @@ SGTELIB::Matrix SGTELIB::Matrix::ones ( const int nbRows , const int nbCols ) {
/*---------------------------*/
/* rank */
/*---------------------------*/
-SGTELIB::Matrix SGTELIB::Matrix::rank ( void ) const {
+SGTELIB::Matrix SGTELIB::Matrix::rank ( void ) const
+{
if ((_nbRows>1) && (_nbCols>1))
throw SGTELIB::Exception ( __FILE__ , __LINE__ ,"Matrix::rank: dimension error" );
@@ -1821,6 +1822,23 @@ double SGTELIB::Matrix::norm ( void ) const{
return sqrt(normsquare());
}//
+
+/*---------------------------*/
+/* norm inf */
+/*---------------------------*/
+double SGTELIB::Matrix::norm_inf ( void ) const{
+ double norm = 0;
+ for (int i = 0 ; i < _nbRows ; ++i)
+ {
+ for (int j = 0 ; j < _nbCols ; ++j)
+ {
+ norm = std::max(std::abs(_X[i][j]), norm);
+ }
+ }
+ return norm;
+}//
+
+
/*---------------------------*/
/* sum */
/*---------------------------*/
@@ -2967,6 +2985,30 @@ SGTELIB::Matrix SGTELIB::Matrix::get_distances_norminf ( const SGTELIB::Matrix &
return D;
}//
+/*-------------------------------------------------*/
+/* Return norm2 distance between two vectors */
+/*-------------------------------------------------*/
+double SGTELIB::Matrix::distNorm2(const SGTELIB::Matrix& v1, const SGTELIB::Matrix& v2)
+{
+ const int n = v1.get_nb_rows();
+ if (v1.get_nb_rows() != n)
+ {
+ throw SGTELIB::Exception(__FILE__ , __LINE__ , "dist: dimension error");
+ }
+
+ if (v1.get_nb_cols() != 1 || v2.get_nb_cols() != 1)
+ {
+ throw SGTELIB::Exception(__FILE__ , __LINE__ , "dist: dimension error: v1 and v2 must be column vectors");
+ }
+
+ double distValue = 0;
+ for (int i = 0; i < n; ++i)
+ {
+ distValue += (v1._X[i][0] - v2._X[i][0]) * (v1._X[i][0] - v2._X[i][0]);
+ }
+ return std::sqrt(distValue);
+}
+
/*-------------------------------------------------*/
/* find_row */
diff --git a/ext/sgtelib/src/Matrix.hpp b/ext/sgtelib/src/Matrix.hpp
index 02d16a3e..c416cdb4 100644
--- a/ext/sgtelib/src/Matrix.hpp
+++ b/ext/sgtelib/src/Matrix.hpp
@@ -199,6 +199,7 @@ namespace SGTELIB {
// Norm
double norm ( void ) const;
double normsquare ( void ) const;
+ double norm_inf ( void ) const;
void normalize_cols ( void );
SGTELIB::Matrix col_norm ( const norm_t nt ) const;
@@ -405,6 +406,8 @@ namespace SGTELIB {
static SGTELIB::Matrix get_distances_norminf ( const SGTELIB::Matrix & A ,
const SGTELIB::Matrix & B );
+ static double distNorm2(const SGTELIB::Matrix& v1, const SGTELIB::Matrix & v2);
+
int find_row (SGTELIB::Matrix & R);
// nan
@@ -423,16 +426,16 @@ namespace SGTELIB {
};
}
-SGTELIB::Matrix operator * (const SGTELIB::Matrix & A , const double v );
-SGTELIB::Matrix operator * (const double v , const SGTELIB::Matrix & A);
-SGTELIB::Matrix operator * (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
-SGTELIB::Matrix operator + (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
-SGTELIB::Matrix operator + (const SGTELIB::Matrix & A , const double v );
-SGTELIB::Matrix operator + (const double v , const SGTELIB::Matrix & A);
-SGTELIB::Matrix operator - (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
-SGTELIB::Matrix operator - (const SGTELIB::Matrix & A , const double v);
-SGTELIB::Matrix operator - (const double v , const SGTELIB::Matrix & A);
-SGTELIB::Matrix operator - (const SGTELIB::Matrix & A);
-SGTELIB::Matrix operator / (const SGTELIB::Matrix & A , const double v );
+DLL_API SGTELIB::Matrix operator * (const SGTELIB::Matrix & A , const double v );
+DLL_API SGTELIB::Matrix operator * (const double v , const SGTELIB::Matrix & A);
+DLL_API SGTELIB::Matrix operator * (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
+DLL_API SGTELIB::Matrix operator + (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
+DLL_API SGTELIB::Matrix operator + (const SGTELIB::Matrix & A , const double v );
+DLL_API SGTELIB::Matrix operator + (const double v , const SGTELIB::Matrix & A);
+DLL_API SGTELIB::Matrix operator - (const SGTELIB::Matrix & A , const SGTELIB::Matrix & B);
+DLL_API SGTELIB::Matrix operator - (const SGTELIB::Matrix & A , const double v);
+DLL_API SGTELIB::Matrix operator - (const double v , const SGTELIB::Matrix & A);
+DLL_API SGTELIB::Matrix operator - (const SGTELIB::Matrix & A);
+DLL_API SGTELIB::Matrix operator / (const SGTELIB::Matrix & A , const double v );
#endif
diff --git a/ext/sgtelib/src/Surrogate_CN.cpp b/ext/sgtelib/src/Surrogate_CN.cpp
index 2952ac6c..b406ca64 100644
--- a/ext/sgtelib/src/Surrogate_CN.cpp
+++ b/ext/sgtelib/src/Surrogate_CN.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_CN::Surrogate_CN ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ) {
#ifdef SGTELIB_DEBUG
std::cout << "constructor CN\n";
diff --git a/ext/sgtelib/src/Surrogate_CN.hpp b/ext/sgtelib/src/Surrogate_CN.hpp
index ca4dfd11..424094ec 100644
--- a/ext/sgtelib/src/Surrogate_CN.hpp
+++ b/ext/sgtelib/src/Surrogate_CN.hpp
@@ -57,7 +57,7 @@ namespace SGTELIB {
// Constructor
Surrogate_CN ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_CN ( void );
diff --git a/ext/sgtelib/src/Surrogate_KS.cpp b/ext/sgtelib/src/Surrogate_KS.cpp
index 77309ed6..1e337b4a 100644
--- a/ext/sgtelib/src/Surrogate_KS.cpp
+++ b/ext/sgtelib/src/Surrogate_KS.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_KS::Surrogate_KS ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ) {
#ifdef SGTELIB_DEBUG
std::cout << "constructor KS\n";
diff --git a/ext/sgtelib/src/Surrogate_KS.hpp b/ext/sgtelib/src/Surrogate_KS.hpp
index 7fa37cd4..ce38bbd2 100644
--- a/ext/sgtelib/src/Surrogate_KS.hpp
+++ b/ext/sgtelib/src/Surrogate_KS.hpp
@@ -54,7 +54,7 @@ namespace SGTELIB {
// Constructor
Surrogate_KS ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_KS ( void );
diff --git a/ext/sgtelib/src/Surrogate_Kriging.cpp b/ext/sgtelib/src/Surrogate_Kriging.cpp
index 9a14a5d3..4e23c2c7 100644
--- a/ext/sgtelib/src/Surrogate_Kriging.cpp
+++ b/ext/sgtelib/src/Surrogate_Kriging.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_Kriging::Surrogate_Kriging ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ),
_R ( "R",0,0 ),
_Ri ( "Ri",0,0 ),
diff --git a/ext/sgtelib/src/Surrogate_Kriging.hpp b/ext/sgtelib/src/Surrogate_Kriging.hpp
index eb8d091d..e6e1dba0 100644
--- a/ext/sgtelib/src/Surrogate_Kriging.hpp
+++ b/ext/sgtelib/src/Surrogate_Kriging.hpp
@@ -97,7 +97,7 @@ namespace SGTELIB {
/* Constructor */
/*--------------------------------------*/
Surrogate_Kriging ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
/*--------------------------------------*/
/* Destructor */
diff --git a/ext/sgtelib/src/Surrogate_LOWESS.cpp b/ext/sgtelib/src/Surrogate_LOWESS.cpp
index c8cc44c5..a2735485 100644
--- a/ext/sgtelib/src/Surrogate_LOWESS.cpp
+++ b/ext/sgtelib/src/Surrogate_LOWESS.cpp
@@ -35,7 +35,7 @@ const int GAMMA_EXP = 2;
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_LOWESS::Surrogate_LOWESS ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ),
_q ( 0 ),
_q_old ( 99999999 ),
diff --git a/ext/sgtelib/src/Surrogate_LOWESS.hpp b/ext/sgtelib/src/Surrogate_LOWESS.hpp
index 5a599411..480e33bc 100644
--- a/ext/sgtelib/src/Surrogate_LOWESS.hpp
+++ b/ext/sgtelib/src/Surrogate_LOWESS.hpp
@@ -78,7 +78,7 @@ namespace SGTELIB {
public:
// Constructor
Surrogate_LOWESS ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_LOWESS ( void );
diff --git a/ext/sgtelib/src/Surrogate_PRS.cpp b/ext/sgtelib/src/Surrogate_PRS.cpp
index dbe12a66..22123f6a 100644
--- a/ext/sgtelib/src/Surrogate_PRS.cpp
+++ b/ext/sgtelib/src/Surrogate_PRS.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_PRS::Surrogate_PRS ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ),
_q ( 0 ),
_M ( "M",0,0 ),
@@ -94,6 +94,7 @@ bool SGTELIB::Surrogate_PRS::build_private ( void ) {
if (_q>200)
return false;
+// Let's try to building model with less points by adding a small ridge
if ( (_q>pvar) && (_param.get_ridge()==0) )
_param.set_ridge(0.001);
@@ -208,14 +209,30 @@ bool SGTELIB::Surrogate_PRS::compute_alpha ( void ){
return false;
}
// COMPUTE COEFS
- if (r>0){
+ if (r>0)
+ {
_Ai = (Ht*_H+r*SGTELIB::Matrix::identity(_q)).SVD_inverse();
//_Ai = (Ht*_H+r*SGTELIB::Matrix::identity(_q)).cholesky_inverse();
}
- else{
- _Ai = (Ht*_H).SVD_inverse();
- //_Ai = (Ht*_H).cholesky_inverse();
+ else
+ {
+ _Ai = (Ht*_H).SVD_inverse();
+ //_Ai = (Ht*_H).cholesky_inverse();
+
+ // We may not have enough points to compute all coefficients of the monome
+ // Let's try with a small ridge
+ if (_Ai.has_nan())
+ {
+ r = 1E-3;
+ _Ai = (Ht*_H+r*SGTELIB::Matrix::identity(_q)).SVD_inverse();
+
+ }
+ }
+ if (_Ai.has_nan())
+ {
+ return false;
}
+
_alpha = _Ai * (Ht * Zs);
SGTELIB::Matrix sing_val = (Ht*_H).get_singular_values();
@@ -949,23 +966,25 @@ void SGTELIB::Surrogate_PRS::compute_multiplier(
const SGTELIB::Matrix & Jacobian,
const double rank_tol)
{
- int ncon = Jacobian.get_nb_rows();
- int nvar = Jacobian.get_nb_cols();
+ const int ncon = Jacobian.get_nb_rows();
+ const int nvar = Jacobian.get_nb_cols();
- if (Grad.get_nb_rows() != nvar || Grad.get_nb_cols() != 1 )
+ if (Grad.get_nb_rows() != nvar || Grad.get_nb_cols() != 1)
{
throw Exception(__FILE__, __LINE__, "Grad dimensions are not ok!");
}
- if (Jacobian.get_nb_rows() > ncon || Jacobian.get_nb_cols() != nvar )
+ if (Jacobian.get_nb_cols() != nvar)
{
throw Exception(__FILE__, __LINE__, "Jacobian dimensions are not ok!");
}
- if (Jacobian.has_nan()) {
+ if (Jacobian.has_nan())
+ {
throw Exception(__FILE__, __LINE__, "Jacobian contains NaN");
}
- if (ncon > nvar) {
- throw Exception(__FILE__, __LINE__, "Jacobian should have full column rank (ncon > nvar)");
- }
+
+ // The multipliers are the solutions of the least-square equation
+ // Jacobian multiplier = Grad.
+ // We use the SVD to compute the inverse of Jacobian t Jacobian.
// init matrices for SVD
double ** U = new double *[nvar];
@@ -981,28 +1000,28 @@ void SGTELIB::Surrogate_PRS::compute_multiplier(
// Perform SVD
std::string error_msg;
// Compute the SVD of the transpose Jacobian
- Jacobian.transpose().SVD_decomposition ( error_msg , U, W, V, 1000000000 );
+ Jacobian.transpose().SVD_decomposition(error_msg , U, W, V, 1000000000);
- int rank=0;
- for (int i=0; i < ncon; i++)
+ int rank = 0;
+ for (int i = 0; i < ncon; i++)
{
if (fabs(W[i]) > rank_tol)
+ {
rank++;
- }
-
- if (rank != ncon) {
- throw Exception(__FILE__, __LINE__, "Jacobian should have full column rank (rank deficient)");
+ }
+ else
+ {
+ W[i] = 0;
+ }
}
SGTELIB::Matrix Wm = SGTELIB::Matrix("Wm", ncon, ncon);
- for (int i=0 ; i < ncon ; i++){
- for (int j=0 ; j < ncon ; j++){
- if (i == j){
- Wm.set(i, j, 1/(pow(W[i], 2)));
- }
- else {
- Wm.set(i, j, 0);
- }
+ for (int i = 0 ; i < ncon ; i++)
+ {
+ for (int j = 0 ; j < ncon ; j++)
+ {
+ const double Wmi = (i == j) && W[i] != 0 ? 1.0 / (W[i] * W[i]) : 0;
+ Wm.set(i, j, Wmi);
}
}
SGTELIB::Matrix Vm = SGTELIB::Matrix("Vm", ncon, ncon, V);
diff --git a/ext/sgtelib/src/Surrogate_PRS.hpp b/ext/sgtelib/src/Surrogate_PRS.hpp
index 1f29ea61..e8be3084 100644
--- a/ext/sgtelib/src/Surrogate_PRS.hpp
+++ b/ext/sgtelib/src/Surrogate_PRS.hpp
@@ -94,7 +94,7 @@ namespace SGTELIB {
// Constructor
Surrogate_PRS ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_PRS ( void );
diff --git a/ext/sgtelib/src/Surrogate_PRS_CAT.cpp b/ext/sgtelib/src/Surrogate_PRS_CAT.cpp
index eeae6ae4..32232651 100644
--- a/ext/sgtelib/src/Surrogate_PRS_CAT.cpp
+++ b/ext/sgtelib/src/Surrogate_PRS_CAT.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_PRS_CAT::Surrogate_PRS_CAT ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate_PRS ( trainingset , param ){
#ifdef SGTELIB_DEBUG
std::cout << "constructor PRS_CAT\n";
diff --git a/ext/sgtelib/src/Surrogate_PRS_CAT.hpp b/ext/sgtelib/src/Surrogate_PRS_CAT.hpp
index 192c8b70..000fb687 100644
--- a/ext/sgtelib/src/Surrogate_PRS_CAT.hpp
+++ b/ext/sgtelib/src/Surrogate_PRS_CAT.hpp
@@ -48,7 +48,7 @@ namespace SGTELIB {
// Constructor
Surrogate_PRS_CAT ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_PRS_CAT ( void );
diff --git a/ext/sgtelib/src/Surrogate_PRS_EDGE.cpp b/ext/sgtelib/src/Surrogate_PRS_EDGE.cpp
index 1d6c6375..6f194b24 100644
--- a/ext/sgtelib/src/Surrogate_PRS_EDGE.cpp
+++ b/ext/sgtelib/src/Surrogate_PRS_EDGE.cpp
@@ -29,7 +29,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_PRS_EDGE::Surrogate_PRS_EDGE ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate_PRS ( trainingset , param ){
#ifdef SGTELIB_DEBUG
std::cout << "constructor PRS_EDGE\n";
diff --git a/ext/sgtelib/src/Surrogate_PRS_EDGE.hpp b/ext/sgtelib/src/Surrogate_PRS_EDGE.hpp
index 91c8ba7b..a5b049ef 100644
--- a/ext/sgtelib/src/Surrogate_PRS_EDGE.hpp
+++ b/ext/sgtelib/src/Surrogate_PRS_EDGE.hpp
@@ -47,7 +47,7 @@ namespace SGTELIB {
// Constructor
Surrogate_PRS_EDGE ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
// destructor:
virtual ~Surrogate_PRS_EDGE ( void );
diff --git a/ext/sgtelib/src/Surrogate_RBF.cpp b/ext/sgtelib/src/Surrogate_RBF.cpp
index fcf23653..1e71a3df 100644
--- a/ext/sgtelib/src/Surrogate_RBF.cpp
+++ b/ext/sgtelib/src/Surrogate_RBF.cpp
@@ -30,7 +30,7 @@
/* constructor */
/*----------------------------*/
SGTELIB::Surrogate_RBF::Surrogate_RBF ( SGTELIB::TrainingSet & trainingset,
- SGTELIB::Surrogate_Parameters param) :
+ const SGTELIB::Surrogate_Parameters& param) :
SGTELIB::Surrogate ( trainingset , param ),
_q ( -1 ),
_qrbf ( -1 ),
diff --git a/ext/sgtelib/src/Surrogate_RBF.hpp b/ext/sgtelib/src/Surrogate_RBF.hpp
index d60b6861..298bea62 100644
--- a/ext/sgtelib/src/Surrogate_RBF.hpp
+++ b/ext/sgtelib/src/Surrogate_RBF.hpp
@@ -92,7 +92,7 @@ namespace SGTELIB {
/* Constructor */
/*--------------------------------------*/
Surrogate_RBF ( SGTELIB::TrainingSet & trainingset ,
- SGTELIB::Surrogate_Parameters param) ;
+ const SGTELIB::Surrogate_Parameters& param) ;
/*--------------------------------------*/
/* Destructor */
diff --git a/ext/sgtelib/src/TrainingSet.hpp b/ext/sgtelib/src/TrainingSet.hpp
index 663e2e4a..530cdf55 100644
--- a/ext/sgtelib/src/TrainingSet.hpp
+++ b/ext/sgtelib/src/TrainingSet.hpp
@@ -213,8 +213,10 @@ namespace SGTELIB {
SGTELIB::bbo_t get_bbo ( int j) const { check_ready(); return _bbo[j]; };
double get_X_scaling_a ( int j) const { check_ready(); return _X_scaling_a[j]; };
+ double get_X_scaling_b ( int j) const { check_ready(); return _X_scaling_b[j]; };
double get_Z_scaling_a ( int j) const { check_ready(); return _Z_scaling_a[j]; };
+ double get_Z_scaling_b ( int j) const { check_ready(); return _Z_scaling_b[j]; };
// Return the design matrix
const SGTELIB::Matrix & get_matrix_Xs ( void ) const { check_ready(); return _Xs; };
diff --git a/interfaces/CInterface/CMakeLists.txt b/interfaces/CInterface/CMakeLists.txt
index 886cc6ac..7714267a 100644
--- a/interfaces/CInterface/CMakeLists.txt
+++ b/interfaces/CInterface/CMakeLists.txt
@@ -12,26 +12,26 @@ set(
)
-#
-# Build
+#
+# Build
#
add_library(
- nomadCInterface
+ nomadCInterface
SHARED ${INTERFACE_SOURCES}
)
target_include_directories(
- nomadCInterface
+ nomadCInterface
PUBLIC
$
$
)
target_link_libraries(
- nomadCInterface
- PUBLIC
- nomadAlgos
- nomadUtils
+ nomadCInterface
+ PUBLIC
+ nomadAlgos
+ nomadUtils
nomadEval
)
@@ -49,15 +49,15 @@ if(OpenMP_CXX_FOUND)
)
endif()
-if (NOT WIN32)
+if (NOT WIN32)
target_link_libraries(
- nomadCInterface
+ nomadCInterface
PRIVATE m
)
endif()
set_target_properties(
- nomadCInterface
+ nomadCInterface
PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
VERSION "${NOMAD_VERSION}"
@@ -66,7 +66,7 @@ set_target_properties(
)
-#
+#
# Install binary and header
#
install(
diff --git a/interfaces/CInterface/NomadStdCInterface.cpp b/interfaces/CInterface/NomadStdCInterface.cpp
index 8cec6c98..0c913a27 100644
--- a/interfaces/CInterface/NomadStdCInterface.cpp
+++ b/interfaces/CInterface/NomadStdCInterface.cpp
@@ -44,163 +44,359 @@
/* */
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*---------------------------------------------------------------------------------*/
-#include "../CInterface/NomadStdCInterface.h"
-
-#include "../Algos/EvcInterface.hpp"
-#include "../Cache/CacheBase.hpp"
-#include "../Math/RNG.hpp"
-#include "../Nomad/nomad.hpp"
-#include "../Param/AllParameters.hpp"
-#include "../Type/EvalSortType.hpp"
-#include "../Type/DirectionType.hpp"
-#include "../Type/LHSearchType.hpp"
-#include "../Type/SgtelibModelFeasibilityType.hpp"
-#include "../Type/SgtelibModelFormulationType.hpp"
-
-#include
+#include "NomadStdCInterface.h"
+
+#include "Algos/EvcInterface.hpp"
+#include "Cache/CacheBase.hpp"
+#include "Math/RNG.hpp"
+#include "Nomad/nomad.hpp"
+#include "Param/AllParameters.hpp"
+#include "Type/DirectionType.hpp"
+#include "Type/DMultiMadsSearchStrategyType.hpp"
+#include "Type/EvalSortType.hpp"
+#include "Type/LHSearchType.hpp"
+#include "Type/SgtelibModelFeasibilityType.hpp"
+#include "Type/SgtelibModelFormulationType.hpp"
+
+#include
#include
struct NomadProblemInfo
{
-
// parameters of the problem
std::shared_ptr p;
- // pointer to the black box function, whose arguments are:
- // nb_inputs: number of blackbox inputs
- // bb_inputs: array of bb_inputs
- // nb_outputs: number of blackbox outputs
- // bb_outputs: array of bb_outputs
- // count_eval: set to true if the evaluation has to be counted.
+ // pointer to the blackbox function, whose arguments are:
+ // - nb_inputs: number of blackbox inputs
+ // - bb_inputs: array of bb_inputs
+ // - nb_outputs: number of blackbox outputs
+ // - bb_outputs: array of bb_outputs
+ // - count_eval: set to true if the evaluation has to be counted.
// must return true if works, otherwise false.
// WARNING: all arrays must be allocated before and deallocated after.
Callback_BB_single bb_single;
- // TODO function of blocks of inputs
- // bool* (*bb_multiple)(int, int, double**, int double**)
+ // pointer to the black box function (evaluation per block), whose arguments are:
+ // - block_size: size of the block
+ // - nb_inputs: number of blackbox inputs
+ // - bb_inputs: array of bb_inputs of size block_size * nb_inputs
+ // - nb_outputs: number of blackbox outputs
+ // - bb_outputs: array of bb_outputs of size block_size * nb_outputs
+ // - count_eval: array of bool of size block_size,
+ // set to true if the evaluation for an element
+ // of the block has to be counted
+ // - eval_ok: array of bool of size block_size,
+ // set to true if the evaluation for an element of the block
+ // has succeeded, false otherwise.
+ // WARNING: all arrays must be allocated before and deallocated after.
+ Callback_BB_block bb_block;
int nb_inputs; // number of inputs
int nb_outputs; // number of outputs
};
+struct NomadResultInfo
+{
+ int nb_inputs;
+ int nb_outputs;
+ int nb_solutions;
+ bool feasible_solutions_found;
+ double *solutions_inputs;
+ double *solutions_outputs;
+};
+
+// NomadProblem API functions
+
NomadProblem createNomadProblem(
- Callback_BB_single bb_single, // black box function
- int nb_inputs, // number of inputs
- int nb_outputs) // number of outputs
+ Callback_BB_single bb_single, // blackbox function
+ Callback_BB_block bb_block, // blackbox function (evaluation per block)
+ const int nb_inputs, // number of inputs
+ const int nb_outputs) // number of outputs
{
// check inputs; redundant but no choice
- if (nb_inputs < 1 || nb_outputs < 1 || bb_single == nullptr)
+ if (nb_inputs < 1 || nb_outputs < 1 || (bb_single == nullptr))
{
return nullptr;
}
- NomadProblem retval = new NomadProblemInfo;
+ auto retval = new(std::nothrow) NomadProblemInfo;
+ if (retval == nullptr)
+ return nullptr;
retval->bb_single = bb_single;
+ retval->bb_block = bb_block;
retval->nb_inputs = nb_inputs;
retval->nb_outputs = nb_outputs;
- retval->p = std::make_shared();
+ try
+ {
+ retval->p = std::make_shared();
+ }
+ catch (std::exception& e)
+ {
+ delete retval;
+ return nullptr;
+ }
return retval;
}
-void freeNomadProblem(NomadProblem nomad_problem)
+void freeNomadProblem(const NomadProblem nomad_problem)
{
- nomad_problem->bb_single = nullptr;
- nomad_problem->p = nullptr;
+ if (nomad_problem == nullptr)
+ return;
+
+ delete nomad_problem;
}
-bool addNomadParam(NomadProblem nomad_problem, char *keyword_value_pair)
+bool addNomadParam(const NomadProblem nomad_problem,
+ const char *keyword_value_pair)
{
- nomad_problem->p->readParamLine(std::string(keyword_value_pair));
+ if (nomad_problem == nullptr)
+ return false;
+
+ try
+ {
+ nomad_problem->p->readParamLine(std::string(keyword_value_pair));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
return true;
}
-bool addNomadValParam(NomadProblem nomad_problem, char *keyword, int value)
+bool addNomadValParam(const NomadProblem nomad_problem,
+ const char *keyword,
+ const int value)
{
- nomad_problem->p->setAttributeValue(std::string(keyword), value);
+ if (nomad_problem == nullptr)
+ return false;
+
+ try
+ {
+ nomad_problem->p->setAttributeValue(std::string(keyword), value);
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
return true;
}
-bool addNomadDoubleParam(NomadProblem nomad_problem, char *keyword, double value)
+bool addNomadDoubleParam(const NomadProblem nomad_problem,
+ const char *keyword,
+ const double value)
{
- nomad_problem->p->setAttributeValue(std::string(keyword), NOMAD::Double(value));
+ if (nomad_problem == nullptr)
+ return false;
+
+ try
+ {
+ nomad_problem->p->setAttributeValue(std::string(keyword), NOMAD::Double(value));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
return true;
}
-bool addNomadBoolParam(NomadProblem nomad_problem, char *keyword, bool value)
+bool addNomadBoolParam(const NomadProblem nomad_problem,
+ const char *keyword,
+ const bool value)
{
- nomad_problem->p->setAttributeValue(std::string(keyword), value);
+ if (nomad_problem == nullptr)
+ return false;
+
+ try
+ {
+ nomad_problem->p->setAttributeValue(std::string(keyword), value);
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
return true;
}
-bool addNomadStringParam(NomadProblem nomad_problem, char *keyword, char *param_str)
+bool addNomadStringParam(const NomadProblem nomad_problem,
+ const char *keyword,
+ const char *param_str)
{
+ if (nomad_problem == nullptr)
+ return false;
+
// particular values
if (std::string(keyword) == "BB_INPUT_TYPE")
{
- nomad_problem->p->getPbParams()->setAttributeValue("BB_INPUT_TYPE",
- NOMAD::stringToBBInputTypeList(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->getPbParams()->setAttributeValue("BB_INPUT_TYPE",
+ NOMAD::stringToBBInputTypeList(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "BB_OUTPUT_TYPE")
{
- nomad_problem->p->getEvalParams()->setAttributeValue("BB_OUTPUT_TYPE",
- NOMAD::stringToBBOutputTypeList(std::string(param_str)));
- }
- else if (std::string(keyword) == "EVAL_QUEUE_SORT")
- {
- nomad_problem->p->getEvalParams()->setAttributeValue("EVAL_QUEUE_SORT",
- NOMAD::stringToEvalSortType(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->getEvalParams()->setAttributeValue("BB_OUTPUT_TYPE",
+ NOMAD::stringToBBOutputTypeList(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "DIRECTION_TYPE")
{
- nomad_problem->p->setAttributeValue("DIRECTION_TYPE", NOMAD::stringToDirectionType(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->setAttributeValue("DIRECTION_TYPE", NOMAD::stringToDirectionType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "DIRECTION_TYPE_SECONDARY_POLL")
{
- nomad_problem->p->setAttributeValue("DIRECTION_TYPE_SECONDARY_POLL", NOMAD::stringToDirectionType(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->setAttributeValue("DIRECTION_TYPE_SECONDARY_POLL", NOMAD::stringToDirectionType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
+ }
+ else if (std::string(keyword) == "DISPLAY_STATS")
+ {
+ try
+ {
+ nomad_problem->p->getDispParams()->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
+ }
+ else if (std::string(keyword) == "DMULTIMADS_NM_STRATEGY")
+ {
+ try
+ {
+ nomad_problem->p->setAttributeValue("DMULTIMADS_NM_STRATEGY",
+ NOMAD::stringToDMultiMadsNMSearchType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
+ }
+ else if (std::string(keyword) == "DMULTIMADS_QUAD_MODEL_STRATEGY")
+ {
+ try
+ {
+ nomad_problem->p->setAttributeValue("DMULTIMADS_QUAD_MODEL_STRATEGY",
+ NOMAD::stringToDMultiMadsQuadSearchType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
+ }
+ else if (std::string(keyword) == "EVAL_QUEUE_SORT")
+ {
+ try
+ {
+ nomad_problem->p->getEvalParams()->setAttributeValue("EVAL_QUEUE_SORT",
+ NOMAD::stringToEvalSortType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "LH_SEARCH")
{
- nomad_problem->p->getRunParams()->setAttributeValue("LH_SEARCH", NOMAD::LHSearchType(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->getRunParams()->setAttributeValue("LH_SEARCH", NOMAD::LHSearchType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "SGTELIB_MODEL_FEASIBILITY")
{
- nomad_problem->p->setAttributeValue("SGTELIB_MODEL_FEASIBILITY",
- NOMAD::stringToSgtelibModelFeasibilityType(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->setAttributeValue("SGTELIB_MODEL_FEASIBILITY",
+ NOMAD::stringToSgtelibModelFeasibilityType(std::string(param_str)));
+ }
+ catch (std::exception&e )
+ {
+ return false;
+ }
}
else if (std::string(keyword) == "SGTELIB_MODEL_FORMULATION")
{
- nomad_problem->p->setAttributeValue("SGTELIB_MODEL_FORMULATION",
- NOMAD::stringToSgtelibModelFormulationType(std::string(param_str)));
- }
- else if (std::string(keyword) == "DISPLAY_STATS")
- {
- nomad_problem->p->getDispParams()->setAttributeValue("DISPLAY_STATS", NOMAD::ArrayOfString(std::string(param_str)));
+ try
+ {
+ nomad_problem->p->setAttributeValue("SGTELIB_MODEL_FORMULATION",
+ NOMAD::stringToSgtelibModelFormulationType(std::string(param_str)));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
// other values
else
{
- nomad_problem->p->setAttributeValue(std::string(keyword), std::string(param_str));
+ try
+ {
+ nomad_problem->p->setAttributeValue(std::string(keyword), std::string(param_str));
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
}
return true;
}
-bool addNomadArrayOfDoubleParam(NomadProblem nomad_problem, char *keyword, double *array_param)
+bool addNomadArrayOfDoubleParam(const NomadProblem nomad_problem,
+ const char *keyword,
+ const double *array_param)
{
+ if (nomad_problem == nullptr)
+ return false;
+
NOMAD::ArrayOfDouble param(nomad_problem->nb_inputs);
- for (size_t i = 0; i < (size_t)nomad_problem->nb_inputs; ++i)
+ for (size_t i = 0; i < (size_t)nomad_problem->nb_inputs; ++i)
{
param[i] = array_param[i];
}
- nomad_problem->p->setAttributeValue(std::string(keyword), param);
+ try
+ {
+ nomad_problem->p->setAttributeValue(std::string(keyword), param);
+ }
+ catch (std::exception& e)
+ {
+ return false;
+ }
return true;
}
// Solve the problem
-// Definition of a specific evaluator for C interface
-class CInterfaceEval : public NOMAD::Evaluator
+// Definition of specific evaluators for C interface
+class CInterfaceEvalSingle : public NOMAD::Evaluator
{
private:
Callback_BB_single _bb_single;
@@ -211,12 +407,12 @@ class CInterfaceEval : public NOMAD::Evaluator
public:
// Constructor
- CInterfaceEval(std::shared_ptr evalParams,
- Callback_BB_single bb_single,
- int nbInputs,
- int nbOutputs,
- bool hasSgte,
- NomadUserDataPtr user_data_ptr)
+ CInterfaceEvalSingle(const std::shared_ptr& evalParams,
+ Callback_BB_single bb_single,
+ const int nbInputs,
+ const int nbOutputs,
+ const bool hasSgte,
+ NomadUserDataPtr user_data_ptr)
: NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB),
_bb_single(bb_single),
_nbInputs(nbInputs),
@@ -232,16 +428,91 @@ class CInterfaceEval : public NOMAD::Evaluator
}
//Destructor
- ~CInterfaceEval() {}
+ ~CInterfaceEvalSingle() override = default;
bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override
{
bool eval_ok = false;
- size_t n = x.size();
+ auto bb_inputs = new double[_nbInputs];
+ auto bb_outputs = new double[_nbOutputs];
+
+ // collect the inputs parameters
+ for (size_t i = 0; i < (size_t)_nbInputs; ++i)
+ {
+ bb_inputs[i] = x[i].todouble();
+ }
+
+ try
+ {
+ // call function
+ eval_ok = _bb_single(_nbInputs, bb_inputs, _nbOutputs, bb_outputs, &countEval, _data_user_ptr);
- double *bb_inputs = new double[_nbInputs];
- double *bb_outputs = new double[_nbOutputs];
+ // collect outputs parameters
+ std::string bbo;
+ for (size_t i = 0; i < (size_t)_nbOutputs; ++i)
+ {
+ bbo += std::to_string(bb_outputs[i]) + " ";
+ }
+ x.setBBO(bbo,_bbOutputTypeList, _evalType);
+ }
+ catch (std::exception &e)
+ {
+ std::string err("Exception: ");
+ err += e.what();
+ throw std::logic_error(err);
+ }
+
+ delete[] bb_inputs;
+ delete[] bb_outputs;
+
+ return eval_ok;
+ }
+};
+
+class CInterfaceEvalBlock : public NOMAD::Evaluator
+{
+private:
+ Callback_BB_single _bb_single;
+ Callback_BB_block _bb_block;
+ NomadUserDataPtr _data_user_ptr;
+ int _nbInputs;
+ int _nbOutputs;
+ bool _hasSgte;
+
+public:
+ // Constructor
+ CInterfaceEvalBlock(const std::shared_ptr& evalParams,
+ Callback_BB_single bb_single,
+ Callback_BB_block bb_block,
+ const int nbInputs,
+ const int nbOutputs,
+ const bool hasSgte,
+ NomadUserDataPtr user_data_ptr)
+ : NOMAD::Evaluator(evalParams, NOMAD::EvalType::BB),
+ _bb_single(bb_single),
+ _bb_block(bb_block),
+ _nbInputs(nbInputs),
+ _nbOutputs(nbOutputs),
+ _hasSgte(hasSgte),
+ _data_user_ptr(user_data_ptr)
+ {
+ if (_hasSgte)
+ {
+ std::cerr << "Warning: Surrogate evaluations are not currently supported." << std::endl;
+ _hasSgte = false;
+ }
+ }
+
+ //Destructor
+ ~CInterfaceEvalBlock() override = default;
+
+ bool eval_x(NOMAD::EvalPoint &x, const NOMAD::Double &hMax, bool &countEval) const override
+ {
+ bool eval_ok = false;
+
+ auto bb_inputs = new double[_nbInputs];
+ auto bb_outputs = new double[_nbOutputs];
// collect the inputs parameters
for (size_t i = 0; i < (size_t)_nbInputs; ++i)
@@ -255,7 +526,7 @@ class CInterfaceEval : public NOMAD::Evaluator
eval_ok = _bb_single(_nbInputs, bb_inputs, _nbOutputs, bb_outputs, &countEval, _data_user_ptr);
// collect outputs parameters
- std::string bbo("");
+ std::string bbo;
for (size_t i = 0; i < (size_t)_nbOutputs; ++i)
{
bbo += std::to_string(bb_outputs[i]) + " ";
@@ -274,139 +545,213 @@ class CInterfaceEval : public NOMAD::Evaluator
return eval_ok;
}
+
+ std::vector eval_block(std::vector> &block,
+ const NOMAD::Double& hMax,
+ std::vector &countEval) const override
+ {
+ const int block_size = (int)block.size();
+ std::vector evalOk(block_size, false);
+
+ auto bb_inputs = new double[_nbInputs * block_size];
+ auto bb_outputs = new double[_nbOutputs * block_size];
+
+ // collect the inputs parameters
+ for (size_t index = 0; index < block_size; ++index)
+ {
+ const auto& x = block[index];
+ for (size_t i = 0; i < (size_t)_nbInputs; ++i)
+ {
+ bb_inputs[index * _nbInputs + i] = x->operator[](i).todouble();
+ }
+ }
+
+ auto eval_ok = new bool[block_size];
+ auto count_eval = new bool[block_size];
+
+ try
+ {
+ // call function
+ _bb_block(block_size, _nbInputs, bb_inputs,
+ _nbOutputs, bb_outputs,
+ count_eval, eval_ok,
+ _data_user_ptr);
+
+ // collect outputs parameters
+ for (size_t index = 0; index < block_size; ++index)
+ {
+ std::string bbo;
+ for (size_t i = 0; i < (size_t)_nbOutputs; ++i)
+ {
+ bbo += std::to_string(bb_outputs[index * _nbOutputs + i]) + " ";
+ }
+ block[index]->setBBO(bbo, _bbOutputTypeList, _evalType);
+ }
+
+ // Set evalOk and countEval
+ for (size_t index = 0; index < block_size; ++index)
+ {
+ evalOk[index] = eval_ok[index];
+ countEval[index] = count_eval[index];
+ }
+ }
+ catch (std::exception &e)
+ {
+ std::string err("Exception: ");
+ err += e.what();
+ throw std::logic_error(err);
+ }
+
+
+ delete[] bb_inputs;
+ delete[] bb_outputs;
+ delete[] eval_ok;
+ delete[] count_eval;
+
+ return evalOk;
+ }
};
-bool solveNomadProblem(NomadProblem nomad_problem,
- int nb_starting_points,
- double *x0s,
- bool *exists_feas_sol,
- double *bb_best_x_feas,
- double *bb_best_feas_outputs,
- bool *exists_inf_sol,
- double *bb_best_x_inf,
- double *bb_best_inf_outputs,
- NomadUserDataPtr data_user_ptr)
+
+int solveNomadProblem(const NomadResult result,
+ const NomadProblem nomad_problem,
+ const int nb_starting_points,
+ const double *x0s,
+ NomadUserDataPtr data_user_ptr)
{
- if ((nb_starting_points < 1) || !x0s || !exists_feas_sol || !bb_best_x_feas || !bb_best_feas_outputs || !exists_inf_sol || !bb_best_x_inf || !bb_best_inf_outputs)
+ if ((nb_starting_points < 1) || !x0s || !result || !nomad_problem)
{
std::cerr << "All parameters must not be null" << std::endl;
- return 1;
+ return -7;
}
// Configure main parameters
nomad_problem->p->getPbParams()->setAttributeValue("DIMENSION", nomad_problem->nb_inputs);
// starting points
- if (x0s != nullptr) {
- NOMAD::ArrayOfPoint start_x0s;
- for (size_t pt_index = 0; pt_index < (size_t)nb_starting_points; ++pt_index)
+ NOMAD::ArrayOfPoint start_x0s;
+ for (size_t pt_index = 0; pt_index < (size_t)nb_starting_points; ++pt_index)
+ {
+ NOMAD::Point start_x0(nomad_problem->nb_inputs);
+ for (size_t i = 0; i < (size_t)nomad_problem->nb_inputs; ++i)
{
- NOMAD::Point start_x0(nomad_problem->nb_inputs);
- for (size_t i = 0; i < (size_t)nomad_problem->nb_inputs; ++i)
- {
- start_x0[i] = x0s[i + pt_index * nomad_problem->nb_inputs];
- }
- start_x0s.push_back(start_x0);
+ start_x0[i] = x0s[i + pt_index * nomad_problem->nb_inputs];
}
- nomad_problem->p->setAttributeValue("X0", start_x0s);
+ start_x0s.push_back(start_x0);
}
+ nomad_problem->p->setAttributeValue("X0", start_x0s);
- // TODO : for the moment allow only one blackbox call.
- nomad_problem->p->getEvaluatorControlGlobalParams()->setAttributeValue("BB_MAX_BLOCK_SIZE", 1);
-
- // TODO: For the moment, let these attributes
+ // For the moment, do not allow warm-start.
nomad_problem->p->getRunParams()->setAttributeValue("HOT_RESTART_READ_FILES", false);
nomad_problem->p->getRunParams()->setAttributeValue("HOT_RESTART_WRITE_FILES", false);
nomad_problem->p->setAttributeValue("HOT_RESTART_ON_USER_INTERRUPT", false);
- // Initialization of main results
- *exists_feas_sol = false;
- *exists_inf_sol = false;
+ result->nb_inputs = 0;
+ result->nb_outputs = 0;
+ result->nb_solutions = 0;
+ result->feasible_solutions_found = false;
+ if (!result->solutions_inputs)
+ delete[] result->solutions_inputs;
+ if (!result->solutions_outputs)
+ delete[] result->solutions_outputs;
- auto bestFeasEvalPoint = std::make_shared();
- auto bestInfEvalPoint = std::make_shared