Optimization Methods For Gas And Power Markets: Theory And Cases