Heuristic optimization and sampling with tensor networks