Example #1
0
        public void DijkstraBus()
        {
            sockets    = new Socket[n];
            potentials = new int[n];
            dialers    = new Dialer[n, 2];
            receivers  = new Aio[n];
            senders    = new Aio[n];
            listeners  = new Listener[n];

            random = new Random(1);

            for (int i = 0; i < n; i++)
            {
                Protocols.Bus0(out sockets[i]);
                listeners[i]  = new Listener(sockets[i], "ipc:///Dijkstra" + i.ToString());
                potentials[i] = int.MaxValue;
            }

            // every node connects to two other random nodes
            for (int i = 0; i < n; i++)
            {
                int target = random.Next(n);
                dialers[i, 0] = new Dialer(sockets[i], "ipc:///Dijkstra" + target.ToString());
                target        = random.Next(n);
                dialers[i, 1] = new Dialer(sockets[i], "ipc:///Dijkstra" + target.ToString());
            }

            // arm the aios
            for (int i = 0; i < n; i++)
            {
                senders[i]   = new Aio(Whatever, i);
                receivers[i] = new Aio(Received, i);
                sockets[i].Receive(receivers[i]);
            }
            Msg msg = new Msg(0);

            msg.AppendU32(0);
            potentials[0] = 0;
            sockets[0].Send(msg);
            //msg.Dispose();
            int oldCount = 0;

            for (;;)
            {
                System.Threading.Thread.Sleep(100);
                if (countReceived > oldCount)
                {
                    oldCount = countReceived;
                }
                else
                {
                    break;
                }
            }
            for (int i = 0; i < n; i++)
            {
                sockets[i].Close();
            }
            return;
        }