00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SJOB_H
00016 #define SJOB_H
00017
00018
00019 #include <iostream>
00020
00021 #include <LEDA/array.h>
00022 #include <LEDA/list.h>
00023
00024
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
00054
00055
00056 SJob(SProbabilityDist* dist);
00057
00058
00059 SJob(double proctime = 1.0);
00060
00063 virtual ~SJob();
00064
00070 enum State {
00071
00072 HIDDEN,
00073
00074 RELEASED,
00075
00076 RUNNING,
00077
00078
00079 FINISHED,
00080
00081 REJECTED
00082 };
00083
00089 virtual void reset();
00090
00091
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
00128
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
00149
00150 const double getWeight() const { return _weight; };
00151
00152
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
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
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
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:
00278
00280 SPref &_pref;
00281 };
00282
00283 std::ostream& operator<<(std::ostream& out, SJob &job);
00284
00285
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
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