public static void buildConnOutSensorMC(XmlDocument docOut, XmlElement transitions, XmlElement places, XmlElement arcs, LocalNetwork localNetwork) { buildConnOutSensorUN(docOut, transitions, places, arcs, localNetwork); int fromId, toId; WSNPNData fromData, toData; foreach (WSNChannel channel in localNetwork.mChannels) { if (channel.Neighbor) { continue; } fromId = ((WSNSensor)channel.From).ID; toId = ((WSNSensor)channel.To).ID; fromData = localNetwork.getMapping(channel.ID); toData = localNetwork.getMapping(toId); foreach (int item in channel.SubIdList) { toData = localNetwork.getMapping(item); if (item == fromId || toData == null) { continue; } arcs.AppendChild(buildArc(docOut, fromData.getOutNodeName(), toData.getInNodeName(), computeCenterXY(fromData, toData))); } } }
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)); } }
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))); } }
/// <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)); } } }
/// <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)); } } }