Public Member Functions | |
project () | |
void | ReadProblem (const char *fname) |
void | ReadProblem2 (const char *fname) |
void | AssignAllTasks (long, long) |
void | AssignmentReport (long, long) |
long | NodeNum (char *) |
long | NewNodeNum (char *) |
long | MakeStation (long, long) |
long | IsTie (long, long) |
long | FindTaskFit (long) |
void | RankTasks (long) |
long | Better (long, long, long) |
void | PrintRanking (long) |
void | CountPreds () |
void | CountSuccessors () |
void | AddPreds (long) |
void | AddSuccessors (long) |
void | ZeroNodeLabels () |
void | ZeroNodePreds () |
void | ZeroNodeSuccessors () |
void | Printout () |
void | NodeReport () |
void | ArcReport () |
void | Evaluate () |
void | DoNode (long, string) |
void | PutNode (long) |
void | OutNodeLabel (long) |
void | PutArc (long, string, long) |
void | Driver (long, char **) |
void | CPM () |
Public Attributes | |
long | min |
long | n |
Private Member Functions | |
void | SkipRestLine (ifstream &file) |
Private Attributes | |
long | tMax |
long | numNodes |
long | numArcs |
long | numStations |
long | numCritical |
long | root |
long | totaltime |
long | istart |
long | iend |
NODE | node [MAXNODES+1] |
ARC | arc [MAXARCS+1] |
STATION | station [MAXNODES+1] |
long | tsort [MAXNODES+1] |
stack< long > | nodestack |
Definition at line 69 of file aon.cpp.
project::project | ( | ) | [inline] |
void project::AddPreds | ( | long | i | ) |
void project::AddSuccessors | ( | long | i | ) |
Definition at line 406 of file aon.cpp.
Referenced by CountSuccessors().
void project::ArcReport | ( | ) |
Definition at line 473 of file aon.cpp.
00473 { 00474 long i; 00475 00476 cout << endl << " *** TASK PRECEDENCE REQUIREMENTS ***"<< endl << endl; 00477 printf(" Arc From To Fstar Bstar\n"); 00478 printf("----- --------- ----- -----\n"); 00479 00480 for(i=1;i<=numArcs; ++i) { 00481 printf("%3d %3d %3d %5d %5d\n", 00482 i, arc[i].fromnode, arc[i].tonode, arc[i].fstar, arc[i].bstar); 00483 } 00484 }
void project::AssignAllTasks | ( | long | ct, | |
long | rule | |||
) |
Definition at line 153 of file aon.cpp.
00153 { 00154 long i, tasksleft; 00155 cout << endl << " *** WORKSTATION ASSIGNMENTS ***" << endl << endl; 00156 cout << "For cycle time = " << ct << ", using rule " << rule << endl ; 00157 if (ct < tMax) { 00158 cout << "Infeasible cycle time, reset to " << tMax << ", the largest task time"<< endl; 00159 ct = tMax; 00160 } 00161 cout << endl; 00162 00163 for (i=1; i <= numNodes; ++i) node[i].label = node[i].bcount; 00164 00165 for (numStations=0,tasksleft=numNodes; numStations <= numNodes && tasksleft; ) { 00166 ++numStations; 00167 MakeStation(numStations,ct); 00168 tasksleft -= station[numStations].numTasks; 00169 } 00170 }
void project::AssignmentReport | ( | long | ct, | |
long | rule | |||
) |
Definition at line 121 of file aon.cpp.
00121 { 00122 long i,idle,calc; 00123 double e; 00124 cout << endl << " *** ASSEMBLY LINE SUMMARY ***" << endl << endl; 00125 00126 printf("Problem:\n"); 00127 printf("--------\n"); 00128 printf("Number of tasks %d\n",numNodes); 00129 printf("Total task time %d\n",totaltime); 00130 printf("Longest task time %d\n",tMax); 00131 printf("Target cycle time %d\n\n",ct); 00132 00133 printf("Assignment:\n"); 00134 printf("-----------\n"); 00135 printf("Rule %d\n",rule); 00136 for(i=1, calc=0; i <= numStations; ++i) {calc = MAX(calc,station[i].stationtime);} 00137 ct = calc; 00138 printf("Computed cycle time %d\n",ct); 00139 printf("Stations used, N %d\n",numStations); 00140 idle = 0; 00141 for(i=1; i <= numStations; ++i) {idle += (ct-station[i].stationtime);} 00142 00143 printf("Output per hour, N' %.2lf (if seconds)\n",3600.0/(double)ct); 00144 printf(" %.2lf (if minutes)\n",60.0/(double)ct); 00145 printf("Station time/cycle %d\n",numStations*ct); 00146 printf("Idle time/cycle %d\n",idle); 00147 e = (double)totaltime/((double) numStations*(double)ct); 00148 printf("Efficiency, E %lf\n",e); 00149 printf("Fraction idle, 1-E %lf\n",1.0-e); 00150 printf("Balance delay %lf\n",100.0*(1.0-e)); 00151 }
long project::Better | ( | long | j, | |
long | i, | |||
long | rule | |||
) |
Definition at line 244 of file aon.cpp.
Referenced by RankTasks().
00244 { // returns i or j, whichever is better 00245 switch (rule) { 00246 case 1: if (node[j].preds > node[i].preds) return 0; 00247 else if (node[j].preds < node[i].preds) return 1; 00248 break; 00249 case 2: if (node[j].successors < node[i].successors) return 0; 00250 else if (node[j].successors > node[i].successors) return 1; 00251 break; 00252 } 00253 // Tie-breaker: longer task time first 00254 if (node[j].tasktime > node[i].tasktime) return 1; 00255 else return 0; 00256 }
void project::CountPreds | ( | ) |
Definition at line 364 of file aon.cpp.
00364 { 00365 long i; 00366 ZeroNodePreds(); 00367 for (i=1; i <= numNodes; ++i) { 00368 ZeroNodeLabels(); 00369 AddPreds(i); 00370 } 00371 return; 00372 }
void project::CountSuccessors | ( | ) |
Definition at line 396 of file aon.cpp.
00396 { 00397 long i; 00398 ZeroNodeSuccessors(); 00399 for (i=1; i <= numNodes; ++i) { 00400 ZeroNodeLabels(); 00401 AddSuccessors(i); 00402 } 00403 return; 00404 }
void project::CPM | ( | ) |
Definition at line 507 of file aon.cpp.
00508 { 00509 // Forward pass 00510 long i,j,n,EFi,LSi; 00511 00512 for (i=1; i < numNodes; ++i) { 00513 node[i].unsetpreds = node[i].bcount; 00514 node[i].unsetsuccs = node[i].fcount; 00515 } 00516 00517 node[istart].ES = 0; 00518 nodestack.push(istart); 00519 do { 00520 i = nodestack.top(); 00521 nodestack.pop(); 00522 EFi = node[i].EF = node[i].ES + node[i].tasktime; 00523 // Explore fstar list for node i and add complete ones to stack 00524 if ((n = node[i].fcount) > 0) { 00525 j = arc[node[i].fstar].tonode; // next successor 00526 for(; n >0; --n){ 00527 if(EFi > node[j].EF) node[j].EF = EFi; 00528 if((--node[j].unsetpreds) == 0) nodestack.push(j); 00529 j = arc[node[j].fstar].tonode; // next successor 00530 } 00531 } 00532 } while(!nodestack.empty()); 00533 00534 // Backward pass 00535 00536 node[iend].LF = node[iend].EF; 00537 nodestack.push(iend); 00538 do { 00539 i = nodestack.top(); 00540 nodestack.pop(); 00541 LSi = node[i].LS = node[i].LF - node[i].tasktime; 00542 if((n = node[i].bcount) > 0) { 00543 j = arc[node[i].bstar].fromnode; // next predecessor node 00544 for (; n > 0; --n) { 00545 if(LSi < node[j].LS) node[j].LS = LSi; // new min LSj 00546 if((--node[j].unsetsuccs) == 0) nodestack.push(j); 00547 j = arc[node[j].bstar].fromnode; // next pred in bstar list 00548 } 00549 } 00550 } while(!nodestack.empty()); 00551 00552 // Compute slacks 00553 00554 for(i=1,numCritical=0; i<numNodes; ++i) { 00555 node[i].slack = node[i].EF - node[i].ES; 00556 if(node[i].slack == 0) ++numCritical; 00557 } 00558 }
void project::DoNode | ( | long | i, | |
string | tab1 | |||
) |
void project::Driver | ( | long | , | |
char ** | ||||
) |
Referenced by main().
void project::Evaluate | ( | ) |
Definition at line 423 of file aon.cpp.
00423 { 00424 long i; 00425 long queue[MAXNODES+1]; 00426 long qlen; 00427 long evnode; // node being evaluated 00428 long evarc; 00429 long pred; 00430 long evcount; 00431 00432 qlen = 0; 00433 for(i = 1; i <=numNodes; ++i) { 00434 } 00435 00436 evcount = numNodes; 00437 while (qlen > 0) { 00438 evnode = queue[qlen--]; 00439 --evcount; 00440 evarc = node[evnode].fstar; 00441 pred = node[evnode].bstar; 00442 --node[pred].label; 00443 if (debug) {cout << "Evaluating node " << evnode << " Q = {"; 00444 for (i=1; i<= qlen; ++i) cout << queue[i] << " "; 00445 cout << "}" << endl; 00446 } 00447 00448 node[pred].bstar = evarc; // add to chain of child arcs for pred node 00449 if ((node[pred].label) <= 0) queue[++qlen] = pred; 00450 } 00451 00452 if (evcount) cout << "** There are " << evcount << " unevaluated nodes" << endl; 00453 root = evnode; 00454 }
long project::FindTaskFit | ( | long | timeleft | ) |
Definition at line 202 of file aon.cpp.
Referenced by MakeStation().
00202 { // Return next task that fits or 0 00203 long i,t; 00204 for (i=1; i <= numNodes; ++i) { 00205 t = tsort[i]; 00206 if (t <= 0) continue; // skip if already assigned 00207 if (node[t].label) continue; // skip if all preds not assigned 00208 if (node[t].tasktime <= timeleft) { 00209 tsort[i] = -tsort[i]; 00210 return t; 00211 } 00212 } 00213 return 0; 00214 }
long project::IsTie | ( | long | i, | |
long | j | |||
) |
long project::MakeStation | ( | long | s, | |
long | cycletime | |||
) |
Definition at line 172 of file aon.cpp.
Referenced by AssignAllTasks().
00172 { // assign tasks to workstation s, return # assigned 00173 long t,a,timeleft,cumtime; 00174 static STATION initstation = {0,0,0}; 00175 00176 timeleft = cycletime; 00177 cumtime = 0; 00178 station[s] = initstation; 00179 // NodeReport(); 00180 // ArcReport(); 00181 00182 // cout << endl<<"Station " << s << ":" << endl; 00183 // cout << "Task Time CumTime" << endl; 00184 // cout << "---- ---- -------" << endl; 00185 cout << "Station " << s << " tasks:" ; 00186 00187 while ((timeleft > 0) && (t=FindTaskFit(timeleft)) > 0) { 00188 node[t].station = s; 00189 ++station[s].numTasks; 00190 station[s].stationtime += node[t].tasktime; 00191 timeleft -= node[t].tasktime; 00192 // printf("%4d%6d%9d\n", t, node[t].tasktime, station[s].stationtime); 00193 cout << " " << node[t].nodename; 00194 a = node[t].fstar; 00195 while(a) { --node[arc[a].tonode].label; a = arc[a].fstar;} 00196 } 00197 00198 cout << " (time = " << station[s].stationtime << ")" << endl; 00199 // cout <<"-------------------" << endl; 00200 }
long project::NewNodeNum | ( | char * | s | ) |
long project::NodeNum | ( | char * | s | ) |
Definition at line 299 of file aon.cpp.
Referenced by ReadProblem2().
00299 { 00300 if (numNodes == 0) return NewNodeNum(s); 00301 for (long i=1; i <= numNodes; ++i) { if (!strncmp(s,node[i].nodename,NAMELEN)) return i; } 00302 return NewNodeNum(s); 00303 }
void project::NodeReport | ( | ) |
Definition at line 456 of file aon.cpp.
00456 { 00457 long i; 00458 char buf[25]; 00459 00460 cout <<endl<<" *** TASK SUMMARY ***"<< endl << endl ; 00461 cout << " Task Time Preds Succs"; 00462 if (debug) cout << "Fstar Bstar Fcount Bcount Label"; 00463 cout << endl; 00464 for(i=1;i<=numNodes; ++i) { 00465 printf("%8.8s %4d %5d %5d ",node[i].nodename,node[i].tasktime, node[i].preds, node[i].successors); 00466 if (debug) printf("% %5d %5d %5d", 00467 node[i].fstar, node[i].bstar, node[i].fcount, node[i].bcount, node[i].label); 00468 cout << endl; 00469 } 00470 cout << endl; 00471 }
void project::OutNodeLabel | ( | long | i | ) |
void project::Printout | ( | ) |
void project::PrintRanking | ( | long | rule | ) |
Definition at line 216 of file aon.cpp.
00216 { 00217 long ties = 0; 00218 cout << "Tasks ranked by rule " << rule << ":" << endl; 00219 for (long i=1; i <= numNodes; ++i) { 00220 cout << " " << node[tsort[i]].nodename; 00221 if (IsTie(tsort[i],tsort[i-1])) {++ties; cout << "*"; } 00222 // if (IsTie(tsort[i],tsort[i-1]) || IsTie(tsort[i],tsort[i+1])) {++ties; cout << "*"; } 00223 } 00224 cout << endl; 00225 if (ties) cout << " (*task tied with prior task in ranking)" << endl; 00226 }
void project::PutArc | ( | long | a, | |
string | tab, | |||
long | usetab | |||
) |
void project::PutNode | ( | long | ) |
void project::RankTasks | ( | long | rule | ) |
Definition at line 234 of file aon.cpp.
00234 { 00235 long i,j,best,hold; 00236 for (i=1; i <= numNodes; ++i) tsort[i] = i; 00237 for (i=1; i < numNodes; ++i) { 00238 best = i; 00239 for (j=i+1; j <= numNodes; ++j) { if(Better(tsort[j],tsort[best],rule)) best = j; } 00240 if (best != i) {hold = tsort[i]; tsort[i]=tsort[best]; tsort[best] = hold;} // Swap 00241 } 00242 }
void project::ReadProblem | ( | const char * | fname | ) |
void project::ReadProblem2 | ( | const char * | fname | ) |
Definition at line 314 of file aon.cpp.
00315 { long ifrom, jto, tasktime; 00316 int nstart, nend; // number of start/end nodes (with 0 preds/succs) 00317 char buf[256],save[256]; 00318 char *token; 00319 00320 ifstream file; 00321 file.open(fname, ios_base::in); 00322 if (file.fail()) { cout << "Cannot open input file.\n"; exit(1); } 00323 00324 for (numArcs=0;;) 00325 { 00326 file.getline (buf,256); 00327 if (file.eof()) break; 00328 memcpy(save,buf,sizeof(char)*256); 00329 00330 token = strtok(buf," \t"); // Node/task name 00331 jto = NodeNum(token); 00332 00333 token = strtok(NULL," \t"); 00334 node[jto].tasktime = atoi(token); 00335 if (node[jto].tasktime > tMax) tMax = node[jto].tasktime; 00336 totaltime += node[jto].tasktime; 00337 00338 while (token = strtok(NULL," \t") ) { 00339 ifrom = NodeNum(token); 00340 ++numArcs; 00341 arc[numArcs].fromnode = ifrom; 00342 arc[numArcs].tonode = jto; 00343 arc[numArcs].bstar = node[jto].bstar; 00344 node[jto].bstar = numArcs; 00345 arc[numArcs].fstar = node[ifrom].fstar; 00346 node[ifrom].fstar = numArcs; 00347 ++node[ifrom].fcount; 00348 ++node[jto].bcount; 00349 } 00350 for (int i=1, nstart=nend=0; i <= numNodes; ++i) { 00351 if (node[i].preds == 0) { istart = i; ++nstart;} 00352 if (node[i].successors == 0) { iend = i; ++nend;} 00353 } 00354 00355 } 00356 00357 file.close(); 00358 cout << numNodes << " task nodes, " << numArcs << " precedence arcs"; 00359 cout << ", and " << totaltime << " time units for all tasks" << endl; 00360 if(istart != 1) { cout << "Exactly 1 start node (with no predecessors) is required.\n"; exit(1); } 00361 if(iend != 1) { cout << "Exactly 1 end node (with no successors) is required.\n"; exit(1); } 00362 }
void project::SkipRestLine | ( | ifstream & | file | ) | [private] |
void project::ZeroNodeLabels | ( | ) |
Definition at line 387 of file aon.cpp.
Referenced by CountPreds(), and CountSuccessors().
void project::ZeroNodePreds | ( | ) |
Definition at line 391 of file aon.cpp.
Referenced by CountPreds().
void project::ZeroNodeSuccessors | ( | ) |
Definition at line 419 of file aon.cpp.
Referenced by CountSuccessors().
ARC project::arc[MAXARCS+1] [private] |
Definition at line 113 of file aon.cpp.
Referenced by AddPreds(), AddSuccessors(), ArcReport(), CPM(), DoNode(), MakeStation(), and ReadProblem2().
long project::iend [private] |
Definition at line 111 of file aon.cpp.
Referenced by CPM(), and ReadProblem2().
long project::istart [private] |
Definition at line 110 of file aon.cpp.
Referenced by CPM(), and ReadProblem2().
long project::min |
long project::n |
NODE project::node[MAXNODES+1] [private] |
Definition at line 112 of file aon.cpp.
Referenced by AddPreds(), AddSuccessors(), AssignAllTasks(), Better(), CPM(), DoNode(), Evaluate(), FindTaskFit(), IsTie(), MakeStation(), NewNodeNum(), NodeNum(), NodeReport(), PrintRanking(), ReadProblem2(), ZeroNodeLabels(), ZeroNodePreds(), and ZeroNodeSuccessors().
stack<long> project::nodestack [private] |
long project::numArcs [private] |
Definition at line 105 of file aon.cpp.
Referenced by ArcReport(), project(), and ReadProblem2().
long project::numCritical [private] |
long project::numNodes [private] |
Definition at line 104 of file aon.cpp.
Referenced by AssignAllTasks(), AssignmentReport(), CountPreds(), CountSuccessors(), CPM(), Evaluate(), FindTaskFit(), IsTie(), NewNodeNum(), NodeNum(), NodeReport(), PrintRanking(), project(), RankTasks(), ReadProblem2(), ZeroNodeLabels(), ZeroNodePreds(), and ZeroNodeSuccessors().
long project::numStations [private] |
Definition at line 106 of file aon.cpp.
Referenced by AssignAllTasks(), and AssignmentReport().
long project::root [private] |
Definition at line 108 of file aon.cpp.
Referenced by Evaluate().
STATION project::station[MAXNODES+1] [private] |
Definition at line 114 of file aon.cpp.
Referenced by AssignAllTasks(), AssignmentReport(), and MakeStation().
long project::tMax [private] |
Definition at line 103 of file aon.cpp.
Referenced by AssignAllTasks(), AssignmentReport(), project(), and ReadProblem2().
long project::totaltime [private] |
Definition at line 109 of file aon.cpp.
Referenced by AssignmentReport(), and ReadProblem2().
long project::tsort[MAXNODES+1] [private] |
Definition at line 115 of file aon.cpp.
Referenced by FindTaskFit(), PrintRanking(), and RankTasks().