// File: /workspace/github_cpp_makefile_star2_O1/uclaopt[P]AsyncQVI/include/algo.h
// Function: VRVI::solve()
void solve(){
			srand (time(NULL));
			for(int t = 0; t < params->max_outer_iter; t++){
				
				// approximate x
				for(int i = 0; i < params->len_state; i++){
					for(int a = 0; a < params->len_action; a++){
						(*x)[i][a] = 0;
						for(int n = 0; n < params->sample_num_1; n++){
							s.SO(i, a, next_state, r);
							(*x)[i][a] += (*v_outer)[next_state];
						}
						(*x)[i][a] /= params->sample_num_1;
					}
				}
				
				// RandomizedVI
				for(int k = 0; k < params->max_inner_iter; k++){
					// APXVAL
					for(int i = 0; i < params->len_state; i++){
						for(int a = 0; a < params->len_action; a++){
							temp = 0.;
							for(int n = 0; n < params->sample_num_2; n++){
								s.SO(i, a, next_state, r);
								temp += r + params->gamma * ((*v_inner)[next_state]-(*v_outer)[next_state]);
							}
							temp = temp/params->sample_num_2 + params->gamma * (*x)[i][a]
								- 2*params->gamma*params->epsilon;
							if (temp > (*v_inner)[i]){
								(*v_inner)[i] = temp;
								(*pi)[i] = a;
							}
						}
					}
				}
				
				// reset parameters. The resetting fashion is tunable
				params->epsilon /= 2.;
				params->sample_num_1 *= 4;
				params->sample_num_2 *= 4;
				
				*v_outer = *v_inner;
				if(t % params->check_step==0){
					test_sailing(s, pi, params);
				}
		
			}
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x21b0
movl %eax, %edi
callq 0x21d0
movq 0x14f8(%rbx), %rax
cmpl $0x0, 0x34(%rax)
jle 0x4ad0
movq %rbx, %r9
leaq 0x20(%rbx), %r15
leaq 0x8(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x10(%rbx), %r8
movq %r15, 0x10(%rsp)
movq %r8, 0x20(%rsp)
movq %r14, 0x30(%rsp)
movq 0x14f8(%r9), %rax
cmpl $0x0, (%rax)
jle 0x48be
xorl %r13d, %r13d
movq 0x14f8(%r9), %rax
cmpl $0x0, 0x4(%rax)
jle 0x48a8
leaq (,%r13,2), %rcx
addq %r13, %rcx
xorl %r12d, %r12d
movq %rcx, 0x8(%rsp)
movq 0x14d8(%r9), %rax
movq (%rax), %rax
movq (%rax,%rcx,8), %rax
movq $0x0, (%rax,%r12,8)
movq 0x14f8(%r9), %rax
movl 0x3c(%rax), %eax
testl %eax, %eax
movq 0x10(%rsp), %rbx
jle 0x486c
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
movq 0x28(%rsp), %rcx
movq %r8, %r14
movq %r9, %rbp
callq 0x3cb2
movq %rbp, %r9
movq %r14, %r8
movq 0x14d8(%rbp), %rax
movq 0x14e0(%rbp), %rcx
movslq 0x8(%rbp), %rdx
movq (%rcx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rsp), %rcx
movq (%rax), %rax
movq (%rax,%rcx,8), %rax
addsd (%rax,%r12,8), %xmm0
movsd %xmm0, (%rax,%r12,8)
incl %r15d
movq 0x14f8(%rbp), %rax
movl 0x3c(%rax), %eax
cmpl %eax, %r15d
jl 0x4809
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x14d8(%r9), %rax
movq (%rax), %rax
movq (%rax,%rcx,8), %rax
movsd (%rax,%r12,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r12,8)
incq %r12
movq 0x14f8(%r9), %rax
movslq 0x4(%rax), %rax
cmpq %rax, %r12
jl 0x47dd
incq %r13
movq 0x14f8(%r9), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jl 0x47b9
movq 0x14f8(%r9), %rax
cmpl $0x0, 0x38(%rax)
jle 0x4a53
xorl %ecx, %ecx
movl %ecx, 0x1c(%rsp)
movq 0x14f8(%r9), %rax
cmpl $0x0, (%rax)
jle 0x4a3d
xorl %edi, %edi
movq 0x14f8(%r9), %rax
cmpl $0x0, 0x4(%rax)
jle 0x4a27
xorl %r14d, %r14d
movq %rdi, 0x8(%rsp)
movq $0x0, 0x18(%r9)
movq 0x14f8(%r9), %rax
movl 0x40(%rax), %esi
testl %esi, %esi
movq 0x10(%rsp), %r13
movq 0x28(%rsp), %rbp
movq %r9, %r12
movq 0x20(%rsp), %rbx
jle 0x4998
xorl %r15d, %r15d
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movl %r14d, %edx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x3cb2
movq 0x14f8(%r12), %rax
movq 0x14e0(%r12), %r8
movq 0x14e8(%r12), %rdi
movslq 0x8(%r12), %rsi
movq (%rdi), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq (%r8), %rdi
subsd (%rdi,%rsi,8), %xmm0
movq 0x8(%rsp), %rdi
mulsd 0x18(%rax), %xmm0
addsd 0x10(%r12), %xmm0
addsd 0x18(%r12), %xmm0
movsd %xmm0, 0x18(%r12)
incl %r15d
movl 0x40(%rax), %esi
cmpl %esi, %r15d
jl 0x492b
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x18(%r12), %xmm1
divsd %xmm0, %xmm1
movsd 0x18(%rax), %xmm0
movq 0x14d8(%r12), %rcx
movq (%rcx), %rcx
leaq (%rdi,%rdi,2), %rsi
movq (%rcx,%rsi,8), %rcx
movsd (%rcx,%r14,8), %xmm2
mulsd %xmm0, %xmm2
mulsd 0x1654(%rip), %xmm0     # 0x6028
mulsd 0x60(%rax), %xmm0
addsd %xmm1, %xmm2
addsd %xmm2, %xmm0
movsd %xmm0, 0x18(%r12)
movq 0x14e8(%r12), %rax
movq (%rax), %rax
ucomisd (%rax,%rdi,8), %xmm0
movq %r12, %r9
jbe 0x4a10
movsd %xmm0, (%rax,%rdi,8)
movq 0x14f0(%r9), %rax
movq (%rax), %rax
movl %r14d, (%rax,%rdi,4)
incq %r14
movq 0x14f8(%r9), %rax
movslq 0x4(%rax), %rax
cmpq %rax, %r14
jl 0x4900
incq %rdi
movq 0x14f8(%r9), %rax
movslq (%rax), %rax
cmpq %rax, %rdi
jl 0x48e7
movl 0x1c(%rsp), %ecx
incl %ecx
movq 0x14f8(%r9), %rax
cmpl 0x38(%rax), %ecx
jl 0x48d1
movsd 0x60(%rax), %xmm0
mulsd 0x15d0(%rip), %xmm0     # 0x6030
movsd %xmm0, 0x60(%rax)
shll $0x2, 0x3c(%rax)
shll $0x2, 0x40(%rax)
movq 0x14e0(%r9), %rdi
movq 0x14e8(%r9), %rsi
movq %r9, %rbx
callq 0x53d0
movq %rbx, %r9
movq 0x14f8(%rbx), %rcx
movq 0x30(%rsp), %r14
movl %r14d, %eax
cltd
idivl 0x6c(%rcx)
testl %edx, %edx
movq 0x10(%rsp), %r15
jne 0x4ab7
movq 0x14f0(%r9), %rsi
movq %r15, %rdi
movq %rcx, %rdx
callq 0x2ebc
movq %rbx, %r9
incl %r14d
movq 0x14f8(%r9), %rax
cmpl 0x34(%rax), %r14d
movq 0x20(%rsp), %r8
jl 0x47a1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop