Bob Matthews wrote:I am very unclear as to how to code the agents to 'wait' after they have sent their prospective trade until they have received all prospective trades from the remaining agents...
Bob Matthews wrote:4) entry and exit = start and stop (i.e. being part of the system or not)
5) decisions are only sent to active agents
3) one takes a collection of prospective trades and reduces this to a collection of optimized trades
1) they need to wait until they have received recommendations from all participating agents
2) the whole process is repeated every six hours
7) I would like some guidance into exactly what I need to code for all this to work smoothly
Bob Matthews wrote:Forget the six hours - replace that with periodically, the coding of which I already have working
i.e. when I require the agents to 'stir' and do something - they do it
Specifically, I don't like the idea of "waiting for all other agents", because there could be any number of reasons why they don't respond:
1. They're having tea.
2. They're playing footie.
3. Their system's crashed.
and, as I said, "everybody waiting on everybody else" is a recipe for deadlock.
Now, there are any number of ways to get around this:
1. Have a single, multi-Threaded "TradingPost" whose business is to receive prospective trades, generate a single Thread for each one, which waits a specified time and then generates an optimized trade for all agents who have responded within the time limit.
2. Do the same thing for each agent independently, but have the agent free to do anything else they like once they've spawned their "waiter" Thread.
I prefer the first, because it's likely to be more flexible, in that the Trading Post can be put on a proper server, and each agent work from a thin client like a smartphone; but it's certainly not required. And there are probably lots of other paradigms for this "share a Trade" idea too.
Bob Matthews wrote:yes - but as far as (3) goes each agent sends a 'subscribe' or 'unsubscribe' message when starting or stopping.
Bob Matthews wrote:As an alternative to my setup description, I have considered the following:-
Create a Master [TradingPost] program, whose only task is to receive a 'prospective' trade from each active agent and when all incoming messages have been received, calculate the reduced set of 'optimized' trades and send that information to all active agents.
Is this similar to your 1. suggestion ?
I think so, but your Master would have to be responsible for a LOT more than just dealing with "optimized" trades - at least in my way of looking at it.
It is the "glue" that keeps all agents talking to each other. It knows who is "logged on" and who isn't; it keeps track of potential quotes, who sent them, and when, and is responsible for sending them out to all other "active" agents; it also processes responses to them, acts as the timekeeper for how long they are "potential", and calculates "optimized" quotes based on responses when their 6 hours is up.
That's quite a bit more than your description.