# LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

9 messages
Open this post in threaded view
|
Report Content as Inappropriate

## LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist) -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 The error message is instructive: you're trying to index an array of variables (x) by a Variable (aux) and an integer (j), and this is not supported.Joey _____________________________From: [hidden email]Sent: Tuesday, October 18, 2016 6:26 PMSubject: [julia-opt] LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supportedTo: julia-opt <[hidden email]>Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist)-- You received this message because you are subscribed to the Google Groups "julia-opt" group.To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].Visit this group at https://groups.google.com/group/julia-opt.For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 Yes, I know... Posted here in hope someone gives an idea on how overcome this...On Tue, 18 Oct 2016 at 20:39 Joey Huchette <[hidden email]> wrote: The error message is instructive: you're trying to index an array of variables (x) by a Variable (aux) and an integer (j), and this is not supported.Joey _____________________________From: [hidden email]Sent: Tuesday, October 18, 2016 6:26 PMSubject: [julia-opt] LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supportedTo: julia-opt <[hidden email]>Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist)-- You received this message because you are subscribed to the Google Groups "julia-opt" group.To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].Visit this group at https://groups.google.com/group/julia-opt.For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to a topic in the Google Groups "julia-opt" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-opt/JOdZy26YEIw/unsubscribe. To unsubscribe from this group and all its topics, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout. -- Ranmsés(84) 99686-6400 -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 In reply to this post by Joey Huchette Yes, I know... Posted here in hope someone gives an idea on how overcome this... Or if it'll be available in next versions.On Tuesday, October 18, 2016 at 8:39:41 PM UTC-3, Joey Huchette wrote: The error message is instructive: you're trying to index an array of variables (x) by a Variable (aux) and an integer (j), and this is not supported.Joey _____________________________From: ran...@...Sent: Tuesday, October 18, 2016 6:26 PMSubject: [julia-opt] LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supportedTo: julia-opt <juli...@...>Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist)-- You received this message because you are subscribed to the Google Groups "julia-opt" group.To unsubscribe from this group and stop receiving emails from it, send an email to julia-opt+...@googlegroups.com.Visit this group at https://groups.google.com/group/julia-opt.For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 In reply to this post by ranmses Anyone?Since I've just learnt to use minizinc and JuMP seems to be more advanced, I find it very odd that this feature isn't present.I did some digging trying to find alternatives by using lazy constraints, but since my problem is non-linear this can't take me too far.I tried to remodel the problem too, but I ended up needing to index Array{Int64,2} with types Tuple{JuMP.Variable}, which is not supported either.Best!On Tue, Oct 18, 2016 at 7:26 PM, wrote:Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist) -- You received this message because you are subscribed to a topic in the Google Groups "julia-opt" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-opt/JOdZy26YEIw/unsubscribe. To unsubscribe from this group and all its topics, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 It will not be available in any JuMP release in the foreseeable future because formulations like this fall outside the scope of mathematical optimization. JuMP is a thin layer on top of existing solution methods and purposely does not perform any magical transformations.On Friday, November 4, 2016 at 3:20:59 PM UTC-7, Ranmsés wrote:Anyone?Since I've just learnt to use minizinc and JuMP seems to be more advanced, I find it very odd that this feature isn't present.I did some digging trying to find alternatives by using lazy constraints, but since my problem is non-linear this can't take me too far.I tried to remodel the problem too, but I ended up needing to index Array{Int64,2} with types Tuple{JuMP.Variable}, which is not supported either.Best!On Tue, Oct 18, 2016 at 7:26 PM, wrote:Hello!I'm trying to modify the TSP model into a new related problem I'm working on.The code below is working (value 13.0, tour sequence [1,3,2,4,1] ) but I need to apply further constraints at the tour sequence.I tried to do it as commented below "NOT WORKING", but instead I get "ERROR: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported".There is any way to do it?Thanks a lot.using JuMPusing Base.Testn = 4dist = [ 0 9 3 1;             9 0 2 7;             3 2 0 4;             1 7 4 0]function extractTour(n, sol)    tour = [1]  # Start at city 1 always    cur_city = 1    while true        # Look for first arc out of current city        for j = 1:n            if sol[cur_city,j] >= 1-1e-6                # Found next city                push!(tour, j)                # Don't ever use this arc again                sol[cur_city, j] = 0.0                sol[j, cur_city] = 0.0                # Move to next city                cur_city = j                break            end        end        # If we have come back to 1, stop        if cur_city == 1            break        end    end  # end while    return tourendfunction solveTSP(n, dist)    m = Model()    # Decision matrix    @variable(m, x[1:n,1:n], Bin)    # TSP - MTZ formulation    @objective(m, Min, sum{dist[i,j]*x[i,j], i=1:n, j=1:n; i != j})    for i = 1:n        @constraint(m, x[i,i] == 0)        @constraint(m, sum{x[i,j], j=1:n} == 1)        @constraint(m, sum{x[j,i], j=1:n} == 1)    end    @variable(m, 1 <= u[1:n] <= n, Int)    @constraint(m, u[1] == 1)    for i = 2:n        @constraint(m, u[i] >= 2)        for j = 2:n            @constraint(m, u[i] - u[j] + 1<= (n-1)*(1 - x[i,j]) )        end    end    # Define tour variable relating to x so I can apply constraints to it -- NOT WORKING    # @variable(m, 1 <= tour[1:n+1] <= n, Int )    # @constraint(m, tour[1] == 1)    # for i = 2:n    #     @variable(m, 1 <= aux <= n, Int)    #     @constraint(m, aux == tour[i-1])    #     @constraint(m, tour[i] == sum{j*x[aux,j], j = 1:n, k = 1:n})    # end    # @constraint(m, tour[n+1] == 1)    #     solve(m)    println("Objective value: ", getobjectivevalue(m))    t = extractTour(n, getvalue(x))    println(t)endsolveTSP(n, dist) -- You received this message because you are subscribed to a topic in the Google Groups "julia-opt" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/julia-opt/JOdZy26YEIw/unsubscribe. To unsubscribe from this group and all its topics, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 In reply to this post by ranmses Hi Ranmses, I recommend using minizinc as an abstraction layer on top of CP solvers and JuMP as an abstraction layer on top of mathematical programming solvers.  This was the original design of each modeling tool. Also, I would not say one is more advanced than another.  The motivations of minizinc and JuMP are quite different, so that's an apples vs oranges type of comparison. Cheers, -Carleton -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: LoadError: indexing Array{JuMP.Variable,2} with types Tuple{JuMP.Variable,Int64} is not supported

 Hello Miles and Carleton,First of all, thank you for taking time to answer.What I meant by more advanced is that JuMP *seems* to be expanding its capabilities each day with new packages. Minizinc is powerful and solid and gives plenty of freedom to the user, but it feels that JuMP has got more attention from the community. All in all, it's just an impression.My research problem is new and to solve it I have developed heuristics and branch-and-bound algorithms. Now I'm working on the mathematical model and I do have a set of constraints that solve it using Minizinc and Gecode, but it takes too much time comparing to the branch-and-bound I have implemented. I thought that using JuMP and Gurobi/CPLEX I could have a better performance finding exact solutions, but here I am.I've found articles saying it's possible to "translate" a Minizinc model to LP format, which could be a lifesaver. But since I use float variables and a nonlinear objective function, the doubt remains.I don't quite think that using a variable to index a fixed array is a magical transformation at all. But you guys know best, I'm just a user.Thank you again. -- You received this message because you are subscribed to the Google Groups "julia-opt" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. Visit this group at https://groups.google.com/group/julia-opt. For more options, visit https://groups.google.com/d/optout.