1
(***************************************************************************
2
* Copyright (C) 2004 by Thomas Nagy *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************)
25
let solve (eq : eqtable) =
26
let nb_molecules = eq#getsize_j () and nb_elements = eq#getsize_i () in
27
let dist = Fd.array nb_molecules 1 900 in
29
(* trivial constraints on domains *)
30
for j = 0 to nb_molecules -1 do
31
let num = try int_of_string (eq#getvar j) with _ -> -1 in
32
if num > -1 then dist.(j) <- Fd.int num
35
(* raises an exception if the problem is not solvable *)
36
for i = 0 to nb_elements - 1 do
37
Cstr.post (Arith.scalprod_fd (eq#getline i) dist =~ i2e 0)
40
let goal = Goals.GlArray.labeling dist in
41
if (Goals.solve goal) then Array.iteri (fun cnt i -> eq#setsol cnt (Fd.min i)) dist
42
else failwith "no solution found"
45
(* workaround for (probably) a bug in the facile library 1.0 (fixed in 1.1?) :
46
* when the constraints make a problem
47
* unsolvable, an exception is raised
49
* unfortunately the next problem
50
* solved afterwards is not handled properly *)
52
let cleanup (eq : eqtable) =
53
(* Printf.printf "cleaning up"; *)
54
let nb_molecules = eq#getsize_j () and nb_elements = eq#getsize_i () in
55
let dist = Fd.array nb_molecules 0 2 in
56
let goal = Goals.GlArray.labeling dist in
57
if not (Goals.solve goal) then failwith "fatal error"