AssemblerLogic module

class AssemblerLogic.AssemblerLogic(width, height, recipe)[source]

Bases: DirectionalElement, GridElement, RecipeElement

This class contains all the constraints that implement the logic of the assemblers. Note that all the constraints of the model are explained in detail in the project report.

Parameters:
  • width (Int) – Width of the blueprint

  • height (Int) – Height of the blueprint

  • recipe (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.

assembler_input()[source]

Generates the constraints that ensure an assembler receives input items that the recipe is associated with can proces.

Returns:

List with all the logic regarding the constraint

Return type:

Array

assembler_output()[source]

Generates the constraints that ensure an assembler only outputs items that the recipe is associated with can produce.

Returns:

List with all the logic regarding the constraint

Return type:

Array

assembler_upper_bound()[source]

Complex method that launches a Z3 process that given the max_assemblers the blueprint can fit and recipes used, calculates the maximum amount of assemblers needed to maximize the output item. The result is the number of assemblers with the recipe associated.

constraints()[source]

Creates a list of all the constraints representing the logic of the class

Returns:

class constraints compacted in a single list

Return type:

Array

create_assembler_dict(selected_recipe)[source]

Creates a dictionary with the recipes that in the best of cases will need more than one assembler, this is later used to break the symmetry with the positions of the assemblers that use the same recipe :param selected_recipe: list with the recipe each assembler is producing :type selected_recipe: Array

Returns:

A dictionary that for each recipe (key) that needs more than one assembler, creates another dictionary

(value) that contains the number of the assembler (key) and a list of 3 Z3 variables (value) :rtype: Dictionary

create_ratio_dict()[source]

Creates a dictionary that for each assembler (key), contains a dictionary (value) with the input items of the associated recipe of the assembler (key) and its ratio variable (value)

Returns:

Dictionary with all the input ratio variables of each input item of each possible assembler

Return type:

Dictionary

demand(item, produced_required_items)[source]

Calculates the amount of “item” used by all the recipes and multiplies the rate variable of the assembler demanding it by the amount it uses :param item: name of the item the demand is calculated :type item: String

Parameters:

produced_required_items (Dictionary) – contains the Z3 variables with the rates and assemblers

Returns:

List of the amount of item used by all recipes multiplied by the rate variable of the assembler

Return type:

Array

distinct_assemblers()[source]

Generates the constraints to ensure there are no duplicate assemblers in the blueprint

Returns:

List with all the logic regarding the constraint

Return type:

Array

domain_constraint()[source]

Generates the constraints in order to define the domain of the variables input_ratio, collision_area and assembler.

Returns:

List with all the logic regarding the constraint

Return type:

Array

equal_ratios()[source]

Generates the constraints that ensure all input ratios end up having the same value

Returns:

List with all the logic regarding the constraint

Return type:

Array

input_ratios()[source]

Generates the constraints that define what values the variable input_ratio can take based on the number of inputting items and the maximum amount of items the associated recipe of the assembler can proces.

Returns:

List with all the logic regarding the constraint

Return type:

Array

is_needed(item)[source]

Checks if the “item” is in the input of the recipes used :param item: name of the item the demand is calculated :type item: String

Returns:

True if the item is used by any of the recipes, false otherwise

Return type:

Bool

is_produced(item)[source]

Checks if the “item” is the output of the recipes used :param item: name of the item the demand is calculated :type item: String

Returns:

True if the item is an output false otherwise

Return type:

Bool

Generates the constraints that ensure for each value greater than 0 in the collision_area variable there is one assembler with the same number in the eight neighbour cells around in the assembler variable.

Returns:

List with all the logic regarding the constraint

Return type:

Array

lower_bound_assemblers()[source]

Generates the constraints to ensure there is at least the minimum amount of assemblers in the blueprint.

Returns:

List with all the logic regarding the constraint

Return type:

Array

set_collision()[source]

Generates the constraints that ensure for each assembler the 3x3 area it occupies is represented in the collision_area variable.

Returns:

List with all the logic regarding the constraint

Return type:

Array

set_inserter(inserter)[source]

Setter of the variable inserter

Parameters:

inserter (Arrat[Array] EnumSort) – reference to the variable inserter

set_item_flow(item_flow)[source]

Setter of the variable item_flow

Parameters:

item_flow (Arrat[Array] Integer) – reference to the variable item_flow

set_item_flow_rate(output_flow_rate)[source]

Setter of the variable output_flow_rate

Parameters:

output_flow_rate (Arrat[Array] Real) – reference to the variable output_flow_rate

set_output_rate()[source]

Generates the constraints that set what is the number of outputting items of an assembler based on the input ratios and the associated recipe.

Returns:

List with all the logic regarding the constraint

Return type:

Array

symmetry_breaking()[source]

Generates the constraints in order to break the symmetry between assemblers producing the same recipe

Returns:

List with all the logic regarding the constraint

Return type:

Array