Example #1
0
 public void HandleNode(Node current, Node origin, Message message, Network network)
 {
     foreach (Node neighbor in current.neighbors)
     {
         network.Enqueue(message, current, neighbor);
     }
 }
Example #2
0
 public void OnMessage(Node origin, Message message, Network network)
 {
     ++messagesReceived;
     if (messagesReceived == 1)
     {
         rcvTime = network.time;
         this.message = message;
         network.routingAlgorithm.HandleNode(this, origin, message, network);
     }
 }
Example #3
0
        public void HandleNode(Node current, Node origin, Message message, Network network)
        {
            if (message.hops >= k && random.NextDouble() > p)
            {
                return;
            }

            foreach (Node neighbor in current.neighbors)
            {
                network.Enqueue(message, current, neighbor);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            #if false
            int k = 4;
            Network n = new Network();

            for (int i = 0; i < 100; ++i)
            {
                float p = (float)i / 100;
                n.routingAlgorithm = new Gossip1(p, k);
                float ratio, msgRatio;
                Test(n, 7500, 3000, 250, 1000, 5, out ratio, out msgRatio);
                System.Console.WriteLine("p = " + p + ", div = " + (ratio - msgRatio));
            }
            #else
            new GraphForm().ShowDialog();
            #endif
        }
Example #5
0
        public static void Test(Network n, int width, int height,
            int distance, int nodeCount, int runs, out float ratio, out float msgRatio)
        {
            ratio = 0;
            msgRatio = 0;

            for (int i = 0; i < runs; ++i)
            {
                n.CreateNetwork(width, height, distance, nodeCount);
                n.nodes[0].StartMessage(n);
                while (n.Step()) ;
                ratio += n.receivedRatio;
                msgRatio += n.messageCount;
            }

            ratio = ratio / runs;
            msgRatio = msgRatio / (runs * n.maxMessageCount);
        }
Example #6
0
 public void OnTimeStep(Network network)
 {
 }
Example #7
0
 public void OnTimeStep(Network network)
 {
     foreach (Node node in network.nodes)
     {
         if (node.broadcasted == false && node.messagesReceived <= m &&
             node.messagesReceived > 0 && node.rcvTime + timeout < network.time)
         {
             node.broadcasted = true;
             foreach (Node neighbor in node.neighbors)
             {
                 network.Enqueue(node.message, node, neighbor);
             }
         }
     }
 }
Example #8
0
 public void StartMessage(Network network)
 {
     Message m = new Message();
     network.routingAlgorithm.HandleNode(this, null, m, network);
 }
Example #9
0
        void RunSimulation(bool displayUsage, bool runGossip1, bool runGossip2, bool runGossip3)
        {
            gossip1Button.Enabled = false;

            chart1.Series.Clear();
            int g1Line = -1;
            int usage1Line = -1;
            int g2Line = -1;
            int usage2Line = -1;
            int g3Line = -1;
            int usage3Line = -1;

            if (runGossip1)
            {
                chart1.Series.Add("Gossip1 reach");
                g1Line = chart1.Series.Count - 1;
                chart1.Series[g1Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

                if (displayUsage)
                {
                    chart1.Series.Add("Gossip1 usage");
                    usage1Line = chart1.Series.Count - 1;
                    chart1.Series[usage1Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
                }
            }

            if (runGossip2)
            {
                chart1.Series.Add("Gossip2 reach");
                g2Line = chart1.Series.Count - 1;
                chart1.Series[g2Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

                if (displayUsage)
                {
                    chart1.Series.Add("Gossip2 usage");
                    usage2Line = chart1.Series.Count - 1;
                    chart1.Series[usage2Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
                }
            }

            if (runGossip3)
            {
                chart1.Series.Add("Gossip3 reach");
                g3Line = chart1.Series.Count - 1;
                chart1.Series[g3Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;

                if (displayUsage)
                {
                    chart1.Series.Add("Gossip3 usage");
                    usage3Line = chart1.Series.Count - 1;
                    chart1.Series[usage3Line].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
                }
            }

            int simCount = (int)simulations.Value;

            BackgroundWorker bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork += new DoWorkEventHandler(
            delegate(object o, DoWorkEventArgs args)
            {
                Network n = new Network();

                int w = (int)width.Value;
                int h = (int)height.Value;
                int nodes = (int)nodeCount.Value;
                int nodeDistance = (int)nodeDist.Value;

                for (int i = 0; i <= 100; i += 2)
                {
                    float p = (float)i / 100;
                    float ratio, msgRatio;

                    if (runGossip1)
                    {
                        gossipMode = 0;
                        SetupRoutingAlgorithm(n, p);
                        Program.Test(n, w, h, nodeDistance, nodes, simCount, out ratio, out msgRatio);
                        chart1.Series[g1Line].Points.AddXY(p, ratio);
                        if (displayUsage)
                        {
                            chart1.Series[usage1Line].Points.AddXY(p, msgRatio);
                        }
                    }

                    if (runGossip2)
                    {
                        gossipMode = 1;
                        SetupRoutingAlgorithm(n, p);
                        Program.Test(n, w, h, nodeDistance, nodes, simCount, out ratio, out msgRatio);
                        chart1.Series[g2Line].Points.AddXY(p, ratio);
                        if (displayUsage)
                        {
                            chart1.Series[usage2Line].Points.AddXY(p, msgRatio);
                        }
                    }

                    if (runGossip3)
                    {
                        gossipMode = 2;
                        SetupRoutingAlgorithm(n, p);
                        Program.Test(n, w, h, nodeDistance, nodes, simCount, out ratio, out msgRatio);
                        chart1.Series[g3Line].Points.AddXY(p, ratio);
                        if (displayUsage)
                        {
                            chart1.Series[usage3Line].Points.AddXY(p, msgRatio);
                        }
                    }
                }

                gossip1Button.Enabled = true;
            });
            bw.RunWorkerAsync();
        }
Example #10
0
        void SetupRoutingAlgorithm(Network network, float p)
        {
            int k = (int)this.k.Value;
            int n = (int)this.n.Value;
            float p2 = (float)this.p2.Value;
            int m = (int)this.m.Value;
            int timeout = (int)this.timeout.Value;

            if (gossipMode == 0)
            {
                network.routingAlgorithm = new Gossip1(p, k);
            }
            else if (gossipMode == 1)
            {
                network.routingAlgorithm = new Gossip2(p, k, p2, n);
            }
            else if (gossipMode == 2)
            {
                network.routingAlgorithm = new Gossip3(p, k, m, timeout);
            }
        }