Notes on solving and estimating economic model with heterogeneous agents using R and C++