minizinc-process: A set of helpers to call minizinc models.

[ apache, library, optimization ] [ Propose Tags ]

MiniZinc is a language and a toolchain to solve discrete optimization problems. This package provides simple wrappers around the MiniZinc executable to pass inputs and read outputs.

[Skip to Readme]
Versions [faq]
Change log
Dependencies aeson, base (==4.13.*), bytestring, containers, directory, hashable, process-extras, stringsearch, text [details]
License Apache-2.0
Copyright Lucas DiCioccio (2020)
Author Lucas DiCioccio
Category Optimization
Home page
Bug tracker
Source repo head: git clone
Uploaded by LucasDiCioccio at 2020-04-18T14:22:20Z
Distributions NixOS:
Downloads 69 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2020-04-18 [all 2 reports]


  • Process
    • Process.Minizinc
      • Process.Minizinc.Inspect


Maintainer's Corner

For package maintainers and hackage trustees

Readme for minizinc-process-

[back to package description]


MiniZinc is a language and a toolchain to solve discrete optimization problems. This package offers wrappers around the minizinc executable to pass inputs and outputs.

Assume that a primitive MiniZinc model is available at the path models/example001.mzn.

0..100: x;
var int: y;
constraint x < y;

This model expects x as an Int and decides y as an Int if a solution is found. Ideally we would like to use minizinc and this model like a function of type Int -> IO (Maybe Int) function in Haskell. This package provides building blocks to create such a mapping.


This package relies on JSON support for MiniZinc by using JSON as an intermediary representation. On the Haskell side we picked the popular aeson package for serializing values.

MiniZinc input binds names to variables, hence the Int -> IO (Maybe Int) example above is insufficient: inputs and outputs need to translate to JSON Object constructor of Aeson's Value type.

Example Use

The runLastMinizincJSON function requires some configuration object to provide parameters like the solver backing MiniZinc, the timeout, where to store MiniZinc data files. The simpleMiniZinc function provides a smart constructor for building such an environment.

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}

module Main where

import Data.Aeson
import Data.Hashable
import GHC.Generics
import Process.Minizinc
import Process.Minizinc.Inspect

data Input = Input {x :: Int}
  deriving (Generic)

instance ToJSON Input -- required for `runLastMinizincJSON`

instance Hashable Input -- required for `runLastMinizincJSON`

data Output = Output {y :: Int}
  deriving (Show, Generic)

instance FromJSON Output -- required for `runLastMinizincJSON`

main :: IO ()
main = do
  inspect "models/example001.mzn" >>= print
  let mzn = simpleMiniZinc @Input @Output "models/example001.mzn" 1000 Gecode
  let problem = Input 10
  runLastMinizincJSON mzn problem >>= print

The @Input and @Output syntax allow to pass type parameters to simpleMiniZinc, this style is optional but helps the GHC compiler inference (in our example, this type application is the only indication needed to tell the compiler to deserialize Output objects).


The author of this package is not affiliated with MiniZinc. See also: