mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-04-17 23:00:15 +00:00
minizinc: enable gecode and cbc solvers by default
Other changes: - switch derivation to finalAttrs pattern
This commit is contained in:
parent
8377abe93b
commit
44a331ac33
@ -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 ];
|
||||
};
|
||||
}
|
||||
})
|
||||
|
16
pkgs/development/tools/minizinc/gecode.msc
Normal file
16
pkgs/development/tools/minizinc/gecode.msc
Normal 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
|
||||
}
|
20
pkgs/development/tools/minizinc/simple-test/aust.mzn
Normal file
20
pkgs/development/tools/minizinc/simple-test/aust.mzn
Normal 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"];
|
16
pkgs/development/tools/minizinc/simple-test/default.nix
Normal file
16
pkgs/development/tools/minizinc/simple-test/default.nix
Normal 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
|
||||
'';
|
||||
}
|
24
pkgs/development/tools/minizinc/simple-test/loan.mzn
Normal file
24
pkgs/development/tools/minizinc/simple-test/loan.mzn
Normal 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"
|
||||
];
|
3
pkgs/development/tools/minizinc/simple-test/loan1.dzn
Normal file
3
pkgs/development/tools/minizinc/simple-test/loan1.dzn
Normal file
@ -0,0 +1,3 @@
|
||||
I = 0.04;
|
||||
P = 1000.0;
|
||||
R = 260.0;
|
Loading…
Reference in New Issue
Block a user