How to count no of agents who have spent X days in the system in Anylogic - 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 .

Related

AnyLogic: Change parameter at certain times with events

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.

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.

Calculate sum overlapping minutes in tableau

I have two excel extracts, one containing the schedules of employees and the other containing the actual times the employees worked. There are multiple schedule blocks in a day and employees can have multiple activity start and stop times in or out of scheduled time.
Schedule:
Actvtivity:
I need to use this data to calculate the sum of actual minutes worked only during the scheduled time with Tableau. In the above images the first schedule event would have 115 minutes worked and the second line would have 92 totaling in 207.
I tried to start easy by only calculating activity entries that fall within both the start and stop of a scheduled block, but tableau either return nothing or the "Many to 1" *
attempt 1:
case attr([#Fields:Date]) when ATTR([ScheduleStopStart].[#fields:excDate])
then
if attr([Start]) >= Min([ScheduleStopStart].[Start])
and attr([Stop]) <= max([ScheduleStopStart].[Stop])
then datediff("minute", attr([Start]), attr([Stop]))
END
END
Attempt 2:
IF ATTR([#Fields:Date]) = ATTR([ScheduleStopStart].[#fields:excDate]) then (
if attr([Start]) >= attr([ScheduleStopStart].[Start])
and attr([Stop]) <= attr([ScheduleStopStart].[Stop])
then DATEDIFF("minute", attr([Start]),attr([Stop]))
else 0
end
)
else
0
END

How do I Loop through a schedule in Crystal Reports

I'm building a report in Crystal Reports 2008. The report is dealing with employee's schedules. There are time slots where the schedule is open, and time slots where the schedule is unavailable.
Currently, I've built my logic so that it finds the start and end of an unavailable time. The report them tells me how many hours that particular staff person was unavailable.
My issue is that sometimes, staff people have a block at the beginning of their schedule marked as 'unavailable', and a block at the end of the day as 'unavailable', but between the two they are 'open'. Thus, the report says that particular staff person was out the whole day, but they actually worked. It isn't an option to tell these particular staff people how to schedule their day - they decide their own schedule, and I write the report to accomodate their needs.
SCHEDULE_TIME EMP_ID UNAVAILABLE_CODE WORK_LENGTH
7/5/2011 11:00 100 NULL 15
7/5/2011 11:15 100 NULL 15
7/5/2011 11:30 100 NULL 15
7/5/2011 11:45 100 NULL 15
7/5/2011 12:00 100 15 5
7/5/2011 17:00 100 15 5
This example shows how somebody would have a 5 hour block calculated for unavailable time, but it's only 2 appointments. For the code, I'm using DATEDIFF between appointment times.
(Essentially, they have built in more than one 'unavailable' block, and my logic will only accomodate one 'unavailable' block per day).
I'm pretty sure that I need to run a type of DO...WHILE loop within the report in order to calculate the total hours unavailable. I'm just not sure how to structure the loop in Crystal Reports.
Maybe i'm missing something but what you want to do looks straight forward. Two obvious options:
Running total:
Set the field to {TABLE.WORK_LENGTH}
Set the type to sum
Set the evaluation formula to not(isnull({TABLE.UNAVAILABLE_CODE}))
Set the reset on change of group/field {TABLE.EMP_ID} (assuming you're looking for totals per employee)
Formula/sum:
Create a formula field unavailable_time with if not(isnull({TABLE.UNAVAILABLE_CODE})) then {TABLE.WORK_LENGTH} else 0
Create a group on {TABLE.EMP_ID}
Create a sum on your formula field in the group footer

How can I schedule bi-weekly jobs?

My app requires users to schedule recurring events that can recur daily, weekly, monthly, or bi-weekly.
By bi-weekly, I mean every fortnight (14 days) starting from an arbitrary date value provided at the time of creation.
My jobs table has two columns to support this: job_frequency_id and job_frequency_value. I'm able to schedule all types except for bi-weekly.
The first col is an FK to the job_frequencies table; it contains daily, weekly, monthy, bi-weekly values. The job_frequency_value contains the value corresponding to the frequency.
For example: If a job has a job_frquency_id == 3 and job_frequency_value == 10, it will run every 10th day of the month.
How do I add bi-weekly support without tampering with my db structure? I will use the job_frequency_value col to store the start date of the 14 day period, but I'm unsure of the calculation going forward.
Say your starting date is stored as a variable named 'createdDate'.
nextFortnight = DateAdd("ww", job_frequency_value*2, createdDate);
can you wrap your scheduled task in a and set it to run every week?
Something like
<cfif DateDiff('ww',CreateDate(2011,01,01),Today'sDate) MOD 2 EQ 1>
That way if the weeks are odd your scheduled task runs completely and if it's an odd week then it runs the scheduled task, but ignore all your code.