Skip to main content

A python module to help you plan your factory for Factorio.

Project description

FactorioCalc is a Python module to help you symbolically plan your factory for Factorio.

With FactorioCalc you can:

  • Symbolically express your exact machine configuration and ask it what the resulting inputs and outputs is.

  • Import a blueprint and determine what it produces.

  • Specify the recipes you want to use and let FactorioCalc determine the exact number of machines needed.

  • Specify what you want, and let FactorioCalc determine both the recipes and the number of machines required.

  • Combine factories, which were created using any of the above methods, to create a larger factory.

FactorioCalc has supports for using custom recipe data and mods. The companion mod, Recipe Exporter, provides the recipe data.

FactorioCalc contains a custom simplex solver so it can easily handle complex cases that involve recipes with more than one output, such as oil and uranium processing.

I, the author, find designing my factory symbolically more natural than using a spreadsheet and tools like FactorioLab.

Read the docs at https://factoriocalc.readthedocs.io/en/stable/

Examples

>>> from factoriocalc import setGameConfig, itm, rcp, mch, presets, config, produce
>>> setGameConfig('v2.0')

Create a simple factory that creates electronic circuits from copper and iron plates:

>>> config.machinePrefs.set(presets.MP_LATE_GAME)
>>> circuits = 2*rcp.electronic_circuit() + 3*rcp.copper_cable()
>>> circuits.summary()
    2x electronic_circuit: AssemblingMachine3:
          electronic_circuit 5/s, iron_plate -5/s, copper_cable -15/s, electricity -0.775 MW
    3x copper_cable: AssemblingMachine3:
          copper_cable 15/s, copper_plate -7.5/s, electricity -1.1625 MW
>>> circuits.flows().print()
electronic_circuit 5/s
copper_cable 0/s (15/s - 15/s)
iron_plate -5/s
copper_plate -7.5/s
electricity -1.9375 MW

Use produce to create a factory that produces rocket fuel:

>>> config.machinePrefs.set(presets.MP_MAX_PROD().withBeacons(presets.SPEED_BEACON,
        {mch.AssemblingMachine3:8, mch.ChemicalPlant:8, mch.OilRefinery:12}))
>>> rocketFuel = produce([itm.rocket_fuel@6], using=[rcp.advanced_oil_processing]).factory
>>> rocketFuel.summary()
b-rocket-fuel:
    11.1x rocket_fuel: AssemblingMachine3  +364% speed +40% prod. +914% energy +40% pollution
    4.67x solid_fuel_from_light_oil: ChemicalPlant  +379% speed +30% prod. +834% energy +30% pollution
    2.21x solid_fuel_from_petroleum_gas: ChemicalPlant  +379% speed +30% prod. +834% energy +30% pollution
    2.57x advanced_oil_processing: OilRefinery  +475% speed +30% prod. +967% energy +30% pollution
    1.00x heavy_oil_cracking: ChemicalPlant  +379% speed +30% prod. +834% energy +30% pollution
  Outputs: rocket_fuel 6/s
  Inputs: water -220.004/s, crude_oil -295.803/s

Figure out the best method to quality grind for legendary electronic circuits by trying both productivity and quality modules and letting the solver figure out the best combination:

>>> setGameConfig('v2.0-sa')
>>> config.machinePrefs.set(presets.MP_LEGENDARY)
>>> legendaryElectronicCcircuits = box(
    [*~rcp.electronic_circuit.allQualities[0:4](modules=itm.legendary_quality_module_3),
     *~rcp.electronic_circuit.allQualities(beacons = 1*mch.LegendaryBeacon(itm.legendary_speed_module_3)),
     *~rcp.electronic_circuit_recycling.allQualities[0:4]()],
    inputs = rcp.electronic_circuit.inputs,
    outputs = [itm.legendary_electronic_circuit@1])
>>> legendaryElectronicCcircuits.summary()
b-legendary-electronic-circuit:
    (  0x)electronic_circuit: LegendaryElectromagneticPlant  -25% speed +50% prod. +31.0% quality
    (  0x)uncommon_electronic_circuit: LegendaryElectromagneticPlant  -25% speed +50% prod. +31.0% quality
    (  0x)rare_electronic_circuit: LegendaryElectromagneticPlant  -25% speed +50% prod. +31.0% quality
    (  0x)epic_electronic_circuit: LegendaryElectromagneticPlant  -25% speed +50% prod. +31.0% quality
    (0.450x)electronic_circuit: LegendaryElectromagneticPlant  +550% speed +175% prod. +750% energy +50% pollution
    (0.143x)uncommon_electronic_circuit: LegendaryElectromagneticPlant  +550% speed +175% prod. +750% energy +50% pollution
    (0.0597x)rare_electronic_circuit: LegendaryElectromagneticPlant  +550% speed +175% prod. +750% energy +50% pollution
    (0.0250x)epic_electronic_circuit: LegendaryElectromagneticPlant  +550% speed +175% prod. +750% energy +50% pollution
    (0.00559x)legendary_electronic_circuit: LegendaryElectromagneticPlant  +550% speed +175% prod. +750% energy +50% pollution
    (2.51x)electronic_circuit_recycling: LegendaryRecycler  -20% speed +24.8% quality
    (0.799x)uncommon_electronic_circuit_recycling: LegendaryRecycler  -20% speed +24.8% quality
    (0.334x)rare_electronic_circuit_recycling: LegendaryRecycler  -20% speed +24.8% quality
    (0.139x)epic_electronic_circuit_recycling: LegendaryRecycler  -20% speed +24.8% quality
  Outputs: legendary_electronic_circuit 1/s
  Inputs: iron_plate -14.1348/s (15.1298/s - 29.2647/s), copper_cable -42.4045/s (45.3895/s - 87.7940/s)

Installation

FactorioCalc is available on PyPI so you can install it using pip:

pip3 install factoriocalc

Status

FactorioCalc has been used by the author to help produce a factory that produces around 2k science packs per minute with Factorio 1.1, beat Space Exploration, beat Krastorio 2, create a Krastorio 2 factory that produces 3k science packs per minute, and beat Factorio: Space Age. The calculations, in terms of the rate of items produced and consumed, should be accurate (which includes tricky cases such as the Kovarex enrichment process). The solver, in nearly all cases, should produce optimal results in terms of materials used. The API is subject to change but the core functionality should be stable.

Possible Bugs

FactorioCalc uses a custom simplex solver written in pure python. The solver has no provisions to prevent cycling, so calls to solve could theoretical loop and need to be killed with control-c; however, so far this has not happened.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

factoriocalc-0.3.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

factoriocalc-0.3.0-py3-none-any.whl (191.3 kB view details)

Uploaded Python 3

File details

Details for the file factoriocalc-0.3.0.tar.gz.

File metadata

  • Download URL: factoriocalc-0.3.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.3

File hashes

Hashes for factoriocalc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 98bc30b54c1e78c4db763d27697e0292928149789ccaea8e3dfeda5bef189400
MD5 68cfcb3a9771d6bf6614c524d2294147
BLAKE2b-256 5d98d5fe34f6e54a4733a73376f5bb928e938d21785e331183a9c68bcd81e0fe

See more details on using hashes here.

File details

Details for the file factoriocalc-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: factoriocalc-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 191.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.3

File hashes

Hashes for factoriocalc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bec0ee75879ff155beda2290df15845f12bccaf84d50ce7599353a3caf190096
MD5 410f8ce461f5819792f258f452a24f22
BLAKE2b-256 40a20987430ad071d891339f314b058a031f849357df12f07958c84aaf8ff01d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page