def re_visited_2(model, k): if k == value(model.s) or k == value(model.t): return Constraint.Skip found = 0 for (i, j) in model.A: if k in (i, j): found = 1 break if found == 0: return Constraint.Skip into_k = sum(model.r[(i, j)] for i, j in model.A if j == k) return into_k <= 1
def re_visited_1(model, k): if k == value(model.s) or k == value(model.t): return Constraint.Skip found = 0 for (i, j) in model.A: if k in (i, j): found = 1 break if found == 0: return Constraint.Skip into_k = sum(model.r[(i, j)] for i, j in model.A if j == k and i != value(model.t)) out_of_k = sum(model.r[(i, j)] for i, j in model.A if i == k and j != value(model.s)) return into_k == out_of_k
def define_path(model): start = value(model.s) end = value(model.t) all_steps = [] path = [start] for v in model.component_objects(Var, active=True): for index in v: if v[index].value == 1: all_steps.append(index) start_step = find_next_step(all_steps, start) next = start_step[1] path.append(next) end_not_found = True while end_not_found: next_step = find_next_step(all_steps, next) next = next_step[1] path.append(next) if next == end: end_not_found = False return path
def costs_(model): return sum(model.r[(i, j)] * model.c[(i, j)] for i, j in model.A) <= value(model.b)
def ends_2(model): sum = 0 for i in model.N: if (value(model.t), i) in model.A.value: sum += model.r[(model.t, i)] return sum == 0
def ends_1(model): sum = 0 for i in model.N: if (i, value(model.t)) in model.A.value: sum += model.r[(i, model.t)] return sum == 1
def starts_2(model): sum = 0 for j in model.N: if (j, value(model.s)) in model.A.value: sum += model.r[(j, model.s)] return sum == 0
def starts_1(model): sum = 0 for j in model.N: if (value(model.s), j) in model.A.value: sum += model.r[(model.s, j)] return sum == 1
def total_rule(model): sum = 0 for i, j in model.A: sum += model.r[(i, j)] * (value(model.eta) * model.g_i[i] + (1 - value(model.eta)) * model.p[i]) return sum
def _build_solution(self, results=None): """ Store the solution of the day-ahead market in the order book. """ model = self.model book = self.orders complexOrders = self.complexOrders book.volumes = { s: {l: {t: 0.0 for t in book.periods} for l in model.L} for s in ['SUPPLY', 'DEMAND'] } book.prices = { l: {t: model.pi[l, t].value for t in book.periods} for l in model.L } self.welfare = value(model.obj) logging.info("welfare: %.2f" % value(self.welfare)) for i in model.sBids: bid = book.bids[i] # Obtain and save the volume xs = model.xs[i].value bid.acceptance = xs # Update volumes and prices if xs > options.EPS: # Compute the total volumes exchanged supplydemand = "SUPPLY" if bid.volume > 0 else "DEMAND" t = bid.period book.volumes[supplydemand][bid.location][t] += bid.volume * xs for c in model.C: flow_up = [] flow_down = [] congestion_up = [] congestion_down = [] for p in model.periods: flow_up.append(model.f[c, 1, p].value) flow_down.append(model.f[c, 2, p].value) congestion_up.append(model.u[c, 1, p].value) congestion_down.append(model.u[c, 2, p].value) self.connections[c - 1].flow_up = flow_up self.connections[c - 1].flow_down = flow_down self.connections[c - 1].congestion_up = congestion_up self.connections[c - 1].congestion_down = congestion_down for i in model.bBids: bid = book.bids[i] # Obtain and save the volume xb = model.xb[i].value bid.acceptance = model.xb[i].value if xb > options.EPS: supplydemand = "SUPPLY" if bid.volumes[0] > 0 else "DEMAND" for t, v in bid.volumes.items(): book.volumes[bid.location][t] += v for i in model.cBids: # logging.info('building solution for complex %d' % i) bid = complexOrders[i - 1] # Obtain and save the volume bid.acceptance = model.xc[i].value bid.surplus = model.sc[i].value bid.volumes = [ model.complexVolume[i, p].value for p in model.periods ] bid.pi_lg = [ model.pi[bid.location, p].value for p in model.periods ] # FIXME could be removed if bid.acceptance < options.EPS: # Bid is rejected, is it paradoxically ? bid.tentativeVolumes = dict( zip(model.periods, [0.0] * len(model.periods))) for p in model.periods: for i in bid.ids: if book.bids[i].price <= bid.pi_lg[ p - 1]: # FIXME assuming supply bid.tentativeVolumes[p] += book.bids[i].volume bid.tentativeIncome = sum(bid.tentativeVolumes[p] * bid.pi_lg[p - 1] for p in model.periods) bid.isPR = (bid.tentativeIncome >= bid.FT + bid.VT * sum(bid.tentativeVolumes[p] for p in model.periods)) else: bid.tentativeVolumes = {} bid.tentativeIncome = 0 bid.isPR = False