/// <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);
        }