Anylogic - recording resource pool activity - anylogic

I have a job shop scheduling model in anylogic and I want to do a gantt chart for the resource pools (machines). In resource pools actions section exists one called On unit state change and in the help of the resource pool it says the this field has a busy variable associated to it.
Here is the help of resource pool.
I though I could do a while loop in this field so that when the busy variable is true I add the value 1 to my data set and when busy is false I add the value 0. But the problem is when I run my model using that while loop I don't get any error but my model doens't run anymore.
Here is the while loop.
If anyone know what to do please help. Thank you in advance.

Yeah, while loops can easily kill models if the condition stays true.
You need to understand that the code is executed whenever any resource in the pool changes its state.
So you should not use a while loop but a simple if-statement:
if (unit.equals(theUnitMyGanttChartCaresAbout) {
if (busy) {
// tell Gantt chart that "unit" started being busy
} else {
// tell Gantt chart that "unit" started being idle
}
}

Related

How to use Resource pool for for cleaning the tank in AnyLogic

When the tank gets empty the valve get close for 30 minutes (this 30 minutes is for cleaning the tank) am using dynamic event for that. as showmen in image below.
Now what I want to do is
use Resoucrepool (a worker) for cleaning the tank.
Use Resoucrepool (a worker) for opening and closing the valve.
Its there any way to achieve that?
what you can do is that on the "on empty" action in the tank, you generate a token, which is an agent called cleaningRequest that goes into a flow that requires a resource (enter-service-sink), and you close all the valves to avoid using that tank.
When the resource is released, or when the token gets to the sink, you open the valves again.
I only answered question 1, but question 2 should follow the same technique

Changing transporterfleet based on programmaticaly created schedule

In following up related to my previous question previous question, when a schedule programmatically is created, where I run the function at the start-up of my main (see image 1), I want to change the transporterfleet (image2) schedule based on this. But when I do this by the initschedule function the next error is given " The parameter capacitySchedule cannot be changed dynamically". So my question is how can you use a programmatically created schedule use in the capacity definition of a transporter fleet?
Later added in response to Benjamin
In the Capacity field, write schedule == null ? 0. : schedule.getValue()
This will link it to your programmatic schedule, but only after it has been created (which is not done right at the start of the model but an instance later).

"While loop" not working in my Anylogic model

I have the model which I posted before on Stack. I am currently running the iterations through 5 Flow Chart blocks contain enter block and service block. when agent fill service block 5 in flow chart 5, the exit block should start to fill block one and so on. I have used While infinite loop to loop between the five flow chart blocks but it isn't working.
while(true)
{
for (Curing_Drying currProcess : collection) {
if (currProcess.allowedDay == (int)time(DAY)) {
currProcess.enter.take(agent);
}
}
if (queue10.size() <= Throughtput1){
break;
}
}
Image for further illustration 1
Image for further illustration 2
Wondering if someone can tell me what is wrong in the code.
Based on the description and the pictures provided, it isn't clear why the while loop is necessary. The On exit action is executed for each Agent arrival to the Exit block. It seems that the intention is to find the appropriate Curing_Drying block based on number of days since the model start time? If so, then just iterating through the collection is enough.
Also, it is generally a good practice to provide more meaningful names to collections. Using simply collection doesn't say anything about the contents and can get pretty confusing later on.

Trouble with agent state chart

I'm trying to create an agent statechart where a transition should happen every day at 4 pm (except weekends).
I have already tried:
1. a conditional transition (condition: getHourOfDay() == 16)
2: A timeout transition that will "reinsert" my agent into the chart every 1 s and check if time = 16.
My code is still not running, does anyone have any idea how to solve it?
This is my statechart view. Customer is a single resource that is supposed to "get" the products out of my stock everyday at 4pm. It is supposed to happen in the "Active" state.
I have set a timeout transition (from Active-Active) that runs every 1s.
Inside my "Active" state in the "entrance action" i wrote my code to check if it is 4 pm and run my action if so.
I thought since i set a timeout transition it would check my condition every 1s, but apparently it is not working.
Your agent does not enter the Active state via an internal transition.
Redraw the transition to actually go out of the Active state and then enter it again as below:
Don't use condition-based transitions, for performance reasons. In your case, it also never triggers because it is only evaluated when something happens in the model. Incidentally, that is not the case at 4pm.
re your timeout approach: Why would you "reinsert" your agent into its own statechart? Not sure I understand...
Why not set up a schedule or event with your recurrence requirement and make it send a message to the statechart: stateChart.fireEvent("trigger!");. In your statechart, add a message-based transition that waits for this message. This will work.
Be careful to understand the difference between the Statechart.fireEvent() and the Statechart.receiveMessage() functions, though.
PS: and agree with Felipe: please start using SOF the way it is meant, i.e. also mark replies as solved. It helps us but also future users to quickly find solutions :-) cheers

Talend ETL - running child job in tLoop

I am trying to run a child job in tLoop. The child job connects to salesforce and downloads "Account" object to local SQL Server table. There are problems with connection to Salesforce, it takes few attempts to connect. Hence, I put the connection stuff in child job and now trying to call the child job in a loop. Below is the image of my parent job.
As you can see in image the tRunJob_1 has error because of Salesforce connection problem in child job. This is correct behaviour.
The setRetryConnect that is connected to OnComponentError has this code: context.retryConnect = true;
The setRetryConnect that is connected to OnComponentOk has this code: context.retryConnect = false;
So, I am tripping this context variable depending on whether child job succeeds or fails.
My tLoop looks as below:
I want the tLoop to run as many times till the condition remains true. That is till the time it continues to error out. However, it just iterates once and then stops. Could anyone please let me know what correction need to be done here to make the tLoop work?
I couldn't re-pro your issue with SalesForce but by looking at your job what I feel is that when you say - "it just iterates once and then stops" is the expected behavior.
As per your job flow after the tRunJob you are using OnComponentOk/OnComponentError trigger which would process and stop the job run as it would have completed the job execution. What it would have ideal was to keep everything in a subjob post tLoop so that it will iterate till the condition is met.
Sample job for explanation -
Here used tSetGlobalVar to define a global variable (in place of your context variable). Then use the globalMap variable as ((Boolean)globalMap.get("tLoop")) in your "Condition" for the tLoop.
And then finally run some code in the tJava component that does something and conditionally sets the global variable to false to mark the ending of loop.
tRunJob provides an Return Code ((Integer)globalMap.get("tRunJob_1_CHILD_RETURN_CODE"))
If you're running your child Job a number of times and want your Job to exit with non-Zero if one of these iterations fails, then after each iteration, you should test this return code and store it in your own globalMap Object if it is non-zero
int returnCode = ((Integer)globalMap.get("tRunJob_1_CHILD_RETURN_CODE"));
if (returnCode > 0) {
globalMap.put("tLoop", false);
}
else {
System.out.println(returnCode);
};
Found the answer myself, posting it here so that it may help others. It appears like OnComponentError breaks the tLoop. Disabled the OnComponentError flow and un-checked the 'Die on Child Error' checkbox in tRunJob.
The tLoop remains as it is. No changes here.
The retryConnect will use the below code. It uses CHILD_RETURN_CODE to check whether the child job threw error. In case of success, its value is 0. I am tripping the variable when the child job succeeds, so the loop will stop. As you can see, the tLoop shows 2 iterations, it is working as expected now. Thanks.