wangrunjie / SHALE

SHALE: An Efficient Algorithm for Allocation of Guaranteed Display Advertising Guaranteed Display Advertising

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

update_sigma 有bug

shelson-woo opened this issue · comments

def update_sigma(self, j):
    solutions = []
    coef = []
    for i in self.demand.get_target_supply(j):
        s = self.supply.get_supply(i)
        a = s * self.theta_ij[j] * (1.0 - self.beta_i[i] / self.demand.get_v(j))
        b = s * self.theta_ij[j] / self.demand.get_v(j)
        coef.append(((self.s_i[i] - a) / b, a / b, a, b, self.s_i[i]))
    coef = sorted(coef, key=lambda t: t[1])

    for k in range(len(coef)):
        temp = copy(coef[k:])
        temp = sorted(temp, key=lambda t: t[0])
        sum_remained = 0.0
        sum_cons = 0.0
        sum_coef = 0.0
        for t in range(len(temp)):
            sum_cons += temp[t][2]
            sum_coef += temp[t][3]
            sum_remained += temp[t][4]
        res = (sum_cons - self.demand.get_demand(j)) / sum_coef
        if sum_remained < self.demand.get_demand(j):
            continue
        if k == 0:
            if res <= temp[0][0] and res <= coef[k][1]:
                solutions.append(res)
        else:
            if res <= temp[0][0] and res <= coef[k][1] and res >= coef[k - 1][1]:
                solutions.append(res)
        sum_remained = 0.0
        for t in range(1, len(temp)):
            sum_cons -= temp[t - 1][2]
            sum_coef -= temp[t - 1][3]
            sum_remained += temp[t - 1][4]
            res = (sum_cons + sum_remained - self.demand.get_demand(j)) / sum_coef
            if k == 0:
                if res <= temp[t][0] and res >= temp[t - 1][0] and res <= coef[k][1]:
                    solutions.append(res)
            else:
                if res <= temp[t][0] and res >= temp[t - 1][0] and res <= coef[k][1] and res >= coef[k - 1][1]:
                    solutions.append(res)
    return solutions

sum_coef -= temp[t][3]
if res <= temp[t][0] and res >= temp[t - 1][0] and -res <= coef[k][1] and -res >= coef[k - 1][1]:
类似的地方都要这样改