// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movq $0x0, (%rsp)
xorl %edi, %edi
callq 0x21b0
movl %eax, %edi
callq 0x21d0
movq 0x14f8(%rbx), %rcx
cmpl $0x0, 0x34(%rcx)
jle 0x4b8a
leaq 0x20(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rbx), %r14
leaq 0x10(%rbx), %r13
movq %r14, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movl (%rcx), %eax
testl %eax, %eax
jle 0x49c5
xorl %r14d, %r14d
cmpl $0x0, 0x4(%rcx)
jle 0x49b6
movq 0x14d8(%rbx), %rax
movq (%rax), %rax
leaq (%r14,%r14,2), %r12
movq (%rax,%r12,8), %rax
xorl %ebp, %ebp
movq $0x0, (%rax,%rbp,8)
movl 0x3c(%rcx), %edx
testl %edx, %edx
jle 0x4990
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
movq 0x20(%rsp), %rcx
movq %r13, %r8
callq 0x3c72
movq 0x14d8(%rbx), %rax
movq 0x14e0(%rbx), %rcx
movslq 0x8(%rbx), %rdx
movq (%rcx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movq (%rax,%r12,8), %rax
addsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%rax,%rbp,8)
incl %r15d
movq 0x14f8(%rbx), %rcx
movl 0x3c(%rcx), %edx
cmpl %edx, %r15d
jl 0x493a
jmp 0x4994
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
movslq 0x4(%rcx), %rdx
cmpq %rdx, %rbp
jl 0x4928
movl (%rcx), %eax
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x490a
cmpl $0x0, 0x38(%rcx)
jle 0x4b15
xorl %eax, %eax
movl %eax, 0x14(%rsp)
movl (%rcx), %eax
testl %eax, %eax
jle 0x4b06
xorl %esi, %esi
cmpl $0x0, 0x4(%rcx)
jle 0x4af7
xorl %r12d, %r12d
movq $0x0, 0x18(%rbx)
movl 0x40(%rcx), %edi
testl %edi, %edi
jle 0x4a72
xorl %r15d, %r15d
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %rbp
movq 0x8(%rsp), %rdi
movl %r12d, %edx
movq %r13, %rcx
movq %rsi, %r14
movq %rbp, %r8
callq 0x3c72
movq %r14, %rsi
movq 0x14f8(%rbx), %rcx
movsd 0x18(%rcx), %xmm0
movq 0x14e0(%rbx), %r8
movq 0x14e8(%rbx), %rax
movslq 0x8(%rbx), %rdi
movq (%rax), %rax
movsd (%rax,%rdi,8), %xmm1
movq (%r8), %r8
subsd (%r8,%rdi,8), %xmm1
mulsd %xmm0, %xmm1
addsd 0x10(%rbx), %xmm1
addsd 0x18(%rbx), %xmm1
movsd %xmm1, 0x18(%rbx)
incl %r15d
movl 0x40(%rcx), %edi
cmpl %edi, %r15d
jl 0x4a0a
jmp 0x4a85
movsd 0x18(%rcx), %xmm0
movq 0x14e8(%rbx), %rax
movq (%rax), %rax
xorpd %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
divsd %xmm2, %xmm1
movq 0x14d8(%rbx), %rdi
movq (%rdi), %r8
leaq (%rsi,%rsi,2), %rdi
movq (%r8,%rdi,8), %rdi
movsd (%rdi,%r12,8), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
mulsd 0x1578(%rip), %xmm0     # 0x6030
mulsd 0x60(%rcx), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rbx)
ucomisd (%rax,%rsi,8), %xmm0
jbe 0x4ae0
movsd %xmm0, (%rax,%rsi,8)
movq 0x14f0(%rbx), %rax
movq (%rax), %rax
movl %r12d, (%rax,%rsi,4)
incq %r12
movslq 0x4(%rcx), %rax
cmpq %rax, %r12
movq 0x18(%rsp), %r13
jl 0x49ee
movl (%rcx), %eax
incq %rsi
movslq %eax, %rdx
cmpq %rdx, %rsi
jl 0x49e1
movl 0x14(%rsp), %eax
incl %eax
cmpl 0x38(%rcx), %eax
jl 0x49d1
movsd 0x60(%rcx), %xmm0
mulsd 0x1516(%rip), %xmm0     # 0x6038
movsd %xmm0, 0x60(%rcx)
movq 0x3c(%rcx), %xmm0
pslld $0x2, %xmm0
movq %xmm0, 0x3c(%rcx)
movq 0x14e0(%rbx), %rdi
movq 0x14e8(%rbx), %rsi
callq 0x5468
movq 0x14f8(%rbx), %rcx
movq (%rsp), %rax
cltd
idivl 0x6c(%rcx)
testl %edx, %edx
jne 0x4b77
movq 0x14f0(%rbx), %rsi
movq 0x8(%rsp), %rdi
movq %rcx, %rdx
callq 0x2ebc
movq 0x14f8(%rbx), %rcx
movq (%rsp), %rax
incl %eax
movq %rax, (%rsp)
cmpl 0x34(%rcx), %eax
jl 0x48fd
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop