Warning, /education/kalzium/src/solver/chem.ml is written in an unsupported language. File is not indexed.
0001 (* 0002 SPDX-FileCopyrightText: 2004 Thomas Nagy <tnagy2^8@yahoo.fr> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 *) 0006 0007 open Facile;; 0008 open Easy;; 0009 open Datastruct;; 0010 0011 let solve (eq : eqtable) = 0012 let nb_molecules = eq#getsize_j () and nb_elements = eq#getsize_i () in 0013 let dist = Fd.array nb_molecules 1 900 in 0014 0015 (* trivial constraints on domains *) 0016 for j = 0 to nb_molecules -1 do 0017 let num = try int_of_string (eq#getvar j) with _ -> -1 in 0018 if num > -1 then dist.(j) <- Fd.int num 0019 done; 0020 0021 (* raises an exception if the problem is not solvable *) 0022 for i = 0 to nb_elements - 1 do 0023 Cstr.post (Arith.scalprod_fd (eq#getline i) dist =~ i2e 0) 0024 done; 0025 0026 let goal = Goals.GlArray.labeling dist in 0027 if (Goals.solve goal) then Array.iteri (fun cnt i -> eq#setsol cnt (Fd.min i)) dist 0028 else failwith "no solution found" 0029 ;; 0030 0031 (* workaround for (probably) a bug in the facile library 1.0 (fixed in 1.1?) : 0032 * when the constraints make a problem 0033 * unsolvable, an exception is raised 0034 * 0035 * unfortunately the next problem 0036 * solved afterwards is not handled properly *) 0037 0038 let cleanup (eq : eqtable) = 0039 (* Printf.printf "cleaning up"; *) 0040 let nb_molecules = eq#getsize_j () and nb_elements = eq#getsize_i () in 0041 let dist = Fd.array nb_molecules 0 2 in 0042 let goal = Goals.GlArray.labeling dist in 0043 if not (Goals.solve goal) then failwith "fatal error" 0044 ;;