Comments (2)
x.lo is not a declaration but an execution statement (similar to Python interpreter running line by line). Hence, when you execute in the following order:
x.lo = 0
s.setRecords(["a"])
you are basically indicating that you want to set the lower bound of elements in the set so far (since set s
is empty at the moment, you do not set the lower bound of anything). But when you change the order:
s.setRecords(["a"])
x.lo = 0
Set s
is not empty anymore. Therefore, you assign the lower bound for a.
Because of this, static variable bounds should be declared after the instantiation of the model to achieve the desired result.
from gamspy.
Okay, that makes sense, thanks for the explanation. My first thought was that if the statement has no effect, it should not be possible to execute it or this should at least be communicated to the user. However, if a set is left empty on purpose, e.g. due to flexibility in the model definition, this makes no sense. So FYI, my current workaround is to define a function for each variable which adds its bounds to the Container
and execute it after the data has been added to the Container
(if the respective variable is contained in it).
I can see this is due to GAMS' underlying set philosophy and not specific to GAMSPy. However, it sort of goes against the "Model Instances vs. Mathematical Models" proposition of GAMSPy's landing page, which is IMO not implemented consistently (or at least it is not clear where the "model world" ends and the "instance world" begins): I am able to define equations using variables and parameters defined over empty sets, as this only creates "symbolic" relationships. This is really nice and appealing. But then it is confusing that it does not work for static variable bounds, as they are also equations from a mathematical perspective. Also, defining the complementary set of an empty subset of an empty set does not work. Moreover, from a modeling perspective a mathematical model is not totally devoid of data: In many cases, variable bounds are known beforehand as they are dictated by the problem at hand (e.g. the voltage angle limits in the optimal power flow problem). And from a software development perspective, I want to make the model building flexible using functions which add sets, parameters, variables and equations to the Container
. If during definition of a variable I already know its static bounds, it makes sense to put them right after its definition.
from gamspy.
Related Issues (8)
- Can gamspy solve neural network functions trained with pytorch as the objective function? HOT 9
- Rust bindings to read and write gdx HOT 2
- Space in Model name leads to compilation error HOT 1
- `gamspy install license` broken with release 0.13.0 HOT 4
- `toGams()` fails with `first` property of a set HOT 1
- Terminate called by json library HOT 3
- Setting records of multidimensional Set with empty DataFrame fails HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gamspy.