cost matrix serializer&deserializer