Optimization of deterministic timed weighted marked graphs