FactorioSolver module¶
- class FactorioSolver.FactorioSolver(width, height, in_out_pos, recipes, selected_opt)[source]¶
Bases:
objectThis class manages all the components form the model given an instance, it also creates the Z3 Optimizer and allows to solve the instance and retrieve the solution in many ways.
- Parameters:
width (Int) – Width of the blueprint
height (Int) – Height of the blueprint
in_out_pos (Dictionary) – Contains the input and output positions and type of item carrying
recipes (Dictionary) – Contains the recipes that the assemblers in the blueprint will use, for each recipe it has a list of the items it requires and which rate in items/min needs and the outputting item and rate.
- find_solution()[source]¶
Tells the solver to find a solution, saves the solving status (SAT, UNSAT, TIMED OUT), it also saves the time it took the solver to finish.
- Returns:
The solving status (solution found or not found)
- Return type:
Bool
- initialize_model(blueprint_width, blueprint_height, in_out_pos, recipes, selected_opt)[source]¶
Creates all the constraints given the instance data, and sets the optimization criteria to the Optimizer. It also saves the model variables to later be evaluated.
- Parameters:
blueprint_width (Int) – number of rows
blueprint_height (Int) – number of columns
in_out_pos (Dictionary) – input and output positions with the corresponding items they are carrying
recipes (Dictionary) – each recipe used with the item quantities and types required for the input and output
selected_opt (String) – optimization criteria (‘maximize-output’, ‘minimize-route’, ‘minimize-loss’)
- model_to_json()[source]¶
Checks if the solver found a solution, if so evaluates all the model variables and store them in a dictionary, it also saves the time spent in solving and the status of the solution.
- Returns:
a JSON transformable dictionary with all the information of the solved instance
- Return type:
Dictionary