The MiniZinc Solver Backend
MiniZinc is an open-source solver for discrete optimization problems.
Use it to solve constraint-based problems with RelationalAI’s SolverModel
API.
Capabilities
Section titled “Capabilities”MiniZinc supports the following problem types:
Problem Type | Supported |
---|---|
Linear Programs (LP) | |
Mixed-Integer Linear Programs (MILP) | |
Quadratic Programs (QP) | |
Quadratically Constrained Programs (QCP) | |
Nonlinear Programs (NLP) | |
Constraint Programming (CP) | |
Discrete Variables | |
Continuous Variables |
Version and Licensing
Section titled “Version and Licensing”MiniZinc is bundled with RelationalAI and does not require a license key or additional setup.
Detail | Info |
---|---|
Version | 2.8.5 |
License Type | MPL 2.0 (Free and Open Source) |
To use MiniZinc with RelationalAI, you can define a prescriptive model using the SolverModel
API and specify "minizinc"
as the solver backend:
import relationalai as raifrom relationalai.experimental import solvers
# Create a RAI model.model = rai.Model("ProductBundling")
12 collapsed lines
# Declare a Product entity type.Product = model.Type("Product")Product.price.declare()Product.cost.declare()
# Define sample products with price and cost properties.with model.rule(): Product.add(name="Laptop").set(price=999.0, cost=650.0) Product.add(name="Mouse").set(price=25.0, cost=8.0) Product.add(name="Keyboard").set(price=70.0, cost=25.0) Product.add(name="Charger").set(price=35.0, cost=12.0) Product.add(name="Headphones").set(price=85.0, cost=30.0)
# Create a solver model.solver_model = solvers.SolverModel(model)
46 collapsed lines
# Specify variables, constraints, and the objective.# Define binary decision variables to include or exclude each product.with model.rule(): product = Product() with model.match(): with product.name == "Laptop": solver_model.variable( product, name_args=["include", product.name], type="zero_one", fixed=1 # Bundle must always include the laptop ) # Other products are optional. with model.case(): solver_model.variable( product, name_args=["include", product.name], type="zero_one" )
# Define a conditional constraint that requires the charger if headphones are included.with solvers.operators(): headphones = Product(name="Headphones") charger = Product(name="Charger") solver_model.constraint( solvers.if_then_else( headphones == 1, # If the headphones are included charger == 1, # Then the charger must be included charger == 0, # Otherwise, the charger must not be included ), name_args=["headphones_require_charger"] )
# Define a constraint to limit the bundle size to 3 products.with solvers.operators(): product = Product() solver_model.constraint( solvers.sum(product) == 3, name_args=["bundle_size"] )
# Define the objective to minimize the total cost of the bundle.with solvers.operators(): product = Product() total_cost = solvers.sum(product.cost * product) solver_model.min_objective(total_cost) # Minimize total bundle cost
# Create a Solver object.solver = solvers.Solver("minizinc")
# Solve the model.solver_model.solve(solver)
# View the solution's objective value.with model.query() as select: response = select(solver_model.objective_value)print(f"\n\nMinimum cost: {response.results.iloc[0, 0]}")
# View the optimal solution.with model.query() as select: product = Product() solver_model.value(product) == 1 # Only select included products response = select(product.name, product.price, product.cost)print("\n\nProducts in optimal bundle:")print(response.results)
Solver Options
Section titled “Solver Options”MiniZinc supports standard solver options. Solver-specific options are not currently supported.
Limitations
Section titled “Limitations”- Currently, RAI only exposes the Chuffed backend for MiniZinc.
- MiniZinc requires a single, scalar objective—even if multi-objective support is added to RelationalAI in the future.