void BD_partial_lik_by_rate( const std::vector<double> &ts, const std::vector<double> &te, const std::vector<double> &vTx, const std::vector<double> &rates, const std::string &par, std::vector<double> &results){ int nSpecies = ts.size(); for(size_t iR=0; iR<rates.size(); ++iR){ double start = vTx[iR]; double end = vTx[iR+1]; unsigned int nEvent; if(par == "l"){ nEvent = countEvent(nSpecies, start, end, ts); } else { nEvent = countEvent(nSpecies, start, end, te); } double totalBL = 0; // Total branch length for(size_t iS=0; iS<(size_t)nSpecies; ++iS) { totalBL += getTimeInsideTF(ts[iS], te[iS], start, end); } results.push_back(nEvent*log(rates[iR]) + -rates[iR]*totalBL); } }
void determineFossilsOccurencePerEpoch(std::vector< double > &aEpochs, std::vector< std::vector <double> > &aFossils) { assert(!aFossils.empty()); assert(!aEpochs.empty()); for(size_t iS=0; iS<aFossils.size(); ++iS) { // For each specie std::vector<size_t> fossilCount(aEpochs.size()); for(size_t iE=0; iE<aEpochs.size()-1; ++iE) { double start = aEpochs[iE]; double end = aEpochs[iE+1]; fossilCount[iE] = countEvent(aFossils[iS].size(), start, end, aFossils[iS]); } fossilCountPerEpoch.push_back(fossilCount); } }
int algo() { int i, j; int RWmP[MAX_TASK_NUM]; fscanf(fin, "%d%d%d%d", &true_task_num, &task_num, &processor_num, &lcm_period); period=(int *)malloc(sizeof(int)*task_num); execute=(int *)malloc(sizeof(int)*task_num); w=(float *)malloc(sizeof(float)*task_num); for(i=0; i<task_num; i++) fscanf(fin, "%d", &period[i]); for(i=0; i<task_num; i++) fscanf(fin, "%d", &execute[i]); for(i=0; i<task_num; i++) { w[i]=((float)execute[i])/((float)period[i]); RWmP[i]=0; } calc_bound(); initialize(); calc_alpha(); calc_UF(); for(i=0; i<processor_num; i++) for(j=0; j<lcm_period; j++) alloc[i][j]=-1; for(i=0; i<row_num; i++) Bfair(RWmP, i); /* for(i=0; i<processor_num; i++) { for(j=0; j<lcm_period; j++) { fprintf(fout, "%d ", alloc[i][j]); } fprintf(fout, "\n"); }*/ if(checkSchedule()==-1) { printf("!!!Schedule error.\n"); } else printf("successfully scheduling.\n"); countPreemption(); countMigration(); countEvent(); fprintf(flog, "preemption:\n"); for(i=0; i<true_task_num; i++) { double ppj=((double)preemption[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", ppj); } fprintf(flog, "\n"); fprintf(flog, "migration:\n"); for(i=0; i<true_task_num; i++) { double mpj=((double)migration[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", mpj); } fprintf(flog, "\n"); fprintf(flog, "event:\n"); for(i=0; i<true_task_num; i++) { double epj=((double)event[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", epj); } fprintf(flog, "\n"); remains(); return 0; }
int main(int argc, char* argv[]) { int i, j, k; if(argc<3) { printf("usage: ./algo <taskset_filename> <logfile_name>\n"); return 0; } fin=fopen(argv[1], "r"); // fout=fopen(argv[2], "w"); flog=fopen(argv[2], "w"); fscanf(fin, "%d%d%d%d", &true_task_num, &task_num, &processor_num, &lcm_period); for(j=0; j<task_num; j++) fscanf(fin, "%d", &period[j]); for(j=0; j<task_num; j++) fscanf(fin, "%d", &execute[j]); for(j=0; j<task_num; j++) for(k=0; k<lcm_period; k++) execute_flag[j][k]=-1; for(j=0; j<processor_num; j++) for(k=0; k<lcm_period; k++) alloc[j][k]=-1; preemption=(int*)malloc(sizeof(int)*true_task_num); migration=(int*)malloc(sizeof(int)*true_task_num); event=(int*)malloc(sizeof(int)*true_task_num); if (lcm_period != schedule_task_set(1, 1)) { printf("%s: Error!!!\n", argv[1]); } printf("%s: Successfull Scheduling\n", argv[1]); allocate(); /* for(j=0; j<processor_num; j++) { for(k=0; k<lcm_period; k++) { fprintf(fout, "%d ", alloc[j][k]); } fprintf(fout, "\n"); }*/ countPreemption(); countMigration(); countEvent(); fprintf(flog, "preemption:\n"); for(i=0; i<true_task_num; i++) { double ppj=((double)preemption[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", ppj); } fprintf(flog, "\n"); fprintf(flog, "migration:\n"); for(i=0; i<true_task_num; i++) { double mpj=((double)migration[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", mpj); } fprintf(flog, "\n"); fprintf(flog, "event:\n"); for(i=0; i<true_task_num; i++) { double epj=((double)event[i])/((double)(lcm_period/period[i])); fprintf(flog, "%lf ", epj); } fprintf(flog, "\n"); free(preemption); free(migration); free(event); // fflush(fout); fflush(flog); fclose(flog); // fclose(fout); fclose(fin); return 0; }