int FCBF(DATA_SET & data, double min_threshold, std::string class_column, std::vector<std::string> & best_features) { PROB_HASH probs; PROB_GIVEN_HASH given_probs; std::vector<std::string> feature_names; std::list<std::pair<std::string, double>> list; GetKeys(data, feature_names); CalculateProbabilities(data, probs, given_probs, class_column); for(auto it = feature_names.begin(); it != feature_names.end(); ++it) { if(*it != class_column) { std::pair<std::string, double> tuple; tuple.first = *it; tuple.second = SU(data, probs, given_probs, class_column, *it); if(tuple.second > min_threshold) { list.push_back(tuple); } } } list.sort(TupleCompare); auto F_j = list.begin(); while (F_j != list.end()) { auto F_i = F_j; ++F_i; while (F_i != list.end()) { double su_ij = SU(data, probs, given_probs, F_j->first, F_i->first); if(su_ij >= F_i->second) { F_i = list.erase(F_i); } else { ++F_i; } } ++F_j; } best_features.clear(); best_features.reserve(list.size()); for(auto it = list.begin(); it != list.end(); ++it) { best_features.push_back(it->first); } return 0; }
int THISCLASS::SelectTask(RobotDevice* robot,\ DataStructureShopTasks::tShopTaskVector* taskvec) { printf(" --- Selecting task for robot %d\n", robot->mID); CalculateProbabilities(robot, taskvec); ConvertProbabilitiesIntoRange(NEXTSTART); mSelectedTaskID = GetRandomSelection(); return mSelectedTaskID; }
/*Main program of the ABC algorithm*/ int main() { int iter,run; double mean; mean=0; srand(time(NULL)); int i,j,k,ii; po s[200]; FILE *f1; file=fopen("result\\out17.txt","w"); if((f1=fopen("input\\P10S2T03.dat","r"))==NULL) { exit(0); } fscanf(f1,"jobs %d\n",&J); fscanf(f1,"stage %d\n",&S); fscanf(f1,"machines %d",&sm[1]); for(i=2;i<=S-1;i++) fscanf(f1," %d",&sm[i]); fscanf(f1," %d\n",&sm[S]); fscanf(f1,"*Pro_req*\n"); for(i=1;i<=S;i++) { for(j=1;j<=J;j++) fscanf(f1,"%d ",&proreq[i][j]); fscanf(f1,"\n"); } fscanf(f1,"*Pro_time*\n"); for(i=1;i<=S;i++) { for(j=1;j<=J;j++) fscanf(f1,"%d ",&protime[i][j]); fscanf(f1,"\n"); } fclose(f1); double lower; lower=func_LB(J,S,sm,proreq,protime); fprintf(file,"lower=%lf\n",lower); for(i=1;i<=S;i++) { ub[i]=sm[i]+1; lb[i]=1; } double mmin=100000000.0; for(run=1;run<=runtime;run++) { initial(); MemorizeBestSource(); for (iter=1;iter<=maxCycle;iter++) //迭代次数 { SendEmployedBees();//雇佣蜂时期 CalculateProbabilities();//计算可能性 //SendOnlookerBees();//跟随蜂时期 MemorizeBestSource();//记录最好的蜂源 SendScoutBees();//如果到达尝试次数后,就到侦察蜂时期 } /* for(j=0;j<D;j++) { printf("GlobalParam[%d]: %f\n",j+1,GlobalParams[j]); }*/ fprintf(file,"%d. run: %f \n",run,GlobalMin); GlobalMins[run]=GlobalMin; mean=mean+GlobalMin; if(GlobalMin<mmin) mmin=GlobalMin; } double pd; pd=PD(mmin,lower); mean=mean/runtime; fprintf(file,"Means of %d runs: %f\n",runtime,mean); fprintf(file,"Mins of %d runs: %f\n",runtime,mmin); fprintf(file,"PD of this time: %f\n",pd); //fprintf(file,"maxspan=%d\n",max); //system("pause"); return 0; }