2
votes

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 
(...) **
1
Be helpful to see the full error so we can see in which function it occurred. - Alexander Morley
When doing ` <= m` in the last constraint, try to replace m with Float64(m). The solver uses continuous values and integers confuse it. - Dan Getz
I tried what you mentioned but the error is still there - Berni
while loading ...\VRTW.jl, in expression starting on line 28 include_string(::String, ::String) at loading.jl:515 include_string(::Module, ::String, ::String) at Compat.jl:577 (::Atom.##55#58{String,String})() at eval.jl:73 withpath(::Atom.##55#58{String,String}, ::String) at utils.jl:30 withpath(::Function, ::String) at eval.jl:38 macro expansion at eval.jl:71 [inlined] (::Atom.##54#57{Dict{String,Any}})() at task.jl:80 - Berni
line 28 refers to the one where the function starts - Berni

1 Answers

3
votes

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.