LCOV - code coverage report
Current view: top level - models/abm - trip_list.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 19 100.0 %
Date: 2024-11-18 12:45:26 Functions: 7 9 77.8 %

          Line data    Source code
       1             : /* 
       2             : * Copyright (C) 2020-2024 MEmilio
       3             : *
       4             : * Authors: Elisabeth Kluth, Daniel Abele
       5             : *
       6             : * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
       7             : *
       8             : * Licensed under the Apache License, Version 2.0 (the "License");
       9             : * you may not use this file except in compliance with the License.
      10             : * You may obtain a copy of the License at
      11             : *
      12             : *     http://www.apache.org/licenses/LICENSE-2.0
      13             : *
      14             : * Unless required by applicable law or agreed to in writing, software
      15             : * distributed under the License is distributed on an "AS IS" BASIS,
      16             : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      17             : * See the License for the specific language governing permissions and
      18             : * limitations under the License.
      19             : */
      20             : #include "abm/trip_list.h"
      21             : #include "abm/random_events.h"
      22             : #include "memilio/utils/stl_util.h"
      23             : 
      24             : namespace mio
      25             : {
      26             : namespace abm
      27             : {
      28             : 
      29         217 : TripList::TripList()
      30         217 :     : m_trips_weekday({})
      31         217 :     , m_trips_weekend({})
      32         217 :     , m_current_index(0)
      33             : {
      34         217 : }
      35             : 
      36         189 : const Trip& TripList::get_next_trip(bool weekend) const
      37             : {
      38         189 :     return weekend ? m_trips_weekend[m_current_index] : m_trips_weekday[m_current_index];
      39             : }
      40             : 
      41         279 : TimePoint TripList::get_next_trip_time(bool weekend) const
      42             : {
      43         279 :     return weekend ? m_trips_weekend[m_current_index].time : m_trips_weekday[m_current_index].time;
      44             : }
      45             : 
      46           9 : void TripList::use_weekday_trips_on_weekend()
      47             : {
      48           9 :     m_trips_weekend = m_trips_weekday;
      49           9 : }
      50             : 
      51         189 : void TripList::add_trip(Trip trip, bool weekend)
      52             : {
      53             :     //Trips are sorted by time.
      54             :     //Also include the person id in the comparison so different persons can make trips at the same time.
      55             :     //The same person can only make one trip at the same time.
      56         189 :     if (!weekend) {
      57         342 :         insert_sorted_replace(m_trips_weekday, trip, [](auto& trip1, auto& trip2) {
      58         180 :             return std::tie(trip1.time, trip1.person_id) < std::tie(trip2.time, trip2.person_id);
      59             :         });
      60             :     }
      61             :     else {
      62          81 :         insert_sorted_replace(m_trips_weekend, trip, [](auto& trip1, auto& trip2) {
      63          54 :             return std::tie(trip1.time, trip1.person_id) < std::tie(trip2.time, trip2.person_id);
      64             :         });
      65             :     }
      66         189 : }
      67             : 
      68             : } // namespace abm
      69             : } // namespace mio

Generated by: LCOV version 1.14