GAMS: Using variables in logical conditions - dollar-sign

I got a question about GAMS. I'm kind of a beginner with GAMS.
I'm using minlp with scip solver.
I'm trying to model a system for a thermal energy storage of a concentrated solar power plant.
I'm right now stuck on modeling the equations for the tank operation strategy, so whether it's on discharging or charging mode. I'm modelling a thermocline tank, where while charging the hot htf enters from the top of the tank and pushes out cold htf from the bottom. For the discharging process it's the other way around.
The operational strategies dependent on the mass flows from the receiver or the power block, which are decision variables. For the different operational strategies the inlet and outlet temperature of the thermal energy storage changes. So there are some equations which logically depent on the values of decision variables.
The thing is, that if I try to use logical conditions (either with the if operator or the $ operator) with variables in it for the definition of equations, I get the errors 52 or 53 "Endogenous $-control operations not allowed". This seems to be an error you get with the solve statements, because it is not possible to put in logical conditions with decision variables. After doing some research on the internet I found these threats, where it is explained quite nicely:
https://forum.gamsworld.org/viewtopic.php?f=13&t=6795
Use variable in GAMS dollar
So ouf of this problem I got some questions:
Does anyone know a possible way, where I can model equations, which logically depend on decision variables? Or is this not possible with GAMS, so that I would need to switch to another language to solve this problem?
These would be the important equations:
e_charge(i+1)$(m_rc_ts(i+1) > 0) .. dec(i+1) =e= 1;
e_discharge(i+1)$(m_pb_ts(i+1)) .. dec(i+1) =e= 2;
e_no_use(i+1)$(m_rc_ts(i+1) = 0 and m_pb_ts(i+1) = 0) .. dec(i+1) =e= dec(i);
e_m_rc_ts_restrict(i+1)$(dec(i+1) = 2) .. m_rc_ts(i+1) =e= 0;
e_m_pb_ts_restrict(i+1)$(dec(i+1) = 1) .. m_pb_ts(i+1) =e= 0;
e_T_ti_charge(nfirst,i+1)$(dec(i+1)= 1) .. T_fl(nfirst,i+1) =e= T_ro;
e_T_ti_discharge(nfirst,i+1)$(dec(i+1)= 2) .. T_fl(nfirst,i+1) =e= T_po(i+1);
Thanks for your help!
Cheers

You cannot use the variable per se, but you are able to use its attributes:
so you cannot write
$(dec(i+1))
but
$(dec.l(i+1))
works (it is the level of the variable).

Related

How can I order the basic solutions of a min cost flow problem according to their cost?

I was wondering if, given a min cost flow problem and an integer n, there is an efficient algorithm/package or mathematical method, to obtain the set of the
n-best basic solutions of the min cost flow problem (instead of just the best).
Not so easy. There were some special LP solvers that could do that (see: Ralph E. Steuer, Multiple Criteria Optimization: Theory, Computation, and Application, Wiley, 1986), but currently available LP solvers can't.
There is a way to encode a basis using binary variables:
b[i] = 1 if variable x[i] = basic
0 nonbasic
Using this, we can use "no good cuts" or "solution pool" technology to get the k best bases. See: https://yetanothermathprogrammingconsultant.blogspot.com/2016/01/finding-all-optimal-lp-solutions.html. Note that not all solution-pools can do the k-best. (Cplex can't, Gurobi can.) The "no-good" cuts work with any mip solver.
Update: a more recent reference is Craig A. Piercy, Ralph E. Steuer,
Reducing wall-clock time for the computation of all efficient extreme points in multiple objective linear programming, European Journal of Operational Research, 2019, https://doi.org/10.1016/j.ejor.2019.02.042

In GAMS, how to deal with divisions?

In my GAMS model, I have a objective function that involves a division.
GAMS sets the initial values to zero whenever it solves something...brilliant idea, how could that possibly ever go wrong!....oh wait, now there's division by zero.
What is the approach to handle this? I have tried manually setting lower bounds such that division by zero is avoided, but then GAMS spits out "infeasible" solution.
Which is wrong, since I know the model is feasible. In fact, removing the division term from my model and resolving does produce a solution. This solution ought to be feasible for the original problem as well, since we are just adding terms to the objective.
Here are some common approaches:
set a lower bound. E.g. Z =E= X/Y, add Y.LO = 0.0001;
similarly, write something like: Z =E= X/(Y+0.0001)
set a initial value. E.g. Y.L = 1
Multiply both sides by Y: Z*Y =E= X
For any non-linear variable you should really think carefully about bounds and initial values (irrespective of division).
Try using the $ sign. For example: A(i,j)$C(i,j) = B(i,j) / C(i,j)

Difference of Convex Functions Optimization

I am looking for the method or idea to solve the following optimization problem:
min f(x)
s.t. g(xi, yi) <= f(x), i=1,...,n
where x, y are variables in R^n. f(x) is convex function with respect to x. g(xi, yi) is a bunch of convex functions with respect to (xi, yi).
It is the problem of difference of convex functions (DC) optimization due to the DC structure of the constraints. Since I am fairly new to 'DC programming', I hope to know the global optimality condition of DC programs and the efficient and popular approaches for global optimization.
In my specific problem, it is already verified that the necessary optimality condition is g(xi*, yi*)=f(x*) for i=1,...,n.
Any ideas or solution would be appreciated, thanks.
For global methods, I would suggest looking into Branch and Bound, Branch and Cut, and Cutting Plane methods. These methods may be notoriously slow though depending on the problem size. It's because it is non-convex. It would be difficult to get efficient algorithms for global optimization for this problem.
For local methods, look into the convex-concave procedure. Actually, any heuristic might work.

Is the equation below means in a MIP model

As the title mentioned
sum((r,l), Mer.l(e,r) * Mel(e,l)) =e= 0;
I use a GAMS mip model to solve a problem, and Mer(e,r) and Mel(e,l) are both binary variables, and if I did not write the .l suffix, the compile will give Endogenous relational operations require model type "dnlp"" error message, but I am not sure the equation above staying the original meaning that is the Mer(e,r) still a variable? and is it still changeable with the mip solving process?
If you use Mer.l, the model will not use Mer as a variable that gets optimized anymore, but will use the (initial) levels of the variables Mer as constant numbers. But you could reformualte your equation, so that it stays linear. As I understand it, you want to make sure that for each e and each combination of r and l you will never get Mer=1 and Mel=1 (one could be 1 or both should be 0). So you could formulate is as e.g.:
equation e(e,r,l);
e(e,r,l).. Mer(e,r) + Mel(e,l) =l= 1;
I hope that helps,
Lutz

Solving a Mixed Integer Quadratic Program using SCIP

I have a mixed integer quadratic program (MIQP) which I would like to solve using SCIP. The program is in the form such that on fixing the integer variables, the problem turns out to be a linear program. And on fixing the the continuous variables it becomes a Integer Program. A simple example :
max. \Sigma_{i} n_i * f_i(x_i)
such that.
n_1 * x_1 + n2 * x_2 < t
n_3 * x_1 + n2 * x_2 < m
.
.
many random quadratic constraints in n_i's and x_i's
so on
Here f_i is a concave piecewise linear function.
x_i's are continuous variables ( they take real values )
n_i's are integer variables
I am able to solve the problem using SCIP. But on problems with a large number of variables SCIP takes a lot of time to find the solution. I have particularly noticed that it does not find many primal solutions. Thus the rate at which the upper bound reduces is very slow. However, I could get better results by doing set heuristics emphasis aggressive.
It would be great if anyone can guide me on the following questions :
1) Is there any particular algorithm/ Software package which solves problems that fit perfectly into the model as described above ?
2) Suggestions on how to improve the rate at which primal solutions are found.
3) What type of branching can I use to get better results ?
4) Any guidance on improving performance would be really helpful.
I am okay with relaxing the integer constraints as well.
Thanks
1) The algorithm in SCIP should fit your problem. There are other software packages that implement similar algorithms, e.g., BARON and ANTIGONE.
2) Have a look which primal heuristics were successful in your run and change their parameters to run them more frequently.
3) No idea. Default should be ok.
4) Make sure that your variables have good bounds. Tighter bounds allow for a tighter relaxation to be constructed.
If you can post an instance of your problem somewhere, or a log of a SCIP run, including the detailed statistics at the end, maybe someone can give more hints on what to improve.