From b04b88f4d4147ec7c18eea720fdbe50f0b7213b6 Mon Sep 17 00:00:00 2001 From: pahimar Date: Wed, 3 Jul 2013 20:31:07 -0400 Subject: [PATCH] Move around some stuff --- ee3_common/com/pahimar/ee3/emc/DynEMC.java | 46 +++++++++++++++++-- .../ee3/emc/graph/WeightedDirectedGraph.java | 6 ++- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/emc/DynEMC.java b/ee3_common/com/pahimar/ee3/emc/DynEMC.java index 3a4a2783..6dec502a 100644 --- a/ee3_common/com/pahimar/ee3/emc/DynEMC.java +++ b/ee3_common/com/pahimar/ee3/emc/DynEMC.java @@ -1,8 +1,10 @@ package com.pahimar.ee3.emc; import java.util.Iterator; +import java.util.List; import java.util.Set; +import com.google.common.collect.Multimap; import com.pahimar.ee3.core.util.LogHelper; import com.pahimar.ee3.emc.graph.WeightedDirectedGraph; import com.pahimar.ee3.emc.graph.WeightedEdge; @@ -13,10 +15,12 @@ public class DynEMC { private static DynEMC dynEMC = null; + private RecipeRegistry recipeRegistry; private WeightedDirectedGraph graph; private DynEMC() { + recipeRegistry = RecipeRegistry.getInstance(); graph = new WeightedDirectedGraph(); init(); @@ -32,15 +36,40 @@ public class DynEMC { } private void init() { - - @SuppressWarnings("unused") - RecipeRegistry recipeManager = RecipeRegistry.getInstance(); populateGraph(); + //printDebugDump(); } private void populateGraph() { - + + for (CustomWrappedStack discoveredStack : recipeRegistry.getDiscoveredStacks()) { + graph.addNode(discoveredStack); + } + + Multimap> recipeMappings = recipeRegistry.getRecipeMappings(); + + Set recipeKeySet = recipeMappings.keySet(); + Iterator recipeKeySetIterator = recipeKeySet.iterator(); + CustomWrappedStack recipeOutput = null; + + while (recipeKeySetIterator.hasNext()) { + recipeOutput = recipeKeySetIterator.next(); + + for (List recipeInputs : recipeMappings.get(recipeOutput)) { + for (CustomWrappedStack recipeInput : recipeInputs) { + + // Unwrapped the wrapped stacks so that we actually find them in the graph + CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack()); + CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); + + if (recipeOutput.getStackSize() != 0) { + + graph.addEdge(unWrappedRecipeOutput, unWrappedRecipeInput, (recipeInput.getStackSize() * 1.0f) / recipeOutput.getStackSize()); + } + } + } + } } public int size() { @@ -50,6 +79,15 @@ public class DynEMC { public void printDebugDump() { + LogHelper.debug("Total node count: " + graph.getAllNodes().size()); + LogHelper.debug("Critical node count: " + graph.getCriticalNodes().size()); + LogHelper.debug("Orphan node count: " + graph.getOrphanNodes().size()); + + List critsMinusOrphans = graph.getCriticalNodes(); + critsMinusOrphans.removeAll(graph.getOrphanNodes()); + + LogHelper.debug("[Critical - Orphans] node count: " + critsMinusOrphans.size()); + LogHelper.debug("***** START NODES *****"); Iterator nodeIter = graph.iterator(); while (nodeIter.hasNext()) { diff --git a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java index 38af9007..1cb586c7 100644 --- a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java +++ b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java @@ -13,6 +13,8 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.logging.Logger; +import com.pahimar.ee3.core.util.LogHelper; + public class WeightedDirectedGraph implements Iterable { private final Map>> graph = new HashMap>>(); @@ -46,10 +48,10 @@ public class WeightedDirectedGraph implements Iterable { if (!(graph.containsKey(from) && graph.containsKey(to))) { if (!graph.containsKey(from)) { - LOGGER.severe("From node doesn't exist: " + from.toString()); + LogHelper.severe("From node doesn't exist: " + from.toString()); } if (!graph.containsKey(to)) { - LOGGER.severe("To node doesn't exist: " + to.toString()); + LogHelper.severe("To node doesn't exist: " + to.toString()); } throw new NoSuchElementException("Missing nodes from graph"); }