aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--methods/linmin/linmin.hpp24
-rw-r--r--methods/powell/powell_method.hpp38
2 files changed, 36 insertions, 26 deletions
diff --git a/methods/linmin/linmin.hpp b/methods/linmin/linmin.hpp
index fe5e58c..b542fba 100644
--- a/methods/linmin/linmin.hpp
+++ b/methods/linmin/linmin.hpp
@@ -26,19 +26,19 @@ namespace opt_utilities
func_adaptor(const func_adaptor&)
:func_obj<rT,rT>(),p1(),xi1(),pfoo(NULL_PTR)
{}
-
+
public:
/*
void set_origin(pT& p2)
{
p1=p2;
}
-
+
void set_direction(pT& xi2)
{
xi1=xi2;
}
-
+
void set_func_obj(func_obj<rT,pT>& foo)
{
pfoo=&foo;
@@ -47,20 +47,22 @@ namespace opt_utilities
func_adaptor(const pT& _p,const pT& _xi,const func_obj<rT,pT>& pf)
:p1(_p),xi1(_xi),pfoo(&pf)
{}
-
+
private:
func_obj<rT,rT>* do_clone()const
{
return new func_adaptor(*this);
}
-
+
rT do_eval(const rT& x)
{
//assert(p1.size()==xi1.size());
-
+
pT xt;
opt_eq(xt,p1);
-#pragma omp parallel for
+#ifdef _OPENMP
+#pragma omp parallel for
+#endif
for(size_t i=0;i<get_size(xt);++i)
{
//get_element(xt,i)+=x*get_element((pT)xi1,i);
@@ -72,7 +74,7 @@ namespace opt_utilities
//return x;
}
};
-
+
template<typename rT,typename pT>
void linmin(pT& p,pT& xi,rT& fret,func_obj<rT,pT>& func)
@@ -90,13 +92,15 @@ namespace opt_utilities
ax=0.;
xx=1.;
-
+
mnbrak(ax,xx,bx,fa,fx,fb,fadpt);
//cout<<xx<<endl;
fret=brent(ax,xx,bx,fadpt,TOL,xmin);
//cout<<xmin<<endl;
-#pragma omp parallel for
+#ifdef _OPENMP
+#pragma omp parallel for
+#endif
for(j=0;j<n;++j)
{
//get_element(xi,j)*=xmin;
diff --git a/methods/powell/powell_method.hpp b/methods/powell/powell_method.hpp
index 381ffe1..228a526 100644
--- a/methods/powell/powell_method.hpp
+++ b/methods/powell/powell_method.hpp
@@ -35,7 +35,7 @@ namespace opt_utilities
optimizer<rT,pT>* p_optimizer;
volatile bool bstop;
//typedef blitz::Array<rT,2> array2d_type;
-
+
const char* do_get_type_name()const
{
return "powell method";
@@ -43,7 +43,7 @@ namespace opt_utilities
private:
array1d_type start_point;
array1d_type end_point;
-
+
private:
int ncom;
array1d_type pcom_p;
@@ -58,7 +58,7 @@ namespace opt_utilities
return p_fo->eval(x);
}
-
+
private:
void clear_xi()
{
@@ -117,7 +117,9 @@ namespace opt_utilities
del=0.0;
for(i=0;i<n;++i)
{
-#pragma omp parallel for
+#ifdef _OPENMP
+#pragma omp parallel for
+#endif
for(j=0;j<n;++j)
{
//get_element(xit,j)=xi[j][i];
@@ -140,7 +142,9 @@ namespace opt_utilities
std::cerr<<"powell exceeding maximun iterations."<<std::endl;
return;
}
-#pragma omp parallel for
+#ifdef _OPENMP
+#pragma omp parallel for
+#endif
for(j=0;j<n;++j)
{
//get_element(ptt,j)=T(2.)*get_element(p,j)-get_element(pt,j);
@@ -158,21 +162,23 @@ namespace opt_utilities
if(t<T(0.))
{
linmin(p,xit,fret,*p_fo);
-#pragma omp parallel for
+#ifdef _OPENMP
+#pragma omp parallel for
+#endif
for(j=0;j<n;++j)
{
xi[j][ibig-1]=xi[j][n-1];
xi[j][n-1]=get_element(xit,j);
-
+
}
}
}
}
}
-
+
public:
-
+
powell_method()
:threshold(1e-4),xi(NULL_PTR),xi_1d(NULL_PTR)
{}
@@ -203,12 +209,12 @@ namespace opt_utilities
ncom=rhs.ncom;
threshold=rhs.threshold;
}
-
+
opt_method<rT,pT>* do_clone()const
{
return new powell_method<rT,pT>(*this);
}
-
+
void do_set_start_point(const array1d_type& p)
{
resize(start_point,get_size(p));
@@ -241,9 +247,9 @@ namespace opt_utilities
p_optimizer=&o;
p_fo=p_optimizer->ptr_func_obj();
}
-
-
-
+
+
+
pT do_optimize()
{
bstop=false;
@@ -257,14 +263,14 @@ namespace opt_utilities
xi[i][j]=(i==j)?1:0;
}
}
-
+
int iter=100;
opt_eq(end_point,start_point);
rT fret;
powell(end_point,threshold,iter,fret);
return end_point;
}
-
+
void do_stop()
{
bstop=true;