minizinc: enable gecode and cbc solvers by default

Other changes:
- switch derivation to finalAttrs pattern
This commit is contained in:
Alexandru Scvortov 2023-06-01 14:07:14 +01:00
parent 8377abe93b
commit 44a331ac33
6 changed files with 98 additions and 5 deletions

View File

@ -1,17 +1,31 @@
{ lib, stdenv, fetchFromGitHub, cmake, flex, bison }:
stdenv.mkDerivation rec {
{ lib, stdenv, fetchFromGitHub, callPackage, jq, cmake, flex, bison, gecode, mpfr, cbc, zlib }:
stdenv.mkDerivation (finalAttrs: {
pname = "minizinc";
version = "2.7.4";
nativeBuildInputs = [ cmake flex bison ];
nativeBuildInputs = [ cmake flex bison gecode mpfr cbc zlib ];
src = fetchFromGitHub {
owner = "MiniZinc";
repo = "libminizinc";
rev = version;
rev = finalAttrs.version;
sha256 = "sha256-Zq5gAwe9IQmknSDilFyHhSk5ZCQ8EfBOiM6Oef2WxYg=";
};
postInstall = ''
mkdir -p $out/share/minizinc/solvers/
${jq}/bin/jq \
'.version = "${gecode.version}"
| .mznlib = "${gecode}/share/gecode/mznlib"
| .executable = "${gecode}/bin/fzn-gecode"' \
${./gecode.msc} \
>$out/share/minizinc/solvers/gecode.msc
'';
passthru.tests = {
simple = callPackage ./simple-test { };
};
meta = with lib; {
homepage = "https://www.minizinc.org/";
description = "A medium-level constraint modelling language";
@ -28,4 +42,4 @@ stdenv.mkDerivation rec {
platforms = platforms.unix;
maintainers = [ maintainers.sheenobu ];
};
}
})

View File

@ -0,0 +1,16 @@
{
"id": "org.gecode.gecode",
"name": "Gecode",
"description": "Gecode FlatZinc executable",
"version": "VERSION-WILL-BE-REPLACED-BY-JQ",
"mznlib": "MZNLIB-WILL-BE-REPLACED-BY-JQ",
"executable": "FZN_GECODE-WILL-BE-REPLACED-BY-JQ",
"tags": ["cp","int", "float", "set", "restart"],
"stdFlags": ["-a","-f","-n","-p","-r","-s","-t"],
"supportsMzn": false,
"supportsFzn": true,
"needsSolns2Out": true,
"needsMznExecutable": false,
"needsStdlibDir": false,
"isGUIApplication": false
}

View File

@ -0,0 +1,20 @@
% Taken from https://www.minizinc.org/doc-2.7.3/en/modelling.html
int: nc = 3;
var 1..nc: wa; var 1..nc: nt; var 1..nc: sa; var 1..nc: q;
var 1..nc: nsw; var 1..nc: v; var 1..nc: t;
constraint wa != nt;
constraint wa != sa;
constraint nt != sa;
constraint nt != q;
constraint sa != q;
constraint sa != nsw;
constraint sa != v;
constraint q != nsw;
constraint nsw != v;
solve satisfy;
output ["wa=\(wa)\t nt=\(nt)\t sa=\(sa)\n",
"q=\(q)\t nsw=\(nsw)\t v=\(v)\n",
"t=", show(t), "\n"];

View File

@ -0,0 +1,16 @@
# These tests show that the minizinc build is capable of running the
# examples in the official tutorial:
# https://www.minizinc.org/doc-2.7.3/en/modelling.html
{ stdenv, minizinc }:
stdenv.mkDerivation {
name = "minizinc-simple-test";
meta.timeout = 10;
dontInstall = true;
buildCommand = ''
${minizinc}/bin/minizinc --solver gecode ${./aust.mzn}
${minizinc}/bin/minizinc --solver cbc ${./loan.mzn} ${./loan1.dzn}
touch $out
'';
}

View File

@ -0,0 +1,24 @@
% Taken from https://www.minizinc.org/doc-2.7.3/en/modelling.html
% variables
var float: R; % quarterly repayment
var float: P; % principal initially borrowed
var 0.0 .. 10.0: I; % interest rate (per quarter)
% intermediate variables
var float: B1; % balance after one quarter
var float: B2; % balance after two quarters
var float: B3; % balance after three quarters
var float: B4; % balance owing at end
constraint B1 = P * (1.0 + I) - R;
constraint B2 = B1 * (1.0 + I) - R;
constraint B3 = B2 * (1.0 + I) - R;
constraint B4 = B3 * (1.0 + I) - R;
solve satisfy;
output [
"Borrowing ", show_float(0, 2, P), " at ", show(I*100.0),
"% interest, and repaying ", show_float(0, 2, R),
"\nper quarter for 1 year leaves ", show_float(0, 2, B4), " owing\n"
];

View File

@ -0,0 +1,3 @@
I = 0.04;
P = 1000.0;
R = 260.0;