graph weighted graph graph metric cost function edge weight path cost scalar numeric