Skip to content

Commit

Permalink
Changed
Browse files Browse the repository at this point in the history
- Replace `sum(x[i,j] for j in range(J))` using `poi.quicksum(x.select(i,'*'))` based on PyOptInterface's features
- Replace `{(i,j):model.get_value(x[i,j]) for i in range(I) for j in range(J)}` using `x.map(model.get_value)` based on PyOptInterface's features
  • Loading branch information
github-actions[bot] committed Jul 23, 2024
1 parent b435d97 commit 12f4f4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
15 changes: 3 additions & 12 deletions prepshot/_model/co2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ def emission_calc_rule(self, y : int) -> poi.ConstraintIndex:
A constraint of the model.
"""
model = self.model
return poi.quicksum(
model.carbon_capacity[y, z]
for z in model.zone
)
return poi.quicksum(model.carbon_capacity.select(y, '*'))

def emission_calc_by_zone_rule(
self, y : int, z : str
Expand All @@ -111,10 +108,7 @@ def emission_calc_by_zone_rule(
A constraint of the model.
"""
model = self.model
return poi.quicksum(
model.carbon_breakdown[y, z, te]
for te in model.tech
)
return poi.quicksum(model.carbon_breakdown.select(y, z, '*'))

def carbon_breakdown(
self,
Expand All @@ -141,7 +135,4 @@ def carbon_breakdown(
model = self.model
ef = model.params['emission_factor'][te, y]
dt = model.params['dt']
return poi.quicksum(
ef * model.gen[h, m, y, z, te] * dt
for h in model.hour for m in model.month
)
return ef * dt * poi.quicksum(model.gen.select('*', '*', y, z, te))
13 changes: 6 additions & 7 deletions prepshot/_model/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def fuel_cost_breakdown(
dt = model.params['dt']
vf = model.params['var_factor'][y]
w = model.params['weight']
return 1 / w * fp * sum(model.gen[h, m, y, z, te]
for h in model.hour for m in model.month) * dt * vf
return (1 / w * fp * dt * vf
* poi.quicksum(model.gen.select('*', '*', y, z, te)))

def cost_var_line_breakdown(
self, y : int, z : str, z1 : str
Expand Down Expand Up @@ -134,9 +134,8 @@ def cost_var_line_breakdown(
dt = model.params['dt']
vf = model.params['var_factor'][y]
w = model.params['weight']
return 0.5 / w * lvc * dt * vf * \
sum(model.trans_export[h, m, y, z, z1]
for h in model.hour for m in model.month)
return (0.5 / w * lvc * dt * vf
* poi.quicksum(model.trans_export.select('*', '*', y, z, z1)))

def cost_var_tech_breakdown(
self, y : int, z : str, te : str
Expand All @@ -163,8 +162,8 @@ def cost_var_tech_breakdown(
dt = model.params['dt']
vf = model.params['var_factor'][y]
w = model.params['weight']
return 1 / w * tvc * sum(model.gen[h, m, y, z, te]
for h in model.hour for m in model.month) * dt * vf
return (1 / w * tvc * dt * vf
* poi.quicksum(model.gen.select('*', '*', y, z, te)))

def cost_fix_line_breakdown(
self, y : int, z : str, z1 : str
Expand Down
3 changes: 2 additions & 1 deletion prepshot/output_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def create_data_array(
index_tuple = cartesian_product(*coords.values())
if len(dims) == 1:
index_tuple = [i[0] for i in index_tuple]
data_values = data.map(model.get_value)
data = np.array(
[model.get_value(data[tuple_]) for tuple_ in index_tuple]
[data_values[tuple_] for tuple_ in index_tuple]
).reshape([len(coord) for coord in coords.values()])
return xr.DataArray(data=data,
dims=dims,
Expand Down

0 comments on commit 12f4f4c

Please sign in to comment.