Frequency of events

Started by
5 comments, last by Xai 16 years, 10 months ago
Hi all, I'm attempting to design an AI system which takes basic needs, and plots their degree of severity based on time. For example, if a given creature has needs... - Food (three 20 minute blocks per 24 hour interval, only during waking hours) - Sleep (one 8 hour block per 24 hour interval) ...and I want to be able to determine, based on given time T, what the creature is likely to be doing at any given time of day based on those needs, how do I represent this in a mathematical formula? I suspect if the above were graphed out, the graph would display two sin waves, however I'm not sure how to go about plotting them.
Advertisement
If you just want to figure out what a creature is likely to be doing, why not design a little logic to how their daily schedule may be laid out?

Say a creature is likely to wake up between 4 and 6 AM; randomly generate that time.
A creature is likely to go to sleep between 9 and 11 PM; randomly generate that time.
Say it starts hunting for food between 0 and 3 hours after it wakes up, and that takes 0 to 1 hour to pull off. Then it repeats every 3-6 hours after every meal until the time it sleeps.

So you set its waking hours, and then build its behavior up until T.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
Sine waves sound a little bit unrealistic for an earthly being.

I'm not sure if this is what you mean, but a measure of an animal's 'desire' to eat or sleep is less smooth.

I would model hunger to increase by a constant amount per unit time spent not eating, and decrease by a constant amount per unit time spent eating. Obviously, the second constant would be far larger than the first. Assuming that the animal seeks food whenever its hunger passes above some critical value, the curve would look like a sawtooth wave.

Similarly, tiredness will increase with wakefulness and decrease with sleep. The increase would again be linear, but I'd take the sleep time to act as an exponential decay on tiredness - so that three hours' sleep is worth far more than half of six hours'. The resulting tiredness curve would then look a little bit like a skewed triangle wave.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Thanks for your replies.

Unfortunately I don't think that static scheduling will solve what I'm attempting.

In my game, when players are not nearby NPCs, they go to sleep, and are not processed. When a player enters an NPC's proximity, that NPC 'wakes up', and based on the time of day and his daily schedules, I need to be able to determine, using a time-based mathematical formula, what the NPC is 'most likely' to be doing at a given time.

(Based on that, I can determine where, in the NPC's travel route between locations, how far between points A and B he will be.)

I only gave two examples of routine-based needs, however I have others, based both on time of day, and time in the NPC's lifespan, which determines its wants, goals, and desires. So when a 'wake up' event occurs, I need to be able to calculate and sort all of an NPC's needs, then make a decision based on the needs' importance... hence my original posting.
I'm not sure if I entirely understand. In particular, is the system meant to be deterministic and clockwork-like, or a little fuzzy and unpredictable? If the latter, here's my thinking:

Given the problem you describe (and the new information), when an agent comes into play, I'd first create a list of its possible activities at the time, sum up the total time quotas for each, then pick a random activity according to those weights. An example:

Amanda leads a boring (and unhygienic) life. She does the following things of a day:

Sleep for a total of eight hours somewhere between 10pm and 10am.
Eat for two hours between 10am and 10pm.
Work for six hours between 10am and 6pm.
Housework for 1 hour between 7pm and 10pm.

Provided we all tasks are independent, with no nasty inclusivity/exclusivity rules (like not eating on the job) we can easily find out what she's likely to be doing at any given time.
Suppose the player brings her into scope at 4pm. We first decide what she may be doing at that time - either working or eating. We sum up the amount of time she spends doing these things (2 + 6 + 8 hours) and decide which it is right now by dividing the times by the total, to form random weights. In this case, she'll have a 6/8 chance of being at work, and a 2/8 of eating.

Am I anywhere close?

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Here's a rather strange idea that occurred to me (read: it's a hasty thought, so it may be rather far off the mark!). So, the problem is given an NPC N and a time T we need to determine the current action of the NPC. This problem may be further complicated by the fact that, if a player leaves the "NPC processing radius" and immediately returns the NPC should return to their previous state (eliminating the class of cases where it appears the NPC went hunting for something absurd like 30 seconds).

Right, so here's my suggestion. Seed a random number generator with the unique NPC id + the current day and "randomly" generate a schedule from this RNG. This scheme ensures not only that every NPC is assigned a unique schedule for each day but also that the schedule remains consistent over the day.

(Random musings: If your NPCs run on a schedule system it then becomes easy to script special schedules for special NPCs. With a fixed daily schedule you can reflect it in the game world e.g., via a journal or day planner. With a fixed schedule you also need to save less game state because you can easily rebuild the schedule at load time.)
I like a tweak of errcw's idea. DO define categories of people or sets of activity probabilites in terms of a number (or genetic code basically), DO give each NPC another number that makes them behave uniquely within their respective groupings ... and DO come up with the ability to create a schedule programatically based on their code, their unique number, and perhaps 1 more input (current day or something).

Then you don't actually create the scheudles and store them, just have function which deterministically yield output (seeded random number generator I'm sure) from those main inputs.

the at any time you can get to exactly what the NPC would be doing - baring other special choices made (which would only happen while in the area of a non-NPC).

as for the original question, it should be fairly easy, and I don't quite think its a sine curve of probability, because the real actions are more like an asmptotically increasing function that drops to zero upon completion.

IE, when real people finish a meal, their likelyness of eating is reset to 0, then it rises until they do eat. In such a way that over time it averages out to being done 3 times a day (I don't know the math formula to figure out the possible probability curves which would do this. Personally I feel it is some form of logistics style curve, where it is fairly flat early, with an exponential bend and then straitens out, then curves back to the right near end (IE the 100% asmptote limit).

That of course it just the plot if you KNOW when they have eaten, until the next meal. Since the first meal might have been had at ANY time, the probability for the second meal at any given time is going to be the sum (or average I guess) of the probabilies for the second meal given each possible first meal time. This has some definite calculous in its core ideas (summing numbers over smaller and smaller granularity slices, until you reach infinite precision).

perhaps you would use a sine wave that starts ancored at a time where you can say it definately would not or definately would be happend (IE, sleeping might be a since wave that peaks at 3 am or somethine, cycling once per day. eating minimizes at 3 am (while sleaping is a max) at cycles 3 times daily, etc).

good luck

This topic is closed to new replies.

Advertisement