private void openClusterBtn_Click(object sender, EventArgs e) { do { string kwsnName = null; if (listViewBefore.SelectedItems.Count > 0) { kwsnName = listViewBefore.SelectedItems[0].Text + ".kwsn"; mListener.onOpenFile(ClusterHelper.CURRENT_PATH + ClusterHelper.BEFORE_FOLDER + "\\" + kwsnName); break; } if (listViewAfter.SelectedItems.Count > 0) { kwsnName = listViewAfter.SelectedItems[0].Text + ".kwsn"; mListener.onOpenFile(ClusterHelper.CURRENT_PATH + ClusterHelper.AFTER_FOLDER + "\\" + kwsnName); break; } DevLog.e(TAG, "Not item selected"); } while (false); // mlqvu-20151026- force close after open kwsn file Close(); }
//private string GetOption() //{ // string option = ""; // option += MenuButton_EnableSimplificationOfTheFormula.Checked ? "" : "l"; // option += MenuButton_EnableOntheflyAutomataSimplification.Checked ? "" : "o"; // option += MenuButton_EnableAPosterioriAutomataSimplification.Checked ? "" : "p"; // option += MenuButton_EnableStronglyConnectedComponentsSimplification.Checked ? "" : "c"; // option += MenuButton_EnableTrickingInAcceptingConditions.Checked ? "" : "a"; // return option; //} private SpecificationBase parseSpecification() { SpecificationBase spec = null; do { if (mTabItem == null || mTabItem.Text.Trim() == "") { DevLog.e(TAG, "mTabItem is null"); break; } // DisableAllControls(); try { string moduleName = mTabItem.ModuleName; if (LoadModule(moduleName)) { //string option = GetOption(); Stopwatch t = new Stopwatch(); // DisableAllControls(); disableAllControls(); t.Start(); spec = mModule.ParseSpecification(mTabItem.Text, "", mTabItem.FileName); t.Stop(); if (spec != null) { mTabItem.Specification = spec; if (spec.Errors.Count > 0) { string key = ""; foreach (KeyValuePair <string, ParsingException> pair in spec.Errors) { key = pair.Key; break; } ParsingException parsingException = spec.Errors[key]; spec.Errors.Remove(key); throw parsingException; } } // Spec = spec; initLogic(); enableAllControls(); // EnableAllControls(); } } catch (ParsingException ex) { } catch (Exception ex) { } } while (false); return(spec); }
public void Write() { FileStream myFile = null; StreamWriter bwFile = null; try { myFile = new FileStream(mPathTmp, FileMode.Create); bwFile = new StreamWriter(myFile); string abstractLevel = getAbstractLevel(); switch (abstractLevel) { case "\\na": bwFile.Write(String.Format("% " + mExtendInfo.mNumberSensor.ToString() + " nodes - " + mExtendInfo.mNumberPacket.ToString() + " Packet - " + getMode() + "\n")); bwFile.Write(String.Format("\\multirow{{10}}{{*}}{{" + mExtendInfo.mNumberSensor.ToString() + "}} & \\multirow{{10}}{{*}}{{" + mExtendInfo.mNumberPacket.ToString() + "}} & \\multirow{{10}}{{*}}{{" + mExtendInfo.mSensorMaxBufferSize.ToString() + "}} &\\multirow{{10}}{{*}}{{" + modelatex + "}} &\\multirow{{3}}{{*}}{{" + getAbstractLevel() + "}} & \\dl \n& ")); writeDeadlockFree(bwFile); writeChannelCongestion(bwFile); writeSensorCongestion(bwFile); bwFile.Write(String.Format("\\cline{{5-10}}\n")); break; case "\\ca": writeDeadlockFree(bwFile); writeSensorCongestion(bwFile); bwFile.Write(String.Format("\\cline{{5-10}}\n")); break; case "\\sa": writeDeadlockFree(bwFile); writeChannelCongestion(bwFile); bwFile.Write(String.Format("\\hline\r\n\n")); break; default: break; } } catch (Exception e) { DevLog.e("latexworker1", e.Message); } finally { if (bwFile != null) { bwFile.Close(); } if (myFile != null) { myFile.Close(); } } }
/// <summary> /// The function used to convert from PN to KWSN /// </summary> /// <param name="topology">input PN file</param> /// public KWSNGenerationHelper(string name, EditorTabItem tabItem) : base(name, tabItem) { mPNDoc = new XmlDocument(); try { mPNDoc.Load(tabItem.FileName); mLoaded = true; } catch { DevLog.e(TAG, String.Format("Error when load PN file ({0})", name)); MessageBox.Show("Error when reading PN file!"); } }
private string getPureId() { string ret = ""; int srcID = -1; int dstID = -1; try { srcID = ((WSNSensor)from).ID; dstID = ((WSNSensor)to).ID; } catch { DevLog.e(TAG, "Parse ID error"); } if (srcID > 0 && dstID > 0) { ret = srcID + "_" + dstID; } return(ret); }
/// <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); }
public void Update() { string abstractLevel = getAbstractLevel(); //chuoi DeadlockFree non-abstraction string res1 = String.Format("& {0:0.00} & " + mParseRes[0].mTransition + " & " + mParseRes[0].mState + " & " + mParseRes[0].mRes + " \\", mParseRes[0].mMemo / 1024.0f); //chuoi channel congestion non-abstraction & channel/sensor abstraction string res2 = String.Format("& & & & & \\chan & {0:0.00} & " + mParseRes[1].mTransition + " & " + mParseRes[1].mState + " & " + mParseRes[1].mRes + " \\", mParseRes[1].mMemo / 1024.0f); //chuoi sensor congestion non-abstraction & channel/sensor abstraction string res3 = String.Format("& & & & & \\sen & {0:0.00} & " + mParseRes[2].mTransition + " & " + mParseRes[2].mState + " & " + mParseRes[2].mRes + " \\", mParseRes[2].mMemo / 1024.0f); //chuoi DeadlockFree channel/sensor abstract string res4 = String.Format("& & & & \\multirow{{2}}{{*}}{{" + abstractLevel + "}} & \\dl & {0:0.00} & " + mParseRes[0].mTransition + " & " + mParseRes[0].mState + " & " + mParseRes[0].mRes + " \\", mParseRes[0].mMemo / 1024.0f); //chuoi timeout deadlockfree non-abstraction string res5 = String.Format("\\multicolumn{{4}}{{|c|}}{{\\cellcolor{{blue!20}}Time out at {0:0.00}}} \\\\", mParseRes[0].mTime / 1.0d); //chuoi timeout deadlockfree channel/sensor abstraction string res6 = String.Format("& & & & \\multirow{{2}}{{*}}{{" + abstractLevel + "}} & \\dl & \\multicolumn{{4}}{{|c|}}{{\\cellcolor{{blue!20}}Time out at {0:0.00}}} \\\\", mParseRes[0].mTime / 1.0d); //chuoi timeout channel congestion non-abstrction & channel/sensor abstraction string res7 = String.Format("& & & & & \\chan & \\multicolumn{{4}}{{|c|}}{{\\cellcolor{{blue!20}}Time out at {0:0.00}}} \\\\", mParseRes[1].mTime / 1.0d); //chuoi timeout sensor congestion non-abstrction & channel/sensor abstraction string res8 = String.Format("& & & & & \\sen & \\multicolumn{{4}}{{|c|}}{{\\cellcolor{{blue!20}}Time out at {0:0.00}}} \\\\", mParseRes[2].mTime / 1.0d); List <string> lines = new List <string>(); FileStream myFile = new FileStream(mPathTmp, FileMode.Open); StreamReader reader = new StreamReader(myFile); string line; while ((line = reader.ReadLine()) != null) { lines.Add(line); } reader.Close(); myFile.Close(); switch (abstractLevel) { case "\\na": if (mParseRes[0].mTransition != 0 && mParseRes[0].mRes != "\\vl" && mParseRes[0].mRes != "\\nv") { lines[2] = res5; } if (mParseRes[0].mTransition != 0 && (mParseRes[0].mRes == "\\vl" || mParseRes[0].mRes == "\\nv")) { lines[2] = res1; } if (mParseRes[1].mTransition != 0 && mParseRes[1].mRes != "\\vl" && mParseRes[1].mRes != "\\nv") { lines[3] = res7; } if (mParseRes[1].mTransition != 0 && (mParseRes[1].mRes == "\\vl" || mParseRes[1].mRes == "\\nv")) { lines[3] = res2; } if (mParseRes[2].mTransition != 0 && mParseRes[2].mRes != "\\vl" && mParseRes[2].mRes != "\\nv") { lines[4] = res8; } if (mParseRes[2].mTransition != 0 && (mParseRes[2].mRes == "\\vl" || mParseRes[2].mRes == "\\nv")) { lines[4] = res3; } break; case "\\ca": if (mParseRes[0].mTransition != 0 && mParseRes[0].mRes != "\\vl" && mParseRes[0].mRes != "\\nv") { lines[0] = res6; } if (mParseRes[0].mTransition != 0 && (mParseRes[0].mRes == "\\vl" || mParseRes[0].mRes == "\\nv")) { lines[0] = res4; } if (mParseRes[2].mTransition != 0 && mParseRes[2].mRes != "\\vl" && mParseRes[2].mRes != "\\nv") { lines[1] = res8; } if (mParseRes[2].mTransition != 0 && (mParseRes[2].mRes == "\\vl" || mParseRes[2].mRes == "\\nv")) { lines[1] = res3; } break; case "\\sa": if (mParseRes[0].mTransition != 0 && mParseRes[0].mRes != "\\vl" && mParseRes[0].mRes != "\\nv") { lines[0] = res6; } if (mParseRes[0].mTransition != 0 && (mParseRes[0].mRes == "\\vl" || mParseRes[0].mRes == "\\nv")) { lines[0] = res4; } if (mParseRes[1].mTransition != 0 && mParseRes[1].mRes != "\\vl" && mParseRes[1].mRes != "\\nv") { lines[1] = res7; } if (mParseRes[1].mTransition != 0 && (mParseRes[1].mRes == "\\vl" || mParseRes[1].mRes == "\\nv")) { lines[1] = res2; } break; default: break; } FileStream myWriteFile = null; StreamWriter writer = null; try { myWriteFile = new FileStream(mPathTmp, FileMode.Create); writer = new StreamWriter(myWriteFile); foreach (String item in lines) { writer.WriteLine(item); } writer.Close(); myWriteFile.Close(); } catch (Exception e) { DevLog.e(TAG, e.Message); } finally { if (writer == null) { writer.Close(); } if (myWriteFile == null) { myWriteFile.Close(); } } }