2

I want to code domination definition in Julia. x dom y. x , y are 2 vectors.

b=all(x<=y) && any(x<y)

would you please help me. How can I code this concept in Julia?

Thank you

Soma
  • 743
  • 6
  • 19

1 Answers1

1

The simplest approach can be almost like you have specified it:

dom(x, y) = all(x .<= y) && any(x .< y)

You could also use a loop e.g. like this:

function dom(x::AbstractVector, y::AbstractVector)
    @assert length(x) == length(y)
    wasless = false
    for (xi, yi) in zip(x, y)
        if xi < yi
            wasless = true
        elseif xi > yi
            return false
        end
    end
    return wasless
end
Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107