Python,基于代理的建模,循环

发布于 2025-02-01 21:44:08 字数 496 浏览 2 评论 0原文

在基于代理的建模中,我正在生成一个循环,其中我有一些步骤如下:

  1. 我想解决一个所谓的“问题”,其中一个名为X的变量必须至少10个。
  2. 我有3个问题,我有3个问题我正在随机选择以解决。
  3. 一旦我选择了一个问题,我就有5个迭代来解决它:i = 1,...,5。
  4. 在每次迭代中,计算变量x。
  5. 如果x大于10,则解决问题。 (例如,它可以在i = 3上)。
  6. 在解决问题的任何迭代中,我都会停止迭代并选择另一个问题。然后,我将从上一个步骤(步骤5)(例如x_output)获得的X用作输入(例如,x_input = x_output)。
  7. 但是,如果我处于上次迭代(i = 5)中,但问题尚未解决,我会在x上进行额外的计算,将其命名为x_output,然后随机选择另一个问题,然后再次进行循环。
  8. 我收集所有X_Output,并让循环运行任何任意数字(例如200次)。

我的问题是如何执行此循环。我感谢任何见解。谢谢,

In an agent based modeling, I'm generating a loop in which I have some steps as follows:

  1. I want to solve a so-called 'problem' in which a variable named x has to be at least 10.
  2. I have 3 problems that I'm picking randomly to solve.
  3. Once I picked a problem, I have 5 iterations to solve it: i = 1, ..., 5.
  4. In each iteration, the variable x is calculated.
  5. If x is greater than, say, 10, then the problem is solved. (it could be on i=3 for example).
  6. In any iteration that the problem is solved, I stop the iteration and pick another problem. Then I use the x I obtained from the previous step (step 5), (say, x_output) in the next problem's first iteration as an input (say, x_input = x_output).
  7. However, if I was in the last iteration (i=5) yet the problem is not solved, I do an extra calculation on x, name it as x_output, and pick another problem randomly, and do the loop again.
  8. I collect all the x_output's and let the loop run for any arbitrary numbers (200 times for example).

My question is how to perform this loop. I'd appreciate any insights. Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文