author | haftmann |
Sat, 06 Sep 2014 20:12:32 +0200 | |
changeset 58195 | 1fee63e0377d |
parent 47455 | 26315a545e26 |
child 69597 | ff784d5a5bfb |
permissions | -rw-r--r-- |
47455 | 1 |
(* Title: HOL/Matrix_LP/fspmlp.ML |
16784 | 2 |
Author: Steven Obua |
3 |
*) |
|
4 |
||
22951 | 5 |
signature FSPMLP = |
16784 | 6 |
sig |
7 |
type linprog |
|
19404 | 8 |
type vector = FloatSparseMatrixBuilder.vector |
9 |
type matrix = FloatSparseMatrixBuilder.matrix |
|
16784 | 10 |
|
22964 | 11 |
val y : linprog -> term |
12 |
val A : linprog -> term * term |
|
13 |
val b : linprog -> term |
|
14 |
val c : linprog -> term * term |
|
15 |
val r12 : linprog -> term * term |
|
16784 | 16 |
|
17 |
exception Load of string |
|
22951 | 18 |
|
16784 | 19 |
val load : string -> int -> bool -> linprog |
20 |
end |
|
21 |
||
22964 | 22 |
structure Fspmlp : FSPMLP = |
16784 | 23 |
struct |
24 |
||
19404 | 25 |
type vector = FloatSparseMatrixBuilder.vector |
26 |
type matrix = FloatSparseMatrixBuilder.matrix |
|
27 |
||
24302 | 28 |
type linprog = term * (term * term) * term * (term * term) * (term * term) |
16784 | 29 |
|
46533 | 30 |
fun y (c1, _, _, _, _) = c1 |
31 |
fun A (_, c2, _, _, _) = c2 |
|
32 |
fun b (_, _, c3, _, _) = c3 |
|
33 |
fun c (_, _, _, c4, _) = c4 |
|
34 |
fun r12 (_, _, _, _, c6) = c6 |
|
16784 | 35 |
|
22951 | 36 |
structure CplexFloatSparseMatrixConverter = |
16784 | 37 |
MAKE_CPLEX_MATRIX_CONVERTER(structure cplex = Cplex and matrix_builder = FloatSparseMatrixBuilder); |
38 |
||
39 |
datatype bound_type = LOWER | UPPER |
|
40 |
||
24135
e7fb7ef2a85e
added int type constraints to accomodate hacked SML/NJ;
wenzelm
parents:
23665
diff
changeset
|
41 |
fun intbound_ord ((i1: int, b1),(i2,b2)) = |
16784 | 42 |
if i1 < i2 then LESS |
22951 | 43 |
else if i1 = i2 then |
44 |
(if b1 = b2 then EQUAL else if b1=LOWER then LESS else GREATER) |
|
16784 | 45 |
else GREATER |
46 |
||
31971
8c1b845ed105
renamed functor TableFun to Table, and GraphFun to Graph;
wenzelm
parents:
24630
diff
changeset
|
47 |
structure Inttab = Table(type key = int val ord = (rev_order o int_ord)); |
16784 | 48 |
|
31971
8c1b845ed105
renamed functor TableFun to Table, and GraphFun to Graph;
wenzelm
parents:
24630
diff
changeset
|
49 |
structure VarGraph = Table(type key = int*bound_type val ord = intbound_ord); |
16784 | 50 |
(* key -> (float option) * (int -> (float * (((float * float) * key) list)))) *) |
51 |
(* dest_key -> (sure_bound * (row_index -> (row_bound * (((coeff_lower * coeff_upper) * src_key) list)))) *) |
|
52 |
||
53 |
exception Internal of string; |
|
54 |
||
22951 | 55 |
fun add_row_bound g dest_key row_index row_bound = |
56 |
let |
|
57 |
val x = |
|
58 |
case VarGraph.lookup g dest_key of |
|
59 |
NONE => (NONE, Inttab.update (row_index, (row_bound, [])) Inttab.empty) |
|
60 |
| SOME (sure_bound, f) => |
|
61 |
(sure_bound, |
|
62 |
case Inttab.lookup f row_index of |
|
63 |
NONE => Inttab.update (row_index, (row_bound, [])) f |
|
64 |
| SOME _ => raise (Internal "add_row_bound")) |
|
16784 | 65 |
in |
22951 | 66 |
VarGraph.update (dest_key, x) g |
16784 | 67 |
end |
68 |
||
22951 | 69 |
fun update_sure_bound g (key as (_, btype)) bound = |
70 |
let |
|
71 |
val x = |
|
72 |
case VarGraph.lookup g key of |
|
73 |
NONE => (SOME bound, Inttab.empty) |
|
74 |
| SOME (NONE, f) => (SOME bound, f) |
|
75 |
| SOME (SOME old_bound, f) => |
|
76 |
(SOME ((case btype of |
|
22964 | 77 |
UPPER => Float.min |
78 |
| LOWER => Float.max) |
|
22951
dfafcd6223ad
whitespace tuned
haftmann |