fix byproducts
parent
db063345c5
commit
ef9209681c
|
|
@ -13,6 +13,8 @@ import java.io.File;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static items.Utils.plot2;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) throws JsonProcessingException {
|
||||
//System.out.println(items.Database.AdaptiveControlUnit);
|
||||
|
|
@ -73,16 +75,19 @@ public class Test {
|
|||
|
||||
plot2(Utils.merge(screws100, computers100), "merged");
|
||||
|
||||
}
|
||||
System.out.println("\n\nPHASE 3");
|
||||
Graph<Item, ProductionEdge> phase3;
|
||||
//phase3 = Utils.sum(Database.VersatileFrameWork, 2500);
|
||||
//phase3 = Utils.merge(phase3, Utils.sum(Database.ModularEngine,500));
|
||||
phase3 = Utils.sum(Database.ModularEngine,5);
|
||||
phase3 = Utils.merge(phase3, Utils.sum(Database.AdaptiveControlUnit, 1));
|
||||
|
||||
plot2(phase3, "phase3");
|
||||
System.out.println("\nrubber");
|
||||
plot2(Utils.sum(Database.Rubber, 75),"rubber");
|
||||
System.out.println("\ntest");
|
||||
Utils.sum(Database.Plastic, 4);
|
||||
|
||||
private static void plot2(Graph<Item, ProductionEdge> sum, String filename) {
|
||||
DOTExporter<Item,ProductionEdge> de = new DOTExporter<>(Item::ID);
|
||||
de.setEdgeAttributeProvider(productionEdge -> {
|
||||
Map<String, Attribute> m = new HashMap<>();
|
||||
m.put("label", DefaultAttribute.createAttribute(productionEdge.label()));
|
||||
return m;
|
||||
});
|
||||
de.exportGraph(sum, new File(filename+".dot"));
|
||||
}
|
||||
|
||||
private static void plot(Item target, String name, int amount, DOTExporter<Item, DefaultWeightedEdge> de) {
|
||||
|
|
|
|||
|
|
@ -369,6 +369,9 @@ public class Database {
|
|||
Plastic.add(residualPlastic, 2);
|
||||
|
||||
Plastic.setPreference(recipe);
|
||||
|
||||
HeavyOilResidue.add(recipe);
|
||||
HeavyOilResidue.setPreference(recipe);
|
||||
}
|
||||
{
|
||||
// Rubber
|
||||
|
|
@ -382,6 +385,8 @@ public class Database {
|
|||
Rubber.add(residualRubber, 2);
|
||||
|
||||
Rubber.setPreference(recipe);
|
||||
|
||||
HeavyOilResidue.add(recipe);
|
||||
}
|
||||
{
|
||||
// Petroleum Coke
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ import org.jgrapht.Graphs;
|
|||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Recipe {
|
||||
|
|
@ -201,9 +198,15 @@ public class Recipe {
|
|||
.forEach(queue::add);
|
||||
// *this* item
|
||||
double sum = 0;
|
||||
Set<Item> byProducts = new HashSet<>();
|
||||
for (DefaultWeightedEdge edge : buildGraph.outgoingEdgesOf(item)) {
|
||||
Item product = buildGraph.getEdgeTarget(edge);
|
||||
Double productWantedPerMinute = map.get(product);
|
||||
if (item.getRecipe().outputs.containsKey(product)){
|
||||
// product is by-product, no forward dependency
|
||||
byProducts.add(product);
|
||||
continue;
|
||||
}
|
||||
if (productWantedPerMinute == null) {
|
||||
sum = 0;
|
||||
break;
|
||||
|
|
@ -216,11 +219,17 @@ public class Recipe {
|
|||
|
||||
production.addVertex(item);
|
||||
production.addEdge(item, product, new ProductionEdge(item, requiredInput, processesNeeded(item, requiredInput)));
|
||||
|
||||
}
|
||||
if (!map.containsKey(item) && sum > 0) {
|
||||
map.put(item, sum);
|
||||
}
|
||||
if (!byProducts.isEmpty()) {
|
||||
byProducts.forEach(item1 -> {
|
||||
production.addVertex(item1);
|
||||
// TODO: calculate produced amount
|
||||
production.addEdge(item, item1, new ProductionEdge(item, 0,0));
|
||||
});
|
||||
}
|
||||
}
|
||||
map.forEach((item, aDouble) -> {
|
||||
System.out.println(item.getName() + ": " + aDouble);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package items;
|
||||
|
||||
import items.type.Ore;
|
||||
import org.jgrapht.Graph;
|
||||
import org.jgrapht.event.ConnectedComponentTraversalEvent;
|
||||
import org.jgrapht.event.EdgeTraversalEvent;
|
||||
|
|
@ -8,9 +9,13 @@ import org.jgrapht.event.VertexTraversalEvent;
|
|||
import org.jgrapht.graph.DefaultDirectedWeightedGraph;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import org.jgrapht.graph.EdgeReversedGraph;
|
||||
import org.jgrapht.nio.Attribute;
|
||||
import org.jgrapht.nio.DefaultAttribute;
|
||||
import org.jgrapht.nio.dot.DOTExporter;
|
||||
import org.jgrapht.traverse.DepthFirstIterator;
|
||||
import org.jgrapht.traverse.GraphIterator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -104,4 +109,25 @@ public class Utils {
|
|||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Graph<Item, ProductionEdge> sum(Item item, int amount) {
|
||||
return item.getRecipe().sum(item,amount);
|
||||
}
|
||||
|
||||
public static void plot2(Graph<Item, ProductionEdge> sum, String filename) {
|
||||
DOTExporter<Item,ProductionEdge> de = new DOTExporter<>(Item::ID);
|
||||
de.setEdgeAttributeProvider(productionEdge -> {
|
||||
Map<String, Attribute> m = new HashMap<>();
|
||||
m.put("label", DefaultAttribute.createAttribute(productionEdge.label()));
|
||||
return m;
|
||||
});
|
||||
de.setVertexAttributeProvider(item -> {
|
||||
Map<String,Attribute> m = new HashMap<>();
|
||||
if (item.isRaw()) {
|
||||
m.put("peripheries", DefaultAttribute.createAttribute(2));
|
||||
}
|
||||
return m;
|
||||
});
|
||||
de.exportGraph(sum, new File(filename+".dot"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue