/** Creates an initial marking. */ private void createMarking() { HNSet set = null; marking = null; marking = new HashMap[size]; // Building the marking data structure. This structure is an array of // hashmaps. // For a given hashmap, we have: // - Key: Integer = element // - Value: HashMap = subsets + the number of tokens associated to them // The idea is to keep track of which tasks fired and the number of // tokens at their output subsets. // Initially, the number of tokens is 0. for (int i = 0; i < size; i++) { set = hNet.getOutputSet(i); HashMap map = new HashMap(); for (int j = 0; j < set.size(); j++) { map.put(set.get(j), new Integer(0)); } marking[i] = map; } auxMapping = new MappingToSubsets(hNet); this.reset(); }
public void addValue(long x, double y) { // calculate the bar in which this value should go int bar = (int) (x / barsize); double Y = y; if (ysum.containsKey(bar)) { double newyvalue = Y + ysum.get(bar); long newxvalue = x + xsum.get(bar); Integer newcount = count.get(bar) + 1; ysum.put(bar, newyvalue); xsum.put(bar, newxvalue); count.put(bar, newcount); Vector<Double> barvalues = values.get(bar); barvalues.add(Y); values.put(bar, barvalues); } else { ysum.put(bar, Y); xsum.put(bar, x); count.put(bar, 1); Vector<Double> barvalues = new Vector<Double>(); barvalues.add(Y); values.put(bar, barvalues); } }
public static void traverseAMLforObjectNames( HashMap partialMap, Node currentNode, HashMap ObjDef_LinkId, HashMap ModelId_ModelType) { if (currentNode.hasChildNodes()) { for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) { Node currentChild = currentNode.getChildNodes().item(i); if (currentChild.getNodeName().equals("Group")) { traverseAMLforObjectNames(partialMap, currentChild, ObjDef_LinkId, ModelId_ModelType); } if (currentChild.getNodeName().equals("Model")) { if (currentChild.hasAttributes()) { String mid = currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue(); String type = currentChild.getAttributes().getNamedItem("Model.Type").getNodeValue(); ModelId_ModelType.put(mid, type); } // traverseAMLforObjectNames(partialMap, currentChild, // ObjDef_LinkId); } if (currentChild.getNodeName().equals("ObjDef")) { String id = currentChild.getAttributes().getNamedItem("ObjDef.ID").getNodeValue(); NodeList currentChildren = currentChild.getChildNodes(); String ObjName = ""; for (int k = 0; k < currentChildren.getLength(); k++) { Node Child = currentChildren.item(k); if (!Child.getNodeName().equals("AttrDef")) { continue; } else if (!Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { continue; } else if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { ObjName = getTextContent(Child.getChildNodes().item(l)); ObjName = ObjName.replaceAll("\n", "\\\\n"); break; } } } } partialMap.put(id, ObjName); for (int j = 0; j < currentChild.getAttributes().getLength(); j++) { if (currentChild.getAttributes().item(j).getNodeName().equals("LinkedModels.IdRefs")) { String links = currentChild.getAttributes().getNamedItem("LinkedModels.IdRefs").getNodeValue(); /* * if (links.indexOf(" ") > -1) { * Message.add("yes, yes, yes"); links = * links.substring(0, links.indexOf(" ")); } */ ObjDef_LinkId.put(id, links); } } } } } }
public XYSeries getXYSeries(String rowname, long factor) { XYSeries mydataset = new XYSeries(rowname); for (Integer key : ysum.keySet()) { Double value = ysum.get(key) / (double) count.get(key); Double point = (double) xsum.get(key) / (double) count.get(key); mydataset.add(point / factor, value); } return mydataset; }
public YIntervalSeries getYIntervalSeries(String rowname, long factor) { YIntervalSeries mydataset = new YIntervalSeries(rowname); double sdcount = 0; double total = 0; Vector<Double> totalvalues = new Vector<Double>(); double avgtotal = 0; double minus = 0; double plus = 0; double zero = 0; for (Integer key : ysum.keySet()) { Double value = ysum.get(key) / (double) count.get(key); Double point = (double) xsum.get(key) / (double) count.get(key); Vector<Double> listofvalues = values.get(key); double sumofdiff = 0.0; for (Double onevalue : listofvalues) { sumofdiff += Math.pow(onevalue - value, 2); sdcount++; total += Math.pow(onevalue, 2); avgtotal += onevalue; totalvalues.add(onevalue); if (onevalue == 1) { plus++; } ; if (onevalue == -1) { minus++; } ; if (onevalue == 0) { zero++; } ; } double sd = Math.sqrt(sumofdiff / count.get(key)); // mydataset.add(point/factor, value,value+sd,value-sd); // mydataset.add(point/factor, value,value,value); mydataset.add( point / factor, value, value + 1.96 * (sd / Math.sqrt(count.get(key))), value - 1.96 * (sd / Math.sqrt(count.get(key)))); } double sdtotal = 0; double avgsd = total / sdcount; double test = 0; for (Double onevalue : totalvalues) { sdtotal += Math.pow(Math.pow(onevalue, 2) - (total / sdcount), 2); test += onevalue; } // System.out.println(rowname+" mean square: "+avgsd+" // +/-95%:"+1.96*Math.sqrt(sdtotal/sdcount)/Math.sqrt(sdcount)); // System.out.println("total -1:"+minus+" total +1:"+plus+" zero: "+zero // +" total:"+sdcount); return mydataset; }
public static MiningResult importFile(InputStream input) throws IOException { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document doc; // NodeList netNodes; dbf.setValidating(false); dbf.setIgnoringComments(true); dbf.setIgnoringElementContentWhitespace(true); // dbf.setExpandEntityReferences(false); // dbf.setNamespaceAware(false); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver( new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if (systemId.indexOf("ARIS-Export") != -1) { return new InputSource("file:" + About.EXTLIBLOCATION() + "ARIS-Export101.dtd"); } else { return null; } } }); InputSource inpStream = new InputSource(input); inpStream.setSystemId("file:" + System.getProperty("user.dir", "")); doc = db.parse(inpStream); // check if root element is a aml tag Message.add("parsing done" + doc, Message.DEBUG); if (!(doc.getDocumentElement().getNodeName().equals("AML"))) { Message.add("aml tag not found", Message.ERROR); throw new Exception("aml tag not found"); } else { Message.add("aml root element found"); } EPCResult result = new EPCResult(null, (EPC) null); HashMap ObjDef_LinkId = new HashMap(); HashMap modelid_net = new HashMap(); HashMap ObjDef_Name = new HashMap(); HashMap function_LinkId = new HashMap(); HashMap ModelId_ModelType = new HashMap(); traverseAMLforObjectNames( ObjDef_Name, doc.getDocumentElement(), ObjDef_LinkId, ModelId_ModelType); Iterator findLinkToEpc = ObjDef_LinkId.keySet().iterator(); while (findLinkToEpc.hasNext()) { String currentObjDef = (String) findLinkToEpc.next(); String Links = (String) ObjDef_LinkId.get(currentObjDef); StringTokenizer linkSet = new StringTokenizer(Links); String realEpcLink = ""; while (linkSet.hasMoreTokens()) { String currentLink = linkSet.nextToken(); if (ModelId_ModelType.get(currentLink).equals("MT_EEPC")) { realEpcLink = currentLink; break; } } if (realEpcLink.equals(" ")) { ObjDef_LinkId.remove(currentObjDef); } else { ObjDef_LinkId.put(currentObjDef, realEpcLink); } } result = traverseAML( result, doc.getDocumentElement(), null, ObjDef_Name, ObjDef_LinkId, modelid_net, function_LinkId); Iterator hierarchicalFunctions = function_LinkId.keySet().iterator(); while (hierarchicalFunctions.hasNext()) { EPCSubstFunction f = (EPCSubstFunction) hierarchicalFunctions.next(); f.setSubstitutedEPC((EPC) modelid_net.get(function_LinkId.get(f))); // Message.add(f.getSubstitutedEPC().getName()); } return result; } catch (Throwable x) { Message.add(x.toString()); throw new IOException(x.getMessage()); } }
public static PetriNet convert(ConfigurableEPC baseEPC) { HashMap<EPCFunction, Transition> functionActivityMapping; HashMap<EPCConnector, Place> xorconnectorChoiceMapping; // HV: Initialize the mappings. functionActivityMapping = new HashMap<EPCFunction, Transition>(); xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>(); // Check to use the weights if necessary // HV: Add both mappings. On completion, these will be filledd. PetriNet petrinet = EPCToPetriNetConverter.convert( baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping); HashSet visible = new HashSet(); // HV: The next block is taken care of by the functionActivityMapping // below. /* * Iterator it = petrinet.getTransitions().iterator(); while * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add * transitions with LogEvent (i.e. referring to functions) * visible.add(t); } } */ // HV: Prevent the places mapped onto from being reduced. visible.addAll(functionActivityMapping.values()); visible.addAll(xorconnectorChoiceMapping.values()); Message.add(visible.toString(), Message.DEBUG); Iterator it = petrinet.getPlaces().iterator(); while (it.hasNext()) { Place p = (Place) it.next(); if (p.inDegree() * p.outDegree() == 0) { // Add Initial and final places to visible, i.e. places that // refer to in and output events visible.add(p); } } // Reduce the PetriNet with Murata rules, while keeping the visible ones PetriNetReduction pnred = new PetriNetReduction(); pnred.setNonReducableNodes(visible); HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to // post-reduction nodes. PetriNet reduced = pnred.reduce(petrinet, pnMap); if (reduced != petrinet) { // Update both mappings from pre-reduction nodes to post-reduction // nodes. HashMap<EPCFunction, Transition> newFunctionActivityMapping = new HashMap<EPCFunction, Transition>(); for (EPCFunction function : functionActivityMapping.keySet()) { Transition transition = (Transition) functionActivityMapping.get(function); if (pnMap.keySet().contains(transition)) { newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition)); } } functionActivityMapping = newFunctionActivityMapping; HashMap<EPCConnector, Place> newXorconnectorChoiceMapping = new HashMap<EPCConnector, Place>(); for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) { Place place = (Place) xorconnectorChoiceMapping.get(connector); if (pnMap.keySet().contains(place)) { newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place)); } } xorconnectorChoiceMapping = newXorconnectorChoiceMapping; } reduced.makeClusters(); // filter the \nunknown:normal ArrayList<Transition> alTrans = reduced.getVisibleTasks(); for (int i = 0; i < alTrans.size(); i++) { Transition t = alTrans.get(i); String id = t.getIdentifier(); int idx = id.indexOf("\\nunknown:normal"); if (idx > 0) { id = id.substring(0, idx); } // �˴������ֵ��ѯ�滻���е�label String mappedId = htDict.get(id); if (mappedId != null) { t.setIdentifier(mappedId); } else { t.setIdentifier(id); } } return reduced; }
private static void parseNet( Node node, EPC net, HashMap ObjDef_Name, HashMap ObjDef_LinkId, HashMap function_LinkId, String ModelName) throws Exception { HashMap mapping = new HashMap(); // read all nodes NodeList nodes = node.getChildNodes(); net.setIdentifier(ModelName); // Message.add("here I am still happy"); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (!n.getNodeName().equals("ObjOcc")) { continue; } if (n.getAttributes().getNamedItem("SymbolNum") == null) { continue; } String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue(); if (!(symbolnum.equals("ST_FUNC") || symbolnum.equals("ST_EV") || symbolnum.equals("ST_OPR_AND_1") || symbolnum.equals("ST_OPR_OR_1") || symbolnum.equals("ST_OPR_XOR_1"))) { continue; } String ObjDef = n.getAttributes().getNamedItem("ObjDef.IdRef").getNodeValue(); String ownName = (String) ObjDef_Name.get(ObjDef); // Message.add("YES " + // n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue()); String id = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue(); // Message.add(id + " " + ownName); if (ownName == null || ownName == "") { ownName = id.substring(7, 11); } if (symbolnum.equals("ST_FUNC")) { if (ObjDef_LinkId.containsKey(ObjDef)) { EPCSubstFunction sf = (EPCSubstFunction) net.addFunction( new EPCSubstFunction(new LogEvent(ownName, "unknown:normal"), net, null)); sf.setIdentifier(ownName); mapping.put(id, sf); function_LinkId.put(sf, ObjDef_LinkId.get(ObjDef)); } else { EPCFunction f = net.addFunction(new EPCFunction(new LogEvent(ownName, "unknown:normal"), net)); f.setIdentifier(ownName); mapping.put(id, f); } } else if (symbolnum.equals("ST_EV")) { EPCEvent e = net.addEvent(new EPCEvent(ownName, net)); e.setIdentifier(ownName); mapping.put(id, e); } else if (symbolnum.equals("ST_OPR_AND_1")) { EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net)); mapping.put(id, c); } else if (symbolnum.equals("ST_OPR_OR_1")) { // EPCConnector c = net.addConnector(new // EPCConnector(EPCConnector.OR, net)); EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.AND, net)); mapping.put(id, c); } else if (symbolnum.equals("ST_OPR_XOR_1")) { EPCConnector c = net.addConnector(new EPCConnector(EPCConnector.XOR, net)); mapping.put(id, c); } } for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (!n.getNodeName().equals("ObjOcc")) { continue; } if (n.getAttributes().getNamedItem("SymbolNum") == null) { continue; } String symbolnum = n.getAttributes().getNamedItem("SymbolNum").getNodeValue(); if (!(symbolnum.equals("ST_FUNC") || symbolnum.equals("ST_EV") || symbolnum.equals("ST_OPR_AND_1") || symbolnum.equals("ST_OPR_OR_1") || symbolnum.equals("ST_OPR_XOR_1"))) { continue; } String source = n.getAttributes().getNamedItem("ObjOcc.ID").getNodeValue(); if (n.hasChildNodes()) { for (int j = 0; j < n.getChildNodes().getLength(); j++) { if (n.getChildNodes().item(j).getNodeName().equals("CxnOcc")) { Node CxnOcc = n.getChildNodes().item(j); String dest = CxnOcc.getAttributes().getNamedItem("ToObjOcc.IdRef").getNodeValue(); if (mapping.get(dest) == null) { continue; } if (net.addEdge((EPCObject) mapping.get(source), (EPCObject) mapping.get(dest)) == null) { throw (new Exception( "<html>Structural properties of EPCs are violated in input file.<br>" + "The following edge could not be added:<br><br>" + mapping.get(source).toString() + " ==> " + mapping.get(dest).toString() + "<br><br>Import aborted.</html>")); } } } } } }
public static EPCResult traverseAML( EPCResult partialResult, Node currentNode, Object parent, HashMap ObjDef_Name, HashMap ObjDef_LinkId, HashMap modelid_net, HashMap function_LinkId) throws Exception { if (currentNode.hasChildNodes()) { for (int i = 0; i < currentNode.getChildNodes().getLength(); i++) { Node currentChild = currentNode.getChildNodes().item(i); if (currentChild.getNodeName().equals("Group")) { String id = currentChild.getAttributes().getNamedItem("Group.ID").getNodeValue(); String GroupName = ""; if (currentChild.hasChildNodes()) { NodeList currentChildren = currentChild.getChildNodes(); for (int j = 0; j < currentChildren.getLength(); j++) { Node Child = currentChildren.item(j); if (!(Child.getNodeName().equals("AttrDef"))) { continue; } if (Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { GroupName = getTextContent(Child.getChildNodes().item(l)); } } break; } } } if (GroupName.equals("")) { GroupName = id; } } ModelHierarchyDirectory dir = new ModelHierarchyDirectory(id, GroupName); partialResult.addInHierarchy(dir, parent, GroupName); partialResult = traverseAML( partialResult, currentChild, dir, ObjDef_Name, ObjDef_LinkId, modelid_net, function_LinkId); } if (currentChild.getNodeName().equals("Model") && currentChild .getAttributes() .getNamedItem("Model.Type") .getNodeValue() .equals("MT_EEPC")) { String ModelName = "gaga"; if (currentChild.hasChildNodes()) { NodeList currentChildren = currentChild.getChildNodes(); for (int j = 0; j < currentChildren.getLength(); j++) { Node Child = currentChildren.item(j); if (!(Child.getNodeName().equals("AttrDef"))) { continue; } if (Child.getAttributes() .getNamedItem("AttrDef.Type") .getNodeValue() .equals("AT_NAME")) { if (Child.hasChildNodes()) { for (int l = 0; l < Child.getChildNodes().getLength(); l++) { if (!(Child.getChildNodes().item(l).getNodeName().equals("AttrValue"))) { continue; } else { ModelName = getTextContent(Child.getChildNodes().item(l)); } } } break; } } } try { ModelName = ModelName.replaceAll("\n", " "); EPC net = read(currentChild, ObjDef_Name, ObjDef_LinkId, function_LinkId, ModelName); partialResult.addInHierarchy(net, parent, ModelName); modelid_net.put( currentChild.getAttributes().getNamedItem("Model.ID").getNodeValue(), net); } catch (Throwable x) { Message.add(x.getClass().getName()); // throw new IOException(x.getMessage()); } } } } return partialResult; }