checkpoint
This commit is contained in:
35
main.py
35
main.py
@@ -29,15 +29,13 @@ def _slugify(name: str) -> str:
|
||||
prev_us = False
|
||||
return ''.join(out).strip('_')
|
||||
|
||||
class ProductionLink(BaseModel):
|
||||
production: Production
|
||||
quantity: float
|
||||
|
||||
|
||||
class Production(BaseModel):
|
||||
recipe: Recipe
|
||||
production_level: float
|
||||
ingress: Dict[Items, ProductionLink] = Field(default_factory=dict)
|
||||
egress: Dict[Items, ProductionLink] = Field(default_factory=dict)
|
||||
ingress: Dict[Items, "ProductionLink"] = Field(default_factory=dict)
|
||||
egress: Dict[Items, "ProductionLink"] = Field(default_factory=dict)
|
||||
|
||||
@property
|
||||
def inputs(self):
|
||||
@@ -65,9 +63,17 @@ class Production(BaseModel):
|
||||
outputs[item] -= self.egress[item].quantity
|
||||
return outputs
|
||||
|
||||
class ProductionLink(BaseModel):
|
||||
item: Items
|
||||
quantity: float
|
||||
production: Optional[Production]
|
||||
raw: bool = False
|
||||
|
||||
|
||||
|
||||
class ProductionChain:
|
||||
def __init__(self):
|
||||
self.recipe_map: Dict[Items, list[Recipes]] = defaultdict(list)
|
||||
def __init__(self, preferred_recipes: Optional[Dict[Items, Recipe]] = None):
|
||||
self.item_to_recipies: Dict[Items, list[Recipes]] = defaultdict(list)
|
||||
for r in Recipes:
|
||||
for o in r.value.outputs:
|
||||
self.item_to_recipies[o].append(r.value)
|
||||
@@ -178,7 +184,7 @@ class ProductionChain:
|
||||
if not targets:
|
||||
return {}
|
||||
demand = defaultdict(float)
|
||||
item_to_production = defaultdict(list)
|
||||
item_to_production: Dict[Items, List[Production]] = defaultdict(list)
|
||||
queue: Deque[Items] = deque()
|
||||
for target in targets:
|
||||
recipe = self.get_recipe(target)
|
||||
@@ -197,12 +203,23 @@ class ProductionChain:
|
||||
item_to_production[output].append(p)
|
||||
for inp in p.inputs:
|
||||
queue.append(inp)
|
||||
calc_queue = deque()
|
||||
calc_queue: Deque[Production] = deque()
|
||||
for item in item_to_production:
|
||||
for production in item_to_production[item]:
|
||||
if not production.demand_satisfied():
|
||||
calc_queue.append(production)
|
||||
print(calc_queue)
|
||||
while calc_queue:
|
||||
prod = calc_queue.popleft()
|
||||
if prod.demand_satisfied():
|
||||
continue
|
||||
for inp in prod.inputs:
|
||||
if inp in RawResources:
|
||||
prod.ingress.append(ProductionLink(item=inp, quantity=prod.recipe.inputs[inp] - prod..raw_resources[inp], production=None, raw=True))
|
||||
else:
|
||||
for p in item_to_production[inp]:
|
||||
if p.demand_satisfied():
|
||||
prod.production_level += p.production_level * p.recipe.outputs[inp] / p.recipe.inputs[inp]
|
||||
|
||||
# print("item_to_production:", item_to_production)
|
||||
|
||||
|
||||
5
plus.py
5
plus.py
@@ -116,11 +116,6 @@ class RawResources(Enum):
|
||||
Coal = Items.Coal
|
||||
Air = Items.Air
|
||||
|
||||
class RawResources(Enum):
|
||||
SiteriteOre = Items.SiteriteOre
|
||||
LarrussiteOre = Items.LarrussiteOre
|
||||
CallaniteOre = Items.CallaniteOre
|
||||
AuroviteOre = Items.AuroviteOre
|
||||
|
||||
class Recipe(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
Reference in New Issue
Block a user