Optimization Methods for Gas and Power Markets: Theory and Cases