Update trunk for MC 1.6.3, and some work on re-jigging the weighted
directed graph. THIS WILL NOT BUILD SUCCESSFULLY OR RUN IN ITS CURRENT STATE. VERY BROKEN ATM.
This commit is contained in:
parent
0a5db4c0ca
commit
9b5584cf28
|
@ -1,5 +1,5 @@
|
|||
#Tue, 17 Sep 2013 20:27:04 -0400
|
||||
minecraft_version=1.6.2
|
||||
forge_version=9.10.1.871
|
||||
minecraft_version=1.6.3
|
||||
forge_version=9.11.0.878
|
||||
mod_version=pre2a
|
||||
build_number=26
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package com.pahimar.ee3.emc.graph;
|
||||
|
||||
import com.pahimar.ee3.core.util.LogHelper;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
|
||||
public class DepthFirstSearchTraversal {
|
||||
|
||||
public static WeightedDirectedGraph<CustomWrappedStack> spanningTree = new WeightedDirectedGraph<CustomWrappedStack>();
|
||||
|
||||
public static void executeDFS(WeightedDirectedGraph<CustomWrappedStack> graph, CustomWrappedStack node) {
|
||||
|
||||
// Label node as discovered
|
||||
if (!spanningTree.containsNode(node)) {
|
||||
spanningTree.addNode(node);
|
||||
}
|
||||
|
||||
LogHelper.debug("Node: " + node);
|
||||
LogHelper.debug("To :" + graph.edgesTo(node));
|
||||
LogHelper.debug("From: " + graph.edgesFrom(node));
|
||||
for (WeightedEdge<CustomWrappedStack> edgeToNode : graph.edgesTo(node)) {
|
||||
LogHelper.debug("To iteration: " + edgeToNode);
|
||||
|
||||
if (!spanningTree.containsNode(edgeToNode.target)) {
|
||||
spanningTree.addNode(edgeToNode.target);
|
||||
}
|
||||
|
||||
if (!spanningTree.containsWeightedEdge(edgeToNode.target, node, edgeToNode.weight)) {
|
||||
spanningTree.addEdge(edgeToNode.target, node, edgeToNode.weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
common/com/pahimar/ee3/emc/graph/Node.java
Normal file
64
common/com/pahimar/ee3/emc/graph/Node.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package com.pahimar.ee3.emc.graph;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
* Node
|
||||
*
|
||||
* @author pahimar
|
||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
|
||||
|
||||
public enum NodeTraversalStatus {
|
||||
UNDISCOVERED, DISCOVERED
|
||||
}
|
||||
|
||||
public final T nodeObject;
|
||||
public NodeTraversalStatus traversalState;
|
||||
|
||||
public Node(T nodeObject) {
|
||||
|
||||
this.nodeObject = nodeObject;
|
||||
traversalState = NodeTraversalStatus.UNDISCOVERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
|
||||
if (!(object instanceof Node<?>)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node<?> node = (Node<?>) object;
|
||||
|
||||
return this.traversalState == node.traversalState && this.nodeObject.equals(node.nodeObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Node<T> node) {
|
||||
|
||||
if (node instanceof Node && node.nodeObject instanceof Comparable<?>) {
|
||||
if (this.nodeObject instanceof Comparable<?>) {
|
||||
return this.nodeObject.compareTo(node.nodeObject);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return nodeObject.toString();
|
||||
}
|
||||
}
|
|
@ -10,7 +10,9 @@ import com.google.common.collect.ImmutableList;
|
|||
|
||||
public class WeightedDirectedGraph<T extends Comparable<T>> implements Iterable<T> {
|
||||
|
||||
private final Map<T, SortedSet<WeightedEdge<T>>> graph = new HashMap<T, SortedSet<WeightedEdge<T>>>();
|
||||
// FIXME This whole class should be considered very broken right now, as it needs to be adjusted now that we are wrapping objects into Nodes
|
||||
|
||||
private final Map<Node<T>, SortedSet<WeightedEdge<T>>> graph = new HashMap<Node<T>, SortedSet<WeightedEdge<T>>>();
|
||||
|
||||
public boolean addNode(T node) {
|
||||
|
||||
|
@ -18,7 +20,7 @@ public class WeightedDirectedGraph<T extends Comparable<T>> implements Iterable<
|
|||
return false;
|
||||
}
|
||||
|
||||
graph.put(node, new TreeSet<WeightedEdge<T>>());
|
||||
graph.put(new Node<T>(node), new TreeSet<WeightedEdge<T>>());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,21 +2,28 @@ package com.pahimar.ee3.emc.graph;
|
|||
|
||||
public class WeightedEdge<T extends Comparable<T>> implements Comparable<WeightedEdge<T>> {
|
||||
|
||||
public enum EdgeTraversalStatus { UNDISCOVERED, DISCOVERY_EDGE, BACK_EDGE }
|
||||
|
||||
public final float weight;
|
||||
public final T target;
|
||||
public EdgeTraversalStatus edgeTraversalStatus;
|
||||
|
||||
public WeightedEdge(T target) {
|
||||
|
||||
this(target, 1);
|
||||
public enum EdgeTraversalStatus {
|
||||
UNDISCOVERED, DISCOVERY_EDGE, BACK_EDGE
|
||||
}
|
||||
|
||||
public WeightedEdge(T target, float weight) {
|
||||
public final float weight;
|
||||
public final Node<T> targetNode;
|
||||
public EdgeTraversalStatus edgeTraversalStatus;
|
||||
|
||||
public WeightedEdge(T nodeObject) {
|
||||
|
||||
this(nodeObject, 1);
|
||||
}
|
||||
|
||||
public WeightedEdge(T nodeObject, float weight) {
|
||||
|
||||
this(new Node<T>(nodeObject), weight);
|
||||
}
|
||||
|
||||
public WeightedEdge(Node<T> targetNode, float weight) {
|
||||
|
||||
this.weight = weight;
|
||||
this.target = target;
|
||||
this.targetNode = targetNode;
|
||||
this.edgeTraversalStatus = EdgeTraversalStatus.UNDISCOVERED;
|
||||
}
|
||||
|
||||
|
@ -29,7 +36,9 @@ public class WeightedEdge<T extends Comparable<T>> implements Comparable<Weighte
|
|||
|
||||
WeightedEdge<?> edge = (WeightedEdge<?>) object;
|
||||
|
||||
return (Float.compare(this.weight, edge.weight) == 0) && target.equals(edge.target);
|
||||
return (Float.compare(this.weight, edge.weight) == 0) &&
|
||||
(this.edgeTraversalStatus == edge.edgeTraversalStatus) &&
|
||||
targetNode.equals(edge.targetNode);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -41,7 +50,7 @@ public class WeightedEdge<T extends Comparable<T>> implements Comparable<Weighte
|
|||
|
||||
if (weightedEdge instanceof WeightedEdge) {
|
||||
if (Float.compare(this.weight, weightedEdge.weight) == 0) {
|
||||
return this.target.compareTo(weightedEdge.target);
|
||||
return this.targetNode.compareTo(weightedEdge.targetNode);
|
||||
}
|
||||
else {
|
||||
return Float.compare(this.weight, weightedEdge.weight);
|
||||
|
@ -57,7 +66,7 @@ public class WeightedEdge<T extends Comparable<T>> implements Comparable<Weighte
|
|||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(String.format("Target: %s, Weight: %s", target, weight));
|
||||
stringBuilder.append(String.format("Target: %s, Weight: %s", targetNode, weight));
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue