From 15228ac1c4c6111ad429b59a5bb976e77f9a1f73 Mon Sep 17 00:00:00 2001 From: fastrgv Date: Thu, 22 Nov 2018 18:57:23 -0800 Subject: [PATCH] test driver + compilation script --- acmp.sh | 8 +++++ munktest.adb | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 acmp.sh create mode 100644 munktest.adb diff --git a/acmp.sh b/acmp.sh new file mode 100644 index 0000000..1307089 --- /dev/null +++ b/acmp.sh @@ -0,0 +1,8 @@ + +export PATH=$HOME/opt/GNAT/2018/bin:$PATH + +gnatmake $1 \ +-O3 -gnat12 -I. --subdirs=./obj + +mv obj/$1 . + diff --git a/munktest.adb b/munktest.adb new file mode 100644 index 0000000..a125c9b --- /dev/null +++ b/munktest.adb @@ -0,0 +1,94 @@ + +-- +-- Copyright (C) 2018 +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You may read the full text of the GNU General Public License +-- at . + +-- This algorithm was copied on 20sep18 from: +-- https://users.cs.duke.edu/~brd/Teaching/ +-- Bio/asmb/current/Handouts/munkres.html +-- and modified to correct some errors. It has now been tested +-- on thousands of testcases and seems to be working properly. +-- Please send any improvements or further corrections back to: +-- + + + + +with text_io; +with munkres; + + +procedure munktest is + + use text_io; + + d: constant integer := 11; + + use munkres; + + assn: iatype(1..d); + + x: constant integer := 65534; + cost: iatype(1..d*d) := ( + + 0, 2, 3, 3, x, 4, 5, 5, 6, 6, x, + 2, 0, 3, 1, x, 2, 5, 3, 6, 4, x, + 3, 1, 4, 2, 1, 3, 6, 4, 7, 5, x, + x, x, 2, 4, x, 5, 6, 6, 7, 7, x, + x, x, 1, 3, x, 4, 5, 5, 6, 6, x, + x, x, 3, 1, 0, 2, 5, 3, 6, 4, x, + x, x, 2, 4, x, 5, 6, 6, 7, 7, x, + x, x, 3, 1, x, 0, 3, 1, 4, 2, x, + x, x, 4, 2, 1, 1, 4, 2, 5, 3, x, + x, x, 8, 8, x, 7, 6, 6, 3, 5, 4, + x, x, 7, 7, x, 6, 5, 5, 2, 4, 3 + + ); + + + j,r,c,total: integer := 0; + + function indx(r,c: integer) return integer is + begin + return (r-1)*d+c; + end indx; + + Ok: boolean; + +begin + + munkres.hungarian(cost,assn,Ok); + + for i in 1..d loop + r:=i; + c:=assn(i); + put("row="&integer'image(r)); + put(" matches col="&integer'image(c)); + new_line; + if c>d or c<1 then + put_line("col is bogus"); + if Ok then + put_line("Ok=true ???"); + else + put_line("Ok=FALSE !!!"); + end if; + raise program_error; + end if; + total := total + cost( indx(r,c) ); + end loop; + put_line("Total Cost: "&integer'image(total)); + +end munktest; +