通过均匀分布生成具有不同颜色的相同类型的剂 - 任何logic

发布于 2025-02-10 02:24:16 字数 465 浏览 7 评论 0原文

您好,

我正在尝试添加一个源,该源生成具有不同颜色的代理,这些颜色是根据不均匀分布随机填充的。例如,我希望看到该来源会产生50%的具有橙色或10%LightskyBlue颜色的代理商。 到目前为止,我有这条线,从 availablecolors 数组中随机选择颜色。但是我需要基于其相关概率选择每种颜色。

availableColors = { oliveDrab, crimson, orange, lightSkyBlue, darkOrchid }

agent.favoriteColor =
    randomFrom(availableColors);

有线索吗?谢谢

Hello there,

I am trying to add a source that generates agents with different colors that are randomly populated based on a non-uniform distribution. For example, I'd like to see this source generates 50% of the agents having orange or 10% of them lightSkyBlue color.
I have this line so far that randomly selects a color from availableColors array. But I need each color to be selected based its associated probability.

availableColors = { oliveDrab, crimson, orange, lightSkyBlue, darkOrchid }

agent.favoriteColor =
    randomFrom(availableColors);

Any clue? thanks

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

°如果伤别离去 2025-02-17 02:24:16

从具有以下属性的代理调色板中创建自定义分发。在下面,2表示“无颜色”。如果您使用百分比,观察值的总和应始终为100。

然后创建一个具有以下属性和主体的函数:

int colorID = colorProbabilities();

if( colorID == 0 ) { return orange;}
else if (colorID == 1 ) { return lightSkyBlue;}
else return null;

最后,您现在可以使用:

agent.favoriteColor = colorPicker();

现在允许您在任意数量的任何颜色和任何概率上自定义分布。

Create a custom distribution from the Agent palette with the following properties. In the below, 2 represents "no color". The sum of the number of observations should always be 100 if you are using percentages.

enter image description here

Then create a function with the following properties and body:
enter image description here

int colorID = colorProbabilities();

if( colorID == 0 ) { return orange;}
else if (colorID == 1 ) { return lightSkyBlue;}
else return null;

Finally, you can now use:

agent.favoriteColor = colorPicker();

This allows you now to customize your distribution at any point to any number of colors and to any probabilities.

赠我空喜 2025-02-17 02:24:16

您应该以另一种方式进行操作:

  1. 在源块创建的代理类型中,添加一个名为myShapeHavingColor
  2. 在源块中,请确保其
  3. 在该类型中 创建该类型的代理源块,在“ on ot Exit”代码框中,您现在可以从所需的分布中更改颜色,例如:

“在此处输入映像”

You should do it the other way around:

  1. In the agent type that your Source block creates, add a shape (rectangle...) named myShapeHavingColor
  2. In the Source block, ensure it creates agents of that type
  3. In the Source block, in the "on at Exit" code box, you can now change colors from your desired distributions, for example:

enter image description here

浅语花开 2025-02-17 02:24:16

如果您不满意编码,另一个简单的答案是使用选择的输出块。这样简单的东西:

Another simple answer if you're not comfortable with coding is to use the select output block. Something as simple as this:
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文