parameters: (self, ids_person, logger=None, **kwargs)
docstring: Generates a plan for these person according to this strategie.
          Overriden by specific strategy.
docstring_summary: Generates a plan for these person according to this strategie.
          Overriden by specific strategy.
docstring_tokens: Generates a plan for these person according to this strategie . Overriden by specific strategy .
function: def plan(self, ids_person, logger=None, **kwargs):
          """
          Generates a plan for these person according to this strategie.
          Overriden by specific strategy.
          """
          print 'TransitStrategy.plan', len(ids_person)
          #make_plans_private(self, ids_person = None, mode = 'passenger')
          # routing necessary?
          virtualpop = self.get_virtualpop()
          plans = virtualpop.get_plans()  # self._plans
          demand = virtualpop.get_demand()
          ptlines = demand.ptlines
  
          walkstages = plans.get_stagetable('walks')
          transitstages = plans.get_stagetable('transits')
          ridestages = plans.get_stagetable('bikerides')
          activitystages = plans.get_stagetable('activities')
  
          activities = virtualpop.get_activities()
          activitytypes = demand.activitytypes
          landuse = virtualpop.get_landuse()
          facilities = landuse.facilities
          #parking = landuse.parking
  
          scenario = virtualpop.get_scenario()
          net = scenario.net
          edges = net.edges
          lanes = net.lanes
          modes = net.modes
  
          ptstops = net.ptstops
  
          # print '   demand',demand
          # print '   demand.ptlines',demand.ptlines,dir(demand.ptlines)
          # print '   demand.ptlines.get_ptlinks()',demand.ptlines.get_ptlinks()
          # print '   demand.virtualpop',demand.virtualpop,dir(demand.virtualpop)
          # print '   demand.trips',demand.trips,dir(demand.trips)
          if len(ptlines) == 0:
              print 'WARNING in TrasitStrategy.plan: no transit services available.'
              return False
  
          ptlinks = ptlines.get_ptlinks()
          ptlinktypes = ptlinks.types.choices
  
          ptfstar = ptlinks.get_fstar()
          pttimes = ptlinks.get_times()
          stops_to_enter, stops_to_exit = ptlinks.get_stops_to_enter_exit()
  
          ids_stoplane = ptstops.ids_lane
          ids_laneedge = net.lanes.ids_edge
  
          times_est_plan = plans.times_est
          # here we can determine edge weights for different modes
  
          # this could be centralized to avoid redundance
          plans.prepare_stagetables(['walks', 'bikerides', 'transits', 'activities'])
  
          ids_person_act, ids_act_from, ids_act_to\
              = virtualpop.get_activities_from_pattern(0, ids_person=ids_person)
  
          if len(ids_person_act) == 0:
              print 'WARNING in TrasitStrategy.plan: no eligible persons found.'
              return False
  
          # temporary maps from ids_person to other parameters
          nm = np.max(ids_person_act)+1
          map_ids_plan = np.zeros(nm, dtype=np.int32)
          #ids_plan_act = virtualpop.add_plans(ids_person_act, id_strategy = self.get_id_strategy())
          map_ids_plan[ids_person_act] = virtualpop.add_plans(ids_person_act, id_strategy=self.get_id_strategy())
  
          map_times = np.zeros(nm, dtype=np.int32)
          map_times[ids_person_act] = activities.get_times_end(ids_act_from, pdf='unit')
  
          # set start time to plans (important!)
          plans.times_begin[map_ids_plan[ids_person_act]] = map_times[ids_person_act]
  
          map_ids_fac_from = np.zeros(nm, dtype=np.int32)
          map_ids_fac_from[ids_person_act] = activities.ids_facility[ids_act_from]
  
          n_plans = len(ids_person_act)
          print 'TrasitStrategy.plan n_plans=', n_plans
  
          # make initial activity stage
          ids_edge_from = facilities.ids_roadedge_closest[map_ids_fac_from[ids_person_act]]
          poss_edge_from = facilities.positions_roadedge_closest[map_ids_fac_from[ids_person_act]]
          # this is the time when first activity starts
          # first activity is normally not simulated
  
          names_acttype_from = activitytypes.names[activities.ids_activitytype[ids_act_from]]
          durations_act_from = activities.get_durations(ids_act_from)
          times_from = map_times[ids_person_act]-durations_act_from
          #times_from = activities.get_times_end(ids_act_from, pdf = 'unit')
  
          for id_plan,\
              time,\
              id_act_from,\
              name_acttype_from,\
              duration_act_from,\
              id_edge_from,\
              pos_edge_from  \
              in zip(map_ids_plan[ids_person_act],
                     times_from,
                     ids_act_from,
                     names_acttype_from,
                     durations_act_from,
                     ids_edge_from,
                     poss_edge_from):
  
              id_stage_act, time = activitystages.append_stage(
                  id_plan, time,
                  ids_activity=id_act_from,
                  names_activitytype=name_acttype_from,
                  durations=duration_act_from,
                  ids_lane=edges.ids_lanes[id_edge_from][0],
                  positions=pos_edge_from,
              )
  
          ##
  
          ind_act = 0
  
          # main loop while there are persons performing
          # an activity at index ind_act
          while len(ids_person_act) > 0:
              ids_plan = map_ids_plan[ids_person_act]
  
              times_from = map_times[ids_person_act]
  
              ids_veh = virtualpop.ids_ibike[ids_person_act]
              dists_walk_max = virtualpop.dists_walk_max[ids_person_act]
              names_acttype_to = activitytypes.names[activities.ids_activitytype[ids_act_to]]
              durations_act_to = activities.get_durations(ids_act_to)
  
              ids_fac_from = map_ids_fac_from[ids_person_act]
              ids_fac_to = activities.ids_facility[ids_act_to]
  
              centroids_from = facilities.centroids[ids_fac_from]
              centroids_to = facilities.centroids[ids_fac_to]
  
              # origin edge and position
              ids_edge_from = facilities.ids_roadedge_closest[ids_fac_from]
              poss_edge_from = facilities.positions_roadedge_closest[ids_fac_from]
  
              # destination edge and position
              ids_edge_to = facilities.ids_roadedge_closest[ids_fac_to]
              poss_edge_to = facilities.positions_roadedge_closest[ids_fac_to]
  
              ids_stop_from = ptstops.get_closest(centroids_from)
              ids_stop_to = ptstops.get_closest(centroids_to)
  
              ids_stopedge_from = ids_laneedge[ids_stoplane[ids_stop_from]]
              ids_stopedge_to = ids_laneedge[ids_stoplane[ids_stop_to]]
  
              centroids_stop_from = ptstops.centroids[ids_stop_from]
              centroids_stop_to = ptstops.centroids[ids_stop_to]
              # do random pos here
              poss_stop_from = 0.5*(ptstops.positions_from[ids_stop_from]
                                    + ptstops.positions_to[ids_stop_from])
  
              poss_stop_to = 0.5*(ptstops.positions_from[ids_stop_to]
                                  + ptstops.positions_to[ids_stop_to])
  
              dists_from_to = np.sqrt(np.sum((centroids_to - centroids_from)**2, 1))
              dists_from_stop_from = np.sqrt(np.sum((centroids_stop_from - centroids_from)**2, 1))
              dists_stop_to_to = np.sqrt(np.sum((centroids_to - centroids_stop_to)**2, 1))
  
              i = 0.0
              for id_person, id_plan, time_from, id_act_from, id_act_to, name_acttype_to, duration_act_to, id_veh, id_edge_from, pos_edge_from, id_edge_to, pos_edge_to, id_stop_from, id_stopedge_from, pos_stop_from, id_stop_to, id_stopedge_to, pos_stop_to, dists_from_to, dist_from_stop_from, dist_stop_to_to, dist_walk_max\
                      in zip(ids_person_act, ids_plan, times_from, ids_act_from, ids_act_to, names_acttype_to, durations_act_to, ids_veh, ids_edge_from, poss_edge_from, ids_edge_to, poss_edge_to, ids_stop_from, ids_stopedge_from, poss_stop_from, ids_stop_to, ids_stopedge_to, poss_stop_to, dists_from_to, dists_from_stop_from, dists_stop_to_to, dists_walk_max):
                  n_pers = len(ids_person_act)
                  if logger:
                      logger.progress(i/n_pers*100)
                  i += 1.0
                  print 79*'_'
                  print '  id_plan=%d, id_person=%d, ' % (id_plan, id_person)
                  #dist_from_stop_from, dist_stop_to_to
  
                  time = self.plan_bikeride(id_plan, time_from, id_veh,
                                            id_edge_from, pos_edge_from,
                                            id_stopedge_from, pos_stop_from,
                                            dist_from_stop_from, dist_walk_max,
                                            walkstages, ridestages)
  
                  time = self.plan_transit(id_plan, time,
                                           id_stopedge_from, pos_stop_from,
                                           id_stopedge_to, pos_stop_to,
                                           id_stop_from, id_stopedge_from, pos_stop_from,
                                           id_stop_to, id_stopedge_to, pos_stop_to,
                                           #dist_from_to, dist_walk_max,
                                           walkstages, transitstages,
                                           ptlines, ptfstar, pttimes,
                                           stops_to_enter, stops_to_exit,
                                           ids_laneedge, ids_stoplane, ptstops)
  
                  time = self.plan_bikeride(id_plan, time, id_veh,
                                            id_stopedge_to, pos_stop_to,
                                            id_edge_to, pos_edge_to,
                                            dist_stop_to_to, dist_walk_max,
                                            walkstages, ridestages)
  
                  # update time for trips estimation for this plan
                  plans.times_est[id_plan] += time-time_from
  
                  # define current end time without last activity duration
                  plans.times_end[id_plan] = time
  
                  id_stage_act, time = activitystages.append_stage(
                      id_plan, time,
                      ids_activity=id_act_to,
                      names_activitytype=name_acttype_to,
                      durations=duration_act_to,
                      ids_lane=edges.ids_lanes[id_edge_to][0],
                      positions=pos_edge_to,
                  )
  
                  # store time for next iteration in case other activities are
                  # following
                  map_times[id_person] = time
  
              # select persons and activities for next setp
              ind_act += 1
              ids_person_act, ids_act_from, ids_act_to\
                  = virtualpop.get_activities_from_pattern(ind_act, ids_person=ids_person_act)
function_tokens: def plan ( self , ids_person , logger = None , * * kwargs ) : print 'TransitStrategy.plan' , len ( ids_person ) #make_plans_private(self, ids_person = None, mode = 'passenger') # routing necessary? virtualpop = self . get_virtualpop ( ) plans = virtualpop . get_plans ( ) # self._plans demand = virtualpop . get_demand ( ) ptlines = demand . ptlines walkstages = plans . get_stagetable ( 'walks' ) transitstages = plans . get_stagetable ( 'transits' ) ridestages = plans . get_stagetable ( 'bikerides' ) activitystages = plans . get_stagetable ( 'activities' ) activities = virtualpop . get_activities ( ) activitytypes = demand . activitytypes landuse = virtualpop . get_landuse ( ) facilities = landuse . facilities #parking = landuse.parking scenario = virtualpop . get_scenario ( ) net = scenario . net edges = net . edges lanes = net . lanes modes = net . modes ptstops = net . ptstops # print '   demand',demand # print '   demand.ptlines',demand.ptlines,dir(demand.ptlines) # print '   demand.ptlines.get_ptlinks()',demand.ptlines.get_ptlinks() # print '   demand.virtualpop',demand.virtualpop,dir(demand.virtualpop) # print '   demand.trips',demand.trips,dir(demand.trips) if len ( ptlines ) == 0 : print 'WARNING in TrasitStrategy.plan: no transit services available.' return False ptlinks = ptlines . get_ptlinks ( ) ptlinktypes = ptlinks . types . choices ptfstar = ptlinks . get_fstar ( ) pttimes = ptlinks . get_times ( ) stops_to_enter , stops_to_exit = ptlinks . get_stops_to_enter_exit ( ) ids_stoplane = ptstops . ids_lane ids_laneedge = net . lanes . ids_edge times_est_plan = plans . times_est # here we can determine edge weights for different modes # this could be centralized to avoid redundance plans . prepare_stagetables ( [ 'walks' , 'bikerides' , 'transits' , 'activities' ] ) ids_person_act , ids_act_from , ids_act_to = virtualpop . get_activities_from_pattern ( 0 , ids_person = ids_person ) if len ( ids_person_act ) == 0 : print 'WARNING in TrasitStrategy.plan: no eligible persons found.' return False # temporary maps from ids_person to other parameters nm = np . max ( ids_person_act ) + 1 map_ids_plan = np . zeros ( nm , dtype = np . int32 ) #ids_plan_act = virtualpop.add_plans(ids_person_act, id_strategy = self.get_id_strategy()) map_ids_plan [ ids_person_act ] = virtualpop . add_plans ( ids_person_act , id_strategy = self . get_id_strategy ( ) ) map_times = np . zeros ( nm , dtype = np . int32 ) map_times [ ids_person_act ] = activities . get_times_end ( ids_act_from , pdf = 'unit' ) # set start time to plans (important!) plans . times_begin [ map_ids_plan [ ids_person_act ] ] = map_times [ ids_person_act ] map_ids_fac_from = np . zeros ( nm , dtype = np . int32 ) map_ids_fac_from [ ids_person_act ] = activities . ids_facility [ ids_act_from ] n_plans = len ( ids_person_act ) print 'TrasitStrategy.plan n_plans=' , n_plans # make initial activity stage ids_edge_from = facilities . ids_roadedge_closest [ map_ids_fac_from [ ids_person_act ] ] poss_edge_from = facilities . positions_roadedge_closest [ map_ids_fac_from [ ids_person_act ] ] # this is the time when first activity starts # first activity is normally not simulated names_acttype_from = activitytypes . names [ activities . ids_activitytype [ ids_act_from ] ] durations_act_from = activities . get_durations ( ids_act_from ) times_from = map_times [ ids_person_act ] - durations_act_from #times_from = activities.get_times_end(ids_act_from, pdf = 'unit') for id_plan , time , id_act_from , name_acttype_from , duration_act_from , id_edge_from , pos_edge_from in zip ( map_ids_plan [ ids_person_act ] , times_from , ids_act_from , names_acttype_from , durations_act_from , ids_edge_from , poss_edge_from ) : id_stage_act , time = activitystages . append_stage ( id_plan , time , ids_activity = id_act_from , names_activitytype = name_acttype_from , durations = duration_act_from , ids_lane = edges . ids_lanes [ id_edge_from ] [ 0 ] , positions = pos_edge_from , ) ## ind_act = 0 # main loop while there are persons performing # an activity at index ind_act while len ( ids_person_act ) > 0 : ids_plan = map_ids_plan [ ids_person_act ] times_from = map_times [ ids_person_act ] ids_veh = virtualpop . ids_ibike [ ids_person_act ] dists_walk_max = virtualpop . dists_walk_max [ ids_person_act ] names_acttype_to = activitytypes . names [ activities . ids_activitytype [ ids_act_to ] ] durations_act_to = activities . get_durations ( ids_act_to ) ids_fac_from = map_ids_fac_from [ ids_person_act ] ids_fac_to = activities . ids_facility [ ids_act_to ] centroids_from = facilities . centroids [ ids_fac_from ] centroids_to = facilities . centroids [ ids_fac_to ] # origin edge and position ids_edge_from = facilities . ids_roadedge_closest [ ids_fac_from ] poss_edge_from = facilities . positions_roadedge_closest [ ids_fac_from ] # destination edge and position ids_edge_to = facilities . ids_roadedge_closest [ ids_fac_to ] poss_edge_to = facilities . positions_roadedge_closest [ ids_fac_to ] ids_stop_from = ptstops . get_closest ( centroids_from ) ids_stop_to = ptstops . get_closest ( centroids_to ) ids_stopedge_from = ids_laneedge [ ids_stoplane [ ids_stop_from ] ] ids_stopedge_to = ids_laneedge [ ids_stoplane [ ids_stop_to ] ] centroids_stop_from = ptstops . centroids [ ids_stop_from ] centroids_stop_to = ptstops . centroids [ ids_stop_to ] # do random pos here poss_stop_from = 0.5 * ( ptstops . positions_from [ ids_stop_from ] + ptstops . positions_to [ ids_stop_from ] ) poss_stop_to = 0.5 * ( ptstops . positions_from [ ids_stop_to ] + ptstops . positions_to [ ids_stop_to ] ) dists_from_to = np . sqrt ( np . sum ( ( centroids_to - centroids_from ) ** 2 , 1 ) ) dists_from_stop_from = np . sqrt ( np . sum ( ( centroids_stop_from - centroids_from ) ** 2 , 1 ) ) dists_stop_to_to = np . sqrt ( np . sum ( ( centroids_to - centroids_stop_to ) ** 2 , 1 ) ) i = 0.0 for id_person , id_plan , time_from , id_act_from , id_act_to , name_acttype_to , duration_act_to , id_veh , id_edge_from , pos_edge_from , id_edge_to , pos_edge_to , id_stop_from , id_stopedge_from , pos_stop_from , id_stop_to , id_stopedge_to , pos_stop_to , dists_from_to , dist_from_stop_from , dist_stop_to_to , dist_walk_max in zip ( ids_person_act , ids_plan , times_from , ids_act_from , ids_act_to , names_acttype_to , durations_act_to , ids_veh , ids_edge_from , poss_edge_from , ids_edge_to , poss_edge_to , ids_stop_from , ids_stopedge_from , poss_stop_from , ids_stop_to , ids_stopedge_to , poss_stop_to , dists_from_to , dists_from_stop_from , dists_stop_to_to , dists_walk_max ) : n_pers = len ( ids_person_act ) if logger : logger . progress ( i / n_pers * 100 ) i += 1.0 print 79 * '_' print '  id_plan=%d, id_person=%d, ' % ( id_plan , id_person ) #dist_from_stop_from, dist_stop_to_to time = self . plan_bikeride ( id_plan , time_from , id_veh , id_edge_from , pos_edge_from , id_stopedge_from , pos_stop_from , dist_from_stop_from , dist_walk_max , walkstages , ridestages ) time = self . plan_transit ( id_plan , time , id_stopedge_from , pos_stop_from , id_stopedge_to , pos_stop_to , id_stop_from , id_stopedge_from , pos_stop_from , id_stop_to , id_stopedge_to , pos_stop_to , #dist_from_to, dist_walk_max, walkstages , transitstages , ptlines , ptfstar , pttimes , stops_to_enter , stops_to_exit , ids_laneedge , ids_stoplane , ptstops ) time = self . plan_bikeride ( id_plan , time , id_veh , id_stopedge_to , pos_stop_to , id_edge_to , pos_edge_to , dist_stop_to_to , dist_walk_max , walkstages , ridestages ) # update time for trips estimation for this plan plans . times_est [ id_plan ] += time - time_from # define current end time without last activity duration plans . times_end [ id_plan ] = time id_stage_act , time = activitystages . append_stage ( id_plan , time , ids_activity = id_act_to , names_activitytype = name_acttype_to , durations = duration_act_to , ids_lane = edges . ids_lanes [ id_edge_to ] [ 0 ] , positions = pos_edge_to , ) # store time for next iteration in case other activities are # following map_times [ id_person ] = time # select persons and activities for next setp ind_act += 1 ids_person_act , ids_act_from , ids_act_to = virtualpop . get_activities_from_pattern ( ind_act , ids_person = ids_person_act )