#include <MSVehicleContainer.h>
Definition at line 52 of file MSVehicleContainer.h.
Public Types | |
| typedef std::pair< SUMOTime, VehicleVector > | VehicleDepartureVector |
| typedef std::vector< MSVehicle * > | VehicleVector |
| definition of a list of vehicles which have the same departure time | |
Public Member Functions | |
| void | add (SUMOTime time, const VehicleVector &cont) |
| Adds a container with vehicles departing at the given time. | |
| void | add (MSVehicle *veh) |
| Adds a single vehicle. | |
| bool | anyWaitingFor (SUMOTime time) const |
| Returns the information whether any vehicles want to depart at the given time. | |
| bool | isEmpty () const |
| Returns the information whether the container is empty. | |
| MSVehicleContainer (size_t capacity=10) | |
| Constructor. | |
| void | pop () |
| Removes the uppermost vehicle vector. | |
| void | showArray () const |
| Prints the container (the departure times). | |
| size_t | size () const |
| Returns the size of the container. | |
| const VehicleVector & | top () |
| Returns the uppermost vehicle vector. | |
| SUMOTime | topTime () const |
| Returns the time the uppermost vehicle vector is assigned to. | |
| ~MSVehicleContainer () | |
| Destructor. | |
Private Types | |
| typedef std::vector < VehicleDepartureVector > | VehicleHeap |
| Definition of the heap type. | |
Private Member Functions | |
| void | addReplacing (const VehicleDepartureVector &cont) |
| Replaces the existing single departure time vector by the one given. | |
| bool | isFull () const |
| void | percolateDown (int hole) |
| Moves the elements down. | |
Private Attributes | |
| VehicleHeap | array |
| The vehicle vector heap. | |
| int | currentSize |
| Number of elements in heap. | |
Friends | |
| std::ostream & | operator<< (std::ostream &strm, MSVehicleContainer &cont) |
| Prints the contents of the container. | |
Data Structures | |
| class | DepartFinder |
| Searches for the VehicleDepartureVector with the wished depart. More... | |
| class | VehicleDepartureVectorSortCrit |
| Sort-criterion for vehicle departure lists. More... | |
| typedef std::pair<SUMOTime, VehicleVector> MSVehicleContainer::VehicleDepartureVector |
definition of a structure storing the departure time and a list of vehicles leaving at this time
Definition at line 59 of file MSVehicleContainer.h.
typedef std::vector<VehicleDepartureVector> MSVehicleContainer::VehicleHeap [private] |
| typedef std::vector<MSVehicle*> MSVehicleContainer::VehicleVector |
definition of a list of vehicles which have the same departure time
Definition at line 55 of file MSVehicleContainer.h.
| MSVehicleContainer::MSVehicleContainer | ( | size_t | capacity = 10 |
) |
Constructor.
Definition at line 72 of file MSVehicleContainer.cpp.
00073 : currentSize(0), array(capacity + 1, VehicleDepartureVector()) {}
| MSVehicleContainer::~MSVehicleContainer | ( | ) |
| void MSVehicleContainer::add | ( | SUMOTime | time, | |
| const VehicleVector & | cont | |||
| ) |
Adds a container with vehicles departing at the given time.
Definition at line 100 of file MSVehicleContainer.cpp.
References addReplacing(), array, and currentSize.
00100 { 00101 VehicleHeap::iterator j = 00102 find_if(array.begin()+1, array.begin()+currentSize+1, 00103 DepartFinder(time)); 00104 if (currentSize==0 || j==array.begin()+currentSize+1) { 00105 VehicleDepartureVector newElem(time, 00106 VehicleVector(cont)); 00107 addReplacing(newElem); 00108 } else { 00109 VehicleVector &stored = (*j).second; 00110 stored.reserve(stored.size() + cont.size()); 00111 copy(cont.begin(), cont.end(), back_inserter(stored)); 00112 } 00113 }
| void MSVehicleContainer::add | ( | MSVehicle * | veh | ) |
Adds a single vehicle.
Definition at line 82 of file MSVehicleContainer.cpp.
References addReplacing(), array, currentSize, and MSVehicle::getDesiredDepart().
Referenced by MSEmitControl::add().
00082 { 00083 // check whether a new item shall be added or the vehicle may be 00084 // added to an existing list 00085 VehicleHeap::iterator i = 00086 find_if(array.begin()+1, array.begin()+currentSize+1, DepartFinder(veh->getDesiredDepart())); 00087 if (currentSize==0 || i==array.begin()+currentSize+1) { 00088 // a new heap-item is necessary 00089 VehicleDepartureVector newElem(veh->getDesiredDepart(), VehicleVector()); 00090 newElem.second.push_back(veh); 00091 addReplacing(newElem); 00092 } else { 00093 // add vehicle to an existing heap-item 00094 (*i).second.push_back(veh); 00095 } 00096 }
| void MSVehicleContainer::addReplacing | ( | const VehicleDepartureVector & | cont | ) | [private] |
Replaces the existing single departure time vector by the one given.
Definition at line 118 of file MSVehicleContainer.cpp.
References array, currentSize, and isFull().
Referenced by add().
00118 { 00119 if (isFull()) { 00120 std::vector<VehicleDepartureVector> array2((array.size()-1)*2+1, VehicleDepartureVector()); 00121 for (size_t i=array.size(); i-->0;) { 00122 assert(array2.size()>i); 00123 array2[i] = array[i]; 00124 } 00125 array = array2; 00126 } 00127 00128 // Percolate up 00129 int hole = ++currentSize; 00130 for (; hole > 1 && (x.first < array[ hole / 2 ].first); hole /= 2) { 00131 assert(array.size()>(size_t) hole); 00132 array[ hole ] = array[ hole / 2 ]; 00133 } 00134 assert(array.size()>(size_t) hole); 00135 array[ hole ] = x; 00136 }
Returns the information whether any vehicles want to depart at the given time.
Definition at line 140 of file MSVehicleContainer.cpp.
References array, and currentSize.
Referenced by MSEmitControl::emitVehicles().
00140 { 00141 VehicleHeap::const_iterator j = 00142 find_if(array.begin()+1, array.begin()+currentSize+1, DepartFinder(time)); 00143 return j!=array.begin()+currentSize+1; 00144 }
| bool MSVehicleContainer::isEmpty | ( | ) | const |
Returns the information whether the container is empty.
Definition at line 179 of file MSVehicleContainer.cpp.
References currentSize.
Referenced by MSEmitControl::checkPrevious(), operator<<(), pop(), top(), and topTime().
00179 { 00180 return currentSize == 0; 00181 }
| bool MSVehicleContainer::isFull | ( | ) | const [private] |
Returns the information whether the container must be extended
Definition at line 185 of file MSVehicleContainer.cpp.
References array, and currentSize.
Referenced by addReplacing().
00185 { 00186 return currentSize >= ((int) array.size()) - 1; 00187 }
| void MSVehicleContainer::percolateDown | ( | int | hole | ) | [private] |
Moves the elements down.
Definition at line 191 of file MSVehicleContainer.cpp.
References array, and currentSize.
Referenced by pop().
00191 { 00192 int child; 00193 assert(array.size()>(size_t)hole); 00194 VehicleDepartureVector tmp = array[ hole ]; 00195 00196 for (; hole * 2 <= currentSize; hole = child) { 00197 child = hole * 2; 00198 if (child != currentSize && (array[ child + 1 ].first < array[ child ].first)) 00199 child++; 00200 if ((array[ child ].first < tmp.first)) { 00201 assert(array.size()>(size_t) hole); 00202 array[ hole ] = array[ child ]; 00203 } else 00204 break; 00205 } 00206 assert(array.size()>(size_t) hole); 00207 array[ hole ] = tmp; 00208 }
| void MSVehicleContainer::pop | ( | ) |
Removes the uppermost vehicle vector.
!!Underflow( );
Definition at line 166 of file MSVehicleContainer.cpp.
References array, currentSize, isEmpty(), and percolateDown().
Referenced by MSEmitControl::checkPrevious(), MSEmitControl::emitVehicles(), and operator<<().
00168 { 00169 if (isEmpty()) 00170 throw 1; 00171 00172 assert(array.size()>1); 00173 array[ 1 ] = array[ currentSize-- ]; 00174 percolateDown(1); 00175 }
| void MSVehicleContainer::showArray | ( | ) | const |
Prints the container (the departure times).
Definition at line 218 of file MSVehicleContainer.cpp.
References array, and currentSize.
00218 { 00219 for (VehicleHeap::const_iterator i=array.begin()+1; i!=array.begin()+currentSize+1; ++i) { 00220 if (i!=array.begin()+1) { 00221 std::cout << ", "; 00222 } 00223 std::cout << (*i).first; 00224 } 00225 std::cout << std::endl << "-------------------------" << std::endl; 00226 }
| size_t MSVehicleContainer::size | ( | ) | const |
Returns the size of the container.
Definition at line 212 of file MSVehicleContainer.cpp.
References currentSize.
00212 { 00213 return currentSize; 00214 }
| const MSVehicleContainer::VehicleVector & MSVehicleContainer::top | ( | ) |
Returns the uppermost vehicle vector.
!!Underflow( );
Definition at line 148 of file MSVehicleContainer.cpp.
References array, and isEmpty().
Referenced by MSEmitControl::checkPrevious(), MSEmitControl::emitVehicles(), and operator<<().
00148 { 00149 if (isEmpty()) 00150 throw 1; 00151 assert(array.size()>1); 00152 return array[ 1 ].second; 00153 }
| SUMOTime MSVehicleContainer::topTime | ( | ) | const |
Returns the time the uppermost vehicle vector is assigned to.
!!Underflow( );
Definition at line 157 of file MSVehicleContainer.cpp.
References array, and isEmpty().
Referenced by MSEmitControl::checkPrevious().
00157 { 00158 if (isEmpty()) 00159 throw 1; 00160 assert(array.size()>1); 00161 return array[ 1 ].first; 00162 }
| std::ostream& operator<< | ( | std::ostream & | strm, | |
| MSVehicleContainer & | cont | |||
| ) | [friend] |
Prints the contents of the container.
Definition at line 229 of file MSVehicleContainer.cpp.
00229 { 00230 strm << "------------------------------------" << std::endl; 00231 while (!cont.isEmpty()) { 00232 const MSVehicleContainer::VehicleVector &v = cont.top(); 00233 for (MSVehicleContainer::VehicleVector::const_iterator i=v.begin(); i!=v.end(); ++i) { 00234 strm << (*i)->getDesiredDepart() << std::endl; 00235 } 00236 cont.pop(); 00237 } 00238 return strm; 00239 }
VehicleHeap MSVehicleContainer::array [private] |
The vehicle vector heap.
Definition at line 136 of file MSVehicleContainer.h.
Referenced by add(), addReplacing(), anyWaitingFor(), isFull(), percolateDown(), pop(), showArray(), top(), and topTime().
int MSVehicleContainer::currentSize [private] |
Number of elements in heap.
Definition at line 130 of file MSVehicleContainer.h.
Referenced by add(), addReplacing(), anyWaitingFor(), isEmpty(), isFull(), percolateDown(), pop(), showArray(), and size().
1.5.6