LIB writes to w a the TSP problem with the given integer weights in a TSPLIB compatible format.
The number of vertices (also called the dimension) is given by n and the function weights returns the weight of the edge from i to j (which is the same as j to i).