private GeneratorNode generateNode() { HashSet<GeneratorNode> spawnedNodes; HashSet<GeneratorNode> newNodes = new HashSet<GeneratorNode>(); int size = 0, atoms = 0; long timeBegin = Stopwatch.GetTimestamp(); // Takes each node and applies its decomposition foreach (GeneratorNode wn in m_nodes) { GeneratorNode wn2 = new GeneratorNode(); wn2.setGamma(wn.getDelta()); spawnedNodes = wn2.spawn(); foreach (GeneratorNode gn in spawnedNodes) { newNodes.Add(gn); } // Shortcut: as soon as one branch returns something, we skip the others if (spawnedNodes.Count > 0) { break; } } long timeEnd = Stopwatch.GetTimestamp(); System.Console.WriteLine("Finished producing the " + newNodes.Count + "nodes " + (timeEnd - timeBegin)); timeBegin = Stopwatch.GetTimestamp(); // Remember the new nodes m_nodes = newNodes; // Updates statistics about maximum number of nodes size = m_nodes.Count; if (size > m_maxNodes) { m_maxNodes = size; } // Updates statistics about total number of formulae size = 0; atoms = 0; foreach (GeneratorNode wn in m_nodes) { size += wn.getSize(); atoms += wn.getAtoms(); } if (size > m_maxFormulae) { m_maxFormulae = size; } if (atoms > m_maxAtoms) { m_maxAtoms = atoms; } // We remove nodes that don't contain any OPlus // (i.e., that don't tell us to do anything) // and check at the same time if at least one node is sound bool hasSound = false; foreach (GeneratorNode wn in m_nodes) { HashSet<OPlus> opluses = wn.getOPluses(); bool contains_element = false; foreach (OPlus op in opluses) { // Remove conditions that only assert path existence if (!op.getOperand().Equals(Operator.m_falseAtom) && !op.getOperand().Equals(Operator.m_trueAtom)) { contains_element = true; } } if (!contains_element) { m_nodes.Remove(wn); } else { if (wn.Sound) { hasSound = true; } } } // Can we produce a new message? if (m_nodes.Count == 0) { // No! return null; } // We remove all nodes whose OPluses are contradictory /*it = m_nodes.iterator(); while (it.hasNext()) { GeneratorNode wn = it.next(); if (wn.containsOPlusContradiction()) it.remove(); }*/ // Is there at least one remaining sound node? if (hasSound) { // Yes: then let's remove any unsound node foreach (GeneratorNode wn in m_nodes) { if (!wn.Sound) { m_nodes.Remove(wn); } } } timeEnd = Stopwatch.GetTimestamp(); System.Console.WriteLine("Finished pruning " + (timeEnd - timeBegin)); // Pick *one* of the nodes randomly long pickIndex = (long)System.Math.Round(new System.Random().NextDouble() * (double)(m_nodes.Count - 1)); int i = 0; GeneratorNode pickedNode = null; foreach (GeneratorNode gn in m_nodes) { if (i == pickIndex) { pickedNode = gn; break; } i++; } // Keep only the selected node for the next state m_nodes = new HashSet<GeneratorNode>(); m_nodes.Add(pickedNode); // Return the picked node return pickedNode; }