// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rdi, %rbx
xorl %edi, %edi
callq 0x2170
movl %eax, %edi
callq 0x2190
xorl %r14d, %r14d
leaq 0x20(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rbx), %r12
leaq 0x10(%rbx), %r13
movq 0x14f8(%rbx), %rax
cmpl 0x34(%rax), %r14d
jge 0x40e3
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
movslq (%rax), %rcx
cmpq %rcx, %r14
jge 0x3f62
imulq $0x18, %r14, %rcx
movq %rcx, (%rsp)
xorl %ebp, %ebp
movslq 0x4(%rax), %rcx
cmpq %rcx, %rbp
jge 0x3f5a
movq 0x14d8(%rbx), %rcx
movq (%rcx), %rcx
movq (%rsp), %rdx
movq (%rcx,%rdx), %rcx
andq $0x0, (%rcx,%rbp,8)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movl 0x3c(%rax), %edx
cmpl %edx, %r15d
jge 0x3f45
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
movq %r12, %rcx
movq %r13, %r8
callq 0x36a0
movq 0x14d8(%rbx), %rax
movq 0x14e0(%rbx), %rcx
movslq 0x8(%rbx), %rdx
movq (%rcx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %rax
movq (%rsp), %rcx
movq (%rax,%rcx), %rcx
addsd (%rcx,%rbp,8), %xmm0
movsd %xmm0, (%rcx,%rbp,8)
incl %r15d
movq 0x14f8(%rbx), %rax
jmp 0x3eed
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rbp,8)
incq %rbp
jmp 0x3ec2
incq %r14
jmp 0x3eac
xorl %edx, %edx
cmpl 0x38(%rax), %edx
jge 0x407c
movl %edx, (%rsp)
xorl %ebp, %ebp
movslq %ecx, %rdx
cmpq %rdx, %rbp
jge 0x4072
xorl %r14d, %r14d
movslq 0x4(%rax), %rcx
cmpq %rcx, %r14
jge 0x4068
andq $0x0, 0x18(%rbx)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movl 0x40(%rax), %ecx
cmpl %ecx, %r15d
jge 0x3ff9
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r12, %rcx
movq %r13, %r8
callq 0x36a0
movq 0x14f8(%rbx), %rax
movq 0x14e0(%rbx), %rcx
movq 0x14e8(%rbx), %rdx
movslq 0x8(%rbx), %rsi
movq (%rdx), %rdx
movsd (%rdx,%rsi,8), %xmm0
movq (%rcx), %rcx
subsd (%rcx,%rsi,8), %xmm0
mulsd 0x18(%rax), %xmm0
addsd 0x10(%rbx), %xmm0
addsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x18(%rbx)
incl %r15d
jmp 0x3f9a
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd 0x18(%rax), %xmm1
movq 0x14d8(%rbx), %rcx
movq 0x14e8(%rbx), %rdx
movq (%rcx), %rcx
imulq $0x18, %rbp, %rsi
movq (%rcx,%rsi), %rcx
movsd (%rcx,%r14,8), %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
mulsd 0x2003(%rip), %xmm1     # 0x6038
mulsd 0x60(%rax), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x18(%rbx)
movq (%rdx), %rcx
ucomisd (%rcx,%rbp,8), %xmm1
jbe 0x4060
movsd %xmm1, (%rcx,%rbp,8)
movq 0x14f0(%rbx), %rcx
movq (%rcx), %rcx
movl %r14d, (%rcx,%rbp,4)
incq %r14
jmp 0x3f81
incq %rbp
movl (%rax), %ecx
jmp 0x3f72
movl (%rsp), %edx
incl %edx
jmp 0x3f64
movsd 0x60(%rax), %xmm0
mulsd 0x1fa7(%rip), %xmm0     # 0x6030
movsd %xmm0, 0x60(%rax)
movq 0x3c(%rax), %xmm0
pslld $0x2, %xmm0
movq %xmm0, 0x3c(%rax)
movq 0x14e0(%rbx), %rdi
movq 0x14e8(%rbx), %rsi
callq 0x4998
movq 0x14f8(%rbx), %rcx
movq 0x10(%rsp), %r14
movl %r14d, %eax
cltd
idivl 0x6c(%rcx)
testl %edx, %edx
jne 0x40db
movq 0x14f0(%rbx), %rsi
movq 0x8(%rsp), %rdi
movq %rcx, %rdx
callq 0x2ba5
incl %r14d
jmp 0x3e93
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq