I have an selectOutput block in which I would like agents of type Patient to continue through OutT if they have passed through a particular timeMeasureStart block. After passing agent.timeMeasureStart in the condition, I receive 'timeMeasureStart' cannot be resolved or is not a field.
Create a variable for your agent type Patient. Let's say you name it tmsTrue. Make the variable of type boolean. In the On Enter field of the timeMeasureStart block write:
agent.tmsTrue = true;
Then set your select output condition as:
agent.tmsTrue == true
Of course make sure that the variable's initial value is set to false.
Related
I am trying to inject with a function objects from a population into a source block.
In the function I used this inject() function:
for (mp_lkw mp : mplkws)
{
if (dateToTime(mp.ankunft) <= time()) {
remove_mplkws(mp);
source1.inject(mp);
}
}
Now my source should accept that injection, but an error occurs, that it is only applicable for Integers
Unresolved compilation problem:
The method inject(int) in the type Source<mp_lkw> is not applicable for the arguments (mp_lkw)
I wonder why it doesnt accept my agent type even though the settings in source for "New agent:" and "Agent type:" are set to my agent "mp_lkw"
This is not how the inect() method works. It only lets you specify the number of agents that the Source block creates when you call it. But the details of the agents themselves are set by the Source block.
In your case (where an agent already exists and just needs to start a new flow chart), you replace the Source block with an "Enter" block.
In the code, you call myEnterBlock.take(mp);
I have a Select function in my block diagram. For the True and False statements I am passing two data types. The True statement is a is a Digital Reference data type to a numerical indicator in the front panel, and the False statement is a knob Reference data type to a gauge in the front panel as well. I am not sure what to put in the middle entry point for the Select function since it needs to have a True Boolean. Ideally I would just connect another Digital Reference data type and it would return the digital indicator in that case but the Select function only receives a boolean as an input.
Ideally I would just connect another Digital Reference data type and it would return the digital indicator in that case
In what case? You haven't defined any case. :-)
The Select node picks between two different values. When you wire the digital reference to one input and the knob reference to the other input, the output will be a control reference to one of those two controls. You have to wire a Bool in order to pick which control you're going to operate on downstream.
You say you want to wire another Digital Reference to the middle terminal, but that's just a reference to a control. It doesn't define a choice. Perhaps you want to read the Value property of that other control and do something on the value? If so, this is your code, where you put whatever test you want instead of the Equal Zero node.
Select function requires a boolean in the selector input. The other two inputs changes according to what you connect.
So, in your scenario:
Output type is the most lower common class between knob reference and numeric reference. It should be a Numeric reference.
the selector input must be a boolean type. You cannot connect any reference or any other data type. So, connect a boolean control or use the approach suggested by srm.
I found a solution by connecting an equal function to the middle boolean selector input of the select function. The equal function has two inputs, an either Knob Reference or Digital Reference for the first input and a Digital Reference for the second input. If those two are equal then the equal function passes true to the selector function and then the Digital Reference gets passed in this case.
I am trying to seize a given number of resources dynamically, but I can't figure out the syntax. In the Resource Sets Dynamic Assignment, each unit is represented by the name of the resource set it belongs to. In the picture, the seize block will seize 3 resources of the set "resourcePool".
I need to seize a specific number of resources for each individual agent. Then I tried creating ArrayList of Resource Pool objects and passing it in the dynamic assignment but it doesn't work as the type doesn't match.
For example, let's say I have an agent which requires 4 resources, so the expression needed is: { resourcePool, resourcePool, resourcePool, resourcePool }. How can I assign this expression in a variable or collection of the agent such that it can be used in the Resource Sets Dynamic Assignment box? I think I should finally get something like:
{{agent.resourceSetsToSeize}}
So how to define "resourceSetsToSeize"?
You were so close. The only issue is that the parameters inside the agent must be of type ResourcePool[][], an array of arrays. To convert an array list, in your case resourceSetsToSeize to array you need to call toArray() but with the argument of the specific array you want to convert it to.
So your code should have looked like
{agent.resourceSetsToSeize.toArray(new ResourcePool[resourceSetsToSeize.size()]}
(Assuming that resourceSetsToSeize is a List object
The code can be a bit confusing, see another example below of how to rather use an array as the parameter and then use that directly without converting.
Here is an agent with the parameter of type ResourcePool[][]
When you create the agent you then create this array and put it in the constructor. As you can see you don't need to use the empty constructor and then assign it, you can make use of your parameterized constructor.
And then in the seize object you can simply access the parameter.
I am trying to pass text with dynamic content as a parameter into a pipeline (execute pipeline activity).
As a super simple example, I want the input to my pipeline to be a timestamp, utcnow(). Here are my results:
I've noticed:
If I put #utcnow() in a set variable activity and set the execute pipeline parameter to that variable it works.
If I put #utcnow() (or #{utcnow()}) in the main parameter and set the execute pipeline parameter to that parameter it does not work. I get that string "utcnow()" as the result.
Is there anything that I am missing here? I definitely feel like I've done this successfully before.
If I understand your question correctly, the issue is caused by the main parameter(pipeline parameter) doesn't support expression or functions.
For example, we could pass the value from variable to pipeline active parameter, and it works well, because variable support expression/functions:
When the main pipeline only contains an Execute Pipeline active, we pass the value from main parameter(pipeline parameter) to the Execute Pipeline parameter:
When we debug the pipeline, we need pass the value of main parameter:
The value of pipeline parameter only support the String value, then function utcNow() or #{utcnow() will considered as the String.
I understood that I can insert different types of agents in the same block by changing the agent type in the whole process to the generic Agent (works well thanks to Amy). snapshot
But, I am stuck on how to get them out using a manual casting for the process selectOutputIn1. Each Agent type has a parameter called p_new_location with type SelectOutputOut.
What I need help in
passing what is equivalent to agent.p_new_location if properly casted through selectOutputIn1.
What I have tried
creating a function with manual casting:
if( agent instanceof Wife){
return ((Wife)agent).p_new_location ;
} else if(agent instanceof Child_M){
return ((Child_M)agent).p_new_location ;
} else if(agent instanceof Child_F){
return ((Child_F)agent).p_new_location ;}
how it looks with the error
Unfortunately, as you can see there is an error saying the method must return a result of type SelectOutputOut although it is already defined.
The parameter type in each class looks like exactly like this. And from inside the simulation, it looks like this before passing the value and like this after passing its value. Furthermore, I noticed that the value of an uncommon parameter type like SelectOutputOut, is not showing during the simulation as shown here. As you can see parameters (age, countDb and taken) are all there with their values but, not p_new_location.
The Solution
Thanks to Amy Again :)
The compiler is seeing if / else if / else if. What if none of those are true? If your last else if is the only option, just change that to an else or put in appropriate code for what you want to do.
This is how the code looks like now
if( agent instanceof Wife){
return ((Wife)agent).p_new_location ;
} else if(agent instanceof Child_M){
return ((Child_M)agent).p_new_location ;
} else{
return ((Child_F)agent).p_new_location ;}
Thanks inAdvance;
Yes, AnyLogic can easily handle multiple agent types in a single process block. A few things to keep in mind:
Make sure the process block is set to handle a generic type "Agent" or the parent class of mother, father, child.
Since you have multiple agent types flowing through the same blocks, you should be prepared to do some casting to get any class specific information.
AnyLogic agents cannot be in more than one flowchart block at a time, even though they can be in many collections. They can also be in NO flowchart blocks. Before you send an agent to an enter block, you must first remove it from any other block it is in (if it is in one). For example, if all you wives were in a queue, you would need to remove the wife agent from the queue before calling your enter.take( wife ) line of code.