00001 /****************************************************************** 00002 * 00003 * Filename : BAPPackage.h 00004 * Author : David Ong Tat-Wee 00005 * 00006 * Version : 1.02b 00007 * Date : 14 May 99 00008 * 00009 * Description : Interface file for problem package class. 00010 * 00011 * Reference : nil 00012 * 00013 * Notes : This class interfaces the algorithm functions with 00014 * the BAP domain classes. It has to encapsulate all 00015 * necessary information for solving the problem, based 00016 * on our problem model: 00017 * - the set of sections S 00018 * - the set of vessels V 00019 * - the intersection distance D 00020 * - the transhipment flows F 00021 * 00022 * Changes : 00023 * 14 May 99 00024 * Add ReadSolution() and WriteSolution() methods 00025 * Add mSolutionExists, mObjectiveValue and mPenalty attributes 00026 * Add VerifySolution() method 00027 * 00028 * Copyright : Copyright (c) 1998, 1999 00029 * All rights reserved by 00030 * Resource Allocation and Scheduling Group 00031 * Department of Information Systems and Computer Science 00032 * National University of Singapore 00033 * 00034 ******************************************************************/ 00035 00036 00037 #ifndef __BAP_PACKAGE__ 00038 #define __BAP_PACKAGE__ 00039 00040 #include "def.h" 00041 #include "BAPBase.h" 00042 00043 using leda::string; 00044 using leda::set; 00045 using leda::array; 00046 using leda::array2; 00047 00048 // 00049 // Structures are used to pass mass information to the user 00050 // 00051 struct Indicators 00052 { 00053 double ObjectiveValue; 00054 double Penalty; 00055 double TranshipmentCost; 00056 double Density; 00057 double ABD; 00058 }; 00059 00060 00061 class BAPPackage : public BAPBase 00062 { 00063 public: 00064 // This class takes in either 00065 // (i) a project filename 00066 // (ii) section, vessel and transshipment filenames 00067 // and constructs the necessary attributes and data structures for 00068 // storing the essential information 00069 BAPPackage(string aProjFile); 00070 BAPPackage(string aSectFile, string aVesFile, string aTransFile); 00071 ~BAPPackage(); 00072 00073 // 00074 // Debugging facility 00075 // 00076 // prints the current package information using the given indentation 00077 // width and in the given detail level 00078 void Print(int aWidth = 1, int aDetail = 0) const; 00079 00080 // 00081 // Accessor member functions 00082 // 00083 00084 // 00085 // Sections S info 00086 // 00087 // returns the number of sections 00088 int NumSections() const; 00089 // returns an array A of section lengths, 00090 // such that A[i] = length of section i 00091 array<int> SectionLengths() const; 00092 00093 // 00094 // Vessels V info 00095 // 00096 // returns the number of vessels 00097 int NumVessels() const; 00098 // returns an array A of vessel lengths, 00099 // such that A[i] = length of vessel i 00100 array<int> VesselLengths() const; 00101 // returns an array A of vessel arrival times, 00102 // such that A[i] = arrival time of vessel i 00103 array<int> Arrivals() const; 00104 // returns an array A of vessel departure times, 00105 // such that A[i] = departure time of vessel i 00106 array<int> Departures() const; 00107 00108 // 00109 // Intersection Distances D info 00110 // 00111 // returns a 2-dimensional array A of intersection distances, 00112 // such that A(k, l) = distance from section k to section l 00113 array2<int> Distances() const; 00114 00115 // 00116 // Transhipment Flows F info 00117 // 00118 // returns a 2-dimensional array A of transshipment flows, 00119 // such that A(i, j) = number of containers being exchanged between 00120 // vessel i and vessel j 00121 array2<int> Transhipments() const; 00122 00123 // 00124 // Solution Information 00125 // 00126 // returns an array A of (section, wharfmark) info, 00127 // so A[i].First() = section assigned to vessel i 00128 // A[i].Second() = wharfmark assigned to vessel i 00129 array<IntPair> Solution() const; 00130 // returns the section assigned to the given vessel 00131 int SectionAssignedTo(int aVesselID) const; 00132 // returns the wharfmark assigned to the given vessel 00133 int WharfmarkAssignedTo(int aVesselID) const; 00134 00135 // 00136 // Solution Indicators 00137 // 00138 // returns the objective value 00139 unsigned long ObjectiveValue() const; 00140 // returns the penalty value 00141 unsigned long Penalty() const; 00142 // returns the transshipment cost of the current solution 00143 unsigned long TranshipmentCost() const; 00144 // returns the density of the current vessel set 00145 double Density() const; 00146 // returns the ABD (Average Berth Demand) of the current vessel set 00147 double ABD() const; 00148 00149 // 00150 // Useful Information 00151 // 00152 // returns true if existing solution is found, false otherwise 00153 bool SolutionExists() const; 00154 // returns the number of time zones wrt to the current vessel set 00155 int NumTimeZones() const; 00156 // returns an array A of time zone info, 00157 // such that A[i].First() = start time of time zone i 00158 // A[i].End() = end time of time zone i 00159 array<IntPair> TimeZones() const; 00160 // returns the set of time zones spanned by the given vessel 00161 set<int> TimeZones(int aVesselID) const; 00162 // returns the set of vessels in the given time zone 00163 set<int> Vessels(int aTimeZoneID) const; 00164 // returns the start (first) time zone of the given vessel 00165 int StartTimeZone(int aVesselID) const; 00166 // returns the end (last) time zone of the given vessel 00167 int EndTimeZone(int aVesselID) const; 00168 // returns the arrival time of the given vessel 00169 int Arrival(int aVesselID) const; 00170 // returns the departure time of the given vessel 00171 int Departure(int aVesselID) const; 00172 00173 // returns the BAPPath specified by shell variable $BAPHOME 00174 string BAPPath() const; 00175 // returns the project filename 00176 string ProjectFilename() const; 00177 // returns the parameter filename 00178 string ParamFilename() const; 00179 // returns the partitioning solution filename 00180 string PartitioningFilename() const; 00181 // returns the packing solution filename 00182 string PackingFilename() const; 00183 // returns the partitioning trace file name 00184 string PartitioningTraceFilename() const; 00185 // returns the packing trace file name 00186 string PackingTraceFilename() const; 00187 00188 // writes the solution 00189 void WriteSolution(string aCreator, string aParamFile) const; 00190 // verifies the solution 00191 void VerifySolution() const; 00192 // analyzes the solution 00193 void AnalyzeSolution() const; 00194 00195 // 00196 // Modifier member functions 00197 // 00198 00199 // reads the solution 00200 void ReadSolution(); 00201 // reads the specific solution 00202 void ReadSolution(string aSolFile); 00203 00204 // 00205 // Functions to do assignment of vessels 00206 // 00207 // assigns the given vessel to the given section 00208 int SectionAssignedTo(int aVesselID, int aSectionID); 00209 // assigns the given vessel to the given wharfmark 00210 int WharfmarkAssignedTo(int aVesselID, int aWharfmark); 00211 00212 // 00213 // Change individual indicators 00214 // 00215 // sets the objective value 00216 unsigned long ObjectiveValue(unsigned long anObjValue); 00217 // sets the penalty value 00218 unsigned long Penalty(unsigned long aPenalty); 00219 // sets the transshipment cost to the given cost 00220 unsigned long TranshipmentCost(unsigned long aCost); 00221 // sets the density to the given density 00222 double Density(double aDensity); 00223 // sets the ABD to the given ABD 00224 double ABD(double aDemand); 00225 00226 00227 private: 00228 // 00229 // Modifier member functions 00230 // 00231 void ComputeTimeZones(); 00232 void Input(string aSectFile, string aVesFile, string aTransFile); 00233 00234 string const mProjectFilename; 00235 string mBAPPath; 00236 string mParamFilename; 00237 string mPartitioningFilename; 00238 string mPackingFilename; 00239 string mPartitioningTraceFilename; 00240 string mPackingTraceFilename; 00241 bool mSolutionExists; 00242 00243 // sections S 00244 array<int> *mSectionLengths; 00245 00246 // vessels V 00247 array<int> *mVesselLengths; 00248 array<int> *mArrivals; 00249 array<int> *mDepartures; 00250 00251 // intersection distances D 00252 array2<int> *mDistances; 00253 00254 // transhipment flows F 00255 array2<int> *mTranshipments; 00256 00257 // solution 00258 array<IntPair> *mSolution; // (section, wharfmark) pair 00259 00260 // useful information 00261 array<IntPair> *mTimeZones; // (start time, end time) pair 00262 set<int> *mVesselsInTimeZone; 00263 set<int> *mTimeZonesByVessel; 00264 00265 // indicators 00266 unsigned long mObjectiveValue; 00267 unsigned long mPenalty; 00268 unsigned long mTranshipmentCost; 00269 double mDensity; 00270 double mABD; 00271 00272 int mUnallocatedVessels; 00273 }; 00274 00275 00276 #endif