void ProcessModel::clearSchedRelData() { // Collect the selection arcs QList<ListDigraph::Arc> selectionArcs; selectionArcs.clear(); for (ListDigraph::ArcIt ait(this->graph); ait != INVALID; ++ait) { if (!this->conjunctive[ait]) { selectionArcs.append(ait); } this->p[ait] = 0.0; } // Clear the scheduling relevant data for (ListDigraph::NodeIt nit(this->graph); nit != INVALID; ++nit) { this->ops[nit]->machID = -1; this->ops[nit]->machAvailTime(0.0); this->ops[nit]->r(this->ops[nit]->ir()); this->ops[nit]->s(this->ops[nit]->r()); this->ops[nit]->p(0.0); } // Clear the selection arcs for (int i = 0; i < selectionArcs.size(); i++) { this->graph.erase(selectionArcs[i]); } }
bool Qt4BuildConfiguration::removeQMLInspectorFromArguments(QString *args) { bool removedArgument = false; for (QtcProcess::ArgIterator ait(args); ait.next(); ) { const QString arg = ait.value(); if (arg.contains(QLatin1String(Constants::QMAKEVAR_QMLJSDEBUGGER_PATH)) || arg.contains(QLatin1String(Constants::QMAKEVAR_QUICK1_DEBUG)) || arg.contains(QLatin1String(Constants::QMAKEVAR_QUICK2_DEBUG))) { ait.deleteArg(); removedArgument = true; } } return removedArgument; }
void SquadronClass::DisposeChildren (void) { // Clears out all flights waiting for takeoff. // Intended for use when the squadron is recalled. CAMPREGLIST_ITERATOR ait(AllAirList); Unit u; u = (Unit) ait.GetFirst(); while (u) { if (u->IsFlight() && !u->Moving() && ((Flight)u)->GetUnitSquadronID() == Id()) RegroupFlight((Flight)u); u = (Unit) ait.GetNext(); } }
/** * Copy the internal presentation of this object into the new * object. */ void UMLAttributeList::copyInto(UMLAttributeList *rhs) const { // Don't copy yourself. if (rhs == this) return; rhs->clear(); // Suffering from const; we shall not modify our object. UMLAttributeList *tmp = new UMLAttributeList(*this); UMLAttribute *item; for (UMLAttributeListIt ait( *tmp ); ait.hasNext() ; ) { item = ait.next(); rhs->append((UMLAttribute*)item->clone()); } delete tmp; }
QStringList QmakeBuildConfiguration::extractDeducedArguments(QString *args) { QStringList allPossibleDeducedArguments; allPossibleDeducedArguments << QLatin1String("CONFIG+=x86") << QLatin1String("CONFIG+=x86_64") << QLatin1String("CONFIG+=iphonesimulator") << QLatin1String("CONFIG+=ppc") << QLatin1String("CONFIG+=ppc64") << QLatin1String("CONFIG+=iphoneos"); QStringList result; for (QtcProcess::ArgIterator ait(args); ait.next(); ) { QString arg = ait.value(); if (allPossibleDeducedArguments.contains(arg)) { result << arg; ait.deleteArg(); } } return result; }
void KU::KGroups::commit() { kdDebug() << "KU::KGroups::commit()" << endl; KU::KGroup *group; DelIt dit( mDelSucc ); AddIt ait( mAddSucc ); ModIt mit = mModSucc.begin(); while ( mit != mModSucc.end() ) { *(mit.key()) = mit.data(); mit++; } while ( (group = dit.current()) != 0 ) { ++dit; mGroups.remove( group ); } while ( (group = ait.current()) != 0 ) { ++ait; mGroups.append( group ); } cancelMods(); }
void ProcessModel::restore() { if (!saved) { Debugger::err << "ProcessModel::restore : Trying to restore an empty PM!" << ENDL; return; } if (saved) { // clearCurrent(); // ####### TESTING // Remove all disjunctive arcs in the graph QList<ListDigraph::Arc> arcsToRem; for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { ListDigraph::Arc curArc = ait; if (!conjunctive[ait]) arcsToRem.append(curArc); } for (int i = 0; i < arcsToRem.size(); i++) { ListDigraph::Arc curArc = arcsToRem[i]; graph.erase(curArc); } // Restore the information about the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; *(ops[curNode]) = savedOps[curNode]; } // Restore the DISJUNCTIVE arcs and the information about the arcs for (int i = 0; i < savedArcs.size(); i++) { if (!savedConjunctive[i]) { // This arc is disjunctive ListDigraph::Node curStartNode = savedArcs[i].first; ListDigraph::Node curEndNode = savedArcs[i].second; ListDigraph::Arc curArc = graph.addArc(curStartNode, curEndNode); p[curArc] = savedP[i]; conjunctive[curArc] = savedConjunctive[i]; } } // Restore the lengths of all arcs for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; double curP = ops[curNode]->p(); for (ListDigraph::OutArcIt oait(graph, curNode); oait != INVALID; ++oait) { ListDigraph::Arc curArc = oait; p[curArc] = -curP; } } // ################ return; // Copy the saved graph into the current one ListDigraph::NodeMap<ListDigraph::Node> noderef(savedGraph); digraphCopy(savedGraph, graph).node(savedHead, head).node(savedTail, tail).nodeRef(noderef).arcMap(savedp, p).arcMap(savedconjunctive, conjunctive).run(); // Create and copy the operations for (ListDigraph::NodeIt nit(savedGraph); nit != INVALID; ++nit) { this->ops[noderef[nit]] = new Operation(*savedops[nit]); } /* // Restore the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { *ops[nit] = *savedOps[ops[nit]->ID]; } // Restore the arcs for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { arcsdel.append(ait); } for (int i = 0; i < arcsdel.size(); i++) { graph.erase(arcsdel[i]); } for (int i = 0; i < savedArcs.size(); i++) { arc = graph.addArc(savedArcs[i].first, savedArcs[i].second); p[arc] = savedP[i]; conjunctive[arc] = savedConjunctive[i]; } */ } //out1 << "Restored PM: " << *this << endl; }
void ProcessModel::save() { //out1 << "Saving PM ..." << endl; // Delete the previous operations clearSaved(); // Mark the PM to be saved saved = true; // ####### TESTING // Preserve the information about the operations savedOps.clear(); for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { ListDigraph::Node curNode = nit; Operation& curOp = (Operation&) * ops[curNode]; savedOps[curNode] = curOp; } // Preserve the information about the arcs savedArcs.clear(); savedP.clear(); savedConjunctive.clear(); for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { ListDigraph::Arc curArc = ait; ListDigraph::Node curStartNode = graph.source(curArc); ListDigraph::Node curEndNode = graph.target(curArc); savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node>(curStartNode, curEndNode)); savedP.append(p[curArc]); savedConjunctive.append(conjunctive[curArc]); } // ################ return; // Copy the current graph into the saved graph //out1 << "Copying the current graph..." << endl; ListDigraph::NodeMap<ListDigraph::Node> noderef(graph); digraphCopy(graph, this->savedGraph).node(head, this->savedHead).node(tail, savedTail).nodeRef(noderef).arcMap(p, savedp).arcMap(conjunctive, savedconjunctive).run(); //out1 << "Done copying the current graph." << endl; // Create and copy the operations //out1 << "Copying the current operations into the saved operations ..."<<endl; for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { this->savedops[noderef[nit]] = new Operation(*ops[nit]); } //out1 << "Done copying the current operations into the saved operations."<<endl; /* // Save the operations for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { savedOps[ops[nit]->ID] = new Operation(*ops[nit]); } // Save the arcs and the assigned data for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) { savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node > (graph.source(ait), graph.target(ait))); savedP.append(p[ait]); savedConjunctive.append(conjunctive[ait]); } */ //out1 << "Saved PM: " << *this << endl; }
void genHardNegativesOnAnnotations(FeatGen* ldgFeatGen,const path& baseDir, datasets currDataset, bool writeOutWins, bool viz,string modelfile) { vector<path> negativePaths; vector<path> negTrainPaths; vector<path> negTestPaths; FrameId firstTestFrame; // separates training and testing data string learnFileStem; vector<path> normPosWinPathsTrain; // if any use folder with normalized cropped windows vector<path> normPosWinPathsTest; // if any use folder with normalized cropped windows getLearnInfos(baseDir, currDataset, negativePaths, negTrainPaths, negTestPaths,normPosWinPathsTrain, normPosWinPathsTest, learnFileStem, firstTestFrame); path negTrainFolder = baseDir / "learning" / "train_neg_hard_annot"; remove_all(negTrainFolder); create_directories(negTrainFolder); //std::ios_base::openmode mode = ; //fs::ofstream trainFile((baseDir / "learning" / learnFileStem).string(), std::ios_base::out | ios_base::app); //fs::ofstream trainFilesFile((baseDir / "learning" / learnFileStem).string() + ".files", std::ios_base::out | ios_base::app); fs::ofstream trainFileHard((baseDir / "learning" / learnFileStem).string() + "_hard_annot"); if ( !(modelfile.length() > 0 ) ) { modelfile = (baseDir / "learning" / learnFileStem).string() + ".model"; } path mfp(modelfile); if ( !exists(mfp)) { cerr << "Modelfile does not exist: " << modelfile << endl; exit(EXIT_FAILURE); } cout << "genHardNegativesOnAnnotations using model: " << modelfile << endl; Detector pd(ldgFeatGen); pd.setStartScale(1.0); pd.setScaleStep(1.04); pd.loadSVMWeights(modelfile); float decThresh = 0; int nww = ldgFeatGen->getWinW(); int nwh = ldgFeatGen->getWinH(); // use caltech annotations FrameId startFrame; startFrame.set= 0; startFrame.video= 0; startFrame.image= 0; size_t featSize = getFeatLen(ldgFeatGen); vector<path> annotFiles; annotFiles = findAllAnnotations(baseDir,startFrame); if ( annotFiles.size() == 0 ) { cerr << "No annotations found." << endl; exit(EXIT_FAILURE); } for ( vector<path>::iterator it (annotFiles.begin()); it != annotFiles.end(); ++it) { path vbbFile = *it; path txtFolder = vbbFile.parent_path() / vbbFile.stem(); vector<path> v; copy(directory_iterator(txtFolder),directory_iterator(),back_inserter(v)); sort(v.begin(),v.end()); int posTrainCounter = 0; cout << "0% "; cout.flush(); for ( vector<path>::iterator vit (v.begin()); vit != v.end(); ++vit) { path txtFile = *vit; // annotation txtFile // corresponding image file path imgFile = baseDir / "videos" / txtFile.parent_path().parent_path().stem() / txtFile.parent_path().stem() / txtFile.filename().stem(); bool isTrain = true; if (frameLTEQ(firstTestFrame,parseFrameFromPath(imgFile))) { isTrain = false; } if ( skipPath(imgFile,startFrame) ) continue; if ( !isTrain ) continue; imgFile += findImageExtension(imgFile); if ( !exists(imgFile) || !is_regular_file(imgFile)) { cerr << "Could not find corresponding image file " <<imgFile <<endl; cerr << "Export all .seq files using provided matlab code." << endl; exit(EXIT_FAILURE); } // parse annotations from txtFile fs::ifstream f(txtFile); if (!f) { cerr << "cannot open file " << txtFile << endl; exit(EXIT_FAILURE); } vector<Annotation> annots; string buffer; while (std::getline(f,buffer)) { Annotation a = parseAnnotation(buffer); if ( a.type == "person" ) { //printAnnotation(a); annots.push_back(a); } } // extract normalized bb images Mat img = imread(imgFile.string(), CV_LOAD_IMAGE_COLOR); posTrainCounter++; if ( (posTrainCounter % 100) == 0) { float donePerc = posTrainCounter / (float)v.size(); cout << floor(donePerc * 100) << "% "; cout.flush(); } path nf = imgFile; string filePre = nf.parent_path().parent_path().stem().string() + nf.parent_path().stem().string() + "_" + nf.filename().stem().string(); vector< pair < Detection,double* > > detections; vector<Detection> alldetections; pd.detect(img,detections,alldetections,decThresh,true); vector<bool> rectIsUsed; rectIsUsed.resize(detections.size()); for ( size_t i = 0; i < detections.size(); i++) { pair < Detection,double* > mp = detections[i]; Detection det = mp.first; Rect r = det.r; double* f = mp.second; // check if rectangle is annotated object bool rectIsFree = true; for (vector<Annotation>::iterator ait (annots.begin()); ait != annots.end(); ++ait) { Annotation an = *ait; Rect a(an.x,an.y,an.width,an.height); // calc intersection area Rect inters = a & r; if ( inters.area() > 0 ) { // further analyze intersection double ratio1 = (double) inters.area() / (double) r.area(); double ratio2 = (double) inters.area() / (double) a.area(); double ratio = min(ratio1,ratio2); rectIsFree = !(ratio > 0.5); if ( !rectIsFree ) { break; } } } rectIsUsed[i] = rectIsFree; if ( rectIsFree ) { // save as negative example writeFeatToSVMStream(f,trainFileHard,featSize,false); } else { // save as positive example writeFeatToSVMStream(f,trainFileHard,featSize,true); } delete[] f; } if ( viz || writeOutWins ) { Mat vizImg = img.clone(); if ( alldetections.size() < 100 ) { for ( vector< Detection >::iterator it(alldetections.begin()); it != alldetections.end(); it++) { Detection det = *it; Rect r = det.rNormWin; //cout << r.x << " " << r.y << " " << r.width << "x" << r.height << " scale:" << det.scale << " decisionValue:" << det.decisionValue << endl; rectangle(vizImg,r,Scalar(255,50,50),1,8); } } for ( size_t i = 0; i < detections.size(); i++) { Detection det = detections[i].first; Rect r = det.r; if ( rectIsUsed[i]) { rectangle(vizImg,r,Scalar(0,0,255),1,8); } else { rectangle(vizImg,r,Scalar(0,255,255),1,8); } } displayAnnotations(vizImg,annots); if ( writeOutWins ) { string fileNameOnly = (filePre +"_hard.png"); path nwPath = negTrainFolder / fileNameOnly; imwrite(nwPath.string(),vizImg); } if ( viz ) { imshow("negative training image",vizImg); waitKey(0); destroyWindow("negative training image"); } } } } cout << "100% "<< endl; trainFileHard.close(); }
FileName Qt4BuildConfiguration::extractSpecFromArguments(QString *args, const QString &directory, const BaseQtVersion *version, QStringList *outArgs) { FileName parsedSpec; bool ignoreNext = false; bool nextIsSpec = false; for (QtcProcess::ArgIterator ait(args); ait.next(); ) { if (ignoreNext) { ignoreNext = false; ait.deleteArg(); } else if (nextIsSpec) { nextIsSpec = false; parsedSpec = FileName::fromUserInput(ait.value()); ait.deleteArg(); } else if (ait.value() == QLatin1String("-spec") || ait.value() == QLatin1String("-platform")) { nextIsSpec = true; ait.deleteArg(); } else if (ait.value() == QLatin1String("-cache")) { // We ignore -cache, because qmake contained a bug that it didn't // mention the -cache in the Makefile. // That means changing the -cache option in the additional arguments // does not automatically rerun qmake. Alas, we could try more // intelligent matching for -cache, but i guess people rarely // do use that. ignoreNext = true; ait.deleteArg(); } else if (outArgs && ait.isSimple()) { outArgs->append(ait.value()); } } if (parsedSpec.isEmpty()) return FileName(); FileName baseMkspecDir = FileName::fromUserInput( version->qmakeProperty("QT_HOST_DATA") + QLatin1String("/mkspecs")); baseMkspecDir = Utils::FileName::fromString(baseMkspecDir.toFileInfo().canonicalFilePath()); // if the path is relative it can be // relative to the working directory (as found in the Makefiles) // or relatively to the mkspec directory // if it is the former we need to get the canonical form // for the other one we don't need to do anything if (parsedSpec.toFileInfo().isRelative()) { if (QFileInfo(directory + QLatin1Char('/') + parsedSpec.toString()).exists()) parsedSpec = FileName::fromUserInput(directory + QLatin1Char('/') + parsedSpec.toString()); else parsedSpec = FileName::fromUserInput(baseMkspecDir.toString() + QLatin1Char('/') + parsedSpec.toString()); } QFileInfo f2 = parsedSpec.toFileInfo(); while (f2.isSymLink()) { parsedSpec = FileName::fromString(f2.symLinkTarget()); f2.setFile(parsedSpec.toString()); } if (parsedSpec.isChildOf(baseMkspecDir)) { parsedSpec = parsedSpec.relativeChildPath(baseMkspecDir); } else { FileName sourceMkSpecPath = FileName::fromString(version->sourcePath().toString() + QLatin1String("/mkspecs")); if (parsedSpec.isChildOf(sourceMkSpecPath)) parsedSpec = parsedSpec.relativeChildPath(sourceMkSpecPath); } return parsedSpec; }
int CSampleLds2Application::Run(void) { // Process command line args const CArgs& args = GetArgs(); const string& db_path = args["db"].AsString(); // // Initialize the local data storage // if ( args["data_dir"] ) { try { CRef<CLDS2_Manager> mgr(new CLDS2_Manager(db_path)); // Allow to split GB release bioseq-sets mgr->SetGBReleaseMode(CLDS2_Manager::eGB_Guess); if ( args["group_aligns"] ) { mgr->SetSeqAlignGroupSize(args["group_aligns"].AsInteger()); } mgr->AddDataDir(args["data_dir"].AsString()); mgr->UpdateData(); } catch(CException& e) { ERR_POST("Error initializing local data storage: " << e.what()); return 1; } } // Create OM and LDS2 data loader CRef<CObjectManager> object_manager = CObjectManager::GetInstance(); try { CLDS2_DataLoader::RegisterInObjectManager(*object_manager, db_path, -1, CObjectManager::eDefault); } catch (CException& e) { ERR_POST("Error registering LDS2 data loader: " << e.what()); return 2; } // Check if an id was requested, try to fetch some data if ( args["id"] ) { string id = args["id"].AsString(); // Create Seq-id, set it to the GI specified on the command line CSeq_id seq_id(id); // Create a new scope ("attached" to our OM). CScope scope(*object_manager); // Add default loaders (GB loader in this demo) to the scope. scope.AddDefaults(); // Get synonyms CBioseq_Handle::TId bh_ids = scope.GetIds(seq_id); NcbiCout << "Synonyms for " << id << ": "; string sep = ""; ITERATE (CBioseq_Handle::TId, id_it, bh_ids) { cout << sep << id_it->AsString(); sep = ", "; } cout << endl; // Get Bioseq handle for the Seq-id. CBioseq_Handle bioseq_handle = scope.GetBioseqHandle(seq_id); if ( !bioseq_handle ) { ERR_POST("Bioseq not found, with id=" << id); } else { // Dump the seq-entry. if ( args["print_entry"] ) { cout << MSerial_AsnText << *bioseq_handle.GetTopLevelEntry().GetCompleteSeq_entry(); } } // Test features SAnnotSelector sel; sel.SetSearchUnresolved() .SetResolveAll(); CSeq_loc loc; loc.SetWhole().Assign(seq_id); cout << "Features by location:" << endl; CFeat_CI fit(scope, loc, sel); int fcount = 0; for (; fit; ++fit) { if ( args["print_feats"] ) { cout << MSerial_AsnText << fit->GetOriginalFeature(); } fcount++; } cout << fcount << " features found" << endl; cout << "Features by product:" << endl; sel.SetByProduct(true); CFeat_CI fitp(scope, loc, sel); fcount = 0; for (; fitp; ++fitp) { if ( args["print_feats"] ) { cout << MSerial_AsnText << fitp->GetOriginalFeature(); } fcount++; } cout << fcount << " features found" << endl; // Test alignments cout << "Alignments:" << endl; sel.SetByProduct(false); CAlign_CI ait(scope, loc, sel); int acount = 0; for (; ait; ++ait) { if ( args["print_aligns"] ) { cout << MSerial_AsnText << ait.GetOriginalSeq_align(); } acount++; } cout << acount << " alignments found" << endl; }
bool BiDirScheduler::schedule(ProcessModel &pm, Resources &rc, Schedule &schedule) { Debugger::info << "Building schedule using simple bidirectional approach." << ENDL; /** Algorithm: * * Lv - set of head scheduled operations; * Lr - set of tail scheduled operations; * Av - set of additionally head-schedulable operations; * Ar - set of additianally tail-schedulable operations; * * 1. Lv = Lr = 0; * Av = first available operations of the graph; * Ar = first available operations in the reverse graph. * * 2. While Av + Ar != 0 * * 2.a) select operation from Av according to some priority rule; * 2.b) schedule the selected operation as soon as possible; * 2.c) include the operation into Lv and exclude it from Av * 2.d) select next available operation(s) which are not in Ar + Lr and insert them into Av * * 2.e) select operation from Ar according to some priority rule; * 2.f) schedule the selected operation as late as possible before all of the operations from Lr; * 2.g) include the operation into Lr and exclude it from Ar; * 2.h) select next available operation(s) (in inverse graph) which are not in Av + Lv and insert them into Ar. * * 3. Shift left the start times of the operations from Lr so that they start immediately after latest from Lv finishes. * * */ QTextStream out(stdout); QList<ListDigraph::Node> Lv; QList<ListDigraph::Node> Lr; QList<ListDigraph::Node> Av; QList<ListDigraph::Node> Ar; QList<ListDigraph::Node> Avnext; QList<ListDigraph::Node> Lravail; // Currently available nodes from Lr QMap<ListDigraph::Node, Machine*> nodemachLr; // Assignments of the operations from Lr to the machines QHash<int, double> backmach; // Machines for backward operation scheduling <machine ID, time for operation finish> for (int i = 0; i < rc.machines().size(); i++) { backmach[rc.machines()[i]->ID] = 10000000; } ListDigraph::NodeMap<bool> nodesscheduled(pm.graph, false); // Scheduled nodes bool nodeavail; // Used for checking whether some node is available fro scheduling ListDigraph::Node curnode; Lv.clear(); Lr.clear(); Av.clear(); Ar.clear(); // Initialize the sets of operations Av for (ListDigraph::OutArcIt gait(pm.graph, pm.head); gait != INVALID; ++gait) { for (ListDigraph::OutArcIt lait(pm.graph, pm.graph.target(gait)); lait != INVALID; ++lait) { Av.append(pm.graph.target(lait)); } } //out << "Operations of Av:" << endl; //for (int i = 0; i < Av.size(); i++) { // out << Av[i] << endl; //} // Initialize the sets of operations Ar for (ListDigraph::InArcIt gait(pm.graph, pm.tail); gait != INVALID; ++gait) { for (ListDigraph::InArcIt lait(pm.graph, pm.graph.source(gait)); lait != INVALID; ++lait) { Ar.append(pm.graph.source(lait)); //Ar.append(pm.graph.source(gait)); } } //out << "Operations of Ar:" << endl; //for (int i = 0; i < Ar.size(); i++) { // out << *pm.ops[Ar[i]] << endl; //} //getchar(); NodeWeightComparatorGreater nwcg(&pm); // Run the loop while (Av.size() + Ar.size() > 0) { // Scheduling one operation from Av Avnext.clear(); //out << "Scheduling operations" << endl; //for (int i = 0; i < Av.size(); i++) { // out << pm.ops[Av[i]]->ID <<" "; //} //out<<endl; if (Av.size() > 0) { // Sort the nodes of Av qSort(Av.begin(), Av.end(), nwcg); curnode = Av[0]; // Schedule the first operation (as soon as possible) //Machine &m = rc(pm.ops[Av[0]]->toolID).nextAvailable(); // Select the fastest available machine from the corresponding tool group //Machine &m = rc(pm.ops[Av[0]]->toolID).fastestAvailable(pm.ops[Av[0]]->r(), pm.ops[Av[0]]->type); // Select the machine from the corresponding tool group to finish the operation the earliest Machine &m = rc(pm.ops[curnode]->toolID).earliestToFinish(pm.ops[curnode]); m << pm.ops[curnode]; nodesscheduled[curnode] = true; // Include the operation into Lv Lv.append(curnode); // Iterate through all child nodes of the current node for (ListDigraph::OutArcIt oait(pm.graph, curnode); oait != INVALID; ++oait) { if (!Lr.contains(pm.graph.target(oait)) && !Ar.contains(pm.graph.target(oait))) { // Check availability nodeavail = true; for (ListDigraph::InArcIt iait(pm.graph, pm.graph.target(oait)); iait != INVALID; ++iait) { nodeavail = nodeavail && nodesscheduled[pm.graph.source(iait)]; } if (nodeavail) { //out << "Now available : " << pm.graph.id(cursucc) << endl; // Update ready time of the newly enabled node pm.ops[pm.graph.target(oait)]->r(0.0); for (ListDigraph::InArcIt init(pm.graph, pm.graph.target(oait)); init != INVALID; ++init) { pm.ops[pm.graph.target(oait)]->r(Math::max(pm.ops[pm.graph.target(oait)]->r(), pm.ops[pm.graph.source(init)]->c())); } //if (!nodesscheduled[pm.graph.target(oait)]) { Av/*next*/.append(pm.graph.target(oait)); //} } } } // Exclude the operation from Av Av.removeAt(0); } //getchar(); //Av = Avnext; // Scheduling one operation from Ar if (Ar.size() > 0) { // Sort the nodes of Ar qSort(Ar.begin(), Ar.end(), nwcg); curnode = Ar.last(); // Schedule the operation with as late as possible before all operations from Lr // The operation with the smallest priority is selected //Machine &m = rc(pm.ops[curnode]->toolID).nextAvailable(); // Select the fastest available machine from the corresponding tool group //Machine &m = rc(pm.ops[curnode]->toolID).fastestAvailable(10000000, pm.ops[curnode]->type); // Select the random machine from the corresponding tool group //Machine &m = rc(pm.ops[curnode]->toolID).randomMachine(); // Find machine which could start this operation the latest Machine *m = NULL; double lateststarttime = 0.0; double curstarttime; // Iterate over all machines able to process the operation QList<Machine*> machines = rc(pm.ops[curnode]->toolID).machines(); for (int i = 0; i < machines.size(); i++) { curstarttime = backmach[machines[i]->ID] - machines[i]->procTime(pm.ops[curnode]); if (lateststarttime <= curstarttime) { lateststarttime = curstarttime; m = machines[i]; } } backmach[m->ID] = lateststarttime; // Select the machine from the corresponding tool group to finish the operation the earliest //Machine &m = rc(pm.ops[curnode]->toolID).earliestToFinish(pm.ops[curnode]); //m << pm.ops[curnode]; nodemachLr[curnode] = m; //nodesscheduled[curnode] = true; // Include the operation into Lr Lr.prepend(curnode); // Iterate through all parent nodes of the current node for (ListDigraph::InArcIt iait(pm.graph, curnode); iait != INVALID; ++iait) { if (!Lv.contains(pm.graph.source(iait)) && !Av.contains(pm.graph.source(iait))) { Ar.prepend(pm.graph.source(iait)); } } // Exclude the operation from Av Ar.removeLast(); } //out << "Av size = " << Av.size() << endl; } // Shift left all of the operations from Lr so that the earliest from them is started as soon as possible //out << "Operations in nodemachLr: " << endl; //for (int i = 0; i < nodemachLr.size(); i++) { // out << *pm.ops[nodemachLr[i].first] << endl; //} //getchar(); QList<ListDigraph::Node> keys; while (nodemachLr.size() > 0) { keys = nodemachLr.keys(); // Collect currently available (immediately schedulable) nodes from Lr Lravail.clear(); for (int i = 0; i < nodemachLr.size(); i++) { for (ListDigraph::InArcIt iait(pm.graph, keys[i]); iait != INVALID; ++iait) { if (Lv.contains(pm.graph.source(iait)) && nodesscheduled[pm.graph.source(iait)]) { Lravail.append(keys[i]); Lv.append(keys[i]); //Lr.removeOne(nodemachLr.keys()[i]); break; } } } // //Sort the nodes in Lravail qSort(Lravail.begin(), Lravail.end(), nwcg); //out << "Lravail operations before ready times update:" << endl; //for (int i = 0; i < Lravail.size(); i++) { // out << *pm.ops[Lravail[i]] << endl; //} //getchar(); // Update the ready time of the operations in Lravail and schedule them for (int i = 0; i < Lravail.size(); i++) { pm.ops[Lravail[i]]->r(0.0); for (ListDigraph::InArcIt iait(pm.graph, Lravail[i]); iait != INVALID; ++iait) { pm.ops[Lravail[i]]->r(Math::max(pm.ops[Lravail[i]]->r(), pm.ops[pm.graph.source(iait)]->c())); } // Schedule the available nodes *(nodemachLr.value(Lravail[i])) << pm.ops[Lravail[i]]; nodesscheduled[Lravail[i]] = true; nodemachLr.remove(Lravail[i]); } //out << "Lravail operations after ready times update:" << endl; //for (int i = 0; i < Lravail.size(); i++) { // out << *pm.ops[Lravail[i]] << endl; //} //getchar(); } //out << "Resources after scheduling" << endl; //out << rc << endl; // Iterate over all nodes directly preceding the tail and //Debugger::info << "Collecting schedule data ..." << ENDL; schedule.objective = 0.0; for (ListDigraph::ArcIt ait(pm.graph); ait != INVALID; ++ait) { if (pm.graph.target(ait) == pm.tail) { if (pm.ops[pm.graph.source(ait)]->ID < 0) { for (ListDigraph::InArcIt iait(pm.graph, pm.graph.source(ait)); iait != INVALID; ++iait) { schedule.objective += pm.ops[pm.graph.source(iait)]->wT(); } } else { schedule.objective += pm.ops[pm.graph.source(ait)]->wT(); } } } //Debugger::info << "Done collecting schedule data." << ENDL; return true; // Run BFS on the reverse graph to set due date for the operations Operation *so; Operation *to; ReverseDigraph<ListDigraph> rg(pm.graph); Bfs<ReverseDigraph<ListDigraph> > bfsr(rg); bfsr.init(); bfsr.addSource(pm.tail); //out << "Running BFS algorithm on the reverse graph ..." << endl; while (!bfsr.emptyQueue()) { curnode = bfsr.processNextNode(); if (pm.ops[curnode]->ID < 0) continue; //out << "Processing node with id= " << rg.id(curnode) << " " << *(pm.ops[curnode]) << endl; //out << "Next available nodes:" << endl; for (ReverseDigraph<ListDigraph>::OutArcIt it(rg, curnode); it != INVALID; ++it) { // Update the due dates of the reverse target nodes // Rev. target d == rev. source d. - rev. source longest processing time so = pm.ops[rg.source(it)]; to = pm.ops[rg.target(it)]; to->d(so->d() - rc(so->toolID).slowestMachine(so->type).procTime(so)); //out << "Node with id= " << rg.id(rg.target(it)) << " " << *(pm.ops[rg.target(it)]) << endl; } } so = to = NULL; //out << "Done running BFS algorithm on the reverse graph." << endl; return true; }