hubbs5 / or-gym

Environments for OR and RL Research
MIT License
373 stars 93 forks source link

Is there some tutorial to this module? #7

Closed A-Pai closed 2 years ago

A-Pai commented 3 years ago

I like this module very much,but I don't know how to use it? Is there some tutorial to this module? Complete case code

hdavid16 commented 3 years ago

Hi @A-Pai,

Thank you for your interest. We need to put together some documentation for this package to make it easier for others to use.

In the mean time, I can point you to the following:

If there is a specific environment that you are interested in using we could send you some example specific to that one for now.

jeroenboeye commented 3 years ago

Hi @hdavid16,

This repo looks promising to me too! Mainly interested in supply chains. I've cloned your fork of the repo and tried running the test.py script you suggested but get this error:

 D = {e: env.graph.edges[e]['demand_dist'].rvs(size=window_size,**env.graph.edges[e]['dist_param']) if np.sum(env.graph.edges[e]['user_D']) == 0 else env.graph.edges[e]['user_D'][env.period:] for e in lp.retail_links} #demands on a retail link for each period
KeyError: 'user_D'

Could you point me in the right direction?

Kind regards, Jeroen

hdavid16 commented 3 years ago

Hi @jeroenboeye ,

user_D is used in the fourth example in the test.py file to feed the supply network known demands for each period (rather than sampling them stochastically). This deterministic demand is specified on lines 25-26 of that file. Can you check if env4.user_D returns something? It should give you:

>>> env4.user_D
{(1, 0): array([20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
       20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
       20., 20., 20., 20.])}

EDIT: The following should also be returned for the metadata on the edge joining the retailer to the customer:

>>> env4.graph.edges[1,0]['user_D']
array([20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
       20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
       20., 20., 20., 20.])

Also, just checking, but you need to install OR Gym from the forked repo (not pypi):

cd or-gym
pip install -e .
A-Pai commented 3 years ago

image but in the “https://github.com/grossmann-group/or-gym”,you said: image

hubbs5 commented 3 years ago

That's just to run the test.py module. It relies on other packages and solvers (e.g. Pyomo and GLPK) which have other requirements, dependencies, and complexities which are outside of the scope of the RL environments. If you want to solve optimization models, then you can do so with that version (which is not currently documented because that was developed for a research paper, the code is available but hasn't been cleaned and organized for an open-source project). If you want to use the library for RL purposes, then the two tutorials listed in the ReadMe should get you started.

I hope that helps to clear things up.

hdavid16 commented 3 years ago

image

but in the “https://github.com/grossmann-group/or-gym”,you said:

image

That was copied over with the fork and is outdated

jeroenboeye commented 3 years ago

Hi @hdavid16,

Thanks for the quick reply! I made sure to install or-gym from the local repo (pip install -e .)

The part of the code where env4 is created works for me and I can confirm I get the same outputs as you for env4.user_D and env4.graph.edges[1,0]['user_D'].

The error happens when net_im_lp_model() is called on any of the other environments (env1, env2, env3, env5). When env4 is created you pass env_config={'user_D': {(1, 0): D}} but this does not happen for the other environments. In the net_im_lp_model() function you do env.graph.edges[e]['user_D'] but for all environments but env4 this results in a KeyError.

Anything I can do on my end to fix this?

Also, you might want to add the installation of glpk to the readme. brew install glpk did the trick for me.

Kind regards, Jeroen

hdavid16 commented 3 years ago

Hi @jeroenboeye ,

Thanks for pointing out this bug. The user specified demands option was added towards the end and introduced a bug when it was not used (the other environments). I have patched this and checked that test.py runs without errors on my end. Let me know if you run into any issues on your end.

jeroenboeye commented 3 years ago

Hi @hdavid16,

Great, the test.py script now works on my end too!

Thanks for resolving this so quickly 🙌

Cheers, Jeroen

hdavid16 commented 3 years ago

Sure thing. Glad to see there is interest in this package. I will leave this issue open until we have a better documentation in place.