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