Skip to content

Commit 3414094

Browse files
committed
Implement guessing
1 parent f3e57be commit 3414094

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

fortran/solver/src/API.f90

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module API_mod
33
use plan_mod, only: plan_t
44
implicit none
55
private
6-
public :: select, explore
6+
public :: select, explore, guess
77
contains
88
subroutine select(task)
99
type(task_t), intent(in) :: task
@@ -104,4 +104,31 @@ subroutine explore(task, plans)
104104
close(lu, status = "delete")
105105

106106
end subroutine explore
107+
subroutine guess(task, solution)
108+
type(task_t), intent(in) :: task
109+
character(len=*), intent(in) :: solution
110+
111+
character(len=:), allocatable :: command, header, request, data
112+
113+
integer :: lu
114+
115+
open(newunit = lu, file = "guess", status = "unknown")
116+
close(lu, status = "delete")
117+
118+
header = ' --header "Content-Type: application/json" '
119+
request = ' --request POST '
120+
data = ' --data ''{ "id": "' // task%API_ID // '", ' // solution // ' }'' '
121+
122+
command = 'curl -s ' // header // request // data // task%API_URL // '/guess > guess'
123+
call execute_command_line(command, wait=.true.)
124+
125+
open(newunit = lu, file = "guess", status = "old")
126+
block
127+
integer :: idx
128+
data = repeat(" ", 1024)
129+
read(lu, '(A)') data
130+
print '(A,A)', 'Resolution: ', trim(data)
131+
end block
132+
close(lu, status = "delete")
133+
end subroutine guess
107134
end module API_mod

fortran/solver/src/solution.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function connection_t_to_json(connection) result(json)
3030
class(connection_t), intent(in) :: connection
3131
character(len=:), allocatable :: json
3232
character(len=120) :: json_tmp
33-
write(json_tmp, '(A,4(I0,A))') '{ "from": { "room": ', connection%room_out, ', ' // &
33+
write(json_tmp, '(A,4(I0,A))') '{ "from": { "room": ', connection%room_out - 1, ', ' // &
3434
'"door": ', connection%door_out, ' }, ' // &
35-
'"to": { "room": ', connection%room_in, ', ' // &
35+
'"to": { "room": ', connection%room_in - 1, ', ' // &
3636
'"door": ', connection%door_in, ' } }'
3737
json = trim(json_tmp)
3838
end function connection_t_to_json
@@ -77,7 +77,7 @@ function solution_t_to_json(solution) result(json)
7777
json = json // trim(tmp)
7878
if (i /= size(solution%connections) / 6) json = json // ', '
7979
end do
80-
json = json // ' ], "startingRoom": 1, "connections": [ '
80+
json = json // ' ], "startingRoom": 0, "connections": [ '
8181
do i = 1, size(solution%connections)
8282
json = json // solution%connections(i)%to_json()
8383
if (i /= size(solution%connections)) json = json // ', '

fortran/solver/src/solver.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module solver_mod
66
type :: solver_t
77
logical(1) :: inited = .false.
88
type(library_t) :: library
9+
type(task_t) :: task
910
contains
1011
procedure :: init
1112
procedure :: submit
@@ -35,6 +36,7 @@ subroutine init(solver, arg)
3536
end do
3637
call solver%library%refine()
3738
call solver%library%show()
39+
solver%task = task
3840
contains
3941
function generate_plans(task) result(plans)
4042
type(task_t) :: task
@@ -53,8 +55,10 @@ end function generate_plans
5355
end subroutine init
5456
subroutine submit(solver)
5557
use solution_mod, only: solution_t
58+
use API_mod, only: guess
5659
class(solver_t), intent(inout) :: solver
5760
type(solution_t) :: solution
5861
call solution%init(solver%library)
62+
call guess(solver%task, solution%to_json())
5963
end subroutine submit
6064
end module solver_mod

0 commit comments

Comments
 (0)