Hi everyone,
I am using pypsa to optimize power system operation.
I added the "PowExpression()" function provided by Pyomo to the objective function to apply the generator's cost function as a quadratic formula.
```
for sn, marginal_cost in zip(snapshots, marginal_cost_it):
gen_mc, gen_a, gen_b, gen_c, su_mc, st_mc, link_mc = marginal_cost
weight = network.snapshot_weightings.objective[sn]
## Original generator cost
'''for gen in network.generators.index:
coefficient = gen_mc.at[gen] * weight
objective.variables.extend([(coefficient, model.generator_p[gen, sn])])'''
# apply quadratic cost
for gen in network.generators.index:
coefficient = (gen_a.at[gen]) * weight
a = PowExpression([model.generator_p[gen, sn], 2])
print(a)
objective.variables.extend([(coefficient, a)])
for gen in network.generators.index:
coefficient = (gen_b.at[gen]) * weight
objective.variables.extend([(coefficient, model.generator_p[gen, sn])])
```
It was confirmed that the quadratic equation was applied to the objective function as follows.
```
... + 0.0*generator_p[G0,2022-10-25 18:30:00]**2 + 0.0*generator_p[G1,2022-10-25 18:30:00]**2 + 0.0*generator_p[G2,2022-10-25 18:30:00]**2 + 0.0*generator_p[G3,2022-10-25 18:30:00]**2 + 0.0*generator_p[G4,2022-10-25 18:30:00]**2 + 0.394*generator_p[G9,2022-10-25 18:30:00]**2 + 0.394*generator_p[G10,2022-10-25 18:30:00]**2 + ...
```
However, the following error occurred.
```
INFO:pypsa.opf:Solving model using gurobi
Traceback (most recent call last):
File "C:/Users/aaa/Desktop/2023 춘계학술대회/code/test_V10.0/jeju_curtail_main.py", line 16, in <module>
uc.opf('net/' + str(i), i) # pypsa network path folder
File "C:\Users\aaa\Desktop\2023 춘계학술대회\code\test_V10.0\uc.py", line 102, in opf
pyomo=True,
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pypsa\components.py", line 768, in lopf
return network_lopf(self, **args)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pypsa\opf.py", line 2471, in network_lopf
extra_postprocessing=extra_postprocessing,
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pypsa\opf.py", line 2330, in network_lopf_solve
options=solver_options
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\opt\base\solvers.py", line 570, in solve
self._presolve(*args, **kwds)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\solvers\plugins\solvers\GUROBI.py", line 234, in _presolve
ILMLicensedSystemCallSolver._presolve(self, *args, **kwds)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\opt\solver\shellcmd.py", line 209, in _presolve
OptSolver._presolve(self, *args, **kwds)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\opt\base\solvers.py", line 670, in _presolve
**kwds)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\opt\base\solvers.py", line 722, in _convert_problem
**kwds)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\opt\base\convert.py", line 101, in convert_problem
problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\solvers\plugins\converter\model.py", line 82, in apply
io_options=io_options)
File "C:\Users\aaa\anaconda3\envs\py3.7\lib\site-packages\pyomo\core\base\block.py", line 1979, in write
io_options)
File "pyomo\repn\plugins\cpxlp.pyx", line 158, in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__
File "pyomo\repn\plugins\cpxlp.pyx", line 159, in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__
File "pyomo\repn\plugins\cpxlp.pyx", line 160, in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp.__call__
File "pyomo\repn\plugins\cpxlp.pyx", line 514, in pyomo.repn.plugins.cpxlp.ProblemWriter_cpxlp._print_model_LP
File "pyomo\repn\standard_repn.pyx", line 289, in pyomo.repn.standard_repn.generate_standard_repn
AttributeError: 'PowExpression' object has no attribute 'fixed'
```
I think neither pypsa nor pyomo support quadratic expressions.
is there a solution to apply the quadratic equation to the objective function?