parameters: (self, ids_person, logger=None)
return_statement: return True
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):
          """
          Generates a plan for these person according to this strategie.
          Overriden by specific strategy.
          """
          #make_plans_private(self, ids_person = None, mode = 'passenger')
          # routing necessary?
          virtualpop = self.get_virtualpop()
          plans = virtualpop.get_plans()  # self._plans
          walkstages = plans.get_stagetable('walks')
          ridestages = plans.get_stagetable('motorides')
          activitystages = plans.get_stagetable('activities')
  
          activities = virtualpop.get_activities()
          activitytypes = virtualpop.get_demand().activitytypes
          landuse = virtualpop.get_landuse()
          facilities = landuse.facilities
          #parking = landuse.parking
  
          scenario = virtualpop.get_scenario()
          edges = scenario.net.edges
          lanes = scenario.net.lanes
          modes = scenario.net.modes
  
          #times_est_plan = plans.times_est
  
          # here we can determine edge weights for different modes
          plans.prepare_stagetables(['walks', 'motorides', 'activities'])
  
          # get initial travel times for persons.
          # initial travel times depend on the initial activity
  
          # landuse.parking.clear_booking()
  
          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 MotorcycleStrategy.plan: no eligible persons found.'
              return False
  
          # ok
  
          # temporary maps from ids_person to other parameters
          nm = np.max(ids_person_act)+1
          map_ids_plan = np.zeros(nm, dtype=np.int32)
          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]
  
          #map_ids_parking_from = np.zeros(nm, dtype = np.int32)
          # ids_parking_from, inds_vehparking = parking.get_closest_parkings( virtualpop.ids_iauto[ids_person_act],
          # facilities.centroids[activities.ids_facility[ids_act_from]])
          # if len(ids_parking_from)==0:
          #    return False
  
          # err
  
          #map_ids_parking_from[ids_person_act] = ids_parking_from
  
          n_plans = len(ids_person_act)
          print 'MotorcycleStrategy.plan n_plans=', n_plans
          # print '  map_ids_parking_from[ids_person_act].shape',map_ids_parking_from[ids_person_act].shape
          # set initial activity
          # this is because the following steps start with travel
          # and set the next activity
          #names_acttype_from = activitytypes.names[activities.ids_activitytype[ids_act_from]]
          # for id_plan
  
          ind_act = 0
  
          # 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]]
          poss_edge_from = self.clip_positions(poss_edge_from, ids_edge_from)
  
          # 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')
  
          # do initial stage
          # could be common to all strategies
          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,
              )
  
          # 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]
              ids_veh = virtualpop.ids_imoto[ids_person_act]
              dists_walk_max = virtualpop.dists_walk_max[ids_person_act]
              times_from = map_times[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]
  
              # origin edge and position
              ids_edge_from = facilities.ids_roadedge_closest[ids_fac_from]
              poss_edge_from = facilities.positions_roadedge_closest[ids_fac_from]
              poss_edge_from = self.clip_positions(poss_edge_from, ids_edge_from)
  
              centroids_from = facilities.centroids[ids_fac_from]
  
              # this method will find and occupy parking space
              #ids_parking_from = map_ids_parking_from[ids_person_act]
  
              # print '  ids_veh.shape',ids_veh.shape
              # print '  centroids_to.shape',centroids_to.shape
              #ids_parking_to, inds_vehparking = parking.get_closest_parkings(ids_veh, centroids_to)
  
              #ids_lane_parking_from = parking.ids_lane[ids_parking_from]
              #ids_edge_parking_from = lanes.ids_edge[ids_lane_parking_from]
              #poss_edge_parking_from = parking.positions[ids_parking_from]
  
              # print '  ids_parking_to.shape',ids_parking_to.shape
              # print '  np.max(parking.get_ids()), np.max(ids_parking_to)',np.max(parking.get_ids()), np.max(ids_parking_to)
              #ids_lane_parking_to = parking.ids_lane[ids_parking_to]
              #ids_edge_parking_to = lanes.ids_edge[ids_lane_parking_to]
              #poss_edge_parking_to = parking.positions[ids_parking_to]
  
              # destination edge and position
              ids_edge_to = facilities.ids_roadedge_closest[ids_fac_to]
  
              poss_edge_to1 = facilities.positions_roadedge_closest[ids_fac_to]
              poss_edge_to = self.clip_positions(poss_edge_to1, ids_edge_to)
              centroids_to = facilities.centroids[ids_fac_to]
  
              # debug poscorrection..OK
              # for id_edge, id_edge_sumo, length, pos_to1, pos in zip(ids_edge_to, edges.ids_sumo[ids_edge_to],edges.lengths[ids_edge_to],poss_edge_to1, poss_edge_to):
              #    print '  ',id_edge, 'IDe%s'%id_edge_sumo, 'L=%.2fm'%length, '%.2fm'%pos_to1, '%.2fm'%pos
  
              dists_from_to = np.sqrt(np.sum((centroids_to - centroids_from)**2, 1))
  
              i = 0.0
              n_pers = len(ids_person_act)
              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, dist_from_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, dists_from_to, dists_walk_max):
                  if logger:
                      logger.progress(i/n_pers*100)
                  i += 1.0
                  print 79*'*'
                  print '  plan id_plan', id_plan, 'time_from', time_from, 'from', id_edge_from, pos_edge_from, 'to', id_edge_to, pos_edge_to
                  print '  id_edge_from', edges.ids_sumo[id_edge_from], 'id_edge_to', edges.ids_sumo[id_edge_to]
  
                  time = self.plan_motoride(id_plan, time_from, id_veh,
                                            id_edge_from, pos_edge_from,
                                            id_edge_to, pos_edge_to,
                                            dist_from_to, dist_walk_max,
                                            walkstages, ridestages)
  
                  ################
  
                  # store time estimation for this plan
                  # note that these are the travel times, no activity time
                  plans.times_est[id_plan] += time-time_from
  
                  # define current end time without last activity duration
                  plans.times_end[id_plan] = time
  
                  # finally add activity and respective duration
  
                  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,
                  )
  
                  map_times[id_person] = time
                  # return 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)
              # update timing with (random) activity duration!!
  
          return True
function_tokens: def plan ( self , ids_person , logger = None ) : #make_plans_private(self, ids_person = None, mode = 'passenger') # routing necessary? virtualpop = self . get_virtualpop ( ) plans = virtualpop . get_plans ( ) # self._plans walkstages = plans . get_stagetable ( 'walks' ) ridestages = plans . get_stagetable ( 'motorides' ) activitystages = plans . get_stagetable ( 'activities' ) activities = virtualpop . get_activities ( ) activitytypes = virtualpop . get_demand ( ) . activitytypes landuse = virtualpop . get_landuse ( ) facilities = landuse . facilities #parking = landuse.parking scenario = virtualpop . get_scenario ( ) edges = scenario . net . edges lanes = scenario . net . lanes modes = scenario . net . modes #times_est_plan = plans.times_est # here we can determine edge weights for different modes plans . prepare_stagetables ( [ 'walks' , 'motorides' , 'activities' ] ) # get initial travel times for persons. # initial travel times depend on the initial activity # landuse.parking.clear_booking() 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 MotorcycleStrategy.plan: no eligible persons found.' return False # ok # temporary maps from ids_person to other parameters nm = np . max ( ids_person_act ) + 1 map_ids_plan = np . zeros ( nm , dtype = np . int32 ) 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 ] #map_ids_parking_from = np.zeros(nm, dtype = np.int32) # ids_parking_from, inds_vehparking = parking.get_closest_parkings( virtualpop.ids_iauto[ids_person_act], # facilities.centroids[activities.ids_facility[ids_act_from]]) # if len(ids_parking_from)==0: #    return False # err #map_ids_parking_from[ids_person_act] = ids_parking_from n_plans = len ( ids_person_act ) print 'MotorcycleStrategy.plan n_plans=' , n_plans # print '  map_ids_parking_from[ids_person_act].shape',map_ids_parking_from[ids_person_act].shape # set initial activity # this is because the following steps start with travel # and set the next activity #names_acttype_from = activitytypes.names[activities.ids_activitytype[ids_act_from]] # for id_plan ind_act = 0 # 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 ] ] poss_edge_from = self . clip_positions ( poss_edge_from , ids_edge_from ) # 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') # do initial stage # could be common to all strategies 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 , ) # 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 ] ids_veh = virtualpop . ids_imoto [ ids_person_act ] dists_walk_max = virtualpop . dists_walk_max [ ids_person_act ] times_from = map_times [ 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 ] # origin edge and position ids_edge_from = facilities . ids_roadedge_closest [ ids_fac_from ] poss_edge_from = facilities . positions_roadedge_closest [ ids_fac_from ] poss_edge_from = self . clip_positions ( poss_edge_from , ids_edge_from ) centroids_from = facilities . centroids [ ids_fac_from ] # this method will find and occupy parking space #ids_parking_from = map_ids_parking_from[ids_person_act] # print '  ids_veh.shape',ids_veh.shape # print '  centroids_to.shape',centroids_to.shape #ids_parking_to, inds_vehparking = parking.get_closest_parkings(ids_veh, centroids_to) #ids_lane_parking_from = parking.ids_lane[ids_parking_from] #ids_edge_parking_from = lanes.ids_edge[ids_lane_parking_from] #poss_edge_parking_from = parking.positions[ids_parking_from] # print '  ids_parking_to.shape',ids_parking_to.shape # print '  np.max(parking.get_ids()), np.max(ids_parking_to)',np.max(parking.get_ids()), np.max(ids_parking_to) #ids_lane_parking_to = parking.ids_lane[ids_parking_to] #ids_edge_parking_to = lanes.ids_edge[ids_lane_parking_to] #poss_edge_parking_to = parking.positions[ids_parking_to] # destination edge and position ids_edge_to = facilities . ids_roadedge_closest [ ids_fac_to ] poss_edge_to1 = facilities . positions_roadedge_closest [ ids_fac_to ] poss_edge_to = self . clip_positions ( poss_edge_to1 , ids_edge_to ) centroids_to = facilities . centroids [ ids_fac_to ] # debug poscorrection..OK # for id_edge, id_edge_sumo, length, pos_to1, pos in zip(ids_edge_to, edges.ids_sumo[ids_edge_to],edges.lengths[ids_edge_to],poss_edge_to1, poss_edge_to): #    print '  ',id_edge, 'IDe%s'%id_edge_sumo, 'L=%.2fm'%length, '%.2fm'%pos_to1, '%.2fm'%pos dists_from_to = np . sqrt ( np . sum ( ( centroids_to - centroids_from ) ** 2 , 1 ) ) i = 0.0 n_pers = len ( ids_person_act ) 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 , dist_from_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 , dists_from_to , dists_walk_max ) : if logger : logger . progress ( i / n_pers * 100 ) i += 1.0 print 79 * '*' print '  plan id_plan' , id_plan , 'time_from' , time_from , 'from' , id_edge_from , pos_edge_from , 'to' , id_edge_to , pos_edge_to print '  id_edge_from' , edges . ids_sumo [ id_edge_from ] , 'id_edge_to' , edges . ids_sumo [ id_edge_to ] time = self . plan_motoride ( id_plan , time_from , id_veh , id_edge_from , pos_edge_from , id_edge_to , pos_edge_to , dist_from_to , dist_walk_max , walkstages , ridestages ) ################ # store time estimation for this plan # note that these are the travel times, no activity time plans . times_est [ id_plan ] += time - time_from # define current end time without last activity duration plans . times_end [ id_plan ] = time # finally add activity and respective duration 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 , ) map_times [ id_person ] = time # return 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 ) # update timing with (random) activity duration!! return True