我对Anylogic来说是相当陌生的,我正在尝试弄清楚如何使用“定制分配optoftions”构造函数来手动创建“选项列表”中定义的项目的随机分发。我的目标是根据用户输入动态定义选项列表 - 项目的自定义分发。在网上研究如何动态定义自定义分发的解决方案之后,我遇到了此解决方案:中。在这篇文章中,用户使用构造函数来创建自定义分发,这也是我想要做的。但是,每次我尝试在“主要”代理中初始化构造函数作为启动行动,我都会得到一个
error 指出该方法对MAIM类型不确定。
我不明白为什么此错误不断弹出,因为文档指出我可以将函数“ customDistributionOftions()”用作构造函数。请让我知道我不了解和/或缺少什么。
I am fairly new to Anylogic and I am trying to figure out how to use the "CustomDistributionOfOptions" constructor to manually create a random distribution of items defined in an "Options list". My goal is to dynamically define the custom distribution of the options-list-items based on a user input. After researching solutions online on how to dynamically define a custom distribution, I came upon this solution: Dynamically Changing Distribution in AnyLogic. In this post, the user uses a constructor to create a custom distribution, which is what I want to do as well. However, every single time I try and initialize the constructor in my "Main" agent as an action on startup, I keep getting an
error that states that that method is undefined for the type Main.
I do not understand why this error keeps popping up, as the documentation states that I can just use the function "CustomDistributionOfOptions()" as a constructor. Please let me know what I am not understanding and/or missing.
发布评论
评论(1)
这是从我的一个模型中初始化自定义分发的一个示例:
它正在做的是宣布类型
cuteandistibutionOftions< vaccineattitude>
的新变量,其中vaccineatitude
是选项。列出列出发行的选项。该变量的名称是customDistributionVaccineattute
。根据任何logic vaccineattitude.values(),类型double
的权重数组以及拥有变量的代理。在此示例中,代码位于MAIN中,因此是指main。您可以按以下方式查询分布:
结果
将从选项列表中包含随机值vaccineattute
根据构造函数中指定的权重从分布中绘制的。Here is an example of initializing a Custom Distribution from one of my models:
What it is doing is declaring a new variable of type
CustomDistributionOfOptions<VaccineAttitude>
, whereVaccineAttitude
is the Option List that lists the options for the distribution. The name of the variable iscustomDistributionVaccineAttitude
. As per the AnyLogic documentation, the constructor takes the values of the Option List,VaccineAttitude.values()
, an array of weights of typedouble
, and the agent that owns the variable. In this example, the code is located in Main, sothis
refers to Main.You may query the distribution as follows:
result
will contain random value from the Option ListVaccineAttitude
drawn from the distribution according to the weights specified in the constructor.