Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

model/jobs/SJob.h

Go to the documentation of this file.
00001 /* #start# ***********************************************************
00002 
00003            Scheduling Simulator
00004         Lehrstuhl f"ur Effiziente Algorithmen
00005            Technische Universit"at M"unchen
00006 
00007  File    : $Id: SJob.h,v 1.8 2003/03/21 15:47:05 taeubig Exp $
00008 
00009  Purpose : the base class for jobs, handles the processing state
00010            (what is being done with it, how long does it still need
00011            to be processed etc.)
00012 
00013  * #end# ************************************************************* */
00014 
00015 #ifndef SJOB_H
00016 #define SJOB_H
00017 
00018 // system header files
00019 #include <iostream>
00020 
00021 #include <LEDA/array.h>
00022 #include <LEDA/list.h>
00023 
00024 // project header files
00025 #include "../SVisJob.h"
00026 #include "../STSysSchedEvent.h"
00027 #include "../topos/STopology.h"
00028 #include "../../general/SObservable.h"
00029 #include "../../general/STypeInfo.h"
00030 #include "../../general/SPref.h"
00031 #include "../../probability/SProbabilityDist.h"
00032 
00033 // -----------------------------------------------------------------------
00034 class SJobMod;
00035 class SMachines;
00036 // -----------------------------------------------------------------------
00037 
00038 using std::cout;
00039 using std::endl;
00040 
00045 class SJob : public STypeInfo, public SObservable {
00046   friend class SJobMod;
00047   NOCOPY(SJob);
00048 public:
00049   
00053   //SJob();
00054 
00055   // create Job with dist-distributed random proc time
00056   SJob(SProbabilityDist* dist);
00057 
00058   // create Job with proc time = proctime
00059   SJob(double proctime = 1.0);
00060   
00063   virtual ~SJob();
00064 
00070   enum State {
00071     // not yet released -> cannot be scheduled
00072     HIDDEN,
00073     // can be scheduled, but is not running at the moment
00074     RELEASED,
00075     // job runs on a machine
00076     RUNNING,
00077     // job is completely finished (all phases are over for jobs with
00078     // multiple phases)
00079     FINISHED,
00080     // job has been rejected at a certain penalty
00081     REJECTED
00082   };
00083   
00089   virtual void reset();
00090 
00091   // access functions
00092 
00095   int getIndex() const { return _index; };
00096   
00101   virtual double getProcTime();
00102 
00103  
00107   virtual double getRemProcTime() const { return _remProcTime; };
00108   
00112   bool isFinished() const {
00113     return getRemProcTime() <= _pref.getProcTimeEps();
00114   };
00115 
00118   double getReleaseTime() const { return _releaseTime; };
00119   
00122   double getDueTime() const { return _dueTime; };
00123 
00126   /*
00127   double getFirstStartTime() const {
00128     return _firstStartTime;
00129   };
00130   */
00131 
00134   double getStartTime(int operation = 0) const {
00135     return _startTime[operation];
00136   };
00137 
00140   const leda_array<double>& getStartTimes() const {
00141     return _startTime;
00142   };
00143 
00146   const STopology& getTopology() const { return *_pTop; };
00147   
00148   /* Get weight (priority) of job. 
00149    */
00150   const double getWeight() const { return _weight; };
00151 
00152   // get and set the state of the job
00153 
00156   State getState() const { return _state; };
00160   virtual void setState(State s);
00161   
00164   bool getOverDue() const { return _due; };
00165 
00168   virtual void setOverDue();
00169   
00174   virtual SJobMod& getModifier() =0;
00175 
00176   // simulation control
00177 
00183   virtual double getNextEventTime(double currTime) const;
00196   void simulate(double oldTime, double newTime);
00204   virtual void process(SMachines& machines, double duration) =0;
00205   
00206   double getExpProcTime(){
00207     if (_randProcTime) {
00208       if (_expProcTime != _procTimeDist->getExpectation())
00209         // _expProcTime = _procTimeDist->getExpectation();
00210         cout << "Error: expected proctime != expectation of proctime dist" << endl;
00211     }
00212 
00213     return _expProcTime;
00214     };
00216   SProbabilityDist* getProcTimeDist();
00217  
00219   bool hasRandProcTime();
00220  
00221 
00222   
00223 
00224 protected:
00229   void advanceProcTime(double by);
00230 
00233   const SPref& getPref() const { return _pref; };
00234 
00235 private:
00236   //  void copy(const SJob& j);
00237 
00240   STopology* _pTop;
00244   SVisJob* _pVisJob;
00246   int _index;
00249   double _procTime;
00255   double _remProcTime;
00257   double _dueTime;
00259   double _releaseTime;
00261   leda_array<double> _startTime;
00262   State _state;
00264   SProbabilityDist* _procTimeDist;
00266   bool _procTimeSet;
00268   bool _relTimeSet;
00269   bool _due;
00272   double _weight;
00274   bool _randProcTime;
00276   double _expProcTime;
00277 public: // Public attributes
00278  
00280   SPref &_pref;
00281 };
00282 // -----------------------------------------------------------------------
00283 std::ostream& operator<<(std::ostream& out, SJob &job);  
00284 // -----------------------------------------------------------------------
00285 // DEFINE_PTR_COMPARE(SJob);
00286 inline int compare(SJob* p1, SJob* p2)
00287 {
00288   if (p1->getIndex() < p2->getIndex())
00289     return -1; 
00290   else if (p1->getIndex() > p2->getIndex())
00291     return 1;
00292   else {
00293     // make sure the the object is actually the same: compare the pointers
00294     if (p1 == p2)
00295       return 0;
00296     else if (p1 < p2)
00297       return -1;
00298     else
00299       return 1;
00300   }
00301 }
00302 // -----------------------------------------------------------------------
00303 
00304 
00305 #endif //SJOB_H
00306 
00307 

Generated on Thu May 22 16:48:09 2003 for Sketch-it! by doxygen1.2.18