public void GenerateEvent(double time, ILocation location)
        {
            // Overloads GenerateEvent to allow the simulation to provide the time the event occurs.
            XYDoubleLocation initalCorner = (XYDoubleLocation)field[0];  // Casting to xyLocation objects. Other
            XYDoubleLocation finalCorner = (XYDoubleLocation)field[1];     // coordinate systems are not supported.

            List<PEQNode> nodesInRange = new List<PEQNode>();

            // Generate the random center location of the event.
            eventCenter = (XYDoubleLocation)location;

            eventCenter.SetField(field);

            Notify(generateStaticReport(time, eventCenter));

            foreach (PEQNode node in nodes.NodeQueue)
            { // Find which nodes are within the effective detection area.
                if (eventCenter.Distance(node.Location) <= eventSize) // if in the event area
                    nodesInRange.Add(node);
            }

            double eventTime = 0;
            for (int i = 0; i < this.numOccurances; i++)
            {
                eventTime = time + i / this.eventFreq;

                foreach (PEQNode node in nodesInRange)
                {
                    PEQMessageApplication appMsg = new PEQMessageApplication(); // Create a new app message
                    appMsg._Data._DataID = _dataID++;
                    MessageEvent msgEvent = new MessageEvent(appMsg); // create a new message event
                    msgEvent.Referrer = node; // set the referrer to the current node

                    PEQDataInfoReport rep = new PEQDataInfoReport(node.ID, eventTime);
                    rep._Sent = 1;
                    rep._DataID = appMsg._Data._DataID;
                    Notify(rep);

                    PEQTimerInternal messageTimer = new PEQTimerInternal(appMsg, eventTime, node);
                    eventMgr.AddEvent(messageTimer);   // add the event to the Event Queue.
                }
            }

            SimulationCompleteEvent simCompleteEvent = new SimulationCompleteEvent(nodes);
            simCompleteEvent.Time = eventTime + 60; // one minute after last event occurs
            eventMgr.AddEvent(simCompleteEvent);
        }
        public void GenerateEvent(double time, ILocation location)
        {
            // Overloads GenerateEvent to allow the simulation to provide the time the event occurs.
            XYDoubleLocation initalCorner = (XYDoubleLocation)field[0];  // Casting to xyLocation objects. Other
            XYDoubleLocation finalCorner = (XYDoubleLocation)field[1];     // coordinate systems are not supported.

            // Generate the random center location of the event.
            eventCenter = (XYDoubleLocation)location;

            eventCenter.SetField(field);

            Notify(generateStaticReport(time, eventCenter));

            foreach (FloodingQueryNode node in nodes.NodeQueue)
            { // Find which nodes are within the effective detection area.
                if (eventCenter.Distance(node.Location) <= eventSize) // if in the event area
                {
                    FloodingQueryApplicationMessage appMsg = new FloodingQueryApplicationMessage(); // Create a new app message
                    MessageEvent msgEvent = new MessageEvent(appMsg); // create a new message event
                    msgEvent.Referrer = node; // set the referrer to the current node

                    NodeTimerEvent timerEvent = new NodeTimerEvent();   // create a timer event
                    timerEvent.Time = time;
                    timerEvent.Event = msgEvent;                        // apply the message event
                    timerEvent.node = node;
                    eventMgr.AddEvent(timerEvent);                      // add the event to the Event Queue.
                }
            }
        }
        public void Deploy()
        {
            if (!isInitialized)
                throw new InvalidOperationException("RandomDeployer not initialized!");

            XYDoubleLocation center, current;
            center = new XYDoubleLocation((field[0].X + field[1].X) / 2, (field[0].Y + field[1].Y) / 2);

            List<XYDoubleLocation> pointList = new List<XYDoubleLocation>();

            //rand = randFactory.CreateRandomizer();

            bool continueFlag = true;

            int i = 0;
            double s = 2 * Math.PI * b;  // For l=pi*s*n^2
            double n, theta, l, r, x, y;
            while (continueFlag)
            {
                l = i * nodeDistance;
                n = Math.Sqrt(l / (Math.PI * s));
                theta = 2 * Math.PI * n;

                r = a + b * theta;
                x = r * Math.Cos(theta) + center.X;
                y = r * Math.Sin(theta) + center.Y;

                current = new XYDoubleLocation(x, y);
                current.SetField(field);

                if (current.InField())
                    nodes.AddNode(nodeFactory.CreateNode(current));
                else
                    continueFlag = false;
                i++;
            }
        }
        public LineReport(double time, XYDoubleLocation nearLoc, XYDoubleLocation farLoc,
            double distance, double length)
        {
            // Closure must still be checked before creating the LineReport!
            double k1 = distance - length;
            double k2 = distance;
            double dx = farLoc.X - nearLoc.X;
            double dy = farLoc.Y - nearLoc.Y;

            double theta = Math.Atan2(dy, dx);

            double inner = k1 * Math.Cos(theta);
            double innerX = nearLoc.X;
            double innerY;
            double outer = k2 * Math.Cos(theta);
            double outerX = farLoc.X;
            double outerY;

            if (!double.IsInfinity(dy / dx))
            {
                double m = dy / dx;
                innerX = inner + nearLoc.X;
                innerY = m * inner + nearLoc.Y;
                outerX = outer + nearLoc.X;
                outerY = m * outer + nearLoc.Y;
            }
            else
            {
                innerY = Math.Sign(dy) * k1 + nearLoc.Y;
                outerY = Math.Sign(dy) * k2 + nearLoc.Y;
            }

            XYDoubleLocation outerLoc;
            XYDoubleLocation innerLoc = new XYDoubleLocation(innerX, innerY);
            if ((Math.Abs(outerX - nearLoc.X) > Math.Abs(dx))
                || (Math.Abs(outerY - nearLoc.Y) > Math.Abs(dy)))
                outerLoc = farLoc;
            else outerLoc = new XYDoubleLocation(outerX, outerY);
            innerLoc.SetField(nearLoc.Field);
            outerLoc.SetField(nearLoc.Field);

            if ((Math.Abs(innerX - nearLoc.X) > Math.Abs(dx))
                || (Math.Abs(innerY - nearLoc.Y) > Math.Abs(dy)))
                innerLoc = outerLoc; // This occurs if the line has already intersected the neighbor

            this.loc1 = innerLoc;
            this.loc2 = outerLoc;
            this.time = time;
        }
        public void Deploy()
        {
            if (!isInitialized)
                throw new InvalidOperationException("RandomDeployer not initialized!");

            List<XYDoubleLocation> pointList = new List<XYDoubleLocation>();

            rand = randFactory.CreateRandomizer();

            bool continueFlag;
            XYDoubleLocation initial, final, current;
            initial = (XYDoubleLocation)field[0];
            final = (XYDoubleLocation)field[1];
            current = new XYDoubleLocation();

            // Sink
            current = new XYDoubleLocation(final.X, (final.Y - initial.Y)/2);
            current.SetField(field);
            nodes.AddNode(nodeFactory.CreateNode(current));
            pointList.Add(current);
            nodes.GetNodeByID(0).IsSink = true;

            // Sources
            for (int i = 1; i < 6; i++)
            {
                current = new XYDoubleLocation(initial.X, (i-1)*(final.Y-initial.Y)/4);
                current.SetField(field);
                nodes.AddNode(nodeFactory.CreateNode(current));
                pointList.Add(current);
            }

            // Node Field
            for (int i = 6; i < numNodes; i++)
            {
                continueFlag = false;
                while (!continueFlag)
                {
                    continueFlag = true;
                    current = new XYDoubleLocation(
                        rand.NextDouble() * (final.X - initial.X - 2 * padding) + initial.X + padding,
                        rand.NextDouble() * (final.Y - initial.Y - 2 * padding) + initial.Y + padding);
                    foreach (XYDoubleLocation point in pointList)
                    {
                        if (current.Distance(point) < minDistance)
                            continueFlag = false;
                    }
                }
                pointList.Add(current);
                current.SetField(field);
                nodes.AddNode(nodeFactory.CreateNode(current));
            }
        }
        public void Deploy()
        {
            if (!isInitialized)
                throw new InvalidOperationException("GridDeployer not initialized!");

            double x, y;
            XYDoubleLocation initial, final, current;
            initial = (XYDoubleLocation)field[0];
            final = (XYDoubleLocation)field[1];

            for (x = initial.X + padding; x <= final.X - padding; x += nodeDistance)
                for (y = initial.Y + padding; y <= final.Y - padding; y += nodeDistance)
                {
                    current = new XYDoubleLocation(x, y);
                    current.SetField(field);
                    nodes.AddNode(nodeFactory.CreateNode(current));  // Creates a node using the factory and adds it to the collection.
                }
        }