Looking for some tips on a Simulation Project!

3 次查看(过去 30 天)
Hi, I'm creating a MATLAB code for a Parasite & Food simulation which is similar to a random walk. In this Simulation; the Food agents remain stationary, scattered randomly around a domain, and the Parasites take steps around this domain. The parasite can move onto a food cell and 'eat the food' (food cell is changes to a parasite cell), or move to an empty cell. (two parasites can't occupy the same cell)
So this is my problem:
In previous random walk simulations I've used a logical array where 1 = a particle, and 0 = free space. In this case I now need three different objects: Free space, Parasites, and Food. So it seems a logical array would no longer work. The best current idea I have is to create an array and somehow set : 0 = free space, 1 = food and 2 = parasite, but I'm wondering if there is a better way of doing this?
any tips or pointers would be great, thanks!

采纳的回答

John D'Errico
John D'Errico 2018-10-12
Is there a better way? Not really. In fact, your plan is actually a good one, and arguably the best approach. The true art will be in terms of how you implement it, how efficiently you write the code, not in terms of how you will store the data in this case.
Of course, there are probably always OTHER ways to solve any problem. But your task should be to find A way to solve it. If it works, then don't worry about finding the truly perfect, optimal solution. Don't waste programmer time in pre-optimizing code that is not a problem otherwise. As you grow in programming skill, your code will improve.
  1 个评论
Ben Shaw
Ben Shaw 2018-10-12
Thanks for the tips, I've started messing around with the idea and trying to get a working code now, so that's good to hear.

请先登录,再进行评论。

更多回答(1 个)

Nicola Bombace
Nicola Bombace 2018-10-12
Enumerations can be a good way to mark your states.

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

产品


版本

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by