XiongPengNUS / rsome

Robust Stochastic Optimization Made Easy
GNU General Public License v3.0
282 stars 54 forks source link

Obtaining the value of an Affine expression #31

Closed vballoli closed 1 year ago

vballoli commented 1 year ago

Hi, can support be added for (x+y).get() given x and y are solved dvars. This will alleviate a lot of boilerplate when tracking a large number of equations. I'm happy to contribute through a PR if this feature is of interest.

XiongPengNUS commented 1 year ago

Hi @vballoli currently RSOME is unable to directly return the solved value of an affine expression like x + y. The best we can do is to obtain the value using x.get() + y.get(). I agree with you this is an interesting feature, and we will consider adding it in future versions.

vballoli commented 1 year ago

Thanks a lot for considering this feature, greatly appreciate your time on this! I also wanted to appreciate such a neat and well-written package, thank you so much for releasing it and maintaining it as open-source!

XiongPengNUS commented 1 year ago

Hi @vballoli, the value of an affine (or convex) expression can not be retrieved using RSOME >= 1.14. As mentioned in Solution Analysis, after the model is successfully solved, the value of expr = x + y can be simply retrieved by calling expr().

Besides, the same idea can be used to find the value of a bi-linear expression involving random variables. For example, if expr = x*z + y, where z is a random variable, then the value of expr when z = zhat is returned by expr(z.assign(zhat)).

vballoli commented 1 year ago

Sorry for the late reply, thank you so much @XiongPengNUS! This is super cool and a nice solution!