主要是为了模拟公交车站站点。
设置实例
#stop Group
Group10.groupID = Stop
Group10.movementModel = MultiStop 移动模型名
Group10.waitTime = 10, 30
Group10.nrofHosts = 59 站点数量
Group10.stopfile= data/city/stop.wkt 站点位置文件
站点文件可以用openjump把线文件(如demo_bus.wkt)转化成点文件。
java代码。
主要是在stationmovement的基础上修改来的。
stationmovement也能设置站点,但是一次只能一个,而且要自己设置坐标。
/*
* Copyright 2010 Aalto University, ComNet
* Released under GPLv3. See LICENSE.txt for details.
*/
package movement;
import input.WKTReader;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import core.Coord;
import core.Settings;
import movement.map.SimMap;
//import movement.MapBasedMovement;
/**
* A dummy stationary "movement" model where nodes do not move. Might be useful
* for simulations with only external connection events.
*/
public class MultiStop extends MapBasedMovement {
/** Per node group setting for setting the location ({@value} ) */
public static final String STOP_FILE_S = "stopfile";
private List<Coord> stops;
private int id;
private static int nextID = 0;
private Coord loc;
/** The location of the nodes */
/**
* Creates a new movement model based on a Settings object's settings.
*
* @param s
* The Settings object where the settings are read from
*/
public MultiStop(Settings s) {
super(s);
List<Coord> coords = new LinkedList<Coord>();
stops = new LinkedList<Coord>();
File stopFile = null;
WKTReader reader = new WKTReader();
stopFile = new File(s.getSetting(STOP_FILE_S));
try {
coords = reader.readPoints(stopFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimMap map = getMap();
Coord offset = map.getOffset();
// mirror points if map data is mirrored
for (Coord c : coords) {
if (map.isMirrored()) { // mirror POIs if map data is also mirrored
c.setLocation(c.getX(), -c.getY()); // flip around X axis
}
// translate to match map data
c.translate(offset.getX(), offset.getY());
stops.add(c);
}
this.id = nextID++;
if(id<stops.size()){
this.loc = stops.get(id);
}else{
nextID=0;
id=0;
this.loc = stops.get(id);
}
}
/**
* Copy constructor.
*
* @param sm
* The MultiStop prototype
*/
public MultiStop(MultiStop sm) {
super(sm);
this.id = nextID++;
if(this.id<sm.stops.size()){
this.loc = sm.stops.get(this.id);
}else{
nextID=0;
this.id=0;
this.loc = sm.stops.get(this.id);
}
}
/**
* Returns the only location of this movement model
*
* @return the only location of this movement model
*/
@Override
public Coord getInitialLocation() {
return loc;
}
/**
* Returns a single coordinate path (using the only possible coordinate)
*
* @return a single coordinate path
*/
@Override
public Path getPath() {
Path p = new Path(0);
p.addWaypoint(loc);
return p;
}
@Override
public double nextPathAvailable() {
return Double.MAX_VALUE; // no new paths available
}
@Override
public MultiStop replicate() {
return new MultiStop(this);
}
}