public void populate(ArrayList<BinaryGraph> bGraphs) { for (int index = 0; index < bGraphs.size(); index++) { BinaryGraph bGraph = new BinaryGraph(); bGraph.copyAndLink(bGraphs.get(index)); this.addGoalPart(bGraph); } }
public void collapse() { ArrayList<BinaryGraph> subgraphs = null; for (int index = 0; index < _goalParts.size(); index++) { BinaryGraph goalPart = _goalParts.get(index); if (subgraphs == null) { subgraphs = goalPart.getSubgraphs(new ArrayList<BinaryGraph>()); continue; } else { ArrayList<BinaryGraph> tempSubtrees = goalPart.getSubgraphs(subgraphs); for (int tempIndex = 0; tempIndex < tempSubtrees.size(); tempIndex++) { BinaryGraph tempGraph = tempSubtrees.get(tempIndex); if (subgraphs.contains(tempGraph)) { // Determine if tempGraph is lefty or righty BinaryGraph parent = tempGraph.getParent(0); if (parent == null) { // TODO: decide what to do if parent does not exist } else if (parent.getLeft().equals(tempGraph)) { parent.setLeft(subgraphs.get(subgraphs.indexOf(tempGraph))); } else { parent.setRight(subgraphs.get(subgraphs.indexOf(tempGraph))); } } else { subgraphs.add(tempGraph); subgraphs = sortList(subgraphs); } } } } calculateStagesSteps(); }
private int traverse(BinaryGraph graph) { if (graph.getLeft() == null && graph.getRight() == null) { return 0; } if (!_visited.contains(graph)) { _visited.add(graph); if (graph.getLeft() != null && graph.getRight() != null) { _steps++; } } return Math.max(traverse(graph.getLeft()), traverse(graph.getRight())) + 1; }