Create a new transporterFleet from an existing transporterFleet [closed] - anylogic

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I have a transporter type agent called Truck. Its population called truck. I added a TransporterFleet block to the model which is called truckFleet. In truckFleet I selected Truck for both New Transporter and Transporter Type sections. An agent called trench seizes from truckfleet and when it release the truck, it will allocate a value to a variable as I used ((Truck)unit).v_capacityFull = true; in the on release transporter section.
Now I have another agent called dumping. Now this agent needs to sieze a specefic truck from truckFleet. one that has the following value v_capacityFull == true.
So I have been applying two approaches:
I used the same transportFleet which called truckFleet. But I use a dynamic Fleet section in which I typed new truckFleet = List filter(truck, t -> v_capacity == 0);
I created a new transporterFleet called fullTruckFleet and in the new transporter section I typed new truckFleet = List filter(truck, t -> v_capacity == 0); but in the transporter type I still used Truck.
for the first approach: I get the following errors:
and for the second option: I get the following errors:
In general, I am not happy about non of them but could not think about another approach. And I am not just interested to resolve errors but to find an approach that fulfill my intentions.

The answer is very easy actually. I can use the same truckFleet but in the Advanced section of the SeizeTransporter block, in Transporter choice condition section, I can type ((Truck)unit).v_capacityFull == true. :)

Related

In AnyLogic, is there a way to easily specify the offset of a resource when attached to an agent?

I think the title of the question is clear enough. I could try to add some code changing the coordinates of the resource every time it is attached. But this is a manual and indirect way. Is there a direct way to do it from within the block's properties? Thank you.
I asked what block it was just to clarify the question, it's the same answer for both of them, which is to use a variable in your resource agent called offset, then the x of your resource will be equal to that variable offset.
On the seize block, in the on seize action you can do ((Resource)unit).offset=theOffsetYouWant;
I think that solves your problem

Anylogic how create new agent and assign properties?

Anylogic: This should be simple but I just cannot find it in the help files..
On creating a new agent instance, we know there are four parameters and what they are, but not in what order they were defined. Lets say parameters are "type_of_car" (String), "number_of_pax" (Integer), "automatic" (boolean), "fuel_capacity" (double). Now when calling: new myagenttype("ford", 5, false, 55) the agent gets created as a ford with 55 pax, manual and 5 liter fuel capacity - which is all wrong. (it seems the definition order of the parameters in the agent definition are in a different order)
How do we include the parameter name (or definition) when we call new agenttype() to avoid this problem, ensuring the right value gets assigned to the right parameter?
The problem originates because of a bug in Anylogic's logic in triggering functions. We have a Split which creates a new agent and assigns the agent properties on the "On exit copy" - event, however what Anylogic does is it creates the agent, forward it to the next logical block (a decision node), then execute the code of the decision - all wrong now for the agent's properties are undefined - and only then executes the "On exit copy" event which assigns the agent's properties. Very frustrating.
This is actually not a bug, this is defined in the simulation experiment properties, in the randomness section, with the "selection mode for simultaneous events" property. The default is LIFO, but if you want the opposite behavior in your case you should use FIFO... I always use LIFO too, and in these cases, sometimes I might use a 1milisecond auxiliary delay between the split and the next block in order to control the order manually... if you do that, you will solver your problem in fact... just use a 0.001 miliseconds delay after your split
Now from your Agent Type problem, the arguments for your class constructor should be written in order, and the only way to know the correct order is by using the autocomplete feature when you write new agenttype()... the autocomplete will tell you the order in which you should write your constructor arguments.

What is the right way to allot a distinct value to an agent's parameter in Anylogic?

I want my agent to be of a single type. Where type contains a list of 3 options. And the allotment should be based on probability. E.g. let's say I want to allot 1: 30%, 2: 50% and 3: 20% to each of the agents generated in the source of my main tab.
I tried with one of the ways by declaring th parameter as int and then writing randomTrue(0.3)?1:randomTrue(0.7)?2:3 in the default value. But every time the agent comes with the same value of 2.
Please can anyone help me with this??
And if I try to allot the parameters in the main window at any of the blocks, do they get attached to the specific agent that passes through that block or its value just gets updated for that time until the other agent passes? Actually I have to check each and every agent for the parameter and then send it through a specific output path from the selectoutput block.
Your code does not actually change anything in the created agent.
Create a parameter `myType´ of type Integer.
In your source code write:
agent.myType = randomTrue(0.3) ? 0 : randomTrue(0.7) ? 1 : 2
Make sure your Source block actually creates agents of the Agent type that holds the myType parameter.
Study some of the example models and tutorials, it is covered in many places :-)

How I can match bags an passenger in the reclaim area?

I'm simulating a security control process, and i can't do that each passenger pickup their baggage. I have tried with Match, Combine, Pickup, but I still can't execute the commands correctly.
I've created the follow flowchart, and the problem is in the wReclaimPax, pickup and wReclaimBags blocks (you can see them in the picture).
https://ibb.co/v3V57Tm
I saw this link Anylogic - Combined multiple items back to original owner to understand something, but I still need help.
I've created 3 functions:
isMatch:
if(equipaje.pasajeroLink.equals(pasajero.equipajeLink)){
return true;
}
return false;
paxBags:
for(int i=0;i<wait.size();i++){
Pasajero p=(Pasajero)wait.get(i);
if(isMatch(p,bag))
return p;
}
return null;
bagsPax:
for(int i=0;i<wait.size();i++){
Equipaje e=(Equipaje)wait.get(i);
if(isMatch(pasajero,e))
return e;
}
return null;
Assumed context
You haven't really explained how your code is related to your process but I'm assuming the following:
Because this is luggage-retrieval, you want to ensure that a passenger
agent (Pasajero) only enters the Pickup block (representing taking bag from
carousel) when his bag (Equipaje agent by the look of it) has
arrived into the wReclaimBag Wait, and been released from it to
queue4 Queue.
For this you need triggers (to remove agents from Wait blocks) when
either a passenger (Pasajero) arrives in wReclaimPax Wait, or a bag (Equipaje) arrives
in the wReclaimBag Wait (because you don't know whether the passenger or their bag will get to their respective Wait blocks first).
So your paxBags function is called in on-entry action of the wReclaimBag Wait, and your bagsPax function in the on-entry action of the wReclaimPax Wait.
Possible problems with current approach
Without knowing more of your model it's hard to say but problems I can think of based on what you've supplied are:
Your functions return the Pasajero or Equipaje if there is one that matches. Your match check relies seemingly on bidirectional connections (links) between Pasajero and Equipaje. Obviously if they're not setup properly the model won't work and, if you're using bidirectional connections you shouldn't need to check both ends.
Your functions need calling so that, if they return non null, they then free the matching agent from the other Wait block, and free themselves. Are you doing that? Without checking, there may be issues with calling free for yourself as you enter a Wait block (since this kind of depends on AnyLogic internals as to whether you count as being 'in' the block at this stage and can be freed). If this seems to be the problem you could create a timeout 0 dynamic event instance to do the free so that you're not doing it within the scope of the on-enter action.
Your pickup block (since it's been setup so that the entering agent will always want to pickup the first agent (Equipaje) in queue4) just needs to be set as waiting for quantity 1 (though see below).
If you've done all this the most likely problem is that the underlying events ordering of AnyLogic is affecting things. When you free agents I'm fairly sure the freeing actually happens in a timeout 0 event scheduled under-the-covers. So it may be that the passenger arrives at the Pickup before their Equipment arrives in queue4 though, if you set the Pickup to be "Exact quantity (wait for)", with quantity of 1, it should handle that.
The animation of the process (numbers in/out/within each block and details when clicking on blocks) should also help you debug what is going wrong; e.g., are bags being left in the Wait when they should have been released, etc.
P.S. With this kind of thing you should always create a minimal example model to make testing the issue/solution easier (and for sharing in help forums such as this where the rest of the complexity of your model is irrelevant). Often you find the problem 'naturally' in the process of trying to construct such a model that reproduces your problem in a minimal way.

Why use a wildcard (_) in Swift? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Going through the Apple documentation for Swift, I'm designed a for loop that creates 5 buttons to act as "stars" in a 5-star rating feature.
I noticed that the for loop is constructed as follows:
for _ in 0...<5
And in the explanation for this, Apple mentions that you can use a wildcard _ operator when you don't need to know which iteration of the loop is currently executing.
But what's the upside to not knowing the iteration? Is it a memory saving issue optimization? Is there ever a scenario where you don't want to know the iteration?
In general, unused variables add semantic overhead to code. When someone reads your code, they need to make an effort to understand the function of each line and identifier, so that they can accurately anticipate the impact of changing the code. A wildcard operator allows you to communicate that a value that is required by the syntax of the language is not relevant to the code that follows (and is not, in fact, even referenced).
In your specific example, a loop might well need executing a certain number of times, but if you want to do the exact same thing on each iteration, the iteration count is irrelevant. It's not especially common, but it does happen. The semantic overhead in this case is low, but it's meaningful (you're making it clear from the start that you intend to do the same thing every time), and it's a good habit to get in, broadly.
The for loop index needs to be stored in memory, so this won't serve as any kind of memory optimization.
I think most importantly it easily conveys to readers of the code that the loop index is not important.
Additionally, it prevents you from having to come up with some arbitrary dummy variable name. It also declutters your name space when you're debugging inside the loop, since you won't be shown this dummy variable.
Is there ever a scenario where you don't want to know the iteration?
Certainly. Consider:
func echo(_ s:String, times:Int) -> String {
var result = ""
for _ in 1...times { result += s }
return result
}
How would you write it?
This is not necessarily about knowing the iteration. When you don't need to know the element inside the loop you are iterating. The underscore is that placeholder - just as the underscore is the symbol in the declaration suppressing externalization of the name. Check this SO Thread for more detail about this.