24 garfn << key <<
".ci.gar";
26 ifstream in(garfn.str());
29 auto c = ar.unarchive_ex(
"c");
30 if(c!=19790923)
throw Error(
"Contours: *.ci.gar error!");
31 FT_N_XN = ex_to<lst>(ar.unarchive_ex(
"ftnxn"));
36 if(FT_N_XN.nops()<1)
return;
41 for(
int i=0; i<FT_N_XN.nops(); i++) ftnxn_vec.push_back(FT_N_XN.op(i));
45 cmd <<
"mkdir -p " << pid;
46 if(!
dir_exists(to_string(pid)))
auto rc = system(cmd.str().c_str());
50 fsofn << key <<
"F.so";
52 fsofn << pid <<
"F.so";
54 void* module = dlopen(fsofn.str().c_str(), RTLD_NOW);
55 if (module ==
nullptr) {
56 module = dlopen((
"./"+fsofn.str()).c_str(), RTLD_NOW);
57 if (module ==
nullptr) {
58 cerr <<
ErrColor <<
"Contours: could not open compiled module!" <<
RESET << endl;
59 cout <<
"dlerror(): " << dlerror() << endl;
67 GiNaC_Parallel(ftnxn_vec.size(), [&ftnxn_vec,
this,module](
int idx)->ex {
71 if(Verbose>5) cout <<
" λ: " << idx <<
" / " << ftnxn_vec.size() << flush;
72 auto ftnxn = ftnxn_vec[idx];
74 for(auto kv : Parameter) if(npara<kv.first) npara = kv.first;
77 for(auto kv : Parameter) {
78 paras[kv.first] = (dREAL)ex2q(kv.second);
79 plRepl.append(PL(kv.first)==kv.second);
82 auto ft = ftnxn.op(0);
87 cout <<
" λ: xSign>0 or CTLaMax<0, back to REAL mode!" << endl;
89 return lst{ ftnxn.op(1), 1979 };
92 int nvars = ex_to<numeric>(ftnxn.op(2)).to_int();
99 fname <<
"minF_"<<ftnxn.op(1);
103 fname <<
"minFM_"<<ftnxn.op(1);
105 if(fp==NULL || fp2==NULL) {
106 cerr <<
ErrColor <<
"Contours: fp==NULL/fp2==NULL" <<
RESET << endl;
107 cout <<
"dlerror(): " << dlerror() << endl;
115 cout <<
" λ: F>0 is Found, back to REAL mode!" << endl;
117 return lst{ ftnxn.op(1), 1979 };
124 cout <<
" λ: F<0 is Found, back to REAL mode!" << endl;
126 return lst{ ftnxn.op(1), 1979 };
131 dREAL max_df = -1, max_f;
132 for(
int i=0; i<nvars; i++) {
136 fname <<
"dirC_"<<ftnxn.op(1)<<
"_"<<i;
140 cout <<
"dlerror(): " << dlerror() << endl;
147 if(max_df<maxdf) max_df = maxdf;
150 for(
int i=0; i<nvars; i++) {
151 if(nlas[i] < 1) nlas[i] = 1;
152 else nlas[i] = 1/nlas[i];
156 for(
int i=0; i<nvars; i++) {
157 las.append(
q2ex(nlas[i]));
163 fname <<
"imgF_"<<ftnxn.op(1);
167 cout <<
"dlerror(): " << dlerror() << endl;
173 for(
int i=0; i<nvars+1; i++) UB[i] = 1;
179 if(res < -1E-5) laEnd = min;
184 cout <<
" λ: " <<
ErrColor <<
"too small lambda!" <<
RESET << endl;
188 if(laEnd-laBegin <= 0.01*laEnd)
break;
189 min = (laBegin + laEnd) / 2.0;
193 las.append(
q2ex(min));
196 cout <<
" λ: " <<
NN(las,3) << endl;
199 return lst{ ftnxn.op(1), las };
203 if(use_dlclose) dlclose(module);
208 if(pkey !=
"") garfn <<
"-" << pkey;
211 for(
auto &item : res) gar_res.append(item);
213 ar.archive_ex(gar_res,
"res");
214 ar.archive_ex(19790923,
"c");
215 ofstream out(garfn.str());
219 for(
auto &item : res) LambdaMap[item.op(0)] = item.op(1);
224 cmd <<
"rm -rf " << pid;
225 if(!
Debug)
auto rc = system(cmd.str().c_str());
class used to wrap error message
class to minimize a function using HookeJeeves
virtual dREAL FindMinimum(int nvars, FunctionType func, dREAL *PL=NULL, dREAL *las=NULL, dREAL *UB=NULL, dREAL *LB=NULL, dREAL *IP=NULL, bool compare0=false, int TryPTS=0, int SavePTS=0)=0
dREAL(* FunctionType)(int nvars, dREAL *x, dREAL *pl, dREAL *las)
void Contours(const string &key="", const string &pkey="")
Contours, note that here we need to provide the specific Parameter.
namespace for Numerical integration with Sector Decomposition method
const char * Color_HighLight
ex q2ex(__float128 num)
__float128 to ex
ex NN(ex expr, int digits)
the nuerical evaluation
map< string, bool > GiNaC_Parallel_RM
string now(bool use_date)
date/time string
map< string, int > GiNaC_Parallel_NP
bool dir_exists(string dir)
void set_precision(long prec, bool push)
int xSign(ex const expr)
the always sign for expr
exvector GiNaC_Parallel(int ntotal, std::function< ex(int)> f, const string &key)
GiNaC Parallel Evaluation using fork.