Example #1
0
        /// <summary>
        /// Add an arc between two nodes
        /// </summary>
        /// <param name="arcs">Parent node of all arcs</param>
        /// <param name="from">From node</param>
        /// <param name="to">To node</param>
        private void addArc(ref XmlElement arcs, ref WSNPNData from, ref WSNPNData to)
        {
            XmlElement arc;
            XmlElement label;
            XmlElement position;

            float xPos, yPos, fTmp;

            arc = _docOut.CreateElement(PNNode.TAG_ARC);
            arc.SetAttribute(PNNode.TAG_ARC_PRO_FROM, from.outNode.name + from.nodeId);
            arc.SetAttribute(PNNode.TAG_ARC_PRO_TO, to.inNode.name + to.nodeId);
            arc.SetAttribute(PNNode.TAG_ARC_PRO_WEIGHT, "1");

            label    = _docOut.CreateElement(PNNode.TAG_LABEL);
            position = _docOut.CreateElement(PNNode.TAG_POSITION);
            fTmp     = Math.Abs(from.outNode.pos.x - to.inNode.pos.x) / 2;
            xPos     = Math.Min(from.outNode.pos.x, to.inNode.pos.x) + fTmp;
            position.SetAttribute(PNNode.TAG_POSITION_X, xPos.ToString());

            fTmp = Math.Abs(from.outNode.pos.y - to.inNode.pos.y) / 2;
            yPos = Math.Min(from.outNode.pos.y, to.inNode.pos.y) + fTmp;
            position.SetAttribute(PNNode.TAG_POSITION_Y, yPos.ToString());
            position.SetAttribute(PNNode.TAG_POSITION_WIDTH, "0.25");
            label.AppendChild(position);
            arc.AppendChild(label);
            arcs.AppendChild(arc);
        }
Example #2
0
        //*********************** CHANNEL BUILD UTILS **********************

        /// <summary>
        /// Compute center XY of between fromData and toData
        /// </summary>
        /// <param name="fromData"></param>
        /// <param name="toData"></param>
        /// <returns>Float point</returns>
        private static PointF computeCenterXY(WSNPNData fromData, WSNPNData toData)
        {
            PointF p = new PointF();

            p.X = (fromData.getOutNodePosition().X + toData.getInNodePosition().X) / 2f;
            p.Y = (fromData.getOutNodePosition().Y + toData.getInNodePosition().Y) / 2f;
            return(p);
        }
Example #3
0
        public static void buildConnInSensorImprove(XmlDocument docOut, XmlElement transitions, XmlElement places, XmlElement arcs, LocalNetwork localNetwork)
        {
            foreach (WSNSensor sensor in localNetwork.mSensors)
            {
                List <WSNChannel> channels = getChannelsInSensor(sensor.ID, localNetwork.mChannels);
                if (channels.Count == 0)
                {
                    continue;
                }

                WSNPNData sData = (WSNPNData)localNetwork.getMapping(sensor.ID);
                if (channels.Count == 1)
                {
                    WSNPNData cData = (WSNPNData)localNetwork.getMapping(channels[0].ID);
                    arcs.AppendChild(buildArc(docOut, cData.getOutNodeName(),
                                              sData.getInNodeName(), computeCenterXY(cData, sData)));
                    continue;
                }

                float  cx, cy;
                float  fx, fy;
                string transName = "ConnIn" + sensor.ID;
                foreach (WSNChannel channel in channels)
                {
                    WSNPNData cData = localNetwork.getMapping(channel.ID);
                    cx = cData.getOutNodePosition().X;
                    cy = cData.getOutNodePosition().Y;
                    fx = (cx + sData.getInNodePosition().X) / 2f;
                    fy = (cy + sData.getInNodePosition().Y) / 2f;

                    String     placeName = "BrFrom" + channel.ID;
                    XmlElement outPlace  = buildPlace(docOut, placeName, fx, fy);
                    places.AppendChild(outPlace);

                    // Build Arcs for place
                    arcs.AppendChild(buildArc(docOut, cData.getOutNodeName(),
                                              placeName, new PointF(fx, fy)));
                    arcs.AppendChild(buildArc(docOut, placeName,
                                              transName, new PointF(fx, fy)));
                }

                //int size = channels.Count;
                //x = x / size;
                //y = y / size;
                //x = (x + sData.getInNodePosition().X) / 3f;
                //y = (y + sData.getInNodePosition().Y) / 3f;
                XmlElement outTrans = buildTransistion(docOut, transName, sData.getInNodePosition().X - 0.8f, sData.getInNodePosition().Y);
                transitions.AppendChild(outTrans);

                // Build connect from ConnectionIn to sensor
                arcs.AppendChild(buildArc(docOut, transName, sData.getInNodeName(), sData.getInNodePosition().X - 0.4f, sData.getInNodePosition().Y));
            }
        }
Example #4
0
        public static void buildConnInSensor(XmlDocument docOut, XmlElement transitions, XmlElement places, XmlElement arcs, LocalNetwork localNetwork)
        {
            float x, y;

            foreach (WSNChannel channel in localNetwork.mChannels)
            {
                WSNPNData cData = localNetwork.getMapping(channel.ID);
                WSNPNData sData = localNetwork.getMapping(((WSNSensor)channel.To).ID);
                x = (cData.getOutNodePosition().X + sData.getInNodePosition().X) / 2f;
                y = (cData.getOutNodePosition().Y + sData.getInNodePosition().Y) / 2f;
                arcs.AppendChild(buildArc(docOut, cData.getOutNodeName(), sData.getInNodeName(), new PointF(x, y)));
            }
        }
Example #5
0
        public WSNPNData getMapping(object id)
        {
            WSNPNData ret = null;

            do
            {
                if (mMapData.ContainsKey(id) == false)
                {
                    break;
                }

                ret = (WSNPNData)mMapData[id];
            } while (false);

            return(ret);
        }
Example #6
0
        /// <summary>
        /// Generate the intermediate arcs that link between sensors
        /// eg: Output1 --> Channel1_2
        /// </summary>
        /// <param name="docOut"></param>
        /// <param name="transitions"></param>
        /// <param name="places"></param>
        /// <param name="arcs"></param>
        /// <param name="localNetwork"></param>
        public static void buildConnOutSensorUN(XmlDocument docOut, XmlElement transitions, XmlElement places, XmlElement arcs, LocalNetwork localNetwork)
        {
            float x, y;

            foreach (WSNSensor sensor in localNetwork.mSensors)
            {
                foreach (WSNChannel channel in localNetwork.mChannels)
                {
                    WSNSensor fromS = (WSNSensor)channel.From;
                    if (fromS.ID != sensor.ID)
                    {
                        continue;
                    }

                    // No need for ConnIn and UniIn on the generated PN

                    //String transName = "UniIn" + channel.ID;
                    //WSNPNData outSData = localNetwork.getMapping(sensor.ID);
                    //WSNPNData inSData = localNetwork.getMapping(channel.ID);
                    //x = (outSData.getOutNodePosition().X + inSData.getInNodePosition().X) / 2f;
                    //y = (outSData.getOutNodePosition().Y + inSData.getInNodePosition().Y) / 2f;
                    //XmlElement trans = buildTransistion(docOut, transName, x, y);
                    //transitions.AppendChild(trans);

                    //arcs.AppendChild(buildArc(
                    //    docOut, outSData.getOutNodeName(), transName,
                    //    (x + outSData.getOutNodePosition().X) / 2f, (y + outSData.getOutNodePosition().Y) / 2f));

                    //String placeName = "ConnIn" + channel.ID;
                    //x = inSData.getInNodePosition().X - 1f;
                    //y = inSData.getInNodePosition().Y;
                    //XmlElement place = buildPlace(docOut, placeName, x, y);
                    //places.AppendChild(place);

                    //arcs.AppendChild(buildArc(
                    //    docOut, transName, placeName, x - 0.5f, y));
                    //arcs.AppendChild(buildArc(
                    //    docOut, placeName, inSData.getInNodeName(), x - 0.15f, y));

                    WSNPNData outSData = localNetwork.getMapping(sensor.ID);
                    WSNPNData inSData  = localNetwork.getMapping(channel.ID);
                    x = (outSData.getOutNodePosition().X + inSData.getInNodePosition().X) / 2f;
                    y = (outSData.getOutNodePosition().Y + inSData.getInNodePosition().Y) / 2f;
                    arcs.AppendChild(buildArc(docOut, outSData.getOutNodeName(), inSData.getInNodeName(), x - 0.5f, y));
                }
            }
        }
Example #7
0
        /// <summary>
        /// Update the PN data to the final output file
        /// </summary>
        /// <param name="data">The input PN data of current item</param>
        /// <param name="places">Places node parent</param>
        /// <param name="transitions">Transitions node parent</param>
        /// <param name="arcs">Arcs node parent</param>
        private void addPNData(WSNPNData data, ref XmlElement places, ref XmlElement transitions, ref XmlElement arcs)
        {
            XmlElement[,] map = new XmlElement[, ]
            {
                { data.places, places },
                { data.transitions, transitions },
                { data.arcs, arcs },
            };
            XmlDocumentFragment xFrag = null;

            for (int i = 0; i < map.GetLength(0); i++)
            {
                foreach (XmlElement xml in map[i, 0].ChildNodes)
                {
                    xFrag          = mDocOut.CreateDocumentFragment();
                    xFrag.InnerXml = xml.OuterXml;
                    map[i, 1].AppendChild(xFrag);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Update the PN data to the final output file
        /// </summary>
        /// <param name="data">The input PN data of current item</param>
        /// <param name="places">Places node parent</param>
        /// <param name="transitions">Transitions node parent</param>
        /// <param name="arcs">Arcs node parent</param>
        private void addPNData(WSNPNData data, ref XmlElement places, ref XmlElement transitions, ref XmlElement arcs)
        {
            XmlElement[,] map = new XmlElement[, ]
            {
                { data.places, places },
                { data.transitions, transitions },
                { data.arcs, arcs },
            };
            XmlDocumentFragment xFrag = null;

            for (int i = 0; i < map.GetLength(0); i++)
            {
                foreach (XmlElement xml in map[i, 0].ChildNodes)
                {
                    xFrag          = _docOut.CreateDocumentFragment();
                    xFrag.InnerXml = xml.OuterXml;
                    map[i, 1].AppendChild(xFrag);
                }
            }

            //Log.d(TAG, string.Format("In: {0} --- Out: {1}", data.inPos, data.outPos));
        }
Example #9
0
        /// <summary>
        /// Generate PN xml file from KWSN model
        /// </summary>
        /// <param name="abstractSensor">if Sensors are abstracted</param>
        /// <param name="abstractChannel">if Channel are abstracted</param>
        /// <returns>PN xml</returns>
        public override XmlDocument GenerateXML(params bool[] values)
        {
            do
            {
                if (values == null || values.Count() != 3)
                {
                    DevLog.e(TAG, "Incorrect input params");
                    break;
                }

                bool abstractSensor  = values[0];
                bool abstractChannel = values[1];
                bool improved        = values[2];

                bool       blError = false;
                XmlElement models  = mDocOut.CreateElement(XmlTag.TAG_MODELS);
                mXRoot.AppendChild(models);

                foreach (WSNCanvas canvas in mCanvas)
                {
                    List <WSNSensor>  sensors              = new List <WSNSensor>();  // sensors list from canvas
                    List <WSNChannel> channels             = new List <WSNChannel>(); // channel list from canvas
                    StringBuilder     ltlSensorCongestion  = new StringBuilder();     // LTL for check on sensor
                    StringBuilder     ltlChannelCongestion = new StringBuilder();     // LTL for check on channel
                    int          maxSensorId    = 0;
                    List <Int32> sensorCheckIds = new List <Int32>();

                    foreach (LTSCanvas.CanvasItemData item in canvas.itemsList) // get the sensors list
                    {
                        if (item.Item is WSNSensor)
                        {
                            WSNSensor add = (WSNSensor)item.Item;
                            add.locateX = item.Item.X / 120;
                            add.locateY = item.Item.Y / 120;

                            if (mMinX == 0 || add.locateX < mMinX)
                            {
                                mMinX = add.locateX;
                            }
                            if (mMinY == 0 || add.locateY < mMinY)
                            {
                                mMinY = add.locateY;
                            }

                            sensors.Add(add.Clone());
                            if (add.ID > maxSensorId)
                            {
                                maxSensorId = add.ID;
                            }

                            // Append LTL for sensor congestion
                            if (abstractSensor || add.NodeType != SensorType.Intermediate)
                            {
                                continue;
                            }
                            sensorCheckIds.Add(add.ID);
                        }
                    }

                    // Add LTL check congestion on sensor
                    int interCnt = sensorCheckIds.Count;
                    if (interCnt > 0)
                    {
                        ltlSensorCongestion.Append("#assert System |= []!(");
                        for (int i = 0; i < interCnt - 1; i++)
                        {
                            ltlSensorCongestion.Append(String.Format("Congestion{0} || ", sensorCheckIds[i]));
                        }
                        ltlSensorCongestion.Append(String.Format("Congestion{0});", sensorCheckIds[interCnt - 1]));
                    }

                    // Get the channels list
                    foreach (Route route in canvas.diagramRouter.routes)
                    {
                        if (route is WSNChannel)
                        {
                            WSNChannel channel = (WSNChannel)route;
                            channel.Type = getChannelType(Build.mMode);
                            channels.Add(channel.Clone());
                        }
                    }

                    XmlElement topology = mDocOut.CreateElement(XmlTag.TAG_TOPOLOGY);
                    topology.SetAttribute(XmlTag.ATTR_mID, mExtendInfo.mID.ToString());
                    topology.SetAttribute(XmlTag.ATTR_NUMOFSENSORS, mExtendInfo.mNumberSensor.ToString());
                    topology.SetAttribute(XmlTag.ATTR_NUMOFPACKETS, mExtendInfo.mNumberPacket.ToString());
                    topology.SetAttribute(XmlTag.ATTR_AVGBUFFER, mExtendInfo.mSensorMaxBufferSize.ToString());
                    topology.SetAttribute(XmlTag.TAG_MODE, Build.mMode.ToString());
                    topology.SetAttribute(XmlTag.TAG_ABSTRACTEDLEVEL, (abstractSensor ? "0" : "1") + (abstractChannel ? "0" : "1"));

                    foreach (WSNSensor sensor in sensors) // append sensor to topology
                    {
                        topology.AppendChild(sensor.WriteToXml(mDocOut));
                    }

                    foreach (WSNChannel channel in channels) // append channel to topology
                    {
                        topology.AppendChild(channel.WriteToXml(mDocOut));
                    }

                    XmlElement model       = mDocOut.CreateElement(XmlTag.TAG_MODEL);
                    XmlElement places      = mDocOut.CreateElement(XmlTag.TAG_PLACES);
                    XmlElement transitions = mDocOut.CreateElement(XmlTag.TAG_TRANSITIONS);
                    XmlElement arcs        = mDocOut.CreateElement(XmlTag.TAG_ARCS);

                    models.AppendChild(model);
                    model.AppendChild(topology);
                    model.AppendChild(places);
                    model.AppendChild(transitions);
                    model.AppendChild(arcs);

                    do
                    {
                        WSNPNData data      = null;
                        float     xStartPos = 0;
                        float     yStartPos = 0;

                        Hashtable mapData = new Hashtable();
                        bool      localSensorAbstract;
                        foreach (WSNSensor sensor in sensors)
                        {
                            ////// Force keep source sensor in case unicast or multicast
                            //localSensorAbstract = abstractSensor;
                            //if (sensor.NodeType == SensorType.Source
                            //    && abstractSensor && (Build.mMode == NetMode.UNICAST || Build.mMode == NetMode.MULTICAST))
                            //    localSensorAbstract = false;

                            data = sensor.GeneratePNXml(mDocPNRes, sensor.ID.ToString(), abstractSensor, sensor.locateX - mMinX, sensor.locateY - mMinY);
                            if (data == null)
                            {
                                DevLog.e(TAG, "Failed to generate the sensor PN xml nodes");
                                blError = true;
                                break;
                            }

                            mapData[sensor.ID] = data;
                            xStartPos         += XPOSITION_SHIFT;

                            // 20151113-lqv-change model
                            // Embed code for sensor
                            BuildUtils.embedCodeToSensor(data, sensor, channels, abstractSensor);
                            addPNData(data, ref places, ref transitions, ref arcs);

                            // Then find the channel connected with this sensor
                            foreach (WSNChannel channel in channels)
                            {
                                WSNSensor sensorFrom = (WSNSensor)channel.From;
                                if (sensorFrom.ID != sensor.ID)
                                {
                                    continue;
                                }

                                // compute positon for channel
                                xStartPos = (channel.From.AbsoluteX + channel.To.AbsoluteX) / 240;
                                yStartPos = (channel.From.AbsoluteY + channel.To.AbsoluteY) / 240;

                                data = channel.GeneratePNXml(mDocPNRes, channel.ID, abstractChannel, xStartPos - mMinX, yStartPos - mMinY, channel.ProbabilityPathCongestion);
                                if (data == null)
                                {
                                    DevLog.d(TAG, "Failed to generate the sensor PN xml nodes");
                                    blError = true;
                                    break;
                                }

                                mapData[channel.ID] = data;
                                xStartPos          += XPOSITION_SHIFT; // Shift x position
                                yStartPos          += YPOSITION_SHIFT; // Shift y position

                                // 20151113-lqv-changle model
                                BuildUtils.embedCodeToChannel(data, channel, abstractChannel, abstractSensor);
                                addPNData(data, ref places, ref transitions, ref arcs);
                            } // foreach

                            if (blError == true)
                            {
                                break;
                            }
                        } // foreach

                        if (blError == true)
                        {
                            break;
                        }


                        LocalNetwork localNetwork = new LocalNetwork(mapData, abstractSensor, abstractChannel, sensors, channels);
                        switch (Build.mMode)  // build connector by mode
                        {
                        case NetMode.BROADCAST:
                            BuildUtils.buildConnOutSensorBR(mDocOut, transitions, places, arcs, localNetwork);
                            if (improved)
                            {
                                BuildUtils.buildConnInSensorImprove(mDocOut, transitions, places, arcs, localNetwork);
                                break;
                            }
                            BuildUtils.buildConnInSensor(mDocOut, transitions, places, arcs, localNetwork);
                            break;

                        case NetMode.UNICAST:
                            BuildUtils.buildConnOutSensorUN(mDocOut, transitions, places, arcs, localNetwork);
                            // Not support improved in unicast mode
                            BuildUtils.buildConnInSensor(mDocOut, transitions, places, arcs, localNetwork);
                            break;

                        case NetMode.MULTICAST:
                            BuildUtils.buildConnOutSensorMC(mDocOut, transitions, places, arcs, localNetwork);
                            BuildUtils.buildConnInSensor(mDocOut, transitions, places, arcs, localNetwork);
                            //if (improved)
                            //{
                            //    BuildUtils.buildConnInSensorImprove(mDocOut, transitions, places, arcs, localNetwork);
                            //    break;
                            //}
                            //BuildUtils.buildConnInSensor(mDocOut, transitions, places, arcs, localNetwork);
                            break;

                        default:
                            break;
                        }

                        #region Update model properties
                        // update the property
                        model.SetAttribute(XmlTag.ATTR_NAME, canvas.ProcessName);
                        model.SetAttribute(XmlTag.ATTR_PRO_PARAM, "");
                        model.SetAttribute(XmlTag.ATTR_ZOOM, "1");
                        model.SetAttribute(XmlTag.TAG_MODEL_PRO_PCOUNTER, "0");
                        model.SetAttribute(XmlTag.TAG_MODEL_PRO_TCOUNTER, "0");
                        #endregion

                        mDocOut.Save(mFileName); // save document
                    } while (false);

                    // Add LTL check congestion on channel
                    if (abstractChannel == false && channels.Count > 0)
                    {
                        ltlChannelCongestion.Append("#assert System |= []!(");
                        for (int i = 0; i < channels.Count - 1; i++)
                        {
                            ltlChannelCongestion.AppendFormat("Congestion{0} || ", channels[i].ID);
                        }
                        ltlChannelCongestion.AppendFormat("Congestion{0});", channels[channels.Count - 1].ID);
                    }

                    // add declaration
                    mDeclaration.InnerXml = String.Format(mDocPNRes.GetElementsByTagName(
                                                              XmlTag.TAG_DECLARATION)[0].InnerXml,
                                                          BuildUtils.buildDeclaration(mExtendInfo, sensors, channels),
                                                          ltlSensorCongestion.ToString(),   // LTL for check on sensor
                                                          ltlChannelCongestion.ToString()); // LTL for check on channel
                }
            } while (false);

            return(mDocOut);
        }
Example #10
0
        public bool generateXML(XmlDocument docRes)
        {
            bool blRet   = false;
            bool blError = false;

            XmlElement models = _docOut.CreateElement(PNNode.TAG_MODELS);

            _xRoot.AppendChild(models);

            XmlElement topologyTag = _docOut.CreateElement(PNNode.TAG_TOPOLOGY);

            foreach (WSNSensorItem sensor in _sensors)
            {
                XmlElement sensorTag = _docOut.CreateElement(PNNode.TAG_SENSOR);
                sensorTag.SetAttribute(PNNode.TAG_SENSOR_TYPE, sensor.NodeType.ToString());
                sensorTag.SetAttribute(PNNode.TAG_SENSOR_ID, sensor.ID.ToString());
                sensorTag.SetAttribute(PNNode.TAG_SENSOR_MODE, sensor.NodeMode.ToString());
                sensorTag.SetAttribute(PNNode.TAG_SENSOR_X, sensor.locateX.ToString());
                sensorTag.SetAttribute(PNNode.TAG_SENSOR_Y, sensor.locateY.ToString());
                topologyTag.AppendChild(sensorTag);
            }
            foreach (WSNSensorChannel channel in _channels)
            {
                XmlElement channelTag = _docOut.CreateElement(PNNode.TAG_CHANNEL);
                channelTag.SetAttribute(PNNode.TAG_CHANNEL_FROM, ((WSNSensorItem)channel.From).ID.ToString());
                channelTag.SetAttribute(PNNode.TAG_CHANNEL_TO, ((WSNSensorItem)channel.To).ID.ToString());
                channelTag.SetAttribute(PNNode.TAG_CHANNEL_ID, channel.ID);
                channelTag.SetAttribute(PNNode.TAG_CHANNEL_TYPE, channel.Type.ToString());
                channelTag.SetAttribute(PNNode.TAG_CHANNEL_MODE, channel.Mode.ToString());
                topologyTag.AppendChild(channelTag);
            }
            _xRoot.AppendChild(topologyTag);

            XmlElement model = _docOut.CreateElement(PNNode.TAG_MODEL);

            models.AppendChild(model);


            XmlElement places      = _docOut.CreateElement(PNNode.TAG_PLACES);
            XmlElement transitions = _docOut.CreateElement(PNNode.TAG_TRANSITIONS);
            XmlElement arcs        = _docOut.CreateElement(PNNode.TAG_ARCS);

            model.AppendChild(places);
            model.AppendChild(transitions);
            model.AppendChild(arcs);


            do
            {
                WSNPNData data = null;

                float xStartPos = 0;
                float yStartPos = 0;

                #region Add Sensor info
                Hashtable mapData = new Hashtable();
                foreach (WSNSensorItem sensor in _sensors)
                {
                    data = sensor.GeneratePNXml(docRes, sensor.ID.ToString(), sensor.locateX - minX, sensor.locateY - minY); //(docRes, xStartPos, 0);
                    if (data == null)
                    {
                        Log.d(TAG, "Failed to generate the sensor PN xml nodes");
                        blError = true;
                        break;
                    }
                    mapData[sensor.ID] = data;
                    xStartPos         += XPositionShift;

                    addPNData(data, ref places, ref transitions, ref arcs);

                    // then find the channel connected with this sensor
                    foreach (WSNSensorChannel channel in _channels)
                    {
                        if (((WSNSensorItem)channel.From).ID != sensor.ID)
                        {
                            continue;
                        }
                        xStartPos = (channel.From.AbsoluteX + channel.To.AbsoluteX) / 240; //kkk

                        yStartPos = (channel.From.AbsoluteY + channel.To.AbsoluteY) / 240;

                        data = channel.GeneratePNXml(docRes, channel.ID, xStartPos - minX, yStartPos - minY);
                        if (data == null)
                        {
                            Log.d(TAG, "Failed to generate the sensor PN xml nodes");
                            blError = true;
                            break;
                        }
                        mapData[channel.ID] = data;
                        //xStartPos += XPositionShift;
                        //yStartPos += YPositionShift;

                        addPNData(data, ref places, ref transitions, ref arcs);
                    }

                    if (blError == true)
                    {
                        break;
                    }
                }
                if (blError == true)
                {
                    break;
                }

                // connect the model
                int       fromId, toId;
                WSNPNData fromData, toData;

                foreach (WSNSensorChannel channel in _channels)
                {
                    fromId = ((WSNSensorItem)channel.From).ID;
                    toId   = ((WSNSensorItem)channel.To).ID;

                    // arc from
                    fromData = (WSNPNData)mapData[fromId];
                    toData   = (WSNPNData)mapData[channel.ID];
                    addArc(ref arcs, ref fromData, ref toData);

                    // arc to
                    fromData = (WSNPNData)mapData[channel.ID];
                    toData   = (WSNPNData)mapData[toId];
                    addArc(ref arcs, ref fromData, ref toData);
                }
                #endregion

                #region Update model properties
                // update the property
                model.SetAttribute(PNNode.TAG_PRO_NAME, "WSN 0");
                model.SetAttribute(PNNode.TAG_MODEL_PRO_PARAM, "");
                model.SetAttribute(PNNode.TAG_MODEL_PRO_ZOOM, "1");
                model.SetAttribute(PNNode.TAG_MODEL_PRO_PCOUNTER, "0");
                model.SetAttribute(PNNode.TAG_MODEL_PRO_TCOUNTER, "0");
                #endregion

                _docOut.Save(_fileName);
                blRet = true;
            } while (false);

            return(blRet);
        }
Example #11
0
        /// <summary>
        /// Combine code for channel
        /// </summary>
        /// <param name="data">Channel data</param>
        /// <param name="channel">Channel item</param>
        /// <param name="channelAbstract"></param>
        /// <param name="sensorAbstract"></param>
        public static void embedCodeToChannel(WSNPNData data, WSNChannel channel, bool channelAbstract, bool sensorAbstract)
        {
            do
            {
                string    id = channel.ID;
                XmlNode   transition; // get xml node to transition then edit content
                WSNSensor fSensor  = (WSNSensor)channel.From;
                WSNSensor tSensor  = (WSNSensor)channel.To;
                bool      isSource = (fSensor.NodeType == SensorType.Source);

                if (channelAbstract)
                {
                    switch (Build.mMode)
                    {
                    case NetMode.BROADCAST:
                    {
                        // {0} - channel id - {1} - b1/q1 of sensor - {2} sensor/main
                        transition = getTransition(data, "Channel", id);
                        string program = String.Format(PROGRAM_CHANNEL_RECEIVE_BR,
                                                       channel.ID, (sensorAbstract ? "q" : "b") + tSensor.ID, "BrOut");

                        setXmlNodeData(transition, "Program", program);
                        setXmlNodeData(transition, "Guard",
                                       String.Format("b{0} > 0 &&  b{0} <= C_MAX_BUFFER", channel.ID));
                        break;
                    }

                    case NetMode.UNICAST:
                    {
                        // {0} - channel id, {1} pkg/qk of from sensor, {2} from sensor id, {3} to sensor id
                        transition = getTransition(data, "Channel", id);
                        //setXmlNodeData(transition, "Program",
                        //String.Format(PROGRAM_CHANNEL_ASTRACTION, id, isSource ? "pkg" : ("q" + fSensor.ID), fSensor.ID, tSensor.ID));
                        setXmlNodeData(
                            transition,
                            "Program",
                            String.Format(
                                PROGRAM_CHANNEL_ASTRACTION,
                                isSource ? "pkg" : ("q" + fSensor.ID),
                                fSensor.ID,
                                tSensor.ID));
                        //setXmlNodeData(transition, "Guard", String.Format("b{0} <= C_MAX_BUFFER", id));
                        break;
                    }

                    case NetMode.MULTICAST:
                    {
                        // {0} - channel id, {1} pkg/qk of from sensor, {2} from sensor id, {3} to sensor id, {4} grp
                        transition = getTransition(data, "Channel", id);
                        StringBuilder programCode = new StringBuilder();
                        programCode.AppendFormat("\n\tb{0} = b{0} + sub;", tSensor.ID);
                        foreach (int sensorID in channel.SubIdList)
                        {
                            programCode.AppendFormat("\n\tb{0} = b{0} + sub;", sensorID);
                        }

                        transition = getTransition(data, "Channel", id);
                        setXmlNodeData(transition, "Program",
                                       String.Format(PROGRAM_CHANNEL_ASTRACTION_MC, id, isSource ? "pkg" : ("q" + fSensor.ID), fSensor.ID, tSensor.ID, programCode.ToString()));
                        setXmlNodeData(transition, "Guard", String.Format("b{0} <= C_MAX_BUFFER", id));
                        break;
                    }

                    default:
                        break;
                    }
                    break;
                }

                // Same code inside congestion transition
                // Embed code for transition's congestion
                transition = getTransition(data, "Congestion", id);
                setXmlNodeData(transition, "Guard", String.Format("b{0} > C_MAX_BUFFER || q{0} > C_MAX_QUEUE", id));
                setXmlNodeData(transition, "Program", String.Format("Input{0}", tSensor.ID));

                switch (channel.Type)
                {
                case ChannelType.Broadcast:
                {
                    transition = getTransition(data, "Send", id);
                    string program = String.Format(PROGRAM_CHANNEL_RECEIVE_BR,
                                                   channel.ID,
                                                   (sensorAbstract ? "q" : "b") + tSensor.ID, "Main");

                    setXmlNodeData(transition, "Program", program);
                    setXmlNodeData(transition, "Guard",
                                   String.Format("b{0} > 0 &&  b{0} <= C_MAX_BUFFER", channel.ID));
                    break;
                }

                case ChannelType.Unicast:
                {
                    // {0} channel id, {1} pkg/qk of from sensor id
                    transition = getTransition(data, "Receive", id);
                    //setXmlNodeData(transition, "Program",
                    //    String.Format(PROGRAM_CHANNEL_RECEIVE_UNI, id, isSource ? "pkg" : ("q" + fSensor.ID)));
                    setXmlNodeData(transition, "Program",
                                   String.Format(PROGRAM_CHANNEL_RECEIVE_UNI, fSensor.ID));
                    setXmlNodeData(transition, "Guard",
                                   isSource ? "pkg > 0" : String.Format("b{0} > 0 && b{0} <= S_MAX_BUFFER && q{0} > 0 && q{0} <= C_MAX_QUEUE", fSensor.ID));

                    // Embed code for transition's send
                    // {0} - channel ID / {1} - to sensor ID / {2} b/q - {3} pkg/q of sensor - {4} - sensor/output - {5} from sensor id
                    // transition = getTransition(data, "Send", id);
                    // setXmlNodeData(transition, "Program",
                    //    String.Format(PROGRAM_CHANNEL_SEND, id, tSensor.ID, sensorAbstract ? "q" : "b"));
                    // setXmlNodeData(transition, "Guard", String.Format("b{0} > 0 && b{0} <= C_MAX_BUFFER", id));
                    break;
                }

                case ChannelType.Multicast:
                {
                    // {0} channel id, {1} pkg/qk of from sensor id
                    transition = getTransition(data, "Receive", id);
                    setXmlNodeData(transition, "Program",
                                   String.Format(PROGRAM_CHANNEL_RECEIVE_UNI, id, isSource ? "pkg" : ("q" + fSensor.ID)));
                    setXmlNodeData(transition, "Guard",
                                   isSource ? "pkg > 0" : String.Format("q{0} > 0 && q{0} <= S_MAX_BUFFER", fSensor.ID));

                    // Embed code for transition's send
                    transition = getTransition(data, "Send", channel.ID);
                    setXmlNodeData(transition, "Program", initSendMulticast(channel, sensorAbstract));
                    setXmlNodeData(transition, "Guard", String.Format("b{0} > 0 && b{0} <= C_MAX_BUFFER", id));
                    break;
                }

                default:
                    break;
                }
            } while (false);
        }
Example #12
0
        /// <summary>
        /// Build connector for broadcast mode
        /// </summary>
        /// <param name="docOut">Xmldocument output</param>
        /// <param name="transitions">trans contain channels instance</param>
        /// <param name="canvas"></param>
        /// <param name="places"></param>
        /// <param name="arcs"></param>
        /// <param name="mapData"></param>
        /// <param name="sensors"></param>
        /// <param name="channels"></param>
        /// <param name="abstractSensor"></param>
        /// <param name="abstractChannel"></param>
        public static void buildConnOutSensorBR(XmlDocument docOut, XmlElement transitions, XmlElement places, XmlElement arcs, LocalNetwork localNetwork)
        {
            float x;
            float y;

            foreach (WSNSensor sensor in localNetwork.mSensors)
            {
                if (sensor.NodeType == SensorType.Sink)
                {
                    continue;
                }

                // Build first transition
                string    transName  = "ConnOut_" + sensor.ID;
                WSNPNData sensorData = localNetwork.getMapping(sensor.ID);

                if (sensorData == null)
                {
                    continue;
                }

                x = sensorData.getOutNodePosition().X + 0.8f;
                y = sensorData.getOutNodePosition().Y;
                XmlElement trans = buildTransistion(docOut, transName, x, y);

                // Add code to transition connector
                // {0} - pkg/q of sensor - {1} sensor id - {2} - channel grp - {3} - main/sensor
                StringBuilder channelGrp = new StringBuilder();
                bool          isSource   = sensor.NodeType.Equals(SensorType.Source);
                string        queue      = isSource ? "pkg" : ("q" + sensor.ID);
                foreach (WSNChannel channel in localNetwork.mChannels)
                {
                    if (((WSNSensor)channel.From).ID == sensor.ID)
                    {
                        channelGrp.AppendFormat("\nb{0} = b{0} + sub;", channel.ID);
                    }
                }

                string program = String.Format(PROGRAM_SENSOR_SEND, queue, sensor.ID, channelGrp, localNetwork.getPlaceNameForToken());
                setXmlNodeData(trans, "Program", program);
                setXmlNodeData(trans, "Guard",
                               isSource ? "pkg > 0" : String.Format("q{0} > 0 && q{0} <= S_MAX_BUFFER", sensor.ID));

                transitions.AppendChild(trans);
                arcs.AppendChild(buildArc(
                                     docOut, sensorData.getOutNodeName(), transName, new PointF(x + 0.4f, y)));

                foreach (WSNChannel channel in localNetwork.mChannels)
                {
                    if (((WSNSensor)channel.From).ID != sensor.ID)
                    {
                        continue;
                    }

                    string    placeName   = "BrOut" + channel.ID;
                    WSNPNData channelData = localNetwork.getMapping(channel.ID);
                    if (channelData == null)
                    {
                        continue;
                    }

                    float fx = (x + channelData.getInNodePosition().X) / 2f;
                    float fy = (y + channelData.getInNodePosition().Y) / 2f;

                    // Build place connect from Connector_ to channels
                    places.AppendChild(buildPlace(docOut, placeName, fx, fy));
                    arcs.AppendChild(buildArc(docOut, transName, placeName, new PointF((x + fx) / 2f, (y + fy) / 2f)));
                    arcs.AppendChild(buildArc(docOut, placeName, channelData.getInNodeName(),
                                              (fx + channelData.getInNodePosition().X) / 2f, (fy + channelData.getInNodePosition().Y) / 2f));
                }
            }
        }
Example #13
0
        /// <summary>
        /// Embed code to sensor
        /// </summary>
        /// <param name="data">Sensor data</param>
        /// <param name="sensor">Sensor object</param>
        /// <param name="channels">Channel Object list</param>
        /// <param name="sensorAbstract">Flag sensor has abstracted</param>
        public static void embedCodeToSensor(WSNPNData data, WSNSensor sensor, IList <WSNChannel> channels, bool sensorAbstract)
        {
            XmlNode transition;
            int     id = sensor.ID;

            switch (sensor.NodeType)
            {
            case SensorType.Source:
                if (sensorAbstract)
                {
                    break;
                }

                //if (Build.mMode == NetMode.UNICAST || Build.mMode == NetMode.MULTICAST)
                //{
                //    // {0} - sensor id / {1} - pkg/q of sensor id / {2} - grp
                //    StringBuilder grpChannels = new StringBuilder();
                //    foreach (WSNChannel channel in channels)
                //    {
                //        if (((WSNSensor)channel.From).ID != id)
                //            continue;
                //        grpChannels.AppendFormat("\n\nsub = util.getMin(pkg, sqr{0});", id);
                //        grpChannels.AppendFormat("\nb{0} = b{0} + sub;", channel.ID);
                //        grpChannels.Append("\npkg = pkg - sub;");
                //    }

                //    transition = getTransition(data, "Send", id);
                //    setXmlNodeData(transition, "Program",
                //        String.Format(PROGRAM_SENSOR_SEND_UN, id, "pkg", grpChannels));
                //    setXmlNodeData(transition, "Guard", "pkg > 0");

                //    break;
                //}

                break;

            case SensorType.Intermediate:
                // Not code inside sensor abstracted
                if (sensorAbstract)
                {
                    break;
                }

                //if (Build.mMode == NetMode.UNICAST || Build.mMode == NetMode.MULTICAST)
                //{
                //    StringBuilder grpChannels = new StringBuilder();
                //    String queue = "q" + id;
                //    foreach (WSNChannel channel in channels)
                //    {
                //        if (((WSNSensor)channel.From).ID != id)
                //            continue;
                //        grpChannels.AppendFormat("\n\nsub = util.getMin({0}, sqr{1});", queue, id);
                //        grpChannels.AppendFormat("\nb{0} = b{0} + sub;", channel.ID);
                //        grpChannels.AppendFormat("\n{0} = {0} - sub;", queue);
                //    }

                //    transition = getTransition(data, "Send", id);
                //    setXmlNodeData(transition, "Program",
                //        String.Format(PROGRAM_SENSOR_SEND_UN, id, queue, grpChannels));
                //    setXmlNodeData(transition, "Guard", String.Format("{0} > 0", queue));
                //}

                // Receive transition
                transition = getTransition(data, "Receive", id);
                setXmlNodeData(transition, "Program", String.Format(PROGRAM_SENSOR_RECEIVE, id));
                setXmlNodeData(transition, "Guard", String.Format("b{0} > 0 && b{0} <= S_MAX_BUFFER", id));

                // Congestion transition
                transition = getTransition(data, "Congestion", id);
                setXmlNodeData(transition, "Guard", String.Format("b{0} > S_MAX_BUFFER", id));
                break;

            //// Send transition
            //transition = getTransition(data, "Send", id);
            //setXmlNodeData(transition, "Guard", String.Format("q{0} > 0", id));
            //setXmlNodeData(transition, "Program", "");
            //break;

            case SensorType.Sink:
                transition = getTransition(data, "Receive", id);
                setXmlNodeData(transition, "Program", String.Format("q{0} = q{0} + b{0};\nb{0} = 0;", id));
                break;

            default:
                break;
            }
        }
Example #14
0
 /// <summary>
 /// Get transition by Name and ID
 /// </summary>
 /// <param name="wsnData">Root xml content transision</param>
 /// <param name="name">Name of transition</param>
 /// <param name="id">ID of transition</param>
 /// <returns></returns>
 private static XmlNode getTransition(WSNPNData wsnData, string name, int id)
 {
     return(getTransition(wsnData, name, id.ToString()));
 }
Example #15
0
 /// <summary>
 /// Get transition by Name and ID
 /// </summary>
 /// <param name="wsnData">Root xml content transision</param>
 /// <param name="name">Name of transition</param>
 /// <param name="id">ID of transition</param>
 /// <returns></returns>
 private static XmlNode getTransition(WSNPNData wsnData, string name, string id)
 {
     return(wsnData.transitions.SelectSingleNode(
                String.Format("./Transition[@Name='{0}{1}']", name, id)));
 }