Пример #1
0
        private void NetworkStats()
        {
            SensorNode tmp = this.headNode;
            int        totCycles = 0, totBitsXmitted = 0, totBitsReceived = 0;
            double     dissipatedPower = 0.0;

//			this.richTextBox1=true;
            this.richTextBox1.Text = "nodeNum;  Cycles;\t\tBits Transmitted;\tBits Received\n";
//			this.richTextBox1.Font.Bold=false;
            for (int i = 0; i < this.numNodes; i++)
            {
                int X, Y, Z;
                X = tmp.MESSAGECYCLES * this.simulationSpeed;
                if (i > 0)
                {
                    dissipatedPower = dissipatedPower + (0.5 - tmp.battery.BATTERYPOWER);
                }
                Y = tmp.TOTALBITSTRANSMITTED * this.simulationSpeed;
                Z = tmp.TOTALBITSRECEIVED * this.simulationSpeed;
                this.richTextBox1.Text += tmp.NODENUM + ";\t  " + X.ToString() + ";\t\t" + Y.ToString() + ";\t\t" + Z.ToString() + "\n";
                totCycles       += X;
                totBitsXmitted  += Y;
                totBitsReceived += Z;
                tmp              = tmp.Next;
            }
//			this.richTextBox1.Font.Bold=true;
            this.richTextBox1.Text += "Total Cycles;\tBits Transmitted;\tBits Received\n";
//			this.richTextBox1.Font.Bold=false;
            this.richTextBox1.Text += totCycles.ToString() + ";\t\t" + totBitsXmitted.ToString() + ";\t\t" + totBitsReceived + "\n";
            this.richTextBox1.Text += "total system energy dissipated = " + dissipatedPower.ToString() + " Joules\n";
        }
Пример #2
0
        private void button5_Click(object sender, System.EventArgs e)
        {
            SensorNode tmp = this.headNode;

            this.timer1.Stop();
            for (int i = 0; i < this.numNodes; i++)
            {
                this.richTextBox1.Text += tmp.NODENUM + ";" + tmp.NUM_CHILDREN + "\n";
                tmp = tmp.Next;
            }
        }
Пример #3
0
        public SensorNetwork(string str1, string str2, string str3)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.numNodes=int.Parse(str1);
            this.xmissionRange=float.Parse(str2);
            this.simulationSpeed=int.Parse(str3);
            rnd   = new Random();
            myPen = new Pen(Color.Blue);
            myLine=new Pen(Color.Gray);
            this.totMsgs=0;
            this.headNode=new SensorNode(true,this.xmissionRange,0, this.simulationSpeed);
            this.headRMsg=new ReceivedMessageList();
            this.temp=this.headNode;
            this.tmpRMsg=this.headRMsg;
            this.headMsg=new MessageList();//dummy node got to be present at all times.
            this.tailMsg=new MessageList();//-do-
            this.headMsg.NEXT=this.tailMsg;
            this.numbers=new bool[this.numNodes];
            this.timerFlag=false;
            this.stopperFlag2=false;
            for(int i=0;i<this.numNodes;i++)
            {
                this.tailNode=new SensorNode(false,this.xmissionRange,i+1,this.simulationSpeed);
                this.temp.Next=this.tailNode;
                this.temp=this.temp.Next;
                this.tailRMsg=new ReceivedMessageList();
                this.tmpRMsg.Next=this.tailRMsg;
                this.tmpRMsg=this.tmpRMsg.Next;
            }
        }
Пример #4
0
        public SensorNetwork(string str1, string str2, string str3)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.numNodes        = int.Parse(str1);
            this.xmissionRange   = float.Parse(str2);
            this.simulationSpeed = int.Parse(str3);
            rnd               = new Random();
            myPen             = new Pen(Color.Blue);
            myLine            = new Pen(Color.Gray);
            this.totMsgs      = 0;
            this.headNode     = new SensorNode(true, this.xmissionRange, 0, this.simulationSpeed);
            this.headRMsg     = new ReceivedMessageList();
            this.temp         = this.headNode;
            this.tmpRMsg      = this.headRMsg;
            this.headMsg      = new MessageList();     //dummy node got to be present at all times.
            this.tailMsg      = new MessageList();     //-do-
            this.headMsg.NEXT = this.tailMsg;
            this.numbers      = new bool[this.numNodes];
            this.timerFlag    = false;
            this.stopperFlag2 = false;
            for (int i = 0; i < this.numNodes; i++)
            {
                this.tailNode     = new SensorNode(false, this.xmissionRange, i + 1, this.simulationSpeed);
                this.temp.Next    = this.tailNode;
                this.temp         = this.temp.Next;
                this.tailRMsg     = new ReceivedMessageList();
                this.tmpRMsg.Next = this.tailRMsg;
                this.tmpRMsg      = this.tmpRMsg.Next;
            }
        }
Пример #5
0
        private void button6_Click(object sender, System.EventArgs e)
        {
            Graphics oGraphics;

            oGraphics    = Graphics.FromImage(DrawingArea);
            myPen.Color  = Color.Red;
            myLine.Color = Color.Gray;
            //	this.tailMsg=this.headMsg;
            this.temp = this.headNode;
            oGraphics.Clear(Color.AliceBlue);
            //		this.richTextBox1.Text+=totMsgs.ToString();
            //		this.richTextBox1.Text+="\n";
            for (int i = 0; i < this.numNodes; i++)
            {
                this.temp.PIXEL_NUMBER_X        = 0;
                this.temp.PIXEL_NUMBER_Y        = 0;
                this.temp.PARENT_PIXEL_NUMBER_X = 0;
                this.temp.PARENT_PIXEL_NUMBER_Y = 0;
                this.temp = this.temp.Next;
            }
            this.headNode.resetNodeAttributes(true);
            this.temp = this.headNode.Next;
            Random rnd = new Random();

            this.headNode.PIXEL_NUMBER_X = rnd.Next(this.interNodeDistance, this.panel1.Width - 2 * this.interNodeDistance);
            this.headNode.PIXEL_NUMBER_Y = rnd.Next(this.interNodeDistance, this.panel1.Height - 2 * this.interNodeDistance);
            this.headNode.MAC_X          = ((float)this.headNode.PIXEL_NUMBER_X * (this.xmissionRange / (float)this.interNodeDistance));
            this.headNode.MAC_Y          = ((float)this.headNode.PIXEL_NUMBER_Y * (this.xmissionRange / (float)this.interNodeDistance));
            oGraphics.DrawImage(this.headNode.IMG, this.headNode.PIXEL_NUMBER_X, this.headNode.PIXEL_NUMBER_Y, 7, 7);
            for (int i = 0; i < this.numNodes - 1; i++)
            {
                int        X1, Y1, X2, Y2, dist;
                bool       flag1 = true, flag2 = false;      //
                SensorNode tmp = this.headNode;
                X2 = rnd.Next(this.interNodeDistance, this.panel1.Width - 2 * this.interNodeDistance);
                Y2 = rnd.Next(this.interNodeDistance, this.panel1.Height - 2 * this.interNodeDistance);
                for (int j = 0; j < this.numNodes; j++)
                {
                    if (tmp.PIXEL_NUMBER_X != 0 && tmp.PIXEL_NUMBER_Y != 0)
                    {
                        X1   = tmp.PIXEL_NUMBER_X;
                        Y1   = tmp.PIXEL_NUMBER_Y;
                        dist = (int)Math.Sqrt((double)(((X1 - X2) * (X1 - X2)) + ((Y1 - Y2) * (Y1 - Y2))));
                        if (dist < this.interNodeDistance * 0.7)
                        {
                            flag1 = false;                          //means that the node is too close
                        }
                        if (dist < this.interNodeDistance * 0.9)
                        {
                            flag2 = true;                          //means that the node is within the range of atleast one other node
                        }
                    }
                    tmp = tmp.Next;
                }
                if (flag1 == true && flag2 == true)
                {
                    oGraphics.DrawImage(this.temp.IMG, X2, Y2, 7, 7);
                    this.temp.resetNodeAttributes(false);
                    this.temp.PIXEL_NUMBER_X = X2;
                    this.temp.PIXEL_NUMBER_Y = Y2;
                    this.temp.MAC_X          = ((float)this.temp.PIXEL_NUMBER_X * (this.xmissionRange / (float)this.interNodeDistance));
                    this.temp.MAC_Y          = ((float)this.temp.PIXEL_NUMBER_Y * (this.xmissionRange / (float)this.interNodeDistance));
                    this.temp = this.temp.Next;
                }
                else
                {
                    i--;                    //random number not appropriate so revert back
                }
            }
            oGraphics.Dispose();
            this.panel1.Invalidate();
        }
Пример #6
0
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            this.oGraphics = Graphics.FromImage(this.DrawingArea);
            this.temp      = this.headNode;
            this.oGraphics.Clear(Color.AliceBlue);
            bool stopperFlag = false;

            for (int i = 0; i < this.numNodes; i++)
            {
                this.temp.bitmapUPDater();
                oGraphics.DrawImage(this.temp.IMG, this.temp.PIXEL_NUMBER_X, this.temp.PIXEL_NUMBER_Y, 7, 7);
                if (this.temp.JOINSTATUS == true)
                {
                    oGraphics.DrawLine(myLine, this.temp.PIXEL_NUMBER_X, this.temp.PIXEL_NUMBER_Y, this.temp.PARENT_PIXEL_NUMBER_X, this.temp.PARENT_PIXEL_NUMBER_Y);                //ammend here
                }
                if (this.temp.BATTERY.BATTERYPOWER <= 0)
                {
                    this.NetworkStats();
                    stopperFlag = true;
                }
                this.temp = this.temp.Next;
            }
            if (stopperFlag == true && this.stopperFlag2 == false)
            {
                this.timer1.Stop();
                this.stopperFlag2 = true;
            }
            Random rnd = new Random();

            for (int j = 0; j < this.numNodes; j++)
            {
                this.numbers[j] = false;
            }
            for (int j = 0; j < this.numNodes; j++)
            {
                int num = 0;
                for (int k = 0; k < this.numNodes; k++)
                {
                    num = rnd.Next(0, this.numNodes);
                    if (this.numbers[num] == false)
                    {
                        this.numbers[num] = true;
                        break;
                    }
                    else
                    {
                        k--;
                    }
                }
                this.temp = this.headNode;
                for (int k = 0; k < num; k++)
                {
                    this.temp = this.temp.Next;
                }
                float Xsq, Ysq, distSq;
                int   msgCount = 1;
                this.flag           = false;    //false for no message received
                this.hiddenNodeFlag = false;    //true for no hidden node problem
                int delMsgs = 0;
                this.tmpMsg = this.headMsg.NEXT;
                String msg = null;
                for (int k = 0; k < this.totMsgs; k++)
                {
                    String [] msgListToks = this.tmpMsg.MESSAGE.Split(';');
                    Xsq = this.temp.MAC_X - float.Parse(msgListToks[0]);
                    Xsq = Xsq * Xsq;
                    Ysq = this.temp.MAC_Y - float.Parse(msgListToks[1]);
                    //			msgListToks=null;
                    Ysq    = Ysq * Ysq;
                    distSq = Xsq + Ysq;
                    if (this.tmpMsg.ITERATION >= this.numNodes)
                    {
                        MessageList MsgToBeRemoved = this.move_to_Message(msgCount);
                        this.move_to_Message(msgCount - 1).NEXT = this.move_to_Message(msgCount + 1);
                        this.temp1 = this.headNode;
                        for (int m = 0; m < this.numNodes; m++)
                        {
                            //			if(this.temp.MAC_X!=this.temp1.MAC_X || this.temp.MAC_Y!=this.temp1.MAC_Y)
                            //			{
                            Xsq = this.temp1.MAC_X - float.Parse(msgListToks[0]);
                            Xsq = Xsq * Xsq;
                            Ysq = this.temp1.MAC_Y - float.Parse(msgListToks[1]);
                            //	msgListToks=null;
                            Ysq    = Ysq * Ysq;
                            distSq = Xsq + Ysq;
                            if ((distSq <= this.xmissionRange * this.xmissionRange))
                            {
                                SensorNode tmp = this.headNode;
                                for (int n = 0; n < this.numNodes; n++)
                                {
                                    float x, y, hyp;
                                    x   = this.temp1.MAC_X - tmp.MAC_X;
                                    x   = x * x;
                                    y   = this.temp1.MAC_Y - tmp.MAC_Y;
                                    y   = y * y;
                                    hyp = x + y;
                                    if (hyp <= this.xmissionRange * this.xmissionRange)
                                    {
                                        if (tmp.ITERATION >= this.numNodes)
                                        {
                                            this.richTextBox1.Text      += "I come here\n";
                                            tmp.NEIGHBOURRECEIVEDXMITTED = false;
                                            tmp.ITERATION = 0;
                                        }
                                    }
                                    tmp = tmp.Next;
                                }
                                if (this.temp1.ITERATION >= this.numNodes)
                                {
                                    this.temp1.NEIGHBOURRECEIVEDXMITTED = false;
                                    this.temp1.ITERATION = 0;
                                }
                            }
                            this.temp1 = this.temp1.Next;
                        }
                        MsgToBeRemoved = null;
                        delMsgs++;
                        msgCount--;
                    }
                    //the value used for msg deletion
                    else if (distSq <= this.xmissionRange * this.xmissionRange)
                    {
                        this.temp.MessageReceiver(this.tmpMsg.MESSAGE);
                        this.temp1 = this.headNode;
                        for (int m = 0; m < this.numNodes; m++)
                        {
                            //			if((this.temp.MAC_X!=this.temp1.MAC_X || this.temp.MAC_Y!=this.temp1.MAC_Y) && (this.temp1.NEIGHBOURRECEIVEDXMITTED==true))
                            //			{
                            Xsq    = this.temp.MAC_X - this.temp1.MAC_X;
                            Xsq    = Xsq * Xsq;
                            Ysq    = this.temp.MAC_Y - this.temp1.MAC_Y;
                            Ysq    = Ysq * Ysq;
                            distSq = Xsq + Ysq;
                            if ((distSq <= this.xmissionRange * this.xmissionRange))
                            {
                                this.temp1.NEIGHBOURRECEIVEDXMITTED = true;                                      //a neighbour has received a message
                                this.temp1.ITERATION = 0;
                                //								this.richTextBox1.Text+="haan jee\n";
                            }
                            //			}
                            this.temp1 = this.temp1.Next;
                        }
                        flag = true;                      //the node received a message
                    }
                    msgCount++;
                    this.tmpMsg = this.tmpMsg.NEXT;
                }
                this.tmpMsg            = this.headMsg.NEXT;
                this.tailMsg.ITERATION = 0;
                while (this.tmpMsg.NEXT != null)
                {
                    this.tmpMsg.ITERATION++;
                    this.tmpMsg = this.tmpMsg.NEXT;
                }
                this.tailMsg.ITERATION = 0;
                this.temp1             = this.headNode;
                for (int i = 0; i < this.numNodes; i++)
                {
                    if (this.temp1.NEIGHBOURRECEIVEDXMITTED == true)
                    {
                        this.temp1.ITERATION++;
                    }
                    if (this.temp1.ITERATION >= this.numNodes)
                    {
                        this.temp1.ITERATION = 0;
                        this.temp1.NEIGHBOURRECEIVEDXMITTED = false;
                    }
                    this.temp1 = this.temp1.Next;
                }
                //if else with a flag
                if (flag == false)
                {
                    bool xmitterFlag = false;
                    this.temp1 = this.headNode;
                    for (int m = 0; m < this.numNodes; m++)
                    {
                        if ((this.temp1.NEIGHBOURRECEIVEDXMITTED == true))
                        {
                            Xsq    = this.temp.MAC_X - this.temp1.MAC_X;
                            Xsq    = Xsq * Xsq;
                            Ysq    = this.temp.MAC_Y - this.temp1.MAC_Y;
                            Ysq    = Ysq * Ysq;
                            distSq = Xsq + Ysq;

                            if ((distSq <= this.xmissionRange * this.xmissionRange))
                            {
                                xmitterFlag = true;                              //a neighbour has received a message
//								this.richTextBox1.Text+="haan jee\n";
                            }
                        }
                        this.temp1 = this.temp1.Next;
                    }
                    if (xmitterFlag == false)
                    {
                        String str;
                        if ((str = this.temp.MessageTransmitter()) != null)
                        {
                            String [] toks = str.Split(';');
                            if (int.Parse(toks[4]) == 1)
                            {
                                myPen.Color = Color.Red;
                            }
                            else if (int.Parse(toks[4]) == 2)
                            {
                                myPen.Color = Color.Green;
                            }
                            else if (int.Parse(toks[4]) == 3)
                            {
                                myPen.Color = Color.Blue;
                            }
                            else
                            {
                                myPen.Color = Color.Purple;
                            }
                            MessageList NewMsg = new MessageList();
                            NewMsg.MESSAGE    = str;
                            NewMsg.NEXT       = this.headMsg.NEXT;
                            this.headMsg.NEXT = NewMsg;
                            this.totMsgs++;
                            oGraphics.DrawEllipse(myPen, this.temp.PIXEL_NUMBER_X - this.interNodeDistance, this.temp.PIXEL_NUMBER_Y - this.interNodeDistance, this.interNodeDistance * 2, this.interNodeDistance * 2);
                            this.temp1 = this.headNode;
                            for (int m = 0; m < this.numNodes; m++)
                            {
                                if ((this.temp.MAC_X != this.temp1.MAC_X || this.temp.MAC_Y != this.temp1.MAC_Y))
                                {
                                    Xsq    = this.temp.MAC_X - this.temp1.MAC_X;
                                    Xsq    = Xsq * Xsq;
                                    Ysq    = this.temp.MAC_Y - this.temp1.MAC_Y;
                                    Ysq    = Ysq * Ysq;
                                    distSq = Xsq + Ysq;
                                    if ((distSq <= this.xmissionRange * this.xmissionRange))
                                    {
                                        this.temp1.NEIGHBOURRECEIVEDXMITTED = true;
                                        this.temp1.ITERATION = 0;
                                    }
                                }
                                this.temp1 = this.temp1.Next;
                            }
                        }
                    }
                }
                this.totMsgs = this.totMsgs - delMsgs;
            }
            rnd = null;
            oGraphics.Dispose();
            this.panel1.Invalidate();
        }