如何使用算法来决定多线程运动模拟. [英] How we can use algorithm for decision about movement simulation by multi thread.

查看:58
本文介绍了如何使用算法来决定多线程运动模拟.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过多线程(很多人)决定模拟运动逃逸的算法是什么.

谢谢

[我希望这是对问题的准确表述]
我想构建一个应用程序来模拟人们在大火中的反应.想象一下,我们有一幢人满为患的建筑物,并且我们要模拟火灾警报器.我们需要为每个人创建一个不同的线程,并有一个算法来确定该人应该去哪里逃跑并以某种方式模拟运动.

用来模拟这种情况的最佳算法是什么?

what algorithm for decision about simulation''s movement escape from on fire by multi thread(many people).

Thank,

[I hope this is an accuracte rephrasing of the question]
I want to build an application to simulate how people respond during a fire. Imagine we have a building full of people and we want to simulate a fire alarm. We need to create a different thread for each person and have an algorithm figure out where the person should go to escape and simulate the movement in some way.

What is the best algorithm to use to simulate this?

推荐答案

您似乎混淆了线程和模拟.通过模拟,您尝试创建一种受控情况,在该情况下您可以通过预定义规则来控制步骤.模拟可以比实时运行得慢或快,而不会出现问题.时间与模拟有关,因此与步骤有关,并且仅由模拟的观察者注意到.为简单起见,模拟以循环方式运行,并且该模拟中的每个实体一次只能执行一个步骤.因此,所有人都要采取行动,消防部队"也要采取行动.所有这一切都以非常可控的方式发生,并且即使有更多或更少的实体,也可以随时随地跟踪.这意味着可以将一个周期定义为一秒钟,并且如果您的仿真需要10秒或1毫秒,则仅意味着观察者必须等待更长或更短的时间才能看到最终结果.

引入线程是另一回事,应该仔细考虑,但是当然不应该作为起点.由于您尚未定义规则,因此不建议您先从线程开始.当然,每个模拟人员都从一个线程开始,因为这样会更快地降低速度而不是加快速度.

模拟是一个单一的游戏,其中每个实体每个周期移动一个步骤,并根据先前的状态做出决定.因此,实体根据周期之前的状态做出主要决策,并且仅进行碰撞检查,以确保不会发生任何不可能发生的事情,尽管在您的情况下人们可能会碰到彼此.必须将单个周期视为单个时刻,并且每个实体都在同一时间进行移动.当然,处理是顺序进行的,它们一个接一个地移动,只有观察者才能注意到这一点.好像把我们的生活分成几步一样看,即使我感觉这一切都是流畅地进行着,也许我们的创造者低头了,必须等待一个小时才能看到你略微动了动.这都是相对的,与使用线程创建一切同时发生的感觉无关,因为这正是模拟所模拟的;)

首先定义元素(实体)及其动作.然后考虑一下规则(例如:如果火距比三块瓷砖近,则远离火).从非常简单和基本的规则开始,然后从那里开始工作.首先创建一个简单但可视的引擎来将模拟数据转换为屏幕上的图像是很不错的.使用此工具,您可以轻松地进行更复杂的仿真.逐步记住,一次记住一个步骤.

祝你好运!
You seem to mix up threads and simulation. With a simulation you try to create a controlled situation where you controls the steps by predefined rules. A simulation can run slower or faster than real-time without a problem. The time is relative to the simulation and therefore to the steps and are only noticed by the observer of the simulation. To keep it simple, the simulation runs in cycles and each entity within that simulation can do one step at a time. So all the people do a step and the "fire units" do a step. This all happens in a very controlled way and can be kept in track with time even when there get more or less entities. This means that a single cycle could be defined as a single second and if your simulation needs 10 seconds or 1 millisecond this only means that the observer has to wait longer or less to see the end results.

To introduce threads is a really other game and should be carefully thought out but certainly shouldn''t be your starting point. Since you do not have the rules defined yet it is not advised to start with threads already. Certainly to start with one thread per simulated person because this would sooner slow it all down instead of speed it up.

A simulation is a single game where every entity moves one step per cycle and makes it''s decision on the previous state. So the entities do their main decision making based on the state it was just right before the cycle and only do for example collision checks to make sure nothing happens that cannot be possible, although people can run into each other in your case. A single cycle must be seen as a single moment in time and every entity makes a move at that same time. Of course the processing is done sequential and they move one after one, this again is only noticed by the observer. Look at it as if our life is divided into steps and even though I have the feeling it is all happening in a fluently motion, maybe our creator looks down and must wait one hour to see that you have slightly moved. It is all relative and has nothing to do with using threads to create a sense that everything happens at the same time, because that is just what a simulation simulates ;)

Start by defining the elements (entities) and what moves they can do. Then think out the rules (Like: If fire closer than three tiles away then move away from fire). Start out with very simple and basic rules and work from there. It''s nice to first create a simple but visual engine to convert the simulation data to images on screen. With this you can easily work towards a more complex simulation. Step by step, one step at a time, keep that in mind.

Good luck!


这篇关于如何使用算法来决定多线程运动模拟.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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