7

Can you help me figure out if this formulation constitutes a non-linear problem? I believe It is a linear problem but my solver (GAMS) is unable to produce a acceptable solution.

$x,y$ and $\text{state}$ are variables and the rest are parameters.

$\sum\limits_{n=1}^{N}\left[\sum\limits_{i=1}^{T}x_{n,i}\cdot p_{i}-y_{n,i}\cdot p_{i}\right]$

$ \forall_{n} \forall_{i} x_{n,i},y_{n,i}\geq 0 \wedge x_{n,i},y_{n,i}\leq M_{n} $

$\forall_{n} \forall_{i} \text{state}_{n,i}=\text{state}_{n,i-1}+y_{n,i}-x_{n,i}$

$ \forall_{n} \forall_{i} \text{statemin}_{n} \leq \text{state}_{n,i} \leq \text{statemax}_{n}$

$ \text{flow}_{l,i} = A \cdot K_{i}$

$ \text{flow}_{l,i} \leq \text{fmax}_{l}$

$ K_{i} = L_{i} - (G_{i} + y_{i} - x_{i})$

Where $A$ is an $N \times N$ matrix. Any feedback is appreciated,

The GAMS code is the following:

** Define the structure to connect with the matlab code
*$onempty
$include matglobs.gms

set      t /1*%timeSteps%/,
         b /1*%bus%/,
         l /1*%lines%/
         ;

Positive Variable x(b,t),
                  y(b,t)
                  state(b,t)
                  ;

Free Variable    res, unit(b), revenue, flow(l,t), K(b,t);

parameters       size(b), rate(b), fmax(l), P(b,t), A(l,b), price(t);

$if exist matdata.gms $include matdata.gms

Equations

stateCalc1(b,t)
stateCalc2(b,t)
Initial_y(b,t)
Initial_x(b,t)
stateMax(b,t)
stateMin(b,t)

max_x(b,t)
max_y(b,t)

K_Calc(b,t)
flow_Calc(l,t)
lim_K(l,t)

Con10(b)
Con11
Obj
;

stateCalc1(b,t)$(ord(t)=1)..      state(b,t) =e= size(b)/2;
stateCalc2(b,t)$(ord(t)>1)..      state(b,t) =e= state(b,t-1) + y(b,t) - x(b,t);

Initial_y(b,t)$(ord(t)=1)..           y(b,t) =e= 0;
Initial_x(b,t)$(ord(t)=1)..           x(b,t) =e= 0;

stateMax(b,t)..                   state(b,t) =l= size(b);
stateMin(b,t)..                   state(b,t) =g= 0;

max_x(b,t)..        x(b,t) =l= rate(b)*size(b); 
max_y(b,t)..        y(b,t) =l= rate(b)*size(b);


K_Calc(b,t)..       K(b,t) =e= P(b,t)+y(b,t)-x(b,t);
flow_Calc(l,t)..    flow(l,t) =e= sum(b, A(l,b)*K(b,t));
lim_K(l,t)..        flow(l,t) =l= fmax(l);

Con10(b)..               sum(t, x(b,t)*price(t) - y(b,t)*price(t)) =e= unit(b);
Con11..                  sum(b, unit(b)) =e= revenue;

Obj..                    revenue =e= res;

Model Opt_Bat /all/;

Solve Opt_Bat using LP maximazing res;

Display state.l, size;

$libinclude matout res.l

To be noted that $M_{n} = size_{n} * rate_{n}$.

MiguelL
  • 81
  • 4
  • 1
    Welcome to OR.SE, it looks to me that the model is linear but may be the way that you define your problem in GAMS is problematic. Can you please edit the model and put it in standard model form? That way it would be easier to help you. – Oguz Toragay Nov 22 '19 at 19:18
  • 1
    You said that only $x$, $y$ and state are variables. So $\mathrm{flow}{\ell,i}$, $\mathrm{fmax}\ell$, $K_i$, $L_i$ and $G_i$ are all parameters? – prubin Nov 22 '19 at 21:34
  • 1
    I think $\text{flow}_{l,i}$ should also a variable... – Oguz Toragay Nov 22 '19 at 21:48
  • 1
    As @OguzToragay said, would you please, share your GAMS source code? – A.Omidi Nov 23 '19 at 06:28
  • @OguzToragay indeed in the GAMS formulation $\text{flow}_{l,i}$ is also a variable, my apologies. I attached the GAMS code to the question. – MiguelL Nov 23 '19 at 12:33
  • @A.Omidi I just shared it above. – MiguelL Nov 23 '19 at 12:52

1 Answers1

6

The model you describe is linear. There are a couple of reasons why GAMS wouldn't like it though: (I) did you define the right solver for your problem? and (ii) GAMS initialises any uninitiated variables to 0 - it then proceeds to evaluate all constraints at the initial values before sending the problem to a solver. If the initial values are infeasible (including the implicit 0 values), then GAMS will refuse to solve your model.

Another possibility for what you report is that your problem is integer, in which case there can be multiple solutions unless you specify that you desire a very small MIP gap for convergence.

Nikos Kazazakis
  • 12,121
  • 17
  • 59
  • (I) I believe the right solver would be "LP" is the problem was linear . (II) What happens is that GAMS solves the problem with no ERROR warnings, but the solutions variables, such as $state_{n,i}$ are not within the proper limits. Would this happen in that situation? – MiguelL Nov 23 '19 at 12:51
  • If GAMS did not produce any error message, but certain variables are not in their range. My suggestion is to double check the constraints related with those variables. One direction to look at is the values of dual variables that correspond to those constraints that are violated. – Qian Zhang Nov 23 '19 at 20:07
  • Adding to what Qian Zhang mentioned, your model has free variables - not setting reasonable bounds for your variables can have very unpredictable effects. Same for the positive variables, try adding some upper bounds. You can also try using a different LP solver to see if the result is different. Out of curiosity, what is it about your result that doesn't make sense? – Nikos Kazazakis Nov 25 '19 at 03:07
  • @nikaza I believe I have the limits in check now. However the result doesn't make sense as my value 'res', is not the sum of all 'unit' like formulated in the gams code above. I dont understand where the value is coming from if these values do not correspond. Moreover a few units have a large negative revenue. Worst case scenario they would not operate and revenue would be 0 OR maybe have slight negative revenue in order to alleviate flow from other units. – MiguelL Nov 25 '19 at 12:37
  • 1
    Interesting. Does GAMS report a solver flag? If it's infeasible many solvers return nonsensical numbers. – Nikos Kazazakis Nov 25 '19 at 23:13
  • @nikaza You're right. It is deemed infeasible. Do you have any suggestions to where I can figure out why? – MiguelL Nov 26 '19 at 17:22
  • It's hard to tell, but you can easily find out by disabling all constraints and turning them on one by one - the moment your model becomes infeasible you will have discovered the offending constraint. – Nikos Kazazakis Nov 27 '19 at 00:44
  • @nikaza Thank you! – MiguelL Nov 28 '19 at 12:23
  • You're welcome! Glad to know it worked out :) – Nikos Kazazakis Nov 30 '19 at 00:45