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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eoVRPUtils_h
00037 #define eoVRPUtils_h
00038
00039
00040 #include <vector>
00041 #include <utility>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <sstream>
00045 #include <math.h>
00046
00052 #define PI 3.14159265
00053
00060 #define VEHICLE_CAPACITY 200
00061
00062
00063 typedef std::vector<int> Route;
00064 typedef std::vector< Route > Routes;
00065
00066
00072 namespace eoVRPUtils {
00073
00086 typedef struct ClientData {
00087
00088 unsigned id;
00089 double x;
00090 double y;
00091 double demand;
00092 double readyTime;
00093 double dueTime;
00094 double serviceTime;
00096 } ClientDataT;
00097
00098
00099 static std::vector <ClientDataT> clients;
00100 static std::vector <std::vector <double> > dist;
00108 void computeDistances () {
00109
00110 unsigned numClients = clients.size ();
00111
00112 dist.resize (numClients) ;
00113
00114 for (unsigned i = 0; i < dist.size (); i ++)
00115 dist [i].resize (numClients);
00116
00117
00118 for (unsigned i = 0; i < dist.size (); i ++)
00119 for (unsigned j = i + 1 ; j < dist.size (); j ++) {
00120
00121 double distX = clients [i].x - clients [j].x;
00122 double distY = clients [i].y - clients [j].y;
00123
00124 dist [i][j] = dist [j][i] = sqrt (distX * distX + distY * distY);
00125
00126 }
00127
00128 }
00129
00130
00139 void getTimeWindow (unsigned _client, double& _readyTime, double& _dueTime, double& _serviceTime) {
00140
00141 assert (_client >= 0 && _client < clients.size ());
00142
00143 _readyTime = clients [_client].readyTime;
00144 _dueTime = clients [_client].dueTime;
00145 _serviceTime = clients [_client].serviceTime;
00146
00147 }
00148
00149
00157 float distance (unsigned _from, unsigned _to) {
00158
00159 assert (_from >= 0 && _from < clients.size ());
00160 assert (_to >= 0 && _to < clients.size ());
00161
00162 return dist [_from][_to];
00163
00164 }
00165
00166
00174 float polarAngle (unsigned _from, unsigned _to) {
00175
00176 assert (_from >= 0 && _from < clients.size ());
00177 assert (_to >= 0 && _to < clients.size ());
00178
00179 double angle = atan2 (clients [_from].y - clients [_to].y,
00180 clients [_from].x - clients [_to].x);
00181
00182
00183 angle *= 180 / PI;
00184
00185 if (angle < 0)
00186 angle *= -1;
00187
00188 return angle;
00189
00190 }
00191
00192
00199 void load (const char* _fileName) {
00200
00201 std::ifstream f (_fileName);
00202
00203 if (f) {
00204
00205 while (!f.eof ()) {
00206
00207 ClientDataT client;
00208
00209 f >> client.id;
00210 f >> client.x;
00211 f >> client.y;
00212 f >> client.demand;
00213 f >> client.readyTime;
00214 f >> client.dueTime;
00215 f >> client.serviceTime;
00216
00217 clients.push_back (client);
00218
00219 }
00220
00221 f.close ();
00222
00223 computeDistances ();
00224
00225 }
00226 else {
00227
00228 std::cerr << "Error: the file: " << _fileName << " doesn't exist !!!" << std::endl ;
00229 exit (1);
00230
00231 }
00232
00233 }
00234
00235
00241 void printRoute (const Route& _route) {
00242
00243 std::cout << "[";
00244
00245 for (unsigned i = 0; i < _route.size (); i++) {
00246
00247 std::cout << _route [i];
00248
00249 if (i != _route.size () -1)
00250 std::cout << ", ";
00251
00252 }
00253
00254 std::cout << "]";
00255
00256 }
00257
00258
00264 void printRoutes (Routes& _routes) {
00265
00266 std::cout << "[";
00267
00268 for (unsigned i = 0; i < _routes.size (); i++) {
00269
00270 std::cout << "[";
00271
00272 for (unsigned j = 0; j < _routes [i].size (); j++) {
00273
00274 std::cout << _routes [i][j];
00275
00276 if (j != _routes [i].size () -1)
00277 std::cout << ", ";
00278
00279 }
00280
00281 if (i == _routes.size () -1)
00282 std::cout << "]";
00283 else
00284 std::cout << "]," << std::endl;
00285 }
00286
00287 std::cout << "]";
00288
00289 }
00290
00291
00292 };
00293
00294 #endif