什么是该模拟器的最佳架构? [英] What is the best architecture for this simulator?

查看:166
本文介绍了什么是该模拟器的最佳架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做在Java模拟器,这将模拟在公路上的汽车骑马。应该有高速公路3条车道,每个车道有以恒定速度车。在此公路,有一个代理,其具有用于驱动通过并不会崩溃到任何其他汽车。详细说明可在本文在2.5节和画面5中找到。

I have to make a simulator in Java, which will simulate car riding on highway. There should be 3 lanes on highway, in every lane there are cars with constant speed. On this highway, there is one agent, which has to drive through and not crash into any other car. Detailed description can be found in this paper at section 2.5 and picture 5.

此图像来自提到造纸和高速公路显示的外观:

This image is from mentioned paper and shows the look of highway:

我的目标是只写一个仿真器(和GUI),代理的不是逻辑。现在,我想设计这个模拟器的架构,这是我需要帮助。

My goal is to write only a simulator (and GUI), not logic of agent. Now, I would like to design an architecture of this simulator and this is where I need help.

我的想法,代理的API可以看看如何为:

My idea, how the agent's API can look is:

public abstract class BaseAgent {
    public abstract void run()
    public abstract void onCrash();
}

在公路上代理(车)应该是这个阶级的后代。在每一个步骤,模拟通话功能的run()哪里是代理的逻辑。在此功能中,代理可以调用​​类的函数:

Agent (car) on highway should be a descendant of this class. In every step, simulator call function run() where is the agents logic. In this function, agent can call functions like:

goLeft();
goRight();
getNearestCarInLane(int lane_no);
getMySpeed();

因此​​,在每一步,代理可以,如果他留在当前车道,或者,如果他转左或右决定。而这一切,有什么可以做代理

So, in every step, agent can decide if he stay in current lane, or if he turns left or right. And that’s all, what can agent do.

因此​​,这是代理商的API,但我不知道,如何设计模拟器的其余部分。我第一次到仿真建筑的尝试是:

So this is agents API, but I do not know, how to design the rest of simulator. My first attempt to simulator architecture was:

class Agent — descendant of BaseAgent, can ride on highway.
class Highway — stores position of all cars on highway.
class Simulator — creates instance of agent and highway; in every step, call agent’s `run()` and monitors any car crash.

这是不是一个好的架构。在哪个类应该是方法 goLeft() goRight() getNearestCarInLane()?因为这些方法必须是 BaseAgent 类里面,但要知道在公路上每一辆汽车的位置。因此,在年底,我有这样的事情:

This is not a good architecture. In which class should be methods goLeft(), goRight() and getNearestCarInLane()? Because these methods has to be inside of BaseAgent class, but has to know position of every car on highway. So at the end, I had something like this:

Simulator s = new Simulator();
Highway h = new Highway();
Agent a = new Agent();

s.setAgent(a);
s.setHighway(h);
a.setHighway(h);
h.setAgent(a);

和它是可怕和丑陋的。

所以我需要从这里聪明的人一点帮助。有人可以给我一个链接,书籍,文章,不管模拟器左右/架构?或解释什么我我做错了?

So I need a little help from smarter people here. Can somebody give me a link to book, article, whatever about simulators/architecture? Or explain my what I am doing wrong?

我不是一个程序员,这个项目是我的教师选修课命名的一部分的软件工程

I am not a programmer and this project is part of an optional course at my faculty named Software engineering.

推荐答案

我的建议是为设计代理的接口的正式概念的智能代理记 :从模拟的角度来看,它是接收一个黑盒子的知觉(如传感器数据),然后决定在一定的动作的(例如,引导向左或向右车)。

My recommendation would be to design the agent's interface with the formal notion of an intelligent agent in mind: from a simulation perspective, it is a black box that receives percepts from its environment (e.g., sensor data) and then decides on a certain action (e.g., to steer the car left or right).

假设一个简单的离散逐步模拟后,您的代理类看起来是这样的:

Based on this definition and assuming a simple discrete step-wise simulation, your agent class could look like this:

public abstract class BaseAgent {
    public AgentAction act(HighwayPerception hwyPerception);
}

其中, AgentAction 将是可再presenting行动代理人可以决定一个步骤去做(以最简单的情况下,这将是一个枚举值与 STEER_LEFT STEER_RIGHT 等等 - 因为更复杂的问题,你可以定义整个类层次与 AgentAction 作为超类/接口)。这是模拟器间preT的作业 AgentAction 对象由代理返回,并且改变其环境的状态(即公路)对象相应。

where AgentAction would be the type representing the actions an agent could decide to do in a single step (in the most simple case, this would be an enumeration with values STEER_LEFT, STEER_RIGHT, etc. --- for more complex problems, you could define a whole class hierarchy with AgentAction as super class / interface). It is the job of the simulator to interpret the AgentAction objects returned by the agent and to change the state of its environment (i.e., the Highway object) accordingly.

参数 HighwayPerception ,在另一方面,重presents所有的代理能够在当前时间步感知:例如,如何快速是汽车( getMySpeed​​()),或下一辆车的距离( getNearestCarInLane(INT laneNumber))。这避免了直接代理耦合到它的环境(即公路)---这是很重要的,因为它的分离的关注:仅代理认为的所处环境的决定,而不是与它直接交互的行动。它是,再次,模拟器的作业创建知觉为代理,给定它的环境的当前状态。

The parameter HighwayPerception, on the other hand, represents all that the agent is able to perceive at the current time step: e.g., how fast is the car (getMySpeed()) or the distance to the next car (getNearestCarInLane(int laneNumber)). This avoids coupling the agent directly to its environment (i.e., Highway) --- which is important, because it separates the concerns: agents only perceive their environment an decide on actions, instead of interacting with it directly. It is, again, the job of the simulator to create the percepts for the agent, given the current state of its environment.

最后,这样的设计也更容易控制剂
HighwayPercept 类已被设计成只能用于的阅读的数据代理的应该能够感知,而不是直接影响周围的环境。相反,在你的原设计的代理有权访问公路对象等,并可能因此试图为作弊,例如,以汽车几英里前进,相应的计划它的路线,或者只是改变在高速公路上的其他车辆的位置。 这应该永远不可能,即使你不那么在意安全性,因为这样的事情也可能会在无意间发生,可能是棘手的调试。

Finally, this design also makes it easier to control agents. The HighwayPercept class has to be designed so that it can only be used to read the data the agent should be able to perceive, not to affect the surrounding environment directly. In contrast, the agent in your original design has access to a Highway object as such, and could hence try to cheat, e.g., to see cars several miles ahead and plan its route accordingly, or to just change the positions of other cars on the highway. This should never be possible, even if you do not care much about security, because such things may also happen unintentionally and may be tricky to debug.

根据您的要求,您的架构可能,当然需要为复杂得多更多信息应该很容易从文学到获得多代理模拟系统(这是你的问题的概括,即几种的药物可以模拟驾驶你的高速公路)。有很多这方面的研究正在进行,有几个工具,多主体仿真,你可能想看看(如就餐)。

Depending on your requirements, your architecture may of course need to be much more sophisticated. Further information should be easy to get from literature on multi-agent simulation systems (this is a generalization of your problem, i.e. several agents can be simulated to drive on your highway). There is a lot of research going on in this field and there are several tools for multi-agent simulation that you may want to look at (such as Repast).

这篇关于什么是该模拟器的最佳架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆