Skip to content

Commit bc1341d

Browse files
committed
Implement infinity search
1 parent 7f4be91 commit bc1341d

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

fortran/solver/src/solver.f90

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,32 @@ subroutine solve(solver)
5858
use guess_mod, only: guess_t
5959
class(solver_t), intent(inout) :: solver
6060
type(guess_t), allocatable :: guess(:)
61-
integer, parameter :: N_guess = 1024
62-
integer :: iter, guess_id, max_length
63-
allocate(guess(N_guess))
64-
do guess_id = 1, N_guess
65-
call guess(guess_id)%init(solver%library)
66-
end do
67-
do iter = 1, 6 * 9 * size(solver%library%rooms)
68-
max_length = 0
61+
integer, parameter :: N_guess = 4096
62+
integer :: iter, guess_id, max_length, corr_id
63+
corr_id = -1
64+
infinity: do
65+
if (allocated(guess)) deallocate(guess)
66+
allocate(guess(N_guess))
6967
do guess_id = 1, N_guess
70-
call guess(guess_id)%eval()
71-
call guess(guess_id)%next()
72-
max_length = max(max_length, guess(guess_id)%max_length)
68+
call guess(guess_id)%init(solver%library)
7369
end do
74-
print '("iter: ",I4," ML:",I4)', iter, max_length
75-
end do
76-
call guess(1)%set_solution(solver%library)
70+
iterations: do iter = 1, 3 * 9 * size(solver%library%rooms)
71+
max_length = 0
72+
do guess_id = 1, N_guess
73+
call guess(guess_id)%eval()
74+
call guess(guess_id)%next()
75+
max_length = max(max_length, guess(guess_id)%max_length)
76+
if (max_length == size(solver%library%plans(1)%steps)) then
77+
corr_id = guess_id
78+
exit infinity
79+
end if
80+
end do
81+
print '("iter: ",I4," ML:",I4)', iter, max_length
82+
end do iterations
83+
end do infinity
84+
85+
if (corr_id < 0) error stop "solution not found"
86+
call guess(corr_id)%set_solution(solver%library)
7787
end subroutine solve
7888
subroutine submit(solver)
7989
use solution_mod, only: solution_t

0 commit comments

Comments
 (0)