Unverified Commit 815f99b2 authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

Merge pull request #228752 from scvalex/minizinc-enable-gecode

minizinc: enable gecode and cbc solvers by default
parents 555023f2 44a331ac
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
{ 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 −0
Original line number Diff line number Diff line
{
    "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 −0
Original line number Diff line number Diff line
% 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 −0
Original line number Diff line number Diff line
# 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 −0
Original line number Diff line number Diff line
% 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"
];
Loading