To reduce the greenhouse gas emissions and move toward a greener environment, using of alternative fuel vehicles (AFVs) has been suggested. Lack of refueling infrastructure is one of the most barriers to the adoption of AFVs, which needs to be investigated considering the number and optimal location of AFVs. In reality, in the first stage of locating stations, when the number of stations is few, drivers may deviate from the pre-planned paths for refueling. Moreover, the capacity of refueling stations is limited and a station can only serve a number of vehicles up to its capacity. In this paper a mixed integer programming (MIP) model is presented in which the deviation paths and capacity of stations are considered simultaneously. In addition, to solve the large-scale problems, a heuristic algorithm is proposed. Finally, some numerical examples are presented to evaluate the performance of the proposed model and solution algorithm.