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

task.cc

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2000 Alan McIvor <alan@mcivor.gen.nz>
00003 **  
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 ** 
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 ** 
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software 
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 #include <cstdarg>
00019 
00020 using namespace std;
00021 
00022 #include "task.h"
00023 #include "projectExceptions.h"
00024 
00025 TASK::TASK(char *id, char *name, int duration):
00026   NAMED_ID(id, name)
00027 {
00028     mDesc = NULL;
00029     mOverrun = NULL;
00030     mDuration = duration;
00031     mFullduration = duration;
00032     remaining = -1;
00033     rremaining = -1;
00034     mAssigned = NULL;
00035     mStart = INVALIDDAYNO;
00036     mFinish = INVALIDDAYNO;
00037     mLstart = INVALIDDAYNO;
00038     mLfinish = INVALIDDAYNO;
00039     mSlack = 0;
00040     mAstart = INVALIDDAYNO;
00041     mAfinish = INVALIDDAYNO;
00042     mBstart = INVALIDDAYNO;
00043     mBfinish = INVALIDDAYNO;
00044     mChildren = 0;
00045     mBlock = false;
00046     scheduled = 0;
00047     rscheduled = 0;
00048     x1 = x2 = y1 = y2 = 0;
00049     nx = ny = -1;
00050     mnDays = 0;
00051     mParents = 0;
00052     mPercentComplete = 0.0;
00053 }
00054 
00055 
00056 void TASK::Error(char *fmt, ...) 
00057 {
00058     char buf[1024];
00059     va_list args;
00060 
00061     va_start(args, fmt);
00062     vsprintf(buf, fmt, args);
00063     va_end(args);
00064 
00065     string sid = id();
00066     throw TASKException( sid, buf );
00067 }
00068 
00069 
00070 void TASK::setDaysDone(int days)
00071 {
00072     mnDays = days;
00073 }
00074 
00075 
00076 void TASK::Blockify()
00077 {
00078     mBlock = true;
00079 }
00080 
00081 
00082 void TASK::setDesc( char * desc )
00083 {
00084     mDesc = strdup(desc);
00085 }
00086 
00087 void TASK::setPercentComplete( double c )
00088 {
00089     if( c < 0.0 || c > 100.0 )
00090         Error("Invalid completion (should be 0<=%s<=100)", c);
00091     mPercentComplete = c;
00092 }
00093 
00094 
00095 void TASK::AddNote(const string & note)
00096 {
00097     mNotes.push_back(note);
00098 }
00099 
00100 
00101 void TASK::addDepends( TASK * depends ) 
00102 { 
00103     mDepends.push_back( depends ); 
00104     ++depends->mChildren;
00105 };
00106 
00107 
00108 void  TASK::addFollows( TASK * follows )
00109 { 
00110     mFollows.push_back( follows );
00111     ++follows->mParents;
00112 }
00113 
00114 
00115 void TASK::addTimeBlock(RESOURCE *r, int start, int finish, TimeBlock::Type type)
00116 {
00117     mWhen.push_back(TaskTimeBlock(r, start, finish, type));
00118 }
00119 
00120 
00121 void TASK::addReverseTimeBlock(RESOURCE *r, int start, int finish, TimeBlock::Type type)
00122 {
00123     mRwhen.push_back(TaskTimeBlock(r, start, finish, type));
00124 }
00125 
00126 
00127 void TASK::copyWhenToReverseWhen()
00128 {
00129     mRwhen = mWhen;
00130 }
00131 
00132 
00133 bool TASK::DayBooked( int dayNo )
00134 {
00135     for ( TaskTimeBlockIterator tb = mWhen.begin(); tb != mWhen.end() ; tb++ )
00136         if ( tb->start() <= dayNo && tb->finish() >= dayNo )
00137             return true;
00138     return false;
00139 }
00140 
00141 
00142 bool TASK::overlap(int start, int finish)
00143 {
00144     for ( TaskTimeBlockIterator tb = mWhen.begin(); tb != mWhen.end(); tb++ )
00145         if ( tb->overlap(start, finish) )
00146             return true;
00147     return false;
00148 }
00149 
00150 
00151 bool TASK::isActiveDuring(int start, int finish)
00152 {
00153     if ( start <= mStart && mStart <= finish )
00154         return true;
00155     if ( start <= mFinish && mFinish <= finish )
00156         return true;
00157     if ( mStart <= start && start <= mFinish )
00158         return true;
00159     if ( mStart <= finish && finish <= mFinish )
00160         return true;
00161     return false;
00162 }
00163 
00164 
00165 void TASK::addCandidate(RESOURCE *res)
00166 {
00167     mCando.push_back(res);
00168 }
00169 
00170 double TASK::timeCost()
00171 {
00172     return mAssigned->rate() * mDuration;
00173 }
00174 
00175 
00176 double TASK::itemCost()
00177 {
00178     double value = 0.0;
00179     for ( ITEM::PTRLIST::const_iterator ip = mItems.begin() ; ip != mItems.end() ; ip++)
00180         value += (*ip)->cost();
00181 
00182     return value;
00183 }
00184 
00185 
00186 bool CompareTaskResources::operator()(const TASK * t1, const TASK * t2) const
00187 {
00188     int deltar = strcmp(t1->assigned()->id(), t2->assigned()->id());
00189     if ( deltar != 0 )
00190         return deltar < 0;
00191 
00192     return t1->start() < t2->start();
00193 }
00194 
00195 
00196 

Generated on Wed Feb 18 22:23:54 2004 for Opensched by doxygen1.2.15