Created
January 20, 2017 18:12
-
-
Save snorfalorpagus/d980cdf04f545b8e66e2cc1a8fd3d9cb to your computer and use it in GitHub Desktop.
Pywr + concurrent.futures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
from pywr.model import Model | |
from pywr.nodes import Input, Output | |
def run_model(demand): | |
model = Model() | |
i = Input(model, "input", max_flow=15) | |
o = Output(model, "output", max_flow=demand, cost=-1) | |
i.connect(o) | |
model.run() | |
return o.flow[0] | |
if __name__ == "__main__": | |
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor: | |
future_to_demand = {executor.submit(run_model, demand): demand for demand in range(10, 20)} | |
for future in concurrent.futures.as_completed(future_to_demand): | |
demand = future_to_demand[future] | |
print(demand, future.result()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment