AnyLogic: Change parameter at certain times with events - simulation

I want to change the parameter parSize at certain times. For example, the parameter parSize should be equal to 50 at XX:XX o'clock and equal to 30 at YY:YY o'clock. This change of the parameter is repeated every day at the same time.
The time when the parameter should be changed can be entered manually by the end user before the simulation starts. The parameters for each time are stored separated by hour and minutes as int.
My approach is to trigger a cyclic event for each parameter change, which repeats every day at time XX:XX, YY:YY, etc.
Is there a better way to change parameters at a certain time of the day (repeated everyday)?
How can I trigger an event with my input int parameters (one for hour, one for minutes) of the time? So that occurrence date not set manually in the selection window, but by code and my end user input parameters?

Use a DynamicEvent object named MyDynamicEvent instead.
Give it 2 arguments of type double:
minsToDailyChange (in mins since midnight).
newValue
For each of the 7 changes per day, call create_MyDynamicEvent(0, SECOND, minsFromMidnightForThisChange, newValue) on the start of the model
In the action code, write:
set_parSize(newValue);
create_MyDynamicEvent(24, HOUR, minsFromMidnightForThisChange, newValue)
Now, you have 7 parallel DEs that manage themselves and will change the value every 24 hrs to the new value required.

Related

How to count no of agents who have spent X days in the system in Anylogic

I am building invoice processing simulation model. invoice creation date is the source generation date . Every Invoice will have due date which varies. 31 days, 60 days, 90 days.
Any agent generated at resource I can add these days to the source generation date and get due date. Next step is at point I should know how many invoices are past due date .
e.g 10 invoices are between 1- 5 days, 15 invoices are between 6 to 20 days etc. I have created three variable in the agent population. Start time, end time and Due time
double DueTime= (time()-dateToTime (due_date));
This is calculating DueTime correctly.
Then in the main I am trying to compute the count of agent
int x_1_5= count( invoices, p -> p.DueTime >1 && p.DueTime<=5 );
age_1_5=String.valueOf(x_1_5);
This is giving me 0 as output.
Is there a way to do do this ?
You are only calculating your DueDate variable once at the start of the agent creation.
You need to turn it into a function getDueTime() that returns the double value when called. Just paste return (time()-dateToTime (due_date)); into the function and then in your counter call
int x_1_5= count( invoices, p -> p.getDueTime() >1 && p.getDueTime()<=5 );
Variables do not act like functions and vice versa.
Tried this approach. Created function in Invoice agent and then calling it on the main inside another function. But it is throwing error .

date parameter updated with time Anylogic

I'm using Anylogic and I would like to assign a parameter of type date to each agent (agent is a customer), called DueDate, that represents deadline to his machine failure. My goal is to update value parameter and make it shorter as model time passes (because the failure date is coming). There is some function or code that I can use? I also want to assign a priority parameter to agent that increases when failure date is nearest, so that in queue a customer with a failure nearest is processed before agents with lower priority. How can I do?
Thanks at all
This question seems to contradict itself somewhat. The parameter described is a Due Date, therefore, by definition, should be fixed. Yet, parameter value should be updated as failure date is coming. Do you mean that there should be two parameters: 1) Due Date and 2) remaining time until Due Date? If so this can be achieve like this:
Due Date - if you want to set due date at 10 time units after model start, you can make a parameter (call it p_dueDate of type ) and use timeToDate(100.0) function (help entry).
Remaining time - create a function in the agent f_getRemainingTime() with this code:
return dateToTime(p_dueDate) - time();
where dateToTime() will convert the p_dueDate value back into a double value representing simulation's time units and time() returns current simulation time (also as a double value).
so, let's say for a model starting on 1st Jan with time units = days; offset of 10 will result in p_dueDate = 10th Jan and on 3rd of Jan f_getRemainingTime() will return 7.0.

want to reset values after some time using scheduler or db event

I have a jsp like:
rule 1 : value
rule 2 : value
Time interval in min :value
I am saving these values to DB
depending on the value of time interval field I want to reset the value of rule 1 and rule 2 to a default value in DB
This time interval can be changed any time even before previous interval is not completed,means it needs to be updated dynamically whatever approach I choose
I am using Sprig MVC and oracle
I opted for
ThreadPoolTaskScheduler
but now problem is as soon as I used
threadPoolTaskScheduler.schedule(runnableObj,trigger);
it is getting executed immediately and then executes on proper interval of 1 min but I want to skip first execution for that I have used PeriodicTrigger
which has method named setInitialDelay() but it is not delaying it
Please provide some insight for this kind of problems as I am doing it first time
I think I solved it using ThreadPoolTaskScheduler
For more info visit http://www.baeldung.com/spring-task-scheduler
Some interesting Spring Scheduling information.

Counting the number of times a specific hour appears in a column after extraction in postgresql

after using the extract function to extract an hour value from a timestamp in postgresql, how can I count the number of times each value appears? I'm trying to produce the number of calls coming into a helpdesk based on time of day. So I need to be able to count the number that came in at 2pm, 3pm, 4pm and so on. Thanks for any help.

How to determine if a user has entered only date or also time in the form field?

I have a field where user can enter only date or also time in a text field. Now I know if I make 2 fields, one for date and one for time, I can check if the time field is empty or not.
What I'd like to do is have only one field. If user puts the ending date it takes time only, if user inputs date and time it takes both.
The problem I have is this: If user enters "8.12.2013" it in fact means "8.12.2013 0:0:0" where I convert it to Cdate. But then the end time is the first second of the date 8.12.2013 which means it 8.12.2013 means stop on that date (this is a stop time field). But in fact if a user writes 8.1.2013 it means roll till the end of the day.
Of course I can do date()>"8.12.2013" and it will work, but then if user enters date and time it will not work as it strips time part.
My question: Is there any function in ASP that would check if the time part of the date is set in a variable? I tried to use TIME but it shows 0 for hours, 0 for minutes and 0 for seconds even if the Cdate("8.12.2013") is used. I'd need the function to tell me that the time is not set so I could make a comparation using date() instead of now().
I hope that makes sense.
You could try something as simple as:
If CLng(myDate) = myDate Then ...
Dates are treated as time past a particular date etc., therefore integerising the date will remove the time.
-- EDIT --
Just to add to the above code: The CLng will convert a Date and Time into just a Date. By comparing this against the whole date you can see if any fractional part was included.
Please be aware that this would be considered bad practice in a strictly typed environment, such as .NET, but Classic ASP types are variants and are quite malleable.