|
|
이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
이대근
가입: 2012년 10월 26일 올린 글: 5
|
올려짐: 2012년12월21일 22:49 주제: 프로젝트 1, 2 테스트셋 공유합니다 |
|
|
1번
코드: |
let rec test n =
let rec range i j = if i > j then [] else i :: (range (i+1) j)
in let comb n l =
let rec comb l c =
if List.length c = n then [c]
else match l with []->[] | (h::t) -> (comb t (h::c))@(comb t c)
in comb l []
in let rec colinear triples =
match triples with
([(ax,ay);(bx,by);(cx,cy)]::t) -> if (cx-ax)*(by-ay) = (cy-ay)*(bx-ax) then true else (colinear t)
| _ -> false
in let rec check tuples =
match tuples with
([(ax,ay);(bx,by)]::t) -> if intersect ax ay bx by then false else (check t)
| _ -> true
and intersect x1 x2 x3 x4 =
((ccw x1 x2 x3) * (ccw x1 x2 x4) <= 0) && ((ccw x3 x4 x1) * (ccw x3 x4 x2) <= 0)
and ccw (px,py) (qx,qy) (rx,ry) =
let (dx1, dy1, dx2, dy2) = (qx-px, qy-py, rx-px, ry-py) in
if dx1*dy2 > dy1*dx2 then 1
else if dx1*dy2 < dy1*dx2 then -1
else if ((dx1*dx2 < 0) || (dy1*dy2 < 0)) then -1
else if ((dx1*dx1 + dy1*dy1) < (dx2*dx2 + dy2*dy2)) then 1
else 0
in
let rlocs = List.map (fun i -> (string_of_int i, (Random.int 10001, Random.int 10001))) (range 1 n)
in let slocs = List.map (fun i -> (i, (Random.int 10001, Random.int 10001))) (range 1 n)
in let coords = (List.map snd rlocs) @ (List.map snd slocs)
in
if colinear (comb 3 coords) then (print_string "Degenerated.\n";)
else
let stime = Sys.time()
in let res = Duststorm.shelterAssign rlocs slocs
in let etime = Sys.time()
in let lines = List.map (fun (r,s) -> (snd(List.find (fun x -> fst(x) = r) rlocs),
snd(List.find (fun x -> fst(x) = s) slocs))) res
in
if check (comb 2 lines) then print_string "True. " else print_string "False. ";
Printf.printf "time=%.2fs.\n" (etime -. stime)
|
2번
코드: |
let test m c y =
let rec range i j = if i > j then [] else i :: (range (i+1) j)
in let check mat1 mat2 =
let f = fun i -> ((fun x -> fun y -> (abs_float(x-.y) < 0.0001)) (Markov.ij mat1 0 i) (Markov.ij mat2 0 i))
in let n = snd(Markov.size(mat1))
in List.fold_left (&&) true (List.map f (range 1 (n-1)))
in let stime = Sys.time()
in let x = Markov.markov_limit m c
in let etime = Sys.time()
in
if check x y then print_string "True. " else print_string "False. ";
Printf.printf "time=%.2fs.\n" (etime -. stime)
let _ =
let m = Markov.add_row [5.;6.]
(Markov.add_row [3.;4.]
(Markov.row [1.;2.]))
in
if (Markov.ij m 0 1) = 3. && (Markov.ij m 1 0) = 2. && (Markov.size m) = (2,3) then
print_string "True.\n"
else print_string "False.\n"
;
let m = Markov.add_column [0.0000001;0.;0.;0.9999999]
(Markov.add_column [1.;0.;0.;0.]
(Markov.add_column [0.;0.;1.;0.]
(Markov.column [0.;1.;0.;0.])))
and c = Markov.column [1.;2.;3.;4.]
and y = Markov.column [3.33333333;3.33333333;3.33333333;0.]
in test m c y
;
let m = Markov.add_row [1.;0.]
(Markov.row [0.;1.])
and c = Markov.column [2.;4.]
and y = Markov.column [3.;3.]
in test m c y
;
let m = Markov.add_column [0.;1.;0.]
(Markov.add_column [1./.3.;1./.3.;1./.3.]
(Markov.column [1./.2.;1./.2.;0.]))
and c = Markov.column [1.;1.;1.]
and y = Markov.column [1.;1.5;0.5]
in test m c y
|
저는 이렇게 나옵니다.
코드: |
# test 50;;
True. time=0.02s.
- : unit = ()
# test 50;;
True. time=0.02s.
- : unit = ()
# test 50;;
True. time=0.01s.
- : unit = ()
|
코드: |
True.
True. time=0.00s.
True. time=0.00s.
True. time=0.00s.
|
덧: 1번 테스트데이터 생성기는 degenerated 되는 경우를 줄이기 위해 [0, 10000] x [0, 10000] 좌표를 씁니다. |
|
위로 |
|
|
이계원
가입: 2012년 9월 14일 올린 글: 9
|
올려짐: 2012년12월21일 23:04 주제: |
|
|
1번이 잘 안나오네요;; 잘못짰나;; ㅠㅠ |
|
위로 |
|
|
최지헌
가입: 2012년 9월 6일 올린 글: 35
|
올려짐: 2012년12월21일 23:13 주제: |
|
|
1번 맵 크기가 10000이라서 충돌 판별함수 짤때 int 범위 초과하면 안나온대요
충돌 판별함수 보통 부호만 중요하니 1, -1, 0으로 바꿔놓고 하니까 잘되네요.
테스트셋 감사합니다 이 대근 학우님 |
|
위로 |
|
|
이계원
가입: 2012년 9월 14일 올린 글: 9
|
올려짐: 2012년12월21일 23:17 주제: |
|
|
10000, 10000을 1000정도로 제한하니 잘되네요. 어느정도 올라가면 degenerated되긴 하지만.. 대근아 고마워 |
|
위로 |
|
|
|
|
새로운 주제를 올릴 수 없습니다 답글을 올릴 수 없습니다 주제를 수정할 수 없습니다 올린 글을 삭제할 수 없습니다 투표를 할 수 없습니다
|
Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group Translated by kss & drssay
|