Some more DynEMC work - lots still to do!

This commit is contained in:
pahimar 2013-06-03 13:06:13 -04:00
parent e2b9869c0e
commit 27fab71f64
3 changed files with 78 additions and 20 deletions

View file

@ -149,7 +149,7 @@ public class EquivalentExchange3 {
// Initialize custom rendering and pre-load textures (Client only)
proxy.initRenderingAndTextures();
// Load the Transmutation Stone recipes
//RecipesTransmutationStone.init();
@ -166,7 +166,7 @@ public class EquivalentExchange3 {
// Initialize the Addon Handler
AddonHandler.init();
// Initialize the DynEMC system
DynEMC dynEMC = DynEMC.getInstance();
}

View file

@ -56,6 +56,7 @@ public class DynEMC {
}
private void populateItemList() {
ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
/*
@ -148,9 +149,9 @@ public class DynEMC {
}
}
}
private void populateGraph() {
for (CustomWrappedStack customWrappedStack : discoveredItems) {
ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(customWrappedStack);
@ -158,13 +159,13 @@ public class DynEMC {
for (IRecipe recipe : recipes) {
ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getCollatedRecipeInputs(recipe);
for (CustomWrappedStack wrappedRecipeInput : recipeInputs) {
float weight = wrappedRecipeInput.getStackSize();
CustomWrappedStack recipeInput = null;
if (wrappedRecipeInput.getItemStack() != null) {
ItemStack itemStack = wrappedRecipeInput.getItemStack();
@ -192,12 +193,60 @@ public class DynEMC {
}
}
@Override
// TODO Make this an actual toString and take out the logging into a debug method
public String toString() {
public int size() {
return graph.size();
}
public List<CustomWrappedStack> getAllNodes() {
ArrayList<CustomWrappedStack> allNodes = new ArrayList<CustomWrappedStack>();
Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
allNodes.add(nodeIter.next());
}
return allNodes;
}
public List<CustomWrappedStack> getCriticalNodes() {
ArrayList<CustomWrappedStack> criticalNodes = new ArrayList<CustomWrappedStack>();
Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
CustomWrappedStack currentNode = nodeIter.next();
if (graph.edgesFrom(currentNode).size() == 0) {
criticalNodes.add(currentNode);
}
}
return criticalNodes;
}
public List<CustomWrappedStack> getOrphanNodes() {
ArrayList<CustomWrappedStack> criticalNodes = new ArrayList<CustomWrappedStack>();
Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
CustomWrappedStack currentNode = nodeIter.next();
if ((graph.edgesFrom(currentNode).size() == 0) && (graph.edgesTo(currentNode).size() == 0)) {
criticalNodes.add(currentNode);
}
}
return criticalNodes;
}
public void printDebugDump() {
StringBuilder stringBuilder = new StringBuilder();
LogHelper.log(Level.INFO, "***** START NODES *****");
Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
@ -205,7 +254,7 @@ public class DynEMC {
LogHelper.log(Level.INFO, "Node: " + node);
}
LogHelper.log(Level.INFO, "***** END NODES *****");
LogHelper.log(Level.INFO, "***** START EDGES FROM *****");
nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
@ -219,7 +268,7 @@ public class DynEMC {
}
}
LogHelper.log(Level.INFO, "***** END EDGES FROM *****");
LogHelper.log(Level.INFO, "***** START EDGES TO *****");
nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
@ -235,6 +284,14 @@ public class DynEMC {
}
}
LogHelper.log(Level.INFO, "***** END EDGES TO *****");
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("DynEMC Node Count: %s", graph.size()));
return stringBuilder.toString();
}

View file

@ -119,6 +119,7 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
Set<WeightedEdge<T>> edgesTo = new TreeSet<WeightedEdge<T>>(new Comparator<WeightedEdge<T>>() {
public int compare(WeightedEdge<T> o1, WeightedEdge<T> o2) {
return o1.hashCode() - o2.hashCode();
}
});
@ -126,7 +127,7 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
for (T node : graph.keySet()) {
if (!node.equals(to)) {
Set<WeightedEdge<T>> edgesFrom = edgesFrom(node);
for (WeightedEdge<T> fromEdge : edgesFrom) {
if (fromEdge.getTarget().equals(to)) {
edgesTo.add(new WeightedEdge<T>(fromEdge.getWeight(), node));
@ -137,17 +138,17 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
return Collections.unmodifiableSet(edgesTo);
}
public void removeNode(T node) {
if (!(graph.containsKey(node))) {
throw new NoSuchElementException("Missing node from graph");
}
// Remove all edges from and to the node
removeAllEdgesFrom(node);
removeAllEdgesTo(node);
// Remove the node
graph.remove(node);
}
@ -174,7 +175,7 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
graph.get(node).clear();
}
public void removeAllEdgesTo(T node) {
if (!(graph.containsKey(node))) {