Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable / scalar or LinearExpression / scalar is broken #57

Closed
coroa opened this issue Nov 8, 2022 · 1 comment · Fixed by #58
Closed

Variable / scalar or LinearExpression / scalar is broken #57

coroa opened this issue Nov 8, 2022 · 1 comment · Fixed by #58

Comments

@coroa
Copy link
Member

coroa commented Nov 8, 2022

Just saw this example:

https://github.com/prakaa/Battery-Optimisation-Benchmarking/blob/master/battery_optimisation_benchmarking/python/linopy.ipynb

With the following soc constraint definition (slightly cleaned)

    # intertemporal energy balance constraints
    intertemp_soc_lhs = (
        soc_mwh
        - soc_mwh.shift(datetime=1)
        - charge_mw * charge_eff * tau
        + discharge_mw / discharge_eff * tau
    ).isel(datetime=slice(1, None))
    intertemp_soc = m.add_constraints(
        intertemp_soc_lhs, "=", 0, "intemporal-energy-balance"
    )

where the operation discharge_mw / discharge_eff is bypassing the linopy definitions and directly dividing the variable labels, and does not even raise an error.

For correct operation needs to be realigned to:

    intertemp_soc_lhs = (
        soc_mwh
        - soc_mwh.shift(datetime=1)
        - charge_eff * tau * charge_mw
        + tau / discharge_eff * discharge_mw 
    ).isel(datetime=slice(1, None))

=> need implementations for __div__ and __truediv__ with a scalar on Variable and LinearExpression.

@FabianHofmann
Copy link
Collaborator

Indeed, this is again en example for unsafe operations. Easiest is to directly address it in #55 right?

FabianHofmann added a commit that referenced this issue Nov 9, 2022
FabianHofmann added a commit that referenced this issue Nov 9, 2022
FabianHofmann added a commit that referenced this issue Nov 9, 2022
FabianHofmann added a commit that referenced this issue Nov 9, 2022
FabianHofmann added a commit that referenced this issue Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants