11 paraq::paraq(int _nprocs, const int _rank)
17 jobListInitialized = false;
20 void paraq::addRange(const string& paraid, char *range)
25 for( int pos=0; pos<strlen(range); pos++ )
26 if( range[pos] == ':' ) nargs++;
28 for(int i=0; i<3; i++) goodrange[i] = strtod(range, NULL);
30 goodrange[0] = strtod(strtok(range, ":"), NULL);
31 for(int i=0; i<nargs; i++) goodrange[i+1] = strtod(strtok(NULL, ":"), NULL);
34 addRange(paraid, goodrange[0], goodrange[1], goodrange[2]);
37 string paraq::rangeString()
39 stringstream rangestring;
41 for( map< string, vector<double*> >::iterator paraIt = rangeMap.begin(); paraIt != rangeMap.end(); ++paraIt )
42 if( paraIt->second.size() > 0 )
43 for( vector<double*>::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt)
44 rangestring << "-" << paraIt->first << (*rangeIt)[0] << "_" << (*rangeIt)[1] << "_" << (*rangeIt)[2];
46 for (vector< pair<string,string> >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit)
47 rangestring << "-" << linkit->first << "->" << linkit->second;
49 for( map<string,double>::iterator defIt = defaultPara.begin(); defIt != defaultPara.end(); ++defIt )
50 if( rangeMap.find(defIt->first) == rangeMap.end() ) {
51 bool linkedpara = false;
53 for (vector< pair<string,string> >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit)
54 if (linkit->first == defIt->first) {
60 rangestring << "-" << defIt->first << defIt->second;
63 return rangestring.str();
66 void paraq::addRange(const string& paraid, double min, double max, double step)
68 double *newrange = new double[3];
72 rangeMap[paraid].push_back( newrange );
74 for( double paraval = min; paraval <= max+0.5*step; paraval += step+(step==0) )
75 if( ! inParas(paraMap[paraid], paraval) ) paraMap[paraid].push_back( paraval );
77 uniqueAllParaIdsAdd(paraid);
80 bool paraq::inParas( vector<double>& paraVec, double& tofind )
82 for( vector<double>::iterator it = paraVec.begin(); it < paraVec.end(); ++it)
83 if( fabs(*it - tofind) < 0.0000000001 ) return true;
87 void paraq::initJobList()
89 if( ! jobListInitialized ) {
90 map<string,double> jobZero;
91 jobList.push_back( jobZero );
93 for( map< string, vector< double > >::iterator paraIt = paraMap.begin(); paraIt != paraMap.end(); ++paraIt )
94 while( jobList.begin()->find(paraIt->first) == jobList.begin()->end() ) {
95 for( vector<double>::iterator valIt = paraIt->second.begin(); valIt != paraIt->second.end(); ++valIt ) {
96 jobList.push_back( *jobList.begin() );
98 jobList.back()[paraIt->first] = *valIt;
100 /* also set linked parameters */
101 for (vector< pair<string,string> >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit)
102 if (linkit->second == paraIt->first)
103 jobList.back()[linkit->first] = *valIt;
105 jobList.erase( jobList.begin() );
107 jobListInitialized = true;
111 int paraq::nextParas()
113 if( thisjob == -1 ) {
120 if( jobList.begin()->size() == 0 ) return 0;
122 if( thisjob < jobList.size() ) return 1;
127 double& paraq::operator[] (string paraid) {
128 if( jobList[thisjob].find(paraid) != jobList[thisjob].end() ) {
129 return jobList[thisjob][paraid];
132 if( defaultPara.find(paraid) != defaultPara.end() ) {
133 return defaultPara[paraid];
136 cerr << "PARAQ: Parameter " << paraid << " does not exist!" << endl << flush;
140 int paraq::getTotalJobs() {
142 return jobList.size();
145 void paraq::uniqueAllParaIdsAdd(const string& paraid) {
146 for (vector<string>::iterator allparait = allParaIds.begin(); allparait != allParaIds.end(); ++allparait)
147 if ( *allparait == paraid )
150 allParaIds.push_back(paraid);
153 string paraq::getParaNames() {
154 stringstream paranames;
156 for (vector<string>::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait)
157 paranames << *parait << ":";
159 return paranames.str();
162 string paraq::getParaVals() {
163 stringstream paravals;
165 for (vector<string>::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) {
166 if ( parait != allParaIds.begin() )
168 paravals << (*this)[*parait];
171 return paravals.str();