I'm writing a program where I have two mathematical models that are solved sequentially in a way that the variable X7(f,p) from the first model becomes the parameter rwdemand(f,p) to the second.
Main code elements for the issue described above:
Sets
f raw materials /f1*f14/
p periods /p1*p4/;
Positive Variable X7(f,p) quantity of raw material f required in period p;
Equation
*First model
r6_rwinventory(f,p).. X4(f,p-1) + X7(f,p-leadtime)=e= sum((t,m,sp),((rmconsumption(f,t,m)*X1(t,m,sp))+X4(f,p)));
Parameter rmdemand(f,p);
rmdemand(f,p)= X7.l;
Equation
*Second model
r3_demand(f,p).. X4(f,p-1) + sum((s,d),X2(f,s,d,p-leadtime)) =e= rmdemand(f,p) + X4(f,p);
Model First_model "real instance set for Lot sizing model (SMM-LS)." /fo,r1_produnits,r2_packsetup,r3_bulkinventory,r4_packinventory,r5_maxbulkinventory,r6_rwinventory,r7_usedinventory1/
Second_model "real instance set for Raw material purchasing model (SMM-RMP)" /fo2,r1_maxd,r2_order,r3_demand,r4_maxinventory,r5_mininventory/;
Solve First_model using mip minimizing Z
Solve Second_model using mip minimizing A;
Display Z.l,A.l;
Writing this way:
Parameter rmdemand(f,p);
rmdemand(f,p)= X7.l;
It doesn't work and appears the error 141: Symbol declared but no values have been assigned. Check for missing data definition, assignment, data loading or implicit assignment via a solve statement.
How can I fix that?
Regards!
Ana! You can only use X7.l to obtain a value after you have solved the first model. So, I believe this might work:
(...)
Equation
*First model
r6_rwinventory(f,p).. X4(f,p-1) + X7(f,p-leadtime)=e= sum((t,m,sp),((rmconsumption(f,t,m)*X1(t,m,sp))+X4(f,p)));
Parameter rmdemand(f,p);
Equation
*Second model
r3_demand(f,p).. X4(f,p-1) + sum((s,d),X2(f,s,d,p-leadtime)) =e= rmdemand(f,p) + X4(f,p);
Model First_model "real instance set for Lot sizing model (SMM-LS)." /fo,r1_produnits,r2_packsetup,r3_bulkinventory,r4_packinventory,r5_maxbulkinventory,r6_rwinventory,r7_usedinventory1/
Second_model "real instance set for Raw material purchasing model (SMM-RMP)" /fo2,r1_maxd,r2_order,r3_demand,r4_maxinventory,r5_mininventory/;
Solve First_model using mip minimizing Z;
*Insert the attribution of value between the two solve statements
rmdemand(f,p)= X7.l;
Solve Second_model using mip minimizing A;
Display Z.l,A.l;
Hope it works :)
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)
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).
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.
I have an optimization in the following form,
argmin_W f(W)
s.t. W_i > 0, for all i
where W is a vector, and f(W) is a function on W.
I know how to optimize without the non-negative constraints. But I am unsure about how to optimize this with gradient descent.
Optimization on the open set is quite tricky, so let us assume that W_i >= 0, consequently you can use many methods:
optimize f(|W|) on the whole domain
use GD for f(W) but after each iteration project your solution back to the domain, so put W = |W|
use constrained optimization techniques, such as L-BFGS-B
I don't think there is a general and simple way of doing it. You will have to do some sort of search at each point to make sure the constraints are met (techniques like line search, trust regions).
Or perhaps f has some structure you can exploit.