/* The statistical results of the day */ static void calc_uas_stats(struct module *mod, int interval) { tDBConn *pconn = NULL; if ((pconn = attach_conn(OMPDB, conf.server_addr, conf.server_port)) == NULL) { logRecord(LOG_ERR, "%s(%d): failed to get db conn\n", __FUNCTION__, __LINE__); return ; } sscanf(conf.output_db_addr, "%[^:]:%s", gds_ip, gds_port); logRecord(LOG_INFO, "%s(%d): gds ip:%s port:%s!", __FUNCTION__, __LINE__, gds_ip, gds_port); /* acquire user count */ mod->emp_record = dbi_query_long(pconn->conn, "count", "select count(*) from \"T_User\";"); if (mod->emp_record != 0) { mod->emp_array = calloc(mod->emp_record, STATS_UAS_SIZE); if (mod->emp_array == NULL) { logRecord(LOG_ERR, "%s(%d): calloc for emp_array error!\n", __FUNCTION__, __LINE__); detach_conn(pconn); return; } } calc_emp_uas_stats(mod, pconn->conn); set_uas_record(mod); detach_conn(pconn); return; }
static int set_uas_record(struct module *mod) { int j, k; char line[LEN_4096] = {0}; char tmp[LEN_2048] = {0}; ST_UAS *pe = NULL; tDBConn *pconn = NULL; if ((pconn = attach_conn(GDSDB, gds_ip, gds_port)) == NULL) { logRecord(LOG_ERR, "%s(%d): failed to get db conn\n", __FUNCTION__, __LINE__); return -1; } /* save collect data to output_db */ if (mod->emp_record != 0 && mod->emp_array != NULL) { pe = mod->emp_array; for (j = 0; j < mod->emp_record; j++) { memset(line, '\0', LEN_4096); sprintf(line, "insert into \"%s\"(", mod->table[0].table); for (k = 0; k < mod->n_col; k++) { memset(tmp, '\0', LEN_2048); sprintf(tmp, "\"%s\",", mod->info[k].hdr); strcat(line, tmp); } line[strlen(line) - 1] = ')'; strcat(line, "values("); memset(tmp, '\0', LEN_2048); sprintf(tmp, "'%lld','%s', '%lld','%lld','%lld','%d');", pe[j].sdr_id, pe[j].sdr_time, pe[j].sdr_num, pe[j].sdr_online_times, pe[j].sdr_offline_times, pe[j].sdr_active_flag); strcat(line, tmp); dbi_conn_queryf(pconn->conn, line); logRecord(LOG_DEBUG, "%s(%d):line->%s\n", __FUNCTION__, __LINE__, line); } } if (mod->emp_array) { free(mod->emp_array); mod->emp_array = NULL; } if (mod->amp_array) { free(mod->amp_array); mod->amp_array = NULL; } if (mod->ser_array) { free(mod->ser_array); mod->ser_array = NULL; } detach_conn(pconn); return 0; }
static int set_ccs_record(struct module *mod) { int j, k; char line[LEN_4096] = {0}; char tmp[LEN_2048] = {0}; char sdr_id_field[LEN_64] = { '\0' }; ST_CCS *pe = NULL; tDBConn *pconn = NULL; if ((pconn = attach_conn(GDSDB, gds_ip, gds_port)) == NULL) { logRecord(LOG_ERR, "%s(%d): failed to get db conn\n", __FUNCTION__, __LINE__); return -1; } /* save collect data to output_db */ if (mod->emp_record != 0 && mod->emp_array != NULL) { pe = mod->emp_array; for (j = 0; j < mod->emp_record; j++) { memset(line, '\0', LEN_4096); sprintf(line, "insert into \"%s\"(", mod->table[0].table); /* for (k = 0; k < mod->n_col; k++) { memset(tmp, '\0', LEN_2048); sprintf(tmp, "\"%s\",", mod->info[k].hdr); strcat(line, tmp); } */ /* EMP: sdr_id, not include sdr_amp_id */ snprintf( sdr_id_field, sizeof(sdr_id_field) - 1, "\"%s\",", mod->info[0].hdr ); strcat( line, sdr_id_field ); for ( k = 2; k < mod->n_col; k++ ) { memset( tmp, '\0', LEN_2048 ); snprintf( tmp, sizeof(tmp) - 1 , "\"%s\",", mod->info[k].hdr ); strncat( line, tmp, sizeof(line) - 1 ); } line[strlen(line) - 1] = ')'; strcat(line, "values("); memset(tmp, '\0', LEN_2048); sprintf(tmp, "'%lld','%s','%s','%lld','%lld','%lld','%lld','%lld','%lld','%lld',\ '%lld','%lld','%lld','%lld','%lld','%lld','%lld','%lld');", pe[j].sdr_id, pe[j].sdr_record_time, pe[j].sdr_time, pe[j].sdr_cyc_type, pe[j].sdr_ptt_time, pe[j].sdr_ptt_count, pe[j].sdr_audio_time, pe[j].sdr_audio_caller_time, pe[j].sdr_audio_callee_time, pe[j].sdr_audio_count, pe[j].sdr_audio_caller_count, pe[j].sdr_audio_callee_count, pe[j].sdr_video_time, pe[j].sdr_video_caller_time, pe[j].sdr_video_callee_time, pe[j].sdr_video_count, pe[j].sdr_video_caller_count, pe[j].sdr_video_callee_count); strcat(line, tmp); dbi_conn_queryf(pconn->conn, line); logRecord(LOG_DEBUG, "%s(%d):line->%s\n", __FUNCTION__, __LINE__, line); } }
static void log_uas_stats(ST_UAS *pe, long long mod_record) { int ct; logRecord(LOG_INFO, "%s|%s|%s|%s|%s|%s\n", uas_info[0].hdr, uas_info[1].hdr, uas_info[2].hdr, uas_info[3].hdr, uas_info[4].hdr, uas_info[5].hdr); for (ct = 0 ; ct < mod_record; ct++) { logRecord(LOG_INFO, "%ld|%s|%ld|%ld|%ld|%d\n", pe[ct].sdr_id, pe[ct].sdr_time, pe[ct].sdr_num, pe[ct].sdr_online_times, pe[ct].sdr_offline_times, pe[ct].sdr_active_flag); } }
vector<DictionaryRecord> DictionaryService::GetLogRecords(sqlite3_stmt* statement) const { vector<DictionaryRecord> logRecords; sqliteProvider->ExecuteReader(statement, [&](map<wstring, int> columnsIndexes) -> void { const unsigned char* word = sqlite3_column_text(statement, columnsIndexes[L"Sentence"]); int count = sqlite3_column_int(statement, columnsIndexes[L"Count"]); const unsigned char* json = sqlite3_column_text(statement, columnsIndexes[L"Json"]); int isForcedTranslation = sqlite3_column_int(statement, columnsIndexes[L"IsForcedTranslation"]); time_t createdDate = sqlite3_column_int64(statement, columnsIndexes[L"CreatedDate"]); time_t updatedDate = sqlite3_column_int64(statement, columnsIndexes[L"UpdatedDate"]); int isActive = sqlite3_column_int(statement, columnsIndexes[L"IsActive"]); DictionaryRecord logRecord( StringUtilities::GetUtf16StringFromChar((char*)word), isForcedTranslation == 1, count, StringUtilities::GetUtf16StringFromChar((char*)json), createdDate, updatedDate, isActive == 1); logRecords.push_back(logRecord); }); return logRecords; }
template<class... ARGS> void log(const LogLevel& logLevel, const ARGS&... args) const { if (this->level()<=logLevel && this->accept(logLevel)) { LogRecord logRecord(this,logLevel); logRecord.processAndPropagate(args...); } }
static void log_cds_stats(ST_CDS *pe, long long mod_record) { int ct; logRecord(LOG_INFO, "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n", cds_info[0].hdr, cds_info[1].hdr, cds_info[2].hdr, cds_info[3].hdr, cds_info[4].hdr, cds_info[5].hdr, cds_info[6].hdr, cds_info[7].hdr, cds_info[8].hdr, cds_info[9].hdr, cds_info[10].hdr, cds_info[11].hdr); for (ct = 0 ; ct < mod_record; ct++) { logRecord(LOG_INFO, "%ld|%s|%s|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld\n", pe[ct].sdr_id, pe[ct].sdr_record_time, pe[ct].sdr_time, pe[ct].sdr_date_flag, pe[ct].sdr_ptt_htime, pe[ct].sdr_ptt_hcount, pe[ct].sdr_call_htime, pe[ct].sdr_call_hcount, pe[ct].sdr_video_htime, pe[ct].sdr_video_hcount, pe[ct].sdr_audio_htime, pe[ct].sdr_audio_hcount); } }
static void log_ccs_stats(ST_CCS *pe, long long mod_record) { int ct; logRecord(LOG_INFO, "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n", ccs_info[0].hdr, ccs_info[1].hdr, ccs_info[2].hdr, ccs_info[3].hdr, ccs_info[4].hdr, ccs_info[5].hdr, ccs_info[6].hdr, ccs_info[7].hdr, ccs_info[8].hdr, ccs_info[9].hdr, ccs_info[10].hdr, ccs_info[11].hdr, ccs_info[12].hdr, ccs_info[13].hdr, ccs_info[14].hdr, ccs_info[15].hdr, ccs_info[16].hdr, ccs_info[17].hdr); for (ct = 0 ; ct < mod_record; ct++) { logRecord(LOG_INFO, "%ld|%s|%s|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%ld|%lld|%lld\n", pe[ct].sdr_id, pe[ct].sdr_record_time, pe[ct].sdr_time, pe[ct].sdr_cyc_type, pe[ct].sdr_ptt_time, pe[ct].sdr_ptt_count, pe[ct].sdr_audio_time, pe[ct].sdr_audio_caller_time, pe[ct].sdr_audio_callee_time, pe[ct].sdr_audio_count, pe[ct].sdr_audio_caller_count, pe[ct].sdr_audio_callee_count, pe[ct].sdr_video_time, pe[ct].sdr_video_caller_time, pe[ct].sdr_video_callee_time, pe[ct].sdr_video_count, pe[ct].sdr_video_caller_count, pe[ct].sdr_video_callee_count); } }
// log a message to remote server with a user token id given // for the remote server to fill in with user token details. am_status_t Log::rlog(ModuleId module, int remote_log_level, const char *user_sso_token, const char *format, ...) throw() { am_status_t status = AM_SUCCESS; char *logMsg = NULL; std::string logMessage; bool cookieEncoded = false; if (rmtLogSvc == NULL || !remoteInitialized) { status = AM_SERVICE_NOT_INITIALIZED; } else { std::va_list args; va_start(args, format); logMsg = PR_vsmprintf(format, args); logMessage = logMsg; if (logMsg != NULL) { if (logMsg[0] == '\0') { Log::log(Log::ALL_MODULES, Log::LOG_WARNING, "Log Record Message is empty"); return status; } try { LogRecord logRecord( static_cast<LogRecord::Level>(remote_log_level), logMessage); std::string userSSOToken = user_sso_token; cookieEncoded = userSSOToken.find('%') != std::string::npos; if (cookieEncoded) { userSSOToken = Http::decode(std::string(user_sso_token)); } logRecord.populateTokenDetails(userSSOToken); status = rmtLogSvc->sendLog("", logRecord, ""); } catch (std::exception& exs) { status = AM_FAILURE; } catch (...) { status = AM_FAILURE; } PR_smprintf_free(logMsg); } va_end(args); } return status; }
/* * Log url access audit message to remote audit log file. * */ am_status_t Log::doRemoteAuditLog(ModuleId module, int remote_log_level, const char *user_sso_token, const char *logMsg) { am_status_t status = AM_SUCCESS; std::string logMessage; bool cookieEncoded = false; if (rmtLogSvc == NULL || !remoteInitialized) { status = AM_SERVICE_NOT_INITIALIZED; } else { if (logMsg != NULL) { logMessage = logMsg; try { LogRecord logRecord( static_cast<LogRecord::Level>(remote_log_level), logMessage); std::string userSSOToken = user_sso_token; cookieEncoded = userSSOToken.find('%') != std::string::npos; if (cookieEncoded) { userSSOToken = Http::decode(std::string(user_sso_token)); } logRecord.populateTokenDetails(userSSOToken); status = rmtLogSvc->sendLog("", logRecord, ""); } catch (std::exception& exs) { status = AM_FAILURE; } catch (...) { status = AM_FAILURE; } } } return status; }
static void calc_amp_cds(struct module *mod, dbi_conn conn, int interval) { int ct = 0, st = 0; dbi_result result = 0; ST_CDS *pa = NULL; ST_CDS *pe = NULL; long long rst = 0; logRecord( LOG_INFO, "%s(%d): cal amp, interval:%d", __FUNCTION__, __LINE__, interval ); pa = (ST_CDS *)mod->amp_array; pe = (ST_CDS *)mod->emp_array; /* acquire omp uss stats */ pa[0].sdr_id = 0; strncpy(pa[0].sdr_amp_id, "0", sizeof(pa[0].sdr_amp_id) - 1); convert_time_to_string(statis.cur_time, pa[ct].sdr_record_time, 0); convert_time_to_string(statis.cur_time - 24*60*60, pa[ct].sdr_time, 1); if (interval == 0) { pa[0].sdr_date_flag = 0; } else if (interval == 7) { pa[0].sdr_date_flag = 1; } else { pa[0].sdr_date_flag = 2; } for (ct = 0; ct < mod->emp_record; ct++) { pa[0].sdr_ptt_htime += pe[ct].sdr_ptt_htime; pa[0].sdr_ptt_hcount += pe[ct].sdr_ptt_hcount; pa[0].sdr_call_htime += pe[ct].sdr_call_htime; pa[0].sdr_call_hcount += pe[ct].sdr_call_hcount; pa[0].sdr_video_htime += pe[ct].sdr_video_htime; pa[0].sdr_video_hcount += pe[ct].sdr_video_hcount; pa[0].sdr_audio_htime += pe[ct].sdr_audio_htime; pa[0].sdr_audio_hcount += pe[ct].sdr_audio_hcount; } st = 1; /* acquire amp uss stats */ result = dbi_conn_queryf(conn, "select ag_number from \"T_Agents\" order by ag_number"); if (result) { while(dbi_result_next_row(result)) { //pa[st].sdr_id = atoll(dbi_result_get_string(result, "ag_number")); strncpy( pa[st].sdr_amp_id, dbi_result_get_string(result, "ag_number"), sizeof(pa[st].sdr_amp_id) - 1 ); pa[st].sdr_amp_id[sizeof(pa[st].sdr_amp_id) - 1] = '\0'; convert_time_to_string(statis.cur_time, pa[st].sdr_record_time, 0); convert_time_to_string(statis.cur_time - 24*60*60, pa[st].sdr_time, 1); if (interval == 0) { pa[st].sdr_date_flag = 0; } else if (interval == 7) { pa[st].sdr_date_flag = 1; } else { pa[st].sdr_date_flag = 2; } st++; } dbi_result_free(result); } for (st = 1; st < mod->amp_record; st++) { /* result = dbi_conn_queryf(conn, "select e_id from \"T_Enterprise\" where \ e_ag_path like '%s%lld%s' order by e_id", "%", pa[st].sdr_id, "%"); */ result = dbi_conn_queryf(conn, "select e_id from \"T_Enterprise\" where \ e_ag_path like '%s%s%s' order by e_id", "%", pa[st].sdr_amp_id, "%"); if (result) { while(dbi_result_next_row(result)) { rst = dbi_result_get_longlong(result, "e_id"); for (ct = 0; ct < mod->emp_record; ct++) { if (rst == pe[ct].sdr_id) { pa[st].sdr_ptt_htime += pe[ct].sdr_ptt_htime; pa[st].sdr_ptt_hcount += pe[ct].sdr_ptt_hcount; pa[st].sdr_call_htime += pe[ct].sdr_call_htime; pa[st].sdr_call_hcount += pe[ct].sdr_call_hcount; pa[st].sdr_video_htime += pe[ct].sdr_video_htime; pa[st].sdr_video_hcount += pe[ct].sdr_video_hcount; pa[st].sdr_audio_htime += pe[ct].sdr_audio_htime; pa[st].sdr_audio_hcount += pe[ct].sdr_audio_hcount; break; } } } dbi_result_free(result); } } //log_cds_stats(pa, mod->amp_record); return; }
static void calc_emp_cds_stats(struct module *mod, dbi_conn conn) { int ct = 0; char dev_ip[LEN_32]; char dev_port[LEN_32]; dbi_result result = 0; ST_CDS *pe = NULL; tDBConn *pconn = NULL; pe = (ST_CDS *)mod->emp_array; /* acquire every enterprise id */ result = dbi_conn_queryf(conn, "select e_id from \"T_Enterprise\" order by e_id"); if (result) { while(dbi_result_next_row(result)) { pe[ct].sdr_id = dbi_result_get_longlong(result, "e_id"); convert_time_to_string(statis.cur_time, pe[ct].sdr_record_time, 0); convert_time_to_string(statis.cur_time - 24*60*60, pe[ct].sdr_time, 1); pe[ct].sdr_date_flag = 0; ct++; } dbi_result_free(result); } for (ct = 0; ct < mod->emp_record; ct++) { long long sdr_id = pe[ct].sdr_id; result = dbi_conn_queryf(conn, "select d_ip2 from \"T_Device\" where d_id = \ (select e_ss_id from \"T_Enterprise\" where e_id = %lld);", sdr_id); if (result) { while (dbi_result_next_row(result)) { memset(dev_ip, '\0', LEN_32); memset(dev_port, '\0', LEN_32); strcpy(dev_ip, dbi_result_get_string(result, "d_ip2")); strcpy(dev_port, "5432"); } dbi_result_free(result); } if ((pconn = attach_conn(SSDB, dev_ip, dev_port)) == NULL) { logRecord(LOG_ERR, "%s(%d): failed to get db conn\n", __FUNCTION__, __LINE__); continue; } pe[ct].sdr_ptt_htime = dbi_query_long(pconn->conn, "sum", "select sum(callsec) from \ \"cdr_%lld\" where endtime < %lld and (call_type = 3 or call_type = 4);", sdr_id, statis.cur_time); pe[ct].sdr_ptt_hcount = dbi_query_long(pconn->conn, "count", "select count(*) from \ \"cdr_%lld\" where endtime < %lld and (call_type = 3 or call_type = 4);", sdr_id, statis.cur_time); pe[ct].sdr_call_htime = 2 * dbi_query_long(pconn->conn, "sum", "select sum(callsec) from \ \"cdr_%lld\" where endtime < %lld and (call_type = 1 or call_type = 2);", sdr_id, statis.cur_time); pe[ct].sdr_call_hcount = 2 * dbi_query_long(pconn->conn, "count", "select count(*) from \ \"cdr_%lld\" where endtime < %lld and (call_type = 1 or call_type = 2);", sdr_id, statis.cur_time); pe[ct].sdr_video_htime = 2 * dbi_query_long(pconn->conn, "sum", "select sum(callsec) from \ \"cdr_%lld\" where endtime < %lld and call_type = 2;", sdr_id, statis.cur_time); pe[ct].sdr_video_hcount = 2 * dbi_query_long(pconn->conn, "count", "select count(*) from \ \"cdr_%lld\" where endtime < %lld and call_type = 2", sdr_id, statis.cur_time); pe[ct].sdr_audio_htime = 2 * dbi_query_long(pconn->conn, "sum", "select sum(callsec) from \ \"cdr_%lld\" where endtime < %lld and call_type = 1;", sdr_id, statis.cur_time); pe[ct].sdr_audio_hcount = 2 * dbi_query_long(pconn->conn, "count", "select count(*) from \ \"cdr_%lld\" where endtime < %lld and call_type = 1;", sdr_id, statis.cur_time); detach_conn(pconn); } //log_cds_stats(pe, mod->emp_record); return; }
static void calc_emp_uas_stats(struct module *mod, dbi_conn conn) { int ct = 0; char dev_ip[LEN_32]; char dev_port[LEN_32]; dbi_result result = 0; ST_UAS *pe = NULL; tDBConn *pconn = NULL; int user_status = -1; pe = (ST_UAS *)mod->emp_array; /* acquire every enterprise id */ result = dbi_conn_queryf(conn, "select u_number, u_e_id from \"T_User\" order by u_e_id"); if (result) { while(dbi_result_next_row(result)) { pe[ct].sdr_num = atoll(dbi_result_get_string(result, "u_number")); pe[ct].sdr_id = dbi_result_get_longlong(result, "u_e_id"); convert_time_to_string(statis.cur_time - 24*60*60, pe[ct].sdr_time, 1); ct++; } dbi_result_free(result); } logRecord(LOG_INFO, "%s(%d) uas start cal...", __FUNCTION__, __LINE__ ); for (ct = 0; ct < mod->emp_record; ct++) { long long sdr_id = pe[ct].sdr_id; long long sdr_num = pe[ct].sdr_num; result = dbi_conn_queryf(conn, "select d_ip2 from \"T_Device\" where d_id = \ (select e_ss_id from \"T_Enterprise\" where e_id = %lld);", sdr_id); if (result) { while (dbi_result_next_row(result)) { memset(dev_ip, '\0', LEN_32); memset(dev_port, '\0', LEN_32); strcpy(dev_ip, dbi_result_get_string(result, "d_ip2")); strcpy(dev_port, "5432"); } dbi_result_free(result); } if ((pconn = attach_conn(SSDB, dev_ip, dev_port)) == NULL) { logRecord(LOG_ERR, "%s(%d): failed to get SSdb conn, ssip(%s)-ssport(%s).\n", \ __FUNCTION__, __LINE__, dev_ip, dev_port ); continue; } pe[ct].sdr_online_times = dbi_query_long(pconn->conn, "count", "select count(*) \ from \"loginrecord_%lld\" where time between '%lld' and '%lld' \ and type = 1 and number = '%lld';", sdr_id, (statis.cur_time-24*60*60), statis.cur_time, sdr_num); pe[ct].sdr_offline_times = dbi_query_long(pconn->conn, "count", "select count(*) \ from \"loginrecord_%lld\" where time between '%lld' and '%lld' \ and type = 2 and number = '%lld';", sdr_id, (statis.cur_time-24*60*60), statis.cur_time, sdr_num); /* if (pe[ct].sdr_online_times != 0 || pe[ct].sdr_offline_times != 0) pe[ct].sdr_active_flag = 1; */ if ( (pe[ct].sdr_online_times > 0) || (pe[ct].sdr_offline_times > 0) ) { pe[ct].sdr_active_flag = 1; } else { /* not find yesterday user status, * need look up user last status in loginrecord_e_id, */ user_status = dbi_query_long( pconn->conn, "type", "select type \ from \"loginrecord_%lld\" where number='%lld' order by time desc limit 1;", \ sdr_id, sdr_num ); if ( user_status == USER_ONLINE ) { pe[ct].sdr_active_flag = USER_STATUS_ACTIVITY; } else if ( user_status == USER_OFFLINE ) { pe[ct].sdr_active_flag = USER_STATUS_INACTIVITY; } else { pe[ct].sdr_active_flag = USER_STATUS_INACTIVITY; } } detach_conn(pconn); } logRecord(LOG_INFO, "%s(%d) uas end cal...", __FUNCTION__, __LINE__ ); //log_uas_stats(pe, mod->emp_record); return; }
int main(int argc, char **argv) { USING_NAMESPACE_ACADO const double KKT_tol = 1e-6; //READ THE DEMO LENGTHS & nBF FROM THE COMMAND LINE std::deque<std::string> args(argv + 1, argv + argc + !argc); const int nBF=atoi(args[0].c_str()); args.pop_front(); const int nD=(int)args.size(); int nS=0; for(int i=0; i<nD;i++) nS+=atoi(args[i].c_str()); //READ DATA std::string path=DATA_PATH; Matrix D = readFromFile((path+"demos.dat").c_str()); //d(:,0)=time, d(:,1)=x, d(:,2)=dx, d(:,3)=ddx; Vector pI = readFromFile((path+"initial_guess.dat").c_str()); Matrix A = readFromFile((path+"inequality_constraint_matrix.dat").c_str()); Vector b = readFromFile((path+"inequality_constraint_vector.dat").c_str()); Matrix S = readFromFile((path+"scale_matrix.dat").c_str()); //RELEVANT INDEX SETS std::vector<std::vector<int> > d_ind=getDemoInd(args); std::vector<int> a_ind=getAInd(nBF,nD); std::vector<int> b_ind=getBInd(nBF,nD); std::vector<std::vector<int> > w_ind=getWInd(nBF,nD); std::vector<int> r_ind=getRInd(nBF,nD); std::vector<int> c_ind=getCInd(nBF,nD); //PARAMETER & OBJECTIVE FUNCTION Parameter p(2*nD+nBF*(2+nD)+1,1); Matrix BM(nS,2*nD+nBF*(2+nD)+1); BM.setZero(); Expression B(BM); double t,x,dx; for (int d=0; d<nD; d++) for(int s=0;s<(int)d_ind[d].size();s++) { t=D(d_ind[d][s],0); x=D(d_ind[d][s],1); dx=D(d_ind[d][s],2); B(d_ind[d][s],a_ind[d])=x; B(d_ind[d][s],b_ind[d])=dx; for(int n=0;n<nBF;n++){ B(d_ind[d][s],w_ind[d][n])=(-0.5*(t-p(c_ind[n])*S(c_ind[n],c_ind[n])).getPowInt(2)/(p(r_ind[n])*p(r_ind[n])*S(r_ind[n],r_ind[n])*S(r_ind[n],r_ind[n]))).getExp(); // std::cout<<d<<std::endl; //std::cout<< S(r_ind[d],r_ind[d])<<std::endl; } } Expression f; f<<B*S*p-D.getCol(3); Expression ez(nS); for (int i=0; i<nS; i++) ez(i)=p(2*nD+nBF*(2+nD)); Vector e(nS); e.setAll(1.0); Vector null(nS); null.setAll(0.0); NLP nlp; nlp.minimize(p(2*nD+nBF*(2+nD))); nlp.subjectTo(f - ez <= null); nlp.subjectTo(f + ez >= null); //nlp.subjectTo(A*S*p <= b); //ALGORITHM ParameterEstimationAlgorithm algorithm(nlp); VariablesGrid initial_guess(2*nD+nBF*(2+nD)+1,0.0,0.0,1 ); initial_guess.setVector( 0,S.getInverse()*pI ); algorithm.initializeParameters(initial_guess); // OPTIONS algorithm.set( KKT_TOLERANCE, KKT_tol); algorithm.set( ABSOLUTE_TOLERANCE, 1e-4); algorithm.set( PRINTLEVEL,HIGH); algorithm.set( MAX_NUM_ITERATIONS, 2000 ); algorithm.set (PRINT_COPYRIGHT, NO); // algorithm.set (PRINT_SCP_METHOD_PROFILE, YES); algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN ); algorithm.set(GLOBALIZATION_STRATEGY, GS_LINESEARCH ); algorithm.set(LINESEARCH_TOLERANCE, 1e-2 ); algorithm.set(INFEASIBLE_QP_HANDLING,IQH_RELAX_L2); algorithm.set(FEASIBILITY_CHECK,BT_TRUE); // LOGGING LogRecord logRecord( LOG_AT_EACH_ITERATION,(path+"log.dat").c_str(),PS_PLAIN); logRecord << LOG_OBJECTIVE_VALUE; algorithm << logRecord; //SOLVING double clock1 = clock(); algorithm.solve(); double clock2 = clock(); Vector solution; algorithm.getParameters(solution); // solution.print("optimal solution \n"); solution.printToFile((path+"solution.dat").c_str(),"",PS_PLAIN); printf("\n computation time (ACADO) = %.16e \n", (clock2-clock1)/CLOCKS_PER_SEC); return 0; }