在repast simphony中有没有行人造型的例子?我是就餐方面的新手,正在尝试建立一个简单的行人运动模拟模型。有没有有用的参考资料/例子?
Repast不是开放库的最佳选择,但我在搜索GitHub时运气不错。这是我曾经构建过的一个基本的PED代理,您必须使用调度程序类构建一个上下文来调用行人:
背景:
public class RoadBuilder extends DefaultContext<Object> implements ContextBuilder<Object> {
context.setId("driving1");
ContinuousSpaceFactory spaceFactory =
ContinuousSpaceFactoryFinder.createContinuousSpaceFactory(null);
ContinuousSpace<Object> space =
spaceFactory.createContinuousSpace("space",context, new SimpleCartesianAdder<Object>(),
new StrictBorders(), roadL, worldW);
clock = RunEnvironment.getInstance().getCurrentSchedule();
flowSource = new Scheduler();
context.add(flowSource);
return context;
}
调度程序:
public class Scheduler {
static ArrayList<Ped> allPeds;
@ScheduledMethod(start = 1, interval = 1, priority = 1)
public void doStuff() {
Ped addedPed = addPed(1);
allPeds.add(addedPed);
for (Ped a : allPeds) {
a.calc();}
for (Ped b : allPeds) {
b.walk();}
public Ped addPed(int direction) {
Context<Object> context = ContextUtils.getContext(this);
ContinuousSpace<Object> space = (ContinuousSpace<Object>) context.getProjection("space");
Ped newPed = new Ped(space,direction);
context.add(newPed);
space.moveTo(newPed,xPlacement,yPlacement);
newPed.myLoc = space.getLocation(newPed);
return(newPed);
}
行人——这是基于“广义力模型”(来源:模拟逃生恐慌的动力学特征——赫尔宾、法卡斯和维切克)https://arxiv.org/pdf/cond-mat/0009448.pdf)
这是行人班
public class Ped {
private ContinuousSpace<Object> space;
private List<Double> forcesX, forcesY;
private NdPoint endPt;
private Random rnd = new Random();
private int age;
private double endPtDist, endPtTheta, critGap;
private double side = RoadBuilder.sidewalk;
private double wS, etaS, wV, etaV, sigR; //errors
private double m, horiz, A, B, k, r; //interactive force constants (accT is also)
public NdPoint myLoc, destination;
public double[] v, dv, newV;
public double xTime, accT, maxV, xLoc, yLoc;
public int dir; // dir = 1 walks up, -1 walks down
public void calc() {
myLoc = space.getLocation(this);
dv = accel(myLoc,dir,destination);
newV = sumV(v,dv);
newV = limitV(newV);
}
public void walk() {
v = newV;
move(myLoc,v);
}
public double[] accel(NdPoint location, int direct, NdPoint endPt) {
forcesX = new ArrayList<Double>();
forcesY = new ArrayList<Double>();
double xF, yF;
double[] acc;
xF = yF = 0;
//calculate heading to endpoint
endPtDist = space.getDistance(location, endPt);
double endPtDelX = endPt.getX()-location.getX();
endPtTheta = FastMath.asin((double)direct*endPtDelX/endPtDist);
if (direct == -1) {
endPtTheta += Math.PI;}
//calculate motive force
Double motFx = (maxV*Math.sin(endPtTheta) - v[0])/accT;
Double motFy = (maxV*Math.cos(endPtTheta) - v[1])/accT;
forcesX.add(motFx);
forcesY.add(motFy);
//calculate interactive forces
//TODO: write code to make a threshold for interaction instead of the arbitrary horizon
for (Ped a : Scheduler.allPeds) {
if (a != this) {
NdPoint otherLoc = space.getLocation(a);
double otherY = otherLoc.getY();
double visible = Math.signum((double)dir*(otherY-yLoc));
if (visible == 1) { //peds only affected by those in front of them
double absDist = space.getDistance(location, otherLoc);
if (absDist < horiz) {
double delX = location.getX()-otherLoc.getX();
double delY = location.getY()-otherLoc.getY();
double delXabs = Math.abs(delX);
double signFx = Math.signum(delX);
double signFy = Math.signum(delY);
double theta = FastMath.asin(delXabs/absDist);
double rij = r + a.r;
Double interFx = signFx*A*Math.exp((rij-absDist)/B)*Math.sin(theta)/m;
Double interFy = signFy*A*Math.exp((rij-absDist)/B)*Math.cos(theta)/m;
forcesX.add(interFx);
forcesY.add(interFy);}}}}
//sum all forces
for (Double b : forcesX) {
xF += b;}
for (Double c : forcesY) {
yF += c;}
acc = new double[] {xF, yF};
return acc;
}
public void move(NdPoint loc, double[] displacement) {
double[] zero = new double[] {0,0};
double yl = loc.getY();
if (displacement != zero) {
space.moveByDisplacement(this,displacement);
myLoc = space.getLocation(this);}
}
public double[] limitV(double[] input) {
double totalV, norm;
if (this.dir == 1) {
if (input[1] < 0) {
input[1] = 0;}}
else {
if (input[1] > 0) {
input[1] = 0;}}
totalV = Math.sqrt(input[0]*input[0] + input[1]*input[1]);
if (totalV > maxV) {
norm = maxV/totalV;
input[0] = input[0]*norm;
input[1] = input[1]*norm;}
return input;
}
public double[] sumV(double[] a, double[] b) {
double[] c = new double[2];
for (int i = 0; i < 2; i++) {
c[i] = a[i] + b[i];}
return c;
}
public Ped(ContinuousSpace<Object> contextSpace, int direction) {
space = contextSpace;
maxV = rnd.nextGaussian() * UserPanel.pedVsd + UserPanel.pedVavg;
dir = direction; // 1 moves up, -1 moves down
v = new double[] {0,(double)dir*.5*maxV};
age = 0;
//3-circle variables - from Helbing, et al (2000) [r from Rouphail et al 1998]
accT = 0.5/UserPanel.tStep; //acceleration time
m = 80; //avg ped mass in kg
horiz = 5/RoadBuilder.spaceScale; //distance at which peds affect each other
A = 2000*UserPanel.tStep*UserPanel.tStep/RoadBuilder.spaceScale; //ped interaction constant (kg*space units/time units^2)
B = 0.08/RoadBuilder.spaceScale; //ped distance interaction constant (space units)
k = 120000*UserPanel.tStep*UserPanel.tStep; //wall force constant
r = 0.275/RoadBuilder.spaceScale; //ped radius (space units)
}
}
Andrew Crook的博客GIS和基于代理的建模(http://www.gisagents.org/)有很多有趣的链接到行人模型。我认为甚至有一些特定于Repast。
我试图遵循以下步骤: 带JPA的Spring靴 创建数据库并填充数据,但当应用程序结束时,数据将被删除。我尝试了各种事务解决方案。 如果我能得到一个完整的例子,我会非常充分。 当做 安德斯
问题内容: 众所周知,有多种原因(请参阅第一个答案)。为什么只有一个例外涵盖所有这些情况,而不是多个继承自的细粒度情况? 问题答案: 我期望如此,因为发生这种情况时,您实际上什么也做不了:为何耗尽资源几乎无关紧要,因为无论如何您都被搞砸了。也许附加信息会很好,但是… 我知道tomcat会尝试执行“内存不足降落伞”操作,在此过程中,它们会保留一块内存并尝试释放它,但是我不确定它的工作原理。
生产者/消费者和读者/作家很容易想到,但是餐饮哲学家呢?在什么样的情况下,N个进程和N个资源会躺在环形拓扑上并相互交错?我可以想到N个进程竞争M个资源,但是在这种情况下,每个进程可以使用任何两个资源。 维基说Dijkstra用它来模拟竞争磁带驱动器外围设备的计算机。这种情况在现代还存在吗?
问题内容: 说我有3个这样的课程: 难道那么有可能确定一个特定的对象是否是他的一个实例,或? 我认为这样的事情可能会起作用: 但是经过一点阅读之后,我认为它始终会被评为B,因为它只是测试强制转换是否有效,并且两者之间没有实质性差异。 问题答案: 做这个:
问题内容: 免责声明:我现在只和Go玩了一天,所以我很有可能错过了很多。 有谁知道为什么Go中没有对泛型/模板/ whatsInAName的真正支持?因此,有一个通用的,但这是由编译器提供的,而Go程序员无法编写自己的实现。关于如何使Go尽可能正交的所有讨论,为什么我可以使用通用类型而不创建新类型? 尤其是在函数式编程方面,有lambda甚至闭包,但是在缺少泛型的静态类型系统中,我该如何编写泛型高
问题内容: 我见过的几乎每个Java项目都使用Maven或Ant。它们是很好的工具,我认为几乎任何项目都可以使用它们。但是,什么都发生在使?它用于各种非Java项目,并且可以轻松处理Java。当然,如果使用Windows,则必须下载make.exe,但JDK并不随附Ant和Maven。 与Java一起使用时,make是否存在一些基本缺陷?仅仅是因为Ant和Maven是用Java编写的吗? 问题答案