0

I use some functions in my main code which they return some values (scalar).
These values will compare in main code.
But when I run the code it has this Error:

"ERROR: MethodError: no method matching isless(::Array{Float64,1}, ::Array{Float64,1})"

Please help me. This is the code:

using JuMP, CPLEX
ZT = [-36    ; -244.5  ]; 
ZB = [27.149 ; -288.747];
M  = 5;

model = CreateModel();
WES   = model[1];
f1    = model[2];    f2    = model[3];
rf1   = model[4];    rf2   = model[5];
lf1   = model[6];    lf2   = model[7];
x     = WES[:x] ;    y     = WES[:y] ;

JuMP.setRHS( rf1, ZB[1] );    JuMP.setRHS( lf1, ZT[1] );
JuMP.setRHS( rf2, ZT[2] );    JuMP.setRHS( lf2, ZB[2] );

ZI, ofvInt             = Intpoint( ZB, ZT );
Hgap, Vgap, ZG, ofvGap = Gappoint( ZB, ZT );

if ofvInt !== NaN
    y = ZI[2];
elseif ofvGap !== NaN
    if isless( Hgap, M + Vgap ) # "MethodError: no method matching 
                                # isless(::Array{Float64,1}, ::Array{Float64,1})" 
        y = ZG[1]
    end

    y = ZG[2];
else
    y = ( ZB[2] + ZT[2] ) / 2;
end
mbauman
  • 30,958
  • 4
  • 88
  • 123
Soma
  • 743
  • 6
  • 19
  • `Hgap` and `M+Vgap` are `Array`s not scalars, as the error indicates. You can't compare two arrays with `isless` (`<`) but you can compare their elements. What exactly is `if isless(Hgap, M+Vgap)` trying to achieve? – hckr Nov 29 '18 at 18:06
  • Hgap and Vgap r two functions that calculate horizontal and vertical gap between two points. if Hgap>Vgap then the cut (y) should be vertical (y=ZG[1]). otherwise it should be horizontal (y=ZG[2]). – Soma Nov 29 '18 at 20:05
  • if `Hgap` and `Vgap` were indeed _functions_, then you would need to call them first to obtain their result. However, given the error, it seems they are not functions but arrays. So, index them appropriately to get the element you need, e.g. `Hgap[1]` for the first (and possibly only) element in the array. – Tasos Papastylianou Nov 30 '18 at 08:26
  • Also, note that the way this code is currently written, `y = ZG[2]` will always be executed after your `isless` check _anyway_, so you will never end up with `y` being assigned `ZG[1]` by the end of the if blocks anyway. – Tasos Papastylianou Nov 30 '18 at 08:28
  • Thanks for your kindly helps. ZG is a vector with two elements. Hgap and Vgap are return by ofvGap function. I didnt know the return values of function is array. As you said I changed Hgap to Hgap[1] and the code was run correctly. – Soma Nov 30 '18 at 09:11

0 Answers0