code: def offers_to_pwl(self, offers):
          
          assert not self.is_load
          # Only apply offers associated with this generator.
          g_offers = [offer for offer in offers if offer.generator == self]
          # Fliter out zero quantity offers.
          gt_zero = [offr for offr in g_offers if round(offr.quantity, 4) > 0.0]
          # Ignore withheld offers.
          valid = [offer for offer in gt_zero if not offer.withheld]
  
          p_offers = [v for v in valid if not v.reactive]
          q_offers = [v for v in valid if v.reactive]
  
          if p_offers:
              self.p_cost = self._offbids_to_points(p_offers)
              self.pcost_model = PW_LINEAR
              self.online = True
          else:
              self.p_cost = [(0.0, 0.0), (self.p_max, 0.0)]
              self.pcost_model = PW_LINEAR
              if q_offers:
                  # Dispatch at zero real power without shutting down
                  # if capacity offered for reactive power.
                  self.p_min = 0.0
                  self.p_max = 0.0
                  self.online = True
              else:
                  self.online = False
  
          if q_offers:
              self.q_cost = self._offbids_to_points(q_offers)
              self.qcost_model = PW_LINEAR
          else:
              self.q_cost = None#[(0.0, 0.0), (self.q_max, 0.0)]
              self.qcost_model = PW_LINEAR
  
          if not len(p_offers) and not len(q_offers):
              logger.info("No valid offers for generator [%s], shutting down." %
                          self.name)
              self.online = False
  
          self._adjust_limits()
docs: Updates the piece-wise linear total cost function using the given
          offer blocks.
  
          Based on off2case.m from MATPOWER by Ray Zimmerman, developed at PSERC
          Cornell. See U{http://www.pserc.cornell.edu/matpower/} for more info.