From 9dcd59ad6cbc42a66dc80f42b98276941248cfac Mon Sep 17 00:00:00 2001
From: Michal Kravcenko <michal.kravcenko@vsb.cz>
Date: Fri, 21 Sep 2018 14:22:13 +0200
Subject: [PATCH] FIX: desolver

---
 .../linux/linux_gcc_build_x64_debug_local.sh  |  6 ++--
 .../linux/linux_gcc_build_x64_debug_system.sh | 11 ++++++-
 .../windows/win_VS_build_x64_debug.bat        |  2 +-
 src/CMakeLists.txt                            | 33 ++++++++++---------
 src/General/ExprtkWrapper.cpp                 |  8 ++++-
 src/General/ExprtkWrapper.h                   |  2 +-
 src/Solvers/DESolver.cpp                      |  2 ++
 7 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/build_scripts/linux/linux_gcc_build_x64_debug_local.sh b/build_scripts/linux/linux_gcc_build_x64_debug_local.sh
index 72ef00bd..1f272757 100755
--- a/build_scripts/linux/linux_gcc_build_x64_debug_local.sh
+++ b/build_scripts/linux/linux_gcc_build_x64_debug_local.sh
@@ -13,7 +13,7 @@ BUILD_EXAMPLES=yes
 BUILD_TESTS=yes
 
 # Should we rebuild BOOST? (yes/no)
-REBUILD_BOOST=yes
+REBUILD_BOOST=no
 # Should we build the lib4neuro library? (yes)
 BUILD_LIB=yes
 
@@ -23,13 +23,13 @@ C_COMPILER="gcc"
 
 #**********************DO NOT CHANGE BEYOND THIS LINE****************************************
 export LINK_TYPE=static
-if [ ${DEPENDENCIES_LINK_TYPE} = "shared" ]
+if [ $DEPENDENCIES_LINK_TYPE = "shared" ]
 then
     export LINK_TYPE=shared
 fi
 
 CLEAN_AF=yes
-if [ ${CLEAN_AFTER} = "no" ]
+if [ $CLEAN_AFTER = "no" ]
 then
     CLEAN_AF=no
 fi
diff --git a/build_scripts/linux/linux_gcc_build_x64_debug_system.sh b/build_scripts/linux/linux_gcc_build_x64_debug_system.sh
index 8fcbdb15..0ab7e2f6 100755
--- a/build_scripts/linux/linux_gcc_build_x64_debug_system.sh
+++ b/build_scripts/linux/linux_gcc_build_x64_debug_system.sh
@@ -22,11 +22,17 @@ C_COMPILER="gcc"
 #**********************DO NOT CHANGE BEYOND THIS LINE****************************************
 
 LINK_TYPE=static
-if [ ${DEPENDENCIES_LINK_TYPE} = "shared" ]
+if [ $DEPENDENCIES_LINK_TYPE = "shared" ]
 then
     LINK_TYPE=shared
 fi
 
+CLEAN_AF=yes
+if [ $CLEAN_AFTER = "no" ]
+then
+    CLEAN_AF=no
+fi
+
 BUILD_ERROR_OCCURED=0
 
 RED='\033[0;31m'
@@ -103,6 +109,8 @@ then
 
 fi
 
+if [ ${CLEAN_AF} = "yes" ]
+then
 if [ $BUILD_LIB = "yes" ]
 then
     ./linux_clean_after_lib.sh
@@ -122,6 +130,7 @@ if [ $BUILD_SOMETHING_LIB = "yes" ]
 then
     ./linux_clean_garbage.sh
 fi
+fi
 
 
 if [ $BUILD_ERROR_OCCURED = "1" ]
diff --git a/build_scripts/windows/win_VS_build_x64_debug.bat b/build_scripts/windows/win_VS_build_x64_debug.bat
index 72beacb6..2071067f 100644
--- a/build_scripts/windows/win_VS_build_x64_debug.bat
+++ b/build_scripts/windows/win_VS_build_x64_debug.bat
@@ -127,7 +127,7 @@ IF "%CLEAN_AF%"=="yes" IF "%BUILD_LIB%"=="yes" call win_clean_after_lib.bat
 IF "%CLEAN_AF%"=="yes" IF "%BUILD_EXAMPLES%"=="yes" call win_clean_after_examples.bat
 IF "%CLEAN_AF%"=="yes" IF "%BUILD_TESTS%"=="yes" call win_clean_after_tests.bat
 IF "%CLEAN_AF%"=="yes" IF "%BUILD_SOMETHING_LIB%"=="yes"  call win_clean_garbage.bat
-rem exit 1
+exit 1
 
 
 :final_goto
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4c1c3367..85bd21f2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,21 +7,24 @@ if ("${BUILD_EXAMPLES}" STREQUAL "yes")
 endif ()
 
 if ("${BUILD_LIB}" STREQUAL "yes")
-    add_library(
-        exprtk_wrap
-
-        SHARED
-
-        General/ExprtkWrapper.cpp
-    )
+	add_library(
+        	exprtk_wrap
+		STATIC
+			General/ExprtkWrapper.cpp
+	)
 
-    target_include_directories(
-        exprtk_wrap
+	target_include_directories(
+		exprtk_wrap
 
-        PRIVATE
-        	${EXPRTK_INCLUDE_DIR}
+		PRIVATE
+	        	${EXPRTK_INCLUDE_DIR}
 			${Boost_INCLUDE_DIRS}
-    )
+	)
+
+	target_compile_options(
+		exprtk_wrap PRIVATE -fPIC
+	)
+	
 
 	target_link_libraries(
 		exprtk_wrap
@@ -33,15 +36,15 @@ if ("${BUILD_LIB}" STREQUAL "yes")
 	add_library(lib4neuro SHARED
 		Neuron/Neuron.cpp
 		Neuron/NeuronBinary.cpp
-        Neuron/NeuronConstant.cpp
+        	Neuron/NeuronConstant.cpp
 		Neuron/NeuronLinear.cpp
 		Neuron/NeuronLogistic.cpp        
 		Network/NeuralNetwork.cpp        
 		Network/NeuralNetworkSum.cpp        
 		NetConnection/ConnectionFunctionGeneral.cpp        
 		NetConnection/ConnectionFunctionIdentity.cpp        
-        LearningMethods/ParticleSwarm.cpp
-        LearningMethods/GradientDescent.cpp
+        	LearningMethods/ParticleSwarm.cpp
+        	LearningMethods/GradientDescent.cpp
 		DataSet/DataSet.cpp
 		ErrorFunction/ErrorFunctions.cpp
 		Solvers/DESolver.cpp
diff --git a/src/General/ExprtkWrapper.cpp b/src/General/ExprtkWrapper.cpp
index 7abf6859..1585b972 100644
--- a/src/General/ExprtkWrapper.cpp
+++ b/src/General/ExprtkWrapper.cpp
@@ -21,6 +21,8 @@ ExprtkWrapper::ExprtkWrapper() {
 
 ExprtkWrapper::ExprtkWrapper( std::string expression_string ) {
 
+    this->p_impl = new ExprtkWrapperImpl();
+
     this->p_impl->expression_str = expression_string;
 
     this->p_impl->symbol_table = new symbol_table_t( );
@@ -56,6 +58,9 @@ ExprtkWrapper::~ExprtkWrapper() {
         this->p_impl->parser = nullptr;
     }
 
+    delete this->p_impl;
+    this->p_impl = nullptr;
+
 }
 
 double ExprtkWrapper::eval(double x1, double x2, double x3, double x4) {
@@ -65,7 +70,8 @@ double ExprtkWrapper::eval(double x1, double x2, double x3, double x4) {
     this->p_impl->z = x3;
     this->p_impl->t = x4;
 
-    return this->p_impl->expression->value();
+    return this->p_impl->expression->value( );
+
 }
 
 double ExprtkWrapper::eval(std::vector<double> &p) {
diff --git a/src/General/ExprtkWrapper.h b/src/General/ExprtkWrapper.h
index 0b7f46d8..aefaff3e 100644
--- a/src/General/ExprtkWrapper.h
+++ b/src/General/ExprtkWrapper.h
@@ -66,7 +66,7 @@ private:
      * to isolate Exprtk dependency from header
      */
     class ExprtkWrapperImpl;
-    std::unique_ptr<ExprtkWrapperImpl> p_impl;
+    ExprtkWrapperImpl *p_impl;
 
 };
 
diff --git a/src/Solvers/DESolver.cpp b/src/Solvers/DESolver.cpp
index bfebaecf..05e3de1e 100644
--- a/src/Solvers/DESolver.cpp
+++ b/src/Solvers/DESolver.cpp
@@ -5,6 +5,7 @@
  * @date 22.7.18 -
  */
 
+#include <string>
 #include "DESolver.h"
 
 //TODO add support for multiple unknown functions
@@ -192,6 +193,7 @@ void DESolver::add_to_differential_equation( size_t equation_idx, MultiIndex &al
         throw std::invalid_argument("The supplied multi-index represents partial derivative of order higher than 2! (Valid degree is at most 2)\n");
     }
 
+
     /* retrieve indices of the variables according to which we perform the derivations ( applicable to any order, not just 2 or less )*/
     std::vector<size_t> partial_derivative_indices;
     partial_derivative_indices.reserve(derivative_degree);
-- 
GitLab