// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x21a0
movl %eax, %edi
callq 0x21c0
movl $0x0, -0xc(%rbp)
movq -0x30(%rbp), %rcx
movl -0xc(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x34(%rcx), %eax
jge 0x63cd
movl $0x0, -0x10(%rbp)
movq -0x30(%rbp), %rcx
movl -0x10(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x60bd
movl $0x0, -0x14(%rbp)
movq -0x30(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x4(%rcx), %eax
jge 0x60ad
movq -0x30(%rbp), %rax
movq 0x14d8(%rax), %rdi
movslq -0x10(%rbp), %rsi
callq 0x7920
movq %rax, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7860
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, -0x18(%rbp)
movq -0x30(%rbp), %rcx
movl -0x18(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x3c(%rcx), %eax
jge 0x605d
movq -0x30(%rbp), %r8
movq %r8, %rdi
addq $0x20, %rdi
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
movq %r8, %rcx
addq $0x8, %rcx
addq $0x10, %r8
callq 0x4dd0
movq -0x30(%rbp), %rax
movq 0x14e0(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x7860
movq %rax, %rcx
movq -0x30(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x14d8(%rax), %rdi
movslq -0x10(%rbp), %rsi
callq 0x7920
movq %rax, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7860
movsd -0x38(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5fce
movq -0x30(%rbp), %rax
movq 0x14f8(%rax), %rcx
cvtsi2sdl 0x3c(%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x14d8(%rax), %rdi
movslq -0x10(%rbp), %rsi
callq 0x7920
movq %rax, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7860
movsd -0x40(%rbp), %xmm1
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5f89
jmp 0x60af
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5f6c
movl $0x0, -0x1c(%rbp)
movq -0x30(%rbp), %rcx
movl -0x1c(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jge 0x6334
movl $0x0, -0x20(%rbp)
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl (%rcx), %eax
jge 0x6324
movl $0x0, -0x24(%rbp)
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x4(%rcx), %eax
jge 0x6314
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rax)
movl $0x0, -0x28(%rbp)
movq -0x30(%rbp), %rcx
movl -0x28(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cmpl 0x40(%rcx), %eax
jge 0x61ea
movq -0x30(%rbp), %r8
movq %r8, %rdi
addq $0x20, %rdi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movq %r8, %rcx
addq $0x8, %rcx
addq $0x10, %r8
callq 0x4dd0
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x14f8(%rax), %rcx
movsd 0x18(%rcx), %xmm0
movsd %xmm0, -0x50(%rbp)
movq 0x14e8(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x7860
movq %rax, %rcx
movq -0x30(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x58(%rbp)
movq 0x14e0(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x7860
movsd -0x58(%rbp), %xmm2
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq %rax, %rcx
movq -0x30(%rbp), %rax
subsd (%rcx), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6129
movq -0x30(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq 0x14f8(%rax), %rcx
cvtsi2sdl 0x40(%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movq 0x14f8(%rax), %rcx
movsd 0x18(%rcx), %xmm0
movsd %xmm0, -0x70(%rbp)
movq 0x14d8(%rax), %rdi
movslq -0x20(%rbp), %rsi
callq 0x7920
movq %rax, %rdi
movslq -0x24(%rbp), %rsi
callq 0x7860
movsd -0x70(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movsd (%rcx), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x14f8(%rax), %rcx
movsd 0x6ddf(%rip), %xmm0     # 0xd040
mulsd 0x18(%rcx), %xmm0
movq 0x14f8(%rax), %rcx
movsd 0x60(%rcx), %xmm2
movq %xmm0, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq 0x14e8(%rax), %rdi
movslq -0x20(%rbp), %rsi
callq 0x7860
movsd -0x60(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x6304
movq -0x30(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq 0x14e8(%rax), %rdi
movslq -0x20(%rbp), %rsi
callq 0x7860
movsd -0x80(%rbp), %xmm0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movsd %xmm0, (%rcx)
movl -0x24(%rbp), %ecx
movl %ecx, -0x74(%rbp)
movq 0x14f0(%rax), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4e40
movl -0x74(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x6306
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x60ff
jmp 0x6316
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x60e2
jmp 0x6326
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x60c4
movq -0x30(%rbp), %rax
movq 0x14f8(%rax), %rcx
movsd 0x60(%rcx), %xmm0
movsd 0x6cf4(%rip), %xmm1     # 0xd040
divsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rcx)
movq 0x14f8(%rax), %rcx
movl 0x3c(%rcx), %edx
shll $0x2, %edx
movl %edx, 0x3c(%rcx)
movq 0x14f8(%rax), %rcx
movl 0x40(%rcx), %edx
shll $0x2, %edx
movl %edx, 0x40(%rcx)
movq 0x14e8(%rax), %rsi
movq 0x14e0(%rax), %rdi
callq 0x7ae0
movq -0x30(%rbp), %rcx
movl -0xc(%rbp), %eax
movq 0x14f8(%rcx), %rcx
cltd
idivl 0x6c(%rcx)
cmpl $0x0, %edx
jne 0x63bd
movq -0x30(%rbp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movq 0x14f0(%rax), %rsi
movq 0x14f8(%rax), %rdx
callq 0x38d0
jmp 0x63bf
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5f4e
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)