Day Exception in Events in AnyLogic - anylogic

I am currently doing a simulation model in AnyLogic of a Distribution Center where from Monday to Saturday I use an event to trigger the loading of a truck. I wish to program this loading every day at the same time, but how can I do it so it happens everyday EXCEPT Sundays. I currently have it as triggered: timeout and mode: cyclic, using calendar dates...

sure, the easy way is to just add a manual exception to the schedule as below:

And the more advanced way is to use a Dynamic Event that executes your daily action.
In the model start code, call create_MyDynamicEvent(7, DAY) to make it trigger after the first 7 days of the sim.
Then in the Dynamic Event action code, add whatever should happen every day. And also add a line that re-creates the same Dynamic event in 1 day, like
create_MyDynamicEvent(1, DAY)
This would then trigger every day, even Sunday. To avoid that, you can add an if-clause in the dynamic event action code to only execute your code if it is not Sunday.

Related

change value of schedule during run time

I have a schedule that indicates the opening time of a service!
it's a schedule of intervals, so from 8:00 to 1:00 it's ON from 1:00 to 2:00 it's OFF, from 2:00 to 6:00 it's ON again and from 6:00 to 8:00 it's OFF.
Is it possible to change dynamically the opening times, so to vary these intervals through some parameters?
If there are only 2 or 3 alternative schedules then it is worth defining them explicitly as separate objects and using them this way.
Another option: Schedule objects have a concept of Exceptions - this is where it is possible to change the value (in this case ON instead of OFF) of the schedule for a particular period of time. These can be done via interface or programmatically using addException() method. Please see more here.
Furthermore, it is possible to create schedules programmatically. There is actually an example model in AnyLogic that shows how to do it. Please see "Schedule created programmatically" in your "AnyLogic => Help => Example Models => How to models".
Unfortunately, programmatically created schedules lack Action property, however this can be achieved by having an Event object with a conditional trigger which triggers when schedule.getValue() returns true.

UiPath Orchestrator Triggers - Cron Expression For specific day of month or next working day if not a working day

I've currently got this Cron expression that I'm using to trigger a process in UiPath Orchestrator:
0 0 15 21W * ? *
Runs on the closest working day to the 21st of each month at 3pm.
However I need it to run on the next working day at 3pm if the 21st is a non working day.
Tried searching for an answer and nothing quite fit the brief.
I used this website to build my expression (which is a great tool) but it only had an option for 'nearest day' and not next working day given a specific day of month: https://www.freeformatter.com/cron-expression-generator-quartz.html
As you don't need the nearest day, you can't use the functionality of Orchestrator cronjob. I would recommend creating a wrapper process as follows:
Create a new process, let's call it StartJobByCheckingDate
Now create a trigger that starts StartJobByCheckingDate each day at 3pm
So that process is now your manager of your desired process
Now we need to check if it is the 21th day
Here you have different ways to solve it
You could create a DataTable or even a file in the StartJobByCheckingDate process, that contains all the different days where your desired process should be fired (but this is very manual, you might not want to update this every year, so this might not be the smartest but the easiest solution)
The other idea is to check if the current day is the 21th day. If so check if it is Saturday/Sunday (non-working day).
If true: you could now create a empty dummy file somewhere that tracks that the 21th was a non-working day, and the next day you check that file existing, if it exists you check the current day to be a working day, and if so you delete the file again and start your desired process
If false: just start your desired process directly
I think 2. idea would be that best. Sure you have 365 jobs runs/year. But when you keep that helper process smart this will just be seconds.
Another idea instead of using the dummy file, would be to use Entities. Smarter but need some more time to get familiar with.
We have (had) the exact same issue. Since UiPath doesn't offer a feasible solution out of the box, we will work around the restriction using the following strategy: We trigger the actual job daily, considering a custom-built, static NonWorkingDay-list that will just suppress the execution of the robot every day we don't want it to run.
These steps are needed:
Get a list with of all known bank holidays, saturdays and sundays until 2053 or so...
Build a the static exclusion-list using a script that does something like this (pseudocode. I will update the answer once we have actually implemented the solution):
1. get all valid execution dates
loop through every 28th of the month until end of 2053
if the date is in the bankHolidayList then
loop until the next bankDay is found
add it to the list of valid ExecutionDates
else
add the date to the validExecutionDate-list
2. build exclusion-list
loop through every day until end of 2053
if the date is not in the validExecutionDate-list
add it to the exclusionDate-list
Format the csv accordingly and upload it to the orchestrator tenant as a NonWorkingDay-List
Update your trigger to run daily at your desired time, using the uploaded NonWorkDay-Calendar
While the accepted answer will surely work as well, we prefered to go with this approach because having a separate robot that does nothing but executing a UiPath trigger just doesn't seem right to me. With this approach we have no additional code that we potentially need to maintain.
In my oppinion not having a solution for this concern out of the box is a lack of feature that UiPath will (hopefully) fix until end of 2053 ;-)
Cheers
You can configure your trigger to launch oftener, then manage dates at init of your process, but you must set up a list of "holydays" or check in some way.
Also you can use the calendar option of orchestrator (+info)

Incorporating tide times into AnyLogic

What would be the best way to incorporate changing tide times into an AnyLogic model? I would like to use the times to effectively block and unblock a port. I have looked at the schedule option and the format (Start: Day1, Time) doesn't seem the best way to do it.
You can model the tide by a reoccuring timed trigger.
AnyLogic offers the Dynamic Event for this, an event that can reschedule itself.
Depending on how you have the time data for the tides (list of DateTimes, fixed periods, database), you can retrieve that value for each new rescheduling of the dynamic event.
I attached a screenshot of a simple sample model. Here I assume you have got a list with the interval in minutes between each port-affecting tide moment (Low Tide/Port Blocked - High Tide/Port Open - Low Tide/Port Blocked - and so on....) . The dynamic event then sets a boolean variable portBlocked, but depending on your needs you could also trigger a Statechart Transition, block flowchart modules, or trigger a function.
The Action code of the Dynamic Event:
portBlocked=!portBlocked;
create_MyDynamicEvent(tideIntervalsInMinutes.get(tideCounter),MINUTE);
tideCounter++;
Explanation of the code:
Trigger your needed actions (here simple boolean variable)
Reschedule the event for the next tide change
Update the tide counter (used to retrieve the corresponding tide interval time from the list)
In the startup code of the model you will have to trigger the Dynamic Event once initially, for this just use the same code as point 2 above.

Any Logic Step Method

I am building a dashboard for my System Dynamics model on Any Logic. I want to create a button that runs the model for 12 time units using getEngine().step() code. The method runs the model for only one time step of the simulation but I need 12 time units which is 1200 times the step. I was wondering if there any way to run the model for 12 time units and then pause it.
Also I want to start the model on a pause mode. I mean after clicking the Run button.
UPDATE: I found an answer to my second question. I created an event and set the following action to happen at time 12. getEngine().pause();
create an event (from the agent palette)
Make the event happen after 12 time units (seconds, minutes or whatever you have)
Add this code to the event:
pauseSimulation();

Google Script Run ClockTrigger Multiple Scripts

The situation I have is this:
a google form signup where people can sign up for notifications
a series of scripts that I would like to run nightly that looks through the form responses and emails people appropriately, Emailer()
an unsubscribe script that ideally runs frequently (every hour or so would be enough) as well as right before the notifications email is
sent. This looks through the inbox for emails and removes the
appropriate entries from the form responses, Unsubscriber()
I am having trouble coming up with a way to coordinate the way these two scripts will run. What I would like to happen is to have Unsubscriber() run every hour or so throughout the day. At midnight or some late night hour, I would like to run Emailer() once and have the Unsubscriber() function not be running at this time. Once Emailer() completes, I would like the Unsubscriber() function to resume running at its regular interval. I feel like this should be possible using a ClockTrigger, but I can't envision how to make it happen.
I am also wondering, if the Unsubscriber() function is scheduled to run every hour with a ClockTrigger, but takes longer than an hour on a certain instance, will the ClockTrigger start a second instance of the script?
Here is the documentation on how to create manually a time trigger, you can set the function to run every hour.
This trigger could be related to a main function in which you could evaluate the current time, if its in the range of midnight (e.g. 12am < current time > 1am) call the function Emailer(), for every other time of the day call Unsuscriber().
Hope this helps.