(* ========================================================================== *)
(* FLYSPECK - CODE FORMALIZATION                                              *)
(*                                                                            *)
(* Lemma: Linear Programs                                                     *)
(* Program: Tame Hypermap                                                     *)
(* Author: Thomas C. Hales                                                    *)
(* Date: 2010-08-01                                                           *)
(* ========================================================================== *)




(* Case notes for the various hard cases 

   This code probably isn't directly executable, because it consists
   of notes from interactive sessions, run over a period of about a
   year (but mostly at the beginning of August, 2010).  

   It is a historical trace of how I got all the linear programs to work
   to eliminate the 12 hard tame hypermaps.

   It is part of the scafffolding.  It has served its purpose and is no longer
   needed, except as a historical record.
*)

(*
When running these scripts, I opened all modules in sight!

Glpk_link, Lpproc, Hard_lp, Temp_ineq, Tame_scaffolding, List,...

*)

raise (failwith "File is not executable");;


open Temp_ineq;;

(*

(* There are parallel versions of several functions here XX and
  XX_include_flat.  I think we can use the XX_include_flat version
  everywhere and delete the others.
*)

  let add_hints_force bb = 
  try(
  let _ = init_hash bb in
  let dart = snd(hd(sorted_azim_weighted_diff darts_of_std_tri bb)) in 
  let f = face_of_dart dart bb in
  if not(mem f (bb.std3_big @ bb.std3_small)) then bb.hints <-  [Triangle_split f] else
  let f1 = subtract f  (bb.node_200_218 @ bb.node_218_252) in
  if not(f1 = []) then bb.hints <- [High_low (hd f1)] else 
  let f2 = intersect (highish bb) f in
  if not(f2 = []) then  bb.hints <- [High_low (hd f2)] else
  let d1 = subtract (rotation [dart]) (bb.d_edge_200_225 @ bb.d_edge_225_252) in
  if not (d1 = []) then bb.hints <- [Edge_split (hd d1)] else ()
  ) with Failure _ -> failwith "add_hints";;

  let add_hints bb = 
  if not(is_feas bb) then () else
  if not(bb.hints = []) then () else
  add_hints_force bb;;

  let filter_feas_hint bbs = filter_feas_f add_hints bbs;;

  let onepass_hint = function 
  [] -> []
  | bb::bbss as bbs -> 
  let _ = onepass_backup := bbs in
  let brs =  switch_hint bb in
  let brs1 = map set_face_numerics brs in
  let brs2 = map set_node_numerics brs1 in
  let _ = echo bbs in
  sortbb ((filter_feas_hint brs2) @ bbss);;

  let rec allpass_hint count bbs = 
  if  count <= 0 then bbs else allpass_hint (count - 1) (onepass_hint bbs);;
*)

let resolve_with_hints t = 
  let u = resolve t in 
  let _ = add_hints_force u in
    u;;


(* ========================================================================== *)
(* Case: Hard 11                                                             *)
(* ========================================================================== *)
 


(* early note on case 11 *)


let bb = findid "34970074286" hard_bb;;

let bb1 = allpass 2 [bb];;
let bb2 = allpass 4 bb1;;
let bb3 = allpass 15 bb2;;
length bb3;; (* 992 *)
map (fun t -> t.lpvalue) bb3;;

let bbmax = find_max bb3;;
bbmax;;

init_dumpfile bbmax;;
init_hash();;
yn 0;;

dumpfile;;
get_dumpvar "yn.1.*=";; 
get_azim_table dih_y [5;4;3] bbmax;;

get_azim_diff dih_y [4;3;5] bbmax;;
get_tri bbmax;;
biggest_azim_diff dih_y bbmax;;



(* ========================================================================== *)
(* Case: Hard 9                                                               *)
(* ========================================================================== *)
 

Glpk_link.resetc();;
let b1 = allpass_hint 500 [hard 9];;
let bx = nth b1 0;; (* 12.011042 , it has become worse?? *) (* 12.0074 *)
#print_length 600;;
resolve_with_hints bx;; (* 0 *)
let b1' = tl b1;;
let b2 = allpass_hint 500 b1';;


(* ========================================================================== *)
(* Case: Hard 8                                                               *)
(* ========================================================================== *)



(* hard 8 , early notes work in progress.  *)
Glpk_link.resetc();;
let b1 = allpass_hint 500 [hard 8];;
let bx = hd b1;;

(* Aug 3 notes on hard 8. *)
length (filter (fun t-> (t.hints = [])) b1);;
bx;;
sorted_azim_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;; 
display_ampl bx;;
get_azim_table[6;11;4] bx;; (* lll_xww *)
let jj = generate_ineq_datum_p  
  "Dihedral" "{2,2,2.14,2,2.25,2.25}" "{2,2,2,2,2.25,2.25}" "{2.18,2.18,2.18,2.52,2.52,2.52}";;
jj;;
let fjj = ocaml_eval jj;;
testval fjj  [6;11;4] bx;;  (* 0.035  not great, but use it *)

(* Aug 3 am . TO HERE, the ineq above has been added to the system,
   but haven't called remake, the one below is in the makes.  It
   hasn't been added, still at the experimentation stages.  *)

get_azim_table [3;6;4] bx;;   (* lll_wxx *)
let kk = generate_ineq_datum  "Dihedral2" "{2,2,2,2.25,2,2}" "{2.18,2.18,2.18,2.52,2.52,2.52}";;
let fkk = ocaml_eval kk;;
testvalsym fkk [3;6;4] bx;;  (* 0.012, not great, but use *)
let bx1 = clone bx;;
remake_model();;
bx.lpvalue;;  (* 12.05 *)
resolve_with_hints bx1;;  (* This digression has helped.  12.018 *)
length b1;;
get_azim_table [3;4;0] bx;;  
let jj1 = generate_ineq_datum_p  
  "mDihedral" "{2.18,2.1,2.1,2.52,2,2}" "{2,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fjj1 = ocaml_eval jj1;;
testvalsym fjj1 [3;4;0] bx;;  (* 0.045, not great, but use *)
let bx1 = clone bx;;
remake_model();;
resolve_with_hints bx1;;  (* This digression didn't  help, still  12.018 *)
get_azim_table [3;4;0] bx1;;  (* but it made the angles more accurate. *)
sorted_azim_diff darts_of_std_tri bx1;;  (* [6;3;2], a mini *)
get_azim_table [6;3;2] bx1;;
let jj2 = generate_ineq_datum_p 
   "Dihedral" "{2,2.18,2.18,2,2.25,2.25}" "{2,2,2,2,2,2}" "{2.18,2.18,2.18,2.25,2.25,2.25}";;
let fjj2 = ocaml_eval jj2;;
testval fjj2 [6;3;2] bx1;;   (* 0.005 huge improvement, use *)
get_azim_table [6;3;2] bx1;;
let jj3 = generate_ineq_datum_p 
   "mDihedral2" "{2,2.18,2.18,2,2.25,2.25}" "{2,2,2,2,2,2}" "{2.18,2.18,2.18,2.25,2.25,2.25}";;
jj3;;
let fjj3 = ocaml_eval jj3;;
testval fjj3 [6;3;2] bx1;;   (* 0.003 huge improvement, use *)
let bx2 = clone bx;;
remake_model();;
resolve_with_hints bx2;;  (* still 12.018 *)
get_azim_table [6;3;2] bx2;;  (* This didn't fix the angles, there must be a bug *)
(* why didn't 9828015955 ineq get used?? *)
display_lp bx2;;
modelbody;;
Glpk_link.cpx_branch model "/tmp/cpx.out"  ampl_of_bb bx2;;
(* bug found dart_std3_mini incorrectly defined in head.mod, fixed. Aug 3, 2010 *)
let bx2 = clone bx;;
remake_model();;
resolve_with_hints bx2;;  (* still 0.0, bug fixed!, unneeded mini inequalities removed. *)



(* hard 8 , restart work in progress.  *)
Glpk_link.resetc();;
let b1 = allpass_hint 5000 [hard 8];;  (* runs out of hints at 3177, stack stize 1025 *)

(* Aug 4 *)
length b1;;
let bx = hd b1;;
bx;;
sorted_azim_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;; 
unset_edge bx;;
get_azim_table[3;6;4] bx;;
let jj = generate_ineq_datum_p  
  "Dihedral2" "{2.18,2,2,2.52,2,2.25}" "{2,2,2,2.25,2,2}" "{2.18,2.18,2.18,2.52,2.52,2.52}";;
jj;;
let fjj = ocaml_eval jj;;
testval fjj  [3;6;4] bx;;  (* 0.041   use it *)
let jj1 = generate_ineq_datum_p  
  "mDihedral3" "{2.18,2,2,2.52,2,2.25}" "{2,2,2,2.25,2,2}" "{2.18,2.18,2.18,2.52,2.52,2.52}";;
jj1;;
let fjj1 = ocaml_eval jj1;;
testval fjj1  [3;6;4] bx;;  (* 0.018   use it *)
testvalsym fjj1 [11;4;6] bx;;
get_azim_table[11;4;6] bx;;
get_azim_table[3;2;6] bx;;
let bx1 = clone bx;;
let bx1 = resolve_with_hints bx1 (* drops to 0 *);;

(* OK, lets go again *)
map (fun t -> t.lpvalue <- None) b1;;
let b1' = filter_feas_hint b1;;
let b1'' = sortbb b1';;
let bx = hd b1'';;
sort (<) bx.d_edge_200_225;;
resolve_with_hints bx;; 
sorted_azim_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;; 
unset_edge bx;;
get_azim_table[2;7;6] bx;;
get_azim_table[2;6;3] bx;;
get_azim_table[4;6;11] bx;;
get_azim_table[4;3;6] bx;;
let kk1 = generate_ineq_datum
  "mDihedral" "{2.18,2,2,2,2.25,2}" "{2.36,2.18,2.18,2.25,2.52,2.25}";;
let fkk1 = ocaml_eval kk1;;
testval fkk1  [2;7;6] bx;;
testvalsym fkk1[2;6;3] bx;;
testvalsym fkk1[4;6;11] bx;;
testval fkk1[4;3;6] bx;;
let kk2 = generate_ineq_datum_p
  "mDihedral" "{2.18,2,2,2.25,2.52,2}" "{2.18,2,2,2,2.25,2}" "{2.36,2.18,2.18,2.25,2.52,2.25}";;
let fkk2 = ocaml_eval kk2;;
testval fkk2  [2;7;6] bx;;
testvalsym fkk2[2;6;3] bx;;
testvalsym fkk2[4;6;11] bx;;
testval fkk2[4;3;6] bx;;
kk2;;
let kk3 = generate_ineq_datum_p
  "mDihedral" "{2.18,2,2,2.25,2.52,2}" "{2.18,2,2,2,2,2}" "{2.36,2.18,2.18,2.25,2.52,2.52}";;
let fkk3 = ocaml_eval kk3;;
testval fkk3  [2;7;6] bx;;
testvalsym fkk3[2;6;3] bx;;
testvalsym fkk3[4;6;11] bx;;
testval fkk3[4;3;6] bx;;
let kk4 = generate_ineq_datum_p
  "Dihedral2" "{2.18,2,2,2.25,2,2.52}" "{2.18,2,2,2,2,2}" "{2.36,2.18,2.18,2.25,2.52,2.52}";;
let fkk4 = ocaml_eval kk4;;
testval fkk4  [2;7;6] bx;;
testval fkk4[2;6;3] bx;;
testval fkk4[4;6;11] bx;;
testvalsym fkk4[4;3;6] bx;;
kk3;;
kk4;;
remake_model();;
let bcx = clone bx;;
resolve bcx;;

(* OK, lets go again *)
map (fun t -> t.lpvalue <- None) b1'';;
let b2 = sortbb(filter_feas_hint b1'');;
length b2;;
let bx = hd b2;;
bx;;
sort (<) bx.d_edge_225_252;;
unset_edge bx;;
resolve_with_hints bx;; 
sorted_azim_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff darts_of_std_tri bx;; 
(* [6;2;3], [3;6;4], [6;7;12], [6;2;7], [4;6;11], [7;12;6], *)
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;; 
get_azim_table[3;6;4] bx;;

(* continue *)
let b3 = allpass_hint 500 b2;;
let b4 = allpass_hint 1500 b3;;

length b3;;
let bx = hd b3;;
sort (<) bx.d_edge_225_252;;
unset_edge bx;;
sorted_azim_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff darts_of_std_tri bx;; 
get_azim_table[6;7;12] bx;;



(* ========================================================================== *)
(* Case: Hard 7                                                               *)
(* ========================================================================== *)
 


(* starts out at 12.4 *)

let b1 =  allpass_hint 10 [hard 7];;

(* hard 6 done, hard 4 done, hard 2 done *)


(* ========================================================================== *)
(* Case: Hard 5                                                               *)
(* ========================================================================== *)
 

(* starts at 12.291 *)
resetc();;
let b1 = allpass_hint 505 [hard 5];;
length b1;;
let b2 = allpass_hint 5000 b1;;
let bxi = hd !onepass_backup;;




(* ========================================================================== *)
(* Case: Hard 3                                                               *)
(* ========================================================================== *)

resetc();;
let c1 =  allpass_hint 1500 [hard 3];;  
let cx = hd c1;;  (* 12.041 , about 600 cases *)
resolve_with_hints_include_flat cx;;
let c2 = allpass_hint_include_flat 500 c1;;
length c2;;
let cx = hd c2;;  (* 12.036, 598 cases *)
length cx.node_200_218;;
#print_length 1000;;
sorted_azim_diff darts_of_std_tri cx;; (* 0.04 *)
sorted_azim_weighted_diff darts_of_std_tri cx;;  (* 0.012 *)
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  cx;;  (* 0.119 *)
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_sup_flat))  cx;;  (* 0.332 *)
[0;1;2];;
get_azim_table[1;2;0] cx;;
cx;;

let kk1 = generate_ineq_datum
  "mDihedral3" "{2,2,2,sqrt8,2,2}" "{2.52,2.52,2.52,3.0,2.52,2.52}";;
let fkk1 = ocaml_eval kk1;;
testval fkk1  [1;2;0] cx;;  (* improves to 0.024, use. *)
kk1;;

let kk2 = generate_ineq_datum_p
  "Dihedral2" "{2.1,2.1,2.3,sqrt8,2.1,2.1}" "{2,2,2,sqrt8,2,2}" "{2.52,2.52,2.52,3.0,2.52,2.52}";;
let fkk2 = ocaml_eval kk2;;
testval fkk2  [1;2;0] cx;;  (* improves to 0.074, use. *)
kk2;;
remake_model();;
resolve_with_hints_include_flat cx;;

(* restart *)
let c3 = allpass_hint_include_flat 500 c2;;
length c3;; (* 98 , worst is 12.015 *)
let c4 = allpass_hint_include_flat 500 c3;; 


(* rerun *)

b65974205892();;


(* ========================================================================== *)
(* Case: Hard 2                                                               *)
(* ========================================================================== *)



let c1 =  allpass_hint 100 [hard 2];;
let c2 = allpass_hint 1000 c1;;



(* ========================================================================== *)
(* Case: Hard 0                                                               *)
(* ========================================================================== *)


(* NEW CASE *)
resetc();;
(* with prune size 10, the list died out before an empty hint was found *)

let b1 = allpass_prune_hint 80 1000 [hard 0];;
let bx = hd b1;;

sorted_azim_diff darts_of_std_tri bx;; (* [2;0;1]; 0.14,   [0;1;2];   [4;2;1]; [2;3;0]  *)
get_azim_table[0;1;2] bx;;
nub (sort (<) (map (fun t-> t.node_218_252) (filter (fun t-> 2 = length t.node_218_252) b1)));;

bx;;
let kk1 = generate_ineq_datum_p
  "Dihedral" "{2,2.18,2.18,2,2.25,2.25}" "{2,2.18,2.18,2,2,2}" "{2.18,2.52,2.52,2.52,2.52,2.52}";;
let fkk1 = ocaml_eval kk1;;
testval fkk1  [0;1;2] bx;;  (* improves to 0.0727, use. *)
let kk2 = generate_ineq_datum_p
  "mDihedral2" "{2,2.18,2.18,2,2.25,2.25}" "{2,2.18,2.18,2,2,2}" "{2.18,2.52,2.52,2.52,2.52,2.52}";;
let fkk2 = ocaml_eval kk2;;
testvalsym fkk2  [0;1;2] bx;;  (* improves to 0.0402, use. *)
remake_model();;
let bcx = clone bx;;
resolve_with_hints bcx;;

(* restart *)
let b2 = map resolve_with_hints b1;;
let b3 = allpass_prune_hint 80 100 b2;;
let bx = hd b3;; (* 12.02 *)
sorted_azim_diff darts_of_std_tri bx;; (* [3;8;0]; [1;5;4] *)
sorted_azim_weighted_diff darts_of_std_tri bx;; (* [3;8;0]; [1;5;4] *)
get_azim_table[3;8;0] bx;;
bx;;
let b4 = allpass_prune_hint 80 300 b3;;
let bx = hd b4;;  (* 12.007 *)
sorted_azim_diff darts_of_std_tri bx;; (* [4;2;1]; [0;1;2]; [0;3;8]; [4;1;5]; [4;3;2]; *)
sorted_azim_weighted_diff darts_of_std_tri bx;; (* [3;8;0]; [1;5;4] *)
let b5 = allpass_prune_hint 80 300 b4;;  (* this goes to zero as well *)

(* restart *)
resetc();;
let b1 = allpass_hint 10000 [hard 0];;



(* ========================================================================== *)
(* Case: Hard 1                                                               *)
(* ========================================================================== *)


(* NEW CASE *)

resetc();;
let b1 = allpass_hint_include_flat 30000 [hard 1];;
(* runs to 13334 before giving one without hints *)
length b1;;  (* 1430 *)
let bx = hd b1;;  (* 12.004, almost there!  *)
map (fun t-> length t.node_236_252) b1;;
sorted_azim_diff darts_of_std_tri bx;; (* [5;3;2]; [6;5;2]  [5;4;3] *)
sorted_azim_weighted_diff darts_of_std_tri bx;; (* 0 *)
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;;  (* [1;2;3], [1;3;0] *)
bx;;
length bx.node_200_218;;
get_azim_table[2;3;1] bx;;
let kk1 = generate_ineq_datum_p
  "Dihedral3" "{2.36,2.1,2.1,2.6,2.1,2.1}" "{2.18,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fkk1 = ocaml_eval kk1;;
testval fkk1  [2;3;1] bx;; 
let kk3 = generate_ineq_datum_p
  "Dihedral3" "{2.36,2.1,2.1,2.55,2.1,2.0}" "{2.18,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fkk3 = ocaml_eval kk3;;
testval fkk3  [2;3;1] bx;; 
kk3;;
let kk3 = generate_ineq_datum_p
  "Dihedral3" "{2.36,2.1,2.1,2.55,2.1,2.0}" "{2,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fkk3 = ocaml_eval kk3;;
testval fkk3  [2;3;1] bx;; 
kk3;;
let kk2 = generate_ineq_datum_p
  "Dihedral3" "{2.36,2.1,2.1,2.6,2.1,2.1}" "{2.18,2,2,2.52,2,2}" "{2.52,2.18,2.18,sqrt8,2.52,2.52}";;
let fkk2 = ocaml_eval kk2;;
testval fkk2  [2;3;1] bx;; 
get_azim_table[2;5;3] bx;;
let jj1 = generate_ineq_datum_p
  "mDihedral3" "{2.36,2.1,2.1,2.45,2.,2.45}" "{2.18,2,2,2,2,2}" "{2.52,2.18,2.18,2.52,2.52,2.52}";;
let fjj1 = ocaml_eval jj1;;
testval fjj1  [2;5;3] bx;;
jj1;;

get_azim_table[2;5;3] bx;;
let jj2 = generate_ineq_datum_p
  "Dihedral2" "{2.36,2.1,2.1,2.45,2.,2.45}" "{2.18,2,2,2,2,2}" "{2.52,2.18,2.18,2.52,2.52,2.52}";;
let fjj2 = ocaml_eval jj2;;
testval fjj2  [2;5;3] bx;;
jj2;;

get_azim_table[2;6;5] bx;;
testvalsym fjj1 [2;6;5] bx;;
testvalsym fjj2 [2;6;5] bx;;

kk3;;
Ineq.getexact "6725783616";;
Ineq.getexact "9185711902";;
Ineq.getexact "6284721194";;
remake_model();;
let bcx = clone bx;;
resolve_with_hints bcx;;

(* restart *)
let b1' = map resolve_with_hints_include_flat b1;;

let b2 = sortbb(filter_feas_hint b1);;
length b2;;  (* 564, this is more reasonable! *)
let bx = hd b2;;
sorted_azim_diff darts_of_std_tri bx;; (* [5;11;10] [5;4;3] [1;6;2] *)
sorted_azim_weighted_diff darts_of_std_tri bx;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;;
get_azim_table [2;3;1] bx;;
let b3 = allpass_hint_include_flat 1000 b2;;
length b3;; (* down to 158 *)
let b4 = allpass_hint_include_flat 1000 b3;;
b4 = [];;


(* ========================================================================== *)
(* Case: Hard 5                                                               *)
(* ========================================================================== *)


resetc();;
let b1 =  allpass_hint_include_flat 30000 [hard 5];;
let bx = hd b1;;
sorted_azim_diff darts_of_std_tri bx;; (* [5;9;0]; [1;0;9];  *)
sorted_azim_weighted_diff darts_of_std_tri bx;;  (* 0 *)
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  bx;; (* [1;3;0]  [5;0;3] *)
get_azim_table [0;1;3]bx ;;
get_azim_table [0;3;5] bx;;
length b1;; (* 1575 *)
map (fun t-> (length t.node_218_236,length t.node_236_252)) b1;;
map (fun t -> t.node_218_236) b1;;
bx;; (* 12.014 *)
let jj1 = generate_ineq_datum_p
  "Dihedral2" "{2.25,2,2.18,2.65,2.,2.2}" "{2.18,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fjj1 = ocaml_eval jj1;;
testval fjj1  [0;1;3] bx;;
testvalsym fjj1  [0;3;5] bx;;  (* use *)
let jj2 = generate_ineq_datum_p
  "Dihedral2" "{2.25,2,2.18,2.65,2.,2.2}" "{2.18,2,2,2.52,2,2}" "{2.36,2.52,2.52,sqrt8,2.52,2.52}";;
let fjj2 = ocaml_eval jj2;;  (* don't use *)
testval fjj2  [0;1;3] bx;;
remake_model();;
let bcx = clone bx;;


(* restart case 5 *)
resetc();;
let b1 =  allpass_hint_include_flat 30000 [hard 5];;

(* This is the last of the 
linear programming cases.  This is when it finished running:
Thu Aug  5 13:31:11 ICT 2010  *)


1;;

(* ========================================================================== *)
(* Case: OLD NOTES, 2009- July 31, 2010                                       *)
(* ========================================================================== *)

(* OLD *)

(* pick it up here tomorrow *)
let jj = generate_ineq_datum_p
  "mDihedral" "{2.09,2.1,2.1,2.52,2,2}"  
   "{2,2,2,2.52,2,2}" "{2.18,2.52,2.52,sqrt8,2.52,2.52}";;
let fn = Temp_ineq.ocaml_eval jj;;
testvalsym fn [3;4;0] bx;;

testvalsym (Temp_ineq.ocaml_eval(hd(Ineq.getexact "8384511215"))) [0;3;5] bx;;
testvalsym (Temp_ineq.ocaml_eval(hd(Ineq.getexact "7291663656"))) [0;3;5] bx;;
testvalsym (fun y1 y2 y3 y4 y5 y6 -> [y1;y2;y3;y4;y5;y6]) [0;3;5] bx;;
let jj = generate_ineq_datum_p
  "Dihedral2" "{2.18,2.18,2,2.65,2,2.3}"  
   "{2,2,2,2.52,2,2}" "{2.18,2.52,2.52,sqrt8,2.52,2.52}";;


get_azim_table [0;1;3] bx;;
let ii = generate_ineq_datum_p "Dihedral2" "{2,2,2.3,2.65,2,2.2}"
 "{2,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let fn = Temp_ineq.ocaml_eval ii;;
testvalsym fn [0;3;5] bx;; (* 0.139931, lousy here, need a new ineq. *)
testval fn [4;5;3] bx;;  (* 0.0629 , install it. *)
testval fn [0;1;3] bx;;  (* 0.0464 , install it. *)
testvalsym (fun y1 y2 y3 y4 y5 y6 -> [y1;y2;y3;y4;y5;y6]) [0;3;5] bx;;
let jj = generate_ineq_datum_p "Dihedral2" "{2.18,2.0,2.2,2.6,2.0,2.25}"
   "{2,2,2,2.52,2,2}" "{2.52,2.52,2.52,sqrt8,2.52,2.52}";;
let jj = generate_ineq_datum 
  "Dihedral" "{2,2,2,2,2,2}" "{2.18,2.18,2.18,2.25,2.25,2.25}";;
let jj = generate_ineq_datum_p
  "Dihedral" "{2,2.1,2.1,2,2.25,2.25}" "{2,2,2,2,2,2}" "{2.18,2.18,2.18,2.25,2.25,2.25}";;
let fnjj = Temp_ineq.ocaml_eval jj;;
let idq = hd(Ineq.getexact "9229542852");;
let fn9 = Temp_ineq.ocaml_eval idq;;
testval fnjj [5;9;0] bx;;
get_azim_table [5;9;0] bx;;
remake_model();;
resolve (hard 9);;



(* OLD experiments *)

#print_length 600;;;
let bx = hd b2;;
bx;; (* 12.001 *)
sorted_azim_diff darts_of_std_tri bx;; 
get_azim_table [2;0;1] bx;;
get_azim_table [2;3;0] bx;;
get_azim_table [2;1;4] bx;;
let ii = hd(Ineq.getexact "7409690040");;
ocaml_fun_of_ineq  ii.ineq;;
let fxx = (fun y1 y2 y3 y4 y5 y6 -> ( dih2_y y1 y2 y3 y4 y5 y6  +. 0.0042) -. (0.952682 +. (((-. 0.268837) *. ((-. 2.36) +. y1)) +. ((0.130607 *. ((-. 2.) +. y2)) +. (((-. 0.168729) *. ((-. 2.) +. y3)) +. (((-. 0.0831764) *. ((-. 2.52) +. y4)) +. ((0.580152 *. ((-. 2.) +. y5)) +. (0.0656612 *. ((-. 2.25) +. y6)))))))));;
testval fxx [2;0;1] bx;;
remake_model();;
resolve amx2;;  (* 2.063 *)
add_hints_force amx2;;


(* <= Jul 31 2010 *)

let tests = ref [];;

(* std4_diag3 disappears: *)
length hard_bb;;  (* 12 *)


let testsuper _ = 
  let allhardpassA_bb = allpass 3 hard_bb in 
  let allhardpassS_bb =  (filter (fun t -> length t.std4_diag3 >0) allhardpassA_bb) in
  let allhardpassF_bb =  filter (fun t -> ( length t.std4_diag3 = 0) && (length t.apex_sup_flat > 0))  allhardpassA_bb in 
    allhardpassS_bb = [] && allhardpassF_bb = [];; 

tests := testsuper :: !tests;;

(* July 29 , 2010  "161847242261" starts out 12.06... *)
let b1 = onepass_hint [hard 0];;
let b2 = allpass_prune_hint 15 [hard 0];;
let b3 = allpass_prune_hint 15 b2;;
let b4 = allpass_prune_hint 15 b3;;
let b5 = allpass_prune_hint 15 b4;;
map (fun bb -> bb.hints) b5;;
let c1 = find_max b5;;  (* runs out of hints at this stage, length of b5 is only 8 *)

(* 223336279535, starts out at 12.130 *)
let a1 = onepass_hint [hard 1];;
let a2 = allpass_prune_hint 5 15 [hard 1];;
let a3 = allpass_prune_hint 5 15 a2;;
find_max (!onepass_backup);;

(* see where this goes....  July 29, 2010, stack started at 145 *)
let a_test_july29 = allpass_prune_hint 40 80 hard_bb;;
let a0 = a_test_july29;;
map (fun bb -> bb.hints) a0;; (* no hints left *)
let amx = find_max (a0);;
map (fun bb -> bb.hypermap_id) a0;;
get_azim_table [4;5;3] amx;;
get_azim_table [0;3;5] amx;;
 (fun bb -> (bb.node_200_218,bb.node_218_236,bb.node_236_252)) amx;;
fst(chop_list 15 (sorted_azim_diff darts_of_std_tri amx));;


darts_of_std_tri;;
find_max (!onepass_backup);;

#print_length 600;;
amx;;
let amx2 =   {hypermap_id = "154005963125"; lpvalue = None; hints = [];
   diagnostic = No_data;
   string_rep =
    "154005963125 20 4 0 1 2 3 4 0 3 4 5 3 4 3 2 3 4 2 6 3 6 2 7 3 7 2 1 3 7 1 8 3 8 1 9 3 9 1 0 3 9 0 5 3 9 5 10 3 10 5 11 3 11 5 4 3 11 4 6 3 11 6 12 3 12 6 7 3 12 7 8 3 12 8 10 3 8 9 10 3 10 11 12 ";
   std_faces_not_super =
    [[4; 3; 2]; [4; 2; 6]; [6; 2; 7]; [7; 2; 1]; [7; 1; 8]; [8; 1; 9];
     [9; 1; 0]; [9; 0; 5]; [9; 5; 10]; [10; 5; 11]; [11; 5; 4]; [11; 4; 6];
     [11; 6; 12]; [12; 6; 7]; [12; 7; 8]; [12; 8; 10]; [8; 9; 10];
     [10; 11; 12]];
   std56_flat_free = []; std4_diag3 = [];
   std3_big = [[7; 1; 8]; [9; 1; 0]; [9; 0; 5]; [8; 1; 9]; [9; 5; 10]];
   std3_small =
    [[11; 4; 6]; [6; 2; 7]; [10; 11; 12]; [11; 6; 12]; [12; 6; 7];
     [12; 7; 8]; [7; 2; 1]; [4; 2; 6]; [11; 5; 4]; [12; 8; 10]; [10; 5; 11];
     [8; 9; 10]; [4; 3; 2]];
   apex_sup_flat = [];
   apex_flat = [[4; 5; 3]; [0; 3; 5]; [2; 3; 1]; [0; 1; 3]]; apex_A = [];
   apex5 = []; apex4 = [];
   d_edge_225_252 = [[5; 9; 0]; [9; 1; 0]; [9; 5; 10]; [1; 9; 8]];
   d_edge_200_225 =
    [[11; 4; 6]; [4; 6; 11]; [6; 11; 4]; [6; 2; 7]; [2; 7; 6]; [7; 6; 2];
     [10; 11; 12]; [11; 12; 10]; [12; 10; 11]; [11; 6; 12]; [6; 12; 11];
     [12; 11; 6]; [12; 6; 7]; [6; 7; 12]; [7; 12; 6]; [12; 7; 8]; [7; 8; 12];
     [8; 12; 7]; [7; 2; 1]; [2; 1; 7]; [1; 7; 2]; [4; 2; 6]; [2; 6; 4];
     [6; 4; 2]; [11; 5; 4]; [5; 4; 11]; [4; 11; 5]; [7; 1; 8]; [8; 7; 1];
     [1; 8; 7]; [12; 8; 10]; [8; 10; 12]; [10; 12; 8]; [0; 5; 9]; [9; 0; 5];
     [10; 5; 11]; [5; 11; 10]; [11; 10; 5]; [8; 9; 10]; [9; 10; 8];
     [10; 8; 9]; [0; 9; 1]; [1; 0; 9]; [10; 9; 5]; [8; 1; 9]; [9; 8; 1];
     [5; 10; 9]; [4; 3; 2]; [3; 2; 4]; [2; 4; 3]];
   node_218_252 = [3]; node_236_252 = [3]; node_218_236 = [];
   node_200_218 = [6; 11; 12; 7; 2; 0; 4; 10; 5; 9; 1; 8]};;

(* amx2;; 2.1878 *)
resolve amx2;;
add_hints_force amx2;;
sorted_azim_diff darts_of_std_tri amx2;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  amx2;; 
(* [(0.17937279505957382, [3; 4; 5]); (0.129169044058939808, [5; 3; 4]);
   (0.115889948342437377, [5; 0; 3]); (0.101279767307688728, [1; 3; 0]);
   (0.101279767307671298, [1; 2; 3]); (0.081429255816779289, [0; 3; 5]);];; *)
(* added new ineq 4750199435 *)
resolve amx2;;  (* 2.1718 *)
add_hints_force amx2;;
sorted_azim_diff darts_of_std_tri amx2;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  amx2;; 
amx2;;
get_azim_table [4;5;3] amx2;;
get_azim_table [0;3;5] amx2;;
get_azim_table [0;1;3] amx2;;
get_azim_table [2;3;1] amx2;;
let f00 = (fun y1 y2 y3 y4 y5 y6 -> (( Sphere_math.dih2_y y1 y2 y3 y4 y5 y6  -.  1.083) +. (((0.6365 *. (y1 -.  2.)) -.  (0.198 *. (y2 -.  2.))) +. ((0.352 *. (y3 -.  2.)) +. (((0.416 *. (y4 -.  2.52)) -.  (0.66 *. (y5 -.  2.))) +. (0.071 *. (y6 -.  2.)))))) -. 0.);;

let dih2_y = Sphere_math.dih2_y;;

ocaml_fun_of_ineq i8384511215.ineq;;
let fxx = (fun y1 y2 y3 y4 y5 y6 -> ( dih2_y y1 y2 y3 y4 y5 y6  +. 0.0015) -. (0.913186 +. (((-. 0.390288) *. ((-. 2.) +. y1)) +. ((0.115895 *. ((-. 2.) +. y2)) +. ((0.164805 *. ((-. 2.52) +. y3)) +. (((-. 0.271329) *. ((-. 2.82843) +. y4)) +. ((0.584817 *. ((-. 2.) +. y5)) +. ((-. 0.170218) *. ((-. 2.) +. y6)))))))));;

testval f00 [4;5;3] amx2;;

remake_model();;
resolve amx2;;  (* 2.063 *)
add_hints_force amx2;;
sorted_azim_diff darts_of_std_tri amx2;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  amx2;; 
get_azim_table[8;1;9] amx2;;
get_azim_table[0;5;9] amx2;;
get_azim_table[0;9;1] amx2;;
ocaml_fun_of_ineq  i7819193535.ineq;;
let fxx = (fun y1 y2 y3 y4 y5 y6 -> ( dih2_y y1 y2 y3 y4 y5 y6  +. 0.0011) -. (1.16613 +. (((-. 0.296776) *. ((-. 2.) +. y1)) +. ((0.208935 *. ((-. 2.) +. y2)) +. (((-. 0.243302) *. ((-. 2.) +. y3)) +. (((-. 0.360575) *. ((-. 2.25) +. y4)) +. ((0.636205 *. ((-. 2.) +. y5)) +. ((-. 0.295156) *. ((-. 2.) +. y6)))))))));;
testval fxx [8;1;9] amx2;;

remake_model();;
resolve amx2;;  (* 2.056 *)
add_hints_force amx2;;
sorted_azim_diff darts_of_std_tri amx2;; 
sorted_azim_weighted_diff (fun bb -> rotation (bb.apex_flat))  amx2;; 
get_azim_table[0;3;5] amx2;;
get_azim_table[0;5;9] amx2;;
get_azim_table[0;9;1] amx2;;
ocaml_fun_of_ineq i2621779878.ineq;;
let fxx = (fun y1 y2 y3 y4 y5 y6 -> ( dih2_y y1 y2 y3 y4 y5 y6  +. 0.0011) -. (1.16613 +. (((-. 0.296776) *. ((-. 2.) +. y1)) +. ((0.208935 *. ((-. 2.) +. y2)) +. (((-. 0.243302) *. ((-. 2.) +. y3)) +. (((-. 0.360575) *. ((-. 2.25) +. y4)) +. ((0.636205 *. ((-. 2.) +. y5)) +. ((-. 0.295156) *. ((-. 2.) +. y6)))))))));;
testval fxx [8;1;9] amx2;;

(* material from 2009 *)
(* case 86506100695 *)
let h86 _ =
  let h86 = [findid "86506100695" hard_bb] in
  let h86a = allpass 10 h86 in
  let h86b = allpass 10  h86a in
    allvpass h86b = [];;
tests := h86 :: !tests;;


(* the 2 pressed icosahedra remain *)

let hard2_bb = filter (fun t -> mem t.hypermap_id ["161847242261";"223336279535"]) hard_bb;;


length hard2_bb;;
let h16 = allvpass (findall "161847242261" hard_bb);;
let h16max = find_max h16;;  (* 12.0627 *)
let b16 = h16;;
let b16a = all_highvpass b16;;
length b16a;;
let b16Amax = find_max b16a;; (* 12.0627 *)
let b16b =   (one_epass b16a);;
let b16c  = one_epass (one_epass b16b);;
let b16d = one_epass b16c;;
length b16d;;
let b16e = find_max b16d;;   (* 12.051 *)
0;; (* -- *)
let c16a= allpass 10 b16d;;
let c16Amax = find_max c16a;; (* 12.048 *)  (* was 12.059 *)
length c16a;;  (* 997 *)
let c16b = allpass 15 c16a;;
let c16Bmax = find_max c16b;;  (* 12.026 *) (* was 12.037 *)
length c16b;;  (* 657 *) (* was 636 *)


(*

(* this one is a dodecahedron modified with node 2 pressed
    into an edge *)
  let h  = findid (nth hardid 3);;  (* 12223336279535  *)
  let h1 = allpass [h];;
  length h1;;   (* length 1885 *)
  let k1 = find_max h1;;  (* 12.0416 *)
  let h2 = onevpassi h1 2;; (* length h2 : 2637 *)
(* unfinished... *)

(* this one is triangles only, types {6,0}, {4,0}, {6,0}. *)
  let r  = findid (nth hardid 5);;  (* 12161847242261  *)
  length r1;;   (* length  *)
  let r1 = allvpass [r];;
  let r2 = allpass r1;;
(* unfinished *)

*)




(*
let allhardpassB_bb = allpass 8 hard2_bb;;
*)

(*
let hard2_bb = [nth  hard_bb 0;nth hard_bb 1];;
(* to here *)

length (allhardpassB_bb);;  (* 288 *)
let h16 = find_max allhardpassB_bb;;
(* unfinished *)
*)

(*
let h0 = nth hard_bb 0;;
let h1 = 
  let s i l= flatten((map (fun t -> switch_node t i)) l) in
  let branches =   s 4(  s 3(  s 2(  s 1 (s 0 [h0])) ) )  in
   filter_feas branches;;
length h1;;
find_max h1;;
let all16_bb = allpass 6 h1;;
(* unfinished *)
*)


(* ========================================================================== *)
(* Case: OLD NOTES, Aug 4, 2010                                               *)
(* ========================================================================== *)

(* Don't need the rest of the file, if execute works. *)

(* this eliminates case 11 *)
let b34970074286() = allpass_hint 500 [hard 11];;

(* this eliminates case 10, about 5000 linear programs *)

let b75641658977() = allpass_hint 2500 [hard 10];;

(*
  let b1 = allpass_hint 500 [hard 10] in
  let b2 = allpass_hint 500 b1 in
  let b3 = allpass_hint 500 b2 in
  let b4 = allpass_hint 500 b3 in
  let b5 = allpass_hint 500 b4 in
    b5;;
*)


let b88089363170() = allpass_hint 1000 [hard 9];;

let b86506100695() = allpass_hint 2000 [hard 8];;

let b242652038506() =  allpass_hint_include_flat 10 [hard 7];;

let b179189825656() = allpass_hint 50 [hard 6];;

let b154005963125() = allpass_hint 3000 [hard 5];;

let b39599353438() = allpass_hint 10 [hard 4];;

let b65974205892() = allpass_hint 30 [hard 3];;

let b50803004532() = allpass_hint 500 [hard 2];;

let b223336279535() = allpass_hint_include_flat 20000 [hard 1];;

let b161847242261() = allpass_hint 5000 [hard 0];;  (* runs to 3583 *)