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

Add examples/guide without macros #86

Open
deanm0000 opened this issue Feb 18, 2025 · 8 comments
Open

Add examples/guide without macros #86

deanm0000 opened this issue Feb 18, 2025 · 8 comments
Labels
documentation Improvements or additions to documentation

Comments

@deanm0000
Copy link

deanm0000 commented Feb 18, 2025

The macros are great for small problems but anything a bit bigger or dynamic needs the non-macro approach. Here's a snippet of something I just did, not sure if there's a better way.

    let mut vars = ProblemVariables::new();
    let to_grid = vars.add_vector(variable().min(0.0).max(grid_out), rows);
    let to_grid_ismax = vars.add_vector(variable().binary(), rows);
    let clip = vars.add_vector(variable().min(0.0).max(max_clip), rows);

    //soc balance rule
    let lhs = charge[0] * rte[0] - discharge[0];
    constraints.push(lhs.eq(soc[0]).set_name("soc_balance_rule_0".to_string()));
    (1..rows).into_iter().for_each(|t| {
        let lhs = soc[t - 1] + charge[t] * rte[t] - discharge[t];
        constraints.push(lhs.eq(soc[t]).set_name(format!("soc_balance_rule_{}", t)));
    });
    let objective = (0..rows).into_iter().fold(Expression::from(0), |acc, t| {
        acc + to_grid[t] * prices[t] - genr[t] * ppa_price + clip[t] * ppa_price
    });
    let mut solver = vars.maximise(objective).using(default_solver);

    for c in constraints {
        solver.add_constraint(c);
    }

    let solution = solver.solve()?;
@lovasoa
Copy link
Collaborator

lovasoa commented Feb 18, 2025

Yes, more examples are always welcome ! Feel free to contribute to the readme and to the crate doc comments

@lovasoa lovasoa added the documentation Improvements or additions to documentation label Feb 18, 2025
@lovasoa
Copy link
Collaborator

lovasoa commented Feb 18, 2025

Out of curiosity, what are you working on ? This seems close to the kind of problems we work on at inthy

@deanm0000
Copy link
Author

deanm0000 commented Feb 18, 2025

Given a production forecast and price forecast, trying to forecast how a battery/solar hybrid PPA holder will charge/discharge the battery in the face of the terms of their PPA. In particular they can't clip the solar except if the solar is greater than the grid connection. Additionally, they can only charge from the solar. My example above doesn't have all my constraints and variables though.

My shift to rust from pyomo is primarily motivated so I can make a polars plugin to do more Q&D battery arbitrage forecasts.

As to making a contribution, do you have any feedback on my example?

@lovasoa
Copy link
Collaborator

lovasoa commented Feb 19, 2025

I think you could make your initial example a little bit more readable by using the constraint! macro and .sum().

@dlaehnemann
Copy link

Sorry for the random chiming in here with a question: can either of you recommend good resources or projects for battery/solar/heat pump energy managers? Sounds like you are both working in the field, and I'd be interested in open source and community-based solutions to use at home.

@lovasoa
Copy link
Collaborator

lovasoa commented Feb 21, 2025

@dlaehnemann : I'm sorry, but I have really no idea what to recommend. My work isn't really close that; I work on proprietary software managing large industrial infrastructure

@dlaehnemann
Copy link

Cool stuff, anyways, and thanks for chiming in. Maybe the project @deanm0000 is on is more in the direction of the question.

@deanm0000
Copy link
Author

Sorry, I work in the wholesale side of the industry too so I'm not aware of home energy managers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants