How can I code dynamic sets in GAMS environment? - dynamic

I want to code a constraint in GAMS environment but I can't. The constraint that I want to code is seen in the image. In this constraint, x(i,m,t) is a binary variable but x(i,m,t) binary varible is changed as x(i,m,d) and as seen in the image shown, the number d depends on t-p(i)+1. In t-p(i)+1, p(i) is a parameter and t is a set of times. In this equaiton, I know what the equation wants to calculate but I can't code it in GAMS.
How can I code this equation in GAMS environment? Thank you.
Constraint

Related

How do I output constraints in SWI-Prolog with CLPFD so that I can reuse them in later computations?

I want to be able to reuse constraints found by the CLPFD library in SWI-Prolog. I can get these from the top level, but seemingly not within a predicate. For example, I can pose a query like the one below and find out the simplified constraint is 2*X+8, as below.
Y = 0+1+X+5+(X+1)+1, RealY #= Y. Y = 0+1+X+5+(X+1)+1, RealY#=2*X+8.
I would like to be able to use this result in further computations.
I have tried copy_term/3, ie doing things like
copy_term(RealY,RealY,Constraints)
to access the constraints themselves. But then it seems I have to use term_string to output these to a file in a form that I can then read back in, and then I can reuse the constraints. It seems there has to be a simpler way of doing this!
Any hints or help would be greatly appreciated.

Gurobi/CVXPY Contraints to Integer Variable

I have a big MILP that I want to solve. It has a vector of binary variables. I can reduce the number of variables the problem has to try out by about half. Meaning I can put half of the values to 0 by default. I have done this by adding constraints to the problem that constraint each variable I can reduce to 0.
My problem is that it does not seem to improve the performance by any means.
The part of the problem looks like this mx5#u where mx5 is a block matrix and u is my binary variable.
Theoretically reducing the integer variable should net huge improvements so I'm a bit confused why this is not helping at all.
Futhermore I wouldn't really know of any way to reduce the integer variable in a different way since this would mean my vector u would still have to be of length L and my integer variable u_red would have length L-L/2.
Anybody has some idea?

how I can seperate negative and positive variables?

Let I have a variable UT[i,j,k,r], whose define as a sum of 2 other variables.
UT[i,j,k,r]= U[i,j,k,r]+D[i,j,k,r]
Now I want to write some constraints just for positive UT[i,j,k,r]! what I can do?
I tried many ways: I defined a binary variable whose is 1 if UT is positive and 0 otherwise but it didn't solve my problem because multiplying them is complicated. is there any way to store the indices where UT is positive?
Suppose that BT[i,j,k,r] is your binary variable. Then if you are using CPLEX, Gurobi, or Xpress as your solver, you can write an "indicator constraint" like this:
BT[i,j,k,r] = 1 ==> *your constraint*
This is the easiest way. Alternatively, for any solver, if your constraint is linear then it is possible to transform the indicator constraint to an equivalent linear constraint, without multiplying the binary variable by any other variables. (If your constraint is nonlinear then there may be a transformation as well.) To learn about how such transformations are done, see the answer by #LarrySnyder610 to if condition in ampl.
One option is to split UT into two parts: UTplus and UTminus, both of which are >= 0. Then define UT = UTplus - UTminus.
Now you need to add a constraint that says that at most one of the two can be non-zero. There are several options for this:
You can use an indicator constraint like you suggested and as 4er explained. Use a binary helper variable to indicate that if that variable is 1 then UTminus must be zero and if the helper variable is 0 then UTplus must be zero. If you can derive an upper bound M for UTplus and UTminus then you can also just add a constraint UTplus <= M*binary and UTminus <= M*(1 - binary). If M is not too big this may give better performance.
You can use an SOS constraint that contains UTplus and UTminus (you need one SOS for each index in the variable). That also enforces that at most one of the two can be non-zero but does not introduce any new variables. Whether this is more efficient than indicator or big-M has to be tested.
If both, UTplus and UTminus have a positive coefficient in the objective function (for minimization) then there are chances that in any optimal solution one of the two will be zero automatically. This depends on what exactly the variable UT represents in your model. Take a look at your model and see whether you can prove that property. Then you don't need any extra constraints or variables at all.

Tensorflow Quickstart Tutorial example - where do we say which column is what?

I'm slowly training myself on Tensorflow, following the Get Started section on Tensorflow.org. So far so good.
I have one question regarding the Iris data set example:
https://www.tensorflow.org/get_started/estimator
When it comes to that section:
https://www.tensorflow.org/get_started/estimator#construct_a_deep_neural_network_classifier
It is not entirely clear to me when/where do we tell the system which columns are features and which column is the target value.
The only thing i see is that when we load the dataset, we tell the system the target is in integer format and the features are in float32. But what if my data is all integer or all float32 ? How can I tell the system that, for example, first 5 columns are features, and target is in last column. Or is it implied that first columns are always features and last column can only be the target ?
The statement 'feature_columns=feature_columns' when defining the DNNClassifier says which columns are to be considered a part of the data, and the input function says what are inputs and what are labels.

Three asterisks (***) in GAMS

I have some questions about the three asterisks (***) in GAMS that may be shown at the end of an individual equation listing. I know they are a warning that the constraint is infeasible at the starting point. I have a model that after solving it by GAMS, the model status and solver status are ‘1’ and the equation seems to be feasible, but at the end of an equation three asterisks are shown.
I want to know:
1) What is the starting point?
2) Is the model infeasible?
I really appreciate your kind helps.
The starting point (or initial point) is comprised of the values of the decision variables just before the solver starts optimizing them. You can change the initial values by assigning say x.l(i) = 5. Note that the default in GAMS is zero (but may be projected to the closest bound just before the solve: variables will always between their bounds in the initial point).
These *** mean that the initial value is such that some equations are not feasible. In general this is not something to worry about. The solver will try to return a feasible and optimal point even if the initial point is not feasible. Sometimes we want to make sure the initial point is feasible for performance reasons, and then this part of the listing file can be a useful debugging tool.
Note that an infeasible initial point does not say anything about whether the model is infeasible.