PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
162 stars 44 forks source link

masking vs selecting #307

Closed aurelije closed 3 months ago

aurelije commented 3 months ago

Hi linopyers, I am wondering if I am using linopy correctly while creating constraints.

In many occasions I have to setup constraint that applies only to a subset of one dimension. For example there is a time dimension but constraint applies only to some dates. In that case I see 2 ways of constructing constraint:

  1. select variables/linear expression by time dimension getting only those on which you would construct constraint. This approach is usually more explicit, simpler to understand and creates dense constraint
  2. use masking in add_constraints, constraint is sparse because all constraint coordinates will be printed with masked out displayed as None

Are both approaches equally good? What are the pros and cons?

FabianHofmann commented 3 months ago

Hey, I would say that both approaches work equally good. The selection might be a bit cleaner and a bit more memory efficient, as no placeholders are required.

aurelije commented 3 months ago

Thanks @FabianHofmann for confirming my taught

FabianHofmann commented 3 months ago

sure :) closing this