Example #1
0
// add to file info about schedule
void Scheduler::PrintOneWFSched(ofstream & res, Schedule & sched, int wfNum){
   res << "WF " << wfNum << endl;
   for (Schedule::iterator it = sched.begin(); it!= sched.end(); it++){
      res << "(" << it->get<0>() << " " << it->get<1>() << " " << it->get<3>() << " ";
      for (vector<int>::iterator it2 = it->get<2>().begin(); it2 != it->get<2>().end(); it2++)
         res << *it2 ;
      res << "))";
   }
   res << endl;
}
Example #2
0
// implements staging scheme for finding the schedule for WFs set
// <PRE> 0 <= firstWfNum < data.workflows.size()
double Scheduler::StagedScheme(int firstWfNum){
   cout << "StagedScheme(int) was called\n";
   try{
      int wfCount = data.GetWFCount();
      if (firstWfNum < 0 || firstWfNum > wfCount) 
         throw UserException("Scheduler::StagedScheme(int) error. Wrong init workflow number");
      // creating XML with init time windows
      //xmlWriter->SetXMLBaseName("Init_");
      Schedule oneWFsched;
      //xmlWriter->CreateXML(oneWFsched, -1);
      // ??!! think about it !
      xmlWriter->SetXMLBaseName("Staged_");
      //double stagedT = clock();

      //string resFileName = "staged_scheme_" + to_string(firstWfNum) + ".txt";
      //ofstream res(resFileName);
      //if (res.fail()) 
      //	throw UserException("Scheduler::StagedScheme(int) error. Unable to create res file");
      //res << "Stage 1, workflow # " << firstWfNum << endl;
      //cout << "Stage 1, workflow # " << firstWfNum << endl;
      
      vector <double> eff;
      // applying settings of scheduling method for initial WF
      unique_ptr <SchedulingMethod> method = SchedulingFactory::GetMethod(data, methodsSet[firstWfNum], firstWfNum);
      // getting schedule for first WF
      double oneStepStart = clock();
      eff.push_back(method->GetWFSchedule(oneWFsched));

      // set local to global packages
      int initNum = data.GetInitPackageNumber(firstWfNum);
      for (int i = 0; i < oneWFsched.size(); i++)
         oneWFsched[i].get<0>() += initNum;


      fullSchedule = oneWFsched;
      
      //cout << "Elapsed time: " << (clock()-oneStepStart)/1000.0 << " sec" << endl;
      scheduledWFs.push_back(firstWfNum);	
      //xmlWriter->CreateXML(oneWFsched, firstWfNum);
      // write result to XML
      data.FixBusyIntervals();

      
      // write result to res file
      //PrintOneWFSched(res, oneWFsched, firstWfNum);
      
      
      // we need to store current busy intervals
      // of schedule that give the best efficiency
      // current best schedule is stored in oneWFsched
      vector<vector <BusyIntervals>> storedIntervals;
      Schedule storedSched;

      while (scheduledWFs.size() != wfCount ){
         //cout << "Stage " << scheduledWFs.size() + 1 << endl;
         double stageMaxEff = numeric_limits<double>::infinity();
         int bestWfNum = -1;
         for (int i = 0; i < wfCount; i++){
            // if this WF wasn't scheduled yet
            if (find(scheduledWFs.begin(), scheduledWFs.end(), i) == scheduledWFs.end()){
               //cout << "CurrentWfNum = " << i << " ";
               oneStepStart = clock();
               method = SchedulingFactory::GetMethod(data, methodsSet[i], i);
               oneWFsched.clear();
               double currentEff = method->GetWFSchedule(oneWFsched);
               //cout << "Elapsed time: " << (clock()-oneStepStart)/1000.0 << " sec" << endl;
               /*ReadData(i);
               directBellman = false;
               BackBellmanProcedure();
               directBellman = true;
               double currentEff = DirectBellman(i);*/
               if (stageMaxEff > currentEff){
                  stageMaxEff = currentEff;
                  bestWfNum = i;
                  storedSched = oneWFsched;
                  storedIntervals.clear();
                  data.GetCurrentIntervals(storedIntervals);
                  //GetBestBusyIntervals(bestBusyIntervals);
               }
               data.ResetBusyIntervals(); // newfag in my program
               //states.clear(); controls.clear(); nextStateNumbers.clear(); stagesCores.clear();
            }
         }
         // set local to global packages
         int initNum = data.GetInitPackageNumber(bestWfNum);
         for (int i = 0; i < storedSched.size(); i++)
            storedSched[i].get<0>() += initNum;

         copy(storedSched.begin(), storedSched.end(), back_inserter(fullSchedule));
         //copy(bestStagesCores.begin(), bestStagesCores.end(),back_inserter(allStagesCores));
         scheduledWFs.push_back(bestWfNum);
         //usedNums = scheduledWFs; ???
         //stagesCores = bestStagesCores;
         //currentWfNum = bestWfNum;
         eff.push_back(stageMaxEff);
         // set current intervals as stored intervals
         data.SetCurrentIntervals(storedIntervals);
         // write result to XML
         // xmlWriter->CreateXML(storedSched, bestWfNum);
         // write result to res file
      //	PrintOneWFSched(res, storedSched, bestWfNum);
           
         data.FixBusyIntervals();
         
         /*SetBestBusyIntervals(bestBusyIntervals);
         FixNewBusyIntervals();
         BellmanToXML(true);*/
         //std::system("pause");
      }
      /*usedNums = scheduledWFs; ???
      SetFirstBusyIntervals();
      stagesCores = allStagesCores;
      BellmanToXML(false);*/
      //PrintFooter(res, eff);
      double sumEff = 0.0;
      for (int i = 0; i < eff.size(); i++)
         sumEff += eff[i];
      
      data.SetInitBusyIntervals();
      //xmlWriter->CreateXML(fullSchedule, -1);
      //res.close();
      cout << "Max eff: " << sumEff/maxPossible << endl;
      //cout << "Elapsed time: " << (clock()-stagedT)/1000.0 << " sec" << endl;
      return sumEff/maxPossible ;
   }
   catch (UserException& e){
      cout<<"error : " << e.what() <<endl;
      std::system("pause");
      exit(EXIT_FAILURE);
   }
}
Example #3
0
// scheduling ordered due to prioretization criteria
void Scheduler::OrderedScheme(int criteriaNumber){
   try{
      maxEff = 0.0;
      // get pointer to criteria 
      unique_ptr<CriteriaMethod> criteria = CriteriaFactory::GetMethod(data,criteriaNumber);
      bool tendsToMin = criteria->TendsToMin();
      // unscheduled WF numbers
      vector <int> unscheduled;
      for (int i = 0; i < data.GetWFCount(); i++)
         unscheduled.push_back(i);
      int stage = 0;
      // while we have unscheduled WFs
      while (unscheduled.size() != 0){
         //if (stage % 10 == 0) cout << "Stage " << stage << endl;
         stage++;
         // best schedule (from the prioretization criteria point of view)
         Schedule best;
         // and "best" wf number
         int bestWFNum = -1;
         // max eff (on this iteration)
         double currentBestEff = 0.0;
         // current best criteria value
         double bestCriteria = tendsToMin ? numeric_limits<double>::max() : 
            -1 * numeric_limits<double>::max();
         // busy intervals for best schedule

         vector<vector <BusyIntervals>> storedIntervals;
         // for each unscheduled WF
         for (auto &wfNum : unscheduled){
            Schedule current;
            unique_ptr <SchedulingMethod> method = 
               SchedulingFactory::GetMethod(data, methodsSet[wfNum], wfNum);
            // get current schedule in current variable
            double currentEff = method->GetWFSchedule(current);
            // get current criteria
            double currentCriteria = criteria->GetCriteria(current, wfNum);
            if (criteria->IsBetter(currentCriteria, bestCriteria)){
               best = current;
               bestWFNum = wfNum;
               currentBestEff = currentEff;
               bestCriteria = currentCriteria;
               storedIntervals.clear();
               data.GetCurrentIntervals(storedIntervals);
            }
            data.ResetBusyIntervals();
         }

         // set local to global packages
         int initNum = data.GetInitPackageNumber(bestWFNum);
         for (int i = 0; i < best.size(); i++)
            best[i].get<0>() += initNum;
         // add best schedule to full schedule
         copy(best.begin(), best.end(), back_inserter(fullSchedule));

         data.SetCurrentIntervals(storedIntervals);
         data.FixBusyIntervals();

         maxEff += currentBestEff;

         //cout << "Best wf num: " << bestWFNum << " bestCriteria: " << bestCriteria << endl;
         if (bestWFNum == -1) { 
            cout << "unscheduled.size() == " << unscheduled.size() << endl;
            break;
         }
         auto idx = find(unscheduled.begin(), unscheduled.end(), bestWFNum);
         if (idx == unscheduled.end()) 
            throw UserException("Scheduler::OrderedScheme(int) error. Best wf number was not found");
         unscheduled.erase(idx);
      }
      data.SetInitBusyIntervals();
      maxEff /= maxPossible;
      cout << "Ordered scheme eff: " << maxEff << endl;
      xmlWriter->SetXMLBaseName("Ordered_");
      // write result to XML
      xmlWriter->CreateXML(fullSchedule, -1);
      string resFileName = "ordered.txt";
      ofstream res(resFileName);
      if (res.fail()) 
         throw UserException("Scheduler::OrderedScheme error. Unable to create res file");
      PrintOneWFSched(res, fullSchedule, -1);
      res.close();
   }
   catch (UserException& e){
      cout<<"error : " << e.what() <<endl;
      std::system("pause");
      exit(EXIT_FAILURE);
   }
}