function [v_tmp] = jcr_rhs_state_value_bellman(na,nb,ntrans,V,gamma,Ra,Pa,Rb,Pb,max_num_cars_can_transfer) % RHS_STATE_VALUE_BELLMAN - computes the right hand side of the bellman equation % % We have to consider the possible number of rentals at sites A/B % and the possible number of returns at sites A/B % % Written by: % -- % John L. Weatherwax 2007-12-07 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % the maximum number of cars at each site (assume equal): max_n_cars = size(V,1)-1; % restrict this action: ntrans = max(-nb,min(ntrans,na)); ntrans = max(-max_num_cars_can_transfer,min(+max_num_cars_can_transfer,ntrans)); v_tmp = -2*abs(ntrans); na_morn = na-ntrans; nb_morn = nb+ntrans; for nna=0:max_n_cars, for nnb=0:max_n_cars, pa = Pa(na_morn+1,nna+1); pb = Pb(nb_morn+1,nnb+1); v_tmp = v_tmp + pa*pb* ( Ra(na_morn+1) + Rb(nb_morn+1) + gamma*V(nna+1,nnb+1) ); end end