Closed apfelix closed 4 months ago
@apfelix, thanks for the nice reproducible example! There was a problem with the mask attribute getter in the constraint class. Could you try with the current master and give feedback if everything works as expected?
Thanks for the quick fix, looks good in general! However, I think the reported number of masked constraints is wrong.
When testing with
mask_for_2 = b == 300
con = x.sum(dims="Canning Plants") >= b
con2 = m.add_constraints(con, name="Satisfy demand at market j", mask=mask_for_2)
print(f"{con2=}")
gives
con2=Constraint `Satisfy demand at market j` (Markets: 3) - 1 masked entries:
------------------------------------------------------------------------
[new-york]: None
[chicago]: +1 Shipment quantities in cases[seattle, chicago] + 1 Shipment quantities in cases[san-diego, chicago] ≥ 300.0
[topeka]: None
but it should be 2 masked entries
at the end of the first row. I think the number of not-masked constraints is shown :)
argh, thanks, did not see that. It will make it in the next release
Hi,
I just started my first modelling experiment with linopy and wanted to use masking for constraints. As the model I'm creating is rather large, I printed the constraints I was adding and wanted to check if my masking has worked (as I already did with masks for creating variables).
However, in the prints, there was no indication that I had masked some of the constraints. Also the
mask
attribute was returning the valueNone
. When testing this on a small example and printing the model to an.lp
file, I realised that the masking actually works, but there is just no indication of it in the string representation (or anywhere else I could find it).Some example code to reproduce the issue based on https://linopy.readthedocs.io/en/latest/transport-tutorial.html
Printing lists two constraints (one for each element in
i
):However, the
.lp
file shows only one of them:Also solving the model gives different results based on whether masking is applied or not.
What I would have expected would be prints as for masked variables. Changing the variable creation above to
gives the following output