Converts arrays of percentage price markups and capacity withholds
        into offers/bids and submits them to the marketplace.

def _offbid(self, markups, withholds):
        """ Converts arrays of percentage price markups and capacity withholds
        into offers/bids and submits them to the marketplace.
        """
        for i, g in enumerate(self.generators):
            ratedPMin = self._g0[g]["p_min"]
            ratedPMax = self._g0[g]["p_max"]
            margPCost = self._g0[g]["p_cost"]
            margPCostModel = self._g0[g]["pcost_model"]

            # Index of the first markup in 'markups' for generator 'i'.
            k = i * (len(markups) / len(self.generators))
            # Index of the first withhold in 'withholds' for generator 'i'.
            kk = i * (len(withholds) / len(self.generators))

            # Determine the cost at zero output.
            if margPCostModel == POLYNOMIAL:
                costNoLoad = margPCost[-1]
            else:
                costNoLoad = 0.0

            # Divide available capacity equally among the offers/bids.
            if g.is_load:
                qty = ratedPMin / self.numOffbids
            else:
                qty = ratedPMax / self.numOffbids

            # Track the total quantity offered/bid for by the generator.
            totQty = 0.0

#            p0 = 0.0
#            c0 = costNoLoad
            for j in range(self.numOffbids):
                wh = withholds[kk+j]
                qty = qty * ((100.0 - wh) / 100.0)

                totQty += qty

                # The markups are cumulative to ensure cost function convexity.
                mk = sum(markups[k:k + j + 1])

                # Marginal cost (cost function gradient).
                if margPCostModel == POLYNOMIAL:
                    cmarg = polyval(polyder(margPCost), totQty)
                elif margPCostModel == PW_LINEAR:
                    n_segments = len(margPCost) - 1
                    for i in range(n_segments):
                        x1, y1 = margPCost[i]
                        x2, y2 = margPCost[i + 1]
                        if x1 <= totQty <= x2:
                            cmarg = (y2 - y1) / (x2 - x1)
                    else:
                        raise ValueError, "Invalid bid quantity [%f]." % totQty
                else:
                    raise ValueError

                # Markup the marginal cost of the generator.
                if not g.is_load:
                    prc = cmarg * ((100.0 + mk) / 100.0)
                else:
                    prc = cmarg * ((100.0 + mk) / 100.0)

                if not g.is_load:
                    offer = Offer(g, qty, prc, costNoLoad)
                    self.market.offers.append(offer)

                    self._lastAction.append(offer)

                    logger.info(
                        "%.2fMW offered at %.2f$/MWh for %s (%.1f%%, %.1f%%)."
                        % (qty, prc, g.name, mk, wh))
                else:
                    bid = Bid(g, -qty, prc, costNoLoad)
                    self.market.bids.append(bid)

                    self._lastAction.append(bid)

                    logger.info(
                        "%.2f$/MWh bid for %.2fMW for %s (%.1f%%, %.1f%%)."
                        % (prc, -qty, g.name, mk, wh))

        return self._lastAction