If S = {v 1 , . . . , v ℓ } is an ordered subset of vertices of a connected graph G and v is a vertex of G, then the vector rIf for any pair of different vertices u, v ∈ V (G), the vectors r(v|S) and r(u|S) differ in at least k positions, then S is a k-metric generator for G. A smallest k-metric generator for G is a k-metric basis for G, its cardinality being the k-metric dimension of G. A sharp upper bound and a closed formulae for the k-metric dimension of the hierarchical product of graphs is proved. Also, sharp lower bounds for the k-metric dimension of the splice and link products of graphs are presented. An integer linear programming model for computing the k-metric dimension and a k-metric basis of a given graph is proposed. These results are applied to bound or to compute the k-metric dimension of some classes of graphs that are of interest in mathematical chemistry.