org.matsim.api.core.v01.population.Activity.setLinkId()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.matsim.api.core.v01.population.Activity.setLinkId()方法的一些代码示例,展示了Activity.setLinkId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.setLinkId()方法的具体详情如下:
包路径:org.matsim.api.core.v01.population.Activity
类名称:Activity
方法名:setLinkId

Activity.setLinkId介绍

暂无

代码示例

代码示例来源:origin: matsim-org/matsim

public static void setLinkId(Activity activity, Id<Link> linkId) {
  if (activity instanceof Activity) {
    ((Activity) activity).setLinkId(linkId);
  } else if (activity instanceof LCActivity) {
    ((LCActivity) activity).setLinkId(linkId);
  } else throw new RuntimeException("Unexpected type of activity was found: " + activity.getClass().toString() + ". Aborting!");
}

代码示例来源:origin: matsim-org/matsim

@Override
public Activity createActivityFromLinkId(final String actType, final Id<Link> linkId) {
    Activity act = new ActivityImpl(actType) ;
    act.setLinkId(linkId);
    return act ;
}

代码示例来源:origin: matsim-org/matsim

public static Activity createActivityFromCoordAndLinkId(String type, Coord coord, Id<Link> linkId) {
  Activity act = getFactory().createActivityFromCoord(type, coord) ;
  act.setLinkId(linkId);
  return act ;
}

代码示例来源:origin: matsim-org/matsim

@Override
  public void run(final Plan plan) {
    for (PlanElement pe : plan.getPlanElements()) {
      if (pe instanceof Activity) {
        ((Activity) pe).setLinkId(null);
      } else if (pe instanceof Leg) {
        ((Leg) pe).setRoute(null);
      }
    }
  }
}

代码示例来源:origin: matsim-org/matsim

public static Activity createAndAddActivityFromLinkId( Plan plan, String type, Id<Link> linkId ) {
  Activity act = getFactory().createActivityFromLinkId(type, linkId) ;
  plan.addActivity(act);
  act.setLinkId(linkId);
  return act ;
}

代码示例来源:origin: matsim-org/matsim

@Override
public void run(final GroupPlans plans) {
  final List<Facility> groupChoiceSet = choiceSet.getGroupChoiceSet( plans );
  for ( Plan plan : plans.getAllIndividualPlans() ) {
    for ( Activity act : TripStructureUtils.getActivities( plan , choiceSet.filter ) ) {
      assert act.getType().equals( choiceSet.type );
      final Facility choice = groupChoiceSet.get( random.nextInt( groupChoiceSet.size() ) );
      ((Activity) act).setCoord( choice.getCoord() );
      ((Activity) act).setLinkId( choice.getLinkId() );
      if ( choice instanceof Identifiable ) {
        ( (Activity) act ).setFacilityId( ((Identifiable)choice).getId() );
      } else {
        throw new RuntimeException( Facility.FACILITY_NO_LONGER_IDENTIFIABLE ) ;
      }
    }
  }
}

代码示例来源:origin: matsim-org/matsim

protected boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius, int trialNr) {
  ArrayList<ActivityFacility> choiceSet = this.computeChoiceSetCircle(startCoord, endCoord, radius, act.getType());
  if (choiceSet.size()>1) {
    //final Facility facility=(Facility)choiceSet.toArray()[
      //		           MatsimRandom.random.nextInt(choiceSet.size())];
    final ActivityFacility facility = choiceSet.get(super.random.nextInt(choiceSet.size()));
    act.setFacilityId(facility.getId());
      act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId());
      act.setCoord(facility.getCoord());
      return true;
  }
  // else ...
  return false;
}

代码示例来源:origin: matsim-org/matsim

private void setNewLocationForAct(Activity act, int length) {
    ActivityFacilityImpl facility = this.facilitiesOfType.get(act.getType())[super.random.nextInt(length)];
    act.setFacilityId(facility.getId());
    act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId());
    act.setCoord(facility.getCoord());
  }
}

代码示例来源:origin: matsim-org/matsim

protected final boolean modifyLocation(Activity act, Coord startCoord, Coord endCoord, double radius) {
  double midPointX = (startCoord.getX() + endCoord.getX()) / 2.0;
  double midPointY = (startCoord.getY() + endCoord.getY()) / 2.0;
  ArrayList<ActivityFacility> facilitySet =
      (ArrayList<ActivityFacility>) this.quadTreesOfType.get(this.defineFlexibleActivities.getConverter().convertType(act.getType())).
          getDisk(midPointX, midPointY, radius);
  ActivityFacility facility = null;
  if (facilitySet.size() > 1) {
    facility = facilitySet.get(super.random.nextInt(facilitySet.size()));
  }
  else {
    return false;
  }
  act.setFacilityId(facility.getId());
    act.setLinkId(NetworkUtils.getNearestLink(((Network) this.scenario.getNetwork()), facility.getCoord()).getId());
    act.setCoord(facility.getCoord());
    return true;
}

代码示例来源:origin: matsim-org/matsim

private void mutateLocations(
    final String type,
    final List<Activity> activitiesToMutate) {
  final Coord coordBarycenter = calcBarycenterCoord( activitiesToMutate );
  final double angle = random.nextDouble() * Math.PI;
  final double distance = nextNormalDouble() * config.getStandardDeviation();
  final ActivityFacility fac = getFacility(
      type,
      coordBarycenter,
      angle,
      distance );
  for ( Activity act : activitiesToMutate ) {
    ((Activity) act).setFacilityId( fac.getId() );
    ((Activity) act).setLinkId( fac.getLinkId() );
    ((Activity) act).setCoord( fac.getCoord() );
  }
}

代码示例来源:origin: matsim-org/matsim

private static void changeLocation(
    final Collection<Subchain> subchains,
    final ActivityFacility facility) {
  for ( Subchain subchain : subchains ) {
    ((Activity) subchain.getToMove()).setFacilityId(
      facility.getId() );
    ((Activity) subchain.getToMove()).setLinkId(
      facility.getLinkId() );
    ((Activity) subchain.getToMove()).setCoord(
      facility.getCoord() );
  }
}

代码示例来源:origin: matsim-org/matsim

public static void copyFromTo(Activity act, Activity newAct) {
  Coord coord = act.getCoord() == null ? null : new Coord(act.getCoord().getX(), act.getCoord().getY());
  // (we don't want to copy the coord ref, but rather the contents!)
  newAct.setCoord(coord);
  newAct.setType( act.getType() );
  newAct.setLinkId(act.getLinkId());
  newAct.setStartTime(act.getStartTime());
  newAct.setEndTime(act.getEndTime());
  newAct.setMaximumDuration(act.getMaximumDuration());
  newAct.setFacilityId(act.getFacilityId());
  AttributesUtils.copyAttributesFromTo( act , newAct );
}

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteFour() 
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityW1;
  activityW1 = (Activity) plan.getPlanElements().get(2);
  activityW1.setLinkId(Id.create("l2", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 2, 8.0*3600 ));	// HW, end Link			
  final NetworkRoute route = (NetworkRoute)((Leg)plan.getPlanElements().get(firstCarLeg)).getRoute();
  assertEquals(true, checkRouteValidity(route));
}
public void testReplanCurrentLegRouteFive()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteSix() 
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityH2;
  activityH2 = (Activity) plan.getPlanElements().get(4);
  activityH2.setLinkId(Id.create("l4", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 1, 8.0*3600 ));	// WH, en-route
  assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute()));
}
public void testReplanCurrentLegRouteSeven()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteEight()
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityH2;
  activityH2 = (Activity) plan.getPlanElements().get(4);
  activityH2.setLinkId(Id.create("l4", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 3, 8.0*3600 ) );	// WH, en-route			
  assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute()));
}
public void testReplanCurrentLegRouteNine()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteNine()
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityH2;
  activityH2 = (Activity) plan.getPlanElements().get(4);
  activityH2.setLinkId(Id.create("l4", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 4, 8.0*3600 ));	// WH, end Link			
  assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute()));
}
public void testReplanCurrentLegRouteTen()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteThree() 
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityW1;
  activityW1 = (Activity) plan.getPlanElements().get(2);
  activityW1.setLinkId(Id.create("l2", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 1, 8.0*3600 ) );	// HW, en-route			
  final NetworkRoute route = (NetworkRoute)((Leg)plan.getPlanElements().get(firstCarLeg)).getRoute();
  assertEquals(true, checkRouteValidity(route));
}    
public void testReplanCurrentLegRouteFour()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteSeven() 
{
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityH2;
  activityH2 = (Activity) plan.getPlanElements().get(4);
  activityH2.setLinkId(Id.create("l4", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 2, 8.0*3600 ));	// WH, en-route			
  assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute()));
}
public void testReplanCurrentLegRouteEight()

代码示例来源:origin: matsim-org/matsim

public void testReplanCurrentLegRouteFive() 
{
  // create new routes for WH-trip
  createScenario();    // reset scenario
  EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory());
  int firstCarLeg = 1 ; // 1-->3	
  int scndCarLeg = 3 ; // 3-->9
  if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { 
    firstCarLeg = 3 ; // 1-->3	
    scndCarLeg = 9 ; // 3-->9
  }
  Activity activityH2;
  activityH2 = (Activity) plan.getPlanElements().get(4);
  activityH2.setLinkId(Id.create("l4", Link.class));	// move Activity location
  assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 0, 8.0*3600 ));	// WH, start Link			
  assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute()));
}
public void testReplanCurrentLegRouteSix()

代码示例来源:origin: matsim-org/matsim

@Test
public void testRouteLeg() {
  Fixture f = new Fixture();
  FreespeedTravelTimeAndDisutility freespeed = new FreespeedTravelTimeAndDisutility(-6.0/3600, +6.0/3600, 0.0);
  LeastCostPathCalculator routeAlgo = new Dijkstra(f.s.getNetwork(), freespeed, freespeed);
  Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class));
  Activity fromAct = PopulationUtils.createActivityFromCoord("h", new Coord(0, 0));
  fromAct.setLinkId(Id.create("1", Link.class));
  Activity toAct = PopulationUtils.createActivityFromCoord("h", new Coord(0, 3000));
  toAct.setLinkId(Id.create("3", Link.class));
  final NetworkRoutingModule routingModule = new NetworkRoutingModule(
        TransportMode.car,
        f.s.getPopulation().getFactory(),
        f.s.getNetwork(),
        routeAlgo);
  Facility fromFacility = new ActivityWrapperFacility( fromAct ) ;
  Facility toFacility = new ActivityWrapperFacility( toAct ) ;
  List<? extends PlanElement> result = routingModule.calcRoute(fromFacility, toFacility, 7.0*3600, person) ;
  Assert.assertEquals(1, result.size() );
  Leg leg = (Leg)result.get(0) ;
  Assert.assertEquals(100.0, leg.getTravelTime(), 1e-8);
  Assert.assertTrue(leg.getRoute() instanceof NetworkRoute);
}

相关文章