Reputation: 3
I want a decreasing function in AnyLogic software that starts from 100 and decreases with a slope of -0.2 in time plot. When it reaches 80, it should completely reach zero. After a few days, it should start again from 85 and then start decreasing with the slope.
i created a variable usestock_boundary3 which initial values is 100 and then i have function
usestock_boundary3 -= 0.2;
if (usestock_boundary3 <= 80) {
usestock_boundary3 = 0;
} else if (usestock_boundary3 <= 0) {
usestock_boundary3 = 90;
}
and event which call this function
Upvotes: -4
Views: 58
Reputation: 630
I would do this with a Dynamic Event, because it's easier to set the occurrence of the next event if it's varying. Let's call it MyDynamicEvent
, then you should use create_MyDynamicEvent(double _dt, TimeUnits _units)
. I don't fully understand your logic, but the body of the dynamic event (or the function body you're calling there) should look something like this:
usestock_boundary3 -= 0.2;
if (usestock_boundary3 <= 0) { //car needs repair
usestock_boundary3 = 85;
create_MyDynamicEvent(1, HOUR); //set the time when the car should start running again
}
else if (usestock_boundary3 <= 80) { //accident happens
usestock_boundary3 = 0;
create_MyDynamicEvent(3, DAY); //set the time of repair
}
else { //normal usage
create_MyDynamicEvent(2, HOUR); //set the normal event cycle time
}
And additionally to initialize the event, you need to call create_MyDynamicEvent(2, HOUR)
function at the On startup: section of the agent that has this Dynamic Event. This way you can control when the next event should occur based on the value of you variable usestock_boundary3
.
Upvotes: 0