Maximum or minimum entropy generation for open systems