00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "BAPTVSection.h"
00026
00027 using std::cout;
00028 using std::endl;
00029
00030 TVSection::TVSection()
00031 : mID(0), mMaxTimeZone(0), mLength(0)
00032 {
00033 }
00034
00035
00036 TVSection::TVSection(int anID, int aMaxTimeZone, int aLength)
00037 : mID(anID), mMaxTimeZone(aMaxTimeZone), mLength(aLength),
00038 mCapacity(array<int>(1, aMaxTimeZone))
00039 {
00040 for (int i = 1; i <= aMaxTimeZone; i++)
00041 {
00042 mCapacity[i] = aLength;
00043 }
00044 }
00045
00046
00047 TVSection::TVSection(const TVSection& aSection)
00048 : mID(aSection.mID),
00049 mLength(aSection.mLength),
00050 mMaxTimeZone(aSection.mMaxTimeZone),
00051 mCapacity(array<int>(aSection.mCapacity.low(),
00052 aSection.mCapacity.high())),
00053 mVessels(aSection.mVessels)
00054 {
00055 for (int i = 1; i <= mMaxTimeZone; i++)
00056 {
00057 mCapacity[i] = aSection.mCapacity[i];
00058 }
00059 }
00060
00061
00062 TVSection::~TVSection()
00063 {
00064 }
00065
00066
00067 TVSection& TVSection::operator=(const TVSection& aSection)
00068 {
00069 if (this != &aSection)
00070 {
00071 mID = aSection.mID;
00072 mLength = aSection.mLength;
00073 mMaxTimeZone = aSection.mMaxTimeZone;
00074 mCapacity = aSection.mCapacity;
00075 mVessels = aSection.mVessels;
00076 }
00077
00078 return (*this);
00079 }
00080
00081
00082 void TVSection::Print(const int& aWidth, const int& aDetail) const
00083 {
00084 cout << "TVSection " << mID << ", length = " << mLength
00085 << ", max time zone = " << mMaxTimeZone << endl;
00086
00087 if (aDetail > 1)
00088 {
00089 cout << "capacity:" << endl;
00090
00091 for (int i = 1; i <= mMaxTimeZone; i++)
00092 {
00093 cout << setw(8) << mCapacity[i];
00094 }
00095
00096 cout << endl;
00097 }
00098
00099 cout << "vessels in section =" << endl;
00100
00101 int v;
00102
00103 forall(v, mVessels)
00104 {
00105 cout << setw(5) << v;
00106 }
00107
00108 cout << endl << endl;
00109 }
00110
00111
00112 istream& operator>>(istream& anIS, TVSection& aSection)
00113 {
00114 return anIS;
00115 }
00116
00117
00118 ostream& operator<<(ostream& anOS, const TVSection& aSection)
00119 {
00120 return anOS << "section " << setw(2) << aSection.mID;
00121 }
00122
00123
00124 int compare(const TVSection& aS1, const TVSection& aS2)
00125 {
00126 return compare(aS1.mID, aS2.mID);
00127 }
00128
00129 int TVSection::ID() const
00130 {
00131 return mID;
00132 }
00133
00134
00135 int TVSection::Length() const
00136 {
00137 return mLength;
00138 }
00139
00140
00141 bool TVSection::CanAccommodate(const TVVessel& aVessel) const
00142 {
00143 int VesLen = aVessel.Length();
00144
00145 for (int i = aVessel.StartTimeZone(); i <= aVessel.EndTimeZone(); i++)
00146 {
00147 if (mCapacity[i] < VesLen)
00148 return false;
00149 }
00150
00151 return true;
00152 }
00153
00154
00155 const set<int>& TVSection::Vessels() const
00156 {
00157 return mVessels;
00158 }
00159
00160
00161 void TVSection::Add(const TVVessel& aVessel)
00162 {
00163 assert(!mVessels.member(aVessel.ID()));
00164
00165 int VesLen = aVessel.Length();
00166
00167 for (int i = aVessel.StartTimeZone(); i <= aVessel.EndTimeZone(); i++)
00168 {
00169 mCapacity[i] -= VesLen;
00170 assert(mCapacity[i] >= 0);
00171 }
00172
00173 mVessels.insert(aVessel.ID());
00174 }
00175
00176
00177 void TVSection::Remove(const TVVessel& aVessel)
00178 {
00179 assert(mVessels.member(aVessel.ID()));
00180
00181 int VesLen = aVessel.Length();
00182
00183 for (int i = aVessel.StartTimeZone(); i <= aVessel.EndTimeZone(); i++)
00184 {
00185 mCapacity[i] += VesLen;
00186 assert(mCapacity[i] <= mLength);
00187 }
00188
00189 mVessels.del(aVessel.ID());
00190 }
00191