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
$include matglobs.gms

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

Positive Variable x(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






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}$.

  • 1
    $\begingroup$ 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. $\endgroup$ – Oguz Toragay Nov 22 '19 at 19:18
  • 1
    $\begingroup$ 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? $\endgroup$ – prubin Nov 22 '19 at 21:34
  • 1
    $\begingroup$ I think $\text{flow}_{l,i}$ should also a variable... $\endgroup$ – Oguz Toragay Nov 22 '19 at 21:48
  • 1
    $\begingroup$ As @OguzToragay said, would you please, share your GAMS source code? $\endgroup$ – A.Omidi Nov 23 '19 at 6:28
  • $\begingroup$ @OguzToragay indeed in the GAMS formulation $\text{flow}_{l,i}$ is also a variable, my apologies. I attached the GAMS code to the question. $\endgroup$ – MiguelL Nov 23 '19 at 12:33

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.

  • $\begingroup$ (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? $\endgroup$ – MiguelL Nov 23 '19 at 12:51
  • $\begingroup$ 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. $\endgroup$ – Qian Zhang Nov 23 '19 at 20:07
  • $\begingroup$ 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? $\endgroup$ – Nikos Kazazakis Nov 25 '19 at 3:07
  • $\begingroup$ @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. $\endgroup$ – MiguelL Nov 25 '19 at 12:37
  • 1
    $\begingroup$ Interesting. Does GAMS report a solver flag? If it's infeasible many solvers return nonsensical numbers. $\endgroup$ – Nikos Kazazakis Nov 25 '19 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.