src/HOL/Matrix/cplex/fspmlp.ML
changeset 17261 193b84a70ca4
parent 16784 92ff7c903585
child 17412 e26cb20ef0cc
equal deleted inserted replaced
17260:df7c3b1f390a 17261:193b84a70ca4
    52 
    52 
    53 fun add_row_bound g dest_key row_index row_bound = 
    53 fun add_row_bound g dest_key row_index row_bound = 
    54     let 
    54     let 
    55 	val x = 
    55 	val x = 
    56 	    case VarGraph.lookup (g, dest_key) of
    56 	    case VarGraph.lookup (g, dest_key) of
    57 		NONE => (NONE, Inttab.update ((row_index, (row_bound, [])), Inttab.empty))
    57 		NONE => (NONE, Inttab.curried_update (row_index, (row_bound, [])) Inttab.empty)
    58 	      | SOME (sure_bound, f) =>
    58 	      | SOME (sure_bound, f) =>
    59 		(sure_bound,
    59 		(sure_bound,
    60 		 case Inttab.lookup (f, row_index) of
    60 		 case Inttab.curried_lookup f row_index of
    61 		     NONE => Inttab.update ((row_index, (row_bound, [])), f)
    61 		     NONE => Inttab.curried_update (row_index, (row_bound, [])) f
    62 		   | SOME _ => raise (Internal "add_row_bound"))				     
    62 		   | SOME _ => raise (Internal "add_row_bound"))				     
    63     in
    63     in
    64 	VarGraph.update ((dest_key, x), g)
    64 	VarGraph.update ((dest_key, x), g)
    65     end    
    65     end    
    66 
    66 
    86 
    86 
    87 (*fun get_row_bound g key row_index = 
    87 (*fun get_row_bound g key row_index = 
    88     case VarGraph.lookup (g, key) of
    88     case VarGraph.lookup (g, key) of
    89 	NONE => NONE
    89 	NONE => NONE
    90       | SOME (sure_bound, f) =>
    90       | SOME (sure_bound, f) =>
    91 	(case Inttab.lookup (f, row_index) of 
    91 	(case Inttab.curried_lookup f row_index of 
    92 	     NONE => NONE
    92 	     NONE => NONE
    93 	   | SOME (row_bound, _) => (sure_bound, row_bound))*)
    93 	   | SOME (row_bound, _) => (sure_bound, row_bound))*)
    94     
    94     
    95 fun add_edge g src_key dest_key row_index coeff = 
    95 fun add_edge g src_key dest_key row_index coeff = 
    96     case VarGraph.lookup (g, dest_key) of
    96     case VarGraph.lookup (g, dest_key) of
    97 	NONE => raise (Internal "add_edge: dest_key not found")
    97 	NONE => raise (Internal "add_edge: dest_key not found")
    98       | SOME (sure_bound, f) =>
    98       | SOME (sure_bound, f) =>
    99 	(case Inttab.lookup (f, row_index) of
    99 	(case Inttab.curried_lookup f row_index of
   100 	     NONE => raise (Internal "add_edge: row_index not found")
   100 	     NONE => raise (Internal "add_edge: row_index not found")
   101 	   | SOME (row_bound, sources) => 
   101 	   | SOME (row_bound, sources) => 
   102 	     VarGraph.update ((dest_key, (sure_bound, Inttab.update ((row_index, (row_bound, (coeff, src_key) :: sources)), f))), g))
   102 	     VarGraph.curried_update (dest_key, (sure_bound, Inttab.curried_update (row_index, (row_bound, (coeff, src_key) :: sources)) f)) g)
   103 
   103 
   104 fun split_graph g = 
   104 fun split_graph g = 
   105     let
   105     let
   106 	fun split ((r1, r2), (key, (sure_bound, _))) = 
   106 	fun split ((r1, r2), (key, (sure_bound, _))) = 
   107 	    case sure_bound of
   107 	    case sure_bound of
   108 		NONE => (r1, r2)
   108 		NONE => (r1, r2)
   109 	      | SOME bound => 
   109 	      | SOME bound => 
   110 		(case key of
   110 		(case key of
   111 		     (u, UPPER) => (r1, Inttab.update ((u, bound), r2))
   111 		     (u, UPPER) => (r1, Inttab.curried_update (u, bound) r2)
   112 		   | (u, LOWER) => (Inttab.update ((u, bound), r1), r2))
   112 		   | (u, LOWER) => (Inttab.curried_update (u, bound) r1, r2))
   113     in
   113     in
   114 	VarGraph.foldl split ((Inttab.empty, Inttab.empty), g)
   114 	VarGraph.foldl split ((Inttab.empty, Inttab.empty), g)
   115     end
   115     end
   116 
   116 
   117 fun it2list t = 
   117 fun it2list t = 
   193 
   193 
   194 fun calcr safe_propagation xlen names prec A b = 
   194 fun calcr safe_propagation xlen names prec A b = 
   195     let
   195     let
   196 	val empty = Inttab.empty
   196 	val empty = Inttab.empty
   197 
   197 
   198 	fun instab t i x = Inttab.update ((i,x), t)
   198 	fun instab t i x = Inttab.curried_update (i, x) t
   199 
   199 
   200 	fun isnegstr x = String.isPrefix "-" x
   200 	fun isnegstr x = String.isPrefix "-" x
   201 	fun negstr x = if isnegstr x then String.extract (x, 1, NONE) else "-"^x
   201 	fun negstr x = if isnegstr x then String.extract (x, 1, NONE) else "-"^x
   202 
   202 
   203 	fun test_1 (lower, upper) = 
   203 	fun test_1 (lower, upper) = 
   278 		let val e = FloatSparseMatrixBuilder.empty_spmat in (e, (e, e)) end
   278 		let val e = FloatSparseMatrixBuilder.empty_spmat in (e, (e, e)) end
   279 	    else
   279 	    else
   280 		let
   280 		let
   281 		    val index = xlen-i
   281 		    val index = xlen-i
   282 		    val (r, (r12_1, r12_2)) = abs_estimate (i-1) r1 r2 
   282 		    val (r, (r12_1, r12_2)) = abs_estimate (i-1) r1 r2 
   283 		    val b1 = case Inttab.lookup (r1, index) of NONE => raise (Load ("x-value not bounded from below: "^(names index))) | SOME x => x
   283 		    val b1 = case Inttab.curried_lookup r1 index of NONE => raise (Load ("x-value not bounded from below: "^(names index))) | SOME x => x
   284 		    val b2 = case Inttab.lookup (r2, index) of NONE => raise (Load ("x-value not bounded from above: "^(names index))) | SOME x => x
   284 		    val b2 = case Inttab.curried_lookup r2 index of NONE => raise (Load ("x-value not bounded from above: "^(names index))) | SOME x => x
   285 		    val abs_max = FloatArith.max (FloatArith.neg (FloatArith.negative_part b1)) (FloatArith.positive_part b2)    
   285 		    val abs_max = FloatArith.max (FloatArith.neg (FloatArith.negative_part b1)) (FloatArith.positive_part b2)    
   286 		in
   286 		in
   287 		    (add_row_entry r index abs_max, (add_row_entry r12_1 index b1, add_row_entry r12_2 index b2))
   287 		    (add_row_entry r index abs_max, (add_row_entry r12_1 index b1, add_row_entry r12_2 index b2))
   288 		end		    		   
   288 		end		    		   
   289 	val sign = FloatSparseMatrixBuilder.sign_term
   289 	val sign = FloatSparseMatrixBuilder.sign_term