Modifying / Changing Objective Function

366 views
Skip to first unread message

Gökhan Durucu

unread,
Sep 9, 2023, 7:35:14 AM9/9/23
to pypsa
Hello everyone,

in kind of a beginner in terms of PyPSA and i would like to know if there is a way to modify the objective function to a completly different one? Right know, as far as i understood, the objective function in PyPSA is composed of the capital cost for each component and operation costs for generators. I would like to change the objective function to minimize the transformer tape ratio for example.


I already tried to do it with the following code:
import pypsa
import numpy as np
import pandas as pd

network = pypsa.Network() 
network.import_from_csv_folder(csv_folder_name=csv_folder_path)

def tape_ratio_transformer():
       "Code to change the objective Function"

model = network.optimize.create_model()
model.add_constraints(tape_ratio_transformer, name="Minimize_Tape_Ratio_Transformer")


but i think in that way i am just adding extra Constraints and not changing the objective function.  I also got the network data thats needed for the optimization like components, voltage magnitudes, power generation and so on.

If anyone has a solution i would really appreciate your help. 
If more information is needed just let me know.

Agnès François

unread,
Sep 11, 2023, 1:04:30 AM9/11/23
to pypsa
Hi,

Instead of model.add_constraint(), you should use model.objective=tape_ratio_transformer()

Regards,
Agnès
Reply all
Reply to author
Forward
0 new messages