Added Cost Matrix Calculation