Deregulated electricity markets with thermal losses and production bounds: models and optimality conditions