Berni
Berni

Reputation: 93

LoadError: MethodError: no method matching getname(::Int64)

I try to run the following code block:

using JuMP
using CPLEX  
function solveRMP(cust::Int64,
  routes::Array{Float64,2},
  routeCost::Array{Float64,1},
  m::Int64)

  cust_dep = cust+2;

  rmp = Model(solver = CplexSolver())
  # Add decistion variables
  @variable(rmp, 0<=x[1:size(routes,2)])
  #
  # Add objective
  @objective(rmp, Min, sum(routeCost[r]*x[r] for r=1:size(routes,2)))
  # #####################
  # ### Constraints
  @constraint(rmp, cVisitCust[i=2:cust_dep-1], sum(routes[i,r]*x[r] for r=1:size(routes,2)) == 1)
  @constraint(rmp, cMaxNrRoutes, sum(x[r] for r=1:size(routes,2)) <= m )

  allConstraints = vcat(cVisitCust,cMaxNrRoutes)


  writeLP(rmp, "myRMP.lp", genericnames=false);


  solve(rmp)
  duals = zeros(1,1)
  append!(duals,getdual(allConstraints))

  return  getvalue(x), duals 
end

and I get the following error:

**LoadError: MethodError: no method matching getname(::Int64)
Closest candidates are:
  getname(!Matched::Expr) at 
(...) **

Upvotes: 2

Views: 1449

Answers (1)

skleinbo
skleinbo

Reputation: 357

In the declaration of the variables x,

@variable(rmp, 0<=x[1:size(routes,2)])

the constraint needs to be on the right side of the variable name

@variable(rmp, x[1:size(routes,2)] >= 0)

Otherwise 0 is interpreted as a variable name, leading to the error.

Upvotes: 3

Related Questions