diff options
-rw-r--r-- | mppa_k1c/InstructionScheduler.ml | 13 | ||||
-rwxr-xr-x | scripts/cplex/ilp_solver | 11 |
2 files changed, 19 insertions, 5 deletions
diff --git a/mppa_k1c/InstructionScheduler.ml b/mppa_k1c/InstructionScheduler.ml index 73e73e15..ce687678 100644 --- a/mppa_k1c/InstructionScheduler.ml +++ b/mppa_k1c/InstructionScheduler.ml @@ -1050,6 +1050,17 @@ let ilp_print_problem channel problem pb_type = mapper_final_predecessors = predecessors.(nr_instructions) };; +(* Guess what? Cplex sometimes outputs 11.000000004 instead of integer 11 *) + +let positive_float_round x = truncate (x +. 0.5) + +let float_round (x : float) : int = + if x > 0.0 + then positive_float_round x + else - (positive_float_round (-. x)) + +let rounded_int_of_string x = float_round (float_of_string x) + let ilp_read_solution mapper channel = let times = Array.make (match mapper.mapper_pb_type with @@ -1075,7 +1086,7 @@ let ilp_read_solution mapper channel = (if tnumber < 0 || tnumber >= (Array.length times) then failwith (Printf.sprintf "bad ilp output: not a correct variable number: %d (%d)" tnumber (Array.length times))); let value = - try int_of_string (String.sub line (space+1) ((String.length line)-space-1)) + try rounded_int_of_string (String.sub line (space+1) ((String.length line)-space-1)) with Failure _ -> failwith "bad ilp output: not a time number" in diff --git a/scripts/cplex/ilp_solver b/scripts/cplex/ilp_solver index a449c203..1e70a652 100755 --- a/scripts/cplex/ilp_solver +++ b/scripts/cplex/ilp_solver @@ -1,7 +1,10 @@ #!/bin/sh tmp=$2.tmp rm -f $tmp $2 -cplex -c "read $1" "optimize" "write $tmp sol" -grep '<variable name="' $tmp | sed -e 's@ *<variable name="@@' -e 's@" index=.* value="@ @' -e 's@"/>@@' > $2 -touch $2 -rm -f $tmp +if cplex -c "read $1" "optimize" "write $tmp sol"; +then + grep '<variable name="' $tmp | sed -e 's@ *<variable name="@@' -e 's@" index=.* value="@ @' -e 's@"/>@@' > $2 + rm -f $tmp +else + exit $? +fi |